source
stringlengths
17
118
lean4
stringlengths
0
335k
.lake/packages/mathlib/Mathlib/Algebra/Module/Shrink.lean
import Mathlib.Algebra.Group.Shrink import Mathlib.Algebra.Module.TransferInstance /-! # Transfer module and algebra structures from `α` to `Shrink α` -/ -- FIXME: `to_additive` is incompatible with `noncomputable section`. -- See https://github.com/leanprover-community/mathlib4/issues/1074. suppress_compilation universe v variable {R α : Type*} [Small.{v} α] [Semiring R] [AddCommMonoid α] [Module R α] namespace Shrink instance : Module R (Shrink.{v} α) := (equivShrink α).symm.module R variable (R α) in /-- Shrinking `α` to a smaller universe preserves module structure. -/ @[simps!] def linearEquiv : Shrink.{v} α ≃ₗ[R] α := (equivShrink α).symm.linearEquiv _ end Shrink /-- A small module is linearly equivalent to its small model. -/ @[deprecated Shrink.linearEquiv (since := "2025-07-11")] def linearEquivShrink (α β) [Semiring α] [AddCommMonoid β] [Module α β] [Small β] : β ≃ₗ[α] Shrink β := ((equivShrink β).symm.linearEquiv α).symm
.lake/packages/mathlib/Mathlib/Algebra/Module/Injective.lean
import Mathlib.Algebra.Module.Shrink import Mathlib.LinearAlgebra.LinearPMap import Mathlib.Logic.Small.Basic import Mathlib.RingTheory.Ideal.Defs /-! # Injective modules ## Main definitions * `Module.Injective`: an `R`-module `Q` is injective if and only if every injective `R`-linear map descends to a linear map to `Q`, i.e. in the following diagram, if `f` is injective then there is an `R`-linear map `h : Y ⟶ Q` such that `g = h ∘ f` ``` X --- f ---> Y | | g v Q ``` * `Module.Baer`: an `R`-module `Q` satisfies Baer's criterion if any `R`-linear map from an `Ideal R` extends to an `R`-linear map `R ⟶ Q` ## Main statements * `Module.Baer.injective`: an `R`-module is injective if it is Baer. -/ assert_not_exists ModuleCat noncomputable section universe u v v' variable (R : Type u) [Ring R] (Q : Type v) [AddCommGroup Q] [Module R Q] /-- An `R`-module `Q` is injective if and only if every injective `R`-linear map descends to a linear map to `Q`, i.e. in the following diagram, if `f` is injective then there is an `R`-linear map `h : Y ⟶ Q` such that `g = h ∘ f` ``` X --- f ---> Y | | g v Q ``` -/ @[mk_iff] class Module.Injective : Prop where out : ∀ ⦃X Y : Type v⦄ [AddCommGroup X] [AddCommGroup Y] [Module R X] [Module R Y] (f : X →ₗ[R] Y) (_ : Function.Injective f) (g : X →ₗ[R] Q), ∃ h : Y →ₗ[R] Q, ∀ x, h (f x) = g x /-- An `R`-module `Q` satisfies Baer's criterion if any `R`-linear map from an `Ideal R` extends to an `R`-linear map `R ⟶ Q` -/ def Module.Baer : Prop := ∀ (I : Ideal R) (g : I →ₗ[R] Q), ∃ g' : R →ₗ[R] Q, ∀ (x : R) (mem : x ∈ I), g' x = g ⟨x, mem⟩ namespace Module.Baer variable {R Q} {M N : Type*} [AddCommGroup M] [AddCommGroup N] variable [Module R M] [Module R N] (i : M →ₗ[R] N) (f : M →ₗ[R] Q) lemma of_equiv (e : Q ≃ₗ[R] M) (h : Module.Baer R Q) : Module.Baer R M := fun I g ↦ have ⟨g', h'⟩ := h I (e.symm ∘ₗ g) ⟨e ∘ₗ g', by simpa [LinearEquiv.eq_symm_apply] using h'⟩ lemma congr (e : Q ≃ₗ[R] M) : Module.Baer R Q ↔ Module.Baer R M := ⟨of_equiv e, of_equiv e.symm⟩ /-- If we view `M` as a submodule of `N` via the injective linear map `i : M ↪ N`, then a submodule between `M` and `N` is a submodule `N'` of `N`. To prove Baer's criterion, we need to consider pairs of `(N', f')` such that `M ≤ N' ≤ N` and `f'` extends `f`. -/ structure ExtensionOf extends LinearPMap R N Q where le : LinearMap.range i ≤ domain is_extension : ∀ m : M, f m = toLinearPMap ⟨i m, le ⟨m, rfl⟩⟩ section Ext variable {i f} @[ext (iff := false)] theorem ExtensionOf.ext {a b : ExtensionOf i f} (domain_eq : a.domain = b.domain) (to_fun_eq : ∀ ⦃x : N⦄ ⦃ha : x ∈ a.domain⦄ ⦃hb : x ∈ b.domain⦄, a.toLinearPMap ⟨x, ha⟩ = b.toLinearPMap ⟨x, hb⟩) : a = b := by rcases a with ⟨a, a_le, e1⟩ congr exact LinearPMap.ext domain_eq to_fun_eq /-- A dependent version of `ExtensionOf.ext` -/ theorem ExtensionOf.dExt {a b : ExtensionOf i f} (domain_eq : a.domain = b.domain) (to_fun_eq : ∀ ⦃x : a.domain⦄ ⦃y : b.domain⦄, (x : N) = y → a.toLinearPMap x = b.toLinearPMap y) : a = b := ext domain_eq fun _ _ _ ↦ to_fun_eq rfl theorem ExtensionOf.dExt_iff {a b : ExtensionOf i f} : a = b ↔ ∃ _ : a.domain = b.domain, ∀ ⦃x : a.domain⦄ ⦃y : b.domain⦄, (x : N) = y → a.toLinearPMap x = b.toLinearPMap y := ⟨fun r => r ▸ ⟨rfl, fun _ _ h => congr_arg a.toFun <| mod_cast h⟩, fun ⟨h1, h2⟩ => ExtensionOf.dExt h1 h2⟩ end Ext instance : Min (ExtensionOf i f) where min X1 X2 := { X1.toLinearPMap ⊓ X2.toLinearPMap with le := fun x hx => (by rcases hx with ⟨x, rfl⟩ refine ⟨X1.le (Set.mem_range_self _), X2.le (Set.mem_range_self _), ?_⟩ rw [← X1.is_extension x, ← X2.is_extension x] : x ∈ X1.toLinearPMap.eqLocus X2.toLinearPMap) is_extension := fun _ => X1.is_extension _ } instance : SemilatticeInf (ExtensionOf i f) := Function.Injective.semilatticeInf ExtensionOf.toLinearPMap (fun X Y h ↦ ExtensionOf.ext (by rw [h]) <| by rw [h] intros rfl) fun X Y ↦ LinearPMap.ext rfl fun x y h => by congr variable {i f} theorem chain_linearPMap_of_chain_extensionOf {c : Set (ExtensionOf i f)} (hchain : IsChain (· ≤ ·) c) : IsChain (· ≤ ·) <| (fun x : ExtensionOf i f => x.toLinearPMap) '' c := by rintro _ ⟨a, a_mem, rfl⟩ _ ⟨b, b_mem, rfl⟩ neq exact hchain a_mem b_mem (ne_of_apply_ne _ neq) /-- The maximal element of every nonempty chain of `extension_of i f`. -/ def ExtensionOf.max {c : Set (ExtensionOf i f)} (hchain : IsChain (· ≤ ·) c) (hnonempty : c.Nonempty) : ExtensionOf i f := { LinearPMap.sSup _ (IsChain.directedOn <| chain_linearPMap_of_chain_extensionOf hchain) with le := by refine le_trans hnonempty.some.le <| (LinearPMap.le_sSup _ <| (Set.mem_image _ _ _).mpr ⟨hnonempty.some, hnonempty.choose_spec, rfl⟩).1 is_extension := fun m => by refine Eq.trans (hnonempty.some.is_extension m) ?_ symm generalize_proofs _ _ h1 exact LinearPMap.sSup_apply (IsChain.directedOn <| chain_linearPMap_of_chain_extensionOf hchain) ((Set.mem_image _ _ _).mpr ⟨hnonempty.some, hnonempty.choose_spec, rfl⟩) ⟨i m, h1⟩ } theorem ExtensionOf.le_max {c : Set (ExtensionOf i f)} (hchain : IsChain (· ≤ ·) c) (hnonempty : c.Nonempty) (a : ExtensionOf i f) (ha : a ∈ c) : a ≤ ExtensionOf.max hchain hnonempty := LinearPMap.le_sSup (IsChain.directedOn <| chain_linearPMap_of_chain_extensionOf hchain) <| (Set.mem_image _ _ _).mpr ⟨a, ha, rfl⟩ variable (i f) [Fact <| Function.Injective i] instance ExtensionOf.inhabited : Inhabited (ExtensionOf i f) where default := { domain := LinearMap.range i toFun := { toFun := fun x => f x.2.choose map_add' := fun x y => by have eq1 : _ + _ = (x + y).1 := congr_arg₂ (· + ·) x.2.choose_spec y.2.choose_spec rw [← map_add, ← (x + y).2.choose_spec] at eq1 dsimp rw [← Fact.out (p := Function.Injective i) eq1, map_add] map_smul' := fun r x => by have eq1 : r • _ = (r • x).1 := congr_arg (r • ·) x.2.choose_spec rw [← LinearMap.map_smul, ← (r • x).2.choose_spec] at eq1 dsimp rw [← Fact.out (p := Function.Injective i) eq1, LinearMap.map_smul] } le := le_refl _ is_extension := fun m => by simp only [LinearPMap.mk_apply, LinearMap.coe_mk] dsimp apply congrArg exact Fact.out (p := Function.Injective i) (⟨i m, ⟨_, rfl⟩⟩ : LinearMap.range i).2.choose_spec.symm } /-- Since every nonempty chain has a maximal element, by Zorn's lemma, there is a maximal `extension_of i f`. -/ def extensionOfMax : ExtensionOf i f := (@zorn_le_nonempty (ExtensionOf i f) _ ⟨Inhabited.default⟩ fun _ hchain hnonempty => ⟨ExtensionOf.max hchain hnonempty, ExtensionOf.le_max hchain hnonempty⟩).choose theorem extensionOfMax_is_max : ∀ (a : ExtensionOf i f), extensionOfMax i f ≤ a → a = extensionOfMax i f := fun _ ↦ (@zorn_le_nonempty (ExtensionOf i f) _ ⟨Inhabited.default⟩ fun _ hchain hnonempty => ⟨ExtensionOf.max hchain hnonempty, ExtensionOf.le_max hchain hnonempty⟩).choose_spec.eq_of_ge -- Auxiliary definition: Lean looks for an instance of `Max (Type u)` if we would write -- `(x : (extensionOfMax i f).domain ⊔ (Submodule.span R {y}))`, so we encapsulate the cast instead. abbrev supExtensionOfMaxSingleton (y : N) : Submodule R N := (extensionOfMax i f).domain ⊔ (Submodule.span R {y}) variable {f} private theorem extensionOfMax_adjoin.aux1 {y : N} (x : supExtensionOfMaxSingleton i f y) : ∃ (a : (extensionOfMax i f).domain) (b : R), x.1 = a.1 + b • y := by have mem1 : x.1 ∈ (_ : Set _) := x.2 rw [Submodule.coe_sup] at mem1 rcases mem1 with ⟨a, a_mem, b, b_mem : b ∈ (Submodule.span R _ : Submodule R N), eq1⟩ rw [Submodule.mem_span_singleton] at b_mem rcases b_mem with ⟨z, eq2⟩ exact ⟨⟨a, a_mem⟩, z, by rw [← eq1, ← eq2]⟩ /-- If `x ∈ M ⊔ ⟨y⟩`, then `x = m + r • y`, `fst` pick an arbitrary such `m`. -/ def ExtensionOfMaxAdjoin.fst {y : N} (x : supExtensionOfMaxSingleton i f y) : (extensionOfMax i f).domain := (extensionOfMax_adjoin.aux1 i x).choose /-- If `x ∈ M ⊔ ⟨y⟩`, then `x = m + r • y`, `snd` pick an arbitrary such `r`. -/ def ExtensionOfMaxAdjoin.snd {y : N} (x : supExtensionOfMaxSingleton i f y) : R := (extensionOfMax_adjoin.aux1 i x).choose_spec.choose theorem ExtensionOfMaxAdjoin.eqn {y : N} (x : supExtensionOfMaxSingleton i f y) : ↑x = ↑(ExtensionOfMaxAdjoin.fst i x) + ExtensionOfMaxAdjoin.snd i x • y := (extensionOfMax_adjoin.aux1 i x).choose_spec.choose_spec variable (f) -- TODO: refactor to use colon ideals? /-- The ideal `I = {r | r • y ∈ N}` -/ def ExtensionOfMaxAdjoin.ideal (y : N) : Ideal R := (extensionOfMax i f).domain.comap ((LinearMap.id : R →ₗ[R] R).smulRight y) /-- A linear map `I ⟶ Q` by `x ↦ f' (x • y)` where `f'` is the maximal extension -/ def ExtensionOfMaxAdjoin.idealTo (y : N) : ExtensionOfMaxAdjoin.ideal i f y →ₗ[R] Q where toFun (z : { x // x ∈ ideal i f y }) := (extensionOfMax i f).toLinearPMap ⟨(↑z : R) • y, z.prop⟩ map_add' (z1 z2 : { x // x ∈ ideal i f y }) := by simp_rw [← (extensionOfMax i f).toLinearPMap.map_add] congr apply add_smul map_smul' z1 (z2 : {x // x ∈ ideal i f y}) := by simp_rw [← (extensionOfMax i f).toLinearPMap.map_smul] congr 2 apply mul_smul /-- Since we assumed `Q` being Baer, the linear map `x ↦ f' (x • y) : I ⟶ Q` extends to `R ⟶ Q`, call this extended map `φ` -/ def ExtensionOfMaxAdjoin.extendIdealTo (h : Module.Baer R Q) (y : N) : R →ₗ[R] Q := (h (ExtensionOfMaxAdjoin.ideal i f y) (ExtensionOfMaxAdjoin.idealTo i f y)).choose theorem ExtensionOfMaxAdjoin.extendIdealTo_is_extension (h : Module.Baer R Q) (y : N) : ∀ (x : R) (mem : x ∈ ExtensionOfMaxAdjoin.ideal i f y), ExtensionOfMaxAdjoin.extendIdealTo i f h y x = ExtensionOfMaxAdjoin.idealTo i f y ⟨x, mem⟩ := (h (ExtensionOfMaxAdjoin.ideal i f y) (ExtensionOfMaxAdjoin.idealTo i f y)).choose_spec theorem ExtensionOfMaxAdjoin.extendIdealTo_wd' (h : Module.Baer R Q) {y : N} (r : R) (eq1 : r • y = 0) : ExtensionOfMaxAdjoin.extendIdealTo i f h y r = 0 := by have : r ∈ ideal i f y := by change (r • y) ∈ (extensionOfMax i f).toLinearPMap.domain rw [eq1] apply Submodule.zero_mem _ rw [ExtensionOfMaxAdjoin.extendIdealTo_is_extension i f h y r this] dsimp [ExtensionOfMaxAdjoin.idealTo] simp only [eq1, ← ZeroMemClass.zero_def, (extensionOfMax i f).toLinearPMap.map_zero] theorem ExtensionOfMaxAdjoin.extendIdealTo_wd (h : Module.Baer R Q) {y : N} (r r' : R) (eq1 : r • y = r' • y) : ExtensionOfMaxAdjoin.extendIdealTo i f h y r = ExtensionOfMaxAdjoin.extendIdealTo i f h y r' := by rw [← sub_eq_zero, ← map_sub] convert ExtensionOfMaxAdjoin.extendIdealTo_wd' i f h (r - r') _ rw [sub_smul, sub_eq_zero, eq1] theorem ExtensionOfMaxAdjoin.extendIdealTo_eq (h : Module.Baer R Q) {y : N} (r : R) (hr : r • y ∈ (extensionOfMax i f).domain) : ExtensionOfMaxAdjoin.extendIdealTo i f h y r = (extensionOfMax i f).toLinearPMap ⟨r • y, hr⟩ := by simp only [ExtensionOfMaxAdjoin.extendIdealTo_is_extension i f h _ _ hr, ExtensionOfMaxAdjoin.idealTo, LinearMap.coe_mk, AddHom.coe_mk] /-- We can finally define a linear map `M ⊔ ⟨y⟩ ⟶ Q` by `x + r • y ↦ f x + φ r` -/ def ExtensionOfMaxAdjoin.extensionToFun (h : Module.Baer R Q) {y : N} : supExtensionOfMaxSingleton i f y → Q := fun x => (extensionOfMax i f).toLinearPMap (ExtensionOfMaxAdjoin.fst i x) + ExtensionOfMaxAdjoin.extendIdealTo i f h y (ExtensionOfMaxAdjoin.snd i x) theorem ExtensionOfMaxAdjoin.extensionToFun_wd (h : Module.Baer R Q) {y : N} (x : supExtensionOfMaxSingleton i f y) (a : (extensionOfMax i f).domain) (r : R) (eq1 : ↑x = ↑a + r • y) : ExtensionOfMaxAdjoin.extensionToFun i f h x = (extensionOfMax i f).toLinearPMap a + ExtensionOfMaxAdjoin.extendIdealTo i f h y r := by obtain ⟨a, ha⟩ := a have eq2 : (ExtensionOfMaxAdjoin.fst i x - a : N) = (r - ExtensionOfMaxAdjoin.snd i x) • y := by change x = a + r • y at eq1 rwa [ExtensionOfMaxAdjoin.eqn, ← sub_eq_zero, ← sub_sub_sub_eq, sub_eq_zero, ← sub_smul] at eq1 have eq3 := ExtensionOfMaxAdjoin.extendIdealTo_eq i f h (r - ExtensionOfMaxAdjoin.snd i x) (by rw [← eq2]; exact Submodule.sub_mem _ (ExtensionOfMaxAdjoin.fst i x).2 ha) simp only [map_sub, sub_smul, sub_eq_iff_eq_add] at eq3 unfold ExtensionOfMaxAdjoin.extensionToFun rw [eq3, ← add_assoc, ← (extensionOfMax i f).toLinearPMap.map_add, AddMemClass.mk_add_mk] congr ext dsimp rw [Subtype.coe_mk, add_sub, ← eq1] exact eq_sub_of_add_eq (ExtensionOfMaxAdjoin.eqn i x).symm /-- The linear map `M ⊔ ⟨y⟩ ⟶ Q` by `x + r • y ↦ f x + φ r` is an extension of `f` -/ def extensionOfMaxAdjoin (h : Module.Baer R Q) (y : N) : ExtensionOf i f where domain := supExtensionOfMaxSingleton i f y -- (extensionOfMax i f).domain ⊔ Submodule.span R {y} le := le_trans (extensionOfMax i f).le le_sup_left toFun := { toFun := ExtensionOfMaxAdjoin.extensionToFun i f h map_add' := fun a b => by have eq1 : ↑a + ↑b = ↑(ExtensionOfMaxAdjoin.fst i a + ExtensionOfMaxAdjoin.fst i b) + (ExtensionOfMaxAdjoin.snd i a + ExtensionOfMaxAdjoin.snd i b) • y := by rw [ExtensionOfMaxAdjoin.eqn, ExtensionOfMaxAdjoin.eqn, add_smul, Submodule.coe_add] ac_rfl rw [ExtensionOfMaxAdjoin.extensionToFun_wd (y := y) i f h (a + b) _ _ eq1, LinearPMap.map_add, map_add] unfold ExtensionOfMaxAdjoin.extensionToFun abel map_smul' := fun r a => by dsimp have eq1 : r • (a : N) = ↑(r • ExtensionOfMaxAdjoin.fst i a) + (r • ExtensionOfMaxAdjoin.snd i a) • y := by rw [ExtensionOfMaxAdjoin.eqn, smul_add, smul_eq_mul, mul_smul] rfl rw [ExtensionOfMaxAdjoin.extensionToFun_wd i f h (r • a :) _ _ eq1, LinearMap.map_smul, LinearPMap.map_smul, ← smul_add] congr } is_extension m := by dsimp rw [(extensionOfMax i f).is_extension, ExtensionOfMaxAdjoin.extensionToFun_wd i f h _ ⟨i m, _⟩ 0 _, map_zero, add_zero] simp theorem extensionOfMax_le (h : Module.Baer R Q) {y : N} : extensionOfMax i f ≤ extensionOfMaxAdjoin i f h y := ⟨le_sup_left, fun x x' EQ => by symm change ExtensionOfMaxAdjoin.extensionToFun i f h _ = _ rw [ExtensionOfMaxAdjoin.extensionToFun_wd i f h x' x 0 (by simp [EQ]), map_zero, add_zero]⟩ theorem extensionOfMax_to_submodule_eq_top (h : Module.Baer R Q) : (extensionOfMax i f).domain = ⊤ := by refine Submodule.eq_top_iff'.mpr fun y => ?_ dsimp rw [← extensionOfMax_is_max i f _ (extensionOfMax_le i f h), extensionOfMaxAdjoin, Submodule.mem_sup] exact ⟨0, Submodule.zero_mem _, y, Submodule.mem_span_singleton_self _, zero_add _⟩ protected theorem extension_property (h : Module.Baer R Q) (f : M →ₗ[R] N) (hf : Function.Injective f) (g : M →ₗ[R] Q) : ∃ h, h ∘ₗ f = g := haveI : Fact (Function.Injective f) := ⟨hf⟩ Exists.intro { toFun := ((extensionOfMax f g).toLinearPMap ⟨·, (extensionOfMax_to_submodule_eq_top f g h).symm ▸ ⟨⟩⟩) map_add' := fun x y ↦ by rw [← LinearPMap.map_add]; congr map_smul' := fun r x ↦ by rw [← LinearPMap.map_smul]; dsimp } <| LinearMap.ext fun x ↦ ((extensionOfMax f g).is_extension x).symm theorem extension_property_addMonoidHom (h : Module.Baer ℤ Q) (f : M →+ N) (hf : Function.Injective f) (g : M →+ Q) : ∃ h : N →+ Q, h.comp f = g := have ⟨g', hg'⟩ := h.extension_property f.toIntLinearMap hf g.toIntLinearMap ⟨g', congr(LinearMap.toAddMonoidHom $hg')⟩ /-- **Baer's criterion** for injective module : a Baer module is an injective module, i.e. if every linear map from an ideal can be extended, then the module is injective. -/ protected theorem injective (h : Module.Baer R Q) : Module.Injective R Q where out X Y _ _ _ _ i hi f := by obtain ⟨h, H⟩ := Module.Baer.extension_property h i hi f exact ⟨h, DFunLike.congr_fun H⟩ protected theorem of_injective [Small.{v} R] (inj : Module.Injective R Q) : Module.Baer R Q := by intro I g let eI := Shrink.linearEquiv R I let eR := Shrink.linearEquiv R R obtain ⟨g', hg'⟩ := Module.Injective.out (eR.symm.toLinearMap ∘ₗ I.subtype ∘ₗ eI.toLinearMap) (eR.symm.injective.comp <| Subtype.val_injective.comp eI.injective) (g ∘ₗ eI.toLinearMap) exact ⟨g' ∘ₗ eR.symm.toLinearMap, fun x mx ↦ by simpa [eI, eR] using hg' (equivShrink I ⟨x, mx⟩)⟩ protected theorem iff_injective [Small.{v} R] : Module.Baer R Q ↔ Module.Injective R Q := ⟨Module.Baer.injective, Module.Baer.of_injective⟩ end Module.Baer section ULift variable {M : Type v} [AddCommGroup M] [Module R M] lemma Module.ulift_injective_of_injective [Small.{v} R] (inj : Module.Injective R M) : Module.Injective R (ULift.{v'} M) := Module.Baer.injective fun I g ↦ have ⟨g', hg'⟩ := Module.Baer.iff_injective.mpr inj I (ULift.moduleEquiv.toLinearMap ∘ₗ g) ⟨ULift.moduleEquiv.symm.toLinearMap ∘ₗ g', fun r hr ↦ ULift.ext _ _ <| hg' r hr⟩ lemma Module.injective_of_ulift_injective (inj : Module.Injective R (ULift.{v'} M)) : Module.Injective R M where out X Y _ _ _ _ f hf g := let eX := ULift.moduleEquiv.{_,_,v'} (R := R) (M := X) have ⟨g', hg'⟩ := inj.out (ULift.moduleEquiv.{_,_,v'}.symm.toLinearMap ∘ₗ f ∘ₗ eX.toLinearMap) (by exact ULift.moduleEquiv.symm.injective.comp <| hf.comp eX.injective) (ULift.moduleEquiv.symm.toLinearMap ∘ₗ g ∘ₗ eX.toLinearMap) ⟨ULift.moduleEquiv.toLinearMap ∘ₗ g' ∘ₗ ULift.moduleEquiv.symm.toLinearMap, fun x ↦ by exact congr(ULift.down $(hg' ⟨x⟩))⟩ variable (M) [Small.{v} R] lemma Module.injective_iff_ulift_injective : Module.Injective R M ↔ Module.Injective R (ULift.{v'} M) := ⟨Module.ulift_injective_of_injective R, Module.injective_of_ulift_injective R⟩ end ULift section lifting_property universe uR uM uP uP' variable (R : Type uR) [Ring R] [Small.{uM} R] variable (M : Type uM) [AddCommGroup M] [Module R M] [inj : Module.Injective R M] variable (P : Type uP) [AddCommGroup P] [Module R P] variable (P' : Type uP') [AddCommGroup P'] [Module R P'] lemma Module.Injective.extension_property (f : P →ₗ[R] P') (hf : Function.Injective f) (g : P →ₗ[R] M) : ∃ h : P' →ₗ[R] M, h ∘ₗ f = g := (Module.Baer.of_injective inj).extension_property f hf g end lifting_property
.lake/packages/mathlib/Mathlib/Algebra/Module/Projective.lean
import Mathlib.Algebra.Module.Shrink import Mathlib.LinearAlgebra.TensorProduct.Basis import Mathlib.Logic.UnivLE /-! # Projective modules This file contains a definition of a projective module, the proof that our definition is equivalent to a lifting property, and the proof that all free modules are projective. ## Main definitions Let `R` be a ring (or a semiring) and let `M` be an `R`-module. * `Module.Projective R M` : the proposition saying that `M` is a projective `R`-module. ## Main theorems * `Module.projective_lifting_property` : a map from a projective module can be lifted along a surjection. * `Module.Projective.of_lifting_property` : If for all R-module surjections `A →ₗ B`, all maps `M →ₗ B` lift to `M →ₗ A`, then `M` is projective. * `Module.Projective.of_free` : Free modules are projective ## Implementation notes The actual definition of projective we use is that the natural R-module map from the free R-module on the type M down to M splits. This is more convenient than certain other definitions which involve quantifying over universes, and also universe-polymorphic (the ring and module can be in different universes). We require that the module sits in at least as high a universe as the ring: without this, free modules don't even exist, and it's unclear if projective modules are even a useful notion. ## References https://en.wikipedia.org/wiki/Projective_module ## TODO - Direct sum of two projective modules is projective. - Arbitrary sum of projective modules is projective. All of these should be relatively straightforward. ## Tags projective module -/ universe w v u open LinearMap hiding id open Finsupp /- The actual implementation we choose: `P` is projective if the natural surjection from the free `R`-module on `P` to `P` splits. -/ /-- An R-module is projective if it is a direct summand of a free module, or equivalently if maps from the module lift along surjections. There are several other equivalent definitions. -/ class Module.Projective (R : Type*) [Semiring R] (P : Type*) [AddCommMonoid P] [Module R P] : Prop where out : ∃ s : P →ₗ[R] P →₀ R, Function.LeftInverse (Finsupp.linearCombination R id) s namespace Module section Semiring variable {R : Type*} [Semiring R] {P : Type*} [AddCommMonoid P] [Module R P] {M : Type*} [AddCommMonoid M] [Module R M] {N : Type*} [AddCommMonoid N] [Module R N] theorem projective_def : Projective R P ↔ ∃ s : P →ₗ[R] P →₀ R, Function.LeftInverse (linearCombination R id) s := ⟨fun h => h.1, fun h => ⟨h⟩⟩ theorem projective_def' : Projective R P ↔ ∃ s : P →ₗ[R] P →₀ R, Finsupp.linearCombination R id ∘ₗ s = .id := by simp_rw [projective_def, DFunLike.ext_iff, Function.LeftInverse, comp_apply, id_apply] /-- A projective R-module has the property that maps from it lift along surjections. -/ theorem projective_lifting_property [h : Projective R P] (f : M →ₗ[R] N) (g : P →ₗ[R] N) (hf : Function.Surjective f) : ∃ h : P →ₗ[R] M, f ∘ₗ h = g := by /- Here's the first step of the proof. Recall that `X →₀ R` is Lean's way of talking about the free `R`-module on a type `X`. The universal property `Finsupp.linearCombination` says that to a map `X → N` from a type to an `R`-module, we get an associated R-module map `(X →₀ R) →ₗ N`. Apply this to a (noncomputable) map `P → M` coming from the map `P →ₗ N` and a random splitting of the surjection `M →ₗ N`, and we get a map `φ : (P →₀ R) →ₗ M`. -/ let φ : (P →₀ R) →ₗ[R] M := Finsupp.linearCombination _ fun p => Function.surjInv hf (g p) -- By projectivity we have a map `P →ₗ (P →₀ R)`; obtain ⟨s, hs⟩ := h.out -- Compose to get `P →ₗ M`. This works. use φ.comp s ext p conv_rhs => rw [← hs p] simp [φ, Finsupp.linearCombination_apply, Function.surjInv_eq hf, map_finsuppSum] theorem _root_.LinearMap.exists_rightInverse_of_surjective [Projective R P] (f : M →ₗ[R] P) (hf_surj : range f = ⊤) : ∃ g : P →ₗ[R] M, f ∘ₗ g = LinearMap.id := projective_lifting_property f (.id : P →ₗ[R] P) (LinearMap.range_eq_top.1 hf_surj) open Function in theorem _root_.Function.Surjective.surjective_linearMapComp_left [Projective R P] {f : M →ₗ[R] P} (hf_surj : Surjective f) : Surjective (fun g : N →ₗ[R] M ↦ f.comp g) := surjective_comp_left_of_exists_rightInverse <| f.exists_rightInverse_of_surjective <| range_eq_top_of_surjective f hf_surj /-- A module which satisfies the universal property is projective: If all surjections of `R`-modules `(P →₀ R) →ₗ[R] P` have `R`-linear left inverse maps, then `P` is projective. -/ theorem Projective.of_lifting_property'' {R : Type u} [Semiring R] {P : Type v} [AddCommMonoid P] [Module R P] (huniv : ∀ (f : (P →₀ R) →ₗ[R] P), Function.Surjective f → ∃ h : P →ₗ[R] (P →₀ R), f.comp h = .id) : Projective R P := projective_def'.2 <| huniv (Finsupp.linearCombination R (id : P → P)) (linearCombination_surjective _ Function.surjective_id) variable {Q : Type*} [AddCommMonoid Q] [Module R Q] instance [Projective R P] [Projective R Q] : Projective R (P × Q) := by refine .of_lifting_property'' fun f hf ↦ ?_ rcases projective_lifting_property f (.inl _ _ _) hf with ⟨g₁, hg₁⟩ rcases projective_lifting_property f (.inr _ _ _) hf with ⟨g₂, hg₂⟩ refine ⟨coprod g₁ g₂, ?_⟩ rw [LinearMap.comp_coprod, hg₁, hg₂, LinearMap.coprod_inl_inr] variable {ι : Type*} (A : ι → Type*) [∀ i : ι, AddCommMonoid (A i)] [∀ i : ι, Module R (A i)] instance [h : ∀ i : ι, Projective R (A i)] : Projective R (Π₀ i, A i) := .of_lifting_property'' fun f hf ↦ by classical choose g hg using fun i ↦ projective_lifting_property f (DFinsupp.lsingle i) hf replace hg : ∀ i x, f (g i x) = DFinsupp.single i x := fun i ↦ DFunLike.congr_fun (hg i) refine ⟨DFinsupp.coprodMap g, ?_⟩ ext i x j simp only [comp_apply, id_apply, DFinsupp.lsingle_apply, DFinsupp.coprodMap_apply_single, hg] /-- Free modules are projective. -/ theorem Projective.of_basis {ι : Type*} (b : Basis ι R P) : Projective R P := by -- need P →ₗ (P →₀ R) for definition of projective. -- get it from `ι → (P →₀ R)` coming from `b`. use b.constr ℕ fun i => Finsupp.single (b i) (1 : R) intro m simp only [b.constr_apply, mul_one, id, Finsupp.smul_single', Finsupp.linearCombination_single, map_finsuppSum] exact b.linearCombination_repr m instance (priority := 100) Projective.of_free [Module.Free R P] : Module.Projective R P := .of_basis <| Module.Free.chooseBasis R P /-- A direct summand of a projective module is projective. -/ theorem Projective.of_split [Module.Projective R M] (i : P →ₗ[R] M) (s : M →ₗ[R] P) (H : s.comp i = LinearMap.id) : Module.Projective R P := by obtain ⟨g, hg⟩ := projective_lifting_property (Finsupp.linearCombination R id) s (fun x ↦ ⟨Finsupp.single x 1, by simp⟩) refine ⟨g.comp i, fun x ↦ ?_⟩ rw [LinearMap.comp_apply, ← LinearMap.comp_apply, hg, ← LinearMap.comp_apply, H, LinearMap.id_apply] theorem Projective.of_equiv [Module.Projective R M] (e : M ≃ₗ[R] P) : Module.Projective R P := Projective.of_split e.symm e.toLinearMap (by simp) /-- A quotient of a projective module is projective iff it is a direct summand. -/ theorem Projective.iff_split_of_projective [Module.Projective R M] (s : M →ₗ[R] P) (hs : Function.Surjective s) : Module.Projective R P ↔ ∃ i, s ∘ₗ i = LinearMap.id := ⟨fun _ ↦ projective_lifting_property _ _ hs, fun ⟨i, H⟩ ↦ Projective.of_split i s H⟩ attribute [local instance] RingHomInvPair.of_ringEquiv in theorem Projective.of_ringEquiv {R S} [Semiring R] [Semiring S] {M N} [AddCommMonoid M] [AddCommMonoid N] [Module R M] [Module S N] (e₁ : R ≃+* S) (e₂ : M ≃ₛₗ[RingHomClass.toRingHom e₁] N) [Projective R M] : Projective S N := by obtain ⟨f, hf⟩ := ‹Projective R M› let g : N →ₗ[S] N →₀ S := { toFun := fun x ↦ (equivCongrLeft e₂ (f (e₂.symm x))).mapRange e₁ e₁.map_zero map_add' := fun x y ↦ by ext; simp map_smul' := fun r v ↦ by ext i; simp [e₂.symm.map_smulₛₗ] } refine ⟨⟨g, fun x ↦ ?_⟩⟩ replace hf := congr(e₂ $(hf (e₂.symm x))) simpa [linearCombination_apply, sum_mapRange_index, g, map_finsuppSum, e₂.map_smulₛₗ] using hf end Semiring section Ring variable {R : Type u} [Semiring R] {P : Type v} [AddCommMonoid P] [Module R P] variable {R₀ M N} [CommSemiring R₀] [Algebra R₀ R] [AddCommMonoid M] [Module R₀ M] [Module R M] variable [IsScalarTower R₀ R M] [AddCommMonoid N] [Module R₀ N] /-- A variant of `Projective.iff_split` allowing for a more flexible selection of the universe for the free module `M`. -/ theorem Projective.iff_split' [Small.{w} R] [Small.{w} P] : Module.Projective R P ↔ ∃ (M : Type w) (_ : AddCommMonoid M) (_ : Module R M) (_ : Module.Free R M) (i : P →ₗ[R] M) (s : M →ₗ[R] P), s.comp i = LinearMap.id := by let e : (Shrink.{w, v} P →₀ Shrink.{w, u} R) ≃ₗ[R] P →₀ R := Finsupp.mapDomain.linearEquiv _ R (equivShrink P).symm ≪≫ₗ Finsupp.mapRange.linearEquiv (Shrink.linearEquiv R R) refine ⟨fun ⟨i, hi⟩ ↦ ⟨(Shrink.{w} P) →₀ (Shrink.{w} R), _, _, Free.of_basis ⟨e⟩, e.symm.toLinearMap ∘ₗ i, (linearCombination R id) ∘ₗ e.toLinearMap, ?_⟩, fun ⟨_, _, _, _, i, s, H⟩ ↦ Projective.of_split i s H⟩ apply LinearMap.ext simp only [coe_comp, LinearEquiv.coe_coe, Function.comp_apply, e.apply_symm_apply] exact hi /-- A module is projective iff it is the direct summand of a free module. -/ theorem Projective.iff_split : Module.Projective R P ↔ ∃ (M : Type max u v) (_ : AddCommMonoid M) (_ : Module R M) (_ : Module.Free R M) (i : P →ₗ[R] M) (s : M →ₗ[R] P), s.comp i = LinearMap.id := Projective.iff_split'.{max u v} open TensorProduct in instance Projective.tensorProduct [hM : Module.Projective R M] [hN : Module.Projective R₀ N] : Module.Projective R (M ⊗[R₀] N) := by obtain ⟨sM, hsM⟩ := hM obtain ⟨sN, hsN⟩ := hN have : Module.Projective R (M ⊗[R₀] (N →₀ R₀)) := by fapply Projective.of_split (R := R) (M := ((M →₀ R) ⊗[R₀] (N →₀ R₀))) · exact (AlgebraTensorModule.map sM (LinearMap.id (R := R₀) (M := N →₀ R₀))) · exact (AlgebraTensorModule.map (Finsupp.linearCombination R id) (LinearMap.id (R := R₀) (M := N →₀ R₀))) · ext; simp [hsM _] fapply Projective.of_split (R := R) (M := (M ⊗[R₀] (N →₀ R₀))) · exact (AlgebraTensorModule.map (LinearMap.id (R := R) (M := M)) sN) · exact (AlgebraTensorModule.map (LinearMap.id (R := R) (M := M)) (linearCombination R₀ id)) · ext; simp [hsN _] end Ring section OfLiftingProperty /-- A module which satisfies the universal property is projective. -/ theorem Projective.of_lifting_property' {R : Type u} [Semiring R] {P : Type v} [AddCommMonoid P] [Module R P] [Small.{v} R] -- If for all surjections of `R`-modules `M →ₗ N`, all maps `P →ₗ N` lift to `P →ₗ M`, (h : ∀ {M : Type v} {N : Type v} [AddCommMonoid M] [AddCommMonoid N] [Module R M] [Module R N] (f : M →ₗ[R] N) (g : P →ₗ[R] N), Function.Surjective f → ∃ h : P →ₗ[R] M, f.comp h = g) : -- then `P` is projective. Projective R P := by refine of_lifting_property'' (fun p hp ↦ ?_) let e := Finsupp.mapRange.linearEquiv (α := P) (Shrink.linearEquiv R R) rcases h (p ∘ₗ e.toLinearMap) LinearMap.id (hp.comp e.surjective) with ⟨g, hg⟩ exact ⟨e.toLinearMap ∘ₗ g, hg⟩ /-- A variant of `of_lifting_property'` when we're working over a `[Ring R]`, which only requires quantifying over modules with an `AddCommGroup` instance. -/ theorem Projective.of_lifting_property {R : Type u} [Ring R] {P : Type v} [AddCommGroup P] [Module R P] [Small.{v} R] -- If for all surjections of `R`-modules `M →ₗ N`, all maps `P →ₗ N` lift to `P →ₗ M`, (h : ∀ {M : Type v} {N : Type v} [AddCommGroup M] [AddCommGroup N] [Module R M] [Module R N] (f : M →ₗ[R] N) (g : P →ₗ[R] N), Function.Surjective f → ∃ h : P →ₗ[R] M, f.comp h = g) : -- then `P` is projective. Projective R P := by refine of_lifting_property'' (fun p hp ↦ ?_) let e := Finsupp.mapRange.linearEquiv (α := P) (Shrink.linearEquiv R R) rcases h (p ∘ₗ e.toLinearMap) LinearMap.id (hp.comp e.surjective) with ⟨g, hg⟩ exact ⟨e.toLinearMap ∘ₗ g, hg⟩ end OfLiftingProperty end Module
.lake/packages/mathlib/Mathlib/Algebra/Module/BigOperators.lean
import Mathlib.Algebra.BigOperators.GroupWithZero.Action import Mathlib.Algebra.Module.Defs import Mathlib.Data.Fintype.BigOperators /-! # Finite sums over modules over a ring -/ variable {ι κ α β R M : Type*} section AddCommMonoid variable [Semiring R] [AddCommMonoid M] [Module R M] theorem List.sum_smul {l : List R} {x : M} : l.sum • x = (l.map fun r ↦ r • x).sum := map_list_sum ((smulAddHom R M).flip x) l theorem Multiset.sum_smul {l : Multiset R} {x : M} : l.sum • x = (l.map fun r ↦ r • x).sum := ((smulAddHom R M).flip x).map_multiset_sum l theorem Multiset.sum_smul_sum {s : Multiset R} {t : Multiset M} : s.sum • t.sum = ((s ×ˢ t).map fun p : R × M ↦ p.fst • p.snd).sum := by induction s using Multiset.induction with | empty => simp | cons a s ih => simp [add_smul, ih, ← Multiset.smul_sum] theorem Finset.sum_smul {f : ι → R} {s : Finset ι} {x : M} : (∑ i ∈ s, f i) • x = ∑ i ∈ s, f i • x := map_sum ((smulAddHom R M).flip x) f s lemma Finset.sum_smul_sum (s : Finset α) (t : Finset β) {f : α → R} {g : β → M} : (∑ i ∈ s, f i) • ∑ j ∈ t, g j = ∑ i ∈ s, ∑ j ∈ t, f i • g j := by simp_rw [sum_smul, ← smul_sum] lemma Fintype.sum_smul_sum [Fintype α] [Fintype β] (f : α → R) (g : β → M) : (∑ i, f i) • ∑ j, g j = ∑ i, ∑ j, f i • g j := Finset.sum_smul_sum _ _ end AddCommMonoid open Finset theorem Finset.cast_card [NonAssocSemiring R] (s : Finset α) : (#s : R) = ∑ _ ∈ s, 1 := by rw [Finset.sum_const, Nat.smul_one_eq_cast] namespace Fintype variable [DecidableEq ι] [Fintype ι] [AddCommMonoid α] lemma sum_piFinset_apply (f : κ → α) (s : Finset κ) (i : ι) : ∑ g ∈ piFinset fun _ : ι ↦ s, f (g i) = #s ^ (card ι - 1) • ∑ b ∈ s, f b := by classical rw [Finset.sum_comp] simp only [eval_image_piFinset_const, card_filter_piFinset_const s, ite_smul, zero_smul, smul_sum, Finset.sum_ite_mem, inter_self] @[simp] lemma sum_single_smul {R : Type*} [Semiring R] [Module R α] (f : ι → α) (r : R) (i₀ : ι) : ∑ i, (Pi.single (M := fun _ ↦ R) i₀ r i) • f i = r • f i₀ := by rw [Finset.sum_eq_single i₀, Pi.single_eq_same] <;> aesop end Fintype
.lake/packages/mathlib/Mathlib/Algebra/Module/FinitePresentation.lean
import Mathlib.LinearAlgebra.FreeModule.Finite.Basic import Mathlib.LinearAlgebra.Isomorphisms import Mathlib.LinearAlgebra.TensorProduct.RightExactness import Mathlib.RingTheory.Finiteness.Projective import Mathlib.RingTheory.Localization.BaseChange import Mathlib.RingTheory.Noetherian.Basic import Mathlib.RingTheory.TensorProduct.Finite /-! # Finitely Presented Modules ## Main definition - `Module.FinitePresentation`: A module is finitely presented if it is generated by some finite set `s` and the kernel of the presentation `Rˢ → M` is also finitely generated. ## Main results - `Module.finitePresentation_iff_finite`: If `R` is Noetherian, then f.p. iff f.g. on `R`-modules. Suppose `0 → K → M → N → 0` is an exact sequence of `R`-modules. - `Module.finitePresentation_of_surjective`: If `M` is f.p., `K` is f.g., then `N` is f.p. - `Module.FinitePresentation.fg_ker`: If `M` is f.g., `N` is f.p., then `K` is f.g. - `Module.finitePresentation_of_ker`: If `N` and `K` is f.p., then `M` is also f.p. - `Module.FinitePresentation.isLocalizedModule_map`: If `M` and `N` are `R`-modules and `M` is f.p., and `S` is a submonoid of `R`, then `Hom(Mₛ, Nₛ)` is the localization of `Hom(M, N)`. Also the instances finite + free => f.p. => finite are also provided ## TODO Suppose `S` is an `R`-algebra, `M` is an `S`-module. Then 1. If `S` is f.p., then `M` is `R`-f.p. implies `M` is `S`-f.p. 2. If `S` is both f.p. (as an algebra) and finite (as a module), then `M` is `S`-fp implies that `M` is `R`-f.p. 3. If `S` is f.p. as a module, then `S` is f.p. as an algebra. In particular, 4. `S` is f.p. as an `R`-module iff it is f.p. as an algebra and is finite as a module. For finitely presented algebras, see `Algebra.FinitePresentation` in file `Mathlib/RingTheory/FinitePresentation.lean`. -/ open Finsupp section Semiring variable (R M) [Semiring R] [AddCommMonoid M] [Module R M] /-- A module is finitely presented if it is finitely generated by some set `s` and the kernel of the presentation `Rˢ → M` is also finitely generated. -/ class Module.FinitePresentation : Prop where out : ∃ (s : Finset M), Submodule.span R (s : Set M) = ⊤ ∧ (LinearMap.ker (Finsupp.linearCombination R ((↑) : s → M))).FG instance (priority := 100) [h : Module.FinitePresentation R M] : Module.Finite R M := by obtain ⟨s, hs₁, _⟩ := h exact ⟨s, hs₁⟩ end Semiring section Ring section universe u v variable (R : Type u) (M : Type*) [Ring R] [AddCommGroup M] [Module R M] theorem Module.FinitePresentation.exists_fin [fp : Module.FinitePresentation R M] : ∃ (n : ℕ) (K : Submodule R (Fin n → R)) (_ : M ≃ₗ[R] (Fin n → R) ⧸ K), K.FG := by have ⟨ι, ⟨hι₁, hι₂⟩⟩ := fp refine ⟨_, LinearMap.ker (linearCombination R Subtype.val ∘ₗ (lcongr ι.equivFin (.refl ..) ≪≫ₗ linearEquivFunOnFinite R R _).symm.toLinearMap), (LinearMap.quotKerEquivOfSurjective _ <| LinearMap.range_eq_top.mp ?_).symm, ?_⟩ · simpa [range_linearCombination] using hι₁ · simpa [LinearMap.ker_comp, Submodule.comap_equiv_eq_map_symm] using hι₂.map _ /-- A finitely presented module is isomorphic to the quotient of a finite free module by a finitely generated submodule. -/ theorem Module.FinitePresentation.equiv_quotient [Module.FinitePresentation R M] [Small.{v} R] : ∃ (L : Type v) (_ : AddCommGroup L) (_ : Module R L) (K : Submodule R L) (_ : M ≃ₗ[R] L ⧸ K), Module.Free R L ∧ Module.Finite R L ∧ K.FG := have ⟨_n, _K, e, fg⟩ := Module.FinitePresentation.exists_fin R M let es := Shrink.linearEquiv ⟨_, inferInstance, inferInstance, _, e ≪≫ₗ Submodule.Quotient.equiv _ _ (es ..).symm rfl, .of_equiv (es ..).symm, .equiv (es ..).symm, fg.map (es ..).symm.toLinearMap⟩ end variable (R M N) [Ring R] [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N] -- Ideally this should be an instance but it makes mathlib much slower. lemma Module.finitePresentation_of_finite [IsNoetherianRing R] [h : Module.Finite R M] : Module.FinitePresentation R M := by obtain ⟨s, hs⟩ := h exact ⟨s, hs, IsNoetherian.noetherian _⟩ lemma Module.finitePresentation_iff_finite [IsNoetherianRing R] : Module.FinitePresentation R M ↔ Module.Finite R M := ⟨fun _ ↦ inferInstance, fun _ ↦ finitePresentation_of_finite R M⟩ variable {R M N} lemma Module.finitePresentation_of_free_of_surjective [Module.Free R M] [Module.Finite R M] (l : M →ₗ[R] N) (hl : Function.Surjective l) (hl' : (LinearMap.ker l).FG) : Module.FinitePresentation R N := by classical let b := Module.Free.chooseBasis R M let π : Free.ChooseBasisIndex R M → (Set.finite_range (l ∘ b)).toFinset := fun i ↦ ⟨l (b i), by simp⟩ have : π.Surjective := fun ⟨x, hx⟩ ↦ by obtain ⟨y, rfl⟩ : ∃ a, l (b a) = x := by simpa using hx exact ⟨y, rfl⟩ choose σ hσ using this have hπ : Subtype.val ∘ π = l ∘ b := rfl have hσ₁ : π ∘ σ = id := by ext i; exact congr_arg Subtype.val (hσ i) have hσ₂ : l ∘ b ∘ σ = Subtype.val := by ext i; exact congr_arg Subtype.val (hσ i) refine ⟨(Set.finite_range (l ∘ b)).toFinset, by simpa [Set.range_comp, LinearMap.range_eq_top], ?_⟩ let f : M →ₗ[R] (Set.finite_range (l ∘ b)).toFinset →₀ R := Finsupp.lmapDomain _ _ π ∘ₗ b.repr.toLinearMap convert hl'.map f ext x; simp only [LinearMap.mem_ker, Submodule.mem_map] constructor · intro hx refine ⟨b.repr.symm (x.mapDomain σ), ?_, ?_⟩ · simp [Finsupp.apply_linearCombination, hσ₂, hx] · simp only [f, LinearMap.comp_apply, b.repr.apply_symm_apply, LinearEquiv.coe_toLinearMap, Finsupp.lmapDomain_apply] rw [← Finsupp.mapDomain_comp, hσ₁, Finsupp.mapDomain_id] · rintro ⟨y, hy, rfl⟩ simp [f, hπ, ← Finsupp.apply_linearCombination, hy] -- Ideally this should be an instance but it makes mathlib much slower. variable (R M) in lemma Module.finitePresentation_of_projective [Projective R M] [Module.Finite R M] : FinitePresentation R M := have ⟨_n, _f, _g, surj, _, hfg⟩ := Finite.exists_comp_eq_id_of_projective R M Module.finitePresentation_of_free_of_surjective _ surj (Finite.iff_fg.mp <| LinearMap.ker_eq_range_of_comp_eq_id hfg ▸ inferInstance) variable {ι} [Finite ι] instance : Module.FinitePresentation R R := Module.finitePresentation_of_projective _ _ instance : Module.FinitePresentation R (ι →₀ R) := Module.finitePresentation_of_projective _ _ instance : Module.FinitePresentation R (ι → R) := Module.finitePresentation_of_projective _ _ lemma Module.finitePresentation_of_surjective [h : Module.FinitePresentation R M] (l : M →ₗ[R] N) (hl : Function.Surjective l) (hl' : (LinearMap.ker l).FG) : Module.FinitePresentation R N := by classical obtain ⟨s, hs, hs'⟩ := h obtain ⟨t, ht⟩ := hl' have H : Function.Surjective (Finsupp.linearCombination R ((↑) : s → M)) := LinearMap.range_eq_top.mp (by rw [range_linearCombination, Subtype.range_val, ← hs]) apply Module.finitePresentation_of_free_of_surjective (l ∘ₗ linearCombination R Subtype.val) (hl.comp H) choose σ hσ using (show _ from H) have : Finsupp.linearCombination R Subtype.val '' (σ '' t) = t := by simp only [Set.image_image, hσ, Set.image_id'] rw [LinearMap.ker_comp, ← ht, ← this, ← Submodule.map_span, Submodule.comap_map_eq, ← Finset.coe_image] exact Submodule.FG.sup ⟨_, rfl⟩ hs' lemma Module.FinitePresentation.fg_ker [Module.Finite R M] [h : Module.FinitePresentation R N] (l : M →ₗ[R] N) (hl : Function.Surjective l) : (LinearMap.ker l).FG := by classical obtain ⟨s, hs, hs'⟩ := h have H : Function.Surjective (Finsupp.linearCombination R ((↑) : s → N)) := LinearMap.range_eq_top.mp (by rw [range_linearCombination, Subtype.range_val, ← hs]) obtain ⟨f, hf⟩ : ∃ f : (s →₀ R) →ₗ[R] M, l ∘ₗ f = (Finsupp.linearCombination R Subtype.val) := by choose f hf using show _ from hl exact ⟨Finsupp.linearCombination R (fun i ↦ f i), by ext; simp [hf]⟩ have : (LinearMap.ker l).map (LinearMap.range f).mkQ = ⊤ := by rw [← top_le_iff] rintro x - obtain ⟨x, rfl⟩ := Submodule.mkQ_surjective _ x obtain ⟨y, hy⟩ := H (l x) rw [← hf, LinearMap.comp_apply, eq_comm, ← sub_eq_zero, ← map_sub] at hy exact ⟨_, hy, by simp⟩ apply Submodule.fg_of_fg_map_of_fg_inf_ker (LinearMap.range f).mkQ · rw [this] exact Module.Finite.fg_top · rw [Submodule.ker_mkQ, inf_comm, ← Submodule.map_comap_eq, ← LinearMap.ker_comp, hf] exact hs'.map f lemma Module.FinitePresentation.fg_ker_iff [Module.FinitePresentation R M] (l : M →ₗ[R] N) (hl : Function.Surjective l) : Submodule.FG (LinearMap.ker l) ↔ Module.FinitePresentation R N := ⟨finitePresentation_of_surjective l hl, fun _ ↦ fg_ker l hl⟩ lemma Module.finitePresentation_of_ker [Module.FinitePresentation R N] (l : M →ₗ[R] N) (hl : Function.Surjective l) [Module.FinitePresentation R (LinearMap.ker l)] : Module.FinitePresentation R M := by obtain ⟨s, hs⟩ : (⊤ : Submodule R M).FG := by apply Submodule.fg_of_fg_map_of_fg_inf_ker l · rw [Submodule.map_top, LinearMap.range_eq_top.mpr hl]; exact Module.Finite.fg_top · rw [top_inf_eq, ← Submodule.fg_top]; exact Module.Finite.fg_top refine ⟨s, hs, ?_⟩ let π := Finsupp.linearCombination R ((↑) : s → M) have H : Function.Surjective π := LinearMap.range_eq_top.mp (by rw [range_linearCombination, Subtype.range_val, ← hs]) have inst : Module.Finite R (LinearMap.ker (l ∘ₗ π)) := by constructor rw [Submodule.fg_top]; exact Module.FinitePresentation.fg_ker _ (hl.comp H) let f : LinearMap.ker (l ∘ₗ π) →ₗ[R] LinearMap.ker l := LinearMap.restrict π (fun x ↦ id) have e : π ∘ₗ Submodule.subtype _ = Submodule.subtype _ ∘ₗ f := by ext; rfl have hf : Function.Surjective f := by rw [← LinearMap.range_eq_top] apply Submodule.map_injective_of_injective (Submodule.injective_subtype _) rw [Submodule.map_top, Submodule.range_subtype, ← LinearMap.range_comp, ← e, LinearMap.range_comp, Submodule.range_subtype, LinearMap.ker_comp, Submodule.map_comap_eq_of_surjective H] change (LinearMap.ker π).FG have : LinearMap.ker π ≤ LinearMap.ker (l ∘ₗ π) := Submodule.comap_mono (f := π) (bot_le (a := LinearMap.ker l)) rw [← inf_eq_right.mpr this, ← Submodule.range_subtype (LinearMap.ker _), ← Submodule.map_comap_eq, ← LinearMap.ker_comp, e, LinearMap.ker_comp f, LinearMap.ker_eq_bot.mpr (Submodule.injective_subtype (LinearMap.ker l)), Submodule.comap_bot] exact (Module.FinitePresentation.fg_ker f hf).map (Submodule.subtype _) /-- Given a split exact sequence `0 → M → N → P → 0` with `N` finitely presented, then `M` is also finitely presented. -/ lemma Module.finitePresentation_of_split_exact {P : Type*} [AddCommGroup P] [Module R P] [Module.FinitePresentation R N] (f : M →ₗ[R] N) (g : N →ₗ[R] P) (l : P →ₗ[R] N) (hl : g ∘ₗ l = .id) (hf : Function.Injective f) (H : Function.Exact f g) : Module.FinitePresentation R M := by have hg : Function.Surjective g := Function.LeftInverse.surjective (DFunLike.congr_fun hl) have := Module.Finite.of_surjective g hg obtain ⟨e, rfl, rfl⟩ := ((Function.Exact.split_tfae' H).out 0 2 rfl rfl).mp ⟨hf, l, hl⟩ refine Module.finitePresentation_of_surjective (LinearMap.fst _ _ _ ∘ₗ e.toLinearMap) (Prod.fst_surjective.comp e.surjective) ?_ rw [LinearMap.ker_comp, Submodule.comap_equiv_eq_map_symm, LinearMap.exact_iff.mp Function.Exact.inr_fst, ← Submodule.map_top] exact .map _ (.map _ (Module.Finite.fg_top)) /-- Given an exact sequence `0 → M → N → P → 0` with `N` finitely presented and `P` projective, then `M` is also finitely presented. -/ lemma Module.finitePresentation_of_projective_of_exact {P : Type*} [AddCommGroup P] [Module R P] [Module.FinitePresentation R N] [Module.Projective R P] (f : M →ₗ[R] N) (g : N →ₗ[R] P) (hf : Function.Injective f) (hg : Function.Surjective g) (H : Function.Exact f g) : Module.FinitePresentation R M := have ⟨l, hl⟩ := Module.projective_lifting_property g .id hg Module.finitePresentation_of_split_exact f g l hl hf H lemma Module.FinitePresentation.of_equiv (e : M ≃ₗ[R] N) [Module.FinitePresentation R M] : Module.FinitePresentation R N := by simp [← Module.FinitePresentation.fg_ker_iff e.toLinearMap e.surjective, Submodule.fg_bot] lemma LinearEquiv.finitePresentation_iff (e : M ≃ₗ[R] N) : Module.FinitePresentation R M ↔ Module.FinitePresentation R N := ⟨fun _ ↦ .of_equiv e, fun _ ↦ .of_equiv e.symm⟩ namespace Module.FinitePresentation variable (M) in instance (priority := 900) of_subsingleton [Subsingleton M] : Module.FinitePresentation R M := .of_equiv (default : (Fin 0 → R) ≃ₗ[R] M) variable (M N) in instance prod [Module.FinitePresentation R M] [Module.FinitePresentation R N] : Module.FinitePresentation R (M × N) := by have hf : Function.Surjective (LinearMap.fst R M N) := LinearMap.fst_surjective have : FinitePresentation R ↥(LinearMap.ker (LinearMap.fst R M N)) := by rw [LinearMap.ker_fst] exact .of_equiv (LinearEquiv.ofInjective (LinearMap.inr R M N) LinearMap.inr_injective) apply Module.finitePresentation_of_ker (.fst R M N) hf instance pi {ι : Type*} (M : ι → Type*) [∀ i, AddCommGroup (M i)] [∀ i, Module R (M i)] [∀ i, Module.FinitePresentation R (M i)] [Finite ι] : Module.FinitePresentation R (∀ i, M i) := by refine Module.pi_induction' (motive := fun N _ _ ↦ Module.FinitePresentation R N) (motive' := fun N _ _ ↦ Module.FinitePresentation R N) R ?_ ?_ ?_ ?_ M inferInstance · exact fun e (hN : Module.FinitePresentation _ _) ↦ .of_equiv e · exact fun e (hN : Module.FinitePresentation _ _) ↦ .of_equiv e · infer_instance · introv hN hN' infer_instance end Module.FinitePresentation end Ring section CommRing variable {R M N N'} [CommRing R] [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N] variable [AddCommGroup N'] [Module R N'] (S : Submonoid R) (f : N →ₗ[R] N') [IsLocalizedModule S f] variable (R M) in lemma Module.FinitePresentation.trans (S : Type*) [CommRing S] [Algebra R S] [Module S M] [IsScalarTower R S M] [Module.FinitePresentation R S] [Module.FinitePresentation S M] : Module.FinitePresentation R M := by obtain ⟨n, K, e, hK⟩ := Module.FinitePresentation.exists_fin S M let f : (Fin n → S) →ₗ[R] M := (e.symm ∘ₗ K.mkQ).restrictScalars R refine Module.finitePresentation_of_surjective f (fun m ↦ ?_) ?_ · obtain ⟨a, ha⟩ := K.mkQ_surjective (e m) exact ⟨a, by simp [f, ha]⟩ · have : Module.Finite S (Submodule.restrictScalars R (LinearMap.ker (e.symm.toLinearMap ∘ₗ K.mkQ))) := by change Module.Finite S (LinearMap.ker (e.symm.toLinearMap ∘ₗ K.mkQ)) simpa [Finite.iff_fg] simp only [f, LinearMap.ker_restrictScalars, ← Module.Finite.iff_fg] exact Module.Finite.trans S _ open TensorProduct in instance {A} [CommRing A] [Algebra R A] [Module.FinitePresentation R M] : Module.FinitePresentation A (A ⊗[R] M) := by classical obtain ⟨n, f, hf⟩ := Module.Finite.exists_fin' R M have inst := Module.finitePresentation_of_projective A (A ⊗[R] (Fin n → R)) apply Module.finitePresentation_of_surjective (f.baseChange A) (LinearMap.lTensor_surjective A hf) have : Function.Exact ((LinearMap.ker f).subtype.baseChange A) (f.baseChange A) := lTensor_exact A f.exact_subtype_ker_map hf rw [LinearMap.exact_iff] at this rw [this, ← Submodule.map_top] apply Submodule.FG.map have : Module.Finite R (LinearMap.ker f) := ⟨(Submodule.fg_top _).mpr (Module.FinitePresentation.fg_ker f hf)⟩ exact Module.Finite.fg_top (R := A) (M := A ⊗[R] LinearMap.ker f) open TensorProduct in lemma FinitePresentation.of_isBaseChange {A} [CommRing A] [Algebra R A] [Module A N] [IsScalarTower R A N] (f : M →ₗ[R] N) (h : IsBaseChange A f) [Module.FinitePresentation R M] : Module.FinitePresentation A N := Module.finitePresentation_of_surjective h.equiv.toLinearMap h.equiv.surjective (by simpa using Submodule.fg_bot) open TensorProduct in instance (S : Submonoid R) [Module.FinitePresentation R M] : Module.FinitePresentation (Localization S) (LocalizedModule S M) := FinitePresentation.of_isBaseChange (LocalizedModule.mkLinearMap S M) ((isLocalizedModule_iff_isBaseChange S _ _).mp inferInstance) lemma Module.FinitePresentation.exists_lift_of_isLocalizedModule [h : Module.FinitePresentation R M] (g : M →ₗ[R] N') : ∃ (h : M →ₗ[R] N) (s : S), f ∘ₗ h = s • g := by obtain ⟨σ, hσ, τ, hτ⟩ := h let π := Finsupp.linearCombination R ((↑) : σ → M) have hπ : Function.Surjective π := LinearMap.range_eq_top.mp (by rw [range_linearCombination, Subtype.range_val, ← hσ]) classical choose s hs using IsLocalizedModule.surj S f let i : σ → N := fun x ↦ (∏ j ∈ σ.erase x.1, (s (g j)).2) • (s (g x)).1 let s₀ := ∏ j ∈ σ, (s (g j)).2 have hi : f ∘ₗ Finsupp.linearCombination R i = (s₀ • g) ∘ₗ π := by ext j simp only [LinearMap.coe_comp, Function.comp_apply, Finsupp.lsingle_apply, linearCombination_single, one_smul, LinearMap.map_smul_of_tower, ← hs, LinearMap.smul_apply, i, s₀, π] rw [← mul_smul, Finset.prod_erase_mul] exact j.prop have : ∀ x : τ, ∃ s : S, s • (Finsupp.linearCombination R i x) = 0 := by intro x convert_to ∃ s : S, s • (Finsupp.linearCombination R i x) = s • 0 · simp only [smul_zero] apply IsLocalizedModule.exists_of_eq (S := S) (f := f) rw [← LinearMap.comp_apply, map_zero, hi, LinearMap.comp_apply] convert map_zero (s₀ • g) rw [← LinearMap.mem_ker, ← hτ] exact Submodule.subset_span x.prop choose s' hs' using this let s₁ := ∏ i : τ, s' i have : LinearMap.ker π ≤ LinearMap.ker (s₁ • Finsupp.linearCombination R i) := by rw [← hτ, Submodule.span_le] intro x hxσ simp only [s₁] rw [SetLike.mem_coe, LinearMap.mem_ker, LinearMap.smul_apply, ← Finset.prod_erase_mul _ _ (Finset.mem_univ ⟨x, hxσ⟩), mul_smul] convert smul_zero _ exact hs' ⟨x, hxσ⟩ refine ⟨Submodule.liftQ _ _ this ∘ₗ (LinearMap.quotKerEquivOfSurjective _ hπ).symm.toLinearMap, s₁ * s₀, ?_⟩ ext x obtain ⟨x, rfl⟩ := hπ x rw [← LinearMap.comp_apply, ← LinearMap.comp_apply, mul_smul, LinearMap.smul_comp, ← hi, ← LinearMap.comp_smul, LinearMap.comp_assoc, LinearMap.comp_assoc] congr 2 convert Submodule.liftQ_mkQ _ _ this using 2 ext x apply (LinearMap.quotKerEquivOfSurjective _ hπ).injective simp [LinearMap.quotKerEquivOfSurjective] lemma Module.Finite.exists_smul_of_comp_eq_of_isLocalizedModule [hM : Module.Finite R M] (g₁ g₂ : M →ₗ[R] N) (h : f.comp g₁ = f.comp g₂) : ∃ (s : S), s • g₁ = s • g₂ := by classical have : ∀ x, ∃ s : S, s • g₁ x = s • g₂ x := fun x ↦ IsLocalizedModule.exists_of_eq (S := S) (f := f) (LinearMap.congr_fun h x) choose s hs using this obtain ⟨σ, hσ⟩ := hM use σ.prod s rw [← sub_eq_zero, ← LinearMap.ker_eq_top, ← top_le_iff, ← hσ, Submodule.span_le] intro x hx simp only [SetLike.mem_coe, LinearMap.mem_ker, LinearMap.sub_apply, LinearMap.smul_apply, sub_eq_zero, ← Finset.prod_erase_mul σ s hx, mul_smul, hs] variable {M' : Type*} [AddCommGroup M'] [Module R M'] (f : M →ₗ[R] M') [IsLocalizedModule S f] variable {N' : Type*} [AddCommGroup N'] [Module R N'] (g : N →ₗ[R] N') [IsLocalizedModule S g] /-- Let `M` be a finite `R`-module, and `N` be a finitely presented `R`-module. If `l : M →ₗ[R] N` is a linear map whose localization at `S : Submonoid R` is bijective, then `l` is already bijective under the localization at some `r ∈ S`. -/ lemma exists_bijective_map_powers [Module.Finite R M] [Module.FinitePresentation R N] (l : M →ₗ[R] N) (hf : Function.Bijective (IsLocalizedModule.map S f g l)) : ∃ r, r ∈ S ∧ ∀ t, r ∣ t → Function.Bijective (LocalizedModule.map (.powers t) l) := by let e : M' ≃ₗ[R] N' := LinearEquiv.ofBijective _ hf obtain ⟨l', s₀, H⟩ := Module.FinitePresentation.exists_lift_of_isLocalizedModule S f (e.symm.toLinearMap.comp g) have H₁ : g ∘ₗ l ∘ₗ l' = g ∘ₗ (s₀ • LinearMap.id) := by ext a; simpa [-EmbeddingLike.apply_eq_iff_eq, e] using congr(e ($H a)) obtain ⟨s₁, hs₁⟩ := Module.Finite.exists_smul_of_comp_eq_of_isLocalizedModule S g _ _ H₁ have H₂ : f ∘ₗ l' ∘ₗ l = f ∘ₗ (s₀ • LinearMap.id) := by rw [← LinearMap.comp_assoc, H, LinearMap.smul_comp, LinearMap.comp_assoc, ← IsLocalizedModule.map_comp S f g l, ← LinearMap.comp_assoc] change s₀ • (e.symm.toLinearMap ∘ₗ e.toLinearMap) ∘ₗ _ = _ simp [LinearMap.comp_smul] obtain ⟨s₂, hs₂⟩ := Module.Finite.exists_smul_of_comp_eq_of_isLocalizedModule S f _ _ H₂ refine ⟨s₀ * s₁ * s₂, (s₀ * s₁ * s₂).2, fun t ht ↦ ?_⟩ let Rₛ := Localization (.powers t) let lₛ := LocalizedModule.map (.powers t) l have hu₀ : IsUnit (algebraMap R Rₛ s₀) := isUnit_of_dvd_unit (hu := IsLocalization.map_units (M := .powers t) Rₛ ⟨t, Submonoid.mem_powers t⟩) (map_dvd (algebraMap R Rₛ) (dvd_trans ⟨s₁ * s₂, by simp [mul_assoc]⟩ ht)) have hu₁ : IsUnit (algebraMap R Rₛ s₁) := isUnit_of_dvd_unit (hu := IsLocalization.map_units (M := .powers t) Rₛ ⟨t, Submonoid.mem_powers t⟩) (map_dvd (algebraMap R Rₛ) (dvd_trans ⟨s₀ * s₂, by ring⟩ ht)) have hu₂ : IsUnit (algebraMap R Rₛ s₂) := isUnit_of_dvd_unit (hu := IsLocalization.map_units (M := .powers t) Rₛ ⟨t, Submonoid.mem_powers t⟩) (map_dvd (algebraMap R Rₛ) (dvd_trans ⟨s₀ * s₁, by ring⟩ ht)) let lₛ' := LocalizedModule.map (.powers t) l' have H_left : ((hu₀.unit⁻¹).1 • lₛ') ∘ₗ lₛ = LinearMap.id := by apply ((Module.End.isUnit_iff _).mp (hu₂.map (algebraMap Rₛ (Module.End Rₛ _)))).1 apply ((Module.End.isUnit_iff _).mp (hu₀.map (algebraMap Rₛ (Module.End Rₛ _)))).1 simp only [Module.algebraMap_end_apply, algebraMap_smul, LinearMap.map_smul_of_tower] rw [LinearMap.smul_comp, ← smul_assoc s₀.1, Algebra.smul_def s₀.1, IsUnit.mul_val_inv, one_smul] apply LinearMap.restrictScalars_injective R apply IsLocalizedModule.ext (.powers t) (LocalizedModule.mkLinearMap (.powers t) M) (IsLocalizedModule.map_units (LocalizedModule.mkLinearMap (.powers t) M)) ext x have : s₂.1 • l' (l x) = s₂.1 • s₀.1 • x := congr($hs₂ x) simp [lₛ, lₛ', LocalizedModule.smul'_mk, this] have H_right : lₛ ∘ₗ ((hu₀.unit⁻¹).1 • lₛ') = LinearMap.id := by apply ((Module.End.isUnit_iff _).mp (hu₁.map (algebraMap Rₛ (Module.End Rₛ _)))).1 apply ((Module.End.isUnit_iff _).mp (hu₀.map (algebraMap Rₛ (Module.End Rₛ _)))).1 simp only [Module.algebraMap_end_apply, algebraMap_smul, LinearMap.map_smul_of_tower] rw [LinearMap.comp_smul, ← smul_assoc s₀.1, Algebra.smul_def s₀.1, IsUnit.mul_val_inv, one_smul] apply LinearMap.restrictScalars_injective R apply IsLocalizedModule.ext (.powers t) (LocalizedModule.mkLinearMap (.powers t) N) (IsLocalizedModule.map_units (LocalizedModule.mkLinearMap (.powers t) N)) ext x have : s₁.1 • l (l' x) = s₁.1 • s₀.1 • x := congr($hs₁ x) simp [lₛ, lₛ', LocalizedModule.smul'_mk, this] let eₛ : LocalizedModule (.powers t) M ≃ₗ[Rₛ] LocalizedModule (.powers t) N := { __ := lₛ, invFun := ((hu₀.unit⁻¹).1 • lₛ'), left_inv := fun x ↦ congr($H_left x), right_inv := fun x ↦ congr($H_right x) } exact eₛ.bijective open IsLocalizedModule in /-- Let `M` `N` be a finitely presented `R`-modules. Any `Mₛ ≃ₗ[R] Nₛ` between the localizations at `S : Submonoid R` can be lifted to an isomorphism between `Mᵣ ≃ₗ[R] Nᵣ` for some `r ∈ S`. -/ lemma Module.FinitePresentation.exists_lift_equiv_of_isLocalizedModule [Module.FinitePresentation R M] [Module.FinitePresentation R N] (l : M' ≃ₗ[R] N') : ∃ (r : R) (hr : r ∈ S) (l' : LocalizedModule (.powers r) M ≃ₗ[Localization (.powers r)] LocalizedModule (.powers r) N), (LocalizedModule.lift (.powers r) g fun s ↦ map_units g ⟨s.1, SetLike.le_def.mp (Submonoid.powers_le.mpr hr) s.2⟩) ∘ₗ l'.toLinearMap = l ∘ₗ (LocalizedModule.lift (.powers r) f fun s ↦ map_units f ⟨s.1, SetLike.le_def.mp (Submonoid.powers_le.mpr hr) s.2⟩) := by obtain ⟨l', s, H⟩ := Module.FinitePresentation.exists_lift_of_isLocalizedModule S g (l ∘ₗ f) have : Function.Bijective (IsLocalizedModule.map S f g l') := by have : IsLocalizedModule.map S f g l' = (s • LinearMap.id) ∘ₗ l := by apply IsLocalizedModule.ext S f (IsLocalizedModule.map_units g) apply LinearMap.ext fun x ↦ ?_ simp only [LinearMap.coe_comp, Function.comp_apply, IsLocalizedModule.map_apply] rw [← LinearMap.comp_apply, H] simp rw [this] exact ((Module.End.isUnit_iff _).mp (IsLocalizedModule.map_units g s)).comp l.bijective obtain ⟨r, hr, hr'⟩ := exists_bijective_map_powers S f g _ this let rs : Submonoid R := (.powers <| r * s) let Rᵣₛ := Localization rs have hsu : IsUnit (algebraMap R Rᵣₛ s) := isUnit_of_dvd_unit (hu := IsLocalization.map_units (M := rs) Rᵣₛ ⟨_, Submonoid.mem_powers _⟩) (map_dvd (algebraMap R Rᵣₛ) ⟨r, mul_comm _ _⟩) have : Function.Bijective ((hsu.unit⁻¹).1 • LocalizedModule.map rs l') := ((Module.End.isUnit_iff _).mp ((hsu.unit⁻¹).isUnit.map (algebraMap _ (End Rᵣₛ (LocalizedModule rs N))))).comp (hr' (r * s) (dvd_mul_right _ _)) refine ⟨r * s, mul_mem hr s.2, LinearEquiv.ofBijective _ this, ?_⟩ apply IsLocalizedModule.ext rs (LocalizedModule.mkLinearMap rs M) fun x ↦ map_units g ⟨x.1, SetLike.le_def.mp (Submonoid.powers_le.mpr (mul_mem hr s.2)) x.2⟩ ext x apply ((Module.End.isUnit_iff _).mp (IsLocalizedModule.map_units g s)).1 have : ∀ x, g (l' x) = s.1 • (l (f x)) := LinearMap.congr_fun H simp only [rs, LinearMap.coe_comp, LinearMap.coe_restrictScalars, LinearEquiv.coe_coe, Function.comp_apply, LocalizedModule.mkLinearMap_apply, LinearEquiv.ofBijective_apply, LinearMap.smul_apply, LocalizedModule.map_mk, algebraMap_end_apply] rw [← map_smul, ← smul_assoc, Algebra.smul_def s.1, hsu.mul_val_inv, one_smul] simp only [LocalizedModule.lift_mk, OneMemClass.coe_one, map_one, IsUnit.unit_one, inv_one, Units.val_one, Module.End.one_apply, this] instance Module.FinitePresentation.isLocalizedModule_map [Module.FinitePresentation R M] : IsLocalizedModule S (IsLocalizedModule.map S f g) := by constructor · intro s rw [Module.End.isUnit_iff] have := (Module.End.isUnit_iff _).mp (IsLocalizedModule.map_units (S := S) (f := g) s) constructor · exact fun _ _ e ↦ LinearMap.ext fun m ↦ this.left (LinearMap.congr_fun e m) · intro h use ((IsLocalizedModule.map_units (S := S) (f := g) s).unit⁻¹).1 ∘ₗ h ext x exact Module.End.isUnit_apply_inv_apply_of_isUnit (IsLocalizedModule.map_units (S := S) (f := g) s) (h x) · intro h obtain ⟨h', s, e⟩ := Module.FinitePresentation.exists_lift_of_isLocalizedModule S g (h ∘ₗ f) refine ⟨⟨h', s⟩, ?_⟩ apply IsLocalizedModule.ext S f (IsLocalizedModule.map_units g) refine e.symm.trans (by ext; simp) · intro h₁ h₂ e apply Module.Finite.exists_smul_of_comp_eq_of_isLocalizedModule S g ext x simpa using LinearMap.congr_fun e (f x) instance Module.FinitePresentation.isLocalizedModule_mapExtendScalars (Rₛ) [CommRing Rₛ] [Algebra R Rₛ] [Module Rₛ M'] [Module Rₛ N'] [IsScalarTower R Rₛ M'] [IsScalarTower R Rₛ N'] [IsLocalization S Rₛ] [Module.FinitePresentation R M] : IsLocalizedModule S (IsLocalizedModule.mapExtendScalars S f g Rₛ) := IsLocalizedModule.of_linearEquiv _ _ _ instance [Module.FinitePresentation R M] : IsLocalizedModule S (LocalizedModule.map S (M := M) (N := N)) := Module.FinitePresentation.isLocalizedModule_mapExtendScalars _ _ _ _ /-- Let `M` be a finitely presented `R`-module, `N` a `R`-module, `S : Submonoid R`. The linear equivalence between the `M →ₗ[R] N` localized at `S` and `LocalizedModule S M →ₗ[R] LocalizedModule S N` -/ noncomputable def Module.FinitePresentation.linearEquivMap [Module.FinitePresentation R M] := IsLocalizedModule.linearEquiv S (LocalizedModule.mkLinearMap S (M →ₗ[R] N)) (IsLocalizedModule.map S (LocalizedModule.mkLinearMap S M) (LocalizedModule.mkLinearMap S N)) lemma Module.FinitePresentation.linearEquivMap_apply [Module.FinitePresentation R M] (f : M →ₗ[R] N) : Module.FinitePresentation.linearEquivMap S ((LocalizedModule.mkLinearMap S (M →ₗ[R] N)) f) = (IsLocalizedModule.map S (LocalizedModule.mkLinearMap S M) (LocalizedModule.mkLinearMap S N)) f := IsLocalizedModule.linearEquiv_apply S _ _ f @[simp] lemma Module.FinitePresentation.linearEquivMap_symm_apply [Module.FinitePresentation R M] (f : M →ₗ[R] N) : (Module.FinitePresentation.linearEquivMap S).symm ((IsLocalizedModule.map S (LocalizedModule.mkLinearMap S M) (LocalizedModule.mkLinearMap S N)) f) = (LocalizedModule.mkLinearMap S (M →ₗ[R] N)) f := IsLocalizedModule.linearEquiv_symm_apply S _ _ f /-- Let `M` be a finitely presented `R`-module, `N` a `R`-module, `S : Submonoid R`. The linear equivalence between the `M →ₗ[R] N` localized at `S` and `LocalizedModule S M →ₗ[Localization S] LocalizedModule S N` -/ noncomputable def Module.FinitePresentation.linearEquivMapExtendScalars [Module.FinitePresentation R M] := IsLocalizedModule.linearEquiv S (LocalizedModule.mkLinearMap S (M →ₗ[R] N)) (IsLocalizedModule.mapExtendScalars S (LocalizedModule.mkLinearMap S M) (LocalizedModule.mkLinearMap S N) (Localization S)) lemma Module.FinitePresentation.linearEquivMapExtendScalars_apply [Module.FinitePresentation R M] (f : M →ₗ[R] N) : Module.FinitePresentation.linearEquivMapExtendScalars S ((LocalizedModule.mkLinearMap S (M →ₗ[R] N)) f) = (IsLocalizedModule.mapExtendScalars S (LocalizedModule.mkLinearMap S M) (LocalizedModule.mkLinearMap S N) (Localization S)) f := IsLocalizedModule.linearEquiv_apply S _ _ f @[simp] lemma Module.FinitePresentation.linearEquivMapExtendScalars_symm_apply [Module.FinitePresentation R M] (f : M →ₗ[R] N) : (Module.FinitePresentation.linearEquivMapExtendScalars S).symm ((IsLocalizedModule.mapExtendScalars S (LocalizedModule.mkLinearMap S M) (LocalizedModule.mkLinearMap S N) (Localization S)) f) = (LocalizedModule.mkLinearMap S (M →ₗ[R] N)) f := IsLocalizedModule.linearEquiv_symm_apply S _ _ f end CommRing
.lake/packages/mathlib/Mathlib/Algebra/Module/ZMod.lean
import Mathlib.Algebra.Module.LinearMap.Defs import Mathlib.Algebra.Module.Submodule.Defs import Mathlib.GroupTheory.Sylow /-! # The `ZMod n`-module structure on Abelian groups whose elements have order dividing `n` -/ assert_not_exists TwoSidedIdeal variable {n : ℕ} {M M₁ : Type*} /-- The `ZMod n`-module structure on commutative monoids whose elements have order dividing `n ≠ 0`. Also implies a group structure via `Module.addCommMonoidToAddCommGroup`. See note [reducible non-instances]. -/ abbrev AddCommMonoid.zmodModule [NeZero n] [AddCommMonoid M] (h : ∀ (x : M), n • x = 0) : Module (ZMod n) M := by have h_mod (c : ℕ) (x : M) : (c % n) • x = c • x := by suffices (c % n + c / n * n) • x = c • x by rwa [add_nsmul, mul_nsmul, h, add_zero] at this rw [Nat.mod_add_div'] have := NeZero.ne n match n with | n + 1 => exact { smul := fun (c : Fin _) x ↦ c.val • x smul_zero := fun _ ↦ nsmul_zero _ zero_smul := fun _ ↦ zero_nsmul _ smul_add := fun _ _ _ ↦ nsmul_add _ _ _ one_smul := fun _ ↦ (h_mod _ _).trans <| one_nsmul _ add_smul := fun _ _ _ ↦ (h_mod _ _).trans <| add_nsmul _ _ _ mul_smul := fun _ _ _ ↦ (h_mod _ _).trans <| mul_nsmul' _ _ _ } /-- The `ZMod n`-module structure on Abelian groups whose elements have order dividing `n`. See note [reducible non-instances]. -/ abbrev AddCommGroup.zmodModule {G : Type*} [AddCommGroup G] (h : ∀ (x : G), n • x = 0) : Module (ZMod n) G := match n with | 0 => AddCommGroup.toIntModule G | _ + 1 => AddCommMonoid.zmodModule h /-- The quotient of an abelian group by a subgroup containing all multiples of `n` is a `n`-torsion group. -/ -- See note [reducible non-instances] abbrev QuotientAddGroup.zmodModule {G : Type*} [AddCommGroup G] {H : AddSubgroup G} (hH : ∀ x, n • x ∈ H) : Module (ZMod n) (G ⧸ H) := AddCommGroup.zmodModule <| by simpa [QuotientAddGroup.forall_mk, ← QuotientAddGroup.mk_nsmul] variable {F S : Type*} [AddCommGroup M] [AddCommGroup M₁] [FunLike F M M₁] [AddMonoidHomClass F M M₁] [Module (ZMod n) M] [Module (ZMod n) M₁] [SetLike S M] [AddSubgroupClass S M] {x : M} {K : S} namespace ZMod theorem map_smul (f : F) (c : ZMod n) (x : M) : f (c • x) = c • f x := by rw [← ZMod.intCast_zmod_cast c] exact map_intCast_smul f _ _ (cast c) x theorem smul_mem (hx : x ∈ K) (c : ZMod n) : c • x ∈ K := by rw [← ZMod.intCast_zmod_cast c, Int.cast_smul_eq_zsmul] exact zsmul_mem hx (cast c) end ZMod variable (n) namespace AddMonoidHom /-- Reinterpret an additive homomorphism as a `ℤ/nℤ`-linear map. See also: `AddMonoidHom.toIntLinearMap`, `AddMonoidHom.toNatLinearMap`, `AddMonoidHom.toRatLinearMap` -/ def toZModLinearMap (f : M →+ M₁) : M →ₗ[ZMod n] M₁ := { f with map_smul' := ZMod.map_smul f } theorem toZModLinearMap_injective : Function.Injective <| toZModLinearMap n (M := M) (M₁ := M₁) := fun _ _ h ↦ ext fun x ↦ congr($h x) @[simp] theorem coe_toZModLinearMap (f : M →+ M₁) : ⇑(f.toZModLinearMap n) = f := rfl /-- `AddMonoidHom.toZModLinearMap` as an equivalence. -/ def toZModLinearMapEquiv : (M →+ M₁) ≃+ (M →ₗ[ZMod n] M₁) where toFun f := f.toZModLinearMap n invFun g := g map_add' f₁ f₂ := by ext; simp end AddMonoidHom namespace AddSubgroup /-- Reinterpret an additive subgroup of a `ℤ/nℤ`-module as a `ℤ/nℤ`-submodule. See also: `AddSubgroup.toIntSubmodule`, `AddSubmonoid.toNatSubmodule`. -/ def toZModSubmodule : AddSubgroup M ≃o Submodule (ZMod n) M where toFun S := { S with smul_mem' := fun c _ h ↦ ZMod.smul_mem (K := S) h c } invFun := Submodule.toAddSubgroup map_rel_iff' := Iff.rfl @[simp] theorem toZModSubmodule_symm : ⇑((toZModSubmodule n).symm : _ ≃o AddSubgroup M) = Submodule.toAddSubgroup := rfl @[simp] lemma coe_toZModSubmodule (S : AddSubgroup M) : (toZModSubmodule n S : Set M) = S := rfl @[simp] lemma mem_toZModSubmodule {S : AddSubgroup M} : x ∈ toZModSubmodule n S ↔ x ∈ S := .rfl @[simp] theorem toZModSubmodule_toAddSubgroup (S : AddSubgroup M) : (toZModSubmodule n S).toAddSubgroup = S := rfl @[simp] theorem _root_.Submodule.toAddSubgroup_toZModSubmodule (S : Submodule (ZMod n) M) : toZModSubmodule n S.toAddSubgroup = S := rfl end AddSubgroup namespace ZModModule variable {p : ℕ} {G : Type*} [AddCommGroup G] /-- In an elementary abelian `p`-group, every finite subgroup `H` contains a further subgroup of cardinality between `k` and `p * k`, if `k ≤ |H|`. -/ lemma exists_submodule_subset_card_le (hp : p.Prime) [Module (ZMod p) G] (H : Submodule (ZMod p) G) {k : ℕ} (hk : k ≤ Nat.card H) (h'k : k ≠ 0) : ∃ H' : Submodule (ZMod p) G, Nat.card H' ≤ k ∧ k < p * Nat.card H' ∧ H' ≤ H := by obtain ⟨H'm, H'mHm, H'mk, kH'm⟩ := Sylow.exists_subgroup_le_card_le (H := AddSubgroup.toSubgroup ((AddSubgroup.toZModSubmodule _).symm H)) hp isPGroup_multiplicative hk h'k exact ⟨AddSubgroup.toZModSubmodule _ (AddSubgroup.toSubgroup.symm H'm), H'mk, kH'm, H'mHm⟩ end ZModModule
.lake/packages/mathlib/Mathlib/Algebra/Module/Lattice.lean
import Mathlib.LinearAlgebra.Dimension.Localization import Mathlib.LinearAlgebra.FiniteDimensional.Lemmas import Mathlib.LinearAlgebra.FreeModule.PID /-! # Lattices Let `A` be an `R`-algebra and `V` an `A`-module. Then an `R`-submodule `M` of `V` is a lattice, if `M` is finitely generated and spans `V` as an `A`-module. The typical use case is `A = K` is the fraction field of an integral domain `R` and `V = ι → K` for some finite `ι`. The scalar multiple a lattice by a unit in `K` is again a lattice. This gives rise to a homothety relation. When `R` is a DVR and `ι = Fin 2`, then by taking the quotient of the type of `R`-lattices in `ι → K` by the homothety relation, one obtains the vertices of what is called the Bruhat-Tits tree of `GL 2 K`. ## Main definitions - `Submodule.IsLattice`: An `R`-submodule `M` of `V` is a lattice, if it is finitely generated and its `A`-span is `V`. ## Main properties Let `R` be a PID and `A = K` its field of fractions. - `Submodule.IsLattice.free`: Every lattice in `V` is `R`-free. - `Basis.extendOfIsLattice`: Any `R`-basis of a lattice `M` in `V` defines a `K`-basis of `V`. - `Submodule.IsLattice.rank`: The `R`-rank of a lattice in `V` is equal to the `K`-rank of `V`. - `Submodule.IsLattice.inf`: The intersection of two lattices is a lattice. ## Note In the case `R = ℤ` and `A = K` a field, there is also `IsZLattice` where the finitely generated condition is replaced by having the discrete topology. This is for example used for complex tori. -/ open Module open scoped Pointwise universe u variable {R : Type*} [CommRing R] namespace Submodule /-- An `R`-submodule `M` of `V` is a lattice if it is finitely generated and spans `V` as an `A`-module. Note 1: `A` is marked as an `outParam` here. In practice this should not cause issues, since `R` and `A` are fixed, where typically `A` is the fraction field of `R`. Note 2: In the case `R = ℤ` and `A = K` a field, there is also `IsZLattice` where the finitely generated condition is replaced by having the discrete topology. -/ class IsLattice (A : outParam Type*) [CommRing A] [Algebra R A] {V : Type*} [AddCommMonoid V] [Module R V] [Module A V] [IsScalarTower R A V] [Algebra R A] [IsScalarTower R A V] (M : Submodule R V) : Prop where fg : M.FG span_eq_top : Submodule.span A (M : Set V) = ⊤ namespace IsLattice section variable (A : Type*) [CommRing A] [Algebra R A] variable {V : Type*} [AddCommGroup V] [Module R V] [Module A V] [IsScalarTower R A V] variable (M : Submodule R V) /-- Any `R`-lattice is finite. -/ instance finite [IsLattice A M] : Module.Finite R M := by rw [Module.Finite.iff_fg] exact IsLattice.fg /-- The action of `Aˣ` on `R`-submodules of `V` preserves `IsLattice`. -/ instance smul [IsLattice A M] (a : Aˣ) : IsLattice A (a • M : Submodule R V) where fg := by obtain ⟨s, rfl⟩ := IsLattice.fg (M := M) rw [Submodule.smul_span] have : Finite (a • (s : Set V) : Set V) := Finite.Set.finite_image _ _ exact Submodule.fg_span (Set.toFinite (a • (s : Set V))) span_eq_top := by rw [Submodule.coe_pointwise_smul, ← Submodule.smul_span, IsLattice.span_eq_top] ext x refine ⟨fun _ ↦ trivial, fun _ ↦ ?_⟩ rw [show x = a • a⁻¹ • x by simp] exact Submodule.smul_mem_pointwise_smul _ _ _ (by trivial) lemma of_le_of_isLattice_of_fg {M N : Submodule R V} (hle : M ≤ N) [IsLattice A M] (hfg : N.FG) : IsLattice A N := ⟨hfg, eq_top_iff.mpr <| le_trans (by rw [IsLattice.span_eq_top]) (Submodule.span_mono hle)⟩ /-- The supremum of two lattices is a lattice. -/ instance sup (M N : Submodule R V) [IsLattice A M] [IsLattice A N] : IsLattice A (M ⊔ N) := of_le_of_isLattice_of_fg A le_sup_left (Submodule.FG.sup IsLattice.fg IsLattice.fg) end section Field variable {K : Type*} [Field K] [Algebra R K] lemma _root_.Submodule.span_range_eq_top_of_injective_of_rank_le {M N : Type u} [IsDomain R] [IsFractionRing R K] [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N] [Module K N] [IsScalarTower R K N] [Module.Finite K N] {f : M →ₗ[R] N} (hf : Function.Injective f) (h : Module.rank K N ≤ Module.rank R M) : Submodule.span K (LinearMap.range f : Set N) = ⊤ := by obtain ⟨s, hs, hli⟩ := exists_set_linearIndependent R M replace hli := hli.map' f (LinearMap.ker_eq_bot.mpr hf) rw [LinearIndependent.iff_fractionRing (R := R) (K := K)] at hli replace hs : Cardinal.mk s = Module.rank K N := le_antisymm (LinearIndependent.cardinal_le_rank hli) (hs ▸ h) rw [← Module.finrank_eq_rank, Cardinal.mk_eq_nat_iff_fintype] at hs obtain ⟨hfin, hcard⟩ := hs have hsubset : Set.range (fun x : s ↦ f x.val) ⊆ (LinearMap.range f : Set N) := by rintro x ⟨a, rfl⟩ simp rw [eq_top_iff, ← LinearIndependent.span_eq_top_of_card_eq_finrank' hli hcard] exact Submodule.span_mono hsubset variable (K) {V : Type*} [AddCommGroup V] [Module K V] [Module R V] [IsScalarTower R K V] /-- Any basis of an `R`-lattice in `V` defines a `K`-basis of `V`. -/ noncomputable def _root_.Module.Basis.extendOfIsLattice [IsFractionRing R K] {κ : Type*} {M : Submodule R V} [IsLattice K M] (b : Basis κ R M) : Basis κ K V := have hli : LinearIndependent K (fun i ↦ (b i).val) := by rw [← LinearIndependent.iff_fractionRing (R := R), linearIndependent_iff'] intro s g hs simp_rw [← Submodule.coe_smul_of_tower, ← Submodule.coe_sum, Submodule.coe_eq_zero] at hs exact linearIndependent_iff'.mp b.linearIndependent s g hs have hsp : ⊤ ≤ span K (Set.range fun i ↦ (M.subtype ∘ b) i) := by rw [← Submodule.span_span_of_tower R, Set.range_comp, ← Submodule.map_span] simp [b.span_eq, Submodule.map_top, span_eq_top] Basis.mk hli hsp @[simp] lemma _root_.Module.Basis.extendOfIsLattice_apply [IsFractionRing R K] {κ : Type*} {M : Submodule R V} [IsLattice K M] (b : Basis κ R M) (k : κ) : b.extendOfIsLattice K k = (b k).val := by simp [Basis.extendOfIsLattice] variable [IsDomain R] /-- A finitely-generated `R`-submodule of `V` of rank at least the `K`-rank of `V` is a lattice. -/ lemma of_rank_le [Module.Finite K V] [IsFractionRing R K] {M : Submodule R V} (hfg : M.FG) (hr : Module.rank K V ≤ Module.rank R M) : IsLattice K M where fg := hfg span_eq_top := by simpa using Submodule.span_range_eq_top_of_injective_of_rank_le M.injective_subtype hr variable [IsPrincipalIdealRing R] /-- Any lattice over a PID is a free `R`-module. Note that under our conditions, `NoZeroSMulDivisors R K` simply says that `algebraMap R K` is injective. -/ instance free [NoZeroSMulDivisors R K] (M : Submodule R V) [IsLattice K M] : Module.Free R M := by have := NoZeroSMulDivisors.trans_faithfulSMul R K V -- any torsion free finite module over a PID is free infer_instance /-- Any lattice has `R`-rank equal to the `K`-rank of `V`. -/ lemma rank' [IsFractionRing R K] (M : Submodule R V) [IsLattice K M] : Module.rank R M = Module.rank K V := by let b := Module.Free.chooseBasis R M rw [rank_eq_card_basis b, ← rank_eq_card_basis (b.extendOfIsLattice K)] /-- Any `R`-lattice in `ι → K` has `#ι` as `R`-rank. -/ lemma rank_of_pi {ι : Type*} [Fintype ι] [IsFractionRing R K] (M : Submodule R (ι → K)) [IsLattice K M] : Module.rank R M = Fintype.card ι := by rw [IsLattice.rank' K M] simp /-- `Module.finrank` version of `IsLattice.rank`. -/ lemma finrank_of_pi {ι : Type*} [Fintype ι] [IsFractionRing R K] (M : Submodule R (ι → K)) [IsLattice K M] : Module.finrank R M = Fintype.card ι := Module.finrank_eq_of_rank_eq (IsLattice.rank_of_pi K M) /-- The intersection of two lattices is a lattice. -/ instance inf [Module.Finite K V] [IsFractionRing R K] (M N : Submodule R V) [IsLattice K M] [IsLattice K N] : IsLattice K (M ⊓ N) where fg := by have : IsNoetherian R ↥(M ⊓ N) := isNoetherian_of_le inf_le_left rw [← Module.Finite.iff_fg] infer_instance span_eq_top := by rw [← range_subtype (M ⊓ N)] apply Submodule.span_range_eq_top_of_injective_of_rank_le (M ⊓ N).injective_subtype have h := Submodule.rank_sup_add_rank_inf_eq M N rw [IsLattice.rank' K M, IsLattice.rank' K N, IsLattice.rank'] at h rw [Cardinal.eq_of_add_eq_add_left h (Module.rank_lt_aleph0 K V)] end Field end IsLattice end Submodule
.lake/packages/mathlib/Mathlib/Algebra/Module/MinimalAxioms.lean
import Mathlib.Algebra.Module.Defs /-! # Minimal Axioms for a Module This file defines a constructor to define a `Module` structure on a Type with an `AddCommGroup`, while proving a minimum number of equalities. ## Main Definitions * `Module.ofMinimalAxioms`: Define a `Module` structure on a Type with an AddCommGroup by proving a minimized set of axioms -/ universe u v /-- Define a `Module` structure on a Type by proving a minimized set of axioms. -/ abbrev Module.ofMinimalAxioms {R : Type u} {M : Type v} [Semiring R] [AddCommGroup M] [SMul R M] -- Scalar multiplication distributes over addition from the left. (smul_add : ∀ (r : R) (x y : M), r • (x + y) = r • x + r • y) -- Scalar multiplication distributes over addition from the right. (add_smul : ∀ (r s : R) (x : M), (r + s) • x = r • x + s • x) -- Scalar multiplication distributes over multiplication from the right. (mul_smul : ∀ (r s : R) (x : M), (r * s) • x = r • s • x) -- Scalar multiplication by one is the identity. (one_smul : ∀ x : M, (1 : R) • x = x) : Module R M := { smul_add := smul_add, add_smul := add_smul, mul_smul := mul_smul, one_smul := one_smul, zero_smul := fun x => (AddMonoidHom.mk' (· • x) fun r s => add_smul r s x).map_zero smul_zero := fun r => (AddMonoidHom.mk' (r • ·) (smul_add r)).map_zero }
.lake/packages/mathlib/Mathlib/Algebra/Module/SnakeLemma.lean
import Mathlib.Algebra.Exact /-! # The snake lemma in terms of modules The snake lemma is proven in `Mathlib/Algebra/Homology/ShortComplex/SnakeLemma.lean` for all abelian categories, but for definitional equality and universe issues we reprove them here for modules. ## Main results - `SnakeLemma.δ`: The connecting homomorphism guaranteed by the snake lemma. - `SnakeLemma.exact_δ_left`: The connecting homomorphism is exact on the right. - `SnakeLemma.exact_δ_right`: The connecting homomorphism is exact on the left. -/ open LinearMap hiding id open Function /-! Suppose we have an exact commutative diagram ``` K₂ -F-→ K₃ | | ι₂ ι₃ ↓ ↓ M₁ -f₁→ M₂ -f₂→ M₃ | | | i₁ i₂ i₃ ↓ ↓ ↓ N₁ -g₁→ N₂ -g₂→ N₃ | | π₁ π₂ ↓ ↓ C₁ -G-→ C₂ ``` such that `f₂` is surjective with a (set-theoretic) section `σ`, `g₁` is injective with a (set-theoretic) retraction `ρ`, and that `ι₃` is injective and `π₁` is surjective. -/ variable {R} [CommRing R] {M₁ M₂ M₃ N₁ N₂ N₃} [AddCommGroup M₁] [Module R M₁] [AddCommGroup M₂] [Module R M₂] [AddCommGroup M₃] [Module R M₃] [AddCommGroup N₁] [Module R N₁] [AddCommGroup N₂] [Module R N₂] [AddCommGroup N₃] [Module R N₃] (i₁ : M₁ →ₗ[R] N₁) (i₂ : M₂ →ₗ[R] N₂) (i₃ : M₃ →ₗ[R] N₃) (f₁ : M₁ →ₗ[R] M₂) (f₂ : M₂ →ₗ[R] M₃) (hf : Exact f₁ f₂) (g₁ : N₁ →ₗ[R] N₂) (g₂ : N₂ →ₗ[R] N₃) (hg : Exact g₁ g₂) (h₁ : g₁.comp i₁ = i₂.comp f₁) (h₂ : g₂.comp i₂ = i₃.comp f₂) (σ : M₃ → M₂) (hσ : f₂ ∘ σ = id) (ρ : N₂ → N₁) (hρ : ρ ∘ g₁ = id) {K₂ K₃ C₁ C₂} [AddCommGroup K₂] [Module R K₂] [AddCommGroup K₃] [Module R K₃] [AddCommGroup C₁] [Module R C₁] [AddCommGroup C₂] [Module R C₂] (ι₂ : K₂ →ₗ[R] M₂) (hι₂ : Exact ι₂ i₂) (ι₃ : K₃ →ₗ[R] M₃) (hι₃ : Exact ι₃ i₃) (π₁ : N₁ →ₗ[R] C₁) (hπ₁ : Exact i₁ π₁) (π₂ : N₂ →ₗ[R] C₂) (hπ₂ : Exact i₂ π₂) include hg hρ h₂ hσ hι₃ in lemma SnakeLemma.δ_aux (x : K₃) : g₁ (ρ (i₂ (σ (ι₃ x)))) = i₂ (σ (ι₃ x)) := by obtain ⟨d, hd⟩ : i₂ (σ (ι₃ x)) ∈ range g₁ := by rw [← hg.linearMap_ker_eq, mem_ker, show g₂ (i₂ _) = i₃ (f₂ _) from DFunLike.congr_fun h₂ _, ← @comp_apply _ _ _ f₂ σ, hσ, id_eq, ← i₃.comp_apply, hι₃.linearMap_comp_eq_zero, zero_apply] rw [← hd, ← ρ.comp_apply, hρ, id_eq] include hf h₁ hρ hπ₁ in lemma SnakeLemma.eq_of_eq (x : K₃) (y₁) (hy₁ : f₂ y₁ = ι₃ x) (z₁) (hz₁ : g₁ z₁ = i₂ y₁) (y₂) (hy₂ : f₂ y₂ = ι₃ x) (z₂) (hz₂ : g₁ z₂ = i₂ y₂) : π₁ z₁ = π₁ z₂ := by have := sub_eq_zero.mpr (hy₁.trans hy₂.symm) rw [← map_sub, hf] at this obtain ⟨d, hd⟩ := this rw [← eq_sub_iff_add_eq.mp hd, map_add, ← hz₂, ← sub_eq_iff_eq_add, ← map_sub, ← i₂.comp_apply, ← h₁, LinearMap.comp_apply, (HasLeftInverse.injective ⟨ρ, congr_fun hρ⟩).eq_iff] at hz₁ rw [← sub_eq_zero, ← map_sub, hz₁, hπ₁] exact ⟨_, rfl⟩ /-- **Snake Lemma** Suppose we have an exact commutative diagram ``` K₃ | ι₃ ↓ M₁ -f₁→ M₂ -f₂→ M₃ | | | i₁ i₂ i₃ ↓ ↓ ↓ N₁ -g₁→ N₂ -g₂→ N₃ | π₁ ↓ C₁ ``` such that `f₂` is surjective with a (set-theoretic) section `σ`, `g₁` is injective with a (set-theoretic) retraction `ρ`, then the map `π₁ ∘ ρ ∘ i₂ ∘ σ ∘ ι₃` is a linear map from `K₃` to `C₁`. Also see `SnakeLemma.δ'` for a noncomputable version that does not require an explicit section and retraction. -/ def SnakeLemma.δ : K₃ →ₗ[R] C₁ := haveI H₁ : ∀ x, f₂ (σ x) = x := congr_fun hσ haveI H₂ := δ_aux i₂ i₃ f₂ g₁ g₂ hg h₂ σ hσ ρ hρ ι₃ hι₃ { toFun := fun x ↦ π₁ (ρ (i₂ (σ (ι₃ x)))) map_add' := fun x y ↦ by rw [← map_add] exact eq_of_eq i₁ i₂ f₁ f₂ hf g₁ h₁ ρ hρ ι₃ π₁ hπ₁ (x + y) _ (H₁ _) _ (H₂ _) (σ (ι₃ x) + σ (ι₃ y)) (by simp only [map_add, H₁]) _ (by simp only [map_add, H₂]) map_smul' := fun r x ↦ by simp only [← map_smul, RingHom.id_apply] apply eq_of_eq i₁ i₂ f₁ f₂ hf g₁ h₁ ρ hρ ι₃ π₁ hπ₁ (r • x) _ (H₁ _) _ (H₂ _) (r • σ (ι₃ x)) (by simp only [map_smul, H₁]) _ (by simp only [map_smul, H₂]) } lemma SnakeLemma.δ_eq (x : K₃) (y) (hy : f₂ y = ι₃ x) (z) (hz : g₁ z = i₂ y) : δ i₁ i₂ i₃ f₁ f₂ hf g₁ g₂ hg h₁ h₂ σ hσ ρ hρ ι₃ hι₃ π₁ hπ₁ x = π₁ z := eq_of_eq i₁ i₂ f₁ f₂ hf g₁ h₁ ρ hρ ι₃ π₁ hπ₁ x _ (congr_fun hσ _) _ (δ_aux i₂ i₃ f₂ g₁ g₂ hg h₂ σ hσ ρ hρ ι₃ hι₃ _) y hy z hz include hι₂ in /-- Suppose we have an exact commutative diagram ``` K₂ -F-→ K₃ | | ι₂ ι₃ ↓ ↓ M₁ -f₁→ M₂ -f₂→ M₃ | | | i₁ i₂ i₃ ↓ ↓ ↓ N₁ -g₁→ N₂ -g₂→ N₃ | π₁ ↓ C₁ ``` such that `f₂` is surjective with a (set-theoretic) section `σ`, `g₁` is injective with a (set-theoretic) retraction `ρ`, and `ι₃` is injective, then `K₂ -F→ K₃ -δ→ C₁` is exact. -/ lemma SnakeLemma.exact_δ_right (F : K₂ →ₗ[R] K₃) (hF : f₂.comp ι₂ = ι₃.comp F) (h : Injective ι₃) : Exact F (δ i₁ i₂ i₃ f₁ f₂ hf g₁ g₂ hg h₁ h₂ σ hσ ρ hρ ι₃ hι₃ π₁ hπ₁) := by haveI H₁ : ∀ x, f₂ (σ x) = x := congr_fun hσ haveI H₂ := δ_aux i₂ i₃ f₂ g₁ g₂ hg h₂ σ hσ ρ hρ ι₃ hι₃ intro x constructor · intro H obtain ⟨y, hy⟩ := (hπ₁ _).mp H obtain ⟨k, hk⟩ : σ (ι₃ x) - f₁ y ∈ Set.range ι₂ := by rw [← hι₂, map_sub, ← H₂, ← hy, sub_eq_zero]; exact congr($h₁ y) refine ⟨k, h ?_⟩ rw [← ι₃.comp_apply, ← hF, f₂.comp_apply, hk, map_sub, H₁, hf.apply_apply_eq_zero, sub_zero] · rintro ⟨y, rfl⟩ exact (δ_eq i₁ i₂ i₃ f₁ f₂ hf g₁ g₂ hg h₁ h₂ σ hσ ρ hρ ι₃ hι₃ π₁ hπ₁ _ (ι₂ y) congr($hF y) _ (by rw [map_zero, hι₂.apply_apply_eq_zero])).trans π₁.map_zero include hπ₂ in /-- Suppose we have an exact commutative diagram ``` K₃ | ι₃ ↓ M₁ -f₁→ M₂ -f₂→ M₃ | | | i₁ i₂ i₃ ↓ ↓ ↓ N₁ -g₁→ N₂ -g₂→ N₃ | | π₁ π₂ ↓ ↓ C₁ -G-→ C₂ ``` such that `f₂` is surjective with a (set-theoretic) section `σ`, `g₁` is injective with a (set-theoretic) retraction `ρ`, and `π₁` is surjective, then `K₃ -δ→ C₁ -G→ C₂` is exact. -/ lemma SnakeLemma.exact_δ_left (G : C₁ →ₗ[R] C₂) (hF : G.comp π₁ = π₂.comp g₁) (h : Surjective π₁) : Exact (δ i₁ i₂ i₃ f₁ f₂ hf g₁ g₂ hg h₁ h₂ σ hσ ρ hρ ι₃ hι₃ π₁ hπ₁) G := by haveI H₂ := δ_aux i₂ i₃ f₂ g₁ g₂ hg h₂ σ hσ ρ hρ ι₃ hι₃ intro x constructor · intro H obtain ⟨x, rfl⟩ := h x obtain ⟨y, hy⟩ := (hπ₂ (g₁ x)).mp (by simpa only [← LinearMap.comp_apply, hF] using H) obtain ⟨z, hz⟩ : f₂ y ∈ range ι₃ := (hι₃ (f₂ y)).mp (by rw [← i₃.comp_apply, ← h₂, g₂.comp_apply, hy, hg.apply_apply_eq_zero]) exact ⟨z, δ_eq i₁ i₂ i₃ f₁ f₂ hf g₁ g₂ hg h₁ h₂ σ hσ ρ hρ ι₃ hι₃ π₁ hπ₁ _ _ hz.symm _ hy.symm⟩ · rintro ⟨x, rfl⟩ simp only [δ, coe_mk, AddHom.coe_mk] rw [← G.comp_apply, hF, π₂.comp_apply, H₂, hπ₂.apply_apply_eq_zero] /-- Suppose we have an exact commutative diagram ``` K₃ | ι₃ ↓ M₁ -f₁→ M₂ -f₂→ M₃ | | | i₁ i₂ i₃ ↓ ↓ ↓ N₁ -g₁→ N₂ -g₂→ N₃ | π₁ ↓ C₁ ``` such that `f₂` is surjective and `g₁` is injective, then this is the linear map `K₃ → C₁` given by the snake lemma. Also see `SnakeLemma.δ` for a computable version. -/ noncomputable def SnakeLemma.δ' (hf₂ : Surjective f₂) (hg₁ : Injective g₁) : K₃ →ₗ[R] C₁ := δ i₁ i₂ i₃ f₁ f₂ hf g₁ g₂ hg h₁ h₂ _ (funext (surjInv_eq hf₂)) _ (invFun_comp hg₁) ι₃ hι₃ π₁ hπ₁ lemma SnakeLemma.δ'_eq (hf₂ : Surjective f₂) (hg₁ : Injective g₁) (x : K₃) (y) (hy : f₂ y = ι₃ x) (z) (hz : g₁ z = i₂ y) : δ' i₁ i₂ i₃ f₁ f₂ hf g₁ g₂ hg h₁ h₂ ι₃ hι₃ π₁ hπ₁ hf₂ hg₁ x = π₁ z := SnakeLemma.δ_eq _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ‹_› ‹_› _ ‹_› include hι₂ in /-- Suppose we have an exact commutative diagram ``` K₂ -F-→ K₃ | | ι₂ ι₃ ↓ ↓ M₁ -f₁→ M₂ -f₂→ M₃ | | | i₁ i₂ i₃ ↓ ↓ ↓ N₁ -g₁→ N₂ -g₂→ N₃ | π₁ ↓ C₁ ``` such that `f₂` is surjective, `g₁` is injective, and `ι₃` is injective, then `K₂ -F→ K₃ -δ→ C₁` is exact. -/ lemma SnakeLemma.exact_δ'_right (hf₂ : Surjective f₂) (hg₁ : Injective g₁) (F : K₂ →ₗ[R] K₃) (hF : f₂.comp ι₂ = ι₃.comp F) (h : Injective ι₃) : Exact F (δ' i₁ i₂ i₃ f₁ f₂ hf g₁ g₂ hg h₁ h₂ ι₃ hι₃ π₁ hπ₁ hf₂ hg₁) := SnakeLemma.exact_δ_right _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ‹_› _ _ _ _ _ ‹_› ‹_› include hπ₂ in /-- Suppose we have an exact commutative diagram ``` K₃ | ι₃ ↓ M₁ -f₁→ M₂ -f₂→ M₃ | | | i₁ i₂ i₃ ↓ ↓ ↓ N₁ -g₁→ N₂ -g₂→ N₃ | | π₁ π₂ ↓ ↓ C₁ -G-→ C₂ ``` such that `f₂` is surjective, `g₁` is injective, and `π₁` is surjective, then `K₃ -δ→ C₁ -G→ C₂` is exact. -/ lemma SnakeLemma.exact_δ'_left (hf₂ : Surjective f₂) (hg₁ : Injective g₁) (G : C₁ →ₗ[R] C₂) (hF : G.comp π₁ = π₂.comp g₁) (h : Surjective π₁) : Exact (δ' i₁ i₂ i₃ f₁ f₂ hf g₁ g₂ hg h₁ h₂ ι₃ hι₃ π₁ hπ₁ hf₂ hg₁) G := SnakeLemma.exact_δ_left _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ‹_› _ ‹_› ‹_›
.lake/packages/mathlib/Mathlib/Algebra/Module/Hom.lean
import Mathlib.Algebra.Group.Hom.Instances import Mathlib.Algebra.GroupWithZero.Action.End import Mathlib.Algebra.GroupWithZero.Action.Hom import Mathlib.Algebra.Module.End import Mathlib.Algebra.Ring.Opposite import Mathlib.GroupTheory.GroupAction.DomAct.Basic /-! # Bundled Hom instances for module and multiplicative actions This file defines instances for `Module` on bundled `Hom` types. These are analogous to the instances in `Algebra.Module.Pi`, but for bundled instead of unbundled functions. We also define bundled versions of `(c • ·)` and `(· • ·)` as `AddMonoidHom.smulLeft` and `AddMonoidHom.smul`, respectively. -/ variable {R S M A B : Type*} namespace ZeroHom instance instModule [Semiring R] [AddMonoid A] [AddCommMonoid B] [Module R B] : Module R (ZeroHom A B) where __ : MulActionWithZero _ _ := ZeroHom.instMulActionWithZero add_smul _ _ _ := ext fun _ => add_smul _ _ _ smul_add _ _ _ := ext fun _ => smul_add _ _ _ end ZeroHom /-! ### Instances for `AddMonoidHom` -/ namespace AddMonoidHom instance instModule [Semiring R] [AddMonoid A] [AddCommMonoid B] [Module R B] : Module R (A →+ B) where add_smul _ _ _ := ext fun _ => add_smul _ _ _ zero_smul _ := ext fun _ => zero_smul _ _ instance instDomMulActModule {S M M₂ : Type*} [Semiring S] [AddCommMonoid M] [AddCommMonoid M₂] [Module S M] : Module Sᵈᵐᵃ (M →+ M₂) where add_smul s s' f := AddMonoidHom.ext fun m ↦ by simp_rw [AddMonoidHom.add_apply, DomMulAct.smul_addMonoidHom_apply, ← map_add, ← add_smul]; rfl zero_smul _ := AddMonoidHom.ext fun _ ↦ by rw [DomMulAct.smul_addMonoidHom_apply] -- TODO there should be a simp lemma for `DomMulAct.mk.symm 0` simp [DomMulAct.mk, MulOpposite.opEquiv] end AddMonoidHom /-! ### Instances for `AddMonoid.End` These are direct copies of the instances above. -/ namespace AddMonoid.End section variable [Monoid R] [Monoid S] [AddCommMonoid A] instance instDistribSMul [DistribSMul M A] : DistribSMul M (AddMonoid.End A) := AddMonoidHom.instDistribSMul variable [DistribMulAction R A] [DistribMulAction S A] instance instDistribMulAction : DistribMulAction R (AddMonoid.End A) := AddMonoidHom.instDistribMulAction @[simp] theorem coe_smul (r : R) (f : AddMonoid.End A) : ⇑(r • f) = r • ⇑f := rfl theorem smul_apply (r : R) (f : AddMonoid.End A) (x : A) : (r • f) x = r • f x := rfl instance smulCommClass [SMulCommClass R S A] : SMulCommClass R S (AddMonoid.End A) := AddMonoidHom.instSMulCommClass instance isScalarTower [SMul R S] [IsScalarTower R S A] : IsScalarTower R S (AddMonoid.End A) := AddMonoidHom.instIsScalarTower instance isCentralScalar [DistribMulAction Rᵐᵒᵖ A] [IsCentralScalar R A] : IsCentralScalar R (AddMonoid.End A) := AddMonoidHom.instIsCentralScalar end instance instModule [Semiring R] [AddCommMonoid A] [Module R A] : Module R (AddMonoid.End A) := AddMonoidHom.instModule /-- The tautological action by `AddMonoid.End α` on `α`. This generalizes `AddMonoid.End.applyDistribMulAction`. -/ instance applyModule [AddCommMonoid A] : Module (AddMonoid.End A) A where add_smul _ _ _ := rfl zero_smul _ := rfl end AddMonoid.End /-! ### Miscellaneous morphisms -/ namespace AddMonoidHom /-- Scalar multiplication on the left as an additive monoid homomorphism. -/ @[simps! -fullyApplied] protected def smulLeft [Monoid M] [AddMonoid A] [DistribMulAction M A] (c : M) : A →+ A := DistribMulAction.toAddMonoidHom _ c /-- Scalar multiplication as a biadditive monoid homomorphism. We need `M` to be commutative to have addition on `M →+ M`. -/ protected def smul [Semiring R] [AddCommMonoid M] [Module R M] : R →+ M →+ M := (Module.toAddMonoidEnd R M).toAddMonoidHom @[simp] theorem coe_smul' [Semiring R] [AddCommMonoid M] [Module R M] : ⇑(.smul : R →+ M →+ M) = AddMonoidHom.smulLeft := rfl end AddMonoidHom
.lake/packages/mathlib/Mathlib/Algebra/Module/LocalizedModule/Away.lean
import Mathlib.Algebra.Module.LocalizedModule.Basic /-! # Localizations of modules away from an element -/ /-- Given `x : R` and `f : M →ₗ[R] M'`, `IsLocalization.Away x f` states that `M'` is isomorphic to the localization of `M` at the submonoid generated by `x`. -/ protected abbrev IsLocalizedModule.Away {R M M' : Type*} [CommSemiring R] (x : R) [AddCommMonoid M] [Module R M] [AddCommMonoid M'] [Module R M'] (f : M →ₗ[R] M') := IsLocalizedModule (Submonoid.powers x) f /-- Given `x : R`, `LocalizedModule.Away x M` is the localization of `M` at the submonoid generated by `x`. -/ protected abbrev LocalizedModule.Away {R : Type*} [CommSemiring R] (x : R) (M : Type*) [AddCommMonoid M] [Module R M] := LocalizedModule (Submonoid.powers x) M
.lake/packages/mathlib/Mathlib/Algebra/Module/LocalizedModule/Int.lean
import Mathlib.Algebra.Module.LocalizedModule.Basic import Mathlib.Algebra.Module.Submodule.Pointwise /-! # Integer elements of a localized module This is a mirror of the corresponding notion for localizations of rings. ## Main definitions * `IsLocalizedModule.IsInteger` is a predicate stating that `m : M'` is in the image of `M` ## Implementation details After `IsLocalizedModule` and `IsLocalization` are unified, the two `IsInteger` predicates can be unified. -/ variable {R : Type*} [CommSemiring R] {S : Submonoid R} {M : Type*} [AddCommMonoid M] [Module R M] {M' : Type*} [AddCommMonoid M'] [Module R M'] (f : M →ₗ[R] M') open Function namespace IsLocalizedModule /-- Given `x : M'`, `M'` a localization of `M` via `f`, `IsInteger f x` iff `x` is in the image of the localization map `f`. -/ def IsInteger (x : M') : Prop := x ∈ LinearMap.range f lemma isInteger_zero : IsInteger f (0 : M') := Submodule.zero_mem _ theorem isInteger_add {x y : M'} (hx : IsInteger f x) (hy : IsInteger f y) : IsInteger f (x + y) := Submodule.add_mem _ hx hy theorem isInteger_smul {a : R} {x : M'} (hx : IsInteger f x) : IsInteger f (a • x) := by rcases hx with ⟨x', hx⟩ use a • x' rw [← hx, LinearMapClass.map_smul] variable (S) variable [IsLocalizedModule S f] /-- Each element `x : M'` has an `S`-multiple which is an integer. -/ theorem exists_integer_multiple (x : M') : ∃ a : S, IsInteger f (a.val • x) := let ⟨⟨Num, denom⟩, h⟩ := IsLocalizedModule.surj S f x ⟨denom, Set.mem_range.mpr ⟨Num, h.symm⟩⟩ /-- We can clear the denominators of a `Finset`-indexed family of fractions. -/ theorem exist_integer_multiples {ι : Type*} (s : Finset ι) (g : ι → M') : ∃ b : S, ∀ i ∈ s, IsInteger f (b.val • g i) := by classical choose sec hsec using (fun i ↦ IsLocalizedModule.surj S f (g i)) refine ⟨∏ i ∈ s, (sec i).2, fun i hi => ⟨?_, ?_⟩⟩ · exact (∏ j ∈ s.erase i, (sec j).2) • (sec i).1 · simp only [LinearMap.map_smul_of_tower, Submonoid.coe_finset_prod] rw [← hsec, ← mul_smul, Submonoid.smul_def] congr simp only [Submonoid.coe_mul, Submonoid.coe_finset_prod, mul_comm] rw [← Finset.prod_insert (f := fun i ↦ ((sec i).snd).val) (s.notMem_erase i), Finset.insert_erase hi] /-- We can clear the denominators of a finite indexed family of fractions. -/ theorem exist_integer_multiples_of_finite {ι : Type*} [Finite ι] (g : ι → M') : ∃ b : S, ∀ i, IsInteger f ((b : R) • g i) := by cases nonempty_fintype ι obtain ⟨b, hb⟩ := exist_integer_multiples S f Finset.univ g exact ⟨b, fun i => hb i (Finset.mem_univ _)⟩ /-- We can clear the denominators of a finite set of fractions. -/ theorem exist_integer_multiples_of_finset (s : Finset M') : ∃ b : S, ∀ a ∈ s, IsInteger f ((b : R) • a) := exist_integer_multiples S f s id /-- A choice of a common multiple of the denominators of a `Finset`-indexed family of fractions. -/ noncomputable def commonDenom {ι : Type*} (s : Finset ι) (g : ι → M') : S := (exist_integer_multiples S f s g).choose /-- The numerator of a fraction after clearing the denominators of a `Finset`-indexed family of fractions. -/ noncomputable def integerMultiple {ι : Type*} (s : Finset ι) (g : ι → M') (i : s) : M := ((exist_integer_multiples S f s g).choose_spec i i.prop).choose @[simp] theorem map_integerMultiple {ι : Type*} (s : Finset ι) (g : ι → M') (i : s) : f (integerMultiple S f s g i) = commonDenom S f s g • g i := ((exist_integer_multiples S f s g).choose_spec _ i.prop).choose_spec /-- A choice of a common multiple of the denominators of a finite set of fractions. -/ noncomputable def commonDenomOfFinset (s : Finset M') : S := commonDenom S f s id /-- The finset of numerators after clearing the denominators of a finite set of fractions. -/ noncomputable def finsetIntegerMultiple [DecidableEq M] (s : Finset M') : Finset M := s.attach.image fun t => integerMultiple S f s id t open Pointwise theorem finsetIntegerMultiple_image [DecidableEq M] (s : Finset M') : f '' finsetIntegerMultiple S f s = commonDenomOfFinset S f s • (s : Set M') := by delta finsetIntegerMultiple commonDenom rw [Finset.coe_image] ext constructor · rintro ⟨_, ⟨x, -, rfl⟩, rfl⟩ rw [map_integerMultiple] exact Set.mem_image_of_mem _ x.prop · rintro ⟨x, hx, rfl⟩ exact ⟨_, ⟨⟨x, hx⟩, s.mem_attach _, rfl⟩, map_integerMultiple S f s id _⟩ theorem smul_mem_finsetIntegerMultiple_span [DecidableEq M] (x : M) (s : Finset M') (hx : f x ∈ Submodule.span R s) : ∃ (m : S), m • x ∈ Submodule.span R (IsLocalizedModule.finsetIntegerMultiple S f s) := by let y : S := IsLocalizedModule.commonDenomOfFinset S f s have hx₁ : y • (s : Set M') = f '' _ := (IsLocalizedModule.finsetIntegerMultiple_image S f s).symm apply congrArg (Submodule.span R) at hx₁ rw [Submodule.span_smul] at hx₁ replace hx : _ ∈ y • Submodule.span R (s : Set M') := Set.smul_mem_smul_set hx rw [hx₁, ← f.map_smul, ← Submodule.map_span f] at hx obtain ⟨x', hx', hx''⟩ := hx obtain ⟨a, ha⟩ := (IsLocalizedModule.eq_iff_exists S f).mp hx'' use a * y convert (Submodule.span R (IsLocalizedModule.finsetIntegerMultiple S f s : Set M)).smul_mem a hx' using 1 convert ha.symm using 1 simp only [Submonoid.smul_def, ← smul_smul] end IsLocalizedModule
.lake/packages/mathlib/Mathlib/Algebra/Module/LocalizedModule/AtPrime.lean
import Mathlib.Algebra.Module.LocalizedModule.Basic import Mathlib.RingTheory.Ideal.Prime /-! # Localizations of modules at the complement of a prime ideal -/ /-- Given a prime ideal `P` and `f : M →ₗ[R] M'`, `IsLocalizedModule.AtPrime P f` states that `M'` is isomorphic to the localization of `M` at the complement of `P`. -/ protected abbrev IsLocalizedModule.AtPrime {R M M' : Type*} [CommSemiring R] (P : Ideal R) [P.IsPrime] [AddCommMonoid M] [AddCommMonoid M'] [Module R M] [Module R M'] (f : M →ₗ[R] M') := IsLocalizedModule P.primeCompl f /-- Given a prime ideal `P`, `LocalizedModule.AtPrime P M` is a localization of `M` at the complement of `P`. -/ protected abbrev LocalizedModule.AtPrime {R : Type*} [CommSemiring R] (P : Ideal R) [P.IsPrime] (M : Type*) [AddCommMonoid M] [Module R M] := LocalizedModule P.primeCompl M
.lake/packages/mathlib/Mathlib/Algebra/Module/LocalizedModule/Basic.lean
import Mathlib.Algebra.Algebra.Tower import Mathlib.Algebra.Module.TransferInstance import Mathlib.RingTheory.Localization.Defs /-! # Localized Module Given a commutative semiring `R`, a multiplicative subset `S ⊆ R` and an `R`-module `M`, we can localize `M` by `S`. This gives us a `Localization S`-module. ## Main definitions * `LocalizedModule.r`: the equivalence relation defining this localization, namely `(m, s) ≈ (m', s')` if and only if there is some `u : S` such that `u • s' • m = u • s • m'`. * `LocalizedModule M S`: the localized module by `S`. * `LocalizedModule.mk`: the canonical map sending `(m, s) : M × S ↦ m/s : LocalizedModule M S` * `LocalizedModule.liftOn`: any well-defined function `f : M × S → α` respecting `r` descents to a function `LocalizedModule M S → α` * `LocalizedModule.liftOn₂`: any well-defined function `f : M × S → M × S → α` respecting `r` descents to a function `LocalizedModule M S → LocalizedModule M S` * `LocalizedModule.mk_add_mk`: in the localized module `mk m s + mk m' s' = mk (s' • m + s • m') (s * s')` * `LocalizedModule.mk_smul_mk` : in the localized module, for any `r : R`, `s t : S`, `m : M`, we have `mk r s • mk m t = mk (r • m) (s * t)` where `mk r s : Localization S` is localized ring by `S`. * `LocalizedModule.isModule` : `LocalizedModule M S` is a `Localization S`-module. ## Future work * Redefine `Localization` for monoids and rings to coincide with `LocalizedModule`. -/ namespace LocalizedModule universe u v variable {R : Type u} [CommSemiring R] (S : Submonoid R) variable (M : Type v) [AddCommMonoid M] [Module R M] variable (T : Type*) [CommSemiring T] [Algebra R T] [IsLocalization S T] /-- The equivalence relation on `M × S` where `(m1, s1) ≈ (m2, s2)` if and only if for some (u : S), u * (s2 • m1 - s1 • m2) = 0 -/ def r (a b : M × S) : Prop := ∃ u : S, u • b.2 • a.1 = u • a.2 • b.1 theorem r.isEquiv : IsEquiv _ (r S M) := { refl := fun ⟨m, s⟩ => ⟨1, by rw [one_smul]⟩ trans := fun ⟨m1, s1⟩ ⟨m2, s2⟩ ⟨m3, s3⟩ ⟨u1, hu1⟩ ⟨u2, hu2⟩ => by use u1 * u2 * s2 -- Put everything in the same shape, sorting the terms using `simp` have hu1' := congr_arg ((u2 * s3) • ·) hu1.symm have hu2' := congr_arg ((u1 * s1) • ·) hu2.symm simp only [← mul_smul, mul_comm, mul_left_comm] at hu1' hu2' ⊢ rw [hu2', hu1'] symm := fun ⟨_, _⟩ ⟨_, _⟩ ⟨u, hu⟩ => ⟨u, hu.symm⟩ } instance r.setoid : Setoid (M × S) where r := r S M iseqv := ⟨(r.isEquiv S M).refl, (r.isEquiv S M).symm _ _, (r.isEquiv S M).trans _ _ _⟩ -- TODO: change `Localization` to use `r'` instead of `r` so that the two types are also defeq, -- `Localization S = LocalizedModule S R`. example {R} [CommSemiring R] (S : Submonoid R) : ⇑(Localization.r' S) = LocalizedModule.r S R := rfl /-- If `S` is a multiplicative subset of a ring `R` and `M` an `R`-module, then we can localize `M` by `S`. -/ def _root_.LocalizedModule : Type max u v := Quotient (r.setoid S M) section variable {M S} /-- The canonical map sending `(m, s) ↦ m/s` -/ def mk (m : M) (s : S) : LocalizedModule S M := Quotient.mk' ⟨m, s⟩ theorem mk_eq {m m' : M} {s s' : S} : mk m s = mk m' s' ↔ ∃ u : S, u • s' • m = u • s • m' := Quotient.eq' @[elab_as_elim, induction_eliminator, cases_eliminator] theorem induction_on {β : LocalizedModule S M → Prop} (h : ∀ (m : M) (s : S), β (mk m s)) : ∀ x : LocalizedModule S M, β x := by rintro ⟨⟨m, s⟩⟩ exact h m s @[elab_as_elim] theorem induction_on₂ {β : LocalizedModule S M → LocalizedModule S M → Prop} (h : ∀ (m m' : M) (s s' : S), β (mk m s) (mk m' s')) : ∀ x y, β x y := by rintro ⟨⟨m, s⟩⟩ ⟨⟨m', s'⟩⟩ exact h m m' s s' /-- If `f : M × S → α` respects the equivalence relation `LocalizedModule.r`, then `f` descents to a map `LocalizedModule M S → α`. -/ def liftOn {α : Type*} (x : LocalizedModule S M) (f : M × S → α) (wd : ∀ (p p' : M × S), p ≈ p' → f p = f p') : α := Quotient.liftOn x f wd theorem liftOn_mk {α : Type*} {f : M × S → α} (wd : ∀ (p p' : M × S), p ≈ p' → f p = f p') (m : M) (s : S) : liftOn (mk m s) f wd = f ⟨m, s⟩ := by convert Quotient.liftOn_mk f wd ⟨m, s⟩ /-- If `f : M × S → M × S → α` respects the equivalence relation `LocalizedModule.r`, then `f` descents to a map `LocalizedModule M S → LocalizedModule M S → α`. -/ def liftOn₂ {α : Type*} (x y : LocalizedModule S M) (f : M × S → M × S → α) (wd : ∀ (p q p' q' : M × S), p ≈ p' → q ≈ q' → f p q = f p' q') : α := Quotient.liftOn₂ x y f wd theorem liftOn₂_mk {α : Type*} (f : M × S → M × S → α) (wd : ∀ (p q p' q' : M × S), p ≈ p' → q ≈ q' → f p q = f p' q') (m m' : M) (s s' : S) : liftOn₂ (mk m s) (mk m' s') f wd = f ⟨m, s⟩ ⟨m', s'⟩ := by convert Quotient.liftOn₂_mk f wd _ _ instance : Zero (LocalizedModule S M) := ⟨mk 0 1⟩ /-- If `S` contains `0` then the localization at `S` is trivial. -/ theorem subsingleton (h : 0 ∈ S) : Subsingleton (LocalizedModule S M) := by refine ⟨fun a b ↦ ?_⟩ induction a,b using LocalizedModule.induction_on₂ exact mk_eq.mpr ⟨⟨0, h⟩, by simp only [Submonoid.mk_smul, zero_smul]⟩ @[simp] theorem zero_mk (s : S) : mk (0 : M) s = 0 := mk_eq.mpr ⟨1, by rw [one_smul, smul_zero, smul_zero, one_smul]⟩ instance : Add (LocalizedModule S M) where add p1 p2 := liftOn₂ p1 p2 (fun x y => mk (y.2 • x.1 + x.2 • y.1) (x.2 * y.2)) <| fun ⟨m1, s1⟩ ⟨m2, s2⟩ ⟨m1', s1'⟩ ⟨m2', s2'⟩ ⟨u1, hu1⟩ ⟨u2, hu2⟩ => mk_eq.mpr ⟨u1 * u2, by -- Put everything in the same shape, sorting the terms using `simp` have hu1' := congr_arg ((u2 * s2 * s2') • ·) hu1 have hu2' := congr_arg ((u1 * s1 * s1') • ·) hu2 simp only [smul_add, ← mul_smul, mul_comm, mul_left_comm] at hu1' hu2' ⊢ rw [hu1', hu2']⟩ theorem mk_add_mk {m1 m2 : M} {s1 s2 : S} : mk m1 s1 + mk m2 s2 = mk (s2 • m1 + s1 • m2) (s1 * s2) := mk_eq.mpr <| ⟨1, rfl⟩ private theorem add_assoc' (x y z : LocalizedModule S M) : x + y + z = x + (y + z) := by induction x with | _ mx sx induction y with | _ my sy induction z with | _ mz sz simp only [mk_add_mk, smul_add] refine mk_eq.mpr ⟨1, ?_⟩ rw [one_smul, one_smul] congr 1 · rw [mul_assoc] · rw [eq_comm, mul_comm, add_assoc, mul_smul, mul_smul, ← mul_smul sx sz, mul_comm, mul_smul] private theorem add_comm' (x y : LocalizedModule S M) : x + y = y + x := LocalizedModule.induction_on₂ (fun m m' s s' => by rw [mk_add_mk, mk_add_mk, add_comm, mul_comm]) x y private theorem zero_add' (x : LocalizedModule S M) : 0 + x = x := induction_on (fun m s => by rw [← zero_mk s, mk_add_mk, smul_zero, zero_add, mk_eq] exact ⟨1, by rw [one_smul, mul_smul, one_smul]⟩) x private theorem add_zero' (x : LocalizedModule S M) : x + 0 = x := induction_on (fun m s => by rw [← zero_mk s, mk_add_mk, smul_zero, add_zero, mk_eq] exact ⟨1, by rw [one_smul, mul_smul, one_smul]⟩) x instance hasNatSMul : SMul ℕ (LocalizedModule S M) where smul n := nsmulRec n private theorem nsmul_zero' (x : LocalizedModule S M) : (0 : ℕ) • x = 0 := LocalizedModule.induction_on (fun _ _ => rfl) x private theorem nsmul_succ' (n : ℕ) (x : LocalizedModule S M) : n.succ • x = n • x + x := LocalizedModule.induction_on (fun _ _ => rfl) x instance : AddCommMonoid (LocalizedModule S M) where add_assoc := add_assoc' zero_add := zero_add' add_zero := add_zero' nsmul := (· • ·) nsmul_zero := nsmul_zero' nsmul_succ := nsmul_succ' add_comm := add_comm' instance {M : Type*} [AddCommGroup M] [Module R M] : Neg (LocalizedModule S M) where neg p := liftOn p (fun x => LocalizedModule.mk (-x.1) x.2) fun ⟨m1, s1⟩ ⟨m2, s2⟩ ⟨u, hu⟩ => by rw [mk_eq] exact ⟨u, by simpa⟩ instance {M : Type*} [AddCommGroup M] [Module R M] : AddCommGroup (LocalizedModule S M) := { show AddCommMonoid (LocalizedModule S M) by infer_instance with neg_add_cancel := by rintro ⟨m, s⟩ change (liftOn (mk m s) (fun x => mk (-x.1) x.2) fun ⟨m1, s1⟩ ⟨m2, s2⟩ ⟨u, hu⟩ => by rw [mk_eq] exact ⟨u, by simpa⟩) + mk m s = 0 rw [liftOn_mk, mk_add_mk] simp -- TODO: fix the diamond zsmul := zsmulRec } theorem mk_neg {M : Type*} [AddCommGroup M] [Module R M] {m : M} {s : S} : mk (-m) s = -mk m s := rfl instance {A : Type*} [Semiring A] [Algebra R A] {S : Submonoid R} : Monoid (LocalizedModule S A) := { mul := fun m₁ m₂ => liftOn₂ m₁ m₂ (fun x₁ x₂ => LocalizedModule.mk (x₁.1 * x₂.1) (x₁.2 * x₂.2)) (by rintro ⟨a₁, s₁⟩ ⟨a₂, s₂⟩ ⟨b₁, t₁⟩ ⟨b₂, t₂⟩ ⟨u₁, e₁⟩ ⟨u₂, e₂⟩ rw [mk_eq] use u₁ * u₂ dsimp only at e₁ e₂ ⊢ rw [eq_comm] trans (u₁ • t₁ • a₁) • u₂ • t₂ • a₂ on_goal 1 => rw [e₁, e₂] on_goal 2 => rw [eq_comm] all_goals rw [smul_smul, mul_mul_mul_comm, ← smul_eq_mul, ← smul_eq_mul (α := A), smul_smul_smul_comm, mul_smul, mul_smul]) one := mk 1 (1 : S) one_mul := by rintro ⟨a, s⟩ exact mk_eq.mpr ⟨1, by simp only [one_mul, one_smul]⟩ mul_one := by rintro ⟨a, s⟩ exact mk_eq.mpr ⟨1, by simp only [mul_one, one_smul]⟩ mul_assoc := by rintro ⟨a₁, s₁⟩ ⟨a₂, s₂⟩ ⟨a₃, s₃⟩ apply mk_eq.mpr _ use 1 simp only [one_mul, smul_smul, ← mul_assoc] } instance {A : Type*} [Semiring A] [Algebra R A] {S : Submonoid R} : Semiring (LocalizedModule S A) := { show (AddCommMonoid (LocalizedModule S A)) by infer_instance, show (Monoid (LocalizedModule S A)) by infer_instance with left_distrib := by rintro ⟨a₁, s₁⟩ ⟨a₂, s₂⟩ ⟨a₃, s₃⟩ apply mk_eq.mpr _ use 1 simp only [one_mul, smul_add, mul_add, mul_smul_comm, smul_smul, ← mul_assoc, mul_right_comm] right_distrib := by rintro ⟨a₁, s₁⟩ ⟨a₂, s₂⟩ ⟨a₃, s₃⟩ apply mk_eq.mpr _ use 1 simp only [one_mul, smul_add, add_mul, smul_smul, ← mul_assoc, smul_mul_assoc, mul_right_comm] zero_mul := by rintro ⟨a, s⟩ exact mk_eq.mpr ⟨1, by simp only [zero_mul, smul_zero]⟩ mul_zero := by rintro ⟨a, s⟩ exact mk_eq.mpr ⟨1, by simp only [mul_zero, smul_zero]⟩ } instance {A : Type*} [CommSemiring A] [Algebra R A] {S : Submonoid R} : CommSemiring (LocalizedModule S A) := { show Semiring (LocalizedModule S A) by infer_instance with mul_comm := by rintro ⟨a₁, s₁⟩ ⟨a₂, s₂⟩ exact mk_eq.mpr ⟨1, by simp only [one_smul, mul_comm]⟩ } instance {A : Type*} [Ring A] [Algebra R A] {S : Submonoid R} : Ring (LocalizedModule S A) := { inferInstanceAs (AddCommGroup (LocalizedModule S A)), inferInstanceAs (Semiring (LocalizedModule S A)) with } instance {A : Type*} [CommRing A] [Algebra R A] {S : Submonoid R} : CommRing (LocalizedModule S A) := { show (Ring (LocalizedModule S A)) by infer_instance with mul_comm := by rintro ⟨a₁, s₁⟩ ⟨a₂, s₂⟩ exact mk_eq.mpr ⟨1, by simp only [one_smul, mul_comm]⟩ } theorem mk_mul_mk {A : Type*} [Semiring A] [Algebra R A] {a₁ a₂ : A} {s₁ s₂ : S} : mk a₁ s₁ * mk a₂ s₂ = mk (a₁ * a₂) (s₁ * s₂) := rfl noncomputable instance : SMul T (LocalizedModule S M) where smul x p := let a := IsLocalization.sec S x liftOn p (fun p ↦ mk (a.1 • p.1) (a.2 * p.2)) (by rintro p p' ⟨s, h⟩ refine mk_eq.mpr ⟨s, ?_⟩ calc _ = a.2 • a.1 • s • p'.2 • p.1 := by simp_rw [Submonoid.smul_def, Submonoid.coe_mul, ← mul_smul]; ring_nf _ = a.2 • a.1 • s • p.2 • p'.1 := by rw [h] _ = s • (a.2 * p.2) • a.1 • p'.1 := by simp_rw [Submonoid.smul_def, ← mul_smul, Submonoid.coe_mul]; ring_nf ) theorem smul_def (x : T) (m : M) (s : S) : x • mk m s = mk ((IsLocalization.sec S x).1 • m) ((IsLocalization.sec S x).2 * s) := rfl theorem mk'_smul_mk (r : R) (m : M) (s s' : S) : IsLocalization.mk' T r s • mk m s' = mk (r • m) (s * s') := by rw [smul_def, mk_eq] obtain ⟨c, hc⟩ := IsLocalization.eq.mp <| IsLocalization.mk'_sec T (IsLocalization.mk' T r s) use c simp_rw [← mul_smul, Submonoid.smul_def, Submonoid.coe_mul, ← mul_smul, ← mul_assoc, mul_comm _ (s' : R), mul_assoc, hc] theorem mk_smul_mk (r : R) (m : M) (s t : S) : Localization.mk r s • mk m t = mk (r • m) (s * t) := by rw [Localization.mk_eq_mk'] exact mk'_smul_mk .. variable {T} private theorem one_smul_aux (p : LocalizedModule S M) : (1 : T) • p = p := by induction p with | _ m s rw [show (1 : T) = IsLocalization.mk' T (1 : R) (1 : S) by rw [IsLocalization.mk'_one, map_one]] rw [mk'_smul_mk, one_smul, one_mul] private theorem mul_smul_aux (x y : T) (p : LocalizedModule S M) : (x * y) • p = x • y • p := by induction p with | _ m s rw [← IsLocalization.mk'_sec (M := S) T x, ← IsLocalization.mk'_sec (M := S) T y] simp_rw [← IsLocalization.mk'_mul, mk'_smul_mk, ← mul_smul, mul_assoc] private theorem smul_add_aux (x : T) (p q : LocalizedModule S M) : x • (p + q) = x • p + x • q := by induction p with | _ m s induction q with | _ n t rw [smul_def, smul_def, mk_add_mk, mk_add_mk] rw [show x • _ = IsLocalization.mk' T _ _ • _ by rw [IsLocalization.mk'_sec (M := S) T]] rw [← IsLocalization.mk'_cancel _ _ (IsLocalization.sec S x).2, mk'_smul_mk] congr 1 · simp only [Submonoid.smul_def, smul_add, ← mul_smul, Submonoid.coe_mul]; ring_nf · rw [mul_mul_mul_comm] -- ring does not work here private theorem smul_zero_aux (x : T) : x • (0 : LocalizedModule S M) = 0 := by conv => lhs; rw [← zero_mk 1, smul_def, smul_zero, zero_mk] private theorem add_smul_aux (x y : T) (p : LocalizedModule S M) : (x + y) • p = x • p + y • p := by induction p with | _ m s rw [smul_def T x, smul_def T y, mk_add_mk, show (x + y) • _ = IsLocalization.mk' T _ _ • _ by rw [← IsLocalization.mk'_sec (M := S) T x, ← IsLocalization.mk'_sec (M := S) T y, ← IsLocalization.mk'_add, IsLocalization.mk'_cancel _ _ s], mk'_smul_mk, ← smul_assoc, ← smul_assoc, ← add_smul] congr 1 · simp only [Submonoid.smul_def, Submonoid.coe_mul, smul_eq_mul]; ring_nf · rw [mul_mul_mul_comm, mul_assoc] -- ring does not work here private theorem zero_smul_aux (p : LocalizedModule S M) : (0 : T) • p = 0 := by induction p with | _ m s rw [show (0 : T) = IsLocalization.mk' T (0 : R) (1 : S) by rw [IsLocalization.mk'_zero], mk'_smul_mk, zero_smul, zero_mk] noncomputable instance isModule : Module T (LocalizedModule S M) where one_smul := one_smul_aux mul_smul := mul_smul_aux smul_add := smul_add_aux smul_zero := smul_zero_aux add_smul := add_smul_aux zero_smul := zero_smul_aux @[simp] theorem mk_cancel_common_left (s' s : S) (m : M) : mk (s' • m) (s' * s) = mk m s := mk_eq.mpr ⟨1, by simp only [mul_smul, one_smul] rw [smul_comm]⟩ @[simp] theorem mk_cancel (s : S) (m : M) : mk (s • m) s = mk m 1 := mk_eq.mpr ⟨1, by simp⟩ @[simp] theorem mk_cancel_common_right (s s' : S) (m : M) : mk (s' • m) (s * s') = mk m s := mk_eq.mpr ⟨1, by simp [mul_smul]⟩ noncomputable instance isModule' : Module R (LocalizedModule S M) := { Module.compHom (LocalizedModule S M) <| algebraMap R (Localization S) with } theorem smul'_mk (r : R) (s : S) (m : M) : r • mk m s = mk (r • m) s := by simpa only [one_mul] using mk_smul_mk r m 1 s lemma smul_eq_iff_of_mem (r : R) (hr : r ∈ S) (x y : LocalizedModule S M) : r • x = y ↔ x = Localization.mk 1 ⟨r, hr⟩ • y := by induction x using induction_on with | h m s => induction y using induction_on with | h n t => rw [smul'_mk, mk_smul_mk, one_smul, mk_eq, mk_eq] simp only [Subtype.exists, Submonoid.mk_smul, exists_prop] fconstructor · rintro ⟨a, ha, eq1⟩ refine ⟨a, ha, ?_⟩ rw [mul_smul, ← eq1, Submonoid.mk_smul, smul_comm r t] · rintro ⟨a, ha, eq1⟩ refine ⟨a, ha, ?_⟩ rw [← eq1, mul_comm, mul_smul, Submonoid.mk_smul, Submonoid.smul_def, Submonoid.mk_smul] lemma eq_zero_of_smul_eq_zero (r : R) (hr : r ∈ S) (x : LocalizedModule S M) (hx : r • x = 0) : x = 0 := by rw [smul_eq_iff_of_mem (hr := hr)] at hx rw [hx, smul_zero] theorem smul'_mul {A : Type*} [Semiring A] [Algebra R A] (x : T) (p₁ p₂ : LocalizedModule S A) : x • p₁ * p₂ = x • (p₁ * p₂) := by induction p₁, p₂ using induction_on₂ with | _ a₁ s₁ a₂ s₂ => _ rw [mk_mul_mk, smul_def, smul_def, mk_mul_mk, mul_assoc, smul_mul_assoc] theorem mul_smul' {A : Type*} [Semiring A] [Algebra R A] (x : T) (p₁ p₂ : LocalizedModule S A) : p₁ * x • p₂ = x • (p₁ * p₂) := by induction p₁, p₂ using induction_on₂ with | _ a₁ s₁ a₂ s₂ => _ rw [smul_def, mk_mul_mk, mk_mul_mk, smul_def, mul_left_comm, mul_smul_comm] variable (T) noncomputable instance {A : Type*} [Semiring A] [Algebra R A] : Algebra T (LocalizedModule S A) := Algebra.ofModule smul'_mul mul_smul' theorem algebraMap_mk' {A : Type*} [Semiring A] [Algebra R A] (a : R) (s : S) : algebraMap _ _ (IsLocalization.mk' T a s) = mk (algebraMap R A a) s := by rw [Algebra.algebraMap_eq_smul_one] change _ • mk _ _ = _ rw [mk'_smul_mk, Algebra.algebraMap_eq_smul_one, mul_one] theorem algebraMap_mk {A : Type*} [Semiring A] [Algebra R A] (a : R) (s : S) : algebraMap _ _ (Localization.mk a s) = mk (algebraMap R A a) s := by rw [Localization.mk_eq_mk'] exact algebraMap_mk' .. instance : IsScalarTower R T (LocalizedModule S M) where smul_assoc r x p := by induction p with | _ m s rw [← IsLocalization.mk'_sec (M := S) T x, IsLocalization.smul_mk', mk'_smul_mk, mk'_smul_mk, smul'_mk, mul_smul] noncomputable instance algebra' {A : Type*} [Semiring A] [Algebra R A] : Algebra R (LocalizedModule S A) where algebraMap := (algebraMap (Localization S) (LocalizedModule S A)).comp (algebraMap R <| Localization S) commutes' := by intro r x induction x using induction_on with | _ a s => _ dsimp rw [← Localization.mk_one_eq_algebraMap, algebraMap_mk, mk_mul_mk, mk_mul_mk, mul_comm, Algebra.commutes] smul_def' := by intro r x induction x using induction_on with | _ a s => _ dsimp rw [← Localization.mk_one_eq_algebraMap, algebraMap_mk, mk_mul_mk, smul'_mk, Algebra.smul_def, one_mul] section variable (S M) /-- The function `m ↦ m / 1` as an `R`-linear map. -/ @[simps] noncomputable def mkLinearMap : M →ₗ[R] LocalizedModule S M where toFun m := mk m 1 map_add' x y := by simp [mk_add_mk] map_smul' _ _ := (smul'_mk _ _ _).symm end /-- For any `s : S`, there is an `R`-linear map given by `a/b ↦ a/(b*s)`. -/ @[simps] noncomputable def divBy (s : S) : LocalizedModule S M →ₗ[R] LocalizedModule S M where toFun p := p.liftOn (fun p => mk p.1 (p.2 * s)) fun ⟨a, b⟩ ⟨a', b'⟩ ⟨c, eq1⟩ => mk_eq.mpr ⟨c, by rw [mul_smul, mul_smul, smul_comm _ s, smul_comm _ s, eq1, smul_comm _ s, smul_comm _ s]⟩ map_add' x y := by refine x.induction_on₂ ?_ y intro m₁ m₂ t₁ t₂ simp_rw [mk_add_mk, LocalizedModule.liftOn_mk, mk_add_mk, mul_smul, mul_comm _ s, mul_assoc, smul_comm _ s, ← smul_add, mul_left_comm s t₁ t₂, mk_cancel_common_left s] map_smul' r x := by refine x.induction_on (fun _ _ ↦ ?_) change liftOn (mk _ _) _ _ = r • (liftOn (mk _ _) _ _) simp_rw [liftOn_mk, mul_assoc, ← smul_def] congr! theorem divBy_mul_by (s : S) (p : LocalizedModule S M) : divBy s (algebraMap R (Module.End R (LocalizedModule S M)) s p) = p := p.induction_on fun m t => by rw [Module.algebraMap_end_apply, divBy_apply, ← algebraMap_smul (Localization S) (s : R), smul_def, LocalizedModule.liftOn_mk, mul_assoc, ← smul_def, algebraMap_smul, smul'_mk, ← Submonoid.smul_def, mk_cancel_common_right _ s] theorem mul_by_divBy (s : S) (p : LocalizedModule S M) : algebraMap R (Module.End R (LocalizedModule S M)) s (divBy s p) = p := p.induction_on fun m t => by rw [divBy_apply, Module.algebraMap_end_apply, LocalizedModule.liftOn_mk, smul'_mk, ← Submonoid.smul_def, mk_cancel_common_right _ s] end end LocalizedModule section IsLocalizedModule universe u v variable {R : Type*} [CommSemiring R] (S : Submonoid R) variable {M M' M'' : Type*} [AddCommMonoid M] [AddCommMonoid M'] [AddCommMonoid M''] variable {A : Type*} [CommSemiring A] [Algebra R A] [Module A M'] [IsLocalization S A] variable [Module R M] [Module R M'] [Module R M''] [IsScalarTower R A M'] variable (f : M →ₗ[R] M') (g : M →ₗ[R] M'') /-- The characteristic predicate for localized module. `IsLocalizedModule S f` describes that `f : M ⟶ M'` is the localization map identifying `M'` as `LocalizedModule S M`. -/ @[mk_iff] class IsLocalizedModule (S : Submonoid R) (f : M →ₗ[R] M') : Prop where map_units : ∀ x : S, IsUnit (algebraMap R (Module.End R M') x) surj (S f) : ∀ y : M', ∃ x : M × S, x.2 • y = f x.1 exists_of_eq : ∀ {x₁ x₂}, f x₁ = f x₂ → ∃ c : S, c • x₁ = c • x₂ attribute [nolint docBlame] IsLocalizedModule.map_units IsLocalizedModule.surj IsLocalizedModule.exists_of_eq @[deprecated (since := "2025-09-05")] alias IsLocalizedModule.surj' := IsLocalizedModule.surj lemma IsLocalizedModule.eq_iff_exists [IsLocalizedModule S f] {x₁ x₂} : f x₁ = f x₂ ↔ ∃ c : S, c • x₁ = c • x₂ := Iff.intro exists_of_eq fun ⟨c, h⟩ ↦ by apply_fun f at h simp_rw [f.map_smul_of_tower, Submonoid.smul_def, ← Module.algebraMap_end_apply R R] at h exact ((Module.End.isUnit_iff _).mp <| map_units f c).1 h lemma IsLocalizedModule.injective_iff_isRegular [IsLocalizedModule S f] : Function.Injective f ↔ ∀ c : S, IsSMulRegular M c := by simp_rw [IsSMulRegular, Function.Injective, eq_iff_exists S, exists_imp, forall_comm (α := S)] instance IsLocalizedModule.of_linearEquiv (e : M' ≃ₗ[R] M'') [hf : IsLocalizedModule S f] : IsLocalizedModule S (e ∘ₗ f : M →ₗ[R] M'') where map_units s := by rw [show algebraMap R (Module.End R M'') s = e ∘ₗ (algebraMap R (Module.End R M') s) ∘ₗ e.symm by ext; simp, Module.End.isUnit_iff, LinearMap.coe_comp, LinearMap.coe_comp, LinearEquiv.coe_coe, LinearEquiv.coe_coe, EquivLike.comp_bijective, EquivLike.bijective_comp] exact (Module.End.isUnit_iff _).mp <| hf.map_units s surj x := by obtain ⟨p, h⟩ := hf.surj (e.symm x) exact ⟨p, by rw [LinearMap.coe_comp, LinearEquiv.coe_coe, Function.comp_apply, ← e.congr_arg h, Submonoid.smul_def, Submonoid.smul_def, LinearEquiv.map_smul, LinearEquiv.apply_symm_apply]⟩ exists_of_eq h := by simp_rw [LinearMap.coe_comp, LinearEquiv.coe_coe, Function.comp_apply, EmbeddingLike.apply_eq_iff_eq] at h exact hf.exists_of_eq h instance IsLocalizedModule.of_linearEquiv_right (e : M'' ≃ₗ[R] M) [hf : IsLocalizedModule S f] : IsLocalizedModule S (f ∘ₗ e : M'' →ₗ[R] M') where map_units s := hf.map_units s surj x := by obtain ⟨⟨p, s⟩, h⟩ := hf.surj x exact ⟨⟨e.symm p, s⟩, by simpa using h⟩ exists_of_eq h := by simp_rw [LinearMap.coe_comp, LinearEquiv.coe_coe, Function.comp_apply] at h obtain ⟨c, hc⟩ := hf.exists_of_eq h exact ⟨c, by simpa only [Submonoid.smul_def, map_smul, e.symm_apply_apply] using congr(e.symm $hc)⟩ variable (M) in lemma isLocalizedModule_id (R') [CommSemiring R'] [Algebra R R'] [IsLocalization S R'] [Module R' M] [IsScalarTower R R' M] : IsLocalizedModule S (.id : M →ₗ[R] M) where map_units s := by rw [← (Algebra.lsmul R (A := R') R M).commutes]; exact (IsLocalization.map_units R' s).map _ surj m := ⟨(m, 1), one_smul _ _⟩ exists_of_eq h := ⟨1, congr_arg _ h⟩ namespace LocalizedModule /-- If `g` is a linear map `M → M''` such that all scalar multiplication by `s : S` is invertible, then there is a linear map `LocalizedModule S M → M''`. -/ noncomputable def lift' (g : M →ₗ[R] M'') (h : ∀ x : S, IsUnit (algebraMap R (Module.End R M'') x)) : LocalizedModule S M → M'' := fun m => m.liftOn (fun p => (h p.2).unit⁻¹.val <| g p.1) fun ⟨m, s⟩ ⟨m', s'⟩ ⟨c, eq1⟩ => by dsimp only simp only [Submonoid.smul_def] at eq1 rw [Module.End.algebraMap_isUnit_inv_apply_eq_iff, ← map_smul, eq_comm, Module.End.algebraMap_isUnit_inv_apply_eq_iff] have : c • s • g m' = c • s' • g m := by simp only [Submonoid.smul_def, ← g.map_smul, eq1] have : Function.Injective (h c).unit.inv := ((Module.End.isUnit_iff _).1 (by simp)).1 apply_fun (h c).unit.inv rw [Units.inv_eq_val_inv, Module.End.algebraMap_isUnit_inv_apply_eq_iff, ← (h c).unit⁻¹.val.map_smul] symm rw [Module.End.algebraMap_isUnit_inv_apply_eq_iff, ← g.map_smul, ← g.map_smul, ← g.map_smul, ← g.map_smul, eq1] theorem lift'_mk (g : M →ₗ[R] M'') (h : ∀ x : S, IsUnit ((algebraMap R (Module.End R M'')) x)) (m : M) (s : S) : LocalizedModule.lift' S g h (LocalizedModule.mk m s) = (h s).unit⁻¹.val (g m) := rfl theorem lift'_add (g : M →ₗ[R] M'') (h : ∀ x : S, IsUnit ((algebraMap R (Module.End R M'')) x)) (x y) : LocalizedModule.lift' S g h (x + y) = LocalizedModule.lift' S g h x + LocalizedModule.lift' S g h y := LocalizedModule.induction_on₂ (by intro a a' b b' rw [mk_add_mk, LocalizedModule.lift'_mk, LocalizedModule.lift'_mk, LocalizedModule.lift'_mk] rw [map_add, Module.End.algebraMap_isUnit_inv_apply_eq_iff, smul_add, ← map_smul, ← map_smul, ← map_smul] congr 1 <;> symm · rw [Module.End.algebraMap_isUnit_inv_apply_eq_iff] simp only [Submonoid.coe_mul, LinearMap.map_smul_of_tower] rw [mul_smul, Submonoid.smul_def] · dsimp rw [Module.End.algebraMap_isUnit_inv_apply_eq_iff, mul_comm, mul_smul, ← map_smul] rfl) x y theorem lift'_smul (g : M →ₗ[R] M'') (h : ∀ x : S, IsUnit ((algebraMap R (Module.End R M'')) x)) (r : R) (m) : r • LocalizedModule.lift' S g h m = LocalizedModule.lift' S g h (r • m) := m.induction_on fun a b => by rw [LocalizedModule.lift'_mk, LocalizedModule.smul'_mk, LocalizedModule.lift'_mk, ← map_smul, ← g.map_smul] /-- If `g` is a linear map `M → M''` such that all scalar multiplication by `s : S` is invertible, then there is a linear map `LocalizedModule S M → M''`. -/ noncomputable def lift (g : M →ₗ[R] M'') (h : ∀ x : S, IsUnit ((algebraMap R (Module.End R M'')) x)) : LocalizedModule S M →ₗ[R] M'' where toFun := LocalizedModule.lift' S g h map_add' := LocalizedModule.lift'_add S g h map_smul' r x := by rw [LocalizedModule.lift'_smul, RingHom.id_apply] /-- If `g` is a linear map `M → M''` such that all scalar multiplication by `s : S` is invertible, then `lift g m s = s⁻¹ • g m`. -/ theorem lift_mk (g : M →ₗ[R] M'') (h : ∀ x : S, IsUnit (algebraMap R (Module.End R M'') x)) (m : M) (s : S) : LocalizedModule.lift S g h (LocalizedModule.mk m s) = (h s).unit⁻¹.val (g m) := rfl @[simp] lemma lift_mk_one (h : ∀ (x : S), IsUnit ((algebraMap R (Module.End R M'')) x)) (m : M) : (LocalizedModule.lift S g h) (LocalizedModule.mk m 1) = g m := by simp [lift_mk] /-- If `g` is a linear map `M → M''` such that all scalar multiplication by `s : S` is invertible, then there is a linear map `lift g ∘ mkLinearMap = g`. -/ theorem lift_comp (g : M →ₗ[R] M'') (h : ∀ x : S, IsUnit ((algebraMap R (Module.End R M'')) x)) : (lift S g h).comp (mkLinearMap S M) = g := by ext x simp [LocalizedModule.lift_mk] /-- If `g` is a linear map `M → M''` such that all scalar multiplication by `s : S` is invertible and `l` is another linear map `LocalizedModule S M ⟶ M''` such that `l ∘ mkLinearMap = g` then `l = lift g` -/ theorem lift_unique (g : M →ₗ[R] M'') (h : ∀ x : S, IsUnit ((algebraMap R (Module.End R M'')) x)) (l : LocalizedModule S M →ₗ[R] M'') (hl : l.comp (LocalizedModule.mkLinearMap S M) = g) : LocalizedModule.lift S g h = l := by ext x; induction x with | _ m s rw [LocalizedModule.lift_mk] rw [Module.End.algebraMap_isUnit_inv_apply_eq_iff, ← hl, LinearMap.coe_comp, Function.comp_apply, LocalizedModule.mkLinearMap_apply, ← l.map_smul, LocalizedModule.smul'_mk] congr 1; rw [LocalizedModule.mk_eq] refine ⟨1, ?_⟩; simp only [one_smul, Submonoid.smul_def] end LocalizedModule instance localizedModuleIsLocalizedModule : IsLocalizedModule S (LocalizedModule.mkLinearMap S M) where map_units s := ⟨⟨algebraMap R (Module.End R (LocalizedModule S M)) s, LocalizedModule.divBy s, DFunLike.ext _ _ <| LocalizedModule.mul_by_divBy s, DFunLike.ext _ _ <| LocalizedModule.divBy_mul_by s⟩, DFunLike.ext _ _ fun p => p.induction_on <| by intros rfl⟩ surj p := p.induction_on fun m t => by refine ⟨⟨m, t⟩, ?_⟩ rw [Submonoid.smul_def, LocalizedModule.smul'_mk, LocalizedModule.mkLinearMap_apply, ← Submonoid.smul_def, LocalizedModule.mk_cancel t] exists_of_eq eq1 := by simpa only [eq_comm, one_smul] using LocalizedModule.mk_eq.mp eq1 lemma IsLocalizedModule.of_restrictScalars (S : Submonoid R) {N : Type*} [AddCommMonoid N] [Module R N] [Module A M] [Module A N] [IsScalarTower R A M] [IsScalarTower R A N] (f : M →ₗ[A] N) [IsLocalizedModule S (f.restrictScalars R)] : IsLocalizedModule (Algebra.algebraMapSubmonoid A S) f where map_units x := by obtain ⟨_, x, hx, rfl⟩ := x have := IsLocalizedModule.map_units (f.restrictScalars R) ⟨x, hx⟩ simp only [← IsScalarTower.algebraMap_apply, Module.End.isUnit_iff] at this ⊢ exact this surj y := by obtain ⟨⟨x, t⟩, e⟩ := IsLocalizedModule.surj S (f.restrictScalars R) y exact ⟨⟨x, ⟨_, t, t.2, rfl⟩⟩, by simpa [Submonoid.smul_def] using e⟩ exists_of_eq {x₁ x₂} e := by obtain ⟨c, hc⟩ := IsLocalizedModule.exists_of_eq (S := S) (f := f.restrictScalars R) e refine ⟨⟨_, c, c.2, rfl⟩, by simpa [Submonoid.smul_def]⟩ lemma IsLocalizedModule.of_exists_mul_mem {N : Type*} [AddCommMonoid N] [Module R N] (S T : Submonoid R) (h : S ≤ T) (h' : ∀ x : T, ∃ m : R, m * x ∈ S) (f : M →ₗ[R] N) [IsLocalizedModule S f] : IsLocalizedModule T f where map_units x := by obtain ⟨m, mx⟩ := h' x have := IsLocalizedModule.map_units f ⟨_, mx⟩ rw [map_mul, (Algebra.commute_algebraMap_left _ _).isUnit_mul_iff] at this exact this.2 surj y := by obtain ⟨⟨x, t⟩, e⟩ := IsLocalizedModule.surj S f y exact ⟨⟨x, ⟨t, h t.2⟩⟩, e⟩ exists_of_eq {x₁ x₂} e := by obtain ⟨c, hc⟩ := IsLocalizedModule.exists_of_eq (S := S) (f := f) e exact ⟨⟨c, h c.2⟩, hc⟩ namespace IsLocalizedModule variable [IsLocalizedModule S f] /-- If `(M', f : M ⟶ M')` satisfies universal property of localized module, there is a canonical map `LocalizedModule S M ⟶ M'`. -/ noncomputable def fromLocalizedModule' : LocalizedModule S M → M' := fun p => p.liftOn (fun x => (IsLocalizedModule.map_units f x.2).unit⁻¹.val (f x.1)) (by rintro ⟨a, b⟩ ⟨a', b'⟩ ⟨c, eq1⟩ dsimp rw [Module.End.algebraMap_isUnit_inv_apply_eq_iff, ← map_smul, ← map_smul, Module.End.algebraMap_isUnit_inv_apply_eq_iff', ← map_smul] exact (IsLocalizedModule.eq_iff_exists S f).mpr ⟨c, eq1.symm⟩) @[simp] theorem fromLocalizedModule'_mk (m : M) (s : S) : fromLocalizedModule' S f (LocalizedModule.mk m s) = (IsLocalizedModule.map_units f s).unit⁻¹.val (f m) := rfl theorem fromLocalizedModule'_add (x y : LocalizedModule S M) : fromLocalizedModule' S f (x + y) = fromLocalizedModule' S f x + fromLocalizedModule' S f y := LocalizedModule.induction_on₂ (by intro a a' b b' simp only [LocalizedModule.mk_add_mk, fromLocalizedModule'_mk] rw [Module.End.algebraMap_isUnit_inv_apply_eq_iff, smul_add, ← map_smul, ← map_smul, ← map_smul, map_add] congr 1 all_goals rw [Module.End.algebraMap_isUnit_inv_apply_eq_iff'] · simp [mul_smul, Submonoid.smul_def] · rw [Submonoid.coe_mul, LinearMap.map_smul_of_tower, mul_comm, mul_smul, Submonoid.smul_def]) x y theorem fromLocalizedModule'_smul (r : R) (x : LocalizedModule S M) : r • fromLocalizedModule' S f x = fromLocalizedModule' S f (r • x) := LocalizedModule.induction_on (by intro a b rw [fromLocalizedModule'_mk, LocalizedModule.smul'_mk, fromLocalizedModule'_mk, f.map_smul, map_smul]) x /-- If `(M', f : M ⟶ M')` satisfies universal property of localized module, there is a canonical map `LocalizedModule S M ⟶ M'`. -/ noncomputable def fromLocalizedModule : LocalizedModule S M →ₗ[R] M' where toFun := fromLocalizedModule' S f map_add' := fromLocalizedModule'_add S f map_smul' r x := by rw [fromLocalizedModule'_smul, RingHom.id_apply] theorem fromLocalizedModule_mk (m : M) (s : S) : fromLocalizedModule S f (LocalizedModule.mk m s) = (IsLocalizedModule.map_units f s).unit⁻¹.val (f m) := rfl theorem fromLocalizedModule.inj : Function.Injective <| fromLocalizedModule S f := fun x y eq1 => by induction x with | _ a b induction y with | _ a' b' simp only [fromLocalizedModule_mk] at eq1 rw [Module.End.algebraMap_isUnit_inv_apply_eq_iff, ← LinearMap.map_smul, Module.End.algebraMap_isUnit_inv_apply_eq_iff'] at eq1 rw [LocalizedModule.mk_eq, ← IsLocalizedModule.eq_iff_exists S f, Submonoid.smul_def, Submonoid.smul_def, f.map_smul, f.map_smul, eq1] theorem fromLocalizedModule.surj : Function.Surjective <| fromLocalizedModule S f := fun x => let ⟨⟨m, s⟩, eq1⟩ := IsLocalizedModule.surj S f x ⟨LocalizedModule.mk m s, by rw [fromLocalizedModule_mk, Module.End.algebraMap_isUnit_inv_apply_eq_iff, ← eq1, Submonoid.smul_def]⟩ theorem fromLocalizedModule.bij : Function.Bijective <| fromLocalizedModule S f := ⟨fromLocalizedModule.inj _ _, fromLocalizedModule.surj _ _⟩ /-- If `(M', f : M ⟶ M')` satisfies universal property of localized module, then `M'` is isomorphic to `LocalizedModule S M` as an `R`-module. -/ noncomputable def iso : LocalizedModule S M ≃ₗ[R] M' := { fromLocalizedModule S f, Equiv.ofBijective (fromLocalizedModule S f) <| fromLocalizedModule.bij _ _ with } theorem iso_apply_mk (m : M) (s : S) : iso S f (LocalizedModule.mk m s) = (IsLocalizedModule.map_units f s).unit⁻¹.val (f m) := rfl @[simp] lemma iso_mk_one (x : M) : (iso S f) (LocalizedModule.mk x 1) = f x := by simp [iso_apply_mk] theorem iso_symm_apply_aux (m : M') : (iso S f).symm m = LocalizedModule.mk (IsLocalizedModule.surj S f m).choose.1 (IsLocalizedModule.surj S f m).choose.2 := by apply_fun iso S f using LinearEquiv.injective (iso S f) rw [LinearEquiv.apply_symm_apply] simp [iso, fromLocalizedModule, Module.End.algebraMap_isUnit_inv_apply_eq_iff', ← Submonoid.smul_def, (surj _ _ _).choose_spec] theorem iso_symm_apply' (m : M') (a : M) (b : S) (eq1 : b • m = f a) : (iso S f).symm m = LocalizedModule.mk a b := (iso_symm_apply_aux S f m).trans <| LocalizedModule.mk_eq.mpr <| by rw [← IsLocalizedModule.eq_iff_exists S f, Submonoid.smul_def, Submonoid.smul_def, f.map_smul, f.map_smul, ← (surj _ _ _).choose_spec, ← Submonoid.smul_def, ← Submonoid.smul_def, ← mul_smul, mul_comm, mul_smul, eq1] theorem iso_symm_comp : (iso S f).symm.toLinearMap.comp f = LocalizedModule.mkLinearMap S M := by ext m rw [LinearMap.comp_apply, LocalizedModule.mkLinearMap_apply, LinearEquiv.coe_coe, iso_symm_apply'] exact one_smul _ _ @[simp] lemma iso_symm_apply (x) : (iso S f).symm (f x) = LocalizedModule.mk x 1 := DFunLike.congr_fun (iso_symm_comp S f) x /-- If `M'` is a localized module and `g` is a linear map `M → M''` such that all scalar multiplication by `s : S` is invertible, then there is a linear map `M' → M''`. -/ noncomputable def lift (g : M →ₗ[R] M'') (h : ∀ x : S, IsUnit ((algebraMap R (Module.End R M'')) x)) : M' →ₗ[R] M'' := (LocalizedModule.lift S g h).comp (iso S f).symm.toLinearMap theorem lift_comp (g : M →ₗ[R] M'') (h : ∀ x : S, IsUnit ((algebraMap R (Module.End R M'')) x)) : (lift S f g h).comp f = g := by dsimp only [IsLocalizedModule.lift] rw [LinearMap.comp_assoc, iso_symm_comp, LocalizedModule.lift_comp S g h] @[simp] lemma lift_iso (h : ∀ (x : S), IsUnit ((algebraMap R (Module.End R M'')) x)) (x : LocalizedModule S M) : IsLocalizedModule.lift S f g h ((iso S f) x) = LocalizedModule.lift S g h x := by simp [lift] @[simp] lemma lift_comp_iso (h : ∀ (x : S), IsUnit ((algebraMap R (Module.End R M'')) x)) : IsLocalizedModule.lift S f g h ∘ₗ iso S f = LocalizedModule.lift S g h := LinearMap.ext fun x ↦ lift_iso S f g h x @[simp] theorem lift_apply (g : M →ₗ[R] M'') (h) (x) : lift S f g h (f x) = g x := LinearMap.congr_fun (lift_comp S f g h) x theorem lift_unique (g : M →ₗ[R] M'') (h : ∀ x : S, IsUnit ((algebraMap R (Module.End R M'')) x)) (l : M' →ₗ[R] M'') (hl : l.comp f = g) : lift S f g h = l := by dsimp only [IsLocalizedModule.lift] rw [LocalizedModule.lift_unique S g h (l.comp (iso S f).toLinearMap), LinearMap.comp_assoc, LinearEquiv.comp_coe, LinearEquiv.symm_trans_self, LinearEquiv.refl_toLinearMap, LinearMap.comp_id] rw [LinearMap.comp_assoc, ← hl] ext x simp /-- Universal property from localized module: If `(M', f : M ⟶ M')` is a localized module then it satisfies the following universal property: For every `R`-module `M''` which every `s : S`-scalar multiplication is invertible and for every `R`-linear map `g : M ⟶ M''`, there is a unique `R`-linear map `l : M' ⟶ M''` such that `l ∘ f = g`. ``` M -----f----> M' | / |g / | / l v / M'' ``` -/ theorem is_universal : ∀ (g : M →ₗ[R] M'') (_ : ∀ x : S, IsUnit ((algebraMap R (Module.End R M'')) x)), ∃! l : M' →ₗ[R] M'', l.comp f = g := fun g h => ⟨lift S f g h, lift_comp S f g h, fun l hl => (lift_unique S f g h l hl).symm⟩ theorem linearMap_ext {N N'} [AddCommMonoid N] [Module R N] [AddCommMonoid N'] [Module R N'] (f' : N →ₗ[R] N') [IsLocalizedModule S f'] ⦃g g' : M' →ₗ[R] N'⦄ (h : g ∘ₗ f = g' ∘ₗ f) : g = g' := (is_universal S f _ <| map_units f').unique h rfl theorem ext (map_unit : ∀ x : S, IsUnit ((algebraMap R (Module.End R M'')) x)) ⦃j k : M' →ₗ[R] M''⦄ (h : j.comp f = k.comp f) : j = k := by rw [← lift_unique S f (k.comp f) map_unit j h, lift_unique] rfl /-- If `(M', f)` and `(M'', g)` both satisfy universal property of localized module, then `M', M''` are isomorphic as `R`-module -/ noncomputable def linearEquiv [IsLocalizedModule S g] : M' ≃ₗ[R] M'' := (iso S f).symm.trans (iso S g) @[simp] lemma linearEquiv_apply [IsLocalizedModule S g] (x : M) : (linearEquiv S f g) (f x) = g x := by simp [linearEquiv] @[simp] lemma linearEquiv_symm_apply [IsLocalizedModule S g] (x : M) : (linearEquiv S f g).symm (g x) = f x := by simp [linearEquiv] variable {S} include f in theorem smul_injective (s : S) : Function.Injective fun m : M' => s • m := ((Module.End.isUnit_iff _).mp (IsLocalizedModule.map_units f s)).injective include f in theorem smul_inj (s : S) (m₁ m₂ : M') : s • m₁ = s • m₂ ↔ m₁ = m₂ := (smul_injective f s).eq_iff include f in lemma isRegular_of_smul_left_injective {m : M'} (inj : Function.Injective fun r : R ↦ r • m) (s : S) : IsRegular (s : R) := (Commute.isRegular_iff (Commute.all _)).mpr fun r r' eq ↦ by have := congr_arg (· • m) eq simp_rw [mul_smul, ← Submonoid.smul_def, smul_inj f] at this exact inj this /-- `mk' f m s` is the fraction `m/s` with respect to the localization map `f`. -/ noncomputable def mk' (m : M) (s : S) : M' := fromLocalizedModule S f (LocalizedModule.mk m s) theorem mk'_smul (r : R) (m : M) (s : S) : mk' f (r • m) s = r • mk' f m s := by delta mk' rw [← LocalizedModule.smul'_mk, LinearMap.map_smul] theorem mk'_add_mk' (m₁ m₂ : M) (s₁ s₂ : S) : mk' f m₁ s₁ + mk' f m₂ s₂ = mk' f (s₂ • m₁ + s₁ • m₂) (s₁ * s₂) := by delta mk' rw [← map_add, LocalizedModule.mk_add_mk] @[simp] theorem mk'_zero (s : S) : mk' f 0 s = 0 := by rw [← zero_smul R (0 : M), mk'_smul, zero_smul] variable (S) in @[simp] theorem mk'_one (m : M) : mk' f m (1 : S) = f m := by delta mk' rw [fromLocalizedModule_mk, Module.End.algebraMap_isUnit_inv_apply_eq_iff, Submonoid.coe_one, one_smul] @[simp] theorem mk'_cancel (m : M) (s : S) : mk' f (s • m) s = f m := by delta mk' rw [LocalizedModule.mk_cancel, ← mk'_one S f, fromLocalizedModule_mk, Module.End.algebraMap_isUnit_inv_apply_eq_iff, OneMemClass.coe_one, mk'_one, one_smul] @[simp] theorem mk'_cancel' (m : M) (s : S) : s • mk' f m s = f m := by rw [Submonoid.smul_def, ← mk'_smul, ← Submonoid.smul_def, mk'_cancel] @[simp] theorem mk'_cancel_left (m : M) (s₁ s₂ : S) : mk' f (s₁ • m) (s₁ * s₂) = mk' f m s₂ := by delta mk' rw [LocalizedModule.mk_cancel_common_left] @[simp] theorem mk'_cancel_right (m : M) (s₁ s₂ : S) : mk' f (s₂ • m) (s₁ * s₂) = mk' f m s₁ := by delta mk' rw [LocalizedModule.mk_cancel_common_right] theorem mk'_add (m₁ m₂ : M) (s : S) : mk' f (m₁ + m₂) s = mk' f m₁ s + mk' f m₂ s := by rw [mk'_add_mk', ← smul_add, mk'_cancel_left] theorem mk'_eq_mk'_iff (m₁ m₂ : M) (s₁ s₂ : S) : mk' f m₁ s₁ = mk' f m₂ s₂ ↔ ∃ s : S, s • s₁ • m₂ = s • s₂ • m₁ := by delta mk' rw [(fromLocalizedModule.inj S f).eq_iff, LocalizedModule.mk_eq] simp_rw [eq_comm] theorem mk'_neg {M M' : Type*} [AddCommGroup M] [SubtractionCommMonoid M'] [Module R M] [Module R M'] (f : M →ₗ[R] M') [IsLocalizedModule S f] (m : M) (s : S) : mk' f (-m) s = -mk' f m s := by delta mk' rw [LocalizedModule.mk_neg, map_neg] theorem mk'_sub {M M' : Type*} [AddCommGroup M] [SubtractionCommMonoid M'] [Module R M] [Module R M'] (f : M →ₗ[R] M') [IsLocalizedModule S f] (m₁ m₂ : M) (s : S) : mk' f (m₁ - m₂) s = mk' f m₁ s - mk' f m₂ s := by rw [sub_eq_add_neg, sub_eq_add_neg, mk'_add, mk'_neg] theorem mk'_sub_mk' {M M' : Type*} [AddCommGroup M] [SubtractionCommMonoid M'] [Module R M] [Module R M'] (f : M →ₗ[R] M') [IsLocalizedModule S f] (m₁ m₂ : M) (s₁ s₂ : S) : mk' f m₁ s₁ - mk' f m₂ s₂ = mk' f (s₂ • m₁ - s₁ • m₂) (s₁ * s₂) := by rw [sub_eq_add_neg, ← mk'_neg, mk'_add_mk', smul_neg, ← sub_eq_add_neg] theorem mk'_mul_mk'_of_map_mul {M M' : Type*} [NonUnitalNonAssocSemiring M] [Semiring M'] [Module R M] [Algebra R M'] (f : M →ₗ[R] M') (hf : ∀ m₁ m₂, f (m₁ * m₂) = f m₁ * f m₂) [IsLocalizedModule S f] (m₁ m₂ : M) (s₁ s₂ : S) : mk' f m₁ s₁ * mk' f m₂ s₂ = mk' f (m₁ * m₂) (s₁ * s₂) := by symm apply (Module.End.algebraMap_isUnit_inv_apply_eq_iff _ _ _ _).mpr simp_rw [Submonoid.coe_mul, ← smul_eq_mul] rw [smul_smul_smul_comm, ← mk'_smul, ← mk'_smul] simp_rw [← Submonoid.smul_def, mk'_cancel, smul_eq_mul, hf] theorem mk'_mul_mk' {M M' : Type*} [Semiring M] [Semiring M'] [Algebra R M] [Algebra R M'] (f : M →ₐ[R] M') [IsLocalizedModule S f.toLinearMap] (m₁ m₂ : M) (s₁ s₂ : S) : mk' f.toLinearMap m₁ s₁ * mk' f.toLinearMap m₂ s₂ = mk' f.toLinearMap (m₁ * m₂) (s₁ * s₂) := mk'_mul_mk'_of_map_mul f.toLinearMap (map_mul f) m₁ m₂ s₁ s₂ variable {f} theorem mk'_eq_iff {m : M} {s : S} {m' : M'} : mk' f m s = m' ↔ f m = s • m' := by rw [← smul_inj f s, Submonoid.smul_def, ← mk'_smul, ← Submonoid.smul_def, mk'_cancel] @[simp] theorem mk'_eq_zero {m : M} (s : S) : mk' f m s = 0 ↔ f m = 0 := by rw [mk'_eq_iff, smul_zero] variable (f) theorem mk'_eq_zero' {m : M} (s : S) : mk' f m s = 0 ↔ ∃ s' : S, s' • m = 0 := by simp_rw [← mk'_zero f (1 : S), mk'_eq_mk'_iff, smul_zero, one_smul, eq_comm] theorem mk_eq_mk' (s : S) (m : M) : LocalizedModule.mk m s = mk' (LocalizedModule.mkLinearMap S M) m s := by rw [eq_comm, mk'_eq_iff, Submonoid.smul_def, LocalizedModule.smul'_mk, ← Submonoid.smul_def, LocalizedModule.mk_cancel, LocalizedModule.mkLinearMap_apply] variable (A) in lemma mk'_smul_mk' (x : R) (m : M) (s t : S) : IsLocalization.mk' A x s • mk' f m t = mk' f (x • m) (s * t) := by apply smul_injective f (s * t) conv_lhs => simp only [smul_assoc, mul_smul, smul_comm t] simp only [mk'_cancel', map_smul, Submonoid.smul_def s] rw [← smul_assoc, IsLocalization.smul_mk'_self, algebraMap_smul] variable (S) theorem eq_zero_iff {m : M} : f m = 0 ↔ ∃ s' : S, s' • m = 0 := (mk'_eq_zero (1 : S)).symm.trans (mk'_eq_zero' f _) theorem mk'_surjective : Function.Surjective (Function.uncurry <| mk' f : M × S → M') := by intro x obtain ⟨⟨m, s⟩, e : s • x = f m⟩ := IsLocalizedModule.surj S f x exact ⟨⟨m, s⟩, mk'_eq_iff.mpr e.symm⟩ section liftOfLE variable {M₁ M₂} [AddCommMonoid M₁] [AddCommMonoid M₂] [Module R M₁] [Module R M₂] variable (S₁ S₂ : Submonoid R) (h : S₁ ≤ S₂) (f₁ : M →ₗ[R] M₁) (f₂ : M →ₗ[R] M₂) variable [IsLocalizedModule S₁ f₁] [IsLocalizedModule S₂ f₂] /-- The natural map `Mₛ →ₗ[R] Mₜ` if `s ≤ t` (in `Submonoid R`). -/ noncomputable def liftOfLE : M₁ →ₗ[R] M₂ := lift S₁ f₁ f₂ fun x ↦ map_units f₂ ⟨x.1, h x.2⟩ /-- The natural map `Mₛ →ₗ[R] Mₜ` if `s ≤ t` (in `Submonoid R`). -/ noncomputable abbrev _root_.LocalizedModule.liftOfLE : LocalizedModule S₁ M →ₗ[R] LocalizedModule S₂ M := IsLocalizedModule.liftOfLE S₁ S₂ h (LocalizedModule.mkLinearMap S₁ M) (LocalizedModule.mkLinearMap S₂ M) lemma liftOfLE_comp : (liftOfLE S₁ S₂ h f₁ f₂).comp f₁ = f₂ := lift_comp .. @[simp] lemma liftOfLE_apply (x) : liftOfLE S₁ S₂ h f₁ f₂ (f₁ x) = f₂ x := lift_apply .. /-- The image of `m/s` under `liftOfLE` is `m/s`. -/ @[simp] lemma liftOfLE_mk' (m : M) (s : S₁) : liftOfLE S₁ S₂ h f₁ f₂ (mk' f₁ m s) = mk' f₂ m ⟨s.1, h s.2⟩ := by apply ((Module.End.isUnit_iff _).mp (map_units f₂ ⟨s, h s.2⟩)).1 simp only [Module.algebraMap_end_apply, ← map_smul, ← Submonoid.smul_def, mk'_cancel'] rw [liftOfLE, lift_apply] exact (mk'_cancel' (S := S₂) f₂ m ⟨s.1, h s.2⟩).symm instance : IsLocalizedModule S₂ (liftOfLE S₁ S₂ h f₁ f₂) where map_units := map_units f₂ surj y := by obtain ⟨⟨y', s⟩, e⟩ := IsLocalizedModule.surj S₂ f₂ y exact ⟨⟨f₁ y', s⟩, by simpa⟩ exists_of_eq := by intro x₁ x₂ e obtain ⟨x₁, s₁, rfl⟩ := mk'_surjective S₁ f₁ x₁ obtain ⟨x₂, s₂, rfl⟩ := mk'_surjective S₁ f₁ x₂ simp only [Function.uncurry, liftOfLE_mk', mk'_eq_mk'_iff, Submonoid.smul_def, ← mk'_smul] at e ⊢ obtain ⟨c, e⟩ := e exact ⟨c, 1, by simpa [← smul_comm c.1]⟩ end liftOfLE include S in lemma injective_of_map_eq {N : Type*} [AddCommMonoid N] [Module R N] {g : M' →ₗ[R] N} (H : ∀ {x y}, g (f x) = g (f y) → f x = f y) : Function.Injective g := by intro a b hab obtain ⟨⟨x, m⟩, (hxm : m • a = f x)⟩ := IsLocalizedModule.surj S f a obtain ⟨⟨y, n⟩, (hym : n • b = f y)⟩ := IsLocalizedModule.surj S f b suffices h : g (f (n.val • x)) = g (f (m.val • y)) by apply H at h rw [map_smul, map_smul] at h rwa [← IsLocalizedModule.smul_inj f (n * m), mul_smul, mul_comm, mul_smul, hxm, hym] simp [← hxm, ← hym, hab, ← S.smul_def, ← mul_smul, mul_comm, ← mul_smul] lemma injective_of_map_zero {M M' N : Type*} [AddCommGroup M] [AddCommGroup M'] [Module R M] [Module R M'] (f : M →ₗ[R] M') [IsLocalizedModule S f] [AddCommGroup N] [Module R N] {g : M' →ₗ[R] N} (H : ∀ m, g (f m) = 0 → f m = 0) : Function.Injective g := by refine IsLocalizedModule.injective_of_map_eq S f (fun hxy ↦ ?_) rw [← sub_eq_zero, ← map_sub] apply H simpa [sub_eq_zero] variable {N N'} [AddCommMonoid N] [AddCommMonoid N'] [Module R N] [Module R N'] variable (g : N →ₗ[R] N') [IsLocalizedModule S g] /-- A linear map `M →ₗ[R] N` gives a map between localized modules `Mₛ →ₗ[R] Nₛ`. -/ noncomputable def map : (M →ₗ[R] N) →ₗ[R] (M' →ₗ[R] N') where toFun h := lift S f (g ∘ₗ h) (IsLocalizedModule.map_units g) map_add' h₁ h₂ := by apply IsLocalizedModule.ext S f (IsLocalizedModule.map_units g) simp only [lift_comp, LinearMap.add_comp, LinearMap.comp_add] map_smul' r h := by apply IsLocalizedModule.ext S f (IsLocalizedModule.map_units g) simp only [lift_comp, LinearMap.smul_comp, LinearMap.comp_smul, RingHom.id_apply] lemma map_comp (h : M →ₗ[R] N) : (map S f g h) ∘ₗ f = g ∘ₗ h := lift_comp S f (g ∘ₗ h) (IsLocalizedModule.map_units g) @[simp] lemma map_apply (h : M →ₗ[R] N) (x) : map S f g h (f x) = g (h x) := lift_apply S f (g ∘ₗ h) (IsLocalizedModule.map_units g) x @[simp] lemma map_mk' (h : M →ₗ[R] N) (x) (s : S) : map S f g h (IsLocalizedModule.mk' f x s) = (IsLocalizedModule.mk' g (h x) s) := by simp only [map, lift, LinearMap.coe_mk, AddHom.coe_mk, LinearMap.coe_comp, LinearEquiv.coe_coe, Function.comp_apply] rw [iso_symm_apply' S f (mk' f x s) x s (mk'_cancel' f x s), LocalizedModule.lift_mk] rfl @[simp] lemma map_id : map S f f (.id ) = .id := by ext x obtain ⟨⟨x, s⟩, rfl⟩ := IsLocalizedModule.mk'_surjective S f x simp @[simp] theorem map_injective (h : M →ₗ[R] N) (h_inj : Function.Injective h) : Function.Injective (map S f g h) := by intro x y obtain ⟨⟨x, s⟩, rfl⟩ := IsLocalizedModule.mk'_surjective S f x obtain ⟨⟨y, t⟩, rfl⟩ := IsLocalizedModule.mk'_surjective S f y simp only [Function.uncurry_apply_pair, map_mk', mk'_eq_mk'_iff, Subtype.exists, Submonoid.mk_smul, exists_prop, forall_exists_index, and_imp] intro c hc e exact ⟨c, hc, h_inj (by simpa)⟩ @[simp] theorem map_surjective (h : M →ₗ[R] N) (h_surj : Function.Surjective h) : Function.Surjective (map S f g h) := by intro x obtain ⟨⟨x, s⟩, rfl⟩ := IsLocalizedModule.mk'_surjective S g x obtain ⟨x, rfl⟩ := h_surj x exact ⟨mk' f x s, by simp⟩ open LocalizedModule LinearEquiv LinearMap Submonoid variable (M) /-- The linear map `(LocalizedModule S M) → (LocalizedModule S M)` from `iso` is the identity. -/ lemma iso_localizedModule_eq_refl : iso S (mkLinearMap S M) = refl R (LocalizedModule S M) := by let f := mkLinearMap S M obtain ⟨e, _, univ⟩ := is_universal S f f (map_units f) rw [← toLinearMap_inj, univ (iso S f) ((eq_toLinearMap_symm_comp f f).1 (iso_symm_comp S f).symm)] exact Eq.symm <| univ (refl R (LocalizedModule S M)) (by simp) variable {M₀ M₀'} [AddCommMonoid M₀] [AddCommMonoid M₀'] [Module R M₀] [Module R M₀'] variable (f₀ : M₀ →ₗ[R] M₀') [IsLocalizedModule S f₀] variable {M₁ M₁'} [AddCommMonoid M₁] [AddCommMonoid M₁'] [Module R M₁] [Module R M₁'] variable (f₁ : M₁ →ₗ[R] M₁') [IsLocalizedModule S f₁] /-- Formula for `IsLocalizedModule.map` when each localized module is a `LocalizedModule`. -/ lemma map_LocalizedModules (g : M₀ →ₗ[R] M₁) (m : M₀) (s : S) : ((map S (mkLinearMap S M₀) (mkLinearMap S M₁)) g) (LocalizedModule.mk m s) = LocalizedModule.mk (g m) s := by have := (iso_apply_mk S (mkLinearMap S M₁) (g m) s).symm rw [iso_localizedModule_eq_refl, refl_apply] at this simpa [map, lift, iso_localizedModule_eq_refl S M₀] lemma map_iso_commute (g : M₀ →ₗ[R] M₁) : (map S f₀ f₁) g ∘ₗ (iso S f₀) = (iso S f₁) ∘ₗ (map S (mkLinearMap S M₀) (mkLinearMap S M₁)) g := by ext x induction x using induction_on with | _ m s refine ((Module.End.isUnit_iff _).1 (map_units f₁ s)).1 ?_ rw [Module.algebraMap_end_apply, Module.algebraMap_end_apply, ← CompatibleSMul.map_smul, ← CompatibleSMul.map_smul, smul'_mk, ← mk_smul _ s.2, mk_cancel] simp [map, lift, iso_localizedModule_eq_refl, lift_mk] end IsLocalizedModule namespace IsLocalizedModule variable {M₀ M₀'} [AddCommMonoid M₀] [AddCommMonoid M₀'] [Module R M₀] [Module R M₀'] variable (f₀ : M₀ →ₗ[R] M₀') [IsLocalizedModule S f₀] variable {M₁ M₁'} [AddCommMonoid M₁] [AddCommMonoid M₁'] [Module R M₁] [Module R M₁'] variable (f₁ : M₁ →ₗ[R] M₁') [IsLocalizedModule S f₁] variable {M₂ M₂'} [AddCommMonoid M₂] [AddCommMonoid M₂'] [Module R M₂] [Module R M₂'] variable (f₂ : M₂ →ₗ[R] M₂') [IsLocalizedModule S f₂] /-- Localization of composition is the composition of localization -/ theorem map_comp' (g : M₀ →ₗ[R] M₁) (h : M₁ →ₗ[R] M₂) : map S f₀ f₂ (h ∘ₗ g) = map S f₁ f₂ h ∘ₗ map S f₀ f₁ g := by ext x obtain ⟨⟨x, s⟩, rfl⟩ := IsLocalizedModule.mk'_surjective S f₀ x simp section Algebra theorem mkOfAlgebra {R S S' : Type*} [CommSemiring R] [Ring S] [Ring S'] [Algebra R S] [Algebra R S'] (M : Submonoid R) (f : S →ₐ[R] S') (h₁ : ∀ x ∈ M, IsUnit (algebraMap R S' x)) (h₂ : ∀ y, ∃ x : S × M, x.2 • y = f x.1) (h₃ : ∀ x, f x = 0 → ∃ m : M, m • x = 0) : IsLocalizedModule M f.toLinearMap := by replace h₃ := fun x => Iff.intro (h₃ x) fun ⟨⟨m, hm⟩, e⟩ => (h₁ m hm).mul_left_cancel <| by rw [← Algebra.smul_def] simpa [Submonoid.smul_def] using f.congr_arg e constructor · intro x rw [Module.End.isUnit_iff] constructor · rintro a b (e : x • a = x • b) simp_rw [Submonoid.smul_def, Algebra.smul_def] at e exact (h₁ x x.2).mul_left_cancel e · intro a refine ⟨((h₁ x x.2).unit⁻¹ :) * a, ?_⟩ rw [Module.algebraMap_end_apply, Algebra.smul_def, ← mul_assoc, IsUnit.mul_val_inv, one_mul] · exact h₂ · intro x y dsimp only [AlgHom.toLinearMap_apply] rw [← sub_eq_zero, ← map_sub, h₃] simp_rw [smul_sub, sub_eq_zero] exact id end Algebra variable {R A M M' : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Submonoid R) [AddCommMonoid M] [Module R M] [AddCommMonoid M'] [Module R M'] [IsLocalization S A] /-- If `M'` is the localization of `M` at `S` and `A = S⁻¹R`, then `M'` is an `A`-module. -/ @[reducible] noncomputable def module (f : M →ₗ[R] M') [IsLocalizedModule S f] : Module A M' := (IsLocalizedModule.iso S f).symm.toAddEquiv.module A lemma isScalarTower_module (f : M →ₗ[R] M') [IsLocalizedModule S f] : letI : Module A M' := IsLocalizedModule.module S f IsScalarTower R A M' := (IsLocalizedModule.iso S f).symm.isScalarTower A section Subsingleton lemma mem_ker_iff (S : Submonoid R) {g : M →ₗ[R] M'} [IsLocalizedModule S g] {m : M} : m ∈ LinearMap.ker g ↔ ∃ r ∈ S, r • m = 0 := by simpa using IsLocalizedModule.eq_zero_iff S g lemma subsingleton_iff_ker_eq_top (S : Submonoid R) (g : M →ₗ[R] M') [IsLocalizedModule S g] : Subsingleton M' ↔ LinearMap.ker g = ⊤ := by rw [← top_le_iff] refine ⟨fun H m _ ↦ Subsingleton.elim _ _, fun H ↦ (subsingleton_iff_forall_eq 0).mpr fun x ↦ ?_⟩ obtain ⟨⟨x, s⟩, rfl⟩ := IsLocalizedModule.mk'_surjective S g x simpa using @H x Submodule.mem_top lemma subsingleton_iff (S : Submonoid R) (g : M →ₗ[R] M') [IsLocalizedModule S g] : Subsingleton M' ↔ ∀ m : M, ∃ r ∈ S, r • m = 0 := by simp_rw [subsingleton_iff_ker_eq_top S g, ← top_le_iff, SetLike.le_def, mem_ker_iff S, Submodule.mem_top, true_implies] end Subsingleton end IsLocalizedModule end IsLocalizedModule namespace LocalizedModule variable {R M : Type*} [CommRing R] [AddCommMonoid M] [Module R M] lemma mem_ker_mkLinearMap_iff {S : Submonoid R} {m : M} : m ∈ LinearMap.ker (mkLinearMap S M) ↔ ∃ r ∈ S, r • m = 0 := IsLocalizedModule.mem_ker_iff S lemma subsingleton_iff_ker_eq_top {S : Submonoid R} : Subsingleton (LocalizedModule S M) ↔ LinearMap.ker (LocalizedModule.mkLinearMap S M) = ⊤ := IsLocalizedModule.subsingleton_iff_ker_eq_top S _ lemma subsingleton_iff {S : Submonoid R} : Subsingleton (LocalizedModule S M) ↔ ∀ m : M, ∃ r ∈ S, r • m = 0 := IsLocalizedModule.subsingleton_iff S (LocalizedModule.mkLinearMap S M) instance [Subsingleton M] (S : Submonoid R) : Subsingleton (LocalizedModule S M) := by rw [IsLocalizedModule.subsingleton_iff S (LocalizedModule.mkLinearMap S M)] intro use 1, S.one_mem, Subsingleton.elim _ _ end LocalizedModule namespace IsLocalizedModule variable {R M A N : Type*} [CommRing R] [AddCommMonoid M] [Module R M] [CommRing A] [AddCommMonoid N] [Module A N] [Algebra R A] [Module R N] [IsScalarTower R A N] (f : M →ₗ[R] N) theorem noZeroSMulDivisors (S : Submonoid R) [NoZeroSMulDivisors R M] [IsLocalization S A] [IsLocalizedModule S f] : NoZeroSMulDivisors A N := by rw [noZeroSMulDivisors_iff] intro c x hcx obtain ⟨a, s, rfl⟩ := IsLocalization.exists_mk'_eq S c obtain ⟨⟨m, t⟩, rfl⟩ := IsLocalizedModule.mk'_surjective S f x rw [Function.uncurry_apply_pair] at hcx ⊢ rw [mk'_smul_mk', mk'_eq_zero, IsLocalizedModule.eq_zero_iff S] at hcx obtain ⟨u, hl⟩ := hcx rw [← smul_assoc] at hl obtain (hua | rfl) := NoZeroSMulDivisors.eq_zero_or_eq_zero_of_smul_eq_zero hl · rw [IsLocalization.mk'_eq_zero_iff] exact Or.inl ⟨u, hua⟩ · simp instance (S : Submonoid R) [NoZeroSMulDivisors R M] : NoZeroSMulDivisors (Localization S) (LocalizedModule S M) := noZeroSMulDivisors (LocalizedModule.mkLinearMap S M) S end IsLocalizedModule
.lake/packages/mathlib/Mathlib/Algebra/Module/LocalizedModule/IsLocalization.lean
import Mathlib.Algebra.Algebra.Bilinear import Mathlib.Algebra.Module.LocalizedModule.Basic /-! # Equivalence between `IsLocalizedModule` and `IsLocalization` -/ section IsLocalizedModule variable {R : Type*} [CommSemiring R] (S : Submonoid R) variable {A Aₛ : Type*} [CommSemiring A] [Algebra R A] variable [CommSemiring Aₛ] [Algebra A Aₛ] [Algebra R Aₛ] [IsScalarTower R A Aₛ] variable {S} in theorem isLocalizedModule_iff_isLocalization : IsLocalizedModule S (IsScalarTower.toAlgHom R A Aₛ).toLinearMap ↔ IsLocalization (Algebra.algebraMapSubmonoid A S) Aₛ := by rw [isLocalizedModule_iff, isLocalization_iff] refine and_congr ?_ (and_congr (forall_congr' fun _ ↦ ?_) (forall₂_congr fun _ _ ↦ ?_)) · simp_rw [← (Algebra.lmul R Aₛ).commutes, Algebra.lmul_isUnit_iff, Subtype.forall, Algebra.algebraMapSubmonoid, ← SetLike.mem_coe, Submonoid.coe_map, Set.forall_mem_image, ← IsScalarTower.algebraMap_apply] · simp_rw [Prod.exists, Subtype.exists, Algebra.algebraMapSubmonoid] simp [← IsScalarTower.algebraMap_apply, Submonoid.mk_smul, Algebra.smul_def, mul_comm] · congr!; simp_rw [Subtype.exists, Algebra.algebraMapSubmonoid]; simp [Algebra.smul_def] instance [IsLocalization (Algebra.algebraMapSubmonoid A S) Aₛ] : IsLocalizedModule S (IsScalarTower.toAlgHom R A Aₛ).toLinearMap := isLocalizedModule_iff_isLocalization.mpr ‹_› variable (A) /-- `A` is a localization of a commutative semiring `R` with respect to `S` iff the associated linear map `R →ₗ[R] A` is a localization of modules with respect to `S`. -/ lemma isLocalizedModule_iff_isLocalization' : IsLocalizedModule S (Algebra.linearMap R A) ↔ IsLocalization S A := by convert isLocalizedModule_iff_isLocalization (S := S) (A := R) (Aₛ := A) exact (Submonoid.map_id S).symm instance [IsLocalization S A] : IsLocalizedModule S (Algebra.linearMap R A) := (isLocalizedModule_iff_isLocalization' S _).mpr inferInstance variable {S A} in /-- `IsLocalization.mk'` agrees with `IsLocalizedModule.mk'`. -/ lemma IsLocalization.mk'_algebraMap_eq_mk' [IsLocalization (Algebra.algebraMapSubmonoid A S) Aₛ] {x : A} {s : S} : IsLocalization.mk' Aₛ x ⟨_, Algebra.mem_algebraMapSubmonoid_of_mem s⟩ = IsLocalizedModule.mk' (IsScalarTower.toAlgHom R A Aₛ).toLinearMap x s := by rw [← IsLocalizedModule.smul_inj (IsScalarTower.toAlgHom R A Aₛ).toLinearMap s, IsLocalizedModule.mk'_cancel', Submonoid.smul_def, ← algebraMap_smul A] exact IsLocalization.smul_mk'_self (m := ⟨_, _⟩) /-- `IsLocalization.mk'` agrees with `IsLocalizedModule.mk'`. -/ lemma IsLocalization.mk'_eq_mk' [IsLocalization S A] (x : R) (s : S) : IsLocalization.mk' A x s = IsLocalizedModule.mk' (Algebra.linearMap R A) x s := by rw [← IsLocalizedModule.smul_inj (Algebra.linearMap R A) s, IsLocalizedModule.mk'_cancel'] exact IsLocalization.smul_mk'_self end IsLocalizedModule
.lake/packages/mathlib/Mathlib/Algebra/Module/LocalizedModule/Exact.lean
import Mathlib.Algebra.Exact import Mathlib.Algebra.Module.LocalizedModule.Basic /-! # Localization of modules is an exact functor ## Main definitions - `LocalizedModule.map_exact`: Localization of modules is an exact functor. - `IsLocalizedModule.map_exact`: A variant expressed in terms of `IsLocalizedModule`. -/ section open IsLocalizedModule Function Submonoid variable {R : Type*} [CommSemiring R] (S : Submonoid R) variable {M₀ M₀'} [AddCommMonoid M₀] [AddCommMonoid M₀'] [Module R M₀] [Module R M₀'] variable (f₀ : M₀ →ₗ[R] M₀') [IsLocalizedModule S f₀] variable {M₁ M₁'} [AddCommMonoid M₁] [AddCommMonoid M₁'] [Module R M₁] [Module R M₁'] variable (f₁ : M₁ →ₗ[R] M₁') [IsLocalizedModule S f₁] variable {M₂ M₂'} [AddCommMonoid M₂] [AddCommMonoid M₂'] [Module R M₂] [Module R M₂'] variable (f₂ : M₂ →ₗ[R] M₂') [IsLocalizedModule S f₂] /-- Localization of modules is an exact functor, proven here for `LocalizedModule`. See `IsLocalizedModule.map_exact` for the more general version. -/ lemma LocalizedModule.map_exact (g : M₀ →ₗ[R] M₁) (h : M₁ →ₗ[R] M₂) (ex : Exact g h) : Exact (map S (mkLinearMap S M₀) (mkLinearMap S M₁) g) (map S (mkLinearMap S M₁) (mkLinearMap S M₂) h) := fun y ↦ Iff.intro (induction_on (fun m s hy ↦ by rw [map_LocalizedModules, ← zero_mk 1, mk_eq, one_smul, smul_zero] at hy obtain ⟨a, aS, ha⟩ := Subtype.exists.1 hy rw [smul_zero, mk_smul, ← LinearMap.map_smul, ex (a • m)] at ha rcases ha with ⟨x, hx⟩ use mk x (⟨a, aS⟩ * s) rw [map_LocalizedModules, hx, ← mk_cancel_common_left ⟨a, aS⟩ s m, mk_smul]) y) fun ⟨x, hx⟩ ↦ by revert hx refine induction_on (fun m s hx ↦ ?_) x rw [← hx, map_LocalizedModules, map_LocalizedModules, (ex (g m)).2 ⟨m, rfl⟩, zero_mk] /-- Localization of modules is an exact functor. -/ theorem IsLocalizedModule.map_exact (g : M₀ →ₗ[R] M₁) (h : M₁ →ₗ[R] M₂) (ex : Function.Exact g h) : Function.Exact (map S f₀ f₁ g) (map S f₁ f₂ h) := Function.Exact.of_ladder_linearEquiv_of_exact (map_iso_commute S f₀ f₁ g) (map_iso_commute S f₁ f₂ h) (LocalizedModule.map_exact S g h ex) end
.lake/packages/mathlib/Mathlib/Algebra/Module/LocalizedModule/Submodule.lean
import Mathlib.Algebra.Module.Submodule.Pointwise import Mathlib.LinearAlgebra.Quotient.Basic import Mathlib.RingTheory.Localization.Module import Mathlib.Algebra.Algebra.Operations /-! # Localization of Submodules Results about localizations of submodules and quotient modules are provided in this file. ## Main results - `Submodule.localized`: The localization of an `R`-submodule of `M` at `p` viewed as an `Rₚ`-submodule of `Mₚ`. A direct consequence of this is that `Rₚ` is flat over `R`; see `IsLocalization.flat`. - `Submodule.toLocalized`: The localization map of a submodule `M' →ₗ[R] M'.localized p`. - `Submodule.toLocalizedQuotient`: The localization map of a quotient module `M ⧸ M' →ₗ[R] LocalizedModule p M ⧸ M'.localized p`. ## TODO - Statements regarding the exactness of localization. -/ open nonZeroDivisors variable {R S M N : Type*} variable (S) [CommSemiring R] [CommSemiring S] [AddCommMonoid M] [AddCommMonoid N] variable [Module R M] [Module R N] [Algebra R S] [Module S N] [IsScalarTower R S N] variable (p : Submonoid R) [IsLocalization p S] (f : M →ₗ[R] N) [IsLocalizedModule p f] variable (M' : Submodule R M) namespace Submodule /-- Let `N` be a localization of an `R`-module `M` at `p`. This is the localization of an `R`-submodule of `M` viewed as an `R`-submodule of `N`. -/ def localized₀ : Submodule R N where carrier := { x | ∃ m ∈ M', ∃ s : p, IsLocalizedModule.mk' f m s = x } add_mem' := fun {x y} ⟨m, hm, s, hx⟩ ⟨n, hn, t, hy⟩ ↦ ⟨t • m + s • n, add_mem (M'.smul_mem t hm) (M'.smul_mem s hn), s * t, by rw [← hx, ← hy, IsLocalizedModule.mk'_add_mk']⟩ zero_mem' := ⟨0, zero_mem _, 1, by simp⟩ smul_mem' r x := by rintro ⟨m, hm, s, hx⟩ exact ⟨r • m, smul_mem M' _ hm, s, by rw [IsLocalizedModule.mk'_smul, hx]⟩ /-- Let `S` be the localization of `R` at `p` and `N` be a localization of `M` at `p`. This is the localization of an `R`-submodule of `M` viewed as an `S`-submodule of `N`. -/ def localized' : Submodule S N where __ := localized₀ p f M' smul_mem' := fun r x ⟨m, hm, s, hx⟩ ↦ by have ⟨y, t, hyt⟩ := IsLocalization.exists_mk'_eq p r exact ⟨y • m, M'.smul_mem y hm, t * s, by simp [← hyt, ← hx, IsLocalizedModule.mk'_smul_mk']⟩ lemma mem_localized₀ (x : N) : x ∈ localized₀ p f M' ↔ ∃ m ∈ M', ∃ s : p, IsLocalizedModule.mk' f m s = x := Iff.rfl lemma mem_localized' (x : N) : x ∈ localized' S p f M' ↔ ∃ m ∈ M', ∃ s : p, IsLocalizedModule.mk' f m s = x := Iff.rfl /-- `localized₀` is the same as `localized'` considered as a submodule over the base ring. -/ lemma restrictScalars_localized' : (localized' S p f M').restrictScalars R = localized₀ p f M' := rfl theorem localized'_eq_span : localized' S p f M' = span S (f '' M') := by refine le_antisymm ?_ (span_le.mpr <| by rintro _ ⟨m, hm, rfl⟩; exact ⟨m, hm, 1, by simp⟩) rintro _ ⟨m, hm, s, rfl⟩ rw [← one_smul R m, ← mul_one s, ← IsLocalizedModule.mk'_smul_mk' S] exact smul_mem _ _ (subset_span ⟨m, hm, by simp⟩) /-- The Galois insertion between `Submodule R M` and `Submodule S N`, where `S` is the localization of `R` at `p` and `N` is the localization of `M` at `p`. -/ def localized'gi : GaloisInsertion (localized' S p f) (comap f <| ·.restrictScalars R) where gc M' N' := ⟨fun h m hm ↦ h ⟨m, hm, 1, by simp⟩, fun h ↦ by rw [localized'_eq_span, span_le]; apply map_le_iff_le_comap.mpr h⟩ le_l_u N' n hn := by obtain ⟨⟨m, s⟩, rfl⟩ := IsLocalizedModule.mk'_surjective p f n refine ⟨m, ?_, s, rfl⟩ rw [mem_comap, restrictScalars_mem, ← IsLocalizedModule.mk'_cancel' _ _ s, Submonoid.smul_def, ← algebraMap_smul S] exact smul_mem _ _ hn choice x _ := localized' S p f x choice_eq _ _ := rfl /-- The localization of an `R`-submodule of `M` at `p` viewed as an `Rₚ`-submodule of `Mₚ`. -/ noncomputable abbrev localized : Submodule (Localization p) (LocalizedModule p M) := M'.localized' (Localization p) p (LocalizedModule.mkLinearMap p M) @[simp] lemma localized₀_bot : (⊥ : Submodule R M).localized₀ p f = ⊥ := by rw [← le_bot_iff] rintro _ ⟨_, rfl, s, rfl⟩ simp only [IsLocalizedModule.mk'_zero, mem_bot] @[simp] lemma localized'_bot : (⊥ : Submodule R M).localized' S p f = ⊥ := SetLike.ext' (by apply SetLike.ext'_iff.mp <| Submodule.localized₀_bot p f) @[simp] lemma localized₀_top : (⊤ : Submodule R M).localized₀ p f = ⊤ := by rw [← top_le_iff] rintro x _ obtain ⟨⟨x, s⟩, rfl⟩ := IsLocalizedModule.mk'_surjective p f x exact ⟨x, trivial, s, rfl⟩ @[simp] lemma localized'_top : (⊤ : Submodule R M).localized' S p f = ⊤ := SetLike.ext' (by apply SetLike.ext'_iff.mp <| Submodule.localized₀_top p f) @[simp] lemma localized'_span (s : Set M) : (span R s).localized' S p f = span S (f '' s) := by rw [localized'_eq_span, ← map_coe, map_span, span_span_of_tower] lemma localized₀_smul (I : Submodule R R) : (I • M').localized₀ p f = I • M'.localized₀ p f := by apply le_antisymm · rintro _ ⟨a, ha, s, rfl⟩ refine Submodule.smul_induction_on ha ?_ ?_ · intro r hr n hn rw [IsLocalizedModule.mk'_smul] exact Submodule.smul_mem_smul hr ⟨n, hn, s, rfl⟩ · simp +contextual only [IsLocalizedModule.mk'_add, add_mem, implies_true] · refine Submodule.smul_le.mpr ?_ rintro r hr _ ⟨a, ha, s, rfl⟩ rw [← IsLocalizedModule.mk'_smul] exact ⟨_, Submodule.smul_mem_smul hr ha, s, rfl⟩ lemma restrictScalars_localized'_smul (I : Submodule R R) (N' : Submodule S N) : (I.localized' S p (Algebra.linearMap R S) • N').restrictScalars R = I • N'.restrictScalars R := by refine le_antisymm (fun x hx ↦ ?_) (Submodule.smul_le.mpr fun r hr n hn ↦ ?_) · refine smul_induction_on ((Submodule.restrictScalars_mem _ _ _).mp hx) ?_ fun _ _ ↦ add_mem rintro _ ⟨r, hr, s, rfl⟩ n hn rw [← IsLocalization.mk'_eq_mk', IsLocalization.mk'_eq_mul_mk'_one, mul_smul, algebraMap_smul] exact smul_mem_smul hr ((Submodule.restrictScalars_mem _ _ _).mpr <| smul_mem _ _ hn) · rw [← algebraMap_smul S, Submodule.restrictScalars_mem] exact Submodule.smul_mem_smul ⟨_, hr, 1, by simp⟩ hn lemma localized'_smul (I : Submodule R R) : (I • M').localized' S p f = I.localized' S p (Algebra.linearMap R S) • M'.localized' S p f := Submodule.restrictScalars_injective R _ _ <| by simp_rw [restrictScalars_localized'_smul, restrictScalars_localized', localized₀_smul] /-- The localization map of a submodule. -/ @[simps!] def toLocalized₀ : M' →ₗ[R] M'.localized₀ p f := f.restrict fun x hx ↦ ⟨x, hx, 1, by simp⟩ /-- The localization map of a submodule. -/ @[simps!] def toLocalized' : M' →ₗ[R] M'.localized' S p f := toLocalized₀ p f M' /-- The localization map of a submodule. -/ noncomputable abbrev toLocalized : M' →ₗ[R] M'.localized p := M'.toLocalized' (Localization p) p (LocalizedModule.mkLinearMap p M) instance : IsLocalizedModule p (M'.toLocalized₀ p f) where map_units x := by simp_rw [Module.End.isUnit_iff] constructor · exact fun _ _ e ↦ Subtype.ext (IsLocalizedModule.smul_injective f x (congr_arg Subtype.val e)) · rintro ⟨_, m, hm, s, rfl⟩ refine ⟨⟨IsLocalizedModule.mk' f m (s * x), ⟨_, hm, _, rfl⟩⟩, Subtype.ext ?_⟩ rw [Module.algebraMap_end_apply, SetLike.val_smul_of_tower, ← IsLocalizedModule.mk'_smul, ← Submonoid.smul_def, IsLocalizedModule.mk'_cancel_right] surj := by rintro ⟨y, x, hx, s, rfl⟩ exact ⟨⟨⟨x, hx⟩, s⟩, by ext; simp⟩ exists_of_eq e := by simpa [Subtype.ext_iff] using IsLocalizedModule.exists_of_eq (S := p) (f := f) (congr_arg Subtype.val e) instance isLocalizedModule : IsLocalizedModule p (M'.toLocalized' S p f) := inferInstanceAs (IsLocalizedModule p (M'.toLocalized₀ p f)) /-- The canonical isomorphism between the localization of a submodule and its realization as a submodule in the localized module. -/ noncomputable def localizedEquiv : M'.localized p ≃ₗ[Localization p] LocalizedModule p M' := have := IsLocalization.linearMap_compatibleSMul p IsLocalizedModule.linearEquiv p (M'.toLocalized p) (LocalizedModule.mkLinearMap _ _) |>.restrictScalars _ open Pointwise lemma localized₀_le_localized₀_of_smul_le {P Q : Submodule R M} (x : p) (h : x • P ≤ Q) : P.localized₀ p f ≤ Q.localized₀ p f := by rintro - ⟨a, ha, r, rfl⟩ refine ⟨x • a, h ⟨a, ha, rfl⟩, x * r, ?_⟩ simp lemma localized'_le_localized'_of_smul_le {P Q : Submodule R M} (x : p) (h : x • P ≤ Q) : P.localized' S p f ≤ Q.localized' S p f := localized₀_le_localized₀_of_smul_le p f x h end Submodule section Quotient variable {R S M N : Type*} variable (S) [CommRing R] [CommRing S] [AddCommGroup M] [AddCommGroup N] variable [Module R M] [Module R N] [Algebra R S] [Module S N] [IsScalarTower R S N] variable (p : Submonoid R) [IsLocalization p S] (f : M →ₗ[R] N) [IsLocalizedModule p f] variable (M' : Submodule R M) /-- The localization map of a quotient module. -/ def Submodule.toLocalizedQuotient' : M ⧸ M' →ₗ[R] N ⧸ M'.localized' S p f := Submodule.mapQ M' ((M'.localized' S p f).restrictScalars R) f (fun x hx ↦ ⟨x, hx, 1, by simp⟩) /-- The localization map of a quotient module. -/ noncomputable abbrev Submodule.toLocalizedQuotient : M ⧸ M' →ₗ[R] LocalizedModule p M ⧸ M'.localized p := M'.toLocalizedQuotient' (Localization p) p (LocalizedModule.mkLinearMap p M) @[simp] lemma Submodule.toLocalizedQuotient'_mk (x : M) : M'.toLocalizedQuotient' S p f (Submodule.Quotient.mk x) = Submodule.Quotient.mk (f x) := rfl open Submodule Submodule.Quotient IsLocalization in instance IsLocalizedModule.toLocalizedQuotient' (M' : Submodule R M) : IsLocalizedModule p (M'.toLocalizedQuotient' S p f) where map_units x := by refine (Module.End.isUnit_iff _).mpr ⟨fun m n e ↦ ?_, fun m ↦ ⟨(IsLocalization.mk' S 1 x) • m, by rw [Module.algebraMap_end_apply, ← smul_assoc, smul_mk'_one, mk'_self', one_smul]⟩⟩ obtain ⟨⟨m, rfl⟩, n, rfl⟩ := PProd.mk (mk_surjective _ m) (mk_surjective _ n) simp only [Module.algebraMap_end_apply, ← mk_smul, Submodule.Quotient.eq, ← smul_sub] at e replace e := Submodule.smul_mem _ (IsLocalization.mk' S 1 x) e rwa [smul_comm, ← smul_assoc, smul_mk'_one, mk'_self', one_smul, ← Submodule.Quotient.eq] at e surj y := by obtain ⟨y, rfl⟩ := mk_surjective _ y obtain ⟨⟨y, s⟩, rfl⟩ := IsLocalizedModule.mk'_surjective p f y exact ⟨⟨Submodule.Quotient.mk y, s⟩, by simp only [Function.uncurry_apply_pair, toLocalizedQuotient'_mk, ← mk_smul, mk'_cancel']⟩ exists_of_eq {m n} e := by obtain ⟨⟨m, rfl⟩, n, rfl⟩ := PProd.mk (mk_surjective _ m) (mk_surjective _ n) obtain ⟨x, hx, s, hs⟩ : f (m - n) ∈ _ := by simpa [Submodule.Quotient.eq] using e obtain ⟨c, hc⟩ := exists_of_eq (S := p) (show f (s • (m - n)) = f x by simp [-map_sub, ← hs]) exact ⟨c * s, by simpa only [← Quotient.mk_smul, Submodule.Quotient.eq, ← smul_sub, mul_smul, hc] using M'.smul_mem c hx⟩ instance (M' : Submodule R M) : IsLocalizedModule p (M'.toLocalizedQuotient p) := IsLocalizedModule.toLocalizedQuotient' _ _ _ _ /-- The canonical isomorphism between the localization of a quotient module and its realization as a quotient of the localized module. -/ noncomputable def localizedQuotientEquiv : (LocalizedModule p M ⧸ M'.localized p) ≃ₗ[Localization p] LocalizedModule p (M ⧸ M') := have := IsLocalization.linearMap_compatibleSMul p IsLocalizedModule.linearEquiv p (M'.toLocalizedQuotient p) (LocalizedModule.mkLinearMap _ _) |>.restrictScalars _ end Quotient namespace LinearMap variable {P : Type*} [AddCommMonoid P] [Module R P] variable {Q : Type*} [AddCommMonoid Q] [Module R Q] [Module S Q] [IsScalarTower R S Q] variable (f' : P →ₗ[R] Q) [IsLocalizedModule p f'] open Submodule IsLocalizedModule lemma ker_localizedMap_eq_localized₀_ker (g : M →ₗ[R] P) : ker (map p f f' g) = (ker g).localized₀ p f := by ext x simp only [Submodule.mem_localized₀, mem_ker] refine ⟨fun h ↦ ?_, ?_⟩ · obtain ⟨⟨a, b⟩, rfl⟩ := IsLocalizedModule.mk'_surjective p f x simp only [Function.uncurry_apply_pair, map_mk', mk'_eq_zero, eq_zero_iff p f'] at h obtain ⟨c, hc⟩ := h refine ⟨c • a, by simpa, c * b, by simp⟩ · rintro ⟨m, hm, a, ha, rfl⟩ simp [IsLocalizedModule.map_mk', hm] lemma localized'_ker_eq_ker_localizedMap (g : M →ₗ[R] P) : (ker g).localized' S p f = ker ((map p f f' g).extendScalarsOfIsLocalization p S) := SetLike.ext (by apply SetLike.ext_iff.mp (f.ker_localizedMap_eq_localized₀_ker p f' g).symm) lemma ker_localizedMap_eq_localized'_ker (g : M →ₗ[R] P) : ker (map p f f' g) = ((ker g).localized' S p f).restrictScalars _ := by ext simp [localized'_ker_eq_ker_localizedMap S p f f'] /-- The canonical map from the kernel of `g` to the kernel of `g` localized at a submonoid. This is a localization map by `LinearMap.toKerLocalized_isLocalizedModule`. -/ @[simps!] noncomputable def toKerIsLocalized (g : M →ₗ[R] P) : ker g →ₗ[R] ker (map p f f' g) := f.restrict (fun x hx ↦ by simp [mem_ker, mem_ker.mp hx]) include S in /-- The canonical map to the kernel of the localization of `g` is localizing. In other words, localization commutes with kernels. -/ lemma toKerLocalized_isLocalizedModule (g : M →ₗ[R] P) : IsLocalizedModule p (toKerIsLocalized p f f' g) := let e : Submodule.localized' S p f (ker g) ≃ₗ[S] ker ((map p f f' g).extendScalarsOfIsLocalization p S) := LinearEquiv.ofEq _ _ (localized'_ker_eq_ker_localizedMap S p f f' g) IsLocalizedModule.of_linearEquiv p (Submodule.toLocalized' S p f (ker g)) (e.restrictScalars R) lemma range_localizedMap_eq_localized₀_range (g : M →ₗ[R] P) : range (map p f f' g) = (range g).localized₀ p f' := by ext; simp [mem_localized₀, mem_range, (mk'_surjective p f).exists] /-- Localization commutes with ranges. -/ lemma localized'_range_eq_range_localizedMap (g : M →ₗ[R] P) : (range g).localized' S p f' = range ((map p f f' g).extendScalarsOfIsLocalization p S) := SetLike.ext (by apply SetLike.ext_iff.mp (f.range_localizedMap_eq_localized₀_range p f' g).symm) end LinearMap
.lake/packages/mathlib/Mathlib/Algebra/Module/Submodule/RestrictScalars.lean
import Mathlib.Algebra.Module.Submodule.Lattice import Mathlib.Order.Hom.CompleteLattice /-! # Restriction of scalars for submodules If semiring `S` acts on a semiring `R` and `M` is a module over both (compatibly with this action) then we can turn an `R`-submodule into an `S`-submodule by forgetting the action of `R`. We call this restriction of scalars for submodules. ## Main definitions: * `Submodule.restrictScalars`: regard an `R`-submodule as an `S`-submodule if `S` acts on `R` -/ namespace Submodule variable (S : Type*) {R M : Type*} [Semiring R] [AddCommMonoid M] [Semiring S] [Module S M] [Module R M] [SMul S R] [IsScalarTower S R M] /-- `V.restrictScalars S` is the `S`-submodule of the `S`-module given by restriction of scalars, corresponding to `V`, an `R`-submodule of the original `R`-module. -/ def restrictScalars (V : Submodule R M) : Submodule S M where carrier := V zero_mem' := V.zero_mem smul_mem' c _ h := V.smul_of_tower_mem c h add_mem' hx hy := V.add_mem hx hy @[simp] theorem coe_restrictScalars (V : Submodule R M) : (V.restrictScalars S : Set M) = V := rfl @[simp] theorem toAddSubmonoid_restrictScalars (V : Submodule R M) : (V.restrictScalars S).toAddSubmonoid = V.toAddSubmonoid := rfl @[simp] theorem restrictScalars_mem (V : Submodule R M) (m : M) : m ∈ V.restrictScalars S ↔ m ∈ V := Iff.refl _ @[simp] theorem restrictScalars_self (V : Submodule R M) : V.restrictScalars R = V := SetLike.coe_injective rfl variable (R M) theorem restrictScalars_injective : Function.Injective (restrictScalars S : Submodule R M → Submodule S M) := fun _ _ h => ext <| Set.ext_iff.1 (SetLike.ext'_iff.1 h :) @[simp] theorem restrictScalars_inj {V₁ V₂ : Submodule R M} : restrictScalars S V₁ = restrictScalars S V₂ ↔ V₁ = V₂ := (restrictScalars_injective S _ _).eq_iff /-- Even though `p.restrictScalars S` has type `Submodule S M`, it is still an `R`-module. -/ instance restrictScalars.origModule (p : Submodule R M) : Module R (p.restrictScalars S) := (by infer_instance : Module R p) instance restrictScalars.isScalarTower (p : Submodule R M) : IsScalarTower S R (p.restrictScalars S) where smul_assoc r s x := Subtype.ext <| smul_assoc r s (x : M) /-- `restrictScalars S` is an embedding of the lattice of `R`-submodules into the lattice of `S`-submodules. -/ @[simps] def restrictScalarsEmbedding : Submodule R M ↪o Submodule S M where toFun := restrictScalars S inj' := restrictScalars_injective S R M map_rel_iff' := by simp [SetLike.le_def] /-- Turning `p : Submodule R M` into an `S`-submodule gives the same module structure as turning it into a type and adding a module structure. -/ @[simps +simpRhs] def restrictScalarsEquiv (p : Submodule R M) : p.restrictScalars S ≃ₗ[R] p := { AddEquiv.refl p with map_smul' := fun _ _ => rfl } @[simp] theorem restrictScalars_bot : restrictScalars S (⊥ : Submodule R M) = ⊥ := rfl @[simp] theorem restrictScalars_eq_bot_iff {p : Submodule R M} : restrictScalars S p = ⊥ ↔ p = ⊥ := by simp [SetLike.ext_iff] @[simp] theorem restrictScalars_top : restrictScalars S (⊤ : Submodule R M) = ⊤ := rfl @[simp] theorem restrictScalars_eq_top_iff {p : Submodule R M} : restrictScalars S p = ⊤ ↔ p = ⊤ := by simp [SetLike.ext_iff] /-- If ring `S` acts on a ring `R` and `M` is a module over both (compatibly with this action) then we can turn an `R`-submodule into an `S`-submodule by forgetting the action of `R`. -/ def restrictScalarsLatticeHom : CompleteLatticeHom (Submodule R M) (Submodule S M) where toFun := restrictScalars S map_sInf' s := by ext; simp map_sSup' s := by rw [← toAddSubmonoid_inj, toAddSubmonoid_sSup, ← Set.image_comp]; simp @[simp] lemma toIntSubmodule_toAddSubgroup {R M : Type*} [Ring R] [AddCommGroup M] [Module R M] (N : Submodule R M) : N.toAddSubgroup.toIntSubmodule = N.restrictScalars ℤ := rfl end Submodule
.lake/packages/mathlib/Mathlib/Algebra/Module/Submodule/Bilinear.lean
import Mathlib.LinearAlgebra.Span.Basic import Mathlib.LinearAlgebra.BilinearMap /-! # Images of pairs of submodules under bilinear maps This file provides `Submodule.map₂`, which is later used to implement `Submodule.mul`. ## Main results * `Submodule.map₂_eq_span_image2`: the image of two submodules under a bilinear map is the span of their `Set.image2`. ## Notes This file is quite similar to the n-ary section of `Data.Set.Basic` and to `Order.Filter.NAry`. Please keep them in sync. ## TODO Generalize this file to semilinear maps. -/ universe uι u v open Set open Pointwise namespace Submodule variable {ι : Sort uι} {R M N P : Type*} variable [CommSemiring R] [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] variable [Module R M] [Module R N] [Module R P] /-- Map a pair of submodules under a bilinear map. This is the submodule version of `Set.image2`. -/ def map₂ (f : M →ₗ[R] N →ₗ[R] P) (p : Submodule R M) (q : Submodule R N) : Submodule R P := ⨆ s : p, q.map (f s) theorem apply_mem_map₂ (f : M →ₗ[R] N →ₗ[R] P) {m : M} {n : N} {p : Submodule R M} {q : Submodule R N} (hm : m ∈ p) (hn : n ∈ q) : f m n ∈ map₂ f p q := (le_iSup _ ⟨m, hm⟩ : _ ≤ map₂ f p q) ⟨n, hn, by rfl⟩ theorem map₂_le {f : M →ₗ[R] N →ₗ[R] P} {p : Submodule R M} {q : Submodule R N} {r : Submodule R P} : map₂ f p q ≤ r ↔ ∀ m ∈ p, ∀ n ∈ q, f m n ∈ r := ⟨fun H _m hm _n hn => H <| apply_mem_map₂ _ hm hn, fun H => iSup_le fun ⟨m, hm⟩ => map_le_iff_le_comap.2 fun n hn => H m hm n hn⟩ variable (R) in theorem map₂_span_span (f : M →ₗ[R] N →ₗ[R] P) (s : Set M) (t : Set N) : map₂ f (span R s) (span R t) = span R (Set.image2 (fun m n => f m n) s t) := by apply le_antisymm · rw [map₂_le] apply @span_induction R M _ _ _ s on_goal 1 => intro a ha apply @span_induction R N _ _ _ t · intro b hb exact subset_span ⟨_, ‹_›, _, ‹_›, rfl⟩ all_goals intros simp only [*, add_mem, smul_mem, zero_mem, map_zero, map_add, LinearMap.zero_apply, LinearMap.add_apply, LinearMap.smul_apply, map_smul] · rw [span_le, image2_subset_iff] intro a ha b hb exact apply_mem_map₂ _ (subset_span ha) (subset_span hb) @[simp] theorem map₂_bot_right (f : M →ₗ[R] N →ₗ[R] P) (p : Submodule R M) : map₂ f p ⊥ = ⊥ := eq_bot_iff.2 <| map₂_le.2 fun m _hm n hn => by rw [Submodule.mem_bot] at hn rw [hn, LinearMap.map_zero]; simp only [mem_bot] @[simp] theorem map₂_bot_left (f : M →ₗ[R] N →ₗ[R] P) (q : Submodule R N) : map₂ f ⊥ q = ⊥ := eq_bot_iff.2 <| map₂_le.2 fun m hm n _ => by rw [Submodule.mem_bot] at hm ⊢ rw [hm, LinearMap.map_zero₂] @[gcongr, mono] theorem map₂_le_map₂ {f : M →ₗ[R] N →ₗ[R] P} {p₁ p₂ : Submodule R M} {q₁ q₂ : Submodule R N} (hp : p₁ ≤ p₂) (hq : q₁ ≤ q₂) : map₂ f p₁ q₁ ≤ map₂ f p₂ q₂ := map₂_le.2 fun _m hm _n hn => apply_mem_map₂ _ (hp hm) (hq hn) theorem map₂_le_map₂_left {f : M →ₗ[R] N →ₗ[R] P} {p₁ p₂ : Submodule R M} {q : Submodule R N} (h : p₁ ≤ p₂) : map₂ f p₁ q ≤ map₂ f p₂ q := map₂_le_map₂ h (le_refl q) theorem map₂_le_map₂_right {f : M →ₗ[R] N →ₗ[R] P} {p : Submodule R M} {q₁ q₂ : Submodule R N} (h : q₁ ≤ q₂) : map₂ f p q₁ ≤ map₂ f p q₂ := map₂_le_map₂ (le_refl p) h theorem map₂_sup_right (f : M →ₗ[R] N →ₗ[R] P) (p : Submodule R M) (q₁ q₂ : Submodule R N) : map₂ f p (q₁ ⊔ q₂) = map₂ f p q₁ ⊔ map₂ f p q₂ := le_antisymm (map₂_le.2 fun _m hm _np hnp => let ⟨_n, hn, _p, hp, hnp⟩ := mem_sup.1 hnp mem_sup.2 ⟨_, apply_mem_map₂ _ hm hn, _, apply_mem_map₂ _ hm hp, hnp ▸ (map_add _ _ _).symm⟩) (sup_le (map₂_le_map₂_right le_sup_left) (map₂_le_map₂_right le_sup_right)) theorem map₂_sup_left (f : M →ₗ[R] N →ₗ[R] P) (p₁ p₂ : Submodule R M) (q : Submodule R N) : map₂ f (p₁ ⊔ p₂) q = map₂ f p₁ q ⊔ map₂ f p₂ q := le_antisymm (map₂_le.2 fun _mn hmn _p hp => let ⟨_m, hm, _n, hn, hmn⟩ := mem_sup.1 hmn mem_sup.2 ⟨_, apply_mem_map₂ _ hm hp, _, apply_mem_map₂ _ hn hp, hmn ▸ (LinearMap.map_add₂ _ _ _ _).symm⟩) (sup_le (map₂_le_map₂_left le_sup_left) (map₂_le_map₂_left le_sup_right)) theorem image2_subset_map₂ (f : M →ₗ[R] N →ₗ[R] P) (p : Submodule R M) (q : Submodule R N) : Set.image2 (fun m n => f m n) (↑p : Set M) (↑q : Set N) ⊆ (↑(map₂ f p q) : Set P) := by rintro _ ⟨i, hi, j, hj, rfl⟩ exact apply_mem_map₂ _ hi hj theorem map₂_eq_span_image2 (f : M →ₗ[R] N →ₗ[R] P) (p : Submodule R M) (q : Submodule R N) : map₂ f p q = span R (Set.image2 (fun m n => f m n) (p : Set M) (q : Set N)) := by rw [← map₂_span_span, span_eq, span_eq] theorem map₂_flip (f : M →ₗ[R] N →ₗ[R] P) (p : Submodule R M) (q : Submodule R N) : map₂ f.flip q p = map₂ f p q := by rw [map₂_eq_span_image2, map₂_eq_span_image2, Set.image2_swap] rfl theorem map₂_iSup_left (f : M →ₗ[R] N →ₗ[R] P) (s : ι → Submodule R M) (t : Submodule R N) : map₂ f (⨆ i, s i) t = ⨆ i, map₂ f (s i) t := by suffices map₂ f (⨆ i, span R (s i : Set M)) (span R t) = ⨆ i, map₂ f (span R (s i)) (span R t) by simpa only [span_eq] using this simp_rw [map₂_span_span, ← span_iUnion, map₂_span_span, Set.image2_iUnion_left] theorem map₂_iSup_right (f : M →ₗ[R] N →ₗ[R] P) (s : Submodule R M) (t : ι → Submodule R N) : map₂ f s (⨆ i, t i) = ⨆ i, map₂ f s (t i) := by suffices map₂ f (span R s) (⨆ i, span R (t i : Set N)) = ⨆ i, map₂ f (span R s) (span R (t i)) by simpa only [span_eq] using this simp_rw [map₂_span_span, ← span_iUnion, map₂_span_span, Set.image2_iUnion_right] theorem map₂_span_singleton_eq_map (f : M →ₗ[R] N →ₗ[R] P) (m : M) : map₂ f (span R {m}) = map (f m) := by funext s rw [← span_eq s, map₂_span_span, image2_singleton_left, map_span] theorem map₂_span_singleton_eq_map_flip (f : M →ₗ[R] N →ₗ[R] P) (s : Submodule R M) (n : N) : map₂ f s (span R {n}) = map (f.flip n) s := by rw [← map₂_span_singleton_eq_map, map₂_flip] section comp variable {M₂ N₂ P₂ : Type*} variable [AddCommMonoid M₂] [AddCommMonoid N₂] [AddCommMonoid P₂] variable [Module R M₂] [Module R N₂] [Module R P₂] theorem map_map₂ (f : P →ₗ[R] P₂) (g : M →ₗ[R] N →ₗ[R] P) (p : Submodule R M) (q : Submodule R N) : map f (map₂ g p q) = map₂ (g.compr₂ f) p q := map_iSup _ _ |>.trans <| iSup_congr fun _ => map_comp _ _ _ |>.symm theorem map₂_map_right (f : M →ₗ[R] N₂ →ₗ[R] P) (g : N →ₗ[R] N₂) (p : Submodule R M) (q : Submodule R N) : map₂ f p (map g q) = map₂ (f.compl₂ g) p q := iSup_congr fun _ => map_comp _ _ _ |>.symm theorem map₂_map_left (f : M₂ →ₗ[R] N →ₗ[R] P) (g : M →ₗ[R] M₂) (p : Submodule R M) (q : Submodule R N) : map₂ f (map g p) q = map₂ (f ∘ₗ g) p q := by rw [← map₂_flip, map₂_map_right, ← map₂_flip] rfl theorem map₂_map_map (f : M₂ →ₗ[R] N₂ →ₗ[R] P) (g : M →ₗ[R] M₂) (h : N →ₗ[R] N₂) (p : Submodule R M) (q : Submodule R N) : map₂ f (map g p) (map h q) = map₂ (f.compl₁₂ g h) p q := by rw [map₂_map_right, map₂_map_left] rfl end comp end Submodule
.lake/packages/mathlib/Mathlib/Algebra/Module/Submodule/Invariant.lean
import Mathlib.Algebra.Module.Equiv.Basic import Mathlib.Algebra.Module.Submodule.Map import Mathlib.LinearAlgebra.Span.Defs import Mathlib.Order.Sublattice /-! # The lattice of invariant submodules In this file we defined the type `Module.End.invtSubmodule`, associated to a linear endomorphism of a module. Its utility stems primarily from those occasions on which we wish to take advantage of the lattice structure of invariant submodules. See also `Mathlib/Algebra/Polynomial/Module/AEval.lean`. -/ open Submodule (span) namespace Module.End variable {R M : Type*} [Semiring R] [AddCommMonoid M] [Module R M] (f : End R M) /-- Given an endomorphism, `f` of some module, this is the sublattice of all `f`-invariant submodules. -/ def invtSubmodule : Sublattice (Submodule R M) where carrier := {p : Submodule R M | p ≤ p.comap f} supClosed' p hp q hq := sup_le_iff.mpr ⟨le_trans hp <| Submodule.comap_mono le_sup_left, le_trans hq <| Submodule.comap_mono le_sup_right⟩ infClosed' p hp q hq := by simp only [Set.mem_setOf_eq, Submodule.comap_inf, le_inf_iff] exact ⟨inf_le_of_left_le hp, inf_le_of_right_le hq⟩ lemma mem_invtSubmodule {p : Submodule R M} : p ∈ f.invtSubmodule ↔ p ≤ p.comap f := Iff.rfl /-- `p` is `f` invariant if and only if `p.map f ≤ p`. -/ theorem mem_invtSubmodule_iff_map_le {p : Submodule R M} : p ∈ f.invtSubmodule ↔ p.map f ≤ p := Submodule.map_le_iff_le_comap.symm /-- `p` is `f` invariant if and only if `Set.MapsTo f p p`. -/ theorem mem_invtSubmodule_iff_mapsTo {p : Submodule R M} : p ∈ f.invtSubmodule ↔ Set.MapsTo f p p := Iff.rfl alias ⟨_, _root_.Set.Mapsto.mem_invtSubmodule⟩ := mem_invtSubmodule_iff_mapsTo theorem mem_invtSubmodule_iff_forall_mem_of_mem {p : Submodule R M} : p ∈ f.invtSubmodule ↔ ∀ x ∈ p, f x ∈ p := Iff.rfl /-- `p` is `f.symm` invariant if and only if `p ≤ p.map f`. -/ lemma mem_invtSubmodule_symm_iff_le_map {f : M ≃ₗ[R] M} {p : Submodule R M} : p ∈ invtSubmodule f.symm ↔ p ≤ p.map f := (mem_invtSubmodule_iff_map_le _).trans (f.toEquiv.symm.subset_symm_image _ _).symm namespace invtSubmodule variable {f} lemma inf_mem {p q : Submodule R M} (hp : p ∈ f.invtSubmodule) (hq : q ∈ f.invtSubmodule) : p ⊓ q ∈ f.invtSubmodule := Sublattice.inf_mem hp hq lemma sup_mem {p q : Submodule R M} (hp : p ∈ f.invtSubmodule) (hq : q ∈ f.invtSubmodule) : p ⊔ q ∈ f.invtSubmodule := Sublattice.sup_mem hp hq variable (f) @[simp] protected lemma top_mem : ⊤ ∈ f.invtSubmodule := by simp [invtSubmodule] @[simp] protected lemma bot_mem : ⊥ ∈ f.invtSubmodule := by simp [invtSubmodule] instance : BoundedOrder (f.invtSubmodule) where top := ⟨⊤, invtSubmodule.top_mem f⟩ bot := ⟨⊥, invtSubmodule.bot_mem f⟩ le_top := fun ⟨p, hp⟩ ↦ by simp bot_le := fun ⟨p, hp⟩ ↦ by simp @[simp] protected lemma zero : (0 : End R M).invtSubmodule = ⊤ := eq_top_iff.mpr fun x ↦ by simp [invtSubmodule] @[simp] protected lemma id : invtSubmodule (LinearMap.id : End R M) = ⊤ := eq_top_iff.mpr fun x ↦ by simp [invtSubmodule] @[simp] protected lemma one : invtSubmodule (1 : End R M) = ⊤ := invtSubmodule.id protected lemma mk_eq_bot_iff {p : Submodule R M} (hp : p ∈ f.invtSubmodule) : (⟨p, hp⟩ : f.invtSubmodule) = ⊥ ↔ p = ⊥ := Subtype.mk_eq_bot_iff (by simp [invtSubmodule]) _ protected lemma mk_eq_top_iff {p : Submodule R M} (hp : p ∈ f.invtSubmodule) : (⟨p, hp⟩ : f.invtSubmodule) = ⊤ ↔ p = ⊤ := Subtype.mk_eq_top_iff (by simp [invtSubmodule]) _ @[simp] protected lemma disjoint_mk_iff {p q : Submodule R M} (hp : p ∈ f.invtSubmodule) (hq : q ∈ f.invtSubmodule) : Disjoint (α := f.invtSubmodule) ⟨p, hp⟩ ⟨q, hq⟩ ↔ Disjoint p q := by rw [disjoint_iff, disjoint_iff, Sublattice.mk_inf_mk, Subtype.mk_eq_bot_iff (⊥ : f.invtSubmodule).property] protected lemma disjoint_iff {p q : f.invtSubmodule} : Disjoint p q ↔ Disjoint (p : Submodule R M) (q : Submodule R M) := by obtain ⟨p, hp⟩ := p obtain ⟨q, hq⟩ := q simp @[simp] protected lemma codisjoint_mk_iff {p q : Submodule R M} (hp : p ∈ f.invtSubmodule) (hq : q ∈ f.invtSubmodule) : Codisjoint (α := f.invtSubmodule) ⟨p, hp⟩ ⟨q, hq⟩ ↔ Codisjoint p q := by rw [codisjoint_iff, codisjoint_iff, Sublattice.mk_sup_mk, Subtype.mk_eq_top_iff (⊤ : f.invtSubmodule).property] protected lemma codisjoint_iff {p q : f.invtSubmodule} : Codisjoint p q ↔ Codisjoint (p : Submodule R M) (q : Submodule R M) := by obtain ⟨p, hp⟩ := p obtain ⟨q, hq⟩ := q simp @[simp] protected lemma isCompl_mk_iff {p q : Submodule R M} (hp : p ∈ f.invtSubmodule) (hq : q ∈ f.invtSubmodule) : IsCompl (α := f.invtSubmodule) ⟨p, hp⟩ ⟨q, hq⟩ ↔ IsCompl p q := by simp [isCompl_iff] protected lemma isCompl_iff {p q : f.invtSubmodule} : IsCompl p q ↔ IsCompl (p : Submodule R M) (q : Submodule R M) := by obtain ⟨p, hp⟩ := p obtain ⟨q, hq⟩ := q simp lemma map_subtype_mem_of_mem_invtSubmodule {p : Submodule R M} (hp : p ∈ f.invtSubmodule) {q : Submodule R p} (hq : q ∈ invtSubmodule (LinearMap.restrict f hp)) : Submodule.map p.subtype q ∈ f.invtSubmodule := by rintro - ⟨⟨x, hx⟩, hx', rfl⟩ specialize hq hx' rw [Submodule.mem_comap, LinearMap.restrict_apply] at hq simpa [hq] using hp hx protected lemma comp {p : Submodule R M} {g : End R M} (hf : p ∈ f.invtSubmodule) (hg : p ∈ g.invtSubmodule) : p ∈ invtSubmodule (f ∘ₗ g) := fun _ hx ↦ hf (hg hx) @[simp] lemma _root_.LinearEquiv.map_mem_invtSubmodule_conj_iff {R M N : Type*} [CommSemiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N] {f : End R M} {e : M ≃ₗ[R] N} {p : Submodule R M} : p.map e ∈ (e.conj f).invtSubmodule ↔ p ∈ f.invtSubmodule := by change p.map e.toLinearMap ∈ _ ↔ _ have : e.symm.toLinearMap ∘ₗ ((e ∘ₗ f) ∘ₗ e.symm.toLinearMap) ∘ₗ e = f := by ext; simp rw [LinearEquiv.conj_apply, mem_invtSubmodule, mem_invtSubmodule, Submodule.map_le_iff_le_comap, Submodule.map_equiv_eq_comap_symm, ← Submodule.comap_comp, ← Submodule.comap_comp, this] lemma _root_.LinearEquiv.map_mem_invtSubmodule_iff {R M N : Type*} [CommSemiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N] {f : End R N} {e : M ≃ₗ[R] N} {p : Submodule R M} : p.map e ∈ f.invtSubmodule ↔ p ∈ (e.symm.conj f).invtSubmodule := by simp [← e.map_mem_invtSubmodule_conj_iff] end invtSubmodule variable (R) in lemma span_orbit_mem_invtSubmodule {G : Type*} [Monoid G] [DistribMulAction G M] [SMulCommClass G R M] (x : M) (g : G) : span R (MulAction.orbit G x) ∈ invtSubmodule (DistribMulAction.toLinearMap R M g) := by rw [mem_invtSubmodule, Submodule.span_le, Submodule.comap_coe] intro y hy simp only [Set.mem_preimage, DistribMulAction.toLinearMap_apply, SetLike.mem_coe] exact Submodule.subset_span <| MulAction.mem_orbit_of_mem_orbit g hy end Module.End
.lake/packages/mathlib/Mathlib/Algebra/Module/Submodule/Pointwise.lean
import Mathlib.Algebra.GroupWithZero.Subgroup import Mathlib.Algebra.Order.Group.Action import Mathlib.LinearAlgebra.Finsupp.Supported import Mathlib.LinearAlgebra.Span.Basic /-! # Pointwise instances on `Submodule`s This file provides: * `Submodule.pointwiseNeg` and the actions * `Submodule.pointwiseDistribMulAction` * `Submodule.pointwiseMulActionWithZero` which matches the action of `Set.mulActionSet`. This file also provides: * `Submodule.pointwiseSetSMulSubmodule`: for `R`-module `M`, a `s : Set R` can act on `N : Submodule R M` by defining `s • N` to be the smallest submodule containing all `a • n` where `a ∈ s` and `n ∈ N`. These actions are available in the `Pointwise` locale. ## Implementation notes For an `R`-module `M`, the action of a subset of `R` acting on a submodule of `M` introduced in section `set_acting_on_submodules` does not have a counterpart in the files `Mathlib/Algebra/Group/Submonoid/Pointwise.lean` and `Mathlib/Algebra/GroupWithZero/Submonoid/Pointwise.lean`. Other than section `set_acting_on_submodules`, most of the lemmas in this file are direct copies of lemmas from the file `Mathlib/Algebra/Group/Submonoid/Pointwise.lean`. -/ assert_not_exists Ideal variable {α : Type*} {R : Type*} {M : Type*} open Pointwise namespace Submodule section Neg section Semiring variable [Semiring R] [AddCommGroup M] [Module R M] /-- The submodule with every element negated. Note if `R` is a ring and not just a semiring, this is a no-op, as shown by `Submodule.neg_eq_self`. Recall that When `R` is the semiring corresponding to the nonnegative elements of `R'`, `Submodule R' M` is the type of cones of `M`. This instance reflects such cones about `0`. This is available as an instance in the `Pointwise` locale. -/ protected def pointwiseNeg : Neg (Submodule R M) where neg p := { -p.toAddSubmonoid with smul_mem' := fun r m hm => Set.mem_neg.2 <| smul_neg r m ▸ p.smul_mem r <| Set.mem_neg.1 hm } scoped[Pointwise] attribute [instance] Submodule.pointwiseNeg open Pointwise @[simp] theorem coe_set_neg (S : Submodule R M) : ↑(-S) = -(S : Set M) := rfl @[simp] theorem neg_toAddSubmonoid (S : Submodule R M) : (-S).toAddSubmonoid = -S.toAddSubmonoid := rfl @[simp] theorem mem_neg {g : M} {S : Submodule R M} : g ∈ -S ↔ -g ∈ S := Iff.rfl /-- `Submodule.pointwiseNeg` is involutive. This is available as an instance in the `Pointwise` locale. -/ protected def involutivePointwiseNeg : InvolutiveNeg (Submodule R M) where neg_neg _S := SetLike.coe_injective <| neg_neg _ scoped[Pointwise] attribute [instance] Submodule.involutivePointwiseNeg @[simp] theorem neg_le_neg (S T : Submodule R M) : -S ≤ -T ↔ S ≤ T := SetLike.coe_subset_coe.symm.trans Set.neg_subset_neg theorem neg_le (S T : Submodule R M) : -S ≤ T ↔ S ≤ -T := SetLike.coe_subset_coe.symm.trans Set.neg_subset /-- `Submodule.pointwiseNeg` as an order isomorphism. -/ def negOrderIso : Submodule R M ≃o Submodule R M where toEquiv := Equiv.neg _ map_rel_iff' := @neg_le_neg _ _ _ _ _ theorem span_neg_eq_neg (s : Set M) : span R (-s) = -span R s := by apply le_antisymm · rw [span_le, coe_set_neg, ← Set.neg_subset, neg_neg] exact subset_span · rw [neg_le, span_le, coe_set_neg, ← Set.neg_subset] exact subset_span @[simp] theorem neg_inf (S T : Submodule R M) : -(S ⊓ T) = -S ⊓ -T := rfl @[simp] theorem neg_sup (S T : Submodule R M) : -(S ⊔ T) = -S ⊔ -T := (negOrderIso : Submodule R M ≃o Submodule R M).map_sup S T @[simp] theorem neg_bot : -(⊥ : Submodule R M) = ⊥ := SetLike.coe_injective <| (Set.neg_singleton 0).trans <| congr_arg _ neg_zero @[simp] theorem neg_top : -(⊤ : Submodule R M) = ⊤ := SetLike.coe_injective <| Set.neg_univ @[simp] theorem neg_iInf {ι : Sort*} (S : ι → Submodule R M) : (-⨅ i, S i) = ⨅ i, -S i := (negOrderIso : Submodule R M ≃o Submodule R M).map_iInf _ @[simp] theorem neg_iSup {ι : Sort*} (S : ι → Submodule R M) : (-⨆ i, S i) = ⨆ i, -S i := (negOrderIso : Submodule R M ≃o Submodule R M).map_iSup _ end Semiring open Pointwise @[simp] theorem neg_eq_self [Ring R] [AddCommGroup M] [Module R M] (p : Submodule R M) : -p = p := ext fun _ => p.neg_mem_iff end Neg variable [Semiring R] [AddCommMonoid M] [Module R M] instance pointwiseZero : Zero (Submodule R M) where zero := ⊥ instance pointwiseAdd : Add (Submodule R M) where add := (· ⊔ ·) instance pointwiseAddCommMonoid : AddCommMonoid (Submodule R M) where add_assoc := sup_assoc zero_add := bot_sup_eq add_zero := sup_bot_eq add_comm := sup_comm nsmul := nsmulRec @[simp] theorem add_eq_sup (p q : Submodule R M) : p + q = p ⊔ q := rfl @[simp] theorem zero_eq_bot : (0 : Submodule R M) = ⊥ := rfl instance : IsOrderedAddMonoid (Submodule R M) := { add_le_add_left := fun _a _b => sup_le_sup_left } instance : CanonicallyOrderedAdd (Submodule R M) where exists_add_of_le {_a b} h := ⟨b, (sup_eq_right.2 h).symm⟩ le_add_self _ _ := le_sup_right le_self_add := fun _a _b => le_sup_left section variable [Monoid α] [DistribMulAction α M] [SMulCommClass α R M] /-- The action on a submodule corresponding to applying the action to every element. This is available as an instance in the `Pointwise` locale. -/ protected def pointwiseDistribMulAction : DistribMulAction α (Submodule R M) where smul a S := S.map (DistribMulAction.toLinearMap R M a : M →ₗ[R] M) one_smul S := (congr_arg (fun f : Module.End R M => S.map f) (LinearMap.ext <| one_smul α)).trans S.map_id mul_smul _a₁ _a₂ S := (congr_arg (fun f : Module.End R M => S.map f) (LinearMap.ext <| mul_smul _ _)).trans (S.map_comp _ _) smul_zero _a := map_bot _ smul_add _a _S₁ _S₂ := map_sup _ _ _ scoped[Pointwise] attribute [instance] Submodule.pointwiseDistribMulAction open Pointwise @[simp, norm_cast] theorem coe_pointwise_smul (a : α) (S : Submodule R M) : ↑(a • S) = a • (S : Set M) := rfl @[simp] theorem pointwise_smul_toAddSubmonoid (a : α) (S : Submodule R M) : (a • S).toAddSubmonoid = a • S.toAddSubmonoid := rfl @[simp] theorem pointwise_smul_toAddSubgroup {R M : Type*} [Ring R] [AddCommGroup M] [DistribMulAction α M] [Module R M] [SMulCommClass α R M] (a : α) (S : Submodule R M) : (a • S).toAddSubgroup = a • S.toAddSubgroup := rfl theorem mem_smul_pointwise_iff_exists (m : M) (a : α) (S : Submodule R M) : m ∈ a • S ↔ ∃ b ∈ S, a • b = m := Set.mem_smul_set theorem smul_mem_pointwise_smul (m : M) (a : α) (S : Submodule R M) : m ∈ S → a • m ∈ a • S := (Set.smul_mem_smul_set : _ → _ ∈ a • (S : Set M)) instance : CovariantClass α (Submodule R M) HSMul.hSMul LE.le := ⟨fun _ _ => map_mono⟩ /-- See also `Submodule.smul_bot`. -/ @[simp] theorem smul_bot' (a : α) : a • (⊥ : Submodule R M) = ⊥ := map_bot _ /-- See also `Submodule.smul_sup`. -/ theorem smul_sup' (a : α) (S T : Submodule R M) : a • (S ⊔ T) = a • S ⊔ a • T := map_sup _ _ _ theorem smul_span (a : α) (s : Set M) : a • span R s = span R (a • s) := map_span _ _ lemma smul_def (a : α) (S : Submodule R M) : a • S = span R (a • S : Set M) := by simp [← smul_span] theorem span_smul (a : α) (s : Set M) : span R (a • s) = a • span R s := Eq.symm (span_image _).symm instance pointwiseCentralScalar [DistribMulAction αᵐᵒᵖ M] [SMulCommClass αᵐᵒᵖ R M] [IsCentralScalar α M] : IsCentralScalar α (Submodule R M) := ⟨fun _a S => (congr_arg fun f : Module.End R M => S.map f) <| LinearMap.ext <| op_smul_eq_smul _⟩ @[simp] theorem smul_le_self_of_tower {α : Type*} [Monoid α] [SMul α R] [DistribMulAction α M] [SMulCommClass α R M] [IsScalarTower α R M] (a : α) (S : Submodule R M) : a • S ≤ S := by rintro y ⟨x, hx, rfl⟩ exact smul_of_tower_mem _ a hx end section variable [Semiring α] [Module α M] [SMulCommClass α R M] /-- The action on a submodule corresponding to applying the action to every element. This is available as an instance in the `Pointwise` locale. This is a stronger version of `Submodule.pointwiseDistribMulAction`. Note that `add_smul` does not hold so this cannot be stated as a `Module`. -/ protected def pointwiseMulActionWithZero : MulActionWithZero α (Submodule R M) := { Submodule.pointwiseDistribMulAction with zero_smul := fun S => (congr_arg (fun f : M →ₗ[R] M => S.map f) (LinearMap.ext <| zero_smul α)).trans S.map_zero } scoped[Pointwise] attribute [instance] Submodule.pointwiseMulActionWithZero end /-! ### Sets acting on Submodules Let `R` be a (semi)ring and `M` an `R`-module. Let `S` be a monoid which acts on `M` distributively, then subsets of `S` can act on submodules of `M`. For subset `s ⊆ S` and submodule `N ≤ M`, we define `s • N` to be the smallest submodule containing all `r • n` where `r ∈ s` and `n ∈ N`. #### Results For arbitrary monoids `S` acting distributively on `M`, there is an induction principle for `s • N`: To prove `P` holds for all `s • N`, it is enough to prove: - for all `r ∈ s` and `n ∈ N`, `P (r • n)`; - for all `r` and `m ∈ s • N`, `P (r • n)`; - for all `m₁, m₂`, `P m₁` and `P m₂` implies `P (m₁ + m₂)`; - `P 0`. To invoke this induction principle, use `induction x, hx using Submodule.set_smul_inductionOn` where `x : M` and `hx : x ∈ s • N` When we consider subset of `R` acting on `M` - `Submodule.pointwiseSetDistribMulAction` : the action described above is distributive. - `Submodule.mem_set_smul` : `x ∈ s • N` iff `x` can be written as `r₀ n₀ + ... + rₖ nₖ` where `rᵢ ∈ s` and `nᵢ ∈ N`. - `Submodule.coe_span_smul`: `s • N` is the same as `⟨s⟩ • N` where `⟨s⟩` is the ideal spanned by `s`. #### Notes - If we assume the addition on subsets of `R` is the `⊔` and subtraction `⊓` i.e. use `SetSemiring`, then this action actually gives a module structure on submodules of `M` over subsets of `R`. - If we generalize so that `r • N` makes sense for all `r : S`, then `Submodule.singleton_set_smul` and `Submodule.singleton_set_smul` can be generalized as well. -/ section set_acting_on_submodules variable {S : Type*} [Monoid S] variable [DistribMulAction S M] /-- Let `s ⊆ R` be a set and `N ≤ M` be a submodule, then `s • N` is the smallest submodule containing all `r • n` where `r ∈ s` and `n ∈ N`. -/ protected def pointwiseSetSMul : SMul (Set S) (Submodule R M) where smul s N := sInf { p | ∀ ⦃r : S⦄ ⦃n : M⦄, r ∈ s → n ∈ N → r • n ∈ p } scoped[Pointwise] attribute [instance] Submodule.pointwiseSetSMul variable (sR : Set R) (s : Set S) (N : Submodule R M) lemma mem_set_smul_def (x : M) : x ∈ s • N ↔ x ∈ sInf { p : Submodule R M | ∀ ⦃r : S⦄ {n : M}, r ∈ s → n ∈ N → r • n ∈ p } := Iff.rfl variable {s N} in @[aesop safe] lemma mem_set_smul_of_mem_mem {r : S} {m : M} (mem1 : r ∈ s) (mem2 : m ∈ N) : r • m ∈ s • N := by rw [mem_set_smul_def, mem_sInf] exact fun _ h => h mem1 mem2 lemma set_smul_le (p : Submodule R M) (closed_under_smul : ∀ ⦃r : S⦄ ⦃n : M⦄, r ∈ s → n ∈ N → r • n ∈ p) : s • N ≤ p := sInf_le closed_under_smul lemma set_smul_le_iff (p : Submodule R M) : s • N ≤ p ↔ ∀ ⦃r : S⦄ ⦃n : M⦄, r ∈ s → n ∈ N → r • n ∈ p := by fconstructor · intro h r n hr hn exact h <| mem_set_smul_of_mem_mem hr hn · apply set_smul_le lemma set_smul_eq_of_le (p : Submodule R M) (closed_under_smul : ∀ ⦃r : S⦄ ⦃n : M⦄, r ∈ s → n ∈ N → r • n ∈ p) (le : p ≤ s • N) : s • N = p := le_antisymm (set_smul_le s N p closed_under_smul) le instance : CovariantClass (Set S) (Submodule R M) HSMul.hSMul LE.le := ⟨fun _ _ _ le => set_smul_le _ _ _ fun _ _ hr hm => mem_set_smul_of_mem_mem (mem1 := hr) (mem2 := le hm)⟩ lemma set_smul_mono_left {s t : Set S} (le : s ≤ t) : s • N ≤ t • N := set_smul_le _ _ _ fun _ _ hr hm => mem_set_smul_of_mem_mem (mem1 := le hr) (mem2 := hm) lemma set_smul_le_of_le_le {s t : Set S} {p q : Submodule R M} (le_set : s ≤ t) (le_submodule : p ≤ q) : s • p ≤ t • q := le_trans (set_smul_mono_left _ le_set) <| smul_mono_right _ le_submodule lemma set_smul_eq_iSup [SMulCommClass S R M] (s : Set S) (N : Submodule R M) : s • N = ⨆ (a ∈ s), a • N := by refine Eq.trans (congrArg sInf ?_) csInf_Ici simp_rw [← Set.Ici_def, iSup_le_iff, @forall_comm M] exact Set.ext fun _ => forall₂_congr (fun _ _ => Iff.symm map_le_iff_le_comap) theorem set_smul_span [SMulCommClass S R M] (s : Set S) (t : Set M) : s • span R t = span R (s • t) := by simp_rw [set_smul_eq_iSup, smul_span, iSup_span, Set.iUnion_smul_set] theorem span_set_smul [SMulCommClass S R M] (s : Set S) (t : Set M) : span R (s • t) = s • span R t := (set_smul_span s t).symm variable {s N} in /-- Induction principle for set acting on submodules. To prove `P` holds for all `s • N`, it is enough to prove: - for all `r ∈ s` and `n ∈ N`, `P (r • n)`; - for all `r` and `m ∈ s • N`, `P (r • n)`; - for all `m₁, m₂`, `P m₁` and `P m₂` implies `P (m₁ + m₂)`; - `P 0`. To invoke this induction principle, use `induction x, hx using Submodule.set_smul_inductionOn` where `x : M` and `hx : x ∈ s • N` -/ @[elab_as_elim] lemma set_smul_inductionOn {motive : (x : M) → (_ : x ∈ s • N) → Prop} (x : M) (hx : x ∈ s • N) (smul₀ : ∀ ⦃r : S⦄ ⦃n : M⦄ (mem₁ : r ∈ s) (mem₂ : n ∈ N), motive (r • n) (mem_set_smul_of_mem_mem mem₁ mem₂)) (smul₁ : ∀ (r : R) ⦃m : M⦄ (mem : m ∈ s • N), motive m mem → motive (r • m) (Submodule.smul_mem _ r mem)) -- (add : ∀ ⦃m₁ m₂ : M⦄ (mem₁ : m₁ ∈ s • N) (mem₂ : m₂ ∈ s • N), motive m₁ mem₁ → motive m₂ mem₂ → motive (m₁ + m₂) (Submodule.add_mem _ mem₁ mem₂)) (zero : motive 0 (Submodule.zero_mem _)) : motive x hx := let ⟨_, h⟩ := set_smul_le s N { carrier := { m | ∃ (mem : m ∈ s • N), motive m mem }, zero_mem' := ⟨Submodule.zero_mem _, zero⟩ add_mem' := fun ⟨mem, h⟩ ⟨mem', h'⟩ ↦ ⟨_, add mem mem' h h'⟩ smul_mem' := fun r _ ⟨mem, h⟩ ↦ ⟨_, smul₁ r mem h⟩ } (fun _ _ mem mem' ↦ ⟨mem_set_smul_of_mem_mem mem mem', smul₀ mem mem'⟩) hx h -- Implementation note: if `N` is both an `R`-submodule and `S`-submodule and `SMulCommClass R S M`, -- this lemma is also true for any `s : Set S`. lemma set_smul_eq_map [SMulCommClass R R N] : sR • N = Submodule.map (N.subtype.comp (Finsupp.lsum R <| DistribMulAction.toLinearMap _ _)) (Finsupp.supported N R sR) := by classical apply set_smul_eq_of_le · intro r n hr hn exact ⟨Finsupp.single r ⟨n, hn⟩, Finsupp.single_mem_supported _ _ hr, by simp⟩ · intro x hx obtain ⟨c, hc, rfl⟩ := hx simp only [LinearMap.coe_comp, coe_subtype, Finsupp.coe_lsum, Finsupp.sum, Function.comp_apply] rw [AddSubmonoid.coe_finset_sum] refine Submodule.sum_mem (p := sR • N) (t := c.support) ?_ _ ⟨sR • N, ?_⟩ · rintro r hr rw [mem_set_smul_def, Submodule.mem_sInf] rintro p hp exact hp (hc hr) (c r).2 · ext x : 1 simp only [Set.mem_iInter, SetLike.mem_coe] fconstructor · refine fun h ↦ h fun r n hr hn ↦ ?_ rw [mem_set_smul_def, mem_sInf] exact fun p hp ↦ hp hr hn · simp_all lemma mem_set_smul (x : M) [SMulCommClass R R N] : x ∈ sR • N ↔ ∃ (c : R →₀ N), (c.support : Set R) ⊆ sR ∧ x = c.sum fun r m ↦ r • m := by fconstructor · intro h rw [set_smul_eq_map] at h obtain ⟨c, hc, rfl⟩ := h exact ⟨c, hc, rfl⟩ · rw [mem_set_smul_def, Submodule.mem_sInf] rintro ⟨c, hc1, rfl⟩ p hp rw [Finsupp.sum, AddSubmonoid.coe_finset_sum] exact Submodule.sum_mem _ fun r hr ↦ hp (hc1 hr) (c _).2 @[simp] lemma empty_set_smul : (∅ : Set S) • N = ⊥ := by ext fconstructor · intro hx rw [mem_set_smul_def, Submodule.mem_sInf] at hx exact hx ⊥ (fun r _ hr ↦ hr.elim) · rintro rfl; exact Submodule.zero_mem _ @[simp] lemma set_smul_bot : s • (⊥ : Submodule R M) = ⊥ := eq_bot_iff.mpr fun x hx ↦ by induction x, hx using set_smul_inductionOn <;> aesop lemma singleton_set_smul [SMulCommClass S R M] (r : S) : ({r} : Set S) • N = r • N := by apply set_smul_eq_of_le · rintro _ m rfl hm; exact ⟨m, hm, rfl⟩ · rintro _ ⟨m, hm, rfl⟩ rw [mem_set_smul_def, Submodule.mem_sInf] intro _ hp; exact hp rfl hm lemma mem_singleton_set_smul [SMulCommClass R S M] (r : S) (x : M) : x ∈ ({r} : Set S) • N ↔ ∃ (m : M), m ∈ N ∧ x = r • m := by fconstructor · intro hx induction x, hx using Submodule.set_smul_inductionOn with | smul₀ => aesop | @smul₁ t n mem h => rcases h with ⟨n, hn, rfl⟩ exact ⟨t • n, by aesop, smul_comm _ _ _⟩ | add mem₁ mem₂ h₁ h₂ => rcases h₁ with ⟨m₁, h₁, rfl⟩ rcases h₂ with ⟨m₂, h₂, rfl⟩ exact ⟨m₁ + m₂, Submodule.add_mem _ h₁ h₂, by simp⟩ | zero => exact ⟨0, Submodule.zero_mem _, by simp⟩ · aesop lemma smul_inductionOn_pointwise [SMulCommClass S R M] {a : S} {p : (x : M) → x ∈ a • N → Prop} (smul₀ : ∀ (s : M) (hs : s ∈ N), p (a • s) (Submodule.smul_mem_pointwise_smul _ _ _ hs)) (smul₁ : ∀ (r : R) (m : M) (mem : m ∈ a • N), p m mem → p (r • m) (Submodule.smul_mem _ _ mem)) (add : ∀ (x y : M) (hx : x ∈ a • N) (hy : y ∈ a • N), p x hx → p y hy → p (x + y) (Submodule.add_mem _ hx hy)) (zero : p 0 (Submodule.zero_mem _)) {x : M} (hx : x ∈ a • N) : p x hx := by simp_all only [← Submodule.singleton_set_smul] let p' (x : M) (hx : x ∈ ({a} : Set S) • N) : Prop := p x (by rwa [← Submodule.singleton_set_smul]) refine Submodule.set_smul_inductionOn (motive := p') _ (N.singleton_set_smul a ▸ hx) (fun r n hr hn ↦ ?_) smul₁ add zero · simp only [Set.mem_singleton_iff] at hr subst hr exact smul₀ n hn -- Note that this can't be generalized to `Set S`, because even though `SMulCommClass R R M` implies -- `SMulComm R R N` for all `R`-submodules `N`, `SMulCommClass R S N` for all `R`-submodules `N` -- does not make sense. If we just focus on `R`-submodules that are also `S`-submodule, then this -- should be true. /-- A subset of a ring `R` has a multiplicative action on submodules of a module over `R`. -/ protected noncomputable def pointwiseSetMulAction [SMulCommClass R R M] : MulAction (Set R) (Submodule R M) where one_smul x := show {(1 : R)} • x = x from SetLike.ext fun m => (mem_singleton_set_smul _ _ _).trans ⟨by rintro ⟨_, h, rfl⟩; rwa [one_smul], fun h => ⟨m, h, (one_smul _ _).symm⟩⟩ mul_smul s t x := le_antisymm (set_smul_le _ _ _ <| by rintro _ _ ⟨_, _, _, _, rfl⟩ _; rw [mul_smul]; aesop) (set_smul_le _ _ _ fun r m hr hm ↦ by have : SMulCommClass R R x := ⟨fun r s m => Subtype.ext <| smul_comm _ _ _⟩ obtain ⟨c, hc1, rfl⟩ := mem_set_smul _ _ _ |>.mp hm rw [Finsupp.sum, AddSubmonoid.coe_finset_sum] simp only [SetLike.val_smul, Finset.smul_sum, smul_smul] exact Submodule.sum_mem _ fun r' hr' ↦ mem_set_smul_of_mem_mem (Set.mul_mem_mul hr (hc1 hr')) (c _).2) scoped[Pointwise] attribute [instance] Submodule.pointwiseSetMulAction -- This cannot be generalized to `Set S` because `MulAction` can't be generalized already. /-- In a ring, sets acts on submodules. -/ protected noncomputable def pointwiseSetDistribMulAction [SMulCommClass R R M] : DistribMulAction (Set R) (Submodule R M) where smul_zero s := set_smul_bot s smul_add s x y := le_antisymm (set_smul_le _ _ _ <| by rintro r m hr hm rw [add_eq_sup, Submodule.mem_sup] at hm obtain ⟨a, ha, b, hb, rfl⟩ := hm rw [smul_add, add_eq_sup, Submodule.mem_sup] exact ⟨r • a, mem_set_smul_of_mem_mem (mem1 := hr) (mem2 := ha), r • b, mem_set_smul_of_mem_mem (mem1 := hr) (mem2 := hb), rfl⟩) (sup_le_iff.mpr ⟨smul_mono_right _ le_sup_left, smul_mono_right _ le_sup_right⟩) scoped[Pointwise] attribute [instance] Submodule.pointwiseSetDistribMulAction lemma sup_set_smul (s t : Set S) : (s ⊔ t) • N = s • N ⊔ t • N := set_smul_eq_of_le _ _ _ (by rintro _ _ (hr|hr) hn · exact Submodule.mem_sup_left (mem_set_smul_of_mem_mem hr hn) · exact Submodule.mem_sup_right (mem_set_smul_of_mem_mem hr hn)) (sup_le (set_smul_mono_left _ le_sup_left) (set_smul_mono_left _ le_sup_right)) end set_acting_on_submodules end Submodule
.lake/packages/mathlib/Mathlib/Algebra/Module/Submodule/Union.lean
import Mathlib.Algebra.Module.Submodule.Lattice import Mathlib.Data.Set.Card import Mathlib.LinearAlgebra.Dual.Defs import Mathlib.Tactic.Module /-! # Unions of `Submodule`s This file is a home for results about unions of submodules. ## Main results: * `Submodule.iUnion_ssubset_of_forall_ne_top_of_card_lt`: a finite union of proper submodules is a proper subset, provided the coefficients are a sufficiently large field. -/ open Function Set variable {ι K M : Type*} [Field K] [AddCommGroup M] [Module K M] lemma Submodule.iUnion_ssubset_of_forall_ne_top_of_card_lt (s : Finset ι) (p : ι → Submodule K M) (h₁ : ∀ i, p i ≠ ⊤) (h₂ : s.card < ENat.card K) : ⋃ i ∈ s, (p i : Set M) ⊂ univ := by -- Following https://mathoverflow.net/a/14241 classical induction s using Finset.induction_on with | empty => simp | insert j s hj hj' => simp only [ssubset_univ_iff] at hj' ⊢ rcases s.eq_empty_or_nonempty with rfl | hs · simpa [← SetLike.coe_ne_coe] using h₁ j replace h₂ : s.card + 1 < ENat.card K := by simpa [Finset.card_insert_of_notMem hj] using h₂ specialize hj' (lt_trans ENat.natCast_lt_succ h₂) contrapose! hj' replace hj' : (p j : Set M) ∪ (⋃ i ∈ s, p i) = univ := by simpa only [Finset.mem_insert, iUnion_iUnion_eq_or_left] using hj' suffices (p j : Set M) ⊆ ⋃ i ∈ s, p i by rwa [union_eq_right.mpr this] at hj' intro x (hx : x ∈ p j) rcases eq_or_ne x 0 with rfl | hx₀ · simpa using hs obtain ⟨y, hy⟩ : ∃ y, y ∉ p j := by specialize h₁ j; contrapose! h₁; ext; simp [h₁] have hy₀ : y ≠ 0 := by aesop let sxy := {x + t • y | (t : K) (ht : t ≠ 0)} have hsxy : sxy ⊆ ⋃ i ∈ s, p i := by suffices Disjoint sxy (p j) from this.subset_right_of_subset_union <| hj' ▸ sxy.subset_univ rw [Set.disjoint_iff] rintro - ⟨⟨t, ht₀, rfl⟩, ht : x + t • y ∈ p j⟩ rw [(p j).add_mem_iff_right hx, (p j).smul_mem_iff ht₀] at ht contradiction obtain ⟨k, hk, t₁, t₂, ht, ht₁, ht₂⟩ : ∃ᵉ (k ∈ s) (t₁ : K) (t₂ : K), t₁ ≠ t₂ ∧ x + t₁ • y ∈ p k ∧ x + t₂ • y ∈ p k := by suffices ∃ᵉ (k ∈ s) (z₁ ∈ sxy) (z₂ ∈ sxy), z₁ ≠ z₂ ∧ z₁ ∈ p k ∧ z₂ ∈ p k by obtain ⟨k, hk, -, ⟨t₁, -, rfl⟩, -, ⟨t₂, -, rfl⟩, htne, ht₁, ht₂⟩ := this exact ⟨k, hk, t₁, t₂, by aesop, ht₁, ht₂⟩ choose f hf using fun z : sxy ↦ mem_iUnion.mp (hsxy z.property) have hf' : MapsTo f univ s := fun z _ ↦ by specialize hf z; aesop suffices ∃ z₁ z₂, z₁ ≠ z₂ ∧ f z₁ = f z₂ by obtain ⟨z₁, z₂, hne, heq⟩ := this exact ⟨f z₁, hf' (mem_univ _), z₁, z₁.property, z₂, z₂.property, Subtype.coe_ne_coe.mpr hne, by specialize hf z₁; simp_all, by specialize hf z₂; aesop⟩ have key : s.card < sxy.encard := by refine lt_of_add_lt_add_right <| lt_of_lt_of_le h₂ ?_ have : Injective (fun t : K ↦ x + t • y) := fun t₁ t₂ ht ↦ smul_left_injective K hy₀ <| by simpa using ht have aux : sxy = ((fun t : K ↦ x + t • y) '' {t | t ≠ 0}) := by ext; simp [sxy] rw [aux, this.encard_image, encard_ne_add_one] obtain ⟨z₁, -, z₂, -, h⟩ := exists_ne_map_eq_of_encard_lt_of_maps_to (by simpa) hf' exact ⟨z₁, z₂, h⟩ replace ht : y ∈ p k := by have : (t₁ - t₂) • y ∈ p k := by convert sub_mem ht₁ ht₂ using 1; module refine ((p k).smul_mem_iff ?_).mp this rwa [sub_ne_zero] replace ht : x ∈ p k := by convert sub_mem ht₁ ((p k).smul_mem t₁ ht); simp simpa using ⟨k, hk, ht⟩ variable [Finite ι] [Infinite K] lemma Submodule.exists_forall_notMem_of_forall_ne_top (p : ι → Submodule K M) (h : ∀ i, p i ≠ ⊤) : ∃ x, ∀ i, x ∉ p i := by let _i : Fintype ι := Fintype.ofFinite ι suffices ⋃ i, (p i : Set M) ⊂ univ by simpa [ssubset_univ_iff, iUnion_eq_univ_iff] using this simpa using iUnion_ssubset_of_forall_ne_top_of_card_lt Finset.univ p h (by simp) lemma Module.Dual.exists_forall_ne_zero_of_forall_exists (f : ι → Dual K M) (h : ∀ i, ∃ x, f i x ≠ 0) : ∃ x, ∀ i, f i x ≠ 0 := by let p i := LinearMap.ker (f i) replace h i : p i ≠ ⊤ := by specialize h i; aesop obtain ⟨x, hx⟩ := Submodule.exists_forall_notMem_of_forall_ne_top p h exact ⟨x, by simpa [p] using hx⟩ /-- A convenience variation of `Module.Dual.exists_forall_ne_zero_of_forall_exists` where we are concerned only about behaviour on a fixed submodule. -/ lemma Module.Dual.exists_forall_mem_ne_zero_of_forall_exists (p : Submodule K M) (f : ι → Dual K M) (h : ∀ i, ∃ x ∈ p, f i x ≠ 0) : ∃ x ∈ p, ∀ i, f i x ≠ 0 := by let f' (i : ι) : Dual K p := (f i).domRestrict p replace h (i : ι) : ∃ x : p, f' i x ≠ 0 := by obtain ⟨x, hxp, hx₀⟩ := h i; exact ⟨⟨x, hxp⟩, hx₀⟩ obtain ⟨⟨x, hxp⟩, hx₀⟩ := exists_forall_ne_zero_of_forall_exists f' h exact ⟨x, hxp, hx₀⟩
.lake/packages/mathlib/Mathlib/Algebra/Module/Submodule/Order.lean
import Mathlib.Algebra.Module.Submodule.Defs import Mathlib.Algebra.Order.Monoid.Basic /-! # Ordered instances on submodules -/ namespace Submodule variable {R M : Type*} section OrderedMonoid variable [Semiring R] /-- A submodule of an ordered additive monoid is an ordered additive monoid. -/ instance toIsOrderedAddMonoid [AddCommMonoid M] [PartialOrder M] [IsOrderedAddMonoid M] [Module R M] (S : Submodule R M) : IsOrderedAddMonoid S := Function.Injective.isOrderedAddMonoid Subtype.val (fun _ _ => rfl) .rfl /-- A submodule of an ordered cancellative additive monoid is an ordered cancellative additive monoid. -/ instance toIsOrderedCancelAddMonoid [AddCommMonoid M] [PartialOrder M] [IsOrderedCancelAddMonoid M] [Module R M] (S : Submodule R M) : IsOrderedCancelAddMonoid S := Function.Injective.isOrderedCancelAddMonoid Subtype.val (fun _ _ => rfl) .rfl end OrderedMonoid end Submodule
.lake/packages/mathlib/Mathlib/Algebra/Module/Submodule/Map.lean
import Mathlib.Algebra.Group.Subgroup.Map import Mathlib.Algebra.Module.Submodule.Basic import Mathlib.Algebra.Module.Submodule.Lattice import Mathlib.Algebra.Module.Submodule.LinearMap /-! # `map` and `comap` for `Submodule`s ## Main declarations * `Submodule.map`: The pushforward of a submodule `p ⊆ M` by `f : M → M₂` * `Submodule.comap`: The pullback of a submodule `p ⊆ M₂` along `f : M → M₂` * `Submodule.giMapComap`: `map f` and `comap f` form a `GaloisInsertion` when `f` is surjective. * `Submodule.gciMapComap`: `map f` and `comap f` form a `GaloisCoinsertion` when `f` is injective. ## Tags submodule, subspace, linear map, pushforward, pullback -/ open Function Pointwise Set variable {R : Type*} {R₁ : Type*} {R₂ : Type*} {R₃ : Type*} variable {M : Type*} {M₁ : Type*} {M₂ : Type*} {M₃ : Type*} namespace Submodule section AddCommMonoid variable [Semiring R] [Semiring R₂] [Semiring R₃] variable [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] variable [Module R M] [Module R₂ M₂] [Module R₃ M₃] variable {σ₁₂ : R →+* R₂} {σ₂₃ : R₂ →+* R₃} {σ₁₃ : R →+* R₃} variable [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃] variable (p p' : Submodule R M) (q q' : Submodule R₂ M₂) variable {x : M} section variable [RingHomSurjective σ₁₂] {F : Type*} [FunLike F M M₂] [SemilinearMapClass F σ₁₂ M M₂] /-- The pushforward of a submodule `p ⊆ M` by `f : M → M₂` -/ def map (f : F) (p : Submodule R M) : Submodule R₂ M₂ := { p.toAddSubmonoid.map f with carrier := f '' p smul_mem' := by rintro c x ⟨y, hy, rfl⟩ obtain ⟨a, rfl⟩ := σ₁₂.surjective c exact ⟨_, p.smul_mem a hy, map_smulₛₗ f _ _⟩ } @[simp] theorem map_coe (f : F) (p : Submodule R M) : (map f p : Set M₂) = f '' p := rfl @[simp] theorem map_coe_toLinearMap (f : F) (p : Submodule R M) : map (f : M →ₛₗ[σ₁₂] M₂) p = map f p := rfl theorem map_toAddSubmonoid (f : M →ₛₗ[σ₁₂] M₂) (p : Submodule R M) : (p.map f).toAddSubmonoid = p.toAddSubmonoid.map (f : M →+ M₂) := SetLike.coe_injective rfl theorem map_toAddSubmonoid' (f : M →ₛₗ[σ₁₂] M₂) (p : Submodule R M) : (p.map f).toAddSubmonoid = p.toAddSubmonoid.map f := SetLike.coe_injective rfl @[simp] theorem _root_.AddMonoidHom.coe_toIntLinearMap_map {A A₂ : Type*} [AddCommGroup A] [AddCommGroup A₂] (f : A →+ A₂) (s : AddSubgroup A) : (AddSubgroup.toIntSubmodule s).map f.toIntLinearMap = AddSubgroup.toIntSubmodule (s.map f) := rfl @[simp] theorem _root_.MonoidHom.coe_toAdditive_map {G G₂ : Type*} [Group G] [Group G₂] (f : G →* G₂) (s : Subgroup G) : s.toAddSubgroup.map (MonoidHom.toAdditive f) = Subgroup.toAddSubgroup (s.map f) := rfl @[simp] theorem _root_.AddMonoidHom.coe_toMultiplicative_map {G G₂ : Type*} [AddGroup G] [AddGroup G₂] (f : G →+ G₂) (s : AddSubgroup G) : s.toSubgroup.map (AddMonoidHom.toMultiplicative f) = AddSubgroup.toSubgroup (s.map f) := rfl @[simp] theorem mem_map {f : F} {p : Submodule R M} {x : M₂} : x ∈ map f p ↔ ∃ y, y ∈ p ∧ f y = x := Iff.rfl theorem mem_map_of_mem {f : F} {p : Submodule R M} {r} (h : r ∈ p) : f r ∈ map f p := Set.mem_image_of_mem _ h theorem apply_coe_mem_map (f : F) {p : Submodule R M} (r : p) : f r ∈ map f p := mem_map_of_mem r.prop @[simp] theorem map_id : map (LinearMap.id : M →ₗ[R] M) p = p := Submodule.ext fun a => by simp theorem map_comp [RingHomSurjective σ₂₃] [RingHomSurjective σ₁₃] (f : M →ₛₗ[σ₁₂] M₂) (g : M₂ →ₛₗ[σ₂₃] M₃) (p : Submodule R M) : map (g.comp f : M →ₛₗ[σ₁₃] M₃) p = map g (map f p) := SetLike.coe_injective <| by simp only [← image_comp, map_coe, LinearMap.coe_comp, comp_apply] @[gcongr] theorem map_mono {f : F} {p p' : Submodule R M} : p ≤ p' → map f p ≤ map f p' := image_mono @[simp] protected theorem map_zero : map (0 : M →ₛₗ[σ₁₂] M₂) p = ⊥ := have : ∃ x : M, x ∈ p := ⟨0, p.zero_mem⟩ ext <| by simp [this, eq_comm] theorem map_add_le (f g : M →ₛₗ[σ₁₂] M₂) : map (f + g) p ≤ map f p ⊔ map g p := by rintro x ⟨m, hm, rfl⟩ exact add_mem_sup (mem_map_of_mem hm) (mem_map_of_mem hm) theorem map_inf_le (f : F) {p q : Submodule R M} : (p ⊓ q).map f ≤ p.map f ⊓ q.map f := image_inter_subset f p q theorem map_inf (f : F) {p q : Submodule R M} (hf : Injective f) : (p ⊓ q).map f = p.map f ⊓ q.map f := SetLike.coe_injective <| Set.image_inter hf lemma map_iInf {ι : Sort*} [Nonempty ι] {p : ι → Submodule R M} (f : F) (hf : Injective f) : (⨅ i, p i).map f = ⨅ i, (p i).map f := SetLike.coe_injective <| by simpa only [map_coe, coe_iInf] using hf.injOn.image_iInter_eq theorem range_map_nonempty (N : Submodule R M) : (Set.range (fun ϕ => Submodule.map ϕ N : (M →ₛₗ[σ₁₂] M₂) → Submodule R₂ M₂)).Nonempty := ⟨_, Set.mem_range.mpr ⟨0, rfl⟩⟩ end section SemilinearMap variable {σ₂₁ : R₂ →+* R} [RingHomInvPair σ₁₂ σ₂₁] [RingHomInvPair σ₂₁ σ₁₂] variable {F : Type*} [FunLike F M M₂] [SemilinearMapClass F σ₁₂ M M₂] /-- The pushforward of a submodule by an injective linear map is linearly equivalent to the original submodule. See also `LinearEquiv.submoduleMap` for a computable version when `f` has an explicit inverse. -/ noncomputable def equivMapOfInjective (f : F) (i : Injective f) (p : Submodule R M) : p ≃ₛₗ[σ₁₂] p.map f := { Equiv.Set.image f p i with map_add' := by intros simp only [coe_add, map_add, Equiv.toFun_as_coe, Equiv.Set.image_apply] rfl map_smul' := by intros -- Note: https://github.com/leanprover-community/mathlib4/pull/8386 changed `map_smulₛₗ` into `map_smulₛₗ _` simp only [coe_smul_of_tower, map_smulₛₗ _, Equiv.toFun_as_coe, Equiv.Set.image_apply] rfl } @[simp] theorem coe_equivMapOfInjective_apply (f : F) (i : Injective f) (p : Submodule R M) (x : p) : (equivMapOfInjective f i p x : M₂) = f x := rfl @[simp] theorem map_equivMapOfInjective_symm_apply (f : F) (i : Injective f) (p : Submodule R M) (x : p.map f) : f ((equivMapOfInjective f i p).symm x) = x := by rw [← LinearEquiv.apply_symm_apply (equivMapOfInjective f i p) x, coe_equivMapOfInjective_apply, i.eq_iff, LinearEquiv.apply_symm_apply] /-- The pullback of a submodule `p ⊆ M₂` along `f : M → M₂` -/ def comap [SemilinearMapClass F σ₁₂ M M₂] (f : F) (p : Submodule R₂ M₂) : Submodule R M := { p.toAddSubmonoid.comap f with carrier := f ⁻¹' p -- Note: https://github.com/leanprover-community/mathlib4/pull/8386 added `map_smulₛₗ _` smul_mem' := fun a x h => by simp [p.smul_mem (σ₁₂ a) h, map_smulₛₗ _] } @[simp] theorem comap_coe (f : F) (p : Submodule R₂ M₂) : (comap f p : Set M) = f ⁻¹' p := rfl @[simp] theorem comap_coe_toLinearMap (f : F) (p : Submodule R₂ M₂) : comap (f : M →ₛₗ[σ₁₂] M₂) p = comap f p := rfl @[simp] theorem AddMonoidHom.coe_toIntLinearMap_comap {A A₂ : Type*} [AddCommGroup A] [AddCommGroup A₂] (f : A →+ A₂) (s : AddSubgroup A₂) : (AddSubgroup.toIntSubmodule s).comap f.toIntLinearMap = AddSubgroup.toIntSubmodule (s.comap f) := rfl @[simp] theorem mem_comap {f : F} {p : Submodule R₂ M₂} : x ∈ comap f p ↔ f x ∈ p := Iff.rfl @[simp] theorem comap_id : comap (LinearMap.id : M →ₗ[R] M) p = p := SetLike.coe_injective rfl theorem comap_comp (f : M →ₛₗ[σ₁₂] M₂) (g : M₂ →ₛₗ[σ₂₃] M₃) (p : Submodule R₃ M₃) : comap (g.comp f : M →ₛₗ[σ₁₃] M₃) p = comap f (comap g p) := rfl @[gcongr] theorem comap_mono {f : F} {q q' : Submodule R₂ M₂} : q ≤ q' → comap f q ≤ comap f q' := preimage_mono theorem le_comap_pow_of_le_comap (p : Submodule R M) {f : M →ₗ[R] M} (h : p ≤ p.comap f) (k : ℕ) : p ≤ p.comap (f ^ k) := by induction k with | zero => simp [Module.End.one_eq_id] | succ k ih => simp [Module.End.iterate_succ, comap_comp, h.trans (comap_mono ih)] section variable [RingHomSurjective σ₁₂] theorem map_le_iff_le_comap {f : F} {p : Submodule R M} {q : Submodule R₂ M₂} : map f p ≤ q ↔ p ≤ comap f q := image_subset_iff theorem gc_map_comap (f : F) : GaloisConnection (map f) (comap f) | _, _ => map_le_iff_le_comap @[simp] theorem map_bot (f : F) : map f ⊥ = ⊥ := (gc_map_comap f).l_bot @[simp] theorem map_sup (f : F) : map f (p ⊔ p') = map f p ⊔ map f p' := (gc_map_comap f : GaloisConnection (map f) (comap f)).l_sup @[simp] theorem map_iSup {ι : Sort*} (f : F) (p : ι → Submodule R M) : map f (⨆ i, p i) = ⨆ i, map f (p i) := (gc_map_comap f : GaloisConnection (map f) (comap f)).l_iSup lemma disjoint_map {f : F} (hf : Function.Injective f) {p q : Submodule R M} (hpq : Disjoint p q) : Disjoint (p.map f) (q.map f) := by rw [disjoint_iff, ← map_inf f hf, disjoint_iff.mp hpq, map_bot] end @[simp] theorem comap_top (f : F) : comap f ⊤ = ⊤ := rfl @[simp] theorem comap_inf (f : F) : comap f (q ⊓ q') = comap f q ⊓ comap f q' := rfl @[simp] theorem comap_iInf [RingHomSurjective σ₁₂] {ι : Sort*} (f : F) (p : ι → Submodule R₂ M₂) : comap f (⨅ i, p i) = ⨅ i, comap f (p i) := (gc_map_comap f : GaloisConnection (map f) (comap f)).u_iInf @[simp] theorem comap_zero : comap (0 : M →ₛₗ[σ₁₂] M₂) q = ⊤ := ext <| by simp theorem map_comap_le [RingHomSurjective σ₁₂] (f : F) (q : Submodule R₂ M₂) : map f (comap f q) ≤ q := (gc_map_comap f).l_u_le _ theorem le_comap_map [RingHomSurjective σ₁₂] (f : F) (p : Submodule R M) : p ≤ comap f (map f p) := (gc_map_comap f).le_u_l _ section submoduleOf /-- For any `R` submodules `p` and `q`, `p ⊓ q` as a submodule of `q`. -/ def submoduleOf (p q : Submodule R M) : Submodule R q := Submodule.comap q.subtype p /-- If `p ≤ q`, then `p` as a subgroup of `q` is isomorphic to `p`. -/ def submoduleOfEquivOfLe {p q : Submodule R M} (h : p ≤ q) : p.submoduleOf q ≃ₗ[R] p where toFun m := ⟨m.1, m.2⟩ invFun m := ⟨⟨m.1, h m.2⟩, m.2⟩ map_add' _ _ := rfl map_smul' _ _ := rfl end submoduleOf section GaloisInsertion variable [RingHomSurjective σ₁₂] {f : F} /-- `map f` and `comap f` form a `GaloisInsertion` when `f` is surjective. -/ def giMapComap (hf : Surjective f) : GaloisInsertion (map f) (comap f) := (gc_map_comap f).toGaloisInsertion fun S x hx => by rcases hf x with ⟨y, rfl⟩ simp only [mem_map, mem_comap] exact ⟨y, hx, rfl⟩ variable (hf : Surjective f) include hf theorem map_comap_eq_of_surjective (p : Submodule R₂ M₂) : (p.comap f).map f = p := (giMapComap hf).l_u_eq _ theorem map_surjective_of_surjective : Function.Surjective (map f) := (giMapComap hf).l_surjective theorem comap_injective_of_surjective : Function.Injective (comap f) := (giMapComap hf).u_injective theorem map_sup_comap_of_surjective (p q : Submodule R₂ M₂) : (p.comap f ⊔ q.comap f).map f = p ⊔ q := (giMapComap hf).l_sup_u _ _ theorem map_iSup_comap_of_surjective {ι : Sort*} (S : ι → Submodule R₂ M₂) : (⨆ i, (S i).comap f).map f = iSup S := (giMapComap hf).l_iSup_u _ @[deprecated (since := "2025-07-08")] alias map_iSup_comap_of_sujective := map_iSup_comap_of_surjective theorem map_inf_comap_of_surjective (p q : Submodule R₂ M₂) : (p.comap f ⊓ q.comap f).map f = p ⊓ q := (giMapComap hf).l_inf_u _ _ theorem map_iInf_comap_of_surjective {ι : Sort*} (S : ι → Submodule R₂ M₂) : (⨅ i, (S i).comap f).map f = iInf S := (giMapComap hf).l_iInf_u _ theorem comap_le_comap_iff_of_surjective {p q : Submodule R₂ M₂} : p.comap f ≤ q.comap f ↔ p ≤ q := (giMapComap hf).u_le_u_iff lemma comap_lt_comap_iff_of_surjective {p q : Submodule R₂ M₂} : p.comap f < q.comap f ↔ p < q := by apply lt_iff_lt_of_le_iff_le' <;> exact comap_le_comap_iff_of_surjective hf theorem comap_strictMono_of_surjective : StrictMono (comap f) := (giMapComap hf).strictMono_u variable {p q} theorem le_map_of_comap_le_of_surjective (h : q.comap f ≤ p) : q ≤ p.map f := map_comap_eq_of_surjective hf q ▸ map_mono h theorem lt_map_of_comap_lt_of_surjective (h : q.comap f < p) : q < p.map f := by rw [lt_iff_le_not_ge] at h ⊢; rw [map_le_iff_le_comap] exact h.imp_left (le_map_of_comap_le_of_surjective hf) end GaloisInsertion section GaloisCoinsertion variable [RingHomSurjective σ₁₂] {f : F} /-- `map f` and `comap f` form a `GaloisCoinsertion` when `f` is injective. -/ def gciMapComap (hf : Injective f) : GaloisCoinsertion (map f) (comap f) := (gc_map_comap f).toGaloisCoinsertion fun S x => by simp only [mem_comap, mem_map, forall_exists_index, and_imp] intro y hy hxy rw [hf.eq_iff] at hxy rwa [← hxy] variable (hf : Injective f) include hf theorem comap_map_eq_of_injective (p : Submodule R M) : (p.map f).comap f = p := (gciMapComap hf).u_l_eq _ theorem comap_surjective_of_injective : Function.Surjective (comap f) := (gciMapComap hf).u_surjective theorem map_injective_of_injective : Function.Injective (map f) := (gciMapComap hf).l_injective theorem comap_inf_map_of_injective (p q : Submodule R M) : (p.map f ⊓ q.map f).comap f = p ⊓ q := (gciMapComap hf).u_inf_l _ _ theorem comap_iInf_map_of_injective {ι : Sort*} (S : ι → Submodule R M) : (⨅ i, (S i).map f).comap f = iInf S := (gciMapComap hf).u_iInf_l _ theorem comap_sup_map_of_injective (p q : Submodule R M) : (p.map f ⊔ q.map f).comap f = p ⊔ q := (gciMapComap hf).u_sup_l _ _ theorem comap_iSup_map_of_injective {ι : Sort*} (S : ι → Submodule R M) : (⨆ i, (S i).map f).comap f = iSup S := (gciMapComap hf).u_iSup_l _ theorem map_le_map_iff_of_injective (p q : Submodule R M) : p.map f ≤ q.map f ↔ p ≤ q := (gciMapComap hf).l_le_l_iff theorem map_strictMono_of_injective : StrictMono (map f) := (gciMapComap hf).strictMono_l lemma map_lt_map_iff_of_injective {p q : Submodule R M} : p.map f < q.map f ↔ p < q := by rw [lt_iff_le_and_ne, lt_iff_le_and_ne, map_le_map_iff_of_injective hf, (map_injective_of_injective hf).ne_iff] lemma comap_lt_of_lt_map_of_injective {p : Submodule R M} {q : Submodule R₂ M₂} (h : q < p.map f) : q.comap f < p := by rw [← map_lt_map_iff_of_injective hf] exact (map_comap_le _ _).trans_lt h lemma map_covBy_of_injective {p q : Submodule R M} (h : p ⋖ q) : p.map f ⋖ q.map f := by refine ⟨lt_of_le_of_ne (map_mono h.1.le) ((map_injective_of_injective hf).ne h.1.ne), ?_⟩ intro P h₁ h₂ refine h.2 ?_ (Submodule.comap_lt_of_lt_map_of_injective hf h₂) rw [← Submodule.map_lt_map_iff_of_injective hf] refine h₁.trans_le ?_ exact (Set.image_preimage_eq_of_subset (.trans h₂.le (Set.image_subset_range _ _))).superset end GaloisCoinsertion end SemilinearMap section OrderIso variable [RingHomSurjective σ₁₂] {F : Type*} /-- A linear isomorphism induces an order isomorphism of submodules. -/ @[simps symm_apply apply] def orderIsoMapComapOfBijective [FunLike F M M₂] [SemilinearMapClass F σ₁₂ M M₂] (f : F) (hf : Bijective f) : Submodule R M ≃o Submodule R₂ M₂ where toFun := map f invFun := comap f left_inv := comap_map_eq_of_injective hf.injective right_inv := map_comap_eq_of_surjective hf.surjective map_rel_iff' := map_le_map_iff_of_injective hf.injective _ _ /-- A linear isomorphism induces an order isomorphism of submodules. -/ @[simps! apply] def orderIsoMapComap [EquivLike F M M₂] [SemilinearMapClass F σ₁₂ M M₂] (f : F) : Submodule R M ≃o Submodule R₂ M₂ := orderIsoMapComapOfBijective f (EquivLike.bijective f) @[simp] lemma orderIsoMapComap_symm_apply [EquivLike F M M₂] [SemilinearMapClass F σ₁₂ M M₂] (f : F) (p : Submodule R₂ M₂) : (orderIsoMapComap f).symm p = comap f p := rfl variable [EquivLike F M M₂] [SemilinearMapClass F σ₁₂ M M₂] {e : F} variable {p} @[simp] protected lemma map_eq_bot_iff : p.map e = ⊥ ↔ p = ⊥ := map_eq_bot_iff (orderIsoMapComap e) @[simp] protected lemma map_eq_top_iff : p.map e = ⊤ ↔ p = ⊤ := map_eq_top_iff (orderIsoMapComap e) protected lemma map_ne_bot_iff : p.map e ≠ ⊥ ↔ p ≠ ⊥ := by simp protected lemma map_ne_top_iff : p.map e ≠ ⊤ ↔ p ≠ ⊤ := by simp end OrderIso variable {F : Type*} [FunLike F M M₂] [SemilinearMapClass F σ₁₂ M M₂] --TODO(Mario): is there a way to prove this from order properties? theorem map_inf_eq_map_inf_comap [RingHomSurjective σ₁₂] {f : F} {p : Submodule R M} {p' : Submodule R₂ M₂} : map f p ⊓ p' = map f (p ⊓ comap f p') := le_antisymm (by rintro _ ⟨⟨x, h₁, rfl⟩, h₂⟩; exact ⟨_, ⟨h₁, h₂⟩, rfl⟩) (le_inf (map_mono inf_le_left) (map_le_iff_le_comap.2 inf_le_right)) @[simp] theorem map_comap_subtype : map p.subtype (comap p.subtype p') = p ⊓ p' := ext fun x => ⟨by rintro ⟨⟨_, h₁⟩, h₂, rfl⟩; exact ⟨h₁, h₂⟩, fun ⟨h₁, h₂⟩ => ⟨⟨_, h₁⟩, h₂, rfl⟩⟩ theorem eq_zero_of_bot_submodule : ∀ b : (⊥ : Submodule R M), b = 0 | ⟨b', hb⟩ => Subtype.eq <| show b' = 0 from (mem_bot R).1 hb /-- The infimum of a family of invariant submodule of an endomorphism is also an invariant submodule. -/ theorem _root_.LinearMap.iInf_invariant {σ : R →+* R} {ι : Sort*} (f : M →ₛₗ[σ] M) {p : ι → Submodule R M} (hf : ∀ i, ∀ v ∈ p i, f v ∈ p i) : ∀ v ∈ iInf p, f v ∈ iInf p := by simp only [mem_iInf] exact fun v a i ↦ hf i v (a i) theorem disjoint_iff_comap_eq_bot {p q : Submodule R M} : Disjoint p q ↔ comap p.subtype q = ⊥ := by rw [← (map_injective_of_injective (show Injective p.subtype from Subtype.coe_injective)).eq_iff, map_comap_subtype, map_bot, disjoint_iff] end AddCommMonoid section AddCommGroup variable [Ring R] [AddCommGroup M] [Module R M] (p : Submodule R M) variable [AddCommGroup M₂] [Module R M₂] @[simp] protected theorem map_neg (f : M →ₗ[R] M₂) : map (-f) p = map f p := ext fun _ => ⟨fun ⟨x, hx, hy⟩ => hy ▸ ⟨-x, show -x ∈ p from neg_mem hx, map_neg f x⟩, fun ⟨x, hx, hy⟩ => hy ▸ ⟨-x, show -x ∈ p from neg_mem hx, (map_neg (-f) _).trans (neg_neg (f x))⟩⟩ @[simp] lemma comap_neg {f : M →ₗ[R] M₂} {p : Submodule R M₂} : p.comap (-f) = p.comap f := by ext; simp lemma map_toAddSubgroup (f : M →ₗ[R] M₂) (p : Submodule R M) : (p.map f).toAddSubgroup = p.toAddSubgroup.map (f : M →+ M₂) := rfl end AddCommGroup end Submodule namespace Submodule variable {K : Type*} {V : Type*} {V₂ : Type*} variable [Semifield K] variable [AddCommMonoid V] [Module K V] variable [AddCommMonoid V₂] [Module K V₂] theorem comap_smul (f : V →ₗ[K] V₂) (p : Submodule K V₂) (a : K) (h : a ≠ 0) : p.comap (a • f) = p.comap f := by ext b; simp only [Submodule.mem_comap, p.smul_mem_iff h, LinearMap.smul_apply] protected theorem map_smul (f : V →ₗ[K] V₂) (p : Submodule K V) (a : K) (h : a ≠ 0) : p.map (a • f) = p.map f := le_antisymm (by rw [map_le_iff_le_comap, comap_smul f _ a h, ← map_le_iff_le_comap]) (by rw [map_le_iff_le_comap, ← comap_smul f _ a h, ← map_le_iff_le_comap]) theorem comap_smul' (f : V →ₗ[K] V₂) (p : Submodule K V₂) (a : K) : p.comap (a • f) = ⨅ _ : a ≠ 0, p.comap f := by classical by_cases h : a = 0 <;> simp [h, comap_smul] theorem map_smul' (f : V →ₗ[K] V₂) (p : Submodule K V) (a : K) : p.map (a • f) = ⨆ _ : a ≠ 0, map f p := by classical by_cases h : a = 0 <;> simp [h, Submodule.map_smul] end Submodule namespace Submodule section Module variable [Semiring R] [AddCommMonoid M] [Module R M] /-- If `s ≤ t`, then we can view `s` as a submodule of `t` by taking the comap of `t.subtype`. -/ @[simps apply_coe symm_apply] def comapSubtypeEquivOfLe {p q : Submodule R M} (hpq : p ≤ q) : comap q.subtype p ≃ₗ[R] p where toFun x := ⟨x, x.2⟩ invFun x := ⟨⟨x, hpq x.2⟩, x.2⟩ left_inv x := by simp only [SetLike.eta] right_inv x := by simp only [SetLike.eta] map_add' _ _ := rfl map_smul' _ _ := rfl end Module end Submodule namespace Submodule variable [Semiring R] [Semiring R₂] variable [AddCommMonoid M] [AddCommMonoid M₂] [Module R M] [Module R₂ M₂] variable {τ₁₂ : R →+* R₂} {τ₂₁ : R₂ →+* R} variable [RingHomInvPair τ₁₂ τ₂₁] [RingHomInvPair τ₂₁ τ₁₂] variable (p : Submodule R M) (q : Submodule R₂ M₂) @[simp high] theorem mem_map_equiv {e : M ≃ₛₗ[τ₁₂] M₂} {x : M₂} : x ∈ p.map (e : M →ₛₗ[τ₁₂] M₂) ↔ e.symm x ∈ p := by rw [Submodule.mem_map]; constructor · rintro ⟨y, hy, hx⟩ simp [← hx, hy] · intro hx exact ⟨e.symm x, hx, by simp⟩ theorem map_equiv_eq_comap_symm (e : M ≃ₛₗ[τ₁₂] M₂) (K : Submodule R M) : K.map (e : M →ₛₗ[τ₁₂] M₂) = K.comap (e.symm : M₂ →ₛₗ[τ₂₁] M) := Submodule.ext fun _ => by rw [mem_map_equiv, mem_comap, LinearEquiv.coe_coe] theorem comap_equiv_eq_map_symm (e : M ≃ₛₗ[τ₁₂] M₂) (K : Submodule R₂ M₂) : K.comap (e : M →ₛₗ[τ₁₂] M₂) = K.map (e.symm : M₂ →ₛₗ[τ₂₁] M) := (map_equiv_eq_comap_symm e.symm K).symm variable {p} theorem map_symm_eq_iff (e : M ≃ₛₗ[τ₁₂] M₂) {K : Submodule R₂ M₂} : K.map e.symm = p ↔ p.map e = K := by constructor <;> rintro rfl · calc map e (map e.symm K) = comap e.symm (map e.symm K) := map_equiv_eq_comap_symm _ _ _ = K := comap_map_eq_of_injective e.symm.injective _ · calc map e.symm (map e p) = comap e (map e p) := (comap_equiv_eq_map_symm _ _).symm _ = p := comap_map_eq_of_injective e.injective _ theorem orderIsoMapComap_apply' (e : M ≃ₛₗ[τ₁₂] M₂) (p : Submodule R M) : orderIsoMapComap e p = comap e.symm p := p.map_equiv_eq_comap_symm _ theorem orderIsoMapComap_symm_apply' (e : M ≃ₛₗ[τ₁₂] M₂) (p : Submodule R₂ M₂) : (orderIsoMapComap e).symm p = map e.symm p := p.comap_equiv_eq_map_symm _ theorem inf_comap_le_comap_add (f₁ f₂ : M →ₛₗ[τ₁₂] M₂) : comap f₁ q ⊓ comap f₂ q ≤ comap (f₁ + f₂) q := by rw [SetLike.le_def] intro m h change f₁ m + f₂ m ∈ q change f₁ m ∈ q ∧ f₂ m ∈ q at h apply q.add_mem h.1 h.2 lemma surjOn_iff_le_map [RingHomSurjective τ₁₂] {f : M →ₛₗ[τ₁₂] M₂} {p : Submodule R M} {q : Submodule R₂ M₂} : Set.SurjOn f p q ↔ q ≤ p.map f := Iff.rfl end Submodule namespace Submodule variable {N N₂ : Type*} variable [CommSemiring R] [CommSemiring R₂] variable [AddCommMonoid M] [AddCommMonoid M₂] [Module R M] [Module R₂ M₂] variable [AddCommMonoid N] [AddCommMonoid N₂] [Module R N] [Module R N₂] variable {τ₁₂ : R →+* R₂} {τ₂₁ : R₂ →+* R} variable [RingHomInvPair τ₁₂ τ₂₁] [RingHomInvPair τ₂₁ τ₁₂] variable (p : Submodule R M) (q : Submodule R₂ M₂) variable (pₗ : Submodule R N) (qₗ : Submodule R N₂) theorem comap_le_comap_smul (fₗ : N →ₗ[R] N₂) (c : R) : comap fₗ qₗ ≤ comap (c • fₗ) qₗ := by rw [SetLike.le_def] intro m h change c • fₗ m ∈ qₗ change fₗ m ∈ qₗ at h apply qₗ.smul_mem _ h /-- Given modules `M`, `M₂` over a commutative ring, together with submodules `p ⊆ M`, `q ⊆ M₂`, the set of maps $\{f ∈ Hom(M, M₂) | f(p) ⊆ q \}$ is a submodule of `Hom(M, M₂)`. -/ def compatibleMaps : Submodule R (N →ₗ[R] N₂) where carrier := { fₗ | pₗ ≤ comap fₗ qₗ } zero_mem' := by simp add_mem' {f₁ f₂} h₁ h₂ := by apply le_trans _ (inf_comap_le_comap_add qₗ f₁ f₂) rw [le_inf_iff] exact ⟨h₁, h₂⟩ smul_mem' c fₗ h := by dsimp at h exact le_trans h (comap_le_comap_smul qₗ fₗ c) end Submodule namespace LinearMap variable [Semiring R] [AddCommMonoid M] [AddCommMonoid M₁] [Module R M] [Module R M₁] /-- The `LinearMap` from the preimage of a submodule to itself. This is the linear version of `AddMonoidHom.addSubmonoidComap` and `AddMonoidHom.addSubgroupComap`. -/ @[simps!] def submoduleComap (f : M →ₗ[R] M₁) (q : Submodule R M₁) : q.comap f →ₗ[R] q := f.restrict fun _ ↦ Submodule.mem_comap.1 theorem submoduleComap_surjective_of_surjective (f : M →ₗ[R] M₁) (q : Submodule R M₁) (hf : Surjective f) : Surjective (f.submoduleComap q) := fun y ↦ by obtain ⟨x, hx⟩ := hf y use ⟨x, Submodule.mem_comap.mpr (hx ▸ y.2)⟩ apply Subtype.val_injective simp [hx] /-- A linear map between two modules restricts to a linear map from any submodule p of the domain onto the image of that submodule. This is the linear version of `AddMonoidHom.addSubmonoidMap` and `AddMonoidHom.addSubgroupMap`. -/ def submoduleMap (f : M →ₗ[R] M₁) (p : Submodule R M) : p →ₗ[R] p.map f := f.restrict fun x hx ↦ Submodule.mem_map.mpr ⟨x, hx, rfl⟩ @[simp] theorem submoduleMap_coe_apply (f : M →ₗ[R] M₁) {p : Submodule R M} (x : p) : ↑(f.submoduleMap p x) = f x := rfl theorem submoduleMap_surjective (f : M →ₗ[R] M₁) (p : Submodule R M) : Function.Surjective (f.submoduleMap p) := f.toAddMonoidHom.addSubmonoidMap_surjective _ variable [Semiring R₂] [AddCommMonoid M₂] [Module R₂ M₂] {σ₂₁ : R₂ →+* R} open Submodule theorem map_codRestrict [RingHomSurjective σ₂₁] (p : Submodule R M) (f : M₂ →ₛₗ[σ₂₁] M) (h p') : Submodule.map (codRestrict p f h) p' = comap p.subtype (p'.map f) := Submodule.ext fun ⟨x, hx⟩ => by simp [Subtype.ext_iff] theorem comap_codRestrict (p : Submodule R M) (f : M₂ →ₛₗ[σ₂₁] M) (hf p') : Submodule.comap (codRestrict p f hf) p' = Submodule.comap f (map p.subtype p') := Submodule.ext fun x => ⟨fun h => ⟨⟨_, hf x⟩, h, rfl⟩, by rintro ⟨⟨_, _⟩, h, ⟨⟩⟩; exact h⟩ end LinearMap /-! ### Linear equivalences -/ namespace LinearEquiv section AddCommMonoid section variable [Semiring R] [Semiring R₂] variable [AddCommMonoid M] [AddCommMonoid M₂] variable {module_M : Module R M} {module_M₂ : Module R₂ M₂} variable {σ₁₂ : R →+* R₂} {σ₂₁ : R₂ →+* R} variable {re₁₂ : RingHomInvPair σ₁₂ σ₂₁} {re₂₁ : RingHomInvPair σ₂₁ σ₁₂} variable (e : M ≃ₛₗ[σ₁₂] M₂) @[deprecated (since := "2025-06-18")] alias map_eq_comap := Submodule.map_equiv_eq_comap_symm /-- A linear equivalence of two modules restricts to a linear equivalence from any submodule `p` of the domain onto the image of that submodule. This is the linear version of `AddEquiv.submonoidMap` and `AddEquiv.subgroupMap`. This is `LinearEquiv.ofSubmodule'` but with `map` on the right instead of `comap` on the left. -/ def submoduleMap (p : Submodule R M) : p ≃ₛₗ[σ₁₂] ↥(p.map (e : M →ₛₗ[σ₁₂] M₂) : Submodule R₂ M₂) := { ((e : M →ₛₗ[σ₁₂] M₂).domRestrict p).codRestrict (p.map (e : M →ₛₗ[σ₁₂] M₂)) fun x => ⟨x, by simp only [LinearMap.domRestrict_apply, and_true, SetLike.coe_mem, SetLike.mem_coe]⟩ with invFun := fun y => ⟨(e.symm : M₂ →ₛₗ[σ₂₁] M) y, by rcases y with ⟨y', hy⟩ rw [Submodule.mem_map] at hy rcases hy with ⟨x, hx, hxy⟩ subst hxy simp only [symm_apply_apply, coe_coe, hx]⟩ left_inv := fun x => by simp only [LinearMap.domRestrict_apply, LinearMap.codRestrict_apply, LinearMap.toFun_eq_coe, LinearEquiv.coe_coe, LinearEquiv.symm_apply_apply, SetLike.eta] right_inv := fun y => by apply SetCoe.ext simp only [LinearMap.domRestrict_apply, LinearMap.codRestrict_apply, LinearMap.toFun_eq_coe, LinearEquiv.coe_coe, LinearEquiv.apply_symm_apply] } @[simp] theorem submoduleMap_apply (p : Submodule R M) (x : p) : ↑(e.submoduleMap p x) = e x := rfl @[simp] theorem submoduleMap_symm_apply (p : Submodule R M) (x : (p.map (e : M →ₛₗ[σ₁₂] M₂) : Submodule R₂ M₂)) : ↑((e.submoduleMap p).symm x) = e.symm x := rfl end end AddCommMonoid end LinearEquiv
.lake/packages/mathlib/Mathlib/Algebra/Module/Submodule/EqLocus.lean
import Mathlib.Algebra.Module.Submodule.Ker /-! # The submodule of elements `x : M` such that `f x = g x` ## Main declarations * `LinearMap.eqLocus`: the submodule of elements `x : M` such that `f x = g x` ## Tags linear algebra, vector space, module -/ variable {R : Type*} {R₂ : Type*} variable {M : Type*} {M₂ : Type*} /-! ### Properties of linear maps -/ namespace LinearMap section AddCommMonoid variable [Semiring R] [Semiring R₂] variable [AddCommMonoid M] [AddCommMonoid M₂] variable [Module R M] [Module R₂ M₂] open Submodule variable {τ₁₂ : R →+* R₂} section variable {F : Type*} [FunLike F M M₂] [SemilinearMapClass F τ₁₂ M M₂] /-- A linear map version of `AddMonoidHom.eqLocusM` -/ def eqLocus (f g : F) : Submodule R M := { (f : M →+ M₂).eqLocusM g with carrier := { x | f x = g x } smul_mem' := fun {r} {x} (hx : _ = _) => show _ = _ by -- Note: https://github.com/leanprover-community/mathlib4/pull/8386 changed `map_smulₛₗ` into `map_smulₛₗ _` simpa only [map_smulₛₗ _] using congr_arg (τ₁₂ r • ·) hx } @[simp] theorem mem_eqLocus {x : M} {f g : F} : x ∈ eqLocus f g ↔ f x = g x := Iff.rfl theorem eqLocus_toAddSubmonoid (f g : F) : (eqLocus f g).toAddSubmonoid = (f : M →+ M₂).eqLocusM g := rfl @[simp] theorem eqLocus_eq_top {f g : F} : eqLocus f g = ⊤ ↔ f = g := by simp [SetLike.ext_iff, DFunLike.ext_iff] @[simp] theorem eqLocus_same (f : F) : eqLocus f f = ⊤ := eqLocus_eq_top.2 rfl theorem le_eqLocus {f g : F} {S : Submodule R M} : S ≤ eqLocus f g ↔ Set.EqOn f g S := Iff.rfl include τ₁₂ in theorem eqOn_sup {f g : F} {S T : Submodule R M} (hS : Set.EqOn f g S) (hT : Set.EqOn f g T) : Set.EqOn f g ↑(S ⊔ T) := by rw [← le_eqLocus] at hS hT ⊢ exact sup_le hS hT include τ₁₂ in theorem ext_on_codisjoint {f g : F} {S T : Submodule R M} (hST : Codisjoint S T) (hS : Set.EqOn f g S) (hT : Set.EqOn f g T) : f = g := DFunLike.ext _ _ fun _ ↦ eqOn_sup hS hT <| hST.eq_top.symm ▸ trivial end end AddCommMonoid section Ring variable [Ring R] [Ring R₂] variable [AddCommGroup M] [AddCommGroup M₂] variable [Module R M] [Module R₂ M₂] variable {τ₁₂ : R →+* R₂} open Submodule theorem eqLocus_eq_ker_sub (f g : M →ₛₗ[τ₁₂] M₂) : eqLocus f g = ker (f - g) := SetLike.ext fun _ => sub_eq_zero.symm end Ring end LinearMap
.lake/packages/mathlib/Mathlib/Algebra/Module/Submodule/Basic.lean
import Mathlib.Algebra.Field.Defs import Mathlib.Algebra.Group.Submonoid.BigOperators import Mathlib.Algebra.Module.Submodule.Defs import Mathlib.Algebra.NoZeroSMulDivisors.Defs import Mathlib.GroupTheory.GroupAction.SubMulAction import Mathlib.Algebra.Group.Pointwise.Set.Basic /-! # Submodules of a module This file contains basic results on submodules that require further theory to be defined. As such it is a good target for organizing and splitting further. ## Tags submodule, subspace, linear map -/ open Function universe u'' u' u v w variable {G : Type u''} {S : Type u'} {R : Type u} {M : Type v} {ι : Type w} namespace Submodule variable [Semiring R] [AddCommMonoid M] [Module R M] variable {p q : Submodule R M} @[mono] theorem toAddSubmonoid_strictMono : StrictMono (toAddSubmonoid : Submodule R M → AddSubmonoid M) := fun _ _ => id theorem toAddSubmonoid_le : p.toAddSubmonoid ≤ q.toAddSubmonoid ↔ p ≤ q := Iff.rfl @[mono] theorem toAddSubmonoid_mono : Monotone (toAddSubmonoid : Submodule R M → AddSubmonoid M) := toAddSubmonoid_strictMono.monotone @[mono] theorem toSubMulAction_strictMono : StrictMono (toSubMulAction : Submodule R M → SubMulAction R M) := fun _ _ => id @[mono] theorem toSubMulAction_mono : Monotone (toSubMulAction : Submodule R M → SubMulAction R M) := toSubMulAction_strictMono.monotone end Submodule namespace Submodule section AddCommMonoid variable [Semiring R] [AddCommMonoid M] -- We can infer the module structure implicitly from the bundled submodule, -- rather than via typeclass resolution. variable {module_M : Module R M} variable {p q : Submodule R M} variable {r : R} {x y : M} variable (p) protected theorem sum_mem {t : Finset ι} {f : ι → M} : (∀ c ∈ t, f c ∈ p) → (∑ i ∈ t, f i) ∈ p := sum_mem theorem sum_smul_mem {t : Finset ι} {f : ι → M} (r : ι → R) (hyp : ∀ c ∈ t, f c ∈ p) : (∑ i ∈ t, r i • f i) ∈ p := sum_mem fun i hi => smul_mem _ _ (hyp i hi) instance isCentralScalar [SMul S R] [SMul S M] [IsScalarTower S R M] [SMul Sᵐᵒᵖ R] [SMul Sᵐᵒᵖ M] [IsScalarTower Sᵐᵒᵖ R M] [IsCentralScalar S M] : IsCentralScalar S p := p.toSubMulAction.isCentralScalar instance noZeroSMulDivisors [NoZeroSMulDivisors R M] : NoZeroSMulDivisors R p := ⟨fun {c} {x : p} h => have : c = 0 ∨ (x : M) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h) this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩ section AddAction /-! ### Additive actions by `Submodule`s These instances transfer the action by an element `m : M` of an `R`-module `M` written as `m +ᵥ a` onto the action by an element `s : S` of a submodule `S : Submodule R M` such that `s +ᵥ a = (s : M) +ᵥ a`. These instances work particularly well in conjunction with `AddGroup.toAddAction`, enabling `s +ᵥ m` as an alias for `↑s + m`. -/ variable {α β : Type*} instance [VAdd M α] : VAdd p α := p.toAddSubmonoid.vadd instance vaddCommClass [VAdd M β] [VAdd α β] [VAddCommClass M α β] : VAddCommClass p α β := ⟨fun a => vadd_comm (a : M)⟩ instance [VAdd M α] [FaithfulVAdd M α] : FaithfulVAdd p α := ⟨fun h => Subtype.ext <| eq_of_vadd_eq_vadd h⟩ variable {p} theorem vadd_def [VAdd M α] (g : p) (m : α) : g +ᵥ m = (g : M) +ᵥ m := rfl end AddAction end AddCommMonoid section AddCommGroup variable [Ring R] [AddCommGroup M] variable {module_M : Module R M} variable (p p' : Submodule R M) variable {r : R} {x y : M} @[mono] theorem toAddSubgroup_strictMono : StrictMono (toAddSubgroup : Submodule R M → AddSubgroup M) := fun _ _ => id theorem toAddSubgroup_le : p.toAddSubgroup ≤ p'.toAddSubgroup ↔ p ≤ p' := Iff.rfl @[mono] theorem toAddSubgroup_mono : Monotone (toAddSubgroup : Submodule R M → AddSubgroup M) := toAddSubgroup_strictMono.monotone @[gcongr] protected alias ⟨_, _root_.GCongr.Submodule.toAddSubgroup_le⟩ := Submodule.toAddSubgroup_le -- See `neg_coe_set` theorem neg_coe : -(p : Set M) = p := Set.ext fun _ => p.neg_mem_iff end AddCommGroup section IsDomain variable [Ring R] [IsDomain R] variable [AddCommGroup M] [Module R M] {b : ι → M} theorem notMem_of_ortho {x : M} {N : Submodule R M} (ortho : ∀ (c : R), ∀ y ∈ N, c • x + y = (0 : M) → c = 0) : x ∉ N := by intro hx simpa using ortho (-1) x hx @[deprecated (since := "2025-05-23")] alias not_mem_of_ortho := notMem_of_ortho theorem ne_zero_of_ortho {x : M} {N : Submodule R M} (ortho : ∀ (c : R), ∀ y ∈ N, c • x + y = (0 : M) → c = 0) : x ≠ 0 := mt (fun h => show x ∈ N from h.symm ▸ N.zero_mem) (notMem_of_ortho ortho) end IsDomain end Submodule namespace Submodule variable [DivisionSemiring S] [Semiring R] [AddCommMonoid M] [Module R M] variable [SMul S R] [Module S M] [IsScalarTower S R M] variable (p : Submodule R M) {s : S} {x y : M} theorem smul_mem_iff (s0 : s ≠ 0) : s • x ∈ p ↔ x ∈ p := p.toSubMulAction.smul_mem_iff s0 end Submodule /-- Subspace of a vector space. Defined to equal `Submodule`. -/ abbrev Subspace (R : Type u) (M : Type v) [DivisionRing R] [AddCommGroup M] [Module R M] := Submodule R M
.lake/packages/mathlib/Mathlib/Algebra/Module/Submodule/Defs.lean
import Mathlib.Algebra.Group.Subgroup.Defs import Mathlib.GroupTheory.GroupAction.SubMulAction import Mathlib.Algebra.Group.Submonoid.Basic /-! # Submodules of a module In this file we define * `Submodule R M` : a subset of a `Module` `M` that contains zero and is closed with respect to addition and scalar multiplication. * `Subspace k M` : an abbreviation for `Submodule` assuming that `k` is a `Field`. ## Tags submodule, subspace, linear map -/ assert_not_exists DivisionRing open Function universe u'' u' u v w variable {G : Type u''} {S : Type u'} {R : Type u} {M : Type v} {ι : Type w} /-- A submodule of a module is one which is closed under vector operations. This is a sufficient condition for the subset of vectors in the submodule to themselves form a module. -/ structure Submodule (R : Type u) (M : Type v) [Semiring R] [AddCommMonoid M] [Module R M] : Type v extends AddSubmonoid M, SubMulAction R M /-- Reinterpret a `Submodule` as an `AddSubmonoid`. -/ add_decl_doc Submodule.toAddSubmonoid /-- Reinterpret a `Submodule` as a `SubMulAction`. -/ add_decl_doc Submodule.toSubMulAction namespace Submodule variable [Semiring R] [AddCommMonoid M] [Module R M] instance setLike : SetLike (Submodule R M) M where coe s := s.carrier coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h initialize_simps_projections Submodule (carrier → coe, as_prefix coe) @[simp] lemma carrier_eq_coe (s : Submodule R M) : s.carrier = s := rfl /-- The actual `Submodule` obtained from an element of a `SMulMemClass` and `AddSubmonoidClass`. -/ @[simps] def ofClass {S R M : Type*} [Semiring R] [AddCommMonoid M] [Module R M] [SetLike S M] [AddSubmonoidClass S M] [SMulMemClass S R M] (s : S) : Submodule R M where carrier := s add_mem' := add_mem zero_mem' := zero_mem _ smul_mem' := SMulMemClass.smul_mem /-- Construct a submodule from closure under two-element linear combinations. I.e., a nonempty set closed under two-element linear combinations is a submodule. -/ @[simps] def ofLinearComb (C : Set M) (nonempty : C.Nonempty) (linearComb : ∀ x ∈ C, ∀ y ∈ C, ∀ a b : R, a • x + b • y ∈ C) : Submodule R M where carrier := C zero_mem' := by obtain ⟨x, hx⟩ := nonempty simpa [zero_smul, add_zero] using linearComb x hx x hx 0 0 add_mem' {x y} hx hy := by simpa [one_smul] using linearComb x hx y hy 1 1 smul_mem' c x hx := by simpa using linearComb x hx x hx c 0 instance (priority := 100) : CanLift (Set M) (Submodule R M) (↑) (fun s ↦ 0 ∈ s ∧ (∀ {x y}, x ∈ s → y ∈ s → x + y ∈ s) ∧ ∀ (r : R) {x}, x ∈ s → r • x ∈ s) where prf s h := ⟨ { carrier := s zero_mem' := h.1 add_mem' := h.2.1 smul_mem' := h.2.2 }, rfl ⟩ instance addSubmonoidClass : AddSubmonoidClass (Submodule R M) M where zero_mem _ := AddSubmonoid.zero_mem' _ add_mem := AddSubsemigroup.add_mem' _ instance smulMemClass : SMulMemClass (Submodule R M) R M where smul_mem {s} c _ h := SubMulAction.smul_mem' s.toSubMulAction c h @[simp] theorem mem_toAddSubmonoid (p : Submodule R M) (x : M) : x ∈ p.toAddSubmonoid ↔ x ∈ p := Iff.rfl variable {p q : Submodule R M} @[simp] theorem mem_mk {S : AddSubmonoid M} {x : M} (h) : x ∈ (⟨S, h⟩ : Submodule R M) ↔ x ∈ S := Iff.rfl @[simp] theorem coe_set_mk (S : AddSubmonoid M) (h) : ((⟨S, h⟩ : Submodule R M) : Set M) = S := rfl @[simp] theorem eta (h) : ({p with smul_mem' := h} : Submodule R M) = p := rfl @[simp] theorem mk_le_mk {S S' : AddSubmonoid M} (h h') : (⟨S, h⟩ : Submodule R M) ≤ (⟨S', h'⟩ : Submodule R M) ↔ S ≤ S' := Iff.rfl @[ext] theorem ext (h : ∀ x, x ∈ p ↔ x ∈ q) : p = q := SetLike.ext h /-- Copy of a submodule with a new `carrier` equal to the old one. Useful to fix definitional equalities. -/ @[simps] protected def copy (p : Submodule R M) (s : Set M) (hs : s = ↑p) : Submodule R M where carrier := s zero_mem' := by simp [hs] add_mem' := hs.symm ▸ p.add_mem' smul_mem' := by simpa [hs] using p.smul_mem' theorem copy_eq (S : Submodule R M) (s : Set M) (hs : s = ↑S) : S.copy s hs = S := SetLike.coe_injective hs theorem toAddSubmonoid_injective : Injective (toAddSubmonoid : Submodule R M → AddSubmonoid M) := fun p q h => SetLike.ext'_iff.2 (show (p.toAddSubmonoid : Set M) = q from SetLike.ext'_iff.1 h) @[simp] theorem toAddSubmonoid_inj : p.toAddSubmonoid = q.toAddSubmonoid ↔ p = q := toAddSubmonoid_injective.eq_iff @[simp] theorem coe_toAddSubmonoid (p : Submodule R M) : (p.toAddSubmonoid : Set M) = p := rfl theorem toSubMulAction_injective : Injective (toSubMulAction : Submodule R M → SubMulAction R M) := fun p q h => SetLike.ext'_iff.2 (show (p.toSubMulAction : Set M) = q from SetLike.ext'_iff.1 h) theorem toSubMulAction_inj : p.toSubMulAction = q.toSubMulAction ↔ p = q := toSubMulAction_injective.eq_iff @[simp] theorem coe_toSubMulAction (p : Submodule R M) : (p.toSubMulAction : Set M) = p := rfl end Submodule namespace SMulMemClass variable [Semiring R] [AddCommMonoid M] [Module R M] {A : Type*} [SetLike A M] [AddSubmonoidClass A M] [SMulMemClass A R M] (S' : A) -- Prefer subclasses of `Module` over `SMulMemClass`. /-- A submodule of a `Module` is a `Module`. -/ instance (priority := 75) toModule : Module R S' := fast_instance% Subtype.coe_injective.module R (AddSubmonoidClass.subtype S') (SetLike.val_smul S') /-- This can't be an instance because Lean wouldn't know how to find `R`, but we can still use this to manually derive `Module` on specific types. -/ def toModule' (S R' R A : Type*) [Semiring R] [NonUnitalNonAssocSemiring A] [Module R A] [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] [SetLike S A] [AddSubmonoidClass S A] [SMulMemClass S R A] (s : S) : Module R' s := haveI : SMulMemClass S R' A := SMulMemClass.ofIsScalarTower S R' R A SMulMemClass.toModule s end SMulMemClass namespace Submodule section AddCommMonoid variable [Semiring R] [AddCommMonoid M] -- We can infer the module structure implicitly from the bundled submodule, -- rather than via typeclass resolution. variable {module_M : Module R M} variable {p q : Submodule R M} variable {r : R} {x y : M} variable (p) theorem mem_carrier : x ∈ p.carrier ↔ x ∈ (p : Set M) := Iff.rfl protected theorem zero_mem : (0 : M) ∈ p := zero_mem _ protected theorem add_mem (h₁ : x ∈ p) (h₂ : y ∈ p) : x + y ∈ p := add_mem h₁ h₂ theorem smul_mem (r : R) (h : x ∈ p) : r • x ∈ p := p.smul_mem' r h theorem smul_of_tower_mem [SMul S R] [SMul S M] [IsScalarTower S R M] (r : S) (h : x ∈ p) : r • x ∈ p := p.toSubMulAction.smul_of_tower_mem r h @[simp] theorem smul_mem_iff' [Group G] [MulAction G M] [SMul G R] [IsScalarTower G R M] (g : G) : g • x ∈ p ↔ x ∈ p := p.toSubMulAction.smul_mem_iff' g @[simp] lemma smul_mem_iff'' [Invertible r] : r • x ∈ p ↔ x ∈ p := by refine ⟨fun h ↦ ?_, p.smul_mem r⟩ rw [← invOf_smul_smul r x] exact p.smul_mem _ h lemma smul_mem_iff_of_isUnit (hr : IsUnit r) : r • x ∈ p ↔ x ∈ p := let _ : Invertible r := hr.invertible smul_mem_iff'' p instance add : Add p := ⟨fun x y => ⟨x.1 + y.1, add_mem x.2 y.2⟩⟩ instance zero : Zero p := ⟨⟨0, zero_mem _⟩⟩ instance inhabited : Inhabited p := ⟨0⟩ instance smul [SMul S R] [SMul S M] [IsScalarTower S R M] : SMul S p := ⟨fun c x => ⟨c • x.1, smul_of_tower_mem _ c x.2⟩⟩ instance isScalarTower [SMul S R] [SMul S M] [IsScalarTower S R M] : IsScalarTower S R p := p.toSubMulAction.isScalarTower instance isScalarTower' {S' : Type*} [SMul S R] [SMul S M] [SMul S' R] [SMul S' M] [SMul S S'] [IsScalarTower S' R M] [IsScalarTower S S' M] [IsScalarTower S R M] : IsScalarTower S S' p := p.toSubMulAction.isScalarTower' protected theorem nonempty : (p : Set M).Nonempty := ⟨0, p.zero_mem⟩ @[simp] theorem mk_eq_zero {x} (h : x ∈ p) : (⟨x, h⟩ : p) = 0 ↔ x = 0 := Subtype.ext_iff variable {p} @[norm_cast] theorem coe_eq_zero {x : p} : (x : M) = 0 ↔ x = 0 := (SetLike.coe_eq_coe : (x : M) = (0 : p) ↔ x = 0) @[simp, norm_cast] theorem coe_add (x y : p) : (↑(x + y) : M) = ↑x + ↑y := rfl @[simp, norm_cast] theorem coe_zero : ((0 : p) : M) = 0 := rfl @[norm_cast] theorem coe_smul (r : R) (x : p) : ((r • x : p) : M) = r • (x : M) := rfl @[simp, norm_cast] theorem coe_smul_of_tower [SMul S R] [SMul S M] [IsScalarTower S R M] (r : S) (x : p) : ((r • x : p) : M) = r • (x : M) := rfl @[norm_cast] theorem coe_mk (x : M) (hx : x ∈ p) : ((⟨x, hx⟩ : p) : M) = x := rfl theorem coe_mem (x : p) : (x : M) ∈ p := x.2 variable (p) instance addCommMonoid : AddCommMonoid p := fast_instance% { p.toAddSubmonoid.toAddCommMonoid with } instance module' [Semiring S] [SMul S R] [Module S M] [IsScalarTower S R M] : Module S p := fast_instance% { (show MulAction S p from p.toSubMulAction.mulAction') with smul_zero := fun a => by ext; simp zero_smul := fun a => by ext; simp add_smul := fun a b x => by ext; simp [add_smul] smul_add := fun a x y => by ext; simp [smul_add] } instance module : Module R p := p.module' end AddCommMonoid section AddCommGroup variable [Ring R] [AddCommGroup M] variable {module_M : Module R M} variable (p p' : Submodule R M) variable {r : R} {x y : M} instance addSubgroupClass [Module R M] : AddSubgroupClass (Submodule R M) M := { Submodule.addSubmonoidClass with neg_mem := fun p {_} => p.toSubMulAction.neg_mem } protected theorem neg_mem (hx : x ∈ p) : -x ∈ p := neg_mem hx /-- Reinterpret a submodule as an additive subgroup. -/ def toAddSubgroup : AddSubgroup M := { p.toAddSubmonoid with neg_mem' := fun {_} => p.neg_mem } @[simp] theorem coe_toAddSubgroup : (p.toAddSubgroup : Set M) = p := rfl @[simp] theorem mem_toAddSubgroup : x ∈ p.toAddSubgroup ↔ x ∈ p := Iff.rfl theorem toAddSubgroup_injective : Injective (toAddSubgroup : Submodule R M → AddSubgroup M) | _, _, h => SetLike.ext (SetLike.ext_iff.1 h :) @[simp] theorem toAddSubgroup_inj : p.toAddSubgroup = p'.toAddSubgroup ↔ p = p' := toAddSubgroup_injective.eq_iff protected theorem sub_mem : x ∈ p → y ∈ p → x - y ∈ p := sub_mem protected theorem neg_mem_iff : -x ∈ p ↔ x ∈ p := neg_mem_iff protected theorem add_mem_iff_left : y ∈ p → (x + y ∈ p ↔ x ∈ p) := add_mem_cancel_right protected theorem add_mem_iff_right : x ∈ p → (x + y ∈ p ↔ y ∈ p) := add_mem_cancel_left protected theorem coe_neg (x : p) : ((-x : p) : M) = -x := NegMemClass.coe_neg _ protected theorem coe_sub (x y : p) : (↑(x - y) : M) = ↑x - ↑y := AddSubgroupClass.coe_sub _ _ theorem sub_mem_iff_left (hy : y ∈ p) : x - y ∈ p ↔ x ∈ p := by rw [sub_eq_add_neg, p.add_mem_iff_left (p.neg_mem hy)] theorem sub_mem_iff_right (hx : x ∈ p) : x - y ∈ p ↔ y ∈ p := by rw [sub_eq_add_neg, p.add_mem_iff_right hx, p.neg_mem_iff] instance addCommGroup : AddCommGroup p := fast_instance% { p.toAddSubgroup.toAddCommGroup with } end AddCommGroup end Submodule namespace SubmoduleClass instance (priority := 75) module' {T : Type*} [Semiring R] [AddCommMonoid M] [Semiring S] [Module R M] [SMul S R] [Module S M] [IsScalarTower S R M] [SetLike T M] [AddSubmonoidClass T M] [SMulMemClass T R M] (t : T) : Module S t where one_smul _ := by ext; simp mul_smul _ _ _ := by ext; simp [mul_smul] smul_zero _ := by ext; simp zero_smul _ := by ext; simp add_smul _ _ _ := by ext; simp [add_smul] smul_add _ _ _ := by ext; simp [smul_add] instance (priority := 75) module [Semiring R] [AddCommMonoid M] [Module R M] [SetLike S M] [AddSubmonoidClass S M] [SMulMemClass S R M] (s : S) : Module R s := module' s end SubmoduleClass
.lake/packages/mathlib/Mathlib/Algebra/Module/Submodule/LinearMap.lean
import Mathlib.Algebra.Module.LinearMap.End import Mathlib.Algebra.Module.Submodule.Defs import Mathlib.Algebra.BigOperators.Group.Finset.Defs /-! # Linear maps involving submodules of a module In this file we define a number of linear maps involving submodules of a module. ## Main declarations * `Submodule.subtype`: Embedding of a submodule `p` to the ambient space `M` as a `Submodule`. * `LinearMap.domRestrict`: The restriction of a semilinear map `f : M → M₂` to a submodule `p ⊆ M` as a semilinear map `p → M₂`. * `LinearMap.restrict`: The restriction of a linear map `f : M → M₁` to a submodule `p ⊆ M` and `q ⊆ M₁` (if `q` contains the codomain). * `Submodule.inclusion`: the inclusion `p ⊆ p'` of submodules `p` and `p'` as a linear map. ## Tags submodule, subspace, linear map -/ open Function Set universe u'' u' u v w section variable {G : Type u''} {S : Type u'} {R : Type u} {M : Type v} {ι : Type w} namespace SMulMemClass variable [Semiring R] [AddCommMonoid M] [Module R M] {A : Type*} [SetLike A M] [AddSubmonoidClass A M] [SMulMemClass A R M] (S' : A) /-- The natural `R`-linear map from a submodule of an `R`-module `M` to `M`. -/ protected def subtype : S' →ₗ[R] M where toFun := Subtype.val map_add' _ _ := rfl map_smul' _ _ := rfl variable {S'} in @[simp] lemma subtype_apply (x : S') : SMulMemClass.subtype S' x = x := rfl lemma subtype_injective : Function.Injective (SMulMemClass.subtype S') := Subtype.coe_injective @[simp] protected theorem coe_subtype : (SMulMemClass.subtype S' : S' → M) = Subtype.val := rfl end SMulMemClass namespace Submodule section AddCommMonoid variable [Semiring R] [AddCommMonoid M] -- We can infer the module structure implicitly from the bundled submodule, -- rather than via typeclass resolution. variable {module_M : Module R M} variable {p q : Submodule R M} variable {r : R} {x y : M} variable (p) /-- Embedding of a submodule `p` to the ambient space `M`. -/ protected def subtype : p →ₗ[R] M where toFun := Subtype.val map_add' := by simp map_smul' := by simp variable {p} in @[simp] theorem subtype_apply (x : p) : p.subtype x = x := rfl lemma subtype_injective : Function.Injective p.subtype := Subtype.coe_injective @[simp] theorem coe_subtype : (Submodule.subtype p : p → M) = Subtype.val := rfl theorem injective_subtype : Injective p.subtype := Subtype.coe_injective /-- Note the `AddSubmonoid` version of this lemma is called `AddSubmonoid.coe_finset_sum`. -/ theorem coe_sum (x : ι → p) (s : Finset ι) : ↑(∑ i ∈ s, x i) = ∑ i ∈ s, (x i : M) := map_sum p.subtype _ _ section AddAction variable {α β : Type*} /-- The action by a submodule is the action by the underlying module. -/ instance [AddAction M α] : AddAction p α := AddAction.compHom _ p.subtype.toAddMonoidHom end AddAction end AddCommMonoid end Submodule end section variable {R : Type*} {R₁ : Type*} {R₂ : Type*} {R₃ : Type*} variable {M : Type*} {M₁ : Type*} {M₂ : Type*} {M₃ : Type*} variable {ι : Type*} namespace LinearMap section AddCommMonoid variable [Semiring R] [Semiring R₂] [Semiring R₃] variable [AddCommMonoid M] [AddCommMonoid M₁] [AddCommMonoid M₂] [AddCommMonoid M₃] variable [Module R M] [Module R M₁] [Module R₂ M₂] [Module R₃ M₃] variable {σ₁₂ : R →+* R₂} {σ₂₃ : R₂ →+* R₃} {σ₁₃ : R →+* R₃} [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃] variable (f : M →ₛₗ[σ₁₂] M₂) (g : M₂ →ₛₗ[σ₂₃] M₃) /-- The restriction of a linear map `f : M → M₂` to a submodule `p ⊆ M` gives a linear map `p → M₂`. -/ def domRestrict (f : M →ₛₗ[σ₁₂] M₂) (p : Submodule R M) : p →ₛₗ[σ₁₂] M₂ := f.comp p.subtype @[simp] theorem domRestrict_apply (f : M →ₛₗ[σ₁₂] M₂) (p : Submodule R M) (x : p) : f.domRestrict p x = f x := rfl lemma coe_domRestrict (f : M →ₛₗ[σ₁₂] M₂) (p : Submodule R M) : ⇑(f.domRestrict p) = Set.restrict p f := rfl /-- A linear map `f : M₂ → M` whose values lie in a submodule `p ⊆ M` can be restricted to a linear map M₂ → p. See also `LinearMap.codLift`. -/ def codRestrict (p : Submodule R₂ M₂) (f : M →ₛₗ[σ₁₂] M₂) (h : ∀ c, f c ∈ p) : M →ₛₗ[σ₁₂] p where toFun c := ⟨f c, h c⟩ map_add' _ _ := by simp map_smul' _ _ := by simp @[simp] theorem codRestrict_apply (p : Submodule R₂ M₂) (f : M →ₛₗ[σ₁₂] M₂) {h} (x : M) : (codRestrict p f h x : M₂) = f x := rfl @[simp] theorem comp_codRestrict (p : Submodule R₃ M₃) (h : ∀ b, g b ∈ p) : ((codRestrict p g h).comp f : M →ₛₗ[σ₁₃] p) = codRestrict p (g.comp f) fun _ => h _ := ext fun _ => rfl @[simp] theorem subtype_comp_codRestrict (p : Submodule R₂ M₂) (h : ∀ b, f b ∈ p) : p.subtype.comp (codRestrict p f h) = f := ext fun _ => rfl section variable {M₂' : Type*} [AddCommMonoid M₂'] [Module R₂ M₂'] (p : M₂' →ₗ[R₂] M₂) (hp : Injective p) (h : ∀ c, f c ∈ range p) /-- A linear map `f : M → M₂` whose values lie in the image of an injective linear map `p : M₂' → M₂` admits a unique lift to a linear map `M → M₂'`. -/ noncomputable def codLift : M →ₛₗ[σ₁₂] M₂' where toFun c := (h c).choose map_add' b c := by apply hp; simp_rw [map_add, (h _).choose_spec, ← map_add, (h _).choose_spec] map_smul' r c := by apply hp; simp_rw [map_smul, (h _).choose_spec, LinearMap.map_smulₛₗ] @[simp] theorem codLift_apply (x : M) : (f.codLift p hp h x) = (h x).choose := rfl @[simp] theorem comp_codLift : p.comp (f.codLift p hp h) = f := by ext x rw [comp_apply, codLift_apply, (h x).choose_spec] end /-- Restrict domain and codomain of a linear map. -/ def restrict (f : M →ₗ[R] M₁) {p : Submodule R M} {q : Submodule R M₁} (hf : ∀ x ∈ p, f x ∈ q) : p →ₗ[R] q := (f.domRestrict p).codRestrict q <| SetLike.forall.2 hf @[simp] theorem restrict_coe_apply (f : M →ₗ[R] M₁) {p : Submodule R M} {q : Submodule R M₁} (hf : ∀ x ∈ p, f x ∈ q) (x : p) : ↑(f.restrict hf x) = f x := rfl theorem restrict_apply {f : M →ₗ[R] M₁} {p : Submodule R M} {q : Submodule R M₁} (hf : ∀ x ∈ p, f x ∈ q) (x : p) : f.restrict hf x = ⟨f x, hf x.1 x.2⟩ := rfl lemma restrict_sub {R M M₁ : Type*} [Ring R] [AddCommGroup M] [AddCommGroup M₁] [Module R M] [Module R M₁] {p : Submodule R M} {q : Submodule R M₁} {f g : M →ₗ[R] M₁} (hf : MapsTo f p q) (hg : MapsTo g p q) (hfg : MapsTo (f - g) p q := fun _ hx ↦ q.sub_mem (hf hx) (hg hx)) : f.restrict hf - g.restrict hg = (f - g).restrict hfg := by ext; simp lemma restrict_comp {M₂ M₃ : Type*} [AddCommMonoid M₂] [AddCommMonoid M₃] [Module R M₂] [Module R M₃] {p : Submodule R M} {p₂ : Submodule R M₂} {p₃ : Submodule R M₃} {f : M →ₗ[R] M₂} {g : M₂ →ₗ[R] M₃} (hf : MapsTo f p p₂) (hg : MapsTo g p₂ p₃) (hfg : MapsTo (g ∘ₗ f) p p₃ := hg.comp hf) : (g ∘ₗ f).restrict hfg = (g.restrict hg) ∘ₗ (f.restrict hf) := rfl -- TODO Consider defining `Algebra R (p.compatibleMaps p)`, `AlgHom` version of `LinearMap.restrict` lemma restrict_smul_one {R M : Type*} [CommSemiring R] [AddCommMonoid M] [Module R M] {p : Submodule R M} (μ : R) (h : ∀ x ∈ p, (μ • (1 : Module.End R M)) x ∈ p := fun _ ↦ p.smul_mem μ) : (μ • 1 : Module.End R M).restrict h = μ • (1 : Module.End R p) := rfl lemma restrict_commute {f g : M →ₗ[R] M} (h : Commute f g) {p : Submodule R M} (hf : MapsTo f p p) (hg : MapsTo g p p) : Commute (f.restrict hf) (g.restrict hg) := by change (f ∘ₗ g).restrict (hf.comp hg) = (g ∘ₗ f).restrict (hg.comp hf) congr 1 theorem subtype_comp_restrict {f : M →ₗ[R] M₁} {p : Submodule R M} {q : Submodule R M₁} (hf : ∀ x ∈ p, f x ∈ q) : q.subtype.comp (f.restrict hf) = f.domRestrict p := rfl theorem restrict_eq_codRestrict_domRestrict {f : M →ₗ[R] M₁} {p : Submodule R M} {q : Submodule R M₁} (hf : ∀ x ∈ p, f x ∈ q) : f.restrict hf = (f.domRestrict p).codRestrict q fun x => hf x.1 x.2 := rfl theorem restrict_eq_domRestrict_codRestrict {f : M →ₗ[R] M₁} {p : Submodule R M} {q : Submodule R M₁} (hf : ∀ x, f x ∈ q) : (f.restrict fun x _ => hf x) = (f.codRestrict q hf).domRestrict p := rfl theorem sum_apply (t : Finset ι) (f : ι → M →ₛₗ[σ₁₂] M₂) (b : M) : (∑ d ∈ t, f d) b = ∑ d ∈ t, f d b := _root_.map_sum ((AddMonoidHom.eval b).comp toAddMonoidHom') f _ @[simp, norm_cast] theorem coeFn_sum {ι : Type*} (t : Finset ι) (f : ι → M →ₛₗ[σ₁₂] M₂) : ⇑(∑ i ∈ t, f i) = ∑ i ∈ t, (f i : M → M₂) := _root_.map_sum (show AddMonoidHom (M →ₛₗ[σ₁₂] M₂) (M → M₂) from { toFun := DFunLike.coe, map_zero' := rfl map_add' := fun _ _ => rfl }) _ _ theorem _root_.Module.End.submodule_pow_eq_zero_of_pow_eq_zero {N : Submodule R M} {g : Module.End R N} {G : Module.End R M} (h : G.comp N.subtype = N.subtype.comp g) {k : ℕ} (hG : G ^ k = 0) : g ^ k = 0 := by ext m have hg : N.subtype.comp (g ^ k) m = 0 := by rw [← Module.End.commute_pow_left_of_commute h, hG, zero_comp, zero_apply] simpa using hg section variable {f' : M →ₗ[R] M} theorem _root_.Module.End.pow_apply_mem_of_forall_mem {p : Submodule R M} (n : ℕ) (h : ∀ x ∈ p, f' x ∈ p) (x : M) (hx : x ∈ p) : (f' ^ n) x ∈ p := by induction n generalizing x with | zero => simpa | succ n ih => simpa only [iterate_succ, coe_comp, Function.comp_apply, restrict_apply] using ih _ (h _ hx) theorem _root_.Module.End.pow_restrict {p : Submodule R M} (n : ℕ) (h : ∀ x ∈ p, f' x ∈ p) (h' := Module.End.pow_apply_mem_of_forall_mem n h) : (f'.restrict h) ^ n = (f' ^ n).restrict h' := by ext x have : Semiconj (↑) (f'.restrict h) f' := fun _ ↦ restrict_coe_apply _ _ _ simp [Module.End.coe_pow, this.iterate_right _ _] end end AddCommMonoid section CommSemiring variable [CommSemiring R] [AddCommMonoid M] [AddCommMonoid M₂] variable [Module R M] [Module R M₂] variable (f g : M →ₗ[R] M₂) /-- Alternative version of `domRestrict` as a linear map. -/ def domRestrict' (p : Submodule R M) : (M →ₗ[R] M₂) →ₗ[R] p →ₗ[R] M₂ where toFun φ := φ.domRestrict p map_add' := by simp [LinearMap.ext_iff] map_smul' := by simp [LinearMap.ext_iff] @[simp] theorem domRestrict'_apply (f : M →ₗ[R] M₂) (p : Submodule R M) (x : p) : domRestrict' p f x = f x := rfl end CommSemiring end LinearMap end namespace Submodule section AddCommMonoid variable {R : Type*} {M : Type*} [Semiring R] [AddCommMonoid M] [Module R M] {p p' : Submodule R M} /-- If two submodules `p` and `p'` satisfy `p ⊆ p'`, then `inclusion p p'` is the linear map version of this inclusion. -/ def inclusion (h : p ≤ p') : p →ₗ[R] p' := p.subtype.codRestrict p' fun ⟨_, hx⟩ => h hx @[simp] theorem coe_inclusion (h : p ≤ p') (x : p) : (inclusion h x : M) = x := rfl theorem inclusion_apply (h : p ≤ p') (x : p) : inclusion h x = ⟨x, h x.2⟩ := rfl theorem inclusion_injective (h : p ≤ p') : Function.Injective (inclusion h) := fun _ _ h => Subtype.val_injective (Subtype.mk.inj h) variable (p p') theorem subtype_comp_inclusion (p q : Submodule R M) (h : p ≤ q) : q.subtype.comp (inclusion h) = p.subtype := rfl end AddCommMonoid end Submodule
.lake/packages/mathlib/Mathlib/Algebra/Module/Submodule/Equiv.lean
import Mathlib.Algebra.Module.Submodule.Range /-! ### Linear equivalences involving submodules -/ open Function variable {R : Type*} {R₁ : Type*} {R₂ : Type*} {R₃ : Type*} variable {M : Type*} {M₁ : Type*} {M₂ : Type*} {M₃ : Type*} variable {N : Type*} namespace LinearEquiv section AddCommMonoid section variable [Semiring R] [Semiring R₂] [Semiring R₃] variable [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] variable {module_M : Module R M} {module_M₂ : Module R₂ M₂} {module_M₃ : Module R₃ M₃} variable {σ₁₂ : R →+* R₂} {σ₂₁ : R₂ →+* R} variable {σ₂₃ : R₂ →+* R₃} {σ₁₃ : R →+* R₃} [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃] variable {σ₃₂ : R₃ →+* R₂} variable {re₁₂ : RingHomInvPair σ₁₂ σ₂₁} {re₂₁ : RingHomInvPair σ₂₁ σ₁₂} variable {re₂₃ : RingHomInvPair σ₂₃ σ₃₂} {re₃₂ : RingHomInvPair σ₃₂ σ₂₃} variable (f : M →ₛₗ[σ₁₂] M₂) (g : M₂ →ₛₗ[σ₂₁] M) (e : M ≃ₛₗ[σ₁₂] M₂) (h : M₂ →ₛₗ[σ₂₃] M₃) variable (p q : Submodule R M) /-- Linear equivalence between two equal submodules. -/ def ofEq (h : p = q) : p ≃ₗ[R] q := { Equiv.setCongr (congr_arg _ h) with map_smul' := fun _ _ => rfl map_add' := fun _ _ => rfl } variable {p q} @[simp] theorem coe_ofEq_apply (h : p = q) (x : p) : (ofEq p q h x : M) = x := rfl @[simp] theorem ofEq_symm (h : p = q) : (ofEq p q h).symm = ofEq q p h.symm := rfl @[simp] theorem ofEq_rfl : ofEq p p rfl = LinearEquiv.refl R p := by ext; rfl /-- A linear equivalence which maps a submodule of one module onto another, restricts to a linear equivalence of the two submodules. -/ def ofSubmodules (p : Submodule R M) (q : Submodule R₂ M₂) (h : p.map (e : M →ₛₗ[σ₁₂] M₂) = q) : p ≃ₛₗ[σ₁₂] q := (e.submoduleMap p).trans (LinearEquiv.ofEq _ _ h) @[simp] theorem ofSubmodules_apply {p : Submodule R M} {q : Submodule R₂ M₂} (h : p.map ↑e = q) (x : p) : ↑(e.ofSubmodules p q h x) = e x := rfl @[simp] theorem ofSubmodules_symm_apply {p : Submodule R M} {q : Submodule R₂ M₂} (h : p.map ↑e = q) (x : q) : ↑((e.ofSubmodules p q h).symm x) = e.symm x := rfl /-- A linear equivalence of two modules restricts to a linear equivalence from the preimage of any submodule to that submodule. This is `LinearEquiv.ofSubmodule` but with `comap` on the left instead of `map` on the right. -/ def ofSubmodule' [Module R M] [Module R₂ M₂] (f : M ≃ₛₗ[σ₁₂] M₂) (U : Submodule R₂ M₂) : U.comap (f : M →ₛₗ[σ₁₂] M₂) ≃ₛₗ[σ₁₂] U := (f.symm.ofSubmodules _ _ (U.map_equiv_eq_comap_symm f.symm)).symm theorem ofSubmodule'_toLinearMap [Module R M] [Module R₂ M₂] (f : M ≃ₛₗ[σ₁₂] M₂) (U : Submodule R₂ M₂) : (f.ofSubmodule' U).toLinearMap = (f.toLinearMap.domRestrict _).codRestrict _ Subtype.prop := by ext rfl @[simp] theorem ofSubmodule'_apply [Module R M] [Module R₂ M₂] (f : M ≃ₛₗ[σ₁₂] M₂) (U : Submodule R₂ M₂) (x : U.comap (f : M →ₛₗ[σ₁₂] M₂)) : (f.ofSubmodule' U x : M₂) = f (x : M) := rfl @[simp] theorem ofSubmodule'_symm_apply [Module R M] [Module R₂ M₂] (f : M ≃ₛₗ[σ₁₂] M₂) (U : Submodule R₂ M₂) (x : U) : ((f.ofSubmodule' U).symm x : M) = f.symm (x : M₂) := rfl variable (p) /-- The top submodule of `M` is linearly equivalent to `M`. -/ def ofTop (h : p = ⊤) : p ≃ₗ[R] M := { p.subtype with invFun := fun x => ⟨x, h.symm ▸ trivial⟩ } @[simp] theorem ofTop_apply {h} (x : p) : ofTop p h x = x := rfl @[simp] theorem coe_ofTop_symm_apply {h} (x : M) : ((ofTop p h).symm x : M) = x := rfl theorem ofTop_symm_apply {h} (x : M) : (ofTop p h).symm x = ⟨x, h.symm ▸ trivial⟩ := rfl @[simp] protected theorem range : LinearMap.range (e : M →ₛₗ[σ₁₂] M₂) = ⊤ := LinearMap.range_eq_top.2 e.toEquiv.surjective @[simp] protected theorem _root_.LinearEquivClass.range [Module R M] [Module R₂ M₂] {F : Type*} [EquivLike F M M₂] [SemilinearEquivClass F σ₁₂ M M₂] (e : F) : LinearMap.range e = ⊤ := LinearMap.range_eq_top.2 (EquivLike.surjective e) theorem eq_bot_of_equiv [Module R₂ M₂] (e : p ≃ₛₗ[σ₁₂] (⊥ : Submodule R₂ M₂)) : p = ⊥ := by refine bot_unique (SetLike.le_def.2 fun b hb => (Submodule.mem_bot R).2 ?_) rw [← p.mk_eq_zero hb, ← e.map_eq_zero_iff] apply Submodule.eq_zero_of_bot_submodule @[simp] theorem range_comp [RingHomSurjective σ₂₃] [RingHomSurjective σ₁₃] : LinearMap.range (h.comp (e : M →ₛₗ[σ₁₂] M₂) : M →ₛₗ[σ₁₃] M₃) = LinearMap.range h := LinearMap.range_comp_of_range_eq_top _ e.range variable {f g} /-- A linear map `f : M →ₗ[R] M₂` with a left-inverse `g : M₂ →ₗ[R] M` defines a linear equivalence between `M` and `f.range`. This is a computable alternative to `LinearEquiv.ofInjective`, and a bidirectional version of `LinearMap.rangeRestrict`. -/ def ofLeftInverse [RingHomInvPair σ₁₂ σ₂₁] [RingHomInvPair σ₂₁ σ₁₂] {g : M₂ → M} (h : Function.LeftInverse g f) : M ≃ₛₗ[σ₁₂] (LinearMap.range f) := { LinearMap.rangeRestrict f with toFun := LinearMap.rangeRestrict f invFun := g ∘ (LinearMap.range f).subtype left_inv := h right_inv := fun x => Subtype.ext <| let ⟨x', hx'⟩ := LinearMap.mem_range.mp x.prop show f (g x) = x by rw [← hx', h x'] } @[simp] theorem ofLeftInverse_apply [RingHomInvPair σ₁₂ σ₂₁] [RingHomInvPair σ₂₁ σ₁₂] (h : Function.LeftInverse g f) (x : M) : ↑(ofLeftInverse h x) = f x := rfl @[simp] theorem ofLeftInverse_symm_apply [RingHomInvPair σ₁₂ σ₂₁] [RingHomInvPair σ₂₁ σ₁₂] (h : Function.LeftInverse g f) (x : LinearMap.range f) : (ofLeftInverse h).symm x = g x := rfl variable (f) /-- An `Injective` linear map `f : M →ₗ[R] M₂` defines a linear equivalence between `M` and `f.range`. See also `LinearMap.ofLeftInverse`. -/ noncomputable def ofInjective [RingHomInvPair σ₁₂ σ₂₁] [RingHomInvPair σ₂₁ σ₁₂] (h : Injective f) : M ≃ₛₗ[σ₁₂] LinearMap.range f := ofLeftInverse <| Classical.choose_spec h.hasLeftInverse @[simp] theorem ofInjective_apply [RingHomInvPair σ₁₂ σ₂₁] [RingHomInvPair σ₂₁ σ₁₂] {h : Injective f} (x : M) : ↑(ofInjective f h x) = f x := rfl @[simp] lemma ofInjective_symm_apply [RingHomInvPair σ₁₂ σ₂₁] [RingHomInvPair σ₂₁ σ₁₂] {h : Injective f} (x : LinearMap.range f) : f ((ofInjective f h).symm x) = x := by obtain ⟨-, ⟨y, rfl⟩⟩ := x have : ⟨f y, LinearMap.mem_range_self f y⟩ = LinearEquiv.ofInjective f h y := rfl simp [this] /-- A bijective linear map is a linear equivalence. -/ noncomputable def ofBijective [RingHomInvPair σ₁₂ σ₂₁] [RingHomInvPair σ₂₁ σ₁₂] (hf : Bijective f) : M ≃ₛₗ[σ₁₂] M₂ := (ofInjective f hf.injective).trans <| ofTop _ <| LinearMap.range_eq_top.2 hf.surjective @[simp] theorem ofBijective_apply [RingHomInvPair σ₁₂ σ₂₁] [RingHomInvPair σ₂₁ σ₁₂] {hf} (x : M) : ofBijective f hf x = f x := rfl @[simp] theorem ofBijective_symm_apply_apply [RingHomInvPair σ₁₂ σ₂₁] [RingHomInvPair σ₂₁ σ₁₂] {h} (x : M) : (ofBijective f h).symm (f x) = x := by simp [LinearEquiv.symm_apply_eq] @[simp] theorem apply_ofBijective_symm_apply [RingHomInvPair σ₁₂ σ₂₁] [RingHomInvPair σ₂₁ σ₁₂] {h} (x : M₂) : f ((ofBijective f h).symm x) = x := by rw [← ofBijective_apply f (hf := h) ((ofBijective f h).symm x), apply_symm_apply] end end AddCommMonoid end LinearEquiv namespace Submodule section Module variable [Semiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N] /-- Given `p` a submodule of the module `M` and `q` a submodule of `p`, `p.equivSubtypeMap q` is the natural `LinearEquiv` between `q` and `q.map p.subtype`. -/ def equivSubtypeMap (p : Submodule R M) (q : Submodule R p) : q ≃ₗ[R] q.map p.subtype := { (p.subtype.domRestrict q).codRestrict _ (by rintro ⟨x, hx⟩; exact ⟨x, hx, rfl⟩) with invFun := by rintro ⟨x, hx⟩ refine ⟨⟨x, ?_⟩, ?_⟩ <;> rcases hx with ⟨⟨_, h⟩, _, rfl⟩ <;> assumption } @[simp] theorem equivSubtypeMap_apply {p : Submodule R M} {q : Submodule R p} (x : q) : (p.equivSubtypeMap q x : M) = p.subtype.domRestrict q x := rfl @[simp] theorem equivSubtypeMap_symm_apply {p : Submodule R M} {q : Submodule R p} (x : q.map p.subtype) : ((p.equivSubtypeMap q).symm x : M) = x := rfl /-- A linear injection `M ↪ N` restricts to an equivalence `f⁻¹ p ≃ p` for any submodule `p` contained in its range. -/ @[simps! apply] noncomputable def comap_equiv_self_of_inj_of_le {f : M →ₗ[R] N} {p : Submodule R N} (hf : Injective f) (h : p ≤ LinearMap.range f) : p.comap f ≃ₗ[R] p := LinearEquiv.ofBijective ((f ∘ₗ (p.comap f).subtype).codRestrict p <| fun ⟨_, hx⟩ ↦ mem_comap.mp hx) (⟨fun x y hxy ↦ by simpa using hf (Subtype.ext_iff.mp hxy), fun ⟨x, hx⟩ ↦ by obtain ⟨y, rfl⟩ := h hx; exact ⟨⟨y, hx⟩, by simp [Subtype.ext_iff]⟩⟩) end Module end Submodule namespace LinearMap variable [CommSemiring R] [AddCommMonoid M] [AddCommMonoid M₁] [AddCommMonoid M₂] [AddCommMonoid M₃] [Module R M] [Module R M₁] [Module R M₂] [Module R M₃] section variable (f : M₁ →ₗ[R] M₂) (i : M₃ →ₗ[R] M₂) (hi : Injective i) (hf : ∀ x, f x ∈ LinearMap.range i) /-- The restriction of a linear map on the target to a submodule of the target given by an inclusion. -/ noncomputable def codRestrictOfInjective : M₁ →ₗ[R] M₃ := (LinearEquiv.ofInjective i hi).symm ∘ₗ f.codRestrict (LinearMap.range i) hf @[simp] lemma codRestrictOfInjective_comp_apply (x : M₁) : i (LinearMap.codRestrictOfInjective f i hi hf x) = f x := by simp [LinearMap.codRestrictOfInjective] @[simp] lemma codRestrictOfInjective_comp : i ∘ₗ LinearMap.codRestrictOfInjective f i hi hf = f := by ext simp end variable (f : M₁ →ₗ[R] M₂ →ₗ[R] M) (i : M₃ →ₗ[R] M) (hi : Injective i) (hf : ∀ x y, f x y ∈ LinearMap.range i) /-- The restriction of a bilinear map to a submodule in which it takes values. -/ noncomputable def codRestrict₂ : M₁ →ₗ[R] M₂ →ₗ[R] M₃ := let e : LinearMap.range i ≃ₗ[R] M₃ := (LinearEquiv.ofInjective i hi).symm { toFun := fun x ↦ e.comp <| (f x).codRestrict (p := LinearMap.range i) (hf x) map_add' := by intro x₁ x₂; ext y; simp [f.map_add, ← e.map_add, codRestrict] map_smul' := by intro t x; ext y; simp [f.map_smul, ← e.map_smul, codRestrict] } @[simp] lemma codRestrict₂_apply (x : M₁) (y : M₂) : i (codRestrict₂ f i hi hf x y) = f x y := by simp [codRestrict₂] end LinearMap
.lake/packages/mathlib/Mathlib/Algebra/Module/Submodule/Range.lean
import Mathlib.Algebra.Module.Submodule.Ker import Mathlib.Algebra.Module.Submodule.RestrictScalars import Mathlib.Data.Set.Finite.Range /-! # Range of linear maps The range `LinearMap.range` of a (semi)linear map `f : M → M₂` is a submodule of `M₂`. More specifically, `LinearMap.range` applies to any `SemilinearMapClass` over a `RingHomSurjective` ring homomorphism. Note that this also means that dot notation (i.e. `f.range` for a linear map `f`) does not work. ## Notation * We continue to use the notations `M →ₛₗ[σ] M₂` and `M →ₗ[R] M₂` for the type of semilinear (resp. linear) maps from `M` to `M₂` over the ring homomorphism `σ` (resp. over the ring `R`). ## Tags linear algebra, vector space, module, range -/ open Function variable {R : Type*} {R₂ : Type*} {R₃ : Type*} variable {K : Type*} variable {M : Type*} {M₂ : Type*} {M₃ : Type*} variable {V : Type*} {V₂ : Type*} namespace LinearMap section AddCommMonoid variable [Semiring R] [Semiring R₂] [Semiring R₃] variable [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] variable [Module R M] [Module R₂ M₂] [Module R₃ M₃] open Submodule variable {τ₁₂ : R →+* R₂} {τ₂₃ : R₂ →+* R₃} {τ₁₃ : R →+* R₃} variable [RingHomCompTriple τ₁₂ τ₂₃ τ₁₃] section variable {F : Type*} [FunLike F M M₂] [SemilinearMapClass F τ₁₂ M M₂] /-- The range of a linear map `f : M → M₂` is a submodule of `M₂`. See Note [range copy pattern]. -/ def range [RingHomSurjective τ₁₂] (f : F) : Submodule R₂ M₂ := (map f ⊤).copy (Set.range f) Set.image_univ.symm theorem coe_range [RingHomSurjective τ₁₂] (f : F) : (range f : Set M₂) = Set.range f := rfl @[deprecated (since := "2025-08-31")] alias range_coe := coe_range theorem range_toAddSubmonoid [RingHomSurjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) : (range f).toAddSubmonoid = AddMonoidHom.mrange f := rfl @[simp] theorem mem_range [RingHomSurjective τ₁₂] {f : F} {x} : x ∈ range f ↔ ∃ y, f y = x := Iff.rfl theorem range_eq_map [RingHomSurjective τ₁₂] (f : F) : range f = map f ⊤ := by ext simp theorem mem_range_self [RingHomSurjective τ₁₂] (f : F) (x : M) : f x ∈ range f := ⟨x, rfl⟩ @[simp] theorem range_id : range (LinearMap.id : M →ₗ[R] M) = ⊤ := SetLike.coe_injective Set.range_id theorem range_comp [RingHomSurjective τ₁₂] [RingHomSurjective τ₂₃] [RingHomSurjective τ₁₃] (f : M →ₛₗ[τ₁₂] M₂) (g : M₂ →ₛₗ[τ₂₃] M₃) : range (g.comp f : M →ₛₗ[τ₁₃] M₃) = map g (range f) := SetLike.coe_injective (Set.range_comp g f) theorem range_comp_le_range [RingHomSurjective τ₂₃] [RingHomSurjective τ₁₃] (f : M →ₛₗ[τ₁₂] M₂) (g : M₂ →ₛₗ[τ₂₃] M₃) : range (g.comp f : M →ₛₗ[τ₁₃] M₃) ≤ range g := SetLike.coe_mono (Set.range_comp_subset_range f g) theorem range_eq_top [RingHomSurjective τ₁₂] {f : F} : range f = ⊤ ↔ Surjective f := by rw [SetLike.ext'_iff, coe_range, top_coe, Set.range_eq_univ] theorem range_eq_top_of_surjective [RingHomSurjective τ₁₂] (f : F) (hf : Surjective f) : range f = ⊤ := range_eq_top.2 hf theorem range_add_le [RingHomSurjective τ₁₂] (f g : M →ₛₗ[τ₁₂] M₂) : range (f + g) ≤ range f ⊔ range g := by rintro - ⟨_, rfl⟩ apply add_mem_sup all_goals simp only [mem_range, exists_apply_eq_apply] theorem range_le_iff_comap [RingHomSurjective τ₁₂] {f : F} {p : Submodule R₂ M₂} : range f ≤ p ↔ comap f p = ⊤ := by rw [range_eq_map, map_le_iff_le_comap, eq_top_iff] theorem map_le_range [RingHomSurjective τ₁₂] {f : F} {p : Submodule R M} : map f p ≤ range f := SetLike.coe_mono (Set.image_subset_range f p) @[simp] theorem range_neg {R : Type*} {R₂ : Type*} {M : Type*} {M₂ : Type*} [Semiring R] [Ring R₂] [AddCommMonoid M] [AddCommGroup M₂] [Module R M] [Module R₂ M₂] {τ₁₂ : R →+* R₂} [RingHomSurjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) : LinearMap.range (-f) = LinearMap.range f := by change range ((-LinearMap.id : M₂ →ₗ[R₂] M₂).comp f) = _ rw [range_comp, Submodule.map_neg, Submodule.map_id] @[simp] lemma range_domRestrict [Module R M₂] (K : Submodule R M) (f : M →ₗ[R] M₂) : range (domRestrict f K) = K.map f := by ext; simp lemma range_domRestrict_le_range [RingHomSurjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) (S : Submodule R M) : LinearMap.range (f.domRestrict S) ≤ LinearMap.range f := by rintro x ⟨⟨y, hy⟩, rfl⟩ exact LinearMap.mem_range_self f y @[simp] theorem _root_.AddMonoidHom.coe_toIntLinearMap_range {M M₂ : Type*} [AddCommGroup M] [AddCommGroup M₂] (f : M →+ M₂) : LinearMap.range f.toIntLinearMap = AddSubgroup.toIntSubmodule f.range := rfl lemma _root_.Submodule.map_comap_eq_of_le [RingHomSurjective τ₁₂] {f : F} {p : Submodule R₂ M₂} (h : p ≤ LinearMap.range f) : (p.comap f).map f = p := SetLike.coe_injective <| Set.image_preimage_eq_of_subset h lemma range_restrictScalars [SMul R R₂] [Module R₂ M] [Module R M₂] [CompatibleSMul M M₂ R R₂] [IsScalarTower R R₂ M₂] (f : M →ₗ[R₂] M₂) : LinearMap.range (f.restrictScalars R) = (LinearMap.range f).restrictScalars R := rfl end /-- The decreasing sequence of submodules consisting of the ranges of the iterates of a linear map. -/ @[simps] def iterateRange (f : M →ₗ[R] M) : ℕ →o (Submodule R M)ᵒᵈ where toFun n := LinearMap.range (f ^ n) monotone' n m w x h := by obtain ⟨c, rfl⟩ := Nat.exists_eq_add_of_le w rw [LinearMap.mem_range] at h obtain ⟨m, rfl⟩ := h rw [LinearMap.mem_range] use (f ^ c) m rw [pow_add, Module.End.mul_apply] /-- Restrict the codomain of a linear map `f` to `f.range`. This is the bundled version of `Set.rangeFactorization`. -/ abbrev rangeRestrict [RingHomSurjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) : M →ₛₗ[τ₁₂] LinearMap.range f := f.codRestrict (LinearMap.range f) (LinearMap.mem_range_self f) /-- The range of a linear map is finite if the domain is finite. Note: this instance can form a diamond with `Subtype.fintype` in the presence of `Fintype M₂`. -/ instance fintypeRange [Fintype M] [DecidableEq M₂] [RingHomSurjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) : Fintype (range f) := Set.fintypeRange f variable {F : Type*} [FunLike F M M₂] [SemilinearMapClass F τ₁₂ M M₂] theorem range_codRestrict {τ₂₁ : R₂ →+* R} [RingHomSurjective τ₂₁] (p : Submodule R M) (f : M₂ →ₛₗ[τ₂₁] M) (hf) : range (codRestrict p f hf) = comap p.subtype (LinearMap.range f) := by simpa only [range_eq_map] using map_codRestrict _ _ _ _ theorem _root_.Submodule.map_comap_eq [RingHomSurjective τ₁₂] (f : F) (q : Submodule R₂ M₂) : map f (comap f q) = range f ⊓ q := le_antisymm (le_inf map_le_range (map_comap_le _ _)) <| by rintro _ ⟨⟨x, _, rfl⟩, hx⟩; exact ⟨x, hx, rfl⟩ theorem _root_.Submodule.map_comap_eq_self [RingHomSurjective τ₁₂] {f : F} {q : Submodule R₂ M₂} (h : q ≤ range f) : map f (comap f q) = q := by rwa [Submodule.map_comap_eq, inf_eq_right] @[simp] theorem range_zero [RingHomSurjective τ₁₂] : range (0 : M →ₛₗ[τ₁₂] M₂) = ⊥ := by simpa only [range_eq_map] using Submodule.map_zero _ section variable [RingHomSurjective τ₁₂] theorem range_le_bot_iff (f : M →ₛₗ[τ₁₂] M₂) : range f ≤ ⊥ ↔ f = 0 := by rw [range_le_iff_comap]; exact ker_eq_top theorem range_eq_bot {f : M →ₛₗ[τ₁₂] M₂} : range f = ⊥ ↔ f = 0 := by rw [← range_le_bot_iff, le_bot_iff] theorem range_le_ker_iff {f : M →ₛₗ[τ₁₂] M₂} {g : M₂ →ₛₗ[τ₂₃] M₃} : range f ≤ ker g ↔ (g.comp f : M →ₛₗ[τ₁₃] M₃) = 0 := ⟨fun h => ker_eq_top.1 <| eq_top_iff'.2 fun _ => h <| ⟨_, rfl⟩, fun h x hx => mem_ker.2 <| Exists.elim hx fun y hy => by rw [← hy, ← comp_apply, h, zero_apply]⟩ theorem comap_le_comap_iff {f : F} (hf : range f = ⊤) {p p'} : comap f p ≤ comap f p' ↔ p ≤ p' := ⟨fun H ↦ by rwa [SetLike.le_def, (range_eq_top.1 hf).forall], comap_mono⟩ theorem comap_injective {f : F} (hf : range f = ⊤) : Injective (comap f) := fun _ _ h => le_antisymm ((comap_le_comap_iff hf).1 (le_of_eq h)) ((comap_le_comap_iff hf).1 (ge_of_eq h)) -- TODO (?): generalize to semilinear maps with `f ∘ₗ g` bijective. theorem ker_eq_range_of_comp_eq_id {M P} [AddCommGroup M] [Module R M] [AddCommGroup P] [Module R P] {f : M →ₗ[R] P} {g : P →ₗ[R] M} (h : f ∘ₗ g = .id) : ker f = range (LinearMap.id - g ∘ₗ f) := le_antisymm (fun x hx ↦ ⟨x, show x - g (f x) = x by rw [hx, map_zero, sub_zero]⟩) <| range_le_ker_iff.mpr <| by rw [comp_sub, comp_id, ← comp_assoc, h, id_comp, sub_self] end end AddCommMonoid section Ring variable [Ring R] [Ring R₂] variable [AddCommGroup M] [AddCommGroup M₂] variable [Module R M] [Module R₂ M₂] variable {τ₁₂ : R →+* R₂} variable {F : Type*} [FunLike F M M₂] [SemilinearMapClass F τ₁₂ M M₂] variable {f : F} open Submodule theorem range_toAddSubgroup [RingHomSurjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) : (range f).toAddSubgroup = f.toAddMonoidHom.range := rfl theorem ker_le_iff [RingHomSurjective τ₁₂] {p : Submodule R M} : ker f ≤ p ↔ ∃ y ∈ range f, f ⁻¹' {y} ⊆ p := by constructor · intro h use 0 rw [← SetLike.mem_coe, coe_range] exact ⟨⟨0, map_zero f⟩, h⟩ · rintro ⟨y, h₁, h₂⟩ rw [SetLike.le_def] intro z hz simp only [mem_ker] at hz rw [← SetLike.mem_coe, coe_range, Set.mem_range] at h₁ obtain ⟨x, hx⟩ := h₁ have hx' : x ∈ p := h₂ hx have hxz : z + x ∈ p := by apply h₂ simp [hx, hz] suffices z + x - x ∈ p by simpa only [this, add_sub_cancel_right] exact p.sub_mem hxz hx' end Ring section Semifield variable [Semifield K] variable [AddCommMonoid V] [Module K V] variable [AddCommMonoid V₂] [Module K V₂] theorem range_smul (f : V →ₗ[K] V₂) (a : K) (h : a ≠ 0) : range (a • f) = range f := by simpa only [range_eq_map] using Submodule.map_smul f _ a h theorem range_smul' (f : V →ₗ[K] V₂) (a : K) : range (a • f) = ⨆ _ : a ≠ 0, range f := by simpa only [range_eq_map] using Submodule.map_smul' f _ a end Semifield end LinearMap namespace Submodule section AddCommMonoid variable [Semiring R] [Semiring R₂] [AddCommMonoid M] [AddCommMonoid M₂] variable [Module R M] [Module R₂ M₂] variable (p : Submodule R M) variable {τ₁₂ : R →+* R₂} variable {F : Type*} [FunLike F M M₂] [SemilinearMapClass F τ₁₂ M M₂] open LinearMap @[simp] theorem map_top [RingHomSurjective τ₁₂] (f : F) : map f ⊤ = range f := (range_eq_map f).symm @[simp] theorem range_subtype : range p.subtype = p := by simpa using map_comap_subtype p ⊤ theorem map_subtype_le (p' : Submodule R p) : map p.subtype p' ≤ p := by simpa using (map_le_range : map p.subtype p' ≤ range p.subtype) /-- Under the canonical linear map from a submodule `p` to the ambient space `M`, the image of the maximal submodule of `p` is just `p`. -/ theorem map_subtype_top : map p.subtype (⊤ : Submodule R p) = p := by simp @[simp] theorem comap_subtype_eq_top {p p' : Submodule R M} : comap p.subtype p' = ⊤ ↔ p ≤ p' := eq_top_iff.trans <| map_le_iff_le_comap.symm.trans <| by rw [map_subtype_top] @[simp] theorem comap_subtype_self : comap p.subtype p = ⊤ := comap_subtype_eq_top.2 le_rfl theorem submoduleOf_self (N : Submodule R M) : N.submoduleOf N = ⊤ := comap_subtype_self _ theorem submoduleOf_sup_of_le {N₁ N₂ N : Submodule R M} (h₁ : N₁ ≤ N) (h₂ : N₂ ≤ N) : (N₁ ⊔ N₂).submoduleOf N = N₁.submoduleOf N ⊔ N₂.submoduleOf N := by apply Submodule.map_injective_of_injective N.subtype_injective simp only [submoduleOf, map_comap_eq] simp_all @[simp] lemma comap_subtype_le_iff {p q r : Submodule R M} : q.comap p.subtype ≤ r.comap p.subtype ↔ p ⊓ q ≤ p ⊓ r := ⟨fun h ↦ by simpa using map_mono (f := p.subtype) h, fun h ↦ by simpa using comap_mono (f := p.subtype) h⟩ theorem range_inclusion (p q : Submodule R M) (h : p ≤ q) : range (inclusion h) = comap q.subtype p := by rw [← map_top, inclusion, LinearMap.map_codRestrict, map_top, range_subtype] @[simp] theorem map_subtype_range_inclusion {p p' : Submodule R M} (h : p ≤ p') : map p'.subtype (range <| inclusion h) = p := by simp [range_inclusion, map_comap_eq, h] lemma restrictScalars_map [SMul R R₂] [Module R₂ M] [Module R M₂] [IsScalarTower R R₂ M] [IsScalarTower R R₂ M₂] (f : M →ₗ[R₂] M₂) (M' : Submodule R₂ M) : (M'.map f).restrictScalars R = (M'.restrictScalars R).map (f.restrictScalars R) := rfl /-- If `N ⊆ M` then submodules of `N` are the same as submodules of `M` contained in `N`. See also `Submodule.mapIic`. -/ def MapSubtype.orderIso : Submodule R p ≃o { p' : Submodule R M // p' ≤ p } where toFun p' := ⟨map p.subtype p', map_subtype_le p _⟩ invFun q := comap p.subtype q left_inv p' := comap_map_eq_of_injective (by exact Subtype.val_injective) p' right_inv := fun ⟨q, hq⟩ => Subtype.ext <| by simp [map_comap_subtype p, inf_of_le_right hq] map_rel_iff' {p₁ p₂} := Subtype.coe_le_coe.symm.trans <| by dsimp rw [map_le_iff_le_comap, comap_map_eq_of_injective (show Injective p.subtype from Subtype.coe_injective) p₂] @[deprecated (since := "2025-06-03")] alias MapSubtype.relIso := MapSubtype.orderIso /-- If `p ⊆ M` is a submodule, the ordering of submodules of `p` is embedded in the ordering of submodules of `M`. -/ def MapSubtype.orderEmbedding : Submodule R p ↪o Submodule R M := (RelIso.toRelEmbedding <| MapSubtype.orderIso p).trans <| Subtype.relEmbedding (X := Submodule R M) (fun p p' ↦ p ≤ p') _ @[simp] theorem map_subtype_embedding_eq (p' : Submodule R p) : MapSubtype.orderEmbedding p p' = map p.subtype p' := rfl /-- If `N ⊆ M` then submodules of `N` are the same as submodules of `M` contained in `N`. -/ def mapIic (p : Submodule R M) : Submodule R p ≃o Set.Iic p := Submodule.MapSubtype.orderIso p @[simp] lemma coe_mapIic_apply (p : Submodule R M) (q : Submodule R p) : (p.mapIic q : Submodule R M) = q.map p.subtype := rfl lemma codisjoint_map [RingHomSurjective τ₁₂] {f : F} (hf : Function.Surjective f) {p q : Submodule R M} (hpq : Codisjoint p q) : Codisjoint (p.map f) (q.map f) := by rw [codisjoint_iff, ← Submodule.map_sup, codisjoint_iff.mp hpq, map_top, LinearMap.range_eq_top_of_surjective f hf] end AddCommMonoid end Submodule namespace LinearMap section Semiring variable [Semiring R] [Semiring R₂] [Semiring R₃] variable [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] variable [Module R M] [Module R₂ M₂] [Module R₃ M₃] variable {τ₁₂ : R →+* R₂} {τ₂₃ : R₂ →+* R₃} {τ₁₃ : R →+* R₃} variable [RingHomCompTriple τ₁₂ τ₂₃ τ₁₃] /-- A monomorphism is injective. -/ theorem ker_eq_bot_of_cancel {f : M →ₛₗ[τ₁₂] M₂} (h : ∀ u v : ker f →ₗ[R] M, f.comp u = f.comp v → u = v) : ker f = ⊥ := by have h₁ : f.comp (0 : ker f →ₗ[R] M) = 0 := comp_zero _ rw [← Submodule.range_subtype (ker f), ← h 0 (ker f).subtype (Eq.trans h₁ (comp_ker_subtype f).symm)] exact range_zero theorem range_comp_of_range_eq_top [RingHomSurjective τ₁₂] [RingHomSurjective τ₂₃] [RingHomSurjective τ₁₃] {f : M →ₛₗ[τ₁₂] M₂} (g : M₂ →ₛₗ[τ₂₃] M₃) (hf : range f = ⊤) : range (g.comp f : M →ₛₗ[τ₁₃] M₃) = range g := by rw [range_comp, hf, Submodule.map_top] section Image /-- If `O` is a submodule of `M`, and `Φ : O →ₗ M'` is a linear map, then `(ϕ : O →ₗ M').submoduleImage N` is `ϕ(N)` as a submodule of `M'` -/ def submoduleImage {M' : Type*} [AddCommMonoid M'] [Module R M'] {O : Submodule R M} (ϕ : O →ₗ[R] M') (N : Submodule R M) : Submodule R M' := (N.comap O.subtype).map ϕ @[simp] theorem mem_submoduleImage {M' : Type*} [AddCommMonoid M'] [Module R M'] {O : Submodule R M} {ϕ : O →ₗ[R] M'} {N : Submodule R M} {x : M'} : x ∈ ϕ.submoduleImage N ↔ ∃ (y : _) (yO : y ∈ O), y ∈ N ∧ ϕ ⟨y, yO⟩ = x := by refine Submodule.mem_map.trans ⟨?_, ?_⟩ <;> simp_rw [Submodule.mem_comap] · rintro ⟨⟨y, yO⟩, yN : y ∈ N, h⟩ exact ⟨y, yO, yN, h⟩ · rintro ⟨y, yO, yN, h⟩ exact ⟨⟨y, yO⟩, yN, h⟩ theorem mem_submoduleImage_of_le {M' : Type*} [AddCommMonoid M'] [Module R M'] {O : Submodule R M} {ϕ : O →ₗ[R] M'} {N : Submodule R M} (hNO : N ≤ O) {x : M'} : x ∈ ϕ.submoduleImage N ↔ ∃ (y : _) (yN : y ∈ N), ϕ ⟨y, hNO yN⟩ = x := by grind [mem_submoduleImage] theorem submoduleImage_apply_of_le {M' : Type*} [AddCommMonoid M'] [Module R M'] {O : Submodule R M} (ϕ : O →ₗ[R] M') (N : Submodule R M) (hNO : N ≤ O) : ϕ.submoduleImage N = range (ϕ.comp (Submodule.inclusion hNO)) := by rw [submoduleImage, range_comp, Submodule.range_inclusion] end Image section rangeRestrict variable [RingHomSurjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) @[simp] theorem range_rangeRestrict : range f.rangeRestrict = ⊤ := by simp [f.range_codRestrict _] theorem surjective_rangeRestrict : Surjective f.rangeRestrict := by rw [← range_eq_top, range_rangeRestrict] @[simp] theorem ker_rangeRestrict : ker f.rangeRestrict = ker f := LinearMap.ker_codRestrict _ _ _ @[simp] theorem injective_rangeRestrict_iff : Injective f.rangeRestrict ↔ Injective f := Set.injective_codRestrict _ end rangeRestrict end Semiring end LinearMap
.lake/packages/mathlib/Mathlib/Algebra/Module/Submodule/Ker.lean
import Mathlib.Algebra.Group.Subgroup.Ker import Mathlib.Algebra.Module.Submodule.Map /-! # Kernel of a linear map This file defines the kernel of a linear map. ## Main definitions * `LinearMap.ker`: the kernel of a linear map as a submodule of the domain ## Notation * We continue to use the notations `M →ₛₗ[σ] M₂` and `M →ₗ[R] M₂` for the type of semilinear (resp. linear) maps from `M` to `M₂` over the ring homomorphism `σ` (resp. over the ring `R`). ## Tags linear algebra, vector space, module -/ open Function open Pointwise variable {R : Type*} {R₂ : Type*} {R₃ : Type*} variable {K : Type*} variable {M : Type*} {M₁ : Type*} {M₂ : Type*} {M₃ : Type*} variable {V : Type*} {V₂ : Type*} /-! ### Properties of linear maps -/ namespace LinearMap section AddCommMonoid variable [Semiring R] [Semiring R₂] [Semiring R₃] variable [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] variable [Module R M] [Module R₂ M₂] [Module R₃ M₃] open Submodule variable {τ₁₂ : R →+* R₂} {τ₂₃ : R₂ →+* R₃} {τ₁₃ : R →+* R₃} variable [RingHomCompTriple τ₁₂ τ₂₃ τ₁₃] variable {F : Type*} [FunLike F M M₂] [SemilinearMapClass F τ₁₂ M M₂] /-- The kernel of a linear map `f : M → M₂` is defined to be `comap f ⊥`. This is equivalent to the set of `x : M` such that `f x = 0`. The kernel is a submodule of `M`. -/ def ker (f : F) : Submodule R M := comap f ⊥ @[simp] theorem mem_ker {f : F} {y} : y ∈ ker f ↔ f y = 0 := mem_bot R₂ @[simp] theorem ker_id : ker (LinearMap.id : M →ₗ[R] M) = ⊥ := rfl @[simp] theorem map_coe_ker (f : F) (x : ker f) : f x = 0 := mem_ker.1 x.2 theorem ker_toAddSubmonoid (f : M →ₛₗ[τ₁₂] M₂) : (ker f).toAddSubmonoid = (AddMonoidHom.mker f) := rfl theorem le_ker_iff_comp_subtype_eq_zero {N : Submodule R M} {f : M →ₛₗ[τ₁₂] M₂} : N ≤ ker f ↔ f ∘ₛₗ N.subtype = 0 := by rw [SetLike.le_def, LinearMap.ext_iff, Subtype.forall]; rfl theorem comp_ker_subtype (f : M →ₛₗ[τ₁₂] M₂) : f.comp (ker f).subtype = 0 := LinearMap.ext fun x => mem_ker.1 x.2 theorem ker_comp (f : M →ₛₗ[τ₁₂] M₂) (g : M₂ →ₛₗ[τ₂₃] M₃) : ker (g.comp f : M →ₛₗ[τ₁₃] M₃) = comap f (ker g) := rfl theorem ker_le_ker_comp (f : M →ₛₗ[τ₁₂] M₂) (g : M₂ →ₛₗ[τ₂₃] M₃) : ker f ≤ ker (g.comp f : M →ₛₗ[τ₁₃] M₃) := by rw [ker_comp]; exact comap_mono bot_le theorem ker_sup_ker_le_ker_comp_of_commute {f g : M →ₗ[R] M} (h : Commute f g) : ker f ⊔ ker g ≤ ker (f ∘ₗ g) := by refine sup_le_iff.mpr ⟨?_, ker_le_ker_comp g f⟩ rw [← Module.End.mul_eq_comp, h.eq, Module.End.mul_eq_comp] exact ker_le_ker_comp f g @[simp] theorem ker_le_comap {p : Submodule R₂ M₂} (f : M →ₛₗ[τ₁₂] M₂) : ker f ≤ p.comap f := fun x hx ↦ by simp [mem_ker.mp hx] theorem disjoint_ker {f : F} {p : Submodule R M} : Disjoint p (ker f) ↔ ∀ x ∈ p, f x = 0 → x = 0 := by simp [disjoint_def] theorem ker_eq_bot' {f : F} : ker f = ⊥ ↔ ∀ m, f m = 0 → m = 0 := by simpa [disjoint_iff_inf_le] using disjoint_ker (f := f) (p := ⊤) theorem ker_eq_bot_of_inverse {τ₂₁ : R₂ →+* R} [RingHomInvPair τ₁₂ τ₂₁] {f : M →ₛₗ[τ₁₂] M₂} {g : M₂ →ₛₗ[τ₂₁] M} (h : (g.comp f : M →ₗ[R] M) = id) : ker f = ⊥ := ker_eq_bot'.2 fun m hm => by rw [← id_apply (R := R) m, ← h, comp_apply, hm, g.map_zero] theorem le_ker_iff_map [RingHomSurjective τ₁₂] {f : F} {p : Submodule R M} : p ≤ ker f ↔ map f p = ⊥ := by rw [ker, eq_bot_iff, map_le_iff_le_comap] theorem ker_codRestrict {τ₂₁ : R₂ →+* R} (p : Submodule R M) (f : M₂ →ₛₗ[τ₂₁] M) (hf) : ker (codRestrict p f hf) = ker f := by rw [ker, comap_codRestrict, Submodule.map_bot]; rfl lemma ker_domRestrict [AddCommMonoid M₁] [Module R M₁] (p : Submodule R M) (f : M →ₗ[R] M₁) : ker (domRestrict f p) = (ker f).comap p.subtype := ker_comp .. theorem ker_restrict [AddCommMonoid M₁] [Module R M₁] {p : Submodule R M} {q : Submodule R M₁} {f : M →ₗ[R] M₁} (hf : ∀ x : M, x ∈ p → f x ∈ q) : ker (f.restrict hf) = (ker f).comap p.subtype := by rw [restrict_eq_codRestrict_domRestrict, ker_codRestrict, ker_domRestrict] @[simp] theorem ker_zero : ker (0 : M →ₛₗ[τ₁₂] M₂) = ⊤ := eq_top_iff'.2 fun x => by simp @[simp] theorem ker_eq_top {f : M →ₛₗ[τ₁₂] M₂} : ker f = ⊤ ↔ f = 0 := ⟨fun h => ext fun _ => mem_ker.1 <| h.symm ▸ trivial, fun h => h.symm ▸ ker_zero⟩ theorem exists_ne_zero_of_sSup_eq_top {f : M →ₛₗ[τ₁₂] M₂} (h : f ≠ 0) (s : Set (Submodule R M)) (hs : sSup s = ⊤) : ∃ m ∈ s, f ∘ₛₗ m.subtype ≠ 0 := by contrapose! h simp_rw [← ker_eq_top, eq_top_iff, ← hs, sSup_le_iff, le_ker_iff_comp_subtype_eq_zero] exact h @[simp] theorem _root_.AddMonoidHom.coe_toIntLinearMap_ker {M M₂ : Type*} [AddCommGroup M] [AddCommGroup M₂] (f : M →+ M₂) : LinearMap.ker f.toIntLinearMap = AddSubgroup.toIntSubmodule f.ker := rfl theorem ker_eq_bot_of_injective {f : F} (hf : Injective f) : ker f = ⊥ := by rw [eq_bot_iff] intro x hx simpa only [mem_ker, mem_bot, ← map_zero f, hf.eq_iff] using hx /-- The increasing sequence of submodules consisting of the kernels of the iterates of a linear map. -/ @[simps] def iterateKer (f : M →ₗ[R] M) : ℕ →o Submodule R M where toFun n := ker (f ^ n) monotone' n m w x h := by obtain ⟨c, rfl⟩ := Nat.exists_eq_add_of_le w rw [LinearMap.mem_ker] at h rw [LinearMap.mem_ker, add_comm, pow_add, Module.End.mul_apply, h, LinearMap.map_zero] end AddCommMonoid section Ring variable [Ring R] [Ring R₂] variable [AddCommGroup M] [AddCommGroup M₂] variable [Module R M] [Module R₂ M₂] variable {τ₁₂ : R →+* R₂} variable {F : Type*} [FunLike F M M₂] [SemilinearMapClass F τ₁₂ M M₂] variable {f : F} open Submodule theorem ker_toAddSubgroup (f : M →ₛₗ[τ₁₂] M₂) : (ker f).toAddSubgroup = f.toAddMonoidHom.ker := rfl theorem sub_mem_ker_iff {x y} : x - y ∈ ker f ↔ f x = f y := by rw [mem_ker, map_sub, sub_eq_zero] theorem disjoint_ker_iff_injOn {p : Submodule R M} : Disjoint p (LinearMap.ker f) ↔ Set.InjOn f p := by rw [disjoint_ker, Set.injOn_iff_map_eq_zero] @[deprecated disjoint_ker_iff_injOn (since := "2025-11-07")] theorem disjoint_ker' {p : Submodule R M} : Disjoint p (ker f) ↔ ∀ x ∈ p, ∀ y ∈ p, f x = f y → x = y := by simp [disjoint_ker_iff_injOn, Set.InjOn] theorem injOn_of_disjoint_ker {p : Submodule R M} {s : Set M} (h : s ⊆ p) (hd : Disjoint p (ker f)) : Set.InjOn f s := disjoint_ker_iff_injOn.mp hd |>.mono h variable (F) in theorem _root_.LinearMapClass.ker_eq_bot : ker f = ⊥ ↔ Injective f := by simpa [disjoint_iff_inf_le] using disjoint_ker_iff_injOn (f := f) (p := ⊤) theorem ker_eq_bot {f : M →ₛₗ[τ₁₂] M₂} : ker f = ⊥ ↔ Injective f := LinearMapClass.ker_eq_bot _ @[simp] lemma injective_domRestrict_iff {f : M →ₛₗ[τ₁₂] M₂} {S : Submodule R M} : Injective (f.domRestrict S) ↔ S ⊓ LinearMap.ker f = ⊥ := by rw [← LinearMap.ker_eq_bot] refine ⟨fun h ↦ le_bot_iff.1 ?_, fun h ↦ le_bot_iff.1 ?_⟩ · intro x ⟨hx, h'x⟩ have : ⟨x, hx⟩ ∈ LinearMap.ker (LinearMap.domRestrict f S) := by simpa using h'x rw [h] at this simpa [mk_eq_zero] using this · rintro ⟨x, hx⟩ h'x have : x ∈ S ⊓ LinearMap.ker f := ⟨hx, h'x⟩ rw [h] at this simpa [mk_eq_zero] using this @[simp] theorem injective_restrict_iff_disjoint {p : Submodule R M} {f : M →ₗ[R] M} (hf : ∀ x ∈ p, f x ∈ p) : Injective (f.restrict hf) ↔ Disjoint p (ker f) := by rw [← ker_eq_bot, ker_restrict hf, ← ker_domRestrict, ker_eq_bot, injective_domRestrict_iff, disjoint_iff] end Ring section Semifield variable [Semifield K] variable [AddCommMonoid V] [Module K V] variable [AddCommMonoid V₂] [Module K V₂] theorem ker_smul (f : V →ₗ[K] V₂) (a : K) (h : a ≠ 0) : ker (a • f) = ker f := Submodule.comap_smul f _ a h theorem ker_smul' (f : V →ₗ[K] V₂) (a : K) : ker (a • f) = ⨅ _ : a ≠ 0, ker f := Submodule.comap_smul' f _ a end Semifield end LinearMap namespace Submodule section AddCommMonoid variable [Semiring R] [Semiring R₂] [AddCommMonoid M] [AddCommMonoid M₂] variable [Module R M] [Module R₂ M₂] variable (p : Submodule R M) variable {τ₁₂ : R →+* R₂} variable {F : Type*} [FunLike F M M₂] [SemilinearMapClass F τ₁₂ M M₂] open LinearMap @[simp] theorem comap_bot (f : F) : comap f ⊥ = ker f := rfl @[simp] theorem ker_subtype : ker p.subtype = ⊥ := ker_eq_bot_of_injective fun _ _ => Subtype.ext @[simp] theorem ker_inclusion (p p' : Submodule R M) (h : p ≤ p') : ker (inclusion h) = ⊥ := by rw [inclusion, ker_codRestrict, ker_subtype] end AddCommMonoid end Submodule namespace LinearMap section Semiring variable [Semiring R] [Semiring R₂] [Semiring R₃] variable [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] variable [Module R M] [Module R₂ M₂] [Module R₃ M₃] variable {τ₁₂ : R →+* R₂} {τ₂₃ : R₂ →+* R₃} {τ₁₃ : R →+* R₃} variable [RingHomCompTriple τ₁₂ τ₂₃ τ₁₃] theorem ker_comp_of_ker_eq_bot (f : M →ₛₗ[τ₁₂] M₂) {g : M₂ →ₛₗ[τ₂₃] M₃} (hg : ker g = ⊥) : ker (g.comp f : M →ₛₗ[τ₁₃] M₃) = ker f := by rw [ker_comp, hg, Submodule.comap_bot] end Semiring end LinearMap /-! ### Linear equivalences -/ namespace LinearEquiv section AddCommMonoid section variable [Semiring R] [Semiring R₂] [Semiring R₃] variable [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] variable {module_M : Module R M} {module_M₂ : Module R₂ M₂} {module_M₃ : Module R₃ M₃} variable {σ₁₂ : R →+* R₂} {σ₂₁ : R₂ →+* R} variable {σ₂₃ : R₂ →+* R₃} {σ₁₃ : R →+* R₃} [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃] variable {σ₃₂ : R₃ →+* R₂} variable {re₁₂ : RingHomInvPair σ₁₂ σ₂₁} {re₂₁ : RingHomInvPair σ₂₁ σ₁₂} variable {re₂₃ : RingHomInvPair σ₂₃ σ₃₂} {re₃₂ : RingHomInvPair σ₃₂ σ₂₃} variable (e : M ≃ₛₗ[σ₁₂] M₂) (e'' : M₂ ≃ₛₗ[σ₂₃] M₃) @[simp] protected theorem ker : LinearMap.ker (e : M →ₛₗ[σ₁₂] M₂) = ⊥ := LinearMap.ker_eq_bot_of_injective e.toEquiv.injective @[simp] theorem ker_comp (l : M →ₛₗ[σ₁₂] M₂) : LinearMap.ker (((e'' : M₂ →ₛₗ[σ₂₃] M₃).comp l : M →ₛₗ[σ₁₃] M₃) : M →ₛₗ[σ₁₃] M₃) = LinearMap.ker l := LinearMap.ker_comp_of_ker_eq_bot _ e''.ker end end AddCommMonoid end LinearEquiv
.lake/packages/mathlib/Mathlib/Algebra/Module/Submodule/Lattice.lean
import Mathlib.Algebra.Group.Subgroup.Lattice import Mathlib.Algebra.Group.Submonoid.Membership import Mathlib.Algebra.Group.Submonoid.BigOperators import Mathlib.Algebra.Module.Submodule.Defs import Mathlib.Algebra.Module.Equiv.Defs import Mathlib.Algebra.Module.PUnit import Mathlib.Data.Set.Subsingleton import Mathlib.Data.Finset.Lattice.Fold import Mathlib.Order.ConditionallyCompleteLattice.Basic /-! # The lattice structure on `Submodule`s This file defines the lattice structure on submodules, `Submodule.CompleteLattice`, with `⊥` defined as `{0}` and `⊓` defined as intersection of the underlying carrier. If `p` and `q` are submodules of a module, `p ≤ q` means that `p ⊆ q`. Many results about operations on this lattice structure are defined in `LinearAlgebra/Basic.lean`, most notably those which use `span`. ## Implementation notes This structure should match the `AddSubmonoid.CompleteLattice` structure, and we should try to unify the APIs where possible. -/ universe v variable {R S M : Type*} section AddCommMonoid variable [Semiring R] [Semiring S] [AddCommMonoid M] [Module R M] [Module S M] variable [SMul S R] [IsScalarTower S R M] variable {p q : Submodule R M} namespace Submodule /-! ## Bottom element of a submodule -/ /-- The set `{0}` is the bottom element of the lattice of submodules. -/ instance : Bot (Submodule R M) := ⟨{ (⊥ : AddSubmonoid M) with carrier := {0} smul_mem' := by simp }⟩ instance inhabited' : Inhabited (Submodule R M) := ⟨⊥⟩ @[simp] theorem bot_coe : ((⊥ : Submodule R M) : Set M) = {0} := rfl @[simp] theorem bot_toAddSubmonoid : (⊥ : Submodule R M).toAddSubmonoid = ⊥ := rfl @[simp] lemma bot_toAddSubgroup {R M} [Ring R] [AddCommGroup M] [Module R M] : (⊥ : Submodule R M).toAddSubgroup = ⊥ := rfl variable (R) in @[simp] theorem mem_bot {x : M} : x ∈ (⊥ : Submodule R M) ↔ x = 0 := Set.mem_singleton_iff instance uniqueBot : Unique (⊥ : Submodule R M) := ⟨inferInstance, fun x ↦ Subtype.ext <| (mem_bot R).1 x.mem⟩ instance : OrderBot (Submodule R M) where bot_le p x := by simp +contextual [zero_mem] protected theorem eq_bot_iff (p : Submodule R M) : p = ⊥ ↔ ∀ x ∈ p, x = (0 : M) := ⟨fun h ↦ h.symm ▸ fun _ hx ↦ (mem_bot R).mp hx, fun h ↦ eq_bot_iff.mpr fun x hx ↦ (mem_bot R).mpr (h x hx)⟩ @[ext high] protected theorem bot_ext (x y : (⊥ : Submodule R M)) : x = y := by subsingleton protected theorem ne_bot_iff (p : Submodule R M) : p ≠ ⊥ ↔ ∃ x ∈ p, x ≠ (0 : M) := by simp only [ne_eq, p.eq_bot_iff, not_forall, exists_prop] theorem nonzero_mem_of_bot_lt {p : Submodule R M} (bot_lt : ⊥ < p) : ∃ a : p, a ≠ 0 := let ⟨b, hb₁, hb₂⟩ := p.ne_bot_iff.mp bot_lt.ne' ⟨⟨b, hb₁⟩, hb₂ ∘ congr_arg Subtype.val⟩ theorem exists_mem_ne_zero_of_ne_bot {p : Submodule R M} (h : p ≠ ⊥) : ∃ b : M, b ∈ p ∧ b ≠ 0 := let ⟨b, hb₁, hb₂⟩ := p.ne_bot_iff.mp h ⟨b, hb₁, hb₂⟩ -- FIXME: we default PUnit to PUnit.{1} here without the explicit universe annotation /-- The bottom submodule is linearly equivalent to punit as an `R`-module. -/ @[simps] def botEquivPUnit : (⊥ : Submodule R M) ≃ₗ[R] PUnit.{v + 1} where toFun _ := PUnit.unit invFun _ := 0 map_add' _ _ := rfl map_smul' _ _ := rfl theorem subsingleton_iff_eq_bot : Subsingleton p ↔ p = ⊥ := by rw [subsingleton_iff, Submodule.eq_bot_iff] refine ⟨fun h x hx ↦ by simpa using h ⟨x, hx⟩ ⟨0, p.zero_mem⟩, fun h ⟨x, hx⟩ ⟨y, hy⟩ ↦ by simp [h x hx, h y hy]⟩ theorem eq_bot_of_subsingleton [Subsingleton p] : p = ⊥ := subsingleton_iff_eq_bot.mp inferInstance theorem nontrivial_iff_ne_bot : Nontrivial p ↔ p ≠ ⊥ := by rw [iff_not_comm, not_nontrivial_iff_subsingleton, subsingleton_iff_eq_bot] /-! ## Top element of a submodule -/ /-- The universal set is the top element of the lattice of submodules. -/ instance : Top (Submodule R M) := ⟨{ (⊤ : AddSubmonoid M) with carrier := Set.univ smul_mem' := fun _ _ _ ↦ trivial }⟩ @[simp] theorem top_coe : ((⊤ : Submodule R M) : Set M) = Set.univ := rfl @[simp] theorem top_toAddSubmonoid : (⊤ : Submodule R M).toAddSubmonoid = ⊤ := rfl @[simp] lemma top_toAddSubgroup {R M} [Ring R] [AddCommGroup M] [Module R M] : (⊤ : Submodule R M).toAddSubgroup = ⊤ := rfl @[simp] theorem mem_top {x : M} : x ∈ (⊤ : Submodule R M) := trivial instance : OrderTop (Submodule R M) where le_top _ _ _ := trivial theorem eq_top_iff' {p : Submodule R M} : p = ⊤ ↔ ∀ x, x ∈ p := eq_top_iff.trans ⟨fun h _ ↦ h trivial, fun h x _ ↦ h x⟩ /-- The top submodule is linearly equivalent to the module. This is the module version of `AddSubmonoid.topEquiv`. -/ @[simps] def topEquiv : (⊤ : Submodule R M) ≃ₗ[R] M where toFun x := x invFun x := ⟨x, mem_top⟩ map_add' _ _ := rfl map_smul' _ _ := rfl /-! ## Infima & suprema in a submodule -/ instance : InfSet (Submodule R M) := ⟨fun S ↦ { carrier := ⋂ s ∈ S, (s : Set M) zero_mem' := by simp [zero_mem] add_mem' := by simp +contextual [add_mem] smul_mem' := by simp +contextual [smul_mem] }⟩ private theorem sInf_le' {S : Set (Submodule R M)} {p} : p ∈ S → sInf S ≤ p := Set.biInter_subset_of_mem private theorem le_sInf' {S : Set (Submodule R M)} {p} : (∀ q ∈ S, p ≤ q) → p ≤ sInf S := Set.subset_iInter₂ instance : Min (Submodule R M) := ⟨fun p q ↦ { carrier := p ∩ q zero_mem' := by simp [zero_mem] add_mem' := by simp +contextual [add_mem] smul_mem' := by simp +contextual [smul_mem] }⟩ instance completeLattice : CompleteLattice (Submodule R M) := { (inferInstance : OrderTop (Submodule R M)), (inferInstance : OrderBot (Submodule R M)) with sup := fun a b ↦ sInf { x | a ≤ x ∧ b ≤ x } le_sup_left := fun _ _ ↦ le_sInf' fun _ ⟨h, _⟩ ↦ h le_sup_right := fun _ _ ↦ le_sInf' fun _ ⟨_, h⟩ ↦ h sup_le := fun _ _ _ h₁ h₂ ↦ sInf_le' ⟨h₁, h₂⟩ inf := (· ⊓ ·) le_inf := fun _ _ _ ↦ Set.subset_inter inf_le_left := fun _ _ ↦ Set.inter_subset_left inf_le_right := fun _ _ ↦ Set.inter_subset_right sSup S := sInf {sm | ∀ s ∈ S, s ≤ sm} le_sSup := fun _ _ hs ↦ le_sInf' fun _ hq ↦ by exact hq _ hs sSup_le := fun _ _ hs ↦ sInf_le' hs le_sInf := fun _ _ ↦ le_sInf' sInf_le := fun _ _ ↦ sInf_le' } @[simp] theorem coe_inf : ↑(p ⊓ q) = (p ∩ q : Set M) := rfl @[deprecated (since := "2025-08-31")] alias inf_coe := coe_inf @[simp] theorem mem_inf {p q : Submodule R M} {x : M} : x ∈ p ⊓ q ↔ x ∈ p ∧ x ∈ q := Iff.rfl @[simp] theorem coe_sInf (P : Set (Submodule R M)) : (↑(sInf P) : Set M) = ⋂ p ∈ P, ↑p := rfl @[deprecated (since := "2025-08-31")] alias sInf_coe := coe_sInf @[simp] theorem coe_finsetInf {ι} (s : Finset ι) (p : ι → Submodule R M) : (↑(s.inf p) : Set M) = ⋂ i ∈ s, ↑(p i) := by letI := Classical.decEq ι refine s.induction_on ?_ fun i s _ ih ↦ ?_ · simp · rw [Finset.inf_insert, coe_inf, ih] simp @[deprecated (since := "2025-08-31")] alias finset_inf_coe := coe_finsetInf @[simp] theorem coe_iInf {ι} (p : ι → Submodule R M) : (↑(⨅ i, p i) : Set M) = ⋂ i, ↑(p i) := by rw [iInf, coe_sInf]; simp only [Set.mem_range, Set.iInter_exists, Set.iInter_iInter_eq'] @[deprecated (since := "2025-08-31")] alias iInf_coe := coe_iInf @[simp] theorem mem_sInf {S : Set (Submodule R M)} {x : M} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := Set.mem_iInter₂ @[simp] theorem mem_iInf {ι} (p : ι → Submodule R M) {x} : (x ∈ ⨅ i, p i) ↔ ∀ i, x ∈ p i := by rw [← SetLike.mem_coe, coe_iInf, Set.mem_iInter]; rfl @[simp] theorem mem_finsetInf {ι} {s : Finset ι} {p : ι → Submodule R M} {x : M} : x ∈ s.inf p ↔ ∀ i ∈ s, x ∈ p i := by simp only [← SetLike.mem_coe, coe_finsetInf, Set.mem_iInter] @[deprecated (since := "2025-08-31")] alias mem_finset_inf := mem_finsetInf lemma inf_iInf {ι : Sort*} [Nonempty ι] {p : ι → Submodule R M} (q : Submodule R M) : q ⊓ ⨅ i, p i = ⨅ i, q ⊓ p i := SetLike.coe_injective <| by simpa only [coe_inf, coe_iInf] using Set.inter_iInter _ _ theorem mem_sup_left {S T : Submodule R M} : ∀ {x : M}, x ∈ S → x ∈ S ⊔ T := by have : S ≤ S ⊔ T := le_sup_left rw [LE.le] at this exact this theorem mem_sup_right {S T : Submodule R M} : ∀ {x : M}, x ∈ T → x ∈ S ⊔ T := by have : T ≤ S ⊔ T := le_sup_right rw [LE.le] at this exact this theorem add_mem_sup {S T : Submodule R M} {s t : M} (hs : s ∈ S) (ht : t ∈ T) : s + t ∈ S ⊔ T := add_mem (mem_sup_left hs) (mem_sup_right ht) theorem sub_mem_sup {R' M' : Type*} [Ring R'] [AddCommGroup M'] [Module R' M'] {S T : Submodule R' M'} {s t : M'} (hs : s ∈ S) (ht : t ∈ T) : s - t ∈ S ⊔ T := by rw [sub_eq_add_neg] exact add_mem_sup hs (neg_mem ht) theorem mem_iSup_of_mem {ι : Sort*} {b : M} {p : ι → Submodule R M} (i : ι) (h : b ∈ p i) : b ∈ ⨆ i, p i := (le_iSup p i) h theorem sum_mem_iSup {ι : Type*} [Fintype ι] {f : ι → M} {p : ι → Submodule R M} (h : ∀ i, f i ∈ p i) : (∑ i, f i) ∈ ⨆ i, p i := sum_mem fun i _ ↦ mem_iSup_of_mem i (h i) theorem sum_mem_biSup {ι : Type*} {s : Finset ι} {f : ι → M} {p : ι → Submodule R M} (h : ∀ i ∈ s, f i ∈ p i) : (∑ i ∈ s, f i) ∈ ⨆ i ∈ s, p i := sum_mem fun i hi ↦ mem_iSup_of_mem i <| mem_iSup_of_mem hi (h i hi) /-! Note that `Submodule.mem_iSup` is provided in `Mathlib/LinearAlgebra/Span.lean`. -/ theorem mem_sSup_of_mem {S : Set (Submodule R M)} {s : Submodule R M} (hs : s ∈ S) : ∀ {x : M}, x ∈ s → x ∈ sSup S := by have := le_sSup hs rw [LE.le] at this exact this @[simp] theorem toAddSubmonoid_sSup (s : Set (Submodule R M)) : (sSup s).toAddSubmonoid = sSup (toAddSubmonoid '' s) := by let p : Submodule R M := { toAddSubmonoid := sSup (toAddSubmonoid '' s) smul_mem' := fun t {m} h ↦ by simp_rw [AddSubsemigroup.mem_carrier, AddSubmonoid.mem_toSubsemigroup, sSup_eq_iSup'] at h ⊢ induction h using AddSubmonoid.iSup_induction' with | mem p x hx => obtain ⟨-, ⟨p : Submodule R M, hp : p ∈ s, rfl⟩⟩ := p suffices p.toAddSubmonoid ≤ ⨆ q : toAddSubmonoid '' s, (q : AddSubmonoid M) by exact this (smul_mem p t hx) apply le_sSup rw [Subtype.range_coe_subtype] exact ⟨p, hp, rfl⟩ | zero => simpa only [smul_zero] using zero_mem _ | add _ _ _ _ mx my => revert mx my; simp_rw [smul_add]; exact add_mem } refine le_antisymm (?_ : sSup s ≤ p) ?_ · exact sSup_le fun q hq ↦ le_sSup <| Set.mem_image_of_mem toAddSubmonoid hq · exact sSup_le fun _ ⟨q, hq, hq'⟩ ↦ hq'.symm ▸ le_sSup hq variable (R) @[simp] theorem subsingleton_iff : Subsingleton (Submodule R M) ↔ Subsingleton M := have h : Subsingleton (Submodule R M) ↔ Subsingleton (AddSubmonoid M) := by rw [← subsingleton_iff_bot_eq_top, ← subsingleton_iff_bot_eq_top, ← toAddSubmonoid_inj, bot_toAddSubmonoid, top_toAddSubmonoid] h.trans AddSubmonoid.subsingleton_iff @[simp] theorem nontrivial_iff : Nontrivial (Submodule R M) ↔ Nontrivial M := not_iff_not.mp ((not_nontrivial_iff_subsingleton.trans <| subsingleton_iff R).trans not_nontrivial_iff_subsingleton.symm) variable {R} instance [Subsingleton M] : Unique (Submodule R M) := ⟨⟨⊥⟩, fun a => @Subsingleton.elim _ ((subsingleton_iff R).mpr ‹_›) a _⟩ instance unique' [Subsingleton R] : Unique (Submodule R M) := by haveI := Module.subsingleton R M; infer_instance instance [Nontrivial M] : Nontrivial (Submodule R M) := (nontrivial_iff R).mpr ‹_› /-! ## Disjointness of submodules -/ theorem disjoint_def {p p' : Submodule R M} : Disjoint p p' ↔ ∀ x ∈ p, x ∈ p' → x = (0 : M) := disjoint_iff_inf_le.trans <| show (∀ x, x ∈ p ∧ x ∈ p' → x ∈ ({0} : Set M)) ↔ _ by simp theorem disjoint_def' {p p' : Submodule R M} : Disjoint p p' ↔ ∀ x ∈ p, ∀ y ∈ p', x = y → x = (0 : M) := disjoint_def.trans ⟨fun h x hx _ hy hxy ↦ h x hx <| hxy.symm ▸ hy, fun h x hx hx' ↦ h _ hx x hx' rfl⟩ theorem eq_zero_of_coe_mem_of_disjoint (hpq : Disjoint p q) {a : p} (ha : (a : M) ∈ q) : a = 0 := mod_cast disjoint_def.mp hpq a (coe_mem a) ha theorem mem_right_iff_eq_zero_of_disjoint {p p' : Submodule R M} (h : Disjoint p p') {x : p} : (x : M) ∈ p' ↔ x = 0 := ⟨fun hx => coe_eq_zero.1 <| disjoint_def.1 h x x.2 hx, fun h => h.symm ▸ p'.zero_mem⟩ theorem mem_left_iff_eq_zero_of_disjoint {p p' : Submodule R M} (h : Disjoint p p') {x : p'} : (x : M) ∈ p ↔ x = 0 := ⟨fun hx => coe_eq_zero.1 <| disjoint_def.1 h x hx x.2, fun h => h.symm ▸ p.zero_mem⟩ end Submodule section NatSubmodule /-! ## ℕ-submodules -/ /-- An additive submonoid is equivalent to a ℕ-submodule. -/ def AddSubmonoid.toNatSubmodule : AddSubmonoid M ≃o Submodule ℕ M where toFun S := { S with smul_mem' := fun r s hs ↦ show r • s ∈ S from nsmul_mem hs _ } invFun := Submodule.toAddSubmonoid map_rel_iff' := Iff.rfl @[simp] theorem AddSubmonoid.toNatSubmodule_symm : ⇑(AddSubmonoid.toNatSubmodule.symm : _ ≃o AddSubmonoid M) = Submodule.toAddSubmonoid := rfl @[simp] theorem AddSubmonoid.coe_toNatSubmodule (S : AddSubmonoid M) : (S.toNatSubmodule : Set M) = S := rfl @[simp] theorem AddSubmonoid.toNatSubmodule_toAddSubmonoid (S : AddSubmonoid M) : S.toNatSubmodule.toAddSubmonoid = S := AddSubmonoid.toNatSubmodule.symm_apply_apply S @[simp] theorem Submodule.toAddSubmonoid_toNatSubmodule (S : Submodule ℕ M) : S.toAddSubmonoid.toNatSubmodule = S := AddSubmonoid.toNatSubmodule.apply_symm_apply S end NatSubmodule end AddCommMonoid section IntSubmodule /-! ## ℤ-submodules -/ variable [AddCommGroup M] /-- An additive subgroup is equivalent to a ℤ-submodule. -/ def AddSubgroup.toIntSubmodule : AddSubgroup M ≃o Submodule ℤ M where toFun S := { S with smul_mem' := fun _ _ hs ↦ S.zsmul_mem hs _ } invFun := Submodule.toAddSubgroup map_rel_iff' := Iff.rfl @[simp] theorem AddSubgroup.toIntSubmodule_symm : ⇑(AddSubgroup.toIntSubmodule.symm : _ ≃o AddSubgroup M) = Submodule.toAddSubgroup := rfl @[simp] theorem AddSubgroup.coe_toIntSubmodule (S : AddSubgroup M) : (S.toIntSubmodule : Set M) = S := rfl @[simp] theorem AddSubgroup.toIntSubmodule_toAddSubgroup (S : AddSubgroup M) : S.toIntSubmodule.toAddSubgroup = S := AddSubgroup.toIntSubmodule.symm_apply_apply S theorem Submodule.toAddSubgroup_toIntSubmodule (S : Submodule ℤ M) : S.toAddSubgroup.toIntSubmodule = S := AddSubgroup.toIntSubmodule.apply_symm_apply S end IntSubmodule
.lake/packages/mathlib/Mathlib/Algebra/Module/Submodule/IterateMapComap.lean
import Mathlib.Algebra.Module.Submodule.Ker /-! # Iterate maps and comaps of submodules Some preliminary work for establishing the strong rank condition for Noetherian rings. Given two linear maps `f i : N →ₗ[R] M` and a submodule `K : Submodule R N`, we can define `LinearMap.iterateMapComap f i n K : Submodule R N` to be `f⁻¹(i(⋯(f⁻¹(i(K)))))` (`n` times). If `f(K) ≤ i(K)`, then this sequence is non-decreasing (`LinearMap.iterateMapComap_le_succ`). On the other hand, if `f` is surjective, `i` is injective, and there exists some `m` such that `LinearMap.iterateMapComap f i m K = LinearMap.iterateMapComap f i (m + 1) K`, then for any `n`, `LinearMap.iterateMapComap f i n K = LinearMap.iterateMapComap f i (n + 1) K`. In particular, by taking `n = 0`, the kernel of `f` is contained in `K` (`LinearMap.ker_le_of_iterateMapComap_eq_succ`), which is a consequence of `LinearMap.ker_le_comap`. As a special case, if one can take `K` to be zero, then `f` is injective. This is the key result for establishing the strong rank condition for Noetherian rings. The construction here is adapted from the proof in Djoković's paper *Epimorphisms of modules which must be isomorphisms* [djokovic1973]. -/ open Function Submodule namespace LinearMap variable {R N M : Type*} [Semiring R] [AddCommMonoid N] [Module R N] [AddCommMonoid M] [Module R M] (f i : N →ₗ[R] M) /-- The `LinearMap.iterateMapComap f i n K : Submodule R N` is `f⁻¹(i(⋯(f⁻¹(i(K)))))` (`n` times). -/ def iterateMapComap (n : ℕ) := (fun K : Submodule R N ↦ (K.map i).comap f)^[n] /-- If `f(K) ≤ i(K)`, then `LinearMap.iterateMapComap` is not decreasing. -/ theorem iterateMapComap_le_succ (K : Submodule R N) (h : K.map f ≤ K.map i) (n : ℕ) : f.iterateMapComap i n K ≤ f.iterateMapComap i (n + 1) K := by nth_rw 2 [iterateMapComap] rw [iterate_succ', Function.comp_apply, ← iterateMapComap, ← map_le_iff_le_comap] induction n with | zero => exact h | succ n ih => simp_rw [iterateMapComap, iterate_succ', Function.comp_apply] calc _ ≤ (f.iterateMapComap i n K).map i := map_comap_le _ _ _ ≤ (((f.iterateMapComap i n K).map f).comap f).map i := by grw [← le_comap_map] _ ≤ _ := by gcongr; exact ih /-- If `f` is surjective, `i` is injective, and there exists some `m` such that `LinearMap.iterateMapComap f i m K = LinearMap.iterateMapComap f i (m + 1) K`, then for any `n`, `LinearMap.iterateMapComap f i n K = LinearMap.iterateMapComap f i (n + 1) K`. In particular, by taking `n = 0`, the kernel of `f` is contained in `K` (`LinearMap.ker_le_of_iterateMapComap_eq_succ`), which is a consequence of `LinearMap.ker_le_comap`. -/ theorem iterateMapComap_eq_succ (K : Submodule R N) (m : ℕ) (heq : f.iterateMapComap i m K = f.iterateMapComap i (m + 1) K) (hf : Surjective f) (hi : Injective i) (n : ℕ) : f.iterateMapComap i n K = f.iterateMapComap i (n + 1) K := by induction n with | zero => contrapose! heq induction m with | zero => exact heq | succ m ih => rw [iterateMapComap, iterateMapComap, iterate_succ', iterate_succ'] exact fun H ↦ ih (map_injective_of_injective hi (comap_injective_of_surjective hf H)) | succ n ih => rw [iterateMapComap, iterateMapComap, iterate_succ', iterate_succ', Function.comp_apply, Function.comp_apply, ← iterateMapComap, ← iterateMapComap, ih] /-- If `f` is surjective, `i` is injective, and there exists some `m` such that `LinearMap.iterateMapComap f i m K = LinearMap.iterateMapComap f i (m + 1) K`, then the kernel of `f` is contained in `K`. This is a corollary of `LinearMap.iterateMapComap_eq_succ` and `LinearMap.ker_le_comap`. As a special case, if one can take `K` to be zero, then `f` is injective. This is the key result for establishing the strong rank condition for Noetherian rings. -/ theorem ker_le_of_iterateMapComap_eq_succ (K : Submodule R N) (m : ℕ) (heq : f.iterateMapComap i m K = f.iterateMapComap i (m + 1) K) (hf : Surjective f) (hi : Injective i) : LinearMap.ker f ≤ K := by rw [show K = _ from f.iterateMapComap_eq_succ i K m heq hf hi 0] exact f.ker_le_comap end LinearMap
.lake/packages/mathlib/Mathlib/Algebra/Module/Equiv/Opposite.lean
import Mathlib.Algebra.Module.Equiv.Defs import Mathlib.Algebra.Module.Opposite /-! # Module operations on `Mᵐᵒᵖ` This file contains definitions that build on top of the group action definitions in `Mathlib/Algebra/GroupWithZero/Action/Opposite.lean`. -/ section variable {R S M : Type*} [Semiring R] [Semiring S] [AddCommMonoid M] [Module S M] @[ext high] theorem LinearMap.ext_ring_op {σ : Rᵐᵒᵖ →+* S} {f g : R →ₛₗ[σ] M} (h : f (1 : R) = g (1 : R)) : f = g := ext fun x ↦ by rw [← one_mul x, ← op_smul_eq_mul, f.map_smulₛₗ, h, g.map_smulₛₗ] end namespace MulOpposite universe u v variable (R : Type u) {M : Type v} [Semiring R] [AddCommMonoid M] [Module R M] /-- The function `op` is a linear equivalence. -/ def opLinearEquiv : M ≃ₗ[R] Mᵐᵒᵖ := { opAddEquiv with map_smul' := MulOpposite.op_smul } @[simp] theorem coe_opLinearEquiv : (opLinearEquiv R : M → Mᵐᵒᵖ) = op := rfl @[simp] theorem coe_opLinearEquiv_symm : ((opLinearEquiv R).symm : Mᵐᵒᵖ → M) = unop := rfl @[simp] theorem coe_opLinearEquiv_toLinearMap : ((opLinearEquiv R).toLinearMap : M → Mᵐᵒᵖ) = op := rfl @[simp] theorem coe_opLinearEquiv_symm_toLinearMap : ((opLinearEquiv R).symm.toLinearMap : Mᵐᵒᵖ → M) = unop := rfl theorem opLinearEquiv_toAddEquiv : (opLinearEquiv R : M ≃ₗ[R] Mᵐᵒᵖ).toAddEquiv = opAddEquiv := rfl @[simp] theorem coe_opLinearEquiv_addEquiv : ((opLinearEquiv R : M ≃ₗ[R] Mᵐᵒᵖ) : M ≃+ Mᵐᵒᵖ) = opAddEquiv := rfl theorem opLinearEquiv_symm_toAddEquiv : (opLinearEquiv R : M ≃ₗ[R] Mᵐᵒᵖ).symm.toAddEquiv = opAddEquiv.symm := rfl @[simp] theorem coe_opLinearEquiv_symm_addEquiv : ((opLinearEquiv R : M ≃ₗ[R] Mᵐᵒᵖ).symm : Mᵐᵒᵖ ≃+ M) = opAddEquiv.symm := rfl end MulOpposite
.lake/packages/mathlib/Mathlib/Algebra/Module/Equiv/Basic.lean
import Mathlib.Algebra.Field.Defs import Mathlib.Algebra.GroupWithZero.Action.Basic import Mathlib.Algebra.GroupWithZero.Action.Units import Mathlib.Algebra.Module.Equiv.Defs import Mathlib.Algebra.Module.Hom import Mathlib.Algebra.Module.LinearMap.Basic import Mathlib.Algebra.Module.LinearMap.End import Mathlib.Algebra.Module.Pi import Mathlib.Algebra.Module.Prod /-! # Further results on (semi)linear equivalences. -/ open Function variable {R : Type*} {R₂ : Type*} variable {K : Type*} {S : Type*} {M : Type*} {M₁ : Type*} {M₂ : Type*} {M₃ : Type*} section AddCommMonoid namespace LinearEquiv variable [Semiring R] [Semiring S] [Semiring R₂] [AddCommMonoid M] [AddCommMonoid M₂] section RestrictScalars variable (R) variable [Module R M] [Module R M₂] [Module S M] [Module S M₂] [LinearMap.CompatibleSMul M M₂ R S] /-- If `M` and `M₂` are both `R`-semimodules and `S`-semimodules and `R`-semimodule structures are defined by an action of `R` on `S` (formally, we have two scalar towers), then any `S`-linear equivalence from `M` to `M₂` is also an `R`-linear equivalence. See also `LinearMap.restrictScalars`. -/ @[simps] def restrictScalars (f : M ≃ₗ[S] M₂) : M ≃ₗ[R] M₂ := { f.toLinearMap.restrictScalars R with toFun := f invFun := f.symm left_inv := f.left_inv right_inv := f.right_inv } theorem restrictScalars_injective : Function.Injective (restrictScalars R : (M ≃ₗ[S] M₂) → M ≃ₗ[R] M₂) := fun _ _ h ↦ ext (LinearEquiv.congr_fun h :) @[simp] theorem restrictScalars_inj (f g : M ≃ₗ[S] M₂) : f.restrictScalars R = g.restrictScalars R ↔ f = g := (restrictScalars_injective R).eq_iff end RestrictScalars theorem _root_.Module.End.isUnit_iff [Module R M] (f : Module.End R M) : IsUnit f ↔ Function.Bijective f := ⟨fun h ↦ Function.bijective_iff_has_inverse.mpr <| ⟨h.unit.inv, ⟨Module.End.isUnit_inv_apply_apply_of_isUnit h, Module.End.isUnit_apply_inv_apply_of_isUnit h⟩⟩, fun H ↦ let e : M ≃ₗ[R] M := { f, Equiv.ofBijective f H with } ⟨⟨_, e.symm, LinearMap.ext e.right_inv, LinearMap.ext e.left_inv⟩, rfl⟩⟩ @[deprecated (since := "2025-04-28")] alias _root_.Module.End_isUnit_iff := _root_.Module.End.isUnit_iff section Automorphisms variable [Module R M] instance automorphismGroup : Group (M ≃ₗ[R] M) where mul f g := g.trans f one := LinearEquiv.refl R M inv f := f.symm mul_assoc _ _ _ := rfl mul_one _ := ext fun _ ↦ rfl one_mul _ := ext fun _ ↦ rfl inv_mul_cancel f := ext <| f.left_inv lemma one_eq_refl : (1 : M ≃ₗ[R] M) = refl R M := rfl lemma mul_eq_trans (f g : M ≃ₗ[R] M) : f * g = g.trans f := rfl @[simp] lemma coe_one : ↑(1 : M ≃ₗ[R] M) = id := rfl @[simp] lemma coe_toLinearMap_one : (↑(1 : M ≃ₗ[R] M) : M →ₗ[R] M) = LinearMap.id := rfl @[simp] lemma coe_toLinearMap_mul {e₁ e₂ : M ≃ₗ[R] M} : (↑(e₁ * e₂) : M →ₗ[R] M) = (e₁ : M →ₗ[R] M) * (e₂ : M →ₗ[R] M) := rfl theorem coe_pow (e : M ≃ₗ[R] M) (n : ℕ) : ⇑(e ^ n) = e^[n] := hom_coe_pow _ rfl (fun _ _ ↦ rfl) _ _ theorem pow_apply (e : M ≃ₗ[R] M) (n : ℕ) (m : M) : (e ^ n) m = e^[n] m := congr_fun (coe_pow e n) m @[simp] lemma mul_apply (f : M ≃ₗ[R] M) (g : M ≃ₗ[R] M) (x : M) : (f * g) x = f (g x) := rfl /-- Restriction from `R`-linear automorphisms of `M` to `R`-linear endomorphisms of `M`, promoted to a monoid hom. -/ @[simps] def automorphismGroup.toLinearMapMonoidHom : (M ≃ₗ[R] M) →* M →ₗ[R] M where toFun e := e.toLinearMap map_one' := rfl map_mul' _ _ := rfl /-- The tautological action by `M ≃ₗ[R] M` on `M`. This generalizes `Function.End.applyMulAction`. -/ instance applyDistribMulAction : DistribMulAction (M ≃ₗ[R] M) M where smul := (· <| ·) smul_zero := LinearEquiv.map_zero smul_add := LinearEquiv.map_add one_smul _ := rfl mul_smul _ _ _ := rfl @[simp] protected theorem smul_def (f : M ≃ₗ[R] M) (a : M) : f • a = f a := rfl /-- `LinearEquiv.applyDistribMulAction` is faithful. -/ instance apply_faithfulSMul : FaithfulSMul (M ≃ₗ[R] M) M := ⟨LinearEquiv.ext⟩ instance apply_smulCommClass [SMul S R] [SMul S M] [IsScalarTower S R M] : SMulCommClass S (M ≃ₗ[R] M) M where smul_comm r e m := (e.map_smul_of_tower r m).symm instance apply_smulCommClass' [SMul S R] [SMul S M] [IsScalarTower S R M] : SMulCommClass (M ≃ₗ[R] M) S M := SMulCommClass.symm _ _ _ end Automorphisms section OfSubsingleton variable (M M₂) variable [Module R M] [Module R M₂] [Subsingleton M] [Subsingleton M₂] /-- Any two modules that are subsingletons are isomorphic. -/ @[simps] def ofSubsingleton : M ≃ₗ[R] M₂ := { (0 : M →ₗ[R] M₂) with toFun := fun _ ↦ 0 invFun := fun _ ↦ 0 left_inv := fun _ ↦ Subsingleton.elim _ _ right_inv := fun _ ↦ Subsingleton.elim _ _ } @[simp] theorem ofSubsingleton_self : ofSubsingleton M M = refl R M := by ext simp [eq_iff_true_of_subsingleton] end OfSubsingleton end LinearEquiv namespace Module /-- `g : R ≃+* S` is `R`-linear when the module structure on `S` is `Module.compHom S g` . -/ @[simps] def compHom.toLinearEquiv {R S : Type*} [Semiring R] [Semiring S] (g : R ≃+* S) : haveI := compHom S (↑g : R →+* S) R ≃ₗ[R] S := letI := compHom S (↑g : R →+* S) { g with toFun := (g : R → S) invFun := (g.symm : S → R) map_smul' := g.map_mul } end Module namespace DistribMulAction variable (R M) [Semiring R] [AddCommMonoid M] [Module R M] variable [Group S] [DistribMulAction S M] [SMulCommClass S R M] /-- Each element of the group defines a linear equivalence. This is a stronger version of `DistribMulAction.toAddEquiv`. -/ @[simps!] def toLinearEquiv (s : S) : M ≃ₗ[R] M := { toAddEquiv M s, toLinearMap R M s with } /-- Each element of the group defines a module automorphism. This is a stronger version of `DistribMulAction.toAddAut`. -/ @[simps] def toModuleAut : S →* M ≃ₗ[R] M where toFun := toLinearEquiv R M map_one' := LinearEquiv.ext <| one_smul _ map_mul' _ _ := LinearEquiv.ext <| mul_smul _ _ end DistribMulAction namespace AddEquiv section AddCommMonoid variable [Semiring R] [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] variable [Module R M] [Module R M₂] variable (e : M ≃+ M₂) /-- An additive equivalence whose underlying function preserves `smul` is a linear equivalence. -/ def toLinearEquiv (h : ∀ (c : R) (x), e (c • x) = c • e x) : M ≃ₗ[R] M₂ := { e with map_smul' := h } @[simp] theorem coe_toLinearEquiv (h : ∀ (c : R) (x), e (c • x) = c • e x) : ⇑(e.toLinearEquiv h) = e := rfl @[simp] theorem coe_toLinearEquiv_symm (h : ∀ (c : R) (x), e (c • x) = c • e x) : ⇑(e.toLinearEquiv h).symm = e.symm := rfl /-- An additive equivalence between commutative additive monoids is a linear equivalence between ℕ-modules -/ def toNatLinearEquiv : M ≃ₗ[ℕ] M₂ := e.toLinearEquiv fun c a ↦ by rw [map_nsmul] @[simp] theorem coe_toNatLinearEquiv : ⇑e.toNatLinearEquiv = e := rfl @[simp] theorem coe_symm_toNatLinearEquiv : ⇑e.toNatLinearEquiv.symm = e.symm := rfl @[simp] theorem toNatLinearEquiv_toAddEquiv : ↑e.toNatLinearEquiv = e := rfl @[simp] theorem _root_.LinearEquiv.toAddEquiv_toNatLinearEquiv (e : M ≃ₗ[ℕ] M₂) : AddEquiv.toNatLinearEquiv ↑e = e := DFunLike.coe_injective rfl @[simp] theorem toNatLinearEquiv_symm : e.symm.toNatLinearEquiv = e.toNatLinearEquiv.symm := rfl @[simp] theorem toNatLinearEquiv_refl : (AddEquiv.refl M).toNatLinearEquiv = LinearEquiv.refl ℕ M := rfl @[simp] theorem toNatLinearEquiv_trans (e₂ : M₂ ≃+ M₃) : (e.trans e₂).toNatLinearEquiv = e.toNatLinearEquiv.trans e₂.toNatLinearEquiv := rfl end AddCommMonoid section AddCommGroup variable [AddCommGroup M] [AddCommGroup M₂] [AddCommGroup M₃] variable (e : M ≃+ M₂) /-- An additive equivalence between commutative additive groups is a linear equivalence between ℤ-modules -/ def toIntLinearEquiv : M ≃ₗ[ℤ] M₂ := e.toLinearEquiv fun c a ↦ e.toAddMonoidHom.map_zsmul a c @[simp] theorem coe_toIntLinearEquiv : ⇑e.toIntLinearEquiv = e := rfl @[simp] theorem coe_symm_toIntLinearEquiv : ⇑e.toIntLinearEquiv.symm = e.symm := rfl @[simp] theorem toIntLinearEquiv_toAddEquiv : ↑e.toIntLinearEquiv = e := by ext rfl @[simp] theorem _root_.LinearEquiv.toAddEquiv_toIntLinearEquiv (e : M ≃ₗ[ℤ] M₂) : AddEquiv.toIntLinearEquiv (e : M ≃+ M₂) = e := DFunLike.coe_injective rfl @[simp] theorem toIntLinearEquiv_symm : e.symm.toIntLinearEquiv = e.toIntLinearEquiv.symm := rfl @[simp] theorem toIntLinearEquiv_refl : (AddEquiv.refl M).toIntLinearEquiv = LinearEquiv.refl ℤ M := rfl @[simp] theorem toIntLinearEquiv_trans (e₂ : M₂ ≃+ M₃) : (e.trans e₂).toIntLinearEquiv = e.toIntLinearEquiv.trans e₂.toIntLinearEquiv := rfl end AddCommGroup end AddEquiv namespace LinearMap variable (R S M) variable [Semiring R] [Semiring S] [AddCommMonoid M] [Module R M] /-- The equivalence between R-linear maps from `R` to `M`, and points of `M` itself. This says that the forgetful functor from `R`-modules to types is representable, by `R`. This is an `S`-linear equivalence, under the assumption that `S` acts on `M` commuting with `R`. When `R` is commutative, we can take this to be the usual action with `S = R`. Otherwise, `S = ℕ` shows that the equivalence is additive. See note [bundled maps over different rings]. -/ @[simps] def ringLmapEquivSelf [Module S M] [SMulCommClass R S M] : (R →ₗ[R] M) ≃ₗ[S] M := { applyₗ' S (1 : R) with toFun := fun f ↦ f 1 invFun := smulRight (1 : R →ₗ[R] R) left_inv := fun f ↦ by ext simp only [coe_smulRight, Module.End.one_apply, smul_eq_mul, ← map_smul f, mul_one] right_inv := fun x ↦ by simp } end LinearMap /-- The `R`-linear equivalence between additive morphisms `A →+ B` and `ℕ`-linear morphisms `A →ₗ[ℕ] B`. -/ @[simps] def addMonoidHomLequivNat {A B : Type*} (R : Type*) [Semiring R] [AddCommMonoid A] [AddCommMonoid B] [Module R B] : (A →+ B) ≃ₗ[R] A →ₗ[ℕ] B where toFun := AddMonoidHom.toNatLinearMap invFun := LinearMap.toAddMonoidHom map_add' _ _ := rfl map_smul' _ _ := rfl /-- The `R`-linear equivalence between additive morphisms `A →+ B` and `ℤ`-linear morphisms `A →ₗ[ℤ] B`. -/ @[simps] def addMonoidHomLequivInt {A B : Type*} (R : Type*) [Semiring R] [AddCommGroup A] [AddCommGroup B] [Module R B] : (A →+ B) ≃ₗ[R] A →ₗ[ℤ] B where toFun := AddMonoidHom.toIntLinearMap invFun := LinearMap.toAddMonoidHom map_add' _ _ := rfl map_smul' _ _ := rfl /-- Ring equivalence between additive group endomorphisms of an `AddCommGroup` `A` and `ℤ`-module endomorphisms of `A.` -/ @[simps] def addMonoidEndRingEquivInt (A : Type*) [AddCommGroup A] : AddMonoid.End A ≃+* Module.End ℤ A := { addMonoidHomLequivInt (B := A) ℤ with map_mul' := fun _ _ ↦ rfl } namespace LinearEquiv section AddCommMonoid section Subsingleton variable [Semiring R] [Semiring R₂] variable [AddCommMonoid M] [AddCommMonoid M₂] variable [Module R M] [Module R₂ M₂] variable {σ₁₂ : R →+* R₂} {σ₂₁ : R₂ →+* R} variable [RingHomInvPair σ₁₂ σ₂₁] [RingHomInvPair σ₂₁ σ₁₂] section Module variable [Subsingleton M] [Subsingleton M₂] /-- Between two zero modules, the zero map is an equivalence. -/ instance : Zero (M ≃ₛₗ[σ₁₂] M₂) := ⟨{ (0 : M →ₛₗ[σ₁₂] M₂) with toFun := 0 invFun := 0 right_inv := Subsingleton.elim _ left_inv := Subsingleton.elim _ }⟩ -- Even though these are implied by `Subsingleton.elim` via the `Unique` instance below, they're -- nice to have as `rfl`-lemmas for `dsimp`. @[simp] theorem zero_symm : (0 : M ≃ₛₗ[σ₁₂] M₂).symm = 0 := rfl @[simp] theorem coe_zero : ⇑(0 : M ≃ₛₗ[σ₁₂] M₂) = 0 := rfl theorem zero_apply (x : M) : (0 : M ≃ₛₗ[σ₁₂] M₂) x = 0 := rfl /-- Between two zero modules, the zero map is the only equivalence. -/ instance : Unique (M ≃ₛₗ[σ₁₂] M₂) where uniq _ := toLinearMap_injective (Subsingleton.elim _ _) default := 0 end Module instance uniqueOfSubsingleton [Subsingleton R] [Subsingleton R₂] : Unique (M ≃ₛₗ[σ₁₂] M₂) := by haveI := Module.subsingleton R M haveI := Module.subsingleton R₂ M₂ infer_instance end Subsingleton section Uncurry variable [Semiring R] variable [AddCommMonoid M] [Module R M] variable (V V₂ R M) /-- Linear equivalence between a curried and uncurried function. Differs from `TensorProduct.curry`. -/ protected def curry : (V × V₂ → M) ≃ₗ[R] V → V₂ → M := { Equiv.curry _ _ _ with map_add' := fun _ _ ↦ rfl map_smul' := fun _ _ ↦ rfl } @[simp] theorem coe_curry : ⇑(LinearEquiv.curry R M V V₂) = curry := rfl @[simp] theorem coe_curry_symm : ⇑(LinearEquiv.curry R M V V₂).symm = uncurry := rfl end Uncurry section variable [Semiring R] [Semiring R₂] variable [AddCommMonoid M] [AddCommMonoid M₂] variable {module_M : Module R M} {module_M₂ : Module R₂ M₂} variable {σ₁₂ : R →+* R₂} {σ₂₁ : R₂ →+* R} variable {re₁₂ : RingHomInvPair σ₁₂ σ₂₁} {re₂₁ : RingHomInvPair σ₂₁ σ₁₂} variable (f : M →ₛₗ[σ₁₂] M₂) (g : M₂ →ₛₗ[σ₂₁] M) /-- If a linear map has an inverse, it is a linear equivalence. -/ def ofLinear (h₁ : f.comp g = LinearMap.id) (h₂ : g.comp f = LinearMap.id) : M ≃ₛₗ[σ₁₂] M₂ := { f with invFun := g left_inv := LinearMap.ext_iff.1 h₂ right_inv := LinearMap.ext_iff.1 h₁ } @[simp] theorem ofLinear_apply {h₁ h₂} (x : M) : (ofLinear f g h₁ h₂ : M ≃ₛₗ[σ₁₂] M₂) x = f x := rfl @[simp] theorem ofLinear_symm_apply {h₁ h₂} (x : M₂) : (ofLinear f g h₁ h₂ : M ≃ₛₗ[σ₁₂] M₂).symm x = g x := rfl @[simp] theorem ofLinear_toLinearMap {h₁ h₂} : (ofLinear f g h₁ h₂ : M ≃ₛₗ[σ₁₂] M₂) = f := rfl @[simp] theorem ofLinear_symm_toLinearMap {h₁ h₂} : (ofLinear f g h₁ h₂ : M ≃ₛₗ[σ₁₂] M₂).symm = g := rfl end end AddCommMonoid section Neg variable (R) [Semiring R] [AddCommGroup M] [Module R M] /-- `x ↦ -x` as a `LinearEquiv` -/ def neg : M ≃ₗ[R] M := { Equiv.neg M, (-LinearMap.id : M →ₗ[R] M) with } variable {R} @[simp] theorem coe_neg : ⇑(neg R : M ≃ₗ[R] M) = -id := rfl theorem neg_apply (x : M) : neg R x = -x := by simp @[simp] theorem symm_neg : (neg R : M ≃ₗ[R] M).symm = neg R := rfl end Neg section Semiring open LinearMap section Semilinear variable {R₁ R₂ R₁' R₂' : Type*} {M₁ M₂ M₁' M₂' : Type*} variable [Semiring R₁] [Semiring R₂] [Semiring R₁'] [Semiring R₂'] variable [AddCommMonoid M₁] [AddCommMonoid M₂] [AddCommMonoid M₁'] [AddCommMonoid M₂'] variable [Module R₁ M₁] [Module R₂ M₂] [Module R₁' M₁'] [Module R₂' M₂'] variable {σ₁₂ : R₁ →+* R₂} {σ₂₁ : R₂ →+* R₁} {σ₁'₂' : R₁' →+* R₂'} {σ₂'₁' : R₂' →+* R₁'} variable {σ₁₁' : R₁ →+* R₁'} {σ₂₂' : R₂ →+* R₂'} variable {σ₂₁' : R₂ →+* R₁'} {σ₁₂' : R₁ →+* R₂'} variable [RingHomInvPair σ₁₂ σ₂₁] [RingHomInvPair σ₂₁ σ₁₂] variable [RingHomInvPair σ₁'₂' σ₂'₁'] [RingHomInvPair σ₂'₁' σ₁'₂'] variable [RingHomCompTriple σ₁₁' σ₁'₂' σ₁₂'] [RingHomCompTriple σ₂₁ σ₁₂' σ₂₂'] variable [RingHomCompTriple σ₂₂' σ₂'₁' σ₂₁'] [RingHomCompTriple σ₁₂ σ₂₁' σ₁₁'] /-- A linear isomorphism between the domains and codomains of two spaces of linear maps gives an additive isomorphism between the two function spaces. See also `LinearEquiv.arrowCongr` for the linear version of this isomorphism. -/ @[simps] def arrowCongrAddEquiv (e₁ : M₁ ≃ₛₗ[σ₁₂] M₂) (e₂ : M₁' ≃ₛₗ[σ₁'₂'] M₂') : (M₁ →ₛₗ[σ₁₁'] M₁') ≃+ (M₂ →ₛₗ[σ₂₂'] M₂') where toFun f := (e₂.comp f).comp e₁.symm.toLinearMap invFun f := (e₂.symm.comp f).comp e₁.toLinearMap left_inv f := by ext x simp only [symm_apply_apply, Function.comp_apply, coe_comp, coe_coe] right_inv f := by ext x simp only [Function.comp_apply, apply_symm_apply, coe_comp, coe_coe] map_add' f g := by ext x simp only [map_add, add_apply, Function.comp_apply, coe_comp, coe_coe] /-- If `M` and `M₂` are linearly isomorphic then the endomorphism rings of `M` and `M₂` are isomorphic. See `LinearEquiv.conj` for the linear version of this isomorphism. -/ @[simps!] def conjRingEquiv (e : M₁ ≃ₛₗ[σ₁₂] M₂) : Module.End R₁ M₁ ≃+* Module.End R₂ M₂ where __ := arrowCongrAddEquiv e e map_mul' _ _ := by ext; simp [arrowCongrAddEquiv] /-- A linear isomorphism between the domains an codomains of two spaces of linear maps gives a linear isomorphism with respect to an action on the domains. -/ @[simps] def domMulActCongrRight [Semiring S] [Module S M₁] [SMulCommClass R₁ S M₁] [RingHomCompTriple σ₁₂' σ₂'₁' σ₁₁'] (e₂ : M₁' ≃ₛₗ[σ₁'₂'] M₂') : (M₁ →ₛₗ[σ₁₁'] M₁') ≃ₗ[Sᵈᵐᵃ] (M₁ →ₛₗ[σ₁₂'] M₂') where __ := arrowCongrAddEquiv (.refl ..) e₂ map_smul' := DomMulAct.mk.forall_congr_right.mp fun _ _ ↦ by ext; simp end Semilinear end Semiring section CommSemiring variable [CommSemiring R] [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] variable [Module R M] [Module R M₂] [Module R M₃] open LinearMap /-- Multiplying by a unit `a` of the ring `R` is a linear equivalence. -/ def smulOfUnit (a : Rˣ) : M ≃ₗ[R] M := DistribMulAction.toLinearEquiv R M a section arrowCongr -- Difference from above: `R₁` and `R₂` are commutative /-! The modules for `arrowCongr` and its lemmas below are related via the semilinearities ``` M₁ ←⎯⎯⎯σ₁₂⎯⎯⎯→ M₂ ←⎯⎯⎯σ₂₃⎯⎯⎯→ M₃ ⏐ ⏐ ⏐ σ₁₁' σ₂₂' σ₃₃' ↓ ↓ ↓ M₁' ←⎯⎯σ₁'₂'⎯⎯→ M₂' ←⎯⎯σ₂'₃'⎯⎯→ M₃ ⏐ ⏐ σ₁'₁'' σ₂'₂'' ↓ ↓ M₁''←⎯σ₁''₂''⎯→ M₂'' ``` where the horizontal direction corresponds to the `≃ₛₗ`s, and is needed for `arrowCongr_trans`, while the vertical direction corresponds to the `→ₛₗ`s, and is needed `arrowCongr_comp`. `Rᵢ` is not necessarily commutative, but `Rᵢ'` and `Rᵢ''` are. -/ variable {R₁ R₂ R₃ R₁' R₂' R₃' R₁'' R₂'' : Type*} {M₁ M₂ M₃ M₁' M₂' M₃' M₁'' M₂'' : Type*} variable [Semiring R₁] [Semiring R₂] [Semiring R₃] variable [CommSemiring R₁'] [CommSemiring R₂'] [CommSemiring R₃'] variable [CommSemiring R₁''] [CommSemiring R₂''] variable [AddCommMonoid M₁] [AddCommMonoid M₂] [AddCommMonoid M₃] variable [AddCommMonoid M₁'] [AddCommMonoid M₂'] [AddCommMonoid M₃'] variable [AddCommMonoid M₁''] [AddCommMonoid M₂''] variable [Module R₁ M₁] [Module R₂ M₂] [Module R₃ M₃] variable [Module R₁' M₁'] [Module R₂' M₂'] [Module R₃' M₃'] variable [Module R₁'' M₁''] [Module R₂'' M₂''] -- horizontal edges and closures variable {σ₁₂ : R₁ →+* R₂} {σ₂₁ : R₂ →+* R₁} variable {σ₂₃ : R₂ →+* R₃} {σ₃₂ : R₃ →+* R₂} variable {σ₁₃ : R₁ →+* R₃} {σ₃₁ : R₃ →+* R₁} variable {σ₁'₂' : R₁' →+* R₂'} {σ₂'₁' : R₂' →+* R₁'} variable {σ₂'₃' : R₂' →+* R₃'} {σ₃'₂' : R₃' →+* R₂'} variable {σ₁'₃' : R₁' →+* R₃'} {σ₃'₁' : R₃' →+* R₁'} -- vertical edges and closures variable {σ₁''₂'' : R₁'' →+* R₂''} {σ₂''₁'' : R₂'' →+* R₁''} variable {σ₁₁' : R₁ →+* R₁'} {σ₂₂' : R₂ →+* R₂'} {σ₃₃' : R₃ →+* R₃'} variable {σ₁'₁'' : R₁' →+* R₁''} {σ₂'₂'' : R₂' →+* R₂''} variable {σ₁₁'' : R₁ →+* R₁''} {σ₂₂'' : R₂ →+* R₂''} -- diagonals variable {σ₂₁' : R₂ →+* R₁'} {σ₁₂' : R₁ →+* R₂'} variable {σ₃₂' : R₃ →+* R₂'} {σ₂₃' : R₂ →+* R₃'} variable {σ₃₁' : R₃ →+* R₁'} {σ₁₃' : R₁ →+* R₃'} variable {σ₂'₁'' : R₂' →+* R₁''} {σ₁'₂'' : R₁' →+* R₂''} variable {σ₂₁'' : R₂ →+* R₁''} {σ₁₂'' : R₁ →+* R₂''} variable [RingHomInvPair σ₁₂ σ₂₁] [RingHomInvPair σ₂₁ σ₁₂] variable [RingHomInvPair σ₁'₂' σ₂'₁'] [RingHomInvPair σ₂'₁' σ₁'₂'] variable [RingHomInvPair σ₂₃ σ₃₂] [RingHomInvPair σ₃₂ σ₂₃] variable [RingHomInvPair σ₂'₃' σ₃'₂'] [RingHomInvPair σ₃'₂' σ₂'₃'] variable [RingHomInvPair σ₁₃ σ₃₁] [RingHomInvPair σ₃₁ σ₁₃] variable [RingHomInvPair σ₁'₃' σ₃'₁'] [RingHomInvPair σ₃'₁' σ₁'₃'] variable [RingHomInvPair σ₁''₂'' σ₂''₁''] [RingHomInvPair σ₂''₁'' σ₁''₂''] variable [RingHomCompTriple σ₁₁' σ₁'₁'' σ₁₁''] [RingHomCompTriple σ₂₂' σ₂'₂'' σ₂₂''] variable [RingHomCompTriple σ₁₁' σ₁'₂' σ₁₂'] [RingHomCompTriple σ₂₁ σ₁₂' σ₂₂'] variable [RingHomCompTriple σ₂₂' σ₂'₁' σ₂₁'] [RingHomCompTriple σ₁₂ σ₂₁' σ₁₁'] variable [RingHomCompTriple σ₁₁' σ₁'₃' σ₁₃'] [RingHomCompTriple σ₃₁ σ₁₃' σ₃₃'] variable [RingHomCompTriple σ₃₃' σ₃'₁' σ₃₁'] [RingHomCompTriple σ₁₃ σ₃₁' σ₁₁'] variable [RingHomCompTriple σ₂₂' σ₂'₃' σ₂₃'] [RingHomCompTriple σ₃₂ σ₂₃' σ₃₃'] variable [RingHomCompTriple σ₃₃' σ₃'₂' σ₃₂'] [RingHomCompTriple σ₂₃ σ₃₂' σ₂₂'] variable [RingHomCompTriple σ₁₁'' σ₁''₂'' σ₁₂''] [RingHomCompTriple σ₂₁ σ₁₂'' σ₂₂''] variable [RingHomCompTriple σ₂₂'' σ₂''₁'' σ₂₁''] [RingHomCompTriple σ₁₂ σ₂₁'' σ₁₁''] variable [RingHomCompTriple σ₁'₁'' σ₁''₂'' σ₁'₂''] [RingHomCompTriple σ₂'₁' σ₁'₂'' σ₂'₂''] variable [RingHomCompTriple σ₂'₂'' σ₂''₁'' σ₂'₁''] [RingHomCompTriple σ₁'₂' σ₂'₁'' σ₁'₁''] variable [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃] [RingHomCompTriple σ₃₂ σ₂₁ σ₃₁] variable [RingHomCompTriple σ₁'₂' σ₂'₃' σ₁'₃'] [RingHomCompTriple σ₃'₂' σ₂'₁' σ₃'₁'] /-- A linear isomorphism between the domains and codomains of two spaces of linear maps gives a linear isomorphism between the two function spaces. See `LinearEquiv.arrowCongrAddEquiv` for the additive version of this isomorphism that works over a not necessarily commutative semiring. -/ def arrowCongr (e₁ : M₁ ≃ₛₗ[σ₁₂] M₂) (e₂ : M₁' ≃ₛₗ[σ₁'₂'] M₂') : (M₁ →ₛₗ[σ₁₁'] M₁') ≃ₛₗ[σ₁'₂'] (M₂ →ₛₗ[σ₂₂'] M₂') where __ := arrowCongrAddEquiv e₁ e₂ map_smul' c f := by ext; simp [arrowCongrAddEquiv, map_smulₛₗ] @[simp] theorem arrowCongr_apply (e₁ : M₁ ≃ₛₗ[σ₁₂] M₂) (e₂ : M₁' ≃ₛₗ[σ₁'₂'] M₂') (f : M₁ →ₛₗ[σ₁₁'] M₁') (x : M₂) : arrowCongr e₁ e₂ f x = e₂ (f (e₁.symm x)) := rfl @[simp] theorem arrowCongr_symm_apply (e₁ : M₁ ≃ₛₗ[σ₁₂] M₂) (e₂ : M₁' ≃ₛₗ[σ₁'₂'] M₂') (f : M₂ →ₛₗ[σ₂₂'] M₂') (x : M₁) : (arrowCongr e₁ e₂).symm f x = e₂.symm (f (e₁ x)) := rfl theorem arrowCongr_comp (e₁ : M₁ ≃ₛₗ[σ₁₂] M₂) (e₂ : M₁' ≃ₛₗ[σ₁'₂'] M₂') (e₃ : M₁'' ≃ₛₗ[σ₁''₂''] M₂'') (f : M₁ →ₛₗ[σ₁₁'] M₁') (g : M₁' →ₛₗ[σ₁'₁''] M₁'') : arrowCongr e₁ e₃ (g.comp f) = (arrowCongr e₂ e₃ g).comp (arrowCongr e₁ e₂ f) := by ext simp only [symm_apply_apply, arrowCongr_apply, LinearMap.comp_apply] theorem arrowCongr_trans (e₁ : M₁ ≃ₛₗ[σ₁₂] M₂) (e₁' : M₁' ≃ₛₗ[σ₁'₂'] M₂') (e₂ : M₂ ≃ₛₗ[σ₂₃] M₃) (e₂' : M₂' ≃ₛₗ[σ₂'₃'] M₃') : ((arrowCongr e₁ e₁').trans (arrowCongr e₂ e₂' : (M₂ →ₛₗ[σ₂₂'] M₂') ≃ₛₗ[σ₂'₃'] _)) = arrowCongr (e₁.trans e₂) (e₁'.trans e₂') := rfl /-- If `M` and `M₂` are linearly isomorphic then the two spaces of linear maps from `M` and `M₂` to themselves are linearly isomorphic. See `LinearEquiv.conjRingEquiv` for the isomorphism between endomorphism rings, which works over a not necessarily commutative semiring. -/ -- TODO: upgrade to AlgEquiv (but this file currently cannot import AlgEquiv) def conj (e : M₁' ≃ₛₗ[σ₁'₂'] M₂') : Module.End R₁' M₁' ≃ₛₗ[σ₁'₂'] Module.End R₂' M₂' := arrowCongr e e theorem conj_apply (e : M₁' ≃ₛₗ[σ₁'₂'] M₂') (f : Module.End R₁' M₁') : e.conj f = ((↑e : M₁' →ₛₗ[σ₁'₂'] M₂').comp f).comp (e.symm : M₂' →ₛₗ[σ₂'₁'] M₁') := rfl theorem conj_apply_apply (e : M₁' ≃ₛₗ[σ₁'₂'] M₂') (f : Module.End R₁' M₁') (x : M₂') : e.conj f x = e (f (e.symm x)) := rfl theorem symm_conj_apply (e : M₁' ≃ₛₗ[σ₁'₂'] M₂') (f : Module.End R₂' M₂') : e.symm.conj f = ((↑e.symm : M₂' →ₛₗ[σ₂'₁'] M₁').comp f).comp (e : M₁' →ₛₗ[σ₁'₂'] M₂') := rfl theorem conj_comp (e : M₁' ≃ₛₗ[σ₁'₂'] M₂') (f g : Module.End R₁' M₁') : e.conj (g.comp f) = (e.conj g).comp (e.conj f) := arrowCongr_comp e e e f g theorem conj_trans (e₁ : M₁' ≃ₛₗ[σ₁'₂'] M₂') (e₂ : M₂' ≃ₛₗ[σ₂'₃'] M₃') : e₁.conj.trans e₂.conj = (e₁.trans e₂).conj := rfl @[simp] lemma conj_conj_symm (e : M₁' ≃ₛₗ[σ₁'₂'] M₂') (f : Module.End R₂' M₂') : e.conj (e.symm.conj f) = f := by ext; simp [conj_apply] @[simp] lemma conj_symm_conj (e : M₁' ≃ₛₗ[σ₁'₂'] M₂') (f : Module.End R₁' M₁') : e.symm.conj (e.conj f) = f := by ext; simp [conj_apply] @[simp] theorem conj_id (e : M₁' ≃ₛₗ[σ₁'₂'] M₂') : e.conj LinearMap.id = LinearMap.id := by simp [conj_apply] @[simp] theorem conj_refl (f : Module.End R M) : (refl R M).conj f = f := rfl end arrowCongr /-- If `M₂` and `M₃` are linearly isomorphic then the two spaces of linear maps from `M` into `M₂` and `M` into `M₃` are linearly isomorphic. -/ def congrRight (f : M₂ ≃ₗ[R] M₃) : (M →ₗ[R] M₂) ≃ₗ[R] M →ₗ[R] M₃ := arrowCongr (LinearEquiv.refl R M) f variable (M) in /-- An `R`-linear isomorphism between two `R`-modules `M₂` and `M₃` induces an `S`-linear isomorphism between `M₂ →ₗ[R] M` and `M₃ →ₗ[R] M`, if `M` is both an `R`-module and an `S`-module and their actions commute. -/ def congrLeft {R} (S) [Semiring R] [Semiring S] [Module R M₂] [Module R M₃] [Module R M] [Module S M] [SMulCommClass R S M] (e : M₂ ≃ₗ[R] M₃) : (M₂ →ₗ[R] M) ≃ₗ[S] (M₃ →ₗ[R] M) where __ := e.arrowCongrAddEquiv (.refl ..) map_smul' _ _ := rfl end CommSemiring section Field variable [Field K] [AddCommGroup M] [Module K M] variable (K) (M) open LinearMap /-- Multiplying by a nonzero element `a` of the field `K` is a linear equivalence. -/ @[simps!] def smulOfNeZero (a : K) (ha : a ≠ 0) : M ≃ₗ[K] M := smulOfUnit <| Units.mk0 a ha end Field end LinearEquiv namespace Equiv variable [Semiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid M₂] [Module R M₂] /-- An equivalence whose underlying function is linear is a linear equivalence. -/ def toLinearEquiv (e : M ≃ M₂) (h : IsLinearMap R (e : M → M₂)) : M ≃ₗ[R] M₂ := { e, h.mk' e with } end Equiv section FunLeft variable (R M) [Semiring R] [AddCommMonoid M] [Module R M] variable {m n p : Type*} namespace LinearMap /-- Given an `R`-module `M` and a function `m → n` between arbitrary types, construct a linear map `(n → M) →ₗ[R] (m → M)` -/ def funLeft (f : m → n) : (n → M) →ₗ[R] m → M where toFun := (· ∘ f) map_add' _ _ := rfl map_smul' _ _ := rfl @[simp] theorem funLeft_apply (f : m → n) (g : n → M) (i : m) : funLeft R M f g i = g (f i) := rfl @[simp] theorem funLeft_id (g : n → M) : funLeft R M _root_.id g = g := rfl theorem funLeft_comp (f₁ : n → p) (f₂ : m → n) : funLeft R M (f₁ ∘ f₂) = (funLeft R M f₂).comp (funLeft R M f₁) := rfl theorem funLeft_surjective_of_injective (f : m → n) (hf : Injective f) : Surjective (funLeft R M f) := hf.surjective_comp_right theorem funLeft_injective_of_surjective (f : m → n) (hf : Surjective f) : Injective (funLeft R M f) := hf.injective_comp_right end LinearMap namespace LinearEquiv open LinearMap /-- Given an `R`-module `M` and an equivalence `m ≃ n` between arbitrary types, construct a linear equivalence `(n → M) ≃ₗ[R] (m → M)` -/ def funCongrLeft (e : m ≃ n) : (n → M) ≃ₗ[R] m → M := LinearEquiv.ofLinear (funLeft R M e) (funLeft R M e.symm) (LinearMap.ext fun x ↦ funext fun i ↦ by rw [id_apply, ← funLeft_comp, Equiv.symm_comp_self, LinearMap.funLeft_id]) (LinearMap.ext fun x ↦ funext fun i ↦ by rw [id_apply, ← funLeft_comp, Equiv.self_comp_symm, LinearMap.funLeft_id]) @[simp] theorem funCongrLeft_apply (e : m ≃ n) (x : n → M) : funCongrLeft R M e x = funLeft R M e x := rfl @[simp] theorem funCongrLeft_id : funCongrLeft R M (Equiv.refl n) = LinearEquiv.refl R (n → M) := rfl @[simp] theorem funCongrLeft_comp (e₁ : m ≃ n) (e₂ : n ≃ p) : funCongrLeft R M (Equiv.trans e₁ e₂) = LinearEquiv.trans (funCongrLeft R M e₂) (funCongrLeft R M e₁) := rfl @[simp] theorem funCongrLeft_symm (e : m ≃ n) : (funCongrLeft R M e).symm = funCongrLeft R M e.symm := rfl end LinearEquiv end FunLeft section Pi namespace LinearEquiv /-- The product over `S ⊕ T` of a family of modules is isomorphic to the product of (the product over `S`) and (the product over `T`). This is `Equiv.sumPiEquivProdPi` as a `LinearEquiv`. -/ @[simps -fullyApplied +simpRhs] def sumPiEquivProdPi (R : Type*) [Semiring R] (S T : Type*) (A : S ⊕ T → Type*) [∀ st, AddCommMonoid (A st)] [∀ st, Module R (A st)] : (Π (st : S ⊕ T), A st) ≃ₗ[R] (Π (s : S), A (.inl s)) × (Π (t : T), A (.inr t)) where __ := Equiv.sumPiEquivProdPi _ map_add' _ _ := rfl map_smul' _ _ := rfl /-- The product `Π t : α, f t` of a family of modules is linearly isomorphic to the module `f ⬝` when `α` only contains `⬝`. This is `Equiv.piUnique` as a `LinearEquiv`. -/ @[simps -fullyApplied] def piUnique {α : Type*} [Unique α] (R : Type*) [Semiring R] (f : α → Type*) [∀ x, AddCommMonoid (f x)] [∀ x, Module R (f x)] : (Π t : α, f t) ≃ₗ[R] f default where __ := Equiv.piUnique _ map_add' _ _ := rfl map_smul' _ _ := rfl end LinearEquiv end Pi end AddCommMonoid
.lake/packages/mathlib/Mathlib/Algebra/Module/Equiv/Defs.lean
import Mathlib.Algebra.Module.LinearMap.Defs /-! # (Semi)linear equivalences In this file we define * `LinearEquiv σ M M₂`, `M ≃ₛₗ[σ] M₂`: an invertible semilinear map. Here, `σ` is a `RingHom` from `R` to `R₂` and an `e : M ≃ₛₗ[σ] M₂` satisfies `e (c • x) = (σ c) • (e x)`. The plain linear version, with `σ` being `RingHom.id R`, is denoted by `M ≃ₗ[R] M₂`, and the star-linear version (with `σ` being `starRingEnd`) is denoted by `M ≃ₗ⋆[R] M₂`. ## Implementation notes To ensure that composition works smoothly for semilinear equivalences, we use the typeclasses `RingHomCompTriple`, `RingHomInvPair` and `RingHomSurjective` from `Algebra/Ring/CompTypeclasses`. The group structure on automorphisms, `LinearEquiv.automorphismGroup`, is provided elsewhere. ## TODO * Parts of this file have not yet been generalized to semilinear maps ## Tags linear equiv, linear equivalences, linear isomorphism, linear isomorphic -/ assert_not_exists Field Pi.module open Function variable {R R₁ R₂ R₃ R₄ S M M₁ M₂ M₃ M₄ N₁ N₂ : Type*} section /-- A linear equivalence is an invertible linear map. -/ structure LinearEquiv {R : Type*} {S : Type*} [Semiring R] [Semiring S] (σ : R →+* S) {σ' : S →+* R} [RingHomInvPair σ σ'] [RingHomInvPair σ' σ] (M : Type*) (M₂ : Type*) [AddCommMonoid M] [AddCommMonoid M₂] [Module R M] [Module S M₂] extends LinearMap σ M M₂, M ≃+ M₂ attribute [coe] LinearEquiv.toLinearMap /-- The linear map underlying a linear equivalence. -/ add_decl_doc LinearEquiv.toLinearMap /-- The additive equivalence of types underlying a linear equivalence. -/ add_decl_doc LinearEquiv.toAddEquiv /-- The backwards directed function underlying a linear equivalence. -/ add_decl_doc LinearEquiv.invFun /-- `LinearEquiv.invFun` is a right inverse to the linear equivalence's underlying function. -/ add_decl_doc LinearEquiv.right_inv /-- `LinearEquiv.invFun` is a left inverse to the linear equivalence's underlying function. -/ add_decl_doc LinearEquiv.left_inv /-- `M ≃ₛₗ[σ] M₂` denotes the type of linear equivalences between `M` and `M₂` over a ring homomorphism `σ`. -/ notation:50 M " ≃ₛₗ[" σ "] " M₂ => LinearEquiv σ M M₂ /-- `M ≃ₗ[R] M₂` denotes the type of linear equivalences between `M` and `M₂` over a plain linear map `M →ₗ M₂`. -/ notation:50 M " ≃ₗ[" R "] " M₂ => LinearEquiv (RingHom.id R) M M₂ /-- `SemilinearEquivClass F σ M M₂` asserts `F` is a type of bundled `σ`-semilinear equivs `M → M₂`. See also `LinearEquivClass F R M M₂` for the case where `σ` is the identity map on `R`. A map `f` between an `R`-module and an `S`-module over a ring homomorphism `σ : R →+* S` is semilinear if it satisfies the two properties `f (x + y) = f x + f y` and `f (c • x) = (σ c) • f x`. -/ class SemilinearEquivClass (F : Type*) {R S : outParam Type*} [Semiring R] [Semiring S] (σ : outParam <| R →+* S) {σ' : outParam <| S →+* R} [RingHomInvPair σ σ'] [RingHomInvPair σ' σ] (M M₂ : outParam Type*) [AddCommMonoid M] [AddCommMonoid M₂] [Module R M] [Module S M₂] [EquivLike F M M₂] : Prop extends AddEquivClass F M M₂ where /-- Applying a semilinear equivalence `f` over `σ` to `r • x` equals `σ r • f x`. -/ map_smulₛₗ : ∀ (f : F) (r : R) (x : M), f (r • x) = σ r • f x -- `R, S, σ, σ'` become metavars, but it's OK since they are outparams. /-- `LinearEquivClass F R M M₂` asserts `F` is a type of bundled `R`-linear equivs `M → M₂`. This is an abbreviation for `SemilinearEquivClass F (RingHom.id R) M M₂`. -/ abbrev LinearEquivClass (F : Type*) (R M M₂ : outParam Type*) [Semiring R] [AddCommMonoid M] [AddCommMonoid M₂] [Module R M] [Module R M₂] [EquivLike F M M₂] := SemilinearEquivClass F (RingHom.id R) M M₂ end namespace SemilinearEquivClass variable (F : Type*) [Semiring R] [Semiring S] variable [AddCommMonoid M] [AddCommMonoid M₁] [AddCommMonoid M₂] variable [Module R M] [Module S M₂] {σ : R →+* S} {σ' : S →+* R} instance (priority := 100) [RingHomInvPair σ σ'] [RingHomInvPair σ' σ] [EquivLike F M M₂] [s : SemilinearEquivClass F σ M M₂] : SemilinearMapClass F σ M M₂ := { s with } variable {F} /-- Reinterpret an element of a type of semilinear equivalences as a semilinear equivalence. -/ @[coe] def semilinearEquiv [RingHomInvPair σ σ'] [RingHomInvPair σ' σ] [EquivLike F M M₂] [SemilinearEquivClass F σ M M₂] (f : F) : M ≃ₛₗ[σ] M₂ := { (f : M ≃+ M₂), (f : M →ₛₗ[σ] M₂) with } /-- Reinterpret an element of a type of semilinear equivalences as a semilinear equivalence. -/ instance instCoeToSemilinearEquiv [RingHomInvPair σ σ'] [RingHomInvPair σ' σ] [EquivLike F M M₂] [SemilinearEquivClass F σ M M₂] : CoeHead F (M ≃ₛₗ[σ] M₂) where coe f := semilinearEquiv f end SemilinearEquivClass namespace LinearEquiv section AddCommMonoid variable [Semiring R] [Semiring S] section variable [AddCommMonoid M] [AddCommMonoid M₁] [AddCommMonoid M₂] variable [Module R M] [Module S M₂] {σ : R →+* S} {σ' : S →+* R} variable [RingHomInvPair σ σ'] [RingHomInvPair σ' σ] instance : Coe (M ≃ₛₗ[σ] M₂) (M →ₛₗ[σ] M₂) := ⟨toLinearMap⟩ -- This exists for compatibility, previously `≃ₗ[R]` extended `≃` instead of `≃+`. /-- The equivalence of types underlying a linear equivalence. -/ def toEquiv : (M ≃ₛₗ[σ] M₂) → M ≃ M₂ := fun f ↦ f.toAddEquiv.toEquiv theorem toEquiv_injective : Function.Injective (toEquiv : (M ≃ₛₗ[σ] M₂) → M ≃ M₂) := fun ⟨⟨⟨_, _⟩, _⟩, _, _, _⟩ ⟨⟨⟨_, _⟩, _⟩, _, _, _⟩ h ↦ (LinearEquiv.mk.injEq _ _ _ _ _ _ _ _).mpr ⟨LinearMap.ext (congr_fun (Equiv.mk.inj h).1), (Equiv.mk.inj h).2⟩ @[simp] theorem toEquiv_inj {e₁ e₂ : M ≃ₛₗ[σ] M₂} : e₁.toEquiv = e₂.toEquiv ↔ e₁ = e₂ := toEquiv_injective.eq_iff theorem toLinearMap_injective : Injective (toLinearMap : (M ≃ₛₗ[σ] M₂) → M →ₛₗ[σ] M₂) := fun _ _ H ↦ toEquiv_injective <| Equiv.ext <| LinearMap.congr_fun H @[simp, norm_cast] theorem toLinearMap_inj {e₁ e₂ : M ≃ₛₗ[σ] M₂} : (↑e₁ : M →ₛₗ[σ] M₂) = e₂ ↔ e₁ = e₂ := toLinearMap_injective.eq_iff instance : EquivLike (M ≃ₛₗ[σ] M₂) M M₂ where coe e := e.toFun inv := LinearEquiv.invFun coe_injective' _ _ h _ := toLinearMap_injective (DFunLike.coe_injective h) left_inv := LinearEquiv.left_inv right_inv := LinearEquiv.right_inv instance : SemilinearEquivClass (M ≃ₛₗ[σ] M₂) σ M M₂ where map_add := (·.map_add') map_smulₛₗ := (·.map_smul') theorem toLinearMap_eq_coe {e : M ≃ₛₗ[σ] M₂} : e.toLinearMap = SemilinearMapClass.semilinearMap e := rfl @[simp] theorem coe_mk {f invFun left_inv right_inv} : ((⟨f, invFun, left_inv, right_inv⟩ : M ≃ₛₗ[σ] M₂) : M → M₂) = f := rfl theorem coe_injective : @Injective (M ≃ₛₗ[σ] M₂) (M → M₂) DFunLike.coe := DFunLike.coe_injective @[simp] lemma _root_.SemilinearEquivClass.semilinearEquiv_apply {F : Type*} [EquivLike F M M₂] [SemilinearEquivClass F σ M M₂] (f : F) (x : M) : SemilinearEquivClass.semilinearEquiv (M₂ := M₂) f x = f x := rfl end section variable [Semiring R₁] [Semiring R₂] [Semiring R₃] [Semiring R₄] variable [AddCommMonoid M] [AddCommMonoid M₁] [AddCommMonoid M₂] [AddCommMonoid M₃] variable [AddCommMonoid M₄] variable [AddCommMonoid N₁] [AddCommMonoid N₂] variable {module_M : Module R M} {module_S_M₂ : Module S M₂} {σ : R →+* S} {σ' : S →+* R} variable {re₁ : RingHomInvPair σ σ'} {re₂ : RingHomInvPair σ' σ} variable (e e' : M ≃ₛₗ[σ] M₂) @[simp, norm_cast] theorem coe_coe : ⇑(e : M →ₛₗ[σ] M₂) = e := rfl @[simp] theorem coe_toEquiv : ⇑(e.toEquiv) = e := rfl @[simp] theorem coe_toLinearMap : ⇑e.toLinearMap = e := rfl theorem toFun_eq_coe : e.toFun = e := by dsimp section variable {e e'} @[ext] theorem ext (h : ∀ x, e x = e' x) : e = e' := DFunLike.ext _ _ h protected theorem congr_arg {x x'} : x = x' → e x = e x' := DFunLike.congr_arg e protected theorem congr_fun (h : e = e') (x : M) : e x = e' x := DFunLike.congr_fun h x end section variable (M R) /-- The identity map is a linear equivalence. -/ @[refl] def refl [Module R M] : M ≃ₗ[R] M := { LinearMap.id, Equiv.refl M with } end @[simp] theorem refl_apply [Module R M] (x : M) : refl R M x = x := rfl /-- Linear equivalences are symmetric. -/ @[symm] def symm (e : M ≃ₛₗ[σ] M₂) : M₂ ≃ₛₗ[σ'] M := { e.toLinearMap.inverse e.invFun e.left_inv e.right_inv, e.toEquiv.symm with toFun := e.toLinearMap.inverse e.invFun e.left_inv e.right_inv invFun := e.toEquiv.symm.invFun map_smul' r x := by rw [map_smulₛₗ] } /-- See Note [custom simps projection] -/ def Simps.apply {R : Type*} {S : Type*} [Semiring R] [Semiring S] {σ : R →+* S} {σ' : S →+* R} [RingHomInvPair σ σ'] [RingHomInvPair σ' σ] {M : Type*} {M₂ : Type*} [AddCommMonoid M] [AddCommMonoid M₂] [Module R M] [Module S M₂] (e : M ≃ₛₗ[σ] M₂) : M → M₂ := e /-- See Note [custom simps projection] -/ def Simps.symm_apply {R S : Type*} [Semiring R] [Semiring S] {σ : R →+* S} {σ' : S →+* R} [RingHomInvPair σ σ'] [RingHomInvPair σ' σ] {M M₂ : Type*} [AddCommMonoid M] [AddCommMonoid M₂] [Module R M] [Module S M₂] (e : M ≃ₛₗ[σ] M₂) : M₂ → M := e.symm initialize_simps_projections LinearEquiv (toFun → apply, invFun → symm_apply) @[simp] theorem invFun_eq_symm : e.invFun = e.symm := rfl theorem coe_toEquiv_symm : e.toEquiv.symm = e.symm := rfl @[simp] theorem toEquiv_symm : e.symm.toEquiv = e.toEquiv.symm := rfl @[simp] theorem coe_symm_toEquiv : ⇑e.toEquiv.symm = e.symm := rfl variable {module_M₁ : Module R₁ M₁} {module_M₂ : Module R₂ M₂} {module_M₃ : Module R₃ M₃} variable {module_M₄ : Module R₄ M₄} {module_N₁ : Module R₁ N₁} {module_N₂ : Module R₁ N₂} variable {σ₁₂ : R₁ →+* R₂} {σ₂₁ : R₂ →+* R₁} variable {σ₁₃ : R₁ →+* R₃} {σ₃₁ : R₃ →+* R₁} [RingHomInvPair σ₁₃ σ₃₁] [RingHomInvPair σ₃₁ σ₁₃] variable {σ₁₄ : R₁ →+* R₄} {σ₄₁ : R₄ →+* R₁} [RingHomInvPair σ₁₄ σ₄₁] [RingHomInvPair σ₄₁ σ₁₄] variable {σ₂₃ : R₂ →+* R₃} {σ₃₂ : R₃ →+* R₂} variable {σ₂₄ : R₂ →+* R₄} {σ₄₂ : R₄ →+* R₂} [RingHomInvPair σ₂₄ σ₄₂] [RingHomInvPair σ₄₂ σ₂₄] variable {σ₃₄ : R₃ →+* R₄} {σ₄₃ : R₄ →+* R₃} [RingHomInvPair σ₃₄ σ₄₃] [RingHomInvPair σ₄₃ σ₃₄] variable {re₁₂ : RingHomInvPair σ₁₂ σ₂₁} {re₂₁ : RingHomInvPair σ₂₁ σ₁₂} variable {re₂₃ : RingHomInvPair σ₂₃ σ₃₂} {re₃₂ : RingHomInvPair σ₃₂ σ₂₃} variable [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃] [RingHomCompTriple σ₃₂ σ₂₁ σ₃₁] variable [RingHomCompTriple σ₁₂ σ₂₄ σ₁₄] [RingHomCompTriple σ₄₂ σ₂₁ σ₄₁] variable [RingHomCompTriple σ₁₃ σ₃₄ σ₁₄] [RingHomCompTriple σ₄₃ σ₃₁ σ₄₁] variable [RingHomCompTriple σ₂₃ σ₃₄ σ₂₄] [RingHomCompTriple σ₄₃ σ₃₂ σ₄₂] variable (e₁₂ : M₁ ≃ₛₗ[σ₁₂] M₂) (e₂₃ : M₂ ≃ₛₗ[σ₂₃] M₃) /-- Linear equivalences are transitive. -/ -- Note: the `RingHomCompTriple σ₃₂ σ₂₁ σ₃₁` is unused, but is convenient to carry around -- implicitly for lemmas like `LinearEquiv.self_trans_symm`. @[trans, nolint unusedArguments] def trans [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃] [RingHomCompTriple σ₃₂ σ₂₁ σ₃₁] {re₁₂ : RingHomInvPair σ₁₂ σ₂₁} {re₂₃ : RingHomInvPair σ₂₃ σ₃₂} [RingHomInvPair σ₁₃ σ₃₁] {re₂₁ : RingHomInvPair σ₂₁ σ₁₂} {re₃₂ : RingHomInvPair σ₃₂ σ₂₃} [RingHomInvPair σ₃₁ σ₁₃] (e₁₂ : M₁ ≃ₛₗ[σ₁₂] M₂) (e₂₃ : M₂ ≃ₛₗ[σ₂₃] M₃) : M₁ ≃ₛₗ[σ₁₃] M₃ := { e₂₃.toLinearMap.comp e₁₂.toLinearMap, e₁₂.toEquiv.trans e₂₃.toEquiv with } /-- `e₁ ≪≫ₗ e₂` denotes the composition of the linear equivalences `e₁` and `e₂`. -/ notation3:80 (name := transNotation) e₁:80 " ≪≫ₗ " e₂:81 => @LinearEquiv.trans _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ (RingHom.id _) (RingHom.id _) (RingHom.id _) (RingHom.id _) (RingHom.id _) (RingHom.id _) RingHomCompTriple.ids RingHomCompTriple.ids RingHomInvPair.ids RingHomInvPair.ids RingHomInvPair.ids RingHomInvPair.ids RingHomInvPair.ids RingHomInvPair.ids e₁ e₂ /-- `LinearEquiv.symm` defines an equivalence between `α ≃ₛₗ[σ] β` and `β ≃ₛₗ[σ] α`. -/ @[simps!] def symmEquiv : (M ≃ₛₗ[σ] M₂) ≃ (M₂ ≃ₛₗ[σ'] M) where toFun := .symm invFun := .symm variable {e₁₂} {e₂₃} theorem coe_toAddEquiv : e.toAddEquiv = e := rfl @[simp] lemma coe_addEquiv_apply (x : M) : (e : M ≃+ M₂) x = e x := rfl /-- The two paths coercion can take to an `AddMonoidHom` are equivalent -/ theorem toAddMonoidHom_commutes : e.toLinearMap.toAddMonoidHom = e.toAddEquiv.toAddMonoidHom := rfl lemma coe_toAddEquiv_symm : (e₁₂.symm : M₂ ≃+ M₁) = (e₁₂ : M₁ ≃+ M₂).symm := rfl @[simp] theorem trans_apply (c : M₁) : (e₁₂.trans e₂₃ : M₁ ≃ₛₗ[σ₁₃] M₃) c = e₂₃ (e₁₂ c) := rfl theorem coe_trans : (e₁₂.trans e₂₃ : M₁ →ₛₗ[σ₁₃] M₃) = (e₂₃ : M₂ →ₛₗ[σ₂₃] M₃).comp (e₁₂ : M₁ →ₛₗ[σ₁₂] M₂) := rfl @[simp] theorem apply_symm_apply (c : M₂) : e (e.symm c) = c := e.right_inv c @[simp] theorem symm_apply_apply (b : M) : e.symm (e b) = b := e.left_inv b theorem comp_symm : e.toLinearMap ∘ₛₗ e.symm.toLinearMap = LinearMap.id := LinearMap.ext e.apply_symm_apply theorem symm_comp : e.symm.toLinearMap ∘ₛₗ e.toLinearMap = LinearMap.id := LinearMap.ext e.symm_apply_apply @[simp] theorem trans_symm : (e₁₂.trans e₂₃ : M₁ ≃ₛₗ[σ₁₃] M₃).symm = e₂₃.symm.trans e₁₂.symm := rfl theorem symm_trans_apply (c : M₃) : (e₁₂.trans e₂₃ : M₁ ≃ₛₗ[σ₁₃] M₃).symm c = e₁₂.symm (e₂₃.symm c) := rfl @[simp] theorem trans_refl : e.trans (refl S M₂) = e := toEquiv_injective e.toEquiv.trans_refl @[simp] theorem refl_trans : (refl R M).trans e = e := toEquiv_injective e.toEquiv.refl_trans theorem symm_apply_eq {x y} : e.symm x = y ↔ x = e y := e.toEquiv.symm_apply_eq theorem eq_symm_apply {x y} : y = e.symm x ↔ e y = x := e.toEquiv.eq_symm_apply theorem eq_comp_symm {α : Type*} (f : M₂ → α) (g : M₁ → α) : f = g ∘ e₁₂.symm ↔ f ∘ e₁₂ = g := e₁₂.toEquiv.eq_comp_symm f g theorem comp_symm_eq {α : Type*} (f : M₂ → α) (g : M₁ → α) : g ∘ e₁₂.symm = f ↔ g = f ∘ e₁₂ := e₁₂.toEquiv.comp_symm_eq f g theorem eq_symm_comp {α : Type*} (f : α → M₁) (g : α → M₂) : f = e₁₂.symm ∘ g ↔ e₁₂ ∘ f = g := e₁₂.toEquiv.eq_symm_comp f g theorem symm_comp_eq {α : Type*} (f : α → M₁) (g : α → M₂) : e₁₂.symm ∘ g = f ↔ g = e₁₂ ∘ f := e₁₂.toEquiv.symm_comp_eq f g @[simp] theorem comp_coe (f : M₁ ≃ₛₗ[σ₁₂] M₂) (f' : M₂ ≃ₛₗ[σ₂₃] M₃) : (f' : M₂ →ₛₗ[σ₂₃] M₃).comp (f : M₁ →ₛₗ[σ₁₂] M₂) = (f.trans f' : M₁ ≃ₛₗ[σ₁₃] M₃) := rfl lemma trans_assoc (e₁₂ : M₁ ≃ₛₗ[σ₁₂] M₂) (e₂₃ : M₂ ≃ₛₗ[σ₂₃] M₃) (e₃₄ : M₃ ≃ₛₗ[σ₃₄] M₄) : (e₁₂.trans e₂₃).trans e₃₄ = e₁₂.trans (e₂₃.trans e₃₄) := rfl variable [RingHomCompTriple σ₂₁ σ₁₃ σ₂₃] [RingHomCompTriple σ₃₁ σ₁₂ σ₃₂] theorem eq_comp_toLinearMap_symm (f : M₂ →ₛₗ[σ₂₃] M₃) (g : M₁ →ₛₗ[σ₁₃] M₃) : f = g.comp e₁₂.symm.toLinearMap ↔ f.comp e₁₂.toLinearMap = g := by constructor <;> intro H <;> ext · simp [H] · simp [← H] theorem comp_toLinearMap_symm_eq (f : M₂ →ₛₗ[σ₂₃] M₃) (g : M₁ →ₛₗ[σ₁₃] M₃) : g.comp e₁₂.symm.toLinearMap = f ↔ g = f.comp e₁₂.toLinearMap := by constructor <;> intro H <;> ext · simp [← H] · simp [H] theorem eq_toLinearMap_symm_comp (f : M₃ →ₛₗ[σ₃₁] M₁) (g : M₃ →ₛₗ[σ₃₂] M₂) : f = e₁₂.symm.toLinearMap.comp g ↔ e₁₂.toLinearMap.comp f = g := by constructor <;> intro H <;> ext · simp [H] · simp [← H] theorem toLinearMap_symm_comp_eq (f : M₃ →ₛₗ[σ₃₁] M₁) (g : M₃ →ₛₗ[σ₃₂] M₂) : e₁₂.symm.toLinearMap.comp g = f ↔ g = e₁₂.toLinearMap.comp f := by constructor <;> intro H <;> ext · simp [← H] · simp [H] @[simp] theorem comp_toLinearMap_eq_iff (f g : M₃ →ₛₗ[σ₃₁] M₁) : e₁₂.toLinearMap.comp f = e₁₂.toLinearMap.comp g ↔ f = g := by refine ⟨fun h => ?_, congrArg e₁₂.comp⟩ rw [← (toLinearMap_symm_comp_eq g (e₁₂.toLinearMap.comp f)).mpr h, eq_toLinearMap_symm_comp] @[simp] theorem eq_comp_toLinearMap_iff (f g : M₂ →ₛₗ[σ₂₃] M₃) : f.comp e₁₂.toLinearMap = g.comp e₁₂.toLinearMap ↔ f = g := by refine ⟨fun h => ?_, fun a ↦ congrFun (congrArg LinearMap.comp a) e₁₂.toLinearMap⟩ rw [(eq_comp_toLinearMap_symm g (f.comp e₁₂.toLinearMap)).mpr h.symm, eq_comp_toLinearMap_symm] lemma comp_symm_cancel_left (e : M₁ ≃ₛₗ[σ₁₂] M₂) (f : M₃ →ₛₗ[σ₃₂] M₂) : e.toLinearMap ∘ₛₗ (e.symm.toLinearMap ∘ₛₗ f) = f := by ext; simp lemma symm_comp_cancel_left (e : M₁ ≃ₛₗ[σ₁₂] M₂) (f : M₃ →ₛₗ[σ₃₁] M₁) : e.symm.toLinearMap ∘ₛₗ (e.toLinearMap ∘ₛₗ f) = f := by ext; simp lemma comp_symm_cancel_right (e : M₁ ≃ₛₗ[σ₁₂] M₂) (f : M₂ →ₛₗ[σ₂₃] M₃) : (f ∘ₛₗ e.toLinearMap) ∘ₛₗ e.symm.toLinearMap = f := by ext; simp lemma symm_comp_cancel_right (e : M₁ ≃ₛₗ[σ₁₂] M₂) (f : M₁ →ₛₗ[σ₁₃] M₃) : (f ∘ₛₗ e.symm.toLinearMap) ∘ₛₗ e.toLinearMap = f := by ext; simp lemma trans_symm_cancel_left (e : M₁ ≃ₛₗ[σ₁₂] M₂) (f : M₁ ≃ₛₗ[σ₁₃] M₃) : e.trans (e.symm.trans f) = f := by ext; simp lemma symm_trans_cancel_left (e : M₁ ≃ₛₗ[σ₁₂] M₂) (f : M₂ ≃ₛₗ[σ₂₃] M₃) : e.symm.trans (e.trans f) = f := by ext; simp lemma trans_symm_cancel_right (e : M₁ ≃ₛₗ[σ₁₂] M₂) (f : M₃ ≃ₛₗ[σ₃₁] M₁) : (f.trans e).trans e.symm = f := by ext; simp lemma symm_trans_cancel_right (e : M₁ ≃ₛₗ[σ₁₂] M₂) (f : M₃ ≃ₛₗ[σ₃₂] M₂) : (f.trans e.symm).trans e = f := by ext; simp @[simp] theorem refl_symm [Module R M] : (refl R M).symm = LinearEquiv.refl R M := rfl @[simp] theorem self_trans_symm (f : M₁ ≃ₛₗ[σ₁₂] M₂) : f.trans f.symm = LinearEquiv.refl R₁ M₁ := by ext x simp @[simp] theorem symm_trans_self (f : M₁ ≃ₛₗ[σ₁₂] M₂) : f.symm.trans f = LinearEquiv.refl R₂ M₂ := by ext x simp @[simp] theorem refl_toLinearMap [Module R M] : (LinearEquiv.refl R M : M →ₗ[R] M) = LinearMap.id := rfl @[simp] theorem mk_coe (f h₁ h₂) : (LinearEquiv.mk e f h₁ h₂ : M ≃ₛₗ[σ] M₂) = e := ext fun _ ↦ rfl protected theorem map_add (a b : M) : e (a + b) = e a + e b := map_add e a b protected theorem map_zero : e 0 = 0 := map_zero e protected theorem map_smulₛₗ (c : R) (x : M) : e (c • x) = (σ : R → S) c • e x := e.map_smul' c x theorem map_smul (e : N₁ ≃ₗ[R₁] N₂) (c : R₁) (x : N₁) : e (c • x) = c • e x := map_smulₛₗ e c x theorem map_eq_zero_iff {x : M} : e x = 0 ↔ x = 0 := e.toAddEquiv.map_eq_zero_iff theorem map_ne_zero_iff {x : M} : e x ≠ 0 ↔ x ≠ 0 := e.toAddEquiv.map_ne_zero_iff @[simp] theorem symm_symm (e : M ≃ₛₗ[σ] M₂) : e.symm.symm = e := rfl theorem symm_bijective [Module R M] [Module S M₂] [RingHomInvPair σ' σ] [RingHomInvPair σ σ'] : Function.Bijective (symm : (M ≃ₛₗ[σ] M₂) → M₂ ≃ₛₗ[σ'] M) := Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩ @[simp] theorem mk_coe' (f h₁ h₂ h₃ h₄) : (LinearEquiv.mk ⟨⟨f, h₁⟩, h₂⟩ (⇑e) h₃ h₄ : M₂ ≃ₛₗ[σ'] M) = e.symm := symm_bijective.injective <| ext fun _ ↦ rfl /-- Auxiliary definition to avoid looping in `dsimp` with `LinearEquiv.symm_mk`. -/ protected def symm_mk.aux (f h₁ h₂ h₃ h₄) := (⟨⟨⟨e, h₁⟩, h₂⟩, f, h₃, h₄⟩ : M ≃ₛₗ[σ] M₂).symm @[simp] theorem symm_mk (f h₁ h₂ h₃ h₄) : (⟨⟨⟨e, h₁⟩, h₂⟩, f, h₃, h₄⟩ : M ≃ₛₗ[σ] M₂).symm = { symm_mk.aux e f h₁ h₂ h₃ h₄ with toFun := f invFun := e } := rfl /-- For a more powerful version, see `coe_symm_mk'`. -/ theorem coe_symm_mk [Module R M] [Module R M₂] {to_fun inv_fun map_add map_smul left_inv right_inv} : ⇑(⟨⟨⟨to_fun, map_add⟩, map_smul⟩, inv_fun, left_inv, right_inv⟩ : M ≃ₗ[R] M₂).symm = inv_fun := rfl @[simp] theorem coe_symm_mk' [Module R M] [Module R M₂] {f inv_fun left_inv right_inv} : ⇑(⟨f, inv_fun, left_inv, right_inv⟩ : M ≃ₗ[R] M₂).symm = inv_fun := rfl protected theorem bijective : Function.Bijective e := e.toEquiv.bijective protected theorem injective : Function.Injective e := e.toEquiv.injective protected theorem surjective : Function.Surjective e := e.toEquiv.surjective protected theorem image_eq_preimage_symm (s : Set M) : e '' s = e.symm ⁻¹' s := e.toEquiv.image_eq_preimage_symm s protected theorem image_symm_eq_preimage (s : Set M₂) : e.symm '' s = e ⁻¹' s := e.toEquiv.symm.image_eq_preimage_symm s end /-- `Equiv.cast (congrArg _ h)` as a linear equiv. Note that unlike `Equiv.cast`, this takes an equality of indices rather than an equality of types, to avoid having to deal with an equality of the algebraic structure itself. -/ @[simps!] protected def cast {ι : Type*} {M : ι → Type*} [∀ i, AddCommMonoid (M i)] [∀ i, Module R (M i)] {i j : ι} (h : i = j) : M i ≃ₗ[R] M j where toAddEquiv := AddEquiv.cast h map_smul' _ _ := by cases h; rfl /-- Interpret a `RingEquiv` `f` as an `f`-semilinear equiv. -/ @[simps] def _root_.RingEquiv.toSemilinearEquiv (f : R ≃+* S) : haveI := RingHomInvPair.of_ringEquiv f haveI := RingHomInvPair.symm (↑f : R →+* S) (f.symm : S →+* R) R ≃ₛₗ[(↑f : R →+* S)] S := haveI := RingHomInvPair.of_ringEquiv f haveI := RingHomInvPair.symm (↑f : R →+* S) (f.symm : S →+* R) { f with toFun := f map_smul' := f.map_mul } variable [AddCommMonoid M] /-- An involutive linear map is a linear equivalence. -/ def ofInvolutive {σ σ' : R →+* R} [RingHomInvPair σ σ'] [RingHomInvPair σ' σ] {_ : Module R M} (f : M →ₛₗ[σ] M) (hf : Involutive f) : M ≃ₛₗ[σ] M := { f, hf.toPerm f with } @[simp] theorem coe_ofInvolutive {σ σ' : R →+* R} [RingHomInvPair σ σ'] [RingHomInvPair σ' σ] {_ : Module R M} (f : M →ₛₗ[σ] M) (hf : Involutive f) : ⇑(ofInvolutive f hf) = f := rfl end AddCommMonoid end LinearEquiv
.lake/packages/mathlib/Mathlib/Algebra/Module/Congruence/Defs.lean
import Mathlib.Algebra.Module.Equiv.Defs import Mathlib.GroupTheory.Congruence.Basic /-! # Congruence relations respecting scalar multiplication -/ variable (R S M N : Type*) /-- A congruence relation that preserves additive action. -/ structure VAddCon [VAdd S M] extends Setoid M where /-- A `VAddCon` is closed under additive action. -/ vadd (s : S) {x y} : r x y → r (s +ᵥ x) (s +ᵥ y) /-- A congruence relation that preserves scalar multiplication. -/ @[to_additive] structure SMulCon [SMul S M] extends Setoid M where /-- A `SMulCon` is closed under scalar multiplication. -/ smul (s : S) {x y} : r x y → r (s • x) (s • y) /-- A congruence relation that preserves addition and scalar multiplication. The quotient by a `ModuleCon` inherits `DistribSMul`, `DistribMulAction`, and `Module` instances. -/ structure ModuleCon [Add M] [SMul S M] extends AddCon M, SMulCon S M /-- The `SMulCon` underlying an `ModuleCon`. -/ add_decl_doc ModuleCon.toSMulCon variable {S} namespace SMulCon /-- The quotient by a congruence relation preserving scalar multiplication. -/ @[to_additive /-- The quotient by a congruence relation preserving additive action. -/] protected def Quotient [SMul S M] (c : SMulCon S M) : Type _ := Quotient c.toSetoid @[to_additive] instance [SMul S M] (c : SMulCon S M) : SMul S c.Quotient where smul s := Quotient.map (s • ·) (@c.smul s) instance [SMul S M] [Zero M] (c : SMulCon S M) : Zero c.Quotient where zero := ⟦0⟧ instance [Zero M] [SMulZeroClass S M] (c : SMulCon S M) : SMulZeroClass S c.Quotient where smul_zero s := congr_arg _ (smul_zero s) instance [Zero S] [Zero M] [SMulWithZero S M] (c : SMulCon S M) : SMulWithZero S c.Quotient := fast_instance% Quotient.mk''_surjective.smulWithZero ⟨_, rfl⟩ fun _ _ ↦ rfl @[to_additive] instance [Monoid S] [MulAction S M] (c : SMulCon S M) : MulAction S c.Quotient := fast_instance% Quotient.mk''_surjective.mulAction (⟦·⟧) fun _ _ ↦ rfl section addConGen variable {M} [AddZeroClass M] [DistribSMul S M] /-- The `AddCon` generated by a relation respecting scalar multiplication is a `ModuleCon`. -/ def addConGen' (r : M → M → Prop) (hr : ∀ (s : S) {m m'}, r m m' → r (s • m) (s • m')) : ModuleCon S M where toAddCon := addConGen r smul s _ _ h := ((addConGen r).comap (DistribSMul.toAddMonoidHom M s) <| by simp).addConGen_le (fun _ _ h ↦ .of _ _ (hr s h)) h /-- The `AddCon` generated by a `SMulCon` is a `ModuleCon`. -/ protected abbrev addConGen (c : SMulCon S M) : ModuleCon S M := addConGen' c.r c.smul end addConGen end SMulCon namespace ModuleCon /-- The quotient by a congruence relation preserving addition and scalar multiplication. -/ protected def Quotient [Add M] [SMul S M] (c : ModuleCon S M) : Type _ := Quotient c.toSetoid instance [SMul S M] [Add M] (c : ModuleCon S M) : SMul S c.Quotient := inferInstanceAs (SMul S c.toSMulCon.Quotient) instance [SMul S M] [Zero M] [Add M] (c : ModuleCon S M) : Zero c.Quotient where zero := ⟦0⟧ instance [SMul S M] [Add M] (c : ModuleCon S M) : Add c.Quotient := inferInstanceAs (Add c.toAddCon.Quotient) instance [SMul S M] [AddZeroClass M] (c : ModuleCon S M) : AddZeroClass c.Quotient := inferInstanceAs (AddZeroClass c.toAddCon.Quotient) instance [SMul S M] [AddCommMagma M] (c : ModuleCon S M) : AddCommMagma c.Quotient := inferInstanceAs (AddCommMagma c.toAddCon.Quotient) instance [SMul S M] [AddSemigroup M] (c : ModuleCon S M) : AddSemigroup c.Quotient := inferInstanceAs (AddSemigroup c.toAddCon.Quotient) instance [SMul S M] [AddCommSemigroup M] (c : ModuleCon S M) : AddCommSemigroup c.Quotient := inferInstanceAs (AddCommSemigroup c.toAddCon.Quotient) instance [SMul S M] [AddMonoid M] (c : ModuleCon S M) : AddMonoid c.Quotient := inferInstanceAs (AddMonoid c.toAddCon.Quotient) instance [SMul S M] [AddCommMonoid M] (c : ModuleCon S M) : AddCommMonoid c.Quotient := inferInstanceAs (AddCommMonoid c.toAddCon.Quotient) instance [SMul S M] [AddGroup M] (c : ModuleCon S M) : AddGroup c.Quotient := inferInstanceAs (AddGroup c.toAddCon.Quotient) instance [SMul S M] [AddCommGroup M] (c : ModuleCon S M) : AddCommGroup c.Quotient := inferInstanceAs (AddCommGroup c.toAddCon.Quotient) instance [Zero M] [Add M] [SMulZeroClass S M] (c : ModuleCon S M) : SMulZeroClass S c.Quotient := inferInstanceAs (SMulZeroClass S c.toSMulCon.Quotient) instance [Zero S] [Zero M] [Add M] [SMulWithZero S M] (c : ModuleCon S M) : SMulWithZero S c.Quotient := inferInstanceAs (SMulWithZero S c.toSMulCon.Quotient) instance [Monoid S] [Add M] [MulAction S M] (c : ModuleCon S M) : MulAction S c.Quotient := inferInstanceAs (MulAction S c.toSMulCon.Quotient) instance [AddZeroClass M] [DistribSMul S M] (c : ModuleCon S M) : DistribSMul S c.Quotient := fast_instance% Quotient.mk''_surjective.distribSMul c.mk' fun _ _ ↦ rfl instance [Monoid S] [AddMonoid M] [DistribMulAction S M] (c : ModuleCon S M) : DistribMulAction S c.Quotient := fast_instance% Quotient.mk''_surjective.distribMulAction c.mk' fun _ _ ↦ rfl instance [Semiring S] [AddCommMonoid M] [Module S M] (c : ModuleCon S M) : Module S c.Quotient := fast_instance% Quotient.mk''_surjective.module _ c.mk' fun _ _ ↦ rfl end ModuleCon section ker variable {R M N} /-- The kernel of a `MulActionHom` as a congruence relation. -/ @[to_additive /-- The kernel of an `AddActionHom` as a congruence relation. -/] def SMulCon.ker [SMul R M] [SMul S N] {φ : R → S} (f : M →ₑ[φ] N) : SMulCon R M where __ := Setoid.ker f smul r _ _ h := by rw [Setoid.ker_def] at h ⊢; simp_rw [map_smulₛₗ, h] /-- The kernel of a `DistribMulActionHom` as a congruence relation. -/ def ModuleCon.ker [Monoid R] [Monoid S] [AddMonoid M] [AddMonoid N] [DistribMulAction R M] [DistribMulAction S N] {φ : R →* S} (f : M →ₑ+[φ] N) : ModuleCon R M where __ := SMulCon.ker f.toMulActionHom __ := AddCon.ker f /-- The first isomorphism theorem for semimodules in the case of a surjective homomorphism. -/ noncomputable def ModuleCon.quotientKerEquivOfSurjective [Semiring S] [AddCommMonoid M] [AddCommMonoid N] [Module S M] [Module S N] (f : M →ₗ[S] N) (hf : Function.Surjective f) : (ker f.toDistribMulActionHom).Quotient ≃ₗ[S] N where __ := AddCon.quotientKerEquivOfSurjective f.toAddMonoidHom hf map_smul' s := by rintro ⟨⟩; apply map_smul f end ker
.lake/packages/mathlib/Mathlib/Algebra/Module/LinearMap/Rat.lean
import Mathlib.Algebra.Module.Rat import Mathlib.Algebra.Module.LinearMap.Defs /-! # Reinterpret an additive homomorphism as a `ℚ`-linear map. -/ open Function variable {M M₂ : Type*} /-- Reinterpret an additive homomorphism as a `ℚ`-linear map. -/ def AddMonoidHom.toRatLinearMap [AddCommGroup M] [Module ℚ M] [AddCommGroup M₂] [Module ℚ M₂] (f : M →+ M₂) : M →ₗ[ℚ] M₂ := { f with map_smul' := map_rat_smul f } theorem AddMonoidHom.toRatLinearMap_injective [AddCommGroup M] [Module ℚ M] [AddCommGroup M₂] [Module ℚ M₂] : Function.Injective (@AddMonoidHom.toRatLinearMap M M₂ _ _ _ _) := by intro f g h ext x exact LinearMap.congr_fun h x @[simp] theorem AddMonoidHom.coe_toRatLinearMap [AddCommGroup M] [Module ℚ M] [AddCommGroup M₂] [Module ℚ M₂] (f : M →+ M₂) : ⇑f.toRatLinearMap = f := rfl
.lake/packages/mathlib/Mathlib/Algebra/Module/LinearMap/Star.lean
import Mathlib.Algebra.Module.Equiv.Defs import Mathlib.Algebra.Star.Basic /-! # Notation for star-linear maps This is in a separate file as a it is not needed until much later, and avoids importing the theory of star operations unnecessarily early. -/ /-- `M →ₗ⋆[R] N` is the type of `R`-conjugate-linear maps from `M` to `N`. -/ notation:25 M " →ₗ⋆[" R:25 "] " M₂:0 => LinearMap (starRingEnd R) M M₂ /-- The notation `M ≃ₗ⋆[R] M₂` denotes the type of star-linear equivalences between `M` and `M₂` over the `⋆` endomorphism of the underlying starred ring `R`. -/ notation:50 M " ≃ₗ⋆[" R "] " M₂ => LinearEquiv (starRingEnd R) M M₂
.lake/packages/mathlib/Mathlib/Algebra/Module/LinearMap/Prod.lean
import Mathlib.Algebra.Module.Prod import Mathlib.Tactic.Abel import Mathlib.Algebra.Module.LinearMap.Defs /-! # Addition and subtraction are linear maps from the product space Note that these results use `IsLinearMap`, which is mostly discouraged. ## Tags linear algebra, vector space, module -/ variable {R : Type*} {M : Type*} [Semiring R] namespace IsLinearMap theorem isLinearMap_add [AddCommMonoid M] [Module R M] : IsLinearMap R fun x : M × M => x.1 + x.2 := by apply IsLinearMap.mk · intro x y simp only [Prod.fst_add, Prod.snd_add] abel · simp [smul_add] theorem isLinearMap_sub [AddCommGroup M] [Module R M] : IsLinearMap R fun x : M × M => x.1 - x.2 := by apply IsLinearMap.mk · simp [add_comm, add_assoc, add_left_comm, sub_eq_add_neg] · simp [smul_sub] end IsLinearMap
.lake/packages/mathlib/Mathlib/Algebra/Module/LinearMap/Basic.lean
import Mathlib.Algebra.Module.LinearMap.Defs import Mathlib.Algebra.NoZeroSMulDivisors.Pi import Mathlib.Algebra.Ring.Opposite import Mathlib.GroupTheory.GroupAction.DomAct.Basic /-! # Further results on (semi)linear maps -/ assert_not_exists Submonoid Finset TrivialStar open Function universe u u' v w x y z variable {R R' S M M' : Type*} namespace LinearMap section SMul variable [Semiring R] [Semiring R'] variable [AddCommMonoid M] [AddCommMonoid M'] variable [Module R M] [Module R' M'] variable {σ₁₂ : R →+* R'} variable {S' T' : Type*} variable [Monoid S'] [DistribMulAction S' M] [SMulCommClass R S' M] variable [Monoid T'] [DistribMulAction T' M] [SMulCommClass R T' M] instance : SMul S'ᵈᵐᵃ (M →ₛₗ[σ₁₂] M') where smul a f := { toFun := a • (f : M → M') map_add' := fun x y ↦ by simp only [DomMulAct.smul_apply, f.map_add, smul_add] map_smul' := fun c x ↦ by simp_rw [DomMulAct.smul_apply, ← smul_comm, f.map_smulₛₗ] } theorem _root_.DomMulAct.smul_linearMap_apply (a : S'ᵈᵐᵃ) (f : M →ₛₗ[σ₁₂] M') (x : M) : (a • f) x = f (DomMulAct.mk.symm a • x) := rfl @[simp] theorem _root_.DomMulAct.mk_smul_linearMap_apply (a : S') (f : M →ₛₗ[σ₁₂] M') (x : M) : (DomMulAct.mk a • f) x = f (a • x) := rfl theorem _root_.DomMulAct.coe_smul_linearMap (a : S'ᵈᵐᵃ) (f : M →ₛₗ[σ₁₂] M') : (a • f : M →ₛₗ[σ₁₂] M') = a • (f : M → M') := rfl instance [SMulCommClass S' T' M] : SMulCommClass S'ᵈᵐᵃ T'ᵈᵐᵃ (M →ₛₗ[σ₁₂] M') := ⟨fun s t f ↦ ext fun m ↦ by simp_rw [DomMulAct.smul_linearMap_apply, smul_comm]⟩ end SMul section Actions variable [Semiring R] [Semiring R'] variable [AddCommMonoid M] [AddCommMonoid M'] variable [Module R M] [Module R' M'] variable {σ₁₂ : R →+* R'} section SMul instance {S'} [Monoid S'] [DistribMulAction S' M] [SMulCommClass R S' M] : DistribMulAction S'ᵈᵐᵃ (M →ₛₗ[σ₁₂] M') where one_smul _ := ext fun _ ↦ congr_arg _ (one_smul _ _) mul_smul _ _ _ := ext fun _ ↦ congr_arg _ (mul_smul _ _ _) smul_add _ _ _ := ext fun _ ↦ rfl smul_zero _ := ext fun _ ↦ rfl end SMul section Module variable [Semiring S] [Module S M] [Module S M'] [SMulCommClass R' S M'] instance [NoZeroSMulDivisors S M'] : NoZeroSMulDivisors S (M →ₛₗ[σ₁₂] M') := coe_injective.noZeroSMulDivisors _ rfl coe_smul instance [SMulCommClass R S M] : Module Sᵈᵐᵃ (M →ₛₗ[σ₁₂] M') where add_smul _ _ _ := ext fun _ ↦ by simp_rw [add_apply, DomMulAct.smul_linearMap_apply, ← map_add, ← add_smul]; rfl zero_smul _ := ext fun _ ↦ by erw [DomMulAct.smul_linearMap_apply, zero_smul, map_zero]; rfl end Module end Actions end LinearMap
.lake/packages/mathlib/Mathlib/Algebra/Module/LinearMap/End.lean
import Mathlib.Algebra.Module.Equiv.Opposite import Mathlib.Algebra.NoZeroSMulDivisors.Defs /-! # Endomorphisms of a module In this file we define the type of linear endomorphisms of a module over a ring (`Module.End`). We set up the basic theory, including the action of `Module.End` on the module we are considering endomorphisms of. ## Main results * `Module.End.instSemiring` and `Module.End.instRing`: the (semi)ring of endomorphisms formed by taking the additive structure above with composition as multiplication. -/ universe u v /-- Linear endomorphisms of a module, with associated ring structure `Module.End.semiring` and algebra structure `Module.End.algebra`. -/ abbrev Module.End (R : Type u) (M : Type v) [Semiring R] [AddCommMonoid M] [Module R M] := M →ₗ[R] M variable {R R₂ S M M₁ M₂ M₃ N₁ : Type*} open Function LinearMap /-! ## Monoid structure of endomorphisms -/ namespace Module.End variable [Semiring R] [AddCommMonoid M] [AddCommGroup N₁] [Module R M] [Module R N₁] instance : One (Module.End R M) := ⟨LinearMap.id⟩ instance : Mul (Module.End R M) := ⟨fun f g => LinearMap.comp f g⟩ theorem one_eq_id : (1 : Module.End R M) = .id := rfl theorem mul_eq_comp (f g : Module.End R M) : f * g = f.comp g := rfl @[simp] theorem one_apply (x : M) : (1 : Module.End R M) x = x := rfl @[simp] theorem mul_apply (f g : Module.End R M) (x : M) : (f * g) x = f (g x) := rfl theorem coe_one : ⇑(1 : Module.End R M) = _root_.id := rfl theorem coe_mul (f g : Module.End R M) : ⇑(f * g) = f ∘ g := rfl instance instNontrivial [Nontrivial M] : Nontrivial (Module.End R M) := by obtain ⟨m, ne⟩ := exists_ne (0 : M) exact nontrivial_of_ne 1 0 fun p => ne (LinearMap.congr_fun p m) instance instMonoid : Monoid (Module.End R M) where mul_assoc _ _ _ := LinearMap.ext fun _ ↦ rfl mul_one := comp_id one_mul := id_comp instance instSemiring : Semiring (Module.End R M) where __ := AddMonoidWithOne.unary __ := instMonoid __ := addCommMonoid mul_zero := comp_zero zero_mul := zero_comp left_distrib := fun _ _ _ ↦ comp_add _ _ _ right_distrib := fun _ _ _ ↦ add_comp _ _ _ natCast := fun n ↦ n • (1 : M →ₗ[R] M) natCast_zero := zero_smul ℕ (1 : M →ₗ[R] M) natCast_succ := fun n ↦ AddMonoid.nsmul_succ n (1 : M →ₗ[R] M) /-- See also `Module.End.natCast_def`. -/ @[simp] theorem natCast_apply (n : ℕ) (m : M) : (↑n : Module.End R M) m = n • m := rfl @[simp] theorem ofNat_apply (n : ℕ) [n.AtLeastTwo] (m : M) : (ofNat(n) : Module.End R M) m = ofNat(n) • m := rfl instance instRing : Ring (Module.End R N₁) where intCast z := z • (1 : N₁ →ₗ[R] N₁) intCast_ofNat := natCast_zsmul _ intCast_negSucc := negSucc_zsmul _ /-- See also `Module.End.intCast_def`. -/ @[simp] theorem intCast_apply (z : ℤ) (m : N₁) : (z : Module.End R N₁) m = z • m := rfl section variable [Monoid S] [DistribMulAction S M] [SMulCommClass R S M] instance instIsScalarTower : IsScalarTower S (Module.End R M) (Module.End R M) := ⟨smul_comp⟩ instance instSMulCommClass [SMul S R] [IsScalarTower S R M] : SMulCommClass S (Module.End R M) (Module.End R M) := ⟨fun s _ _ ↦ (comp_smul _ s _).symm⟩ instance instSMulCommClass' [SMul S R] [IsScalarTower S R M] : SMulCommClass (Module.End R M) S (Module.End R M) := SMulCommClass.symm _ _ _ theorem isUnit_apply_inv_apply_of_isUnit {f : End R M} (h : IsUnit f) (x : M) : f (h.unit.inv x) = x := show (f * h.unit.inv) x = x by simp @[deprecated (since := "2025-04-28")] alias _root_.Module.End_isUnit_apply_inv_apply_of_isUnit := isUnit_apply_inv_apply_of_isUnit theorem isUnit_inv_apply_apply_of_isUnit {f : End R M} (h : IsUnit f) (x : M) : h.unit.inv (f x) = x := (by simp : (h.unit.inv * f) x = x) @[deprecated (since := "2025-04-28")] alias _root_.Module.End_isUnit_inv_apply_apply_of_isUnit := isUnit_inv_apply_apply_of_isUnit theorem coe_pow (f : End R M) (n : ℕ) : ⇑(f ^ n) = f^[n] := hom_coe_pow _ rfl (fun _ _ ↦ rfl) _ _ theorem pow_apply (f : End R M) (n : ℕ) (m : M) : (f ^ n) m = f^[n] m := congr_fun (coe_pow f n) m theorem pow_map_zero_of_le {f : End R M} {m : M} {k l : ℕ} (hk : k ≤ l) (hm : (f ^ k) m = 0) : (f ^ l) m = 0 := by rw [← Nat.sub_add_cancel hk, pow_add, mul_apply, hm, map_zero] theorem commute_pow_left_of_commute [Semiring R₂] [AddCommMonoid M₂] [Module R₂ M₂] {σ₁₂ : R →+* R₂} {f : M →ₛₗ[σ₁₂] M₂} {g : Module.End R M} {g₂ : Module.End R₂ M₂} (h : g₂.comp f = f.comp g) (k : ℕ) : (g₂ ^ k).comp f = f.comp (g ^ k) := by induction k with | zero => simp [one_eq_id] | succ k ih => rw [pow_succ', pow_succ', mul_eq_comp, LinearMap.comp_assoc, ih, ← LinearMap.comp_assoc, h, LinearMap.comp_assoc, mul_eq_comp] @[simp] theorem id_pow (n : ℕ) : (id : End R M) ^ n = .id := one_pow n variable {f' : End R M} theorem iterate_succ (n : ℕ) : f' ^ (n + 1) = .comp (f' ^ n) f' := by rw [pow_succ, mul_eq_comp] theorem iterate_surjective (h : Surjective f') : ∀ n : ℕ, Surjective (f' ^ n) | 0 => surjective_id | n + 1 => by rw [iterate_succ] exact (iterate_surjective h n).comp h theorem iterate_injective (h : Injective f') : ∀ n : ℕ, Injective (f' ^ n) | 0 => injective_id | n + 1 => by rw [iterate_succ] exact (iterate_injective h n).comp h theorem iterate_bijective (h : Bijective f') : ∀ n : ℕ, Bijective (f' ^ n) | 0 => bijective_id | n + 1 => by rw [iterate_succ] exact (iterate_bijective h n).comp h theorem injective_of_iterate_injective {n : ℕ} (hn : n ≠ 0) (h : Injective (f' ^ n)) : Injective f' := by rw [← Nat.succ_pred_eq_of_pos (show 0 < n by cutsat), iterate_succ, coe_comp] at h exact h.of_comp theorem surjective_of_iterate_surjective {n : ℕ} (hn : n ≠ 0) (h : Surjective (f' ^ n)) : Surjective f' := by rw [← Nat.succ_pred_eq_of_pos (Nat.pos_iff_ne_zero.mpr hn), pow_succ', coe_mul] at h exact Surjective.of_comp h end /-! ## Action by a module endomorphism. -/ /-- The tautological action by `Module.End R M` (aka `M →ₗ[R] M`) on `M`. This generalizes `Function.End.applyMulAction`. -/ instance applyModule : Module (Module.End R M) M where smul := (· <| ·) smul_zero := LinearMap.map_zero smul_add := LinearMap.map_add add_smul := LinearMap.add_apply zero_smul := (LinearMap.zero_apply : ∀ m, (0 : M →ₗ[R] M) m = 0) one_smul _ := rfl mul_smul _ _ _ := rfl @[simp] protected theorem smul_def (f : Module.End R M) (a : M) : f • a = f a := rfl /-- `LinearMap.applyModule` is faithful. -/ instance apply_faithfulSMul : FaithfulSMul (Module.End R M) M := ⟨LinearMap.ext⟩ instance apply_smulCommClass [SMul S R] [SMul S M] [IsScalarTower S R M] : SMulCommClass S (Module.End R M) M where smul_comm r e m := (e.map_smul_of_tower r m).symm instance apply_smulCommClass' [SMul S R] [SMul S M] [IsScalarTower S R M] : SMulCommClass (Module.End R M) S M := SMulCommClass.symm _ _ _ instance apply_isScalarTower [Monoid S] [DistribMulAction S M] [SMulCommClass R S M] : IsScalarTower S (Module.End R M) M := ⟨fun _ _ _ ↦ rfl⟩ end Module.End /-! ## Actions as module endomorphisms -/ namespace DistribMulAction variable (R M) [Semiring R] [AddCommMonoid M] [Module R M] variable [Monoid S] [DistribMulAction S M] [SMulCommClass S R M] /-- Each element of the monoid defines a linear map. This is a stronger version of `DistribMulAction.toAddMonoidHom`. -/ @[simps] def toLinearMap (s : S) : M →ₗ[R] M where toFun := HSMul.hSMul s map_add' := smul_add s map_smul' _ _ := smul_comm _ _ _ /-- Each element of the monoid defines a module endomorphism. This is a stronger version of `DistribMulAction.toAddMonoidEnd`. -/ @[simps] def toModuleEnd : S →* Module.End R M where toFun := toLinearMap R M map_one' := LinearMap.ext <| one_smul _ map_mul' _ _ := LinearMap.ext <| mul_smul _ _ end DistribMulAction section Module variable (R M) [Semiring R] [AddCommMonoid M] [Module R M] variable [Semiring S] [Module S M] [SMulCommClass S R M] /-- Each element of the semiring defines a module endomorphism. This is a stronger version of `DistribMulAction.toModuleEnd`. -/ @[simps] def Module.toModuleEnd : S →+* Module.End R M := { DistribMulAction.toModuleEnd R M with toFun := DistribMulAction.toLinearMap R M map_zero' := LinearMap.ext <| zero_smul S map_add' := fun _ _ ↦ LinearMap.ext <| add_smul _ _ } /-- The canonical (semi)ring isomorphism from `Rᵐᵒᵖ` to `Module.End R R` induced by the right multiplication. -/ @[simps] def RingEquiv.moduleEndSelf : Rᵐᵒᵖ ≃+* Module.End R R := { Module.toModuleEnd R R with toFun := DistribMulAction.toLinearMap R R invFun := fun f ↦ MulOpposite.op (f 1) left_inv := mul_one right_inv := fun _ ↦ LinearMap.ext_ring <| one_mul _ } /-- The canonical (semi)ring isomorphism from `R` to `Module.End Rᵐᵒᵖ R` induced by the left multiplication. -/ @[simps] def RingEquiv.moduleEndSelfOp : R ≃+* Module.End Rᵐᵒᵖ R := { Module.toModuleEnd _ _ with toFun := DistribMulAction.toLinearMap _ _ invFun := fun f ↦ f 1 left_inv := mul_one right_inv := fun _ ↦ LinearMap.ext_ring_op <| mul_one _ } theorem Module.End.natCast_def (n : ℕ) [AddCommMonoid N₁] [Module R N₁] : (↑n : Module.End R N₁) = Module.toModuleEnd R N₁ n := rfl theorem Module.End.intCast_def (z : ℤ) [AddCommGroup N₁] [Module R N₁] : (z : Module.End R N₁) = Module.toModuleEnd R N₁ z := rfl end Module namespace LinearMap section AddCommMonoid section SMulRight variable [Semiring R] [AddCommMonoid M] [AddCommMonoid M₁] [Module R M] [Module R M₁] variable [Semiring S] [Module R S] [Module S M] [IsScalarTower R S M] /-- When `f` is an `R`-linear map taking values in `S`, then `fun b ↦ f b • x` is an `R`-linear map. -/ def smulRight (f : M₁ →ₗ[R] S) (x : M) : M₁ →ₗ[R] M where toFun b := f b • x map_add' x y := by rw [f.map_add, add_smul] map_smul' b y := by rw [RingHom.id_apply, map_smul, smul_assoc] @[simp] theorem coe_smulRight (f : M₁ →ₗ[R] S) (x : M) : (smulRight f x : M₁ → M) = fun c => f c • x := rfl theorem smulRight_apply (f : M₁ →ₗ[R] S) (x : M) (c : M₁) : smulRight f x c = f c • x := rfl @[simp] lemma smulRight_zero (f : M₁ →ₗ[R] S) : f.smulRight (0 : M) = 0 := by ext; simp @[simp] lemma zero_smulRight (x : M) : (0 : M₁ →ₗ[R] S).smulRight x = 0 := by ext; simp @[simp] lemma smulRight_apply_eq_zero_iff {f : M₁ →ₗ[R] S} {x : M} [NoZeroSMulDivisors S M] : f.smulRight x = 0 ↔ f = 0 ∨ x = 0 := by rcases eq_or_ne x 0 with rfl | hx · simp refine ⟨fun h ↦ Or.inl ?_, fun h ↦ by simp [h.resolve_right hx]⟩ ext v replace h : f v • x = 0 := by simpa only [LinearMap.zero_apply] using LinearMap.congr_fun h v rw [smul_eq_zero] at h tauto end SMulRight end AddCommMonoid section Module variable [Semiring R] [Semiring S] [AddCommMonoid M] [AddCommMonoid M₁] [AddCommMonoid M₂] variable [Module R M] [Module R M₁] [Module R M₂] [Module S M₁] [Module S M₂] variable [SMulCommClass R S M₁] [SMulCommClass R S M₂] variable (S) /-- Applying a linear map at `v : M`, seen as `S`-linear map from `M →ₗ[R] M₂` to `M₂`. See `LinearMap.applyₗ` for a version where `S = R`. -/ @[simps] def applyₗ' : M →+ (M →ₗ[R] M₂) →ₗ[S] M₂ where toFun v := { toFun := fun f => f v map_add' := fun f g => f.add_apply g v map_smul' := fun x f => f.smul_apply x v } map_zero' := LinearMap.ext fun f => f.map_zero map_add' _ _ := LinearMap.ext fun f => f.map_add _ _ variable [CompatibleSMul M₁ M₂ S R] /-- Composition by `f : M₂ → M₃` is a linear map from the space of linear maps `M → M₂` to the space of linear maps `M → M₃`. -/ def compRight (f : M₁ →ₗ[R] M₂) : (M →ₗ[R] M₁) →ₗ[S] M →ₗ[R] M₂ where toFun g := f.comp g map_add' _ _ := LinearMap.ext fun _ ↦ map_add f _ _ map_smul' _ _ := LinearMap.ext fun _ ↦ map_smul_of_tower .. @[simp] theorem compRight_apply (f : M₁ →ₗ[R] M₂) (g : M →ₗ[R] M₁) : compRight S f g = f.comp g := rfl end Module section CommSemiring variable [CommSemiring R] [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] variable [Module R M] [Module R M₂] [Module R M₃] variable (f : M →ₗ[R] M₂) /-- Applying a linear map at `v : M`, seen as a linear map from `M →ₗ[R] M₂` to `M₂`. See also `LinearMap.applyₗ'` for a version that works with two different semirings. This is the `LinearMap` version of `toAddMonoidHom.eval`. -/ @[simps] def applyₗ : M →ₗ[R] (M →ₗ[R] M₂) →ₗ[R] M₂ := { applyₗ' R with toFun := fun v => { applyₗ' R v with toFun := fun f => f v } map_smul' := fun _ _ => LinearMap.ext fun f => map_smul f _ _ } /-- The family of linear maps `M₂ → M` parameterised by `f ∈ M₂ → R`, `x ∈ M`, is linear in `f`, `x`. -/ def smulRightₗ : (M₂ →ₗ[R] R) →ₗ[R] M →ₗ[R] M₂ →ₗ[R] M where toFun f := { toFun := LinearMap.smulRight f map_add' := fun m m' => by ext apply smul_add map_smul' := fun c m => by ext apply smul_comm } map_add' f f' := by ext apply add_smul map_smul' c f := by ext apply mul_smul @[simp] theorem smulRightₗ_apply (f : M₂ →ₗ[R] R) (x : M) (c : M₂) : (smulRightₗ : (M₂ →ₗ[R] R) →ₗ[R] M →ₗ[R] M₂ →ₗ[R] M) f x c = f c • x := rfl end CommSemiring end LinearMap namespace Module.End variable {R M : Type*} [Ring R] [AddCommGroup M] [Module R M] (f : Module.End R M) lemma commute_id_left : Commute LinearMap.id f := by ext; simp lemma commute_id_right : Commute f LinearMap.id := by ext; simp end Module.End
.lake/packages/mathlib/Mathlib/Algebra/Module/LinearMap/Defs.lean
import Mathlib.Algebra.Group.Hom.Instances import Mathlib.Algebra.Module.NatInt import Mathlib.Algebra.Module.RingHom import Mathlib.Algebra.Ring.CompTypeclasses import Mathlib.GroupTheory.GroupAction.Hom /-! # (Semi)linear maps In this file we define * `LinearMap σ M M₂`, `M →ₛₗ[σ] M₂` : a semilinear map between two `Module`s. Here, `σ` is a `RingHom` from `R` to `R₂` and an `f : M →ₛₗ[σ] M₂` satisfies `f (c • x) = (σ c) • (f x)`. We recover plain linear maps by choosing `σ` to be `RingHom.id R`. This is denoted by `M →ₗ[R] M₂`. We also add the notation `M →ₗ⋆[R] M₂` for star-linear maps. * `IsLinearMap R f` : predicate saying that `f : M → M₂` is a linear map. (Note that this was not generalized to semilinear maps.) We then provide `LinearMap` with the following instances: * `LinearMap.addCommMonoid` and `LinearMap.addCommGroup`: the elementwise addition structures corresponding to addition in the codomain * `LinearMap.distribMulAction` and `LinearMap.module`: the elementwise scalar action structures corresponding to applying the action in the codomain. ## Implementation notes To ensure that composition works smoothly for semilinear maps, we use the typeclasses `RingHomCompTriple`, `RingHomInvPair` and `RingHomSurjective` from `Mathlib/Algebra/Ring/CompTypeclasses.lean`. ## Notation * Throughout the file, we denote regular linear maps by `fₗ`, `gₗ`, etc, and semilinear maps by `f`, `g`, etc. ## TODO * Parts of this file have not yet been generalized to semilinear maps (i.e. `CompatibleSMul`) ## Tags linear map -/ assert_not_exists TrivialStar DomMulAct Pi.module WCovBy.image Field open Function universe u u' v w variable {R R₁ R₂ R₃ S S₃ T M M₁ M₂ M₃ N₂ N₃ : Type*} /-- A map `f` between modules over a semiring is linear if it satisfies the two properties `f (x + y) = f x + f y` and `f (c • x) = c • f x`. The predicate `IsLinearMap R f` asserts this property. A bundled version is available with `LinearMap`, and should be favored over `IsLinearMap` most of the time. -/ structure IsLinearMap (R : Type u) {M : Type v} {M₂ : Type w} [Semiring R] [AddCommMonoid M] [AddCommMonoid M₂] [Module R M] [Module R M₂] (f : M → M₂) : Prop where /-- A linear map preserves addition. -/ map_add : ∀ x y, f (x + y) = f x + f y /-- A linear map preserves scalar multiplication. -/ map_smul : ∀ (c : R) (x), f (c • x) = c • f x section /-- A map `f` between an `R`-module and an `S`-module over a ring homomorphism `σ : R →+* S` is semilinear if it satisfies the two properties `f (x + y) = f x + f y` and `f (c • x) = (σ c) • f x`. Elements of `LinearMap σ M M₂` (available under the notation `M →ₛₗ[σ] M₂`) are bundled versions of such maps. For plain linear maps (i.e. for which `σ = RingHom.id R`), the notation `M →ₗ[R] M₂` is available. An unbundled version of plain linear maps is available with the predicate `IsLinearMap`, but it should be avoided most of the time. -/ structure LinearMap {R S : Type*} [Semiring R] [Semiring S] (σ : R →+* S) (M : Type*) (M₂ : Type*) [AddCommMonoid M] [AddCommMonoid M₂] [Module R M] [Module S M₂] extends AddHom M M₂, MulActionHom σ M M₂ /-- The `MulActionHom` underlying a `LinearMap`. -/ add_decl_doc LinearMap.toMulActionHom /-- The `AddHom` underlying a `LinearMap`. -/ add_decl_doc LinearMap.toAddHom /-- `M →ₛₗ[σ] N` is the type of `σ`-semilinear maps from `M` to `N`. -/ notation:25 M " →ₛₗ[" σ:25 "] " M₂:0 => LinearMap σ M M₂ /-- `M →ₗ[R] N` is the type of `R`-linear maps from `M` to `N`. -/ notation:25 M " →ₗ[" R:25 "] " M₂:0 => LinearMap (RingHom.id R) M M₂ /-- `SemilinearMapClass F σ M M₂` asserts `F` is a type of bundled `σ`-semilinear maps `M → M₂`. See also `LinearMapClass F R M M₂` for the case where `σ` is the identity map on `R`. A map `f` between an `R`-module and an `S`-module over a ring homomorphism `σ : R →+* S` is semilinear if it satisfies the two properties `f (x + y) = f x + f y` and `f (c • x) = (σ c) • f x`. -/ class SemilinearMapClass (F : Type*) {R S : outParam Type*} [Semiring R] [Semiring S] (σ : outParam (R →+* S)) (M M₂ : outParam Type*) [AddCommMonoid M] [AddCommMonoid M₂] [Module R M] [Module S M₂] [FunLike F M M₂] : Prop extends AddHomClass F M M₂, MulActionSemiHomClass F σ M M₂ end -- `map_smulₛₗ` should be `@[simp]` but doesn't fire due to https://github.com/leanprover/lean4/pull/3701. -- attribute [simp] map_smulₛₗ /-- `LinearMapClass F R M M₂` asserts `F` is a type of bundled `R`-linear maps `M → M₂`. This is an abbreviation for `SemilinearMapClass F (RingHom.id R) M M₂`. -/ abbrev LinearMapClass (F : Type*) (R : outParam Type*) (M M₂ : Type*) [Semiring R] [AddCommMonoid M] [AddCommMonoid M₂] [Module R M] [Module R M₂] [FunLike F M M₂] := SemilinearMapClass F (RingHom.id R) M M₂ protected lemma LinearMapClass.map_smul {R M M₂ : outParam Type*} [Semiring R] [AddCommMonoid M] [AddCommMonoid M₂] [Module R M] [Module R M₂] {F : Type*} [FunLike F M M₂] [LinearMapClass F R M M₂] (f : F) (r : R) (x : M) : f (r • x) = r • f x := by rw [map_smul] namespace SemilinearMapClass variable (F : Type*) variable [Semiring R] [Semiring S] variable [AddCommMonoid M] [AddCommMonoid M₁] [AddCommMonoid M₂] [AddCommMonoid M₃] variable [Module R M] [Module R M₂] [Module S M₃] variable {σ : R →+* S} instance (priority := 100) instAddMonoidHomClass [FunLike F M M₃] [SemilinearMapClass F σ M M₃] : AddMonoidHomClass F M M₃ := { SemilinearMapClass.toAddHomClass with map_zero := fun f ↦ show f 0 = 0 by rw [← zero_smul R (0 : M), map_smulₛₗ] simp } instance (priority := 100) distribMulActionSemiHomClass [FunLike F M M₃] [SemilinearMapClass F σ M M₃] : DistribMulActionSemiHomClass F σ M M₃ := { SemilinearMapClass.toAddHomClass with map_smulₛₗ := fun f c x ↦ by rw [map_smulₛₗ] } variable {F} (f : F) [FunLike F M M₃] [SemilinearMapClass F σ M M₃] theorem map_smul_inv {σ' : S →+* R} [RingHomInvPair σ σ'] (c : S) (x : M) : c • f x = f (σ' c • x) := by simp [map_smulₛₗ _] /-- Reinterpret an element of a type of semilinear maps as a semilinear map. -/ @[coe] def semilinearMap : M →ₛₗ[σ] M₃ where toFun := f map_add' := map_add f map_smul' := map_smulₛₗ f /-- Reinterpret an element of a type of semilinear maps as a semilinear map. -/ instance instCoeToSemilinearMap : CoeHead F (M →ₛₗ[σ] M₃) where coe f := semilinearMap f end SemilinearMapClass namespace LinearMapClass variable {F : Type*} [Semiring R] [AddCommMonoid M₁] [AddCommMonoid M₂] [Module R M₁] [Module R M₂] (f : F) [FunLike F M₁ M₂] [LinearMapClass F R M₁ M₂] /-- Reinterpret an element of a type of linear maps as a linear map. -/ abbrev linearMap : M₁ →ₗ[R] M₂ := SemilinearMapClass.semilinearMap f /-- Reinterpret an element of a type of linear maps as a linear map. -/ instance instCoeToLinearMap : CoeHead F (M₁ →ₗ[R] M₂) where coe f := SemilinearMapClass.semilinearMap f end LinearMapClass namespace LinearMap section AddCommMonoid variable [Semiring R] [Semiring S] section variable [AddCommMonoid M] [AddCommMonoid M₁] [AddCommMonoid M₂] [AddCommMonoid M₃] variable [Module R M] [Module R M₂] [Module S M₃] variable {σ : R →+* S} instance instFunLike : FunLike (M →ₛₗ[σ] M₃) M M₃ where coe f := f.toFun coe_injective' f g h := by cases f cases g congr apply DFunLike.coe_injective' exact h instance semilinearMapClass : SemilinearMapClass (M →ₛₗ[σ] M₃) σ M M₃ where map_add f := f.map_add' map_smulₛₗ := LinearMap.map_smul' @[simp, norm_cast] lemma coe_coe {F : Type*} [FunLike F M M₃] [SemilinearMapClass F σ M M₃] {f : F} : ⇑(f : M →ₛₗ[σ] M₃) = f := rfl /-- The `DistribMulActionHom` underlying a `LinearMap`. -/ def toDistribMulActionHom (f : M →ₛₗ[σ] M₃) : DistribMulActionHom σ.toMonoidHom M M₃ := { f with map_zero' := show f 0 = 0 from map_zero f } @[simp] theorem coe_toAddHom (f : M →ₛₗ[σ] M₃) : ⇑f.toAddHom = f := rfl @[simp] theorem toFun_eq_coe {f : M →ₛₗ[σ] M₃} : f.toFun = (f : M → M₃) := rfl @[ext] theorem ext {f g : M →ₛₗ[σ] M₃} (h : ∀ x, f x = g x) : f = g := DFunLike.ext f g h /-- Copy of a `LinearMap` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (f : M →ₛₗ[σ] M₃) (f' : M → M₃) (h : f' = ⇑f) : M →ₛₗ[σ] M₃ where toFun := f' map_add' := h.symm ▸ f.map_add' map_smul' := h.symm ▸ f.map_smul' @[simp] theorem coe_copy (f : M →ₛₗ[σ] M₃) (f' : M → M₃) (h : f' = ⇑f) : ⇑(f.copy f' h) = f' := rfl theorem copy_eq (f : M →ₛₗ[σ] M₃) (f' : M → M₃) (h : f' = ⇑f) : f.copy f' h = f := DFunLike.ext' h initialize_simps_projections LinearMap (toFun → apply) @[simp] theorem coe_mk {σ : R →+* S} (f : AddHom M M₃) (h) : ((LinearMap.mk f h : M →ₛₗ[σ] M₃) : M → M₃) = f := rfl @[simp] theorem coe_addHom_mk {σ : R →+* S} (f : AddHom M M₃) (h) : ((LinearMap.mk f h : M →ₛₗ[σ] M₃) : AddHom M M₃) = f := rfl theorem coe_semilinearMap {F : Type*} [FunLike F M M₃] [SemilinearMapClass F σ M M₃] (f : F) : ((f : M →ₛₗ[σ] M₃) : M → M₃) = f := rfl theorem toLinearMap_injective {F : Type*} [FunLike F M M₃] [SemilinearMapClass F σ M M₃] {f g : F} (h : (f : M →ₛₗ[σ] M₃) = (g : M →ₛₗ[σ] M₃)) : f = g := by apply DFunLike.ext intro m exact DFunLike.congr_fun h m /-- Identity map as a `LinearMap` -/ def id : M →ₗ[R] M := { DistribMulActionHom.id R with toFun := _root_.id } theorem id_apply (x : M) : @id R M _ _ _ x = x := rfl @[simp, norm_cast] theorem id_coe : ((LinearMap.id : M →ₗ[R] M) : M → M) = _root_.id := rfl /-- A generalisation of `LinearMap.id` that constructs the identity function as a `σ`-semilinear map for any ring homomorphism `σ` which we know is the identity. -/ @[simps] def id' {σ : R →+* R} [RingHomId σ] : M →ₛₗ[σ] M where toFun x := x map_add' _ _ := rfl map_smul' r x := by have := (RingHomId.eq_id : σ = _) subst this rfl @[simp, norm_cast] theorem id'_coe {σ : R →+* R} [RingHomId σ] : ((id' : M →ₛₗ[σ] M) : M → M) = _root_.id := rfl end section variable [AddCommMonoid M] [AddCommMonoid M₁] [AddCommMonoid M₂] [AddCommMonoid M₃] variable [Module R M] [Module R M₂] [Module S M₃] variable (σ : R →+* S) variable (fₗ : M →ₗ[R] M₂) (f g : M →ₛₗ[σ] M₃) theorem isLinear : IsLinearMap R fₗ := ⟨fₗ.map_add', fₗ.map_smul'⟩ variable {fₗ f g σ} theorem coe_injective : Injective (DFunLike.coe : (M →ₛₗ[σ] M₃) → _) := DFunLike.coe_injective protected theorem congr_arg {x x' : M} : x = x' → f x = f x' := DFunLike.congr_arg f /-- If two linear maps are equal, they are equal at each point. -/ protected theorem congr_fun (h : f = g) (x : M) : f x = g x := DFunLike.congr_fun h x @[simp] lemma mk_coe (f : M →ₛₗ[σ] M₃) (h) : (mk f h : M →ₛₗ[σ] M₃) = f := rfl @[simp] lemma mk_coe' (f : M →ₛₗ[σ] M₃) (h) : (mk f.toAddHom h : M →ₛₗ[σ] M₃) = f := rfl variable (fₗ f g) protected theorem map_add (x y : M) : f (x + y) = f x + f y := map_add f x y protected theorem map_zero : f 0 = 0 := map_zero f -- Porting note: `simp` wasn't picking up `map_smulₛₗ` for `LinearMap`s without specifying -- `map_smulₛₗ f`, so we marked this as `@[simp]` in Mathlib3. -- For Mathlib4, let's try without the `@[simp]` attribute and hope it won't need to be re-enabled. -- This has to be re-tagged as `@[simp]` in https://github.com/leanprover-community/mathlib4/pull/8386 (see also https://github.com/leanprover/lean4/issues/3107). @[simp] protected theorem map_smulₛₗ (c : R) (x : M) : f (c • x) = σ c • f x := map_smulₛₗ f c x protected theorem map_smul (c : R) (x : M) : fₗ (c • x) = c • fₗ x := map_smul fₗ c x protected theorem map_smul_inv {σ' : S →+* R} [RingHomInvPair σ σ'] (c : S) (x : M) : c • f x = f (σ' c • x) := by simp @[simp] theorem map_eq_zero_iff (h : Function.Injective f) {x : M} : f x = 0 ↔ x = 0 := _root_.map_eq_zero_iff f h variable (M M₂) /-- A typeclass for `SMul` structures which can be moved through a `LinearMap`. This typeclass is generated automatically from an `IsScalarTower` instance, but exists so that we can also add an instance for `AddCommGroup.toIntModule`, allowing `z •` to be moved even if `S` does not support negation. -/ class CompatibleSMul (R S : Type*) [Semiring S] [SMul R M] [Module S M] [SMul R M₂] [Module S M₂] : Prop where /-- Scalar multiplication by `R` of `M` can be moved through linear maps. -/ map_smul : ∀ (fₗ : M →ₗ[S] M₂) (c : R) (x : M), fₗ (c • x) = c • fₗ x variable {M M₂} section variable {R S : Type*} [Semiring S] [SMul R M] [Module S M] [SMul R M₂] [Module S M₂] instance (priority := 100) IsScalarTower.compatibleSMul [SMul R S] [IsScalarTower R S M] [IsScalarTower R S M₂] : CompatibleSMul M M₂ R S := ⟨fun fₗ c x ↦ by rw [← smul_one_smul S c x, ← smul_one_smul S c (fₗ x), map_smul]⟩ instance IsScalarTower.compatibleSMul' [SMul R S] [IsScalarTower R S M] : CompatibleSMul S M R S where map_smul := (IsScalarTower.smulHomClass R S M (S →ₗ[S] M)).map_smulₛₗ @[simp] theorem map_smul_of_tower [CompatibleSMul M M₂ R S] (fₗ : M →ₗ[S] M₂) (c : R) (x : M) : fₗ (c • x) = c • fₗ x := CompatibleSMul.map_smul fₗ c x theorem _root_.LinearMapClass.map_smul_of_tower {F : Type*} [CompatibleSMul M M₂ R S] [FunLike F M M₂] [LinearMapClass F S M M₂] (fₗ : F) (c : R) (x : M) : fₗ (c • x) = c • fₗ x := LinearMap.CompatibleSMul.map_smul (fₗ : M →ₗ[S] M₂) c x variable (R R) in theorem isScalarTower_of_injective [SMul R S] [CompatibleSMul M M₂ R S] [IsScalarTower R S M₂] (f : M →ₗ[S] M₂) (hf : Function.Injective f) : IsScalarTower R S M where smul_assoc r s _ := hf <| by rw [f.map_smul_of_tower r, map_smul, map_smul, smul_assoc] @[simp] lemma _root_.map_zsmul_unit {F M N : Type*} [AddGroup M] [AddGroup N] [FunLike F M N] [AddMonoidHomClass F M N] (f : F) (c : ℤˣ) (m : M) : f (c • m) = c • f m := by simp [Units.smul_def] end variable (R) in theorem isLinearMap_of_compatibleSMul [Module S M] [Module S M₂] [CompatibleSMul M M₂ R S] (f : M →ₗ[S] M₂) : IsLinearMap R f where map_add := map_add f map_smul := map_smul_of_tower f /-- convert a linear map to an additive map -/ def toAddMonoidHom : M →+ M₃ where toFun := f map_zero' := f.map_zero map_add' := f.map_add @[simp] theorem toAddMonoidHom_coe : ⇑f.toAddMonoidHom = f := rfl section RestrictScalars variable (R) variable [Module S M] [Module S M₂] [CompatibleSMul M M₂ R S] /-- If `M` and `M₂` are both `R`-modules and `S`-modules and `R`-module structures are defined by an action of `R` on `S` (formally, we have two scalar towers), then any `S`-linear map from `M` to `M₂` is `R`-linear. See also `LinearMap.map_smul_of_tower`. -/ @[coe] def restrictScalars (fₗ : M →ₗ[S] M₂) : M →ₗ[R] M₂ where toFun := fₗ map_add' := fₗ.map_add map_smul' := fₗ.map_smul_of_tower instance coeIsScalarTower : CoeHTCT (M →ₗ[S] M₂) (M →ₗ[R] M₂) := ⟨restrictScalars R⟩ @[simp, norm_cast] theorem coe_restrictScalars (f : M →ₗ[S] M₂) : ((f : M →ₗ[R] M₂) : M → M₂) = f := rfl @[simp] lemma restrictScalars_self (f : M →ₗ[R] M₂) : f.restrictScalars R = f := rfl theorem restrictScalars_apply (fₗ : M →ₗ[S] M₂) (x) : restrictScalars R fₗ x = fₗ x := rfl theorem restrictScalars_injective : Function.Injective (restrictScalars R : (M →ₗ[S] M₂) → M →ₗ[R] M₂) := fun _ _ h ↦ ext (LinearMap.congr_fun h :) @[simp] theorem restrictScalars_inj (fₗ gₗ : M →ₗ[S] M₂) : fₗ.restrictScalars R = gₗ.restrictScalars R ↔ fₗ = gₗ := (restrictScalars_injective R).eq_iff @[simp] lemma restrictScalars_id [CompatibleSMul M M R S] : (id (R := S) (M := M)).restrictScalars R = id := rfl end RestrictScalars theorem toAddMonoidHom_injective : Function.Injective (toAddMonoidHom : (M →ₛₗ[σ] M₃) → M →+ M₃) := fun fₗ gₗ h ↦ ext <| (DFunLike.congr_fun h : ∀ x, fₗ.toAddMonoidHom x = gₗ.toAddMonoidHom x) /-- If two `σ`-linear maps from `R` are equal on `1`, then they are equal. -/ @[ext high] theorem ext_ring {f g : R →ₛₗ[σ] M₃} (h : f 1 = g 1) : f = g := ext fun x ↦ by rw [← mul_one x, ← smul_eq_mul, f.map_smulₛₗ, g.map_smulₛₗ, h] end /-- Interpret a `RingHom` `f` as an `f`-semilinear map. -/ @[simps] def _root_.RingHom.toSemilinearMap (f : R →+* S) : R →ₛₗ[f] S := { f with map_smul' := f.map_mul } @[simp] theorem _root_.RingHom.coe_toSemilinearMap (f : R →+* S) : ⇑f.toSemilinearMap = f := rfl section variable [Semiring R₁] [Semiring R₂] [Semiring R₃] variable [AddCommMonoid M] [AddCommMonoid M₁] [AddCommMonoid M₂] [AddCommMonoid M₃] variable {module_M₁ : Module R₁ M₁} {module_M₂ : Module R₂ M₂} {module_M₃ : Module R₃ M₃} variable {σ₁₂ : R₁ →+* R₂} {σ₂₃ : R₂ →+* R₃} {σ₁₃ : R₁ →+* R₃} /-- Composition of two linear maps is a linear map -/ def comp [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃] (f : M₂ →ₛₗ[σ₂₃] M₃) (g : M₁ →ₛₗ[σ₁₂] M₂) : M₁ →ₛₗ[σ₁₃] M₃ where toFun := f ∘ g map_add' := by simp only [map_add, forall_const, Function.comp_apply] -- Note that https://github.com/leanprover-community/mathlib4/pull/8386 changed `map_smulₛₗ` to `map_smulₛₗ _` map_smul' r x := by simp only [Function.comp_apply, map_smulₛₗ _, RingHomCompTriple.comp_apply] variable [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃] variable (f : M₂ →ₛₗ[σ₂₃] M₃) (g : M₁ →ₛₗ[σ₁₂] M₂) /-- `∘ₗ` is notation for composition of two linear (not semilinear!) maps into a linear map. This is useful when Lean is struggling to infer the `RingHomCompTriple` instance. -/ notation3:80 (name := compNotation) f:81 " ∘ₗ " g:80 => LinearMap.comp (σ₁₂ := RingHom.id _) (σ₂₃ := RingHom.id _) (σ₁₃ := RingHom.id _) f g @[inherit_doc] infixr:90 " ∘ₛₗ " => comp theorem comp_apply (x : M₁) : f.comp g x = f (g x) := rfl @[simp, norm_cast] theorem coe_comp : (f.comp g : M₁ → M₃) = f ∘ g := rfl @[simp] theorem comp_id : f.comp id = f := rfl @[simp] theorem id_comp : id.comp f = f := rfl theorem comp_assoc {R₄ M₄ : Type*} [Semiring R₄] [AddCommMonoid M₄] [Module R₄ M₄] {σ₃₄ : R₃ →+* R₄} {σ₂₄ : R₂ →+* R₄} {σ₁₄ : R₁ →+* R₄} [RingHomCompTriple σ₂₃ σ₃₄ σ₂₄] [RingHomCompTriple σ₁₃ σ₃₄ σ₁₄] [RingHomCompTriple σ₁₂ σ₂₄ σ₁₄] (f : M₁ →ₛₗ[σ₁₂] M₂) (g : M₂ →ₛₗ[σ₂₃] M₃) (h : M₃ →ₛₗ[σ₃₄] M₄) : ((h.comp g : M₂ →ₛₗ[σ₂₄] M₄).comp f : M₁ →ₛₗ[σ₁₄] M₄) = h.comp (g.comp f : M₁ →ₛₗ[σ₁₃] M₃) := rfl variable {f g} {f' : M₂ →ₛₗ[σ₂₃] M₃} {g' : M₁ →ₛₗ[σ₁₂] M₂} /-- The linear map version of `Function.Surjective.injective_comp_right` -/ lemma _root_.Function.Surjective.injective_linearMapComp_right (hg : Surjective g) : Injective fun f : M₂ →ₛₗ[σ₂₃] M₃ ↦ f.comp g := fun _ _ h ↦ ext <| hg.forall.2 (LinearMap.ext_iff.1 h) @[simp] theorem cancel_right (hg : Surjective g) : f.comp g = f'.comp g ↔ f = f' := hg.injective_linearMapComp_right.eq_iff /-- The linear map version of `Function.Injective.comp_left` -/ lemma _root_.Function.Injective.injective_linearMapComp_left (hf : Injective f) : Injective fun g : M₁ →ₛₗ[σ₁₂] M₂ ↦ f.comp g := fun g₁ g₂ (h : f.comp g₁ = f.comp g₂) ↦ ext fun x ↦ hf <| by rw [← comp_apply, h, comp_apply] theorem surjective_comp_left_of_exists_rightInverse {σ₃₂ : R₃ →+* R₂} [RingHomInvPair σ₂₃ σ₃₂] [RingHomCompTriple σ₁₃ σ₃₂ σ₁₂] (hf : ∃ f' : M₃ →ₛₗ[σ₃₂] M₂, f.comp f' = .id) : Surjective fun g : M₁ →ₛₗ[σ₁₂] M₂ ↦ f.comp g := by intro h obtain ⟨f', hf'⟩ := hf refine ⟨f'.comp h, ?_⟩ simp_rw [← comp_assoc, hf', id_comp] @[simp] theorem cancel_left (hf : Injective f) : f.comp g = f.comp g' ↔ g = g' := hf.injective_linearMapComp_left.eq_iff end variable [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] variable [Module R M] [Module S M₂] {σ : R →+* S} {σ' : S →+* R} [RingHomInvPair σ σ'] /-- If a function `g` is a left and right inverse of a linear map `f`, then `g` is linear itself. -/ def inverse (f : M →ₛₗ[σ] M₂) (g : M₂ → M) (h₁ : LeftInverse g f) (h₂ : RightInverse g f) : M₂ →ₛₗ[σ'] M := by dsimp [LeftInverse, Function.RightInverse] at h₁ h₂ exact { toFun := g map_add' := fun x y ↦ by rw [← h₁ (g (x + y)), ← h₁ (g x + g y)]; simp [h₂] map_smul' := fun a b ↦ by rw [← h₁ (g (a • b)), ← h₁ (σ' a • g b)] simp [h₂] } variable (f : M →ₛₗ[σ] M₂) (g : M₂ →ₛₗ[σ'] M) (h : g.comp f = .id) include h theorem injective_of_comp_eq_id : Injective f := .of_comp (f := g) <| by simp_rw [← coe_comp, h, id_coe, bijective_id.1] theorem surjective_of_comp_eq_id : Surjective g := .of_comp (g := f) <| by simp_rw [← coe_comp, h, id_coe, bijective_id.2] end AddCommMonoid section AddCommGroup variable [Semiring R] [Semiring S] [AddCommGroup M] [AddCommGroup M₂] variable {module_M : Module R M} {module_M₂ : Module S M₂} {σ : R →+* S} variable (f : M →ₛₗ[σ] M₂) protected theorem map_neg (x : M) : f (-x) = -f x := map_neg f x protected theorem map_sub (x y : M) : f (x - y) = f x - f y := map_sub f x y instance CompatibleSMul.intModule {S : Type*} [Semiring S] [Module S M] [Module S M₂] : CompatibleSMul M M₂ ℤ S := ⟨fun fₗ c x ↦ by induction c with | zero => simp | succ n ih => simp [add_smul] | pred n ih => simp [sub_smul]⟩ instance CompatibleSMul.units {R S : Type*} [Monoid R] [MulAction R M] [MulAction R M₂] [Semiring S] [Module S M] [Module S M₂] [CompatibleSMul M M₂ R S] : CompatibleSMul M M₂ Rˣ S := ⟨fun fₗ c x ↦ (CompatibleSMul.map_smul fₗ (c : R) x :)⟩ end AddCommGroup end LinearMap namespace Module /-- `g : R →+* S` is `R`-linear when the module structure on `S` is `Module.compHom S g` . -/ @[simps] def compHom.toLinearMap {R S : Type*} [Semiring R] [Semiring S] (g : R →+* S) : letI := compHom S g; R →ₗ[R] S := letI := compHom S g { toFun := (g : R → S) map_add' := g.map_add map_smul' := g.map_mul } end Module namespace DistribMulActionHom variable [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] variable [Semiring R] [Module R M] [Semiring S] [Module S M₂] [Module R M₃] variable {σ : R →+* S} instance : SemilinearMapClass (M →ₑ+[σ.toMonoidHom] M₂) σ M M₂ where /-- A `DistribMulActionHom` between two modules is a linear map. -/ instance : LinearMapClass (M →+[R] M₃) R M M₃ where @[simp] theorem coe_toLinearMap (f : M →ₑ+[σ.toMonoidHom] M₂) : ((f : M →ₛₗ[σ] M₂) : M → M₂) = f := rfl theorem toLinearMap_injective {f g : M →ₑ+[σ.toMonoidHom] M₂} (h : (f : M →ₛₗ[σ] M₂) = (g : M →ₛₗ[σ] M₂)) : f = g := by ext m exact LinearMap.congr_fun h m end DistribMulActionHom namespace IsLinearMap section AddCommMonoid variable [Semiring R] [AddCommMonoid M] [AddCommMonoid M₂] variable [Module R M] [Module R M₂] /-- Convert an `IsLinearMap` predicate to a `LinearMap` -/ def mk' (f : M → M₂) (lin : IsLinearMap R f) : M →ₗ[R] M₂ where toFun := f map_add' := lin.1 map_smul' := lin.2 @[simp] theorem mk'_apply {f : M → M₂} (lin : IsLinearMap R f) (x : M) : mk' f lin x = f x := rfl theorem isLinearMap_smul {R M : Type*} [CommSemiring R] [AddCommMonoid M] [Module R M] (c : R) : IsLinearMap R fun z : M ↦ c • z := by refine IsLinearMap.mk (smul_add c) ?_ intro _ _ simp only [smul_smul, mul_comm] theorem isLinearMap_smul' {R M : Type*} [Semiring R] [AddCommMonoid M] [Module R M] (a : M) : IsLinearMap R fun c : R ↦ c • a := IsLinearMap.mk (fun x y ↦ add_smul x y a) fun x y ↦ mul_smul x y a theorem map_zero {f : M → M₂} (lin : IsLinearMap R f) : f (0 : M) = (0 : M₂) := (lin.mk' f).map_zero end AddCommMonoid section AddCommGroup variable [Semiring R] [AddCommGroup M] [AddCommGroup M₂] variable [Module R M] [Module R M₂] theorem isLinearMap_neg : IsLinearMap R fun z : M ↦ -z := IsLinearMap.mk neg_add fun x y ↦ (smul_neg x y).symm theorem map_neg {f : M → M₂} (lin : IsLinearMap R f) (x : M) : f (-x) = -f x := (lin.mk' f).map_neg x theorem map_sub {f : M → M₂} (lin : IsLinearMap R f) (x y : M) : f (x - y) = f x - f y := (lin.mk' f).map_sub x y end AddCommGroup end IsLinearMap /-- Reinterpret an additive homomorphism as an `ℕ`-linear map. -/ def AddMonoidHom.toNatLinearMap [AddCommMonoid M] [AddCommMonoid M₂] (f : M →+ M₂) : M →ₗ[ℕ] M₂ where toFun := f map_add' := f.map_add map_smul' := map_nsmul f theorem AddMonoidHom.toNatLinearMap_injective [AddCommMonoid M] [AddCommMonoid M₂] : Function.Injective (@AddMonoidHom.toNatLinearMap M M₂ _ _) := by intro f g h ext x exact LinearMap.congr_fun h x @[simp] theorem AddMonoidHom.coe_toNatLinearMap [AddCommMonoid M] [AddCommMonoid M₂] (f : M →+ M₂) : ⇑f.toNatLinearMap = f := rfl /-- Reinterpret an additive homomorphism as a `ℤ`-linear map. -/ def AddMonoidHom.toIntLinearMap [AddCommGroup M] [AddCommGroup M₂] (f : M →+ M₂) : M →ₗ[ℤ] M₂ where toFun := f map_add' := f.map_add map_smul' := map_zsmul f theorem AddMonoidHom.toIntLinearMap_injective [AddCommGroup M] [AddCommGroup M₂] : Function.Injective (@AddMonoidHom.toIntLinearMap M M₂ _ _) := by intro f g h ext x exact LinearMap.congr_fun h x @[simp] theorem AddMonoidHom.coe_toIntLinearMap [AddCommGroup M] [AddCommGroup M₂] (f : M →+ M₂) : ⇑f.toIntLinearMap = f := rfl namespace LinearMap section SMul variable [Semiring R] [Semiring R₂] variable [AddCommMonoid M] [AddCommMonoid M₂] variable [Module R M] [Module R₂ M₂] variable {σ₁₂ : R →+* R₂} variable [Monoid S] [DistribMulAction S M₂] [SMulCommClass R₂ S M₂] variable [Monoid T] [DistribMulAction T M₂] [SMulCommClass R₂ T M₂] instance : SMul S (M →ₛₗ[σ₁₂] M₂) := ⟨fun a f ↦ { toFun := a • (f : M → M₂) map_add' := fun x y ↦ by simp only [Pi.smul_apply, f.map_add, smul_add] map_smul' := fun c x ↦ by simp [Pi.smul_apply, smul_comm] }⟩ @[simp] theorem smul_apply (a : S) (f : M →ₛₗ[σ₁₂] M₂) (x : M) : (a • f) x = a • f x := rfl theorem coe_smul (a : S) (f : M →ₛₗ[σ₁₂] M₂) : (a • f : M →ₛₗ[σ₁₂] M₂) = a • (f : M → M₂) := rfl instance [SMulCommClass S T M₂] : SMulCommClass S T (M →ₛₗ[σ₁₂] M₂) := ⟨fun _ _ _ ↦ ext fun _ ↦ smul_comm _ _ _⟩ -- example application of this instance: if S -> T -> R are homomorphisms of commutative rings and -- M and M₂ are R-modules then the S-module and T-module structures on Hom_R(M,M₂) are compatible. instance [SMul S T] [IsScalarTower S T M₂] : IsScalarTower S T (M →ₛₗ[σ₁₂] M₂) where smul_assoc _ _ _ := ext fun _ ↦ smul_assoc _ _ _ instance [DistribMulAction Sᵐᵒᵖ M₂] [SMulCommClass R₂ Sᵐᵒᵖ M₂] [IsCentralScalar S M₂] : IsCentralScalar S (M →ₛₗ[σ₁₂] M₂) where op_smul_eq_smul _ _ := ext fun _ ↦ op_smul_eq_smul _ _ end SMul /-! ### Arithmetic on the codomain -/ section Arithmetic variable [Semiring R₁] [Semiring R₂] [Semiring R₃] variable [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] variable [AddCommGroup N₂] [AddCommGroup N₃] variable [Module R₁ M] [Module R₂ M₂] [Module R₃ M₃] variable [Module R₂ N₂] [Module R₃ N₃] variable {σ₁₂ : R₁ →+* R₂} {σ₂₃ : R₂ →+* R₃} {σ₁₃ : R₁ →+* R₃} [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃] /-- The constant 0 map is linear. -/ instance : Zero (M →ₛₗ[σ₁₂] M₂) := ⟨{ toFun := 0 map_add' := by simp map_smul' := by simp }⟩ @[simp] theorem zero_apply (x : M) : (0 : M →ₛₗ[σ₁₂] M₂) x = 0 := rfl @[simp] theorem comp_zero (g : M₂ →ₛₗ[σ₂₃] M₃) : (g.comp (0 : M →ₛₗ[σ₁₂] M₂) : M →ₛₗ[σ₁₃] M₃) = 0 := ext fun c ↦ by rw [comp_apply, zero_apply, zero_apply, g.map_zero] @[simp] theorem zero_comp (f : M →ₛₗ[σ₁₂] M₂) : ((0 : M₂ →ₛₗ[σ₂₃] M₃).comp f : M →ₛₗ[σ₁₃] M₃) = 0 := rfl instance : Inhabited (M →ₛₗ[σ₁₂] M₂) := ⟨0⟩ @[simp] theorem default_def : (default : M →ₛₗ[σ₁₂] M₂) = 0 := rfl instance uniqueOfLeft [Subsingleton M] : Unique (M →ₛₗ[σ₁₂] M₂) := { inferInstanceAs (Inhabited (M →ₛₗ[σ₁₂] M₂)) with uniq := fun f => ext fun x => by rw [Subsingleton.elim x 0, map_zero, map_zero] } instance uniqueOfRight [Subsingleton M₂] : Unique (M →ₛₗ[σ₁₂] M₂) := coe_injective.unique theorem ne_zero_of_injective [Nontrivial M] {f : M →ₛₗ[σ₁₂] M₂} (hf : Injective f) : f ≠ 0 := have ⟨x, ne⟩ := exists_ne (0 : M) fun h ↦ hf.ne ne <| by simp [h] theorem ne_zero_of_surjective [Nontrivial M₂] {f : M →ₛₗ[σ₁₂] M₂} (hf : Surjective f) : f ≠ 0 := by have ⟨y, ne⟩ := exists_ne (0 : M₂) obtain ⟨x, rfl⟩ := hf y exact fun h ↦ ne congr($h x) /-- The sum of two linear maps is linear. -/ instance : Add (M →ₛₗ[σ₁₂] M₂) := ⟨fun f g ↦ { toFun := f + g map_add' := by simp [add_comm, add_left_comm] map_smul' := by simp [smul_add] }⟩ @[simp] theorem add_apply (f g : M →ₛₗ[σ₁₂] M₂) (x : M) : (f + g) x = f x + g x := rfl theorem add_comp (f : M →ₛₗ[σ₁₂] M₂) (g h : M₂ →ₛₗ[σ₂₃] M₃) : ((h + g).comp f : M →ₛₗ[σ₁₃] M₃) = h.comp f + g.comp f := rfl theorem comp_add (f g : M →ₛₗ[σ₁₂] M₂) (h : M₂ →ₛₗ[σ₂₃] M₃) : (h.comp (f + g) : M →ₛₗ[σ₁₃] M₃) = h.comp f + h.comp g := ext fun _ ↦ h.map_add _ _ /-- The type of linear maps is an additive monoid. -/ instance addCommMonoid : AddCommMonoid (M →ₛₗ[σ₁₂] M₂) := DFunLike.coe_injective.addCommMonoid _ rfl (fun _ _ ↦ rfl) fun _ _ ↦ rfl /-- The negation of a linear map is linear. -/ instance : Neg (M →ₛₗ[σ₁₂] N₂) := ⟨fun f ↦ { toFun := -f map_add' := by simp [add_comm] map_smul' := by simp }⟩ @[simp] theorem neg_apply (f : M →ₛₗ[σ₁₂] N₂) (x : M) : (-f) x = -f x := rfl @[simp] theorem neg_comp (f : M →ₛₗ[σ₁₂] M₂) (g : M₂ →ₛₗ[σ₂₃] N₃) : (-g).comp f = -g.comp f := rfl @[simp] theorem comp_neg (f : M →ₛₗ[σ₁₂] N₂) (g : N₂ →ₛₗ[σ₂₃] N₃) : g.comp (-f) = -g.comp f := ext fun _ ↦ g.map_neg _ /-- The subtraction of two linear maps is linear. -/ instance : Sub (M →ₛₗ[σ₁₂] N₂) := ⟨fun f g ↦ { toFun := f - g map_add' := fun x y ↦ by simp only [Pi.sub_apply, map_add, add_sub_add_comm] map_smul' := fun r x ↦ by simp [Pi.sub_apply, smul_sub] }⟩ @[simp] theorem sub_apply (f g : M →ₛₗ[σ₁₂] N₂) (x : M) : (f - g) x = f x - g x := rfl theorem sub_comp (f : M →ₛₗ[σ₁₂] M₂) (g h : M₂ →ₛₗ[σ₂₃] N₃) : (g - h).comp f = g.comp f - h.comp f := rfl theorem comp_sub (f g : M →ₛₗ[σ₁₂] N₂) (h : N₂ →ₛₗ[σ₂₃] N₃) : h.comp (g - f) = h.comp g - h.comp f := ext fun _ ↦ h.map_sub _ _ /-- The type of linear maps is an additive group. -/ instance addCommGroup : AddCommGroup (M →ₛₗ[σ₁₂] N₂) := DFunLike.coe_injective.addCommGroup _ rfl (fun _ _ ↦ rfl) (fun _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ _ ↦ rfl) fun _ _ ↦ rfl /-- Evaluation of a `σ₁₂`-linear map at a fixed `a`, as an `AddMonoidHom`. -/ @[simps] def evalAddMonoidHom (a : M) : (M →ₛₗ[σ₁₂] M₂) →+ M₂ where toFun f := f a map_add' f g := LinearMap.add_apply f g a map_zero' := rfl /-- `LinearMap.toAddMonoidHom` promoted to an `AddMonoidHom`. -/ @[simps] def toAddMonoidHom' : (M →ₛₗ[σ₁₂] M₂) →+ M →+ M₂ where toFun := toAddMonoidHom map_zero' := by ext; rfl map_add' := by intros; ext; rfl /-- If `M` is the zero module, then the identity map of `M` is the zero map. -/ @[simp] theorem identityMapOfZeroModuleIsZero [Subsingleton M] : id (R := R₁) (M := M) = 0 := Subsingleton.eq_zero id end Arithmetic section Actions variable [Semiring R] [Semiring R₂] [Semiring R₃] variable [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] variable [Module R M] [Module R₂ M₂] [Module R₃ M₃] variable {σ₁₂ : R →+* R₂} {σ₂₃ : R₂ →+* R₃} {σ₁₃ : R →+* R₃} [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃] section SMul variable [Monoid S] [DistribMulAction S M₂] [SMulCommClass R₂ S M₂] variable [Monoid S₃] [DistribMulAction S₃ M₃] [SMulCommClass R₃ S₃ M₃] instance : DistribMulAction S (M →ₛₗ[σ₁₂] M₂) where one_smul _ := ext fun _ ↦ one_smul _ _ mul_smul _ _ _ := ext fun _ ↦ mul_smul _ _ _ smul_add _ _ _ := ext fun _ ↦ smul_add _ _ _ smul_zero _ := ext fun _ ↦ smul_zero _ theorem smul_comp (a : S₃) (g : M₂ →ₛₗ[σ₂₃] M₃) (f : M →ₛₗ[σ₁₂] M₂) : (a • g).comp f = a • g.comp f := rfl -- TODO: generalize this to semilinear maps theorem comp_smul [Module R M₂] [Module R M₃] [SMulCommClass R S M₂] [DistribMulAction S M₃] [SMulCommClass R S M₃] [CompatibleSMul M₃ M₂ S R] (g : M₃ →ₗ[R] M₂) (a : S) (f : M →ₗ[R] M₃) : g.comp (a • f) = a • g.comp f := ext fun _ ↦ g.map_smul_of_tower _ _ end SMul section Module variable [Semiring S] [Module S M] [Module S M₂] [SMulCommClass R₂ S M₂] instance module : Module S (M →ₛₗ[σ₁₂] M₂) where add_smul _ _ _ := ext fun _ ↦ add_smul _ _ _ zero_smul _ := ext fun _ ↦ zero_smul _ _ end Module end Actions section RestrictScalarsAsLinearMap variable {R S M N P : Type*} [Semiring R] [Semiring S] [AddCommMonoid M] [AddCommMonoid N] [Module R M] [Module R N] [Module S M] [Module S N] [CompatibleSMul M N R S] variable (R S M N) in @[simp] lemma restrictScalars_zero : (0 : M →ₗ[S] N).restrictScalars R = 0 := rfl @[simp] theorem restrictScalars_add (f g : M →ₗ[S] N) : (f + g).restrictScalars R = f.restrictScalars R + g.restrictScalars R := rfl @[simp] theorem restrictScalars_neg {M N : Type*} [AddCommMonoid M] [AddCommGroup N] [Module R M] [Module R N] [Module S M] [Module S N] [CompatibleSMul M N R S] (f : M →ₗ[S] N) : (-f).restrictScalars R = -f.restrictScalars R := rfl variable {R₁ : Type*} [Semiring R₁] [Module R₁ N] [SMulCommClass S R₁ N] [SMulCommClass R R₁ N] @[simp] theorem restrictScalars_smul (c : R₁) (f : M →ₗ[S] N) : (c • f).restrictScalars R = c • f.restrictScalars R := rfl @[simp] lemma restrictScalars_comp [AddCommMonoid P] [Module S P] [Module R P] [CompatibleSMul N P R S] [CompatibleSMul M P R S] (f : N →ₗ[S] P) (g : M →ₗ[S] N) : (f ∘ₗ g).restrictScalars R = f.restrictScalars R ∘ₗ g.restrictScalars R := rfl @[simp] lemma restrictScalars_trans {T : Type*} [Semiring T] [Module T M] [Module T N] [CompatibleSMul M N S T] [CompatibleSMul M N R T] (f : M →ₗ[T] N) : (f.restrictScalars S).restrictScalars R = f.restrictScalars R := rfl variable (S M N R R₁) /-- `LinearMap.restrictScalars` as a `LinearMap`. -/ @[simps apply] def restrictScalarsₗ : (M →ₗ[S] N) →ₗ[R₁] M →ₗ[R] N where toFun := restrictScalars R map_add' := restrictScalars_add map_smul' := restrictScalars_smul end RestrictScalarsAsLinearMap end LinearMap
.lake/packages/mathlib/Mathlib/Algebra/Module/LinearMap/DivisionRing.lean
import Mathlib.Algebra.Module.Submodule.Range import Mathlib.LinearAlgebra.Span.Defs /-! # Some lemmas about linear functionals on division rings This file proves some results on linear functionals on division semirings. ## Main results * `LinearMap.surjective_iff_ne_zero`: a linear functional `f` is surjective iff `f ≠ 0`. * `LinearMap.range_smulRight_apply`: for a nonzero linear functional `f` and element `x`, the range of `f.smulRight x` is the span of the set `{x}`. -/ namespace LinearMap variable {R M M₁ : Type*} [AddCommMonoid M] [AddCommMonoid M₁] theorem surjective_iff_ne_zero [DivisionSemiring R] [Module R M] {f : M →ₗ[R] R} : Function.Surjective f ↔ f ≠ 0 := by refine ⟨ne_zero_of_surjective, fun hf z ↦ ?_⟩ obtain ⟨y, hy⟩ : ∃ y, f y ≠ 0 := by simpa [Ne, LinearMap.ext_iff] using hf exact ⟨(z * (f y)⁻¹) • y, by simp [hy]⟩ protected alias ⟨_, surjective⟩ := surjective_iff_ne_zero theorem range_smulRight_apply_of_surjective [Semiring R] [Module R M] [Module R M₁] {f : M →ₗ[R] R} (hf : Function.Surjective f) (x : M₁) : range (f.smulRight x) = Submodule.span R {x} := Submodule.ext fun z ↦ by simp_rw [mem_range, smulRight_apply, Submodule.mem_span_singleton] refine ⟨fun ⟨w, hw⟩ ↦ ⟨f w, hw ▸ rfl⟩, fun ⟨w, hw⟩ ↦ ?_⟩ obtain ⟨y, rfl⟩ := hf w exact ⟨y, hw⟩ theorem range_smulRight_apply [DivisionSemiring R] [Module R M] [Module R M₁] {f : M →ₗ[R] R} (hf : f ≠ 0) (x : M₁) : range (f.smulRight x) = Submodule.span R {x} := range_smulRight_apply_of_surjective (f.surjective hf) x end LinearMap
.lake/packages/mathlib/Mathlib/Algebra/Module/LinearMap/Polynomial.lean
import Mathlib.Algebra.MvPolynomial.Monad import Mathlib.LinearAlgebra.Charpoly.ToMatrix import Mathlib.LinearAlgebra.FreeModule.StrongRankCondition import Mathlib.LinearAlgebra.Matrix.Charpoly.Univ import Mathlib.RingTheory.TensorProduct.Finite import Mathlib.RingTheory.TensorProduct.Free /-! # Characteristic polynomials of linear families of endomorphisms The coefficients of the characteristic polynomials of a linear family of endomorphisms are homogeneous polynomials in the parameters. This result is used in Lie theory to establish the existence of regular elements and Cartan subalgebras, and ultimately a well-defined notion of rank for Lie algebras. In this file we prove this result about characteristic polynomials. Let `L` and `M` be modules over a nontrivial commutative ring `R`, and let `φ : L →ₗ[R] Module.End R M` be a linear map. Let `b` be a basis of `L`, indexed by `ι`. Then we define a multivariate polynomial with variables indexed by `ι` that evaluates on elements `x` of `L` to the characteristic polynomial of `φ x`. ## Main declarations * `Matrix.toMvPolynomial M i`: the family of multivariate polynomials that evaluates on `c : n → R` to the dot product of the `i`-th row of `M` with `c`. `Matrix.toMvPolynomial M i` is the sum of the monomials `C (M i j) * X j`. * `LinearMap.toMvPolynomial b₁ b₂ f`: a version of `Matrix.toMvPolynomial` for linear maps `f` with respect to bases `b₁` and `b₂` of the domain and codomain. * `LinearMap.polyCharpoly`: the multivariate polynomial that evaluates on elements `x` of `L` to the characteristic polynomial of `φ x`. * `LinearMap.polyCharpoly_map_eq_charpoly`: the evaluation of `polyCharpoly` on elements `x` of `L` is the characteristic polynomial of `φ x`. * `LinearMap.polyCharpoly_coeff_isHomogeneous`: the coefficients of `polyCharpoly` are homogeneous polynomials in the parameters. * `LinearMap.nilRank`: the smallest index at which `polyCharpoly` has a non-zero coefficient, which is independent of the choice of basis for `L`. * `LinearMap.IsNilRegular`: an element `x` of `L` is *nil-regular* with respect to `φ` if the `n`-th coefficient of the characteristic polynomial of `φ x` is non-zero, where `n` denotes the nil-rank of `φ`. ## Implementation details We show that `LinearMap.polyCharpoly` does not depend on the choice of basis of the target module. This is done via `LinearMap.polyCharpoly_eq_polyCharpolyAux` and `LinearMap.polyCharpolyAux_basisIndep`. The latter is proven by considering the base change of the `R`-linear map `φ : L →ₗ[R] End R M` to the multivariate polynomial ring `MvPolynomial ι R`, and showing that `polyCharpolyAux φ` is equal to the characteristic polynomial of this base change. The proof concludes because characteristic polynomials are independent of the chosen basis. ## References * [barnes1967]: "On Cartan subalgebras of Lie algebras" by D.W. Barnes. -/ open Module MvPolynomial open scoped Matrix namespace Matrix variable {m n o R S : Type*} variable [Fintype n] [Fintype o] [CommSemiring R] [CommSemiring S] /-- Let `M` be an `(m × n)`-matrix over `R`. Then `Matrix.toMvPolynomial M` is the family (indexed by `i : m`) of multivariate polynomials in `n` variables over `R` that evaluates on `c : n → R` to the dot product of the `i`-th row of `M` with `c`: `Matrix.toMvPolynomial M i` is the sum of the monomials `C (M i j) * X j`. -/ noncomputable def toMvPolynomial (M : Matrix m n R) (i : m) : MvPolynomial n R := ∑ j, monomial (.single j 1) (M i j) lemma toMvPolynomial_eval_eq_apply (M : Matrix m n R) (i : m) (c : n → R) : eval c (M.toMvPolynomial i) = (M *ᵥ c) i := by simp only [toMvPolynomial, map_sum, eval_monomial, pow_zero, Finsupp.prod_single_index, pow_one, mulVec, dotProduct] lemma toMvPolynomial_map (f : R →+* S) (M : Matrix m n R) (i : m) : (M.map f).toMvPolynomial i = MvPolynomial.map f (M.toMvPolynomial i) := by simp only [toMvPolynomial, map_apply, map_sum, map_monomial] lemma toMvPolynomial_isHomogeneous (M : Matrix m n R) (i : m) : (M.toMvPolynomial i).IsHomogeneous 1 := by apply MvPolynomial.IsHomogeneous.sum rintro j - apply MvPolynomial.isHomogeneous_monomial _ _ simp [Finsupp.degree, Finsupp.support_single_ne_zero _ one_ne_zero, Finset.sum_singleton, Finsupp.single_eq_same] lemma toMvPolynomial_totalDegree_le (M : Matrix m n R) (i : m) : (M.toMvPolynomial i).totalDegree ≤ 1 := by apply (toMvPolynomial_isHomogeneous _ _).totalDegree_le @[simp] lemma toMvPolynomial_constantCoeff (M : Matrix m n R) (i : m) : constantCoeff (M.toMvPolynomial i) = 0 := by simp only [toMvPolynomial, ← C_mul_X_eq_monomial, map_sum, map_mul, constantCoeff_X, mul_zero, Finset.sum_const_zero] @[simp] lemma toMvPolynomial_zero : (0 : Matrix m n R).toMvPolynomial = 0 := by ext; simp only [toMvPolynomial, zero_apply, map_zero, Finset.sum_const_zero, Pi.zero_apply] @[simp] lemma toMvPolynomial_one [DecidableEq n] : (1 : Matrix n n R).toMvPolynomial = X := by ext i : 1 rw [toMvPolynomial, Finset.sum_eq_single i] · simp only [one_apply_eq, ← C_mul_X_eq_monomial, C_1, one_mul] · rintro j - hj simp only [one_apply_ne hj.symm, map_zero] · grind lemma toMvPolynomial_add (M N : Matrix m n R) : (M + N).toMvPolynomial = M.toMvPolynomial + N.toMvPolynomial := by ext i : 1 simp only [toMvPolynomial, add_apply, map_add, Finset.sum_add_distrib, Pi.add_apply] lemma toMvPolynomial_mul (M : Matrix m n R) (N : Matrix n o R) (i : m) : (M * N).toMvPolynomial i = bind₁ N.toMvPolynomial (M.toMvPolynomial i) := by simp only [toMvPolynomial, mul_apply, map_sum, Finset.sum_comm (γ := o), bind₁, aeval, AlgHom.coe_mk, coe_eval₂Hom, eval₂_monomial, algebraMap_apply, Algebra.algebraMap_self, RingHom.id_apply, C_apply, pow_zero, Finsupp.prod_single_index, pow_one, Finset.mul_sum, monomial_mul, zero_add] end Matrix namespace LinearMap open MvPolynomial section variable {R M₁ M₂ ι₁ ι₂ : Type*} variable [CommRing R] [AddCommGroup M₁] [AddCommGroup M₂] variable [Module R M₁] [Module R M₂] variable [Fintype ι₁] [Finite ι₂] variable [DecidableEq ι₁] variable (b₁ : Basis ι₁ R M₁) (b₂ : Basis ι₂ R M₂) /-- Let `f : M₁ →ₗ[R] M₂` be an `R`-linear map between modules `M₁` and `M₂` with bases `b₁` and `b₂` respectively. Then `LinearMap.toMvPolynomial b₁ b₂ f` is the family of multivariate polynomials over `R` that evaluates on an element `x` of `M₁` (represented on the basis `b₁`) to the element `f x` of `M₂` (represented on the basis `b₂`). -/ noncomputable def toMvPolynomial (f : M₁ →ₗ[R] M₂) (i : ι₂) : MvPolynomial ι₁ R := (toMatrix b₁ b₂ f).toMvPolynomial i lemma toMvPolynomial_eval_eq_apply (f : M₁ →ₗ[R] M₂) (i : ι₂) (c : ι₁ →₀ R) : eval c (f.toMvPolynomial b₁ b₂ i) = b₂.repr (f (b₁.repr.symm c)) i := by rw [toMvPolynomial, Matrix.toMvPolynomial_eval_eq_apply, ← LinearMap.toMatrix_mulVec_repr b₁ b₂, LinearEquiv.apply_symm_apply] open Algebra.TensorProduct in lemma toMvPolynomial_baseChange (f : M₁ →ₗ[R] M₂) (i : ι₂) (A : Type*) [CommRing A] [Algebra R A] : (f.baseChange A).toMvPolynomial (basis A b₁) (basis A b₂) i = MvPolynomial.map (algebraMap R A) (f.toMvPolynomial b₁ b₂ i) := by simp only [toMvPolynomial, toMatrix_baseChange, Matrix.toMvPolynomial_map] lemma toMvPolynomial_isHomogeneous (f : M₁ →ₗ[R] M₂) (i : ι₂) : (f.toMvPolynomial b₁ b₂ i).IsHomogeneous 1 := Matrix.toMvPolynomial_isHomogeneous _ _ lemma toMvPolynomial_totalDegree_le (f : M₁ →ₗ[R] M₂) (i : ι₂) : (f.toMvPolynomial b₁ b₂ i).totalDegree ≤ 1 := Matrix.toMvPolynomial_totalDegree_le _ _ @[simp] lemma toMvPolynomial_constantCoeff (f : M₁ →ₗ[R] M₂) (i : ι₂) : constantCoeff (f.toMvPolynomial b₁ b₂ i) = 0 := Matrix.toMvPolynomial_constantCoeff _ _ @[simp] lemma toMvPolynomial_zero : (0 : M₁ →ₗ[R] M₂).toMvPolynomial b₁ b₂ = 0 := by unfold toMvPolynomial; simp only [map_zero, Matrix.toMvPolynomial_zero] @[simp] lemma toMvPolynomial_id : (id : M₁ →ₗ[R] M₁).toMvPolynomial b₁ b₁ = X := by unfold toMvPolynomial; simp only [toMatrix_id, Matrix.toMvPolynomial_one] lemma toMvPolynomial_add (f g : M₁ →ₗ[R] M₂) : (f + g).toMvPolynomial b₁ b₂ = f.toMvPolynomial b₁ b₂ + g.toMvPolynomial b₁ b₂ := by unfold toMvPolynomial; simp only [map_add, Matrix.toMvPolynomial_add] end variable {R M₁ M₂ M₃ ι₁ ι₂ ι₃ : Type*} variable [CommRing R] [AddCommGroup M₁] [AddCommGroup M₂] [AddCommGroup M₃] variable [Module R M₁] [Module R M₂] [Module R M₃] variable [Fintype ι₁] [Fintype ι₂] [Finite ι₃] variable [DecidableEq ι₁] [DecidableEq ι₂] variable (b₁ : Basis ι₁ R M₁) (b₂ : Basis ι₂ R M₂) (b₃ : Basis ι₃ R M₃) lemma toMvPolynomial_comp (g : M₂ →ₗ[R] M₃) (f : M₁ →ₗ[R] M₂) (i : ι₃) : (g ∘ₗ f).toMvPolynomial b₁ b₃ i = bind₁ (f.toMvPolynomial b₁ b₂) (g.toMvPolynomial b₂ b₃ i) := by simp only [toMvPolynomial, toMatrix_comp b₁ b₂ b₃, Matrix.toMvPolynomial_mul] rfl end LinearMap variable {R L M n ι ι' ιM : Type*} variable [CommRing R] [AddCommGroup L] [Module R L] [AddCommGroup M] [Module R M] variable (φ : L →ₗ[R] Module.End R M) variable [Fintype ι] [Fintype ι'] [Fintype ιM] [DecidableEq ι] [DecidableEq ι'] namespace LinearMap section aux variable [DecidableEq ιM] (b : Basis ι R L) (bₘ : Basis ιM R M) open Matrix /-- (Implementation detail, see `LinearMap.polyCharpoly`.) Let `L` and `M` be finite free modules over `R`, and let `φ : L →ₗ[R] Module.End R M` be a linear map. Let `b` be a basis of `L` and `bₘ` a basis of `M`. Then `LinearMap.polyCharpolyAux φ b bₘ` is the polynomial that evaluates on elements `x` of `L` to the characteristic polynomial of `φ x` acting on `M`. This definition does not depend on the choice of `bₘ` (see `LinearMap.polyCharpolyAux_basisIndep`). -/ noncomputable def polyCharpolyAux : Polynomial (MvPolynomial ι R) := (charpoly.univ R ιM).map <| MvPolynomial.bind₁ (φ.toMvPolynomial b bₘ.end) open Algebra.TensorProduct MvPolynomial in lemma polyCharpolyAux_baseChange (A : Type*) [CommRing A] [Algebra R A] : polyCharpolyAux (tensorProduct _ _ _ _ ∘ₗ φ.baseChange A) (basis A b) (basis A bₘ) = (polyCharpolyAux φ b bₘ).map (MvPolynomial.map (algebraMap R A)) := by simp only [polyCharpolyAux] rw [← charpoly.univ_map_map _ (algebraMap R A)] simp only [Polynomial.map_map] congr 1 apply ringHom_ext · intro r simp only [RingHom.coe_comp, RingHom.coe_coe, Function.comp_apply, map_C, bind₁_C_right] · rintro ij simp only [RingHom.coe_comp, RingHom.coe_coe, Function.comp_apply, map_X, bind₁_X_right] classical rw [toMvPolynomial_comp _ (basis A (Basis.end bₘ)), ← toMvPolynomial_baseChange] suffices toMvPolynomial (M₂ := (Module.End A (TensorProduct R A M))) (basis A bₘ.end) (basis A bₘ).end (tensorProduct R A M M) ij = X ij by rw [this, bind₁_X_right] simp only [toMvPolynomial, Matrix.toMvPolynomial] suffices ∀ kl, (toMatrix (basis A bₘ.end) (basis A bₘ).end) (tensorProduct R A M M) ij kl = if kl = ij then 1 else 0 by rw [Finset.sum_eq_single ij] · rw [this, if_pos rfl, X] · rintro kl - H rw [this, if_neg H, map_zero] · grind intro kl rw [toMatrix_apply, tensorProduct, TensorProduct.AlgebraTensorModule.lift_apply, basis_apply, TensorProduct.lift.tmul, coe_restrictScalars] dsimp only [coe_mk, AddHom.coe_mk, smul_apply, baseChangeHom_apply] rw [one_smul, Basis.baseChange_end, Basis.repr_self_apply] open LinearMap in lemma polyCharpolyAux_map_eq_toMatrix_charpoly (x : L) : (polyCharpolyAux φ b bₘ).map (MvPolynomial.eval (b.repr x)) = (toMatrix bₘ bₘ (φ x)).charpoly := by rw [polyCharpolyAux, Polynomial.map_map, ← MvPolynomial.eval₂Hom_C_eq_bind₁, MvPolynomial.comp_eval₂Hom, charpoly.univ_map_eval₂Hom] congr ext rw [of_apply, Function.curry_apply, toMvPolynomial_eval_eq_apply, LinearEquiv.symm_apply_apply] rfl open LinearMap in lemma polyCharpolyAux_eval_eq_toMatrix_charpoly_coeff (x : L) (i : ℕ) : MvPolynomial.eval (b.repr x) ((polyCharpolyAux φ b bₘ).coeff i) = (toMatrix bₘ bₘ (φ x)).charpoly.coeff i := by simp [← polyCharpolyAux_map_eq_toMatrix_charpoly φ b bₘ x] @[simp] lemma polyCharpolyAux_map_eq_charpoly [Module.Finite R M] [Module.Free R M] (x : L) : (polyCharpolyAux φ b bₘ).map (MvPolynomial.eval (b.repr x)) = (φ x).charpoly := by nontriviality R rw [polyCharpolyAux_map_eq_toMatrix_charpoly, LinearMap.charpoly_toMatrix] @[simp] lemma polyCharpolyAux_coeff_eval [Module.Finite R M] [Module.Free R M] (x : L) (i : ℕ) : MvPolynomial.eval (b.repr x) ((polyCharpolyAux φ b bₘ).coeff i) = (φ x).charpoly.coeff i := by nontriviality R rw [← polyCharpolyAux_map_eq_charpoly φ b bₘ x, Polynomial.coeff_map] lemma polyCharpolyAux_map_eval [Module.Finite R M] [Module.Free R M] (x : ι → R) : (polyCharpolyAux φ b bₘ).map (MvPolynomial.eval x) = (φ (b.repr.symm (Finsupp.equivFunOnFinite.symm x))).charpoly := by simp only [← polyCharpolyAux_map_eq_charpoly φ b bₘ, LinearEquiv.apply_symm_apply, Finsupp.equivFunOnFinite, Equiv.coe_fn_symm_mk, Finsupp.coe_mk] open Algebra.TensorProduct TensorProduct in lemma polyCharpolyAux_map_aeval (A : Type*) [CommRing A] [Algebra R A] [Module.Finite A (A ⊗[R] M)] [Module.Free A (A ⊗[R] M)] (x : ι → A) : (polyCharpolyAux φ b bₘ).map (MvPolynomial.aeval x).toRingHom = LinearMap.charpoly ((tensorProduct R A M M).comp (baseChange A φ) ((basis A b).repr.symm (Finsupp.equivFunOnFinite.symm x))) := by rw [← polyCharpolyAux_map_eval (tensorProduct R A M M ∘ₗ baseChange A φ) _ (basis A bₘ), polyCharpolyAux_baseChange, Polynomial.map_map] congr exact DFunLike.ext _ _ fun f ↦ (MvPolynomial.eval_map (algebraMap R A) x f).symm open Algebra.TensorProduct MvPolynomial in /-- `LinearMap.polyCharpolyAux` is independent of the choice of basis of the target module. Proof strategy: 1. Rewrite `polyCharpolyAux` as the (honest, ordinary) characteristic polynomial of the basechange of `φ` to the multivariate polynomial ring `MvPolynomial ι R`. 2. Use that the characteristic polynomial of a linear map is independent of the choice of basis. This independence result is used transitively via `LinearMap.polyCharpolyAux_map_aeval` and `LinearMap.polyCharpolyAux_map_eq_charpoly`. -/ lemma polyCharpolyAux_basisIndep {ιM' : Type*} [Fintype ιM'] [DecidableEq ιM'] (bₘ' : Basis ιM' R M) : polyCharpolyAux φ b bₘ = polyCharpolyAux φ b bₘ' := by let f : Polynomial (MvPolynomial ι R) → Polynomial (MvPolynomial ι R) := Polynomial.map (MvPolynomial.aeval X).toRingHom have hf : Function.Injective f := by simp only [f, aeval_X_left, AlgHom.toRingHom_eq_coe, AlgHom.id_toRingHom] exact Polynomial.map_injective (RingHom.id _) Function.injective_id apply hf let _h1 : Module.Finite (MvPolynomial ι R) (TensorProduct R (MvPolynomial ι R) M) := Module.Finite.of_basis (basis (MvPolynomial ι R) bₘ) let _h2 : Module.Free (MvPolynomial ι R) (TensorProduct R (MvPolynomial ι R) M) := Module.Free.of_basis (basis (MvPolynomial ι R) bₘ) simp only [f, polyCharpolyAux_map_aeval, polyCharpolyAux_map_aeval] end aux open Module Matrix variable [Module.Free R M] [Module.Finite R M] (b : Basis ι R L) /-- Let `L` and `M` be finite free modules over `R`, and let `φ : L →ₗ[R] Module.End R M` be a linear family of endomorphisms. Let `b` be a basis of `L` and `bₘ` a basis of `M`. Then `LinearMap.polyCharpoly φ b` is the polynomial that evaluates on elements `x` of `L` to the characteristic polynomial of `φ x` acting on `M`. -/ noncomputable def polyCharpoly : Polynomial (MvPolynomial ι R) := φ.polyCharpolyAux b (Module.Free.chooseBasis R M) lemma polyCharpoly_eq_of_basis [DecidableEq ιM] (bₘ : Basis ιM R M) : polyCharpoly φ b = (charpoly.univ R ιM).map (MvPolynomial.bind₁ (φ.toMvPolynomial b bₘ.end)) := by rw [polyCharpoly, φ.polyCharpolyAux_basisIndep b (Module.Free.chooseBasis R M) bₘ, polyCharpolyAux] lemma polyCharpoly_monic : (polyCharpoly φ b).Monic := (charpoly.univ_monic R _).map _ lemma polyCharpoly_ne_zero [Nontrivial R] : (polyCharpoly φ b) ≠ 0 := (polyCharpoly_monic _ _).ne_zero @[simp] lemma polyCharpoly_natDegree [Nontrivial R] : (polyCharpoly φ b).natDegree = finrank R M := by rw [polyCharpoly, polyCharpolyAux, (charpoly.univ_monic _ _).natDegree_map, charpoly.univ_natDegree, finrank_eq_card_chooseBasisIndex] lemma polyCharpoly_coeff_isHomogeneous (i j : ℕ) (hij : i + j = finrank R M) [Nontrivial R] : ((polyCharpoly φ b).coeff i).IsHomogeneous j := by rw [finrank_eq_card_chooseBasisIndex] at hij rw [polyCharpoly, polyCharpolyAux, Polynomial.coeff_map, ← one_mul j] apply (charpoly.univ_coeff_isHomogeneous _ _ _ _ hij).eval₂ · exact fun r ↦ MvPolynomial.isHomogeneous_C _ _ · exact LinearMap.toMvPolynomial_isHomogeneous _ _ _ open Algebra.TensorProduct MvPolynomial in lemma polyCharpoly_baseChange (A : Type*) [CommRing A] [Algebra R A] : polyCharpoly (tensorProduct _ _ _ _ ∘ₗ φ.baseChange A) (basis A b) = (polyCharpoly φ b).map (MvPolynomial.map (algebraMap R A)) := by unfold polyCharpoly rw [← φ.polyCharpolyAux_baseChange] apply polyCharpolyAux_basisIndep @[simp] lemma polyCharpoly_map_eq_charpoly (x : L) : (polyCharpoly φ b).map (MvPolynomial.eval (b.repr x)) = (φ x).charpoly := by rw [polyCharpoly, polyCharpolyAux_map_eq_charpoly] @[simp] lemma polyCharpoly_coeff_eval (x : L) (i : ℕ) : MvPolynomial.eval (b.repr x) ((polyCharpoly φ b).coeff i) = (φ x).charpoly.coeff i := by rw [polyCharpoly, polyCharpolyAux_coeff_eval] lemma polyCharpoly_coeff_eq_zero_of_basis (b : Basis ι R L) (b' : Basis ι' R L) (k : ℕ) (H : (polyCharpoly φ b).coeff k = 0) : (polyCharpoly φ b').coeff k = 0 := by rw [polyCharpoly, polyCharpolyAux, Polynomial.coeff_map] at H ⊢ set B := (Module.Free.chooseBasis R M).end set g := toMvPolynomial b' b LinearMap.id apply_fun (MvPolynomial.bind₁ g) at H have : toMvPolynomial b' B φ = fun i ↦ (MvPolynomial.bind₁ g) (toMvPolynomial b B φ i) := funext <| toMvPolynomial_comp b' b B φ LinearMap.id rwa [map_zero, RingHom.coe_coe, MvPolynomial.bind₁_bind₁, ← this] at H lemma polyCharpoly_coeff_eq_zero_iff_of_basis (b : Basis ι R L) (b' : Basis ι' R L) (k : ℕ) : (polyCharpoly φ b).coeff k = 0 ↔ (polyCharpoly φ b').coeff k = 0 := by constructor <;> apply polyCharpoly_coeff_eq_zero_of_basis section aux /-- (Implementation detail, see `LinearMap.nilRank`.) Let `L` and `M` be finite free modules over `R`, and let `φ : L →ₗ[R] Module.End R M` be a linear family of endomorphisms. Then `LinearMap.nilRankAux φ b` is the smallest index at which `LinearMap.polyCharpoly φ b` has a non-zero coefficient. This number does not depend on the choice of `b`, see `nilRankAux_basis_indep`. -/ noncomputable def nilRankAux (φ : L →ₗ[R] Module.End R M) (b : Basis ι R L) : ℕ := (polyCharpoly φ b).natTrailingDegree lemma polyCharpoly_coeff_nilRankAux_ne_zero [Nontrivial R] : (polyCharpoly φ b).coeff (nilRankAux φ b) ≠ 0 := by apply Polynomial.trailingCoeff_nonzero_iff_nonzero.mpr apply polyCharpoly_ne_zero lemma nilRankAux_le [Nontrivial R] (b : Basis ι R L) (b' : Basis ι' R L) : nilRankAux φ b ≤ nilRankAux φ b' := by apply Polynomial.natTrailingDegree_le_of_ne_zero rw [Ne, (polyCharpoly_coeff_eq_zero_iff_of_basis φ b b' _).not] apply polyCharpoly_coeff_nilRankAux_ne_zero lemma nilRankAux_basis_indep [Nontrivial R] (b : Basis ι R L) (b' : Basis ι' R L) : nilRankAux φ b = (polyCharpoly φ b').natTrailingDegree := by apply le_antisymm <;> apply nilRankAux_le end aux variable [Module.Finite R L] [Module.Free R L] /-- Let `L` and `M` be finite free modules over `R`, and let `φ : L →ₗ[R] Module.End R M` be a linear family of endomorphisms. Then `LinearMap.nilRank φ b` is the smallest index at which `LinearMap.polyCharpoly φ b` has a non-zero coefficient. This number does not depend on the choice of `b`, see `LinearMap.nilRank_eq_polyCharpoly_natTrailingDegree`. -/ noncomputable def nilRank (φ : L →ₗ[R] Module.End R M) : ℕ := nilRankAux φ (Module.Free.chooseBasis R L) section variable [Nontrivial R] lemma nilRank_eq_polyCharpoly_natTrailingDegree (b : Basis ι R L) : nilRank φ = (polyCharpoly φ b).natTrailingDegree := by apply nilRankAux_basis_indep lemma polyCharpoly_coeff_nilRank_ne_zero : (polyCharpoly φ b).coeff (nilRank φ) ≠ 0 := by rw [nilRank_eq_polyCharpoly_natTrailingDegree _ b] apply polyCharpoly_coeff_nilRankAux_ne_zero open Module Module.Free lemma nilRank_le_card {ι : Type*} [Fintype ι] (b : Basis ι R M) : nilRank φ ≤ Fintype.card ι := by apply Polynomial.natTrailingDegree_le_of_ne_zero rw [← Module.finrank_eq_card_basis b, ← polyCharpoly_natDegree φ (chooseBasis R L), Polynomial.coeff_natDegree, (polyCharpoly_monic _ _).leadingCoeff] apply one_ne_zero lemma nilRank_le_finrank : nilRank φ ≤ finrank R M := by simpa only [finrank_eq_card_chooseBasisIndex R M] using nilRank_le_card φ (chooseBasis R M) lemma nilRank_le_natTrailingDegree_charpoly (x : L) : nilRank φ ≤ (φ x).charpoly.natTrailingDegree := by apply Polynomial.natTrailingDegree_le_of_ne_zero intro h apply_fun (MvPolynomial.eval ((chooseBasis R L).repr x)) at h rw [polyCharpoly_coeff_eval, map_zero] at h apply Polynomial.trailingCoeff_nonzero_iff_nonzero.mpr _ h apply (LinearMap.charpoly_monic _).ne_zero end /-- Let `L` and `M` be finite free modules over `R`, and let `φ : L →ₗ[R] Module.End R M` be a linear family of endomorphisms, and denote `n := nilRank φ`. An element `x : L` is *nil-regular* with respect to `φ` if the `n`-th coefficient of the characteristic polynomial of `φ x` is non-zero. -/ def IsNilRegular (x : L) : Prop := Polynomial.coeff (φ x).charpoly (nilRank φ) ≠ 0 variable (x : L) lemma isNilRegular_def : IsNilRegular φ x ↔ (Polynomial.coeff (φ x).charpoly (nilRank φ) ≠ 0) := Iff.rfl lemma isNilRegular_iff_coeff_polyCharpoly_nilRank_ne_zero : IsNilRegular φ x ↔ MvPolynomial.eval (b.repr x) ((polyCharpoly φ b).coeff (nilRank φ)) ≠ 0 := by rw [IsNilRegular, polyCharpoly_coeff_eval] lemma isNilRegular_iff_natTrailingDegree_charpoly_eq_nilRank [Nontrivial R] : IsNilRegular φ x ↔ (φ x).charpoly.natTrailingDegree = nilRank φ := by rw [isNilRegular_def] constructor · intro h exact le_antisymm (Polynomial.natTrailingDegree_le_of_ne_zero h) (nilRank_le_natTrailingDegree_charpoly φ x) · intro h rw [← h] apply Polynomial.trailingCoeff_nonzero_iff_nonzero.mpr apply (LinearMap.charpoly_monic _).ne_zero section IsDomain variable [IsDomain R] open Cardinal Module MvPolynomial Module.Free in lemma exists_isNilRegular_of_finrank_le_card (h : finrank R M ≤ #R) : ∃ x : L, IsNilRegular φ x := by let b := chooseBasis R L let bₘ := chooseBasis R M let n := Fintype.card (ChooseBasisIndex R M) have aux : ((polyCharpoly φ b).coeff (nilRank φ)).IsHomogeneous (n - nilRank φ) := polyCharpoly_coeff_isHomogeneous _ b (nilRank φ) (n - nilRank φ) (by simp [n, nilRank_le_card φ bₘ, finrank_eq_card_chooseBasisIndex]) obtain ⟨x, hx⟩ : ∃ r, eval r ((polyCharpoly _ b).coeff (nilRank φ)) ≠ 0 := by by_contra! h₀ apply polyCharpoly_coeff_nilRank_ne_zero φ b apply aux.eq_zero_of_forall_eval_eq_zero_of_le_card h₀ (le_trans _ h) simp only [n, finrank_eq_card_chooseBasisIndex, Nat.cast_le, Nat.sub_le] let c := Finsupp.equivFunOnFinite.symm x use b.repr.symm c rwa [isNilRegular_iff_coeff_polyCharpoly_nilRank_ne_zero _ b, LinearEquiv.apply_symm_apply] lemma exists_isNilRegular [Infinite R] : ∃ x : L, IsNilRegular φ x := by apply exists_isNilRegular_of_finrank_le_card exact (Cardinal.nat_lt_aleph0 _).le.trans <| Cardinal.infinite_iff.mp ‹Infinite R› end IsDomain end LinearMap
.lake/packages/mathlib/Mathlib/Algebra/Module/Torsion/Prod.lean
import Mathlib.Algebra.Module.Prod import Mathlib.Algebra.Module.Torsion.Free /-! # Product of torsion-free modules This file shows that the product of two torsion-free modules is torsion-free. -/ open Module variable {R M N : Type*} namespace Prod instance moduleIsTorsionFree [Semiring R] [AddCommMonoid M] [AddCommMonoid N] [Module R M] [Module R N] [IsTorsionFree R M] [IsTorsionFree R N] : IsTorsionFree R (M × N) where isSMulRegular _r hr := hr.isSMulRegular.prodMap hr.isSMulRegular end Prod
.lake/packages/mathlib/Mathlib/Algebra/Module/Torsion/Pi.lean
import Mathlib.Algebra.Module.Torsion.Free import Mathlib.Algebra.Module.Pi /-! # Product of torsion-free modules This file shows that the product of torsion-free modules is torsion-free. -/ open Module variable {ι R : Type*} {M : ι → Type*} namespace Pi instance instModuleIsTorsionFree [Semiring R] [∀ i, AddCommMonoid (M i)] [∀ i, Module R (M i)] [∀ i, IsTorsionFree R (M i)] : Module.IsTorsionFree R (∀ i, M i) where isSMulRegular _r hr := .piMap fun _i ↦ hr.isSMulRegular end Pi
.lake/packages/mathlib/Mathlib/Algebra/Module/Torsion/Basic.lean
import Mathlib.Algebra.DirectSum.Module import Mathlib.Algebra.Module.ZMod import Mathlib.Algebra.Regular.Opposite import Mathlib.GroupTheory.Torsion import Mathlib.LinearAlgebra.Isomorphisms import Mathlib.RingTheory.Coprime.Ideal import Mathlib.RingTheory.Finiteness.Defs import Mathlib.RingTheory.Ideal.Maps import Mathlib.RingTheory.Ideal.Quotient.Defs import Mathlib.RingTheory.SimpleModule.Basic /-! # Torsion submodules ## Main definitions * `torsionOf R M x` : the torsion ideal of `x`, containing all `a` such that `a • x = 0`. * `Submodule.torsionBy R M a` : the `a`-torsion submodule, containing all elements `x` of `M` such that `a • x = 0`. * `Submodule.torsionBySet R M s` : the submodule containing all elements `x` of `M` such that `a • x = 0` for all `a` in `s`. * `Submodule.torsion' R M S` : the `S`-torsion submodule, containing all elements `x` of `M` such that `a • x = 0` for some `a` in `S`. * `Submodule.torsion R M` : the torsion submodule, containing all elements `x` of `M` such that `a • x = 0` for some non-zero-divisor `a` in `R`. * `Module.IsTorsionBy R M a` : the property that defines an `a`-torsion module. Similarly, `IsTorsionBySet`, `IsTorsion'` and `IsTorsion`. * `Module.IsTorsionBySet.module` : Creates an `R ⧸ I`-module from an `R`-module that `IsTorsionBySet R _ I`. ## Main statements * `quot_torsionOf_equiv_span_singleton` : isomorphism between the span of an element of `M` and the quotient by its torsion ideal. * `torsion' R M S` and `torsion R M` are submodules. * `torsionBySet_eq_torsionBySet_span` : torsion by a set is torsion by the ideal generated by it. * `Submodule.torsionBy_is_torsionBy` : the `a`-torsion submodule is an `a`-torsion module. Similar lemmas for `torsion'` and `torsion`. * `Submodule.torsionBy_isInternal` : a `∏ i, p i`-torsion module is the internal direct sum of its `p i`-torsion submodules when the `p i` are pairwise coprime. A more general version with coprime ideals is `Submodule.torsionBySet_isInternal`. * `Submodule.noZeroSMulDivisors_iff_torsion_bot` : a module over a domain has `NoZeroSMulDivisors` (that is, there is no non-zero `a`, `x` such that `a • x = 0`) iff its torsion submodule is trivial. * `Submodule.QuotientTorsion.torsion_eq_bot` : quotienting by the torsion submodule makes the torsion submodule of the new module trivial. If `R` is a domain, we can derive an instance `Submodule.QuotientTorsion.noZeroSMulDivisors : NoZeroSMulDivisors R (M ⧸ torsion R M)`. ## Notation * The notions are defined for a `CommSemiring R` and a `Module R M`. Some additional hypotheses on `R` and `M` are required by some lemmas. * The letters `a`, `b`, ... are used for scalars (in `R`), while `x`, `y`, ... are used for vectors (in `M`). ## TODO * Move the advanced material to a new file `RingTheory.Torsion`. * Replace `NoZeroSMulDivisors` with `Module.IsTorsionFree` ## Tags Torsion, submodule, module, quotient -/ namespace Ideal section TorsionOf variable (R M : Type*) [Semiring R] [AddCommMonoid M] [Module R M] /-- The torsion ideal of `x`, containing all `a` such that `a • x = 0`. -/ @[simps!] def torsionOf (x : M) : Ideal R := -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11036): broken dot notation on LinearMap.ker https://github.com/leanprover/lean4/issues/1629 LinearMap.ker (LinearMap.toSpanSingleton R M x) @[simp] theorem torsionOf_zero : torsionOf R M (0 : M) = ⊤ := by simp [torsionOf] variable {R M} @[simp] theorem mem_torsionOf_iff (x : M) (a : R) : a ∈ torsionOf R M x ↔ a • x = 0 := Iff.rfl variable (R) @[simp] theorem torsionOf_eq_top_iff (m : M) : torsionOf R M m = ⊤ ↔ m = 0 := by refine ⟨fun h => ?_, fun h => by simp [h]⟩ rw [← one_smul R m, ← mem_torsionOf_iff m (1 : R), h] exact Submodule.mem_top @[simp] theorem torsionOf_eq_bot_iff_of_noZeroSMulDivisors [Nontrivial R] [NoZeroSMulDivisors R M] (m : M) : torsionOf R M m = ⊥ ↔ m ≠ 0 := by refine ⟨fun h contra => ?_, fun h => (Submodule.eq_bot_iff _).mpr fun r hr => ?_⟩ · rw [contra, torsionOf_zero] at h exact bot_ne_top.symm h · rw [mem_torsionOf_iff, smul_eq_zero] at hr tauto /-- See also `iSupIndep.linearIndependent` which provides the same conclusion but requires the stronger hypothesis `NoZeroSMulDivisors R M`. -/ theorem iSupIndep.linearIndependent' {ι R M : Type*} {v : ι → M} [Ring R] [AddCommGroup M] [Module R M] (hv : iSupIndep fun i => R ∙ v i) (h_ne_zero : ∀ i, Ideal.torsionOf R M (v i) = ⊥) : LinearIndependent R v := by refine linearIndependent_iff_eq_zero_of_smul_mem_span.mpr fun i r hi => ?_ replace hv := iSupIndep_def.mp hv i simp only [iSup_subtype', ← Submodule.span_range_eq_iSup (ι := Subtype _), disjoint_iff] at hv have : r • v i ∈ (⊥ : Submodule R M) := by rw [← hv, Submodule.mem_inf] refine ⟨Submodule.mem_span_singleton.mpr ⟨r, rfl⟩, ?_⟩ convert hi ext simp rw [← Submodule.mem_bot R, ← h_ne_zero i] simpa using this end TorsionOf section variable (R M : Type*) [Ring R] [AddCommGroup M] [Module R M] /-- The span of `x` in `M` is isomorphic to `R` quotiented by the torsion ideal of `x`. -/ noncomputable def quotTorsionOfEquivSpanSingleton (x : M) : (R ⧸ torsionOf R M x) ≃ₗ[R] R ∙ x := (LinearMap.toSpanSingleton R M x).quotKerEquivRange.trans <| LinearEquiv.ofEq _ _ (LinearMap.span_singleton_eq_range R M x).symm variable {R M} @[simp] theorem quotTorsionOfEquivSpanSingleton_apply_mk (x : M) (a : R) : quotTorsionOfEquivSpanSingleton R M x (Submodule.Quotient.mk a) = a • ⟨x, Submodule.mem_span_singleton_self x⟩ := rfl end end Ideal open nonZeroDivisors section Defs namespace Submodule variable (R M : Type*) [CommSemiring R] [AddCommMonoid M] [Module R M] -- TODO: generalize to `Submodule S M` with `SMulCommClass R S M`. /-- The `a`-torsion submodule for `a` in `R`, containing all elements `x` of `M` such that `a • x = 0`. -/ @[simps!] def torsionBy (a : R) : Submodule R M := -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11036): broken dot notation on LinearMap.ker https://github.com/leanprover/lean4/issues/1629 LinearMap.ker (DistribMulAction.toLinearMap R M a) /-- The submodule containing all elements `x` of `M` such that `a • x = 0` for all `a` in `s`. -/ @[simps!] def torsionBySet (s : Set R) : Submodule R M := sInf (torsionBy R M '' s) /-- The `S`-torsion submodule, containing all elements `x` of `M` such that `a • x = 0` for some `a` in `S`. -/ @[simps!] def torsion' (S : Type*) [CommMonoid S] [DistribMulAction S M] [SMulCommClass S R M] : Submodule R M where carrier := { x | ∃ a : S, a • x = 0 } add_mem' := by intro x y ⟨a,hx⟩ ⟨b,hy⟩ use b * a rw [smul_add, mul_smul, mul_comm, mul_smul, hx, hy, smul_zero, smul_zero, add_zero] zero_mem' := ⟨1, smul_zero 1⟩ smul_mem' := fun a x ⟨b, h⟩ => ⟨b, by rw [smul_comm, h, smul_zero]⟩ /-- The torsion submodule, containing all elements `x` of `M` such that `a • x = 0` for some non-zero-divisor `a` in `R`. -/ abbrev torsion := torsion' R M R⁰ end Submodule namespace Module variable (R M : Type*) [Semiring R] [AddCommMonoid M] [Module R M] /-- An `a`-torsion module is a module where every element is `a`-torsion. -/ abbrev IsTorsionBy (a : R) := ∀ ⦃x : M⦄, a • x = 0 /-- A module where every element is `a`-torsion for all `a` in `s`. -/ abbrev IsTorsionBySet (s : Set R) := ∀ ⦃x : M⦄ ⦃a : s⦄, (a : R) • x = 0 /-- An `S`-torsion module is a module where every element is `a`-torsion for some `a` in `S`. -/ abbrev IsTorsion' (S : Type*) [SMul S M] := ∀ ⦃x : M⦄, ∃ a : S, a • x = 0 /-- A torsion module is a module where every element is `a`-torsion for some non-zero-divisor `a`. -/ abbrev IsTorsion := ∀ ⦃x : M⦄, ∃ a : R⁰, a • x = 0 theorem isTorsionBySet_annihilator : IsTorsionBySet R M (annihilator R M) := fun _ r ↦ Module.mem_annihilator.mp r.2 _ theorem isTorsionBy_iff_mem_annihilator {a : R} : IsTorsionBy R M a ↔ a ∈ annihilator R M := by rw [IsTorsionBy, mem_annihilator] theorem isTorsionBySet_iff_subset_annihilator {s : Set R} : IsTorsionBySet R M s ↔ s ⊆ annihilator R M := by simp_rw [IsTorsionBySet, Set.subset_def, SetLike.mem_coe, mem_annihilator] rw [forall_comm, SetCoe.forall] end Module end Defs lemma isSMulRegular_iff_torsionBy_eq_bot {R} (M : Type*) [CommRing R] [AddCommGroup M] [Module R M] (r : R) : IsSMulRegular M r ↔ Submodule.torsionBy R M r = ⊥ := Iff.symm (DistribMulAction.toLinearMap R M r).ker_eq_bot variable {R M : Type*} section namespace Submodule variable [CommSemiring R] [AddCommMonoid M] [Module R M] (s : Set R) (a : R) @[simp] theorem smul_torsionBy (x : torsionBy R M a) : a • x = 0 := Subtype.ext x.prop @[simp] theorem smul_coe_torsionBy (x : torsionBy R M a) : a • (x : M) = 0 := x.prop @[simp] theorem mem_torsionBy_iff (x : M) : x ∈ torsionBy R M a ↔ a • x = 0 := Iff.rfl @[simp] theorem mem_torsionBySet_iff (x : M) : x ∈ torsionBySet R M s ↔ ∀ a : s, (a : R) • x = 0 := by refine ⟨fun h ⟨a, ha⟩ => mem_sInf.mp h _ (Set.mem_image_of_mem _ ha), fun h => mem_sInf.mpr ?_⟩ rintro _ ⟨a, ha, rfl⟩; exact h ⟨a, ha⟩ @[simp] theorem torsionBySet_singleton_eq : torsionBySet R M {a} = torsionBy R M a := by ext x simp only [mem_torsionBySet_iff, SetCoe.forall, Set.mem_singleton_iff, forall_eq, mem_torsionBy_iff] theorem torsionBySet_le_torsionBySet_of_subset {s t : Set R} (st : s ⊆ t) : torsionBySet R M t ≤ torsionBySet R M s := sInf_le_sInf fun _ ⟨a, ha, h⟩ => ⟨a, st ha, h⟩ /-- Torsion by a set is torsion by the ideal generated by it. -/ theorem torsionBySet_eq_torsionBySet_span : torsionBySet R M s = torsionBySet R M (Ideal.span s) := by refine le_antisymm (fun x hx => ?_) (torsionBySet_le_torsionBySet_of_subset subset_span) rw [mem_torsionBySet_iff] at hx ⊢ suffices Ideal.span s ≤ Ideal.torsionOf R M x by rintro ⟨a, ha⟩ exact this ha rw [Ideal.span_le] exact fun a ha => hx ⟨a, ha⟩ theorem torsionBySet_span_singleton_eq : torsionBySet R M (R ∙ a) = torsionBy R M a := (torsionBySet_eq_torsionBySet_span _).symm.trans <| torsionBySet_singleton_eq _ theorem torsionBy_le_torsionBy_of_dvd (a b : R) (dvd : a ∣ b) : torsionBy R M a ≤ torsionBy R M b := by rw [← torsionBySet_span_singleton_eq, ← torsionBySet_singleton_eq] apply torsionBySet_le_torsionBySet_of_subset rintro c (rfl : c = b); exact Ideal.mem_span_singleton.mpr dvd @[simp] theorem torsionBy_one : torsionBy R M 1 = ⊥ := eq_bot_iff.mpr fun _ h => by rw [mem_torsionBy_iff, one_smul] at h exact h @[simp] theorem torsionBySet_univ : torsionBySet R M Set.univ = ⊥ := by rw [eq_bot_iff, ← torsionBy_one, ← torsionBySet_singleton_eq] exact torsionBySet_le_torsionBySet_of_subset fun _ _ => trivial end Submodule open Submodule namespace Module variable [Semiring R] [AddCommMonoid M] [Module R M] (s : Set R) (a : R) theorem isTorsionBySet_of_subset {s t : Set R} (h : s ⊆ t) (ht : IsTorsionBySet R M t) : IsTorsionBySet R M s := fun m r ↦ @ht m ⟨r, h r.2⟩ @[simp] theorem isTorsionBySet_singleton_iff : IsTorsionBySet R M {a} ↔ IsTorsionBy R M a := by refine ⟨fun h x => @h _ ⟨_, Set.mem_singleton _⟩, fun h x => ?_⟩ rintro ⟨b, rfl : b = a⟩; exact @h _ theorem isTorsionBySet_iff_is_torsion_by_span : IsTorsionBySet R M s ↔ IsTorsionBySet R M (Ideal.span s) := by simpa only [isTorsionBySet_iff_subset_annihilator] using Ideal.span_le.symm theorem isTorsionBySet_span_singleton_iff : IsTorsionBySet R M (R ∙ a) ↔ IsTorsionBy R M a := (isTorsionBySet_iff_is_torsion_by_span _).symm.trans <| isTorsionBySet_singleton_iff _ end Module namespace Module variable [CommSemiring R] [AddCommMonoid M] [Module R M] (s : Set R) (a : R) theorem isTorsionBySet_iff_torsionBySet_eq_top : IsTorsionBySet R M s ↔ torsionBySet R M s = ⊤ := ⟨fun h => eq_top_iff.mpr fun _ _ => (mem_torsionBySet_iff _ _).mpr <| @h _, fun h x => by rw [← mem_torsionBySet_iff, h] trivial⟩ /-- An `a`-torsion module is a module whose `a`-torsion submodule is the full space. -/ theorem isTorsionBy_iff_torsionBy_eq_top : IsTorsionBy R M a ↔ torsionBy R M a = ⊤ := by rw [← torsionBySet_singleton_eq, ← isTorsionBySet_singleton_iff, isTorsionBySet_iff_torsionBySet_eq_top] theorem isTorsionBySet_iff_subseteq_ker_lsmul : IsTorsionBySet R M s ↔ s ⊆ LinearMap.ker (LinearMap.lsmul R M) where mp h r hr := LinearMap.mem_ker.mpr <| LinearMap.ext fun x => @h x ⟨r, hr⟩ mpr | h, x, ⟨_, hr⟩ => DFunLike.congr_fun (LinearMap.mem_ker.mp (h hr)) x theorem isTorsionBy_iff_mem_ker_lsmul : IsTorsionBy R M a ↔ a ∈ LinearMap.ker (LinearMap.lsmul R M) := Iff.symm LinearMap.ext_iff end Module namespace Submodule open Module variable [CommSemiring R] [AddCommMonoid M] [Module R M] (s : Set R) (a : R) theorem torsionBySet_isTorsionBySet : IsTorsionBySet R (torsionBySet R M s) s := fun ⟨_, hx⟩ a => Subtype.ext <| (mem_torsionBySet_iff _ _).mp hx a /-- The `a`-torsion submodule is an `a`-torsion module. -/ theorem torsionBy_isTorsionBy : IsTorsionBy R (torsionBy R M a) a := smul_torsionBy a @[simp] theorem torsionBy_torsionBy_eq_top : torsionBy R (torsionBy R M a) a = ⊤ := (isTorsionBy_iff_torsionBy_eq_top a).mp <| torsionBy_isTorsionBy a @[simp] theorem torsionBySet_torsionBySet_eq_top : torsionBySet R (torsionBySet R M s) s = ⊤ := (isTorsionBySet_iff_torsionBySet_eq_top s).mp <| torsionBySet_isTorsionBySet s variable (R M) theorem torsion_gc : @GaloisConnection (Submodule R M) (Ideal R)ᵒᵈ _ _ annihilator fun I => torsionBySet R M ↑(OrderDual.ofDual I) := fun _ _ => ⟨fun h x hx => (mem_torsionBySet_iff _ _).mpr fun ⟨_, ha⟩ => mem_annihilator.mp (h ha) x hx, fun h a ha => mem_annihilator.mpr fun _ hx => (mem_torsionBySet_iff _ _).mp (h hx) ⟨a, ha⟩⟩ variable {R M} section Coprime variable {ι : Type*} {p : ι → Ideal R} {S : Finset ι} theorem iSup_torsionBySet_ideal_eq_torsionBySet_iInf (hp : (S : Set ι).Pairwise fun i j => p i ⊔ p j = ⊤) : ⨆ i ∈ S, torsionBySet R M (p i) = torsionBySet R M ↑(⨅ i ∈ S, p i) := by rcases S.eq_empty_or_nonempty with h | h · simp [h] apply le_antisymm · apply iSup_le _ intro i apply iSup_le _ intro is apply torsionBySet_le_torsionBySet_of_subset exact (iInf_le (fun i => ⨅ _ : i ∈ S, p i) i).trans (iInf_le _ is) · intro x hx rw [mem_iSup_finset_iff_exists_sum] obtain ⟨μ, hμ⟩ := (mem_iSup_finset_iff_exists_sum _ _).mp ((Ideal.eq_top_iff_one _).mp <| (Ideal.iSup_iInf_eq_top_iff_pairwise h _).mpr hp) refine ⟨fun i => ⟨(μ i : R) • x, ?_⟩, ?_⟩ · rw [mem_torsionBySet_iff] at hx ⊢ rintro ⟨a, ha⟩ rw [smul_smul] suffices a * μ i ∈ ⨅ i ∈ S, p i from hx ⟨_, this⟩ rw [mem_iInf] intro j rw [mem_iInf] intro hj by_cases ij : j = i · rw [ij] exact Ideal.mul_mem_right _ _ ha · have := coe_mem (μ i) simp only [mem_iInf] at this exact Ideal.mul_mem_left _ _ (this j hj ij) · rw [← Finset.sum_smul, hμ, one_smul] theorem supIndep_torsionBySet_ideal (hp : (S : Set ι).Pairwise fun i j => p i ⊔ p j = ⊤) : S.SupIndep fun i => torsionBySet R M <| p i := fun T hT i hi hiT => by rw [disjoint_iff, Finset.sup_eq_iSup, iSup_torsionBySet_ideal_eq_torsionBySet_iInf fun i hi j hj ij => hp (hT hi) (hT hj) ij] have := GaloisConnection.u_inf (b₁ := OrderDual.toDual (p i)) (b₂ := OrderDual.toDual (⨅ i ∈ T, p i)) (torsion_gc R M) dsimp at this ⊢ rw [← this, Ideal.sup_iInf_eq_top, top_coe, torsionBySet_univ] intro j hj; apply hp hi (hT hj); rintro rfl; exact hiT hj variable {q : ι → R} open scoped Function -- required for scoped `on` notation theorem iSup_torsionBy_eq_torsionBy_prod (hq : (S : Set ι).Pairwise <| (IsCoprime on q)) : ⨆ i ∈ S, torsionBy R M (q i) = torsionBy R M (∏ i ∈ S, q i) := by rw [← torsionBySet_span_singleton_eq, Ideal.submodule_span_eq, ← Ideal.finset_inf_span_singleton _ _ hq, Finset.inf_eq_iInf, ← iSup_torsionBySet_ideal_eq_torsionBySet_iInf] · congr ext : 1 congr ext : 1 exact (torsionBySet_span_singleton_eq _).symm exact fun i hi j hj ij => (Ideal.sup_eq_top_iff_isCoprime _ _).mpr (hq hi hj ij) theorem supIndep_torsionBy (hq : (S : Set ι).Pairwise <| (IsCoprime on q)) : S.SupIndep fun i => torsionBy R M <| q i := by convert supIndep_torsionBySet_ideal (M := M) fun i hi j hj ij => (Ideal.sup_eq_top_iff_isCoprime (q i) _).mpr <| hq hi hj ij exact (torsionBySet_span_singleton_eq (R := R) (M := M) _).symm end Coprime end Submodule end section NeedsGroup namespace Submodule variable [CommRing R] [AddCommGroup M] [Module R M] variable {ι : Type*} [DecidableEq ι] {S : Finset ι} /-- If the `p i` are pairwise coprime, a `⨅ i, p i`-torsion module is the internal direct sum of its `p i`-torsion submodules. -/ theorem torsionBySet_isInternal {p : ι → Ideal R} (hp : (S : Set ι).Pairwise fun i j => p i ⊔ p j = ⊤) (hM : Module.IsTorsionBySet R M (⨅ i ∈ S, p i : Ideal R)) : DirectSum.IsInternal fun i : S => torsionBySet R M <| p i := DirectSum.isInternal_submodule_of_iSupIndep_of_iSup_eq_top (iSupIndep_iff_supIndep.mpr <| supIndep_torsionBySet_ideal hp) (by apply (iSup_subtype'' ↑S fun i => torsionBySet R M <| p i).trans -- Porting note: times out if we change apply below to <| apply (iSup_torsionBySet_ideal_eq_torsionBySet_iInf hp).trans <| (Module.isTorsionBySet_iff_torsionBySet_eq_top _).mp hM) open scoped Function in -- required for scoped `on` notation /-- If the `q i` are pairwise coprime, a `∏ i, q i`-torsion module is the internal direct sum of its `q i`-torsion submodules. -/ theorem torsionBy_isInternal {q : ι → R} (hq : (S : Set ι).Pairwise <| (IsCoprime on q)) (hM : Module.IsTorsionBy R M <| ∏ i ∈ S, q i) : DirectSum.IsInternal fun i : S => torsionBy R M <| q i := by rw [← Module.isTorsionBySet_span_singleton_iff, Ideal.submodule_span_eq, ← Ideal.finset_inf_span_singleton _ _ hq, Finset.inf_eq_iInf] at hM convert torsionBySet_isInternal (fun i hi j hj ij => (Ideal.sup_eq_top_iff_isCoprime (q i) _).mpr <| hq hi hj ij) hM exact (torsionBySet_span_singleton_eq _ (R := R) (M := M)).symm end Submodule namespace Module variable [Ring R] [AddCommGroup M] [Module R M] variable {I : Ideal R} {r : R} /-- can't be an instance because `hM` can't be inferred -/ def IsTorsionBySet.hasSMul (hM : IsTorsionBySet R M I) : SMul (R ⧸ I) M where smul b := QuotientAddGroup.lift I.toAddSubgroup (smulAddHom R M) (by rwa [isTorsionBySet_iff_subset_annihilator] at hM) b /-- can't be an instance because `hM` can't be inferred -/ abbrev IsTorsionBy.hasSMul (hM : IsTorsionBy R M r) : SMul (R ⧸ Ideal.span {r}) M := ((isTorsionBySet_span_singleton_iff r).mpr hM).hasSMul @[simp] theorem IsTorsionBySet.mk_smul [I.IsTwoSided] (hM : IsTorsionBySet R M I) (b : R) (x : M) : haveI := hM.hasSMul Ideal.Quotient.mk I b • x = b • x := rfl @[simp] theorem IsTorsionBy.mk_smul [(Ideal.span {r}).IsTwoSided] (hM : IsTorsionBy R M r) (b : R) (x : M) : haveI := hM.hasSMul Ideal.Quotient.mk (Ideal.span {r}) b • x = b • x := rfl /-- An `(R ⧸ I)`-module is an `R`-module which `IsTorsionBySet R M I`. -/ def IsTorsionBySet.module [I.IsTwoSided] (hM : IsTorsionBySet R M I) : Module (R ⧸ I) M := letI := hM.hasSMul; I.mkQ_surjective.moduleLeft _ (IsTorsionBySet.mk_smul hM) instance IsTorsionBySet.isScalarTower [I.IsTwoSided] (hM : IsTorsionBySet R M I) {S : Type*} [SMul S R] [SMul S M] [IsScalarTower S R M] [IsScalarTower S R R] : @IsScalarTower S (R ⧸ I) M _ (IsTorsionBySet.module hM).toSMul _ := -- Porting note: still needed to be fed the Module R / I M instance @IsScalarTower.mk S (R ⧸ I) M _ (IsTorsionBySet.module hM).toSMul _ (fun b d x => Quotient.inductionOn' d fun c => (smul_assoc b c x :)) /-- If a `R`-module `M` is annihilated by a two-sided ideal `I`, then the identity is a semilinear map from the `R`-module `M` to the `R ⧸ I`-module `M`. -/ def IsTorsionBySet.semilinearMap [I.IsTwoSided] (hM : IsTorsionBySet R M I) : let _ := hM.module; M →ₛₗ[Ideal.Quotient.mk I] M := let _ := hM.module { toFun := id map_add' := fun _ _ ↦ rfl map_smul' := fun _ _ ↦ rfl } theorem IsTorsionBySet.isSemisimpleModule_iff [I.IsTwoSided] (hM : Module.IsTorsionBySet R M I) : let _ := hM.module IsSemisimpleModule (R ⧸ I) M ↔ IsSemisimpleModule R M := let _ := hM.module (hM.semilinearMap.isSemisimpleModule_iff_of_bijective Function.bijective_id).symm /-- An `(R ⧸ Ideal.span {r})`-module is an `R`-module for which `IsTorsionBy R M r`. -/ abbrev IsTorsionBy.module [h : (Ideal.span {r}).IsTwoSided] (hM : IsTorsionBy R M r) : Module (R ⧸ Ideal.span {r}) M := by rw [Ideal.span] at h; exact ((isTorsionBySet_span_singleton_iff r).mpr hM).module /-- Any module is also a module over the quotient of the ring by the annihilator. Not an instance because it causes synthesis failures / timeouts. -/ def quotientAnnihilator : Module (R ⧸ Module.annihilator R M) M := (isTorsionBySet_annihilator R M).module theorem isTorsionBy_quotient_iff (N : Submodule R M) (r : R) : IsTorsionBy R (M⧸N) r ↔ ∀ x, r • x ∈ N := Iff.trans N.mkQ_surjective.forall <| forall_congr' fun _ => Submodule.Quotient.mk_eq_zero N theorem IsTorsionBy.quotient (N : Submodule R M) {r : R} (h : IsTorsionBy R M r) : IsTorsionBy R (M⧸N) r := (isTorsionBy_quotient_iff N r).mpr fun x => @h x ▸ N.zero_mem theorem isTorsionBySet_quotient_iff (N : Submodule R M) (s : Set R) : IsTorsionBySet R (M⧸N) s ↔ ∀ x, ∀ r ∈ s, r • x ∈ N := Iff.trans N.mkQ_surjective.forall <| forall_congr' fun _ => Iff.trans Subtype.forall <| forall₂_congr fun _ _ => Submodule.Quotient.mk_eq_zero N theorem IsTorsionBySet.quotient (N : Submodule R M) {s} (h : IsTorsionBySet R M s) : IsTorsionBySet R (M⧸N) s := (isTorsionBySet_quotient_iff N s).mpr fun x r h' => @h x ⟨r, h'⟩ ▸ N.zero_mem variable (M I) (s : Set R) (r : R) open Pointwise Submodule lemma isTorsionBySet_quotient_set_smul : IsTorsionBySet R (M⧸s • (⊤ : Submodule R M)) s := (isTorsionBySet_quotient_iff _ _).mpr fun _ _ h => mem_set_smul_of_mem_mem h mem_top lemma isTorsionBySet_quotient_ideal_smul : IsTorsionBySet R (M⧸I • (⊤ : Submodule R M)) I := (isTorsionBySet_quotient_iff _ _).mpr fun _ _ h => smul_mem_smul h ⟨⟩ instance [I.IsTwoSided] : Module (R ⧸ I) (M ⧸ I • (⊤ : Submodule R M)) := (isTorsionBySet_quotient_ideal_smul M I).module lemma Quotient.mk_smul_mk [I.IsTwoSided] (r : R) (m : M) : Ideal.Quotient.mk I r • Submodule.Quotient.mk (p := (I • ⊤ : Submodule R M)) m = Submodule.Quotient.mk (p := (I • ⊤ : Submodule R M)) (r • m) := rfl end Module namespace Module variable (M) [CommRing R] [AddCommGroup M] [Module R M] (s : Set R) (r : R) open Pointwise lemma isTorsionBy_quotient_element_smul : IsTorsionBy R (M⧸r • (⊤ : Submodule R M)) r := (isTorsionBy_quotient_iff _ _).mpr (Submodule.smul_mem_pointwise_smul · r ⊤ ⟨⟩) instance : Module (R ⧸ Ideal.span s) (M ⧸ s • (⊤ : Submodule R M)) := ((isTorsionBySet_iff_is_torsion_by_span s).mp (isTorsionBySet_quotient_set_smul M s)).module instance : Module (R ⧸ Ideal.span {r}) (M ⧸ r • (⊤ : Submodule R M)) := (isTorsionBy_quotient_element_smul M r).module end Module namespace Submodule variable [CommRing R] [AddCommGroup M] [Module R M] instance (I : Ideal R) : Module (R ⧸ I) (torsionBySet R M I) := -- Porting note: times out without the (R := R) Module.IsTorsionBySet.module <| torsionBySet_isTorsionBySet (R := R) I @[simp] theorem torsionBySet.mk_smul (I : Ideal R) (b : R) (x : torsionBySet R M I) : Ideal.Quotient.mk I b • x = b • x := rfl instance (I : Ideal R) {S : Type*} [SMul S R] [SMul S M] [IsScalarTower S R M] [IsScalarTower S R R] : IsScalarTower S (R ⧸ I) (torsionBySet R M I) := inferInstance /-- The `a`-torsion submodule as an `(R ⧸ R∙a)`-module. -/ instance instModuleQuotientTorsionBy (a : R) : Module (R ⧸ R ∙ a) (torsionBy R M a) := Module.IsTorsionBySet.module <| (Module.isTorsionBySet_span_singleton_iff a).mpr <| torsionBy_isTorsionBy a instance (a : R) : Module (R ⧸ Ideal.span {a}) (torsionBy R M a) := inferInstanceAs <| Module (R ⧸ R ∙ a) (torsionBy R M a) @[simp] theorem torsionBy.mk_ideal_smul (a b : R) (x : torsionBy R M a) : (Ideal.Quotient.mk (Ideal.span {a})) b • x = b • x := rfl theorem torsionBy.mk_smul (a b : R) (x : torsionBy R M a) : Ideal.Quotient.mk (R ∙ a) b • x = b • x := rfl instance (a : R) {S : Type*} [SMul S R] [SMul S M] [IsScalarTower S R M] [IsScalarTower S R R] : IsScalarTower S (R ⧸ R ∙ a) (torsionBy R M a) := inferInstance /-- Given an `R`-module `M` and an element `a` in `R`, submodules of the `a`-torsion submodule of `M` do not depend on whether we take scalars to be `R` or `R ⧸ R ∙ a`. -/ def submodule_torsionBy_orderIso (a : R) : Submodule (R ⧸ R ∙ a) (torsionBy R M a) ≃o Submodule R (torsionBy R M a) := { restrictScalarsEmbedding R (R ⧸ R ∙ a) (torsionBy R M a) with invFun := fun p ↦ { carrier := p add_mem' := add_mem zero_mem' := p.zero_mem smul_mem' := by rintro ⟨b⟩; exact p.smul_mem b } left_inv := by intro; ext; simp [restrictScalarsEmbedding] right_inv := by intro; ext; simp [restrictScalarsEmbedding] } end Submodule end NeedsGroup namespace Submodule section Torsion' open Module variable [CommSemiring R] [AddCommMonoid M] [Module R M] variable (S : Type*) [CommMonoid S] [DistribMulAction S M] [SMulCommClass S R M] @[simp] theorem mem_torsion'_iff (x : M) : x ∈ torsion' R M S ↔ ∃ a : S, a • x = 0 := Iff.rfl theorem mem_torsion_iff (x : M) : x ∈ torsion R M ↔ ∃ a : R⁰, a • x = 0 := Iff.rfl @[simps] instance : SMul S (torsion' R M S) := ⟨fun s x => ⟨s • (x : M), by obtain ⟨x, a, h⟩ := x use a dsimp rw [smul_comm, h, smul_zero]⟩⟩ instance : DistribMulAction S (torsion' R M S) := Subtype.coe_injective.distribMulAction (torsion' R M S).subtype.toAddMonoidHom fun (_ : S) _ => rfl instance : SMulCommClass S R (torsion' R M S) := ⟨fun _ _ _ => Subtype.ext <| smul_comm _ _ _⟩ /-- An `S`-torsion module is a module whose `S`-torsion submodule is the full space. -/ theorem isTorsion'_iff_torsion'_eq_top : IsTorsion' M S ↔ torsion' R M S = ⊤ := ⟨fun h => eq_top_iff.mpr fun _ _ => @h _, fun h x => by rw [← @mem_torsion'_iff R, h] trivial⟩ /-- The `S`-torsion submodule is an `S`-torsion module. -/ theorem torsion'_isTorsion' : IsTorsion' (torsion' R M S) S := fun ⟨_, ⟨a, h⟩⟩ => ⟨a, Subtype.ext h⟩ @[simp] theorem torsion'_torsion'_eq_top : torsion' R (torsion' R M S) S = ⊤ := (isTorsion'_iff_torsion'_eq_top S).mp <| torsion'_isTorsion' S /-- The torsion submodule of the torsion submodule (viewed as a module) is the full torsion module. -/ theorem torsion_torsion_eq_top : torsion R (torsion R M) = ⊤ := torsion'_torsion'_eq_top R⁰ /-- The torsion submodule is always a torsion module. -/ theorem torsion_isTorsion : Module.IsTorsion R (torsion R M) := torsion'_isTorsion' R⁰ end Torsion' section Torsion variable [CommSemiring R] [AddCommMonoid M] [Module R M] variable (R M) theorem _root_.Module.isTorsionBySet_annihilator_top : Module.IsTorsionBySet R M (⊤ : Submodule R M).annihilator := fun x ha => mem_annihilator.mp ha.prop x mem_top variable {R M} theorem _root_.Submodule.annihilator_top_inter_nonZeroDivisors [Module.Finite R M] (hM : Module.IsTorsion R M) : ((⊤ : Submodule R M).annihilator : Set R) ∩ R⁰ ≠ ∅ := by obtain ⟨S, hS⟩ := ‹Module.Finite R M›.fg_top refine Set.Nonempty.ne_empty ⟨_, ?_, (∏ x ∈ S, (@hM x).choose : R⁰).prop⟩ rw [Submonoid.coe_finset_prod, SetLike.mem_coe, ← hS, mem_annihilator_span] intro n letI := Classical.decEq M rw [← Finset.prod_erase_mul _ _ n.prop, mul_smul, ← Submonoid.smul_def, (@hM n).choose_spec, smul_zero] variable [NoZeroDivisors R] [Nontrivial R] theorem coe_torsion_eq_annihilator_ne_bot : (torsion R M : Set M) = { x : M | (R ∙ x).annihilator ≠ ⊥ } := by ext x; simp_rw [Submodule.ne_bot_iff, mem_annihilator, mem_span_singleton] exact ⟨fun ⟨a, hax⟩ => ⟨a, fun _ ⟨b, hb⟩ => by rw [← hb, smul_comm, ← Submonoid.smul_def, hax, smul_zero], nonZeroDivisors.coe_ne_zero _⟩, fun ⟨a, hax, ha⟩ => ⟨⟨_, mem_nonZeroDivisors_of_ne_zero ha⟩, hax x ⟨1, one_smul _ _⟩⟩⟩ /-- A module over a domain has `NoZeroSMulDivisors` iff its torsion submodule is trivial. -/ theorem noZeroSMulDivisors_iff_torsion_eq_bot : NoZeroSMulDivisors R M ↔ torsion R M = ⊥ := by constructor <;> intro h · haveI : NoZeroSMulDivisors R M := h rw [eq_bot_iff] rintro x ⟨a, hax⟩ change (a : R) • x = 0 at hax rcases eq_zero_or_eq_zero_of_smul_eq_zero hax with h0 | h0 · exfalso exact nonZeroDivisors.coe_ne_zero a h0 · exact h0 · exact { eq_zero_or_eq_zero_of_smul_eq_zero := fun {a} {x} hax => by by_cases ha : a = 0 · left exact ha · right rw [← mem_bot R, ← h] exact ⟨⟨a, mem_nonZeroDivisors_of_ne_zero ha⟩, hax⟩ } lemma torsion_int {G} [AddCommGroup G] : (torsion ℤ G).toAddSubgroup = AddCommGroup.torsion G := by ext x refine ((isOfFinAddOrder_iff_zsmul_eq_zero (x := x)).trans ?_).symm simp [mem_nonZeroDivisors_iff_ne_zero] end Torsion namespace QuotientTorsion variable [CommRing R] [AddCommGroup M] [Module R M] /-- Quotienting by the torsion submodule gives a torsion-free module. -/ @[simp] theorem torsion_eq_bot : torsion R (M ⧸ torsion R M) = ⊥ := eq_bot_iff.mpr fun z => Quotient.inductionOn' z fun x ⟨a, hax⟩ => by rw [Quotient.mk''_eq_mk, ← Quotient.mk_smul, Quotient.mk_eq_zero] at hax rw [mem_bot, Quotient.mk''_eq_mk, Quotient.mk_eq_zero] obtain ⟨b, h⟩ := hax exact ⟨b * a, (mul_smul _ _ _).trans h⟩ instance noZeroSMulDivisors [IsDomain R] : NoZeroSMulDivisors R (M ⧸ torsion R M) := noZeroSMulDivisors_iff_torsion_eq_bot.mpr torsion_eq_bot end QuotientTorsion section PTorsion open Module section variable [Monoid R] [AddCommMonoid M] [DistribMulAction R M] theorem isTorsion'_powers_iff (p : R) : IsTorsion' M (Submonoid.powers p) ↔ ∀ x : M, ∃ n : ℕ, p ^ n • x = 0 := by constructor · intro h x let ⟨⟨a, ⟨n, hn⟩⟩, hx⟩ := @h x dsimp at hn use n rw [hn] apply hx · intro h x let ⟨n, hn⟩ := h x exact ⟨⟨_, ⟨n, rfl⟩⟩, hn⟩ /-- In a `p ^ ∞`-torsion module (that is, a module where all elements are cancelled by scalar multiplication by some power of `p`), the smallest `n` such that `p ^ n • x = 0`. -/ def pOrder {p : R} (hM : IsTorsion' M <| Submonoid.powers p) (x : M) [∀ n : ℕ, Decidable (p ^ n • x = 0)] := Nat.find <| (isTorsion'_powers_iff p).mp hM x @[simp] theorem pow_pOrder_smul {p : R} (hM : IsTorsion' M <| Submonoid.powers p) (x : M) [∀ n : ℕ, Decidable (p ^ n • x = 0)] : p ^ pOrder hM x • x = 0 := Nat.find_spec <| (isTorsion'_powers_iff p).mp hM x end variable [CommSemiring R] [AddCommMonoid M] [Module R M] [∀ x : M, Decidable (x = 0)] theorem exists_isTorsionBy {p : R} (hM : IsTorsion' M <| Submonoid.powers p) (d : ℕ) (hd : d ≠ 0) (s : Fin d → M) (hs : span R (Set.range s) = ⊤) : ∃ j : Fin d, Module.IsTorsionBy R M (p ^ pOrder hM (s j)) := by let oj := List.argmax (fun i => pOrder hM <| s i) (List.finRange d) have hoj : oj.isSome := Option.ne_none_iff_isSome.mp fun eq_none => hd <| List.finRange_eq_nil.mp <| List.argmax_eq_none.mp eq_none use Option.get _ hoj rw [isTorsionBy_iff_torsionBy_eq_top, eq_top_iff, ← hs, Submodule.span_le, Set.range_subset_iff] intro i; change (p ^ pOrder hM (s (Option.get oj hoj))) • s i = 0 have : pOrder hM (s i) ≤ pOrder hM (s <| Option.get _ hoj) := List.le_of_mem_argmax (List.mem_finRange i) (Option.get_mem hoj) rw [← Nat.sub_add_cancel this, pow_add, mul_smul, pow_pOrder_smul, smul_zero] end PTorsion end Submodule namespace Ideal.Quotient open Submodule universe w theorem torsionBy_eq_span_singleton {R : Type w} [CommRing R] (a b : R) (ha : a ∈ R⁰) : torsionBy R (R ⧸ R ∙ a * b) a = R ∙ mk (R ∙ a * b) b := by ext x; rw [mem_torsionBy_iff, Submodule.mem_span_singleton] obtain ⟨x, rfl⟩ := mk_surjective x; constructor <;> intro h · rw [← mk_eq_mk, ← Quotient.mk_smul, Quotient.mk_eq_zero, Submodule.mem_span_singleton] at h obtain ⟨c, h⟩ := h rw [smul_eq_mul, smul_eq_mul, mul_comm, mul_assoc, mul_cancel_left_mem_nonZeroDivisors ha, mul_comm] at h use c rw [← h, ← mk_eq_mk, ← Quotient.mk_smul, smul_eq_mul, mk_eq_mk] · obtain ⟨c, h⟩ := h rw [← h, smul_comm, ← mk_eq_mk, ← Quotient.mk_smul, (Quotient.mk_eq_zero _).mpr <| mem_span_singleton_self _, smul_zero] end Ideal.Quotient namespace AddMonoid theorem isTorsion_iff_isTorsion_nat [AddCommMonoid M] : AddMonoid.IsTorsion M ↔ Module.IsTorsion ℕ M := by refine ⟨fun h x => ?_, fun h x => ?_⟩ · obtain ⟨n, h0, hn⟩ := (h x).exists_nsmul_eq_zero exact ⟨⟨n, mem_nonZeroDivisors_of_ne_zero <| ne_of_gt h0⟩, hn⟩ · rw [isOfFinAddOrder_iff_nsmul_eq_zero] obtain ⟨n, hn⟩ := @h x exact ⟨n, Nat.pos_of_ne_zero (nonZeroDivisors.coe_ne_zero _), hn⟩ theorem isTorsion_iff_isTorsion_int [AddCommGroup M] : AddMonoid.IsTorsion M ↔ Module.IsTorsion ℤ M := by refine ⟨fun h x => ?_, fun h x => ?_⟩ · obtain ⟨n, h0, hn⟩ := (h x).exists_nsmul_eq_zero exact ⟨⟨n, mem_nonZeroDivisors_of_ne_zero <| ne_of_gt <| Int.natCast_pos.mpr h0⟩, (natCast_zsmul _ _).trans hn⟩ · rw [isOfFinAddOrder_iff_nsmul_eq_zero] obtain ⟨n, hn⟩ := @h x exact ⟨_, Int.natAbs_pos.2 (nonZeroDivisors.coe_ne_zero n), natAbs_nsmul_eq_zero.2 hn⟩ end AddMonoid namespace AddSubgroup variable (A : Type*) [AddCommGroup A] (n : ℤ) /-- The additive `n`-torsion subgroup for an integer `n`, denoted as `A[n]`. -/ @[reducible] def torsionBy : AddSubgroup A := (Submodule.torsionBy ℤ A n).toAddSubgroup @[inherit_doc torsionBy] scoped syntax:max (name := torsionByStx) (priority := high) term noWs "[" term "]" : term macro_rules | `($A[$n]) => `(torsionBy $A $n) /-- Unexpander for `torsionBy`. -/ @[scoped app_unexpander torsionBy] def torsionByUnexpander : Lean.PrettyPrinter.Unexpander | `($_ $A $n) => `($A[$n]) | _ => throw () lemma torsionBy.neg : A[-n] = A[n] := by ext a simp variable {A} {n : ℕ} @[simp] lemma torsionBy.nsmul (x : A[n]) : n • x = 0 := Nat.cast_smul_eq_nsmul ℤ n x ▸ Submodule.smul_torsionBy .. lemma torsionBy.nsmul_iff {x : A} : x ∈ A[n] ↔ n • x = 0 := Nat.cast_smul_eq_nsmul ℤ n x ▸ Submodule.mem_torsionBy_iff .. lemma torsionBy.mod_self_nsmul (s : ℕ) (x : A[n]) : s • x = (s % n) • x := nsmul_eq_mod_nsmul s (torsionBy.nsmul x) lemma torsionBy.mod_self_nsmul' (s : ℕ) {x : A} (h : x ∈ A[n]) : s • x = (s % n) • x := nsmul_eq_mod_nsmul s (torsionBy.nsmul_iff.mp h) /-- For a natural number `n`, the `n`-torsion subgroup of `A` is a `ZMod n` module. -/ def torsionBy.zmodModule : Module (ZMod n) A[n] := AddCommGroup.zmodModule torsionBy.nsmul end AddSubgroup section InfiniteRange @[simp] lemma infinite_range_add_smul_iff [AddCommGroup M] [Ring R] [Module R M] [Infinite R] [NoZeroSMulDivisors R M] (x y : M) : (Set.range <| fun r : R ↦ x + r • y).Infinite ↔ y ≠ 0 := by refine ⟨fun h hy ↦ by simp [hy] at h, fun h ↦ Set.infinite_range_of_injective fun r s hrs ↦ ?_⟩ rw [add_right_inj] at hrs exact smul_left_injective _ h hrs @[simp] lemma infinite_range_add_nsmul_iff [AddCommGroup M] [IsAddTorsionFree M] (x y : M) : (Set.range <| fun n : ℕ ↦ x + n • y).Infinite ↔ y ≠ 0 := by refine ⟨fun h hy ↦ by simp [hy] at h, fun h ↦ Set.infinite_range_of_injective fun r s hrs ↦ ?_⟩ rw [add_right_inj, ← natCast_zsmul, ← natCast_zsmul] at hrs simpa using smul_left_injective _ h hrs end InfiniteRange
.lake/packages/mathlib/Mathlib/Algebra/Module/Torsion/Field.lean
import Mathlib.Algebra.Field.Defs import Mathlib.Algebra.GroupWithZero.Action.Units import Mathlib.Algebra.Module.Torsion.Free /-! # Vector spaces are torsion-free In this file, we show that any module over a division semiring is torsion-free. Note that more generally any reflexive module is torsion-free. -/ open Module variable {𝕜 M : Type*} [DivisionSemiring 𝕜] [AddCommMonoid M] [Module 𝕜 M] /-- Any (semi)vector space is torsion-free. -/ instance (priority := 100) DivisionSemiring.to_moduleIsTorsionFree : IsTorsionFree 𝕜 M where isSMulRegular r hr m₁ m₂ hm := by simpa [hr.ne_zero] using congr(r⁻¹ • $hm)
.lake/packages/mathlib/Mathlib/Algebra/Module/Torsion/Free.lean
import Mathlib.Algebra.GroupWithZero.Regular import Mathlib.Algebra.Module.NatInt import Mathlib.Algebra.Module.Opposite import Mathlib.Algebra.Regular.Opposite import Mathlib.Algebra.Regular.SMul /-! # Torsion-free modules This files defines a torsion-free `R`-(semi)module `M` as a (semi)module where scalar multiplication by a regular element `r : R` is injective as a map `M → M`. In the case of a module (group over a ring), this is equivalent to saying that `r • m = 0` for some `r : R`, `m : M` implies that `r` is a zero-divisor. If furthermore the base ring is a domain, this is equivalent to the naïve `r • m = 0 ↔ r = 0 ∨ m = 0` definition. -/ open Module variable {R M N : Type*} section Semiring variable [Semiring R] section AddCommMonoid variable [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N] {r : R} {m m₁ m₂ : M} variable (R M) in /-- A `R`-module `M` is torsion-free if scalar multiplication by an element `r : R` is injective if multiplication (on `R`) by `r` is. For domains, this is equivalent to the usual condition of `r • m = 0 → r = 0 ∨ m = 0`. See `smul_eq_zero`. -/ class Module.IsTorsionFree where isSMulRegular ⦃r : R⦄ : IsRegular r → IsSMulRegular M r alias IsRegular.isSMulRegular := IsTorsionFree.isSMulRegular instance : IsTorsionFree R R where isSMulRegular _r hr := hr.1 instance : IsTorsionFree Rᵐᵒᵖ R where isSMulRegular _r hr := hr.unop.2 /-- Pullback an `IsTorsionFree` instance along an injective function. -/ lemma Function.Injective.moduleIsTorsionFree [IsTorsionFree R N] (f : M → N) (hf : f.Injective) (smul : ∀ (r : R) (m : M), f (r • m) = r • f m) : IsTorsionFree R M where isSMulRegular r hr m₁ m₂ hm := hf <| hr.isSMulRegular <| by simpa [smul] using congr(f $hm) instance IsAddTorsionFree.to_isTorsionFree_nat [IsAddTorsionFree M] : IsTorsionFree ℕ M where isSMulRegular n hn := nsmul_right_injective (by simpa [isRegular_iff_ne_zero] using hn) variable [IsTorsionFree R M] variable (M) in protected lemma IsRegular.smul_right_injective (hr : IsRegular r) : ((r • ·) : M → M).Injective := hr.isSMulRegular @[simp] protected lemma IsRegular.smul_right_inj (hr : IsRegular r) : r • m₁ = r • m₂ ↔ m₁ = m₂ := (hr.smul_right_injective _).eq_iff @[simp] protected lemma IsRegular.smul_eq_zero_iff_right (hr : IsRegular r) : r • m = 0 ↔ m = 0 := by rw [← hr.smul_right_inj (m₁ := m), smul_zero] protected lemma IsRegular.smul_ne_zero_iff_right (hr : IsRegular r) : r • m ≠ 0 ↔ m ≠ 0 := hr.smul_eq_zero_iff_right.ne variable [IsDomain R] lemma IsSMulRegular.of_ne_zero (hr : r ≠ 0) : IsSMulRegular M r := (isRegular_of_ne_zero hr).isSMulRegular variable [CharZero R] variable (R M) in include R in lemma IsAddTorsionFree.of_isTorsionFree : IsAddTorsionFree M where nsmul_right_injective n hn := by simp_rw [← Nat.cast_smul_eq_nsmul R] apply IsRegular.smul_right_injective simpa [isRegular_iff_ne_zero] /-- A characteristic zero domain is torsion-free. -/ instance (priority := 100) IsAddTorsionFree.of_isDomain_charZero : IsAddTorsionFree R := .of_isTorsionFree R R @[simp] lemma Module.isTorsionFree_nat_iff_isAddTorsionFree : IsTorsionFree ℕ M ↔ IsAddTorsionFree M where mp _ := .of_isTorsionFree ℕ _ mpr _ := inferInstance end AddCommMonoid section AddCommGroup variable [CharZero R] [IsDomain R] [AddCommGroup M] [Module R M] {m : M} instance [IsAddTorsionFree M] : IsTorsionFree ℤ M where isSMulRegular n hn := zsmul_right_injective (by simpa [isRegular_iff_ne_zero] using hn) @[simp] lemma Module.isTorsionFree_int_iff_isAddTorsionFree : IsTorsionFree ℤ M ↔ IsAddTorsionFree M where mp _ := .of_isTorsionFree ℤ _ mpr _ := inferInstance end AddCommGroup end Semiring
.lake/packages/mathlib/Mathlib/Algebra/Module/Presentation/Finite.lean
import Mathlib.Algebra.Module.Presentation.Basic import Mathlib.Algebra.Module.FinitePresentation /-! # Characterization of finitely presented modules A module is finitely presented (in the sense of `Module.FinitePresentation`) iff it admits a presentation with finitely many generators and relations. -/ universe w₀ w₁ v u namespace Module variable {A : Type u} [Ring A] {M : Type v} [AddCommGroup M] [Module A M] namespace Presentation variable (pres : Presentation A M) lemma finite [Finite pres.G] : Module.Finite A M := Finite.of_surjective _ pres.surjective_π lemma finitePresentation [Finite pres.G] [Finite pres.R] : Module.FinitePresentation A M := Module.finitePresentation_of_surjective _ pres.surjective_π (by rw [pres.ker_π] exact Submodule.fg_span (Set.finite_range _)) end Presentation lemma finitePresentation_iff_exists_presentation : Module.FinitePresentation A M ↔ ∃ (pres : Presentation.{w₀, w₁} A M), Finite pres.G ∧ Finite pres.R := by constructor · intro obtain ⟨G : Type w₀, _, var, hG⟩ := Submodule.fg_iff_exists_finite_generating_family.1 (finite_def.1 (inferInstanceAs (Module.Finite A M))) obtain ⟨R : Type w₁, _, relation, hR⟩ := Submodule.fg_iff_exists_finite_generating_family.1 (Module.FinitePresentation.fg_ker (Finsupp.linearCombination A var) (by rw [← LinearMap.range_eq_top, Finsupp.range_linearCombination, hG])) exact ⟨{ G := G R := R relation := relation var := var linearCombination_var_relation := fun r ↦ by rw [Submodule.ext_iff] at hR exact (hR _).1 (Submodule.subset_span ⟨_, rfl⟩) toIsPresentation := by rw [Relations.Solution.isPresentation_iff] exact ⟨hG, hR.symm⟩ }, inferInstance, inferInstance⟩ · rintro ⟨pres, _, _⟩ exact pres.finitePresentation end Module
.lake/packages/mathlib/Mathlib/Algebra/Module/Presentation/DirectSum.lean
import Mathlib.Algebra.Module.Presentation.Basic import Mathlib.Algebra.DirectSum.Module import Mathlib.Data.Finsupp.ToDFinsupp /-! # Presentation of a direct sum If `M : ι → Type _` is a family of `A`-modules, then the data of a presentation of each `M i`, we obtain a presentation of the module `⨁ i, M i`. In particular, from a presentation of an `A`-module `M`, we get a presentation of `ι →₀ M`. -/ universe w' w₀ w₁ w v u namespace Module open DirectSum variable {A : Type u} [Ring A] {ι : Type w} [DecidableEq ι] (relations : ι → Relations.{w₀, w₁} A) {M : ι → Type v} [∀ i, AddCommGroup (M i)] [∀ i, Module A (M i)] namespace Relations /-- The direct sum operations on `Relations A`. Given a family `relations : ι → Relations A`, the type of generators and relations in `directSum relations` are the corresponding `Sigma` types. -/ @[simps G R relation] noncomputable def directSum : Relations A where G := Σ i, (relations i).G R := Σ i, (relations i).R relation := fun ⟨i, r⟩ ↦ Finsupp.embDomain (Function.Embedding.sigmaMk (β := fun i ↦ (relations i).G) i) ((relations i).relation r) namespace Solution variable {relations} variable {N : Type v} [AddCommGroup N] [Module A N] /-- Given an `A`-module `N` and a family `relations : ι → Relations A`, the data of a solution of `Relations.directSum relations` in `N` is equivalent to the data of a family of solutions of `relations i` in `N` for all `i`. -/ @[simps] noncomputable def directSumEquiv : (Relations.directSum relations).Solution N ≃ ∀ i, (relations i).Solution N where toFun s i := { var := fun g ↦ s.var ⟨i, g⟩ linearCombination_var_relation := fun r ↦ by rw [← s.linearCombination_var_relation ⟨i, r⟩] symm apply Finsupp.linearCombination_embDomain } invFun t := { var := fun ⟨i, g⟩ ↦ (t i).var g linearCombination_var_relation := fun ⟨i, r⟩ ↦ by rw [← (t i).linearCombination_var_relation r] apply Finsupp.linearCombination_embDomain } /-- Given `solution : ∀ (i : ι), (relations i).Solution (M i)`, this is the canonical solution of `Relations.directSum relations` in `⨁ i, M i`. -/ noncomputable def directSum (solution : ∀ (i : ι), (relations i).Solution (M i)) : (Relations.directSum relations).Solution (⨁ i, M i) := directSumEquiv.symm (fun i ↦ (solution i).postcomp (lof A ι M i)) @[simp] lemma directSum_var (solution : ∀ (i : ι), (relations i).Solution (M i)) (i : ι) (g : (relations i).G) : (directSum solution).var ⟨i, g⟩ = lof A ι M i ((solution i).var g) := rfl namespace IsPresentation variable {solution : ∀ (i : ι), (relations i).Solution (M i)} (h : ∀ i, (solution i).IsPresentation) /-- The direct sum admits a presentation by generators and relations. -/ noncomputable def directSum.isRepresentationCore : Solution.IsPresentationCore.{w'} (directSum solution) where desc s := DirectSum.toModule _ _ _ (fun i ↦ (h i).desc (directSumEquiv s i)) postcomp_desc s := by ext ⟨i, g⟩; simp postcomp_injective h' := by ext i : 1 apply (h i).postcomp_injective ext g exact Solution.congr_var h' ⟨i, g⟩ include h in lemma directSum : (directSum solution).IsPresentation := (directSum.isRepresentationCore h).isPresentation end IsPresentation end Solution end Relations namespace Presentation /-- The obvious presentation of the module `⨁ i, M i` that is obtained from the data of presentations of the module `M i` for each `i`. -/ @[simps! G R relation] noncomputable def directSum (pres : ∀ (i : ι), Presentation A (M i)) : Presentation A (⨁ i, M i) := ofIsPresentation (Relations.Solution.IsPresentation.directSum (fun i ↦ (pres i).toIsPresentation)) @[simp] lemma directSum_var (pres : ∀ (i : ι), Presentation A (M i)) (i : ι) (g : (pres i).G) : (directSum pres).var ⟨i, g⟩ = lof A ι M i ((pres i).var g) := rfl section variable {N : Type v} [AddCommGroup N] [Module A N] (pres : Presentation A N) (ι : Type w) [DecidableEq ι] [DecidableEq N] /-- The obvious presentation of the module `ι →₀ N` that is deduced from a presentation of the module `N`. -/ @[simps! G R relation] noncomputable def finsupp : Presentation A (ι →₀ N) := (directSum (fun (_ : ι) ↦ pres)).ofLinearEquiv (finsuppLequivDFinsupp _).symm @[simp] lemma finsupp_var (i : ι) (g : pres.G) : (finsupp pres ι).var ⟨i, g⟩ = Finsupp.single i (pres.var g) := by apply (finsuppLequivDFinsupp A).injective erw [(finsuppLequivDFinsupp A).apply_symm_apply] rw [directSum_var, finsuppLequivDFinsupp_apply_apply, Finsupp.toDFinsupp_single] rfl end end Presentation end Module
.lake/packages/mathlib/Mathlib/Algebra/Module/Presentation/RestrictScalars.lean
import Mathlib.Algebra.Module.Presentation.DirectSum import Mathlib.Algebra.Module.Presentation.Cokernel /-! # Presentation of the restriction of scalars of a module Given a morphism of rings `A → B` and a `B`-module `M`, we obtain a presentation of `M` as a `A`-module from a presentation of `M` as `B`-module, a presentation of `B` as a `A`-module (and some additional data). ## TODO * deduce that if `B` is a finitely presented as an `A`-module and `M` is finitely presented as an `B`-module, then `M` is finitely presented as an `A`-module -/ namespace Module variable {B : Type*} [Ring B] {M : Type*} [AddCommGroup M] [Module B M] [DecidableEq B] (presM : Presentation B M) [DecidableEq presM.G] {A : Type*} [CommRing A] [Algebra A B] [Module A M] [IsScalarTower A B M] (presB : Presentation A B) namespace Presentation /-- The additional data that is necessary in order to obtain a presentation of the restriction of scalars of a module. -/ abbrev RestrictScalarsData : Type _ := (presB.finsupp presM.G).CokernelData (LinearMap.restrictScalars A presM.map) (fun (⟨g, g'⟩ : presB.G × presM.R) ↦ presB.var g • Finsupp.single g' (1 : B)) variable (data : presM.RestrictScalarsData presB) /-- A presentation of the restriction of scalars from `B` to `A` of a `B`-module `M`, given a presentation of `M` as a `B`-module, a presentation of `B` as an `A`-module, and an additional data. -/ noncomputable def restrictScalars : Presentation A M := ofExact (g := LinearMap.restrictScalars A presM.π) (presB.finsupp presM.G) data presM.exact presM.surjective_π (by ext v dsimp simp only [Submodule.mem_top, iff_true] apply Finsupp.induction · simp · intro r b w _ _ hw refine Submodule.add_mem _ ?_ hw obtain ⟨β, rfl⟩ := presB.surjective_π b apply Finsupp.induction (motive := fun β ↦ Finsupp.single r (presB.π β) ∈ _) · simp · intro g a f _ _ hf rw [map_add, Finsupp.single_add] refine Submodule.add_mem _ ?_ hf rw [← Finsupp.smul_single_one, ← Finsupp.smul_single_one, map_smul, Relations.Solution.π_single, smul_assoc] exact Submodule.smul_mem _ _ (Submodule.subset_span ⟨⟨g, r⟩, rfl⟩)) end Presentation end Module
.lake/packages/mathlib/Mathlib/Algebra/Module/Presentation/Differentials.lean
import Mathlib.Algebra.Module.Presentation.Basic import Mathlib.RingTheory.Kaehler.Polynomial import Mathlib.RingTheory.Extension.Cotangent.Basic import Mathlib.RingTheory.Extension.Presentation.Basic /-! # Presentation of the module of differentials Given a presentation of a `R`-algebra `S`, we obtain a presentation of the `S`-module `Ω[S⁄R]`. Assume `pres : Algebra.Presentation R S` is a presentation of `S` as an `R`-algebra. We then have a type `ι` for the generators, a type `σ` for the relations, and for each `r : σ` we have the relation `pres.relation r` in `pres.Ring` (which is a ring of polynomials over `R` with variables indexed by `ι`). Then, `Ω[pres.Ring⁄R]` identifies to the free module on the type `ι`, and for each `r : σ`, we may consider the image of the differential of `pres.relation r` in this free module, and by using the (surjective) map `pres.Ring → S`, we obtain an element `pres.differentialsRelations.relation r` in the free `S`-module on `ι`. The main result in this file is that `Ω[S⁄R]` identifies to the quotient of the free `S`-module on `ι` by the submodule generated by these elements `pres.differentialsRelations.relation r`. We show this as a consequence of `Algebra.Extension.exact_cotangentComplex_toKaehler` from the file `Mathlib/RingTheory/Kaehler/CotangentComplex.lean`. -/ open Module universe w' t w u v namespace Algebra.Presentation open KaehlerDifferential variable {R : Type u} {S : Type v} {ι : Type w} {σ : Type t} [CommRing R] [CommRing S] [Algebra R S] (pres : Algebra.Presentation R S ι σ) /-- The shape of the presentation by generators and relations of the `S`-module `Ω[S⁄R]` that is obtained from a presentation of `S` as an `R`-algebra. -/ @[simps G R] noncomputable def differentialsRelations : Module.Relations S where G := ι R := σ relation r := Finsupp.mapRange (algebraMap pres.Ring S) (by simp) ((mvPolynomialBasis R ι).repr (D _ _ (pres.relation r))) namespace differentials /-! We obtain here a few compatibilities which allow to compare the two sequences `(σ →₀ S) → (ι →₀ S) → Ω[S⁄R]` and `pres.toExtension.Cotangent →ₗ[S] pres.toExtension.CotangentSpace → Ω[S⁄R]`. Indeed, there is commutative diagram with a surjective map `hom₁ : (σ →₀ S) →ₗ[S] pres.toExtension.Cotangent` on the left and bijections on the middle and on the right. Then, the exactness of the first sequence shall follow from the exactness of the second which is `Algebra.Extension.exact_cotangentComplex_toKaehler`. -/ /-- Same as `comm₂₃` below, but here we have not yet constructed `differentialsSolution`. -/ lemma comm₂₃' : pres.toExtension.toKaehler.comp pres.cotangentSpaceBasis.repr.symm.toLinearMap = Finsupp.linearCombination S (fun g ↦ D _ _ (pres.val g)) := by ext simp /-- The canonical map `(σ →₀ S) →ₗ[S] pres.toExtension.Cotangent`. -/ noncomputable def hom₁ : (σ →₀ S) →ₗ[S] pres.toExtension.Cotangent := Finsupp.linearCombination S (fun r ↦ Extension.Cotangent.mk ⟨pres.relation r, by simp⟩) lemma hom₁_single (r : σ) : hom₁ pres (Finsupp.single r 1) = Extension.Cotangent.mk ⟨pres.relation r, by simp⟩ := by simp [hom₁] lemma surjective_hom₁ : Function.Surjective (hom₁ pres) := by let φ : (σ →₀ S) →ₗ[pres.Ring] pres.toExtension.Cotangent := { toFun := hom₁ pres map_add' := by simp map_smul' := by simp } change Function.Surjective φ have h₁ := Algebra.Extension.Cotangent.mk_surjective (P := pres.toExtension) have h₂ : Submodule.span pres.Ring (Set.range (fun r ↦ (⟨pres.relation r, by simp⟩ : pres.ker))) = ⊤ := by refine Submodule.map_injective_of_injective (f := Submodule.subtype pres.ker) Subtype.coe_injective ?_ rw [Submodule.map_top, Submodule.range_subtype, Submodule.map_span, Submodule.coe_subtype, Ideal.submodule_span_eq] simp only [← pres.span_range_relation_eq_ker] congr aesop rw [← LinearMap.range_eq_top] at h₁ ⊢ rw [← top_le_iff, ← h₁, LinearMap.range_eq_map, ← h₂] dsimp rw [Submodule.map_span_le] rintro _ ⟨r, rfl⟩ simp only [LinearMap.mem_range] refine ⟨Finsupp.single r 1, ?_⟩ simp only [LinearMap.coe_mk, AddHom.coe_mk, hom₁_single, φ] rfl lemma comm₁₂_single (r : σ) : pres.toExtension.cotangentComplex (hom₁ pres (Finsupp.single r 1)) = pres.cotangentSpaceBasis.repr.symm ((differentialsRelations pres).relation r) := by simp only [hom₁, Finsupp.linearCombination_single, one_smul, differentialsRelations, Basis.repr_symm_apply, Extension.cotangentComplex_mk] exact pres.cotangentSpaceBasis.repr.injective (by ext; simp) lemma comm₁₂ : pres.toExtension.cotangentComplex.comp (hom₁ pres) = pres.cotangentSpaceBasis.repr.symm.comp (differentialsRelations pres).map := by ext r have := (differentialsRelations pres).map_single dsimp at this ⊢ rw [comm₁₂_single, this] end differentials open differentials in /-- The `S`-module `Ω[S⁄R]` contains an obvious solution to the system of linear equations `pres.differentialsRelations.Solution` when `pres` is a presentation of `S` as an `R`-algebra. -/ noncomputable def differentialsSolution : pres.differentialsRelations.Solution Ω[S⁄R] where var g := D _ _ (pres.val g) linearCombination_var_relation r := by simp only [differentialsRelations_G, LinearMap.coe_comp, LinearEquiv.coe_coe, Function.comp_apply, ← comm₂₃', ← comm₁₂_single] apply DFunLike.congr_fun (Function.Exact.linearMap_comp_eq_zero (pres.toExtension.exact_cotangentComplex_toKaehler)) lemma differentials.comm₂₃ : pres.toExtension.toKaehler.comp pres.cotangentSpaceBasis.repr.symm.toLinearMap = pres.differentialsSolution.π := comm₂₃' pres open differentials in lemma differentialsSolution_isPresentation : pres.differentialsSolution.IsPresentation := by rw [Module.Relations.Solution.isPresentation_iff] constructor · rw [← Module.Relations.Solution.surjective_π_iff_span_eq_top, ← comm₂₃] exact Extension.toKaehler_surjective.comp pres.cotangentSpaceBasis.repr.symm.surjective · rw [← Module.Relations.range_map] exact Function.Exact.linearMap_ker_eq ((LinearMap.exact_iff_of_surjective_of_bijective_of_injective _ _ _ _ (hom₁ pres) pres.cotangentSpaceBasis.repr.symm.toLinearMap .id (comm₁₂ pres) (by simpa using comm₂₃ pres) (surjective_hom₁ pres) (LinearEquiv.bijective _) (Equiv.refl _).injective).2 pres.toExtension.exact_cotangentComplex_toKaehler) /-- The presentation of the `S`-module `Ω[S⁄R]` deduced from a presentation of `S` as a `R`-algebra. -/ noncomputable def differentials : Module.Presentation S Ω[S⁄R] where G := ι R := σ relation := _ toSolution := differentialsSolution pres toIsPresentation := pres.differentialsSolution_isPresentation end Algebra.Presentation
.lake/packages/mathlib/Mathlib/Algebra/Module/Presentation/Tautological.lean
import Mathlib.Algebra.Module.Presentation.Basic /-! # The tautological presentation of a module Given an `A`-module `M`, we provide its tautological presentation: * there is a generator `[m]` for each `m : M`; * the relations are `[m₁] + [m₂] - [m₁ + m₂] = 0` and `a • [m] - [a • m] = 0`. -/ universe w v u namespace Module variable (A : Type u) [Ring A] (M : Type v) [AddCommGroup M] [Module A M] namespace Presentation /-- The type which parametrizes the tautological relations in an `A`-module `M`. -/ inductive tautological.R | add (m₁ m₂ : M) | smul (a : A) (m : M) /-- The system of equations corresponding to the tautological presentation of an `A`-module. -/ @[simps] noncomputable def tautologicalRelations : Relations A where G := M R := tautological.R A M relation | .add m₁ m₂ => Finsupp.single m₁ 1 + Finsupp.single m₂ 1 - Finsupp.single (m₁ + m₂) 1 | .smul a m => a • Finsupp.single m 1 - Finsupp.single (a • m) 1 variable {A M} in /-- Solutions of `tautologicalRelations A M` in an `A`-module `N` identify to `M →ₗ[A] N`. -/ noncomputable def tautologicalRelationsSolutionEquiv {N : Type w} [AddCommGroup N] [Module A N] : (tautologicalRelations A M).Solution N ≃ (M →ₗ[A] N) where toFun s := { toFun := s.var map_add' := fun m₁ m₂ ↦ by symm rw [← sub_eq_zero] simpa using s.linearCombination_var_relation (.add m₁ m₂) map_smul' := fun a m ↦ by symm rw [← sub_eq_zero] simpa using s.linearCombination_var_relation (.smul a m) } invFun f := { var := f linearCombination_var_relation := by rintro (_ | _) <;> simp } /-- The obvious solution of `tautologicalRelations A M` in the module `M`. -/ @[simps! var] noncomputable def tautologicalSolution : (tautologicalRelations A M).Solution M := tautologicalRelationsSolutionEquiv.symm .id /-- Any `A`-module admits a tautological presentation by generators and relations. -/ noncomputable def tautologicalSolutionIsPresentationCore : Relations.Solution.IsPresentationCore.{w} (tautologicalSolution A M) where desc s := tautologicalRelationsSolutionEquiv s postcomp_desc _ := rfl postcomp_injective h := by ext m exact Relations.Solution.congr_var h m lemma tautologicalSolution_isPresentation : (tautologicalSolution A M).IsPresentation := (tautologicalSolutionIsPresentationCore A M).isPresentation /-- The tautological presentation of any `A`-module `M` by generators and relations. There is a generator `[m]` for any element `m : M`, and there are two types of relations: * `[m₁] + [m₂] - [m₁ + m₂] = 0` * `a • [m] - [a • m] = 0`. -/ @[simps!] noncomputable def tautological : Presentation A M := ofIsPresentation (tautologicalSolution_isPresentation A M) end Presentation end Module
.lake/packages/mathlib/Mathlib/Algebra/Module/Presentation/Basic.lean
import Mathlib.Algebra.Exact import Mathlib.Algebra.Module.ULift import Mathlib.LinearAlgebra.Quotient.Basic import Mathlib.LinearAlgebra.Finsupp.LinearCombination /-! # Presentations of modules Given a ring `A`, we introduce a structure `Relations A` which contains the data that is necessary to define a module by generators and relations. A term `relations : Relations A` involves two index types: a type `G` for the generators and a type `R` for the relations. The relation attached to `r : R` is an element `G →₀ A` which expresses the coefficients of the expected linear relation. One may think of `relations : Relations A` as a particular shape for systems of linear equations in any `A`-module `M`. Each `g : G` can be thought of as a variable (in `M`) and each `r : R` specifies a linear relation that these variables should satisfy. This way, we get a type `relations.Solution M`. Then, if `solution : relations.Solution M`, we introduce the predicate `solution.IsPresentation` which asserts that `solution` is the universal solution to the given equations, i.e. `solution` gives a presentation of `M` by generators and relations. Given an `A`-module `M`, we also introduce the type `Presentation A M` which contains all the data and properties involved in a presentation of `M` by generators and relations. ## TODO * Relate this to `Module.FinitePresentation` * Behaviour of presentations with respect to the extension of scalars and the restriction of scalars -/ assert_not_exists Cardinal universe w' w'' w₀ w₁ v'' v' v u namespace Module variable (A : Type u) [Ring A] /-- Given a ring `A`, this structure involves a family of elements (indexed by a type `R`) in a free module `G →₀ A`. This allows to define an `A`-module by generators and relations, see `Relations.Quotient`. -/ @[nolint checkUnivs] structure Relations where /-- the index type for generators -/ G : Type w₀ /-- the index type for relations -/ R : Type w₁ /-- the coefficients of the linear relations that are expected between the generators -/ relation (r : R) : G →₀ A namespace Relations variable {A} (relations : Relations.{w₀, w₁} A) /-- The module that is presented by generators and relations given by `relations : Relations A`. This is the quotient of the free `A`-module on `relations.G` by the submodule generated by the given relations. -/ def Quotient := (relations.G →₀ A) ⧸ Submodule.span A (Set.range relations.relation) noncomputable instance : AddCommGroup relations.Quotient := by dsimp only [Quotient]; infer_instance noncomputable instance : Module A relations.Quotient := by dsimp only [Quotient]; infer_instance /-- The canonical (surjective) linear map `(relations.G →₀ A) →ₗ[A] relations.Quotient`. -/ noncomputable def toQuotient : (relations.G →₀ A) →ₗ[A] relations.Quotient := Submodule.mkQ _ variable {relations} in @[ext] lemma Quotient.linearMap_ext {M : Type v} [AddCommGroup M] [Module A M] {f f' : relations.Quotient →ₗ[A] M} (h : ∀ (g : relations.G), f (relations.toQuotient (Finsupp.single g 1)) = f' (relations.toQuotient (Finsupp.single g 1))) : f = f' := Submodule.linearMap_qext _ (Finsupp.lhom_ext' (fun g ↦ LinearMap.ext_ring (h g))) lemma surjective_toQuotient : Function.Surjective relations.toQuotient := Submodule.mkQ_surjective _ lemma ker_toQuotient : LinearMap.ker relations.toQuotient = Submodule.span A (Set.range relations.relation) := Submodule.ker_mkQ _ @[simp] lemma toQuotient_relation (r : relations.R) : relations.toQuotient (relations.relation r) = 0 := by dsimp only [toQuotient, Quotient] rw [Submodule.mkQ_apply, Submodule.Quotient.mk_eq_zero] exact Submodule.subset_span (by simp) /-- The linear map `(relations.R →₀ A) →ₗ[A] (relations.G →₀ A)` corresponding to the relations given by `relations : Relations A`. -/ noncomputable def map : (relations.R →₀ A) →ₗ[A] (relations.G →₀ A) := Finsupp.linearCombination _ relations.relation @[simp] lemma map_single (r : relations.R) : relations.map (Finsupp.single r 1) = relations.relation r := by simp [map] @[simp] lemma range_map : LinearMap.range relations.map = Submodule.span A (Set.range relations.relation) := Finsupp.range_linearCombination _ @[simp] lemma toQuotient_map : relations.toQuotient.comp relations.map = 0 := by aesop @[simp] lemma toQuotient_map_apply (x : relations.R →₀ A) : relations.toQuotient (relations.map x) = 0 := DFunLike.congr_fun relations.toQuotient_map x variable (M : Type v) [AddCommGroup M] [Module A M] /-- The type of solutions in a module `M` of the equations given by `relations : Relations A`. -/ @[ext] structure Solution where /-- the image in `M` of each variable -/ var (g : relations.G) : M linearCombination_var_relation (r : relations.R) : Finsupp.linearCombination _ var (relations.relation r) = 0 namespace Solution variable {relations M} section variable (solution : relations.Solution M) /-- Given `relations : Relations A` and a solution in `relations.Solution M`, this is the linear map `(relations.G →₀ A) →ₗ[A] M` canonically associated to the solution. -/ noncomputable def π : (relations.G →₀ A) →ₗ[A] M := Finsupp.linearCombination _ solution.var @[simp] lemma π_single (g : relations.G) : solution.π (Finsupp.single g 1) = solution.var g := by simp [π] @[simp] lemma π_relation (r : relations.R) : solution.π (relations.relation r) = 0 := solution.linearCombination_var_relation r @[simp] lemma π_comp_map : solution.π.comp relations.map = 0 := by aesop @[simp] lemma π_comp_map_apply (x : relations.R →₀ A) : solution.π (relations.map x) = 0 := by change solution.π.comp relations.map x = 0 rw [π_comp_map, LinearMap.zero_apply] lemma range_π : LinearMap.range solution.π = Submodule.span A (Set.range solution.var) := Finsupp.range_linearCombination _ lemma span_relation_le_ker_π : Submodule.span A (Set.range relations.relation) ≤ LinearMap.ker solution.π := by rw [Submodule.span_le] rintro _ ⟨r, rfl⟩ simp only [SetLike.mem_coe, LinearMap.mem_ker, π_relation] /-- Given `relations : Relations A` and `solution : relations.Solution M`, this is the canonical linear map `relations.Quotient →ₗ[A] M` from the module. -/ noncomputable def fromQuotient : relations.Quotient →ₗ[A] M := Submodule.liftQ _ solution.π solution.span_relation_le_ker_π @[simp] lemma fromQuotient_comp_toQuotient : solution.fromQuotient.comp relations.toQuotient = solution.π := rfl @[simp] lemma fromQuotient_toQuotient (x : relations.G →₀ A) : solution.fromQuotient (relations.toQuotient x) = solution.π x := rfl variable {N : Type v'} [AddCommGroup N] [Module A N] (f : M →ₗ[A] N) /-- The image of a solution to `relations : Relation A` by a linear map `M →ₗ[A] N`. -/ @[simps] def postcomp : relations.Solution N where var g := f (solution.var g) linearCombination_var_relation r := by have : Finsupp.linearCombination _ (fun g ↦ f (solution.var g)) = f.comp solution.π := by aesop simp [this] @[simp] lemma postcomp_comp {N' : Type v''} [AddCommGroup N'] [Module A N'] (g : N →ₗ[A] N') : solution.postcomp (g.comp f) = (solution.postcomp f).postcomp g := rfl @[simp] lemma postcomp_id : solution.postcomp LinearMap.id = solution := rfl variable {solution} lemma congr_var {solution' : relations.Solution M} (h : solution = solution') (g : relations.G) : solution.var g = solution'.var g := by rw [h] lemma congr_postcomp {solution' : relations.Solution M} (h : solution = solution') (f : M →ₗ[A] N) : solution.postcomp f = solution'.postcomp f := by rw [h] end section variable (π : (relations.G →₀ A) →ₗ[A] M) (hπ : ∀ (r : relations.R), π (relations.relation r) = 0) /-- Given `relations : Relations A` and an `A`-module `M`, this is a constructor for `relations.Solution M` for which the data is given as a linear map `π : (relations.G →₀ A) →ₗ[A] M`. (See also `ofπ'` for an alternate vanishing criterion.) -/ @[simps -isSimp] noncomputable def ofπ : relations.Solution M where var g := π (Finsupp.single g 1) linearCombination_var_relation r := by have : π = Finsupp.linearCombination _ (fun g ↦ π (Finsupp.single g 1)) := by ext; simp rw [← this] exact hπ r @[simp] lemma ofπ_π : (ofπ π hπ).π = π := by ext; simp [ofπ] end section variable (π : (relations.G →₀ A) →ₗ[A] M) (hπ : π.comp relations.map = 0) /-- Variant of `ofπ` where the vanishing condition is expressed in terms of a composition of linear maps. -/ @[simps! -isSimp] noncomputable def ofπ' : relations.Solution M := ofπ π (fun r ↦ by simpa using DFunLike.congr_fun hπ (Finsupp.single r 1)) @[simp] lemma ofπ'_π : (ofπ' π hπ).π = π := by simp [ofπ'] end section variable (solution : relations.Solution M) lemma injective_fromQuotient_iff_ker_π_eq_span : Function.Injective solution.fromQuotient ↔ LinearMap.ker solution.π = Submodule.span A (Set.range relations.relation) := by constructor · intro h rw [← ker_toQuotient, ← fromQuotient_comp_toQuotient, LinearMap.ker_comp, LinearMap.ker_eq_bot.2 h, Submodule.comap_bot] · intro h rw [← LinearMap.ker_eq_bot, eq_bot_iff] intro x hx obtain ⟨x, rfl⟩ := relations.surjective_toQuotient x replace hx : x ∈ LinearMap.ker solution.π := by simpa only [LinearMap.mem_ker, fromQuotient_toQuotient] using hx rw [h, ← range_map] at hx obtain ⟨x, rfl⟩ := hx simp only [toQuotient_map_apply, Submodule.zero_mem] lemma surjective_fromQuotient_iff_surjective_π : Function.Surjective solution.fromQuotient ↔ Function.Surjective solution.π := by simpa only [← fromQuotient_comp_toQuotient] using (Function.Surjective.of_comp_iff (f := solution.fromQuotient) relations.surjective_toQuotient).symm lemma surjective_π_iff_span_eq_top : Function.Surjective solution.π ↔ Submodule.span A (Set.range solution.var) = ⊤ := by rw [← LinearMap.range_eq_top, range_π] end /-- Given `relations : Relations A`, an `A`-module `M` and `solution : relations.Solution M`, this property asserts that `solution` gives a presentation of `M` by generators and relations. -/ structure IsPresentation (solution : relations.Solution M) : Prop where bijective : Function.Bijective solution.fromQuotient namespace IsPresentation variable {solution : relations.Solution M} (h : solution.IsPresentation) include h /-- When `M` admits a presentation by generators and relations given by `solution : relations.Solutions M`, this is the associated linear equivalence `relations.Quotient ≃ₗ[A] M`. -/ noncomputable def linearEquiv : relations.Quotient ≃ₗ[A] M := LinearEquiv.ofBijective _ h.bijective @[simp] lemma linearEquiv_apply (x : relations.Quotient) : h.linearEquiv x = solution.fromQuotient x := rfl @[simp] lemma linearEquiv_symm_var (g : relations.G) : h.linearEquiv.symm (solution.var g) = relations.toQuotient (Finsupp.single g 1) := h.linearEquiv.injective (by simp) lemma surjective_π : Function.Surjective solution.π := by simpa only [← surjective_fromQuotient_iff_surjective_π] using h.bijective.2 lemma ker_π : LinearMap.ker solution.π = Submodule.span A (Set.range relations.relation) := by simpa only [← injective_fromQuotient_iff_ker_π_eq_span] using h.bijective.1 /-- The sequence `(relations.R →₀ A) → (relations.G →₀ A) → M → 0` is exact. -/ lemma exact : Function.Exact relations.map solution.π := by rw [LinearMap.exact_iff, range_map, ← solution.injective_fromQuotient_iff_ker_π_eq_span] exact h.bijective.1 variable {N : Type v'} [AddCommGroup N] [Module A N] /-- If `M` admits a presentation by generators and relations, and we have a solution of the same equations in a module `N`, then this is the canonical induced linear map `M →ₗ[A] N`. -/ noncomputable def desc (s : relations.Solution N) : M →ₗ[A] N := s.fromQuotient.comp h.linearEquiv.symm.toLinearMap @[simp] lemma desc_var (s : relations.Solution N) (g : relations.G) : h.desc s (solution.var g) = s.var g := by dsimp [desc] simp only [linearEquiv_symm_var, fromQuotient_toQuotient, π_single] @[simp] lemma desc_comp_π (s : relations.Solution N) : (h.desc s).comp solution.π = s.π := by aesop @[simp] lemma π_desc_apply (s : relations.Solution N) (x : relations.G →₀ A) : h.desc s (solution.π x) = s.π x := DFunLike.congr_fun (h.desc_comp_π s) x @[simp] lemma postcomp_desc (s : relations.Solution N) : solution.postcomp (h.desc s) = s := by aesop lemma postcomp_injective {f f' : M →ₗ[A] N} (h' : solution.postcomp f = solution.postcomp f') : f = f' := by suffices f.comp solution.fromQuotient = f'.comp solution.fromQuotient by ext x obtain ⟨y, rfl⟩ := h.bijective.2 x exact DFunLike.congr_fun this y ext g simpa using congr_var h' g /-- If `M` admits a presentation by generators and relations, then linear maps from `M` can be (naturally) identified to the solutions of certain linear equations. -/ @[simps] noncomputable def linearMapEquiv : (M →ₗ[A] N) ≃ relations.Solution N where toFun f := solution.postcomp f invFun s := h.desc s left_inv f := h.postcomp_injective (by simp) right_inv s := by simp section variable {solution' : relations.Solution N} (h' : solution'.IsPresentation) /-- Uniqueness (up to a unique linear equivalence) of the module defined by generators and relations. -/ noncomputable def uniq : M ≃ₗ[A] N := LinearEquiv.ofLinear (h.desc solution') (h'.desc solution) (h'.postcomp_injective (by simp)) (h.postcomp_injective (by simp)) @[simp] lemma postcomp_uniq : solution.postcomp (uniq h h').toLinearMap = solution' := by simp [uniq] @[simp] lemma postcomp_uniq_symm : solution'.postcomp (uniq h h').symm.toLinearMap = solution := by simp [uniq] @[simp] lemma uniq_var (g : relations.G) : uniq h h' (solution.var g) = solution'.var g := by simp [uniq] @[simp] lemma uniq_symm_var (g : relations.G) : (uniq h h').symm (solution'.var g) = solution.var g := by simp [uniq] end lemma of_linearEquiv (e : M ≃ₗ[A] N) : (solution.postcomp e.toLinearMap).IsPresentation where bijective := by have : (solution.postcomp e.toLinearMap).fromQuotient = e.toLinearMap.comp (solution.fromQuotient) := by aesop rw [this, LinearMap.coe_comp, LinearEquiv.coe_coe] exact Function.Bijective.comp e.bijective h.bijective end IsPresentation variable (relations) /-- Given `relations : Relations A`, this is the obvious solution to `relations` in the quotient `relations.Quotient`. -/ @[simps!] noncomputable def ofQuotient : relations.Solution relations.Quotient := ofπ relations.toQuotient (by simp) @[simp] lemma ofQuotient_π : (ofQuotient relations).π = Submodule.mkQ _ := ofπ_π _ _ @[simp] lemma ofQuotient_fromQuotient : (ofQuotient relations).fromQuotient = .id := by aesop lemma ofQuotient_isPresentation : (ofQuotient relations).IsPresentation where bijective := by simpa only [ofQuotient_fromQuotient, LinearMap.id_coe] using Function.bijective_id variable {relations} /-- Helper structure in order to prove `Module.Relations.Solutions.IsPresentation` by showing the universal property of the module defined by generators and relations. The universal property is restricted to modules that are in `Type w'` for an auxiliary universe `w'`. See `IsPresentationCore.isPresentation`. -/ structure IsPresentationCore (solution : relations.Solution M) where /-- any solution in a module `N : Type w'` is obtained in a unique way by postcomposing `solution : relations.Solution M` by a linear map `M →ₗ[A] N`. -/ desc {N : Type w'} [AddCommGroup N] [Module A N] (s : relations.Solution N) : M →ₗ[A] N postcomp_desc {N : Type w'} [AddCommGroup N] [Module A N] (s : relations.Solution N) : solution.postcomp (desc s) = s postcomp_injective {N : Type w'} [AddCommGroup N] [Module A N] {f f' : M →ₗ[A] N} (h : solution.postcomp f = solution.postcomp f') : f = f' namespace IsPresentationCore variable {solution : relations.Solution M} @[simp] lemma desc_var (h : IsPresentationCore.{w'} solution) {N : Type w'} [AddCommGroup N] [Module A N] (s : relations.Solution N) (g : relations.G) : h.desc s (solution.var g) = s.var g := congr_var (h.postcomp_desc s) g /-- The structure `IsPresentationCore` can be shrunk to a lower universe. -/ def down (h : IsPresentationCore.{max w' w''} solution) : IsPresentationCore.{w''} solution where desc s := ULift.moduleEquiv.toLinearMap.comp (h.desc (s.postcomp ULift.moduleEquiv.symm.toLinearMap)) postcomp_desc s:= by simpa using congr_postcomp (h.postcomp_desc (s.postcomp ULift.moduleEquiv.symm.toLinearMap)) ULift.moduleEquiv.toLinearMap postcomp_injective {N _ _ f f'} h' := by ext x have := congr_postcomp h' ULift.moduleEquiv.{_, _, w'}.symm.toLinearMap simp only [← postcomp_comp] at this simpa using DFunLike.congr_fun (h.postcomp_injective this) x lemma isPresentation {solution : relations.Solution M} (h : IsPresentationCore.{max u v w₀} solution) : solution.IsPresentation where bijective := by let e : relations.Quotient ≃ₗ[A] M := LinearEquiv.ofLinear solution.fromQuotient ((down.{v} h).desc (ofQuotient relations)) ((down.{max u w₀} h).postcomp_injective (by aesop)) (by aesop) exact e.bijective end IsPresentationCore variable (solution : relations.Solution M) lemma isPresentation_iff : solution.IsPresentation ↔ Submodule.span A (Set.range solution.var) = ⊤ ∧ LinearMap.ker solution.π = Submodule.span A (Set.range relations.relation) := by rw [← injective_fromQuotient_iff_ker_π_eq_span, ← surjective_π_iff_span_eq_top, ← surjective_fromQuotient_iff_surjective_π, ] exact ⟨fun h ↦ ⟨h.bijective.2, h.bijective.1⟩, fun h ↦ ⟨⟨h.2, h.1⟩⟩⟩ lemma isPresentation_mk (h₁ : Submodule.span A (Set.range solution.var) = ⊤) (h₂ : LinearMap.ker solution.π = Submodule.span A (Set.range relations.relation)) : solution.IsPresentation := by rw [isPresentation_iff]; constructor <;> assumption end Solution end Relations variable (M : Type v) [AddCommGroup M] [Module A M] /-- Given an `A`-module `M`, a term in this type is a presentation by `M` by generators and relations. -/ @[nolint checkUnivs] structure Presentation extends Relations.{w₀, w₁} A, toRelations.Solution M, toSolution.IsPresentation where variable {A M} /-- Constructor for `Module.Presentation`. -/ @[simps toRelations toSolution] def Presentation.ofIsPresentation {relations : Relations.{w₀, w₁} A} {solution : relations.Solution M} (h : solution.IsPresentation) : Presentation.{w₀, w₁} A M where __ := relations toSolution := solution toIsPresentation := h /-- The presentation of an `A`-module `N` that is deduced from a presentation of a module `M` and a linear equivalence `e : M ≃ₗ[A] N`. -/ @[simps! toRelations toSolution] def Presentation.ofLinearEquiv (pres : Presentation.{w₀, w₁} A M) {N : Type v'} [AddCommGroup N] [Module A N] (e : M ≃ₗ[A] N) : Presentation A N := ofIsPresentation (pres.toIsPresentation.of_linearEquiv e) end Module
.lake/packages/mathlib/Mathlib/Algebra/Module/Presentation/Cokernel.lean
import Mathlib.Algebra.Module.Presentation.Basic /-! # Presentation of a cokernel If `f : M₁ →ₗ[A] M₂` is a linear map between modules, `pres₂` is a presentation of `M₂` and `g₁ : ι → M₁` is a family of generators of `M₁` (which is expressed as `hg₁ : Submodule.span A (Set.range g₁) = ⊤`), then we provide a way to obtain a presentation of the cokernel of `f`. It requires an additional data `data : pres₂.CokernelData f g₁`, which consists of liftings of the images by `f` of the generators of `M₁` as linear combinations of the generators of `M₂`. Then, we obtain a presentation `pres₂.cokernel data hg₁ : Presentation A (M₂ ⧸ LinearMap.range f)`. More generally, if we have an exact sequence `M₁ → M₂ → M₃ → 0`, we obtain a presentation of `M₃`, see `Presentation.ofExact`. -/ universe w w₁ w₂₀ w₂₁ v₁ v₂ v₃ u namespace Module variable {A : Type u} [Ring A] {M₁ : Type v₁} {M₂ : Type v₂} {M₃ : Type v₃} [AddCommGroup M₁] [Module A M₁] [AddCommGroup M₂] [Module A M₂] [AddCommGroup M₃] [Module A M₃] namespace Presentation section Cokernel variable (pres₂ : Presentation.{w₂₀, w₂₁} A M₂) (f : M₁ →ₗ[A] M₂) {ι : Type w₁} (g₁ : ι → M₁) /-- Given a linear map `f : M₁ →ₗ[A] M₂`, a presentation of `M₂` and a choice of generators of `M₁`, this structure specifies a lifting of the image by `f` of each generator of `M₁` as a linear combination of the generators of `M₂`. -/ structure CokernelData where /-- a lifting of `f (g₁ i)` in `pres₂.G →₀ A` -/ lift (i : ι) : pres₂.G →₀ A π_lift (i : ι) : pres₂.π (lift i) = f (g₁ i) /-- Constructor for `Presentation.CokernelData` in case we have a chosen set-theoretic section of the projection `(pres₂.G →₀ A) → M₂`. -/ @[simps] def CokernelData.ofSection (s : M₂ → (pres₂.G →₀ A)) (hs : ∀ (m₂ : M₂), pres₂.π (s m₂) = m₂) : pres₂.CokernelData f g₁ where lift i := s (f (g₁ i)) π_lift i := by simp [hs] instance nonempty_cokernelData : Nonempty (pres₂.CokernelData f g₁) := by obtain ⟨s, hs⟩ := pres₂.surjective_π.hasRightInverse exact ⟨CokernelData.ofSection _ _ _ s hs⟩ variable {g₁ f} (data : pres₂.CokernelData f g₁) /-- The shape of the presentation by generators and relations of the cokernel of `f : M₁ →ₗ[A] M₂`. It consists of a generator for each generator of `M₂`, and there are two types of relations: one for each relation in the presentation in `M₂`, and one for each generator of `M₁`. -/ @[simps] def cokernelRelations : Relations A where G := pres₂.G R := Sum pres₂.R ι relation | .inl r => pres₂.relation r | .inr i => data.lift i /-- The obvious solution in `M₂ ⧸ LinearMap.range f` to the equations in `pres₂.cokernelRelations data`. -/ @[simps] def cokernelSolution : (pres₂.cokernelRelations data).Solution (M₂ ⧸ LinearMap.range f) where var g := Submodule.mkQ _ (pres₂.var g) linearCombination_var_relation := by intro x erw [← Finsupp.apply_linearCombination] obtain (r | i) := x · erw [pres₂.linearCombination_var_relation] dsimp · erw [data.π_lift] simp variable (hg₁ : Submodule.span A (Set.range g₁) = ⊤) namespace cokernelSolution /-- The cokernel can be defined by generators and relations. -/ noncomputable def isPresentationCore : Relations.Solution.IsPresentationCore.{w} (pres₂.cokernelSolution data) where desc s := (LinearMap.range f).liftQ (pres₂.desc { var := s.var linearCombination_var_relation := fun r ↦ s.linearCombination_var_relation (.inl r) }) (by rw [LinearMap.range_eq_map, ← hg₁, Submodule.map_span, Submodule.span_le, Set.image_subset_iff] rintro _ ⟨i, rfl⟩ rw [Set.mem_preimage, SetLike.mem_coe, LinearMap.mem_ker, ← data.π_lift, Relations.Solution.IsPresentation.π_desc_apply] exact s.linearCombination_var_relation (.inr i)) postcomp_desc s := by aesop postcomp_injective h := by ext : 1 apply pres₂.toIsPresentation.postcomp_injective ext g exact Relations.Solution.congr_var h g include hg₁ in lemma isPresentation : (pres₂.cokernelSolution data).IsPresentation := (isPresentationCore pres₂ data hg₁).isPresentation end cokernelSolution /-- The presentation of the cokernel of a linear map `f : M₁ →ₗ[A] M₂` that is obtained from a presentation `pres₂` of `M₂`, a choice of generators `g₁ : ι → M₁` of `M₁`, and an additional data in `pres₂.CokernelData f g₁`. -/ @[simps!] def cokernel : Presentation A (M₂ ⧸ LinearMap.range f) := ofIsPresentation (cokernelSolution.isPresentation pres₂ data hg₁) end Cokernel /-- Given an exact sequence of `A`-modules `M₁ → M₂ → M₃ → 0`, this is the presentation of `M₃` that is obtained from a presentation `pres₂` of `M₂`, a choice of generators `g₁ : ι → M₁` of `M₁`, and an additional data in a `Presentation.CokernelData` structure. -/ @[simps!] noncomputable def ofExact {f : M₁ →ₗ[A] M₂} {g : M₂ →ₗ[A] M₃} (pres₂ : Presentation.{w₂₀, w₂₁} A M₂) {ι : Type w₁} {g₁ : ι → M₁} (data : pres₂.CokernelData f g₁) (hfg : Function.Exact f g) (hg : Function.Surjective g) (hg₁ : Submodule.span A (Set.range g₁) = ⊤) : Presentation A M₃ := (pres₂.cokernel data hg₁).ofLinearEquiv (hfg.linearEquivOfSurjective hg) end Presentation end Module
.lake/packages/mathlib/Mathlib/Algebra/Module/Presentation/Free.lean
import Mathlib.Algebra.Module.Presentation.Basic import Mathlib.LinearAlgebra.Finsupp.VectorSpace import Mathlib.LinearAlgebra.FreeModule.Basic import Mathlib.Logic.UnivLE /-! # Presentation of free modules A module is free iff it admits a presentation with generators but no relation, see `Module.free_iff_exists_presentation`. -/ assert_not_exists Cardinal universe w w₀ w₁ v u namespace Module variable {A : Type u} [Ring A] (relations : Relations.{w₀, w₁} A) (M : Type v) [AddCommGroup M] [Module A M] namespace Relations variable [IsEmpty relations.R] /-- If `relations : Relations A` involved no relation, then it has an obvious solution in the module `relations.G →₀ A`. -/ @[simps] noncomputable def solutionFinsupp : relations.Solution (relations.G →₀ A) where var g := Finsupp.single g 1 linearCombination_var_relation r := by exfalso; exact IsEmpty.false r /-- If `relations : Relations A` involves no relations (`[IsEmpty relations.R]`), then the free module `relations.G →₀ A` satisfies the universal property of the corresponding module defined by generators (and relations). -/ noncomputable def solutionFinsupp.isPresentationCore : Solution.IsPresentationCore.{w} relations.solutionFinsupp where desc s := Finsupp.linearCombination _ s.var postcomp_desc := by aesop postcomp_injective h := by ext; apply Solution.congr_var h lemma solutionFinsupp_isPresentation : relations.solutionFinsupp.IsPresentation := (solutionFinsupp.isPresentationCore relations).isPresentation variable {relations} lemma Solution.IsPresentation.free {solution : relations.Solution M} (h : solution.IsPresentation) : Module.Free A M := Free.of_equiv ((solutionFinsupp_isPresentation relations).uniq h) end Relations variable (A) /-- The presentation of the `A`-module `G →₀ A` with generators indexed by `G`, and no relation. (Note that there is an auxiliary universe parameter `w₁` for the empty type `R`.) -/ @[simps! G R var] noncomputable def presentationFinsupp (G : Type w₀) : Presentation.{w₀, w₁} A (G →₀ A) where G := G R := PEmpty.{w₁ + 1} relation := by rintro ⟨⟩ toSolution := Relations.solutionFinsupp _ toIsPresentation := by exact Relations.solutionFinsupp_isPresentation _ lemma free_iff_exists_presentation : Free A M ↔ ∃ (p : Presentation.{v, w₁} A M), IsEmpty p.R := by constructor · rw [free_def.{_, _, v}] rintro ⟨G, ⟨⟨e⟩⟩⟩ exact ⟨(presentationFinsupp A G).ofLinearEquiv e.symm, by dsimp; infer_instance⟩ · rintro ⟨p, h⟩ exact p.toIsPresentation.free end Module
.lake/packages/mathlib/Mathlib/Algebra/Module/Presentation/Tensor.lean
import Mathlib.Algebra.Module.Presentation.Basic import Mathlib.LinearAlgebra.TensorProduct.Basic /-! # Presentation of the tensor product of two modules Given presentations of two `A`-modules `M₁` and `M₂`, we obtain a presentation of `M₁ ⊗[A] M₂`. -/ universe w w₁₀ w₁₁ w₂₀ w₂₁ u v₁ v₂ namespace Module open TensorProduct variable {A : Type u} [CommRing A] {M₁ : Type v₁} {M₂ : Type v₂} [AddCommGroup M₁] [AddCommGroup M₂] [Module A M₁] [Module A M₂] namespace Relations variable (relations₁ : Relations.{w₁₀, w₁₁} A) (relations₂ : Relations.{w₂₀, w₂₁} A) /-- The tensor product of systems of linear equations. -/ @[simps] noncomputable def tensor : Relations A where G := relations₁.G × relations₂.G R := Sum (relations₁.R × relations₂.G) (relations₁.G × relations₂.R) relation | .inl ⟨r₁, g₂⟩ => Finsupp.embDomain (Function.Embedding.sectL relations₁.G g₂) (relations₁.relation r₁) | .inr ⟨g₁, r₂⟩ => Finsupp.embDomain (Function.Embedding.sectR g₁ relations₂.G) (relations₂.relation r₂) namespace Solution variable {relations₁ relations₂} (solution₁ : relations₁.Solution M₁) (solution₂ : relations₂.Solution M₂) /-- Given solutions in `M₁` and `M₂` to systems of linear equations, this is the obvious solution to the tensor product of these systems in `M₁ ⊗[A] M₂`. -/ @[simps] noncomputable def tensor : (relations₁.tensor relations₂).Solution (M₁ ⊗[A] M₂) where var := fun ⟨g₁, g₂⟩ => solution₁.var g₁ ⊗ₜ solution₂.var g₂ linearCombination_var_relation := by rintro (⟨r₁, g₂⟩ | ⟨g₁, r₂⟩) · dsimp rw [Finsupp.linearCombination_embDomain] exact (solution₁.postcomp (curry (TensorProduct.comm A M₂ M₁).toLinearMap (solution₂.var g₂))).linearCombination_var_relation r₁ · dsimp rw [Finsupp.linearCombination_embDomain] exact (solution₂.postcomp (curry .id (solution₁.var g₁))).linearCombination_var_relation r₂ variable {solution₁ solution₂} (h₁ : solution₁.IsPresentation) (h₂ : solution₂.IsPresentation) /-- The tensor product of two modules admits a presentation by generators and relations. -/ noncomputable def isPresentationCoreTensor : Solution.IsPresentationCore.{w} (solution₁.tensor solution₂) where desc s := uncurry _ _ _ _ (h₁.desc { var := fun g₁ ↦ h₂.desc { var := fun g₂ ↦ s.var ⟨g₁, g₂⟩ linearCombination_var_relation := fun r₂ ↦ by erw [← Finsupp.linearCombination_embDomain A (Function.Embedding.sectR g₁ relations₂.G)] exact s.linearCombination_var_relation (.inr ⟨g₁, r₂⟩) } linearCombination_var_relation := fun r₁ ↦ h₂.postcomp_injective (by ext g₂ dsimp erw [Finsupp.apply_linearCombination A (LinearMap.applyₗ (solution₂.var g₂))] have := s.linearCombination_var_relation (.inl ⟨r₁, g₂⟩) erw [Finsupp.linearCombination_embDomain] at this convert this ext g₁ simp) }) postcomp_desc _ := by aesop postcomp_injective h := curry_injective (h₁.postcomp_injective (by ext g₁ : 2 refine h₂.postcomp_injective ?_ ext g₂ exact congr_var h ⟨g₁, g₂⟩)) include h₁ h₂ in lemma IsPresentation.tensor : (solution₁.tensor solution₂).IsPresentation := (isPresentationCoreTensor h₁ h₂).isPresentation end Solution end Relations namespace Presentation variable (pres₁ : Presentation.{w₁₀, w₁₁} A M₁) (pres₂ : Presentation.{w₂₀, w₂₁} A M₂) /-- The presentation of the `A`-module `M₁ ⊗[A] M₂` that is deduced from a presentation of `M₁` and a presentation of `M₂`. -/ @[simps!] noncomputable def tensor : Presentation A (M₁ ⊗[A] M₂) where G := _ R := _ relation := _ toSolution := pres₁.toSolution.tensor pres₂.toSolution toIsPresentation := pres₁.toIsPresentation.tensor pres₂.toIsPresentation end Presentation end Module
.lake/packages/mathlib/Mathlib/Algebra/Module/ZLattice/Summable.lean
import Mathlib.Algebra.Module.ZLattice.Basic import Mathlib.Algebra.Order.BigOperators.Group.LocallyFinite import Mathlib.Analysis.PSeries /-! # Convergence of `p`-series on lattices Let `E` be a finite dimensional normed `ℝ`-space, and `L` a discrete subgroup of `E` of rank `d`. We show that `∑ z ∈ L, ‖z - x‖ʳ` is convergent for `r < -d`. ## Main results - `ZLattice.summable_norm_rpow`: `∑ z ∈ L, ‖z‖ʳ` converges when `r < -d`. - `ZLattice.summable_norm_sub_rpow`: `∑ z ∈ L, ‖z - x‖ʳ` converges when `r < -d`. - `ZLattice.tsum_norm_rpow_le`: `∑ z ∈ L, ‖z‖ʳ ≤ Aʳ * ∑ k : ℕ, kᵈ⁺ʳ⁻¹` for some `A > 0` depending only on `L`. -/ noncomputable section open Module variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] variable [FiniteDimensional ℝ E] {L : Submodule ℤ E} [DiscreteTopology L] variable {ι : Type*} (b : Basis ι ℤ L) namespace ZLattice lemma exists_forall_abs_repr_le_norm : ∃ (ε : ℝ), 0 < ε ∧ ∀ (x : L), ∀ i, ε * |b.repr x i| ≤ ‖x‖ := by wlog H : IsZLattice ℝ L · let E' := Submodule.span ℝ (L : Set E) let L' : Submodule ℤ E' := ZLattice.comap ℝ L E'.subtype have inst : DiscreteTopology L' := comap_discreteTopology _ _ (by fun_prop) Subtype.val_injective let e : L' ≃ₗ[ℤ] L := Submodule.comapSubtypeEquivOfLe (p := L) (q := E'.restrictScalars ℤ) Submodule.subset_span have inst : IsZLattice ℝ L' := ⟨Submodule.map_injective_of_injective E'.subtype_injective (by simp [E', L'])⟩ obtain ⟨ε, hε, H⟩ := this (b.map e.symm) inst exact ⟨ε, hε, fun x i ↦ by simpa using H ⟨⟨x.1, Submodule.subset_span x.2⟩, x.2⟩ i⟩ have : Finite ι := Module.Finite.finite_basis b let b' : Basis ι ℝ E := Basis.ofZLatticeBasis ℝ L b let e := ((b'.repr ≪≫ₗ Finsupp.linearEquivFunOnFinite _ _ _).toContinuousLinearEquiv (𝕜 := ℝ)) have := e.continuous.1 (Set.univ.pi fun _ ↦ Set.Ioo (-1) 1) (isOpen_set_pi Set.finite_univ fun _ _ ↦ isOpen_Ioo) obtain ⟨ε, hε, hε'⟩ := Metric.isOpen_iff.mp this 0 (by simp) refine ⟨ε / 2, by positivity, fun x i ↦ ?_⟩ by_cases hx : x = 0 · simp [hx] have hx : ‖x.1‖ ≠ 0 := by simpa have : |ε / 2 * (‖↑x‖⁻¹ * (b.repr x) i)| < 1 := by simpa [e, b', ← abs_lt] using @hε' ((ε / 2) • ‖x‖⁻¹ • x) (by simpa [norm_smul, inv_mul_cancel₀ hx, abs_eq_self.mpr hε.le]) i trivial rw [abs_mul, abs_mul, abs_inv, mul_left_comm, abs_norm, inv_mul_lt_iff₀ (by positivity), mul_one, abs_eq_self.mpr (by positivity), ← Int.cast_abs] at this exact this.le /-- Given a basis of a (possibly not full rank) `ℤ`-lattice, there exists a `ε > 0` such that `|b.repr x i| < n` for all `‖x‖ < n * ε` (i.e. `b.repr x i = O(x)` depending only on `b`). This is an arbitrary choice of such an `ε`. -/ def normBound {ι : Type*} (b : Basis ι ℤ L) : ℝ := (exists_forall_abs_repr_le_norm b).choose lemma normBound_pos {ι : Type*} (b : Basis ι ℤ L) : 0 < normBound b := (exists_forall_abs_repr_le_norm b).choose_spec.1 lemma normBound_spec {ι : Type*} (b : Basis ι ℤ L) (x : L) (i : ι) : normBound b * |b.repr x i| ≤ ‖x‖ := (exists_forall_abs_repr_le_norm b).choose_spec.2 x i lemma abs_repr_le {ι : Type*} (b : Basis ι ℤ L) (x : L) (i : ι) : |b.repr x i| ≤ (normBound b)⁻¹ * ‖x‖ := by rw [le_inv_mul_iff₀ (normBound_pos b)] exact normBound_spec b x i lemma abs_repr_lt_of_norm_lt {ι : Type*} (b : Basis ι ℤ L) (x : L) (n : ℕ) (hxn : ‖x‖ < normBound b * n) (i : ι) : |b.repr x i| < n := by refine Int.cast_lt.mp ((abs_repr_le b x i).trans_lt ?_) rwa [inv_mul_lt_iff₀ (normBound_pos b)] lemma le_norm_of_le_abs_repr {ι : Type*} (b : Basis ι ℤ L) (x : L) (n : ℕ) (i : ι) (hi : n ≤ |b.repr x i|) : normBound b * n ≤ ‖x‖ := by contrapose! hi exact abs_repr_lt_of_norm_lt b x n hi i open Finset in lemma sum_piFinset_Icc_rpow_le {ι : Type*} [Fintype ι] [DecidableEq ι] (b : Basis ι ℤ L) {d : ℕ} (hd : d = Fintype.card ι) (n : ℕ) (r : ℝ) (hr : r < -d) : ∑ p ∈ Fintype.piFinset fun _ : ι ↦ Icc (-n : ℤ) n, ‖∑ i, p i • b i‖ ^ r ≤ 2 * d * 3 ^ (d - 1) * normBound b ^ r * ∑' k : ℕ, (k : ℝ) ^ (d - 1 + r) := by let s (n : ℕ) := Fintype.piFinset fun i : ι ↦ Icc (-n : ℤ) n subst hd set d := Fintype.card ι have hr' : r < 0 := hr.trans_le (by linarith) by_cases hd : d = 0 · have : IsEmpty ι := Fintype.card_eq_zero_iff.mp hd simp [hd, hr'.ne] replace hd : 1 ≤ d := by rwa [Nat.one_le_iff_ne_zero] have hs0 : s 0 = {0} := by ext; simp [s, funext_iff] have hs {a b : ℕ} (ha : a ≤ b) : s a ⊆ s b := by intros x hx simp only [Fintype.mem_piFinset, s] at hx ⊢ exact fun i ↦ Icc_subset_Icc (by simpa) (by simpa) (hx i) have (k : ℕ) : #(s (k + 1) \ s k) ≤ 2 * d * (2 * k + 3) ^ (d - 1) := by trans (2 * k + 3) ^ d - (2 * k + 1) ^ d · simp only [le_add_iff_nonneg_right, zero_le, hs, card_sdiff_of_subset, s] simp only [Fintype.card_piFinset, Int.card_Icc, sub_neg_eq_add, prod_const, card_univ] gcongr <;> norm_cast <;> omega · have := abs_pow_sub_pow_le (α := ℤ) ↑(2 * k + 3) ↑(2 * k + 1) d norm_num at this zify convert this using 3 · rw [abs_eq_self.mpr (sub_nonneg.mpr (by gcongr; omega)), Nat.cast_sub (by gcongr; omega)] simp · rw [max_eq_left (by gcongr; omega), abs_eq_self.mpr (by positivity)] let ε := normBound b have hε : 0 < ε := normBound_pos b calc ∑ p ∈ s n, ‖∑ i, p i • b i‖ ^ r = ∑ k ∈ range n, ∑ p ∈ (s (k + 1) \ s k), ‖∑ i, p i • b i‖ ^ r := by simp [Finset.sum_eq_sum_range_sdiff _ @hs, hs0, hr'.ne] _ ≤ ∑ k ∈ range n, ∑ p ∈ (s (k + 1) \ s k), ((k + 1) * ε) ^ r := by gcongr ∑ k ∈ Finset.range n, ∑ p ∈ (s (k + 1) \ s k), ?_ with k hk v hv rw [← Nat.cast_one, ← Nat.cast_add] refine Real.rpow_le_rpow_of_nonpos (by positivity) ?_ hr'.le obtain ⟨j, hj⟩ : ∃ i, v i ∉ Icc (-k : ℤ) k := by simpa [s] using (mem_sdiff.mp hv).2 refine mul_comm _ ε ▸ le_norm_of_le_abs_repr b _ _ j ?_ suffices ↑k + 1 ≤ |v j| by simpa [Finsupp.single_apply] using this by_contra! H rw [Int.lt_add_one_iff, abs_le, ← Finset.mem_Icc] at H exact hj H _ ≤ ∑ k ∈ range n, ↑(2 * d * (3 * (k + 1)) ^ (d - 1)) * ((k + 1) * ε) ^ r := by simp only [sum_const, nsmul_eq_mul] gcongr with k hk refine (this _).trans ?_ gcongr omega _ = 2 * d * 3 ^ (d - 1) * ε ^ r * ∑ k ∈ range n, (k + 1) ^ (d - 1) * (k + 1 : ℝ) ^ r := by simp_rw [Finset.mul_sum] congr with k push_cast rw [Real.mul_rpow (by positivity) (by positivity), mul_pow] group _ = 2 * d * 3 ^ (d - 1) * ε ^ r * ∑ k ∈ range n, (↑(k + 1) : ℝ) ^ (d - 1 + r) := by congr with k rw [← Real.rpow_natCast, ← Real.rpow_add (by positivity), Nat.cast_sub hd] norm_cast _ ≤ 2 * d * 3 ^ (d - 1) * ε ^ r * ∑ k ∈ range (n + 1), (k : ℝ) ^ (d - 1 + r) := by gcongr rw [Finset.sum_range_succ', le_add_iff_nonneg_right] positivity _ ≤ 2 * d * 3 ^ (d - 1) * ε ^ r * ∑' k : ℕ, (k : ℝ) ^ (d - 1 + r) := by gcongr refine Summable.sum_le_tsum _ (fun _ _ ↦ by positivity) (Real.summable_nat_rpow.mpr ?_) linarith variable (L) lemma exists_finsetSum_norm_rpow_le_tsum : ∃ A > (0 : ℝ), ∀ r < (-Module.finrank ℤ L : ℝ), ∀ s : Finset L, ∑ z ∈ s, ‖z‖ ^ r ≤ A ^ r * ∑' k : ℕ, (k : ℝ) ^ (Module.finrank ℤ L - 1 + r) := by classical cases subsingleton_or_nontrivial L · refine ⟨1, zero_lt_one, fun r hr s ↦ ?_⟩ have hr : r ≠ 0 := by linarith simpa [Subsingleton.elim _ (0 : L), Real.zero_rpow hr] using tsum_nonneg fun _ ↦ by positivity classical let I : Type _ := Module.Free.ChooseBasisIndex ℤ L have : Fintype I := inferInstance let b : Basis I ℤ L := Module.Free.chooseBasis ℤ L simp_rw [Module.finrank_eq_card_basis b] set d := Fintype.card I have hd : d ≠ 0 := by simp [d] let ε := normBound b obtain ⟨A, hA, B, hB, H⟩ : ∃ A > (0 : ℝ), ∃ B > (0 : ℝ), ∀ r < (-d : ℝ), ∀ s : Finset L, ∑ z ∈ s, ‖z‖ ^ r ≤ A * B ^ r * ∑' k : ℕ, (k : ℝ) ^ (d - 1 + r) := by refine ⟨2 * d * 3 ^ (d - 1), by positivity, ε, normBound_pos b, fun r hr u ↦ ?_⟩ let e : (I → ℤ) ≃ₗ[ℤ] L := (b.repr ≪≫ₗ Finsupp.linearEquivFunOnFinite _ _ _).symm obtain ⟨u, rfl⟩ : ∃ u' : Finset _, u = u'.image e.toEmbedding := ⟨u.image e.symm.toEmbedding, Finset.coe_injective (by simpa using (e.image_symm_image _).symm)⟩ dsimp simp only [EmbeddingLike.apply_eq_iff_eq, implies_true, Set.injOn_of_eq_iff_eq, Finset.sum_image, ge_iff_le] obtain ⟨n, hn⟩ : ∃ n : ℕ, u ⊆ Fintype.piFinset fun _ : I ↦ Finset.Icc (-n : ℤ) n := by obtain ⟨r, hr, hr'⟩ := u.finite_toSet.isCompact.isBounded.subset_closedBall_lt 0 0 refine ⟨⌊r⌋.toNat, fun x hx ↦ ?_⟩ have hr'' : ⌊r⌋ ⊔ 0 = ⌊r⌋ := by simp; positivity have := hr' hx simp only [Metric.mem_closedBall, dist_zero_right, pi_norm_le_iff_of_nonneg hr.le, Int.norm_eq_abs, ← Int.cast_abs, ← Int.le_floor] at this simpa only [Int.ofNat_toNat, Fintype.mem_piFinset, Finset.mem_Icc, ← abs_le, hr''] refine (Finset.sum_le_sum_of_subset_of_nonneg hn (by intros; positivity)).trans ?_ dsimp simp only [Submodule.norm_coe] convert sum_piFinset_Icc_rpow_le b rfl n r hr with x simp [e, Finsupp.linearCombination] rfl by_cases hA' : A ≤ 1 · refine ⟨B, hB, fun r hr s ↦ (H r hr s).trans ?_⟩ rw [mul_assoc] exact mul_le_of_le_one_left (mul_nonneg (by positivity) (by positivity)) hA' · refine ⟨A⁻¹ * B, mul_pos (inv_pos.mpr hA) hB, fun r hr s ↦ (H r hr s).trans ?_⟩ rw [Real.mul_rpow (inv_pos.mpr hA).le hB.le, mul_assoc, mul_assoc] refine mul_le_mul_of_nonneg_right ?_ (mul_nonneg (by positivity) (by positivity)) rw [← Real.rpow_neg_one, ← Real.rpow_mul hA.le] refine Real.self_le_rpow_of_one_le (not_le.mp hA').le ?_ simp only [neg_mul, one_mul, le_neg (b := r)] refine hr.le.trans ?_ norm_num exact Nat.one_le_iff_ne_zero.mpr hd /-- Let `L` be a lattice with (possibly non-full) rank `d`, and `r : ℝ` such that `d < r`. Then `∑ z ∈ L, ‖z‖⁻ʳ ≤ A⁻ʳ * ∑ k : ℕ, kᵈ⁻ʳ⁻¹` for some `A > 0` depending only on `L`. This is an arbitrary choice of `A`. See `ZLattice.tsum_norm_rpow_le`. -/ def tsumNormRPowBound : ℝ := (exists_finsetSum_norm_rpow_le_tsum L).choose lemma tsumNormRPowBound_pos : 0 < tsumNormRPowBound L := (exists_finsetSum_norm_rpow_le_tsum L).choose_spec.1 lemma tsumNormRPowBound_spec (r : ℝ) (h : r < -Module.finrank ℤ L) (s : Finset L) : ∑ z ∈ s, ‖z‖ ^ r ≤ tsumNormRPowBound L ^ r * ∑' k : ℕ, (k : ℝ) ^ (Module.finrank ℤ L - 1 + r) := (exists_finsetSum_norm_rpow_le_tsum L).choose_spec.2 r h s /-- If `L` is a `ℤ`-lattice with rank `d` in `E`, then `∑ z ∈ L, ‖z‖ʳ` converges when `r < -d`. -/ lemma summable_norm_rpow (r : ℝ) (hr : r < -Module.finrank ℤ L) : Summable fun z : L ↦ ‖z‖ ^ r := summable_of_sum_le (fun _ ↦ by positivity) (tsumNormRPowBound_spec L r hr) /-- `∑ z ∈ L, ‖z‖⁻ʳ ≤ A⁻ʳ * ∑ k : ℕ, kᵈ⁻ʳ⁻¹` for some `A > 0` depending only on `L`. -/ lemma tsum_norm_rpow_le (r : ℝ) (hr : r < -Module.finrank ℤ L) : ∑' z : L, ‖z‖ ^ r ≤ tsumNormRPowBound L ^ r * ∑' k : ℕ, (k : ℝ) ^ (Module.finrank ℤ L - 1 + r) := Summable.tsum_le_of_sum_le (summable_norm_rpow L r hr) (tsumNormRPowBound_spec L r hr) lemma summable_norm_sub_rpow (r : ℝ) (hr : r < -Module.finrank ℤ L) (x : E) : Summable fun z : L ↦ ‖z - x‖ ^ r := by cases subsingleton_or_nontrivial L · exact .of_finite refine Summable.of_norm_bounded_eventually (.mul_left ((1 / 2) ^ r) (summable_norm_rpow L r hr)) ?_ have H : IsClosed (X := E) L := @AddSubgroup.isClosed_of_discrete _ _ _ _ _ L.toAddSubgroup (inferInstanceAs (DiscreteTopology L)) refine ((Metric.finite_isBounded_inter_isClosed (Metric.isBounded_closedBall (x := (0 : E)) (r := 2 * ‖x‖)) H).preimage_embedding (.subtype _)).subset ?_ intro t ht by_cases ht₁ : ‖t‖ = 0 · simp [show t = 0 by simpa using ht₁] by_cases ht₂ : ‖t - x‖ = 0 · simpa [show t = x by simpa [sub_eq_zero] using ht₂, two_mul] using t.2 have : 0 < Module.finrank ℤ L := Module.finrank_pos have : ‖t - x‖ < 2⁻¹ * ‖t‖ := by rw [← Real.rpow_lt_rpow_iff_of_neg (by positivity) (by positivity) (hr.trans (by simpa))] simpa [Real.mul_rpow, abs_eq_self.mpr (show 0 ≤ ‖t - x‖ ^ r by positivity)] using ht have := (norm_sub_norm_le _ _).trans_lt this rw [sub_lt_iff_lt_add, ← sub_lt_iff_lt_add', AddSubgroupClass.coe_norm] at this simpa using show ‖t.1‖ ≤ 2 * ‖x‖ by linarith lemma summable_norm_sub_zpow (n : ℤ) (hn : n < -Module.finrank ℤ L) (x : E) : Summable fun z : L ↦ ‖z - x‖ ^ n := mod_cast summable_norm_sub_rpow L n (mod_cast hn) x lemma summable_norm_zpow (n : ℤ) (hn : n < -Module.finrank ℤ L) : Summable fun z : L ↦ ‖z‖ ^ n := by simpa using summable_norm_sub_zpow L n hn 0 lemma summable_norm_sub_inv_pow (n : ℕ) (hn : Module.finrank ℤ L < n) (x : E) : Summable fun z : L ↦ ‖z - x‖⁻¹ ^ n := by simpa using summable_norm_sub_zpow L (-n) (by gcongr) x lemma summable_norm_pow_inv (n : ℕ) (hn : Module.finrank ℤ L < n) : Summable fun z : L ↦ ‖z‖⁻¹ ^ n := by simpa using summable_norm_sub_inv_pow L n hn 0 end ZLattice
.lake/packages/mathlib/Mathlib/Algebra/Module/ZLattice/Basic.lean
import Mathlib.LinearAlgebra.Countable import Mathlib.LinearAlgebra.FreeModule.PID import Mathlib.MeasureTheory.Group.FundamentalDomain import Mathlib.MeasureTheory.Measure.Lebesgue.EqHaar import Mathlib.RingTheory.Localization.Module /-! # ℤ-lattices Let `E` be a finite-dimensional vector space over a `NormedLinearOrderedField` `K` with a solid norm that is also a `FloorRing`, e.g. `ℝ`. A (full) `ℤ`-lattice `L` of `E` is a discrete subgroup of `E` such that `L` spans `E` over `K`. A `ℤ`-lattice `L` can be defined in two ways: * For `b` a basis of `E`, then `L = Submodule.span ℤ (Set.range b)` is a ℤ-lattice of `E` * As a `ℤ-submodule` of `E` with the additional properties: * `DiscreteTopology L`, that is `L` is discrete * `Submodule.span ℝ (L : Set E) = ⊤`, that is `L` spans `E` over `K`. Results about the first point of view are in the `ZSpan` namespace and results about the second point of view are in the `ZLattice` namespace. ## Main results and definitions * `ZSpan.isAddFundamentalDomain`: for a ℤ-lattice `Submodule.span ℤ (Set.range b)`, proves that the set defined by `ZSpan.fundamentalDomain` is a fundamental domain. * `ZLattice.module_free`: a `ℤ`-submodule of `E` that is discrete and spans `E` over `K` is a free `ℤ`-module * `ZLattice.rank`: a `ℤ`-submodule of `E` that is discrete and spans `E` over `K` is free of `ℤ`-rank equal to the `K`-rank of `E` * `ZLattice.comap`: for `e : E → F` a linear map and `L : Submodule ℤ E`, define the pullback of `L` by `e`. If `L` is a `IsZLattice` and `e` is a continuous linear equiv, then it is also a `IsZLattice`, see `instIsZLatticeComap`. ## Note There is also `Submodule.IsLattice` which has slightly different applications. There no topology is needed and the discrete condition is replaced by finitely generated. ## Implementation Notes A `ZLattice` could be defined either as a `AddSubgroup E` or a `Submodule ℤ E`. However, the module aspect appears to be the more useful one (especially in computations involving basis) and is also consistent with the `ZSpan` construction of `ℤ`-lattices. -/ noncomputable section namespace ZSpan open MeasureTheory MeasurableSet Module Submodule Bornology variable {E ι : Type*} section NormedLatticeField variable {K : Type*} [NormedField K] variable [NormedAddCommGroup E] [NormedSpace K E] variable (b : Basis ι K E) theorem span_top : span K (span ℤ (Set.range b) : Set E) = ⊤ := by simp [span_span_of_tower] theorem map {F : Type*} [AddCommGroup F] [Module K F] (f : E ≃ₗ[K] F) : Submodule.map (f.restrictScalars ℤ) (span ℤ (Set.range b)) = span ℤ (Set.range (b.map f)) := by simp_rw [Submodule.map_span, LinearEquiv.restrictScalars_apply, Basis.coe_map, Set.range_comp] open scoped Pointwise in theorem smul {c : K} (hc : c ≠ 0) : c • span ℤ (Set.range b) = span ℤ (Set.range (b.isUnitSMul (fun _ ↦ hc.isUnit))) := by rw [smul_span, Set.smul_set_range] congr! rw [Basis.isUnitSMul_apply] variable [LinearOrder K] /-- The fundamental domain of the ℤ-lattice spanned by `b`. See `ZSpan.isAddFundamentalDomain` for the proof that it is a fundamental domain. -/ def fundamentalDomain : Set E := {m | ∀ i, b.repr m i ∈ Set.Ico (0 : K) 1} @[simp] theorem mem_fundamentalDomain {m : E} : m ∈ fundamentalDomain b ↔ ∀ i, b.repr m i ∈ Set.Ico (0 : K) 1 := Iff.rfl theorem map_fundamentalDomain {F : Type*} [NormedAddCommGroup F] [NormedSpace K F] (f : E ≃ₗ[K] F) : f '' (fundamentalDomain b) = fundamentalDomain (b.map f) := by ext x rw [mem_fundamentalDomain, Basis.map_repr, LinearEquiv.trans_apply, ← mem_fundamentalDomain, show f.symm x = f.toEquiv.symm x by rfl, ← Set.mem_image_equiv] rfl @[simp] theorem fundamentalDomain_reindex {ι' : Type*} (e : ι ≃ ι') : fundamentalDomain (b.reindex e) = fundamentalDomain b := by ext simp_rw [mem_fundamentalDomain, Basis.repr_reindex_apply] rw [Equiv.forall_congr' e] simp_rw [implies_true] variable [IsStrictOrderedRing K] lemma fundamentalDomain_pi_basisFun [Fintype ι] : fundamentalDomain (Pi.basisFun ℝ ι) = Set.pi Set.univ fun _ : ι ↦ Set.Ico (0 : ℝ) 1 := by ext; simp variable [FloorRing K] section Fintype variable [Fintype ι] /-- The map that sends a vector of `E` to the element of the ℤ-lattice spanned by `b` obtained by rounding down its coordinates on the basis `b`. -/ def floor (m : E) : span ℤ (Set.range b) := ∑ i, ⌊b.repr m i⌋ • b.restrictScalars ℤ i /-- The map that sends a vector of `E` to the element of the ℤ-lattice spanned by `b` obtained by rounding up its coordinates on the basis `b`. -/ def ceil (m : E) : span ℤ (Set.range b) := ∑ i, ⌈b.repr m i⌉ • b.restrictScalars ℤ i @[simp] theorem repr_floor_apply (m : E) (i : ι) : b.repr (floor b m) i = ⌊b.repr m i⌋ := by classical simp only [floor, ← Int.cast_smul_eq_zsmul K, b.repr.map_smul, Finsupp.single_apply, Finset.sum_apply', Basis.repr_self, Finsupp.smul_single', mul_one, Finset.sum_ite_eq', coe_sum, Finset.mem_univ, if_true, coe_smul_of_tower, Basis.restrictScalars_apply, map_sum] @[simp] theorem repr_ceil_apply (m : E) (i : ι) : b.repr (ceil b m) i = ⌈b.repr m i⌉ := by classical simp only [ceil, ← Int.cast_smul_eq_zsmul K, b.repr.map_smul, Finsupp.single_apply, Finset.sum_apply', Basis.repr_self, Finsupp.smul_single', mul_one, Finset.sum_ite_eq', coe_sum, Finset.mem_univ, if_true, coe_smul_of_tower, Basis.restrictScalars_apply, map_sum] @[simp] theorem floor_eq_self_of_mem (m : E) (h : m ∈ span ℤ (Set.range b)) : (floor b m : E) = m := by apply b.ext_elem simp_rw [repr_floor_apply b] intro i obtain ⟨z, hz⟩ := (b.mem_span_iff_repr_mem ℤ _).mp h i rw [← hz] exact congr_arg (Int.cast : ℤ → K) (Int.floor_intCast z) @[simp] theorem ceil_eq_self_of_mem (m : E) (h : m ∈ span ℤ (Set.range b)) : (ceil b m : E) = m := by apply b.ext_elem simp_rw [repr_ceil_apply b] intro i obtain ⟨z, hz⟩ := (b.mem_span_iff_repr_mem ℤ _).mp h i rw [← hz] exact congr_arg (Int.cast : ℤ → K) (Int.ceil_intCast z) /-- The map that sends a vector `E` to the `fundamentalDomain` of the lattice, see `ZSpan.fract_mem_fundamentalDomain`, and `fractRestrict` for the map with the codomain restricted to `fundamentalDomain`. -/ def fract (m : E) : E := m - floor b m theorem fract_apply (m : E) : fract b m = m - floor b m := rfl @[simp] theorem repr_fract_apply (m : E) (i : ι) : b.repr (fract b m) i = Int.fract (b.repr m i) := by rw [fract, map_sub, Finsupp.coe_sub, Pi.sub_apply, repr_floor_apply, Int.fract] @[simp] theorem fract_fract (m : E) : fract b (fract b m) = fract b m := Basis.ext_elem b fun _ => by classical simp only [repr_fract_apply, Int.fract_fract] @[simp] theorem fract_zSpan_add (m : E) {v : E} (h : v ∈ span ℤ (Set.range b)) : fract b (v + m) = fract b m := by classical refine (Basis.ext_elem_iff b).mpr fun i => ?_ simp_rw [repr_fract_apply, Int.fract_eq_fract] use (b.restrictScalars ℤ).repr ⟨v, h⟩ i rw [map_add, Finsupp.coe_add, Pi.add_apply, add_tsub_cancel_right, ← eq_intCast (algebraMap ℤ K) _, Basis.restrictScalars_repr_apply, coe_mk] @[simp] theorem fract_add_ZSpan (m : E) {v : E} (h : v ∈ span ℤ (Set.range b)) : fract b (m + v) = fract b m := by rw [add_comm, fract_zSpan_add b m h] variable {b} in theorem fract_eq_self {x : E} : fract b x = x ↔ x ∈ fundamentalDomain b := by classical simp only [Basis.ext_elem_iff b, repr_fract_apply, Int.fract_eq_self, mem_fundamentalDomain, Set.mem_Ico] theorem fract_mem_fundamentalDomain (x : E) : fract b x ∈ fundamentalDomain b := fract_eq_self.mp (fract_fract b _) /-- The map `fract` with codomain restricted to `fundamentalDomain`. -/ def fractRestrict (x : E) : fundamentalDomain b := ⟨fract b x, fract_mem_fundamentalDomain b x⟩ theorem fractRestrict_surjective : Function.Surjective (fractRestrict b) := fun x => ⟨↑x, Subtype.eq (fract_eq_self.mpr (Subtype.mem x))⟩ @[simp] theorem fractRestrict_apply (x : E) : (fractRestrict b x : E) = fract b x := rfl theorem fract_eq_fract (m n : E) : fract b m = fract b n ↔ -m + n ∈ span ℤ (Set.range b) := by classical rw [eq_comm, Basis.ext_elem_iff b] simp_rw [repr_fract_apply, Int.fract_eq_fract, eq_comm, Basis.mem_span_iff_repr_mem, sub_eq_neg_add, map_add, map_neg, Finsupp.coe_add, Finsupp.coe_neg, Pi.add_apply, Pi.neg_apply, ← eq_intCast (algebraMap ℤ K) _, Set.mem_range] theorem norm_fract_le [HasSolidNorm K] (m : E) : ‖fract b m‖ ≤ ∑ i, ‖b i‖ := by classical calc ‖fract b m‖ = ‖∑ i, b.repr (fract b m) i • b i‖ := by rw [b.sum_repr] _ = ‖∑ i, Int.fract (b.repr m i) • b i‖ := by simp_rw [repr_fract_apply] _ ≤ ∑ i, ‖Int.fract (b.repr m i) • b i‖ := norm_sum_le _ _ _ = ∑ i, ‖Int.fract (b.repr m i)‖ * ‖b i‖ := by simp_rw [norm_smul] _ ≤ ∑ i, ‖b i‖ := Finset.sum_le_sum fun i _ => ?_ suffices ‖Int.fract ((b.repr m) i)‖ ≤ 1 by convert mul_le_mul_of_nonneg_right this (norm_nonneg _ : 0 ≤ ‖b i‖) exact (one_mul _).symm rw [(norm_one.symm : 1 = ‖(1 : K)‖)] apply norm_le_norm_of_abs_le_abs rw [abs_one, Int.abs_fract] exact le_of_lt (Int.fract_lt_one _) section Unique variable [Unique ι] @[simp] theorem coe_floor_self (k : K) : (floor (Basis.singleton ι K) k : K) = ⌊k⌋ := Basis.ext_elem (Basis.singleton ι K) fun _ => by rw [repr_floor_apply, Basis.singleton_repr, Basis.singleton_repr] @[simp] theorem coe_fract_self (k : K) : (fract (Basis.singleton ι K) k : K) = Int.fract k := Basis.ext_elem (Basis.singleton ι K) fun _ => by rw [repr_fract_apply, Basis.singleton_repr, Basis.singleton_repr] end Unique end Fintype theorem fundamentalDomain_isBounded [Finite ι] [HasSolidNorm K] : IsBounded (fundamentalDomain b) := by cases nonempty_fintype ι refine isBounded_iff_forall_norm_le.2 ⟨∑ j, ‖b j‖, fun x hx ↦ ?_⟩ rw [← fract_eq_self.mpr hx] apply norm_fract_le theorem vadd_mem_fundamentalDomain [Fintype ι] (y : span ℤ (Set.range b)) (x : E) : y +ᵥ x ∈ fundamentalDomain b ↔ y = -floor b x := by rw [Subtype.ext_iff, ← add_right_inj x, NegMemClass.coe_neg, ← sub_eq_add_neg, ← fract_apply, ← fract_zSpan_add b _ (Subtype.mem y), add_comm, ← vadd_eq_add, ← vadd_def, eq_comm, ← fract_eq_self] theorem exist_unique_vadd_mem_fundamentalDomain [Finite ι] (x : E) : ∃! v : span ℤ (Set.range b), v +ᵥ x ∈ fundamentalDomain b := by cases nonempty_fintype ι refine ⟨-floor b x, ?_, fun y h => ?_⟩ · exact (vadd_mem_fundamentalDomain b (-floor b x) x).mpr rfl · exact (vadd_mem_fundamentalDomain b y x).mp h /-- The map `ZSpan.fractRestrict` defines an equiv map between `E ⧸ span ℤ (Set.range b)` and `ZSpan.fundamentalDomain b`. -/ def quotientEquiv [Fintype ι] : E ⧸ span ℤ (Set.range b) ≃ (fundamentalDomain b) := by refine Equiv.ofBijective ?_ ⟨fun x y => ?_, fun x => ?_⟩ · refine fun q => Quotient.liftOn q (fractRestrict b) (fun _ _ h => ?_) rw [Subtype.mk.injEq, fractRestrict_apply, fractRestrict_apply, fract_eq_fract] exact QuotientAddGroup.leftRel_apply.mp h · refine Quotient.inductionOn₂ x y (fun _ _ hxy => ?_) rw [Quotient.liftOn_mk (s := quotientRel (span ℤ (Set.range b))), fractRestrict, Quotient.liftOn_mk (s := quotientRel (span ℤ (Set.range b))), fractRestrict, Subtype.mk.injEq] at hxy apply Quotient.sound' rwa [QuotientAddGroup.leftRel_apply, mem_toAddSubgroup, ← fract_eq_fract] · obtain ⟨a, rfl⟩ := fractRestrict_surjective b x exact ⟨Quotient.mk'' a, rfl⟩ @[simp] theorem quotientEquiv_apply_mk [Fintype ι] (x : E) : quotientEquiv b (Submodule.Quotient.mk x) = fractRestrict b x := rfl @[simp] theorem quotientEquiv.symm_apply [Fintype ι] (x : fundamentalDomain b) : (quotientEquiv b).symm x = Submodule.Quotient.mk ↑x := by rw [Equiv.symm_apply_eq, quotientEquiv_apply_mk b ↑x, Subtype.ext_iff, fractRestrict_apply] exact (fract_eq_self.mpr x.prop).symm end NormedLatticeField section Real theorem discreteTopology_pi_basisFun [Finite ι] : DiscreteTopology (span ℤ (Set.range (Pi.basisFun ℝ ι))) := by cases nonempty_fintype ι refine discreteTopology_iff_isOpen_singleton_zero.mpr ⟨Metric.ball 0 1, Metric.isOpen_ball, ?_⟩ ext x rw [Set.mem_preimage, mem_ball_zero_iff, pi_norm_lt_iff zero_lt_one, Set.mem_singleton_iff] simp_rw [← coe_eq_zero, funext_iff, Pi.zero_apply, Real.norm_eq_abs] refine forall_congr' (fun i => ?_) rsuffices ⟨y, hy⟩ : ∃ (y : ℤ), (y : ℝ) = (x : ι → ℝ) i · rw [← hy, ← Int.cast_abs, ← Int.cast_one, Int.cast_lt, Int.abs_lt_one_iff, Int.cast_eq_zero] exact ((Pi.basisFun ℝ ι).mem_span_iff_repr_mem ℤ x).mp (SetLike.coe_mem x) i variable [NormedAddCommGroup E] [NormedSpace ℝ E] (b : Basis ι ℝ E) theorem fundamentalDomain_subset_parallelepiped [Fintype ι] : fundamentalDomain b ⊆ parallelepiped b := by rw [fundamentalDomain, parallelepiped_basis_eq, Set.setOf_subset_setOf] exact fun _ h i ↦ Set.Ico_subset_Icc_self (h i) instance [Finite ι] : DiscreteTopology (span ℤ (Set.range b)) := by have h : Set.MapsTo b.equivFun (span ℤ (Set.range b)) (span ℤ (Set.range (Pi.basisFun ℝ ι))) := by intro _ hx rwa [SetLike.mem_coe, Basis.mem_span_iff_repr_mem] at hx ⊢ convert DiscreteTopology.of_continuous_injective ((continuous_equivFun_basis b).restrict h) ?_ · exact discreteTopology_pi_basisFun · refine Subtype.map_injective _ (Basis.equivFun b).injective instance [Finite ι] : DiscreteTopology (span ℤ (Set.range b)).toAddSubgroup := inferInstanceAs <| DiscreteTopology (span ℤ (Set.range b)) theorem setFinite_inter [ProperSpace E] [Finite ι] {s : Set E} (hs : Bornology.IsBounded s) : Set.Finite (s ∩ span ℤ (Set.range b)) := by have : DiscreteTopology (span ℤ (Set.range b)) := inferInstance refine Metric.finite_isBounded_inter_isClosed hs ?_ rw [← coe_toAddSubgroup] exact AddSubgroup.isClosed_of_discrete @[measurability] theorem fundamentalDomain_measurableSet [MeasurableSpace E] [OpensMeasurableSpace E] [Finite ι] : MeasurableSet (fundamentalDomain b) := by cases nonempty_fintype ι haveI : FiniteDimensional ℝ E := b.finiteDimensional_of_finite let D : Set (ι → ℝ) := Set.pi Set.univ fun _ : ι => Set.Ico (0 : ℝ) 1 rw [(_ : fundamentalDomain b = b.equivFun.toLinearMap ⁻¹' D)] · refine measurableSet_preimage (LinearMap.continuous_of_finiteDimensional _).measurable ?_ exact MeasurableSet.pi Set.countable_univ fun _ _ => measurableSet_Ico · ext simp only [D, fundamentalDomain, Set.mem_Ico, Set.mem_setOf_eq, LinearEquiv.coe_coe, Set.mem_preimage, Basis.equivFun_apply, Set.mem_pi, Set.mem_univ, forall_true_left] /-- For a ℤ-lattice `Submodule.span ℤ (Set.range b)`, proves that the set defined by `ZSpan.fundamentalDomain` is a fundamental domain. -/ protected theorem isAddFundamentalDomain [Finite ι] [MeasurableSpace E] [OpensMeasurableSpace E] (μ : Measure E) : IsAddFundamentalDomain (span ℤ (Set.range b)) (fundamentalDomain b) μ := by cases nonempty_fintype ι exact IsAddFundamentalDomain.mk' (nullMeasurableSet (fundamentalDomain_measurableSet b)) fun x => exist_unique_vadd_mem_fundamentalDomain b x /-- A version of `ZSpan.isAddFundamentalDomain` for `AddSubgroup`. -/ protected theorem isAddFundamentalDomain' [Finite ι] [MeasurableSpace E] [OpensMeasurableSpace E] (μ : Measure E) : IsAddFundamentalDomain (span ℤ (Set.range b)).toAddSubgroup (fundamentalDomain b) μ := ZSpan.isAddFundamentalDomain b μ theorem measure_fundamentalDomain_ne_zero [Finite ι] [MeasurableSpace E] [BorelSpace E] {μ : Measure E} [Measure.IsAddHaarMeasure μ] : μ (fundamentalDomain b) ≠ 0 := by convert (ZSpan.isAddFundamentalDomain b μ).measure_ne_zero (NeZero.ne μ) exact inferInstanceAs <| VAddInvariantMeasure (span ℤ (Set.range b)).toAddSubgroup E μ theorem measure_fundamentalDomain [Fintype ι] [DecidableEq ι] [MeasurableSpace E] (μ : Measure E) [BorelSpace E] [Measure.IsAddHaarMeasure μ] (b₀ : Basis ι ℝ E) : μ (fundamentalDomain b) = ENNReal.ofReal |b₀.det b| * μ (fundamentalDomain b₀) := by have : FiniteDimensional ℝ E := b.finiteDimensional_of_finite convert μ.addHaar_preimage_linearEquiv (b.equiv b₀ (Equiv.refl ι)) (fundamentalDomain b₀) · rw [Set.eq_preimage_iff_image_eq (LinearEquiv.bijective _), map_fundamentalDomain, Basis.map_equiv, Equiv.refl_symm, Basis.reindex_refl] · simp theorem measureReal_fundamentalDomain [Fintype ι] [DecidableEq ι] [MeasurableSpace E] (μ : Measure E) [BorelSpace E] [Measure.IsAddHaarMeasure μ] (b₀ : Basis ι ℝ E) : μ.real (fundamentalDomain b) = |b₀.det b| * μ.real (fundamentalDomain b₀) := by simp [measureReal_def, measure_fundamentalDomain b μ b₀] @[simp] theorem volume_fundamentalDomain [Fintype ι] [DecidableEq ι] (b : Basis ι ℝ (ι → ℝ)) : volume (fundamentalDomain b) = ENNReal.ofReal |(Matrix.of b).det| := by rw [measure_fundamentalDomain b volume (b₀ := Pi.basisFun ℝ ι), fundamentalDomain_pi_basisFun, volume_pi, Measure.pi_pi, Real.volume_Ico, sub_zero, ENNReal.ofReal_one, Finset.prod_const_one, mul_one, ← Matrix.det_transpose] rfl @[simp] theorem volume_real_fundamentalDomain [Fintype ι] [DecidableEq ι] (b : Basis ι ℝ (ι → ℝ)) : volume.real (fundamentalDomain b) = |(Matrix.of b).det| := by simp [measureReal_def] theorem fundamentalDomain_ae_parallelepiped [Fintype ι] [MeasurableSpace E] (μ : Measure E) [BorelSpace E] [Measure.IsAddHaarMeasure μ] : fundamentalDomain b =ᵐ[μ] parallelepiped b := by classical have : FiniteDimensional ℝ E := b.finiteDimensional_of_finite rw [← measure_symmDiff_eq_zero_iff, symmDiff_of_le (fundamentalDomain_subset_parallelepiped b)] suffices (parallelepiped b \ fundamentalDomain b) ⊆ ⋃ i, AffineSubspace.mk' (b i) (span ℝ (b '' (Set.univ \ {i}))) by refine measure_mono_null this (measure_iUnion_null_iff.mpr fun i ↦ Measure.addHaar_affineSubspace μ _ ?_) refine (ne_of_mem_of_not_mem' (AffineSubspace.mem_top _ _ 0) (AffineSubspace.mem_mk'.not.mpr ?_)).symm simp_rw [vsub_eq_sub, zero_sub, neg_mem_iff] exact linearIndependent_iff_notMem_span.mp b.linearIndependent i intro x hx simp_rw [parallelepiped_basis_eq, Set.mem_Icc, Set.mem_diff, Set.mem_setOf_eq, mem_fundamentalDomain, Set.mem_Ico, not_forall, not_and, not_lt] at hx obtain ⟨i, hi⟩ := hx.2 have : b.repr x i = 1 := le_antisymm (hx.1 i).2 (hi (hx.1 i).1) rw [← b.sum_repr x, ← Finset.sum_erase_add _ _ (Finset.mem_univ i), this, one_smul, ← vadd_eq_add] refine Set.mem_iUnion.mpr ⟨i, AffineSubspace.vadd_mem_mk' _ (sum_smul_mem _ _ (fun i hi ↦ Submodule.subset_span ?_))⟩ exact ⟨i, Set.mem_diff_singleton.mpr ⟨trivial, Finset.ne_of_mem_erase hi⟩, rfl⟩ end Real end ZSpan section ZLattice open Submodule Module ZSpan -- TODO: generalize this class to other rings than `ℤ` /-- `L : Submodule ℤ E` where `E` is a vector space over a normed field `K` is a `ℤ`-lattice if it is discrete and spans `E` over `K`. -/ class IsZLattice (K : Type*) [NormedField K] {E : Type*} [NormedAddCommGroup E] [NormedSpace K E] (L : Submodule ℤ E) [DiscreteTopology L] : Prop where /-- `L` spans the full space `E` over `K`. -/ span_top : span K (L : Set E) = ⊤ instance instIsZLatticeRealSpan {E ι : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [Finite ι] (b : Basis ι ℝ E) : IsZLattice ℝ (span ℤ (Set.range b)) where span_top := ZSpan.span_top b @[deprecated (since := "2025-05-08")] alias ZSpan.isZLattice := instIsZLatticeRealSpan section NormedLinearOrderedField variable (K : Type*) [NormedField K] [LinearOrder K] [IsStrictOrderedRing K] [HasSolidNorm K] [FloorRing K] variable {E : Type*} [NormedAddCommGroup E] [NormedSpace K E] [FiniteDimensional K E] variable [ProperSpace E] (L : Submodule ℤ E) [DiscreteTopology L] theorem ZLattice.FG [hs : IsZLattice K L] : L.FG := by obtain ⟨s, ⟨h_incl, ⟨h_span, h_lind⟩⟩⟩ := exists_linearIndependent K (L : Set E) -- Let `s` be a maximal `K`-linear independent family of elements of `L`. We show that -- `L` is finitely generated (as a ℤ-module) because it fits in the exact sequence -- `0 → span ℤ s → L → L ⧸ span ℤ s → 0` with `span ℤ s` and `L ⧸ span ℤ s` finitely generated. refine fg_of_fg_map_of_fg_inf_ker (span ℤ s).mkQ ?_ ?_ · -- Let `b` be the `K`-basis of `E` formed by the vectors in `s`. The elements of -- `L ⧸ span ℤ s = L ⧸ span ℤ b` are in bijection with elements of `L ∩ fundamentalDomain b` -- so there are finitely many since `fundamentalDomain b` is bounded. refine fg_def.mpr ⟨map (span ℤ s).mkQ L, ?_, span_eq _⟩ let b := Basis.mk h_lind (by rw [← hs.span_top, ← h_span] exact span_mono (by simp only [Subtype.range_coe_subtype, Set.setOf_mem_eq, subset_rfl])) rw [show span ℤ s = span ℤ (Set.range b) by simp [b, Basis.coe_mk, Subtype.range_coe_subtype]] have : Fintype s := h_lind.setFinite.fintype refine Set.Finite.of_finite_image (f := ((↑) : _ → E) ∘ quotientEquiv b) ?_ (Function.Injective.injOn (Subtype.coe_injective.comp (quotientEquiv b).injective)) have : ((fundamentalDomain b) ∩ L).Finite := by change ((fundamentalDomain b) ∩ L.toAddSubgroup).Finite have : DiscreteTopology L.toAddSubgroup := (inferInstance : DiscreteTopology L) exact Metric.finite_isBounded_inter_isClosed (fundamentalDomain_isBounded b) inferInstance refine Set.Finite.subset this ?_ rintro _ ⟨_, ⟨⟨x, ⟨h_mem, rfl⟩⟩, rfl⟩⟩ rw [Function.comp_apply, mkQ_apply, quotientEquiv_apply_mk, fractRestrict_apply] refine ⟨?_, ?_⟩ · exact fract_mem_fundamentalDomain b x · rw [fract, SetLike.mem_coe, sub_eq_add_neg] refine Submodule.add_mem _ h_mem (neg_mem (Set.mem_of_subset_of_mem ?_ (Subtype.mem (floor b x)))) rw [SetLike.coe_subset_coe, Basis.coe_mk, Subtype.range_coe_subtype, Set.setOf_mem_eq] exact span_le.mpr h_incl · -- `span ℤ s` is finitely generated because `s` is finite rw [ker_mkQ, inf_of_le_right (span_le.mpr h_incl)] exact fg_span (LinearIndependent.setFinite h_lind) @[deprecated (since := "2025-08-11")] alias Zlattice.FG := ZLattice.FG theorem ZLattice.module_finite [IsZLattice K L] : Module.Finite ℤ L := Module.Finite.iff_fg.mpr (ZLattice.FG K L) instance instModuleFinite_of_discrete_submodule {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [FiniteDimensional ℝ E] (L : Submodule ℤ E) [DiscreteTopology L] : Module.Finite ℤ L := by let f := (span ℝ (L : Set E)).subtype let L₀ := L.comap (f.restrictScalars ℤ) have h_img : f '' L₀ = L := by rw [← LinearMap.coe_restrictScalars ℤ f, ← Submodule.map_coe (f.restrictScalars ℤ), Submodule.map_comap_eq_self] exact fun x hx ↦ LinearMap.mem_range.mpr ⟨⟨x, Submodule.subset_span hx⟩, rfl⟩ suffices Module.Finite ℤ L₀ by have : L₀.map (f.restrictScalars ℤ) = L := SetLike.ext'_iff.mpr h_img convert this ▸ Module.Finite.map L₀ (f.restrictScalars ℤ) have : DiscreteTopology L₀ := by refine DiscreteTopology.preimage_of_continuous_injective (L : Set E) ?_ (injective_subtype _) exact LinearMap.continuous_of_finiteDimensional f have : IsZLattice ℝ L₀ := ⟨by rw [← (Submodule.map_injective_of_injective (injective_subtype _)).eq_iff, Submodule.map_span, Submodule.map_top, range_subtype, h_img]⟩ exact ZLattice.module_finite ℝ L₀ theorem ZLattice.module_free [IsZLattice K L] : Module.Free ℤ L := by have : Module.Finite ℤ L := module_finite K L have : Module ℚ E := Module.compHom E (algebraMap ℚ K) have : IsAddTorsionFree E := .of_module_rat _ infer_instance instance instModuleFree_of_discrete_submodule {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [FiniteDimensional ℝ E] (L : Submodule ℤ E) [DiscreteTopology L] : Module.Free ℤ L := by have : Module ℚ E := Module.compHom E (algebraMap ℚ ℝ) have : IsAddTorsionFree E := .of_module_rat _ infer_instance theorem ZLattice.rank [hs : IsZLattice K L] : finrank ℤ L = finrank K E := by classical have : Module.Finite ℤ L := module_finite K L have : Module ℚ E := Module.compHom E (algebraMap ℚ K) have : IsAddTorsionFree E := .of_module_rat _ let b₀ := Module.Free.chooseBasis ℤ L -- Let `b` be a `ℤ`-basis of `L` formed of vectors of `E` let b := Subtype.val ∘ b₀ have : LinearIndependent ℤ b := LinearIndependent.map' b₀.linearIndependent (L.subtype) (ker_subtype _) -- We prove some assertions that will be useful later on have h_spanL : span ℤ (Set.range b) = L := by convert congrArg (map (Submodule.subtype L)) b₀.span_eq · rw [map_span, Set.range_comp] rfl · exact (map_subtype_top _).symm have h_spanE : span K (Set.range b) = ⊤ := by rw [← span_span_of_tower (R := ℤ), h_spanL] exact hs.span_top have h_card : Fintype.card (Module.Free.ChooseBasisIndex ℤ L) = (Set.range b).toFinset.card := by rw [Set.toFinset_range, Finset.univ.card_image_of_injective] · rfl · exact Subtype.coe_injective.comp (Basis.injective _) rw [finrank_eq_card_chooseBasisIndex] -- We prove that `finrank ℤ L ≤ finrank K E` and `finrank K E ≤ finrank ℤ L` refine le_antisymm ?_ ?_ · -- To prove that `finrank ℤ L ≤ finrank K E`, we proceed by contradiction and prove that, in -- this case, there is a ℤ-relation between the vectors of `b` obtain ⟨t, ⟨ht_inc, ⟨ht_span, ht_lin⟩⟩⟩ := exists_linearIndependent K (Set.range b) -- `e` is a `K`-basis of `E` formed of vectors of `b` let e : Basis t K E := Basis.mk ht_lin (by simp [ht_span, h_spanE]) have : Fintype t := Set.Finite.fintype ((Set.range b).toFinite.subset ht_inc) have h : LinearIndepOn ℤ id (Set.range b) := by rwa [linearIndepOn_id_range_iff (Subtype.coe_injective.comp b₀.injective)] contrapose! h -- Since `finrank ℤ L > finrank K E`, there exists a vector `v ∈ b` with `v ∉ e` obtain ⟨v, hv⟩ : (Set.range b \ Set.range e).Nonempty := by rw [Basis.coe_mk, Subtype.range_coe_subtype, Set.setOf_mem_eq, ← Set.toFinset_nonempty] contrapose h rw [Finset.not_nonempty_iff_eq_empty, Set.toFinset_diff, Finset.sdiff_eq_empty_iff_subset] at h replace h := Finset.card_le_card h rwa [not_lt, h_card, ← topEquiv.finrank_eq, ← h_spanE, ← ht_span, finrank_span_set_eq_card ht_lin] -- Assume that `e ∪ {v}` is not `ℤ`-linear independent then we get the contradiction suffices ¬ LinearIndepOn ℤ id (insert v (Set.range e)) by contrapose! this refine this.mono ?_ exact Set.insert_subset (Set.mem_of_mem_diff hv) (by simp [e, ht_inc]) -- We prove finally that `e ∪ {v}` is not ℤ-linear independent or, equivalently, -- not ℚ-linear independent by showing that `v ∈ span ℚ e`. rw [LinearIndepOn, LinearIndependent.iff_fractionRing ℤ ℚ, ← LinearIndepOn, linearIndepOn_id_insert (Set.notMem_of_mem_diff hv), not_and, not_not] intro _ -- But that follows from the fact that there exist `n, m : ℕ`, `n ≠ m` -- such that `(n - m) • v ∈ span ℤ e` which is true since `n ↦ ZSpan.fract e (n • v)` -- takes value into the finite set `fundamentalDomain e ∩ L` have h_mapsto : Set.MapsTo (fun n : ℤ => fract e (n • v)) Set.univ (Metric.closedBall 0 (∑ i, ‖e i‖) ∩ (L : Set E)) := by rw [Set.mapsTo_inter, Set.mapsTo_univ_iff, Set.mapsTo_univ_iff] refine ⟨fun _ ↦ mem_closedBall_zero_iff.mpr (norm_fract_le e _), fun _ => ?_⟩ · rw [← h_spanL] refine sub_mem ?_ ?_ · exact zsmul_mem (subset_span (Set.diff_subset hv)) _ · exact span_mono (by simp [e, ht_inc]) (coe_mem _) have h_finite : Set.Finite (Metric.closedBall 0 (∑ i, ‖e i‖) ∩ (L : Set E)) := by change ((_ : Set E) ∩ L.toAddSubgroup).Finite have : DiscreteTopology L.toAddSubgroup := (inferInstance : DiscreteTopology L) exact Metric.finite_isBounded_inter_isClosed Metric.isBounded_closedBall inferInstance obtain ⟨n, -, m, -, h_neq, h_eq⟩ := Set.Infinite.exists_ne_map_eq_of_mapsTo Set.infinite_univ h_mapsto h_finite have h_nz : (-n + m : ℚ) ≠ 0 := by rwa [Ne, add_eq_zero_iff_eq_neg.not, neg_inj, Rat.coe_int_inj, ← Ne] apply (smul_mem_iff _ h_nz).mp refine span_subset_span ℤ ℚ _ ?_ rwa [add_smul, neg_smul, SetLike.mem_coe, ← fract_eq_fract, Int.cast_smul_eq_zsmul ℚ, Int.cast_smul_eq_zsmul ℚ] · -- To prove that `finrank K E ≤ finrank ℤ L`, we use the fact `b` generates `E` over `K` -- and thus `finrank K E ≤ card b = finrank ℤ L` rw [← topEquiv.finrank_eq, ← h_spanE] convert finrank_span_le_card (R := K) (Set.range b) variable {ι : Type*} [hs : IsZLattice K L] (b : Basis ι ℤ L) namespace Module.Basis /-- Any `ℤ`-basis of `L` is also a `K`-basis of `E`. -/ def ofZLatticeBasis : Basis ι K E := by have : Module.Finite ℤ L := ZLattice.module_finite K L have : Free ℤ L := ZLattice.module_free K L let e := (Free.chooseBasis ℤ L).indexEquiv b have : Fintype ι := Fintype.ofEquiv _ e refine basisOfTopLeSpanOfCardEqFinrank (L.subtype ∘ b) ?_ ?_ · rw [← span_span_of_tower ℤ, Set.range_comp, ← map_span, Basis.span_eq, Submodule.map_top, range_subtype, top_le_iff, hs.span_top] · rw [← Fintype.card_congr e, ← finrank_eq_card_chooseBasisIndex, ZLattice.rank K L] @[simp] theorem ofZLatticeBasis_apply (i : ι) : b.ofZLatticeBasis K L i = b i := by simp [Basis.ofZLatticeBasis] @[simp] theorem ofZLatticeBasis_repr_apply (x : L) (i : ι) : (b.ofZLatticeBasis K L).repr x i = b.repr x i := by suffices ((b.ofZLatticeBasis K L).repr.toLinearMap.restrictScalars ℤ) ∘ₗ L.subtype = Finsupp.mapRange.linearMap (Algebra.linearMap ℤ K) ∘ₗ b.repr.toLinearMap by exact DFunLike.congr_fun (LinearMap.congr_fun this x) i refine Basis.ext b fun i ↦ ?_ simp_rw [LinearMap.coe_comp, Function.comp_apply, LinearMap.coe_restrictScalars, LinearEquiv.coe_coe, coe_subtype, ← b.ofZLatticeBasis_apply K, repr_self, Finsupp.mapRange.linearMap_apply, Finsupp.mapRange_single, Algebra.linearMap_apply, map_one] theorem ofZLatticeBasis_span : span ℤ (Set.range (b.ofZLatticeBasis K)) = L := by calc span ℤ (Set.range (b.ofZLatticeBasis K)) _ = span ℤ (L.subtype '' Set.range b) := by congr; ext; simp _ = map L.subtype (span ℤ (Set.range b)) := by rw [Submodule.map_span] _ = L := by simp [b.span_eq] end Module.Basis open MeasureTheory in theorem ZLattice.isAddFundamentalDomain {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [FiniteDimensional ℝ E] {L : Submodule ℤ E} [DiscreteTopology L] [IsZLattice ℝ L] [Finite ι] (b : Basis ι ℤ L) [MeasurableSpace E] [OpensMeasurableSpace E] (μ : Measure E) : IsAddFundamentalDomain L (fundamentalDomain (b.ofZLatticeBasis ℝ)) μ := by convert ZSpan.isAddFundamentalDomain (b.ofZLatticeBasis ℝ) μ all_goals exact (b.ofZLatticeBasis_span ℝ).symm instance instCountable_of_discrete_submodule {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [FiniteDimensional ℝ E] (L : Submodule ℤ E) [DiscreteTopology L] [IsZLattice ℝ L] : Countable L := by simp_rw [← (Module.Free.chooseBasis ℤ L).ofZLatticeBasis_span ℝ] infer_instance /-- Assume that the set `s` spans over `ℤ` a discrete set. Then its `ℝ`-rank is equal to its `ℤ`-rank. -/ theorem Real.finrank_eq_int_finrank_of_discrete {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [FiniteDimensional ℝ E] {s : Set E} (hs : DiscreteTopology (span ℤ s)) : Set.finrank ℝ s = Set.finrank ℤ s := by let F := span ℝ s let L : Submodule ℤ (span ℝ s) := comap (F.restrictScalars ℤ).subtype (span ℤ s) let f := Submodule.comapSubtypeEquivOfLe (span_le_restrictScalars ℤ ℝ s) have : DiscreteTopology L := by let e : span ℤ s ≃L[ℤ] L := ⟨f.symm, continuous_of_discreteTopology, Isometry.continuous fun _ ↦ congrFun rfl⟩ exact e.toHomeomorph.discreteTopology have : IsZLattice ℝ L := ⟨eq_top_iff.mpr <| span_span_coe_preimage.symm.le.trans (span_mono (Set.preimage_mono subset_span))⟩ rw [Set.finrank, Set.finrank, ← f.finrank_eq] exact (ZLattice.rank ℝ L).symm end NormedLinearOrderedField section Basis variable {ι : Type*} [Fintype ι] (L : Submodule ℤ (ι → ℝ)) [DiscreteTopology L] [IsZLattice ℝ L] /-- Return an arbitrary `ℤ`-basis of a lattice `L` of `ι → ℝ` indexed by `ι`. -/ def IsZLattice.basis : Basis ι ℤ L := (Free.chooseBasis ℤ L).reindex (Fintype.equivOfCardEq (by rw [← finrank_eq_card_chooseBasisIndex, ZLattice.rank ℝ, finrank_fintype_fun_eq_card])) end Basis section comap variable (K : Type*) [NormedField K] {E F : Type*} [NormedAddCommGroup E] [NormedSpace K E] [NormedAddCommGroup F] [NormedSpace K F] (L : Submodule ℤ E) /-- Let `e : E → F` a linear map, the map that sends a `L : Submodule ℤ E` to the `Submodule ℤ F` that is the pullback of `L` by `e`. If `IsZLattice L` and `e` is a continuous linear equiv, then it is a `IsZLattice` of `E`, see `instIsZLatticeComap`. -/ protected def ZLattice.comap (e : F →ₗ[K] E) := L.comap (e.restrictScalars ℤ) @[simp] theorem ZLattice.coe_comap (e : F →ₗ[K] E) : (ZLattice.comap K L e : Set F) = e⁻¹' L := rfl theorem ZLattice.comap_refl : ZLattice.comap K L (1 : E →ₗ[K] E)= L := Submodule.comap_id L theorem ZLattice.comap_discreteTopology [hL : DiscreteTopology L] {e : F →ₗ[K] E} (he₁ : Continuous e) (he₂ : Function.Injective e) : DiscreteTopology (ZLattice.comap K L e) := by exact DiscreteTopology.preimage_of_continuous_injective L he₁ he₂ instance [DiscreteTopology L] (e : F ≃L[K] E) : DiscreteTopology (ZLattice.comap K L e.toLinearMap) := ZLattice.comap_discreteTopology K L e.continuous e.injective theorem ZLattice.comap_span_top (hL : span K (L : Set E) = ⊤) {e : F →ₗ[K] E} (he : (L : Set E) ⊆ LinearMap.range e) : span K (ZLattice.comap K L e : Set F) = ⊤ := by rw [ZLattice.coe_comap, Submodule.span_preimage_eq (Submodule.nonempty L) he, hL, comap_top] instance instIsZLatticeComap [DiscreteTopology L] [IsZLattice K L] (e : F ≃L[K] E) : IsZLattice K (ZLattice.comap K L e.toLinearMap) where span_top := by rw [ZLattice.coe_comap, LinearEquiv.coe_coe, e.coe_toLinearEquiv, ← e.image_symm_eq_preimage, ← Submodule.map_span, IsZLattice.span_top, Submodule.map_top, LinearEquivClass.range] @[simp] theorem ZLattice.comap_toAddSubgroup (e : F →ₗ[K] E) : (ZLattice.comap K L e).toAddSubgroup = L.toAddSubgroup.comap e.toAddMonoidHom := rfl theorem ZLattice.comap_comp {G : Type*} [NormedAddCommGroup G] [NormedSpace K G] (e : F →ₗ[K] E) (e' : G →ₗ[K] F) : (ZLattice.comap K (ZLattice.comap K L e) e') = ZLattice.comap K L (e ∘ₗ e') := (Submodule.comap_comp _ _ L).symm /-- If `e` is a linear equivalence, it induces a `ℤ`-linear equivalence between `L` and `ZLattice.comap K L e`. -/ def ZLattice.comap_equiv (e : F ≃ₗ[K] E) : L ≃ₗ[ℤ] (ZLattice.comap K L e.toLinearMap) := LinearEquiv.ofBijective ((e.symm.toLinearMap.restrictScalars ℤ).restrict (fun _ h ↦ by simpa [← SetLike.mem_coe] using h)) ⟨fun _ _ h ↦ Subtype.ext_iff.mpr (e.symm.injective (congr_arg Subtype.val h)), fun ⟨x, hx⟩ ↦ ⟨⟨e x, by rwa [← SetLike.mem_coe, ZLattice.coe_comap] at hx⟩, by simp [Subtype.ext_iff]⟩⟩ @[simp] theorem ZLattice.comap_equiv_apply (e : F ≃ₗ[K] E) (x : L) : ZLattice.comap_equiv K L e x = e.symm x := rfl namespace Module.Basis /-- The basis of `ZLattice.comap K L e` given by the image of a basis `b` of `L` by `e.symm`. -/ def ofZLatticeComap (e : F ≃ₗ[K] E) {ι : Type*} (b : Basis ι ℤ L) : Basis ι ℤ (ZLattice.comap K L e.toLinearMap) := b.map (ZLattice.comap_equiv K L e) @[simp] theorem ofZLatticeComap_apply (e : F ≃ₗ[K] E) {ι : Type*} (b : Basis ι ℤ L) (i : ι) : b.ofZLatticeComap K L e i = e.symm (b i) := by simp [Basis.ofZLatticeComap] @[simp] theorem ofZLatticeComap_repr_apply (e : F ≃ₗ[K] E) {ι : Type*} (b : Basis ι ℤ L) (x : L) (i : ι) : (b.ofZLatticeComap K L e).repr (ZLattice.comap_equiv K L e x) i = b.repr x i := by simp [Basis.ofZLatticeComap] end Module.Basis end comap section NormedLinearOrderedField_comap variable (K : Type*) [NormedField K] [LinearOrder K] [IsStrictOrderedRing K] [HasSolidNorm K] [FloorRing K] variable {E : Type*} [NormedAddCommGroup E] [NormedSpace K E] [FiniteDimensional K E] [ProperSpace E] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace K F] [FiniteDimensional K F] [ProperSpace F] variable (L : Submodule ℤ E) [DiscreteTopology L] [IsZLattice K L] theorem Module.Basis.ofZLatticeBasis_comap (e : F ≃L[K] E) {ι : Type*} (b : Basis ι ℤ L) : (b.ofZLatticeComap K L e.toLinearEquiv).ofZLatticeBasis K (ZLattice.comap K L e.toLinearMap) = (b.ofZLatticeBasis K L).map e.symm.toLinearEquiv := by ext simp end NormedLinearOrderedField_comap end ZLattice
.lake/packages/mathlib/Mathlib/Algebra/Module/ZLattice/Covolume.lean
import Mathlib.Analysis.BoxIntegral.UnitPartition import Mathlib.LinearAlgebra.FreeModule.Finite.CardQuotient import Mathlib.MeasureTheory.Measure.Haar.InnerProductSpace /-! # Covolume of ℤ-lattices Let `E` be a finite-dimensional real vector space. Let `L` be a `ℤ`-lattice `L` defined as a discrete `ℤ`-submodule of `E` that spans `E` over `ℝ`. ## Main definitions and results * `ZLattice.covolume`: the covolume of `L` defined as the volume of an arbitrary fundamental domain of `L`. * `ZLattice.covolume_eq_measure_fundamentalDomain`: the covolume of `L` does not depend on the choice of the fundamental domain of `L`. * `ZLattice.covolume_eq_det`: if `L` is a lattice in `ℝ^n`, then its covolume is the absolute value of the determinant of any `ℤ`-basis of `L`. * `ZLattice.covolume_div_covolume_eq_relIndex`: Let `L₁` be a sub-`ℤ`-lattice of `L₂`. Then the index of `L₁` inside `L₂` is equal to `covolume L₁ / covolume L₂`. * `ZLattice.covolume.tendsto_card_div_pow`: Let `s` be a bounded measurable set of `ι → ℝ`, then the number of points in `s ∩ n⁻¹ • L` divided by `n ^ card ι` tends to `volume s / covolume L` when `n : ℕ` tends to infinity. See also `ZLattice.covolume.tendsto_card_div_pow'` for a version for `InnerProductSpace ℝ E` and `ZLattice.covolume.tendsto_card_div_pow''` for the general version. * `ZLattice.covolume.tendsto_card_le_div`: Let `X` be a cone in `ι → ℝ` and let `F : (ι → ℝ) → ℝ` be a function such that `F (c • x) = c ^ card ι * F x`. Then the number of points `x ∈ X` such that `F x ≤ c` divided by `c` tends to `volume {x ∈ X | F x ≤ 1} / covolume L` when `c : ℝ` tends to infinity. See also `ZLattice.covolume.tendsto_card_le_div'` for a version for `InnerProductSpace ℝ E` and `ZLattice.covolume.tendsto_card_le_div''` for the general version. ## Naming convention Some results are true in the case where the ambient finite-dimensional real vector space is the pi-space `ι → ℝ` and in the case where it is an `InnerProductSpace`. We use the following convention: the plain name is for the pi case, for e.g. `volume_image_eq_volume_div_covolume`. For the same result in the `InnerProductSpace` case, we add a `prime`, for e.g. `volume_image_eq_volume_div_covolume'`. When the same result exists in the general case, we had two primes, e.g. `covolume.tendsto_card_div_pow''`. -/ noncomputable section namespace ZLattice open Submodule MeasureTheory Module MeasureTheory Module ZSpan section General variable {E : Type*} [NormedAddCommGroup E] [MeasurableSpace E] (L : Submodule ℤ E) /-- The covolume of a `ℤ`-lattice is the volume of some fundamental domain; see `ZLattice.covolume_eq_volume` for the proof that the volume does not depend on the choice of the fundamental domain. -/ def covolume (μ : Measure E := by volume_tac) : ℝ := (addCovolume L E μ).toReal end General section Basic variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [FiniteDimensional ℝ E] variable [MeasurableSpace E] [BorelSpace E] variable (L : Submodule ℤ E) [DiscreteTopology L] [IsZLattice ℝ L] variable (μ : Measure E := by volume_tac) [Measure.IsAddHaarMeasure μ] theorem covolume_eq_measure_fundamentalDomain {F : Set E} (h : IsAddFundamentalDomain L F μ) : covolume L μ = μ.real F := by have : MeasurableVAdd L E := (inferInstance : MeasurableVAdd L.toAddSubgroup E) have : VAddInvariantMeasure L E μ := (inferInstance : VAddInvariantMeasure L.toAddSubgroup E μ) exact congr_arg ENNReal.toReal (h.covolume_eq_volume μ) theorem covolume_ne_zero : covolume L μ ≠ 0 := by rw [covolume_eq_measure_fundamentalDomain L μ (isAddFundamentalDomain (Free.chooseBasis ℤ L) μ), measureReal_ne_zero_iff (ne_of_lt _)] · exact measure_fundamentalDomain_ne_zero _ · exact Bornology.IsBounded.measure_lt_top (fundamentalDomain_isBounded _) theorem covolume_pos : 0 < covolume L μ := lt_of_le_of_ne ENNReal.toReal_nonneg (covolume_ne_zero L μ).symm theorem covolume_comap {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] [FiniteDimensional ℝ F] [MeasurableSpace F] [BorelSpace F] (ν : Measure F := by volume_tac) [Measure.IsAddHaarMeasure ν] {e : F ≃L[ℝ] E} (he : MeasurePreserving e ν μ) : covolume (ZLattice.comap ℝ L e.toLinearMap) ν = covolume L μ := by rw [covolume_eq_measure_fundamentalDomain _ _ (isAddFundamentalDomain (Free.chooseBasis ℤ L) μ), covolume_eq_measure_fundamentalDomain _ _ ((isAddFundamentalDomain ((Free.chooseBasis ℤ L).ofZLatticeComap ℝ L e.toLinearEquiv) ν)), ← he.measureReal_preimage (fundamentalDomain_measurableSet _).nullMeasurableSet, ← e.image_symm_eq_preimage, ← e.symm.coe_toLinearEquiv, map_fundamentalDomain] congr! ext; simp theorem covolume_eq_det_mul_measureReal {ι : Type*} [Fintype ι] [DecidableEq ι] (b : Basis ι ℤ L) (b₀ : Basis ι ℝ E) : covolume L μ = |b₀.det ((↑) ∘ b)| * μ.real (fundamentalDomain b₀) := by rw [covolume_eq_measure_fundamentalDomain L μ (isAddFundamentalDomain b μ), measureReal_fundamentalDomain _ _ b₀, measureReal_congr (fundamentalDomain_ae_parallelepiped b₀ μ)] congr ext exact b.ofZLatticeBasis_apply ℝ L _ theorem covolume_eq_det {ι : Type*} [Fintype ι] [DecidableEq ι] (L : Submodule ℤ (ι → ℝ)) [DiscreteTopology L] [IsZLattice ℝ L] (b : Basis ι ℤ L) : covolume L = |(Matrix.of ((↑) ∘ b)).det| := by rw [covolume_eq_measure_fundamentalDomain L volume (isAddFundamentalDomain b volume), volume_real_fundamentalDomain] congr ext1 exact b.ofZLatticeBasis_apply ℝ L _ theorem covolume_eq_det_inv {ι : Type*} [Fintype ι] (L : Submodule ℤ (ι → ℝ)) [DiscreteTopology L] [IsZLattice ℝ L] (b : Basis ι ℤ L) : covolume L = |(LinearEquiv.det (b.ofZLatticeBasis ℝ L).equivFun : ℝ)|⁻¹ := by classical rw [covolume_eq_det L b, ← Pi.basisFun_det_apply, show (((↑) : L → _) ∘ ⇑b) = (b.ofZLatticeBasis ℝ) by ext; simp, ← Basis.det_inv, ← abs_inv, Units.val_inv_eq_inv_val, IsUnit.unit_spec, ← Basis.det_basis, LinearEquiv.coe_det] rfl /-- Let `L₁` be a sub-`ℤ`-lattice of `L₂`. Then the index of `L₁` inside `L₂` is equal to `covolume L₁ / covolume L₂`. -/ theorem covolume_div_covolume_eq_relIndex {ι : Type*} [Fintype ι] (L₁ L₂ : Submodule ℤ (ι → ℝ)) [DiscreteTopology L₁] [IsZLattice ℝ L₁] [DiscreteTopology L₂] [IsZLattice ℝ L₂] (h : L₁ ≤ L₂) : covolume L₁ / covolume L₂ = L₁.toAddSubgroup.relIndex L₂.toAddSubgroup := by classical let b₁ := IsZLattice.basis L₁ let b₂ := IsZLattice.basis L₂ rw [AddSubgroup.relIndex_eq_natAbs_det L₁.toAddSubgroup L₂.toAddSubgroup h b₁ b₂, Nat.cast_natAbs, Int.cast_abs] trans |(b₂.ofZLatticeBasis ℝ).det (b₁.ofZLatticeBasis ℝ)| · rw [← Basis.det_mul_det _ (Pi.basisFun ℝ ι) _, abs_mul, Pi.basisFun_det_apply, ← Basis.det_inv, Units.val_inv_eq_inv_val, IsUnit.unit_spec, Pi.basisFun_det_apply, covolume_eq_det _ b₁, covolume_eq_det _ b₂, mul_comm, abs_inv] congr 3 <;> ext <;> simp · rw [Basis.det_apply, Basis.det_apply, Int.cast_det] congr; ext i j rw [Matrix.map_apply, Basis.toMatrix_apply, Basis.toMatrix_apply, Basis.ofZLatticeBasis_apply] exact (b₂.ofZLatticeBasis_repr_apply ℝ L₂ ⟨b₁ j, h (coe_mem _)⟩ i) @[deprecated (since := "2025-08-12")] alias covolume_div_covolume_eq_relindex := covolume_div_covolume_eq_relIndex /-- A more general version of `covolume_div_covolume_eq_relIndex`; see the `Naming conventions` section in the introduction. -/ theorem covolume_div_covolume_eq_relIndex' {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] (L₁ L₂ : Submodule ℤ E) [DiscreteTopology L₁] [IsZLattice ℝ L₁] [DiscreteTopology L₂] [IsZLattice ℝ L₂] (h : L₁ ≤ L₂) : covolume L₁ / covolume L₂ = L₁.toAddSubgroup.relIndex L₂.toAddSubgroup := by let f := (EuclideanSpace.equiv _ ℝ).symm.trans (stdOrthonormalBasis ℝ E).repr.toContinuousLinearEquiv.symm have hf : MeasurePreserving f := (stdOrthonormalBasis ℝ E).measurePreserving_repr_symm.comp (EuclideanSpace.volume_preserving_symm_measurableEquiv_toLp _).symm rw [← covolume_comap L₁ volume volume hf, ← covolume_comap L₂ volume volume hf, covolume_div_covolume_eq_relIndex _ _ (fun _ h' ↦ h h'), ZLattice.comap_toAddSubgroup, ZLattice.comap_toAddSubgroup, Nat.cast_inj, LinearEquiv.toAddMonoidHom_commutes, AddSubgroup.comap_equiv_eq_map_symm', AddSubgroup.comap_equiv_eq_map_symm', AddSubgroup.relIndex_map_map_of_injective _ _ f.symm.injective] @[deprecated (since := "2025-08-12")] alias covolume_div_covolume_eq_relindex' := covolume_div_covolume_eq_relIndex' theorem volume_image_eq_volume_div_covolume {ι : Type*} [Fintype ι] (L : Submodule ℤ (ι → ℝ)) [DiscreteTopology L] [IsZLattice ℝ L] (b : Basis ι ℤ L) {s : Set (ι → ℝ)} : volume ((b.ofZLatticeBasis ℝ L).equivFun '' s) = volume s / ENNReal.ofReal (covolume L) := by rw [LinearEquiv.image_eq_preimage_symm, Measure.addHaar_preimage_linearEquiv, LinearEquiv.symm_symm, covolume_eq_det_inv L b, ENNReal.div_eq_inv_mul, ENNReal.ofReal_inv_of_pos (abs_pos.2 (LinearEquiv.det _).ne_zero), inv_inv, LinearEquiv.coe_det] /-- A more general version of `ZLattice.volume_image_eq_volume_div_covolume`; see the `Naming conventions` section in the introduction. -/ theorem volume_image_eq_volume_div_covolume' {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] (L : Submodule ℤ E) [DiscreteTopology L] [IsZLattice ℝ L] {ι : Type*} [Fintype ι] (b : Basis ι ℤ L) {s : Set E} (hs : NullMeasurableSet s) : volume ((b.ofZLatticeBasis ℝ).equivFun '' s) = volume s / ENNReal.ofReal (covolume L) := by classical let e : Fin (finrank ℝ E) ≃ ι := Fintype.equivOfCardEq (by rw [Fintype.card_fin, finrank_eq_card_basis (b.ofZLatticeBasis ℝ)]) let f := (EuclideanSpace.equiv ι ℝ).symm.trans ((stdOrthonormalBasis ℝ E).reindex e).repr.toContinuousLinearEquiv.symm have hf : MeasurePreserving f := ((stdOrthonormalBasis ℝ E).reindex e).measurePreserving_repr_symm.comp (PiLp.volume_preserving_toLp ι) rw [← hf.measure_preimage hs, ← (covolume_comap L volume volume hf), ← volume_image_eq_volume_div_covolume (ZLattice.comap ℝ L f.toLinearMap) (b.ofZLatticeComap ℝ L f.toLinearEquiv), Basis.ofZLatticeBasis_comap, ← f.image_symm_eq_preimage, ← Set.image_comp] simp end Basic namespace covolume section General open Filter Fintype Pointwise Topology BoxIntegral Bornology variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] variable {L : Submodule ℤ E} [DiscreteTopology L] [IsZLattice ℝ L] variable {ι : Type*} [Fintype ι] (b : Basis ι ℤ L) /-- A version of `ZLattice.covolume.tendsto_card_div_pow` for the general case; see the `Naming convention` section in the introduction. -/ theorem tendsto_card_div_pow'' [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] {s : Set E} (hs₁ : IsBounded s) (hs₂ : MeasurableSet s) (hs₃ : volume (frontier ((b.ofZLatticeBasis ℝ).equivFun '' s)) = 0) : Tendsto (fun n : ℕ ↦ (Nat.card (s ∩ (n : ℝ)⁻¹ • L : Set E) : ℝ) / n ^ card ι) atTop (𝓝 (volume.real ((b.ofZLatticeBasis ℝ).equivFun '' s))) := by refine Tendsto.congr' ?_ (tendsto_card_div_pow_atTop_volume ((b.ofZLatticeBasis ℝ).equivFun '' s) ?_ ?_ hs₃) · filter_upwards [eventually_gt_atTop 0] with n hn congr refine Nat.card_congr <| ((b.ofZLatticeBasis ℝ).equivFun.toEquiv.subtypeEquiv fun x ↦ ?_).symm simp_rw [Set.mem_inter_iff, ← b.ofZLatticeBasis_span ℝ, LinearEquiv.coe_toEquiv, Basis.equivFun_apply, Set.mem_image, DFunLike.coe_fn_eq, EmbeddingLike.apply_eq_iff_eq, exists_eq_right, and_congr_right_iff, Set.mem_inv_smul_set_iff₀ (mod_cast hn.ne' : (n : ℝ) ≠ 0), ← Finsupp.coe_smul, ← LinearEquiv.map_smul, SetLike.mem_coe, Basis.mem_span_iff_repr_mem, Pi.basisFun_repr, implies_true] · rw [← NormedSpace.isVonNBounded_iff ℝ] at hs₁ ⊢ exact Bornology.IsVonNBounded.image hs₁ ((b.ofZLatticeBasis ℝ).equivFunL : E →L[ℝ] ι → ℝ) · exact (b.ofZLatticeBasis ℝ).equivFunL.toHomeomorph.toMeasurableEquiv.measurableSet_image.mpr hs₂ private theorem tendsto_card_le_div''_aux {X : Set E} (hX : ∀ ⦃x⦄ ⦃r : ℝ⦄, x ∈ X → 0 < r → r • x ∈ X) {F : E → ℝ} (hF₁ : ∀ x ⦃r : ℝ⦄, 0 ≤ r → F (r • x) = r ^ card ι * (F x)) {c : ℝ} (hc : 0 < c) : c • {x ∈ X | F x ≤ 1} = {x ∈ X | F x ≤ c ^ card ι} := by ext x simp_rw [Set.mem_smul_set_iff_inv_smul_mem₀ hc.ne', Set.mem_setOf_eq, hF₁ _ (inv_pos_of_pos hc).le, inv_pow, inv_mul_le_iff₀ (pow_pos hc _), mul_one, and_congr_left_iff] exact fun _ ↦ ⟨fun h ↦ (smul_inv_smul₀ hc.ne' x) ▸ hX h hc, fun h ↦ hX h (inv_pos_of_pos hc)⟩ /-- A version of `ZLattice.covolume.tendsto_card_le_div` for the general case; see the `Naming conventions` section in the introduction. -/ theorem tendsto_card_le_div'' [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] [Nonempty ι] {X : Set E} (hX : ∀ ⦃x⦄ ⦃r : ℝ⦄, x ∈ X → 0 < r → r • x ∈ X) {F : E → ℝ} (h₁ : ∀ x ⦃r : ℝ⦄, 0 ≤ r → F (r • x) = r ^ card ι * (F x)) (h₂ : IsBounded {x ∈ X | F x ≤ 1}) (h₃ : MeasurableSet {x ∈ X | F x ≤ 1}) (h₄ : volume (frontier ((b.ofZLatticeBasis ℝ L).equivFun '' {x | x ∈ X ∧ F x ≤ 1})) = 0) : Tendsto (fun c : ℝ ↦ Nat.card ({x ∈ X | F x ≤ c} ∩ L : Set E) / (c : ℝ)) atTop (𝓝 (volume.real ((b.ofZLatticeBasis ℝ).equivFun '' {x ∈ X | F x ≤ 1}))) := by refine Tendsto.congr' ?_ <| (tendsto_card_div_pow_atTop_volume' ((b.ofZLatticeBasis ℝ).equivFun '' {x ∈ X | F x ≤ 1}) ?_ ?_ h₄ fun x y hx hy ↦ ?_).comp (tendsto_rpow_atTop <| inv_pos.mpr (Nat.cast_pos.mpr card_pos) : Tendsto (fun x ↦ x ^ (card ι : ℝ)⁻¹) atTop atTop) · filter_upwards [eventually_gt_atTop 0] with c hc have aux₁ : (card ι : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr card_ne_zero have aux₂ : 0 < c ^ (card ι : ℝ)⁻¹ := Real.rpow_pos_of_pos hc _ have aux₃ : (c ^ (card ι : ℝ)⁻¹)⁻¹ ≠ 0 := inv_ne_zero aux₂.ne' have aux₄ : c ^ (-(card ι : ℝ)⁻¹) ≠ 0 := (Real.rpow_pos_of_pos hc _).ne' obtain ⟨hc₁, hc₂⟩ := lt_iff_le_and_ne.mp hc rw [Function.comp_apply, ← Real.rpow_natCast, Real.rpow_inv_rpow hc₁ aux₁, eq_comm] congr refine Nat.card_congr <| Equiv.subtypeEquiv ((b.ofZLatticeBasis ℝ).equivFun.toEquiv.trans (Equiv.smulRight aux₄)) fun _ ↦ ?_ rw [Set.mem_inter_iff, Set.mem_inter_iff, Equiv.trans_apply, LinearEquiv.coe_toEquiv, Equiv.smulRight_apply, Real.rpow_neg hc₁, Set.smul_mem_smul_set_iff₀ aux₃, ← Set.mem_smul_set_iff_inv_smul_mem₀ aux₂.ne', ← image_smul_set, tendsto_card_le_div''_aux hX h₁ aux₂, ← Real.rpow_natCast, ← Real.rpow_mul hc₁, inv_mul_cancel₀ aux₁, Real.rpow_one] simp_rw [SetLike.mem_coe, Set.mem_image, EmbeddingLike.apply_eq_iff_eq, exists_eq_right, and_congr_right_iff, ← b.ofZLatticeBasis_span ℝ, Basis.mem_span_iff_repr_mem, Pi.basisFun_repr, Basis.equivFun_apply, implies_true] · rw [← NormedSpace.isVonNBounded_iff ℝ] at h₂ ⊢ exact Bornology.IsVonNBounded.image h₂ ((b.ofZLatticeBasis ℝ).equivFunL : E →L[ℝ] ι → ℝ) · exact (b.ofZLatticeBasis ℝ).equivFunL.toHomeomorph.toMeasurableEquiv.measurableSet_image.mpr h₃ · simp_rw [← image_smul_set] apply Set.image_mono rw [tendsto_card_le_div''_aux hX h₁ hx, tendsto_card_le_div''_aux hX h₁ (lt_of_lt_of_le hx hy)] exact fun a ⟨ha₁, ha₂⟩ ↦ ⟨ha₁, le_trans ha₂ <| pow_le_pow_left₀ (le_of_lt hx) hy _⟩ end General section Pi open Filter Fintype Pointwise Topology Bornology private theorem frontier_equivFun {E : Type*} [AddCommGroup E] [Module ℝ E] {ι : Type*} [Fintype ι] [TopologicalSpace E] [IsTopologicalAddGroup E] [ContinuousSMul ℝ E] [T2Space E] (b : Basis ι ℝ E) (s : Set E) : frontier (b.equivFun '' s) = b.equivFun '' (frontier s) := by rw [LinearEquiv.image_eq_preimage_symm, LinearEquiv.image_eq_preimage_symm] exact (Homeomorph.preimage_frontier b.equivFunL.toHomeomorph.symm s).symm variable {ι : Type*} [Fintype ι] variable (L : Submodule ℤ (ι → ℝ)) [DiscreteTopology L] [IsZLattice ℝ L] theorem tendsto_card_div_pow (b : Basis ι ℤ L) {s : Set (ι → ℝ)} (hs₁ : IsBounded s) (hs₂ : MeasurableSet s) (hs₃ : volume (frontier s) = 0) : Tendsto (fun n : ℕ ↦ (Nat.card (s ∩ (n : ℝ)⁻¹ • L : Set (ι → ℝ)) : ℝ) / n ^ card ι) atTop (𝓝 (volume.real s / covolume L)) := by classical convert tendsto_card_div_pow'' b hs₁ hs₂ ?_ · simp only [measureReal_def] rw [volume_image_eq_volume_div_covolume L b, ENNReal.toReal_div, ENNReal.toReal_ofReal (covolume_pos L volume).le] · rw [frontier_equivFun, volume_image_eq_volume_div_covolume, hs₃, ENNReal.zero_div] theorem tendsto_card_le_div {X : Set (ι → ℝ)} (hX : ∀ ⦃x⦄ ⦃r : ℝ⦄, x ∈ X → 0 < r → r • x ∈ X) {F : (ι → ℝ) → ℝ} (h₁ : ∀ x ⦃r : ℝ⦄, 0 ≤ r → F (r • x) = r ^ card ι * (F x)) (h₂ : IsBounded {x ∈ X | F x ≤ 1}) (h₃ : MeasurableSet {x ∈ X | F x ≤ 1}) (h₄ : volume (frontier {x | x ∈ X ∧ F x ≤ 1}) = 0) [Nonempty ι] : Tendsto (fun c : ℝ ↦ Nat.card ({x ∈ X | F x ≤ c} ∩ L : Set (ι → ℝ)) / (c : ℝ)) atTop (𝓝 (volume.real {x ∈ X | F x ≤ 1} / covolume L)) := by classical let e : Free.ChooseBasisIndex ℤ ↥L ≃ ι := by refine Fintype.equivOfCardEq ?_ rw [← finrank_eq_card_chooseBasisIndex, ZLattice.rank ℝ, finrank_fintype_fun_eq_card] let b := (Module.Free.chooseBasis ℤ L).reindex e convert tendsto_card_le_div'' b hX h₁ h₂ h₃ ?_ · simp only [measureReal_def] rw [volume_image_eq_volume_div_covolume L b, ENNReal.toReal_div, ENNReal.toReal_ofReal (covolume_pos L volume).le] · rw [frontier_equivFun, volume_image_eq_volume_div_covolume, h₄, ENNReal.zero_div] end Pi section InnerProductSpace open Filter Pointwise Topology Bornology variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] variable (L : Submodule ℤ E) [DiscreteTopology L] [IsZLattice ℝ L] /-- A version of `ZLattice.covolume.tendsto_card_div_pow` for the `InnerProductSpace` case; see the `Naming convention` section in the introduction. -/ theorem tendsto_card_div_pow' {s : Set E} (hs₁ : IsBounded s) (hs₂ : MeasurableSet s) (hs₃ : volume (frontier s) = 0) : Tendsto (fun n : ℕ ↦ (Nat.card (s ∩ (n : ℝ)⁻¹ • L : Set E) : ℝ) / n ^ finrank ℝ E) atTop (𝓝 (volume.real s / covolume L)) := by let b := Module.Free.chooseBasis ℤ L convert tendsto_card_div_pow'' b hs₁ hs₂ ?_ · rw [← finrank_eq_card_chooseBasisIndex, ZLattice.rank ℝ L] · simp only [measureReal_def] rw [volume_image_eq_volume_div_covolume' L b hs₂.nullMeasurableSet, ENNReal.toReal_div, ENNReal.toReal_ofReal (covolume_pos L volume).le] · rw [frontier_equivFun, volume_image_eq_volume_div_covolume', hs₃, ENNReal.zero_div] exact NullMeasurableSet.of_null hs₃ /-- A version of `ZLattice.covolume.tendsto_card_le_div` for the `InnerProductSpace` case; see the `Naming convention` section in the introduction. -/ theorem tendsto_card_le_div' [Nontrivial E] {X : Set E} {F : E → ℝ} (hX : ∀ ⦃x⦄ ⦃r : ℝ⦄, x ∈ X → 0 < r → r • x ∈ X) (h₁ : ∀ x ⦃r : ℝ⦄, 0 ≤ r → F (r • x) = r ^ finrank ℝ E * (F x)) (h₂ : IsBounded {x ∈ X | F x ≤ 1}) (h₃ : MeasurableSet {x ∈ X | F x ≤ 1}) (h₄ : volume (frontier {x ∈ X | F x ≤ 1}) = 0) : Tendsto (fun c : ℝ ↦ Nat.card ({x ∈ X | F x ≤ c} ∩ L : Set E) / (c : ℝ)) atTop (𝓝 (volume.real {x ∈ X | F x ≤ 1} / covolume L)) := by let b := Module.Free.chooseBasis ℤ L convert tendsto_card_le_div'' b hX ?_ h₂ h₃ ?_ · simp only [measureReal_def] rw [volume_image_eq_volume_div_covolume' L b h₃.nullMeasurableSet, ENNReal.toReal_div, ENNReal.toReal_ofReal (covolume_pos L volume).le] · have : Nontrivial L := nontrivial_of_finrank_pos <| (ZLattice.rank ℝ L).symm ▸ finrank_pos infer_instance · rwa [← finrank_eq_card_chooseBasisIndex, ZLattice.rank ℝ L] · rw [frontier_equivFun, volume_image_eq_volume_div_covolume', h₄, ENNReal.zero_div] exact NullMeasurableSet.of_null h₄ end InnerProductSpace end covolume end ZLattice
.lake/packages/mathlib/Mathlib/Algebra/FreeAbelianGroup/UniqueSums.lean
import Mathlib.Algebra.FreeAbelianGroup.Finsupp import Mathlib.Algebra.Group.UniqueProds.Basic /-! # Free abelian groups have unique sums -/ assert_not_exists Cardinal StarModule instance {σ : Type*} : TwoUniqueSums (FreeAbelianGroup σ) := (FreeAbelianGroup.equivFinsupp σ).twoUniqueSums_iff.mpr inferInstance
.lake/packages/mathlib/Mathlib/Algebra/FreeAbelianGroup/Finsupp.lean
import Mathlib.Algebra.BigOperators.Finsupp.Basic import Mathlib.Algebra.Module.End import Mathlib.GroupTheory.FreeAbelianGroup /-! # Isomorphism between `FreeAbelianGroup X` and `X →₀ ℤ` In this file we construct the canonical isomorphism between `FreeAbelianGroup X` and `X →₀ ℤ`. We use this to transport the notion of `support` from `Finsupp` to `FreeAbelianGroup`. ## Main declarations - `FreeAbelianGroup.equivFinsupp`: group isomorphism between `FreeAbelianGroup X` and `X →₀ ℤ` - `FreeAbelianGroup.coeff`: the multiplicity of `x : X` in `a : FreeAbelianGroup X` - `FreeAbelianGroup.support`: the finset of `x : X` that occur in `a : FreeAbelianGroup X` -/ assert_not_exists Cardinal Module.Basis noncomputable section variable {X : Type*} /-- The group homomorphism `FreeAbelianGroup X →+ (X →₀ ℤ)`. -/ def FreeAbelianGroup.toFinsupp : FreeAbelianGroup X →+ X →₀ ℤ := FreeAbelianGroup.lift fun x => Finsupp.single x (1 : ℤ) /-- The group homomorphism `(X →₀ ℤ) →+ FreeAbelianGroup X`. -/ def Finsupp.toFreeAbelianGroup : (X →₀ ℤ) →+ FreeAbelianGroup X := Finsupp.liftAddHom fun x => (smulAddHom ℤ (FreeAbelianGroup X)).flip (FreeAbelianGroup.of x) @[simp] lemma FreeAbelianGroup.toFinsupp_of (x : X) : toFinsupp (of x) = .single x 1 := by simp [toFinsupp] @[simp] lemma Finsupp.toFreeAbelianGroup_single (x : X) (n : ℤ) : toFreeAbelianGroup (single x n) = n • .of x := by simp [toFreeAbelianGroup] open Finsupp FreeAbelianGroup @[simp] theorem Finsupp.toFreeAbelianGroup_comp_singleAddHom (x : X) : Finsupp.toFreeAbelianGroup.comp (Finsupp.singleAddHom x) = (smulAddHom ℤ (FreeAbelianGroup X)).flip (of x) := AddMonoidHom.ext <| toFreeAbelianGroup_single _ @[simp] theorem FreeAbelianGroup.toFinsupp_comp_toFreeAbelianGroup : toFinsupp.comp toFreeAbelianGroup = AddMonoidHom.id (X →₀ ℤ) := by ext simp @[simp] theorem Finsupp.toFreeAbelianGroup_comp_toFinsupp : toFreeAbelianGroup.comp toFinsupp = AddMonoidHom.id (FreeAbelianGroup X) := by ext rw [toFreeAbelianGroup, toFinsupp, AddMonoidHom.comp_apply, lift_apply_of, liftAddHom_apply_single, AddMonoidHom.flip_apply, smulAddHom_apply, one_smul, AddMonoidHom.id_apply] @[simp] theorem Finsupp.toFreeAbelianGroup_toFinsupp {X} (x : FreeAbelianGroup X) : Finsupp.toFreeAbelianGroup (FreeAbelianGroup.toFinsupp x) = x := by rw [← AddMonoidHom.comp_apply, Finsupp.toFreeAbelianGroup_comp_toFinsupp, AddMonoidHom.id_apply] namespace FreeAbelianGroup open Finsupp @[simp] theorem toFinsupp_toFreeAbelianGroup (f : X →₀ ℤ) : FreeAbelianGroup.toFinsupp (Finsupp.toFreeAbelianGroup f) = f := by rw [← AddMonoidHom.comp_apply, toFinsupp_comp_toFreeAbelianGroup, AddMonoidHom.id_apply] variable (X) /-- The additive equivalence between `FreeAbelianGroup X` and `(X →₀ ℤ)`. -/ @[simps!] def equivFinsupp : FreeAbelianGroup X ≃+ (X →₀ ℤ) where toFun := toFinsupp invFun := toFreeAbelianGroup left_inv := toFreeAbelianGroup_toFinsupp right_inv := toFinsupp_toFreeAbelianGroup map_add' := toFinsupp.map_add variable {X} /-- `coeff x` is the additive group homomorphism `FreeAbelianGroup X →+ ℤ` that sends `a` to the multiplicity of `x : X` in `a`. -/ def coeff (x : X) : FreeAbelianGroup X →+ ℤ := (Finsupp.applyAddHom x).comp toFinsupp /-- `support a` for `a : FreeAbelianGroup X` is the finite set of `x : X` that occur in the formal sum `a`. -/ def support (a : FreeAbelianGroup X) : Finset X := a.toFinsupp.support theorem mem_support_iff (x : X) (a : FreeAbelianGroup X) : x ∈ a.support ↔ coeff x a ≠ 0 := by rw [support, Finsupp.mem_support_iff] exact Iff.rfl theorem notMem_support_iff (x : X) (a : FreeAbelianGroup X) : x ∉ a.support ↔ coeff x a = 0 := by rw [support, Finsupp.notMem_support_iff] exact Iff.rfl @[deprecated (since := "2025-05-23")] alias not_mem_support_iff := notMem_support_iff @[simp] theorem support_zero : support (0 : FreeAbelianGroup X) = ∅ := by simp only [support, Finsupp.support_zero, AddMonoidHom.map_zero] @[simp] theorem support_of (x : X) : support (of x) = {x} := by rw [support, toFinsupp_of, Finsupp.support_single_ne_zero _ one_ne_zero] @[simp] theorem support_neg (a : FreeAbelianGroup X) : support (-a) = support a := by simp only [support, AddMonoidHom.map_neg, Finsupp.support_neg] @[simp] theorem support_zsmul (k : ℤ) (h : k ≠ 0) (a : FreeAbelianGroup X) : support (k • a) = support a := by ext x simp only [mem_support_iff, AddMonoidHom.map_zsmul] simp only [h, zsmul_int_int, false_or, Ne, mul_eq_zero] @[simp] theorem support_nsmul (k : ℕ) (h : k ≠ 0) (a : FreeAbelianGroup X) : support (k • a) = support a := by apply support_zsmul k _ a exact mod_cast h open scoped Classical in theorem support_add (a b : FreeAbelianGroup X) : support (a + b) ⊆ a.support ∪ b.support := by simp only [support, AddMonoidHom.map_add] apply Finsupp.support_add end FreeAbelianGroup
.lake/packages/mathlib/Mathlib/Algebra/Divisibility/Finite.lean
import Mathlib.Algebra.Divisibility.Basic import Mathlib.Data.Fintype.Defs /-! # Divisibility in finite types -/ variable {M : Type*} [Semigroup M] instance [Fintype M] [DecidableEq M] (a b : M) : Decidable (a ∣ b) := decidable_of_iff (∃ c, b = a * c) dvd_def
.lake/packages/mathlib/Mathlib/Algebra/Divisibility/Prod.lean
import Mathlib.Algebra.Divisibility.Basic import Mathlib.Algebra.Group.Pi.Basic import Mathlib.Algebra.Group.Prod import Mathlib.Tactic.Common /-! # Lemmas about the divisibility relation in product (semi)groups -/ variable {ι G₁ G₂ : Type*} {G : ι → Type*} [Semigroup G₁] [Semigroup G₂] [∀ i, Semigroup (G i)] theorem prod_dvd_iff {x y : G₁ × G₂} : x ∣ y ↔ x.1 ∣ y.1 ∧ x.2 ∣ y.2 := by cases x; cases y simp only [dvd_def, Prod.exists, Prod.mk_mul_mk, Prod.mk.injEq, exists_and_left, exists_and_right] @[simp] theorem Prod.mk_dvd_mk {x₁ y₁ : G₁} {x₂ y₂ : G₂} : (x₁, x₂) ∣ (y₁, y₂) ↔ x₁ ∣ y₁ ∧ x₂ ∣ y₂ := prod_dvd_iff instance [DecompositionMonoid G₁] [DecompositionMonoid G₂] : DecompositionMonoid (G₁ × G₂) where primal a b c h := by simp_rw [prod_dvd_iff] at h ⊢ obtain ⟨a₁, a₁', h₁, h₁', eq₁⟩ := DecompositionMonoid.primal a.1 h.1 obtain ⟨a₂, a₂', h₂, h₂', eq₂⟩ := DecompositionMonoid.primal a.2 h.2 -- aesop works here exact ⟨(a₁, a₂), (a₁', a₂'), ⟨h₁, h₂⟩, ⟨h₁', h₂'⟩, Prod.ext eq₁ eq₂⟩ theorem pi_dvd_iff {x y : ∀ i, G i} : x ∣ y ↔ ∀ i, x i ∣ y i := by simp_rw [dvd_def, funext_iff, Classical.skolem]; rfl instance [∀ i, DecompositionMonoid (G i)] : DecompositionMonoid (∀ i, G i) where primal a b c h := by simp_rw [pi_dvd_iff] at h ⊢ choose a₁ a₂ h₁ h₂ eq using fun i ↦ DecompositionMonoid.primal _ (h i) exact ⟨a₁, a₂, h₁, h₂, funext eq⟩
.lake/packages/mathlib/Mathlib/Algebra/Divisibility/Basic.lean
import Mathlib.Algebra.Group.Basic import Mathlib.Tactic.Common /-! # Divisibility This file defines the basics of the divisibility relation in the context of `(Comm)` `Monoid`s. ## Main definitions * `semigroupDvd` ## Implementation notes The divisibility relation is defined for all monoids, and as such, depends on the order of multiplication if the monoid is not commutative. There are two possible conventions for divisibility in the noncommutative context, and this relation follows the convention for ordinals, so `a | b` is defined as `∃ c, b = a * c`. ## Tags divisibility, divides -/ variable {α : Type*} section Semigroup variable [Semigroup α] {a b c : α} /-- There are two possible conventions for divisibility, which coincide in a `CommMonoid`. This matches the convention for ordinals. -/ instance (priority := 100) semigroupDvd : Dvd α := Dvd.mk fun a b => ∃ c, b = a * c -- TODO: this used to not have `c` explicit, but that seems to be important -- for use with tactics, similar to `Exists.intro` theorem Dvd.intro (c : α) (h : a * c = b) : a ∣ b := Exists.intro c h.symm alias dvd_of_mul_right_eq := Dvd.intro theorem exists_eq_mul_right_of_dvd (h : a ∣ b) : ∃ c, b = a * c := h theorem dvd_def : a ∣ b ↔ ∃ c, b = a * c := Iff.rfl alias dvd_iff_exists_eq_mul_right := dvd_def theorem Dvd.elim {P : Prop} {a b : α} (H₁ : a ∣ b) (H₂ : ∀ c, b = a * c → P) : P := Exists.elim H₁ H₂ attribute [local simp] mul_assoc mul_comm mul_left_comm @[trans] theorem dvd_trans : a ∣ b → b ∣ c → a ∣ c | ⟨d, h₁⟩, ⟨e, h₂⟩ => ⟨d * e, h₁ ▸ h₂.trans <| mul_assoc a d e⟩ alias Dvd.dvd.trans := dvd_trans /-- Transitivity of `|` for use in `calc` blocks. -/ instance : IsTrans α Dvd.dvd := ⟨fun _ _ _ => dvd_trans⟩ @[simp] theorem dvd_mul_right (a b : α) : a ∣ a * b := Dvd.intro b rfl theorem dvd_mul_of_dvd_left (h : a ∣ b) (c : α) : a ∣ b * c := h.trans (dvd_mul_right b c) alias Dvd.dvd.mul_right := dvd_mul_of_dvd_left theorem dvd_of_mul_right_dvd (h : a * b ∣ c) : a ∣ c := (dvd_mul_right a b).trans h /-- An element `a` in a semigroup is primal if whenever `a` is a divisor of `b * c`, it can be factored as the product of a divisor of `b` and a divisor of `c`. -/ def IsPrimal (a : α) : Prop := ∀ ⦃b c⦄, a ∣ b * c → ∃ a₁ a₂, a₁ ∣ b ∧ a₂ ∣ c ∧ a = a₁ * a₂ variable (α) in /-- A monoid is a decomposition monoid if every element is primal. An integral domain whose multiplicative monoid is a decomposition monoid, is called a pre-Schreier domain; it is a Schreier domain if it is moreover integrally closed. -/ @[mk_iff] class DecompositionMonoid : Prop where primal (a : α) : IsPrimal a theorem exists_dvd_and_dvd_of_dvd_mul [DecompositionMonoid α] {b c a : α} (H : a ∣ b * c) : ∃ a₁ a₂, a₁ ∣ b ∧ a₂ ∣ c ∧ a = a₁ * a₂ := DecompositionMonoid.primal a H @[gcongr] theorem mul_dvd_mul_left (a : α) (h : b ∣ c) : a * b ∣ a * c := by obtain ⟨d, rfl⟩ := h use d rw [mul_assoc] theorem IsLeftRegular.dvd_cancel_left (h : IsLeftRegular a) : a * b ∣ a * c ↔ b ∣ c := ⟨fun dvd ↦ have ⟨d, eq⟩ := dvd; ⟨d, h (eq.trans <| mul_assoc ..)⟩, mul_dvd_mul_left a⟩ end Semigroup section Monoid variable [Monoid α] {a b c : α} {m n : ℕ} @[refl, simp] theorem dvd_refl (a : α) : a ∣ a := Dvd.intro 1 (mul_one a) theorem dvd_rfl : ∀ {a : α}, a ∣ a := fun {a} => dvd_refl a instance : IsRefl α (· ∣ ·) := ⟨dvd_refl⟩ theorem one_dvd (a : α) : 1 ∣ a := Dvd.intro a (one_mul a) theorem dvd_of_eq (h : a = b) : a ∣ b := by rw [h] alias Eq.dvd := dvd_of_eq @[gcongr] lemma pow_dvd_pow (a : α) (h : m ≤ n) : a ^ m ∣ a ^ n := ⟨a ^ (n - m), by rw [← pow_add, Nat.add_comm, Nat.sub_add_cancel h]⟩ lemma dvd_pow (hab : a ∣ b) : ∀ {n : ℕ} (_ : n ≠ 0), a ∣ b ^ n | 0, hn => (hn rfl).elim | n + 1, _ => by rw [pow_succ']; exact hab.mul_right _ alias Dvd.dvd.pow := dvd_pow lemma dvd_pow_self (a : α) {n : ℕ} (hn : n ≠ 0) : a ∣ a ^ n := dvd_rfl.pow hn end Monoid section CommSemigroup variable [CommSemigroup α] {a b c : α} theorem Dvd.intro_left (c : α) (h : c * a = b) : a ∣ b := Dvd.intro c (by rw [mul_comm] at h; apply h) alias dvd_of_mul_left_eq := Dvd.intro_left theorem exists_eq_mul_left_of_dvd (h : a ∣ b) : ∃ c, b = c * a := Dvd.elim h fun c => fun H1 : b = a * c => Exists.intro c (Eq.trans H1 (mul_comm a c)) theorem dvd_iff_exists_eq_mul_left : a ∣ b ↔ ∃ c, b = c * a := ⟨exists_eq_mul_left_of_dvd, by rintro ⟨c, rfl⟩ exact ⟨c, mul_comm _ _⟩⟩ theorem Dvd.elim_left {P : Prop} (h₁ : a ∣ b) (h₂ : ∀ c, b = c * a → P) : P := Exists.elim (exists_eq_mul_left_of_dvd h₁) fun c => fun h₃ : b = c * a => h₂ c h₃ @[simp] theorem dvd_mul_left (a b : α) : a ∣ b * a := Dvd.intro b (mul_comm a b) theorem dvd_mul_of_dvd_right (h : a ∣ b) (c : α) : a ∣ c * b := by rw [mul_comm]; exact h.mul_right _ alias Dvd.dvd.mul_left := dvd_mul_of_dvd_right attribute [local simp] mul_assoc mul_comm mul_left_comm @[gcongr] theorem mul_dvd_mul : ∀ {a b c d : α}, a ∣ b → c ∣ d → a * c ∣ b * d | a, _, c, _, ⟨e, rfl⟩, ⟨f, rfl⟩ => ⟨e * f, by simp⟩ theorem dvd_of_mul_left_dvd (h : a * b ∣ c) : b ∣ c := Dvd.elim h fun d ceq => Dvd.intro (a * d) (by simp [ceq]) theorem dvd_mul [DecompositionMonoid α] {k m n : α} : k ∣ m * n ↔ ∃ d₁ d₂, d₁ ∣ m ∧ d₂ ∣ n ∧ k = d₁ * d₂ := by refine ⟨exists_dvd_and_dvd_of_dvd_mul, ?_⟩ rintro ⟨d₁, d₂, hy, hz, rfl⟩ gcongr end CommSemigroup section CommMonoid variable [CommMonoid α] {a b : α} theorem mul_dvd_mul_right (h : a ∣ b) (c : α) : a * c ∣ b * c := by gcongr theorem pow_dvd_pow_of_dvd (h : a ∣ b) (n : ℕ) : a ^ n ∣ b ^ n := by induction n with | zero => simp | succ => rw [pow_succ, pow_succ] gcongr @[gcongr] lemma pow_dvd_pow_of_dvd_of_le {m n : ℕ} (hab : a ∣ b) (hmn : m ≤ n) : a ^ m ∣ b ^ n := by trans (a ^ n) <;> [gcongr; apply_rules [pow_dvd_pow_of_dvd]] end CommMonoid
.lake/packages/mathlib/Mathlib/Algebra/Divisibility/Units.lean
import Mathlib.Algebra.Divisibility.Basic import Mathlib.Algebra.Group.Units.Basic /-! # Divisibility and units ## Main definition * `IsRelPrime x y`: that `x` and `y` are relatively prime, defined to mean that the only common divisors of `x` and `y` are the units. -/ variable {α : Type*} namespace Units section Monoid variable [Monoid α] {a b : α} {u : αˣ} /-- Elements of the unit group of a monoid represented as elements of the monoid divide any element of the monoid. -/ theorem coe_dvd : ↑u ∣ a := ⟨↑u⁻¹ * a, by simp⟩ /-- In a monoid, an element `a` divides an element `b` iff `a` divides all associates of `b`. -/ theorem dvd_mul_right : a ∣ b * u ↔ a ∣ b := Iff.intro (fun ⟨c, eq⟩ ↦ ⟨c * ↑u⁻¹, by rw [← mul_assoc, ← eq, Units.mul_inv_cancel_right]⟩) fun ⟨_, eq⟩ ↦ eq.symm ▸ (_root_.dvd_mul_right _ _).mul_right _ /-- In a monoid, an element `a` divides an element `b` iff all associates of `a` divide `b`. -/ theorem mul_right_dvd : a * u ∣ b ↔ a ∣ b := Iff.intro (fun ⟨c, eq⟩ => ⟨↑u * c, eq.trans (mul_assoc _ _ _)⟩) fun h => dvd_trans (Dvd.intro (↑u⁻¹) (by rw [mul_assoc, u.mul_inv, mul_one])) h end Monoid section CommMonoid variable [CommMonoid α] {a b : α} {u : αˣ} /-- In a commutative monoid, an element `a` divides an element `b` iff `a` divides all left associates of `b`. -/ theorem dvd_mul_left : a ∣ u * b ↔ a ∣ b := by rw [mul_comm] apply dvd_mul_right /-- In a commutative monoid, an element `a` divides an element `b` iff all left associates of `a` divide `b`. -/ theorem mul_left_dvd : ↑u * a ∣ b ↔ a ∣ b := by rw [mul_comm] apply mul_right_dvd end CommMonoid end Units namespace IsUnit section Monoid variable [Monoid α] {a b u : α} /-- Units of a monoid divide any element of the monoid. -/ @[simp] theorem dvd (hu : IsUnit u) : u ∣ a := by rcases hu with ⟨u, rfl⟩ apply Units.coe_dvd @[simp] theorem dvd_mul_right (hu : IsUnit u) : a ∣ b * u ↔ a ∣ b := by rcases hu with ⟨u, rfl⟩ apply Units.dvd_mul_right /-- In a monoid, an element a divides an element b iff all associates of `a` divide `b`. -/ @[simp] theorem mul_right_dvd (hu : IsUnit u) : a * u ∣ b ↔ a ∣ b := by rcases hu with ⟨u, rfl⟩ apply Units.mul_right_dvd theorem isPrimal (hu : IsUnit u) : IsPrimal u := fun _ _ _ ↦ ⟨u, 1, hu.dvd, one_dvd _, (mul_one u).symm⟩ end Monoid section CommMonoid variable [CommMonoid α] {a b u : α} /-- In a commutative monoid, an element `a` divides an element `b` iff `a` divides all left associates of `b`. -/ @[simp] theorem dvd_mul_left (hu : IsUnit u) : a ∣ u * b ↔ a ∣ b := by rcases hu with ⟨u, rfl⟩ apply Units.dvd_mul_left /-- In a commutative monoid, an element `a` divides an element `b` iff all left associates of `a` divide `b`. -/ @[simp] theorem mul_left_dvd (hu : IsUnit u) : u * a ∣ b ↔ a ∣ b := by rcases hu with ⟨u, rfl⟩ apply Units.mul_left_dvd end CommMonoid end IsUnit section CommMonoid variable [CommMonoid α] theorem isUnit_iff_dvd_one {x : α} : IsUnit x ↔ x ∣ 1 := ⟨IsUnit.dvd, fun ⟨y, h⟩ => ⟨⟨x, y, h.symm, by rw [h, mul_comm]⟩, rfl⟩⟩ theorem isUnit_iff_forall_dvd {x : α} : IsUnit x ↔ ∀ y, x ∣ y := isUnit_iff_dvd_one.trans ⟨fun h _ => h.trans (one_dvd _), fun h => h _⟩ theorem isUnit_of_dvd_unit {x y : α} (xy : x ∣ y) (hu : IsUnit y) : IsUnit x := isUnit_iff_dvd_one.2 <| xy.trans <| isUnit_iff_dvd_one.1 hu theorem isUnit_of_dvd_one {a : α} (h : a ∣ 1) : IsUnit (a : α) := isUnit_iff_dvd_one.mpr h theorem not_isUnit_of_not_isUnit_dvd {a b : α} (ha : ¬IsUnit a) (hb : a ∣ b) : ¬IsUnit b := mt (isUnit_of_dvd_unit hb) ha @[simp] lemma dvd_pow_self_iff {x : α} {n : ℕ} : x ∣ x ^ n ↔ n ≠ 0 ∨ IsUnit x := by rcases eq_or_ne n 0 with rfl | hn · simp [isUnit_iff_dvd_one] · simp [hn, dvd_pow_self] end CommMonoid section RelPrime /-- `x` and `y` are relatively prime if every common divisor is a unit. -/ def IsRelPrime [Monoid α] (x y : α) : Prop := ∀ ⦃d⦄, d ∣ x → d ∣ y → IsUnit d variable [CommMonoid α] {x y z : α} @[symm] theorem IsRelPrime.symm (H : IsRelPrime x y) : IsRelPrime y x := fun _ hx hy ↦ H hy hx theorem symmetric_isRelPrime : Symmetric (IsRelPrime : α → α → Prop) := fun _ _ ↦ .symm theorem isRelPrime_comm : IsRelPrime x y ↔ IsRelPrime y x := ⟨IsRelPrime.symm, IsRelPrime.symm⟩ theorem isRelPrime_self : IsRelPrime x x ↔ IsUnit x := ⟨(· dvd_rfl dvd_rfl), fun hu _ _ dvd ↦ isUnit_of_dvd_unit dvd hu⟩ theorem IsUnit.isRelPrime_left (h : IsUnit x) : IsRelPrime x y := fun _ hx _ ↦ isUnit_of_dvd_unit hx h theorem IsUnit.isRelPrime_right (h : IsUnit y) : IsRelPrime x y := h.isRelPrime_left.symm theorem isRelPrime_one_left : IsRelPrime 1 x := isUnit_one.isRelPrime_left theorem isRelPrime_one_right : IsRelPrime x 1 := isUnit_one.isRelPrime_right theorem IsRelPrime.of_mul_left_left (H : IsRelPrime (x * y) z) : IsRelPrime x z := fun _ hx ↦ H (dvd_mul_of_dvd_left hx _) theorem IsRelPrime.of_mul_left_right (H : IsRelPrime (x * y) z) : IsRelPrime y z := (mul_comm x y ▸ H).of_mul_left_left theorem IsRelPrime.of_mul_right_left (H : IsRelPrime x (y * z)) : IsRelPrime x y := by rw [isRelPrime_comm] at H ⊢ exact H.of_mul_left_left theorem IsRelPrime.of_mul_right_right (H : IsRelPrime x (y * z)) : IsRelPrime x z := (mul_comm y z ▸ H).of_mul_right_left theorem IsRelPrime.of_dvd_left (h : IsRelPrime y z) (dvd : x ∣ y) : IsRelPrime x z := by obtain ⟨d, rfl⟩ := dvd; exact IsRelPrime.of_mul_left_left h theorem IsRelPrime.of_dvd_right (h : IsRelPrime z y) (dvd : x ∣ y) : IsRelPrime z x := (h.symm.of_dvd_left dvd).symm theorem IsRelPrime.isUnit_of_dvd (H : IsRelPrime x y) (d : x ∣ y) : IsUnit x := H dvd_rfl d section IsUnit variable (hu : IsUnit x) include hu theorem isRelPrime_mul_unit_left_left : IsRelPrime (x * y) z ↔ IsRelPrime y z := ⟨IsRelPrime.of_mul_left_right, fun H _ h ↦ H (hu.dvd_mul_left.mp h)⟩ theorem isRelPrime_mul_unit_left_right : IsRelPrime y (x * z) ↔ IsRelPrime y z := by rw [isRelPrime_comm, isRelPrime_mul_unit_left_left hu, isRelPrime_comm] theorem isRelPrime_mul_unit_left : IsRelPrime (x * y) (x * z) ↔ IsRelPrime y z := by rw [isRelPrime_mul_unit_left_left hu, isRelPrime_mul_unit_left_right hu] theorem isRelPrime_mul_unit_right_left : IsRelPrime (y * x) z ↔ IsRelPrime y z := by rw [mul_comm, isRelPrime_mul_unit_left_left hu] theorem isRelPrime_mul_unit_right_right : IsRelPrime y (z * x) ↔ IsRelPrime y z := by rw [mul_comm, isRelPrime_mul_unit_left_right hu] theorem isRelPrime_mul_unit_right : IsRelPrime (y * x) (z * x) ↔ IsRelPrime y z := by rw [isRelPrime_mul_unit_right_left hu, isRelPrime_mul_unit_right_right hu] end IsUnit theorem IsRelPrime.dvd_of_dvd_mul_right_of_isPrimal (H1 : IsRelPrime x z) (H2 : x ∣ y * z) (h : IsPrimal x) : x ∣ y := by obtain ⟨a, b, ha, hb, rfl⟩ := h H2 exact (H1.of_mul_left_right.isUnit_of_dvd hb).mul_right_dvd.mpr ha theorem IsRelPrime.dvd_of_dvd_mul_left_of_isPrimal (H1 : IsRelPrime x y) (H2 : x ∣ y * z) (h : IsPrimal x) : x ∣ z := H1.dvd_of_dvd_mul_right_of_isPrimal (mul_comm y z ▸ H2) h theorem IsRelPrime.mul_dvd_of_right_isPrimal (H : IsRelPrime x y) (H1 : x ∣ z) (H2 : y ∣ z) (hy : IsPrimal y) : x * y ∣ z := by obtain ⟨w, rfl⟩ := H1 exact mul_dvd_mul_left x (H.symm.dvd_of_dvd_mul_left_of_isPrimal H2 hy) theorem IsRelPrime.mul_dvd_of_left_isPrimal (H : IsRelPrime x y) (H1 : x ∣ z) (H2 : y ∣ z) (hx : IsPrimal x) : x * y ∣ z := by rw [mul_comm]; exact H.symm.mul_dvd_of_right_isPrimal H2 H1 hx /-! `IsRelPrime` enjoys desirable properties in a decomposition monoid. See Lemma 6.3 in *On properties of square-free elements in commutative cancellative monoids*, https://doi.org/10.1007/s00233-019-10022-3. -/ variable [DecompositionMonoid α] theorem IsRelPrime.dvd_of_dvd_mul_right (H1 : IsRelPrime x z) (H2 : x ∣ y * z) : x ∣ y := H1.dvd_of_dvd_mul_right_of_isPrimal H2 (DecompositionMonoid.primal x) theorem IsRelPrime.dvd_of_dvd_mul_left (H1 : IsRelPrime x y) (H2 : x ∣ y * z) : x ∣ z := H1.dvd_of_dvd_mul_right (mul_comm y z ▸ H2) theorem IsRelPrime.mul_left (H1 : IsRelPrime x z) (H2 : IsRelPrime y z) : IsRelPrime (x * y) z := fun _ h hz ↦ by obtain ⟨a, b, ha, hb, rfl⟩ := exists_dvd_and_dvd_of_dvd_mul h exact (H1 ha <| (dvd_mul_right a b).trans hz).mul (H2 hb <| (dvd_mul_left b a).trans hz) theorem IsRelPrime.mul_right (H1 : IsRelPrime x y) (H2 : IsRelPrime x z) : IsRelPrime x (y * z) := by rw [isRelPrime_comm] at H1 H2 ⊢; exact H1.mul_left H2 theorem IsRelPrime.mul_left_iff : IsRelPrime (x * y) z ↔ IsRelPrime x z ∧ IsRelPrime y z := ⟨fun H ↦ ⟨H.of_mul_left_left, H.of_mul_left_right⟩, fun ⟨H1, H2⟩ ↦ H1.mul_left H2⟩ theorem IsRelPrime.mul_right_iff : IsRelPrime x (y * z) ↔ IsRelPrime x y ∧ IsRelPrime x z := ⟨fun H ↦ ⟨H.of_mul_right_left, H.of_mul_right_right⟩, fun ⟨H1, H2⟩ ↦ H1.mul_right H2⟩ theorem IsRelPrime.mul_dvd (H : IsRelPrime x y) (H1 : x ∣ z) (H2 : y ∣ z) : x * y ∣ z := H.mul_dvd_of_left_isPrimal H1 H2 (DecompositionMonoid.primal x) end RelPrime
.lake/packages/mathlib/Mathlib/Algebra/Divisibility/Hom.lean
import Mathlib.Algebra.Divisibility.Basic import Mathlib.Algebra.Group.Hom.Defs /-! # Mapping divisibility across multiplication-preserving homomorphisms ## Main definitions * `map_dvd` ## Tags divisibility, divides -/ attribute [local simp] mul_assoc mul_comm mul_left_comm variable {M N : Type*} @[gcongr] theorem map_dvd [Semigroup M] [Semigroup N] {F : Type*} [FunLike F M N] [MulHomClass F M N] (f : F) {a b} : a ∣ b → f a ∣ f b | ⟨c, h⟩ => ⟨f c, h.symm ▸ map_mul f a c⟩ theorem MulHom.map_dvd [Semigroup M] [Semigroup N] (f : M →ₙ* N) {a b} : a ∣ b → f a ∣ f b := _root_.map_dvd f theorem MonoidHom.map_dvd [Monoid M] [Monoid N] (f : M →* N) {a b} : a ∣ b → f a ∣ f b := _root_.map_dvd f
.lake/packages/mathlib/Mathlib/Algebra/PresentedMonoid/Basic.lean
import Mathlib.Algebra.FreeMonoid.Basic import Mathlib.Algebra.Group.Submonoid.Operations import Mathlib.GroupTheory.Congruence.Hom /-! # Defining a monoid given by generators and relations Given relations `rels` on the free monoid on a type `α`, this file constructs the monoid given by generators `x : α` and relations `rels`. ## Main definitions * `PresentedMonoid rels`: the quotient of the free monoid on a type `α` by the closure of one-step reductions (arising from a binary relation on free monoid elements `rels`). * `PresentedMonoid.of`: The canonical map from `α` to a presented monoid with generators `α`. * `PresentedMonoid.lift f`: the canonical monoid homomorphism `PresentedMonoid rels → M`, given a function `f : α → G` from a type `α` to a monoid `M` which satisfies the relations `rels`. ## Tags generators, relations, monoid presentations -/ variable {α : Type*} /-- Given a set of relations, `rels`, over a type `α`, `PresentedMonoid` constructs the monoid with generators `x : α` and relations `rels` as a quotient of a congruence structure over rels. -/ @[to_additive /-- Given a set of relations, `rels`, over a type `α`, `PresentedAddMonoid` constructs the monoid with generators `x : α` and relations `rels` as a quotient of an AddCon structure over rels -/] def PresentedMonoid (rel : FreeMonoid α → FreeMonoid α → Prop) := (conGen rel).Quotient namespace PresentedMonoid open Set Submonoid @[to_additive] instance {rels : FreeMonoid α → FreeMonoid α → Prop} : Monoid (PresentedMonoid rels) := Con.monoid (conGen rels) /-- The quotient map from the free monoid on `α` to the presented monoid with the same generators and the given relations `rels`. -/ @[to_additive /-- The quotient map from the free additive monoid on `α` to the presented additive monoid with the same generators and the given relations `rels` -/] def mk (rels : FreeMonoid α → FreeMonoid α → Prop) : FreeMonoid α →* PresentedMonoid rels where toFun := Quotient.mk (conGen rels).toSetoid map_one' := rfl map_mul' := fun _ _ => rfl /-- `of` is the canonical map from `α` to a presented monoid with generators `x : α`. The term `x` is mapped to the equivalence class of the image of `x` in `FreeMonoid α`. -/ @[to_additive /-- `of` is the canonical map from `α` to a presented additive monoid with generators `x : α`. The term `x` is mapped to the equivalence class of the image of `x` in `FreeAddMonoid α`. -/] def of (rels : FreeMonoid α → FreeMonoid α → Prop) (x : α) : PresentedMonoid rels := mk rels (.of x) section inductionOn variable {α₁ α₂ α₃ : Type*} {rels₁ : FreeMonoid α₁ → FreeMonoid α₁ → Prop} {rels₂ : FreeMonoid α₂ → FreeMonoid α₂ → Prop} {rels₃ : FreeMonoid α₃ → FreeMonoid α₃ → Prop} local notation "P₁" => PresentedMonoid rels₁ local notation "P₂" => PresentedMonoid rels₂ local notation "P₃" => PresentedMonoid rels₃ @[to_additive (attr := elab_as_elim), induction_eliminator] protected theorem inductionOn {δ : P₁ → Prop} (q : P₁) (h : ∀ a, δ (mk rels₁ a)) : δ q := Quotient.ind h q @[to_additive (attr := elab_as_elim)] protected theorem inductionOn₂ {δ : P₁ → P₂ → Prop} (q₁ : P₁) (q₂ : P₂) (h : ∀ a b, δ (mk rels₁ a) (mk rels₂ b)) : δ q₁ q₂ := Quotient.inductionOn₂ q₁ q₂ h @[to_additive (attr := elab_as_elim)] protected theorem inductionOn₃ {δ : P₁ → P₂ → P₃ → Prop} (q₁ : P₁) (q₂ : P₂) (q₃ : P₃) (h : ∀ a b c, δ (mk rels₁ a) (mk rels₂ b) (mk rels₃ c)) : δ q₁ q₂ q₃ := Quotient.inductionOn₃ q₁ q₂ q₃ h end inductionOn variable {α : Type*} {rels : FreeMonoid α → FreeMonoid α → Prop} /-- The generators of a presented monoid generate the presented monoid. That is, the submonoid closure of the set of generators equals `⊤`. -/ @[to_additive (attr := simp) /-- The generators of a presented additive monoid generate the presented additive monoid. That is, the additive submonoid closure of the set of generators equals `⊤`. -/] theorem closure_range_of (rels : FreeMonoid α → FreeMonoid α → Prop) : Submonoid.closure (Set.range (PresentedMonoid.of rels)) = ⊤ := by rw [Submonoid.eq_top_iff'] intro x induction x with | _ a induction a with | one => exact Submonoid.one_mem _ | of x => exact subset_closure <| by simp [range, of] | mul x y hx hy => exact Submonoid.mul_mem _ hx hy @[to_additive] theorem surjective_mk {rels : FreeMonoid α → FreeMonoid α → Prop} : Function.Surjective (mk rels) := fun x ↦ PresentedMonoid.inductionOn x fun a ↦ .intro a rfl section ToMonoid variable {α M : Type*} [Monoid M] (f : α → M) variable {rels : FreeMonoid α → FreeMonoid α → Prop} variable (h : ∀ a b : FreeMonoid α, rels a b → FreeMonoid.lift f a = FreeMonoid.lift f b) /-- The extension of a map `f : α → M` that satisfies the given relations to a monoid homomorphism from `PresentedMonoid rels → M`. -/ @[to_additive /-- The extension of a map `f : α → M` that satisfies the given relations to an additive-monoid homomorphism from `PresentedAddMonoid rels → M` -/] def lift : PresentedMonoid rels →* M := Con.lift _ (FreeMonoid.lift f) (Con.conGen_le h) @[to_additive] theorem toMonoid.unique (g : MonoidHom (conGen rels).Quotient M) (hg : ∀ a : α, g (of rels a) = f a) : g = lift f h := Con.lift_unique (Con.conGen_le h) g (FreeMonoid.hom_eq hg) @[to_additive (attr := simp)] theorem lift_of {x : α} : lift f h (of rels x) = f x := rfl end ToMonoid @[to_additive (attr := ext)] theorem ext {M : Type*} [Monoid M] (rels : FreeMonoid α → FreeMonoid α → Prop) {φ ψ : PresentedMonoid rels →* M} (hx : ∀ (x : α), φ (.of rels x) = ψ (.of rels x)) : φ = ψ := by apply MonoidHom.eq_of_eqOn_denseM (closure_range_of _) grind [Set.eqOn_range] end PresentedMonoid
.lake/packages/mathlib/Mathlib/Algebra/EuclideanDomain/Int.lean
import Mathlib.Algebra.Group.Nat.Defs import Mathlib.Algebra.EuclideanDomain.Defs import Mathlib.Algebra.Order.Group.Unbundled.Int import Mathlib.Algebra.Ring.Int.Defs /-! # Instances for Euclidean domains * `Int.euclideanDomain`: shows that `ℤ` is a Euclidean domain. -/ instance Int.euclideanDomain : EuclideanDomain ℤ := { inferInstanceAs (CommRing Int), inferInstanceAs (Nontrivial Int) with quotient := (· / ·), quotient_zero := Int.ediv_zero, remainder := (· % ·), quotient_mul_add_remainder_eq := Int.mul_ediv_add_emod, r := fun a b => a.natAbs < b.natAbs, r_wellFounded := (measure natAbs).wf remainder_lt := fun a b b0 => Int.ofNat_lt.1 <| by rw [Int.natAbs_of_nonneg (Int.emod_nonneg _ b0), ← Int.abs_eq_natAbs] exact Int.emod_lt_abs _ b0 mul_left_not_lt := fun a b b0 => not_lt_of_ge <| by rw [← mul_one a.natAbs, Int.natAbs_mul] rw [← Int.natAbs_pos] at b0 exact Nat.mul_le_mul_left _ b0 }
.lake/packages/mathlib/Mathlib/Algebra/EuclideanDomain/Basic.lean
import Mathlib.Algebra.EuclideanDomain.Defs import Mathlib.Algebra.Ring.Divisibility.Basic import Mathlib.Algebra.Ring.Regular import Mathlib.Algebra.GroupWithZero.Divisibility import Mathlib.Algebra.Ring.Basic /-! # Lemmas about Euclidean domains ## Main statements * `gcd_eq_gcd_ab`: states Bézout's lemma for Euclidean domains. -/ universe u namespace EuclideanDomain variable {R : Type u} variable [EuclideanDomain R] /-- The well-founded relation in a Euclidean Domain satisfying `a % b ≺ b` for `b ≠ 0` -/ local infixl:50 " ≺ " => EuclideanDomain.r -- See note [lower instance priority] instance (priority := 100) toMulDivCancelClass : MulDivCancelClass R where mul_div_cancel a b hb := by refine (eq_of_sub_eq_zero ?_).symm by_contra h have := mul_right_not_lt b h rw [sub_mul, mul_comm (_ / _), sub_eq_iff_eq_add'.2 (div_add_mod (a * b) b).symm] at this exact this (mod_lt _ hb) theorem mod_eq_sub_mul_div {R : Type*} [EuclideanDomain R] (a b : R) : a % b = a - b * (a / b) := calc a % b = b * (a / b) + a % b - b * (a / b) := (add_sub_cancel_left _ _).symm _ = a - b * (a / b) := by rw [div_add_mod] theorem val_dvd_le : ∀ a b : R, b ∣ a → a ≠ 0 → ¬a ≺ b | _, b, ⟨d, rfl⟩, ha => mul_left_not_lt b (mt (by rintro rfl; exact mul_zero _) ha) @[simp] theorem mod_eq_zero {a b : R} : a % b = 0 ↔ b ∣ a := ⟨fun h => by rw [← div_add_mod a b, h, add_zero] exact dvd_mul_right _ _, fun ⟨c, e⟩ => by rw [e, ← add_left_cancel_iff, div_add_mod, add_zero] haveI := Classical.dec by_cases b0 : b = 0 · simp only [b0, zero_mul] · rw [mul_div_cancel_left₀ _ b0]⟩ @[simp] theorem mod_self (a : R) : a % a = 0 := mod_eq_zero.2 dvd_rfl theorem dvd_mod_iff {a b c : R} (h : c ∣ b) : c ∣ a % b ↔ c ∣ a := by rw [← dvd_add_right (h.mul_right _), div_add_mod] @[simp] theorem mod_one (a : R) : a % 1 = 0 := mod_eq_zero.2 (one_dvd _) @[simp] theorem zero_mod (b : R) : 0 % b = 0 := mod_eq_zero.2 (dvd_zero _) @[simp] theorem zero_div {a : R} : 0 / a = 0 := by_cases (fun a0 : a = 0 => a0.symm ▸ div_zero 0) fun a0 => by simpa only [zero_mul] using mul_div_cancel_right₀ 0 a0 @[simp] theorem div_self {a : R} (a0 : a ≠ 0) : a / a = 1 := by simpa only [one_mul] using mul_div_cancel_right₀ 1 a0 theorem eq_div_of_mul_eq_left {a b c : R} (hb : b ≠ 0) (h : a * b = c) : a = c / b := by rw [← h, mul_div_cancel_right₀ _ hb] theorem eq_div_of_mul_eq_right {a b c : R} (ha : a ≠ 0) (h : a * b = c) : b = c / a := by rw [← h, mul_div_cancel_left₀ _ ha] theorem mul_div_assoc (x : R) {y z : R} (h : z ∣ y) : x * y / z = x * (y / z) := by by_cases hz : z = 0 · subst hz rw [div_zero, div_zero, mul_zero] rcases h with ⟨p, rfl⟩ rw [mul_div_cancel_left₀ _ hz, mul_left_comm, mul_div_cancel_left₀ _ hz] protected theorem mul_div_cancel' {a b : R} (hb : b ≠ 0) (hab : b ∣ a) : b * (a / b) = a := by rw [← mul_div_assoc _ hab, mul_div_cancel_left₀ _ hb] -- This generalizes `Int.div_one`, see note [simp-normal form] @[simp] theorem div_one (p : R) : p / 1 = p := (EuclideanDomain.eq_div_of_mul_eq_left (one_ne_zero' R) (mul_one p)).symm theorem div_dvd_of_dvd {p q : R} (hpq : q ∣ p) : p / q ∣ p := by by_cases hq : q = 0 · rw [hq, zero_dvd_iff] at hpq rw [hpq] exact dvd_zero _ use q rw [mul_comm, ← EuclideanDomain.mul_div_assoc _ hpq, mul_comm, mul_div_cancel_right₀ _ hq] theorem dvd_div_of_mul_dvd {a b c : R} (h : a * b ∣ c) : b ∣ c / a := by rcases eq_or_ne a 0 with (rfl | ha) · simp only [div_zero, dvd_zero] rcases h with ⟨d, rfl⟩ refine ⟨d, ?_⟩ rw [mul_assoc, mul_div_cancel_left₀ _ ha] section GCD variable [DecidableEq R] @[simp] theorem gcd_zero_right (a : R) : gcd a 0 = a := by rw [gcd] split_ifs with h <;> simp only [h, zero_mod, gcd_zero_left] theorem gcd_val (a b : R) : gcd a b = gcd (b % a) a := by rw [gcd] split_ifs with h <;> [simp only [h, mod_zero, gcd_zero_right]; rfl] theorem gcd_dvd (a b : R) : gcd a b ∣ a ∧ gcd a b ∣ b := GCD.induction a b (fun b => by rw [gcd_zero_left] exact ⟨dvd_zero _, dvd_rfl⟩) fun a b _ ⟨IH₁, IH₂⟩ => by rw [gcd_val] exact ⟨IH₂, (dvd_mod_iff IH₂).1 IH₁⟩ theorem gcd_dvd_left (a b : R) : gcd a b ∣ a := (gcd_dvd a b).left theorem gcd_dvd_right (a b : R) : gcd a b ∣ b := (gcd_dvd a b).right protected theorem gcd_eq_zero_iff {a b : R} : gcd a b = 0 ↔ a = 0 ∧ b = 0 := ⟨fun h => by simpa [h] using gcd_dvd a b, by rintro ⟨rfl, rfl⟩ exact gcd_zero_right _⟩ theorem dvd_gcd {a b c : R} : c ∣ a → c ∣ b → c ∣ gcd a b := GCD.induction a b (fun _ _ H => by simpa only [gcd_zero_left] using H) fun a b _ IH ca cb => by rw [gcd_val] exact IH ((dvd_mod_iff ca).2 cb) ca theorem gcd_eq_left {a b : R} : gcd a b = a ↔ a ∣ b := ⟨fun h => by rw [← h] apply gcd_dvd_right, fun h => by rw [gcd_val, mod_eq_zero.2 h, gcd_zero_left]⟩ @[simp] theorem gcd_one_left (a : R) : gcd 1 a = 1 := gcd_eq_left.2 (one_dvd _) @[simp] theorem gcd_self (a : R) : gcd a a = a := gcd_eq_left.2 dvd_rfl @[simp] theorem xgcdAux_fst (x y : R) : ∀ s t s' t', (xgcdAux x s t y s' t').1 = gcd x y := GCD.induction x y (by intros rw [xgcd_zero_left, gcd_zero_left]) fun x y h IH s t s' t' => by simp only [xgcdAux_rec h, IH] rw [← gcd_val] theorem xgcdAux_val (x y : R) : xgcdAux x 1 0 y 0 1 = (gcd x y, xgcd x y) := by rw [xgcd, ← xgcdAux_fst x y 1 0 0 1] private def P (a b : R) : R × R × R → Prop | (r, s, t) => (r : R) = a * s + b * t theorem xgcdAux_P (a b : R) {r r' : R} {s t s' t'} (p : P a b (r, s, t)) (p' : P a b (r', s', t')) : P a b (xgcdAux r s t r' s' t') := by induction r, r' using GCD.induction generalizing s t s' t' with | H0 n => simpa only [xgcd_zero_left] | H1 _ _ h IH => rw [xgcdAux_rec h] refine IH ?_ p unfold P at p p' ⊢ dsimp rw [mul_sub, mul_sub, add_sub, sub_add_eq_add_sub, ← p', sub_sub, mul_comm _ s, ← mul_assoc, mul_comm _ t, ← mul_assoc, ← add_mul, ← p, mod_eq_sub_mul_div] /-- An explicit version of **Bézout's lemma** for Euclidean domains. -/ theorem gcd_eq_gcd_ab (a b : R) : (gcd a b : R) = a * gcdA a b + b * gcdB a b := by have := @xgcdAux_P _ _ _ a b a b 1 0 0 1 (by dsimp [P]; rw [mul_one, mul_zero, add_zero]) (by dsimp [P]; rw [mul_one, mul_zero, zero_add]) rwa [xgcdAux_val, xgcd_val] at this -- see Note [lower instance priority] instance (priority := 70) (R : Type*) [e : EuclideanDomain R] : NoZeroDivisors R := haveI := Classical.decEq R { eq_zero_or_eq_zero_of_mul_eq_zero := fun {a b} h => or_iff_not_and_not.2 fun h0 => h0.1 <| by rw [← mul_div_cancel_right₀ a h0.2, h, zero_div] } -- see Note [lower instance priority] instance (priority := 70) (R : Type*) [e : EuclideanDomain R] : IsDomain R := { e, NoZeroDivisors.to_isDomain R with } theorem div_pow {R : Type*} [EuclideanDomain R] {a b : R} {n : ℕ} (hab : b ∣ a) : (a / b) ^ n = a ^ n / b ^ n := by obtain ⟨c, rfl⟩ := hab obtain rfl | hb := eq_or_ne b 0 · obtain rfl | hn := eq_or_ne n 0 <;> simp [*] · simp [hb, mul_pow] end GCD section LCM variable [DecidableEq R] theorem dvd_lcm_left (x y : R) : x ∣ lcm x y := by_cases (fun hxy : gcd x y = 0 => by rw [lcm, hxy, div_zero] exact dvd_zero _) fun hxy => let ⟨z, hz⟩ := (gcd_dvd x y).2 ⟨z, Eq.symm <| eq_div_of_mul_eq_left hxy <| by rw [mul_right_comm, mul_assoc, ← hz]⟩ theorem dvd_lcm_right (x y : R) : y ∣ lcm x y := by_cases (fun hxy : gcd x y = 0 => by rw [lcm, hxy, div_zero] exact dvd_zero _) fun hxy => let ⟨z, hz⟩ := (gcd_dvd x y).1 ⟨z, Eq.symm <| eq_div_of_mul_eq_right hxy <| by rw [← mul_assoc, mul_right_comm, ← hz]⟩ theorem lcm_dvd {x y z : R} (hxz : x ∣ z) (hyz : y ∣ z) : lcm x y ∣ z := by rw [lcm] by_cases hxy : gcd x y = 0 · rw [hxy, div_zero] rw [EuclideanDomain.gcd_eq_zero_iff] at hxy rwa [hxy.1] at hxz rcases gcd_dvd x y with ⟨⟨r, hr⟩, ⟨s, hs⟩⟩ suffices x * y ∣ z * gcd x y by obtain ⟨p, hp⟩ := this use p generalize gcd x y = g at hxy hs hp ⊢ subst hs rw [mul_left_comm, mul_div_cancel_left₀ _ hxy, ← mul_left_inj' hxy, hp] rw [← mul_assoc] simp only [mul_right_comm] rw [gcd_eq_gcd_ab, mul_add] apply dvd_add · rw [mul_left_comm] gcongr apply hyz.mul_right · rw [mul_left_comm, mul_comm] gcongr apply hxz.mul_right @[simp] theorem lcm_dvd_iff {x y z : R} : lcm x y ∣ z ↔ x ∣ z ∧ y ∣ z := ⟨fun hz => ⟨(dvd_lcm_left _ _).trans hz, (dvd_lcm_right _ _).trans hz⟩, fun ⟨hxz, hyz⟩ => lcm_dvd hxz hyz⟩ @[simp] theorem lcm_zero_left (x : R) : lcm 0 x = 0 := by rw [lcm, zero_mul, zero_div] @[simp] theorem lcm_zero_right (x : R) : lcm x 0 = 0 := by rw [lcm, mul_zero, zero_div] @[simp] theorem lcm_eq_zero_iff {x y : R} : lcm x y = 0 ↔ x = 0 ∨ y = 0 := by constructor · intro hxy rw [lcm, mul_div_assoc _ (gcd_dvd_right _ _), mul_eq_zero] at hxy apply Or.imp_right _ hxy intro hy by_cases hgxy : gcd x y = 0 · rw [EuclideanDomain.gcd_eq_zero_iff] at hgxy exact hgxy.2 · rcases gcd_dvd x y with ⟨⟨r, hr⟩, ⟨s, hs⟩⟩ generalize gcd x y = g at hr hs hy hgxy ⊢ subst hs rw [mul_div_cancel_left₀ _ hgxy] at hy rw [hy, mul_zero] rintro (hx | hy) · rw [hx, lcm_zero_left] · rw [hy, lcm_zero_right] @[simp] theorem gcd_mul_lcm (x y : R) : gcd x y * lcm x y = x * y := by rw [lcm]; by_cases h : gcd x y = 0 · rw [h, zero_mul] rw [EuclideanDomain.gcd_eq_zero_iff] at h rw [h.1, zero_mul] rcases gcd_dvd x y with ⟨⟨r, hr⟩, ⟨s, hs⟩⟩ generalize gcd x y = g at h hr ⊢; subst hr rw [mul_assoc, mul_div_cancel_left₀ _ h] end LCM section Div theorem mul_div_mul_cancel {a b c : R} (ha : a ≠ 0) (hcb : c ∣ b) : a * b / (a * c) = b / c := by by_cases hc : c = 0; · simp [hc] refine eq_div_of_mul_eq_right hc (mul_left_cancel₀ ha ?_) rw [← mul_assoc, ← mul_div_assoc _ (by gcongr), mul_div_cancel_left₀ _ (mul_ne_zero ha hc)] theorem mul_div_mul_comm_of_dvd_dvd {a b c d : R} (hac : c ∣ a) (hbd : d ∣ b) : a * b / (c * d) = a / c * (b / d) := by rcases eq_or_ne c 0 with (rfl | hc0); · simp rcases eq_or_ne d 0 with (rfl | hd0); · simp obtain ⟨k1, rfl⟩ := hac obtain ⟨k2, rfl⟩ := hbd rw [mul_div_cancel_left₀ _ hc0, mul_div_cancel_left₀ _ hd0, mul_mul_mul_comm, mul_div_cancel_left₀ _ (mul_ne_zero hc0 hd0)] theorem add_mul_div_left (x y z : R) (h1 : y ≠ 0) (h2 : y ∣ x) : (x + y * z) / y = x / y + z := by rw [eq_comm] apply eq_div_of_mul_eq_right h1 rw [mul_add, EuclideanDomain.mul_div_cancel' h1 h2] theorem add_mul_div_right (x y z : R) (h1 : y ≠ 0) (h2 : y ∣ x) : (x + z * y) / y = x / y + z := by rw [mul_comm z y] exact add_mul_div_left _ _ _ h1 h2 theorem sub_mul_div_left (x y z : R) (h1 : y ≠ 0) (h2 : y ∣ x) : (x - y * z) / y = x / y - z := by rw [eq_comm] apply eq_div_of_mul_eq_right h1 rw [mul_sub, EuclideanDomain.mul_div_cancel' h1 h2] theorem sub_mul_div_right (x y z : R) (h1 : y ≠ 0) (h2 : y ∣ x) : (x - z * y) / y = x / y - z := by rw [mul_comm z y] exact sub_mul_div_left _ _ _ h1 h2 theorem mul_add_div_left (x y z : R) (h1 : z ≠ 0) (h2 : z ∣ y) : (z * x + y) / z = x + y / z := by rw [eq_comm] apply eq_div_of_mul_eq_right h1 rw [mul_add, EuclideanDomain.mul_div_cancel' h1 h2] theorem mul_add_div_right (x y z : R) (h1 : z ≠ 0) (h2 : z ∣ y) : (x * z + y) / z = x + y / z := by rw [mul_comm x z] exact mul_add_div_left _ _ _ h1 h2 theorem mul_sub_div_left (x y z : R) (h1 : z ≠ 0) (h2 : z ∣ y) : (z * x - y) / z = x - y / z := by rw [eq_comm] apply eq_div_of_mul_eq_right h1 rw [mul_sub, EuclideanDomain.mul_div_cancel' h1 h2] theorem mul_sub_div_right (x y z : R) (h1 : z ≠ 0) (h2 : z ∣ y) : (x * z - y) / z = x - y / z := by rw [mul_comm x z] exact mul_sub_div_left _ _ _ h1 h2 theorem div_mul {x y z : R} (h1 : y ∣ x) (h2 : y * z ∣ x) : x / (y * z) = x / y / z := by rcases eq_or_ne z 0 with rfl | hz · simp only [mul_zero, div_zero] apply eq_div_of_mul_eq_right hz rw [← EuclideanDomain.mul_div_assoc z h2, mul_comm y z, mul_div_mul_cancel hz h1] theorem div_div {x y z : R} (h1 : y ∣ x) (h2 : z ∣ (x / y)) : x / y / z = x / (y * z) := by rcases eq_or_ne y 0 with rfl | hy · simp only [div_zero, zero_div, zero_mul] rw [← mul_dvd_mul_iff_left hy, EuclideanDomain.mul_div_cancel' hy h1] at h2 exact (div_mul h1 h2).symm theorem div_add_div_of_dvd {x y z t : R} (h1 : y ≠ 0) (h2 : t ≠ 0) (h3 : y ∣ x) (h4 : t ∣ z) : x / y + z / t = (t * x + y * z) / (t * y) := by apply eq_div_of_mul_eq_right (mul_ne_zero h2 h1) rw [mul_add, mul_assoc, EuclideanDomain.mul_div_cancel' h1 h3, mul_comm t y, mul_assoc, EuclideanDomain.mul_div_cancel' h2 h4] theorem div_sub_div_of_dvd {x y z t : R} (h1 : y ≠ 0) (h2 : t ≠ 0) (h3 : y ∣ x) (h4 : t ∣ z) : x / y - z / t = (t * x - y * z) / (t * y) := by apply eq_div_of_mul_eq_right (mul_ne_zero h2 h1) rw [mul_sub, mul_assoc, EuclideanDomain.mul_div_cancel' h1 h3, mul_comm t y, mul_assoc, EuclideanDomain.mul_div_cancel' h2 h4] theorem div_eq_iff_eq_mul_of_dvd (x y z : R) (h1 : y ≠ 0) (h2 : y ∣ x) : x / y = z ↔ x = y * z := by obtain ⟨a, ha⟩ := h2 rw [ha, mul_div_cancel_left₀ _ h1] simp only [mul_eq_mul_left_iff, h1, or_false] theorem eq_div_iff_mul_eq_of_dvd (x y z : R) (h1 : z ≠ 0) (h2 : z ∣ y) : x = y / z ↔ z * x = y := by rw [eq_comm, div_eq_iff_eq_mul_of_dvd _ _ _ h1 h2, eq_comm] theorem div_eq_div_iff_mul_eq_mul_of_dvd {x y z t : R} (h1 : y ≠ 0) (h2 : t ≠ 0) (h3 : y ∣ x) (h4 : t ∣ z) : x / y = z / t ↔ t * x = y * z := by rw [div_eq_iff_eq_mul_of_dvd _ _ _ h1 h3, ← mul_div_assoc _ h4, eq_div_iff_mul_eq_of_dvd _ _ _ h2] obtain ⟨a, ha⟩ := h4 use y * a rw [ha, mul_comm, mul_assoc, mul_comm y a] end Div end EuclideanDomain
.lake/packages/mathlib/Mathlib/Algebra/EuclideanDomain/Defs.lean
import Mathlib.Algebra.Ring.Defs import Mathlib.Order.RelClasses /-! # Euclidean domains This file introduces Euclidean domains and provides the extended Euclidean algorithm. To be precise, a slightly more general version is provided which is sometimes called a transfinite Euclidean domain and differs in the fact that the degree function need not take values in `ℕ` but can take values in any well-ordered set. Transfinite Euclidean domains were introduced by Motzkin and examples which don't satisfy the classical notion were provided independently by Hiblot and Nagata. ## Main definitions * `EuclideanDomain`: Defines Euclidean domain with functions `quotient` and `remainder`. Instances of `Div` and `Mod` are provided, so that one can write `a = b * (a / b) + a % b`. * `gcd`: defines the greatest common divisors of two elements of a Euclidean domain. * `xgcd`: given two elements `a b : R`, `xgcd a b` defines the pair `(x, y)` such that `x * a + y * b = gcd a b`. * `lcm`: defines the lowest common multiple of two elements `a` and `b` of a Euclidean domain as `a * b / (gcd a b)` ## Main statements See `Algebra.EuclideanDomain.Basic` for most of the theorems about Euclidean domains, including Bézout's lemma. See `Algebra.EuclideanDomain.Instances` for the fact that `ℤ` is a Euclidean domain, as is any field. ## Notation `≺` denotes the well-founded relation on the Euclidean domain, e.g. in the example of the polynomial ring over a field, `p ≺ q` for polynomials `p` and `q` if and only if the degree of `p` is less than the degree of `q`. ## Implementation details Instead of working with a valuation, `EuclideanDomain` is implemented with the existence of a well founded relation `r` on the integral domain `R`, which in the example of `ℤ` would correspond to setting `i ≺ j` for integers `i` and `j` if the absolute value of `i` is smaller than the absolute value of `j`. ## References * [Th. Motzkin, *The Euclidean algorithm*][MR32592] * [J.-J. Hiblot, *Des anneaux euclidiens dont le plus petit algorithme n'est pas à valeurs finies*] [MR399081] * [M. Nagata, *On Euclid algorithm*][MR541021] ## Tags Euclidean domain, transfinite Euclidean domain, Bézout's lemma -/ universe u /-- A `EuclideanDomain` is a non-trivial commutative ring with a division and a remainder, satisfying `b * (a / b) + a % b = a`. The definition of a Euclidean domain usually includes a valuation function `R → ℕ`. This definition is slightly generalised to include a well-founded relation `r` with the property that `r (a % b) b`, instead of a valuation. -/ class EuclideanDomain (R : Type u) extends CommRing R, Nontrivial R where /-- A division function (denoted `/`) on `R`. This satisfies the property `b * (a / b) + a % b = a`, where `%` denotes `remainder`. -/ protected quotient : R → R → R /-- Division by zero should always give zero by convention. -/ protected quotient_zero : ∀ a, quotient a 0 = 0 /-- A remainder function (denoted `%`) on `R`. This satisfies the property `b * (a / b) + a % b = a`, where `/` denotes `quotient`. -/ protected remainder : R → R → R /-- The property that links the quotient and remainder functions. This allows us to compute GCDs and LCMs. -/ protected quotient_mul_add_remainder_eq : ∀ a b, b * quotient a b + remainder a b = a /-- A well-founded relation on `R`, satisfying `r (a % b) b`. This ensures that the GCD algorithm always terminates. -/ protected r : R → R → Prop /-- The relation `r` must be well-founded. This ensures that the GCD algorithm always terminates. -/ r_wellFounded : WellFounded r /-- The relation `r` satisfies `r (a % b) b`. -/ protected remainder_lt : ∀ (a) {b}, b ≠ 0 → r (remainder a b) b /-- An additional constraint on `r`. -/ mul_left_not_lt : ∀ (a) {b}, b ≠ 0 → ¬r (a * b) a namespace EuclideanDomain variable {R : Type u} [EuclideanDomain R] /-- Abbreviated notation for the well-founded relation `r` in a Euclidean domain. -/ local infixl:50 " ≺ " => EuclideanDomain.r local instance wellFoundedRelation : WellFoundedRelation R where rel := EuclideanDomain.r wf := r_wellFounded instance isWellFounded : IsWellFounded R (· ≺ ·) where wf := r_wellFounded -- see Note [lower instance priority] instance (priority := 70) : Div R := ⟨EuclideanDomain.quotient⟩ -- see Note [lower instance priority] instance (priority := 70) : Mod R := ⟨EuclideanDomain.remainder⟩ theorem div_add_mod (a b : R) : b * (a / b) + a % b = a := EuclideanDomain.quotient_mul_add_remainder_eq _ _ theorem mod_add_div (a b : R) : a % b + b * (a / b) = a := (add_comm _ _).trans (div_add_mod _ _) theorem mod_add_div' (m k : R) : m % k + m / k * k = m := by rw [mul_comm] exact mod_add_div _ _ theorem div_add_mod' (m k : R) : m / k * k + m % k = m := by rw [mul_comm] exact div_add_mod _ _ theorem mod_lt : ∀ (a) {b : R}, b ≠ 0 → a % b ≺ b := EuclideanDomain.remainder_lt theorem mul_right_not_lt {a : R} (b) (h : a ≠ 0) : ¬a * b ≺ b := by rw [mul_comm] exact mul_left_not_lt b h @[simp] theorem mod_zero (a : R) : a % 0 = a := by simpa only [zero_mul, zero_add] using div_add_mod a 0 theorem lt_one (a : R) : a ≺ (1 : R) → a = 0 := haveI := Classical.dec not_imp_not.1 fun h => by simpa only [one_mul] using mul_left_not_lt 1 h @[simp] theorem div_zero (a : R) : a / 0 = 0 := EuclideanDomain.quotient_zero a section @[elab_as_elim] theorem GCD.induction {P : R → R → Prop} (a b : R) (H0 : ∀ x, P 0 x) (H1 : ∀ a b, a ≠ 0 → P (b % a) a → P a b) : P a b := by classical exact if a0 : a = 0 then a0.symm ▸ H0 b else have _ := mod_lt b a0 H1 _ _ a0 (GCD.induction (b % a) a H0 H1) termination_by a end section GCD variable [DecidableEq R] /-- `gcd a b` is a (non-unique) element such that `gcd a b ∣ a` `gcd a b ∣ b`, and for any element `c` such that `c ∣ a` and `c ∣ b`, then `c ∣ gcd a b` -/ def gcd (a b : R) : R := if a0 : a = 0 then b else have _ := mod_lt b a0 gcd (b % a) a termination_by a @[simp] theorem gcd_zero_left (a : R) : gcd 0 a = a := by rw [gcd] exact if_pos rfl /-- An implementation of the extended GCD algorithm. At each step we are computing a triple `(r, s, t)`, where `r` is the next value of the GCD algorithm, to compute the greatest common divisor of the input (say `x` and `y`), and `s` and `t` are the coefficients in front of `x` and `y` to obtain `r` (i.e. `r = s * x + t * y`). The function `xgcdAux` takes in two triples, and from these recursively computes the next triple: ``` xgcdAux (r, s, t) (r', s', t') = xgcdAux (r' % r, s' - (r' / r) * s, t' - (r' / r) * t) (r, s, t) ``` -/ def xgcdAux (r s t r' s' t' : R) : R × R × R := if _hr : r = 0 then (r', s', t') else let q := r' / r have _ := mod_lt r' _hr xgcdAux (r' % r) (s' - q * s) (t' - q * t) r s t termination_by r @[simp] theorem xgcd_zero_left {s t r' s' t' : R} : xgcdAux 0 s t r' s' t' = (r', s', t') := by unfold xgcdAux exact if_pos rfl theorem xgcdAux_rec {r s t r' s' t' : R} (h : r ≠ 0) : xgcdAux r s t r' s' t' = xgcdAux (r' % r) (s' - r' / r * s) (t' - r' / r * t) r s t := by conv => lhs rw [xgcdAux] exact if_neg h /-- Use the extended GCD algorithm to generate the `a` and `b` values satisfying `gcd x y = x * a + y * b`. -/ def xgcd (x y : R) : R × R := (xgcdAux x 1 0 y 0 1).2 /-- The extended GCD `a` value in the equation `gcd x y = x * a + y * b`. -/ def gcdA (x y : R) : R := (xgcd x y).1 /-- The extended GCD `b` value in the equation `gcd x y = x * a + y * b`. -/ def gcdB (x y : R) : R := (xgcd x y).2 @[simp] theorem gcdA_zero_left {s : R} : gcdA 0 s = 0 := by unfold gcdA rw [xgcd, xgcd_zero_left] @[simp] theorem gcdB_zero_left {s : R} : gcdB 0 s = 1 := by unfold gcdB rw [xgcd, xgcd_zero_left] theorem xgcd_val (x y : R) : xgcd x y = (gcdA x y, gcdB x y) := rfl end GCD section LCM variable [DecidableEq R] /-- `lcm a b` is a (non-unique) element such that `a ∣ lcm a b` `b ∣ lcm a b`, and for any element `c` such that `a ∣ c` and `b ∣ c`, then `lcm a b ∣ c` -/ def lcm (x y : R) : R := x * y / gcd x y end LCM end EuclideanDomain
.lake/packages/mathlib/Mathlib/Algebra/EuclideanDomain/Field.lean
import Mathlib.Algebra.EuclideanDomain.Defs import Mathlib.Algebra.Field.Defs import Mathlib.Algebra.GroupWithZero.Units.Basic /-! # Instances for Euclidean domains * `Field.toEuclideanDomain`: shows that any field is a Euclidean domain. -/ namespace Field variable {K : Type*} [Field K] -- see Note [lower instance priority] instance (priority := 100) toEuclideanDomain : EuclideanDomain K := { toCommRing := toCommRing quotient := (· / ·), remainder := fun a b => a - a * b / b, quotient_zero := div_zero, quotient_mul_add_remainder_eq := fun a b => by by_cases h : b = 0 <;> simp [h, mul_div_cancel₀] r := fun a b => a = 0 ∧ b ≠ 0, r_wellFounded := WellFounded.intro fun _ => (Acc.intro _) fun _ ⟨hb, _⟩ => (Acc.intro _) fun _ ⟨_, hnb⟩ => False.elim <| hnb hb, remainder_lt := fun a b hnb => by simp [hnb], mul_left_not_lt := fun _ _ hnb ⟨hab, hna⟩ => Or.casesOn (mul_eq_zero.1 hab) hna hnb } @[simp] protected theorem mod_eq (a b : K) : a % b = a - a * b / b := rfl @[simp] protected theorem gcd_eq [DecidableEq K] (a b : K) : EuclideanDomain.gcd a b = if a = 0 then b else a := by unfold EuclideanDomain.gcd split_ifs <;> simp [*, Field.mod_eq] protected theorem gcd_zero_eq [DecidableEq K] (b : K) : EuclideanDomain.gcd 0 b = b := by rw [Field.gcd_eq, if_pos rfl] protected theorem gcd_eq_of_ne [DecidableEq K] {a : K} (ha : a ≠ 0) (b : K) : EuclideanDomain.gcd a b = a := by rw [Field.gcd_eq, if_neg ha] end Field
.lake/packages/mathlib/Mathlib/Algebra/GroupWithZero/Idempotent.lean
import Mathlib.Algebra.Group.Idempotent import Mathlib.Algebra.GroupWithZero.Defs /-! # Idempotent elements of a group with zero -/ assert_not_exists Ring variable {M N S M₀ M₁ R G G₀ : Type*} variable [MulOneClass M₁] [CancelMonoidWithZero G₀] namespace IsIdempotentElem section MulZeroClass variable [MulZeroClass M₀] lemma zero : IsIdempotentElem (0 : M₀) := mul_zero _ instance : Zero { p : M₀ // IsIdempotentElem p } where zero := ⟨0, zero⟩ @[simp] lemma coe_zero : ↑(0 : { p : M₀ // IsIdempotentElem p }) = (0 : M₀) := rfl end MulZeroClass section CancelMonoidWithZero variable [CancelMonoidWithZero M₀] @[simp] lemma iff_eq_zero_or_one {p : G₀} : IsIdempotentElem p ↔ p = 0 ∨ p = 1 where mp h := or_iff_not_imp_left.mpr fun hp ↦ mul_left_cancel₀ hp (h.trans (mul_one p).symm) mpr h := h.elim (fun hp => hp.symm ▸ zero) fun hp => hp.symm ▸ one end CancelMonoidWithZero end IsIdempotentElem
.lake/packages/mathlib/Mathlib/Algebra/GroupWithZero/Opposite.lean
import Mathlib.Algebra.Group.Opposite import Mathlib.Algebra.GroupWithZero.InjSurj import Mathlib.Algebra.GroupWithZero.NeZero /-! # Opposites of groups with zero -/ assert_not_exists Ring variable {α : Type*} namespace MulOpposite instance instMulZeroClass [MulZeroClass α] : MulZeroClass αᵐᵒᵖ where zero_mul _ := unop_injective <| mul_zero _ mul_zero _ := unop_injective <| zero_mul _ instance instMulZeroOneClass [MulZeroOneClass α] : MulZeroOneClass αᵐᵒᵖ where __ := instMulOneClass __ := instMulZeroClass instance instSemigroupWithZero [SemigroupWithZero α] : SemigroupWithZero αᵐᵒᵖ where __ := instSemigroup __ := instMulZeroClass instance instMonoidWithZero [MonoidWithZero α] : MonoidWithZero αᵐᵒᵖ where __ := instMonoid __ := instMulZeroOneClass instance instGroupWithZero [GroupWithZero α] : GroupWithZero αᵐᵒᵖ where __ := instMonoidWithZero __ := instNontrivial __ := instDivInvMonoid mul_inv_cancel _ hx := unop_injective <| inv_mul_cancel₀ <| unop_injective.ne hx inv_zero := unop_injective inv_zero instance instNoZeroDivisors [Zero α] [Mul α] [NoZeroDivisors α] : NoZeroDivisors αᵐᵒᵖ where eq_zero_or_eq_zero_of_mul_eq_zero (H : op (_ * _) = op (0 : α)) := Or.casesOn (eq_zero_or_eq_zero_of_mul_eq_zero <| op_injective H) (fun hy => Or.inr <| unop_injective <| hy) fun hx => Or.inl <| unop_injective <| hx instance [Mul α] [Zero α] [IsLeftCancelMulZero α] : IsRightCancelMulZero αᵐᵒᵖ where mul_right_cancel_of_ne_zero h _ _ eq := unop_injective <| mul_left_cancel₀ (unop_injective.ne_iff.mpr h) (congr_arg unop eq) instance [Mul α] [Zero α] [IsRightCancelMulZero α] : IsLeftCancelMulZero αᵐᵒᵖ where mul_left_cancel_of_ne_zero h _ _ eq := unop_injective <| mul_right_cancel₀ (unop_injective.ne_iff.mpr h) (congr_arg unop eq) instance [Mul α] [Zero α] [IsCancelMulZero α] : IsCancelMulZero αᵐᵒᵖ where @[simp] theorem isLeftCancelMulZero_iff [Mul α] [Zero α] : IsLeftCancelMulZero αᵐᵒᵖ ↔ IsRightCancelMulZero α where mp _ := (op_injective.comp op_injective).isRightCancelMulZero _ rfl fun _ _ ↦ rfl mpr _ := inferInstance @[simp] theorem isRightCancelMulZero_iff [Mul α] [Zero α] : IsRightCancelMulZero αᵐᵒᵖ ↔ IsLeftCancelMulZero α where mp _ := (op_injective.comp op_injective).isLeftCancelMulZero _ rfl fun _ _ ↦ rfl mpr _ := inferInstance @[simp] theorem isCancelMulZero_iff [Mul α] [Zero α] : IsCancelMulZero αᵐᵒᵖ ↔ IsCancelMulZero α where mp _ := (op_injective.comp op_injective).isCancelMulZero _ rfl fun _ _ ↦ rfl mpr _ := inferInstance end MulOpposite namespace AddOpposite instance instMulZeroClass [MulZeroClass α] : MulZeroClass αᵃᵒᵖ where zero_mul _ := unop_injective <| zero_mul _ mul_zero _ := unop_injective <| mul_zero _ instance instMulZeroOneClass [MulZeroOneClass α] : MulZeroOneClass αᵃᵒᵖ where __ := instMulOneClass __ := instMulZeroClass instance instSemigroupWithZero [SemigroupWithZero α] : SemigroupWithZero αᵃᵒᵖ where __ := instSemigroup __ := instMulZeroClass instance instMonoidWithZero [MonoidWithZero α] : MonoidWithZero αᵃᵒᵖ where __ := instMonoid __ := instMulZeroOneClass instance instNoZeroDivisors [Zero α] [Mul α] [NoZeroDivisors α] : NoZeroDivisors αᵃᵒᵖ where eq_zero_or_eq_zero_of_mul_eq_zero (H : op (_ * _) = op (0 : α)) := Or.imp (fun hx => unop_injective hx) (fun hy => unop_injective hy) (@eq_zero_or_eq_zero_of_mul_eq_zero α _ _ _ _ _ <| op_injective H) instance instGroupWithZero [GroupWithZero α] : GroupWithZero αᵃᵒᵖ where __ := instMonoidWithZero __ := instNontrivial __ := instDivInvMonoid mul_inv_cancel _ hx := unop_injective <| mul_inv_cancel₀ <| unop_injective.ne hx inv_zero := unop_injective inv_zero end AddOpposite
.lake/packages/mathlib/Mathlib/Algebra/GroupWithZero/Semiconj.lean
import Mathlib.Algebra.GroupWithZero.Units.Basic import Mathlib.Algebra.Group.Semiconj.Units /-! # Lemmas about semiconjugate elements in a `GroupWithZero`. -/ assert_not_exists DenselyOrdered Ring variable {G₀ : Type*} namespace SemiconjBy @[simp] theorem zero_right [MulZeroClass G₀] (a : G₀) : SemiconjBy a 0 0 := by simp only [SemiconjBy, mul_zero, zero_mul] @[simp] theorem zero_left [MulZeroClass G₀] (x y : G₀) : SemiconjBy 0 x y := by simp only [SemiconjBy, mul_zero, zero_mul] variable [GroupWithZero G₀] {a x y x' y' : G₀} @[simp] theorem inv_symm_left_iff₀ : SemiconjBy a⁻¹ x y ↔ SemiconjBy a y x := Classical.by_cases (fun ha : a = 0 => by simp only [ha, inv_zero, SemiconjBy.zero_left]) fun ha => @units_inv_symm_left_iff _ _ (Units.mk0 a ha) _ _ theorem inv_symm_left₀ (h : SemiconjBy a x y) : SemiconjBy a⁻¹ y x := SemiconjBy.inv_symm_left_iff₀.2 h theorem inv_right₀ (h : SemiconjBy a x y) : SemiconjBy a x⁻¹ y⁻¹ := by by_cases ha : a = 0 · simp only [ha, zero_left] by_cases hx : x = 0 · subst x simp only [SemiconjBy, mul_zero, @eq_comm _ _ (y * a), mul_eq_zero] at h simp [h.resolve_right ha] · have := mul_ne_zero ha hx rw [h.eq, mul_ne_zero_iff] at this exact @units_inv_right _ _ _ (Units.mk0 x hx) (Units.mk0 y this.1) h @[simp] theorem inv_right_iff₀ : SemiconjBy a x⁻¹ y⁻¹ ↔ SemiconjBy a x y := ⟨fun h => inv_inv x ▸ inv_inv y ▸ h.inv_right₀, inv_right₀⟩ theorem div_right (h : SemiconjBy a x y) (h' : SemiconjBy a x' y') : SemiconjBy a (x / x') (y / y') := by rw [div_eq_mul_inv, div_eq_mul_inv] exact h.mul_right h'.inv_right₀ lemma zpow_right₀ {a x y : G₀} (h : SemiconjBy a x y) : ∀ m : ℤ, SemiconjBy a (x ^ m) (y ^ m) | (n : ℕ) => by simp [h.pow_right n] | .negSucc n => by simp only [zpow_negSucc, (h.pow_right (n + 1)).inv_right₀] end SemiconjBy namespace Commute variable [GroupWithZero G₀] {a b : G₀} lemma zpow_right₀ (h : Commute a b) : ∀ m : ℤ, Commute a (b ^ m) := SemiconjBy.zpow_right₀ h lemma zpow_left₀ (h : Commute a b) (m : ℤ) : Commute (a ^ m) b := (h.symm.zpow_right₀ m).symm lemma zpow_zpow₀ (h : Commute a b) (m n : ℤ) : Commute (a ^ m) (b ^ n) := (h.zpow_left₀ m).zpow_right₀ n lemma zpow_self₀ (a : G₀) (n : ℤ) : Commute (a ^ n) a := (Commute.refl a).zpow_left₀ n lemma self_zpow₀ (a : G₀) (n : ℤ) : Commute a (a ^ n) := (Commute.refl a).zpow_right₀ n lemma zpow_zpow_self₀ (a : G₀) (m n : ℤ) : Commute (a ^ m) (a ^ n) := (Commute.refl a).zpow_zpow₀ m n end Commute
.lake/packages/mathlib/Mathlib/Algebra/GroupWithZero/Int.lean
import Mathlib.Algebra.Group.Int.Defs import Mathlib.Algebra.GroupWithZero.WithZero /-! # Lemmas about `ℤᵐ⁰`. -/ assert_not_exists Ring open Multiplicative namespace WithZero @[deprecated exp_zsmul (since := "2025-05-17")] theorem ofAdd_zpow (a : ℤ) : (↑(ofAdd a) : ℤᵐ⁰) = ofAdd (1 : ℤ) ^ a := show exp a = exp 1 ^ a by simp @[deprecated exp_neg (since := "2025-05-17")] theorem ofAdd_neg_one_pow_comm (a : ℤ) (n : ℕ) : ((↑(ofAdd (-1 : ℤ)) : ℤᵐ⁰) ^ (-a)) ^ n = ofAdd (n : ℤ) ^ a := show (exp (-1 : ℤ) ^ (-a)) ^ n = exp (n : ℤ) ^ a by simp [mul_comm] end WithZero
.lake/packages/mathlib/Mathlib/Algebra/GroupWithZero/WithZero.lean
import Mathlib.Algebra.Group.TypeTags.Basic import Mathlib.Algebra.Group.WithOne.Defs import Mathlib.Algebra.GroupWithZero.Equiv import Mathlib.Algebra.GroupWithZero.Units.Basic import Mathlib.Data.Nat.Cast.Defs import Mathlib.Data.Option.Basic import Mathlib.Data.Option.NAry /-! # Adjoining a zero to a group This file proves that one can adjoin a new zero element to a group and get a group with zero. In valuation theory, valuations have codomain `{0} ∪ {c ^ n | n : ℤ}` for some `c > 1`, which we can formalise as `ℤᵐ⁰ := WithZero (Multiplicative ℤ)`. It is important to be able to talk about the maps `n ↦ c ^ n` and `c ^ n ↦ n`. We define these as `exp : ℤ → ℤᵐ⁰` and `log : ℤᵐ⁰ → ℤ` with junk value `log 0 = 0`. Junkless versions are defined as `expEquiv : ℤ ≃ ℤᵐ⁰ˣ` and `logEquiv : ℤᵐ⁰ˣ ≃ ℤ`. ## Notation In scope `WithZero`: * `Mᵐ⁰` for `WithZero (Multiplicative M)` ## Main definitions * `WithZero.map'`: the `MonoidWithZero` homomorphism `WithZero α →* WithZero β` induced by a monoid homomorphism `f : α →* β`. * `WithZero.exp`: The "exponential map" `M → Mᵐ⁰` * `WithZero.exp`: The "logarithm" `Mᵐ⁰ → M` -/ open Function assert_not_exists DenselyOrdered Ring namespace WithZero variable {α β γ : Type*} section One variable [One α] instance one : One (WithZero α) where __ := ‹One α› @[simp, norm_cast] lemma coe_one : ((1 : α) : WithZero α) = 1 := rfl @[simp] lemma recZeroCoe_one {M N : Type*} [One M] (f : M → N) (z : N) : recZeroCoe z f 1 = f 1 := rfl end One section Mul variable [Mul α] instance instMulZeroClass : MulZeroClass (WithZero α) where mul := Option.map₂ (· * ·) zero_mul := Option.map₂_none_left (· * ·) mul_zero := Option.map₂_none_right (· * ·) @[simp, norm_cast] lemma coe_mul (a b : α) : (↑(a * b) : WithZero α) = a * b := rfl lemma unzero_mul {x y : WithZero α} (hxy : x * y ≠ 0) : unzero hxy = unzero (left_ne_zero_of_mul hxy) * unzero (right_ne_zero_of_mul hxy) := by simp only [← coe_inj, coe_mul, coe_unzero] instance instNoZeroDivisors : NoZeroDivisors (WithZero α) := ⟨Option.map₂_eq_none_iff.1⟩ end Mul instance instSemigroupWithZero [Semigroup α] : SemigroupWithZero (WithZero α) where mul_assoc _ _ _ := Option.map₂_assoc mul_assoc instance instCommSemigroup [CommSemigroup α] : CommSemigroup (WithZero α) where mul_comm _ _ := Option.map₂_comm mul_comm section MulOneClass variable [MulOneClass α] instance instMulZeroOneClass [MulOneClass α] : MulZeroOneClass (WithZero α) where one_mul := Option.map₂_left_identity one_mul mul_one := Option.map₂_right_identity mul_one /-- Coercion as a monoid hom. -/ @[simps apply] def coeMonoidHom : α →* WithZero α where toFun := (↑) map_one' := rfl map_mul' _ _ := rfl section lift variable [MulZeroOneClass β] -- See note [partially-applied ext lemmas] @[ext high] theorem monoidWithZeroHom_ext ⦃f g : WithZero α →*₀ β⦄ (h : f.toMonoidHom.comp coeMonoidHom = g.toMonoidHom.comp coeMonoidHom) : f = g := DFunLike.ext _ _ fun | 0 => (map_zero f).trans (map_zero g).symm | (g : α) => DFunLike.congr_fun h g /-- The (multiplicative) universal property of `WithZero`. -/ @[simps! symm_apply_apply] nonrec def lift' : (α →* β) ≃ (WithZero α →*₀ β) where toFun f := { toFun := recZeroCoe 0 f map_zero' := rfl map_one' := by simp map_mul' := fun | 0, _ => (zero_mul _).symm | (_ : α), 0 => (mul_zero _).symm | (_ : α), (_ : α) => map_mul f _ _ } invFun F := F.toMonoidHom.comp coeMonoidHom lemma lift'_zero (f : α →* β) : lift' f (0 : WithZero α) = 0 := rfl @[simp] lemma lift'_coe (f : α →* β) (x : α) : lift' f (x : WithZero α) = f x := rfl lemma lift'_unique (f : WithZero α →*₀ β) : f = lift' (f.toMonoidHom.comp coeMonoidHom) := (lift'.apply_symm_apply f).symm lemma lift'_surjective {f : α →* β} (hf : Surjective f) : Surjective (lift' f) := by intro b obtain ⟨a, rfl⟩ := hf b exact ⟨a, by simp⟩ end lift variable [MulOneClass β] [MulOneClass γ] /-- The `MonoidWithZero` homomorphism `WithZero α →* WithZero β` induced by a monoid homomorphism `f : α →* β`. -/ def map' (f : α →* β) : WithZero α →*₀ WithZero β := lift' (coeMonoidHom.comp f) lemma map'_zero (f : α →* β) : map' f 0 = 0 := rfl @[simp] lemma map'_coe (f : α →* β) (x : α) : map' f (x : WithZero α) = f x := rfl @[simp] lemma map'_id : map' (MonoidHom.id β) = MonoidHom.id (WithZero β) := by ext x; induction x <;> rfl lemma map'_map' (f : α →* β) (g : β →* γ) (x) : map' g (map' f x) = map' (g.comp f) x := by induction x <;> rfl @[simp] lemma map'_comp (f : α →* β) (g : β →* γ) : map' (g.comp f) = (map' g).comp (map' f) := MonoidWithZeroHom.ext fun x => (map'_map' f g x).symm lemma map'_injective_iff {f : α →* β} : Injective (map' f) ↔ Injective f := by simp [Injective, WithZero.forall] alias ⟨_, map'_injective⟩ := map'_injective_iff lemma map'_surjective_iff {f : α →* β} : Surjective (map' f) ↔ Surjective f := by simp only [Surjective, «forall»] refine ⟨fun h b ↦ ?_, fun h ↦ ⟨⟨0, by simp⟩, fun b ↦ ?_⟩⟩ · obtain ⟨a, hab⟩ := h.2 b induction a using WithZero.recZeroCoe <;> simp at hab grind · obtain ⟨a, ha⟩ := h b use a simp [ha] alias ⟨_, map'_surjective⟩ := map'_surjective_iff end MulOneClass section Pow variable [One α] [Pow α ℕ] instance pow : Pow (WithZero α) ℕ where pow | none, 0 => 1 | none, _ + 1 => 0 | some x, n => ↑(x ^ n) @[simp, norm_cast] lemma coe_pow (a : α) (n : ℕ) : (↑(a ^ n) : WithZero α) = a ^ n := rfl end Pow instance instMonoidWithZero [Monoid α] : MonoidWithZero (WithZero α) where npow n a := a ^ n npow_zero | 0 => rfl | some _ => congr_arg some (pow_zero _) npow_succ | n, 0 => by simp only [mul_zero]; rfl | n, some _ => congr_arg some <| pow_succ _ _ instance instCommMonoidWithZero [CommMonoid α] : CommMonoidWithZero (WithZero α) := { WithZero.instMonoidWithZero, WithZero.instCommSemigroup with } section Inv variable [Inv α] /-- Extend the inverse operation on `α` to `WithZero α` by sending `0` to `0`. -/ instance inv : Inv (WithZero α) where inv a := Option.map (·⁻¹) a @[simp, norm_cast] lemma coe_inv (a : α) : ((a⁻¹ : α) : WithZero α) = (↑a)⁻¹ := rfl @[simp] protected lemma inv_zero : (0 : WithZero α)⁻¹ = 0 := rfl end Inv instance invOneClass [InvOneClass α] : InvOneClass (WithZero α) where inv_one := show ((1⁻¹ : α) : WithZero α) = 1 by simp section Div variable [Div α] instance div : Div (WithZero α) where div := Option.map₂ (· / ·) @[norm_cast] lemma coe_div (a b : α) : ↑(a / b : α) = (a / b : WithZero α) := rfl end Div section ZPow variable [One α] [Pow α ℤ] instance : Pow (WithZero α) ℤ where pow | none, Int.ofNat 0 => 1 | none, Int.ofNat (Nat.succ _) => 0 | none, Int.negSucc _ => 0 | some x, n => ↑(x ^ n) @[simp, norm_cast] lemma coe_zpow (a : α) (n : ℤ) : ↑(a ^ n) = (↑a : WithZero α) ^ n := rfl end ZPow instance instDivInvMonoid [DivInvMonoid α] : DivInvMonoid (WithZero α) where div_eq_mul_inv | none, _ => rfl | some _, none => rfl | some a, some b => congr_arg some (div_eq_mul_inv a b) zpow n a := a ^ n zpow_zero' | none => rfl | some _ => congr_arg some (zpow_zero _) zpow_succ' | n, none => by change 0 ^ _ = 0 ^ _ * 0; simp only [mul_zero]; rfl | n, some _ => congr_arg some (DivInvMonoid.zpow_succ' _ _) zpow_neg' | n, none => rfl | n, some _ => congr_arg some (DivInvMonoid.zpow_neg' _ _) instance instDivInvOneMonoid [DivInvOneMonoid α] : DivInvOneMonoid (WithZero α) where instance instInvolutiveInv [InvolutiveInv α] : InvolutiveInv (WithZero α) where inv_inv a := (Option.map_map _ _ _).trans <| by simp instance instDivisionMonoid [DivisionMonoid α] : DivisionMonoid (WithZero α) where mul_inv_rev | none, none => rfl | none, some _ => rfl | some _, none => rfl | some _, some _ => congr_arg some (mul_inv_rev _ _) inv_eq_of_mul | none, none, _ => rfl | some _, some _, h => congr_arg some <| inv_eq_of_mul_eq_one_right <| Option.some_injective _ h instance instDivisionCommMonoid [DivisionCommMonoid α] : DivisionCommMonoid (WithZero α) where section Group variable [Group α] /-- If `α` is a group then `WithZero α` is a group with zero. -/ instance instGroupWithZero : GroupWithZero (WithZero α) where inv_zero := WithZero.inv_zero mul_inv_cancel a ha := by lift a to α using ha norm_cast apply mul_inv_cancel /-- Any group is isomorphic to the units of itself adjoined with `0`. -/ @[simps] def unitsWithZeroEquiv : (WithZero α)ˣ ≃* α where toFun a := unzero a.ne_zero invFun a := Units.mk0 a coe_ne_zero left_inv _ := Units.ext <| by simp only [coe_unzero, Units.mk0_val] map_mul' _ _ := coe_inj.mp <| by simp only [Units.val_mul, coe_unzero, coe_mul] instance [Nontrivial α] : Nontrivial (WithZero α)ˣ := unitsWithZeroEquiv.toEquiv.surjective.nontrivial theorem coe_unitsWithZeroEquiv_eq_units_val (γ : (WithZero α)ˣ) : ↑(unitsWithZeroEquiv γ) = γ.val := by simp only [WithZero.unitsWithZeroEquiv, MulEquiv.coe_mk, Equiv.coe_fn_mk, WithZero.coe_unzero] /-- Any group with zero is isomorphic to adjoining `0` to the units of itself. -/ @[simps] def withZeroUnitsEquiv {G : Type*} [GroupWithZero G] [DecidablePred (fun a : G ↦ a = 0)] : WithZero Gˣ ≃* G where toFun := WithZero.recZeroCoe 0 Units.val invFun a := if h : a = 0 then 0 else (Units.mk0 a h : Gˣ) left_inv := (by induction · <;> simp) right_inv _ := by simp only; split <;> simp_all map_mul' := (by induction · <;> induction · <;> simp [← WithZero.coe_mul]) lemma withZeroUnitsEquiv_symm_apply_coe {G : Type*} [GroupWithZero G] [DecidablePred (fun a : G ↦ a = 0)] (a : Gˣ) : WithZero.withZeroUnitsEquiv.symm (a : G) = a := by simp /-- A version of `Equiv.optionCongr` for `WithZero`. -/ @[simps!] def _root_.MulEquiv.withZero [Group β] : (α ≃* β) ≃ (WithZero α ≃* WithZero β) where toFun e := ⟨⟨map' e, map' e.symm, (by induction · <;> simp), (by induction · <;> simp)⟩, (by induction · <;> induction · <;> simp)⟩ invFun e := ⟨⟨ fun x ↦ unzero (x := e x) (by simp [ne_eq, ← e.eq_symm_apply]), fun x ↦ unzero (x := e.symm x) (by simp [e.symm_apply_eq]), by intro; simp, by intro; simp⟩, by intro; simp [← coe_inj]⟩ left_inv _ := by ext; simp right_inv _ := by ext x; cases x <;> simp /-- The inverse of `MulEquiv.withZero`. -/ abbrev _root_.MulEquiv.unzero [Group β] (e : WithZero α ≃* WithZero β) : α ≃* β := _root_.MulEquiv.withZero.symm e end Group instance instCommGroupWithZero [CommGroup α] : CommGroupWithZero (WithZero α) where instance instAddMonoidWithOne [AddMonoidWithOne α] : AddMonoidWithOne (WithZero α) where natCast n := if n = 0 then 0 else (n : α) natCast_zero := rfl natCast_succ n := by cases n <;> simp /-! ### Exponential and logarithm -/ variable {M G : Type*} /-- `Mᵐ⁰` is notation for `WithZero (Multiplicative M)`. This naturally shows up as the codomain of valuations in valuation theory. -/ scoped notation:1024 M:1024 "ᵐ⁰" => WithZero <| Multiplicative M section AddMonoid /-- The exponential map as a function `M → Mᵐ⁰`. -/ def exp (a : M) : Mᵐ⁰ := coe <| .ofAdd a @[simp] lemma exp_ne_zero {a : M} : exp a ≠ 0 := by simp [exp] lemma exp_injective : Injective (exp : M → Mᵐ⁰) := Multiplicative.ofAdd.injective.comp WithZero.coe_injective @[simp] lemma exp_inj {x y : M} : exp x = exp y ↔ x = y := exp_injective.eq_iff /-- Recursion principle for `Mᵐ⁰`. To construct predicate for all elements of `Mᵐ⁰`, it is enough to construct its value at `0` and its value at `exp a` for all `a : M`. -/ -- TODO: Uncomment once it stops firing on `WithZero M`. -- See https://github.com/leanprover-community/mathlib4/issues/31213 @[elab_as_elim] -- , induction_eliminator, cases_eliminator] def expRecOn {motive : Mᵐ⁰ → Sort*} (x : Mᵐ⁰) (zero : motive 0) (exp : ∀ a, motive (exp a)) : motive x := Option.recOn x zero exp @[simp] lemma expRecOn_zero {motive : Mᵐ⁰ → Sort*} (zero : motive 0) (exp : ∀ a, motive (exp a)) : expRecOn 0 zero exp = zero := rfl @[simp] lemma expRecOn_exp {motive : Mᵐ⁰ → Sort*} (x : M) (zero : motive 0) (exp : ∀ a, motive (exp a)) : expRecOn (M := M) (motive := motive) (.exp x) zero exp = exp x := rfl instance : CanLift Mᵐ⁰ M exp (· ≠ 0) where prf | (.exp a : Mᵐ⁰), _ => ⟨a, rfl⟩ variable [AddMonoid M] /-- The logarithm as a function `Mᵐ⁰ → M` with junk value `log 0 = 0`. -/ def log (x : Mᵐ⁰) : M := x.recZeroCoe 0 Multiplicative.toAdd @[simp] lemma log_exp (a : M) : log (exp a) = a := rfl @[simp] lemma exp_log {x : Mᵐ⁰} (hx : x ≠ 0) : exp (log x) = x := by lift x to Multiplicative M using hx; rfl @[simp] lemma log_zero : log 0 = (0 : M) := rfl @[simp] lemma exp_zero : exp (0 : M) = 1 := rfl @[simp] lemma exp_eq_one {x : M} : exp x = 1 ↔ x = 0 := by rw [← exp_zero, exp_inj] @[simp] lemma log_one : log 1 = (0 : M) := rfl @[simp] lemma exp_add (a b : M) : exp (a + b) = exp a * exp b := rfl @[simp] lemma log_mul {x y : Mᵐ⁰} (hx : x ≠ 0) (hy : y ≠ 0) : log (x * y) = log x + log y := by lift x to Multiplicative M using hx; lift y to Multiplicative M using hy; rfl @[simp← ] lemma exp_nsmul (n : ℕ) (a : M) : exp (n • a) = exp a ^ n := rfl @[simp] lemma log_pow : ∀ (x : Mᵐ⁰) (n : ℕ), log (x ^ n) = n • log x | 0, 0 => by simp | 0, n + 1 => by simp | (x : Multiplicative M), n => rfl end AddMonoid section AddGroup variable [AddGroup G] /-- The exponential map as an equivalence between `G` and `(Gᵐ⁰)ˣ`. -/ def expEquiv : G ≃ (Gᵐ⁰)ˣ := Multiplicative.ofAdd.trans unitsWithZeroEquiv.symm.toEquiv /-- The logarithm as an equivalence between `(Gᵐ⁰)ˣ` and `G`. -/ def logEquiv : (Gᵐ⁰)ˣ ≃ G := unitsWithZeroEquiv.toEquiv.trans Multiplicative.toAdd @[simp] lemma logEquiv_symm : (logEquiv (G := G)).symm = expEquiv := rfl @[simp] lemma expEquiv_symm : (expEquiv (G := G)).symm = logEquiv := rfl @[simp] lemma coe_expEquiv_apply (a : G) : expEquiv a = exp a := rfl @[simp] lemma logEquiv_apply (x : (Gᵐ⁰)ˣ) : logEquiv x = log x := by obtain ⟨_ | a, _ | b, hab, hba⟩ := x · cases hab · cases hab · cases hab · rfl lemma logEquiv_unitsMk0 (x : Gᵐ⁰) (hx) : logEquiv (.mk0 x hx) = log x := logEquiv_apply _ @[simp] lemma exp_sub (a b : G) : exp (a - b) = exp a / exp b := rfl @[simp] lemma log_div {x y : Gᵐ⁰} (hx : x ≠ 0) (hy : y ≠ 0) : log (x / y) = log x - log y := by lift x to Multiplicative G using hx; lift y to Multiplicative G using hy; rfl @[simp] lemma exp_neg (a : G) : exp (-a) = (exp a)⁻¹ := rfl @[simp] lemma log_inv : ∀ x : Gᵐ⁰, log x⁻¹ = -log x | 0 => by simp | (x : Multiplicative G) => rfl @[simp← ] lemma exp_zsmul (n : ℤ) (a : G) : exp (n • a) = exp a ^ n := rfl @[simp] lemma log_zpow (x : Gᵐ⁰) (n : ℤ) : log (x ^ n) = n • log x := by cases n <;> simp [log_pow, log_inv] end AddGroup end WithZero namespace MonoidWithZeroHom protected lemma map_eq_zero_iff {G₀ M₀ : Type*} [GroupWithZero G₀] [MulZeroOneClass M₀] [Nontrivial M₀] {f : G₀ →*₀ M₀} {x : G₀} : f x = 0 ↔ x = 0 := by refine ⟨?_, by simp +contextual⟩ contrapose! intro hx H lift x to G₀ˣ using isUnit_iff_ne_zero.mpr hx apply one_ne_zero (α := M₀) rw [← map_one f, ← Units.mul_inv x, map_mul, H, zero_mul] @[simp] lemma one_apply_val_unit {M₀ N₀ : Type*} [MonoidWithZero M₀] [MulZeroOneClass N₀] [DecidablePred fun x : M₀ ↦ x = 0] [Nontrivial M₀] [NoZeroDivisors M₀] (x : M₀ˣ) : (1 : M₀ →*₀ N₀) x = (1 : N₀) := one_apply_of_ne_zero x.ne_zero /-- The trivial group-with-zero hom is absorbing for composition. -/ @[simp] lemma apply_one_apply_eq {M₀ N₀ G₀ : Type*} [MulZeroOneClass M₀] [Nontrivial M₀] [NoZeroDivisors M₀] [MulZeroOneClass N₀] [MulZeroOneClass G₀] [DecidablePred fun x : M₀ ↦ x = 0] (f : N₀ →*₀ G₀) (x : M₀) : f ((1 : M₀ →*₀ N₀) x) = (1 : M₀ →*₀ G₀) x := by rcases eq_or_ne x 0 with rfl | hx · simp · rw [one_apply_of_ne_zero hx, one_apply_of_ne_zero hx, map_one] /-- The trivial group-with-zero hom is absorbing for composition. -/ @[simp] lemma comp_one {M₀ N₀ G₀ : Type*} [MulZeroOneClass M₀] [Nontrivial M₀] [NoZeroDivisors M₀] [MulZeroOneClass N₀] [MulZeroOneClass G₀] [DecidablePred fun x : M₀ ↦ x = 0] (f : N₀ →*₀ G₀) : f.comp (1 : M₀ →*₀ N₀) = (1 : M₀ →*₀ G₀) := ext <| apply_one_apply_eq _ end MonoidWithZeroHom
.lake/packages/mathlib/Mathlib/Algebra/GroupWithZero/Regular.lean
import Mathlib.Algebra.GroupWithZero.Defs import Mathlib.Tactic.Push /-! # Results about `IsRegular` and `0` -/ variable {R} section MulZeroClass variable [MulZeroClass R] {a b : R} /-- The element `0` is left-regular if and only if `R` is trivial. -/ theorem IsLeftRegular.subsingleton (h : IsLeftRegular (0 : R)) : Subsingleton R := ⟨fun a b => h <| Eq.trans (zero_mul a) (zero_mul b).symm⟩ /-- The element `0` is right-regular if and only if `R` is trivial. -/ theorem IsRightRegular.subsingleton (h : IsRightRegular (0 : R)) : Subsingleton R := ⟨fun a b => h <| Eq.trans (mul_zero a) (mul_zero b).symm⟩ /-- The element `0` is regular if and only if `R` is trivial. -/ theorem IsRegular.subsingleton (h : IsRegular (0 : R)) : Subsingleton R := h.left.subsingleton /-- The element `0` is left-regular if and only if `R` is trivial. -/ theorem isLeftRegular_zero_iff_subsingleton : IsLeftRegular (0 : R) ↔ Subsingleton R := ⟨fun h => h.subsingleton, fun H a b _ => @Subsingleton.elim _ H a b⟩ /-- In a non-trivial `MulZeroClass`, the `0` element is not left-regular. -/ theorem not_isLeftRegular_zero_iff : ¬IsLeftRegular (0 : R) ↔ Nontrivial R := by rw [nontrivial_iff, not_iff_comm, isLeftRegular_zero_iff_subsingleton, subsingleton_iff] push_neg exact Iff.rfl /-- The element `0` is right-regular if and only if `R` is trivial. -/ theorem isRightRegular_zero_iff_subsingleton : IsRightRegular (0 : R) ↔ Subsingleton R := ⟨fun h => h.subsingleton, fun H a b _ => @Subsingleton.elim _ H a b⟩ /-- In a non-trivial `MulZeroClass`, the `0` element is not right-regular. -/ theorem not_isRightRegular_zero_iff : ¬IsRightRegular (0 : R) ↔ Nontrivial R := by rw [nontrivial_iff, not_iff_comm, isRightRegular_zero_iff_subsingleton, subsingleton_iff] push_neg exact Iff.rfl /-- The element `0` is regular if and only if `R` is trivial. -/ theorem isRegular_iff_subsingleton : IsRegular (0 : R) ↔ Subsingleton R := ⟨fun h => h.left.subsingleton, fun h => ⟨isLeftRegular_zero_iff_subsingleton.mpr h, isRightRegular_zero_iff_subsingleton.mpr h⟩⟩ /-- A left-regular element of a `Nontrivial` `MulZeroClass` is non-zero. -/ theorem IsLeftRegular.ne_zero [Nontrivial R] (la : IsLeftRegular a) : a ≠ 0 := by rintro rfl rcases exists_pair_ne R with ⟨x, y, xy⟩ refine xy (la ?_) simp /-- A right-regular element of a `Nontrivial` `MulZeroClass` is non-zero. -/ theorem IsRightRegular.ne_zero [Nontrivial R] (ra : IsRightRegular a) : a ≠ 0 := by rintro rfl rcases exists_pair_ne R with ⟨x, y, xy⟩ refine xy (ra ?_) simp /-- A regular element of a `Nontrivial` `MulZeroClass` is non-zero. -/ theorem IsRegular.ne_zero [Nontrivial R] (la : IsRegular a) : a ≠ 0 := la.left.ne_zero /-- In a non-trivial ring, the element `0` is not left-regular -- with typeclasses. -/ theorem not_isLeftRegular_zero [nR : Nontrivial R] : ¬IsLeftRegular (0 : R) := not_isLeftRegular_zero_iff.mpr nR /-- In a non-trivial ring, the element `0` is not right-regular -- with typeclasses. -/ theorem not_isRightRegular_zero [nR : Nontrivial R] : ¬IsRightRegular (0 : R) := not_isRightRegular_zero_iff.mpr nR /-- In a non-trivial ring, the element `0` is not regular -- with typeclasses. -/ theorem not_isRegular_zero [Nontrivial R] : ¬IsRegular (0 : R) := fun h => IsRegular.ne_zero h rfl @[simp] lemma IsLeftRegular.mul_left_eq_zero_iff (hb : IsLeftRegular b) : b * a = 0 ↔ a = 0 := by conv_lhs => rw [← mul_zero b] exact ⟨fun h ↦ hb h, fun ha ↦ by rw [ha]⟩ @[simp] lemma IsRightRegular.mul_right_eq_zero_iff (hb : IsRightRegular b) : a * b = 0 ↔ a = 0 := by conv_lhs => rw [← zero_mul b] exact ⟨fun h ↦ hb h, fun ha ↦ by rw [ha]⟩ end MulZeroClass section CancelMonoidWithZero variable [MulZeroClass R] [IsCancelMulZero R] {a : R} /-- Non-zero elements of an integral domain are regular. -/ theorem isRegular_of_ne_zero (a0 : a ≠ 0) : IsRegular a := ⟨fun _ _ => mul_left_cancel₀ a0, fun _ _ => mul_right_cancel₀ a0⟩ /-- In a non-trivial integral domain, an element is regular iff it is non-zero. -/ theorem isRegular_iff_ne_zero [Nontrivial R] : IsRegular a ↔ a ≠ 0 := ⟨IsRegular.ne_zero, isRegular_of_ne_zero⟩ end CancelMonoidWithZero
.lake/packages/mathlib/Mathlib/Algebra/GroupWithZero/Indicator.lean
import Mathlib.Algebra.Group.Pi.Basic import Mathlib.Algebra.Group.Support import Mathlib.Algebra.GroupWithZero.Basic import Mathlib.Algebra.Notation.Indicator /-! # Indicator functions and support of a function in groups with zero -/ assert_not_exists Ring open Set variable {ι κ G₀ M₀ R : Type*} namespace Set section MulZeroClass variable [MulZeroClass M₀] {s t : Set ι} {i : ι} lemma indicator_mul (s : Set ι) (f g : ι → M₀) : indicator s (fun i ↦ f i * g i) = fun i ↦ indicator s f i * indicator s g i := by funext simp only [indicator] split_ifs · rfl rw [mul_zero] lemma indicator_mul_left (s : Set ι) (f g : ι → M₀) : indicator s (fun j ↦ f j * g j) i = indicator s f i * g i := by simp only [indicator] split_ifs · rfl · rw [zero_mul] lemma indicator_mul_right (s : Set ι) (f g : ι → M₀) : indicator s (fun j ↦ f j * g j) i = f i * indicator s g i := by simp only [indicator] split_ifs · rfl · rw [mul_zero] lemma indicator_mul_const (s : Set ι) (f : ι → M₀) (a : M₀) (i : ι) : s.indicator (f · * a) i = s.indicator f i * a := by rw [indicator_mul_left] lemma indicator_const_mul (s : Set ι) (f : ι → M₀) (a : M₀) (i : ι) : s.indicator (a * f ·) i = a * s.indicator f i := by rw [indicator_mul_right] lemma inter_indicator_mul (f g : ι → M₀) (i : ι) : (s ∩ t).indicator (fun j ↦ f j * g j) i = s.indicator f i * t.indicator g i := by rw [← Set.indicator_indicator] simp_rw [indicator] split_ifs <;> simp end MulZeroClass section MulZeroOneClass variable [MulZeroOneClass M₀] {s t : Set ι} {i : ι} lemma inter_indicator_one : (s ∩ t).indicator (1 : ι → M₀) = s.indicator 1 * t.indicator 1 := funext fun _ ↦ by simp only [← inter_indicator_mul, Pi.mul_apply, Pi.one_apply, one_mul]; congr lemma indicator_prod_one {t : Set κ} {j : κ} : (s ×ˢ t).indicator (1 : ι × κ → M₀) (i, j) = s.indicator 1 i * t.indicator 1 j := by simp_rw [indicator, mem_prod_eq] split_ifs with h₀ <;> simp only [Pi.one_apply, mul_one, mul_zero] <;> tauto variable (M₀) [Nontrivial M₀] lemma indicator_eq_zero_iff_notMem : indicator s 1 i = (0 : M₀) ↔ i ∉ s := by classical simp [indicator_apply, imp_false] @[deprecated (since := "2025-05-23")] alias indicator_eq_zero_iff_not_mem := indicator_eq_zero_iff_notMem lemma indicator_eq_one_iff_mem : indicator s 1 i = (1 : M₀) ↔ i ∈ s := by classical simp [indicator_apply, imp_false] lemma indicator_one_inj (h : indicator s (1 : ι → M₀) = indicator t 1) : s = t := by ext; simp_rw [← indicator_eq_one_iff_mem M₀, h] end MulZeroOneClass end Set namespace Function section ZeroOne variable (R) [Zero R] [One R] [NeZero (1 : R)] @[simp] lemma support_one : support (1 : ι → R) = univ := support_const one_ne_zero @[simp] lemma mulSupport_zero : mulSupport (0 : ι → R) = univ := mulSupport_const zero_ne_one end ZeroOne section MulZeroClass variable [MulZeroClass M₀] lemma support_mul_subset_left (f g : ι → M₀) : support (fun x ↦ f x * g x) ⊆ support f := fun x hfg hf ↦ hfg <| by simp only [hf, zero_mul] lemma support_mul_subset_right (f g : ι → M₀) : support (fun x ↦ f x * g x) ⊆ support g := fun x hfg hg => hfg <| by simp only [hg, mul_zero] variable [NoZeroDivisors M₀] @[simp] lemma support_mul (f g : ι → M₀) : support (fun x ↦ f x * g x) = support f ∩ support g := ext fun x ↦ by simp [not_or] @[simp] lemma support_mul' (f g : ι → M₀) : support (f * g) = support f ∩ support g := support_mul _ _ end MulZeroClass section MonoidWithZero variable [MonoidWithZero M₀] [NoZeroDivisors M₀] {n : ℕ} @[simp] lemma support_pow (f : ι → M₀) (hn : n ≠ 0) : support (fun a ↦ f a ^ n) = support f := by ext; exact (pow_eq_zero_iff hn).not @[simp] lemma support_pow' (f : ι → M₀) (hn : n ≠ 0) : support (f ^ n) = support f := support_pow _ hn end MonoidWithZero section GroupWithZero variable [GroupWithZero G₀] @[simp] lemma support_inv (f : ι → G₀) : support (fun a ↦ (f a)⁻¹) = support f := Set.ext fun _ ↦ not_congr inv_eq_zero @[simp] lemma support_inv' (f : ι → G₀) : support f⁻¹ = support f := support_inv _ @[simp] lemma support_div (f g : ι → G₀) : support (fun a ↦ f a / g a) = support f ∩ support g := by simp [div_eq_mul_inv] @[simp] lemma support_div' (f g : ι → G₀) : support (f / g) = support f ∩ support g := support_div _ _ end GroupWithZero variable [One R] lemma mulSupport_one_add [AddLeftCancelMonoid R] (f : ι → R) : mulSupport (fun x ↦ 1 + f x) = support f := Set.ext fun _ ↦ not_congr add_eq_left lemma mulSupport_one_add' [AddLeftCancelMonoid R] (f : ι → R) : mulSupport (1 + f) = support f := mulSupport_one_add f lemma mulSupport_add_one [AddRightCancelMonoid R] (f : ι → R) : mulSupport (fun x ↦ f x + 1) = support f := Set.ext fun _ ↦ not_congr add_eq_right lemma mulSupport_add_one' [AddRightCancelMonoid R] (f : ι → R) : mulSupport (f + 1) = support f := mulSupport_add_one f lemma mulSupport_one_sub' [AddGroup R] (f : ι → R) : mulSupport (1 - f) = support f := by rw [sub_eq_add_neg, mulSupport_one_add', support_neg] lemma mulSupport_one_sub [AddGroup R] (f : ι → R) : mulSupport (fun x ↦ 1 - f x) = support f := mulSupport_one_sub' f end Function
.lake/packages/mathlib/Mathlib/Algebra/GroupWithZero/TransferInstance.lean
import Mathlib.Algebra.Group.TransferInstance import Mathlib.Algebra.GroupWithZero.InjSurj /-! # Transfer algebraic structures across `Equiv`s This continues the pattern set in `Mathlib/Algebra/Group/TransferInstance.lean`. -/ assert_not_exists MulAction Ring universe u v variable {α : Type u} {β : Type v} namespace Equiv variable (e : α ≃ β) /-- Transfer `SemigroupWithZero` across an `Equiv` -/ protected abbrev semigroupWithZero [SemigroupWithZero β] : SemigroupWithZero α := by let mul := e.mul let zero := e.zero apply e.injective.semigroupWithZero _ <;> intros <;> exact e.apply_symm_apply _ /-- Transfer `MulZeroClass` across an `Equiv` -/ protected abbrev mulZeroClass [MulZeroClass β] : MulZeroClass α := by let zero := e.zero let mul := e.mul apply e.injective.mulZeroClass _ <;> intros <;> exact e.apply_symm_apply _ /-- Transfer `MulZeroOneClass` across an `Equiv` -/ protected abbrev mulZeroOneClass [MulZeroOneClass β] : MulZeroOneClass α := by let zero := e.zero let one := e.one let mul := e.mul apply e.injective.mulZeroOneClass _ <;> intros <;> exact e.apply_symm_apply _ /-- Transfer `MonoidWithZero` across an `Equiv` -/ protected abbrev monoidWithZero [MonoidWithZero β] : MonoidWithZero α := by let _ := e.mulZeroOneClass let _ := e.pow ℕ apply e.injective.monoidWithZero _ <;> intros <;> exact e.apply_symm_apply _ /-- Transfer `CommMonoidWithZero` across an `Equiv` -/ protected abbrev commMonoidWithZero [CommMonoidWithZero β] : CommMonoidWithZero α := by let _ := e.monoidWithZero apply e.injective.commMonoidWithZero _ <;> intros <;> exact e.apply_symm_apply _ end Equiv
.lake/packages/mathlib/Mathlib/Algebra/GroupWithZero/ProdHom.lean
import Mathlib.Algebra.Group.Prod import Mathlib.Algebra.GroupWithZero.Commute import Mathlib.Algebra.GroupWithZero.Units.Lemmas import Mathlib.Algebra.GroupWithZero.WithZero /-! # Homomorphisms for products of groups with zero This file defines homomorphisms for products of groups with zero, which is identified with the `WithZero` of the product of the units of the groups. The product of groups with zero `WithZero (αˣ × βˣ)` is a group with zero itself with natural inclusions. TODO: Give `GrpWithZero` instances of `HasBinaryProducts` and `HasBinaryCoproducts`, as well as a terminal object. -/ namespace MonoidWithZeroHom /-- The trivial group-with-zero hom is absorbing for composition. -/ @[simp] lemma one_apply_apply_eq {M₀ N₀ G₀ : Type*} [GroupWithZero M₀] [MulZeroOneClass N₀] [Nontrivial N₀] [NoZeroDivisors N₀] [MulZeroOneClass G₀] [DecidablePred fun x : M₀ ↦ x = 0] [DecidablePred fun x : N₀ ↦ x = 0] (f : M₀ →*₀ N₀) (x : M₀) : (1 : N₀ →*₀ G₀) (f x) = (1 : M₀ →*₀ G₀) x := by rcases eq_or_ne x 0 with rfl | hx · simp · rw [one_apply_of_ne_zero hx, one_apply_of_ne_zero] rwa [map_ne_zero f] /-- The trivial group-with-zero hom is absorbing for composition. -/ @[simp] lemma one_comp {M₀ N₀ G₀ : Type*} [GroupWithZero M₀] [MulZeroOneClass N₀] [Nontrivial N₀] [NoZeroDivisors N₀] [MulZeroOneClass G₀] [DecidablePred fun x : M₀ ↦ x = 0] [DecidablePred fun x : N₀ ↦ x = 0] (f : M₀ →*₀ N₀) : (1 : N₀ →*₀ G₀).comp f = (1 : M₀ →*₀ G₀) := ext <| one_apply_apply_eq _ variable (G₀ H₀ : Type*) [GroupWithZero G₀] [GroupWithZero H₀] /-- Given groups with zero `G₀`, `H₀`, the natural inclusion ordered homomorphism from `G₀` to `WithZero (G₀ˣ × H₀ˣ)`, which is the group with zero that can be identified as their product. -/ def inl [DecidablePred fun x : G₀ ↦ x = 0] : G₀ →*₀ WithZero (G₀ˣ × H₀ˣ) := (WithZero.map' (.inl _ _)).comp (MonoidWithZeroHomClass.toMonoidWithZeroHom WithZero.withZeroUnitsEquiv.symm) /-- Given groups with zero `G₀`, `H₀`, the natural inclusion ordered homomorphism from `H₀` to `WithZero (G₀ˣ × H₀ˣ)`, which is the group with zero that can be identified as their product. -/ def inr [DecidablePred fun x : H₀ ↦ x = 0] : H₀ →*₀ WithZero (G₀ˣ × H₀ˣ) := (WithZero.map' (.inr _ _)).comp (MonoidWithZeroHomClass.toMonoidWithZeroHom WithZero.withZeroUnitsEquiv.symm) /-- Given groups with zero `G₀`, `H₀`, the natural projection homomorphism from `WithZero (G₀ˣ × H₀ˣ)` to `G₀`, which is the group with zero that can be identified as their product. -/ def fst : WithZero (G₀ˣ × H₀ˣ) →*₀ G₀ := WithZero.lift' ((Units.coeHom _).comp (.fst ..)) /-- Given groups with zero `G₀`, `H₀`, the natural projection homomorphism from `WithZero (G₀ˣ × H₀ˣ)` to `H₀`, which is the group with zero that can be identified as their product. -/ def snd : WithZero (G₀ˣ × H₀ˣ) →*₀ H₀ := WithZero.lift' ((Units.coeHom _).comp (.snd ..)) variable {G₀ H₀} @[simp] lemma inl_apply_unit [DecidablePred fun x : G₀ ↦ x = 0] (x : G₀ˣ) : inl G₀ H₀ x = ((x, (1 : H₀ˣ)) : WithZero (G₀ˣ × H₀ˣ)) := by simp [inl] @[simp] lemma inr_apply_unit [DecidablePred fun x : H₀ ↦ x = 0] (x : H₀ˣ) : inr G₀ H₀ x = (((1 : G₀ˣ), x) : WithZero (G₀ˣ × H₀ˣ)) := by simp [inr] @[simp] lemma fst_apply_coe (x : G₀ˣ × H₀ˣ) : fst G₀ H₀ x = x.fst := by rfl @[simp] lemma snd_apply_coe (x : G₀ˣ × H₀ˣ) : snd G₀ H₀ x = x.snd := by rfl @[simp] theorem fst_inl [DecidablePred fun x : G₀ ↦ x = 0] (x : G₀) : fst _ H₀ (inl _ _ x) = x := by obtain rfl | ⟨_, rfl⟩ := GroupWithZero.eq_zero_or_unit x <;> simp [WithZero.withZeroUnitsEquiv, fst, inl] @[simp] theorem fst_comp_inl [DecidablePred fun x : G₀ ↦ x = 0] : (fst ..).comp (inl G₀ H₀) = .id _ := MonoidWithZeroHom.ext fun _ ↦ fst_inl _ @[simp] theorem snd_comp_inl [DecidablePred fun x : G₀ ↦ x = 0] : (snd ..).comp (inl G₀ H₀) = 1 := by ext x obtain rfl | ⟨_, rfl⟩ := GroupWithZero.eq_zero_or_unit x <;> simp_all [WithZero.withZeroUnitsEquiv, snd, inl] theorem snd_inl_apply_of_ne_zero [DecidablePred fun x : G₀ ↦ x = 0] {x : G₀} (hx : x ≠ 0) : snd _ _ (inl _ H₀ x) = 1 := by rw [← MonoidWithZeroHom.comp_apply, snd_comp_inl, one_apply_of_ne_zero hx] @[simp] theorem fst_comp_inr [DecidablePred fun x : H₀ ↦ x = 0] : (fst ..).comp (inr G₀ H₀) = 1 := by ext x obtain rfl | ⟨_, rfl⟩ := GroupWithZero.eq_zero_or_unit x <;> simp_all [WithZero.withZeroUnitsEquiv, fst, inr] theorem fst_inr_apply_of_ne_zero [DecidablePred fun x : H₀ ↦ x = 0] {x : H₀} (hx : x ≠ 0) : fst _ _ (inr G₀ _ x) = 1 := by rw [← MonoidWithZeroHom.comp_apply, fst_comp_inr, one_apply_of_ne_zero hx] @[simp] theorem snd_inr [DecidablePred fun x : H₀ ↦ x = 0] (x : H₀) : snd _ _ (inr G₀ _ x) = x := by obtain rfl | ⟨_, rfl⟩ := GroupWithZero.eq_zero_or_unit x <;> simp [WithZero.withZeroUnitsEquiv, snd, inr] @[simp] theorem snd_comp_inr [DecidablePred fun x : H₀ ↦ x = 0] : (snd ..).comp (inr G₀ H₀) = .id _ := MonoidWithZeroHom.ext fun _ ↦ snd_inr _ lemma inl_injective [DecidablePred fun x : G₀ ↦ x = 0] : Function.Injective (inl G₀ H₀) := Function.HasLeftInverse.injective ⟨fst .., fun _ ↦ by simp⟩ lemma inr_injective [DecidablePred fun x : H₀ ↦ x = 0] : Function.Injective (inr G₀ H₀) := Function.HasLeftInverse.injective ⟨snd .., fun _ ↦ by simp⟩ lemma fst_surjective : Function.Surjective (fst G₀ H₀) := by classical exact Function.HasRightInverse.surjective ⟨inl .., fun _ ↦ by simp⟩ lemma snd_surjective : Function.Surjective (snd G₀ H₀) := by classical exact Function.HasRightInverse.surjective ⟨inr .., fun _ ↦ by simp⟩ variable [DecidablePred fun x : G₀ ↦ x = 0] [DecidablePred fun x : H₀ ↦ x = 0] theorem inl_mul_inr_eq_mk_of_unit (m : G₀ˣ) (n : H₀ˣ) : (inl G₀ H₀ m * inr G₀ H₀ n) = (m, n) := by simp [inl, WithZero.withZeroUnitsEquiv, inr, ← WithZero.coe_mul] theorem commute_inl_inr (m : G₀) (n : H₀) : Commute (inl G₀ H₀ m) (inr G₀ H₀ n) := by obtain rfl | ⟨_, rfl⟩ := GroupWithZero.eq_zero_or_unit m <;> obtain rfl | ⟨_, rfl⟩ := GroupWithZero.eq_zero_or_unit n <;> simp [inl, inr, WithZero.withZeroUnitsEquiv, commute_iff_eq, ← WithZero.coe_mul] end MonoidWithZeroHom
.lake/packages/mathlib/Mathlib/Algebra/GroupWithZero/Prod.lean
import Mathlib.Algebra.Group.Prod import Mathlib.Algebra.GroupWithZero.Hom import Mathlib.Algebra.GroupWithZero.Units.Basic import Mathlib.Algebra.GroupWithZero.WithZero /-! # Products of monoids with zero, groups with zero In this file we define `MonoidWithZero`, `GroupWithZero`, etc... instances for `M₀ × N₀`. ## Main declarations * `mulMonoidWithZeroHom`: Multiplication bundled as a monoid with zero homomorphism. * `divMonoidWithZeroHom`: Division bundled as a monoid with zero homomorphism. -/ assert_not_exists DenselyOrdered Ring variable {M₀ N₀ : Type*} namespace Prod instance instMulZeroClass [MulZeroClass M₀] [MulZeroClass N₀] : MulZeroClass (M₀ × N₀) where zero_mul := by simp [Prod.mul_def] mul_zero := by simp [Prod.mul_def] instance instSemigroupWithZero [SemigroupWithZero M₀] [SemigroupWithZero N₀] : SemigroupWithZero (M₀ × N₀) where zero_mul := by simp mul_zero := by simp instance instMulZeroOneClass [MulZeroOneClass M₀] [MulZeroOneClass N₀] : MulZeroOneClass (M₀ × N₀) where zero_mul := by simp mul_zero := by simp instance instMonoidWithZero [MonoidWithZero M₀] [MonoidWithZero N₀] : MonoidWithZero (M₀ × N₀) where zero_mul := by simp mul_zero := by simp instance instCommMonoidWithZero [CommMonoidWithZero M₀] [CommMonoidWithZero N₀] : CommMonoidWithZero (M₀ × N₀) where zero_mul := by simp mul_zero := by simp end Prod variable (M₀) in @[simp] lemma WithZero.toMonoidWithZeroHom_withZeroUnitsEquiv [GroupWithZero M₀] [DecidablePred fun x : M₀ ↦ x = 0] : MonoidWithZeroHomClass.toMonoidWithZeroHom WithZero.withZeroUnitsEquiv = WithZero.lift' (Units.coeHom M₀) := rfl /-! ### Multiplication and division as homomorphisms -/ section BundledMulDiv /-- Multiplication as a multiplicative homomorphism with zero. -/ @[simps] def mulMonoidWithZeroHom [CommMonoidWithZero M₀] : M₀ × M₀ →*₀ M₀ where __ := mulMonoidHom map_zero' := mul_zero _ /-- Division as a multiplicative homomorphism with zero. -/ @[simps] def divMonoidWithZeroHom [CommGroupWithZero M₀] : M₀ × M₀ →*₀ M₀ where __ := divMonoidHom map_zero' := zero_div _ end BundledMulDiv
.lake/packages/mathlib/Mathlib/Algebra/GroupWithZero/Nat.lean
import Mathlib.Algebra.Group.Nat.Defs import Mathlib.Algebra.GroupWithZero.Defs import Mathlib.Tactic.Spread /-! # The natural numbers form a `CancelCommMonoidWithZero` This file contains the `CancelCommMonoidWithZero` instance on the natural numbers. See note [foundational algebra order theory]. -/ assert_not_exists Ring namespace Nat instance instMulZeroClass : MulZeroClass ℕ where zero_mul := Nat.zero_mul mul_zero := Nat.mul_zero instance instSemigroupWithZero : SemigroupWithZero ℕ where __ := instSemigroup __ := instMulZeroClass instance instMonoidWithZero : MonoidWithZero ℕ where __ := instMonoid __ := instMulZeroClass __ := instSemigroupWithZero instance instCommMonoidWithZero : CommMonoidWithZero ℕ where __ := instCommMonoid __ := instMonoidWithZero instance instIsLeftCancelMulZero : IsLeftCancelMulZero ℕ where mul_left_cancel_of_ne_zero h _ _ := Nat.eq_of_mul_eq_mul_left (Nat.pos_of_ne_zero h) instance instCancelCommMonoidWithZero : CancelCommMonoidWithZero ℕ where __ := instCommMonoidWithZero __ := instIsLeftCancelMulZero instance instMulDivCancelClass : MulDivCancelClass ℕ where mul_div_cancel _ _b hb := Nat.mul_div_cancel _ (Nat.pos_iff_ne_zero.2 hb) instance instMulZeroOneClass : MulZeroOneClass ℕ where __ := instMulZeroClass __ := instMulOneClass end Nat
.lake/packages/mathlib/Mathlib/Algebra/GroupWithZero/Invertible.lean
import Mathlib.Algebra.Group.Invertible.Basic import Mathlib.Algebra.GroupWithZero.Units.Basic /-! # Theorems about invertible elements in a `GroupWithZero` We intentionally keep imports minimal here as this file is used by `Mathlib/Tactic/NormNum.lean`. -/ assert_not_exists DenselyOrdered Ring universe u variable {α : Type u} theorem Invertible.ne_zero [MulZeroOneClass α] (a : α) [Nontrivial α] [Invertible a] : a ≠ 0 := fun ha => zero_ne_one <| calc 0 = ⅟a * a := by simp [ha] _ = 1 := invOf_mul_self instance (priority := 100) Invertible.toNeZero [MulZeroOneClass α] [Nontrivial α] (a : α) [Invertible a] : NeZero a := ⟨Invertible.ne_zero a⟩ section MonoidWithZero variable [MonoidWithZero α] /-- A variant of `Ring.inverse_unit`. -/ @[simp] theorem Ring.inverse_invertible (x : α) [Invertible x] : Ring.inverse x = ⅟x := Ring.inverse_unit (unitOfInvertible _) end MonoidWithZero section GroupWithZero variable [GroupWithZero α] /-- `a⁻¹` is an inverse of `a` if `a ≠ 0` -/ def invertibleOfNonzero {a : α} (h : a ≠ 0) : Invertible a := ⟨a⁻¹, inv_mul_cancel₀ h, mul_inv_cancel₀ h⟩ @[simp] theorem invOf_eq_inv (a : α) [Invertible a] : ⅟a = a⁻¹ := invOf_eq_right_inv (mul_inv_cancel₀ (Invertible.ne_zero a)) @[simp] theorem inv_mul_cancel_of_invertible (a : α) [Invertible a] : a⁻¹ * a = 1 := inv_mul_cancel₀ (Invertible.ne_zero a) @[simp] theorem mul_inv_cancel_of_invertible (a : α) [Invertible a] : a * a⁻¹ = 1 := mul_inv_cancel₀ (Invertible.ne_zero a) /-- `a` is the inverse of `a⁻¹` -/ def invertibleInv {a : α} [Invertible a] : Invertible a⁻¹ := ⟨a, by simp, by simp⟩ @[simp] theorem div_mul_cancel_of_invertible (a b : α) [Invertible b] : a / b * b = a := div_mul_cancel₀ a (Invertible.ne_zero b) @[simp] theorem mul_div_cancel_of_invertible (a b : α) [Invertible b] : a * b / b = a := mul_div_cancel_right₀ a (Invertible.ne_zero b) @[simp] theorem div_self_of_invertible (a : α) [Invertible a] : a / a = 1 := div_self (Invertible.ne_zero a) /-- `b / a` is the inverse of `a / b` -/ def invertibleDiv (a b : α) [Invertible a] [Invertible b] : Invertible (a / b) := ⟨b / a, by simp [← mul_div_assoc], by simp [← mul_div_assoc]⟩ theorem invOf_div (a b : α) [Invertible a] [Invertible b] [Invertible (a / b)] : ⅟(a / b) = b / a := invOf_eq_right_inv (by simp [← mul_div_assoc]) end GroupWithZero
.lake/packages/mathlib/Mathlib/Algebra/GroupWithZero/Pi.lean
import Mathlib.Algebra.GroupWithZero.Defs import Mathlib.Algebra.Group.Hom.Defs import Mathlib.Algebra.Group.Pi.Basic /-! # Pi instances for groups with zero This file defines monoid with zero, group with zero, and related structure instances for pi types. -/ assert_not_exists DenselyOrdered Ring variable {ι : Type*} {α : ι → Type*} namespace Pi section MulZeroClass variable [∀ i, MulZeroClass (α i)] [DecidableEq ι] {i : ι} {f : ∀ i, α i} instance mulZeroClass : MulZeroClass (∀ i, α i) where zero_mul := by intros; ext; exact zero_mul _ mul_zero := by intros; ext; exact mul_zero _ /-- The multiplicative homomorphism including a single `MulZeroClass` into a dependent family of `MulZeroClass`es, as functions supported at a point. This is the `MulHom` version of `Pi.single`. -/ @[simps] def _root_.MulHom.single (i : ι) : α i →ₙ* ∀ i, α i where toFun := Pi.single i map_mul' := Pi.single_op₂ (fun _ ↦ (· * ·)) (fun _ ↦ zero_mul _) _ lemma single_mul (i : ι) (x y : α i) : single i (x * y) = single i x * single i y := (MulHom.single _).map_mul _ _ lemma single_mul_left_apply (i j : ι) (a : α i) (f : ∀ i, α i) : single i (a * f i) j = single i a j * f j := (apply_single (fun i ↦ (· * f i)) (fun _ ↦ zero_mul _) _ _ _).symm lemma single_mul_right_apply (i j : ι) (f : ∀ i, α i) (a : α i) : single i (f i * a) j = f j * single i a j := (apply_single (f · * ·) (fun _ ↦ mul_zero _) _ _ _).symm lemma single_mul_left (a : α i) : single i (a * f i) = single i a * f := funext fun _ ↦ single_mul_left_apply _ _ _ _ lemma single_mul_right (a : α i) : single i (f i * a) = f * single i a := funext fun _ ↦ single_mul_right_apply _ _ _ _ end MulZeroClass instance mulZeroOneClass [∀ i, MulZeroOneClass (α i)] : MulZeroOneClass (∀ i, α i) where __ := mulZeroClass __ := mulOneClass instance monoidWithZero [∀ i, MonoidWithZero (α i)] : MonoidWithZero (∀ i, α i) where __ := monoid __ := mulZeroClass instance commMonoidWithZero [∀ i, CommMonoidWithZero (α i)] : CommMonoidWithZero (∀ i, α i) where __ := monoidWithZero __ := commMonoid instance semigroupWithZero [∀ i, SemigroupWithZero (α i)] : SemigroupWithZero (∀ i, α i) where __ := semigroup __ := mulZeroClass end Pi
.lake/packages/mathlib/Mathlib/Algebra/GroupWithZero/Center.lean
import Mathlib.Algebra.Group.Center import Mathlib.Algebra.GroupWithZero.Units.Basic /-! # Center of a group with zero -/ assert_not_exists RelIso Finset Ring Subsemigroup variable {M₀ G₀ : Type*} namespace Set section MulZeroClass variable [MulZeroClass M₀] {s : Set M₀} @[simp] lemma zero_mem_center : (0 : M₀) ∈ center M₀ where comm _ := by rw [commute_iff_eq, zero_mul, mul_zero] left_assoc _ _ := by rw [zero_mul, zero_mul, zero_mul] right_assoc _ _ := by rw [mul_zero, mul_zero, mul_zero] @[simp] lemma zero_mem_centralizer : (0 : M₀) ∈ centralizer s := by simp [mem_centralizer_iff] end MulZeroClass section GroupWithZero variable [GroupWithZero G₀] {s : Set G₀} {a b : G₀} lemma center_units_subset : center G₀ˣ ⊆ ((↑) : G₀ˣ → G₀) ⁻¹' center G₀ := by simp_rw [subset_def, mem_preimage, _root_.Semigroup.mem_center_iff] intro u hu a obtain rfl | ha := eq_or_ne a 0 · rw [zero_mul, mul_zero] · exact congr_arg Units.val <| hu <| Units.mk0 a ha /-- In a group with zero, the center of the units is the preimage of the center. -/ lemma center_units_eq : center G₀ˣ = ((↑) : G₀ˣ → G₀) ⁻¹' center G₀ := center_units_subset.antisymm subset_center_units @[simp] lemma inv_mem_centralizer₀ (ha : a ∈ centralizer s) : a⁻¹ ∈ centralizer s := by obtain rfl | ha₀ := eq_or_ne a 0 · rw [inv_zero] exact zero_mem_centralizer · rintro c hc rw [mul_inv_eq_iff_eq_mul₀ ha₀, mul_assoc, eq_inv_mul_iff_mul_eq₀ ha₀, ha c hc] @[simp] lemma div_mem_centralizer₀ (ha : a ∈ centralizer s) (hb : b ∈ centralizer s) : a / b ∈ centralizer s := by simpa only [div_eq_mul_inv] using mul_mem_centralizer ha (inv_mem_centralizer₀ hb) end GroupWithZero end Set
.lake/packages/mathlib/Mathlib/Algebra/GroupWithZero/Commute.lean
import Mathlib.Algebra.GroupWithZero.Semiconj import Mathlib.Algebra.Group.Commute.Units import Mathlib.Tactic.Nontriviality /-! # Lemmas about commuting elements in a `MonoidWithZero` or a `GroupWithZero`. -/ assert_not_exists DenselyOrdered Ring variable {M₀ G₀ : Type*} variable [MonoidWithZero M₀] namespace Ring theorem mul_inverse_rev' {a b : M₀} (h : Commute a b) : inverse (a * b) = inverse b * inverse a := by by_cases hab : IsUnit (a * b) · obtain ⟨⟨a, rfl⟩, b, rfl⟩ := h.isUnit_mul_iff.mp hab rw [← Units.val_mul, inverse_unit, inverse_unit, inverse_unit, ← Units.val_mul, mul_inv_rev] obtain ha | hb := not_and_or.mp (mt h.isUnit_mul_iff.mpr hab) · rw [inverse_non_unit _ hab, inverse_non_unit _ ha, mul_zero] · rw [inverse_non_unit _ hab, inverse_non_unit _ hb, zero_mul] theorem mul_inverse_rev {M₀} [CommMonoidWithZero M₀] (a b : M₀) : Ring.inverse (a * b) = inverse b * inverse a := mul_inverse_rev' (Commute.all _ _) lemma inverse_pow (r : M₀) : ∀ n : ℕ, Ring.inverse r ^ n = Ring.inverse (r ^ n) | 0 => by rw [pow_zero, pow_zero, Ring.inverse_one] | n + 1 => by rw [pow_succ', pow_succ, Ring.mul_inverse_rev' ((Commute.refl r).pow_left n), Ring.inverse_pow r n] lemma inverse_pow_mul_eq_iff_eq_mul {a : M₀} (b c : M₀) (ha : IsUnit a) {k : ℕ} : Ring.inverse a ^ k * b = c ↔ b = a ^ k * c := by rw [Ring.inverse_pow, Ring.inverse_mul_eq_iff_eq_mul _ _ _ (IsUnit.pow _ ha)] end Ring theorem Commute.ringInverse_ringInverse {a b : M₀} (h : Commute a b) : Commute (Ring.inverse a) (Ring.inverse b) := (Ring.mul_inverse_rev' h.symm).symm.trans <| (congr_arg _ h.symm.eq).trans <| Ring.mul_inverse_rev' h @[deprecated (since := "2025-04-22")] alias Commute.ring_inverse_ring_inverse := Commute.ringInverse_ringInverse namespace Commute @[simp] theorem zero_right [MulZeroClass G₀] (a : G₀) : Commute a 0 := SemiconjBy.zero_right a @[simp] theorem zero_left [MulZeroClass G₀] (a : G₀) : Commute 0 a := SemiconjBy.zero_left a a variable [GroupWithZero G₀] {a b c : G₀} @[simp] theorem inv_left_iff₀ : Commute a⁻¹ b ↔ Commute a b := SemiconjBy.inv_symm_left_iff₀ theorem inv_left₀ (h : Commute a b) : Commute a⁻¹ b := inv_left_iff₀.2 h @[simp] theorem inv_right_iff₀ : Commute a b⁻¹ ↔ Commute a b := SemiconjBy.inv_right_iff₀ theorem inv_right₀ (h : Commute a b) : Commute a b⁻¹ := inv_right_iff₀.2 h @[simp] theorem div_right (hab : Commute a b) (hac : Commute a c) : Commute a (b / c) := SemiconjBy.div_right hab hac @[simp] theorem div_left (hac : Commute a c) (hbc : Commute b c) : Commute (a / b) c := by rw [div_eq_mul_inv] exact hac.mul_left hbc.inv_left₀ end Commute section GroupWithZero variable [GroupWithZero G₀] theorem pow_inv_comm₀ (a : G₀) (m n : ℕ) : a⁻¹ ^ m * a ^ n = a ^ n * a⁻¹ ^ m := (Commute.refl a).inv_left₀.pow_pow m n end GroupWithZero
.lake/packages/mathlib/Mathlib/Algebra/GroupWithZero/Basic.lean
import Mathlib.Algebra.Group.Basic import Mathlib.Algebra.GroupWithZero.NeZero import Mathlib.Logic.Unique import Mathlib.Tactic.Conv /-! # Groups with an adjoined zero element This file describes structures that are not usually studied on their own right in mathematics, namely a special sort of monoid: apart from a distinguished “zero element” they form a group, or in other words, they are groups with an adjoined zero element. Examples are: * division rings; * the value monoid of a multiplicative valuation; * in particular, the non-negative real numbers. ## Main definitions Various lemmas about `GroupWithZero` and `CommGroupWithZero`. To reduce import dependencies, the type-classes themselves are in `Algebra.GroupWithZero.Defs`. ## Implementation details As is usual in mathlib, we extend the inverse function to the zero element, and require `0⁻¹ = 0`. -/ assert_not_exists DenselyOrdered Ring open Function variable {M₀ G₀ : Type*} section section MulZeroClass variable [MulZeroClass M₀] {a b : M₀} theorem left_ne_zero_of_mul : a * b ≠ 0 → a ≠ 0 := mt fun h => mul_eq_zero_of_left h b theorem right_ne_zero_of_mul : a * b ≠ 0 → b ≠ 0 := mt (mul_eq_zero_of_right a) theorem ne_zero_and_ne_zero_of_mul (h : a * b ≠ 0) : a ≠ 0 ∧ b ≠ 0 := ⟨left_ne_zero_of_mul h, right_ne_zero_of_mul h⟩ theorem mul_eq_zero_of_ne_zero_imp_eq_zero {a b : M₀} (h : a ≠ 0 → b = 0) : a * b = 0 := by have : Decidable (a = 0) := Classical.propDecidable (a = 0) exact if ha : a = 0 then by rw [ha, zero_mul] else by rw [h ha, mul_zero] /-- To match `one_mul_eq_id`. -/ theorem zero_mul_eq_const : ((0 : M₀) * ·) = Function.const _ 0 := funext zero_mul /-- To match `mul_one_eq_id`. -/ theorem mul_zero_eq_const : (· * (0 : M₀)) = Function.const _ 0 := funext mul_zero end MulZeroClass section Mul variable [Mul M₀] [Zero M₀] [NoZeroDivisors M₀] {a b : M₀} theorem eq_zero_of_mul_self_eq_zero (h : a * a = 0) : a = 0 := (eq_zero_or_eq_zero_of_mul_eq_zero h).elim id id theorem mul_ne_zero (ha : a ≠ 0) (hb : b ≠ 0) : a * b ≠ 0 := mt eq_zero_or_eq_zero_of_mul_eq_zero <| not_or.mpr ⟨ha, hb⟩ end Mul namespace NeZero instance mul [Zero M₀] [Mul M₀] [NoZeroDivisors M₀] {x y : M₀} [NeZero x] [NeZero y] : NeZero (x * y) := ⟨mul_ne_zero out out⟩ end NeZero end section variable [MulZeroOneClass M₀] /-- In a monoid with zero, if zero equals one, then zero is the only element. -/ theorem eq_zero_of_zero_eq_one (h : (0 : M₀) = 1) (a : M₀) : a = 0 := by rw [← mul_one a, ← h, mul_zero] /-- In a monoid with zero, if zero equals one, then zero is the unique element. Somewhat arbitrarily, we define the default element to be `0`. All other elements will be provably equal to it, but not necessarily definitionally equal. -/ def uniqueOfZeroEqOne (h : (0 : M₀) = 1) : Unique M₀ where default := 0 uniq := eq_zero_of_zero_eq_one h /-- In a monoid with zero, zero equals one if and only if all elements of that semiring are equal. -/ theorem subsingleton_iff_zero_eq_one : (0 : M₀) = 1 ↔ Subsingleton M₀ := ⟨fun h => haveI := uniqueOfZeroEqOne h; inferInstance, fun h => @Subsingleton.elim _ h _ _⟩ alias ⟨subsingleton_of_zero_eq_one, _⟩ := subsingleton_iff_zero_eq_one theorem eq_of_zero_eq_one (h : (0 : M₀) = 1) (a b : M₀) : a = b := @Subsingleton.elim _ (subsingleton_of_zero_eq_one h) a b /-- In a monoid with zero, either zero and one are nonequal, or zero is the only element. -/ theorem zero_ne_one_or_forall_eq_0 : (0 : M₀) ≠ 1 ∨ ∀ a : M₀, a = 0 := not_or_of_imp eq_zero_of_zero_eq_one end section variable [MulZeroOneClass M₀] [Nontrivial M₀] {a b : M₀} theorem left_ne_zero_of_mul_eq_one (h : a * b = 1) : a ≠ 0 := left_ne_zero_of_mul <| ne_zero_of_eq_one h theorem right_ne_zero_of_mul_eq_one (h : a * b = 1) : b ≠ 0 := right_ne_zero_of_mul <| ne_zero_of_eq_one h end section MonoidWithZero variable [MonoidWithZero M₀] {a : M₀} {n : ℕ} @[simp] lemma zero_pow : ∀ {n : ℕ}, n ≠ 0 → (0 : M₀) ^ n = 0 | n + 1, _ => by rw [pow_succ, mul_zero] lemma zero_pow_eq (n : ℕ) : (0 : M₀) ^ n = if n = 0 then 1 else 0 := by split_ifs with h · rw [h, pow_zero] · rw [zero_pow h] lemma zero_pow_eq_one₀ [Nontrivial M₀] : (0 : M₀) ^ n = 1 ↔ n = 0 := by rw [zero_pow_eq, one_ne_zero.ite_eq_left_iff] lemma pow_eq_zero_of_le : ∀ {m n}, m ≤ n → a ^ m = 0 → a ^ n = 0 | _, _, Nat.le.refl, ha => ha | _, _, Nat.le.step hmn, ha => by rw [pow_succ, pow_eq_zero_of_le hmn ha, zero_mul] lemma ne_zero_pow (hn : n ≠ 0) (ha : a ^ n ≠ 0) : a ≠ 0 := by rintro rfl; exact ha <| zero_pow hn @[simp] lemma zero_pow_eq_zero [Nontrivial M₀] : (0 : M₀) ^ n = 0 ↔ n ≠ 0 := ⟨by rintro h rfl; simp at h, zero_pow⟩ lemma pow_mul_eq_zero_of_le {a b : M₀} {m n : ℕ} (hmn : m ≤ n) (h : a ^ m * b = 0) : a ^ n * b = 0 := by rw [show n = n - m + m by cutsat, pow_add, mul_assoc, h] simp variable [NoZeroDivisors M₀] lemma eq_zero_of_pow_eq_zero : ∀ {n}, a ^ n = 0 → a = 0 | 0, ha => by simpa using congr_arg (a * ·) ha | n + 1, ha => by rw [pow_succ, mul_eq_zero] at ha; exact ha.elim eq_zero_of_pow_eq_zero id @[deprecated (since := "2025-10-14")] alias pow_eq_zero := eq_zero_of_pow_eq_zero @[simp] lemma pow_eq_zero_iff (hn : n ≠ 0) : a ^ n = 0 ↔ a = 0 := ⟨eq_zero_of_pow_eq_zero, by rintro rfl; exact zero_pow hn⟩ lemma pow_ne_zero_iff (hn : n ≠ 0) : a ^ n ≠ 0 ↔ a ≠ 0 := (pow_eq_zero_iff hn).not lemma pow_ne_zero (n : ℕ) (h : a ≠ 0) : a ^ n ≠ 0 := mt eq_zero_of_pow_eq_zero h instance NeZero.pow [NeZero a] : NeZero (a ^ n) := ⟨pow_ne_zero n NeZero.out⟩ lemma sq_eq_zero_iff : a ^ 2 = 0 ↔ a = 0 := pow_eq_zero_iff two_ne_zero @[simp] lemma pow_eq_zero_iff' [Nontrivial M₀] : a ^ n = 0 ↔ a = 0 ∧ n ≠ 0 := by obtain rfl | hn := eq_or_ne n 0 <;> simp [*] theorem exists_right_inv_of_exists_left_inv {α} [MonoidWithZero α] (h : ∀ a : α, a ≠ 0 → ∃ b : α, b * a = 1) {a : α} (ha : a ≠ 0) : ∃ b : α, a * b = 1 := by obtain _ | _ := subsingleton_or_nontrivial α · exact ⟨a, Subsingleton.elim _ _⟩ obtain ⟨b, hb⟩ := h a ha obtain ⟨c, hc⟩ := h b (left_ne_zero_of_mul <| hb.trans_ne one_ne_zero) refine ⟨b, ?_⟩ conv_lhs => rw [← one_mul (a * b), ← hc, mul_assoc, ← mul_assoc b, hb, one_mul, hc] end MonoidWithZero section CancelMonoidWithZero variable [CancelMonoidWithZero M₀] {a b c : M₀} -- see Note [lower instance priority] instance (priority := 10) CancelMonoidWithZero.to_noZeroDivisors : NoZeroDivisors M₀ := ⟨fun ab0 => or_iff_not_imp_left.mpr fun ha => mul_left_cancel₀ ha <| ab0.trans (mul_zero _).symm⟩ @[simp] theorem mul_eq_mul_right_iff : a * c = b * c ↔ a = b ∨ c = 0 := by by_cases hc : c = 0 <;> [simp only [hc, mul_zero, or_true]; simp [mul_left_inj', hc]] @[simp] theorem mul_eq_mul_left_iff : a * b = a * c ↔ b = c ∨ a = 0 := by by_cases ha : a = 0 <;> [simp only [ha, zero_mul, or_true]; simp [mul_right_inj', ha]] theorem mul_right_eq_self₀ : a * b = a ↔ b = 1 ∨ a = 0 := calc a * b = a ↔ a * b = a * 1 := by rw [mul_one] _ ↔ b = 1 ∨ a = 0 := mul_eq_mul_left_iff theorem mul_left_eq_self₀ : a * b = b ↔ a = 1 ∨ b = 0 := calc a * b = b ↔ a * b = 1 * b := by rw [one_mul] _ ↔ a = 1 ∨ b = 0 := mul_eq_mul_right_iff @[simp] theorem mul_eq_left₀ (ha : a ≠ 0) : a * b = a ↔ b = 1 := by rw [Iff.comm, ← mul_right_inj' ha, mul_one] @[simp] theorem mul_eq_right₀ (hb : b ≠ 0) : a * b = b ↔ a = 1 := by rw [Iff.comm, ← mul_left_inj' hb, one_mul] @[simp] theorem left_eq_mul₀ (ha : a ≠ 0) : a = a * b ↔ b = 1 := by rw [eq_comm, mul_eq_left₀ ha] @[simp] theorem right_eq_mul₀ (hb : b ≠ 0) : b = a * b ↔ a = 1 := by rw [eq_comm, mul_eq_right₀ hb] /-- An element of a `CancelMonoidWithZero` fixed by right multiplication by an element other than one must be zero. -/ theorem eq_zero_of_mul_eq_self_right (h₁ : b ≠ 1) (h₂ : a * b = a) : a = 0 := Classical.byContradiction fun ha => h₁ <| mul_left_cancel₀ ha <| h₂.symm ▸ (mul_one a).symm /-- An element of a `CancelMonoidWithZero` fixed by left multiplication by an element other than one must be zero. -/ theorem eq_zero_of_mul_eq_self_left (h₁ : b ≠ 1) (h₂ : b * a = a) : a = 0 := Classical.byContradiction fun ha => h₁ <| mul_right_cancel₀ ha <| h₂.symm ▸ (one_mul a).symm end CancelMonoidWithZero section GroupWithZero variable [GroupWithZero G₀] {a b x : G₀} theorem GroupWithZero.mul_right_injective (h : x ≠ 0) : Function.Injective fun y => x * y := fun y y' w => by simpa only [← mul_assoc, inv_mul_cancel₀ h, one_mul] using congr_arg (fun y => x⁻¹ * y) w theorem GroupWithZero.mul_left_injective (h : x ≠ 0) : Function.Injective fun y => y * x := fun y y' w => by simpa only [mul_assoc, mul_inv_cancel₀ h, mul_one] using congr_arg (fun y => y * x⁻¹) w @[simp high] -- should take priority over `IsUnit.mul_inv_cancel_right` theorem inv_mul_cancel_right₀ (h : b ≠ 0) (a : G₀) : a * b⁻¹ * b = a := calc a * b⁻¹ * b = a * (b⁻¹ * b) := mul_assoc _ _ _ _ = a := by simp [h] @[simp high] -- should take priority over `IsUnit.mul_inv_cancel_left` theorem inv_mul_cancel_left₀ (h : a ≠ 0) (b : G₀) : a⁻¹ * (a * b) = b := calc a⁻¹ * (a * b) = a⁻¹ * a * b := (mul_assoc _ _ _).symm _ = b := by simp [h] private theorem inv_eq_of_mul (h : a * b = 1) : a⁻¹ = b := by rw [← inv_mul_cancel_left₀ (left_ne_zero_of_mul_eq_one h) b, h, mul_one] -- See note [lower instance priority] instance (priority := 100) GroupWithZero.toDivisionMonoid : DivisionMonoid G₀ := { ‹GroupWithZero G₀› with inv := Inv.inv, inv_inv := fun a => by by_cases h : a = 0 · simp [h] · exact left_inv_eq_right_inv (inv_mul_cancel₀ <| inv_ne_zero h) (inv_mul_cancel₀ h) mul_inv_rev := fun a b => by by_cases ha : a = 0 · simp [ha] by_cases hb : b = 0 · simp [hb] apply inv_eq_of_mul simp [mul_assoc, ha, hb], inv_eq_of_mul := fun _ _ => inv_eq_of_mul } -- see Note [lower instance priority] instance (priority := 10) GroupWithZero.toCancelMonoidWithZero : CancelMonoidWithZero G₀ := { (‹_› : GroupWithZero G₀) with mul_left_cancel_of_ne_zero {x} hx y z h := by dsimp only at h; rw [← inv_mul_cancel_left₀ hx y, h, inv_mul_cancel_left₀ hx z], mul_right_cancel_of_ne_zero {x} hx y z h := by dsimp only at h; rw [← mul_inv_cancel_right₀ hx y, h, mul_inv_cancel_right₀ hx z] } end GroupWithZero section GroupWithZero variable [GroupWithZero G₀] {a : G₀} @[simp] theorem zero_div (a : G₀) : 0 / a = 0 := by rw [div_eq_mul_inv, zero_mul] @[simp] theorem div_zero (a : G₀) : a / 0 = 0 := by rw [div_eq_mul_inv, inv_zero, mul_zero] /-- Multiplying `a` by itself and then by its inverse results in `a` (whether or not `a` is zero). -/ @[simp] theorem mul_self_mul_inv (a : G₀) : a * a * a⁻¹ = a := by by_cases h : a = 0 · rw [h, inv_zero, mul_zero] · rw [mul_assoc, mul_inv_cancel₀ h, mul_one] /-- Multiplying `a` by its inverse and then by itself results in `a` (whether or not `a` is zero). -/ @[simp] theorem mul_inv_mul_cancel (a : G₀) : a * a⁻¹ * a = a := by by_cases h : a = 0 · rw [h, inv_zero, mul_zero] · rw [mul_inv_cancel₀ h, one_mul] /-- Multiplying `a⁻¹` by `a` twice results in `a` (whether or not `a` is zero). -/ @[simp] theorem inv_mul_mul_self (a : G₀) : a⁻¹ * a * a = a := by by_cases h : a = 0 · rw [h, inv_zero, mul_zero] · rw [inv_mul_cancel₀ h, one_mul] /-- Multiplying `a` by itself and then dividing by itself results in `a`, whether or not `a` is zero. -/ @[simp] theorem mul_self_div_self (a : G₀) : a * a / a = a := by rw [div_eq_mul_inv, mul_self_mul_inv a] /-- Dividing `a` by itself and then multiplying by itself results in `a`, whether or not `a` is zero. -/ @[simp] theorem div_self_mul_self (a : G₀) : a / a * a = a := by rw [div_eq_mul_inv, mul_inv_mul_cancel a] attribute [local simp] div_eq_mul_inv mul_comm mul_assoc mul_left_comm @[simp] theorem div_self_mul_self' (a : G₀) : a / (a * a) = a⁻¹ := calc a / (a * a) = a⁻¹⁻¹ * a⁻¹ * a⁻¹ := by simp [mul_inv_rev] _ = a⁻¹ := inv_mul_mul_self _ theorem one_div_ne_zero {a : G₀} (h : a ≠ 0) : 1 / a ≠ 0 := by simpa only [one_div] using inv_ne_zero h @[simp] theorem inv_eq_zero {a : G₀} : a⁻¹ = 0 ↔ a = 0 := by rw [inv_eq_iff_eq_inv, inv_zero] @[simp] theorem zero_eq_inv {a : G₀} : 0 = a⁻¹ ↔ 0 = a := eq_comm.trans <| inv_eq_zero.trans eq_comm /-- Dividing `a` by the result of dividing `a` by itself results in `a` (whether or not `a` is zero). -/ @[simp] theorem div_div_self (a : G₀) : a / (a / a) = a := by rw [div_div_eq_mul_div] exact mul_self_div_self a theorem ne_zero_of_one_div_ne_zero {a : G₀} (h : 1 / a ≠ 0) : a ≠ 0 := fun ha : a = 0 => by rw [ha, div_zero] at h contradiction theorem eq_zero_of_one_div_eq_zero {a : G₀} (h : 1 / a = 0) : a = 0 := Classical.byCases (fun ha => ha) fun ha => ((one_div_ne_zero ha) h).elim theorem mul_left_surjective₀ {a : G₀} (h : a ≠ 0) : Surjective fun g => a * g := fun g => ⟨a⁻¹ * g, by simp [← mul_assoc, mul_inv_cancel₀ h]⟩ theorem mul_right_surjective₀ {a : G₀} (h : a ≠ 0) : Surjective fun g => g * a := fun g => ⟨g * a⁻¹, by simp [mul_assoc, inv_mul_cancel₀ h]⟩ lemma zero_zpow : ∀ n : ℤ, n ≠ 0 → (0 : G₀) ^ n = 0 | (n : ℕ), h => by rw [zpow_natCast, zero_pow]; simpa [Int.natCast_eq_zero] using h | .negSucc n, _ => by simp lemma zero_zpow_eq (n : ℤ) : (0 : G₀) ^ n = if n = 0 then 1 else 0 := by split_ifs with h · rw [h, zpow_zero] · rw [zero_zpow _ h] lemma zero_zpow_eq_one₀ {n : ℤ} : (0 : G₀) ^ n = 1 ↔ n = 0 := by rw [zero_zpow_eq, one_ne_zero.ite_eq_left_iff] lemma zpow_add_one₀ (ha : a ≠ 0) : ∀ n : ℤ, a ^ (n + 1) = a ^ n * a | (n : ℕ) => by simp only [← Int.natCast_succ, zpow_natCast, pow_succ] | -1 => by simp [ha] | .negSucc (n + 1) => by rw [Int.negSucc_eq, zpow_neg, Int.neg_add, Int.neg_add_cancel_right, zpow_neg, ← Int.natCast_succ, zpow_natCast, zpow_natCast, pow_succ' _ (n + 1), mul_inv_rev, mul_assoc, inv_mul_cancel₀ ha, mul_one] lemma zpow_sub_one₀ (ha : a ≠ 0) (n : ℤ) : a ^ (n - 1) = a ^ n * a⁻¹ := calc a ^ (n - 1) = a ^ (n - 1) * a * a⁻¹ := by rw [mul_assoc, mul_inv_cancel₀ ha, mul_one] _ = a ^ n * a⁻¹ := by rw [← zpow_add_one₀ ha, Int.sub_add_cancel] lemma zpow_add₀ (ha : a ≠ 0) (m n : ℤ) : a ^ (m + n) = a ^ m * a ^ n := by induction n with | zero => simp | succ n ihn => simp only [← Int.add_assoc, zpow_add_one₀ ha, ihn, mul_assoc] | pred n ihn => rw [zpow_sub_one₀ ha, ← mul_assoc, ← ihn, ← zpow_sub_one₀ ha, Int.add_sub_assoc] lemma zpow_add' {m n : ℤ} (h : a ≠ 0 ∨ m + n ≠ 0 ∨ m = 0 ∧ n = 0) : a ^ (m + n) = a ^ m * a ^ n := by by_cases hm : m = 0 · simp [hm] by_cases hn : n = 0 · simp [hn] by_cases ha : a = 0 · subst a simp only [false_or, not_true, Ne, hm, hn, false_and, or_false] at h rw [zero_zpow _ h, zero_zpow _ hm, zero_mul] · exact zpow_add₀ ha m n lemma zpow_one_add₀ (h : a ≠ 0) (i : ℤ) : a ^ (1 + i) = a * a ^ i := by rw [zpow_add₀ h, zpow_one] end GroupWithZero section CommGroupWithZero variable [CommGroupWithZero G₀] theorem div_mul_eq_mul_div₀ (a b c : G₀) : a / c * b = a * b / c := by simp_rw [div_eq_mul_inv, mul_assoc, mul_comm c⁻¹] lemma div_sq_cancel (a b : G₀) : a ^ 2 * b / a = a * b := by obtain rfl | ha := eq_or_ne a 0 · simp · rw [sq, mul_assoc, mul_div_cancel_left₀ _ ha] end CommGroupWithZero
.lake/packages/mathlib/Mathlib/Algebra/GroupWithZero/ULift.lean
import Mathlib.Algebra.Group.ULift import Mathlib.Algebra.GroupWithZero.InjSurj /-! # `ULift` instances for groups and monoids with zero This file defines instances for group and monoid with zero and related structures on `ULift` types. (Recall `ULift α` is just a "copy" of a type `α` in a higher universe.) -/ assert_not_exists Ring universe u variable {α : Type u} namespace ULift instance mulZeroOneClass [MulZeroOneClass α] : MulZeroOneClass (ULift α) := Equiv.ulift.injective.mulZeroOneClass _ rfl rfl (by intros; rfl) instance monoidWithZero [MonoidWithZero α] : MonoidWithZero (ULift α) := Equiv.ulift.injective.monoidWithZero _ rfl rfl (fun _ _ => rfl) fun _ _ => rfl instance commMonoidWithZero [CommMonoidWithZero α] : CommMonoidWithZero (ULift α) := Equiv.ulift.injective.commMonoidWithZero _ rfl rfl (fun _ _ => rfl) fun _ _ => rfl instance groupWithZero [GroupWithZero α] : GroupWithZero (ULift α) := Equiv.ulift.injective.groupWithZero _ rfl rfl (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl instance commGroupWithZero [CommGroupWithZero α] : CommGroupWithZero (ULift α) := Equiv.ulift.injective.commGroupWithZero _ rfl rfl (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl end ULift
.lake/packages/mathlib/Mathlib/Algebra/GroupWithZero/Conj.lean
import Mathlib.Algebra.Group.Conj import Mathlib.Algebra.GroupWithZero.Units.Basic /-! # Conjugacy in a group with zero -/ assert_not_exists Multiset Ring -- TODO -- assert_not_exists DenselyOrdered namespace GroupWithZero variable {α : Type*} [GroupWithZero α] {a b : α} @[simp] lemma isConj_iff₀ : IsConj a b ↔ ∃ c : α, c ≠ 0 ∧ c * a * c⁻¹ = b := by rw [IsConj, Units.exists_iff_ne_zero (p := (SemiconjBy · a b))] congr! 2 with c exact and_congr_right (mul_inv_eq_iff_eq_mul₀ · |>.symm) lemma conj_pow₀ {s : ℕ} {a d : α} (ha : a ≠ 0) : (a⁻¹ * d * a) ^ s = a⁻¹ * d ^ s * a := let u : αˣ := ⟨a, a⁻¹, mul_inv_cancel₀ ha, inv_mul_cancel₀ ha⟩ Units.conj_pow' u d s end GroupWithZero
.lake/packages/mathlib/Mathlib/Algebra/GroupWithZero/InjSurj.lean
import Mathlib.Algebra.Group.InjSurj import Mathlib.Algebra.GroupWithZero.NeZero /-! # Lifting groups with zero along injective/surjective maps -/ assert_not_exists DenselyOrdered Ring open Function variable {M₀ G₀ M₀' G₀' : Type*} section MulZeroClass variable [MulZeroClass M₀] /-- Pull back a `MulZeroClass` instance along an injective function. See note [reducible non-instances]. -/ protected abbrev Function.Injective.mulZeroClass [Mul M₀'] [Zero M₀'] (f : M₀' → M₀) (hf : Injective f) (zero : f 0 = 0) (mul : ∀ a b, f (a * b) = f a * f b) : MulZeroClass M₀' where zero_mul a := hf <| by simp only [mul, zero, zero_mul] mul_zero a := hf <| by simp only [mul, zero, mul_zero] /-- Push forward a `MulZeroClass` instance along a surjective function. See note [reducible non-instances]. -/ protected abbrev Function.Surjective.mulZeroClass [Mul M₀'] [Zero M₀'] (f : M₀ → M₀') (hf : Surjective f) (zero : f 0 = 0) (mul : ∀ a b, f (a * b) = f a * f b) : MulZeroClass M₀' where mul_zero := hf.forall.2 fun x => by simp only [← zero, ← mul, mul_zero] zero_mul := hf.forall.2 fun x => by simp only [← zero, ← mul, zero_mul] end MulZeroClass section NoZeroDivisors variable [Mul M₀] [Zero M₀] [Mul M₀'] [Zero M₀'] (f : M₀ → M₀') (hf : Injective f) (zero : f 0 = 0) (mul : ∀ x y, f (x * y) = f x * f y) include hf zero mul /-- Pull back a `NoZeroDivisors` instance along an injective function. -/ protected theorem Function.Injective.noZeroDivisors [NoZeroDivisors M₀'] : NoZeroDivisors M₀ where eq_zero_or_eq_zero_of_mul_eq_zero {a b} H := have : f a * f b = 0 := by rw [← mul, H, zero] (eq_zero_or_eq_zero_of_mul_eq_zero this).imp (fun H ↦ hf <| by rwa [zero]) fun H ↦ hf <| by rwa [zero] protected theorem Function.Injective.isLeftCancelMulZero [IsLeftCancelMulZero M₀'] : IsLeftCancelMulZero M₀ where mul_left_cancel_of_ne_zero Hne _ _ He := by have := congr_arg f He rw [mul, mul] at this exact hf (mul_left_cancel₀ (fun Hfa => Hne <| hf <| by rw [Hfa, zero]) this) protected theorem Function.Injective.isRightCancelMulZero [IsRightCancelMulZero M₀'] : IsRightCancelMulZero M₀ where mul_right_cancel_of_ne_zero Hne _ _ He := by have := congr_arg f He rw [mul, mul] at this exact hf (mul_right_cancel₀ (fun Hfa => Hne <| hf <| by rw [Hfa, zero]) this) protected theorem Function.Injective.isCancelMulZero [IsCancelMulZero M₀'] : IsCancelMulZero M₀ where __ := hf.isLeftCancelMulZero f zero mul __ := hf.isRightCancelMulZero f zero mul end NoZeroDivisors section MulZeroOneClass variable [MulZeroOneClass M₀] /-- Pull back a `MulZeroOneClass` instance along an injective function. See note [reducible non-instances]. -/ protected abbrev Function.Injective.mulZeroOneClass [Mul M₀'] [Zero M₀'] [One M₀'] (f : M₀' → M₀) (hf : Injective f) (zero : f 0 = 0) (one : f 1 = 1) (mul : ∀ a b, f (a * b) = f a * f b) : MulZeroOneClass M₀' := { hf.mulZeroClass f zero mul, hf.mulOneClass f one mul with } /-- Push forward a `MulZeroOneClass` instance along a surjective function. See note [reducible non-instances]. -/ protected abbrev Function.Surjective.mulZeroOneClass [Mul M₀'] [Zero M₀'] [One M₀'] (f : M₀ → M₀') (hf : Surjective f) (zero : f 0 = 0) (one : f 1 = 1) (mul : ∀ a b, f (a * b) = f a * f b) : MulZeroOneClass M₀' := { hf.mulZeroClass f zero mul, hf.mulOneClass f one mul with } end MulZeroOneClass section SemigroupWithZero /-- Pull back a `SemigroupWithZero` along an injective function. See note [reducible non-instances]. -/ protected abbrev Function.Injective.semigroupWithZero [Zero M₀'] [Mul M₀'] [SemigroupWithZero M₀] (f : M₀' → M₀) (hf : Injective f) (zero : f 0 = 0) (mul : ∀ x y, f (x * y) = f x * f y) : SemigroupWithZero M₀' := { hf.mulZeroClass f zero mul, ‹Zero M₀'›, hf.semigroup f mul with } /-- Push forward a `SemigroupWithZero` along a surjective function. See note [reducible non-instances]. -/ protected abbrev Function.Surjective.semigroupWithZero [SemigroupWithZero M₀] [Zero M₀'] [Mul M₀'] (f : M₀ → M₀') (hf : Surjective f) (zero : f 0 = 0) (mul : ∀ x y, f (x * y) = f x * f y) : SemigroupWithZero M₀' := { hf.mulZeroClass f zero mul, ‹Zero M₀'›, hf.semigroup f mul with } end SemigroupWithZero section MonoidWithZero /-- Pull back a `MonoidWithZero` along an injective function. See note [reducible non-instances]. -/ protected abbrev Function.Injective.monoidWithZero [Zero M₀'] [Mul M₀'] [One M₀'] [Pow M₀' ℕ] [MonoidWithZero M₀] (f : M₀' → M₀) (hf : Injective f) (zero : f 0 = 0) (one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) : MonoidWithZero M₀' := { hf.monoid f one mul npow, hf.mulZeroClass f zero mul with } /-- Push forward a `MonoidWithZero` along a surjective function. See note [reducible non-instances]. -/ protected abbrev Function.Surjective.monoidWithZero [Zero M₀'] [Mul M₀'] [One M₀'] [Pow M₀' ℕ] [MonoidWithZero M₀] (f : M₀ → M₀') (hf : Surjective f) (zero : f 0 = 0) (one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) : MonoidWithZero M₀' := { hf.monoid f one mul npow, hf.mulZeroClass f zero mul with } /-- Pull back a `CommMonoidWithZero` along an injective function. See note [reducible non-instances]. -/ protected abbrev Function.Injective.commMonoidWithZero [Zero M₀'] [Mul M₀'] [One M₀'] [Pow M₀' ℕ] [CommMonoidWithZero M₀] (f : M₀' → M₀) (hf : Injective f) (zero : f 0 = 0) (one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) : CommMonoidWithZero M₀' := { hf.commMonoid f one mul npow, hf.mulZeroClass f zero mul with } /-- Push forward a `CommMonoidWithZero` along a surjective function. See note [reducible non-instances]. -/ protected abbrev Function.Surjective.commMonoidWithZero [Zero M₀'] [Mul M₀'] [One M₀'] [Pow M₀' ℕ] [CommMonoidWithZero M₀] (f : M₀ → M₀') (hf : Surjective f) (zero : f 0 = 0) (one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) : CommMonoidWithZero M₀' := { hf.commMonoid f one mul npow, hf.mulZeroClass f zero mul with } end MonoidWithZero section CancelMonoidWithZero variable [CancelMonoidWithZero M₀] /-- Pull back a `CancelMonoidWithZero` along an injective function. See note [reducible non-instances]. -/ protected abbrev Function.Injective.cancelMonoidWithZero [Zero M₀'] [Mul M₀'] [One M₀'] [Pow M₀' ℕ] (f : M₀' → M₀) (hf : Injective f) (zero : f 0 = 0) (one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) : CancelMonoidWithZero M₀' := { hf.monoid f one mul npow, hf.mulZeroClass f zero mul with mul_left_cancel_of_ne_zero hx _ _ H := hf <| mul_left_cancel₀ ((hf.ne_iff' zero).2 hx) <| by dsimp only at H; rw [← mul, ← mul, H], mul_right_cancel_of_ne_zero hx _ _ H := hf <| mul_right_cancel₀ ((hf.ne_iff' zero).2 hx) <| by dsimp only at H; rw [← mul, ← mul, H] } end CancelMonoidWithZero section CancelCommMonoidWithZero variable [CancelCommMonoidWithZero M₀] /-- Pull back a `CancelCommMonoidWithZero` along an injective function. See note [reducible non-instances]. -/ protected abbrev Function.Injective.cancelCommMonoidWithZero [Zero M₀'] [Mul M₀'] [One M₀'] [Pow M₀' ℕ] (f : M₀' → M₀) (hf : Injective f) (zero : f 0 = 0) (one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) : CancelCommMonoidWithZero M₀' := { hf.commMonoidWithZero f zero one mul npow, hf.cancelMonoidWithZero f zero one mul npow with } end CancelCommMonoidWithZero section GroupWithZero variable [GroupWithZero G₀] /-- Pull back a `GroupWithZero` along an injective function. See note [reducible non-instances]. -/ protected abbrev Function.Injective.groupWithZero [Zero G₀'] [Mul G₀'] [One G₀'] [Inv G₀'] [Div G₀'] [Pow G₀' ℕ] [Pow G₀' ℤ] (f : G₀' → G₀) (hf : Injective f) (zero : f 0 = 0) (one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) (inv : ∀ x, f x⁻¹ = (f x)⁻¹) (div : ∀ x y, f (x / y) = f x / f y) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) (zpow : ∀ (x) (n : ℤ), f (x ^ n) = f x ^ n) : GroupWithZero G₀' := { hf.monoidWithZero f zero one mul npow, hf.divInvMonoid f one mul inv div npow zpow, domain_nontrivial f zero one with inv_zero := hf <| by rw [inv, zero, inv_zero], mul_inv_cancel := fun x hx => hf <| by rw [one, mul, inv, mul_inv_cancel₀ ((hf.ne_iff' zero).2 hx)] } /-- Push forward a `GroupWithZero` along a surjective function. See note [reducible non-instances]. -/ protected abbrev Function.Surjective.groupWithZero [Zero G₀'] [Mul G₀'] [One G₀'] [Inv G₀'] [Div G₀'] [Pow G₀' ℕ] [Pow G₀' ℤ] (h01 : (0 : G₀') ≠ 1) (f : G₀ → G₀') (hf : Surjective f) (zero : f 0 = 0) (one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) (inv : ∀ x, f x⁻¹ = (f x)⁻¹) (div : ∀ x y, f (x / y) = f x / f y) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) (zpow : ∀ (x) (n : ℤ), f (x ^ n) = f x ^ n) : GroupWithZero G₀' := { hf.monoidWithZero f zero one mul npow, hf.divInvMonoid f one mul inv div npow zpow with inv_zero := by rw [← zero, ← inv, inv_zero], mul_inv_cancel := hf.forall.2 fun x hx => by rw [← inv, ← mul, mul_inv_cancel₀ (mt (congr_arg f) fun h ↦ hx (h.trans zero)), one] exists_pair_ne := ⟨0, 1, h01⟩ } end GroupWithZero section CommGroupWithZero variable [CommGroupWithZero G₀] /-- Pull back a `CommGroupWithZero` along an injective function. See note [reducible non-instances]. -/ protected abbrev Function.Injective.commGroupWithZero [Zero G₀'] [Mul G₀'] [One G₀'] [Inv G₀'] [Div G₀'] [Pow G₀' ℕ] [Pow G₀' ℤ] (f : G₀' → G₀) (hf : Injective f) (zero : f 0 = 0) (one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) (inv : ∀ x, f x⁻¹ = (f x)⁻¹) (div : ∀ x y, f (x / y) = f x / f y) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) (zpow : ∀ (x) (n : ℤ), f (x ^ n) = f x ^ n) : CommGroupWithZero G₀' := { hf.groupWithZero f zero one mul inv div npow zpow, hf.commSemigroup f mul with } /-- Push forward a `CommGroupWithZero` along a surjective function. See note [reducible non-instances]. -/ protected def Function.Surjective.commGroupWithZero [Zero G₀'] [Mul G₀'] [One G₀'] [Inv G₀'] [Div G₀'] [Pow G₀' ℕ] [Pow G₀' ℤ] (h01 : (0 : G₀') ≠ 1) (f : G₀ → G₀') (hf : Surjective f) (zero : f 0 = 0) (one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) (inv : ∀ x, f x⁻¹ = (f x)⁻¹) (div : ∀ x y, f (x / y) = f x / f y) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) (zpow : ∀ (x) (n : ℤ), f (x ^ n) = f x ^ n) : CommGroupWithZero G₀' := { hf.groupWithZero h01 f zero one mul inv div npow zpow, hf.commSemigroup f mul with } end CommGroupWithZero
.lake/packages/mathlib/Mathlib/Algebra/GroupWithZero/Defs.lean
import Mathlib.Algebra.Group.Defs import Mathlib.Logic.Nontrivial.Defs import Mathlib.Logic.Basic /-! # Typeclasses for groups with an adjoined zero element This file provides just the typeclass definitions, and the projection lemmas that expose their members. ## Main definitions * `GroupWithZero` * `CommGroupWithZero` -/ assert_not_exists DenselyOrdered Ring universe u -- We have to fix the universe of `G₀` here, since the default argument to -- `GroupWithZero.div'` cannot contain a universe metavariable. variable {G₀ : Type u} {M₀ : Type*} /-- Typeclass for expressing that a type `M₀` with multiplication and a zero satisfies `0 * a = 0` and `a * 0 = 0` for all `a : M₀`. -/ class MulZeroClass (M₀ : Type u) extends Mul M₀, Zero M₀ where /-- Zero is a left absorbing element for multiplication -/ zero_mul : ∀ a : M₀, 0 * a = 0 /-- Zero is a right absorbing element for multiplication -/ mul_zero : ∀ a : M₀, a * 0 = 0 /-- A mixin for left cancellative multiplication by nonzero elements. -/ @[mk_iff] class IsLeftCancelMulZero (M₀ : Type u) [Mul M₀] [Zero M₀] : Prop where /-- Multiplication by a nonzero element is left cancellative. -/ protected mul_left_cancel_of_ne_zero : ∀ {a : M₀}, a ≠ 0 → IsLeftRegular a section IsLeftCancelMulZero variable [Mul M₀] [Zero M₀] [IsLeftCancelMulZero M₀] {a b c : M₀} theorem mul_left_cancel₀ (ha : a ≠ 0) (h : a * b = a * c) : b = c := IsLeftCancelMulZero.mul_left_cancel_of_ne_zero ha h theorem mul_right_injective₀ (ha : a ≠ 0) : Function.Injective (a * ·) := fun _ _ => mul_left_cancel₀ ha end IsLeftCancelMulZero /-- A mixin for right cancellative multiplication by nonzero elements. -/ @[mk_iff] class IsRightCancelMulZero (M₀ : Type u) [Mul M₀] [Zero M₀] : Prop where /-- Multiplication by a nonzero element is right cancellative. -/ protected mul_right_cancel_of_ne_zero : ∀ {a : M₀}, a ≠ 0 → IsRightRegular a section IsRightCancelMulZero variable [Mul M₀] [Zero M₀] [IsRightCancelMulZero M₀] {a b c : M₀} theorem mul_right_cancel₀ (hb : b ≠ 0) (h : a * b = c * b) : a = c := IsRightCancelMulZero.mul_right_cancel_of_ne_zero hb h theorem mul_left_injective₀ (hb : b ≠ 0) : Function.Injective fun a => a * b := fun _ _ => mul_right_cancel₀ hb end IsRightCancelMulZero /-- A mixin for cancellative multiplication by nonzero elements. -/ @[mk_iff] class IsCancelMulZero (M₀ : Type u) [Mul M₀] [Zero M₀] : Prop extends IsLeftCancelMulZero M₀, IsRightCancelMulZero M₀ export MulZeroClass (zero_mul mul_zero) attribute [simp] zero_mul mul_zero theorem isCancelMulZero_iff_forall_isRegular {M₀} [Mul M₀] [Zero M₀] : IsCancelMulZero M₀ ↔ ∀ {a : M₀}, a ≠ 0 → IsRegular a := by simp only [isCancelMulZero_iff, isLeftCancelMulZero_iff, isRightCancelMulZero_iff, ← forall_and] exact forall₂_congr fun _ _ ↦ isRegular_iff.symm /-- Predicate typeclass for expressing that `a * b = 0` implies `a = 0` or `b = 0` for all `a` and `b` of type `M₀`. It is weaker than `IsCancelMulZero` in general, but equivalent to it if `M₀` is a (not necessarily unital or associative) ring. -/ @[mk_iff] class NoZeroDivisors (M₀ : Type*) [Mul M₀] [Zero M₀] : Prop where /-- For all `a` and `b` of `M₀`, `a * b = 0` implies `a = 0` or `b = 0`. -/ eq_zero_or_eq_zero_of_mul_eq_zero : ∀ {a b : M₀}, a * b = 0 → a = 0 ∨ b = 0 export NoZeroDivisors (eq_zero_or_eq_zero_of_mul_eq_zero) /-- A type `S₀` is a "semigroup with zero” if it is a semigroup with zero element, and `0` is left and right absorbing. -/ class SemigroupWithZero (S₀ : Type u) extends Semigroup S₀, MulZeroClass S₀ /-- A typeclass for non-associative monoids with zero elements. -/ class MulZeroOneClass (M₀ : Type u) extends MulOneClass M₀, MulZeroClass M₀ /-- A type `M₀` is a “monoid with zero” if it is a monoid with zero element, and `0` is left and right absorbing. -/ class MonoidWithZero (M₀ : Type u) extends Monoid M₀, MulZeroOneClass M₀, SemigroupWithZero M₀ section MonoidWithZero variable [MonoidWithZero M₀] /-- If `x` is multiplicative with respect to `f`, then so is any `x^n`. -/ theorem pow_mul_apply_eq_pow_mul {M : Type*} [Monoid M] (f : M₀ → M) {x : M₀} (hx : ∀ y : M₀, f (x * y) = f x * f y) (n : ℕ) : ∀ (y : M₀), f (x ^ n * y) = f x ^ n * f y := by induction n with | zero => intro y; rw [pow_zero, pow_zero, one_mul, one_mul] | succ n hn => intro y; rw [pow_succ', pow_succ', mul_assoc, mul_assoc, hx, hn] end MonoidWithZero /-- A type `M` is a `CancelMonoidWithZero` if it is a monoid with zero element, `0` is left and right absorbing, and left/right multiplication by a non-zero element is injective. -/ class CancelMonoidWithZero (M₀ : Type*) extends MonoidWithZero M₀, IsCancelMulZero M₀ /-- A type `M` is a commutative “monoid with zero” if it is a commutative monoid with zero element, and `0` is left and right absorbing. -/ class CommMonoidWithZero (M₀ : Type*) extends CommMonoid M₀, MonoidWithZero M₀ section CancelMonoidWithZero variable [CancelMonoidWithZero M₀] {a b c : M₀} theorem mul_left_inj' (hc : c ≠ 0) : a * c = b * c ↔ a = b := (mul_left_injective₀ hc).eq_iff theorem mul_right_inj' (ha : a ≠ 0) : a * b = a * c ↔ b = c := (mul_right_injective₀ ha).eq_iff end CancelMonoidWithZero section CommSemigroup variable [CommSemigroup M₀] [Zero M₀] lemma IsLeftCancelMulZero.to_isRightCancelMulZero [IsLeftCancelMulZero M₀] : IsRightCancelMulZero M₀ := { mul_right_cancel_of_ne_zero := fun hb _ _ h => mul_left_cancel₀ hb <| (mul_comm _ _).trans (h.trans (mul_comm _ _)) } lemma IsRightCancelMulZero.to_isLeftCancelMulZero [IsRightCancelMulZero M₀] : IsLeftCancelMulZero M₀ := { mul_left_cancel_of_ne_zero := fun hb _ _ h => mul_right_cancel₀ hb <| (mul_comm _ _).trans (h.trans (mul_comm _ _)) } lemma IsLeftCancelMulZero.to_isCancelMulZero [IsLeftCancelMulZero M₀] : IsCancelMulZero M₀ := { IsLeftCancelMulZero.to_isRightCancelMulZero with } lemma IsRightCancelMulZero.to_isCancelMulZero [IsRightCancelMulZero M₀] : IsCancelMulZero M₀ := { IsRightCancelMulZero.to_isLeftCancelMulZero with } end CommSemigroup /-- A type `M` is a `CancelCommMonoidWithZero` if it is a commutative monoid with zero element, `0` is left and right absorbing, and left/right multiplication by a non-zero element is injective. -/ class CancelCommMonoidWithZero (M₀ : Type*) extends CommMonoidWithZero M₀, IsLeftCancelMulZero M₀ -- See note [lower cancel priority] attribute [instance 75] CancelCommMonoidWithZero.toCommMonoidWithZero instance (priority := 100) CancelCommMonoidWithZero.toCancelMonoidWithZero [CancelCommMonoidWithZero M₀] : CancelMonoidWithZero M₀ := { IsLeftCancelMulZero.to_isCancelMulZero (M₀ := M₀) with } /-- Prop-valued mixin for a monoid with zero to be equipped with a cancelling division. The obvious use case is groups with zero, but this condition is also satisfied by `ℕ`, `ℤ` and, more generally, any Euclidean domain. -/ class MulDivCancelClass (M₀ : Type*) [MonoidWithZero M₀] [Div M₀] : Prop where protected mul_div_cancel (a b : M₀) : b ≠ 0 → a * b / b = a section MulDivCancelClass variable [MonoidWithZero M₀] [Div M₀] [MulDivCancelClass M₀] @[simp] lemma mul_div_cancel_right₀ (a : M₀) {b : M₀} (hb : b ≠ 0) : a * b / b = a := MulDivCancelClass.mul_div_cancel _ _ hb end MulDivCancelClass section MulDivCancelClass variable [CommMonoidWithZero M₀] [Div M₀] [MulDivCancelClass M₀] @[simp] lemma mul_div_cancel_left₀ (b : M₀) {a : M₀} (ha : a ≠ 0) : a * b / a = b := by rw [mul_comm, mul_div_cancel_right₀ _ ha] end MulDivCancelClass /-- A type `G₀` is a “group with zero” if it is a monoid with zero element (distinct from `1`) such that every nonzero element is invertible. The type is required to come with an “inverse” function, and the inverse of `0` must be `0`. Examples include division rings and the ordered monoids that are the target of valuations in general valuation theory. -/ class GroupWithZero (G₀ : Type u) extends MonoidWithZero G₀, DivInvMonoid G₀, Nontrivial G₀ where /-- The inverse of `0` in a group with zero is `0`. -/ protected inv_zero : (0 : G₀)⁻¹ = 0 /-- Every nonzero element of a group with zero is invertible. -/ protected mul_inv_cancel (a : G₀) : a ≠ 0 → a * a⁻¹ = 1 section GroupWithZero variable [GroupWithZero G₀] {a : G₀} @[simp] lemma inv_zero : (0 : G₀)⁻¹ = 0 := GroupWithZero.inv_zero @[simp high] -- should take priority over `IsUnit.mul_inv_cancel` lemma mul_inv_cancel₀ (h : a ≠ 0) : a * a⁻¹ = 1 := GroupWithZero.mul_inv_cancel a h -- See note [lower instance priority] instance (priority := 100) GroupWithZero.toMulDivCancelClass : MulDivCancelClass G₀ where mul_div_cancel a b hb := by rw [div_eq_mul_inv, mul_assoc, mul_inv_cancel₀ hb, mul_one] end GroupWithZero /-- A type `G₀` is a commutative “group with zero” if it is a commutative monoid with zero element (distinct from `1`) such that every nonzero element is invertible. The type is required to come with an “inverse” function, and the inverse of `0` must be `0`. -/ class CommGroupWithZero (G₀ : Type*) extends CommMonoidWithZero G₀, GroupWithZero G₀ section variable [CancelMonoidWithZero M₀] {x : M₀} lemma eq_zero_or_one_of_sq_eq_self (hx : x ^ 2 = x) : x = 0 ∨ x = 1 := or_iff_not_imp_left.mpr (mul_left_injective₀ · <| by simpa [sq] using hx) end section GroupWithZero variable [GroupWithZero G₀] {a b : G₀} @[simp high] -- should take priority over `IsUnit.mul_inv_cancel_right` theorem mul_inv_cancel_right₀ (h : b ≠ 0) (a : G₀) : a * b * b⁻¹ = a := calc a * b * b⁻¹ = a * (b * b⁻¹) := mul_assoc _ _ _ _ = a := by simp [h] @[simp high] -- should take priority over `IsUnit.mul_inv_cancel_left` theorem mul_inv_cancel_left₀ (h : a ≠ 0) (b : G₀) : a * (a⁻¹ * b) = b := calc a * (a⁻¹ * b) = a * a⁻¹ * b := (mul_assoc _ _ _).symm _ = b := by simp [h] end GroupWithZero section MulZeroClass variable [MulZeroClass M₀] theorem mul_eq_zero_of_left {a : M₀} (h : a = 0) (b : M₀) : a * b = 0 := h.symm ▸ zero_mul b theorem mul_eq_zero_of_right (a : M₀) {b : M₀} (h : b = 0) : a * b = 0 := h.symm ▸ mul_zero a lemma noZeroDivisors_iff_right_eq_zero_of_mul : NoZeroDivisors M₀ ↔ ∀ x : M₀, x ≠ 0 → ∀ y, x * y = 0 → y = 0 := by simp only [noZeroDivisors_iff, or_iff_not_imp_left] exact ⟨fun h a ha b eq ↦ h eq ha, fun h a b eq ha ↦ h a ha b eq⟩ lemma noZeroDivisors_iff_left_eq_zero_of_mul : NoZeroDivisors M₀ ↔ ∀ x : M₀, x ≠ 0 → ∀ y, y * x = 0 → y = 0 := by simp only [noZeroDivisors_iff, or_iff_not_imp_right] exact ⟨fun h b hb a eq ↦ h eq hb, fun h a b eq hb ↦ h b hb a eq⟩ lemma noZeroDivisors_iff_eq_zero_of_mul : NoZeroDivisors M₀ ↔ ∀ x : M₀, x ≠ 0 → (∀ y, x * y = 0 → y = 0) ∧ (∀ y, y * x = 0 → y = 0) := by simp only [forall_and, ← noZeroDivisors_iff_right_eq_zero_of_mul, ← noZeroDivisors_iff_left_eq_zero_of_mul, and_self] variable [NoZeroDivisors M₀] {a b : M₀} /-- If `α` has no zero divisors, then the product of two elements equals zero iff one of them equals zero. -/ @[simp] theorem mul_eq_zero : a * b = 0 ↔ a = 0 ∨ b = 0 := ⟨eq_zero_or_eq_zero_of_mul_eq_zero, fun o ↦ o.elim (fun h ↦ mul_eq_zero_of_left h b) (mul_eq_zero_of_right a)⟩ /-- If `α` has no zero divisors, then the product of two elements equals zero iff one of them equals zero. -/ @[simp] theorem zero_eq_mul : 0 = a * b ↔ a = 0 ∨ b = 0 := by rw [eq_comm, mul_eq_zero] /-- If `α` has no zero divisors, then the product of two elements is nonzero iff both of them are nonzero. -/ theorem mul_ne_zero_iff : a * b ≠ 0 ↔ a ≠ 0 ∧ b ≠ 0 := mul_eq_zero.not.trans not_or /-- If `α` has no zero divisors, then for elements `a, b : α`, `a * b` equals zero iff so is `b * a`. -/ theorem mul_eq_zero_comm : a * b = 0 ↔ b * a = 0 := mul_eq_zero.trans <| or_comm.trans mul_eq_zero.symm /-- If `α` has no zero divisors, then for elements `a, b : α`, `a * b` is nonzero iff so is `b * a`. -/ theorem mul_ne_zero_comm : a * b ≠ 0 ↔ b * a ≠ 0 := mul_eq_zero_comm.not theorem mul_self_eq_zero : a * a = 0 ↔ a = 0 := by simp theorem zero_eq_mul_self : 0 = a * a ↔ a = 0 := by simp theorem mul_self_ne_zero : a * a ≠ 0 ↔ a ≠ 0 := mul_self_eq_zero.not theorem zero_ne_mul_self : 0 ≠ a * a ↔ a ≠ 0 := zero_eq_mul_self.not theorem mul_eq_zero_iff_left (ha : a ≠ 0) : a * b = 0 ↔ b = 0 := by simp [ha] theorem mul_eq_zero_iff_right (hb : b ≠ 0) : a * b = 0 ↔ a = 0 := by simp [hb] theorem mul_ne_zero_iff_left (ha : a ≠ 0) : a * b ≠ 0 ↔ b ≠ 0 := by simp [ha] theorem mul_ne_zero_iff_right (hb : b ≠ 0) : a * b ≠ 0 ↔ a ≠ 0 := by simp [hb] end MulZeroClass
.lake/packages/mathlib/Mathlib/Algebra/GroupWithZero/Shrink.lean
import Mathlib.Algebra.Group.Shrink import Mathlib.Algebra.GroupWithZero.Action.TransferInstance import Mathlib.Algebra.GroupWithZero.TransferInstance /-! # Transfer group with zero structures from `α` to `Shrink α` -/ noncomputable section universe v variable {M α : Type*} [Small.{v} α] instance [SemigroupWithZero α] : SemigroupWithZero (Shrink α) := (equivShrink _).symm.semigroupWithZero instance [MulZeroClass α] : MulZeroClass (Shrink α) := (equivShrink _).symm.mulZeroClass instance [MulZeroOneClass α] : MulZeroOneClass (Shrink α) := (equivShrink _).symm.mulZeroOneClass instance [Monoid M] [AddCommMonoid α] [DistribMulAction M α] : DistribMulAction M (Shrink.{v} α) := (equivShrink α).symm.distribMulAction M
.lake/packages/mathlib/Mathlib/Algebra/GroupWithZero/NonZeroDivisors.lean
import Mathlib.Algebra.Group.Submonoid.Membership import Mathlib.Algebra.GroupWithZero.Associated import Mathlib.Algebra.GroupWithZero.Regular import Mathlib.Algebra.NoZeroSMulDivisors.Defs import Mathlib.Algebra.Regular.SMul /-! # Non-zero divisors and smul-divisors In this file we define the submonoid `nonZeroDivisors` and `nonZeroSMulDivisors` of a `MonoidWithZero`. We also define `nonZeroDivisorsLeft` and `nonZeroDivisorsRight` for non-commutative monoids. ## Notation This file declares the notations: - `M₀⁰` for the submonoid of non-zero-divisors of `M₀`, in the scope `nonZeroDivisors`. - `M₀⁰[M]` for the submonoid of non-zero smul-divisors of `M₀` with respect to `M`, in the locale `nonZeroSMulDivisors` Use the statement `open scoped nonZeroDivisors nonZeroSMulDivisors` to access this notation in your own code. -/ assert_not_exists Ring open Function section variable (M₀ : Type*) [MonoidWithZero M₀] {x : M₀} /-- The collection of elements of a `MonoidWithZero` that are not left zero divisors form a `Submonoid`. -/ def nonZeroDivisorsLeft : Submonoid M₀ where carrier := {x | ∀ y, x * y = 0 → y = 0} one_mem' := by simp mul_mem' {x y} hx hy := fun z hz ↦ hy _ <| hx _ (mul_assoc x y z ▸ hz) @[simp] lemma mem_nonZeroDivisorsLeft_iff : x ∈ nonZeroDivisorsLeft M₀ ↔ ∀ y, x * y = 0 → y = 0 := .rfl lemma notMem_nonZeroDivisorsLeft_iff : x ∉ nonZeroDivisorsLeft M₀ ↔ {y | x * y = 0 ∧ y ≠ 0}.Nonempty := by simpa [mem_nonZeroDivisorsLeft_iff] using Set.nonempty_def.symm @[deprecated (since := "2025-05-24")] alias nmem_nonZeroDivisorsLeft_iff := notMem_nonZeroDivisorsLeft_iff /-- The collection of elements of a `MonoidWithZero` that are not right zero divisors form a `Submonoid`. -/ def nonZeroDivisorsRight : Submonoid M₀ where carrier := {x | ∀ y, y * x = 0 → y = 0} one_mem' := by simp mul_mem' := fun {x y} hx hy z hz ↦ hx _ (hy _ ((mul_assoc z x y).symm ▸ hz)) @[simp] lemma mem_nonZeroDivisorsRight_iff : x ∈ nonZeroDivisorsRight M₀ ↔ ∀ y, y * x = 0 → y = 0 := .rfl lemma notMem_nonZeroDivisorsRight_iff : x ∉ nonZeroDivisorsRight M₀ ↔ {y | y * x = 0 ∧ y ≠ 0}.Nonempty := by simpa [mem_nonZeroDivisorsRight_iff] using Set.nonempty_def.symm @[deprecated (since := "2025-05-24")] alias nmem_nonZeroDivisorsRight_iff := notMem_nonZeroDivisorsRight_iff lemma nonZeroDivisorsLeft_eq_right (M₀ : Type*) [CommMonoidWithZero M₀] : nonZeroDivisorsLeft M₀ = nonZeroDivisorsRight M₀ := by ext x; simp [mul_comm x] @[simp] lemma coe_nonZeroDivisorsLeft_eq [NoZeroDivisors M₀] [Nontrivial M₀] : nonZeroDivisorsLeft M₀ = {x : M₀ | x ≠ 0} := by ext x simp only [SetLike.mem_coe, mem_nonZeroDivisorsLeft_iff, mul_eq_zero, Set.mem_setOf_eq] refine ⟨fun h ↦ ?_, fun hx y hx' ↦ by simp_all⟩ contrapose! h exact ⟨1, Or.inl h, one_ne_zero⟩ @[simp] lemma coe_nonZeroDivisorsRight_eq [NoZeroDivisors M₀] [Nontrivial M₀] : nonZeroDivisorsRight M₀ = {x : M₀ | x ≠ 0} := by ext x simp only [SetLike.mem_coe, mem_nonZeroDivisorsRight_iff, mul_eq_zero, forall_eq_or_imp, true_and, Set.mem_setOf_eq] refine ⟨fun h ↦ ?_, fun hx y hx' ↦ by contradiction⟩ contrapose! h exact ⟨1, h, one_ne_zero⟩ end /-- The submonoid of non-zero-divisors of a `MonoidWithZero` `M₀`. -/ def nonZeroDivisors (M₀ : Type*) [MonoidWithZero M₀] : Submonoid M₀ := nonZeroDivisorsLeft M₀ ⊓ nonZeroDivisorsRight M₀ /-- The notation for the submonoid of non-zero divisors. -/ scoped[nonZeroDivisors] notation:9000 M₀ "⁰" => nonZeroDivisors M₀ /-- Let `M₀` be a monoid with zero and `M` an additive monoid with an `M₀`-action, then the collection of non-zero smul-divisors forms a submonoid. These elements are also called `M`-regular. -/ def nonZeroSMulDivisors (M₀ : Type*) [MonoidWithZero M₀] (M : Type*) [Zero M] [MulAction M₀ M] : Submonoid M₀ where carrier := { r | ∀ m : M, r • m = 0 → m = 0} one_mem' m h := (one_smul M₀ m) ▸ h mul_mem' {r₁ r₂} h₁ h₂ m H := h₂ _ <| h₁ _ <| mul_smul r₁ r₂ m ▸ H /-- The notation for the submonoid of non-zero smul-divisors. -/ scoped[nonZeroSMulDivisors] notation:9000 M₀ "⁰[" M "]" => nonZeroSMulDivisors M₀ M open nonZeroDivisors section MonoidWithZero variable {F M₀ M₀' : Type*} [MonoidWithZero M₀] [MonoidWithZero M₀'] {r x y : M₀} lemma nonZeroDivisorsLeft_eq_nonZeroSMulDivisors : nonZeroDivisorsLeft M₀ = nonZeroSMulDivisors M₀ M₀ := rfl @[deprecated (since := "2025-07-16")] alias nonZeroDivisorsRight_eq_nonZeroSMulDivisors := nonZeroDivisorsLeft_eq_nonZeroSMulDivisors theorem mem_nonZeroDivisors_iff : r ∈ M₀⁰ ↔ (∀ x, r * x = 0 → x = 0) ∧ ∀ x, x * r = 0 → x = 0 := Iff.rfl lemma notMem_nonZeroDivisors_iff : r ∉ M₀⁰ ↔ {s | r * s = 0 ∧ s ≠ 0}.Nonempty ∨ {s | s * r = 0 ∧ s ≠ 0}.Nonempty := by simp [-not_and, not_and_or, mem_nonZeroDivisors_iff, Set.nonempty_def] @[deprecated (since := "2025-05-24")] alias nmem_nonZeroDivisors_iff := notMem_nonZeroDivisors_iff theorem mul_left_mem_nonZeroDivisorsLeft_eq_zero_iff (hr : r ∈ nonZeroDivisorsLeft M₀) : r * x = 0 ↔ x = 0 := ⟨hr _, by simp +contextual⟩ theorem mul_right_mem_nonZeroDivisorsRight_eq_zero_iff (hr : r ∈ nonZeroDivisorsRight M₀) : x * r = 0 ↔ x = 0 := ⟨hr _, by simp +contextual⟩ theorem mul_right_mem_nonZeroDivisors_eq_zero_iff (hr : r ∈ M₀⁰) : x * r = 0 ↔ x = 0 := mul_right_mem_nonZeroDivisorsRight_eq_zero_iff hr.2 @[simp] theorem mul_right_coe_nonZeroDivisors_eq_zero_iff {c : M₀⁰} : x * c = 0 ↔ x = 0 := mul_right_mem_nonZeroDivisors_eq_zero_iff c.prop lemma IsUnit.mem_nonZeroDivisors (hx : IsUnit x) : x ∈ M₀⁰ := ⟨fun _ ↦ hx.mul_right_eq_zero.mp, fun _ ↦ hx.mul_left_eq_zero.mp⟩ variable (M₀) in lemma isUnit_le_nonZeroDivisors : IsUnit.submonoid M₀ ≤ M₀⁰ := fun _ ↦ (·.mem_nonZeroDivisors) section Nontrivial variable [Nontrivial M₀] theorem zero_notMem_nonZeroDivisorsLeft : 0 ∉ nonZeroDivisorsLeft M₀ := fun h ↦ one_ne_zero <| h 1 <| zero_mul _ theorem zero_notMem_nonZeroDivisorsRight : 0 ∉ nonZeroDivisorsRight M₀ := fun h ↦ one_ne_zero <| h 1 <| mul_zero _ theorem zero_notMem_nonZeroDivisors : 0 ∉ M₀⁰ := fun h ↦ zero_notMem_nonZeroDivisorsLeft h.1 @[deprecated (since := "2025-05-23")] alias zero_not_mem_nonZeroDivisors := zero_notMem_nonZeroDivisors theorem nonZeroDivisors.ne_zero (hx : x ∈ M₀⁰) : x ≠ 0 := ne_of_mem_of_not_mem hx zero_notMem_nonZeroDivisors @[simp] theorem nonZeroDivisors.coe_ne_zero (x : M₀⁰) : (x : M₀) ≠ 0 := nonZeroDivisors.ne_zero x.2 instance [IsLeftCancelMulZero M₀] : LeftCancelMonoid M₀⁰ where mul_left_cancel _ _ _ h := Subtype.ext <| mul_left_cancel₀ (nonZeroDivisors.coe_ne_zero _) (by simpa only [Subtype.ext_iff, Submonoid.coe_mul] using h) instance [IsRightCancelMulZero M₀] : RightCancelMonoid M₀⁰ where mul_right_cancel _ _ _ h := Subtype.ext <| mul_right_cancel₀ (nonZeroDivisors.coe_ne_zero _) (by simpa only [Subtype.ext_iff, Submonoid.coe_mul] using h) end Nontrivial section NoZeroDivisors variable [NoZeroDivisors M₀] theorem eq_zero_of_ne_zero_of_mul_right_eq_zero (hx : x ≠ 0) (hxy : y * x = 0) : y = 0 := Or.resolve_right (eq_zero_or_eq_zero_of_mul_eq_zero hxy) hx theorem eq_zero_of_ne_zero_of_mul_left_eq_zero (hx : x ≠ 0) (hxy : x * y = 0) : y = 0 := Or.resolve_left (eq_zero_or_eq_zero_of_mul_eq_zero hxy) hx theorem mem_nonZeroDivisors_of_ne_zero (hx : x ≠ 0) : x ∈ M₀⁰ := ⟨fun _ ↦ eq_zero_of_ne_zero_of_mul_left_eq_zero hx, fun _ ↦ eq_zero_of_ne_zero_of_mul_right_eq_zero hx⟩ @[simp] lemma mem_nonZeroDivisors_iff_ne_zero [Nontrivial M₀] : x ∈ M₀⁰ ↔ x ≠ 0 := ⟨nonZeroDivisors.ne_zero, mem_nonZeroDivisors_of_ne_zero⟩ theorem le_nonZeroDivisors_of_noZeroDivisors {S : Submonoid M₀} (hS : (0 : M₀) ∉ S) : S ≤ M₀⁰ := fun _ hx ↦ mem_nonZeroDivisors_of_ne_zero <| by rintro rfl; exact hS hx theorem powers_le_nonZeroDivisors_of_noZeroDivisors (hx : x ≠ 0) : Submonoid.powers x ≤ M₀⁰ := le_nonZeroDivisors_of_noZeroDivisors fun h ↦ hx (h.recOn fun _ ↦ eq_zero_of_pow_eq_zero) end NoZeroDivisors lemma IsLeftRegular.mem_nonZeroDivisorsLeft (h : IsLeftRegular r) : r ∈ nonZeroDivisorsLeft M₀ := fun _x hx ↦ h.mul_left_eq_zero_iff.mp hx lemma IsRightRegular.mem_nonZeroDivisorsRight (h : IsRightRegular r) : r ∈ nonZeroDivisorsRight M₀ := fun _x hx ↦ h.mul_right_eq_zero_iff.mp hx lemma IsRegular.mem_nonZeroDivisors (h : IsRegular r) : r ∈ M₀⁰ := ⟨h.1.mem_nonZeroDivisorsLeft, h.2.mem_nonZeroDivisorsRight⟩ lemma noZeroDivisors_iff_forall_mem_nonZeroDivisorsLeft : NoZeroDivisors M₀ ↔ ∀ x : M₀, x ≠ 0 → x ∈ nonZeroDivisorsLeft M₀ := noZeroDivisors_iff_right_eq_zero_of_mul lemma noZeroDivisors_iff_forall_mem_nonZeroDivisorsRight : NoZeroDivisors M₀ ↔ ∀ x : M₀, x ≠ 0 → x ∈ nonZeroDivisorsRight M₀ := noZeroDivisors_iff_left_eq_zero_of_mul lemma noZeroDivisors_iff_forall_mem_nonZeroDivisors : NoZeroDivisors M₀ ↔ ∀ x : M₀, x ≠ 0 → x ∈ M₀⁰ := noZeroDivisors_iff_eq_zero_of_mul lemma noZeroSMulDivisors_iff_forall_mem_nonZeroSMulDivisors {M : Type*} [Zero M] [MulAction M₀ M] : NoZeroSMulDivisors M₀ M ↔ ∀ x : M₀, x ≠ 0 → x ∈ nonZeroSMulDivisors M₀ M := noZeroSMulDivisors_iff_right_eq_zero_of_smul lemma IsSMulRegular.mem_nonZeroSMulDivisors {M : Type*} [Zero M] [MulActionWithZero M₀ M] {m₀ : M₀} (h : IsSMulRegular M m₀) : m₀ ∈ nonZeroSMulDivisors M₀ M := fun _ ↦ h.right_eq_zero_of_smul lemma isSMulRegular_iff_mem_nonZeroSMulDivisors {M : Type*} [AddGroup M] [DistribMulAction M₀ M] {m₀ : M₀} : IsSMulRegular M m₀ ↔ m₀ ∈ nonZeroSMulDivisors M₀ M := isSMulRegular_iff_right_eq_zero_of_smul variable [FunLike F M₀ M₀'] -- TODO: nonZeroDivisorsLeft/Right also works theorem map_ne_zero_of_mem_nonZeroDivisors [Nontrivial M₀] [ZeroHomClass F M₀ M₀'] (g : F) (hg : Injective (g : M₀ → M₀')) {x : M₀} (h : x ∈ M₀⁰) : g x ≠ 0 := fun h0 ↦ one_ne_zero (h.2 1 ((one_mul x).symm ▸ hg (h0.trans (map_zero g).symm))) theorem map_mem_nonZeroDivisors [Nontrivial M₀] [NoZeroDivisors M₀'] [ZeroHomClass F M₀ M₀'] (g : F) (hg : Injective g) {x : M₀} (h : x ∈ M₀⁰) : g x ∈ M₀'⁰ := ⟨fun _ ↦ eq_zero_of_ne_zero_of_mul_left_eq_zero (map_ne_zero_of_mem_nonZeroDivisors g hg h), fun _ ↦ eq_zero_of_ne_zero_of_mul_right_eq_zero (map_ne_zero_of_mem_nonZeroDivisors g hg h)⟩ theorem MulEquivClass.map_nonZeroDivisors {M₀ S F : Type*} [MonoidWithZero M₀] [MonoidWithZero S] [EquivLike F M₀ S] [MulEquivClass F M₀ S] (h : F) : Submonoid.map h (nonZeroDivisors M₀) = nonZeroDivisors S := by let h : M₀ ≃* S := h change Submonoid.map h _ = _ ext simp_rw [Submonoid.map_equiv_eq_comap_symm, Submonoid.mem_comap, mem_nonZeroDivisors_iff, ← h.symm.forall_congr_right, h.symm.toEquiv_eq_coe, h.symm.coe_toEquiv, ← map_mul, map_eq_zero_iff _ h.symm.injective] theorem map_le_nonZeroDivisors_of_injective [NoZeroDivisors M₀'] [MonoidWithZeroHomClass F M₀ M₀'] (f : F) (hf : Injective f) {S : Submonoid M₀} (hS : S ≤ M₀⁰) : S.map f ≤ M₀'⁰ := by cases subsingleton_or_nontrivial M₀ · simp [Subsingleton.elim S ⊥] · refine le_nonZeroDivisors_of_noZeroDivisors ?_ rintro ⟨x, hx, hx0⟩ exact zero_notMem_nonZeroDivisors <| hS <| map_eq_zero_iff f hf |>.mp hx0 ▸ hx theorem nonZeroDivisors_le_comap_nonZeroDivisors_of_injective [NoZeroDivisors M₀'] [MonoidWithZeroHomClass F M₀ M₀'] (f : F) (hf : Injective f) : M₀⁰ ≤ M₀'⁰.comap f := Submonoid.le_comap_of_map_le _ (map_le_nonZeroDivisors_of_injective _ hf le_rfl) /-- If an element maps to a non-zero-divisor via injective homomorphism, then it is a non-zero-divisor. -/ theorem mem_nonZeroDivisors_of_injective [MonoidWithZeroHomClass F M₀ M₀'] {f : F} (hf : Injective f) (hx : f x ∈ M₀'⁰) : x ∈ M₀⁰ := ⟨fun y hy ↦ hf <| map_zero f ▸ hx.1 (f y) (map_mul f x y ▸ map_zero f ▸ congrArg f hy), fun y hy ↦ hf <| map_zero f ▸ hx.2 (f y) (map_mul f y x ▸ map_zero f ▸ congrArg f hy)⟩ theorem comap_nonZeroDivisors_le_of_injective [MonoidWithZeroHomClass F M₀ M₀'] {f : F} (hf : Injective f) : M₀'⁰.comap f ≤ M₀⁰ := fun _ ha ↦ mem_nonZeroDivisors_of_injective hf (Submonoid.mem_comap.mp ha) end MonoidWithZero section CommMonoidWithZero variable {M₀ : Type*} [CommMonoidWithZero M₀] {a b r x : M₀} lemma nonZeroDivisorsLeft_eq_nonZeroDivisors : nonZeroDivisorsLeft M₀ = nonZeroDivisors M₀ := by rw [nonZeroDivisors, nonZeroDivisorsLeft_eq_right, inf_idem] lemma nonZeroDivisorsRight_eq_nonZeroDivisors : nonZeroDivisorsRight M₀ = nonZeroDivisors M₀ := by rw [← nonZeroDivisorsLeft_eq_right, nonZeroDivisorsLeft_eq_nonZeroDivisors] theorem mem_nonZeroDivisors_iff_right : r ∈ M₀⁰ ↔ ∀ x, x * r = 0 → x = 0 := by rw [← nonZeroDivisorsRight_eq_nonZeroDivisors]; rfl lemma notMem_nonZeroDivisors_iff_right : r ∉ M₀⁰ ↔ {s | s * r = 0 ∧ s ≠ 0}.Nonempty := by simp [mem_nonZeroDivisors_iff_right, Set.nonempty_def] lemma mul_left_mem_nonZeroDivisors_eq_zero_iff (hr : r ∈ M₀⁰) : r * x = 0 ↔ x = 0 := by rw [mul_comm, mul_right_mem_nonZeroDivisors_eq_zero_iff hr] @[simp] lemma mul_left_coe_nonZeroDivisors_eq_zero_iff {c : M₀⁰} : (c : M₀) * x = 0 ↔ x = 0 := mul_left_mem_nonZeroDivisors_eq_zero_iff c.prop lemma mul_mem_nonZeroDivisors : a * b ∈ M₀⁰ ↔ a ∈ M₀⁰ ∧ b ∈ M₀⁰ where mp h := by rw [← nonZeroDivisorsRight_eq_nonZeroDivisors] constructor <;> intro x h' <;> apply h.2 · rw [← mul_assoc, h', zero_mul] · rw [mul_comm a b, ← mul_assoc, h', zero_mul] mpr := fun h ↦ mul_mem h.1 h.2 theorem nonZeroDivisors_dvd_iff_dvd_coe {a b : M₀⁰} : a ∣ b ↔ (a : M₀) ∣ (b : M₀) := ⟨fun ⟨c, hc⟩ ↦ by simp_rw [hc, Submonoid.coe_mul, dvd_mul_right], fun ⟨c, hc⟩ ↦ ⟨⟨c, (mul_mem_nonZeroDivisors.mp (hc ▸ b.prop)).2⟩, by simp_rw [Subtype.ext_iff, Submonoid.coe_mul, hc]⟩⟩ end CommMonoidWithZero section GroupWithZero variable {G₀ : Type*} [GroupWithZero G₀] {x : G₀} /-- Canonical isomorphism between the non-zero-divisors and units of a group with zero. -/ @[simps] noncomputable def nonZeroDivisorsEquivUnits : G₀⁰ ≃* G₀ˣ where toFun u := .mk0 _ <| mem_nonZeroDivisors_iff_ne_zero.1 u.2 invFun u := ⟨u, u.isUnit.mem_nonZeroDivisors⟩ right_inv u := by simp map_mul' u v := by simp lemma isUnit_of_mem_nonZeroDivisors (hx : x ∈ nonZeroDivisors G₀) : IsUnit x := (nonZeroDivisorsEquivUnits ⟨x, hx⟩).isUnit end GroupWithZero section nonZeroSMulDivisors open nonZeroSMulDivisors variable {M₀ M : Type*} [MonoidWithZero M₀] [Zero M] [MulAction M₀ M] {x : M₀} lemma mem_nonZeroSMulDivisors_iff : x ∈ M₀⁰[M] ↔ ∀ (m : M), x • m = 0 → m = 0 := Iff.rfl @[deprecated (since := "2025-07-16")] alias unop_nonZeroSMulDivisors_mulOpposite_eq_nonZeroDivisors := nonZeroDivisorsLeft_eq_nonZeroSMulDivisors @[deprecated (since := "2025-07-16")] alias nonZeroSMulDivisors_mulOpposite_eq_op_nonZeroDivisors := nonZeroDivisorsLeft_eq_nonZeroSMulDivisors end nonZeroSMulDivisors open scoped nonZeroDivisors variable {M₀} section MonoidWithZero variable [MonoidWithZero M₀] {a b : M₀⁰} /-- The units of the monoid of non-zero divisors of `M₀` are equivalent to the units of `M₀`. -/ @[simps] def unitsNonZeroDivisorsEquiv : M₀⁰ˣ ≃* M₀ˣ where __ := Units.map M₀⁰.subtype invFun u := ⟨⟨u, u.isUnit.mem_nonZeroDivisors⟩, ⟨(u⁻¹ : M₀ˣ), u⁻¹.isUnit.mem_nonZeroDivisors⟩, by simp, by simp⟩ @[simp, norm_cast] lemma nonZeroDivisors.associated_coe : Associated (a : M₀) b ↔ Associated a b := unitsNonZeroDivisorsEquiv.symm.exists_congr_left.trans <| by simp [Associated]; norm_cast end MonoidWithZero section CommMonoidWithZero variable {M₀ : Type*} [CommMonoidWithZero M₀] {a : M₀} theorem mk_mem_nonZeroDivisors_associates : Associates.mk a ∈ (Associates M₀)⁰ ↔ a ∈ M₀⁰ := by rw [mem_nonZeroDivisors_iff_right, mem_nonZeroDivisors_iff_right, ← not_iff_not] push_neg constructor · rintro ⟨⟨x⟩, hx₁, hx₂⟩ refine ⟨x, ?_, ?_⟩ · rwa [← Associates.mk_eq_zero, ← Associates.mk_mul_mk, ← Associates.quot_mk_eq_mk] · rwa [← Associates.mk_ne_zero, ← Associates.quot_mk_eq_mk] · refine fun ⟨b, hb₁, hb₂⟩ ↦ ⟨Associates.mk b, ?_, by rwa [Associates.mk_ne_zero]⟩ rw [Associates.mk_mul_mk, hb₁, Associates.mk_zero] /-- The non-zero divisors of associates of a monoid with zero `M₀` are isomorphic to the associates of the non-zero divisors of `M₀` under the map `⟨⟦a⟧, _⟩ ↦ ⟦⟨a, _⟩⟧`. -/ def associatesNonZeroDivisorsEquiv : (Associates M₀)⁰ ≃* Associates M₀⁰ where toEquiv := .subtypeQuotientEquivQuotientSubtype _ (s₂ := Associated.setoid _) (· ∈ nonZeroDivisors _) (by simp [mem_nonZeroDivisors_iff, Quotient.forall, Associates.mk_mul_mk]) (by simp [Associated.setoid]) map_mul' := by simp [Quotient.forall, Associates.mk_mul_mk] @[simp] lemma associatesNonZeroDivisorsEquiv_mk_mk (a : M₀) (ha) : associatesNonZeroDivisorsEquiv ⟨⟦a⟧, ha⟩ = ⟦⟨a, mk_mem_nonZeroDivisors_associates.1 ha⟩⟧ := rfl @[simp] lemma associatesNonZeroDivisorsEquiv_symm_mk_mk (a : M₀) (ha) : associatesNonZeroDivisorsEquiv.symm ⟦⟨a, ha⟩⟧ = ⟨⟦a⟧, mk_mem_nonZeroDivisors_associates.2 ha⟩ := rfl end CommMonoidWithZero
.lake/packages/mathlib/Mathlib/Algebra/GroupWithZero/Subgroup.lean
import Mathlib.Algebra.Group.Subgroup.Pointwise import Mathlib.Algebra.GroupWithZero.Submonoid.Pointwise /-! # Subgroups in a group with zero -/ assert_not_exists Ring open Set open scoped Pointwise variable {G₀ G M A : Type*} namespace Subgroup section GroupWithZero variable [GroupWithZero G₀] [Group G] [MulDistribMulAction G₀ G] {S T : Subgroup G} {a : G₀} @[simp] lemma smul_mem_pointwise_smul_iff₀ (ha : a ≠ 0) (S : Subgroup G) (x : G) : a • x ∈ a • S ↔ x ∈ S := smul_mem_smul_set_iff₀ ha (S : Set G) x lemma mem_pointwise_smul_iff_inv_smul_mem₀ (ha : a ≠ 0) (S : Subgroup G) (x : G) : x ∈ a • S ↔ a⁻¹ • x ∈ S := mem_smul_set_iff_inv_smul_mem₀ ha (S : Set G) x lemma mem_inv_pointwise_smul_iff₀ (ha : a ≠ 0) (S : Subgroup G) (x : G) : x ∈ a⁻¹ • S ↔ a • x ∈ S := mem_inv_smul_set_iff₀ ha (S : Set G) x @[simp] lemma pointwise_smul_le_pointwise_smul_iff₀ (ha : a ≠ 0) : a • S ≤ a • T ↔ S ≤ T := smul_set_subset_smul_set_iff₀ ha lemma pointwise_smul_le_iff₀ (ha : a ≠ 0) : a • S ≤ T ↔ S ≤ a⁻¹ • T := smul_set_subset_iff₀ ha lemma le_pointwise_smul_iff₀ (ha : a ≠ 0) : S ≤ a • T ↔ a⁻¹ • S ≤ T := subset_smul_set_iff₀ ha end GroupWithZero end Subgroup namespace AddSubgroup section Monoid variable [Monoid M] [AddGroup A] [DistribMulAction M A] {a : M} /-- The action on an additive subgroup corresponding to applying the action to every element. This is available as an instance in the `Pointwise` locale. -/ protected def pointwiseMulAction : MulAction M (AddSubgroup A) where smul a S := S.map (DistribMulAction.toAddMonoidEnd _ A a) one_smul S := (congr_arg (fun f : AddMonoid.End A => S.map f) (MonoidHom.map_one _)).trans S.map_id mul_smul _ _ S := (congr_arg (fun f : AddMonoid.End A => S.map f) (MonoidHom.map_mul _ _ _)).trans (S.map_map _ _).symm scoped[Pointwise] attribute [instance] AddSubgroup.pointwiseMulAction lemma pointwise_smul_def (S : AddSubgroup A) : a • S = S.map (DistribMulAction.toAddMonoidEnd _ _ a) := rfl @[simp, norm_cast] lemma coe_pointwise_smul (a : M) (S : AddSubgroup A) : ↑(a • S) = a • (S : Set A) := rfl @[simp] lemma pointwise_smul_toAddSubmonoid (a : M) (S : AddSubgroup A) : (a • S).toAddSubmonoid = a • S.toAddSubmonoid := rfl lemma smul_mem_pointwise_smul (m : A) (a : M) (S : AddSubgroup A) : m ∈ S → a • m ∈ a • S := (Set.smul_mem_smul_set : _ → _ ∈ a • (S : Set A)) lemma mem_smul_pointwise_iff_exists (m : A) (a : M) (S : AddSubgroup A) : m ∈ a • S ↔ ∃ s : A, s ∈ S ∧ a • s = m := (Set.mem_smul_set : m ∈ a • (S : Set A) ↔ _) instance pointwise_isCentralScalar [DistribMulAction Mᵐᵒᵖ A] [IsCentralScalar M A] : IsCentralScalar M (AddSubgroup A) := ⟨fun _ S => (congr_arg fun f => S.map f) <| AddMonoidHom.ext <| op_smul_eq_smul _⟩ -- TODO: Check that these lemmas are useful and uncomment. -- @[simp] -- lemma smul_bot (m : M) : m • (⊥ : AddSubgroup A) = ⊥ := map_bot _ -- lemma smul_sup (m : M) (S T : AddSubgroup A) : m • (S ⊔ T) = m • S ⊔ m • T := map_sup _ _ _ -- @[simp] -- lemma smul_closure (m : M) (s : Set A) : m • closure s = closure (m • s) := -- AddMonoidHom.map_closure .. scoped[Pointwise] attribute [instance] AddSubgroup.pointwise_isCentralScalar end Monoid section Group variable [Group G] [AddGroup A] [DistribMulAction G A] {S T : AddSubgroup A} {a : G} {x : A} @[simp] lemma smul_mem_pointwise_smul_iff : a • x ∈ a • S ↔ x ∈ S := smul_mem_smul_set_iff lemma mem_pointwise_smul_iff_inv_smul_mem : x ∈ a • S ↔ a⁻¹ • x ∈ S := mem_smul_set_iff_inv_smul_mem lemma mem_inv_pointwise_smul_iff : x ∈ a⁻¹ • S ↔ a • x ∈ S := mem_inv_smul_set_iff @[simp] lemma pointwise_smul_le_pointwise_smul_iff : a • S ≤ a • T ↔ S ≤ T := smul_set_subset_smul_set_iff lemma pointwise_smul_le_iff : a • S ≤ T ↔ S ≤ a⁻¹ • T := smul_set_subset_iff_subset_inv_smul_set lemma le_pointwise_smul_iff : S ≤ a • T ↔ a⁻¹ • S ≤ T := subset_smul_set_iff end Group section GroupWithZero variable [GroupWithZero G₀] [AddGroup A] [DistribMulAction G₀ A] {S T : AddSubgroup A} {a : G₀} @[simp] lemma smul_mem_pointwise_smul_iff₀ (ha : a ≠ 0) (S : AddSubgroup A) (x : A) : a • x ∈ a • S ↔ x ∈ S := smul_mem_smul_set_iff₀ ha (S : Set A) x lemma mem_pointwise_smul_iff_inv_smul_mem₀ (ha : a ≠ 0) (S : AddSubgroup A) (x : A) : x ∈ a • S ↔ a⁻¹ • x ∈ S := mem_smul_set_iff_inv_smul_mem₀ ha (S : Set A) x lemma mem_inv_pointwise_smul_iff₀ (ha : a ≠ 0) (S : AddSubgroup A) (x : A) : x ∈ a⁻¹ • S ↔ a • x ∈ S := mem_inv_smul_set_iff₀ ha (S : Set A) x @[simp] lemma pointwise_smul_le_pointwise_smul_iff₀ (ha : a ≠ 0) : a • S ≤ a • T ↔ S ≤ T := smul_set_subset_smul_set_iff₀ ha lemma pointwise_smul_le_iff₀ (ha : a ≠ 0) : a • S ≤ T ↔ S ≤ a⁻¹ • T := smul_set_subset_iff₀ ha lemma le_pointwise_smul_iff₀ (ha : a ≠ 0) : S ≤ a • T ↔ a⁻¹ • S ≤ T := subset_smul_set_iff₀ ha end GroupWithZero end AddSubgroup
.lake/packages/mathlib/Mathlib/Algebra/GroupWithZero/Torsion.lean
import Mathlib.Algebra.Regular.Basic import Mathlib.RingTheory.UniqueFactorizationDomain.NormalizedFactors /-! # Torsion-free monoids with zero We prove that if `M` is an `UniqueFactorizationMonoid` that can be equipped with a `NormalizationMonoid` structure and such that `Mˣ` is torsion-free, then `M` is torsion-free. Note. You need to import this file to get that the monoid of ideals of a Dedekind domain is torsion-free. -/ variable {M : Type*} [CancelCommMonoidWithZero M] theorem IsMulTorsionFree.mk' (ih : ∀ x ≠ 0, ∀ y ≠ 0, ∀ n ≠ 0, (x ^ n : M) = y ^ n → x = y) : IsMulTorsionFree M := by refine ⟨fun n hn x y hxy ↦ ?_⟩ by_cases h : x ≠ 0 ∧ y ≠ 0 · exact ih x h.1 y h.2 n hn hxy grind [pow_eq_zero, zero_pow] variable [UniqueFactorizationMonoid M] [NormalizationMonoid M] [IsMulTorsionFree Mˣ] namespace UniqueFactorizationMonoid instance : IsMulTorsionFree M := by refine .mk' fun x hx y hy n hn hxy ↦ ?_ obtain ⟨u, hu⟩ : Associated x y := by have := (Associated.of_eq hxy).normalizedFactors_eq rwa [normalizedFactors_pow, normalizedFactors_pow, nsmul_right_inj hn, ← associated_iff_normalizedFactors_eq_normalizedFactors hx hy] at this replace hx : IsLeftRegular (x ^ n) := (IsLeftCancelMulZero.mul_left_cancel_of_ne_zero hx).pow n rw [← hu, mul_pow, eq_comm, IsLeftRegular.mul_left_eq_self_iff hx, ← Units.val_pow_eq_pow_val, Units.val_eq_one, IsMulTorsionFree.pow_eq_one_iff_left hn] at hxy rwa [hxy, Units.val_one, mul_one] at hu end UniqueFactorizationMonoid
.lake/packages/mathlib/Mathlib/Algebra/GroupWithZero/Divisibility.lean
import Mathlib.Algebra.GroupWithZero.Units.Basic import Mathlib.Algebra.Divisibility.Units import Mathlib.Data.Nat.Basic /-! # Divisibility in groups with zero. Lemmas about divisibility in groups and monoids with zero. -/ assert_not_exists DenselyOrdered Ring variable {α : Type*} section SemigroupWithZero variable [SemigroupWithZero α] {a : α} theorem eq_zero_of_zero_dvd (h : 0 ∣ a) : a = 0 := Dvd.elim h fun c H' => H'.trans (zero_mul c) /-- Given an element `a` of a commutative semigroup with zero, there exists another element whose product with zero equals `a` iff `a` equals zero. -/ @[simp] theorem zero_dvd_iff : 0 ∣ a ↔ a = 0 := ⟨eq_zero_of_zero_dvd, fun h => by rw [h] exact ⟨0, by simp⟩⟩ @[simp] theorem dvd_zero (a : α) : a ∣ 0 := Dvd.intro 0 (by simp) end SemigroupWithZero /-- Given two elements `b`, `c` of a `CancelMonoidWithZero` and a nonzero element `a`, `a*b` divides `a*c` iff `b` divides `c`. -/ theorem mul_dvd_mul_iff_left [CancelMonoidWithZero α] {a b c : α} (ha : a ≠ 0) : a * b ∣ a * c ↔ b ∣ c := exists_congr fun d => by rw [mul_assoc, mul_right_inj' ha] /-- Given two elements `a`, `b` of a commutative `CancelMonoidWithZero` and a nonzero element `c`, `a*c` divides `b*c` iff `a` divides `b`. -/ theorem mul_dvd_mul_iff_right [CancelCommMonoidWithZero α] {a b c : α} (hc : c ≠ 0) : a * c ∣ b * c ↔ a ∣ b := exists_congr fun d => by rw [mul_right_comm, mul_left_inj' hc] section CommMonoidWithZero variable [CommMonoidWithZero α] /-- `DvdNotUnit a b` expresses that `a` divides `b` "strictly", i.e. that `b` divided by `a` is not a unit. -/ def DvdNotUnit (a b : α) : Prop := a ≠ 0 ∧ ∃ x, ¬IsUnit x ∧ b = a * x theorem dvdNotUnit_of_dvd_of_not_dvd {a b : α} (hd : a ∣ b) (hnd : ¬b ∣ a) : DvdNotUnit a b := by constructor · rintro rfl exact hnd (dvd_zero _) · rcases hd with ⟨c, rfl⟩ refine ⟨c, ?_, rfl⟩ rintro ⟨u, rfl⟩ simp at hnd variable {x y : α} theorem isRelPrime_zero_left : IsRelPrime 0 x ↔ IsUnit x := ⟨(· (dvd_zero _) dvd_rfl), IsUnit.isRelPrime_right⟩ theorem isRelPrime_zero_right : IsRelPrime x 0 ↔ IsUnit x := isRelPrime_comm.trans isRelPrime_zero_left theorem not_isRelPrime_zero_zero [Nontrivial α] : ¬IsRelPrime (0 : α) 0 := mt isRelPrime_zero_right.mp not_isUnit_zero theorem IsRelPrime.ne_zero_or_ne_zero [Nontrivial α] (h : IsRelPrime x y) : x ≠ 0 ∨ y ≠ 0 := not_or_of_imp <| by rintro rfl rfl; exact not_isRelPrime_zero_zero h end CommMonoidWithZero theorem isRelPrime_of_no_nonunits_factors [MonoidWithZero α] {x y : α} (nonzero : ¬(x = 0 ∧ y = 0)) (H : ∀ z, ¬ IsUnit z → z ≠ 0 → z ∣ x → ¬z ∣ y) : IsRelPrime x y := by refine fun z hx hy ↦ by_contra fun h ↦ H z h ?_ hx hy rintro rfl; exact nonzero ⟨zero_dvd_iff.1 hx, zero_dvd_iff.1 hy⟩ theorem dvd_and_not_dvd_iff [CancelCommMonoidWithZero α] {x y : α} : x ∣ y ∧ ¬y ∣ x ↔ DvdNotUnit x y := ⟨fun ⟨⟨d, hd⟩, hyx⟩ => ⟨fun hx0 => by simp [hx0] at hyx, ⟨d, mt isUnit_iff_dvd_one.1 fun ⟨e, he⟩ => hyx ⟨e, by rw [hd, mul_assoc, ← he, mul_one]⟩, hd⟩⟩, fun ⟨hx0, d, hdu, hdx⟩ => ⟨⟨d, hdx⟩, fun ⟨e, he⟩ => hdu (isUnit_of_dvd_one ⟨e, mul_left_cancel₀ hx0 <| by conv => lhs rw [he, hdx] simp [mul_assoc]⟩)⟩⟩ section MonoidWithZero variable [MonoidWithZero α] theorem ne_zero_of_dvd_ne_zero {p q : α} (h₁ : q ≠ 0) (h₂ : p ∣ q) : p ≠ 0 := by rcases h₂ with ⟨u, rfl⟩ exact left_ne_zero_of_mul h₁ theorem isPrimal_zero : IsPrimal (0 : α) := fun a b h ↦ ⟨a, b, dvd_rfl, dvd_rfl, (zero_dvd_iff.mp h).symm⟩ theorem IsPrimal.mul {α} [CancelCommMonoidWithZero α] {m n : α} (hm : IsPrimal m) (hn : IsPrimal n) : IsPrimal (m * n) := by obtain rfl | h0 := eq_or_ne m 0; · rwa [zero_mul] intro b c h obtain ⟨a₁, a₂, ⟨b, rfl⟩, ⟨c, rfl⟩, rfl⟩ := hm (dvd_of_mul_right_dvd h) rw [mul_mul_mul_comm, mul_dvd_mul_iff_left h0] at h obtain ⟨a₁', a₂', h₁, h₂, rfl⟩ := hn h exact ⟨a₁ * a₁', a₂ * a₂', mul_dvd_mul_left _ h₁, mul_dvd_mul_left _ h₂, mul_mul_mul_comm _ _ _ _⟩ end MonoidWithZero section CancelCommMonoidWithZero variable [CancelCommMonoidWithZero α] {a b : α} {m n : ℕ} section Subsingleton variable [Subsingleton αˣ] theorem dvd_antisymm : a ∣ b → b ∣ a → a = b := by rintro ⟨c, rfl⟩ ⟨d, hcd⟩ rw [mul_assoc, eq_comm, mul_right_eq_self₀, mul_eq_one] at hcd obtain ⟨rfl, -⟩ | rfl := hcd <;> simp theorem dvd_antisymm' : a ∣ b → b ∣ a → b = a := flip dvd_antisymm alias Dvd.dvd.antisymm := dvd_antisymm alias Dvd.dvd.antisymm' := dvd_antisymm' theorem eq_of_forall_dvd (h : ∀ c, a ∣ c ↔ b ∣ c) : a = b := ((h _).2 dvd_rfl).antisymm <| (h _).1 dvd_rfl theorem eq_of_forall_dvd' (h : ∀ c, c ∣ a ↔ c ∣ b) : a = b := ((h _).1 dvd_rfl).antisymm <| (h _).2 dvd_rfl end Subsingleton lemma pow_dvd_pow_iff (ha₀ : a ≠ 0) (ha : ¬IsUnit a) : a ^ n ∣ a ^ m ↔ n ≤ m := by constructor · intro h rw [← not_lt] intro hmn apply ha have : a ^ m * a ∣ a ^ m * 1 := by rw [← pow_succ, mul_one] exact (pow_dvd_pow _ (Nat.succ_le_of_lt hmn)).trans h rwa [mul_dvd_mul_iff_left, ← isUnit_iff_dvd_one] at this apply pow_ne_zero m ha₀ · apply pow_dvd_pow end CancelCommMonoidWithZero section GroupWithZero variable [GroupWithZero α] /-- `∣` is not a useful definition if an inverse is available. -/ @[simp] lemma GroupWithZero.dvd_iff {m n : α} : m ∣ n ↔ (m = 0 → n = 0) := by refine ⟨fun ⟨a, ha⟩ hm => ?_, fun h => ?_⟩ · simp [hm, ha] · refine ⟨m⁻¹ * n, ?_⟩ obtain rfl | hn := eq_or_ne n 0 · simp · rw [mul_inv_cancel_left₀ (mt h hn)] end GroupWithZero
.lake/packages/mathlib/Mathlib/Algebra/GroupWithZero/Equiv.lean
import Mathlib.Algebra.Group.Equiv.Defs import Mathlib.Algebra.GroupWithZero.Hom /-! # Isomorphisms of monoids with zero -/ assert_not_exists Ring namespace MulEquivClass variable {F α β : Type*} [EquivLike F α β] -- See note [lower instance priority] instance (priority := 100) toZeroHomClass [MulZeroClass α] [MulZeroClass β] [MulEquivClass F α β] : ZeroHomClass F α β where map_zero f := calc f 0 = f 0 * f (EquivLike.inv f 0) := by rw [← map_mul, zero_mul] _ = 0 := by simp -- See note [lower instance priority] instance (priority := 100) toMonoidWithZeroHomClass [MulZeroOneClass α] [MulZeroOneClass β] [MulEquivClass F α β] : MonoidWithZeroHomClass F α β := { MulEquivClass.instMonoidHomClass F, MulEquivClass.toZeroHomClass with } end MulEquivClass namespace MulEquiv variable {G H : Type*} [MulZeroOneClass G] [MulZeroOneClass H] /-- An isomorphism of monoids with zero can be treated as a homomorphism preserving zero. This is a helper projection that utilizes the `MonoidWithZeroHomClass` instance. -/ def toMonoidWithZeroHom (f : G ≃* H) : G →*₀ H := f @[simp] lemma toMonoidWithZeroHom_apply (f : G ≃* H) (x : G) : f.toMonoidWithZeroHom x = f x := rfl lemma toMonoidWithZeroHom_injective (f : G ≃* H) : Function.Injective f.toMonoidWithZeroHom := f.injective lemma toMonoidWithZeroHom_surjective (f : G ≃* H) : Function.Surjective f.toMonoidWithZeroHom := f.surjective lemma toMonoidWithZeroHom_bijective (f : G ≃* H) : Function.Bijective f.toMonoidWithZeroHom := f.bijective @[simp] lemma toMonoidWithZeroHom_inj {f g : G ≃* H} : f.toMonoidWithZeroHom = g.toMonoidWithZeroHom ↔ f = g := by simp [MonoidWithZeroHom.ext_iff, MulEquiv.ext_iff] end MulEquiv