source
stringlengths
17
118
lean4
stringlengths
0
335k
.lake/packages/mathlib/Mathlib/RingTheory/Congruence/Basic.lean
import Mathlib.Algebra.Ring.Action.Basic import Mathlib.GroupTheory.Congruence.Basic import Mathlib.RingTheory.Congruence.Defs /-! # Congruence relations on rings This file contains basic results concerning 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`. -/ variable {α β R : Type*} namespace RingCon section Quotient section Algebraic /-! ### Scalar multiplication The operation of scalar multiplication `•` descends naturally to the quotient. -/ section SMul variable [Add R] [MulOneClass R] variable [SMul α R] [IsScalarTower α R R] variable [SMul β R] [IsScalarTower β R R] variable (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 instance [SMulCommClass α β R] : SMulCommClass α β c.Quotient := inferInstanceAs (SMulCommClass α β c.toCon.Quotient) instance [SMul α β] [IsScalarTower α β R] : IsScalarTower α β c.Quotient := inferInstanceAs (IsScalarTower α β c.toCon.Quotient) instance [SMul αᵐᵒᵖ R] [IsCentralScalar α R] : IsCentralScalar α c.Quotient := inferInstanceAs (IsCentralScalar α c.toCon.Quotient) end SMul 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 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_def] 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]⟩ instance [Subsingleton R] : Subsingleton (RingCon R) where allEq c c' := ext fun r r' ↦ by simp_rw [Subsingleton.elim r' r, c.refl, c'.refl] theorem nontrivial_iff : Nontrivial (RingCon R) ↔ Nontrivial R := by cases subsingleton_or_nontrivial R on_goal 1 => simp_rw [← not_subsingleton_iff_nontrivial, not_iff_not] all_goals exact iff_of_true inferInstance ‹_› theorem subsingleton_iff : Subsingleton (RingCon R) ↔ Subsingleton R := by simp_rw [← not_nontrivial_iff_subsingleton, nontrivial_iff] /-- 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 [iSup_apply, iSup_Prop_eq, exists_prop] 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
.lake/packages/mathlib/Mathlib/RingTheory/Congruence/Defs.lean
import Mathlib.Algebra.Ring.Hom.Defs import Mathlib.Algebra.Ring.InjSurj import Mathlib.GroupTheory.Congruence.Defs import Mathlib.Tactic.FastInstance /-! # 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) /-- A coercion from a congruence relation to its underlying binary relation. -/ instance : FunLike (RingCon R) R (R → Prop) where coe c := c.r coe_injective' x y h := by rcases x with ⟨⟨x, _⟩, _⟩ rcases y with ⟨⟨y, _⟩, _⟩ congr! rw [Setoid.ext_iff, (show ⇑x = ⇑y from h)] simp @[simp] theorem coe_mk (s : Con R) (h) : ⇑(mk s h) = s := rfl 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*} [AddMonoid 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. -/ @[ext] theorem ext {c d : RingCon R} (H : ∀ x y, c x y ↔ d x y) : c = d := ext' <| by ext; apply H /-- Pulling back a `RingCon` across a ring homomorphism. -/ def comap {R R' F : Type*} [Add R] [Add R'] [FunLike F R R'] [AddHomClass F R R'] [Mul R] [Mul R'] [MulHomClass F R R'] (J : RingCon R') (f : F) : RingCon R where __ := J.toCon.comap f (map_mul f) __ := J.toAddCon.comap f (map_add f) 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 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 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 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 := fast_instance% Function.Surjective.nonUnitalNonAssocSemiring _ Quotient.mk''_surjective rfl (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl instance [NonAssocSemiring R] (c : RingCon R) : NonAssocSemiring c.Quotient := fast_instance% Function.Surjective.nonAssocSemiring _ Quotient.mk''_surjective rfl rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ => rfl instance [NonUnitalSemiring R] (c : RingCon R) : NonUnitalSemiring c.Quotient := fast_instance% Function.Surjective.nonUnitalSemiring _ Quotient.mk''_surjective rfl (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl instance [Semiring R] (c : RingCon R) : Semiring c.Quotient := fast_instance% Function.Surjective.semiring _ Quotient.mk''_surjective rfl rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ => rfl instance [CommSemiring R] (c : RingCon R) : CommSemiring c.Quotient := fast_instance% Function.Surjective.commSemiring _ Quotient.mk''_surjective rfl rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ => rfl instance [NonUnitalNonAssocRing R] (c : RingCon R) : NonUnitalNonAssocRing c.Quotient := fast_instance% Function.Surjective.nonUnitalNonAssocRing _ Quotient.mk''_surjective rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl instance [NonAssocRing R] (c : RingCon R) : NonAssocRing c.Quotient := fast_instance% Function.Surjective.nonAssocRing _ Quotient.mk''_surjective 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 := fast_instance% Function.Surjective.nonUnitalRing _ Quotient.mk''_surjective rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl instance [Ring R] (c : RingCon R) : Ring c.Quotient := fast_instance% Function.Surjective.ring _ Quotient.mk''_surjective 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 := fast_instance% Function.Surjective.commRing _ Quotient.mk''_surjective rfl rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) fun _ => rfl 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 end RingCon
.lake/packages/mathlib/Mathlib/RingTheory/Congruence/BigOperators.lean
import Mathlib.GroupTheory.Congruence.BigOperators import Mathlib.RingTheory.Congruence.Defs /-! # 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
.lake/packages/mathlib/Mathlib/RingTheory/OreLocalization/Ring.lean
import Mathlib.Algebra.Algebra.Defs import Mathlib.Algebra.Field.Defs import Mathlib.RingTheory.OreLocalization.NonZeroDivisors /-! # Module and Ring instances of Ore Localizations The `Monoid` and `DistribMulAction` instances and additive versions are provided in `Mathlib/RingTheory/OreLocalization/Basic.lean`. -/ assert_not_exists Subgroup universe u namespace OreLocalization section Module variable {R : Type*} [Semiring R] {S : Submonoid R} [OreSet S] variable {X : Type*} [AddCommMonoid X] [Module R X] protected theorem zero_smul (x : X[S⁻¹]) : (0 : R[S⁻¹]) • x = 0 := by induction x with | _ r s rw [OreLocalization.zero_def, oreDiv_smul_char 0 r 1 s 0 1 (by simp)]; simp protected theorem add_smul (y z : R[S⁻¹]) (x : X[S⁻¹]) : (y + z) • x = y • x + z • x := by induction x with | _ r₁ s₁ induction y with | _ r₂ s₂ induction z with | _ r₃ s₃ rcases oreDivAddChar' r₂ r₃ s₂ s₃ with ⟨ra, sa, ha, q⟩ rw [q] clear q rw [OreLocalization.expand' r₂ s₂ sa] rcases oreDivSMulChar' (sa • r₂) r₁ (sa * s₂) s₁ with ⟨rb, sb, hb, q⟩ rw [q] clear q have hs₃rasb : sb * ra * s₃ ∈ S := by rw [mul_assoc, ← ha] norm_cast apply SetLike.coe_mem rw [OreLocalization.expand _ _ _ hs₃rasb] have ha' : ↑((sb * sa) * s₂) = sb * ra * s₃ := by simp [ha, mul_assoc] rw [← Subtype.coe_eq_of_eq_mk ha'] rcases oreDivSMulChar' ((sb * ra) • r₃) r₁ (sb * sa * s₂) s₁ with ⟨rc, sc, hc, hc'⟩ rw [hc'] rw [oreDiv_add_char _ _ 1 sc (by simp [mul_assoc])] rw [OreLocalization.expand' (sa • r₂ + ra • r₃) (sa * s₂) (sc * sb)] simp only [smul_eq_mul, one_smul, Submonoid.smul_def, mul_add, Submonoid.coe_mul] at hb hc ⊢ rw [mul_assoc, hb, mul_assoc, ← mul_assoc _ ra, hc, ← mul_assoc, ← add_mul] rw [OreLocalization.smul_cancel'] simp only [add_smul, ← mul_assoc, smul_smul] end Module section Semiring variable {R : Type*} [Semiring R] {S : Submonoid R} [OreSet S] attribute [local instance] OreLocalization.oreEqv @[deprecated zero_mul (since := "2025-08-20")] protected theorem zero_mul (x : R[S⁻¹]) : 0 * x = 0 := OreLocalization.zero_smul x @[deprecated mul_zero (since := "2025-08-20")] protected theorem mul_zero (x : R[S⁻¹]) : x * 0 = 0 := OreLocalization.smul_zero x protected theorem left_distrib (x y z : R[S⁻¹]) : x * (y + z) = x * y + x * z := OreLocalization.smul_add _ _ _ theorem right_distrib (x y z : R[S⁻¹]) : (x + y) * z = x * z + y * z := OreLocalization.add_smul _ _ _ instance : Semiring R[S⁻¹] where __ := inferInstanceAs (MonoidWithZero (R[S⁻¹])) __ := inferInstanceAs (AddCommMonoid (R[S⁻¹])) left_distrib := OreLocalization.left_distrib right_distrib := right_distrib variable {X : Type*} [AddCommMonoid X] [Module R X] instance : Module R[S⁻¹] X[S⁻¹] where add_smul := OreLocalization.add_smul zero_smul := OreLocalization.zero_smul instance {R₀} [Semiring R₀] [Module R₀ X] [Module R₀ R] [IsScalarTower R₀ R X] [IsScalarTower R₀ R R] : Module R₀ X[S⁻¹] where add_smul r s x := by simp only [← smul_one_oreDiv_one_smul, add_smul, ← add_oreDiv] zero_smul x := by rw [← smul_one_oreDiv_one_smul, zero_smul, zero_oreDiv, zero_smul] @[simp] lemma nsmul_eq_nsmul (n : ℕ) (x : X[S⁻¹]) : letI inst := OreLocalization.instModuleOfIsScalarTower (R₀ := ℕ) (R := R) (X := X) (S := S) HSMul.hSMul (self := @instHSMul _ _ inst.toSMul) n x = n • x := by letI inst := OreLocalization.instModuleOfIsScalarTower (R₀ := ℕ) (R := R) (X := X) (S := S) exact congr($(AddCommMonoid.uniqueNatModule.2 inst).smul n x) /-- The ring homomorphism from `R` to `R[S⁻¹]`, mapping `r : R` to the fraction `r /ₒ 1`. -/ @[simps!] def numeratorRingHom : R →+* R[S⁻¹] where __ := numeratorHom map_zero' := by with_unfolding_all exact OreLocalization.zero_def map_add' _ _ := add_oreDiv.symm instance {R₀} [CommSemiring R₀] [Algebra R₀ R] : Algebra R₀ R[S⁻¹] where __ := inferInstanceAs (Module R₀ R[S⁻¹]) algebraMap := numeratorRingHom.comp (algebraMap R₀ R) commutes' r x := by induction x using OreLocalization.ind with | _ r₁ s₁ dsimp rw [mul_div_one, oreDiv_mul_char _ _ _ _ (algebraMap R₀ R r) s₁ (Algebra.commutes _ _).symm, Algebra.commutes, mul_one] smul_def' r x := by dsimp rw [Algebra.algebraMap_eq_smul_one, ← smul_eq_mul, smul_one_oreDiv_one_smul] section UMP variable {T : Type*} [Semiring T] variable (f : R →+* T) (fS : S →* Units T) variable (hf : ∀ s : S, f s = fS s) /-- The universal lift from a ring homomorphism `f : R →+* T`, which maps elements in `S` to units of `T`, to a ring homomorphism `R[S⁻¹] →+* T`. This extends the construction on monoids. -/ def universalHom : R[S⁻¹] →+* T := { universalMulHom f.toMonoidHom fS hf with map_zero' := by simp only [RingHom.toMonoidHom_eq_coe, OneHom.toFun_eq_coe, MonoidHom.toOneHom_coe] rw [OreLocalization.zero_def, universalMulHom_apply] simp map_add' := fun x y => by simp only [RingHom.toMonoidHom_eq_coe, OneHom.toFun_eq_coe, MonoidHom.toOneHom_coe] induction x with | _ r₁ s₁ induction y with | _ r₂ s₂ rcases oreDivAddChar' r₁ r₂ s₁ s₂ with ⟨r₃, s₃, h₃, h₃'⟩ rw [h₃'] clear h₃' simp only [smul_eq_mul, universalMulHom_apply, MonoidHom.coe_coe, Submonoid.smul_def] simp only [mul_inv_rev, MonoidHom.map_mul, RingHom.map_add, RingHom.map_mul, Units.val_mul] rw [mul_add, mul_assoc, ← mul_assoc _ (f s₃), hf, ← Units.val_mul] simp only [one_mul, inv_mul_cancel, Units.val_one] congr 1 rw [← mul_assoc] congr 1 norm_cast at h₃ have h₃' := Subtype.coe_eq_of_eq_mk h₃ rw [← Units.val_mul, ← mul_inv_rev, ← fS.map_mul, h₃'] rw [Units.inv_mul_eq_iff_eq_mul, Units.eq_mul_inv_iff_mul_eq, ← hf, ← hf] simp only [map_mul] } theorem universalHom_apply {r : R} {s : S} : universalHom f fS hf (r /ₒ s) = ((fS s)⁻¹ : Units T) * f r := rfl theorem universalHom_commutes {r : R} : universalHom f fS hf (numeratorHom r) = f r := by simp [numeratorHom_apply, universalHom_apply] theorem universalHom_unique (φ : R[S⁻¹] →+* T) (huniv : ∀ r : R, φ (numeratorHom r) = f r) : φ = universalHom f fS hf := RingHom.coe_monoidHom_injective <| universalMulHom_unique (RingHom.toMonoidHom f) fS hf (↑φ) huniv end UMP end Semiring section Ring variable {R : Type*} [Ring R] {S : Submonoid R} [OreSet S] variable {X : Type*} [AddCommGroup X] [Module R X] instance : Ring R[S⁻¹] where __ := inferInstanceAs (Semiring R[S⁻¹]) __ := inferInstanceAs (AddGroup R[S⁻¹]) @[simp] lemma zsmul_eq_zsmul (n : ℤ) (x : X[S⁻¹]) : letI inst := OreLocalization.instModuleOfIsScalarTower (R₀ := ℤ) (R := R) (X := X) (S := S) HSMul.hSMul (self := @instHSMul _ _ inst.toSMul) n x = n • x := by letI inst := OreLocalization.instModuleOfIsScalarTower (R₀ := ℤ) (R := R) (X := X) (S := S) exact congr($(AddCommGroup.uniqueIntModule.2 inst).smul n x) open nonZeroDivisors theorem numeratorHom_inj (hS : S ≤ nonZeroDivisorsLeft R) : Function.Injective (numeratorHom : R → R[S⁻¹]) := fun r₁ r₂ h => by rw [numeratorHom_apply, numeratorHom_apply, oreDiv_eq_iff] at h rcases h with ⟨u, v, h₁, h₂⟩ simp only [S.coe_one, mul_one, Submonoid.smul_def, smul_eq_mul] at h₁ h₂ rw [← h₂, ← sub_eq_zero, ← mul_sub] at h₁ exact (sub_eq_zero.mp (hS u.2 _ h₁)).symm end Ring noncomputable section DivisionRing open nonZeroDivisors variable {R : Type*} [Ring R] [Nontrivial R] [NoZeroDivisors R] [OreSet R⁰] instance : DivisionRing R[R⁰⁻¹] where mul_inv_cancel := OreLocalization.mul_inv_cancel inv_zero := OreLocalization.inv_zero nnqsmul := _ nnqsmul_def := fun _ _ => rfl qsmul := _ qsmul_def := fun _ _ => rfl end DivisionRing section CommSemiring variable {R : Type*} [CommSemiring R] {S : Submonoid R} [OreSet S] instance : CommSemiring R[S⁻¹] where __ := inferInstanceAs (Semiring R[S⁻¹]) __ := inferInstanceAs (CommMonoid R[S⁻¹]) end CommSemiring section CommRing variable {R : Type*} [CommRing R] {S : Submonoid R} [OreSet S] instance : CommRing R[S⁻¹] where __ := inferInstanceAs (Ring R[S⁻¹]) __ := inferInstanceAs (CommMonoid R[S⁻¹]) end CommRing section Field open nonZeroDivisors variable {R : Type*} [CommRing R] [Nontrivial R] [NoZeroDivisors R] [OreSet R⁰] noncomputable instance : Field R[R⁰⁻¹] where __ := inferInstanceAs (DivisionRing R[R⁰⁻¹]) __ := inferInstanceAs (CommMonoid R[R⁰⁻¹]) end Field end OreLocalization
.lake/packages/mathlib/Mathlib/RingTheory/OreLocalization/OreSet.lean
import Mathlib.Algebra.Group.Submonoid.Defs import Mathlib.Algebra.GroupWithZero.Basic import Mathlib.Algebra.Ring.Regular import Mathlib.GroupTheory.OreLocalization.OreSet /-! # (Left) Ore sets and rings This file contains results on left Ore sets for rings and monoids with zero. ## References * https://ncatlab.org/nlab/show/Ore+set -/ assert_not_exists RelIso namespace OreLocalization /-- Cancellability in monoids with zeros can act as a replacement for the `ore_right_cancel` condition of an ore set. -/ def oreSetOfCancelMonoidWithZero {R : Type*} [CancelMonoidWithZero R] {S : Submonoid R} (oreNum : R → S → R) (oreDenom : R → S → S) (ore_eq : ∀ (r : R) (s : S), oreDenom r s * r = oreNum r s * s) : OreSet S := { ore_right_cancel := fun _ _ s h => ⟨s, mul_eq_mul_left_iff.mpr (mul_eq_mul_right_iff.mp h)⟩ oreNum oreDenom ore_eq } /-- In rings without zero divisors, the first (cancellability) condition is always fulfilled, it suffices to give a proof for the Ore condition itself. -/ def oreSetOfNoZeroDivisors {R : Type*} [Ring R] [NoZeroDivisors R] {S : Submonoid R} (oreNum : R → S → R) (oreDenom : R → S → S) (ore_eq : ∀ (r : R) (s : S), oreDenom r s * r = oreNum r s * s) : OreSet S := letI : CancelMonoidWithZero R := NoZeroDivisors.toCancelMonoidWithZero oreSetOfCancelMonoidWithZero oreNum oreDenom ore_eq lemma nonempty_oreSet_iff {R : Type*} [Monoid R] {S : Submonoid R} : Nonempty (OreSet S) ↔ (∀ (r₁ r₂ : R) (s : S), r₁ * s = r₂ * s → ∃ s' : S, s' * r₁ = s' * r₂) ∧ (∀ (r : R) (s : S), ∃ (r' : R) (s' : S), s' * r = r' * s) := by constructor · exact fun ⟨_⟩ ↦ ⟨ore_right_cancel, fun r s ↦ ⟨oreNum r s, oreDenom r s, ore_eq r s⟩⟩ · intro ⟨H, H'⟩ choose r' s' h using H' exact ⟨H, r', s', h⟩ lemma nonempty_oreSet_iff_of_noZeroDivisors {R : Type*} [Ring R] [NoZeroDivisors R] {S : Submonoid R} : Nonempty (OreSet S) ↔ ∀ (r : R) (s : S), ∃ (r' : R) (s' : S), s' * r = r' * s := by constructor · exact fun ⟨_⟩ ↦ fun r s ↦ ⟨oreNum r s, oreDenom r s, ore_eq r s⟩ · intro H choose r' s' h using H exact ⟨oreSetOfNoZeroDivisors r' s' h⟩ end OreLocalization
.lake/packages/mathlib/Mathlib/RingTheory/OreLocalization/Basic.lean
import Mathlib.Algebra.Group.Submonoid.DistribMulAction import Mathlib.GroupTheory.OreLocalization.Basic import Mathlib.Algebra.GroupWithZero.Defs /-! # Localization over left Ore sets. This file proves results on the localization of rings (monoids with zeros) over a left Ore set. ## References * <https://ncatlab.org/nlab/show/Ore+localization> * [Zoran Škoda, *Noncommutative localization in noncommutative geometry*][skoda2006] ## Tags localization, Ore, non-commutative -/ assert_not_exists RelIso universe u namespace OreLocalization section MonoidWithZero variable {R : Type*} [MonoidWithZero R] {S : Submonoid R} [OreSet S] @[simp] theorem zero_oreDiv' (s : S) : (0 : R) /ₒ s = 0 := by rw [OreLocalization.zero_def, oreDiv_eq_iff] exact ⟨s, 1, by simp [Submonoid.smul_def]⟩ instance : MonoidWithZero R[S⁻¹] where zero_mul x := by induction x using OreLocalization.ind with | _ r s rw [OreLocalization.zero_def, oreDiv_mul_char 0 r 1 s 0 1 (by simp), zero_mul, one_mul] mul_zero x := by induction x using OreLocalization.ind with | _ r s rw [OreLocalization.zero_def, mul_div_one, mul_zero, zero_oreDiv', zero_oreDiv'] theorem subsingleton_iff : Subsingleton R[S⁻¹] ↔ 0 ∈ S := by rw [← subsingleton_iff_zero_eq_one, OreLocalization.one_def, OreLocalization.zero_def, oreDiv_eq_iff] simp theorem nontrivial_iff : Nontrivial R[S⁻¹] ↔ 0 ∉ S := by rw [← not_subsingleton_iff_nontrivial, subsingleton_iff] end MonoidWithZero section CommMonoidWithZero variable {R : Type*} [CommMonoidWithZero R] {S : Submonoid R} [OreSet S] instance : CommMonoidWithZero R[S⁻¹] where __ := inferInstanceAs (MonoidWithZero R[S⁻¹]) __ := inferInstanceAs (CommMonoid R[S⁻¹]) end CommMonoidWithZero section DistribMulAction variable {R : Type*} [Monoid R] {S : Submonoid R} [OreSet S] {X : Type*} [AddMonoid X] variable [DistribMulAction R X] private def add'' (r₁ : X) (s₁ : S) (r₂ : X) (s₂ : S) : X[S⁻¹] := (oreDenom (s₁ : R) s₂ • r₁ + oreNum (s₁ : R) s₂ • r₂) /ₒ (oreDenom (s₁ : R) s₂ * s₁) private theorem add''_char (r₁ : X) (s₁ : S) (r₂ : X) (s₂ : S) (rb : R) (sb : R) (hb : sb * s₁ = rb * s₂) (h : sb * s₁ ∈ S) : add'' r₁ s₁ r₂ s₂ = (sb • r₁ + rb • r₂) /ₒ ⟨sb * s₁, h⟩ := by simp only [add''] have ha := ore_eq (s₁ : R) s₂ generalize oreNum (s₁ : R) s₂ = ra at * generalize oreDenom (s₁ : R) s₂ = sa at * rw [oreDiv_eq_iff] rcases oreCondition sb sa with ⟨rc, sc, hc⟩ have : sc * rb * s₂ = rc * ra * s₂ := by rw [mul_assoc rc, ← ha, ← mul_assoc, ← hc, mul_assoc, mul_assoc, hb] rcases ore_right_cancel _ _ s₂ this with ⟨sd, hd⟩ use sd * sc use sd * rc simp only [smul_add, smul_smul, Submonoid.smul_def, Submonoid.coe_mul] constructor · rw [mul_assoc _ _ rb, hd, mul_assoc, hc, mul_assoc, mul_assoc] · rw [mul_assoc, ← mul_assoc (sc : R), hc, mul_assoc, mul_assoc] attribute [local instance] OreLocalization.oreEqv private def add' (r₂ : X) (s₂ : S) : X[S⁻¹] → X[S⁻¹] := (--plus tilde Quotient.lift fun r₁s₁ : X × S => add'' r₁s₁.1 r₁s₁.2 r₂ s₂) <| by -- Porting note: `assoc_rw` & `noncomm_ring` were not ported yet rintro ⟨r₁', s₁'⟩ ⟨r₁, s₁⟩ ⟨sb, rb, hb, hb'⟩ -- s*, r* rcases oreCondition (s₁' : R) s₂ with ⟨rc, sc, hc⟩ --s~~, r~~ rcases oreCondition rb sc with ⟨rd, sd, hd⟩ -- s#, r# dsimp at * rw [add''_char _ _ _ _ rc sc hc (sc * s₁').2] have : sd * sb * s₁ = rd * rc * s₂ := by rw [mul_assoc, hb', ← mul_assoc, hd, mul_assoc, hc, ← mul_assoc] rw [add''_char _ _ _ _ (rd * rc : R) (sd * sb) this (sd * sb * s₁).2] rw [mul_smul, ← Submonoid.smul_def sb, hb, smul_smul, hd, oreDiv_eq_iff] use 1 use rd simp only [mul_smul, smul_add, one_smul, OneMemClass.coe_one, one_mul, true_and] rw [this, hc, mul_assoc] /-- The addition on the Ore localization. -/ @[irreducible] private def add : X[S⁻¹] → X[S⁻¹] → X[S⁻¹] := fun x => Quotient.lift (fun rs : X × S => add' rs.1 rs.2 x) (by rintro ⟨r₁, s₁⟩ ⟨r₂, s₂⟩ ⟨sb, rb, hb, hb'⟩ induction x with | _ r₃ s₃ change add'' _ _ _ _ = add'' _ _ _ _ dsimp only at * rcases oreCondition (s₃ : R) s₂ with ⟨rc, sc, hc⟩ rcases oreCondition rc sb with ⟨rd, sd, hd⟩ have : rd * rb * s₁ = sd * sc * s₃ := by rw [mul_assoc, ← hb', ← mul_assoc, ← hd, mul_assoc, ← hc, mul_assoc] rw [add''_char _ _ _ _ rc sc hc (sc * s₃).2] rw [add''_char _ _ _ _ _ _ this.symm (sd * sc * s₃).2] refine oreDiv_eq_iff.mpr ?_ simp only [smul_add] use sd, 1 simp only [one_smul, one_mul, mul_smul, ← hb, Submonoid.smul_def, ← mul_assoc, and_true] simp only [smul_smul, hd]) instance : Add X[S⁻¹] := ⟨add⟩ theorem oreDiv_add_oreDiv {r r' : X} {s s' : S} : r /ₒ s + r' /ₒ s' = (oreDenom (s : R) s' • r + oreNum (s : R) s' • r') /ₒ (oreDenom (s : R) s' * s) := by with_unfolding_all rfl theorem oreDiv_add_char' {r r' : X} (s s' : S) (rb : R) (sb : R) (h : sb * s = rb * s') (h' : sb * s ∈ S) : r /ₒ s + r' /ₒ s' = (sb • r + rb • r') /ₒ ⟨sb * s, h'⟩ := by with_unfolding_all exact add''_char r s r' s' rb sb h h' /-- A characterization of the addition on the Ore localization, allowing for arbitrary Ore numerator and Ore denominator. -/ theorem oreDiv_add_char {r r' : X} (s s' : S) (rb : R) (sb : S) (h : sb * s = rb * s') : r /ₒ s + r' /ₒ s' = (sb • r + rb • r') /ₒ (sb * s) := oreDiv_add_char' s s' rb sb h (sb * s).2 /-- Another characterization of the addition on the Ore localization, bundling up all witnesses and conditions into a sigma type. -/ def oreDivAddChar' (r r' : X) (s s' : S) : Σ' r'' : R, Σ' s'' : S, s'' * s = r'' * s' ∧ r /ₒ s + r' /ₒ s' = (s'' • r + r'' • r') /ₒ (s'' * s) := ⟨oreNum (s : R) s', oreDenom (s : R) s', ore_eq (s : R) s', oreDiv_add_oreDiv⟩ @[simp] theorem add_oreDiv {r r' : X} {s : S} : r /ₒ s + r' /ₒ s = (r + r') /ₒ s := by simp [oreDiv_add_char s s 1 1 (by simp)] protected theorem add_assoc (x y z : X[S⁻¹]) : x + y + z = x + (y + z) := by induction x with | _ r₁ s₁ induction y with | _ r₂ s₂ induction z with | _ r₃ s₃ rcases oreDivAddChar' r₁ r₂ s₁ s₂ with ⟨ra, sa, ha, ha'⟩; rw [ha']; clear ha' rcases oreDivAddChar' (sa • r₁ + ra • r₂) r₃ (sa * s₁) s₃ with ⟨rc, sc, hc, q⟩; rw [q]; clear q simp only [smul_add, add_assoc] simp_rw [← add_oreDiv, ← OreLocalization.expand'] congr 2 · rw [OreLocalization.expand r₂ s₂ ra (ha.symm ▸ (sa * s₁).2)]; congr; ext; exact ha · rw [OreLocalization.expand r₃ s₃ rc (hc.symm ▸ (sc * (sa * s₁)).2)]; congr; ext; exact hc @[simp] theorem zero_oreDiv (s : S) : (0 : X) /ₒ s = 0 := by rw [OreLocalization.zero_def, oreDiv_eq_iff] exact ⟨s, 1, by simp⟩ protected theorem zero_add (x : X[S⁻¹]) : 0 + x = x := by induction x rw [← zero_oreDiv, add_oreDiv]; simp protected theorem add_zero (x : X[S⁻¹]) : x + 0 = x := by induction x rw [← zero_oreDiv, add_oreDiv]; simp @[irreducible] private def nsmul : ℕ → X[S⁻¹] → X[S⁻¹] := nsmulRec instance : AddMonoid X[S⁻¹] where add_assoc := OreLocalization.add_assoc zero_add := OreLocalization.zero_add add_zero := OreLocalization.add_zero nsmul := nsmul nsmul_zero _ := by with_unfolding_all rfl nsmul_succ _ _ := by with_unfolding_all rfl protected theorem smul_zero (x : R[S⁻¹]) : x • (0 : X[S⁻¹]) = 0 := by induction x with | _ r s rw [OreLocalization.zero_def, smul_div_one, smul_zero, zero_oreDiv, zero_oreDiv] protected theorem smul_add (z : R[S⁻¹]) (x y : X[S⁻¹]) : z • (x + y) = z • x + z • y := by induction x with | _ r₁ s₁ induction y with | _ r₂ s₂ induction z with | _ r₃ s₃ rcases oreDivAddChar' r₁ r₂ s₁ s₂ with ⟨ra, sa, ha, ha'⟩; rw [ha']; clear ha'; norm_cast at ha rw [OreLocalization.expand' r₁ s₁ sa] rw [OreLocalization.expand r₂ s₂ ra (by rw [← ha]; apply SetLike.coe_mem)] rw [← Subtype.coe_eq_of_eq_mk ha] repeat rw [oreDiv_smul_oreDiv] simp only [smul_add, add_oreDiv] instance : DistribMulAction R[S⁻¹] X[S⁻¹] where smul_zero := OreLocalization.smul_zero smul_add := OreLocalization.smul_add instance {R₀} [Monoid R₀] [MulAction R₀ X] [MulAction R₀ R] [IsScalarTower R₀ R X] [IsScalarTower R₀ R R] : DistribMulAction R₀ X[S⁻¹] where smul_zero _ := by rw [← smul_one_oreDiv_one_smul, smul_zero] smul_add _ _ _ := by simp only [← smul_one_oreDiv_one_smul, smul_add] end DistribMulAction section AddCommMonoid variable {R : Type*} [Monoid R] {S : Submonoid R} [OreSet S] variable {X : Type*} [AddCommMonoid X] [DistribMulAction R X] protected theorem add_comm (x y : X[S⁻¹]) : x + y = y + x := by induction x with | _ r s induction y with | _ r' s' rcases oreDivAddChar' r r' s s' with ⟨ra, sa, ha, ha'⟩ rw [ha', oreDiv_add_char' s' s _ _ ha.symm (ha ▸ (sa * s).2), add_comm] congr; ext; exact ha instance instAddCommMonoidOreLocalization : AddCommMonoid X[S⁻¹] where add_comm := OreLocalization.add_comm end AddCommMonoid section AddGroup variable {R : Type*} [Monoid R] {S : Submonoid R} [OreSet S] variable {X : Type*} [AddGroup X] [DistribMulAction R X] /-- Negation on the Ore localization is defined via negation on the numerator. -/ @[irreducible] protected def neg : X[S⁻¹] → X[S⁻¹] := liftExpand (fun (r : X) (s : S) => -r /ₒ s) fun r t s ht => by -- Porting note (https://github.com/leanprover-community/mathlib4/issues/12129): additional beta reduction needed beta_reduce rw [← smul_neg, ← OreLocalization.expand] instance instNegOreLocalization : Neg X[S⁻¹] := ⟨OreLocalization.neg⟩ @[simp] protected theorem neg_def (r : X) (s : S) : -(r /ₒ s) = -r /ₒ s := by with_unfolding_all rfl protected theorem neg_add_cancel (x : X[S⁻¹]) : -x + x = 0 := by induction x with | _ r s; simp /-- `zsmul` of `OreLocalization` -/ @[irreducible] protected def zsmul : ℤ → X[S⁻¹] → X[S⁻¹] := zsmulRec unseal OreLocalization.zsmul in instance instAddGroupOreLocalization : AddGroup X[S⁻¹] where neg_add_cancel := OreLocalization.neg_add_cancel zsmul := OreLocalization.zsmul end AddGroup section AddCommGroup variable {R : Type*} [Monoid R] {S : Submonoid R} [OreSet S] variable {X : Type*} [AddCommGroup X] [DistribMulAction R X] instance : AddCommGroup X[S⁻¹] where __ := inferInstanceAs (AddGroup X[S⁻¹]) __ := inferInstanceAs (AddCommMonoid X[S⁻¹]) end AddCommGroup end OreLocalization
.lake/packages/mathlib/Mathlib/RingTheory/OreLocalization/Cardinality.lean
import Mathlib.GroupTheory.OreLocalization.Cardinality import Mathlib.RingTheory.OreLocalization.Ring /-! # Cardinality of Ore localizations of rings This file contains some results on cardinality of Ore localizations of rings. -/ universe u open Cardinal namespace OreLocalization variable {R : Type u} [Ring R] {S : Submonoid R} [OreLocalization.OreSet S] theorem cardinalMk (hS : S ≤ nonZeroDivisorsLeft R) : #(OreLocalization S R) = #R := le_antisymm (cardinalMk_le S) (mk_le_of_injective (numeratorHom_inj hS)) end OreLocalization
.lake/packages/mathlib/Mathlib/RingTheory/OreLocalization/NonZeroDivisors.lean
import Mathlib.Algebra.GroupWithZero.NonZeroDivisors import Mathlib.RingTheory.OreLocalization.Basic /-! # Ore Localization over nonZeroDivisors in monoids with zeros. -/ open scoped nonZeroDivisors namespace OreLocalization section MonoidWithZero variable {R : Type*} [MonoidWithZero R] {S : Submonoid R} [OreSet S] theorem nontrivial_of_nonZeroDivisorsLeft [Nontrivial R] (hS : S ≤ nonZeroDivisorsLeft R) : Nontrivial R[S⁻¹] := nontrivial_iff.mpr (fun e ↦ one_ne_zero <| hS e 1 (zero_mul _)) theorem nontrivial_of_nonZeroDivisorsRight [Nontrivial R] (hS : S ≤ nonZeroDivisorsRight R) : Nontrivial R[S⁻¹] := nontrivial_iff.mpr (fun e ↦ one_ne_zero <| hS e 1 (mul_zero _)) theorem nontrivial_of_nonZeroDivisors [Nontrivial R] (hS : S ≤ R⁰) : Nontrivial R[S⁻¹] := nontrivial_of_nonZeroDivisorsLeft (hS.trans inf_le_left) variable [Nontrivial R] [OreSet R⁰] instance nontrivial : Nontrivial R[R⁰⁻¹] := nontrivial_of_nonZeroDivisors (refl R⁰) variable [NoZeroDivisors R] open Classical in /-- The inversion of Ore fractions for a ring without zero divisors, satisfying `0⁻¹ = 0` and `(r /ₒ r')⁻¹ = r' /ₒ r` for `r ≠ 0`. -/ @[irreducible] protected noncomputable def inv : R[R⁰⁻¹] → R[R⁰⁻¹] := liftExpand (fun r s => if hr : r = (0 : R) then (0 : R[R⁰⁻¹]) else s /ₒ ⟨r, mem_nonZeroDivisors_of_ne_zero hr⟩) (by intro r t s hst by_cases hr : r = 0 · simp [hr] · by_cases ht : t = 0 · exfalso apply nonZeroDivisors.coe_ne_zero ⟨_, hst⟩ simp [ht] · simp only [hr, ht, dif_neg, not_false_iff, or_self_iff, mul_eq_zero, smul_eq_mul] apply OreLocalization.expand) noncomputable instance inv' : Inv R[R⁰⁻¹] := ⟨OreLocalization.inv⟩ open Classical in protected theorem inv_def {r : R} {s : R⁰} : (r /ₒ s)⁻¹ = if hr : r = (0 : R) then (0 : R[R⁰⁻¹]) else s /ₒ ⟨r, mem_nonZeroDivisors_of_ne_zero hr⟩ := by with_unfolding_all rfl protected theorem mul_inv_cancel (x : R[R⁰⁻¹]) (h : x ≠ 0) : x * x⁻¹ = 1 := by induction x with | _ r s rw [OreLocalization.inv_def, OreLocalization.one_def] have hr : r ≠ 0 := by rintro rfl simp at h simp only [hr] with_unfolding_all apply OreLocalization.mul_inv ⟨r, _⟩ protected theorem inv_zero : (0 : R[R⁰⁻¹])⁻¹ = 0 := by rw [OreLocalization.zero_def, OreLocalization.inv_def] simp noncomputable instance : GroupWithZero R[R⁰⁻¹] where inv_zero := OreLocalization.inv_zero mul_inv_cancel := OreLocalization.mul_inv_cancel end MonoidWithZero section CommMonoidWithZero variable {R : Type*} [CommMonoidWithZero R] [Nontrivial R] [OreSet R⁰] [NoZeroDivisors R] noncomputable instance : CommGroupWithZero R[R⁰⁻¹] where end CommMonoidWithZero end OreLocalization
.lake/packages/mathlib/Mathlib/RingTheory/Finiteness/Subalgebra.lean
import Mathlib.Algebra.Algebra.Subalgebra.Lattice import Mathlib.RingTheory.Finiteness.Basic import Mathlib.RingTheory.Finiteness.Bilinear /-! # Subalgebras that are finitely generated as submodules -/ open Function (Surjective) open Finsupp namespace Subalgebra open Submodule variable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] theorem fg_bot_toSubmodule : (⊥ : Subalgebra R A).toSubmodule.FG := ⟨{1}, by simp [Algebra.toSubmodule_bot, one_eq_span]⟩ instance finite_bot : Module.Finite R (⊥ : Subalgebra R A) := Module.Finite.range (Algebra.linearMap R A) end Subalgebra namespace Submodule theorem fg_unit {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] (I : (Submodule R A)ˣ) : (I : Submodule R A).FG := by obtain ⟨T, T', hT, hT', one_mem⟩ := mem_span_mul_finite_of_mem_mul (I.mul_inv ▸ one_le.mp le_rfl) refine ⟨T, span_eq_of_le _ hT ?_⟩ rw [← one_mul I, ← mul_one (span R (T : Set A))] conv_rhs => rw [← I.inv_mul, ← mul_assoc] grw [← span_le.mpr hT', Units.val_mul, Units.val_one, span_mul_span, one_le.2 one_mem] theorem fg_of_isUnit {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] {I : Submodule R A} (hI : IsUnit I) : I.FG := fg_unit hI.unit section Mul variable {R : Type*} {A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] variable {M N : Submodule R A} theorem FG.mul (hm : M.FG) (hn : N.FG) : (M * N).FG := by rw [mul_eq_map₂]; exact hm.map₂ _ hn theorem FG.pow (h : M.FG) (n : ℕ) : (M ^ n).FG := Nat.recOn n ⟨{1}, by simp [one_eq_span]⟩ fun n ih => by simpa [pow_succ] using ih.mul h end Mul end Submodule
.lake/packages/mathlib/Mathlib/RingTheory/Finiteness/Bilinear.lean
import Mathlib.RingTheory.Finiteness.Defs import Mathlib.Algebra.Module.Submodule.Bilinear /-! # Finitely generated submodules and bilinear maps -/ open Function (Surjective) open Finsupp namespace Submodule section Map₂ variable {R M N P : Type*} variable [CommSemiring R] [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] variable [Module R M] [Module R N] [Module R P] theorem FG.map₂ (f : M →ₗ[R] N →ₗ[R] P) {p : Submodule R M} {q : Submodule R N} (hp : p.FG) (hq : q.FG) : (map₂ f p q).FG := let ⟨sm, hfm, hm⟩ := fg_def.1 hp let ⟨sn, hfn, hn⟩ := fg_def.1 hq fg_def.2 ⟨Set.image2 (fun m n => f m n) sm sn, hfm.image2 _ hfn, map₂_span_span R f sm sn ▸ hm ▸ hn ▸ rfl⟩ end Map₂ end Submodule
.lake/packages/mathlib/Mathlib/RingTheory/Finiteness/Nilpotent.lean
import Mathlib.RingTheory.Finiteness.Basic import Mathlib.RingTheory.Nilpotent.Lemmas /-! # Nilpotent maps on finite modules -/ variable {R M : Type*} [CommSemiring R] [AddCommMonoid M] [Module R M] theorem Module.End.isNilpotent_iff_of_finite [Module.Finite R M] {f : End R M} : IsNilpotent f ↔ ∀ m : M, ∃ n : ℕ, (f ^ n) m = 0 := by refine ⟨fun ⟨n, hn⟩ m ↦ ⟨n, by simp [hn]⟩, fun h ↦ ?_⟩ rcases Module.Finite.fg_top (R := R) (M := M) with ⟨S, hS⟩ choose g hg using h use Finset.sup S g ext m have hm : m ∈ Submodule.span R S := by simp [hS] induction hm using Submodule.span_induction with | mem x hx => exact pow_map_zero_of_le (Finset.le_sup hx) (hg x) | zero => simp | add => simp_all | smul => simp_all namespace Matrix open scoped Matrix variable {ι : Type*} [DecidableEq ι] [Fintype ι] {A : Matrix ι ι R} @[simp] theorem isNilpotent_transpose_iff : IsNilpotent Aᵀ ↔ IsNilpotent A := by simp_rw [IsNilpotent, ← transpose_pow, transpose_eq_zero] theorem isNilpotent_iff : IsNilpotent A ↔ ∀ v, ∃ n : ℕ, A ^ n *ᵥ v = 0 := by simp_rw [← isNilpotent_toLin'_iff, Module.End.isNilpotent_iff_of_finite, ← toLin'_pow, toLin'_apply] theorem isNilpotent_iff_forall_row : IsNilpotent A ↔ ∀ i, ∃ n : ℕ, (A ^ n).row i = 0 := by rw [← isNilpotent_transpose_iff, isNilpotent_iff] refine ⟨fun h i ↦ ?_, fun h v ↦ ?_⟩ · obtain ⟨n, hn⟩ := h (Pi.single i 1) exact ⟨n, by simpa [← transpose_pow] using hn⟩ · choose n hn using h suffices ∀ i, (A ^ ⨆ j, n j) i = 0 from ⟨⨆ j, n j, by simp [mulVec_eq_sum, this]⟩ exact fun i ↦ pow_row_eq_zero_of_le (hn i) (Finite.le_ciSup n i) theorem isNilpotent_iff_forall_col : IsNilpotent A ↔ ∀ i, ∃ n : ℕ, (A ^ n).col i = 0 := by rw [← isNilpotent_transpose_iff, isNilpotent_iff_forall_row] simp_rw [← transpose_pow, row_transpose] end Matrix
.lake/packages/mathlib/Mathlib/RingTheory/Finiteness/ModuleFinitePresentation.lean
import Mathlib.Algebra.Module.FinitePresentation import Mathlib.RingTheory.AdjoinRoot /-! # Finitely presented algebras and finitely presented modules In this file we establish relations between finitely presented as an algebra and finitely presented as a module. ## Main results: - `Algebra.FinitePresentation.of_finitePresentation`: If `S` is finitely presented as a module over `R`, then it is finitely presented as an algebra over `R`. - `Module.FinitePresentation.of_finite_of_finitePresentation`: If `S` is finite as a module over `R` and finitely presented as an algebra over `R`, then it is finitely presented as a module over `R`. ## References - [Grothendieck, EGA IV₁ 1.4.7][ega-iv-1] -/ universe u variable (R : Type u) (S : Type*) [CommRing R] [CommRing S] [Algebra R S] /-- EGA IV₁, 1.4.7.1 -/ lemma Module.Finite.exists_free_surjective [Module.Finite R S] : ∃ (S' : Type u) (_ : CommRing S') (_ : Algebra R S') (_ : Module.Finite R S') (_ : Module.Free R S') (_ : Algebra.FinitePresentation R S') (f : S' →ₐ[R] S), Function.Surjective f := by classical obtain ⟨s, hs⟩ : (⊤ : Submodule R S).FG := Module.finite_def.mp inferInstance suffices h : ∃ (S' : Type u) (_ : CommRing S') (_ : Algebra R S') (_ : Module.Finite R S') (_ : Module.Free R S') (_ : Algebra.FinitePresentation R S') (f : S' →ₐ[R] S), (s : Set S) ⊆ AlgHom.range f by obtain ⟨S', _, _, _, _, _, f, hsf⟩ := h have hf : Function.Surjective f := by have := (Submodule.span_le (p := LinearMap.range f.toLinearMap)).mpr hsf rwa [hs, top_le_iff, LinearMap.range_eq_top] at this use S', ‹_›, ‹_›, ‹_›, ‹_›, ‹_›, f clear hs induction s using Finset.induction with | empty => exact ⟨R, _, _, inferInstance, inferInstance, inferInstance, Algebra.ofId R S, by simp⟩ | insert a s has IH => obtain ⟨S', _, _, _, _, _, f, hsf⟩ := IH have ha := Algebra.IsIntegral.isIntegral (R := R) a have := ((minpoly.monic ha).map (algebraMap R S')).finite_adjoinRoot have := ((minpoly.monic ha).map (algebraMap R S')).free_adjoinRoot algebraize [f.toRingHom] refine ⟨AdjoinRoot ((minpoly R a).map (algebraMap R S')), inferInstance, inferInstance, .trans S' _, .trans (S := S'), .trans _ S' _, (AdjoinRoot.liftAlgHom _ (Algebra.ofId _ _) a (by simp [← Polynomial.aeval_def])).restrictScalars R, ?_⟩ simp only [Finset.coe_insert, AlgHom.coe_range, AlgHom.coe_restrictScalars', Set.insert_subset_iff, Set.mem_range] exact ⟨⟨.root _, by simp⟩, hsf.trans fun y ⟨x, hx⟩ ↦ ⟨.of _ x, by simpa⟩⟩ /-- If `S` is finitely presented as a module over `R`, it is finitely presented as an algebra over `R`. -/ instance Algebra.FinitePresentation.of_finitePresentation [Module.FinitePresentation R S] : Algebra.FinitePresentation R S := by obtain ⟨S', _, _, _, _, _, f, hf⟩ := Module.Finite.exists_free_surjective R S refine .of_surjective hf ?_ apply Submodule.FG.of_restrictScalars R exact Module.FinitePresentation.fg_ker f.toLinearMap hf /-- If `S` is finite as a module over `R` and finitely presented as an algebra over `R`, then it is finitely presented as a module over `R`. -/ @[stacks 0564 "The case M = S"] lemma Module.FinitePresentation.of_finite_of_finitePresentation [Module.Finite R S] [Algebra.FinitePresentation R S] : Module.FinitePresentation R S := by classical obtain ⟨R', _, _, _, _, _, f, hf⟩ := Module.Finite.exists_free_surjective R S letI := f.toRingHom.toAlgebra have : IsScalarTower R R' S := .of_algebraMap_eq' f.comp_algebraMap.symm have : Module.FinitePresentation R R' := Module.finitePresentation_of_projective R R' have : Module.FinitePresentation R' S := Module.finitePresentation_of_surjective (Algebra.linearMap R' S) hf (Algebra.FinitePresentation.ker_fG_of_surjective f hf) exact .trans R S R' /-- If `S` is a finite `R`-algebra, finitely presented as a module and as an algebra is equivalent. -/ lemma Module.FinitePresentation.iff_finitePresentation_of_finite [Module.Finite R S] : Module.FinitePresentation R S ↔ Algebra.FinitePresentation R S := ⟨fun _ ↦ .of_finitePresentation R S, fun _ ↦ .of_finite_of_finitePresentation R S⟩
.lake/packages/mathlib/Mathlib/RingTheory/Finiteness/Nakayama.lean
import Mathlib.RingTheory.Finiteness.Defs import Mathlib.RingTheory.Ideal.Operations /-! # Nakayama's lemma ## Main results * `exists_sub_one_mem_and_smul_eq_zero_of_fg_of_le_smul` is Nakayama's lemma, in the following form: if N is a finitely generated submodule of an ambient R-module M and I is an ideal of R such that N ⊆ IN, then there exists r ∈ 1 + I such that rN = 0. -/ namespace Submodule /-- **Nakayama's Lemma**. Atiyah-Macdonald 2.5, Eisenbud 4.7, Matsumura 2.2. -/ @[stacks 00DV] theorem exists_sub_one_mem_and_smul_eq_zero_of_fg_of_le_smul {R : Type*} [CommRing R] {M : Type*} [AddCommGroup M] [Module R M] (I : Ideal R) (N : Submodule R M) (hn : N.FG) (hin : N ≤ I • N) : ∃ r : R, r - 1 ∈ I ∧ ∀ n ∈ N, r • n = (0 : M) := by rw [fg_def] at hn rcases hn with ⟨s, hfs, hs⟩ have H : ∃ r : R, r - 1 ∈ I ∧ N ≤ (I • span R s).comap (LinearMap.lsmul R M r) ∧ s ⊆ N := by refine ⟨1, ?_, ?_, ?_⟩ · rw [sub_self] exact I.zero_mem · rw [hs] intro n hn rw [mem_comap] change (1 : R) • n ∈ I • N rw [one_smul] exact hin hn · rw [← span_le, hs] clear hin hs induction s, hfs using Set.Finite.induction_on with | empty => rcases H with ⟨r, hr1, hrn, _⟩ refine ⟨r, hr1, fun n hn => ?_⟩ specialize hrn hn rwa [mem_comap, span_empty, smul_bot, mem_bot] at hrn | @insert i s _ _ ih => apply ih rcases H with ⟨r, hr1, hrn, hs⟩ rw [← Set.singleton_union, span_union, smul_sup] at hrn rw [Set.insert_subset_iff] at hs have : ∃ c : R, c - 1 ∈ I ∧ c • i ∈ I • span R s := by specialize hrn hs.1 rw [mem_comap, mem_sup] at hrn rcases hrn with ⟨y, hy, z, hz, hyz⟩ dsimp at hyz rw [mem_smul_span_singleton] at hy rcases hy with ⟨c, hci, rfl⟩ use r - c constructor · rw [sub_right_comm] exact I.sub_mem hr1 hci · rw [sub_smul, ← hyz, add_sub_cancel_left] exact hz rcases this with ⟨c, hc1, hci⟩ refine ⟨c * r, ?_, ?_, hs.2⟩ · simpa only [mul_sub, mul_one, sub_add_sub_cancel] using I.add_mem (I.mul_mem_left c hr1) hc1 · intro n hn specialize hrn hn rw [mem_comap, mem_sup] at hrn rcases hrn with ⟨y, hy, z, hz, hyz⟩ dsimp at hyz rw [mem_smul_span_singleton] at hy rcases hy with ⟨d, _, rfl⟩ simp only [mem_comap, LinearMap.lsmul_apply] rw [mul_smul, ← hyz, smul_add, smul_smul, mul_comm, mul_smul] exact add_mem (smul_mem _ _ hci) (smul_mem _ _ hz) theorem exists_mem_and_smul_eq_self_of_fg_of_le_smul {R : Type*} [CommRing R] {M : Type*} [AddCommGroup M] [Module R M] (I : Ideal R) (N : Submodule R M) (hn : N.FG) (hin : N ≤ I • N) : ∃ r ∈ I, ∀ n ∈ N, r • n = n := by obtain ⟨r, hr, hr'⟩ := exists_sub_one_mem_and_smul_eq_zero_of_fg_of_le_smul I N hn hin exact ⟨-(r - 1), I.neg_mem hr, fun n hn => by simpa [sub_smul] using hr' n hn⟩ end Submodule
.lake/packages/mathlib/Mathlib/RingTheory/Finiteness/Prod.lean
import Mathlib.LinearAlgebra.Prod import Mathlib.RingTheory.Finiteness.Defs /-! # Finitely generated product (sub)modules -/ open Function (Surjective) open Finsupp namespace Submodule variable {R : Type*} {M : Type*} [Semiring R] [AddCommMonoid M] [Module R M] open Set variable {P : Type*} [AddCommMonoid P] [Module R P] theorem FG.prod {sb : Submodule R M} {sc : Submodule R P} (hsb : sb.FG) (hsc : sc.FG) : (sb.prod sc).FG := let ⟨tb, htb⟩ := fg_def.1 hsb let ⟨tc, htc⟩ := fg_def.1 hsc fg_def.2 ⟨LinearMap.inl R M P '' tb ∪ LinearMap.inr R M P '' tc, (htb.1.image _).union (htc.1.image _), by rw [LinearMap.span_inl_union_inr, htb.2, htc.2]⟩ end Submodule namespace Module namespace Finite variable {R M N : Type*} variable [Semiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N] instance prod [hM : Module.Finite R M] [hN : Module.Finite R N] : Module.Finite R (M × N) := ⟨by rw [← Submodule.prod_top] exact hM.1.prod hN.1⟩ end Finite end Module
.lake/packages/mathlib/Mathlib/RingTheory/Finiteness/Basic.lean
import Mathlib.Algebra.Algebra.Tower import Mathlib.Algebra.Order.Nonneg.Module import Mathlib.LinearAlgebra.Pi import Mathlib.LinearAlgebra.Quotient.Defs import Mathlib.RingTheory.Finiteness.Defs /-! # Basic results on finitely generated (sub)modules This file contains the basic results on `Submodule.FG` and `Module.Finite` that do not need heavy further imports. -/ assert_not_exists Module.Basis Ideal.radical Matrix Subalgebra open Function (Surjective) open Finsupp namespace Submodule variable {R : Type*} {M : Type*} [Semiring R] [AddCommMonoid M] [Module R M] open Set theorem fg_bot : (⊥ : Submodule R M).FG := ⟨∅, by rw [Finset.coe_empty, span_empty]⟩ theorem fg_span {s : Set M} (hs : s.Finite) : FG (span R s) := ⟨hs.toFinset, by rw [hs.coe_toFinset]⟩ theorem fg_span_singleton (x : M) : FG (R ∙ x) := fg_span (finite_singleton x) theorem FG.sup {N₁ N₂ : Submodule R M} (hN₁ : N₁.FG) (hN₂ : N₂.FG) : (N₁ ⊔ N₂).FG := let ⟨t₁, ht₁⟩ := fg_def.1 hN₁ let ⟨t₂, ht₂⟩ := fg_def.1 hN₂ fg_def.2 ⟨t₁ ∪ t₂, ht₁.1.union ht₂.1, by rw [span_union, ht₁.2, ht₂.2]⟩ theorem fg_finset_sup {ι : Type*} (s : Finset ι) (N : ι → Submodule R M) (h : ∀ i ∈ s, (N i).FG) : (s.sup N).FG := Finset.sup_induction fg_bot (fun _ ha _ hb => ha.sup hb) h theorem fg_biSup {ι : Type*} (s : Finset ι) (N : ι → Submodule R M) (h : ∀ i ∈ s, (N i).FG) : (⨆ i ∈ s, N i).FG := by simpa only [Finset.sup_eq_iSup] using fg_finset_sup s N h theorem fg_iSup {ι : Sort*} [Finite ι] (N : ι → Submodule R M) (h : ∀ i, (N i).FG) : (iSup N).FG := by cases nonempty_fintype (PLift ι) simpa [iSup_plift_down] using fg_biSup Finset.univ (N ∘ PLift.down) fun i _ => h i.down instance : SemilatticeSup {P : Submodule R M // P.FG} where sup := fun P Q ↦ ⟨P.val ⊔ Q.val, Submodule.FG.sup P.property Q.property⟩ le_sup_left := fun P Q ↦ by rw [← Subtype.coe_le_coe]; exact le_sup_left le_sup_right := fun P Q ↦ by rw [← Subtype.coe_le_coe]; exact le_sup_right sup_le := fun P Q R hPR hQR ↦ by rw [← Subtype.coe_le_coe] at hPR hQR ⊢ exact sup_le hPR hQR instance : Inhabited {P : Submodule R M // P.FG} where default := ⟨⊥, fg_bot⟩ section variable {S P : Type*} [Semiring S] [AddCommMonoid P] [Module S P] variable {σ : R →+* S} [RingHomSurjective σ] (f : M →ₛₗ[σ] P) theorem fg_pi {ι : Type*} {M : ι → Type*} [Finite ι] [∀ i, AddCommMonoid (M i)] [∀ i, Module R (M i)] {p : ∀ i, Submodule R (M i)} (hsb : ∀ i, (p i).FG) : (Submodule.pi Set.univ p).FG := by classical simp_rw [fg_def] at hsb ⊢ choose t htf hts using hsb refine ⟨⋃ i, (LinearMap.single R _ i) '' t i, Set.finite_iUnion fun i => (htf i).image _, ?_⟩ -- Note: https://github.com/leanprover-community/mathlib4/pull/8386 changed `span_image` into `span_image _` simp_rw [span_iUnion, span_image _, hts, Submodule.iSup_map_single] theorem FG.map {N : Submodule R M} (hs : N.FG) : (N.map f).FG := let ⟨t, ht⟩ := fg_def.1 hs fg_def.2 ⟨f '' t, ht.1.image _, by rw [span_image, ht.2]⟩ theorem fg_of_fg_map_injective (hf : Function.Injective f) {N : Submodule R M} (hfn : (N.map f).FG) : N.FG := let ⟨t, ht⟩ := hfn ⟨t.preimage f fun _ _ _ _ h => hf h, Submodule.map_injective_of_injective hf <| by rw [map_span, Finset.coe_preimage, Set.image_preimage_eq_inter_range, Set.inter_eq_self_of_subset_left, ht] rw [← LinearMap.coe_range, ← span_le, ht, ← map_top] exact map_mono le_top⟩ end variable {P : Type*} [AddCommMonoid P] [Module R P] variable {f : M →ₗ[R] P} theorem fg_of_fg_map {R M P : Type*} [Ring R] [AddCommGroup M] [Module R M] [AddCommGroup P] [Module R P] (f : M →ₗ[R] P) (hf : LinearMap.ker f = ⊥) {N : Submodule R M} (hfn : (N.map f).FG) : N.FG := fg_of_fg_map_injective f (LinearMap.ker_eq_bot.1 hf) hfn theorem fg_top (N : Submodule R M) : (⊤ : Submodule R N).FG ↔ N.FG := ⟨fun h => N.range_subtype ▸ map_top N.subtype ▸ h.map _, fun h => fg_of_fg_map_injective N.subtype Subtype.val_injective <| by rwa [map_top, range_subtype]⟩ theorem fg_of_linearEquiv (e : M ≃ₗ[R] P) (h : (⊤ : Submodule R P).FG) : (⊤ : Submodule R M).FG := e.symm.range ▸ map_top (e.symm : P →ₗ[R] M) ▸ h.map _ theorem fg_induction (R M : Type*) [Semiring R] [AddCommMonoid M] [Module R M] (P : Submodule R M → Prop) (h₁ : ∀ x, P (Submodule.span R {x})) (h₂ : ∀ M₁ M₂, P M₁ → P M₂ → P (M₁ ⊔ M₂)) (N : Submodule R M) (hN : N.FG) : P N := by classical obtain ⟨s, rfl⟩ := hN induction s using Finset.induction with | empty => rw [Finset.coe_empty, Submodule.span_empty, ← Submodule.span_zero_singleton] exact h₁ _ | insert _ _ _ ih => rw [Finset.coe_insert, Submodule.span_insert] exact h₂ _ _ (h₁ _) ih theorem fg_restrictScalars {R S M : Type*} [CommSemiring R] [Semiring S] [Algebra R S] [AddCommMonoid M] [Module S M] [Module R M] [IsScalarTower R S M] (N : Submodule S M) (hfin : N.FG) (h : Function.Surjective (algebraMap R S)) : (Submodule.restrictScalars R N).FG := by obtain ⟨X, rfl⟩ := hfin use X exact (Submodule.restrictScalars_span R S h (X : Set M)).symm lemma FG.of_restrictScalars (R) {A M} [Semiring R] [Semiring A] [AddCommMonoid M] [SMul R A] [Module R M] [Module A M] [IsScalarTower R A M] (S : Submodule A M) (hS : (S.restrictScalars R).FG) : S.FG := by obtain ⟨s, e⟩ := hS refine ⟨s, Submodule.restrictScalars_injective R _ _ (le_antisymm ?_ ?_)⟩ · change Submodule.span A s ≤ S have := Submodule.span_le.mp e.le rwa [Submodule.span_le] · rw [← e] exact Submodule.span_le_restrictScalars _ _ _ theorem FG.stabilizes_of_iSup_eq {M' : Submodule R M} (hM' : M'.FG) (N : ℕ →o Submodule R M) (H : iSup N = M') : ∃ n, M' = N n := by obtain ⟨S, hS⟩ := hM' have : ∀ s : S, ∃ n, (s : M) ∈ N n := fun s => (Submodule.mem_iSup_of_chain N s).mp (by rw [H, ← hS] exact Submodule.subset_span s.2) choose f hf using this use S.attach.sup f apply le_antisymm · conv_lhs => rw [← hS] rw [Submodule.span_le] intro s hs exact N.2 (Finset.le_sup <| S.mem_attach ⟨s, hs⟩) (hf _) · rw [← H] exact le_iSup _ _ /-- Finitely generated submodules are precisely compact elements in the submodule lattice. -/ theorem fg_iff_compact (s : Submodule R M) : s.FG ↔ CompleteLattice.IsCompactElement s := by classical -- Introduce shorthand for span of an element let sp : M → Submodule R M := fun a => span R {a} -- Trivial rewrite lemma; a small hack since simp (only) & rw can't accomplish this smoothly. have supr_rw : ∀ t : Finset M, ⨆ x ∈ t, sp x = ⨆ x ∈ (↑t : Set M), sp x := fun t => by rfl constructor · rintro ⟨t, rfl⟩ rw [span_eq_iSup_of_singleton_spans, ← supr_rw, ← Finset.sup_eq_iSup t sp] apply CompleteLattice.isCompactElement_finsetSup exact fun n _ => singleton_span_isCompactElement n · intro h -- s is the Sup of the spans of its elements. have sSup' : s = sSup (sp '' ↑s) := by rw [sSup_eq_iSup, iSup_image, ← span_eq_iSup_of_singleton_spans, eq_comm, span_eq] -- by h, s is then below (and equal to) the sup of the spans of finitely many elements. obtain ⟨u, ⟨huspan, husup⟩⟩ := h (sp '' ↑s) (le_of_eq sSup') have ssup : s = u.sup id := by suffices u.sup id ≤ s from le_antisymm husup this rw [sSup', Finset.sup_id_eq_sSup] exact sSup_le_sSup huspan obtain ⟨t, -, rfl⟩ := Finset.subset_set_image_iff.mp huspan rw [Finset.sup_image, Function.id_comp, Finset.sup_eq_iSup, supr_rw, ← span_eq_iSup_of_singleton_spans, eq_comm] at ssup exact ⟨t, ssup⟩ end Submodule section ModuleAndAlgebra variable (R A B M N : Type*) namespace Module variable [Semiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N] namespace Finite open Submodule Set variable {R M N} instance [Module.Finite R M] : IsCoatomic (Submodule R M) := CompleteLattice.coatomic_of_top_compact <| by rwa [← fg_iff_compact, ← finite_def] -- See note [lower instance priority] instance (priority := 100) of_finite [Finite M] : Module.Finite R M := by cases nonempty_fintype M exact ⟨⟨Finset.univ, by rw [Finset.coe_univ]; exact Submodule.span_univ⟩⟩ section variable {S} {P : Type*} [Semiring S] [AddCommMonoid P] [Module S P] {σ : R →+* S} [RingHomSurjective σ] -- TODO: remove RingHomSurjective theorem of_surjective [hM : Module.Finite R M] (f : M →ₛₗ[σ] P) (hf : Surjective f) : Module.Finite S P := ⟨by rw [← LinearMap.range_eq_top.2 hf, ← Submodule.map_top] exact hM.1.map f⟩ theorem _root_.LinearMap.finite_iff_of_bijective (f : M →ₛₗ[σ] P) (hf : Function.Bijective f) : Module.Finite R M ↔ Module.Finite S P := ⟨fun _ ↦ of_surjective f hf.surjective, fun _ ↦ ⟨fg_of_fg_map_injective f hf.injective <| by rwa [Submodule.map_top, LinearMap.range_eq_top.2 hf.surjective, ← Module.finite_def]⟩⟩ end instance quotient (R) {A M} [Semiring R] [AddCommGroup M] [Ring A] [Module A M] [Module R M] [SMul R A] [IsScalarTower R A M] [Module.Finite R M] (N : Submodule A M) : Module.Finite R (M ⧸ N) := Module.Finite.of_surjective (N.mkQ.restrictScalars R) N.mkQ_surjective /-- The range of a linear map from a finite module is finite. -/ instance range {F : Type*} [FunLike F M N] [SemilinearMapClass F (RingHom.id R) M N] [Module.Finite R M] (f : F) : Module.Finite R (LinearMap.range f) := of_surjective (SemilinearMapClass.semilinearMap f).rangeRestrict fun ⟨_, y, hy⟩ => ⟨y, Subtype.ext hy⟩ /-- Pushforwards of finite submodules are finite. -/ instance map (p : Submodule R M) [Module.Finite R p] (f : M →ₗ[R] N) : Module.Finite R (p.map f) := of_surjective (f.restrict fun _ => Submodule.mem_map_of_mem) fun ⟨_, _, hy, hy'⟩ => ⟨⟨_, hy⟩, Subtype.ext hy'⟩ instance pi {ι : Type*} {M : ι → Type*} [_root_.Finite ι] [∀ i, AddCommMonoid (M i)] [∀ i, Module R (M i)] [h : ∀ i, Module.Finite R (M i)] : Module.Finite R (∀ i, M i) := ⟨by rw [← Submodule.pi_top] exact Submodule.fg_pi fun i => (h i).1⟩ theorem of_pi {ι : Type*} (M : ι → Type*) [∀ i, AddCommMonoid (M i)] [∀ i, Module R (M i)] [Module.Finite R (∀ i, M i)] (i : ι) : Module.Finite R (M i) := Module.Finite.of_surjective _ <| LinearMap.proj_surjective i theorem pi_iff {ι : Type*} {M : ι → Type*} [_root_.Finite ι] [∀ i, AddCommMonoid (M i)] [∀ i, Module R (M i)] : Module.Finite R (∀ i, M i) ↔ ∀ i, Module.Finite R (M i) := ⟨fun _ i => of_pi M i, fun _ => inferInstance⟩ variable (R) theorem _root_.Ideal.fg_top : (⊤ : Ideal R).FG := ⟨{1}, by simpa only [Finset.coe_singleton] using Ideal.span_singleton_one⟩ instance self : Module.Finite R R := ⟨Ideal.fg_top R⟩ variable (M) theorem of_restrictScalars_finite (R A M : Type*) [Semiring R] [Semiring A] [AddCommMonoid M] [Module R M] [Module A M] [SMul R A] [IsScalarTower R A M] [hM : Module.Finite R M] : Module.Finite A M := by rw [finite_def, Submodule.fg_def] at hM ⊢ obtain ⟨S, hSfin, hSgen⟩ := hM refine ⟨S, hSfin, eq_top_iff.2 ?_⟩ have := Submodule.span_le_restrictScalars R A S rwa [hSgen] at this variable {R M} theorem equiv [Module.Finite R M] (e : M ≃ₗ[R] N) : Module.Finite R N := of_surjective (e : M →ₗ[R] N) e.surjective theorem equiv_iff (e : M ≃ₗ[R] N) : Module.Finite R M ↔ Module.Finite R N := ⟨fun _ ↦ equiv e, fun _ ↦ equiv e.symm⟩ instance [Module.Finite R M] : Module.Finite R Mᵐᵒᵖ := equiv (MulOpposite.opLinearEquiv R) instance ulift [Module.Finite R M] : Module.Finite R (ULift M) := equiv ULift.moduleEquiv.symm theorem iff_fg {N : Submodule R M} : Module.Finite R N ↔ N.FG := Module.finite_def.trans N.fg_top variable (R M) instance bot : Module.Finite R (⊥ : Submodule R M) := iff_fg.mpr fg_bot instance top [Module.Finite R M] : Module.Finite R (⊤ : Submodule R M) := iff_fg.mpr fg_top variable {M} /-- The submodule generated by a finite set is `R`-finite. -/ theorem span_of_finite {A : Set M} (hA : Set.Finite A) : Module.Finite R (Submodule.span R A) := ⟨(Submodule.fg_top _).mpr ⟨hA.toFinset, hA.coe_toFinset.symm ▸ rfl⟩⟩ /-- The submodule generated by a single element is `R`-finite. -/ instance span_singleton (x : M) : Module.Finite R (R ∙ x) := Module.Finite.span_of_finite R <| Set.finite_singleton _ /-- The submodule generated by a finset is `R`-finite. -/ instance span_finset (s : Finset M) : Module.Finite R (span R (s : Set M)) := ⟨(Submodule.fg_top _).mpr ⟨s, rfl⟩⟩ variable {R} section Algebra theorem trans {R : Type*} (A M : Type*) [Semiring R] [Semiring A] [Module R A] [AddCommMonoid M] [Module R M] [Module A M] [IsScalarTower R A M] : ∀ [Module.Finite R A] [Module.Finite A M], Module.Finite R M | ⟨⟨s, hs⟩⟩, ⟨⟨t, ht⟩⟩ => ⟨Submodule.fg_def.2 ⟨Set.image2 (· • ·) (↑s : Set A) (↑t : Set M), Set.Finite.image2 _ s.finite_toSet t.finite_toSet, by rw [Set.image2_smul, Submodule.span_smul_of_span_eq_top hs (↑t : Set M), ht, Submodule.restrictScalars_top]⟩⟩ lemma of_equiv_equiv {A₁ B₁ A₂ B₂ : Type*} [CommSemiring A₁] [CommSemiring B₁] [CommSemiring A₂] [Semiring B₂] [Algebra A₁ B₁] [Algebra A₂ B₂] (e₁ : A₁ ≃+* A₂) (e₂ : B₁ ≃+* B₂) (he : RingHom.comp (algebraMap A₂ B₂) ↑e₁ = RingHom.comp ↑e₂ (algebraMap A₁ B₁)) [Module.Finite A₁ B₁] : Module.Finite A₂ B₂ := by letI := e₁.toRingHom.toAlgebra letI := ((algebraMap A₁ B₁).comp e₁.symm.toRingHom).toAlgebra haveI : IsScalarTower A₁ A₂ B₁ := IsScalarTower.of_algebraMap_eq (fun x ↦ by simp [RingHom.algebraMap_toAlgebra]) let e : B₁ ≃ₐ[A₂] B₂ := { e₂ with commutes' := fun r ↦ by simpa [RingHom.algebraMap_toAlgebra] using DFunLike.congr_fun he.symm (e₁.symm r) } haveI := Module.Finite.of_restrictScalars_finite A₁ A₂ B₁ exact Module.Finite.equiv e.toLinearEquiv end Algebra end Finite end Module end ModuleAndAlgebra namespace Submodule open Module variable {R V} [Ring R] [AddCommGroup V] [Module R V] /-- The sup of two fg submodules is finite. Also see `Submodule.FG.sup`. -/ instance finite_sup (S₁ S₂ : Submodule R V) [h₁ : Module.Finite R S₁] [h₂ : Module.Finite R S₂] : Module.Finite R (S₁ ⊔ S₂ : Submodule R V) := by rw [finite_def] at * exact (fg_top _).2 (((fg_top S₁).1 h₁).sup ((fg_top S₂).1 h₂)) /-- The submodule generated by a finite supremum of finite-dimensional submodules is finite-dimensional. Note that strictly this only needs `∀ i ∈ s, FiniteDimensional K (S i)`, but that doesn't work well with typeclass search. -/ instance finite_finset_sup {ι : Type*} (s : Finset ι) (S : ι → Submodule R V) [∀ i, Module.Finite R (S i)] : Module.Finite R (s.sup S : Submodule R V) := by refine @Finset.sup_induction _ _ _ _ s S (fun i => Module.Finite R ↑i) (Module.Finite.bot R V) ?_ fun i _ => by infer_instance intro S₁ hS₁ S₂ hS₂ exact Submodule.finite_sup S₁ S₂ end Submodule namespace RingHom variable {A B C : Type*} [CommRing A] [CommRing B] [CommRing C] namespace Finite variable (A) in theorem id : Finite (RingHom.id A) := Module.Finite.self A theorem of_surjective (f : A →+* B) (hf : Surjective f) : f.Finite := letI := f.toAlgebra Module.Finite.of_surjective (Algebra.linearMap A B) hf theorem comp {g : B →+* C} {f : A →+* B} (hg : g.Finite) (hf : f.Finite) : (g.comp f).Finite := by algebraize [f, g, g.comp f] exact Module.Finite.trans B C theorem of_comp_finite {f : A →+* B} {g : B →+* C} (h : (g.comp f).Finite) : g.Finite := by algebraize [f, g, g.comp f] exact Module.Finite.of_restrictScalars_finite A B C end Finite end RingHom namespace AlgHom variable {R A B C : Type*} [CommRing R] variable [CommRing A] [CommRing B] [CommRing C] variable [Algebra R A] [Algebra R B] [Algebra R C] namespace Finite variable (R A) theorem id : Finite (AlgHom.id R A) := RingHom.Finite.id A variable {R A} theorem comp {g : B →ₐ[R] C} {f : A →ₐ[R] B} (hg : g.Finite) (hf : f.Finite) : (g.comp f).Finite := RingHom.Finite.comp hg hf theorem of_surjective (f : A →ₐ[R] B) (hf : Surjective f) : f.Finite := RingHom.Finite.of_surjective f.toRingHom hf theorem of_comp_finite {f : A →ₐ[R] B} {g : B →ₐ[R] C} (h : (g.comp f).Finite) : g.Finite := RingHom.Finite.of_comp_finite h end Finite end AlgHom section Ring variable {R E : Type*} [Ring R] [LinearOrder R] [IsOrderedRing R] [AddCommMonoid E] [Module R E] local notation3 "R≥0" => {c : R // 0 ≤ c} private instance instModuleFiniteAux : Module.Finite R≥0 R := by simp_rw [Module.finite_def, Submodule.fg_def, Submodule.eq_top_iff'] refine ⟨{1, -1}, by simp, fun x ↦ ?_⟩ obtain hx | hx := le_total 0 x · simpa using Submodule.smul_mem (M := R) (.span R≥0 {1, -1}) ⟨x, hx⟩ (x := 1) (Submodule.subset_span <| by simp) · simpa using Submodule.smul_mem (M := R) (.span R≥0 {1, -1}) ⟨-x, neg_nonneg.2 hx⟩ (x := -1) (Submodule.subset_span <| by simp) /-- If a module is finite over a linearly ordered ring, then it is also finite over the non-negative scalars. -/ instance instModuleFinite [Module.Finite R E] : Module.Finite R≥0 E := .trans R E end Ring
.lake/packages/mathlib/Mathlib/RingTheory/Finiteness/Cardinality.lean
import Mathlib.Algebra.Module.Congruence.Defs import Mathlib.LinearAlgebra.Basis.Cardinality import Mathlib.LinearAlgebra.DFinsupp import Mathlib.LinearAlgebra.Isomorphisms import Mathlib.LinearAlgebra.StdBasis import Mathlib.RingTheory.Finiteness.Basic /-! # Finite modules and types with finitely many elements This file relates `Module.Finite` and `_root_.Finite`. -/ open Function (Surjective) open Finsupp section ModuleAndAlgebra variable (R M : Type*) [Semiring R] [AddCommMonoid M] [Module R M] open Module in theorem Submodule.fg_iff_exists_fin_linearMap {N : Submodule R M} : N.FG ↔ ∃ (n : ℕ) (f : (Fin n → R) →ₗ[R] M), LinearMap.range f = N := by simp_rw [fg_iff_exists_fin_generating_family, ← ((Pi.basisFun R _).constr ℕ).exists_congr_right] simp [Basis.constr_range] theorem AddSubmonoid.fg_iff_exists_fin_addMonoidHom {M : Type*} [AddCommMonoid M] {S : AddSubmonoid M} : S.FG ↔ ∃ (n : ℕ) (f : (Fin n → ℕ) →+ M), AddMonoidHom.mrange f = S := by rw [← S.toNatSubmodule_toAddSubmonoid, ← Submodule.fg_iff_addSubmonoid_fg, Submodule.fg_iff_exists_fin_linearMap] exact exists_congr fun n => ⟨fun ⟨f, hf⟩ => ⟨f, hf ▸ LinearMap.range_toAddSubmonoid _⟩, fun ⟨f, hf⟩ => ⟨f.toNatLinearMap, Submodule.toAddSubmonoid_inj.mp <| hf ▸ LinearMap.range_toAddSubmonoid _⟩⟩ theorem AddSubgroup.fg_iff_exists_fin_addMonoidHom {M : Type*} [AddCommGroup M] {H : AddSubgroup M} : H.FG ↔ ∃ (n : ℕ) (f : (Fin n → ℤ) →+ M), AddMonoidHom.range f = H := by rw [← H.toIntSubmodule_toAddSubgroup, ← Submodule.fg_iff_addSubgroup_fg, Submodule.fg_iff_exists_fin_linearMap] refine exists_congr fun n => ⟨fun ⟨f, hf⟩ => ⟨f, hf ▸ LinearMap.range_toAddSubgroup _⟩, fun ⟨f, hf⟩ => ⟨f.toIntLinearMap, Submodule.toAddSubmonoid_inj.mp ?_⟩⟩ simp [hf] namespace Module namespace Finite open Submodule Set /-- A finite module admits a surjective linear map from a finite free module. -/ lemma exists_fin' [Module.Finite R M] : ∃ (n : ℕ) (f : (Fin n → R) →ₗ[R] M), Surjective f := have ⟨n, f, hf⟩ := (Submodule.fg_iff_exists_fin_linearMap R M).mp fg_top ⟨n, f, by rw [← LinearMap.range_eq_top, hf]⟩ /-- A finite module can be realised as a quotient of `Fin n → R` (i.e. `R^n`). -/ theorem exists_fin_quot_equiv (R M : Type*) [Ring R] [AddCommGroup M] [Module R M] [Module.Finite R M] : ∃ (n : ℕ) (S : Submodule R (Fin n → R)), Nonempty ((_ ⧸ S) ≃ₗ[R] M) := let ⟨n, f, hf⟩ := Module.Finite.exists_fin' R M ⟨n, LinearMap.ker f, ⟨f.quotKerEquivOfSurjective hf⟩⟩ variable {M} lemma _root_.Module.finite_of_finite [Finite R] [Module.Finite R M] : Finite M := by obtain ⟨n, f, hf⟩ := exists_fin' R M; exact .of_surjective f hf variable {R} /-- A module over a finite ring has finite dimension iff it is finite. -/ lemma _root_.Module.finite_iff_finite [Finite R] : Module.Finite R M ↔ Finite M := ⟨fun _ ↦ finite_of_finite R, fun _ ↦ .of_finite⟩ variable (R) in lemma _root_.Set.Finite.submoduleSpan [Finite R] {s : Set M} (hs : s.Finite) : (Submodule.span R s : Set M).Finite := by lift s to Finset M using hs rw [Set.Finite, ← Module.finite_iff_finite (R := R)] dsimp infer_instance /-- If a free module is finite, then any arbitrary basis is finite. -/ lemma finite_basis [Nontrivial R] {ι} [Module.Finite R M] (b : Basis ι R M) : _root_.Finite ι := let ⟨s, hs⟩ := ‹Module.Finite R M› basis_finite_of_finite_spans s.finite_toSet hs b end Finite variable {R M} lemma not_finite_of_infinite_basis [Nontrivial R] {ι} [Infinite ι] (b : Basis ι R M) : ¬ Module.Finite R M := fun _ ↦ (Finite.finite_basis b).not_infinite ‹_› end Module end ModuleAndAlgebra namespace Module.Finite universe u variable (R : Type u) (M : Type*) section Ring variable [Ring R] [AddCommGroup M] [Module R M] [Module.Finite R M] /-- The kernel of a random surjective linear map from a finite free module to a given finite module. -/ noncomputable def kerRepr := LinearMap.ker (Finite.exists_fin' R M).choose_spec.choose /-- A representative of a finite module in the same universe as the ring. -/ protected abbrev repr : Type u := _ ⧸ kerRepr R M /-- The representative is isomorphic to the original module. -/ noncomputable def reprEquiv : Finite.repr R M ≃ₗ[R] M := LinearMap.quotKerEquivOfSurjective _ (Finite.exists_fin' R M).choose_spec.choose_spec end Ring section Semiring variable [Semiring R] [AddCommMonoid M] [Module R M] [Module.Finite R M] /-- The kernel (as a congruence relation) of a random surjective linear map from a finite free module to a given finite module. -/ noncomputable def kerReprₛ := ModuleCon.ker (Finite.exists_fin' R M).choose_spec.choose.toDistribMulActionHom /-- A representative of a finite module in the same universe as the semiring. -/ protected abbrev reprₛ : Type u := (kerReprₛ R M).Quotient /-- The representative is isomorphic to the original module. -/ noncomputable def reprEquivₛ : Finite.reprₛ R M ≃ₗ[R] M := ModuleCon.quotientKerEquivOfSurjective _ (Finite.exists_fin' R M).choose_spec.choose_spec end Semiring end Module.Finite
.lake/packages/mathlib/Mathlib/RingTheory/Finiteness/Quotient.lean
import Mathlib.Algebra.Group.Subgroup.Actions import Mathlib.RingTheory.FiniteType import Mathlib.RingTheory.Ideal.Pointwise import Mathlib.RingTheory.Ideal.Over /-! # Finiteness of quotient modules -/ variable {A B : Type*} [CommRing A] [CommRing B] [Algebra A B] variable (P : Ideal B) (p : Ideal A) [P.LiesOver p] /-- `B ⧸ P` is a finite `A ⧸ p`-module if `B` is a finite `A`-module. -/ instance module_finite_of_liesOver [Module.Finite A B] : Module.Finite (A ⧸ p) (B ⧸ P) := Module.Finite.of_restrictScalars_finite A (A ⧸ p) (B ⧸ P) example [Module.Finite A B] : Module.Finite (A ⧸ P.under A) (B ⧸ P) := inferInstance /-- `B ⧸ P` is a finitely generated `A ⧸ p`-algebra if `B` is a finitely generated `A`-algebra. -/ instance algebra_finiteType_of_liesOver [Algebra.FiniteType A B] : Algebra.FiniteType (A ⧸ p) (B ⧸ P) := Algebra.FiniteType.of_restrictScalars_finiteType A (A ⧸ p) (B ⧸ P) /-- `B ⧸ P` is a Noetherian `A ⧸ p`-module if `B` is a Noetherian `A`-module. -/ instance isNoetherian_of_liesOver [IsNoetherian A B] : IsNoetherian (A ⧸ p) (B ⧸ P) := isNoetherian_of_tower A inferInstance instance QuotientMapQuotient.isNoetherian [IsNoetherian A B] : IsNoetherian (A ⧸ p) (B ⧸ p.map (algebraMap A B)) := isNoetherian_of_tower A <| isNoetherian_of_surjective B (Ideal.Quotient.mkₐ A _).toLinearMap <| LinearMap.range_eq_top.mpr Ideal.Quotient.mk_surjective
.lake/packages/mathlib/Mathlib/RingTheory/Finiteness/Ideal.lean
import Mathlib.Algebra.Group.Pointwise.Finset.Scalar import Mathlib.RingTheory.Finiteness.Finsupp import Mathlib.RingTheory.Ideal.Maps /-! # Finitely generated ideals Lemmas about finiteness of ideal operations. -/ open Function (Surjective) open Finsupp namespace Ideal variable {R : Type*} {M : Type*} [Semiring R] [AddCommMonoid M] [Module R M] /-- The image of a finitely generated ideal is finitely generated. This is the `Ideal` version of `Submodule.FG.map`. -/ theorem FG.map {R S : Type*} [Semiring R] [Semiring S] {I : Ideal R} (h : I.FG) (f : R →+* S) : (I.map f).FG := by classical obtain ⟨s, hs⟩ := h refine ⟨s.image f, ?_⟩ rw [Finset.coe_image, ← Ideal.map_span, hs] theorem fg_ker_comp {R S A : Type*} [CommRing R] [CommRing S] [CommRing A] (f : R →+* S) (g : S →+* A) (hf : (RingHom.ker f).FG) (hg : (RingHom.ker g).FG) (hsur : Function.Surjective f) : (RingHom.ker (g.comp f)).FG := by letI : Algebra R S := RingHom.toAlgebra f letI : Algebra R A := RingHom.toAlgebra (g.comp f) letI : Algebra S A := RingHom.toAlgebra g letI : IsScalarTower R S A := IsScalarTower.of_algebraMap_eq fun _ => rfl let f₁ := Algebra.linearMap R S let g₁ := (IsScalarTower.toAlgHom R S A).toLinearMap exact Submodule.fg_ker_comp f₁ g₁ hf (Submodule.fg_restrictScalars (RingHom.ker g) hg hsur) hsur theorem exists_radical_pow_le_of_fg {R : Type*} [CommSemiring R] (I : Ideal R) (h : I.radical.FG) : ∃ n : ℕ, I.radical ^ n ≤ I := by have := le_refl I.radical; revert this refine Submodule.fg_induction _ _ (fun J => J ≤ I.radical → ∃ n : ℕ, J ^ n ≤ I) ?_ ?_ _ h · intro x hx obtain ⟨n, hn⟩ := hx (subset_span (Set.mem_singleton x)) exact ⟨n, by rwa [← Ideal.span, span_singleton_pow, span_le, Set.singleton_subset_iff]⟩ · intro J K hJ hK hJK obtain ⟨n, hn⟩ := hJ fun x hx => hJK <| Ideal.mem_sup_left hx obtain ⟨m, hm⟩ := hK fun x hx => hJK <| Ideal.mem_sup_right hx use n + m rw [← Ideal.add_eq_sup, add_pow, Ideal.sum_eq_sup, Finset.sup_le_iff] refine fun i _ => Ideal.mul_le_right.trans ?_ obtain h | h := le_or_gt n i · apply Ideal.mul_le_right.trans ((Ideal.pow_le_pow_right h).trans hn) · apply Ideal.mul_le_left.trans refine (Ideal.pow_le_pow_right ?_).trans hm rw [add_comm, Nat.add_sub_assoc h.le] apply Nat.le_add_right theorem exists_pow_le_of_le_radical_of_fg_radical {R : Type*} [CommSemiring R] {I J : Ideal R} (hIJ : I ≤ J.radical) (hJ : J.radical.FG) : ∃ k : ℕ, I ^ k ≤ J := by obtain ⟨k, hk⟩ := J.exists_radical_pow_le_of_fg hJ use k calc I ^ k ≤ J.radical ^ k := Ideal.pow_right_mono hIJ _ _ ≤ J := hk lemma exists_pow_le_of_le_radical_of_fg {R : Type*} [CommSemiring R] {I J : Ideal R} (h' : I ≤ J.radical) (h : I.FG) : ∃ n : ℕ, I ^ n ≤ J := by revert h' apply Submodule.fg_induction _ _ _ _ _ I h · intro x hJ simp only [Ideal.submodule_span_eq, Ideal.span_le, Set.singleton_subset_iff, SetLike.mem_coe] at hJ obtain ⟨n, hn⟩ := hJ refine ⟨n, by simpa [Ideal.span_singleton_pow, Ideal.span_le]⟩ · intro I₁ I₂ h₁ h₂ hJ obtain ⟨n₁, hn₁⟩ := h₁ (le_sup_left.trans hJ) obtain ⟨n₂, hn₂⟩ := h₂ (le_sup_right.trans hJ) use n₁ + n₂ exact Ideal.sup_pow_add_le_pow_sup_pow.trans (sup_le hn₁ hn₂) theorem _root_.Submodule.FG.smul {I : Ideal R} [I.IsTwoSided] {N : Submodule R M} (hI : I.FG) (hN : N.FG) : (I • N).FG := by obtain ⟨s, rfl⟩ := hI obtain ⟨t, rfl⟩ := hN classical rw [Submodule.span_smul_span, ← s.coe_smul] exact ⟨_, rfl⟩ theorem FG.mul {I J : Ideal R} [I.IsTwoSided] (hI : I.FG) (hJ : J.FG) : (I * J).FG := Submodule.FG.smul hI hJ theorem FG.pow {I : Ideal R} [I.IsTwoSided] {n : ℕ} (hI : I.FG) : (I ^ n).FG := n.rec (by rw [I.pow_zero, one_eq_top]; exact fg_top R) fun n ih ↦ by rw [IsTwoSided.pow_succ]; exact hI.mul ih end Ideal
.lake/packages/mathlib/Mathlib/RingTheory/Finiteness/Defs.lean
import Mathlib.Algebra.Algebra.Hom import Mathlib.Data.Set.Finite.Lemmas import Mathlib.Data.Finsupp.Defs import Mathlib.GroupTheory.Finiteness import Mathlib.RingTheory.Ideal.Span import Mathlib.Tactic.Algebraize /-! # Finiteness conditions in commutative algebra In this file we define a notion of finiteness that is common in commutative algebra. ## Main declarations - `Submodule.FG`, `Ideal.FG` These express that some object is finitely generated as *submodule* over some base ring. - `Module.Finite`, `RingHom.Finite`, `AlgHom.Finite` all of these express that some object is finitely generated *as module* over some base ring. -/ assert_not_exists Module.Basis Ideal.radical Matrix Subalgebra open Function (Surjective) open Finsupp namespace Submodule variable {R : Type*} {M : Type*} [Semiring R] [AddCommMonoid M] [Module R M] open Set /-- A submodule of `M` is finitely generated if it is the span of a finite subset of `M`. -/ def FG (N : Submodule R M) : Prop := ∃ S : Finset M, Submodule.span R ↑S = N theorem fg_def {N : Submodule R M} : N.FG ↔ ∃ S : Set M, S.Finite ∧ span R S = N := ⟨fun ⟨t, h⟩ => ⟨_, Finset.finite_toSet t, h⟩, by rintro ⟨t', h, rfl⟩ rcases Finite.exists_finset_coe h with ⟨t, rfl⟩ exact ⟨t, rfl⟩⟩ theorem fg_iff_addSubmonoid_fg (P : Submodule ℕ M) : P.FG ↔ P.toAddSubmonoid.FG := ⟨fun ⟨S, hS⟩ => ⟨S, by simpa [← span_nat_eq_addSubmonoidClosure] using hS⟩, fun ⟨S, hS⟩ => ⟨S, by simpa [← span_nat_eq_addSubmonoidClosure] using hS⟩⟩ theorem fg_iff_addSubgroup_fg {G : Type*} [AddCommGroup G] (P : Submodule ℤ G) : P.FG ↔ P.toAddSubgroup.FG := ⟨fun ⟨S, hS⟩ => ⟨S, by simpa [← span_int_eq_addSubgroupClosure] using hS⟩, fun ⟨S, hS⟩ => ⟨S, by simpa [← span_int_eq_addSubgroupClosure] using hS⟩⟩ @[deprecated (since := "2025-08-20")] alias fg_iff_add_subgroup_fg := fg_iff_addSubgroup_fg theorem fg_iff_exists_fin_generating_family {N : Submodule R M} : N.FG ↔ ∃ (n : ℕ) (s : Fin n → M), span R (range s) = N := by rw [fg_def] constructor · rintro ⟨S, Sfin, hS⟩ obtain ⟨n, f, rfl⟩ := Sfin.fin_embedding exact ⟨n, f, hS⟩ · rintro ⟨n, s, hs⟩ exact ⟨range s, finite_range s, hs⟩ universe w v u in lemma fg_iff_exists_finite_generating_family {A : Type u} [Semiring A] {M : Type v} [AddCommMonoid M] [Module A M] {N : Submodule A M} : N.FG ↔ ∃ (G : Type w) (_ : Finite G) (g : G → M), Submodule.span A (Set.range g) = N := by constructor · intro hN obtain ⟨n, f, h⟩ := Submodule.fg_iff_exists_fin_generating_family.1 hN refine ⟨ULift (Fin n), inferInstance, f ∘ ULift.down, ?_⟩ convert h ext x simp only [Set.mem_range, Function.comp_apply, ULift.exists] · rintro ⟨G, _, g, hg⟩ have := Fintype.ofFinite (range g) exact ⟨(range g).toFinset, by simpa using hg⟩ theorem fg_span_iff_fg_span_finset_subset (s : Set M) : (span R s).FG ↔ ∃ s' : Finset M, ↑s' ⊆ s ∧ span R s = span R s' := by unfold FG constructor · intro ⟨s'', hs''⟩ obtain ⟨s', hs's, hss'⟩ := subset_span_finite_of_subset_span <| hs'' ▸ subset_span refine ⟨s', hs's, ?_⟩ apply le_antisymm · rwa [← hs'', Submodule.span_le] · rw [Submodule.span_le] exact le_trans hs's subset_span · intro ⟨s', _, h⟩ exact ⟨s', h.symm⟩ end Submodule namespace Ideal variable {R : Type*} {M : Type*} [Semiring R] [AddCommMonoid M] [Module R M] /-- An ideal of `R` is finitely generated if it is the span of a finite subset of `R`. This is defeq to `Submodule.FG`, but unfolds more nicely. -/ def FG (I : Ideal R) : Prop := ∃ S : Finset R, Ideal.span ↑S = I end Ideal section ModuleAndAlgebra variable (R A B M N : Type*) /-- A module over a semiring is `Module.Finite` if it is finitely generated as a module. -/ protected class Module.Finite [Semiring R] [AddCommMonoid M] [Module R M] : Prop where fg_top : (⊤ : Submodule R M).FG attribute [inherit_doc Module.Finite] Module.Finite.fg_top namespace Module variable [Semiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N] theorem finite_def {R M} [Semiring R] [AddCommMonoid M] [Module R M] : Module.Finite R M ↔ (⊤ : Submodule R M).FG := ⟨fun h => h.1, fun h => ⟨h⟩⟩ namespace Finite open Submodule Set theorem iff_addMonoid_fg {M : Type*} [AddCommMonoid M] : Module.Finite ℕ M ↔ AddMonoid.FG M := ⟨fun h => AddMonoid.fg_def.2 <| (Submodule.fg_iff_addSubmonoid_fg ⊤).1 (finite_def.1 h), fun h => finite_def.2 <| (Submodule.fg_iff_addSubmonoid_fg ⊤).2 (AddMonoid.fg_def.1 h)⟩ theorem iff_addGroup_fg {G : Type*} [AddCommGroup G] : Module.Finite ℤ G ↔ AddGroup.FG G := ⟨fun h => AddGroup.fg_def.2 <| (Submodule.fg_iff_addSubgroup_fg ⊤).1 (finite_def.1 h), fun h => finite_def.2 <| (Submodule.fg_iff_addSubgroup_fg ⊤).2 (AddGroup.fg_def.1 h)⟩ variable {R M N} /-- See also `Module.Finite.exists_fin'`. -/ lemma exists_fin [Module.Finite R M] : ∃ (n : ℕ) (s : Fin n → M), Submodule.span R (range s) = ⊤ := Submodule.fg_iff_exists_fin_generating_family.mp fg_top end Finite end Module instance AddMonoid.FG.to_moduleFinite_nat {M : Type*} [AddCommMonoid M] [FG M] : Module.Finite ℕ M := Module.Finite.iff_addMonoid_fg.mpr ‹_› instance AddMonoid.FG.to_moduleFinite_int {G : Type*} [AddCommGroup G] [FG G] : Module.Finite ℤ G := Module.Finite.iff_addGroup_fg.mpr <| AddGroup.fg_iff_addMonoid_fg.mpr ‹_› end ModuleAndAlgebra namespace RingHom variable {A B C : Type*} [CommRing A] [CommRing B] [CommRing C] /-- A ring morphism `A →+* B` is `RingHom.Finite` if `B` is finitely generated as `A`-module. -/ @[algebraize Module.Finite, stacks 0563] def Finite (f : A →+* B) : Prop := letI : Algebra A B := f.toAlgebra Module.Finite A B @[simp] lemma finite_algebraMap [Algebra A B] : (algebraMap A B).Finite ↔ Module.Finite A B := by rw [RingHom.Finite, toAlgebra_algebraMap] end RingHom namespace AlgHom variable {R A B C : Type*} [CommRing R] variable [CommRing A] [CommRing B] [CommRing C] variable [Algebra R A] [Algebra R B] [Algebra R C] /-- An algebra morphism `A →ₐ[R] B` is finite if it is finite as ring morphism. In other words, if `B` is finitely generated as `A`-module. -/ def Finite (f : A →ₐ[R] B) : Prop := f.toRingHom.Finite end AlgHom
.lake/packages/mathlib/Mathlib/RingTheory/Finiteness/Finsupp.lean
import Mathlib.Algebra.FreeAbelianGroup.Finsupp import Mathlib.Algebra.MonoidAlgebra.Module import Mathlib.LinearAlgebra.Finsupp.LinearCombination import Mathlib.LinearAlgebra.Quotient.Basic import Mathlib.RingTheory.Finiteness.Basic /-! # Finiteness of (sub)modules and finitely supported functions -/ open Function (Surjective) open Finsupp namespace Submodule variable {R M N P : Type*} [Ring R] [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N] [AddCommGroup P] [Module R P] open Set /-- If 0 → M' → M → M'' → 0 is exact and M' and M'' are finitely generated then so is M. -/ theorem fg_of_fg_map_of_fg_inf_ker (f : M →ₗ[R] P) {s : Submodule R M} (hs1 : (s.map f).FG) (hs2 : (s ⊓ LinearMap.ker f).FG) : s.FG := by haveI := Classical.decEq R haveI := Classical.decEq M haveI := Classical.decEq P obtain ⟨t1, ht1⟩ := hs1 obtain ⟨t2, ht2⟩ := hs2 have : ∀ y ∈ t1, ∃ x ∈ s, f x = y := by intro y hy have : y ∈ s.map f := by rw [← ht1] exact subset_span hy rcases mem_map.1 this with ⟨x, hx1, hx2⟩ exact ⟨x, hx1, hx2⟩ have : ∃ g : P → M, ∀ y ∈ t1, g y ∈ s ∧ f (g y) = y := by choose g hg1 hg2 using this exists fun y => if H : y ∈ t1 then g y H else 0 intro y H constructor · simp only [dif_pos H] apply hg1 · simp only [dif_pos H] apply hg2 obtain ⟨g, hg⟩ := this clear this exists t1.image g ∪ t2 rw [Finset.coe_union, span_union, Finset.coe_image] apply le_antisymm · refine sup_le (span_le.2 <| image_subset_iff.2 ?_) (span_le.2 ?_) · intro y hy exact (hg y hy).1 · intro x hx have : x ∈ span R t2 := subset_span hx rw [ht2] at this exact this.1 intro x hx have : f x ∈ s.map f := by rw [mem_map] exact ⟨x, hx, rfl⟩ rw [← ht1, ← Set.image_id (t1 : Set P), Finsupp.mem_span_image_iff_linearCombination] at this rcases this with ⟨l, hl1, hl2⟩ refine mem_sup.2 ⟨(linearCombination R id).toFun ((lmapDomain R R g : (P →₀ R) → M →₀ R) l), ?_, x - linearCombination R id ((lmapDomain R R g : (P →₀ R) → M →₀ R) l), ?_, add_sub_cancel _ _⟩ · rw [← Set.image_id (g '' ↑t1), Finsupp.mem_span_image_iff_linearCombination] refine ⟨_, ?_, rfl⟩ haveI : Inhabited P := ⟨0⟩ rw [← Finsupp.lmapDomain_supported _ _ g, mem_map] refine ⟨l, hl1, ?_⟩ rfl rw [ht2, mem_inf] constructor · apply s.sub_mem hx rw [Finsupp.linearCombination_apply, Finsupp.lmapDomain_apply, Finsupp.sum_mapDomain_index] · refine s.sum_mem ?_ intro y hy exact s.smul_mem _ (hg y (hl1 hy)).1 · exact zero_smul _ · exact fun _ _ _ => add_smul _ _ _ · rw [LinearMap.mem_ker, f.map_sub, ← hl2] rw [Finsupp.linearCombination_apply, Finsupp.linearCombination_apply, Finsupp.lmapDomain_apply] rw [Finsupp.sum_mapDomain_index, Finsupp.sum, Finsupp.sum, map_sum] · rw [sub_eq_zero] refine Finset.sum_congr rfl fun y hy => ?_ unfold id rw [f.map_smul, (hg y (hl1 hy)).2] · exact zero_smul _ · exact fun _ _ _ => add_smul _ _ _ /-- The kernel of the composition of two linear maps is finitely generated if both kernels are and the first morphism is surjective. -/ theorem fg_ker_comp (f : M →ₗ[R] N) (g : N →ₗ[R] P) (hf1 : (LinearMap.ker f).FG) (hf2 : (LinearMap.ker g).FG) (hsur : Function.Surjective f) : (LinearMap.ker (g.comp f)).FG := by rw [LinearMap.ker_comp] apply fg_of_fg_map_of_fg_inf_ker f · rwa [Submodule.map_comap_eq, LinearMap.range_eq_top.2 hsur, top_inf_eq] · rwa [inf_of_le_right (show (LinearMap.ker f) ≤ (LinearMap.ker g).comap f from comap_mono bot_le)] theorem _root_.Module.Finite.of_submodule_quotient (N : Submodule R M) [Module.Finite R N] [Module.Finite R (M ⧸ N)] : Module.Finite R M where fg_top := fg_of_fg_map_of_fg_inf_ker N.mkQ (by simpa only [map_top, range_mkQ] using Module.finite_def.mp ‹_›) <| by simpa only [top_inf_eq, ker_mkQ] using Module.Finite.iff_fg.mp ‹_› end Submodule section variable {R V} [Semiring R] [AddCommMonoid V] [Module R V] instance Module.Finite.finsupp {ι : Type*} [_root_.Finite ι] [Module.Finite R V] : Module.Finite R (ι →₀ V) := Module.Finite.equiv (Finsupp.linearEquivFunOnFinite R V ι).symm end namespace AddMonoidAlgebra variable {ι R S : Type*} [Finite ι] [Semiring R] [Semiring S] [Module R S] [Module.Finite R S] instance moduleFinite : Module.Finite R S[ι] := .finsupp end AddMonoidAlgebra namespace MonoidAlgebra variable {ι R S : Type*} [Finite ι] [Semiring R] [Semiring S] [Module R S] [Module.Finite R S] instance moduleFinite : Module.Finite R (MonoidAlgebra S ι) := .finsupp end MonoidAlgebra namespace FreeAbelianGroup variable {σ : Type*} [Finite σ] instance : Module.Finite ℤ (FreeAbelianGroup σ) := .of_surjective _ (FreeAbelianGroup.equivFinsupp σ).toIntLinearEquiv.symm.surjective instance : AddMonoid.FG (FreeAbelianGroup σ) := by rw [← AddGroup.fg_iff_addMonoid_fg, ← Module.Finite.iff_addGroup_fg]; infer_instance end FreeAbelianGroup
.lake/packages/mathlib/Mathlib/RingTheory/Finiteness/Projective.lean
import Mathlib.Algebra.Module.Projective import Mathlib.RingTheory.Finiteness.Cardinality /-! # Finite and projective modules -/ open Function (Surjective) namespace Module namespace Finite open Submodule Set variable {R M N : Type*} variable [Semiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N] variable (R M) in theorem exists_comp_eq_id_of_projective [Module.Finite R M] [Projective R M] : ∃ (n : ℕ) (f : (Fin n → R) →ₗ[R] M) (g : M →ₗ[R] Fin n → R), Function.Surjective f ∧ Function.Injective g ∧ f ∘ₗ g = .id := have ⟨n, f, surj⟩ := exists_fin' R M have ⟨g, hfg⟩ := Module.projective_lifting_property f .id surj ⟨n, f, g, surj, LinearMap.injective_of_comp_eq_id _ _ hfg, hfg⟩ end Finite end Module
.lake/packages/mathlib/Mathlib/RingTheory/Finiteness/Small.lean
import Mathlib.LinearAlgebra.Finsupp.LinearCombination import Mathlib.RingTheory.FiniteType import Mathlib.LinearAlgebra.DFinsupp import Mathlib.Algebra.Algebra.Subalgebra.Basic import Mathlib.LinearAlgebra.Basis.Cardinality import Mathlib.LinearAlgebra.StdBasis import Mathlib.RingTheory.Finiteness.Basic import Mathlib.RingTheory.MvPolynomial.Basic import Mathlib.Data.DFinsupp.Small /-! # Smallness properties of modules and algebras -/ universe u namespace Submodule variable {R M : Type*} [Semiring R] [AddCommMonoid M] [Module R M] instance small_sup {P Q : Submodule R M} [smallP : Small.{u} P] [smallQ : Small.{u} Q] : Small.{u} (P ⊔ Q : Submodule R M) := by rw [Submodule.sup_eq_range] exact small_range _ instance : SemilatticeSup {P : Submodule R M // Small.{u} P} where sup := fun P Q ↦ ⟨P.val ⊔ Q.val, small_sup (smallP := P.property) (smallQ := Q.property)⟩ le_sup_left := fun P Q ↦ by rw [← Subtype.coe_le_coe]; exact le_sup_left le_sup_right := fun P Q ↦ by rw [← Subtype.coe_le_coe]; exact le_sup_right sup_le := fun _ _ _ hPR hQR ↦ by rw [← Subtype.coe_le_coe] at hPR hQR ⊢ exact sup_le hPR hQR instance : Inhabited {P : Submodule R M // Small.{u} P} where default := ⟨⊥, inferInstance⟩ instance small_iSup {ι : Type*} {P : ι → Submodule R M} [Small.{u} ι] [∀ i, Small.{u} (P i)] : Small.{u} (iSup P : Submodule R M) := by classical rw [iSup_eq_range_dfinsupp_lsum] apply small_range theorem FG.small [Small.{u} R] (P : Submodule R M) (hP : P.FG) : Small.{u} P := by rw [fg_iff_exists_fin_generating_family] at hP obtain ⟨n, s, rfl⟩ := hP rw [← Fintype.range_linearCombination] apply small_range variable (R M) in theorem _root_.Module.Finite.small [Small.{u} R] [Module.Finite R M] : Small.{u} M := by have : Small.{u} (⊤ : Submodule R M) := FG.small _ (Module.finite_def.mp inferInstance) rwa [← small_univ_iff] instance small_span_singleton [Small.{u} R] (m : M) : Small.{u} (span R {m}) := FG.small _ (fg_span_singleton _) theorem small_span [Small.{u} R] (s : Set M) [Small.{u} s] : Small.{u} (span R s) := by suffices span R s = iSup (fun i : s ↦ span R ({(↑i : M)} : Set M)) by rw [this] apply small_iSup simp [← Submodule.span_iUnion] end Submodule variable {R S : Type*} [CommSemiring R] [CommSemiring S] [Algebra R S] namespace Algebra open MvPolynomial AlgHom instance small_adjoin [Small.{u} R] {s : Set S} [Small.{u} s] : Small.{u} (adjoin R s : Subalgebra R S) := by rw [Algebra.adjoin_eq_range] apply small_range theorem _root_.Subalgebra.FG.small [Small.{u} R] {A : Subalgebra R S} (fgS : A.FG) : Small.{u} A := by obtain ⟨s, hs, rfl⟩ := fgS exact small_adjoin theorem FiniteType.small [Small.{u} R] [Algebra.FiniteType R S] : Small.{u} S := by have : Small.{u} (⊤ : Subalgebra R S) := Subalgebra.FG.small Algebra.FiniteType.out rwa [← small_univ_iff] end Algebra
.lake/packages/mathlib/Mathlib/RingTheory/Finiteness/Lattice.lean
import Mathlib.Data.Fintype.Lattice import Mathlib.RingTheory.Finiteness.Basic /-! # Finite suprema of finite modules -/ namespace Submodule open Module variable {R V} [Ring R] [AddCommGroup V] [Module R V] /-- The submodule generated by a supremum of finite-dimensional submodules, indexed by a finite sort is finite-dimensional. -/ instance finite_iSup {ι : Sort*} [Finite ι] (S : ι → Submodule R V) [∀ i, Module.Finite R (S i)] : Module.Finite R ↑(⨆ i, S i) := by cases nonempty_fintype (PLift ι) rw [← iSup_plift_down, ← Finset.sup_univ_eq_iSup] exact Submodule.finite_finset_sup _ _ end Submodule
.lake/packages/mathlib/Mathlib/RingTheory/RootsOfUnity/CyclotomicUnits.lean
import Mathlib.RingTheory.RootsOfUnity.PrimitiveRoots /-! # Cyclotomic units. We gather miscellaneous results about units given by sums of powers of roots of unit, the so-called *cyclotomic units*. ## Main results * `IsPrimitiveRoot.associated_sub_one_pow_sub_one_of_coprime` : given an `n`-th primitive root of unity `ζ`, we have that `ζ - 1` and `ζ ^ j - 1` are associated for all `j` coprime with `n`. * `IsPrimitiveRoot.associated_pow_sub_one_pow_of_coprime` : given an `n`-th primitive root of unity `ζ`, we have that `ζ ^ i - 1` and `ζ ^ j - 1` are associated for all `i` and `j` coprime with `n`. * `IsPrimitiveRoot.associated_pow_add_sub_sub_one` : given an `n`-th primitive root of unity `ζ`, where `2 ≤ n`, we have that `ζ - 1` and `ζ ^ (i + j) - ζ ^ i` are associated for all and `j` coprime with `n` and all `i`. ## Implementation details We sometimes state series of results of the form `a = u * b`, `IsUnit u` and `Associated a b`. Often, `Associated a b` is everything one needs, and it is more convenient to use, we include the other version for completeness. -/ open Polynomial Finset Nat variable {n i j p : ℕ} {A K : Type*} {ζ : A} variable [CommRing A] [IsDomain A] {R : Type*} [CommRing R] [Algebra R A] namespace IsPrimitiveRoot /-- Given an `n`-th primitive root of unity `ζ,` we have that `ζ - 1` and `ζ ^ j - 1` are associated for all `j` coprime with `n`. `pow_sub_one_mul_geom_sum_eq_pow_sub_one_mul_geom_sum` gives an explicit formula for the unit. -/ theorem associated_sub_one_pow_sub_one_of_coprime (hζ : IsPrimitiveRoot ζ n) (hj : j.Coprime n) : Associated (ζ - 1) (ζ ^ j - 1) := by refine associated_of_dvd_dvd ⟨∑ i ∈ range j, ζ ^ i, (mul_geom_sum _ _).symm⟩ ?_ match n with | 0 => simp_all | 1 => simp_all | n + 2 => obtain ⟨m, hm⟩ := exists_mul_emod_eq_one_of_coprime hj (by omega) use ∑ i ∈ range m, (ζ ^ j) ^ i rw [mul_geom_sum, ← pow_mul, ← pow_mod_orderOf, ← hζ.eq_orderOf, hm, pow_one] /-- Given an `n`-th primitive root of unity `ζ`, we have that `ζ ^ j - 1` and `ζ ^ i - 1` are associated for all `i` and `j` coprime with `n`. -/ theorem associated_pow_sub_one_pow_of_coprime (hζ : IsPrimitiveRoot ζ n) (hi : i.Coprime n) (hj : j.Coprime n) : Associated (ζ ^ j - 1) (ζ ^ i - 1) := by suffices ∀ {j}, j.Coprime n → Associated (ζ - 1) (ζ ^ j - 1) by grind [Associated.trans, Associated.symm] exact hζ.associated_sub_one_pow_sub_one_of_coprime /-- Given an `n`-th primitive root of unity `ζ`, we have that `ζ - 1` is associated to any of its conjugate. -/ theorem associated_sub_one_map_sub_one {n : ℕ} [NeZero n] (hζ : IsPrimitiveRoot ζ n) (σ : A ≃ₐ[R] A) : Associated (ζ - 1) (σ (ζ - 1)) := by rw [map_sub, map_one, ← hζ.autToPow_spec R σ] apply hζ.associated_sub_one_pow_sub_one_of_coprime exact ZMod.val_coe_unit_coprime ((autToPow R hζ) σ) /-- Given an `n`-th primitive root of unity `ζ`, we have that two conjugates of `ζ - 1` are associated. -/ theorem associated_map_sub_one_map_sub_one {n : ℕ} [NeZero n] (hζ : IsPrimitiveRoot ζ n) (σ τ : A ≃ₐ[R] A) : Associated (σ (ζ - 1)) (τ (ζ - 1)) := by rw [map_sub, map_sub, map_one, map_one, ← hζ.autToPow_spec R σ, ← hζ.autToPow_spec R τ] apply hζ.associated_pow_sub_one_pow_of_coprime <;> exact ZMod.val_coe_unit_coprime ((autToPow R hζ) _) /-- Given an `n`-th primitive root of unity `ζ`, where `2 ≤ n`, we have that `∑ i ∈ range j, ζ ^ i` is a unit for all `j` coprime with `n`. This is the unit given by `associated_pow_sub_one_pow_of_coprime` (see `pow_sub_one_mul_geom_sum_eq_pow_sub_one_mul_geom_sum`). -/ theorem geom_sum_isUnit (hζ : IsPrimitiveRoot ζ n) (hn : 2 ≤ n) (hj : j.Coprime n) : IsUnit (∑ i ∈ range j, ζ ^ i) := by obtain ⟨u, hu⟩ := hζ.associated_pow_sub_one_pow_of_coprime hj (coprime_one_left n) convert u.isUnit apply mul_right_injective₀ (show 1 - ζ ≠ 0 by grind [sub_one_ne_zero]) grind [mul_neg_geom_sum] /-- Similar to `geom_sum_isUnit`, but instead of assuming `2 ≤ n` we assume that `j` is a unit in `A`. -/ theorem geom_sum_isUnit' (hζ : IsPrimitiveRoot ζ n) (hj : j.Coprime n) (hj_Unit : IsUnit (j : A)) : IsUnit (∑ i ∈ range j, ζ ^ i) := by match n with | 0 => simp_all | 1 => simp_all | n + 2 => exact geom_sum_isUnit hζ (by linarith) hj theorem pow_sub_one_eq_geom_sum_mul_geom_sum_inv_mul_pow_sub_one (hζ : IsPrimitiveRoot ζ n) (hn : 2 ≤ n) (hi : i.Coprime n) (hj : j.Coprime n) : (ζ ^ j - 1) = (hζ.geom_sum_isUnit hn hj).unit * (hζ.geom_sum_isUnit hn hi).unit⁻¹ * (ζ ^ i - 1) := by grind [IsUnit.mul_val_inv, pow_sub_one_mul_geom_sum_eq_pow_sub_one_mul_geom_sum, IsUnit.unit_spec] /-- Given an `n`-th primitive root of unity `ζ`, where `2 ≤ n`, we have that `ζ - 1` and `ζ ^ (i + j) - ζ ^ i` are associated for all and `j` coprime with `n` and all `i`. See `pow_sub_one_eq_geom_sum_mul_geom_sum_inv_mul_pow_sub_one` for the explicit formula of the unit. -/ theorem associated_pow_add_sub_sub_one (hζ : IsPrimitiveRoot ζ n) (hn : 2 ≤ n) (i : ℕ) (hjn : j.Coprime n) : Associated (ζ - 1) (ζ ^ (i + j) - ζ ^ i) := by use (hζ.isUnit (by omega)).unit ^ i * (hζ.geom_sum_isUnit hn hjn).unit suffices (ζ - 1) * ζ ^ i * ∑ i ∈ range j, ζ ^ i = (ζ ^ (i + j) - ζ ^ i) by simp [← this, mul_assoc] grind [mul_geom_sum] /-- If `p` is prime and `ζ` is a `p`-th primitive root of unit, then `ζ - 1` and `η₁ - η₂` are associated for all distincts `p`-th root of unit `η₁` and `η₂`. -/ lemma ntRootsFinset_pairwise_associated_sub_one_sub_of_prime (hζ : IsPrimitiveRoot ζ p) (hp : p.Prime) : Set.Pairwise (nthRootsFinset p (1 : A)) (fun η₁ η₂ ↦ Associated (ζ - 1) (η₁ - η₂)) := by intro η₁ hη₁ η₂ hη₂ e have : NeZero p := ⟨hp.ne_zero⟩ obtain ⟨i, hi, rfl⟩ := hζ.eq_pow_of_pow_eq_one ((Polynomial.mem_nthRootsFinset hp.pos 1).1 hη₁) obtain ⟨j, hj, rfl⟩ := hζ.eq_pow_of_pow_eq_one ((Polynomial.mem_nthRootsFinset hp.pos 1).1 hη₂) wlog hij : j ≤ i · simpa using (this hζ ‹_› ‹_› _ hj ‹_› _ hi ‹_› e.symm (by omega)).neg_right have H : (i - j).Coprime p := (coprime_of_lt_prime (by grind) (by grind) hp).symm obtain ⟨u, h⟩ := hζ.associated_pow_add_sub_sub_one hp.two_le j H simp only [hij, add_tsub_cancel_of_le] at h rw [← h, associated_mul_unit_right_iff] end IsPrimitiveRoot
.lake/packages/mathlib/Mathlib/RingTheory/RootsOfUnity/EnoughRootsOfUnity.lean
import Mathlib.RingTheory.RootsOfUnity.PrimitiveRoots /-! # Commutative monoids with enough roots of unity We define a typeclass `HasEnoughRootsOfUnity M n` for a commutative monoid `M` and a natural number `n` that asserts that `M` contains a primitive `n`th root of unity and that the group of `n`th roots of unity in `M` is cyclic. Such monoids are suitable targets for homomorphisms from groups of exponent (dividing) `n`; for example, the homomorphisms can then be used to separate elements of the source group. -/ /-- This is a type class recording that a commutative monoid `M` contains primitive `n`th roots of unity and such that the group of `n`th roots of unity is cyclic. Such monoids are suitable targets in the context of duality statements for groups of exponent `n`. -/ class HasEnoughRootsOfUnity (M : Type*) [CommMonoid M] (n : ℕ) where prim : ∃ m : M, IsPrimitiveRoot m n cyc : IsCyclic <| rootsOfUnity n M namespace HasEnoughRootsOfUnity lemma exists_primitiveRoot (M : Type*) [CommMonoid M] (n : ℕ) [HasEnoughRootsOfUnity M n] : ∃ ζ : M, IsPrimitiveRoot ζ n := HasEnoughRootsOfUnity.prim instance rootsOfUnity_isCyclic (M : Type*) [CommMonoid M] (n : ℕ) [HasEnoughRootsOfUnity M n] : IsCyclic (rootsOfUnity n M) := HasEnoughRootsOfUnity.cyc /-- If `HasEnoughRootsOfUnity M n` and `m ∣ n`, then also `HasEnoughRootsOfUnity M m`. -/ lemma of_dvd (M : Type*) [CommMonoid M] {m n : ℕ} [NeZero n] (hmn : m ∣ n) [HasEnoughRootsOfUnity M n] : HasEnoughRootsOfUnity M m where prim := have ⟨ζ, hζ⟩ := exists_primitiveRoot M n have ⟨k, hk⟩ := hmn ⟨ζ ^ k, IsPrimitiveRoot.pow (NeZero.pos n) hζ (mul_comm m k ▸ hk)⟩ cyc := Subgroup.isCyclic_of_le <| rootsOfUnity_le_of_dvd hmn /-- If `M` satisfies `HasEnoughRootsOfUnity`, then the group of `n`th roots of unity in `M` is finite. -/ instance finite_rootsOfUnity (M : Type*) [CommMonoid M] (n : ℕ) [NeZero n] [HasEnoughRootsOfUnity M n] : Finite <| rootsOfUnity n M := by have := rootsOfUnity_isCyclic M n obtain ⟨g, hg⟩ := IsCyclic.exists_generator (α := rootsOfUnity n M) have hg' : g ^ n = 1 := OneMemClass.coe_eq_one.mp g.prop let f (j : ZMod n) : rootsOfUnity n M := g ^ (j.val : ℤ) refine Finite.of_surjective f fun x ↦ ?_ obtain ⟨k, hk⟩ := Subgroup.mem_zpowers_iff.mp <| hg x refine ⟨k, ?_⟩ simpa only [ZMod.natCast_val, ← hk, f, ZMod.coe_intCast] using (zpow_eq_zpow_emod' k hg').symm /-- If `M` satisfies `HasEnoughRootsOfUnity`, then the group of `n`th roots of unity in `M` (is cyclic and) has order `n`. -/ lemma natCard_rootsOfUnity (M : Type*) [CommMonoid M] (n : ℕ) [NeZero n] [HasEnoughRootsOfUnity M n] : Nat.card (rootsOfUnity n M) = n := by obtain ⟨ζ, h⟩ := exists_primitiveRoot M n rw [← IsCyclic.exponent_eq_card] refine dvd_antisymm ?_ ?_ · exact Monoid.exponent_dvd_of_forall_pow_eq_one fun g ↦ OneMemClass.coe_eq_one.mp g.prop · nth_rewrite 1 [h.eq_orderOf] rw [← (h.isUnit NeZero.out).unit_spec, orderOf_units] let ζ' : rootsOfUnity n M := ⟨(h.isUnit NeZero.out).unit, ?_⟩ · rw [← Subgroup.orderOf_mk] exact Monoid.order_dvd_exponent ζ' simp only [mem_rootsOfUnity] rw [← Units.val_inj, Units.val_pow_eq_pow_val, IsUnit.unit_spec, h.pow_eq_one, Units.val_one] lemma of_card_le {R : Type*} [CommRing R] [IsDomain R] {n : ℕ} [NeZero n] (h : n ≤ Fintype.card (rootsOfUnity n R)) : HasEnoughRootsOfUnity R n where prim := card_rootsOfUnity_eq_iff_exists_isPrimitiveRoot.mp (le_antisymm (card_rootsOfUnity R n) h) cyc := rootsOfUnity.isCyclic R n end HasEnoughRootsOfUnity lemma MulEquiv.hasEnoughRootsOfUnity {n : ℕ} [NeZero n] {M N : Type*} [CommMonoid M] [CommMonoid N] [hm : HasEnoughRootsOfUnity M n] (e : rootsOfUnity n M ≃* rootsOfUnity n N) : HasEnoughRootsOfUnity N n where prim := by obtain ⟨m, hm⟩ := hm.prim use (e hm.toRootsOfUnity).val.val rw [IsPrimitiveRoot.coe_units_iff, IsPrimitiveRoot.coe_submonoidClass_iff] refine .map_of_injective ?_ e.injective rwa [← IsPrimitiveRoot.coe_submonoidClass_iff, ← IsPrimitiveRoot.coe_units_iff] cyc := isCyclic_of_surjective e e.surjective section cyclic /-- The group of group homomorphisms from a finite cyclic group `G` of order `n` into the group of units of a ring `M` with all roots of unity is isomorphic to `G` -/ lemma IsCyclic.monoidHom_equiv_self (G M : Type*) [CommGroup G] [Finite G] [IsCyclic G] [CommMonoid M] [HasEnoughRootsOfUnity M (Nat.card G)] : Nonempty ((G →* Mˣ) ≃* G) := by have : NeZero (Nat.card G) := ⟨Nat.card_pos.ne'⟩ have hord := HasEnoughRootsOfUnity.natCard_rootsOfUnity M (Nat.card G) let e := (IsCyclic.monoidHom_mulEquiv_rootsOfUnity G Mˣ).some exact ⟨e.trans (rootsOfUnityUnitsMulEquiv M (Nat.card G)) |>.trans (mulEquivOfCyclicCardEq hord)⟩ end cyclic instance {M : Type*} [CommMonoid M] : HasEnoughRootsOfUnity M 1 where prim := ⟨1, by simp⟩ cyc := isCyclic_of_subsingleton
.lake/packages/mathlib/Mathlib/RingTheory/RootsOfUnity/Lemmas.lean
import Mathlib.FieldTheory.KummerExtension /-! # More results on primitive roots of unity (We put these in a separate file because of the `KummerExtension` import.) Assume that `μ` is a primitive `n`th root of unity in an integral domain `R`. Then $$ \prod_{k=1}^{n-1} (1 - \mu^k) = n \,; $$ see `IsPrimitiveRoot.prod_one_sub_pow_eq_order` and its variant `IsPrimitiveRoot.prod_pow_sub_one_eq_order` in terms of `∏ (μ^k - 1)`. We use this to deduce that `n` is divisible by `(μ - 1)^k` in `ℤ[μ] ⊆ R` when `k < n`. -/ variable {R : Type*} [CommRing R] [IsDomain R] namespace IsPrimitiveRoot open Finset Polynomial /-- If `μ` is a primitive `n`th root of unity in `R`, then `∏(1≤k<n) (1-μ^k) = n`. (Stated with `n+1` in place of `n` to avoid the condition `n ≠ 0`.) -/ lemma prod_one_sub_pow_eq_order {n : ℕ} {μ : R} (hμ : IsPrimitiveRoot μ (n + 1)) : ∏ k ∈ range n, (1 - μ ^ (k + 1)) = n + 1 := by have := X_pow_sub_C_eq_prod hμ n.zero_lt_succ (one_pow (n + 1)) rw [C_1, ← mul_geom_sum, prod_range_succ', pow_zero, mul_one, mul_comm, eq_comm] at this replace this := mul_right_cancel₀ (Polynomial.X_sub_C_ne_zero 1) this apply_fun Polynomial.eval 1 at this simpa only [mul_one, map_pow, eval_prod, eval_sub, eval_X, eval_pow, eval_C, eval_geom_sum, one_pow, sum_const, card_range, nsmul_eq_mul, Nat.cast_add, Nat.cast_one] using this /-- If `μ` is a primitive `n`th root of unity in `R`, then `(-1)^(n-1) * ∏(1≤k<n) (μ^k-1) = n`. (Stated with `n+1` in place of `n` to avoid the condition `n ≠ 0`.) -/ lemma prod_pow_sub_one_eq_order {n : ℕ} {μ : R} (hμ : IsPrimitiveRoot μ (n + 1)) : (-1) ^ n * ∏ k ∈ range n, (μ ^ (k + 1) - 1) = n + 1 := by have : (-1 : R) ^ n = ∏ k ∈ range n, -1 := by rw [prod_const, card_range] simp only [this, ← prod_mul_distrib, neg_one_mul, neg_sub, ← prod_one_sub_pow_eq_order hμ] open Algebra in /-- If `μ` is a primitive `n`th root of unity in `R` and `k < n`, then `n` is divisible by `(μ-1)^k` in `ℤ[μ] ⊆ R`. -/ lemma self_sub_one_pow_dvd_order {k n : ℕ} (hn : k < n) {μ : R} (hμ : IsPrimitiveRoot μ n) : ∃ z ∈ adjoin ℤ {μ}, n = z * (μ - 1) ^ k := by let n' + 1 := n obtain ⟨m, rfl⟩ := Nat.exists_eq_add_of_le' (Nat.le_of_lt_succ hn) have hdvd k : ∃ z ∈ adjoin ℤ {μ}, μ ^ k - 1 = z * (μ - 1) := by refine ⟨(Finset.range k).sum (μ ^ ·), ?_, (geom_sum_mul μ k).symm⟩ exact Subalgebra.sum_mem _ fun m _ ↦ Subalgebra.pow_mem _ (self_mem_adjoin_singleton _ μ) _ let Z k := Classical.choose <| hdvd k have Zdef k : Z k ∈ adjoin ℤ {μ} ∧ μ ^ k - 1 = Z k * (μ - 1) := Classical.choose_spec <| hdvd k refine ⟨(-1) ^ (m + k) * (∏ j ∈ range k, Z (j + 1)) * ∏ j ∈ Ico k (m + k), (μ ^ (j + 1) - 1), ?_, ?_⟩ · apply Subalgebra.mul_mem · apply Subalgebra.mul_mem · exact Subalgebra.pow_mem _ (Subalgebra.neg_mem _ <| Subalgebra.one_mem _) _ · exact Subalgebra.prod_mem _ fun _ _ ↦ (Zdef _).1 · refine Subalgebra.prod_mem _ fun _ _ ↦ ?_ apply Subalgebra.sub_mem · exact Subalgebra.pow_mem _ (self_mem_adjoin_singleton ℤ μ) _ · exact Subalgebra.one_mem _ · push_cast have := Nat.cast_add (R := R) m k ▸ hμ.prod_pow_sub_one_eq_order rw [← this, mul_assoc, mul_assoc] congr 1 conv => enter [2, 2, 2]; rw [← card_range k] rw [← prod_range_mul_prod_Ico _ (Nat.le_add_left k m), mul_comm _ (_ ^ #_), ← mul_assoc, prod_mul_pow_card] conv => enter [2, 1, 2, j]; rw [← (Zdef _).2] end IsPrimitiveRoot
.lake/packages/mathlib/Mathlib/RingTheory/RootsOfUnity/AlgebraicallyClosed.lean
import Mathlib.RingTheory.RootsOfUnity.EnoughRootsOfUnity import Mathlib.NumberTheory.Cyclotomic.Basic /-! # Instances for HasEnoughRootsOfUnity We provide an instance for `HasEnoughRootsOfUnity F n` when `F` is a separably closed field and `n` is not divisible by the characteristic. In particular, when `F` has characteristic zero, this hold for all `n ≠ 0`. -/ variable (F : Type*) [Field F] (n k : ℕ) [NeZero (n : F)] namespace IsSepClosed variable [IsSepClosed F] /-- A separably closed field `F` satisfies `HasEnoughRootsOfUnity F n` for all `n` that are not divisible by the characteristic of `F`. -/ instance hasEnoughRootsOfUnity : HasEnoughRootsOfUnity F n where prim := by have : NeZero n := .of_neZero_natCast F have := isCyclotomicExtension {n} F fun _ h _ ↦ Set.mem_singleton_iff.mp h ▸ ‹NeZero (n : F)› exact IsCyclotomicExtension.exists_isPrimitiveRoot (S := {n}) F _ rfl (NeZero.ne _) cyc := have : NeZero n := .of_neZero_natCast F rootsOfUnity.isCyclic F n instance hasEnoughRootsOfUnity_pow : HasEnoughRootsOfUnity F (n ^ k) := have : NeZero ((n ^ k : ℕ) : F) := by exact_mod_cast ‹NeZero (n : F)›.pow inferInstance end IsSepClosed @[deprecated (since := "2025-06-22")] alias IsAlgClosed.hasEnoughRootsOfUnity := IsSepClosed.hasEnoughRootsOfUnity namespace AlgebraicClosure instance hasEnoughRootsOfUnity : HasEnoughRootsOfUnity (AlgebraicClosure F) n := have : NeZero (n : AlgebraicClosure F) := ‹NeZero (n : F)›.of_injective (algebraMap F (AlgebraicClosure F)).injective inferInstance instance hasEnoughRootsOfUnity_pow : HasEnoughRootsOfUnity (AlgebraicClosure F) (n ^ k) := have : NeZero (n : AlgebraicClosure F) := ‹NeZero (n : F)›.of_injective (algebraMap F (AlgebraicClosure F)).injective inferInstance end AlgebraicClosure namespace SeparableClosure instance hasEnoughRootsOfUnity : HasEnoughRootsOfUnity (SeparableClosure F) n := have : NeZero (n : SeparableClosure F) := ‹NeZero (n : F)›.of_injective (algebraMap F (SeparableClosure F)).injective inferInstance instance hasEnoughRootsOfUnity_pow : HasEnoughRootsOfUnity (SeparableClosure F) (n ^ k) := have : NeZero (n : SeparableClosure F) := ‹NeZero (n : F)›.of_injective (algebraMap F (SeparableClosure F)).injective inferInstance end SeparableClosure
.lake/packages/mathlib/Mathlib/RingTheory/RootsOfUnity/Basic.lean
import Mathlib.Algebra.CharP.Reduced import Mathlib.RingTheory.IntegralDomain -- TODO: remove Mathlib.Algebra.CharP.Reduced and move the last two lemmas to Lemmas /-! # Roots of unity We define roots of unity in the context of an arbitrary commutative monoid, as a subgroup of the group of units. ## Main definitions * `rootsOfUnity n M`, for `n : ℕ` is the subgroup of the units of a commutative monoid `M` consisting of elements `x` that satisfy `x ^ n = 1`. ## Main results * `rootsOfUnity.isCyclic`: the roots of unity in an integral domain form a cyclic group. ## Implementation details It is desirable that `rootsOfUnity` is a subgroup, and it will mainly be applied to rings (e.g. the ring of integers in a number field) and fields. We therefore implement it as a subgroup of the units of a commutative monoid. We have chosen to define `rootsOfUnity n` for `n : ℕ` and add a `[NeZero n]` typeclass assumption when we need `n` to be non-zero (which is the case for most interesting statements). Note that `rootsOfUnity 0 M` is the top subgroup of `Mˣ` (as the condition `ζ^0 = 1` is satisfied for all units). -/ noncomputable section open Polynomial open Finset variable {M N G R S F : Type*} variable [CommMonoid M] [CommMonoid N] [DivisionCommMonoid G] section rootsOfUnity variable {k l : ℕ} /-- `rootsOfUnity k M` is the subgroup of elements `m : Mˣ` that satisfy `m ^ k = 1`. -/ def rootsOfUnity (k : ℕ) (M : Type*) [CommMonoid M] : Subgroup Mˣ where carrier := {ζ | ζ ^ k = 1} one_mem' := one_pow _ mul_mem' _ _ := by simp_all only [Set.mem_setOf_eq, mul_pow, one_mul] inv_mem' _ := by simp_all only [Set.mem_setOf_eq, inv_pow, inv_one] @[simp] theorem mem_rootsOfUnity (k : ℕ) (ζ : Mˣ) : ζ ∈ rootsOfUnity k M ↔ ζ ^ k = 1 := Iff.rfl /-- A variant of `mem_rootsOfUnity` using `ζ : Mˣ`. -/ theorem mem_rootsOfUnity' (k : ℕ) (ζ : Mˣ) : ζ ∈ rootsOfUnity k M ↔ (ζ : M) ^ k = 1 := by rw [mem_rootsOfUnity]; norm_cast @[simp] theorem rootsOfUnity_one (M : Type*) [CommMonoid M] : rootsOfUnity 1 M = ⊥ := by ext1 simp only [mem_rootsOfUnity, pow_one, Subgroup.mem_bot] @[simp] lemma rootsOfUnity_zero (M : Type*) [CommMonoid M] : rootsOfUnity 0 M = ⊤ := by ext1 simp only [mem_rootsOfUnity, pow_zero, Subgroup.mem_top] theorem rootsOfUnity.coe_injective {n : ℕ} : Function.Injective (fun x : rootsOfUnity n M ↦ x.val.val) := Units.val_injective.comp Subtype.val_injective /-- Make an element of `rootsOfUnity` from a member of the base ring, and a proof that it has a positive power equal to one. -/ @[simps! coe_val] def rootsOfUnity.mkOfPowEq (ζ : M) {n : ℕ} [NeZero n] (h : ζ ^ n = 1) : rootsOfUnity n M := ⟨Units.ofPowEqOne ζ n h <| NeZero.ne n, Units.pow_ofPowEqOne _ _⟩ @[simp] theorem rootsOfUnity.coe_mkOfPowEq {ζ : M} {n : ℕ} [NeZero n] (h : ζ ^ n = 1) : ((rootsOfUnity.mkOfPowEq _ h : Mˣ) : M) = ζ := rfl theorem rootsOfUnity_le_of_dvd (h : k ∣ l) : rootsOfUnity k M ≤ rootsOfUnity l M := by obtain ⟨d, rfl⟩ := h intro ζ h simp_all only [mem_rootsOfUnity, pow_mul, one_pow] theorem map_rootsOfUnity (f : Mˣ →* Nˣ) (k : ℕ) : (rootsOfUnity k M).map f ≤ rootsOfUnity k N := by rintro _ ⟨ζ, h, rfl⟩ simp_all only [← map_pow, mem_rootsOfUnity, SetLike.mem_coe, MonoidHom.map_one] instance : Subsingleton (rootsOfUnity 1 M) := by simp [subsingleton_iff] lemma rootsOfUnity_inf_rootsOfUnity {m n : ℕ} : (rootsOfUnity m M ⊓ rootsOfUnity n M) = rootsOfUnity (m.gcd n) M := by refine le_antisymm ?_ ?_ · intro simp +contextual [pow_gcd_eq_one] · rw [le_inf_iff] exact ⟨rootsOfUnity_le_of_dvd (m.gcd_dvd_left n), rootsOfUnity_le_of_dvd (m.gcd_dvd_right n)⟩ lemma disjoint_rootsOfUnity_of_coprime {m n : ℕ} (h : m.Coprime n) : Disjoint (rootsOfUnity m M) (rootsOfUnity n M) := by simp [disjoint_iff_inf_le, rootsOfUnity_inf_rootsOfUnity, Nat.coprime_iff_gcd_eq_one.mp h] @[norm_cast] theorem rootsOfUnity.coe_pow [CommMonoid R] (ζ : rootsOfUnity k R) (m : ℕ) : (((ζ ^ m :) : Rˣ) : R) = ((ζ : Rˣ) : R) ^ m := by rw [Subgroup.coe_pow, Units.val_pow_eq_pow_val] /-- The canonical isomorphism from the `n`th roots of unity in `Mˣ` to the `n`th roots of unity in `M`. -/ def rootsOfUnityUnitsMulEquiv (M : Type*) [CommMonoid M] (n : ℕ) : rootsOfUnity n Mˣ ≃* rootsOfUnity n M where toFun ζ := ⟨ζ.val, (mem_rootsOfUnity ..).mpr <| (mem_rootsOfUnity' ..).mp ζ.prop⟩ invFun ζ := ⟨toUnits ζ.val, by simp only [mem_rootsOfUnity, ← map_pow, EmbeddingLike.map_eq_one_iff] exact (mem_rootsOfUnity ..).mp ζ.prop⟩ left_inv ζ := by simp only [toUnits_val_apply, Subtype.coe_eta] right_inv ζ := by simp only [val_toUnits_apply, Subtype.coe_eta] map_mul' ζ ζ' := by simp only [Subgroup.coe_mul, Units.val_mul, MulMemClass.mk_mul_mk] section CommMonoid variable [CommMonoid R] [CommMonoid S] [FunLike F R S] /-- Restrict a ring homomorphism to the nth roots of unity. -/ def restrictRootsOfUnity [MonoidHomClass F R S] (σ : F) (n : ℕ) : rootsOfUnity n R →* rootsOfUnity n S := { toFun := fun ξ ↦ ⟨Units.map σ (ξ : Rˣ), by rw [mem_rootsOfUnity, ← map_pow, Units.ext_iff, Units.coe_map, ξ.prop] exact map_one σ⟩ map_one' := by ext1; simp only [OneMemClass.coe_one, map_one] map_mul' := fun ξ₁ ξ₂ ↦ by ext1; simp only [Subgroup.coe_mul, map_mul, MulMemClass.mk_mul_mk] } @[simp] theorem restrictRootsOfUnity_coe_apply [MonoidHomClass F R S] (σ : F) (ζ : rootsOfUnity k R) : (restrictRootsOfUnity σ k ζ : Sˣ) = σ (ζ : Rˣ) := rfl /-- Restrict a monoid isomorphism to the nth roots of unity. -/ nonrec def MulEquiv.restrictRootsOfUnity (σ : R ≃* S) (n : ℕ) : rootsOfUnity n R ≃* rootsOfUnity n S where toFun := restrictRootsOfUnity σ n invFun := restrictRootsOfUnity σ.symm n left_inv ξ := by ext; exact σ.symm_apply_apply _ right_inv ξ := by ext; exact σ.apply_symm_apply _ map_mul' := (restrictRootsOfUnity _ n).map_mul @[simp] theorem MulEquiv.restrictRootsOfUnity_coe_apply (σ : R ≃* S) (ζ : rootsOfUnity k R) : (σ.restrictRootsOfUnity k ζ : Sˣ) = σ (ζ : Rˣ) := rfl @[simp] theorem MulEquiv.restrictRootsOfUnity_symm (σ : R ≃* S) : (σ.restrictRootsOfUnity k).symm = σ.symm.restrictRootsOfUnity k := rfl @[simp] theorem Units.val_set_image_rootsOfUnity [NeZero k] : ((↑) : Rˣ → _) '' (rootsOfUnity k R) = {z : R | z^k = 1} := by ext x exact ⟨fun ⟨y,hy1,hy2⟩ => by rw [← hy2]; exact (mem_rootsOfUnity' k y).mp hy1, fun h ↦ ⟨(rootsOfUnity.mkOfPowEq x h), ⟨Subtype.coe_prop (rootsOfUnity.mkOfPowEq x h), rfl⟩⟩⟩ theorem Units.val_set_image_rootsOfUnity_one : ((↑) : Rˣ → R) '' (rootsOfUnity 1 R) = {1} := by ext x simp end CommMonoid open Set in theorem Units.val_set_image_rootsOfUnity_two [CommRing R] [NoZeroDivisors R] : ((↑) : Rˣ → R) '' (rootsOfUnity 2 R) = {1, -1} := by ext x simp section IsDomain -- The following results need `k` to be nonzero. variable [NeZero k] [CommRing R] [IsDomain R] theorem mem_rootsOfUnity_iff_mem_nthRoots {ζ : Rˣ} : ζ ∈ rootsOfUnity k R ↔ (ζ : R) ∈ nthRoots k (1 : R) := by simp only [mem_rootsOfUnity, mem_nthRoots (NeZero.pos k), Units.ext_iff, Units.val_one, Units.val_pow_eq_pow_val] variable (k R) /-- Equivalence between the `k`-th roots of unity in `R` and the `k`-th roots of `1`. This is implemented as equivalence of subtypes, because `rootsOfUnity` is a subgroup of the group of units, whereas `nthRoots` is a multiset. -/ def rootsOfUnityEquivNthRoots : rootsOfUnity k R ≃ { x // x ∈ nthRoots k (1 : R) } where toFun x := ⟨(x : Rˣ), mem_rootsOfUnity_iff_mem_nthRoots.mp x.2⟩ invFun x := by refine ⟨⟨x, ↑x ^ (k - 1 : ℕ), ?_, ?_⟩, ?_⟩ all_goals rcases x with ⟨x, hx⟩; rw [mem_nthRoots <| NeZero.pos k] at hx simp only [← pow_succ, ← pow_succ', hx, tsub_add_cancel_of_le NeZero.one_le] simp only [mem_rootsOfUnity, Units.ext_iff, Units.val_pow_eq_pow_val, hx, Units.val_one] variable {k R} @[simp] theorem rootsOfUnityEquivNthRoots_apply (x : rootsOfUnity k R) : (rootsOfUnityEquivNthRoots R k x : R) = ((x : Rˣ) : R) := rfl @[simp] theorem rootsOfUnityEquivNthRoots_symm_apply (x : { x // x ∈ nthRoots k (1 : R) }) : (((rootsOfUnityEquivNthRoots R k).symm x : Rˣ) : R) = (x : R) := rfl variable (k R) instance rootsOfUnity.fintype : Fintype (rootsOfUnity k R) := by classical exact Fintype.ofEquiv { x // x ∈ nthRoots k (1 : R) } (rootsOfUnityEquivNthRoots R k).symm instance rootsOfUnity.isCyclic : IsCyclic (rootsOfUnity k R) := isCyclic_of_subgroup_isDomain ((Units.coeHom R).comp (rootsOfUnity k R).subtype) coe_injective theorem card_rootsOfUnity : Fintype.card (rootsOfUnity k R) ≤ k := by classical calc Fintype.card (rootsOfUnity k R) = Fintype.card { x // x ∈ nthRoots k (1 : R) } := Fintype.card_congr (rootsOfUnityEquivNthRoots R k) _ ≤ Multiset.card (nthRoots k (1 : R)).attach := Multiset.card_le_card (Multiset.dedup_le _) _ = Multiset.card (nthRoots k (1 : R)) := Multiset.card_attach _ ≤ k := card_nthRoots k 1 variable {k R} theorem map_rootsOfUnity_eq_pow_self [FunLike F R R] [MonoidHomClass F R R] (σ : F) (ζ : rootsOfUnity k R) : ∃ m : ℕ, σ (ζ : Rˣ) = ((ζ : Rˣ) : R) ^ m := by obtain ⟨m, hm⟩ := MonoidHom.map_cyclic (restrictRootsOfUnity σ k) rw [← restrictRootsOfUnity_coe_apply, hm, ← zpow_mod_orderOf, ← Int.toNat_of_nonneg (m.emod_nonneg (Int.natCast_ne_zero.mpr (pos_iff_ne_zero.mp (orderOf_pos ζ)))), zpow_natCast, rootsOfUnity.coe_pow] exact ⟨(m % orderOf ζ).toNat, rfl⟩ end IsDomain section Reduced variable (R) [CommRing R] [IsReduced R] -- simp normal form is `mem_rootsOfUnity_prime_pow_mul_iff'` theorem mem_rootsOfUnity_prime_pow_mul_iff (p k : ℕ) (m : ℕ) [ExpChar R p] {ζ : Rˣ} : ζ ∈ rootsOfUnity (p ^ k * m) R ↔ ζ ∈ rootsOfUnity m R := by simp only [mem_rootsOfUnity', ExpChar.pow_prime_pow_mul_eq_one_iff] /-- A variant of `mem_rootsOfUnity_prime_pow_mul_iff` in terms of `ζ ^ _` -/ @[simp] theorem mem_rootsOfUnity_prime_pow_mul_iff' (p k : ℕ) (m : ℕ) [ExpChar R p] {ζ : Rˣ} : ζ ^ (p ^ k * m) = 1 ↔ ζ ∈ rootsOfUnity m R := by rw [← mem_rootsOfUnity, mem_rootsOfUnity_prime_pow_mul_iff] end Reduced end rootsOfUnity section cyclic namespace IsCyclic /-- The isomorphism from the group of group homomorphisms from a finite cyclic group `G` of order `n` into another group `G'` to the group of `n`th roots of unity in `G'` determined by a generator `g` of `G`. It sends `φ : G →* G'` to `φ g`. -/ noncomputable def monoidHomMulEquivRootsOfUnityOfGenerator {G : Type*} [CommGroup G] {g : G} (hg : ∀ (x : G), x ∈ Subgroup.zpowers g) (G' : Type*) [CommGroup G'] : (G →* G') ≃* rootsOfUnity (Nat.card G) G' where toFun φ := ⟨(IsUnit.map φ <| Group.isUnit g).unit, by simp only [mem_rootsOfUnity, Units.ext_iff, Units.val_pow_eq_pow_val, IsUnit.unit_spec, ← map_pow, pow_card_eq_one', map_one, Units.val_one]⟩ invFun ζ := monoidHomOfForallMemZpowers hg (g' := (ζ.val : G')) <| by simpa only [orderOf_eq_card_of_forall_mem_zpowers hg, orderOf_dvd_iff_pow_eq_one, ← Units.val_pow_eq_pow_val, Units.val_eq_one] using ζ.prop left_inv φ := (MonoidHom.eq_iff_eq_on_generator hg _ φ).mpr <| by simp only [IsUnit.unit_spec, monoidHomOfForallMemZpowers_apply_gen] right_inv φ := Subtype.ext <| by simp only [monoidHomOfForallMemZpowers_apply_gen, IsUnit.unit_of_val_units] map_mul' x y := by simp only [MonoidHom.mul_apply, MulMemClass.mk_mul_mk, Subtype.mk.injEq, Units.ext_iff, IsUnit.unit_spec, Units.val_mul] /-- The group of group homomorphisms from a finite cyclic group `G` of order `n` into another group `G'` is (noncanonically) isomorphic to the group of `n`th roots of unity in `G'`. -/ lemma monoidHom_mulEquiv_rootsOfUnity (G : Type*) [CommGroup G] [IsCyclic G] (G' : Type*) [CommGroup G'] : Nonempty <| (G →* G') ≃* rootsOfUnity (Nat.card G) G' := by obtain ⟨g, hg⟩ := IsCyclic.exists_generator (α := G) exact ⟨monoidHomMulEquivRootsOfUnityOfGenerator hg G'⟩ end IsCyclic end cyclic
.lake/packages/mathlib/Mathlib/RingTheory/RootsOfUnity/Complex.lean
import Mathlib.Analysis.SpecialFunctions.Complex.Log import Mathlib.RingTheory.RootsOfUnity.PrimitiveRoots import Mathlib.Tactic.Rify /-! # Complex roots of unity In this file we show that the `n`-th complex roots of unity are exactly the complex numbers `exp (2 * π * I * (i / n))` for `i ∈ Finset.range n`. ## Main declarations * `Complex.mem_rootsOfUnity`: the complex `n`-th roots of unity are exactly the complex numbers of the form `exp (2 * π * I * (i / n))` for some `i < n`. * `Complex.card_rootsOfUnity`: the number of `n`-th roots of unity is exactly `n`. * `Complex.norm_rootOfUnity_eq_one`: A complex root of unity has norm `1`. -/ namespace Complex open Polynomial Real open scoped Nat Real theorem isPrimitiveRoot_exp_of_coprime (i n : ℕ) (h0 : n ≠ 0) (hi : i.Coprime n) : IsPrimitiveRoot (exp (2 * π * I * (i / n))) n := by rw [IsPrimitiveRoot.iff_def] simp only [← exp_nat_mul, exp_eq_one_iff] constructor · use i simp (discharger := norm_cast) [field] · simp only [forall_exists_index] have hn0 : (n : ℂ) ≠ 0 := mod_cast h0 rintro l k hk field_simp at hk norm_cast at hk have : n ∣ l * i := by rw [← Int.natCast_dvd_natCast, hk]; apply dvd_mul_right exact hi.symm.dvd_of_dvd_mul_right this theorem isPrimitiveRoot_exp (n : ℕ) (h0 : n ≠ 0) : IsPrimitiveRoot (exp (2 * π * I / n)) n := by simpa only [Nat.cast_one, one_div] using isPrimitiveRoot_exp_of_coprime 1 n h0 n.coprime_one_left theorem isPrimitiveRoot_iff (ζ : ℂ) (n : ℕ) (hn : n ≠ 0) : IsPrimitiveRoot ζ n ↔ ∃ i < n, ∃ _ : i.Coprime n, exp (2 * π * I * (i / n)) = ζ := by have hn0 : (n : ℂ) ≠ 0 := mod_cast hn constructor; swap · rintro ⟨i, -, hi, rfl⟩; exact isPrimitiveRoot_exp_of_coprime i n hn hi intro h have : NeZero n := ⟨hn⟩ obtain ⟨i, hi, rfl⟩ := (isPrimitiveRoot_exp n hn).eq_pow_of_pow_eq_one h.pow_eq_one refine ⟨i, hi, ((isPrimitiveRoot_exp n hn).pow_iff_coprime (Nat.pos_of_ne_zero hn) i).mp h, ?_⟩ rw [← exp_nat_mul] congr 1 ring /-- The complex `n`-th roots of unity are exactly the complex numbers of the form `exp (2 * Real.pi * Complex.I * (i / n))` for some `i < n`. -/ nonrec theorem mem_rootsOfUnity (n : ℕ) [NeZero n] (x : Units ℂ) : x ∈ rootsOfUnity n ℂ ↔ ∃ i < n, exp (2 * π * I * (i / n)) = x := by rw [mem_rootsOfUnity, Units.ext_iff, Units.val_pow_eq_pow_val, Units.val_one] have hn0 : (n : ℂ) ≠ 0 := mod_cast NeZero.out constructor · intro h obtain ⟨i, hi, H⟩ : ∃ i < (n : ℕ), exp (2 * π * I / n) ^ i = x := by simpa only using (isPrimitiveRoot_exp n NeZero.out).eq_pow_of_pow_eq_one h refine ⟨i, hi, ?_⟩ rw [← H, ← exp_nat_mul] congr 1 ring · rintro ⟨i, _, H⟩ rw [← H, ← exp_nat_mul, exp_eq_one_iff] use i simp [field] theorem card_rootsOfUnity (n : ℕ) [NeZero n] : Fintype.card (rootsOfUnity n ℂ) = n := (isPrimitiveRoot_exp n NeZero.out).card_rootsOfUnity theorem card_primitiveRoots (k : ℕ) : (primitiveRoots k ℂ).card = φ k := by by_cases h : k = 0 · simp [h] exact (isPrimitiveRoot_exp k h).card_primitiveRoots end Complex theorem IsPrimitiveRoot.norm'_eq_one {ζ : ℂ} {n : ℕ} (h : IsPrimitiveRoot ζ n) (hn : n ≠ 0) : ‖ζ‖ = 1 := Complex.norm_eq_one_of_pow_eq_one h.pow_eq_one hn theorem IsPrimitiveRoot.nnnorm_eq_one {ζ : ℂ} {n : ℕ} (h : IsPrimitiveRoot ζ n) (hn : n ≠ 0) : ‖ζ‖₊ = 1 := Subtype.ext <| h.norm'_eq_one hn theorem IsPrimitiveRoot.arg_ext {n m : ℕ} {ζ μ : ℂ} (hζ : IsPrimitiveRoot ζ n) (hμ : IsPrimitiveRoot μ m) (hn : n ≠ 0) (hm : m ≠ 0) (h : ζ.arg = μ.arg) : ζ = μ := Complex.ext_norm_arg ((hζ.norm'_eq_one hn).trans (hμ.norm'_eq_one hm).symm) h theorem IsPrimitiveRoot.arg_eq_zero_iff {n : ℕ} {ζ : ℂ} (hζ : IsPrimitiveRoot ζ n) (hn : n ≠ 0) : ζ.arg = 0 ↔ ζ = 1 := ⟨fun h => hζ.arg_ext IsPrimitiveRoot.one hn one_ne_zero (h.trans Complex.arg_one.symm), fun h => h.symm ▸ Complex.arg_one⟩ theorem IsPrimitiveRoot.arg_eq_pi_iff {n : ℕ} {ζ : ℂ} (hζ : IsPrimitiveRoot ζ n) (hn : n ≠ 0) : ζ.arg = Real.pi ↔ ζ = -1 := ⟨fun h => hζ.arg_ext (IsPrimitiveRoot.neg_one 0 two_ne_zero.symm) hn two_ne_zero (h.trans Complex.arg_neg_one.symm), fun h => h.symm ▸ Complex.arg_neg_one⟩ theorem IsPrimitiveRoot.arg {n : ℕ} {ζ : ℂ} (h : IsPrimitiveRoot ζ n) (hn : n ≠ 0) : ∃ i : ℤ, ζ.arg = i / n * (2 * Real.pi) ∧ IsCoprime i n ∧ i.natAbs < n := by rw [Complex.isPrimitiveRoot_iff _ _ hn] at h obtain ⟨i, h, hin, rfl⟩ := h rw [mul_comm, ← mul_assoc, Complex.exp_mul_I] refine ⟨if i * 2 ≤ n then i else i - n, ?_, ?isCoprime, by cutsat⟩ case isCoprime => replace hin := Nat.isCoprime_iff_coprime.mpr hin split_ifs · exact hin · convert hin.add_mul_left_left (-1) using 1 rw [mul_neg_one, sub_eq_add_neg] split_ifs with h₂ · convert Complex.arg_cos_add_sin_mul_I _ · push_cast; rfl · push_cast; rfl simp only [Int.cast_natCast, Set.mem_Ioc] refine ⟨(neg_lt_neg Real.pi_pos).trans_le ?_, ?_⟩ · rw [neg_zero] positivity refine Eq.trans_le (b := Real.pi * (i * 2 / n)) (by ring) ?_ rw [← mul_one n] at h₂ exact mul_le_of_le_one_right Real.pi_pos.le ((div_le_iff₀' <| mod_cast pos_of_gt h).mpr <| mod_cast h₂) rw [← Complex.cos_sub_two_pi, ← Complex.sin_sub_two_pi] convert Complex.arg_cos_add_sin_mul_I _ · push_cast rw [← sub_one_mul, sub_div, div_self] exact mod_cast hn · push_cast rw [← sub_one_mul, sub_div, div_self] exact mod_cast hn simp only [Int.cast_sub, Int.cast_natCast, Set.mem_Ioc] field_simp constructor · push_neg at h₂ rify at h₂ linear_combination h₂ · rify at h linear_combination 2 * h + (n:ℝ) * one_pos (α := ℝ) lemma Complex.norm_eq_one_of_mem_rootsOfUnity {ζ : ℂˣ} {n : ℕ} [NeZero n] (hζ : ζ ∈ rootsOfUnity n ℂ) : ‖(ζ : ℂ)‖ = 1 := by refine norm_eq_one_of_pow_eq_one ?_ <| NeZero.ne n norm_cast rw [_root_.mem_rootsOfUnity] at hζ rw [hζ, Units.val_one] theorem Complex.conj_rootsOfUnity {ζ : ℂˣ} {n : ℕ} [NeZero n] (hζ : ζ ∈ rootsOfUnity n ℂ) : (starRingEnd ℂ) ζ = ζ⁻¹ := by rw [← Units.mul_eq_one_iff_eq_inv, conj_mul', norm_eq_one_of_mem_rootsOfUnity hζ, ofReal_one, one_pow]
.lake/packages/mathlib/Mathlib/RingTheory/RootsOfUnity/PrimitiveRoots.lean
import Mathlib.Data.Nat.Factorization.LCM import Mathlib.Algebra.Group.TypeTags.Finite import Mathlib.RingTheory.RootsOfUnity.Basic /-! # Primitive roots of unity We define a predicate `IsPrimitiveRoot` on commutative monoids, expressing that an element is a primitive root of unity. ## Main definitions * `IsPrimitiveRoot ζ k`: an element `ζ` is a primitive `k`-th root of unity if `ζ ^ k = 1`, and if `l` satisfies `ζ ^ l = 1` then `k ∣ l`. * `primitiveRoots k R`: the finset of primitive `k`-th roots of unity in an integral domain `R`. * `IsPrimitiveRoot.autToPow`: the monoid hom that takes an automorphism of a ring to the power it sends that specific primitive root, as a member of `(ZMod n)ˣ`. ## Main results * `IsPrimitiveRoot.zmodEquivZPowers`: `ZMod k` is equivalent to the subgroup generated by a primitive `k`-th root of unity. * `IsPrimitiveRoot.zpowers_eq`: in an integral domain, the subgroup generated by a primitive `k`-th root of unity is equal to the `k`-th roots of unity. * `IsPrimitiveRoot.card_primitiveRoots`: if an integral domain has a primitive `k`-th root of unity, then it has `φ k` of them. ## Implementation details For primitive roots of unity, it is desirable to have a predicate not just on units, but directly on elements of the ring/field. For example, we want to say that `exp (2 * pi * I / n)` is a primitive `n`-th root of unity in the complex numbers, without having to turn that number into a unit first. This creates a little bit of friction with how `rootsOfUnity` is implemented (as a subgroup of the `Units`), but lemmas like `IsPrimitiveRoot.isUnit` and `IsPrimitiveRoot.coe_units_iff` should provide the necessary glue. -/ noncomputable section open Polynomial Finset variable {M N G R S F : Type*} [CommMonoid M] [CommMonoid N] [DivisionCommMonoid G] /-- An element `ζ` is a primitive `k`-th root of unity if `ζ ^ k = 1`, and if `l` satisfies `ζ ^ l = 1` then `k ∣ l`. -/ @[mk_iff IsPrimitiveRoot.iff_def] structure IsPrimitiveRoot (ζ : M) (k : ℕ) : Prop where pow_eq_one : ζ ^ k = 1 dvd_of_pow_eq_one : ∀ l : ℕ, ζ ^ l = 1 → k ∣ l /-- Turn a primitive root μ into a member of the `rootsOfUnity` subgroup. -/ @[simps!] def IsPrimitiveRoot.toRootsOfUnity {μ : M} {n : ℕ} [NeZero n] (h : IsPrimitiveRoot μ n) : rootsOfUnity n M := rootsOfUnity.mkOfPowEq μ h.pow_eq_one section primitiveRoots variable {k : ℕ} open scoped Classical in /-- `primitiveRoots k R` is the finset of primitive `k`-th roots of unity in the integral domain `R`. -/ def primitiveRoots (k : ℕ) (R : Type*) [CommRing R] [IsDomain R] : Finset R := {ζ ∈ (nthRoots k (1 : R)).toFinset | IsPrimitiveRoot ζ k} variable [CommRing R] [IsDomain R] -- TODO?: replace `(h0 : 0 < k)` by `[NeZero k]` @[simp] theorem mem_primitiveRoots {ζ : R} (h0 : 0 < k) : ζ ∈ primitiveRoots k R ↔ IsPrimitiveRoot ζ k := by classical rw [primitiveRoots, mem_filter, Multiset.mem_toFinset, mem_nthRoots h0, and_iff_right_iff_imp] exact IsPrimitiveRoot.pow_eq_one @[simp] theorem primitiveRoots_zero : primitiveRoots 0 R = ∅ := by classical rw [primitiveRoots, nthRoots_zero, Multiset.toFinset_zero, Finset.filter_empty] theorem isPrimitiveRoot_of_mem_primitiveRoots {ζ : R} (h : ζ ∈ primitiveRoots k R) : IsPrimitiveRoot ζ k := k.eq_zero_or_pos.elim (fun hk ↦ by simp [hk] at h) fun hk ↦ (mem_primitiveRoots hk).1 h end primitiveRoots namespace IsPrimitiveRoot variable {k l : ℕ} theorem mk_of_lt (ζ : M) (hk : 0 < k) (h1 : ζ ^ k = 1) (h : ∀ l : ℕ, 0 < l → l < k → ζ ^ l ≠ 1) : IsPrimitiveRoot ζ k := by refine ⟨h1, fun l hl ↦ ?_⟩ suffices k.gcd l = k by exact this ▸ k.gcd_dvd_right l rw [eq_iff_le_not_lt] refine ⟨Nat.le_of_dvd hk (k.gcd_dvd_left l), ?_⟩ intro h'; apply h _ (Nat.gcd_pos_of_pos_left _ hk) h' exact pow_gcd_eq_one _ h1 hl section CommMonoid variable {ζ : M} {f : F} @[nontriviality] theorem of_subsingleton [Subsingleton M] (x : M) : IsPrimitiveRoot x 1 := ⟨Subsingleton.elim _ _, fun _ _ ↦ one_dvd _⟩ theorem pow_eq_one_iff_dvd (h : IsPrimitiveRoot ζ k) (l : ℕ) : ζ ^ l = 1 ↔ k ∣ l := ⟨h.dvd_of_pow_eq_one l, by rintro ⟨i, rfl⟩; simp only [pow_mul, h.pow_eq_one, one_pow]⟩ theorem isUnit (h : IsPrimitiveRoot ζ k) (h0 : k ≠ 0) : IsUnit ζ := .of_mul_eq_one (ζ ^ (k - 1)) <| by rw [← pow_succ', Nat.sub_one_add_one h0, h.pow_eq_one] theorem pow_ne_one_of_pos_of_lt (h : IsPrimitiveRoot ζ k) (h0 : l ≠ 0) (hl : l < k) : ζ ^ l ≠ 1 := mt (Nat.le_of_dvd (Nat.pos_iff_ne_zero.mpr h0) ∘ h.dvd_of_pow_eq_one _) <| not_le_of_gt hl theorem ne_one (h : IsPrimitiveRoot ζ k) (hk : 1 < k) : ζ ≠ 1 := h.pow_ne_one_of_pos_of_lt one_ne_zero hk ∘ (pow_one ζ).trans theorem pow_inj (h : IsPrimitiveRoot ζ k) ⦃i j : ℕ⦄ (hi : i < k) (hj : j < k) (H : ζ ^ i = ζ ^ j) : i = j := by wlog hij : i ≤ j generalizing i j · exact (this hj hi H.symm (le_of_not_ge hij)).symm apply le_antisymm hij rw [← tsub_eq_zero_iff_le] apply Nat.eq_zero_of_dvd_of_lt _ (lt_of_le_of_lt tsub_le_self hj) apply h.dvd_of_pow_eq_one rw [← ((h.isUnit (Nat.ne_zero_of_lt hi)).pow i).mul_left_inj, ← pow_add, tsub_add_cancel_of_le hij, H, one_mul] theorem one : IsPrimitiveRoot (1 : M) 1 := { pow_eq_one := pow_one _ dvd_of_pow_eq_one := fun _ _ ↦ one_dvd _ } @[simp] theorem one_right_iff : IsPrimitiveRoot ζ 1 ↔ ζ = 1 := by constructor · intro h; rw [← pow_one ζ, h.pow_eq_one] · rintro rfl; exact one @[simp] theorem coe_submonoidClass_iff {M B : Type*} [CommMonoid M] [SetLike B M] [SubmonoidClass B M] {N : B} {ζ : N} : IsPrimitiveRoot (ζ : M) k ↔ IsPrimitiveRoot ζ k := by simp_rw [iff_def] norm_cast @[simp] theorem coe_units_iff {ζ : Mˣ} : IsPrimitiveRoot (ζ : M) k ↔ IsPrimitiveRoot ζ k := by simp only [iff_def, Units.ext_iff, Units.val_pow_eq_pow_val, Units.val_one] lemma isUnit_unit {ζ : M} {n} (hn) (hζ : IsPrimitiveRoot ζ n) : IsPrimitiveRoot (hζ.isUnit hn).unit n := coe_units_iff.mp hζ lemma isUnit_unit' {ζ : G} {n} (hn) (hζ : IsPrimitiveRoot ζ n) : IsPrimitiveRoot (hζ.isUnit hn).unit' n := coe_units_iff.mp hζ theorem pow_of_coprime (h : IsPrimitiveRoot ζ k) (i : ℕ) (hi : i.Coprime k) : IsPrimitiveRoot (ζ ^ i) k := by by_cases h0 : k = 0 · subst k; simp_all only [pow_one, Nat.coprime_zero_right] rcases h.isUnit h0 with ⟨ζ, rfl⟩ rw [← Units.val_pow_eq_pow_val] rw [coe_units_iff] at h ⊢ refine { pow_eq_one := by rw [← pow_mul', pow_mul, h.pow_eq_one, one_pow] dvd_of_pow_eq_one := fun l hl ↦ h.dvd_of_pow_eq_one l ?_ } rw [← pow_one ζ, ← zpow_natCast ζ, ← hi.gcd_eq_one, Nat.gcd_eq_gcd_ab, zpow_add, mul_pow, ← zpow_natCast, ← zpow_mul, mul_right_comm] simp only [zpow_mul, hl, h.pow_eq_one, one_zpow, one_pow, one_mul, zpow_natCast] theorem pow_of_prime (h : IsPrimitiveRoot ζ k) {p : ℕ} (hprime : Nat.Prime p) (hdiv : ¬p ∣ k) : IsPrimitiveRoot (ζ ^ p) k := h.pow_of_coprime p (hprime.coprime_iff_not_dvd.2 hdiv) theorem pow_iff_coprime (h : IsPrimitiveRoot ζ k) (h0 : 0 < k) (i : ℕ) : IsPrimitiveRoot (ζ ^ i) k ↔ i.Coprime k := by refine ⟨fun hi ↦ ?_, h.pow_of_coprime i⟩ obtain ⟨a, ha⟩ := i.gcd_dvd_left k obtain ⟨b, hb⟩ := i.gcd_dvd_right k suffices b = k by rwa [this, eq_comm, Nat.mul_eq_right h0.ne', ← Nat.coprime_iff_gcd_eq_one] at hb rw [ha] at hi rw [mul_comm] at hb apply Nat.dvd_antisymm ⟨i.gcd k, hb⟩ (hi.dvd_of_pow_eq_one b _) rw [← pow_mul', ← mul_assoc, ← hb, pow_mul, h.pow_eq_one, one_pow] protected theorem orderOf (ζ : M) : IsPrimitiveRoot ζ (orderOf ζ) := ⟨pow_orderOf_eq_one ζ, fun _ ↦ orderOf_dvd_of_pow_eq_one⟩ theorem unique {ζ : M} (hk : IsPrimitiveRoot ζ k) (hl : IsPrimitiveRoot ζ l) : k = l := Nat.dvd_antisymm (hk.2 _ hl.1) (hl.2 _ hk.1) theorem eq_orderOf (h : IsPrimitiveRoot ζ k) : k = orderOf ζ := h.unique (IsPrimitiveRoot.orderOf ζ) protected theorem iff (hk : 0 < k) : IsPrimitiveRoot ζ k ↔ ζ ^ k = 1 ∧ ∀ l : ℕ, 0 < l → l < k → ζ ^ l ≠ 1 := by refine ⟨fun h ↦ ⟨h.pow_eq_one, fun l hl' hl ↦ ?_⟩, fun ⟨hζ, hl⟩ ↦ IsPrimitiveRoot.mk_of_lt ζ hk hζ hl⟩ rw [h.eq_orderOf] at hl exact pow_ne_one_of_lt_orderOf hl'.ne' hl protected theorem not_iff : ¬IsPrimitiveRoot ζ k ↔ orderOf ζ ≠ k := ⟨fun h hk ↦ h <| hk ▸ IsPrimitiveRoot.orderOf ζ, fun h hk ↦ h.symm <| hk.unique <| IsPrimitiveRoot.orderOf ζ⟩ protected theorem iff_orderOf : IsPrimitiveRoot ζ k ↔ orderOf ζ = k := not_iff_not.mp IsPrimitiveRoot.not_iff theorem pow_mul_pow_lcm {ζ' : M} {k' : ℕ} (hζ : IsPrimitiveRoot ζ k) (hζ' : IsPrimitiveRoot ζ' k') (hk : k ≠ 0) (hk' : k' ≠ 0) : IsPrimitiveRoot (ζ ^ (k / Nat.factorizationLCMLeft k k') * ζ' ^ (k' / Nat.factorizationLCMRight k k')) (Nat.lcm k k') := by convert IsPrimitiveRoot.orderOf _ convert ((Commute.all ζ ζ').orderOf_mul_pow_eq_lcm (by simpa [← hζ.eq_orderOf]) (by simpa [← hζ'.eq_orderOf])).symm using 2 all_goals simp [hζ.eq_orderOf, hζ'.eq_orderOf] theorem pow_of_dvd (h : IsPrimitiveRoot ζ k) {p : ℕ} (hp : p ≠ 0) (hdiv : p ∣ k) : IsPrimitiveRoot (ζ ^ p) (k / p) := by rw [h.eq_orderOf] at hdiv ⊢ rw [← orderOf_pow_of_dvd hp hdiv] exact IsPrimitiveRoot.orderOf _ protected theorem mem_rootsOfUnity {ζ : Mˣ} {n : ℕ} (h : IsPrimitiveRoot ζ n) : ζ ∈ rootsOfUnity n M := h.pow_eq_one /-- If there is an `n`-th primitive root of unity in `R` and `b` divides `n`, then there is a `b`-th primitive root of unity in `R`. -/ theorem pow {n : ℕ} {a b : ℕ} (hn : 0 < n) (h : IsPrimitiveRoot ζ n) (hprod : n = a * b) : IsPrimitiveRoot (ζ ^ a) b := by subst n simp only [iff_def, ← pow_mul, h.pow_eq_one, true_and] intro l hl exact Nat.dvd_of_mul_dvd_mul_left (Nat.pos_of_mul_pos_right hn) <| h.dvd_of_pow_eq_one _ hl lemma injOn_pow {n : ℕ} {ζ : M} (hζ : IsPrimitiveRoot ζ n) : Set.InjOn (ζ ^ ·) (Finset.range n) := by intro i hi j hj e rw [Finset.coe_range, Set.mem_Iio] at hi hj exact hζ.pow_inj hi hj e lemma exists_pos {k : ℕ} (hζ : ζ ^ k = 1) (hk : k ≠ 0) : ∃ k' > 0, IsPrimitiveRoot ζ k' := ⟨orderOf ζ, by rw [gt_iff_lt, orderOf_pos_iff, isOfFinOrder_iff_pow_eq_one] exact ⟨k, Nat.pos_iff_ne_zero.mpr hk, hζ⟩, .orderOf _⟩ lemma existsUnique : ∃! k, IsPrimitiveRoot ζ k := ⟨_, .orderOf _, fun _ hl ↦ unique hl (.orderOf _)⟩ theorem _root_.isPrimitiveRoot_of_mem_rootsOfUnity {u : Mˣ} {n : ℕ} [NeZero n] (hu : u ∈ rootsOfUnity n M) : ∃ d : ℕ, d ≠ 0 ∧ d ∣ n ∧ IsPrimitiveRoot u d := ⟨orderOf u, (IsOfFinOrder.orderOf_pos ⟨n, NeZero.pos n, (isPeriodicPt_mul_iff_pow_eq_one u).mpr hu⟩).ne', orderOf_dvd_of_pow_eq_one hu, IsPrimitiveRoot.orderOf u⟩ section Maps open Function variable [FunLike F M N] theorem map_of_injective [MonoidHomClass F M N] (h : IsPrimitiveRoot ζ k) (hf : Injective f) : IsPrimitiveRoot (f ζ) k where pow_eq_one := by rw [← map_pow, h.pow_eq_one, map_one] dvd_of_pow_eq_one := by rw [h.eq_orderOf] intro l hl rw [← map_pow, ← map_one f] at hl exact orderOf_dvd_of_pow_eq_one (hf hl) theorem of_map_of_injective [MonoidHomClass F M N] (h : IsPrimitiveRoot (f ζ) k) (hf : Injective f) : IsPrimitiveRoot ζ k where pow_eq_one := by apply_fun f; rw [map_pow, map_one, h.pow_eq_one] dvd_of_pow_eq_one := by rw [h.eq_orderOf] intro l hl apply_fun f at hl rw [map_pow, map_one] at hl exact orderOf_dvd_of_pow_eq_one hl theorem map_iff_of_injective [MonoidHomClass F M N] (hf : Injective f) : IsPrimitiveRoot (f ζ) k ↔ IsPrimitiveRoot ζ k := ⟨fun h => h.of_map_of_injective hf, fun h => h.map_of_injective hf⟩ end Maps end CommMonoid section CommMonoidWithZero variable {M₀ : Type*} [CommMonoidWithZero M₀] theorem zero [Nontrivial M₀] : IsPrimitiveRoot (0 : M₀) 0 := ⟨pow_zero 0, fun l hl ↦ by simpa [zero_pow_eq] using hl⟩ protected theorem ne_zero [Nontrivial M₀] {ζ : M₀} (h : IsPrimitiveRoot ζ k) : k ≠ 0 → ζ ≠ 0 := mt fun hn ↦ h.unique (hn.symm ▸ IsPrimitiveRoot.zero) end CommMonoidWithZero section CancelCommMonoidWithZero variable {M₀ : Type*} [CancelCommMonoidWithZero M₀] lemma injOn_pow_mul {n : ℕ} {ζ : M₀} (hζ : IsPrimitiveRoot ζ n) {α : M₀} (hα : α ≠ 0) : Set.InjOn (ζ ^ · * α) (Finset.range n) := fun i hi j hj e ↦ hζ.injOn_pow hi hj (by simpa [mul_eq_mul_right_iff, or_iff_left hα] using e) end CancelCommMonoidWithZero section DivisionCommMonoid variable {ζ : G} theorem zpow_eq_one (h : IsPrimitiveRoot ζ k) : ζ ^ (k : ℤ) = 1 := by exact_mod_cast h.pow_eq_one theorem zpow_eq_one_iff_dvd (h : IsPrimitiveRoot ζ k) (l : ℤ) : ζ ^ l = 1 ↔ (k : ℤ) ∣ l := by by_cases h0 : 0 ≤ l · lift l to ℕ using h0; exact_mod_cast h.pow_eq_one_iff_dvd l · have : 0 ≤ -l := (Int.neg_pos_of_neg <| Int.lt_of_not_ge h0).le lift -l to ℕ using this with l' hl' rw [← dvd_neg, ← hl'] norm_cast rw [← h.pow_eq_one_iff_dvd, ← inv_inj, ← zpow_neg, ← hl', zpow_natCast, inv_one] theorem inv (h : IsPrimitiveRoot ζ k) : IsPrimitiveRoot ζ⁻¹ k := { pow_eq_one := by simp only [h.pow_eq_one, inv_one, inv_pow] dvd_of_pow_eq_one := by intro l hl apply h.dvd_of_pow_eq_one l rw [← inv_inj, ← inv_pow, hl, inv_one] } @[simp] theorem inv_iff : IsPrimitiveRoot ζ⁻¹ k ↔ IsPrimitiveRoot ζ k := ⟨fun h ↦ inv_inv ζ ▸ inv h, fun h ↦ inv h⟩ theorem zpow_of_gcd_eq_one (h : IsPrimitiveRoot ζ k) (i : ℤ) (hi : i.gcd k = 1) : IsPrimitiveRoot (ζ ^ i) k := by by_cases h0 : 0 ≤ i · lift i to ℕ using h0 exact_mod_cast h.pow_of_coprime i hi have : 0 ≤ -i := (Int.neg_pos_of_neg <| Int.lt_of_not_ge h0).le lift -i to ℕ using this with i' hi' rw [← inv_iff, ← zpow_neg, ← hi', zpow_natCast] apply h.pow_of_coprime rwa [Int.gcd, ← Int.natAbs_neg, ← hi'] at hi end DivisionCommMonoid section CommRing variable [CommRing R] {n : ℕ} {ζ : R} theorem sub_one_ne_zero (hn : 1 < n) (hζ : IsPrimitiveRoot ζ n) : ζ - 1 ≠ 0 := sub_ne_zero.mpr <| hζ.ne_one hn end CommRing section IsDomain variable {ζ : R} [CommRing R] [IsDomain R] @[simp] theorem primitiveRoots_one : primitiveRoots 1 R = {(1 : R)} := by refine Finset.eq_singleton_iff_unique_mem.2 ⟨?_, fun x hx ↦ ?_⟩ · simp only [IsPrimitiveRoot.one_right_iff, mem_primitiveRoots zero_lt_one] · rwa [mem_primitiveRoots zero_lt_one, IsPrimitiveRoot.one_right_iff] at hx theorem neZero' {n : ℕ} [NeZero n] (hζ : IsPrimitiveRoot ζ n) : NeZero ((n : ℕ) : R) := by let p := ringChar R refine .of_not_dvd R (p := p) fun hpn ↦ ?_ obtain ⟨n, rfl⟩ := hpn have h : p ≠ 0 ∧ n ≠ 0 := by aesop have : NeZero p := .mk h.1 have hp : Fact p.Prime := CharP.char_is_prime_of_pos R p refine (hζ.pow_ne_one_of_pos_of_lt h.2 (lt_mul_of_one_lt_left (by grind) hp.1.one_lt) <| frobenius_inj R p ?_).elim rw [frobenius_def, ← pow_mul', hζ.1, map_one] nonrec theorem mem_nthRootsFinset (hζ : IsPrimitiveRoot ζ k) (hk : 0 < k) : ζ ∈ nthRootsFinset k (1 : R) := (mem_nthRootsFinset hk (1 : R)).2 hζ.pow_eq_one end IsDomain section IsDomain variable [CommRing R] {ζ : Rˣ} (h : IsPrimitiveRoot ζ k) theorem eq_neg_one_of_two_right [NoZeroDivisors R] {ζ : R} (h : IsPrimitiveRoot ζ 2) : ζ = -1 := (sq_eq_one_iff.mp h.pow_eq_one).resolve_left <| ne_one h one_lt_two theorem neg_one (p : ℕ) [Nontrivial R] [h : CharP R p] (hp : p ≠ 2) : IsPrimitiveRoot (-1 : R) 2 := by convert IsPrimitiveRoot.orderOf (-1 : R) rw [orderOf_neg_one, if_neg <| by rwa [ringChar.eq_iff.mpr h]] /-- If `1 < k` then `(∑ i ∈ range k, ζ ^ i) = 0`. -/ theorem geom_sum_eq_zero [IsDomain R] {ζ : R} (hζ : IsPrimitiveRoot ζ k) (hk : 1 < k) : ∑ i ∈ range k, ζ ^ i = 0 := by refine eq_zero_of_ne_zero_of_mul_left_eq_zero (sub_ne_zero_of_ne (hζ.ne_one hk).symm) ?_ rw [mul_neg_geom_sum, hζ.pow_eq_one, sub_self] /-- If `1 < k`, then `ζ ^ k.pred = -(∑ i ∈ range k.pred, ζ ^ i)`. -/ theorem pow_sub_one_eq [IsDomain R] {ζ : R} (hζ : IsPrimitiveRoot ζ k) (hk : 1 < k) : ζ ^ k.pred = -∑ i ∈ range k.pred, ζ ^ i := by rw [eq_neg_iff_add_eq_zero, add_comm, ← sum_range_succ, ← Nat.succ_eq_add_one, Nat.succ_pred_eq_of_pos (pos_of_gt hk), hζ.geom_sum_eq_zero hk] /-- The (additive) monoid equivalence between `ZMod k` and the powers of a primitive root of unity `ζ`. -/ def zmodEquivZPowers (h : IsPrimitiveRoot ζ k) : ZMod k ≃+ Additive (Subgroup.zpowers ζ) := AddEquiv.ofBijective (AddMonoidHom.liftOfRightInverse (Int.castAddHom <| ZMod k) _ ZMod.intCast_rightInverse ⟨{ toFun := fun i ↦ Additive.ofMul (⟨_, i, rfl⟩ : Subgroup.zpowers ζ) map_zero' := by simp only [zpow_zero]; rfl map_add' := by intro i j; simp only [zpow_add]; rfl }, fun i hi ↦ by simp only [AddMonoidHom.mem_ker, CharP.intCast_eq_zero_iff (ZMod k) k, AddMonoidHom.coe_mk, Int.coe_castAddHom] at hi ⊢ obtain ⟨i, rfl⟩ := hi simp [zpow_mul, h.pow_eq_one, one_zpow, zpow_natCast]⟩) (by constructor · rw [injective_iff_map_eq_zero] intro i hi rw [Subtype.ext_iff] at hi have := (h.zpow_eq_one_iff_dvd _).mp hi rw [← (CharP.intCast_eq_zero_iff (ZMod k) k _).mpr this, eq_comm] exact ZMod.intCast_rightInverse i · rintro ⟨ξ, i, rfl⟩ refine ⟨Int.castAddHom (ZMod k) i, ?_⟩ rw [AddMonoidHom.liftOfRightInverse_comp_apply] rfl) @[simp] theorem zmodEquivZPowers_apply_coe_int (i : ℤ) : h.zmodEquivZPowers i = Additive.ofMul (⟨ζ ^ i, i, rfl⟩ : Subgroup.zpowers ζ) := by rw [zmodEquivZPowers, AddEquiv.ofBijective_apply] -- Porting note: Original proof didn't have `rw` exact AddMonoidHom.liftOfRightInverse_comp_apply _ _ ZMod.intCast_rightInverse _ _ @[simp] theorem zmodEquivZPowers_apply_coe_nat (i : ℕ) : h.zmodEquivZPowers i = Additive.ofMul (⟨ζ ^ i, i, rfl⟩ : Subgroup.zpowers ζ) := by have : (i : ZMod k) = (i : ℤ) := by norm_cast simp only [this, zmodEquivZPowers_apply_coe_int, zpow_natCast] @[simp] theorem zmodEquivZPowers_symm_apply_zpow (i : ℤ) : h.zmodEquivZPowers.symm (Additive.ofMul (⟨ζ ^ i, i, rfl⟩ : Subgroup.zpowers ζ)) = i := by rw [← h.zmodEquivZPowers.symm_apply_apply i, zmodEquivZPowers_apply_coe_int] @[simp] theorem zmodEquivZPowers_symm_apply_zpow' (i : ℤ) : h.zmodEquivZPowers.symm ⟨ζ ^ i, i, rfl⟩ = i := h.zmodEquivZPowers_symm_apply_zpow i @[simp] theorem zmodEquivZPowers_symm_apply_pow (i : ℕ) : h.zmodEquivZPowers.symm (Additive.ofMul (⟨ζ ^ i, i, rfl⟩ : Subgroup.zpowers ζ)) = i := by rw [← h.zmodEquivZPowers.symm_apply_apply i, zmodEquivZPowers_apply_coe_nat] @[simp] theorem zmodEquivZPowers_symm_apply_pow' (i : ℕ) : h.zmodEquivZPowers.symm ⟨ζ ^ i, i, rfl⟩ = i := h.zmodEquivZPowers_symm_apply_pow i variable [IsDomain R] theorem zpowers_eq {k : ℕ} [NeZero k] {ζ : Rˣ} (h : IsPrimitiveRoot ζ k) : Subgroup.zpowers ζ = rootsOfUnity k R := by apply SetLike.coe_injective have F : Fintype (Subgroup.zpowers ζ) := Fintype.ofEquiv _ h.zmodEquivZPowers.toEquiv refine @Set.eq_of_subset_of_card_le Rˣ _ _ F (rootsOfUnity.fintype R k) (Subgroup.zpowers_le_of_mem <| show ζ ∈ rootsOfUnity k R from h.pow_eq_one) ?_ calc Fintype.card (rootsOfUnity k R) ≤ k := card_rootsOfUnity R k _ = Fintype.card (ZMod k) := (ZMod.card k).symm _ = Fintype.card (Subgroup.zpowers ζ) := Fintype.card_congr h.zmodEquivZPowers.toEquiv lemma map_rootsOfUnity {S F} [CommRing S] [IsDomain S] [FunLike F R S] [MonoidHomClass F R S] {ζ : R} {n : ℕ} [NeZero n] (hζ : IsPrimitiveRoot ζ n) {f : F} (hf : Function.Injective f) : (rootsOfUnity n R).map (Units.map f) = rootsOfUnity n S := by letI : CommMonoid Sˣ := inferInstance replace hζ := hζ.isUnit_unit NeZero.out rw [← hζ.zpowers_eq, ← (hζ.map_of_injective (Units.map_injective (f := (f : R →* S)) hf)).zpowers_eq, MonoidHom.map_zpowers] /-- If `R` contains an `n`-th primitive root, and `S/R` is a ring extension, then the `n`-th roots of unity in `R` and `S` are isomorphic. Also see `IsPrimitiveRoot.map_rootsOfUnity` for the equality as `Subgroup Sˣ`. -/ @[simps! -isSimp apply_coe_val apply_coe_inv_val] noncomputable def _root_.rootsOfUnityEquivOfPrimitiveRoots {S F} [CommRing S] [IsDomain S] [FunLike F R S] [MonoidHomClass F R S] {n : ℕ} [NeZero n] {f : F} (hf : Function.Injective f) (hζ : (primitiveRoots n R).Nonempty) : (rootsOfUnity n R) ≃* rootsOfUnity n S := (Subgroup.equivMapOfInjective _ (Units.map f) (Units.map_injective hf)).trans (MulEquiv.subgroupCongr <| ((mem_primitiveRoots <| NeZero.pos n).mp hζ.choose_spec).map_rootsOfUnity hf) lemma _root_.rootsOfUnityEquivOfPrimitiveRoots_symm_apply {S F} [CommRing S] [IsDomain S] [FunLike F R S] [MonoidHomClass F R S] {n : ℕ} [NeZero n] {f : F} (hf : Function.Injective f) (hζ : (primitiveRoots n R).Nonempty) (η) : f ((rootsOfUnityEquivOfPrimitiveRoots hf hζ).symm η : Rˣ) = (η : Sˣ) := by obtain ⟨ε, rfl⟩ := (rootsOfUnityEquivOfPrimitiveRoots hf hζ).surjective η rw [MulEquiv.symm_apply_apply, val_rootsOfUnityEquivOfPrimitiveRoots_apply_coe] theorem eq_pow_of_mem_rootsOfUnity {k : ℕ} [NeZero k] {ζ ξ : Rˣ} (h : IsPrimitiveRoot ζ k) (hξ : ξ ∈ rootsOfUnity k R) : ∃ i < k, ζ ^ i = ξ := by obtain ⟨n, rfl⟩ : ∃ n : ℤ, ζ ^ n = ξ := by rwa [← h.zpowers_eq] at hξ have hk0 : (0 : ℤ) < k := mod_cast NeZero.pos k let i := n % k have hi0 : 0 ≤ i := Int.emod_nonneg _ (ne_of_gt hk0) lift i to ℕ using hi0 with i₀ hi₀ refine ⟨i₀, ?_, ?_⟩ · zify; rw [hi₀]; exact Int.emod_lt_of_pos _ hk0 · rw [← zpow_natCast, hi₀, ← Int.emod_add_mul_ediv n k, zpow_add, zpow_mul, h.zpow_eq_one, one_zpow, mul_one] theorem eq_pow_of_pow_eq_one {k : ℕ} [NeZero k] {ζ ξ : R} (h : IsPrimitiveRoot ζ k) (hξ : ξ ^ k = 1) : ∃ i < k, ζ ^ i = ξ := by lift ζ to Rˣ using h.isUnit NeZero.out lift ξ to Rˣ using .of_pow_eq_one hξ <| NeZero.ne k simp only [← Units.val_pow_eq_pow_val, ← Units.ext_iff] rw [coe_units_iff] at h exact h.eq_pow_of_mem_rootsOfUnity <| (mem_rootsOfUnity' k ξ).mpr hξ theorem isPrimitiveRoot_iff' {k : ℕ} [NeZero k] {ζ ξ : Rˣ} (h : IsPrimitiveRoot ζ k) : IsPrimitiveRoot ξ k ↔ ∃ i < k, i.Coprime k ∧ ζ ^ i = ξ := by constructor · intro hξ obtain ⟨i, hik, rfl⟩ := h.eq_pow_of_mem_rootsOfUnity hξ.pow_eq_one rw [h.pow_iff_coprime <| NeZero.pos k] at hξ exact ⟨i, hik, hξ, rfl⟩ · rintro ⟨i, -, hi, rfl⟩; exact h.pow_of_coprime i hi theorem isPrimitiveRoot_iff {k : ℕ} [NeZero k] {ζ ξ : R} (h : IsPrimitiveRoot ζ k) : IsPrimitiveRoot ξ k ↔ ∃ i < k, i.Coprime k ∧ ζ ^ i = ξ := by constructor · intro hξ obtain ⟨i, hik, rfl⟩ := h.eq_pow_of_pow_eq_one hξ.pow_eq_one rw [h.pow_iff_coprime <| NeZero.pos k] at hξ exact ⟨i, hik, hξ, rfl⟩ · rintro ⟨i, -, hi, rfl⟩; exact h.pow_of_coprime i hi theorem nthRoots_eq {n : ℕ} {ζ : R} (hζ : IsPrimitiveRoot ζ n) {α a : R} (e : α ^ n = a) : nthRoots n a = (Multiset.range n).map (ζ ^ · * α) := by obtain (rfl | hn) := n.eq_zero_or_pos; · simp by_cases hα : α = 0 · rw [hα, zero_pow hn.ne'] at e simp only [hα, e.symm, nthRoots_zero_right, mul_zero, Multiset.map_const', Multiset.card_range] classical symm; apply Multiset.eq_of_le_of_card_le · rw [← Finset.range_val, ← Finset.image_val_of_injOn (hζ.injOn_pow_mul hα), Finset.val_le_iff_val_subset] intro x hx simp only [Finset.image_val, Finset.range_val, Multiset.mem_dedup, Multiset.mem_map, Multiset.mem_range] at hx obtain ⟨m, _, rfl⟩ := hx rw [mem_nthRoots hn, mul_pow, e, ← pow_mul, mul_comm m, pow_mul, hζ.pow_eq_one, one_pow, one_mul] · simpa only [Multiset.card_map, Multiset.card_range] using card_nthRoots n a /-- The sub-algebra generated by two roots of unity of order `k₁` and `k₂` resp. is the same as the one generated by a root of unity of order `lcm k₁ k₂`. See `IsPrimitiveRoot.pow_mul_pow_lcm` for how to construct a root of unity of order `lcm k₁ k₂` from roots of unity of order `k₁` and `k₂`. -/ theorem adjoin_pair_eq (S : Type*) [CommSemiring S] [Algebra S R] {ζ₁ ζ₂ : R} {k₁ : ℕ} {k₂ : ℕ} (hζ₁ : IsPrimitiveRoot ζ₁ k₁) (hζ₂ : IsPrimitiveRoot ζ₂ k₂) (hk₁ : k₁ ≠ 0) (hk₂ : k₂ ≠ 0) {ζ : R} (hζ : IsPrimitiveRoot ζ (k₁.lcm k₂)) : Algebra.adjoin S {ζ₁, ζ₂} = Algebra.adjoin S {ζ} := by have : NeZero (k₁.lcm k₂) := ⟨Nat.lcm_ne_zero hk₁ hk₂⟩ refine le_antisymm (Algebra.adjoin_le ?_) (Algebra.adjoin_le ?_) · refine Set.pair_subset_iff.mpr ⟨?_, ?_⟩ · obtain ⟨_, _, rfl⟩ := hζ.eq_pow_of_pow_eq_one <| (hζ₁.pow_eq_one_iff_dvd _).mpr <| k₁.dvd_lcm_left k₂ exact Subalgebra.pow_mem _ (Algebra.self_mem_adjoin_singleton S _) _ · obtain ⟨_, _, rfl⟩ := hζ.eq_pow_of_pow_eq_one <| (hζ₂.pow_eq_one_iff_dvd _).mpr <| k₁.dvd_lcm_right k₂ exact Subalgebra.pow_mem _ (Algebra.self_mem_adjoin_singleton S _) _ · have hζ' := IsPrimitiveRoot.pow_mul_pow_lcm hζ₁ hζ₂ hk₁ hk₂ obtain ⟨_, _, rfl⟩ := hζ'.eq_pow_of_pow_eq_one hζ.pow_eq_one aesop open scoped Classical in theorem card_nthRoots {n : ℕ} {ζ : R} (hζ : IsPrimitiveRoot ζ n) (a : R) : Multiset.card (nthRoots n a) = if ∃ α, α ^ n = a then n else 0 := by split_ifs with h · obtain ⟨α, hα⟩ := h rw [nthRoots_eq hζ hα, Multiset.card_map, Multiset.card_range] · obtain (rfl | hn) := n.eq_zero_or_pos; · simp push_neg at h simpa only [Multiset.card_eq_zero, Multiset.eq_zero_iff_forall_notMem, mem_nthRoots hn] /-- A variant of `IsPrimitiveRoot.card_rootsOfUnity` for `ζ : Rˣ`. -/ theorem card_rootsOfUnity' {n : ℕ} [NeZero n] (h : IsPrimitiveRoot ζ n) : Fintype.card (rootsOfUnity n R) = n := by let e := h.zmodEquivZPowers have : Fintype (Subgroup.zpowers ζ) := Fintype.ofEquiv _ e.toEquiv calc Fintype.card (rootsOfUnity n R) = Fintype.card (Subgroup.zpowers ζ) := Fintype.card_congr <| by rw [h.zpowers_eq] _ = Fintype.card (ZMod n) := Fintype.card_congr e.toEquiv.symm _ = n := ZMod.card n theorem card_rootsOfUnity {ζ : R} {n : ℕ} [NeZero n] (h : IsPrimitiveRoot ζ n) : Fintype.card (rootsOfUnity n R) = n := by obtain ⟨ζ, hζ⟩ := h.isUnit NeZero.out rw [← hζ, IsPrimitiveRoot.coe_units_iff] at h exact h.card_rootsOfUnity' lemma _root_.card_rootsOfUnity_eq_iff_exists_isPrimitiveRoot {n : ℕ} [NeZero n] : Fintype.card (rootsOfUnity n R) = n ↔ ∃ ζ : R, IsPrimitiveRoot ζ n := by refine ⟨fun h ↦ ?_, fun ⟨ζ, hζ⟩ ↦ hζ.card_rootsOfUnity⟩ obtain ⟨⟨ζ, hζ'⟩, hζ⟩ := (rootsOfUnity.isCyclic R n).exists_ofOrder_eq_natCard rw [Nat.card_eq_fintype_card, h, ← IsPrimitiveRoot.iff_orderOf, ← coe_submonoidClass_iff, ← IsPrimitiveRoot.coe_units_iff] at hζ use ζ /-- The cardinality of the multiset `nthRoots ↑n (1 : R)` is `n` if there is a primitive root of unity in `R`. -/ theorem card_nthRoots_one {ζ : R} {n : ℕ} (h : IsPrimitiveRoot ζ n) : Multiset.card (nthRoots n (1 : R)) = n := by rw [card_nthRoots h, if_pos ⟨ζ, h.pow_eq_one⟩] theorem nthRoots_nodup {ζ : R} {n : ℕ} (h : IsPrimitiveRoot ζ n) {a : R} (ha : a ≠ 0) : (nthRoots n a).Nodup := by obtain (rfl | hn) := n.eq_zero_or_pos; · simp by_cases! h : ∃ α, α ^ n = a · obtain ⟨α, hα⟩ := h by_cases hα' : α = 0 · exact (ha (by rwa [hα', zero_pow hn.ne', eq_comm] at hα)).elim rw [nthRoots_eq h hα, Multiset.nodup_map_iff_inj_on (Multiset.nodup_range n)] exact h.injOn_pow_mul hα' · suffices nthRoots n a = 0 by simp [this] simpa only [Multiset.card_eq_zero, Multiset.eq_zero_iff_forall_notMem, mem_nthRoots hn] /-- The multiset `nthRoots ↑n (1 : R)` has no repeated elements if there is a primitive root of unity in `R`. -/ theorem nthRoots_one_nodup {ζ : R} {n : ℕ} (h : IsPrimitiveRoot ζ n) : (nthRoots n (1 : R)).Nodup := h.nthRoots_nodup one_ne_zero -- Cannot be @[simp] because `ζ` cannot be inferred by `simp`. theorem card_nthRootsFinset {ζ : R} {n : ℕ} (h : IsPrimitiveRoot ζ n) : #(nthRootsFinset n (1 : R)) = n := by classical rw [nthRootsFinset, ← Multiset.toFinset_eq (nthRoots_one_nodup h), card_mk, h.card_nthRoots_one] open scoped Nat /-- If an integral domain has a primitive `k`-th root of unity, then it has `φ k` of them. -/ theorem card_primitiveRoots {ζ : R} {k : ℕ} (h : IsPrimitiveRoot ζ k) : #(primitiveRoots k R) = φ k := by by_cases h0 : k = 0 · simp [h0] have : NeZero k := ⟨h0⟩ symm refine Finset.card_bij (fun i _ ↦ ζ ^ i) ?_ ?_ ?_ · simp only [and_imp, mem_filter, mem_range] rintro i - hi rw [mem_primitiveRoots (Nat.pos_of_ne_zero h0)] exact h.pow_of_coprime i hi.symm · simp only [and_imp, mem_filter, mem_range] rintro i hi - j hj - H exact h.pow_inj hi hj H · simp only [exists_prop, mem_filter, mem_range] intro ξ hξ rw [mem_primitiveRoots (Nat.pos_of_ne_zero h0), h.isPrimitiveRoot_iff] at hξ rcases hξ with ⟨i, hin, hi, H⟩ exact ⟨i, ⟨hin, hi.symm⟩, H⟩ /-- The sets `primitiveRoots k R` are pairwise disjoint. -/ theorem disjoint {k l : ℕ} (h : k ≠ l) : Disjoint (primitiveRoots k R) (primitiveRoots l R) := Finset.disjoint_left.2 fun _ hk hl ↦ h <| (isPrimitiveRoot_of_mem_primitiveRoots hk).unique <| isPrimitiveRoot_of_mem_primitiveRoots hl /-- `nthRoots n` as a `Finset` is equal to the union of `primitiveRoots i R` for `i ∣ n`. -/ private -- marking as `private` since `nthRoots_one_eq_biUnion_primitiveRoots` can be used instead theorem nthRoots_one_eq_biUnion_primitiveRoots' [DecidableEq R] {n : ℕ} [NeZero n] : nthRootsFinset n (1 : R) = (Nat.divisors n).biUnion fun i ↦ primitiveRoots i R := by ext x suffices x ^ n = 1 ↔ ∃ a, a ∣ n ∧ x ∈ primitiveRoots a R by simpa [Polynomial.mem_nthRootsFinset (NeZero.pos n), (NeZero.ne n)] constructor · intro H obtain ⟨k, hk, hx⟩ := exists_pos H (NeZero.ne n) exact ⟨k, hx.2 _ H, (mem_primitiveRoots hk).mpr hx⟩ · rintro ⟨a, ⟨d, hd⟩, ha⟩ have hazero : 0 < a := Nat.pos_of_ne_zero fun ha₀ ↦ by simp_all rw [mem_primitiveRoots hazero] at ha rw [hd, pow_mul, ha.pow_eq_one, one_pow] /-- `nthRoots n` as a `Finset` is equal to the union of `primitiveRoots i R` for `i ∣ n`. -/ theorem nthRoots_one_eq_biUnion_primitiveRoots [DecidableEq R] {n : ℕ} : nthRootsFinset n (1 : R) = (Nat.divisors n).biUnion fun i ↦ primitiveRoots i R := by by_cases hn : n = 0 · simp only [hn, nthRootsFinset_zero, Nat.divisors_zero, biUnion_empty] have : NeZero n := ⟨hn⟩ exact nthRoots_one_eq_biUnion_primitiveRoots' end IsDomain section Automorphisms variable [CommRing S] [IsDomain S] {μ : S} {n : ℕ} (hμ : IsPrimitiveRoot μ n) (R) [CommRing R] [Algebra R S] /-- The `MonoidHom` that takes an automorphism to the power of `μ` that `μ` gets mapped to under it. -/ noncomputable def autToPow [NeZero n] : (S ≃ₐ[R] S) →* (ZMod n)ˣ := let μ' := hμ.toRootsOfUnity have ho : orderOf μ' = n := by refine Eq.trans ?_ hμ.eq_orderOf.symm -- `rw [hμ.eq_orderOf]` gives "motive not type correct" rw [← hμ.val_toRootsOfUnity_coe, orderOf_units, Subgroup.orderOf_coe] MonoidHom.toHomUnits { toFun := fun σ ↦ (map_rootsOfUnity_eq_pow_self σ.toAlgHom μ').choose map_one' := by generalize_proofs h1 have h := h1.choose_spec replace h : μ' = μ' ^ h1.choose := rootsOfUnity.coe_injective (by simpa only [rootsOfUnity.coe_pow] using h) nth_rw 1 [← pow_one μ'] at h convert ho ▸ (ZMod.natCast_eq_natCast_iff ..).mpr (pow_eq_pow_iff_modEq.mp h).symm exact Nat.cast_one.symm map_mul' := by intro x y generalize_proofs hxy' hx' hy' have hxy := hxy'.choose_spec replace hxy : x (((μ' : Sˣ) : S) ^ hy'.choose) = ((μ' : Sˣ) : S) ^ hxy'.choose := hy'.choose_spec ▸ hxy rw [map_pow] at hxy replace hxy : (((μ' : Sˣ) : S) ^ hx'.choose) ^ hy'.choose = ((μ' : Sˣ) : S) ^ hxy'.choose := hx'.choose_spec ▸ hxy rw [← pow_mul] at hxy replace hxy : μ' ^ (hx'.choose * hy'.choose) = μ' ^ hxy'.choose := rootsOfUnity.coe_injective (by simpa only [rootsOfUnity.coe_pow] using hxy) convert ho ▸ (ZMod.natCast_eq_natCast_iff ..).mpr (pow_eq_pow_iff_modEq.mp hxy).symm exact (Nat.cast_mul ..).symm } -- We are not using @[simps] in `autToPow` to avoid a timeout. theorem coe_autToPow_apply [NeZero n] (f : S ≃ₐ[R] S) : (autToPow R hμ f : ZMod n) = ((map_rootsOfUnity_eq_pow_self f hμ.toRootsOfUnity).choose : ZMod n) := rfl @[simp] theorem autToPow_spec [NeZero n] (f : S ≃ₐ[R] S) : μ ^ (hμ.autToPow R f : ZMod n).val = f μ := by rw [IsPrimitiveRoot.coe_autToPow_apply] generalize_proofs h refine (?_ : ((hμ.toRootsOfUnity : Sˣ) : S) ^ _ = _).trans h.choose_spec.symm rw [← rootsOfUnity.coe_pow, ← rootsOfUnity.coe_pow] congr 2 rw [pow_eq_pow_iff_modEq, ZMod.val_natCast] conv => enter [2, 2]; rw [hμ.eq_orderOf] rw [← Subgroup.orderOf_coe, ← orderOf_units] exact Nat.mod_modEq _ _ end Automorphisms end IsPrimitiveRoot section cyclic /-- If `G` is cyclic of order `n` and `G'` contains a primitive `n`th root of unity, then for each `a : G` with `a ≠ 1` there is a homomorphism `φ : G →* G'` such that `φ a ≠ 1`. -/ lemma IsCyclic.exists_apply_ne_one {G G' : Type*} [Group G] [IsCyclic G] [Finite G] [CommGroup G'] (hG' : ∃ ζ : G', IsPrimitiveRoot ζ (Nat.card G)) ⦃a : G⦄ (ha : a ≠ 1) : ∃ φ : G →* G', φ a ≠ 1 := by let inst : Fintype G := Fintype.ofFinite _ obtain ⟨ζ, hζ⟩ := hG' -- pick a generator `g` of `G` obtain ⟨g, hg⟩ := IsCyclic.exists_generator (α := G) have hζg : orderOf ζ ∣ orderOf g := by rw [← hζ.eq_orderOf, orderOf_eq_card_of_forall_mem_zpowers hg, Nat.card_eq_fintype_card] -- use the homomorphism `φ` given by `g ↦ ζ` let φ := monoidHomOfForallMemZpowers hg hζg have hφg : IsPrimitiveRoot (φ g) (Nat.card G) := by rwa [monoidHomOfForallMemZpowers_apply_gen hg hζg] use φ contrapose! ha specialize hg a rw [← mem_powers_iff_mem_zpowers, Submonoid.mem_powers_iff] at hg obtain ⟨k, hk⟩ := hg rw [← hk, map_pow] at ha obtain ⟨l, rfl⟩ := (hφg.pow_eq_one_iff_dvd k).mp ha rw [← hk, pow_mul, Nat.card_eq_fintype_card, pow_card_eq_one, one_pow] /-- If `M` is a commutative group that contains a primitive `n`th root of unity and `a : ZMod n` is nonzero, then there exists a group homomorphism `φ` from the additive group `ZMod n` to the multiplicative group `Mˣ` such that `φ a ≠ 1`. -/ lemma ZMod.exists_monoidHom_apply_ne_one {M : Type*} [CommMonoid M] {n : ℕ} [NeZero n] (hG : ∃ ζ : M, IsPrimitiveRoot ζ n) {a : ZMod n} (ha : a ≠ 0) : ∃ φ : Multiplicative (ZMod n) →* Mˣ, φ (Multiplicative.ofAdd a) ≠ 1 := by obtain ⟨ζ, hζ⟩ := hG have hc : n = Nat.card (Multiplicative (ZMod n)) := by simp only [Nat.card_eq_fintype_card, Fintype.card_multiplicative, card] exact IsCyclic.exists_apply_ne_one (hc ▸ ⟨hζ.toRootsOfUnity.val, IsPrimitiveRoot.coe_units_iff.mp hζ⟩) <| by simp only [ne_eq, ofAdd_eq_one, ha, not_false_eq_true] end cyclic
.lake/packages/mathlib/Mathlib/RingTheory/RootsOfUnity/Minpoly.lean
import Mathlib.Algebra.GCDMonoid.IntegrallyClosed import Mathlib.FieldTheory.Finite.Basic import Mathlib.FieldTheory.Minpoly.IsIntegrallyClosed import Mathlib.RingTheory.RootsOfUnity.PrimitiveRoots import Mathlib.RingTheory.UniqueFactorizationDomain.Nat /-! # Minimal polynomial of roots of unity We gather several results about minimal polynomial of root of unity. ## Main results * `IsPrimitiveRoot.totient_le_degree_minpoly`: The degree of the minimal polynomial of an `n`-th primitive root of unity is at least `totient n`. -/ open minpoly Polynomial open scoped Polynomial namespace IsPrimitiveRoot section CommRing variable {n : ℕ} {K : Type*} [CommRing K] {μ : K} (h : IsPrimitiveRoot μ n) include h /-- `μ` is integral over `ℤ`. -/ theorem isIntegral (hpos : 0 < n) : IsIntegral ℤ μ := by use X ^ n - 1 constructor · exact monic_X_pow_sub_C 1 (ne_of_lt hpos).symm · simp only [((IsPrimitiveRoot.iff_def μ n).mp h).left, eval₂_one, eval₂_X_pow, eval₂_sub, sub_self] section IsDomain variable [IsDomain K] [CharZero K] /-- The minimal polynomial of a root of unity `μ` divides `X ^ n - 1`. -/ theorem minpoly_dvd_x_pow_sub_one : minpoly ℤ μ ∣ X ^ n - 1 := by rcases n.eq_zero_or_pos with (rfl | h0) · simp apply minpoly.isIntegrallyClosed_dvd (isIntegral h h0) simp only [((IsPrimitiveRoot.iff_def μ n).mp h).left, aeval_X_pow, aeval_one, map_sub, sub_self] /-- The reduction modulo `p` of the minimal polynomial of a root of unity `μ` is separable. -/ theorem separable_minpoly_mod {p : ℕ} [Fact p.Prime] (hdiv : ¬p ∣ n) : Separable (map (Int.castRingHom (ZMod p)) (minpoly ℤ μ)) := by have hdvd : map (Int.castRingHom (ZMod p)) (minpoly ℤ μ) ∣ X ^ n - 1 := by convert _root_.map_dvd (mapRingHom (Int.castRingHom (ZMod p))) (minpoly_dvd_x_pow_sub_one h) simp only [map_sub, map_pow, coe_mapRingHom, map_X, map_one] refine Separable.of_dvd (separable_X_pow_sub_C 1 ?_ one_ne_zero) hdvd by_contra hzero exact hdiv ((ZMod.natCast_eq_zero_iff n p).1 hzero) /-- The reduction modulo `p` of the minimal polynomial of a root of unity `μ` is squarefree. -/ theorem squarefree_minpoly_mod {p : ℕ} [Fact p.Prime] (hdiv : ¬p ∣ n) : Squarefree (map (Int.castRingHom (ZMod p)) (minpoly ℤ μ)) := (separable_minpoly_mod h hdiv).squarefree /-- Let `P` be the minimal polynomial of a root of unity `μ` and `Q` be the minimal polynomial of `μ ^ p`, where `p` is a natural number that does not divide `n`. Then `P` divides `expand ℤ p Q`. -/ theorem minpoly_dvd_expand {p : ℕ} (hdiv : ¬p ∣ n) : minpoly ℤ μ ∣ expand ℤ p (minpoly ℤ (μ ^ p)) := by rcases n.eq_zero_or_pos with (rfl | hpos) · simp_all letI : IsIntegrallyClosed ℤ := GCDMonoid.toIsIntegrallyClosed refine minpoly.isIntegrallyClosed_dvd (h.isIntegral hpos) ?_ rw [aeval_def, coe_expand, ← comp, eval₂_eq_eval_map, map_comp, Polynomial.map_pow, map_X, eval_comp, eval_X_pow, ← eval₂_eq_eval_map, ← aeval_def] exact minpoly.aeval _ _ /-- Let `P` be the minimal polynomial of a root of unity `μ` and `Q` be the minimal polynomial of `μ ^ p`, where `p` is a prime that does not divide `n`. Then `P` divides `Q ^ p` modulo `p`. -/ theorem minpoly_dvd_pow_mod {p : ℕ} [hprime : Fact p.Prime] (hdiv : ¬p ∣ n) : map (Int.castRingHom (ZMod p)) (minpoly ℤ μ) ∣ map (Int.castRingHom (ZMod p)) (minpoly ℤ (μ ^ p)) ^ p := by set Q := minpoly ℤ (μ ^ p) have hfrob : map (Int.castRingHom (ZMod p)) Q ^ p = map (Int.castRingHom (ZMod p)) (expand ℤ p Q) := by rw [← ZMod.expand_card, map_expand] rw [hfrob] apply _root_.map_dvd (mapRingHom (Int.castRingHom (ZMod p))) exact minpoly_dvd_expand h hdiv /-- Let `P` be the minimal polynomial of a root of unity `μ` and `Q` be the minimal polynomial of `μ ^ p`, where `p` is a prime that does not divide `n`. Then `P` divides `Q` modulo `p`. -/ theorem minpoly_dvd_mod_p {p : ℕ} [Fact p.Prime] (hdiv : ¬p ∣ n) : map (Int.castRingHom (ZMod p)) (minpoly ℤ μ) ∣ map (Int.castRingHom (ZMod p)) (minpoly ℤ (μ ^ p)) := (squarefree_minpoly_mod h hdiv).isRadical _ _ (minpoly_dvd_pow_mod h hdiv) /-- If `p` is a prime that does not divide `n`, then the minimal polynomials of a primitive `n`-th root of unity `μ` and of `μ ^ p` are the same. -/ theorem minpoly_eq_pow {p : ℕ} [hprime : Fact p.Prime] (hdiv : ¬p ∣ n) : minpoly ℤ μ = minpoly ℤ (μ ^ p) := by classical by_cases hn : n = 0 · simp_all have hpos := Nat.pos_of_ne_zero hn by_contra hdiff set P := minpoly ℤ μ set Q := minpoly ℤ (μ ^ p) have Pmonic : P.Monic := minpoly.monic (h.isIntegral hpos) have Qmonic : Q.Monic := minpoly.monic ((h.pow_of_prime hprime.1 hdiv).isIntegral hpos) have Pirr : Irreducible P := minpoly.irreducible (h.isIntegral hpos) have Qirr : Irreducible Q := minpoly.irreducible ((h.pow_of_prime hprime.1 hdiv).isIntegral hpos) have PQprim : IsPrimitive (P * Q) := Pmonic.isPrimitive.mul Qmonic.isPrimitive have prod : P * Q ∣ X ^ n - 1 := by rw [IsPrimitive.Int.dvd_iff_map_cast_dvd_map_cast (P * Q) (X ^ n - 1) PQprim (monic_X_pow_sub_C (1 : ℤ) (ne_of_gt hpos)).isPrimitive, Polynomial.map_mul] refine IsCoprime.mul_dvd ?_ ?_ ?_ · have aux := IsPrimitive.Int.irreducible_iff_irreducible_map_cast Pmonic.isPrimitive refine (dvd_or_isCoprime _ _ (aux.1 Pirr)).resolve_left ?_ rw [map_dvd_map (Int.castRingHom ℚ) Int.cast_injective Pmonic] intro hdiv refine hdiff (eq_of_monic_of_associated Pmonic Qmonic ?_) exact associated_of_dvd_dvd hdiv (Pirr.dvd_symm Qirr hdiv) · apply (map_dvd_map (Int.castRingHom ℚ) Int.cast_injective Pmonic).2 exact minpoly_dvd_x_pow_sub_one h · apply (map_dvd_map (Int.castRingHom ℚ) Int.cast_injective Qmonic).2 exact minpoly_dvd_x_pow_sub_one (pow_of_prime h hprime.1 hdiv) replace prod := _root_.map_dvd (mapRingHom (Int.castRingHom (ZMod p))) prod rw [coe_mapRingHom, Polynomial.map_mul, Polynomial.map_sub, Polynomial.map_one, Polynomial.map_pow, map_X] at prod obtain ⟨R, hR⟩ := minpoly_dvd_mod_p h hdiv rw [hR, ← mul_assoc, ← Polynomial.map_mul, ← sq, Polynomial.map_pow] at prod have habs : map (Int.castRingHom (ZMod p)) P ^ 2 ∣ map (Int.castRingHom (ZMod p)) P ^ 2 * R := by use R replace habs := lt_of_lt_of_le (Nat.cast_lt.2 one_lt_two) (le_emultiplicity_of_pow_dvd (dvd_trans habs prod)) have hfree : Squarefree (X ^ n - 1 : (ZMod p)[X]) := (separable_X_pow_sub_C 1 (fun h => hdiv <| (ZMod.natCast_eq_zero_iff n p).1 h) one_ne_zero).squarefree rcases (squarefree_iff_emultiplicity_le_one (X ^ n - 1)).1 hfree (map (Int.castRingHom (ZMod p)) P) with hle | hunit · rw [Nat.cast_one] at habs; exact hle.not_gt habs · replace hunit := degree_eq_zero_of_isUnit hunit rw [degree_map_eq_of_leadingCoeff_ne_zero (Int.castRingHom (ZMod p)) _] at hunit · exact (minpoly.degree_pos (isIntegral h hpos)).ne' hunit simp only [Pmonic, eq_intCast, Monic.leadingCoeff, Int.cast_one, Ne, not_false_iff, one_ne_zero] /-- If `m : ℕ` is coprime with `n`, then the minimal polynomials of a primitive `n`-th root of unity `μ` and of `μ ^ m` are the same. -/ theorem minpoly_eq_pow_coprime {m : ℕ} (hcop : Nat.Coprime m n) : minpoly ℤ μ = minpoly ℤ (μ ^ m) := by revert n hcop refine UniqueFactorizationMonoid.induction_on_prime m ?_ ?_ ?_ · intro h hn congr simpa [(Nat.coprime_zero_left _).mp hn] using h · intro u hunit _ _ congr simp [Nat.isUnit_iff.mp hunit] · intro a p _ hprime hind h hcop rw [hind h (Nat.Coprime.coprime_mul_left hcop)]; clear hind replace hprime := hprime.nat_prime have hdiv := (Nat.Prime.coprime_iff_not_dvd hprime).1 (Nat.Coprime.coprime_mul_right hcop) haveI := Fact.mk hprime rw [minpoly_eq_pow (h.pow_of_coprime a (Nat.Coprime.coprime_mul_left hcop)) hdiv] congr 1 ring /-- If `m : ℕ` is coprime with `n`, then the minimal polynomial of a primitive `n`-th root of unity `μ` has `μ ^ m` as root. -/ theorem pow_isRoot_minpoly {m : ℕ} (hcop : Nat.Coprime m n) : IsRoot (map (Int.castRingHom K) (minpoly ℤ μ)) (μ ^ m) := by simp only [minpoly_eq_pow_coprime h hcop, IsRoot.def, eval_map] exact minpoly.aeval ℤ (μ ^ m) /-- `primitiveRoots n K` is a subset of the roots of the minimal polynomial of a primitive `n`-th root of unity `μ`. -/ theorem is_roots_of_minpoly [DecidableEq K] : primitiveRoots n K ⊆ (map (Int.castRingHom K) (minpoly ℤ μ)).roots.toFinset := by by_cases hn : n = 0; · simp_all have : NeZero n := ⟨hn⟩ have hpos := Nat.pos_of_ne_zero hn intro x hx obtain ⟨m, _, hcop, rfl⟩ := (isPrimitiveRoot_iff h).1 ((mem_primitiveRoots hpos).1 hx) simp only [Multiset.mem_toFinset] convert pow_isRoot_minpoly h hcop using 0 rw [← mem_roots] exact map_monic_ne_zero <| minpoly.monic <| isIntegral h hpos /-- The degree of the minimal polynomial of `μ` is at least `totient n`. -/ theorem totient_le_degree_minpoly : Nat.totient n ≤ (minpoly ℤ μ).natDegree := by classical let P : ℤ[X] := minpoly ℤ μ -- minimal polynomial of `μ` let P_K : K[X] := map (Int.castRingHom K) P -- minimal polynomial of `μ` sent to `K[X]` calc n.totient = (primitiveRoots n K).card := h.card_primitiveRoots.symm _ ≤ P_K.roots.toFinset.card := Finset.card_le_card (is_roots_of_minpoly h) _ ≤ Multiset.card P_K.roots := Multiset.toFinset_card_le _ _ ≤ P_K.natDegree := card_roots' _ _ ≤ P.natDegree := natDegree_map_le end IsDomain end CommRing end IsPrimitiveRoot
.lake/packages/mathlib/Mathlib/RingTheory/RingHom/Bijective.lean
import Mathlib.RingTheory.LocalProperties.Basic import Mathlib.RingTheory.LocalProperties.Exactness /-! # Meta properties of bijective ring homomorphisms We show some meta properties of bijective ring homomorphisms. ## Implementation details We don't define a `RingHom.Bijective` predicate, but use `fun f ↦ Function.Bijective f` as the ring hom property. -/ open TensorProduct variable {R S : Type*} [CommRing R] [CommRing S] namespace RingHom.Bijective lemma containsIdentities : ContainsIdentities (fun f ↦ Function.Bijective f) := fun _ _ ↦ Function.bijective_id lemma stableUnderComposition : StableUnderComposition (fun f ↦ Function.Bijective f) := fun _ _ _ _ _ _ _ _ hf hg ↦ hg.comp hf lemma respectsIso : RespectsIso (fun f ↦ Function.Bijective f) := RingHom.Bijective.stableUnderComposition.respectsIso fun e ↦ e.bijective lemma isStableUnderBaseChange : IsStableUnderBaseChange (fun f ↦ Function.Bijective f) := .mk respectsIso fun R _ _ _ _ _ _ _ hf ↦ Algebra.TensorProduct.includeLeft_bijective (S := R) hf lemma ofLocalizationSpan : OfLocalizationSpan (fun f ↦ Function.Bijective f) := fun _ _ _ _ f s hs hf ↦ bijective_of_isLocalization_of_span_eq_top (s := s) hs (fun r ↦ Localization.Away r.val) (fun r ↦ Localization.Away (f r.val)) f hf end RingHom.Bijective
.lake/packages/mathlib/Mathlib/RingTheory/RingHom/Finite.lean
import Mathlib.RingTheory.LocalProperties.Basic import Mathlib.RingTheory.Localization.Integer import Mathlib.RingTheory.TensorProduct.Finite /-! # The meta properties of finite ring homomorphisms. ## Main results Let `R` be a commutative ring, `S` is an `R`-algebra, `M` be a submonoid of `R`. * `finite_localizationPreserves` : If `S` is a finite `R`-algebra, then `S' = M⁻¹S` is a finite `R' = M⁻¹R`-algebra. * `finite_ofLocalizationSpan` : `S` is a finite `R`-algebra if there exists a set `{ r }` that spans `R` such that `Sᵣ` is a finite `Rᵣ`-algebra. -/ namespace RingHom open scoped TensorProduct open TensorProduct Algebra.TensorProduct theorem finite_stableUnderComposition : StableUnderComposition @Finite := by introv R hf hg exact hg.comp hf theorem finite_respectsIso : RespectsIso @Finite := by apply finite_stableUnderComposition.respectsIso intros exact Finite.of_surjective _ (RingEquiv.toEquiv _).surjective lemma finite_containsIdentities : ContainsIdentities @Finite := Finite.id theorem finite_isStableUnderBaseChange : IsStableUnderBaseChange @Finite := by refine IsStableUnderBaseChange.mk finite_respectsIso ?_ classical introv h replace h : Module.Finite R T := by rw [RingHom.Finite] at h; convert h; ext; simp_rw [Algebra.smul_def]; rfl suffices Module.Finite S (S ⊗[R] T) by rw [RingHom.Finite]; convert this; congr; ext; simp_rw [Algebra.smul_def]; rfl exact inferInstance end RingHom open scoped Pointwise universe u variable {R S : Type*} [CommRing R] [CommRing S] (M : Submonoid R) (f : R →+* S) variable (R' S' : Type*) [CommRing R'] [CommRing S'] variable [Algebra R R'] [Algebra S S'] lemma Module.Finite.of_isLocalization (R S) {Rₚ Sₚ : Type*} [CommSemiring R] [CommSemiring S] [CommSemiring Rₚ] [CommSemiring 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.exists_mk'_eq (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: https://github.com/leanprover-community/mathlib4/pull/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] @[deprecated (since := "2025-05-01")] alias Module.Finite_of_isLocalization := Module.Finite.of_isLocalization open Algebra nonZeroDivisors in instance {A C : Type*} [CommRing A] [CommRing C] [Algebra A C] [Module.Finite A C] : Module.Finite (FractionRing A) (Localization (algebraMapSubmonoid C A⁰)) := have : IsScalarTower A (FractionRing A) (Localization (algebraMapSubmonoid C A⁰)) := instIsScalarTowerLocalizationAlgebraMapSubmonoid A⁰ C .of_isLocalization A C A⁰ /-- If `S` is a finite `R`-algebra, then `S' = M⁻¹S` is a finite `R' = M⁻¹R`-algebra. -/ theorem RingHom.finite_localizationPreserves : 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 exact .of_isLocalization R S M theorem RingHom.localization_away_map_finite (R S R' S' : Type u) [CommRing R] [CommRing S] [CommRing R'] [CommRing S'] [Algebra R R'] (f : R →+* S) [Algebra S S'] (r : R) [IsLocalization.Away r R'] [IsLocalization.Away (f r) S'] (hf : f.Finite) : (IsLocalization.Away.map R' S' f r).Finite := finite_localizationPreserves.away f r _ _ hf open scoped Classical in /-- 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] have g_apply : ∀ x, g x = algebraMap S S' x := fun _ => rfl -- 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₁, ← g_apply, ← map_smul g, g_apply, ← Algebra.linearMap_apply, ← Submodule.map_span] 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 with | empty => use 1; simpa using hs' | insert a s _ hs => simp only [Finset.coe_insert, 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 [Submonoid.smul_def] /-- 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 /-- `S` is a finite `R`-algebra if there exists a set `{ r }` that spans `R` such that `Sᵣ` is a finite `Rᵣ`-algebra. -/ theorem RingHom.finite_ofLocalizationSpan : RingHom.OfLocalizationSpan @RingHom.Finite := by classical 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, ← 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₂ instance {R S : Type*} [CommRing R] {P : Ideal R} [CommRing S] [Algebra R S] [Module.Finite R S] [P.IsPrime] : Module.Finite (Localization.AtPrime P) (Localization (Algebra.algebraMapSubmonoid S P.primeCompl)) := .of_isLocalization R S P.primeCompl
.lake/packages/mathlib/Mathlib/RingTheory/RingHom/Unramified.lean
import Mathlib.RingTheory.Unramified.Locus import Mathlib.RingTheory.LocalProperties.Basic /-! # The meta properties of unramified ring homomorphisms. -/ namespace RingHom variable {R : Type*} {S : Type*} [CommRing R] [CommRing S] /-- A ring homomorphism `R →+* A` is formally unramified if `Ω[A⁄R]` is trivial. See `Algebra.FormallyUnramified`. -/ @[algebraize Algebra.FormallyUnramified] def FormallyUnramified (f : R →+* S) : Prop := letI := f.toAlgebra Algebra.FormallyUnramified R S lemma formallyUnramified_algebraMap [Algebra R S] : (algebraMap R S).FormallyUnramified ↔ Algebra.FormallyUnramified R S := by rw [FormallyUnramified, toAlgebra_algebraMap] namespace FormallyUnramified lemma stableUnderComposition : StableUnderComposition FormallyUnramified := by intro R S T _ _ _ f g _ _ algebraize [f, g, g.comp f] exact .comp R S T lemma respectsIso : RespectsIso FormallyUnramified := by refine stableUnderComposition.respectsIso ?_ intro R S _ _ e letI := e.toRingHom.toAlgebra exact Algebra.FormallyUnramified.of_surjective (Algebra.ofId R S) e.surjective lemma isStableUnderBaseChange : IsStableUnderBaseChange FormallyUnramified := by refine .mk respectsIso ?_ introv H rw [formallyUnramified_algebraMap] at H ⊢ infer_instance lemma holdsForLocalizationAway : HoldsForLocalizationAway FormallyUnramified := by intro R S _ _ _ r _ rw [formallyUnramified_algebraMap] exact .of_isLocalization (.powers r) lemma ofLocalizationPrime : OfLocalizationPrime FormallyUnramified := by intro R S _ _ f H algebraize [f] rw [FormallyUnramified, ← Algebra.unramifiedLocus_eq_univ_iff, Set.eq_univ_iff_forall] intro x let Rₓ := Localization.AtPrime (x.asIdeal.comap f) let Sₓ := Localization.AtPrime x.asIdeal have := Algebra.FormallyUnramified.of_isLocalization (Rₘ := Rₓ) (x.asIdeal.comap f).primeCompl letI : Algebra Rₓ Sₓ := (Localization.localRingHom _ _ _ rfl).toAlgebra have : IsScalarTower R Rₓ Sₓ := .of_algebraMap_eq fun x ↦ (Localization.localRingHom_to_map _ _ _ rfl x).symm have : Algebra.FormallyUnramified Rₓ Sₓ := H _ _ exact Algebra.FormallyUnramified.comp R Rₓ Sₓ lemma ofLocalizationSpanTarget : OfLocalizationSpanTarget FormallyUnramified := by intro R S _ _ f s hs H algebraize [f] rw [FormallyUnramified, ← Algebra.unramifiedLocus_eq_univ_iff, Set.eq_univ_iff_forall] intro x obtain ⟨r, hr, hrx⟩ : ∃ r ∈ s, x ∈ PrimeSpectrum.basicOpen r := by simpa using (PrimeSpectrum.iSup_basicOpen_eq_top_iff'.mpr hs).ge (TopologicalSpace.Opens.mem_top x) refine Algebra.basicOpen_subset_unramifiedLocus_iff.mpr ?_ hrx convert H ⟨r, hr⟩ dsimp rw [← algebraMap_toAlgebra f, ← IsScalarTower.algebraMap_eq, formallyUnramified_algebraMap] lemma propertyIsLocal : PropertyIsLocal FormallyUnramified := by constructor · intro R S _ _ f r R' S' _ _ _ _ _ _ H algebraize [f, (algebraMap S S').comp f, IsLocalization.Away.map R' S' f r] have := Algebra.FormallyUnramified.of_isLocalization (Rₘ := S') (.powers (f r)) have := Algebra.FormallyUnramified.comp R S S' have H : Submonoid.powers r ≤ (Submonoid.powers (f r)).comap f := by rintro x ⟨n, rfl⟩; exact ⟨n, by simp⟩ have : IsScalarTower R R' S' := .of_algebraMap_eq' (IsLocalization.map_comp H).symm exact Algebra.FormallyUnramified.of_comp R R' S' · exact ofLocalizationSpanTarget · exact ofLocalizationSpanTarget.ofLocalizationSpan (stableUnderComposition.stableUnderCompositionWithLocalizationAway holdsForLocalizationAway).1 · exact (stableUnderComposition.stableUnderCompositionWithLocalizationAway holdsForLocalizationAway).2 end RingHom.FormallyUnramified
.lake/packages/mathlib/Mathlib/RingTheory/RingHom/Flat.lean
import Mathlib.RingTheory.Flat.Localization import Mathlib.RingTheory.LocalProperties.Basic import Mathlib.RingTheory.Ideal.GoingDown /-! # Flat ring homomorphisms In this file we define flat ring homomorphisms and show their meta properties. -/ universe u v open TensorProduct /-- A ring homomorphism `f : R →+* S` is flat if `S` is flat as an `R` module. -/ @[algebraize Module.Flat] def RingHom.Flat {R : Type u} {S : Type v} [CommRing R] [CommRing S] (f : R →+* S) : Prop := letI : Algebra R S := f.toAlgebra Module.Flat R S lemma RingHom.flat_algebraMap_iff {R S : Type*} [CommRing R] [CommRing S] [Algebra R S] : (algebraMap R S).Flat ↔ Module.Flat R S := by rw [RingHom.Flat, toAlgebra_algebraMap] @[deprecated (since := "2025-06-03")] alias flat_algebraMap_iff := RingHom.flat_algebraMap_iff namespace RingHom.Flat variable {R S T : Type*} [CommRing R] [CommRing S] [CommRing T] variable (R) in /-- The identity of a ring is flat. -/ lemma id : RingHom.Flat (RingHom.id R) := Module.Flat.self /-- Composition of flat ring homomorphisms is flat. -/ lemma comp {f : R →+* S} {g : S →+* T} (hf : f.Flat) (hg : g.Flat) : Flat (g.comp f) := by algebraize [f, g, (g.comp f)] exact Module.Flat.trans R S T /-- Bijective ring maps are flat. -/ lemma of_bijective {f : R →+* S} (hf : Function.Bijective f) : Flat f := by algebraize [f] exact Module.Flat.of_linearEquiv (LinearEquiv.ofBijective (Algebra.linearMap R S) hf).symm lemma containsIdentities : ContainsIdentities Flat := id lemma stableUnderComposition : StableUnderComposition Flat := by introv R hf hg exact hf.comp hg lemma respectsIso : RespectsIso Flat := by apply stableUnderComposition.respectsIso introv exact of_bijective e.bijective lemma isStableUnderBaseChange : IsStableUnderBaseChange Flat := by apply IsStableUnderBaseChange.mk respectsIso introv h rw [flat_algebraMap_iff] at h ⊢ infer_instance lemma holdsForLocalizationAway : HoldsForLocalizationAway Flat := by introv R h suffices Module.Flat R S by rw [RingHom.Flat]; convert this; ext; simp_rw [Algebra.smul_def]; rfl exact IsLocalization.flat _ (Submonoid.powers r) lemma ofLocalizationSpanTarget : OfLocalizationSpanTarget Flat := by introv R hsp h algebraize_only [f] refine Module.flat_of_isLocalized_span _ _ s hsp _ (fun r ↦ Algebra.linearMap S <| Localization.Away r.1) ?_ dsimp only [RingHom.Flat] at h convert h; ext apply Algebra.smul_def /-- Flat is a local property of ring homomorphisms. -/ lemma propertyIsLocal : PropertyIsLocal Flat where localizationAwayPreserves := isStableUnderBaseChange.localizationPreserves.away ofLocalizationSpanTarget := ofLocalizationSpanTarget ofLocalizationSpan := ofLocalizationSpanTarget.ofLocalizationSpan (stableUnderComposition.stableUnderCompositionWithLocalizationAway holdsForLocalizationAway).left StableUnderCompositionWithLocalizationAwayTarget := (stableUnderComposition.stableUnderCompositionWithLocalizationAway holdsForLocalizationAway).right lemma ofLocalizationPrime : OfLocalizationPrime Flat := by introv R h algebraize_only [f] rw [RingHom.Flat] apply Module.flat_of_isLocalized_maximal S S (fun P ↦ Localization.AtPrime P) (fun P ↦ Algebra.linearMap S _) intro P _ algebraize_only [Localization.localRingHom (Ideal.comap f P) P f rfl] have : IsScalarTower R (Localization.AtPrime (Ideal.comap f P)) (Localization.AtPrime P) := .of_algebraMap_eq fun x ↦ (Localization.localRingHom_to_map _ _ _ rfl x).symm replace h : Module.Flat (Localization.AtPrime (Ideal.comap f P)) (Localization.AtPrime P) := h .. exact Module.Flat.trans R (Localization.AtPrime <| Ideal.comap f P) (Localization.AtPrime P) lemma localRingHom {f : R →+* S} (hf : f.Flat) (P : Ideal S) [P.IsPrime] (Q : Ideal R) [Q.IsPrime] (hQP : Q = Ideal.comap f P) : (Localization.localRingHom Q P f hQP).Flat := by subst hQP algebraize [f, Localization.localRingHom (Ideal.comap f P) P f rfl] have : IsScalarTower R (Localization.AtPrime (Ideal.comap f P)) (Localization.AtPrime P) := .of_algebraMap_eq fun x ↦ (Localization.localRingHom_to_map _ _ _ rfl x).symm rw [RingHom.Flat, Module.flat_iff_of_isLocalization (S := (Localization.AtPrime (Ideal.comap f P))) (p := (Ideal.comap f P).primeCompl)] exact Module.Flat.trans R S (Localization.AtPrime P) open PrimeSpectrum /-- `Spec S → Spec R` is generalizing if `R →+* S` is flat. -/ lemma generalizingMap_comap {f : R →+* S} (hf : f.Flat) : GeneralizingMap (comap f) := by algebraize [f] change GeneralizingMap (comap (algebraMap R S)) rw [← Algebra.HasGoingDown.iff_generalizingMap_primeSpectrumComap] infer_instance end RingHom.Flat
.lake/packages/mathlib/Mathlib/RingTheory/RingHom/Integral.lean
import Mathlib.RingTheory.LocalProperties.Basic import Mathlib.RingTheory.Localization.Integral /-! # The meta properties of integral ring homomorphisms. -/ namespace RingHom open scoped TensorProduct open TensorProduct Algebra.TensorProduct theorem isIntegral_stableUnderComposition : StableUnderComposition fun f => f.IsIntegral := by introv R hf hg; exact hf.trans _ _ hg theorem isIntegral_respectsIso : RespectsIso fun f => f.IsIntegral := by apply isIntegral_stableUnderComposition.respectsIso introv x rw [← e.apply_symm_apply x] apply RingHom.isIntegralElem_map theorem isIntegral_isStableUnderBaseChange : IsStableUnderBaseChange fun f => f.IsIntegral := by refine IsStableUnderBaseChange.mk isIntegral_respectsIso ?_ introv int rw [algebraMap_isIntegral_iff] at int ⊢ infer_instance open Polynomial in /-- `S` is an integral `R`-algebra if there exists a set `{ r }` that spans `R` such that each `Sᵣ` is an integral `Rᵣ`-algebra. -/ theorem isIntegral_ofLocalizationSpan : OfLocalizationSpan (RingHom.IsIntegral ·) := by introv R hs H r letI := f.toAlgebra change r ∈ (integralClosure R S).toSubmodule apply Submodule.mem_of_span_eq_top_of_smul_pow_mem _ s hs rintro ⟨t, ht⟩ letI := (Localization.awayMap f t).toAlgebra haveI : IsScalarTower R (Localization.Away t) (Localization.Away (f t)) := .of_algebraMap_eq' (IsLocalization.lift_comp _).symm have : _root_.IsIntegral (Localization.Away t) (algebraMap S (Localization.Away (f t)) r) := H ⟨t, ht⟩ (algebraMap _ _ r) obtain ⟨⟨_, n, rfl⟩, p, hp, hp'⟩ := this.exists_multiple_integral_of_isLocalization (.powers t) rw [IsScalarTower.algebraMap_eq R S, Submonoid.smul_def, Algebra.smul_def, IsScalarTower.algebraMap_apply R S, ← map_mul, ← hom_eval₂, IsLocalization.map_eq_zero_iff (.powers (f t))] at hp' obtain ⟨⟨x, m, (rfl : algebraMap R S t ^ m = x)⟩, e⟩ := hp' by_cases hp' : 1 ≤ p.natDegree; swap · obtain rfl : p = 1 := eq_one_of_monic_natDegree_zero hp (by cutsat) exact ⟨m, by simp [Algebra.smul_def, show algebraMap R S t ^ m = 0 by simpa using e]⟩ refine ⟨m + n, p.scaleRoots (t ^ m), (monic_scaleRoots_iff _).mpr hp, ?_⟩ have := p.scaleRoots_eval₂_mul (algebraMap R S) (t ^ n • r) (t ^ m) simp only [pow_add, ← Algebra.smul_def, mul_smul, ← map_pow] at e this ⊢ rw [this, ← tsub_add_cancel_of_le hp', pow_succ, mul_smul, e, smul_zero] end RingHom
.lake/packages/mathlib/Mathlib/RingTheory/RingHom/OpenImmersion.lean
import Mathlib.RingTheory.LocalProperties.Basic /-! # Standard Open Immersion We define the property `RingHom.IsStandardOpenImmersion` on ring homomorphisms: it means that the morphism is a localization map away from some element. We also define the equivalent `Algebra.IsStandardOpenImmersion`. -/ universe u namespace Algebra open IsLocalization Away variable {R S T : Type*} [CommSemiring R] [CommSemiring S] [CommSemiring T] [Algebra R S] [Algebra R T] /-- A standard open immersion is one that is a localization map away from some element. -/ @[mk_iff] class IsStandardOpenImmersion (R S : Type*) [CommSemiring R] [CommSemiring S] [Algebra R S] : Prop where exists_away (R S) : ∃ r : R, IsLocalization.Away r S open IsStandardOpenImmersion instance (r : R) : IsStandardOpenImmersion R (Localization.Away r) := ⟨r, inferInstance⟩ variable (R S T) in @[trans] theorem IsStandardOpenImmersion.trans [Algebra S T] [IsScalarTower R S T] [IsStandardOpenImmersion R S] [IsStandardOpenImmersion S T] : IsStandardOpenImmersion R T := let ⟨r, _⟩ := exists_away R S let ⟨s, _⟩ := exists_away S T have : Away (algebraMap R S (sec r s).1) T := .of_associated (associated_sec_fst r s).symm ⟨r * (sec r s).1, mul' S T r _⟩ open _root_.TensorProduct in instance [IsStandardOpenImmersion R T] : IsStandardOpenImmersion S (S ⊗[R] T) := let ⟨r, _⟩ := exists_away R T ⟨algebraMap R S r, inferInstance⟩ end Algebra namespace RingHom variable {R S T : Type*} [CommRing R] [CommRing S] [CommRing T] (f : R →+* S) (g : S →+* T) /-- A standard open immersion is one that is a localization map away from some element. -/ @[algebraize RingHom.IsStandardOpenImmersion.toAlgebra] def IsStandardOpenImmersion : Prop := letI := f.toAlgebra Algebra.IsStandardOpenImmersion R S lemma isStandardOpenImmersion_algebraMap [Algebra R S] : (algebraMap R S).IsStandardOpenImmersion ↔ Algebra.IsStandardOpenImmersion R S := by rw [IsStandardOpenImmersion, toAlgebra_algebraMap] namespace IsStandardOpenImmersion protected lemma algebraMap [Algebra R S] (r : R) [IsLocalization.Away r S] : (algebraMap R S).IsStandardOpenImmersion := isStandardOpenImmersion_algebraMap.2 ⟨r, inferInstance⟩ lemma toAlgebra {f : R →+* S} (hf : f.IsStandardOpenImmersion) : @Algebra.IsStandardOpenImmersion R S _ _ f.toAlgebra := letI := f.toAlgebra; hf /-- A bijective ring map is a standard open immersion. -/ lemma of_bijective {f : R →+* S} (hf : Function.Bijective f) : f.IsStandardOpenImmersion := letI := f.toAlgebra ⟨1, IsLocalization.away_of_isUnit_of_bijective _ isUnit_one hf⟩ variable (R) in /-- The identity map of a ring is a standard open immersion. -/ lemma id : (RingHom.id R).IsStandardOpenImmersion := of_bijective Function.bijective_id variable {f g} in /-- The composition of two standard open immersions is a standard open immersion. -/ lemma comp (hf : f.IsStandardOpenImmersion) (hg : g.IsStandardOpenImmersion) : (g.comp f).IsStandardOpenImmersion := by algebraize [f, g, g.comp f] obtain ⟨r, hr⟩ := hf obtain ⟨s, hs⟩ := hg exact .trans _ S _ theorem containsIdentities : ContainsIdentities.{u} IsStandardOpenImmersion := id theorem stableUnderComposition : StableUnderComposition.{u} IsStandardOpenImmersion := @comp theorem respectsIso : RespectsIso.{u} IsStandardOpenImmersion := stableUnderComposition.respectsIso fun e ↦ of_bijective e.bijective theorem isStableUnderBaseChange : IsStableUnderBaseChange.{u} IsStandardOpenImmersion := by refine .mk respectsIso ?_ introv h rw [isStandardOpenImmersion_algebraMap] at h ⊢ infer_instance theorem holdsForLocalizationAway : HoldsForLocalizationAway.{u} IsStandardOpenImmersion := by introv R h exact .algebraMap r end IsStandardOpenImmersion end RingHom
.lake/packages/mathlib/Mathlib/RingTheory/RingHom/StandardSmooth.lean
import Mathlib.RingTheory.LocalProperties.Basic import Mathlib.RingTheory.Smooth.StandardSmooth import Mathlib.Tactic.Algebraize /-! # Standard smooth ring homomorphisms In this file we define standard smooth ring homomorphisms and show their meta properties. ## Main definitions - `RingHom.IsStandardSmooth`: A ring homomorphism `R →+* S` is standard smooth if `S` is standard smooth as `R`-algebra. - `RingHom.IsStandardSmoothOfRelativeDimension n`: A ring homomorphism `R →+* S` is standard smooth of relative dimension `n` if `S` is standard smooth of relative dimension `n` as `R`-algebra. ## Notes This contribution was created as part of the AIM workshop "Formalizing algebraic geometry" in June 2024. -/ universe t t' w w' u v variable (n m : ℕ) open TensorProduct namespace RingHom variable {R : Type u} {S : Type v} [CommRing R] [CommRing S] /-- A ring homomorphism `R →+* S` is standard smooth if `S` is standard smooth as `R`-algebra. -/ @[algebraize RingHom.IsStandardSmooth.toAlgebra] def IsStandardSmooth (f : R →+* S) : Prop := @Algebra.IsStandardSmooth _ _ _ _ f.toAlgebra /-- Helper lemma for the `algebraize` tactic -/ lemma IsStandardSmooth.toAlgebra {f : R →+* S} (hf : IsStandardSmooth f) : @Algebra.IsStandardSmooth R S _ _ f.toAlgebra := hf /-- A ring homomorphism `R →+* S` is standard smooth of relative dimension `n` if `S` is standard smooth of relative dimension `n` as `R`-algebra. -/ @[algebraize RingHom.IsStandardSmoothOfRelativeDimension.toAlgebra] def IsStandardSmoothOfRelativeDimension (f : R →+* S) : Prop := @Algebra.IsStandardSmoothOfRelativeDimension n _ _ _ _ f.toAlgebra /-- Helper lemma for the `algebraize` tactic -/ lemma IsStandardSmoothOfRelativeDimension.toAlgebra {f : R →+* S} (hf : IsStandardSmoothOfRelativeDimension n f) : @Algebra.IsStandardSmoothOfRelativeDimension n R S _ _ f.toAlgebra := hf lemma IsStandardSmoothOfRelativeDimension.isStandardSmooth (f : R →+* S) (hf : IsStandardSmoothOfRelativeDimension n f) : IsStandardSmooth f := by algebraize [f] exact Algebra.IsStandardSmoothOfRelativeDimension.isStandardSmooth n variable {n m} variable (R) in lemma IsStandardSmoothOfRelativeDimension.id : IsStandardSmoothOfRelativeDimension 0 (RingHom.id R) := Algebra.IsStandardSmoothOfRelativeDimension.id R lemma IsStandardSmoothOfRelativeDimension.equiv (e : R ≃+* S) : IsStandardSmoothOfRelativeDimension 0 (e : R →+* S) := by algebraize [e.toRingHom] exact Algebra.IsStandardSmoothOfRelativeDimension.of_algebraMap_bijective e.bijective variable {T : Type*} [CommRing T] lemma IsStandardSmooth.comp {g : S →+* T} {f : R →+* S} (hg : IsStandardSmooth g) (hf : IsStandardSmooth f) : IsStandardSmooth (g.comp f) := by rw [IsStandardSmooth] algebraize [f, g, (g.comp f)] exact Algebra.IsStandardSmooth.trans R S T lemma IsStandardSmoothOfRelativeDimension.comp {g : S →+* T} {f : R →+* S} (hg : IsStandardSmoothOfRelativeDimension n g) (hf : IsStandardSmoothOfRelativeDimension m f) : IsStandardSmoothOfRelativeDimension (n + m) (g.comp f) := by rw [IsStandardSmoothOfRelativeDimension] algebraize [f, g, (g.comp f)] exact Algebra.IsStandardSmoothOfRelativeDimension.trans m n R S T lemma isStandardSmooth_stableUnderComposition : StableUnderComposition @IsStandardSmooth := fun _ _ _ _ _ _ _ _ hf hg ↦ hg.comp hf lemma isStandardSmooth_respectsIso : RespectsIso @IsStandardSmooth := by apply isStandardSmooth_stableUnderComposition.respectsIso introv exact (IsStandardSmoothOfRelativeDimension.equiv e).isStandardSmooth lemma isStandardSmoothOfRelativeDimension_respectsIso : RespectsIso (@IsStandardSmoothOfRelativeDimension n) where left {R S T _ _ _} f e hf := by rw [← zero_add n] exact (IsStandardSmoothOfRelativeDimension.equiv e).comp hf right {R S T _ _ _} f e hf := by rw [← add_zero n] exact hf.comp (IsStandardSmoothOfRelativeDimension.equiv e) lemma isStandardSmooth_isStableUnderBaseChange : IsStableUnderBaseChange @IsStandardSmooth := by apply IsStableUnderBaseChange.mk · exact isStandardSmooth_respectsIso · introv h replace h : Algebra.IsStandardSmooth R T := by rw [RingHom.IsStandardSmooth] at h; convert h; ext; simp_rw [Algebra.smul_def]; rfl suffices Algebra.IsStandardSmooth S (S ⊗[R] T) by rw [RingHom.IsStandardSmooth]; convert this; ext; simp_rw [Algebra.smul_def]; rfl infer_instance variable (n) lemma isStandardSmoothOfRelativeDimension_isStableUnderBaseChange : IsStableUnderBaseChange (@IsStandardSmoothOfRelativeDimension n) := by apply IsStableUnderBaseChange.mk · exact isStandardSmoothOfRelativeDimension_respectsIso · introv h replace h : Algebra.IsStandardSmoothOfRelativeDimension n R T := by rw [RingHom.IsStandardSmoothOfRelativeDimension] at h convert h; ext; simp_rw [Algebra.smul_def]; rfl suffices Algebra.IsStandardSmoothOfRelativeDimension n S (S ⊗[R] T) by rw [RingHom.IsStandardSmoothOfRelativeDimension] convert this; ext; simp_rw [Algebra.smul_def]; rfl infer_instance lemma IsStandardSmoothOfRelativeDimension.algebraMap_isLocalizationAway {Rᵣ : Type*} [CommRing Rᵣ] [Algebra R Rᵣ] (r : R) [IsLocalization.Away r Rᵣ] : IsStandardSmoothOfRelativeDimension 0 (algebraMap R Rᵣ) := by have : (algebraMap R Rᵣ).toAlgebra = ‹Algebra R Rᵣ› := by ext rw [Algebra.smul_def] rfl rw [IsStandardSmoothOfRelativeDimension, this] exact Algebra.IsStandardSmoothOfRelativeDimension.localization_away r lemma isStandardSmooth_localizationPreserves : LocalizationPreserves IsStandardSmooth := isStandardSmooth_isStableUnderBaseChange.localizationPreserves lemma isStandardSmoothOfRelativeDimension_localizationPreserves : LocalizationPreserves (IsStandardSmoothOfRelativeDimension n) := (isStandardSmoothOfRelativeDimension_isStableUnderBaseChange n).localizationPreserves lemma isStandardSmooth_holdsForLocalizationAway : HoldsForLocalizationAway IsStandardSmooth := by introv R h exact (IsStandardSmoothOfRelativeDimension.algebraMap_isLocalizationAway r).isStandardSmooth lemma isStandardSmoothOfRelativeDimension_holdsForLocalizationAway : HoldsForLocalizationAway (IsStandardSmoothOfRelativeDimension 0) := by introv R h exact IsStandardSmoothOfRelativeDimension.algebraMap_isLocalizationAway r lemma isStandardSmooth_stableUnderCompositionWithLocalizationAway : StableUnderCompositionWithLocalizationAway IsStandardSmooth := isStandardSmooth_stableUnderComposition.stableUnderCompositionWithLocalizationAway isStandardSmooth_holdsForLocalizationAway lemma isStandardSmoothOfRelativeDimension_stableUnderCompositionWithLocalizationAway : StableUnderCompositionWithLocalizationAway (IsStandardSmoothOfRelativeDimension n) where left R S _ _ _ _ _ r _ _ hf := have : (algebraMap R S).IsStandardSmoothOfRelativeDimension 0 := IsStandardSmoothOfRelativeDimension.algebraMap_isLocalizationAway r add_zero n ▸ IsStandardSmoothOfRelativeDimension.comp hf this right _ S T _ _ _ _ s _ _ hf := have : (algebraMap S T).IsStandardSmoothOfRelativeDimension 0 := IsStandardSmoothOfRelativeDimension.algebraMap_isLocalizationAway s zero_add n ▸ IsStandardSmoothOfRelativeDimension.comp this hf end RingHom
.lake/packages/mathlib/Mathlib/RingTheory/RingHom/Surjective.lean
import Mathlib.RingTheory.LocalProperties.Basic /-! # The meta properties of surjective ring homomorphisms. ## Main results Let `R` be a commutative ring, `M` be a submonoid of `R`. * `surjective_localizationPreserves` : `M⁻¹R →+* M⁻¹S` is surjective if `R →+* S` is surjective. * `surjective_ofLocalizationSpan` : `R →+* S` is surjective if there exists a set `{ r }` that spans `R` such that `Rᵣ →+* Sᵣ` is surjective. * `surjective_localRingHom_of_surjective` : A surjective ring homomorphism `R →+* S` induces a surjective homomorphism `R_{f⁻¹(P)} →+* S_P` for every prime ideal `P` of `S`. -/ namespace RingHom open scoped TensorProduct open TensorProduct Algebra.TensorProduct universe u local notation "surjective" => fun {X Y : Type _} [CommRing X] [CommRing Y] => fun f : X →+* Y => Function.Surjective f theorem surjective_stableUnderComposition : StableUnderComposition surjective := by introv R hf hg; exact hg.comp hf theorem surjective_respectsIso : RespectsIso surjective := by apply surjective_stableUnderComposition.respectsIso intro _ _ _ _ e exact e.surjective theorem surjective_isStableUnderBaseChange : IsStableUnderBaseChange surjective := by refine IsStableUnderBaseChange.mk surjective_respectsIso ?_ classical introv h x induction x with | zero => exact ⟨0, map_zero _⟩ | tmul x y => obtain ⟨y, rfl⟩ := h y; use y • x; dsimp rw [TensorProduct.smul_tmul, Algebra.algebraMap_eq_smul_one] | add x y ex ey => obtain ⟨⟨x, rfl⟩, ⟨y, rfl⟩⟩ := ex, ey; exact ⟨x + y, map_add _ x y⟩ /-- `M⁻¹R →+* M⁻¹S` is surjective if `R →+* S` is surjective. -/ theorem surjective_localizationPreserves : LocalizationPreserves surjective := by introv R H x obtain ⟨x, ⟨_, s, hs, rfl⟩, rfl⟩ := IsLocalization.exists_mk'_eq (M.map f) x obtain ⟨y, rfl⟩ := H x use IsLocalization.mk' R' y ⟨s, hs⟩ rw [IsLocalization.map_mk'] /-- `R →+* S` is surjective if there exists a set `{ r }` that spans `R` such that `Rᵣ →+* Sᵣ` is surjective. -/ theorem surjective_ofLocalizationSpan : OfLocalizationSpan surjective := by introv R e H rw [← Set.range_eq_univ, 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.exists_mk'_eq (Submonoid.powers (r : R)) a rw [Localization.awayMap, IsLocalization.Away.map, IsLocalization.map_mk', 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 {R S : Type u} [CommRing R] [CommRing S] (f : R →+* S) (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 surjective_localizationPreserves _ _ _ _ h end RingHom
.lake/packages/mathlib/Mathlib/RingTheory/RingHom/Locally.lean
import Mathlib.RingTheory.LocalProperties.Basic import Mathlib.RingTheory.Localization.BaseChange import Mathlib.RingTheory.Localization.Away.Lemmas /-! # Target local closure of ring homomorphism properties If `P` is a property of ring homomorphisms, we call `Locally P` the closure of `P` with respect to standard open coverings on the (algebraic) target (i.e. geometric source). Hence for `f : R →+* S`, the property `Locally P` holds if it holds locally on `S`, i.e. if there exists a subset `{ t }` of `S` generating the unit ideal, such that `P` holds for all compositions `R →+* Sₜ`. Assuming without further mention that `P` is stable under composition with isomorphisms, `Locally P` is local on the target by construction, i.e. it satisfies `RingHom.OfLocalizationSpanTarget`. If `P` itself is local on the target, `Locally P` coincides with `P`. The `Locally` construction preserves various properties of `P`, e.g. if `P` is stable under composition, base change, etc., so is `Locally P`. ## Main results - `RingHom.locally_ofLocalizationSpanTarget`: `Locally P` is local on the target. - `RingHom.locally_holdsForLocalizationAway`: `Locally P` holds for localization away maps if `P` does. - `RingHom.locally_isStableUnderBaseChange`: `Locally P` is stable under base change if `P` is. - `RingHom.locally_stableUnderComposition`: `Locally P` is stable under composition if `P` is and `P` is preserved under localizations. - `RingHom.locally_StableUnderCompositionWithLocalizationAwayTarget` and `RingHom.locally_StableUnderCompositionWithLocalizationAwaySource`: `Locally P` is stable under composition with localization away maps if `P` is. - `RingHom.locally_localizationPreserves`: If `P` is preserved by localizations, then so is `Locally P`. -/ universe u v open TensorProduct namespace RingHom variable (P : ∀ {R S : Type u} [CommRing R] [CommRing S] (_ : R →+* S), Prop) /-- For a property of ring homomorphisms `P`, `Locally P` holds for `f : R →+* S` if it holds locally on `S`, i.e. if there exists a subset `{ t }` of `S` generating the unit ideal, such that `P` holds for all compositions `R →+* Sₜ`. We may require `s` to be finite here, for the equivalence, see `locally_iff_finite`. -/ def Locally {R S : Type u} [CommRing R] [CommRing S] (f : R →+* S) : Prop := ∃ (s : Set S) (_ : Ideal.span s = ⊤), ∀ t ∈ s, P ((algebraMap S (Localization.Away t)).comp f) variable {R S : Type u} [CommRing R] [CommRing S] lemma locally_iff_finite (f : R →+* S) : Locally P f ↔ ∃ (s : Finset S) (_ : Ideal.span (s : Set S) = ⊤), ∀ t ∈ s, P ((algebraMap S (Localization.Away t)).comp f) := by constructor · intro ⟨s, hsone, hs⟩ obtain ⟨s', h₁, h₂⟩ := (Ideal.span_eq_top_iff_finite s).mp hsone exact ⟨s', h₂, fun t ht ↦ hs t (h₁ ht)⟩ · intro ⟨s, hsone, hs⟩ use s, hsone, hs variable {P} /-- If `P` respects isomorphisms, to check `P` holds locally for `f : R →+* S`, it suffices to check `P` holds on a standard open cover. -/ lemma locally_of_exists (hP : RespectsIso P) (f : R →+* S) {ι : Type*} (s : ι → S) (hsone : Ideal.span (Set.range s) = ⊤) (Sₜ : ι → Type u) [∀ i, CommRing (Sₜ i)] [∀ i, Algebra S (Sₜ i)] [∀ i, IsLocalization.Away (s i) (Sₜ i)] (hf : ∀ i, P ((algebraMap S (Sₜ i)).comp f)) : Locally P f := by use Set.range s, hsone rintro - ⟨i, rfl⟩ let e : Localization.Away (s i) ≃+* Sₜ i := (IsLocalization.algEquiv (Submonoid.powers (s i)) _ _).toRingEquiv have : algebraMap S (Localization.Away (s i)) = e.symm.toRingHom.comp (algebraMap S (Sₜ i)) := RingHom.ext (fun x ↦ (AlgEquiv.commutes (IsLocalization.algEquiv _ _ _).symm _).symm) rw [this, RingHom.comp_assoc] exact hP.left _ _ (hf i) /-- Equivalence variant of `locally_of_exists`. This is sometimes easier to use, if the `IsLocalization.Away` instance can't be automatically inferred. -/ lemma locally_iff_exists (hP : RespectsIso P) (f : R →+* S) : Locally P f ↔ ∃ (ι : Type u) (s : ι → S) (_ : Ideal.span (Set.range s) = ⊤) (Sₜ : ι → Type u) (_ : (i : ι) → CommRing (Sₜ i)) (_ : (i : ι) → Algebra S (Sₜ i)) (_ : (i : ι) → IsLocalization.Away (s i : S) (Sₜ i)), ∀ i, P ((algebraMap S (Sₜ i)).comp f) := ⟨fun ⟨s, hsone, hs⟩ ↦ ⟨s, fun t : s ↦ (t : S), by simpa, fun t ↦ Localization.Away (t : S), inferInstance, inferInstance, inferInstance, fun t ↦ hs t.val t.property⟩, fun ⟨ι, s, hsone, Sₜ, _, _, hislocal, hs⟩ ↦ locally_of_exists hP f s hsone Sₜ hs⟩ /-- In the definition of `Locally` we may replace `Localization.Away` with an arbitrary algebra satisfying `IsLocalization.Away`. -/ lemma locally_iff_isLocalization (hP : RespectsIso P) (f : R →+* S) : Locally P f ↔ ∃ (s : Finset S) (_ : Ideal.span (s : Set S) = ⊤), ∀ t ∈ s, ∀ (Sₜ : Type u) [CommRing Sₜ] [Algebra S Sₜ] [IsLocalization.Away t Sₜ], P ((algebraMap S Sₜ).comp f) := by rw [locally_iff_finite P f] refine ⟨fun ⟨s, hsone, hs⟩ ↦ ⟨s, hsone, fun t ht Sₜ _ _ _ ↦ ?_⟩, fun ⟨s, hsone, hs⟩ ↦ ?_⟩ · let e : Localization.Away t ≃+* Sₜ := (IsLocalization.algEquiv (Submonoid.powers t) _ _).toRingEquiv have : algebraMap S Sₜ = e.toRingHom.comp (algebraMap S (Localization.Away t)) := RingHom.ext (fun x ↦ (AlgEquiv.commutes (IsLocalization.algEquiv _ _ _) _).symm) rw [this, RingHom.comp_assoc] exact hP.left _ _ (hs t ht) · exact ⟨s, hsone, fun t ht ↦ hs t ht _⟩ /-- If `f` satisfies `P`, then in particular it satisfies `Locally P`. -/ lemma locally_of (hP : RespectsIso P) (f : R →+* S) (hf : P f) : Locally P f := by use {1} let e : S ≃+* Localization.Away (1 : S) := (IsLocalization.atUnits S (Submonoid.powers 1) (by simp)).toRingEquiv simp only [Set.mem_singleton_iff, forall_eq, Ideal.span_singleton_one, exists_const] exact hP.left f e hf lemma locally_of_locally {Q : ∀ {R S : Type u} [CommRing R] [CommRing S], (R →+* S) → Prop} (hPQ : ∀ {R S : Type u} [CommRing R] [CommRing S] {f : R →+* S}, P f → Q f) {R S : Type u} [CommRing R] [CommRing S] {f : R →+* S} (hf : Locally P f) : Locally Q f := by obtain ⟨s, hsone, hs⟩ := hf exact ⟨s, hsone, fun t ht ↦ hPQ (hs t ht)⟩ /-- If `P` is local on the target, then `Locally P` coincides with `P`. -/ lemma locally_iff_of_localizationSpanTarget (hPi : RespectsIso P) (hPs : OfLocalizationSpanTarget P) {R S : Type u} [CommRing R] [CommRing S] (f : R →+* S) : Locally P f ↔ P f := ⟨fun ⟨s, hsone, hs⟩ ↦ hPs f s hsone (fun a ↦ hs a.val a.property), locally_of hPi f⟩ section OfLocalizationSpanTarget /-- `Locally P` is local on the target. -/ lemma locally_ofLocalizationSpanTarget (hP : RespectsIso P) : OfLocalizationSpanTarget (Locally P) := by intro R S _ _ f s hsone hs choose t htone ht using hs rw [locally_iff_exists hP] refine ⟨(a : s) × t a, IsLocalization.Away.mulNumerator s t, IsLocalization.Away.span_range_mulNumerator_eq_top hsone htone, fun ⟨a, b⟩ ↦ Localization.Away b.val, inferInstance, inferInstance, fun ⟨a, b⟩ ↦ ?_, ?_⟩ · haveI : IsLocalization.Away ((algebraMap S (Localization.Away a.val)) (IsLocalization.Away.sec a.val b.val).1) (Localization.Away b.val) := by apply IsLocalization.Away.of_associated (r := b.val) rw [← IsLocalization.Away.sec_spec] apply associated_mul_unit_right rw [map_pow _ _] exact IsUnit.pow _ (IsLocalization.Away.algebraMap_isUnit _) apply IsLocalization.Away.mul' (Localization.Away a.val) (Localization.Away b.val) · intro ⟨a, b⟩ rw [IsScalarTower.algebraMap_eq S (Localization.Away a.val) (Localization.Away b.val)] apply ht _ _ b.property end OfLocalizationSpanTarget section Stability /-- If `P` respects isomorphism, so does `Locally P`. -/ lemma locally_respectsIso (hPi : RespectsIso P) : RespectsIso (Locally P) where left {R S T} _ _ _ f e := fun ⟨s, hsone, hs⟩ ↦ by refine ⟨e '' s, ?_, ?_⟩ · rw [← Ideal.map_span, hsone, Ideal.map_top] · rintro - ⟨a, ha, rfl⟩ let e' : Localization.Away a ≃+* Localization.Away (e a) := IsLocalization.ringEquivOfRingEquiv _ _ e (Submonoid.map_powers e a) have : (algebraMap T (Localization.Away (e a))).comp e.toRingHom = e'.toRingHom.comp (algebraMap S (Localization.Away a)) := by ext x simp [e'] rw [← RingHom.comp_assoc, this, RingHom.comp_assoc] apply hPi.left exact hs a ha right {R S T} _ _ _ f e := fun ⟨s, hsone, hs⟩ ↦ ⟨s, hsone, fun a ha ↦ (RingHom.comp_assoc _ _ _).symm ▸ hPi.right _ _ (hs a ha)⟩ /-- If `P` holds for localization away maps, then so does `Locally P`. -/ lemma locally_holdsForLocalizationAway (hPa : HoldsForLocalizationAway P) : HoldsForLocalizationAway (Locally P) := by introv R _ use {1} simp only [Set.mem_singleton_iff, forall_eq, Ideal.span_singleton_one, exists_const] let e : S ≃ₐ[R] (Localization.Away (1 : S)) := (IsLocalization.atUnits S (Submonoid.powers 1) (by simp)).restrictScalars R haveI : IsLocalization.Away r (Localization.Away (1 : S)) := IsLocalization.isLocalization_of_algEquiv (Submonoid.powers r) e rw [← IsScalarTower.algebraMap_eq] apply hPa _ r /-- If `P` preserves localizations, then `Locally P` is stable under composition if `P` is. -/ lemma locally_stableUnderComposition (hPi : RespectsIso P) (hPl : LocalizationPreserves P) (hPc : StableUnderComposition P) : StableUnderComposition (Locally P) := by classical intro R S T _ _ _ f g hf hg rw [locally_iff_finite] at hf hg obtain ⟨sf, hsfone, hsf⟩ := hf obtain ⟨sg, hsgone, hsg⟩ := hg rw [locally_iff_exists hPi] refine ⟨sf × sg, fun (a, b) ↦ g a * b, ?_, fun (a, b) ↦ Localization.Away ((algebraMap T (Localization.Away b.val)) (g a.val)), inferInstance, inferInstance, inferInstance, ?_⟩ · rw [eq_top_iff, ← hsgone, Ideal.span_le] intro t ht have : 1 ∈ Ideal.span (Set.range <| fun a : sf ↦ a.val) := by simp [hsfone] simp only [Ideal.mem_span_range_iff_exists_fun, SetLike.mem_coe] at this ⊢ obtain ⟨cf, hcf⟩ := this let cg : sg → T := Pi.single ⟨t, ht⟩ 1 use fun (a, b) ↦ g (cf a) * cg b simp [cg, Pi.single_apply, Fintype.sum_prod_type, ← mul_assoc, ← Finset.sum_mul, ← map_mul, ← map_sum, hcf] at hcf ⊢ · intro ⟨a, b⟩ let g' := (algebraMap T (Localization.Away b.val)).comp g let a' := (algebraMap T (Localization.Away b.val)) (g a.val) have : (algebraMap T <| Localization.Away a').comp (g.comp f) = (Localization.awayMap g' a.val).comp ((algebraMap S (Localization.Away a.val)).comp f) := by ext x simp only [coe_comp, Function.comp_apply, a'] change _ = Localization.awayMap g' a.val (algebraMap S _ (f x)) simp only [Localization.awayMap, IsLocalization.Away.map, IsLocalization.map_eq] rfl simp only [this, a'] apply hPc _ _ (hsf a.val a.property) apply @hPl _ _ _ _ g' _ _ _ _ _ _ _ _ ?_ (hsg b.val b.property) exact IsLocalization.Away.instMapRingHomPowersOfCoe (Localization.Away (g' a.val)) a.val /-- If `P` is stable under composition with localization away maps on the right, then so is `Locally P`. -/ lemma locally_StableUnderCompositionWithLocalizationAwayTarget (hP0 : RespectsIso P) (hPa : StableUnderCompositionWithLocalizationAwayTarget P) : StableUnderCompositionWithLocalizationAwayTarget (Locally P) := by intro R S T _ _ _ _ t _ f hf simp only [locally_iff_isLocalization hP0 f] at hf obtain ⟨s, hsone, hs⟩ := hf refine ⟨algebraMap S T '' s, ?_, ?_⟩ · rw [← Ideal.map_span, hsone, Ideal.map_top] · rintro - ⟨a, ha, rfl⟩ letI : Algebra (Localization.Away a) (Localization.Away (algebraMap S T a)) := (IsLocalization.Away.map _ _ (algebraMap S T) a).toAlgebra have : (algebraMap (Localization.Away a) (Localization.Away (algebraMap S T a))).comp (algebraMap S (Localization.Away a)) = (algebraMap T (Localization.Away (algebraMap S T a))).comp (algebraMap S T) := by simp [algebraMap_toAlgebra, IsLocalization.Away.map] rw [← comp_assoc, ← this, comp_assoc] haveI : IsScalarTower S (Localization.Away a) (Localization.Away ((algebraMap S T) a)) := by apply IsScalarTower.of_algebraMap_eq intro x simp [algebraMap_toAlgebra, IsLocalization.Away.map, ← IsScalarTower.algebraMap_apply] haveI : IsLocalization.Away (algebraMap S (Localization.Away a) t) (Localization.Away (algebraMap S T a)) := IsLocalization.Away.commutes _ T ((Localization.Away (algebraMap S T a))) a t apply hPa _ (algebraMap S (Localization.Away a) t) apply hs a ha /-- If `P` is stable under composition with localization away maps on the left, then so is `Locally P`. -/ lemma locally_StableUnderCompositionWithLocalizationAwaySource (hPa : StableUnderCompositionWithLocalizationAwaySource P) : StableUnderCompositionWithLocalizationAwaySource (Locally P) := by intro R S T _ _ _ _ r _ f ⟨s, hsone, hs⟩ refine ⟨s, hsone, fun t ht ↦ ?_⟩ rw [← comp_assoc] exact hPa _ r _ (hs t ht) attribute [local instance] Algebra.TensorProduct.rightAlgebra in /-- If `P` is stable under base change, then so is `Locally P`. -/ lemma locally_isStableUnderBaseChange (hPi : RespectsIso P) (hPb : IsStableUnderBaseChange P) : IsStableUnderBaseChange (Locally P) := by apply IsStableUnderBaseChange.mk (locally_respectsIso hPi) introv hf obtain ⟨s, hsone, hs⟩ := hf rw [locally_iff_exists hPi] letI (a : s) : Algebra (S ⊗[R] T) (S ⊗[R] Localization.Away a.val) := (Algebra.TensorProduct.map (AlgHom.id R S) (IsScalarTower.toAlgHom R _ _)).toRingHom.toAlgebra letI (a : s) : Algebra T (S ⊗[R] Localization.Away a.val) := ((algebraMap _ (S ⊗[R] Localization.Away a.val)).comp (algebraMap T (S ⊗[R] T))).toAlgebra haveI (a : s) : IsScalarTower T (S ⊗[R] T) (S ⊗[R] Localization.Away a.val) := IsScalarTower.of_algebraMap_eq' rfl haveI (a : s) : IsScalarTower T (Localization.Away a.val) (S ⊗[R] Localization.Away a.val) := IsScalarTower.of_algebraMap_eq' rfl haveI (a : s) : IsScalarTower S (S ⊗[R] T) (S ⊗[R] Localization.Away a.val) := IsScalarTower.of_algebraMap_eq <| by intro x simp [RingHom.algebraMap_toAlgebra] haveI (a : s) : Algebra.IsPushout T (Localization.Away a.val) (S ⊗[R] T) (S ⊗[R] Localization.Away a.val) := by rw [← Algebra.IsPushout.comp_iff R _ S] infer_instance refine ⟨s, fun a ↦ Algebra.TensorProduct.includeRight a.val, ?_, fun a ↦ (S ⊗[R] Localization.Away a.val), inferInstance, inferInstance, ?_, ?_⟩ · rw [← Set.image_eq_range, ← Ideal.map_span, hsone, Ideal.map_top] · intro a convert_to IsLocalization (Algebra.algebraMapSubmonoid (S ⊗[R] T) (Submonoid.powers a.val)) (S ⊗[R] Localization.Away a.val) · simp only [Algebra.TensorProduct.includeRight_apply, Algebra.algebraMapSubmonoid, Submonoid.map_powers] rfl · rw [← isLocalizedModule_iff_isLocalization, isLocalizedModule_iff_isBaseChange (S := Submonoid.powers a.val) (A := Localization.Away a.val)] exact Algebra.IsPushout.out · intro a rw [← IsScalarTower.algebraMap_eq] apply hPb R (Localization.Away a.val) rw [IsScalarTower.algebraMap_eq R T] exact hs a a.property /-- If `P` is preserved by localization away, then so is `Locally P`. -/ lemma locally_localizationAwayPreserves (hPl : LocalizationAwayPreserves P) : LocalizationAwayPreserves (Locally P) := by introv R hf obtain ⟨s, hsone, hs⟩ := hf rw [locally_iff_exists hPl.respectsIso] let rₐ (a : s) : Localization.Away a.val := algebraMap _ _ (f r) let Sₐ (a : s) := Localization.Away (rₐ a) haveI (a : s) : IsLocalization.Away (((algebraMap S (Localization.Away a.val)).comp f) r) (Sₐ a) := inferInstanceAs (IsLocalization.Away (rₐ a) (Sₐ a)) haveI (a : s) : IsLocalization (Algebra.algebraMapSubmonoid (Localization.Away a.val) (Submonoid.map f (Submonoid.powers r))) (Sₐ a) := by convert inferInstanceAs (IsLocalization.Away (rₐ a) (Sₐ a)) simp [rₐ, Algebra.algebraMapSubmonoid] have H (a : s) : Submonoid.powers (f r) ≤ (Submonoid.powers (rₐ a)).comap (algebraMap S (Localization.Away a.val)) := by simp [rₐ, Submonoid.powers_le] letI (a : s) : Algebra S' (Sₐ a) := (IsLocalization.map (Sₐ a) (algebraMap S (Localization.Away a.val)) (H a)).toAlgebra haveI (a : s) : IsScalarTower S S' (Sₐ a) := IsScalarTower.of_algebraMap_eq' (IsLocalization.map_comp (H a)).symm refine ⟨s, fun a ↦ algebraMap S S' a.val, ?_, Sₐ, inferInstance, inferInstance, fun a ↦ ?_, fun a ↦ ?_⟩ · rw [← Set.image_eq_range, ← Ideal.map_span, hsone, Ideal.map_top] · convert IsLocalization.commutes (T := Sₐ a) (M₁ := (Submonoid.powers r).map f) (S₁ := S') (S₂ := Localization.Away a.val) (M₂ := Submonoid.powers a.val) simp [Algebra.algebraMapSubmonoid] · rw [algebraMap_toAlgebra, IsLocalization.Away.map, IsLocalization.map_comp_map] exact hPl ((algebraMap _ (Localization.Away a.val)).comp f) r R' (Sₐ a) (hs _ a.2) /-- If `P` is preserved by localizations, then so is `Locally P`. -/ lemma locally_localizationPreserves (hPl : LocalizationPreserves P) : LocalizationPreserves (Locally P) := by introv R hf obtain ⟨s, hsone, hs⟩ := hf rw [locally_iff_exists hPl.away.respectsIso] let Mₐ (a : s) : Submonoid (Localization.Away a.val) := (M.map f).map (algebraMap S (Localization.Away a.val)) let Sₐ (a : s) := Localization (Mₐ a) have hM (a : s) : M.map ((algebraMap S (Localization.Away a.val)).comp f) = Mₐ a := (M.map_map _ _).symm haveI (a : s) : IsLocalization (M.map ((algebraMap S (Localization.Away a.val)).comp f)) (Sₐ a) := by rw [hM] infer_instance haveI (a : s) : IsLocalization (Algebra.algebraMapSubmonoid (Localization.Away a.val) (M.map f)) (Sₐ a) := inferInstanceAs <| IsLocalization (Mₐ a) (Sₐ a) letI (a : s) : Algebra S' (Sₐ a) := (IsLocalization.map (Sₐ a) (algebraMap S (Localization.Away a.val)) (M.map f).le_comap_map).toAlgebra haveI (a : s) : IsScalarTower S S' (Sₐ a) := IsScalarTower.of_algebraMap_eq' (IsLocalization.map_comp (M.map f).le_comap_map).symm refine ⟨s, fun a ↦ algebraMap S S' a.val, ?_, Sₐ, inferInstance, inferInstance, fun a ↦ ?_, fun a ↦ ?_⟩ · rw [← Set.image_eq_range, ← Ideal.map_span, hsone, Ideal.map_top] · convert IsLocalization.commutes (T := Sₐ a) (M₁ := M.map f) (S₁ := S') (S₂ := Localization.Away a.val) (M₂ := Submonoid.powers a.val) simp [Algebra.algebraMapSubmonoid] · rw [algebraMap_toAlgebra, IsLocalization.map_comp_map] apply hPl exact hs a.val a.property /-- If `P` is preserved by localizations and stable under composition with localization away maps, then `Locally P` is a local property of ring homomorphisms. -/ lemma locally_propertyIsLocal (hPl : LocalizationAwayPreserves P) (hPa : StableUnderCompositionWithLocalizationAway P) : PropertyIsLocal (Locally P) where localizationAwayPreserves := locally_localizationAwayPreserves hPl StableUnderCompositionWithLocalizationAwayTarget := locally_StableUnderCompositionWithLocalizationAwayTarget hPl.respectsIso hPa.right ofLocalizationSpan := (locally_ofLocalizationSpanTarget hPl.respectsIso).ofLocalizationSpan (locally_StableUnderCompositionWithLocalizationAwaySource hPa.left) ofLocalizationSpanTarget := locally_ofLocalizationSpanTarget hPl.respectsIso end Stability end RingHom
.lake/packages/mathlib/Mathlib/RingTheory/RingHom/Etale.lean
import Mathlib.RingTheory.RingHom.Smooth import Mathlib.RingTheory.RingHom.Unramified /-! # Étale ring homomorphisms We show the meta properties of étale morphisms. -/ universe u namespace RingHom variable {R S : Type*} [CommRing R] [CommRing S] /-- A ring hom `R →+* S` is étale, if `S` is an étale `R`-algebra. -/ @[algebraize RingHom.Etale.toAlgebra] def Etale {R S : Type*} [CommRing R] [CommRing S] (f : R →+* S) : Prop := @Algebra.Etale R S _ _ f.toAlgebra /-- Helper lemma for the `algebraize` tactic -/ lemma Etale.toAlgebra {f : R →+* S} (hf : Etale f) : @Algebra.Etale R S _ _ f.toAlgebra := hf variable {R S : Type*} [CommRing R] [CommRing S] (f : R →+* S) lemma etale_algebraMap [Algebra R S] : (algebraMap R S).Etale ↔ Algebra.Etale R S := by rw [RingHom.Etale, toAlgebra_algebraMap] lemma etale_iff_formallyUnramified_and_smooth : f.Etale ↔ f.FormallyUnramified ∧ f.Smooth := by algebraize [f] simp only [Etale, Smooth, FormallyUnramified] exact ⟨fun h ↦ ⟨inferInstance, inferInstance, inferInstance⟩, fun ⟨h1, h2⟩ ↦ ⟨.of_formallyUnramified_and_formallySmooth, inferInstance⟩⟩ lemma Etale.eq_formallyUnramified_and_smooth : @Etale = fun R S (_ : CommRing R) (_ : CommRing S) f ↦ f.FormallyUnramified ∧ f.Smooth := by ext rw [etale_iff_formallyUnramified_and_smooth] lemma Etale.isStableUnderBaseChange : IsStableUnderBaseChange Etale := by rw [eq_formallyUnramified_and_smooth] exact FormallyUnramified.isStableUnderBaseChange.and Smooth.isStableUnderBaseChange lemma Etale.propertyIsLocal : PropertyIsLocal Etale := by rw [eq_formallyUnramified_and_smooth] exact FormallyUnramified.propertyIsLocal.and Smooth.propertyIsLocal lemma Etale.respectsIso : RespectsIso Etale := propertyIsLocal.respectsIso lemma Etale.ofLocalizationSpanTarget : OfLocalizationSpanTarget Etale := propertyIsLocal.ofLocalizationSpanTarget lemma Etale.ofLocalizationSpan : OfLocalizationSpan Etale := propertyIsLocal.ofLocalizationSpan lemma Etale.stableUnderComposition : StableUnderComposition Etale := by rw [eq_formallyUnramified_and_smooth] exact FormallyUnramified.stableUnderComposition.and Smooth.stableUnderComposition end RingHom
.lake/packages/mathlib/Mathlib/RingTheory/RingHom/FaithfullyFlat.lean
import Mathlib.RingTheory.RingHom.Flat /-! # Faithfully flat ring maps A ring map `f : R →+* S` is faithfully flat if `S` is faithfully flat as an `R`-algebra. This is the same as being flat and a surjection on prime spectra. -/ namespace RingHom variable {R S : Type*} [CommRing R] [CommRing S] {f : R →+* S} /-- A ring map `f : R →+* S` is faithfully flat if `S` is faithfully flat as an `R`-algebra. -/ @[stacks 00HB "Part (4)", algebraize Module.FaithfullyFlat] def FaithfullyFlat {R S : Type*} [CommRing R] [CommRing S] (f : R →+* S) : Prop := letI : Algebra R S := f.toAlgebra Module.FaithfullyFlat R S lemma faithfullyFlat_algebraMap_iff [Algebra R S] : (algebraMap R S).FaithfullyFlat ↔ Module.FaithfullyFlat R S := by simp only [FaithfullyFlat] congr! exact Algebra.algebra_ext _ _ fun _ ↦ rfl namespace FaithfullyFlat lemma flat (hf : f.FaithfullyFlat) : f.Flat := by algebraize [f] exact inferInstanceAs <| Module.Flat R S lemma iff_flat_and_comap_surjective : f.FaithfullyFlat ↔ f.Flat ∧ Function.Surjective f.specComap := by algebraize [f] rw [← algebraMap_toAlgebra f, faithfullyFlat_algebraMap_iff, flat_algebraMap_iff] exact ⟨fun h ↦ ⟨inferInstance, PrimeSpectrum.specComap_surjective_of_faithfullyFlat⟩, fun ⟨h, hf⟩ ↦ .of_specComap_surjective hf⟩ lemma eq_and : FaithfullyFlat = fun (f : R →+* S) ↦ f.Flat ∧ Function.Surjective f.specComap := by ext rw [iff_flat_and_comap_surjective] lemma stableUnderComposition : StableUnderComposition FaithfullyFlat := by introv R hf hg algebraize [f, g, g.comp f] rw [← algebraMap_toAlgebra (g.comp f), faithfullyFlat_algebraMap_iff] exact .trans R S T lemma of_bijective (hf : Function.Bijective f) : f.FaithfullyFlat := by rw [iff_flat_and_comap_surjective] refine ⟨.of_bijective hf, fun p ↦ ?_⟩ use ((RingEquiv.ofBijective f hf).symm : _ →+* _).specComap p have : ((RingEquiv.ofBijective f hf).symm : _ →+* _).comp f = id R := by ext exact (RingEquiv.ofBijective f hf).injective (by simp) rw [← PrimeSpectrum.specComap_comp_apply, this, PrimeSpectrum.specComap_id] lemma injective (hf : f.FaithfullyFlat) : Function.Injective ⇑f := by algebraize [f] exact FaithfulSMul.algebraMap_injective R S lemma respectsIso : RespectsIso FaithfullyFlat := stableUnderComposition.respectsIso (fun e ↦ .of_bijective e.bijective) lemma isStableUnderBaseChange : IsStableUnderBaseChange FaithfullyFlat := by refine .mk respectsIso (fun R S T _ _ _ _ _ _ ↦ show (algebraMap _ _).FaithfullyFlat from ?_) rw [faithfullyFlat_algebraMap_iff] at * infer_instance end RingHom.FaithfullyFlat
.lake/packages/mathlib/Mathlib/RingTheory/RingHom/FiniteType.lean
import Mathlib.RingTheory.FiniteStability import Mathlib.RingTheory.Localization.InvSubmonoid import Mathlib.RingTheory.RingHom.Finite /-! # The meta properties of finite-type ring homomorphisms. ## Main results Let `R` be a commutative ring, `S` is an `R`-algebra, `M` be a submonoid of `R`. * `finiteType_localizationPreserves` : If `S` is a finite type `R`-algebra, then `S' = M⁻¹S` is a finite type `R' = M⁻¹R`-algebra. * `finiteType_ofLocalizationSpan` : `S` is a finite type `R`-algebra if there exists a set `{ r }` that spans `R` such that `Sᵣ` is a finite type `Rᵣ`-algebra. *`RingHom.finiteType_isLocal`: `RingHom.FiniteType` is a local property. -/ section Algebra open scoped Pointwise TensorProduct variable {R S : Type*} [CommRing R] [CommRing S] [Algebra R S] (M : Submonoid R) variable (R' S' : Type*) [CommRing R'] [CommRing S'] variable [Algebra R R'] [Algebra S S'] variable {S'} in open scoped Classical in /-- 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'] [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_mono hA₁) hx (Set.mem_image_of_mem _ (hA₂ y.2)) obtain ⟨x', hx', hx''⟩ := hn n (le_of_eq rfl) rw [Algebra.smul_def, ← 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] variable {S'} in open scoped Classical in /-- 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'] [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 /-- Finite-type can be checked on a standard covering of the target. -/ lemma Algebra.FiniteType.of_span_eq_top_target (s : Set S) (hs : Ideal.span (s : Set S) = ⊤) (h : ∀ x ∈ s, Algebra.FiniteType R (Localization.Away x)) : Algebra.FiniteType R S := by obtain ⟨s, h₁, hs⟩ := (Ideal.span_eq_top_iff_finite s).mp hs replace h (i : s) : Algebra.FiniteType R (Localization.Away i.val) := h i (h₁ i.property) classical -- Suppose `s : Finset S` spans `S`, and each `Sᵣ` is finitely generated as an `R`-algebra. -- Say `t r : Finset Sᵣ` generates `Sᵣ`. By assumption, we may find `lᵢ` such that -- `∑ lᵢ * sᵢ = 1`. I claim that all `s` and `l` and the numerators of `t` and generates `S`. replace h := fun r => (h r).1 choose t ht using h obtain ⟨l, hl⟩ := (Finsupp.mem_span_iff_linearCombination S (s : Set S) 1).mp (show (1 : S) ∈ Ideal.span (s : Set S) by rw [hs]; trivial) let sf := fun x : s => IsLocalization.finsetIntegerMultiple (Submonoid.powers (x : S)) (t x) use s.attach.biUnion sf ∪ s ∪ l.support.image l rw [_root_.eq_top_iff] -- We need to show that every `x` falls in the subalgebra generated by those elements. -- Since all `s` and `l` are in the subalgebra, it suffices to check that `sᵢ ^ nᵢ • x` falls in -- the algebra for each `sᵢ` and some `nᵢ`. rintro x - apply Subalgebra.mem_of_span_eq_top_of_smul_pow_mem _ (s : Set S) l hl _ _ x _ · intro x hx apply Algebra.subset_adjoin rw [Finset.coe_union, Finset.coe_union] exact Or.inl (Or.inr hx) · intro i by_cases h : l i = 0; · rw [h]; exact zero_mem _ apply Algebra.subset_adjoin rw [Finset.coe_union, Finset.coe_image] exact Or.inr (Set.mem_image_of_mem _ (Finsupp.mem_support_iff.mpr h)) · intro r rw [Finset.coe_union, Finset.coe_union, Finset.coe_biUnion] -- Since all `sᵢ` and numerators of `t r` are in the algebra, it suffices to show that the -- image of `x` in `Sᵣ` falls in the `R`-adjoin of `t r`, which is of course true. -- Porting note: The following `obtain` fails because Lean wants to know right away what the -- placeholders are, so we need to provide a little more guidance -- obtain ⟨⟨_, n₂, rfl⟩, hn₂⟩ := IsLocalization.exists_smul_mem_of_mem_adjoin -- (Submonoid.powers (r : S)) x (t r) (Algebra.adjoin R _) _ _ _ rw [show ∀ A : Set S, (∃ n, (r : S) ^ n • x ∈ Algebra.adjoin R A) ↔ (∃ m : (Submonoid.powers (r : S)), (m : S) • x ∈ Algebra.adjoin R A) by { exact fun _ => by simp [Submonoid.mem_powers_iff] }] refine IsLocalization.exists_smul_mem_of_mem_adjoin (Submonoid.powers (r : S)) x (t r) (Algebra.adjoin R _) ?_ ?_ ?_ · intro x hx apply Algebra.subset_adjoin exact Or.inl (Or.inl ⟨_, ⟨r, rfl⟩, _, ⟨s.mem_attach r, rfl⟩, hx⟩) · rw [Submonoid.powers_eq_closure, Submonoid.closure_le, Set.singleton_subset_iff] apply Algebra.subset_adjoin exact Or.inl (Or.inr r.2) · rw [ht]; trivial attribute [local instance] Algebra.TensorProduct.rightAlgebra in lemma Algebra.FiniteType.of_span_eq_top_source (s : Set R) (hs : Ideal.span (s : Set R) = ⊤) (h : ∀ i ∈ s, Algebra.FiniteType (Localization.Away i) (Localization.Away i ⊗[R] S)) : Algebra.FiniteType R S := by obtain ⟨s, h₁, hs⟩ := (Ideal.span_eq_top_iff_finite s).mp hs replace h (i : s) := h i.val (h₁ i.property) classical letI := fun r : s => (Localization.awayMap (algebraMap R S) r).toAlgebra set f := algebraMap R 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 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 r.val ⊗[R] S)) (algebraMap S _ 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, ← 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 Algebra namespace RingHom open scoped Pointwise TensorProduct universe u variable {R S : Type*} [CommRing R] [CommRing S] (M : Submonoid R) (f : R →+* S) variable (R' S' : Type*) [CommRing R'] [CommRing S'] variable [Algebra R R'] [Algebra S S'] theorem finiteType_stableUnderComposition : StableUnderComposition @FiniteType := by introv R hf hg exact hg.comp hf theorem finiteType_respectsIso : RingHom.RespectsIso @RingHom.FiniteType := by refine finiteType_stableUnderComposition.respectsIso (fun {R S} _ _ e ↦ ?_) algebraize [e.toRingHom] apply Algebra.FiniteType.equiv (inferInstanceAs <| Algebra.FiniteType R R) <| .ofRingEquiv (congrFun rfl) theorem finiteType_isStableUnderBaseChange : IsStableUnderBaseChange @FiniteType := by apply IsStableUnderBaseChange.mk · exact finiteType_respectsIso · introv h rw [finiteType_algebraMap] at h suffices Algebra.FiniteType S (S ⊗[R] T) by rw [RingHom.FiniteType]; convert this; ext; simp_rw [Algebra.smul_def]; rfl infer_instance /-- If `S` is a finite type `R`-algebra, then `S' = M⁻¹S` is a finite type `R' = M⁻¹R`-algebra. -/ theorem finiteType_localizationPreserves : RingHom.LocalizationPreserves @RingHom.FiniteType := finiteType_isStableUnderBaseChange.localizationPreserves theorem localization_away_map_finiteType (R S R' S' : Type u) [CommRing R] [CommRing S] [CommRing R'] [CommRing S'] [Algebra R R'] (f : R →+* S) [Algebra S S'] (r : R) [IsLocalization.Away r R'] [IsLocalization.Away (f r) S'] (hf : f.FiniteType) : (IsLocalization.Away.map R' S' f r).FiniteType := finiteType_localizationPreserves.away _ r _ _ hf theorem finiteType_ofLocalizationSpan : RingHom.OfLocalizationSpan @RingHom.FiniteType := by refine OfLocalizationSpan.mk _ finiteType_respectsIso (fun s hs h ↦ ?_) simp_rw [finiteType_algebraMap] at h ⊢ exact Algebra.FiniteType.of_span_eq_top_source s hs h theorem finiteType_holdsForLocalizationAway : HoldsForLocalizationAway @FiniteType := by introv R _ rw [finiteType_algebraMap] exact IsLocalization.finiteType_of_monoid_fg (Submonoid.powers r) S theorem finiteType_ofLocalizationSpanTarget : OfLocalizationSpanTarget @FiniteType := by introv R hs H algebraize [f] replace H : ∀ r ∈ s, Algebra.FiniteType R (Localization.Away (r : S)) := by intro r hr; simp_rw [RingHom.FiniteType] at H; convert H ⟨r, hr⟩; ext simp_rw [Algebra.smul_def]; rfl exact Algebra.FiniteType.of_span_eq_top_target s hs H theorem finiteType_isLocal : PropertyIsLocal @FiniteType := ⟨finiteType_localizationPreserves.away, finiteType_ofLocalizationSpanTarget, finiteType_ofLocalizationSpanTarget.ofLocalizationSpan (finiteType_stableUnderComposition.stableUnderCompositionWithLocalizationAway finiteType_holdsForLocalizationAway).left, (finiteType_stableUnderComposition.stableUnderCompositionWithLocalizationAway finiteType_holdsForLocalizationAway).right⟩ end RingHom
.lake/packages/mathlib/Mathlib/RingTheory/RingHom/Smooth.lean
import Mathlib.RingTheory.RingHom.FinitePresentation import Mathlib.RingTheory.Smooth.Locus /-! # Smooth ring homomorphisms In this file we define smooth ring homomorphisms and show their meta properties. -/ universe u variable {R S : Type*} [CommRing R] [CommRing S] open TensorProduct namespace RingHom /-- A ring homomorphism `f : R →+* S` is formally smooth if `S` is formally smooth as an `R` algebra. -/ @[algebraize RingHom.FormallySmooth.toAlgebra] def FormallySmooth (f : R →+* S) : Prop := letI := f.toAlgebra Algebra.FormallySmooth R S /-- Helper lemma for the `algebraize` tactic -/ lemma FormallySmooth.toAlgebra {f : R →+* S} (hf : FormallySmooth f) : @Algebra.FormallySmooth R S _ _ f.toAlgebra := hf lemma formallySmooth_algebraMap [Algebra R S] : (algebraMap R S).FormallySmooth ↔ Algebra.FormallySmooth R S := by rw [FormallySmooth, toAlgebra_algebraMap] lemma FormallySmooth.holdsForLocalizationAway : HoldsForLocalizationAway @FormallySmooth := fun _ _ _ _ _ r _ ↦ formallySmooth_algebraMap.mpr <| .of_isLocalization (.powers r) lemma FormallySmooth.stableUnderComposition : StableUnderComposition @FormallySmooth := by intro R S T _ _ _ f g hf hg algebraize [f, g, g.comp f] exact .comp R S T lemma FormallySmooth.respectsIso : RespectsIso @FormallySmooth := stableUnderComposition.respectsIso fun e ↦ holdsForLocalizationAway.of_bijective _ _ e.bijective lemma FormallySmooth.isStableUnderBaseChange : IsStableUnderBaseChange @FormallySmooth := by refine .mk respectsIso ?_ introv H rw [formallySmooth_algebraMap] at H ⊢ infer_instance lemma FormallySmooth.localizationPreserves : LocalizationPreserves @FormallySmooth := isStableUnderBaseChange.localizationPreserves /-- A ring homomorphism `f : R →+* S` is smooth if `S` is smooth as an `R` algebra. -/ @[algebraize RingHom.Smooth.toAlgebra] def Smooth (f : R →+* S) : Prop := letI : Algebra R S := f.toAlgebra Algebra.Smooth R S /-- Helper lemma for the `algebraize` tactic -/ lemma Smooth.toAlgebra {f : R →+* S} (hf : Smooth f) : @Algebra.Smooth R _ S _ f.toAlgebra := hf lemma smooth_algebraMap [Algebra R S] : (algebraMap R S).Smooth ↔ Algebra.Smooth R S := by rw [RingHom.Smooth, toAlgebra_algebraMap] lemma smooth_def {f : R →+* S} : f.Smooth ↔ f.FormallySmooth ∧ f.FinitePresentation := letI := f.toAlgebra Algebra.smooth_iff _ _ namespace Smooth variable {R S T : Type*} [CommRing R] [CommRing S] [CommRing T] /-- Composition of smooth ring homomorphisms is smooth. -/ lemma comp {f : R →+* S} {g : S →+* T} (hf : f.Smooth) (hg : g.Smooth) : (g.comp f).Smooth := by algebraize [f, g, g.comp f] exact Algebra.Smooth.comp R S T lemma stableUnderComposition : StableUnderComposition Smooth := fun _ _ _ _ _ _ _ _ ↦ RingHom.Smooth.comp lemma isStableUnderBaseChange : IsStableUnderBaseChange Smooth := by convert RingHom.FormallySmooth.isStableUnderBaseChange.and RingHom.finitePresentation_isStableUnderBaseChange rw [smooth_def] lemma holdsForLocalizationAway : HoldsForLocalizationAway Smooth := by introv R h rw [smooth_algebraMap] exact ⟨Algebra.FormallySmooth.of_isLocalization (.powers r), IsLocalization.Away.finitePresentation r⟩ variable (R) in /-- The identity of a ring is smooth. -/ lemma id : RingHom.Smooth (RingHom.id R) := holdsForLocalizationAway.containsIdentities R lemma ofLocalizationSpanTarget : OfLocalizationSpanTarget Smooth := by introv R hs hf have : f.FinitePresentation := finitePresentation_ofLocalizationSpanTarget _ s hs fun r ↦ (hf r).finitePresentation algebraize [f] refine ⟨?_, ‹_›⟩ rw [← Algebra.smoothLocus_eq_univ_iff, ← Set.univ_subset_iff, ← TopologicalSpace.Opens.coe_top, ← PrimeSpectrum.iSup_basicOpen_eq_top_iff'.mpr hs] simp only [TopologicalSpace.Opens.coe_iSup, Set.iUnion_subset_iff, Algebra.basicOpen_subset_smoothLocus_iff, ← formallySmooth_algebraMap] exact fun r hr ↦ (hf ⟨r, hr⟩).1 /-- Smoothness is a local property of ring homomorphisms. -/ lemma propertyIsLocal : PropertyIsLocal Smooth where localizationAwayPreserves := isStableUnderBaseChange.localizationPreserves.away ofLocalizationSpanTarget := ofLocalizationSpanTarget ofLocalizationSpan := ofLocalizationSpanTarget.ofLocalizationSpan (stableUnderComposition.stableUnderCompositionWithLocalizationAway holdsForLocalizationAway).left StableUnderCompositionWithLocalizationAwayTarget := (stableUnderComposition.stableUnderCompositionWithLocalizationAway holdsForLocalizationAway).right end RingHom.Smooth
.lake/packages/mathlib/Mathlib/RingTheory/RingHom/Injective.lean
import Mathlib.RingTheory.RingHomProperties /-! # Meta properties of injective ring homomorphisms -/ lemma _root_.RingHom.injective_stableUnderComposition : RingHom.StableUnderComposition (fun f ↦ Function.Injective f) := by intro R S T _ _ _ f g hf hg simp only [RingHom.coe_comp] exact Function.Injective.comp hg hf lemma _root_.RingHom.injective_respectsIso : RingHom.RespectsIso (fun f ↦ Function.Injective f) := by apply RingHom.injective_stableUnderComposition.respectsIso intro R S _ _ e exact e.bijective.injective
.lake/packages/mathlib/Mathlib/RingTheory/RingHom/FinitePresentation.lean
import Mathlib.RingTheory.Localization.Finiteness import Mathlib.RingTheory.RingHom.FiniteType import Mathlib.RingTheory.Localization.Away.AdjoinRoot /-! # The meta properties of finitely-presented ring homomorphisms. The main result is `RingHom.finitePresentation_isLocal`. -/ open scoped Pointwise TensorProduct namespace Algebra.FinitePresentation variable {R S : Type*} [CommRing R] [CommRing S] [Algebra R S] /-- If `S` is an `R`-algebra with a surjection from a finitely-presented `R`-algebra `A`, such that localized at a spanning set `{ r }` of elements of `A`, `Sᵣ` is finitely-presented, then `S` is finitely presented. This is almost `finitePresentation_ofLocalizationSpanTarget`. The difference is, that here the set `t` generates the unit ideal of `A`, while in the general version, it only generates a quotient of `A`. -/ lemma of_span_eq_top_target_aux {A : Type*} [CommRing A] [Algebra R A] [Algebra.FinitePresentation R A] (f : A →ₐ[R] S) (hf : Function.Surjective f) (t : Finset A) (ht : Ideal.span (t : Set A) = ⊤) (H : ∀ g : t, Algebra.FinitePresentation R (Localization.Away (f g))) : Algebra.FinitePresentation R S := by apply Algebra.FinitePresentation.of_surjective hf apply RingHom.ker_fg_of_localizationSpan t ht intro g let f' : Localization.Away g.val →ₐ[R] Localization.Away (f g) := Localization.awayMapₐ f g.val have (g : t) : Algebra.FinitePresentation R (Localization.Away g.val) := haveI : Algebra.FinitePresentation A (Localization.Away g.val) := IsLocalization.Away.finitePresentation g.val Algebra.FinitePresentation.trans R A (Localization.Away g.val) apply Algebra.FinitePresentation.ker_fG_of_surjective f' exact IsLocalization.Away.mapₐ_surjective_of_surjective _ hf universe u /-- Finite-presentation can be checked on a standard covering of the target. -/ lemma of_span_eq_top_target (s : Set S) (hs : Ideal.span (s : Set S) = ⊤) (h : ∀ i ∈ s, Algebra.FinitePresentation R (Localization.Away i)) : Algebra.FinitePresentation R S := by obtain ⟨s, h₁, hs⟩ := (Ideal.span_eq_top_iff_finite s).mp hs replace h (i : s) : Algebra.FinitePresentation R (Localization.Away i.val) := h i (h₁ i.property) classical /- We already know that `S` is of finite type over `R`, so we have a surjection `MvPolynomial (Fin n) R →ₐ[R] S`. To reason about the kernel, we want to check it on the stalks of preimages of `s`. But the preimages do not necessarily span `MvPolynomial (Fin n) R`, so we quotient out by an ideal and apply `finitePresentation_ofLocalizationSpanTarget_aux`. -/ have hfintype : Algebra.FiniteType R S := by apply Algebra.FiniteType.of_span_eq_top_target s hs intro x hx have := h ⟨x, hx⟩ infer_instance obtain ⟨n, f, hf⟩ := Algebra.FiniteType.iff_quotient_mvPolynomial''.mp hfintype obtain ⟨l, hl⟩ := (Finsupp.mem_span_iff_linearCombination S (s : Set S) 1).mp (show (1 : S) ∈ Ideal.span (s : Set S) by rw [hs]; trivial) choose g' hg' using (fun g : s ↦ hf g) choose h' hh' using (fun g : s ↦ hf (l g)) let I : Ideal (MvPolynomial (Fin n) R) := Ideal.span { ∑ g : s, g' g * h' g - 1 } let A := MvPolynomial (Fin n) R ⧸ I have hfI : ∀ a ∈ I, f a = 0 := by intro p hp simp only [Finset.univ_eq_attach, I, Ideal.mem_span_singleton] at hp obtain ⟨q, rfl⟩ := hp simp only [map_mul, map_sub, map_sum, map_one, hg', hh'] rw [Finsupp.linearCombination_apply_of_mem_supported (α := (s : Set S)) S (s := s.attach)] at hl · rw [← hl] simp only [Finset.coe_sort_coe, smul_eq_mul, mul_comm, sub_self, zero_mul] · rintro a - simp let f' : A →ₐ[R] S := Ideal.Quotient.liftₐ I f hfI have hf' : Function.Surjective f' := Ideal.Quotient.lift_surjective_of_surjective I hfI hf let t : Finset A := Finset.image (fun g ↦ g' g) Finset.univ have ht : Ideal.span (t : Set A) = ⊤ := by rw [Ideal.eq_top_iff_one] have : ∑ g : { x // x ∈ s }, g' g * h' g = (1 : A) := by apply eq_of_sub_eq_zero rw [← map_one (Ideal.Quotient.mk I), ← map_sub, Ideal.Quotient.eq_zero_iff_mem] apply Ideal.subset_span simp simp_rw [← this, Finset.univ_eq_attach, map_sum, map_mul] refine Ideal.sum_mem _ (fun g _ ↦ Ideal.mul_mem_right _ _ <| Ideal.subset_span ?_) simp [t] have : Algebra.FinitePresentation R A := by apply Algebra.FinitePresentation.quotient simp only [Finset.univ_eq_attach, I] exact ⟨{∑ g ∈ s.attach, g' g * h' g - 1}, by simp⟩ have Ht (g : t) : Algebra.FinitePresentation R (Localization.Away (f' g)) := by have : ∃ (a : S) (hb : a ∈ s), (Ideal.Quotient.mk I) (g' ⟨a, hb⟩) = g.val := by obtain ⟨g, hg⟩ := g convert hg simp [A, t] obtain ⟨r, hr, hrr⟩ := this simp only [f'] rw [← hrr, Ideal.Quotient.liftₐ_apply, Ideal.Quotient.lift_mk] simp_rw [RingHom.coe_coe] rw [hg'] apply h exact of_span_eq_top_target_aux f' hf' t ht Ht end Algebra.FinitePresentation namespace RingHom /-- Being finitely-presented is stable under composition. -/ theorem finitePresentation_stableUnderComposition : StableUnderComposition @FinitePresentation := by introv R hf hg exact hg.comp hf /-- Being finitely-presented respects isomorphisms. -/ theorem finitePresentation_respectsIso : RingHom.RespectsIso @RingHom.FinitePresentation := finitePresentation_stableUnderComposition.respectsIso fun e ↦ .of_surjective _ e.surjective <| by simpa using Submodule.fg_bot /-- Being finitely-presented is stable under base change. -/ theorem finitePresentation_isStableUnderBaseChange : IsStableUnderBaseChange @FinitePresentation := by apply IsStableUnderBaseChange.mk · exact finitePresentation_respectsIso · introv h rw [finitePresentation_algebraMap] at h suffices Algebra.FinitePresentation S (S ⊗[R] T) by rw [RingHom.FinitePresentation]; convert this; ext; simp_rw [Algebra.smul_def]; rfl infer_instance /-- Being finitely-presented is preserved by localizations. -/ theorem finitePresentation_localizationPreserves : LocalizationPreserves @FinitePresentation := finitePresentation_isStableUnderBaseChange.localizationPreserves /-- If `R` is a ring, then `Rᵣ` is `R`-finitely-presented for any `r : R`. -/ theorem finitePresentation_holdsForLocalizationAway : HoldsForLocalizationAway @FinitePresentation := by introv R _ rw [finitePresentation_algebraMap] exact IsLocalization.Away.finitePresentation r /-- Finite-presentation can be checked on a standard covering of the target. -/ theorem finitePresentation_ofLocalizationSpanTarget : OfLocalizationSpanTarget @FinitePresentation := by introv R hs H algebraize [f] replace H : ∀ r ∈ s, Algebra.FinitePresentation R (Localization.Away (r : S)) := by intro r hr; simp_rw [RingHom.FinitePresentation] at H; convert H ⟨r, hr⟩; ext simp_rw [Algebra.smul_def]; rfl exact Algebra.FinitePresentation.of_span_eq_top_target s hs H /-- Being finitely-presented is a local property of rings. -/ theorem finitePresentation_isLocal : PropertyIsLocal @FinitePresentation := ⟨finitePresentation_localizationPreserves.away, finitePresentation_ofLocalizationSpanTarget, finitePresentation_ofLocalizationSpanTarget.ofLocalizationSpan (finitePresentation_stableUnderComposition.stableUnderCompositionWithLocalizationAway finitePresentation_holdsForLocalizationAway).left, (finitePresentation_stableUnderComposition.stableUnderCompositionWithLocalizationAway finitePresentation_holdsForLocalizationAway).right⟩ end RingHom
.lake/packages/mathlib/Mathlib/RingTheory/Spectrum/Prime/ChevalleyComplexity.lean
import Mathlib.Algebra.Order.SuccPred.WithBot import Mathlib.Algebra.Polynomial.CoeffMem import Mathlib.Data.DFinsupp.WellFounded import Mathlib.RingTheory.Spectrum.Prime.ConstructibleSet import Mathlib.RingTheory.Spectrum.Prime.Polynomial /-! # Chevalley's theorem with complexity bound ⚠ For general usage, see `Mathlib/RingTheory/Spectrum/Prime/Chevalley.lean`. Chevalley's theorem states that if `f : R → S` is a finitely presented ring hom between commutative rings, then the image of a constructible set in `Spec S` is a constructible set in `Spec R`. Constructible sets in the prime spectrum of `R[X]` are made of closed sets in the prime spectrum (using unions, intersections, and complements), which are themselves made from a family of polynomials. We say a closed set *has complexity at most `M`* if it can be written as the zero locus of a family of at most `M` polynomials each of degree at most `M`. We say a constructible set *has complexity at most `M`* if it can be written as `(C₁ ∪ ... ∪ Cₖ) \ D` where `k ≤ M`, `C₁, ..., Cₖ` are closed sets of complexity at most `M` and `D` is a closed set. This file proves a complexity-aware version of Chevalley's theorem, namely that a constructible set of complexity at most `M` in `Spec R[X₁, ..., Xₘ]` gets mapped under `f : R[Y₁, ..., Yₙ] → R[X₁, ..., Xₘ]` to a constructible set of complexity `O_{M, m, n}(1)` in `Spec R[Y₁, ..., Yₙ]`. The bound `O_{M, m, n}(1)` we find is of tower type. ## Sketch proof We first show the result in the case of `C : R → R[X]`. We prove this by induction on the number of components of the form `(C₁ ∪ ... ∪ Cₖ) \ D`, then by induction again on the number of polynomials used to describe `(C₁ ∪ ... ∪ Cₖ)`. See the (private) lemma `chevalley_polynomialC`. Secondly, we prove the result in the case of `C : R → R[X₁, ..., Xₘ]` by composing the first result with itself `m` times. See the (private) lemma `chevalley_mvPolynomialC`. Note that, if composing the first result for `C : R → R[X₁]` and `C : R[X₁] → R[X₁, X₂]` naïvely, the second map `C : R[X₁] → R[X₁, X₂]` won't *see* the `X₁`-degree of the polynomials used to describe the constructible set in `Spec R[X₁]`. One therefore needs to track a subgroup of the ring which all coefficients of all used polynomials lie in. Finally, we deduce the result for any `f : R[Y₁, ..., Yₙ] → R[X₁, ..., Xₘ]` by decomposing it into two maps `C : R[Y₁, ..., Yₙ] → R[X₁, ..., Xₘ, Y₁, ..., Yₙ]` and `σ : R[X₁, ..., Xₘ, Y₁, ..., Yₙ] → R[X₁, ..., Xₘ]`. See `chevalley_mvPolynomial_mvPolynomial`. ## Main reference The structure of the proof follows https://stacks.math.columbia.edu/tag/00FE, although they do not give an explicit bound on the complexity. -/ variable {R₀ R S M A : Type*} [CommRing R₀] [CommRing R] [Algebra R₀ R] [CommRing S] [Algebra R₀ S] variable [AddCommGroup M] [Module R M] [CommRing A] [Algebra R A] {n : ℕ} open Function Localization MvPolynomial Polynomial TensorProduct PrimeSpectrum open scoped Pointwise namespace ChevalleyThm /-! ### The `C : R → R[X]` case -/ namespace PolynomialC local notation3 "coeff("p")" => Set.range (Polynomial.coeff p) variable (n) in /-- The codomain of the measure that will decrease during the induction in the `C : R → R[X]` case of Chevalley's theorem with complexity bound. -/ private abbrev DegreeType := (Fin n → WithBot ℕ) ×ₗ Prop variable (R n) in /-- A type synonym for families of polynomials. This is used in the induction for the case of `C : R → R[X]` of Chevalley's theorem with complexity bound. -/ @[ext] private structure InductionObj where /-- The underlying family of polynomials of an induction object. -/ val : Fin n → R[X] namespace InductionObj private instance : CoeFun (InductionObj R n) (fun _ ↦ Fin n → R[X]) := ⟨InductionObj.val⟩ variable (R₀) in /-- A subgroup containing all coefficients of all polynomials of a given induction object for Chevalley's theorem with complexity. Note that we force `1` to lie in that subgroup so that `fun n ↦ e.coeffSubmodule ^ n` is increasing. -/ private def coeffSubmodule (e : InductionObj R n) : Submodule R₀ R := .span R₀ ({1} ∪ ⋃ i, coeff(e i)) private lemma coeffSubmodule_mapRingHom_comp (e : InductionObj R n) (f : R →ₐ[R₀] S) : ({ val := mapRingHom f ∘ e } : InductionObj S n).coeffSubmodule R₀ = (e.coeffSubmodule R₀).map f.toLinearMap := by simp [coeffSubmodule, Submodule.map_span, Set.image_insert_eq, Set.image_iUnion, ← Set.range_comp, coeff_map_eq_comp] variable {e T : InductionObj R n} private lemma coeff_mem_coeffSubmodule {i : Fin n} {d : ℕ} : (e i).coeff d ∈ e.coeffSubmodule R₀ := Submodule.subset_span <| .inr <| Set.mem_iUnion.2 ⟨i, Set.mem_range_self _⟩ private lemma one_mem_coeffSubmodule : 1 ∈ e.coeffSubmodule R₀ := Submodule.subset_span (.inl rfl) private lemma one_le_coeffSubmodule : 1 ≤ e.coeffSubmodule R₀ := by rw [Submodule.one_eq_span, Submodule.span_le, Set.singleton_subset_iff] exact one_mem_coeffSubmodule variable (e) in /-- The measure that will decrease during the induction in the `C : R → R[X]` case of Chevalley's theorem with complexity bound. -/ private def degree : DegreeType n := toLex (Polynomial.degree ∘ e, ¬ ∃ i, (e i).Monic ∧ ∀ j, e j ≠ 0 → (e i).degree ≤ (e j).degree) @[simp] private lemma ofLex_degree_fst (i) : (ofLex e.degree).fst i = (e i).degree := rfl private lemma ofLex_degree_snd : (ofLex e.degree).snd ↔ ¬ ∃ i, (e i).Monic ∧ ∀ j, e j ≠ 0 → (e i).degree ≤ (e j).degree := .rfl variable (e) in /-- The bound on the degree of the polynomials used to describe the constructible set appearing in the case of `C : R → R[X]` of Chevalley's theorem with complexity bound. -/ private def degBound : ℕ := ∑ i, (e i).degree.succ variable (e) in /-- The bound on the power of the subgroup generated by the coefficients of the polynomials used to describe the constructible set appearing in the case of `C : R → R[X]` of Chevalley's theorem with complexity bound. -/ private def powBound : ℕ := e.degBound ^ e.degBound private lemma powBound_ne_zero : e.powBound ≠ 0 := Nat.pow_self_pos.ne' variable (R₀ R n e) in /-- The statement we induct on in the `C : R → R[X]` case of Chevalley's theorem with complexity bound. -/ private def Statement [Algebra ℤ R] : Prop := ∀ f : R[X], ∃ T : ConstructibleSetData R, comap Polynomial.C '' (zeroLocus (Set.range e) \ zeroLocus {f}) = T.toSet ∧ ∀ C ∈ T, C.n ≤ e.degBound ∧ ∀ i, C.g i ∈ e.coeffSubmodule R₀ ^ e.powBound end InductionObj open InductionObj universe u /-- The structure of the induction in the proof of Chevalley's theorem: Consider a property on a vector `e` of polynomials. Suppose that it holds for the following cases: 1. The vector contains zeroes only. 2. The vector contains a single monic polynomial (and zero otherwise). 3. Suppose `eᵢ` has the lowest degree among all monic polynomials and `eⱼ` is some other polynomial. If the property holds when `eⱼ` is replaced by `eⱼ % eᵢ`, then it holds for `e`. 4. Suppose the property holds for both the localization at some leading coefficient of `eᵢ` and the localization at the leading coefficient of `eᵢ`, then the property holds for `e`. Then it holds for all vectors `e` over all rings. -/ private lemma induction_structure (n : ℕ) (P : ∀ (R : Type u) [CommRing R], (InductionObj R n) → Prop) (hP₁ : ∀ (R) [CommRing R], P R ⟨0⟩) (hP₂ : ∀ (R) [CommRing R] (e : InductionObj R n) (i : Fin n), (e.1 i).Monic → (∀ j ≠ i, e.1 j = 0) → P R e) (hP₃ : ∀ (R) [CommRing R] (e : InductionObj R n) (i j : Fin n), (e.1 i).Monic → (e.1 i).degree ≤ (e.1 j).degree → i ≠ j → P R ⟨update e.1 j (e.1 j %ₘ e.1 i)⟩ → P R e) (hP₄ : ∀ (R) [CommRing R] (c : R) (i : Fin n) (e : InductionObj R n), c = (e.1 i).leadingCoeff → c ≠ 0 → P (Away c) ⟨Polynomial.C (IsLocalization.Away.invSelf (S := Away c) c) • mapRingHom (algebraMap _ _) ∘ e⟩ → P (R ⧸ Ideal.span {c}) ⟨mapRingHom (algebraMap _ _) ∘ e⟩ → P R e) {R} [CommRing R] (e : InductionObj R n) : P R e := by classical set v := e.degree with hv clear_value v induction v using WellFoundedLT.induction generalizing R with | ind v H_IH => by_cases he0 : e = ⟨0⟩ · exact he0 ▸ hP₁ R cases subsingleton_or_nontrivial R · convert hP₁ R; ext; exact Subsingleton.elim _ _ simp only [InductionObj.ext_iff, funext_iff, Pi.zero_apply, not_forall] at he0 -- Case I : The `e i ≠ 0` with minimal degree has invertible leading coefficient by_cases H : (∃ i, (e.1 i).Monic ∧ ∀ j, e.1 j ≠ 0 → (e.1 i).degree ≤ (e.1 j).degree) · obtain ⟨i, hi, i_min⟩ := H -- Case I.ii : `e j = 0` for all `j ≠ i`. by_cases! H' : ∀ j ≠ i, e.1 j = 0 -- then `I = Ideal.span {e i}` · exact hP₂ R e i hi H' -- Case I.i : There is another `e j ≠ 0` · obtain ⟨j, hj, hj'⟩ := H' replace i_min := i_min j hj' -- then we can replace `e j` with `e j %ₘ (C h.unit⁻¹ * e i) ` -- with `h : IsUnit (e i).leadingCoeff`. apply hP₃ R e i j hi i_min (hj.symm) (H_IH _ ?_ _ rfl) refine .left _ _ (lt_of_le_of_ne (b := (ofLex v).1) ?_ ?_) · intro k simp only [comp_apply, update_apply, hv] split_ifs with hjk · rw [hjk] exact (degree_modByMonic_le _ hi).trans i_min · exact le_rfl · simp only [hv, ne_eq, not_forall, funext_iff, comp_apply] use j simp only [update_self] refine ((degree_modByMonic_lt _ hi).trans_le i_min).ne -- Case II : The `e i ≠ 0` with minimal degree has non-invertible leading coefficient obtain ⟨i, hi, i_min⟩ : ∃ i, e.1 i ≠ 0 ∧ ∀ j, e.1 j ≠ 0 → (e.1 i).degree ≤ (e.1 j).degree := by have : ∃ n : ℕ, ∃ i, (e.1 i).degree = n ∧ (e.1 i) ≠ 0 := by obtain ⟨i, hi⟩ := he0; exact ⟨(e.1 i).natDegree, i, degree_eq_natDegree hi, hi⟩ let m := Nat.find this obtain ⟨i, hi, hi'⟩ : ∃ i, (e.1 i).degree = m ∧ (e.1 i) ≠ 0 := Nat.find_spec this refine ⟨i, hi', fun j hj ↦ ?_⟩ refine hi.le.trans ?_ rw [degree_eq_natDegree hj, Nat.cast_le] exact Nat.find_min' _ ⟨j, degree_eq_natDegree hj, hj⟩ -- We replace `R` by `R ⧸ Ideal.span {(e i).leadingCoeff}` where `(e i).degree` is lowered -- and `Away (e i).leadingCoeff` where `(e i).leadingCoeff` becomes invertible. apply hP₄ _ _ i e rfl (by simpa using hi) (H_IH _ ?_ _ rfl) (H_IH _ ?_ _ rfl) · rw [hv, Prod.Lex.lt_iff'] constructor · intro j simp only [coe_mapRingHom, InductionObj.ofLex_degree_fst, Pi.smul_apply, comp_apply, smul_eq_mul] refine ((degree_mul_le _ _).trans (add_le_add degree_C_le degree_map_le)).trans ?_ simp rw [lt_iff_le_not_ge] simp only [coe_mapRingHom, funext_iff, InductionObj.ofLex_degree_fst, Pi.smul_apply, comp_apply, smul_eq_mul, show (ofLex e.degree).2 from H, le_Prop_eq, implies_true, true_implies, true_and] simp only [InductionObj.ofLex_degree_snd, Pi.smul_apply, comp_apply, smul_eq_mul, ne_eq, not_exists, not_and, not_forall, not_le, not_lt] intro h_eq refine ⟨i, ?_, ?_⟩ · rw [Monic.def, ← coeff_natDegree (p := _ * _), natDegree_eq_of_degree_eq (h_eq i), Polynomial.coeff_C_mul, Polynomial.coeff_map, coeff_natDegree, mul_comm, IsLocalization.Away.mul_invSelf] · intro j hj; rw [h_eq, h_eq]; exact i_min j fun H ↦ (by simp [H] at hj) · rw [hv] refine .left _ _ (lt_of_le_of_ne ?_ ?_) · intro j; simpa using degree_map_le simp only [coe_mapRingHom, ne_eq] intro h_eq replace h_eq := congr_fun h_eq i simp only [Ideal.Quotient.algebraMap_eq, comp_apply, degree_map_eq_iff, Ideal.Quotient.mk_singleton_self, ne_eq, not_true_eq_false, false_or] at h_eq exact hi h_eq open IsLocalization in open Submodule hiding comap in /-- Part 4 of the induction structure applied to `Statement R₀ R n`. See the docstring of `induction_structure`. -/ private lemma induction_aux (R : Type*) [CommRing R] [Algebra R₀ R] (c : R) (i : Fin n) (e : InductionObj R n) (hi : c = (e.1 i).leadingCoeff) (hc : c ≠ 0) : Statement R₀ (Away c) n ⟨Polynomial.C (IsLocalization.Away.invSelf (S := Away c) c) • mapRingHom (algebraMap _ _) ∘ e⟩ → Statement R₀ (R ⧸ Ideal.span {c}) n ⟨mapRingHom (algebraMap _ _) ∘ e⟩ → Statement R₀ R n e := by set q₁ := IsScalarTower.toAlgHom R₀ R (Away c) set q₂ := Ideal.Quotient.mkₐ R₀ (.span {c}) have q₂_surjective : Surjective q₂ := Ideal.Quotient.mk_surjective set e₁ : InductionObj (Away c) n := ⟨Polynomial.C (IsLocalization.Away.invSelf (S := Away c) c) • mapRingHom q₁ ∘ e⟩ set e₂ : InductionObj (R ⧸ Ideal.span {c}) n := ⟨mapRingHom q₂ ∘ e⟩ have degBound_e₁_le : e₁.degBound ≤ e.degBound := by unfold degBound gcongr with j exact (degree_mul_le _ _).trans <| (add_le_of_nonpos_left degree_C_le).trans degree_map_le have degBound_e₂_lt : e₂.degBound < e.degBound := by unfold degBound refine Fintype.sum_strictMono <| Pi.lt_def.2 ⟨fun j ↦ ?_, i, ?_⟩ · dsimp gcongr exact degree_map_le · gcongr exact degree_map_lt (by simp [q₂, ← hi]) (by simpa [hi] using hc) intro (H₁ : Statement R₀ _ _ e₁) (H₂ : Statement R₀ _ _ e₂) f obtain ⟨T₁, hT₁⟩ := H₁ (mapRingHom q₁ f) obtain ⟨T₂, hT₂⟩ := H₂ (mapRingHom q₂ f) simp only [forall_and] at hT₁ hT₂ obtain ⟨hT₁, hT₁deg, hT₁span⟩ := hT₁ obtain ⟨hT₂, hT₂deg, hT₂span⟩ := hT₂ -- Lift the tuples of `T₁` from `Away c` to `R` let _ : Invertible (q₁ c) := -- TODO(Andrew): add API for `IsLocalization.Away.invSelf` ⟨IsLocalization.Away.invSelf c, by simp [q₁, IsLocalization.Away.invSelf], by simp [q₁, IsLocalization.Away.invSelf]⟩ have he₁span : e₁.coeffSubmodule R₀ ^ e₁.powBound = ⅟(q₁ c ^ e₁.powBound) • (span R₀ ({c} ∪ ⋃ i, coeff(e i)) ^ e₁.powBound).map q₁.toLinearMap := by unfold coeffSubmodule rw [Submodule.map_pow, map_span, invOf_pow, ← smul_pow, ← span_smul] simp [Set.image_insert_eq, Set.smul_set_insert, Set.image_iUnion, Set.smul_set_iUnion, q₁, e₁] congr! with i change _ = IsLocalization.Away.invSelf c • _ simp [← Set.range_comp, Set.smul_set_range] ext simp replace hT₁span x hx i := smul_mem_pointwise_smul _ (q₁ c ^ e₁.powBound) _ (hT₁span x hx i) simp only [he₁span, smul_invOf_smul, smul_eq_mul] at hT₁span choose! g₁ hg₁ hq₁g₁ using hT₁span -- Lift the constants of `T₁` from `Away c` to `R` choose! n₁ f₁ hf₁ using Away.surj (S := Away c) c change (∀ _, _ * q₁ _ ^ _ = q₁ _) at hf₁ -- Lift the tuples of `T₂` from `R ⧸ Ideal.span {c}` to `R` rw [coeffSubmodule_mapRingHom_comp, ← Submodule.map_pow] at hT₂span choose! g₂ hg₂ hq₂g₂ using hT₂span -- Lift the constants of `T₂` from `R ⧸ Ideal.span {c}` to `R` choose! f₂ hf₂ using Ideal.Quotient.mkₐ_surjective R₀ (I := .span {c}) change (∀ _, q₂ _ = _) at hf₂ -- Lift everything together classical let S₁ : Finset (BasicConstructibleSetData R) := T₁.image fun x ↦ ⟨c * f₁ x.f, _, g₁ x⟩ let S₂ : Finset (BasicConstructibleSetData R) := T₂.image fun x ↦ ⟨f₂ x.f, _, Fin.cons c (g₂ x)⟩ refine ⟨S₁ ∪ S₂, ?_, ?_⟩ · calc comap Polynomial.C '' (zeroLocus (.range e) \ zeroLocus {f}) = comap q₁ '' (comap Polynomial.C '' (comap (mapRingHom q₁.toRingHom) ⁻¹' (zeroLocus (.range e) \ zeroLocus {f}))) ∪ comap q₂ '' (comap Polynomial.C '' (comap (mapRingHom q₂.toRingHom) ⁻¹' (zeroLocus (.range e) \ zeroLocus {f}))) := Set.image_of_range_union_range_eq_univ (by ext; simp) (by ext; simp) (by rw [Ideal.Quotient.mkₐ_toRingHom, ← range_comap_algebraMap_localization_compl_eq_range_comap_quotientMk, RingHom.algebraMap_toAlgebra]; exact Set.union_compl_self _) _ _ = (⋃ C ∈ S₁, C.toSet) ∪ ⋃ C ∈ S₂, C.toSet := ?_ _ = ⋃ C ∈ S₁ ∪ S₂, C.toSet := by simpa using (Set.biUnion_union (SetLike.coe S₁) S₂ _).symm congr 1 · convert congr(comap q₁.toRingHom '' $hT₁) · dsimp only [e₁] rw [Set.preimage_diff, preimage_comap_zeroLocus, preimage_comap_zeroLocus, Set.image_singleton, Pi.smul_def, ← Set.smul_set_range, Set.range_comp] congr 1 refine (PrimeSpectrum.zeroLocus_smul_of_isUnit (.map _ ?_) _).symm exact isUnit_iff_exists_inv'.mpr ⟨_, IsLocalization.Away.mul_invSelf c⟩ · rw [ConstructibleSetData.toSet, Set.image_iUnion₂] simp_rw [← Finset.mem_coe, S₁, Finset.coe_image, Set.biUnion_image] congr! with x hxT₁ apply Set.injOn_preimage subset_rfl (f := comap q₁.toRingHom) · dsimp only [q₁, AlgHom.toRingHom_eq_coe] rw [IsScalarTower.coe_toAlgHom, localization_away_comap_range (S := Localization.Away c) (r := c), BasicConstructibleSetData.toSet, sdiff_eq, ← basicOpen_eq_zeroLocus_compl, basicOpen_mul] exact Set.inter_subset_right.trans Set.inter_subset_left · exact Set.image_subset_range .. · rw [BasicConstructibleSetData.toSet, BasicConstructibleSetData.toSet, Set.preimage_diff, preimage_comap_zeroLocus, preimage_comap_zeroLocus, Set.preimage_image_eq] swap; · exact localization_specComap_injective _ (.powers c) simp only [AlgHom.toLinearMap_apply] at hq₁g₁ simp only [← Set.range_comp, comp_def, AlgHom.toRingHom_eq_coe, RingHom.coe_coe, hq₁g₁ _ hxT₁, Set.image_singleton, map_mul, ← hf₁, mul_comm x.1, ← mul_assoc, ← pow_succ'] simp only [← smul_eq_mul, ← Set.smul_set_range, ← Set.smul_set_singleton, zeroLocus_smul_of_isUnit ((isUnit_of_invertible (q₁ c)).pow _)] · convert congr(comap q₂.toRingHom '' $hT₂) · rw [Set.preimage_diff, preimage_comap_zeroLocus, preimage_comap_zeroLocus, Set.image_singleton, Set.range_comp, AlgHom.toRingHom_eq_coe] · rw [ConstructibleSetData.toSet, Set.image_iUnion₂] simp_rw [← Finset.mem_coe, S₂, Finset.coe_image, Set.biUnion_image] congr! 3 with x hxT₂ apply Set.injOn_preimage subset_rfl (f := comap q₂.toRingHom) · rw [range_comap_of_surjective _ _ q₂_surjective] simp only [AlgHom.toRingHom_eq_coe, Ideal.Quotient.mkₐ_ker, zeroLocus_span, q₂] exact Set.diff_subset.trans (zeroLocus_anti_mono (by simp)) · exact Set.image_subset_range _ _ · simp only [AlgHom.toLinearMap_apply] at hq₂g₂ have : q₂ c = 0 := by simp [q₂] simp only [BasicConstructibleSetData.toSet, Set.preimage_diff, preimage_comap_zeroLocus, preimage_comap_zeroLocus, Set.preimage_image_eq _ (comap_injective_of_surjective _ q₂_surjective)] simp only [Fin.range_cons, Set.image_singleton, Set.image_insert_eq, ← Set.range_comp, comp_def] simp only [AlgHom.toRingHom_eq_coe, AlgHom.coe_toRingHom, hq₂g₂ _ hxT₂, hf₂] rw [← Set.union_singleton, zeroLocus_union, this, zeroLocus_singleton_zero, Set.inter_univ] · simp only [Finset.mem_union, forall_and, or_imp, Finset.forall_mem_image, S₁, S₂] refine ⟨⟨fun x hx ↦ (hT₁deg _ hx).trans degBound_e₁_le, fun x hx ↦ (hT₂deg _ hx).trans_lt degBound_e₂_lt⟩, fun x hx k ↦ SetLike.mem_of_subset ?_ (hg₁ _ hx _), fun x hx ↦ Fin.cons ?_ fun k ↦ SetLike.mem_of_subset ?_ (hg₂ _ hx _)⟩ · norm_cast calc span R₀ ({c} ∪ ⋃ i, coeff(e i)) ^ e₁.powBound _ ≤ span R₀ (⋃ i, coeff(e i)) ^ e₁.powBound := by gcongr; simpa [Set.insert_subset_iff] using ⟨_, _, hi.symm⟩ _ ≤ e.coeffSubmodule R₀ ^ e.powBound := by unfold coeffSubmodule powBound gcongr · exact one_le_coeffSubmodule · exact Set.subset_union_right · cutsat · exact le_self_pow one_le_coeffSubmodule powBound_ne_zero <| subset_span <| .inr <| by simpa using ⟨_, _, hi.symm⟩ · unfold powBound gcongr · exact one_le_coeffSubmodule · cutsat /-- The main induction in the proof of Chevalley's theorem for `R →+* R[X]`. See the docstring of `induction_structure` for the overview. -/ private lemma statement : ∀ S : InductionObj R n, Statement R₀ R n S := by intro S; revert R₀; revert S classical apply induction_structure · intro R _ R₀ _ _ f refine ⟨(Finset.range (f.natDegree + 2)).image fun j ↦ ⟨f.coeff j, 0, 0⟩, ?_, ?_⟩ · convert image_comap_C_basicOpen f · simp only [basicOpen_eq_zeroLocus_compl, Set.compl_eq_univ_diff] congr 1 rw [← Set.univ_subset_iff] rintro x _ _ ⟨_, rfl⟩ exact zero_mem x.asIdeal · suffices Set.range f.coeff = ⋃ i < f.natDegree + 2, {f.coeff i} by simp [BasicConstructibleSetData.toSet, ConstructibleSetData.toSet, ← Set.compl_eq_univ_diff, eq_compl_comm (y := zeroLocus _), ← zeroLocus_iUnion₂, this] trans f.coeff '' (Set.Iio (f.natDegree + 2)) · refine ((Set.image_subset_range _ _).antisymm ?_).symm rintro _ ⟨i, rfl⟩ by_cases! hi : i ≤ f.natDegree · exact ⟨i, hi.trans_lt (by simp), rfl⟩ · exact ⟨f.natDegree + 1, by simp, by simp [f.coeff_eq_zero_of_natDegree_lt hi]⟩ · ext; simp [eq_comm] · simp · intro R _ g i hi hi_min _ R₀ _ f let M := R[X] ⧸ Ideal.span {g.1 i} have : Module.Free R M := .of_basis (AdjoinRoot.powerBasis' hi).basis have : Module.Finite R M := .of_basis (AdjoinRoot.powerBasis' hi).basis refine ⟨(Finset.range (Module.finrank R M)).image fun j ↦ ⟨(Algebra.lmul R M (Ideal.Quotient.mk _ f)).charpoly.coeff j, 0, 0⟩, ?_, ?_⟩ · ext x have : zeroLocus (Set.range g.val) = zeroLocus {g.1 i} := by rw [Set.range_eq_iUnion, zeroLocus_iUnion] refine (Set.iInter_subset _ _).antisymm (Set.subset_iInter fun j ↦ ?_) by_cases hij : i = j · subst hij; rfl · rw [hi_min j (.symm hij), zeroLocus_singleton_zero]; exact Set.subset_univ _ rw [this, ← Polynomial.algebraMap_eq, mem_image_comap_zeroLocus_sdiff, IsScalarTower.algebraMap_apply R[X] M, isNilpotent_tensor_residueField_iff] simp [BasicConstructibleSetData.toSet, ConstructibleSetData.toSet, Set.subset_def, M] · simp · intro R _ c i j hi hle hne H R₀ _ _ f cases subsingleton_or_nontrivial R · use ∅ simp [ConstructibleSetData.toSet, Subsingleton.elim f 0] obtain ⟨S, hS, hS'⟩ := H (R₀ := R₀) f refine ⟨S, Eq.trans ?_ hS, ?_⟩ · rw [← zeroLocus_span (Set.range _), ← zeroLocus_span (Set.range _), idealSpan_range_update_divByMonic hne _ hi] · intro C hC let c' : InductionObj _ _ := ⟨update c.val j (c.val j %ₘ c.val i)⟩ have deg_bound₁ : c'.degBound ≤ c.degBound := by dsimp [InductionObj.degBound, c'] gcongr with k · rw [update_apply] split_ifs with hkj · subst hkj; exact (degree_modByMonic_le _ hi).trans hle · rfl refine ⟨(hS' C hC).1.trans deg_bound₁, fun k ↦ SetLike.le_def.mp ?_ ((hS' C hC).2 k)⟩ change c'.coeffSubmodule R₀ ^ c'.powBound ≤ _ delta powBound suffices hij : c'.coeffSubmodule R₀ ≤ c.coeffSubmodule R₀ ^ (c.val j).degree.succ by by_cases hi' : c.val i = 1 · gcongr · exact c.one_le_coeffSubmodule · refine Submodule.span_le.mpr (Set.union_subset ?_ ?_) · exact Set.subset_union_left.trans Submodule.subset_span · refine Set.iUnion_subset fun k ↦ ?_ simp only [update_apply, hi', modByMonic_one, c'] split_ifs · rintro _ ⟨_, rfl⟩ exact zero_mem _ · exact (Set.subset_iUnion (fun i ↦ coeff(c.val i)) k).trans (Set.subset_union_right.trans Submodule.subset_span) rw [Nat.one_le_iff_ne_zero, ← Nat.pos_iff_ne_zero, InductionObj.degBound] refine Fintype.sum_pos (Pi.lt_def.mpr ⟨by positivity, i, by simp [hi']⟩) refine (pow_le_pow_left' hij _).trans ?_ rw [← pow_mul] apply pow_le_pow_right' c.one_le_coeffSubmodule have deg_bound₂ : c'.degBound < c.degBound := by dsimp [InductionObj.degBound, c'] apply Finset.sum_lt_sum ?_ ⟨j, Finset.mem_univ _, ?_⟩ · intro k _ rw [update_apply] split_ifs with hkj · subst hkj; gcongr; exact (degree_modByMonic_le _ hi).trans hle · rfl · gcongr; simpa using (degree_modByMonic_lt _ hi).trans_le hle calc (c.val j).degree.succ * c'.degBound ^ c'.degBound _ ≤ c.degBound * c.degBound ^ c'.degBound := by gcongr delta InductionObj.degBound exact Finset.single_le_sum (f := fun i ↦ (c.val i).degree.succ) (by intros; positivity) (Finset.mem_univ _) _ = c.degBound ^ (c'.degBound + 1) := by rw [pow_succ'] _ ≤ c.degBound ^ c.degBound := by gcongr <;> omega rw [coeffSubmodule] simp only [Submodule.span_le, Set.union_subset_iff, Set.singleton_subset_iff, SetLike.mem_coe, Set.iUnion_subset_iff, Set.range_subset_iff, c'] constructor · apply one_le_pow_of_one_le' c.one_le_coeffSubmodule rw [Submodule.one_eq_span] exact Submodule.subset_span rfl · intro l m rw [update_apply] split_ifs with hlj · convert coeff_modByMonic_mem_pow_natDegree_mul _ _ _ (fun _ ↦ coeff_mem_coeffSubmodule) one_mem_coeffSubmodule _ (fun _ ↦ coeff_mem_coeffSubmodule) one_mem_coeffSubmodule _ rw [← pow_succ, Polynomial.degree_eq_natDegree, WithBot.succ_natCast, Nat.cast_id] intro e simp [show c.val i = 0 by simpa [e] using hle] at hi · have : (c.val j).degree.succ ≠ 0 := by rw [← Nat.pos_iff_ne_zero] apply WithBot.succ_lt_succ (x := ⊥) refine lt_of_lt_of_le ?_ hle rw [bot_lt_iff_ne_bot, ne_eq, degree_eq_bot] intro e simp [e] at hi refine le_self_pow c.one_le_coeffSubmodule this ?_ exact Submodule.subset_span (.inr (Set.mem_iUnion_of_mem l ⟨m, rfl⟩)) · intro R _ c i e he hc H₁ H₂ R₀ _ _ exact induction_aux (R₀ := R₀) R c i e he hc H₁ H₂ end PolynomialC open PolynomialC InductionObj in /-- The `C : R → R[X]` case of **Chevalley's theorem** with complexity bound. -/ lemma chevalley_polynomialC {R : Type*} [CommRing R] (M : Submodule ℤ R) (hM : 1 ∈ M) (S : ConstructibleSetData R[X]) (hS : ∀ C ∈ S, ∀ j k, (C.g j).coeff k ∈ M) : ∃ T : ConstructibleSetData R, comap Polynomial.C '' S.toSet = T.toSet ∧ ∀ C ∈ T, C.n ≤ S.degBound ∧ ∀ i, C.g i ∈ M ^ S.degBound ^ S.degBound := by classical choose f hf₁ hf₂ hf₃ using fun C : BasicConstructibleSetData R[X] ↦ statement (R₀ := ℤ) ⟨C.g⟩ C.f refine ⟨S.biUnion f, ?_, ?_⟩ · simp only [BasicConstructibleSetData.toSet, ConstructibleSetData.toSet, Set.image_iUnion, Finset.set_biUnion_biUnion, hf₁] · simp only [Finset.mem_biUnion, forall_exists_index, and_imp] intro x y hy hx have H : degBound ⟨y.g⟩ ≤ S.degBound := Finset.le_sup (f := fun e ↦ ∑ i, (e.g i).degree.succ) hy refine ⟨(hf₂ y x hx).trans H, fun i ↦ SetLike.le_def.mp ?_ (hf₃ y x hx i)⟩ gcongr · simpa [Submodule.one_eq_span] · refine Submodule.span_le.mpr ?_ simp [Set.subset_def, hM, forall_comm (α := R), hS y hy] · delta powBound by_cases h : S.degBound = 0 · have : degBound ⟨y.g⟩ = 0 := by nlinarith rw [h, this] gcongr rwa [Nat.one_le_iff_ne_zero] /-! ### The `C : R → R[X₁, ..., Xₘ]` case -/ namespace MvPolynomialC mutual /-- The bound on the number of polynomials used to describe the constructible set appearing in the case of `C : R → R[X₁, ..., Xₘ]` of Chevalley's theorem with complexity bound. -/ def numBound (k : ℕ) (D : ℕ → ℕ) : ℕ → ℕ | 0 => k | n + 1 => numBound k D n * degBound k D n * D n /-- The bound on the degree of the polynomials used to describe the constructible set appearing in the case of `C : R → R[X₁, ..., Xₘ]` of Chevalley's theorem with complexity bound. -/ def degBound (k : ℕ) (D : ℕ → ℕ) : ℕ → ℕ | 0 => 1 | n + 1 => numBound k D (n + 1) ^ numBound k D (n + 1) * degBound k D n end @[simp] lemma degBound_zero (k : ℕ) (D : ℕ → ℕ) : degBound k D 0 = 1 := by rw [degBound] @[simp] lemma numBound_zero (k : ℕ) (D : ℕ → ℕ) : numBound k D 0 = k := by rw [numBound] @[simp] lemma degBound_succ (k : ℕ) (D : ℕ → ℕ) (n) : degBound k D (n + 1) = numBound k D (n + 1) ^ numBound k D (n + 1) * degBound k D n := by rw [degBound] @[simp] lemma numBound_succ (k : ℕ) (D : ℕ → ℕ) (n) : numBound k D (n + 1) = numBound k D n * degBound k D n * D n := by rw [numBound] mutual lemma degBound_casesOn_succ (k₀ k : ℕ) (D : ℕ → ℕ) : ∀ n, degBound k₀ (fun t ↦ Nat.casesOn t k D) (n + 1) = (k₀ * k) ^ (k₀ * k) * degBound (k₀ * k) ((k₀ * k) ^ (k₀ * k) • D) n | 0 => by simp | n + 1 => by rw [degBound_succ, numBound_casesOn_succ, degBound_casesOn_succ, numBound_succ, degBound_succ, numBound_succ] ring lemma numBound_casesOn_succ (k₀ k : ℕ) (D : ℕ → ℕ) : ∀ n, numBound k₀ (Nat.casesOn · k D) (n + 1) = numBound (k₀ * k) ((k₀ * k) ^ (k₀ * k) • D) n | 0 => by simp | n + 1 => by rw [numBound_succ (n := n + 1), numBound_casesOn_succ k₀ k D n, numBound_succ, degBound_casesOn_succ] dsimp ring end variable {k₁ k₂ : ℕ} (hk : k₁ ≤ k₂) {D₁ D₂ : ℕ → ℕ} mutual lemma degBound_le_degBound (hk : k₁ ≤ k₂) : ∀ (n) (_ : ∀ i < n, D₁ i ≤ D₂ i), degBound k₁ D₁ n ≤ degBound k₂ D₂ n | 0, hD => by simp | n + 1, hD => by rw [degBound_succ, degBound_succ] refine Nat.mul_le_mul (Nat.pow_self_mono (numBound_mono hk _ hD)) (degBound_le_degBound hk _ fun i hi ↦ hD _ (hi.trans n.lt_succ_self)) lemma numBound_mono (hk : k₁ ≤ k₂) : ∀ n, (∀ i < n, D₁ i ≤ D₂ i) → numBound k₁ D₁ n ≤ numBound k₂ D₂ n | 0, hD => by simpa using hk | n + 1, hD => by rw [numBound_succ, numBound_succ] gcongr · exact numBound_mono hk _ fun i hi ↦ hD _ (hi.trans n.lt_succ_self) · exact degBound_le_degBound hk _ fun i hi ↦ hD _ (hi.trans n.lt_succ_self) · exact hD _ n.lt_succ_self end lemma degBound_pos (k : ℕ) (D : ℕ → ℕ) : ∀ n, 0 < degBound k D n | 0 => by simp | n + 1 => by simp [degBound_succ, Nat.pow_self_pos, degBound_pos] end MvPolynomialC open MvPolynomialC in /-- The `C : R → R[X₁, ..., Xₘ]` case of **Chevalley's theorem** with complexity bound. -/ lemma chevalley_mvPolynomialC {M : Submodule ℤ R} (hM : 1 ∈ M) (k : ℕ) (d : Multiset (Fin n)) (S : ConstructibleSetData (MvPolynomial (Fin n) R)) (hSn : ∀ C ∈ S, C.n ≤ k) (hS : ∀ C ∈ S, ∀ j, C.g j ∈ coeffsIn _ M ⊓ (degreesLE _ _ d).restrictScalars _) : ∃ T : ConstructibleSetData R, comap MvPolynomial.C '' S.toSet = T.toSet ∧ ∀ C ∈ T, C.n ≤ numBound k (fun i ↦ 1 + (d.map Fin.val).count i) n ∧ ∀ i, C.g i ∈ M ^ (degBound k (fun i ↦ 1 + (d.map Fin.val).count i) n) := by classical induction n generalizing k M with | zero => refine ⟨(S.map (isEmptyRingEquiv _ _).toRingHom), ?_, ?_⟩ · rw [ConstructibleSetData.toSet_map] change _ = (comapEquiv (isEmptyRingEquiv _ _)).symm ⁻¹' _ rw [← OrderIso.image_eq_preimage_symm] rfl · simp only [ConstructibleSetData.map, RingEquiv.toRingHom_eq_coe, Finset.mem_image, comp_apply, BasicConstructibleSetData.map, RingHom.coe_coe, isEmptyRingEquiv_eq_coeff_zero, pow_one, numBound_zero, degBound_zero, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂] exact fun a haS ↦ ⟨hSn a haS, fun i ↦ (hS a haS i).1 0⟩ | succ n IH => ?_ let e : MvPolynomial (Fin (n + 1)) R ≃ₐ[R] (MvPolynomial (Fin n) R)[X] := finSuccEquiv R n let S' := S.map e.toRingHom have hS' : S'.degBound ≤ k * (1 + d.count 0) := by apply Finset.sup_le fun x hxS ↦ ?_ simp only [ConstructibleSetData.map, AlgEquiv.toRingEquiv_eq_coe, RingEquiv.toRingHom_eq_coe, AlgEquiv.toRingEquiv_toRingHom, Finset.mem_image, BasicConstructibleSetData.map, RingHom.coe_coe, S'] at hxS obtain ⟨C, hxS, rfl⟩ := hxS trans ∑ i : Fin C.n, (1 + d.count 0) · gcongr with j hj simp only [e, comp_apply] by_cases hgj : C.g j = 0 · rw [hgj, map_zero] simp rw [degree_finSuccEquiv hgj, WithBot.succ_natCast, add_comm] simp only [Nat.cast_id, add_le_add_iff_left, degreeOf_def] exact Multiset.count_le_of_le _ (hS _ hxS _).2 · simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, smul_eq_mul] gcongr exact hSn _ hxS let B : Multiset (Fin n) := (d.toFinsupp.comapDomain Fin.succ (Fin.succ_injective _).injOn).toMultiset obtain ⟨T, hT₁, hT₂⟩ := chevalley_polynomialC (R := MvPolynomial (Fin n) R) (coeffsIn _ M ⊓ (degreesLE _ _ B).restrictScalars ℤ) (by simpa [MvPolynomial.coeff_one, apply_ite] using hM) S' (fun x hxS j k ↦ by simp only [ConstructibleSetData.map, AlgEquiv.toRingEquiv_eq_coe, RingEquiv.toRingHom_eq_coe, AlgEquiv.toRingEquiv_toRingHom, Finset.mem_image, BasicConstructibleSetData.map, RingHom.coe_coe, S', e] at hxS obtain ⟨C, hxS, rfl⟩ := hxS simp only [comp_apply, Submodule.mem_inf, mem_coeffsIn, Submodule.restrictScalars_mem, mem_degreesLE] constructor · intro d simp only [finSuccEquiv_coeff_coeff] exact (hS _ hxS _).1 _ · simp only [B] replace hS := (hS _ hxS j).2 simp only [Submodule.coe_restrictScalars, SetLike.mem_coe, mem_degreesLE, Multiset.le_iff_count, Finsupp.count_toMultiset, Finsupp.comapDomain_apply, Multiset.toFinsupp_apply, ← degreeOf_def] at hS ⊢ intro a exact (degreeOf_coeff_finSuccEquiv (C.g j) a k).trans (hS _)) let N := (k * (1 + d.count 0)) ^ (k * (1 + d.count 0)) have (C) (hCT : C ∈ T) (a) : C.g a ∈ coeffsIn (Fin n) (M ^ N) ⊓ (degreesLE R (Fin n) (N • B)).restrictScalars ℤ := by refine SetLike.le_def.mp ?_ ((hT₂ C hCT).2 a) refine pow_inf_le.trans (inf_le_inf ?_ ?_) · refine (pow_le_pow_right' ?_ (Nat.pow_self_mono hS')).trans le_coeffsIn_pow simpa [MvPolynomial.coeff_one, apply_ite] using hM · rw [degreesLE_nsmul, Submodule.restrictScalars_pow Nat.pow_self_pos.ne'] refine pow_le_pow_right' ?_ (Nat.pow_self_mono hS') simp have h1M : 1 ≤ M := Submodule.one_le.mpr hM obtain ⟨U, hU₁, hU₂⟩ := IH (M := M ^ N) (SetLike.le_def.mp (le_self_pow h1M Nat.pow_self_pos.ne') hM) _ _ T (fun C hCT ↦ (hT₂ C hCT).1) (fun C hCT k ↦ this C hCT k) simp only [Multiset.map_nsmul, Multiset.count_nsmul, ← pow_mul, N] at hU₂ have : ∀ i < n + 1, i.casesOn (1 + d.count 0) (1 + (B.map Fin.val).count ·) ≤ 1 + (d.map Fin.val).count i := by intro t ht change _ ≤ 1 + (d.map Fin.val).count (Fin.mk t ht).val rw [Multiset.count_map_eq_count' _ _ Fin.val_injective] obtain - | t := t · exact le_rfl · simp only [add_lt_add_iff_right] at ht change 1 + (B.map Fin.val).count (Fin.mk t ht).val ≤ _ rw [Multiset.count_map_eq_count' _ _ Fin.val_injective] simp [B] refine ⟨U, ?_, fun C hCU ↦ ⟨(hU₂ C hCU).1.trans ?_, fun i ↦ pow_le_pow_right' h1M ?_ <| (hU₂ C hCU).2 i⟩⟩ · unfold S' at hT₁ rw [← hU₁, ← hT₁, ← Set.image_comp, ← ContinuousMap.coe_comp, ← comap_comp, ConstructibleSetData.toSet_map] change _ = _ '' ((comapEquiv e.toRingEquiv).symm ⁻¹' _) rw [← OrderIso.image_eq_preimage_symm, Set.image_image] simp only [comapEquiv_apply, ← comap_apply, ← comap_comp_apply] congr! exact e.symm.toAlgHom.comp_algebraMap.symm · refine (numBound_mono hS' _ fun _ _ ↦ ?_).trans ((numBound_casesOn_succ k _ _ _).symm.trans_le (numBound_mono le_rfl _ this)) simp +contextual [mul_add, Nat.one_le_iff_ne_zero] · refine (Nat.mul_le_mul le_rfl (degBound_le_degBound hS' _ fun _ _ ↦ ?_)).trans ((degBound_casesOn_succ k _ _ _).symm.trans_le (degBound_le_degBound le_rfl _ this)) simp +contextual [mul_add, Nat.one_le_iff_ne_zero] /-! ### The general `f : R[Y₁, ..., Yₙ] → R[X₁, ..., Xₘ]` case -/ /-- The bound on the number of polynomials used to describe the constructible set appearing in Chevalley's theorem with complexity bound. -/ def numBound (k m n : ℕ) (d : Multiset (Fin m)) : ℕ := MvPolynomialC.numBound (k + n) (1 + (d.map Fin.val).count ·) m /-- The bound on the degree of the polynomials used to describe the constructible set appearing in Chevalley's theorem with complexity bound. -/ def degBound (k m n : ℕ) (d : Multiset (Fin m)) : ℕ := MvPolynomialC.degBound (k + n) (1 + (d.map Fin.val).count ·) m end ChevalleyThm open ChevalleyThm /-- **Chevalley's theorem** with complexity bound. A constructible set of complexity at most `M` in `Spec R[X₁, ..., Xₘ]` gets mapped under `f : R[Y₁, ..., Yₙ] → R[X₁, ..., Xₘ]` to a constructible set of complexity `O_{M, m, n}(1)` in `Spec R[Y₁, ..., Yₙ]`. See the module doc of `Mathlib/RingTheory/Spectrum/Prime/ChevalleyComplexity.lean` for an explanation of this notion of complexity. -/ lemma chevalley_mvPolynomial_mvPolynomial {m n : ℕ} (f : MvPolynomial (Fin n) R →ₐ[R] MvPolynomial (Fin m) R) (k : ℕ) (d : Multiset (Fin m)) (S : ConstructibleSetData (MvPolynomial (Fin m) R)) (hSn : ∀ C ∈ S, C.n ≤ k) (hS : ∀ C ∈ S, ∀ j, (C.g j).degrees ≤ d) (hf : ∀ i, (f (.X i)).degrees ≤ d) : ∃ T : ConstructibleSetData (MvPolynomial (Fin n) R), comap f '' S.toSet = T.toSet ∧ ∀ C ∈ T, C.n ≤ numBound k m n d ∧ ∀ i j, (C.g i).degreeOf j ≤ degBound k m n d := by classical let g : MvPolynomial (Fin m) (MvPolynomial (Fin n) R) →+* MvPolynomial (Fin m) R := eval₂Hom f.toRingHom X have hg : g.comp (algebraMap (MvPolynomial (Fin n) R) _) = f := by ext x : 2 <;> simp [g] let σ : MvPolynomial (Fin m) R →+* MvPolynomial (Fin m) (MvPolynomial (Fin n) R) := map (algebraMap _ _) have hσ : g.comp σ = .id _ := by ext : 2 <;> simp [g, σ] have hσ' (x) : g (σ x) = x := DFunLike.congr_fun hσ x have hg' : Surjective g := LeftInverse.surjective hσ' let S' : ConstructibleSetData (MvPolynomial (Fin m) (MvPolynomial (Fin n) R)) := S.image fun ⟨fk, k, gk⟩ ↦ ⟨σ fk, k + n, fun s ↦ (finSumFinEquiv.symm s).elim (σ ∘ gk) fun i ↦ .C (.X i) - σ (f (.X i))⟩ let s₀ : Set (MvPolynomial (Fin m) (MvPolynomial (Fin n) R)) := .range fun i ↦ .C (.X i) - σ (f (.X i)) have hs : zeroLocus s₀ = Set.range (comap g) := by rw [range_comap_of_surjective _ _ hg', ← zeroLocus_span] congr! 2 have H : Ideal.span s₀ ≤ RingHom.ker g := by simp only [Ideal.span_le, Set.range_subset_iff, SetLike.mem_coe, RingHom.mem_ker, map_sub, hσ', s₀] simp [g] refine H.antisymm fun p hp ↦ ?_ obtain ⟨q₁, q₂, hq₁, rfl⟩ : ∃ q₁ q₂, q₁ ∈ Ideal.span s₀ ∧ p = q₁ + σ q₂ := by clear hp obtain ⟨p, rfl⟩ := (commAlgEquiv _ _ _).surjective p simp_rw [← (commAlgEquiv R (Fin n) (Fin m)).symm.injective.eq_iff, AlgEquiv.symm_apply_apply] induction p using MvPolynomial.induction_on with | C q => exact ⟨0, q, by simp, (commAlgEquiv _ _ _).injective <| by simp [commAlgEquiv_C, σ]⟩ | add p q hp hq => obtain ⟨q₁, q₂, hq₁, rfl⟩ := hp obtain ⟨q₃, q₄, hq₃, rfl⟩ := hq refine ⟨q₁ + q₃, q₂ + q₄, add_mem hq₁ hq₃, by simp only [map_add, add_add_add_comm]⟩ | mul_X p i hp => obtain ⟨q₁, q₂, hq₁, rfl⟩ := hp simp only [← (commAlgEquiv R (Fin n) (Fin m)).injective.eq_iff, map_mul, AlgEquiv.apply_symm_apply, commAlgEquiv_X] refine ⟨q₁ * .C (.X i) + σ q₂ * (.C (.X i) - σ (f (.X i))), q₂ * f (.X i), ?_, ?_⟩ · exact add_mem (Ideal.mul_mem_right _ _ hq₁) (Ideal.mul_mem_left _ _ (Ideal.subset_span (Set.mem_range_self _))) · simp; ring obtain rfl : q₂ = 0 := by simpa [hσ', show g q₁ = 0 from H hq₁] using hp simpa using hq₁ have hg'' (t) : comap g '' t = comap σ ⁻¹' t ∩ zeroLocus s₀ := by refine Set.injOn_preimage (f := comap g) .rfl ?_ ?_ ?_ · simp · simp [hs] · rw [Set.preimage_image_eq _ (comap_injective_of_surjective g hg'), Set.preimage_inter, hs, Set.preimage_range, Set.inter_univ, ← Set.preimage_comp, ← ContinuousMap.coe_comp, ← comap_comp, hσ] simp only [comap_id, ContinuousMap.coe_id, Set.preimage_id_eq, id_eq] have hS' : comap g '' S.toSet = S'.toSet := by simp only [S', BasicConstructibleSetData.toSet, ConstructibleSetData.toSet, Set.image_iUnion₂, Finset.set_biUnion_finset_image, ← comp_def (g := finSumFinEquiv.symm), Set.range_comp, Equiv.range_eq_univ, Set.image_univ, Set.Sum.elim_range, Set.image_diff (hf := comap_injective_of_surjective g hg'), zeroLocus_union] simp [hg'', ← Set.inter_diff_distrib_right, Set.sdiff_inter_right_comm, s₀] obtain ⟨T, hT, hT'⟩ := chevalley_mvPolynomialC (M := (degreesLE R (Fin n) Finset.univ.1).restrictScalars ℤ) (by simp) (k + n) d S' (Finset.forall_mem_image.mpr fun x hx ↦ (by simpa using hSn _ hx)) (Finset.forall_mem_image.mpr fun x hx ↦ by intro j obtain ⟨j, rfl⟩ := finSumFinEquiv.surjective j simp only [Equiv.symm_apply_apply, Submodule.mem_inf, mem_coeffsIn, Submodule.restrictScalars_mem, mem_degreesLE] constructor · intro i obtain j | j := j · simp [σ, MvPolynomial.coeff_map, degrees_C] · simp only [MvPolynomial.algebraMap_eq, Sum.elim_inr, MvPolynomial.coeff_sub, MvPolynomial.coeff_C, MvPolynomial.coeff_map, σ] refine degrees_sub_le.trans ?_ simp only [degrees_C, apply_ite, degrees_zero, Multiset.union_zero] split_ifs with h · refine (degrees_X' _).trans ?_ simp · simp · obtain j | j := j · simp only [MvPolynomial.algebraMap_eq, Sum.elim_inl, comp_apply, σ] exact degrees_map_le.trans (hS _ hx j) · refine degrees_sub_le.trans ?_ simp only [degrees_C, Multiset.zero_union] exact degrees_map_le.trans (hf _)) refine ⟨T, ?_, fun C hCT ↦ ⟨(hT' C hCT).1, fun i j ↦ ?_⟩⟩ · rwa [← hg, comap_comp, ContinuousMap.coe_comp, Set.image_comp, hS'] · have := (hT' C hCT).2 i rw [← Submodule.restrictScalars_pow (MvPolynomialC.degBound_pos ..).ne', ← degreesLE_nsmul, Submodule.restrictScalars_mem, mem_degreesLE, Multiset.le_iff_count] at this simpa only [Multiset.count_nsmul, Multiset.count_univ, mul_one, ← degreeOf_def] using this j
.lake/packages/mathlib/Mathlib/RingTheory/Spectrum/Prime/Chevalley.lean
import Mathlib.RingTheory.Ideal.GoingDown import Mathlib.RingTheory.Spectrum.Prime.ChevalleyComplexity /-! # Chevalley's theorem In this file we provide the usual (algebraic) version of Chevalley's theorem. For the proof see `Mathlib/RingTheory/Spectrum/Prime/ChevalleyComplexity.lean`. -/ variable {R S : Type*} [CommRing R] [CommRing S] open Function Localization MvPolynomial Polynomial TensorProduct PrimeSpectrum Topology open scoped Pointwise namespace PrimeSpectrum lemma isConstructible_comap_C {s : Set (PrimeSpectrum (Polynomial R))} (hs : IsConstructible s) : IsConstructible (comap Polynomial.C '' s) := by obtain ⟨S, rfl⟩ := exists_constructibleSetData_iff.mpr hs obtain ⟨T, hT, -⟩ := ChevalleyThm.chevalley_polynomialC _ Submodule.mem_top S (by simp) rw [hT] exact T.isConstructible_toSet /-- **Chevalley's theorem**: If `f` is of finite presentation, then the image of a constructible set under `Spec(f)` is constructible. -/ lemma isConstructible_comap_image {f : R →+* S} (hf : f.FinitePresentation) {s : Set (PrimeSpectrum S)} (hs : IsConstructible s) : IsConstructible (comap f '' s) := by refine hf.polynomial_induction (fun _ _ _ _ f ↦ ∀ s, IsConstructible s → IsConstructible (comap f '' s)) (fun _ _ _ _ f ↦ ∀ s, IsConstructible s → IsConstructible (comap f '' s)) (fun _ _ _ ↦ isConstructible_comap_C) ?_ ?_ f s hs · intro R _ S _ f hf hf' s hs refine hs.image_of_isClosedEmbedding (isClosedEmbedding_comap_of_surjective _ f hf) ?_ rw [range_comap_of_surjective _ f hf] exact isRetrocompact_zeroLocus_compl_of_fg hf' · intro R _ S _ T _ f g H₁ H₂ s hs simp only [comap_comp, ContinuousMap.coe_comp, Set.image_comp] exact H₁ _ (H₂ _ hs) lemma isConstructible_range_comap {f : R →+* S} (hf : f.FinitePresentation) : IsConstructible (Set.range <| comap f) := Set.image_univ ▸ isConstructible_comap_image hf .univ @[stacks 00I1] lemma isOpenMap_comap_of_hasGoingDown_of_finitePresentation [Algebra R S] [Algebra.HasGoingDown R S] [Algebra.FinitePresentation R S] : IsOpenMap (comap (algebraMap R S)) := by rw [isBasis_basic_opens.isOpenMap_iff] rintro _ ⟨_, ⟨f, rfl⟩, rfl⟩ exact isOpen_of_stableUnderGeneralization_of_isConstructible ((basicOpen f).2.stableUnderGeneralization.image (Algebra.HasGoingDown.iff_generalizingMap_primeSpectrumComap.mp ‹_›)) (isConstructible_comap_image (RingHom.finitePresentation_algebraMap.mpr ‹_›) isConstructible_basicOpen) end PrimeSpectrum
.lake/packages/mathlib/Mathlib/RingTheory/Spectrum/Prime/Homeomorph.lean
import Mathlib.FieldTheory.PurelyInseparable.Basic import Mathlib.RingTheory.Flat.Basic import Mathlib.RingTheory.Spectrum.Prime.Topology /-! # Purely inseparable extensions are universal homeomorphisms If `K` is a purely inseparable extension of `k`, the induced map `Spec K ⟶ Spec k` is a universal homeomorphism, i.e. it stays a homeomorphism after arbitrary base change. ## Main results - `PrimeSpectrum.isHomeomorph_comap`: if `f : R →+* S` is a ring map with locally nilpotent kernel such that for every `x : S`, there exists `n > 0` such that `x ^ n` is in the image of `f`, `Spec f` is a homeomorphism. - `PrimeSpectrum.isHomeomorph_comap_of_isPurelyInseparable`: `Spec K ⟶ Spec k` is a universal homeomorphism for a purely inseparable field extension `K` over `k`. -/ open TensorProduct variable (k K R S : Type*) [Field k] [Field K] [Algebra k K] [CommRing R] [Algebra k R] [CommRing S] variable {R S} in /-- If the kernel of `f : R →+* S` consists of nilpotent elements and for every `x : S`, there exists `n > 0` such that `x ^ n` is in the range of `f`, then `Spec f` is a homeomorphism. Note: This does not hold for semirings, because `ℕ →+* ℤ` satisfies these conditions, but `Spec ℕ` has one more point than `Spec ℤ`. -/ @[stacks 0BR8 "Homeomorphism part"] lemma PrimeSpectrum.isHomeomorph_comap (f : R →+* S) (H : ∀ (x : S), ∃ n > 0, x ^ n ∈ f.range) (hker : RingHom.ker f ≤ nilradical R) : IsHomeomorph (comap f) := by have h1 : Function.Injective (comap f) := by intro q q' hqq' ext x obtain ⟨n, hn, y, hy⟩ := H x rw [← q.2.pow_mem_iff_mem _ hn, ← q'.2.pow_mem_iff_mem _ hn, ← hy] rw [PrimeSpectrum.ext_iff, SetLike.ext_iff] at hqq' apply hqq' have hint : f.kerLift.IsIntegral := fun x ↦ have ⟨n, hn, y, hy⟩ := H x let _ := f.kerLift.toAlgebra IsIntegral.of_pow hn (hy ▸ f.kerLift.isIntegralElem_map (x := ⟦y⟧)) have hbij : Function.Bijective (comap f) := ⟨h1, (comap_quotientMk_bijective_of_le_nilradical hker).2.comp <| hint.specComap_surjective f.kerLift_injective⟩ refine ⟨(comap f).continuous, ?_, h1, hbij.2⟩ rw [isTopologicalBasis_basic_opens.isOpenMap_iff] rintro - ⟨s, rfl⟩ obtain ⟨n, hn, r, hr⟩ := H s have : (comap f) '' (basicOpen s) = basicOpen r := (Set.eq_preimage_iff_image_eq hbij).mp <| by rw [← basicOpen_pow _ n hn, ← hr]; rfl exact this ▸ isOpen_basicOpen /-- Purely inseparable field extensions are universal homeomorphisms. -/ @[stacks 0BRA "Special case for purely inseparable field extensions"] lemma PrimeSpectrum.isHomeomorph_comap_of_isPurelyInseparable [IsPurelyInseparable k K] : IsHomeomorph (comap <| algebraMap R (R ⊗[k] K)) := by let q := ringExpChar k refine isHomeomorph_comap _ (IsPurelyInseparable.exists_pow_mem_range_tensorProduct) ?_ convert bot_le rw [← RingHom.injective_iff_ker_eq_bot] exact Algebra.TensorProduct.includeLeft_injective (S := R) (algebraMap k K).injective /-- If `L` is a purely inseparable extension of `K` over `R` and `S` is an `R`-algebra, the induced map `Spec (L ⊗[R] S) ⟶ Spec (K ⊗[R] S)` is a homeomorphism. -/ lemma PrimeSpectrum.isHomeomorph_comap_tensorProductMap_of_isPurelyInseparable [Algebra R K] [Algebra R S] (L : Type*) [Field L] [Algebra R L] [Algebra K L] [IsScalarTower R K L] [IsPurelyInseparable K L] : IsHomeomorph (comap (Algebra.TensorProduct.map (Algebra.ofId K L) (.id R S)).toRingHom) := by let e : (L ⊗[R] S) ≃ₐ[K] L ⊗[K] (K ⊗[R] S) := (Algebra.TensorProduct.cancelBaseChange R K K L S).symm let e2 : L ⊗[K] (K ⊗[R] S) ≃ₐ[K] (K ⊗[R] S) ⊗[K] L := Algebra.TensorProduct.comm .. have heq : Algebra.TensorProduct.map (Algebra.ofId K L) (AlgHom.id R S) = (e.symm.toAlgHom.comp e2.symm.toAlgHom).comp (IsScalarTower.toAlgHom K (K ⊗[R] S) ((K ⊗[R] S) ⊗[K] L)) := by ext; simp [e, e2] rw [heq] simp only [AlgEquiv.toAlgHom_eq_coe, AlgHom.toRingHom_eq_coe, AlgHom.comp_toRingHom, AlgEquiv.toAlgHom_toRingHom, IsScalarTower.coe_toAlgHom, comap_comp, ContinuousMap.coe_comp] exact (isHomeomorph_comap_of_isPurelyInseparable K L (K ⊗[R] S)).comp <| (isHomeomorph_comap_of_bijective e2.symm.bijective).comp <| isHomeomorph_comap_of_bijective e.symm.bijective
.lake/packages/mathlib/Mathlib/RingTheory/Spectrum/Prime/Module.lean
import Mathlib.RingTheory.Spectrum.Prime.Topology import Mathlib.RingTheory.Support /-! # Subsets of prime spectra related to modules ## Main results - `LocalizedModule.subsingleton_iff_disjoint` : `M[1/f] = 0 ↔ D(f) ∩ Supp M = 0`. - `Module.isClosed_support` : If `M` is a finite `R`-module, then `Supp M` is closed. ## TODO - If `M` is finitely presented, the complement of `Supp M` is quasi-compact. (stacks#051B) -/ variable {R A M : Type*} [CommRing R] [AddCommGroup M] [Module R M] [CommRing A] [Algebra R A] [Module A M] variable (R M) in lemma IsLocalRing.closedPoint_mem_support [IsLocalRing R] [Nontrivial M] : IsLocalRing.closedPoint R ∈ Module.support R M := by obtain ⟨p, hp⟩ := (Module.nonempty_support_iff (R := R)).mpr ‹_› exact Module.mem_support_mono le_top hp /-- `M[1/f] = 0` if and only if `D(f) ∩ Supp M = 0`. -/ lemma LocalizedModule.subsingleton_iff_disjoint {f : R} : Subsingleton (LocalizedModule (.powers f) M) ↔ Disjoint ↑(PrimeSpectrum.basicOpen f) (Module.support R M) := by rw [subsingleton_iff_support_subset, PrimeSpectrum.basicOpen_eq_zeroLocus_compl, disjoint_compl_left_iff, Set.le_iff_subset] lemma Module.stableUnderSpecialization_support : StableUnderSpecialization (Module.support R M) := fun x y e ↦ mem_support_mono <| (PrimeSpectrum.le_iff_specializes x y).mpr e lemma Module.isClosed_support [Module.Finite R M] : IsClosed (Module.support R M) := by rw [support_eq_zeroLocus] apply PrimeSpectrum.isClosed_zeroLocus lemma Module.support_subset_preimage_comap [IsScalarTower R A M] : Module.support A M ⊆ PrimeSpectrum.comap (algebraMap R A) ⁻¹' Module.support R M := by intro x hx simp only [Set.mem_preimage, mem_support_iff', PrimeSpectrum.comap_asIdeal, Ideal.mem_comap, ne_eq, not_imp_not] at hx ⊢ obtain ⟨m, hm⟩ := hx exact ⟨m, fun r e ↦ hm _ (by simpa)⟩
.lake/packages/mathlib/Mathlib/RingTheory/Spectrum/Prime/LTSeries.lean
import Mathlib.RingTheory.Ideal.KrullsHeightTheorem /-! # Lemmas about `LTSeries` in the prime spectrum ## Main results * `PrimeSpectrum.exist_ltSeries_mem_one_of_mem_last`: Let $R$ be a Noetherian ring, $\mathfrak{p}_0 < \dots < \mathfrak{p}_n$ be a chain of primes, $x \in \mathfrak{p}_n$. Then we can find another chain of primes $\mathfrak{q}_0 < \dots < \mathfrak{q}_n$ such that $x \in \mathfrak{q}_1$, $\mathfrak{p}_0 = \mathfrak{q}_0$ and $\mathfrak{p}_n = \mathfrak{q}_n$. -/ variable {R : Type*} [CommRing R] [IsNoetherianRing R] local notation "𝔪" => IsLocalRing.maximalIdeal R open Ideal IsLocalRing namespace PrimeSpectrum theorem exist_mem_one_of_mem_maximal_ideal [IsLocalRing R] {p₁ p₀ : PrimeSpectrum R} (h₀ : p₀ < p₁) (h₁ : p₁ < closedPoint R) {x : R} (hx : x ∈ 𝔪) : ∃ q : PrimeSpectrum R, x ∈ q.asIdeal ∧ p₀ < q ∧ q.asIdeal < 𝔪 := by by_cases hn : x ∈ p₀.1 · exact ⟨p₁, h₀.le hn, h₀, h₁⟩ let e := p₀.1.primeSpectrumQuotientOrderIsoZeroLocus.symm obtain ⟨q, hq⟩ := (p₀.1 + span {x}).nonempty_minimalPrimes <| sup_le (IsLocalRing.le_maximalIdeal_of_isPrime p₀.1) ((span_singleton_le_iff_mem 𝔪).mpr hx) |>.trans_lt (IsMaximal.isPrime' 𝔪).1.lt_top |>.ne let q : PrimeSpectrum R := ⟨q, hq.1.1⟩ have : q.1.IsPrime := q.2 have hxq : x ∈ q.1 := le_sup_right.trans hq.1.2 (mem_span_singleton_self x) refine ⟨q, hxq, lt_of_le_not_ge (le_sup_left.trans hq.1.2) fun h ↦ hn (h hxq), ?_⟩ refine lt_of_le_of_ne (IsLocalRing.le_maximalIdeal_of_isPrime q.1) fun hqm ↦ ?_ have h : (e ⟨q, le_sup_left.trans hq.1.2⟩).1.height ≤ 1 := map_height_le_one_of_mem_minimalPrimes hq simp_rw [show q = closedPoint R from PrimeSpectrum.ext hqm] at h have hph : (e ⟨p₁, h₀.le⟩).1.height ≤ 0 := Order.lt_one_iff_nonpos.mp (height_le_iff.mp h _ inferInstance (by simpa using h₁)) refine ENat.not_lt_zero (e ⟨p₀, le_refl p₀⟩).1.height (height_le_iff.mp hph _ inferInstance ?_) simpa using h₀ theorem exist_mem_one_of_mem_two {p₁ p₀ p₂ : PrimeSpectrum R} (h₀ : p₀ < p₁) (h₁ : p₁ < p₂) {x : R} (hx : x ∈ p₂.asIdeal) : ∃ q : (PrimeSpectrum R), x ∈ q.asIdeal ∧ p₀ < q ∧ q < p₂ := by let e := IsLocalization.AtPrime.primeSpectrumOrderIso (Localization.AtPrime p₂.1) p₂.1 have hm : closedPoint (Localization.AtPrime p₂.1) = e.symm ⟨p₂, le_refl p₂⟩ := (PrimeSpectrum.ext Localization.AtPrime.map_eq_maximalIdeal).symm obtain ⟨q, hxq, h₀, h₁⟩ := @exist_mem_one_of_mem_maximal_ideal (Localization.AtPrime p₂.1) _ _ _ (e.symm ⟨p₁, h₁.le⟩) (e.symm ⟨p₀, (h₀.trans h₁).le⟩) (e.symm.lt_iff_lt.mpr h₀) (by simp [hm, h₁]) (algebraMap R (Localization.AtPrime p₂.1) x) <| by rw [← Localization.AtPrime.map_eq_maximalIdeal] exact mem_map_of_mem (algebraMap R (Localization.AtPrime p₂.1)) hx rw [← e.symm_apply_apply q] at h₀ h₁ hxq have hq : (e q).1 < p₂ := by have h : e.symm (e q) < e.symm ⟨p₂, le_refl p₂⟩ := h₁.trans_eq Localization.AtPrime.map_eq_maximalIdeal.symm rwa [OrderIso.lt_iff_lt, Subtype.mk_lt_mk] at h exact Exists.intro (e q).1 ⟨(p₂.1.under_map_of_isLocalizationAtPrime hq.le).le hxq, e.symm.lt_iff_lt.mp h₀, hq⟩ /-- Let $R$ be a Noetherian ring, $\mathfrak{p}_0 < \dots < \mathfrak{p}_n$ be a chain of primes, $x \in \mathfrak{p}_n$. Then we can find another chain of primes $\mathfrak{q}_0 < \dots < \mathfrak{q}_n$ such that $x \in \mathfrak{q}_1$, $\mathfrak{p}_0 = \mathfrak{q}_0$ and $\mathfrak{p}_n = \mathfrak{q}_n$. -/ theorem exist_ltSeries_mem_one_of_mem_last (p : LTSeries (PrimeSpectrum R)) {x : R} (hx : x ∈ p.last.asIdeal) : ∃ q : LTSeries (PrimeSpectrum R), x ∈ (q 1).asIdeal ∧ p.length = q.length ∧ p.head = q.head ∧ p.last = q.last := by generalize hp : p.length = n induction n generalizing p with | zero => use RelSeries.singleton _ p.last simp only [RelSeries.singleton_toFun, hx, RelSeries.singleton_length, RelSeries.head, RelSeries.last_singleton, and_true, true_and] rw [show 0 = Fin.last p.length from Fin.zero_eq_mk.mpr hp, RelSeries.last] | succ n hn => ?_ by_cases h0 : n = 0 · use p have h1 : 1 = Fin.last p.length := by rw [Fin.last, hp, h0, zero_add] exact Fin.natCast_eq_mk (Nat.one_lt_succ_succ 0) simpa [h1, hp] using hx obtain ⟨q, hxq, h2, hq⟩ : ∃ q : PrimeSpectrum R, x ∈ q.1 ∧ p ⟨p.length - 2, _⟩ < q ∧ q < p.last := (p ⟨p.length - 1, p.length.sub_lt_succ 1⟩).exist_mem_one_of_mem_two (p.strictMono (Nat.pred_lt (by simpa [hp]))) (p.strictMono (Nat.pred_lt (by simp [hp]))) hx obtain ⟨Q, hx, hQ, hh, hl⟩ := hn (p.eraseLast.eraseLast.snoc q h2) (by simpa using hxq) <| by simpa [hp] using Nat.succ_pred_eq_of_ne_zero h0 have h1 : 1 < Q.length + 1 := Nat.lt_of_sub_ne_zero (hQ.symm.trans_ne h0) have h : 1 = (1 : Fin (Q.length + 1)).castSucc := by simp [Fin.one_eq_mk_of_lt h1] exact ⟨Q.snoc p.last (by simpa [← hl] using hq), by simpa [h], by simpa, by simp [← hh], by simp⟩ end PrimeSpectrum
.lake/packages/mathlib/Mathlib/RingTheory/Spectrum/Prime/TensorProduct.lean
import Mathlib.RingTheory.Spectrum.Prime.Topology import Mathlib.RingTheory.SurjectiveOnStalks /-! # Lemmas regarding the prime spectrum of tensor products ## Main result - `PrimeSpectrum.isEmbedding_tensorProductTo_of_surjectiveOnStalks`: If `R →+* T` is surjective on stalks (see Mathlib/RingTheory/SurjectiveOnStalks.lean), then `Spec(S ⊗[R] T) → Spec S × Spec T` is a topological embedding (where `Spec S × Spec T` is the Cartesian product with the product topology). -/ variable (R S T : Type*) [CommRing R] [CommRing S] [Algebra R S] variable [CommRing T] [Algebra R T] open TensorProduct Topology /-- The canonical map from `Spec(S ⊗[R] T)` to the Cartesian product `Spec S × Spec T`. -/ noncomputable def PrimeSpectrum.tensorProductTo (x : PrimeSpectrum (S ⊗[R] T)) : PrimeSpectrum S × PrimeSpectrum T := ⟨comap (algebraMap _ _) x, comap Algebra.TensorProduct.includeRight.toRingHom x⟩ @[fun_prop] lemma PrimeSpectrum.continuous_tensorProductTo : Continuous (tensorProductTo R S T) := (comap _).2.prodMk (comap _).2 variable (hRT : (algebraMap R T).SurjectiveOnStalks) include hRT lemma PrimeSpectrum.isEmbedding_tensorProductTo_of_surjectiveOnStalks_aux (p₁ p₂ : PrimeSpectrum (S ⊗[R] T)) (h : tensorProductTo R S T p₁ = tensorProductTo R S T p₂) : p₁ ≤ p₂ := by let g : T →+* S ⊗[R] T := Algebra.TensorProduct.includeRight.toRingHom intro x hxp₁ by_contra hxp₂ obtain ⟨t, r, a, ht, e⟩ := hRT.exists_mul_eq_tmul x (p₂.asIdeal.comap g) inferInstance have h₁ : a ⊗ₜ[R] t ∈ p₁.asIdeal := e ▸ p₁.asIdeal.mul_mem_left (1 ⊗ₜ[R] (r • t)) hxp₁ have h₂ : a ⊗ₜ[R] t ∉ p₂.asIdeal := e ▸ p₂.asIdeal.primeCompl.mul_mem ht hxp₂ rw [← mul_one a, ← one_mul t, ← Algebra.TensorProduct.tmul_mul_tmul] at h₁ h₂ have h₃ : t ∉ p₂.asIdeal.comap g := fun h ↦ h₂ (Ideal.mul_mem_left _ _ h) have h₄ : a ∉ p₂.asIdeal.comap (algebraMap S (S ⊗[R] T)) := fun h ↦ h₂ (Ideal.mul_mem_right _ _ h) replace h₃ : t ∉ p₁.asIdeal.comap g := by rwa [show p₁.asIdeal.comap g = p₂.asIdeal.comap g from congr($h.2.1)] replace h₄ : a ∉ p₁.asIdeal.comap (algebraMap S (S ⊗[R] T)) := by rwa [show p₁.asIdeal.comap (algebraMap S (S ⊗[R] T)) = p₂.asIdeal.comap _ from congr($h.1.1)] exact p₁.asIdeal.primeCompl.mul_mem h₄ h₃ h₁ lemma PrimeSpectrum.isEmbedding_tensorProductTo_of_surjectiveOnStalks : IsEmbedding (tensorProductTo R S T) := by refine ⟨?_, fun p₁ p₂ e ↦ (isEmbedding_tensorProductTo_of_surjectiveOnStalks_aux R S T hRT p₁ p₂ e).antisymm (isEmbedding_tensorProductTo_of_surjectiveOnStalks_aux R S T hRT p₂ p₁ e.symm)⟩ let g : T →+* S ⊗[R] T := Algebra.TensorProduct.includeRight.toRingHom refine ⟨(continuous_tensorProductTo ..).le_induced.antisymm (isBasis_basic_opens.le_iff.mpr ?_)⟩ rintro _ ⟨f, rfl⟩ rw [@isOpen_iff_forall_mem_open] rintro J (hJ : f ∉ J.asIdeal) obtain ⟨t, r, a, ht, e⟩ := hRT.exists_mul_eq_tmul f (J.asIdeal.comap g) inferInstance refine ⟨_, ?_, ⟨_, (basicOpen a).2.prod (basicOpen t).2, rfl⟩, ?_⟩ · rintro x ⟨hx₁ : a ⊗ₜ[R] (1 : T) ∉ x.asIdeal, hx₂ : (1 : S) ⊗ₜ[R] t ∉ x.asIdeal⟩ (hx₃ : f ∈ x.asIdeal) apply x.asIdeal.primeCompl.mul_mem hx₁ hx₂ rw [Algebra.TensorProduct.tmul_mul_tmul, mul_one, one_mul, ← e] exact x.asIdeal.mul_mem_left _ hx₃ · have : a ⊗ₜ[R] (1 : T) * (1 : S) ⊗ₜ[R] t ∉ J.asIdeal := by rw [Algebra.TensorProduct.tmul_mul_tmul, mul_one, one_mul, ← e] exact J.asIdeal.primeCompl.mul_mem ht hJ rwa [J.isPrime.mul_mem_iff_mem_or_mem.not, not_or] at this
.lake/packages/mathlib/Mathlib/RingTheory/Spectrum/Prime/Topology.lean
import Mathlib.Algebra.Order.Ring.Idempotent import Mathlib.Order.Heyting.Hom import Mathlib.RingTheory.Finiteness.Ideal import Mathlib.RingTheory.Ideal.GoingUp import Mathlib.RingTheory.Ideal.MinimalPrime.Localization import Mathlib.RingTheory.KrullDimension.Basic import Mathlib.RingTheory.Localization.Algebra import Mathlib.RingTheory.Spectrum.Maximal.Localization import Mathlib.Topology.Constructible import Mathlib.Topology.KrullDimension import Mathlib.Topology.Spectral.Basic /-! # The Zariski topology on the prime spectrum of a commutative (semi)ring ## 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). ## Main definitions * `PrimeSpectrum.zariskiTopology`: the Zariski topology on the prime spectrum, whose closed sets are zero loci (`zeroLocus`). * `PrimeSpectrum.basicOpen`: the complement of the zero locus of a single element. The `basicOpen`s form a topological basis of the Zariski topology: `PrimeSpectrum.isTopologicalBasis_basic_opens`. * `PrimeSpectrum.comap`: the continuous map between prime spectra induced by a ring homomorphism. * `IsLocalRing.closedPoint`: the maximal ideal of a local ring is the unique closed point in its prime spectrum. ## Main results * `PrimeSpectrum.instSpectralSpace`: every prime spectrum is a spectral space, i.e. it is quasi-compact, sober (in particular T0), quasi-separated, and its compact open subsets form a topological basis. * `PrimeSpectrum.discreteTopology_iff_finite_and_krullDimLE_zero`: the prime spectrum of a commutative semiring is discrete iff it is finite and the semiring has zero Krull dimension or is trivial. * `PrimeSpectrum.localization_comap_range`, `PrimeSpectrum.localization_comap_isEmbedding`: localization at a submonoid of a commutative semiring induces an embedding between the prime spectra, with range consisting of prime ideals disjoint from the submonoid. * `PrimeSpectrum.localization_away_comap_range`: for localization away from an element, the range of the embedding is the `basicOpen` associated to the element. * `PrimeSpectrum.comap_isEmbedding_of_surjective`: a surjective ring homomorphism between commutative semirings induces an embedding between the prime spectra. * `PrimeSpectrum.isClosedEmbedding_comap_of_surjective`: a surjective ring homomorphism between commutative rings induces a closed embedding between the prime spectra. * `PrimeSpectrum.primeSpectrumProdHomeo`: the prime spectrum of a product semiring is homeomorphic to the disjoint union of the prime spectra. * `PrimeSpectrum.stableUnderSpecialization_range_iff`: the range of `PrimeSpectrum.comap _` is closed iff it is stable under specialization. * `PrimeSpectrum.denseRange_comap_iff_minimalPrimes`, `PrimeSpectrum.denseRange_comap_iff_ker_le_nilRadical`: the range of `comap f` is dense iff it contains all minimal primes, iff the kernel of `f` is contained in the nilradical. * `PrimeSpectrum.isClosedMap_comap_of_isIntegral`: `comap f` is a closed map if `f` is integral. * `PrimeSpectrum.isIntegral_of_isClosedMap_comap_mapRingHom`: `f : R →+* S` is integral if `comap (Polynomial.mapRingHom f : R[X] →+* S[X])` is a closed map. In the prime spectrum of a commutative semiring: * `PrimeSpectrum.isClosed_iff_zeroLocus_radical_ideal`, `PrimeSpectrum.isRadical_vanishingIdeal`, `PrimeSpectrum.zeroLocus_eq_iff`, `PrimeSpectrum.vanishingIdeal_anti_mono_iff`: closed subsets correspond to radical ideals. * `PrimeSpectrum.isClosed_singleton_iff_isMaximal`: closed points correspond to maximal ideals. * `PrimeSpectrum.isIrreducible_iff_vanishingIdeal_isPrime`: irreducible closed subsets correspond to prime ideals. * `minimalPrimes.equivIrreducibleComponents`: irreducible components correspond to minimal primes. * `PrimeSpectrum.mulZeroAddOneEquivClopens`: clopen subsets correspond to pairs of elements that add up to 1 and multiply to 0 in the semiring. * `PrimeSpectrum.isIdempotentElemEquivClopens`: (if the semiring is a ring) clopen subsets correspond to idempotents in the ring. -/ open Topology noncomputable section universe u v variable (R : Type u) (S : Type v) namespace PrimeSpectrum section CommSemiring variable [CommSemiring R] [CommSemiring S] variable {R S} /-- The Zariski topology on the prime spectrum of a commutative (semi)ring is defined via the closed sets of the topology: they are exactly those sets that are the zero locus of a subset of the ring. -/ instance zariskiTopology : TopologicalSpace (PrimeSpectrum R) := TopologicalSpace.ofClosed (Set.range PrimeSpectrum.zeroLocus) ⟨Set.univ, by simp⟩ (by intro Zs h rw [Set.sInter_eq_iInter] choose f hf using fun i : Zs => h i.prop simp only [← hf] exact ⟨_, zeroLocus_iUnion _⟩) (by rintro _ ⟨s, rfl⟩ _ ⟨t, rfl⟩ exact ⟨_, (union_zeroLocus s t).symm⟩) theorem isOpen_iff (U : Set (PrimeSpectrum R)) : IsOpen U ↔ ∃ s, Uᶜ = zeroLocus s := by simp only [@eq_comm _ Uᶜ]; rfl theorem isClosed_iff_zeroLocus (Z : Set (PrimeSpectrum R)) : IsClosed Z ↔ ∃ s, Z = zeroLocus s := by rw [← isOpen_compl_iff, isOpen_iff, compl_compl] theorem isClosed_iff_zeroLocus_ideal (Z : Set (PrimeSpectrum R)) : IsClosed Z ↔ ∃ I : Ideal R, Z = zeroLocus I := (isClosed_iff_zeroLocus _).trans ⟨fun ⟨s, hs⟩ => ⟨_, (zeroLocus_span s).substr hs⟩, fun ⟨I, hI⟩ => ⟨I, hI⟩⟩ theorem isClosed_iff_zeroLocus_radical_ideal (Z : Set (PrimeSpectrum R)) : IsClosed Z ↔ ∃ I : Ideal R, I.IsRadical ∧ Z = zeroLocus I := (isClosed_iff_zeroLocus_ideal _).trans ⟨fun ⟨I, hI⟩ => ⟨_, I.radical_isRadical, (zeroLocus_radical I).substr hI⟩, fun ⟨I, _, hI⟩ => ⟨I, hI⟩⟩ theorem isClosed_zeroLocus (s : Set R) : IsClosed (zeroLocus s) := by rw [isClosed_iff_zeroLocus] exact ⟨s, rfl⟩ theorem zeroLocus_vanishingIdeal_eq_closure (t : Set (PrimeSpectrum R)) : zeroLocus (vanishingIdeal t : Set R) = closure t := by rcases isClosed_iff_zeroLocus (closure t) |>.mp isClosed_closure with ⟨I, hI⟩ rw [subset_antisymm_iff, (isClosed_zeroLocus _).closure_subset_iff, hI, subset_zeroLocus_iff_subset_vanishingIdeal, (gc R).u_l_u_eq_u, ← subset_zeroLocus_iff_subset_vanishingIdeal, ← hI] exact ⟨subset_closure, subset_zeroLocus_vanishingIdeal t⟩ theorem vanishingIdeal_closure (t : Set (PrimeSpectrum R)) : vanishingIdeal (closure t) = vanishingIdeal t := zeroLocus_vanishingIdeal_eq_closure t ▸ (gc R).u_l_u_eq_u t theorem closure_singleton (x) : closure ({x} : Set (PrimeSpectrum R)) = zeroLocus x.asIdeal := by rw [← zeroLocus_vanishingIdeal_eq_closure, vanishingIdeal_singleton] theorem isClosed_singleton_iff_isMaximal (x : PrimeSpectrum R) : IsClosed ({x} : Set (PrimeSpectrum R)) ↔ x.asIdeal.IsMaximal := by rw [← closure_subset_iff_isClosed, ← zeroLocus_vanishingIdeal_eq_closure, vanishingIdeal_singleton] constructor <;> intro H · rcases x.asIdeal.exists_le_maximal x.2.1 with ⟨m, hm, hxm⟩ exact (congr_arg asIdeal (@H ⟨m, hm.isPrime⟩ hxm)) ▸ hm · exact fun p hp ↦ PrimeSpectrum.ext (H.eq_of_le p.2.1 hp).symm theorem isRadical_vanishingIdeal (s : Set (PrimeSpectrum R)) : (vanishingIdeal s).IsRadical := by rw [← vanishingIdeal_closure, ← zeroLocus_vanishingIdeal_eq_closure, vanishingIdeal_zeroLocus_eq_radical] apply Ideal.radical_isRadical theorem zeroLocus_eq_iff {I J : Ideal R} : zeroLocus (I : Set R) = zeroLocus J ↔ I.radical = J.radical := by constructor · intro h; simp_rw [← vanishingIdeal_zeroLocus_eq_radical, h] · intro h; rw [← zeroLocus_radical, h, zeroLocus_radical] theorem vanishingIdeal_anti_mono_iff {s t : Set (PrimeSpectrum R)} (ht : IsClosed t) : s ⊆ t ↔ vanishingIdeal t ≤ vanishingIdeal s := ⟨vanishingIdeal_anti_mono, fun h => by rw [← ht.closure_subset_iff, ← ht.closure_eq] convert ← zeroLocus_anti_mono_ideal h <;> apply zeroLocus_vanishingIdeal_eq_closure⟩ theorem vanishingIdeal_strict_anti_mono_iff {s t : Set (PrimeSpectrum R)} (hs : IsClosed s) (ht : IsClosed t) : s ⊂ t ↔ vanishingIdeal t < vanishingIdeal s := by rw [Set.ssubset_def, vanishingIdeal_anti_mono_iff hs, vanishingIdeal_anti_mono_iff ht, lt_iff_le_not_ge] /-- The antitone order embedding of closed subsets of `Spec R` into ideals of `R`. -/ def closedsEmbedding (R : Type*) [CommSemiring R] : (TopologicalSpace.Closeds <| PrimeSpectrum R)ᵒᵈ ↪o Ideal R := OrderEmbedding.ofMapLEIff (fun s => vanishingIdeal ↑(OrderDual.ofDual s)) fun s _ => (vanishingIdeal_anti_mono_iff s.2).symm theorem t1Space_iff_isField [IsDomain R] : T1Space (PrimeSpectrum R) ↔ IsField R := by refine ⟨?_, fun h => ?_⟩ · intro h have hbot : Ideal.IsPrime (⊥ : Ideal R) := Ideal.bot_prime exact Classical.not_not.1 (mt (Ring.ne_bot_of_isMaximal_of_not_isField <| (isClosed_singleton_iff_isMaximal _).1 (T1Space.t1 ⟨⊥, hbot⟩)) (by simp)) · refine ⟨fun x => (isClosed_singleton_iff_isMaximal x).2 ?_⟩ by_cases hx : x.asIdeal = ⊥ · letI := h.toSemifield exact hx.symm ▸ Ideal.bot_isMaximal · exact absurd h (Ring.not_isField_iff_exists_prime.2 ⟨x.asIdeal, ⟨hx, x.2⟩⟩) local notation "Z(" a ")" => zeroLocus (a : Set R) theorem isIrreducible_zeroLocus_iff_of_radical (I : Ideal R) (hI : I.IsRadical) : IsIrreducible (zeroLocus (I : Set R)) ↔ I.IsPrime := by rw [Ideal.isPrime_iff, IsIrreducible] apply and_congr · rw [Set.nonempty_iff_ne_empty, Ne, zeroLocus_empty_iff_eq_top] · trans ∀ x y : Ideal R, Z(I) ⊆ Z(x) ∪ Z(y) → Z(I) ⊆ Z(x) ∨ Z(I) ⊆ Z(y) · simp_rw [isPreirreducible_iff_isClosed_union_isClosed, isClosed_iff_zeroLocus_ideal] constructor · rintro h x y exact h _ _ ⟨x, rfl⟩ ⟨y, rfl⟩ · rintro h _ _ ⟨x, rfl⟩ ⟨y, rfl⟩ exact h x y · simp_rw [← zeroLocus_inf, subset_zeroLocus_iff_le_vanishingIdeal, vanishingIdeal_zeroLocus_eq_radical, hI.radical] constructor · simp_rw [← SetLike.mem_coe, ← Set.singleton_subset_iff, ← Ideal.span_le, ← Ideal.span_singleton_mul_span_singleton] refine fun h x y h' => h _ _ ?_ rw [← hI.radical_le_iff] at h' ⊢ simpa only [Ideal.radical_inf, Ideal.radical_mul] using h' · simp_rw [or_iff_not_imp_left, SetLike.not_le_iff_exists] rintro h s t h' ⟨x, hx, hx'⟩ y hy exact h (h' ⟨Ideal.mul_mem_right _ _ hx, Ideal.mul_mem_left _ _ hy⟩) hx' theorem isIrreducible_zeroLocus_iff (I : Ideal R) : IsIrreducible (zeroLocus (I : Set R)) ↔ I.radical.IsPrime := zeroLocus_radical I ▸ isIrreducible_zeroLocus_iff_of_radical _ I.radical_isRadical theorem isIrreducible_iff_vanishingIdeal_isPrime {s : Set (PrimeSpectrum R)} : IsIrreducible s ↔ (vanishingIdeal s).IsPrime := by rw [← isIrreducible_iff_closure, ← zeroLocus_vanishingIdeal_eq_closure, isIrreducible_zeroLocus_iff_of_radical _ (isRadical_vanishingIdeal s)] lemma vanishingIdeal_isIrreducible : vanishingIdeal (R := R) '' {s | IsIrreducible s} = {P | P.IsPrime} := Set.ext fun I ↦ ⟨fun ⟨_, hs, e⟩ ↦ e ▸ isIrreducible_iff_vanishingIdeal_isPrime.mp hs, fun h ↦ ⟨zeroLocus I, (isIrreducible_zeroLocus_iff_of_radical _ h.isRadical).mpr h, (vanishingIdeal_zeroLocus_eq_radical I).trans h.radical⟩⟩ lemma vanishingIdeal_isClosed_isIrreducible : vanishingIdeal (R := R) '' {s | IsClosed s ∧ IsIrreducible s} = {P | P.IsPrime} := by refine (subset_antisymm ?_ ?_).trans vanishingIdeal_isIrreducible · exact Set.image_mono fun _ ↦ And.right rintro _ ⟨s, hs, rfl⟩ exact ⟨closure s, ⟨isClosed_closure, hs.closure⟩, vanishingIdeal_closure s⟩ instance irreducibleSpace [IsDomain R] : IrreducibleSpace (PrimeSpectrum R) := by rw [irreducibleSpace_def, Set.top_eq_univ, ← zeroLocus_bot, isIrreducible_zeroLocus_iff] simpa using Ideal.bot_prime instance quasiSober : QuasiSober (PrimeSpectrum R) := ⟨fun {S} h₁ h₂ => ⟨⟨_, isIrreducible_iff_vanishingIdeal_isPrime.1 h₁⟩, by rw [IsGenericPoint, closure_singleton, zeroLocus_vanishingIdeal_eq_closure, h₂.closure_eq]⟩⟩ /-- The prime spectrum of a commutative (semi)ring is a compact topological space. -/ instance compactSpace : CompactSpace (PrimeSpectrum R) := by refine compactSpace_of_finite_subfamily_closed fun S S_closed S_empty ↦ ?_ choose I hI using fun i ↦ (isClosed_iff_zeroLocus_ideal (S i)).mp (S_closed i) simp_rw [hI, ← zeroLocus_iSup, zeroLocus_empty_iff_eq_top, ← top_le_iff] at S_empty ⊢ exact Ideal.isCompactElement_top.exists_finset_of_le_iSup _ _ S_empty /-- The prime spectrum of a commutative semiring has discrete Zariski topology iff it is finite and the semiring has Krull dimension zero or is trivial. -/ theorem discreteTopology_iff_finite_and_krullDimLE_zero : DiscreteTopology (PrimeSpectrum R) ↔ Finite (PrimeSpectrum R) ∧ Ring.KrullDimLE 0 R := ⟨fun _ ↦ ⟨finite_of_compact_of_discrete, .mk₀ fun I h ↦ isClosed_singleton_iff_isMaximal ⟨I, h⟩ |>.mp <| discreteTopology_iff_forall_isClosed.mp ‹_› _⟩, fun ⟨_, _⟩ ↦ .of_finite_of_isClosed_singleton fun p ↦ (isClosed_singleton_iff_isMaximal p).mpr inferInstance⟩ /-- The prime spectrum of a semiring has discrete Zariski topology iff there are only finitely many maximal ideals and their intersection is contained in the nilradical. -/ theorem discreteTopology_iff_finite_isMaximal_and_sInf_le_nilradical : letI s := {I : Ideal R | I.IsMaximal} DiscreteTopology (PrimeSpectrum R) ↔ Finite s ∧ sInf s ≤ nilradical R := by rw [discreteTopology_iff_finite_and_krullDimLE_zero, Ring.krullDimLE_zero_iff, (equivSubtype R).finite_iff, ← Set.coe_setOf, Set.finite_coe_iff, Set.finite_coe_iff] refine ⟨fun h ↦ ⟨h.1.subset fun _ h ↦ h.isPrime, nilradical_eq_sInf R ▸ sInf_le_sInf h.2⟩, fun ⟨fin, le⟩ ↦ ?_⟩ have hpm (I : Ideal R) (hI : I.IsPrime): I.IsMaximal := by replace le := le.trans (nilradical_le_prime I) rw [← fin.coe_toFinset, ← Finset.inf_id_eq_sInf, hI.inf_le'] at le have ⟨M, hM, hMI⟩ := le rw [fin.mem_toFinset] at hM rwa [← hM.eq_of_le hI.1 hMI] exact ⟨fin.subset hpm, hpm⟩ theorem discreteTopology_of_toLocalization_surjective (surj : Function.Surjective (toPiLocalization R)) : DiscreteTopology (PrimeSpectrum R) := discreteTopology_iff_finite_and_krullDimLE_zero.mpr ⟨finite_of_toPiLocalization_surjective surj, .mk₀ fun I prime ↦ isMaximal_of_toPiLocalization_surjective surj ⟨I, prime⟩⟩ section Comap variable {S' : Type*} [CommSemiring S'] /-- The continuous function between prime spectra of commutative (semi)rings induced by a ring homomorphism. -/ def comap (f : R →+* S) : C(PrimeSpectrum S, PrimeSpectrum R) where toFun := f.specComap continuous_toFun := by simp only [continuous_iff_isClosed, isClosed_iff_zeroLocus] rintro _ ⟨s, rfl⟩ exact ⟨_, preimage_specComap_zeroLocus_aux f s⟩ lemma coe_comap (f : R →+* S) : comap f = f.specComap := rfl lemma comap_apply (f : R →+* S) (x) : comap f x = f.specComap x := rfl variable (f : R →+* S) @[simp] theorem comap_asIdeal (y : PrimeSpectrum S) : (comap f y).asIdeal = Ideal.comap f y.asIdeal := rfl @[simp] theorem comap_id : comap (RingHom.id R) = ContinuousMap.id _ := by ext rfl @[simp] theorem comap_comp (f : R →+* S) (g : S →+* S') : comap (g.comp f) = (comap f).comp (comap g) := rfl theorem comap_comp_apply (f : R →+* S) (g : S →+* S') (x : PrimeSpectrum S') : PrimeSpectrum.comap (g.comp f) x = (PrimeSpectrum.comap f) (PrimeSpectrum.comap g x) := rfl @[simp] theorem preimage_comap_zeroLocus (s : Set R) : comap f ⁻¹' zeroLocus s = zeroLocus (f '' s) := preimage_specComap_zeroLocus_aux f s theorem comap_injective_of_surjective (f : R →+* S) (hf : Function.Surjective f) : Function.Injective (comap f) := fun _ _ h => specComap_injective_of_surjective _ hf h variable (S) theorem localization_specComap_injective [Algebra R S] (M : Submonoid R) [IsLocalization M S] : Function.Injective (algebraMap R S).specComap := by intro p q h replace h := _root_.congr_arg (fun x : PrimeSpectrum R => Ideal.map (algebraMap R S) x.asIdeal) h dsimp only [RingHom.specComap] at h rw [IsLocalization.map_comap M S, IsLocalization.map_comap M S] at h ext1 exact h theorem localization_specComap_range [Algebra R S] (M : Submonoid R) [IsLocalization M S] : Set.range (algebraMap R S).specComap = { p | Disjoint (M : Set R) p.asIdeal } := by refine Set.ext fun x ↦ ⟨?_, fun h ↦ ?_⟩ · rintro ⟨p, rfl⟩ exact ((IsLocalization.isPrime_iff_isPrime_disjoint ..).mp p.2).2 · use ⟨x.asIdeal.map (algebraMap R S), IsLocalization.isPrime_of_isPrime_disjoint M S _ x.2 h⟩ ext1 exact IsLocalization.comap_map_of_isPrime_disjoint M S _ x.2 h theorem localization_comap_isInducing [Algebra R S] (M : Submonoid R) [IsLocalization M S] : IsInducing (comap (algebraMap R S)) := by refine ⟨TopologicalSpace.ext_isClosed fun Z ↦ ?_⟩ simp_rw [isClosed_induced_iff, isClosed_iff_zeroLocus, @eq_comm _ _ (zeroLocus _), exists_exists_eq_and, preimage_comap_zeroLocus] constructor · rintro ⟨s, rfl⟩ refine ⟨(Ideal.span s).comap (algebraMap R S), ?_⟩ rw [← zeroLocus_span, ← zeroLocus_span s, ← Ideal.map, IsLocalization.map_comap M S] · rintro ⟨s, rfl⟩ exact ⟨_, rfl⟩ theorem localization_comap_injective [Algebra R S] (M : Submonoid R) [IsLocalization M S] : Function.Injective (comap (algebraMap R S)) := fun _ _ h => localization_specComap_injective S M h theorem localization_comap_isEmbedding [Algebra R S] (M : Submonoid R) [IsLocalization M S] : IsEmbedding (comap (algebraMap R S)) := ⟨localization_comap_isInducing S M, localization_comap_injective S M⟩ theorem localization_comap_range [Algebra R S] (M : Submonoid R) [IsLocalization M S] : Set.range (comap (algebraMap R S)) = { p | Disjoint (M : Set R) p.asIdeal } := localization_specComap_range .. open Function RingHom theorem comap_isInducing_of_surjective (hf : Surjective f) : IsInducing (comap f) where eq_induced := by simp only [TopologicalSpace.ext_iff, ← isClosed_compl_iff, isClosed_iff_zeroLocus, isClosed_induced_iff] refine fun s => ⟨fun ⟨F, hF⟩ => ⟨zeroLocus (f ⁻¹' F), ⟨f ⁻¹' F, rfl⟩, by rw [preimage_comap_zeroLocus, Function.Surjective.image_preimage hf, hF]⟩, ?_⟩ rintro ⟨-, ⟨F, rfl⟩, hF⟩ exact ⟨f '' F, hF.symm.trans (preimage_comap_zeroLocus f F)⟩ /-- The embedding has closed range if the domain (and therefore the codomain) is a ring, see `PrimeSpectrum.isClosedEmbedding_comap_of_surjective`. On the other hand, `comap (Nat.castRingHom (ZMod 2))` does not have closed range. -/ theorem isEmbedding_comap_of_surjective (hf : Surjective f) : IsEmbedding (comap f) := (isEmbedding_iff _).2 ⟨comap_isInducing_of_surjective _ _ hf, comap_injective_of_surjective f hf⟩ end Comap /-- Homeomorphism between prime spectra induced by an isomorphism of semirings. -/ def homeomorphOfRingEquiv (e : R ≃+* S) : PrimeSpectrum R ≃ₜ PrimeSpectrum S where toFun := comap (e.symm : S →+* R) invFun := comap (e : R →+* S) left_inv _ := (comap_comp_apply ..).symm.trans (by simp) right_inv _ := (comap_comp_apply ..).symm.trans (by simp) lemma isHomeomorph_comap_of_bijective {f : R →+* S} (hf : Function.Bijective f) : IsHomeomorph (comap f) := (homeomorphOfRingEquiv (.ofBijective f hf)).symm.isHomeomorph end CommSemiring section SpecOfSurjective /-! The comap of a surjective ring homomorphism is a closed embedding between the prime spectra. -/ open Function RingHom variable [CommRing R] [CommRing S] variable (f : R →+* S) variable {R} theorem comap_singleton_isClosed_of_surjective (f : R →+* S) (hf : Function.Surjective f) (x : PrimeSpectrum S) (hx : IsClosed ({x} : Set (PrimeSpectrum S))) : IsClosed ({comap f x} : Set (PrimeSpectrum R)) := haveI : x.asIdeal.IsMaximal := (isClosed_singleton_iff_isMaximal x).1 hx (isClosed_singleton_iff_isMaximal _).2 (Ideal.comap_isMaximal_of_surjective f hf) theorem image_comap_zeroLocus_eq_zeroLocus_comap (hf : Surjective f) (I : Ideal S) : comap f '' zeroLocus I = zeroLocus (I.comap f) := image_specComap_zeroLocus_eq_zeroLocus_comap _ f hf I theorem range_comap_of_surjective (hf : Surjective f) : Set.range (comap f) = zeroLocus (ker f) := range_specComap_of_surjective _ f hf lemma comap_quotientMk_bijective_of_le_nilradical {I : Ideal R} (hle : I ≤ nilradical R) : Function.Bijective (comap <| Ideal.Quotient.mk I) := by refine ⟨comap_injective_of_surjective _ Ideal.Quotient.mk_surjective, ?_⟩ simpa [← Set.range_eq_univ, range_comap_of_surjective _ _ Ideal.Quotient.mk_surjective, zeroLocus_eq_univ_iff] theorem isClosed_range_comap_of_surjective (hf : Surjective f) : IsClosed (Set.range (comap f)) := by rw [range_comap_of_surjective _ f hf] exact isClosed_zeroLocus _ lemma isClosedEmbedding_comap_of_surjective (hf : Surjective f) : IsClosedEmbedding (comap f) where toIsInducing := comap_isInducing_of_surjective S f hf injective := comap_injective_of_surjective f hf isClosed_range := isClosed_range_comap_of_surjective S f hf end SpecOfSurjective section SpecProd variable {R S} [CommSemiring R] [CommSemiring S] lemma primeSpectrumProd_symm_inl (x) : (primeSpectrumProd R S).symm (.inl x) = comap (RingHom.fst R S) x := by ext; simp [Ideal.prod] lemma primeSpectrumProd_symm_inr (x) : (primeSpectrumProd R S).symm (.inr x) = comap (RingHom.snd R S) x := by ext; simp [Ideal.prod] lemma range_comap_fst : Set.range (comap (RingHom.fst R S)) = zeroLocus (RingHom.ker (RingHom.fst R S)) := by refine Set.ext fun p ↦ ⟨?_, fun h ↦ ?_⟩ · rintro ⟨I, hI, rfl⟩; exact Ideal.comap_mono bot_le obtain ⟨p, hp, eq⟩ | ⟨p, hp, eq⟩ := p.1.ideal_prod_prime.mp p.2 · exact ⟨⟨p, hp⟩, PrimeSpectrum.ext <| by simpa [Ideal.prod] using eq.symm⟩ · refine (hp.ne_top <| (Ideal.eq_top_iff_one _).mpr ?_).elim simpa [eq] using h (show (0, 1) ∈ RingHom.ker (RingHom.fst R S) by simp) lemma range_comap_snd : Set.range (comap (RingHom.snd R S)) = zeroLocus (RingHom.ker (RingHom.snd R S)) := by refine Set.ext fun p ↦ ⟨?_, fun h ↦ ?_⟩ · rintro ⟨I, hI, rfl⟩; exact Ideal.comap_mono bot_le obtain ⟨p, hp, eq⟩ | ⟨p, hp, eq⟩ := p.1.ideal_prod_prime.mp p.2 · refine (hp.ne_top <| (Ideal.eq_top_iff_one _).mpr ?_).elim simpa [eq] using h (show (1, 0) ∈ RingHom.ker (RingHom.snd R S) by simp) · exact ⟨⟨p, hp⟩, PrimeSpectrum.ext <| by simpa [Ideal.prod] using eq.symm⟩ lemma isClosedEmbedding_comap_fst : IsClosedEmbedding (comap (RingHom.fst R S)) := (isClosedEmbedding_iff _).mpr ⟨isEmbedding_comap_of_surjective _ _ Prod.fst_surjective, by simp_rw [range_comap_fst, isClosed_zeroLocus]⟩ lemma isClosedEmbedding_comap_snd : IsClosedEmbedding (comap (RingHom.snd R S)) := (isClosedEmbedding_iff _).mpr ⟨isEmbedding_comap_of_surjective _ _ Prod.snd_surjective, by simp_rw [range_comap_snd, isClosed_zeroLocus]⟩ /-- The prime spectrum of `R × S` is homeomorphic to the disjoint union of `PrimeSpectrum R` and `PrimeSpectrum S`. -/ noncomputable def primeSpectrumProdHomeo : PrimeSpectrum (R × S) ≃ₜ PrimeSpectrum R ⊕ PrimeSpectrum S := by refine ((primeSpectrumProd R S).symm.toHomeomorphOfIsInducing ?_).symm refine (IsClosedEmbedding.of_continuous_injective_isClosedMap ?_ (Equiv.injective _) ?_).isInducing · rw [continuous_sum_dom] simp only [Function.comp_def, primeSpectrumProd_symm_inl, primeSpectrumProd_symm_inr] exact ⟨(comap _).2, (comap _).2⟩ · simp_rw [isClosedMap_sum, primeSpectrumProd_symm_inl, primeSpectrumProd_symm_inr] exact ⟨isClosedEmbedding_comap_fst.isClosedMap, isClosedEmbedding_comap_snd.isClosedMap⟩ end SpecProd section CommSemiring variable [CommSemiring R] [CommSemiring S] variable {R S} section BasicOpen /-- `basicOpen r` is the open subset containing all prime ideals not containing `r`. -/ def basicOpen (r : R) : TopologicalSpace.Opens (PrimeSpectrum R) where carrier := { x | r ∉ x.asIdeal } is_open' := ⟨{r}, Set.ext fun _ => Set.singleton_subset_iff.trans <| Classical.not_not.symm⟩ @[simp] theorem mem_basicOpen (f : R) (x : PrimeSpectrum R) : x ∈ basicOpen f ↔ f ∉ x.asIdeal := Iff.rfl theorem isOpen_basicOpen {a : R} : IsOpen (basicOpen a : Set (PrimeSpectrum R)) := (basicOpen a).isOpen @[simp] theorem basicOpen_eq_zeroLocus_compl (r : R) : (basicOpen r : Set (PrimeSpectrum R)) = (zeroLocus {r})ᶜ := Set.ext fun x => by simp only [SetLike.mem_coe, mem_basicOpen, Set.mem_compl_iff, mem_zeroLocus, Set.singleton_subset_iff] @[simp] theorem basicOpen_one : basicOpen (1 : R) = ⊤ := TopologicalSpace.Opens.ext <| by simp @[simp] theorem basicOpen_zero : basicOpen (0 : R) = ⊥ := TopologicalSpace.Opens.ext <| by simp theorem basicOpen_le_basicOpen_iff (f g : R) : basicOpen f ≤ basicOpen g ↔ f ∈ (Ideal.span ({g} : Set R)).radical := by rw [← SetLike.coe_subset_coe, basicOpen_eq_zeroLocus_compl, basicOpen_eq_zeroLocus_compl, Set.compl_subset_compl, zeroLocus_subset_zeroLocus_singleton_iff] theorem basicOpen_le_basicOpen_iff_algebraMap_isUnit {f g : R} [Algebra R S] [IsLocalization.Away f S] : basicOpen f ≤ basicOpen g ↔ IsUnit (algebraMap R S g) := by simp_rw [basicOpen_le_basicOpen_iff, Ideal.mem_radical_iff, Ideal.mem_span_singleton, IsLocalization.Away.algebraMap_isUnit_iff f] theorem basicOpen_mul (f g : R) : basicOpen (f * g) = basicOpen f ⊓ basicOpen g := TopologicalSpace.Opens.ext <| by simp [zeroLocus_singleton_mul] theorem basicOpen_mul_le_left (f g : R) : basicOpen (f * g) ≤ basicOpen f := by rw [basicOpen_mul f g] exact inf_le_left theorem basicOpen_mul_le_right (f g : R) : basicOpen (f * g) ≤ basicOpen g := by rw [basicOpen_mul f g] exact inf_le_right @[simp] theorem basicOpen_pow (f : R) (n : ℕ) (hn : 0 < n) : basicOpen (f ^ n) = basicOpen f := TopologicalSpace.Opens.ext <| by simpa using zeroLocus_singleton_pow f n hn theorem isTopologicalBasis_basic_opens : TopologicalSpace.IsTopologicalBasis (Set.range fun r : R => (basicOpen r : Set (PrimeSpectrum R))) := by apply TopologicalSpace.isTopologicalBasis_of_isOpen_of_nhds · rintro _ ⟨r, rfl⟩ exact isOpen_basicOpen · rintro p U hp ⟨s, hs⟩ rw [← compl_compl U, Set.mem_compl_iff, ← hs, mem_zeroLocus, Set.not_subset] at hp obtain ⟨f, hfs, hfp⟩ := hp refine ⟨basicOpen f, ⟨f, rfl⟩, hfp, ?_⟩ rw [← Set.compl_subset_compl, ← hs, basicOpen_eq_zeroLocus_compl, compl_compl] exact zeroLocus_anti_mono (Set.singleton_subset_iff.mpr hfs) theorem eq_biUnion_of_isOpen {s : Set (PrimeSpectrum R)} (hs : IsOpen s) : s = ⋃ (r : R) (_ : ↑(basicOpen r) ⊆ s), basicOpen r := (isTopologicalBasis_basic_opens.open_eq_sUnion' hs).trans <| by aesop theorem isBasis_basic_opens : TopologicalSpace.Opens.IsBasis (Set.range (@basicOpen R _)) := by unfold TopologicalSpace.Opens.IsBasis convert isTopologicalBasis_basic_opens (R := R) rw [← Set.range_comp] rfl @[simp] theorem basicOpen_eq_bot_iff (f : R) : basicOpen f = ⊥ ↔ IsNilpotent f := by rw [← TopologicalSpace.Opens.coe_inj, basicOpen_eq_zeroLocus_compl] simp only [Set.eq_univ_iff_forall, Set.singleton_subset_iff, TopologicalSpace.Opens.coe_bot, nilpotent_iff_mem_prime, Set.compl_empty_iff, mem_zeroLocus, SetLike.mem_coe] exact ⟨fun h I hI => h ⟨I, hI⟩, fun h ⟨I, hI⟩ => h I hI⟩ theorem localization_away_comap_range (S : Type v) [CommSemiring S] [Algebra R S] (r : R) [IsLocalization.Away r S] : Set.range (comap (algebraMap R S)) = basicOpen r := by rw [localization_comap_range S (Submonoid.powers r)] ext x simp only [mem_zeroLocus, basicOpen_eq_zeroLocus_compl, SetLike.mem_coe, Set.mem_setOf_eq, Set.singleton_subset_iff, Set.mem_compl_iff, disjoint_iff_inf_le] constructor · intro h₁ h₂ exact h₁ ⟨Submonoid.mem_powers r, h₂⟩ · rintro h₁ _ ⟨⟨n, rfl⟩, h₃⟩ exact h₁ (x.2.mem_of_pow_mem _ h₃) theorem localization_away_isOpenEmbedding (S : Type v) [CommSemiring S] [Algebra R S] (r : R) [IsLocalization.Away r S] : IsOpenEmbedding (comap (algebraMap R S)) where toIsEmbedding := localization_comap_isEmbedding S (Submonoid.powers r) isOpen_range := by rw [localization_away_comap_range S r] exact isOpen_basicOpen theorem isCompact_basicOpen (f : R) : IsCompact (basicOpen f : Set (PrimeSpectrum R)) := by rw [← localization_away_comap_range (Localization (Submonoid.powers f))] exact isCompact_range (map_continuous _) lemma comap_basicOpen (f : R →+* S) (x : R) : TopologicalSpace.Opens.comap (comap f) (basicOpen x) = basicOpen (f x) := rfl open TopologicalSpace in lemma iSup_basicOpen_eq_top_iff {ι : Type*} {f : ι → R} : (⨆ i : ι, PrimeSpectrum.basicOpen (f i)) = ⊤ ↔ Ideal.span (Set.range f) = ⊤ := by rw [SetLike.ext'_iff, Opens.coe_iSup] simp only [PrimeSpectrum.basicOpen_eq_zeroLocus_compl, Opens.coe_top, ← Set.compl_iInter, ← PrimeSpectrum.zeroLocus_iUnion] rw [← PrimeSpectrum.zeroLocus_empty_iff_eq_top, compl_involutive.eq_iff] simp only [Set.iUnion_singleton_eq_range, Set.compl_univ, PrimeSpectrum.zeroLocus_span] lemma iSup_basicOpen_eq_top_iff' {s : Set R} : (⨆ i ∈ s, PrimeSpectrum.basicOpen i) = ⊤ ↔ Ideal.span s = ⊤ := by conv_rhs => rw [← Subtype.range_val (s := s), ← iSup_basicOpen_eq_top_iff] simp theorem isLocalization_away_iff_atPrime_of_basicOpen_eq_singleton [Algebra R S] {f : R} {p : PrimeSpectrum R} (h : (basicOpen f).1 = {p}) : IsLocalization.Away f S ↔ IsLocalization.AtPrime S p.1 := have : IsLocalization.AtPrime (Localization.Away f) p.1 := by refine .of_le_of_exists_dvd (.powers f) _ (Submonoid.powers_le.mpr <| by apply h ▸ Set.mem_singleton p) fun r hr ↦ ?_ contrapose! hr simp_rw [← Ideal.mem_span_singleton] at hr have ⟨q, prime, le, disj⟩ := Ideal.exists_le_prime_disjoint (Ideal.span {r}) (.powers f) (Set.disjoint_right.mpr hr) have : ⟨q, prime⟩ ∈ (basicOpen f).1 := Set.disjoint_right.mp disj (Submonoid.mem_powers f) rw [h, Set.mem_singleton_iff] at this rw [← this] exact not_not.mpr (q.span_singleton_le_iff_mem.mp le) IsLocalization.isLocalization_iff_of_isLocalization _ _ (Localization.Away f) open Localization Polynomial Set in lemma range_comap_algebraMap_localization_compl_eq_range_comap_quotientMk {R : Type*} [CommRing R] (c : R) : letI := (mapRingHom (algebraMap R (Away c))).toAlgebra (range (comap (algebraMap R[X] (Away c)[X])))ᶜ = range (comap (mapRingHom (Ideal.Quotient.mk (.span {c})))) := by letI := (mapRingHom (algebraMap R (Away c))).toAlgebra have := Polynomial.isLocalization (.powers c) (Away c) rw [Submonoid.map_powers] at this have surj : Function.Surjective (mapRingHom (Ideal.Quotient.mk (.span {c}))) := Polynomial.map_surjective _ Ideal.Quotient.mk_surjective rw [range_comap_of_surjective _ _ surj, localization_away_comap_range _ (C c)] simp [Polynomial.ker_mapRingHom, Ideal.map_span] instance : QuasiSeparatedSpace (PrimeSpectrum R) := .of_isTopologicalBasis isTopologicalBasis_basic_opens fun i j ↦ by simpa [← TopologicalSpace.Opens.coe_inf, ← basicOpen_mul, -basicOpen_eq_zeroLocus_compl] using isCompact_basicOpen _ end BasicOpen section DiscreteTopology variable (R) [DiscreteTopology (PrimeSpectrum R)] theorem toPiLocalization_surjective_of_discreteTopology : Function.Surjective (toPiLocalization R) := fun x ↦ by have (p : PrimeSpectrum R) : ∃ f, (basicOpen f : Set _) = {p} := have ⟨_, ⟨f, rfl⟩, hpf, hfp⟩ := isTopologicalBasis_basic_opens.isOpen_iff.mp (isOpen_discrete {p}) p rfl ⟨f, hfp.antisymm <| Set.singleton_subset_iff.mpr hpf⟩ choose f hf using this let e := Equiv.ofInjective f fun p q eq ↦ Set.singleton_injective (hf p ▸ eq ▸ hf q) have loc a : IsLocalization.AtPrime (Localization.Away a.1) (e.symm a).1 := (isLocalization_away_iff_atPrime_of_basicOpen_eq_singleton <| hf _).mp <| by simp_rw [e, Equiv.apply_ofInjective_symm]; infer_instance let algE a := IsLocalization.algEquiv (e.symm a).1.primeCompl (Localization.AtPrime (e.symm a).1) (Localization.Away a.1) have span_eq : Ideal.span (Set.range f) = ⊤ := iSup_basicOpen_eq_top_iff.mp <| top_unique fun p _ ↦ TopologicalSpace.Opens.mem_iSup.mpr ⟨p, (hf p).ge rfl⟩ replace hf a : (basicOpen a.1 : Set _) = {e.symm a} := by simp_rw [e, ← hf, Equiv.apply_ofInjective_symm] obtain ⟨r, eq, -⟩ := Localization.existsUnique_algebraMap_eq_of_span_eq_top _ span_eq (fun a ↦ algE a (x _)) fun a b ↦ by obtain rfl | ne := eq_or_ne a b; · rfl have nil : IsNilpotent (a * b : R) := (basicOpen_eq_bot_iff _).mp <| by simp_rw [basicOpen_mul, SetLike.ext'_iff, TopologicalSpace.Opens.coe_inf, hf] exact bot_unique (fun _ ⟨ha, hb⟩ ↦ ne <| e.symm.injective (ha.symm.trans hb)) apply (IsLocalization.subsingleton (M := .powers (a * b : R)) nil).elim refine ⟨r, funext fun I ↦ ?_⟩ have := eq (e I) rwa [← AlgEquiv.symm_apply_eq, AlgEquiv.commutes, e.symm_apply_apply] at this theorem maximalSpectrumToPiLocalization_surjective_of_discreteTopology : Function.Surjective (MaximalSpectrum.toPiLocalization R) := by rw [← piLocalizationToMaximal_comp_toPiLocalization] exact (piLocalizationToMaximal_surjective R).comp (toPiLocalization_surjective_of_discreteTopology R) /-- If the prime spectrum of a commutative semiring R has discrete Zariski topology, then R is canonically isomorphic to the product of its localizations at the (finitely many) maximal ideals. -/ @[stacks 00JA "See also `PrimeSpectrum.discreteTopology_iff_finite_isMaximal_and_sInf_le_nilradical`."] def _root_.MaximalSpectrum.toPiLocalizationEquiv : R ≃+* MaximalSpectrum.PiLocalization R := .ofBijective _ ⟨MaximalSpectrum.toPiLocalization_injective R, maximalSpectrumToPiLocalization_surjective_of_discreteTopology R⟩ theorem discreteTopology_iff_toPiLocalization_surjective {R} [CommSemiring R] : DiscreteTopology (PrimeSpectrum R) ↔ Function.Surjective (toPiLocalization R) := ⟨fun _ ↦ toPiLocalization_surjective_of_discreteTopology _, discreteTopology_of_toLocalization_surjective⟩ theorem discreteTopology_iff_toPiLocalization_bijective {R} [CommSemiring R] : DiscreteTopology (PrimeSpectrum R) ↔ Function.Bijective (toPiLocalization R) := discreteTopology_iff_toPiLocalization_surjective.trans (and_iff_right <| toPiLocalization_injective _).symm end DiscreteTopology section Order /-! ## The specialization order We endow `PrimeSpectrum R` with a partial order, where `x ≤ y` if and only if `y ∈ closure {x}`. -/ theorem le_iff_mem_closure (x y : PrimeSpectrum R) : x ≤ y ↔ y ∈ closure ({x} : Set (PrimeSpectrum R)) := by rw [← asIdeal_le_asIdeal, ← zeroLocus_vanishingIdeal_eq_closure, mem_zeroLocus, vanishingIdeal_singleton, SetLike.coe_subset_coe] theorem le_iff_specializes (x y : PrimeSpectrum R) : x ≤ y ↔ x ⤳ y := (le_iff_mem_closure x y).trans specializes_iff_mem_closure.symm /-- `nhds` as an order embedding. -/ @[simps!] def nhdsOrderEmbedding : PrimeSpectrum R ↪o Filter (PrimeSpectrum R) := OrderEmbedding.ofMapLEIff nhds fun a b => (le_iff_specializes a b).symm instance : T0Space (PrimeSpectrum R) := ⟨nhdsOrderEmbedding.inj'⟩ instance : PrespectralSpace (PrimeSpectrum R) := .of_isTopologicalBasis' isTopologicalBasis_basic_opens isCompact_basicOpen instance : SpectralSpace (PrimeSpectrum R) where end Order /-- If `x` specializes to `y`, then there is a natural map from the localization of `y` to the localization of `x`. -/ def localizationMapOfSpecializes {x y : PrimeSpectrum R} (h : x ⤳ y) : Localization.AtPrime y.asIdeal →+* Localization.AtPrime x.asIdeal := @IsLocalization.lift _ _ _ _ _ _ _ _ Localization.isLocalization (algebraMap R (Localization.AtPrime x.asIdeal)) (by rintro ⟨a, ha⟩ rw [← PrimeSpectrum.le_iff_specializes, ← asIdeal_le_asIdeal, ← SetLike.coe_subset_coe, ← Set.compl_subset_compl] at h exact (IsLocalization.map_units (Localization.AtPrime x.asIdeal) ⟨a, show a ∈ x.asIdeal.primeCompl from h ha⟩ :)) section stableUnderSpecialization variable {R S : Type*} [CommSemiring R] [CommSemiring S] (f : R →+* S) lemma isClosed_image_of_stableUnderSpecialization (Z : Set (PrimeSpectrum S)) (hZ : IsClosed Z) (hf : StableUnderSpecialization (comap f '' Z)) : IsClosed (comap f '' Z) := by obtain ⟨I, rfl⟩ := (PrimeSpectrum.isClosed_iff_zeroLocus_ideal Z).mp hZ refine (isClosed_iff_zeroLocus _).mpr ⟨I.comap f, le_antisymm ?_ fun p hp ↦ ?_⟩ · rintro _ ⟨q, hq, rfl⟩ exact Ideal.comap_mono hq · obtain ⟨q, hqI, hq, hqle⟩ := p.asIdeal.exists_ideal_comap_le_prime I hp exact hf ((le_iff_specializes ⟨q.comap f, inferInstance⟩ p).mp hqle) ⟨⟨q, hq⟩, hqI, rfl⟩ @[stacks 00HY] lemma isClosed_range_of_stableUnderSpecialization (hf : StableUnderSpecialization (Set.range (comap f))) : IsClosed (Set.range (comap f)) := by rw [← Set.image_univ] at hf ⊢ exact isClosed_image_of_stableUnderSpecialization _ _ isClosed_univ hf variable {f} in @[stacks 00HY] lemma stableUnderSpecialization_range_iff : StableUnderSpecialization (Set.range (comap f)) ↔ IsClosed (Set.range (comap f)) := ⟨isClosed_range_of_stableUnderSpecialization f, fun h ↦ h.stableUnderSpecialization⟩ lemma stableUnderSpecialization_image_iff (Z : Set (PrimeSpectrum S)) (hZ : IsClosed Z) : StableUnderSpecialization (comap f '' Z) ↔ IsClosed (comap f '' Z) := ⟨isClosed_image_of_stableUnderSpecialization f Z hZ, fun h ↦ h.stableUnderSpecialization⟩ end stableUnderSpecialization section IsQuotientMap variable {R S : Type*} [CommSemiring R] [CommSemiring S] {f : R →+* S} (h₁ : Function.Surjective (comap f)) include h₁ /-- If `f : Spec S → Spec R` is specializing and surjective, the topology on `Spec R` is the quotient topology induced by `f`. -/ lemma isQuotientMap_of_specializingMap (h₂ : SpecializingMap (comap f)) : Topology.IsQuotientMap (comap f) := by rw [Topology.isQuotientMap_iff_isClosed] exact ⟨h₁, fun s ↦ ⟨fun hs ↦ hs.preimage (comap f).continuous, fun hsc ↦ Set.image_preimage_eq s h₁ ▸ isClosed_image_of_stableUnderSpecialization _ _ hsc (h₂.stableUnderSpecialization_image hsc.stableUnderSpecialization)⟩⟩ /-- If `f : Spec S → Spec R` is generalizing and surjective, the topology on `Spec R` is the quotient topology induced by `f`. -/ lemma isQuotientMap_of_generalizingMap (h₂ : GeneralizingMap (comap f)) : Topology.IsQuotientMap (comap f) := by rw [Topology.isQuotientMap_iff_isClosed] refine ⟨h₁, fun s ↦ ⟨fun hs ↦ hs.preimage (comap f).continuous, fun hsc ↦ Set.image_preimage_eq s h₁ ▸ ?_⟩⟩ apply isClosed_image_of_stableUnderSpecialization _ _ hsc rw [Set.image_preimage_eq s h₁, ← stableUnderGeneralization_compl_iff] convert h₂.stableUnderGeneralization_image hsc.isOpen_compl.stableUnderGeneralization rw [← Set.preimage_compl, Set.image_preimage_eq _ h₁] end IsQuotientMap section denseRange variable {R S : Type*} [CommSemiring R] [CommSemiring S] (f : R →+* S) lemma vanishingIdeal_range_comap : vanishingIdeal (Set.range (comap f)) = (RingHom.ker f).radical := by ext x rw [RingHom.ker_eq_comap_bot, ← Ideal.comap_radical, Ideal.radical_eq_sInf] simp only [mem_vanishingIdeal, Set.mem_range, forall_exists_index, forall_apply_eq_imp_iff, comap_asIdeal, Ideal.mem_comap, bot_le, true_and, Submodule.mem_sInf, Set.mem_setOf_eq] exact ⟨fun H I hI ↦ H ⟨I, hI⟩, fun H I ↦ H I.1 I.2⟩ lemma closure_range_comap : closure (Set.range (comap f)) = zeroLocus (RingHom.ker f) := by rw [← zeroLocus_vanishingIdeal_eq_closure, vanishingIdeal_range_comap, zeroLocus_radical] lemma denseRange_comap_iff_ker_le_nilRadical : DenseRange (comap f) ↔ RingHom.ker f ≤ nilradical R := by rw [denseRange_iff_closure_range, closure_range_comap, zeroLocus_eq_univ_iff, SetLike.coe_subset_coe] @[stacks 00FL] lemma denseRange_comap_iff_minimalPrimes : DenseRange (comap f) ↔ ∀ I (h : I ∈ minimalPrimes R), ⟨I, h.1.1⟩ ∈ Set.range (comap f) := by constructor · intro H I hI have : I ∈ (RingHom.ker f).minimalPrimes := by rw [denseRange_comap_iff_ker_le_nilRadical] at H simp only [minimalPrimes, Ideal.minimalPrimes, Set.mem_setOf] at hI ⊢ convert hI using 2 with p exact ⟨fun h ↦ ⟨h.1, bot_le⟩, fun h ↦ ⟨h.1, H.trans (h.1.radical_le_iff.mpr bot_le)⟩⟩ obtain ⟨p, hp, _, rfl⟩ := Ideal.exists_comap_eq_of_mem_minimalPrimes f (I := ⊥) I this exact ⟨⟨p, hp⟩, rfl⟩ · intro H p obtain ⟨q, hq, hq'⟩ := Ideal.exists_minimalPrimes_le (J := p.asIdeal) bot_le exact ((le_iff_specializes ⟨q, hq.1.1⟩ p).mp hq').mem_closed isClosed_closure (subset_closure (H q hq)) end denseRange variable (R) in /-- Zero loci of prime ideals are closed irreducible sets in the Zariski topology and any closed irreducible set is a zero locus of some prime ideal. -/ protected def pointsEquivIrreducibleCloseds : PrimeSpectrum R ≃o (TopologicalSpace.IrreducibleCloseds (PrimeSpectrum R))ᵒᵈ where __ := irreducibleSetEquivPoints.toEquiv.symm.trans OrderDual.toDual map_rel_iff' {p q} := (RelIso.symm irreducibleSetEquivPoints).map_rel_iff.trans (le_iff_specializes p q).symm lemma stableUnderSpecialization_singleton {x : PrimeSpectrum R} : StableUnderSpecialization {x} ↔ x.asIdeal.IsMaximal := by simp_rw [← isMax_iff, StableUnderSpecialization, ← le_iff_specializes, Set.mem_singleton_iff, @forall_comm _ (_ = _), forall_eq] exact ⟨fun H a h ↦ (H a h).le, fun H a h ↦ le_antisymm (H h) h⟩ lemma stableUnderGeneralization_singleton {x : PrimeSpectrum R} : StableUnderGeneralization {x} ↔ x.asIdeal ∈ minimalPrimes R := by simp_rw [← isMin_iff, StableUnderGeneralization, ← le_iff_specializes, Set.mem_singleton_iff, @forall_comm _ (_ = _), forall_eq] exact ⟨fun H a h ↦ (H a h).ge, fun H a h ↦ le_antisymm h (H h)⟩ lemma isCompact_isOpen_iff {s : Set (PrimeSpectrum R)} : IsCompact s ∧ IsOpen s ↔ ∃ t : Finset R, (zeroLocus t)ᶜ = s := by rw [isCompact_open_iff_eq_finite_iUnion_of_isTopologicalBasis _ isTopologicalBasis_basic_opens isCompact_basicOpen] simp only [basicOpen_eq_zeroLocus_compl, ← Set.compl_iInter₂, ← zeroLocus_iUnion₂, Set.biUnion_of_singleton] exact ⟨fun ⟨s, hs, e⟩ ↦ ⟨hs.toFinset, by simpa using e.symm⟩, fun ⟨s, e⟩ ↦ ⟨s, s.finite_toSet, by simpa using e.symm⟩⟩ lemma isCompact_isOpen_iff_ideal {s : Set (PrimeSpectrum R)} : IsCompact s ∧ IsOpen s ↔ ∃ I : Ideal R, I.FG ∧ (zeroLocus I)ᶜ = s := by rw [isCompact_isOpen_iff] exact ⟨fun ⟨s, e⟩ ↦ ⟨.span s, ⟨s, rfl⟩, by simpa using e⟩, fun ⟨I, ⟨s, hs⟩, e⟩ ↦ ⟨s, by simpa [hs.symm] using e⟩⟩ lemma basicOpen_eq_zeroLocus_of_mul_add (e f : R) (mul : e * f = 0) (add : e + f = 1) : basicOpen e = zeroLocus {f} := by ext p suffices e ∉ p.asIdeal ↔ f ∈ p.asIdeal by simpa refine ⟨(p.2.mem_or_mem_of_mul_eq_zero mul).resolve_left, fun h₁ h₂ ↦ p.2.1 ?_⟩ rw [Ideal.eq_top_iff_one, ← add] exact add_mem h₂ h₁ lemma zeroLocus_eq_basicOpen_of_mul_add (e f : R) (mul : e * f = 0) (add : e + f = 1) : zeroLocus {e} = basicOpen f := by rw [basicOpen_eq_zeroLocus_of_mul_add f e] <;> simp only [mul, add, mul_comm, add_comm] lemma isClopen_basicOpen_of_mul_add (e f : R) (mul : e * f = 0) (add : e + f = 1) : IsClopen (basicOpen e : Set (PrimeSpectrum R)) := ⟨basicOpen_eq_zeroLocus_of_mul_add e f mul add ▸ isClosed_zeroLocus _, (basicOpen e).2⟩ lemma basicOpen_injOn_isIdempotentElem : {e : R | IsIdempotentElem e}.InjOn basicOpen := fun x hx y hy eq ↦ by by_contra! ne wlog ne' : x * y ≠ x generalizing x y · apply this y hy x hx eq.symm ne.symm rwa [mul_comm, of_not_not ne'] have : x ∉ Ideal.span {y} := fun mem ↦ ne' <| by obtain ⟨r, rfl⟩ := Ideal.mem_span_singleton'.mp mem rw [mul_assoc, hy] have ⟨p, prime, le, notMem⟩ := Ideal.exists_le_prime_notMem_of_isIdempotentElem _ x hx this exact ne_of_mem_of_not_mem' (a := ⟨p, prime⟩) notMem (not_not.mpr <| p.span_singleton_le_iff_mem.mp le) eq lemma exists_mul_eq_zero_add_eq_one_basicOpen_eq_of_isClopen {s : Set (PrimeSpectrum R)} (hs : IsClopen s) : ∃ e f : R, e * f = 0 ∧ e + f = 1 ∧ s = basicOpen e ∧ sᶜ = basicOpen f := by cases subsingleton_or_nontrivial R · refine ⟨0, 0, ?_, ?_, ?_, ?_⟩ <;> apply Subsingleton.elim obtain ⟨I, hI, hI'⟩ := isCompact_isOpen_iff_ideal.mp ⟨hs.1.isCompact, hs.2⟩ obtain ⟨J, hJ, hJ'⟩ := isCompact_isOpen_iff_ideal.mp ⟨hs.2.isClosed_compl.isCompact, hs.1.isOpen_compl⟩ simp only [compl_eq_iff_isCompl, ← eq_compl_iff_isCompl, compl_compl] at hI' hJ' have : I * J ≤ nilradical R := by refine Ideal.radical_le_radical_iff.mp (le_of_eq ?_) rw [← zeroLocus_eq_iff, Ideal.zero_eq_bot, zeroLocus_bot, zeroLocus_mul, hI', hJ', Set.compl_union_self] obtain ⟨n, hn⟩ := Ideal.exists_pow_le_of_le_radical_of_fg this (Submodule.FG.mul hI hJ) have hnz : n ≠ 0 := by rintro rfl; simp at hn rw [mul_pow, Ideal.zero_eq_bot] at hn have : I ^ n ⊔ J ^ n = ⊤ := by rw [eq_top_iff, ← Ideal.span_pow_eq_top (I ∪ J : Set R) _ n, Ideal.span_le, Set.image_union, Set.union_subset_iff] constructor · rintro _ ⟨x, hx, rfl⟩; exact Ideal.mem_sup_left (Ideal.pow_mem_pow hx n) · rintro _ ⟨x, hx, rfl⟩; exact Ideal.mem_sup_right (Ideal.pow_mem_pow hx n) · rw [Ideal.span_union, Ideal.span_eq, Ideal.span_eq, ← zeroLocus_empty_iff_eq_top, zeroLocus_sup, hI', hJ', Set.compl_inter_self] rw [Ideal.eq_top_iff_one, Submodule.mem_sup] at this obtain ⟨x, hx, y, hy, add⟩ := this have mul : x * y = 0 := hn (Ideal.mul_mem_mul hx hy) have : s = basicOpen x := by refine subset_antisymm ?_ ?_ · rw [← hJ', basicOpen_eq_zeroLocus_of_mul_add _ _ mul add] exact zeroLocus_anti_mono (Set.singleton_subset_iff.mpr <| Ideal.pow_le_self hnz hy) · rw [basicOpen_eq_zeroLocus_compl, Set.compl_subset_comm, ← hI'] exact zeroLocus_anti_mono (Set.singleton_subset_iff.mpr <| Ideal.pow_le_self hnz hx) refine ⟨x, y, mul, add, this, ?_⟩ rw [this, basicOpen_eq_zeroLocus_of_mul_add _ _ mul add, basicOpen_eq_zeroLocus_compl] lemma exists_idempotent_basicOpen_eq_of_isClopen {s : Set (PrimeSpectrum R)} (hs : IsClopen s) : ∃ e : R, IsIdempotentElem e ∧ s = basicOpen e := have ⟨e, _, mul, add, eq, _⟩ := exists_mul_eq_zero_add_eq_one_basicOpen_eq_of_isClopen hs ⟨e, (IsIdempotentElem.of_mul_add mul add).1, eq⟩ @[stacks 00EE] lemma existsUnique_idempotent_basicOpen_eq_of_isClopen {s : Set (PrimeSpectrum R)} (hs : IsClopen s) : ∃! e : R, IsIdempotentElem e ∧ s = basicOpen e := by refine existsUnique_of_exists_of_unique (exists_idempotent_basicOpen_eq_of_isClopen hs) ?_ rintro x y ⟨hx, rfl⟩ ⟨hy, eq⟩ exact basicOpen_injOn_isIdempotentElem hx hy (SetLike.ext' eq) open TopologicalSpace.Opens in lemma isClopen_iff_mul_add {s : Set (PrimeSpectrum R)} : IsClopen s ↔ ∃ e f : R, e * f = 0 ∧ e + f = 1 ∧ s = basicOpen e := by refine ⟨fun h ↦ ?_, ?_⟩ · have ⟨e, f, h⟩ := exists_mul_eq_zero_add_eq_one_basicOpen_eq_of_isClopen h exact ⟨e, f, by simp only [h, and_self]⟩ rintro ⟨e, f, mul, add, rfl⟩ exact isClopen_basicOpen_of_mul_add e f mul add lemma isClopen_iff_mul_add_zeroLocus {s : Set (PrimeSpectrum R)} : IsClopen s ↔ ∃ e f : R, e * f = 0 ∧ e + f = 1 ∧ s = zeroLocus {e} := by rw [isClopen_iff_mul_add, exists_swap] refine exists₂_congr fun e f ↦ ?_ rw [mul_comm, add_comm, ← and_assoc, ← and_assoc, and_congr_right] intro ⟨mul, add⟩ rw [zeroLocus_eq_basicOpen_of_mul_add e f mul add] open TopologicalSpace (Clopens) /-- Clopen subsets in the prime spectrum of a commutative semiring are in order-preserving bijection with pairs of elements with product 0 and sum 1. (By definition, `(e₁, f₁) ≤ (e₂, f₂)` iff `e₁ * e₂ = e₁`.) Both elements in such pairs must be idempotents, but there may exists idempotents that do not form such pairs (does not have a "complement"). For example, in the semiring {0, 0.5, 1} with ⊔ as + and ⊓ as *, 0.5 has no complement. -/ def mulZeroAddOneEquivClopens : {e : R × R // e.1 * e.2 = 0 ∧ e.1 + e.2 = 1} ≃o Clopens (PrimeSpectrum R) where toEquiv := .ofBijective (fun e ↦ ⟨basicOpen e.1.1, isClopen_iff_mul_add.mpr ⟨_, _, e.2.1, e.2.2, rfl⟩⟩) <| by refine ⟨fun ⟨x, hx⟩ ⟨y, hy⟩ eq ↦ mul_eq_zero_add_eq_one_ext_left ?_, fun s ↦ ?_⟩ · exact basicOpen_injOn_isIdempotentElem (IsIdempotentElem.of_mul_add hx.1 hx.2).1 (IsIdempotentElem.of_mul_add hy.1 hy.2).1 <| SetLike.ext' (congr_arg (·.1) eq) · have ⟨e, f, mul, add, eq⟩ := isClopen_iff_mul_add.mp s.2 exact ⟨⟨(e, f), mul, add⟩, SetLike.ext' eq.symm⟩ map_rel_iff' {a b} := show basicOpen _ ≤ basicOpen _ ↔ _ by rw [← inf_eq_left, ← basicOpen_mul] refine ⟨fun h ↦ ?_, (by rw [·])⟩ rw [← inf_eq_left] have := (IsIdempotentElem.of_mul_add a.2.1 a.2.2).1 exact mul_eq_zero_add_eq_one_ext_left (basicOpen_injOn_isIdempotentElem (this.mul (IsIdempotentElem.of_mul_add b.2.1 b.2.2).1) this h) lemma isRetrocompact_zeroLocus_compl {s : Set R} (hs : s.Finite) : IsRetrocompact (zeroLocus s)ᶜ := (QuasiSeparatedSpace.isRetrocompact_iff_isCompact (isClosed_zeroLocus _).isOpen_compl).mpr (isCompact_isOpen_iff.mpr ⟨hs.toFinset, by simp⟩).1 lemma isRetrocompact_zeroLocus_compl_of_fg {I : Ideal R} (hI : I.FG) : IsRetrocompact (zeroLocus (I : Set R))ᶜ := by obtain ⟨s, rfl⟩ := hI rw [zeroLocus_span] exact isRetrocompact_zeroLocus_compl s.finite_toSet lemma isRetrocompact_basicOpen {f : R} : IsRetrocompact (basicOpen f : Set (PrimeSpectrum R)) := by simpa using isRetrocompact_zeroLocus_compl (Set.finite_singleton f) lemma isConstructible_basicOpen {f : R} : IsConstructible (basicOpen f : Set (PrimeSpectrum R)) := isRetrocompact_basicOpen.isConstructible (basicOpen f).2 section IsIntegral open Polynomial variable {R S : Type*} [CommRing R] [CommRing S] (f : R →+* S) theorem isClosedMap_comap_of_isIntegral (hf : f.IsIntegral) : IsClosedMap (comap f) := by refine fun s hs ↦ isClosed_image_of_stableUnderSpecialization _ _ hs ?_ rintro _ y e ⟨x, hx, rfl⟩ algebraize [f] obtain ⟨q, hq₁, hq₂, hq₃⟩ := Ideal.exists_ideal_over_prime_of_isIntegral y.asIdeal x.asIdeal ((le_iff_specializes _ _).mpr e) refine ⟨⟨q, hq₂⟩, ((le_iff_specializes _ ⟨q, hq₂⟩).mp hq₁).mem_closed hs hx, PrimeSpectrum.ext hq₃⟩ theorem isClosed_comap_singleton_of_isIntegral (hf : f.IsIntegral) (x : PrimeSpectrum S) (hx : IsClosed ({x} : Set (PrimeSpectrum S))) : IsClosed ({comap f x} : Set (PrimeSpectrum R)) := by simpa using isClosedMap_comap_of_isIntegral f hf _ hx lemma closure_image_comap_zeroLocus (I : Ideal S) : closure (comap f '' zeroLocus I) = zeroLocus (I.comap f) := by apply subset_antisymm · rw [(isClosed_zeroLocus _).closure_subset_iff, Set.image_subset_iff, preimage_comap_zeroLocus] exact zeroLocus_anti_mono (Set.image_preimage_subset _ _) · rintro x (hx : I.comap f ≤ x.asIdeal) obtain ⟨q, hq₁, hq₂⟩ := Ideal.exists_minimalPrimes_le hx obtain ⟨p', hp', hp'', rfl⟩ := Ideal.exists_comap_eq_of_mem_minimalPrimes f _ hq₁ let p'' : PrimeSpectrum S := ⟨p', hp'⟩ apply isClosed_closure.stableUnderSpecialization ((le_iff_specializes (comap f ⟨p', hp'⟩) x).mp hq₂) (subset_closure (by exact ⟨_, hp'', rfl⟩)) lemma isIntegral_of_isClosedMap_comap_mapRingHom (h : IsClosedMap (comap (mapRingHom f))) : f.IsIntegral := by algebraize [f] suffices Algebra.IsIntegral R S by rwa [Algebra.isIntegral_def] at this nontriviality R nontriviality S constructor intro r let p : S[X] := C r * X - 1 have : (1 : R[X]) ∈ Ideal.span {X} ⊔ (Ideal.span {p}).comap (mapRingHom f) := by have H := h _ (isClosed_zeroLocus {p}) rw [← zeroLocus_span, ← closure_eq_iff_isClosed, closure_image_comap_zeroLocus] at H rw [← Ideal.eq_top_iff_one, sup_comm, ← zeroLocus_empty_iff_eq_top, zeroLocus_sup, H] suffices ∀ (a : PrimeSpectrum S[X]), p ∈ a.asIdeal → X ∉ a.asIdeal by simpa [Set.eq_empty_iff_forall_notMem] intro q hpq hXq have : 1 ∈ q.asIdeal := by simpa [p] using (sub_mem (q.asIdeal.mul_mem_left (C r) hXq) hpq) exact q.2.ne_top (q.asIdeal.eq_top_iff_one.mpr this) obtain ⟨a, b, hb, e⟩ := Ideal.mem_span_singleton_sup.mp this obtain ⟨c, hc : b.map (algebraMap R S) = _⟩ := Ideal.mem_span_singleton.mp hb refine ⟨b.reverse * X ^ (1 + c.natDegree), ?_, ?_⟩ · refine Monic.mul ?_ (by simp) have h : b.coeff 0 = 1 := by simpa using congr(($e).coeff 0) have : b.natTrailingDegree = 0 := by simp [h] rw [Monic.def, reverse_leadingCoeff, trailingCoeff, this, h] · have : p.natDegree ≤ 1 := by simpa using natDegree_linear_le (a := r) (b := -1) rw [eval₂_eq_eval_map, reverse, Polynomial.map_mul, ← reflect_map, Polynomial.map_pow, map_X, ← revAt_zero (1 + _), ← reflect_monomial, ← reflect_mul _ _ natDegree_map_le (by simp), pow_zero, mul_one, hc, ← add_assoc, reflect_mul _ _ (this.trans (by simp)) le_rfl, eval_mul, reflect_sub, reflect_mul _ _ (by simp) (by simp)] simp [← pow_succ'] lemma _root_.RingHom.IsIntegral.specComap_surjective {f : R →+* S} (hf : f.IsIntegral) (hinj : Function.Injective f) : Function.Surjective f.specComap := by algebraize [f] intro ⟨p, hp⟩ obtain ⟨Q, _, hQ, rfl⟩ := Ideal.exists_ideal_over_prime_of_isIntegral p (⊥ : Ideal S) (by simp [Ideal.comap_bot_of_injective (algebraMap R S) hinj]) exact ⟨⟨Q, hQ⟩, rfl⟩ end IsIntegral variable (R) /-- Zero loci of minimal prime ideals of `R` are irreducible components in `Spec R` and any irreducible component is a zero locus of some minimal prime ideal. -/ @[stacks 00ES] protected def _root_.minimalPrimes.equivIrreducibleComponents : minimalPrimes R ≃o (irreducibleComponents <| PrimeSpectrum R)ᵒᵈ := by let e : {p : Ideal R | p.IsPrime ∧ ⊥ ≤ p} ≃o PrimeSpectrum R := ⟨⟨fun x ↦ ⟨x.1, x.2.1⟩, fun x ↦ ⟨x.1, x.2, bot_le⟩, fun _ ↦ rfl, fun _ ↦ rfl⟩, Iff.rfl⟩ rw [irreducibleComponents_eq_maximals_closed] exact OrderIso.setOfMinimalIsoSetOfMaximal (e.trans ((PrimeSpectrum.pointsEquivIrreducibleCloseds R).trans (TopologicalSpace.IrreducibleCloseds.orderIsoSubtype' (PrimeSpectrum R)).dual)) lemma vanishingIdeal_irreducibleComponents : vanishingIdeal '' (irreducibleComponents <| PrimeSpectrum R) = minimalPrimes R := by rw [irreducibleComponents_eq_maximals_closed, minimalPrimes_eq_minimals, image_antitone_setOf_maximal (fun s t hs _ ↦ (vanishingIdeal_anti_mono_iff hs.1).symm), ← funext (@Set.mem_setOf_eq _ · Ideal.IsPrime), ← vanishingIdeal_isClosed_isIrreducible] rfl lemma zeroLocus_minimalPrimes : zeroLocus ∘ (↑) '' minimalPrimes R = irreducibleComponents (PrimeSpectrum R) := by rw [← vanishingIdeal_irreducibleComponents, ← Set.image_comp, Set.EqOn.image_eq_self] intro s hs simpa [zeroLocus_vanishingIdeal_eq_closure, closure_eq_iff_isClosed] using isClosed_of_mem_irreducibleComponents s hs variable {R} lemma vanishingIdeal_mem_minimalPrimes {s : Set (PrimeSpectrum R)} : vanishingIdeal s ∈ minimalPrimes R ↔ closure s ∈ irreducibleComponents (PrimeSpectrum R) := by constructor · rw [← zeroLocus_minimalPrimes, ← zeroLocus_vanishingIdeal_eq_closure] exact Set.mem_image_of_mem _ · rw [← vanishingIdeal_irreducibleComponents, ← vanishingIdeal_closure] exact Set.mem_image_of_mem _ lemma zeroLocus_ideal_mem_irreducibleComponents {I : Ideal R} : zeroLocus I ∈ irreducibleComponents (PrimeSpectrum R) ↔ I.radical ∈ minimalPrimes R := by rw [← vanishingIdeal_zeroLocus_eq_radical] conv_lhs => rw [← (isClosed_zeroLocus _).closure_eq] exact vanishingIdeal_mem_minimalPrimes.symm end CommSemiring end PrimeSpectrum namespace IsLocalRing variable [CommSemiring R] [IsLocalRing R] /-- The closed point in the prime spectrum of a local ring. -/ def closedPoint : PrimeSpectrum R := ⟨maximalIdeal R, (maximalIdeal.isMaximal R).isPrime⟩ instance : OrderTop (PrimeSpectrum R) where top := closedPoint R le_top := fun _ ↦ le_maximalIdeal Ideal.IsPrime.ne_top' variable {R} theorem isLocalHom_iff_comap_closedPoint {S : Type v} [CommSemiring S] [IsLocalRing S] (f : R →+* S) : IsLocalHom f ↔ PrimeSpectrum.comap f (closedPoint S) = closedPoint R := by -- Porting note: inline `this` does **not** work have := (local_hom_TFAE f).out 0 4 rw [this, PrimeSpectrum.ext_iff] rfl @[simp] theorem comap_closedPoint {S : Type v} [CommSemiring S] [IsLocalRing S] (f : R →+* S) [IsLocalHom f] : PrimeSpectrum.comap f (closedPoint S) = closedPoint R := (isLocalHom_iff_comap_closedPoint f).mp inferInstance theorem specializes_closedPoint (x : PrimeSpectrum R) : x ⤳ closedPoint R := (PrimeSpectrum.le_iff_specializes _ _).mp (IsLocalRing.le_maximalIdeal x.2.1) theorem closedPoint_mem_iff (U : TopologicalSpace.Opens <| PrimeSpectrum R) : closedPoint R ∈ U ↔ U = ⊤ := by constructor · rw [eq_top_iff] exact fun h x _ => (specializes_closedPoint x).mem_open U.2 h · rintro rfl exact TopologicalSpace.Opens.mem_top _ lemma closed_point_mem_iff {U : TopologicalSpace.Opens (PrimeSpectrum R)} : closedPoint R ∈ U ↔ U = ⊤ := ⟨(eq_top_iff.mpr fun x _ ↦ (specializes_closedPoint x).mem_open U.2 ·), (· ▸ trivial)⟩ @[simp] theorem PrimeSpectrum.comap_residue (T : Type u) [CommRing T] [IsLocalRing T] (x : PrimeSpectrum (ResidueField T)) : PrimeSpectrum.comap (residue T) x = closedPoint T := by rw [Subsingleton.elim x ⊥] ext1 exact Ideal.mk_ker variable (R) in lemma isClosed_singleton_closedPoint : IsClosed {closedPoint R} := by rw [PrimeSpectrum.isClosed_singleton_iff_isMaximal, closedPoint] infer_instance end IsLocalRing section KrullDimension theorem PrimeSpectrum.topologicalKrullDim_eq_ringKrullDim [CommSemiring R] : topologicalKrullDim (PrimeSpectrum R) = ringKrullDim R := Order.krullDim_orderDual.symm.trans <| Order.krullDim_eq_of_orderIso (PrimeSpectrum.pointsEquivIrreducibleCloseds R).symm end KrullDimension section Idempotent variable {R} [CommRing R] namespace PrimeSpectrum @[stacks 00EC] lemma basicOpen_eq_zeroLocus_of_isIdempotentElem (e : R) (he : IsIdempotentElem e) : basicOpen e = zeroLocus {1 - e} := basicOpen_eq_zeroLocus_of_mul_add _ _ (by simp [mul_sub, he.eq]) (by simp) @[stacks 00EC] lemma zeroLocus_eq_basicOpen_of_isIdempotentElem (e : R) (he : IsIdempotentElem e) : zeroLocus {e} = basicOpen (1 - e) := by rw [basicOpen_eq_zeroLocus_of_isIdempotentElem _ he.one_sub, sub_sub_cancel] lemma isClopen_iff {s : Set (PrimeSpectrum R)} : IsClopen s ↔ ∃ e : R, IsIdempotentElem e ∧ s = basicOpen e := by refine ⟨exists_idempotent_basicOpen_eq_of_isClopen, ?_⟩ rintro ⟨e, he, rfl⟩ refine ⟨?_, (basicOpen e).2⟩ rw [PrimeSpectrum.basicOpen_eq_zeroLocus_of_isIdempotentElem e he] exact isClosed_zeroLocus _ lemma isClopen_iff_zeroLocus {s : Set (PrimeSpectrum R)} : IsClopen s ↔ ∃ e : R, IsIdempotentElem e ∧ s = zeroLocus {e} := isClopen_iff.trans <| ⟨fun ⟨e, he, h⟩ ↦ ⟨1 - e, he.one_sub, h.trans (basicOpen_eq_zeroLocus_of_isIdempotentElem e he)⟩, fun ⟨e, he, h⟩ ↦ ⟨1 - e, he.one_sub, h.trans (zeroLocus_eq_basicOpen_of_isIdempotentElem e he)⟩⟩ open TopologicalSpace (Clopens Opens) /-- Clopen subsets in the prime spectrum of a commutative ring are in 1-1 correspondence with idempotent elements in the ring. -/ @[stacks 00EE] def isIdempotentElemEquivClopens : {e : R // IsIdempotentElem e} ≃o Clopens (PrimeSpectrum R) := .trans .isIdempotentElemMulZeroAddOne mulZeroAddOneEquivClopens lemma basicOpen_isIdempotentElemEquivClopens_symm (s) : basicOpen (isIdempotentElemEquivClopens (R := R).symm s).1 = s.toOpens := Opens.ext <| congr_arg (·.1) (isIdempotentElemEquivClopens.apply_symm_apply s) lemma coe_isIdempotentElemEquivClopens_apply (e) : (isIdempotentElemEquivClopens e : Set (PrimeSpectrum R)) = basicOpen (e.1 : R) := rfl lemma isIdempotentElemEquivClopens_apply_toOpens (e) : (isIdempotentElemEquivClopens e).toOpens = basicOpen (e.1 : R) := rfl lemma isIdempotentElemEquivClopens_mul (e₁ e₂ : {e : R | IsIdempotentElem e}) : isIdempotentElemEquivClopens ⟨_, e₁.2.mul e₂.2⟩ = isIdempotentElemEquivClopens e₁ ⊓ isIdempotentElemEquivClopens e₂ := map_inf .. lemma isIdempotentElemEquivClopens_one_sub (e : {e : R | IsIdempotentElem e}) : isIdempotentElemEquivClopens ⟨_, e.2.one_sub⟩ = (isIdempotentElemEquivClopens e)ᶜ := map_compl .. lemma isIdempotentElemEquivClopens_symm_inf (s₁ s₂) : letI e := isIdempotentElemEquivClopens (R := R).symm e (s₁ ⊓ s₂) = ⟨_, (e s₁).2.mul (e s₂).2⟩ := map_inf .. lemma isIdempotentElemEquivClopens_symm_compl (s : Clopens (PrimeSpectrum R)) : isIdempotentElemEquivClopens.symm sᶜ = ⟨_, (isIdempotentElemEquivClopens.symm s).2.one_sub⟩ := map_compl .. lemma isIdempotentElemEquivClopens_symm_top : isIdempotentElemEquivClopens.symm ⊤ = ⟨(1 : R), .one⟩ := map_top _ lemma isIdempotentElemEquivClopens_symm_bot : isIdempotentElemEquivClopens.symm ⊥ = ⟨(0 : R), .zero⟩ := map_bot _ lemma isIdempotentElemEquivClopens_symm_sup (s₁ s₂ : Clopens (PrimeSpectrum R)) : letI e := isIdempotentElemEquivClopens (R := R).symm e (s₁ ⊔ s₂) = ⟨_, (e s₁).2.add_sub_mul (e s₂).2⟩ := map_sup .. end PrimeSpectrum end Idempotent
.lake/packages/mathlib/Mathlib/RingTheory/Spectrum/Prime/Basic.lean
import Mathlib.RingTheory.Ideal.MinimalPrime.Basic import Mathlib.RingTheory.Nilpotent.Lemmas import Mathlib.RingTheory.Noetherian.Basic import Mathlib.RingTheory.Spectrum.Prime.Defs /-! # Prime spectrum of a commutative (semi)ring For the Zariski topology, see `Mathlib/RingTheory/Spectrum/Prime/Topology.lean`. (It is also naturally endowed with a sheaf of rings, which is constructed in `AlgebraicGeometry.StructureSheaf`.) ## Main definitions * `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). ## References * [M. F. Atiyah and I. G. Macdonald, *Introduction to commutative algebra*][atiyah-macdonald] * [P. Samuel, *Algebraic Theory of Numbers*][samuel1967] -/ -- A dividing line between this file and `Mathlib/RingTheory/Spectrum/Prime/Topology.lean` is -- that we should not depend on the Zariski topology here assert_not_exists TopologicalSpace noncomputable section open scoped Pointwise universe u v variable (R : Type u) (S : Type v) namespace PrimeSpectrum section CommSemiRing variable [CommSemiring R] [CommSemiring S] variable {R S} lemma nonempty_iff_nontrivial : Nonempty (PrimeSpectrum R) ↔ Nontrivial R := by refine ⟨fun ⟨p⟩ ↦ ⟨0, 1, fun h ↦ p.2.ne_top ?_⟩, fun h ↦ ?_⟩ · simp [Ideal.eq_top_iff_one p.asIdeal, ← h] · obtain ⟨I, hI⟩ := Ideal.exists_maximal R exact ⟨⟨I, hI.isPrime⟩⟩ lemma isEmpty_iff_subsingleton : IsEmpty (PrimeSpectrum R) ↔ Subsingleton R := by rw [← not_iff_not, not_isEmpty_iff, not_subsingleton_iff_nontrivial, nonempty_iff_nontrivial] instance [Nontrivial R] : Nonempty <| PrimeSpectrum R := nonempty_iff_nontrivial.mpr inferInstance /-- The prime spectrum of the zero ring is empty. -/ instance [Subsingleton R] : IsEmpty (PrimeSpectrum R) := isEmpty_iff_subsingleton.mpr inferInstance lemma nontrivial (p : PrimeSpectrum R) : Nontrivial R := nonempty_iff_nontrivial.mp ⟨p⟩ variable (R S) theorem range_asIdeal : Set.range PrimeSpectrum.asIdeal = {J : Ideal R | J.IsPrime} := Set.ext fun J ↦ ⟨fun hJ ↦ let ⟨j, hj⟩ := Set.mem_range.mp hJ; Set.mem_setOf.mpr <| hj ▸ j.isPrime, fun hJ ↦ Set.mem_range.mpr ⟨⟨J, Set.mem_setOf.mp hJ⟩, rfl⟩⟩ /-- 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_inj, 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_def] 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⟩⟩ theorem nilradical_eq_iInf : nilradical R = iInf asIdeal := by apply range_asIdeal R ▸ nilradical_eq_sInf R @[simp] theorem vanishingIdeal_univ : vanishingIdeal Set.univ = nilradical R := by rw [vanishingIdeal, iInf_univ, nilradical_eq_iInf] @[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] lemma zeroLocus_nilradical : zeroLocus (nilradical R : Set R) = Set.univ := by rw [nilradical, zeroLocus_radical, Ideal.zero_eq_bot, zeroLocus_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_notMem] 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_univ_iff (s : Set R) : zeroLocus s = Set.univ ↔ s ⊆ nilradical R := by rw [← Set.univ_subset_iff, subset_zeroLocus_iff_subset_vanishingIdeal, vanishingIdeal_univ] 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_notMem {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 @[deprecated (since := "2025-05-23")] alias mem_compl_zeroLocus_iff_not_mem := mem_compl_zeroLocus_iff_notMem @[simp] lemma zeroLocus_insert_zero (s : Set R) : zeroLocus (insert 0 s) = zeroLocus s := by rw [← Set.union_singleton, zeroLocus_union, zeroLocus_singleton_zero, Set.inter_univ] @[simp] lemma zeroLocus_diff_singleton_zero (s : Set R) : zeroLocus (s \ {0}) = zeroLocus s := by rw [← zeroLocus_insert_zero, ← zeroLocus_insert_zero (s := s)]; simp lemma zeroLocus_smul_of_isUnit {r : R} (hr : IsUnit r) (s : Set R) : zeroLocus (r • s) = zeroLocus s := by ext; simp [Set.subset_def, ← Set.image_smul, Ideal.unit_mul_mem_iff_mem _ hr] section Order 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) /-- Also see `PrimeSpectrum.isClosed_singleton_iff_isMaximal` -/ lemma isMax_iff {x : PrimeSpectrum R} : IsMax x ↔ x.asIdeal.IsMaximal := by refine ⟨fun hx ↦ ⟨⟨x.2.ne_top, fun I hI ↦ ?_⟩⟩, fun hx y e ↦ (hx.eq_of_le y.2.ne_top e).ge⟩ by_contra e obtain ⟨m, hm, hm'⟩ := Ideal.exists_le_maximal I e exact hx.not_lt (show x < ⟨m, hm.isPrime⟩ from hI.trans_le hm') lemma zeroLocus_eq_singleton (m : Ideal R) [m.IsMaximal] : zeroLocus m = {⟨m, inferInstance⟩} := by ext I refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · simp only [mem_zeroLocus, SetLike.coe_subset_coe] at h simpa using PrimeSpectrum.ext_iff.mpr (Ideal.IsMaximal.eq_of_le ‹_› I.2.ne_top h).symm · simp [Set.mem_singleton_iff.mp h] lemma isMin_iff {x : PrimeSpectrum R} : IsMin x ↔ x.asIdeal ∈ minimalPrimes R := by change IsMin _ ↔ Minimal (fun q : Ideal R ↦ q.IsPrime ∧ ⊥ ≤ q) _ simp only [IsMin, Minimal, x.2, bot_le, and_self, and_true, true_and] exact ⟨fun H y hy e ↦ @H ⟨y, hy⟩ e, fun H y e ↦ H y.2 e⟩ 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 ([samuel1967, § 3.3, Lemma 3]). -/ theorem exists_primeSpectrum_prod_le (I : Ideal R) : ∃ Z : Multiset (PrimeSpectrum R), Multiset.prod (Z.map asIdeal) ≤ I := by induction I using IsNoetherian.induction with | hgt M hgt => change Ideal R at M 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 (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 ([samuel1967, § 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 induction I using IsNoetherian.induction with | hgt M hgt => change Ideal A at M 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_nzI⟩ 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 (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
.lake/packages/mathlib/Mathlib/RingTheory/Spectrum/Prime/RingHom.lean
import Mathlib.RingTheory.Spectrum.Prime.Basic import Mathlib.RingTheory.LocalRing.ResidueField.Ideal import Mathlib.RingTheory.TensorProduct.Maps /-! # Functoriality of the prime spectrum In this file we define the induced map on prime spectra induced by a ring homomorphism. ## Main definitions * `RingHom.specComap`: The induced map on prime spectra by a ring homomorphism. The bundled continuous version is `PrimeSpectrum.comap` in `Mathlib/RingTheory/Spectrum/Prime/Topology.lean`. -/ universe u v variable (R : Type u) (S : Type v) open PrimeSpectrum /-- The pullback of an element of `PrimeSpectrum S` along a ring homomorphism `f : R →+* S`. The bundled continuous version is `PrimeSpectrum.comap`. -/ abbrev RingHom.specComap {R S : Type*} [CommSemiring R] [CommSemiring S] (f : R →+* S) : PrimeSpectrum S → PrimeSpectrum R := fun y => ⟨Ideal.comap f y.asIdeal, inferInstance⟩ namespace PrimeSpectrum open RingHom variable {R S} {S' : Type*} [CommSemiring R] [CommSemiring S] [CommSemiring S'] theorem preimage_specComap_zeroLocus_aux (f : R →+* S) (s : Set R) : f.specComap ⁻¹' zeroLocus s = zeroLocus (f '' s) := by ext x simp only [mem_zeroLocus, Set.image_subset_iff, Set.mem_preimage, mem_zeroLocus, Ideal.coe_comap] variable (f : R →+* S) @[simp] theorem specComap_asIdeal (y : PrimeSpectrum S) : (f.specComap y).asIdeal = Ideal.comap f y.asIdeal := rfl @[simp] theorem specComap_id : (RingHom.id R).specComap = fun x => x := rfl @[simp] theorem specComap_comp (f : R →+* S) (g : S →+* S') : (g.comp f).specComap = f.specComap.comp g.specComap := rfl theorem specComap_comp_apply (f : R →+* S) (g : S →+* S') (x : PrimeSpectrum S') : (g.comp f).specComap x = f.specComap (g.specComap x) := rfl @[simp] theorem preimage_specComap_zeroLocus (s : Set R) : f.specComap ⁻¹' zeroLocus s = zeroLocus (f '' s) := preimage_specComap_zeroLocus_aux f s theorem specComap_injective_of_surjective (f : R →+* S) (hf : Function.Surjective f) : Function.Injective f.specComap := fun x y h => PrimeSpectrum.ext (Ideal.comap_injective_of_surjective f hf (congr_arg PrimeSpectrum.asIdeal h : (f.specComap x).asIdeal = (f.specComap y).asIdeal)) /-- `RingHom.specComap` of an isomorphism of rings as an equivalence of their prime spectra. -/ @[simps apply symm_apply] def comapEquiv (e : R ≃+* S) : PrimeSpectrum R ≃o PrimeSpectrum S where toFun := e.symm.toRingHom.specComap invFun := e.toRingHom.specComap left_inv x := by rw [← specComap_comp_apply, RingEquiv.toRingHom_eq_coe, RingEquiv.toRingHom_eq_coe, RingEquiv.symm_comp] rfl right_inv x := by rw [← specComap_comp_apply, RingEquiv.toRingHom_eq_coe, RingEquiv.toRingHom_eq_coe, RingEquiv.comp_symm] rfl map_rel_iff' {I J} := Ideal.comap_le_comap_iff_of_surjective _ e.symm.surjective .. section Pi variable {ι} (R : ι → Type*) [∀ i, CommSemiring (R i)] /-- The canonical map from a disjoint union of prime spectra of commutative semirings to the prime spectrum of the product semiring. -/ /- TODO: show this is always a topological embedding (even when ι is infinite) and is a homeomorphism when ι is finite. -/ @[simps] def sigmaToPi : (Σ i, PrimeSpectrum (R i)) → PrimeSpectrum (Π i, R i) | ⟨i, p⟩ => (Pi.evalRingHom R i).specComap p theorem sigmaToPi_injective : (sigmaToPi R).Injective := fun ⟨i, p⟩ ⟨j, q⟩ eq ↦ by classical obtain rfl | ne := eq_or_ne i j · congr; ext x simpa using congr_arg (Function.update (0 : ∀ i, R i) i x ∈ ·.asIdeal) eq · refine (p.1.ne_top_iff_one.mp p.2.ne_top ?_).elim have : Function.update (1 : ∀ i, R i) j 0 ∈ (sigmaToPi R ⟨j, q⟩).asIdeal := by simp simpa [← eq, Function.update_of_ne ne] variable [Infinite ι] [∀ i, Nontrivial (R i)] /-- An infinite product of nontrivial commutative semirings has a maximal ideal outside of the range of `sigmaToPi`, i.e. is not of the form `πᵢ⁻¹(𝔭)` for some prime `𝔭 ⊂ R i`, where `πᵢ : (Π i, R i) →+* R i` is the projection. For a complete description of all prime ideals, see https://math.stackexchange.com/a/1563190. -/ theorem exists_maximal_notMem_range_sigmaToPi_of_infinite : ∃ (I : Ideal (Π i, R i)) (_ : I.IsMaximal), ⟨I, inferInstance⟩ ∉ Set.range (sigmaToPi R) := by classical let J : Ideal (Π i, R i) := -- `J := Π₀ i, R i` is an ideal in `Π i, R i` { __ := AddMonoidHom.mrange DFinsupp.coeFnAddMonoidHom smul_mem' := by rintro r _ ⟨x, rfl⟩ refine ⟨.mk x.support fun i ↦ r i * x i, funext fun i ↦ show dite _ _ _ = _ from ?_⟩ simp_rw [DFinsupp.coeFnAddMonoidHom] refine dite_eq_left_iff.mpr fun h ↦ ?_ rw [DFinsupp.notMem_support_iff.mp h, mul_zero] } have ⟨I, max, le⟩ := J.exists_le_maximal <| (Ideal.ne_top_iff_one _).mpr <| by -- take a maximal ideal I containing J rintro ⟨x, hx⟩ have ⟨i, hi⟩ := x.support.exists_notMem simpa [DFinsupp.coeFnAddMonoidHom, DFinsupp.notMem_support_iff.mp hi] using congr_fun hx i refine ⟨I, max, fun ⟨⟨i, p⟩, eq⟩ ↦ ?_⟩ -- then I is not in the range of `sigmaToPi` have : ⇑(DFinsupp.single i 1) ∉ (sigmaToPi R ⟨i, p⟩).asIdeal := by simpa using p.1.ne_top_iff_one.mp p.2.ne_top rw [eq] at this exact this (le ⟨.single i 1, rfl⟩) @[deprecated (since := "2025-05-24")] alias exists_maximal_nmem_range_sigmaToPi_of_infinite := exists_maximal_notMem_range_sigmaToPi_of_infinite theorem sigmaToPi_not_surjective_of_infinite : ¬ (sigmaToPi R).Surjective := fun surj ↦ have ⟨_, _, notMem⟩ := exists_maximal_notMem_range_sigmaToPi_of_infinite R (Set.range_eq_univ.mpr surj ▸ notMem) ⟨⟩ lemma exists_comap_evalRingHom_eq {ι : Type*} {R : ι → Type*} [∀ i, CommRing (R i)] [Finite ι] (p : PrimeSpectrum (Π i, R i)) : ∃ (i : ι) (q : PrimeSpectrum (R i)), (Pi.evalRingHom R i).specComap q = p := by classical cases nonempty_fintype ι let e (i) : Π i, R i := Function.update 1 i 0 have H : ∏ i, e i = 0 := by ext j rw [Finset.prod_apply, Pi.zero_apply, Finset.prod_eq_zero (Finset.mem_univ j)] simp [e] obtain ⟨i, hi⟩ : ∃ i, e i ∈ p.asIdeal := by simpa [← H, Ideal.IsPrime.prod_mem_iff] using p.asIdeal.zero_mem let h₁ : Function.Surjective (Pi.evalRingHom R i) := RingHomSurjective.is_surjective have h₂ : RingHom.ker (Pi.evalRingHom R i) ≤ p.asIdeal := by intro x hx convert p.asIdeal.mul_mem_left x hi ext j by_cases hj : i = j · subst hj; simpa [e] · simp [e, Function.update_of_ne (.symm hj)] have : (p.asIdeal.map (Pi.evalRingHom R i)).comap (Pi.evalRingHom R i) = p.asIdeal := by rwa [Ideal.comap_map_of_surjective _ h₁, sup_eq_left] exact ⟨i, ⟨_, Ideal.map_isPrime_of_surjective h₁ h₂⟩, PrimeSpectrum.ext this⟩ lemma sigmaToPi_bijective {ι : Type*} (R : ι → Type*) [∀ i, CommRing (R i)] [Finite ι] : Function.Bijective (sigmaToPi R) := by refine ⟨sigmaToPi_injective R, ?_⟩ intro q obtain ⟨i, q, rfl⟩ := exists_comap_evalRingHom_eq q exact ⟨⟨i, q⟩, rfl⟩ lemma iUnion_range_specComap_comp_evalRingHom {ι : Type*} {R : ι → Type*} [∀ i, CommRing (R i)] [Finite ι] {S : Type*} [CommRing S] (f : S →+* Π i, R i) : ⋃ i, Set.range ((Pi.evalRingHom R i).comp f).specComap = Set.range f.specComap := by simp_rw [specComap_comp] apply subset_antisymm · exact Set.iUnion_subset fun _ ↦ Set.range_comp_subset_range _ _ · rintro _ ⟨p, rfl⟩ obtain ⟨i, p, rfl⟩ := exists_comap_evalRingHom_eq p exact Set.mem_iUnion_of_mem i ⟨p, rfl⟩ end Pi end PrimeSpectrum section SpecOfSurjective open Function RingHom variable [CommRing R] [CommRing S] variable (f : R →+* S) variable {R} theorem image_specComap_zeroLocus_eq_zeroLocus_comap (hf : Surjective f) (I : Ideal S) : f.specComap '' zeroLocus I = zeroLocus (I.comap f) := by simp only [Set.ext_iff, Set.mem_image, mem_zeroLocus, SetLike.coe_subset_coe] refine fun p => ⟨?_, fun h_I_p => ?_⟩ · rintro ⟨p, hp, rfl⟩ a ha exact hp ha · have hp : ker f ≤ p.asIdeal := (Ideal.comap_mono bot_le).trans h_I_p refine ⟨⟨p.asIdeal.map f, Ideal.map_isPrime_of_surjective hf hp⟩, fun x hx => ?_, ?_⟩ · obtain ⟨x', rfl⟩ := hf x exact Ideal.mem_map_of_mem f (h_I_p hx) · ext x rw [specComap_asIdeal, Ideal.mem_comap, Ideal.mem_map_iff_of_surjective f hf] refine ⟨?_, fun hx => ⟨x, hx, rfl⟩⟩ rintro ⟨x', hx', heq⟩ rw [← sub_sub_cancel x' x] refine p.asIdeal.sub_mem hx' (hp ?_) rwa [mem_ker, map_sub, sub_eq_zero] theorem range_specComap_of_surjective (hf : Surjective f) : Set.range f.specComap = zeroLocus (ker f) := by rw [← Set.image_univ] convert image_specComap_zeroLocus_eq_zeroLocus_comap _ _ hf _ rw [zeroLocus_bot] variable {S} /-- Let `f : R →+* S` be a surjective ring homomorphism, then `Spec S` is order-isomorphic to `Z(I)` where `I = ker f`. -/ noncomputable def Ideal.primeSpectrumOrderIsoZeroLocusOfSurj (hf : Surjective f) {I : Ideal R} (hI : RingHom.ker f = I) : PrimeSpectrum S ≃o (PrimeSpectrum.zeroLocus (R := R) I) where toFun p := ⟨f.specComap p, hI.symm.trans_le (Ideal.ker_le_comap f)⟩ invFun := fun ⟨⟨p, _⟩, hp⟩ ↦ ⟨p.map f, p.map_isPrime_of_surjective hf (hI.trans_le hp)⟩ left_inv := by intro ⟨p, _⟩ simp only [PrimeSpectrum.mk.injEq] exact p.map_comap_of_surjective f hf right_inv := by intro ⟨⟨p, _⟩, hp⟩ simp only [Subtype.mk.injEq, PrimeSpectrum.mk.injEq] exact (p.comap_map_of_surjective f hf).trans <| sup_eq_left.mpr (hI.trans_le hp) map_rel_iff' {a b} := by change a.asIdeal.comap _ ≤ b.asIdeal.comap _ ↔ a ≤ b rw [← Ideal.map_le_iff_le_comap, Ideal.map_comap_of_surjective f hf, PrimeSpectrum.asIdeal_le_asIdeal] /-- `Spec (R / I)` is order-isomorphic to `Z(I)`. -/ noncomputable def Ideal.primeSpectrumQuotientOrderIsoZeroLocus (I : Ideal R) : PrimeSpectrum (R ⧸ I) ≃o (PrimeSpectrum.zeroLocus (R := R) I) := primeSpectrumOrderIsoZeroLocusOfSurj (Quotient.mk I) Quotient.mk_surjective I.mk_ker /-- `p` is in the image of `Spec S → Spec R` if and only if `p` extended to `S` and restricted back to `R` is `p`. -/ lemma PrimeSpectrum.mem_range_comap_iff {p : PrimeSpectrum R} : p ∈ Set.range f.specComap ↔ (p.asIdeal.map f).comap f = p.asIdeal := by refine ⟨fun ⟨q, hq⟩ ↦ by simp [← hq], ?_⟩ rw [Ideal.comap_map_eq_self_iff_of_isPrime] rintro ⟨q, _, hq⟩ exact ⟨⟨q, inferInstance⟩, PrimeSpectrum.ext hq⟩ open TensorProduct /-- A prime `p` is in the range of `Spec S → Spec R` if the fiber over `p` is nontrivial. -/ lemma PrimeSpectrum.nontrivial_iff_mem_rangeComap {S : Type*} [CommRing S] [Algebra R S] (p : PrimeSpectrum R) : Nontrivial (p.asIdeal.ResidueField ⊗[R] S) ↔ p ∈ Set.range (algebraMap R S).specComap := by let k := p.asIdeal.ResidueField refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · obtain ⟨m, hm⟩ := Ideal.exists_maximal (k ⊗[R] S) use (Algebra.TensorProduct.includeRight).specComap ⟨m, hm.isPrime⟩ ext : 1 rw [← PrimeSpectrum.specComap_comp_apply, ← Algebra.TensorProduct.includeLeftRingHom_comp_algebraMap, specComap_comp_apply] simp [Ideal.eq_bot_of_prime, k, ← RingHom.ker_eq_comap_bot] · obtain ⟨q, rfl⟩ := h let f : k ⊗[R] S →ₐ[R] q.asIdeal.ResidueField := Algebra.TensorProduct.lift (Ideal.ResidueField.mapₐ _ _ rfl) (IsScalarTower.toAlgHom _ _ _) (fun _ _ ↦ Commute.all ..) exact RingHom.domain_nontrivial f.toRingHom end SpecOfSurjective section ResidueField variable {R : Type*} [CommRing R] lemma PrimeSpectrum.residueField_specComap (I : PrimeSpectrum R) : Set.range (algebraMap R I.asIdeal.ResidueField).specComap = {I} := by rw [Set.range_unique, Set.singleton_eq_singleton_iff] exact PrimeSpectrum.ext (Ideal.ext fun x ↦ Ideal.algebraMap_residueField_eq_zero) end ResidueField variable {R S} in theorem IsLocalHom.of_specComap_surjective [CommSemiring R] [CommSemiring S] (f : R →+* S) (hf : Function.Surjective f.specComap) : IsLocalHom f where map_nonunit x hfx := by by_contra hx obtain ⟨p, hp, _⟩ := exists_max_ideal_of_mem_nonunits hx obtain ⟨⟨q, hqp⟩, hq⟩ := hf ⟨p, hp.isPrime⟩ simp only [PrimeSpectrum.mk.injEq] at hq exact hqp.ne_top (q.eq_top_of_isUnit_mem (q.mem_comap.mp (by rwa [hq])) hfx)
.lake/packages/mathlib/Mathlib/RingTheory/Spectrum/Prime/Defs.lean
import Mathlib.RingTheory.Ideal.Prime /-! # 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 `Mathlib/RingTheory/Spectrum/Prime/Topology.lean`. (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`. -/ /-- 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 `Mathlib/AlgebraicGeometry/StructureSheaf.lean`). It is a fundamental building block in algebraic geometry. -/ @[ext] structure PrimeSpectrum (R : Type*) [CommSemiring R] where asIdeal : Ideal R isPrime : asIdeal.IsPrime attribute [instance] PrimeSpectrum.isPrime namespace PrimeSpectrum /-! ## 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/RingTheory/Spectrum/Prime/Topology.lean`. -/ variable {R : Type*} [CommSemiring R] 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 variable (R) in /-- The prime spectrum is in bijection with the set of prime ideals. -/ @[simps] def equivSubtype : PrimeSpectrum R ≃o {I : Ideal R // I.IsPrime} where toFun I := ⟨I.asIdeal, I.2⟩ invFun I := ⟨I, I.2⟩ map_rel_iff' := .rfl end PrimeSpectrum
.lake/packages/mathlib/Mathlib/RingTheory/Spectrum/Prime/FreeLocus.lean
import Mathlib.RingTheory.Flat.Stability import Mathlib.RingTheory.LocalProperties.Projective import Mathlib.RingTheory.LocalRing.Module import Mathlib.RingTheory.Localization.Free import Mathlib.RingTheory.Localization.LocalizationLocalization import Mathlib.RingTheory.Spectrum.Prime.Topology import Mathlib.Topology.LocallyConstant.Basic import Mathlib.RingTheory.TensorProduct.Free import Mathlib.RingTheory.TensorProduct.IsBaseChangePi import Mathlib.RingTheory.Support /-! # The free locus of a module ## Main definitions and results Let `M` be a finitely presented `R`-module. - `Module.freeLocus`: The set of points `x` in `Spec R` such that `Mₓ` is free over `Rₓ`. - `Module.freeLocus_eq_univ_iff`: The free locus is the whole `Spec R` if and only if `M` is projective. - `Module.basicOpen_subset_freeLocus_iff`: `D(f)` is contained in the free locus if and only if `M_f` is projective over `R_f`. - `Module.rankAtStalk`: The function `Spec R → ℕ` sending `x` to `rank_{Rₓ} Mₓ`. - `Module.isLocallyConstant_rankAtStalk`: If `M` is flat over `R`, then `rankAtStalk` is locally constant. -/ universe uR uM variable (R : Type uR) (M : Type uM) [CommRing R] [AddCommGroup M] [Module R M] namespace Module open PrimeSpectrum TensorProduct /-- The free locus of a module, i.e. the set of primes `p` such that `Mₚ` is free over `Rₚ`. -/ def freeLocus : Set (PrimeSpectrum R) := { p | Module.Free (Localization.AtPrime p.asIdeal) (LocalizedModule p.asIdeal.primeCompl M) } variable {R M} lemma mem_freeLocus {p} : p ∈ freeLocus R M ↔ Module.Free (Localization.AtPrime p.asIdeal) (LocalizedModule p.asIdeal.primeCompl M) := Iff.rfl attribute [local instance] RingHomInvPair.of_ringEquiv in lemma mem_freeLocus_of_isLocalization (p : PrimeSpectrum R) (Rₚ Mₚ) [CommRing Rₚ] [Algebra R Rₚ] [IsLocalization.AtPrime Rₚ p.asIdeal] [AddCommGroup Mₚ] [Module R Mₚ] (f : M →ₗ[R] Mₚ) [IsLocalizedModule p.asIdeal.primeCompl f] [Module Rₚ Mₚ] [IsScalarTower R Rₚ Mₚ] : p ∈ freeLocus R M ↔ Module.Free Rₚ Mₚ := by apply Module.Free.iff_of_ringEquiv (IsLocalization.algEquiv p.asIdeal.primeCompl (Localization.AtPrime p.asIdeal) Rₚ).toRingEquiv refine { __ := IsLocalizedModule.iso p.asIdeal.primeCompl f, map_smul' := ?_ } intro r x obtain ⟨r, s, rfl⟩ := IsLocalization.exists_mk'_eq p.asIdeal.primeCompl r apply ((Module.End.isUnit_iff _).mp (IsLocalizedModule.map_units f s)).1 simp only [AddHom.toFun_eq_coe, LinearMap.coe_toAddHom, LinearEquiv.coe_coe, algebraMap_end_apply, AlgEquiv.toRingEquiv_eq_coe, AlgEquiv.toRingEquiv_toRingHom, RingHom.coe_coe, IsLocalization.algEquiv_apply, IsLocalization.map_id_mk'] simp only [← map_smul, ← smul_assoc, IsLocalization.smul_mk'_self, algebraMap_smul] attribute [local instance] RingHomInvPair.of_ringEquiv in lemma mem_freeLocus_iff_tensor (p : PrimeSpectrum R) (Rₚ) [CommRing Rₚ] [Algebra R Rₚ] [IsLocalization.AtPrime Rₚ p.asIdeal] : p ∈ freeLocus R M ↔ Module.Free Rₚ (Rₚ ⊗[R] M) := by have := (isLocalizedModule_iff_isBaseChange p.asIdeal.primeCompl _ _).mpr (TensorProduct.isBaseChange R M Rₚ) exact mem_freeLocus_of_isLocalization p Rₚ (f := TensorProduct.mk R Rₚ M 1) lemma freeLocus_congr {M'} [AddCommGroup M'] [Module R M'] (e : M ≃ₗ[R] M') : freeLocus R M = freeLocus R M' := by ext p exact mem_freeLocus_of_isLocalization _ _ _ (LocalizedModule.mkLinearMap p.asIdeal.primeCompl M' ∘ₗ e.toLinearMap) open TensorProduct in lemma comap_freeLocus_le {A} [CommRing A] [Algebra R A] : comap (algebraMap R A) ⁻¹' freeLocus R M ≤ freeLocus A (A ⊗[R] M) := by intro p hp let Rₚ := Localization.AtPrime (comap (algebraMap R A) p).asIdeal let Aₚ := Localization.AtPrime p.asIdeal rw [Set.mem_preimage, mem_freeLocus_iff_tensor _ Rₚ] at hp rw [mem_freeLocus_iff_tensor _ Aₚ] letI algebra : Algebra Rₚ Aₚ := (Localization.localRingHom (comap (algebraMap R A) p).asIdeal p.asIdeal (algebraMap R A) rfl).toAlgebra have : IsScalarTower R Rₚ Aₚ := IsScalarTower.of_algebraMap_eq' (by simp [Rₚ, Aₚ, algebra, RingHom.algebraMap_toAlgebra, Localization.localRingHom, ← IsScalarTower.algebraMap_eq]) let e := AlgebraTensorModule.cancelBaseChange R Rₚ Aₚ Aₚ M ≪≫ₗ (AlgebraTensorModule.cancelBaseChange R A Aₚ Aₚ M).symm exact .of_equiv e lemma freeLocus_localization (S : Submonoid R) : freeLocus (Localization S) (LocalizedModule S M) = comap (algebraMap R _) ⁻¹' freeLocus R M := by ext p simp only [Set.mem_preimage] let p' := p.asIdeal.comap (algebraMap R _) have hp' : S ≤ p'.primeCompl := fun x hx H ↦ p.isPrime.ne_top (Ideal.eq_top_of_isUnit_mem _ H (IsLocalization.map_units _ ⟨x, hx⟩)) let Rₚ := Localization.AtPrime p' let Mₚ := LocalizedModule p'.primeCompl M letI : Algebra (Localization S) Rₚ := IsLocalization.localizationAlgebraOfSubmonoidLe _ _ S p'.primeCompl hp' have : IsScalarTower R (Localization S) Rₚ := IsLocalization.localization_isScalarTower_of_submonoid_le .. have : IsLocalization.AtPrime Rₚ p.asIdeal := by have := IsLocalization.isLocalization_of_submonoid_le (Localization S) Rₚ _ _ hp' apply IsLocalization.isLocalization_of_is_exists_mul_mem _ (Submonoid.map (algebraMap R (Localization S)) p'.primeCompl) · rintro _ ⟨x, hx, rfl⟩; exact hx · rintro ⟨x, hx⟩ obtain ⟨x, s, rfl⟩ := IsLocalization.exists_mk'_eq S x refine ⟨algebraMap _ _ s.1, x, fun H ↦ hx ?_, by simp⟩ rw [IsLocalization.mk'_eq_mul_mk'_one] exact Ideal.mul_mem_right _ _ H letI : Module (Localization S) Mₚ := Module.compHom Mₚ (algebraMap _ Rₚ) have : IsScalarTower R (Localization S) Mₚ := ⟨fun r r' m ↦ show algebraMap _ Rₚ (r • r') • m = _ by simp [p', Rₚ, Mₚ, Algebra.smul_def, ← IsScalarTower.algebraMap_apply, mul_smul]; rfl⟩ have : IsScalarTower (Localization S) Rₚ Mₚ := ⟨fun r r' m ↦ show _ = algebraMap _ Rₚ r • r' • m by rw [← mul_smul, ← Algebra.smul_def]⟩ let l := (IsLocalizedModule.liftOfLE _ _ hp' (LocalizedModule.mkLinearMap S M) (LocalizedModule.mkLinearMap p'.primeCompl M)).extendScalarsOfIsLocalization S (Localization S) have : IsLocalizedModule p.asIdeal.primeCompl l := by have : IsLocalizedModule p'.primeCompl (l.restrictScalars R) := inferInstanceAs (IsLocalizedModule p'.primeCompl (IsLocalizedModule.liftOfLE _ _ hp' (LocalizedModule.mkLinearMap S M) (LocalizedModule.mkLinearMap p'.primeCompl M))) have : IsLocalizedModule (Algebra.algebraMapSubmonoid (Localization S) p'.primeCompl) l := IsLocalizedModule.of_restrictScalars p'.primeCompl .. apply IsLocalizedModule.of_exists_mul_mem (Algebra.algebraMapSubmonoid (Localization S) p'.primeCompl) · rintro _ ⟨x, hx, rfl⟩; exact hx · rintro ⟨x, hx⟩ obtain ⟨x, s, rfl⟩ := IsLocalization.exists_mk'_eq S x refine ⟨algebraMap _ _ s.1, x, fun H ↦ hx ?_, by simp⟩ rw [IsLocalization.mk'_eq_mul_mk'_one] exact Ideal.mul_mem_right _ _ H rw [mem_freeLocus_of_isLocalization (R := Localization S) p Rₚ Mₚ l] rfl lemma freeLocus_eq_univ_iff [Module.FinitePresentation R M] : freeLocus R M = Set.univ ↔ Module.Projective R M := by simp_rw [Set.eq_univ_iff_forall, mem_freeLocus] exact ⟨fun H ↦ Module.projective_of_localization_maximal fun I hI ↦ have := H ⟨I, hI.isPrime⟩; .of_free, fun H x ↦ Module.free_of_flat_of_isLocalRing⟩ lemma freeLocus_eq_univ [Module.Finite R M] [Module.Flat R M] : freeLocus R M = Set.univ := by simp_rw [Set.eq_univ_iff_forall, mem_freeLocus] exact fun x ↦ Module.free_of_flat_of_isLocalRing lemma basicOpen_subset_freeLocus_iff [Module.FinitePresentation R M] {f : R} : (basicOpen f : Set (PrimeSpectrum R)) ⊆ freeLocus R M ↔ Module.Projective (Localization.Away f) (LocalizedModule (.powers f) M) := by rw [← freeLocus_eq_univ_iff, freeLocus_localization, Set.preimage_eq_univ_iff, localization_away_comap_range _ f] lemma isOpen_freeLocus [Module.FinitePresentation R M] : IsOpen (freeLocus R M) := by refine isOpen_iff_forall_mem_open.mpr fun x hx ↦ ?_ have : Module.Free _ _ := hx obtain ⟨r, hr, hr', _⟩ := Module.FinitePresentation.exists_free_localizedModule_powers x.asIdeal.primeCompl (LocalizedModule.mkLinearMap x.asIdeal.primeCompl M) (Localization.AtPrime x.asIdeal) exact ⟨basicOpen r, basicOpen_subset_freeLocus_iff.mpr inferInstance, (basicOpen r).2, hr⟩ variable (M) in /-- The rank of `M` at the stalk of `p` is the rank of `Mₚ` as a `Rₚ`-module. -/ noncomputable def rankAtStalk (p : PrimeSpectrum R) : ℕ := Module.finrank (Localization.AtPrime p.asIdeal) (LocalizedModule p.asIdeal.primeCompl M) lemma isLocallyConstant_rankAtStalk_freeLocus [Module.FinitePresentation R M] : IsLocallyConstant (fun x : freeLocus R M ↦ rankAtStalk M x.1) := by refine (IsLocallyConstant.iff_exists_open _).mpr fun ⟨x, hx⟩ ↦ ?_ have : Module.Free _ _ := hx obtain ⟨f, hf, hf', hf''⟩ := Module.FinitePresentation.exists_free_localizedModule_powers x.asIdeal.primeCompl (LocalizedModule.mkLinearMap x.asIdeal.primeCompl M) (Localization.AtPrime x.asIdeal) refine ⟨Subtype.val ⁻¹' basicOpen f, (basicOpen f).2.preimage continuous_subtype_val, hf, ?_⟩ rintro ⟨p, hp''⟩ hp let p' := Algebra.algebraMapSubmonoid (Localization (.powers f)) p.asIdeal.primeCompl have hp' : Submonoid.powers f ≤ p.asIdeal.primeCompl := by simpa [Submonoid.powers_le, Ideal.primeCompl] let Rₚ := Localization.AtPrime p.asIdeal let Mₚ := LocalizedModule p.asIdeal.primeCompl M letI : Algebra (Localization.Away f) Rₚ := IsLocalization.localizationAlgebraOfSubmonoidLe _ _ (.powers f) p.asIdeal.primeCompl hp' have : IsScalarTower R (Localization.Away f) Rₚ := IsLocalization.localization_isScalarTower_of_submonoid_le .. letI : Module (Localization.Away f) Mₚ := Module.compHom Mₚ (algebraMap _ Rₚ) have : IsScalarTower R (Localization.Away f) Mₚ := ⟨fun r r' m ↦ show algebraMap _ Rₚ (r • r') • m = _ by simp [Rₚ, Mₚ, Algebra.smul_def, ← IsScalarTower.algebraMap_apply, mul_smul]; rfl⟩ have : IsScalarTower (Localization.Away f) Rₚ Mₚ := ⟨fun r r' m ↦ show _ = algebraMap _ Rₚ r • r' • m by rw [← mul_smul, ← Algebra.smul_def]⟩ let l := (IsLocalizedModule.liftOfLE _ _ hp' (LocalizedModule.mkLinearMap (.powers f) M) (LocalizedModule.mkLinearMap p.asIdeal.primeCompl M)).extendScalarsOfIsLocalization (.powers f) (Localization.Away f) have : IsLocalization p' Rₚ := IsLocalization.isLocalization_of_submonoid_le (Localization.Away f) Rₚ _ _ hp' have : IsLocalizedModule p.asIdeal.primeCompl (l.restrictScalars R) := inferInstanceAs (IsLocalizedModule p.asIdeal.primeCompl ((IsLocalizedModule.liftOfLE _ _ hp' (LocalizedModule.mkLinearMap (.powers f) M) (LocalizedModule.mkLinearMap p.asIdeal.primeCompl M)))) have : IsLocalizedModule (Algebra.algebraMapSubmonoid _ p.asIdeal.primeCompl) l := IsLocalizedModule.of_restrictScalars p.asIdeal.primeCompl .. have := Module.finrank_of_isLocalizedModule_of_free Rₚ p' l simp [Rₚ, rankAtStalk, this, hf''] lemma isLocallyConstant_rankAtStalk [Module.FinitePresentation R M] [Module.Flat R M] : IsLocallyConstant (rankAtStalk (R := R) M) := by let e : freeLocus R M ≃ₜ PrimeSpectrum R := (Homeomorph.setCongr freeLocus_eq_univ).trans (Homeomorph.Set.univ (PrimeSpectrum R)) convert isLocallyConstant_rankAtStalk_freeLocus.comp_continuous e.symm.continuous @[simp] lemma rankAtStalk_eq_zero_of_subsingleton [Subsingleton M] : rankAtStalk (R := R) M = 0 := by ext p exact Module.finrank_zero_of_subsingleton lemma nontrivial_of_rankAtStalk_pos (h : 0 < rankAtStalk (R := R) M) : Nontrivial M := by by_contra! hn simp at h lemma rankAtStalk_eq_of_equiv {N : Type*} [AddCommGroup N] [Module R N] (e : M ≃ₗ[R] N) : rankAtStalk (R := R) M = rankAtStalk N := by ext p exact IsLocalizedModule.mapEquiv p.asIdeal.primeCompl (LocalizedModule.mkLinearMap p.asIdeal.primeCompl M) (LocalizedModule.mkLinearMap p.asIdeal.primeCompl N) _ e |>.finrank_eq /-- If `M` is `R`-free, its rank at stalks is constant and agrees with the `R`-rank of `M`. -/ @[simp] lemma rankAtStalk_eq_finrank_of_free [Module.Free R M] : rankAtStalk (R := R) M = Module.finrank R M := by ext p simp [rankAtStalk, finrank_of_isLocalizedModule_of_free _ p.asIdeal.primeCompl (LocalizedModule.mkLinearMap p.asIdeal.primeCompl M)] lemma rankAtStalk_self [Nontrivial R] : rankAtStalk (R := R) R = 1 := by simp open LocalizedModule Localization /-- The rank of `Π i, M i` at a prime `p` is the sum of the ranks of `M i` at `p`. -/ lemma rankAtStalk_pi {ι : Type*} [Finite ι] (M : ι → Type*) [∀ i, AddCommGroup (M i)] [∀ i, Module R (M i)] [∀ i, Module.Flat R (M i)] [∀ i, Module.Finite R (M i)] (p : PrimeSpectrum R) : rankAtStalk (Π i, M i) p = ∑ᶠ i, rankAtStalk (M i) p := by cases nonempty_fintype ι let f : (Π i, M i) →ₗ[R] Π i, LocalizedModule p.asIdeal.primeCompl (M i) := .pi (fun i ↦ mkLinearMap p.asIdeal.primeCompl (M i) ∘ₗ LinearMap.proj i) let e : LocalizedModule p.asIdeal.primeCompl (Π i, M i) ≃ₗ[Localization.AtPrime p.asIdeal] Π i, LocalizedModule p.asIdeal.primeCompl (M i) := IsLocalizedModule.linearEquiv p.asIdeal.primeCompl (mkLinearMap _ _) f |>.extendScalarsOfIsLocalization p.asIdeal.primeCompl _ have (i : ι) : Free (Localization.AtPrime p.asIdeal) (LocalizedModule p.asIdeal.primeCompl (M i)) := free_of_flat_of_isLocalRing simp_rw [rankAtStalk, e.finrank_eq, Module.finrank_pi_fintype, finsum_eq_sum_of_fintype] lemma rankAtStalk_eq_finrank_tensorProduct (p : PrimeSpectrum R) : rankAtStalk M p = finrank (Localization.AtPrime p.asIdeal) (Localization.AtPrime p.asIdeal ⊗[R] M) := by let e : LocalizedModule p.asIdeal.primeCompl M ≃ₗ[Localization.AtPrime p.asIdeal] Localization.AtPrime p.asIdeal ⊗[R] M := LocalizedModule.equivTensorProduct p.asIdeal.primeCompl M rw [rankAtStalk, e.finrank_eq] variable [Flat R M] [Module.Finite R M] attribute [local instance] free_of_flat_of_isLocalRing lemma rankAtStalk_eq_zero_iff_notMem_support (p : PrimeSpectrum R) : rankAtStalk M p = 0 ↔ p ∉ support R M := by rw [notMem_support_iff] refine ⟨fun h ↦ ?_, fun h ↦ Module.finrank_zero_of_subsingleton⟩ apply subsingleton_of_rank_zero (R := Localization.AtPrime p.asIdeal) dsimp [rankAtStalk] at h simp [← finrank_eq_rank, h] lemma rankAtStalk_pos_iff_mem_support (p : PrimeSpectrum R) : 0 < rankAtStalk M p ↔ p ∈ support R M := Nat.pos_iff_ne_zero.trans (rankAtStalk_eq_zero_iff_notMem_support _).not_left lemma rankAtStalk_eq_zero_iff_subsingleton : rankAtStalk (R := R) M = 0 ↔ Subsingleton M := by refine ⟨fun h ↦ ?_, fun _ ↦ rankAtStalk_eq_zero_of_subsingleton⟩ simp_rw [← support_eq_empty_iff (R := R), Set.eq_empty_iff_forall_notMem] intro p rw [← rankAtStalk_eq_zero_iff_notMem_support, h, Pi.zero_apply] variable (M) in /-- The rank of `M × N` at `p` is equal to the sum of the ranks. -/ lemma rankAtStalk_prod (N : Type*) [AddCommGroup N] [Module R N] [Module.Flat R N] [Module.Finite R N] : rankAtStalk (R := R) (M × N) = rankAtStalk M + rankAtStalk N := by ext p let e : LocalizedModule p.asIdeal.primeCompl (M × N) ≃ₗ[Localization.AtPrime p.asIdeal] LocalizedModule p.asIdeal.primeCompl M × LocalizedModule p.asIdeal.primeCompl N := IsLocalizedModule.linearEquiv p.asIdeal.primeCompl (mkLinearMap _ _) (.prodMap (mkLinearMap _ M) (mkLinearMap _ N)) |>.extendScalarsOfIsLocalization p.asIdeal.primeCompl _ simp [rankAtStalk, e.finrank_eq] lemma rankAtStalk_baseChange {S : Type*} [CommRing S] [Algebra R S] (p : PrimeSpectrum S) : rankAtStalk (S ⊗[R] M) p = rankAtStalk M ((algebraMap R S).specComap p) := by let q : PrimeSpectrum R := (algebraMap R S).specComap p let e : LocalizedModule p.asIdeal.primeCompl (S ⊗[R] M) ≃ₗ[Localization.AtPrime p.asIdeal] Localization.AtPrime p.asIdeal ⊗[Localization.AtPrime q.asIdeal] LocalizedModule q.asIdeal.primeCompl M := LocalizedModule.equivTensorProduct _ _ ≪≫ₗ (AlgebraTensorModule.cancelBaseChange R S _ _ M) ≪≫ₗ (AlgebraTensorModule.cancelBaseChange R _ _ _ M).symm ≪≫ₗ (AlgebraTensorModule.congr (LinearEquiv.refl _ _) (LocalizedModule.equivTensorProduct _ M).symm) rw [rankAtStalk, e.finrank_eq] apply Module.finrank_baseChange /-- See `rankAtStalk_tensorProduct_of_isScalarTower` for a hetero-basic version. -/ lemma rankAtStalk_tensorProduct (N : Type*) [AddCommGroup N] [Module R N] [Module.Finite R N] [Module.Flat R N] : rankAtStalk (M ⊗[R] N) = rankAtStalk M * rankAtStalk (R := R) N := by ext p let e : Localization.AtPrime p.asIdeal ⊗[R] (M ⊗[R] N) ≃ₗ[Localization.AtPrime p.asIdeal] (Localization.AtPrime p.asIdeal ⊗[R] M) ⊗[Localization.AtPrime p.asIdeal] (Localization.AtPrime p.asIdeal ⊗[R] N) := (AlgebraTensorModule.assoc _ _ _ _ _ _).symm ≪≫ₗ (AlgebraTensorModule.cancelBaseChange _ _ _ _ _).symm rw [rankAtStalk_eq_finrank_tensorProduct, e.finrank_eq, finrank_tensorProduct, ← rankAtStalk_eq_finrank_tensorProduct, ← rankAtStalk_eq_finrank_tensorProduct, Pi.mul_apply] lemma rankAtStalk_tensorProduct_of_isScalarTower {S : Type*} [CommRing S] [Algebra R S] (N : Type*) [AddCommGroup N] [Module R N] [Module S N] [IsScalarTower R S N] [Module.Finite S N] [Module.Flat S N] (p : PrimeSpectrum S) : rankAtStalk (N ⊗[R] M) p = rankAtStalk N p * rankAtStalk M ((algebraMap R S).specComap p) := by simp [rankAtStalk_eq_of_equiv (AlgebraTensorModule.cancelBaseChange R S S N M).symm, rankAtStalk_tensorProduct, rankAtStalk_baseChange] /-- The rank of a module `M` at a prime `p` is equal to the dimension of `κ(p) ⊗[R] M` as a `κ(p)`-module. -/ lemma rankAtStalk_eq (p : PrimeSpectrum R) : rankAtStalk M p = finrank p.asIdeal.ResidueField (p.asIdeal.ResidueField ⊗[R] M) := by let k := p.asIdeal.ResidueField let e : k ⊗[Localization.AtPrime p.asIdeal] (Localization.AtPrime p.asIdeal ⊗[R] M) ≃ₗ[k] k ⊗[R] M := AlgebraTensorModule.cancelBaseChange _ _ _ _ _ rw [← e.finrank_eq, finrank_baseChange, rankAtStalk_eq_finrank_tensorProduct] end Module
.lake/packages/mathlib/Mathlib/RingTheory/Spectrum/Prime/ConstructibleSet.lean
import Mathlib.Order.SuccPred.WithBot import Mathlib.RingTheory.Spectrum.Prime.Topology /-! # Constructible sets in the prime spectrum This file provides tooling for manipulating constructible sets in the prime spectrum of a ring. -/ open Finset Topology open scoped Polynomial namespace PrimeSpectrum variable {R S T : Type*} [CommSemiring R] [CommSemiring S] [CommSemiring T] variable (R) in /-- The data of a basic constructible set `s` is a tuple `(f, g₁, ..., gₙ)` -/ @[ext] structure BasicConstructibleSetData where /-- Given the data of a basic constructible set `s = V(g₁, ..., gₙ) \ V(f)`, return `f`. -/ protected f : R /-- Given the data of a basic constructible set `s = V(g₁, ..., gₙ) \ V(f)`, return `n`. -/ protected n : ℕ /-- Given the data of a basic constructible set `s = V(g₁, ..., gₙ) \ V(f)`, return `g`. -/ protected g : Fin n → R namespace BasicConstructibleSetData noncomputable instance : DecidableEq (BasicConstructibleSetData R) := Classical.decEq _ /-- Given the data of the constructible set `s`, build the data of the constructible set `{I | {x | φ x ∈ I} ∈ s}`. -/ @[simps] noncomputable def map (φ : R →+* S) (C : BasicConstructibleSetData R) : BasicConstructibleSetData S where f := φ C.f n := C.n g := φ ∘ C.g @[simp] lemma map_id (C : BasicConstructibleSetData R) : C.map (.id _) = C := by simp [map] @[simp] lemma map_id' : map (.id R) = id := by ext : 1; simp lemma map_comp (φ : S →+* T) (ψ : R →+* S) (C : BasicConstructibleSetData R) : C.map (φ.comp ψ) = (C.map ψ).map φ := by simp [map, Function.comp_def] lemma map_comp' (φ : S →+* T) (ψ : R →+* S) : map (φ.comp ψ) = map φ ∘ map ψ := by ext : 1; simp [map_comp] /-- Given the data of a basic constructible set `s`, namely a tuple `(f, g₁, ..., gₙ)` such that `s = V(g₁, ..., gₙ) \ V(f)`, return `s`. -/ def toSet (C : BasicConstructibleSetData R) : Set (PrimeSpectrum R) := zeroLocus (Set.range C.g) \ zeroLocus {C.f} @[simp] lemma toSet_map (φ : R →+* S) (C : BasicConstructibleSetData R) : (C.map φ).toSet = comap φ ⁻¹' C.toSet := by simp [toSet, map, ← Set.range_comp] end BasicConstructibleSetData variable (R) in /-- The data of a constructible set `s` in the prime spectrum of a ring is finitely many tuples `(f, g₁, ..., gₙ)` such that `s = ⋃ (f, g₁, ..., gₙ), V(g₁, ..., gₙ) \ V(f)`. To obtain `s` from its data, use `PrimeSpectrum.ConstructibleSetData.toSet`. -/ abbrev ConstructibleSetData := Finset (BasicConstructibleSetData R) namespace ConstructibleSetData /-- Given the data of the constructible set `s`, build the data of the constructible set `{I | {x | f x ∈ I} ∈ s}`. -/ noncomputable def map (φ : R →+* S) (s : ConstructibleSetData R) : ConstructibleSetData S := s.image (.map φ) @[simp] lemma map_id (s : ConstructibleSetData R) : s.map (.id _) = s := by simp [map] lemma map_comp (f : S →+* T) (g : R →+* S) (s : ConstructibleSetData R) : s.map (f.comp g) = (s.map g).map f := by simp [map, image_image, Function.comp_def, BasicConstructibleSetData.map_comp'] /-- Given the data of a constructible set `s`, namely finitely many tuples `(f, g₁, ..., gₙ)` such that `s = ⋃ (f, g₁, ..., gₙ), V(g₁, ..., gₙ) \ V(f)`, return `s`. -/ def toSet (S : ConstructibleSetData R) : Set (PrimeSpectrum R) := ⋃ C ∈ S, C.toSet @[simp] lemma toSet_map (f : R →+* S) (s : ConstructibleSetData R) : (s.map f).toSet = comap f ⁻¹' s.toSet := by unfold toSet map rw [set_biUnion_finset_image] simp /-- The degree bound on a constructible set for Chevalley's theorem for the inclusion `R ↪ R[X]`. -/ def degBound (S : ConstructibleSetData R[X]) : ℕ := S.sup fun C ↦ ∑ i, (C.g i).degree.succ lemma isConstructible_toSet (S : ConstructibleSetData R) : IsConstructible S.toSet := by refine .biUnion S.finite_toSet fun _ _ ↦ .sdiff ?_ ?_ · rw [← isConstructible_compl] exact (isRetrocompact_zeroLocus_compl (Set.finite_range _)).isConstructible (isClosed_zeroLocus _).isOpen_compl · rw [← isConstructible_compl] exact (isRetrocompact_zeroLocus_compl (Set.finite_singleton _)).isConstructible (isClosed_zeroLocus _).isOpen_compl end ConstructibleSetData lemma exists_constructibleSetData_iff {s : Set (PrimeSpectrum R)} : (∃ S : ConstructibleSetData R, S.toSet = s) ↔ IsConstructible s := by refine ⟨fun ⟨S, H⟩ ↦ H ▸ S.isConstructible_toSet, fun H ↦ ?_⟩ induction s, H using IsConstructible.induction_of_isTopologicalBasis _ (isTopologicalBasis_basic_opens (R := R)) with | isCompact_basis i => exact isCompact_basicOpen _ | sdiff i s hs => have : Finite s := hs refine ⟨{⟨i, Nat.card s, fun i ↦ ((Finite.equivFin s).symm i).1⟩}, ?_⟩ simp only [ConstructibleSetData.toSet, Finset.mem_singleton, BasicConstructibleSetData.toSet, Set.iUnion_iUnion_eq_left, basicOpen_eq_zeroLocus_compl, ← Set.compl_iInter₂, compl_sdiff_compl, ← zeroLocus_iUnion₂, Set.biUnion_of_singleton] congr! 2 ext simp [← (Finite.equivFin s).exists_congr_right, - Nat.card_coe_set_eq] | union s hs t ht Hs Ht => obtain ⟨S, rfl⟩ := Hs obtain ⟨T, rfl⟩ := Ht refine ⟨S ∪ T, ?_⟩ simp only [ConstructibleSetData.toSet, Set.biUnion_union, ← Finset.mem_coe, Finset.coe_union] universe u in @[stacks 00F8 "without the finite presentation part"] -- TODO: show that the constructed `f` is of finite presentation lemma exists_range_eq_of_isConstructible {R : Type u} [CommRing R] {s : Set (PrimeSpectrum R)} (hs : IsConstructible s) : ∃ (S : Type u) (_ : CommRing S) (f : R →+* S), Set.range (comap f) = s := by obtain ⟨s, rfl⟩ := exists_constructibleSetData_iff.mpr hs refine ⟨Π i : s, Localization.Away (Ideal.Quotient.mk (Ideal.span (Set.range i.1.g)) i.1.f), inferInstance, algebraMap _ _, ?_⟩ rw [coe_comap, ← iUnion_range_specComap_comp_evalRingHom, ConstructibleSetData.toSet] simp_rw [← Finset.mem_coe, Set.biUnion_eq_iUnion] congr! with _ _ C let I := Ideal.span (Set.range C.1.g) let f := Ideal.Quotient.mk I C.1.f trans comap (Ideal.Quotient.mk I) '' (Set.range (comap (algebraMap _ (Localization.Away f)))) · rw [← Set.range_comp]; rfl · rw [localization_away_comap_range _ f, ← comap_basicOpen, TopologicalSpace.Opens.coe_comap, Set.image_preimage_eq_inter_range, range_comap_of_surjective _ _ Ideal.Quotient.mk_surjective, BasicConstructibleSetData.toSet, Set.diff_eq_compl_inter, basicOpen_eq_zeroLocus_compl, Ideal.mk_ker, zeroLocus_span] @[stacks 00I0 "(1)"] lemma isClosed_of_stableUnderSpecialization_of_isConstructible {R : Type*} [CommRing R] {s : Set (PrimeSpectrum R)} (hs : StableUnderSpecialization s) (hs' : IsConstructible s) : IsClosed s := by obtain ⟨S, _, f, rfl⟩ := exists_range_eq_of_isConstructible hs' exact isClosed_range_of_stableUnderSpecialization _ hs @[stacks 00I0 "(1)"] lemma isOpen_of_stableUnderGeneralization_of_isConstructible {R : Type*} [CommRing R] {s : Set (PrimeSpectrum R)} (hs : StableUnderGeneralization s) (hs' : IsConstructible s) : IsOpen s := by rw [← isClosed_compl_iff] exact isClosed_of_stableUnderSpecialization_of_isConstructible hs.compl hs'.compl end PrimeSpectrum
.lake/packages/mathlib/Mathlib/RingTheory/Spectrum/Prime/Polynomial.lean
import Mathlib.LinearAlgebra.Charpoly.BaseChange import Mathlib.LinearAlgebra.Eigenspace.Zero import Mathlib.RingTheory.AdjoinRoot import Mathlib.RingTheory.LocalRing.ResidueField.Ideal import Mathlib.RingTheory.Spectrum.Prime.Topology import Mathlib.RingTheory.TensorProduct.MvPolynomial /-! # Prime spectrum of (multivariate) polynomials Also see `AlgebraicGeometry/AffineSpace` for the affine space over arbitrary schemes. ## Main results - `isNilpotent_tensor_residueField_iff`: If `A` is a finite free `R`-algebra, then `f : A` is nilpotent on `κ(𝔭) ⊗ A` for some prime `𝔭 ◃ R` if and only if every non-leading coefficient of `charpoly(f)` is in `𝔭`. - `Polynomial.exists_image_comap_of_monic`: If `g : R[X]` is monic, the image of `Z(g) ∩ D(f) : Spec R[X]` in `Spec R` is compact open. - `Polynomial.isOpenMap_comap_C`: The structure map `Spec R[X] → Spec R` is an open map. - `MvPolynomial.isOpenMap_comap_C`: The structure map `Spec R[X̲] → Spec R` is an open map. -/ open Polynomial TensorProduct PrimeSpectrum variable {R M A} [CommRing R] [AddCommGroup M] [Module R M] [CommRing A] [Algebra R A] /-- If `A` is a finite free `R`-algebra, then `f : A` is nilpotent on `κ(𝔭) ⊗ A` for some prime `𝔭 ◃ R` if and only if every non-leading coefficient of `charpoly(f)` is in `𝔭`. -/ lemma isNilpotent_tensor_residueField_iff [Module.Free R A] [Module.Finite R A] (f : A) (I : Ideal R) [I.IsPrime] : IsNilpotent (algebraMap A (A ⊗[R] I.ResidueField) f) ↔ ∀ i < Module.finrank R A, (Algebra.lmul R A f).charpoly.coeff i ∈ I := by cases subsingleton_or_nontrivial R · have := (algebraMap R (A ⊗[R] I.ResidueField)).codomain_trivial simp [Subsingleton.elim I ⊤, Subsingleton.elim (f ⊗ₜ[R] (1 : I.ResidueField)) 0] have : Module.finrank I.ResidueField (I.ResidueField ⊗[R] A) = Module.finrank R A := by rw [Module.finrank_tensorProduct, Module.finrank_self, one_mul] rw [← IsNilpotent.map_iff (Algebra.TensorProduct.comm R A I.ResidueField).injective] simp only [Algebra.TensorProduct.algebraMap_apply, Algebra.algebraMap_self, RingHom.id_apply, Algebra.coe_lmul_eq_mul, Algebra.TensorProduct.comm_tmul] rw [← IsNilpotent.map_iff (Algebra.lmul_injective (R := I.ResidueField)), LinearMap.isNilpotent_iff_charpoly, ← Algebra.baseChange_lmul, LinearMap.charpoly_baseChange] simp_rw [this, ← ((LinearMap.mul R A) f).charpoly_natDegree] constructor · intro e i hi replace e := congr(($e).coeff i) simpa only [Algebra.coe_lmul_eq_mul, coeff_map, coeff_X_pow, hi.ne, ↓reduceIte, ← RingHom.mem_ker, Ideal.ker_algebraMap_residueField] using e · intro H ext i obtain (hi | hi) := eq_or_ne i ((LinearMap.mul R A) f).charpoly.natDegree · simp only [Algebra.coe_lmul_eq_mul, hi, coeff_map, coeff_X_pow, ↓reduceIte] rw [← Polynomial.leadingCoeff, ((LinearMap.mul R A) f).charpoly_monic, map_one] obtain (hi | hi) := lt_or_gt_of_ne hi · simpa [hi.ne, ← RingHom.mem_ker, Ideal.ker_algebraMap_residueField] using H i hi · simp [hi.ne', coeff_eq_zero_of_natDegree_lt hi] namespace PrimeSpectrum /-- Let `A` be an `R`-algebra. `𝔭 : Spec R` is in the image of `Z(I) ∩ D(f) ⊆ Spec S` if and only if `f` is not nilpotent on `κ(𝔭) ⊗ A ⧸ I`. -/ lemma mem_image_comap_zeroLocus_sdiff (f : A) (s : Set A) (x) : x ∈ comap (algebraMap R A) '' (zeroLocus s \ zeroLocus {f}) ↔ ¬ IsNilpotent (algebraMap A ((A ⧸ Ideal.span s) ⊗[R] x.asIdeal.ResidueField) f) := by constructor · rintro ⟨q, ⟨hqg, hqf⟩, rfl⟩ H simp only [mem_zeroLocus, Set.singleton_subset_iff, SetLike.mem_coe] at hqg hqf have hs : Ideal.span s ≤ RingHom.ker (algebraMap A q.asIdeal.ResidueField) := by rwa [Ideal.span_le, Ideal.ker_algebraMap_residueField] let F : (A ⧸ Ideal.span s) ⊗[R] (q.asIdeal.comap (algebraMap R A)).ResidueField →ₐ[A] q.asIdeal.ResidueField := Algebra.TensorProduct.lift (Ideal.Quotient.liftₐ (Ideal.span s) (Algebra.ofId A _) hs) (Ideal.ResidueField.mapₐ _ _ rfl) fun _ _ ↦ .all _ _ have := H.map F rw [AlgHom.commutes, isNilpotent_iff_eq_zero, ← RingHom.mem_ker, Ideal.ker_algebraMap_residueField] at this exact hqf this · intro H rw [← mem_nilradical, nilradical_eq_sInf, Ideal.mem_sInf] at H simp only [Set.mem_setOf_eq, Algebra.TensorProduct.algebraMap_apply, Ideal.Quotient.algebraMap_eq, not_forall] at H obtain ⟨q, hq, hfq⟩ := H have : ∀ a ∈ s, Ideal.Quotient.mk (Ideal.span s) a ⊗ₜ[R] 1 ∈ q := fun a ha ↦ by simp [Ideal.Quotient.eq_zero_iff_mem.mpr (Ideal.subset_span ha)] refine ⟨comap (algebraMap A _) ⟨q, hq⟩, ⟨by simpa [Set.subset_def], by simpa⟩, ?_⟩ rw [← comap_comp_apply, ← IsScalarTower.algebraMap_eq, ← Algebra.TensorProduct.includeRight.comp_algebraMap, comap_comp_apply, Subsingleton.elim (α := PrimeSpectrum x.asIdeal.ResidueField) (comap _ _) ⊥] ext a exact congr(a ∈ $(Ideal.ker_algebraMap_residueField _)) /-- Let `A` be an `R`-algebra. `𝔭 : Spec R` is in the image of `D(f) ⊆ Spec S` if and only if `f` is not nilpotent on `κ(𝔭) ⊗ A`. -/ lemma mem_image_comap_basicOpen (f : A) (x) : x ∈ comap (algebraMap R A) '' basicOpen f ↔ ¬ IsNilpotent (algebraMap A (A ⊗[R] x.asIdeal.ResidueField) f) := by have e : A ⊗[R] x.asIdeal.ResidueField ≃ₐ[A] (A ⧸ (Ideal.span ∅ : Ideal A)) ⊗[R] x.asIdeal.ResidueField := by refine Algebra.TensorProduct.congr ?f AlgEquiv.refl rw [Ideal.span_empty] exact { __ := (RingEquiv.quotientBot A).symm, __ := Algebra.ofId _ _ } rw [← IsNilpotent.map_iff e.injective, AlgEquiv.commutes, ← mem_image_comap_zeroLocus_sdiff f ∅ x, zeroLocus_empty, ← Set.compl_eq_univ_diff, basicOpen_eq_zeroLocus_compl] /-- Let `A` be an `R`-algebra. If `A ⧸ I` is finite free over `R`, then the image of `Z(I) ∩ D(f) ⊆ Spec S` in `Spec R` is compact open. -/ lemma exists_image_comap_of_finite_of_free (f : A) (s : Set A) [Module.Finite R (A ⧸ Ideal.span s)] [Module.Free R (A ⧸ Ideal.span s)] : ∃ t : Finset R, comap (algebraMap R A) '' (zeroLocus s \ zeroLocus {f}) = (zeroLocus t)ᶜ := by classical use (Finset.range (Module.finrank R (A ⧸ Ideal.span s))).image (Algebra.lmul R (A ⧸ Ideal.span s) (Ideal.Quotient.mk _ f)).charpoly.coeff ext x rw [mem_image_comap_zeroLocus_sdiff, IsScalarTower.algebraMap_apply A (A ⧸ Ideal.span s), isNilpotent_tensor_residueField_iff] simp [Set.subset_def] end PrimeSpectrum namespace Polynomial lemma mem_image_comap_C_basicOpen (f : R[X]) (x : PrimeSpectrum R) : x ∈ comap C '' basicOpen f ↔ ∃ i, f.coeff i ∉ x.asIdeal := by trans f.map (algebraMap R x.asIdeal.ResidueField) ≠ 0 · refine (mem_image_comap_basicOpen _ _).trans (not_iff_not.mpr ?_) let e : R[X] ⊗[R] x.asIdeal.ResidueField ≃ₐ[R] x.asIdeal.ResidueField[X] := (Algebra.TensorProduct.comm R _ _).trans (polyEquivTensor R x.asIdeal.ResidueField).symm rw [← IsNilpotent.map_iff e.injective, isNilpotent_iff_eq_zero] change (e.toAlgHom.toRingHom).comp (algebraMap _ _) f = 0 ↔ Polynomial.mapRingHom _ f = 0 congr! ext1 · ext; simp [e] · simp [e] · simp [Polynomial.ext_iff] lemma image_comap_C_basicOpen (f : R[X]) : comap C '' basicOpen f = (zeroLocus (Set.range f.coeff))ᶜ := by ext p rw [mem_image_comap_C_basicOpen] simp [Set.range_subset_iff] lemma isOpenMap_comap_C : IsOpenMap (comap (R := R) C) := by intro U hU obtain ⟨S, hS, rfl⟩ := isTopologicalBasis_basic_opens.open_eq_sUnion hU rw [Set.image_sUnion] apply isOpen_sUnion rintro _ ⟨t, ht, rfl⟩ obtain ⟨r, rfl⟩ := hS ht simp only [image_comap_C_basicOpen] exact (isClosed_zeroLocus _).isOpen_compl lemma comap_C_surjective : Function.Surjective (comap (R := R) C) := by intro x refine ⟨comap (evalRingHom 0) x, ?_⟩ rw [← comap_comp_apply, (show (evalRingHom 0).comp C = .id R by ext; simp), comap_id, ContinuousMap.id_apply] lemma exists_image_comap_of_monic (f g : R[X]) (hg : g.Monic) : ∃ t : Finset R, comap C '' (zeroLocus {g} \ zeroLocus {f}) = (zeroLocus t)ᶜ := by apply (config := { allowSynthFailures := true }) exists_image_comap_of_finite_of_free · exact .of_basis (AdjoinRoot.powerBasis' hg).basis · exact .of_basis (AdjoinRoot.powerBasis' hg).basis lemma isCompact_image_comap_of_monic (f g : R[X]) (hg : g.Monic) : IsCompact (comap C '' (zeroLocus {g} \ zeroLocus {f})) := by obtain ⟨t, ht⟩ := exists_image_comap_of_monic f g hg rw [ht, ← (t : Set R).iUnion_of_singleton_coe, zeroLocus_iUnion, Set.compl_iInter] apply isCompact_iUnion exact fun _ ↦ by simpa using isCompact_basicOpen _ lemma isOpen_image_comap_of_monic (f g : R[X]) (hg : g.Monic) : IsOpen (comap C '' (zeroLocus {g} \ zeroLocus {f})) := by obtain ⟨t, ht⟩ := exists_image_comap_of_monic f g hg rw [ht] exact (isClosed_zeroLocus (R := R) t).isOpen_compl end Polynomial namespace MvPolynomial variable {σ : Type*} lemma mem_image_comap_C_basicOpen (f : MvPolynomial σ R) (x : PrimeSpectrum R) : x ∈ comap (C (σ := σ)) '' basicOpen f ↔ ∃ i, f.coeff i ∉ x.asIdeal := by classical trans f.map (algebraMap R x.asIdeal.ResidueField) ≠ 0 · refine (mem_image_comap_basicOpen _ _).trans (not_iff_not.mpr ?_) let e : MvPolynomial σ R ⊗[R] x.asIdeal.ResidueField ≃ₐ[R] MvPolynomial σ x.asIdeal.ResidueField := scalarRTensorAlgEquiv rw [← IsNilpotent.map_iff e.injective, isNilpotent_iff_eq_zero] change (e.toAlgHom.toRingHom).comp (algebraMap _ _) f = 0 ↔ MvPolynomial.map _ f = 0 congr! ext · simp [scalarRTensorAlgEquiv, e, coeff_map, Algebra.smul_def, apply_ite (f := algebraMap _ _)] · simp [e, scalarRTensorAlgEquiv, coeff_map, coeff_X'] · simp [MvPolynomial.ext_iff, coeff_map] lemma image_comap_C_basicOpen (f : MvPolynomial σ R) : comap (C (σ := σ)) '' basicOpen f = (zeroLocus (Set.range f.coeff))ᶜ := by ext p rw [mem_image_comap_C_basicOpen] simp [Set.range_subset_iff] lemma isOpenMap_comap_C : IsOpenMap (comap (R := R) (C (σ := σ))) := by intro U hU obtain ⟨S, hS, rfl⟩ := isTopologicalBasis_basic_opens.open_eq_sUnion hU rw [Set.image_sUnion] apply isOpen_sUnion rintro _ ⟨t, ht, rfl⟩ obtain ⟨r, rfl⟩ := hS ht simp only [image_comap_C_basicOpen] exact (isClosed_zeroLocus _).isOpen_compl lemma comap_C_surjective : Function.Surjective (comap (R := R) (C (σ := σ))) := by intro x refine ⟨comap (eval₂Hom (.id _) 0) x, ?_⟩ rw [← comap_comp_apply, (show (eval₂Hom (.id _) 0).comp C = .id R by ext; simp), comap_id, ContinuousMap.id_apply] end MvPolynomial
.lake/packages/mathlib/Mathlib/RingTheory/Spectrum/Prime/Jacobson.lean
import Mathlib.RingTheory.Jacobson.Ring import Mathlib.RingTheory.Spectrum.Prime.Noetherian import Mathlib.Topology.JacobsonSpace /-! # The prime spectrum of a Jacobson ring ## Main results - `PrimeSpectrum.exists_isClosed_singleton_of_isJacobson`: The spectrum of a Jacobson ring is a Jacobson space. - `PrimeSpectrum.isOpen_singleton_tfae_of_isNoetherian_of_isJacobson`: If `R` is both Noetherian and Jacobson, then the following are equivalent for `x : Spec R`: 1. `{x}` is open (i.e. `x` is an isolated point) 2. `{x}` is clopen 3. `{x}` is both closed and stable under generalization (i.e. `x` is both a minimal prime and a maximal ideal) -/ open Ideal variable {R : Type*} [CommRing R] namespace PrimeSpectrum lemma exists_isClosed_singleton_of_isJacobsonRing [IsJacobsonRing R] (s : (Set (PrimeSpectrum R))) (hs : IsOpen s) (hs' : s.Nonempty) : ∃ x ∈ s, IsClosed {x} := by simp_rw [isClosed_singleton_iff_isMaximal] obtain ⟨I, hI'⟩ := (isClosed_iff_zeroLocus_ideal _).mp hs.isClosed_compl simp_rw [← @Set.notMem_compl_iff _ s, hI', mem_zeroLocus] have := hs'.ne_empty contrapose! this simp_rw [not_imp_not] at this rw [← Set.compl_univ, eq_compl_comm, hI', eq_comm, ← zeroLocus_bot, zeroLocus_eq_iff, Ideal.radical_eq_jacobson, Ideal.radical_eq_jacobson] refine le_antisymm (le_sInf ?_) (Ideal.jacobson_mono bot_le) rintro x ⟨-, hx⟩ exact sInf_le ⟨this ⟨x, hx.isPrime⟩ hx, hx⟩ instance [IsJacobsonRing R] : JacobsonSpace (PrimeSpectrum R) := by rw [jacobsonSpace_iff_locallyClosed] rintro S hS ⟨U, Z, hU, hZ, rfl⟩ simp only [← isClosed_compl_iff, isClosed_iff_zeroLocus_ideal, @compl_eq_comm _ U] at hU hZ obtain ⟨⟨I, rfl⟩, ⟨J, rfl⟩⟩ := And.intro hU hZ simp only [Set.nonempty_iff_ne_empty, ne_eq, Set.inter_assoc, ← Set.disjoint_iff_inter_eq_empty, Set.disjoint_compl_left_iff_subset, zeroLocus_subset_zeroLocus_iff, Ideal.radical_eq_jacobson, Ideal.jacobson, le_sInf_iff] at hS ⊢ contrapose! hS rintro x ⟨hJx, hx⟩ exact @hS ⟨x, hx.isPrime⟩ ⟨hJx, (isClosed_singleton_iff_isMaximal _).mpr hx⟩ lemma isJacobsonRing_iff_jacobsonSpace : IsJacobsonRing R ↔ JacobsonSpace (PrimeSpectrum R) := by refine ⟨fun _ ↦ inferInstance, fun H ↦ ⟨fun I hI ↦ le_antisymm ?_ Ideal.le_jacobson⟩⟩ rw [← I.isRadical_jacobson.radical] conv_rhs => rw [← hI.radical] simp_rw [← vanishingIdeal_zeroLocus_eq_radical] apply vanishingIdeal_anti_mono rw [← H.1 (isClosed_zeroLocus I), (isClosed_zeroLocus _).closure_subset_iff] rintro x ⟨hx : I ≤ x.asIdeal, hx'⟩ change jacobson I ≤ x.asIdeal exact sInf_le ⟨hx, (isClosed_singleton_iff_isMaximal _).mp hx'⟩ /-- If `R` is both Noetherian and Jacobson, then the following are equivalent for `x : Spec R`: 1. `{x}` is open (i.e. `x` is an isolated point) 2. `{x}` is clopen 3. `{x}` is both closed and stable under generalization (i.e. `x` is both a minimal prime and a maximal ideal) -/ lemma isOpen_singleton_tfae_of_isNoetherian_of_isJacobsonRing [IsNoetherianRing R] [IsJacobsonRing R] (x : PrimeSpectrum R) : List.TFAE [IsOpen {x}, IsClopen {x}, IsClosed {x} ∧ StableUnderGeneralization {x}] := by tfae_have 1 → 2 | h => by obtain ⟨y, rfl : y = x, h'⟩ := exists_isClosed_singleton_of_isJacobsonRing _ h ⟨x, Set.mem_singleton x⟩ exact ⟨h', h⟩ tfae_have 2 → 3 | h => ⟨h.isClosed, h.isOpen.stableUnderGeneralization⟩ tfae_have 3 → 1 | ⟨h₁, h₂⟩ => by rw [isClosed_singleton_iff_isMaximal, ← isMax_iff] at h₁ suffices {x} = (⋃ p ∈ { p : PrimeSpectrum R | IsMin p ∧ p ≠ x }, closure {p})ᶜ by rw [this, isOpen_compl_iff] refine Set.Finite.isClosed_biUnion ?_ (fun _ _ ↦ isClosed_closure) exact (finite_setOf_isMin R).subset fun x h ↦ h.1 ext p simp only [Set.mem_singleton_iff, ne_eq, Set.mem_setOf_eq, Set.compl_iUnion, Set.mem_iInter, Set.mem_compl_iff, and_imp, ← specializes_iff_mem_closure, ← le_iff_specializes, not_imp_not] constructor · rintro rfl _ _ rw [stableUnderGeneralization_singleton, ← isMin_iff] at h₂ exact h₂.eq_of_le · intro hp apply h₁.eq_of_ge obtain ⟨q, hq, hq'⟩ := Ideal.exists_minimalPrimes_le (J := p.asIdeal) bot_le exact (hp ⟨q, hq.1.1⟩ (isMin_iff.mpr hq) hq').ge.trans hq' tfae_finish end PrimeSpectrum
.lake/packages/mathlib/Mathlib/RingTheory/Spectrum/Prime/Noetherian.lean
import Mathlib.RingTheory.Spectrum.Prime.Topology import Mathlib.RingTheory.Ideal.Quotient.Noetherian import Mathlib.RingTheory.Artinian.Module import Mathlib.Topology.NoetherianSpace /-! This file proves additional properties of the prime spectrum a ring is Noetherian. -/ universe u v namespace PrimeSpectrum open TopologicalSpace section IsNoetherianRing variable (R : Type u) [CommRing R] [IsNoetherianRing R] instance : NoetherianSpace (PrimeSpectrum R) := ((noetherianSpace_TFAE <| PrimeSpectrum R).out 0 1).mpr (closedsEmbedding R).dual.wellFoundedLT lemma _root_.minimalPrimes.finite_of_isNoetherianRing : (minimalPrimes R).Finite := minimalPrimes.equivIrreducibleComponents R |>.set_finite_iff |>.mpr NoetherianSpace.finite_irreducibleComponents lemma finite_setOf_isMin : {x : PrimeSpectrum R | IsMin x}.Finite := by have : Function.Injective (asIdeal (R := R)) := @PrimeSpectrum.ext _ _ refine Set.Finite.of_finite_image (f := asIdeal) ?_ this.injOn simp_rw [isMin_iff] exact (minimalPrimes.finite_of_isNoetherianRing R).subset (Set.image_preimage_subset _ _) lemma _root_.Ideal.finite_minimalPrimes_of_isNoetherianRing (I : Ideal R) : I.minimalPrimes.Finite := by rw [I.minimalPrimes_eq_comap] apply Set.Finite.image apply minimalPrimes.finite_of_isNoetherianRing end IsNoetherianRing section IsArtinianRing variable (R : Type u) [CommRing R] [IsArtinianRing R] instance : Ring.KrullDimLE 0 R := .mk₀ fun _ _ ↦ inferInstance instance : DiscreteTopology (PrimeSpectrum R) := discreteTopology_iff_finite_and_krullDimLE_zero.mpr ⟨inferInstance, inferInstance⟩ end IsArtinianRing end PrimeSpectrum
.lake/packages/mathlib/Mathlib/RingTheory/Spectrum/Prime/IsOpenComapC.lean
import Mathlib.RingTheory.Polynomial.Basic import Mathlib.RingTheory.Spectrum.Prime.Topology /-! The morphism `Spec R[x] --> Spec R` induced by the natural inclusion `R --> R[x]` is an open map. The main result is the first part of the statement of Lemma 00FB in the Stacks Project. https://stacks.math.columbia.edu/tag/00FB -/ open Ideal Polynomial PrimeSpectrum Set namespace AlgebraicGeometry namespace Polynomial variable {R : Type*} [CommRing R] {f : R[X]} /-- Given a polynomial `f ∈ R[x]`, `imageOfDf` is the subset of `Spec R` where at least one of the coefficients of `f` does not vanish. Lemma `imageOfDf_eq_comap_C_compl_zeroLocus` proves that `imageOfDf` is the image of `(zeroLocus {f})ᶜ` under the morphism `comap C : Spec R[x] → Spec R`. -/ def imageOfDf (f : R[X]) : Set (PrimeSpectrum R) := { p : PrimeSpectrum R | ∃ i : ℕ, coeff f i ∉ p.asIdeal } theorem isOpen_imageOfDf : IsOpen (imageOfDf f) := by rw [imageOfDf, setOf_exists fun i (x : PrimeSpectrum R) => coeff f i ∉ x.asIdeal] exact isOpen_iUnion fun i => isOpen_basicOpen /-- If a point of `Spec R[x]` is not contained in the vanishing set of `f`, then its image in `Spec R` is contained in the open set where at least one of the coefficients of `f` is non-zero. This lemma is a reformulation of `exists_C_coeff_notMem`. -/ theorem comap_C_mem_imageOfDf {I : PrimeSpectrum R[X]} (H : I ∈ (zeroLocus {f} : Set (PrimeSpectrum R[X]))ᶜ) : PrimeSpectrum.comap (Polynomial.C : R →+* R[X]) I ∈ imageOfDf f := exists_C_coeff_notMem (mem_compl_zeroLocus_iff_notMem.mp H) /-- The open set `imageOfDf f` coincides with the image of `basicOpen f` under the morphism `C⁺ : Spec R[x] → Spec R`. -/ theorem imageOfDf_eq_comap_C_compl_zeroLocus : imageOfDf f = PrimeSpectrum.comap (C : R →+* R[X]) '' (zeroLocus {f})ᶜ := by ext x refine ⟨fun hx => ⟨⟨map C x.asIdeal, isPrime_map_C_of_isPrime x.isPrime⟩, ⟨?_, ?_⟩⟩, ?_⟩ · rw [mem_compl_iff, mem_zeroLocus, singleton_subset_iff] obtain ⟨i, hi⟩ := hx exact fun a => hi (mem_map_C_iff.mp a i) · ext x refine ⟨fun h => ?_, fun h => subset_span (mem_image_of_mem C.1 h)⟩ rw [← @coeff_C_zero R x _] exact mem_map_C_iff.mp h 0 · rintro ⟨xli, complement, rfl⟩ exact comap_C_mem_imageOfDf complement /-- The morphism `C⁺ : Spec R[x] → Spec R` is open. -/ @[stacks 00FB "First part"] theorem isOpenMap_comap_C : IsOpenMap (PrimeSpectrum.comap (C : R →+* R[X])) := by rintro U ⟨s, z⟩ rw [← compl_compl U, ← z, ← iUnion_of_singleton_coe s, zeroLocus_iUnion, compl_iInter, image_iUnion] simp_rw [← imageOfDf_eq_comap_C_compl_zeroLocus] exact isOpen_iUnion fun f => isOpen_imageOfDf end Polynomial end AlgebraicGeometry
.lake/packages/mathlib/Mathlib/RingTheory/Spectrum/Maximal/Topology.lean
import Mathlib.RingTheory.Spectrum.Maximal.Basic import Mathlib.RingTheory.Spectrum.Prime.Topology /-! # The Zariski topology on the maximal spectrum of a commutative (semi)ring ## 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 universe u v variable (R : Type u) [CommRing R] variable {R} namespace MaximalSpectrum open PrimeSpectrum Set theorem toPrimeSpectrum_range : Set.range (@toPrimeSpectrum R _) = { x | IsClosed ({x} : Set <| PrimeSpectrum R) } := by simp only [isClosed_singleton_iff_isMaximal] ext ⟨x, _⟩ exact ⟨fun ⟨y, hy⟩ => hy ▸ y.isMaximal, fun hx => ⟨⟨x, hx⟩, rfl⟩⟩ /-- The Zariski topology on the maximal spectrum of a commutative ring is defined as the subspace topology induced by the natural inclusion into the prime spectrum. -/ instance zariskiTopology : TopologicalSpace <| MaximalSpectrum R := PrimeSpectrum.zariskiTopology.induced toPrimeSpectrum instance : T1Space <| MaximalSpectrum R := ⟨fun x => isClosed_induced_iff.mpr ⟨{toPrimeSpectrum x}, (isClosed_singleton_iff_isMaximal _).mpr x.isMaximal, by simpa only [← image_singleton] using preimage_image_eq {x} toPrimeSpectrum_injective⟩⟩ theorem toPrimeSpectrum_continuous : Continuous <| @toPrimeSpectrum R _ := continuous_induced_dom end MaximalSpectrum
.lake/packages/mathlib/Mathlib/RingTheory/Spectrum/Maximal/Basic.lean
import Mathlib.RingTheory.Spectrum.Maximal.Defs import Mathlib.RingTheory.Spectrum.Prime.Defs /-! # Maximal spectrum of a commutative (semi)ring Basic properties the maximal spectrum of a ring. -/ noncomputable section variable (R S P : Type*) [CommSemiring R] [CommSemiring S] [CommSemiring P] namespace MaximalSpectrum /-- The prime spectrum is in bijection with the set of prime ideals. -/ @[simps] def equivSubtype : MaximalSpectrum R ≃ {I : Ideal R // I.IsMaximal} where toFun I := ⟨I.asIdeal, I.2⟩ invFun I := ⟨I, I.2⟩ theorem range_asIdeal : Set.range MaximalSpectrum.asIdeal = {J : Ideal R | J.IsMaximal} := Set.ext fun J ↦ ⟨fun hJ ↦ let ⟨j, hj⟩ := Set.mem_range.mp hJ; Set.mem_setOf.mpr <| hj ▸ j.isMaximal, fun hJ ↦ Set.mem_range.mpr ⟨⟨J, Set.mem_setOf.mp hJ⟩, rfl⟩⟩ variable {R} 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 end MaximalSpectrum
.lake/packages/mathlib/Mathlib/RingTheory/Spectrum/Maximal/Defs.lean
import Mathlib.RingTheory.Ideal.Maximal /-! # Maximal spectrum of a commutative (semi)ring The maximal spectrum of a commutative (semi)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 (semi)ring `R`, i.e., the set of all maximal ideals of `R`. -/ /-- The maximal spectrum of a commutative (semi)ring `R` is the type of all maximal ideals of `R`. -/ @[ext] structure MaximalSpectrum (R : Type*) [CommSemiring R] where asIdeal : Ideal R isMaximal : asIdeal.IsMaximal attribute [instance] MaximalSpectrum.isMaximal
.lake/packages/mathlib/Mathlib/RingTheory/Spectrum/Maximal/Localization.lean
import Mathlib.RingTheory.Localization.AsSubring import Mathlib.RingTheory.Spectrum.Maximal.Basic import Mathlib.RingTheory.Spectrum.Prime.RingHom /-! # Maximal spectrum of a commutative (semi)ring Localization results. -/ noncomputable section variable (R S P : Type*) [CommSemiring R] [CommSemiring S] [CommSemiring P] namespace MaximalSpectrum variable {R} open PrimeSpectrum Set variable (R : Type*) variable [CommRing R] [IsDomain R] (K : Type*) [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 := (1 : Submodule R K).comap (LinearMap.toSpanSingleton R K x) have hdenom : (1 : R) ∉ denom := by simpa [denom] using hrange rcases denom.exists_le_maximal (denom.ne_top_iff_one.mpr hdenom) with ⟨max, hmax, hle⟩ rcases hlocal ⟨max, hmax⟩ with ⟨n, d, hd, rfl⟩ exact hd (hle ⟨n, by simp [Algebra.smul_def, mul_left_comm, mul_inv_cancel₀ <| (map_ne_zero_iff _ <| IsFractionRing.injective R K).mpr fun h ↦ hd (h ▸ 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 : Type*) variable [CommRing R] [IsDomain R] (K : Type*) [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 refine bot_unique (.trans (fun _ ↦ ?_) (MaximalSpectrum.iInf_localization_eq_bot R K).le) simpa only [Algebra.mem_iInf] using fun hx ⟨v, hv⟩ ↦ hx ⟨v, hv.isPrime⟩ end PrimeSpectrum namespace MaximalSpectrum /-- The product of localizations at all maximal ideals of a commutative semiring. -/ abbrev PiLocalization : Type _ := Π I : MaximalSpectrum R, Localization.AtPrime I.1 /-- The canonical ring homomorphism from a commutative semiring to the product of its localizations at all maximal ideals. It is always injective. -/ def toPiLocalization : R →+* PiLocalization R := algebraMap R _ theorem toPiLocalization_injective : Function.Injective (toPiLocalization R) := fun r r' eq ↦ by rw [← one_mul r, ← one_mul r'] by_contra ne have ⟨I, mI, hI⟩ := (Module.eqIdeal R r r').exists_le_maximal ((Ideal.ne_top_iff_one _).mpr ne) have ⟨s, hs⟩ := (IsLocalization.eq_iff_exists I.primeCompl _).mp (congr_fun eq ⟨I, mI⟩) exact s.2 (hI hs) theorem toPiLocalization_apply_apply {r I} : toPiLocalization R r I = algebraMap R _ r := rfl variable {R S} (f : R →+* S) (g : S →+* P) (hf : Function.Bijective f) (hg : Function.Bijective g) /-- Functoriality of `PiLocalization` but restricted to bijective ring homs. If R and S are commutative rings, surjectivity would be enough. -/ noncomputable def mapPiLocalization : PiLocalization R →+* PiLocalization S := Pi.ringHom fun I ↦ (Localization.localRingHom _ _ f rfl).comp <| Pi.evalRingHom _ (⟨_, I.2.comap_bijective f hf⟩ : MaximalSpectrum R) theorem mapPiLocalization_naturality : (mapPiLocalization f hf).comp (toPiLocalization R) = (toPiLocalization S).comp f := by ext r I change Localization.localRingHom _ _ _ rfl (algebraMap _ _ r) = algebraMap _ _ (f r) simp_rw [← IsLocalization.mk'_one (M := (I.1.comap f).primeCompl), Localization.localRingHom_mk', ← IsLocalization.mk'_one (M := I.1.primeCompl), Submonoid.coe_one, map_one f] rfl theorem mapPiLocalization_id : mapPiLocalization (.id R) Function.bijective_id = .id _ := RingHom.ext fun _ ↦ funext fun _ ↦ congr($(Localization.localRingHom_id _) _) theorem mapPiLocalization_comp : mapPiLocalization (g.comp f) (hg.comp hf) = (mapPiLocalization g hg).comp (mapPiLocalization f hf) := RingHom.ext fun _ ↦ funext fun _ ↦ congr($(Localization.localRingHom_comp _ _ _ _ rfl _ rfl) _) theorem mapPiLocalization_bijective : Function.Bijective (mapPiLocalization f hf) := by let f := RingEquiv.ofBijective f hf let e := RingEquiv.ofRingHom (mapPiLocalization f hf) (mapPiLocalization (f.symm : S →+* R) f.symm.bijective) ?_ ?_ · exact e.bijective · rw [← mapPiLocalization_comp] simp_rw [RingEquiv.comp_symm, mapPiLocalization_id] · rw [← mapPiLocalization_comp] simp_rw [RingEquiv.symm_comp, mapPiLocalization_id] section Pi variable {ι} (R : ι → Type*) [∀ i, CommSemiring (R i)] [∀ i, Nontrivial (R i)] theorem toPiLocalization_not_surjective_of_infinite [Infinite ι] : ¬ Function.Surjective (toPiLocalization (Π i, R i)) := fun surj ↦ by classical have ⟨J, max, notMem⟩ := PrimeSpectrum.exists_maximal_notMem_range_sigmaToPi_of_infinite R obtain ⟨r, hr⟩ := surj (Function.update 0 ⟨J, max⟩ 1) have : r = 0 := funext fun i ↦ toPiLocalization_injective _ <| funext fun I ↦ by replace hr := congr_fun hr ⟨_, I.2.comap_piEvalRingHom⟩ dsimp only [toPiLocalization_apply_apply, Subtype.coe_mk] at hr simp_rw [toPiLocalization_apply_apply, ← Localization.AtPrime.mapPiEvalRingHom_algebraMap_apply, hr] rw [Function.update_of_ne]; · simp_rw [Pi.zero_apply, map_zero] exact fun h ↦ notMem ⟨⟨i, I.1, I.2.isPrime⟩, PrimeSpectrum.ext congr($h.1)⟩ replace hr := congr_fun hr ⟨J, max⟩ rw [this, map_zero, Function.update_self] at hr exact zero_ne_one hr variable {R} theorem finite_of_toPiLocalization_pi_surjective (h : Function.Surjective (toPiLocalization (Π i, R i))) : Finite ι := by contrapose! h exact toPiLocalization_not_surjective_of_infinite _ end Pi theorem finite_of_toPiLocalization_surjective (surj : Function.Surjective (toPiLocalization R)) : Finite (MaximalSpectrum R) := by replace surj := mapPiLocalization_bijective _ ⟨toPiLocalization_injective R, surj⟩ |>.2.comp surj rw [← RingHom.coe_comp, mapPiLocalization_naturality, RingHom.coe_comp] at surj exact finite_of_toPiLocalization_pi_surjective surj.of_comp end MaximalSpectrum namespace PrimeSpectrum /-- The product of localizations at all prime ideals of a commutative semiring. -/ abbrev PiLocalization : Type _ := Π p : PrimeSpectrum R, Localization p.asIdeal.primeCompl /-- The canonical ring homomorphism from a commutative semiring to the product of its localizations at all prime ideals. It is always injective. -/ def toPiLocalization : R →+* PiLocalization R := algebraMap R _ theorem toPiLocalization_injective : Function.Injective (toPiLocalization R) := fun _ _ eq ↦ MaximalSpectrum.toPiLocalization_injective R <| funext fun I ↦ congr_fun eq I.toPrimeSpectrum /-- The projection from the product of localizations at primes to the product of localizations at maximal ideals. -/ def piLocalizationToMaximal : PiLocalization R →+* MaximalSpectrum.PiLocalization R := Pi.ringHom fun I ↦ Pi.evalRingHom _ I.toPrimeSpectrum open scoped Classical in theorem piLocalizationToMaximal_surjective : Function.Surjective (piLocalizationToMaximal R) := fun r ↦ ⟨fun I ↦ if h : I.1.IsMaximal then r ⟨_, h⟩ else 0, funext fun _ ↦ dif_pos _⟩ variable {R} /-- If R has Krull dimension ≤ 0, then `piLocalizationToIsMaximal R` is an isomorphism. -/ def piLocalizationToMaximalEquiv (h : ∀ I : Ideal R, I.IsPrime → I.IsMaximal) : PiLocalization R ≃+* MaximalSpectrum.PiLocalization R where __ := piLocalizationToMaximal R invFun := Pi.ringHom fun I ↦ Pi.evalRingHom _ (⟨_, h _ I.2⟩ : MaximalSpectrum R) theorem piLocalizationToMaximal_bijective (h : ∀ I : Ideal R, I.IsPrime → I.IsMaximal) : Function.Bijective (piLocalizationToMaximal R) := (piLocalizationToMaximalEquiv h).bijective theorem piLocalizationToMaximal_comp_toPiLocalization : (piLocalizationToMaximal R).comp (toPiLocalization R) = MaximalSpectrum.toPiLocalization R := rfl variable {S} theorem isMaximal_of_toPiLocalization_surjective (surj : Function.Surjective (toPiLocalization R)) (I : PrimeSpectrum R) : I.1.IsMaximal := by classical have ⟨J, max, le⟩ := I.1.exists_le_maximal I.2.ne_top obtain ⟨r, hr⟩ := surj (Function.update 0 ⟨J, max.isPrime⟩ 1) by_contra h have hJ : algebraMap _ _ r = _ := (congr_fun hr _).trans (Function.update_self ..) have hI : algebraMap _ _ r = _ := congr_fun hr I rw [← IsLocalization.lift_eq (M := J.primeCompl) (S := Localization J.primeCompl), hJ, map_one, Function.update_of_ne] at hI · exact one_ne_zero hI · intro eq; have : I.1 = J := congr_arg (·.1) eq; exact h (this ▸ max) · exact fun ⟨s, hs⟩ ↦ IsLocalization.map_units (M := I.1.primeCompl) _ ⟨s, fun h ↦ hs (le h)⟩ variable (f : R →+* S) /-- A ring homomorphism induces a homomorphism between the products of localizations at primes. -/ noncomputable def mapPiLocalization : PiLocalization R →+* PiLocalization S := Pi.ringHom fun I ↦ (Localization.localRingHom _ I.1 f rfl).comp (Pi.evalRingHom _ (f.specComap I)) theorem mapPiLocalization_naturality : (mapPiLocalization f).comp (toPiLocalization R) = (toPiLocalization S).comp f := by ext r I change Localization.localRingHom _ _ _ rfl (algebraMap _ _ r) = algebraMap _ _ (f r) simp_rw [← IsLocalization.mk'_one (M := (I.1.comap f).primeCompl), Localization.localRingHom_mk', ← IsLocalization.mk'_one (M := I.1.primeCompl), Submonoid.coe_one, map_one f] rfl theorem mapPiLocalization_id : mapPiLocalization (.id R) = .id _ := by ext; exact congr($(Localization.localRingHom_id _) _) theorem mapPiLocalization_comp (g : S →+* P) : mapPiLocalization (g.comp f) = (mapPiLocalization g).comp (mapPiLocalization f) := by ext; exact congr($(Localization.localRingHom_comp _ _ _ _ rfl _ rfl) _) theorem mapPiLocalization_bijective (hf : Function.Bijective f) : Function.Bijective (mapPiLocalization f) := by let f := RingEquiv.ofBijective f hf let e := RingEquiv.ofRingHom (mapPiLocalization (f : R →+* S)) (mapPiLocalization f.symm) ?_ ?_ · exact e.bijective · rw [← mapPiLocalization_comp, RingEquiv.comp_symm, mapPiLocalization_id] · rw [← mapPiLocalization_comp, RingEquiv.symm_comp, mapPiLocalization_id] section Pi variable {ι} (R : ι → Type*) [∀ i, CommSemiring (R i)] [∀ i, Nontrivial (R i)] theorem toPiLocalization_not_surjective_of_infinite [Infinite ι] : ¬ Function.Surjective (toPiLocalization (Π i, R i)) := fun surj ↦ MaximalSpectrum.toPiLocalization_not_surjective_of_infinite R <| by rw [← piLocalizationToMaximal_comp_toPiLocalization] exact (piLocalizationToMaximal_surjective _).comp surj variable {R} theorem finite_of_toPiLocalization_pi_surjective (h : Function.Surjective (toPiLocalization (Π i, R i))) : Finite ι := by contrapose! h exact toPiLocalization_not_surjective_of_infinite _ end Pi theorem finite_of_toPiLocalization_surjective (surj : Function.Surjective (toPiLocalization R)) : Finite (PrimeSpectrum R) := by replace surj := (mapPiLocalization_bijective _ ⟨toPiLocalization_injective R, surj⟩).2.comp surj rw [← RingHom.coe_comp, mapPiLocalization_naturality, RingHom.coe_comp] at surj exact finite_of_toPiLocalization_pi_surjective surj.of_comp end PrimeSpectrum
.lake/packages/mathlib/Mathlib/RingTheory/AdicCompletion/LocalRing.lean
import Mathlib.RingTheory.AdicCompletion.Basic import Mathlib.RingTheory.LocalRing.Defs /-! # Basic Properties of Complete Local Ring In this file we prove that a ring that is adic complete with respect to a maximal ideal ia a local ring (complete local ring). -/ variable {R : Type*} [CommRing R] (m : Ideal R) [hmax : m.IsMaximal] open Ideal Quotient lemma isUnit_iff_notMem_of_isAdicComplete_maximal [IsAdicComplete m R] (r : R) : IsUnit r ↔ r ∉ m := by refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · by_contra mem rcases IsUnit.exists_left_inv h with ⟨s, hs⟩ absurd m.ne_top_iff_one.mp (Ideal.IsMaximal.ne_top hmax) simp [← hs, Ideal.mul_mem_left m s mem] · have mapu {n : ℕ} (npos : 0 < n) : IsUnit (Ideal.Quotient.mk (m ^ n) r) := by induction n with | zero => absurd npos exact Nat.not_lt_zero 0 | succ n ih => by_cases neq0 : n = 0 · let max' : (m ^ (n + 1)).IsMaximal := by simpa only [neq0, zero_add, pow_one] using hmax let hField : Field (R ⧸ m ^ (n + 1)) := Ideal.Quotient.field (m ^ (n + 1)) simpa [isUnit_iff_ne_zero, ne_eq, Ideal.Quotient.eq_zero_iff_mem.not, neq0] using h · apply factorPowSucc.isUnit_of_isUnit_image (Nat.zero_lt_of_ne_zero neq0) simpa using (ih (Nat.zero_lt_of_ne_zero neq0)) choose invSeries' invSeries_spec' using fun (n : {n : ℕ // 0 < n}) ↦ (IsUnit.exists_left_inv (mapu n.2)) let invSeries : ℕ → R := fun n ↦ if h : n = 0 then 0 else Classical.choose <| Ideal.Quotient.mk_surjective <| invSeries' ⟨n, (Nat.zero_lt_of_ne_zero h)⟩ have invSeries_spec {n : ℕ} (npos : 0 < n) : (Ideal.Quotient.mk (m ^ n)) (invSeries n) = invSeries' ⟨n, npos⟩ := by simpa only [Nat.ne_zero_of_lt npos, invSeries] using Classical.choose_spec (Ideal.Quotient.mk_surjective (invSeries' ⟨n, npos⟩)) have mod {a b : ℕ} (le : a ≤ b) : invSeries a ≡ invSeries b [SMOD m ^ a • (⊤ : Submodule R R)] := by by_cases apos : 0 < a · simp only [smul_eq_mul, Ideal.mul_top] rw [SModEq.sub_mem, ← eq_zero_iff_mem, map_sub, ← (mapu apos).mul_right_inj, mul_zero, mul_sub] nth_rw 3 [← factor_mk (pow_le_pow_right le), ← factor_mk (pow_le_pow_right le)] simp only [invSeries_spec apos, invSeries_spec (Nat.lt_of_lt_of_le apos le)] rw [← map_mul, mul_comm, invSeries_spec', mul_comm, invSeries_spec', map_one, sub_self] · simp [Nat.eq_zero_of_not_pos apos] rcases IsAdicComplete.toIsPrecomplete.prec mod with ⟨inv, hinv⟩ have eq (n : ℕ) : inv * r - 1 ≡ 0 [SMOD m ^ n • (⊤ : Submodule R R)] := by by_cases npos : 0 < n · apply SModEq.sub_mem.mpr simp only [smul_eq_mul, Ideal.mul_top, sub_zero, ← eq_zero_iff_mem] rw [map_sub, map_one, map_mul, ← sub_add_cancel inv (invSeries n), map_add] have := SModEq.sub_mem.mp (hinv n).symm simp only [smul_eq_mul, Ideal.mul_top] at this simp [Ideal.Quotient.eq_zero_iff_mem.mpr this, invSeries_spec npos, invSeries_spec'] · simp [Nat.eq_zero_of_not_pos npos] apply isUnit_iff_exists_inv'.mpr use inv exact sub_eq_zero.mp <| IsHausdorff.haus IsAdicComplete.toIsHausdorff (inv * r - 1) eq @[deprecated (since := "2025-05-24")] alias isUnit_iff_nmem_of_isAdicComplete_maximal := isUnit_iff_notMem_of_isAdicComplete_maximal theorem isLocalRing_of_isAdicComplete_maximal [IsAdicComplete m R] : IsLocalRing R where exists_pair_ne := ⟨0, 1, ne_of_mem_of_not_mem m.zero_mem (m.ne_top_iff_one.mp (Ideal.IsMaximal.ne_top hmax))⟩ isUnit_or_isUnit_of_add_one {a b} hab := by simp only [isUnit_iff_notMem_of_isAdicComplete_maximal m] by_contra! h absurd m.add_mem h.1 h.2 simpa [hab] using m.ne_top_iff_one.mp (Ideal.IsMaximal.ne_top hmax)
.lake/packages/mathlib/Mathlib/RingTheory/AdicCompletion/Functoriality.lean
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 simp 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 h /-- 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 h /-- 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 change (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 - `AdicCompletion 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*} (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 [DecidableEq ι] : (⨁ 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 [DecidableEq ι] (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 [DecidableEq ι] (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 variable [DecidableEq ι] theorem sumInv_comp_sum : sumInv I M ∘ₗ sum I M = LinearMap.id := by ext j x : 2 apply DirectSum.ext_component (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_apply, mk_apply_coe, AdicCauchySequence.map_apply_coe] simp only [← Submodule.mkQ_apply, ← map_sum, ← apply_eq_component, lof_eq_of, 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 [DecidableEq ι] [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
.lake/packages/mathlib/Mathlib/RingTheory/AdicCompletion/Topology.lean
import Mathlib.RingTheory.AdicCompletion.Basic import Mathlib.Topology.Algebra.Nonarchimedean.AdicTopology /-! # Connection between adic properties and topological properties ## Main results - `IsAdic.isPrecomplete_iff`: `IsPrecomplete I R` is equivalent to `CompleteSpace R` in the adic topology. - `IsAdic.isAdicComplete_iff`: `IsAdicComplete I R` is equivalent to `CompleteSpace R` and `T2Space R` in the adic topology. -/ section TopologicalSpace variable {R : Type*} [CommRing R] [TopologicalSpace R] {I : Ideal R} (hI : IsAdic I) include hI in /-- `IsHausdorff I R` is equivalent to being Hausdorff in the adic topology. -/ protected lemma IsAdic.isHausdorff_iff : IsHausdorff I R ↔ T2Space R := by rw [I.ringFilterBasis.t2Space_iff_sInter_subset hI.symm, isHausdorff_iff] simp [SModEq.zero, Ideal.ringFilterBasis, RingSubgroupsBasis.toRingFilterBasis] end TopologicalSpace section UniformSpace open Topology Uniformity variable {R : Type*} [CommRing R] [UniformSpace R] [IsUniformAddGroup R] {I : Ideal R} (hI : IsAdic I) include hI in /-- `IsPrecomplete I R` is equivalent to being complete in the adic topology. -/ protected lemma IsAdic.isPrecomplete_iff : IsPrecomplete I R ↔ CompleteSpace R := by have := hI.hasBasis_nhds_zero.isCountablyGenerated have : (𝓤 R).IsCountablyGenerated := IsUniformAddGroup.uniformity_countably_generated simp only [isPrecomplete_iff, smul_eq_mul, Ideal.mul_top, SModEq.sub_mem] constructor · intro H refine UniformSpace.complete_of_cauchySeq_tendsto fun u hu ↦ ?_ have : ∀ i, ∃ N, ∀ m, N ≤ m → ∀ n, N ≤ n → u n - u m ∈ I ^ i := by simpa using hI.hasBasis_nhds_zero.uniformity_of_nhds_zero.cauchySeq_iff.mp hu choose N hN using this obtain ⟨L, hL⟩ := H (fun i ↦ u ((Finset.Iic i).sup N)) fun _ ↦ hN _ _ (Finset.le_sup (by simpa)) _ (Finset.le_sup (by simp)) use L suffices ∀ i, ∃ N, ∀ n, N ≤ n → u n - L ∈ I ^ i by simpa [(hI.hasBasis_nhds L).tendsto_right_iff, sub_eq_neg_add] refine fun i ↦ ⟨(Finset.Iic i).sup N, fun n hn ↦ ?_⟩ have := Ideal.add_mem _ (hN i ((Finset.Iic i).sup N) (Finset.le_sup (by simp)) n (.trans (Finset.le_sup (by simp)) hn)) (hL i) rwa [sub_add_sub_cancel] at this · intro H f hf obtain ⟨L, hL⟩ := CompleteSpace.complete (f := Filter.atTop.map f) (hI.hasBasis_nhds_zero.uniformity_of_nhds_zero.cauchySeq_iff.mpr fun i _ ↦ ⟨i, fun m hm n hn ↦ by simpa using Ideal.sub_mem _ (hf hm) (hf hn)⟩) refine ⟨L, fun i ↦ ?_⟩ obtain ⟨N, hN⟩ : ∃ N, ∀ n, N ≤ n → f n - L ∈ I ^ i := by simpa [sub_eq_neg_add] using (hI.hasBasis_nhds L).tendsto_right_iff.mp hL i simpa using Ideal.add_mem _ (hN (max i N) le_sup_right) (hf (le_max_left i N)) include hI in /-- `IsAdicComplete I R` is equivalent to being complete and hausdorff in the adic topology. -/ protected lemma IsAdic.isAdicComplete_iff : IsAdicComplete I R ↔ CompleteSpace R ∧ T2Space R := by rw [isAdicComplete_iff, hI.isHausdorff_iff, hI.isPrecomplete_iff, and_comm] end UniformSpace
.lake/packages/mathlib/Mathlib/RingTheory/AdicCompletion/AsTensorProduct.lean
import Mathlib.Algebra.FiveLemma import Mathlib.LinearAlgebra.TensorProduct.Pi import Mathlib.LinearAlgebra.TensorProduct.RightExactness import Mathlib.RingTheory.AdicCompletion.Exactness import Mathlib.RingTheory.Flat.Tensor /-! # 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 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] /-! ### 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} (f : (ι → R) →ₗ[R] M) /- 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 variable (hf : Function.Surjective f) include hf private lemma tens_exact : Function.Exact (lTensorKerIncl I M f) (lTensorf I M f) := lTensor_exact (AdicCompletion I R) (f.exact_subtype_ker_map) hf private lemma tens_surj : Function.Surjective (lTensorf I M f) := LinearMap.lTensor_surjective (AdicCompletion I R) hf private lemma adic_exact [IsNoetherianRing R] [Fintype ι] : Function.Exact (map I (LinearMap.ker f).subtype) (map I f) := map_exact (Submodule.injective_subtype _) (f.exact_subtype_ker_map) hf private lemma adic_surj : Function.Surjective (map I f) := map_surjective I hf private lemma ofTensorProduct_bijective_of_map_from_fin [Fintype ι] [IsNoetherianRing R] : Function.Bijective (ofTensorProduct I M) := LinearMap.bijective_of_surjective_of_bijective_of_bijective_of_injective (lTensorKerIncl I M f) (lTensorf I M f) (0 : AdicCompletion I R ⊗[R] M →ₗ[AdicCompletion I R] Unit) (0 : _ →ₗ[AdicCompletion I R] Unit) (map I <| (LinearMap.ker f).subtype) (map I f) (0 : _ →ₗ[AdicCompletion I R] Unit) (0 : _ →ₗ[AdicCompletion I R] Unit) (ofTensorProduct I (LinearMap.ker f)) (ofTensorProduct I (ι → R)) (ofTensorProduct I M) 0 0 (ofTensorProduct_naturality I <| (LinearMap.ker f).subtype) (ofTensorProduct_naturality I f) rfl rfl (tens_exact I M f hf) ((LinearMap.exact_zero_iff_surjective _ _).mpr <| tens_surj I M f hf) ((LinearMap.exact_zero_iff_surjective _ _).mpr <| Function.surjective_to_subsingleton _) (adic_exact I M f hf) ((LinearMap.exact_zero_iff_surjective _ _).mpr <| adic_surj I M f hf) ((LinearMap.exact_zero_iff_surjective _ _).mpr <| Function.surjective_to_subsingleton _) (ofTensorProduct_surjective_of_finite I (LinearMap.ker f)) (ofTensorProduct_bijective_of_pi_of_fintype I ι) (Function.bijective_of_subsingleton _) (Function.injective_of_subsingleton _) end variable [IsNoetherianRing R] /-- 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) lemma coe_ofTensorProductEquivOfFiniteNoetherian [Module.Finite R M] : ofTensorProductEquivOfFiniteNoetherian I M = ofTensorProduct I M := rfl @[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 rw [coe_ofTensorProductEquivOfFiniteNoetherian, 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] : Module.Flat R (AdicCompletion I R) := Module.Flat.iff_lTensor_injective'.mpr fun J ↦ tensor_map_id_left_injective_of_injective I (Submodule.injective_subtype J) end Noetherian end AdicCompletion
.lake/packages/mathlib/Mathlib/RingTheory/AdicCompletion/Basic.lean
import Mathlib.Algebra.Ring.GeomSum import Mathlib.LinearAlgebra.SModEq.Basic import Mathlib.RingTheory.Ideal.Quotient.PowTransition import Mathlib.RingTheory.Jacobson.Ideal /-! # 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 with a linear map `AdicCompletion.lift` from `M`. This map is injective iff `M` is Hausdorff and surjective iff `M` is precomplete. - `IsAdicComplete.lift`: if `N` is `I`-adically complete, then a compatible family of linear maps `M →ₗ[R] N ⧸ (I ^ n • ⊤)` can be lifted to a unique linear map `M →ₗ[R] N`. Together with `mk_lift_apply` and `eq_lift`, it gives the universal property of being `I`-adically complete. -/ suppress_compilation open Submodule Ideal Quotient variable {R S T : 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. -/ @[mk_iff, stacks 0317 "see also `IsAdicComplete.of_bijective_iff`"] class IsAdicComplete : Prop extends IsHausdorff I M, IsPrecomplete I M 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 IsHausdorff.eq_iff_smodEq [IsHausdorff I M] {x y : M} : x = y ↔ ∀ n, x ≡ y [SMOD (I ^ n • ⊤ : Submodule R M)] := by refine ⟨fun h _ ↦ h ▸ rfl, fun h ↦ ?_⟩ rw [← sub_eq_zero] apply IsHausdorff.haus' (I := I) (x - y) simpa [SModEq.sub_mem] using 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`. -/ abbrev AdicCompletion.transitionMap {m n : ℕ} (hmn : m ≤ n) := factorPow I M hmn /-- The completion of a module with respect to an ideal. This is Hausdorff but not necessarily complete: a classical sufficient condition for completeness is that `M` be finitely generated [Stacks, 0G1Q]. -/ 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} in 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⟩ 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'', Submodule.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 => ?_⟩⟩ rcases 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 instSMul [SMul S R] [SMul S M] [IsScalarTower S R M] : SMul S (AdicCompletion I M) where smul r x := ⟨r • x.val, by simp [x.property]⟩ @[simp, norm_cast] lemma val_zero : (0 : AdicCompletion I M).val = 0 := rfl lemma val_zero_apply (n : ℕ) : (0 : AdicCompletion I M).val n = 0 := rfl variable {I M} @[simp, norm_cast] lemma val_add (f g : AdicCompletion I M) : (f + g).val = f.val + g.val := rfl @[simp, norm_cast] lemma val_sub (f g : AdicCompletion I M) : (f - g).val = f.val - g.val := rfl @[simp, norm_cast] lemma val_neg (f : AdicCompletion I M) : (-f).val = -f.val := rfl lemma val_add_apply (f g : AdicCompletion I M) (n : ℕ) : (f + g).val n = f.val n + g.val n := rfl lemma val_sub_apply (f g : AdicCompletion I M) (n : ℕ) : (f - g).val n = f.val n - g.val n := rfl lemma val_neg_apply (f : AdicCompletion I M) (n : ℕ) : (-f).val n = -f.val n := rfl /- No `simp` attribute, since it causes `simp` unification timeouts when considering the `Module (AdicCompletion I R) (AdicCompletion I M)` instance (see `AdicCompletion/Algebra`). -/ @[norm_cast] lemma val_smul [SMul S R] [SMul S M] [IsScalarTower S R M] (s : S) (f : AdicCompletion I M) : (s • f).val = s • f.val := rfl lemma val_smul_apply [SMul S R] [SMul S M] [IsScalarTower S R M] (s : S) (f : AdicCompletion I M) (n : ℕ) : (s • f).val n = s • f.val n := rfl @[ext] lemma ext {x y : AdicCompletion I M} (h : ∀ n, x.val n = y.val n) : x = y := Subtype.eq <| funext h variable (I M) 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 val_add val_neg val_sub (fun _ _ ↦ val_smul ..) (fun _ _ ↦ val_smul ..) instance [Semiring S] [SMul S R] [Module S M] [IsScalarTower S R M] : Module S (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 S f val_smul instance instIsScalarTower [SMul S T] [SMul S R] [SMul T R] [SMul S M] [SMul T M] [IsScalarTower S R M] [IsScalarTower T R M] [IsScalarTower S T M] : IsScalarTower S T (AdicCompletion I M) where smul_assoc s t f := by ext; simp [val_smul] instance instSMulCommClass [SMul S R] [SMul T R] [SMul S M] [SMul T M] [IsScalarTower S R M] [IsScalarTower T R M] [SMulCommClass S T M] : SMulCommClass S T (AdicCompletion I M) where smul_comm s t f := by ext; simp [val_smul, smul_comm] instance instIsCentralScalar [SMul S R] [SMul Sᵐᵒᵖ R] [SMul S M] [SMul Sᵐᵒᵖ M] [IsScalarTower S R M] [IsScalarTower Sᵐᵒᵖ R M] [IsCentralScalar S M] : IsCentralScalar S (AdicCompletion I M) where op_smul_eq_smul s f := by ext; simp [val_smul, op_smul_eq_smul] /-- 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 variable {I M} @[simp, norm_cast] lemma val_sum {ι : Type*} (s : Finset ι) (f : ι → AdicCompletion I M) : (∑ i ∈ s, f i).val = ∑ i ∈ s, (f i).val := by simp_rw [← funext (incl_apply _ _ _), map_sum] lemma val_sum_apply {ι : Type*} (s : Finset ι) (f : ι → AdicCompletion I M) (n : ℕ) : (∑ i ∈ s, f i).val n = ∑ i ∈ s, (f i).val n := by simp variable (I M) /-- 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) variable {I M} 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_apply, val_zero] exact Quotient.inductionOn' (x.val n) (fun a ↦ SModEq.zero.2 <| smul_mem_smul hr mem_top) · simp only [val_add_apply, hx, val_zero_apply, hy, add_zero] @[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] 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 cutsat) rw [mk_apply_coe, Submodule.mkQ_apply, val_zero, ← AdicCauchySequence.mk_eq_mk (show n ≤ m by cutsat)] simpa using (Submodule.smul_mono_left (Ideal.pow_le_pow_right (by cutsat))) 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, ← mkQ_apply, ← factor_mk (Submodule.smul_mono_left (Ideal.pow_le_pow_right hmn)) (a n), mkQ_apply, 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 section Bijective variable {I} theorem of_injective_iff : Function.Injective (of I M) ↔ IsHausdorff I M := by constructor · refine fun h ↦ ⟨fun x hx ↦ h ?_⟩ ext n simpa [of, SModEq.zero] using hx n · intro h rw [← LinearMap.ker_eq_bot] ext x simp only [LinearMap.mem_ker, Submodule.mem_bot] refine ⟨fun hx ↦ h.haus x fun n ↦ ?_, fun hx ↦ by simp [hx]⟩ rw [Subtype.ext_iff] at hx simpa [SModEq.zero] using congrFun hx n variable (I M) in theorem of_injective [IsHausdorff I M] : Function.Injective (of I M) := of_injective_iff.mpr ‹_› @[simp] theorem of_inj [IsHausdorff I M] {a b : M} : of I M a = of I M b ↔ a = b := (of_injective I M).eq_iff theorem of_surjective_iff : Function.Surjective (of I M) ↔ IsPrecomplete I M := by constructor · refine fun h ↦ ⟨fun f hmn ↦ ?_⟩ let u : AdicCompletion I M := ⟨fun n ↦ Submodule.Quotient.mk (f n), fun c ↦ (hmn c).symm⟩ obtain ⟨x, hx⟩ := h u refine ⟨x, fun n ↦ ?_⟩ simp only [SModEq] rw [← mkQ_apply _ x, ← eval_of, hx] simp [u] · intro h u choose x hx using (fun n ↦ Submodule.Quotient.mk_surjective (I ^ n • ⊤ : Submodule R M) (u.1 n)) obtain ⟨a, ha⟩ := h.prec (f := x) (fun hmn ↦ by rw [SModEq, hx, ← u.2 hmn, ← hx]; simp) use a ext n simpa [SModEq, ← eval_of, ha, ← hx] using (ha n).symm variable (I M) in theorem of_surjective [IsPrecomplete I M] : Function.Surjective (of I M) := of_surjective_iff.mpr ‹_› theorem of_bijective_iff : Function.Bijective (of I M) ↔ IsAdicComplete I M := ⟨fun h ↦ { toIsHausdorff := of_injective_iff.mp h.1, toIsPrecomplete := of_surjective_iff.mp h.2 }, fun h ↦ ⟨of_injective_iff.mpr h.1, of_surjective_iff.mpr h.2⟩⟩ variable (I M) variable [IsAdicComplete I M] theorem of_bijective : Function.Bijective (of I M) := of_bijective_iff.mpr ‹_› /-- When `M` is `I`-adic complete, the canonical map from `M` to its `I`-adic completion is a linear equivalence. -/ @[simps! apply] def ofLinearEquiv : M ≃ₗ[R] AdicCompletion I M := LinearEquiv.ofBijective (of I M) (of_bijective I M) variable {M} @[simp] theorem ofLinearEquiv_symm_of (x : M) : (ofLinearEquiv I M).symm (of I M x) = x := by simp [ofLinearEquiv] @[simp] theorem of_ofLinearEquiv_symm (x : AdicCompletion I M) : of I M ((ofLinearEquiv I M).symm x) = x := by simp [ofLinearEquiv] end Bijective end AdicCompletion namespace IsAdicComplete open AdicCompletion section lift variable [IsAdicComplete I N] variable {M} /-- Universal property of `IsAdicComplete`. The lift linear map `lift I f h : M →ₗ[R] N` of a sequence of compatible linear maps `f n : M →ₗ[R] N ⧸ (I ^ n • ⊤)`. -/ def lift (f : ∀ (n : ℕ), M →ₗ[R] N ⧸ (I ^ n • ⊤ : Submodule R N)) (h : ∀ {m n : ℕ} (hle : m ≤ n), factorPow I N hle ∘ₗ f n = f m) : M →ₗ[R] N := (ofLinearEquiv I N).symm ∘ₗ AdicCompletion.lift I f h @[simp] theorem of_lift (f : ∀ (n : ℕ), M →ₗ[R] N ⧸ (I ^ n • ⊤ : Submodule R N)) (h : ∀ {m n : ℕ} (hle : m ≤ n), factorPow I N hle ∘ₗ f n = f m) (x : M) : of I N (lift I f h x) = AdicCompletion.lift I f h x := by simp [lift] @[simp] theorem of_comp_lift (f : ∀ (n : ℕ), M →ₗ[R] N ⧸ (I ^ n • ⊤ : Submodule R N)) (h : ∀ {m n : ℕ} (hle : m ≤ n), factorPow I N hle ∘ₗ f n = f m) : of I N ∘ₗ lift I f h = AdicCompletion.lift I f h := by ext1; simp /-- The composition of lift linear map `lift I f h : M →ₗ[R] N` with the canonical projection `N → N ⧸ (I ^ n • ⊤)` is `f n` . -/ @[simp] theorem mk_lift {f : (n : ℕ) → M →ₗ[R] N ⧸ (I ^ n • ⊤)} (h : ∀ {m n : ℕ} (hle : m ≤ n), factorPow I N hle ∘ₗ f n = f m) (n : ℕ) (x : M) : Submodule.Quotient.mk (lift I f h x) = f n x := by simp only [lift, LinearMap.coe_comp, LinearEquiv.coe_coe, Function.comp_apply] rw [← mkQ_apply, ← eval_of] simp /-- The composition of lift linear map `lift I f h : M →ₗ[R] N` with the canonical projection `N →ₗ[R] N ⧸ (I ^ n • ⊤)` is `f n` . -/ @[simp] theorem mkQ_comp_lift {f : (n : ℕ) → M →ₗ[R] N ⧸ (I ^ n • ⊤)} (h : ∀ {m n : ℕ} (hle : m ≤ n), factorPow I N hle ∘ₗ f n = f m) (n : ℕ) : mkQ (I ^ n • ⊤ : Submodule R N) ∘ₗ lift I f h = f n := by ext; simp /-- Uniqueness of the lift. Given a compatible family of linear maps `f n : M →ₗ[R] N ⧸ (I ^ n • ⊤)`. If `F : M →ₗ[R] N` makes the following diagram commutes ``` N | \ F| \ f n | \ v v M --> M ⧸ (I ^ n • ⊤) ``` Then it is the map `IsAdicComplete.lift`. -/ theorem eq_lift {f : (n : ℕ) → M →ₗ[R] N ⧸ (I ^ n • ⊤)} (h : ∀ {m n : ℕ} (hle : m ≤ n), factorPow I N hle ∘ₗ f n = f m) {F : M →ₗ[R] N} (hF : ∀ n, mkQ _ ∘ₗ F = f n) : F = lift I f h := by ext s rw [IsHausdorff.eq_iff_smodEq (I := I)] intro n simp [SModEq, ← hF n] end lift namespace StrictMono variable {a : ℕ → ℕ} (ha : StrictMono a) (f : (n : ℕ) → M →ₗ[R] N ⧸ (I ^ (a n) • ⊤ : Submodule R N)) variable {I M} /-- Instead of providing all `M →ₗ[R] N ⧸ (I ^ n • ⊤)`, one can just provide `M →ₗ[R] N ⧸ (I ^ (a n) • ⊤)` for a strictly increasing sequence `a n` to recover all `M →ₗ[R] N ⧸ (I ^ n • ⊤)`. -/ def extend (n : ℕ) : M →ₗ[R] N ⧸ (I ^ n • ⊤ : Submodule R N) := factorPow I N (ha.id_le n) ∘ₗ f n variable (hf : ∀ {m}, factorPow I N (ha.monotone m.le_succ) ∘ₗ (f (m + 1)) = f m) include hf in theorem factorPow_comp_eq_of_factorPow_comp_succ_eq {m n : ℕ} (hle : m ≤ n) : factorPow I N (ha.monotone hle) ∘ₗ f n = f m := by ext x symm refine Submodule.eq_factor_of_eq_factor_succ ?_ (fun n ↦ f n x) ?_ hle · exact fun _ _ le ↦ smul_mono_left (Ideal.pow_le_pow_right (ha.monotone le)) · intro s simp only [LinearMap.ext_iff] at hf simpa using (hf x).symm include hf in theorem extend_eq (n : ℕ) : extend ha f (a n) = f n := factorPow_comp_eq_of_factorPow_comp_succ_eq ha f hf (ha.id_le n) include hf in theorem factorPow_comp_extend {m n : ℕ} (hle : m ≤ n) : factorPow I N hle ∘ₗ extend ha f n = extend ha f m := by ext simp [extend, ← factorPow_comp_eq_of_factorPow_comp_succ_eq ha f hf hle] variable [IsAdicComplete I N] variable (I) /-- A variant of `IsAdicComplete.lift`. Only takes `f n : M →ₗ[R] N ⧸ (I ^ (a n) • ⊤)` from a strictly increasing sequence `a n`. -/ def lift : M →ₗ[R] N := IsAdicComplete.lift I (extend ha f) (factorPow_comp_extend ha f hf) theorem of_lift (x : M) : of I N (lift I ha f hf x) = AdicCompletion.lift I (extend ha f) (factorPow_comp_extend ha f hf) x := IsAdicComplete.of_lift I (extend ha f) (factorPow_comp_extend ha f hf) x theorem of_comp_lift : of I N ∘ₗ lift I ha f hf = AdicCompletion.lift I (extend ha f) (factorPow_comp_extend ha f hf) := IsAdicComplete.of_comp_lift I (extend ha f) (factorPow_comp_extend ha f hf) @[simp] theorem mk_lift {n : ℕ} (x : M) : (Submodule.Quotient.mk (lift I ha f hf x)) = f n x := by simp only [lift, IsAdicComplete.lift, ofLinearEquiv, LinearMap.coe_comp, LinearEquiv.coe_coe, Function.comp_apply] rw [← mkQ_apply, ← eval_of] simp [extend_eq ha f hf] @[simp] theorem mkQ_comp_lift {n : ℕ} : mkQ (I ^ (a n) • ⊤ : Submodule R N) ∘ₗ (lift I ha f hf) = f n := by ext; simp theorem eq_lift {F : M →ₗ[R] N} (hF : ∀ n, mkQ _ ∘ₗ F = f n) : F = lift I ha f hf := by ext s rw [IsHausdorff.eq_iff_smodEq (I := I)] intro n apply SModEq.mono (smul_mono_left (Ideal.pow_le_pow_right (ha.id_le n))) simp [SModEq, ← hF n, mk_lift I ha f hf] end StrictMono 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, 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
.lake/packages/mathlib/Mathlib/RingTheory/AdicCompletion/Exactness.lean
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} /- In each step, a preimage is constructed from the preimage of the previous step by subtracting this delta. -/ private noncomputable def mapPreimageDelta (hf : Function.Surjective f) (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.2 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 (hf : Function.Surjective f) (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 hf x n let ⟨⟨d, _⟩, (p : f d = f (yₙ - y))⟩ := mapPreimageDelta hf x hy hyₙ ⟨yₙ - d, by simpa [p]⟩ variable (I) in /-- Adic completion preserves surjectivity -/ theorem map_surjective (hf : Function.Surjective f) : 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, 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) /-- 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 cutsat, n, by cutsat, ?_⟩⟩ 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 1 [show n = n + k - k by cutsat] rw [← hk (n + k) (show n + k ≥ k by cutsat)] 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 cutsat) _ · exact (Submodule.smul_mono_left (Ideal.pow_le_pow_right (by cutsat))) 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 cutsat)] exact ⟨h, ⟨y - yₙ, rfl⟩⟩ ⟨⟨y - yₙ, hyyₙ⟩, by simpa [hd, Nat.succ_eq_add_one, Nat.add_assoc]⟩ open Submodule include hfg in /-- 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 include hf hfg hg in /-- `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 cutsat)] 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 cutsat)) exact hle (a n).property end end AdicCompletion
.lake/packages/mathlib/Mathlib/RingTheory/AdicCompletion/Algebra.lean
import Mathlib.Algebra.Algebra.Pi import Mathlib.Algebra.Module.Torsion.Basic import Mathlib.RingTheory.AdicCompletion.Basic /-! # 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 S : Type*} [CommRing R] [CommRing S] (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 [transitionMap_map_one I]) (fun x y hx hy m n hmn ↦ by simp [hx hmn, hy hmn, transitionMap_map_mul I 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, fun hmn ↦ by simp [x.property, y.property, transitionMap_map_mul I hmn]⟩ instance : One (AdicCompletion I R) where one := ⟨1, by simp [transitionMap_map_one I]⟩ 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 hmn ↦ by simp [x.property, transitionMap_map_pow I hmn]⟩ 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 S R] : Algebra S (AdicCompletion I R) where algebraMap := { toFun r := ⟨algebraMap S (∀ n, R ⧸ (I ^ n • ⊤ : Ideal R)) r, fun hmn ↦ by simp only [Pi.algebraMap_apply, IsScalarTower.algebraMap_apply S R (R ⧸ (I ^ _ • ⊤ : Ideal R)), Ideal.Quotient.algebraMap_eq, mapQ_eq_factor] 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 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 algebraMap := { 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 [← Ideal.Quotient.mk_eq_mk, ← Ideal.Quotient.mk_eq_mk, h] 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 ↦ by refine Quotient.inductionOn' x (fun x ↦ ?_) have h : b₁ - b₂ ∈ (I : Submodule R R) := by rwa [show I = I • ⊤ by simp, ← Submodule.quotientRel_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, mapQ_eq_factor, mk_apply_coe, mkQ_apply, Ideal.Quotient.mk_eq_mk, mk_smul_mk, map_smul, mapQ_apply, LinearMap.id_coe, id_eq] 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; simp smul_add r x y := by ext n; simp add_smul r s x := by ext n; simp [add_smul] zero_smul x := by ext n; simp instance : IsScalarTower R (AdicCompletion I R) (AdicCompletion I M) where smul_assoc r s x := by ext n rw [smul_eval, val_smul_apply, val_smul_apply, 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
.lake/packages/mathlib/Mathlib/RingTheory/AdicCompletion/Noetherian.lean
import Mathlib.RingTheory.AdicCompletion.Basic import Mathlib.RingTheory.Filtration /-! # Hausdorff-ness for Noetherian rings -/ open IsLocalRing variable {R : Type*} [CommRing R] (I : Ideal R) (M : Type*) [AddCommGroup M] [Module R M] variable [IsNoetherianRing R] [Module.Finite R M] lemma IsHausdorff.of_le_jacobson (h : I ≤ Ideal.jacobson ⊥) : IsHausdorff I M := ⟨fun x hx ↦ (Ideal.iInf_pow_smul_eq_bot_of_le_jacobson I h).le (by simpa [SModEq.zero] using hx)⟩ theorem IsHausdorff.of_isLocalRing [IsLocalRing R] (h : I ≠ ⊤) : IsHausdorff I M := of_le_jacobson I M ((le_maximalIdeal h).trans (maximalIdeal_le_jacobson _)) instance [IsLocalRing R] : IsHausdorff (maximalIdeal R) M := .of_le_jacobson _ _ (maximalIdeal_le_jacobson _) theorem IsHausdorff.of_noZeroSMulDivisors [NoZeroSMulDivisors R M] (h : I ≠ ⊤) : IsHausdorff I M := ⟨fun x hx ↦ (I.iInf_pow_smul_eq_bot_of_noZeroSMulDivisors h).le (by simpa [SModEq.zero] using hx)⟩ theorem IsHausdorff.of_isDomain [IsDomain R] (h : I ≠ ⊤) : IsHausdorff I R := .of_noZeroSMulDivisors I R h
.lake/packages/mathlib/Mathlib/RingTheory/Regular/Flat.lean
import Mathlib.RingTheory.Flat.FaithfullyFlat.Basic import Mathlib.RingTheory.Flat.Localization import Mathlib.RingTheory.Regular.RegularSequence /-! # `RingTheory.Sequence.IsWeaklyRegular` is stable under flat base change ## Main results * `RingTheory.Sequence.IsWeaklyRegular.of_flat_of_isBaseChange`: Let `R` be a commutative ring, `M` be an `R`-module, `S` be a flat `R`-algebra, `N` be the base change of `M` to `S`. If `[r₁, …, rₙ]` is a weakly regular `M`-sequence, then its image in `N` is a weakly regular `N`-sequence. -/ namespace RingTheory.Sequence open Module variable {R S M N : Type*} [CommRing R] [CommRing S] [Algebra R S] [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N] [Module S N] [IsScalarTower R S N] /-- Let `R` be a commutative ring, `M` be an `R`-module, `S` be a flat `R`-algebra, `N` be the base change of `M` to `S`. If `[r₁, …, rₙ]` is a weakly regular `M`-sequence, then its image in `N` is a weakly regular `N`-sequence. -/ theorem IsWeaklyRegular.of_flat_of_isBaseChange [Flat R S] {f : M →ₗ[R] N} (hf : IsBaseChange S f) {rs : List R} (reg : IsWeaklyRegular M rs) : IsWeaklyRegular N (rs.map (algebraMap R S)) := by induction rs generalizing M N with | nil => simp | cons x _ ih => simp only [List.map_cons, isWeaklyRegular_cons_iff] at reg ⊢ have e := (QuotSMulTop.algebraMapTensorEquivTensorQuotSMulTop x M S).symm ≪≫ₗ QuotSMulTop.congr ((algebraMap R S) x) hf.equiv have hg : IsBaseChange S <| e.toLinearMap.restrictScalars R ∘ₗ TensorProduct.mk R S (QuotSMulTop x M) 1 := IsBaseChange.of_equiv e (fun _ ↦ by simp) exact ⟨reg.1.of_flat_of_isBaseChange hf, ih hg reg.2⟩ theorem IsWeaklyRegular.of_flat [Flat R S] {rs : List R} (reg : IsWeaklyRegular R rs) : IsWeaklyRegular S (rs.map (algebraMap R S)) := reg.of_flat_of_isBaseChange (IsBaseChange.linearMap R S) variable (S) (T : Submonoid R) [IsLocalization T S] theorem IsWeaklyRegular.of_isLocalizedModule (f : M →ₗ[R] N) [IsLocalizedModule T f] {rs : List R} (reg : IsWeaklyRegular M rs) : IsWeaklyRegular N (rs.map (algebraMap R S)) := have : Flat R S := IsLocalization.flat S T reg.of_flat_of_isBaseChange (IsLocalizedModule.isBaseChange T S f) include T in theorem IsWeaklyRegular.of_isLocalization {rs : List R} (reg : IsWeaklyRegular R rs) : IsWeaklyRegular S (rs.map (algebraMap R S)) := reg.of_isLocalizedModule S T (Algebra.linearMap R S) variable (p : Ideal R) [p.IsPrime] [IsLocalization.AtPrime S p] theorem IsWeaklyRegular.isRegular_of_isLocalizedModule_of_mem [Nontrivial N] [Module.Finite S N] (f : M →ₗ[R] N) [IsLocalizedModule.AtPrime p f] {rs : List R} (reg : IsWeaklyRegular M rs) (mem : ∀ r ∈ rs, r ∈ p) : IsRegular N (rs.map (algebraMap R S)) := by have : IsLocalRing S := IsLocalization.AtPrime.isLocalRing S p refine (IsLocalRing.isRegular_iff_isWeaklyRegular_of_subset_maximalIdeal (fun _ hr ↦ ?_)).mpr <| reg.of_isLocalizedModule S p.primeCompl f rcases List.mem_map.mp hr with ⟨r, hr, eq⟩ simpa only [← eq, IsLocalization.AtPrime.to_map_mem_maximal_iff S p] using mem r hr theorem IsWeaklyRegular.isRegular_of_isLocalization_of_mem {rs : List R} (reg : IsWeaklyRegular R rs) (mem : ∀ r ∈ rs, r ∈ p) : IsRegular S (rs.map (algebraMap R S)) := have : Nontrivial S := IsLocalization.AtPrime.nontrivial S p reg.isRegular_of_isLocalizedModule_of_mem S p (Algebra.linearMap R S) mem variable {S} [FaithfullyFlat R S] /-- Let `R` be a commutative ring, `M` be an `R`-module, `S` be a faithfully flat `R`-algebra, `N` be the base change of `M` to `S`. If `[r₁, …, rₙ]` is a regular `M`-sequence, then its image in `N` is a regular `N`-sequence. -/ theorem IsRegular.of_faithfullyFlat_of_isBaseChange {f : M →ₗ[R] N} (hf : IsBaseChange S f) {rs : List R} (reg : IsRegular M rs) : IsRegular N (rs.map (algebraMap R S)) := by refine ⟨reg.1.of_flat_of_isBaseChange hf, ?_⟩ rw [← Ideal.map_ofList] exact ((hf.map_smul_top_ne_top_iff_of_faithfullyFlat R M _).mpr reg.2.symm).symm theorem IsRegular.of_faithfullyFlat {rs : List R} (reg : IsRegular R rs) : IsRegular S (rs.map (algebraMap R S)) := reg.of_faithfullyFlat_of_isBaseChange (IsBaseChange.linearMap R S) end RingTheory.Sequence
.lake/packages/mathlib/Mathlib/RingTheory/Regular/Depth.lean
import Mathlib.Algebra.Module.FinitePresentation import Mathlib.LinearAlgebra.Dual.Lemmas import Mathlib.RingTheory.Ideal.AssociatedPrime.Finiteness import Mathlib.RingTheory.Ideal.AssociatedPrime.Localization import Mathlib.RingTheory.LocalRing.ResidueField.Ideal import Mathlib.RingTheory.Regular.IsSMulRegular import Mathlib.RingTheory.Support /-! # Hom(N,M) is subsingleton iff there exists a smul regular element of M in ann(N) Let `M` and `N` be `R`-modules. In this section we prove that `Hom(N,M)` is subsingleton iff there exist `r : R`, such that `IsSMulRegular M r` and `r ∈ ann(N)`. This is the case if `Depth[I](M) = 0`. ## Main statements * `IsSMulRegular.subsingleton_linearMap_iff` : for `R` module `N M`, `Hom(N, M) = 0` iff there is a `M`-regular in `Module.annihilator R N`. -/ open IsLocalRing LinearMap Module namespace IsSMulRegular variable {R M N : Type*} [CommRing R] [AddCommGroup M] [AddCommGroup N] [Module R M] [Module R N] lemma linearMap_subsingleton_of_mem_annihilator {r : R} (reg : IsSMulRegular M r) (mem_ann : r ∈ Module.annihilator R N) : Subsingleton (N →ₗ[R] M) := by apply subsingleton_of_forall_eq 0 (fun f ↦ ext fun x ↦ ?_) have : r • (f x) = r • 0 := by rw [smul_zero, ← map_smul, Module.mem_annihilator.mp mem_ann x, map_zero] simpa using reg this lemma subsingleton_linearMap_iff [IsNoetherianRing R] [Module.Finite R M] [Module.Finite R N] : Subsingleton (N →ₗ[R] M) ↔ ∃ r ∈ Module.annihilator R N, IsSMulRegular M r := by refine ⟨fun hom0 ↦ ?_, fun ⟨r, mem_ann, reg⟩ ↦ linearMap_subsingleton_of_mem_annihilator reg mem_ann⟩ cases subsingleton_or_nontrivial M · exact ⟨0, ⟨Submodule.zero_mem (Module.annihilator R N), IsSMulRegular.zero⟩⟩ · by_contra! h have hexist : ∃ p ∈ associatedPrimes R M, Module.annihilator R N ≤ p := by rcases associatedPrimes.nonempty R M with ⟨Ia, hIa⟩ apply (Ideal.subset_union_prime_finite (associatedPrimes.finite R M) Ia Ia _).mp · rw [biUnion_associatedPrimes_eq_compl_regular R M] exact fun r hr ↦ h r hr · exact fun I hin _ _ ↦ IsAssociatedPrime.isPrime hin rcases hexist with ⟨p, pass, hp⟩ let _ := pass.isPrime let p' : PrimeSpectrum R := ⟨p, pass.isPrime⟩ have loc_ne_zero : p' ∈ Module.support R N := Module.mem_support_iff_of_finite.mpr hp rw [Module.mem_support_iff] at loc_ne_zero let Rₚ := Localization.AtPrime p let Nₚ := LocalizedModule p'.asIdeal.primeCompl N let Mₚ := LocalizedModule p'.asIdeal.primeCompl M let Nₚ' := Nₚ ⧸ (IsLocalRing.maximalIdeal (Localization.AtPrime p)) • (⊤ : Submodule Rₚ Nₚ) have ntr : Nontrivial Nₚ' := Submodule.Quotient.nontrivial_of_lt_top _ (Ne.lt_top' (Submodule.top_ne_ideal_smul_of_le_jacobson_annihilator (IsLocalRing.maximalIdeal_le_jacobson (Module.annihilator Rₚ Nₚ)))) let Mₚ' := Mₚ ⧸ (IsLocalRing.maximalIdeal (Localization.AtPrime p)) • (⊤ : Submodule Rₚ Mₚ) let _ : Module p.ResidueField Nₚ' := Module.instQuotientIdealSubmoduleHSMulTop Nₚ (maximalIdeal (Localization.AtPrime p)) have := AssociatePrimes.mem_iff.mp (associatedPrimes.mem_associatePrimes_localizedModule_atPrime_of_mem_associated_primes pass) rcases this.2 with ⟨x, hx⟩ have : Nontrivial (Module.Dual p.ResidueField Nₚ') := by simpa using ntr rcases exists_ne (α := Module.Dual p.ResidueField Nₚ') 0 with ⟨g, hg⟩ let to_res' : Nₚ' →ₗ[Rₚ] p.ResidueField := { __ := g map_smul' r x := by simp only [AddHom.toFun_eq_coe, coe_toAddHom, RingHom.id_apply] convert g.map_smul (Ideal.Quotient.mk _ r) x } let to_res : Nₚ →ₗ[Rₚ] p.ResidueField := to_res'.comp ((maximalIdeal (Localization.AtPrime p)) • (⊤ : Submodule Rₚ Nₚ)).mkQ let i : p.ResidueField →ₗ[Rₚ] Mₚ := Submodule.liftQ _ (LinearMap.toSpanSingleton Rₚ Mₚ x) (le_of_eq hx) have inj1 : Function.Injective i := LinearMap.ker_eq_bot.mp (Submodule.ker_liftQ_eq_bot _ _ _ (le_of_eq hx.symm)) let f := i.comp to_res have f_ne0 : f ≠ 0 := by intro eq0 absurd hg apply LinearMap.ext intro np' induction np' using Submodule.Quotient.induction_on with | _ np change to_res np = 0 apply inj1 change f np = _ simp [eq0] absurd hom0 let _ := Module.finitePresentation_of_finite R N contrapose! f_ne0 exact (Module.FinitePresentation.linearEquivMapExtendScalars p'.asIdeal.primeCompl).symm.map_eq_zero_iff.mp (Subsingleton.eq_zero _) end IsSMulRegular
.lake/packages/mathlib/Mathlib/RingTheory/Regular/Category.lean
import Mathlib.Algebra.Homology.ShortComplex.ModuleCat import Mathlib.RingTheory.QuotSMulTop /-! # Categorical constructions for `IsSMulRegular` -/ universe u v w variable {R : Type u} [CommRing R] (M : ModuleCat.{v} R) open CategoryTheory Ideal Pointwise lemma LinearMap.exact_smul_id_smul_top_mkQ (M : Type v) [AddCommGroup M] [Module R M] (r : R) : Function.Exact (r • LinearMap.id : M →ₗ[R] M) (r • (⊤ : Submodule R M)).mkQ := by intro x simp [Submodule.mem_smul_pointwise_iff_exists, Submodule.mem_smul_pointwise_iff_exists] namespace ModuleCat /-- The short (exact) complex `M → M → M⧸xM` obtain from the scalar multiple of `x : R` on `M`. -/ @[simps] def smulShortComplex (r : R) : ShortComplex (ModuleCat R) where X₁ := M X₂ := M X₃ := ModuleCat.of R (QuotSMulTop r M) f := ModuleCat.ofHom (r • LinearMap.id) g := ModuleCat.ofHom (r • (⊤ : Submodule R M)).mkQ zero := by ext x exact (LinearMap.exact_smul_id_smul_top_mkQ M r).apply_apply_eq_zero x lemma smulShortComplex_exact (r : R) : (smulShortComplex M r).Exact := by simp [smulShortComplex, ShortComplex.ShortExact.moduleCat_exact_iff_function_exact, LinearMap.exact_smul_id_smul_top_mkQ] instance smulShortComplex_g_epi (r : R) : Epi (smulShortComplex M r).g := by simpa [smulShortComplex, ModuleCat.epi_iff_surjective] using Submodule.mkQ_surjective _ end ModuleCat variable {M} in lemma IsSMulRegular.smulShortComplex_shortExact {r : R} (reg : IsSMulRegular M r) : (ModuleCat.smulShortComplex M r).ShortExact where exact := ModuleCat.smulShortComplex_exact M r mono_f := by simpa [ModuleCat.smulShortComplex, ModuleCat.mono_iff_injective] using reg
.lake/packages/mathlib/Mathlib/RingTheory/Regular/IsSMulRegular.lean
import Mathlib.Algebra.Module.Torsion.Basic import Mathlib.RingTheory.Flat.Basic import Mathlib.RingTheory.Ideal.AssociatedPrime.Basic import Mathlib.RingTheory.QuotSMulTop /-! # Lemmas about the `IsSMulRegular` Predicate For modules over a ring the proposition `IsSMulRegular r M` is equivalent to `r` being a *non-zero-divisor*, i.e. `r • x = 0` only if `x = 0` for `x ∈ M`. This specific result is `isSMulRegular_iff_smul_eq_zero_imp_eq_zero`. Lots of results starting from this, especially ones about quotients (which don't make sense without some algebraic assumptions), are in this file. We don't pollute the `Mathlib/Algebra/Regular/SMul.lean` file with these because it's supposed to import a minimal amount of the algebraic hierarchy. ## Tags module, regular element, commutative algebra -/ section Congr variable {R S M N} [Semiring R] [Semiring S] {σ : R →+* S} {σ' : S →+* R} [RingHomInvPair σ σ'] [RingHomInvPair σ' σ] [AddCommMonoid M] [Module R M] lemma LinearEquiv.isSMulRegular_congr' [AddCommMonoid N] [Module S N] (e : M ≃ₛₗ[σ] N) (r : R) : IsSMulRegular M r ↔ IsSMulRegular N (σ r) := e.toEquiv.isSMulRegular_congr (e.map_smul' r) lemma LinearEquiv.isSMulRegular_congr [AddCommMonoid N] [Module R N] (e : M ≃ₗ[R] N) (r : R) : IsSMulRegular M r ↔ IsSMulRegular N r := e.isSMulRegular_congr' r end Congr variable {R S M M' M'' : Type*} lemma IsSMulRegular.submodule [Semiring R] [AddCommMonoid M] [Module R M] (N : Submodule R M) (r : R) (h : IsSMulRegular M r) : IsSMulRegular N r := h.of_injective N.subtype N.injective_subtype section TensorProduct open scoped TensorProduct variable (M) [CommRing R] [AddCommGroup M] [AddCommGroup M'] [Module R M] [Module R M'] [Module.Flat R M] {r : R} (h : IsSMulRegular M' r) include h lemma IsSMulRegular.lTensor : IsSMulRegular (M ⊗[R] M') r := have h1 := congrArg DFunLike.coe (LinearMap.lTensor_smul_action M M' r) h1.subst (Module.Flat.lTensor_preserves_injective_linearMap _ h) lemma IsSMulRegular.rTensor : IsSMulRegular (M' ⊗[R] M) r := have h1 := congrArg DFunLike.coe (LinearMap.rTensor_smul_action M M' r) h1.subst (Module.Flat.rTensor_preserves_injective_linearMap _ h) end TensorProduct lemma isSMulRegular_algebraMap_iff [CommSemiring R] [Semiring S] [Algebra R S] [AddCommMonoid M] [Module R M] [Module S M] [IsScalarTower R S M] (r : R) : IsSMulRegular M (algebraMap R S r) ↔ IsSMulRegular M r := (Equiv.refl M).isSMulRegular_congr (algebraMap_smul S r) section Ring variable [Ring R] [AddCommGroup M] [Module R M] [AddCommGroup M'] [Module R M'] [AddCommGroup M''] [Module R M''] (N : Submodule R M) (r : R) lemma isSMulRegular_submodule_iff_right_eq_zero_of_smul : IsSMulRegular N r ↔ ∀ x ∈ N, r • x = 0 → x = 0 := isSMulRegular_iff_right_eq_zero_of_smul.trans <| Subtype.forall.trans <| by simp only [SetLike.mk_smul_mk, Submodule.mk_eq_zero] lemma isSMulRegular_quotient_iff_mem_of_smul_mem : IsSMulRegular (M ⧸ N) r ↔ ∀ x : M, r • x ∈ N → x ∈ N := isSMulRegular_iff_right_eq_zero_of_smul.trans <| N.mkQ_surjective.forall.trans <| by simp_rw [← map_smul, N.mkQ_apply, Submodule.Quotient.mk_eq_zero] variable {N r} lemma mem_of_isSMulRegular_quotient_of_smul_mem (h1 : IsSMulRegular (M ⧸ N) r) {x : M} (h2 : r • x ∈ N) : x ∈ N := (isSMulRegular_quotient_iff_mem_of_smul_mem N r).mp h1 x h2 @[deprecated (since := "2025-08-04")] alias isSMulRegular_on_submodule_iff_mem_imp_smul_eq_zero_imp_eq_zero := isSMulRegular_submodule_iff_right_eq_zero_of_smul @[deprecated (since := "2025-08-04")] alias isSMulRegular_on_quot_iff_smul_mem_implies_mem := isSMulRegular_quotient_iff_mem_of_smul_mem @[deprecated (since := "2025-08-04")] alias mem_of_isSMulRegular_on_quot_of_smul_mem := mem_of_isSMulRegular_quotient_of_smul_mem /-- Given a left exact sequence `0 → M → M' → M''`, if `r` is regular on both `M` and `M''` it's regular `M'` too. -/ lemma isSMulRegular_of_range_eq_ker {f : M →ₗ[R] M'} {g : M' →ₗ[R] M''} (hf : Function.Injective f) (hfg : LinearMap.range f = LinearMap.ker g) (h1 : IsSMulRegular M r) (h2 : IsSMulRegular M'' r) : IsSMulRegular M' r := by refine IsSMulRegular.of_right_eq_zero_of_smul ?_ intro x hx obtain ⟨y, ⟨⟩⟩ := (congrArg (x ∈ ·) hfg).mpr <| h2.right_eq_zero_of_smul <| (g.map_smul r x).symm.trans <| (congrArg _ hx).trans g.map_zero refine (congrArg f (h1.right_eq_zero_of_smul ?_)).trans f.map_zero exact hf <| (f.map_smul r y).trans <| hx.trans f.map_zero.symm lemma isSMulRegular_of_isSMulRegular_on_submodule_on_quotient (h1 : IsSMulRegular N r) (h2 : IsSMulRegular (M ⧸ N) r) : IsSMulRegular M r := isSMulRegular_of_range_eq_ker N.injective_subtype (N.range_subtype.trans N.ker_mkQ.symm) h1 h2 end Ring section CommRing open Submodule Pointwise variable (M) [CommRing R] [AddCommGroup M] [Module R M] [AddCommGroup M'] [Module R M'] [AddCommGroup M''] [Module R M''] (N : Submodule R M) (r : R) variable (R) in lemma biUnion_associatedPrimes_eq_compl_regular [IsNoetherianRing R] : ⋃ p ∈ associatedPrimes R M, p = { r : R | IsSMulRegular M r }ᶜ := Eq.trans (biUnion_associatedPrimes_eq_zero_divisors R M) <| by simp_rw [Set.compl_setOf, isSMulRegular_iff_right_eq_zero_of_smul, not_forall, exists_prop, and_comm] lemma isSMulRegular_iff_ker_lsmul_eq_bot : IsSMulRegular M r ↔ LinearMap.ker (LinearMap.lsmul R M r) = ⊥ := isSMulRegular_iff_torsionBy_eq_bot M r variable {M} lemma isSMulRegular_on_submodule_iff_disjoint_ker_lsmul_submodule : IsSMulRegular N r ↔ Disjoint (LinearMap.ker (LinearMap.lsmul R M r)) N := Iff.trans (isSMulRegular_submodule_iff_right_eq_zero_of_smul N r) <| Iff.symm <| Iff.trans disjoint_comm disjoint_def lemma isSMulRegular_on_quot_iff_lsmul_comap_le : IsSMulRegular (M ⧸ N) r ↔ N.comap (LinearMap.lsmul R M r) ≤ N := isSMulRegular_quotient_iff_mem_of_smul_mem N r lemma isSMulRegular_on_quot_iff_lsmul_comap_eq : IsSMulRegular (M ⧸ N) r ↔ N.comap (LinearMap.lsmul R M r) = N := Iff.trans (isSMulRegular_on_quot_iff_lsmul_comap_le N r) <| LE.le.ge_iff_eq' (fun _ => N.smul_mem r) variable {r} lemma IsSMulRegular.isSMulRegular_on_quot_iff_smul_top_inf_eq_smul : IsSMulRegular M r → (IsSMulRegular (M ⧸ N) r ↔ r • ⊤ ⊓ N ≤ r • N) := by intro (h : Function.Injective (DistribMulAction.toLinearMap R M r)) rw [isSMulRegular_on_quot_iff_lsmul_comap_le, ← map_le_map_iff_of_injective h, ← LinearMap.lsmul_eq_DistribMulAction_toLinearMap, map_comap_eq, LinearMap.range_eq_map]; rfl lemma isSMulRegular_of_ker_lsmul_eq_bot (h : LinearMap.ker (LinearMap.lsmul R M r) = ⊥) : IsSMulRegular M r := (isSMulRegular_iff_ker_lsmul_eq_bot M r).mpr h variable {N} in lemma smul_top_inf_eq_smul_of_isSMulRegular_on_quot : IsSMulRegular (M ⧸ N) r → r • ⊤ ⊓ N ≤ r • N := by convert map_mono ∘ (isSMulRegular_on_quot_iff_lsmul_comap_le N r).mp using 2 exact Eq.trans (congrArg (· ⊓ N) (map_top _)) (map_comap_eq _ _).symm -- Who knew this didn't rely on exactness at the right!? open Function in lemma QuotSMulTop.map_first_exact_on_four_term_exact_of_isSMulRegular_last {M'''} [AddCommGroup M'''] [Module R M'''] {r : R} {f₁ : M →ₗ[R] M'} {f₂ : M' →ₗ[R] M''} {f₃ : M'' →ₗ[R] M'''} (h₁₂ : Exact f₁ f₂) (h₂₃ : Exact f₂ f₃) (h : IsSMulRegular M''' r) : Exact (map r f₁) (map r f₂) := suffices IsSMulRegular (M'' ⧸ LinearMap.range f₂) r by dsimp [map, mapQLinear] rw [Exact.exact_mapQ_iff h₁₂, map_pointwise_smul, Submodule.map_top, inf_comm] exact smul_top_inf_eq_smul_of_isSMulRegular_on_quot this h.of_injective _ <| LinearMap.ker_eq_bot.mp <| ker_liftQ_eq_bot' _ _ h₂₃.linearMap_ker_eq.symm end CommRing
.lake/packages/mathlib/Mathlib/RingTheory/Regular/RegularSequence.lean
import Mathlib.RingTheory.Artinian.Module import Mathlib.RingTheory.LocalRing.MaximalIdeal.Basic import Mathlib.RingTheory.Nakayama import Mathlib.RingTheory.Regular.IsSMulRegular /-! # Regular sequences and weakly regular sequences The notion of a regular sequence is fundamental in commutative algebra. Properties of regular sequences encode information about singularities of a ring and regularity of a sequence can be tested homologically. However the notion of a regular sequence is only really sensible for Noetherian local rings. TODO: Koszul regular sequences, H_1-regular sequences, quasi-regular sequences, depth. ## Tags module, regular element, regular sequence, commutative algebra -/ universe u v open scoped Pointwise variable {R S M M₂ M₃ M₄ : Type*} namespace Ideal variable [Semiring R] [Semiring S] /-- The ideal generated by a list of elements. -/ abbrev ofList (rs : List R) := span { r | r ∈ rs } @[simp] lemma ofList_nil : (ofList [] : Ideal R) = ⊥ := have : { r | r ∈ [] } = ∅ := Set.eq_empty_of_forall_notMem (fun _ => List.not_mem_nil) Eq.trans (congrArg span this) span_empty @[simp] lemma ofList_append (rs₁ rs₂ : List R) : ofList (rs₁ ++ rs₂) = ofList rs₁ ⊔ ofList rs₂ := have : { r | r ∈ rs₁ ++ rs₂ } = _ := Set.ext (fun _ => List.mem_append) Eq.trans (congrArg span this) (span_union _ _) lemma ofList_singleton (r : R) : ofList [r] = span {r} := congrArg span (Set.ext fun _ => List.mem_singleton) @[simp] lemma ofList_cons (r : R) (rs : List R) : ofList (r::rs) = span {r} ⊔ ofList rs := Eq.trans (ofList_append [r] rs) (congrArg (· ⊔ _) (ofList_singleton r)) @[simp] lemma map_ofList (f : R →+* S) (rs : List R) : map f (ofList rs) = ofList (rs.map f) := Eq.trans (map_span f { r | r ∈ rs }) <| congrArg span <| Set.ext (fun _ => List.mem_map.symm) lemma ofList_cons_smul {R} [CommSemiring R] (r : R) (rs : List R) {M} [AddCommMonoid M] [Module R M] (N : Submodule R M) : ofList (r :: rs) • N = r • N ⊔ ofList rs • N := by rw [ofList_cons, Submodule.sup_smul, Submodule.ideal_span_singleton_smul] end Ideal namespace Submodule lemma smul_top_le_comap_smul_top [Semiring R] [AddCommMonoid M] [AddCommMonoid M₂] [Module R M] [Module R M₂] (I : Ideal R) (f : M →ₗ[R] M₂) : I • ⊤ ≤ comap f (I • ⊤) := map_le_iff_le_comap.mp <| le_of_eq_of_le (map_smul'' _ _ _) <| smul_mono_right _ le_top variable (M) [CommRing R] [AddCommGroup M] [AddCommGroup M₂] [Module R M] [Module R M₂] (r : R) (rs : List R) /-- The equivalence between M ⧸ (r₀, r₁, …, rₙ)M and (M ⧸ r₀M) ⧸ (r₁, …, rₙ) (M ⧸ r₀M). -/ def quotOfListConsSMulTopEquivQuotSMulTopInner : (M ⧸ (Ideal.ofList (r :: rs) • ⊤ : Submodule R M)) ≃ₗ[R] QuotSMulTop r M ⧸ (Ideal.ofList rs • ⊤ : Submodule R (QuotSMulTop r M)) := quotEquivOfEq _ _ (Ideal.ofList_cons_smul r rs ⊤) ≪≫ₗ (quotientQuotientEquivQuotientSup (r • ⊤) (Ideal.ofList rs • ⊤)).symm ≪≫ₗ quotEquivOfEq _ _ (by rw [map_smul'', map_top, range_mkQ]) /-- The equivalence between M ⧸ (r₀, r₁, …, rₙ)M and (M ⧸ (r₁, …, rₙ)) ⧸ r₀ (M ⧸ (r₁, …, rₙ)). -/ def quotOfListConsSMulTopEquivQuotSMulTopOuter : (M ⧸ (Ideal.ofList (r :: rs) • ⊤ : Submodule R M)) ≃ₗ[R] QuotSMulTop r (M ⧸ (Ideal.ofList rs • ⊤ : Submodule R M)) := quotEquivOfEq _ _ (Eq.trans (Ideal.ofList_cons_smul r rs ⊤) (sup_comm _ _)) ≪≫ₗ (quotientQuotientEquivQuotientSup (Ideal.ofList rs • ⊤) (r • ⊤)).symm ≪≫ₗ quotEquivOfEq _ _ (by rw [map_pointwise_smul, map_top, range_mkQ]) variable {M} lemma quotOfListConsSMulTopEquivQuotSMulTopInner_naturality (f : M →ₗ[R] M₂) : (quotOfListConsSMulTopEquivQuotSMulTopInner M₂ r rs).toLinearMap ∘ₗ mapQ _ _ _ (smul_top_le_comap_smul_top (Ideal.ofList (r :: rs)) f) = mapQ _ _ _ (smul_top_le_comap_smul_top _ (QuotSMulTop.map r f)) ∘ₗ (quotOfListConsSMulTopEquivQuotSMulTopInner M r rs).toLinearMap := quot_hom_ext _ _ _ fun _ => rfl lemma top_eq_ofList_cons_smul_iff : (⊤ : Submodule R M) = Ideal.ofList (r :: rs) • ⊤ ↔ (⊤ : Submodule R (QuotSMulTop r M)) = Ideal.ofList rs • ⊤ := by conv => congr <;> rw [eq_comm, ← subsingleton_quotient_iff_eq_top] exact (quotOfListConsSMulTopEquivQuotSMulTopInner M r rs).toEquiv.subsingleton_congr end Submodule namespace RingTheory.Sequence open scoped TensorProduct List open Function Submodule QuotSMulTop variable (S M) section Definitions /- In theory, regularity of `rs : List α` on `M` makes sense as soon as `[Monoid α]`, `[AddCommGroup M]`, and `[DistribMulAction α M]`. Instead of `Ideal.ofList (rs.take i) • (⊤ : Submodule R M)` we use `⨆ (j : Fin i), rs[j] • (⊤ : AddSubgroup M)`. However it's not clear that this is a useful generalization. If we add the assumption `[SMulCommClass α α M]` this is essentially the same as focusing on the commutative ring case, by passing to the monoid ring `ℤ[abelianization of α]`. -/ variable [CommRing R] [AddCommGroup M] [Module R M] open Ideal /-- A sequence `[r₁, …, rₙ]` is weakly regular on `M` iff `rᵢ` is regular on `M⧸(r₁, …, rᵢ₋₁)M` for all `1 ≤ i ≤ n`. -/ @[mk_iff] structure IsWeaklyRegular (rs : List R) : Prop where regular_mod_prev : ∀ i (h : i < rs.length), IsSMulRegular (M ⧸ (ofList (rs.take i) • ⊤ : Submodule R M)) rs[i] lemma isWeaklyRegular_iff_Fin (rs : List R) : IsWeaklyRegular M rs ↔ ∀ (i : Fin rs.length), IsSMulRegular (M ⧸ (ofList (rs.take i) • ⊤ : Submodule R M)) rs[i] := Iff.trans (isWeaklyRegular_iff M rs) (Iff.symm Fin.forall_iff) /-- A weakly regular sequence `rs` on `M` is regular if also `M/rsM ≠ 0`. -/ @[mk_iff] structure IsRegular (rs : List R) : Prop extends IsWeaklyRegular M rs where top_ne_smul : (⊤ : Submodule R M) ≠ Ideal.ofList rs • ⊤ end Definitions section Congr variable {S M} [CommRing R] [CommRing S] [AddCommGroup M] [AddCommGroup M₂] [Module R M] [Module S M₂] {σ : R →+* S} {σ' : S →+* R} [RingHomInvPair σ σ'] [RingHomInvPair σ' σ] open DistribMulAction AddSubgroup in private lemma _root_.AddHom.map_smul_top_toAddSubgroup_of_surjective {f : M →+ M₂} {as : List R} {bs : List S} (hf : Function.Surjective f) (h : List.Forall₂ (fun r s => ∀ x, f (r • x) = s • f x) as bs) : (Ideal.ofList as • ⊤ : Submodule R M).toAddSubgroup.map f = (Ideal.ofList bs • ⊤ : Submodule S M₂).toAddSubgroup := by induction h with | nil => convert AddSubgroup.map_bot f using 1 <;> rw [Ideal.ofList_nil, bot_smul, bot_toAddSubgroup] | @cons r s _ _ h _ ih => conv => congr <;> rw [Ideal.ofList_cons, sup_smul, sup_toAddSubgroup, ideal_span_singleton_smul, pointwise_smul_toAddSubgroup, top_toAddSubgroup, pointwise_smul_def] apply DFunLike.ext (f.comp (toAddMonoidEnd R M r)) ((toAddMonoidEnd S M₂ s).comp f) at h rw [AddSubgroup.map_sup, ih, map_map, h, ← map_map, map_top_of_surjective f hf] lemma _root_.AddEquiv.isWeaklyRegular_congr {e : M ≃+ M₂} {as bs} (h : List.Forall₂ (fun (r : R) (s : S) => ∀ x, e (r • x) = s • e x) as bs) : IsWeaklyRegular M as ↔ IsWeaklyRegular M₂ bs := by conv => congr <;> rw [isWeaklyRegular_iff_Fin] let e' i : (M ⧸ (Ideal.ofList (as.take i) • ⊤ : Submodule R M)) ≃+ M₂ ⧸ (Ideal.ofList (bs.take i) • ⊤ : Submodule S M₂) := QuotientAddGroup.congr _ _ e <| AddHom.map_smul_top_toAddSubgroup_of_surjective e.surjective <| List.forall₂_take i h refine (finCongr h.length_eq).forall_congr @fun _ => (e' _).isSMulRegular_congr ?_ exact (mkQ_surjective _).forall.mpr fun _ => congrArg (mkQ _) (h.get _ _ _) lemma _root_.LinearEquiv.isWeaklyRegular_congr' (e : M ≃ₛₗ[σ] M₂) (rs : List R) : IsWeaklyRegular M rs ↔ IsWeaklyRegular M₂ (rs.map σ) := e.toAddEquiv.isWeaklyRegular_congr <| List.forall₂_map_right_iff.mpr <| List.forall₂_same.mpr fun r _ x => e.map_smul' r x lemma _root_.LinearEquiv.isWeaklyRegular_congr [Module R M₂] (e : M ≃ₗ[R] M₂) (rs : List R) : IsWeaklyRegular M rs ↔ IsWeaklyRegular M₂ rs := Iff.trans (e.isWeaklyRegular_congr' rs) <| iff_of_eq <| congrArg _ rs.map_id lemma _root_.AddEquiv.isRegular_congr {e : M ≃+ M₂} {as bs} (h : List.Forall₂ (fun (r : R) (s : S) => ∀ x, e (r • x) = s • e x) as bs) : IsRegular M as ↔ IsRegular M₂ bs := by conv => congr <;> rw [isRegular_iff, ne_eq, eq_comm, ← subsingleton_quotient_iff_eq_top] let e' := QuotientAddGroup.congr _ _ e <| AddHom.map_smul_top_toAddSubgroup_of_surjective e.surjective h exact and_congr (e.isWeaklyRegular_congr h) e'.subsingleton_congr.not lemma _root_.LinearEquiv.isRegular_congr' (e : M ≃ₛₗ[σ] M₂) (rs : List R) : IsRegular M rs ↔ IsRegular M₂ (rs.map σ) := e.toAddEquiv.isRegular_congr <| List.forall₂_map_right_iff.mpr <| List.forall₂_same.mpr fun r _ x => e.map_smul' r x lemma _root_.LinearEquiv.isRegular_congr [Module R M₂] (e : M ≃ₗ[R] M₂) (rs : List R) : IsRegular M rs ↔ IsRegular M₂ rs := Iff.trans (e.isRegular_congr' rs) <| iff_of_eq <| congrArg _ rs.map_id end Congr lemma isWeaklyRegular_map_algebraMap_iff [CommRing R] [CommRing S] [Algebra R S] [AddCommGroup M] [Module R M] [Module S M] [IsScalarTower R S M] (rs : List R) : IsWeaklyRegular M (rs.map (algebraMap R S)) ↔ IsWeaklyRegular M rs := (AddEquiv.refl M).isWeaklyRegular_congr <| List.forall₂_map_left_iff.mpr <| List.forall₂_same.mpr fun r _ => algebraMap_smul S r variable [CommRing R] [AddCommGroup M] [AddCommGroup M₂] [AddCommGroup M₃] [AddCommGroup M₄] [Module R M] [Module R M₂] [Module R M₃] [Module R M₄] @[simp] lemma isWeaklyRegular_cons_iff (r : R) (rs : List R) : IsWeaklyRegular M (r :: rs) ↔ IsSMulRegular M r ∧ IsWeaklyRegular (QuotSMulTop r M) rs := have := Eq.trans (congrArg (· • ⊤) Ideal.ofList_nil) (bot_smul ⊤) let e i := quotOfListConsSMulTopEquivQuotSMulTopInner M r (rs.take i) Iff.trans (isWeaklyRegular_iff_Fin _ _) <| Iff.trans Fin.forall_iff_succ <| and_congr ((quotEquivOfEqBot _ this).isSMulRegular_congr r) <| Iff.trans (forall_congr' fun i => (e i).isSMulRegular_congr (rs.get i)) (isWeaklyRegular_iff_Fin _ _).symm lemma isWeaklyRegular_cons_iff' (r : R) (rs : List R) : IsWeaklyRegular M (r :: rs) ↔ IsSMulRegular M r ∧ IsWeaklyRegular (QuotSMulTop r M) (rs.map (Ideal.Quotient.mk (Ideal.span {r}))) := Iff.trans (isWeaklyRegular_cons_iff M r rs) <| and_congr_right' <| Iff.symm <| isWeaklyRegular_map_algebraMap_iff (R ⧸ Ideal.span {r}) _ rs @[simp] lemma isRegular_cons_iff (r : R) (rs : List R) : IsRegular M (r :: rs) ↔ IsSMulRegular M r ∧ IsRegular (QuotSMulTop r M) rs := by rw [isRegular_iff, isRegular_iff, isWeaklyRegular_cons_iff M r rs, ne_eq, top_eq_ofList_cons_smul_iff, and_assoc] lemma isRegular_cons_iff' (r : R) (rs : List R) : IsRegular M (r :: rs) ↔ IsSMulRegular M r ∧ IsRegular (QuotSMulTop r M) (rs.map (Ideal.Quotient.mk (Ideal.span {r}))) := by conv => congr <;> rw [isRegular_iff, ne_eq] rw [isWeaklyRegular_cons_iff', ← restrictScalars_inj R (R ⧸ _), ← Ideal.map_ofList, ← Ideal.Quotient.algebraMap_eq, Ideal.smul_restrictScalars, restrictScalars_top, top_eq_ofList_cons_smul_iff, and_assoc] variable {M} namespace IsWeaklyRegular variable (R M) in @[simp] lemma nil : IsWeaklyRegular M ([] : List R) := .mk (False.elim <| Nat.not_lt_zero · ·) lemma cons {r : R} {rs : List R} (h1 : IsSMulRegular M r) (h2 : IsWeaklyRegular (QuotSMulTop r M) rs) : IsWeaklyRegular M (r :: rs) := (isWeaklyRegular_cons_iff M r rs).mpr ⟨h1, h2⟩ lemma cons' {r : R} {rs : List R} (h1 : IsSMulRegular M r) (h2 : IsWeaklyRegular (QuotSMulTop r M) (rs.map (Ideal.Quotient.mk (Ideal.span {r})))) : IsWeaklyRegular M (r :: rs) := (isWeaklyRegular_cons_iff' M r rs).mpr ⟨h1, h2⟩ /-- Weakly regular sequences can be inductively characterized by: * The empty sequence is weakly regular on any module. * If `r` is regular on `M` and `rs` is a weakly regular sequence on `M⧸rM` then the sequence obtained from `rs` by prepending `r` is weakly regular on `M`. This is the induction principle produced by the inductive definition above. The motive will usually be valued in `Prop`, but `Sort*` works too. -/ @[induction_eliminator] def recIterModByRegular {motive : (M : Type v) → [AddCommGroup M] → [Module R M] → (rs : List R) → IsWeaklyRegular M rs → Sort*} (nil : (M : Type v) → [AddCommGroup M] → [Module R M] → motive M [] (nil R M)) (cons : {M : Type v} → [AddCommGroup M] → [Module R M] → (r : R) → (rs : List R) → (h1 : IsSMulRegular M r) → (h2 : IsWeaklyRegular (QuotSMulTop r M) rs) → (ih : motive (QuotSMulTop r M) rs h2) → motive M (r :: rs) (cons h1 h2)) : {M : Type v} → [AddCommGroup M] → [Module R M] → {rs : List R} → (h : IsWeaklyRegular M rs) → motive M rs h | M, _, _, [], _ => nil M | M, _, _, r :: rs, h => let ⟨h1, h2⟩ := (isWeaklyRegular_cons_iff M r rs).mp h cons r rs h1 h2 (recIterModByRegular nil cons h2) /-- A simplified version of `IsWeaklyRegular.recIterModByRegular` where the motive is not allowed to depend on the proof of `IsWeaklyRegular`. -/ def ndrecIterModByRegular {motive : (M : Type v) → [AddCommGroup M] → [Module R M] → (rs : List R) → Sort*} (nil : (M : Type v) → [AddCommGroup M] → [Module R M] → motive M []) (cons : {M : Type v} → [AddCommGroup M] → [Module R M] → (r : R) → (rs : List R) → IsSMulRegular M r → IsWeaklyRegular (QuotSMulTop r M) rs → motive (QuotSMulTop r M) rs → motive M (r :: rs)) {M} [AddCommGroup M] [Module R M] {rs} : IsWeaklyRegular M rs → motive M rs := recIterModByRegular (motive := fun M _ _ rs _ => motive M rs) nil cons /-- An alternate induction principle from `IsWeaklyRegular.recIterModByRegular` where we mod out by successive elements in both the module and the base ring. This is useful for propagating certain properties of the initial `M`, e.g. faithfulness or freeness, throughout the induction. -/ def recIterModByRegularWithRing {motive : (R : Type u) → [CommRing R] → (M : Type v) → [AddCommGroup M] → [Module R M] → (rs : List R) → IsWeaklyRegular M rs → Sort*} (nil : (R : Type u) → [CommRing R] → (M : Type v) → [AddCommGroup M] → [Module R M] → motive R M [] (nil R M)) (cons : {R : Type u} → [CommRing R] → {M : Type v} → [AddCommGroup M] → [Module R M] → (r : R) → (rs : List R) → (h1 : IsSMulRegular M r) → (h2 : IsWeaklyRegular (QuotSMulTop r M) (rs.map (Ideal.Quotient.mk (Ideal.span {r})))) → (ih : motive (R ⧸ Ideal.span {r}) (QuotSMulTop r M) (rs.map (Ideal.Quotient.mk (Ideal.span {r}))) h2) → motive R M (r :: rs) (cons' h1 h2)) : {R : Type u} → [CommRing R] → {M : Type v} → [AddCommGroup M] → [Module R M] → {rs : List R} → (h : IsWeaklyRegular M rs) → motive R M rs h | R, _, M, _, _, [], _ => nil R M | _, _, M, _, _, r :: rs, h => let ⟨h1, h2⟩ := (isWeaklyRegular_cons_iff' M r rs).mp h cons r rs h1 h2 (recIterModByRegularWithRing nil cons h2) termination_by _ _ _ _ _ rs => List.length rs /-- A simplified version of `IsWeaklyRegular.recIterModByRegularWithRing` where the motive is not allowed to depend on the proof of `IsWeaklyRegular`. -/ def ndrecWithRing {motive : (R : Type u) → [CommRing R] → (M : Type v) → [AddCommGroup M] → [Module R M] → (rs : List R) → Sort*} (nil : (R : Type u) → [CommRing R] → (M : Type v) → [AddCommGroup M] → [Module R M] → motive R M []) (cons : {R : Type u} → [CommRing R] → {M : Type v} → [AddCommGroup M] → [Module R M] → (r : R) → (rs : List R) → IsSMulRegular M r → IsWeaklyRegular (QuotSMulTop r M) (rs.map (Ideal.Quotient.mk (Ideal.span {r}))) → motive (R ⧸ Ideal.span {r}) (QuotSMulTop r M) (rs.map (Ideal.Quotient.mk (Ideal.span {r}))) → motive R M (r :: rs)) {R} [CommRing R] {M} [AddCommGroup M] [Module R M] {rs} : IsWeaklyRegular M rs → motive R M rs := recIterModByRegularWithRing (motive := fun R _ M _ _ rs _ => motive R M rs) nil cons end IsWeaklyRegular section variable (M) lemma isWeaklyRegular_singleton_iff (r : R) : IsWeaklyRegular M [r] ↔ IsSMulRegular M r := Iff.trans (isWeaklyRegular_cons_iff M r []) (and_iff_left (.nil R _)) lemma isWeaklyRegular_append_iff (rs₁ rs₂ : List R) : IsWeaklyRegular M (rs₁ ++ rs₂) ↔ IsWeaklyRegular M rs₁ ∧ IsWeaklyRegular (M ⧸ (Ideal.ofList rs₁ • ⊤ : Submodule R M)) rs₂ := by induction rs₁ generalizing M with | nil => refine Iff.symm <| Iff.trans (and_iff_right (.nil R M)) ?_ refine (quotEquivOfEqBot _ ?_).isWeaklyRegular_congr rs₂ rw [Ideal.ofList_nil, bot_smul] | cons r rs₁ ih => let e := quotOfListConsSMulTopEquivQuotSMulTopInner M r rs₁ rw [List.cons_append, isWeaklyRegular_cons_iff, isWeaklyRegular_cons_iff, ih, ← and_assoc, ← e.isWeaklyRegular_congr rs₂] lemma isWeaklyRegular_append_iff' (rs₁ rs₂ : List R) : IsWeaklyRegular M (rs₁ ++ rs₂) ↔ IsWeaklyRegular M rs₁ ∧ IsWeaklyRegular (M ⧸ (Ideal.ofList rs₁ • ⊤ : Submodule R M)) (rs₂.map (Ideal.Quotient.mk (Ideal.ofList rs₁))) := Iff.trans (isWeaklyRegular_append_iff M rs₁ rs₂) <| and_congr_right' <| Iff.symm <| isWeaklyRegular_map_algebraMap_iff (R ⧸ Ideal.ofList rs₁) _ rs₂ end namespace IsRegular variable (R M) in lemma nil [Nontrivial M] : IsRegular M ([] : List R) where toIsWeaklyRegular := IsWeaklyRegular.nil R M top_ne_smul h := by rw [Ideal.ofList_nil, bot_smul, eq_comm, subsingleton_iff_bot_eq_top] at h exact not_subsingleton M ((Submodule.subsingleton_iff _).mp h) lemma cons {r : R} {rs : List R} (h1 : IsSMulRegular M r) (h2 : IsRegular (QuotSMulTop r M) rs) : IsRegular M (r :: rs) := (isRegular_cons_iff M r rs).mpr ⟨h1, h2⟩ lemma cons' {r : R} {rs : List R} (h1 : IsSMulRegular M r) (h2 : IsRegular (QuotSMulTop r M) (rs.map (Ideal.Quotient.mk (Ideal.span {r})))) : IsRegular M (r :: rs) := (isRegular_cons_iff' M r rs).mpr ⟨h1, h2⟩ /-- Regular sequences can be inductively characterized by: * The empty sequence is regular on any nonzero module. * If `r` is regular on `M` and `rs` is a regular sequence on `M⧸rM` then the sequence obtained from `rs` by prepending `r` is regular on `M`. This is the induction principle produced by the inductive definition above. The motive will usually be valued in `Prop`, but `Sort*` works too. -/ @[induction_eliminator] def recIterModByRegular {motive : (M : Type v) → [AddCommGroup M] → [Module R M] → (rs : List R) → IsRegular M rs → Sort*} (nil : (M : Type v) → [AddCommGroup M] → [Module R M] → [Nontrivial M] → motive M [] (nil R M)) (cons : {M : Type v} → [AddCommGroup M] → [Module R M] → (r : R) → (rs : List R) → (h1 : IsSMulRegular M r) → (h2 : IsRegular (QuotSMulTop r M) rs) → (ih : motive (QuotSMulTop r M) rs h2) → motive M (r :: rs) (cons h1 h2)) {M} [AddCommGroup M] [Module R M] {rs} (h : IsRegular M rs) : motive M rs h := h.toIsWeaklyRegular.recIterModByRegular (motive := fun N _ _ rs' h' => ∀ h'', motive N rs' ⟨h', h''⟩) (fun N _ _ h' => haveI := (nontrivial_iff R).mp (nontrivial_of_ne _ _ h'); nil N) (fun r rs' h1 h2 h3 h4 => have ⟨h5, h6⟩ := (isRegular_cons_iff _ _ _).mp ⟨h2.cons h1, h4⟩ cons r rs' h5 h6 (h3 h6.top_ne_smul)) h.top_ne_smul /-- A simplified version of `IsRegular.recIterModByRegular` where the motive is not allowed to depend on the proof of `IsRegular`. -/ def ndrecIterModByRegular {motive : (M : Type v) → [AddCommGroup M] → [Module R M] → (rs : List R) → Sort*} (nil : (M : Type v) → [AddCommGroup M] → [Module R M] → [Nontrivial M] → motive M []) (cons : {M : Type v} → [AddCommGroup M] → [Module R M] → (r : R) → (rs : List R) → IsSMulRegular M r → IsRegular (QuotSMulTop r M) rs → motive (QuotSMulTop r M) rs → motive M (r :: rs)) {M} [AddCommGroup M] [Module R M] {rs} : IsRegular M rs → motive M rs := recIterModByRegular (motive := fun M _ _ rs _ => motive M rs) nil cons /-- An alternate induction principle from `IsRegular.recIterModByRegular` where we mod out by successive elements in both the module and the base ring. This is useful for propagating certain properties of the initial `M`, e.g. faithfulness or freeness, throughout the induction. -/ def recIterModByRegularWithRing {motive : (R : Type u) → [CommRing R] → (M : Type v) → [AddCommGroup M] → [Module R M] → (rs : List R) → IsRegular M rs → Sort*} (nil : (R : Type u) → [CommRing R] → (M : Type v) → [AddCommGroup M] → [Module R M] → [Nontrivial M] → motive R M [] (nil R M)) (cons : {R : Type u} → [CommRing R] → {M : Type v} → [AddCommGroup M] → [Module R M] → (r : R) → (rs : List R) → (h1 : IsSMulRegular M r) → (h2 : IsRegular (QuotSMulTop r M) (rs.map (Ideal.Quotient.mk (Ideal.span {r})))) → (ih : motive (R ⧸ Ideal.span {r}) (QuotSMulTop r M) (rs.map (Ideal.Quotient.mk (Ideal.span {r}))) h2) → motive R M (r :: rs) (cons' h1 h2)) {R} [CommRing R] {M} [AddCommGroup M] [Module R M] {rs} (h : IsRegular M rs) : motive R M rs h := h.toIsWeaklyRegular.recIterModByRegularWithRing (motive := fun R _ N _ _ rs' h' => ∀ h'', motive R N rs' ⟨h', h''⟩) (fun R _ N _ _ h' => haveI := (nontrivial_iff R).mp (nontrivial_of_ne _ _ h'); nil R N) (fun r rs' h1 h2 h3 h4 => have ⟨h5, h6⟩ := (isRegular_cons_iff' _ _ _).mp ⟨h2.cons' h1, h4⟩ cons r rs' h5 h6 <| h3 h6.top_ne_smul) h.top_ne_smul /-- A simplified version of `IsRegular.recIterModByRegularWithRing` where the motive is not allowed to depend on the proof of `IsRegular`. -/ def ndrecIterModByRegularWithRing {motive : (R : Type u) → [CommRing R] → (M : Type v) → [AddCommGroup M] → [Module R M] → (rs : List R) → Sort*} (nil : (R : Type u) → [CommRing R] → (M : Type v) → [AddCommGroup M] → [Module R M] → [Nontrivial M] → motive R M []) (cons : {R : Type u} → [CommRing R] → {M : Type v} → [AddCommGroup M] → [Module R M] → (r : R) → (rs : List R) → IsSMulRegular M r → IsRegular (QuotSMulTop r M) (rs.map (Ideal.Quotient.mk (Ideal.span {r}))) → motive (R ⧸ Ideal.span {r}) (QuotSMulTop r M) (rs.map (Ideal.Quotient.mk (Ideal.span {r}))) → motive R M (r :: rs)) {R} [CommRing R] {M} [AddCommGroup M] [Module R M] {rs} : IsRegular M rs → motive R M rs := recIterModByRegularWithRing (motive := fun R _ M _ _ rs _ => motive R M rs) nil cons lemma quot_ofList_smul_nontrivial {rs : List R} (h : IsRegular M rs) (N : Submodule R M) : Nontrivial (M ⧸ Ideal.ofList rs • N) := Submodule.Quotient.nontrivial_of_lt_top _ <| lt_of_le_of_lt (smul_mono_right _ le_top) h.top_ne_smul.symm.lt_top lemma nontrivial {rs : List R} (h : IsRegular M rs) : Nontrivial M := haveI := quot_ofList_smul_nontrivial h ⊤ (mkQ_surjective (Ideal.ofList rs • ⊤ : Submodule R M)).nontrivial end IsRegular lemma isRegular_iff_isWeaklyRegular_of_subset_jacobson_annihilator [Nontrivial M] [Module.Finite R M] {rs : List R} (h : ∀ r ∈ rs, r ∈ Ideal.jacobson (Module.annihilator R M)) : IsRegular M rs ↔ IsWeaklyRegular M rs := Iff.trans (isRegular_iff M rs) <| and_iff_left <| top_ne_ideal_smul_of_le_jacobson_annihilator <| Ideal.span_le.mpr h lemma _root_.IsLocalRing.isRegular_iff_isWeaklyRegular_of_subset_maximalIdeal [IsLocalRing R] [Nontrivial M] [Module.Finite R M] {rs : List R} (h : ∀ r ∈ rs, r ∈ IsLocalRing.maximalIdeal R) : IsRegular M rs ↔ IsWeaklyRegular M rs := have H h' := bot_ne_top.symm <| annihilator_eq_top_iff.mp <| Eq.trans annihilator_top h' isRegular_iff_isWeaklyRegular_of_subset_jacobson_annihilator fun r hr => IsLocalRing.jacobson_eq_maximalIdeal (Module.annihilator R M) H ▸ h r hr open IsWeaklyRegular IsArtinian in lemma eq_nil_of_isRegular_on_artinian [IsArtinian R M] : {rs : List R} → IsRegular M rs → rs = [] | [], _ => rfl | r :: rs, h => by rw [isRegular_iff, ne_comm, ← lt_top_iff_ne_top, Ideal.ofList_cons, sup_smul, ideal_span_singleton_smul, isWeaklyRegular_cons_iff] at h refine absurd ?_ (ne_of_lt (lt_of_le_of_lt le_sup_left h.right)) exact Eq.trans (Submodule.map_top _) <| LinearMap.range_eq_top.mpr <| surjective_of_injective_endomorphism (LinearMap.lsmul R M r) h.left.left lemma IsWeaklyRegular.isWeaklyRegular_lTensor [Module.Flat R M₂] {rs : List R} (h : IsWeaklyRegular M rs) : IsWeaklyRegular (M₂ ⊗[R] M) rs := by induction h with | nil N => exact nil R (M₂ ⊗[R] N) | @cons N _ _ r rs' h1 _ ih => let e := tensorQuotSMulTopEquivQuotSMulTop r M₂ N exact ((e.isWeaklyRegular_congr rs').mp ih).cons (h1.lTensor M₂) lemma IsWeaklyRegular.isWeaklyRegular_rTensor [Module.Flat R M₂] {rs : List R} (h : IsWeaklyRegular M rs) : IsWeaklyRegular (M ⊗[R] M₂) rs := by induction h with | nil N => exact nil R (N ⊗[R] M₂) | @cons N _ _ r rs' h1 _ ih => let e := quotSMulTopTensorEquivQuotSMulTop r M₂ N exact ((e.isWeaklyRegular_congr rs').mp ih).cons (h1.rTensor M₂) -- TODO: apply the above to localization and completion (Corollary 1.1.3 in B&H) lemma map_first_exact_on_four_term_right_exact_of_isSMulRegular_last {rs : List R} {f₁ : M →ₗ[R] M₂} {f₂ : M₂ →ₗ[R] M₃} {f₃ : M₃ →ₗ[R] M₄} (h₁₂ : Exact f₁ f₂) (h₂₃ : Exact f₂ f₃) (h₃ : Surjective f₃) (h₄ : IsWeaklyRegular M₄ rs) : Exact (mapQ _ _ _ (smul_top_le_comap_smul_top (Ideal.ofList rs) f₁)) (mapQ _ _ _ (smul_top_le_comap_smul_top (Ideal.ofList rs) f₂)) := by induction h₄ generalizing M M₂ M₃ with | nil => apply (Exact.iff_of_ladder_linearEquiv ?_ ?_).mp h₁₂ any_goals exact quotEquivOfEqBot _ <| Eq.trans (congrArg (· • ⊤) Ideal.ofList_nil) (bot_smul ⊤) all_goals exact quot_hom_ext _ _ _ fun _ => rfl | cons r rs h₄ _ ih => specialize ih (map_first_exact_on_four_term_exact_of_isSMulRegular_last h₁₂ h₂₃ h₄) (map_exact r h₂₃ h₃) (map_surjective r h₃) have H₁ := quotOfListConsSMulTopEquivQuotSMulTopInner_naturality r rs f₁ have H₂ := quotOfListConsSMulTopEquivQuotSMulTopInner_naturality r rs f₂ exact (Exact.iff_of_ladder_linearEquiv H₁.symm H₂.symm).mp ih -- todo: modding out a complex by a regular sequence (prop 1.1.5 in B&H) section Perm open _root_.LinearMap in private lemma IsWeaklyRegular.swap {a b : R} (h1 : IsWeaklyRegular M [a, b]) (h2 : torsionBy R M b = a • torsionBy R M b → torsionBy R M b = ⊥) : IsWeaklyRegular M [b, a] := by rw [isWeaklyRegular_cons_iff, isWeaklyRegular_singleton_iff] at h1 ⊢ obtain ⟨ha, hb⟩ := h1 rw [← isSMulRegular_iff_torsionBy_eq_bot] at h2 specialize h2 (le_antisymm ?_ (smul_le_self_of_tower a (torsionBy R M b))) · refine le_of_eq_of_le ?_ <| smul_top_inf_eq_smul_of_isSMulRegular_on_quot <| ha.of_injective _ <| ker_eq_bot.mp <| ker_liftQ_eq_bot' _ (lsmul R M b) rfl rw [← (isSMulRegular_on_quot_iff_lsmul_comap_eq _ _).mp hb] exact (inf_eq_right.mpr (ker_le_comap _)).symm · rwa [ha.isSMulRegular_on_quot_iff_smul_top_inf_eq_smul, inf_comm, smul_comm, ← h2.isSMulRegular_on_quot_iff_smul_top_inf_eq_smul, and_iff_left hb] -- TODO: Equivalence of permutability of regular sequences to regularity of -- subsequences and regularity on poly ring. See [07DW] in stacks project -- We need a theory of multivariate polynomial modules first lemma IsWeaklyRegular.prototype_perm {rs : List R} (h : IsWeaklyRegular M rs) {rs'} (h'' : rs ~ rs') (h' : ∀ a b rs', (a :: b :: rs') <+~ rs → let K := torsionBy R (M ⧸ (Ideal.ofList rs' • ⊤ : Submodule R M)) b K = a • K → K = ⊥) : IsWeaklyRegular M rs' := have H := LinearEquiv.isWeaklyRegular_congr <| quotEquivOfEqBot _ <| Eq.trans (congrArg (· • ⊤) Ideal.ofList_nil) (bot_smul ⊤) (H rs').mp <| (aux [] h'' (.refl rs) (h''.symm.subperm)) <| (H rs).mpr h where aux {rs₁ rs₂} (rs₀ : List R) (h₁₂ : rs₁ ~ rs₂) (H₁ : rs₀ ++ rs₁ <+~ rs) (H₃ : rs₀ ++ rs₂ <+~ rs) (h : IsWeaklyRegular (M ⧸ (Ideal.ofList rs₀ • ⊤ : Submodule R M)) rs₁) : IsWeaklyRegular (M ⧸ (Ideal.ofList rs₀ • ⊤ : Submodule R M)) rs₂ := by { induction h₁₂ generalizing rs₀ with | nil => exact .nil R _ | cons r _ ih => let e := quotOfListConsSMulTopEquivQuotSMulTopOuter M r rs₀ rw [isWeaklyRegular_cons_iff, ← e.isWeaklyRegular_congr] at h ⊢ refine h.imp_right (ih (r :: rs₀) ?_ ?_) <;> exact List.perm_middle.subperm_right.mp ‹_› | swap a b t => rw [show ∀ x y z, x :: y :: z = [x, y] ++ z from fun _ _ _ => rfl, isWeaklyRegular_append_iff] at h ⊢ have : Ideal.ofList [b, a] = Ideal.ofList [a, b] := congrArg Ideal.span <| Set.ext fun _ => (List.Perm.swap a b []).mem_iff rw [(quotEquivOfEq _ _ (congrArg₂ _ this rfl)).isWeaklyRegular_congr] at h rw [List.append_cons, List.append_cons, List.append_assoc _ [b] [a]] at H₁ apply (List.sublist_append_left (rs₀ ++ [b, a]) _).subperm.trans at H₁ apply List.perm_append_comm.subperm.trans at H₁ exact h.imp_left (swap · (h' b a rs₀ H₁)) | trans h₁₂ _ ih₁₂ ih₂₃ => have H₂ := (h₁₂.append_left rs₀).subperm_right.mp H₁ exact ih₂₃ rs₀ H₂ H₃ (ih₁₂ rs₀ H₁ H₂ h) } -- putting `{rs' : List R}` and `h2` after `h3` would be better for partial -- application, but this argument order seems nicer overall lemma IsWeaklyRegular.of_perm_of_subset_jacobson_annihilator [IsNoetherian R M] {rs rs' : List R} (h1 : IsWeaklyRegular M rs) (h2 : List.Perm rs rs') (h3 : ∀ r ∈ rs, r ∈ (Module.annihilator R M).jacobson) : IsWeaklyRegular M rs' := h1.prototype_perm h2 fun r _ _ h h' => eq_bot_of_eq_pointwise_smul_of_mem_jacobson_annihilator (IsNoetherian.noetherian _) h' (Ideal.jacobson_mono (le_trans -- The named argument `(R := R)` below isn't necessary, but -- typechecking is much slower without it (LinearMap.annihilator_le_of_surjective (R := R) _ (mkQ_surjective _)) (LinearMap.annihilator_le_of_injective _ (injective_subtype _))) (h3 r (h.subset List.mem_cons_self))) end Perm lemma IsRegular.of_perm_of_subset_jacobson_annihilator [IsNoetherian R M] {rs rs' : List R} (h1 : IsRegular M rs) (h2 : List.Perm rs rs') (h3 : ∀ r ∈ rs, r ∈ (Module.annihilator R M).jacobson) : IsRegular M rs' := ⟨h1.toIsWeaklyRegular.of_perm_of_subset_jacobson_annihilator h2 h3, letI := h1.nontrivial top_ne_ideal_smul_of_le_jacobson_annihilator <| Ideal.span_le.mpr (h3 · <| h2.mem_iff.mpr ·)⟩ lemma _root_.IsLocalRing.isWeaklyRegular_of_perm_of_subset_maximalIdeal [IsLocalRing R] [IsNoetherian R M] {rs rs' : List R} (h1 : IsWeaklyRegular M rs) (h2 : List.Perm rs rs') (h3 : ∀ r ∈ rs, r ∈ IsLocalRing.maximalIdeal R) : IsWeaklyRegular M rs' := IsWeaklyRegular.of_perm_of_subset_jacobson_annihilator h1 h2 fun r hr => IsLocalRing.maximalIdeal_le_jacobson _ (h3 r hr) lemma _root_.IsLocalRing.isRegular_of_perm [IsLocalRing R] [IsNoetherian R M] {rs rs' : List R} (h1 : IsRegular M rs) (h2 : List.Perm rs rs') : IsRegular M rs' := by obtain ⟨h3, h4⟩ := h1 refine ⟨IsLocalRing.isWeaklyRegular_of_perm_of_subset_maximalIdeal h3 h2 ?_, ?_⟩ · intro x (h6 : x ∈ { r | r ∈ rs }) refine IsLocalRing.le_maximalIdeal ?_ (Ideal.subset_span h6) exact h4 ∘ Eq.trans (top_smul _).symm ∘ Eq.symm ∘ congrArg (· • ⊤) · refine ne_of_ne_of_eq h4 (congrArg (Ideal.span · • ⊤) ?_) exact Set.ext fun _ => h2.mem_iff end RingTheory.Sequence
.lake/packages/mathlib/Mathlib/RingTheory/HopfAlgebra/GroupLike.lean
import Mathlib.RingTheory.HopfAlgebra.Basic import Mathlib.RingTheory.Bialgebra.GroupLike /-! # Group-like elements in a Hopf algebra This file proves that group-like elements in a Hopf algebra form a group. -/ open HopfAlgebra variable {R A : Type*} section Semiring variable [CommSemiring R] [Semiring A] [HopfAlgebra R A] {a b : A} @[simp] lemma IsGroupLikeElem.antipode_mul_cancel (ha : IsGroupLikeElem R a) : antipode R a * a = 1 := by simpa [ha, -mul_antipode_lTensor_comul_apply] using mul_antipode_rTensor_comul_apply (R := R) a @[simp] lemma IsGroupLikeElem.mul_antipode_cancel (ha : IsGroupLikeElem R a) : a * antipode R a = 1 := by simpa [ha, -mul_antipode_lTensor_comul_apply] using mul_antipode_lTensor_comul_apply (R := R) a variable (R) in /-- Turn a group-like element `a` into a unit with inverse its antipode. -/ @[simps] def GroupLike.toUnits : GroupLike R A →* Aˣ where toFun a := { val := a inv := antipode R a val_inv := a.2.mul_antipode_cancel inv_val := a.2.antipode_mul_cancel } map_one' := by ext; rfl map_mul' a b := by ext; rfl lemma IsGroupLikeElem.isUnit (ha : IsGroupLikeElem R a) : IsUnit a := (GroupLike.toUnits R ⟨a, ha⟩).isUnit @[simp] protected lemma IsGroupLikeElem.antipode (ha : IsGroupLikeElem R a) : IsGroupLikeElem R (antipode R a) := ha.of_mul_eq_one ha.mul_antipode_cancel ha.antipode_mul_cancel @[simp] lemma IsGroupLikeElem.antipode_antipode (ha : IsGroupLikeElem R a) : antipode R (antipode R a) = a := left_inv_eq_right_inv ha.antipode.antipode_mul_cancel ha.antipode_mul_cancel namespace GroupLike instance : Inv (GroupLike R A) where inv a := ⟨antipode R a, a.2.antipode⟩ @[simp] lemma val_inv (a : GroupLike R A) : ↑(a⁻¹) = (antipode R a : A) := rfl instance : Group (GroupLike R A) where inv_mul_cancel a := by ext; simp end GroupLike end Semiring variable [CommSemiring R] [CommSemiring A] [HopfAlgebra R A] {a b : A} instance GroupLike.instCommGroup : CommGroup (GroupLike R A) where __ := instCommMonoid __ := instGroup
.lake/packages/mathlib/Mathlib/RingTheory/HopfAlgebra/TensorProduct.lean
import Mathlib.RingTheory.HopfAlgebra.Basic import Mathlib.RingTheory.Bialgebra.TensorProduct /-! # Tensor products of Hopf algebras We define the Hopf algebra instance on the tensor product of two Hopf algebras. -/ open Coalgebra TensorProduct HopfAlgebra /-- Upgrade a bialgebra to a Hopf algebra by specifying the antipode as an algebra map with appropriate conditions. -/ noncomputable abbrev HopfAlgebra.ofAlgHom {R A : Type*} [CommSemiring R] [CommSemiring A] [Bialgebra R A] (antipode : A →ₐ[R] A) (mul_antipode_rTensor_comul : ((Algebra.TensorProduct.lift antipode (.id R A) fun _ ↦ .all _).comp (Bialgebra.comulAlgHom R A)) = (Algebra.ofId R A).comp (Bialgebra.counitAlgHom R A)) (mul_antipode_lTensor_comul : (Algebra.TensorProduct.lift (.id R A) antipode fun _ _ ↦ .all _ _).comp (Bialgebra.comulAlgHom R A) = (Algebra.ofId R A).comp (Bialgebra.counitAlgHom R A)) : HopfAlgebra R A where antipode := antipode mul_antipode_rTensor_comul := by rw [← Algebra.TensorProduct.lmul'_comp_map] at mul_antipode_rTensor_comul exact congr(($mul_antipode_rTensor_comul).toLinearMap) mul_antipode_lTensor_comul := by rw [← Algebra.TensorProduct.lmul'_comp_map] at mul_antipode_lTensor_comul exact congr(($mul_antipode_lTensor_comul).toLinearMap) namespace TensorProduct variable {R S A B : Type*} [CommSemiring R] [CommSemiring S] [Semiring A] [Semiring B] [Algebra R S] [HopfAlgebra R A] [HopfAlgebra S B] [Algebra R B] [IsScalarTower R S B] noncomputable instance : HopfAlgebra S (B ⊗[R] A) where antipode := AlgebraTensorModule.map (HopfAlgebra.antipode S) (HopfAlgebra.antipode R) mul_antipode_rTensor_comul := by ext x y convert congr($(mul_antipode_rTensor_comul_apply (R := S) x) ⊗ₜ[R] $(mul_antipode_rTensor_comul_apply (R := R) y)) using 1 · dsimp hopf_tensor_induction comul (R := S) x with x₁ x₂ hopf_tensor_induction comul (R := R) y with y₁ y₂ simp · dsimp [Algebra.TensorProduct.one_def] simp [Algebra.algebraMap_eq_smul_one, smul_tmul'] mul_antipode_lTensor_comul := by ext x y convert congr($(mul_antipode_lTensor_comul_apply (R := S) x) ⊗ₜ[R] $(mul_antipode_lTensor_comul_apply (R := R) y)) using 1 · dsimp [Algebra.TensorProduct.one_def] hopf_tensor_induction comul (R := S) x with x₁ x₂ hopf_tensor_induction comul (R := R) y with y₁ y₂ simp · dsimp [Algebra.TensorProduct.one_def] simp [Algebra.algebraMap_eq_smul_one, smul_tmul'] @[simp] theorem antipode_def : antipode S (A := B ⊗[R] A) = AlgebraTensorModule.map (antipode S) (antipode R) := rfl end TensorProduct
.lake/packages/mathlib/Mathlib/RingTheory/HopfAlgebra/Basic.lean
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. (Note that all three facts have been proved for Hopf bimonoids in an arbitrary braided category, so we could deduce the facts here from an equivalence `HopfAlgCat R ≌ Hopf (ModuleCat R)`.) ## References * <https://en.wikipedia.org/wiki/Hopf_algebra> * [C. Kassel, *Quantum Groups* (§III.3)][Kassel1995] -/ open Bialgebra universe u v w /-- Isolates the antipode of a Hopf algebra, to allow API to be constructed before proving the Hopf algebra axioms. See `HopfAlgebra` for documentation. -/ class HopfAlgebraStruct (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends Bialgebra R A where /-- The antipode of the Hopf algebra. -/ antipode (R) : A →ₗ[R] A /-- 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 HopfAlgebraStruct R A where /-- 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 export HopfAlgebraStruct (antipode) variable {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [HopfAlgebra R A] {a : A} @[simp] theorem mul_antipode_rTensor_comul_apply (a : A) : LinearMap.mul' R A ((antipode R).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 R).lTensor A (Coalgebra.comul a)) = algebraMap R A (Coalgebra.counit a) := LinearMap.congr_fun mul_antipode_lTensor_comul a @[simp] theorem antipode_one : HopfAlgebra.antipode R (1 : A) = 1 := by simpa [Algebra.TensorProduct.one_def] using mul_antipode_rTensor_comul_apply (R := R) (1 : A) open Coalgebra lemma sum_antipode_mul_eq_algebraMap_counit (repr : Repr R a) : ∑ i ∈ repr.index, antipode 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) @[deprecated (since := "2025-05-29")] alias sum_antipode_mul_eq := sum_antipode_mul_eq_algebraMap_counit lemma sum_mul_antipode_eq_algebraMap_counit (repr : Repr R a) : ∑ i ∈ repr.index, repr.left i * antipode R (repr.right i) = algebraMap R A (counit a) := by simpa [← repr.eq, map_sum] using congr($(mul_antipode_lTensor_comul (R := R)) a) @[deprecated (since := "2025-05-29")] alias sum_mul_antipode_eq := sum_mul_antipode_eq_algebraMap_counit lemma sum_antipode_mul_eq_smul (repr : Repr R a) : ∑ i ∈ repr.index, antipode R (repr.left i) * repr.right i = counit (R := R) a • 1 := by rw [sum_antipode_mul_eq_algebraMap_counit, Algebra.smul_def, mul_one] lemma sum_mul_antipode_eq_smul (repr : Repr R a) : ∑ i ∈ repr.index, repr.left i * antipode R (repr.right i) = counit (R := R) a • 1 := by rw [sum_mul_antipode_eq_algebraMap_counit, Algebra.smul_def, mul_one] @[simp] lemma counit_antipode (a : A) : counit (R := R) (antipode R a) = counit a := by calc counit (antipode R a) _ = counit (∑ i ∈ (ℛ R a).index, (ℛ R a).left i * antipode R ((ℛ R a).right i)) := by simp_rw [map_sum, counit_mul, ← smul_eq_mul, ← map_smul, ← map_sum, sum_counit_smul] _ = counit a := by simpa using congr(counit (R := R) $(sum_mul_antipode_eq_smul (ℛ R a))) @[simp] lemma counit_comp_antipode : counit ∘ₗ antipode R = counit (A := A) := by ext; exact counit_antipode _ 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 (A := R) = .id := rfl end CommSemiring
.lake/packages/mathlib/Mathlib/RingTheory/HopfAlgebra/MonoidAlgebra.lean
import Mathlib.RingTheory.Bialgebra.MonoidAlgebra import Mathlib.RingTheory.HopfAlgebra.Basic /-! # The Hopf algebra structure on group algebras Given a group `G`, a commutative semiring `R` and an `R`-Hopf algebra `A`, this file collects results about the `R`-Hopf algebra instance on `A[G]`, building upon results in `Mathlib/RingTheory/Bialgebra/MonoidAlgebra.lean` about the bialgebra structure. ## Main definitions * `(Add)MonoidAlgebra.instHopfAlgebra`: the `R`-Hopf algebra structure on `A[G]` when `G` is an (add) group and `A` is an `R`-Hopf algebra. * `LaurentPolynomial.instHopfAlgebra`: the `R`-Hopf algebra structure on the Laurent polynomials `A[T;T⁻¹]` when `A` is an `R`-Hopf algebra. When `A = R` this corresponds to the fact that `𝔾ₘ/R` is a group scheme. -/ noncomputable section open HopfAlgebra namespace MonoidAlgebra variable {R A : Type*} [CommSemiring R] [Semiring A] [HopfAlgebra R A] variable {G : Type*} [Group G] variable (R A G) in instance instHopfAlgebraStruct : HopfAlgebraStruct R (MonoidAlgebra A G) where antipode := Finsupp.lsum R fun g => Finsupp.lsingle g⁻¹ ∘ₗ antipode R @[simp] lemma antipode_single (g : G) (a : A) : antipode R (single g a) = single g⁻¹ (antipode R a) := by simp [MonoidAlgebra, antipode] open Coalgebra in instance instHopfAlgebra : HopfAlgebra R (MonoidAlgebra A G) where mul_antipode_rTensor_comul := by ext a b : 2 simpa [← (ℛ R b).eq] using congr(lsingle (R := R) (1 : G) $(sum_antipode_mul_eq_algebraMap_counit (ℛ R b))) mul_antipode_lTensor_comul := by ext a b : 2 simpa [← (ℛ R b).eq] using congr(lsingle (R := R) (1 : G) $(sum_mul_antipode_eq_algebraMap_counit (ℛ R b))) end MonoidAlgebra namespace AddMonoidAlgebra variable {R A : Type*} [CommSemiring R] [Semiring A] [HopfAlgebra R A] variable {G : Type*} [AddGroup G] variable (R A G) in instance instHopfAlgebraStruct : HopfAlgebraStruct R A[G] where antipode := Finsupp.lsum R fun g => Finsupp.lsingle (-g) ∘ₗ antipode R @[simp] lemma antipode_single (g : G) (a : A) : antipode R (single g a) = single (-g) (antipode R a) := by simp [AddMonoidAlgebra, antipode] open Coalgebra in instance instHopfAlgebra : HopfAlgebra R A[G] where mul_antipode_rTensor_comul := by ext a b : 2 simpa [← (ℛ R b).eq, single_mul_single] using congr(lsingle (R := R) (0 : G) $(sum_antipode_mul_eq_algebraMap_counit (ℛ R b))) mul_antipode_lTensor_comul := by ext a b : 2 simpa [← (ℛ R b).eq, single_mul_single] using congr(lsingle (R := R) (0 : G) $(sum_mul_antipode_eq_algebraMap_counit (ℛ R b))) end AddMonoidAlgebra namespace LaurentPolynomial open Finsupp variable (R A : Type*) [CommSemiring R] [Semiring A] [HopfAlgebra R A] instance instHopfAlgebra : HopfAlgebra R A[T;T⁻¹] := inferInstanceAs (HopfAlgebra R <| AddMonoidAlgebra A ℤ) variable {R A} @[simp] theorem antipode_C (a : A) : HopfAlgebra.antipode R (C a) = C (HopfAlgebra.antipode R a) := by rw [← single_eq_C, AddMonoidAlgebra.antipode_single] simp @[simp] theorem antipode_T (n : ℤ) : HopfAlgebra.antipode R (T n : A[T;T⁻¹]) = T (-n) := by unfold T rw [AddMonoidAlgebra.antipode_single] simp only [HopfAlgebra.antipode_one, single_eq_C_mul_T, map_one, one_mul] @[simp] theorem antipode_C_mul_T (a : A) (n : ℤ) : HopfAlgebra.antipode R (C a * T n) = C (HopfAlgebra.antipode R a) * T (-n) := by simp [← single_eq_C_mul_T] end LaurentPolynomial
.lake/packages/mathlib/Mathlib/RingTheory/Unramified/Finite.lean
import Mathlib.RingTheory.Ideal.IdempotentFG import Mathlib.RingTheory.Unramified.Basic import Mathlib.RingTheory.Flat.Stability /-! # Various results about unramified algebras We prove various theorems about unramified algebras. In fact we work in the more general setting of formally unramified algebras which are essentially of finite type. ## Main results - `Algebra.FormallyUnramified.iff_exists_tensorProduct`: A finite-type `R`-algebra `S` is (formally) unramified iff there exists a `t : S ⊗[R] S` satisfying 1. `t` annihilates every `1 ⊗ s - s ⊗ 1`. 2. the image of `t` is `1` under the map `S ⊗[R] S → S`. - `Algebra.FormallyUnramified.finite_of_free`: An unramified free algebra is finitely generated. - `Algebra.FormallyUnramified.flat_of_restrictScalars`: If `S` is an unramified `R`-algebra, then `R`-flat implies `S`-flat. ## References - [B. Iversen, *Generic Local Structure of the Morphisms in Commutative Algebra*][iversen] -/ open Algebra Module open scoped TensorProduct variable {R S : Type*} [CommRing R] [CommRing S] [Algebra R S] variable (M : Type*) [AddCommGroup M] [Module R M] [Module S M] [IsScalarTower R S M] namespace Algebra.FormallyUnramified /-- Proposition I.2.3 + I.2.6 of [iversen] A finite-type `R`-algebra `S` is (formally) unramified iff there exists a `t : S ⊗[R] S` satisfying 1. `t` annihilates every `1 ⊗ s - s ⊗ 1`. 2. the image of `t` is `1` under the map `S ⊗[R] S → S`. -/ theorem iff_exists_tensorProduct [EssFiniteType R S] : FormallyUnramified R S ↔ ∃ t : S ⊗[R] S, (∀ s, ((1 : S) ⊗ₜ[R] s - s ⊗ₜ[R] (1 : S)) * t = 0) ∧ TensorProduct.lmul' R t = 1 := by rw [formallyUnramified_iff, KaehlerDifferential, Ideal.cotangent_subsingleton_iff, Ideal.isIdempotentElem_iff_of_fg _ (KaehlerDifferential.ideal_fg R S)] have : ∀ t : S ⊗[R] S, TensorProduct.lmul' R t = 1 ↔ 1 - t ∈ KaehlerDifferential.ideal R S := by intro t simp only [KaehlerDifferential.ideal, RingHom.mem_ker, map_sub, map_one, sub_eq_zero, @eq_comm S 1] simp_rw [this, ← KaehlerDifferential.span_range_eq_ideal] constructor · rintro ⟨e, he₁, he₂ : _ = Ideal.span _⟩ refine ⟨1 - e, ?_, ?_⟩ · intro s obtain ⟨x, hx⟩ : e ∣ 1 ⊗ₜ[R] s - s ⊗ₜ[R] 1 := by rw [← Ideal.mem_span_singleton, ← he₂] exact Ideal.subset_span ⟨s, rfl⟩ rw [hx, mul_comm, ← mul_assoc, sub_mul, one_mul, he₁.eq, sub_self, zero_mul] · rw [sub_sub_cancel, he₂, Ideal.mem_span_singleton] · rintro ⟨t, ht₁, ht₂⟩ use 1 - t rw [← sub_sub_self 1 t] at ht₁; generalize 1 - t = e at * constructor · suffices e ∈ (Submodule.span (S ⊗[R] S) {1 - e}).annihilator by simpa [IsIdempotentElem, mul_sub, sub_eq_zero, eq_comm, -Ideal.submodule_span_eq, Submodule.mem_annihilator_span_singleton] using this exact (show Ideal.span _ ≤ _ by simpa only [Ideal.span_le, Set.range_subset_iff, Submodule.mem_annihilator_span_singleton, SetLike.mem_coe]) ht₂ · apply le_antisymm <;> simp only [Ideal.submodule_span_eq, Ideal.mem_span_singleton, ht₂, Ideal.span_le, Set.singleton_subset_iff, SetLike.mem_coe, Set.range_subset_iff] intro s use 1 ⊗ₜ[R] s - s ⊗ₜ[R] 1 linear_combination ht₁ s lemma finite_of_free_aux (I) [DecidableEq I] (b : Basis I R S) (f : I →₀ S) (x : S) (a : I → I →₀ R) (ha : a = fun i ↦ b.repr (b i * x)) : (1 ⊗ₜ[R] x * Finsupp.sum f fun i y ↦ y ⊗ₜ[R] b i) = Finset.sum (f.support.biUnion fun i ↦ (a i).support) fun k ↦ Finsupp.sum (b.repr (f.sum fun i y ↦ a i k • y)) fun j c ↦ c • b j ⊗ₜ[R] b k := by rw [Finsupp.sum, Finset.mul_sum] subst ha let a i := b.repr (b i * x) conv_lhs => simp only [TensorProduct.tmul_mul_tmul, one_mul, mul_comm x (b _), ← show ∀ i, Finsupp.linearCombination _ b (a i) = b i * x from fun _ ↦ b.linearCombination_repr _] conv_lhs => simp only [Finsupp.linearCombination, Finsupp.coe_lsum, LinearMap.coe_smulRight, LinearMap.id_coe, id_eq, Finsupp.sum, TensorProduct.tmul_sum, ← TensorProduct.smul_tmul] have h₁ : ∀ k, (Finsupp.sum (Finsupp.sum f fun i y ↦ a i k • b.repr y) fun j z ↦ z • b j ⊗ₜ[R] b k) = (f.sum fun i y ↦ (b.repr y).sum fun j z ↦ a i k • z • b j ⊗ₜ[R] b k) := by intro i rw [Finsupp.sum_sum_index] · congr ext j s rw [Finsupp.sum_smul_index] · simp only [mul_smul, Finsupp.sum, ← Finset.smul_sum] intro; simp only [zero_smul] · intro; simp only [zero_smul] · intros; simp only [add_smul] have h₂ : ∀ (x : S), ((b.repr x).support.sum fun a ↦ b.repr x a • b a) = x := by simpa only [Finsupp.linearCombination_apply, Finsupp.sum] using b.linearCombination_repr simp only [a] at h₁ simp_rw [map_finsuppSum, map_smul, h₁, Finsupp.sum, Finset.sum_comm (t := f.support), TensorProduct.smul_tmul', ← TensorProduct.sum_tmul, ← Finset.smul_sum, h₂] apply Finset.sum_congr rfl intro i hi apply Finset.sum_subset_zero_on_sdiff · exact Finset.subset_biUnion_of_mem (fun i ↦ (a i).support) hi · simp only [a, Finset.mem_sdiff, Finset.mem_biUnion, Finsupp.mem_support_iff, ne_eq, not_not, and_imp, forall_exists_index] simp +contextual · exact fun _ _ ↦ rfl variable [FormallyUnramified R S] [EssFiniteType R S] variable (R S) in /-- A finite-type `R`-algebra `S` is (formally) unramified iff there exists a `t : S ⊗[R] S` satisfying 1. `t` annihilates every `1 ⊗ s - s ⊗ 1`. 2. the image of `t` is `1` under the map `S ⊗[R] S → S`. See `Algebra.FormallyUnramified.iff_exists_tensorProduct`. This is the choice of such a `t`. -/ noncomputable def elem : S ⊗[R] S := (iff_exists_tensorProduct.mp inferInstance).choose lemma one_tmul_sub_tmul_one_mul_elem (s : S) : (1 ⊗ₜ s - s ⊗ₜ 1) * elem R S = 0 := (iff_exists_tensorProduct.mp inferInstance).choose_spec.1 s lemma one_tmul_mul_elem (s : S) : (1 ⊗ₜ s) * elem R S = (s ⊗ₜ 1) * elem R S := by rw [← sub_eq_zero, ← sub_mul, one_tmul_sub_tmul_one_mul_elem] lemma lmul_elem : TensorProduct.lmul' R (elem R S) = 1 := (iff_exists_tensorProduct.mp inferInstance).choose_spec.2 variable (R S) /-- An unramified free algebra is finitely generated. Iversen I.2.8 -/ lemma finite_of_free [Module.Free R S] : Module.Finite R S := by classical let I := Module.Free.ChooseBasisIndex R S -- Let `bᵢ` be an `R`-basis of `S`. let b : Basis I R S := Module.Free.chooseBasis R S -- Let `∑ₛ fᵢ ⊗ bᵢ : S ⊗[R] S` (summing over some finite `s`) be an element such that -- `∑ₛ fᵢbᵢ = 1` and `∀ x : S, xfᵢ ⊗ bᵢ = aᵢ ⊗ xfᵢ` which exists since `S` is unramified over `R`. have ⟨f, hf⟩ : ∃ (a : I →₀ S), elem R S = a.sum (fun i x ↦ x ⊗ₜ b i) := by let b' := ((Basis.singleton PUnit.{1} S).tensorProduct b).reindex (Equiv.punitProd I) use b'.repr (elem R S) conv_lhs => rw [← b'.linearCombination_repr (elem R S), Finsupp.linearCombination_apply] congr! with _ i x simp [b', Basis.tensorProduct, TensorProduct.smul_tmul'] constructor -- I claim that `{ fᵢbⱼ | i, j ∈ s }` spans `S` over `R`. use Finset.image₂ (fun i j ↦ f i * b j) f.support f.support rw [← top_le_iff] -- For all `x : S`, let `bᵢx = ∑ aᵢⱼbⱼ`. rintro x - let a : I → I →₀ R := fun i ↦ b.repr (b i * x) -- Consider `F` such that `fⱼx = ∑ Fᵢⱼbⱼ`. let F : I →₀ I →₀ R := Finsupp.onFinset f.support (fun j ↦ b.repr (x * f j)) (fun j ↦ not_imp_comm.mp fun hj ↦ by simp [Finsupp.notMem_support_iff.mp hj]) have hG : ∀ j ∉ (Finset.biUnion f.support fun i ↦ (a i).support), b.repr (f.sum (fun i y ↦ a i j • y)) = 0 := by intro j hj simp only [Finset.mem_biUnion, Finsupp.mem_support_iff, ne_eq, not_exists, not_and, not_not] at hj simp only [Finsupp.sum] trans b.repr (f.support.sum (fun _ ↦ 0)) · refine congr_arg b.repr (Finset.sum_congr rfl ?_) simp only [Finsupp.mem_support_iff] intro i hi rw [hj i hi, zero_smul] · simp only [Finset.sum_const_zero, map_zero] -- And `G` such that `∑ₛ aᵢⱼfᵢ = ∑ Gᵢⱼbⱼ`, where `aᵢⱼ` are the coefficients `bᵢx = ∑ aᵢⱼbⱼ`. let G : I →₀ I →₀ R := Finsupp.onFinset (Finset.biUnion f.support (fun i ↦ (a i).support)) (fun j ↦ b.repr (f.sum (fun i y ↦ a i j • y))) (fun j ↦ not_imp_comm.mp (hG j)) -- Then `∑ Fᵢⱼ(bⱼ ⊗ bᵢ) = ∑ fⱼx ⊗ bᵢ = ∑ fⱼ ⊗ xbᵢ = ∑ aᵢⱼ(fⱼ ⊗ bᵢ) = ∑ Gᵢⱼ(bⱼ ⊗ bᵢ)`. -- Since `bⱼ ⊗ bᵢ` forms an `R`-basis of `S ⊗ S`, we conclude that `F = G`. have : F = G := by apply Finsupp.finsuppProdEquiv.symm.injective apply (Finsupp.equivCongrLeft (Equiv.prodComm I I)).injective apply (b.tensorProduct b).repr.symm.injective suffices (F.sum fun a f ↦ f.sum fun b' c ↦ c • b b' ⊗ₜ[R] b a) = G.sum fun a f ↦ f.sum fun b' c ↦ c • b b' ⊗ₜ[R] b a by simpa [Finsupp.linearCombination_apply, Finsupp.sum_uncurry_index] have : ∀ i, ((b.repr (x * f i)).sum fun j k ↦ k • b j ⊗ₜ[R] b i) = (x * f i) ⊗ₜ[R] b i := by intro i simp_rw [Finsupp.sum, TensorProduct.smul_tmul', ← TensorProduct.sum_tmul] congr 1 exact b.linearCombination_repr _ rw [Finsupp.onFinset_sum, Finsupp.onFinset_sum] · trans (x ⊗ₜ 1) * elem R S · simp_rw [this, hf, Finsupp.sum, Finset.mul_sum, TensorProduct.tmul_mul_tmul, one_mul] · rw [← one_tmul_mul_elem, hf, finite_of_free_aux] rfl · intro; simp · intro; simp -- In particular, `fⱼx = ∑ Fᵢⱼbⱼ = ∑ Gᵢⱼbⱼ = ∑ₛ aᵢⱼfᵢ` for all `j`. have : ∀ j, x * f j = f.sum fun i y ↦ a i j • y := by intro j apply b.repr.injective exact DFunLike.congr_fun this j -- Since `∑ₛ fⱼbⱼ = 1`, `x = ∑ₛ aᵢⱼfᵢbⱼ` is indeed in the span of `{ fᵢbⱼ | i, j ∈ s }`. rw [← mul_one x, ← @lmul_elem R, hf, map_finsuppSum, Finsupp.sum, Finset.mul_sum] simp only [TensorProduct.lmul'_apply_tmul, Finset.coe_image₂, ← mul_assoc, this, Finsupp.sum, Finset.sum_mul, smul_mul_assoc] apply Submodule.sum_mem; intro i hi apply Submodule.sum_mem; intro j hj apply Submodule.smul_mem apply Submodule.subset_span use j, hj, i, hi /-- Proposition I.2.3 of [iversen] If `S` is an unramified `R`-algebra, and `M` is a `S`-module, then the map `S ⊗[R] M →ₗ[S] M` taking `(b, m) ↦ b • m` admits a `S`-linear section. -/ noncomputable def sec : M →ₗ[S] S ⊗[R] M where __ := ((TensorProduct.AlgebraTensorModule.mapBilinear R S S S S S M LinearMap.id).flip (elem R S)).comp (lsmul R R M).toLinearMap.flip map_smul' r m := by simp only [AddHom.toFun_eq_coe, LinearMap.coe_toAddHom, LinearMap.coe_comp, Function.comp_apply, LinearMap.flip_apply, TensorProduct.AlgebraTensorModule.mapBilinear_apply, RingHom.id_apply] trans (TensorProduct.AlgebraTensorModule.map (LinearMap.id (R := S) (M := S)) ((LinearMap.flip (AlgHom.toLinearMap (lsmul R R M))) m)) ((1 ⊗ₜ r) * elem R S) · induction elem R S using TensorProduct.induction_on · simp · simp [smul_comm r] · simp only [map_add, mul_add, *] · have := one_tmul_sub_tmul_one_mul_elem (R := R) r rw [sub_mul, sub_eq_zero] at this rw [this] induction elem R S using TensorProduct.induction_on · simp · simp [TensorProduct.smul_tmul'] · simp only [map_add, smul_add, mul_add, *] lemma comp_sec : (TensorProduct.AlgebraTensorModule.lift ((lsmul S S M).toLinearMap.flip.restrictScalars R).flip).comp (sec R S M) = LinearMap.id := by ext x simp only [sec, LinearMap.coe_comp, LinearMap.coe_mk, LinearMap.coe_toAddHom, Function.comp_apply, LinearMap.flip_apply, TensorProduct.AlgebraTensorModule.mapBilinear_apply, TensorProduct.AlgebraTensorModule.lift_apply, LinearMap.id_coe, id_eq] trans (TensorProduct.lmul' R (elem R S)) • x · induction elem R S using TensorProduct.induction_on with | zero => simp | tmul r s => simp [mul_smul, smul_comm r s] | add y z hy hz => simp [hy, hz, add_smul] · rw [lmul_elem, one_smul] /-- If `S` is an unramified `R`-algebra, then `R`-flat implies `S`-flat. Iversen I.2.7 -/ lemma flat_of_restrictScalars [Module.Flat R M] : Module.Flat S M := Module.Flat.of_retract _ _ (comp_sec R S M) /-- If `S` is an unramified `R`-algebra, then `R`-projective implies `S`-projective. -/ lemma projective_of_restrictScalars [Module.Projective R M] : Module.Projective S M := Module.Projective.of_split _ _ (comp_sec R S M) end Algebra.FormallyUnramified
.lake/packages/mathlib/Mathlib/RingTheory/Unramified/LocalRing.lean
import Mathlib.RingTheory.LocalRing.Module import Mathlib.RingTheory.LocalRing.ResidueField.Ideal import Mathlib.RingTheory.Unramified.Field import Mathlib.RingTheory.Unramified.Locus /-! # Unramified algebras over local rings ## Main results - `Algebra.FormallyUnramified.iff_map_maximalIdeal_eq`: Let `R` be a local ring, `A` be a local `R`-algebra essentially of finite type. Then `A/R` is unramified if and only if `κA/κR` is separable, and `m_R S = m_S`. - `Algebra.isUnramifiedAt_iff_map_eq`: Let `A` be an essentially of finite type `R`-algebra, `q` be a prime over `p`. Then `A` is unramified at `p` if and only if `κ(q)/κ(p)` is separable, and `pS_q = qS_q`. -/ open IsLocalRing namespace Algebra section IsLocalRing variable {R S : Type*} [CommRing R] [CommRing S] [Algebra R S] variable [IsLocalRing R] [IsLocalRing S] [IsLocalHom (algebraMap R S)] instance : FormallyUnramified S (ResidueField S) := .quotient _ instance [FormallyUnramified R S] : FormallyUnramified (ResidueField R) (ResidueField S) := have : FormallyUnramified R (ResidueField S) := .comp _ S _ .of_comp R _ _ variable [EssFiniteType R S] @[stacks 00UW "(2)"] instance [FormallyUnramified R S] : Module.Finite (ResidueField R) (ResidueField S) := have : EssFiniteType R (ResidueField S) := .comp _ S _ have : EssFiniteType (ResidueField R) (ResidueField S) := .of_comp R _ _ FormallyUnramified.finite_of_free _ _ @[stacks 00UW "(2)"] instance [FormallyUnramified R S] : Algebra.IsSeparable (ResidueField R) (ResidueField S) := FormallyUnramified.isSeparable _ _ lemma FormallyUnramified.isField_quotient_map_maximalIdeal [FormallyUnramified R S] : IsField (S ⧸ (maximalIdeal R).map (algebraMap R S)) := by let mR := (maximalIdeal R).map (algebraMap R S) have hmR : mR ≤ maximalIdeal S := ((local_hom_TFAE (algebraMap R S)).out 0 2 rfl rfl).mp ‹_› letI : Algebra (ResidueField R) (S ⧸ mR) := inferInstanceAs (Algebra (R ⧸ _) _) have : IsScalarTower R (ResidueField R) (S ⧸ mR) := inferInstanceAs (IsScalarTower R (R ⧸ _) _) have : FormallyUnramified (ResidueField R) (S ⧸ mR) := .of_comp R _ _ have : EssFiniteType (ResidueField R) (S ⧸ mR) := .of_comp R _ _ have : Module.Finite (ResidueField R) (S ⧸ mR) := FormallyUnramified.finite_of_free _ _ have : IsReduced (S ⧸ mR) := FormallyUnramified.isReduced_of_field (ResidueField R) (S ⧸ mR) have : IsArtinianRing (S ⧸ mR) := isArtinian_of_tower (ResidueField R) inferInstance have : Nontrivial (S ⧸ mR) := Ideal.Quotient.nontrivial fun e ↦ (maximalIdeal.isMaximal S).ne_top (top_le_iff.mp <| e.symm.trans_le hmR) have : IsLocalRing (S ⧸ mR) := .of_surjective' _ Ideal.Quotient.mk_surjective have : maximalIdeal (S ⧸ mR) = ⊥ := by rw [← jacobson_eq_maximalIdeal _ bot_ne_top, IsArtinianRing.jacobson_eq_radical, ← Ideal.zero_eq_bot, ← nilradical, nilradical_eq_zero] rwa [← isField_iff_maximalIdeal_eq] at this @[stacks 00UW "(1)"] lemma FormallyUnramified.map_maximalIdeal [FormallyUnramified R S] : (maximalIdeal R).map (algebraMap R S) = maximalIdeal S := by apply eq_maximalIdeal rw [Ideal.Quotient.maximal_ideal_iff_isField_quotient] exact isField_quotient_map_maximalIdeal @[stacks 02FM] lemma FormallyUnramified.of_map_maximalIdeal [Algebra.IsSeparable (ResidueField R) (ResidueField S)] (H : (maximalIdeal R).map (algebraMap R S) = maximalIdeal S) : Algebra.FormallyUnramified R S := by constructor have : FormallyUnramified (ResidueField R) (ResidueField S) := .of_isSeparable _ _ have : FormallyUnramified R (ResidueField S) := .comp _ (ResidueField R) _ rw [← subsingleton_tensorProduct (R := S)] refine subsingleton_of_forall_eq 0 fun x ↦ ?_ obtain ⟨x, rfl⟩ := (KaehlerDifferential.exact_kerCotangentToTensor_mapBaseChange R S (ResidueField S) Ideal.Quotient.mk_surjective x).mp (Subsingleton.elim _ _) obtain ⟨⟨x, hx⟩, rfl⟩ := Ideal.toCotangent_surjective _ x simp only [KaehlerDifferential.kerCotangentToTensor_toCotangent] replace hx : x ∈ Ideal.map (algebraMap R S) (maximalIdeal R) := by simpa [H] using hx induction hx using Submodule.span_induction with | zero => simp | mem x h => obtain ⟨x, hx, rfl⟩ := h; simp | add x y hx hy _ _ => simp [*, TensorProduct.tmul_add] | smul a x hx _ => have : residue S x = 0 := by rwa [residue_eq_zero_iff, ← H] simp [*, TensorProduct.tmul_add, TensorProduct.smul_tmul', ← Algebra.algebraMap_eq_smul_one] lemma FormallyUnramified.iff_map_maximalIdeal_eq : Algebra.FormallyUnramified R S ↔ Algebra.IsSeparable (ResidueField R) (ResidueField S) ∧ (maximalIdeal R).map (algebraMap R S) = maximalIdeal S := ⟨fun _ ↦ ⟨inferInstance, map_maximalIdeal⟩, fun ⟨_, e⟩ ↦ of_map_maximalIdeal e⟩ end IsLocalRing section IsUnramifiedAt variable (R : Type*) {S : Type*} [CommRing R] [CommRing S] [Algebra R S] noncomputable instance (p : Ideal R) [p.IsPrime] (q : Ideal S) [q.IsPrime] [q.LiesOver p] : Algebra p.ResidueField q.ResidueField := (Ideal.ResidueField.mapₐ p q Ideal.LiesOver.over).toAlgebra /-- Let `A` be an essentially of finite type `R`-algebra, `q` be a prime over `p`. Then `A` is unramified at `p` if and only if `κ(q)/κ(p)` is separable, and `pS_q = qS_q`. -/ lemma isUnramifiedAt_iff_map_eq [EssFiniteType R S] (p : Ideal R) [p.IsPrime] (q : Ideal S) [q.IsPrime] [q.LiesOver p] : Algebra.IsUnramifiedAt R q ↔ Algebra.IsSeparable p.ResidueField q.ResidueField ∧ p.map (algebraMap R (Localization.AtPrime q)) = maximalIdeal _ := by letI : Algebra (Localization.AtPrime p) (Localization.AtPrime q) := (Localization.localRingHom p q (algebraMap R S) Ideal.LiesOver.over).toAlgebra have : IsScalarTower R (Localization.AtPrime p) (Localization.AtPrime q) := .of_algebraMap_eq fun x ↦ (Localization.localRingHom_to_map p q (algebraMap R S) Ideal.LiesOver.over x).symm letI : IsLocalHom (algebraMap (Localization.AtPrime p) (Localization.AtPrime q)) := Localization.isLocalHom_localRingHom _ _ _ Ideal.LiesOver.over have : EssFiniteType (Localization.AtPrime p) (Localization.AtPrime q) := .of_comp R _ _ trans Algebra.FormallyUnramified (Localization.AtPrime p) (Localization.AtPrime q) · exact ⟨fun _ ↦ .of_comp R _ _, fun _ ↦ Algebra.FormallyUnramified.comp _ (Localization.AtPrime p) _⟩ rw [FormallyUnramified.iff_map_maximalIdeal_eq] congr! rw [RingHom.algebraMap_toAlgebra, ← Localization.AtPrime.map_eq_maximalIdeal, Ideal.map_map, Localization.localRingHom, IsLocalization.map_comp, ← IsScalarTower.algebraMap_eq] end IsUnramifiedAt end Algebra
.lake/packages/mathlib/Mathlib/RingTheory/Unramified/Pi.lean
import Mathlib.RingTheory.Unramified.Basic /-! # Formal-unramification of finite products of rings ## Main result - `Algebra.FormallyUnramified.pi_iff`: If `I` is finite, `Π i : I, A i` is `R`-formally-smooth if and only if each `A i` is `R`-formally-smooth. -/ namespace Algebra.FormallyUnramified variable {R : Type*} {I : Type*} [Finite I] (f : I → Type*) variable [CommRing R] [∀ i, CommRing (f i)] [∀ i, Algebra R (f i)] theorem pi_iff : FormallyUnramified R (∀ i, f i) ↔ ∀ i, FormallyUnramified R (f i) := by classical cases nonempty_fintype I constructor · intro _ i exact FormallyUnramified.of_surjective (Pi.evalAlgHom R f i) (Function.surjective_eval i) · intro H rw [iff_comp_injective] intro B _ _ J hJ f₁ f₂ e ext g rw [← Finset.univ_sum_single g, map_sum, map_sum] refine Finset.sum_congr rfl ?_ rintro x - have hf : ∀ x, f₁ x - f₂ x ∈ J := by intro g rw [← Ideal.Quotient.eq_zero_iff_mem, map_sub, sub_eq_zero] exact AlgHom.congr_fun e g let e : ∀ i, f i := Pi.single x 1 have he : IsIdempotentElem e := by simp [IsIdempotentElem, e, ← Pi.single_mul] have h₁ : (f₁ e) * (1 - f₂ e) = 0 := by rw [← Ideal.mem_bot, ← hJ, ← ((he.map f₁).mul (he.map f₂).one_sub).eq, ← pow_two] apply Ideal.pow_mem_pow convert Ideal.mul_mem_left _ (f₁ e) (hf e) using 1 rw [mul_sub, mul_sub, mul_one, (he.map f₁).eq] have h₂ : (f₂ e) * (1 - f₁ e) = 0 := by rw [← Ideal.mem_bot, ← hJ, ← ((he.map f₂).mul (he.map f₁).one_sub).eq, ← pow_two] apply Ideal.pow_mem_pow convert Ideal.mul_mem_left _ (-f₂ e) (hf e) using 1 rw [neg_mul, mul_sub, mul_sub, mul_one, neg_sub, (he.map f₂).eq] have H : f₁ e = f₂ e := by trans f₁ e * f₂ e · rw [← sub_eq_zero, ← h₁, mul_sub, mul_one] · rw [eq_comm, ← sub_eq_zero, ← h₂, mul_sub, mul_one, mul_comm] let J' := Ideal.span {1 - f₁ e} let f₁' : f x →ₐ[R] B ⧸ J' := by apply AlgHom.ofLinearMap (((Ideal.Quotient.mkₐ R J').comp f₁).toLinearMap.comp (LinearMap.single _ _ x)) · simp only [AlgHom.comp_toLinearMap, LinearMap.coe_comp, LinearMap.coe_single, Function.comp_apply, AlgHom.toLinearMap_apply, Ideal.Quotient.mkₐ_eq_mk] rw [eq_comm, ← sub_eq_zero, ← (Ideal.Quotient.mk J').map_one, ← map_sub, Ideal.Quotient.eq_zero_iff_mem, Ideal.mem_span_singleton] · intro r s; simp [Pi.single_mul] let f₂' : f x →ₐ[R] B ⧸ J' := by apply AlgHom.ofLinearMap (((Ideal.Quotient.mkₐ R J').comp f₂).toLinearMap.comp (LinearMap.single _ _ x)) · simp only [AlgHom.comp_toLinearMap, LinearMap.coe_comp, LinearMap.coe_single, Function.comp_apply, AlgHom.toLinearMap_apply, Ideal.Quotient.mkₐ_eq_mk] rw [eq_comm, ← sub_eq_zero, ← (Ideal.Quotient.mk J').map_one, ← map_sub, Ideal.Quotient.eq_zero_iff_mem, Ideal.mem_span_singleton, H] · intro r s; simp [Pi.single_mul] suffices f₁' = f₂' by have := AlgHom.congr_fun this (g x) simp only [AlgHom.comp_toLinearMap, AlgHom.ofLinearMap_apply, LinearMap.coe_comp, LinearMap.coe_single, Function.comp_apply, AlgHom.toLinearMap_apply, ← map_sub, Ideal.Quotient.mkₐ_eq_mk, ← sub_eq_zero (b := Ideal.Quotient.mk J' _), f₁', f₂', Ideal.Quotient.eq_zero_iff_mem, Ideal.mem_span_singleton, J'] at this obtain ⟨c, hc⟩ := this apply_fun (f₁ e * ·) at hc rwa [← mul_assoc, mul_sub, mul_sub, mul_one, (he.map f₁).eq, sub_self, zero_mul, ← map_mul, H, ← map_mul, ← Pi.single_mul, one_mul, sub_eq_zero] at hc apply FormallyUnramified.comp_injective (I := J.map (algebraMap _ _)) · rw [← Ideal.map_pow, hJ, Ideal.map_bot] · ext r rw [← sub_eq_zero] simp only [Ideal.Quotient.algebraMap_eq, AlgHom.coe_comp, Ideal.Quotient.mkₐ_eq_mk, Function.comp_apply, ← map_sub, Ideal.Quotient.eq_zero_iff_mem, f₁', f₂', AlgHom.comp_toLinearMap, AlgHom.ofLinearMap_apply, LinearMap.coe_comp, LinearMap.coe_single, Function.comp_apply, AlgHom.toLinearMap_apply, Ideal.Quotient.mkₐ_eq_mk] exact Ideal.mem_map_of_mem (Ideal.Quotient.mk J') (hf (Pi.single x r)) instance [∀ i, FormallyUnramified R (f i)] : FormallyUnramified R (Π i, f i) := (pi_iff _).mpr ‹_› end Algebra.FormallyUnramified
.lake/packages/mathlib/Mathlib/RingTheory/Unramified/Basic.lean
import Mathlib.RingTheory.FiniteStability import Mathlib.RingTheory.Ideal.Quotient.Nilpotent import Mathlib.RingTheory.Kaehler.Basic import Mathlib.RingTheory.Localization.Away.AdjoinRoot import Mathlib.Algebra.Algebra.Shrink /-! # Unramified morphisms An `R`-algebra `A` is formally unramified if `Ω[A⁄R]` is trivial. This is equivalent to the standard definition "for every `R`-algebra, every square-zero ideal `I : Ideal B` and `f : A →ₐ[R] B ⧸ I`, there exists at most one lift `A →ₐ[R] B`". It is unramified if it is formally unramified and of finite type. Note that there are multiple definitions in the literature. The definition we give is equivalent to the one in the Stacks Project https://stacks.math.columbia.edu/tag/00US. Note that in EGA unramified is defined as formally unramified and of finite presentation. We show that the property extends onto nilpotent ideals, and that it is stable under `R`-algebra homomorphisms and compositions. We show that unramified is stable under algebra isomorphisms, composition and localization at an element. -/ open scoped TensorProduct universe w u v namespace Algebra section variable (R : Type v) (A : Type u) [CommRing R] [CommRing A] [Algebra R A] /-- An `R`-algebra `A` is formally unramified if `Ω[A⁄R]` is trivial. This is equivalent to "for every `R`-algebra, every square-zero ideal `I : Ideal B` and `f : A →ₐ[R] B ⧸ I`, there exists at most one lift `A →ₐ[R] B`". See `Algebra.FormallyUnramified.iff_comp_injective`. -/ @[mk_iff, stacks 00UM] class FormallyUnramified : Prop where subsingleton_kaehlerDifferential : Subsingleton Ω[A⁄R] attribute [instance] FormallyUnramified.subsingleton_kaehlerDifferential end namespace FormallyUnramified section variable {R : Type v} [CommRing R] variable {A : Type u} [CommRing A] [Algebra R A] variable {B : Type w} [CommRing B] [Algebra R B] (I : Ideal B) theorem comp_injective [FormallyUnramified R A] (hI : I ^ 2 = ⊥) : Function.Injective ((Ideal.Quotient.mkₐ R I).comp : (A →ₐ[R] B) → A →ₐ[R] B ⧸ I) := by intro f₁ f₂ e letI := f₁.toRingHom.toAlgebra haveI := IsScalarTower.of_algebraMap_eq' f₁.comp_algebraMap.symm have := ((KaehlerDifferential.linearMapEquivDerivation R A).toEquiv.trans (derivationToSquareZeroEquivLift I hI)).surjective.subsingleton exact Subtype.ext_iff.mp (@Subsingleton.elim _ this ⟨f₁, rfl⟩ ⟨f₂, e.symm⟩) theorem iff_comp_injective_of_small [Small.{w} A] : FormallyUnramified R A ↔ ∀ ⦃B : Type w⦄ [CommRing B], ∀ [Algebra R B] (I : Ideal B) (_ : I ^ 2 = ⊥), Function.Injective ((Ideal.Quotient.mkₐ R I).comp : (A →ₐ[R] B) → A →ₐ[R] B ⧸ I) := by constructor · intros; exact comp_injective _ ‹_› · intro H replace H : ∀ ⦃B : Type u⦄ [CommRing B] [Small.{w} B], ∀ [Algebra R B] (I : Ideal B) (_ : I ^ 2 = ⊥), Function.Injective ((Ideal.Quotient.mkₐ R I).comp : (A →ₐ[R] B) → A →ₐ[R] B ⧸ I) := by intro B _ _ _ I hI f g e simpa [DFunLike.ext_iff] using H (B := Shrink B) (I.comap (Shrink.ringEquiv _)) (by rw [← Ideal.map_symm, ← Ideal.map_pow, hI]; simp) (a₁ := (Shrink.algEquiv _ _).symm.toAlgHom.comp f) (a₂ := (Shrink.algEquiv _ _).symm.toAlgHom.comp g) (by simpa [DFunLike.ext_iff, Ideal.Quotient.mk_eq_mk_iff_sub_mem, Shrink.ringEquiv] using e) constructor by_contra! h obtain ⟨f₁, f₂, e⟩ := (KaehlerDifferential.endEquiv R A).injective.nontrivial apply e ext1 let f := RingHom.ker (TensorProduct.lmul' R (S := A)).kerSquareLift.toRingHom refine H (RingHom.ker (TensorProduct.lmul' R (S := A)).kerSquareLift.toRingHom) ?_ ?_ · rw [AlgHom.ker_kerSquareLift] exact Ideal.cotangentIdeal_square _ · ext x apply RingHom.kerLift_injective (TensorProduct.lmul' R (S := A)).kerSquareLift.toRingHom simpa using DFunLike.congr_fun (f₁.2.trans f₂.2.symm) x /-- A version without stray universes that is more easy to rewrite with. -/ theorem iff_comp_injective : FormallyUnramified R A ↔ ∀ ⦃B : Type u⦄ [CommRing B], ∀ [Algebra R B] (I : Ideal B) (_ : I ^ 2 = ⊥), Function.Injective ((Ideal.Quotient.mkₐ R I).comp : (A →ₐ[R] B) → A →ₐ[R] B ⧸ I) := iff_comp_injective_of_small theorem lift_unique [FormallyUnramified R A] (I : Ideal B) (hI : IsNilpotent I) (g₁ g₂ : A →ₐ[R] B) (h : (Ideal.Quotient.mkₐ R I).comp g₁ = (Ideal.Quotient.mkₐ R I).comp g₂) : g₁ = g₂ := by revert g₁ g₂ change Function.Injective (Ideal.Quotient.mkₐ R I).comp revert ‹Algebra R B› apply Ideal.IsNilpotent.induction_on (S := B) I hI · intro B _ I hI _; exact FormallyUnramified.comp_injective I hI · intro B _ I J hIJ h₁ h₂ _ g₁ g₂ e apply h₁ apply h₂ ext x replace e := AlgHom.congr_fun e x dsimp only [AlgHom.comp_apply, Ideal.Quotient.mkₐ_eq_mk] at e ⊢ rwa [Ideal.Quotient.eq, ← map_sub, Ideal.mem_quotient_iff_mem hIJ, ← Ideal.Quotient.eq] theorem ext [FormallyUnramified R A] (hI : IsNilpotent I) {g₁ g₂ : A →ₐ[R] B} (H : ∀ x, Ideal.Quotient.mk I (g₁ x) = Ideal.Quotient.mk I (g₂ x)) : g₁ = g₂ := FormallyUnramified.lift_unique I hI g₁ g₂ (AlgHom.ext H) theorem lift_unique_of_ringHom [FormallyUnramified R A] {C : Type*} [Ring C] (f : B →+* C) (hf : IsNilpotent <| RingHom.ker f) (g₁ g₂ : A →ₐ[R] B) (h : f.comp ↑g₁ = f.comp (g₂ : A →+* B)) : g₁ = g₂ := FormallyUnramified.lift_unique _ hf _ _ (by ext x have := RingHom.congr_fun h x simpa only [Ideal.Quotient.eq, Function.comp_apply, AlgHom.coe_comp, Ideal.Quotient.mkₐ_eq_mk, RingHom.mem_ker, map_sub, sub_eq_zero]) theorem ext' [FormallyUnramified R A] {C : Type*} [Ring C] (f : B →+* C) (hf : IsNilpotent <| RingHom.ker f) (g₁ g₂ : A →ₐ[R] B) (h : ∀ x, f (g₁ x) = f (g₂ x)) : g₁ = g₂ := FormallyUnramified.lift_unique_of_ringHom f hf g₁ g₂ (RingHom.ext h) theorem lift_unique' [FormallyUnramified R A] {C : Type*} [Ring C] [Algebra R C] (f : B →ₐ[R] C) (hf : IsNilpotent <| RingHom.ker (f : B →+* C)) (g₁ g₂ : A →ₐ[R] B) (h : f.comp g₁ = f.comp g₂) : g₁ = g₂ := FormallyUnramified.ext' _ hf g₁ g₂ (AlgHom.congr_fun h) theorem ext_of_iInf [FormallyUnramified R A] (hI : ⨅ i, I ^ i = ⊥) {g₁ g₂ : A →ₐ[R] B} (H : ∀ x, Ideal.Quotient.mk I (g₁ x) = Ideal.Quotient.mk I (g₂ x)) : g₁ = g₂ := by have (i : ℕ) : (Ideal.Quotient.mkₐ R (I ^ i)).comp g₁ = (Ideal.Quotient.mkₐ R (I ^ i)).comp g₂ := by by_cases hi : i = 0 · ext x have : Subsingleton (B ⧸ I ^ i) := by rw [hi, pow_zero, Ideal.one_eq_top] infer_instance exact Subsingleton.elim _ _ apply ext (I.map (algebraMap _ _)) ⟨i, by simp [← Ideal.map_pow]⟩ intro x dsimp rw [Ideal.Quotient.eq, ← map_sub, ← Ideal.mem_comap, Ideal.comap_map_of_surjective', sup_eq_left.mpr, ← Ideal.Quotient.eq] · exact H _ · simpa using Ideal.pow_le_self hi · exact Ideal.Quotient.mk_surjective ext x rw [← sub_eq_zero, ← Ideal.mem_bot, ← hI, Ideal.mem_iInf] intro i rw [← Ideal.Quotient.eq_zero_iff_mem, map_sub, sub_eq_zero] exact DFunLike.congr_fun (this i) x end instance {R : Type u} [CommRing R] : FormallyUnramified R R := by rw [iff_comp_injective] intro B _ _ _ _ f₁ f₂ _ exact Subsingleton.elim _ _ section OfEquiv variable {R : Type*} [CommRing R] variable {A B : Type*} [CommRing A] [Algebra R A] [CommRing B] [Algebra R B] theorem of_equiv [FormallyUnramified R A] (e : A ≃ₐ[R] B) : FormallyUnramified R B := by rw [iff_comp_injective] intro C _ _ I hI f₁ f₂ e' rw [← f₁.comp_id, ← f₂.comp_id, ← e.comp_symm, ← AlgHom.comp_assoc, ← AlgHom.comp_assoc] congr 1 refine FormallyUnramified.comp_injective I hI ?_ rw [← AlgHom.comp_assoc, e', AlgHom.comp_assoc] end OfEquiv section Comp variable (R : Type*) [CommRing R] variable (A : Type*) [CommRing A] [Algebra R A] variable (B : Type*) [CommRing B] [Algebra R B] [Algebra A B] [IsScalarTower R A B] theorem comp [FormallyUnramified R A] [FormallyUnramified A B] : FormallyUnramified R B := by rw [iff_comp_injective] intro C _ _ I hI f₁ f₂ e have e' := FormallyUnramified.lift_unique I ⟨2, hI⟩ (f₁.comp <| IsScalarTower.toAlgHom R A B) (f₂.comp <| IsScalarTower.toAlgHom R A B) (by rw [← AlgHom.comp_assoc, e, AlgHom.comp_assoc]) letI := (f₁.restrictDomain A).toAlgebra let F₁ : B →ₐ[A] C := { f₁ with commutes' := fun r => rfl } let F₂ : B →ₐ[A] C := { f₂ with commutes' := AlgHom.congr_fun e'.symm } ext1 x change F₁ x = F₂ x congr exact FormallyUnramified.ext I ⟨2, hI⟩ (AlgHom.congr_fun e) theorem of_comp [FormallyUnramified R B] : FormallyUnramified A B := by rw [iff_comp_injective] intro Q _ _ I e f₁ f₂ e' letI := ((algebraMap A Q).comp (algebraMap R A)).toAlgebra letI : IsScalarTower R A Q := IsScalarTower.of_algebraMap_eq' rfl refine AlgHom.restrictScalars_injective R ?_ refine FormallyUnramified.ext I ⟨2, e⟩ ?_ intro x exact AlgHom.congr_fun e' x end Comp section of_surjective variable {R : Type*} [CommRing R] variable {A B : Type*} [CommRing A] [Algebra R A] [CommRing B] [Algebra R B] /-- This holds in general for epimorphisms. -/ theorem of_surjective [FormallyUnramified R A] (f : A →ₐ[R] B) (H : Function.Surjective f) : FormallyUnramified R B := by rw [iff_comp_injective] intro Q _ _ I hI f₁ f₂ e ext x obtain ⟨x, rfl⟩ := H x rw [← AlgHom.comp_apply, ← AlgHom.comp_apply] congr 1 apply FormallyUnramified.comp_injective I hI ext x; exact DFunLike.congr_fun e (f x) instance quotient {A} [CommRing A] [Algebra R A] [FormallyUnramified R A] (I : Ideal A) : FormallyUnramified R (A ⧸ I) := FormallyUnramified.of_surjective (IsScalarTower.toAlgHom R A (A ⧸ I)) Ideal.Quotient.mk_surjective theorem iff_of_equiv (e : A ≃ₐ[R] B) : FormallyUnramified R A ↔ FormallyUnramified R B := ⟨fun _ ↦ of_equiv e, fun _ ↦ of_equiv e.symm⟩ end of_surjective section BaseChange open scoped TensorProduct variable {R : Type*} [CommRing R] variable {A : Type*} [CommRing A] [Algebra R A] variable (B : Type*) [CommRing B] [Algebra R B] instance base_change [FormallyUnramified R A] : FormallyUnramified B (B ⊗[R] A) := by rw [iff_comp_injective] intro C _ _ I hI f₁ f₂ e letI := ((algebraMap B C).comp (algebraMap R B)).toAlgebra haveI : IsScalarTower R B C := IsScalarTower.of_algebraMap_eq' rfl ext : 1 · subsingleton · exact FormallyUnramified.ext I ⟨2, hI⟩ fun x => AlgHom.congr_fun e (1 ⊗ₜ x) end BaseChange section Localization variable {R S Rₘ Sₘ : Type*} [CommRing R] [CommRing S] [CommRing Rₘ] [CommRing Sₘ] variable (M : Submonoid R) 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ₘ] variable [IsLocalization (M.map (algebraMap R S)) Sₘ] include M /-- This holds in general for epimorphisms. -/ theorem of_isLocalization [IsLocalization M Rₘ] : FormallyUnramified R Rₘ := by rw [iff_comp_injective] intro Q _ _ I _ f₁ f₂ _ apply AlgHom.coe_ringHom_injective refine IsLocalization.ringHom_ext M ?_ ext simp instance [FormallyUnramified R S] (M : Submonoid S) : FormallyUnramified R (Localization M) := have := of_isLocalization (Rₘ := Localization M) M .comp _ S _ set_option linter.unusedSectionVars false in /-- This actually does not need the localization instance, and is stated here again for consistency. See `Algebra.FormallyUnramified.of_comp` instead. The intended use is for copying proofs between `Formally{Unramified, Smooth, Etale}` without the need to change anything (including removing redundant arguments). -/ @[nolint unusedArguments] theorem localization_base [FormallyUnramified R Sₘ] : FormallyUnramified Rₘ Sₘ := FormallyUnramified.of_comp R Rₘ Sₘ theorem localization_map [FormallyUnramified R S] : FormallyUnramified Rₘ Sₘ := by haveI : FormallyUnramified S Sₘ := FormallyUnramified.of_isLocalization (M.map (algebraMap R S)) haveI : FormallyUnramified R Sₘ := FormallyUnramified.comp R S Sₘ exact FormallyUnramified.localization_base M end Localization end FormallyUnramified section variable (R : Type*) [CommRing R] variable (A : Type*) [CommRing A] [Algebra R A] /-- An `R`-algebra `A` is unramified if it is formally unramified and of finite type. -/ @[stacks 00UT "Note that the Stacks project has a different definition of unramified, and tag <https://stacks.math.columbia.edu/tag/00UU> shows that their definition is the same as this one."] class Unramified : Prop where formallyUnramified : FormallyUnramified R A := by infer_instance finiteType : FiniteType R A := by infer_instance end namespace Unramified attribute [instance] formallyUnramified finiteType variable {R : Type*} [CommRing R] variable {A B : Type*} [CommRing A] [Algebra R A] [CommRing B] [Algebra R B] /-- Being unramified is transported via algebra isomorphisms. -/ theorem of_equiv [Unramified R A] (e : A ≃ₐ[R] B) : Unramified R B where formallyUnramified := FormallyUnramified.of_equiv e finiteType := FiniteType.equiv Unramified.finiteType e /-- Localization at an element is unramified. -/ theorem of_isLocalization_Away (r : R) [IsLocalization.Away r A] : Unramified R A where formallyUnramified := Algebra.FormallyUnramified.of_isLocalization (Submonoid.powers r) finiteType := haveI : FinitePresentation R A := IsLocalization.Away.finitePresentation r inferInstance section Comp variable (R A B) /-- Unramified is stable under composition. -/ theorem comp [Algebra A B] [IsScalarTower R A B] [Unramified R A] [Unramified A B] : Unramified R B where formallyUnramified := FormallyUnramified.comp R A B finiteType := FiniteType.trans (S := A) Unramified.finiteType Unramified.finiteType /-- Unramified is stable under base change. -/ instance baseChange [Unramified R A] : Unramified B (B ⊗[R] A) where end Comp end Unramified end Algebra
.lake/packages/mathlib/Mathlib/RingTheory/Unramified/Locus.lean
import Mathlib.RingTheory.Spectrum.Prime.Topology import Mathlib.RingTheory.Etale.Kaehler import Mathlib.RingTheory.Support /-! # Unramified locus of an algebra ## Main results - `Algebra.unramifiedLocus` : The set of primes that is unramified over the base. - `Algebra.basicOpen_subset_unramifiedLocus_iff` : `D(f)` is contained in the unramified locus if and only if `A_f` is unramified over `R`. - `Algebra.unramifiedLocus_eq_univ_iff` : The unramified locus is the whole spectrum if and only if `A` is unramified over `R`. - `Algebra.isOpen_unramifiedLocus` : If `A` is (essentially) of finite type over `R`, then the unramified locus is open. -/ universe u namespace Algebra section variable {R A B : Type*} [CommRing R] [CommRing A] [CommRing B] [Algebra R A] [Algebra A B] [Algebra R B] [IsScalarTower R A B] variable (R) in /-- We say that an `R`-algebra `A` is unramified at a prime `q` of `A` if `A_q` is formally unramified over `R`. If `A` is of finite type over `R` and `q` is lying over `p`, then this is equivalent to `κ(q)/κ(p)` being separable and `pA_q = qA_q`. See `Algebra.isUnramifiedAt_iff_map_eq` in `RingTheory.Unramified.LocalRing` -/ abbrev IsUnramifiedAt (q : Ideal A) [q.IsPrime] : Prop := FormallyUnramified R (Localization.AtPrime q) variable (R A) in /-- `Algebra.unramifiedLocus R A` is the set of primes `p` of `A` that are unramified. -/ def unramifiedLocus : Set (PrimeSpectrum A) := { p | IsUnramifiedAt R p.asIdeal } lemma IsUnramifiedAt.comp (p : Ideal A) (P : Ideal B) [P.LiesOver p] [p.IsPrime] [P.IsPrime] [IsUnramifiedAt R p] [IsUnramifiedAt A P] : IsUnramifiedAt R P := by have : FormallyUnramified (Localization.AtPrime p) (Localization.AtPrime P) := .of_comp A _ _ exact FormallyUnramified.comp R (Localization.AtPrime p) _ variable (R) in lemma IsUnramifiedAt.of_restrictScalars (P : Ideal B) [P.IsPrime] [IsUnramifiedAt R P] : IsUnramifiedAt A P := FormallyUnramified.of_comp R _ _ end section variable {R A : Type u} [CommRing R] [CommRing A] [Algebra R A] lemma unramifiedLocus_eq_compl_support : unramifiedLocus R A = (Module.support A Ω[A⁄R])ᶜ := by ext p simp only [Set.mem_compl_iff, Module.notMem_support_iff] have := IsLocalizedModule.iso p.asIdeal.primeCompl (KaehlerDifferential.map R R A (Localization.AtPrime p.asIdeal)) exact (Algebra.formallyUnramified_iff _ _).trans this.subsingleton_congr.symm lemma basicOpen_subset_unramifiedLocus_iff {f : A} : ↑(PrimeSpectrum.basicOpen f) ⊆ unramifiedLocus R A ↔ Algebra.FormallyUnramified R (Localization.Away f) := by rw [unramifiedLocus_eq_compl_support, Set.subset_compl_comm, PrimeSpectrum.basicOpen_eq_zeroLocus_compl, compl_compl, ← LocalizedModule.subsingleton_iff_support_subset, Algebra.formallyUnramified_iff] exact (IsLocalizedModule.iso (.powers f) (KaehlerDifferential.map R R A (Localization.Away f))).subsingleton_congr lemma unramifiedLocus_eq_univ_iff : unramifiedLocus R A = Set.univ ↔ Algebra.FormallyUnramified R A := by rw [unramifiedLocus_eq_compl_support, compl_eq_comm, Set.compl_univ, eq_comm, Module.support_eq_empty_iff, Algebra.formallyUnramified_iff] lemma isOpen_unramifiedLocus [EssFiniteType R A] : IsOpen (unramifiedLocus R A) := by rw [unramifiedLocus_eq_compl_support, Module.support_eq_zeroLocus] exact (PrimeSpectrum.isClosed_zeroLocus _).isOpen_compl end end Algebra
.lake/packages/mathlib/Mathlib/RingTheory/Unramified/Field.lean
import Mathlib.FieldTheory.PurelyInseparable.Basic import Mathlib.RingTheory.Artinian.Ring import Mathlib.RingTheory.LocalProperties.Basic import Mathlib.Algebra.Polynomial.Taylor import Mathlib.RingTheory.Unramified.Finite /-! # Unramified algebras over fields ## Main results Let `K` be a field, `A` be a `K`-algebra and `L` be a field extension of `K`. - `Algebra.FormallyUnramified.bijective_of_isAlgClosed_of_isLocalRing`: If `A` is `K`-unramified and `K` is alg-closed, then `K = A`. - `Algebra.FormallyUnramified.isReduced_of_field`: If `A` is `K`-unramified then `A` is reduced. - `Algebra.FormallyUnramified.iff_isSeparable`: `L` is unramified over `K` iff `L` is separable over `K`. ## References - [B. Iversen, *Generic Local Structure of the Morphisms in Commutative Algebra*][iversen] -/ open Algebra Module Polynomial open scoped TensorProduct universe u variable (K A L : Type*) [Field K] [Field L] [CommRing A] [Algebra K A] [Algebra K L] namespace Algebra.FormallyUnramified theorem of_isSeparable [Algebra.IsSeparable K L] : FormallyUnramified K L := by rw [iff_comp_injective] intro B _ _ I hI f₁ f₂ e ext x have : f₁ x - f₂ x ∈ I := by simpa [Ideal.Quotient.mk_eq_mk_iff_sub_mem] using AlgHom.congr_fun e x have := Polynomial.eval_add_of_sq_eq_zero ((minpoly K x).map (algebraMap K B)) (f₂ x) (f₁ x - f₂ x) (show (f₁ x - f₂ x) ^ 2 ∈ ⊥ from hI ▸ Ideal.pow_mem_pow this 2) simp only [add_sub_cancel, eval_map_algebraMap, aeval_algHom_apply, minpoly.aeval, map_zero, derivative_map, zero_add] at this rwa [eq_comm, ((isUnit_iff_ne_zero.mpr ((Algebra.IsSeparable.isSeparable K x).aeval_derivative_ne_zero (minpoly.aeval K x))).map f₂).mul_right_eq_zero, sub_eq_zero] at this variable [FormallyUnramified K A] [EssFiniteType K A] variable [FormallyUnramified K L] [EssFiniteType K L] theorem bijective_of_isAlgClosed_of_isLocalRing [IsAlgClosed K] [IsLocalRing A] : Function.Bijective (algebraMap K A) := by have := finite_of_free (R := K) (S := A) have : IsArtinianRing A := isArtinian_of_tower K inferInstance have hA : IsNilpotent (IsLocalRing.maximalIdeal A) := by rw [← IsLocalRing.jacobson_eq_maximalIdeal ⊥] · exact IsArtinianRing.isNilpotent_jacobson_bot · exact bot_ne_top let e : K ≃ₐ[K] A ⧸ IsLocalRing.maximalIdeal A := { __ := Algebra.ofId K (A ⧸ IsLocalRing.maximalIdeal A) __ := Equiv.ofBijective _ IsAlgClosed.algebraMap_bijective_of_isIntegral } let e' : A ⊗[K] (A ⧸ IsLocalRing.maximalIdeal A) ≃ₐ[A] A := (Algebra.TensorProduct.congr AlgEquiv.refl e.symm).trans (Algebra.TensorProduct.rid K A A) let f : A ⧸ IsLocalRing.maximalIdeal A →ₗ[A] A := e'.toLinearMap.comp (sec K A _) have hf : (Algebra.ofId _ _).toLinearMap ∘ₗ f = LinearMap.id := by dsimp [f] rw [← LinearMap.comp_assoc, ← comp_sec K A] congr 1 apply LinearMap.restrictScalars_injective K apply _root_.TensorProduct.ext' intro r s obtain ⟨s, rfl⟩ := e.surjective s suffices s • (Ideal.Quotient.mk (IsLocalRing.maximalIdeal A)) r = r • e s by simpa [ofId, e'] simp [Algebra.smul_def, e, ofId, mul_comm] have hf₁ : f 1 • (1 : A ⧸ IsLocalRing.maximalIdeal A) = 1 := by rw [← algebraMap_eq_smul_one] exact LinearMap.congr_fun hf 1 have hf₂ : 1 - f 1 ∈ IsLocalRing.maximalIdeal A := by rw [← Ideal.Quotient.eq_zero_iff_mem, map_sub, map_one, ← Ideal.Quotient.algebraMap_eq, algebraMap_eq_smul_one, hf₁, sub_self] have hf₃ : IsIdempotentElem (1 - f 1) := by apply IsIdempotentElem.one_sub rw [IsIdempotentElem, ← smul_eq_mul, ← map_smul, hf₁] have hf₄ : f 1 = 1 := by obtain ⟨n, hn⟩ := hA have : (1 - f 1) ^ n = 0 := by rw [← Ideal.mem_bot, ← Ideal.zero_eq_bot, ← hn] exact Ideal.pow_mem_pow hf₂ n rw [eq_comm, ← sub_eq_zero, ← hf₃.pow_succ_eq n, pow_succ, this, zero_mul] refine Equiv.bijective ⟨algebraMap K A, ⇑e.symm ∘ ⇑(algebraMap A _), fun x ↦ by simp, fun x ↦ ?_⟩ have : ⇑(algebraMap K A) = ⇑f ∘ ⇑e := by ext k conv_rhs => rw [← mul_one k, ← smul_eq_mul, Function.comp_apply, map_smul, LinearMap.map_smul_of_tower, map_one, hf₄, ← algebraMap_eq_smul_one] rw [this] simp only [Function.comp_apply, AlgEquiv.apply_symm_apply, algebraMap_eq_smul_one, map_smul, hf₄, smul_eq_mul, mul_one] theorem isField_of_isAlgClosed_of_isLocalRing [IsAlgClosed K] [IsLocalRing A] : IsField A := by rw [IsLocalRing.isField_iff_maximalIdeal_eq, eq_bot_iff] intro x hx obtain ⟨x, rfl⟩ := (bijective_of_isAlgClosed_of_isLocalRing K A).surjective x change _ = 0 rw [← (algebraMap K A).map_zero] by_contra hx' exact hx ((isUnit_iff_ne_zero.mpr (fun e ↦ hx' ((algebraMap K A).congr_arg e))).map (algebraMap K A)) include K in theorem isReduced_of_field : IsReduced A := by constructor intro x hx let f := (Algebra.TensorProduct.includeRight (R := K) (A := AlgebraicClosure K) (B := A)) have : Function.Injective f := by have : ⇑f = (LinearMap.rTensor A (Algebra.ofId K (AlgebraicClosure K)).toLinearMap).comp (Algebra.TensorProduct.lid K A).symm.toLinearMap := by ext x; simp [f] rw [this] suffices Function.Injective (LinearMap.rTensor A (Algebra.ofId K (AlgebraicClosure K)).toLinearMap) by exact this.comp (Algebra.TensorProduct.lid K A).symm.injective apply Module.Flat.rTensor_preserves_injective_linearMap exact (algebraMap K _).injective apply this rw [map_zero] apply eq_zero_of_localization intro M hM have hy := (hx.map f).map (algebraMap _ (Localization.AtPrime M)) generalize algebraMap _ (Localization.AtPrime M) (f x) = y at * have := EssFiniteType.of_isLocalization (Localization.AtPrime M) M.primeCompl have := of_isLocalization (Rₘ := Localization.AtPrime M) M.primeCompl have := EssFiniteType.comp (AlgebraicClosure K) (AlgebraicClosure K ⊗[K] A) (Localization.AtPrime M) have := comp (AlgebraicClosure K) (AlgebraicClosure K ⊗[K] A) (Localization.AtPrime M) letI := (isField_of_isAlgClosed_of_isLocalRing (AlgebraicClosure K) (A := Localization.AtPrime M)).toField exact hy.eq_zero theorem range_eq_top_of_isPurelyInseparable [IsPurelyInseparable K L] : (algebraMap K L).range = ⊤ := by classical have : Nontrivial (L ⊗[K] L) := by rw [← not_subsingleton_iff_nontrivial, ← rank_zero_iff (R := K), rank_tensorProduct', mul_eq_zero, or_self, rank_zero_iff, not_subsingleton_iff_nontrivial] infer_instance rw [← top_le_iff] intro x _ obtain ⟨n, hn⟩ := IsPurelyInseparable.pow_mem K (ringExpChar K) x have : ExpChar (L ⊗[K] L) (ringExpChar K) := by refine expChar_of_injective_ringHom (algebraMap K _).injective (ringExpChar K) have : (1 ⊗ₜ x - x ⊗ₜ 1 : L ⊗[K] L) ^ (ringExpChar K) ^ n = 0 := by rw [sub_pow_expChar_pow, TensorProduct.tmul_pow, one_pow, TensorProduct.tmul_pow, one_pow] obtain ⟨r, hr⟩ := hn rw [← hr, algebraMap_eq_smul_one, TensorProduct.smul_tmul, sub_self] have H : (1 ⊗ₜ x : L ⊗[K] L) = x ⊗ₜ 1 := by have inst : IsReduced (L ⊗[K] L) := isReduced_of_field L _ exact sub_eq_zero.mp (IsNilpotent.eq_zero ⟨_, this⟩) by_cases h' : LinearIndependent K ![1, x] · have h := h'.linearIndepOn_id let S := h.extend (Set.subset_univ _) let a : S := ⟨1, h.subset_extend _ (by simp)⟩ have ha : Basis.extend h a = 1 := by simp [a] let b : S := ⟨x, h.subset_extend _ (by simp)⟩ have hb : Basis.extend h b = x := by simp [b] by_cases e : a = b · obtain rfl : 1 = x := congr_arg Subtype.val e exact ⟨1, map_one _⟩ have := DFunLike.congr_fun (DFunLike.congr_arg ((Basis.extend h).tensorProduct (Basis.extend h)).repr H) (a, b) simp only [Basis.tensorProduct_repr_tmul_apply, ← ha, ← hb, Basis.repr_self, smul_eq_mul, Finsupp.single_apply, e, Ne.symm e, ↓reduceIte, mul_one, mul_zero, one_ne_zero] at this · rw [LinearIndependent.pair_iff] at h' simp only [not_forall, not_and, exists_prop] at h' obtain ⟨a, b, e, hab⟩ := h' have : IsUnit b := by rw [isUnit_iff_ne_zero] rintro rfl rw [zero_smul, ← algebraMap_eq_smul_one, add_zero, (injective_iff_map_eq_zero' _).mp (algebraMap K L).injective] at e cases hab e rfl use (-this.unit⁻¹ * a) rw [map_mul, ← Algebra.smul_def, algebraMap_eq_smul_one, eq_neg_iff_add_eq_zero.mpr e, smul_neg, neg_smul, neg_neg, smul_smul, this.val_inv_mul, one_smul] theorem isSeparable : Algebra.IsSeparable K L := by have := finite_of_free (R := K) (S := L) rw [← separableClosure.eq_top_iff] have := of_comp K (separableClosure K L) L have := EssFiniteType.of_comp K (separableClosure K L) L ext change _ ↔ _ ∈ (⊤ : Subring _) rw [← range_eq_top_of_isPurelyInseparable (separableClosure K L) L] simp theorem iff_isSeparable (L : Type u) [Field L] [Algebra K L] [EssFiniteType K L] : FormallyUnramified K L ↔ Algebra.IsSeparable K L := ⟨fun _ ↦ isSeparable K L, fun _ ↦ of_isSeparable K L⟩ end Algebra.FormallyUnramified
.lake/packages/mathlib/Mathlib/RingTheory/IntegralClosure/IntegrallyClosed.lean
import Mathlib.RingTheory.Localization.Integral import Mathlib.RingTheory.Localization.LocalizationLocalization /-! # Integrally closed rings An integrally closed ring `R` contains all the elements of `Frac(R)` that are integral over `R`. A special case of integrally closed rings are the Dedekind domains. ## Main definitions * `IsIntegrallyClosedIn R A` states `R` contains all integral elements of `A` * `IsIntegrallyClosed R` states `R` contains all integral elements of `Frac(R)` ## Main results * `isIntegrallyClosed_iff K`, where `K` is a fraction field of `R`, states `R` is integrally closed iff it is the integral closure of `R` in `K` ## TODO Related notions The following definitions are closely related, especially in their applications in Mathlib. A *normal domain* is a domain that is integrally closed in its field of fractions. [Stacks: normal domain](https://stacks.math.columbia.edu/tag/037B#0309) Normal domains are the major use case of `IsIntegrallyClosed` at the time of writing, and we have quite a few results that can be moved wholesale to a new `NormalDomain` definition. In fact, before PR https://github.com/leanprover-community/mathlib4/pull/6126 `IsIntegrallyClosed` was exactly defined to be a normal domain. (So you might want to copy some of its API when you define normal domains.) A normal ring means that localizations at all prime ideals are normal domains. [Stacks: normal ring](https://stacks.math.columbia.edu/tag/037B#00GV) This implies `IsIntegrallyClosed`, [Stacks: Tag 034M](https://stacks.math.columbia.edu/tag/037B#034M) but is equivalent to it only under some conditions (reduced + finitely many minimal primes), [Stacks: Tag 030C](https://stacks.math.columbia.edu/tag/037B#030C) in which case it's also equivalent to being a finite product of normal domains. We'd need to add these conditions if we want exactly the products of Dedekind domains. In fact Noetherianity is sufficient to guarantee finitely many minimal primes, so `IsDedekindRing` could be defined as `IsReduced`, `IsNoetherian`, `Ring.DimensionLEOne`, and either `IsIntegrallyClosed` or `NormalDomain`. If we use `NormalDomain` then `IsReduced` is automatic, but we could also consider a version of `NormalDomain` that only requires the localizations are `IsIntegrallyClosed` but may not be domains, and that may not equivalent to the ring itself being `IsIntegrallyClosed` (even for Noetherian rings?). -/ open scoped nonZeroDivisors Polynomial open Polynomial /-- `R` is integrally closed in `A` if all integral elements of `A` are also elements of `R`. -/ abbrev IsIntegrallyClosedIn (R A : Type*) [CommRing R] [CommRing A] [Algebra R A] := IsIntegralClosure R R A /-- `R` is integrally closed if all integral elements of `Frac(R)` are also elements of `R`. This definition uses `FractionRing R` to denote `Frac(R)`. See `isIntegrallyClosed_iff` if you want to choose another field of fractions for `R`. -/ abbrev IsIntegrallyClosed (R : Type*) [CommRing R] := IsIntegrallyClosedIn R (FractionRing R) section Iff variable {R : Type*} [CommRing R] variable {A B : Type*} [CommRing A] [CommRing B] [Algebra R A] [Algebra R B] /-- Being integrally closed is preserved under injective algebra homomorphisms. -/ theorem AlgHom.isIntegrallyClosedIn (f : A →ₐ[R] B) (hf : Function.Injective f) : IsIntegrallyClosedIn R B → IsIntegrallyClosedIn R A := by rintro ⟨inj, cl⟩ refine ⟨Function.Injective.of_comp (f := f) ?_, fun hx => ?_, ?_⟩ · convert inj aesop · obtain ⟨y, fx_eq⟩ := cl.mp ((isIntegral_algHom_iff f hf).mpr hx) aesop · rintro ⟨y, rfl⟩ apply (isIntegral_algHom_iff f hf).mp simp_all /-- Being integrally closed is preserved under algebra isomorphisms. -/ theorem AlgEquiv.isIntegrallyClosedIn (e : A ≃ₐ[R] B) : IsIntegrallyClosedIn R A ↔ IsIntegrallyClosedIn R B := ⟨AlgHom.isIntegrallyClosedIn e.symm e.symm.injective, AlgHom.isIntegrallyClosedIn e e.injective⟩ variable (K : Type*) [CommRing K] [Algebra R K] [IsFractionRing R K] /-- `R` is integrally closed iff it is the integral closure of itself in its field of fractions. -/ theorem isIntegrallyClosed_iff_isIntegrallyClosedIn : IsIntegrallyClosed R ↔ IsIntegrallyClosedIn R K := (IsLocalization.algEquiv R⁰ _ _).isIntegrallyClosedIn /-- `R` is integrally closed iff it is the integral closure of itself in its field of fractions. -/ theorem isIntegrallyClosed_iff_isIntegralClosure : IsIntegrallyClosed R ↔ IsIntegralClosure R R K := isIntegrallyClosed_iff_isIntegrallyClosedIn K /-- `R` is integrally closed in `A` iff all integral elements of `A` are also elements of `R`. -/ theorem isIntegrallyClosedIn_iff {R A : Type*} [CommRing R] [CommRing A] [Algebra R A] : IsIntegrallyClosedIn R A ↔ Function.Injective (algebraMap R A) ∧ ∀ {x : A}, IsIntegral R x → ∃ y, algebraMap R A y = x := by constructor · rintro ⟨_, cl⟩ simp_all · rintro ⟨inj, cl⟩ refine ⟨inj, by simp_all, ?_⟩ rintro ⟨y, rfl⟩ apply isIntegral_algebraMap /-- `R` is integrally closed iff all integral elements of its fraction field `K` are also elements of `R`. -/ theorem isIntegrallyClosed_iff : IsIntegrallyClosed R ↔ ∀ {x : K}, IsIntegral R x → ∃ y, algebraMap R K y = x := by simp [isIntegrallyClosed_iff_isIntegrallyClosedIn K, isIntegrallyClosedIn_iff, IsFractionRing.injective R K] end Iff namespace IsIntegrallyClosedIn variable {R A : Type*} [CommRing R] [CommRing A] [Algebra R A] theorem algebraMap_eq_of_integral [IsIntegrallyClosedIn R A] {x : A} : IsIntegral R x → ∃ y : R, algebraMap R A y = x := IsIntegralClosure.isIntegral_iff.mp theorem isIntegral_iff [IsIntegrallyClosedIn R A] {x : A} : IsIntegral R x ↔ ∃ y : R, algebraMap R A y = x := IsIntegralClosure.isIntegral_iff theorem exists_algebraMap_eq_of_isIntegral_pow [IsIntegrallyClosedIn R A] {x : A} {n : ℕ} (hn : 0 < n) (hx : IsIntegral R <| x ^ n) : ∃ y : R, algebraMap R A y = x := isIntegral_iff.mp <| hx.of_pow hn theorem exists_algebraMap_eq_of_pow_mem_subalgebra {A : Type*} [CommRing A] [Algebra R A] {S : Subalgebra R A} [IsIntegrallyClosedIn S A] {x : A} {n : ℕ} (hn : 0 < n) (hx : x ^ n ∈ S) : ∃ y : S, algebraMap S A y = x := exists_algebraMap_eq_of_isIntegral_pow hn <| isIntegral_iff.mpr ⟨⟨x ^ n, hx⟩, rfl⟩ variable (A) theorem integralClosure_eq_bot_iff (hRA : Function.Injective (algebraMap R A)) : integralClosure R A = ⊥ ↔ IsIntegrallyClosedIn R A := by refine eq_bot_iff.trans ?_ constructor · intro h refine ⟨ hRA, fun hx => Set.mem_range.mp (Algebra.mem_bot.mp (h hx)), ?_⟩ rintro ⟨y, rfl⟩ apply isIntegral_algebraMap · intro h x hx rw [Algebra.mem_bot, Set.mem_range] exact isIntegral_iff.mp hx variable (R) @[simp] theorem integralClosure_eq_bot [IsIntegrallyClosedIn R A] [NoZeroSMulDivisors R A] [Nontrivial A] : integralClosure R A = ⊥ := (integralClosure_eq_bot_iff A (FaithfulSMul.algebraMap_injective _ _)).mpr ‹_› variable {A} {B : Type*} [CommRing B] /-- If `R` is the integral closure of `S` in `A`, then it is integrally closed in `A`. -/ lemma of_isIntegralClosure [Algebra R B] [Algebra A B] [IsScalarTower R A B] [IsIntegralClosure A R B] : IsIntegrallyClosedIn A B := have : Algebra.IsIntegral R A := IsIntegralClosure.isIntegral_algebra R B IsIntegralClosure.tower_top (R := R) variable {R} lemma _root_.IsIntegralClosure.of_isIntegrallyClosedIn [Algebra R B] [Algebra A B] [IsScalarTower R A B] [IsIntegrallyClosedIn A B] [Algebra.IsIntegral R A] : IsIntegralClosure A R B := by refine ⟨IsIntegralClosure.algebraMap_injective _ A _, fun {x} ↦ ⟨fun hx ↦ IsIntegralClosure.isIntegral_iff.mp (IsIntegral.tower_top (A := A) hx), ?_⟩⟩ rintro ⟨y, rfl⟩ exact IsIntegral.map (IsScalarTower.toAlgHom A A B) (Algebra.IsIntegral.isIntegral y) end IsIntegrallyClosedIn namespace IsIntegrallyClosed variable {R S : Type*} [CommRing R] [CommRing S] variable {K : Type*} [CommRing K] [Algebra R K] [ifr : IsFractionRing R K] /-- Note that this is not a duplicate instance, since `IsIntegrallyClosed R` is instead defined as `IsIntegrallyClosed R R (FractionRing R)`. -/ instance [iic : IsIntegrallyClosed R] : IsIntegralClosure R R K := (isIntegrallyClosed_iff_isIntegralClosure K).mp iic theorem algebraMap_eq_of_integral [IsIntegrallyClosed R] {x : K} : IsIntegral R x → ∃ y : R, algebraMap R K y = x := IsIntegralClosure.isIntegral_iff.mp theorem isIntegral_iff [IsIntegrallyClosed R] {x : K} : IsIntegral R x ↔ ∃ y : R, algebraMap R K y = x := IsIntegrallyClosedIn.isIntegral_iff theorem exists_algebraMap_eq_of_isIntegral_pow [IsIntegrallyClosed R] {x : K} {n : ℕ} (hn : 0 < n) (hx : IsIntegral R <| x ^ n) : ∃ y : R, algebraMap R K y = x := IsIntegrallyClosedIn.exists_algebraMap_eq_of_isIntegral_pow hn hx theorem exists_algebraMap_eq_of_pow_mem_subalgebra {K : Type*} [CommRing K] [Algebra R K] {S : Subalgebra R K} [IsIntegrallyClosed S] [IsFractionRing S K] {x : K} {n : ℕ} (hn : 0 < n) (hx : x ^ n ∈ S) : ∃ y : S, algebraMap S K y = x := IsIntegrallyClosedIn.exists_algebraMap_eq_of_pow_mem_subalgebra hn hx theorem of_equiv (f : R ≃+* S) [h : IsIntegrallyClosed R] : IsIntegrallyClosed S := by let _ : Algebra S R := f.symm.toRingHom.toAlgebra let f : S ≃ₐ[S] R := AlgEquiv.ofRingEquiv fun _ ↦ rfl let g : FractionRing S ≃ₐ[S] FractionRing R := IsFractionRing.algEquivOfAlgEquiv f refine (isIntegrallyClosed_iff (FractionRing S)).mpr (fun hx ↦ ?_) rcases (isIntegrallyClosed_iff _).mp h ((isIntegral_algEquiv g).mpr hx).tower_top with ⟨z, hz⟩ exact ⟨f.symm z, (IsFractionRing.algEquivOfAlgEquiv_algebraMap f.symm z).symm.trans <| (AlgEquiv.symm_apply_eq g).mpr hz⟩ variable (R S K) instance _root_.IsIntegralClosure.of_isIntegrallyClosed [IsIntegrallyClosed R] [Algebra S R] [Algebra S K] [IsScalarTower S R K] [Algebra.IsIntegral S R] : IsIntegralClosure R S K := IsIntegralClosure.of_isIntegrallyClosedIn variable {R} theorem integralClosure_eq_bot_iff : integralClosure R K = ⊥ ↔ IsIntegrallyClosed R := (IsIntegrallyClosedIn.integralClosure_eq_bot_iff _ (IsFractionRing.injective _ _)).trans (isIntegrallyClosed_iff_isIntegrallyClosedIn _).symm @[simp] theorem pow_dvd_pow_iff [IsDomain R] [IsIntegrallyClosed R] {n : ℕ} (hn : n ≠ 0) {a b : R} : a ^ n ∣ b ^ n ↔ a ∣ b := by refine ⟨fun ⟨x, hx⟩ ↦ ?_, fun h ↦ pow_dvd_pow_of_dvd h n⟩ by_cases ha : a = 0 · simpa [ha, hn] using hx let K := FractionRing R replace ha : algebraMap R K a ≠ 0 := fun h ↦ ha <| (injective_iff_map_eq_zero _).1 (IsFractionRing.injective R K) _ h let y := (algebraMap R K b) / (algebraMap R K a) have hy : IsIntegral R y := by refine ⟨X ^ n - C x, monic_X_pow_sub_C _ hn, ?_⟩ simp only [y, eval₂_sub, eval₂_X_pow, div_pow, eval₂_C] replace hx := congr_arg (algebraMap R K) hx rw [map_pow] at hx simp [hx, ha] obtain ⟨k, hk⟩ := algebraMap_eq_of_integral hy refine ⟨k, IsFractionRing.injective R K ?_⟩ rw [map_mul, hk, mul_div_cancel₀ _ ha] @[simp] theorem _root_.Associated.pow_iff [IsDomain R] [IsIntegrallyClosed R] {n : ℕ} (hn : n ≠ 0) {a b : R} : Associated (a ^ n) (b ^ n) ↔ Associated a b := by simp_rw [← dvd_dvd_iff_associated, pow_dvd_pow_iff hn] variable (R) /-- This is almost a duplicate of `IsIntegrallyClosedIn.integralClosure_eq_bot`, except the `NoZeroSMulDivisors` hypothesis isn't inferred automatically from `IsFractionRing`. -/ @[simp] theorem integralClosure_eq_bot [IsIntegrallyClosed R] : integralClosure R K = ⊥ := (integralClosure_eq_bot_iff K).mpr ‹_› end IsIntegrallyClosed namespace integralClosure open IsIntegrallyClosed variable {R : Type*} [CommRing R] variable (K : Type*) [Field K] [Algebra R K] variable [IsFractionRing R K] variable {L : Type*} [Field L] [Algebra K L] [Algebra R L] [IsScalarTower R K L] -- Can't be an instance because you need to supply `K`. theorem isIntegrallyClosedOfFiniteExtension [IsDomain R] [FiniteDimensional K L] : IsIntegrallyClosed (integralClosure R L) := letI : IsFractionRing (integralClosure R L) L := isFractionRing_of_finite_extension K L (integralClosure_eq_bot_iff L).mp integralClosure_idem end integralClosure section localization variable {R : Type*} (S : Type*) [CommRing R] [CommRing S] [Algebra R S] lemma isIntegrallyClosed_of_isLocalization [IsIntegrallyClosed R] [IsDomain R] (M : Submonoid R) (hM : M ≤ R⁰) [IsLocalization M S] : IsIntegrallyClosed S := by let K := FractionRing R let g : S →+* K := IsLocalization.map _ (T := R⁰) (RingHom.id R) hM letI := g.toAlgebra have : IsScalarTower R S K := IsScalarTower.of_algebraMap_eq' (by rw [RingHom.algebraMap_toAlgebra, IsLocalization.map_comp, RingHomCompTriple.comp_eq]) have := IsFractionRing.isFractionRing_of_isDomain_of_isLocalization M S K refine (isIntegrallyClosed_iff_isIntegralClosure (K := K)).mpr ⟨IsFractionRing.injective _ _, fun {x} ↦ ⟨?_, fun e ↦ e.choose_spec ▸ isIntegral_algebraMap⟩⟩ intro hx obtain ⟨⟨y, y_mem⟩, hy⟩ := hx.exists_multiple_integral_of_isLocalization M _ obtain ⟨z, hz⟩ := (isIntegrallyClosed_iff _).mp ‹_› hy refine ⟨IsLocalization.mk' S z ⟨y, y_mem⟩, (IsLocalization.lift_mk'_spec _ _ _ _).mpr ?_⟩ rw [RingHom.comp_id, hz, ← Algebra.smul_def, Submonoid.mk_smul] end localization /-- Any field is integral closed. -/ /- Although `infer_instance` can find this if you import Mathlib, in this file they have not been proven yet. However, it is used to prove a fundamental property of `IsIntegrallyClosed`, and it is not desirable to involve more content from other files. -/ instance Field.instIsIntegrallyClosed (K : Type*) [Field K] : IsIntegrallyClosed K := (isIntegrallyClosed_iff K).mpr fun {x} _ ↦ ⟨x, rfl⟩
.lake/packages/mathlib/Mathlib/RingTheory/IntegralClosure/IntegralRestrict.lean
import Mathlib.RingTheory.DedekindDomain.IntegralClosure import Mathlib.RingTheory.RingHom.Finite import Mathlib.RingTheory.Localization.LocalizationLocalization import Mathlib.RingTheory.Localization.NormTrace import Mathlib.RingTheory.Norm.Transitivity /-! # Restriction of various maps between fields to integrally closed subrings. In this file, we assume `A` is an integrally closed domain; `K` is the fraction ring of `A`; `L` is a finite extension of `K`; `B` is the integral closure of `A` in `L`. We call this the AKLB setup. ## Main definition - `galRestrict`: The restriction `Aut(L/K) → Aut(B/A)` as an `MulEquiv` in an AKLB setup. - `Algebra.intTrace`: The trace map of a finite extension of integrally closed domains `B/A` is defined to be the restriction of the trace map of `Frac(B)/Frac(A)`. - `Algebra.intNorm`: The norm map of a finite extension of integrally closed domains `B/A` is defined to be the restriction of the norm map of `Frac(B)/Frac(A)`. -/ open nonZeroDivisors variable (A K L L₂ L₃ B B₂ B₃ : Type*) variable [CommRing A] [CommRing B] [CommRing B₂] [CommRing B₃] variable [Algebra A B] [Algebra A B₂] [Algebra A B₃] variable [Field K] [Field L] [Field L₂] [Field L₃] variable [Algebra A K] [IsFractionRing A K] variable [Algebra K L] [Algebra A L] [IsScalarTower A K L] variable [Algebra K L₂] [Algebra A L₂] [IsScalarTower A K L₂] variable [Algebra K L₃] [Algebra A L₃] [IsScalarTower A K L₃] variable [Algebra B L] [IsScalarTower A B L] [IsIntegralClosure B A L] variable [Algebra B₂ L₂] [IsScalarTower A B₂ L₂] [IsIntegralClosure B₂ A L₂] variable [Algebra B₃ L₃] [IsScalarTower A B₃ L₃] [IsIntegralClosure B₃ A L₃] section galois section galRestrict' variable {K L L₂ L₃} omit [IsFractionRing A K] /-- A generalization of `galRestrictHom` beyond endomorphisms. -/ noncomputable def galRestrict' (f : L →ₐ[K] L₂) : (B →ₐ[A] B₂) := (IsIntegralClosure.equiv A (integralClosure A L₂) L₂ B₂).toAlgHom.comp (((f.restrictScalars A).comp (IsScalarTower.toAlgHom A B L)).codRestrict (integralClosure A L₂) (fun x ↦ IsIntegral.map _ (IsIntegralClosure.isIntegral A L x))) @[simp] lemma algebraMap_galRestrict'_apply (σ : L →ₐ[K] L₂) (x : B) : algebraMap B₂ L₂ (galRestrict' A B B₂ σ x) = σ (algebraMap B L x) := by simp [galRestrict', galRestrict', Subalgebra.algebraMap_eq] @[simp] theorem galRestrict'_id : galRestrict' A B B (.id K L) = .id A B := by ext apply IsIntegralClosure.algebraMap_injective B A L simp theorem galRestrict'_comp (σ : L →ₐ[K] L₂) (σ' : L₂ →ₐ[K] L₃) : galRestrict' A B B₃ (σ'.comp σ) = (galRestrict' A B₂ B₃ σ').comp (galRestrict' A B B₂ σ) := by ext x apply (IsIntegralClosure.equiv A (integralClosure A L₃) L₃ B₃).symm.injective ext simp [galRestrict', Subalgebra.algebraMap_eq] end galRestrict' variable [Algebra.IsAlgebraic K L] section galLift variable {A B B₂ B₃} /-- A generalization of the lift `End(B/A) → End(L/K)` in an ALKB setup. This is inverse to the restriction. See `galRestrictHom`. -/ noncomputable def galLift (σ : B →ₐ[A] B₂) : L →ₐ[K] L₂ := haveI := (IsFractionRing.injective A K).isDomain haveI := NoZeroSMulDivisors.trans_faithfulSMul A K L₂ haveI := IsIntegralClosure.isLocalization A K L B haveI H : ∀ (y : Algebra.algebraMapSubmonoid B A⁰), IsUnit (((algebraMap B₂ L₂).comp σ) (y : B)) := by rintro ⟨_, x, hx, rfl⟩ simpa only [RingHom.coe_comp, RingHom.coe_coe, Function.comp_apply, AlgHom.commutes, isUnit_iff_ne_zero, ne_eq, map_eq_zero_iff _ (FaithfulSMul.algebraMap_injective _ _), ← IsScalarTower.algebraMap_apply] using nonZeroDivisors.ne_zero hx haveI H_eq : (IsLocalization.lift (S := L) H).comp (algebraMap K L) = (algebraMap K L₂) := by apply IsLocalization.ringHom_ext A⁰ ext simp only [RingHom.coe_comp, Function.comp_apply, ← IsScalarTower.algebraMap_apply A K L, ← IsScalarTower.algebraMap_apply A K L₂, IsScalarTower.algebraMap_apply A B L, IsScalarTower.algebraMap_apply A B₂ L₂, IsLocalization.lift_eq, RingHom.coe_coe, AlgHom.commutes] { IsLocalization.lift (S := L) H with commutes' := DFunLike.congr_fun H_eq } omit [IsIntegralClosure B₂ A L₂] in @[simp] theorem galLift_algebraMap_apply (σ : B →ₐ[A] B₂) (x : B) : galLift K L L₂ σ (algebraMap B L x) = algebraMap B₂ L₂ (σ x) := by simp [galLift] @[simp] theorem galLift_id : galLift K L L (.id A B) = .id K L := by ext; simp [galLift] omit [IsIntegralClosure B₃ A L₃] in theorem galLift_comp [Algebra.IsAlgebraic K L₂] (σ : B →ₐ[A] B₂) (σ' : B₂ →ₐ[A] B₃) : galLift K L L₃ (σ'.comp σ) = (galLift K L₂ L₃ σ').comp (galLift K L L₂ σ) := have := (IsFractionRing.injective A K).isDomain have := IsIntegralClosure.isLocalization A K L B AlgHom.coe_ringHom_injective <| IsLocalization.ringHom_ext (Algebra.algebraMapSubmonoid B A⁰) <| RingHom.ext fun x ↦ by simp @[simp] theorem galLift_galRestrict' (σ : L →ₐ[K] L₂) : galLift K L L₂ (galRestrict' A B B₂ σ) = σ := have := (IsFractionRing.injective A K).isDomain have := IsIntegralClosure.isLocalization A K L B AlgHom.coe_ringHom_injective <| IsLocalization.ringHom_ext (Algebra.algebraMapSubmonoid B A⁰) <| RingHom.ext fun x ↦ by simp [galRestrict', Subalgebra.algebraMap_eq, galLift] @[simp] theorem galRestrict'_galLift (σ : B →ₐ[A] B₂) : galRestrict' A B B₂ (galLift K L L₂ σ) = σ := have := (IsFractionRing.injective A K).isDomain have := IsIntegralClosure.isLocalization A K L B AlgHom.ext fun x ↦ IsIntegralClosure.algebraMap_injective B₂ A L₂ (by simp [galRestrict', Subalgebra.algebraMap_eq, galLift]) /-- A version of `galLift` for `AlgEquiv`. -/ @[simps! -fullyApplied apply symm_apply] noncomputable def galLiftEquiv [Algebra.IsAlgebraic K L₂] (σ : B ≃ₐ[A] B₂) : L ≃ₐ[K] L₂ := AlgEquiv.ofAlgHom (galLift K L L₂ σ.toAlgHom) (galLift K L₂ L σ.symm.toAlgHom) (by simp [← galLift_comp]) (by simp [← galLift_comp]) theorem galLiftEquiv_algebraMap_apply [Algebra.IsAlgebraic K L₂] (σ : B ≃ₐ[A] B₂) (x : B) : galLiftEquiv K L L₂ σ (algebraMap B L x) = algebraMap B₂ L₂ (σ x) := by simp [galLiftEquiv] end galLift /-- The restriction `End(L/K) → End(B/A)` in an AKLB setup. Also see `galRestrict` for the `AlgEquiv` version. -/ @[simps -isSimp] noncomputable def galRestrictHom : (L →ₐ[K] L) ≃* (B →ₐ[A] B) where toFun f := galRestrict' A B B f map_mul' σ₁ σ₂ := galRestrict'_comp _ _ _ _ σ₂ σ₁ invFun := galLift K L L left_inv σ := galLift_galRestrict' _ _ _ σ right_inv σ := galRestrict'_galLift _ _ _ σ @[simp] lemma algebraMap_galRestrictHom_apply (σ : L →ₐ[K] L) (x : B) : algebraMap B L (galRestrictHom A K L B σ x) = σ (algebraMap B L x) := algebraMap_galRestrict'_apply _ _ _ _ _ @[simp, nolint unusedHavesSuffices] -- false positive from unfolding galRestrictHom lemma galRestrictHom_symm_algebraMap_apply (σ : B →ₐ[A] B) (x : B) : (galRestrictHom A K L B).symm σ (algebraMap B L x) = algebraMap B L (σ x) := galLift_algebraMap_apply _ _ _ _ _ /-- The restriction `Aut(L/K) → Aut(B/A)` in an AKLB setup. -/ noncomputable def galRestrict : Gal(L/K) ≃* (B ≃ₐ[A] B) := (AlgEquiv.algHomUnitsEquiv K L).symm.trans ((Units.mapEquiv <| galRestrictHom A K L B).trans (AlgEquiv.algHomUnitsEquiv A B)) variable {K L} lemma coe_galRestrict_apply (σ : Gal(L/K)) : (galRestrict A K L B σ : B →ₐ[A] B) = galRestrictHom A K L B σ := rfl variable {B} lemma galRestrict_apply (σ : Gal(L/K)) (x : B) : galRestrict A K L B σ x = galRestrictHom A K L B σ x := rfl lemma algebraMap_galRestrict_apply (σ : Gal(L/K)) (x : B) : algebraMap B L (galRestrict A K L B σ x) = σ (algebraMap B L x) := algebraMap_galRestrictHom_apply A K L B σ.toAlgHom x variable (K) in lemma galRestrict_symm_algebraMap_apply (σ : B ≃ₐ[A] B) (x : B) : (galRestrict A K L B).symm σ (algebraMap B L x) = algebraMap B L (σ x) := galRestrictHom_symm_algebraMap_apply A K L B σ x end galois variable [FiniteDimensional K L] lemma prod_galRestrict_eq_norm [IsGalois K L] [IsIntegrallyClosed A] (x : B) : (∏ σ : Gal(L/K), galRestrict A K L B σ x) = algebraMap A B (IsIntegralClosure.mk' (R := A) A (Algebra.norm K <| algebraMap B L x) (Algebra.isIntegral_norm K (IsIntegralClosure.isIntegral A L x).algebraMap)) := by apply IsIntegralClosure.algebraMap_injective B A L rw [← IsScalarTower.algebraMap_apply, IsScalarTower.algebraMap_eq A K L] simp only [map_prod, algebraMap_galRestrict_apply, IsIntegralClosure.algebraMap_mk', Algebra.norm_eq_prod_automorphisms, RingHom.coe_comp, Function.comp_apply] attribute [local instance] FractionRing.liftAlgebra FractionRing.isScalarTower_liftAlgebra noncomputable instance (priority := 900) [IsDomain A] [IsDomain B] [IsIntegrallyClosed B] [Module.Finite A B] [NoZeroSMulDivisors A B] : Fintype (B ≃ₐ[A] B) := haveI : IsIntegralClosure B A (FractionRing B) := IsIntegralClosure.of_isIntegrallyClosed _ _ _ haveI : IsLocalization (Algebra.algebraMapSubmonoid B A⁰) (FractionRing B) := IsIntegralClosure.isLocalization _ (FractionRing A) _ _ haveI : FiniteDimensional (FractionRing A) (FractionRing B) := .of_isLocalization A B A⁰ Fintype.ofEquiv _ (galRestrict A (FractionRing A) (FractionRing B) B).toEquiv variable {Aₘ Bₘ} [CommRing Aₘ] [CommRing Bₘ] [Algebra Aₘ Bₘ] [Algebra A Aₘ] [Algebra B Bₘ] variable [Algebra A Bₘ] [IsScalarTower A Aₘ Bₘ] [IsScalarTower A B Bₘ] variable (M : Submonoid A) [IsLocalization M Aₘ] variable [IsLocalization (Algebra.algebraMapSubmonoid B M) Bₘ] section trace /-- The restriction of the trace on `L/K` restricted onto `B/A` in an AKLB setup. See `Algebra.intTrace` instead. -/ noncomputable def Algebra.intTraceAux [IsIntegrallyClosed A] : B →ₗ[A] A := (IsIntegralClosure.equiv A (integralClosure A K) K A).toLinearMap.comp ((((Algebra.trace K L).restrictScalars A).comp (IsScalarTower.toAlgHom A B L).toLinearMap).codRestrict (Subalgebra.toSubmodule <| integralClosure A K) (fun x ↦ isIntegral_trace (IsIntegral.algebraMap (IsIntegralClosure.isIntegral A L x)))) variable {A K L B} lemma Algebra.map_intTraceAux [IsIntegrallyClosed A] (x : B) : algebraMap A K (Algebra.intTraceAux A K L B x) = Algebra.trace K L (algebraMap B L x) := IsIntegralClosure.algebraMap_equiv A (integralClosure A K) K A _ variable (A B) variable [IsDomain A] [IsIntegrallyClosed A] [IsDomain B] [IsIntegrallyClosed B] variable [Module.Finite A B] [NoZeroSMulDivisors A B] /-- The trace of a finite extension of integrally closed domains `B/A` is the restriction of the trace on `Frac(B)/Frac(A)` onto `B/A`. See `Algebra.algebraMap_intTrace`. -/ noncomputable def Algebra.intTrace : B →ₗ[A] A := haveI : IsIntegralClosure B A (FractionRing B) := IsIntegralClosure.of_isIntegrallyClosed _ _ _ haveI : IsLocalization (algebraMapSubmonoid B A⁰) (FractionRing B) := IsIntegralClosure.isLocalization _ (FractionRing A) _ _ haveI : FiniteDimensional (FractionRing A) (FractionRing B) := .of_isLocalization A B A⁰ Algebra.intTraceAux A (FractionRing A) (FractionRing B) B variable {A B} lemma Algebra.algebraMap_intTrace (x : B) : algebraMap A K (Algebra.intTrace A B x) = Algebra.trace K L (algebraMap B L x) := by haveI : IsIntegralClosure B A (FractionRing B) := IsIntegralClosure.of_isIntegrallyClosed _ _ _ haveI : IsLocalization (algebraMapSubmonoid B A⁰) (FractionRing B) := IsIntegralClosure.isLocalization _ (FractionRing A) _ _ haveI : FiniteDimensional (FractionRing A) (FractionRing B) := .of_isLocalization A B A⁰ haveI := IsIntegralClosure.isFractionRing_of_finite_extension A K L B apply (FractionRing.algEquiv A K).symm.injective rw [AlgEquiv.commutes, Algebra.intTrace, Algebra.map_intTraceAux, ← AlgEquiv.commutes (FractionRing.algEquiv B L)] apply Algebra.trace_eq_of_equiv_equiv (FractionRing.algEquiv A K).toRingEquiv (FractionRing.algEquiv B L).toRingEquiv ext exact IsFractionRing.algEquiv_commutes (FractionRing.algEquiv A K) (FractionRing.algEquiv B L) _ lemma Algebra.algebraMap_intTrace_fractionRing (x : B) : algebraMap A (FractionRing A) (Algebra.intTrace A B x) = Algebra.trace (FractionRing A) (FractionRing B) (algebraMap B _ x) := by haveI : IsIntegralClosure B A (FractionRing B) := IsIntegralClosure.of_isIntegrallyClosed _ _ _ haveI : IsLocalization (algebraMapSubmonoid B A⁰) (FractionRing B) := IsIntegralClosure.isLocalization _ (FractionRing A) _ _ haveI : FiniteDimensional (FractionRing A) (FractionRing B) := .of_isLocalization A B A⁰ exact Algebra.map_intTraceAux x variable (A B) lemma Algebra.intTrace_eq_trace [Module.Free A B] : Algebra.intTrace A B = Algebra.trace A B := by ext x haveI : IsIntegralClosure B A (FractionRing B) := IsIntegralClosure.of_isIntegrallyClosed _ _ _ haveI : IsLocalization (algebraMapSubmonoid B A⁰) (FractionRing B) := IsIntegralClosure.isLocalization _ (FractionRing A) _ _ apply IsFractionRing.injective A (FractionRing A) rw [Algebra.algebraMap_intTrace_fractionRing, Algebra.trace_localization A A⁰] open nonZeroDivisors variable [IsDomain Aₘ] [IsIntegrallyClosed Aₘ] [IsDomain Bₘ] [IsIntegrallyClosed Bₘ] variable [NoZeroSMulDivisors Aₘ Bₘ] [Module.Finite Aₘ Bₘ] include M in lemma Algebra.intTrace_eq_of_isLocalization (x : B) : algebraMap A Aₘ (Algebra.intTrace A B x) = Algebra.intTrace Aₘ Bₘ (algebraMap B Bₘ x) := by by_cases hM : 0 ∈ M · subsingleton [IsLocalization.uniqueOfZeroMem (S := Aₘ) hM] replace hM : M ≤ A⁰ := fun x hx ↦ mem_nonZeroDivisors_iff_ne_zero.mpr (fun e ↦ hM (e ▸ hx)) let K := FractionRing A let L := FractionRing B have : IsIntegralClosure B A L := IsIntegralClosure.of_isIntegrallyClosed _ _ _ have : IsLocalization (algebraMapSubmonoid B A⁰) L := IsIntegralClosure.isLocalization _ (FractionRing A) _ _ let f : Aₘ →+* K := IsLocalization.map _ (T := A⁰) (RingHom.id A) hM letI := f.toAlgebra have : IsScalarTower A Aₘ K := IsScalarTower.of_algebraMap_eq' (by rw [RingHom.algebraMap_toAlgebra, IsLocalization.map_comp, RingHomCompTriple.comp_eq]) letI := IsFractionRing.isFractionRing_of_isDomain_of_isLocalization M Aₘ K let g : Bₘ →+* L := IsLocalization.map _ (M := algebraMapSubmonoid B M) (T := algebraMapSubmonoid B A⁰) (RingHom.id B) (Submonoid.monotone_map hM) letI := g.toAlgebra have : IsScalarTower B Bₘ L := IsScalarTower.of_algebraMap_eq' (by rw [RingHom.algebraMap_toAlgebra, IsLocalization.map_comp, RingHomCompTriple.comp_eq]) letI := ((algebraMap K L).comp f).toAlgebra have : IsScalarTower Aₘ K L := IsScalarTower.of_algebraMap_eq' rfl have : IsScalarTower Aₘ Bₘ L := by apply IsScalarTower.of_algebraMap_eq' apply IsLocalization.ringHom_ext M rw [RingHom.algebraMap_toAlgebra, RingHom.algebraMap_toAlgebra (R := Bₘ), RingHom.comp_assoc, RingHom.comp_assoc, ← IsScalarTower.algebraMap_eq, IsScalarTower.algebraMap_eq A B Bₘ, IsLocalization.map_comp, RingHom.comp_id, ← RingHom.comp_assoc, IsLocalization.map_comp, RingHom.comp_id, ← IsScalarTower.algebraMap_eq, ← IsScalarTower.algebraMap_eq] letI := IsFractionRing.isFractionRing_of_isDomain_of_isLocalization (algebraMapSubmonoid B M) Bₘ L have : FiniteDimensional K L := .of_isLocalization A B A⁰ have : IsIntegralClosure Bₘ Aₘ L := IsIntegralClosure.of_isIntegrallyClosed _ _ _ apply IsFractionRing.injective Aₘ K rw [← IsScalarTower.algebraMap_apply, Algebra.algebraMap_intTrace_fractionRing, Algebra.algebraMap_intTrace (L := L), ← IsScalarTower.algebraMap_apply] end trace section norm variable [IsIntegrallyClosed A] /-- The restriction of the norm on `L/K` restricted onto `B/A` in an AKLB setup. See `Algebra.intNorm` instead. -/ noncomputable def Algebra.intNormAux : B →* A where toFun := fun s ↦ IsIntegralClosure.mk' (R := A) A (Algebra.norm K (algebraMap B L s)) (isIntegral_norm K <| IsIntegral.map (IsScalarTower.toAlgHom A B L) (IsIntegralClosure.isIntegral A L s)) map_one' := by simp map_mul' := fun x y ↦ by simpa using IsIntegralClosure.mk'_mul _ _ _ _ _ variable {A K L B} omit [FiniteDimensional K L] in lemma Algebra.map_intNormAux (x : B) : algebraMap A K (Algebra.intNormAux A K L B x) = Algebra.norm K (algebraMap B L x) := by dsimp [Algebra.intNormAux] exact IsIntegralClosure.algebraMap_mk' _ _ _ variable (A B) variable [IsDomain A] [IsDomain B] [IsIntegrallyClosed B] variable [Module.Finite A B] [NoZeroSMulDivisors A B] /-- The norm of a finite extension of integrally closed domains `B/A` is the restriction of the norm on `Frac(B)/Frac(A)` onto `B/A`. See `Algebra.algebraMap_intNorm`. -/ noncomputable def Algebra.intNorm : B →* A := haveI : IsIntegralClosure B A (FractionRing B) := IsIntegralClosure.of_isIntegrallyClosed _ _ _ haveI : IsLocalization (algebraMapSubmonoid B A⁰) (FractionRing B) := IsIntegralClosure.isLocalization _ (FractionRing A) _ _ haveI : FiniteDimensional (FractionRing A) (FractionRing B) := .of_isLocalization A B A⁰ Algebra.intNormAux A (FractionRing A) (FractionRing B) B variable {A B} lemma Algebra.algebraMap_intNorm (x : B) : algebraMap A K (Algebra.intNorm A B x) = Algebra.norm K (algebraMap B L x) := by haveI : IsIntegralClosure B A (FractionRing B) := IsIntegralClosure.of_isIntegrallyClosed _ _ _ haveI : IsLocalization (algebraMapSubmonoid B A⁰) (FractionRing B) := IsIntegralClosure.isLocalization _ (FractionRing A) _ _ haveI : FiniteDimensional (FractionRing A) (FractionRing B) := .of_isLocalization A B A⁰ haveI := IsIntegralClosure.isFractionRing_of_finite_extension A K L B apply (FractionRing.algEquiv A K).symm.injective rw [AlgEquiv.commutes, Algebra.intNorm, Algebra.map_intNormAux, ← AlgEquiv.commutes (FractionRing.algEquiv B L)] apply Algebra.norm_eq_of_equiv_equiv (FractionRing.algEquiv A K).toRingEquiv (FractionRing.algEquiv B L).toRingEquiv ext exact IsFractionRing.algEquiv_commutes (FractionRing.algEquiv A K) (FractionRing.algEquiv B L) _ @[simp] lemma Algebra.algebraMap_intNorm_fractionRing (x : B) : algebraMap A (FractionRing A) (Algebra.intNorm A B x) = Algebra.norm (FractionRing A) (algebraMap B (FractionRing B) x) := by haveI : IsIntegralClosure B A (FractionRing B) := IsIntegralClosure.of_isIntegrallyClosed _ _ _ haveI : IsLocalization (algebraMapSubmonoid B A⁰) (FractionRing B) := IsIntegralClosure.isLocalization _ (FractionRing A) _ _ haveI : FiniteDimensional (FractionRing A) (FractionRing B) := .of_isLocalization A B A⁰ exact Algebra.map_intNormAux x variable (A B) theorem Algebra.intNorm_intNorm {C : Type*} [CommRing C] [IsDomain C] [IsIntegrallyClosed C] [Algebra A C] [Algebra B C] [IsScalarTower A B C] [Module.Finite A C] [Module.Finite B C] [NoZeroSMulDivisors A C] [NoZeroSMulDivisors B C] (x : C) : intNorm A B (intNorm B C x) = intNorm A C x := by apply FaithfulSMul.algebraMap_injective A (FractionRing A) rw [algebraMap_intNorm_fractionRing, algebraMap_intNorm_fractionRing, algebraMap_intNorm_fractionRing, Algebra.norm_norm] lemma Algebra.intNorm_eq_norm [Module.Free A B] : Algebra.intNorm A B = Algebra.norm A := by ext x haveI : IsIntegralClosure B A (FractionRing B) := IsIntegralClosure.of_isIntegrallyClosed _ _ _ haveI : IsLocalization (algebraMapSubmonoid B A⁰) (FractionRing B) := IsIntegralClosure.isLocalization _ (FractionRing A) _ _ apply IsFractionRing.injective A (FractionRing A) rw [Algebra.algebraMap_intNorm_fractionRing, Algebra.norm_localization A A⁰] @[simp] lemma Algebra.intNorm_zero : Algebra.intNorm A B 0 = 0 := by haveI : IsIntegralClosure B A (FractionRing B) := IsIntegralClosure.of_isIntegrallyClosed _ _ _ haveI : IsLocalization (algebraMapSubmonoid B A⁰) (FractionRing B) := IsIntegralClosure.isLocalization _ (FractionRing A) _ _ haveI : FiniteDimensional (FractionRing A) (FractionRing B) := .of_isLocalization A B A⁰ apply IsFractionRing.injective A (FractionRing A) simp variable {A B} @[simp] theorem Algebra.intNorm_map_algEquiv [IsDomain B₂] [IsIntegrallyClosed B₂] [Module.Finite A B₂] [NoZeroSMulDivisors A B₂] (x : B) (σ : B ≃ₐ[A] B₂) : Algebra.intNorm A B₂ (σ x) = Algebra.intNorm A B x := by apply FaithfulSMul.algebraMap_injective A (FractionRing A) rw [algebraMap_intNorm_fractionRing, algebraMap_intNorm_fractionRing, ← galLiftEquiv_algebraMap_apply (FractionRing A) (FractionRing B), norm_eq_of_algEquiv] @[simp] lemma Algebra.intNorm_eq_zero {x : B} : Algebra.intNorm A B x = 0 ↔ x = 0 := by haveI : IsIntegralClosure B A (FractionRing B) := IsIntegralClosure.of_isIntegrallyClosed _ _ _ haveI : IsLocalization (algebraMapSubmonoid B A⁰) (FractionRing B) := IsIntegralClosure.isLocalization _ (FractionRing A) _ _ haveI : FiniteDimensional (FractionRing A) (FractionRing B) := .of_isLocalization A B A⁰ rw [← (IsFractionRing.injective A (FractionRing A)).eq_iff, ← (IsFractionRing.injective B (FractionRing B)).eq_iff] simp only [algebraMap_intNorm_fractionRing, map_zero, norm_eq_zero_iff] lemma Algebra.intNorm_ne_zero {x : B} : Algebra.intNorm A B x ≠ 0 ↔ x ≠ 0 := by simp variable [IsDomain Aₘ] [IsIntegrallyClosed Aₘ] [IsDomain Bₘ] [IsIntegrallyClosed Bₘ] variable [NoZeroSMulDivisors Aₘ Bₘ] [Module.Finite Aₘ Bₘ] include M in lemma Algebra.intNorm_eq_of_isLocalization (x : B) : algebraMap A Aₘ (Algebra.intNorm A B x) = Algebra.intNorm Aₘ Bₘ (algebraMap B Bₘ x) := by by_cases hM : 0 ∈ M · subsingleton [IsLocalization.uniqueOfZeroMem (S := Aₘ) hM] replace hM : M ≤ A⁰ := fun x hx ↦ mem_nonZeroDivisors_iff_ne_zero.mpr (fun e ↦ hM (e ▸ hx)) let K := FractionRing A let L := FractionRing B have : IsIntegralClosure B A L := IsIntegralClosure.of_isIntegrallyClosed _ _ _ have : IsLocalization (algebraMapSubmonoid B A⁰) L := IsIntegralClosure.isLocalization _ (FractionRing A) _ _ let f : Aₘ →+* K := IsLocalization.map _ (T := A⁰) (RingHom.id A) hM letI := f.toAlgebra have : IsScalarTower A Aₘ K := IsScalarTower.of_algebraMap_eq' (by rw [RingHom.algebraMap_toAlgebra, IsLocalization.map_comp, RingHomCompTriple.comp_eq]) letI := IsFractionRing.isFractionRing_of_isDomain_of_isLocalization M Aₘ K let g : Bₘ →+* L := IsLocalization.map _ (M := algebraMapSubmonoid B M) (T := algebraMapSubmonoid B A⁰) (RingHom.id B) (Submonoid.monotone_map hM) letI := g.toAlgebra have : IsScalarTower B Bₘ L := IsScalarTower.of_algebraMap_eq' (by rw [RingHom.algebraMap_toAlgebra, IsLocalization.map_comp, RingHomCompTriple.comp_eq]) letI := ((algebraMap K L).comp f).toAlgebra have : IsScalarTower Aₘ K L := IsScalarTower.of_algebraMap_eq' rfl have : IsScalarTower Aₘ Bₘ L := by apply IsScalarTower.of_algebraMap_eq' apply IsLocalization.ringHom_ext M rw [RingHom.algebraMap_toAlgebra, RingHom.algebraMap_toAlgebra (R := Bₘ), RingHom.comp_assoc, RingHom.comp_assoc, ← IsScalarTower.algebraMap_eq, IsScalarTower.algebraMap_eq A B Bₘ, IsLocalization.map_comp, RingHom.comp_id, ← RingHom.comp_assoc, IsLocalization.map_comp, RingHom.comp_id, ← IsScalarTower.algebraMap_eq, ← IsScalarTower.algebraMap_eq] letI := IsFractionRing.isFractionRing_of_isDomain_of_isLocalization (algebraMapSubmonoid B M) Bₘ L have : FiniteDimensional K L := .of_isLocalization A B A⁰ have : IsIntegralClosure Bₘ Aₘ L := IsIntegralClosure.of_isIntegrallyClosed _ _ _ apply IsFractionRing.injective Aₘ K rw [← IsScalarTower.algebraMap_apply, Algebra.algebraMap_intNorm_fractionRing, Algebra.algebraMap_intNorm (L := L), ← IsScalarTower.algebraMap_apply] end norm variable [IsDomain A] [IsIntegrallyClosed A] [IsDomain B] [IsIntegrallyClosed B] [Module.Finite A B] [NoZeroSMulDivisors A B] lemma Algebra.algebraMap_intNorm_of_isGalois [IsGalois (FractionRing A) (FractionRing B)] {x : B} : algebraMap A B (Algebra.intNorm A B x) = ∏ σ : B ≃ₐ[A] B, σ x := by haveI : IsIntegralClosure B A (FractionRing B) := IsIntegralClosure.of_isIntegrallyClosed _ _ _ haveI : IsLocalization (Algebra.algebraMapSubmonoid B A⁰) (FractionRing B) := IsIntegralClosure.isLocalization _ (FractionRing A) _ _ haveI : FiniteDimensional (FractionRing A) (FractionRing B) := .of_isLocalization A B A⁰ rw [← (galRestrict A (FractionRing A) (FractionRing B) B).toEquiv.prod_comp] simp only [MulEquiv.toEquiv_eq_coe, EquivLike.coe_coe] convert (prod_galRestrict_eq_norm A (FractionRing A) (FractionRing B) B x).symm open Polynomial IsScalarTower in theorem Algebra.dvd_algebraMap_intNorm_self (x : B) : x ∣ algebraMap A B (intNorm A B x) := by classical by_cases hx : x = 0 · exact ⟨1, by simp [hx]⟩ let K := FractionRing A let L := FractionRing B let E := AlgebraicClosure L suffices IsIntegral A ((algebraMap B L x)⁻¹ * (algebraMap A L (intNorm A B x))) by obtain ⟨y, hy⟩ := IsIntegrallyClosed.isIntegral_iff.mp <| _root_.IsIntegral.tower_top (A := B) this refine ⟨y, ?_⟩ apply FaithfulSMul.algebraMap_injective B L rw [← algebraMap_apply, map_mul, hy, mul_inv_cancel_left₀] exact (map_ne_zero_iff _ (FaithfulSMul.algebraMap_injective B L)).mpr hx rw [← isIntegral_algHom_iff (toAlgHom A L E) (FaithfulSMul.algebraMap_injective L E), coe_toAlgHom', map_mul, map_inv₀, algebraMap_apply A K L, algebraMap_intNorm (L := L), ← algebraMap_apply, ← algebraMap_apply, norm_eq_prod_roots _ (IsAlgClosed.splits_codomain _), ← Multiset.prod_erase (a := algebraMap B E x)] · have := NoZeroSMulDivisors.trans_faithfulSMul B L E rw [mul_pow, ← mul_pow_sub_one (Nat.pos_iff_ne_zero.1 Module.finrank_pos) (algebraMap B E x), mul_assoc, inv_mul_cancel_left₀] · refine IsIntegral.mul (IsIntegral.pow ?_ _) (IsIntegral.pow (IsIntegral.multiset_prod (fun a ha ↦ ⟨minpoly A x, minpoly.monic (IsIntegral.isIntegral x), ?_⟩)) _) · exact (isIntegral_algebraMap_iff (NoZeroSMulDivisors.iff_algebraMap_injective.1 this)).mpr (IsIntegral.isIntegral x) · replace ha := Multiset.erase_subset _ _ ha suffices (aeval a) ((minpoly A x).map (algebraMap A K)) = 0 by simpa rw [← minpoly.isIntegrallyClosed_eq_field_fractions K L (IsIntegral.isIntegral x)] simp only [mem_roots', ne_eq, Polynomial.map_eq_zero, IsRoot.def, eval_map_algebraMap] at ha exact ha.2 · exact (map_ne_zero_iff _ (FaithfulSMul.algebraMap_injective B E)).mpr hx · simp only [mem_roots', ne_eq, Polynomial.map_eq_zero, IsRoot.def, eval_map_algebraMap] refine ⟨minpoly.ne_zero (IsIntegral.isIntegral _), ?_⟩ simp [algebraMap_apply B L E, aeval_algebraMap_apply]
.lake/packages/mathlib/Mathlib/RingTheory/IntegralClosure/IsIntegralClosure/Basic.lean
import Mathlib.Algebra.Polynomial.Roots import Mathlib.RingTheory.FiniteType import Mathlib.RingTheory.IntegralClosure.Algebra.Basic import Mathlib.RingTheory.IntegralClosure.IsIntegralClosure.Defs import Mathlib.RingTheory.Polynomial.IntegralNormalization import Mathlib.RingTheory.Polynomial.ScaleRoots import Mathlib.RingTheory.TensorProduct.MvPolynomial /-! # # Integral closure as a characteristic predicate We prove basic properties of `IsIntegralClosure`. -/ open Polynomial Submodule section inv open Algebra variable {R S : Type*} /-- A nonzero element in a domain integral over a field is a unit. -/ theorem IsIntegral.isUnit [Field R] [Ring S] [IsDomain S] [Algebra R S] {x : S} (int : IsIntegral R x) (h0 : x ≠ 0) : IsUnit x := have : FiniteDimensional R (adjoin R {x}) := ⟨(Submodule.fg_top _).mpr int.fg_adjoin_singleton⟩ (FiniteDimensional.isUnit R (K := adjoin R {x}) (x := ⟨x, subset_adjoin rfl⟩) <| mt Subtype.ext_iff.mp h0).map (adjoin R {x}).val /-- A commutative domain that is an integral algebra over a field is a field. -/ theorem isField_of_isIntegral_of_isField' [CommRing R] [CommRing S] [IsDomain S] [Algebra R S] [Algebra.IsIntegral R S] (hR : IsField R) : IsField S where exists_pair_ne := ⟨0, 1, zero_ne_one⟩ mul_comm := mul_comm mul_inv_cancel {x} hx := by letI := hR.toField obtain ⟨y, rfl⟩ := (Algebra.IsIntegral.isIntegral (R := R) x).isUnit hx exact ⟨y.inv, y.val_inv⟩ variable [Field R] [DivisionRing S] [Algebra R S] {x : S} {A : Subalgebra R S} theorem IsIntegral.inv_mem_adjoin (int : IsIntegral R x) : x⁻¹ ∈ adjoin R {x} := by obtain rfl | h0 := eq_or_ne x 0 · rw [inv_zero]; exact Subalgebra.zero_mem _ have : FiniteDimensional R (adjoin R {x}) := ⟨(Submodule.fg_top _).mpr int.fg_adjoin_singleton⟩ obtain ⟨⟨y, hy⟩, h1⟩ := FiniteDimensional.exists_mul_eq_one R (K := adjoin R {x}) (x := ⟨x, subset_adjoin rfl⟩) (mt Subtype.ext_iff.mp h0) rwa [← mul_left_cancel₀ h0 ((Subtype.ext_iff.mp h1).trans (mul_inv_cancel₀ h0).symm)] /-- The inverse of an integral element in a subalgebra of a division ring over a field also lies in that subalgebra. -/ theorem IsIntegral.inv_mem (int : IsIntegral R x) (hx : x ∈ A) : x⁻¹ ∈ A := adjoin_le (Set.singleton_subset_iff.mpr hx) int.inv_mem_adjoin /-- An integral subalgebra of a division ring over a field is closed under inverses. -/ theorem Algebra.IsIntegral.inv_mem [Algebra.IsIntegral R A] (hx : x ∈ A) : x⁻¹ ∈ A := ((isIntegral_algHom_iff A.val Subtype.val_injective).mpr <| Algebra.IsIntegral.isIntegral (⟨x, hx⟩ : A)).inv_mem hx /-- The inverse of an integral element in a division ring over a field is also integral. -/ theorem IsIntegral.inv (int : IsIntegral R x) : IsIntegral R x⁻¹ := .of_mem_of_fg _ int.fg_adjoin_singleton _ int.inv_mem_adjoin theorem IsIntegral.mem_of_inv_mem (int : IsIntegral R x) (inv_mem : x⁻¹ ∈ A) : x ∈ A := by rw [← inv_inv x]; exact int.inv.inv_mem inv_mem end inv section variable {R A B S : Type*} variable [CommRing R] [CommRing A] [Ring B] [CommRing S] variable [Algebra R A] [Algebra R B] {f : R →+* S} /-- The [Kurosh problem](https://en.wikipedia.org/wiki/Kurosh_problem) asks to show that this is still true when `A` is not necessarily commutative and `R` is a field, but it has been solved in the negative. See https://arxiv.org/pdf/1706.02383.pdf for criteria for a finitely generated algebraic (= integral) algebra over a field to be finite dimensional. This could be an `instance`, but we tend to go from `Module.Finite` to `IsIntegral`/`IsAlgebraic`, and making it an instance will cause the search to be complicated a lot. -/ theorem Algebra.IsIntegral.finite [Algebra.IsIntegral R A] [h' : Algebra.FiniteType R A] : Module.Finite R A := have ⟨s, hs⟩ := h' ⟨by apply hs ▸ fg_adjoin_of_finite s.finite_toSet fun x _ ↦ Algebra.IsIntegral.isIntegral x⟩ /-- finite = integral + finite type -/ theorem Algebra.finite_iff_isIntegral_and_finiteType : Module.Finite R A ↔ Algebra.IsIntegral R A ∧ Algebra.FiniteType R A := ⟨fun _ ↦ ⟨⟨.of_finite R⟩, inferInstance⟩, fun ⟨h, _⟩ ↦ h.finite⟩ theorem RingHom.IsIntegral.to_finite (h : f.IsIntegral) (h' : f.FiniteType) : f.Finite := let _ := f.toAlgebra let _ : Algebra.IsIntegral R S := ⟨h⟩ Algebra.IsIntegral.finite (h' := h') alias RingHom.Finite.of_isIntegral_of_finiteType := RingHom.IsIntegral.to_finite /-- finite = integral + finite type -/ theorem RingHom.finite_iff_isIntegral_and_finiteType : f.Finite ↔ f.IsIntegral ∧ f.FiniteType := ⟨fun h ↦ ⟨h.to_isIntegral, h.to_finiteType⟩, fun ⟨h, h'⟩ ↦ h.to_finite h'⟩ variable (f : R →+* S) (R A) theorem mem_integralClosure_iff_mem_fg {r : A} : r ∈ integralClosure R A ↔ ∃ M : Subalgebra R A, M.toSubmodule.FG ∧ r ∈ M := ⟨fun hr => ⟨Algebra.adjoin R {r}, hr.fg_adjoin_singleton, Algebra.subset_adjoin rfl⟩, fun ⟨M, Hf, hrM⟩ => .of_mem_of_fg M Hf _ hrM⟩ variable {R A} theorem adjoin_le_integralClosure {x : A} (hx : IsIntegral R x) : Algebra.adjoin R {x} ≤ integralClosure R A := by rw [Algebra.adjoin_le_iff] simp only [SetLike.mem_coe, Set.singleton_subset_iff] exact hx theorem le_integralClosure_iff_isIntegral {S : Subalgebra R A} : S ≤ integralClosure R A ↔ Algebra.IsIntegral R S := SetLike.forall.symm.trans <| (forall_congr' fun x => show IsIntegral R (algebraMap S A x) ↔ IsIntegral R x from isIntegral_algebraMap_iff Subtype.coe_injective).trans Algebra.isIntegral_def.symm theorem Algebra.IsIntegral.adjoin {S : Set A} (hS : ∀ x ∈ S, IsIntegral R x) : Algebra.IsIntegral R (adjoin R S) := le_integralClosure_iff_isIntegral.mp <| adjoin_le hS theorem integralClosure_eq_top_iff : integralClosure R A = ⊤ ↔ Algebra.IsIntegral R A := by rw [← top_le_iff, le_integralClosure_iff_isIntegral, (Subalgebra.topEquiv (R := R) (A := A)).isIntegral_iff] -- explicit arguments for speedup theorem Algebra.isIntegral_sup {S T : Subalgebra R A} : Algebra.IsIntegral R (S ⊔ T : Subalgebra R A) ↔ Algebra.IsIntegral R S ∧ Algebra.IsIntegral R T := by simp_rw [← le_integralClosure_iff_isIntegral, sup_le_iff] theorem Algebra.isIntegral_iSup {ι} (S : ι → Subalgebra R A) : Algebra.IsIntegral R ↑(iSup S) ↔ ∀ i, Algebra.IsIntegral R (S i) := by simp_rw [← le_integralClosure_iff_isIntegral, iSup_le_iff] /-- Mapping an integral closure along an `AlgEquiv` gives the integral closure. -/ theorem integralClosure_map_algEquiv [Algebra R S] (f : A ≃ₐ[R] S) : (integralClosure R A).map (f : A →ₐ[R] S) = integralClosure R S := by ext y rw [Subalgebra.mem_map] constructor · rintro ⟨x, hx, rfl⟩ exact hx.map f · intro hy use f.symm y, hy.map (f.symm : S →ₐ[R] A) simp /-- An `AlgHom` between two rings restrict to an `AlgHom` between the integral closures inside them. -/ def AlgHom.mapIntegralClosure [Algebra R S] (f : A →ₐ[R] S) : integralClosure R A →ₐ[R] integralClosure R S := (f.restrictDomain (integralClosure R A)).codRestrict (integralClosure R S) (fun ⟨_, h⟩ => h.map f) @[simp] theorem AlgHom.coe_mapIntegralClosure [Algebra R S] (f : A →ₐ[R] S) (x : integralClosure R A) : (f.mapIntegralClosure x : S) = f (x : A) := rfl /-- An `AlgEquiv` between two rings restrict to an `AlgEquiv` between the integral closures inside them. -/ def AlgEquiv.mapIntegralClosure [Algebra R S] (f : A ≃ₐ[R] S) : integralClosure R A ≃ₐ[R] integralClosure R S := AlgEquiv.ofAlgHom (f : A →ₐ[R] S).mapIntegralClosure (f.symm : S →ₐ[R] A).mapIntegralClosure (AlgHom.ext fun _ ↦ Subtype.ext (f.right_inv _)) (AlgHom.ext fun _ ↦ Subtype.ext (f.left_inv _)) @[simp] theorem AlgEquiv.coe_mapIntegralClosure [Algebra R S] (f : A ≃ₐ[R] S) (x : integralClosure R A) : (f.mapIntegralClosure x : S) = f (x : A) := rfl theorem integralClosure.isIntegral (x : integralClosure R A) : IsIntegral R x := let ⟨p, hpm, hpx⟩ := x.2 ⟨p, hpm, Subtype.eq <| by rwa [← aeval_def, ← Subalgebra.val_apply, aeval_algHom_apply] at hpx⟩ instance integralClosure.AlgebraIsIntegral : Algebra.IsIntegral R (integralClosure R A) := ⟨integralClosure.isIntegral⟩ theorem IsIntegral.of_mul_unit {x y : B} {r : R} (hr : algebraMap R B r * y = 1) (hx : IsIntegral R (x * y)) : IsIntegral R x := by obtain ⟨p, p_monic, hp⟩ := hx refine ⟨scaleRoots p r, (monic_scaleRoots_iff r).2 p_monic, ?_⟩ convert scaleRoots_aeval_eq_zero hp rw [Algebra.commutes] at hr ⊢ rw [mul_assoc, hr, mul_one]; rfl theorem RingHom.IsIntegralElem.of_mul_unit (x y : S) (r : R) (hr : f r * y = 1) (hx : f.IsIntegralElem (x * y)) : f.IsIntegralElem x := letI : Algebra R S := f.toAlgebra IsIntegral.of_mul_unit hr hx /-- Generalization of `IsIntegral.of_mem_closure` bootstrapped up from that lemma -/ theorem IsIntegral.of_mem_closure' (G : Set A) (hG : ∀ x ∈ G, IsIntegral R x) : ∀ x ∈ Subring.closure G, IsIntegral R x := fun _ hx ↦ Subring.closure_induction hG isIntegral_zero isIntegral_one (fun _ _ _ _ ↦ IsIntegral.add) (fun _ _ ↦ IsIntegral.neg) (fun _ _ _ _ ↦ IsIntegral.mul) hx theorem IsIntegral.of_mem_closure'' {S : Type*} [CommRing S] {f : R →+* S} (G : Set S) (hG : ∀ x ∈ G, f.IsIntegralElem x) : ∀ x ∈ Subring.closure G, f.IsIntegralElem x := fun x hx => @IsIntegral.of_mem_closure' R S _ _ f.toAlgebra G hG x hx theorem IsIntegral.pow {x : B} (h : IsIntegral R x) (n : ℕ) : IsIntegral R (x ^ n) := .of_mem_of_fg _ h.fg_adjoin_singleton _ <| Subalgebra.pow_mem _ (by exact Algebra.subset_adjoin rfl) _ theorem IsIntegral.nsmul {x : B} (h : IsIntegral R x) (n : ℕ) : IsIntegral R (n • x) := h.smul n theorem IsIntegral.zsmul {x : B} (h : IsIntegral R x) (n : ℤ) : IsIntegral R (n • x) := h.smul n theorem IsIntegral.multiset_prod {s : Multiset A} (h : ∀ x ∈ s, IsIntegral R x) : IsIntegral R s.prod := (integralClosure R A).multiset_prod_mem h theorem IsIntegral.multiset_sum {s : Multiset A} (h : ∀ x ∈ s, IsIntegral R x) : IsIntegral R s.sum := (integralClosure R A).multiset_sum_mem h theorem IsIntegral.prod {α : Type*} {s : Finset α} (f : α → A) (h : ∀ x ∈ s, IsIntegral R (f x)) : IsIntegral R (∏ x ∈ s, f x) := (integralClosure R A).prod_mem h theorem IsIntegral.sum {α : Type*} {s : Finset α} (f : α → A) (h : ∀ x ∈ s, IsIntegral R (f x)) : IsIntegral R (∑ x ∈ s, f x) := (integralClosure R A).sum_mem h theorem IsIntegral.det {n : Type*} [Fintype n] [DecidableEq n] {M : Matrix n n A} (h : ∀ i j, IsIntegral R (M i j)) : IsIntegral R M.det := by rw [Matrix.det_apply] exact IsIntegral.sum _ fun σ _hσ ↦ (IsIntegral.prod _ fun i _hi => h _ _).zsmul _ @[simp] theorem IsIntegral.pow_iff {x : A} {n : ℕ} (hn : 0 < n) : IsIntegral R (x ^ n) ↔ IsIntegral R x := ⟨IsIntegral.of_pow hn, fun hx ↦ hx.pow n⟩ section Pushout variable (R S A) [Algebra R S] [int : Algebra.IsIntegral R S] variable (SA : Type*) [CommRing SA] [Algebra R SA] [Algebra S SA] [Algebra A SA] [IsScalarTower R S SA] [IsScalarTower R A SA] theorem Algebra.IsPushout.isIntegral' [IsPushout R A S SA] : Algebra.IsIntegral A SA := (equiv R A S SA).isIntegral_iff.mp inferInstance theorem Algebra.IsPushout.isIntegral [h : IsPushout R S A SA] : Algebra.IsIntegral A SA := h.symm.isIntegral' attribute [local instance] Polynomial.algebra in instance : Algebra.IsIntegral R[X] S[X] := Algebra.IsPushout.isIntegral R _ S _ attribute [local instance] MvPolynomial.algebraMvPolynomial in instance {σ} : Algebra.IsIntegral (MvPolynomial σ R) (MvPolynomial σ S) := Algebra.IsPushout.isIntegral R _ S _ end Pushout section variable (p : R[X]) (x : S) /-- Given a `p : R[X]` and a `x : S` such that `p.eval₂ f x = 0`, `f p.leadingCoeff * x` is integral. -/ theorem RingHom.isIntegralElem_leadingCoeff_mul (h : p.eval₂ f x = 0) : f.IsIntegralElem (f p.leadingCoeff * x) := by by_cases h' : 1 ≤ p.natDegree · use integralNormalization p have : p ≠ 0 := fun h'' => by rw [h'', natDegree_zero] at h' exact Nat.not_succ_le_zero 0 h' use monic_integralNormalization this rw [integralNormalization_eval₂_leadingCoeff_mul h' f x, h, mul_zero] · by_cases hp : p.map f = 0 · apply_fun fun q => coeff q p.natDegree at hp rw [coeff_map, coeff_zero, coeff_natDegree] at hp rw [hp, zero_mul] exact f.isIntegralElem_zero · rw [Nat.one_le_iff_ne_zero, Classical.not_not] at h' rw [eq_C_of_natDegree_eq_zero h', eval₂_C] at h suffices p.map f = 0 by exact (hp this).elim rw [eq_C_of_natDegree_eq_zero h', map_C, h, C_eq_zero] /-- Given a `p : R[X]` and a root `x : S`, then `p.leadingCoeff • x : S` is integral over `R`. -/ theorem isIntegral_leadingCoeff_smul [Algebra R S] (h : aeval x p = 0) : IsIntegral R (p.leadingCoeff • x) := by rw [aeval_def] at h rw [Algebra.smul_def] exact (algebraMap R S).isIntegralElem_leadingCoeff_mul p x h end lemma Polynomial.Monic.quotient_isIntegralElem {g : S[X]} (mon : g.Monic) {I : Ideal S[X]} (h : g ∈ I) : ((Ideal.Quotient.mk I).comp (algebraMap S S[X])).IsIntegralElem (Ideal.Quotient.mk I X) := by exact ⟨g, mon, by rw [← (Ideal.Quotient.eq_zero_iff_mem.mpr h), eval₂_eq_sum_range] nth_rw 3 [(as_sum_range_C_mul_X_pow g)] simp only [map_sum, algebraMap_eq, RingHom.coe_comp, Function.comp_apply, map_mul, map_pow]⟩ /- If `I` is an ideal of the polynomial ring `S[X]` and contains a monic polynomial `f`, then `S[X]/I` is integral over `S`. -/ lemma Polynomial.Monic.quotient_isIntegral {g : S[X]} (mon : g.Monic) {I : Ideal S[X]} (h : g ∈ I) : ((Ideal.Quotient.mkₐ S I).comp (Algebra.ofId S S[X])).IsIntegral := by have eq_top : Algebra.adjoin S {(Ideal.Quotient.mkₐ S I) X} = ⊤ := by ext g constructor · simp only [Algebra.mem_top, implies_true] · intro _ obtain ⟨g', hg⟩ := Ideal.Quotient.mkₐ_surjective S I g have : g = (Polynomial.aeval ((Ideal.Quotient.mkₐ S I) X)) g' := by nth_rw 1 [← hg, aeval_eq_sum_range' (lt_add_one _), as_sum_range_C_mul_X_pow g', map_sum] simp only [Polynomial.C_mul', ← map_pow, map_smul] exact this ▸ (aeval_mem_adjoin_singleton S ((Ideal.Quotient.mk I) Polynomial.X)) exact fun a ↦ (eq_top ▸ adjoin_le_integralClosure <| mon.quotient_isIntegralElem h) Algebra.mem_top end section IsIntegralClosure instance integralClosure.isIntegralClosure (R A : Type*) [CommRing R] [CommRing A] [Algebra R A] : IsIntegralClosure (integralClosure R A) R A where algebraMap_injective := Subtype.coe_injective isIntegral_iff {x} := ⟨fun h => ⟨⟨x, h⟩, rfl⟩, by rintro ⟨⟨_, h⟩, rfl⟩; exact h⟩ namespace IsIntegralClosure variable {R A B : Type*} [CommRing R] [CommRing A] [CommRing B] variable [Algebra R B] [Algebra A B] [IsIntegralClosure A R B] variable (R B) protected theorem isIntegral [Algebra R A] [IsScalarTower R A B] (x : A) : IsIntegral R x := (isIntegral_algebraMap_iff (algebraMap_injective A R B)).mp <| show IsIntegral R (algebraMap A B x) from isIntegral_iff.mpr ⟨x, rfl⟩ theorem isIntegral_algebra [Algebra R A] [IsScalarTower R A B] : Algebra.IsIntegral R A := ⟨fun x => IsIntegralClosure.isIntegral R B x⟩ theorem noZeroSMulDivisors [SMul R A] [IsScalarTower R A B] [NoZeroSMulDivisors R B] : NoZeroSMulDivisors R A := by refine Function.Injective.noZeroSMulDivisors _ (IsIntegralClosure.algebraMap_injective A R B) (map_zero _) fun _ _ => ?_ simp only [Algebra.algebraMap_eq_smul_one, IsScalarTower.smul_assoc] variable {R} (A) {B} /-- If `x : B` is integral over `R`, then it is an element of the integral closure of `R` in `B`. -/ noncomputable def mk' (x : B) (hx : IsIntegral R x) : A := Classical.choose (isIntegral_iff.mp hx) @[simp] theorem algebraMap_mk' (x : B) (hx : IsIntegral R x) : algebraMap A B (mk' A x hx) = x := Classical.choose_spec (isIntegral_iff.mp hx) @[simp] theorem mk'_one (h : IsIntegral R (1 : B) := isIntegral_one) : mk' A 1 h = 1 := algebraMap_injective A R B <| by rw [algebraMap_mk', RingHom.map_one] @[simp] theorem mk'_zero (h : IsIntegral R (0 : B) := isIntegral_zero) : mk' A 0 h = 0 := algebraMap_injective A R B <| by rw [algebraMap_mk', RingHom.map_zero] @[simp] theorem mk'_add (x y : B) (hx : IsIntegral R x) (hy : IsIntegral R y) : mk' A (x + y) (hx.add hy) = mk' A x hx + mk' A y hy := algebraMap_injective A R B <| by simp only [algebraMap_mk', RingHom.map_add] @[simp] theorem mk'_mul (x y : B) (hx : IsIntegral R x) (hy : IsIntegral R y) : mk' A (x * y) (hx.mul hy) = mk' A x hx * mk' A y hy := algebraMap_injective A R B <| by simp only [algebraMap_mk', RingHom.map_mul] @[simp] theorem mk'_algebraMap [Algebra R A] [IsScalarTower R A B] (x : R) (h : IsIntegral R (algebraMap R B x) := isIntegral_algebraMap) : IsIntegralClosure.mk' A (algebraMap R B x) h = algebraMap R A x := algebraMap_injective A R B <| by rw [algebraMap_mk', ← IsScalarTower.algebraMap_apply] /-- The integral closure of a field in a commutative domain is always a field. -/ theorem isField [Algebra R A] [IsScalarTower R A B] [IsDomain A] (hR : IsField R) : IsField A := have := IsIntegralClosure.isIntegral_algebra R (A := A) B isField_of_isIntegral_of_isField' hR section lift variable (B) {S : Type*} [CommRing S] [Algebra R S] -- split from above, since otherwise it does not synthesize `Semiring S` variable [Algebra S B] [IsScalarTower R S B] variable [Algebra R A] [IsScalarTower R A B] [isIntegral : Algebra.IsIntegral R S] variable (R) /-- If `B / S / R` is a tower of ring extensions where `S` is integral over `R`, then `S` maps (uniquely) into an integral closure `B / A / R`. -/ noncomputable def lift : S →ₐ[R] A where toFun x := mk' A (algebraMap S B x) (IsIntegral.algebraMap (Algebra.IsIntegral.isIntegral (R := R) x)) map_one' := by simp only [RingHom.map_one, mk'_one] map_zero' := by simp only [RingHom.map_zero, mk'_zero] map_add' x y := by simp_rw [← mk'_add, map_add] map_mul' x y := by simp_rw [← mk'_mul, RingHom.map_mul] commutes' x := by simp_rw [← IsScalarTower.algebraMap_apply, mk'_algebraMap] @[simp] theorem algebraMap_lift (x : S) : algebraMap A B (lift R A B x) = algebraMap S B x := algebraMap_mk' A (algebraMap S B x) (IsIntegral.algebraMap (Algebra.IsIntegral.isIntegral (R := R) x)) end lift section Equiv variable (R B) (A' : Type*) [CommRing A'] variable [Algebra A' B] [IsIntegralClosure A' R B] variable [Algebra R A] [Algebra R A'] [IsScalarTower R A B] [IsScalarTower R A' B] /-- Integral closures are all isomorphic to each other. -/ noncomputable def equiv : A ≃ₐ[R] A' := AlgEquiv.ofAlgHom (lift R A' B (isIntegral := isIntegral_algebra R B)) (lift R A B (isIntegral := isIntegral_algebra R B)) (by ext x; apply algebraMap_injective A' R B; simp) (by ext x; apply algebraMap_injective A R B; simp) @[simp] theorem algebraMap_equiv (x : A) : algebraMap A' B (equiv R A B A' x) = algebraMap A B x := algebraMap_lift R A' B (isIntegral := isIntegral_algebra R B) x end Equiv end IsIntegralClosure end IsIntegralClosure section Algebra open Algebra variable {R A B S T : Type*} variable [CommRing R] [CommRing A] [Ring B] [CommRing S] [CommRing T] variable [Algebra A B] [Algebra R B] (f : R →+* S) (g : S →+* T) variable [Algebra R A] [IsScalarTower R A B] /-- If A is an R-algebra all of whose elements are integral over R, and x is an element of an A-algebra that is integral over A, then x is integral over R. -/ theorem isIntegral_trans [Algebra.IsIntegral R A] (x : B) (hx : IsIntegral A x) : IsIntegral R x := by rcases hx with ⟨p, pmonic, hp⟩ let S := adjoin R (p.coeffs : Set A) have : Module.Finite R S := ⟨(Subalgebra.toSubmodule S).fg_top.mpr <| fg_adjoin_of_finite p.coeffs.finite_toSet fun a _ ↦ Algebra.IsIntegral.isIntegral a⟩ let p' : S[X] := p.toSubring S.toSubring subset_adjoin have hSx : IsIntegral S x := ⟨p', (p.monic_toSubring _ _).mpr pmonic, by rw [IsScalarTower.algebraMap_eq S A B, ← eval₂_map] convert hp; apply p.map_toSubring S.toSubring⟩ let Sx := Subalgebra.toSubmodule (adjoin S {x}) let MSx : Module S Sx := SMulMemClass.toModule _ -- the next line times out without this have : Module.Finite S Sx := ⟨(Submodule.fg_top _).mpr hSx.fg_adjoin_singleton⟩ refine .of_mem_of_fg ((adjoin S {x}).restrictScalars R) ?_ _ ((Subalgebra.mem_restrictScalars R).mpr <| subset_adjoin rfl) rw [← Submodule.fg_top, ← Module.finite_def] letI : SMul S Sx := { MSx with } -- need this even though MSx is there have : IsScalarTower R S Sx := Submodule.isScalarTower Sx -- Lean looks for `Module A Sx` without this exact Module.Finite.trans S Sx variable (A) in /-- If A is an R-algebra all of whose elements are integral over R, and B is an A-algebra all of whose elements are integral over A, then all elements of B are integral over R. -/ protected theorem Algebra.IsIntegral.trans [Algebra.IsIntegral R A] [Algebra.IsIntegral A B] : Algebra.IsIntegral R B := ⟨fun x ↦ isIntegral_trans x (Algebra.IsIntegral.isIntegral (R := A) x)⟩ protected theorem RingHom.IsIntegral.trans (hf : f.IsIntegral) (hg : g.IsIntegral) : (g.comp f).IsIntegral := let _ := f.toAlgebra; let _ := g.toAlgebra; let _ := (g.comp f).toAlgebra have : IsScalarTower R S T := IsScalarTower.of_algebraMap_eq fun _ ↦ rfl have : Algebra.IsIntegral R S := ⟨hf⟩ have : Algebra.IsIntegral S T := ⟨hg⟩ have : Algebra.IsIntegral R T := Algebra.IsIntegral.trans S Algebra.IsIntegral.isIntegral /-- If `R → A → B` is an algebra tower, `C` is the integral closure of `R` in `B` and `A` is integral over `R`, then `C` is the integral closure of `A` in `B`. -/ lemma IsIntegralClosure.tower_top {B C : Type*} [CommSemiring C] [CommRing B] [Algebra R B] [Algebra A B] [Algebra C B] [IsScalarTower R A B] [IsIntegralClosure C R B] [Algebra.IsIntegral R A] : IsIntegralClosure C A B := ⟨IsIntegralClosure.algebraMap_injective _ R _, fun hx => (IsIntegralClosure.isIntegral_iff).mp (isIntegral_trans (R := R) _ hx), fun hx => ((IsIntegralClosure.isIntegral_iff (R := R)).mpr hx).tower_top⟩ theorem RingHom.isIntegral_of_surjective (hf : Function.Surjective f) : f.IsIntegral := fun x ↦ (hf x).recOn fun _y hy ↦ hy ▸ f.isIntegralElem_map /-- If `R → A → B` is an algebra tower with `A → B` injective, then if the entire tower is an integral extension so is `R → A` -/ theorem IsIntegral.tower_bot (H : Function.Injective (algebraMap A B)) {x : A} (h : IsIntegral R (algebraMap A B x)) : IsIntegral R x := (isIntegral_algHom_iff (IsScalarTower.toAlgHom R A B) H).mp h nonrec theorem RingHom.IsIntegral.tower_bot (hg : Function.Injective g) (hfg : (g.comp f).IsIntegral) : f.IsIntegral := letI := f.toAlgebra; letI := g.toAlgebra; letI := (g.comp f).toAlgebra haveI : IsScalarTower R S T := IsScalarTower.of_algebraMap_eq fun _ ↦ rfl fun x ↦ IsIntegral.tower_bot hg (hfg (g x)) variable (T) in /-- Let `T / S / R` be a tower of algebras, `T` is non-trivial and is a torsion free `S`-module, then if `T` is an integral `R`-algebra, then `S` is an integral `R`-algebra. -/ theorem Algebra.IsIntegral.tower_bot [Algebra R S] [Algebra R T] [Algebra S T] [NoZeroSMulDivisors S T] [Nontrivial T] [IsScalarTower R S T] [h : Algebra.IsIntegral R T] : Algebra.IsIntegral R S where isIntegral := by apply RingHom.IsIntegral.tower_bot (algebraMap R S) (algebraMap S T) (FaithfulSMul.algebraMap_injective S T) rw [← IsScalarTower.algebraMap_eq R S T] exact h.isIntegral theorem IsIntegral.tower_bot_of_field {R A B : Type*} [CommRing R] [Field A] [Ring B] [Nontrivial B] [Algebra R A] [Algebra A B] [Algebra R B] [IsScalarTower R A B] {x : A} (h : IsIntegral R (algebraMap A B x)) : IsIntegral R x := h.tower_bot (algebraMap A B).injective theorem RingHom.isIntegralElem.of_comp {x : T} (h : (g.comp f).IsIntegralElem x) : g.IsIntegralElem x := let ⟨p, hp, hp'⟩ := h ⟨p.map f, hp.map f, by rwa [← eval₂_map] at hp'⟩ theorem RingHom.IsIntegral.tower_top (h : (g.comp f).IsIntegral) : g.IsIntegral := fun x ↦ RingHom.isIntegralElem.of_comp f g (h x) variable (R) in /-- Let `T / S / R` be a tower of algebras, `T` is an integral `R`-algebra, then it is integral as an `S`-algebra. -/ theorem Algebra.IsIntegral.tower_top [Algebra R S] [Algebra R T] [Algebra S T] [IsScalarTower R S T] [h : Algebra.IsIntegral R T] : Algebra.IsIntegral S T where isIntegral := by apply RingHom.IsIntegral.tower_top (algebraMap R S) (algebraMap S T) rw [← IsScalarTower.algebraMap_eq R S T] exact h.isIntegral theorem RingHom.IsIntegral.quotient {I : Ideal S} (hf : f.IsIntegral) : (Ideal.quotientMap I f le_rfl).IsIntegral := by rintro ⟨x⟩ obtain ⟨p, p_monic, hpx⟩ := hf x refine ⟨p.map (Ideal.Quotient.mk _), p_monic.map _, ?_⟩ simpa only [hom_eval₂, eval₂_map] using congr_arg (Ideal.Quotient.mk I) hpx instance {I : Ideal A} [Algebra.IsIntegral R A] : Algebra.IsIntegral R (A ⧸ I) := Algebra.IsIntegral.trans A instance Algebra.IsIntegral.quotient {I : Ideal A} [Algebra.IsIntegral R A] : Algebra.IsIntegral (R ⧸ I.comap (algebraMap R A)) (A ⧸ I) := ⟨RingHom.IsIntegral.quotient (algebraMap R A) Algebra.IsIntegral.isIntegral⟩ theorem isIntegral_quotientMap_iff {I : Ideal S} : (Ideal.quotientMap I f le_rfl).IsIntegral ↔ ((Ideal.Quotient.mk I).comp f : R →+* S ⧸ I).IsIntegral := by let g := Ideal.Quotient.mk (I.comap f) -- Porting note: added type ascription have : (Ideal.quotientMap I f le_rfl).comp g = (Ideal.Quotient.mk I).comp f := Ideal.quotientMap_comp_mk le_rfl refine ⟨fun h => ?_, fun h => RingHom.IsIntegral.tower_top g _ (this ▸ h)⟩ refine this ▸ RingHom.IsIntegral.trans g (Ideal.quotientMap I f le_rfl) ?_ h exact g.isIntegral_of_surjective Ideal.Quotient.mk_surjective variable {R S : Type*} [CommRing R] [CommRing S] theorem RingHom.IsIntegral.isLocalHom {f : R →+* S} (hf : f.IsIntegral) (inj : Function.Injective f) : IsLocalHom f where map_nonunit a ha := by -- `f a` is invertible in `S`, and we need to show that `(f a)⁻¹` is of the form `f b`. -- Let `p : R[X]` be monic with root `(f a)⁻¹`, obtain ⟨p, p_monic, hp⟩ := hf (ha.unit⁻¹ : _) -- and `q` be `p` with coefficients reversed (so `q(a) = q'(a) * a + 1`). -- We have `q(a) = 0`, so `-q'(a)` is the inverse of `a`. refine .of_mul_eq_one (-p.reverse.divX.eval a) ?_ nth_rewrite 1 [mul_neg, ← eval_X (x := a), ← eval_mul, ← p_monic, ← coeff_zero_reverse, ← add_eq_zero_iff_neg_eq, ← eval_C (a := p.reverse.coeff 0), ← eval_add, X_mul_divX_add, ← (injective_iff_map_eq_zero' _).mp inj, ← eval₂_hom] rwa [← eval₂_reverse_eq_zero_iff] at hp variable [Algebra R S] [Algebra.IsIntegral R S] variable (R S) in instance Algebra.IsIntegral.isLocalHom [FaithfulSMul R S] : IsLocalHom (algebraMap R S) := (algebraMap_isIntegral_iff.mpr ‹_›).isLocalHom (FaithfulSMul.algebraMap_injective R S) /-- If the integral extension `R → S` is injective, and `S` is a field, then `R` is also a field. -/ theorem isField_of_isIntegral_of_isField (hRS : Function.Injective (algebraMap R S)) (hS : IsField S) : IsField R := have := (faithfulSMul_iff_algebraMap_injective R S).mpr hRS IsLocalHom.isField hRS hS theorem Algebra.IsIntegral.isField_iff_isField [IsDomain S] (hRS : Function.Injective (algebraMap R S)) : IsField R ↔ IsField S := ⟨isField_of_isIntegral_of_isField', isField_of_isIntegral_of_isField hRS⟩ end Algebra theorem integralClosure_idem {R A : Type*} [CommRing R] [CommRing A] [Algebra R A] : integralClosure (integralClosure R A) A = ⊥ := letI := (integralClosure R A).algebra eq_bot_iff.2 fun x hx ↦ Algebra.mem_bot.2 ⟨⟨x, isIntegral_trans (A := integralClosure R A) x hx⟩, rfl⟩ section IsDomain variable {R S : Type*} [CommRing R] [CommRing S] [IsDomain S] [Algebra R S] instance : IsDomain (integralClosure R S) := inferInstance theorem roots_mem_integralClosure {f : R[X]} (hf : f.Monic) {a : S} (ha : a ∈ f.aroots S) : a ∈ integralClosure R S := ⟨f, hf, (eval₂_eq_eval_map _).trans <| (mem_roots <| (hf.map _).ne_zero).1 ha⟩ end IsDomain
.lake/packages/mathlib/Mathlib/RingTheory/IntegralClosure/IsIntegralClosure/Defs.lean
import Mathlib.RingTheory.IntegralClosure.IsIntegral.Defs /-! # Integral closure as a characteristic predicate ## Main definitions Let `R` be a `CommRing` and let `A` be an R-algebra. * `IsIntegralClosure R A` : the characteristic predicate stating `A` is the integral closure of `R` in `B`, i.e. that an element of `B` is integral over `R` iff it is an element of (the image of) `A`. -/ /-- `IsIntegralClosure A R B` is the characteristic predicate stating `A` is the integral closure of `R` in `B`, i.e. that an element of `B` is integral over `R` iff it is an element of (the image of) `A`. -/ class IsIntegralClosure (A R B : Type*) [CommRing R] [CommSemiring A] [CommRing B] [Algebra R B] [Algebra A B] : Prop where algebraMap_injective (A R B) : Function.Injective (algebraMap A B) isIntegral_iff : ∀ {x : B}, IsIntegral R x ↔ ∃ y, algebraMap A B y = x namespace IsIntegralClosure @[deprecated (since := "2025-08-29")] alias algebraMap_injective' := algebraMap_injective end IsIntegralClosure
.lake/packages/mathlib/Mathlib/RingTheory/IntegralClosure/IsIntegral/Basic.lean
import Mathlib.RingTheory.IntegralClosure.IsIntegral.Defs import Mathlib.Algebra.Polynomial.Expand import Mathlib.RingTheory.Adjoin.Polynomial import Mathlib.RingTheory.Finiteness.Subalgebra import Mathlib.RingTheory.Polynomial.Tower /-! # Properties of integral elements. We prove basic properties of integral elements in a ring extension. -/ open Polynomial Submodule section Ring variable {R S A : Type*} variable [CommRing R] [Ring A] [Ring S] (f : R →+* S) variable [Algebra R A] theorem RingHom.isIntegralElem_map {x : R} : f.IsIntegralElem (f x) := ⟨X - C x, monic_X_sub_C _, by simp⟩ theorem isIntegral_algebraMap {x : R} : IsIntegral R (algebraMap R A x) := (algebraMap R A).isIntegralElem_map end Ring section variable {R A B S : Type*} variable [CommRing R] [CommRing A] [Ring B] [CommRing S] variable [Algebra R A] (f : R →+* S) theorem IsIntegral.map {B C F : Type*} [Ring B] [Ring C] [Algebra R B] [Algebra A B] [Algebra R C] [IsScalarTower R A B] [Algebra A C] [IsScalarTower R A C] {b : B} [FunLike F B C] [AlgHomClass F A B C] (f : F) (hb : IsIntegral R b) : IsIntegral R (f b) := by obtain ⟨P, hP⟩ := hb refine ⟨P, hP.1, ?_⟩ rw [← aeval_def, ← aeval_map_algebraMap A, aeval_algHom_apply, aeval_map_algebraMap, aeval_def, hP.2, map_zero] section variable {A B : Type*} [Ring A] [Ring B] [Algebra R A] [Algebra R B] theorem isIntegral_algHom_iff (f : A →ₐ[R] B) (hf : Function.Injective f) {x : A} : IsIntegral R (f x) ↔ IsIntegral R x := by refine ⟨fun ⟨p, hp, hx⟩ ↦ ⟨p, hp, ?_⟩, IsIntegral.map f⟩ rwa [← f.comp_algebraMap, ← AlgHom.coe_toRingHom, ← hom_eval₂, AlgHom.coe_toRingHom, map_eq_zero_iff f hf] at hx end open Classical in theorem Submodule.span_range_natDegree_eq_adjoin {R A} [CommRing R] [Semiring A] [Algebra R A] {x : A} {f : R[X]} (hf : f.Monic) (hfx : aeval x f = 0) : span R (Finset.image (x ^ ·) (Finset.range (natDegree f))) = Subalgebra.toSubmodule (Algebra.adjoin R {x}) := by nontriviality A have hf1 : f ≠ 1 := by rintro rfl; simp [one_ne_zero' A] at hfx refine (span_le.mpr fun s hs ↦ ?_).antisymm fun r hr ↦ ?_ · rcases Finset.mem_image.1 (SetLike.mem_coe.mp hs) with ⟨k, -, rfl⟩ exact (Algebra.adjoin R {x}).pow_mem (Algebra.subset_adjoin rfl) k rw [Subalgebra.mem_toSubmodule, Algebra.adjoin_singleton_eq_range_aeval] at hr rcases (aeval x).mem_range.mp hr with ⟨p, rfl⟩ rw [← modByMonic_add_div p hf, map_add, map_mul, hfx, zero_mul, add_zero, ← sum_C_mul_X_pow_eq (p %ₘ f), aeval_def, eval₂_sum, sum_def] refine sum_mem fun k hkq ↦ ?_ rw [C_mul_X_pow_eq_monomial, eval₂_monomial, ← Algebra.smul_def] exact smul_mem _ _ (subset_span <| Finset.mem_image_of_mem _ <| Finset.mem_range.mpr <| (le_natDegree_of_mem_supp _ hkq).trans_lt <| natDegree_modByMonic_lt p hf hf1) theorem IsIntegral.fg_adjoin_singleton [Algebra R B] {x : B} (hx : IsIntegral R x) : (Algebra.adjoin R {x}).toSubmodule.FG := by classical rcases hx with ⟨f, hfm, hfx⟩ use (Finset.range <| f.natDegree).image (x ^ ·) exact span_range_natDegree_eq_adjoin hfm (by rwa [aeval_def]) variable (f : R →+* B) theorem RingHom.isIntegralElem_zero : f.IsIntegralElem 0 := f.map_zero ▸ f.isIntegralElem_map theorem isIntegral_zero [Algebra R B] : IsIntegral R (0 : B) := (algebraMap R B).isIntegralElem_zero theorem RingHom.isIntegralElem_one : f.IsIntegralElem 1 := f.map_one ▸ f.isIntegralElem_map theorem isIntegral_one [Algebra R B] : IsIntegral R (1 : B) := (algebraMap R B).isIntegralElem_one variable (f : R →+* S) theorem IsIntegral.of_pow [Algebra R B] {x : B} {n : ℕ} (hn : 0 < n) (hx : IsIntegral R <| x ^ n) : IsIntegral R x := have ⟨p, hmonic, heval⟩ := hx ⟨expand R n p, hmonic.expand hn, by rwa [← aeval_def, expand_aeval]⟩ theorem IsIntegral.of_aeval_monic {x : A} {p : R[X]} (monic : p.Monic) (deg : p.natDegree ≠ 0) (hx : IsIntegral R (aeval x p)) : IsIntegral R x := have ⟨p, hmonic, heval⟩ := hx ⟨_, hmonic.comp monic deg, by rwa [eval₂_comp, ← aeval_def x]⟩ end section variable {R A B S : Type*} variable [CommRing R] [CommRing A] [Ring B] [CommRing S] variable [Algebra R A] [Algebra R B] (f : R →+* S) theorem IsIntegral.map_of_comp_eq {R S T U : Type*} [CommRing R] [Ring S] [CommRing T] [Ring U] [Algebra R S] [Algebra T U] (φ : R →+* T) (ψ : S →+* U) (h : (algebraMap T U).comp φ = ψ.comp (algebraMap R S)) {a : S} (ha : IsIntegral R a) : IsIntegral T (ψ a) := let ⟨p, hp⟩ := ha ⟨p.map φ, hp.1.map _, by rw [← eval_map, map_map, h, ← map_map, eval_map, eval₂_at_apply, eval_map, hp.2, ψ.map_zero]⟩ @[simp] theorem isIntegral_algEquiv {A B : Type*} [Ring A] [Ring B] [Algebra R A] [Algebra R B] (f : A ≃ₐ[R] B) {x : A} : IsIntegral R (f x) ↔ IsIntegral R x := ⟨fun h ↦ by simpa using h.map f.symm, IsIntegral.map f⟩ /-- If `R → A → B` is an algebra tower, then if the entire tower is an integral extension so is `A → B`. -/ theorem IsIntegral.tower_top [Algebra A B] [IsScalarTower R A B] {x : B} (hx : IsIntegral R x) : IsIntegral A x := let ⟨p, hp, hpx⟩ := hx ⟨p.map <| algebraMap R A, hp.map _, by rw [← aeval_def, aeval_map_algebraMap, aeval_def, hpx]⟩ /- If `R` and `T` are isomorphic commutative rings and `S` is an `R`-algebra and a `T`-algebra in a compatible way, then an element `a ∈ S` is integral over `R` if and only if it is integral over `T`. -/ theorem RingEquiv.isIntegral_iff {R S T : Type*} [CommRing R] [Ring S] [CommRing T] [Algebra R S] [Algebra T S] (φ : R ≃+* T) (h : (algebraMap T S).comp φ.toRingHom = algebraMap R S) (a : S) : IsIntegral R a ↔ IsIntegral T a := by constructor <;> intro ha · letI : Algebra R T := φ.toRingHom.toAlgebra letI : IsScalarTower R T S := ⟨fun r t s ↦ by simp only [Algebra.smul_def, map_mul, ← h, mul_assoc]; rfl⟩ exact IsIntegral.tower_top ha · have h' : (algebraMap T S) = (algebraMap R S).comp φ.symm.toRingHom := by simp only [← h, RingHom.comp_assoc, RingEquiv.toRingHom_eq_coe, RingEquiv.comp_symm, RingHomCompTriple.comp_eq] letI : Algebra T R := φ.symm.toRingHom.toAlgebra letI : IsScalarTower T R S := ⟨fun r t s ↦ by simp only [Algebra.smul_def, map_mul, h', mul_assoc]; rfl⟩ exact IsIntegral.tower_top ha theorem map_isIntegral_int {B C F : Type*} [Ring B] [Ring C] {b : B} [FunLike F B C] [RingHomClass F B C] (f : F) (hb : IsIntegral ℤ b) : IsIntegral ℤ (f b) := hb.map (f : B →+* C).toIntAlgHom theorem IsIntegral.of_subring {x : B} (T : Subring R) (hx : IsIntegral T x) : IsIntegral R x := hx.tower_top protected theorem IsIntegral.algebraMap [Algebra A B] [IsScalarTower R A B] {x : A} (h : IsIntegral R x) : IsIntegral R (algebraMap A B x) := by rcases h with ⟨f, hf, hx⟩ use f, hf rw [IsScalarTower.algebraMap_eq R A B, ← hom_eval₂, hx, RingHom.map_zero] theorem isIntegral_algebraMap_iff [Algebra A B] [IsScalarTower R A B] {x : A} (hAB : Function.Injective (algebraMap A B)) : IsIntegral R (algebraMap A B x) ↔ IsIntegral R x := isIntegral_algHom_iff (IsScalarTower.toAlgHom R A B) hAB theorem isIntegral_iff_isIntegral_closure_finite {r : B} : IsIntegral R r ↔ ∃ s : Set R, s.Finite ∧ IsIntegral (Subring.closure s) r := by constructor <;> intro hr · rcases hr with ⟨p, hmp, hpr⟩ refine ⟨_, Finset.finite_toSet _, p.restriction, monic_restriction.2 hmp, ?_⟩ rw [← aeval_def, ← aeval_map_algebraMap R r p.restriction, map_restriction, aeval_def, hpr] rcases hr with ⟨s, _, hsr⟩ exact hsr.of_subring _ @[stacks 09GH] theorem fg_adjoin_of_finite {s : Set A} (hfs : s.Finite) (his : ∀ x ∈ s, IsIntegral R x) : (Algebra.adjoin R s).toSubmodule.FG := by induction s, hfs using Set.Finite.induction_on with | empty => refine ⟨{1}, Submodule.ext fun x => ?_⟩ rw [Algebra.adjoin_empty, Finset.coe_singleton, ← one_eq_span, Algebra.toSubmodule_bot] | @insert a s _ _ ih => rw [← Set.union_singleton, Algebra.adjoin_union_coe_submodule] exact FG.mul (ih fun i hi => his i <| Set.mem_insert_of_mem a hi) (his a <| Set.mem_insert a s).fg_adjoin_singleton theorem Algebra.finite_adjoin_of_finite_of_isIntegral {s : Set A} (hf : s.Finite) (hi : ∀ x ∈ s, IsIntegral R x) : Module.Finite R (adjoin R s) := Module.Finite.iff_fg.mpr <| fg_adjoin_of_finite hf hi theorem Algebra.finite_adjoin_simple_of_isIntegral {x : B} (hi : IsIntegral R x) : Module.Finite R (adjoin R {x}) := Module.Finite.iff_fg.mpr hi.fg_adjoin_singleton theorem isNoetherian_adjoin_finset [IsNoetherianRing R] (s : Finset A) (hs : ∀ x ∈ s, IsIntegral R x) : IsNoetherian R (Algebra.adjoin R (s : Set A)) := isNoetherian_of_fg_of_noetherian _ (fg_adjoin_of_finite s.finite_toSet hs) end section Prod variable {R A B : Type*} variable [CommRing R] [Ring A] [Ring B] [Algebra R A] [Algebra R B] /-- An element of a product algebra is integral if each component is integral. -/ theorem IsIntegral.pair {x : A × B} (hx₁ : IsIntegral R x.1) (hx₂ : IsIntegral R x.2) : IsIntegral R x := by obtain ⟨p₁, ⟨hp₁Monic, hp₁Eval⟩⟩ := hx₁ obtain ⟨p₂, ⟨hp₂Monic, hp₂Eval⟩⟩ := hx₂ refine ⟨p₁ * p₂, ⟨hp₁Monic.mul hp₂Monic, ?_⟩⟩ rw [← aeval_def] at * rw [aeval_prod_apply, aeval_mul, hp₁Eval, zero_mul, aeval_mul, hp₂Eval, mul_zero, Prod.zero_eq_mk] /-- An element of a product algebra is integral iff each component is integral. -/ theorem IsIntegral.pair_iff {x : A × B} : IsIntegral R x ↔ IsIntegral R x.1 ∧ IsIntegral R x.2 := ⟨fun h ↦ ⟨h.map (AlgHom.fst R A B), h.map (AlgHom.snd R A B)⟩, fun h ↦ h.1.pair h.2⟩ end Prod
.lake/packages/mathlib/Mathlib/RingTheory/IntegralClosure/IsIntegral/Defs.lean
import Mathlib.Algebra.Polynomial.Degree.Definitions import Mathlib.Algebra.Polynomial.Eval.Defs import Mathlib.Tactic.Algebraize /-! # Integral closure of a subring. If A is an R-algebra then `a : A` is integral over R if it is a root of a monic polynomial with coefficients in R. ## Main definitions Let `R` be a `CommRing` and let `A` be an R-algebra. * `RingHom.IsIntegralElem (f : R →+* A) (x : A)` : `x` is integral with respect to the map `f`, * `IsIntegral (x : A)` : `x` is integral over `R`, i.e., is a root of a monic polynomial with coefficients in `R`. -/ open Polynomial section Ring variable {R S A : Type*} variable [CommRing R] [Ring A] [Ring S] (f : R →+* S) /-- An element `x` of `A` is said to be integral over `R` with respect to `f` if it is a root of a monic polynomial `p : R[X]` evaluated under `f` -/ def RingHom.IsIntegralElem (f : R →+* A) (x : A) := ∃ p : R[X], Monic p ∧ eval₂ f x p = 0 /-- A ring homomorphism `f : R →+* A` is said to be integral if every element `A` is integral with respect to the map `f` -/ @[algebraize Algebra.IsIntegral.mk, stacks 00GI "(2)"] def RingHom.IsIntegral (f : R →+* A) := ∀ x : A, f.IsIntegralElem x variable [Algebra R A] (R) /-- An element `x` of an algebra `A` over a commutative ring `R` is said to be *integral*, if it is a root of some monic polynomial `p : R[X]`. Equivalently, the element is integral over `R` with respect to the induced `algebraMap` -/ def IsIntegral (x : A) : Prop := (algebraMap R A).IsIntegralElem x end Ring
.lake/packages/mathlib/Mathlib/RingTheory/IntegralClosure/Algebra/Basic.lean
import Mathlib.LinearAlgebra.Matrix.Charpoly.LinearMap import Mathlib.RingTheory.IntegralClosure.Algebra.Defs import Mathlib.RingTheory.IntegralClosure.IsIntegral.Basic /-! # Integral closure of a subring. Let `A` be an `R`-algebra. We prove that integral elements form a sub-`R`-algebra of `A`. ## Main definitions Let `R` be a `CommRing` and let `A` be an R-algebra. * `integralClosure R A` : the integral closure of `R` in an `R`-algebra `A`. -/ open Polynomial Submodule section variable {R A B S : Type*} variable [CommRing R] [CommRing A] [Ring B] [CommRing S] variable [Algebra R A] [Algebra R B] (f : R →+* S) theorem Subalgebra.isIntegral_iff (S : Subalgebra R B) : Algebra.IsIntegral R S ↔ ∀ x ∈ S, IsIntegral R x := Algebra.isIntegral_def.trans <| .trans (forall_congr' fun _ ↦ (isIntegral_algHom_iff S.val Subtype.val_injective).symm) Subtype.forall section variable {A B : Type*} [Ring A] [Ring B] [Algebra R A] [Algebra R B] theorem Algebra.IsIntegral.of_injective (f : A →ₐ[R] B) (hf : Function.Injective f) [Algebra.IsIntegral R B] : Algebra.IsIntegral R A := ⟨fun _ ↦ (isIntegral_algHom_iff f hf).mp (isIntegral _)⟩ /-- Homomorphic image of an integral algebra is an integral algebra. -/ theorem Algebra.IsIntegral.of_surjective [Algebra.IsIntegral R A] (f : A →ₐ[R] B) (hf : Function.Surjective f) : Algebra.IsIntegral R B := isIntegral_def.mpr fun b ↦ let ⟨a, ha⟩ := hf b; ha ▸ (isIntegral_def.mp ‹_› a).map f theorem AlgEquiv.isIntegral_iff (e : A ≃ₐ[R] B) : Algebra.IsIntegral R A ↔ Algebra.IsIntegral R B := ⟨fun h ↦ h.of_injective e.symm e.symm.injective, fun h ↦ h.of_injective e e.injective⟩ end instance Module.End.isIntegral {M : Type*} [AddCommGroup M] [Module R M] [Module.Finite R M] : Algebra.IsIntegral R (Module.End R M) := ⟨LinearMap.exists_monic_and_aeval_eq_zero R⟩ variable (R) in @[nontriviality] theorem IsIntegral.of_finite [Module.Finite R B] (x : B) : IsIntegral R x := (isIntegral_algHom_iff (Algebra.lmul R B) Algebra.lmul_injective).mp (Algebra.IsIntegral.isIntegral _) theorem isIntegral_of_noetherian (_ : IsNoetherian R B) (x : B) : IsIntegral R x := .of_finite R x variable (R B) in instance Algebra.IsIntegral.of_finite [Module.Finite R B] : Algebra.IsIntegral R B := ⟨.of_finite R⟩ lemma Algebra.isIntegral_of_surjective (H : Function.Surjective (algebraMap R B)) : Algebra.IsIntegral R B := .of_surjective (Algebra.ofId R B) H /-- If `S` is a sub-`R`-algebra of `A` and `S` is finitely-generated as an `R`-module, then all elements of `S` are integral over `R`. -/ theorem IsIntegral.of_mem_of_fg (S : Subalgebra R B) (HS : S.toSubmodule.FG) (x : B) (hx : x ∈ S) : IsIntegral R x := have : Module.Finite R S := ⟨(fg_top _).mpr HS⟩ (isIntegral_algHom_iff S.val Subtype.val_injective).mpr (.of_finite R (⟨x, hx⟩ : S)) theorem isIntegral_of_submodule_noetherian (S : Subalgebra R B) (H : IsNoetherian R (Subalgebra.toSubmodule S)) (x : B) (hx : x ∈ S) : IsIntegral R x := .of_mem_of_fg _ ((fg_top _).mp <| H.noetherian _) _ hx /-- Suppose `A` is an `R`-algebra, `M` is an `A`-module such that `a • m ≠ 0` for all non-zero `a` and `m`. If `x : A` fixes a nontrivial f.g. `R`-submodule `N` of `M`, then `x` is `R`-integral. -/ theorem isIntegral_of_smul_mem_submodule {M : Type*} [AddCommGroup M] [Module R M] [Module A M] [IsScalarTower R A M] [NoZeroSMulDivisors A M] (N : Submodule R M) (hN : N ≠ ⊥) (hN' : N.FG) (x : A) (hx : ∀ n ∈ N, x • n ∈ N) : IsIntegral R x := by let A' : Subalgebra R A := { carrier := { x | ∀ n ∈ N, x • n ∈ N } mul_mem' := fun {a b} ha hb n hn => smul_smul a b n ▸ ha _ (hb _ hn) one_mem' := fun n hn => (one_smul A n).symm ▸ hn add_mem' := fun {a b} ha hb n hn => (add_smul a b n).symm ▸ N.add_mem (ha _ hn) (hb _ hn) zero_mem' := fun n _hn => (zero_smul A n).symm ▸ N.zero_mem algebraMap_mem' := fun r n hn => (algebraMap_smul A r n).symm ▸ N.smul_mem r hn } let f : A' →ₐ[R] Module.End R N := AlgHom.ofLinearMap { toFun := fun x => (DistribMulAction.toLinearMap R M x).restrict x.prop map_add' := by intro x y; ext; exact add_smul _ _ _ map_smul' := by intro r s; ext; apply smul_assoc } (by ext; apply one_smul) (by intro x y; ext; apply mul_smul) obtain ⟨a, ha₁, ha₂⟩ : ∃ a ∈ N, a ≠ (0 : M) := by by_contra! h' apply hN rwa [eq_bot_iff] have : Function.Injective f := by change Function.Injective f.toLinearMap rw [← LinearMap.ker_eq_bot, eq_bot_iff] intro s hs have : s.1 • a = 0 := congr_arg Subtype.val (LinearMap.congr_fun hs ⟨a, ha₁⟩) exact Subtype.ext ((eq_zero_or_eq_zero_of_smul_eq_zero this).resolve_right ha₂) change IsIntegral R (A'.val ⟨x, hx⟩) rw [isIntegral_algHom_iff A'.val Subtype.val_injective, ← isIntegral_algHom_iff f this] haveI : Module.Finite R N := by rwa [Module.finite_def, Submodule.fg_top] apply Algebra.IsIntegral.isIntegral variable {f} @[stacks 00GK] theorem RingHom.Finite.to_isIntegral (h : f.Finite) : f.IsIntegral := letI := f.toAlgebra fun _ ↦ IsIntegral.of_mem_of_fg ⊤ h.1 _ trivial alias RingHom.IsIntegral.of_finite := RingHom.Finite.to_isIntegral variable (f) theorem RingHom.IsIntegralElem.of_mem_closure {x y z : S} (hx : f.IsIntegralElem x) (hy : f.IsIntegralElem y) (hz : z ∈ Subring.closure ({x, y} : Set S)) : f.IsIntegralElem z := by letI : Algebra R S := f.toAlgebra have := (IsIntegral.fg_adjoin_singleton hx).mul (IsIntegral.fg_adjoin_singleton hy) rw [← Algebra.adjoin_union_coe_submodule, Set.singleton_union] at this exact IsIntegral.of_mem_of_fg (Algebra.adjoin R {x, y}) this z (Algebra.mem_adjoin_iff.2 <| Subring.closure_mono Set.subset_union_right hz) nonrec theorem IsIntegral.of_mem_closure {x y z : A} (hx : IsIntegral R x) (hy : IsIntegral R y) (hz : z ∈ Subring.closure ({x, y} : Set A)) : IsIntegral R z := hx.of_mem_closure (algebraMap R A) hy hz variable (f : R →+* B) theorem RingHom.IsIntegralElem.add (f : R →+* S) {x y : S} (hx : f.IsIntegralElem x) (hy : f.IsIntegralElem y) : f.IsIntegralElem (x + y) := hx.of_mem_closure f hy <| Subring.add_mem _ (Subring.subset_closure (Or.inl rfl)) (Subring.subset_closure (Or.inr rfl)) nonrec theorem IsIntegral.add {x y : A} (hx : IsIntegral R x) (hy : IsIntegral R y) : IsIntegral R (x + y) := hx.add (algebraMap R A) hy variable (f : R →+* S) -- can be generalized to noncommutative S. theorem RingHom.IsIntegralElem.neg {x : S} (hx : f.IsIntegralElem x) : f.IsIntegralElem (-x) := hx.of_mem_closure f hx (Subring.neg_mem _ (Subring.subset_closure (Or.inl rfl))) theorem RingHom.IsIntegralElem.of_neg {x : S} (h : f.IsIntegralElem (-x)) : f.IsIntegralElem x := neg_neg x ▸ h.neg @[simp] theorem RingHom.IsIntegralElem.neg_iff {x : S} : f.IsIntegralElem (-x) ↔ f.IsIntegralElem x := ⟨fun h => h.of_neg, fun h => h.neg⟩ theorem IsIntegral.neg {x : B} (hx : IsIntegral R x) : IsIntegral R (-x) := .of_mem_of_fg _ hx.fg_adjoin_singleton _ (Subalgebra.neg_mem _ <| Algebra.subset_adjoin rfl) theorem IsIntegral.of_neg {x : B} (hx : IsIntegral R (-x)) : IsIntegral R x := neg_neg x ▸ hx.neg @[simp] theorem IsIntegral.neg_iff {x : B} : IsIntegral R (-x) ↔ IsIntegral R x := ⟨IsIntegral.of_neg, IsIntegral.neg⟩ theorem RingHom.IsIntegralElem.sub {x y : S} (hx : f.IsIntegralElem x) (hy : f.IsIntegralElem y) : f.IsIntegralElem (x - y) := by simpa only [sub_eq_add_neg] using hx.add f (hy.neg f) nonrec theorem IsIntegral.sub {x y : A} (hx : IsIntegral R x) (hy : IsIntegral R y) : IsIntegral R (x - y) := hx.sub (algebraMap R A) hy theorem RingHom.IsIntegralElem.mul {x y : S} (hx : f.IsIntegralElem x) (hy : f.IsIntegralElem y) : f.IsIntegralElem (x * y) := hx.of_mem_closure f hy (Subring.mul_mem _ (Subring.subset_closure (Or.inl rfl)) (Subring.subset_closure (Or.inr rfl))) nonrec theorem IsIntegral.mul {x y : A} (hx : IsIntegral R x) (hy : IsIntegral R y) : IsIntegral R (x * y) := hx.mul (algebraMap R A) hy theorem IsIntegral.smul {R} [CommSemiring R] [Algebra R B] [Algebra S B] [Algebra R S] [IsScalarTower R S B] {x : B} (r : R) (hx : IsIntegral S x) : IsIntegral S (r • x) := .of_mem_of_fg _ hx.fg_adjoin_singleton _ <| by rw [← algebraMap_smul S]; apply Subalgebra.smul_mem; exact Algebra.subset_adjoin rfl variable (R A) /-- The integral closure of `R` in an `R`-algebra `A`. -/ def integralClosure : Subalgebra R A where carrier := { r | IsIntegral R r } zero_mem' := isIntegral_zero one_mem' := isIntegral_one add_mem' := IsIntegral.add mul_mem' := IsIntegral.mul algebraMap_mem' _ := isIntegral_algebraMap theorem mem_integralClosure_iff {a : A} : a ∈ integralClosure R A ↔ IsIntegral R a := Iff.rfl variable {R} {A B : Type*} [Ring A] [Algebra R A] [Ring B] [Algebra R B] /-- Product of two integral algebras is an integral algebra. -/ instance Algebra.IsIntegral.prod [Algebra.IsIntegral R A] [Algebra.IsIntegral R B] : Algebra.IsIntegral R (A × B) := Algebra.isIntegral_def.mpr fun x ↦ (Algebra.isIntegral_def.mp ‹_› x.1).pair (Algebra.isIntegral_def.mp ‹_› x.2) end section TensorProduct variable {R A B : Type*} [CommRing R] [CommRing A] open TensorProduct theorem IsIntegral.tmul [Ring B] [Algebra R A] [Algebra R B] (x : A) {y : B} (h : IsIntegral R y) : IsIntegral A (x ⊗ₜ[R] y) := by rw [← mul_one x, ← smul_eq_mul, ← smul_tmul'] exact smul _ (h.map_of_comp_eq (algebraMap R A) (Algebra.TensorProduct.includeRight (R := R) (A := A) (B := B)).toRingHom Algebra.TensorProduct.includeLeftRingHom_comp_algebraMap) variable (R A B) instance Algebra.IsIntegral.tensorProduct [CommRing B] [Algebra R A] [Algebra R B] [int : Algebra.IsIntegral R B] : Algebra.IsIntegral A (A ⊗[R] B) where isIntegral p := p.induction_on isIntegral_zero (fun _ s ↦ .tmul _ <| int.1 s) (fun _ _ ↦ .add) end TensorProduct section MulSemiringAction variable {G R K : Type*} [CommRing R] [CommRing K] [Algebra R K] [Group G] [MulSemiringAction G K] [SMulCommClass G R K] instance : MulSemiringAction G (integralClosure R K) where smul := fun g x ↦ ⟨g • (x : K), x.2.map (MulSemiringAction.toAlgHom R K g)⟩ one_smul x := by ext; exact one_smul G (x : K) mul_smul g h x := by ext; exact mul_smul g h (x : K) smul_zero g := by ext; exact smul_zero g smul_add g x y := by ext; exact smul_add g (x : K) (y : K) smul_one g := by ext; exact smul_one g smul_mul g x y := by ext; exact smul_mul' g (x : K) (y : K) @[simp] theorem integralClosure.coe_smul (g : G) (k : integralClosure R K) : (g • k : integralClosure R K) = g • (k : K) := rfl instance : SMulCommClass G R (integralClosure R K) where smul_comm g r k := Subtype.ext (smul_comm g r (k : K)) instance : SMulDistribClass G (integralClosure R K) K where smul_distrib_smul g r k := smul_mul' g (r : K) k end MulSemiringAction
.lake/packages/mathlib/Mathlib/RingTheory/IntegralClosure/Algebra/Defs.lean
import Mathlib.RingTheory.IntegralClosure.IsIntegral.Defs /-! # Integral algebras ## Main definitions Let `R` be a `CommRing` and let `A` be an R-algebra. * `Algebra.IsIntegral R A` : An algebra is integral if every element of the extension is integral over the base ring. -/ open Polynomial Submodule section Ring variable {R S A : Type*} variable [CommRing R] [Ring A] [Ring S] (f : R →+* S) variable [Algebra R A] (R) variable (A) /-- An algebra is integral if every element of the extension is integral over the base ring. -/ @[mk_iff] protected class Algebra.IsIntegral : Prop where isIntegral : ∀ x : A, IsIntegral R x variable {R A} lemma Algebra.isIntegral_def : Algebra.IsIntegral R A ↔ ∀ x : A, IsIntegral R x := ⟨fun ⟨h⟩ ↦ h, fun h ↦ ⟨h⟩⟩ lemma algebraMap_isIntegral_iff : (algebraMap R A).IsIntegral ↔ Algebra.IsIntegral R A := (Algebra.isIntegral_iff ..).symm end Ring
.lake/packages/mathlib/Mathlib/RingTheory/DedekindDomain/Instances.lean
import Mathlib.RingTheory.DedekindDomain.PID import Mathlib.FieldTheory.Separable import Mathlib.RingTheory.RingHom.Finite /-! # Instances for Dedekind domains This file contains various instances to work with localization of a ring extension. A very common situation in number theory is to have an extension of (say) Dedekind domains `R` and `S`, and to prove a property of this extension it is useful to consider the localization `Rₚ` of `R` at `P`, a prime ideal of `R`. One also works with the corresponding localization `Sₚ` of `S` and the fraction fields `K` and `L` of `R` and `S`. In this situation there are many compatible algebra structures and various properties of the rings involved. Another situation is when we have a tower extension `R ⊆ S ⊆ T` and thus we work with `Rₚ ⊆ Sₚ ⊆ Tₚ` where `Tₚ` is the localization of `T` at `P`. This file contains a collection of such instances. ## Implementation details In general one wants all the results below for any algebra satisfying `IsLocalization`, but those cannot be instances (since Lean has no way of guessing the submonoid). Having the instances in the special case of *the* localization at a prime ideal is useful in working with Dedekind domains. -/ open nonZeroDivisors IsLocalization Algebra IsFractionRing IsScalarTower attribute [local instance] FractionRing.liftAlgebra variable {R : Type*} (S : Type*) (T : Type*) [CommRing R] [CommRing S] [CommRing T] [IsDomain R] [IsDomain S] [IsDomain T] [Algebra R S] local notation3 "K" => FractionRing R local notation3 "L" => FractionRing S local notation3 "F" => FractionRing T section theorem algebraMapSubmonoid_le_nonZeroDivisors_of_faithfulSMul {A : Type*} (B : Type*) [CommSemiring A] [CommSemiring B] [Algebra A B] [NoZeroDivisors B] [FaithfulSMul A B] {S : Submonoid A} (hS : S ≤ A⁰) : algebraMapSubmonoid B S ≤ B⁰ := map_le_nonZeroDivisors_of_injective _ (FaithfulSMul.algebraMap_injective A B) hS variable (Rₘ Sₘ : Type*) [CommRing Rₘ] [CommRing Sₘ] [Algebra R Rₘ] [NoZeroSMulDivisors R S] [Algebra.IsSeparable (FractionRing R) (FractionRing S)] {M : Submonoid R} [IsLocalization M Rₘ] [Algebra Rₘ Sₘ] [Algebra S Sₘ] [Algebra R Sₘ] [IsScalarTower R Rₘ Sₘ] [IsScalarTower R S Sₘ] [IsLocalization (algebraMapSubmonoid S M) Sₘ] [Algebra (FractionRing Rₘ) (FractionRing Sₘ)] [IsScalarTower Rₘ (FractionRing Rₘ) (FractionRing Sₘ)] include R S in theorem FractionRing.isSeparable_of_isLocalization (hM : M ≤ R⁰) : Algebra.IsSeparable (FractionRing Rₘ) (FractionRing Sₘ) := by let M' := algebraMapSubmonoid S M have hM' : algebraMapSubmonoid S M ≤ S⁰ := algebraMapSubmonoid_le_nonZeroDivisors_of_faithfulSMul _ hM let f₁ : Rₘ →+* K := map _ (T := R⁰) (RingHom.id R) hM let f₂ : Sₘ →+* L := map _ (T := S⁰) (RingHom.id S) hM' algebraize [f₁, f₂] have := localization_isScalarTower_of_submonoid_le Rₘ K _ _ hM have := localization_isScalarTower_of_submonoid_le Sₘ L _ _ hM' have := isFractionRing_of_isDomain_of_isLocalization M Rₘ K have := isFractionRing_of_isDomain_of_isLocalization M' Sₘ L have : IsDomain Rₘ := isDomain_of_le_nonZeroDivisors _ hM apply Algebra.IsSeparable.of_equiv_equiv (FractionRing.algEquiv Rₘ K).symm.toRingEquiv (FractionRing.algEquiv Sₘ L).symm.toRingEquiv apply ringHom_ext R⁰ ext simp only [AlgEquiv.toRingEquiv_eq_coe, RingHom.coe_comp, RingHom.coe_coe, Function.comp_apply, ← algebraMap_apply] rw [algebraMap_apply R Rₘ (FractionRing R), AlgEquiv.coe_ringEquiv, AlgEquiv.commutes, algebraMap_apply R S L, algebraMap_apply S Sₘ L, AlgEquiv.coe_ringEquiv, AlgEquiv.commutes] simp only [← algebraMap_apply] rw [algebraMap_apply R Rₘ (FractionRing Rₘ), ← algebraMap_apply Rₘ, ← algebraMap_apply] end variable {P : Ideal R} [P.IsPrime] local notation3 "P'" => algebraMapSubmonoid S P.primeCompl local notation3 "Rₚ" => Localization.AtPrime P local notation3 "Sₚ" => Localization P' variable [FaithfulSMul R S] instance : NoZeroSMulDivisors S Sₚ := by rw [NoZeroSMulDivisors.iff_algebraMap_injective, injective_iff_isRegular (algebraMapSubmonoid S P.primeCompl)] exact fun ⟨x, hx⟩ ↦ isRegular_iff_ne_zero'.mpr <| ne_of_mem_of_not_mem hx <| by simp [Algebra.algebraMapSubmonoid] instance : NoZeroSMulDivisors R Sₚ := by have := IsLocalization.AtPrime.faithfulSMul Rₚ R P exact NoZeroSMulDivisors.trans_faithfulSMul R Rₚ _ /-- This is not an instance because it creates a diamond with `OreLocalization.instAlgebra`. -/ noncomputable abbrev Localization.AtPrime.liftAlgebra : Algebra Sₚ L := (map _ (T := S⁰) (RingHom.id S) (algebraMapSubmonoid_le_nonZeroDivisors_of_faithfulSMul _ P.primeCompl_le_nonZeroDivisors)).toAlgebra attribute [local instance] Localization.AtPrime.liftAlgebra instance : IsScalarTower S Sₚ L := localization_isScalarTower_of_submonoid_le _ _ _ _ (algebraMapSubmonoid_le_nonZeroDivisors_of_faithfulSMul _ P.primeCompl_le_nonZeroDivisors) instance : IsFractionRing Rₚ K := isFractionRing_of_isDomain_of_isLocalization P.primeCompl _ _ instance : IsFractionRing Sₚ L := isFractionRing_of_isDomain_of_isLocalization P' _ _ noncomputable instance : Algebra Rₚ L := (lift (M := P.primeCompl) (g := algebraMap R L) <| fun ⟨x, hx⟩ ↦ by simpa using fun h ↦ hx <| by simp [h]).toAlgebra -- Make sure there are no diamonds in the case `R = S`. example : instAlgebraLocalizationAtPrime P = instAlgebraAtPrimeFractionRing (S := R) := by with_reducible_and_instances rfl instance : IsScalarTower Rₚ K L := of_algebraMap_eq' (ringHom_ext P.primeCompl (RingHom.ext fun x ↦ by simp [RingHom.algebraMap_toAlgebra])) instance : IsScalarTower R Rₚ K := of_algebraMap_eq' (RingHom.ext fun x ↦ by simp [RingHom.algebraMap_toAlgebra]) instance : IsScalarTower Rₚ Sₚ L := by refine IsScalarTower.of_algebraMap_eq' <| IsLocalization.ringHom_ext P.primeCompl ?_ rw [RingHom.comp_assoc, ← IsScalarTower.algebraMap_eq R Rₚ Sₚ, IsScalarTower.algebraMap_eq R S Sₚ, ← RingHom.comp_assoc, ← IsScalarTower.algebraMap_eq S Sₚ L, IsScalarTower.algebraMap_eq Rₚ K L, RingHom.comp_assoc, ← IsScalarTower.algebraMap_eq, ← IsScalarTower.algebraMap_eq, ← IsScalarTower.algebraMap_eq] instance [IsDedekindDomain S] : IsDedekindDomain Sₚ := isDedekindDomain S (algebraMapSubmonoid_le_nonZeroDivisors_of_faithfulSMul _ P.primeCompl_le_nonZeroDivisors) _ instance [IsDedekindDomain R] [IsDedekindDomain S] [Module.Finite R S] [hP : NeZero P] : IsPrincipalIdealRing Sₚ := IsDedekindDomain.isPrincipalIdealRing_localization_over_prime S P (fun h ↦ hP.1 h) instance [Algebra.IsSeparable K L] : -- Without the following line there is a timeout letI : Algebra Rₚ (FractionRing Sₚ) := OreLocalization.instAlgebra Algebra.IsSeparable (FractionRing Rₚ) (FractionRing Sₚ) := let _ : Algebra Rₚ (FractionRing Sₚ) := OreLocalization.instAlgebra FractionRing.isSeparable_of_isLocalization S _ _ P.primeCompl_le_nonZeroDivisors local notation3 "P''" => algebraMapSubmonoid T P.primeCompl local notation3 "Tₚ" => Localization P'' variable [Algebra S T] [Algebra R T] [IsScalarTower R S T] instance : IsLocalization (algebraMapSubmonoid T P') Tₚ := by rw [show algebraMapSubmonoid T P' = P'' by simp] exact Localization.isLocalization /-- Let `R ⊆ S ⊆ T` be a tower of rings. Let `Sₚ` and `Tₚ` denote the localizations of `S` and `T` at the prime ideal `P` of `R`. Then `Tₚ` is a `Sₚ`-algebra. This cannot be an instance since it creates a diamond when `S = T`. -/ noncomputable abbrev Localization.AtPrime.algebra_localization_localization : Algebra Sₚ Tₚ := localizationAlgebra P' T attribute [local instance] Localization.AtPrime.algebra_localization_localization instance : IsScalarTower S Sₚ Tₚ := IsScalarTower.of_algebraMap_eq' <| by rw [RingHom.algebraMap_toAlgebra, IsLocalization.map_comp, ← IsScalarTower.algebraMap_eq] instance : IsScalarTower R Sₚ Tₚ := IsScalarTower.of_algebraMap_eq' <| by rw [IsScalarTower.algebraMap_eq R S Sₚ, ← RingHom.comp_assoc, ← IsScalarTower.algebraMap_eq S, ← IsScalarTower.algebraMap_eq] instance [Module.Finite S T] : Module.Finite Sₚ Tₚ := Module.Finite.of_isLocalization S T P' instance [NoZeroSMulDivisors S T] : NoZeroSMulDivisors Sₚ Tₚ := NoZeroSMulDivisors_of_isLocalization S T Sₚ Tₚ <| algebraMapSubmonoid_le_nonZeroDivisors_of_faithfulSMul _ <| Ideal.primeCompl_le_nonZeroDivisors P instance [Algebra.IsIntegral R S] : Algebra.IsIntegral Rₚ Sₚ := Algebra.isIntegral_def.mpr <| (algebraMap_eq_map_map_submonoid P.primeCompl S Rₚ Sₚ ▸ isIntegral_localization : (algebraMap Rₚ Sₚ).IsIntegral) variable [NoZeroSMulDivisors R T] instance : IsScalarTower Rₚ Sₚ Tₚ := by refine ⟨fun a b c ↦ a.ind fun ⟨a₁, a₂⟩ ↦ ?_⟩ have : a₂.val ≠ 0 := nonZeroDivisors.ne_zero <| Ideal.primeCompl_le_nonZeroDivisors P <| a₂.prop rw [← smul_right_inj this, ← _root_.smul_assoc (M := R) (N := Sₚ), ← _root_.smul_assoc (M := R) (α := Sₚ), ← _root_.smul_assoc (M := R) (α := Tₚ), Localization.smul_mk, smul_eq_mul, Localization.mk_eq_mk', IsLocalization.mk'_mul_cancel_left, algebraMap_smul, algebraMap_smul, _root_.smul_assoc] instance [NoZeroSMulDivisors S T] [Algebra.IsSeparable L F] : Algebra.IsSeparable (FractionRing Sₚ) (FractionRing Tₚ) := by refine FractionRing.isSeparable_of_isLocalization T Sₚ Tₚ (M := P') ?_ apply algebraMapSubmonoid_le_nonZeroDivisors_of_faithfulSMul exact fun _ h ↦ mem_nonZeroDivisors_of_ne_zero <| ne_of_mem_of_not_mem h <| by simp
.lake/packages/mathlib/Mathlib/RingTheory/DedekindDomain/Different.lean
import Mathlib.NumberTheory.RamificationInertia.Unramified import Mathlib.RingTheory.Conductor import Mathlib.RingTheory.FractionalIdeal.Extended import Mathlib.RingTheory.Trace.Quotient /-! # 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`. - `not_dvd_differentIdeal_iff`: A prime does not divide the different ideal iff it is unramified (in the sense of `Algebra.IsUnramifiedAt`). - `differentIdeal_eq_differentIdeal_mul_differentIdeal`: Transitivity of the different ideal. ## TODO - Show properties of the different ideal -/ open Module universe u attribute [local instance] FractionRing.liftAlgebra FractionRing.isScalarTower_liftAlgebra Ideal.Quotient.field 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 Pointwise Polynomial Submodule 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 := forall₂_congr fun _ _ ↦ mem_one 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 restrictScalars_traceDual {I : Submodule B L} : Iᵛ.restrictScalars A = (Algebra.traceForm K L).dualSubmodule (I.restrictScalars A) := rfl variable (A) in /-- If the module `I` is spanned by the basis `b`, then its `traceDual` module is spanned by `b.traceDual`. -/ theorem traceDual_span_of_basis [FiniteDimensional K L] [Algebra.IsSeparable K L] (I : Submodule B L) {ι : Type*} [Finite ι] [DecidableEq ι] (b : Basis ι K L) (hb : I.restrictScalars A = Submodule.span A (Set.range b)) : (traceDual A K I).restrictScalars A = span A (Set.range b.traceDual) := by rw [restrictScalars_traceDual, hb] exact (traceForm K L).dualSubmodule_span_of_basis (traceForm_nondegenerate K L) b @[simp] lemma traceDual_bot : (⊥ : Submodule B L)ᵛ = ⊤ := by ext; simp [mem_traceDual, -RingHom.mem_range] 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_eq_top, _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] [FaithfulSMul 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 change 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 [traceDual, Submodule.mem_comap, Submodule.mem_mk] apply (FractionRing.algEquiv B L).forall_congr simp only [restrictScalars_mem, LinearEquiv.coe_coe, AlgEquiv.coe_symm_toLinearEquiv, traceForm_apply, mem_one, AlgEquiv.toEquiv_eq_coe, EquivLike.coe_coe, mem_comap, 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 · ext exact IsFractionRing.algEquiv_commutes (FractionRing.algEquiv A K) (FractionRing.algEquiv B L) _ simp only [AlgEquiv.toRingEquiv_eq_coe, map_mul, AlgEquiv.coe_ringEquiv, AlgEquiv.apply_symm_apply, ← AlgEquiv.symm_toRingEquiv, 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 _ _ ↦ mem_one.trans 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, one_eq_range] rintro _ ⟨x, ⟨x, rfl⟩, rfl⟩ rw [mem_one] 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 intro j k rw [updateCol_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) variable [IsDomain A] [IsFractionRing B L] [Nontrivial B] [NoZeroDivisors B] namespace FractionalIdeal open scoped Classical in /-- The dual of a non-zero fractional ideal is the dual of the submodule under the trace form. -/ 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 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]; exact forall₂_congr fun _ _ ↦ mem_one 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 rw [mem_one] 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] 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 := by classical exact 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] rw [inv_le_comm₀ (by simpa [pos_iff_ne_zero]) (by simpa [pos_iff_ne_zero])] exact inv_le_dual .. 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 · rw [le_mul_inv_iff₀ (pos_iff_ne_zero.2 hI), ← 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 variable (A K B L) attribute [local instance] SMulCommClass.of_commMonoid variable (C M : Type*) [CommRing C] [IsDedekindDomain C] [Field M] [Algebra C M] [IsFractionRing C M] [Algebra A C] [Algebra B C] [Algebra A M] [Algebra B M] [Algebra K M] [Algebra L M] [IsScalarTower A C M] [IsScalarTower A K M] [IsScalarTower B C M] [IsScalarTower B L M] [IsScalarTower K L M] [IsIntegralClosure C A M] [FiniteDimensional K M] [FiniteDimensional L M] [Algebra.IsSeparable K M] theorem trace_mem_dual_one (x : M) (hx : x ∈ dual A K (1 : FractionalIdeal C⁰ M)) : Algebra.trace L M x ∈ dual A K (1 : FractionalIdeal B⁰ L) := by simp only [ne_eq, one_ne_zero, not_false_eq_true, mem_dual, mem_one_iff, traceForm_apply, RingHom.mem_range, forall_exists_index, forall_apply_eq_imp_iff, mul_comm _ (algebraMap _ _ _), ← Algebra.smul_def, ← LinearMap.map_smul_of_tower, Algebra.trace_trace] at hx ⊢ simpa using fun b ↦ hx (algebraMap B C b) variable [IsIntegralClosure C B M] [Algebra.IsSeparable L M] theorem smul_mem_dual_one {x : L} (hx : x ∈ dual A K (1 : FractionalIdeal B⁰ L)) {y : M} (hy : y ∈ dual B L (1 : FractionalIdeal C⁰ M)) : x • y ∈ dual A K (1 : FractionalIdeal C⁰ M) := by simp only [ne_eq, one_ne_zero, not_false_eq_true, mem_dual, mem_one_iff, traceForm_apply, RingHom.mem_range, forall_exists_index, forall_apply_eq_imp_iff, mul_comm _ (algebraMap _ _ _), ← Algebra.smul_def] at hx hy ⊢ intro c obtain ⟨b, hb⟩ := hy c obtain ⟨a, ha⟩ := hx b use a simpa [Algebra.smul_def b, hb, mul_comm _ x, ← smul_eq_mul, ← (Algebra.trace L M).map_smul, Algebra.trace_trace, -id.smul_eq_mul, smul_comm x c y] using ha variable [NoZeroSMulDivisors B C] theorem dual_eq_dual_mul_dual : dual A K (1 : FractionalIdeal C⁰ M) = dual B L (1 : FractionalIdeal C⁰ M) * (dual A K (1 : FractionalIdeal B⁰ L)).extendedHomₐ M C := by have := IsIntegralClosure.isLocalization B L M C have h : B⁰ ≤ Submonoid.comap (algebraMap B C) C⁰ := nonZeroDivisors_le_comap_nonZeroDivisors_of_injective _ <| FaithfulSMul.algebraMap_injective _ _ have h_alg {x : L} : algebraMap L M x = IsLocalization.map M (algebraMap B C) h x := IsLocalization.algebraMap_apply_eq_map_map_submonoid B⁰ C L M x refine le_antisymm ?_ ?_ · intro x hx dsimp only [val_eq_coe] at hx ⊢ rw [mem_coe, ← spanSingleton_le_iff_mem, ← mul_inv_le_iff₀ (bot_lt_iff_ne_bot.mpr (by simp [-extendedHom_apply])), ← map_inv₀, ← FractionalIdeal.coe_le_coe, extendedHom_apply, coe_mul, coe_spanSingleton, coe_extended_eq_span, coe_dual_one, span_mul_span, span_le] rintro _ ⟨x, rfl, _, ⟨a, ha, rfl⟩, rfl⟩ _ ⟨m, rfl⟩ simp only [← h_alg, mul_comm _ (algebraMap _ _ _), ← Algebra.smul_def a, map_smul, LinearMap.toSpanSingleton_apply, Algebra.smul_def m, mul_one, LinearMap.smul_apply, traceForm_apply, smul_eq_mul] rw [← FractionalIdeal.coe_one (S := B⁰)] refine (mem_inv_iff (by simp)).mp ha _ (trace_mem_dual_one A K L B C M _ ?_) exact Algebra.smul_def m x ▸ smul_mem _ _ hx · rw [← FractionalIdeal.coe_le_coe, coe_mul, extendedHom_apply, coe_extended_eq_span, ← span_eq (coeToSubmodule _), span_mul_span, span_le] rintro _ ⟨a, ha, _, ⟨b, hb, rfl⟩, rfl⟩ simp only [SetLike.mem_coe, mem_coe, ← h_alg, mul_comm a, ← Algebra.smul_def] at ha hb ⊢ exact smul_mem_dual_one A K L B C M hb ha end FractionalIdeal section IsIntegrallyClosed variable (B) variable [IsIntegrallyClosed A] [IsDedekindDomain B] [NoZeroSMulDivisors A 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`. -/ noncomputable def differentIdeal : Ideal B := (1 / Submodule.traceDual A (FractionRing A) 1 : Submodule B (FractionRing B)).comap (Algebra.linearMap B (FractionRing B)) lemma coeSubmodule_differentIdeal_fractionRing [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, Submodule.one_eq_range] using this · exact one_ne_zero · exact one_ne_zero section variable [IsFractionRing B L] lemma coeSubmodule_differentIdeal : 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 : ↑(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} theorem differentIdeal_ne_bot [Module.Finite A B] [Algebra.IsSeparable (FractionRing A) (FractionRing B)] : differentIdeal A B ≠ ⊥ := by let K := FractionRing A let L := FractionRing B have : IsLocalization (Algebra.algebraMapSubmonoid B A⁰) L := IsIntegralClosure.isLocalization _ K _ _ have : FiniteDimensional K L := .of_isLocalization A B A⁰ rw [ne_eq, ← FractionalIdeal.coeIdeal_inj (K := L), coeIdeal_differentIdeal (K := K)] simp lemma differentialIdeal_le_fractionalIdeal_iff {I : FractionalIdeal B⁰ L} (hI : I ≠ 0) : 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 ≠ ⊥) : 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 B L) open FractionalIdeal in /-- Transitivity of the different ideal. -/ theorem differentIdeal_eq_differentIdeal_mul_differentIdeal (C : Type*) [IsDomain B] [CommRing C] [Algebra B C] [Algebra A C] [IsDedekindDomain C] [Module.Finite A B] [Module.Finite A C] [Module.Finite B C] [NoZeroSMulDivisors A C] [NoZeroSMulDivisors B C] [IsScalarTower A B C] [Algebra.IsSeparable (FractionRing A) (FractionRing C)] : differentIdeal A C = differentIdeal B C * (differentIdeal A B).map (algebraMap B C) := by have : Algebra.IsSeparable (FractionRing B) (FractionRing C) := isSeparable_tower_top_of_isSeparable (FractionRing A) _ _ have : Algebra.IsSeparable (FractionRing A) (FractionRing B) := isSeparable_tower_bot_of_isSeparable _ _ (FractionRing C) rw [← coeIdeal_inj (K := FractionRing C), coeIdeal_mul, coeIdeal_differentIdeal A (FractionRing A), coeIdeal_differentIdeal B (FractionRing B)] rw [← extendedHomₐ_coeIdeal_eq_map (K := FractionRing B), coeIdeal_differentIdeal A (FractionRing A), map_inv₀, ← mul_inv, ← inv_eq_iff_eq_inv, inv_inv] exact dual_eq_dual_mul_dual A (FractionRing A) (FractionRing B) B C (FractionRing C) variable {B L} 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 hnondeg : (traceForm K L).Nondegenerate := traceForm_nondegenerate K L have hpb : ⇑(LinearMap.BilinForm.dualBasis (traceForm K L) hnondeg pb.basis) = _ := _root_.funext (Basis.traceDual_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 [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 _ hnondeg, Submodule.smul_span, hpb] change _ = 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 hi end variable (L) {B} open Polynomial Pointwise in lemma conductor_mul_differentIdeal (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', Submodule.one_eq_range, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂, ← 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 (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 end IsIntegrallyClosed section variable (L) variable [IsFractionRing B L] [IsDedekindDomain A] [IsDedekindDomain B] [NoZeroSMulDivisors A B] [Module.Finite A B] include K L in lemma pow_sub_one_dvd_differentIdeal_aux {p : Ideal A} [p.IsMaximal] (P : Ideal B) {e : ℕ} (he : e ≠ 0) (hp : p ≠ ⊥) (hP : P ^ e ∣ p.map (algebraMap A B)) : P ^ (e - 1) ∣ differentIdeal A B := by obtain ⟨a, ha⟩ := (pow_dvd_pow _ (Nat.sub_le e 1)).trans hP have hp' := (Ideal.map_eq_bot_iff_of_injective (FaithfulSMul.algebraMap_injective A B)).not.mpr hp have habot : a ≠ ⊥ := fun ha' ↦ hp' (by simpa [ha'] using ha) have hPbot : P ≠ ⊥ := by rintro rfl; apply hp' rwa [← Ideal.zero_eq_bot, zero_pow he, zero_dvd_iff, Ideal.zero_eq_bot] at hP have : p.map (algebraMap A B) ∣ a ^ e := by obtain ⟨b, hb⟩ := hP apply_fun (· ^ e : Ideal B → _) at ha apply_fun (· ^ (e - 1) : Ideal B → _) at hb simp only [mul_pow, ← pow_mul, mul_comm e] at ha hb conv_lhs at ha => rw [← Nat.sub_add_cancel (Nat.one_le_iff_ne_zero.mpr he)] rw [pow_add, hb, mul_assoc, mul_right_inj' (pow_ne_zero _ hPbot), pow_one, mul_comm] at ha exact ⟨_, ha.symm⟩ suffices ∀ x ∈ a, intTrace A B x ∈ p by have hP : ((P ^ (e - 1) :)⁻¹ : FractionalIdeal B⁰ L) = a / p.map (algebraMap A B) := by apply inv_involutive.injective simp only [inv_inv, ha, FractionalIdeal.coeIdeal_mul, inv_div, mul_div_assoc] rw [div_self (by simpa), mul_one] rw [Ideal.dvd_iff_le, differentialIdeal_le_iff (K := K) (L := L) (pow_ne_zero _ hPbot), hP, Submodule.map_le_iff_le_comap] intro x hx rw [Submodule.restrictScalars_mem, FractionalIdeal.mem_coe, FractionalIdeal.mem_div_iff_of_ne_zero (by simpa using hp')] at hx rw [Submodule.mem_comap, LinearMap.coe_restrictScalars, ← FractionalIdeal.coe_one, ← div_self (G₀ := FractionalIdeal A⁰ K) (a := p) (by simpa using hp), FractionalIdeal.mem_coe, FractionalIdeal.mem_div_iff_of_ne_zero (by simpa using hp)] simp only [FractionalIdeal.mem_coeIdeal, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂] at hx intro y hy' obtain ⟨y, hy, rfl : algebraMap A K _ = _⟩ := (FractionalIdeal.mem_coeIdeal _).mp hy' obtain ⟨z, hz, hz'⟩ := hx _ (Ideal.mem_map_of_mem _ hy) have : trace K L (algebraMap B L z) ∈ (p : FractionalIdeal A⁰ K) := by rw [← algebraMap_intTrace (A := A)] exact ⟨intTrace A B z, this z hz, rfl⟩ rwa [mul_comm, ← smul_eq_mul, ← LinearMap.map_smul, Algebra.smul_def, mul_comm, ← IsScalarTower.algebraMap_apply, IsScalarTower.algebraMap_apply A B L, ← hz'] intro x hx rw [← Ideal.Quotient.eq_zero_iff_mem, ← trace_quotient_eq_of_isDedekindDomain, ← isNilpotent_iff_eq_zero] refine isNilpotent_trace_of_isNilpotent ⟨e, ?_⟩ rw [← map_pow, Ideal.Quotient.eq_zero_iff_mem] exact (Ideal.dvd_iff_le.mp this) <| Ideal.pow_mem_pow hx _ lemma pow_sub_one_dvd_differentIdeal [Algebra.IsSeparable (FractionRing A) (FractionRing B)] {p : Ideal A} [p.IsMaximal] (P : Ideal B) (e : ℕ) (hp : p ≠ ⊥) (hP : P ^ e ∣ p.map (algebraMap A B)) : P ^ (e - 1) ∣ differentIdeal A B := by have : IsLocalization (algebraMapSubmonoid B A⁰) (FractionRing B) := IsIntegralClosure.isLocalization _ (FractionRing A) _ _ have : FiniteDimensional (FractionRing A) (FractionRing B) := .of_isLocalization A B A⁰ by_cases he : e = 0 · rw [he, pow_zero]; exact one_dvd _ exact pow_sub_one_dvd_differentIdeal_aux A (FractionRing A) (FractionRing B) _ he hp hP theorem not_dvd_differentIdeal_of_intTrace_not_mem [Algebra.IsSeparable (FractionRing A) (FractionRing B)] {p : Ideal A} (P Q : Ideal B) (hP : P * Q = Ideal.map (algebraMap A B) p) (x : B) (hxQ : x ∈ Q) (hx : Algebra.intTrace A B x ∉ p) : ¬ P ∣ differentIdeal A B := by by_cases hp : p = ⊥ · subst hp simp only [Ideal.map_bot, Ideal.mul_eq_bot] at hP obtain (rfl | rfl) := hP · rw [← Ideal.zero_eq_bot, zero_dvd_iff] exact differentIdeal_ne_bot · obtain rfl := hxQ simp at hx letI : Algebra (A ⧸ p) (B ⧸ Q) := Ideal.Quotient.algebraQuotientOfLEComap (by rw [← Ideal.map_le_iff_le_comap, ← hP] exact Ideal.mul_le_left) let K := FractionRing A let L := FractionRing B have : IsLocalization (Algebra.algebraMapSubmonoid B A⁰) L := IsIntegralClosure.isLocalization _ K _ _ have : FiniteDimensional K L := .of_isLocalization A B A⁰ rw [Ideal.dvd_iff_le] intro H replace H := (mul_le_mul_right' H Q).trans_eq hP replace H := (FractionalIdeal.coeIdeal_le_coeIdeal' _ (P := L) le_rfl).mpr H rw [FractionalIdeal.coeIdeal_mul, coeIdeal_differentIdeal A K] at H replace H := mul_le_mul_left' H (FractionalIdeal.dual A K 1) simp only [ne_eq, FractionalIdeal.dual_eq_zero_iff, one_ne_zero, not_false_eq_true, mul_inv_cancel_left₀] at H apply hx suffices Algebra.trace K L (algebraMap B L x) ∈ (p : FractionalIdeal A⁰ K) by obtain ⟨y, hy, e⟩ := this rw [← Algebra.algebraMap_intTrace (A := A), Algebra.linearMap_apply, (IsLocalization.injective _ le_rfl).eq_iff] at e exact e ▸ hy refine FractionalIdeal.mul_induction_on (H ⟨_, hxQ, rfl⟩) ?_ ?_ · rintro x hx _ ⟨y, hy, rfl⟩ induction hy using Submodule.span_induction generalizing x with | mem y h => obtain ⟨y, hy, rfl⟩ := h obtain ⟨z, hz⟩ := (FractionalIdeal.mem_dual (by simp)).mp hx 1 ⟨1, trivial, (algebraMap B L).map_one⟩ simp only [Algebra.traceForm_apply, mul_one] at hz refine ⟨z * y, Ideal.mul_mem_left _ _ hy, ?_⟩ rw [Algebra.linearMap_apply, Algebra.linearMap_apply, mul_comm x, ← IsScalarTower.algebraMap_apply, ← Algebra.smul_def, LinearMap.map_smul_of_tower, ← hz, Algebra.smul_def, map_mul, mul_comm] | zero => simp | add y z _ _ hy hz => simp only [map_add, mul_add] exact Submodule.add_mem _ (hy x hx) (hz x hx) | smul y z hz IH => simpa [Algebra.smul_def, mul_assoc, -FractionalIdeal.mem_coeIdeal, mul_left_comm x] using IH _ (Submodule.smul_mem _ y hx) · simp only [map_add] exact fun _ _ h₁ h₂ ↦ Submodule.add_mem _ h₁ h₂ open nonZeroDivisors theorem not_dvd_differentIdeal_of_isCoprime_of_isSeparable [Algebra.IsSeparable (FractionRing A) (FractionRing B)] {p : Ideal A} [p.IsMaximal] (P Q : Ideal B) [P.IsMaximal] [P.LiesOver p] (hPQ : IsCoprime P Q) (hP : P * Q = Ideal.map (algebraMap A B) p) [Algebra.IsSeparable (A ⧸ p) (B ⧸ P)] : ¬ P ∣ differentIdeal A B := by letI : Algebra (A ⧸ p) (B ⧸ Q) := Ideal.Quotient.algebraQuotientOfLEComap (by rw [← Ideal.map_le_iff_le_comap, ← hP] exact Ideal.mul_le_left) have : IsScalarTower A (A ⧸ p) (B ⧸ Q) := .of_algebraMap_eq' rfl have : Module.Finite (A ⧸ p) (B ⧸ Q) := Module.Finite.of_restrictScalars_finite A (A ⧸ p) (B ⧸ Q) letI e : (B ⧸ p.map (algebraMap A B)) ≃ₐ[A ⧸ p] ((B ⧸ P) × B ⧸ Q) := { __ := (Ideal.quotEquivOfEq hP.symm).trans (Ideal.quotientMulEquivQuotientProd P Q hPQ), commutes' := Quotient.ind fun _ ↦ rfl } obtain ⟨x, hx⟩ : ∃ x, Algebra.trace (A ⧸ p) (B ⧸ P) x ≠ 0 := by simpa [LinearMap.ext_iff] using Algebra.trace_ne_zero (A ⧸ p) (B ⧸ P) obtain ⟨y, hy⟩ := Ideal.Quotient.mk_surjective (e.symm (x, 0)) refine not_dvd_differentIdeal_of_intTrace_not_mem A P Q hP y ?_ ?_ · simpa [e, Ideal.Quotient.eq_zero_iff_mem] using congr((e $hy).2) · rw [← Ideal.Quotient.eq_zero_iff_mem, ← Algebra.trace_quotient_eq_of_isDedekindDomain, hy, Algebra.trace_eq_of_algEquiv, Algebra.trace_prod_apply] simpa theorem not_dvd_differentIdeal_of_isCoprime [Algebra.IsSeparable (FractionRing A) (FractionRing B)] {p : Ideal A} [p.IsMaximal] [Finite (A ⧸ p)] (P Q : Ideal B) [P.IsMaximal] (hPQ : IsCoprime P Q) (hP : P * Q = Ideal.map (algebraMap A B) p) : ¬ P ∣ differentIdeal A B := by have : P.LiesOver p := by constructor refine ‹p.IsMaximal›.eq_of_le ?_ ?_ · simpa using ‹P.IsMaximal›.ne_top · rw [← Ideal.map_le_iff_le_comap, ← hP] exact Ideal.mul_le_right exact not_dvd_differentIdeal_of_isCoprime_of_isSeparable A P Q hPQ hP lemma dvd_differentIdeal_of_not_isSeparable [Algebra.IsSeparable (FractionRing A) (FractionRing B)] {p : Ideal A} [p.IsMaximal] (hp : p ≠ ⊥) (P : Ideal B) [P.IsMaximal] [P.LiesOver p] (H : ¬ Algebra.IsSeparable (A ⧸ p) (B ⧸ P)) : P ∣ differentIdeal A B := by obtain ⟨a, ha⟩ : P ∣ p.map (algebraMap A B) := Ideal.dvd_iff_le.mpr (Ideal.map_le_iff_le_comap.mpr Ideal.LiesOver.over.le) by_cases hPa : P ∣ a · simpa using pow_sub_one_dvd_differentIdeal A P 2 hp (by rw [pow_two, ha]; exact mul_dvd_mul_left _ hPa) let K := FractionRing A let L := FractionRing B have : IsLocalization (Algebra.algebraMapSubmonoid B A⁰) L := IsIntegralClosure.isLocalization _ K _ _ have : FiniteDimensional K L := .of_isLocalization A B A⁰ have hp' := (Ideal.map_eq_bot_iff_of_injective (FaithfulSMul.algebraMap_injective A B)).not.mpr hp have habot : a ≠ ⊥ := fun ha' ↦ hp' (by simpa [ha'] using ha) have hPbot : P ≠ ⊥ := by rintro rfl; apply hp' rwa [Ideal.bot_mul] at ha suffices ∀ x ∈ a, Algebra.intTrace A B x ∈ p by have hP : ((P :)⁻¹ : FractionalIdeal B⁰ L) = a / p.map (algebraMap A B) := by apply inv_involutive.injective simp only [ha, FractionalIdeal.coeIdeal_mul, inv_div, mul_div_assoc] rw [div_self (by simpa), mul_one, inv_inv] rw [Ideal.dvd_iff_le, differentialIdeal_le_iff (K := K) (L := L) hPbot, hP, Submodule.map_le_iff_le_comap] intro x hx rw [Submodule.restrictScalars_mem, FractionalIdeal.mem_coe, FractionalIdeal.mem_div_iff_of_ne_zero (by simpa using hp')] at hx rw [Submodule.mem_comap, LinearMap.coe_restrictScalars, ← FractionalIdeal.coe_one, ← div_self (G₀ := FractionalIdeal A⁰ K) (a := p) (by simpa using hp), FractionalIdeal.mem_coe, FractionalIdeal.mem_div_iff_of_ne_zero (by simpa using hp)] simp only [FractionalIdeal.mem_coeIdeal, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂] at hx intro y hy' obtain ⟨y, hy, rfl : algebraMap A K _ = _⟩ := (FractionalIdeal.mem_coeIdeal _).mp hy' obtain ⟨z, hz, hz'⟩ := hx _ (Ideal.mem_map_of_mem _ hy) have : Algebra.trace K L (algebraMap B L z) ∈ (p : FractionalIdeal A⁰ K) := by rw [← Algebra.algebraMap_intTrace (A := A)] exact ⟨Algebra.intTrace A B z, this z hz, rfl⟩ rwa [mul_comm, ← smul_eq_mul, ← LinearMap.map_smul, Algebra.smul_def, mul_comm, ← IsScalarTower.algebraMap_apply, IsScalarTower.algebraMap_apply A B L, ← hz'] intro x hx rw [← Ideal.Quotient.eq_zero_iff_mem, ← Algebra.trace_quotient_eq_of_isDedekindDomain] letI : Algebra (A ⧸ p) (B ⧸ a) := Ideal.Quotient.algebraQuotientOfLEComap (Ideal.map_le_iff_le_comap.mp (Ideal.dvd_iff_le.mp ⟨_, ha.trans (mul_comm _ _)⟩)) have : IsScalarTower A (A ⧸ p) (B ⧸ a) := .of_algebraMap_eq' rfl have : Module.Finite (A ⧸ p) (B ⧸ a) := .of_restrictScalars_finite A _ _ have := ((Ideal.prime_iff_isPrime hPbot).mpr inferInstance) rw [← this.irreducible.gcd_eq_one_iff, ← Ideal.isCoprime_iff_gcd] at hPa letI e : (B ⧸ p.map (algebraMap A B)) ≃ₐ[A ⧸ p] ((B ⧸ P) × B ⧸ a) := { __ := (Ideal.quotEquivOfEq ha).trans (Ideal.quotientMulEquivQuotientProd P a hPa), commutes' := Quotient.ind fun _ ↦ rfl } have hx' : (e (Ideal.Quotient.mk _ x)).2 = 0 := by simpa [e, Ideal.Quotient.eq_zero_iff_mem] rw [← Algebra.trace_eq_of_algEquiv e, Algebra.trace_prod_apply, Algebra.trace_eq_zero_of_not_isSeparable H, LinearMap.zero_apply, zero_add, hx', map_zero] variable {A} /-- A prime does not divide the different ideal iff it is unramified. -/ theorem not_dvd_differentIdeal_iff [Algebra.IsSeparable (FractionRing A) (FractionRing B)] {P : Ideal B} [P.IsPrime] : ¬ P ∣ differentIdeal A B ↔ Algebra.IsUnramifiedAt A P := by classical rcases eq_or_ne P ⊥ with rfl | hPbot · simp_rw [← Ideal.zero_eq_bot, zero_dvd_iff] simp only [Submodule.zero_eq_bot, differentIdeal_ne_bot, not_false_eq_true, true_iff] let K := FractionRing A let L := FractionRing B have : FiniteDimensional K L := .of_isLocalization A B A⁰ have : IsLocalization B⁰ (Localization.AtPrime (⊥ : Ideal B)) := by convert (inferInstanceAs (IsLocalization (⊥ : Ideal B).primeCompl (Localization.AtPrime (⊥ : Ideal B)))) ext; simp [Ideal.primeCompl] refine (Algebra.FormallyUnramified.iff_of_equiv (A := L) ((IsLocalization.algEquiv B⁰ _ _).restrictScalars A)).mp ?_ have : Algebra.FormallyUnramified K L := by rwa [Algebra.FormallyUnramified.iff_isSeparable] refine .comp A K L have hp : P.under A ≠ ⊥ := mt Ideal.eq_bot_of_comap_eq_bot hPbot have hp' := (Ideal.map_eq_bot_iff_of_injective (FaithfulSMul.algebraMap_injective A B)).not.mpr hp have := Ideal.IsPrime.isMaximal inferInstance hPbot constructor · intro H · rw [Algebra.isUnramifiedAt_iff_map_eq (p := P.under A)] constructor · suffices Algebra.IsSeparable (A ⧸ P.under A) (B ⧸ P) by infer_instance contrapose! H exact dvd_differentIdeal_of_not_isSeparable A hp P H · rw [← Ideal.IsDedekindDomain.ramificationIdx_eq_one_iff hPbot Ideal.map_comap_le] apply Ideal.ramificationIdx_spec · simp [Ideal.map_le_iff_le_comap] · contrapose! H rw [← pow_one P, show 1 = 2 - 1 by simp] apply pow_sub_one_dvd_differentIdeal _ _ _ hp simpa [Ideal.dvd_iff_le] using H · intro H obtain ⟨Q, h₁, h₂⟩ := Ideal.eq_prime_pow_mul_coprime hp' P rw [← Ideal.IsDedekindDomain.ramificationIdx_eq_normalizedFactors_count hp' ‹_› hPbot, Ideal.ramificationIdx_eq_one_of_isUnramifiedAt hPbot, pow_one] at h₂ obtain ⟨h₃, h₄⟩ := (Algebra.isUnramifiedAt_iff_map_eq (p := P.under A) _ _).mp H exact not_dvd_differentIdeal_of_isCoprime_of_isSeparable A P Q (Ideal.isCoprime_iff_sup_eq.mpr h₁) h₂.symm /-- A prime divides the different ideal iff it is ramified. -/ theorem dvd_differentIdeal_iff [Algebra.IsSeparable (FractionRing A) (FractionRing B)] {P : Ideal B} [P.IsPrime] : P ∣ differentIdeal A B ↔ ¬ Algebra.IsUnramifiedAt A P := iff_not_comm.mp not_dvd_differentIdeal_iff.symm end
.lake/packages/mathlib/Mathlib/RingTheory/DedekindDomain/FiniteAdeleRing.lean
import Mathlib.RingTheory.DedekindDomain.AdicValuation import Mathlib.RingTheory.DedekindDomain.Factorization import Mathlib.Topology.Algebra.RestrictedProduct.TopologicalSpace /-! # The finite adèle ring of a Dedekind domain We define the ring of finite adèles of a Dedekind domain `R`. ## Main definitions - `IsDedekindDomain.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öhlich, *Algebraic Number Theory*][cassels1967algebraic] ## Tags finite adèle ring, dedekind domain -/ variable (R : Type*) [CommRing R] [IsDedekindDomain R] {K : Type*} [Field K] [Algebra R K] [IsFractionRing R K] namespace IsDedekindDomain /-- The support of an element `k` of the field of fractions of a Dedekind domain is the set of maximal ideals of the Dedekind domain at which `k` is not integral. -/ def HeightOneSpectrum.Support (k : K) : Set (HeightOneSpectrum R) := {v : HeightOneSpectrum R | 1 < v.valuation K k} /-- The support of an element of the field of fractions of a Dedekind domain is finite. -/ lemma HeightOneSpectrum.Support.finite (k : K) : (Support R k).Finite := by -- We write k=n/d. obtain ⟨⟨n, ⟨d, hd⟩⟩, hk⟩ := IsLocalization.surj (nonZeroDivisors R) k have hd' : d ≠ 0 := nonZeroDivisors.ne_zero hd suffices {v : HeightOneSpectrum R | v.valuation K (algebraMap R K d) < 1}.Finite by apply Set.Finite.subset this intro v hv apply_fun v.valuation K at hk simp only [Valuation.map_mul, valuation_of_algebraMap] at hk rw [Set.mem_setOf_eq, valuation_of_algebraMap] have := intValuation_le_one v n contrapose! this rw [← hk, mul_comm] exact (lt_mul_of_one_lt_right (by simp) hv).trans_le <| mul_le_mul_of_nonneg_right this (by simp) simp_rw [valuation_lt_one_iff_dvd] apply Ideal.finite_factors simpa only [Submodule.zero_eq_bot, ne_eq, Ideal.span_singleton_eq_bot] end IsDedekindDomain noncomputable section open Function Set IsDedekindDomain.HeightOneSpectrum namespace IsDedekindDomain variable (K) open scoped RestrictedProduct /-! ### 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. -/ /-- If `K` is the field of fractions of the Dedekind domain `R` then `FiniteAdeleRing R K` is the ring of finite adeles of `K`, defined as the restricted product of the completions `K_v` with respect to the subrings `R_v`. Here `v` runs through the nonzero primes of `R` and the restricted product is the subring of `∏_v K_v` consisting of elements which are in `R_v` for all but finitely many `v`. -/ abbrev FiniteAdeleRing : Type _ := Πʳ v : HeightOneSpectrum R, [v.adicCompletion K, v.adicCompletionIntegers K] namespace FiniteAdeleRing /-- The canonical map from `K` to the finite adeles of `K`. The content of the existence of this map is the fact that an element `k` of `K` is integral at all but finitely many places, which is `IsDedekindDomain.HeightOneSpectrum.Support.finite R k`. -/ protected def algebraMap : K →+* FiniteAdeleRing R K where toFun k := ⟨fun i ↦ k, by simp only [Filter.eventually_cofinite, SetLike.mem_coe, mem_adicCompletionIntegers R K, adicCompletion, Valued.valuedCompletion_apply, not_le] exact HeightOneSpectrum.Support.finite R k⟩ map_one' := rfl map_mul' x y := Subtype.eq <| funext (fun v ↦ UniformSpace.Completion.coe_mul ((WithVal.equiv (valuation K v)).symm x) y) map_zero' := rfl map_add' x y := Subtype.eq <| funext (fun v ↦ UniformSpace.Completion.coe_add ((WithVal.equiv (valuation K v)).symm x) y) instance : Algebra K (FiniteAdeleRing R K) := (FiniteAdeleRing.algebraMap R K).toAlgebra instance : Algebra R (FiniteAdeleRing R K) := Algebra.compHom _ (algebraMap R K) instance : IsScalarTower R K (FiniteAdeleRing R K) := IsScalarTower.of_algebraMap_eq' rfl variable {R} in @[ext] lemma ext {a₁ a₂ : FiniteAdeleRing R K} (h : ∀ v, a₁ v = a₂ v) : a₁ = a₂ := Subtype.ext <| funext h instance : DFunLike (FiniteAdeleRing R K) (HeightOneSpectrum R) (adicCompletion K) where coe a := a.1 coe_injective' _a _b h := ext K (congrFun h) section Topology instance : IsTopologicalRing (FiniteAdeleRing R K) := haveI : Fact (∀ v : HeightOneSpectrum R, IsOpen (v.adicCompletionIntegers K : Set (v.adicCompletion K))) := ⟨fun _ ↦ Valued.isOpen_valuationSubring _⟩ RestrictedProduct.isTopologicalRing (fun (v : HeightOneSpectrum R) ↦ v.adicCompletion K) end Topology end FiniteAdeleRing end IsDedekindDomain