source
stringlengths
17
118
lean4
stringlengths
0
335k
.lake/packages/mathlib/Mathlib/Algebra/GroupWithZero/Range.lean
import Mathlib.Algebra.Group.Subgroup.Pointwise import Mathlib.Algebra.GroupWithZero.Submonoid.Instances import Mathlib.Algebra.GroupWithZero.WithZero /-! # The range of a MonoidWithZeroHom Given a `MonoidWithZeroHom` `f : A → B` whose codomain `B` is a `MonoidWithZero`, we define the type `MonoidWithZeroHom.valueMonoid` as the submonoid of `Bˣ` generated by the invertible elements in the range of `f`. For example, if `A = ℕ`, `f` is the natural cast to `B` where `B` is * `ℝ≥0`, then `MonoidWithZero.valueMonoid` are the positive natural numbers in `ℝ≥0`; * `WithZero ℤ`, then `MonoidWithZero.valueMonoid = {1}`. `MonoidWithZeroHom.ValueMonoid₀` is the `MonoidWithZero` obtained by adjoining `0` to the previous type. Likewise, `MonoidWithZeroHom.valueGroup` is the *subgroup* of `Bˣ` generated by the invertible elements in `range f` and `MonoidWithZeroHom.ValueGroup₀` adds a `0` to the previous group. When `B` is commutative, then both `MonoidWithZeroHom.valueGroup f` and `MonoidWithZeroHom.ValueGroup₀ f` are also commutative and the former can be described more explicitly (see `MonoidWithZeroHom.mem_valueGroup_iff_of_comm`). ## Main declarations * `valueMonoid f` is the smallest submonoid of `Bˣ` containing the range of `f`; * `ValueMonoid₀ f` is the smallest monoid with `0` containing the range of `f`; * `valueGroup f` is the smallest subgroup of `Bˣ` containing the range of `f`; * `ValueMonoid₀ f` is the smallest group with `0` containing the range of `f`; * When `B` is a group with zero, rather than merely a monoid with zero, the above definitions all coincide: see `valueMonoid_eq_valueGroup` for an equality as submonoids and `valueMonoid_eq_valueGroup'` for an equality as subsets. * When `B` is a *commutative* group with zero, `MonoidWithZeroHom.valueGroup` can be explicitly described as the elements that are ratios of terms in `range f`, see `MonoidWithZeroHom.mem_valueGroup_iff_of_comm`. ## Implementation details `MonoidWithZeroHom.valueMonoid` is defined explicitly in terms of its carrier, by proving the required properties; that it coincides with the submonoid generated by the closure is proven in `MonoidWithZeroHom.valueMonoid_eq_closure`, but using the latter as definition yields to unwanted unfolding. -/ namespace MonoidWithZeroHom open Set Subgroup Submonoid section mrange variable {G H : Type*} [MulZeroOneClass G] [MulZeroOneClass H] [Nontrivial H] (f : G →*₀ H) lemma mrange_nontrivial : Nontrivial (MonoidHom.mrange f) := ⟨1, 0, by simp [Subtype.ext_iff]⟩ lemma range_nontrivial : (Set.range f).Nontrivial := Set.nontrivial_coe_sort.mp f.mrange_nontrivial end mrange variable {A B F : Type*} [FunLike F A B] (f : F) section MonoidWithZero variable [MonoidWithZero A] [MonoidWithZero B] [MonoidWithZeroHomClass F A B] /-- For a morphism of monoids with zero `f`, this is a smallest submonoid of the invertible elements in the codomain containing the range of `f`. -/ def valueMonoid : Submonoid Bˣ where carrier := (↑)⁻¹' (range f) mul_mem' hb hb' := by obtain ⟨y, hy⟩ := hb obtain ⟨y', hy'⟩ := hb' use y * y' rw [map_mul, hy, hy', Units.val_mul] one_mem' := ⟨1, by simp⟩ lemma one_mem_valueMonoid : 1 ∈ valueMonoid f := ⟨1, map_one ..⟩ lemma coe_one : (⟨(1 : Bˣ), one_mem_valueMonoid f⟩ : valueMonoid f) = 1 := rfl lemma mem_valueMonoid_iff {b : Bˣ} : b ∈ valueMonoid f ↔ b ∈ (↑)⁻¹' (range f) := Iff.rfl lemma valueMonoid_eq_closure : valueMonoid f = Submonoid.closure ((↑)⁻¹' (range f)) := (valueMonoid f).closure_eq.symm /-- For a morphism of monoids with zero `f`, this is the smallest subgroup of the invertible elements in the codomain containing the range of `f`. -/ def valueGroup : Subgroup Bˣ := closure (valueMonoid f) lemma valueGroup_def : valueGroup f = Subgroup.closure (valueMonoid f) := rfl /-- For a morphism of monoids with zero `f`, this is the smallest submonoid with zero of the codomain containing the range of `f`. -/ abbrev ValueMonoid₀ := WithZero (valueMonoid f) @[deprecated (since := "2025-09-03")] alias valueMonoid₀ := ValueMonoid₀ /-- For a morphism of monoids with zero `f`, this is a smallest subgroup with zero of the codomain containing the range of `f`. -/ abbrev ValueGroup₀ := WithZero (valueGroup f) @[deprecated (since := "2025-09-03")] alias valueGroup₀ := ValueGroup₀ lemma mem_valueMonoid {b : Bˣ} (hb : b.val ∈ range f) : b ∈ valueMonoid f := by tauto lemma mem_valueGroup {b : Bˣ} (hb : b.1 ∈ range f) : b ∈ valueGroup f := by suffices b ∈ valueMonoid f from Subgroup.mem_closure.mpr fun _ a ↦ a this exact mem_valueMonoid _ hb lemma inv_mem_valueGroup {b : Bˣ} (hb : b.1 ∈ range f) : b⁻¹ ∈ valueGroup f := Subgroup.inv_mem _ (mem_valueGroup f hb) end MonoidWithZero noncomputable section GroupWithZero variable [GroupWithZero A] [GroupWithZero B] [MonoidWithZeroHomClass F A B] {f} /- When the *domain* is itself a group with zero, the `valueMonoid` and the `valueGroup` coincide.-/ lemma valueMonoid_eq_valueGroup : (valueMonoid f) = (valueGroup f).toSubmonoid := by rw [valueGroup_def, Subgroup.closure_toSubmonoid, Eq.comm] apply Submonoid.closure_eq_of_le · simp only [union_subset_iff, subset_refl, true_and] intro _ ⟨y, hy⟩ use y⁻¹ simp [hy] · simp [Submonoid.closure_union] variable (f) in lemma valueMonoid_eq_valueGroup' : (valueMonoid f : Set Bˣ) = valueGroup f := by rw [valueMonoid_eq_valueGroup, coe_toSubmonoid] lemma valueGroup_eq_range : Units.val '' (valueGroup f) = (range f \ {0}) := by ext x simp only [mem_diff, mem_range, mem_singleton_iff, ← valueMonoid_eq_valueGroup' f, mem_image, SetLike.mem_coe, mem_valueMonoid_iff, mem_preimage, mem_range] constructor · rintro ⟨y, hy, rfl⟩ simp only [Units.ne_zero, not_false_eq_true, and_true, hy] · rintro ⟨⟨y, hy⟩, hx₀⟩ refine ⟨Units.mk0 x hx₀, ?_, rfl⟩ simpa [Units.val_mk0, mem_range] using ⟨y, hy⟩ end GroupWithZero section CommGroupWithZero -- variable [MonoidWithZero A] [CommGroupWithZero B] [MonoidWithZeroHomClass F A B] theorem mem_valueGroup_iff_of_comm {y : Bˣ} : y ∈ valueGroup f ↔ ∃ a, f a ≠ 0 ∧ ∃ x, f a * y = f x := by refine ⟨fun hy ↦ ?_, fun ⟨a, ha, x, hy⟩ ↦ ?_⟩ · simp only [valueGroup, valueMonoid, Submonoid.coe_set_mk, Subsemigroup.coe_set_mk] at hy induction hy using Subgroup.closure_induction with | mem _ h => obtain ⟨a, ha⟩ := h exact ⟨a, ha.symm ▸ Units.ne_zero _, ⟨a * a, by simp [← ha]⟩⟩ | one => exact ⟨1, by simp, 1, by simp⟩ | mul c d hc hd hcy hdy => obtain ⟨u, hu, a, ha⟩ := hcy obtain ⟨v, hv, b, hb⟩ := hdy refine ⟨u * v, by simp [hu, hv], a * b, ?_⟩ simpa [map_mul, Units.val_mul, ← hb, ← ha] using mul_mul_mul_comm .. | inv c hc hcy => obtain ⟨u, hu, a, ha⟩ := hcy exact ⟨a, by simp [← ha, hu], u, by simp [← ha]⟩ · have hv : f x ≠ 0 := by simp only [← hy, ne_eq, mul_eq_zero, ha, Units.ne_zero, or_self, not_false_eq_true] let v := (Ne.isUnit hv).unit have hv₀ : f x = ↑v := IsUnit.unit_spec (Ne.isUnit hv) let u := (Ne.isUnit ha).unit have ha₀ : f a = ↑u := IsUnit.unit_spec (Ne.isUnit ha) rw_mod_cast [hv₀, ha₀, Eq.comm, ← inv_mul_eq_iff_eq_mul] at hy rw [← hy] apply Subgroup.mul_mem · apply inv_mem_valueGroup use a · apply mem_valueGroup use x instance : CommGroupWithZero (ValueGroup₀ f) where end CommGroupWithZero end MonoidWithZeroHom namespace MonoidHomWithZero @[deprecated (since := "2025-07-02")] alias valueMonoid := MonoidWithZeroHom.valueMonoid @[deprecated (since := "2025-07-02")] alias valueGroup := MonoidWithZeroHom.valueGroup @[deprecated (since := "2025-07-02")] alias valueMonoid₀ := MonoidWithZeroHom.ValueMonoid₀ @[deprecated (since := "2025-07-02")] alias valueGroup₀ := MonoidWithZeroHom.ValueGroup₀ end MonoidHomWithZero
.lake/packages/mathlib/Mathlib/Algebra/GroupWithZero/NeZero.lean
import Mathlib.Algebra.GroupWithZero.Defs import Mathlib.Algebra.NeZero /-! # `NeZero 1` in a nontrivial `MulZeroOneClass`. This file exists to minimize the dependencies of `Mathlib/Algebra/GroupWithZero/Defs.lean`, which is a part of the algebraic hierarchy used by basic tactics. -/ assert_not_exists DenselyOrdered Ring universe u variable {M₀ M₀' : Type*} [MulZeroOneClass M₀] [Nontrivial M₀] /-- In a nontrivial monoid with zero, zero and one are different. -/ instance NeZero.one : NeZero (1 : M₀) := ⟨by intro h rcases exists_pair_ne M₀ with ⟨x, y, hx⟩ apply hx calc x = 1 * x := by rw [one_mul] _ = 0 := by rw [h, zero_mul] _ = 1 * y := by rw [h, zero_mul] _ = y := by rw [one_mul]⟩ /-- Pullback a `Nontrivial` instance along a function sending `0` to `0` and `1` to `1`. -/ theorem domain_nontrivial [Zero M₀'] [One M₀'] (f : M₀' → M₀) (zero : f 0 = 0) (one : f 1 = 1) : Nontrivial M₀' := ⟨⟨0, 1, mt (congr_arg f) <| by rw [zero, one] exact zero_ne_one⟩⟩ section GroupWithZero variable {G₀ : Type*} [GroupWithZero G₀] {a : G₀} theorem inv_ne_zero (h : a ≠ 0) : a⁻¹ ≠ 0 := fun a_eq_0 => by simpa [a_eq_0] using mul_inv_cancel₀ h @[simp high] -- should take priority over `IsUnit.inv_mul_cancel` theorem inv_mul_cancel₀ (h : a ≠ 0) : a⁻¹ * a = 1 := calc a⁻¹ * a = a⁻¹ * a * a⁻¹ * a⁻¹⁻¹ := by simp [inv_ne_zero h] _ = a⁻¹ * a⁻¹⁻¹ := by simp [h] _ = 1 := by simp [inv_ne_zero h] end GroupWithZero
.lake/packages/mathlib/Mathlib/Algebra/GroupWithZero/Hom.lean
import Mathlib.Algebra.Group.Hom.Basic import Mathlib.Algebra.GroupWithZero.Basic /-! # Monoid with zero and group with zero homomorphisms This file defines homomorphisms of monoids with zero. We also define coercion to a function, and usual operations: composition, identity homomorphism, pointwise multiplication and pointwise inversion. ## Notation * `→*₀`: `MonoidWithZeroHom`, the type of bundled `MonoidWithZero` homs. Also use for `GroupWithZero` homs. ## Implementation notes Implicit `{}` brackets are often used instead of type class `[]` brackets. This is done when the instances can be inferred because they are implicit arguments to the type `MonoidHom`. When they can be inferred from the type it is faster to use this method than to use type class inference. ## Tags monoid homomorphism -/ assert_not_exists DenselyOrdered Ring open Function namespace NeZero variable {F α β : Type*} [Zero α] [Zero β] [FunLike F α β] [ZeroHomClass F α β] {a : α} lemma of_map (f : F) [neZero : NeZero (f a)] : NeZero a := ⟨fun h ↦ ne (f a) <| by rw [h]; exact ZeroHomClass.map_zero f⟩ lemma of_injective {f : F} (hf : Injective f) [NeZero a] : NeZero (f a) := ⟨by rw [← ZeroHomClass.map_zero f]; exact hf.ne NeZero.out⟩ end NeZero variable {F α β γ δ M₀ : Type*} [MulZeroOneClass α] [MulZeroOneClass β] [MulZeroOneClass γ] [MulZeroOneClass δ] /-- `MonoidWithZeroHomClass F α β` states that `F` is a type of `MonoidWithZero`-preserving homomorphisms. You should also extend this typeclass when you extend `MonoidWithZeroHom`. -/ class MonoidWithZeroHomClass (F : Type*) (α β : outParam Type*) [MulZeroOneClass α] [MulZeroOneClass β] [FunLike F α β] : Prop extends MonoidHomClass F α β, ZeroHomClass F α β /-- `α →*₀ β` is the type of functions `α → β` that preserve the `MonoidWithZero` structure. `MonoidWithZeroHom` is also used for group homomorphisms. When possible, instead of parametrizing results over `(f : α →*₀ β)`, you should parametrize over `(F : Type*) [MonoidWithZeroHomClass F α β] (f : F)`. When you extend this structure, make sure to extend `MonoidWithZeroHomClass`. -/ structure MonoidWithZeroHom (α β : Type*) [MulZeroOneClass α] [MulZeroOneClass β] extends ZeroHom α β, MonoidHom α β /-- `α →*₀ β` denotes the type of zero-preserving monoid homomorphisms from `α` to `β`. -/ infixr:25 " →*₀ " => MonoidWithZeroHom /-- Turn an element of a type `F` satisfying `MonoidWithZeroHomClass F α β` into an actual `MonoidWithZeroHom`. This is declared as the default coercion from `F` to `α →*₀ β`. -/ @[coe] def MonoidWithZeroHomClass.toMonoidWithZeroHom [FunLike F α β] [MonoidWithZeroHomClass F α β] (f : F) : α →*₀ β := { (f : α →* β), (f : ZeroHom α β) with } /-- Any type satisfying `MonoidWithZeroHomClass` can be cast into `MonoidWithZeroHom` via `MonoidWithZeroHomClass.toMonoidWithZeroHom`. -/ instance [FunLike F α β] [MonoidWithZeroHomClass F α β] : CoeTC F (α →*₀ β) := ⟨MonoidWithZeroHomClass.toMonoidWithZeroHom⟩ namespace MonoidWithZeroHom attribute [nolint docBlame] toMonoidHom attribute [nolint docBlame] toZeroHom instance funLike : FunLike (α →*₀ β) α β where coe f := f.toFun coe_injective' f g h := by obtain ⟨⟨_, _⟩, _⟩ := f; obtain ⟨⟨_, _⟩, _⟩ := g; congr instance monoidWithZeroHomClass : MonoidWithZeroHomClass (α →*₀ β) α β where map_mul := MonoidWithZeroHom.map_mul' map_one := MonoidWithZeroHom.map_one' map_zero f := f.map_zero' instance [Subsingleton α] : Subsingleton (α →*₀ β) := .of_oneHomClass variable [FunLike F α β] @[simp] lemma coe_coe [MonoidWithZeroHomClass F α β] (f : F) : ((f : α →*₀ β) : α → β) = f := rfl -- Completely uninteresting lemmas about coercion to function, that all homs need section Coes /-! Bundled morphisms can be down-cast to weaker bundlings -/ attribute [coe] toMonoidHom /-- `MonoidWithZeroHom` down-cast to a `MonoidHom`, forgetting the 0-preserving property. -/ instance coeToMonoidHom : Coe (α →*₀ β) (α →* β) := ⟨toMonoidHom⟩ attribute [coe] toZeroHom /-- `MonoidWithZeroHom` down-cast to a `ZeroHom`, forgetting the monoidal property. -/ instance coeToZeroHom : Coe (α →*₀ β) (ZeroHom α β) := ⟨toZeroHom⟩ -- This must come after the coe_toFun definitions initialize_simps_projections MonoidWithZeroHom (toFun → apply) @[simp] lemma coe_mk (f h1 hmul) : (mk f h1 hmul : α → β) = (f : α → β) := rfl @[simp] lemma toZeroHom_coe (f : α →*₀ β) : (f.toZeroHom : α → β) = f := rfl lemma toMonoidHom_coe (f : α →*₀ β) : f.toMonoidHom.toFun = f := rfl @[ext] lemma ext ⦃f g : α →*₀ β⦄ (h : ∀ x, f x = g x) : f = g := DFunLike.ext _ _ h @[simp] lemma mk_coe (f : α →*₀ β) (h1 hmul) : mk f h1 hmul = f := ext fun _ ↦ rfl end Coes /-- Copy of a `MonoidHom` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (f : α →*₀ β) (f' : α → β) (h : f' = f) : α →* β := { f.toZeroHom.copy f' h, f.toMonoidHom.copy f' h with } @[simp] lemma coe_copy (f : α →*₀ β) (f' : α → β) (h) : (f.copy f' h) = f' := rfl lemma copy_eq (f : α →*₀ β) (f' : α → β) (h) : f.copy f' h = f := DFunLike.ext' h protected lemma map_one (f : α →*₀ β) : f 1 = 1 := f.map_one' protected lemma map_zero (f : α →*₀ β) : f 0 = 0 := f.map_zero' protected lemma map_mul (f : α →*₀ β) (a b : α) : f (a * b) = f a * f b := f.map_mul' a b @[simp] theorem map_ite_zero_one {F : Type*} [FunLike F α β] [MonoidWithZeroHomClass F α β] (f : F) (p : Prop) [Decidable p] : f (ite p 0 1) = ite p 0 1 := by split_ifs with h <;> simp @[simp] theorem map_ite_one_zero {F : Type*} [FunLike F α β] [MonoidWithZeroHomClass F α β] (f : F) (p : Prop) [Decidable p] : f (ite p 1 0) = ite p 1 0 := by split_ifs with h <;> simp /-- The identity map from a `MonoidWithZero` to itself. -/ @[simps] def id (α : Type*) [MulZeroOneClass α] : α →*₀ α where toFun x := x map_zero' := rfl map_one' := rfl map_mul' _ _ := rfl /-- Composition of `MonoidWithZeroHom`s as a `MonoidWithZeroHom`. -/ def comp (hnp : β →*₀ γ) (hmn : α →*₀ β) : α →*₀ γ where toFun := hnp ∘ hmn map_zero' := by rw [comp_apply, map_zero, map_zero] map_one' := by simp map_mul' := by simp @[simp] lemma coe_comp (g : β →*₀ γ) (f : α →*₀ β) : ↑(g.comp f) = g ∘ f := rfl lemma comp_apply (g : β →*₀ γ) (f : α →*₀ β) (x : α) : g.comp f x = g (f x) := rfl lemma comp_assoc (f : α →*₀ β) (g : β →*₀ γ) (h : γ →*₀ δ) : (h.comp g).comp f = h.comp (g.comp f) := rfl lemma cancel_right {g₁ g₂ : β →*₀ γ} {f : α →*₀ β} (hf : Surjective f) : g₁.comp f = g₂.comp f ↔ g₁ = g₂ := ⟨fun h ↦ ext <| hf.forall.2 (DFunLike.ext_iff.1 h), fun h ↦ h ▸ rfl⟩ lemma cancel_left {g : β →*₀ γ} {f₁ f₂ : α →*₀ β} (hg : Injective g) : g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ := ⟨fun h ↦ ext fun x ↦ hg <| by rw [← comp_apply, h, comp_apply], fun h ↦ h ▸ rfl⟩ lemma toMonoidHom_injective : Injective (toMonoidHom : (α →*₀ β) → α →* β) := Injective.of_comp (f := DFunLike.coe) DFunLike.coe_injective lemma toZeroHom_injective : Injective (toZeroHom : (α →*₀ β) → ZeroHom α β) := Injective.of_comp (f := DFunLike.coe) DFunLike.coe_injective @[simp] lemma comp_id (f : α →*₀ β) : f.comp (id α) = f := ext fun _ ↦ rfl @[simp] lemma id_comp (f : α →*₀ β) : (id β).comp f = f := ext fun _ ↦ rfl -- Unlike the other homs, `MonoidWithZeroHom` does not have a `1` or `0` instance : Inhabited (α →*₀ α) := ⟨id α⟩ /-- Given two monoid with zero morphisms `f`, `g` to a commutative monoid with zero, `f * g` is the monoid with zero morphism sending `x` to `f x * g x`. -/ instance {β} [CommMonoidWithZero β] : Mul (α →*₀ β) where mul f g := { (f * g : α →* β) with map_zero' := by dsimp; rw [map_zero, zero_mul] } /-- The trivial homomorphism between monoids with zero, sending 0 to 0 and all other elements to 1. -/ protected instance one (M₀ N₀ : Type*) [MulZeroOneClass M₀] [MulZeroOneClass N₀] [DecidablePred fun x : M₀ ↦ x = 0] [Nontrivial M₀] [NoZeroDivisors M₀] : One (M₀ →*₀ N₀) where one.toFun x := if x = 0 then 0 else 1 one.map_zero' := by simp one.map_one' := by simp one.map_mul' x y := by split_ifs <;> simp_all lemma one_apply_def {M₀ N₀ : Type*} [MulZeroOneClass M₀] [MulZeroOneClass N₀] [DecidablePred fun x : M₀ ↦ x = 0] [Nontrivial M₀] [NoZeroDivisors M₀] (x : M₀) : (1 : M₀ →*₀ N₀) x = if x = 0 then 0 else 1 := rfl @[simp] lemma one_apply_zero {M₀ N₀ : Type*} [MulZeroOneClass M₀] [MulZeroOneClass N₀] [DecidablePred fun x : M₀ ↦ x = 0] [Nontrivial M₀] [NoZeroDivisors M₀] : (1 : M₀ →*₀ N₀) 0 = 0 := if_pos rfl lemma one_apply_of_ne_zero {M₀ N₀ : Type*} [MulZeroOneClass M₀] [MulZeroOneClass N₀] [DecidablePred fun x : M₀ ↦ x = 0] [Nontrivial M₀] [NoZeroDivisors M₀] {x : M₀} (hx : x ≠ 0) : (1 : M₀ →*₀ N₀) x = 1 := if_neg hx @[simp] lemma one_apply_eq_zero_iff {M₀ N₀ : Type*} [MulZeroOneClass M₀] [MulZeroOneClass N₀] [DecidablePred fun x : M₀ ↦ x = 0] [Nontrivial M₀] [NoZeroDivisors M₀] [Nontrivial N₀] {x : M₀} : (1 : M₀ →*₀ N₀) x = 0 ↔ x = 0 := by rcases eq_or_ne x 0 with rfl | hx <;> simp_all [one_apply_of_ne_zero] @[simp] lemma one_apply_eq_one_iff {M₀ N₀ : Type*} [MulZeroOneClass M₀] [MulZeroOneClass N₀] [DecidablePred fun x : M₀ ↦ x = 0] [Nontrivial M₀] [NoZeroDivisors M₀] [Nontrivial N₀] {x : M₀} : (1 : M₀ →*₀ N₀) x = 1 ↔ x ≠ 0 := by rcases eq_or_ne x 0 with rfl | hx <;> simp_all [one_apply_of_ne_zero] end MonoidWithZeroHom section CommMonoidWithZero variable [CommMonoidWithZero M₀] {n : ℕ} (hn : n ≠ 0) /-- We define `x ↦ x^n` (for positive `n : ℕ`) as a `MonoidWithZeroHom` -/ def powMonoidWithZeroHom : M₀ →*₀ M₀ := { powMonoidHom n with map_zero' := zero_pow hn } @[simp] lemma coe_powMonoidWithZeroHom : (powMonoidWithZeroHom hn : M₀ → M₀) = fun x ↦ x ^ n := rfl @[simp] lemma powMonoidWithZeroHom_apply (a : M₀) : powMonoidWithZeroHom hn a = a ^ n := rfl end CommMonoidWithZero
.lake/packages/mathlib/Mathlib/Algebra/GroupWithZero/Associated.lean
import Mathlib.Algebra.Prime.Lemmas import Mathlib.Order.BoundedOrder.Basic /-! # Associated elements. In this file we define an equivalence relation `Associated` saying that two elements of a monoid differ by a multiplication by a unit. Then we show that the quotient type `Associates` is a monoid and prove basic properties of this quotient. -/ assert_not_exists IsOrderedMonoid Multiset Ring variable {M : Type*} /-- Two elements of a `Monoid` are `Associated` if one of them is another one multiplied by a unit on the right. -/ def Associated [Monoid M] (x y : M) : Prop := ∃ u : Mˣ, x * u = y /-- Notation for two elements of a monoid are associated, i.e. if one of them is another one multiplied by a unit on the right. -/ local infixl:50 " ~ᵤ " => Associated namespace Associated @[refl] protected theorem refl [Monoid M] (x : M) : x ~ᵤ x := ⟨1, by simp⟩ protected theorem rfl [Monoid M] {x : M} : x ~ᵤ x := .refl x instance [Monoid M] : IsRefl M Associated := ⟨Associated.refl⟩ @[symm] protected theorem symm [Monoid M] : ∀ {x y : M}, x ~ᵤ y → y ~ᵤ x | x, _, ⟨u, rfl⟩ => ⟨u⁻¹, by rw [mul_assoc, Units.mul_inv, mul_one]⟩ instance [Monoid M] : IsSymm M Associated := ⟨fun _ _ => Associated.symm⟩ protected theorem comm [Monoid M] {x y : M} : x ~ᵤ y ↔ y ~ᵤ x := ⟨Associated.symm, Associated.symm⟩ @[trans] protected theorem trans [Monoid M] : ∀ {x y z : M}, x ~ᵤ y → y ~ᵤ z → x ~ᵤ z | x, _, _, ⟨u, rfl⟩, ⟨v, rfl⟩ => ⟨u * v, by rw [Units.val_mul, mul_assoc]⟩ instance [Monoid M] : IsTrans M Associated := ⟨fun _ _ _ => Associated.trans⟩ /-- The setoid of the relation `x ~ᵤ y` iff there is a unit `u` such that `x * u = y` -/ protected def setoid (M : Type*) [Monoid M] : Setoid M where r := Associated iseqv := ⟨Associated.refl, Associated.symm, Associated.trans⟩ theorem map {M N : Type*} [Monoid M] [Monoid N] {F : Type*} [FunLike F M N] [MonoidHomClass F M N] (f : F) {x y : M} (ha : Associated x y) : Associated (f x) (f y) := by obtain ⟨u, ha⟩ := ha exact ⟨Units.map f u, by rw [← ha, map_mul, Units.coe_map, MonoidHom.coe_coe]⟩ end Associated attribute [local instance] Associated.setoid theorem Associated.of_eq [Monoid M] {a b : M} (h : a = b) : a ~ᵤ b := ⟨1, by rwa [Units.val_one, mul_one]⟩ theorem unit_associated_one [Monoid M] {u : Mˣ} : (u : M) ~ᵤ 1 := ⟨u⁻¹, Units.mul_inv u⟩ @[simp] theorem associated_one_iff_isUnit [Monoid M] {a : M} : (a : M) ~ᵤ 1 ↔ IsUnit a := Iff.intro (fun h => let ⟨c, h⟩ := h.symm h ▸ ⟨c, (one_mul _).symm⟩) fun ⟨c, h⟩ => Associated.symm ⟨c, by simp [h]⟩ @[simp] theorem associated_zero_iff_eq_zero [MonoidWithZero M] (a : M) : a ~ᵤ 0 ↔ a = 0 := Iff.intro (fun h => by let ⟨u, h⟩ := h.symm simpa using h.symm) fun h => h ▸ Associated.refl a theorem associated_one_of_mul_eq_one [CommMonoid M] {a : M} (b : M) (hab : a * b = 1) : a ~ᵤ 1 := show (Units.mkOfMulEqOne a b hab : M) ~ᵤ 1 from unit_associated_one theorem associated_one_of_associated_mul_one [CommMonoid M] {a b : M} : a * b ~ᵤ 1 → a ~ᵤ 1 | ⟨u, h⟩ => associated_one_of_mul_eq_one (b * u) <| by simpa [mul_assoc] using h theorem associated_mul_unit_left {N : Type*} [Monoid N] (a u : N) (hu : IsUnit u) : Associated (a * u) a := let ⟨u', hu⟩ := hu ⟨u'⁻¹, hu ▸ Units.mul_inv_cancel_right _ _⟩ theorem associated_unit_mul_left {N : Type*} [CommMonoid N] (a u : N) (hu : IsUnit u) : Associated (u * a) a := by rw [mul_comm] exact associated_mul_unit_left _ _ hu theorem associated_mul_unit_right {N : Type*} [Monoid N] (a u : N) (hu : IsUnit u) : Associated a (a * u) := (associated_mul_unit_left a u hu).symm theorem associated_unit_mul_right {N : Type*} [CommMonoid N] (a u : N) (hu : IsUnit u) : Associated a (u * a) := (associated_unit_mul_left a u hu).symm theorem associated_mul_isUnit_left_iff {N : Type*} [Monoid N] {a u b : N} (hu : IsUnit u) : Associated (a * u) b ↔ Associated a b := ⟨(associated_mul_unit_right _ _ hu).trans, (associated_mul_unit_left _ _ hu).trans⟩ theorem associated_isUnit_mul_left_iff {N : Type*} [CommMonoid N] {u a b : N} (hu : IsUnit u) : Associated (u * a) b ↔ Associated a b := by rw [mul_comm] exact associated_mul_isUnit_left_iff hu theorem associated_mul_isUnit_right_iff {N : Type*} [Monoid N] {a b u : N} (hu : IsUnit u) : Associated a (b * u) ↔ Associated a b := Associated.comm.trans <| (associated_mul_isUnit_left_iff hu).trans Associated.comm theorem associated_isUnit_mul_right_iff {N : Type*} [CommMonoid N] {a u b : N} (hu : IsUnit u) : Associated a (u * b) ↔ Associated a b := Associated.comm.trans <| (associated_isUnit_mul_left_iff hu).trans Associated.comm @[simp] theorem associated_mul_unit_left_iff {N : Type*} [Monoid N] {a b : N} {u : Units N} : Associated (a * u) b ↔ Associated a b := associated_mul_isUnit_left_iff u.isUnit @[simp] theorem associated_unit_mul_left_iff {N : Type*} [CommMonoid N] {a b : N} {u : Units N} : Associated (↑u * a) b ↔ Associated a b := associated_isUnit_mul_left_iff u.isUnit @[simp] theorem associated_mul_unit_right_iff {N : Type*} [Monoid N] {a b : N} {u : Units N} : Associated a (b * u) ↔ Associated a b := associated_mul_isUnit_right_iff u.isUnit @[simp] theorem associated_unit_mul_right_iff {N : Type*} [CommMonoid N] {a b : N} {u : Units N} : Associated a (↑u * b) ↔ Associated a b := associated_isUnit_mul_right_iff u.isUnit theorem Associated.mul_left [Monoid M] (a : M) {b c : M} (h : b ~ᵤ c) : a * b ~ᵤ a * c := by obtain ⟨d, rfl⟩ := h; exact ⟨d, mul_assoc _ _ _⟩ theorem Associated.mul_right [CommMonoid M] {a b : M} (h : a ~ᵤ b) (c : M) : a * c ~ᵤ b * c := by obtain ⟨d, rfl⟩ := h; exact ⟨d, mul_right_comm _ _ _⟩ theorem Associated.mul_mul [CommMonoid M] {a₁ a₂ b₁ b₂ : M} (h₁ : a₁ ~ᵤ b₁) (h₂ : a₂ ~ᵤ b₂) : a₁ * a₂ ~ᵤ b₁ * b₂ := (h₁.mul_right _).trans (h₂.mul_left _) theorem Associated.pow_pow [CommMonoid M] {a b : M} {n : ℕ} (h : a ~ᵤ b) : a ^ n ~ᵤ b ^ n := by induction n with | zero => simp [Associated.refl] | succ n ih => convert h.mul_mul ih <;> rw [pow_succ'] protected theorem Associated.dvd [Monoid M] {a b : M} : a ~ᵤ b → a ∣ b := fun ⟨u, hu⟩ => ⟨u, hu.symm⟩ protected theorem Associated.dvd' [Monoid M] {a b : M} (h : a ~ᵤ b) : b ∣ a := h.symm.dvd protected theorem Associated.dvd_dvd [Monoid M] {a b : M} (h : a ~ᵤ b) : a ∣ b ∧ b ∣ a := ⟨h.dvd, h.symm.dvd⟩ theorem associated_of_dvd_dvd [CancelMonoidWithZero M] {a b : M} (hab : a ∣ b) (hba : b ∣ a) : a ~ᵤ b := by rcases hab with ⟨c, rfl⟩ rcases hba with ⟨d, a_eq⟩ by_cases ha0 : a = 0 · simp_all have hac0 : a * c ≠ 0 := by intro con rw [con, zero_mul] at a_eq apply ha0 a_eq have : a * (c * d) = a * 1 := by rw [← mul_assoc, ← a_eq, mul_one] have hcd : c * d = 1 := mul_left_cancel₀ ha0 this have : a * c * (d * c) = a * c * 1 := by rw [← mul_assoc, ← a_eq, mul_one] have hdc : d * c = 1 := mul_left_cancel₀ hac0 this exact ⟨⟨c, d, hcd, hdc⟩, rfl⟩ theorem dvd_dvd_iff_associated [CancelMonoidWithZero M] {a b : M} : a ∣ b ∧ b ∣ a ↔ a ~ᵤ b := ⟨fun ⟨h1, h2⟩ => associated_of_dvd_dvd h1 h2, Associated.dvd_dvd⟩ instance [CancelMonoidWithZero M] [DecidableRel ((· ∣ ·) : M → M → Prop)] : DecidableRel ((· ~ᵤ ·) : M → M → Prop) := fun _ _ => decidable_of_iff _ dvd_dvd_iff_associated theorem Associated.dvd_iff_dvd_left [Monoid M] {a b c : M} (h : a ~ᵤ b) : a ∣ c ↔ b ∣ c := let ⟨_, hu⟩ := h hu ▸ Units.mul_right_dvd.symm theorem Associated.dvd_iff_dvd_right [Monoid M] {a b c : M} (h : b ~ᵤ c) : a ∣ b ↔ a ∣ c := let ⟨_, hu⟩ := h hu ▸ Units.dvd_mul_right.symm theorem Associated.eq_zero_iff [MonoidWithZero M] {a b : M} (h : a ~ᵤ b) : a = 0 ↔ b = 0 := by obtain ⟨u, rfl⟩ := h rw [← Units.eq_mul_inv_iff_mul_eq, zero_mul] theorem Associated.ne_zero_iff [MonoidWithZero M] {a b : M} (h : a ~ᵤ b) : a ≠ 0 ↔ b ≠ 0 := not_congr h.eq_zero_iff protected theorem Associated.prime [CommMonoidWithZero M] {p q : M} (h : p ~ᵤ q) (hp : Prime p) : Prime q := ⟨h.ne_zero_iff.1 hp.ne_zero, let ⟨u, hu⟩ := h ⟨fun ⟨v, hv⟩ => hp.not_unit ⟨v * u⁻¹, by simp [hv, hu.symm]⟩, hu ▸ by simp only [Units.isUnit, IsUnit.mul_right_dvd] intro a b exact hp.dvd_or_dvd⟩⟩ theorem prime_mul_iff [CancelCommMonoidWithZero M] {x y : M} : Prime (x * y) ↔ (Prime x ∧ IsUnit y) ∨ (IsUnit x ∧ Prime y) := by refine ⟨fun h ↦ ?_, ?_⟩ · rcases of_irreducible_mul h.irreducible with hx | hy · exact Or.inr ⟨hx, (associated_unit_mul_left y x hx).prime h⟩ · exact Or.inl ⟨(associated_mul_unit_left x y hy).prime h, hy⟩ · rintro (⟨hx, hy⟩ | ⟨hx, hy⟩) · exact (associated_mul_unit_left x y hy).symm.prime hx · exact (associated_unit_mul_right y x hx).prime hy @[simp] lemma prime_pow_iff [CancelCommMonoidWithZero M] {p : M} {n : ℕ} : Prime (p ^ n) ↔ Prime p ∧ n = 1 := by refine ⟨fun hp ↦ ?_, fun ⟨hp, hn⟩ ↦ by simpa [hn]⟩ suffices n = 1 by simp_all rcases n with - | n · simp at hp · rw [Nat.succ.injEq] rw [pow_succ', prime_mul_iff] at hp rcases hp with ⟨hp, hpn⟩ | ⟨hp, hpn⟩ · by_contra contra rw [isUnit_pow_iff contra] at hpn exact hp.not_unit hpn · exfalso exact hpn.not_unit (hp.pow n) theorem Irreducible.dvd_iff [Monoid M] {x y : M} (hx : Irreducible x) : y ∣ x ↔ IsUnit y ∨ Associated x y := by constructor · rintro ⟨z, hz⟩ obtain (h | h) := hx.isUnit_or_isUnit hz · exact Or.inl h · rw [hz] exact Or.inr (associated_mul_unit_left _ _ h) · rintro (hy | h) · exact hy.dvd · exact h.symm.dvd theorem Irreducible.associated_of_dvd [Monoid M] {p q : M} (p_irr : Irreducible p) (q_irr : Irreducible q) (dvd : p ∣ q) : Associated p q := ((q_irr.dvd_iff.mp dvd).resolve_left p_irr.not_isUnit).symm theorem Irreducible.dvd_irreducible_iff_associated [Monoid M] {p q : M} (pp : Irreducible p) (qp : Irreducible q) : p ∣ q ↔ Associated p q := ⟨Irreducible.associated_of_dvd pp qp, Associated.dvd⟩ theorem Prime.associated_of_dvd [CancelCommMonoidWithZero M] {p q : M} (p_prime : Prime p) (q_prime : Prime q) (dvd : p ∣ q) : Associated p q := p_prime.irreducible.associated_of_dvd q_prime.irreducible dvd theorem Prime.dvd_prime_iff_associated [CancelCommMonoidWithZero M] {p q : M} (pp : Prime p) (qp : Prime q) : p ∣ q ↔ Associated p q := pp.irreducible.dvd_irreducible_iff_associated qp.irreducible theorem Associated.prime_iff [CommMonoidWithZero M] {p q : M} (h : p ~ᵤ q) : Prime p ↔ Prime q := ⟨h.prime, h.symm.prime⟩ protected theorem Associated.isUnit [Monoid M] {a b : M} (h : a ~ᵤ b) : IsUnit a → IsUnit b := let ⟨u, hu⟩ := h fun ⟨v, hv⟩ => ⟨v * u, by simp [hv, hu.symm]⟩ theorem Associated.isUnit_iff [Monoid M] {a b : M} (h : a ~ᵤ b) : IsUnit a ↔ IsUnit b := ⟨h.isUnit, h.symm.isUnit⟩ theorem Irreducible.isUnit_iff_not_associated_of_dvd [Monoid M] {x y : M} (hx : Irreducible x) (hy : y ∣ x) : IsUnit y ↔ ¬ Associated x y := ⟨fun hy hxy => hx.1 (hxy.symm.isUnit hy), (hx.dvd_iff.mp hy).resolve_right⟩ protected theorem Associated.irreducible [Monoid M] {p q : M} (h : p ~ᵤ q) (hp : Irreducible p) : Irreducible q := ⟨mt h.symm.isUnit hp.1, let ⟨u, hu⟩ := h fun a b hab => have hpab : p = a * (b * (u⁻¹ : Mˣ)) := calc p = p * u * (u⁻¹ : Mˣ) := by simp _ = _ := by rw [hu]; simp [hab, mul_assoc] (hp.isUnit_or_isUnit hpab).elim Or.inl fun ⟨v, hv⟩ => Or.inr ⟨v * u, by simp [hv]⟩⟩ protected theorem Associated.irreducible_iff [Monoid M] {p q : M} (h : p ~ᵤ q) : Irreducible p ↔ Irreducible q := ⟨h.irreducible, h.symm.irreducible⟩ theorem Associated.of_mul_left [CancelCommMonoidWithZero M] {a b c d : M} (h : a * b ~ᵤ c * d) (h₁ : a ~ᵤ c) (ha : a ≠ 0) : b ~ᵤ d := let ⟨u, hu⟩ := h let ⟨v, hv⟩ := Associated.symm h₁ ⟨u * (v : Mˣ), mul_left_cancel₀ ha (by rw [← hv, mul_assoc c (v : M) d, mul_left_comm c, ← hu] simp [hv.symm, mul_comm, mul_left_comm])⟩ theorem Associated.of_mul_right [CancelCommMonoidWithZero M] {a b c d : M} : a * b ~ᵤ c * d → b ~ᵤ d → b ≠ 0 → a ~ᵤ c := by rw [mul_comm a, mul_comm c]; exact Associated.of_mul_left theorem Associated.of_pow_associated_of_prime [CancelCommMonoidWithZero M] {p₁ p₂ : M} {k₁ k₂ : ℕ} (hp₁ : Prime p₁) (hp₂ : Prime p₂) (hk₁ : 0 < k₁) (h : p₁ ^ k₁ ~ᵤ p₂ ^ k₂) : p₁ ~ᵤ p₂ := by have : p₁ ∣ p₂ ^ k₂ := by rw [← h.dvd_iff_dvd_right] apply dvd_pow_self _ hk₁.ne' rw [← hp₁.dvd_prime_iff_associated hp₂] exact hp₁.dvd_of_dvd_pow this theorem Associated.of_pow_associated_of_prime' [CancelCommMonoidWithZero M] {p₁ p₂ : M} {k₁ k₂ : ℕ} (hp₁ : Prime p₁) (hp₂ : Prime p₂) (hk₂ : 0 < k₂) (h : p₁ ^ k₁ ~ᵤ p₂ ^ k₂) : p₁ ~ᵤ p₂ := (h.symm.of_pow_associated_of_prime hp₂ hp₁ hk₂).symm /-- See also `Irreducible.coprime_iff_not_dvd`. -/ lemma Irreducible.isRelPrime_iff_not_dvd [Monoid M] {p n : M} (hp : Irreducible p) : IsRelPrime p n ↔ ¬ p ∣ n := by refine ⟨fun h contra ↦ hp.not_isUnit (h dvd_rfl contra), fun hpn d hdp hdn ↦ ?_⟩ contrapose! hpn suffices Associated p d from this.dvd.trans hdn exact (hp.dvd_iff.mp hdp).resolve_left hpn lemma Irreducible.dvd_or_isRelPrime [Monoid M] {p n : M} (hp : Irreducible p) : p ∣ n ∨ IsRelPrime p n := Classical.or_iff_not_imp_left.mpr hp.isRelPrime_iff_not_dvd.2 section UniqueUnits variable [Monoid M] [Subsingleton Mˣ] theorem associated_iff_eq {x y : M} : x ~ᵤ y ↔ x = y := by constructor · rintro ⟨c, rfl⟩ rw [units_eq_one c, Units.val_one, mul_one] · rintro rfl rfl theorem associated_eq_eq : (Associated : M → M → Prop) = Eq := by ext rw [associated_iff_eq] theorem prime_dvd_prime_iff_eq {M : Type*} [CancelCommMonoidWithZero M] [Subsingleton Mˣ] {p q : M} (pp : Prime p) (qp : Prime q) : p ∣ q ↔ p = q := by rw [pp.dvd_prime_iff_associated qp, ← associated_eq_eq] end UniqueUnits section UniqueUnits₀ variable {R : Type*} [CancelCommMonoidWithZero R] [Subsingleton Rˣ] {p₁ p₂ : R} {k₁ k₂ : ℕ} theorem eq_of_prime_pow_eq (hp₁ : Prime p₁) (hp₂ : Prime p₂) (hk₁ : 0 < k₁) (h : p₁ ^ k₁ = p₂ ^ k₂) : p₁ = p₂ := by rw [← associated_iff_eq] at h ⊢ apply h.of_pow_associated_of_prime hp₁ hp₂ hk₁ theorem eq_of_prime_pow_eq' (hp₁ : Prime p₁) (hp₂ : Prime p₂) (hk₁ : 0 < k₂) (h : p₁ ^ k₁ = p₂ ^ k₂) : p₁ = p₂ := by rw [← associated_iff_eq] at h ⊢ apply h.of_pow_associated_of_prime' hp₁ hp₂ hk₁ end UniqueUnits₀ /-- The quotient of a monoid by the `Associated` relation. Two elements `x` and `y` are associated iff there is a unit `u` such that `x * u = y`. There is a natural monoid structure on `Associates M`. -/ abbrev Associates (M : Type*) [Monoid M] : Type _ := Quotient (Associated.setoid M) namespace Associates open Associated /-- The canonical quotient map from a monoid `M` into the `Associates` of `M` -/ protected abbrev mk {M : Type*} [Monoid M] (a : M) : Associates M := ⟦a⟧ instance [Monoid M] : Inhabited (Associates M) := ⟨⟦1⟧⟩ theorem mk_eq_mk_iff_associated [Monoid M] {a b : M} : Associates.mk a = Associates.mk b ↔ a ~ᵤ b := Iff.intro Quotient.exact Quot.sound theorem quotient_mk_eq_mk [Monoid M] (a : M) : ⟦a⟧ = Associates.mk a := rfl theorem quot_mk_eq_mk [Monoid M] (a : M) : Quot.mk Setoid.r a = Associates.mk a := rfl @[simp] theorem quot_out [Monoid M] (a : Associates M) : Associates.mk (Quot.out a) = a := by rw [← quot_mk_eq_mk, Quot.out_eq] theorem mk_quot_out [Monoid M] (a : M) : Quot.out (Associates.mk a) ~ᵤ a := by rw [← Associates.mk_eq_mk_iff_associated, Associates.quot_out] theorem forall_associated [Monoid M] {p : Associates M → Prop} : (∀ a, p a) ↔ ∀ a, p (Associates.mk a) := Iff.intro (fun h _ => h _) fun h a => Quotient.inductionOn a h theorem mk_surjective [Monoid M] : Function.Surjective (@Associates.mk M _) := forall_associated.2 fun a => ⟨a, rfl⟩ instance [Monoid M] : One (Associates M) := ⟨⟦1⟧⟩ @[simp] theorem mk_one [Monoid M] : Associates.mk (1 : M) = 1 := rfl theorem one_eq_mk_one [Monoid M] : (1 : Associates M) = Associates.mk 1 := rfl @[simp] theorem mk_eq_one [Monoid M] {a : M} : Associates.mk a = 1 ↔ IsUnit a := by rw [← mk_one, mk_eq_mk_iff_associated, associated_one_iff_isUnit] instance [Monoid M] : Bot (Associates M) := ⟨1⟩ theorem bot_eq_one [Monoid M] : (⊥ : Associates M) = 1 := rfl theorem exists_rep [Monoid M] (a : Associates M) : ∃ a0 : M, Associates.mk a0 = a := Quot.exists_rep a instance [Monoid M] [Subsingleton M] : Unique (Associates M) where default := 1 uniq := forall_associated.2 fun _ ↦ mk_eq_one.2 <| isUnit_of_subsingleton _ theorem mk_injective [Monoid M] [Subsingleton Mˣ] : Function.Injective (@Associates.mk M _) := fun _ _ h => associated_iff_eq.mp (Associates.mk_eq_mk_iff_associated.mp h) section CommMonoid variable [CommMonoid M] instance instMul : Mul (Associates M) := ⟨Quotient.map₂ (· * ·) fun _ _ h₁ _ _ h₂ ↦ h₁.mul_mul h₂⟩ theorem mk_mul_mk {x y : M} : Associates.mk x * Associates.mk y = Associates.mk (x * y) := rfl instance instCommMonoid : CommMonoid (Associates M) where mul_one a' := Quotient.inductionOn a' fun a => show ⟦a * 1⟧ = ⟦a⟧ by simp one_mul a' := Quotient.inductionOn a' fun a => show ⟦1 * a⟧ = ⟦a⟧ by simp mul_assoc a' b' c' := Quotient.inductionOn₃ a' b' c' fun a b c => show ⟦a * b * c⟧ = ⟦a * (b * c)⟧ by rw [mul_assoc] mul_comm a' b' := Quotient.inductionOn₂ a' b' fun a b => show ⟦a * b⟧ = ⟦b * a⟧ by rw [mul_comm] instance instPreorder : Preorder (Associates M) where le := Dvd.dvd le_refl := dvd_refl le_trans _ _ _ := dvd_trans /-- `Associates.mk` as a `MonoidHom`. -/ protected def mkMonoidHom : M →* Associates M where toFun := Associates.mk map_one' := mk_one map_mul' _ _ := mk_mul_mk @[simp] theorem mkMonoidHom_apply (a : M) : Associates.mkMonoidHom a = Associates.mk a := rfl theorem associated_map_mk {f : Associates M →* M} (hinv : Function.RightInverse f Associates.mk) (a : M) : a ~ᵤ f (Associates.mk a) := Associates.mk_eq_mk_iff_associated.1 (hinv (Associates.mk a)).symm theorem mk_pow (a : M) (n : ℕ) : Associates.mk (a ^ n) = Associates.mk a ^ n := by induction n <;> simp [*, pow_succ, Associates.mk_mul_mk.symm] theorem dvd_eq_le : ((· ∣ ·) : Associates M → Associates M → Prop) = (· ≤ ·) := rfl instance uniqueUnits : Unique (Associates M)ˣ where uniq := by rintro ⟨a, b, hab, hba⟩ revert hab hba exact Quotient.inductionOn₂ a b <| fun a b hab hba ↦ Units.ext <| Quotient.sound <| associated_one_of_associated_mul_one <| Quotient.exact hab @[simp] theorem coe_unit_eq_one (u : (Associates M)ˣ) : (u : Associates M) = 1 := by simp [eq_iff_true_of_subsingleton] theorem isUnit_iff_eq_one (a : Associates M) : IsUnit a ↔ a = 1 := Iff.intro (fun ⟨_, h⟩ => h ▸ coe_unit_eq_one _) fun h => h.symm ▸ isUnit_one theorem isUnit_iff_eq_bot {a : Associates M} : IsUnit a ↔ a = ⊥ := by rw [Associates.isUnit_iff_eq_one, bot_eq_one] theorem isUnit_mk {a : M} : IsUnit (Associates.mk a) ↔ IsUnit a := calc IsUnit (Associates.mk a) ↔ a ~ᵤ 1 := by rw [isUnit_iff_eq_one, one_eq_mk_one, mk_eq_mk_iff_associated] _ ↔ IsUnit a := associated_one_iff_isUnit section Order theorem mul_mono {a b c d : Associates M} (h₁ : a ≤ b) (h₂ : c ≤ d) : a * c ≤ b * d := let ⟨x, hx⟩ := h₁ let ⟨y, hy⟩ := h₂ ⟨x * y, by simp [hx, hy, mul_comm, mul_left_comm]⟩ theorem one_le {a : Associates M} : 1 ≤ a := Dvd.intro _ (one_mul a) theorem le_mul_right {a b : Associates M} : a ≤ a * b := ⟨b, rfl⟩ theorem le_mul_left {a b : Associates M} : a ≤ b * a := by rw [mul_comm]; exact le_mul_right instance instOrderBot : OrderBot (Associates M) where bot := 1 bot_le _ := one_le end Order @[simp] theorem mk_dvd_mk {a b : M} : Associates.mk a ∣ Associates.mk b ↔ a ∣ b := by simp only [dvd_def, mk_surjective.exists, mk_mul_mk, mk_eq_mk_iff_associated, Associated.comm (x := b)] constructor · rintro ⟨x, u, rfl⟩ exact ⟨_, mul_assoc ..⟩ · rintro ⟨c, rfl⟩ use c theorem dvd_of_mk_le_mk {a b : M} : Associates.mk a ≤ Associates.mk b → a ∣ b := mk_dvd_mk.mp theorem mk_le_mk_of_dvd {a b : M} : a ∣ b → Associates.mk a ≤ Associates.mk b := mk_dvd_mk.mpr theorem mk_le_mk_iff_dvd {a b : M} : Associates.mk a ≤ Associates.mk b ↔ a ∣ b := mk_dvd_mk @[simp] theorem isPrimal_mk {a : M} : IsPrimal (Associates.mk a) ↔ IsPrimal a := by simp_rw [IsPrimal, forall_associated, mk_surjective.exists, mk_mul_mk, mk_dvd_mk] constructor <;> intro h b c dvd <;> obtain ⟨a₁, a₂, h₁, h₂, eq⟩ := @h b c dvd · obtain ⟨u, rfl⟩ := mk_eq_mk_iff_associated.mp eq.symm exact ⟨a₁, a₂ * u, h₁, Units.mul_right_dvd.mpr h₂, mul_assoc _ _ _⟩ · exact ⟨a₁, a₂, h₁, h₂, congr_arg _ eq⟩ @[simp] theorem decompositionMonoid_iff : DecompositionMonoid (Associates M) ↔ DecompositionMonoid M := by simp_rw [_root_.decompositionMonoid_iff, forall_associated, isPrimal_mk] instance instDecompositionMonoid [DecompositionMonoid M] : DecompositionMonoid (Associates M) := decompositionMonoid_iff.mpr ‹_› @[simp] theorem mk_isRelPrime_iff {a b : M} : IsRelPrime (Associates.mk a) (Associates.mk b) ↔ IsRelPrime a b := by simp_rw [IsRelPrime, forall_associated, mk_dvd_mk, isUnit_mk] end CommMonoid instance [Zero M] [Monoid M] : Zero (Associates M) := ⟨⟦0⟧⟩ instance [Zero M] [Monoid M] : Top (Associates M) := ⟨0⟩ @[simp] theorem mk_zero [Zero M] [Monoid M] : Associates.mk (0 : M) = 0 := rfl section MonoidWithZero variable [MonoidWithZero M] @[simp] theorem mk_eq_zero {a : M} : Associates.mk a = 0 ↔ a = 0 := ⟨fun h => (associated_zero_iff_eq_zero a).1 <| Quotient.exact h, fun h => h.symm ▸ rfl⟩ @[simp] theorem quot_out_zero : Quot.out (0 : Associates M) = 0 := by rw [← mk_eq_zero, quot_out] theorem mk_ne_zero {a : M} : Associates.mk a ≠ 0 ↔ a ≠ 0 := not_congr mk_eq_zero instance [Nontrivial M] : Nontrivial (Associates M) := ⟨⟨1, 0, mk_ne_zero.2 one_ne_zero⟩⟩ theorem exists_non_zero_rep {a : Associates M} : a ≠ 0 → ∃ a0 : M, a0 ≠ 0 ∧ Associates.mk a0 = a := Quotient.inductionOn a fun b nz => ⟨b, mt (congr_arg Quotient.mk'') nz, rfl⟩ end MonoidWithZero section CommMonoidWithZero variable [CommMonoidWithZero M] instance instCommMonoidWithZero : CommMonoidWithZero (Associates M) where zero_mul := forall_associated.2 fun a ↦ by rw [← mk_zero, mk_mul_mk, zero_mul] mul_zero := forall_associated.2 fun a ↦ by rw [← mk_zero, mk_mul_mk, mul_zero] instance instOrderTop : OrderTop (Associates M) where top := 0 le_top := dvd_zero @[simp] protected theorem le_zero (a : Associates M) : a ≤ 0 := le_top instance instBoundedOrder : BoundedOrder (Associates M) where instance [DecidableRel ((· ∣ ·) : M → M → Prop)] : DecidableRel ((· ∣ ·) : Associates M → Associates M → Prop) := fun a b => Quotient.recOnSubsingleton₂ a b fun _ _ => decidable_of_iff' _ mk_dvd_mk theorem Prime.le_or_le {p : Associates M} (hp : Prime p) {a b : Associates M} (h : p ≤ a * b) : p ≤ a ∨ p ≤ b := hp.2.2 a b h @[simp] theorem prime_mk {p : M} : Prime (Associates.mk p) ↔ Prime p := by rw [Prime, _root_.Prime, forall_associated] simp only [forall_associated, mk_ne_zero, isUnit_mk, mk_mul_mk, mk_dvd_mk] @[simp] theorem irreducible_mk {a : M} : Irreducible (Associates.mk a) ↔ Irreducible a := by simp only [irreducible_iff, isUnit_mk, forall_associated, isUnit_mk, mk_mul_mk, mk_eq_mk_iff_associated, Associated.comm (x := a)] apply Iff.rfl.and constructor · rintro h x y rfl exact h _ _ <| .refl _ · rintro h x y ⟨u, rfl⟩ simpa using h (mul_assoc _ _ _) @[simp] theorem mk_dvdNotUnit_mk_iff {a b : M} : DvdNotUnit (Associates.mk a) (Associates.mk b) ↔ DvdNotUnit a b := by simp only [DvdNotUnit, mk_ne_zero, mk_surjective.exists, isUnit_mk, mk_mul_mk, mk_eq_mk_iff_associated, Associated.comm (x := b)] refine Iff.rfl.and ?_ constructor · rintro ⟨x, hx, u, rfl⟩ refine ⟨x * u, ?_, mul_assoc ..⟩ simpa · rintro ⟨x, ⟨hx, rfl⟩⟩ use x theorem dvdNotUnit_of_lt {a b : Associates M} (hlt : a < b) : DvdNotUnit a b := by constructor · rintro rfl apply not_lt_of_ge _ hlt apply dvd_zero rcases hlt with ⟨⟨x, rfl⟩, ndvd⟩ refine ⟨x, ?_, rfl⟩ contrapose! ndvd rcases ndvd with ⟨u, rfl⟩ simp theorem irreducible_iff_prime_iff : (∀ a : M, Irreducible a ↔ Prime a) ↔ ∀ a : Associates M, Irreducible a ↔ Prime a := by simp_rw [forall_associated, irreducible_mk, prime_mk] end CommMonoidWithZero section CancelCommMonoidWithZero variable [CancelCommMonoidWithZero M] instance instPartialOrder : PartialOrder (Associates M) where le_antisymm := mk_surjective.forall₂.2 fun _a _b hab hba => mk_eq_mk_iff_associated.2 <| associated_of_dvd_dvd (dvd_of_mk_le_mk hab) (dvd_of_mk_le_mk hba) instance instCancelCommMonoidWithZero : CancelCommMonoidWithZero (Associates M) := { (by infer_instance : CommMonoidWithZero (Associates M)) with mul_left_cancel_of_ne_zero := by rintro ⟨a⟩ ha ⟨b⟩ ⟨c⟩ h rcases Quotient.exact' h with ⟨u, hu⟩ have hu : a * (b * ↑u) = a * c := by rwa [← mul_assoc] exact Quotient.sound' ⟨u, mul_left_cancel₀ (mk_ne_zero.1 ha) hu⟩ } theorem _root_.associates_irreducible_iff_prime [DecompositionMonoid M] {p : Associates M} : Irreducible p ↔ Prime p := irreducible_iff_prime instance : NoZeroDivisors (Associates M) := by infer_instance theorem le_of_mul_le_mul_left (a b c : Associates M) (ha : a ≠ 0) : a * b ≤ a * c → b ≤ c | ⟨d, hd⟩ => ⟨d, mul_left_cancel₀ ha <| by rwa [← mul_assoc]⟩ theorem one_or_eq_of_le_of_prime {p m : Associates M} (hp : Prime p) (hle : m ≤ p) : m = 1 ∨ m = p := by rcases mk_surjective p with ⟨p, rfl⟩ rcases mk_surjective m with ⟨m, rfl⟩ simpa [mk_eq_mk_iff_associated, Associated.comm, -Quotient.eq] using (prime_mk.1 hp).irreducible.dvd_iff.mp (mk_le_mk_iff_dvd.1 hle) theorem dvdNotUnit_iff_lt {a b : Associates M} : DvdNotUnit a b ↔ a < b := dvd_and_not_dvd_iff.symm theorem le_one_iff {p : Associates M} : p ≤ 1 ↔ p = 1 := by rw [← Associates.bot_eq_one, le_bot_iff] end CancelCommMonoidWithZero end Associates section CommMonoidWithZero theorem dvdNotUnit_of_dvdNotUnit_associated [CommMonoidWithZero M] [Nontrivial M] {p q r : M} (h : DvdNotUnit p q) (h' : Associated q r) : DvdNotUnit p r := by obtain ⟨u, rfl⟩ := Associated.symm h' obtain ⟨hp, x, hx⟩ := h refine ⟨hp, x * ↑u⁻¹, DvdNotUnit.not_unit ⟨u⁻¹.ne_zero, x, hx.left, mul_comm _ _⟩, ?_⟩ rw [← mul_assoc, ← hx.right, mul_assoc, Units.mul_inv, mul_one] end CommMonoidWithZero section CancelCommMonoidWithZero theorem isUnit_of_associated_mul [CancelCommMonoidWithZero M] {p b : M} (h : Associated (p * b) p) (hp : p ≠ 0) : IsUnit b := by obtain ⟨a, ha⟩ := h refine .of_mul_eq_one a ((mul_right_inj' hp).mp ?_) rwa [← mul_assoc, mul_one] theorem DvdNotUnit.not_associated [CancelCommMonoidWithZero M] {p q : M} (h : DvdNotUnit p q) : ¬Associated p q := by rintro ⟨a, rfl⟩ obtain ⟨hp, x, hx, hx'⟩ := h rcases (mul_right_inj' hp).mp hx' with rfl exact hx a.isUnit theorem dvd_prime_pow [CancelCommMonoidWithZero M] {p q : M} (hp : Prime p) (n : ℕ) : q ∣ p ^ n ↔ ∃ i ≤ n, Associated q (p ^ i) := by induction n generalizing q with | zero => simp [← isUnit_iff_dvd_one, associated_one_iff_isUnit] | succ n ih => refine ⟨fun h => ?_, fun ⟨i, hi, hq⟩ => hq.dvd.trans (pow_dvd_pow p hi)⟩ rw [pow_succ'] at h rcases hp.left_dvd_or_dvd_right_of_dvd_mul h with (⟨q, rfl⟩ | hno) · rw [mul_dvd_mul_iff_left hp.ne_zero, ih] at h rcases h with ⟨i, hi, hq⟩ refine ⟨i + 1, Nat.succ_le_succ hi, (hq.mul_left p).trans ?_⟩ rw [pow_succ'] · obtain ⟨i, hi, hq⟩ := ih.mp hno exact ⟨i, hi.trans n.le_succ, hq⟩ end CancelCommMonoidWithZero
.lake/packages/mathlib/Mathlib/Algebra/GroupWithZero/Submonoid/Instances.lean
import Mathlib.Algebra.Group.Submonoid.Operations import Mathlib.Algebra.GroupWithZero.Units.Lemmas /-! # Instances for the range submonoid of a monoid with zero hom -/ assert_not_exists Ring namespace MonoidWithZeroHom variable {G H : Type*} instance [MulZeroOneClass G] [MulZeroOneClass H] (f : G →*₀ H) : MulZeroOneClass (MonoidHom.mrange f) where zero := ⟨0, 0, by simp⟩ zero_mul _ := Subtype.ext (zero_mul _) mul_zero _ := Subtype.ext (mul_zero _) @[simp] lemma val_mrange_zero [MulZeroOneClass G] [MulZeroOneClass H] (f : G →*₀ H) : ((0 : MonoidHom.mrange f) : H) = 0 := rfl instance [MulZeroOneClass G] [MonoidWithZero H] (f : G →*₀ H) : MonoidWithZero (MonoidHom.mrange f) where instance [MulZeroOneClass G] [CommMonoidWithZero H] (f : G →*₀ H) : CommMonoidWithZero (MonoidHom.mrange f) where instance [GroupWithZero G] [GroupWithZero H] (f : G →*₀ H) : GroupWithZero (MonoidHom.mrange f) where inv := fun x ↦ ⟨x⁻¹, by obtain ⟨y, hy⟩ := x.prop use y⁻¹ simp [← hy]⟩ exists_pair_ne := ⟨⟨f 0, 0, rfl⟩, ⟨f 1, by simp [- map_one]⟩, by simp⟩ inv_zero := Subtype.ext inv_zero mul_inv_cancel := by rintro ⟨a, ha⟩ h simp only [ne_eq, Subtype.ext_iff] at h simpa using mul_inv_cancel₀ h instance [GroupWithZero G] [CommGroupWithZero H] (f : G →*₀ H) : CommGroupWithZero (MonoidHom.mrange f) where end MonoidWithZeroHom
.lake/packages/mathlib/Mathlib/Algebra/GroupWithZero/Submonoid/Pointwise.lean
import Mathlib.Algebra.Group.Submonoid.Pointwise import Mathlib.Algebra.GroupWithZero.Action.Pointwise.Set /-! # Submonoids in a group with zero -/ assert_not_exists Ring open Set open scoped Pointwise variable {G₀ G M A : Type*} [Monoid M] [AddMonoid A] namespace Submonoid section GroupWithZero variable [GroupWithZero G₀] [MulDistribMulAction G₀ M] {a : G₀} @[simp] lemma smul_mem_pointwise_smul_iff₀ (ha : a ≠ 0) (S : Submonoid M) (x : M) : a • x ∈ a • S ↔ x ∈ S := smul_mem_smul_set_iff₀ ha (S : Set M) x lemma mem_pointwise_smul_iff_inv_smul_mem₀ (ha : a ≠ 0) (S : Submonoid M) (x : M) : x ∈ a • S ↔ a⁻¹ • x ∈ S := mem_smul_set_iff_inv_smul_mem₀ ha (S : Set M) x lemma mem_inv_pointwise_smul_iff₀ (ha : a ≠ 0) (S : Submonoid M) (x : M) : x ∈ a⁻¹ • S ↔ a • x ∈ S := mem_inv_smul_set_iff₀ ha (S : Set M) x @[simp] lemma pointwise_smul_le_pointwise_smul_iff₀ (ha : a ≠ 0) {S T : Submonoid M} : a • S ≤ a • T ↔ S ≤ T := smul_set_subset_smul_set_iff₀ ha lemma pointwise_smul_le_iff₀ (ha : a ≠ 0) {S T : Submonoid M} : a • S ≤ T ↔ S ≤ a⁻¹ • T := smul_set_subset_iff₀ ha lemma le_pointwise_smul_iff₀ (ha : a ≠ 0) {S T : Submonoid M} : S ≤ a • T ↔ a⁻¹ • S ≤ T := subset_smul_set_iff₀ ha end GroupWithZero end Submonoid namespace AddSubmonoid section Monoid variable [DistribMulAction M A] /-- The action on an additive submonoid corresponding to applying the action to every element. This is available as an instance in the `Pointwise` locale. -/ protected def pointwiseMulAction : MulAction M (AddSubmonoid 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] AddSubmonoid.pointwiseMulAction @[simp, norm_cast] lemma coe_pointwise_smul (m : M) (S : AddSubmonoid A) : ↑(m • S) = m • (S : Set A) := rfl lemma smul_mem_pointwise_smul (a : A) (m : M) (S : AddSubmonoid A) : a ∈ S → m • a ∈ m • S := (Set.smul_mem_smul_set : _ → _ ∈ m • (S : Set A)) lemma mem_smul_pointwise_iff_exists (a : A) (m : M) (S : AddSubmonoid A) : a ∈ m • S ↔ ∃ s : A, s ∈ S ∧ m • s = a := (Set.mem_smul_set : a ∈ m • (S : Set A) ↔ _) @[simp] lemma smul_bot (m : M) : m • (⊥ : AddSubmonoid A) = ⊥ := map_bot _ lemma smul_sup (m : M) (S T : AddSubmonoid 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_mclosure _ _ lemma pointwise_isCentralScalar [DistribMulAction Mᵐᵒᵖ A] [IsCentralScalar M A] : IsCentralScalar M (AddSubmonoid A) := ⟨fun _ S => (congr_arg fun f : AddMonoid.End A => S.map f) <| AddMonoidHom.ext <| op_smul_eq_smul _⟩ scoped[Pointwise] attribute [instance] AddSubmonoid.pointwise_isCentralScalar end Monoid section Group variable [Group G] [DistribMulAction G A] {a : G} @[simp] lemma smul_mem_pointwise_smul_iff {S : AddSubmonoid A} {x : A} : a • x ∈ a • S ↔ x ∈ S := smul_mem_smul_set_iff lemma mem_pointwise_smul_iff_inv_smul_mem {S : AddSubmonoid A} {x : A} : x ∈ a • S ↔ a⁻¹ • x ∈ S := mem_smul_set_iff_inv_smul_mem lemma mem_inv_pointwise_smul_iff {S : AddSubmonoid A} {x : A} : x ∈ a⁻¹ • S ↔ a • x ∈ S := mem_inv_smul_set_iff @[simp] lemma pointwise_smul_le_pointwise_smul_iff {S T : AddSubmonoid A} : a • S ≤ a • T ↔ S ≤ T := smul_set_subset_smul_set_iff lemma pointwise_smul_le_iff {S T : AddSubmonoid A} : a • S ≤ T ↔ S ≤ a⁻¹ • T := smul_set_subset_iff_subset_inv_smul_set lemma le_pointwise_smul_iff {S T : AddSubmonoid A} : S ≤ a • T ↔ a⁻¹ • S ≤ T := subset_smul_set_iff end Group section GroupWithZero variable [GroupWithZero G₀] [DistribMulAction G₀ A] {S T : AddSubmonoid A} {a : G₀} @[simp] lemma smul_mem_pointwise_smul_iff₀ (ha : a ≠ 0) (S : AddSubmonoid 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 : AddSubmonoid 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 : AddSubmonoid 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 AddSubmonoid
.lake/packages/mathlib/Mathlib/Algebra/GroupWithZero/Submonoid/CancelMulZero.lean
import Mathlib.Algebra.GroupWithZero.InjSurj import Mathlib.Algebra.Group.Submonoid.Defs /-! # Submagmas with zero inherit cancellations -/ namespace MulZeroMemClass variable {M₀ : Type*} [Mul M₀] [Zero M₀] {S : Type*} [SetLike S M₀] [MulMemClass S M₀] [ZeroMemClass S M₀] (s : S) /-- A submagma with zero of a left cancellative magma with zero inherits left cancellation. -/ instance isLeftCancelMulZero [IsLeftCancelMulZero M₀] : IsLeftCancelMulZero s := Subtype.coe_injective.isLeftCancelMulZero Subtype.val rfl fun _ _ => rfl /-- A submagma with zero of a right cancellative magma with zero inherits right cancellation. -/ instance isRightCancelMulZero [IsRightCancelMulZero M₀] : IsRightCancelMulZero s := Subtype.coe_injective.isRightCancelMulZero Subtype.val rfl fun _ _ => rfl /-- A submagma with zero of a cancellative magma with zero inherits cancellation. -/ instance isCancelMulZero [IsCancelMulZero M₀] : IsCancelMulZero s where end MulZeroMemClass
.lake/packages/mathlib/Mathlib/Algebra/GroupWithZero/Submonoid/Primal.lean
import Mathlib.Algebra.Group.Submonoid.Defs import Mathlib.Algebra.GroupWithZero.Divisibility /-! # Submonoid of primal elements -/ assert_not_exists RelIso Ring /-- The submonoid of primal elements in a cancellative commutative monoid with zero. -/ def Submonoid.isPrimal (M₀ : Type*) [CancelCommMonoidWithZero M₀] : Submonoid M₀ where carrier := {a | IsPrimal a} mul_mem' := .mul one_mem' := isUnit_one.isPrimal
.lake/packages/mathlib/Mathlib/Algebra/GroupWithZero/Units/Lemmas.lean
import Mathlib.Algebra.Group.Units.Hom import Mathlib.Algebra.GroupWithZero.Commute import Mathlib.Algebra.GroupWithZero.Hom /-! # Further lemmas about units in a `MonoidWithZero` or a `GroupWithZero`. -/ assert_not_exists DenselyOrdered MulAction Ring variable {M M₀ G₀ M₀' G₀' F F' : Type*} variable [MonoidWithZero M₀] section Monoid variable [Monoid M] [GroupWithZero G₀] lemma isLocalHom_of_exists_map_ne_one [FunLike F G₀ M] [MonoidHomClass F G₀ M] {f : F} (hf : ∃ x : G₀, f x ≠ 1) : IsLocalHom f where map_nonunit a h := by rcases eq_or_ne a 0 with (rfl | h) · obtain ⟨t, ht⟩ := hf refine (ht ?_).elim have := map_mul f t 0 rw [← one_mul (f (t * 0)), mul_zero] at this exact (h.mul_right_cancel this).symm · exact ⟨⟨a, a⁻¹, mul_inv_cancel₀ h, inv_mul_cancel₀ h⟩, rfl⟩ instance [GroupWithZero G₀] [FunLike F G₀ M₀] [MonoidWithZeroHomClass F G₀ M₀] [Nontrivial M₀] (f : F) : IsLocalHom f := isLocalHom_of_exists_map_ne_one ⟨0, by simp⟩ end Monoid section GroupWithZero namespace Commute variable [GroupWithZero G₀] {a b c d : G₀} /-- The `MonoidWithZero` version of `div_eq_div_iff_mul_eq_mul`. -/ protected lemma div_eq_div_iff (hbd : Commute b d) (hb : b ≠ 0) (hd : d ≠ 0) : a / b = c / d ↔ a * d = c * b := hbd.div_eq_div_iff_of_isUnit hb.isUnit hd.isUnit /-- The `MonoidWithZero` version of `mul_inv_eq_mul_inv_iff_mul_eq_mul`. -/ protected lemma mul_inv_eq_mul_inv_iff (hbd : Commute b d) (hb : b ≠ 0) (hd : d ≠ 0) : a * b⁻¹ = c * d⁻¹ ↔ a * d = c * b := hbd.mul_inv_eq_mul_inv_iff_of_isUnit hb.isUnit hd.isUnit /-- The `MonoidWithZero` version of `inv_mul_eq_inv_mul_iff_mul_eq_mul`. -/ protected lemma inv_mul_eq_inv_mul_iff (hbd : Commute b d) (hb : b ≠ 0) (hd : d ≠ 0) : b⁻¹ * a = d⁻¹ * c ↔ d * a = b * c := hbd.inv_mul_eq_inv_mul_iff_of_isUnit hb.isUnit hd.isUnit end Commute section MulZeroOneClass variable [GroupWithZero G₀] [MulZeroOneClass M₀'] [Nontrivial M₀'] [FunLike F G₀ M₀'] [MonoidWithZeroHomClass F G₀ M₀'] (f : F) {a : G₀} theorem map_ne_zero : f a ≠ 0 ↔ a ≠ 0 := by refine ⟨fun hfa ha => hfa <| ha.symm ▸ map_zero f, ?_⟩ intro hx H lift a to G₀ˣ using isUnit_iff_ne_zero.mpr hx apply one_ne_zero (α := M₀') rw [← map_one f, ← Units.mul_inv a, map_mul, H, zero_mul] @[simp] theorem map_eq_zero : f a = 0 ↔ a = 0 := not_iff_not.1 (map_ne_zero f) end MulZeroOneClass section MonoidWithZero variable [GroupWithZero G₀] [Nontrivial M₀] [MonoidWithZero M₀'] [FunLike F G₀ M₀] [MonoidWithZeroHomClass F G₀ M₀] [FunLike F' G₀ M₀'] (f : F) {a : G₀} theorem eq_on_inv₀ [MonoidWithZeroHomClass F' G₀ M₀'] (f g : F') (h : f a = g a) : f a⁻¹ = g a⁻¹ := by rcases eq_or_ne a 0 with (rfl | ha) · rw [inv_zero, map_zero, map_zero] · exact (IsUnit.mk0 a ha).eq_on_inv f g h end MonoidWithZero section GroupWithZero variable [GroupWithZero G₀] [GroupWithZero G₀'] [FunLike F G₀ G₀'] [MonoidWithZeroHomClass F G₀ G₀'] (f : F) (a b : G₀) /-- A monoid homomorphism between groups with zeros sending `0` to `0` sends `a⁻¹` to `(f a)⁻¹`. -/ @[simp] theorem map_inv₀ : f a⁻¹ = (f a)⁻¹ := by by_cases h : a = 0 · simp [h, map_zero f] · apply eq_inv_of_mul_eq_one_left rw [← map_mul, inv_mul_cancel₀ h, map_one] @[simp] theorem map_div₀ : f (a / b) = f a / f b := map_div' f (map_inv₀ f) a b end GroupWithZero /-- We define the inverse as a `MonoidWithZeroHom` by extending the inverse map by zero on non-units. -/ noncomputable def MonoidWithZero.inverse {M : Type*} [CommMonoidWithZero M] : M →*₀ M where toFun := Ring.inverse map_zero' := Ring.inverse_zero _ map_one' := Ring.inverse_one _ map_mul' x y := (Ring.mul_inverse_rev x y).trans (mul_comm _ _) @[simp] theorem MonoidWithZero.coe_inverse {M : Type*} [CommMonoidWithZero M] : (MonoidWithZero.inverse : M → M) = Ring.inverse := rfl @[simp] theorem MonoidWithZero.inverse_apply {M : Type*} [CommMonoidWithZero M] (a : M) : MonoidWithZero.inverse a = Ring.inverse a := rfl /-- Inversion on a commutative group with zero, considered as a monoid with zero homomorphism. -/ def invMonoidWithZeroHom {G₀ : Type*} [CommGroupWithZero G₀] : G₀ →*₀ G₀ := { invMonoidHom with map_zero' := inv_zero } /-- If a monoid homomorphism `f` between two `GroupWithZero`s maps `0` to `0`, then it maps `x^n`, `n : ℤ`, to `(f x)^n`. -/ @[simp] theorem map_zpow₀ {F G₀ G₀' : Type*} [GroupWithZero G₀] [GroupWithZero G₀'] [FunLike F G₀ G₀'] [MonoidWithZeroHomClass F G₀ G₀'] (f : F) (x : G₀) (n : ℤ) : f (x ^ n) = f x ^ n := map_zpow' f (map_inv₀ f) x n end GroupWithZero
.lake/packages/mathlib/Mathlib/Algebra/GroupWithZero/Units/Basic.lean
import Mathlib.Algebra.Group.Units.Basic import Mathlib.Algebra.GroupWithZero.Basic import Mathlib.Data.Int.Basic import Mathlib.Lean.Meta.CongrTheorems import Mathlib.Tactic.Contrapose import Mathlib.Tactic.Spread /-! # Lemmas about units in a `MonoidWithZero` or a `GroupWithZero`. We also define `Ring.inverse`, a globally defined function on any ring (in fact any `MonoidWithZero`), which inverts units and sends non-units to zero. -/ assert_not_exists DenselyOrdered Equiv Subtype.restrict Multiplicative Ring variable {α M₀ G₀ : Type*} variable [MonoidWithZero M₀] namespace Units /-- An element of the unit group of a nonzero monoid with zero represented as an element of the monoid is nonzero. -/ @[simp] theorem ne_zero [Nontrivial M₀] (u : M₀ˣ) : (u : M₀) ≠ 0 := left_ne_zero_of_mul_eq_one u.mul_inv -- We can't use `mul_eq_zero` + `Units.ne_zero` in the next two lemmas because we don't assume -- `Nonzero M₀`. @[simp] theorem mul_left_eq_zero (u : M₀ˣ) {a : M₀} : a * u = 0 ↔ a = 0 := ⟨fun h => by simpa using mul_eq_zero_of_left h ↑u⁻¹, fun h => mul_eq_zero_of_left h u⟩ @[simp] theorem mul_right_eq_zero (u : M₀ˣ) {a : M₀} : ↑u * a = 0 ↔ a = 0 := ⟨fun h => by simpa using mul_eq_zero_of_right (↑u⁻¹) h, mul_eq_zero_of_right (u : M₀)⟩ end Units namespace IsUnit theorem ne_zero [Nontrivial M₀] {a : M₀} (ha : IsUnit a) : a ≠ 0 := let ⟨u, hu⟩ := ha hu ▸ u.ne_zero theorem mul_right_eq_zero {a b : M₀} (ha : IsUnit a) : a * b = 0 ↔ b = 0 := let ⟨u, hu⟩ := ha hu ▸ u.mul_right_eq_zero theorem mul_left_eq_zero {a b : M₀} (hb : IsUnit b) : a * b = 0 ↔ a = 0 := let ⟨u, hu⟩ := hb hu ▸ u.mul_left_eq_zero end IsUnit @[simp] theorem isUnit_zero_iff : IsUnit (0 : M₀) ↔ (0 : M₀) = 1 := ⟨fun ⟨⟨_, a, (a0 : 0 * a = 1), _⟩, rfl⟩ => by rwa [zero_mul] at a0, fun h => @isUnit_of_subsingleton _ _ (subsingleton_of_zero_eq_one h) 0⟩ theorem not_isUnit_zero [Nontrivial M₀] : ¬IsUnit (0 : M₀) := mt isUnit_zero_iff.1 zero_ne_one namespace Ring open Classical in /-- Introduce a function `inverse` on a monoid with zero `M₀`, which sends `x` to `x⁻¹` if `x` is invertible and to `0` otherwise. This definition is somewhat ad hoc, but one needs a fully (rather than partially) defined inverse function for some purposes, including for calculus. Note that while this is in the `Ring` namespace for brevity, it requires the weaker assumption `MonoidWithZero M₀` instead of `Ring M₀`. -/ noncomputable def inverse : M₀ → M₀ := fun x => if h : IsUnit x then ((h.unit⁻¹ : M₀ˣ) : M₀) else 0 /-- By definition, if `x` is invertible then `inverse x = x⁻¹`. -/ theorem inverse_unit (u : M₀ˣ) : inverse (u : M₀) = (u⁻¹ : M₀ˣ) := by rw [inverse, dif_pos u.isUnit, IsUnit.unit_of_val_units] theorem inverse_of_isUnit {x : M₀} (h : IsUnit x) : inverse x = ((h.unit⁻¹ : M₀ˣ) : M₀) := dif_pos h /-- By definition, if `x` is not invertible then `inverse x = 0`. -/ @[simp] theorem inverse_non_unit (x : M₀) (h : ¬IsUnit x) : inverse x = 0 := dif_neg h theorem mul_inverse_cancel (x : M₀) (h : IsUnit x) : x * inverse x = 1 := by rcases h with ⟨u, rfl⟩ rw [inverse_unit, Units.mul_inv] theorem inverse_mul_cancel (x : M₀) (h : IsUnit x) : inverse x * x = 1 := by rcases h with ⟨u, rfl⟩ rw [inverse_unit, Units.inv_mul] theorem mul_inverse_cancel_right (x y : M₀) (h : IsUnit x) : y * x * inverse x = y := by rw [mul_assoc, mul_inverse_cancel x h, mul_one] theorem inverse_mul_cancel_right (x y : M₀) (h : IsUnit x) : y * inverse x * x = y := by rw [mul_assoc, inverse_mul_cancel x h, mul_one] theorem mul_inverse_cancel_left (x y : M₀) (h : IsUnit x) : x * (inverse x * y) = y := by rw [← mul_assoc, mul_inverse_cancel x h, one_mul] theorem inverse_mul_cancel_left (x y : M₀) (h : IsUnit x) : inverse x * (x * y) = y := by rw [← mul_assoc, inverse_mul_cancel x h, one_mul] theorem inverse_mul_eq_iff_eq_mul (x y z : M₀) (h : IsUnit x) : inverse x * y = z ↔ y = x * z := ⟨fun h1 => by rw [← h1, mul_inverse_cancel_left _ _ h], fun h1 => by rw [h1, inverse_mul_cancel_left _ _ h]⟩ theorem eq_mul_inverse_iff_mul_eq (x y z : M₀) (h : IsUnit z) : x = y * inverse z ↔ x * z = y := ⟨fun h1 => by rw [h1, inverse_mul_cancel_right _ _ h], fun h1 => by rw [← h1, mul_inverse_cancel_right _ _ h]⟩ variable (M₀) @[simp] theorem inverse_one : inverse (1 : M₀) = 1 := inverse_unit 1 @[simp] theorem inverse_zero : inverse (0 : M₀) = 0 := by nontriviality exact inverse_non_unit _ not_isUnit_zero variable {M₀} end Ring theorem IsUnit.ringInverse {a : M₀} : IsUnit a → IsUnit (Ring.inverse a) | ⟨u, hu⟩ => hu ▸ ⟨u⁻¹, (Ring.inverse_unit u).symm⟩ @[deprecated (since := "2025-04-22")] alias IsUnit.ring_inverse := IsUnit.ringInverse @[deprecated (since := "2025-04-22")] protected alias Ring.IsUnit.ringInverse := IsUnit.ringInverse @[simp] theorem isUnit_ringInverse {a : M₀} : IsUnit (Ring.inverse a) ↔ IsUnit a := ⟨fun h => by cases subsingleton_or_nontrivial M₀ · convert h · contrapose h rw [Ring.inverse_non_unit _ h] exact not_isUnit_zero, IsUnit.ringInverse⟩ @[deprecated (since := "2025-04-22")] alias isUnit_ring_inverse := isUnit_ringInverse namespace Units variable [GroupWithZero G₀] /-- Embed a non-zero element of a `GroupWithZero` into the unit group. By combining this function with the operations on units, or the `/ₚ` operation, it is possible to write a division as a partial function with three arguments. -/ def mk0 (a : G₀) (ha : a ≠ 0) : G₀ˣ := ⟨a, a⁻¹, mul_inv_cancel₀ ha, inv_mul_cancel₀ ha⟩ @[simp] theorem mk0_one (h := one_ne_zero) : mk0 (1 : G₀) h = 1 := by ext rfl @[simp] theorem val_mk0 {a : G₀} (h : a ≠ 0) : (mk0 a h : G₀) = a := rfl @[simp] theorem mk0_val (u : G₀ˣ) (h : (u : G₀) ≠ 0) : mk0 (u : G₀) h = u := Units.ext rfl theorem mul_inv' (u : G₀ˣ) : u * (u : G₀)⁻¹ = 1 := mul_inv_cancel₀ u.ne_zero theorem inv_mul' (u : G₀ˣ) : (u⁻¹ : G₀) * u = 1 := inv_mul_cancel₀ u.ne_zero @[simp] theorem mk0_inj {a b : G₀} (ha : a ≠ 0) (hb : b ≠ 0) : Units.mk0 a ha = Units.mk0 b hb ↔ a = b := ⟨fun h => by injection h, fun h => Units.ext h⟩ /-- In a group with zero, an existential over a unit can be rewritten in terms of `Units.mk0`. -/ theorem exists0 {p : G₀ˣ → Prop} : (∃ g : G₀ˣ, p g) ↔ ∃ (g : G₀) (hg : g ≠ 0), p (Units.mk0 g hg) := ⟨fun ⟨g, pg⟩ => ⟨g, g.ne_zero, (g.mk0_val g.ne_zero).symm ▸ pg⟩, fun ⟨g, hg, pg⟩ => ⟨Units.mk0 g hg, pg⟩⟩ /-- An alternative version of `Units.exists0`. This one is useful if Lean cannot figure out `p` when using `Units.exists0` from right to left. -/ theorem exists0' {p : ∀ g : G₀, g ≠ 0 → Prop} : (∃ (g : G₀) (hg : g ≠ 0), p g hg) ↔ ∃ g : G₀ˣ, p g g.ne_zero := Iff.trans (by simp_rw [val_mk0]) exists0.symm @[simp] theorem exists_iff_ne_zero {p : G₀ → Prop} : (∃ u : G₀ˣ, p u) ↔ ∃ x ≠ 0, p x := by simp [exists0] theorem _root_.GroupWithZero.eq_zero_or_unit (a : G₀) : a = 0 ∨ ∃ u : G₀ˣ, a = u := by simpa using em _ end Units section GroupWithZero variable [GroupWithZero G₀] {a b c : G₀} {m n : ℕ} theorem IsUnit.mk0 (x : G₀) (hx : x ≠ 0) : IsUnit x := (Units.mk0 x hx).isUnit @[simp] theorem isUnit_iff_ne_zero : IsUnit a ↔ a ≠ 0 := (Units.exists_iff_ne_zero (p := (· = a))).trans (by simp) protected alias ⟨_, Ne.isUnit⟩ := isUnit_iff_ne_zero -- see Note [lower instance priority] instance (priority := 10) GroupWithZero.noZeroDivisors : NoZeroDivisors G₀ := { (‹_› : GroupWithZero G₀) with eq_zero_or_eq_zero_of_mul_eq_zero := @fun a b h => by contrapose! h exact (Units.mk0 a h.1 * Units.mk0 b h.2).ne_zero } -- Can't be put next to the other `mk0` lemmas because it depends on the -- `NoZeroDivisors` instance, which depends on `mk0`. @[simp] theorem Units.mk0_mul (x y : G₀) (hxy) : Units.mk0 (x * y) hxy = Units.mk0 x (mul_ne_zero_iff.mp hxy).1 * Units.mk0 y (mul_ne_zero_iff.mp hxy).2 := by ext; rfl theorem div_ne_zero (ha : a ≠ 0) (hb : b ≠ 0) : a / b ≠ 0 := by rw [div_eq_mul_inv] exact mul_ne_zero ha (inv_ne_zero hb) @[simp] theorem div_eq_zero_iff : a / b = 0 ↔ a = 0 ∨ b = 0 := by simp [div_eq_mul_inv] theorem div_ne_zero_iff : a / b ≠ 0 ↔ a ≠ 0 ∧ b ≠ 0 := div_eq_zero_iff.not.trans not_or @[simp] lemma div_self (h : a ≠ 0) : a / a = 1 := h.isUnit.div_self lemma eq_mul_inv_iff_mul_eq₀ (hc : c ≠ 0) : a = b * c⁻¹ ↔ a * c = b := hc.isUnit.eq_mul_inv_iff_mul_eq lemma eq_inv_mul_iff_mul_eq₀ (hb : b ≠ 0) : a = b⁻¹ * c ↔ b * a = c := hb.isUnit.eq_inv_mul_iff_mul_eq lemma inv_mul_eq_iff_eq_mul₀ (ha : a ≠ 0) : a⁻¹ * b = c ↔ b = a * c := ha.isUnit.inv_mul_eq_iff_eq_mul lemma mul_inv_eq_iff_eq_mul₀ (hb : b ≠ 0) : a * b⁻¹ = c ↔ a = c * b := hb.isUnit.mul_inv_eq_iff_eq_mul lemma mul_inv_eq_one₀ (hb : b ≠ 0) : a * b⁻¹ = 1 ↔ a = b := hb.isUnit.mul_inv_eq_one lemma inv_mul_eq_one₀ (ha : a ≠ 0) : a⁻¹ * b = 1 ↔ a = b := ha.isUnit.inv_mul_eq_one lemma mul_eq_one_iff_eq_inv₀ (hb : b ≠ 0) : a * b = 1 ↔ a = b⁻¹ := hb.isUnit.mul_eq_one_iff_eq_inv lemma mul_eq_one_iff_inv_eq₀ (ha : a ≠ 0) : a * b = 1 ↔ a⁻¹ = b := ha.isUnit.mul_eq_one_iff_inv_eq /-- A variant of `eq_mul_inv_iff_mul_eq₀` that moves the nonzero hypothesis to another variable. -/ lemma mul_eq_of_eq_mul_inv₀ (ha : a ≠ 0) (h : a = c * b⁻¹) : a * b = c := by rwa [← eq_mul_inv_iff_mul_eq₀]; rintro rfl; simp [ha] at h /-- A variant of `eq_inv_mul_iff_mul_eq₀` that moves the nonzero hypothesis to another variable. -/ lemma mul_eq_of_eq_inv_mul₀ (hb : b ≠ 0) (h : b = a⁻¹ * c) : a * b = c := by rwa [← eq_inv_mul_iff_mul_eq₀]; rintro rfl; simp [hb] at h /-- A variant of `inv_mul_eq_iff_eq_mul₀` that moves the nonzero hypothesis to another variable. -/ lemma eq_mul_of_inv_mul_eq₀ (hc : c ≠ 0) (h : b⁻¹ * a = c) : a = b * c := (mul_eq_of_eq_inv_mul₀ hc h.symm).symm /-- A variant of `mul_inv_eq_iff_eq_mul₀` that moves the nonzero hypothesis to another variable. -/ lemma eq_mul_of_mul_inv_eq₀ (hb : b ≠ 0) (h : a * c⁻¹ = b) : a = b * c := (mul_eq_of_eq_mul_inv₀ hb h.symm).symm lemma div_mul_cancel₀ (a : G₀) (h : b ≠ 0) : a / b * b = a := by simp [h] lemma mul_one_div_cancel (h : a ≠ 0) : a * (1 / a) = 1 := h.isUnit.mul_one_div_cancel lemma one_div_mul_cancel (h : a ≠ 0) : 1 / a * a = 1 := h.isUnit.one_div_mul_cancel @[simp] lemma div_left_inj' (hc : c ≠ 0) : a / c = b / c ↔ a = b := hc.isUnit.div_left_inj lemma div_eq_iff (hb : b ≠ 0) : a / b = c ↔ a = c * b := hb.isUnit.div_eq_iff lemma eq_div_iff (hb : b ≠ 0) : c = a / b ↔ c * b = a := hb.isUnit.eq_div_iff -- TODO: Swap RHS around lemma div_eq_iff_mul_eq (hb : b ≠ 0) : a / b = c ↔ c * b = a := hb.isUnit.div_eq_iff.trans eq_comm lemma eq_div_iff_mul_eq (hc : c ≠ 0) : a = b / c ↔ a * c = b := hc.isUnit.eq_div_iff lemma div_eq_of_eq_mul (hb : b ≠ 0) : a = c * b → a / b = c := hb.isUnit.div_eq_of_eq_mul lemma eq_div_of_mul_eq (hc : c ≠ 0) : a * c = b → a = b / c := hc.isUnit.eq_div_of_mul_eq lemma div_eq_one_iff_eq (hb : b ≠ 0) : a / b = 1 ↔ a = b := hb.isUnit.div_eq_one_iff_eq lemma div_mul_cancel_right₀ (hb : b ≠ 0) (a : G₀) : b / (a * b) = a⁻¹ := hb.isUnit.div_mul_cancel_right _ lemma mul_div_mul_right (a b : G₀) (hc : c ≠ 0) : a * c / (b * c) = a / b := hc.isUnit.mul_div_mul_right _ _ -- TODO: Duplicate of `mul_inv_cancel_right₀` lemma mul_mul_div (a : G₀) (hb : b ≠ 0) : a = a * b * (1 / b) := (hb.isUnit.mul_mul_div _).symm lemma div_div_div_cancel_right₀ (hc : c ≠ 0) (a b : G₀) : a / c / (b / c) = a / b := by rw [div_div_eq_mul_div, div_mul_cancel₀ _ hc] lemma div_mul_div_cancel₀ (hb : b ≠ 0) : a / b * (b / c) = a / c := by rw [← mul_div_assoc, div_mul_cancel₀ _ hb] lemma div_mul_cancel_of_imp (h : b = 0 → a = 0) : a / b * b = a := by obtain rfl | hb := eq_or_ne b 0 <;> simp [*] lemma mul_div_cancel_of_imp (h : b = 0 → a = 0) : a * b / b = a := by obtain rfl | hb := eq_or_ne b 0 <;> simp [*] @[simp] lemma divp_mk0 (a : G₀) (hb : b ≠ 0) : a /ₚ Units.mk0 b hb = a / b := divp_eq_div _ _ lemma pow_sub₀ (a : G₀) (ha : a ≠ 0) (h : n ≤ m) : a ^ (m - n) = a ^ m * (a ^ n)⁻¹ := by have h1 : m - n + n = m := Nat.sub_add_cancel h have h2 : a ^ (m - n) * a ^ n = a ^ m := by rw [← pow_add, h1] simpa only [div_eq_mul_inv] using eq_div_of_mul_eq (pow_ne_zero _ ha) h2 lemma pow_sub_of_lt (a : G₀) (h : n < m) : a ^ (m - n) = a ^ m * (a ^ n)⁻¹ := by obtain rfl | ha := eq_or_ne a 0 · rw [zero_pow (Nat.ne_of_gt <| Nat.sub_pos_of_lt h), zero_pow (by cutsat), zero_mul] · exact pow_sub₀ _ ha <| Nat.le_of_lt h lemma inv_pow_sub₀ (ha : a ≠ 0) (h : n ≤ m) : a⁻¹ ^ (m - n) = (a ^ m)⁻¹ * a ^ n := by rw [pow_sub₀ _ (inv_ne_zero ha) h, inv_pow, inv_pow, inv_inv] lemma inv_pow_sub_of_lt (a : G₀) (h : n < m) : a⁻¹ ^ (m - n) = (a ^ m)⁻¹ * a ^ n := by rw [pow_sub_of_lt a⁻¹ h, inv_pow, inv_pow, inv_inv] lemma zpow_sub₀ (ha : a ≠ 0) (m n : ℤ) : a ^ (m - n) = a ^ m / a ^ n := by rw [Int.sub_eq_add_neg, zpow_add₀ ha, zpow_neg, div_eq_mul_inv] lemma zpow_natCast_sub_natCast₀ (ha : a ≠ 0) (m n : ℕ) : a ^ (m - n : ℤ) = a ^ m / a ^ n := by simpa using zpow_sub₀ ha m n lemma zpow_natCast_sub_one₀ (ha : a ≠ 0) (n : ℕ) : a ^ (n - 1 : ℤ) = a ^ n / a := by simpa using zpow_sub₀ ha n 1 lemma zpow_one_sub_natCast₀ (ha : a ≠ 0) (n : ℕ) : a ^ (1 - n : ℤ) = a / a ^ n := by simpa using zpow_sub₀ ha 1 n lemma zpow_ne_zero {a : G₀} : ∀ n : ℤ, a ≠ 0 → a ^ n ≠ 0 | (_ : ℕ) => by rw [zpow_natCast]; exact pow_ne_zero _ | .negSucc n => fun ha ↦ by rw [zpow_negSucc]; exact inv_ne_zero (pow_ne_zero _ ha) lemma eq_zero_of_zpow_eq_zero {n : ℤ} : a ^ n = 0 → a = 0 := not_imp_not.1 (zpow_ne_zero _) lemma zpow_eq_zero_iff {n : ℤ} (hn : n ≠ 0) : a ^ n = 0 ↔ a = 0 := ⟨eq_zero_of_zpow_eq_zero, fun ha => ha.symm ▸ zero_zpow _ hn⟩ lemma zpow_ne_zero_iff {n : ℤ} (hn : n ≠ 0) : a ^ n ≠ 0 ↔ a ≠ 0 := (zpow_eq_zero_iff hn).ne lemma zpow_neg_mul_zpow_self (n : ℤ) (ha : a ≠ 0) : a ^ (-n) * a ^ n = 1 := by rw [zpow_neg]; exact inv_mul_cancel₀ (zpow_ne_zero n ha) theorem Ring.inverse_eq_inv (a : G₀) : Ring.inverse a = a⁻¹ := by obtain rfl | ha := eq_or_ne a 0 · simp · exact Ring.inverse_unit (Units.mk0 a ha) @[simp] theorem Ring.inverse_eq_inv' : (Ring.inverse : G₀ → G₀) = Inv.inv := funext Ring.inverse_eq_inv end GroupWithZero section CommGroupWithZero -- comm variable [CommGroupWithZero G₀] {a b c d : G₀} -- see Note [lower instance priority] instance (priority := 10) CommGroupWithZero.toCancelCommMonoidWithZero : CancelCommMonoidWithZero G₀ := { GroupWithZero.toCancelMonoidWithZero, CommGroupWithZero.toCommMonoidWithZero with } -- See note [lower instance priority] instance (priority := 100) CommGroupWithZero.toDivisionCommMonoid : DivisionCommMonoid G₀ where __ := ‹CommGroupWithZero G₀› __ := GroupWithZero.toDivisionMonoid lemma div_mul_cancel_left₀ (ha : a ≠ 0) (b : G₀) : a / (a * b) = b⁻¹ := ha.isUnit.div_mul_cancel_left _ lemma mul_div_cancel_left_of_imp (h : a = 0 → b = 0) : a * b / a = b := by rw [mul_comm, mul_div_cancel_of_imp h] lemma mul_div_cancel_of_imp' (h : b = 0 → a = 0) : b * (a / b) = a := by rw [mul_comm, div_mul_cancel_of_imp h] lemma mul_div_cancel₀ (a : G₀) (hb : b ≠ 0) : b * (a / b) = a := hb.isUnit.mul_div_cancel _ lemma mul_div_mul_left (a b : G₀) (hc : c ≠ 0) : c * a / (c * b) = a / b := hc.isUnit.mul_div_mul_left _ _ lemma mul_eq_mul_of_div_eq_div (a c : G₀) (hb : b ≠ 0) (hd : d ≠ 0) (h : a / b = c / d) : a * d = c * b := by rw [← mul_one a, ← div_self hb, ← mul_comm_div, h, div_mul_eq_mul_div, div_mul_cancel₀ _ hd] lemma div_eq_div_iff (hb : b ≠ 0) (hd : d ≠ 0) : a / b = c / d ↔ a * d = c * b := hb.isUnit.div_eq_div_iff hd.isUnit lemma mul_inv_eq_mul_inv_iff (hb : b ≠ 0) (hd : d ≠ 0) : a * b⁻¹ = c * d⁻¹ ↔ a * d = c * b := hb.isUnit.mul_inv_eq_mul_inv_iff hd.isUnit lemma inv_mul_eq_inv_mul_iff (hb : b ≠ 0) (hd : d ≠ 0) : b⁻¹ * a = d⁻¹ * c ↔ a * d = c * b := hb.isUnit.inv_mul_eq_inv_mul_iff hd.isUnit /-- The `CommGroupWithZero` version of `div_eq_div_iff_div_eq_div`. -/ lemma div_eq_div_iff_div_eq_div' (hb : b ≠ 0) (hc : c ≠ 0) : a / b = c / d ↔ a / c = b / d := by conv_lhs => rw [← mul_left_inj' hb, div_mul_cancel₀ _ hb] conv_rhs => rw [← mul_left_inj' hc, div_mul_cancel₀ _ hc] rw [mul_comm _ c, div_mul_eq_mul_div, mul_div_assoc] lemma div_eq_div_of_div_eq_div (hc : c ≠ 0) (hd : d ≠ 0) (h : a / b = c / d) : a / c = b / d := have hb : b ≠ 0 := by intro hb rw [hb, div_zero] at h exact div_ne_zero hc hd h.symm (div_eq_div_iff_div_eq_div' hb hc).mp h @[simp] lemma div_div_cancel₀ (ha : a ≠ 0) : a / (a / b) = b := ha.isUnit.div_div_cancel lemma div_div_cancel_left' (ha : a ≠ 0) : a / b / a = b⁻¹ := ha.isUnit.div_div_cancel_left lemma div_helper (b : G₀) (h : a ≠ 0) : 1 / (a * b) * a = 1 / b := by rw [div_mul_eq_mul_div, one_mul, div_mul_cancel_left₀ h, one_div] lemma div_div_div_cancel_left' (a b : G₀) (hc : c ≠ 0) : c / a / (c / b) = b / a := by rw [div_div_div_eq, mul_comm, mul_div_mul_right _ _ hc] @[simp] lemma div_mul_div_cancel₀' (ha : a ≠ 0) (b c : G₀) : a / b * (c / a) = c / b := by rw [mul_comm, div_mul_div_cancel₀ ha] end CommGroupWithZero section NoncomputableDefs variable {M : Type*} [Nontrivial M] open Classical in /-- Constructs a `GroupWithZero` structure on a `MonoidWithZero` consisting only of units and 0. -/ noncomputable def groupWithZeroOfIsUnitOrEqZero [hM : MonoidWithZero M] (h : ∀ a : M, IsUnit a ∨ a = 0) : GroupWithZero M := { hM with inv := fun a => if h0 : a = 0 then 0 else ↑((h a).resolve_right h0).unit⁻¹, inv_zero := dif_pos rfl, mul_inv_cancel := fun a h0 => by change (a * if h0 : a = 0 then 0 else ↑((h a).resolve_right h0).unit⁻¹) = 1 rw [dif_neg h0, Units.mul_inv_eq_iff_eq_mul, one_mul, IsUnit.unit_spec] } /-- Constructs a `CommGroupWithZero` structure on a `CommMonoidWithZero` consisting only of units and 0. -/ noncomputable def commGroupWithZeroOfIsUnitOrEqZero [hM : CommMonoidWithZero M] (h : ∀ a : M, IsUnit a ∨ a = 0) : CommGroupWithZero M := { groupWithZeroOfIsUnitOrEqZero h, hM with } end NoncomputableDefs
.lake/packages/mathlib/Mathlib/Algebra/GroupWithZero/Units/Equiv.lean
import Mathlib.Algebra.Group.Units.Equiv import Mathlib.Algebra.GroupWithZero.Units.Basic /-! # Multiplication by a nonzero element in a `GroupWithZero` is a permutation. -/ assert_not_exists DenselyOrdered Ring variable {G₀ : Type*} namespace Equiv section GroupWithZero variable [GroupWithZero G₀] /-- In a `GroupWithZero` `G₀`, the unit group `G₀ˣ` is equivalent to the subtype of nonzero elements. -/ @[simps] def _root_.unitsEquivNeZero : G₀ˣ ≃ {a : G₀ // a ≠ 0} where toFun a := ⟨a, a.ne_zero⟩ invFun a := Units.mk0 _ a.prop /-- Left multiplication by a nonzero element in a `GroupWithZero` is a permutation of the underlying type. -/ @[simps! -fullyApplied] protected def mulLeft₀ (a : G₀) (ha : a ≠ 0) : Perm G₀ := (Units.mk0 a ha).mulLeft theorem _root_.mulLeft_bijective₀ (a : G₀) (ha : a ≠ 0) : Function.Bijective (a * · : G₀ → G₀) := (Equiv.mulLeft₀ a ha).bijective /-- Right multiplication by a nonzero element in a `GroupWithZero` is a permutation of the underlying type. -/ @[simps! -fullyApplied] protected def mulRight₀ (a : G₀) (ha : a ≠ 0) : Perm G₀ := (Units.mk0 a ha).mulRight theorem _root_.mulRight_bijective₀ (a : G₀) (ha : a ≠ 0) : Function.Bijective ((· * a) : G₀ → G₀) := (Equiv.mulRight₀ a ha).bijective /-- Right division by a nonzero element in a `GroupWithZero` is a permutation of the underlying type. -/ @[simps! +simpRhs] def divRight₀ (a : G₀) (ha : a ≠ 0) : Perm G₀ where toFun := (· / a) invFun := (· * a) left_inv _ := by simp [ha] right_inv _ := by simp [ha] end GroupWithZero section CommGroupWithZero variable [CommGroupWithZero G₀] /-- Left division by a nonzero element in a `CommGroupWithZero` is a permutation of the underlying type. -/ @[simps! +simpRhs] def divLeft₀ (a : G₀) (ha : a ≠ 0) : Perm G₀ where toFun := (a / ·) invFun := (a / ·) left_inv _ := by simp [ha] right_inv _ := by simp [ha] end CommGroupWithZero end Equiv
.lake/packages/mathlib/Mathlib/Algebra/GroupWithZero/Action/Opposite.lean
import Mathlib.Algebra.Group.Action.Faithful import Mathlib.Algebra.Group.Action.Opposite import Mathlib.Algebra.GroupWithZero.Action.Defs import Mathlib.Algebra.GroupWithZero.NeZero /-! # Scalar actions on and by `Mᵐᵒᵖ` This file defines the actions on the opposite type `SMul R Mᵐᵒᵖ`, and actions by the opposite type, `SMul Rᵐᵒᵖ M`. Note that `MulOpposite.smul` is provided in an earlier file as it is needed to provide the `AddMonoid.nsmul` and `AddCommGroup.zsmul` fields. ## Notation With `open scoped RightActions`, this provides: * `r •> m` as an alias for `r • m` * `m <• r` as an alias for `MulOpposite.op r • m` * `v +ᵥ> p` as an alias for `v +ᵥ p` * `p <+ᵥ v` as an alias for `AddOpposite.op v +ᵥ p` -/ assert_not_exists Ring variable {M α : Type*} /-! ### Actions _on_ the opposite type Actions on the opposite type just act on the underlying type. -/ namespace MulOpposite instance instSMulZeroClass [AddMonoid α] [SMulZeroClass M α] : SMulZeroClass M αᵐᵒᵖ where smul_zero _ := unop_injective <| smul_zero _ instance instSMulWithZero [MonoidWithZero M] [AddMonoid α] [SMulWithZero M α] : SMulWithZero M αᵐᵒᵖ where zero_smul _ := unop_injective <| zero_smul _ _ instance instMulActionWithZero [MonoidWithZero M] [AddMonoid α] [MulActionWithZero M α] : MulActionWithZero M αᵐᵒᵖ where smul_zero _ := unop_injective <| smul_zero _ zero_smul _ := unop_injective <| zero_smul _ _ instance instDistribMulAction [Monoid M] [AddMonoid α] [DistribMulAction M α] : DistribMulAction M αᵐᵒᵖ where smul_add _ _ _ := unop_injective <| smul_add _ _ _ smul_zero _ := unop_injective <| smul_zero _ instance instMulDistribMulAction [Monoid M] [Monoid α] [MulDistribMulAction M α] : MulDistribMulAction M αᵐᵒᵖ where smul_mul _ _ _ := unop_injective <| smul_mul' _ _ _ smul_one _ := unop_injective <| smul_one _ end MulOpposite /-! ### Actions _by_ the opposite type (right actions) In `Mul.toSMul` in another file, we define the left action `a₁ • a₂ = a₁ * a₂`. For the multiplicative opposite, we define `MulOpposite.op a₁ • a₂ = a₂ * a₁`, with the multiplication reversed. -/ open MulOpposite /-- `Monoid.toOppositeMulAction` is faithful on nontrivial cancellative monoids with zero. -/ instance CancelMonoidWithZero.toFaithfulSMul_opposite [CancelMonoidWithZero α] [Nontrivial α] : FaithfulSMul αᵐᵒᵖ α := ⟨fun h => unop_injective <| mul_left_cancel₀ one_ne_zero (h 1)⟩
.lake/packages/mathlib/Mathlib/Algebra/GroupWithZero/Action/Faithful.lean
import Mathlib.Algebra.Group.Action.Faithful import Mathlib.Algebra.GroupWithZero.NeZero /-! # Faithful actions involving groups with zero -/ assert_not_exists Equiv.Perm.equivUnitsEnd Prod.fst_mul Ring open Function variable {α : Type*} /-- `Monoid.toMulAction` is faithful on nontrivial cancellative monoids with zero. -/ instance CancelMonoidWithZero.faithfulSMul [CancelMonoidWithZero α] [Nontrivial α] : FaithfulSMul α α where eq_of_smul_eq_smul h := mul_left_injective₀ one_ne_zero (h 1)
.lake/packages/mathlib/Mathlib/Algebra/GroupWithZero/Action/TransferInstance.lean
import Mathlib.Algebra.Group.Action.TransferInstance import Mathlib.Algebra.GroupWithZero.Action.Defs /-! # Transfer algebraic structures across `Equiv`s This continues the pattern set in `Mathlib/Algebra/Group/TransferInstance.lean`. -/ assert_not_exists Ring variable {M M₀ A B : Type*} namespace Equiv variable (M) in /-- Transfer `SMulZeroClass` across an `Equiv` -/ protected abbrev smulZeroClass (e : A ≃ B) [Zero B] [SMulZeroClass M B] : letI := e.zero SMulZeroClass M A := by letI := e.zero exact { e.smul M with smul_zero := by simp [smul_def, zero_def] } variable (M₀) in /-- Transfer `SMulWithZero` across an `Equiv` -/ protected abbrev smulWithZero (e : A ≃ B) [Zero M₀] [Zero B] [SMulWithZero M₀ B] : letI := e.zero SMulWithZero M₀ A := by letI := e.zero exact { e.smulZeroClass M₀ with zero_smul := by simp [smul_def, zero_def] } variable (M₀) in /-- Transfer `MulActionWithZero` across an `Equiv` -/ protected abbrev mulActionWithZero (e : A ≃ B) [MonoidWithZero M₀] [Zero B] [MulActionWithZero M₀ B] : letI := e.zero MulActionWithZero M₀ A := by letI := e.zero exact { e.smulWithZero M₀, e.mulAction M₀ with } variable (M) in /-- Transfer `DistribSMul` across an `Equiv` -/ protected abbrev distribSMul (e : A ≃ B) [AddZeroClass B] [DistribSMul M B] : letI := e.addZeroClass DistribSMul M A := by letI := e.addZeroClass exact { e.smulZeroClass M with smul_add := by simp [add_def, smul_def, smul_add] } variable (M) in /-- Transfer `DistribMulAction` across an `Equiv` -/ protected abbrev distribMulAction (e : A ≃ B) [Monoid M] [AddMonoid B] [DistribMulAction M B] : letI := e.addMonoid DistribMulAction M A := by letI := e.addMonoid exact { e.distribSMul M, e.mulAction M with } end Equiv
.lake/packages/mathlib/Mathlib/Algebra/GroupWithZero/Action/ConjAct.lean
import Mathlib.Algebra.GroupWithZero.Basic import Mathlib.GroupTheory.GroupAction.ConjAct /-! # Conjugation action of a group with zero on itself -/ assert_not_exists Ring variable {α G₀ : Type*} namespace ConjAct variable [GroupWithZero G₀] instance : GroupWithZero (ConjAct G₀) := ‹GroupWithZero G₀› @[simp] lemma ofConjAct_zero : ofConjAct 0 = (0 : G₀) := rfl @[simp] lemma toConjAct_zero : toConjAct (0 : G₀) = 0 := rfl instance mulAction₀ : MulAction (ConjAct G₀) G₀ where one_smul := by simp [smul_def] mul_smul := by simp [smul_def, mul_assoc] instance smulCommClass₀ [SMul α G₀] [SMulCommClass α G₀ G₀] [IsScalarTower α G₀ G₀] : SMulCommClass α (ConjAct G₀) G₀ where smul_comm a ug g := by rw [smul_def, smul_def, mul_smul_comm, smul_mul_assoc] instance smulCommClass₀' [SMul α G₀] [SMulCommClass G₀ α G₀] [IsScalarTower α G₀ G₀] : SMulCommClass (ConjAct G₀) α G₀ := haveI := SMulCommClass.symm G₀ α G₀ .symm .. end ConjAct
.lake/packages/mathlib/Mathlib/Algebra/GroupWithZero/Action/Prod.lean
import Mathlib.Algebra.Group.Action.Prod import Mathlib.Algebra.GroupWithZero.Action.End /-! # Prod instances for multiplicative actions with zero This file defines instances for `MulActionWithZero` and related structures on `α × β` ## See also * `Algebra.GroupWithZero.Action.Opposite` * `Algebra.GroupWithZero.Action.Pi` * `Algebra.GroupWithZero.Action.Units` -/ assert_not_exists Ring variable {M N α β : Type*} namespace Prod section variable [SMul M α] [SMul M β] theorem smul_zero_mk {α : Type*} [Monoid M] [AddMonoid α] [DistribMulAction M α] (a : M) (c : β) : a • ((0 : α), c) = (0, a • c) := by rw [Prod.smul_mk, smul_zero] theorem smul_mk_zero {β : Type*} [Monoid M] [AddMonoid β] [DistribMulAction M β] (a : M) (b : α) : a • (b, (0 : β)) = (a • b, 0) := by rw [Prod.smul_mk, smul_zero] end instance smulZeroClass {R M N : Type*} [Zero M] [Zero N] [SMulZeroClass R M] [SMulZeroClass R N] : SMulZeroClass R (M × N) where smul_zero _ := by ext <;> exact smul_zero _ instance distribSMul {R M N : Type*} [AddZeroClass M] [AddZeroClass N] [DistribSMul R M] [DistribSMul R N] : DistribSMul R (M × N) where smul_add _ _ _ := by ext <;> exact smul_add .. instance distribMulAction {R : Type*} [Monoid R] [AddMonoid M] [AddMonoid N] [DistribMulAction R M] [DistribMulAction R N] : DistribMulAction R (M × N) := { Prod.mulAction, Prod.distribSMul with } instance mulDistribMulAction {R : Type*} [Monoid R] [Monoid M] [Monoid N] [MulDistribMulAction R M] [MulDistribMulAction R N] : MulDistribMulAction R (M × N) where smul_mul _ _ _ := by ext <;> exact smul_mul' .. smul_one _ := by ext <;> exact smul_one _ instance smulWithZero {R : Type*} [Zero R] [Zero M] [Zero N] [SMulWithZero R M] [SMulWithZero R N] : SMulWithZero R (M × N) where zero_smul _ := by ext <;> exact zero_smul .. instance mulActionWithZero {R : Type*} [MonoidWithZero R] [Zero M] [Zero N] [MulActionWithZero R M] [MulActionWithZero R N] : MulActionWithZero R (M × N) := { Prod.mulAction, Prod.smulWithZero with } end Prod /-! ### Scalar multiplication as a homomorphism -/ section Action_by_Prod variable (M N α) [Monoid M] [Monoid N] [AddMonoid α] /-- Construct a `DistribMulAction` by a product monoid from `DistribMulAction`s by the factors. -/ abbrev DistribMulAction.prodOfSMulCommClass [DistribMulAction M α] [DistribMulAction N α] [SMulCommClass M N α] : DistribMulAction (M × N) α where __ := MulAction.prodOfSMulCommClass M N α smul_zero mn := by change mn.1 • mn.2 • 0 = (0 : α); rw [smul_zero, smul_zero] smul_add mn a a' := by change mn.1 • mn.2 • _ = (_ : α); rw [smul_add, smul_add]; rfl /-- A `DistribMulAction` by a product monoid is equivalent to commuting `DistribMulAction`s by the factors. -/ def DistribMulAction.prodEquiv : DistribMulAction (M × N) α ≃ Σ' (_ : DistribMulAction M α) (_ : DistribMulAction N α), SMulCommClass M N α where toFun _ := letI instM := DistribMulAction.compHom α (.inl M N) letI instN := DistribMulAction.compHom α (.inr M N) ⟨instM, instN, (MulAction.prodEquiv M N α inferInstance).2.2⟩ invFun _insts := letI := _insts.1; letI := _insts.2.1; have := _insts.2.2 DistribMulAction.prodOfSMulCommClass M N α left_inv _ := by dsimp only; ext ⟨m, n⟩ a change (m, (1 : N)) • ((1 : M), n) • a = _ rw [smul_smul, Prod.mk_mul_mk, mul_one, one_mul]; rfl right_inv := by rintro ⟨_, x, _⟩ dsimp only; congr 1 · ext m a; (conv_rhs => rw [← one_smul N a]); rfl congr 1 · funext i; congr; ext m a; clear i; (conv_rhs => rw [← one_smul N a]); rfl · ext n a; (conv_rhs => rw [← one_smul M (SMul.smul n a)]); rfl · exact proof_irrel_heq .. end Action_by_Prod
.lake/packages/mathlib/Mathlib/Algebra/GroupWithZero/Action/Pi.lean
import Mathlib.Algebra.Group.Action.Pi import Mathlib.Algebra.GroupWithZero.Action.Defs import Mathlib.Algebra.GroupWithZero.Defs import Mathlib.Algebra.GroupWithZero.Pi import Mathlib.Tactic.Common /-! # Pi instances for multiplicative actions with zero This file defines instances for `MulActionWithZero` and related structures on `Pi` types. ## See also * `Algebra.GroupWithZero.Action.Opposite` * `Algebra.GroupWithZero.Action.Prod` * `Algebra.GroupWithZero.Action.Units` -/ assert_not_exists Ring universe u v variable {I : Type u} -- The indexing type variable {f : I → Type v} namespace Pi instance smulZeroClass (α) {n : ∀ i, Zero <| f i} [∀ i, SMulZeroClass α <| f i] : @SMulZeroClass α (∀ i : I, f i) (@Pi.instZero I f n) where smul_zero _ := funext fun _ => smul_zero _ instance smulZeroClass' {g : I → Type*} {n : ∀ i, Zero <| g i} [∀ i, SMulZeroClass (f i) (g i)] : @SMulZeroClass (∀ i, f i) (∀ i : I, g i) (@Pi.instZero I g n) where smul_zero := by intros; ext x; exact smul_zero _ instance distribSMul (α) {n : ∀ i, AddZeroClass <| f i} [∀ i, DistribSMul α <| f i] : @DistribSMul α (∀ i : I, f i) (@Pi.addZeroClass I f n) where smul_zero _ := funext fun _ => smul_zero _ smul_add _ _ _ := funext fun _ => smul_add _ _ _ instance distribSMul' {g : I → Type*} {n : ∀ i, AddZeroClass <| g i} [∀ i, DistribSMul (f i) (g i)] : @DistribSMul (∀ i, f i) (∀ i : I, g i) (@Pi.addZeroClass I g n) where smul_zero := by intros; ext x; exact smul_zero _ smul_add := by intros; ext x; exact smul_add _ _ _ instance distribMulAction (α) {m : Monoid α} {n : ∀ i, AddMonoid <| f i} [∀ i, DistribMulAction α <| f i] : @DistribMulAction α (∀ i : I, f i) m (@Pi.addMonoid I f n) := { Pi.mulAction _, Pi.distribSMul _ with } instance distribMulAction' {g : I → Type*} {m : ∀ i, Monoid (f i)} {n : ∀ i, AddMonoid <| g i} [∀ i, DistribMulAction (f i) (g i)] : @DistribMulAction (∀ i, f i) (∀ i : I, g i) (@Pi.monoid I f m) (@Pi.addMonoid I g n) := { Pi.mulAction', Pi.distribSMul' with } instance smulWithZero (α) [Zero α] [∀ i, Zero (f i)] [∀ i, SMulWithZero α (f i)] : SMulWithZero α (∀ i, f i) := { Pi.instSMul with smul_zero := fun _ => funext fun _ => smul_zero _ zero_smul := fun _ => funext fun _ => zero_smul _ _ } instance smulWithZero' {g : I → Type*} [∀ i, Zero (g i)] [∀ i, Zero (f i)] [∀ i, SMulWithZero (g i) (f i)] : SMulWithZero (∀ i, g i) (∀ i, f i) := { Pi.smul' with smul_zero := fun _ => funext fun _ => smul_zero _ zero_smul := fun _ => funext fun _ => zero_smul _ _ } instance mulActionWithZero (α) [MonoidWithZero α] [∀ i, Zero (f i)] [∀ i, MulActionWithZero α (f i)] : MulActionWithZero α (∀ i, f i) := { Pi.mulAction _, Pi.smulWithZero _ with } instance mulActionWithZero' {g : I → Type*} [∀ i, MonoidWithZero (g i)] [∀ i, Zero (f i)] [∀ i, MulActionWithZero (g i) (f i)] : MulActionWithZero (∀ i, g i) (∀ i, f i) := { Pi.mulAction', Pi.smulWithZero' with } theorem single_smul {α} [Monoid α] [∀ i, AddMonoid <| f i] [∀ i, DistribMulAction α <| f i] [DecidableEq I] (i : I) (r : α) (x : f i) : single i (r • x) = r • single i x := single_op (fun i : I => (r • · : f i → f i)) (fun _ => smul_zero _) _ _ /-- A version of `Pi.single_smul` for non-dependent functions. It is useful in cases where Lean fails to apply `Pi.single_smul`. -/ theorem single_smul' {α β} [Monoid α] [AddMonoid β] [DistribMulAction α β] [DecidableEq I] (i : I) (r : α) (x : β) : single (M := fun _ => β) i (r • x) = r • single (M := fun _ => β) i x := single_smul (f := fun _ => β) i r x theorem single_smul₀ {g : I → Type*} [∀ i, MonoidWithZero (f i)] [∀ i, AddMonoid (g i)] [∀ i, DistribMulAction (f i) (g i)] [DecidableEq I] (i : I) (r : f i) (x : g i) : single i (r • x) = single i r • single i x := single_op₂ (fun i : I => ((· • ·) : f i → g i → g i)) (fun _ => smul_zero _) _ _ _ instance mulDistribMulAction (α) {m : Monoid α} {n : ∀ i, Monoid <| f i} [∀ i, MulDistribMulAction α <| f i] : @MulDistribMulAction α (∀ i : I, f i) m (@Pi.monoid I f n) := { Pi.mulAction _ with smul_one := fun _ => funext fun _ => smul_one _ smul_mul := fun _ _ _ => funext fun _ => smul_mul' _ _ _ } instance mulDistribMulAction' {g : I → Type*} {m : ∀ i, Monoid (f i)} {n : ∀ i, Monoid <| g i} [∀ i, MulDistribMulAction (f i) (g i)] : @MulDistribMulAction (∀ i, f i) (∀ i : I, g i) (@Pi.monoid I f m) (@Pi.monoid I g n) where smul_mul := by intros ext x apply smul_mul' smul_one := by intros ext x apply smul_one end Pi
.lake/packages/mathlib/Mathlib/Algebra/GroupWithZero/Action/Center.lean
import Mathlib.Algebra.GroupWithZero.Units.Basic import Mathlib.GroupTheory.Subgroup.Center /-! # The center of a group with zero -/ assert_not_exists Ring /-- For a group with zero, the center of the units is the same as the units of the center. -/ @[simps! apply_val_coe symm_apply_coe_val] def Subgroup.centerUnitsEquivUnitsCenter (G₀ : Type*) [GroupWithZero G₀] : center G₀ˣ ≃* (Submonoid.center G₀)ˣ where toFun := MonoidHom.toHomUnits { toFun u := by refine ⟨(u : G₀ˣ), Submonoid.mem_center_iff.mpr fun r ↦ ?_⟩ obtain rfl | hr := eq_or_ne r 0 · rw [mul_zero, zero_mul] · exact congrArg Units.val <| (u.2.comm <| Units.mk0 r hr).symm map_one' := rfl map_mul' _ _ := rfl } invFun u := unitsCenterToCenterUnits G₀ u map_mul' := map_mul _
.lake/packages/mathlib/Mathlib/Algebra/GroupWithZero/Action/Basic.lean
import Mathlib.Algebra.Group.Action.End import Mathlib.Algebra.GroupWithZero.Action.Defs import Mathlib.Algebra.Group.Action.Prod import Mathlib.Algebra.GroupWithZero.Prod /-! # Definitions of group actions This file defines a hierarchy of group action type-classes on top of the previously defined notation classes `SMul` and its additive version `VAdd`: * `MulAction M α` and its additive version `AddAction G P` are typeclasses used for actions of multiplicative and additive monoids and groups; they extend notation classes `SMul` and `VAdd` that are defined in `Algebra.Group.Defs`; * `DistribMulAction M A` is a typeclass for an action of a multiplicative monoid on an additive monoid such that `a • (b + c) = a • b + a • c` and `a • 0 = 0`. The hierarchy is extended further by `Module`, defined elsewhere. Also provided are typeclasses for faithful and transitive actions, and typeclasses regarding the interaction of different group actions, * `SMulCommClass M N α` and its additive version `VAddCommClass M N α`; * `IsScalarTower M N α` and its additive version `VAddAssocClass M N α`; * `IsCentralScalar M α` and its additive version `IsCentralVAdd M N α`. ## Notation - `a • b` is used as notation for `SMul.smul a b`. - `a +ᵥ b` is used as notation for `VAdd.vadd a b`. ## Implementation details This file should avoid depending on other parts of `GroupTheory`, to avoid import cycles. More sophisticated lemmas belong in `GroupTheory.GroupAction`. ## Tags group action -/ assert_not_exists Ring open Function variable {G G₀ A M M₀ N₀ R α : Type*} section GroupWithZero variable [GroupWithZero G₀] [MulAction G₀ α] {a : G₀} protected lemma MulAction.bijective₀ (ha : a ≠ 0) : Bijective (a • · : α → α) := MulAction.bijective <| Units.mk0 a ha protected lemma MulAction.injective₀ (ha : a ≠ 0) : Injective (a • · : α → α) := (MulAction.bijective₀ ha).injective protected lemma MulAction.surjective₀ (ha : a ≠ 0) : Surjective (a • · : α → α) := (MulAction.bijective₀ ha).surjective end GroupWithZero section DistribMulAction variable [Group G] [Monoid M] [AddMonoid A] variable (A) /-- Each element of the group defines an additive monoid isomorphism. This is a stronger version of `MulAction.toPerm`. -/ @[simps +simpRhs] def DistribMulAction.toAddEquiv [DistribMulAction G A] (x : G) : A ≃+ A where __ := toAddMonoidHom A x __ := MulAction.toPermHom G A x variable (G) /-- Each element of the group defines an additive monoid isomorphism. This is a stronger version of `MulAction.toPermHom`. -/ @[simps] def DistribMulAction.toAddAut [DistribMulAction G A] : G →* AddAut A where toFun := toAddEquiv _ map_one' := AddEquiv.ext (one_smul _) map_mul' _ _ := AddEquiv.ext (mul_smul _ _) end DistribMulAction /-- Scalar multiplication as a monoid homomorphism with zero. -/ @[simps] def smulMonoidWithZeroHom [MonoidWithZero M₀] [MulZeroOneClass N₀] [MulActionWithZero M₀ N₀] [IsScalarTower M₀ N₀ N₀] [SMulCommClass M₀ N₀ N₀] : M₀ × N₀ →*₀ N₀ := { smulMonoidHom with map_zero' := smul_zero _ } namespace AddAut /-- The tautological action by `AddAut A` on `A`. This generalizes `Function.End.applyMulAction`. -/ instance applyDistribMulAction [AddMonoid A] : DistribMulAction (AddAut A) A where smul := (· <| ·) smul_zero := map_zero smul_add := map_add one_smul _ := rfl mul_smul _ _ _ := rfl end AddAut lemma IsUnit.smul_sub_iff_sub_inv_smul [Group G] [Monoid R] [AddGroup R] [DistribMulAction G R] [IsScalarTower G R R] [SMulCommClass G R R] (r : G) (a : R) : IsUnit (r • (1 : R) - a) ↔ IsUnit (1 - r⁻¹ • a) := by rw [← isUnit_smul_iff r (1 - r⁻¹ • a), smul_sub, smul_inv_smul] @[simp] theorem smul_zpow₀' [Group G] [GroupWithZero G₀] [MulDistribMulAction G G₀] (g : G) (x : G₀) (n : ℤ) : g • (x ^ n) = (g • x) ^ n := by cases n <;> simp
.lake/packages/mathlib/Mathlib/Algebra/GroupWithZero/Action/End.lean
import Mathlib.Algebra.Group.Action.Hom import Mathlib.Algebra.Group.Equiv.Defs import Mathlib.Algebra.GroupWithZero.Action.Units /-! # Group actions and (endo)morphisms -/ assert_not_exists RelIso Equiv.Perm.equivUnitsEnd Prod.fst_mul Ring open Function variable {M N A α β : Type*} /-- Push forward the action of `R` on `M` along a compatible surjective map `f : R →* S`. See also `Function.Surjective.mulActionLeft` and `Function.Surjective.moduleLeft`. -/ abbrev Function.Surjective.distribMulActionLeft {R S M : Type*} [Monoid R] [AddMonoid M] [DistribMulAction R M] [Monoid S] [SMul S M] (f : R →* S) (hf : Function.Surjective f) (hsmul : ∀ (c) (x : M), f c • x = c • x) : DistribMulAction S M := { hf.distribSMulLeft f hsmul, hf.mulActionLeft f hsmul with } section AddMonoid variable (A) [AddMonoid A] [Monoid M] [DistribMulAction M A] /-- Compose a `DistribMulAction` with a `MonoidHom`, with action `f r' • m`. See note [reducible non-instances]. -/ abbrev DistribMulAction.compHom [Monoid N] (f : N →* M) : DistribMulAction N A := { DistribSMul.compFun A f, MulAction.compHom A f with } end AddMonoid section Monoid variable (A) [Monoid A] [Monoid M] [MulDistribMulAction M A] /-- Compose a `MulDistribMulAction` with a `MonoidHom`, with action `f r' • m`. See note [reducible non-instances]. -/ abbrev MulDistribMulAction.compHom [Monoid N] (f : N →* M) : MulDistribMulAction N A := { MulAction.compHom A f with smul_one := fun x => smul_one (f x), smul_mul := fun x => smul_mul' (f x) } end Monoid /-- The tautological action by `AddMonoid.End α` on `α`. This generalizes `Function.End.applyMulAction`. -/ instance AddMonoid.End.applyDistribMulAction [AddMonoid α] : DistribMulAction (AddMonoid.End α) α where smul := (· <| ·) smul_zero := AddMonoidHom.map_zero smul_add := AddMonoidHom.map_add one_smul _ := rfl mul_smul _ _ _ := rfl @[simp] theorem AddMonoid.End.smul_def [AddMonoid α] (f : AddMonoid.End α) (a : α) : f • a = f a := rfl /-- `AddMonoid.End.applyDistribMulAction` is faithful. -/ instance AddMonoid.End.applyFaithfulSMul [AddMonoid α] : FaithfulSMul (AddMonoid.End α) α := ⟨fun {_ _ h} => AddMonoidHom.ext h⟩ /-- Each non-zero element of a `GroupWithZero` defines an additive monoid isomorphism of an `AddMonoid` on which it acts distributively. This is a stronger version of `DistribMulAction.toAddMonoidHom`. -/ def DistribMulAction.toAddEquiv₀ {α : Type*} (β : Type*) [GroupWithZero α] [AddMonoid β] [DistribMulAction α β] (x : α) (hx : x ≠ 0) : β ≃+ β := { DistribMulAction.toAddMonoidHom β x with invFun := fun b ↦ x⁻¹ • b left_inv := fun b ↦ inv_smul_smul₀ hx b right_inv := fun b ↦ smul_inv_smul₀ hx b }
.lake/packages/mathlib/Mathlib/Algebra/GroupWithZero/Action/Defs.lean
import Mathlib.Algebra.Group.Action.Opposite import Mathlib.Algebra.GroupWithZero.Hom import Mathlib.Algebra.GroupWithZero.Opposite import Mathlib.Algebra.Notation.Pi.Basic /-! # Definitions of group actions This file defines a hierarchy of group action type-classes on top of the previously defined notation classes `SMul` and its additive version `VAdd`: * `SMulZeroClass` is a typeclass for an action that preserves zero * `DistribSMul M A` is a typeclass for an action on an additive monoid (`AddZeroClass`) that preserves addition and zero * `DistribMulAction M A` is a typeclass for an action of a multiplicative monoid on an additive monoid such that `a • (b + c) = a • b + a • c` and `a • 0 = 0`. The hierarchy is extended further by `Module`, defined elsewhere. ## Notation - `a • b` is used as notation for `SMul.smul a b`. ## Implementation details This file should avoid depending on other parts of `GroupTheory`, to avoid import cycles. More sophisticated lemmas belong in `GroupTheory.GroupAction`. ## Tags group action -/ assert_not_exists Equiv.Perm.equivUnitsEnd Prod.fst_mul Ring open Function variable {M M₀ M₀' G₀ G₀' N A A' B α β : Type*} /-- Typeclass for scalar multiplication that preserves `0` on the right. -/ class SMulZeroClass (M A : Type*) [Zero A] extends SMul M A where /-- Multiplying `0` by a scalar gives `0` -/ smul_zero : ∀ a : M, a • (0 : A) = 0 section smul_zero variable [Zero A] [SMulZeroClass M A] @[simp] theorem smul_zero (a : M) : a • (0 : A) = 0 := SMulZeroClass.smul_zero _ lemma smul_ite_zero (p : Prop) [Decidable p] (a : M) (b : A) : (a • if p then b else 0) = if p then a • b else 0 := by split_ifs <;> simp lemma smul_eq_zero_of_right (a : M) {b : A} (h : b = 0) : a • b = 0 := h.symm ▸ smul_zero a lemma right_ne_zero_of_smul {a : M} {b : A} : a • b ≠ 0 → b ≠ 0 := mt <| smul_eq_zero_of_right a /-- Pullback a zero-preserving scalar multiplication along an injective zero-preserving map. See note [reducible non-instances]. -/ protected abbrev Function.Injective.smulZeroClass [Zero B] [SMul M B] (f : ZeroHom B A) (hf : Injective f) (smul : ∀ (c : M) (x), f (c • x) = c • f x) : SMulZeroClass M B where smul_zero c := hf <| by simp only [smul, map_zero, smul_zero] /-- Pushforward a zero-preserving scalar multiplication along a zero-preserving map. See note [reducible non-instances]. -/ protected abbrev ZeroHom.smulZeroClass [Zero B] [SMul M B] (f : ZeroHom A B) (smul : ∀ (c : M) (x), f (c • x) = c • f x) : SMulZeroClass M B where smul_zero c := by rw [← map_zero f, ← smul, smul_zero] /-- Push forward the multiplication of `R` on `M` along a compatible surjective map `f : R → S`. See also `Function.Surjective.distribMulActionLeft`. -/ abbrev Function.Surjective.smulZeroClassLeft {R S M : Type*} [Zero M] [SMulZeroClass R M] [SMul S M] (f : R → S) (hf : Function.Surjective f) (hsmul : ∀ (c) (x : M), f c • x = c • x) : SMulZeroClass S M where smul_zero := hf.forall.mpr fun c => by rw [hsmul, smul_zero] variable (A) /-- Compose a `SMulZeroClass` with a function, with scalar multiplication `f r' • m`. See note [reducible non-instances]. -/ abbrev SMulZeroClass.compFun (f : N → M) : SMulZeroClass N A where smul := SMul.comp.smul f smul_zero x := smul_zero (f x) /-- Each element of the scalars defines a zero-preserving map. -/ @[simps] def SMulZeroClass.toZeroHom (x : M) : ZeroHom A A where toFun := (x • ·) map_zero' := smul_zero x end smul_zero section Zero variable (M₀ A) /-- `SMulWithZero` is a class consisting of a Type `M₀` with `0 ∈ M₀` and a scalar multiplication of `M₀` on a Type `A` with `0`, such that the equality `r • m = 0` holds if at least one among `r` or `m` equals `0`. -/ class SMulWithZero [Zero M₀] [Zero A] extends SMulZeroClass M₀ A where /-- Scalar multiplication by the scalar `0` is `0`. -/ zero_smul : ∀ m : A, (0 : M₀) • m = 0 instance MulZeroClass.toSMulWithZero [MulZeroClass M₀] : SMulWithZero M₀ M₀ where smul := (· * ·) smul_zero := mul_zero zero_smul := zero_mul /-- Like `MulZeroClass.toSMulWithZero`, but multiplies on the right. -/ instance MulZeroClass.toOppositeSMulWithZero [MulZeroClass M₀] : SMulWithZero M₀ᵐᵒᵖ M₀ where smul_zero _ := zero_mul _ zero_smul := mul_zero variable {A} [Zero M₀] [Zero A] [SMulWithZero M₀ A] @[simp] theorem zero_smul (m : A) : (0 : M₀) • m = 0 := SMulWithZero.zero_smul m variable {M₀} {a : M₀} {b : A} lemma smul_eq_zero_of_left (h : a = 0) (b : A) : a • b = 0 := h.symm ▸ zero_smul _ b lemma left_ne_zero_of_smul : a • b ≠ 0 → a ≠ 0 := mt fun h ↦ smul_eq_zero_of_left h b variable [Zero M₀'] [Zero A'] [SMul M₀ A'] /-- Pullback a `SMulWithZero` structure along an injective zero-preserving homomorphism. -/ -- See note [reducible non-instances] protected abbrev Function.Injective.smulWithZero (f : ZeroHom A' A) (hf : Injective f) (smul : ∀ (a : M₀) (b), f (a • b) = a • f b) : SMulWithZero M₀ A' where zero_smul a := hf <| by simp [smul] smul_zero a := hf <| by simp [smul] /-- Pushforward a `SMulWithZero` structure along a surjective zero-preserving homomorphism. -/ -- See note [reducible non-instances] protected abbrev Function.Surjective.smulWithZero (f : ZeroHom A A') (hf : Surjective f) (smul : ∀ (a : M₀) (b), f (a • b) = a • f b) : SMulWithZero M₀ A' where zero_smul m := by rcases hf m with ⟨x, rfl⟩ simp [← smul] smul_zero c := by rw [← f.map_zero, ← smul, smul_zero] variable (A) /-- Compose a `SMulWithZero` with a `ZeroHom`, with action `f r' • m` -/ def SMulWithZero.compHom (f : ZeroHom M₀' M₀) : SMulWithZero M₀' A where smul := (f · • ·) smul_zero m := smul_zero (f m) zero_smul m := by change (f 0) • m = 0; rw [map_zero, zero_smul] end Zero instance AddMonoid.natSMulWithZero [AddMonoid A] : SMulWithZero ℕ A where smul_zero := _root_.nsmul_zero zero_smul := zero_nsmul instance AddGroup.intSMulWithZero [AddGroup A] : SMulWithZero ℤ A where smul_zero := zsmul_zero zero_smul := zero_zsmul section MonoidWithZero variable (M₀ A) [MonoidWithZero M₀] [MonoidWithZero M₀'] [Zero A] /-- An action of a monoid with zero `M₀` on a Type `A`, also with `0`, extends `MulAction` and is compatible with `0` (both in `M₀` and in `A`), with `1 ∈ M₀`, and with associativity of multiplication on the monoid `A`. -/ class MulActionWithZero extends MulAction M₀ A where -- these fields are copied from `SMulWithZero`, as `extends` behaves poorly /-- Scalar multiplication by any element send `0` to `0`. -/ smul_zero : ∀ r : M₀, r • (0 : A) = 0 /-- Scalar multiplication by the scalar `0` is `0`. -/ zero_smul : ∀ m : A, (0 : M₀) • m = 0 -- see Note [lower instance priority] instance (priority := 100) MulActionWithZero.toSMulWithZero (M₀ A) {_ : MonoidWithZero M₀} {_ : Zero A} [m : MulActionWithZero M₀ A] : SMulWithZero M₀ A := { m with } /-- See also `Semiring.toModule` -/ instance MonoidWithZero.toMulActionWithZero : MulActionWithZero M₀ M₀ := { MulZeroClass.toSMulWithZero M₀, Monoid.toMulAction M₀ with } /-- Like `MonoidWithZero.toMulActionWithZero`, but multiplies on the right. See also `Semiring.toOppositeModule` -/ instance MonoidWithZero.toOppositeMulActionWithZero : MulActionWithZero M₀ᵐᵒᵖ M₀ := { MulZeroClass.toOppositeSMulWithZero M₀, Monoid.toOppositeMulAction with } protected lemma MulActionWithZero.subsingleton [MulActionWithZero M₀ A] [Subsingleton M₀] : Subsingleton A where allEq x y := by rw [← one_smul M₀ x, ← one_smul M₀ y, Subsingleton.elim (1 : M₀) 0, zero_smul, zero_smul] protected lemma MulActionWithZero.nontrivial [MulActionWithZero M₀ A] [Nontrivial A] : Nontrivial M₀ := (subsingleton_or_nontrivial M₀).resolve_left fun _ => not_subsingleton A <| MulActionWithZero.subsingleton M₀ A variable {M₀ A} [MulActionWithZero M₀ A] [Zero A'] [SMul M₀ A'] (p : Prop) [Decidable p] lemma ite_zero_smul (a : M₀) (b : A) : (if p then a else 0 : M₀) • b = if p then a • b else 0 := by rw [ite_smul, zero_smul] lemma boole_smul (a : A) : (if p then 1 else 0 : M₀) • a = if p then a else 0 := by simp lemma Pi.single_apply_smul {ι : Type*} [DecidableEq ι] (x : A) (i j : ι) : (Pi.single i 1 : ι → M₀) j • x = (Pi.single i x : ι → A) j := by rw [single_apply, ite_smul, one_smul, zero_smul, single_apply] /-- Pullback a `MulActionWithZero` structure along an injective zero-preserving homomorphism. -/ -- See note [reducible non-instances] protected abbrev Function.Injective.mulActionWithZero (f : ZeroHom A' A) (hf : Injective f) (smul : ∀ (a : M₀) (b), f (a • b) = a • f b) : MulActionWithZero M₀ A' := { hf.mulAction f smul, hf.smulWithZero f smul with } /-- Pushforward a `MulActionWithZero` structure along a surjective zero-preserving homomorphism. -/ -- See note [reducible non-instances] protected abbrev Function.Surjective.mulActionWithZero (f : ZeroHom A A') (hf : Surjective f) (smul : ∀ (a : M₀) (b), f (a • b) = a • f b) : MulActionWithZero M₀ A' := { hf.mulAction f smul, hf.smulWithZero f smul with } variable (A) /-- Compose a `MulActionWithZero` with a `MonoidWithZeroHom`, with action `f r' • m` -/ def MulActionWithZero.compHom (f : M₀' →*₀ M₀) : MulActionWithZero M₀' A where __ := SMulWithZero.compHom A f.toZeroHom mul_smul r s m := by change f (r * s) • m = f r • f s • m; simp [mul_smul] one_smul m := by change f 1 • m = m; simp end MonoidWithZero section GroupWithZero variable [GroupWithZero G₀] [GroupWithZero G₀'] [MulActionWithZero G₀ G₀'] [SMulCommClass G₀ G₀' G₀'] [IsScalarTower G₀ G₀' G₀'] lemma smul_inv₀ (c : G₀) (x : G₀') : (c • x)⁻¹ = c⁻¹ • x⁻¹ := by obtain rfl | hc := eq_or_ne c 0 · simp only [inv_zero, zero_smul] obtain rfl | hx := eq_or_ne x 0 · simp only [inv_zero, smul_zero] · refine inv_eq_of_mul_eq_one_left ?_ rw [smul_mul_smul_comm, inv_mul_cancel₀ hc, inv_mul_cancel₀ hx, one_smul] end GroupWithZero /-- Typeclass for scalar multiplication that preserves `0` and `+` on the right. This is exactly `DistribMulAction` without the `MulAction` part. -/ @[ext] class DistribSMul (M A : Type*) [AddZeroClass A] extends SMulZeroClass M A where /-- Scalar multiplication distributes across addition -/ smul_add : ∀ (a : M) (x y : A), a • (x + y) = a • x + a • y section DistribSMul variable [AddZeroClass A] [DistribSMul M A] theorem smul_add (a : M) (b₁ b₂ : A) : a • (b₁ + b₂) = a • b₁ + a • b₂ := DistribSMul.smul_add _ _ _ /-- Pullback a distributive scalar multiplication along an injective additive monoid homomorphism. See note [reducible non-instances]. -/ protected abbrev Function.Injective.distribSMul [AddZeroClass B] [SMul M B] (f : B →+ A) (hf : Injective f) (smul : ∀ (c : M) (x), f (c • x) = c • f x) : DistribSMul M B := { hf.smulZeroClass f.toZeroHom smul with smul_add := fun c x y => hf <| by simp only [smul, map_add, smul_add] } /-- Pushforward a distributive scalar multiplication along a surjective additive monoid homomorphism. See note [reducible non-instances]. -/ protected abbrev Function.Surjective.distribSMul [AddZeroClass B] [SMul M B] (f : A →+ B) (hf : Surjective f) (smul : ∀ (c : M) (x), f (c • x) = c • f x) : DistribSMul M B := { f.toZeroHom.smulZeroClass smul with smul_add := fun c x y => by rcases hf x with ⟨x, rfl⟩ rcases hf y with ⟨y, rfl⟩ simp only [smul_add, ← smul, ← map_add] } /-- Push forward the multiplication of `R` on `M` along a compatible surjective map `f : R → S`. See also `Function.Surjective.distribMulActionLeft`. -/ abbrev Function.Surjective.distribSMulLeft {R S M : Type*} [AddZeroClass M] [DistribSMul R M] [SMul S M] (f : R → S) (hf : Function.Surjective f) (hsmul : ∀ (c) (x : M), f c • x = c • x) : DistribSMul S M := { hf.smulZeroClassLeft f hsmul with smul_add := hf.forall.mpr fun c x y => by simp only [hsmul, smul_add] } variable (A) /-- Compose a `DistribSMul` with a function, with scalar multiplication `f r' • m`. See note [reducible non-instances]. -/ abbrev DistribSMul.compFun (f : N → M) : DistribSMul N A := { SMulZeroClass.compFun A f with smul_add := fun x => smul_add (f x) } /-- Each element of the scalars defines an additive monoid homomorphism. -/ @[simps] def DistribSMul.toAddMonoidHom (x : M) : A →+ A := { SMulZeroClass.toZeroHom A x with toFun := (x • ·), map_add' := smul_add x } instance AddMonoid.nat_smulCommClass {M A : Type*} [AddMonoid A] [DistribSMul M A] : SMulCommClass ℕ M A where smul_comm n x y := ((DistribSMul.toAddMonoidHom A x).map_nsmul y n).symm -- `SMulCommClass.symm` is not registered as an instance, as it would cause a loop instance AddMonoid.nat_smulCommClass' {M A : Type*} [AddMonoid A] [DistribSMul M A] : SMulCommClass M ℕ A := .symm _ _ _ end DistribSMul /-- Typeclass for multiplicative actions on additive structures. For example, if `G` is a group (with group law written as multiplication) and `A` is an abelian group (with group law written as addition), then to give `A` a `G`-module structure (for example, to use the theory of group cohomology) is to say `[DistribMulAction G A]`. Note in that we do not use the `Module` typeclass for `G`-modules, as the `Module` typeclass is for modules over a ring rather than a group. Mathematically, `DistribMulAction G A` is equivalent to giving `A` the structure of a `ℤ[G]`-module. -/ @[ext] class DistribMulAction (M A : Type*) [Monoid M] [AddMonoid A] extends MulAction M A where /-- Multiplying `0` by a scalar gives `0` -/ smul_zero : ∀ a : M, a • (0 : A) = 0 /-- Scalar multiplication distributes across addition -/ smul_add : ∀ (a : M) (x y : A), a • (x + y) = a • x + a • y section variable [Monoid M] [AddMonoid A] [DistribMulAction M A] -- See note [lower instance priority] instance (priority := 100) DistribMulAction.toDistribSMul : DistribSMul M A := { ‹DistribMulAction M A› with } /-! We make sure that the definition of `DistribMulAction.toDistribSMul` was done correctly, and the two paths from `DistribMulAction` to `SMul` are indeed definitionally equal. -/ example : (DistribMulAction.toMulAction.toSMul : SMul M A) = DistribMulAction.toDistribSMul.toSMul := rfl /-- Pullback a distributive multiplicative action along an injective additive monoid homomorphism. See note [reducible non-instances]. -/ protected abbrev Function.Injective.distribMulAction [AddMonoid B] [SMul M B] (f : B →+ A) (hf : Injective f) (smul : ∀ (c : M) (x), f (c • x) = c • f x) : DistribMulAction M B := { hf.distribSMul f smul, hf.mulAction f smul with } /-- Pushforward a distributive multiplicative action along a surjective additive monoid homomorphism. See note [reducible non-instances]. -/ protected abbrev Function.Surjective.distribMulAction [AddMonoid B] [SMul M B] (f : A →+ B) (hf : Surjective f) (smul : ∀ (c : M) (x), f (c • x) = c • f x) : DistribMulAction M B := { hf.distribSMul f smul, hf.mulAction f smul with } variable (A) /-- Each element of the monoid defines an additive monoid homomorphism. -/ @[simps!] def DistribMulAction.toAddMonoidHom (x : M) : A →+ A := DistribSMul.toAddMonoidHom A x variable (M) /-- Each element of the monoid defines an additive monoid homomorphism. -/ @[simps] def DistribMulAction.toAddMonoidEnd : M →* AddMonoid.End A where toFun := DistribMulAction.toAddMonoidHom A map_one' := AddMonoidHom.ext <| one_smul M map_mul' x y := AddMonoidHom.ext <| mul_smul x y end section variable [AddGroup A] [DistribSMul M A] instance AddGroup.int_smulCommClass : SMulCommClass ℤ M A where smul_comm n x y := ((DistribSMul.toAddMonoidHom A x).map_zsmul y n).symm -- `SMulCommClass.symm` is not registered as an instance, as it would cause a loop instance AddGroup.int_smulCommClass' : SMulCommClass M ℤ A := SMulCommClass.symm _ _ _ @[simp] theorem smul_neg (r : M) (x : A) : r • -x = -(r • x) := eq_neg_of_add_eq_zero_left <| by rw [← smul_add, neg_add_cancel, smul_zero] theorem smul_sub (r : M) (x y : A) : r • (x - y) = r • x - r • y := by rw [sub_eq_add_neg, sub_eq_add_neg, smul_add, smul_neg] end section DistribMulAction variable [Group α] [AddMonoid β] [DistribMulAction α β] lemma smul_eq_zero_iff_eq (a : α) {x : β} : a • x = 0 ↔ x = 0 := ⟨fun h => by rw [← inv_smul_smul a x, h, smul_zero], fun h => h.symm ▸ smul_zero _⟩ lemma smul_ne_zero_iff_ne (a : α) {x : β} : a • x ≠ 0 ↔ x ≠ 0 := not_congr <| smul_eq_zero_iff_eq a end DistribMulAction section MulDistribMulAction variable [Group α] [GroupWithZero β] [MulDistribMulAction α β] instance : SMulZeroClass α β where smul_zero g := not_imp_comm.mp mul_inv_cancel₀ <| by rw [← smul_one g, ← inv_smul_eq_iff, smul_mul', inv_smul_smul, zero_mul] exact zero_ne_one /-- A version of `smul_inv'` for groups with zero. -/ @[simp] theorem smul_inv₀' (g : α) (x : β) : g • x⁻¹ = (g • x)⁻¹ := by by_cases hx : x = 0 · rw [hx, inv_zero, smul_zero, inv_zero] · apply eq_inv_of_mul_eq_one_right rw [← smul_mul', mul_inv_cancel₀ hx, smul_one] theorem smul_div₀' (g : α) (x y : β) : g • (x / y) = (g • x) / (g • y) := by rw [div_eq_mul_inv, div_eq_mul_inv, smul_mul', smul_inv₀'] end MulDistribMulAction
.lake/packages/mathlib/Mathlib/Algebra/GroupWithZero/Action/Units.lean
import Mathlib.Algebra.Group.Action.Units import Mathlib.Algebra.GroupWithZero.Action.Defs import Mathlib.Algebra.GroupWithZero.Units.Basic /-! # Multiplicative actions with zero on and by `Mˣ` This file provides the multiplicative actions with zero of a unit on a type `α`, `SMul Mˣ α`, in the presence of `SMulWithZero M α`, with the obvious definition stated in `Units.smul_def`. Additionally, a `MulDistribMulAction G M` for some group `G` satisfying some additional properties admits a `MulDistribMulAction G Mˣ` structure, again with the obvious definition stated in `Units.coe_smul`. This instance uses a primed name. ## See also * `Algebra.GroupWithZero.Action.Opposite` * `Algebra.GroupWithZero.Action.Pi` * `Algebra.GroupWithZero.Action.Prod` -/ assert_not_exists Ring variable {G₀ G M α β : Type*} namespace Units variable [GroupWithZero G₀] @[simp] lemma smul_mk0 {α : Type*} [SMul G₀ α] {g : G₀} (hg : g ≠ 0) (a : α) : mk0 g hg • a = g • a := rfl end Units section GroupWithZero variable [GroupWithZero α] [MulAction α β] {a : α} @[simp] lemma inv_smul_smul₀ (ha : a ≠ 0) (x : β) : a⁻¹ • a • x = x := inv_smul_smul (Units.mk0 a ha) x @[simp] lemma smul_inv_smul₀ (ha : a ≠ 0) (x : β) : a • a⁻¹ • x = x := smul_inv_smul (Units.mk0 a ha) x lemma inv_smul_eq_iff₀ (ha : a ≠ 0) {x y : β} : a⁻¹ • x = y ↔ x = a • y := inv_smul_eq_iff (g := Units.mk0 a ha) lemma eq_inv_smul_iff₀ (ha : a ≠ 0) {x y : β} : x = a⁻¹ • y ↔ a • x = y := eq_inv_smul_iff (g := Units.mk0 a ha) @[simp] lemma Commute.smul_right_iff₀ [Mul β] [SMulCommClass α β β] [IsScalarTower α β β] {x y : β} (ha : a ≠ 0) : Commute x (a • y) ↔ Commute x y := Commute.smul_right_iff (g := Units.mk0 a ha) @[simp] lemma Commute.smul_left_iff₀ [Mul β] [SMulCommClass α β β] [IsScalarTower α β β] {x y : β} (ha : a ≠ 0) : Commute (a • x) y ↔ Commute x y := Commute.smul_left_iff (g := Units.mk0 a ha) /-- Right scalar multiplication as an order isomorphism. -/ @[simps] def Equiv.smulRight (ha : a ≠ 0) : β ≃ β where toFun b := a • b invFun b := a⁻¹ • b left_inv := inv_smul_smul₀ ha right_inv := smul_inv_smul₀ ha end GroupWithZero namespace Units /-! ### Action of the units of `M` on a type `α` -/ instance instSMulZeroClass [Monoid M] [Zero α] [SMulZeroClass M α] : SMulZeroClass Mˣ α where smul_zero m := smul_zero (m : M) instance instDistribSMulUnits [Monoid M] [AddZeroClass α] [DistribSMul M α] : DistribSMul Mˣ α where smul_add m := smul_add (m : M) instance instDistribMulAction [Monoid M] [AddMonoid α] [DistribMulAction M α] : DistribMulAction Mˣ α where __ := instDistribSMulUnits one_smul := fun b => one_smul M b mul_smul := fun x y b => mul_smul (x : M) y b instance instMulDistribMulAction [Monoid M] [Monoid α] [MulDistribMulAction M α] : MulDistribMulAction Mˣ α where smul_mul m := smul_mul' (m : M) smul_one m := smul_one (m : M) /-! ### Action of a group `G` on units of `M` -/ /-- A stronger form of `Units.mul_action'`. -/ instance mulDistribMulAction' [Group G] [Monoid M] [MulDistribMulAction G M] [SMulCommClass G M M] [IsScalarTower G M M] : MulDistribMulAction G Mˣ := { Units.mulAction' with smul_one := fun _ => Units.ext <| smul_one _, smul_mul := fun _ _ _ => Units.ext <| smul_mul' _ _ _ } end Units section Monoid variable [Monoid G] [AddMonoid M] [DistribMulAction G M] {u : G} {x : M} @[simp] lemma IsUnit.smul_eq_zero (hu : IsUnit u) : u • x = 0 ↔ x = 0 := smul_eq_zero_iff_eq hu.unit end Monoid
.lake/packages/mathlib/Mathlib/Algebra/GroupWithZero/Action/Hom.lean
import Mathlib.Algebra.GroupWithZero.Action.Defs import Mathlib.Algebra.Group.Hom.Instances /-! # Zero-related `•` instances on group-like morphisms -/ variable {M N A B C : Type*} namespace ZeroHom section Zero variable [Zero A] [Zero B] [Zero C] instance [SMulZeroClass M B] : SMulZeroClass M (ZeroHom A B) where smul r f := { toFun a := r • f a map_zero' := by simp only [map_zero, smul_zero] } smul_zero _ := ext fun _ => smul_zero _ @[norm_cast] theorem coe_smul [SMulZeroClass M B] (m : M) (f : ZeroHom A B) : ⇑(m • f) = m • f := rfl @[simp] theorem smul_apply [SMulZeroClass M B] (m : M) (f : ZeroHom A B) (a : A) : (m • f) a = m • f a := rfl theorem smul_comp [SMulZeroClass M C] (m : M) (g : ZeroHom B C) (f : ZeroHom A B) : (m • g).comp f = m • g.comp f := rfl instance [SMulZeroClass M B] [SMulZeroClass N B] [SMulCommClass M N B] : SMulCommClass M N (ZeroHom A B) where smul_comm _ _ _ := ext fun _ => smul_comm _ _ _ instance [SMul M N] [SMulZeroClass M B] [SMulZeroClass N B] [IsScalarTower M N B] : IsScalarTower M N (ZeroHom A B) where smul_assoc _ _ _ := ext fun _ => smul_assoc _ _ _ instance [SMulZeroClass M B] [SMulZeroClass Mᵐᵒᵖ B] [IsCentralScalar M B] : IsCentralScalar M (ZeroHom A B) where op_smul_eq_smul _ _ := ext fun _ => op_smul_eq_smul _ _ instance [Zero M] [SMulWithZero M B] : SMulWithZero M (ZeroHom A B) where zero_smul _ := ext fun _ => zero_smul _ _ instance [MonoidWithZero M] [MulActionWithZero M B] : MulActionWithZero M (ZeroHom A B) where __ : SMulWithZero _ _ := inferInstance one_smul _ := ext fun _ => one_smul _ _ mul_smul _ _ _ := ext fun _ => mul_smul _ _ _ end Zero end ZeroHom namespace AddMonoidHom section variable [AddZeroClass A] [AddZeroClass B] [AddZeroClass C] instance [DistribSMul M B] : SMulZeroClass M (A →+ B) where smul r f := { toFun a := r • f a map_zero' := by simp only [map_zero, smul_zero] map_add' _ _ := by simp only [map_add, smul_add] } smul_zero _ := ext fun _ => smul_zero _ @[norm_cast] theorem coe_smul [DistribSMul M B] (m : M) (f : A →+ B) : ⇑(m • f) = m • f := rfl @[simp] theorem smul_apply [DistribSMul M B] (m : M) (f : A →+ B) (a : A) : (m • f) a = m • f a := rfl theorem smul_comp [DistribSMul M C] (m : M) (g : B →+ C) (f : A →+ B) : (m • g).comp f = m • g.comp f := rfl instance [DistribSMul M B] [DistribSMul N B] [SMulCommClass M N B] : SMulCommClass M N (A →+ B) where smul_comm _ _ _ := ext fun _ => smul_comm _ _ _ instance [SMul M N] [DistribSMul M B] [DistribSMul N B] [IsScalarTower M N B] : IsScalarTower M N (A →+ B) where smul_assoc _ _ _ := ext fun _ => smul_assoc _ _ _ instance [DistribSMul M B] [DistribSMul Mᵐᵒᵖ B] [IsCentralScalar M B] : IsCentralScalar M (A →+ B) where op_smul_eq_smul _ _ := ext fun _ => op_smul_eq_smul _ _ end variable [AddZeroClass A] [AddCommMonoid B] instance [DistribSMul M B] : DistribSMul M (A →+ B) where smul_add _ _ _ := ext fun _ => smul_add _ _ _ instance [Monoid M] [DistribMulAction M B] : DistribMulAction M (A →+ B) where __ : DistribSMul _ _ := inferInstance one_smul _ := ext fun _ => one_smul _ _ mul_smul _ _ _ := ext fun _ => mul_smul _ _ _ end AddMonoidHom
.lake/packages/mathlib/Mathlib/Algebra/GroupWithZero/Action/Pointwise/Finset.lean
import Mathlib.Algebra.Group.Action.Pointwise.Finset import Mathlib.Algebra.GroupWithZero.InjSurj import Mathlib.Algebra.GroupWithZero.Action.Defs import Mathlib.Algebra.GroupWithZero.Action.Pointwise.Set import Mathlib.Algebra.GroupWithZero.Pointwise.Finset /-! # Pointwise operations of finsets in a group with zero This file proves properties of pointwise operations of finsets in a group with zero. -/ assert_not_exists Ring open scoped Pointwise namespace Finset variable {α β : Type*} [DecidableEq β] /-- If scalar multiplication by elements of `α` sends `(0 : β)` to zero, then the same is true for `(0 : Finset β)`. -/ protected def smulZeroClass [Zero β] [SMulZeroClass α β] : SMulZeroClass α (Finset β) := coe_injective.smulZeroClass ⟨_, coe_zero⟩ coe_smul_finset /-- If the scalar multiplication `(· • ·) : α → β → β` is distributive, then so is `(· • ·) : α → Finset β → Finset β`. -/ protected noncomputable def distribSMul [AddZeroClass β] [DistribSMul α β] : DistribSMul α (Finset β) := coe_injective.distribSMul coeAddMonoidHom coe_smul_finset /-- A distributive multiplicative action of a monoid on an additive monoid `β` gives a distributive multiplicative action on `Finset β`. -/ protected noncomputable def distribMulAction [Monoid α] [AddMonoid β] [DistribMulAction α β] : DistribMulAction α (Finset β) := coe_injective.distribMulAction coeAddMonoidHom coe_smul_finset /-- A multiplicative action of a monoid on a monoid `β` gives a multiplicative action on `Set β`. -/ protected noncomputable def mulDistribMulAction [Monoid α] [Monoid β] [MulDistribMulAction α β] : MulDistribMulAction α (Finset β) := coe_injective.mulDistribMulAction coeMonoidHom coe_smul_finset scoped[Pointwise] attribute [instance] Finset.smulZeroClass Finset.distribSMul Finset.distribMulAction Finset.mulDistribMulAction instance [DecidableEq α] [Zero α] [Mul α] [NoZeroDivisors α] : NoZeroDivisors (Finset α) := Function.Injective.noZeroDivisors _ coe_injective coe_zero coe_mul instance noZeroSMulDivisors [Zero α] [Zero β] [SMul α β] [NoZeroSMulDivisors α β] : NoZeroSMulDivisors (Finset α) (Finset β) where eq_zero_or_eq_zero_of_smul_eq_zero {s t} := by exact_mod_cast eq_zero_or_eq_zero_of_smul_eq_zero (c := (s : Set α)) (x := (t : Set β)) instance noZeroSMulDivisors_finset [Zero α] [Zero β] [SMul α β] [NoZeroSMulDivisors α β] : NoZeroSMulDivisors α (Finset β) := Function.Injective.noZeroSMulDivisors _ coe_injective coe_zero coe_smul_finset section SMulZeroClass variable [Zero β] [SMulZeroClass α β] {s : Finset α} {t : Finset β} {a : α} lemma smul_zero_subset (s : Finset α) : s • (0 : Finset β) ⊆ 0 := by simp [subset_iff, mem_smul] lemma Nonempty.smul_zero (hs : s.Nonempty) : s • (0 : Finset β) = 0 := s.smul_zero_subset.antisymm <| by simpa [mem_smul] using hs lemma zero_mem_smul_finset (h : (0 : β) ∈ t) : (0 : β) ∈ a • t := mem_smul_finset.2 ⟨0, h, smul_zero _⟩ variable [Zero α] [NoZeroSMulDivisors α β] lemma zero_mem_smul_finset_iff (ha : a ≠ 0) : (0 : β) ∈ a • t ↔ (0 : β) ∈ t := by rw [← mem_coe, coe_smul_finset, Set.zero_mem_smul_set_iff ha, mem_coe] end SMulZeroClass section SMulWithZero variable [Zero α] [Zero β] [SMulWithZero α β] {s : Finset α} {t : Finset β} /-! Note that we have neither `SMulWithZero α (Finset β)` nor `SMulWithZero (Finset α) (Finset β)` because `0 • ∅ ≠ 0`. -/ lemma zero_smul_subset (t : Finset β) : (0 : Finset α) • t ⊆ 0 := by simp [subset_iff, mem_smul] lemma Nonempty.zero_smul (ht : t.Nonempty) : (0 : Finset α) • t = 0 := t.zero_smul_subset.antisymm <| by simpa [mem_smul] using ht /-- A nonempty set is scaled by zero to the singleton set containing zero. -/ @[simp] lemma zero_smul_finset {s : Finset β} (h : s.Nonempty) : (0 : α) • s = (0 : Finset β) := coe_injective <| by simpa using @Set.zero_smul_set α _ _ _ _ _ h lemma zero_smul_finset_subset (s : Finset β) : (0 : α) • s ⊆ 0 := image_subset_iff.2 fun x _ ↦ mem_zero.2 <| zero_smul α x variable [NoZeroSMulDivisors α β] lemma zero_mem_smul_iff : (0 : β) ∈ s • t ↔ (0 : α) ∈ s ∧ t.Nonempty ∨ (0 : β) ∈ t ∧ s.Nonempty := by rw [← mem_coe, coe_smul, Set.zero_mem_smul_iff]; rfl end SMulWithZero section GroupWithZero variable [GroupWithZero α] section MulAction variable [MulAction α β] {s t : Finset β} {a : α} {b : β} @[simp] lemma smul_mem_smul_finset_iff₀ (ha : a ≠ 0) : a • b ∈ a • s ↔ b ∈ s := smul_mem_smul_finset_iff (Units.mk0 a ha) lemma inv_smul_mem_iff₀ (ha : a ≠ 0) : a⁻¹ • b ∈ s ↔ b ∈ a • s := show _ ↔ _ ∈ Units.mk0 a ha • _ from inv_smul_mem_iff lemma mem_inv_smul_finset_iff₀ (ha : a ≠ 0) : b ∈ a⁻¹ • s ↔ a • b ∈ s := show _ ∈ (Units.mk0 a ha)⁻¹ • _ ↔ _ from mem_inv_smul_finset_iff @[simp] lemma smul_finset_subset_smul_finset_iff₀ (ha : a ≠ 0) : a • s ⊆ a • t ↔ s ⊆ t := show Units.mk0 a ha • _ ⊆ _ ↔ _ from smul_finset_subset_smul_finset_iff lemma smul_finset_subset_iff₀ (ha : a ≠ 0) : a • s ⊆ t ↔ s ⊆ a⁻¹ • t := show Units.mk0 a ha • _ ⊆ _ ↔ _ from smul_finset_subset_iff lemma subset_smul_finset_iff₀ (ha : a ≠ 0) : s ⊆ a • t ↔ a⁻¹ • s ⊆ t := show _ ⊆ Units.mk0 a ha • _ ↔ _ from subset_smul_finset_iff lemma smul_finset_inter₀ (ha : a ≠ 0) : a • (s ∩ t) = a • s ∩ a • t := image_inter _ _ <| MulAction.injective₀ ha lemma smul_finset_sdiff₀ (ha : a ≠ 0) : a • (s \ t) = a • s \ a • t := image_sdiff _ _ <| MulAction.injective₀ ha open scoped symmDiff in lemma smul_finset_symmDiff₀ (ha : a ≠ 0) : a • s ∆ t = (a • s) ∆ (a • t) := image_symmDiff _ _ <| MulAction.injective₀ ha lemma smul_finset_univ₀ [Fintype β] (ha : a ≠ 0) : a • (univ : Finset β) = univ := coe_injective <| by push_cast; exact Set.smul_set_univ₀ ha lemma smul_univ₀ [Fintype β] {s : Finset α} (hs : ¬s ⊆ 0) : s • (univ : Finset β) = univ := coe_injective <| by rw [← coe_subset] at hs push_cast at hs ⊢ exact Set.smul_univ₀ hs lemma smul_univ₀' [Fintype β] {s : Finset α} (hs : s.Nontrivial) : s • (univ : Finset β) = univ := coe_injective <| by push_cast; exact Set.smul_univ₀' hs end MulAction variable [DecidableEq α] {s : Finset α} open scoped RightActions @[simp] lemma inv_smul_finset_distrib₀ (a : α) (s : Finset α) : (a • s)⁻¹ = s⁻¹ <• a⁻¹ := by obtain rfl | ha := eq_or_ne a 0 · obtain rfl | hs := s.eq_empty_or_nonempty <;> simp [*] -- was `simp` and very slow (https://github.com/leanprover-community/mathlib4/issues/19751) · ext; simp only [mem_inv', ne_eq, not_false_eq_true, ← inv_smul_mem_iff₀, smul_eq_mul, MulOpposite.op_inv, inv_eq_zero, MulOpposite.op_eq_zero_iff, inv_inv, MulOpposite.smul_eq_mul_unop, MulOpposite.unop_op, mul_inv_rev, ha] lemma inv_op_smul_finset_distrib₀ (a : α) (s : Finset α) : (s <• a)⁻¹ = a⁻¹ • s⁻¹ := by obtain rfl | ha := eq_or_ne a 0 · obtain rfl | hs := s.eq_empty_or_nonempty <;> simp [*] -- was `simp` and very slow (https://github.com/leanprover-community/mathlib4/issues/19751) · ext; simp only [mem_inv', ne_eq, MulOpposite.op_eq_zero_iff, not_false_eq_true, ← inv_smul_mem_iff₀, MulOpposite.smul_eq_mul_unop, MulOpposite.unop_inv, MulOpposite.unop_op, inv_eq_zero, inv_inv, smul_eq_mul, mul_inv_rev, ha] end GroupWithZero section Monoid variable [Monoid α] [AddGroup β] [DistribMulAction α β] @[simp] lemma smul_finset_neg (a : α) (t : Finset β) : a • -t = -(a • t) := by simp only [← image_smul, ← image_neg_eq_neg, Function.comp_def, image_image, smul_neg] @[simp] protected lemma smul_neg (s : Finset α) (t : Finset β) : s • -t = -(s • t) := by simp_rw [← image_neg_eq_neg]; exact image_image₂_right_comm smul_neg end Monoid end Finset
.lake/packages/mathlib/Mathlib/Algebra/GroupWithZero/Action/Pointwise/Set.lean
import Mathlib.Algebra.Group.Action.Pointwise.Set.Basic import Mathlib.Algebra.GroupWithZero.Action.Basic import Mathlib.Algebra.GroupWithZero.Action.Units import Mathlib.Algebra.GroupWithZero.Pointwise.Set.Basic import Mathlib.Algebra.NoZeroSMulDivisors.Defs /-! # Pointwise operations of sets in a group with zero This file proves properties of pointwise operations of sets in a group with zero. ## Tags set multiplication, set addition, pointwise addition, pointwise multiplication, pointwise subtraction -/ assert_not_exists IsOrderedMonoid Ring open Function open scoped Pointwise variable {α β : Type*} namespace Set lemma smul_set_pi₀ {M ι : Type*} {α : ι → Type*} [GroupWithZero M] [∀ i, MulAction M (α i)] {c : M} (hc : c ≠ 0) (I : Set ι) (s : ∀ i, Set (α i)) : c • I.pi s = I.pi (c • s) := smul_set_pi_of_isUnit (.mk0 _ hc) I s /-- A slightly more general version of `Set.smul_set_pi₀`. -/ lemma smul_set_pi₀' {M ι : Type*} {α : ι → Type*} [GroupWithZero M] [∀ i, MulAction M (α i)] {c : M} {I : Set ι} (h : c ≠ 0 ∨ I = univ) (s : ∀ i, Set (α i)) : c • I.pi s = I.pi (c • s) := h.elim (fun hc ↦ smul_set_pi_of_isUnit (.mk0 _ hc) I s) (fun hI ↦ hI ▸ smul_set_univ_pi ..) section SMulZeroClass variable [Zero β] [SMulZeroClass α β] {s : Set α} {t : Set β} {a : α} /-- If scalar multiplication by elements of `α` sends `(0 : β)` to zero, then the same is true for `(0 : Set β)`. -/ protected def smulZeroClassSet [Zero β] [SMulZeroClass α β] : SMulZeroClass α (Set β) where smul_zero _ := image_singleton.trans <| by rw [smul_zero, singleton_zero] scoped[Pointwise] attribute [instance] Set.smulZeroClassSet lemma smul_zero_subset (s : Set α) : s • (0 : Set β) ⊆ 0 := by simp [subset_def, mem_smul] lemma Nonempty.smul_zero (hs : s.Nonempty) : s • (0 : Set β) = 0 := s.smul_zero_subset.antisymm <| by simpa [mem_smul] using hs lemma zero_mem_smul_set (h : (0 : β) ∈ t) : (0 : β) ∈ a • t := ⟨0, h, smul_zero _⟩ variable [Zero α] [NoZeroSMulDivisors α β] lemma zero_mem_smul_set_iff (ha : a ≠ 0) : (0 : β) ∈ a • t ↔ (0 : β) ∈ t := by refine ⟨?_, zero_mem_smul_set⟩ rintro ⟨b, hb, h⟩ rwa [(eq_zero_or_eq_zero_of_smul_eq_zero h).resolve_left ha] at hb end SMulZeroClass section SMulWithZero variable [Zero α] [Zero β] [SMulWithZero α β] {s : Set α} {t : Set β} /-! Note that we have neither `SMulWithZero α (Set β)` nor `SMulWithZero (Set α) (Set β)` because `0 * ∅ ≠ 0`. -/ lemma zero_smul_subset (t : Set β) : (0 : Set α) • t ⊆ 0 := by simp [subset_def, mem_smul] lemma Nonempty.zero_smul (ht : t.Nonempty) : (0 : Set α) • t = 0 := t.zero_smul_subset.antisymm <| by simpa [mem_smul] using ht /-- A nonempty set is scaled by zero to the singleton set containing 0. -/ @[simp] lemma zero_smul_set {s : Set β} (h : s.Nonempty) : (0 : α) • s = (0 : Set β) := by simp only [← image_smul, zero_smul, h.image_const, singleton_zero] lemma zero_smul_set_subset (s : Set β) : (0 : α) • s ⊆ 0 := image_subset_iff.2 fun x _ ↦ zero_smul α x lemma subsingleton_zero_smul_set (s : Set β) : ((0 : α) • s).Subsingleton := subsingleton_singleton.anti <| zero_smul_set_subset s variable [NoZeroSMulDivisors α β] {a : α} lemma zero_mem_smul_iff : 0 ∈ s • t ↔ 0 ∈ s ∧ t.Nonempty ∨ 0 ∈ t ∧ s.Nonempty where mp := by rintro ⟨a, ha, b, hb, h⟩ obtain rfl | rfl := eq_zero_or_eq_zero_of_smul_eq_zero h · exact Or.inl ⟨ha, b, hb⟩ · exact Or.inr ⟨hb, a, ha⟩ mpr := by rintro (⟨hs, b, hb⟩ | ⟨ht, a, ha⟩) · exact ⟨0, hs, b, hb, zero_smul _ _⟩ · exact ⟨a, ha, 0, ht, smul_zero _⟩ end SMulWithZero /-- If the scalar multiplication `(· • ·) : α → β → β` is distributive, then so is `(· • ·) : α → Set β → Set β`. -/ protected noncomputable def distribSMulSet [AddZeroClass β] [DistribSMul α β] : DistribSMul α (Set β) where smul_add _ _ _ := image_image2_distrib <| smul_add _ scoped[Pointwise] attribute [instance] Set.distribSMulSet /-- A distributive multiplicative action of a monoid on an additive monoid `β` gives a distributive multiplicative action on `Set β`. -/ protected noncomputable def distribMulActionSet [Monoid α] [AddMonoid β] [DistribMulAction α β] : DistribMulAction α (Set β) where smul_add := smul_add smul_zero := smul_zero /-- A multiplicative action of a monoid on a monoid `β` gives a multiplicative action on `Set β`. -/ protected noncomputable def mulDistribMulActionSet [Monoid α] [Monoid β] [MulDistribMulAction α β] : MulDistribMulAction α (Set β) where smul_mul _ _ _ := image_image2_distrib <| smul_mul' _ smul_one _ := image_singleton.trans <| by rw [smul_one, singleton_one] scoped[Pointwise] attribute [instance] Set.distribMulActionSet Set.mulDistribMulActionSet instance instNoZeroSMulDivisors [Zero α] [Zero β] [SMul α β] [NoZeroSMulDivisors α β] : NoZeroSMulDivisors (Set α) (Set β) where eq_zero_or_eq_zero_of_smul_eq_zero {s t} h := by by_contra! H have hst : (s • t).Nonempty := h.symm.subst zero_nonempty rw [Ne, ← hst.of_smul_left.subset_zero_iff, Ne, ← hst.of_smul_right.subset_zero_iff] at H simp only [not_subset, mem_zero] at H obtain ⟨⟨a, hs, ha⟩, b, ht, hb⟩ := H exact (eq_zero_or_eq_zero_of_smul_eq_zero <| h.subset <| smul_mem_smul hs ht).elim ha hb instance noZeroSMulDivisors_set [Zero α] [Zero β] [SMul α β] [NoZeroSMulDivisors α β] : NoZeroSMulDivisors α (Set β) where eq_zero_or_eq_zero_of_smul_eq_zero {a s} h := by by_contra! H have hst : (a • s).Nonempty := h.symm.subst zero_nonempty rw [Ne, Ne, ← hst.of_image.subset_zero_iff, not_subset] at H obtain ⟨ha, b, ht, hb⟩ := H exact (eq_zero_or_eq_zero_of_smul_eq_zero <| h.subset <| smul_mem_smul_set ht).elim ha hb instance [Zero α] [Mul α] [NoZeroDivisors α] : NoZeroDivisors (Set α) where eq_zero_or_eq_zero_of_mul_eq_zero h := eq_zero_or_eq_zero_of_smul_eq_zero h section GroupWithZero variable [GroupWithZero α] [MulAction α β] {s t : Set β} {a : α} @[simp] lemma smul_mem_smul_set_iff₀ (ha : a ≠ 0) (A : Set β) (x : β) : a • x ∈ a • A ↔ x ∈ A := show Units.mk0 a ha • _ ∈ _ ↔ _ from smul_mem_smul_set_iff lemma mem_smul_set_iff_inv_smul_mem₀ (ha : a ≠ 0) (A : Set β) (x : β) : x ∈ a • A ↔ a⁻¹ • x ∈ A := show _ ∈ Units.mk0 a ha • _ ↔ _ from mem_smul_set_iff_inv_smul_mem lemma mem_inv_smul_set_iff₀ (ha : a ≠ 0) (A : Set β) (x : β) : x ∈ a⁻¹ • A ↔ a • x ∈ A := show _ ∈ (Units.mk0 a ha)⁻¹ • _ ↔ _ from mem_inv_smul_set_iff lemma preimage_smul₀ (ha : a ≠ 0) (t : Set β) : (fun x ↦ a • x) ⁻¹' t = a⁻¹ • t := preimage_smul (Units.mk0 a ha) t lemma preimage_smul_inv₀ (ha : a ≠ 0) (t : Set β) : (fun x ↦ a⁻¹ • x) ⁻¹' t = a • t := preimage_smul (Units.mk0 a ha)⁻¹ t @[simp] lemma smul_set_subset_smul_set_iff₀ (ha : a ≠ 0) {A B : Set β} : a • A ⊆ a • B ↔ A ⊆ B := show Units.mk0 a ha • _ ⊆ _ ↔ _ from smul_set_subset_smul_set_iff lemma smul_set_subset_iff₀ (ha : a ≠ 0) {A B : Set β} : a • A ⊆ B ↔ A ⊆ a⁻¹ • B := show Units.mk0 a ha • _ ⊆ _ ↔ _ from smul_set_subset_iff_subset_inv_smul_set lemma subset_smul_set_iff₀ (ha : a ≠ 0) {A B : Set β} : A ⊆ a • B ↔ a⁻¹ • A ⊆ B := show _ ⊆ Units.mk0 a ha • _ ↔ _ from subset_smul_set_iff lemma smul_set_inter₀ (ha : a ≠ 0) : a • (s ∩ t) = a • s ∩ a • t := show Units.mk0 a ha • _ = _ from smul_set_inter lemma smul_set_sdiff₀ (ha : a ≠ 0) : a • (s \ t) = a • s \ a • t := image_diff (MulAction.injective₀ ha) _ _ open scoped symmDiff in lemma smul_set_symmDiff₀ (ha : a ≠ 0) : a • s ∆ t = (a • s) ∆ (a • t) := image_symmDiff (MulAction.injective₀ ha) _ _ lemma smul_set_univ₀ (ha : a ≠ 0) : a • (univ : Set β) = univ := image_univ_of_surjective <| MulAction.surjective₀ ha lemma smul_univ₀ {s : Set α} (hs : ¬s ⊆ 0) : s • (univ : Set β) = univ := let ⟨a, ha, ha₀⟩ := not_subset.1 hs eq_univ_of_forall fun b ↦ ⟨a, ha, a⁻¹ • b, trivial, smul_inv_smul₀ ha₀ _⟩ lemma smul_univ₀' {s : Set α} (hs : s.Nontrivial) : s • (univ : Set β) = univ := smul_univ₀ hs.not_subset_singleton open scoped RightActions in @[simp] lemma inv_smul_set_distrib₀ (a : α) (s : Set α) : (a • s)⁻¹ = s⁻¹ <• a⁻¹ := by obtain rfl | ha := eq_or_ne a 0 · obtain rfl | hs := s.eq_empty_or_nonempty <;> simp [*] · ext; simp [mem_smul_set_iff_inv_smul_mem₀, *] open scoped RightActions in @[simp] lemma inv_op_smul_set_distrib₀ (a : α) (s : Set α) : (s <• a)⁻¹ = a⁻¹ • s⁻¹ := by obtain rfl | ha := eq_or_ne a 0 · obtain rfl | hs := s.eq_empty_or_nonempty <;> simp [*] · ext; simp [mem_smul_set_iff_inv_smul_mem₀, *] end GroupWithZero end Set
.lake/packages/mathlib/Mathlib/Algebra/GroupWithZero/Pointwise/Finset.lean
import Mathlib.Algebra.GroupWithZero.Basic import Mathlib.Algebra.Group.Pointwise.Finset.Basic /-! # Pointwise operations of finsets in a group with zero This file proves properties of pointwise operations of finsets in a group with zero. -/ assert_not_exists MulAction Ring open scoped Pointwise namespace Finset variable {α : Type*} section Mul variable [Mul α] [Zero α] [DecidableEq α] {s t : Finset α} {a : α} lemma card_le_card_mul_left₀ [IsLeftCancelMulZero α] (has : a ∈ s) (ha : a ≠ 0) : #t ≤ #(s * t) := card_le_card_mul_left_of_injective has (mul_right_injective₀ ha) lemma card_le_card_mul_right₀ [IsRightCancelMulZero α] (hat : a ∈ t) (ha : a ≠ 0) : #s ≤ #(s * t) := card_le_card_mul_right_of_injective hat (mul_left_injective₀ ha) lemma card_le_card_mul_self₀ [IsLeftCancelMulZero α] : #s ≤ #(s * s) := by obtain hs | hs := (s.erase 0).eq_empty_or_nonempty · rw [erase_eq_empty_iff] at hs obtain rfl | rfl := hs <;> simp obtain ⟨a, ha⟩ := hs simp only [mem_erase, ne_eq] at ha exact card_le_card_mul_left₀ ha.2 ha.1 end Mul section MulZeroClass variable [DecidableEq α] [MulZeroClass α] {s : Finset α} /-! Note that `Finset` is not a `MulZeroClass` because `0 * ∅ ≠ 0`. -/ lemma mul_zero_subset (s : Finset α) : s * 0 ⊆ 0 := by simp [subset_iff, mem_mul] lemma zero_mul_subset (s : Finset α) : 0 * s ⊆ 0 := by simp [subset_iff, mem_mul] lemma Nonempty.mul_zero (hs : s.Nonempty) : s * 0 = 0 := s.mul_zero_subset.antisymm <| by simpa [mem_mul] using hs lemma Nonempty.zero_mul (hs : s.Nonempty) : 0 * s = 0 := s.zero_mul_subset.antisymm <| by simpa [mem_mul] using hs end MulZeroClass section GroupWithZero variable [GroupWithZero α] [DecidableEq α] {s : Finset α} lemma div_zero_subset (s : Finset α) : s / 0 ⊆ 0 := by simp [subset_iff, mem_div] lemma zero_div_subset (s : Finset α) : 0 / s ⊆ 0 := by simp [subset_iff, mem_div] lemma Nonempty.div_zero (hs : s.Nonempty) : s / 0 = 0 := s.div_zero_subset.antisymm <| by simpa [mem_div] using hs lemma Nonempty.zero_div (hs : s.Nonempty) : 0 / s = 0 := s.zero_div_subset.antisymm <| by simpa [mem_div] using hs @[simp] protected lemma inv_zero : (0 : Finset α)⁻¹ = 0 := by ext; simp end GroupWithZero end Finset
.lake/packages/mathlib/Mathlib/Algebra/GroupWithZero/Pointwise/Set/Card.lean
import Mathlib.Algebra.Group.Pointwise.Set.Scalar import Mathlib.Algebra.GroupWithZero.Action.Basic import Mathlib.SetTheory.Cardinal.Finite /-! # Cardinality of sets under pointwise group with zero operations -/ assert_not_exists Field open scoped Cardinal Pointwise variable {G₀ M₀ : Type*} namespace Set variable [GroupWithZero G₀] [Zero M₀] [MulActionWithZero G₀ M₀] {a : G₀} lemma _root_.Cardinal.mk_smul_set₀ (ha : a ≠ 0) (s : Set M₀) : #↥(a • s) = #s := Cardinal.mk_image_eq_of_injOn _ _ (MulAction.injective₀ ha).injOn lemma natCard_smul_set₀ (ha : a ≠ 0) (s : Set M₀) : Nat.card ↥(a • s) = Nat.card s := Nat.card_image_of_injective (MulAction.injective₀ ha) _ end Set
.lake/packages/mathlib/Mathlib/Algebra/GroupWithZero/Pointwise/Set/Basic.lean
import Mathlib.Algebra.GroupWithZero.Basic import Mathlib.Algebra.Group.Pointwise.Set.Basic /-! # Pointwise operations of sets in a group with zero This file proves properties of pointwise operations of sets in a group with zero. ## Tags set multiplication, set addition, pointwise addition, pointwise multiplication, pointwise subtraction -/ assert_not_exists MulAction IsOrderedMonoid Ring open Function open scoped Pointwise variable {α : Type*} namespace Set section MulZeroClass variable [MulZeroClass α] {s : Set α} /-! Note that `Set` is not a `MulZeroClass` because `0 * ∅ ≠ 0`. -/ lemma mul_zero_subset (s : Set α) : s * 0 ⊆ 0 := by simp [subset_def, mem_mul] lemma zero_mul_subset (s : Set α) : 0 * s ⊆ 0 := by simp [subset_def, mem_mul] lemma Nonempty.mul_zero (hs : s.Nonempty) : s * 0 = 0 := s.mul_zero_subset.antisymm <| by simpa [mem_mul] using hs lemma Nonempty.zero_mul (hs : s.Nonempty) : 0 * s = 0 := s.zero_mul_subset.antisymm <| by simpa [mem_mul] using hs end MulZeroClass section GroupWithZero variable [GroupWithZero α] {s : Set α} lemma div_zero_subset (s : Set α) : s / 0 ⊆ 0 := by simp [subset_def, mem_div] lemma zero_div_subset (s : Set α) : 0 / s ⊆ 0 := by simp [subset_def, mem_div] lemma Nonempty.div_zero (hs : s.Nonempty) : s / 0 = 0 := s.div_zero_subset.antisymm <| by simpa [mem_div] using hs lemma Nonempty.zero_div (hs : s.Nonempty) : 0 / s = 0 := s.zero_div_subset.antisymm <| by simpa [mem_div] using hs @[simp] protected lemma inv_zero : (0 : Set α)⁻¹ = 0 := by ext; simp end GroupWithZero end Set
.lake/packages/mathlib/Mathlib/Algebra/Field/Opposite.lean
import Mathlib.Algebra.Field.Defs import Mathlib.Algebra.Ring.Opposite import Mathlib.Data.Int.Cast.Lemmas /-! # Field structure on the multiplicative/additive opposite -/ assert_not_exists RelIso variable {α : Type*} namespace MulOpposite @[to_additive] instance instNNRatCast [NNRatCast α] : NNRatCast αᵐᵒᵖ := ⟨fun q ↦ op q⟩ @[to_additive] instance instRatCast [RatCast α] : RatCast αᵐᵒᵖ := ⟨fun q ↦ op q⟩ @[to_additive (attr := simp, norm_cast)] lemma op_nnratCast [NNRatCast α] (q : ℚ≥0) : op (q : α) = q := rfl @[to_additive (attr := simp, norm_cast)] lemma unop_nnratCast [NNRatCast α] (q : ℚ≥0) : unop (q : αᵐᵒᵖ) = q := rfl @[to_additive (attr := simp, norm_cast)] lemma op_ratCast [RatCast α] (q : ℚ) : op (q : α) = q := rfl @[to_additive (attr := simp, norm_cast)] lemma unop_ratCast [RatCast α] (q : ℚ) : unop (q : αᵐᵒᵖ) = q := rfl instance instDivisionSemiring [DivisionSemiring α] : DivisionSemiring αᵐᵒᵖ where __ := instSemiring __ := instGroupWithZero nnqsmul := _ nnqsmul_def := fun _ _ => rfl nnratCast_def q := unop_injective <| by rw [unop_nnratCast, unop_div, unop_natCast, unop_natCast, NNRat.cast_def, div_eq_mul_inv, Nat.cast_comm] instance instDivisionRing [DivisionRing α] : DivisionRing αᵐᵒᵖ where __ := instRing __ := instDivisionSemiring qsmul := _ qsmul_def := fun _ _ => rfl ratCast_def q := unop_injective <| by rw [unop_ratCast, Rat.cast_def, unop_div, unop_natCast, unop_intCast, Int.commute_cast, div_eq_mul_inv] instance instSemifield [Semifield α] : Semifield αᵐᵒᵖ where __ := instCommSemiring __ := instDivisionSemiring instance instField [Field α] : Field αᵐᵒᵖ where __ := instCommRing __ := instDivisionRing end MulOpposite namespace AddOpposite instance instDivisionSemiring [DivisionSemiring α] : DivisionSemiring αᵃᵒᵖ where __ := instSemiring __ := instGroupWithZero nnqsmul := _ nnqsmul_def := fun _ _ => rfl nnratCast_def q := unop_injective <| by rw [unop_nnratCast, unop_div, unop_natCast, unop_natCast, NNRat.cast_def, div_eq_mul_inv] instance instDivisionRing [DivisionRing α] : DivisionRing αᵃᵒᵖ where __ := instRing __ := instDivisionSemiring qsmul := _ qsmul_def := fun _ _ => rfl ratCast_def q := unop_injective <| by rw [unop_ratCast, Rat.cast_def, unop_div, unop_natCast, unop_intCast, div_eq_mul_inv] instance instSemifield [Semifield α] : Semifield αᵃᵒᵖ where __ := instCommSemiring __ := instDivisionSemiring instance instField [Field α] : Field αᵃᵒᵖ where __ := instCommRing __ := instDivisionRing end AddOpposite
.lake/packages/mathlib/Mathlib/Algebra/Field/Rat.lean
import Mathlib.Algebra.Field.Defs import Mathlib.Data.NNRat.Defs /-! # The rational numbers form a field This file contains the field instance on the rational numbers. See note [foundational algebra order theory]. ## Tags rat, rationals, field, ℚ, numerator, denominator, num, denom -/ namespace Rat instance instField : Field ℚ where __ := commRing __ := commGroupWithZero nnqsmul := _ nnqsmul_def := fun _ _ => rfl qsmul := _ qsmul_def := fun _ _ => rfl nnratCast_def q := by rw [← NNRat.den_coe, ← Int.cast_natCast q.num, ← NNRat.num_coe]; exact(num_div_den _).symm ratCast_def _ := (num_div_den _).symm /-! ### Extra instances to short-circuit type class resolution These also prevent non-computable instances being used to construct these instances non-computably. -/ instance instDivisionRing : DivisionRing ℚ := inferInstance protected lemma inv_nonneg {a : ℚ} (ha : 0 ≤ a) : 0 ≤ a⁻¹ := by rw [inv_def] exact divInt_nonneg (Int.natCast_nonneg a.den) (num_nonneg.mpr ha) protected lemma div_nonneg {a b : ℚ} (ha : 0 ≤ a) (hb : 0 ≤ b) : 0 ≤ a / b := mul_nonneg ha (Rat.inv_nonneg hb) end Rat namespace NNRat instance instInv : Inv ℚ≥0 where inv x := ⟨x⁻¹, Rat.inv_nonneg x.2⟩ instance instDiv : Div ℚ≥0 where div x y := ⟨x / y, Rat.div_nonneg x.2 y.2⟩ instance instZPow : Pow ℚ≥0 ℤ where pow x n := ⟨x ^ n, Rat.zpow_nonneg x.2⟩ @[simp, norm_cast] lemma coe_inv (q : ℚ≥0) : ((q⁻¹ : ℚ≥0) : ℚ) = (q : ℚ)⁻¹ := rfl @[simp, norm_cast] lemma coe_div (p q : ℚ≥0) : ((p / q : ℚ≥0) : ℚ) = p / q := rfl @[simp, norm_cast] lemma coe_zpow (p : ℚ≥0) (n : ℤ) : ((p ^ n : ℚ≥0) : ℚ) = p ^ n := rfl lemma inv_def (q : ℚ≥0) : q⁻¹ = divNat q.den q.num := by ext; simp [Rat.inv_def, num_coe, den_coe] lemma div_def (p q : ℚ≥0) : p / q = divNat (p.num * q.den) (p.den * q.num) := by ext; simp [Rat.div_def', num_coe, den_coe] lemma num_inv_of_ne_zero {q : ℚ≥0} (hq : q ≠ 0) : q⁻¹.num = q.den := by rw [inv_def, divNat, num, coe_mk, Rat.divInt_ofNat, ← Rat.mk_eq_mkRat _ _ (num_ne_zero.mpr hq), Int.natAbs_natCast] simpa using q.coprime_num_den.symm lemma den_inv_of_ne_zero {q : ℚ≥0} (hq : q ≠ 0) : q⁻¹.den = q.num := by rw [inv_def, divNat, den, coe_mk, Rat.divInt_ofNat, ← Rat.mk_eq_mkRat _ _ (num_ne_zero.mpr hq)] simpa using q.coprime_num_den.symm @[simp] lemma num_div_den (q : ℚ≥0) : (q.num : ℚ≥0) / q.den = q := by ext1 rw [coe_div, coe_natCast, coe_natCast, num, ← Int.cast_natCast] exact (cast_def _).symm instance instSemifield : Semifield ℚ≥0 where inv_zero := by ext; simp mul_inv_cancel q h := by ext; simp [h] nnratCast_def q := q.num_div_den.symm nnqsmul q a := q * a nnqsmul_def q a := rfl zpow n a := a ^ n zpow_zero' a := by ext; apply Field.zpow_zero' zpow_succ' n a := by ext; apply Field.zpow_succ' zpow_neg' n a := by ext; apply Field.zpow_neg' end NNRat
.lake/packages/mathlib/Mathlib/Algebra/Field/TransferInstance.lean
import Mathlib.Algebra.Field.Basic import Mathlib.Algebra.Ring.TransferInstance /-! # Transfer algebraic structures across `Equiv`s This continues the pattern set in `Mathlib/Algebra/Group/TransferInstance.lean`. -/ assert_not_exists Module namespace Equiv variable {α β : Type*} (e : α ≃ β) /-- Transfer `NNRatCast` across an `Equiv` -/ protected abbrev nnratCast [NNRatCast β] : NNRatCast α where nnratCast q := e.symm q /-- Transfer `RatCast` across an `Equiv` -/ protected abbrev ratCast [RatCast β] : RatCast α where ratCast n := e.symm n /-- Transfer `DivisionRing` across an `Equiv` -/ protected abbrev divisionRing [DivisionRing β] : DivisionRing α := by let add_group_with_one := e.addGroupWithOne let inv := e.Inv let div := e.div let mul := e.mul let npow := e.pow ℕ let zpow := e.pow ℤ let nnratCast := e.nnratCast let ratCast := e.ratCast let nnqsmul := e.smul ℚ≥0 let qsmul := e.smul ℚ apply e.injective.divisionRing _ <;> intros <;> exact e.apply_symm_apply _ /-- Transfer `Field` across an `Equiv` -/ protected abbrev field [Field β] : Field α := by let add_group_with_one := e.addGroupWithOne let neg := e.Neg let inv := e.Inv let div := e.div let mul := e.mul let npow := e.pow ℕ let zpow := e.pow ℤ let nnratCast := e.nnratCast let ratCast := e.ratCast let nnqsmul := e.smul ℚ≥0 let qsmul := e.smul ℚ apply e.injective.field _ <;> intros <;> exact e.apply_symm_apply _ end Equiv
.lake/packages/mathlib/Mathlib/Algebra/Field/NegOnePow.lean
import Mathlib.Algebra.Field.Defs import Mathlib.Algebra.Ring.NegOnePow import Mathlib.Tactic.NormNum /-! # Integer powers of `-1` in a field -/ namespace Int lemma cast_negOnePow (K : Type*) (n : ℤ) [DivisionRing K] : n.negOnePow = (-1 : K) ^ n := by rcases even_or_odd' n with ⟨k, rfl | rfl⟩ · simp [zpow_mul, zpow_ofNat] · rw [zpow_add_one₀ (by simp), zpow_mul, zpow_ofNat] simp end Int
.lake/packages/mathlib/Mathlib/Algebra/Field/IsField.lean
import Mathlib.Algebra.Field.Defs import Mathlib.Tactic.Common /-! # `IsField` predicate Predicate on a (semi)ring that it is a (semi)field, i.e. that the multiplication is commutative, that it has more than one element and that all non-zero elements have a multiplicative inverse. In contrast to `Field`, which contains the data of a function associating to an element of the field its multiplicative inverse, this predicate only assumes the existence and can therefore more easily be used to e.g. transfer along ring isomorphisms. -/ universe u section IsField /-- A predicate to express that a (semi)ring is a (semi)field. This is mainly useful because such a predicate does not contain data, and can therefore be easily transported along ring isomorphisms. Additionally, this is useful when trying to prove that a particular ring structure extends to a (semi)field. -/ structure IsField (R : Type u) [Semiring R] : Prop where /-- For a semiring to be a field, it must have two distinct elements. -/ exists_pair_ne : ∃ x y : R, x ≠ y /-- Fields are commutative. -/ mul_comm : ∀ x y : R, x * y = y * x /-- Nonzero elements have multiplicative inverses. -/ mul_inv_cancel : ∀ {a : R}, a ≠ 0 → ∃ b, a * b = 1 /-- Transferring from `Semifield` to `IsField`. -/ theorem Semifield.toIsField (R : Type u) [Semifield R] : IsField R where __ := ‹Semifield R› mul_inv_cancel {a} ha := ⟨a⁻¹, mul_inv_cancel₀ ha⟩ /-- Transferring from `Field` to `IsField`. -/ theorem Field.toIsField (R : Type u) [Field R] : IsField R := Semifield.toIsField _ @[simp] theorem IsField.nontrivial {R : Type u} [Semiring R] (h : IsField R) : Nontrivial R := ⟨h.exists_pair_ne⟩ lemma IsField.isDomain {R : Type u} [Semiring R] (h : IsField R) : IsDomain R where mul_left_cancel_of_ne_zero ha _ _ hb := by obtain ⟨x, hx⟩ := h.mul_inv_cancel ha simpa [← mul_assoc, h.mul_comm, hx] using congr_arg (x * ·) hb mul_right_cancel_of_ne_zero ha _ _ hb := by obtain ⟨x, hx⟩ := h.mul_inv_cancel ha simpa [mul_assoc, hx] using congr_arg (· * x) hb exists_pair_ne := h.exists_pair_ne instance {R : Type u} [Semifield R] : IsDomain R := (Semifield.toIsField _).isDomain @[simp] theorem not_isField_of_subsingleton (R : Type u) [Semiring R] [Subsingleton R] : ¬IsField R := fun h => let ⟨_, _, h⟩ := h.exists_pair_ne h (Subsingleton.elim _ _) open Classical in /-- Transferring from `IsField` to `Semifield`. -/ noncomputable def IsField.toSemifield {R : Type u} [Semiring R] (h : IsField R) : Semifield R where __ := ‹Semiring R› __ := h inv a := if ha : a = 0 then 0 else Classical.choose (h.mul_inv_cancel ha) inv_zero := dif_pos rfl mul_inv_cancel a ha := by convert Classical.choose_spec (h.mul_inv_cancel ha); exact dif_neg ha nnqsmul := _ nnqsmul_def _ _ := rfl /-- Transferring from `IsField` to `Field`. -/ noncomputable def IsField.toField {R : Type u} [Ring R] (h : IsField R) : Field R where __ := (‹Ring R›:) -- this also works without the `( :)`, but it's slow __ := h.toSemifield qsmul := _ qsmul_def := fun _ _ => rfl /-- For each field, and for each nonzero element of said field, there is a unique inverse. Since `IsField` doesn't remember the data of an `inv` function and as such, a lemma that there is a unique inverse could be useful. -/ theorem uniq_inv_of_isField (R : Type u) [Ring R] (hf : IsField R) : ∀ x : R, x ≠ 0 → ∃! y : R, x * y = 1 := by intro x hx apply existsUnique_of_exists_of_unique · exact hf.mul_inv_cancel hx · intro y z hxy hxz calc y = y * (x * z) := by rw [hxz, mul_one] _ = x * y * z := by rw [← mul_assoc, hf.mul_comm y x] _ = z := by rw [hxy, one_mul] end IsField
.lake/packages/mathlib/Mathlib/Algebra/Field/Basic.lean
import Mathlib.Algebra.Field.Defs import Mathlib.Algebra.Ring.GrindInstances import Mathlib.Algebra.Ring.Commute import Mathlib.Algebra.Ring.Invertible import Mathlib.Order.Synonym /-! # Lemmas about division (semi)rings and (semi)fields -/ open Function OrderDual Set universe u variable {K L : Type*} section DivisionSemiring variable [DivisionSemiring K] {a b c d : K} theorem add_div (a b c : K) : (a + b) / c = a / c + b / c := by simp_rw [div_eq_mul_inv, add_mul] @[deprecated add_div (since := "2025-08-25")] theorem div_add_div_same (a b c : K) : a / c + b / c = (a + b) / c := (add_div _ _ _).symm theorem same_add_div (h : b ≠ 0) : (b + a) / b = 1 + a / b := by rw [← div_self h, add_div] theorem div_add_same (h : b ≠ 0) : (a + b) / b = a / b + 1 := by rw [← div_self h, add_div] theorem one_add_div (h : b ≠ 0) : 1 + a / b = (b + a) / b := (same_add_div h).symm theorem div_add_one (h : b ≠ 0) : a / b + 1 = (a + b) / b := (div_add_same h).symm /-- See `inv_add_inv` for the more convenient version when `K` is commutative. -/ theorem inv_add_inv' (ha : a ≠ 0) (hb : b ≠ 0) : a⁻¹ + b⁻¹ = a⁻¹ * (a + b) * b⁻¹ := let _ := invertibleOfNonzero ha; let _ := invertibleOfNonzero hb; invOf_add_invOf a b theorem one_div_mul_add_mul_one_div_eq_one_div_add_one_div (ha : a ≠ 0) (hb : b ≠ 0) : 1 / a * (a + b) * (1 / b) = 1 / a + 1 / b := by simpa only [one_div] using (inv_add_inv' ha hb).symm theorem add_div_eq_mul_add_div (a b : K) (hc : c ≠ 0) : a + b / c = (a * c + b) / c := (eq_div_iff_mul_eq hc).2 <| by rw [right_distrib, div_mul_cancel₀ _ hc] theorem add_div' (a b c : K) (hc : c ≠ 0) : b + a / c = (b * c + a) / c := by rw [add_div, mul_div_cancel_right₀ _ hc] theorem div_add' (a b c : K) (hc : c ≠ 0) : a / c + b = (a + b * c) / c := by rwa [add_comm, add_div', add_comm] protected theorem Commute.div_add_div (hbc : Commute b c) (hbd : Commute b d) (hb : b ≠ 0) (hd : d ≠ 0) : a / b + c / d = (a * d + b * c) / (b * d) := by rw [add_div, mul_div_mul_right _ b hd, hbc.eq, hbd.eq, mul_div_mul_right c d hb] protected theorem Commute.one_div_add_one_div (hab : Commute a b) (ha : a ≠ 0) (hb : b ≠ 0) : 1 / a + 1 / b = (a + b) / (a * b) := by rw [(Commute.one_right a).div_add_div hab ha hb, one_mul, mul_one, add_comm] protected theorem Commute.inv_add_inv (hab : Commute a b) (ha : a ≠ 0) (hb : b ≠ 0) : a⁻¹ + b⁻¹ = (a + b) / (a * b) := by rw [inv_eq_one_div, inv_eq_one_div, hab.one_div_add_one_div ha hb] variable [NeZero (2 : K)] @[simp] lemma add_self_div_two (a : K) : (a + a) / 2 = a := by rw [← mul_two, mul_div_cancel_right₀ a two_ne_zero] @[simp] lemma add_halves (a : K) : a / 2 + a / 2 = a := by rw [← add_div, add_self_div_two] end DivisionSemiring section DivisionRing variable [DivisionRing K] {a b c d : K} @[simp] theorem div_neg_self {a : K} (h : a ≠ 0) : a / -a = -1 := by rw [div_neg_eq_neg_div, div_self h] @[simp] theorem neg_div_self {a : K} (h : a ≠ 0) : -a / a = -1 := by rw [neg_div, div_self h] theorem div_sub_div_same (a b c : K) : a / c - b / c = (a - b) / c := by rw [sub_eq_add_neg, ← neg_div, ← add_div, sub_eq_add_neg] theorem same_sub_div {a b : K} (h : b ≠ 0) : (b - a) / b = 1 - a / b := by simpa only [← @div_self _ _ b h] using (div_sub_div_same b a b).symm theorem one_sub_div {a b : K} (h : b ≠ 0) : 1 - a / b = (b - a) / b := (same_sub_div h).symm theorem div_sub_same {a b : K} (h : b ≠ 0) : (a - b) / b = a / b - 1 := by simpa only [← @div_self _ _ b h] using (div_sub_div_same a b b).symm theorem div_sub_one {a b : K} (h : b ≠ 0) : a / b - 1 = (a - b) / b := (div_sub_same h).symm theorem sub_div (a b c : K) : (a - b) / c = a / c - b / c := (div_sub_div_same _ _ _).symm /-- See `inv_sub_inv` for the more convenient version when `K` is commutative. -/ theorem inv_sub_inv' {a b : K} (ha : a ≠ 0) (hb : b ≠ 0) : a⁻¹ - b⁻¹ = a⁻¹ * (b - a) * b⁻¹ := let _ := invertibleOfNonzero ha; let _ := invertibleOfNonzero hb; invOf_sub_invOf a b theorem one_div_mul_sub_mul_one_div_eq_one_div_add_one_div (ha : a ≠ 0) (hb : b ≠ 0) : 1 / a * (b - a) * (1 / b) = 1 / a - 1 / b := by simpa only [one_div] using (inv_sub_inv' ha hb).symm -- see Note [lower instance priority] instance (priority := 100) DivisionRing.isDomain : IsDomain K := NoZeroDivisors.to_isDomain _ protected theorem Commute.div_sub_div (hbc : Commute b c) (hbd : Commute b d) (hb : b ≠ 0) (hd : d ≠ 0) : a / b - c / d = (a * d - b * c) / (b * d) := by simpa only [mul_neg, neg_div, ← sub_eq_add_neg] using hbc.neg_right.div_add_div hbd hb hd protected theorem Commute.inv_sub_inv (hab : Commute a b) (ha : a ≠ 0) (hb : b ≠ 0) : a⁻¹ - b⁻¹ = (b - a) / (a * b) := by simp only [inv_eq_one_div, (Commute.one_right a).div_sub_div hab ha hb, one_mul, mul_one] variable [NeZero (2 : K)] lemma sub_half (a : K) : a - a / 2 = a / 2 := by rw [sub_eq_iff_eq_add, add_halves] lemma half_sub (a : K) : a / 2 - a = -(a / 2) := by rw [← neg_sub, sub_half] end DivisionRing section Semifield variable [Semifield K] {a b d : K} theorem div_add_div (a : K) (c : K) (hb : b ≠ 0) (hd : d ≠ 0) : a / b + c / d = (a * d + b * c) / (b * d) := (Commute.all b _).div_add_div (Commute.all _ _) hb hd theorem one_div_add_one_div (ha : a ≠ 0) (hb : b ≠ 0) : 1 / a + 1 / b = (a + b) / (a * b) := (Commute.all a _).one_div_add_one_div ha hb theorem inv_add_inv (ha : a ≠ 0) (hb : b ≠ 0) : a⁻¹ + b⁻¹ = (a + b) / (a * b) := (Commute.all a _).inv_add_inv ha hb end Semifield section Field variable [Field K] instance (priority := 100) Field.toGrindField [Field K] : Lean.Grind.Field K := { CommRing.toGrindCommRing K, ‹Field K› with zpow := ⟨fun a n => a^n⟩ zpow_zero a := by simp zpow_succ a n := by by_cases h : a = 0 · rw [← Int.natCast_add_one, zpow_natCast, zpow_natCast, pow_succ] · rw [zpow_add_one₀ h] zpow_neg a n := by simp zero_ne_one := zero_ne_one' K } attribute [local simp] mul_assoc mul_comm mul_left_comm theorem div_sub_div (a : K) {b : K} (c : K) {d : K} (hb : b ≠ 0) (hd : d ≠ 0) : a / b - c / d = (a * d - b * c) / (b * d) := (Commute.all b _).div_sub_div (Commute.all _ _) hb hd theorem inv_sub_inv {a b : K} (ha : a ≠ 0) (hb : b ≠ 0) : a⁻¹ - b⁻¹ = (b - a) / (a * b) := by rw [inv_eq_one_div, inv_eq_one_div, div_sub_div _ _ ha hb, one_mul, mul_one] theorem sub_div' {a b c : K} (hc : c ≠ 0) : b - a / c = (b * c - a) / c := by simpa using div_sub_div b a one_ne_zero hc theorem div_sub' {a b c : K} (hc : c ≠ 0) : a / c - b = (a - c * b) / c := by simpa using div_sub_div a b hc one_ne_zero -- see Note [lower instance priority] instance (priority := 100) Field.isDomain : IsDomain K := { DivisionRing.isDomain with } end Field section NoncomputableDefs variable {R : Type*} [Nontrivial R] /-- Constructs a `DivisionRing` structure on a `Ring` consisting only of units and 0. -/ -- See note [reducible non-instances] noncomputable abbrev DivisionRing.ofIsUnitOrEqZero [Ring R] (h : ∀ a : R, IsUnit a ∨ a = 0) : DivisionRing R where toRing := ‹Ring R› __ := groupWithZeroOfIsUnitOrEqZero h nnqsmul := _ nnqsmul_def := fun _ _ => rfl qsmul := _ qsmul_def := fun _ _ => rfl /-- Constructs a `Field` structure on a `CommRing` consisting only of units and 0. -/ -- See note [reducible non-instances] noncomputable abbrev Field.ofIsUnitOrEqZero [CommRing R] (h : ∀ a : R, IsUnit a ∨ a = 0) : Field R where toCommRing := ‹CommRing R› __ := DivisionRing.ofIsUnitOrEqZero h end NoncomputableDefs namespace Function.Injective variable [Zero K] [Add K] [Neg K] [Sub K] [One K] [Mul K] [Inv K] [Div K] [SMul ℕ K] [SMul ℤ K] [SMul ℚ≥0 K] [SMul ℚ K] [Pow K ℕ] [Pow K ℤ] [NatCast K] [IntCast K] [NNRatCast K] [RatCast K] (f : K → L) (hf : Injective f) /-- Pullback a `DivisionSemiring` along an injective function. -/ -- See note [reducible non-instances] protected abbrev divisionSemiring [DivisionSemiring L] (zero : f 0 = 0) (one : f 1 = 1) (add : ∀ x y, f (x + y) = f x + f y) (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) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (nnqsmul : ∀ (q : ℚ≥0) (x), f (q • x) = q • f x) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) (zpow : ∀ (x) (n : ℤ), f (x ^ n) = f x ^ n) (natCast : ∀ n : ℕ, f n = n) (nnratCast : ∀ q : ℚ≥0, f q = q) : DivisionSemiring K where toSemiring := hf.semiring f zero one add mul nsmul npow natCast __ := hf.groupWithZero f zero one mul inv div npow zpow nnratCast_def q := hf <| by rw [nnratCast, NNRat.cast_def, div, natCast, natCast] nnqsmul := (· • ·) nnqsmul_def q a := hf <| by rw [nnqsmul, NNRat.smul_def, mul, nnratCast] /-- Pullback a `DivisionSemiring` along an injective function. -/ -- See note [reducible non-instances] protected abbrev divisionRing [DivisionRing L] (zero : f 0 = 0) (one : f 1 = 1) (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) (neg : ∀ x, f (-x) = -f x) (sub : ∀ 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) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (zsmul : ∀ (n : ℤ) (x), f (n • x) = n • f x) (nnqsmul : ∀ (q : ℚ≥0) (x), f (q • x) = q • f x) (qsmul : ∀ (q : ℚ) (x), f (q • x) = q • f x) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) (zpow : ∀ (x) (n : ℤ), f (x ^ n) = f x ^ n) (natCast : ∀ n : ℕ, f n = n) (intCast : ∀ n : ℤ, f n = n) (nnratCast : ∀ q : ℚ≥0, f q = q) (ratCast : ∀ q : ℚ, f q = q) : DivisionRing K where toRing := hf.ring f zero one add mul neg sub nsmul zsmul npow natCast intCast __ := hf.groupWithZero f zero one mul inv div npow zpow __ := hf.divisionSemiring f zero one add mul inv div nsmul nnqsmul npow zpow natCast nnratCast ratCast_def q := hf <| by rw [ratCast, div, intCast, natCast, Rat.cast_def] qsmul := (· • ·) qsmul_def q a := hf <| by rw [qsmul, mul, Rat.smul_def, ratCast] /-- Pullback a `Field` along an injective function. -/ -- See note [reducible non-instances] protected abbrev semifield [Semifield L] (zero : f 0 = 0) (one : f 1 = 1) (add : ∀ x y, f (x + y) = f x + f y) (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) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (nnqsmul : ∀ (q : ℚ≥0) (x), f (q • x) = q • f x) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) (zpow : ∀ (x) (n : ℤ), f (x ^ n) = f x ^ n) (natCast : ∀ n : ℕ, f n = n) (nnratCast : ∀ q : ℚ≥0, f q = q) : Semifield K where toCommSemiring := hf.commSemiring f zero one add mul nsmul npow natCast __ := hf.commGroupWithZero f zero one mul inv div npow zpow __ := hf.divisionSemiring f zero one add mul inv div nsmul nnqsmul npow zpow natCast nnratCast /-- Pullback a `Field` along an injective function. -/ -- See note [reducible non-instances] protected abbrev field [Field L] (zero : f 0 = 0) (one : f 1 = 1) (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) (neg : ∀ x, f (-x) = -f x) (sub : ∀ 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) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (zsmul : ∀ (n : ℤ) (x), f (n • x) = n • f x) (nnqsmul : ∀ (q : ℚ≥0) (x), f (q • x) = q • f x) (qsmul : ∀ (q : ℚ) (x), f (q • x) = q • f x) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) (zpow : ∀ (x) (n : ℤ), f (x ^ n) = f x ^ n) (natCast : ∀ n : ℕ, f n = n) (intCast : ∀ n : ℤ, f n = n) (nnratCast : ∀ q : ℚ≥0, f q = q) (ratCast : ∀ q : ℚ, f q = q) : Field K where toCommRing := hf.commRing f zero one add mul neg sub nsmul zsmul npow natCast intCast __ := hf.divisionRing f zero one add mul neg sub inv div nsmul zsmul nnqsmul qsmul npow zpow natCast intCast nnratCast ratCast end Function.Injective /-! ### Order dual -/ namespace OrderDual instance instRatCast [RatCast K] : RatCast Kᵒᵈ := ‹_› instance instDivisionSemiring [DivisionSemiring K] : DivisionSemiring Kᵒᵈ := ‹_› instance instDivisionRing [DivisionRing K] : DivisionRing Kᵒᵈ := ‹_› instance instSemifield [Semifield K] : Semifield Kᵒᵈ := ‹_› instance instField [Field K] : Field Kᵒᵈ := ‹_› end OrderDual @[simp] lemma toDual_ratCast [RatCast K] (n : ℚ) : toDual (n : K) = n := rfl @[simp] lemma ofDual_ratCast [RatCast K] (n : ℚ) : (ofDual n : K) = n := rfl /-! ### Lexicographic order -/ namespace Lex instance instRatCast [RatCast K] : RatCast (Lex K) := ‹_› instance instDivisionSemiring [DivisionSemiring K] : DivisionSemiring (Lex K) := ‹_› instance instDivisionRing [DivisionRing K] : DivisionRing (Lex K) := ‹_› instance instSemifield [Semifield K] : Semifield (Lex K) := ‹_› instance instField [Field K] : Field (Lex K) := ‹_› end Lex @[simp] lemma toLex_ratCast [RatCast K] (n : ℚ) : toLex (n : K) = n := rfl @[simp] lemma ofLex_ratCast [RatCast K] (n : ℚ) : (ofLex n : K) = n := rfl
.lake/packages/mathlib/Mathlib/Algebra/Field/ULift.lean
import Mathlib.Algebra.Field.Defs import Mathlib.Algebra.GroupWithZero.ULift import Mathlib.Algebra.Ring.ULift /-! # Field instances for `ULift` This file defines instances for field, semifield and related structures on `ULift` types. (Recall `ULift α` is just a "copy" of a type `α` in a higher universe.) -/ universe u variable {α : Type u} namespace ULift instance instNNRatCast [NNRatCast α] : NNRatCast (ULift α) where nnratCast q := up q instance instRatCast [RatCast α] : RatCast (ULift α) where ratCast q := up q @[simp, norm_cast] lemma up_nnratCast [NNRatCast α] (q : ℚ≥0) : up (q : α) = q := rfl @[simp, norm_cast] lemma down_nnratCast [NNRatCast α] (q : ℚ≥0) : down (q : ULift α) = q := rfl @[simp, norm_cast] lemma up_ratCast [RatCast α] (q : ℚ) : up (q : α) = q := rfl @[simp, norm_cast] lemma down_ratCast [RatCast α] (q : ℚ) : down (q : ULift α) = q := rfl instance divisionSemiring [DivisionSemiring α] : DivisionSemiring (ULift α) where nnqsmul q x := up (DivisionSemiring.nnqsmul q x.down) nnqsmul_def _ _ := congrArg up <| DivisionSemiring.nnqsmul_def _ _ nnratCast_def _ := congrArg up <| DivisionSemiring.nnratCast_def _ instance semifield [Semifield α] : Semifield (ULift α) := { ULift.divisionSemiring, ULift.commGroupWithZero with } instance divisionRing [DivisionRing α] : DivisionRing (ULift α) where toRing := ring __ := groupWithZero nnqsmul q x := up (DivisionSemiring.nnqsmul q x.down) nnqsmul_def _ _ := congrArg up <| DivisionSemiring.nnqsmul_def _ _ nnratCast_def _ := congrArg up <| DivisionSemiring.nnratCast_def _ qsmul q x := up (DivisionRing.qsmul q x.down) qsmul_def _ _ := congrArg up <| DivisionRing.qsmul_def _ _ ratCast_def _ := congrArg up <| DivisionRing.ratCast_def _ instance field [Field α] : Field (ULift α) := {} end ULift
.lake/packages/mathlib/Mathlib/Algebra/Field/Defs.lean
import Mathlib.Algebra.Ring.Defs import Mathlib.Data.Rat.Init /-! # Division (semi)rings and (semi)fields This file introduces fields and division rings (also known as skewfields) and proves some basic statements about them. For a more extensive theory of fields, see the `FieldTheory` folder. ## Main definitions * `DivisionSemiring`: Nontrivial semiring with multiplicative inverses for nonzero elements. * `DivisionRing`: Nontrivial ring with multiplicative inverses for nonzero elements. * `Semifield`: Commutative division semiring. * `Field`: Commutative division ring. * `IsField`: Predicate on a (semi)ring that it is a (semi)field, i.e. that the multiplication is commutative, that it has more than one element and that all non-zero elements have a multiplicative inverse. In contrast to `Field`, which contains the data of a function associating to an element of the field its multiplicative inverse, this predicate only assumes the existence and can therefore more easily be used to e.g. transfer along ring isomorphisms. ## Implementation details By convention `0⁻¹ = 0` in a field or division ring. This is due to the fact that working with total functions has the advantage of not constantly having to check that `x ≠ 0` when writing `x⁻¹`. With this convention in place, some statements like `(a + b) * c⁻¹ = a * c⁻¹ + b * c⁻¹` still remain true, while others like the defining property `a * a⁻¹ = 1` need the assumption `a ≠ 0`. If you are a beginner in using Lean and are confused by that, you can read more about why this convention is taken in Kevin Buzzard's [blogpost](https://xenaproject.wordpress.com/2020/07/05/division-by-zero-in-type-theory-a-faq/) A division ring or field is an example of a `GroupWithZero`. If you cannot find a division ring / field lemma that does not involve `+`, you can try looking for a `GroupWithZero` lemma instead. ## Tags field, division ring, skew field, skew-field, skewfield -/ assert_not_imported Mathlib.Tactic.Common -- `NeZero` theory should not be needed in the basic algebraic hierarchy assert_not_imported Mathlib.Algebra.NeZero assert_not_exists MonoidHom Set open Function universe u variable {K : Type*} /-- The default definition of the coercion `ℚ≥0 → K` for a division semiring `K`. `↑q : K` is defined as `(q.num : K) / (q.den : K)`. Do not use this directly (instances of `DivisionSemiring` are allowed to override that default for better definitional properties). Instead, use the coercion. -/ def NNRat.castRec [NatCast K] [Div K] (q : ℚ≥0) : K := q.num / q.den /-- The default definition of the coercion `ℚ → K` for a division ring `K`. `↑q : K` is defined as `(q.num : K) / (q.den : K)`. Do not use this directly (instances of `DivisionRing` are allowed to override that default for better definitional properties). Instead, use the coercion. -/ def Rat.castRec [NatCast K] [IntCast K] [Div K] (q : ℚ) : K := q.num / q.den /-- A `DivisionSemiring` is a `Semiring` with multiplicative inverses for nonzero elements. An instance of `DivisionSemiring K` includes maps `nnratCast : ℚ≥0 → K` and `nnqsmul : ℚ≥0 → K → K`. Those two fields are needed to implement the `DivisionSemiring K → Algebra ℚ≥0 K` instance since we need to control the specific definitions for some special cases of `K` (in particular `K = ℚ≥0` itself). See also note [forgetful inheritance]. If the division semiring has positive characteristic `p`, our division by zero convention forces `nnratCast (1 / p) = 1 / 0 = 0`. -/ class DivisionSemiring (K : Type*) extends Semiring K, GroupWithZero K, NNRatCast K where protected nnratCast := NNRat.castRec /-- However `NNRat.cast` is defined, it must be propositionally equal to `a / b`. Do not use this lemma directly. Use `NNRat.cast_def` instead. -/ protected nnratCast_def (q : ℚ≥0) : (NNRat.cast q : K) = q.num / q.den := by intros; rfl /-- Scalar multiplication by a nonnegative rational number. Unless there is a risk of a `Module ℚ≥0 _` instance diamond, write `nnqsmul := _`. This will set `nnqsmul` to `(NNRat.cast · * ·)` thanks to unification in the default proof of `nnqsmul_def`. Do not use directly. Instead use the `•` notation. -/ protected nnqsmul : ℚ≥0 → K → K /-- However `qsmul` is defined, it must be propositionally equal to multiplication by `Rat.cast`. Do not use this lemma directly. Use `NNRat.smul_def` instead. -/ protected nnqsmul_def (q : ℚ≥0) (a : K) : nnqsmul q a = NNRat.cast q * a := by intros; rfl /-- A `DivisionRing` is a `Ring` with multiplicative inverses for nonzero elements. An instance of `DivisionRing K` includes maps `ratCast : ℚ → K` and `qsmul : ℚ → K → K`. Those two fields are needed to implement the `DivisionRing K → Algebra ℚ K` instance since we need to control the specific definitions for some special cases of `K` (in particular `K = ℚ` itself). See also note [forgetful inheritance]. Similarly, there are maps `nnratCast ℚ≥0 → K` and `nnqsmul : ℚ≥0 → K → K` to implement the `DivisionSemiring K → Algebra ℚ≥0 K` instance. If the division ring has positive characteristic `p`, our division by zero convention forces `ratCast (1 / p) = 1 / 0 = 0`. -/ class DivisionRing (K : Type*) extends Ring K, DivInvMonoid K, Nontrivial K, NNRatCast K, RatCast K where /-- For a nonzero `a`, `a⁻¹` is a right multiplicative inverse. -/ protected mul_inv_cancel : ∀ (a : K), a ≠ 0 → a * a⁻¹ = 1 /-- The inverse of `0` is `0` by convention. -/ protected inv_zero : (0 : K)⁻¹ = 0 protected nnratCast := NNRat.castRec /-- However `NNRat.cast` is defined, it must be equal to `a / b`. Do not use this lemma directly. Use `NNRat.cast_def` instead. -/ protected nnratCast_def (q : ℚ≥0) : (NNRat.cast q : K) = q.num / q.den := by intros; rfl /-- Scalar multiplication by a nonnegative rational number. Unless there is a risk of a `Module ℚ≥0 _` instance diamond, write `nnqsmul := _`. This will set `nnqsmul` to `(NNRat.cast · * ·)` thanks to unification in the default proof of `nnqsmul_def`. Do not use directly. Instead use the `•` notation. -/ protected nnqsmul : ℚ≥0 → K → K /-- However `qsmul` is defined, it must be propositionally equal to multiplication by `Rat.cast`. Do not use this lemma directly. Use `NNRat.smul_def` instead. -/ protected nnqsmul_def (q : ℚ≥0) (a : K) : nnqsmul q a = NNRat.cast q * a := by intros; rfl protected ratCast := Rat.castRec /-- However `Rat.cast q` is defined, it must be propositionally equal to `q.num / q.den`. Do not use this lemma directly. Use `Rat.cast_def` instead. -/ protected ratCast_def (q : ℚ) : (Rat.cast q : K) = q.num / q.den := by intros; rfl /-- Scalar multiplication by a rational number. Unless there is a risk of a `Module ℚ _` instance diamond, write `qsmul := _`. This will set `qsmul` to `(Rat.cast · * ·)` thanks to unification in the default proof of `qsmul_def`. Do not use directly. Instead use the `•` notation. -/ protected qsmul : ℚ → K → K /-- However `qsmul` is defined, it must be propositionally equal to multiplication by `Rat.cast`. Do not use this lemma directly. Use `Rat.cast_def` instead. -/ protected qsmul_def (a : ℚ) (x : K) : qsmul a x = Rat.cast a * x := by intros; rfl -- see Note [lower instance priority] instance (priority := 100) DivisionRing.toDivisionSemiring [DivisionRing K] : DivisionSemiring K := { ‹DivisionRing K› with } /-- A `Semifield` is a `CommSemiring` with multiplicative inverses for nonzero elements. An instance of `Semifield K` includes maps `nnratCast : ℚ≥0 → K` and `nnqsmul : ℚ≥0 → K → K`. Those two fields are needed to implement the `DivisionSemiring K → Algebra ℚ≥0 K` instance since we need to control the specific definitions for some special cases of `K` (in particular `K = ℚ≥0` itself). See also note [forgetful inheritance]. If the semifield has positive characteristic `p`, our division by zero convention forces `nnratCast (1 / p) = 1 / 0 = 0`. -/ class Semifield (K : Type*) extends CommSemiring K, DivisionSemiring K, CommGroupWithZero K /-- A `Field` is a `CommRing` with multiplicative inverses for nonzero elements. An instance of `Field K` includes maps `ratCast : ℚ → K` and `qsmul : ℚ → K → K`. Those two fields are needed to implement the `DivisionRing K → Algebra ℚ K` instance since we need to control the specific definitions for some special cases of `K` (in particular `K = ℚ` itself). See also note [forgetful inheritance]. If the field has positive characteristic `p`, our division by zero convention forces `ratCast (1 / p) = 1 / 0 = 0`. -/ @[stacks 09FD "first part"] class Field (K : Type u) extends CommRing K, DivisionRing K -- see Note [lower instance priority] instance (priority := 100) Field.toSemifield [Field K] : Semifield K := { ‹Field K› with } namespace NNRat variable [DivisionSemiring K] instance (priority := 100) smulDivisionSemiring : SMul ℚ≥0 K := ⟨DivisionSemiring.nnqsmul⟩ lemma cast_def (q : ℚ≥0) : (q : K) = q.num / q.den := DivisionSemiring.nnratCast_def _ lemma smul_def (q : ℚ≥0) (a : K) : q • a = q * a := DivisionSemiring.nnqsmul_def q a variable (K) @[simp] lemma smul_one_eq_cast (q : ℚ≥0) : q • (1 : K) = q := by rw [NNRat.smul_def, mul_one] end NNRat namespace Rat variable [DivisionRing K] lemma cast_def (q : ℚ) : (q : K) = q.num / q.den := DivisionRing.ratCast_def _ lemma cast_mk' (a b h1 h2) : ((⟨a, b, h1, h2⟩ : ℚ) : K) = a / b := cast_def _ instance (priority := 100) smulDivisionRing : SMul ℚ K := ⟨DivisionRing.qsmul⟩ theorem smul_def (a : ℚ) (x : K) : a • x = ↑a * x := DivisionRing.qsmul_def a x @[simp] theorem smul_one_eq_cast (A : Type*) [DivisionRing A] (m : ℚ) : m • (1 : A) = ↑m := by rw [Rat.smul_def, mul_one] end Rat /-- `OfScientific.ofScientific` is the simp-normal form. -/ @[simp] theorem Rat.ofScientific_eq_ofScientific (m : ℕ) (s : Bool) (e : ℕ) : Rat.ofScientific (OfNat.ofNat m) s (OfNat.ofNat e) = OfScientific.ofScientific m s e := rfl
.lake/packages/mathlib/Mathlib/Algebra/Field/Shrink.lean
import Mathlib.Algebra.Field.TransferInstance import Mathlib.Logic.Small.Defs import Mathlib.Tactic.SuppressCompilation /-! # Transfer field structures from `α` to `Shrink α` -/ noncomputable section universe v variable {α : Type*} [Small.{v} α] namespace Shrink instance [NNRatCast α] : NNRatCast (Shrink.{v} α) := (equivShrink α).symm.nnratCast instance [RatCast α] : RatCast (Shrink.{v} α) := (equivShrink α).symm.ratCast instance [DivisionRing α] : DivisionRing (Shrink.{v} α) := (equivShrink _).symm.divisionRing instance [Field α] : Field (Shrink.{v} α) := (equivShrink _).symm.field end Shrink
.lake/packages/mathlib/Mathlib/Algebra/Field/GeomSum.lean
import Mathlib.Algebra.Field.Basic import Mathlib.Algebra.Ring.GeomSum /-! # Partial sums of geometric series in a field This file determines the values of the geometric series $\sum_{i=0}^{n-1} x^i$ and $\sum_{i=0}^{n-1} x^i y^{n-1-i}$ and variants thereof. ## Main statements * `geom_sum_Ico` proves that $\sum_{i=m}^{n-1} x^i=\frac{x^n-x^m}{x-1}$ in a division ring. * `geom_sum₂_Ico` proves that $\sum_{i=m}^{n-1} x^iy^{n - 1 - i}=\frac{x^n-y^{n-m}x^m}{x-y}$ in a field. Several variants are recorded, generalising in particular to the case of a division ring in which `x` and `y` commute. -/ assert_not_exists IsOrderedRing variable {R K : Type*} open Finset MulOpposite section DivisionRing variable [DivisionRing K] {x y : K} protected theorem Commute.geom_sum₂ (h' : Commute x y) (h : x ≠ y) (n : ℕ) : ∑ i ∈ range n, x ^ i * y ^ (n - 1 - i) = (x ^ n - y ^ n) / (x - y) := by have : x - y ≠ 0 := by simp_all [sub_eq_iff_eq_add] rw [← h'.geom_sum₂_mul, mul_div_cancel_right₀ _ this] theorem geom_sum_eq (h : x ≠ 1) (n : ℕ) : ∑ i ∈ range n, x ^ i = (x ^ n - 1) / (x - 1) := by have : x - 1 ≠ 0 := by simp_all [sub_eq_iff_eq_add] rw [← geom_sum_mul, mul_div_cancel_right₀ _ this] protected theorem Commute.geom_sum₂_Ico (h : Commute x y) (hxy : x ≠ y) {m n : ℕ} (hmn : m ≤ n) : ∑ i ∈ Finset.Ico m n, x ^ i * y ^ (n - 1 - i) = (x ^ n - y ^ (n - m) * x ^ m) / (x - y) := by have : x - y ≠ 0 := by simp_all [sub_eq_iff_eq_add] rw [← h.geom_sum₂_Ico_mul hmn, mul_div_cancel_right₀ _ this] lemma geom_sum_Ico (hx : x ≠ 1) {m n : ℕ} (hmn : m ≤ n) : ∑ i ∈ Finset.Ico m n, x ^ i = (x ^ n - x ^ m) / (x - 1) := by simp only [sum_Ico_eq_sub _ hmn, geom_sum_eq hx, div_sub_div_same, sub_sub_sub_cancel_right] lemma geom_sum_Ico' (hx : x ≠ 1) {m n : ℕ} (hmn : m ≤ n) : ∑ i ∈ Finset.Ico m n, x ^ i = (x ^ m - x ^ n) / (1 - x) := by simpa [geom_sum_Ico hx hmn] using neg_div_neg_eq (x ^ m - x ^ n) (1 - x) lemma geom_sum_inv (hx1 : x ≠ 1) (hx0 : x ≠ 0) (n : ℕ) : ∑ i ∈ range n, x⁻¹ ^ i = (x - 1)⁻¹ * (x - x⁻¹ ^ n * x) := by have h₁ : x⁻¹ ≠ 1 := by rwa [inv_eq_one_div, Ne, div_eq_iff_mul_eq hx0, one_mul] have h₂ : x⁻¹ - 1 ≠ 0 := mt sub_eq_zero.1 h₁ have h₃ : x - 1 ≠ 0 := mt sub_eq_zero.1 hx1 have h₄ : x * (x ^ n)⁻¹ = (x ^ n)⁻¹ * x := Nat.recOn n (by simp) fun n h => by rw [pow_succ', mul_inv_rev, ← mul_assoc, h, mul_assoc, mul_inv_cancel₀ hx0, mul_assoc, inv_mul_cancel₀ hx0] rw [geom_sum_eq h₁, div_eq_iff_mul_eq h₂, ← mul_right_inj' h₃, ← mul_assoc, ← mul_assoc, mul_inv_cancel₀ h₃] simp [mul_add, add_mul, mul_inv_cancel₀ hx0, mul_assoc, h₄, sub_eq_add_neg, add_comm, add_left_comm] rw [add_comm _ (-x), add_assoc, add_assoc _ _ 1] end DivisionRing section Field variable [Field K] {x y : K} lemma geom₂_sum (h : x ≠ y) (n : ℕ) : ∑ i ∈ range n, x ^ i * y ^ (n - 1 - i) = (x ^ n - y ^ n) / (x - y) := (Commute.all x y).geom_sum₂ h n lemma geom_sum₂_Ico (hxy : x ≠ y) {m n : ℕ} (hmn : m ≤ n) : (∑ i ∈ Finset.Ico m n, x ^ i * y ^ (n - 1 - i)) = (x ^ n - y ^ (n - m) * x ^ m) / (x - y) := (Commute.all x y).geom_sum₂_Ico hxy hmn end Field
.lake/packages/mathlib/Mathlib/Algebra/Field/Power.lean
import Mathlib.Algebra.Field.Defs import Mathlib.Algebra.Ring.Int.Parity /-! # Results about powers in fields or division rings. This file exists to ensure we can define `Field` with minimal imports, so contains some lemmas about powers of elements which need imports beyond those needed for the basic definition. -/ variable {α : Type*} section DivisionRing variable [DivisionRing α] {n : ℤ} theorem Odd.neg_zpow (h : Odd n) (a : α) : (-a) ^ n = -a ^ n := by have hn : n ≠ 0 := by rintro rfl; exact Int.not_even_iff_odd.2 h .zero obtain ⟨k, rfl⟩ := h simp_rw [zpow_add' (.inr (.inl hn)), zpow_one, zpow_mul, zpow_two, neg_mul_neg, neg_mul_eq_mul_neg] theorem Odd.neg_one_zpow (h : Odd n) : (-1 : α) ^ n = -1 := by rw [h.neg_zpow, one_zpow] end DivisionRing
.lake/packages/mathlib/Mathlib/Algebra/Field/Equiv.lean
import Mathlib.Algebra.Field.IsField import Mathlib.Algebra.Group.Units.Equiv import Mathlib.Algebra.GroupWithZero.Equiv /-! # If a semiring is a field, any isomorphic semiring is also a field. This is in a separate file to avoid needing to import `Field` in `Mathlib/Algebra/Ring/Equiv.lean` -/ variable {A B F : Type*} [Semiring A] [Semiring B] protected theorem IsLocalHom.isField [FunLike F A B] [MonoidWithZeroHomClass F A B] {f : F} [IsLocalHom f] (inj : Function.Injective f) (hB : IsField B) : IsField A where exists_pair_ne := have : Nontrivial B := ⟨hB.1⟩; (domain_nontrivial f (map_zero f) (map_one f)).1 mul_comm x y := inj <| by rw [map_mul, map_mul, hB.mul_comm] mul_inv_cancel h := have ⟨a', he⟩ := hB.mul_inv_cancel ((inj.ne h).trans_eq <| map_zero f) let _ := hB.toSemifield (IsUnit.of_mul_eq_one _ he).of_map.exists_right_inv protected theorem MulEquiv.isField (hB : IsField B) (e : A ≃* B) : IsField A := IsLocalHom.isField e.injective hB
.lake/packages/mathlib/Mathlib/Algebra/Field/Periodic.lean
import Mathlib.Algebra.Field.Opposite import Mathlib.Algebra.Module.Opposite import Mathlib.Algebra.Order.Archimedean.Basic import Mathlib.Algebra.Ring.Periodic /-! # Periodic functions This file proves facts about periodic and antiperiodic functions from and to a field. ## Main definitions * `Function.Periodic`: A function `f` is *periodic* if `∀ x, f (x + c) = f x`. `f` is referred to as periodic with period `c` or `c`-periodic. * `Function.Antiperiodic`: A function `f` is *antiperiodic* if `∀ x, f (x + c) = -f x`. `f` is referred to as antiperiodic with antiperiod `c` or `c`-antiperiodic. Note that any `c`-antiperiodic function will necessarily also be `2 • c`-periodic. ## Tags period, periodic, periodicity, antiperiodic -/ assert_not_exists TwoSidedIdeal variable {α β γ : Type*} {f g : α → β} {c c₁ c₂ x : α} open Set namespace Function /-! ### Periodicity -/ protected theorem Periodic.const_smul₀ [AddCommMonoid α] [DivisionSemiring γ] [Module γ α] (h : Periodic f c) (a : γ) : Periodic (fun x => f (a • x)) (a⁻¹ • c) := fun x => by by_cases ha : a = 0 · simp only [ha, zero_smul] · simpa only [smul_add, smul_inv_smul₀ ha] using h (a • x) protected theorem Periodic.const_mul [DivisionSemiring α] (h : Periodic f c) (a : α) : Periodic (fun x => f (a * x)) (a⁻¹ * c) := Periodic.const_smul₀ h a theorem Periodic.const_inv_smul₀ [AddCommMonoid α] [DivisionSemiring γ] [Module γ α] (h : Periodic f c) (a : γ) : Periodic (fun x => f (a⁻¹ • x)) (a • c) := by simpa only [inv_inv] using h.const_smul₀ a⁻¹ theorem Periodic.const_inv_mul [DivisionSemiring α] (h : Periodic f c) (a : α) : Periodic (fun x => f (a⁻¹ * x)) (a * c) := h.const_inv_smul₀ a theorem Periodic.mul_const [DivisionSemiring α] (h : Periodic f c) (a : α) : Periodic (fun x => f (x * a)) (c * a⁻¹) := h.const_smul₀ (MulOpposite.op a) theorem Periodic.mul_const' [DivisionSemiring α] (h : Periodic f c) (a : α) : Periodic (fun x => f (x * a)) (c / a) := by simpa only [div_eq_mul_inv] using h.mul_const a theorem Periodic.mul_const_inv [DivisionSemiring α] (h : Periodic f c) (a : α) : Periodic (fun x => f (x * a⁻¹)) (c * a) := h.const_inv_smul₀ (MulOpposite.op a) theorem Periodic.div_const [DivisionSemiring α] (h : Periodic f c) (a : α) : Periodic (fun x => f (x / a)) (c * a) := by simpa only [div_eq_mul_inv] using h.mul_const_inv a /-- If a function `f` is `Periodic` with positive period `c`, then for all `x` there exists some `y ∈ Ico 0 c` such that `f x = f y`. -/ theorem Periodic.exists_mem_Ico₀ [AddCommGroup α] [LinearOrder α] [IsOrderedAddMonoid α] [Archimedean α] (h : Periodic f c) (hc : 0 < c) (x) : ∃ y ∈ Ico 0 c, f x = f y := let ⟨n, H, _⟩ := existsUnique_zsmul_near_of_pos' hc x ⟨x - n • c, H, (h.sub_zsmul_eq n).symm⟩ /-- If a function `f` is `Periodic` with positive period `c`, then for all `x` there exists some `y ∈ Ico a (a + c)` such that `f x = f y`. -/ theorem Periodic.exists_mem_Ico [AddCommGroup α] [LinearOrder α] [IsOrderedAddMonoid α] [Archimedean α] (h : Periodic f c) (hc : 0 < c) (x a) : ∃ y ∈ Ico a (a + c), f x = f y := let ⟨n, H, _⟩ := existsUnique_add_zsmul_mem_Ico hc x a ⟨x + n • c, H, (h.zsmul n x).symm⟩ /-- If a function `f` is `Periodic` with positive period `c`, then for all `x` there exists some `y ∈ Ioc a (a + c)` such that `f x = f y`. -/ theorem Periodic.exists_mem_Ioc [AddCommGroup α] [LinearOrder α] [IsOrderedAddMonoid α] [Archimedean α] (h : Periodic f c) (hc : 0 < c) (x a) : ∃ y ∈ Ioc a (a + c), f x = f y := let ⟨n, H, _⟩ := existsUnique_add_zsmul_mem_Ioc hc x a ⟨x + n • c, H, (h.zsmul n x).symm⟩ theorem Periodic.image_Ioc [AddCommGroup α] [LinearOrder α] [IsOrderedAddMonoid α] [Archimedean α] (h : Periodic f c) (hc : 0 < c) (a : α) : f '' Ioc a (a + c) = range f := (image_subset_range _ _).antisymm <| range_subset_iff.2 fun x => let ⟨y, hy, hyx⟩ := h.exists_mem_Ioc hc x a ⟨y, hy, hyx.symm⟩ theorem Periodic.image_Icc [AddCommGroup α] [LinearOrder α] [IsOrderedAddMonoid α] [Archimedean α] (h : Periodic f c) (hc : 0 < c) (a : α) : f '' Icc a (a + c) = range f := (image_subset_range _ _).antisymm <| h.image_Ioc hc a ▸ image_mono Ioc_subset_Icc_self theorem Periodic.image_uIcc [AddCommGroup α] [LinearOrder α] [IsOrderedAddMonoid α] [Archimedean α] (h : Periodic f c) (hc : c ≠ 0) (a : α) : f '' uIcc a (a + c) = range f := by cases hc.lt_or_gt with | inl hc => rw [uIcc_of_ge (add_le_of_nonpos_right hc.le), ← h.neg.image_Icc (neg_pos.2 hc) (a + c), add_neg_cancel_right] | inr hc => rw [uIcc_of_le (le_add_of_nonneg_right hc.le), h.image_Icc hc] /-! ### Antiperiodicity -/ theorem Antiperiodic.add_nat_mul_eq [NonAssocSemiring α] [Ring β] (h : Antiperiodic f c) (n : ℕ) : f (x + n * c) = (-1) ^ n * f x := by simpa only [nsmul_eq_mul, zsmul_eq_mul, Int.cast_pow, Int.cast_neg, Int.cast_one] using h.add_nsmul_eq n theorem Antiperiodic.sub_nat_mul_eq [NonAssocRing α] [Ring β] (h : Antiperiodic f c) (n : ℕ) : f (x - n * c) = (-1) ^ n * f x := by simpa only [nsmul_eq_mul, zsmul_eq_mul, Int.cast_pow, Int.cast_neg, Int.cast_one] using h.sub_nsmul_eq n theorem Antiperiodic.nat_mul_sub_eq [NonAssocRing α] [Ring β] (h : Antiperiodic f c) (n : ℕ) : f (n * c - x) = (-1) ^ n * f (-x) := by simpa only [nsmul_eq_mul, zsmul_eq_mul, Int.cast_pow, Int.cast_neg, Int.cast_one] using h.nsmul_sub_eq n theorem Antiperiodic.const_smul₀ [AddMonoid α] [Neg β] [GroupWithZero γ] [DistribMulAction γ α] (h : Antiperiodic f c) {a : γ} (ha : a ≠ 0) : Antiperiodic (fun x => f (a • x)) (a⁻¹ • c) := fun x => by simpa only [smul_add, smul_inv_smul₀ ha] using h (a • x) theorem Antiperiodic.const_mul [DivisionSemiring α] [Neg β] (h : Antiperiodic f c) {a : α} (ha : a ≠ 0) : Antiperiodic (fun x => f (a * x)) (a⁻¹ * c) := h.const_smul₀ ha theorem Antiperiodic.const_inv_smul₀ [AddMonoid α] [Neg β] [GroupWithZero γ] [DistribMulAction γ α] (h : Antiperiodic f c) {a : γ} (ha : a ≠ 0) : Antiperiodic (fun x => f (a⁻¹ • x)) (a • c) := by simpa only [inv_inv] using h.const_smul₀ (inv_ne_zero ha) theorem Antiperiodic.const_inv_mul [DivisionSemiring α] [Neg β] (h : Antiperiodic f c) {a : α} (ha : a ≠ 0) : Antiperiodic (fun x => f (a⁻¹ * x)) (a * c) := h.const_inv_smul₀ ha theorem Antiperiodic.mul_const [DivisionSemiring α] [Neg β] (h : Antiperiodic f c) {a : α} (ha : a ≠ 0) : Antiperiodic (fun x => f (x * a)) (c * a⁻¹) := h.const_smul₀ <| (MulOpposite.op_ne_zero_iff a).mpr ha theorem Antiperiodic.mul_const' [DivisionSemiring α] [Neg β] (h : Antiperiodic f c) {a : α} (ha : a ≠ 0) : Antiperiodic (fun x => f (x * a)) (c / a) := by simpa only [div_eq_mul_inv] using h.mul_const ha theorem Antiperiodic.mul_const_inv [DivisionSemiring α] [Neg β] (h : Antiperiodic f c) {a : α} (ha : a ≠ 0) : Antiperiodic (fun x => f (x * a⁻¹)) (c * a) := h.const_inv_smul₀ <| (MulOpposite.op_ne_zero_iff a).mpr ha theorem Antiperiodic.div_inv [DivisionSemiring α] [Neg β] (h : Antiperiodic f c) {a : α} (ha : a ≠ 0) : Antiperiodic (fun x => f (x / a)) (c * a) := by simpa only [div_eq_mul_inv] using h.mul_const_inv ha end Function theorem Int.fract_periodic (α) [Ring α] [LinearOrder α] [IsStrictOrderedRing α] [FloorRing α] : Function.Periodic Int.fract (1 : α) := fun a => mod_cast Int.fract_add_intCast a 1
.lake/packages/mathlib/Mathlib/Algebra/Field/ZMod.lean
import Mathlib.Algebra.Field.Basic import Mathlib.Data.ZMod.Basic /-! # `ZMod p` is a field -/ namespace ZMod variable (p : ℕ) [hp : Fact p.Prime] private theorem mul_inv_cancel_aux (a : ZMod p) (h : a ≠ 0) : a * a⁻¹ = 1 := by obtain ⟨k, rfl⟩ := natCast_zmod_surjective a apply coe_mul_inv_eq_one apply Nat.Coprime.symm rwa [Nat.Prime.coprime_iff_not_dvd Fact.out, ← CharP.cast_eq_zero_iff (ZMod p)] /-- Field structure on `ZMod p` if `p` is prime. -/ instance : Field (ZMod p) where mul_inv_cancel := mul_inv_cancel_aux p inv_zero := inv_zero p nnqsmul := _ nnqsmul_def := fun _ _ => rfl qsmul := _ qsmul_def := fun _ _ => rfl /-- `ZMod p` is an integral domain when `p` is prime. -/ instance : IsDomain (ZMod p) := by constructor end ZMod
.lake/packages/mathlib/Mathlib/Algebra/Field/MinimalAxioms.lean
import Mathlib.Algebra.Field.Defs import Mathlib.Algebra.Ring.MinimalAxioms /-! # Minimal Axioms for a Field This file defines constructors to define a `Field` structure on a Type, while proving a minimum number of equalities. ## Main Definitions * `Field.ofMinimalAxioms`: Define a `Field` structure on a Type by proving a minimal set of axioms -/ universe u /-- Define a `Field` structure on a Type by proving a minimal set of axioms. Note that this uses the default definitions for `npow`, `nsmul`, `zsmul`, `div` and `sub`. See note [reducible non-instances]. -/ abbrev Field.ofMinimalAxioms (K : Type u) [Add K] [Mul K] [Neg K] [Inv K] [Zero K] [One K] (add_assoc : ∀ a b c : K, a + b + c = a + (b + c)) (zero_add : ∀ a : K, 0 + a = a) (neg_add_cancel : ∀ a : K, -a + a = 0) (mul_assoc : ∀ a b c : K, a * b * c = a * (b * c)) (mul_comm : ∀ a b : K, a * b = b * a) (one_mul : ∀ a : K, 1 * a = a) (mul_inv_cancel : ∀ a : K, a ≠ 0 → a * a⁻¹ = 1) (inv_zero : (0 : K)⁻¹ = 0) (left_distrib : ∀ a b c : K, a * (b + c) = a * b + a * c) (exists_pair_ne : ∃ x y : K, x ≠ y) : Field K := letI := CommRing.ofMinimalAxioms add_assoc zero_add neg_add_cancel mul_assoc mul_comm one_mul left_distrib { exists_pair_ne := exists_pair_ne mul_inv_cancel := mul_inv_cancel inv_zero := inv_zero nnqsmul := _ nnqsmul_def := fun _ _ => rfl qsmul := _ qsmul_def := fun _ _ => rfl }
.lake/packages/mathlib/Mathlib/Algebra/Field/Action/ConjAct.lean
import Mathlib.Algebra.Field.Defs import Mathlib.Algebra.GroupWithZero.Action.ConjAct import Mathlib.Algebra.GroupWithZero.Action.Defs /-! # Conjugation action on a field on itself -/ namespace ConjAct variable {K : Type*} [DivisionRing K] instance distribMulAction₀ : DistribMulAction (ConjAct K) K := { ConjAct.mulAction₀ with smul_zero := by simp [smul_def] smul_add := by simp [smul_def, mul_add, add_mul] } end ConjAct
.lake/packages/mathlib/Mathlib/Algebra/Field/Subfield/Basic.lean
import Mathlib.Algebra.Algebra.Defs import Mathlib.Algebra.Field.Subfield.Defs import Mathlib.Algebra.GroupWithZero.Units.Lemmas import Mathlib.Algebra.Ring.Subring.Basic import Mathlib.RingTheory.SimpleRing.Basic /-! # Subfields Let `K` be a division ring, for example a field. This file concerns the "bundled" subfield type `Subfield K`, a type whose terms correspond to subfields of `K`. Note we do not require the "subfields" to be commutative, so they are really sub-division rings / skew fields. This is the preferred way to talk about subfields in mathlib. Unbundled subfields (`s : Set K` and `IsSubfield s`) are not in this file, and they will ultimately be deprecated. We prove that subfields are a complete lattice, and that you can `map` (pushforward) and `comap` (pull back) them along ring homomorphisms. We define the `closure` construction from `Set K` to `Subfield K`, sending a subset of `K` to the subfield it generates, and prove that it is a Galois insertion. ## Main definitions Notation used here: `(K : Type u) [DivisionRing K] (L : Type u) [DivisionRing L] (f g : K →+* L)` `(A : Subfield K) (B : Subfield L) (s : Set K)` * `instance : CompleteLattice (Subfield K)` : the complete lattice structure on the subfields. * `Subfield.closure` : subfield closure of a set, i.e., the smallest subfield that includes the set. * `Subfield.gi` : `closure : Set M → Subfield M` and coercion `(↑) : Subfield M → Set M` form a `GaloisInsertion`. * `comap f B : Subfield K` : the preimage of a subfield `B` along the ring homomorphism `f` * `map f A : Subfield L` : the image of a subfield `A` along the ring homomorphism `f`. * `f.fieldRange : Subfield L` : the range of the ring homomorphism `f`. * `eqLocusField f g : Subfield K` : given ring homomorphisms `f g : K →+* R`, the subfield of `K` where `f x = g x` ## Implementation notes A subfield is implemented as a subring which is closed under `⁻¹`. Lattice inclusion (e.g. `≤` and `⊓`) is used rather than set notation (`⊆` and `∩`), although `∈` is defined as membership of a subfield's underlying set. ## Tags subfield, subfields -/ universe u v w variable {K : Type u} {L : Type v} {M : Type w} variable [DivisionRing K] [DivisionRing L] [DivisionRing M] namespace Subfield variable (s t : Subfield K) section DerivedFromSubfieldClass /-- Product of a list of elements in a subfield is in the subfield. -/ protected theorem list_prod_mem {l : List K} : (∀ x ∈ l, x ∈ s) → l.prod ∈ s := list_prod_mem /-- Sum of a list of elements in a subfield is in the subfield. -/ protected theorem list_sum_mem {l : List K} : (∀ x ∈ l, x ∈ s) → l.sum ∈ s := list_sum_mem /-- Sum of a multiset of elements in a `Subfield` is in the `Subfield`. -/ protected theorem multiset_sum_mem (m : Multiset K) : (∀ a ∈ m, a ∈ s) → m.sum ∈ s := multiset_sum_mem m /-- Sum of elements in a `Subfield` indexed by a `Finset` is in the `Subfield`. -/ protected theorem sum_mem {ι : Type*} {t : Finset ι} {f : ι → K} (h : ∀ c ∈ t, f c ∈ s) : (∑ i ∈ t, f i) ∈ s := sum_mem h end DerivedFromSubfieldClass /-! ### top -/ /-- The subfield of `K` containing all elements of `K`. -/ instance : Top (Subfield K) := ⟨{ (⊤ : Subring K) with inv_mem' := fun x _ => Subring.mem_top x }⟩ instance : Inhabited (Subfield K) := ⟨⊤⟩ @[simp] theorem mem_top (x : K) : x ∈ (⊤ : Subfield K) := Set.mem_univ x @[simp, norm_cast] theorem coe_top : ((⊤ : Subfield K) : Set K) = Set.univ := rfl /-- The ring equiv between the top element of `Subfield K` and `K`. -/ def topEquiv : (⊤ : Subfield K) ≃+* K := Subsemiring.topEquiv /-! ### comap -/ variable (f : K →+* L) /-- The preimage of a subfield along a ring homomorphism is a subfield. -/ def comap (s : Subfield L) : Subfield K := { s.toSubring.comap f with inv_mem' := fun x hx => show f x⁻¹ ∈ s by rw [map_inv₀ f] exact s.inv_mem hx } @[simp] theorem coe_comap (s : Subfield L) : (s.comap f : Set K) = f ⁻¹' s := rfl @[simp] theorem mem_comap {s : Subfield L} {f : K →+* L} {x : K} : x ∈ s.comap f ↔ f x ∈ s := Iff.rfl theorem comap_comap (s : Subfield M) (g : L →+* M) (f : K →+* L) : (s.comap g).comap f = s.comap (g.comp f) := rfl /-! ### map -/ /-- The image of a subfield along a ring homomorphism is a subfield. -/ def map (s : Subfield K) : Subfield L := { s.toSubring.map f with inv_mem' := by rintro _ ⟨x, hx, rfl⟩ exact ⟨x⁻¹, s.inv_mem hx, map_inv₀ f x⟩ } @[simp, norm_cast] theorem coe_map : (s.map f : Set L) = f '' s := rfl @[simp] theorem mem_map {f : K →+* L} {s : Subfield K} {y : L} : y ∈ s.map f ↔ ∃ x ∈ s, f x = y := by unfold map simp only [mem_mk, Subring.mem_map, mem_toSubring] theorem map_map (g : L →+* M) (f : K →+* L) : (s.map f).map g = s.map (g.comp f) := SetLike.ext' <| Set.image_image _ _ _ theorem map_le_iff_le_comap {f : K →+* L} {s : Subfield K} {t : Subfield L} : s.map f ≤ t ↔ s ≤ t.comap f := Set.image_subset_iff theorem gc_map_comap (f : K →+* L) : GaloisConnection (map f) (comap f) := fun _ _ => map_le_iff_le_comap end Subfield namespace RingHom variable (g : L →+* M) (f : K →+* L) /-! ### range -/ /-- The range of a ring homomorphism, as a subfield of the target. See Note [range copy pattern]. -/ def fieldRange : Subfield L := ((⊤ : Subfield K).map f).copy (Set.range f) Set.image_univ.symm @[simp, norm_cast] theorem coe_fieldRange : (f.fieldRange : Set L) = Set.range f := rfl @[simp] theorem mem_fieldRange {f : K →+* L} {y : L} : y ∈ f.fieldRange ↔ ∃ x, f x = y := Iff.rfl theorem fieldRange_eq_map : f.fieldRange = Subfield.map f ⊤ := by ext simp theorem map_fieldRange : f.fieldRange.map g = (g.comp f).fieldRange := by simpa only [fieldRange_eq_map] using (⊤ : Subfield K).map_map g f theorem mem_fieldRange_self (x : K) : f x ∈ f.fieldRange := exists_apply_eq_apply _ _ theorem fieldRange_eq_top_iff {f : K →+* L} : f.fieldRange = ⊤ ↔ Function.Surjective f := SetLike.ext'_iff.trans Set.range_eq_univ /-- The range of a morphism of fields is a fintype, if the domain is a fintype. Note that this instance can cause a diamond with `Subtype.Fintype` if `L` is also a fintype. -/ instance fintypeFieldRange [Fintype K] [DecidableEq L] (f : K →+* L) : Fintype f.fieldRange := Set.fintypeRange f end RingHom namespace Subfield /-! ### inf -/ /-- The inf of two subfields is their intersection. -/ instance : Min (Subfield K) := ⟨fun s t => { s.toSubring ⊓ t.toSubring with inv_mem' := fun _ hx => Subring.mem_inf.mpr ⟨s.inv_mem (Subring.mem_inf.mp hx).1, t.inv_mem (Subring.mem_inf.mp hx).2⟩ }⟩ @[simp, norm_cast] theorem coe_inf (p p' : Subfield K) : ((p ⊓ p' : Subfield K) : Set K) = p.carrier ∩ p'.carrier := rfl @[simp] theorem mem_inf {p p' : Subfield K} {x : K} : x ∈ p ⊓ p' ↔ x ∈ p ∧ x ∈ p' := Iff.rfl instance : InfSet (Subfield K) := ⟨fun S => { sInf (Subfield.toSubring '' S) with inv_mem' := by rintro x hx apply Subring.mem_sInf.mpr rintro _ ⟨p, p_mem, rfl⟩ exact p.inv_mem (Subring.mem_sInf.mp hx p.toSubring ⟨p, p_mem, rfl⟩) }⟩ @[simp, norm_cast] theorem coe_sInf (S : Set (Subfield K)) : ((sInf S : Subfield K) : Set K) = ⋂ s ∈ S, ↑s := show ((sInf (Subfield.toSubring '' S) : Subring K) : Set K) = ⋂ s ∈ S, ↑s by simp theorem mem_sInf {S : Set (Subfield K)} {x : K} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := Subring.mem_sInf.trans ⟨fun h p hp => h p.toSubring ⟨p, hp, rfl⟩, fun h _ ⟨p', hp', p_eq⟩ => p_eq ▸ h p' hp'⟩ @[simp, norm_cast] theorem coe_iInf {ι : Sort*} {S : ι → Subfield K} : (↑(⨅ i, S i) : Set K) = ⋂ i, S i := by simp only [iInf, coe_sInf, Set.biInter_range] theorem mem_iInf {ι : Sort*} {S : ι → Subfield K} {x : K} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by simp only [iInf, mem_sInf, Set.forall_mem_range] @[simp] theorem sInf_toSubring (s : Set (Subfield K)) : (sInf s).toSubring = ⨅ t ∈ s, Subfield.toSubring t := by ext x simp [mem_sInf, ← sInf_image, Subring.mem_sInf] theorem isGLB_sInf (S : Set (Subfield K)) : IsGLB S (sInf S) := by have : ∀ {s t : Subfield K}, (s : Set K) ≤ t ↔ s ≤ t := by simp [SetLike.coe_subset_coe] refine IsGLB.of_image this ?_ convert isGLB_biInf (s := S) (f := SetLike.coe) exact coe_sInf _ /-- Subfields of a ring form a complete lattice. -/ instance : CompleteLattice (Subfield K) := { completeLatticeOfInf (Subfield K) isGLB_sInf with top := ⊤ le_top := fun _ _ _ => trivial inf := (· ⊓ ·) inf_le_left := fun _ _ _ => And.left inf_le_right := fun _ _ _ => And.right le_inf := fun _ _ _ h₁ h₂ _ hx => ⟨h₁ hx, h₂ hx⟩ } /-! ### subfield closure of a subset -/ /-- The `Subfield` generated by a set. -/ def closure (s : Set K) : Subfield K := sInf {S | s ⊆ S} theorem mem_closure {x : K} {s : Set K} : x ∈ closure s ↔ ∀ S : Subfield K, s ⊆ S → x ∈ S := mem_sInf /-- The subfield generated by a set includes the set. -/ @[simp, aesop safe 20 (rule_sets := [SetLike])] theorem subset_closure {s : Set K} : s ⊆ closure s := fun _ hx => mem_closure.2 fun _ hS => hS hx @[aesop 80% (rule_sets := [SetLike])] theorem mem_closure_of_mem {s : Set K} {x : K} (hx : x ∈ s) : x ∈ closure s := subset_closure hx theorem subring_closure_le (s : Set K) : Subring.closure s ≤ (closure s).toSubring := Subring.closure_le.mpr subset_closure theorem notMem_of_notMem_closure {s : Set K} {P : K} (hP : P ∉ closure s) : P ∉ s := fun h => hP (subset_closure h) @[deprecated (since := "2025-05-23")] alias not_mem_of_not_mem_closure := notMem_of_notMem_closure /-- A subfield `t` includes `closure s` if and only if it includes `s`. -/ @[simp] theorem closure_le {s : Set K} {t : Subfield K} : closure s ≤ t ↔ s ⊆ t := ⟨Set.Subset.trans subset_closure, fun h _ hx => mem_closure.mp hx t h⟩ /-- Subfield closure of a set is monotone in its argument: if `s ⊆ t`, then `closure s ≤ closure t`. -/ @[gcongr] theorem closure_mono ⦃s t : Set K⦄ (h : s ⊆ t) : closure s ≤ closure t := closure_le.2 <| Set.Subset.trans h subset_closure theorem closure_eq_of_le {s : Set K} {t : Subfield K} (h₁ : s ⊆ t) (h₂ : t ≤ closure s) : closure s = t := le_antisymm (closure_le.2 h₁) h₂ /-- An induction principle for closure membership. If `p` holds for `1`, and all elements of `s`, and is preserved under addition, negation, and multiplication, then `p` holds for all elements of the closure of `s`. -/ @[elab_as_elim] theorem closure_induction {s : Set K} {p : ∀ x ∈ closure s, Prop} (mem : ∀ x hx, p x (subset_closure hx)) (one : p 1 (one_mem _)) (add : ∀ x y hx hy, p x hx → p y hy → p (x + y) (add_mem hx hy)) (neg : ∀ x hx, p x hx → p (-x) (neg_mem hx)) (inv : ∀ x hx, p x hx → p x⁻¹ (inv_mem hx)) (mul : ∀ x y hx hy, p x hx → p y hy → p (x * y) (mul_mem hx hy)) {x} (h : x ∈ closure s) : p x h := letI : Subfield K := { carrier := {x | ∃ hx, p x hx} mul_mem' := by rintro _ _ ⟨_, hx⟩ ⟨_, hy⟩; exact ⟨_, mul _ _ _ _ hx hy⟩ one_mem' := ⟨_, one⟩ add_mem' := by rintro _ _ ⟨_, hx⟩ ⟨_, hy⟩; exact ⟨_, add _ _ _ _ hx hy⟩ zero_mem' := ⟨zero_mem _, by simp_rw [← @add_neg_cancel K _ 1]; exact add _ _ _ _ one (neg _ _ one)⟩ neg_mem' := by rintro _ ⟨_, hx⟩; exact ⟨_, neg _ _ hx⟩ inv_mem' := by rintro _ ⟨_, hx⟩; exact ⟨_, inv _ _ hx⟩ } ((closure_le (t := this)).2 (fun x hx ↦ ⟨_, mem x hx⟩) h).2 variable (K) in /-- `closure` forms a Galois insertion with the coercion to set. -/ protected def gi : GaloisInsertion (@closure K _) (↑) where choice s _ := closure s gc _ _ := closure_le le_l_u _ := subset_closure choice_eq _ _ := rfl /-- Closure of a subfield `S` equals `S`. -/ @[simp] theorem closure_eq (s : Subfield K) : closure (s : Set K) = s := (Subfield.gi K).l_u_eq s @[simp] theorem closure_empty : closure (∅ : Set K) = ⊥ := (Subfield.gi K).gc.l_bot @[simp] theorem closure_univ : closure (Set.univ : Set K) = ⊤ := @coe_top K _ ▸ closure_eq ⊤ theorem closure_union (s t : Set K) : closure (s ∪ t) = closure s ⊔ closure t := (Subfield.gi K).gc.l_sup theorem closure_iUnion {ι} (s : ι → Set K) : closure (⋃ i, s i) = ⨆ i, closure (s i) := (Subfield.gi K).gc.l_iSup theorem closure_sUnion (s : Set (Set K)) : closure (⋃₀ s) = ⨆ t ∈ s, closure t := (Subfield.gi K).gc.l_sSup theorem map_sup (s t : Subfield K) (f : K →+* L) : (s ⊔ t).map f = s.map f ⊔ t.map f := (gc_map_comap f).l_sup theorem map_iSup {ι : Sort*} (f : K →+* L) (s : ι → Subfield K) : (iSup s).map f = ⨆ i, (s i).map f := (gc_map_comap f).l_iSup theorem map_inf (s t : Subfield K) (f : K →+* L) : (s ⊓ t).map f = s.map f ⊓ t.map f := SetLike.coe_injective (Set.image_inter f.injective) theorem map_iInf {ι : Sort*} [Nonempty ι] (f : K →+* L) (s : ι → Subfield K) : (iInf s).map f = ⨅ i, (s i).map f := by apply SetLike.coe_injective simpa using (Set.injOn_of_injective f.injective).image_iInter_eq (s := SetLike.coe ∘ s) theorem comap_inf (s t : Subfield L) (f : K →+* L) : (s ⊓ t).comap f = s.comap f ⊓ t.comap f := (gc_map_comap f).u_inf theorem comap_iInf {ι : Sort*} (f : K →+* L) (s : ι → Subfield L) : (iInf s).comap f = ⨅ i, (s i).comap f := (gc_map_comap f).u_iInf @[simp] theorem map_bot (f : K →+* L) : (⊥ : Subfield K).map f = ⊥ := (gc_map_comap f).l_bot @[simp] theorem comap_top (f : K →+* L) : (⊤ : Subfield L).comap f = ⊤ := (gc_map_comap f).u_top /-- The underlying set of a non-empty directed sSup of subfields is just a union of the subfields. Note that this fails without the directedness assumption (the union of two subfields is typically not a subfield) -/ theorem mem_iSup_of_directed {ι} [hι : Nonempty ι] {S : ι → Subfield K} (hS : Directed (· ≤ ·) S) {x : K} : (x ∈ ⨆ i, S i) ↔ ∃ i, x ∈ S i := by let s : Subfield K := { __ := Subring.copy _ _ (Subring.coe_iSup_of_directed hS).symm inv_mem' := fun _ hx ↦ have ⟨i, hi⟩ := Set.mem_iUnion.mp hx Set.mem_iUnion.mpr ⟨i, (S i).inv_mem hi⟩ } have : iSup S = s := le_antisymm (iSup_le fun i ↦ le_iSup (fun i ↦ (S i : Set K)) i) (Set.iUnion_subset fun _ ↦ le_iSup S _) exact this ▸ Set.mem_iUnion theorem coe_iSup_of_directed {ι} [hι : Nonempty ι] {S : ι → Subfield K} (hS : Directed (· ≤ ·) S) : ((⨆ i, S i : Subfield K) : Set K) = ⋃ i, ↑(S i) := Set.ext fun x => by simp [mem_iSup_of_directed hS] theorem mem_sSup_of_directedOn {S : Set (Subfield K)} (Sne : S.Nonempty) (hS : DirectedOn (· ≤ ·) S) {x : K} : x ∈ sSup S ↔ ∃ s ∈ S, x ∈ s := by haveI : Nonempty S := Sne.to_subtype simp only [sSup_eq_iSup', mem_iSup_of_directed hS.directed_val, Subtype.exists, exists_prop] theorem coe_sSup_of_directedOn {S : Set (Subfield K)} (Sne : S.Nonempty) (hS : DirectedOn (· ≤ ·) S) : (↑(sSup S) : Set K) = ⋃ s ∈ S, ↑s := Set.ext fun x => by simp [mem_sSup_of_directedOn Sne hS] end Subfield namespace RingHom variable {s : Subfield K} open Subfield /-- Restriction of a ring homomorphism to its range interpreted as a subfield. -/ def rangeRestrictField (f : K →+* L) : K →+* f.fieldRange := f.rangeSRestrict @[simp] theorem coe_rangeRestrictField (f : K →+* L) (x : K) : (f.rangeRestrictField x : L) = f x := rfl theorem rangeRestrictField_bijective (f : K →+* L) : Function.Bijective (rangeRestrictField f) := (Equiv.ofInjective f f.injective).bijective /-- `RingHom.rangeRestrictField` as a `RingEquiv`. -/ @[simps! apply_coe] noncomputable def rangeRestrictFieldEquiv (f : K →+* L) : K ≃+* f.fieldRange := RingEquiv.ofBijective f.rangeRestrictField f.rangeRestrictField_bijective @[simp] theorem rangeRestrictFieldEquiv_apply_symm_apply (f : K →+* L) (x : f.fieldRange) : f (f.rangeRestrictFieldEquiv.symm x) = x := by rw [← rangeRestrictFieldEquiv_apply_coe, RingEquiv.apply_symm_apply] section eqLocus variable {L : Type v} [Semiring L] /-- The subfield of elements `x : R` such that `f x = g x`, i.e., the equalizer of f and g as a subfield of R -/ def eqLocusField (f g : K →+* L) : Subfield K where __ := (f : K →+* L).eqLocus g inv_mem' _ := eq_on_inv₀ f g carrier := { x | f x = g x } @[simp] theorem mem_eqLocusField {f g : K →+* L} {x : K} : x ∈ f.eqLocusField g ↔ f x = g x := Iff.rfl /-- If two ring homomorphisms are equal on a set, then they are equal on its subfield closure. -/ theorem eqOn_field_closure {f g : K →+* L} {s : Set K} (h : Set.EqOn f g s) : Set.EqOn f g (closure s) := show closure s ≤ f.eqLocusField g from closure_le.2 h theorem eq_of_eqOn_subfield_top {f g : K →+* L} (h : Set.EqOn f g (⊤ : Subfield K)) : f = g := ext fun _ => h trivial theorem eq_of_eqOn_of_field_closure_eq_top {s : Set K} (hs : closure s = ⊤) {f g : K →+* L} (h : s.EqOn f g) : f = g := eq_of_eqOn_subfield_top <| hs ▸ eqOn_field_closure h end eqLocus theorem field_closure_preimage_le (f : K →+* L) (s : Set L) : closure (f ⁻¹' s) ≤ (closure s).comap f := closure_le.2 fun _ hx => SetLike.mem_coe.2 <| mem_comap.2 <| subset_closure hx /-- The image under a ring homomorphism of the subfield generated by a set equals the subfield generated by the image of the set. -/ theorem map_field_closure (f : K →+* L) (s : Set K) : (closure s).map f = closure (f '' s) := Set.image_preimage.l_comm_of_u_comm (gc_map_comap f) (Subfield.gi L).gc (Subfield.gi K).gc fun _ ↦ rfl end RingHom namespace Subfield open RingHom /-- The ring homomorphism associated to an inclusion of subfields. -/ def inclusion {S T : Subfield K} (h : S ≤ T) : S →+* T := S.subtype.codRestrict _ fun x => h x.2 @[simp] theorem fieldRange_subtype (s : Subfield K) : s.subtype.fieldRange = s := SetLike.ext' <| (coe_rangeS _).trans Subtype.range_coe end Subfield namespace RingEquiv variable {s t : Subfield K} /-- Makes the identity isomorphism from a proof two subfields of a multiplicative monoid are equal. -/ def subfieldCongr (h : s = t) : s ≃+* t := { Equiv.setCongr <| SetLike.ext'_iff.1 h with map_mul' := fun _ _ => rfl map_add' := fun _ _ => rfl } end RingEquiv namespace Subfield variable {s : Set K} theorem closure_preimage_le (f : K →+* L) (s : Set L) : closure (f ⁻¹' s) ≤ (closure s).comap f := closure_le.2 fun _ hx => SetLike.mem_coe.2 <| mem_comap.2 <| subset_closure hx section Commutative variable {K : Type u} [Field K] (s : Subfield K) /-- Product of a multiset of elements in a subfield is in the subfield. -/ protected theorem multiset_prod_mem (m : Multiset K) : (∀ a ∈ m, a ∈ s) → m.prod ∈ s := multiset_prod_mem m /-- Product of elements of a subfield indexed by a `Finset` is in the subfield. -/ protected theorem prod_mem {ι : Type*} {t : Finset ι} {f : ι → K} (h : ∀ c ∈ t, f c ∈ s) : (∏ i ∈ t, f i) ∈ s := prod_mem h instance toAlgebra : Algebra s K := RingHom.toAlgebra s.subtype /-- The `Subfield` generated by a set in a field. -/ private def commClosure (s : Set K) : Subfield K where carrier := {z : K | ∃ x ∈ Subring.closure s, ∃ y ∈ Subring.closure s, x / y = z} zero_mem' := ⟨0, Subring.zero_mem _, 1, Subring.one_mem _, div_one _⟩ one_mem' := ⟨1, Subring.one_mem _, 1, Subring.one_mem _, div_one _⟩ neg_mem' {x} := by rintro ⟨y, hy, z, hz, x_eq⟩ exact ⟨-y, Subring.neg_mem _ hy, z, hz, x_eq ▸ neg_div _ _⟩ inv_mem' x := by rintro ⟨y, hy, z, hz, x_eq⟩; exact ⟨z, hz, y, hy, x_eq ▸ (inv_div _ _).symm⟩ add_mem' x_mem y_mem := by -- Use `id` in the next 2 `obtain`s so that assumptions stay there for the `rwa`s below obtain ⟨nx, hnx, dx, hdx, rfl⟩ := id x_mem obtain ⟨ny, hny, dy, hdy, rfl⟩ := id y_mem by_cases hx0 : dx = 0; · rwa [hx0, div_zero, zero_add] by_cases hy0 : dy = 0; · rwa [hy0, div_zero, add_zero] exact ⟨nx * dy + dx * ny, Subring.add_mem _ (Subring.mul_mem _ hnx hdy) (Subring.mul_mem _ hdx hny), dx * dy, Subring.mul_mem _ hdx hdy, (div_add_div nx ny hx0 hy0).symm⟩ mul_mem' := by rintro _ _ ⟨nx, hnx, dx, hdx, rfl⟩ ⟨ny, hny, dy, hdy, rfl⟩ exact ⟨nx * ny, Subring.mul_mem _ hnx hny, dx * dy, Subring.mul_mem _ hdx hdy, (div_mul_div_comm _ _ _ _).symm⟩ private theorem commClosure_eq_closure {s : Set K} : commClosure s = closure s := le_antisymm (fun _ ⟨_, hy, _, hz, eq⟩ ↦ eq ▸ div_mem (subring_closure_le s hy) (subring_closure_le s hz)) (closure_le.mpr fun x hx ↦ ⟨x, Subring.subset_closure hx, 1, Subring.one_mem _, div_one x⟩) theorem mem_closure_iff {s : Set K} {x} : x ∈ closure s ↔ ∃ y ∈ Subring.closure s, ∃ z ∈ Subring.closure s, y / z = x := by rw [← commClosure_eq_closure]; rfl end Commutative end Subfield namespace Subfield theorem map_comap_eq (f : K →+* L) (s : Subfield L) : (s.comap f).map f = s ⊓ f.fieldRange := SetLike.coe_injective Set.image_preimage_eq_inter_range theorem map_comap_eq_self {f : K →+* L} {s : Subfield L} (h : s ≤ f.fieldRange) : (s.comap f).map f = s := by simpa only [inf_of_le_left h] using map_comap_eq f s theorem map_comap_eq_self_of_surjective {f : K →+* L} (hf : Function.Surjective f) (s : Subfield L) : (s.comap f).map f = s := SetLike.coe_injective (Set.image_preimage_eq _ hf) theorem comap_map (f : K →+* L) (s : Subfield K) : (s.map f).comap f = s := SetLike.coe_injective (Set.preimage_image_eq _ f.injective) end Subfield /-! ### Actions by `Subfield`s These are just copies of the definitions about `Subsemiring` starting from `Subsemiring.MulAction`. -/ section Actions namespace Subfield variable {X Y} /-- The action by a subfield is the action by the underlying field. -/ instance [SMul K X] (F : Subfield K) : SMul F X := inferInstanceAs (SMul F.toSubsemiring X) theorem smul_def [SMul K X] {F : Subfield K} (g : F) (m : X) : g • m = (g : K) • m := rfl instance smulCommClass_left [SMul K Y] [SMul X Y] [SMulCommClass K X Y] (F : Subfield K) : SMulCommClass F X Y := inferInstanceAs (SMulCommClass F.toSubsemiring X Y) instance smulCommClass_right [SMul X Y] [SMul K Y] [SMulCommClass X K Y] (F : Subfield K) : SMulCommClass X F Y := inferInstanceAs (SMulCommClass X F.toSubsemiring Y) /-- Note that this provides `IsScalarTower F K K` which is needed by `smul_mul_assoc`. -/ instance [SMul X Y] [SMul K X] [SMul K Y] [IsScalarTower K X Y] (F : Subfield K) : IsScalarTower F X Y := inferInstanceAs (IsScalarTower F.toSubsemiring X Y) instance [SMul K X] [FaithfulSMul K X] (F : Subfield K) : FaithfulSMul F X := inferInstanceAs (FaithfulSMul F.toSubsemiring X) /-- The action by a subfield is the action by the underlying field. -/ instance [MulAction K X] (F : Subfield K) : MulAction F X := inferInstanceAs (MulAction F.toSubsemiring X) /-- The action by a subfield is the action by the underlying field. -/ instance [AddMonoid X] [DistribMulAction K X] (F : Subfield K) : DistribMulAction F X := inferInstanceAs (DistribMulAction F.toSubsemiring X) /-- The action by a subfield is the action by the underlying field. -/ instance [Monoid X] [MulDistribMulAction K X] (F : Subfield K) : MulDistribMulAction F X := inferInstanceAs (MulDistribMulAction F.toSubsemiring X) /-- The action by a subfield is the action by the underlying field. -/ instance [Zero X] [SMulWithZero K X] (F : Subfield K) : SMulWithZero F X := inferInstanceAs (SMulWithZero F.toSubsemiring X) /-- The action by a subfield is the action by the underlying field. -/ instance [Zero X] [MulActionWithZero K X] (F : Subfield K) : MulActionWithZero F X := inferInstanceAs (MulActionWithZero F.toSubsemiring X) /-- The action by a subfield is the action by the underlying field. -/ instance [AddCommMonoid X] [Module K X] (F : Subfield K) : Module F X := inferInstanceAs (Module F.toSubsemiring X) /-- The action by a subfield is the action by the underlying field. -/ instance [Semiring X] [MulSemiringAction K X] (F : Subfield K) : MulSemiringAction F X := inferInstanceAs (MulSemiringAction F.toSubsemiring X) end Subfield end Actions
.lake/packages/mathlib/Mathlib/Algebra/Field/Subfield/Defs.lean
import Mathlib.Algebra.Field.Basic import Mathlib.Algebra.Ring.Subring.Defs import Mathlib.Algebra.Order.Ring.Unbundled.Rat /-! # Subfields Let `K` be a division ring, for example a field. This file defines the "bundled" subfield type `Subfield K`, a type whose terms correspond to subfields of `K`. Note we do not require the "subfields" to be commutative, so they are really sub-division rings / skew fields. This is the preferred way to talk about subfields in mathlib. Unbundled subfields (`s : Set K` and `IsSubfield s`) are not in this file, and they will ultimately be deprecated. We prove that subfields are a complete lattice, and that you can `map` (pushforward) and `comap` (pull back) them along ring homomorphisms. We define the `closure` construction from `Set K` to `Subfield K`, sending a subset of `K` to the subfield it generates, and prove that it is a Galois insertion. ## Main definitions Notation used here: `(K : Type u) [DivisionRing K] (L : Type u) [DivisionRing L] (f g : K →+* L)` `(A : Subfield K) (B : Subfield L) (s : Set K)` * `Subfield K` : the type of subfields of a division ring `K`. ## Implementation notes A subfield is implemented as a subring which is closed under `⁻¹`. Lattice inclusion (e.g. `≤` and `⊓`) is used rather than set notation (`⊆` and `∩`), although `∈` is defined as membership of a subfield's underlying set. ## Tags subfield, subfields -/ universe u v w variable {K : Type u} {L : Type v} {M : Type w} variable [DivisionRing K] [DivisionRing L] [DivisionRing M] /-- `SubfieldClass S K` states `S` is a type of subsets `s ⊆ K` closed under field operations. -/ class SubfieldClass (S K : Type*) [DivisionRing K] [SetLike S K] : Prop extends SubringClass S K, InvMemClass S K namespace SubfieldClass variable (S : Type*) [SetLike S K] [h : SubfieldClass S K] -- See note [lower instance priority] /-- A subfield contains `1`, products and inverses. Be assured that we're not actually proving that subfields are subgroups: `SubgroupClass` is really an abbreviation of `SubgroupWithOrWithoutZeroClass`. -/ instance (priority := 100) toSubgroupClass : SubgroupClass S K := { h with } variable {S} {x : K} @[simp, aesop safe (rule_sets := [SetLike])] lemma nnratCast_mem (s : S) (q : ℚ≥0) : (q : K) ∈ s := by simpa only [NNRat.cast_def] using div_mem (natCast_mem s q.num) (natCast_mem s q.den) @[simp, aesop safe (rule_sets := [SetLike])] lemma ratCast_mem (s : S) (q : ℚ) : (q : K) ∈ s := by simpa only [Rat.cast_def] using div_mem (intCast_mem s q.num) (natCast_mem s q.den) instance instNNRatCast (s : S) : NNRatCast s where nnratCast q := ⟨q, nnratCast_mem s q⟩ instance instRatCast (s : S) : RatCast s where ratCast q := ⟨q, ratCast_mem s q⟩ @[simp, norm_cast] lemma coe_nnratCast (s : S) (q : ℚ≥0) : ((q : s) : K) = q := rfl @[simp, norm_cast] lemma coe_ratCast (s : S) (x : ℚ) : ((x : s) : K) = x := rfl @[aesop 90% (rule_sets := [SetLike])] lemma nnqsmul_mem (s : S) (q : ℚ≥0) (hx : x ∈ s) : q • x ∈ s := by simpa only [NNRat.smul_def] using mul_mem (nnratCast_mem _ _) hx @[aesop 90% (rule_sets := [SetLike])] lemma qsmul_mem (s : S) (q : ℚ) (hx : x ∈ s) : q • x ∈ s := by simpa only [Rat.smul_def] using mul_mem (ratCast_mem _ _) hx @[simp, aesop safe (rule_sets := [SetLike])] lemma ofScientific_mem (s : S) {b : Bool} {n m : ℕ} : (OfScientific.ofScientific n b m : K) ∈ s := SubfieldClass.nnratCast_mem s (OfScientific.ofScientific n b m) instance instSMulNNRat (s : S) : SMul ℚ≥0 s where smul q x := ⟨q • x, nnqsmul_mem s q x.2⟩ instance instSMulRat (s : S) : SMul ℚ s where smul q x := ⟨q • x, qsmul_mem s q x.2⟩ @[simp, norm_cast] lemma coe_nnqsmul (s : S) (q : ℚ≥0) (x : s) : ↑(q • x) = q • (x : K) := rfl @[simp, norm_cast] lemma coe_qsmul (s : S) (q : ℚ) (x : s) : ↑(q • x) = q • (x : K) := rfl variable (S) /-- A subfield inherits a division ring structure -/ instance (priority := 75) toDivisionRing (s : S) : DivisionRing s := fast_instance% Subtype.coe_injective.divisionRing ((↑) : s → K) rfl rfl (fun _ _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ _ ↦ rfl) (coe_nnqsmul _) (coe_qsmul _) (fun _ _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ ↦ rfl) (fun _ ↦ rfl) (fun _ ↦ rfl) (fun _ ↦ rfl) -- Prefer subclasses of `Field` over subclasses of `SubfieldClass`. /-- A subfield of a field inherits a field structure -/ instance (priority := 75) toField {K} [Field K] [SetLike S K] [SubfieldClass S K] (s : S) : Field s := fast_instance% Subtype.coe_injective.field ((↑) : s → K) rfl rfl (fun _ _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ _ ↦ rfl) (coe_nnqsmul _) (coe_qsmul _) (fun _ _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ ↦ rfl) (fun _ ↦ rfl) (fun _ ↦ rfl) (fun _ ↦ rfl) end SubfieldClass /-- `Subfield R` is the type of subfields of `R`. A subfield of `R` is a subset `s` that is a multiplicative submonoid and an additive subgroup. Note in particular that it shares the same 0 and 1 as R. -/ @[stacks 09FD "second part"] structure Subfield (K : Type u) [DivisionRing K] extends Subring K where /-- A subfield is closed under multiplicative inverses. -/ inv_mem' : ∀ x ∈ carrier, x⁻¹ ∈ carrier /-- Reinterpret a `Subfield` as a `Subring`. -/ add_decl_doc Subfield.toSubring namespace Subfield /-- The underlying `AddSubgroup` of a subfield. -/ def toAddSubgroup (s : Subfield K) : AddSubgroup K := { s.toSubring.toAddSubgroup with } instance : SetLike (Subfield K) K where coe s := s.carrier coe_injective' p q h := by cases p; cases q; congr; exact SetLike.ext' h instance : SubfieldClass (Subfield K) K where add_mem {s} := s.add_mem' zero_mem s := s.zero_mem' neg_mem {s} := s.neg_mem' mul_mem {s} := s.mul_mem' one_mem s := s.one_mem' inv_mem {s} := s.inv_mem' _ theorem mem_carrier {s : Subfield K} {x : K} : x ∈ s.carrier ↔ x ∈ s := Iff.rfl @[simp] theorem mem_mk {S : Subring K} {x : K} (h) : x ∈ (⟨S, h⟩ : Subfield K) ↔ x ∈ S := Iff.rfl @[simp] theorem coe_set_mk (S : Subring K) (h) : ((⟨S, h⟩ : Subfield K) : Set K) = S := rfl @[simp] theorem mk_le_mk {S S' : Subring K} (h h') : (⟨S, h⟩ : Subfield K) ≤ (⟨S', h'⟩ : Subfield K) ↔ S ≤ S' := Iff.rfl /-- Two subfields are equal if they have the same elements. -/ @[ext] theorem ext {S T : Subfield K} (h : ∀ x, x ∈ S ↔ x ∈ T) : S = T := SetLike.ext h /-- Copy of a subfield with a new `carrier` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (S : Subfield K) (s : Set K) (hs : s = ↑S) : Subfield K := { S.toSubring.copy s hs with carrier := s inv_mem' := hs.symm ▸ S.inv_mem' } @[simp, norm_cast] theorem coe_copy (S : Subfield K) (s : Set K) (hs : s = ↑S) : (S.copy s hs : Set K) = s := rfl theorem copy_eq (S : Subfield K) (s : Set K) (hs : s = ↑S) : S.copy s hs = S := SetLike.coe_injective hs @[simp] theorem coe_toSubring (s : Subfield K) : (s.toSubring : Set K) = s := rfl @[simp] theorem mem_toSubring (s : Subfield K) (x : K) : x ∈ s.toSubring ↔ x ∈ s := Iff.rfl end Subfield /-- A `Subring` containing inverses is a `Subfield`. -/ def Subring.toSubfield (s : Subring K) (hinv : ∀ x ∈ s, x⁻¹ ∈ s) : Subfield K := { s with inv_mem' := hinv } namespace Subfield variable (s t : Subfield K) section DerivedFromSubfieldClass /-- A subfield contains the field's 1. -/ protected theorem one_mem : (1 : K) ∈ s := one_mem s /-- A subfield contains the field's 0. -/ protected theorem zero_mem : (0 : K) ∈ s := zero_mem s /-- A subfield is closed under multiplication. -/ protected theorem mul_mem {x y : K} : x ∈ s → y ∈ s → x * y ∈ s := mul_mem /-- A subfield is closed under addition. -/ protected theorem add_mem {x y : K} : x ∈ s → y ∈ s → x + y ∈ s := add_mem /-- A subfield is closed under negation. -/ protected theorem neg_mem {x : K} : x ∈ s → -x ∈ s := neg_mem /-- A subfield is closed under subtraction. -/ protected theorem sub_mem {x y : K} : x ∈ s → y ∈ s → x - y ∈ s := sub_mem /-- A subfield is closed under inverses. -/ protected theorem inv_mem {x : K} : x ∈ s → x⁻¹ ∈ s := inv_mem /-- A subfield is closed under division. -/ protected theorem div_mem {x y : K} : x ∈ s → y ∈ s → x / y ∈ s := div_mem protected theorem pow_mem {x : K} (hx : x ∈ s) (n : ℕ) : x ^ n ∈ s := pow_mem hx n protected theorem zsmul_mem {x : K} (hx : x ∈ s) (n : ℤ) : n • x ∈ s := zsmul_mem hx n protected theorem intCast_mem (n : ℤ) : (n : K) ∈ s := intCast_mem s n protected theorem zpow_mem {x : K} (hx : x ∈ s) (n : ℤ) : x ^ n ∈ s := zpow_mem hx n instance : Ring s := s.toSubring.toRing instance : Div s := ⟨fun x y => ⟨x / y, s.div_mem x.2 y.2⟩⟩ instance : Inv s := ⟨fun x => ⟨x⁻¹, s.inv_mem x.2⟩⟩ instance : Pow s ℤ := ⟨fun x z => ⟨x ^ z, s.zpow_mem x.2 z⟩⟩ -- TODO: Those are just special cases of `SubfieldClass.toDivisionRing`/`SubfieldClass.toField` instance toDivisionRing (s : Subfield K) : DivisionRing s := fast_instance% Subtype.coe_injective.divisionRing ((↑) : s → K) rfl rfl (fun _ _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ ↦ rfl) (fun _ ↦ rfl) (fun _ ↦ rfl) fun _ ↦ rfl /-- A subfield inherits a field structure -/ instance toField {K} [Field K] (s : Subfield K) : Field s := fast_instance% Subtype.coe_injective.field ((↑) : s → K) rfl rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ ↦ rfl) (fun _ => rfl) (fun _ => rfl) (fun _ ↦ rfl) fun _ => rfl @[simp, norm_cast] theorem coe_add (x y : s) : (↑(x + y) : K) = ↑x + ↑y := rfl @[simp, norm_cast] theorem coe_sub (x y : s) : (↑(x - y) : K) = ↑x - ↑y := rfl @[simp, norm_cast] theorem coe_neg (x : s) : (↑(-x) : K) = -↑x := rfl @[simp, norm_cast] theorem coe_mul (x y : s) : (↑(x * y) : K) = ↑x * ↑y := rfl @[simp, norm_cast] theorem coe_div (x y : s) : (↑(x / y) : K) = ↑x / ↑y := rfl @[simp, norm_cast] theorem coe_inv (x : s) : (↑x⁻¹ : K) = (↑x)⁻¹ := rfl @[simp, norm_cast] theorem coe_zero : ((0 : s) : K) = 0 := rfl @[simp, norm_cast] theorem coe_one : ((1 : s) : K) = 1 := rfl end DerivedFromSubfieldClass /-- The embedding from a subfield of the field `K` to `K`. -/ def subtype (s : Subfield K) : s →+* K := { s.toSubmonoid.subtype, s.toAddSubgroup.subtype with toFun := (↑) } @[simp] lemma subtype_apply {s : Subfield K} (x : s) : s.subtype x = x := rfl lemma subtype_injective (s : Subfield K) : Function.Injective s.subtype := Subtype.coe_injective @[simp] theorem coe_subtype : ⇑(s.subtype) = ((↑) : s → K) := rfl variable (K) in theorem toSubring_subtype_eq_subtype (S : Subfield K) : S.toSubring.subtype = S.subtype := rfl /-! ### Partial order -/ theorem mem_toSubmonoid {s : Subfield K} {x : K} : x ∈ s.toSubmonoid ↔ x ∈ s := Iff.rfl @[simp] theorem coe_toSubmonoid : (s.toSubmonoid : Set K) = s := rfl @[simp] theorem mem_toAddSubgroup {s : Subfield K} {x : K} : x ∈ s.toAddSubgroup ↔ x ∈ s := Iff.rfl @[simp] theorem coe_toAddSubgroup : (s.toAddSubgroup : Set K) = s := rfl end Subfield
.lake/packages/mathlib/Mathlib/Algebra/NonAssoc/LieAdmissible/Defs.lean
import Mathlib.Algebra.Lie.Basic import Mathlib.Algebra.NonAssoc.PreLie.Basic /-! # Lie admissible rings and algebras We define a Lie-admissible ring as a nonunital nonassociative ring such that the associator satisfies the identity ``` associator x y z + associator z x y + associator y z x = associator y x z + associator z y x + associator x z y ``` ## Main definitions: * `LieAdmissibleRing` * `LieAdmissibleAlgebra` ## Main results * `LieAdmissibleRing.instLieRing`: a Lie-admissible ring as a Lie ring * `LeftPreLieRing.instLieAdmissibleRing`: a left pre-Lie ring as a Lie admissible ring * `RightPreLieRing.instLieAdmissibleRing`: a right pre-Lie ring as a Lie admissible ring * `LieAdmissibleAlgebra.instLieAlgebra`: a Lie-admissible algebra as a Lie algebra * `LeftPreLieAlgebra.instLieAdmissibleAlgebra`: a left pre-Lie ring as a Lie admissible algebra * `RightPreLieAlgebra.instLieAdmissibleAlgebra`: a right pre-Lie ring as a Lie admissible algebra ## Implementation Notes Algebras are implemented as extending `Module`, `IsScalarTower` and `SMulCommClass` following the documentation of `Algebra`. ## References [Munthe-Kaas, H.Z., Lundervold, A. **On Post-Lie Algebras, Lie–Butcher Series and Moving Frames.**][munthe-kaas_lundervold_2013] -/ /-- A `LieAdmissibleRing` is a `NonUnitalNonAssocRing` such that the canonical bracket `⁅x, y⁆ := x * y - y * x` turns it into a `LieRing`. This is expressed by an associator identity. -/ @[ext] class LieAdmissibleRing (L : Type*) extends NonUnitalNonAssocRing L where assoc_def (x y z : L) : associator x y z + associator z x y + associator y z x = associator y x z + associator z y x + associator x z y /-- A `LieAdmissibleAlgebra` is a `LieAdmissibleRing` equipped with a compatible action by scalars from a commutative ring. -/ @[ext] class LieAdmissibleAlgebra (R L : Type*) [CommRing R] [LieAdmissibleRing L] extends Module R L, IsScalarTower R L L, SMulCommClass R L L section instances variable {R L : Type*} [CommRing R] namespace LieAdmissibleRing /-- By definition, every `LieAdmissibleRing` yields a `LieRing` with the commutator bracket. -/ instance instLieRing [LieAdmissibleRing L] : LieRing L where add_lie x y z := by simp only [Ring.lie_def, mul_add, add_mul] abel lie_add x y z := by simp only [Ring.lie_def, mul_add, add_mul] abel lie_self := by simp [Ring.lie_def] leibniz_lie x y z := by have := LieAdmissibleRing.assoc_def x y z simp only [associator_apply] at this grind [Ring.lie_def, mul_sub, sub_mul] end LieAdmissibleRing namespace LieAdmissibleAlgebra /-- Every `LieAdmissibleAlgebra` is a `LieAlgebra` with the commutator bracket. -/ instance instLieAlgebra [LieAdmissibleRing L] [LieAdmissibleAlgebra R L] : LieAlgebra R L where lie_smul r x y := by simp [Ring.lie_def, mul_smul_comm, smul_mul_assoc, ← smul_sub] end LieAdmissibleAlgebra end instances namespace LeftPreLieRing variable {L : Type*} [LeftPreLieRing L] /-- `LeftPreLieRings` are examples of `LieAdmissibleRings` by the commutatitvity assumption on the associator. -/ instance instLieAdmissibleRing : LieAdmissibleRing L where assoc_def x y z := by have assoc_xyz := LeftPreLieRing.assoc_symm' x y z have assoc_zxy := LeftPreLieRing.assoc_symm' z x y have assoc_yzx := LeftPreLieRing.assoc_symm' y z x grind end LeftPreLieRing namespace LeftPreLieAlgebra variable {R L : Type*} [CommRing R] [LeftPreLieRing L] [LeftPreLieAlgebra R L] instance instLieAdmissibleAlgebra : LieAdmissibleAlgebra R L where end LeftPreLieAlgebra namespace RightPreLieRing variable {L : Type*} [RightPreLieRing L] /-- `RightPreLieRings` are examples of `LieAdmissibleRings` by the commutatitvity assumption on the associator. -/ instance instLieAdmissibleRing : LieAdmissibleRing L where assoc_def x y z := by have assoc_xyz := RightPreLieRing.assoc_symm' x y z have assoc_zxy := RightPreLieRing.assoc_symm' z x y have assoc_yzx := RightPreLieRing.assoc_symm' y z x grind end RightPreLieRing namespace RightPreLieAlgebra variable {R L : Type*} [CommRing R] [RightPreLieRing L] [RightPreLieAlgebra R L] instance instLieAdmissibleAlgebra : LieAdmissibleAlgebra R L where end RightPreLieAlgebra
.lake/packages/mathlib/Mathlib/Algebra/NonAssoc/PreLie/Basic.lean
import Mathlib.Algebra.Module.Opposite import Mathlib.Algebra.Ring.Associator import Mathlib.GroupTheory.GroupAction.Ring /-! # Pre-Lie rings and algebras In this file we introduce left and right pre-Lie rings, defined as a `NonUnitalNonAssocRing` where the associator `associator x y z := (x * y) * z - x * (y * z)` is left or right symmetric, respectively. We prove that every `Left(Right)PreLieRing L` is a `Right(Left)PreLieRing L` with the opposite `mul`. The equivalence is simple given by `op : L ≃* Lᵐᵒᵖ`. Everything holds for the algebra versions where `L` is also an `R`-Module over a commutative ring `R`. ## Main definitions All are a defined as a `NonUnitalNonAssocRing` whose `associator` satisfies an identity. * `LeftPreLieRing` * `RightPreLieRing` * `LeftPreLieAlgebra` * `RightPreLieAlgebra` ## Main results * Every `LeftPreLieRing` is a `RightPreLieRing` with the opposite multiplication. ## Implementation notes There are left and right versions of the structures, equivalent via `ᵐᵒᵖ`. Perhaps one could be favored but there is no real reason to. ## References [F. Chapoton, M. Livernet, *Pre-Lie algebras and the rooted trees operad*][chapoton_livernet_2001] [D. Manchon, *A short survey on pre-Lie algebras*][manchon_2011] [J.-M. Oudom, D. Guin, *On the Lie enveloping algebra of a pre-Lie algebra*][oudom_guin_2008] <https://ncatlab.org/nlab/show/pre-Lie+algebra> -/ /-- `LeftPreLieRing`s are `NonUnitalNonAssocRing`s such that the `associator` is symmetric in the first two variables. -/ @[ext] class LeftPreLieRing (L : Type*) extends NonUnitalNonAssocRing L where assoc_symm' (x y z : L) : associator x y z = associator y x z /-- `RightPreLieRing`s are `NonUnitalNonAssocRing`s such that the `associator` is symmetric in the last two variables. -/ @[ext] class RightPreLieRing (L : Type*) extends NonUnitalNonAssocRing L where assoc_symm' (x y z : L) : associator x y z = associator x z y section algebras variable (R : Type*) [CommRing R] /-- A `LeftPreLieAlgebra` is a `LeftPreLieRing` with an action of a `CommRing` satisfying `r • x * y = r • (x * y)` and ` x * (r • y) = r • (x * y)`. -/ @[ext] class LeftPreLieAlgebra (L : Type*) [LeftPreLieRing L] : Type _ extends Module R L, IsScalarTower R L L, SMulCommClass R L L /-- A `RightPreLieAlgebra` is a `RightPreLieRing` with an action of a `CommRing` satisfying `r • x * y = r • (x * y)` and ` x * (r • y) = r • (x * y)`. -/ @[ext] class RightPreLieAlgebra (L : Type*) [RightPreLieRing L] : Type _ extends Module R L, IsScalarTower R L L, SMulCommClass R L L end algebras variable {R L : Type*} [CommRing R] namespace LeftPreLieRing variable [LeftPreLieRing L] theorem assoc_symm (x y z : L) : associator x y z = associator y x z := LeftPreLieRing.assoc_symm' x y z /-- Every left pre-Lie ring is a right pre-Lie ring with the opposite multiplication -/ instance : RightPreLieRing Lᵐᵒᵖ where assoc_symm' x y z := by simp [assoc_symm] end LeftPreLieRing namespace LeftPreLieAlgebra variable [LeftPreLieRing L] [LeftPreLieAlgebra R L] /-- Every left pre-Lie algebra is a right pre-Lie algebra with the opposite multiplication -/ instance : RightPreLieAlgebra R Lᵐᵒᵖ where end LeftPreLieAlgebra namespace RightPreLieRing variable [RightPreLieRing L] theorem assoc_symm (x y z : L) : associator x y z = associator x z y := RightPreLieRing.assoc_symm' x y z /-- Every left pre-Lie ring is a right pre-Lie ring with the opposite multiplication -/ instance : LeftPreLieRing Lᵐᵒᵖ where assoc_symm' x y z := by simp [assoc_symm] end RightPreLieRing namespace RightPreLieAlgebra variable [RightPreLieRing L] [RightPreLieAlgebra R L] /-- Every left pre-Lie algebra is a right pre-Lie algebra with the opposite multiplication -/ instance : LeftPreLieAlgebra R Lᵐᵒᵖ where end RightPreLieAlgebra
.lake/packages/mathlib/Mathlib/Algebra/Star/Subalgebra.lean
import Mathlib.Algebra.Algebra.Subalgebra.Lattice import Mathlib.Algebra.Algebra.Tower import Mathlib.Algebra.Star.Module import Mathlib.Algebra.Star.NonUnitalSubalgebra /-! # Star subalgebras A *-subalgebra is a subalgebra of a *-algebra which is closed under *. The centralizer of a *-closed set is a *-subalgebra. -/ universe u v /-- A *-subalgebra is a subalgebra of a *-algebra which is closed under *. -/ structure StarSubalgebra (R : Type u) (A : Type v) [CommSemiring R] [StarRing R] [Semiring A] [StarRing A] [Algebra R A] [StarModule R A] : Type v extends Subalgebra R A where /-- The `carrier` is closed under the `star` operation. -/ star_mem' {a} : a ∈ carrier → star a ∈ carrier namespace StarSubalgebra /-- Forgetting that a *-subalgebra is closed under *. -/ add_decl_doc StarSubalgebra.toSubalgebra variable {F R A B C : Type*} [CommSemiring R] [StarRing R] variable [Semiring A] [StarRing A] [Algebra R A] [StarModule R A] variable [Semiring B] [StarRing B] [Algebra R B] [StarModule R B] variable [Semiring C] [StarRing C] [Algebra R C] [StarModule R C] instance setLike : SetLike (StarSubalgebra R A) A where coe S := S.carrier coe_injective' p q h := by obtain ⟨⟨⟨⟨⟨_, _⟩, _⟩, _⟩, _⟩, _⟩ := p; cases q; congr /-- The actual `StarSubalgebra` obtained from an element of a type satisfying `SubsemiringClass`, `SMulMemClass` and `StarMemClass`. -/ @[simps] def ofClass {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] [StarRing R] [StarRing A] [StarModule R A] [SetLike S A] [SubsemiringClass S A] [SMulMemClass S R A] [StarMemClass S A] (s : S) : StarSubalgebra R A where carrier := s add_mem' := add_mem zero_mem' := zero_mem _ mul_mem' := mul_mem one_mem' := one_mem _ algebraMap_mem' := algebraMap_mem s star_mem' := star_mem instance (priority := 100) : CanLift (Set A) (StarSubalgebra R A) (↑) (fun s ↦ (∀ {x y}, x ∈ s → y ∈ s → x + y ∈ s) ∧ (∀ {x y}, x ∈ s → y ∈ s → x * y ∈ s) ∧ (∀ (r : R), algebraMap R A r ∈ s) ∧ ∀ {x}, x ∈ s → star x ∈ s) where prf s h := ⟨ { carrier := s zero_mem' := by simpa using h.2.2.1 0 add_mem' := h.1 one_mem' := by simpa using h.2.2.1 1 mul_mem' := h.2.1 algebraMap_mem' := h.2.2.1 star_mem' := h.2.2.2 }, rfl ⟩ instance starMemClass : StarMemClass (StarSubalgebra R A) A where star_mem {s} := s.star_mem' instance subsemiringClass : SubsemiringClass (StarSubalgebra R A) A where add_mem {s} := s.add_mem' mul_mem {s} := s.mul_mem' one_mem {s} := s.one_mem' zero_mem {s} := s.zero_mem' instance smulMemClass : SMulMemClass (StarSubalgebra R A) R A where smul_mem {s} r a (ha : a ∈ s.toSubalgebra) := (SMulMemClass.smul_mem r ha : r • a ∈ s.toSubalgebra) instance subringClass {R A} [CommRing R] [StarRing R] [Ring A] [StarRing A] [Algebra R A] [StarModule R A] : SubringClass (StarSubalgebra R A) A where neg_mem {s a} ha := show -a ∈ s.toSubalgebra from neg_mem ha -- this uses the `Star` instance `s` inherits from `StarMemClass (StarSubalgebra R A) A` instance starRing (s : StarSubalgebra R A) : StarRing s := { StarMemClass.instStar s with star_involutive := fun r => Subtype.ext (star_star (r : A)) star_mul := fun r₁ r₂ => Subtype.ext (star_mul (r₁ : A) (r₂ : A)) star_add := fun r₁ r₂ => Subtype.ext (star_add (r₁ : A) (r₂ : A)) } instance algebra (s : StarSubalgebra R A) : Algebra R s := s.toSubalgebra.algebra' instance starModule (s : StarSubalgebra R A) : StarModule R s where star_smul r a := Subtype.ext (star_smul r (a : A)) /-- Turn a `StarSubalgebra` into a `NonUnitalStarSubalgebra` by forgetting that it contains `1`. -/ def toNonUnitalStarSubalgebra (S : StarSubalgebra R A) : NonUnitalStarSubalgebra R A where __ := S smul_mem' r _x hx := S.smul_mem hx r lemma one_mem_toNonUnitalStarSubalgebra (S : StarSubalgebra R A) : 1 ∈ S.toNonUnitalStarSubalgebra := S.one_mem' theorem mem_carrier {s : StarSubalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s := Iff.rfl @[ext] theorem ext {S T : StarSubalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T := SetLike.ext h @[simp] lemma coe_mk (S : Subalgebra R A) (h) : ((⟨S, h⟩ : StarSubalgebra R A) : Set A) = S := rfl @[simp] theorem mem_toSubalgebra {S : StarSubalgebra R A} {x} : x ∈ S.toSubalgebra ↔ x ∈ S := Iff.rfl @[simp] theorem coe_toSubalgebra (S : StarSubalgebra R A) : (S.toSubalgebra : Set A) = S := rfl theorem toSubalgebra_injective : Function.Injective (toSubalgebra : StarSubalgebra R A → Subalgebra R A) := fun S T h => ext fun x => by rw [← mem_toSubalgebra, ← mem_toSubalgebra, h] theorem toSubalgebra_inj {S U : StarSubalgebra R A} : S.toSubalgebra = U.toSubalgebra ↔ S = U := toSubalgebra_injective.eq_iff theorem toSubalgebra_le_iff {S₁ S₂ : StarSubalgebra R A} : S₁.toSubalgebra ≤ S₂.toSubalgebra ↔ S₁ ≤ S₂ := Iff.rfl /-- Copy of a star subalgebra with a new `carrier` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (S : StarSubalgebra R A) (s : Set A) (hs : s = ↑S) : StarSubalgebra R A where toSubalgebra := Subalgebra.copy S.toSubalgebra s hs star_mem' {a} ha := hs ▸ S.star_mem' (by simpa [hs] using ha) @[simp, norm_cast] theorem coe_copy (S : StarSubalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s := rfl theorem copy_eq (S : StarSubalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S := SetLike.coe_injective hs variable (S : StarSubalgebra R A) protected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S := S.algebraMap_mem' r theorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubalgebra.toSubsemiring := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r theorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r theorem range_le : Set.range (algebraMap R A) ≤ S := S.range_subset protected theorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem r) hx /-- Embedding of a subalgebra into the algebra. -/ def subtype : S →⋆ₐ[R] A where toFun := ((↑) : S → A) map_one' := rfl map_mul' _ _ := rfl map_zero' := rfl map_add' _ _ := rfl commutes' _ := rfl map_star' _ := rfl @[simp] theorem coe_subtype : (S.subtype : S → A) = Subtype.val := rfl theorem subtype_apply (x : S) : S.subtype x = (x : A) := rfl @[simp] theorem toSubalgebra_subtype : S.toSubalgebra.val = S.subtype.toAlgHom := rfl /-- The inclusion map between `StarSubalgebra`s given by `Subtype.map id` as a `StarAlgHom`. -/ @[simps] def inclusion {S₁ S₂ : StarSubalgebra R A} (h : S₁ ≤ S₂) : S₁ →⋆ₐ[R] S₂ where toFun := Subtype.map id h map_one' := rfl map_mul' _ _ := rfl map_zero' := rfl map_add' _ _ := rfl commutes' _ := rfl map_star' _ := rfl theorem inclusion_injective {S₁ S₂ : StarSubalgebra R A} (h : S₁ ≤ S₂) : Function.Injective <| inclusion h := Set.inclusion_injective h @[simp] theorem subtype_comp_inclusion {S₁ S₂ : StarSubalgebra R A} (h : S₁ ≤ S₂) : S₂.subtype.comp (inclusion h) = S₁.subtype := rfl section Map /-- Transport a star subalgebra via a star algebra homomorphism. -/ def map (f : A →⋆ₐ[R] B) (S : StarSubalgebra R A) : StarSubalgebra R B := { S.toSubalgebra.map f.toAlgHom with star_mem' := by rintro _ ⟨a, ha, rfl⟩ exact map_star f a ▸ Set.mem_image_of_mem _ (S.star_mem' ha) } theorem map_mono {S₁ S₂ : StarSubalgebra R A} {f : A →⋆ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f := Set.image_mono theorem map_injective {f : A →⋆ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) := fun _S₁ _S₂ ih => ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih @[simp] theorem map_id (S : StarSubalgebra R A) : S.map (StarAlgHom.id R A) = S := SetLike.coe_injective <| Set.image_id _ theorem map_map (S : StarSubalgebra R A) (g : B →⋆ₐ[R] C) (f : A →⋆ₐ[R] B) : (S.map f).map g = S.map (g.comp f) := SetLike.coe_injective <| Set.image_image _ _ _ @[simp] theorem mem_map {S : StarSubalgebra R A} {f : A →⋆ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y := Subsemiring.mem_map theorem map_toSubalgebra {S : StarSubalgebra R A} {f : A →⋆ₐ[R] B} : (S.map f).toSubalgebra = S.toSubalgebra.map f.toAlgHom := SetLike.coe_injective rfl @[simp, norm_cast] theorem coe_map (S : StarSubalgebra R A) (f : A →⋆ₐ[R] B) : (S.map f : Set B) = f '' S := rfl /-- Preimage of a star subalgebra under a star algebra homomorphism. -/ def comap (f : A →⋆ₐ[R] B) (S : StarSubalgebra R B) : StarSubalgebra R A := { S.toSubalgebra.comap f.toAlgHom with star_mem' := @fun a ha => show f (star a) ∈ S from (map_star f a).symm ▸ star_mem ha } theorem map_le_iff_le_comap {S : StarSubalgebra R A} {f : A →⋆ₐ[R] B} {U : StarSubalgebra R B} : map f S ≤ U ↔ S ≤ comap f U := Set.image_subset_iff theorem gc_map_comap (f : A →⋆ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le_iff_le_comap theorem comap_mono {S₁ S₂ : StarSubalgebra R B} {f : A →⋆ₐ[R] B} : S₁ ≤ S₂ → S₁.comap f ≤ S₂.comap f := Set.preimage_mono theorem comap_injective {f : A →⋆ₐ[R] B} (hf : Function.Surjective f) : Function.Injective (comap f) := fun _S₁ _S₂ h => ext fun b => let ⟨x, hx⟩ := hf b let this := SetLike.ext_iff.1 h x hx ▸ this @[simp] theorem comap_id (S : StarSubalgebra R A) : S.comap (StarAlgHom.id R A) = S := SetLike.coe_injective <| Set.preimage_id theorem comap_comap (S : StarSubalgebra R C) (g : B →⋆ₐ[R] C) (f : A →⋆ₐ[R] B) : (S.comap g).comap f = S.comap (g.comp f) := SetLike.coe_injective <| by exact Set.preimage_preimage @[simp] theorem mem_comap (S : StarSubalgebra R B) (f : A →⋆ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S := Iff.rfl @[simp, norm_cast] theorem coe_comap (S : StarSubalgebra R B) (f : A →⋆ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) := rfl end Map section Centralizer variable (R) /-- The centralizer, or commutant, of the star-closure of a set as a star subalgebra. -/ def centralizer (s : Set A) : StarSubalgebra R A where toSubalgebra := Subalgebra.centralizer R (s ∪ star s) star_mem' := Set.star_mem_centralizer @[simp, norm_cast] theorem coe_centralizer (s : Set A) : (centralizer R s : Set A) = (s ∪ star s).centralizer := rfl open Set in nonrec theorem mem_centralizer_iff {s : Set A} {z : A} : z ∈ centralizer R s ↔ ∀ g ∈ s, g * z = z * g ∧ star g * z = z * star g := by simp [← SetLike.mem_coe, centralizer_union, ← image_star, mem_centralizer_iff, forall_and] theorem centralizer_le (s t : Set A) (h : s ⊆ t) : centralizer R t ≤ centralizer R s := Set.centralizer_subset (Set.union_subset_union h <| Set.preimage_mono h) theorem centralizer_toSubalgebra (s : Set A) : (centralizer R s).toSubalgebra = Subalgebra.centralizer R (s ∪ star s):= rfl theorem coe_centralizer_centralizer (s : Set A) : (centralizer R (centralizer R s : Set A)) = (s ∪ star s).centralizer.centralizer := by rw [coe_centralizer, StarMemClass.star_coe_eq, Set.union_self, coe_centralizer] end Centralizer end StarSubalgebra /-! ### The star closure of a subalgebra -/ namespace Subalgebra open Pointwise variable {F R A B : Type*} [CommSemiring R] [StarRing R] variable [Semiring A] [Algebra R A] [StarRing A] [StarModule R A] variable [Semiring B] [Algebra R B] [StarRing B] [StarModule R B] /-- The pointwise `star` of a subalgebra is a subalgebra. -/ instance involutiveStar : InvolutiveStar (Subalgebra R A) where star S := { carrier := star S.carrier mul_mem' := fun {x y} hx hy => by simp only [Set.mem_star, Subalgebra.mem_carrier] at * exact (star_mul x y).symm ▸ mul_mem hy hx one_mem' := Set.mem_star.mp ((star_one A).symm ▸ one_mem S : star (1 : A) ∈ S) add_mem' := fun {x y} hx hy => by simp only [Set.mem_star, Subalgebra.mem_carrier] at * exact (star_add x y).symm ▸ add_mem hx hy zero_mem' := Set.mem_star.mp ((star_zero A).symm ▸ zero_mem S : star (0 : A) ∈ S) algebraMap_mem' := fun r => by simpa only [Set.mem_star, Subalgebra.mem_carrier, ← algebraMap_star_comm] using S.algebraMap_mem (star r) } star_involutive S := Subalgebra.ext fun x => ⟨fun hx => star_star x ▸ hx, fun hx => ((star_star x).symm ▸ hx : star (star x) ∈ S)⟩ @[simp] theorem mem_star_iff (S : Subalgebra R A) (x : A) : x ∈ star S ↔ star x ∈ S := Iff.rfl theorem star_mem_star_iff (S : Subalgebra R A) (x : A) : star x ∈ star S ↔ x ∈ S := by simp @[simp] theorem coe_star (S : Subalgebra R A) : ((star S : Subalgebra R A) : Set A) = star (S : Set A) := rfl theorem star_mono : Monotone (star : Subalgebra R A → Subalgebra R A) := fun _ _ h _ hx => h hx variable (R) in /-- The star operation on `Subalgebra` commutes with `Algebra.adjoin`. -/ theorem star_adjoin_comm (s : Set A) : star (Algebra.adjoin R s) = Algebra.adjoin R (star s) := have this : ∀ t : Set A, Algebra.adjoin R (star t) ≤ star (Algebra.adjoin R t) := fun _ => Algebra.adjoin_le fun _ hx => Algebra.subset_adjoin hx le_antisymm (by simpa only [star_star] using Subalgebra.star_mono (this (star s))) (this s) /-- The `StarSubalgebra` obtained from `S : Subalgebra R A` by taking the smallest subalgebra containing both `S` and `star S`. -/ def starClosure (S : Subalgebra R A) : StarSubalgebra R A where toSubalgebra := S ⊔ star S star_mem' := fun {a} ha => by simp only [Subalgebra.mem_carrier, ← (@Algebra.gi R A _ _ _).l_sup_u _ _] at * rw [← mem_star_iff _ a, star_adjoin_comm, sup_comm] simpa using ha @[simp] theorem coe_starClosure (S : Subalgebra R A) : (S.starClosure : Set A) = (S ⊔ star S : Subalgebra R A) := rfl @[simp] theorem mem_starClosure (S : Subalgebra R A) {x : A} : x ∈ S.starClosure ↔ x ∈ S ⊔ star S := Iff.rfl theorem starClosure_toSubalgebra (S : Subalgebra R A) : S.starClosure.toSubalgebra = S ⊔ star S := rfl theorem starClosure_le {S₁ : Subalgebra R A} {S₂ : StarSubalgebra R A} (h : S₁ ≤ S₂.toSubalgebra) : S₁.starClosure ≤ S₂ := StarSubalgebra.toSubalgebra_le_iff.1 <| sup_le h fun x hx => (star_star x ▸ star_mem (show star x ∈ S₂ from h <| (S₁.mem_star_iff _).1 hx) : x ∈ S₂) theorem starClosure_le_iff {S₁ : Subalgebra R A} {S₂ : StarSubalgebra R A} : S₁.starClosure ≤ S₂ ↔ S₁ ≤ S₂.toSubalgebra := ⟨fun h => le_sup_left.trans h, starClosure_le⟩ end Subalgebra /-! ### The star subalgebra generated by a set -/ namespace StarAlgebra open StarSubalgebra variable {F R A B : Type*} [CommSemiring R] [StarRing R] variable [Semiring A] [Algebra R A] [StarRing A] [StarModule R A] variable [Semiring B] [Algebra R B] [StarRing B] [StarModule R B] variable (R) /-- The minimal star subalgebra that contains `s`. -/ def adjoin (s : Set A) : StarSubalgebra R A := { Algebra.adjoin R (s ∪ star s) with star_mem' := fun hx => by rwa [Subalgebra.mem_carrier, ← Subalgebra.mem_star_iff, Subalgebra.star_adjoin_comm, Set.union_star, star_star, Set.union_comm] } theorem adjoin_eq_starClosure_adjoin (s : Set A) : adjoin R s = (Algebra.adjoin R s).starClosure := toSubalgebra_injective <| show Algebra.adjoin R (s ∪ star s) = Algebra.adjoin R s ⊔ star (Algebra.adjoin R s) from (Subalgebra.star_adjoin_comm R s).symm ▸ Algebra.adjoin_union s (star s) theorem adjoin_toSubalgebra (s : Set A) : (adjoin R s).toSubalgebra = Algebra.adjoin R (s ∪ star s) := rfl @[simp, aesop safe 20 (rule_sets := [SetLike])] theorem subset_adjoin (s : Set A) : s ⊆ adjoin R s := Set.subset_union_left.trans Algebra.subset_adjoin @[simp, aesop safe 20 (rule_sets := [SetLike])] theorem star_subset_adjoin (s : Set A) : star s ⊆ adjoin R s := Set.subset_union_right.trans Algebra.subset_adjoin @[aesop 80% (rule_sets := [SetLike])] theorem mem_adjoin_of_mem {s : Set A} {x : A} (hx : x ∈ s) : x ∈ adjoin R s := subset_adjoin R s hx theorem self_mem_adjoin_singleton (x : A) : x ∈ adjoin R ({x} : Set A) := Algebra.subset_adjoin <| Set.mem_union_left _ (Set.mem_singleton x) theorem star_self_mem_adjoin_singleton (x : A) : star x ∈ adjoin R ({x} : Set A) := star_mem <| self_mem_adjoin_singleton R x variable {R} protected theorem gc : GaloisConnection (adjoin R : Set A → StarSubalgebra R A) (↑) := by intro s S rw [← toSubalgebra_le_iff, adjoin_toSubalgebra, Algebra.adjoin_le_iff, coe_toSubalgebra] exact ⟨fun h => Set.subset_union_left.trans h, fun h => Set.union_subset h fun x hx => star_star x ▸ star_mem (show star x ∈ S from h hx)⟩ /-- Galois insertion between `adjoin` and `coe`. -/ protected def gi : GaloisInsertion (adjoin R : Set A → StarSubalgebra R A) (↑) where choice s hs := (adjoin R s).copy s <| le_antisymm (StarAlgebra.gc.le_u_l s) hs gc := StarAlgebra.gc le_l_u S := (StarAlgebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl choice_eq _ _ := StarSubalgebra.copy_eq _ _ _ theorem adjoin_le {S : StarSubalgebra R A} {s : Set A} (hs : s ⊆ S) : adjoin R s ≤ S := StarAlgebra.gc.l_le hs @[simp] theorem adjoin_le_iff {S : StarSubalgebra R A} {s : Set A} : adjoin R s ≤ S ↔ s ⊆ S := StarAlgebra.gc _ _ @[gcongr] theorem adjoin_mono {s t : Set A} (H : s ⊆ t) : adjoin R s ≤ adjoin R t := StarAlgebra.gc.monotone_l H @[simp] lemma adjoin_eq (S : StarSubalgebra R A) : adjoin R (S : Set A) = S := le_antisymm (adjoin_le le_rfl) (subset_adjoin R (S : Set A)) open Submodule in lemma adjoin_eq_span (s : Set A) : Subalgebra.toSubmodule (adjoin R s).toSubalgebra = span R (Submonoid.closure (s ∪ star s)) := by rw [adjoin_toSubalgebra, Algebra.adjoin_eq_span] open Submodule in lemma adjoin_nonUnitalStarSubalgebra_eq_span (s : NonUnitalStarSubalgebra R A) : (adjoin R (s : Set A)).toSubalgebra.toSubmodule = span R {1} ⊔ s.toSubmodule := by rw [adjoin_eq_span, Submonoid.closure_eq_one_union, span_union, ← NonUnitalStarAlgebra.adjoin_eq_span, NonUnitalStarAlgebra.adjoin_eq] theorem _root_.Subalgebra.starClosure_eq_adjoin (S : Subalgebra R A) : S.starClosure = adjoin R (S : Set A) := le_antisymm (Subalgebra.starClosure_le_iff.2 <| subset_adjoin R (S : Set A)) (adjoin_le (le_sup_left : S ≤ S ⊔ star S)) /-- If some predicate holds for all `x ∈ (s : Set A)` and this predicate is closed under the `algebraMap`, addition, multiplication and star operations, then it holds for `a ∈ adjoin R s`. -/ @[elab_as_elim] theorem adjoin_induction {s : Set A} {p : (x : A) → x ∈ adjoin R s → Prop} (mem : ∀ (x) (h : x ∈ s), p x (subset_adjoin R s h)) (algebraMap : ∀ r, p (_root_.algebraMap R _ r) (_root_.algebraMap_mem _ r)) (add : ∀ x y hx hy, p x hx → p y hy → p (x + y) (add_mem hx hy)) (mul : ∀ x y hx hy, p x hx → p y hy → p (x * y) (mul_mem hx hy)) (star : ∀ x hx, p x hx → p (star x) (star_mem hx)) {a : A} (ha : a ∈ adjoin R s) : p a ha := by refine Algebra.adjoin_induction (fun x hx ↦ ?_) algebraMap add mul ha simp only [Set.mem_union, Set.mem_star] at hx obtain (hx | hx) := hx · exact mem x hx · simpa using star _ (Algebra.subset_adjoin (by simpa using Or.inl hx)) (mem _ hx) @[elab_as_elim] theorem adjoin_induction₂ {s : Set A} {p : (x y : A) → x ∈ adjoin R s → y ∈ adjoin R s → Prop} (mem_mem : ∀ (x) (y) (hx : x ∈ s) (hy : y ∈ s), p x y (subset_adjoin R s hx) (subset_adjoin R s hy)) (algebraMap_both : ∀ r₁ r₂, p (algebraMap R A r₁) (algebraMap R A r₂) (_root_.algebraMap_mem _ r₁) (_root_.algebraMap_mem _ r₂)) (algebraMap_left : ∀ (r) (x) (hx : x ∈ s), p (algebraMap R A r) x (_root_.algebraMap_mem _ r) (subset_adjoin R s hx)) (algebraMap_right : ∀ (r) (x) (hx : x ∈ s), p x (algebraMap R A r) (subset_adjoin R s hx) (_root_.algebraMap_mem _ r)) (add_left : ∀ x y z hx hy hz, p x z hx hz → p y z hy hz → p (x + y) z (add_mem hx hy) hz) (add_right : ∀ x y z hx hy hz, p x y hx hy → p x z hx hz → p x (y + z) hx (add_mem hy hz)) (mul_left : ∀ x y z hx hy hz, p x z hx hz → p y z hy hz → p (x * y) z (mul_mem hx hy) hz) (mul_right : ∀ x y z hx hy hz, p x y hx hy → p x z hx hz → p x (y * z) hx (mul_mem hy hz)) (star_left : ∀ x y hx hy, p x y hx hy → p (star x) y (star_mem hx) hy) (star_right : ∀ x y hx hy, p x y hx hy → p x (star y) hx (star_mem hy)) {a b : A} (ha : a ∈ adjoin R s) (hb : b ∈ adjoin R s) : p a b ha hb := by induction hb using adjoin_induction with | mem z hz => induction ha using adjoin_induction with | mem _ h => exact mem_mem _ _ h hz | algebraMap _ => exact algebraMap_left _ _ hz | mul _ _ _ _ h₁ h₂ => exact mul_left _ _ _ _ _ _ h₁ h₂ | add _ _ _ _ h₁ h₂ => exact add_left _ _ _ _ _ _ h₁ h₂ | star _ _ h => exact star_left _ _ _ _ h | algebraMap r => induction ha using adjoin_induction with | mem _ h => exact algebraMap_right _ _ h | algebraMap _ => exact algebraMap_both _ _ | mul _ _ _ _ h₁ h₂ => exact mul_left _ _ _ _ _ _ h₁ h₂ | add _ _ _ _ h₁ h₂ => exact add_left _ _ _ _ _ _ h₁ h₂ | star _ _ h => exact star_left _ _ _ _ h | mul _ _ _ _ h₁ h₂ => exact mul_right _ _ _ _ _ _ h₁ h₂ | add _ _ _ _ h₁ h₂ => exact add_right _ _ _ _ _ _ h₁ h₂ | star _ _ h => exact star_right _ _ _ _ h /-- The difference with `StarSubalgebra.adjoin_induction` is that this acts on the subtype. -/ @[elab_as_elim] theorem adjoin_induction_subtype {s : Set A} {p : adjoin R s → Prop} (a : adjoin R s) (mem : ∀ (x) (h : x ∈ s), p ⟨x, subset_adjoin R s h⟩) (algebraMap : ∀ r, p (algebraMap R _ r)) (add : ∀ x y, p x → p y → p (x + y)) (mul : ∀ x y, p x → p y → p (x * y)) (star : ∀ x, p x → p (star x)) : p a := Subtype.recOn a fun b hb => by induction hb using adjoin_induction with | mem _ h => exact mem _ h | algebraMap _ => exact algebraMap _ | mul _ _ _ _ h₁ h₂ => exact mul _ _ h₁ h₂ | add _ _ _ _ h₁ h₂ => exact add _ _ h₁ h₂ | star _ _ h => exact star _ h variable (R) lemma adjoin_le_centralizer_centralizer (s : Set A) : adjoin R s ≤ centralizer R (centralizer R s) := by rw [← toSubalgebra_le_iff, centralizer_toSubalgebra, adjoin_toSubalgebra] convert Algebra.adjoin_le_centralizer_centralizer R (s ∪ star s) rw [StarMemClass.star_coe_eq] simp /-- If all elements of `s : Set A` commute pairwise and also commute pairwise with elements of `star s`, then `StarSubalgebra.adjoin R s` is commutative. See note [reducible non-instances]. -/ abbrev adjoinCommSemiringOfComm {s : Set A} (hcomm : ∀ a ∈ s, ∀ b ∈ s, a * b = b * a) (hcomm_star : ∀ a ∈ s, ∀ b ∈ s, a * star b = star b * a) : CommSemiring (adjoin R s) := { (adjoin R s).toSemiring with mul_comm := fun ⟨_, h₁⟩ ⟨_, h₂⟩ ↦ by have hcomm : ∀ a ∈ s ∪ star s, ∀ b ∈ s ∪ star s, a * b = b * a := fun a ha b hb ↦ Set.union_star_self_comm (fun _ ha _ hb ↦ hcomm _ hb _ ha) (fun _ ha _ hb ↦ hcomm_star _ hb _ ha) b hb a ha have := adjoin_le_centralizer_centralizer R s apply this at h₁ apply this at h₂ rw [← SetLike.mem_coe, coe_centralizer_centralizer] at h₁ h₂ exact Subtype.ext <| Set.centralizer_centralizer_comm_of_comm hcomm _ h₁ _ h₂ } /-- If all elements of `s : Set A` commute pairwise and also commute pairwise with elements of `star s`, then `StarSubalgebra.adjoin R s` is commutative. See note [reducible non-instances]. -/ abbrev adjoinCommRingOfComm (R : Type u) {A : Type v} [CommRing R] [StarRing R] [Ring A] [Algebra R A] [StarRing A] [StarModule R A] {s : Set A} (hcomm : ∀ a : A, a ∈ s → ∀ b : A, b ∈ s → a * b = b * a) (hcomm_star : ∀ a : A, a ∈ s → ∀ b : A, b ∈ s → a * star b = star b * a) : CommRing (adjoin R s) := { StarAlgebra.adjoinCommSemiringOfComm R hcomm hcomm_star, (adjoin R s).toSubalgebra.toRing with } /-- The star subalgebra `StarSubalgebra.adjoin R {x}` generated by a single `x : A` is commutative if `x` is normal. -/ instance adjoinCommSemiringOfIsStarNormal (x : A) [IsStarNormal x] : CommSemiring (adjoin R ({x} : Set A)) := adjoinCommSemiringOfComm R (fun a ha b hb => by rw [Set.mem_singleton_iff] at ha hb rw [ha, hb]) fun a ha b hb => by rw [Set.mem_singleton_iff] at ha hb simpa only [ha, hb] using (star_comm_self' x).symm /-- The star subalgebra `StarSubalgebra.adjoin R {x}` generated by a single `x : A` is commutative if `x` is normal. -/ instance adjoinCommRingOfIsStarNormal (R : Type u) {A : Type v} [CommRing R] [StarRing R] [Ring A] [Algebra R A] [StarRing A] [StarModule R A] (x : A) [IsStarNormal x] : CommRing (adjoin R ({x} : Set A)) := { (adjoin R ({x} : Set A)).toSubalgebra.toRing with mul_comm := mul_comm } end StarAlgebra /-! ### Complete lattice structure -/ namespace StarSubalgebra variable {F R A B : Type*} [CommSemiring R] [StarRing R] variable [Semiring A] [Algebra R A] [StarRing A] [StarModule R A] variable [Semiring B] [Algebra R B] [StarRing B] [StarModule R B] instance completeLattice : CompleteLattice (StarSubalgebra R A) where __ := GaloisInsertion.liftCompleteLattice StarAlgebra.gi bot := { toSubalgebra := ⊥, star_mem' := fun ⟨r, hr⟩ => ⟨star r, hr ▸ algebraMap_star_comm _⟩ } bot_le S := (bot_le : ⊥ ≤ S.toSubalgebra) instance inhabited : Inhabited (StarSubalgebra R A) := ⟨⊤⟩ @[simp, norm_cast] theorem coe_top : (↑(⊤ : StarSubalgebra R A) : Set A) = Set.univ := rfl @[simp] theorem mem_top {x : A} : x ∈ (⊤ : StarSubalgebra R A) := Set.mem_univ x @[simp] theorem top_toSubalgebra : (⊤ : StarSubalgebra R A).toSubalgebra = ⊤ := by ext; simp -- Porting note: Lean can no longer prove this by `rfl`, it times out @[simp] theorem toSubalgebra_eq_top {S : StarSubalgebra R A} : S.toSubalgebra = ⊤ ↔ S = ⊤ := StarSubalgebra.toSubalgebra_injective.eq_iff' top_toSubalgebra theorem mem_sup_left {S T : StarSubalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T := have : S ≤ S ⊔ T := le_sup_left; (this ·) theorem mem_sup_right {S T : StarSubalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T := have : T ≤ S ⊔ T := le_sup_right; (this ·) theorem mul_mem_sup {S T : StarSubalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T := mul_mem (mem_sup_left hx) (mem_sup_right hy) theorem map_sup (f : A →⋆ₐ[R] B) (S T : StarSubalgebra R A) : map f (S ⊔ T) = map f S ⊔ map f T := (StarSubalgebra.gc_map_comap f).l_sup theorem map_inf (f : A →⋆ₐ[R] B) (hf : Function.Injective f) (S T : StarSubalgebra R A) : map f (S ⊓ T) = map f S ⊓ map f T := SetLike.coe_injective (Set.image_inter hf) @[simp, norm_cast] theorem coe_inf (S T : StarSubalgebra R A) : (↑(S ⊓ T) : Set A) = (S : Set A) ∩ T := rfl @[simp] theorem mem_inf {S T : StarSubalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl @[simp] theorem inf_toSubalgebra (S T : StarSubalgebra R A) : (S ⊓ T).toSubalgebra = S.toSubalgebra ⊓ T.toSubalgebra := by ext; simp -- Porting note: Lean can no longer prove this by `rfl`, it times out @[simp, norm_cast] theorem coe_sInf (S : Set (StarSubalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s := sInf_image theorem mem_sInf {S : Set (StarSubalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂] @[simp] theorem sInf_toSubalgebra (S : Set (StarSubalgebra R A)) : (sInf S).toSubalgebra = sInf (StarSubalgebra.toSubalgebra '' S) := SetLike.coe_injective <| by simp @[simp, norm_cast] theorem coe_iInf {ι : Sort*} {S : ι → StarSubalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by simp [iInf] theorem mem_iInf {ι : Sort*} {S : ι → StarSubalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by simp only [iInf, mem_sInf, Set.forall_mem_range] theorem map_iInf {ι : Sort*} [Nonempty ι] (f : A →⋆ₐ[R] B) (hf : Function.Injective f) (s : ι → StarSubalgebra R A) : map f (iInf s) = ⨅ (i : ι), map f (s i) := by apply SetLike.coe_injective simpa using (Set.injOn_of_injective hf).image_iInter_eq (s := SetLike.coe ∘ s) @[simp] theorem iInf_toSubalgebra {ι : Sort*} (S : ι → StarSubalgebra R A) : (⨅ i, S i).toSubalgebra = ⨅ i, (S i).toSubalgebra := SetLike.coe_injective <| by simp theorem bot_toSubalgebra : (⊥ : StarSubalgebra R A).toSubalgebra = ⊥ := rfl theorem mem_bot {x : A} : x ∈ (⊥ : StarSubalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl @[simp, norm_cast] theorem coe_bot : ((⊥ : StarSubalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl theorem eq_top_iff {S : StarSubalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S := ⟨fun h x => by rw [h]; exact mem_top, fun h => by ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩ end StarSubalgebra namespace StarAlgHom open StarSubalgebra StarAlgebra variable {F R A B : Type*} [CommSemiring R] [StarRing R] variable [Semiring A] [Algebra R A] [StarRing A] variable [Semiring B] [Algebra R B] [StarRing B] section variable [StarModule R A] theorem ext_adjoin {s : Set A} [FunLike F (adjoin R s) B] [AlgHomClass F R (adjoin R s) B] [StarHomClass F (adjoin R s) B] {f g : F} (h : ∀ x : adjoin R s, (x : A) ∈ s → f x = g x) : f = g := by refine DFunLike.ext f g fun a => adjoin_induction_subtype (p := fun y => f y = g y) a (fun x hx => ?_) (fun r => ?_) (fun x y hx hy => ?_) (fun x y hx hy => ?_) fun x hx => ?_ · exact h ⟨x, subset_adjoin R s hx⟩ hx · simp only [AlgHomClass.commutes] · simp only [map_add, map_add, hx, hy] · simp only [map_mul, map_mul, hx, hy] · simp only [map_star, hx] theorem ext_adjoin_singleton {a : A} [FunLike F (adjoin R ({a} : Set A)) B] [AlgHomClass F R (adjoin R ({a} : Set A)) B] [StarHomClass F (adjoin R ({a} : Set A)) B] {f g : F} (h : f ⟨a, self_mem_adjoin_singleton R a⟩ = g ⟨a, self_mem_adjoin_singleton R a⟩) : f = g := ext_adjoin fun x hx => (show x = ⟨a, self_mem_adjoin_singleton R a⟩ from Subtype.ext <| Set.mem_singleton_iff.mp hx).symm ▸ h variable [FunLike F A B] [AlgHomClass F R A B] [StarHomClass F A B] (f g : F) /-- The equalizer of two star `R`-algebra homomorphisms. -/ def equalizer : StarSubalgebra R A where toSubalgebra := AlgHom.equalizer (f : A →ₐ[R] B) g star_mem' {a} (ha : f a = g a) := by simpa only [← map_star] using congrArg star ha @[simp] theorem mem_equalizer (x : A) : x ∈ StarAlgHom.equalizer f g ↔ f x = g x := Iff.rfl theorem adjoin_le_equalizer {s : Set A} (h : s.EqOn f g) : adjoin R s ≤ StarAlgHom.equalizer f g := adjoin_le h theorem ext_of_adjoin_eq_top {s : Set A} (h : adjoin R s = ⊤) ⦃f g : F⦄ (hs : s.EqOn f g) : f = g := DFunLike.ext f g fun _x => StarAlgHom.adjoin_le_equalizer f g hs <| h.symm ▸ trivial variable [StarModule R B] theorem map_adjoin (f : A →⋆ₐ[R] B) (s : Set A) : map f (adjoin R s) = adjoin R (f '' s) := GaloisConnection.l_comm_of_u_comm Set.image_preimage (gc_map_comap f) StarAlgebra.gc StarAlgebra.gc fun _ => rfl /-- Range of a `StarAlgHom` as a star subalgebra. -/ protected def range (φ : A →⋆ₐ[R] B) : StarSubalgebra R B where toSubalgebra := φ.toAlgHom.range star_mem' := by rintro _ ⟨b, rfl⟩; exact ⟨star b, map_star φ b⟩ theorem range_eq_map_top (φ : A →⋆ₐ[R] B) : φ.range = (⊤ : StarSubalgebra R A).map φ := StarSubalgebra.ext fun x => ⟨by rintro ⟨a, ha⟩; exact ⟨a, by simp, ha⟩, by rintro ⟨a, -, ha⟩; exact ⟨a, ha⟩⟩ end variable [StarModule R B] /-- Restriction of the codomain of a `StarAlgHom` to a star subalgebra containing the range. -/ protected def codRestrict (f : A →⋆ₐ[R] B) (S : StarSubalgebra R B) (hf : ∀ x, f x ∈ S) : A →⋆ₐ[R] S where toAlgHom := AlgHom.codRestrict f.toAlgHom S.toSubalgebra hf map_star' := fun x => Subtype.ext (map_star f x) @[simp] theorem coe_codRestrict (f : A →⋆ₐ[R] B) (S : StarSubalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) : ↑(f.codRestrict S hf x) = f x := rfl @[simp] theorem subtype_comp_codRestrict (f : A →⋆ₐ[R] B) (S : StarSubalgebra R B) (hf : ∀ x : A, f x ∈ S) : S.subtype.comp (f.codRestrict S hf) = f := StarAlgHom.ext <| coe_codRestrict _ S hf theorem injective_codRestrict (f : A →⋆ₐ[R] B) (S : StarSubalgebra R B) (hf : ∀ x : A, f x ∈ S) : Function.Injective (StarAlgHom.codRestrict f S hf) ↔ Function.Injective f := ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy :)⟩ /-- Restriction of the codomain of a `StarAlgHom` to its range. -/ def rangeRestrict (f : A →⋆ₐ[R] B) : A →⋆ₐ[R] f.range := StarAlgHom.codRestrict f _ fun x => ⟨x, rfl⟩ /-- The `StarAlgEquiv` onto the range corresponding to an injective `StarAlgHom`. -/ @[simps] noncomputable def _root_.StarAlgEquiv.ofInjective (f : A →⋆ₐ[R] B) (hf : Function.Injective f) : A ≃⋆ₐ[R] f.range := { AlgEquiv.ofInjective (f : A →ₐ[R] B) hf with toFun := f.rangeRestrict map_star' := fun a => Subtype.ext (map_star f a) map_smul' := fun r a => Subtype.ext (map_smul f r a) } end StarAlgHom section RestrictScalars variable (R : Type*) {S A B : Type*} [CommSemiring R] [CommSemiring S] [Semiring A] [Semiring B] [Algebra R S] [Algebra S A] [Algebra S B] [Algebra R A] [Algebra R B] [IsScalarTower R S A] [IsScalarTower R S B] [Star A] [Star B] @[simps!] def StarAlgHom.restrictScalars (f : A →⋆ₐ[S] B) : A →⋆ₐ[R] B where toAlgHom := f.toAlgHom.restrictScalars R map_star' := map_star f theorem StarAlgHom.restrictScalars_injective : Function.Injective (StarAlgHom.restrictScalars R : (A →⋆ₐ[S] B) → A →⋆ₐ[R] B) := fun f g h => StarAlgHom.ext fun x => show f.restrictScalars R x = g.restrictScalars R x from DFunLike.congr_fun h x @[simps] def StarAlgEquiv.restrictScalars (f : A ≃⋆ₐ[S] B) : A ≃⋆ₐ[R] B := { (f : A →⋆ₐ[S] B).restrictScalars R, f with toFun := f map_smul' := map_smul ((f : A →⋆ₐ[S] B).restrictScalars R) } theorem StarAlgEquiv.restrictScalars_injective : Function.Injective (StarAlgEquiv.restrictScalars R : (A ≃⋆ₐ[S] B) → A ≃⋆ₐ[R] B) := fun f g h => StarAlgEquiv.ext fun x => show f.restrictScalars R x = g.restrictScalars R x from DFunLike.congr_fun h x end RestrictScalars variable {R A : Type*} [CommSemiring R] [StarRing R] [Semiring A] [StarRing A] [Algebra R A] [StarModule R A] /-- Turn a non-unital star subalgebra containing `1` into a `StarSubalgebra`. -/ def NonUnitalStarSubalgebra.toStarSubalgebra (S : NonUnitalStarSubalgebra R A) (h1 : 1 ∈ S) : StarSubalgebra R A where __ := S one_mem' := h1 algebraMap_mem' r := (Algebra.algebraMap_eq_smul_one (R := R) (A := A) r).symm ▸ SMulMemClass.smul_mem r h1 lemma StarSubalgebra.toNonUnitalStarSubalgebra_toStarSubalgebra (S : StarSubalgebra R A) : S.toNonUnitalStarSubalgebra.toStarSubalgebra S.one_mem' = S := by cases S; rfl lemma NonUnitalStarSubalgebra.toStarSubalgebra_toNonUnitalStarSubalgebra (S : NonUnitalStarSubalgebra R A) (h1 : (1 : A) ∈ S) : (S.toStarSubalgebra h1).toNonUnitalStarSubalgebra = S := by cases S; rfl variable (R) lemma NonUnitalStarAlgebra.adjoin_le_starAlgebra_adjoin (s : Set A) : adjoin R s ≤ (StarAlgebra.adjoin R s).toNonUnitalStarSubalgebra := adjoin_le <| StarAlgebra.subset_adjoin R s lemma StarAlgebra.adjoin_nonUnitalStarSubalgebra (s : Set A) : adjoin R (NonUnitalStarAlgebra.adjoin R s : Set A) = adjoin R s := le_antisymm (adjoin_le <| NonUnitalStarAlgebra.adjoin_le_starAlgebra_adjoin R s) (adjoin_le <| (NonUnitalStarAlgebra.subset_adjoin R s).trans <| subset_adjoin R _)
.lake/packages/mathlib/Mathlib/Algebra/Star/UnitaryStarAlgAut.lean
import Mathlib.Algebra.Ring.Action.ConjAct import Mathlib.Algebra.Star.StarAlgHom import Mathlib.Algebra.Star.Unitary /-! # The ⋆-algebra automorphism given by a unitary element This file defines the ⋆-algebra automorphism on `R` given by a unitary `u`, which is `Unitary.conjStarAlgAut S R u`, defined to be `x ↦ u * x * star u`. -/ namespace Unitary variable {S R : Type*} [Semiring R] [StarMul R] [SMul S R] [IsScalarTower S R R] [SMulCommClass S R R] variable (S R) in /-- Each unitary element `u` defines a ⋆-algebra automorphism such that `x ↦ u * x * star u`. This is the ⋆-algebra automorphism version of a specialized version of `MulSemiringAction.toAlgAut`. -/ def conjStarAlgAut : unitary R →* (R ≃⋆ₐ[S] R) where toFun u := { toRingEquiv := MulSemiringAction.toRingEquiv _ R (ConjAct.toConjAct <| toUnits u) map_smul' _ _ := smul_comm _ _ _ |>.symm map_star' _ := by dsimp [ConjAct.units_smul_def] simp [mul_assoc, ← Unitary.star_eq_inv] } map_one' := by ext; simp map_mul' g h := by ext; simp [mul_smul] @[simp] theorem conjStarAlgAut_apply (u : unitary R) (x : R) : conjStarAlgAut S R u x = u * x * (star u : R) := rfl theorem conjStarAlgAut_symm_apply (u : unitary R) (x : R) : (conjStarAlgAut S R u).symm x = (star u : R) * x * u := rfl theorem conjStarAlgAut_star_apply (u : unitary R) (x : R) : conjStarAlgAut S R (star u) x = (star u : R) * x * u := by simp @[simp] theorem conjStarAlgAut_symm (u : unitary R) : (conjStarAlgAut S R u).symm = conjStarAlgAut S R (star u) := by ext; simp [conjStarAlgAut_symm_apply] theorem conjStarAlgAut_trans_conjStarAlgAut (u₁ u₂ : unitary R) : (conjStarAlgAut S R u₁).trans (conjStarAlgAut S R u₂) = conjStarAlgAut S R (u₂ * u₁) := map_mul _ _ _ |>.symm theorem conjStarAlgAut_mul_apply (u₁ u₂ : unitary R) (x : R) : conjStarAlgAut S R (u₁ * u₂) x = conjStarAlgAut S R u₁ (conjStarAlgAut S R u₂ x) := by simp theorem toRingEquiv_conjStarAlgAut (u : unitary R) : (conjStarAlgAut S R u).toRingEquiv = MulSemiringAction.toRingEquiv _ R (ConjAct.toConjAct <| toUnits u) := rfl theorem toAlgEquiv_conjStarAlgAut {S : Type*} [CommSemiring S] [Algebra S R] (u : unitary R) : (conjStarAlgAut S R u).toAlgEquiv = MulSemiringAction.toAlgEquiv _ R (ConjAct.toConjAct <| toUnits u) := rfl end Unitary
.lake/packages/mathlib/Mathlib/Algebra/Star/Module.lean
import Mathlib.Algebra.Star.SelfAdjoint import Mathlib.Algebra.Module.Basic import Mathlib.Algebra.Module.Equiv.Defs import Mathlib.Algebra.Module.LinearMap.Star import Mathlib.Algebra.Module.Rat import Mathlib.LinearAlgebra.Prod /-! # The star operation, bundled as a star-linear equiv We define `starLinearEquiv`, which is the star operation bundled as a star-linear map. It is defined on a star algebra `A` over the base ring `R`. This file also provides some lemmas that need `Algebra.Module.Basic` imported to prove. ## TODO - Define `starLinearEquiv` for noncommutative `R`. We only the commutative case for now since, in the noncommutative case, the ring hom needs to reverse the order of multiplication. This requires a ring hom of type `R →+* Rᵐᵒᵖ`, which is very undesirable in the commutative case. One way out would be to define a new typeclass `IsOp R S` and have an instance `IsOp R R` for commutative `R`. - Also note that such a definition involving `Rᵐᵒᵖ` or `is_op R S` would require adding the appropriate `RingHomInvPair` instances to be able to define the semilinear equivalence. -/ section SMulLemmas variable {R M : Type*} @[simp] theorem star_natCast_smul [Semiring R] [AddCommMonoid M] [Module R M] [StarAddMonoid M] (n : ℕ) (x : M) : star ((n : R) • x) = (n : R) • star x := map_natCast_smul (starAddEquiv : M ≃+ M) R R n x @[simp] theorem star_intCast_smul [Ring R] [AddCommGroup M] [Module R M] [StarAddMonoid M] (n : ℤ) (x : M) : star ((n : R) • x) = (n : R) • star x := map_intCast_smul (starAddEquiv : M ≃+ M) R R n x @[simp] theorem star_inv_natCast_smul [DivisionSemiring R] [AddCommMonoid M] [Module R M] [StarAddMonoid M] (n : ℕ) (x : M) : star ((n⁻¹ : R) • x) = (n⁻¹ : R) • star x := map_inv_natCast_smul (starAddEquiv : M ≃+ M) R R n x @[simp] theorem star_inv_intCast_smul [DivisionRing R] [AddCommGroup M] [Module R M] [StarAddMonoid M] (n : ℤ) (x : M) : star ((n⁻¹ : R) • x) = (n⁻¹ : R) • star x := map_inv_intCast_smul (starAddEquiv : M ≃+ M) R R n x @[simp] theorem star_ratCast_smul [DivisionRing R] [AddCommGroup M] [Module R M] [StarAddMonoid M] (n : ℚ) (x : M) : star ((n : R) • x) = (n : R) • star x := map_ratCast_smul (starAddEquiv : M ≃+ M) _ _ _ x /-! Per the naming convention, these two lemmas call `(q • ·)` `nnrat_smul` and `rat_smul` respectively, rather than `nnqsmul` and `qsmul` because the latter are reserved to the actions coming from `DivisionSemiring` and `DivisionRing`. We provide aliases with `nnqsmul` and `qsmul` for discoverability. -/ /-- Note that this lemma holds for an arbitrary `ℚ≥0`-action, rather than merely one coming from a `DivisionSemiring`. We keep both the `nnqsmul` and `nnrat_smul` naming conventions for discoverability. See `star_nnqsmul`. -/ @[simp high] lemma star_nnrat_smul [AddCommMonoid R] [StarAddMonoid R] [Module ℚ≥0 R] (q : ℚ≥0) (x : R) : star (q • x) = q • star x := map_nnrat_smul (starAddEquiv : R ≃+ R) _ _ /-- Note that this lemma holds for an arbitrary `ℚ`-action, rather than merely one coming from a `DivisionRing`. We keep both the `qsmul` and `rat_smul` naming conventions for discoverability. See `star_qsmul`. -/ @[simp high] lemma star_rat_smul [AddCommGroup R] [StarAddMonoid R] [Module ℚ R] (q : ℚ) (x : R) : star (q • x) = q • star x := map_rat_smul (starAddEquiv : R ≃+ R) _ _ /-- Note that this lemma holds for an arbitrary `ℚ≥0`-action, rather than merely one coming from a `DivisionSemiring`. We keep both the `nnqsmul` and `nnrat_smul` naming conventions for discoverability. See `star_nnrat_smul`. -/ alias star_nnqsmul := star_nnrat_smul /-- Note that this lemma holds for an arbitrary `ℚ`-action, rather than merely one coming from a `DivisionRing`. We keep both the `qsmul` and `rat_smul` naming conventions for discoverability. See `star_rat_smul`. -/ alias star_qsmul := star_rat_smul instance StarAddMonoid.toStarModuleNNRat [AddCommMonoid R] [Module ℚ≥0 R] [StarAddMonoid R] : StarModule ℚ≥0 R where star_smul := star_nnrat_smul instance StarAddMonoid.toStarModuleRat [AddCommGroup R] [Module ℚ R] [StarAddMonoid R] : StarModule ℚ R where star_smul := star_rat_smul end SMulLemmas /-- If `A` is a module over a commutative `R` with compatible actions, then `star` is a semilinear equivalence. -/ @[simps] def starLinearEquiv (R : Type*) {A : Type*} [CommSemiring R] [StarRing R] [AddCommMonoid A] [StarAddMonoid A] [Module R A] [StarModule R A] : A ≃ₗ⋆[R] A := { starAddEquiv with toFun := star map_smul' := star_smul } section SelfSkewAdjoint variable (R : Type*) (A : Type*) [Semiring R] [StarMul R] [TrivialStar R] [AddCommGroup A] [Module R A] [StarAddMonoid A] [StarModule R A] /-- The self-adjoint elements of a star module, as a submodule. -/ def selfAdjoint.submodule : Submodule R A := { selfAdjoint A with smul_mem' := fun _ _ => (IsSelfAdjoint.all _).smul } /-- The skew-adjoint elements of a star module, as a submodule. -/ def skewAdjoint.submodule : Submodule R A := { skewAdjoint A with smul_mem' := skewAdjoint.smul_mem } variable {A} [Invertible (2 : R)] /-- The self-adjoint part of an element of a star module, as a linear map. -/ @[simps] def selfAdjointPart : A →ₗ[R] selfAdjoint A where toFun x := ⟨(⅟2 : R) • (x + star x), by rw [selfAdjoint.mem_iff, star_smul, star_trivial, star_add, star_star, add_comm]⟩ map_add' x y := by ext simp [add_add_add_comm] map_smul' r x := by ext simp [← mul_smul, show ⅟2 * r = r * ⅟2 from Commute.invOf_left <| (2 : ℕ).cast_commute r] /-- The skew-adjoint part of an element of a star module, as a linear map. -/ @[simps] def skewAdjointPart : A →ₗ[R] skewAdjoint A where toFun x := ⟨(⅟2 : R) • (x - star x), by simp only [skewAdjoint.mem_iff, star_smul, star_sub, star_star, star_trivial, ← smul_neg, neg_sub]⟩ map_add' x y := by ext simp only [sub_add, ← smul_add, sub_sub_eq_add_sub, star_add, AddSubgroup.coe_add] map_smul' r x := by ext simp [← mul_smul, ← smul_sub, show r * ⅟2 = ⅟2 * r from Commute.invOf_right <| (2 : ℕ).commute_cast r] theorem StarModule.selfAdjointPart_add_skewAdjointPart (x : A) : (selfAdjointPart R x : A) + skewAdjointPart R x = x := by simp only [smul_sub, selfAdjointPart_apply_coe, smul_add, skewAdjointPart_apply_coe, add_add_sub_cancel, invOf_two_smul_add_invOf_two_smul] theorem IsSelfAdjoint.coe_selfAdjointPart_apply {x : A} (hx : IsSelfAdjoint x) : (selfAdjointPart R x : A) = x := by rw [selfAdjointPart_apply_coe, hx.star_eq, smul_add, invOf_two_smul_add_invOf_two_smul] theorem IsSelfAdjoint.selfAdjointPart_apply {x : A} (hx : IsSelfAdjoint x) : selfAdjointPart R x = ⟨x, hx⟩ := Subtype.eq (hx.coe_selfAdjointPart_apply R) @[simp] theorem selfAdjointPart_comp_subtype_selfAdjoint : (selfAdjointPart R).comp (selfAdjoint.submodule R A).subtype = .id := LinearMap.ext fun x ↦ x.2.selfAdjointPart_apply R theorem IsSelfAdjoint.skewAdjointPart_apply {x : A} (hx : IsSelfAdjoint x) : skewAdjointPart R x = 0 := Subtype.eq <| by rw [skewAdjointPart_apply_coe, hx.star_eq, sub_self, smul_zero, ZeroMemClass.coe_zero] @[simp] theorem skewAdjointPart_comp_subtype_selfAdjoint : (skewAdjointPart R).comp (selfAdjoint.submodule R A).subtype = 0 := LinearMap.ext fun x ↦ x.2.skewAdjointPart_apply R @[simp] theorem selfAdjointPart_comp_subtype_skewAdjoint : (selfAdjointPart R).comp (skewAdjoint.submodule R A).subtype = 0 := LinearMap.ext fun ⟨x, (hx : _ = _)⟩ ↦ Subtype.eq <| by simp [hx] @[simp] theorem skewAdjointPart_comp_subtype_skewAdjoint : (skewAdjointPart R).comp (skewAdjoint.submodule R A).subtype = .id := LinearMap.ext fun ⟨x, (hx : _ = _)⟩ ↦ Subtype.eq <| by simp only [LinearMap.comp_apply, Submodule.subtype_apply, skewAdjointPart_apply_coe, hx, sub_neg_eq_add, smul_add, invOf_two_smul_add_invOf_two_smul]; rfl variable (A) /-- The decomposition of elements of a star module into their self- and skew-adjoint parts, as a linear equivalence. -/ @[simps!] def StarModule.decomposeProdAdjoint : A ≃ₗ[R] selfAdjoint A × skewAdjoint A := by refine LinearEquiv.ofLinear ((selfAdjointPart R).prod (skewAdjointPart R)) (LinearMap.coprod ((selfAdjoint.submodule R A).subtype) (skewAdjoint.submodule R A).subtype) ?_ (LinearMap.ext <| StarModule.selfAdjointPart_add_skewAdjointPart R) -- Note: with https://github.com/leanprover-community/mathlib4/pull/6965 `Submodule.coe_subtype` doesn't fire in `dsimp` or `simp` ext x <;> dsimp <;> erw [Submodule.coe_subtype, Submodule.coe_subtype] <;> simp end SelfSkewAdjoint section algebraMap variable {R A : Type*} [CommSemiring R] [StarRing R] [Semiring A] variable [StarMul A] [Algebra R A] [StarModule R A] @[simp] theorem algebraMap_star_comm (r : R) : algebraMap R A (star r) = star (algebraMap R A r) := by simp only [Algebra.algebraMap_eq_smul_one, star_smul, star_one] variable (A) in protected lemma IsSelfAdjoint.algebraMap {r : R} (hr : IsSelfAdjoint r) : IsSelfAdjoint (algebraMap R A r) := by simpa using congr(algebraMap R A $(hr.star_eq)) lemma isSelfAdjoint_algebraMap_iff {r : R} (h : Function.Injective (algebraMap R A)) : IsSelfAdjoint (algebraMap R A r) ↔ IsSelfAdjoint r := ⟨fun hr ↦ h <| algebraMap_star_comm r (A := A) ▸ hr.star_eq, IsSelfAdjoint.algebraMap A⟩ end algebraMap theorem IsIdempotentElem.star_iff {R : Type*} [Mul R] [StarMul R] {a : R} : IsIdempotentElem (star a) ↔ IsIdempotentElem a := by simp [IsIdempotentElem, ← star_mul] alias ⟨_, IsIdempotentElem.star⟩ := IsIdempotentElem.star_iff
.lake/packages/mathlib/Mathlib/Algebra/Star/Rat.lean
import Mathlib.Algebra.Field.Opposite import Mathlib.Algebra.Star.Basic import Mathlib.Data.NNRat.Defs import Mathlib.Data.Rat.Cast.Defs /-! # *-ring structure on ℚ and ℚ≥0. -/ instance Rat.instStarRing : StarRing ℚ := starRingOfComm instance NNRat.instStarRing : StarRing ℚ≥0 := starRingOfComm instance Rat.instTrivialStar : TrivialStar ℚ := ⟨fun _ ↦ rfl⟩ instance NNRat.instTrivialStar : TrivialStar ℚ≥0 := ⟨fun _ ↦ rfl⟩ variable {R : Type*} open MulOpposite @[simp, norm_cast] lemma star_nnratCast [DivisionSemiring R] [StarRing R] (q : ℚ≥0) : star (q : R) = q := (congr_arg unop <| map_nnratCast (starRingEquiv : R ≃+* Rᵐᵒᵖ) q).trans (unop_nnratCast _) @[simp, norm_cast] theorem star_ratCast [DivisionRing R] [StarRing R] (r : ℚ) : star (r : R) = r := (congr_arg unop <| map_ratCast (starRingEquiv : R ≃+* Rᵐᵒᵖ) r).trans (unop_ratCast _)
.lake/packages/mathlib/Mathlib/Algebra/Star/TensorProduct.lean
import Mathlib.Algebra.Star.Module import Mathlib.LinearAlgebra.TensorProduct.Basic /-! # The star structure on tensor products This file defines the `Star` structure on tensor products. This also defines the `StarAddMonoid` and `StarModule` instances for tensor products. -/ namespace TensorProduct variable {R A B : Type*} [CommSemiring R] [StarRing R] [AddCommMonoid A] [StarAddMonoid A] [Module R A] [StarModule R A] [AddCommMonoid B] [StarAddMonoid B] [Module R B] [StarModule R B] open scoped TensorProduct instance : Star (A ⊗[R] B) where star x := congr (starLinearEquiv R) (starLinearEquiv R) x @[simp] theorem star_tmul (x : A) (y : B) : star (x ⊗ₜ[R] y) = star x ⊗ₜ[R] star y := rfl noncomputable instance : InvolutiveStar (A ⊗[R] B) where star_involutive x := by simp_rw [star] rw [congr_congr] convert congr($congr_refl_refl x) <;> ext <;> simp noncomputable instance : StarAddMonoid (A ⊗[R] B) where star_add := LinearMap.map_add _ instance : StarModule R (A ⊗[R] B) where star_smul := LinearMap.map_smulₛₗ _ theorem _root_.starLinearEquiv_tensor : starLinearEquiv R (A := A ⊗[R] B) = congr (starLinearEquiv R) (starLinearEquiv R) := rfl end TensorProduct
.lake/packages/mathlib/Mathlib/Algebra/Star/SelfAdjoint.lean
import Mathlib.Algebra.Group.Subgroup.Defs import Mathlib.Algebra.Module.Defs import Mathlib.Algebra.Star.Rat /-! # Self-adjoint, skew-adjoint and normal elements of a star additive group This file defines `selfAdjoint R` (resp. `skewAdjoint R`), where `R` is a star additive group, as the additive subgroup containing the elements that satisfy `star x = x` (resp. `star x = -x`). This includes, for instance, (skew-)Hermitian operators on Hilbert spaces. We also define `IsStarNormal R`, a `Prop` that states that an element `x` satisfies `star x * x = x * star x`. ## Implementation notes * When `R` is a `StarModule R₂ R`, then `selfAdjoint R` has a natural `Module (selfAdjoint R₂) (selfAdjoint R)` structure. However, doing this literally would be undesirable since in the main case of interest (`R₂ = ℂ`) we want `Module ℝ (selfAdjoint R)` and not `Module (selfAdjoint ℂ) (selfAdjoint R)`. We solve this issue by adding the typeclass `[TrivialStar R₃]`, of which `ℝ` is an instance (registered in `Data/Real/Basic`), and then add a `[Module R₃ (selfAdjoint R)]` instance whenever we have `[Module R₃ R] [TrivialStar R₃]`. (Another approach would have been to define `[StarInvariantScalars R₃ R]` to express the fact that `star (x • v) = x • star v`, but this typeclass would have the disadvantage of taking two type arguments.) ## TODO * Define `IsSkewAdjoint` to match `IsSelfAdjoint`. * Define `fun z x => z * x * star z` (i.e. conjugation by `z`) as a monoid action of `R` on `R` (similar to the existing `ConjAct` for groups), and then state the fact that `selfAdjoint R` is invariant under it. -/ open Function variable {R A : Type*} /-- An element is self-adjoint if it is equal to its star. -/ def IsSelfAdjoint [Star R] (x : R) : Prop := star x = x /-- An element of a star monoid is normal if it commutes with its adjoint. -/ @[mk_iff] class IsStarNormal [Mul R] [Star R] (x : R) : Prop where /-- A normal element of a star monoid commutes with its adjoint. -/ star_comm_self : Commute (star x) x export IsStarNormal (star_comm_self) theorem star_comm_self' [Mul R] [Star R] (x : R) [IsStarNormal x] : star x * x = x * star x := IsStarNormal.star_comm_self namespace IsSelfAdjoint -- named to match `Commute.allₓ` /-- All elements are self-adjoint when `star` is trivial. -/ theorem all [Star R] [TrivialStar R] (r : R) : IsSelfAdjoint r := star_trivial _ theorem star_eq [Star R] {x : R} (hx : IsSelfAdjoint x) : star x = x := hx theorem _root_.isSelfAdjoint_iff [Star R] {x : R} : IsSelfAdjoint x ↔ star x = x := Iff.rfl @[simp] theorem star_iff [InvolutiveStar R] {x : R} : IsSelfAdjoint (star x) ↔ IsSelfAdjoint x := by simpa only [IsSelfAdjoint, star_star] using eq_comm @[simp] theorem star_mul_self [Mul R] [StarMul R] (x : R) : IsSelfAdjoint (star x * x) := by simp only [IsSelfAdjoint, star_mul, star_star] @[simp] theorem mul_star_self [Mul R] [StarMul R] (x : R) : IsSelfAdjoint (x * star x) := by simpa only [star_star] using star_mul_self (star x) /-- Self-adjoint elements commute if and only if their product is self-adjoint. -/ lemma commute_iff {R : Type*} [Mul R] [StarMul R] {x y : R} (hx : IsSelfAdjoint x) (hy : IsSelfAdjoint y) : Commute x y ↔ IsSelfAdjoint (x * y) := by refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · rw [isSelfAdjoint_iff, star_mul, hx.star_eq, hy.star_eq, h.eq] · simpa only [star_mul, hx.star_eq, hy.star_eq] using h.symm /-- Functions in a `StarHomClass` preserve self-adjoint elements. -/ @[aesop 10% apply] theorem map {F R S : Type*} [Star R] [Star S] [FunLike F R S] [StarHomClass F R S] {x : R} (hx : IsSelfAdjoint x) (f : F) : IsSelfAdjoint (f x) := show star (f x) = f x from map_star f x ▸ congr_arg f hx /- note: this lemma is *not* marked as `simp` so that Lean doesn't look for a `[TrivialStar R]` instance every time it sees `⊢ IsSelfAdjoint (f x)`, which will likely occur relatively often. -/ theorem _root_.isSelfAdjoint_map {F R S : Type*} [Star R] [Star S] [FunLike F R S] [StarHomClass F R S] [TrivialStar R] (f : F) (x : R) : IsSelfAdjoint (f x) := (IsSelfAdjoint.all x).map f @[aesop 10% apply] theorem isStarNormal {R : Type*} [Mul R] [Star R] {x : R} (hx : IsSelfAdjoint x) : IsStarNormal x := ⟨by simp only [Commute, SemiconjBy, hx.star_eq]⟩ section AddMonoid variable [AddMonoid R] [StarAddMonoid R] variable (R) in @[simp] protected theorem zero : IsSelfAdjoint (0 : R) := star_zero R @[aesop 90% apply] theorem add {x y : R} (hx : IsSelfAdjoint x) (hy : IsSelfAdjoint y) : IsSelfAdjoint (x + y) := by simp only [isSelfAdjoint_iff, star_add, hx.star_eq, hy.star_eq] end AddMonoid section AddGroup variable [AddGroup R] [StarAddMonoid R] @[aesop safe apply] theorem neg {x : R} (hx : IsSelfAdjoint x) : IsSelfAdjoint (-x) := by simp only [isSelfAdjoint_iff, star_neg, hx.star_eq] @[aesop 90% apply] theorem sub {x y : R} (hx : IsSelfAdjoint x) (hy : IsSelfAdjoint y) : IsSelfAdjoint (x - y) := by simp only [isSelfAdjoint_iff, star_sub, hx.star_eq, hy.star_eq] end AddGroup section AddCommMonoid variable [AddCommMonoid R] [StarAddMonoid R] @[simp] theorem add_star_self (x : R) : IsSelfAdjoint (x + star x) := by simp only [isSelfAdjoint_iff, add_comm, star_add, star_star] @[simp] theorem star_add_self (x : R) : IsSelfAdjoint (star x + x) := by simp only [isSelfAdjoint_iff, add_comm, star_add, star_star] end AddCommMonoid section Semigroup variable [Semigroup R] [StarMul R] @[aesop safe apply] theorem conjugate {x : R} (hx : IsSelfAdjoint x) (z : R) : IsSelfAdjoint (z * x * star z) := by simp only [isSelfAdjoint_iff, star_mul, star_star, mul_assoc, hx.star_eq] @[aesop safe apply] theorem conjugate' {x : R} (hx : IsSelfAdjoint x) (z : R) : IsSelfAdjoint (star z * x * z) := by simp only [isSelfAdjoint_iff, star_mul, star_star, mul_assoc, hx.star_eq] @[aesop 90% apply] theorem conjugate_self {x : R} (hx : IsSelfAdjoint x) {z : R} (hz : IsSelfAdjoint z) : IsSelfAdjoint (z * x * z) := by nth_rewrite 2 [← hz]; exact conjugate hx z end Semigroup section MulOneClass variable [MulOneClass R] [StarMul R] variable (R) @[simp] protected theorem one : IsSelfAdjoint (1 : R) := star_one R end MulOneClass section Monoid variable [Monoid R] [StarMul R] @[aesop safe apply] theorem pow {x : R} (hx : IsSelfAdjoint x) (n : ℕ) : IsSelfAdjoint (x ^ n) := by simp only [isSelfAdjoint_iff, star_pow, hx.star_eq] @[grind =] lemma _root_.IsUnit.isSelfAdjoint_conjugate_iff {a u : R} (hu : IsUnit u) : IsSelfAdjoint (u * a * star u) ↔ IsSelfAdjoint a := by simp [IsSelfAdjoint, mul_assoc, hu.mul_right_inj, hu.star.mul_left_inj] @[grind =] lemma _root_.IsUnit.isSelfAdjoint_conjugate_iff' {a u : R} (hu : IsUnit u) : IsSelfAdjoint (star u * a * u) ↔ IsSelfAdjoint a := by simpa using hu.star.isSelfAdjoint_conjugate_iff @[deprecated (since := "2025-09-28")] alias _root_.isSelfAdjoint_conjugate_iff_of_isUnit := IsUnit.isSelfAdjoint_conjugate_iff @[deprecated (since := "2025-09-28")] alias _root_.isSelfAdjoint_conjugate_iff_of_isUnit' := IsUnit.isSelfAdjoint_conjugate_iff' end Monoid section Semiring variable [Semiring R] [StarRing R] @[simp] protected theorem natCast (n : ℕ) : IsSelfAdjoint (n : R) := star_natCast _ @[simp] protected theorem ofNat (n : ℕ) [n.AtLeastTwo] : IsSelfAdjoint (ofNat(n) : R) := .natCast n end Semiring section CommSemigroup variable [CommSemigroup R] [StarMul R] theorem mul {x y : R} (hx : IsSelfAdjoint x) (hy : IsSelfAdjoint y) : IsSelfAdjoint (x * y) := by simp only [isSelfAdjoint_iff, star_mul', hx.star_eq, hy.star_eq] end CommSemigroup section CommSemiring variable {α : Type*} [CommSemiring α] [StarRing α] {a : α} open scoped ComplexConjugate lemma conj_eq (ha : IsSelfAdjoint a) : conj a = a := ha.star_eq end CommSemiring section Ring variable [Ring R] [StarRing R] @[simp] protected theorem intCast (z : ℤ) : IsSelfAdjoint (z : R) := star_intCast _ end Ring section Group variable [Group R] [StarMul R] @[aesop safe apply] theorem inv {x : R} (hx : IsSelfAdjoint x) : IsSelfAdjoint x⁻¹ := by simp only [isSelfAdjoint_iff, star_inv, hx.star_eq] @[aesop safe apply] theorem zpow {x : R} (hx : IsSelfAdjoint x) (n : ℤ) : IsSelfAdjoint (x ^ n) := by simp only [isSelfAdjoint_iff, star_zpow, hx.star_eq] end Group section GroupWithZero variable [GroupWithZero R] [StarMul R] @[aesop safe apply] theorem inv₀ {x : R} (hx : IsSelfAdjoint x) : IsSelfAdjoint x⁻¹ := by simp only [isSelfAdjoint_iff, star_inv₀, hx.star_eq] @[aesop safe apply] theorem zpow₀ {x : R} (hx : IsSelfAdjoint x) (n : ℤ) : IsSelfAdjoint (x ^ n) := by simp only [isSelfAdjoint_iff, star_zpow₀, hx.star_eq] end GroupWithZero @[simp] protected lemma nnratCast [DivisionSemiring R] [StarRing R] (q : ℚ≥0) : IsSelfAdjoint (q : R) := star_nnratCast _ section DivisionRing variable [DivisionRing R] [StarRing R] @[simp] protected theorem ratCast (x : ℚ) : IsSelfAdjoint (x : R) := star_ratCast _ end DivisionRing section Semifield variable [Semifield R] [StarRing R] theorem div {x y : R} (hx : IsSelfAdjoint x) (hy : IsSelfAdjoint y) : IsSelfAdjoint (x / y) := by simp only [isSelfAdjoint_iff, star_div₀, hx.star_eq, hy.star_eq] end Semifield section SMul @[aesop safe apply] theorem smul [Star R] [Star A] [SMul R A] [StarModule R A] {r : R} (hr : IsSelfAdjoint r) {x : A} (hx : IsSelfAdjoint x) : IsSelfAdjoint (r • x) := by simp only [isSelfAdjoint_iff, star_smul, hr.star_eq, hx.star_eq] theorem smul_iff [Monoid R] [StarMul R] [Star A] [MulAction R A] [StarModule R A] {r : R} (hr : IsSelfAdjoint r) (hu : IsUnit r) {x : A} : IsSelfAdjoint (r • x) ↔ IsSelfAdjoint x := by refine ⟨fun hrx ↦ ?_, .smul hr⟩ lift r to Rˣ using hu rw [← inv_smul_smul r x] replace hr : IsSelfAdjoint r := Units.ext hr.star_eq exact hr.inv.smul hrx end SMul end IsSelfAdjoint variable (R) /-- The self-adjoint elements of a star additive group, as an additive subgroup. -/ def selfAdjoint [AddGroup R] [StarAddMonoid R] : AddSubgroup R where carrier := { x | IsSelfAdjoint x } zero_mem' := star_zero R add_mem' hx := hx.add neg_mem' hx := hx.neg /-- The skew-adjoint elements of a star additive group, as an additive subgroup. -/ def skewAdjoint [AddCommGroup R] [StarAddMonoid R] : AddSubgroup R where carrier := { x | star x = -x } zero_mem' := show star (0 : R) = -0 by simp only [star_zero, neg_zero] add_mem' := @fun x y (hx : star x = -x) (hy : star y = -y) => show star (x + y) = -(x + y) by rw [star_add x y, hx, hy, neg_add] neg_mem' := @fun x (hx : star x = -x) => show star (-x) = - -x by simp only [hx, star_neg] variable {R} namespace selfAdjoint section AddGroup variable [AddGroup R] [StarAddMonoid R] theorem mem_iff {x : R} : x ∈ selfAdjoint R ↔ star x = x := by rw [← AddSubgroup.mem_carrier] exact Iff.rfl @[simp, norm_cast] theorem star_val_eq {x : selfAdjoint R} : star (x : R) = x := x.prop instance : Inhabited (selfAdjoint R) := ⟨0⟩ @[simp] lemma isSelfAdjoint {x : selfAdjoint R} : IsSelfAdjoint (x : R) := by simp [isSelfAdjoint_iff] end AddGroup instance isStarNormal [NonUnitalRing R] [StarRing R] (x : selfAdjoint R) : IsStarNormal (x : R) := x.prop.isStarNormal section Ring variable [Ring R] [StarRing R] instance : One (selfAdjoint R) := ⟨⟨1, .one R⟩⟩ @[simp, norm_cast] theorem val_one : ↑(1 : selfAdjoint R) = (1 : R) := rfl instance [Nontrivial R] : Nontrivial (selfAdjoint R) := ⟨⟨0, 1, ne_of_apply_ne Subtype.val zero_ne_one⟩⟩ instance : NatCast (selfAdjoint R) where natCast n := ⟨n, .natCast _⟩ instance : IntCast (selfAdjoint R) where intCast n := ⟨n, .intCast _⟩ instance : Pow (selfAdjoint R) ℕ where pow x n := ⟨(x : R) ^ n, x.prop.pow n⟩ @[simp, norm_cast] theorem val_pow (x : selfAdjoint R) (n : ℕ) : ↑(x ^ n) = (x : R) ^ n := rfl end Ring section NonUnitalCommRing variable [NonUnitalCommRing R] [StarRing R] instance : Mul (selfAdjoint R) where mul x y := ⟨(x : R) * y, x.prop.mul y.prop⟩ @[simp, norm_cast] theorem val_mul (x y : selfAdjoint R) : ↑(x * y) = (x : R) * y := rfl end NonUnitalCommRing section CommRing variable [CommRing R] [StarRing R] instance : CommRing (selfAdjoint R) := Function.Injective.commRing _ Subtype.coe_injective (selfAdjoint R).coe_zero val_one (selfAdjoint R).coe_add val_mul (selfAdjoint R).coe_neg (selfAdjoint R).coe_sub (by intros; rfl) (by intros; rfl) val_pow (fun _ => rfl) fun _ => rfl end CommRing section Field variable [Field R] [StarRing R] instance : Inv (selfAdjoint R) where inv x := ⟨x.val⁻¹, x.prop.inv₀⟩ @[simp, norm_cast] theorem val_inv (x : selfAdjoint R) : ↑x⁻¹ = (x : R)⁻¹ := rfl instance : Div (selfAdjoint R) where div x y := ⟨x / y, x.prop.div y.prop⟩ @[simp, norm_cast] theorem val_div (x y : selfAdjoint R) : ↑(x / y) = (x / y : R) := rfl instance : Pow (selfAdjoint R) ℤ where pow x z := ⟨(x : R) ^ z, x.prop.zpow₀ z⟩ @[simp, norm_cast] theorem val_zpow (x : selfAdjoint R) (z : ℤ) : ↑(x ^ z) = (x : R) ^ z := rfl instance instNNRatCast : NNRatCast (selfAdjoint R) where nnratCast q := ⟨q, .nnratCast q⟩ instance instRatCast : RatCast (selfAdjoint R) where ratCast q := ⟨q, .ratCast q⟩ @[simp, norm_cast] lemma val_nnratCast (q : ℚ≥0) : (q : selfAdjoint R) = (q : R) := rfl @[simp, norm_cast] lemma val_ratCast (q : ℚ) : (q : selfAdjoint R) = (q : R) := rfl instance instSMulNNRat : SMul ℚ≥0 (selfAdjoint R) where smul a x := ⟨a • (x : R), by rw [NNRat.smul_def]; exact .mul (.nnratCast a) x.prop⟩ instance instSMulRat : SMul ℚ (selfAdjoint R) where smul a x := ⟨a • (x : R), by rw [Rat.smul_def]; exact .mul (.ratCast a) x.prop⟩ @[simp, norm_cast] lemma val_nnqsmul (q : ℚ≥0) (x : selfAdjoint R) : ↑(q • x) = q • (x : R) := rfl @[simp, norm_cast] lemma val_qsmul (q : ℚ) (x : selfAdjoint R) : ↑(q • x) = q • (x : R) := rfl instance instField : Field (selfAdjoint R) := Subtype.coe_injective.field _ (selfAdjoint R).coe_zero val_one (selfAdjoint R).coe_add val_mul (selfAdjoint R).coe_neg (selfAdjoint R).coe_sub val_inv val_div (swap (selfAdjoint R).coe_nsmul) (by intros; rfl) val_nnqsmul val_qsmul val_pow val_zpow (fun _ => rfl) (fun _ => rfl) val_nnratCast val_ratCast end Field section SMul variable [Star R] [TrivialStar R] [AddGroup A] [StarAddMonoid A] instance [SMul R A] [StarModule R A] : SMul R (selfAdjoint A) where smul r x := ⟨r • (x : A), (IsSelfAdjoint.all _).smul x.prop⟩ @[simp, norm_cast] theorem val_smul [SMul R A] [StarModule R A] (r : R) (x : selfAdjoint A) : ↑(r • x) = r • (x : A) := rfl instance [Monoid R] [MulAction R A] [StarModule R A] : MulAction R (selfAdjoint A) := Function.Injective.mulAction Subtype.val Subtype.coe_injective val_smul instance [Monoid R] [DistribMulAction R A] [StarModule R A] : DistribMulAction R (selfAdjoint A) := Function.Injective.distribMulAction (selfAdjoint A).subtype Subtype.coe_injective val_smul end SMul section Module variable [Star R] [TrivialStar R] [AddCommGroup A] [StarAddMonoid A] instance [Semiring R] [Module R A] [StarModule R A] : Module R (selfAdjoint A) := Function.Injective.module R (selfAdjoint A).subtype Subtype.coe_injective val_smul end Module end selfAdjoint namespace skewAdjoint section AddGroup variable [AddCommGroup R] [StarAddMonoid R] theorem mem_iff {x : R} : x ∈ skewAdjoint R ↔ star x = -x := by rw [← AddSubgroup.mem_carrier] exact Iff.rfl @[simp, norm_cast] theorem star_val_eq {x : skewAdjoint R} : star (x : R) = -x := x.prop instance : Inhabited (skewAdjoint R) := ⟨0⟩ end AddGroup section Ring variable [Ring R] [StarRing R] theorem conjugate {x : R} (hx : x ∈ skewAdjoint R) (z : R) : z * x * star z ∈ skewAdjoint R := by simp only [mem_iff, star_mul, star_star, mem_iff.mp hx, neg_mul, mul_neg, mul_assoc] theorem conjugate' {x : R} (hx : x ∈ skewAdjoint R) (z : R) : star z * x * z ∈ skewAdjoint R := by simp only [mem_iff, star_mul, star_star, mem_iff.mp hx, neg_mul, mul_neg, mul_assoc] theorem isStarNormal_of_mem {x : R} (hx : x ∈ skewAdjoint R) : IsStarNormal x := ⟨by simp only [mem_iff] at hx simp only [hx, Commute.neg_left, Commute.refl]⟩ instance (x : skewAdjoint R) : IsStarNormal (x : R) := isStarNormal_of_mem (SetLike.coe_mem _) end Ring section SMul variable [Star R] [TrivialStar R] [AddCommGroup A] [StarAddMonoid A] @[aesop 90% (rule_sets := [SetLike])] theorem smul_mem [Monoid R] [DistribMulAction R A] [StarModule R A] (r : R) {x : A} (h : x ∈ skewAdjoint A) : r • x ∈ skewAdjoint A := by rw [mem_iff, star_smul, star_trivial, mem_iff.mp h, smul_neg r] instance [Monoid R] [DistribMulAction R A] [StarModule R A] : SMul R (skewAdjoint A) where smul r x := ⟨r • (x : A), smul_mem r x.prop⟩ @[simp, norm_cast] theorem val_smul [Monoid R] [DistribMulAction R A] [StarModule R A] (r : R) (x : skewAdjoint A) : ↑(r • x) = r • (x : A) := rfl instance [Monoid R] [DistribMulAction R A] [StarModule R A] : DistribMulAction R (skewAdjoint A) := Function.Injective.distribMulAction (skewAdjoint A).subtype Subtype.coe_injective val_smul instance [Semiring R] [Module R A] [StarModule R A] : Module R (skewAdjoint A) := Function.Injective.module R (skewAdjoint A).subtype Subtype.coe_injective val_smul end SMul end skewAdjoint /-- Scalar multiplication of a self-adjoint element by a skew-adjoint element produces a skew-adjoint element. -/ theorem IsSelfAdjoint.smul_mem_skewAdjoint [Ring R] [AddCommGroup A] [Module R A] [StarAddMonoid R] [StarAddMonoid A] [StarModule R A] {r : R} (hr : r ∈ skewAdjoint R) {a : A} (ha : IsSelfAdjoint a) : r • a ∈ skewAdjoint A := (star_smul _ _).trans <| (congr_arg₂ _ hr ha).trans <| neg_smul _ _ /-- Scalar multiplication of a skew-adjoint element by a skew-adjoint element produces a self-adjoint element. -/ theorem isSelfAdjoint_smul_of_mem_skewAdjoint [Ring R] [AddCommGroup A] [Module R A] [StarAddMonoid R] [StarAddMonoid A] [StarModule R A] {r : R} (hr : r ∈ skewAdjoint R) {a : A} (ha : a ∈ skewAdjoint A) : IsSelfAdjoint (r • a) := (star_smul _ _).trans <| (congr_arg₂ _ hr ha).trans <| neg_smul_neg _ _ protected instance IsStarNormal.zero [NonUnitalNonAssocSemiring R] [StarAddMonoid R] : IsStarNormal (0 : R) := ⟨by simp only [Commute.refl, star_zero]⟩ protected instance IsStarNormal.one [MulOneClass R] [StarMul R] : IsStarNormal (1 : R) := ⟨by simp only [Commute.refl, star_one]⟩ protected instance IsStarNormal.star [Mul R] [StarMul R] {x : R} [IsStarNormal x] : IsStarNormal (star x) := ⟨show star (star x) * star x = star x * star (star x) by rw [star_star, star_comm_self']⟩ protected instance IsStarNormal.neg [NonUnitalNonAssocRing R] [StarAddMonoid R] {x : R} [IsStarNormal x] : IsStarNormal (-x) := ⟨show star (-x) * -x = -x * star (-x) by simp_rw [star_neg, neg_mul_neg, star_comm_self']⟩ protected instance IsStarNormal.val_inv [Monoid R] [StarMul R] {x : Rˣ} [IsStarNormal (x : R)] : IsStarNormal (↑x⁻¹ : R) where star_comm_self := by simpa [← Units.coe_star_inv, -Commute.units_val_iff] using star_comm_self protected instance IsStarNormal.map {F R S : Type*} [Mul R] [Star R] [Mul S] [Star S] [FunLike F R S] [MulHomClass F R S] [StarHomClass F R S] (f : F) (r : R) [hr : IsStarNormal r] : IsStarNormal (f r) where star_comm_self := by simpa [map_star] using congr(f $(hr.star_comm_self)) protected instance IsStarNormal.smul {R A : Type*} [SMul R A] [Star R] [Star A] [Mul A] [StarModule R A] [SMulCommClass R A A] [IsScalarTower R A A] (r : R) (a : A) [ha : IsStarNormal a] : IsStarNormal (r • a) where star_comm_self := star_smul r a ▸ ha.star_comm_self.smul_left (star r) |>.smul_right r -- see Note [lower instance priority] instance (priority := 100) TrivialStar.isStarNormal [Mul R] [StarMul R] [TrivialStar R] {x : R} : IsStarNormal x := ⟨by rw [star_trivial]⟩ -- see Note [lower instance priority] instance (priority := 100) CommMonoid.isStarNormal [CommMonoid R] [StarMul R] {x : R} : IsStarNormal x := ⟨mul_comm _ _⟩ theorem Commute.isStarNormal_add [NonUnitalNonAssocSemiring R] [StarRing R] {a b : R} (hab : Commute a (star b)) [ha : IsStarNormal a] [hb : IsStarNormal b] : IsStarNormal (a + b) := by rw [isStarNormal_iff] at ha hb ⊢ have := _root_.star_star b ▸ hab.star_star simp only [star_add, commute_iff_eq, mul_add, add_mul] rw [ha.eq, hb.eq, add_add_add_comm, hab.eq, this.eq] theorem Commute.isStarNormal_sub [NonUnitalNonAssocRing R] [StarRing R] {a b : R} (hab : Commute a (star b)) [ha : IsStarNormal a] [hb : IsStarNormal b] : IsStarNormal (a - b) := sub_eq_add_neg a b ▸ (star_neg b ▸ hab.neg_right).isStarNormal_add instance IsStarNormal.one_add [NonAssocSemiring R] [StarRing R] {a : R} [ha : IsStarNormal a] : IsStarNormal (1 + a) := Commute.one_left (star a) |>.isStarNormal_add instance IsStarNormal.one_sub [NonAssocRing R] [StarRing R] {a : R} [ha : IsStarNormal a] : IsStarNormal (1 - a) := Commute.one_left (star a) |>.isStarNormal_sub namespace Pi variable {ι : Type*} {α : ι → Type*} [∀ i, Star (α i)] {f : ∀ i, α i} protected lemma isSelfAdjoint : IsSelfAdjoint f ↔ ∀ i, IsSelfAdjoint (f i) := funext_iff alias ⟨_root_.IsSelfAdjoint.apply, _⟩ := Pi.isSelfAdjoint end Pi
.lake/packages/mathlib/Mathlib/Algebra/Star/Prod.lean
import Mathlib.Algebra.Ring.Prod import Mathlib.Algebra.Star.Basic /-! # Basic Results about Star on Product Type This file provides basic results about the star on product types defined in `Mathlib/Algebra/Notation/Prod.lean`. -/ universe u v w variable {R : Type u} {S : Type v} namespace Prod instance [Star R] [Star S] [TrivialStar R] [TrivialStar S] : TrivialStar (R × S) where star_trivial _ := Prod.ext (star_trivial _) (star_trivial _) instance [InvolutiveStar R] [InvolutiveStar S] : InvolutiveStar (R × S) where star_involutive _ := Prod.ext (star_star _) (star_star _) instance [Mul R] [Mul S] [StarMul R] [StarMul S] : StarMul (R × S) where star_mul _ _ := Prod.ext (star_mul _ _) (star_mul _ _) instance [AddMonoid R] [AddMonoid S] [StarAddMonoid R] [StarAddMonoid S] : StarAddMonoid (R × S) where star_add _ _ := Prod.ext (star_add _ _) (star_add _ _) instance [NonUnitalNonAssocSemiring R] [NonUnitalNonAssocSemiring S] [StarRing R] [StarRing S] : StarRing (R × S) := { inferInstanceAs (StarAddMonoid (R × S)), inferInstanceAs (StarMul (R × S)) with } instance {α : Type w} [SMul α R] [SMul α S] [Star α] [Star R] [Star S] [StarModule α R] [StarModule α S] : StarModule α (R × S) where star_smul _ _ := Prod.ext (star_smul _ _) (star_smul _ _) end Prod theorem Units.embed_product_star [Monoid R] [StarMul R] (u : Rˣ) : Units.embedProduct R (star u) = star (Units.embedProduct R u) := rfl
.lake/packages/mathlib/Mathlib/Algebra/Star/Pointwise.lean
import Mathlib.Algebra.Star.Basic import Mathlib.Data.Set.Finite.Basic import Mathlib.Data.Set.Lattice.Image import Mathlib.Algebra.Group.Pointwise.Set.Basic /-! # Pointwise star operation on sets This file defines the star operation pointwise on sets and provides the basic API. Besides basic facts about how the star operation acts on sets (e.g., `(s ∩ t)⋆ = s⋆ ∩ t⋆`), if `s t : Set α`, then under suitable assumption on `α`, it is shown * `(s + t)⋆ = s⋆ + t⋆` * `(s * t)⋆ = t⋆ + s⋆` * `(s⁻¹)⋆ = (s⋆)⁻¹` -/ namespace Set open Pointwise local postfix:max "⋆" => star variable {α : Type*} {s t : Set α} {a : α} /-- The set `(star s : Set α)` is defined as `{x | star x ∈ s}` in the scope `Pointwise`. In the usual case where `star` is involutive, it is equal to `{star s | x ∈ s}`, see `Set.image_star`. -/ protected def star [Star α] : Star (Set α) := ⟨preimage Star.star⟩ scoped[Pointwise] attribute [instance] Set.star @[simp] theorem star_empty [Star α] : (∅ : Set α)⋆ = ∅ := rfl @[simp] theorem star_univ [Star α] : (univ : Set α)⋆ = univ := rfl @[simp] theorem nonempty_star [InvolutiveStar α] {s : Set α} : s⋆.Nonempty ↔ s.Nonempty := star_involutive.surjective.nonempty_preimage theorem Nonempty.star [InvolutiveStar α] {s : Set α} (h : s.Nonempty) : s⋆.Nonempty := nonempty_star.2 h @[simp] theorem mem_star [Star α] : a ∈ s⋆ ↔ a⋆ ∈ s := Iff.rfl theorem star_mem_star [InvolutiveStar α] : a⋆ ∈ s⋆ ↔ a ∈ s := by simp only [mem_star, star_star] @[simp] theorem star_preimage [Star α] : Star.star ⁻¹' s = s⋆ := rfl @[simp] theorem image_star [InvolutiveStar α] : Star.star '' s = s⋆ := by simp only [← star_preimage] rw [image_eq_preimage_of_inverse] <;> intro <;> simp only [star_star] @[simp] theorem inter_star [Star α] : (s ∩ t)⋆ = s⋆ ∩ t⋆ := preimage_inter @[simp] theorem union_star [Star α] : (s ∪ t)⋆ = s⋆ ∪ t⋆ := preimage_union @[simp] theorem iInter_star {ι : Sort*} [Star α] (s : ι → Set α) : (⋂ i, s i)⋆ = ⋂ i, (s i)⋆ := preimage_iInter @[simp] theorem iUnion_star {ι : Sort*} [Star α] (s : ι → Set α) : (⋃ i, s i)⋆ = ⋃ i, (s i)⋆ := preimage_iUnion @[simp] theorem compl_star [Star α] : sᶜ⋆ = s⋆ᶜ := preimage_compl @[simp] instance [InvolutiveStar α] : InvolutiveStar (Set α) where star_involutive s := by simp only [← star_preimage, preimage_preimage, star_star, preimage_id'] @[simp] theorem star_subset_star [InvolutiveStar α] {s t : Set α} : s⋆ ⊆ t⋆ ↔ s ⊆ t := Equiv.star.surjective.preimage_subset_preimage_iff theorem star_subset [InvolutiveStar α] {s t : Set α} : s⋆ ⊆ t ↔ s ⊆ t⋆ := by rw [← star_subset_star, star_star] theorem Finite.star [InvolutiveStar α] {s : Set α} (hs : s.Finite) : s⋆.Finite := hs.preimage star_injective.injOn theorem star_singleton {β : Type*} [InvolutiveStar β] (x : β) : ({x} : Set β)⋆ = {x⋆} := by ext1 y rw [mem_star, mem_singleton_iff, mem_singleton_iff, star_eq_iff_star_eq, eq_comm] protected theorem star_mul [Mul α] [StarMul α] (s t : Set α) : (s * t)⋆ = t⋆ * s⋆ := by simp_rw [← image_star, ← image2_mul, image_image2, image2_image_left, image2_image_right, star_mul, image2_swap _ s t] protected theorem star_add [AddMonoid α] [StarAddMonoid α] (s t : Set α) : (s + t)⋆ = s⋆ + t⋆ := by simp_rw [← image_star, ← image2_add, image_image2, image2_image_left, image2_image_right, star_add] @[simp] instance [Star α] [TrivialStar α] : TrivialStar (Set α) where star_trivial s := by rw [← star_preimage] ext1 simp [star_trivial] protected theorem star_inv [Group α] [StarMul α] (s : Set α) : s⁻¹⋆ = s⋆⁻¹ := by ext simp only [mem_star, mem_inv, star_inv] protected theorem star_inv' [GroupWithZero α] [StarMul α] (s : Set α) : s⁻¹⋆ = s⋆⁻¹ := by ext simp only [mem_star, mem_inv, star_inv₀] end Set @[simp] lemma StarMemClass.star_coe_eq {S α : Type*} [InvolutiveStar α] [SetLike S α] [StarMemClass S α] (s : S) : star (s : Set α) = s := by ext x simp only [Set.mem_star, SetLike.mem_coe] exact ⟨by simpa only [star_star] using star_mem (s := s) (r := star x), star_mem⟩
.lake/packages/mathlib/Mathlib/Algebra/Star/StarAlgHom.lean
import Mathlib.Algebra.Algebra.Equiv import Mathlib.Algebra.Algebra.NonUnitalHom import Mathlib.Algebra.Algebra.Prod import Mathlib.Algebra.Algebra.Pi import Mathlib.Algebra.Star.StarRingHom /-! # Morphisms of star algebras This file defines morphisms between `R`-algebras (unital or non-unital) `A` and `B` where both `A` and `B` are equipped with a `star` operation. These morphisms, namely `StarAlgHom` and `NonUnitalStarAlgHom` are direct extensions of their non-`star`red counterparts with a field `map_star` which guarantees they preserve the star operation. We keep the type classes as generic as possible, in keeping with the definition of `NonUnitalAlgHom` in the non-unital case. In this file, we only assume `Star` unless we want to talk about the zero map as a `NonUnitalStarAlgHom`, in which case we need `StarAddMonoid`. Note that the scalar ring `R` is not required to have a star operation, nor do we need `StarRing` or `StarModule` structures on `A` and `B`. As with `NonUnitalAlgHom`, in the non-unital case the multiplications are not assumed to be associative or unital, or even to be compatible with the scalar actions. In a typical application, the operations will satisfy compatibility conditions making them into algebras (albeit possibly non-associative and/or non-unital) but such conditions are not required here for the definitions. The primary impetus for defining these types is that they constitute the morphisms in the categories of unital C⋆-algebras (with `StarAlgHom`s) and of C⋆-algebras (with `NonUnitalStarAlgHom`s). ## Main definitions * `NonUnitalStarAlgHom` * `StarAlgHom` ## Tags non-unital, algebra, morphism, star -/ open EquivLike /-! ### Non-unital star algebra homomorphisms -/ /-- A *non-unital ⋆-algebra homomorphism* is a non-unital algebra homomorphism between non-unital `R`-algebras `A` and `B` equipped with a `star` operation, and this homomorphism is also `star`-preserving. -/ structure NonUnitalStarAlgHom (R A B : Type*) [Monoid R] [NonUnitalNonAssocSemiring A] [DistribMulAction R A] [Star A] [NonUnitalNonAssocSemiring B] [DistribMulAction R B] [Star B] extends A →ₙₐ[R] B where /-- By definition, a non-unital ⋆-algebra homomorphism preserves the `star` operation. -/ map_star' : ∀ a : A, toFun (star a) = star (toFun a) @[inherit_doc NonUnitalStarAlgHom] infixr:25 " →⋆ₙₐ " => NonUnitalStarAlgHom _ @[inherit_doc] notation:25 A " →⋆ₙₐ[" R "] " B => NonUnitalStarAlgHom R A B /-- Reinterpret a non-unital star algebra homomorphism as a non-unital algebra homomorphism by forgetting the interaction with the star operation. -/ add_decl_doc NonUnitalStarAlgHom.toNonUnitalAlgHom namespace NonUnitalStarAlgHomClass variable {F R A B : Type*} [Monoid R] variable [NonUnitalNonAssocSemiring A] [DistribMulAction R A] [Star A] variable [NonUnitalNonAssocSemiring B] [DistribMulAction R B] [Star B] variable [FunLike F A B] [NonUnitalAlgHomClass F R A B] /-- Turn an element of a type `F` satisfying `NonUnitalAlgHomClass F R A B` and `StarHomClass F A B` into an actual `NonUnitalStarAlgHom`. This is declared as the default coercion from `F` to `A →⋆ₙₐ[R] B`. -/ @[coe] def toNonUnitalStarAlgHom [StarHomClass F A B] (f : F) : A →⋆ₙₐ[R] B := { (f : A →ₙₐ[R] B) with map_star' := map_star f } instance [StarHomClass F A B] : CoeTC F (A →⋆ₙₐ[R] B) := ⟨toNonUnitalStarAlgHom⟩ instance [StarHomClass F A B] : NonUnitalStarRingHomClass F A B := NonUnitalStarRingHomClass.mk end NonUnitalStarAlgHomClass namespace NonUnitalStarAlgHom section Basic variable {R A B C D : Type*} [Monoid R] variable [NonUnitalNonAssocSemiring A] [DistribMulAction R A] [Star A] variable [NonUnitalNonAssocSemiring B] [DistribMulAction R B] [Star B] variable [NonUnitalNonAssocSemiring C] [DistribMulAction R C] [Star C] variable [NonUnitalNonAssocSemiring D] [DistribMulAction R D] [Star D] instance : FunLike (A →⋆ₙₐ[R] B) A B where coe f := f.toFun coe_injective' := by rintro ⟨⟨⟨⟨f, _⟩, _⟩, _⟩, _⟩ ⟨⟨⟨⟨g, _⟩, _⟩, _⟩, _⟩ h; congr instance : NonUnitalAlgHomClass (A →⋆ₙₐ[R] B) R A B where map_smulₛₗ f := f.map_smul' map_add f := f.map_add' map_zero f := f.map_zero' map_mul f := f.map_mul' instance : StarHomClass (A →⋆ₙₐ[R] B) A B where map_star f := f.map_star' initialize_simps_projections NonUnitalStarAlgHom (toFun → apply) @[simp] protected theorem coe_coe {F : Type*} [FunLike F A B] [NonUnitalAlgHomClass F R A B] [StarHomClass F A B] (f : F) : ⇑(f : A →⋆ₙₐ[R] B) = f := rfl @[simp] theorem coe_toNonUnitalAlgHom {f : A →⋆ₙₐ[R] B} : (f.toNonUnitalAlgHom : A → B) = f := rfl @[ext] theorem ext {f g : A →⋆ₙₐ[R] B} (h : ∀ x, f x = g x) : f = g := DFunLike.ext _ _ h /-- Copy of a `NonUnitalStarAlgHom` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (f : A →⋆ₙₐ[R] B) (f' : A → B) (h : f' = f) : A →⋆ₙₐ[R] B where toFun := f' map_smul' := h.symm ▸ map_smul f map_zero' := h.symm ▸ map_zero f map_add' := h.symm ▸ map_add f map_mul' := h.symm ▸ map_mul f map_star' := h.symm ▸ map_star f @[simp] theorem coe_copy (f : A →⋆ₙₐ[R] B) (f' : A → B) (h : f' = f) : ⇑(f.copy f' h) = f' := rfl theorem copy_eq (f : A →⋆ₙₐ[R] B) (f' : A → B) (h : f' = f) : f.copy f' h = f := DFunLike.ext' h @[simp] theorem coe_mk (f : A → B) (h₁ h₂ h₃ h₄ h₅) : ((⟨⟨⟨⟨f, h₁⟩, h₂, h₃⟩, h₄⟩, h₅⟩ : A →⋆ₙₐ[R] B) : A → B) = f := rfl -- this is probably the more useful lemma for Lean 4 and should likely replace `coe_mk` above @[simp] theorem coe_mk' (f : A →ₙₐ[R] B) (h) : ((⟨f, h⟩ : A →⋆ₙₐ[R] B) : A → B) = f := rfl @[simp] theorem mk_coe (f : A →⋆ₙₐ[R] B) (h₁ h₂ h₃ h₄ h₅) : (⟨⟨⟨⟨f, h₁⟩, h₂, h₃⟩, h₄⟩, h₅⟩ : A →⋆ₙₐ[R] B) = f := by ext rfl section variable (R A) /-- The identity as a non-unital ⋆-algebra homomorphism. -/ protected def id : A →⋆ₙₐ[R] A := { (1 : A →ₙₐ[R] A) with map_star' := fun _ => rfl } @[simp, norm_cast] theorem coe_id : ⇑(NonUnitalStarAlgHom.id R A) = id := rfl end /-- The composition of non-unital ⋆-algebra homomorphisms, as a non-unital ⋆-algebra homomorphism. -/ def comp (f : B →⋆ₙₐ[R] C) (g : A →⋆ₙₐ[R] B) : A →⋆ₙₐ[R] C := { f.toNonUnitalAlgHom.comp g.toNonUnitalAlgHom with map_star' := by simp only [map_star, NonUnitalAlgHom.toFun_eq_coe, NonUnitalAlgHom.coe_comp, coe_toNonUnitalAlgHom, Function.comp_apply, forall_const] } @[simp] theorem coe_comp (f : B →⋆ₙₐ[R] C) (g : A →⋆ₙₐ[R] B) : ⇑(comp f g) = f ∘ g := rfl @[simp] theorem comp_apply (f : B →⋆ₙₐ[R] C) (g : A →⋆ₙₐ[R] B) (a : A) : comp f g a = f (g a) := rfl @[simp] theorem comp_assoc (f : C →⋆ₙₐ[R] D) (g : B →⋆ₙₐ[R] C) (h : A →⋆ₙₐ[R] B) : (f.comp g).comp h = f.comp (g.comp h) := rfl @[simp] theorem id_comp (f : A →⋆ₙₐ[R] B) : (NonUnitalStarAlgHom.id _ _).comp f = f := ext fun _ => rfl @[simp] theorem comp_id (f : A →⋆ₙₐ[R] B) : f.comp (NonUnitalStarAlgHom.id _ _) = f := ext fun _ => rfl instance : Monoid (A →⋆ₙₐ[R] A) where mul := comp mul_assoc := comp_assoc one := NonUnitalStarAlgHom.id R A one_mul := id_comp mul_one := comp_id @[simp] theorem coe_one : ((1 : A →⋆ₙₐ[R] A) : A → A) = id := rfl theorem one_apply (a : A) : (1 : A →⋆ₙₐ[R] A) a = a := rfl end Basic section Zero -- the `zero` requires extra type class assumptions because we need `star_zero` variable {R A B C D : Type*} [Monoid R] variable [NonUnitalNonAssocSemiring A] [DistribMulAction R A] [StarAddMonoid A] variable [NonUnitalNonAssocSemiring B] [DistribMulAction R B] [StarAddMonoid B] instance : Zero (A →⋆ₙₐ[R] B) := ⟨{ (0 : NonUnitalAlgHom (MonoidHom.id R) A B) with map_star' := by simp }⟩ instance : Inhabited (A →⋆ₙₐ[R] B) := ⟨0⟩ instance : MonoidWithZero (A →⋆ₙₐ[R] A) := { inferInstanceAs (Monoid (A →⋆ₙₐ[R] A)), inferInstanceAs (Zero (A →⋆ₙₐ[R] A)) with zero_mul := fun _ => ext fun _ => rfl mul_zero := fun f => ext fun _ => map_zero f } @[simp] theorem coe_zero : ((0 : A →⋆ₙₐ[R] B) : A → B) = 0 := rfl theorem zero_apply (a : A) : (0 : A →⋆ₙₐ[R] B) a = 0 := rfl end Zero section RestrictScalars variable (R : Type*) {S A B : Type*} [Monoid R] [Monoid S] [Star A] [Star B] [NonUnitalNonAssocSemiring A] [NonUnitalNonAssocSemiring B] [MulAction R S] [DistribMulAction S A] [DistribMulAction S B] [DistribMulAction R A] [DistribMulAction R B] [IsScalarTower R S A] [IsScalarTower R S B] /-- If a monoid `R` acts on another monoid `S`, then a non-unital star algebra homomorphism over `S` can be viewed as a non-unital star algebra homomorphism over `R`. -/ def restrictScalars (f : A →⋆ₙₐ[S] B) : A →⋆ₙₐ[R] B := { (f : A →ₙₐ[S] B).restrictScalars R with map_star' := map_star f } @[simp] lemma restrictScalars_apply (f : A →⋆ₙₐ[S] B) (x : A) : f.restrictScalars R x = f x := rfl lemma coe_restrictScalars (f : A →⋆ₙₐ[S] B) : (f.restrictScalars R : A →ₙ+* B) = f := rfl lemma coe_restrictScalars' (f : A →⋆ₙₐ[S] B) : (f.restrictScalars R : A → B) = f := rfl theorem restrictScalars_injective : Function.Injective (restrictScalars R : (A →⋆ₙₐ[S] B) → A →⋆ₙₐ[R] B) := fun _ _ h ↦ ext (DFunLike.congr_fun h :) end RestrictScalars end NonUnitalStarAlgHom /-! ### Unital star algebra homomorphisms -/ section Unital /-- A *⋆-algebra homomorphism* is an algebra homomorphism between `R`-algebras `A` and `B` equipped with a `star` operation, and this homomorphism is also `star`-preserving. -/ structure StarAlgHom (R A B : Type*) [CommSemiring R] [Semiring A] [Algebra R A] [Star A] [Semiring B] [Algebra R B] [Star B] extends AlgHom R A B where /-- By definition, a ⋆-algebra homomorphism preserves the `star` operation. -/ map_star' : ∀ x : A, toFun (star x) = star (toFun x) @[inherit_doc StarAlgHom] infixr:25 " →⋆ₐ " => StarAlgHom _ @[inherit_doc] notation:25 A " →⋆ₐ[" R "] " B => StarAlgHom R A B /-- Reinterpret a unital star algebra homomorphism as a unital algebra homomorphism by forgetting the interaction with the star operation. -/ add_decl_doc StarAlgHom.toAlgHom namespace StarAlgHomClass variable {F R A B : Type*} variable [CommSemiring R] [Semiring A] [Algebra R A] [Star A] variable [Semiring B] [Algebra R B] [Star B] [FunLike F A B] [AlgHomClass F R A B] variable [StarHomClass F A B] /-- Turn an element of a type `F` satisfying `AlgHomClass F R A B` and `StarHomClass F A B` into an actual `StarAlgHom`. This is declared as the default coercion from `F` to `A →⋆ₐ[R] B`. -/ @[coe] def toStarAlgHom (f : F) : A →⋆ₐ[R] B := { (f : A →ₐ[R] B) with map_star' := map_star f } instance : CoeTC F (A →⋆ₐ[R] B) := ⟨toStarAlgHom⟩ end StarAlgHomClass namespace StarAlgHom variable {F R A B C D : Type*} [CommSemiring R] [Semiring A] [Algebra R A] [Star A] [Semiring B] [Algebra R B] [Star B] [Semiring C] [Algebra R C] [Star C] [Semiring D] [Algebra R D] [Star D] instance : FunLike (A →⋆ₐ[R] B) A B where coe f := f.toFun coe_injective' := by rintro ⟨⟨⟨⟨⟨f, _⟩, _⟩, _⟩, _⟩, _⟩ ⟨⟨⟨⟨⟨g, _⟩, _⟩, _⟩, _⟩, _⟩ h; congr instance : AlgHomClass (A →⋆ₐ[R] B) R A B where map_mul f := f.map_mul' map_one f := f.map_one' map_add f := f.map_add' map_zero f := f.map_zero' commutes f := f.commutes' instance : StarHomClass (A →⋆ₐ[R] B) A B where map_star f := f.map_star' @[simp] protected theorem coe_coe {F : Type*} [FunLike F A B] [AlgHomClass F R A B] [StarHomClass F A B] (f : F) : ⇑(f : A →⋆ₐ[R] B) = f := rfl initialize_simps_projections StarAlgHom (toFun → apply) @[simp] theorem coe_toAlgHom {f : A →⋆ₐ[R] B} : (f.toAlgHom : A → B) = f := rfl @[ext] theorem ext {f g : A →⋆ₐ[R] B} (h : ∀ x, f x = g x) : f = g := DFunLike.ext _ _ h /-- Copy of a `StarAlgHom` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (f : A →⋆ₐ[R] B) (f' : A → B) (h : f' = f) : A →⋆ₐ[R] B where toFun := f' map_one' := h.symm ▸ map_one f map_mul' := h.symm ▸ map_mul f map_zero' := h.symm ▸ map_zero f map_add' := h.symm ▸ map_add f commutes' := h.symm ▸ AlgHomClass.commutes f map_star' := h.symm ▸ map_star f @[simp] theorem coe_copy (f : A →⋆ₐ[R] B) (f' : A → B) (h : f' = f) : ⇑(f.copy f' h) = f' := rfl theorem copy_eq (f : A →⋆ₐ[R] B) (f' : A → B) (h : f' = f) : f.copy f' h = f := DFunLike.ext' h @[simp] theorem coe_mk (f : A → B) (h₁ h₂ h₃ h₄ h₅ h₆) : ((⟨⟨⟨⟨⟨f, h₁⟩, h₂⟩, h₃, h₄⟩, h₅⟩, h₆⟩ : A →⋆ₐ[R] B) : A → B) = f := rfl -- this is probably the more useful lemma for Lean 4 and should likely replace `coe_mk` above @[simp] theorem coe_mk' (f : A →ₐ[R] B) (h) : ((⟨f, h⟩ : A →⋆ₐ[R] B) : A → B) = f := rfl @[simp] theorem mk_coe (f : A →⋆ₐ[R] B) (h₁ h₂ h₃ h₄ h₅ h₆) : (⟨⟨⟨⟨⟨f, h₁⟩, h₂⟩, h₃, h₄⟩, h₅⟩, h₆⟩ : A →⋆ₐ[R] B) = f := by ext rfl section variable (R A) /-- The identity as a `StarAlgHom`. -/ protected def id : A →⋆ₐ[R] A := { AlgHom.id _ _ with map_star' := fun _ => rfl } @[simp, norm_cast] theorem coe_id : ⇑(StarAlgHom.id R A) = id := rfl /-- `algebraMap R A` as a `StarAlgHom` when `A` is a star algebra over `R`. -/ @[simps] def ofId (R A : Type*) [CommSemiring R] [StarRing R] [Semiring A] [StarMul A] [Algebra R A] [StarModule R A] : R →⋆ₐ[R] A := { Algebra.ofId R A with toFun := algebraMap R A map_star' := by simp [Algebra.algebraMap_eq_smul_one] } end instance : Inhabited (A →⋆ₐ[R] A) := ⟨StarAlgHom.id R A⟩ /-- The composition of ⋆-algebra homomorphisms, as a ⋆-algebra homomorphism. -/ def comp (f : B →⋆ₐ[R] C) (g : A →⋆ₐ[R] B) : A →⋆ₐ[R] C := { f.toAlgHom.comp g.toAlgHom with map_star' := by simp only [map_star, AlgHom.toFun_eq_coe, AlgHom.coe_comp, coe_toAlgHom, Function.comp_apply, forall_const] } @[simp] theorem coe_comp (f : B →⋆ₐ[R] C) (g : A →⋆ₐ[R] B) : ⇑(comp f g) = f ∘ g := rfl @[simp] theorem comp_apply (f : B →⋆ₐ[R] C) (g : A →⋆ₐ[R] B) (a : A) : comp f g a = f (g a) := rfl @[simp] theorem comp_assoc (f : C →⋆ₐ[R] D) (g : B →⋆ₐ[R] C) (h : A →⋆ₐ[R] B) : (f.comp g).comp h = f.comp (g.comp h) := rfl @[simp] theorem id_comp (f : A →⋆ₐ[R] B) : (StarAlgHom.id _ _).comp f = f := ext fun _ => rfl @[simp] theorem comp_id (f : A →⋆ₐ[R] B) : f.comp (StarAlgHom.id _ _) = f := ext fun _ => rfl instance : Monoid (A →⋆ₐ[R] A) where mul := comp mul_assoc := comp_assoc one := StarAlgHom.id R A one_mul := id_comp mul_one := comp_id /-- A unital morphism of ⋆-algebras is a `NonUnitalStarAlgHom`. -/ def toNonUnitalStarAlgHom (f : A →⋆ₐ[R] B) : A →⋆ₙₐ[R] B := { f with map_smul' := map_smul f } @[simp] theorem coe_toNonUnitalStarAlgHom (f : A →⋆ₐ[R] B) : (f.toNonUnitalStarAlgHom : A → B) = f := rfl end StarAlgHom end Unital /-! ### Operations on the product type Note that this is copied from [`Algebra.Hom.NonUnitalAlg`](../Hom/NonUnitalAlg). -/ namespace NonUnitalStarAlgHom section Prod variable (R A B C : Type*) [Monoid R] [NonUnitalNonAssocSemiring A] [DistribMulAction R A] [Star A] [NonUnitalNonAssocSemiring B] [DistribMulAction R B] [Star B] [NonUnitalNonAssocSemiring C] [DistribMulAction R C] [Star C] /-- The first projection of a product is a non-unital ⋆-algebra homomorphism. -/ @[simps!] def fst : A × B →⋆ₙₐ[R] A := { NonUnitalAlgHom.fst R A B with map_star' := fun _ => rfl } /-- The second projection of a product is a non-unital ⋆-algebra homomorphism. -/ @[simps!] def snd : A × B →⋆ₙₐ[R] B := { NonUnitalAlgHom.snd R A B with map_star' := fun _ => rfl } variable {R A B C} /-- The `Pi.prod` of two morphisms is a morphism. -/ @[simps!] def prod (f : A →⋆ₙₐ[R] B) (g : A →⋆ₙₐ[R] C) : A →⋆ₙₐ[R] B × C := { f.toNonUnitalAlgHom.prod g.toNonUnitalAlgHom with map_star' := fun x => by simp [map_star, Prod.star_def] } theorem coe_prod (f : A →⋆ₙₐ[R] B) (g : A →⋆ₙₐ[R] C) : ⇑(f.prod g) = Pi.prod f g := rfl @[simp] theorem fst_prod (f : A →⋆ₙₐ[R] B) (g : A →⋆ₙₐ[R] C) : (fst R B C).comp (prod f g) = f := by ext; rfl @[simp] theorem snd_prod (f : A →⋆ₙₐ[R] B) (g : A →⋆ₙₐ[R] C) : (snd R B C).comp (prod f g) = g := by ext; rfl @[simp] theorem prod_fst_snd : prod (fst R A B) (snd R A B) = 1 := DFunLike.coe_injective Pi.prod_fst_snd /-- Taking the product of two maps with the same domain is equivalent to taking the product of their codomains. -/ @[simps] def prodEquiv : (A →⋆ₙₐ[R] B) × (A →⋆ₙₐ[R] C) ≃ (A →⋆ₙₐ[R] B × C) where toFun f := f.1.prod f.2 invFun f := ((fst _ _ _).comp f, (snd _ _ _).comp f) end Prod section Pi variable {ι : Type*} /-- `Function.eval` as a `NonUnitalStarAlgHom`. -/ @[simps] def _root_.Pi.evalNonUnitalStarAlgHom (R : Type*) (A : ι → Type*) (j : ι) [Monoid R] [∀ i, NonUnitalNonAssocSemiring (A i)] [∀ i, DistribMulAction R (A i)] [∀ i, Star (A i)] : (∀ i, A i) →⋆ₙₐ[R] A j:= { Pi.evalMulHom A j, Pi.evalAddHom A j with map_smul' _ _ := rfl map_zero' := rfl map_star' _ := rfl } /-- `Function.eval` as a `StarAlgHom`. -/ @[simps] def _root_.Pi.evalStarAlgHom (R : Type*) (A : ι → Type*) (j : ι) [CommSemiring R] [∀ i, Semiring (A i)] [∀ i, Algebra R (A i)] [∀ i, Star (A i)] : (∀ i, A i) →⋆ₐ[R] A j := { Pi.evalNonUnitalStarAlgHom R A j, Pi.evalRingHom A j with commutes' _ := rfl } end Pi section InlInr variable (R A B C : Type*) [Monoid R] [NonUnitalNonAssocSemiring A] [DistribMulAction R A] [StarAddMonoid A] [NonUnitalNonAssocSemiring B] [DistribMulAction R B] [StarAddMonoid B] [NonUnitalNonAssocSemiring C] [DistribMulAction R C] [StarAddMonoid C] /-- The left injection into a product is a non-unital algebra homomorphism. -/ def inl : A →⋆ₙₐ[R] A × B := prod 1 0 /-- The right injection into a product is a non-unital algebra homomorphism. -/ def inr : B →⋆ₙₐ[R] A × B := prod 0 1 variable {R A B} @[simp] theorem coe_inl : (inl R A B : A → A × B) = fun x => (x, 0) := rfl theorem inl_apply (x : A) : inl R A B x = (x, 0) := rfl @[simp] theorem coe_inr : (inr R A B : B → A × B) = Prod.mk 0 := rfl theorem inr_apply (x : B) : inr R A B x = (0, x) := rfl end InlInr end NonUnitalStarAlgHom namespace StarAlgHom variable (R A B C : Type*) [CommSemiring R] [Semiring A] [Algebra R A] [Star A] [Semiring B] [Algebra R B] [Star B] [Semiring C] [Algebra R C] [Star C] /-- The first projection of a product is a ⋆-algebra homomorphism. -/ @[simps!] def fst : A × B →⋆ₐ[R] A := { AlgHom.fst R A B with map_star' := fun _ => rfl } /-- The second projection of a product is a ⋆-algebra homomorphism. -/ @[simps!] def snd : A × B →⋆ₐ[R] B := { AlgHom.snd R A B with map_star' := fun _ => rfl } variable {R A B C} /-- The `Pi.prod` of two morphisms is a morphism. -/ @[simps!] def prod (f : A →⋆ₐ[R] B) (g : A →⋆ₐ[R] C) : A →⋆ₐ[R] B × C := { f.toAlgHom.prod g.toAlgHom with map_star' := fun x => by simp [Prod.star_def, map_star] } theorem coe_prod (f : A →⋆ₐ[R] B) (g : A →⋆ₐ[R] C) : ⇑(f.prod g) = Pi.prod f g := rfl @[simp] theorem fst_prod (f : A →⋆ₐ[R] B) (g : A →⋆ₐ[R] C) : (fst R B C).comp (prod f g) = f := by ext; rfl @[simp] theorem snd_prod (f : A →⋆ₐ[R] B) (g : A →⋆ₐ[R] C) : (snd R B C).comp (prod f g) = g := by ext; rfl @[simp] theorem prod_fst_snd : prod (fst R A B) (snd R A B) = 1 := DFunLike.coe_injective Pi.prod_fst_snd /-- Taking the product of two maps with the same domain is equivalent to taking the product of their codomains. -/ @[simps] def prodEquiv : (A →⋆ₐ[R] B) × (A →⋆ₐ[R] C) ≃ (A →⋆ₐ[R] B × C) where toFun f := f.1.prod f.2 invFun f := ((fst _ _ _).comp f, (snd _ _ _).comp f) end StarAlgHom /-! ### Star algebra equivalences -/ /-- A *⋆-algebra* equivalence is an equivalence preserving addition, multiplication, scalar multiplication and the star operation, which allows for considering both unital and non-unital equivalences with a single structure. -/ structure StarAlgEquiv (R A B : Type*) [Add A] [Add B] [Mul A] [Mul B] [SMul R A] [SMul R B] [Star A] [Star B] extends A ≃⋆+* B where /-- By definition, a ⋆-algebra equivalence commutes with the action of scalars. -/ map_smul' : ∀ (r : R) (a : A), toFun (r • a) = r • toFun a @[inherit_doc StarAlgEquiv] infixr:25 " ≃⋆ₐ " => StarAlgEquiv _ @[inherit_doc] notation:25 A " ≃⋆ₐ[" R "] " B => StarAlgEquiv R A B /-- Reinterpret a star algebra equivalence as a `StarRingEquiv` by forgetting the interaction with the scalar multiplication. -/ add_decl_doc StarAlgEquiv.toStarRingEquiv /-- The class that directly extends `RingEquivClass` and `SMulHomClass`. Mostly an implementation detail for the ⋆-algebra equivalence class which is currently: `[NonUnitalAlgEquivClass]` and `[StarHomClass]`. -/ class NonUnitalAlgEquivClass (F : Type*) (R A B : outParam Type*) [Add A] [Mul A] [SMul R A] [Add B] [Mul B] [SMul R B] [EquivLike F A B] : Prop extends RingEquivClass F A B, MulActionSemiHomClass F (@id R) A B where -- See note [lower instance priority] instance (priority := 100) {F R A B : Type*} [Monoid R] [NonUnitalNonAssocSemiring A] [DistribMulAction R A] [NonUnitalNonAssocSemiring B] [DistribMulAction R B] [EquivLike F A B] [NonUnitalAlgEquivClass F R A B] : NonUnitalAlgHomClass F R A B := { } -- See note [lower instance priority] instance (priority := 100) (F R A B : Type*) [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [EquivLike F A B] [NonUnitalAlgEquivClass F R A B] : AlgEquivClass F R A B := { commutes := fun f r => by simp only [Algebra.algebraMap_eq_smul_one, map_smul, map_one] } namespace StarAlgEquivClass /-- Turn an element of a type `F` satisfying `AlgEquivClass F R A B` and `StarHomClass F A B` into an actual `StarAlgEquiv`. This is declared as the default coercion from `F` to `A ≃⋆ₐ[R] B`. -/ @[coe] def toStarAlgEquiv {F R A B : Type*} [Add A] [Mul A] [SMul R A] [Star A] [Add B] [Mul B] [SMul R B] [Star B] [EquivLike F A B] [NonUnitalAlgEquivClass F R A B] [StarHomClass F A B] (f : F) : A ≃⋆ₐ[R] B := { (f : A ≃+* B) with map_star' := map_star f map_smul' := map_smul f} /-- Any type satisfying `AlgEquivClass` and `StarHomClass` can be cast into `StarAlgEquiv` via `StarAlgEquivClass.toStarAlgEquiv`. -/ instance instCoeHead {F R A B : Type*} [Add A] [Mul A] [SMul R A] [Star A] [Add B] [Mul B] [SMul R B] [Star B] [EquivLike F A B] [NonUnitalAlgEquivClass F R A B] [StarHomClass F A B] : CoeHead F (A ≃⋆ₐ[R] B) := ⟨toStarAlgEquiv⟩ end StarAlgEquivClass namespace StarAlgEquiv section Basic variable {F R A B C : Type*} [Add A] [Add B] [Mul A] [Mul B] [SMul R A] [SMul R B] [Star A] [Star B] [Add C] [Mul C] [SMul R C] [Star C] instance : EquivLike (A ≃⋆ₐ[R] B) A B where coe f := f.toFun inv f := f.invFun left_inv f := f.left_inv right_inv f := f.right_inv coe_injective' f g h₁ h₂ := by rcases f with ⟨⟨⟨⟨_, _, _⟩, _⟩, _⟩, _⟩ rcases g with ⟨⟨⟨⟨_, _, _⟩, _⟩, _⟩, _⟩ congr instance : NonUnitalAlgEquivClass (A ≃⋆ₐ[R] B) R A B where map_mul f := f.map_mul' map_add f := f.map_add' map_smulₛₗ := map_smul' instance : StarRingEquivClass (A ≃⋆ₐ[R] B) A B where map_star f := f.map_star' /-- Helper instance for cases where the inference via `EquivLike` is too hard. -/ instance : FunLike (A ≃⋆ₐ[R] B) A B where coe f := f.toFun coe_injective' := DFunLike.coe_injective @[simp] theorem toStarRingEquiv_eq_coe (e : A ≃⋆ₐ[R] B) : e.toStarRingEquiv = e := rfl theorem toRingEquiv_eq_coe (e : A ≃⋆ₐ[R] B) : e.toRingEquiv = e := rfl @[ext] theorem ext {f g : A ≃⋆ₐ[R] B} (h : ∀ a, f a = g a) : f = g := DFunLike.ext f g h /-- The identity map is a star algebra isomorphism. -/ @[refl] def refl : A ≃⋆ₐ[R] A := { StarRingEquiv.refl (A := A) with map_smul' := fun _ _ => rfl } instance : Inhabited (A ≃⋆ₐ[R] A) := ⟨refl⟩ @[simp] theorem coe_refl : ⇑(refl : A ≃⋆ₐ[R] A) = id := rfl /-- The inverse of a star algebra isomorphism is a star algebra isomorphism. -/ @[symm] nonrec def symm (e : A ≃⋆ₐ[R] B) : B ≃⋆ₐ[R] A := { e.symm with map_smul' := fun r b => by simpa only [apply_inv_apply, inv_apply_apply] using congr_arg (inv e) (map_smul e r (inv e b)).symm } /-- See Note [custom simps projection] -/ def Simps.symm_apply (e : A ≃⋆ₐ[R] B) : B → A := e.symm initialize_simps_projections StarAlgEquiv (toFun → apply, invFun → symm_apply) @[simp] theorem invFun_eq_symm {e : A ≃⋆ₐ[R] B} : EquivLike.inv e = e.symm := rfl @[simp] theorem symm_symm (e : A ≃⋆ₐ[R] B) : e.symm.symm = e := rfl theorem symm_bijective : Function.Bijective (symm : (A ≃⋆ₐ[R] B) → B ≃⋆ₐ[R] A) := Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩ @[simp] theorem coe_mk (e h) : ⇑(⟨e, h⟩ : A ≃⋆ₐ[R] B) = e := rfl @[simp] theorem mk_coe (e : A ≃⋆ₐ[R] B) (e' h₁ h₂ h₃ h₄ h₅ h₆) : (⟨⟨⟨⟨e, e', h₁, h₂⟩, h₃, h₄⟩, h₅⟩, h₆⟩ : A ≃⋆ₐ[R] B) = e := ext fun _ => rfl /-- Auxiliary definition to avoid looping in `dsimp` with `StarAlgEquiv.symm_mk`. -/ protected def symm_mk.aux (f f') (h₁ h₂ h₃ h₄ h₅ h₆) := (⟨⟨⟨⟨f, f', h₁, h₂⟩, h₃, h₄⟩, h₅⟩, h₆⟩ : A ≃⋆ₐ[R] B).symm @[simp] theorem symm_mk (f f') (h₁ h₂ h₃ h₄ h₅ h₆) : (⟨⟨⟨⟨f, f', h₁, h₂⟩, h₃, h₄⟩, h₅⟩, h₆⟩ : A ≃⋆ₐ[R] B).symm = { symm_mk.aux f f' h₁ h₂ h₃ h₄ h₅ h₆ with toFun := f' invFun := f } := rfl @[simp] theorem refl_symm : (StarAlgEquiv.refl : A ≃⋆ₐ[R] A).symm = StarAlgEquiv.refl := rfl @[simp] theorem toStarRingEquiv_symm (e : A ≃⋆ₐ[R] B) : (e.symm : B ≃⋆+* A) = (e : A ≃⋆+* B).symm := rfl @[simp] theorem toRingEquiv_symm (e : A ≃⋆ₐ[R] B) : (e.symm : B ≃+* A) = (e : A ≃+* B).symm := rfl @[deprecated "← toRingEquiv_symm" (since := "2025-08-25")] theorem to_ringEquiv_symm (f : A ≃⋆ₐ[R] B) : (f : A ≃+* B).symm = f.symm := rfl @[deprecated (since := "2025-08-25")] alias symm_to_ringEquiv := toRingEquiv_symm /-- Transitivity of `StarAlgEquiv`. -/ @[trans] def trans (e₁ : A ≃⋆ₐ[R] B) (e₂ : B ≃⋆ₐ[R] C) : A ≃⋆ₐ[R] C := { e₁.toStarRingEquiv.trans e₂.toStarRingEquiv with map_smul' := fun r a => show e₂.toFun (e₁.toFun (r • a)) = r • e₂.toFun (e₁.toFun a) by rw [e₁.map_smul', e₂.map_smul'] } @[simp] theorem apply_symm_apply (e : A ≃⋆ₐ[R] B) : ∀ x, e (e.symm x) = x := e.toStarRingEquiv.apply_symm_apply @[simp] theorem symm_apply_apply (e : A ≃⋆ₐ[R] B) : ∀ x, e.symm (e x) = x := e.toStarRingEquiv.symm_apply_apply @[simp] theorem symm_trans_apply (e₁ : A ≃⋆ₐ[R] B) (e₂ : B ≃⋆ₐ[R] C) (x : C) : (e₁.trans e₂).symm x = e₁.symm (e₂.symm x) := rfl @[simp] theorem coe_trans (e₁ : A ≃⋆ₐ[R] B) (e₂ : B ≃⋆ₐ[R] C) : ⇑(e₁.trans e₂) = e₂ ∘ e₁ := rfl @[simp] theorem trans_apply (e₁ : A ≃⋆ₐ[R] B) (e₂ : B ≃⋆ₐ[R] C) (x : A) : (e₁.trans e₂) x = e₂ (e₁ x) := rfl theorem leftInverse_symm (e : A ≃⋆ₐ[R] B) : Function.LeftInverse e.symm e := e.left_inv theorem rightInverse_symm (e : A ≃⋆ₐ[R] B) : Function.RightInverse e.symm e := e.right_inv section AlgEquiv variable {R A B : Type*} [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B] [Star A] [Star B] /-- Interpret a ⋆-algebra equivalence as an algebra equivalence. -/ def toAlgEquiv (f : A ≃⋆ₐ[R] B) : A ≃ₐ[R] B where toRingEquiv := f.toRingEquiv commutes' r := by simp_rw [Algebra.algebraMap_eq_smul_one', map_smul']; simp @[simp] theorem toAlgEquiv_symm (f : A ≃⋆ₐ[R] B) : f.symm.toAlgEquiv = f.toAlgEquiv.symm := rfl @[simp] theorem coe_toAlgEquiv (f : A ≃⋆ₐ[R] B) : ⇑f.toAlgEquiv = ⇑f := rfl @[simp] theorem coe_symm_toAlgEquiv (f : A ≃⋆ₐ[R] B) : ⇑f.toAlgEquiv.symm = ⇑f.symm := rfl @[simp] theorem toAlgEquiv_trans {C : Type*} [Semiring C] [Algebra R C] [Star C] (f : A ≃⋆ₐ[R] B) (g : B ≃⋆ₐ[R] C) : (f.trans g).toAlgEquiv = f.toAlgEquiv.trans g.toAlgEquiv := rfl theorem toAlgEquiv_injective : Function.Injective (toAlgEquiv (R:=R) (A:=A) (B:=B)) := fun _ _ h => ext <| AlgEquiv.congr_fun h @[simp] theorem toAlgEquiv_refl : (refl : A ≃⋆ₐ[R] A).toAlgEquiv = AlgEquiv.refl := rfl /-- Upgrade an algebra equivalence to a ⋆-algebra equivalence given that it preserves the `star` operation. -/ def ofAlgEquiv (f : A ≃ₐ[R] B) (map_star : ∀ x, f (star x) = star (f x)) : A ≃⋆ₐ[R] B where toRingEquiv := f.toRingEquiv map_smul' := f.toLinearEquiv.map_smul map_star' := map_star @[simp] theorem ofAlgEquiv_apply (f : A ≃ₐ[R] B) (map_star : ∀ x, f (star x) = star (f x)) (x : A) : ofAlgEquiv f map_star x = f x := rfl @[simp] theorem ofAlgEquiv_symm (f : A ≃ₐ[R] B) (map_star : ∀ x, f (star x) = star (f x)) : (ofAlgEquiv f map_star).symm = ofAlgEquiv f.symm (ofAlgEquiv f map_star).symm.map_star' := rfl @[simp] theorem toAlgEquiv_ofAlgEquiv (f : A ≃ₐ[R] B) (map_star : ∀ x, f (star x) = star (f x)) : (ofAlgEquiv f map_star).toAlgEquiv = f := rfl @[simp] theorem ofAlgEquiv_toAlgEquiv (f : A ≃⋆ₐ[R] B) (map_star) : ofAlgEquiv f.toAlgEquiv map_star = f := rfl end AlgEquiv end Basic section Bijective variable {F G R A B : Type*} [Monoid R] variable [NonUnitalNonAssocSemiring A] [DistribMulAction R A] [Star A] variable [NonUnitalNonAssocSemiring B] [DistribMulAction R B] [Star B] variable [FunLike F A B] [NonUnitalAlgHomClass F R A B] [StarHomClass F A B] variable [FunLike G B A] [NonUnitalAlgHomClass G R B A] [StarHomClass G B A] /-- If a (unital or non-unital) star algebra morphism has an inverse, it is an isomorphism of star algebras. -/ @[simps] def ofStarAlgHom (f : F) (g : G) (h₁ : ∀ x, g (f x) = x) (h₂ : ∀ x, f (g x) = x) : A ≃⋆ₐ[R] B where toFun := f invFun := g left_inv := h₁ right_inv := h₂ map_add' := map_add f map_mul' := map_mul f map_smul' := map_smul f map_star' := map_star f /-- Promote a bijective star algebra homomorphism to a star algebra equivalence. -/ noncomputable def ofBijective (f : F) (hf : Function.Bijective f) : A ≃⋆ₐ[R] B := { RingEquiv.ofBijective f (hf : Function.Bijective (f : A → B)) with toFun := f map_star' := map_star f map_smul' := map_smul f } @[simp] theorem coe_ofBijective {f : F} (hf : Function.Bijective f) : (StarAlgEquiv.ofBijective f hf : A → B) = f := rfl theorem ofBijective_apply {f : F} (hf : Function.Bijective f) (a : A) : (StarAlgEquiv.ofBijective f hf) a = f a := rfl end Bijective section Group variable {S R : Type*} [Mul R] [Add R] [Star R] [SMul S R] @[simps -isSimp one mul] instance aut : Group (R ≃⋆ₐ[S] R) where one := refl mul a b := b.trans a one_mul _ := rfl mul_one _ := rfl mul_assoc _ _ _ := rfl inv f := f.symm inv_mul_cancel f := ext <| symm_apply_apply f @[simp] theorem mul_apply (f g : R ≃⋆ₐ[S] R) (x : R) : (f * g) x = f (g x) := rfl @[simp] theorem one_apply (x : R) : (1 : R ≃⋆ₐ[S] R) x = x := rfl theorem aut_inv (f : R ≃⋆ₐ[S] R) : f⁻¹ = f.symm := rfl @[simp] theorem coe_pow (f : R ≃⋆ₐ[S] R) (n : ℕ) : ⇑(f ^ n) = (⇑f)^[n] := hom_coe_pow _ (funext one_apply) (fun f g ↦ funext <| mul_apply f g) _ _ end Group end StarAlgEquiv
.lake/packages/mathlib/Mathlib/Algebra/Star/Pi.lean
import Mathlib.Algebra.Star.Basic import Mathlib.Algebra.Notation.Pi.Defs import Mathlib.Algebra.Ring.Pi /-! # Basic Results about Star on Pi Types This file provides basic results about the star on product types defined in `Mathlib/Algebra/Notation/Pi/Defs.lean`. -/ universe u v w variable {I : Type u} -- The indexing type variable {f : I → Type v} -- The family of types already equipped with instances namespace Pi instance [∀ i, Star (f i)] [∀ i, TrivialStar (f i)] : TrivialStar (∀ i, f i) where star_trivial _ := funext fun _ => star_trivial _ instance [∀ i, InvolutiveStar (f i)] : InvolutiveStar (∀ i, f i) where star_involutive _ := funext fun _ => star_star _ instance [∀ i, Mul (f i)] [∀ i, StarMul (f i)] : StarMul (∀ i, f i) where star_mul _ _ := funext fun _ => star_mul _ _ instance [∀ i, AddMonoid (f i)] [∀ i, StarAddMonoid (f i)] : StarAddMonoid (∀ i, f i) where star_add _ _ := funext fun _ => star_add _ _ instance [∀ i, NonUnitalSemiring (f i)] [∀ i, StarRing (f i)] : StarRing (∀ i, f i) where star_add _ _ := funext fun _ => star_add _ _ instance {R : Type w} [∀ i, SMul R (f i)] [Star R] [∀ i, Star (f i)] [∀ i, StarModule R (f i)] : StarModule R (∀ i, f i) where star_smul r x := funext fun i => star_smul r (x i) theorem single_star [∀ i, AddMonoid (f i)] [∀ i, StarAddMonoid (f i)] [DecidableEq I] (i : I) (a : f i) : Pi.single i (star a) = star (Pi.single i a) := single_op (fun i => @star (f i) _) (fun _ => star_zero _) i a open scoped ComplexConjugate @[simp] lemma conj_apply {ι : Type*} {α : ι → Type*} [∀ i, CommSemiring (α i)] [∀ i, StarRing (α i)] (f : ∀ i, α i) (i : ι) : conj f i = conj (f i) := rfl end Pi namespace Function theorem update_star [∀ i, Star (f i)] [DecidableEq I] (h : ∀ i : I, f i) (i : I) (a : f i) : Function.update (star h) i (star a) = star (Function.update h i a) := funext fun j => (apply_update (fun _ => star) h i a j).symm theorem star_sumElim {I J α : Type*} (x : I → α) (y : J → α) [Star α] : star (Sum.elim x y) = Sum.elim (star x) (star y) := by ext x; cases x <;> simp only [Pi.star_apply, Sum.elim_inl, Sum.elim_inr] end Function
.lake/packages/mathlib/Mathlib/Algebra/Star/Center.lean
import Mathlib.Algebra.Star.Basic import Mathlib.Algebra.Star.Pointwise import Mathlib.Algebra.Group.Center /-! # `Set.center`, `Set.centralizer` and the `star` operation -/ variable {R : Type*} [Mul R] [StarMul R] {a : R} {s : Set R} theorem Set.star_mem_center (ha : a ∈ Set.center R) : star a ∈ Set.center R where comm := by simpa only [star_mul, star_star] using fun g => congr_arg star ((mem_center_iff.1 ha).comm <| star g).symm left_assoc b c := calc star a * (b * c) = star a * (star (star b) * star (star c)) := by rw [star_star, star_star] _ = star a * star (star c * star b) := by rw [star_mul] _ = star ((star c * star b) * a) := by rw [← star_mul] _ = star (star c * (star b * a)) := by rw [ha.right_assoc] _ = star (star b * a) * c := by rw [star_mul, star_star] _ = (star a * b) * c := by rw [star_mul, star_star] right_assoc b c := calc b * c * star a = star (a * star (b * c)) := by rw [star_mul, star_star] _ = star (a * (star c * star b)) := by rw [star_mul b] _ = star ((a * star c) * star b) := by rw [ha.left_assoc] _ = b * star (a * star c) := by rw [star_mul, star_star] _ = b * (c * star a) := by rw [star_mul, star_star] theorem Set.star_centralizer : star s.centralizer = (star s).centralizer := by simp_rw [centralizer, ← commute_iff_eq] conv_lhs => simp only [← star_preimage, preimage_setOf_eq, ← commute_star_comm] conv_rhs => simp only [← image_star, forall_mem_image] theorem Set.union_star_self_comm (hcomm : ∀ x ∈ s, ∀ y ∈ s, y * x = x * y) (hcomm_star : ∀ x ∈ s, ∀ y ∈ s, y * star x = star x * y) : ∀ x ∈ s ∪ star s, ∀ y ∈ s ∪ star s, y * x = x * y := by change s ∪ star s ⊆ (s ∪ star s).centralizer simp_rw [centralizer_union, ← star_centralizer, union_subset_iff, subset_inter_iff, star_subset_star, star_subset] exact ⟨⟨hcomm, hcomm_star⟩, ⟨hcomm_star, hcomm⟩⟩ theorem Set.star_mem_centralizer' (h : ∀ a : R, a ∈ s → star a ∈ s) (ha : a ∈ Set.centralizer s) : star a ∈ Set.centralizer s := fun y hy => by simpa using congr_arg star (ha _ (h _ hy)).symm open scoped Pointwise theorem Set.star_mem_centralizer (ha : a ∈ Set.centralizer (s ∪ star s)) : star a ∈ Set.centralizer (s ∪ star s) := Set.star_mem_centralizer' (fun _x hx => hx.elim (fun hx => Or.inr <| Set.star_mem_star.mpr hx) Or.inl) ha
.lake/packages/mathlib/Mathlib/Algebra/Star/Basic.lean
import Mathlib.Algebra.Group.Action.Opposite import Mathlib.Algebra.Group.Action.Units import Mathlib.Algebra.Group.Invertible.Defs import Mathlib.Algebra.GroupWithZero.Units.Lemmas import Mathlib.Algebra.Ring.Aut import Mathlib.Algebra.Ring.CompTypeclasses import Mathlib.Algebra.Ring.Opposite import Mathlib.Data.Int.Cast.Lemmas import Mathlib.Data.SetLike.Basic /-! # Star monoids, rings, and modules We introduce the basic algebraic notions of star monoids, star rings, and star modules. A star algebra is simply a star ring that is also a star module. These are implemented as "mixin" typeclasses, so to summon a star ring (for example) one needs to write `(R : Type*) [Ring R] [StarRing R]`. This avoids difficulties with diamond inheritance. For now we simply do not introduce notations, as different users are expected to feel strongly about the relative merits of `r^*`, `r†`, `rᘁ`, and so on. Our star rings are actually star non-unital, non-associative, semirings, but of course we can prove `star_neg : star (-r) = - star r` when the underlying semiring is a ring. -/ assert_not_exists Finset Subgroup Rat.instField universe u v w open MulOpposite variable {R : Type u} /-- `StarMemClass S G` states `S` is a type of subsets `s ⊆ G` closed under star. -/ class StarMemClass (S R : Type*) [Star R] [SetLike S R] : Prop where /-- Closure under star. -/ star_mem : ∀ {s : S} {r : R}, r ∈ s → star r ∈ s export StarMemClass (star_mem) attribute [aesop 90% (rule_sets := [SetLike])] star_mem namespace StarMemClass variable {S : Type w} [Star R] [SetLike S R] [hS : StarMemClass S R] (s : S) instance instStar : Star s where star r := ⟨star (r : R), star_mem r.prop⟩ @[simp] lemma coe_star (x : s) : star x = star (x : R) := rfl end StarMemClass /-- Typeclass for a star operation with is involutive. -/ class InvolutiveStar (R : Type u) extends Star R where /-- Involutive condition. -/ star_involutive : Function.Involutive star export InvolutiveStar (star_involutive) @[simp] theorem star_star [InvolutiveStar R] (r : R) : star (star r) = r := star_involutive _ lemma star_mem_iff {S : Type*} [SetLike S R] [InvolutiveStar R] [StarMemClass S R] {s : S} {x : R} : star x ∈ s ↔ x ∈ s := ⟨fun h => star_star x ▸ star_mem h, fun h => star_mem h⟩ theorem star_injective [InvolutiveStar R] : Function.Injective (star : R → R) := Function.Involutive.injective star_involutive @[aesop 5% (rule_sets := [SetLike!])] theorem mem_of_star_mem {S R : Type*} [InvolutiveStar R] [SetLike S R] [StarMemClass S R] {s : S} {r : R} (hr : star r ∈ s) : r ∈ s := by rw [← star_star r]; exact star_mem hr @[simp] theorem star_inj [InvolutiveStar R] {x y : R} : star x = star y ↔ x = y := star_injective.eq_iff /-- `star` as an equivalence when it is involutive. -/ protected def Equiv.star [InvolutiveStar R] : Equiv.Perm R := star_involutive.toPerm _ theorem eq_star_of_eq_star [InvolutiveStar R] {r s : R} (h : r = star s) : s = star r := by simp [h] theorem eq_star_iff_eq_star [InvolutiveStar R] {r s : R} : r = star s ↔ s = star r := ⟨eq_star_of_eq_star, eq_star_of_eq_star⟩ theorem star_eq_iff_star_eq [InvolutiveStar R] {r s : R} : star r = s ↔ star s = r := eq_comm.trans <| eq_star_iff_eq_star.trans eq_comm /-- Typeclass for a trivial star operation. This is mostly meant for `ℝ`. -/ class TrivialStar (R : Type u) [Star R] : Prop where /-- Condition that star is trivial -/ star_trivial : ∀ r : R, star r = r export TrivialStar (star_trivial) attribute [simp] star_trivial /-- A `*`-magma is a magma `R` with an involutive operation `star` such that `star (r * s) = star s * star r`. -/ class StarMul (R : Type u) [Mul R] extends InvolutiveStar R where /-- `star` skew-distributes over multiplication. -/ star_mul : ∀ r s : R, star (r * s) = star s * star r export StarMul (star_mul) attribute [simp 900] star_mul section StarMul variable [Mul R] [StarMul R] theorem star_star_mul (x y : R) : star (star x * y) = star y * x := by rw [star_mul, star_star] theorem star_mul_star (x y : R) : star (x * star y) = y * star x := by rw [star_mul, star_star] @[simp] theorem semiconjBy_star_star_star {x y z : R} : SemiconjBy (star x) (star z) (star y) ↔ SemiconjBy x y z := by simp_rw [SemiconjBy, ← star_mul, star_inj, eq_comm] alias ⟨_, SemiconjBy.star_star_star⟩ := semiconjBy_star_star_star @[simp] theorem commute_star_star {x y : R} : Commute (star x) (star y) ↔ Commute x y := semiconjBy_star_star_star alias ⟨_, Commute.star_star⟩ := commute_star_star theorem commute_star_comm {x y : R} : Commute (star x) y ↔ Commute x (star y) := by rw [← commute_star_star, star_star] alias ⟨Commute.star_right, Commute.star_left⟩ := commute_star_comm end StarMul /-- In a commutative ring, make `simp` prefer leaving the order unchanged. -/ @[simp] theorem star_mul' [CommMagma R] [StarMul R] (x y : R) : star (x * y) = star x * star y := (star_mul x y).trans (mul_comm _ _) /-- `star` as a `MulEquiv` from `R` to `Rᵐᵒᵖ` -/ @[simps apply] def starMulEquiv [Mul R] [StarMul R] : R ≃* Rᵐᵒᵖ := { (InvolutiveStar.star_involutive.toPerm star).trans opEquiv with toFun := fun x => MulOpposite.op (star x) map_mul' := fun x y => by simp only [star_mul, op_mul] } /-- `star` as a `MulAut` for commutative `R`. -/ @[simps apply] def starMulAut [CommSemigroup R] [StarMul R] : MulAut R := { InvolutiveStar.star_involutive.toPerm star with toFun := star map_mul' := star_mul' } variable (R) in @[simp] theorem star_one [MulOneClass R] [StarMul R] : star (1 : R) = 1 := op_injective <| (starMulEquiv : R ≃* Rᵐᵒᵖ).map_one.trans op_one.symm @[simp] lemma Pi.star_mulSingle {ι : Type*} {R : ι → Type*} [DecidableEq ι] [∀ i, MulOneClass (R i)] [∀ i, StarMul (R i)] (i : ι) (r : R i) : star (mulSingle i r) = mulSingle i (star r) := by ext; exact apply_mulSingle (fun _ ↦ star) (fun _ ↦ star_one _) .. @[simp] theorem star_pow [Monoid R] [StarMul R] (x : R) (n : ℕ) : star (x ^ n) = star x ^ n := op_injective <| ((starMulEquiv : R ≃* Rᵐᵒᵖ).toMonoidHom.map_pow x n).trans (op_pow (star x) n).symm @[simp] theorem star_inv [Group R] [StarMul R] (x : R) : star x⁻¹ = (star x)⁻¹ := op_injective <| ((starMulEquiv : R ≃* Rᵐᵒᵖ).toMonoidHom.map_inv x).trans (op_inv (star x)).symm @[simp] theorem star_zpow [Group R] [StarMul R] (x : R) (z : ℤ) : star (x ^ z) = star x ^ z := op_injective <| ((starMulEquiv : R ≃* Rᵐᵒᵖ).toMonoidHom.map_zpow x z).trans (op_zpow (star x) z).symm /-- When multiplication is commutative, `star` preserves division. -/ @[simp] theorem star_div [CommGroup R] [StarMul R] (x y : R) : star (x / y) = star x / star y := map_div (starMulAut : R ≃* R) _ _ /-- Any commutative monoid admits the trivial `*`-structure. See note [reducible non-instances]. -/ abbrev starMulOfComm {R : Type*} [CommMonoid R] : StarMul R where star := id star_involutive _ := rfl star_mul := mul_comm section attribute [local instance] starMulOfComm /-- Note that since `starMulOfComm` is reducible, `simp` can already prove this. -/ theorem star_id_of_comm {R : Type*} [CommMonoid R] {x : R} : star x = x := rfl end /-- A `*`-additive monoid `R` is an additive monoid with an involutive `star` operation which preserves addition. -/ class StarAddMonoid (R : Type u) [AddMonoid R] extends InvolutiveStar R where /-- `star` commutes with addition -/ star_add : ∀ r s : R, star (r + s) = star r + star s export StarAddMonoid (star_add) attribute [simp] star_add /-- `star` as an `AddEquiv` -/ @[simps apply] def starAddEquiv [AddMonoid R] [StarAddMonoid R] : R ≃+ R := { InvolutiveStar.star_involutive.toPerm star with toFun := star map_add' := star_add } variable (R) in @[simp] theorem star_zero [AddMonoid R] [StarAddMonoid R] : star (0 : R) = 0 := (starAddEquiv : R ≃+ R).map_zero @[simp] lemma Pi.star_single {ι : Type*} {R : ι → Type*} [DecidableEq ι] [∀ i, AddMonoid (R i)] [∀ i, StarAddMonoid (R i)] (i : ι) (r : R i) : star (single i r) = single i (star r) := by ext; exact apply_single (fun _ ↦ star) (fun _ ↦ star_zero _) .. @[simp] theorem star_eq_zero [AddMonoid R] [StarAddMonoid R] {x : R} : star x = 0 ↔ x = 0 := starAddEquiv.map_eq_zero_iff (M := R) theorem star_ne_zero [AddMonoid R] [StarAddMonoid R] {x : R} : star x ≠ 0 ↔ x ≠ 0 := by simp only [ne_eq, star_eq_zero] @[simp] theorem star_neg [AddGroup R] [StarAddMonoid R] (r : R) : star (-r) = -star r := (starAddEquiv : R ≃+ R).map_neg _ @[simp] theorem star_sub [AddGroup R] [StarAddMonoid R] (r s : R) : star (r - s) = star r - star s := (starAddEquiv : R ≃+ R).map_sub _ _ @[simp] theorem star_nsmul [AddMonoid R] [StarAddMonoid R] (n : ℕ) (x : R) : star (n • x) = n • star x := (starAddEquiv : R ≃+ R).toAddMonoidHom.map_nsmul _ _ @[simp] theorem star_zsmul [AddGroup R] [StarAddMonoid R] (n : ℤ) (x : R) : star (n • x) = n • star x := (starAddEquiv : R ≃+ R).toAddMonoidHom.map_zsmul _ _ /-- A `*`-ring `R` is a non-unital, non-associative (semi)ring with an involutive `star` operation which is additive which makes `R` with its multiplicative structure into a `*`-multiplication (i.e. `star (r * s) = star s * star r`). -/ class StarRing (R : Type u) [NonUnitalNonAssocSemiring R] extends StarMul R where /-- `star` commutes with addition -/ star_add : ∀ r s : R, star (r + s) = star r + star s instance (priority := 100) StarRing.toStarAddMonoid [NonUnitalNonAssocSemiring R] [StarRing R] : StarAddMonoid R where star_add := StarRing.star_add /-- `star` as a `RingEquiv` from `R` to `Rᵐᵒᵖ` -/ @[simps apply] def starRingEquiv [NonUnitalNonAssocSemiring R] [StarRing R] : R ≃+* Rᵐᵒᵖ := { starAddEquiv.trans (MulOpposite.opAddEquiv : R ≃+ Rᵐᵒᵖ), starMulEquiv with toFun := fun x => MulOpposite.op (star x) } @[simp, norm_cast] theorem star_natCast [NonAssocSemiring R] [StarRing R] (n : ℕ) : star (n : R) = n := (congr_arg unop (map_natCast (starRingEquiv : R ≃+* Rᵐᵒᵖ) n)).trans (unop_natCast _) @[simp] theorem star_ofNat [NonAssocSemiring R] [StarRing R] (n : ℕ) [n.AtLeastTwo] : star (ofNat(n) : R) = ofNat(n) := star_natCast _ section @[simp, norm_cast] theorem star_intCast [NonAssocRing R] [StarRing R] (z : ℤ) : star (z : R) = z := (congr_arg unop <| map_intCast (starRingEquiv : R ≃+* Rᵐᵒᵖ) z).trans (unop_intCast _) end section CommSemiring variable [CommSemiring R] [StarRing R] /-- `star` as a ring automorphism, for commutative `R`. -/ @[simps apply] def starRingAut : RingAut R := { starAddEquiv, starMulAut (R := R) with toFun := star } variable (R) in /-- `star` as a ring endomorphism, for commutative `R`. This is used to denote complex conjugation, and is available under the notation `conj` in the scope `ComplexConjugate`. Note that this is the preferred form (over `starRingAut`, available under the same hypotheses) because the notation `E →ₗ⋆[R] F` for an `R`-conjugate-linear map (short for `E →ₛₗ[starRingEnd R] F`) does not pretty-print if there is a coercion involved, as would be the case for `(↑starRingAut : R →* R)`. -/ def starRingEnd : R →+* R := @starRingAut R _ _ @[inherit_doc] scoped[ComplexConjugate] notation "conj" => starRingEnd _ /-- This is not a simp lemma, since we usually want simp to keep `starRingEnd` bundled. For example, for complex conjugation, we don't want simp to turn `conj x` into the bare function `star x` automatically since most lemmas are about `conj x`. -/ theorem starRingEnd_apply (x : R) : starRingEnd R x = star x := rfl -- Not `@[simp]` because `simp` can already prove it. theorem starRingEnd_self_apply (x : R) : starRingEnd R (starRingEnd R x) = x := star_star x instance RingHom.involutiveStar {S : Type*} [NonAssocSemiring S] : InvolutiveStar (S →+* R) where toStar := { star := fun f => RingHom.comp (starRingEnd R) f } star_involutive := by intro ext simp only [RingHom.coe_comp, Function.comp_apply, starRingEnd_self_apply] theorem RingHom.star_def {S : Type*} [NonAssocSemiring S] (f : S →+* R) : Star.star f = RingHom.comp (starRingEnd R) f := rfl theorem RingHom.star_apply {S : Type*} [NonAssocSemiring S] (f : S →+* R) (s : S) : star f s = star (f s) := rfl -- A more convenient name for complex conjugation alias Complex.conj_conj := starRingEnd_self_apply alias RCLike.conj_conj := starRingEnd_self_apply open scoped ComplexConjugate @[simp] lemma conj_trivial [TrivialStar R] (a : R) : conj a = a := star_trivial _ end CommSemiring @[simp] theorem star_inv₀ [GroupWithZero R] [StarMul R] (x : R) : star x⁻¹ = (star x)⁻¹ := op_injective <| (map_inv₀ (starMulEquiv : R ≃* Rᵐᵒᵖ) x).trans (op_inv (star x)).symm @[simp] theorem star_zpow₀ [GroupWithZero R] [StarMul R] (x : R) (z : ℤ) : star (x ^ z) = star x ^ z := op_injective <| (map_zpow₀ (starMulEquiv : R ≃* Rᵐᵒᵖ) x z).trans (op_zpow (star x) z).symm /-- When multiplication is commutative, `star` preserves division. -/ @[simp] theorem star_div₀ [CommGroupWithZero R] [StarMul R] (x y : R) : star (x / y) = star x / star y := by apply op_injective rw [division_def, op_div, mul_comm, star_mul, star_inv₀, op_mul, op_inv] /-- Any commutative semiring admits the trivial `*`-structure. See note [reducible non-instances]. -/ abbrev starRingOfComm {R : Type*} [CommSemiring R] : StarRing R := { starMulOfComm with star_add := fun _ _ => rfl } instance Nat.instStarRing : StarRing ℕ := starRingOfComm instance Int.instStarRing : StarRing ℤ := starRingOfComm instance Nat.instTrivialStar : TrivialStar ℕ := ⟨fun _ ↦ rfl⟩ instance Int.instTrivialStar : TrivialStar ℤ := ⟨fun _ ↦ rfl⟩ /-- A star module `A` over a star ring `R` is a module which is a star additive monoid, and the two star structures are compatible in the sense `star (r • a) = star r • star a`. Note that it is up to the user of this typeclass to enforce `[Semiring R] [StarRing R] [AddCommMonoid A] [StarAddMonoid A] [Module R A]`, and that the statement only requires `[Star R] [Star A] [SMul R A]`. If used as `[CommRing R] [StarRing R] [Semiring A] [StarRing A] [Algebra R A]`, this represents a star algebra. -/ class StarModule (R : Type u) (A : Type v) [Star R] [Star A] [SMul R A] : Prop where /-- `star` commutes with scalar multiplication -/ star_smul : ∀ (r : R) (a : A), star (r • a) = star r • star a export StarModule (star_smul) attribute [simp] star_smul /-- A commutative star monoid is a star module over itself via `Monoid.toMulAction`. -/ instance StarMul.toStarModule [CommMonoid R] [StarMul R] : StarModule R R := ⟨star_mul'⟩ instance StarAddMonoid.toStarModuleNat {α} [AddCommMonoid α] [StarAddMonoid α] : StarModule ℕ α where star_smul := star_nsmul instance StarAddMonoid.toStarModuleInt {α} [AddCommGroup α] [StarAddMonoid α] : StarModule ℤ α where star_smul := star_zsmul namespace RingHomInvPair /-- Instance needed to define star-linear maps over a commutative star ring (ex: conjugate-linear maps when R = ℂ). -/ instance [CommSemiring R] [StarRing R] : RingHomInvPair (starRingEnd R) (starRingEnd R) := ⟨RingHom.ext star_star, RingHom.ext star_star⟩ end RingHomInvPair section /-- `StarHomClass F R S` states that `F` is a type of `star`-preserving maps from `R` to `S`. -/ class StarHomClass (F : Type*) (R S : outParam Type*) [Star R] [Star S] [FunLike F R S] : Prop where /-- the maps preserve star -/ map_star : ∀ (f : F) (r : R), f (star r) = star (f r) export StarHomClass (map_star) end /-! ### Instances -/ namespace Units variable [Monoid R] [StarMul R] instance : StarMul Rˣ where star u := { val := star u inv := star ↑u⁻¹ val_inv := (star_mul _ _).symm.trans <| (congr_arg star u.inv_val).trans <| star_one _ inv_val := (star_mul _ _).symm.trans <| (congr_arg star u.val_inv).trans <| star_one _ } star_involutive _ := Units.ext (star_involutive _) star_mul _ _ := Units.ext (star_mul _ _) @[simp] theorem coe_star (u : Rˣ) : ↑(star u) = (star ↑u : R) := rfl @[simp] theorem coe_star_inv (u : Rˣ) : ↑(star u)⁻¹ = (star ↑u⁻¹ : R) := rfl instance {A : Type*} [Star A] [SMul R A] [StarModule R A] : StarModule Rˣ A := ⟨fun u a => star_smul (u : R) a⟩ end Units protected theorem IsUnit.star [Monoid R] [StarMul R] {a : R} : IsUnit a → IsUnit (star a) | ⟨u, hu⟩ => ⟨Star.star u, hu ▸ rfl⟩ @[simp] theorem isUnit_star [Monoid R] [StarMul R] {a : R} : IsUnit (star a) ↔ IsUnit a := ⟨fun h => star_star a ▸ h.star, IsUnit.star⟩ theorem Ring.inverse_star [Semiring R] [StarRing R] (a : R) : Ring.inverse (star a) = star (Ring.inverse a) := by by_cases ha : IsUnit a · obtain ⟨u, rfl⟩ := ha rw [Ring.inverse_unit, ← Units.coe_star, Ring.inverse_unit, ← Units.coe_star_inv] rw [Ring.inverse_non_unit _ ha, Ring.inverse_non_unit _ (mt isUnit_star.mp ha), star_zero] protected instance Invertible.star {R : Type*} [MulOneClass R] [StarMul R] (r : R) [Invertible r] : Invertible (star r) where invOf := Star.star (⅟r) invOf_mul_self := by rw [← star_mul, mul_invOf_self, star_one] mul_invOf_self := by rw [← star_mul, invOf_mul_self, star_one] theorem star_invOf {R : Type*} [Monoid R] [StarMul R] (r : R) [Invertible r] [Invertible (star r)] : star (⅟r) = ⅟(star r) := by have : star (⅟r) = star (⅟r) * ((star r) * ⅟(star r)) := by simp only [mul_invOf_self, mul_one] rw [this, ← mul_assoc] have : (star (⅟r)) * (star r) = star 1 := by rw [← star_mul, mul_invOf_self] rw [this, star_one, one_mul] section Regular protected theorem IsLeftRegular.star [Mul R] [StarMul R] {x : R} (hx : IsLeftRegular x) : IsRightRegular (star x) := fun a b h => star_injective <| hx <| by simpa using congr_arg Star.star h protected theorem IsRightRegular.star [Mul R] [StarMul R] {x : R} (hx : IsRightRegular x) : IsLeftRegular (star x) := fun a b h => star_injective <| hx <| by simpa using congr_arg Star.star h protected theorem IsRegular.star [Mul R] [StarMul R] {x : R} (hx : IsRegular x) : IsRegular (star x) := ⟨hx.right.star, hx.left.star⟩ @[simp] theorem isRightRegular_star_iff [Mul R] [StarMul R] {x : R} : IsRightRegular (star x) ↔ IsLeftRegular x := ⟨fun h => star_star x ▸ h.star, (·.star)⟩ @[simp] theorem isLeftRegular_star_iff [Mul R] [StarMul R] {x : R} : IsLeftRegular (star x) ↔ IsRightRegular x := ⟨fun h => star_star x ▸ h.star, (·.star)⟩ @[simp] theorem isRegular_star_iff [Mul R] [StarMul R] {x : R} : IsRegular (star x) ↔ IsRegular x := by rw [isRegular_iff, isRegular_iff, isRightRegular_star_iff, isLeftRegular_star_iff, and_comm] end Regular namespace MulOpposite /-- The opposite type carries the same star operation. -/ instance [Star R] : Star Rᵐᵒᵖ where star r := op (star r.unop) @[simp] theorem unop_star [Star R] (r : Rᵐᵒᵖ) : unop (star r) = star (unop r) := rfl @[simp] theorem op_star [Star R] (r : R) : op (star r) = star (op r) := rfl instance [InvolutiveStar R] : InvolutiveStar Rᵐᵒᵖ where star_involutive r := unop_injective (star_star r.unop) instance [Mul R] [StarMul R] : StarMul Rᵐᵒᵖ where star_mul x y := unop_injective (star_mul y.unop x.unop) instance [AddMonoid R] [StarAddMonoid R] : StarAddMonoid Rᵐᵒᵖ where star_add x y := unop_injective (star_add x.unop y.unop) instance [NonUnitalSemiring R] [StarRing R] : StarRing Rᵐᵒᵖ where star_add x y := unop_injective (star_add x.unop y.unop) instance {M : Type*} [Star R] [Star M] [SMul R M] [StarModule R M] : StarModule R Mᵐᵒᵖ where star_smul r x := unop_injective (star_smul r x.unop) end MulOpposite /-- A commutative star monoid is a star module over its opposite via `Monoid.toOppositeMulAction`. -/ instance StarSemigroup.toOpposite_starModule [CommMonoid R] [StarMul R] : StarModule Rᵐᵒᵖ R := ⟨fun r s => star_mul' s r.unop⟩
.lake/packages/mathlib/Mathlib/Algebra/Star/Subsemiring.lean
import Mathlib.Algebra.Star.NonUnitalSubsemiring import Mathlib.Algebra.Ring.Subsemiring.Basic /-! # Star subrings A *-subring is a subring of a *-ring which is closed under *. -/ universe v /-- A (unital) star subsemiring is a non-associative ring which is closed under the `star` operation. -/ structure StarSubsemiring (R : Type v) [NonAssocSemiring R] [Star R] : Type v extends Subsemiring R where /-- The `carrier` of a `StarSubsemiring` is closed under the `star` operation. -/ star_mem' {a} : a ∈ carrier → star a ∈ carrier section StarSubsemiring namespace StarSubsemiring /-- Reinterpret a `StarSubsemiring` as a `Subsemiring`. -/ add_decl_doc StarSubsemiring.toSubsemiring instance setLike {R : Type v} [NonAssocSemiring R] [Star R] : SetLike (StarSubsemiring R) R where coe {s} := s.carrier coe_injective' p q h := by obtain ⟨⟨⟨⟨_, _⟩, _⟩, _⟩, _⟩ := p; cases q; congr initialize_simps_projections StarSubsemiring (carrier → coe, as_prefix coe) variable {R : Type v} [NonAssocSemiring R] [StarRing R] /-- The actual `StarSubsemiring` obtained from an element of a `StarSubsemiringClass`. -/ @[simps] def ofClass {S R : Type*} [NonAssocSemiring R] [SetLike S R] [StarRing R] [SubsemiringClass S R] [StarMemClass S R] (s : S) : StarSubsemiring R where carrier := s add_mem' := add_mem zero_mem' := zero_mem _ mul_mem' := mul_mem one_mem' := one_mem _ star_mem' := star_mem instance (priority := 100) : CanLift (Set R) (StarSubsemiring R) (↑) (fun s ↦ 0 ∈ s ∧ (∀ {x y}, x ∈ s → y ∈ s → x + y ∈ s) ∧ 1 ∈ s ∧ (∀ {x y}, x ∈ s → y ∈ s → x * y ∈ s) ∧ (∀ {x}, x ∈ s → star x ∈ s)) where prf s h := ⟨ { carrier := s zero_mem' := h.1 add_mem' := h.2.1 one_mem' := h.2.2.1 mul_mem' := h.2.2.2.1 star_mem' := h.2.2.2.2 }, rfl ⟩ instance starMemClass : StarMemClass (StarSubsemiring R) R where star_mem {s} := s.star_mem' instance subsemiringClass : SubsemiringClass (StarSubsemiring R) R where add_mem {s} := s.add_mem' mul_mem {s} := s.mul_mem' zero_mem {s} := s.zero_mem' one_mem {s} := s.one_mem' -- this uses the `Star` instance `s` inherits from `StarMemClass (StarSubsemiring R A) A` instance starRing (s : StarSubsemiring R) : StarRing s := { StarMemClass.instStar s with star_involutive := fun r => Subtype.ext (star_star (r : R)) star_mul := fun r₁ r₂ => Subtype.ext (star_mul (r₁ : R) (r₂ : R)) star_add := fun r₁ r₂ => Subtype.ext (star_add (r₁ : R) (r₂ : R)) } instance semiring (s : StarSubsemiring R) : NonAssocSemiring s := s.toSubsemiring.toNonAssocSemiring theorem mem_carrier {s : StarSubsemiring R} {x : R} : x ∈ s.carrier ↔ x ∈ s := Iff.rfl @[ext] theorem ext {S T : StarSubsemiring R} (h : ∀ x : R, x ∈ S ↔ x ∈ T) : S = T := SetLike.ext h @[simp] lemma coe_mk (S : Subsemiring R) (h) : ((⟨S, h⟩ : StarSubsemiring R) : Set R) = S := rfl @[simp] theorem mem_toSubsemiring {S : StarSubsemiring R} {x} : x ∈ S.toSubsemiring ↔ x ∈ S := Iff.rfl @[simp] theorem coe_toSubsemiring (S : StarSubsemiring R) : (S.toSubsemiring : Set R) = S := rfl theorem toSubsemiring_injective : Function.Injective (toSubsemiring : StarSubsemiring R → Subsemiring R) := fun S T h => ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h] theorem toSubsemiring_inj {S U : StarSubsemiring R} : S.toSubsemiring = U.toSubsemiring ↔ S = U := toSubsemiring_injective.eq_iff theorem toSubsemiring_le_iff {S₁ S₂ : StarSubsemiring R} : S₁.toSubsemiring ≤ S₂.toSubsemiring ↔ S₁ ≤ S₂ := Iff.rfl /-- Copy of a non-unital star subalgebra with a new `carrier` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (S : StarSubsemiring R) (s : Set R) (hs : s = ↑S) : StarSubsemiring R where toSubsemiring := Subsemiring.copy S.toSubsemiring s hs star_mem' := @fun a ha => hs ▸ (S.star_mem' (by simpa [hs] using ha) : star a ∈ (S : Set R)) @[simp, norm_cast] theorem coe_copy (S : StarSubsemiring R) (s : Set R) (hs : s = ↑S) : (S.copy s hs : Set R) = s := rfl theorem copy_eq (S : StarSubsemiring R) (s : Set R) (hs : s = ↑S) : S.copy s hs = S := SetLike.coe_injective hs section Center variable (R) /-- The center of a semiring `R` is the set of elements that commute and associate with everything in `R` -/ def center (R) [NonAssocSemiring R] [StarRing R] : StarSubsemiring R where toSubsemiring := Subsemiring.center R star_mem' := Set.star_mem_center end Center end StarSubsemiring end StarSubsemiring section SubStarSemigroup variable (A) [Mul A] [StarMul A] namespace SubStarSemigroup /-- The center of magma `A` is the set of elements that commute and associate with everything in `A`, here realized as a `SubStarSemigroup`. -/ def center : SubStarSemigroup A := { Subsemigroup.center A with star_mem' := Set.star_mem_center } end SubStarSemigroup end SubStarSemigroup
.lake/packages/mathlib/Mathlib/Algebra/Star/NonUnitalSubsemiring.lean
import Mathlib.Algebra.Ring.Defs import Mathlib.Algebra.Group.Subsemigroup.Basic import Mathlib.RingTheory.NonUnitalSubsemiring.Basic import Mathlib.Algebra.Star.Center /-! # Non-unital Star Subsemirings In this file we define `NonUnitalStarSubsemiring`s and the usual operations on them. ## Implementation This file is heavily inspired by `Mathlib/Algebra/Star/NonUnitalSubalgebra.lean`. -/ universe v w w' variable {A : Type v} {B : Type w} {C : Type w'} /-- A sub star semigroup is a subset of a magma which is closed under the `star`. -/ structure SubStarSemigroup (M : Type v) [Mul M] [Star M] : Type v extends Subsemigroup M where /-- The `carrier` of a `StarSubset` is closed under the `star` operation. -/ star_mem' : ∀ {a : M} (_ha : a ∈ carrier), star a ∈ carrier /-- Reinterpret a `SubStarSemigroup` as a `Subsemigroup`. -/ add_decl_doc SubStarSemigroup.toSubsemigroup /-- A non-unital star subsemiring is a non-unital subsemiring which also is closed under the `star` operation. -/ structure NonUnitalStarSubsemiring (R : Type v) [NonUnitalNonAssocSemiring R] [Star R] : Type v extends NonUnitalSubsemiring R where /-- The `carrier` of a `NonUnitalStarSubsemiring` is closed under the `star` operation. -/ star_mem' : ∀ {a : R} (_ha : a ∈ carrier), star a ∈ carrier /-- Reinterpret a `NonUnitalStarSubsemiring` as a `NonUnitalSubsemiring`. -/ add_decl_doc NonUnitalStarSubsemiring.toNonUnitalSubsemiring section NonUnitalStarSubsemiring namespace NonUnitalStarSubsemiring instance instSetLike {R : Type v} [NonUnitalNonAssocSemiring R] [Star R] : SetLike (NonUnitalStarSubsemiring R) R where coe {s} := s.carrier coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective h initialize_simps_projections NonUnitalStarSubsemiring (carrier → coe, as_prefix coe) variable {R : Type v} [NonUnitalNonAssocSemiring R] [StarRing R] /-- The actual `NonUnitalStarSubsemiring` obtained from an element of a type satisfying `NonUnitalSubsemiringClass` and `StarMemClass`. -/ @[simps] def ofClass {S R : Type*} [NonUnitalNonAssocSemiring R] [StarRing R] [SetLike S R] [NonUnitalSubsemiringClass S R] [StarMemClass S R] (s : S) : NonUnitalStarSubsemiring R where carrier := s add_mem' := add_mem zero_mem' := zero_mem _ mul_mem' := mul_mem star_mem' := star_mem instance (priority := 100) : CanLift (Set R) (NonUnitalStarSubsemiring R) (↑) (fun s ↦ 0 ∈ s ∧ (∀ {x y}, x ∈ s → y ∈ s → x + y ∈ s) ∧ (∀ {x y}, x ∈ s → y ∈ s → x * y ∈ s) ∧ ∀ {x}, x ∈ s → star x ∈ s) where prf s h := ⟨ { carrier := s zero_mem' := h.1 add_mem' := h.2.1 mul_mem' := h.2.2.1 star_mem' := h.2.2.2 }, rfl ⟩ instance instNonUnitalSubsemiringClass : NonUnitalSubsemiringClass (NonUnitalStarSubsemiring R) R where add_mem {s} := s.add_mem' mul_mem {s} := s.mul_mem' zero_mem {s} := s.zero_mem' instance instStarMemClass : StarMemClass (NonUnitalStarSubsemiring R) R where star_mem {s} := s.star_mem' theorem mem_carrier {s : NonUnitalStarSubsemiring R} {x : R} : x ∈ s.carrier ↔ x ∈ s := Iff.rfl /-- Copy of a non-unital star subsemiring with a new `carrier` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (S : NonUnitalStarSubsemiring R) (s : Set R) (hs : s = ↑S) : NonUnitalStarSubsemiring R := { S.toNonUnitalSubsemiring.copy s hs with star_mem' := fun {x} (hx : x ∈ s) => by change star x ∈ s rw [hs] at hx ⊢ exact S.star_mem' hx } @[simp, norm_cast] theorem coe_copy (S : NonUnitalStarSubsemiring R) (s : Set R) (hs : s = ↑S) : (S.copy s hs : Set R) = s := rfl theorem copy_eq (S : NonUnitalStarSubsemiring R) (s : Set R) (hs : s = ↑S) : S.copy s hs = S := SetLike.coe_injective hs section Center variable (R) /-- The center of a non-unital non-associative semiring `R` is the set of elements that commute and associate with everything in `R`, here realized as non-unital star subsemiring. -/ def center (R) [NonUnitalNonAssocSemiring R] [StarRing R] : NonUnitalStarSubsemiring R where toNonUnitalSubsemiring := NonUnitalSubsemiring.center R star_mem' := Set.star_mem_center end Center end NonUnitalStarSubsemiring end NonUnitalStarSubsemiring
.lake/packages/mathlib/Mathlib/Algebra/Star/NonUnitalSubalgebra.lean
import Mathlib.Algebra.Algebra.NonUnitalSubalgebra import Mathlib.Algebra.Star.StarAlgHom import Mathlib.Algebra.Star.Center import Mathlib.Algebra.Star.SelfAdjoint import Mathlib.Algebra.Star.Prod /-! # Non-unital Star Subalgebras In this file we define `NonUnitalStarSubalgebra`s and the usual operations on them (`map`, `comap`). ## TODO * once we have scalar actions by semigroups (as opposed to monoids), implement the action of a non-unital subalgebra on the larger algebra. -/ namespace StarMemClass /-- If a type carries an involutive star, then any star-closed subset does too. -/ instance instInvolutiveStar {S R : Type*} [InvolutiveStar R] [SetLike S R] [StarMemClass S R] (s : S) : InvolutiveStar s where star_involutive r := Subtype.ext <| star_star (r : R) /-- In a star magma (i.e., a multiplication with an antimultiplicative involutive star operation), any star-closed subset which is also closed under multiplication is itself a star magma. -/ instance instStarMul {S R : Type*} [Mul R] [StarMul R] [SetLike S R] [MulMemClass S R] [StarMemClass S R] (s : S) : StarMul s where star_mul _ _ := Subtype.ext <| star_mul _ _ /-- In a `StarAddMonoid` (i.e., an additive monoid with an additive involutive star operation), any star-closed subset which is also closed under addition and contains zero is itself a `StarAddMonoid`. -/ instance instStarAddMonoid {S R : Type*} [AddMonoid R] [StarAddMonoid R] [SetLike S R] [AddSubmonoidClass S R] [StarMemClass S R] (s : S) : StarAddMonoid s where star_add _ _ := Subtype.ext <| star_add _ _ /-- In a star ring (i.e., a non-unital, non-associative, semiring with an additive, antimultiplicative, involutive star operation), a star-closed non-unital subsemiring is itself a star ring. -/ instance instStarRing {S R : Type*} [NonUnitalNonAssocSemiring R] [StarRing R] [SetLike S R] [NonUnitalSubsemiringClass S R] [StarMemClass S R] (s : S) : StarRing s := { StarMemClass.instStarMul s, StarMemClass.instStarAddMonoid s with } /-- In a star `R`-module (i.e., `star (r • m) = (star r) • m`) any star-closed subset which is also closed under the scalar action by `R` is itself a star `R`-module. -/ instance instStarModule {S : Type*} (R : Type*) {M : Type*} [Star R] [Star M] [SMul R M] [StarModule R M] [SetLike S M] [SMulMemClass S R M] [StarMemClass S M] (s : S) : StarModule R s where star_smul _ _ := Subtype.ext <| star_smul _ _ end StarMemClass universe u u' v v' w w' w'' variable {F : Type v'} {R' : Type u'} {R : Type u} variable {A : Type v} {B : Type w} {C : Type w'} namespace NonUnitalStarSubalgebraClass variable [CommSemiring R] [NonUnitalNonAssocSemiring A] variable [Star A] [Module R A] variable {S : Type w''} [SetLike S A] [NonUnitalSubsemiringClass S A] variable [hSR : SMulMemClass S R A] [StarMemClass S A] (s : S) /-- Embedding of a non-unital star subalgebra into the non-unital star algebra. -/ def subtype (s : S) : s →⋆ₙₐ[R] A := { NonUnitalSubalgebraClass.subtype s with toFun := Subtype.val map_star' := fun _ => rfl } variable {s} in @[simp] lemma subtype_apply (x : s) : subtype s x = x := rfl lemma subtype_injective : Function.Injective (subtype s) := Subtype.coe_injective @[simp] theorem coe_subtype : (subtype s : s → A) = Subtype.val := rfl end NonUnitalStarSubalgebraClass /-- A non-unital star subalgebra is a non-unital subalgebra which is closed under the `star` operation. -/ structure NonUnitalStarSubalgebra (R : Type u) (A : Type v) [CommSemiring R] [NonUnitalNonAssocSemiring A] [Module R A] [Star A] : Type v extends NonUnitalSubalgebra R A where /-- The `carrier` of a `NonUnitalStarSubalgebra` is closed under the `star` operation. -/ star_mem' : ∀ {a : A} (_ha : a ∈ carrier), star a ∈ carrier /-- Reinterpret a `NonUnitalStarSubalgebra` as a `NonUnitalSubalgebra`. -/ add_decl_doc NonUnitalStarSubalgebra.toNonUnitalSubalgebra namespace NonUnitalStarSubalgebra variable [CommSemiring R] variable [NonUnitalNonAssocSemiring A] [Module R A] [Star A] variable [NonUnitalNonAssocSemiring B] [Module R B] [Star B] variable [NonUnitalNonAssocSemiring C] [Module R C] [Star C] variable [FunLike F A B] [NonUnitalAlgHomClass F R A B] [StarHomClass F A B] instance instSetLike : SetLike (NonUnitalStarSubalgebra R A) A where coe {s} := s.carrier coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective h /-- The actual `NonUnitalStarSubalgebra` obtained from an element of a type satisfying `NonUnitalSubsemiringClass`, `SMulMemClass` and `StarMemClass`. -/ @[simps] def ofClass {S R A : Type*} [CommSemiring R] [NonUnitalNonAssocSemiring A] [Module R A] [Star A] [SetLike S A] [NonUnitalSubsemiringClass S A] [SMulMemClass S R A] [StarMemClass S A] (s : S) : NonUnitalStarSubalgebra R A where carrier := s add_mem' := add_mem zero_mem' := zero_mem _ mul_mem' := mul_mem smul_mem' := SMulMemClass.smul_mem star_mem' := star_mem instance (priority := 100) : CanLift (Set A) (NonUnitalStarSubalgebra R A) (↑) (fun s ↦ 0 ∈ s ∧ (∀ {x y}, x ∈ s → y ∈ s → x + y ∈ s) ∧ (∀ {x y}, x ∈ s → y ∈ s → x * y ∈ s) ∧ (∀ (r : R) {x}, x ∈ s → r • x ∈ s) ∧ ∀ {x}, x ∈ s → star x ∈ s) where prf s h := ⟨ { carrier := s zero_mem' := h.1 add_mem' := h.2.1 mul_mem' := h.2.2.1 smul_mem' := h.2.2.2.1 star_mem' := h.2.2.2.2 }, rfl ⟩ instance instNonUnitalSubsemiringClass : NonUnitalSubsemiringClass (NonUnitalStarSubalgebra R A) A where add_mem {s} := s.add_mem' mul_mem {s} := s.mul_mem' zero_mem {s} := s.zero_mem' instance instSMulMemClass : SMulMemClass (NonUnitalStarSubalgebra R A) R A where smul_mem {s} := s.smul_mem' instance instStarMemClass : StarMemClass (NonUnitalStarSubalgebra R A) A where star_mem {s} := s.star_mem' instance instNonUnitalSubringClass {R : Type u} {A : Type v} [CommRing R] [NonUnitalNonAssocRing A] [Module R A] [Star A] : NonUnitalSubringClass (NonUnitalStarSubalgebra R A) A := { NonUnitalStarSubalgebra.instNonUnitalSubsemiringClass with neg_mem := fun _S {x} hx => neg_one_smul R x ▸ SMulMemClass.smul_mem _ hx } theorem mem_carrier {s : NonUnitalStarSubalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s := Iff.rfl @[ext] theorem ext {S T : NonUnitalStarSubalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T := SetLike.ext h @[simp] theorem mem_toNonUnitalSubalgebra {S : NonUnitalStarSubalgebra R A} {x} : x ∈ S.toNonUnitalSubalgebra ↔ x ∈ S := Iff.rfl @[simp] theorem coe_toNonUnitalSubalgebra (S : NonUnitalStarSubalgebra R A) : (↑S.toNonUnitalSubalgebra : Set A) = S := rfl theorem toNonUnitalSubalgebra_injective : Function.Injective (toNonUnitalSubalgebra : NonUnitalStarSubalgebra R A → NonUnitalSubalgebra R A) := fun S T h => ext fun x => by rw [← mem_toNonUnitalSubalgebra, ← mem_toNonUnitalSubalgebra, h] theorem toNonUnitalSubalgebra_inj {S U : NonUnitalStarSubalgebra R A} : S.toNonUnitalSubalgebra = U.toNonUnitalSubalgebra ↔ S = U := toNonUnitalSubalgebra_injective.eq_iff theorem toNonUnitalSubalgebra_le_iff {S₁ S₂ : NonUnitalStarSubalgebra R A} : S₁.toNonUnitalSubalgebra ≤ S₂.toNonUnitalSubalgebra ↔ S₁ ≤ S₂ := Iff.rfl /-- Copy of a non-unital star subalgebra with a new `carrier` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (S : NonUnitalStarSubalgebra R A) (s : Set A) (hs : s = ↑S) : NonUnitalStarSubalgebra R A := { S.toNonUnitalSubalgebra.copy s hs with star_mem' := @fun x (hx : x ∈ s) => by change star x ∈ s rw [hs] at hx ⊢ exact S.star_mem' hx } @[simp, norm_cast] theorem coe_copy (S : NonUnitalStarSubalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s := rfl theorem copy_eq (S : NonUnitalStarSubalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S := SetLike.coe_injective hs variable (S : NonUnitalStarSubalgebra R A) /-- A non-unital star subalgebra over a ring is also a `Subring`. -/ def toNonUnitalSubring {R : Type u} {A : Type v} [CommRing R] [NonUnitalRing A] [Module R A] [Star A] (S : NonUnitalStarSubalgebra R A) : NonUnitalSubring A where toNonUnitalSubsemiring := S.toNonUnitalSubsemiring neg_mem' := neg_mem (s := S) @[simp] theorem mem_toNonUnitalSubring {R : Type u} {A : Type v} [CommRing R] [NonUnitalRing A] [Module R A] [Star A] {S : NonUnitalStarSubalgebra R A} {x} : x ∈ S.toNonUnitalSubring ↔ x ∈ S := Iff.rfl @[simp] theorem coe_toNonUnitalSubring {R : Type u} {A : Type v} [CommRing R] [NonUnitalRing A] [Module R A] [Star A] (S : NonUnitalStarSubalgebra R A) : (↑S.toNonUnitalSubring : Set A) = S := rfl theorem toNonUnitalSubring_injective {R : Type u} {A : Type v} [CommRing R] [NonUnitalRing A] [Module R A] [Star A] : Function.Injective (toNonUnitalSubring : NonUnitalStarSubalgebra R A → NonUnitalSubring A) := fun S T h => ext fun x => by rw [← mem_toNonUnitalSubring, ← mem_toNonUnitalSubring, h] theorem toNonUnitalSubring_inj {R : Type u} {A : Type v} [CommRing R] [NonUnitalRing A] [Module R A] [Star A] {S U : NonUnitalStarSubalgebra R A} : S.toNonUnitalSubring = U.toNonUnitalSubring ↔ S = U := toNonUnitalSubring_injective.eq_iff instance instInhabited : Inhabited S := ⟨(0 : S.toNonUnitalSubalgebra)⟩ section /-! `NonUnitalStarSubalgebra`s inherit structure from their `NonUnitalSubsemiringClass` and `NonUnitalSubringClass` instances. -/ instance toNonUnitalSemiring {R A} [CommSemiring R] [NonUnitalSemiring A] [Module R A] [Star A] (S : NonUnitalStarSubalgebra R A) : NonUnitalSemiring S := inferInstance instance toNonUnitalCommSemiring {R A} [CommSemiring R] [NonUnitalCommSemiring A] [Module R A] [Star A] (S : NonUnitalStarSubalgebra R A) : NonUnitalCommSemiring S := inferInstance instance toNonUnitalRing {R A} [CommRing R] [NonUnitalRing A] [Module R A] [Star A] (S : NonUnitalStarSubalgebra R A) : NonUnitalRing S := inferInstance instance toNonUnitalCommRing {R A} [CommRing R] [NonUnitalCommRing A] [Module R A] [Star A] (S : NonUnitalStarSubalgebra R A) : NonUnitalCommRing S := inferInstance end /-- The forgetful map from `NonUnitalStarSubalgebra` to `NonUnitalSubalgebra` as an `OrderEmbedding` -/ def toNonUnitalSubalgebra' : NonUnitalStarSubalgebra R A ↪o NonUnitalSubalgebra R A where toEmbedding := { toFun := fun S => S.toNonUnitalSubalgebra inj' := fun S T h => ext <| by apply SetLike.ext_iff.1 h } map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe section /-! `NonUnitalStarSubalgebra`s inherit structure from their `Submodule` coercions. -/ instance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S := SMulMemClass.toModule' _ R' R A S instance instModule : Module R S := S.module' instance instIsScalarTower' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S := S.toNonUnitalSubalgebra.instIsScalarTower' instance instIsScalarTower [IsScalarTower R A A] : IsScalarTower R S S where smul_assoc r x y := Subtype.ext <| smul_assoc r (x : A) (y : A) instance instSMulCommClass' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] [SMulCommClass R' R A] : SMulCommClass R' R S where smul_comm r' r s := Subtype.ext <| smul_comm r' r (s : A) instance instSMulCommClass [SMulCommClass R A A] : SMulCommClass R S S where smul_comm r x y := Subtype.ext <| smul_comm r (x : A) (y : A) end instance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S := ⟨fun {c x} h => have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg ((↑) : S → A) h) this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩ protected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl protected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl protected theorem coe_zero : ((0 : S) : A) = 0 := rfl protected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [NonUnitalNonAssocRing A] [Module R A] [Star A] {S : NonUnitalStarSubalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl protected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [NonUnitalNonAssocRing A] [Module R A] [Star A] {S : NonUnitalStarSubalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl @[simp, norm_cast] theorem coe_smul [SMul R' R] [SMul R' A] [IsScalarTower R' R A] (r : R') (x : S) : ↑(r • x) = r • (x : A) := rfl protected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 := ZeroMemClass.coe_eq_zero @[simp] theorem toNonUnitalSubalgebra_subtype : NonUnitalSubalgebraClass.subtype S = NonUnitalStarSubalgebraClass.subtype S := rfl @[simp] theorem toSubring_subtype {R A : Type*} [CommRing R] [NonUnitalNonAssocRing A] [Module R A] [Star A] (S : NonUnitalStarSubalgebra R A) : NonUnitalSubringClass.subtype S = NonUnitalStarSubalgebraClass.subtype S := rfl /-- Transport a non-unital star subalgebra via a non-unital star algebra homomorphism. -/ def map (f : F) (S : NonUnitalStarSubalgebra R A) : NonUnitalStarSubalgebra R B where toNonUnitalSubalgebra := S.toNonUnitalSubalgebra.map (f : A →ₙₐ[R] B) star_mem' := by rintro _ ⟨a, ha, rfl⟩; exact ⟨star a, star_mem (s := S) ha, map_star f a⟩ theorem map_mono {S₁ S₂ : NonUnitalStarSubalgebra R A} {f : F} : S₁ ≤ S₂ → (map f S₁ : NonUnitalStarSubalgebra R B) ≤ map f S₂ := Set.image_mono theorem map_injective {f : F} (hf : Function.Injective f) : Function.Injective (map f : NonUnitalStarSubalgebra R A → NonUnitalStarSubalgebra R B) := fun _S₁ _S₂ ih => ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih @[simp] theorem map_id (S : NonUnitalStarSubalgebra R A) : map (NonUnitalStarAlgHom.id R A) S = S := SetLike.coe_injective <| Set.image_id _ theorem map_map (S : NonUnitalStarSubalgebra R A) (g : B →⋆ₙₐ[R] C) (f : A →⋆ₙₐ[R] B) : (S.map f).map g = S.map (g.comp f) := SetLike.coe_injective <| Set.image_image _ _ _ @[simp] theorem mem_map {S : NonUnitalStarSubalgebra R A} {f : F} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y := NonUnitalSubalgebra.mem_map theorem map_toNonUnitalSubalgebra {S : NonUnitalStarSubalgebra R A} {f : F} : (map f S : NonUnitalStarSubalgebra R B).toNonUnitalSubalgebra = NonUnitalSubalgebra.map f S.toNonUnitalSubalgebra := SetLike.coe_injective rfl @[simp, norm_cast] theorem coe_map (S : NonUnitalStarSubalgebra R A) (f : F) : map f S = f '' S := rfl /-- Preimage of a non-unital star subalgebra under a non-unital star algebra homomorphism. -/ def comap (f : F) (S : NonUnitalStarSubalgebra R B) : NonUnitalStarSubalgebra R A where toNonUnitalSubalgebra := S.toNonUnitalSubalgebra.comap f star_mem' := @fun a (ha : f a ∈ S) => show f (star a) ∈ S from (map_star f a).symm ▸ star_mem (s := S) ha theorem map_le {S : NonUnitalStarSubalgebra R A} {f : F} {U : NonUnitalStarSubalgebra R B} : map f S ≤ U ↔ S ≤ comap f U := Set.image_subset_iff theorem gc_map_comap (f : F) : GaloisConnection (map f) (comap f) := fun _S _U => map_le @[simp] theorem mem_comap (S : NonUnitalStarSubalgebra R B) (f : F) (x : A) : x ∈ comap f S ↔ f x ∈ S := Iff.rfl @[simp, norm_cast] theorem coe_comap (S : NonUnitalStarSubalgebra R B) (f : F) : comap f S = f ⁻¹' (S : Set B) := rfl instance instNoZeroDivisors {R A : Type*} [CommSemiring R] [NonUnitalSemiring A] [NoZeroDivisors A] [Module R A] [Star A] (S : NonUnitalStarSubalgebra R A) : NoZeroDivisors S := NonUnitalSubsemiringClass.noZeroDivisors S end NonUnitalStarSubalgebra namespace NonUnitalSubalgebra variable [CommSemiring R] [NonUnitalSemiring A] [Module R A] [Star A] variable (s : NonUnitalSubalgebra R A) /-- A non-unital subalgebra closed under `star` is a non-unital star subalgebra. -/ def toNonUnitalStarSubalgebra (h_star : ∀ x, x ∈ s → star x ∈ s) : NonUnitalStarSubalgebra R A := { s with star_mem' := @h_star } @[simp] theorem mem_toNonUnitalStarSubalgebra {s : NonUnitalSubalgebra R A} {h_star} {x} : x ∈ s.toNonUnitalStarSubalgebra h_star ↔ x ∈ s := Iff.rfl @[simp] theorem coe_toNonUnitalStarSubalgebra (s : NonUnitalSubalgebra R A) (h_star) : (s.toNonUnitalStarSubalgebra h_star : Set A) = s := rfl @[simp] theorem toNonUnitalStarSubalgebra_toNonUnitalSubalgebra (s : NonUnitalSubalgebra R A) (h_star) : (s.toNonUnitalStarSubalgebra h_star).toNonUnitalSubalgebra = s := SetLike.coe_injective rfl @[simp] theorem _root_.NonUnitalStarSubalgebra.toNonUnitalSubalgebra_toNonUnitalStarSubalgebra (S : NonUnitalStarSubalgebra R A) : (S.toNonUnitalSubalgebra.toNonUnitalStarSubalgebra fun _ => star_mem (s := S)) = S := SetLike.coe_injective rfl end NonUnitalSubalgebra namespace NonUnitalStarAlgHom variable [CommSemiring R] variable [NonUnitalNonAssocSemiring A] [Module R A] [Star A] variable [NonUnitalNonAssocSemiring B] [Module R B] [Star B] variable [NonUnitalNonAssocSemiring C] [Module R C] [Star C] variable [FunLike F A B] [NonUnitalAlgHomClass F R A B] [StarHomClass F A B] /-- Range of an `NonUnitalAlgHom` as a `NonUnitalStarSubalgebra`. -/ protected def range (φ : F) : NonUnitalStarSubalgebra R B where toNonUnitalSubalgebra := NonUnitalAlgHom.range (φ : A →ₙₐ[R] B) star_mem' := by rintro _ ⟨a, rfl⟩; exact ⟨star a, map_star φ a⟩ @[simp] theorem mem_range (φ : F) {y : B} : y ∈ (NonUnitalStarAlgHom.range φ : NonUnitalStarSubalgebra R B) ↔ ∃ x : A, φ x = y := NonUnitalRingHom.mem_srange theorem mem_range_self (φ : F) (x : A) : φ x ∈ (NonUnitalStarAlgHom.range φ : NonUnitalStarSubalgebra R B) := (NonUnitalAlgHom.mem_range φ).2 ⟨x, rfl⟩ @[simp, norm_cast] theorem coe_range (φ : F) : ((NonUnitalStarAlgHom.range φ : NonUnitalStarSubalgebra R B) : Set B) = Set.range (φ : A → B) := by rfl theorem range_comp (f : A →⋆ₙₐ[R] B) (g : B →⋆ₙₐ[R] C) : NonUnitalStarAlgHom.range (g.comp f) = (NonUnitalStarAlgHom.range f).map g := SetLike.coe_injective (Set.range_comp g f) theorem range_comp_le_range (f : A →⋆ₙₐ[R] B) (g : B →⋆ₙₐ[R] C) : NonUnitalStarAlgHom.range (g.comp f) ≤ NonUnitalStarAlgHom.range g := SetLike.coe_mono (Set.range_comp_subset_range f g) /-- Restrict the codomain of a non-unital star algebra homomorphism. -/ def codRestrict (f : F) (S : NonUnitalStarSubalgebra R B) (hf : ∀ x, f x ∈ S) : A →⋆ₙₐ[R] S where toNonUnitalAlgHom := NonUnitalAlgHom.codRestrict f S.toNonUnitalSubalgebra hf map_star' := fun a => Subtype.ext <| map_star f a @[simp] theorem subtype_comp_codRestrict (f : F) (S : NonUnitalStarSubalgebra R B) (hf : ∀ x : A, f x ∈ S) : (NonUnitalStarSubalgebraClass.subtype S).comp (NonUnitalStarAlgHom.codRestrict f S hf) = f := NonUnitalStarAlgHom.ext fun _ => rfl @[simp] theorem coe_codRestrict (f : F) (S : NonUnitalStarSubalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) : ↑(NonUnitalStarAlgHom.codRestrict f S hf x) = f x := rfl theorem injective_codRestrict (f : F) (S : NonUnitalStarSubalgebra R B) (hf : ∀ x : A, f x ∈ S) : Function.Injective (NonUnitalStarAlgHom.codRestrict f S hf) ↔ Function.Injective f := ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy :)⟩ /-- Restrict the codomain of a non-unital star algebra homomorphism `f` to `f.range`. This is the bundled version of `Set.rangeFactorization`. -/ abbrev rangeRestrict (f : F) : A →⋆ₙₐ[R] (NonUnitalStarAlgHom.range f : NonUnitalStarSubalgebra R B) := NonUnitalStarAlgHom.codRestrict f (NonUnitalStarAlgHom.range f) (NonUnitalStarAlgHom.mem_range_self f) /-- The equalizer of two non-unital star `R`-algebra homomorphisms -/ def equalizer (ϕ ψ : F) : NonUnitalStarSubalgebra R A where toNonUnitalSubalgebra := NonUnitalAlgHom.equalizer ϕ ψ star_mem' := @fun x (hx : ϕ x = ψ x) => by simp [map_star, hx] @[simp] theorem mem_equalizer (φ ψ : F) (x : A) : x ∈ NonUnitalStarAlgHom.equalizer φ ψ ↔ φ x = ψ x := Iff.rfl end NonUnitalStarAlgHom namespace StarAlgEquiv variable [CommSemiring R] variable [NonUnitalSemiring A] [Module R A] [Star A] variable [NonUnitalSemiring B] [Module R B] [Star B] variable [NonUnitalSemiring C] [Module R C] [Star C] variable [FunLike F A B] [NonUnitalAlgHomClass F R A B] [StarHomClass F A B] /-- Restrict a non-unital star algebra homomorphism with a left inverse to an algebra isomorphism to its range. This is a computable alternative to `StarAlgEquiv.ofInjective`. -/ def ofLeftInverse' {g : B → A} {f : F} (h : Function.LeftInverse g f) : A ≃⋆ₐ[R] NonUnitalStarAlgHom.range f := { NonUnitalStarAlgHom.rangeRestrict f with toFun := NonUnitalStarAlgHom.rangeRestrict f invFun := g ∘ (NonUnitalStarSubalgebraClass.subtype <| NonUnitalStarAlgHom.range f) left_inv := h right_inv := fun x => Subtype.ext <| let ⟨x', hx'⟩ := (NonUnitalStarAlgHom.mem_range f).mp x.prop show f (g x) = x by rw [← hx', h x'] } @[simp] theorem ofLeftInverse'_apply {g : B → A} {f : F} (h : Function.LeftInverse g f) (x : A) : ofLeftInverse' h x = f x := rfl @[simp] theorem ofLeftInverse'_symm_apply {g : B → A} {f : F} (h : Function.LeftInverse g f) (x : NonUnitalStarAlgHom.range f) : (ofLeftInverse' h).symm x = g x := rfl /-- Restrict an injective non-unital star algebra homomorphism to a star algebra isomorphism -/ noncomputable def ofInjective' (f : F) (hf : Function.Injective f) : A ≃⋆ₐ[R] NonUnitalStarAlgHom.range f := ofLeftInverse' (Classical.choose_spec hf.hasLeftInverse) @[simp] theorem ofInjective'_apply (f : F) (hf : Function.Injective f) (x : A) : ofInjective' f hf x = f x := rfl end StarAlgEquiv /-! ### The star closure of a subalgebra -/ namespace NonUnitalSubalgebra open scoped Pointwise variable [CommSemiring R] [StarRing R] variable [NonUnitalSemiring A] [StarRing A] [Module R A] variable [StarModule R A] /-- The pointwise `star` of a non-unital subalgebra is a non-unital subalgebra. -/ instance instInvolutiveStar : InvolutiveStar (NonUnitalSubalgebra R A) where star S := { carrier := star S.carrier mul_mem' := @fun x y hx hy => by simpa only [Set.mem_star, NonUnitalSubalgebra.mem_carrier] using (star_mul x y).symm ▸ mul_mem hy hx add_mem' := @fun x y hx hy => by simpa only [Set.mem_star, NonUnitalSubalgebra.mem_carrier] using (star_add x y).symm ▸ add_mem hx hy zero_mem' := Set.mem_star.mp ((star_zero A).symm ▸ zero_mem S : star (0 : A) ∈ S) smul_mem' := fun r x hx => by simpa only [Set.mem_star, NonUnitalSubalgebra.mem_carrier] using (star_smul r x).symm ▸ SMulMemClass.smul_mem (star r) hx } star_involutive S := NonUnitalSubalgebra.ext fun x => ⟨fun hx => star_star x ▸ hx, fun hx => ((star_star x).symm ▸ hx : star (star x) ∈ S)⟩ @[simp] theorem mem_star_iff (S : NonUnitalSubalgebra R A) (x : A) : x ∈ star S ↔ star x ∈ S := Iff.rfl theorem star_mem_star_iff (S : NonUnitalSubalgebra R A) (x : A) : star x ∈ star S ↔ x ∈ S := by simp @[simp] theorem coe_star (S : NonUnitalSubalgebra R A) : star S = star (S : Set A) := rfl theorem star_mono : Monotone (star : NonUnitalSubalgebra R A → NonUnitalSubalgebra R A) := fun _ _ h _ hx => h hx variable (R) variable [IsScalarTower R A A] [SMulCommClass R A A] /-- The star operation on `NonUnitalSubalgebra` commutes with `NonUnitalAlgebra.adjoin`. -/ theorem star_adjoin_comm (s : Set A) : star (NonUnitalAlgebra.adjoin R s) = NonUnitalAlgebra.adjoin R (star s) := have this : ∀ t : Set A, NonUnitalAlgebra.adjoin R (star t) ≤ star (NonUnitalAlgebra.adjoin R t) := fun _ => NonUnitalAlgebra.adjoin_le fun _ hx => NonUnitalAlgebra.subset_adjoin R hx le_antisymm (by simpa only [star_star] using NonUnitalSubalgebra.star_mono (this (star s))) (this s) variable {R} /-- The `NonUnitalStarSubalgebra` obtained from `S : NonUnitalSubalgebra R A` by taking the smallest non-unital subalgebra containing both `S` and `star S`. -/ def starClosure (S : NonUnitalSubalgebra R A) : NonUnitalStarSubalgebra R A where toNonUnitalSubalgebra := S ⊔ star S star_mem' {a} ha := by simpa [← mem_star_iff _ a, ← (@NonUnitalAlgebra.gi R A _ _ _ _ _).l_sup_u _ _, star_adjoin_comm, Set.union_comm] using ha @[simp] theorem coe_starClosure (S : NonUnitalSubalgebra R A) : (S.starClosure : Set A) = (S ⊔ star S : NonUnitalSubalgebra R A) := rfl @[simp] theorem mem_starClosure (S : NonUnitalSubalgebra R A) {x : A} : x ∈ S.starClosure ↔ x ∈ S ⊔ star S := Iff.rfl @[simp] theorem starClosure_toNonUnitalSubalgebra (S : NonUnitalSubalgebra R A) : S.starClosure.toNonUnitalSubalgebra = S ⊔ star S := rfl @[deprecated (since := "2025-06-17")] alias starClosure_toNonunitalSubalgebra := starClosure_toNonUnitalSubalgebra theorem starClosure_le {S₁ : NonUnitalSubalgebra R A} {S₂ : NonUnitalStarSubalgebra R A} (h : S₁ ≤ S₂.toNonUnitalSubalgebra) : S₁.starClosure ≤ S₂ := NonUnitalStarSubalgebra.toNonUnitalSubalgebra_le_iff.1 <| sup_le h fun x hx => (star_star x ▸ star_mem (show star x ∈ S₂ from h <| (S₁.mem_star_iff _).1 hx) : x ∈ S₂) theorem starClosure_le_iff {S₁ : NonUnitalSubalgebra R A} {S₂ : NonUnitalStarSubalgebra R A} : S₁.starClosure ≤ S₂ ↔ S₁ ≤ S₂.toNonUnitalSubalgebra := ⟨fun h => le_sup_left.trans h, starClosure_le⟩ @[mono] theorem starClosure_mono : Monotone (starClosure (R := R) (A := A)) := fun _ _ h => starClosure_le <| h.trans le_sup_left end NonUnitalSubalgebra namespace NonUnitalStarAlgebra variable [CommSemiring R] [StarRing R] variable [NonUnitalSemiring A] [StarRing A] [Module R A] variable [NonUnitalSemiring B] [StarRing B] [Module R B] variable [FunLike F A B] [NonUnitalAlgHomClass F R A B] [StarHomClass F A B] section StarSubAlgebraA variable [IsScalarTower R A A] [SMulCommClass R A A] [StarModule R A] open scoped Pointwise open NonUnitalStarSubalgebra variable (R) /-- The minimal non-unital subalgebra that includes `s`. -/ def adjoin (s : Set A) : NonUnitalStarSubalgebra R A where toNonUnitalSubalgebra := NonUnitalAlgebra.adjoin R (s ∪ star s) star_mem' _ := by rwa [NonUnitalSubalgebra.mem_carrier, ← NonUnitalSubalgebra.mem_star_iff, NonUnitalSubalgebra.star_adjoin_comm, Set.union_star, star_star, Set.union_comm] theorem adjoin_eq_starClosure_adjoin (s : Set A) : adjoin R s = (NonUnitalAlgebra.adjoin R s).starClosure := toNonUnitalSubalgebra_injective <| show NonUnitalAlgebra.adjoin R (s ∪ star s) = NonUnitalAlgebra.adjoin R s ⊔ star (NonUnitalAlgebra.adjoin R s) from (NonUnitalSubalgebra.star_adjoin_comm R s).symm ▸ NonUnitalAlgebra.adjoin_union s (star s) theorem adjoin_toNonUnitalSubalgebra (s : Set A) : (adjoin R s).toNonUnitalSubalgebra = NonUnitalAlgebra.adjoin R (s ∪ star s) := rfl @[simp, aesop safe 20 (rule_sets := [SetLike])] theorem subset_adjoin (s : Set A) : s ⊆ adjoin R s := Set.subset_union_left.trans <| NonUnitalAlgebra.subset_adjoin R @[simp, aesop safe 20 (rule_sets := [SetLike])] theorem star_subset_adjoin (s : Set A) : star s ⊆ adjoin R s := Set.subset_union_right.trans <| NonUnitalAlgebra.subset_adjoin R @[aesop 80% (rule_sets := [SetLike])] theorem mem_adjoin_of_mem {s : Set A} {x : A} (hx : x ∈ s) : x ∈ adjoin R s := subset_adjoin R s hx theorem self_mem_adjoin_singleton (x : A) : x ∈ adjoin R ({x} : Set A) := NonUnitalAlgebra.subset_adjoin R <| Set.mem_union_left _ (Set.mem_singleton x) theorem star_self_mem_adjoin_singleton (x : A) : star x ∈ adjoin R ({x} : Set A) := star_mem <| self_mem_adjoin_singleton R x @[elab_as_elim] lemma adjoin_induction {s : Set A} {p : (x : A) → x ∈ adjoin R s → Prop} (mem : ∀ (x : A) (hx : x ∈ s), p x (subset_adjoin R s hx)) (add : ∀ x y hx hy, p x hx → p y hy → p (x + y) (add_mem hx hy)) (zero : p 0 (zero_mem _)) (mul : ∀ x y hx hy, p x hx → p y hy → p (x * y) (mul_mem hx hy)) (smul : ∀ (r : R) x hx, p x hx → p (r • x) (SMulMemClass.smul_mem r hx)) (star : ∀ x hx, p x hx → p (star x) (star_mem hx)) {a : A} (ha : a ∈ adjoin R s) : p a ha := by refine NonUnitalAlgebra.adjoin_induction (fun x hx ↦ ?_) add zero mul smul ha simp only [Set.mem_union, Set.mem_star] at hx obtain (hx | hx) := hx · exact mem x hx · simpa using star _ (NonUnitalAlgebra.subset_adjoin R (by simpa using Or.inl hx)) (mem _ hx) variable {R} protected theorem gc : GaloisConnection (adjoin R : Set A → NonUnitalStarSubalgebra R A) (↑) := by intro s S rw [← toNonUnitalSubalgebra_le_iff, adjoin_toNonUnitalSubalgebra, NonUnitalAlgebra.adjoin_le_iff, coe_toNonUnitalSubalgebra] exact ⟨fun h => Set.subset_union_left.trans h, fun h => Set.union_subset h fun x hx => star_star x ▸ star_mem (show star x ∈ S from h hx)⟩ /-- Galois insertion between `adjoin` and `SetLike.coe`. -/ protected def gi : GaloisInsertion (adjoin R : Set A → NonUnitalStarSubalgebra R A) (↑) where choice s hs := (adjoin R s).copy s <| le_antisymm (NonUnitalStarAlgebra.gc.le_u_l s) hs gc := NonUnitalStarAlgebra.gc le_l_u S := (NonUnitalStarAlgebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl choice_eq _ _ := NonUnitalStarSubalgebra.copy_eq _ _ _ theorem adjoin_le {S : NonUnitalStarSubalgebra R A} {s : Set A} (hs : s ⊆ S) : adjoin R s ≤ S := NonUnitalStarAlgebra.gc.l_le hs @[simp] theorem adjoin_le_iff {S : NonUnitalStarSubalgebra R A} {s : Set A} : adjoin R s ≤ S ↔ s ⊆ S := NonUnitalStarAlgebra.gc _ _ @[gcongr] theorem adjoin_mono {s t : Set A} (H : s ⊆ t) : adjoin R s ≤ adjoin R t := NonUnitalStarAlgebra.gc.monotone_l H @[simp] lemma adjoin_eq (s : NonUnitalStarSubalgebra R A) : adjoin R (s : Set A) = s := le_antisymm (adjoin_le le_rfl) (subset_adjoin R (s : Set A)) lemma adjoin_eq_span (s : Set A) : (adjoin R s).toSubmodule = Submodule.span R (Subsemigroup.closure (s ∪ star s)) := by rw [adjoin_toNonUnitalSubalgebra, NonUnitalAlgebra.adjoin_eq_span] @[simp] lemma span_eq_toSubmodule {R} [CommSemiring R] [Module R A] (s : NonUnitalStarSubalgebra R A) : Submodule.span R (s : Set A) = s.toSubmodule := by simp [SetLike.ext'_iff, Submodule.coe_span_eq_self] theorem _root_.NonUnitalSubalgebra.starClosure_eq_adjoin (S : NonUnitalSubalgebra R A) : S.starClosure = adjoin R (S : Set A) := le_antisymm (NonUnitalSubalgebra.starClosure_le_iff.2 <| subset_adjoin R (S : Set A)) (adjoin_le (le_sup_left : S ≤ S ⊔ star S)) instance : CompleteLattice (NonUnitalStarSubalgebra R A) := GaloisInsertion.liftCompleteLattice NonUnitalStarAlgebra.gi @[simp, norm_cast] theorem coe_top : ((⊤ : NonUnitalStarSubalgebra R A) : Set A) = Set.univ := rfl @[simp] theorem mem_top {x : A} : x ∈ (⊤ : NonUnitalStarSubalgebra R A) := Set.mem_univ x @[simp] theorem top_toNonUnitalSubalgebra : (⊤ : NonUnitalStarSubalgebra R A).toNonUnitalSubalgebra = ⊤ := by ext; simp @[simp] theorem toNonUnitalSubalgebra_eq_top {S : NonUnitalStarSubalgebra R A} : S.toNonUnitalSubalgebra = ⊤ ↔ S = ⊤ := NonUnitalStarSubalgebra.toNonUnitalSubalgebra_injective.eq_iff' top_toNonUnitalSubalgebra theorem mem_sup_left {S T : NonUnitalStarSubalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T := by rw [← SetLike.le_def] exact le_sup_left theorem mem_sup_right {S T : NonUnitalStarSubalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T := by rw [← SetLike.le_def] exact le_sup_right theorem mul_mem_sup {S T : NonUnitalStarSubalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T := mul_mem (mem_sup_left hx) (mem_sup_right hy) theorem map_sup [IsScalarTower R B B] [SMulCommClass R B B] [StarModule R B] (f : F) (S T : NonUnitalStarSubalgebra R A) : ((S ⊔ T).map f : NonUnitalStarSubalgebra R B) = S.map f ⊔ T.map f := (NonUnitalStarSubalgebra.gc_map_comap f).l_sup theorem map_inf [IsScalarTower R B B] [SMulCommClass R B B] [StarModule R B] (f : F) (hf : Function.Injective f) (S T : NonUnitalStarSubalgebra R A) : ((S ⊓ T).map f : NonUnitalStarSubalgebra R B) = S.map f ⊓ T.map f := SetLike.coe_injective (Set.image_inter hf) @[simp, norm_cast] theorem coe_inf (S T : NonUnitalStarSubalgebra R A) : (↑(S ⊓ T) : Set A) = (S : Set A) ∩ T := rfl @[simp] theorem mem_inf {S T : NonUnitalStarSubalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl @[simp] theorem inf_toNonUnitalSubalgebra (S T : NonUnitalStarSubalgebra R A) : (S ⊓ T).toNonUnitalSubalgebra = S.toNonUnitalSubalgebra ⊓ T.toNonUnitalSubalgebra := SetLike.coe_injective <| coe_inf _ _ -- it's a bit surprising `rfl` fails here. @[simp, norm_cast] theorem coe_sInf (S : Set (NonUnitalStarSubalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s := sInf_image theorem mem_sInf {S : Set (NonUnitalStarSubalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂] @[simp] theorem sInf_toNonUnitalSubalgebra (S : Set (NonUnitalStarSubalgebra R A)) : (sInf S).toNonUnitalSubalgebra = sInf (NonUnitalStarSubalgebra.toNonUnitalSubalgebra '' S) := SetLike.coe_injective <| by simp @[simp, norm_cast] theorem coe_iInf {ι : Sort*} {S : ι → NonUnitalStarSubalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by simp [iInf] theorem mem_iInf {ι : Sort*} {S : ι → NonUnitalStarSubalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by simp only [iInf, mem_sInf, Set.forall_mem_range] theorem map_iInf {ι : Sort*} [Nonempty ι] [IsScalarTower R B B] [SMulCommClass R B B] [StarModule R B] (f : F) (hf : Function.Injective f) (S : ι → NonUnitalStarSubalgebra R A) : ((⨅ i, S i).map f : NonUnitalStarSubalgebra R B) = ⨅ i, (S i).map f := by apply SetLike.coe_injective simpa using (Set.injOn_of_injective hf).image_iInter_eq (s := SetLike.coe ∘ S) @[simp] theorem iInf_toNonUnitalSubalgebra {ι : Sort*} (S : ι → NonUnitalStarSubalgebra R A) : (⨅ i, S i).toNonUnitalSubalgebra = ⨅ i, (S i).toNonUnitalSubalgebra := SetLike.coe_injective <| by simp instance : Inhabited (NonUnitalStarSubalgebra R A) := ⟨⊥⟩ theorem mem_bot {x : A} : x ∈ (⊥ : NonUnitalStarSubalgebra R A) ↔ x = 0 := show x ∈ NonUnitalAlgebra.adjoin R (∅ ∪ star ∅ : Set A) ↔ x = 0 by rw [Set.star_empty, Set.union_empty, NonUnitalAlgebra.adjoin_empty, NonUnitalAlgebra.mem_bot] theorem toNonUnitalSubalgebra_bot : (⊥ : NonUnitalStarSubalgebra R A).toNonUnitalSubalgebra = ⊥ := by ext x simp only [mem_bot, NonUnitalStarSubalgebra.mem_toNonUnitalSubalgebra, NonUnitalAlgebra.mem_bot] @[simp, norm_cast] theorem coe_bot : ((⊥ : NonUnitalStarSubalgebra R A) : Set A) = {0} := by simp only [Set.ext_iff, NonUnitalStarAlgebra.mem_bot, SetLike.mem_coe, Set.mem_singleton_iff, forall_const] theorem eq_top_iff {S : NonUnitalStarSubalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S := ⟨fun h x => by rw [h]; exact mem_top, fun h => by ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩ @[simp] theorem range_id : NonUnitalStarAlgHom.range (NonUnitalStarAlgHom.id R A) = ⊤ := SetLike.coe_injective Set.range_id @[simp] theorem map_bot [IsScalarTower R B B] [SMulCommClass R B B] [StarModule R B] (f : F) : (⊥ : NonUnitalStarSubalgebra R A).map f = ⊥ := SetLike.coe_injective <| by simp [NonUnitalStarSubalgebra.coe_map] @[simp] theorem comap_top [IsScalarTower R B B] [SMulCommClass R B B] [StarModule R B] (f : F) : (⊤ : NonUnitalStarSubalgebra R B).comap f = ⊤ := eq_top_iff.2 fun _x => mem_top /-- `NonUnitalStarAlgHom` to `⊤ : NonUnitalStarSubalgebra R A`. -/ def toTop : A →⋆ₙₐ[R] (⊤ : NonUnitalStarSubalgebra R A) := NonUnitalStarAlgHom.codRestrict (NonUnitalStarAlgHom.id R A) ⊤ fun _ => mem_top end StarSubAlgebraA theorem range_eq_top [IsScalarTower R B B] [SMulCommClass R B B] [StarModule R B] (f : F) : NonUnitalStarAlgHom.range f = (⊤ : NonUnitalStarSubalgebra R B) ↔ Function.Surjective f := NonUnitalStarAlgebra.eq_top_iff @[simp] theorem map_top [IsScalarTower R A A] [SMulCommClass R A A] [StarModule R A] (f : F) : (⊤ : NonUnitalStarSubalgebra R A).map f = NonUnitalStarAlgHom.range f := SetLike.coe_injective Set.image_univ end NonUnitalStarAlgebra namespace NonUnitalStarSubalgebra open NonUnitalStarAlgebra variable [CommSemiring R] variable [NonUnitalSemiring A] [StarRing A] [Module R A] variable [NonUnitalSemiring B] [StarRing B] [Module R B] variable [FunLike F A B] [NonUnitalAlgHomClass F R A B] [StarHomClass F A B] variable (S : NonUnitalStarSubalgebra R A) section StarSubalgebra variable [StarRing R] variable [IsScalarTower R A A] [SMulCommClass R A A] [StarModule R A] variable [IsScalarTower R B B] [SMulCommClass R B B] [StarModule R B] lemma _root_.NonUnitalStarAlgHom.map_adjoin (f : F) (s : Set A) : map f (adjoin R s) = adjoin R (f '' s) := Set.image_preimage.l_comm_of_u_comm (gc_map_comap f) NonUnitalStarAlgebra.gi.gc NonUnitalStarAlgebra.gi.gc fun _t => rfl @[simp] lemma _root_.NonUnitalStarAlgHom.map_adjoin_singleton (f : F) (x : A) : map f (adjoin R {x}) = adjoin R {f x} := by simp [NonUnitalStarAlgHom.map_adjoin] instance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (NonUnitalStarSubalgebra R A) := ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩ instance _root_.NonUnitalStarAlgHom.subsingleton [Subsingleton (NonUnitalStarSubalgebra R A)] : Subsingleton (A →⋆ₙₐ[R] B) := ⟨fun f g => NonUnitalStarAlgHom.ext fun a => have : a ∈ (⊥ : NonUnitalStarSubalgebra R A) := Subsingleton.elim (⊤ : NonUnitalStarSubalgebra R A) ⊥ ▸ mem_top (mem_bot.mp this).symm ▸ (map_zero f).trans (map_zero g).symm⟩ /-- The map `S → T` when `S` is a non-unital star subalgebra contained in the non-unital star algebra `T`. This is the non-unital star subalgebra version of `Submodule.inclusion`, or `NonUnitalSubalgebra.inclusion` -/ def inclusion {S T : NonUnitalStarSubalgebra R A} (h : S ≤ T) : S →⋆ₙₐ[R] T where toNonUnitalAlgHom := NonUnitalSubalgebra.inclusion h map_star' _ := rfl theorem inclusion_injective {S T : NonUnitalStarSubalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) := fun _ _ => Subtype.ext ∘ Subtype.mk.inj @[simp] theorem inclusion_self {S : NonUnitalStarSubalgebra R A} : inclusion (le_refl S) = NonUnitalAlgHom.id R S := NonUnitalAlgHom.ext fun _x => Subtype.ext rfl @[simp] theorem inclusion_mk {S T : NonUnitalStarSubalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) : inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ := rfl theorem inclusion_right {S T : NonUnitalStarSubalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) : inclusion h ⟨x, m⟩ = x := Subtype.ext rfl @[simp] theorem inclusion_inclusion {S T U : NonUnitalStarSubalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) : inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x := Subtype.ext rfl @[simp] theorem val_inclusion {S T : NonUnitalStarSubalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s := rfl end StarSubalgebra theorem range_val : NonUnitalStarAlgHom.range (NonUnitalStarSubalgebraClass.subtype S) = S := ext <| Set.ext_iff.1 <| (NonUnitalStarAlgHom.coe_range (NonUnitalStarSubalgebraClass.subtype S)).trans Subtype.range_val section Prod variable (S₁ : NonUnitalStarSubalgebra R B) /-- The product of two non-unital star subalgebras is a non-unital star subalgebra. -/ def prod : NonUnitalStarSubalgebra R (A × B) := { S.toNonUnitalSubalgebra.prod S₁.toNonUnitalSubalgebra with carrier := S ×ˢ S₁ star_mem' := fun hx => ⟨star_mem hx.1, star_mem hx.2⟩ } @[simp, norm_cast] theorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ S₁ := rfl theorem prod_toNonUnitalSubalgebra : (S.prod S₁).toNonUnitalSubalgebra = S.toNonUnitalSubalgebra.prod S₁.toNonUnitalSubalgebra := rfl @[simp] theorem mem_prod {S : NonUnitalStarSubalgebra R A} {S₁ : NonUnitalStarSubalgebra R B} {x : A × B} : x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod variable [StarRing R] variable [IsScalarTower R A A] [SMulCommClass R A A] [StarModule R A] variable [IsScalarTower R B B] [SMulCommClass R B B] [StarModule R B] @[simp] theorem prod_top : (prod ⊤ ⊤ : NonUnitalStarSubalgebra R (A × B)) = ⊤ := by ext; simp theorem prod_mono {S T : NonUnitalStarSubalgebra R A} {S₁ T₁ : NonUnitalStarSubalgebra R B} : S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ := Set.prod_mono @[simp] theorem prod_inf_prod {S T : NonUnitalStarSubalgebra R A} {S₁ T₁ : NonUnitalStarSubalgebra R B} : S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) := SetLike.coe_injective Set.prod_inter_prod end Prod section iSupLift variable {ι : Type*} variable [StarRing R] [IsScalarTower R A A] [SMulCommClass R A A] [StarModule R A] section StarSubalgebraB variable [IsScalarTower R B B] [SMulCommClass R B B] [StarModule R B] theorem coe_iSup_of_directed [Nonempty ι] {S : ι → NonUnitalStarSubalgebra R A} (dir : Directed (· ≤ ·) S) : ↑(iSup S) = ⋃ i, (S i : Set A) := let K : NonUnitalStarSubalgebra R A := { __ := NonUnitalSubalgebra.copy _ _ (NonUnitalSubalgebra.coe_iSup_of_directed dir).symm star_mem' := fun hx ↦ let ⟨i, hi⟩ := Set.mem_iUnion.1 hx Set.mem_iUnion.2 ⟨i, star_mem (s := S i) hi⟩ } have : iSup S = K := le_antisymm (iSup_le fun i ↦ le_iSup (fun i ↦ (S i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup S _) this.symm ▸ rfl /-- Define a non-unital star algebra homomorphism on a directed supremum of non-unital star subalgebras by defining it on each non-unital star subalgebra, and proving that it agrees on the intersection of non-unital star subalgebras. -/ noncomputable def iSupLift [Nonempty ι] (K : ι → NonUnitalStarSubalgebra R A) (dir : Directed (· ≤ ·) K) (f : ∀ i, K i →⋆ₙₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h)) (T : NonUnitalStarSubalgebra R A) (hT : T = iSup K) : ↥T →⋆ₙₐ[R] B := by subst hT exact { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x) (fun i j x hxi hxj => by let ⟨k, hik, hjk⟩ := dir i j simp only rw [hf i k hik, hf j k hjk] rfl) _ (by rw [coe_iSup_of_directed dir]) map_zero' := by dsimp only [SetLike.coe_sort_coe, NonUnitalAlgHom.coe_comp, Function.comp_apply, inclusion_mk, Eq.ndrec, id_eq, eq_mpr_eq_cast] exact Set.iUnionLift_const _ (fun i : ι => (0 : K i)) (fun _ => rfl) _ (by simp) map_mul' := by dsimp only [SetLike.coe_sort_coe, NonUnitalAlgHom.coe_comp, Function.comp_apply, inclusion_mk, Eq.ndrec, id_eq, eq_mpr_eq_cast, ZeroMemClass.coe_zero, AddSubmonoid.mk_add_mk, Set.inclusion_mk] apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·)) all_goals simp map_add' := by dsimp only [SetLike.coe_sort_coe, NonUnitalAlgHom.coe_comp, Function.comp_apply, inclusion_mk, Eq.ndrec, id_eq, eq_mpr_eq_cast] apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·)) all_goals simp map_smul' := fun r => by dsimp only [SetLike.coe_sort_coe, NonUnitalAlgHom.coe_comp, Function.comp_apply, inclusion_mk, Eq.ndrec, id_eq, eq_mpr_eq_cast] apply Set.iUnionLift_unary (coe_iSup_of_directed dir) _ (fun _ x => r • x) (fun _ _ => rfl) all_goals simp map_star' := by dsimp only [SetLike.coe_sort_coe, NonUnitalStarAlgHom.comp_apply, inclusion_mk, Eq.ndrec, id_eq, eq_mpr_eq_cast, ZeroMemClass.coe_zero, AddSubmonoid.mk_add_mk, Set.inclusion_mk, MulMemClass.mk_mul_mk, NonUnitalAlgHom.toDistribMulActionHom_eq_coe, DistribMulActionHom.toFun_eq_coe, NonUnitalAlgHom.coe_to_distribMulActionHom, NonUnitalAlgHom.coe_mk] apply Set.iUnionLift_unary (coe_iSup_of_directed dir) _ (fun _ x => star x) (fun _ _ => rfl) all_goals simp [map_star] } end StarSubalgebraB variable [Nonempty ι] {K : ι → NonUnitalStarSubalgebra R A} {dir : Directed (· ≤ ·) K} {f : ∀ i, K i →⋆ₙₐ[R] B} {hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h)} {T : NonUnitalStarSubalgebra R A} {hT : T = iSup K} @[simp] theorem iSupLift_inclusion {i : ι} (x : K i) (h : K i ≤ T) : iSupLift K dir f hf T hT (inclusion h x) = f i x := by subst T dsimp [iSupLift] apply Set.iUnionLift_inclusion exact h @[simp] theorem iSupLift_comp_inclusion {i : ι} (h : K i ≤ T) : (iSupLift K dir f hf T hT).comp (inclusion h) = f i := by ext; simp @[simp] theorem iSupLift_mk {i : ι} (x : K i) (hx : (x : A) ∈ T) : iSupLift K dir f hf T hT ⟨x, hx⟩ = f i x := by subst hT dsimp [iSupLift] apply Set.iUnionLift_mk theorem iSupLift_of_mem {i : ι} (x : T) (hx : (x : A) ∈ K i) : iSupLift K dir f hf T hT x = f i ⟨x, hx⟩ := by subst hT dsimp [iSupLift] apply Set.iUnionLift_of_mem end iSupLift section Center variable (R A) variable [IsScalarTower R A A] [SMulCommClass R A A] /-- The center of a non-unital star algebra is the set of elements which commute with every element. They form a non-unital star subalgebra. -/ def center : NonUnitalStarSubalgebra R A where toNonUnitalSubalgebra := NonUnitalSubalgebra.center R A star_mem' := Set.star_mem_center @[norm_cast] theorem coe_center : (center R A : Set A) = Set.center A := rfl @[simp] theorem center_toNonUnitalSubalgebra : (center R A).toNonUnitalSubalgebra = NonUnitalSubalgebra.center R A := rfl @[simp] theorem center_eq_top (A : Type*) [StarRing R] [NonUnitalCommSemiring A] [StarRing A] [Module R A] [IsScalarTower R A A] [SMulCommClass R A A] [StarModule R A] : center R A = ⊤ := SetLike.coe_injective (Set.center_eq_univ A) variable {R A} instance instNonUnitalCommSemiring : NonUnitalCommSemiring (center R A) := NonUnitalSubalgebra.center.instNonUnitalCommSemiring instance instNonUnitalCommRing {A : Type*} [NonUnitalRing A] [StarRing A] [Module R A] [IsScalarTower R A A] [SMulCommClass R A A] : NonUnitalCommRing (center R A) := NonUnitalSubalgebra.center.instNonUnitalCommRing theorem mem_center_iff {a : A} : a ∈ center R A ↔ ∀ b : A, b * a = a * b := Subsemigroup.mem_center_iff end Center section Centralizer variable (R) variable [IsScalarTower R A A] [SMulCommClass R A A] /-- The centralizer of the star-closure of a set as a non-unital star subalgebra. -/ def centralizer (s : Set A) : NonUnitalStarSubalgebra R A := { NonUnitalSubalgebra.centralizer R (s ∪ star s) with star_mem' := Set.star_mem_centralizer } @[simp, norm_cast] theorem coe_centralizer (s : Set A) : (centralizer R s : Set A) = (s ∪ star s).centralizer := rfl theorem mem_centralizer_iff {s : Set A} {z : A} : z ∈ centralizer R s ↔ ∀ g ∈ s, g * z = z * g ∧ star g * z = z * star g := by change (∀ g ∈ s ∪ star s, g * z = z * g) ↔ ∀ g ∈ s, g * z = z * g ∧ star g * z = z * star g simp only [Set.mem_union, or_imp, forall_and, and_congr_right_iff] exact fun _ => ⟨fun hz a ha => hz _ (Set.star_mem_star.mpr ha), fun hz a ha => star_star a ▸ hz _ ha⟩ theorem centralizer_le (s t : Set A) (h : s ⊆ t) : centralizer R t ≤ centralizer R s := Set.centralizer_subset (Set.union_subset_union h <| Set.preimage_mono h) @[simp] theorem centralizer_univ : centralizer R Set.univ = center R A := SetLike.ext' <| by rw [coe_centralizer, Set.univ_union, coe_center, Set.centralizer_univ] theorem centralizer_toNonUnitalSubalgebra (s : Set A) : (centralizer R s).toNonUnitalSubalgebra = NonUnitalSubalgebra.centralizer R (s ∪ star s) := rfl theorem coe_centralizer_centralizer (s : Set A) : (centralizer R (centralizer R s : Set A)) = (s ∪ star s).centralizer.centralizer := by rw [coe_centralizer, StarMemClass.star_coe_eq, Set.union_self, coe_centralizer] end Centralizer end NonUnitalStarSubalgebra namespace NonUnitalStarAlgebra open NonUnitalStarSubalgebra variable [CommSemiring R] [StarRing R] variable [NonUnitalSemiring A] [StarRing A] [Module R A] variable [IsScalarTower R A A] [SMulCommClass R A A] [StarModule R A] variable (R) in lemma adjoin_le_centralizer_centralizer (s : Set A) : adjoin R s ≤ centralizer R (centralizer R s) := by rw [← toNonUnitalSubalgebra_le_iff, centralizer_toNonUnitalSubalgebra, adjoin_toNonUnitalSubalgebra] convert NonUnitalAlgebra.adjoin_le_centralizer_centralizer R (s ∪ star s) rw [StarMemClass.star_coe_eq] simp lemma commute_of_mem_adjoin_of_forall_mem_commute {a b : A} {s : Set A} (hb : b ∈ adjoin R s) (h : ∀ b ∈ s, Commute a b) (h_star : ∀ b ∈ s, Commute a (star b)) : Commute a b := NonUnitalAlgebra.commute_of_mem_adjoin_of_forall_mem_commute hb fun b hb ↦ hb.elim (h b) (by simpa using h_star (star b)) lemma commute_of_mem_adjoin_singleton_of_commute {a b c : A} (hc : c ∈ adjoin R {b}) (h : Commute a b) (h_star : Commute a (star b)) : Commute a c := commute_of_mem_adjoin_of_forall_mem_commute hc (by simpa) (by simpa) lemma commute_of_mem_adjoin_self {a b : A} [IsStarNormal a] (hb : b ∈ adjoin R {a}) : Commute a b := commute_of_mem_adjoin_singleton_of_commute hb rfl (isStarNormal_iff a |>.mp inferInstance).symm variable (R) in /-- If all elements of `s : Set A` commute pairwise and with elements of `star s`, then `adjoin R s` is a non-unital commutative semiring. See note [reducible non-instances]. -/ abbrev adjoinNonUnitalCommSemiringOfComm {s : Set A} (hcomm : ∀ a ∈ s, ∀ b ∈ s, a * b = b * a) (hcomm_star : ∀ a ∈ s, ∀ b ∈ s, a * star b = star b * a) : NonUnitalCommSemiring (adjoin R s) := { (adjoin R s).toNonUnitalSemiring with mul_comm := fun ⟨_, h₁⟩ ⟨_, h₂⟩ ↦ by have hcomm : ∀ a ∈ s ∪ star s, ∀ b ∈ s ∪ star s, a * b = b * a := fun a ha b hb ↦ Set.union_star_self_comm (fun _ ha _ hb ↦ hcomm _ hb _ ha) (fun _ ha _ hb ↦ hcomm_star _ hb _ ha) b hb a ha have := adjoin_le_centralizer_centralizer R s apply this at h₁ apply this at h₂ rw [← SetLike.mem_coe, coe_centralizer_centralizer] at h₁ h₂ exact Subtype.ext <| Set.centralizer_centralizer_comm_of_comm hcomm _ h₁ _ h₂ } /-- If all elements of `s : Set A` commute pairwise and with elements of `star s`, then `adjoin R s` is a non-unital commutative ring. See note [reducible non-instances]. -/ abbrev adjoinNonUnitalCommRingOfComm (R : Type*) {A : Type*} [CommRing R] [StarRing R] [NonUnitalRing A] [StarRing A] [Module R A] [IsScalarTower R A A] [SMulCommClass R A A] [StarModule R A] {s : Set A} (hcomm : ∀ a ∈ s, ∀ b ∈ s, a * b = b * a) (hcomm_star : ∀ a ∈ s, ∀ b ∈ s, a * star b = star b * a) : NonUnitalCommRing (adjoin R s) := { (adjoin R s).toNonUnitalRing, adjoinNonUnitalCommSemiringOfComm R hcomm hcomm_star with } end NonUnitalStarAlgebra
.lake/packages/mathlib/Mathlib/Algebra/Star/CHSH.lean
import Mathlib.Tactic.LinearCombination import Mathlib.Algebra.CharP.Invertible import Mathlib.Algebra.Order.Star.Basic import Mathlib.Data.Real.Sqrt import Mathlib.Data.Real.Star /-! # The Clauser-Horne-Shimony-Holt inequality and Tsirelson's inequality. We establish a version of the Clauser-Horne-Shimony-Holt (CHSH) inequality (which is a generalization of Bell's inequality). This is a foundational result which implies that quantum mechanics is not a local hidden variable theory. As usually stated the CHSH inequality requires substantial language from physics and probability, but it is possible to give a statement that is purely about ordered `*`-algebras. We do that here, to avoid as many practical and logical dependencies as possible. Since the algebra of observables of any quantum system is an ordered `*`-algebra (in particular a von Neumann algebra) this is a strict generalization of the usual statement. Let `R` be a `*`-ring. A CHSH tuple in `R` consists of * four elements `A₀ A₁ B₀ B₁ : R`, such that * each `Aᵢ` and `Bⱼ` is a self-adjoint involution, and * the `Aᵢ` commute with the `Bⱼ`. The physical interpretation is that the four elements are observables (hence self-adjoint) that take values ±1 (hence involutions), and that the `Aᵢ` are spacelike separated from the `Bⱼ` (and hence commute). The CHSH inequality says that when `R` is an ordered `*`-ring (that is, a `*`-ring which is ordered, and for every `r : R`, `0 ≤ star r * r`), which is moreover *commutative*, we have `A₀ * B₀ + A₀ * B₁ + A₁ * B₀ - A₁ * B₁ ≤ 2` On the other hand, Tsirelson's inequality says that for any ordered `*`-ring we have `A₀ * B₀ + A₀ * B₁ + A₁ * B₀ - A₁ * B₁ ≤ 2√2` (A caveat: in the commutative case we need 2⁻¹ in the ring, and in the noncommutative case we need √2 and √2⁻¹. To keep things simple we just assume our rings are ℝ-algebras.) The proofs I've seen in the literature either assume a significant framework for quantum mechanics, or assume the ring is a `C^*`-algebra. In the `C^*`-algebra case, the order structure is completely determined by the `*`-algebra structure: `0 ≤ A` iff there exists some `B` so `A = star B * B`. There's a nice proof of both bounds in this setting at https://en.wikipedia.org/wiki/Tsirelson%27s_bound The proof given here is purely algebraic. ## Future work One can show that Tsirelson's inequality is tight. In the `*`-ring of n-by-n complex matrices, if `A ≤ λ I` for some `λ : ℝ`, then every eigenvalue has absolute value at most `λ`. There is a CHSH tuple in 4-by-4 matrices such that `A₀ * B₀ + A₀ * B₁ + A₁ * B₀ - A₁ * B₁` has `2√2` as an eigenvalue. ## References * [Clauser, Horne, Shimony, Holt, *Proposed experiment to test local hidden-variable theories*][zbMATH06785026] * [Bell, *On the Einstein Podolsky Rosen Paradox*][MR3790629] * [Tsirelson, *Quantum generalizations of Bell's inequality*][MR577178] -/ universe u /-- A CHSH tuple in a *-monoid consists of 4 self-adjoint involutions `A₀ A₁ B₀ B₁` such that the `Aᵢ` commute with the `Bⱼ`. The physical interpretation is that `A₀` and `A₁` are a pair of Boolean observables which are spacelike separated from another pair `B₀` and `B₁` of Boolean observables. -/ structure IsCHSHTuple {R} [Monoid R] [StarMul R] (A₀ A₁ B₀ B₁ : R) : Prop where A₀_inv : A₀ ^ 2 = 1 A₁_inv : A₁ ^ 2 = 1 B₀_inv : B₀ ^ 2 = 1 B₁_inv : B₁ ^ 2 = 1 A₀_sa : star A₀ = A₀ A₁_sa : star A₁ = A₁ B₀_sa : star B₀ = B₀ B₁_sa : star B₁ = B₁ A₀B₀_commutes : A₀ * B₀ = B₀ * A₀ A₀B₁_commutes : A₀ * B₁ = B₁ * A₀ A₁B₀_commutes : A₁ * B₀ = B₀ * A₁ A₁B₁_commutes : A₁ * B₁ = B₁ * A₁ variable {R : Type u} theorem CHSH_id [CommRing R] {A₀ A₁ B₀ B₁ : R} (A₀_inv : A₀ ^ 2 = 1) (A₁_inv : A₁ ^ 2 = 1) (B₀_inv : B₀ ^ 2 = 1) (B₁_inv : B₁ ^ 2 = 1) : (2 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁) * (2 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁) = 4 * (2 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁) := by grind /-- Given a CHSH tuple (A₀, A₁, B₀, B₁) in a *commutative* ordered `*`-algebra over ℝ, `A₀ * B₀ + A₀ * B₁ + A₁ * B₀ - A₁ * B₁ ≤ 2`. (We could work over ℤ[⅟2] if we wanted to!) -/ theorem CHSH_inequality_of_comm [CommRing R] [PartialOrder R] [StarRing R] [StarOrderedRing R] [Algebra ℝ R] [IsOrderedModule ℝ R] (A₀ A₁ B₀ B₁ : R) (T : IsCHSHTuple A₀ A₁ B₀ B₁) : A₀ * B₀ + A₀ * B₁ + A₁ * B₀ - A₁ * B₁ ≤ 2 := by let P := 2 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ have i₁ : 0 ≤ P := by have idem : P * P = 4 * P := CHSH_id T.A₀_inv T.A₁_inv T.B₀_inv T.B₁_inv have idem' : P = (1 / 4 : ℝ) • (P * P) := by have h : 4 * P = (4 : ℝ) • P := by simp [map_ofNat, Algebra.smul_def] rw [idem, h, ← mul_smul] simp have sa : star P = P := by dsimp [P] simp only [star_add, star_sub, star_mul, star_ofNat, T.A₀_sa, T.A₁_sa, T.B₀_sa, T.B₁_sa, mul_comm B₀, mul_comm B₁] simpa only [← idem', sa] using smul_nonneg (by simp : (0 : ℝ) ≤ 1 / 4) (star_mul_self_nonneg P) apply le_of_sub_nonneg simpa only [sub_add_eq_sub_sub, ← sub_add] using i₁ /-! We now prove some rather specialized lemmas in preparation for the Tsirelson inequality, which we hide in a namespace as they are unlikely to be useful elsewhere. -/ namespace TsirelsonInequality /-! Before proving Tsirelson's bound, we prepare some easy lemmas about √2. -/ theorem sqrt_two_inv_mul_self : (√2)⁻¹ * (√2)⁻¹ = (2⁻¹ : ℝ) := by rw [← mul_inv] simp end TsirelsonInequality open TsirelsonInequality /-- In a noncommutative ordered `*`-algebra over ℝ, Tsirelson's bound for a CHSH tuple (A₀, A₁, B₀, B₁) is `A₀ * B₀ + A₀ * B₁ + A₁ * B₀ - A₁ * B₁ ≤ 2^(3/2) • 1`. We prove this by providing an explicit sum-of-squares decomposition of the difference. (We could work over `ℤ[2^(1/2), 2^(-1/2)]` if we really wanted to!) -/ theorem tsirelson_inequality [Ring R] [PartialOrder R] [StarRing R] [StarOrderedRing R] [Algebra ℝ R] [IsOrderedModule ℝ R] [StarModule ℝ R] (A₀ A₁ B₀ B₁ : R) (T : IsCHSHTuple A₀ A₁ B₀ B₁) : A₀ * B₀ + A₀ * B₁ + A₁ * B₀ - A₁ * B₁ ≤ √2 ^ 3 • (1 : R) := by -- abel will create `ℤ` multiplication. We will `simp` them away to `ℝ` multiplication. have M : ∀ (m : ℤ) (a : ℝ) (x : R), m • a • x = ((m : ℝ) * a) • x := fun m a x => by rw [← Int.cast_smul_eq_zsmul ℝ, ← mul_smul] let P := (√2)⁻¹ • (A₁ + A₀) - B₀ let Q := (√2)⁻¹ • (A₁ - A₀) + B₁ have w : √2 ^ 3 • (1 : R) - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ = (√2)⁻¹ • (P ^ 2 + Q ^ 2) := by dsimp [P, Q] -- distribute out all the powers and products appearing on the RHS simp only [sq, sub_mul, mul_sub, add_mul, mul_add, smul_add, smul_sub] -- pull all coefficients out to the front, and combine `√2`s where possible simp only [Algebra.mul_smul_comm, Algebra.smul_mul_assoc, ← mul_smul, sqrt_two_inv_mul_self] -- replace Aᵢ * Aᵢ = 1 and Bᵢ * Bᵢ = 1 simp only [← sq, T.A₀_inv, T.A₁_inv, T.B₀_inv, T.B₁_inv] -- move Aᵢ to the left of Bᵢ simp only [← T.A₀B₀_commutes, ← T.A₀B₁_commutes, ← T.A₁B₀_commutes, ← T.A₁B₁_commutes] -- collect terms, simplify coefficients, and collect terms again: abel_nf -- all terms coincide, but the last one. Simplify all other terms simp only [M] simp only [neg_mul, mul_inv_cancel_of_invertible, add_assoc, add_comm, add_left_comm, one_smul, Int.cast_neg, neg_smul, Int.cast_ofNat, ← add_smul] have : √2 ^ 2 = 2 := by norm_num grind have pos : 0 ≤ (√2)⁻¹ • (P ^ 2 + Q ^ 2) := by have P_sa : star P = P := by simp only [P, star_smul, star_add, star_sub, star_id_of_comm, T.A₀_sa, T.A₁_sa, T.B₀_sa] have Q_sa : star Q = Q := by simp only [Q, star_smul, star_add, star_sub, star_id_of_comm, T.A₀_sa, T.A₁_sa, T.B₁_sa] have P2_nonneg : 0 ≤ P ^ 2 := by simpa only [P_sa, sq] using star_mul_self_nonneg P have Q2_nonneg : 0 ≤ Q ^ 2 := by simpa only [Q_sa, sq] using star_mul_self_nonneg Q positivity apply le_of_sub_nonneg simpa only [sub_add_eq_sub_sub, ← sub_add, w, Nat.cast_zero] using pos
.lake/packages/mathlib/Mathlib/Algebra/Star/LinearMap.lean
import Mathlib.Algebra.Algebra.Bilinear import Mathlib.Algebra.Star.SelfAdjoint import Mathlib.Algebra.Star.TensorProduct /-! # Intrinsic star operation on `E →ₗ[R] F` This file defines the star operation on linear maps: `(star f) x = star (f (star x))`. This corresponds to a map being star-preserving, i.e., a map is self-adjoint iff it is star-preserving. ## Implementation notes **Note** that in the case of when `E = F` for a finite-dimensional Hilbert space, this `star` is mathematically distinct from the global instance on `E →ₗ[𝕜] E` where `star := LinearMap.adjoint`. For that reason, the intrinsic star operation is scoped to `IntrinsicStar`. -/ namespace LinearMap variable {R E F : Type*} [Semiring R] [InvolutiveStar R] [AddCommMonoid E] [Module R E] [StarAddMonoid E] [StarModule R E] [AddCommMonoid F] [Module R F] [StarAddMonoid F] [StarModule R F] /-- The intrinsic star operation on linear maps `E →ₗ F` defined by `(star f) x = star (f (star x))`. -/ def intrinsicStar : Star (E →ₗ[R] F) where star f := { toFun x := star (f (star x)) map_add' _ _ := by simp map_smul' _ _ := by simp } scoped[IntrinsicStar] attribute [instance] LinearMap.intrinsicStar open scoped IntrinsicStar @[simp] theorem intrinsicStar_apply (f : E →ₗ[R] F) (x : E) : (star f) x = star (f (star x)) := rfl /-- The involutive intrinsic star structure on linear maps. -/ def intrinsicInvolutiveStar : InvolutiveStar (E →ₗ[R] F) where star_involutive x := by ext; simp scoped[IntrinsicStar] attribute [instance] LinearMap.intrinsicInvolutiveStar /-- The intrinsic star additive monoid structure on linear maps. -/ def intrinsicStarAddMonoid : StarAddMonoid (E →ₗ[R] F) where star_add x y := by ext; simp scoped[IntrinsicStar] attribute [instance] LinearMap.intrinsicStarAddMonoid /-- A linear map is self-adjoint (with respect to the intrinsic star) iff it is star-preserving. -/ theorem isSelfAdjoint_iff_map_star (f : E →ₗ[R] F) : IsSelfAdjoint f ↔ ∀ x, f (star x) = star (f x) := by simp_rw [IsSelfAdjoint, LinearMap.ext_iff, intrinsicStar_apply, star_eq_iff_star_eq, eq_comm] /-- A star-preserving linear map is self-adjoint (with respect to the intrinsic star). -/ @[simp] protected theorem _root_.StarHomClass.isSelfAdjoint {S : Type*} [FunLike S E F] [LinearMapClass S R E F] [StarHomClass S E F] {f : S} : IsSelfAdjoint (f : E →ₗ[R] F) := isSelfAdjoint_iff_map_star _ |>.mpr (map_star f) variable {G : Type*} [AddCommMonoid G] [Module R G] [StarAddMonoid G] [StarModule R G] theorem intrinsicStar_comp (f : E →ₗ[R] F) (g : G →ₗ[R] E) : star (f ∘ₗ g) = star f ∘ₗ star g := by ext; simp @[simp] theorem intrinsicStar_id : star (LinearMap.id (R := R) (M := E)) = LinearMap.id := by ext; simp @[simp] theorem intrinsicStar_zero : star (0 : E →ₗ[R] F) = 0 := by ext; simp section NonUnitalNonAssocSemiring variable {R' E : Type*} [CommSemiring R'] [StarRing R'] [NonUnitalNonAssocSemiring E] [StarRing E] [Module R E] [Module R' E] [StarModule R E] [StarModule R' E] [SMulCommClass R E E] [IsScalarTower R E E] theorem intrinsicStar_mulLeft (x : E) : star (mulLeft R x) = mulRight R (star x) := by ext; simp theorem intrinsicStar_mulRight (x : E) : star (mulRight R x) = mulLeft R (star x) := by rw [star_eq_iff_star_eq, intrinsicStar_mulLeft, star_star] theorem intrinsicStar_mul' [SMulCommClass R' E E] [IsScalarTower R' E E] : star (mul' R' E) = mul' R' E ∘ₗ TensorProduct.comm R' E E := TensorProduct.ext' fun _ _ ↦ by simp end NonUnitalNonAssocSemiring variable [SMulCommClass R R F] in lemma intrinsicStarModule : StarModule R (E →ₗ[R] F) where star_smul _ _ := by ext; simp scoped[IntrinsicStar] attribute [instance] LinearMap.intrinsicStarModule section TensorProduct variable {R E F G H : Type*} [CommSemiring R] [StarRing R] [AddCommMonoid E] [StarAddMonoid E] [Module R E] [StarModule R E] [AddCommMonoid F] [StarAddMonoid F] [Module R F] [StarModule R F] [AddCommMonoid G] [StarAddMonoid G] [Module R G] [StarModule R G] [AddCommMonoid H] [StarAddMonoid H] [Module R H] [StarModule R H] theorem _root_.TensorProduct.intrinsicStar_map (f : E →ₗ[R] F) (g : G →ₗ[R] H) : star (TensorProduct.map f g) = TensorProduct.map (star f) (star g) := TensorProduct.ext' fun _ _ ↦ by simp theorem intrinsicStar_lTensor (f : F →ₗ[R] G) : star (lTensor E f) = lTensor E (star f) := by simp [lTensor, TensorProduct.intrinsicStar_map] theorem intrinsicStar_rTensor (f : E →ₗ[R] F) : star (rTensor G f) = rTensor G (star f) := by simp [rTensor, TensorProduct.intrinsicStar_map] end TensorProduct end LinearMap
.lake/packages/mathlib/Mathlib/Algebra/Star/RingQuot.lean
import Mathlib.Algebra.RingQuot import Mathlib.Algebra.Star.Basic /-! # The *-ring structure on suitable quotients of a *-ring. -/ namespace RingQuot universe u variable {R : Type u} [Semiring R] (r : R → R → Prop) section StarRing variable [StarRing R] theorem Rel.star (hr : ∀ a b, r a b → r (star a) (star b)) ⦃a b : R⦄ (h : Rel r a b) : Rel r (star a) (star b) := by induction h with | of h => exact Rel.of (hr _ _ h) | add_left _ h => rw [star_add, star_add] exact Rel.add_left h | mul_left _ h => rw [star_mul, star_mul] exact Rel.mul_right h | mul_right _ h => rw [star_mul, star_mul] exact Rel.mul_left h private irreducible_def star' (hr : ∀ a b, r a b → r (star a) (star b)) : RingQuot r → RingQuot r | ⟨a⟩ => ⟨Quot.map (star : R → R) (Rel.star r hr) a⟩ theorem star'_quot (hr : ∀ a b, r a b → r (star a) (star b)) {a} : (star' r hr ⟨Quot.mk _ a⟩ : RingQuot r) = ⟨Quot.mk _ (star a)⟩ := star'_def _ _ _ /-- Transfer a star_ring instance through a quotient, if the quotient is invariant to `star` -/ def starRing {R : Type u} [Semiring R] [StarRing R] (r : R → R → Prop) (hr : ∀ a b, r a b → r (star a) (star b)) : StarRing (RingQuot r) where star := star' r hr star_involutive := by rintro ⟨⟨⟩⟩ simp [star'_quot] star_mul := by rintro ⟨⟨⟩⟩ ⟨⟨⟩⟩ simp [star'_quot, mul_quot, star_mul] star_add := by rintro ⟨⟨⟩⟩ ⟨⟨⟩⟩ simp [star'_quot, add_quot, star_add] end StarRing end RingQuot
.lake/packages/mathlib/Mathlib/Algebra/Star/CentroidHom.lean
import Mathlib.Algebra.Ring.CentroidHom import Mathlib.Algebra.Star.StarRingHom import Mathlib.Algebra.Star.Subsemiring import Mathlib.Algebra.Star.Basic /-! # Centroid homomorphisms on Star Rings When a (nonunital, non-associative) semiring is equipped with an involutive automorphism the center of the centroid becomes a star ring in a natural way and the natural mapping of the centre of the semiring into the centre of the centroid becomes a *-homomorphism. ## Tags centroid -/ variable {α : Type*} namespace CentroidHom section NonUnitalNonAssocStarSemiring variable [NonUnitalNonAssocSemiring α] [StarRing α] instance : Star (CentroidHom α) where star f := { toFun := fun a => star (f (star a)) map_zero' := by simp only [star_zero, map_zero] map_add' := fun a b => by simp only [star_add, map_add] map_mul_left' := fun a b => by simp only [star_mul, map_mul_right, star_star] map_mul_right' := fun a b => by simp only [star_mul, map_mul_left, star_star] } @[simp] lemma star_apply (f : CentroidHom α) (a : α) : (star f) a = star (f (star a)) := rfl instance instStarAddMonoid : StarAddMonoid (CentroidHom α) where star_involutive f := ext (fun _ => by rw [star_apply, star_apply, star_star, star_star]) star_add _ _ := ext fun _ => star_add _ _ instance : Star (Subsemiring.center (CentroidHom α)) where star f := ⟨star (f : CentroidHom α), Subsemiring.mem_center_iff.mpr (fun g => ext (fun a => calc g (star (f (star a))) = star (star g (f (star a))) := by rw [star_apply, star_star] _ = star ((star g * f) (star a)) := rfl _ = star ((f * star g) (star a)) := by rw [f.property.comm] _ = star (f (star g (star a))) := rfl _ = star (f (star (g a))) := by rw [star_apply, star_star]))⟩ instance instStarAddMonoidCenter : StarAddMonoid (Subsemiring.center (CentroidHom α)) where star_involutive f := SetCoe.ext (star_involutive f.val) star_add f g := SetCoe.ext (star_add f.val g.val) instance : StarRing (Subsemiring.center (CentroidHom α)) where __ := instStarAddMonoidCenter star_mul f g := by ext a calc star (f * g) a = star (g * f) a := by rw [CommMonoid.mul_comm f g] _ = star (g (f (star a))) := rfl _ = star (g (star (star (f (star a))))) := by simp only [star_star] _ = (star g * star f) a := rfl /-- The canonical *-homomorphism embedding the center of `CentroidHom α` into `CentroidHom α`. -/ def centerStarEmbedding : Subsemiring.center (CentroidHom α) →⋆ₙ+* CentroidHom α where toNonUnitalRingHom := (SubsemiringClass.subtype (Subsemiring.center (CentroidHom α))).toNonUnitalRingHom map_star' f := by simp only [RingHom.toMonoidHom_eq_coe, OneHom.toFun_eq_coe, MonoidHom.toOneHom_coe, MonoidHom.coe_coe, SubsemiringClass.coe_subtype] exact rfl theorem star_centerToCentroidCenter (z : NonUnitalStarSubsemiring.center α) : star (centerToCentroidCenter z) = (centerToCentroidCenter (star z : NonUnitalStarSubsemiring.center α)) := by ext a calc (star (centerToCentroidCenter z)) a = star (z * star a) := rfl _ = star (star a) * star z := by simp only [star_mul, star_star, StarMemClass.coe_star] _ = a * star z := by rw [star_star] _ = (star z) * a := by rw [(star z).property.comm] _ = (centerToCentroidCenter ((star z) : NonUnitalStarSubsemiring.center α)) a := rfl /-- The canonical *-homomorphism from the center of a non-unital, non-associative *-semiring into the center of its centroid. -/ def starCenterToCentroidCenter : NonUnitalStarSubsemiring.center α →⋆ₙ+* Subsemiring.center (CentroidHom α) where toNonUnitalRingHom := centerToCentroidCenter map_star' _ := by simp only [MulHom.toFun_eq_coe, NonUnitalRingHom.coe_toMulHom] exact (star_centerToCentroidCenter _).symm /-- The canonical homomorphism from the center into the centroid -/ def starCenterToCentroid : NonUnitalStarSubsemiring.center α →⋆ₙ+* CentroidHom α := NonUnitalStarRingHom.comp (centerStarEmbedding) (starCenterToCentroidCenter) lemma starCenterToCentroid_apply (z : NonUnitalStarSubsemiring.center α) (a : α) : (starCenterToCentroid z) a = z * a := rfl /-- Let `α` be a star ring with commutative centroid. Then the centroid is a star ring. -/ @[reducible] def starRingOfCommCentroidHom (mul_comm : Std.Commutative (α := CentroidHom α) (· * ·)) : StarRing (CentroidHom α) where __ := instStarAddMonoid star_mul _ _ := ext (fun _ => by rw [mul_comm.comm, star_apply, mul_apply, mul_apply, star_apply, star_apply, star_star]) end NonUnitalNonAssocStarSemiring section NonAssocStarSemiring variable [NonAssocSemiring α] [StarRing α] /-- The canonical isomorphism from the center of a (non-associative) semiring onto its centroid. -/ def starCenterIsoCentroid : StarSubsemiring.center α ≃⋆+* CentroidHom α where __ := starCenterToCentroid invFun T := ⟨T 1, by constructor <;> simp [commute_iff_eq, ← map_mul_left, ← map_mul_right]⟩ left_inv z := Subtype.ext <| by simp only [MulHom.toFun_eq_coe, NonUnitalRingHom.coe_toMulHom, NonUnitalStarRingHom.coe_toNonUnitalRingHom, starCenterToCentroid_apply, mul_one] right_inv T := CentroidHom.ext <| fun _ => by simp [starCenterToCentroid_apply, ← map_mul_right] @[simp] lemma starCenterIsoCentroid_apply (a : ↥(NonUnitalStarSubsemiring.center α)) : CentroidHom.starCenterIsoCentroid a = CentroidHom.starCenterToCentroid a := rfl @[simp] lemma starCenterIsoCentroid_symm_apply_coe (T : CentroidHom α) : ↑(CentroidHom.starCenterIsoCentroid.symm T) = T 1 := rfl end NonAssocStarSemiring end CentroidHom
.lake/packages/mathlib/Mathlib/Algebra/Star/Unitary.lean
import Mathlib.Algebra.Group.Submonoid.Operations import Mathlib.Algebra.Star.SelfAdjoint import Mathlib.Algebra.Algebra.Spectrum.Basic import Mathlib.Tactic.ContinuousFunctionalCalculus import Mathlib.Algebra.Star.MonoidHom import Mathlib.Algebra.Star.StarProjection /-! # Unitary elements of a star monoid This file defines `unitary R`, where `R` is a star monoid, as the submonoid made of the elements that satisfy `star U * U = 1` and `U * star U = 1`, and these form a group. This includes, for instance, unitary operators on Hilbert spaces. See also `Matrix.UnitaryGroup` for specializations to `unitary (Matrix n n R)`. ## Tags unitary -/ /-- In a *-monoid, `unitary R` is the submonoid consisting of all the elements `U` of `R` such that `star U * U = 1` and `U * star U = 1`. -/ def unitary (R : Type*) [Monoid R] [StarMul R] : Submonoid R where carrier := { U | star U * U = 1 ∧ U * star U = 1 } one_mem' := by simp only [mul_one, and_self_iff, Set.mem_setOf_eq, star_one] mul_mem' := @fun U B ⟨hA₁, hA₂⟩ ⟨hB₁, hB₂⟩ => by refine ⟨?_, ?_⟩ · calc star (U * B) * (U * B) = star B * star U * U * B := by simp only [mul_assoc, star_mul] _ = star B * (star U * U) * B := by rw [← mul_assoc] _ = 1 := by rw [hA₁, mul_one, hB₁] · calc U * B * star (U * B) = U * B * (star B * star U) := by rw [star_mul] _ = U * (B * star B) * star U := by simp_rw [← mul_assoc] _ = 1 := by rw [hB₂, mul_one, hA₂] variable {R : Type*} namespace Unitary section Monoid variable [Monoid R] [StarMul R] theorem mem_iff {U : R} : U ∈ unitary R ↔ star U * U = 1 ∧ U * star U = 1 := Iff.rfl @[simp] theorem star_mul_self_of_mem {U : R} (hU : U ∈ unitary R) : star U * U = 1 := hU.1 @[simp] theorem mul_star_self_of_mem {U : R} (hU : U ∈ unitary R) : U * star U = 1 := hU.2 theorem star_mem {U : R} (hU : U ∈ unitary R) : star U ∈ unitary R := ⟨by rw [star_star, mul_star_self_of_mem hU], by rw [star_star, star_mul_self_of_mem hU]⟩ @[simp] theorem star_mem_iff {U : R} : star U ∈ unitary R ↔ U ∈ unitary R := ⟨fun h => star_star U ▸ star_mem h, star_mem⟩ instance : Star (unitary R) := ⟨fun U => ⟨star U, star_mem U.prop⟩⟩ @[simp, norm_cast] theorem coe_star {U : unitary R} : ↑(star U) = (star U : R) := rfl theorem coe_star_mul_self (U : unitary R) : (star U : R) * U = 1 := star_mul_self_of_mem U.prop theorem coe_mul_star_self (U : unitary R) : (U : R) * star U = 1 := mul_star_self_of_mem U.prop @[simp] theorem star_mul_self (U : unitary R) : star U * U = 1 := Subtype.ext <| coe_star_mul_self U @[simp] theorem mul_star_self (U : unitary R) : U * star U = 1 := Subtype.ext <| coe_mul_star_self U instance : Group (unitary R) := { Submonoid.toMonoid _ with inv := star inv_mul_cancel := star_mul_self } instance : InvolutiveStar (unitary R) := ⟨by intro x ext rw [coe_star, coe_star, star_star]⟩ instance : StarMul (unitary R) := ⟨by intro x y ext rw [coe_star, Submonoid.coe_mul, Submonoid.coe_mul, coe_star, coe_star, star_mul]⟩ instance : Inhabited (unitary R) := ⟨1⟩ theorem star_eq_inv (U : unitary R) : star U = U⁻¹ := rfl theorem star_eq_inv' : (star : unitary R → unitary R) = Inv.inv := rfl /-- The unitary elements embed into the units. -/ @[simps] def toUnits : unitary R →* Rˣ where toFun x := ⟨x, ↑x⁻¹, coe_mul_star_self x, coe_star_mul_self x⟩ map_one' := Units.ext rfl map_mul' _ _ := Units.ext rfl theorem toUnits_injective : Function.Injective (toUnits : unitary R → Rˣ) := fun _ _ h => Subtype.ext <| Units.ext_iff.mp h theorem _root_.IsUnit.mem_unitary_iff_star_mul_self {u : R} (hu : IsUnit u) : u ∈ unitary R ↔ star u * u = 1 := by rw [mem_iff, and_iff_left_of_imp fun h_mul => ?_] lift u to Rˣ using hu exact left_inv_eq_right_inv h_mul u.mul_inv ▸ u.mul_inv theorem _root_.IsUnit.mem_unitary_iff_mul_star_self {u : R} (hu : IsUnit u) : u ∈ unitary R ↔ u * star u = 1 := by rw [← star_mem_iff, hu.star.mem_unitary_iff_star_mul_self, star_star] alias ⟨_, _root_.IsUnit.mem_unitary_of_star_mul_self⟩ := IsUnit.mem_unitary_iff_star_mul_self alias ⟨_, _root_.IsUnit.mem_unitary_of_mul_star_self⟩ := IsUnit.mem_unitary_iff_mul_star_self theorem isUnit_coe {U : unitary R} : IsUnit (U : R) := (Unitary.toUnits _).isUnit /-- For unitary `U` in a star-monoid `R`, `x * U = y * U` if and only if `x = y` for all `x` and `y` in `R`. -/ protected theorem mul_left_inj {x y : R} (U : unitary R) : x * U = y * U ↔ x = y := val_toUnits_apply U ▸ Units.mul_left_inj _ /-- For unitary `U` in a star-monoid `R`, `U * x = U * y` if and only if `x = y` for all `x` and `y` in `R`. -/ protected theorem mul_right_inj {x y : R} (U : unitary R) : U * x = U * y ↔ x = y := val_toUnits_apply U ▸ Units.mul_right_inj _ lemma mul_inv_mem_iff {G : Type*} [Group G] [StarMul G] (a b : G) : a * b⁻¹ ∈ unitary G ↔ star a * a = star b * b := by rw [(Group.isUnit _).mem_unitary_iff_star_mul_self, star_mul, star_inv, mul_assoc, inv_mul_eq_iff_eq_mul, mul_one, ← mul_assoc, mul_inv_eq_iff_eq_mul] lemma inv_mul_mem_iff {G : Type*} [Group G] [StarMul G] (a b : G) : a⁻¹ * b ∈ unitary G ↔ a * star a = b * star b := by simpa [← mul_inv_rev] using mul_inv_mem_iff a⁻¹ b⁻¹ theorem _root_.Units.unitary_eq : unitary Rˣ = (unitary R).comap (Units.coeHom R) := by ext simp [mem_iff, Units.ext_iff] /-- In a star monoid, the product `a * b⁻¹` of units is unitary if `star a * a = star b * b`. -/ protected lemma _root_.Units.mul_inv_mem_unitary (a b : Rˣ) : (a * b⁻¹ : R) ∈ unitary R ↔ star a * a = star b * b := by simp [← mul_inv_mem_iff, Units.unitary_eq] /-- In a star monoid, the product `a⁻¹ * b` of units is unitary if `a * star a = b * star b`. -/ protected lemma _root_.Units.inv_mul_mem_unitary (a b : Rˣ) : (a⁻¹ * b : R) ∈ unitary R ↔ a * star a = b * star b := by simp [← inv_mul_mem_iff, Units.unitary_eq] instance instIsStarNormal (u : unitary R) : IsStarNormal u where star_comm_self := star_mul_self u |>.trans <| (mul_star_self u).symm instance coe_isStarNormal (u : unitary R) : IsStarNormal (u : R) where star_comm_self := congr(Subtype.val $(star_comm_self' u)) @[aesop 10% apply (rule_sets := [CStarAlgebra])] lemma _root_.isStarNormal_of_mem_unitary {u : R} (hu : u ∈ unitary R) : IsStarNormal u := coe_isStarNormal ⟨u, hu⟩ end Monoid end Unitary section Group variable {G : Type*} [Group G] [StarMul G] theorem Unitary.inv_mem {g : G} (hg : g ∈ unitary G) : g⁻¹ ∈ unitary G := by simp_rw [mem_iff, star_inv, ← mul_inv_rev, inv_eq_one] at * exact hg.symm variable (G) in /-- `unitary` as a `Subgroup` of a group. Note the group structure on this type is not defeq to the one on `unitary`. This situation naturally arises when considering the unitary elements as a subgroup of the group of units of a star monoid. -/ def unitarySubgroup : Subgroup G where toSubmonoid := unitary G inv_mem' := Unitary.inv_mem @[simp] theorem unitarySubgroup_toSubmonoid : (unitarySubgroup G).toSubmonoid = unitary G := rfl @[simp] theorem mem_unitarySubgroup_iff {g : G} : g ∈ unitarySubgroup G ↔ g ∈ unitary G := Iff.rfl nonrec theorem Unitary.inv_mem_iff {g : G} : g⁻¹ ∈ unitary G ↔ g ∈ unitary G := inv_mem_iff (H := unitarySubgroup G) end Group namespace Unitary section SMul section variable {A : Type*} [Monoid R] [Monoid A] [MulAction R A] [SMulCommClass R A A] [IsScalarTower R A A] [StarMul R] [StarMul A] [StarModule R A] lemma smul_mem_of_mem {r : R} {a : A} (hr : r ∈ unitary R) (ha : a ∈ unitary A) : r • a ∈ unitary A := by simp [mem_iff, smul_smul, mul_smul_comm, smul_mul_assoc, hr, ha] lemma smul_mem (r : unitary R) {a : A} (ha : a ∈ unitary A) : r • a ∈ unitary A := smul_mem_of_mem (R := R) r.prop ha instance : SMul (unitary R) (unitary A) where smul r a := ⟨r • a, smul_mem r a.prop⟩ @[simp, norm_cast] lemma coe_smul (r : unitary R) (a : unitary A) : ↑(r • a) = r • (a : A) := rfl instance : MulAction (unitary R) (unitary A) where one_smul _ := Subtype.ext <| one_smul .. mul_smul _ _ _ := Subtype.ext <| mul_smul .. instance : StarModule (unitary R) (unitary A) where star_smul _ _ := Subtype.ext <| star_smul (_ : R) _ end section variable {S A : Type*} [Monoid R] [Monoid S] [Monoid A] [StarMul R] [StarMul S] [StarMul A] [MulAction R S] [MulAction R A] [MulAction S A] [StarModule R S] [StarModule R A] [StarModule S A] [IsScalarTower R A A] [IsScalarTower S A A] [SMulCommClass R A A] [SMulCommClass S A A] instance [SMulCommClass R S A] : SMulCommClass (unitary R) (unitary S) (unitary A) where smul_comm _ _ _ := Subtype.ext <| smul_comm _ (_ : S) (_ : A) instance [IsScalarTower R S S] [SMulCommClass R S S] [IsScalarTower R S A] : IsScalarTower (unitary R) (unitary S) (unitary A) where smul_assoc _ _ _ := Subtype.ext <| smul_assoc _ (_ : S) (_ : A) end end SMul section Map variable {R S T : Type*} [Monoid R] [StarMul R] [Monoid S] [StarMul S] [Monoid T] [StarMul T] lemma map_mem {F : Type*} [FunLike F R S] [StarHomClass F R S] [MonoidHomClass F R S] (f : F) {r : R} (hr : r ∈ unitary R) : f r ∈ unitary S := by rw [mem_iff] at hr simpa [map_star, map_mul] using And.intro congr(f $(hr.1)) congr(f $(hr.2)) /-- The star monoid homomorphism between unitary subgroups induced by a star monoid homomorphism of the underlying star monoids. -/ @[simps] def map (f : R →⋆* S) : unitary R →⋆* unitary S where toFun := Subtype.map f (fun _ ↦ map_mem f) map_one' := Subtype.ext <| map_one f map_mul' _ _ := Subtype.ext <| map_mul f _ _ map_star' _ := Subtype.ext <| map_star f _ @[simp] lemma coe_map (f : R →⋆* S) (x : unitary R) : map f x = f x := rfl @[simp] lemma coe_map_star (f : R →⋆* S) (x : unitary R) : map f (star x) = f (star x) := rfl @[simp] lemma map_id : map (.id R) = .id (unitary R) := rfl lemma map_comp (g : S →⋆* T) (f : R →⋆* S) : map (g.comp f) = (map g).comp (map f) := rfl @[simp] lemma map_injective {f : R →⋆* S} (hf : Function.Injective f) : Function.Injective (map f : unitary R → unitary S) := Subtype.map_injective (fun _ ↦ map_mem f) hf lemma toUnits_comp_map (f : R →⋆* S) : toUnits.comp (map f).toMonoidHom = (Units.map f.toMonoidHom).comp toUnits := by ext; rfl /-- The star monoid isomorphism between unitary subgroups induced by a star monoid isomorphism of the underlying star monoids. -/ @[simps] def mapEquiv (f : R ≃⋆* S) : unitary R ≃⋆* unitary S := { map f.toStarMonoidHom with toFun := map f.toStarMonoidHom invFun := map f.symm.toStarMonoidHom left_inv := fun _ ↦ Subtype.ext <| f.left_inv _ right_inv := fun _ ↦ Subtype.ext <| f.right_inv _ } @[simp] lemma mapEquiv_refl : mapEquiv (.refl R) = .refl (unitary R) := rfl @[simp] lemma mapEquiv_symm (f : R ≃⋆* S) : mapEquiv f.symm = (mapEquiv f).symm := rfl @[simp] lemma mapEquiv_trans (f : R ≃⋆* S) (g : S ≃⋆* T) : mapEquiv (f.trans g) = (mapEquiv f).trans (mapEquiv g) := rfl @[simp] lemma toMonoidHom_mapEquiv (f : R ≃⋆* S) : (mapEquiv f).toStarMonoidHom = map f.toStarMonoidHom := rfl /-- The unitary subgroup of the units is equivalent to the unitary elements of the monoid. -/ @[simps!] def _root_.unitarySubgroupUnitsEquiv {M : Type*} [Monoid M] [StarMul M] : unitarySubgroup Mˣ ≃* unitary M where toFun x := ⟨x.val, congr_arg Units.val x.prop.1, congr_arg Units.val x.prop.2⟩ invFun x := ⟨⟨x, star x, x.prop.2, x.prop.1⟩, Units.ext x.prop.1, Units.ext x.prop.2⟩ map_mul' _ _ := rfl left_inv _ := Subtype.ext <| Units.ext rfl right_inv _ := rfl end Map section CommMonoid variable [CommMonoid R] [StarMul R] instance : CommGroup (unitary R) := { inferInstanceAs (Group (unitary R)), Submonoid.toCommMonoid _ with } theorem mem_iff_star_mul_self {U : R} : U ∈ unitary R ↔ star U * U = 1 := mem_iff.trans <| and_iff_left_of_imp fun h => mul_comm (star U) U ▸ h theorem mem_iff_self_mul_star {U : R} : U ∈ unitary R ↔ U * star U = 1 := mem_iff.trans <| and_iff_right_of_imp fun h => mul_comm U (star U) ▸ h end CommMonoid section GroupWithZero variable [GroupWithZero R] [StarMul R] @[norm_cast] theorem coe_inv (U : unitary R) : ↑U⁻¹ = (U⁻¹ : R) := eq_inv_of_mul_eq_one_right <| coe_mul_star_self _ @[norm_cast] theorem coe_div (U₁ U₂ : unitary R) : ↑(U₁ / U₂) = (U₁ / U₂ : R) := by simp only [div_eq_mul_inv, coe_inv, Submonoid.coe_mul] @[norm_cast] theorem coe_zpow (U : unitary R) (z : ℤ) : ↑(U ^ z) = (U : R) ^ z := by cases z · simp [SubmonoidClass.coe_pow] · simp [coe_inv] end GroupWithZero section Ring variable [Ring R] [StarRing R] instance : Neg (unitary R) where neg U := ⟨-U, by simp [mem_iff, star_neg]⟩ @[norm_cast] theorem coe_neg (U : unitary R) : ↑(-U) = (-U : R) := rfl instance : HasDistribNeg (unitary R) := Subtype.coe_injective.hasDistribNeg _ coe_neg (unitary R).coe_mul end Ring section UnitaryConjugate universe u variable {R A : Type*} [CommSemiring R] [Ring A] [Algebra R A] [StarMul A] /-- Unitary conjugation preserves the spectrum, star on right. -/ @[simp] lemma spectrum_star_right_conjugate {a : A} {U : unitary A} : spectrum R (U * a * (star U : A)) = spectrum R a := spectrum.units_conjugate (u := toUnits U) /-- Unitary conjugation preserves the spectrum, star on left. -/ @[simp] lemma spectrum_star_left_conjugate {a : A} {U : unitary A} : spectrum R ((star U : A) * a * U) = spectrum R a := by simpa using spectrum_star_right_conjugate (U := star U) end UnitaryConjugate end Unitary theorem IsStarProjection.two_mul_sub_one_mem_unitary {R : Type*} [Ring R] [StarRing R] {p : R} (hp : IsStarProjection p) : 2 * p - 1 ∈ unitary R := by simp only [two_mul, Unitary.mem_iff, star_sub, star_add, hp.isSelfAdjoint.star_eq, star_one, mul_sub, mul_add, sub_mul, add_mul, hp.isIdempotentElem.eq, one_mul, add_sub_cancel_right, mul_one, sub_sub_cancel, and_self] namespace unitary /-! ### Deprecated results -/ @[deprecated (since := "2025-10-29")] alias mem_iff := Unitary.mem_iff @[deprecated (since := "2025-10-29")] alias star_mul_self_of_mem := Unitary.star_mul_self_of_mem @[deprecated (since := "2025-10-29")] alias mul_star_self_of_mem := Unitary.mul_star_self_of_mem @[deprecated (since := "2025-10-29")] alias star_mem := Unitary.star_mem @[deprecated (since := "2025-10-29")] alias star_mem_iff := Unitary.star_mem_iff @[deprecated (since := "2025-10-29")] alias coe_star := Unitary.coe_star @[deprecated (since := "2025-10-29")] alias coe_star_mul_self := Unitary.coe_star_mul_self @[deprecated (since := "2025-10-29")] alias coe_mul_star_self := Unitary.coe_mul_star_self @[deprecated (since := "2025-10-29")] alias star_mul_self := Unitary.star_mul_self @[deprecated (since := "2025-10-29")] alias mul_star_self := Unitary.mul_star_self @[deprecated (since := "2025-10-29")] alias star_eq_inv := Unitary.star_eq_inv @[deprecated (since := "2025-10-29")] alias star_eq_inv' := Unitary.star_eq_inv' @[deprecated (since := "2025-10-29")] alias toUnits := Unitary.toUnits @[deprecated (since := "2025-10-29")] alias val_toUnits_apply := Unitary.val_toUnits_apply @[deprecated (since := "2025-10-29")] alias toUnits_injective := Unitary.toUnits_injective @[deprecated (since := "2025-10-29")] alias mul_left_inj := Unitary.mul_left_inj @[deprecated (since := "2025-10-29")] alias mul_right_inj := Unitary.mul_right_inj @[deprecated (since := "2025-10-29")] alias mul_inv_mem_iff := Unitary.mul_inv_mem_iff @[deprecated (since := "2025-10-29")] alias inv_mul_mem_iff := Unitary.inv_mul_mem_iff @[deprecated (since := "2025-10-29")] alias inv_mem := Unitary.inv_mem @[deprecated (since := "2025-10-29")] alias smul_mem_of_mem := Unitary.smul_mem_of_mem @[deprecated (since := "2025-10-29")] alias smul_mem := Unitary.smul_mem @[deprecated (since := "2025-10-29")] alias coe_smul := Unitary.coe_smul @[deprecated (since := "2025-10-29")] alias map_mem := Unitary.map_mem @[deprecated (since := "2025-10-29")] alias map := Unitary.map @[deprecated (since := "2025-10-29")] alias coe_map := Unitary.coe_map @[deprecated (since := "2025-10-29")] alias coe_map_star := Unitary.coe_map_star @[deprecated (since := "2025-10-29")] alias map_id := Unitary.map_id @[deprecated (since := "2025-10-29")] alias map_comp := Unitary.map_comp @[deprecated (since := "2025-10-29")] alias map_injective := Unitary.map_injective @[deprecated (since := "2025-10-29")] alias toUnits_comp_map := Unitary.toUnits_comp_map @[deprecated (since := "2025-10-29")] alias mapEquiv := Unitary.mapEquiv @[deprecated (since := "2025-10-29")] alias mapEquiv_refl := Unitary.mapEquiv_refl @[deprecated (since := "2025-10-29")] alias mapEquiv_symm := Unitary.mapEquiv_symm @[deprecated (since := "2025-10-29")] alias mapEquiv_trans := Unitary.mapEquiv_trans @[deprecated (since := "2025-10-29")] alias toMonoidHom_mapEquiv := Unitary.toMonoidHom_mapEquiv @[deprecated (since := "2025-10-29")] alias mem_iff_star_mul_self := Unitary.mem_iff_star_mul_self @[deprecated (since := "2025-10-29")] alias mem_iff_self_mul_star := Unitary.mem_iff_self_mul_star @[deprecated (since := "2025-10-29")] alias coe_inv := Unitary.coe_inv @[deprecated (since := "2025-10-29")] alias coe_div := Unitary.coe_div @[deprecated (since := "2025-10-29")] alias coe_zpow := Unitary.coe_zpow @[deprecated (since := "2025-10-29")] alias coe_neg := Unitary.coe_neg @[deprecated (since := "2025-10-20")] alias spectrum.unitary_conjugate := Unitary.spectrum_star_right_conjugate @[deprecated (since := "2025-10-20")] alias spectrum.unitary_conjugate' := Unitary.spectrum_star_left_conjugate end unitary
.lake/packages/mathlib/Mathlib/Algebra/Star/StarProjection.lean
import Mathlib.Algebra.Star.SelfAdjoint import Mathlib.Algebra.Group.Idempotent import Mathlib.Algebra.Ring.Idempotent /-! # Star projections This file defines star projections, which are self-adjoint idempotents. In star-ordered rings, star projections are non-negative. (See `IsStarProjection.nonneg` in `Mathlib/Algebra/Order/Star/Basic.lean`.) -/ variable {R : Type*} /-- A star projection is a self-adjoint idempotent. -/ @[mk_iff] structure IsStarProjection [Mul R] [Star R] (p : R) : Prop where protected isIdempotentElem : IsIdempotentElem p protected isSelfAdjoint : IsSelfAdjoint p namespace IsStarProjection variable {p q : R} lemma _root_.isStarProjection_iff' [Mul R] [Star R] : IsStarProjection p ↔ p * p = p ∧ star p = p := isStarProjection_iff _ theorem isStarNormal [Mul R] [Star R] (hp : IsStarProjection p) : IsStarNormal p := hp.isSelfAdjoint.isStarNormal variable (R) in @[simp] protected theorem zero [NonUnitalNonAssocSemiring R] [StarAddMonoid R] : IsStarProjection (0 : R) := ⟨.zero, .zero _⟩ variable (R) in @[simp] protected theorem one [MulOneClass R] [StarMul R] : IsStarProjection (1 : R) := ⟨.one, .one _⟩ theorem pow_eq [Monoid R] [Star R] (hp : IsStarProjection p) {n : ℕ} (hn : n ≠ 0) : p ^ n = p := hp.isIdempotentElem.pow_eq hn theorem pow_succ_eq [Monoid R] [Star R] (hp : IsStarProjection p) (n : ℕ) : p ^ (n + 1) = p := hp.isIdempotentElem.pow_succ_eq n section NonAssocRing variable [NonAssocRing R] theorem one_sub [StarRing R] (hp : IsStarProjection p) : IsStarProjection (1 - p) where isIdempotentElem := hp.isIdempotentElem.one_sub isSelfAdjoint := .sub (.one _) hp.isSelfAdjoint theorem _root_.isStarProjection_one_sub_iff [StarRing R] : IsStarProjection (1 - p) ↔ IsStarProjection p := ⟨fun h ↦ sub_sub_cancel 1 p ▸ h.one_sub, .one_sub⟩ alias ⟨of_one_sub, _⟩ := isStarProjection_one_sub_iff lemma mul_one_sub_self [Star R] (hp : IsStarProjection p) : p * (1 - p) = 0 := hp.isIdempotentElem.mul_one_sub_self lemma one_sub_mul_self [Star R] (hp : IsStarProjection p) : (1 - p) * p = 0 := hp.isIdempotentElem.one_sub_mul_self end NonAssocRing /-- The sum of star projections is a star projection if their product is `0`. -/ theorem add [NonUnitalNonAssocSemiring R] [StarRing R] (hp : IsStarProjection p) (hq : IsStarProjection q) (hpq : p * q = 0) : IsStarProjection (p + q) where isSelfAdjoint := hp.isSelfAdjoint.add hq.isSelfAdjoint isIdempotentElem := hp.isIdempotentElem.add hq.isIdempotentElem <| by rw [hpq, zero_add] simpa [hp.isSelfAdjoint.star_eq, hq.isSelfAdjoint.star_eq] using congr(star $(hpq)) /-- The product of star projections is a star projection if they commute. -/ theorem mul [NonUnitalSemiring R] [StarRing R] (hp : IsStarProjection p) (hq : IsStarProjection q) (hpq : Commute p q) : IsStarProjection (p * q) where isSelfAdjoint := (IsSelfAdjoint.commute_iff hp.isSelfAdjoint hq.isSelfAdjoint).mp hpq isIdempotentElem := hp.isIdempotentElem.mul_of_commute hpq hq.isIdempotentElem /-- `q - p` is a star projection when `p * q = p`. -/ theorem sub_of_mul_eq_left [NonUnitalNonAssocRing R] [StarRing R] (hp : IsStarProjection p) (hq : IsStarProjection q) (hpq : p * q = p) : IsStarProjection (q - p) where isSelfAdjoint := hq.isSelfAdjoint.sub hp.isSelfAdjoint isIdempotentElem := hp.isIdempotentElem.sub hq.isIdempotentElem hpq (by simpa [hp.isSelfAdjoint.star_eq, hq.isSelfAdjoint.star_eq] using congr(star $(hpq))) /-- `q - p` is a star projection when `q * p = p`. -/ theorem sub_of_mul_eq_right [NonUnitalNonAssocRing R] [StarRing R] (hp : IsStarProjection p) (hq : IsStarProjection q) (hqp : q * p = p) : IsStarProjection (q - p) := hp.sub_of_mul_eq_left hq (by simpa [hp.isSelfAdjoint.star_eq, hq.isSelfAdjoint.star_eq] using congr(star $(hqp))) /-- `q - p` is a star projection iff `p * q = p`. -/ theorem sub_iff_mul_eq_left [NonUnitalRing R] [StarRing R] [IsAddTorsionFree R] {p q : R} (hp : IsStarProjection p) (hq : IsStarProjection q) : IsStarProjection (q - p) ↔ p * q = p := by rw [isStarProjection_iff, hp.isIdempotentElem.sub_iff hq.isIdempotentElem] simp_rw [hq.isSelfAdjoint.sub hp.isSelfAdjoint, and_true] nth_rw 3 [← hp.isSelfAdjoint] nth_rw 2 [← hq.isSelfAdjoint] rw [← star_mul, star_eq_iff_star_eq, hp.isSelfAdjoint, eq_comm] simp_rw [and_self] /-- `q - p` is a star projection iff `q * p = p`. -/ theorem sub_iff_mul_eq_right [NonUnitalRing R] [StarRing R] [IsAddTorsionFree R] {p q : R} (hp : IsStarProjection p) (hq : IsStarProjection q) : IsStarProjection (q - p) ↔ q * p = p := by rw [← star_inj] simp [star_mul, hp.isSelfAdjoint.star_eq, hq.isSelfAdjoint.star_eq, sub_iff_mul_eq_left hp hq] theorem add_sub_mul_of_commute [NonUnitalRing R] [StarRing R] (hpq : Commute p q) (hp : IsStarProjection p) (hq : IsStarProjection q) : IsStarProjection (p + q - p * q) where isIdempotentElem := hp.isIdempotentElem.add_sub_mul_of_commute hpq hq.isIdempotentElem isSelfAdjoint := .sub (hp.isSelfAdjoint.add hq.isSelfAdjoint) ((IsSelfAdjoint.commute_iff hp.isSelfAdjoint hq.isSelfAdjoint).mp hpq) end IsStarProjection
.lake/packages/mathlib/Mathlib/Algebra/Star/BigOperators.lean
import Mathlib.Algebra.BigOperators.Group.Finset.Basic import Mathlib.Algebra.Star.Basic import Mathlib.Algebra.Star.SelfAdjoint /-! # Big-operators lemmas about `star` algebraic operations These results are kept separate from `Algebra.Star.Basic` to avoid it needing to import `Finset`. -/ variable {R : Type*} @[simp] theorem star_prod [CommMonoid R] [StarMul R] {α : Type*} (s : Finset α) (f : α → R) : star (∏ x ∈ s, f x) = ∏ x ∈ s, star (f x) := map_prod (starMulAut : R ≃* R) _ _ @[simp] theorem star_sum [AddCommMonoid R] [StarAddMonoid R] {α : Type*} (s : Finset α) (f : α → R) : star (∑ x ∈ s, f x) = ∑ x ∈ s, star (f x) := map_sum (starAddEquiv : R ≃+ R) _ _ theorem isSelfAdjoint_sum {ι : Type*} [AddCommMonoid R] [StarAddMonoid R] (s : Finset ι) {x : ι → R} (h : ∀ i ∈ s, IsSelfAdjoint (x i)) : IsSelfAdjoint (∑ i ∈ s, x i) := by simpa [IsSelfAdjoint, star_sum] using Finset.sum_congr rfl fun _ hi => h _ hi
.lake/packages/mathlib/Mathlib/Algebra/Star/StarRingHom.lean
import Mathlib.Algebra.Ring.Defs import Mathlib.Algebra.Star.Basic /-! # Morphisms of star rings This file defines a new type of morphism between (non-unital) rings `A` and `B` where both `A` and `B` are equipped with a `star` operation. This morphism, namely `NonUnitalStarRingHom`, is a direct extension of its non-`star`red counterpart with a field `map_star` which guarantees it preserves the star operation. As with `NonUnitalRingHom`, the multiplications are not assumed to be associative or unital. ## Main definitions * `NonUnitalStarRingHom` ## Implementation This file is heavily inspired by `Mathlib/Algebra/Star/StarAlgHom.lean`. ## Tags non-unital, ring, morphism, star -/ open EquivLike /-! ### Non-unital star ring homomorphisms -/ /-- A *non-unital ⋆-ring homomorphism* is a non-unital ring homomorphism between non-unital non-associative semirings `A` and `B` equipped with a `star` operation, and this homomorphism is also `star`-preserving. -/ structure NonUnitalStarRingHom (A B : Type*) [NonUnitalNonAssocSemiring A] [Star A] [NonUnitalNonAssocSemiring B] [Star B] extends A →ₙ+* B where /-- By definition, a non-unital ⋆-ring homomorphism preserves the `star` operation. -/ map_star' : ∀ a : A, toFun (star a) = star (toFun a) /-- `α →⋆ₙ+* β` denotes the type of non-unital ring homomorphisms from `α` to `β`. -/ infixr:25 " →⋆ₙ+* " => NonUnitalStarRingHom /-- Reinterpret a non-unital star ring homomorphism as a non-unital ring homomorphism by forgetting the interaction with the star operation. Users should not make use of this, but instead utilize the coercion obtained through the `NonUnitalRingHomClass` instance. -/ add_decl_doc NonUnitalStarRingHom.toNonUnitalRingHom /-- `NonUnitalStarRingHomClass F A B` states that `F` is a type of non-unital ⋆-ring homomorphisms. You should also extend this typeclass when you extend `NonUnitalStarRingHom`. -/ class NonUnitalStarRingHomClass (F : Type*) (A B : outParam Type*) [NonUnitalNonAssocSemiring A] [Star A] [NonUnitalNonAssocSemiring B] [Star B] [FunLike F A B] [NonUnitalRingHomClass F A B] : Prop extends StarHomClass F A B namespace NonUnitalStarRingHomClass variable {F A B : Type*} variable [NonUnitalNonAssocSemiring A] [Star A] variable [NonUnitalNonAssocSemiring B] [Star B] variable [FunLike F A B] [NonUnitalRingHomClass F A B] /-- Turn an element of a type `F` satisfying `NonUnitalStarRingHomClass F A B` into an actual `NonUnitalStarRingHom`. This is declared as the default coercion from `F` to `A →⋆ₙ+ B`. -/ @[coe] def toNonUnitalStarRingHom [NonUnitalStarRingHomClass F A B] (f : F) : A →⋆ₙ+* B := { (f : A →ₙ+* B) with map_star' := map_star f } instance [NonUnitalStarRingHomClass F A B] : CoeHead F (A →⋆ₙ+* B) := ⟨toNonUnitalStarRingHom⟩ end NonUnitalStarRingHomClass namespace NonUnitalStarRingHom section Basic variable {A B C D : Type*} variable [NonUnitalNonAssocSemiring A] [Star A] variable [NonUnitalNonAssocSemiring B] [Star B] variable [NonUnitalNonAssocSemiring C] [Star C] variable [NonUnitalNonAssocSemiring D] [Star D] instance : FunLike (A →⋆ₙ+* B) A B where coe f := f.toFun coe_injective' := by rintro ⟨⟨⟨f, _⟩, _⟩, _⟩ ⟨⟨⟨g, _⟩, _⟩, _⟩ h; congr instance : NonUnitalRingHomClass (A →⋆ₙ+* B) A B where map_mul f := f.map_mul' map_add f := f.map_add' map_zero f := f.map_zero' instance : NonUnitalStarRingHomClass (A →⋆ₙ+* B) A B where map_star f := f.map_star' /-- See Note [custom simps projection] -/ def Simps.apply (f : A →⋆ₙ+* B) : A → B := f initialize_simps_projections NonUnitalStarRingHom (toFun → apply) @[simp] protected theorem coe_coe {F : Type*} [FunLike F A B] [NonUnitalRingHomClass F A B] [NonUnitalStarRingHomClass F A B] (f : F) : ⇑(f : A →⋆ₙ+* B) = f := rfl @[simp] theorem coe_toNonUnitalRingHom (f : A →⋆ₙ+* B) : ⇑f.toNonUnitalRingHom = f := rfl @[ext] theorem ext {f g : A →⋆ₙ+* B} (h : ∀ x, f x = g x) : f = g := DFunLike.ext _ _ h /-- Copy of a `NonUnitalStarRingHom` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (f : A →⋆ₙ+* B) (f' : A → B) (h : f' = f) : A →⋆ₙ+* B where toFun := f' map_zero' := h.symm ▸ map_zero f map_add' := h.symm ▸ map_add f map_mul' := h.symm ▸ map_mul f map_star' := h.symm ▸ map_star f @[simp] theorem coe_copy (f : A →⋆ₙ+* B) (f' : A → B) (h : f' = f) : ⇑(f.copy f' h) = f' := rfl theorem copy_eq (f : A →⋆ₙ+* B) (f' : A → B) (h : f' = f) : f.copy f' h = f := DFunLike.ext' h @[simp] theorem coe_mk (f : A →ₙ+* B) (h) : ((⟨f, h⟩ : A →⋆ₙ+* B) : A → B) = f := rfl @[simp] theorem mk_coe (f : A →⋆ₙ+* B) (h₁ h₂ h₃ h₄) : (⟨⟨⟨f, h₁⟩, h₂, h₃⟩, h₄⟩ : A →⋆ₙ+* B) = f := by ext rfl section variable (A) /-- The identity as a non-unital ⋆-ring homomorphism. -/ protected def id : A →⋆ₙ+* A := { (1 : A →ₙ+* A) with map_star' := fun _ => rfl } @[simp, norm_cast] theorem coe_id : ⇑(NonUnitalStarRingHom.id A) = id := rfl end /-- The composition of non-unital ⋆-ring homomorphisms, as a non-unital ⋆-ring homomorphism. -/ def comp (f : B →⋆ₙ+* C) (g : A →⋆ₙ+* B) : A →⋆ₙ+* C := { f.toNonUnitalRingHom.comp g.toNonUnitalRingHom with map_star' := fun a => by simp [map_star, map_star] } @[simp] theorem coe_comp (f : B →⋆ₙ+* C) (g : A →⋆ₙ+* B) : ⇑(comp f g) = f ∘ g := rfl @[simp] theorem comp_apply (f : B →⋆ₙ+* C) (g : A →⋆ₙ+* B) (a : A) : comp f g a = f (g a) := rfl @[simp] theorem comp_assoc (f : C →⋆ₙ+* D) (g : B →⋆ₙ+* C) (h : A →⋆ₙ+* B) : (f.comp g).comp h = f.comp (g.comp h) := rfl @[simp] theorem id_comp (f : A →⋆ₙ+* B) : (NonUnitalStarRingHom.id _).comp f = f := ext fun _ => rfl @[simp] theorem comp_id (f : A →⋆ₙ+* B) : f.comp (NonUnitalStarRingHom.id _) = f := ext fun _ => rfl instance : Monoid (A →⋆ₙ+* A) where mul := comp mul_assoc := comp_assoc one := NonUnitalStarRingHom.id A one_mul := id_comp mul_one := comp_id @[simp] theorem coe_one : ((1 : A →⋆ₙ+* A) : A → A) = id := rfl theorem one_apply (a : A) : (1 : A →⋆ₙ+* A) a = a := rfl end Basic section Zero -- the `zero` requires extra type class assumptions because we need `star_zero` variable {A B C : Type*} variable [NonUnitalNonAssocSemiring A] [StarAddMonoid A] variable [NonUnitalNonAssocSemiring B] [StarAddMonoid B] instance : Zero (A →⋆ₙ+* B) := ⟨{ (0 : NonUnitalRingHom A B) with map_star' := by simp }⟩ instance : Inhabited (A →⋆ₙ+* B) := ⟨0⟩ instance : MonoidWithZero (A →⋆ₙ+* A) where zero_mul := fun _ => ext fun _ => rfl mul_zero := fun f => ext fun _ => map_zero f @[simp] theorem coe_zero : ((0 : A →⋆ₙ+* B) : A → B) = 0 := rfl theorem zero_apply (a : A) : (0 : A →⋆ₙ+* B) a = 0 := rfl end Zero end NonUnitalStarRingHom /-! ### Star ring equivalences -/ /-- A *⋆-ring* equivalence is an equivalence preserving addition, multiplication, and the star operation, which allows for considering both unital and non-unital equivalences with a single structure. -/ structure StarRingEquiv (A B : Type*) [Add A] [Add B] [Mul A] [Mul B] [Star A] [Star B] extends A ≃+* B where /-- By definition, a ⋆-ring equivalence preserves the `star` operation. -/ map_star' : ∀ a : A, toFun (star a) = star (toFun a) @[inherit_doc] notation:25 A " ≃⋆+* " B => StarRingEquiv A B /-- Reinterpret a star ring equivalence as a `RingEquiv` by forgetting the interaction with the star operation. -/ add_decl_doc StarRingEquiv.toRingEquiv /-- `StarRingEquivClass F A B` asserts `F` is a type of bundled ⋆-ring equivalences between `A` and `B`. You should also extend this typeclass when you extend `StarRingEquiv`. -/ class StarRingEquivClass (F : Type*) (A B : outParam Type*) [Add A] [Mul A] [Star A] [Add B] [Mul B] [Star B] [EquivLike F A B] : Prop extends RingEquivClass F A B where /-- By definition, a ⋆-ring equivalence preserves the `star` operation. -/ map_star : ∀ (f : F) (a : A), f (star a) = star (f a) namespace StarRingEquivClass -- See note [lower instance priority] instance (priority := 50) {F A B : Type*} [Add A] [Mul A] [Star A] [Add B] [Mul B] [Star B] [EquivLike F A B] [hF : StarRingEquivClass F A B] : StarHomClass F A B := { hF with } -- See note [lower instance priority] instance (priority := 100) {F A B : Type*} [NonUnitalNonAssocSemiring A] [Star A] [NonUnitalNonAssocSemiring B] [Star B] [EquivLike F A B] [RingEquivClass F A B] [StarRingEquivClass F A B] : NonUnitalStarRingHomClass F A B := { } /-- Turn an element of a type `F` satisfying `StarRingEquivClass F A B` into an actual `StarRingEquiv`. This is declared as the default coercion from `F` to `A ≃⋆+* B`. -/ @[coe] def toStarRingEquiv {F A B : Type*} [Add A] [Mul A] [Star A] [Add B] [Mul B] [Star B] [EquivLike F A B] [RingEquivClass F A B] [StarRingEquivClass F A B] (f : F) : A ≃⋆+* B := { (f : A ≃+* B) with map_star' := map_star f} /-- Any type satisfying `StarRingEquivClass` can be cast into `StarRingEquiv` via `StarRingEquivClass.toStarRingEquiv`. -/ instance instCoeHead {F A B : Type*} [Add A] [Mul A] [Star A] [Add B] [Mul B] [Star B] [EquivLike F A B] [RingEquivClass F A B] [StarRingEquivClass F A B] : CoeHead F (A ≃⋆+* B) := ⟨toStarRingEquiv⟩ end StarRingEquivClass namespace StarRingEquiv section Basic variable {A B C : Type*} [Add A] [Add B] [Mul A] [Mul B] [Star A] [Star B] [Add C] [Mul C] [Star C] instance : EquivLike (A ≃⋆+* B) A B where coe f := f.toFun inv f := f.invFun left_inv f := f.left_inv right_inv f := f.right_inv coe_injective' f g h₁ h₂ := by rcases f with ⟨⟨⟨_, _, _⟩, _⟩, _⟩ rcases g with ⟨⟨⟨_, _, _⟩, _⟩, _⟩ congr instance : RingEquivClass (A ≃⋆+* B) A B where map_mul f := f.map_mul' map_add f := f.map_add' instance : StarRingEquivClass (A ≃⋆+* B) A B where map_star := map_star' /-- Helper instance for cases where the inference via `EquivLike` is too hard. -/ instance : FunLike (A ≃⋆+* B) A B where coe f := f.toFun coe_injective' := DFunLike.coe_injective @[simp] theorem toRingEquiv_eq_coe (e : A ≃⋆+* B) : e.toRingEquiv = e := rfl @[ext] theorem ext {f g : A ≃⋆+* B} (h : ∀ a, f a = g a) : f = g := DFunLike.ext f g h /-- The identity map as a star ring isomorphism. -/ @[refl] def refl : A ≃⋆+* A := { RingEquiv.refl A with map_star' := fun _ => rfl } instance : Inhabited (A ≃⋆+* A) := ⟨refl⟩ @[simp] theorem coe_refl : ⇑(refl : A ≃⋆+* A) = id := rfl /-- The inverse of a star ring isomorphism is a star ring isomorphism. -/ @[symm] nonrec def symm (e : A ≃⋆+* B) : B ≃⋆+* A := { e.symm with map_star' := fun b => by simpa only [apply_inv_apply, inv_apply_apply] using congr_arg (inv e) (map_star e (inv e b)).symm } /-- See Note [custom simps projection] -/ def Simps.apply (e : A ≃⋆+* B) : A → B := e /-- See Note [custom simps projection] -/ def Simps.symm_apply (e : A ≃⋆+* B) : B → A := e.symm initialize_simps_projections StarRingEquiv (toFun → apply, invFun → symm_apply) @[simp] theorem invFun_eq_symm {e : A ≃⋆+* B} : EquivLike.inv e = e.symm := rfl @[simp] theorem symm_symm (e : A ≃⋆+* B) : e.symm.symm = e := rfl theorem symm_bijective : Function.Bijective (symm : (A ≃⋆+* B) → B ≃⋆+* A) := Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩ @[simp] theorem coe_mk (e h₁) : ⇑(⟨e, h₁⟩ : A ≃⋆+* B) = e := rfl @[simp] theorem mk_coe (e : A ≃⋆+* B) (e' h₁ h₂ h₃ h₄ h₅) : (⟨⟨⟨e, e', h₁, h₂⟩, h₃, h₄⟩, h₅⟩ : A ≃⋆+* B) = e := ext fun _ => rfl /-- Auxiliary definition to avoid looping in `dsimp` with `StarRingEquiv.symm_mk`. -/ protected def symm_mk.aux (f f') (h₁ h₂ h₃ h₄ h₅) := (⟨⟨⟨f, f', h₁, h₂⟩, h₃, h₄⟩, h₅⟩ : A ≃⋆+* B).symm @[simp] theorem symm_mk (f f') (h₁ h₂ h₃ h₄ h₅) : (⟨⟨⟨f, f', h₁, h₂⟩, h₃, h₄⟩, h₅⟩ : A ≃⋆+* B).symm = { symm_mk.aux f f' h₁ h₂ h₃ h₄ h₅ with toFun := f' invFun := f } := rfl @[simp] theorem refl_symm : (StarRingEquiv.refl : A ≃⋆+* A).symm = StarRingEquiv.refl := rfl /-- Transitivity of `StarRingEquiv`. -/ @[trans] def trans (e₁ : A ≃⋆+* B) (e₂ : B ≃⋆+* C) : A ≃⋆+* C := { e₁.toRingEquiv.trans e₂.toRingEquiv with map_star' := fun a => show e₂.toFun (e₁.toFun (star a)) = star (e₂.toFun (e₁.toFun a)) by rw [e₁.map_star', e₂.map_star'] } @[simp] theorem apply_symm_apply (e : A ≃⋆+* B) : ∀ x, e (e.symm x) = x := e.toRingEquiv.apply_symm_apply @[simp] theorem symm_apply_apply (e : A ≃⋆+* B) : ∀ x, e.symm (e x) = x := e.toRingEquiv.symm_apply_apply @[simp] theorem symm_trans_apply (e₁ : A ≃⋆+* B) (e₂ : B ≃⋆+* C) (x : C) : (e₁.trans e₂).symm x = e₁.symm (e₂.symm x) := rfl @[simp] theorem coe_trans (e₁ : A ≃⋆+* B) (e₂ : B ≃⋆+* C) : ⇑(e₁.trans e₂) = e₂ ∘ e₁ := rfl @[simp] theorem trans_apply (e₁ : A ≃⋆+* B) (e₂ : B ≃⋆+* C) (x : A) : (e₁.trans e₂) x = e₂ (e₁ x) := rfl theorem leftInverse_symm (e : A ≃⋆+* B) : Function.LeftInverse e.symm e := e.left_inv theorem rightInverse_symm (e : A ≃⋆+* B) : Function.RightInverse e.symm e := e.right_inv end Basic section Bijective variable {F G A B : Type*} variable [NonUnitalNonAssocSemiring A] [Star A] variable [NonUnitalNonAssocSemiring B] [Star B] variable [FunLike F A B] [NonUnitalRingHomClass F A B] [NonUnitalStarRingHomClass F A B] variable [FunLike G B A] /-- If a (unital or non-unital) star ring morphism has an inverse, it is an isomorphism of star rings. -/ @[simps] def ofStarRingHom (f : F) (g : G) (h₁ : ∀ x, g (f x) = x) (h₂ : ∀ x, f (g x) = x) : A ≃⋆+* B where toFun := f invFun := g left_inv := h₁ right_inv := h₂ map_add' := map_add f map_mul' := map_mul f map_star' := map_star f /-- Promote a bijective star ring homomorphism to a star ring equivalence. -/ noncomputable def ofBijective (f : F) (hf : Function.Bijective f) : A ≃⋆+* B := { RingEquiv.ofBijective f (hf : Function.Bijective (f : A → B)) with toFun := f map_star' := map_star f } @[simp] theorem coe_ofBijective {f : F} (hf : Function.Bijective f) : (StarRingEquiv.ofBijective f hf : A → B) = f := rfl theorem ofBijective_apply {f : F} (hf : Function.Bijective f) (a : A) : (StarRingEquiv.ofBijective f hf) a = f a := rfl end Bijective end StarRingEquiv
.lake/packages/mathlib/Mathlib/Algebra/Star/MonoidHom.lean
import Mathlib.Algebra.Star.Basic /-! # Morphisms of star monoids This file defines the type of morphisms `StarMonoidHom` between monoids `A` and `B` where both `A` and `B` are equipped with a `star` operation. These morphisms are star-preserving monoid homomorphisms and are equipped with the notation `A →⋆* B`. The primary motivation for these morphisms is to provide a target type for morphisms which induce a corresponding morphism between the unitary groups in a star monoid. ## Main definitions * `StarMonoidHom` * `StarMulEquiv` ## Tags monoid, star -/ variable {F A B C D : Type*} /-! ### Star monoid homomorphisms -/ /-- A *star monoid homomorphism* is a monoid homomorphism which is `star`-preserving. -/ structure StarMonoidHom (A B : Type*) [Monoid A] [Star A] [Monoid B] [Star B] extends A →* B where /-- By definition, a star monoid homomorphism preserves the `star` operation. -/ map_star' : ∀ a : A, toFun (star a) = star (toFun a) /-- `α →⋆* β` denotes the type of star monoid homomorphisms from `α` to `β`. -/ infixr:25 " →⋆* " => StarMonoidHom /-- Reinterpret a star monoid homomorphism as a monoid homomorphism by forgetting the interaction with the star operation. -/ add_decl_doc StarMonoidHom.toMonoidHom namespace StarMonoidHom variable [Monoid A] [Star A] [Monoid B] [Star B] instance : FunLike (A →⋆* B) A B where coe f := f.toFun coe_injective' f g h := by cases f; cases g; simp_all instance : MonoidHomClass (A →⋆* B) A B where map_mul f := f.map_mul' map_one f := f.map_one' instance : StarHomClass (A →⋆* B) A B where map_star f := f.map_star' /-- See Note [custom simps projection] -/ def Simps.coe (f : A →⋆* B) : A → B := f initialize_simps_projections StarMonoidHom (toFun → coe) /-- Construct a `StarMonoidHom` from a morphism in some type which preserves `1`, `*` and `star`. -/ @[simps] def ofClass [FunLike F A B] [MonoidHomClass F A B] [StarHomClass F A B] (f : F) : A →⋆* B where toFun := f map_one' := map_one f map_mul' := map_mul f map_star' := map_star f @[simp] theorem coe_toMonoidHom (f : A →⋆* B) : ⇑f.toMonoidHom = f := rfl @[ext] theorem ext {f g : A →⋆* B} (h : ∀ x, f x = g x) : f = g := DFunLike.ext _ _ h /-- Copy of a `StarMonoidHom` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (f : A →⋆* B) (f' : A → B) (h : f' = f) : A →⋆* B where toFun := f' map_one' := h.symm ▸ map_one f map_mul' := h.symm ▸ map_mul f map_star' := h.symm ▸ map_star f @[simp] theorem coe_copy (f : A →⋆* B) (f' : A → B) (h : f' = f) : ⇑(f.copy f' h) = f' := rfl theorem copy_eq (f : A →⋆* B) (f' : A → B) (h : f' = f) : f.copy f' h = f := DFunLike.ext' h @[simp] theorem coe_mk (f : A →* B) (h) : ((⟨f, h⟩ : A →⋆* B) : A → B) = f := rfl section Id variable (A) /-- The identity as a star monoid homomorphism. -/ protected def id : A →⋆* A := { (.id A : A →* A) with map_star' := fun _ ↦ rfl } @[simp, norm_cast] theorem coe_id : ⇑(StarMonoidHom.id A) = id := rfl end Id section Comp variable [Monoid C] [Star C] [Monoid D] [Star D] /-- The composition of star monoid homomorphisms, as a star monoid homomorphism. -/ def comp (f : B →⋆* C) (g : A →⋆* B) : A →⋆* C := { f.toMonoidHom.comp g.toMonoidHom with map_star' := fun a => by simp [map_star] } @[simp] theorem coe_comp (f : B →⋆* C) (g : A →⋆* B) : ⇑(comp f g) = f ∘ g := rfl @[simp] theorem comp_apply (f : B →⋆* C) (g : A →⋆* B) (a : A) : comp f g a = f (g a) := rfl @[simp] theorem comp_assoc (f : C →⋆* D) (g : B →⋆* C) (h : A →⋆* B) : (f.comp g).comp h = f.comp (g.comp h) := rfl @[simp] theorem id_comp (f : A →⋆* B) : (StarMonoidHom.id B).comp f = f := ext fun _ => rfl @[simp] theorem comp_id (f : A →⋆* B) : f.comp (.id _) = f := ext fun _ => rfl instance : Monoid (A →⋆* A) where mul := comp mul_assoc := comp_assoc one := .id A one_mul := id_comp mul_one := comp_id @[simp] theorem coe_one : ((1 : A →⋆* A) : A → A) = id := rfl theorem one_apply (a : A) : (1 : A →⋆* A) a = a := rfl end Comp end StarMonoidHom /-! ### Star monoid equivalences -/ /-- A *star monoid equivalence* is an equivalence preserving multiplication and the star operation. -/ structure StarMulEquiv (A B : Type*) [Mul A] [Mul B] [Star A] [Star B] extends A ≃* B where /-- By definition, a star monoid equivalence preserves the `star` operation. -/ map_star' : ∀ a : A, toFun (star a) = star (toFun a) @[inherit_doc] notation:25 A " ≃⋆* " B => StarMulEquiv A B /-- Reinterpret a star monoid equivalence as a `MulEquiv` by forgetting the interaction with the star operation. -/ add_decl_doc StarMulEquiv.toMulEquiv namespace StarMulEquiv section Basic variable [Mul A] [Mul B] [Mul C] [Mul D] variable [Star A] [Star B] [Star C] [Star D] instance : EquivLike (A ≃⋆* B) A B where coe e := e.toFun inv e := e.invFun left_inv e := e.left_inv right_inv e := e.right_inv coe_injective' f g h := by cases f; cases g; simp_all instance : MulEquivClass (A ≃⋆* B) A B where map_mul f := f.map_mul' instance : StarHomClass (A ≃⋆* B) A B where map_star f := f.map_star' @[ext] theorem ext {f g : A ≃⋆* B} (h : ∀ a, f a = g a) : f = g := DFunLike.ext f g h variable (A) in /-- The identity map as a star monoid isomorphism. -/ @[refl] protected def refl : A ≃⋆* A := { MulEquiv.refl A with map_star' := fun _ => rfl } instance : Inhabited (A ≃⋆* A) := ⟨.refl A⟩ @[simp] theorem coe_refl : ⇑(.refl A : A ≃⋆* A) = id := rfl /-- The inverse of a star monoid isomorphism is a star monoid isomorphism. -/ @[symm] nonrec def symm (e : A ≃⋆* B) : B ≃⋆* A := { e.symm with map_star' := fun b => by simpa only [EquivLike.apply_inv_apply, EquivLike.inv_apply_apply] using congr_arg (EquivLike.inv e) (map_star e (EquivLike.inv e b)).symm } /-- See Note [custom simps projection] -/ def Simps.apply (e : A ≃⋆* B) : A → B := e /-- See Note [custom simps projection] -/ def Simps.symm_apply (e : A ≃⋆* B) : B → A := e.symm initialize_simps_projections StarMulEquiv (toFun → apply, invFun → symm_apply) @[simp] theorem invFun_eq_symm {e : A ≃⋆* B} : EquivLike.inv e = e.symm := rfl @[simp] theorem symm_symm (e : A ≃⋆* B) : e.symm.symm = e := rfl theorem symm_bijective : Function.Bijective (symm : (A ≃⋆* B) → B ≃⋆* A) := Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩ theorem coe_mk (e h₁) : ⇑(⟨e, h₁⟩ : A ≃⋆* B) = e := rfl /-- Construct a `StarMulEquiv` from an equivalence in some type which preserves `*` and `star`. -/ @[simps] def ofClass [EquivLike F A B] [MulEquivClass F A B] [StarHomClass F A B] (f : F) : A ≃⋆* B where toFun := f invFun := EquivLike.inv f left_inv := EquivLike.left_inv f right_inv := EquivLike.right_inv f map_mul' := map_mul f map_star' := map_star f @[simp] theorem coe_toMulEquiv (f : A ≃⋆* B) : ⇑f.toMulEquiv = f := rfl @[simp] theorem toMulEquiv_symm (f : A ≃⋆* B) : f.symm.toMulEquiv = f.toMulEquiv.symm := rfl @[simp] theorem refl_symm : (.refl A : A ≃⋆* A).symm = .refl A := rfl /-- Transitivity of `StarMulEquiv`. -/ @[trans] def trans (e₁ : A ≃⋆* B) (e₂ : B ≃⋆* C) : A ≃⋆* C := { e₁.toMulEquiv.trans e₂.toMulEquiv with map_star' := fun a => show e₂.toFun (e₁.toFun (star a)) = star (e₂.toFun (e₁.toFun a)) by rw [e₁.map_star', e₂.map_star'] } @[simp] theorem apply_symm_apply (e : A ≃⋆* B) : ∀ x, e (e.symm x) = x := e.toMulEquiv.apply_symm_apply @[simp] theorem symm_apply_apply (e : A ≃⋆* B) : ∀ x, e.symm (e x) = x := e.toMulEquiv.symm_apply_apply @[simp] theorem symm_trans_apply (e₁ : A ≃⋆* B) (e₂ : B ≃⋆* C) (x : C) : (e₁.trans e₂).symm x = e₁.symm (e₂.symm x) := rfl @[simp] theorem coe_trans (e₁ : A ≃⋆* B) (e₂ : B ≃⋆* C) : ⇑(e₁.trans e₂) = e₂ ∘ e₁ := rfl @[simp] theorem trans_apply (e₁ : A ≃⋆* B) (e₂ : B ≃⋆* C) (x : A) : (e₁.trans e₂) x = e₂ (e₁ x) := rfl @[simp] theorem toMulEquiv_trans (e₁ : A ≃⋆* B) (e₂ : B ≃⋆* C) : (e₁.trans e₂).toMulEquiv = e₁.toMulEquiv.trans e₂.toMulEquiv := rfl theorem leftInverse_symm (e : A ≃⋆* B) : Function.LeftInverse e.symm e := e.left_inv theorem rightInverse_symm (e : A ≃⋆* B) : Function.RightInverse e.symm e := e.right_inv end Basic section Bijective variable [Monoid A] [Monoid B] [Star A] [Star B] /-- Reinterpret a `StarMulEquiv` as a `StarMonoidHom`. -/ @[simps] def toStarMonoidHom (f : A ≃⋆* B) : A →⋆* B where toFun := f map_one' := map_one f map_mul' := map_mul f map_star' := map_star f /-- If a star monoid morphism has an inverse, it is an isomorphism of star monoids. -/ @[simps] def ofStarMonoidHom (f : A →⋆* B) (g : B →⋆* A) (h₁ : g.comp f = .id _) (h₂ : f.comp g = .id _) : A ≃⋆* B where toFun := f invFun := g left_inv := DFunLike.ext_iff.mp h₁ right_inv := DFunLike.ext_iff.mp h₂ map_mul' := map_mul f map_star' := map_star f /-- Promote a bijective star monoid homomorphism to a star monoid equivalence. -/ noncomputable def ofBijective (f : A →⋆* B) (hf : Function.Bijective f) : A ≃⋆* B := { MulEquiv.ofBijective f (hf : Function.Bijective (f : A → B)) with toFun := f map_star' := map_star f } @[simp] theorem coe_ofBijective {f : A →⋆* B} (hf : Function.Bijective f) : (StarMulEquiv.ofBijective f hf : A → B) = f := rfl theorem ofBijective_apply {f : A →⋆* B} (hf : Function.Bijective f) (a : A) : StarMulEquiv.ofBijective f hf a = f a := rfl end Bijective end StarMulEquiv
.lake/packages/mathlib/Mathlib/Algebra/Star/Free.lean
import Mathlib.Algebra.Star.Basic import Mathlib.Algebra.FreeAlgebra /-! # A *-algebra structure on the free algebra. Reversing words gives a *-structure on the free monoid or on the free algebra on a type. ## Implementation note We have this in a separate file, rather than in `Algebra.FreeMonoid` and `Algebra.FreeAlgebra`, to avoid importing `Algebra.Star.Basic` into the entire hierarchy. -/ namespace FreeMonoid variable {α : Type*} instance : StarMul (FreeMonoid α) where star := List.reverse star_involutive := List.reverse_reverse star_mul := fun _ _ => List.reverse_append @[simp] theorem star_of (x : α) : star (of x) = of x := rfl /-- Note that `star_one` is already a global simp lemma, but this one works with dsimp too -/ @[simp] theorem star_one : star (1 : FreeMonoid α) = 1 := rfl end FreeMonoid namespace FreeAlgebra variable {R : Type*} [CommSemiring R] {X : Type*} /-- The star ring formed by reversing the elements of products -/ instance : StarRing (FreeAlgebra R X) where star := MulOpposite.unop ∘ lift R (MulOpposite.op ∘ ι R) star_involutive x := by simp only [Function.comp_apply] let y := lift R (X := X) (MulOpposite.op ∘ ι R) refine induction (motive := fun x ↦ (y (y x).unop).unop = x) _ _ ?_ ?_ ?_ ?_ x · intros simp only [AlgHom.commutes, MulOpposite.algebraMap_apply, MulOpposite.unop_op] · intros simp only [y, lift_ι_apply, Function.comp_apply, MulOpposite.unop_op] · intros simp only [*, map_mul, MulOpposite.unop_mul] · intros simp only [*, map_add, MulOpposite.unop_add] star_mul a b := by simp only [Function.comp_apply, map_mul, MulOpposite.unop_mul] star_add a b := by simp only [Function.comp_apply, map_add, MulOpposite.unop_add] @[simp] theorem star_ι (x : X) : star (ι R x) = ι R x := by simp [star, Star.star] @[simp] theorem star_algebraMap (r : R) : star (algebraMap R (FreeAlgebra R X) r) = algebraMap R _ r := by simp [star, Star.star] /-- `star` as an `AlgEquiv` -/ def starHom : FreeAlgebra R X ≃ₐ[R] (FreeAlgebra R X)ᵐᵒᵖ := { starRingEquiv with commutes' := fun r => by simp [star_algebraMap] } end FreeAlgebra
.lake/packages/mathlib/Mathlib/Algebra/Star/Conjneg.lean
import Mathlib.Algebra.BigOperators.Pi import Mathlib.Algebra.Star.Pi import Mathlib.Algebra.Group.Pointwise.Set.Basic /-! # Conjugation-negation operator This file defines the conjugation-negation operator, useful in Fourier analysis. The way this operator enters the picture is that the adjoint of convolution with a function `f` is convolution with `conjneg f`. -/ open Function open scoped ComplexConjugate variable {ι G R : Type*} [AddGroup G] section CommSemiring variable [CommSemiring R] [StarRing R] {f g : G → R} /-- Conjugation-negation. Sends `f` to `fun x ↦ conj (f (-x))`. -/ def conjneg (f : G → R) : G → R := conj fun x ↦ f (-x) @[simp] lemma conjneg_apply (f : G → R) (x : G) : conjneg f x = conj (f (-x)) := rfl @[simp] lemma conjneg_conjneg (f : G → R) : conjneg (conjneg f) = f := by ext; simp lemma conjneg_involutive : Involutive (conjneg : (G → R) → G → R) := conjneg_conjneg lemma conjneg_bijective : Bijective (conjneg : (G → R) → G → R) := conjneg_involutive.bijective lemma conjneg_injective : Injective (conjneg : (G → R) → G → R) := conjneg_involutive.injective lemma conjneg_surjective : Surjective (conjneg : (G → R) → G → R) := conjneg_involutive.surjective @[simp] lemma conjneg_inj : conjneg f = conjneg g ↔ f = g := conjneg_injective.eq_iff lemma conjneg_ne_conjneg : conjneg f ≠ conjneg g ↔ f ≠ g := conjneg_injective.ne_iff @[simp] lemma conjneg_conj (f : G → R) : conjneg (conj f) = conj (conjneg f) := rfl @[simp] lemma conjneg_zero : conjneg (0 : G → R) = 0 := by ext; simp @[simp] lemma conjneg_one : conjneg (1 : G → R) = 1 := by ext; simp @[simp] lemma conjneg_add (f g : G → R) : conjneg (f + g) = conjneg f + conjneg g := by ext; simp @[simp] lemma conjneg_mul (f g : G → R) : conjneg (f * g) = conjneg f * conjneg g := by ext; simp @[simp] lemma conjneg_sum (s : Finset ι) (f : ι → G → R) : conjneg (∑ i ∈ s, f i) = ∑ i ∈ s, conjneg (f i) := by ext; simp @[simp] lemma conjneg_prod (s : Finset ι) (f : ι → G → R) : conjneg (∏ i ∈ s, f i) = ∏ i ∈ s, conjneg (f i) := by ext; simp @[simp] lemma conjneg_eq_zero : conjneg f = 0 ↔ f = 0 := by rw [← conjneg_inj, conjneg_conjneg, conjneg_zero] @[simp] lemma conjneg_eq_one : conjneg f = 1 ↔ f = 1 := by rw [← conjneg_inj, conjneg_conjneg, conjneg_one] lemma conjneg_ne_zero : conjneg f ≠ 0 ↔ f ≠ 0 := conjneg_eq_zero.not lemma conjneg_ne_one : conjneg f ≠ 1 ↔ f ≠ 1 := conjneg_eq_one.not lemma sum_conjneg [Fintype G] (f : G → R) : ∑ a, conjneg f a = ∑ a, conj (f a) := Fintype.sum_equiv (Equiv.neg _) _ _ fun _ ↦ rfl @[simp] lemma support_conjneg (f : G → R) : support (conjneg f) = -support f := by ext; simp [starRingEnd_apply] /-- `conjneg` bundled as a ring homomorphism. -/ @[simps] def conjnegRingHom : (G → R) →+* (G → R) where toFun := conjneg map_zero' := conjneg_zero map_one' := conjneg_one map_add' := conjneg_add map_mul' := conjneg_mul end CommSemiring section CommRing variable [CommRing R] [StarRing R] @[simp] lemma conjneg_sub (f g : G → R) : conjneg (f - g) = conjneg f - conjneg g := by ext; simp @[simp] lemma conjneg_neg (f : G → R) : conjneg (-f) = -conjneg f := by ext; simp end CommRing
.lake/packages/mathlib/Mathlib/Algebra/SkewPolynomial/Basic.lean
import Mathlib.Algebra.Algebra.Defs import Mathlib.Algebra.SkewMonoidAlgebra.Basic /-! # Univariate skew polynomials Given a ring `R` and an endomorphism `φ` on `R` the skew polynomials over `R` are polynomials $$\sum_{i= 0}^n a_iX^n, n\geq 0, a_i\in R$$ where the addition is the usual addition of polynomials $$\sum_{i= 0}^n a_iX^n + \sum_{i= 0}^n b_iX^n= \sum_{i= 0}^n (a_i + b_i)X^n.$$ The multiplication, however, is determined by $$Xa = \varphi (a)X$$ by extending it to all polynomials in the obvious way. Skew polynomials are represented as `SkewMonoidAlgebra R (Multiplicative ℕ)`, where `R` is usually at least a Semiring. In this file, we define `SkewPolynomial` and provide basic instances. **Note**: To register the endomorphism `φ` see notation below. ## Notation The endomorphism `φ` is implemented using some action of `Multiplicative ℕ` on `R`. From this action, `φ` is an `abbrev` denoting $(\text{ofAdd } 1) \cdot a := \varphi(a)$. Users that want to work with a specific map `φ` should introduce an an action of `Multiplicative ℕ` on `R`. Specifying that this action is a `MulSemiringAction` amounts to saying that `φ` is an endomorphism. Furthermore, with this notation `φ^[n](a) = (ofAdd n) • a`, see `φ_iterate_apply`. ## Implementation notes The implementation uses `Muliplicative ℕ` instead of `ℕ` as some notion of `AddSkewMonoidAlgebra` like the current implementation of `Polynomials` in Mathlib. This decision was made because we use the type class `MulSemiringAction` to specify the properties the action needs to respect for associativity. There is no version of this in Mathlib that uses an acting `AddMonoid M` and so we need to use `Multiplicative ℕ` for the action. For associativity to hold, there should be an instance of `MulSemiringAction (Multiplicative ℕ) R` present in the context. For example, in the context of $\mathbb{F}_q$-linear polynomials, this can be the $q$-th Frobenius endomorphism - so $\varphi(a) = a^q$. ## Reference The definition is inspired by Chapter 3 of [Papikian2023]. ## Tags Skew Polynomials, Twisted Polynomials. ## TODO : - Add algebra instance - Add `ext` lemma in terms of `Coeff`. Note that [ore33] proposes a more general definition of skew polynomial ring, where the multiplication is determined by $Xa = \varphi (a)X + δ (a)$, where `ϕ` is as above and `δ` is a derivation. -/ noncomputable section open Multiplicative SkewMonoidAlgebra /-- The skew polynomials over `R` is the type of univariate polynomials over `R` endowed with a skewed convolution product. -/ def SkewPolynomial (R : Type*) [AddCommMonoid R] := SkewMonoidAlgebra R (Multiplicative ℕ) namespace SkewPolynomial variable {R : Type*} section Semiring variable [Semiring R] {p q : SkewPolynomial R} instance : Inhabited (SkewPolynomial R) := SkewMonoidAlgebra.instInhabited instance : AddCommMonoid (SkewPolynomial R) := SkewMonoidAlgebra.instAddCommMonoid instance instSemiring [MulSemiringAction (Multiplicative ℕ) R] : Semiring (SkewPolynomial R) := SkewMonoidAlgebra.instSemiring variable {S S₁ S₂ : Type*} instance [Semiring S] [Module S R] : Module S (SkewPolynomial R) := SkewMonoidAlgebra.instModule instance [Semiring S₁] [Semiring S₂] [Module S₁ R] [Module S₂ R] [SMulCommClass S₁ S₂ R] : SMulCommClass S₁ S₂ (SkewPolynomial R) := SkewMonoidAlgebra.instSMulCommClass instance [SMulZeroClass S R] : SMulZeroClass S (SkewPolynomial R) := SkewMonoidAlgebra.instSMulZeroClass instance [SMul S₁ S₂] [SMulZeroClass S₁ R] [SMulZeroClass S₂ R] [IsScalarTower S₁ S₂ R] : IsScalarTower S₁ S₂ (SkewPolynomial R) := SkewMonoidAlgebra.instIsScalarTower instance [Subsingleton R] : Unique (SkewPolynomial R) := SkewMonoidAlgebra.instUniqueOfSubsingleton /-- The set of all `n` such that `X^n` has a non-zero coefficient. -/ def support (p : SkewPolynomial R) : Finset ℕ := Finset.map ⟨toAdd, toAdd.injective⟩ (SkewMonoidAlgebra.support p) @[simp] lemma support_zero : (0 : SkewPolynomial R).support = ∅ := rfl @[simp] lemma support_eq_empty : p.support = ∅ ↔ p = 0 := by simp [support] lemma card_support_eq_zero : p.support.card = 0 ↔ p = 0 := by simp lemma support_add : (p + q).support ⊆ p.support ∪ q.support := by simpa [support, ← Finset.map_union, Finset.map_subset_map] using SkewMonoidAlgebra.support_add section phi variable [MulSemiringAction (Multiplicative ℕ) R] /-- Ring homomorphism associated to the twist of the skew polynomial ring. The multiplication in a skew polynomial ring is given by `xr = φ(r)x`. -/ abbrev φ := MulSemiringAction.toRingHom (Multiplicative ℕ) R (ofAdd 1) theorem φ_def : φ = MulSemiringAction.toRingHom (Multiplicative ℕ) R (ofAdd 1) := rfl lemma φ_iterate_apply (n : ℕ) (a : R) : (φ^[n] a) = ((ofAdd n) • a) := by induction n with | zero => simp | succ n hn => simp_all [MulSemiringAction.toRingHom_apply, Function.iterate_succ', -Function.iterate_succ, ← mul_smul, mul_comm] end phi /-- `monomial s a` is the monomial `a * X^s` -/ def monomial (n : ℕ) : R →ₗ[R] SkewPolynomial R := lsingle (ofAdd n) lemma monomial_zero_right (n : ℕ) : monomial n (0 : R) = 0 := single_zero _ lemma monomial_zero_one [MulSemiringAction (Multiplicative ℕ) R] : monomial (0 : ℕ) (1 : R) = 1 := rfl lemma monomial_def (n : ℕ) (a : R) : monomial n a = single (ofAdd n) a := rfl lemma monomial_add (n : ℕ) (r s : R) : monomial n (r + s) = monomial n r + monomial n s := single_add .. lemma smul_monomial {S} [Semiring S] [Module S R] (a : S) (n : ℕ) (b : R) : a • monomial n b = monomial n (a • b) := smul_single .. lemma monomial_mul_monomial [MulSemiringAction (Multiplicative ℕ) R] (n m : ℕ) (r s : R) : monomial n r * monomial m s = monomial (n + m) (r * (φ^[n] s)) := by rw [φ_iterate_apply] exact SkewMonoidAlgebra.single_mul_single end Semiring end SkewPolynomial
.lake/packages/mathlib/Mathlib/Algebra/Tropical/Basic.lean
import Mathlib.Algebra.Order.AddGroupWithTop import Mathlib.Algebra.Order.Monoid.Unbundled.MinMax import Mathlib.Algebra.Order.Monoid.Unbundled.Pow import Mathlib.Algebra.Order.Monoid.Unbundled.WithTop import Mathlib.Algebra.Ring.Defs import Mathlib.Order.Hom.Basic /-! # Tropical algebraic structures This file defines algebraic structures of the (min-)tropical numbers, up to the tropical semiring. Some basic lemmas about conversion from the base type `R` to `Tropical R` are provided, as well as the expected implementations of tropical addition and tropical multiplication. ## Main declarations * `Tropical R`: The type synonym of the tropical interpretation of `R`. If `[LinearOrder R]`, then addition on `R` is via `min`. * `Semiring (Tropical R)`: A `LinearOrderedAddCommMonoidWithTop R` induces a `Semiring (Tropical R)`. If one solely has `[LinearOrderedAddCommMonoid R]`, then the "tropicalization of `R`" would be `Tropical (WithTop R)`. ## Implementation notes The tropical structure relies on `Top` and `min`. For the max-tropical numbers, use `OrderDual R`. Inspiration was drawn from the implementation of `Additive`/`Multiplicative`/`Opposite`, where a type synonym is created with some barebones API, and quickly made irreducible. Algebraic structures are provided with as few typeclass assumptions as possible, even though most references rely on `Semiring (Tropical R)` for building up the whole theory. ## References followed * https://arxiv.org/pdf/math/0408099.pdf * https://www.mathenjeans.fr/sites/default/files/sujets/tropical_geometry_-_casagrande.pdf -/ assert_not_exists Nat.instMulOneClass universe u v variable (R : Type u) /-- The tropicalization of a type `R`. -/ def Tropical : Type u := R variable {R} namespace Tropical /-- Reinterpret `x : R` as an element of `Tropical R`. See `Tropical.tropEquiv` for the equivalence. -/ def trop : R → Tropical R := id /-- Reinterpret `x : Tropical R` as an element of `R`. See `Tropical.tropEquiv` for the equivalence. -/ @[pp_nodot] def untrop : Tropical R → R := id theorem trop_injective : Function.Injective (trop : R → Tropical R) := fun _ _ => id theorem untrop_injective : Function.Injective (untrop : Tropical R → R) := fun _ _ => id @[simp] theorem trop_inj_iff (x y : R) : trop x = trop y ↔ x = y := Iff.rfl @[simp] theorem untrop_inj_iff (x y : Tropical R) : untrop x = untrop y ↔ x = y := Iff.rfl @[simp] theorem trop_untrop (x : Tropical R) : trop (untrop x) = x := rfl @[simp] theorem untrop_trop (x : R) : untrop (trop x) = x := rfl attribute [irreducible] Tropical theorem leftInverse_trop : Function.LeftInverse (trop : R → Tropical R) untrop := trop_untrop theorem rightInverse_trop : Function.RightInverse (trop : R → Tropical R) untrop := untrop_trop /-- Reinterpret `x : R` as an element of `Tropical R`. See `Tropical.tropOrderIso` for the order-preserving equivalence. -/ def tropEquiv : R ≃ Tropical R where toFun := trop invFun := untrop left_inv := untrop_trop right_inv := trop_untrop @[simp] theorem tropEquiv_coe_fn : (tropEquiv : R → Tropical R) = trop := rfl @[simp] theorem tropEquiv_symm_coe_fn : (tropEquiv.symm : Tropical R → R) = untrop := rfl theorem trop_eq_iff_eq_untrop {x : R} {y} : trop x = y ↔ x = untrop y := tropEquiv.apply_eq_iff_eq_symm_apply theorem untrop_eq_iff_eq_trop {x} {y : R} : untrop x = y ↔ x = trop y := tropEquiv.symm.apply_eq_iff_eq_symm_apply theorem injective_trop : Function.Injective (trop : R → Tropical R) := tropEquiv.injective theorem injective_untrop : Function.Injective (untrop : Tropical R → R) := tropEquiv.symm.injective theorem surjective_trop : Function.Surjective (trop : R → Tropical R) := tropEquiv.surjective theorem surjective_untrop : Function.Surjective (untrop : Tropical R → R) := tropEquiv.symm.surjective instance [Inhabited R] : Inhabited (Tropical R) := ⟨trop default⟩ /-- Recursing on an `x' : Tropical R` is the same as recursing on an `x : R` reinterpreted as a term of `Tropical R` via `trop x`. -/ @[simp] def tropRec {F : Tropical R → Sort v} (h : ∀ X, F (trop X)) : ∀ X, F X := fun X => h (untrop X) instance [DecidableEq R] : DecidableEq (Tropical R) := fun _ _ => decidable_of_iff _ injective_untrop.eq_iff section Order instance instLETropical [LE R] : LE (Tropical R) where le x y := untrop x ≤ untrop y @[simp] theorem untrop_le_iff [LE R] {x y : Tropical R} : untrop x ≤ untrop y ↔ x ≤ y := Iff.rfl instance decidableLE [LE R] [DecidableLE R] : DecidableLE (Tropical R) := fun x y => ‹DecidableLE R› (untrop x) (untrop y) instance instLTTropical [LT R] : LT (Tropical R) where lt x y := untrop x < untrop y @[simp] theorem untrop_lt_iff [LT R] {x y : Tropical R} : untrop x < untrop y ↔ x < y := Iff.rfl instance decidableLT [LT R] [DecidableLT R] : DecidableLT (Tropical R) := fun x y => ‹DecidableLT R› (untrop x) (untrop y) instance instPreorderTropical [Preorder R] : Preorder (Tropical R) := { instLETropical, instLTTropical with le_refl := fun x => le_refl (untrop x) le_trans := fun _ _ _ h h' => le_trans (α := R) h h' lt_iff_le_not_ge := fun _ _ => lt_iff_le_not_ge (α := R) } /-- Reinterpret `x : R` as an element of `Tropical R`, preserving the order. -/ def tropOrderIso [Preorder R] : R ≃o Tropical R := { tropEquiv with map_rel_iff' := untrop_le_iff } @[simp] theorem tropOrderIso_coe_fn [Preorder R] : (tropOrderIso : R → Tropical R) = trop := rfl @[simp] theorem tropOrderIso_symm_coe_fn [Preorder R] : (tropOrderIso.symm : Tropical R → R) = untrop := rfl theorem trop_monotone [Preorder R] : Monotone (trop : R → Tropical R) := fun _ _ => id theorem untrop_monotone [Preorder R] : Monotone (untrop : Tropical R → R) := fun _ _ => id instance instPartialOrderTropical [PartialOrder R] : PartialOrder (Tropical R) := { instPreorderTropical with le_antisymm := fun _ _ h h' => untrop_injective (le_antisymm h h') } instance instZeroTropical [Top R] : Zero (Tropical R) := ⟨trop ⊤⟩ instance instTopTropical [Top R] : Top (Tropical R) := ⟨0⟩ @[simp] theorem untrop_zero [Top R] : untrop (0 : Tropical R) = ⊤ := rfl @[simp] theorem trop_top [Top R] : trop (⊤ : R) = 0 := rfl @[simp] theorem trop_coe_ne_zero (x : R) : trop (x : WithTop R) ≠ 0 := nofun @[simp] theorem zero_ne_trop_coe (x : R) : 0 ≠ (trop x : Tropical (WithTop R)) := nofun @[simp] theorem le_zero [LE R] [OrderTop R] (x : Tropical R) : x ≤ 0 := le_top (α := R) instance [LE R] [OrderTop R] : OrderTop (Tropical R) := { instTopTropical with le_top := fun _ => le_top (α := R) } variable [LinearOrder R] /-- Tropical addition is the minimum of two underlying elements of `R`. -/ instance : Add (Tropical R) := ⟨fun x y => trop (min (untrop x) (untrop y))⟩ instance instAddCommSemigroupTropical : AddCommSemigroup (Tropical R) where add_assoc _ _ _ := untrop_injective (min_assoc _ _ _) add_comm _ _ := untrop_injective (min_comm _ _) @[simp] theorem untrop_add (x y : Tropical R) : untrop (x + y) = min (untrop x) (untrop y) := rfl @[simp] theorem trop_min (x y : R) : trop (min x y) = trop x + trop y := rfl @[simp] theorem trop_inf (x y : R) : trop (x ⊓ y) = trop x + trop y := rfl theorem trop_add_def (x y : Tropical R) : x + y = trop (min (untrop x) (untrop y)) := rfl instance instLinearOrderTropical : LinearOrder (Tropical R) := { instPartialOrderTropical with le_total := fun a b => le_total (untrop a) (untrop b) toDecidableLE := Tropical.decidableLE toDecidableEq := Tropical.instDecidableEq toDecidableLT := Tropical.decidableLT max := fun a b => trop (max (untrop a) (untrop b)) max_def := fun a b => untrop_injective (by simp only [max_def, untrop_le_iff, untrop_trop]; split_ifs <;> simp) min := (· + ·) min_def := fun a b => untrop_injective (by simp only [untrop_add, min_def, untrop_le_iff]; split_ifs <;> simp) } @[simp] theorem untrop_sup (x y : Tropical R) : untrop (x ⊔ y) = untrop x ⊔ untrop y := rfl @[simp] theorem untrop_max (x y : Tropical R) : untrop (max x y) = max (untrop x) (untrop y) := rfl @[simp] theorem min_eq_add : (min : Tropical R → Tropical R → Tropical R) = (· + ·) := rfl @[simp] theorem inf_eq_add : ((· ⊓ ·) : Tropical R → Tropical R → Tropical R) = (· + ·) := rfl theorem trop_max_def (x y : Tropical R) : max x y = trop (max (untrop x) (untrop y)) := rfl theorem trop_sup_def (x y : Tropical R) : x ⊔ y = trop (untrop x ⊔ untrop y) := rfl @[simp] theorem add_eq_left ⦃x y : Tropical R⦄ (h : x ≤ y) : x + y = x := untrop_injective (by simpa using h) @[simp] theorem add_eq_right ⦃x y : Tropical R⦄ (h : y ≤ x) : x + y = y := untrop_injective (by simpa using h) theorem add_eq_left_iff {x y : Tropical R} : x + y = x ↔ x ≤ y := by rw [trop_add_def, trop_eq_iff_eq_untrop, ← untrop_le_iff, min_eq_left_iff] theorem add_eq_right_iff {x y : Tropical R} : x + y = y ↔ y ≤ x := by rw [trop_add_def, trop_eq_iff_eq_untrop, ← untrop_le_iff, min_eq_right_iff] theorem add_self (x : Tropical R) : x + x = x := untrop_injective (min_eq_right le_rfl) theorem add_eq_iff {x y z : Tropical R} : x + y = z ↔ x = z ∧ x ≤ y ∨ y = z ∧ y ≤ x := by rw [trop_add_def, trop_eq_iff_eq_untrop] simp [min_eq_iff] @[simp] theorem add_eq_zero_iff {a b : Tropical (WithTop R)} : a + b = 0 ↔ a = 0 ∧ b = 0 := by rw [add_eq_iff] constructor · rintro (⟨rfl, h⟩ | ⟨rfl, h⟩) · exact ⟨rfl, le_antisymm (le_zero _) h⟩ · exact ⟨le_antisymm (le_zero _) h, rfl⟩ · rintro ⟨rfl, rfl⟩ simp instance instAddCommMonoidTropical [OrderTop R] : AddCommMonoid (Tropical R) := { instZeroTropical, instAddCommSemigroupTropical with zero_add := fun _ => untrop_injective (min_top_left _) add_zero := fun _ => untrop_injective (min_top_right _) nsmul := nsmulRec } end Order section Monoid /-- Tropical multiplication is the addition in the underlying `R`. -/ instance [Add R] : Mul (Tropical R) := ⟨fun x y => trop (untrop x + untrop y)⟩ @[simp] theorem trop_add [Add R] (x y : R) : trop (x + y) = trop x * trop y := rfl @[simp] theorem untrop_mul [Add R] (x y : Tropical R) : untrop (x * y) = untrop x + untrop y := rfl theorem trop_mul_def [Add R] (x y : Tropical R) : x * y = trop (untrop x + untrop y) := rfl instance instOneTropical [Zero R] : One (Tropical R) := ⟨trop 0⟩ @[simp] theorem trop_zero [Zero R] : trop (0 : R) = 1 := rfl @[simp] theorem untrop_one [Zero R] : untrop (1 : Tropical R) = 0 := rfl instance instAddMonoidWithOneTropical [LinearOrder R] [OrderTop R] [Zero R] : AddMonoidWithOne (Tropical R) := { instOneTropical, instAddCommMonoidTropical with natCast := fun n => if n = 0 then 0 else 1 natCast_zero := rfl natCast_succ := fun n => (untrop_inj_iff _ _).1 (by cases n <;> simp) } instance [Zero R] : Nontrivial (Tropical (WithTop R)) := ⟨⟨0, 1, trop_injective.ne WithTop.top_ne_coe⟩⟩ instance [Neg R] : Inv (Tropical R) := ⟨fun x => trop (-untrop x)⟩ @[simp] theorem untrop_inv [Neg R] (x : Tropical R) : untrop x⁻¹ = -untrop x := rfl instance [Sub R] : Div (Tropical R) := ⟨fun x y => trop (untrop x - untrop y)⟩ @[simp] theorem untrop_div [Sub R] (x y : Tropical R) : untrop (x / y) = untrop x - untrop y := rfl instance instSemigroupTropical [AddSemigroup R] : Semigroup (Tropical R) where mul_assoc _ _ _ := untrop_injective (add_assoc _ _ _) instance instCommSemigroupTropical [AddCommSemigroup R] : CommSemigroup (Tropical R) := { instSemigroupTropical with mul_comm := fun _ _ => untrop_injective (add_comm _ _) } instance {α : Type*} [SMul α R] : Pow (Tropical R) α where pow x n := trop <| n • untrop x @[simp] theorem untrop_pow {α : Type*} [SMul α R] (x : Tropical R) (n : α) : untrop (x ^ n) = n • untrop x := rfl @[simp] theorem trop_smul {α : Type*} [SMul α R] (x : R) (n : α) : trop (n • x) = trop x ^ n := rfl instance instMulOneClassTropical [AddZeroClass R] : MulOneClass (Tropical R) where one_mul _ := untrop_injective <| zero_add _ mul_one _ := untrop_injective <| add_zero _ instance instMonoidTropical [AddMonoid R] : Monoid (Tropical R) := { instMulOneClassTropical, instSemigroupTropical with npow := fun n x => x ^ n npow_zero := fun _ => untrop_injective <| by simp npow_succ := fun _ _ => untrop_injective <| succ_nsmul _ _ } @[simp] theorem trop_nsmul [AddMonoid R] (x : R) (n : ℕ) : trop (n • x) = trop x ^ n := rfl instance instCommMonoidTropical [AddCommMonoid R] : CommMonoid (Tropical R) := { instMonoidTropical, instCommSemigroupTropical with } instance instGroupTropical [AddGroup R] : Group (Tropical R) := { instMonoidTropical with div_eq_mul_inv := fun _ _ => untrop_injective <| by simp [sub_eq_add_neg] inv_mul_cancel := fun _ => untrop_injective <| neg_add_cancel _ zpow := fun n x => trop <| n • untrop x zpow_zero' := fun _ => untrop_injective <| zero_zsmul _ zpow_succ' := fun _ _ => untrop_injective <| SubNegMonoid.zsmul_succ' _ _ zpow_neg' := fun _ _ => untrop_injective <| SubNegMonoid.zsmul_neg' _ _ } instance [AddCommGroup R] : CommGroup (Tropical R) := { instGroupTropical with mul_comm := fun _ _ => untrop_injective (add_comm _ _) } @[simp] theorem untrop_zpow [AddGroup R] (x : Tropical R) (n : ℤ) : untrop (x ^ n) = n • untrop x := rfl @[simp] theorem trop_zsmul [AddGroup R] (x : R) (n : ℤ) : trop (n • x) = trop x ^ n := rfl end Monoid section Distrib instance mulLeftMono [LE R] [Add R] [AddLeftMono R] : MulLeftMono (Tropical R) := ⟨fun _ y z h => add_le_add_left (show untrop y ≤ untrop z from h) _⟩ instance mulRightMono [LE R] [Add R] [AddRightMono R] : MulRightMono (Tropical R) := ⟨fun _ y z h => add_le_add_right (show untrop y ≤ untrop z from h) _⟩ instance addLeftMono [LinearOrder R] : AddLeftMono (Tropical R) := ⟨fun x y z h => by rcases le_total x y with hx | hy · rw [add_eq_left hx, add_eq_left (hx.trans h)] · rw [add_eq_right hy] rcases le_total x z with hx | hx · rwa [add_eq_left hx] · rwa [add_eq_right hx]⟩ instance mulLeftStrictMono [LT R] [Add R] [AddLeftStrictMono R] : MulLeftStrictMono (Tropical R) := ⟨fun _ _ _ h => add_lt_add_left (untrop_lt_iff.2 h) _⟩ instance mulRightStrictMono [Preorder R] [Add R] [AddRightStrictMono R] : MulRightStrictMono (Tropical R) := ⟨fun _ y z h => add_lt_add_right (show untrop y < untrop z from h) _⟩ instance instDistribTropical [LinearOrder R] [Add R] [AddLeftMono R] [AddRightMono R] : Distrib (Tropical R) where left_distrib _ _ _ := untrop_injective (min_add_add_left _ _ _).symm right_distrib _ _ _ := untrop_injective (min_add_add_right _ _ _).symm @[simp] theorem add_pow [LinearOrder R] [AddMonoid R] [AddLeftMono R] [AddRightMono R] (x y : Tropical R) (n : ℕ) : (x + y) ^ n = x ^ n + y ^ n := by rcases le_total x y with h | h · rw [add_eq_left h, add_eq_left (pow_le_pow_left' h _)] · rw [add_eq_right h, add_eq_right (pow_le_pow_left' h _)] end Distrib section Semiring variable [LinearOrderedAddCommMonoidWithTop R] instance : CommSemiring (Tropical R) := { instAddMonoidWithOneTropical, instDistribTropical, instAddCommMonoidTropical, instCommMonoidTropical with zero_mul := fun _ => untrop_injective (by simp [top_add]) mul_zero := fun _ => untrop_injective (by simp [add_top]) } @[simp] theorem succ_nsmul {R} [LinearOrder R] [OrderTop R] (x : Tropical R) (n : ℕ) : (n + 1) • x = x := by induction n with | zero => simp | succ n IH => rw [add_nsmul, IH, one_nsmul, add_self] -- TODO: find/create the right classes to make this hold (for enat, ennreal, etc) -- Requires `zero_eq_bot` to be true -- lemma add_eq_zero_iff {a b : tropical R} : -- a + b = 1 ↔ a = 1 ∨ b = 1 := sorry theorem mul_eq_zero_iff {R : Type*} [AddCommMonoid R] {a b : Tropical (WithTop R)} : a * b = 0 ↔ a = 0 ∨ b = 0 := by simp [← untrop_inj_iff, WithTop.add_eq_top] instance {R : Type*} [AddCommMonoid R] : NoZeroDivisors (Tropical (WithTop R)) := ⟨mul_eq_zero_iff.mp⟩ end Semiring end Tropical
.lake/packages/mathlib/Mathlib/Algebra/Tropical/BigOperators.lean
import Mathlib.Data.List.MinMax import Mathlib.Algebra.Tropical.Basic import Mathlib.Order.ConditionallyCompleteLattice.Finset import Mathlib.Algebra.BigOperators.Group.Finset.Basic /-! # Tropicalization of finitary operations This file provides the "big-op" or notation-based finitary operations on tropicalized types. This allows easy conversion between sums to Infs and prods to sums. Results here are important for expressing that evaluation of tropical polynomials are the minimum over a finite piecewise collection of linear functions. ## Main declarations * `untrop_sum` ## Implementation notes No concrete (semi)ring is used here, only ones with inferable order/lattice structure, to support `Real`, `Rat`, `EReal`, and others (`ERat` is not yet defined). Minima over `List α` are defined as producing a value in `WithTop α` so proofs about lists do not directly transfer to minima over multisets or finsets. -/ variable {R S : Type*} open Tropical Finset theorem List.trop_sum [AddMonoid R] (l : List R) : trop l.sum = List.prod (l.map trop) := by induction l with | nil => simp | cons hd tl IH => simp [← IH] theorem Multiset.trop_sum [AddCommMonoid R] (s : Multiset R) : trop s.sum = Multiset.prod (s.map trop) := Quotient.inductionOn s (by simpa using List.trop_sum) theorem trop_sum [AddCommMonoid R] (s : Finset S) (f : S → R) : trop (∑ i ∈ s, f i) = ∏ i ∈ s, trop (f i) := by convert Multiset.trop_sum (s.val.map f) simp only [Multiset.map_map, Function.comp_apply] rfl theorem List.untrop_prod [AddMonoid R] (l : List (Tropical R)) : untrop l.prod = List.sum (l.map untrop) := by induction l with | nil => simp | cons hd tl IH => simp [← IH] theorem Multiset.untrop_prod [AddCommMonoid R] (s : Multiset (Tropical R)) : untrop s.prod = Multiset.sum (s.map untrop) := Quotient.inductionOn s (by simpa using List.untrop_prod) theorem untrop_prod [AddCommMonoid R] (s : Finset S) (f : S → Tropical R) : untrop (∏ i ∈ s, f i) = ∑ i ∈ s, untrop (f i) := by convert Multiset.untrop_prod (s.val.map f) simp only [Multiset.map_map, Function.comp_apply] rfl theorem List.trop_minimum [LinearOrder R] (l : List R) : trop l.minimum = List.sum (l.map (trop ∘ WithTop.some)) := by induction l with | nil => simp | cons hd tl IH => simp [List.minimum_cons, ← IH] theorem Multiset.trop_inf [LinearOrder R] [OrderTop R] (s : Multiset R) : trop s.inf = Multiset.sum (s.map trop) := by induction s using Multiset.induction with | empty => simp | cons s x IH => simp [← IH] theorem Finset.trop_inf [LinearOrder R] [OrderTop R] (s : Finset S) (f : S → R) : trop (s.inf f) = ∑ i ∈ s, trop (f i) := by convert Multiset.trop_inf (s.val.map f) simp only [Multiset.map_map, Function.comp_apply] rfl theorem trop_sInf_image [ConditionallyCompleteLinearOrder R] (s : Finset S) (f : S → WithTop R) : trop (sInf (f '' s)) = ∑ i ∈ s, trop (f i) := by rcases s.eq_empty_or_nonempty with (rfl | h) · simp only [Set.image_empty, coe_empty, sum_empty, WithTop.sInf_empty, trop_top] rw [← inf'_eq_csInf_image _ h, inf'_eq_inf, s.trop_inf] theorem trop_iInf [ConditionallyCompleteLinearOrder R] [Fintype S] (f : S → WithTop R) : trop (⨅ i : S, f i) = ∑ i : S, trop (f i) := by rw [iInf, ← Set.image_univ, ← coe_univ, trop_sInf_image] theorem Multiset.untrop_sum [LinearOrder R] [OrderTop R] (s : Multiset (Tropical R)) : untrop s.sum = Multiset.inf (s.map untrop) := by induction s using Multiset.induction with | empty => simp | cons s x IH => simp only [sum_cons, untrop_add, map_cons, inf_cons, ← IH] theorem Finset.untrop_sum' [LinearOrder R] [OrderTop R] (s : Finset S) (f : S → Tropical R) : untrop (∑ i ∈ s, f i) = s.inf (untrop ∘ f) := by convert Multiset.untrop_sum (s.val.map f) simp only [Multiset.map_map, Function.comp_apply, inf_def] theorem untrop_sum_eq_sInf_image [ConditionallyCompleteLinearOrder R] (s : Finset S) (f : S → Tropical (WithTop R)) : untrop (∑ i ∈ s, f i) = sInf (untrop ∘ f '' s) := by rcases s.eq_empty_or_nonempty with (rfl | h) · simp only [Set.image_empty, coe_empty, sum_empty, WithTop.sInf_empty, untrop_zero] · rw [← inf'_eq_csInf_image _ h, inf'_eq_inf, Finset.untrop_sum'] theorem untrop_sum [ConditionallyCompleteLinearOrder R] [Fintype S] (f : S → Tropical (WithTop R)) : untrop (∑ i : S, f i) = ⨅ i : S, untrop (f i) := by rw [iInf, ← Set.image_univ, ← coe_univ, untrop_sum_eq_sInf_image, Function.comp_def] /-- Note we cannot use `i ∈ s` instead of `i : s` here as it is simply not true on conditionally complete lattices! -/ theorem Finset.untrop_sum [ConditionallyCompleteLinearOrder R] (s : Finset S) (f : S → Tropical (WithTop R)) : untrop (∑ i ∈ s, f i) = ⨅ i : s, untrop (f i) := by simpa [← _root_.untrop_sum] using (sum_attach _ _).symm
.lake/packages/mathlib/Mathlib/Algebra/Tropical/Lattice.lean
import Mathlib.Algebra.Tropical.Basic import Mathlib.Order.ConditionallyCompleteLattice.Basic /-! # Order on tropical algebraic structure This file defines the orders induced on tropical algebraic structures by the underlying type. ## Main declarations * `ConditionallyCompleteLattice (Tropical R)` * `ConditionallyCompleteLinearOrder (Tropical R)` ## Implementation notes The order induced is the definitionally equal underlying order, which makes the proofs and constructions quicker to implement. -/ variable {R S : Type*} open Tropical instance instSemilatticeInfTropical [SemilatticeInf R] : SemilatticeInf (Tropical R) := { Tropical.instPartialOrderTropical with inf := fun x y ↦ trop (untrop x ⊓ untrop y) le_inf := fun _ _ _ ↦ @SemilatticeInf.le_inf R _ _ _ _ inf_le_left := fun _ _ ↦ inf_le_left inf_le_right := fun _ _ ↦ inf_le_right } instance instSemilatticeSupTropical [SemilatticeSup R] : SemilatticeSup (Tropical R) := { Tropical.instPartialOrderTropical with sup := fun x y ↦ trop (untrop x ⊔ untrop y) sup_le := fun _ _ _ ↦ @SemilatticeSup.sup_le R _ _ _ _ le_sup_left := fun _ _ ↦ le_sup_left le_sup_right := fun _ _ ↦ le_sup_right } instance instLatticeTropical [Lattice R] : Lattice (Tropical R) := { instSemilatticeInfTropical, instSemilatticeSupTropical with } instance [SupSet R] : SupSet (Tropical R) where sSup s := trop (sSup (untrop '' s)) instance [InfSet R] : InfSet (Tropical R) where sInf s := trop (sInf (untrop '' s)) instance instConditionallyCompleteLatticeTropical [ConditionallyCompleteLattice R] : ConditionallyCompleteLattice (Tropical R) := { instLatticeTropical with le_csSup := fun _s _x hs hx ↦ le_csSup (untrop_monotone.map_bddAbove hs) (Set.mem_image_of_mem untrop hx) csSup_le := fun _s _x hs hx ↦ csSup_le (hs.image untrop) (untrop_monotone.mem_upperBounds_image hx) le_csInf := fun _s _x hs hx ↦ le_csInf (hs.image untrop) (untrop_monotone.mem_lowerBounds_image hx) csInf_le := fun _s _x hs hx ↦ csInf_le (untrop_monotone.map_bddBelow hs) (Set.mem_image_of_mem untrop hx) } instance [ConditionallyCompleteLinearOrder R] : ConditionallyCompleteLinearOrder (Tropical R) := { instConditionallyCompleteLatticeTropical, Tropical.instLinearOrderTropical with csSup_of_not_bddAbove := by intro s hs have : Set.range untrop = (Set.univ : Set R) := Equiv.range_eq_univ tropEquiv.symm simp only [sSup, Set.image_empty, trop_inj_iff] apply csSup_of_not_bddAbove contrapose! hs change BddAbove (tropOrderIso.symm '' s) at hs exact tropOrderIso.symm.bddAbove_image.1 hs csInf_of_not_bddBelow := by intro s hs have : Set.range untrop = (Set.univ : Set R) := Equiv.range_eq_univ tropEquiv.symm simp only [sInf, Set.image_empty, trop_inj_iff] apply csInf_of_not_bddBelow contrapose! hs change BddBelow (tropOrderIso.symm '' s) at hs exact tropOrderIso.symm.bddBelow_image.1 hs }
.lake/packages/mathlib/Mathlib/Algebra/FreeMonoid/Count.lean
import Mathlib.Algebra.FreeMonoid.Basic import Mathlib.Algebra.Group.TypeTags.Basic /-! # `List.count` as a bundled homomorphism In this file we define `FreeMonoid.countP`, `FreeMonoid.count`, `FreeAddMonoid.countP`, and `FreeAddMonoid.count`. These are `List.countP` and `List.count` bundled as multiplicative and additive homomorphisms from `FreeMonoid` and `FreeAddMonoid`. We do not use `to_additive` too much because it can't map `Multiplicative ℕ` to `ℕ`. -/ variable {α : Type*} (p : α → Prop) [DecidablePred p] namespace FreeMonoid /-- `List.countP` lifted to free monoids -/ @[to_additive /-- `List.countP` lifted to free additive monoids -/] def countP' (l : FreeMonoid α) : ℕ := l.toList.countP p @[to_additive] lemma countP'_one : (1 : FreeMonoid α).countP' p = 0 := rfl @[to_additive] lemma countP'_mul (l₁ l₂ : FreeMonoid α) : (l₁ * l₂).countP' p = l₁.countP' p + l₂.countP' p := by dsimp [countP'] simp only [List.countP_append] /-- `List.countP` as a bundled multiplicative monoid homomorphism. -/ def countP : FreeMonoid α →* Multiplicative ℕ where toFun := .ofAdd ∘ FreeMonoid.countP' p map_one' := by simp [countP'_one p] map_mul' x y := by simp [countP'_mul p] theorem countP_apply (l : FreeMonoid α) : l.countP p = .ofAdd (l.toList.countP p) := rfl lemma countP_of (x : α) : (of x).countP p = if p x then Multiplicative.ofAdd 1 else Multiplicative.ofAdd 0 := by rw [countP_apply, toList_of, List.countP_singleton, apply_ite (Multiplicative.ofAdd)] simp only [decide_eq_true_eq] /-- `List.count` as a bundled additive monoid homomorphism. -/ def count [DecidableEq α] (x : α) : FreeMonoid α →* Multiplicative ℕ := countP (· = x) theorem count_apply [DecidableEq α] (x : α) (l : FreeAddMonoid α) : count x l = Multiplicative.ofAdd (l.toList.count x) := rfl theorem count_of [DecidableEq α] (x y : α) : count x (of y) = Pi.mulSingle (M := fun _ => Multiplicative ℕ) x (Multiplicative.ofAdd 1) y := by simp only [count, eq_comm, countP_of, ofAdd_zero, Pi.mulSingle_apply] end FreeMonoid namespace FreeAddMonoid /-- `List.countP` as a bundled additive monoid homomorphism. -/ def countP : FreeAddMonoid α →+ ℕ where toFun := FreeAddMonoid.countP' p map_zero' := countP'_zero p map_add' := countP'_add p theorem countP_apply (l : FreeAddMonoid α) : l.countP p = l.toList.countP p := rfl theorem countP_of (x : α) : countP p (of x) = if p x then 1 else 0 := by rw [countP_apply, toList_of, List.countP_singleton] simp only [decide_eq_true_eq] /-- `List.count` as a bundled additive monoid homomorphism. -/ -- Porting note: was (x = ·) def count [DecidableEq α] (x : α) : FreeAddMonoid α →+ ℕ := countP (· = x) lemma count_of [DecidableEq α] (x y : α) : count x (of y) = (Pi.single x 1 : α → ℕ) y := by dsimp [count] rw [countP_of] simp [Pi.single, Function.update] theorem count_apply [DecidableEq α] (x : α) (l : FreeAddMonoid α) : l.count x = l.toList.count x := rfl end FreeAddMonoid
.lake/packages/mathlib/Mathlib/Algebra/FreeMonoid/Basic.lean
import Mathlib.Algebra.Group.Action.Defs import Mathlib.Algebra.Group.Units.Defs import Mathlib.Algebra.BigOperators.Group.List.Basic import Mathlib.Algebra.Group.Equiv.Defs /-! # Free monoid over a given alphabet ## Main definitions * `FreeMonoid α`: free monoid over alphabet `α`; defined as a synonym for `List α` with multiplication given by `(++)`. * `FreeMonoid.of`: embedding `α → FreeMonoid α` sending each element `x` to `[x]`; * `FreeMonoid.lift`: natural equivalence between `α → M` and `FreeMonoid α →* M` * `FreeMonoid.map`: embedding of `α → β` into `FreeMonoid α →* FreeMonoid β` given by `List.map`. -/ variable {α : Type*} {β : Type*} {γ : Type*} {M : Type*} [Monoid M] {N : Type*} [Monoid N] /-- If `α` is a type, then `FreeMonoid α` is the free monoid generated by `α`. This is a monoid equipped with a function `FreeMonoid.of : α → FreeMonoid α` which has the following universal property: if `M` is any monoid, and `f : α → M` is any function, then this function is the composite of `FreeMonoid.of` and a unique monoid homomorphism `FreeMonoid.lift f : FreeMonoid α →* M`. A typical element of `FreeMonoid α` is a formal product of elements of `α`. For example if `x` and `y` are terms of type `α` then `x * y * y * x` is a "typical" element of `FreeMonoid α`. In particular if `α` is empty then `FreeMonoid α` is isomorphic to the trivial monoid, and if `α` has one term then `FreeMonoid α` is isomorphic to `Multiplicative ℕ`. If `α` has two or more terms then `FreeMonoid α` is not commutative. One can think of `FreeMonoid α` as the type of lists of `α`, with multiplication given by concatenation. -/ @[to_additive /-- If `α` is a type, then `FreeAddMonoid α` is the free additive monoid generated by `α`. This is a monoid equipped with a function `FreeAddMonoid.of : α → FreeAddMonoid α` which has the following universal property: if `M` is any monoid, and `f : α → M` is any function, then this function is the composite of `FreeAddMonoid.of` and a unique monoid homomorphism `FreeAddMonoid.lift f : FreeAddMonoid α →+ M`. A typical element of `FreeAddMonoid α` is a formal sum of elements of `α`. For example if `x` and `y` are terms of type `α` then `x + y + y + x` is a "typical" element of `FreeAddMonoid α`. In particular if `α` is empty then `FreeAddMonoid α` is isomorphic to the trivial monoid, and if `α` has one term then `FreeAddMonoid α` is isomorphic to `ℕ`. If `α` has two or more terms then `FreeAddMonoid α` is not commutative. One can think of `FreeAddMonoid α` as the type of lists of `α`, with addition given by concatenation. -/] def FreeMonoid (α) := List α namespace FreeMonoid /-- The identity equivalence between `FreeMonoid α` and `List α`. -/ @[to_additive /-- The identity equivalence between `FreeAddMonoid α` and `List α`. -/] def toList : FreeMonoid α ≃ List α := Equiv.refl _ /-- The identity equivalence between `List α` and `FreeMonoid α`. -/ @[to_additive /-- The identity equivalence between `List α` and `FreeAddMonoid α`. -/] def ofList : List α ≃ FreeMonoid α := Equiv.refl _ @[to_additive (attr := simp)] theorem toList_symm : (@toList α).symm = ofList := rfl @[to_additive (attr := simp)] theorem ofList_symm : (@ofList α).symm = toList := rfl @[to_additive (attr := simp)] theorem toList_ofList (l : List α) : toList (ofList l) = l := rfl @[to_additive (attr := simp)] theorem ofList_toList (xs : FreeMonoid α) : ofList (toList xs) = xs := rfl @[to_additive (attr := simp)] theorem toList_comp_ofList : @toList α ∘ ofList = id := rfl @[to_additive (attr := simp)] theorem ofList_comp_toList : @ofList α ∘ toList = id := rfl @[to_additive] instance : CancelMonoid (FreeMonoid α) where one := ofList [] mul x y := ofList (toList x ++ toList y) mul_one := List.append_nil one_mul := List.nil_append mul_assoc := List.append_assoc mul_left_cancel _ _ _ := List.append_cancel_left mul_right_cancel _ _ _ := List.append_cancel_right @[to_additive] instance : Inhabited (FreeMonoid α) := ⟨1⟩ @[to_additive] instance [IsEmpty α] : Unique (FreeMonoid α) := inferInstanceAs <| Unique (List α) @[to_additive (attr := simp)] theorem toList_one : toList (1 : FreeMonoid α) = [] := rfl @[to_additive (attr := simp)] theorem ofList_nil : ofList ([] : List α) = 1 := rfl -- TODO: this statement uses defeq abuse, but so does much of the downstream use of `FreeMonoid`. -- This should be removed from the simp set and deprecated once those defeq abuses are cleaned up. @[to_additive (attr := simp)] theorem toList_nil : toList ([] : FreeMonoid α) = [] := rfl -- TODO: this statement uses defeq abuse, but so does much of the downstream use of `FreeMonoid`. -- This should be removed from the simp set and deprecated once those defeq abuses are cleaned up. @[to_additive (attr := simp)] theorem toList_cons (x : α) (xs : FreeMonoid α) : toList (x :: xs) = x :: toList xs := rfl @[to_additive (attr := simp)] theorem toList_mul (xs ys : FreeMonoid α) : toList (xs * ys) = toList xs ++ toList ys := rfl @[to_additive (attr := simp)] theorem ofList_append (xs ys : List α) : ofList (xs ++ ys) = ofList xs * ofList ys := rfl @[to_additive (attr := simp)] theorem toList_prod (xs : List (FreeMonoid α)) : toList xs.prod = (xs.map toList).flatten := by induction xs <;> simp [*] @[to_additive (attr := simp)] theorem ofList_flatten (xs : List (List α)) : ofList xs.flatten = (xs.map ofList).prod := toList.injective <| by simp /-- Embeds an element of `α` into `FreeMonoid α` as a singleton list. -/ @[to_additive /-- Embeds an element of `α` into `FreeAddMonoid α` as a singleton list. -/] def of (x : α) : FreeMonoid α := ofList [x] @[to_additive (attr := simp)] theorem toList_of (x : α) : toList (of x) = [x] := rfl @[to_additive] theorem ofList_singleton (x : α) : ofList [x] = of x := rfl @[to_additive (attr := simp)] theorem ofList_cons (x : α) (xs : List α) : ofList (x :: xs) = of x * ofList xs := rfl @[to_additive] theorem toList_of_mul (x : α) (xs : FreeMonoid α) : toList (of x * xs) = x :: toList xs := rfl @[to_additive] theorem of_injective : Function.Injective (@of α) := List.singleton_injective /-! ### Length -/ section Length variable {a : FreeMonoid α} /-- The length of a free monoid element: 1.length = 0 and (a * b).length = a.length + b.length -/ @[to_additive /-- The length of an additive free monoid element: 1.length = 0 and (a + b).length = a.length + b.length -/] def length (a : FreeMonoid α) : ℕ := a.toList.length @[to_additive (attr := simp)] theorem length_one : length (1 : FreeMonoid α) = 0 := rfl @[to_additive (attr := simp)] theorem length_eq_zero : length a = 0 ↔ a = 1 := List.length_eq_zero_iff @[to_additive (attr := simp)] theorem length_of (m : α) : length (of m) = 1 := rfl @[to_additive FreeAddMonoid.length_eq_one] theorem length_eq_one : length a = 1 ↔ ∃ m, a = FreeMonoid.of m := List.length_eq_one_iff @[to_additive] theorem length_eq_two {v : FreeMonoid α} : v.length = 2 ↔ ∃ c d, v = FreeMonoid.of c * FreeMonoid.of d := List.length_eq_two @[to_additive] theorem length_eq_three {v : FreeMonoid α} : v.length = 3 ↔ ∃ (a b c : α), v = of a * of b * of c := List.length_eq_three @[to_additive] theorem length_eq_four {v : FreeMonoid α} : v.length = 4 ↔ ∃ (a b c d : α), v = of a * of b * of c * of d := List.length_eq_four @[to_additive (attr := simp)] theorem length_mul (a b : FreeMonoid α) : (a * b).length = a.length + b.length := List.length_append @[to_additive (attr := simp)] theorem of_ne_one (a : α) : of a ≠ 1 := by intro h have := congrArg FreeMonoid.length h simp only [length_of, length_one, Nat.succ_ne_self] at this @[to_additive (attr := simp)] theorem one_ne_of (a : α) : 1 ≠ of a := of_ne_one _ |>.symm end Length section Mem variable {m : α} /-- Membership in a free monoid element -/ @[to_additive /-- Membership in a free monoid element -/] def mem (a : FreeMonoid α) (m : α) := m ∈ toList a @[to_additive] instance : Membership α (FreeMonoid α) := ⟨mem⟩ @[to_additive] theorem notMem_one : m ∉ (1 : FreeMonoid α) := List.not_mem_nil @[deprecated (since := "2025-05-23")] alias _root_.FreeAddMonoid.not_mem_zero := FreeAddMonoid.notMem_zero @[to_additive existing, deprecated (since := "2025-05-23")] alias not_mem_one := notMem_one @[to_additive (attr := simp)] theorem mem_of {n : α} : m ∈ of n ↔ m = n := List.mem_singleton @[to_additive] theorem mem_of_self : m ∈ of m := List.mem_singleton_self _ @[to_additive (attr := simp)] theorem mem_mul {a b : FreeMonoid α} : m ∈ (a * b) ↔ m ∈ a ∨ m ∈ b := List.mem_append end Mem /-- Recursor for `FreeMonoid` using `1` and `FreeMonoid.of x * xs` instead of `[]` and `x :: xs`. -/ @[to_additive (attr := elab_as_elim, induction_eliminator) /-- Recursor for `FreeAddMonoid` using `0` and `FreeAddMonoid.of x + xs` instead of `[]` and `x :: xs`. -/] -- Porting note: change from `List.recOn` to `List.rec` since only the latter is computable def recOn {C : FreeMonoid α → Sort*} (xs : FreeMonoid α) (h0 : C 1) (ih : ∀ x xs, C xs → C (of x * xs)) : C xs := List.rec h0 ih xs @[to_additive (attr := simp)] theorem recOn_one {C : FreeMonoid α → Sort*} (h0 : C 1) (ih : ∀ x xs, C xs → C (of x * xs)) : @recOn α C 1 h0 ih = h0 := rfl @[to_additive (attr := simp)] theorem recOn_of_mul {C : FreeMonoid α → Sort*} (x : α) (xs : FreeMonoid α) (h0 : C 1) (ih : ∀ x xs, C xs → C (of x * xs)) : @recOn α C (of x * xs) h0 ih = ih x xs (recOn xs h0 ih) := rfl /-! ### Induction -/ section induction_principles /-- An induction principle on free monoids, with cases for `1`, `FreeMonoid.of` and `*`. -/ @[to_additive (attr := elab_as_elim, induction_eliminator) /-- An induction principle on free monoids, with cases for `0`, `FreeAddMonoid.of` and `+`. -/] protected theorem inductionOn {C : FreeMonoid α → Prop} (z : FreeMonoid α) (one : C 1) (of : ∀ (x : α), C (FreeMonoid.of x)) (mul : ∀ (x y : FreeMonoid α), C x → C y → C (x * y)) : C z := List.rec one (fun _ _ ih => mul [_] _ (of _) ih) z /-- An induction principle for free monoids which mirrors induction on lists, with cases analogous to the empty list and cons -/ @[to_additive (attr := elab_as_elim) /-- An induction principle for free monoids which mirrors induction on lists, with cases analogous to the empty list and cons -/] protected theorem inductionOn' {p : FreeMonoid α → Prop} (a : FreeMonoid α) (one : p (1 : FreeMonoid α)) (mul_of : ∀ b a, p a → p (of b * a)) : p a := List.rec one (fun _ _ tail_ih => mul_of _ _ tail_ih) a end induction_principles /-- A version of `List.cases_on` for `FreeMonoid` using `1` and `FreeMonoid.of x * xs` instead of `[]` and `x :: xs`. -/ @[to_additive (attr := elab_as_elim, cases_eliminator) /-- A version of `List.casesOn` for `FreeAddMonoid` using `0` and `FreeAddMonoid.of x + xs` instead of `[]` and `x :: xs`. -/] def casesOn {C : FreeMonoid α → Sort*} (xs : FreeMonoid α) (h0 : C 1) (ih : ∀ x xs, C (of x * xs)) : C xs := List.casesOn xs h0 ih @[to_additive (attr := simp)] theorem casesOn_one {C : FreeMonoid α → Sort*} (h0 : C 1) (ih : ∀ x xs, C (of x * xs)) : @casesOn α C 1 h0 ih = h0 := rfl @[to_additive (attr := simp)] theorem casesOn_of_mul {C : FreeMonoid α → Sort*} (x : α) (xs : FreeMonoid α) (h0 : C 1) (ih : ∀ x xs, C (of x * xs)) : @casesOn α C (of x * xs) h0 ih = ih x xs := rfl @[to_additive (attr := ext)] theorem hom_eq ⦃f g : FreeMonoid α →* M⦄ (h : ∀ x, f (of x) = g (of x)) : f = g := MonoidHom.ext fun l ↦ recOn l (f.map_one.trans g.map_one.symm) (fun x xs hxs ↦ by simp only [h, hxs, MonoidHom.map_mul]) /-- A variant of `List.prod` that has `[x].prod = x` true definitionally. The purpose is to make `FreeMonoid.lift_eval_of` true by `rfl`. -/ @[to_additive /-- A variant of `List.sum` that has `[x].sum = x` true definitionally. The purpose is to make `FreeAddMonoid.lift_eval_of` true by `rfl`. -/] def prodAux {M} [Monoid M] : List M → M | [] => 1 | (x :: xs) => List.foldl (· * ·) x xs @[to_additive] lemma prodAux_eq : ∀ l : List M, FreeMonoid.prodAux l = l.prod | [] => rfl | (_ :: xs) => by simp [prodAux, List.prod_eq_foldl] /-- Equivalence between maps `α → M` and monoid homomorphisms `FreeMonoid α →* M`. -/ @[to_additive /-- Equivalence between maps `α → A` and additive monoid homomorphisms `FreeAddMonoid α →+ A`. -/] def lift : (α → M) ≃ (FreeMonoid α →* M) where toFun f := { toFun := fun l ↦ prodAux ((toList l).map f) map_one' := rfl map_mul' := fun _ _ ↦ by simp only [prodAux_eq, toList_mul, List.map_append, List.prod_append] } invFun f x := f (of x) @[to_additive (attr := simp)] theorem lift_ofList (f : α → M) (l : List α) : lift f (ofList l) = (l.map f).prod := prodAux_eq _ @[to_additive (attr := simp)] theorem lift_symm_apply (f : FreeMonoid α →* M) : lift.symm f = f ∘ of := rfl @[to_additive] theorem lift_apply (f : α → M) (l : FreeMonoid α) : lift f l = ((toList l).map f).prod := prodAux_eq _ @[to_additive] theorem lift_comp_of (f : α → M) : lift f ∘ of = f := rfl @[to_additive (attr := simp)] theorem lift_eval_of (f : α → M) (x : α) : lift f (of x) = f x := rfl @[to_additive (attr := simp)] theorem lift_restrict (f : FreeMonoid α →* M) : lift (f ∘ of) = f := lift.apply_symm_apply f @[to_additive] theorem comp_lift (g : M →* N) (f : α → M) : g.comp (lift f) = lift (g ∘ f) := by ext simp @[to_additive] theorem hom_map_lift (g : M →* N) (f : α → M) (x : FreeMonoid α) : g (lift f x) = lift (g ∘ f) x := DFunLike.ext_iff.1 (comp_lift g f) x /-- Define a multiplicative action of `FreeMonoid α` on `β`. -/ @[to_additive /-- Define an additive action of `FreeAddMonoid α` on `β`. -/] def mkMulAction (f : α → β → β) : MulAction (FreeMonoid α) β where smul l b := l.toList.foldr f b one_smul _ := rfl mul_smul _ _ _ := List.foldr_append @[to_additive] theorem smul_def (f : α → β → β) (l : FreeMonoid α) (b : β) : haveI := mkMulAction f l • b = l.toList.foldr f b := rfl @[to_additive] theorem ofList_smul (f : α → β → β) (l : List α) (b : β) : haveI := mkMulAction f ofList l • b = l.foldr f b := rfl @[to_additive (attr := simp)] theorem of_smul (f : α → β → β) (x : α) (y : β) : (haveI := mkMulAction f of x • y) = f x y := rfl /-! ### map -/ section Map variable {f : α → β} {a b : FreeMonoid α} /-- The unique monoid homomorphism `FreeMonoid α →* FreeMonoid β` that sends each `of x` to `of (f x)`. -/ @[to_additive /-- The unique additive monoid homomorphism `FreeAddMonoid α →+ FreeAddMonoid β` that sends each `of x` to `of (f x)`. -/] def map (f : α → β) : FreeMonoid α →* FreeMonoid β where toFun l := ofList <| l.toList.map f map_one' := rfl map_mul' _ _ := List.map_append @[to_additive (attr := simp)] theorem map_of (f : α → β) (x : α) : map f (of x) = of (f x) := rfl @[to_additive] theorem mem_map {m : β} : m ∈ map f a ↔ ∃ n ∈ a, f n = m := List.mem_map @[to_additive] theorem map_map {α₁ : Type*} {g : α₁ → α} {x : FreeMonoid α₁} : map f (map g x) = map (f ∘ g) x := by unfold map simp only [MonoidHom.coe_mk, OneHom.coe_mk, toList_ofList, List.map_map] @[to_additive (attr := simp)] theorem toList_map (f : α → β) (xs : FreeMonoid α) : toList (map f xs) = xs.toList.map f := rfl @[to_additive] theorem ofList_map (f : α → β) (xs : List α) : ofList (xs.map f) = map f (ofList xs) := rfl @[to_additive] theorem lift_of_comp_eq_map (f : α → β) : (lift fun x ↦ of (f x)) = map f := hom_eq fun _ ↦ rfl @[to_additive] theorem map_comp (g : β → γ) (f : α → β) : map (g ∘ f) = (map g).comp (map f) := hom_eq fun _ ↦ rfl @[to_additive (attr := simp)] theorem map_id : map (@id α) = MonoidHom.id (FreeMonoid α) := hom_eq fun _ ↦ rfl @[to_additive (attr := simp)] theorem map_symm_apply_map_eq {x : FreeMonoid α} (e : α ≃ β) : (map ⇑e.symm) ((map ⇑e) x) = x := by simp [map_map] @[to_additive (attr := simp)] theorem map_apply_map_symm_eq {x : FreeMonoid β} (e : α ≃ β) : (map ⇑e) ((map ⇑e.symm) x) = x := by simp [map_map] /-- The only invertible element of the free monoid is 1; this instance enables `units_eq_one`. -/ @[to_additive] instance uniqueUnits : Unique (FreeMonoid α)ˣ where uniq u := Units.ext <| toList.injective <| have : toList u.val ++ toList u.inv = [] := DFunLike.congr_arg toList u.val_inv (List.append_eq_nil_iff.mp this).1 @[to_additive (attr := simp)] theorem map_surjective {f : α → β} : Function.Surjective (map f) ↔ Function.Surjective f := by constructor · intro fs d rcases fs (FreeMonoid.of d) with ⟨b, hb⟩ induction b using FreeMonoid.inductionOn' with | one => have H := congr_arg length hb simp only [length_one, length_of, Nat.zero_ne_one, map_one] at H | mul_of head _ _ => simp only [map_mul, map_of] at hb use head have H := congr_arg length hb simp only [length_mul, length_of, add_eq_left, length_eq_zero] at H rw [H, mul_one] at hb exact FreeMonoid.of_injective hb intro fs d induction d using FreeMonoid.inductionOn' with | one => use 1; rfl | mul_of head tail ih => specialize fs head rcases fs with ⟨a, rfl⟩ rcases ih with ⟨b, rfl⟩ use FreeMonoid.of a * b rfl end Map /-! ### reverse -/ section Reverse /-- reverses the symbols in a free monoid element -/ @[to_additive /-- reverses the symbols in an additive free monoid element -/] def reverse : FreeMonoid α → FreeMonoid α := List.reverse @[to_additive (attr := simp)] theorem reverse_of (a : α) : reverse (of a) = of a := rfl @[to_additive] theorem reverse_mul {a b : FreeMonoid α} : reverse (a * b) = reverse b * reverse a := List.reverse_append @[to_additive (attr := simp)] theorem reverse_reverse {a : FreeMonoid α} : reverse (reverse a) = a := by apply List.reverse_reverse @[to_additive (attr := simp)] theorem length_reverse {a : FreeMonoid α} : a.reverse.length = a.length := List.length_reverse end Reverse section IsomorphicTypes variable {α β : Type*} /-- free monoids over isomorphic types are isomorphic -/ @[to_additive /-- if two types are isomorphic, the additive free monoids over those types are isomorphic -/] def freeMonoidCongr (e : α ≃ β) : FreeMonoid α ≃* FreeMonoid β where toFun := FreeMonoid.map ⇑e invFun := FreeMonoid.map ⇑e.symm left_inv _ := map_symm_apply_map_eq e right_inv _ := map_apply_map_symm_eq e map_mul' := by simp [map_mul] @[to_additive (attr := simp)] theorem freeMonoidCongr_of (e : α ≃ β) (a : α) : freeMonoidCongr e (of a) = of (e a) := rfl @[to_additive (attr := simp)] theorem freeMonoidCongr_symm_of (e : α ≃ β) (b : β) : freeMonoidCongr e.symm (of b) = of (e.symm b) := rfl end IsomorphicTypes end FreeMonoid
.lake/packages/mathlib/Mathlib/Algebra/FreeMonoid/Symbols.lean
import Mathlib.Algebra.FreeMonoid.Basic import Mathlib.Data.Finset.Lattice.Lemmas /-! # The finite set of symbols in a FreeMonoid element This is separated from the main FreeMonoid file, as it imports the finiteness hierarchy -/ variable {α : Type*} [DecidableEq α] namespace FreeMonoid /-- the set of unique symbols in a free monoid element -/ @[to_additive /-- The set of unique symbols in an additive free monoid element -/] def symbols (a : FreeMonoid α) : Finset α := List.toFinset a @[to_additive (attr := simp)] theorem symbols_one : symbols (1 : FreeMonoid α) = ∅ := rfl @[to_additive (attr := simp)] theorem symbols_of {m : α} : symbols (of m) = {m} := rfl @[to_additive (attr := simp)] theorem symbols_mul {a b : FreeMonoid α} : symbols (a * b) = symbols a ∪ symbols b := List.toFinset_append @[to_additive (attr := simp)] theorem mem_symbols {m : α} {a : FreeMonoid α} : m ∈ symbols a ↔ m ∈ a := List.mem_toFinset end FreeMonoid
.lake/packages/mathlib/Mathlib/Algebra/FreeMonoid/UniqueProds.lean
import Mathlib.Algebra.FreeMonoid.Basic import Mathlib.Algebra.Group.UniqueProds.Basic import Mathlib.Algebra.Order.Group.Nat /-! # Free monoids have unique products -/ assert_not_exists Cardinal Subsemiring Algebra Submodule StarModule open Finset /-- Any `FreeMonoid` has the `TwoUniqueProds` property. -/ instance FreeMonoid.instTwoUniqueProds {κ : Type*} : TwoUniqueProds (FreeMonoid κ) := .of_mulHom ⟨Multiplicative.ofAdd ∘ List.length, fun _ _ ↦ congr_arg _ List.length_append⟩ (fun _ _ _ _ h h' ↦ List.append_inj h <| Equiv.injective Multiplicative.ofAdd h'.1) /-- Any `FreeAddMonoid` has the `TwoUniqueSums` property. -/ instance FreeAddMonoid.instTwoUniqueSums {κ : Type*} : TwoUniqueSums (FreeAddMonoid κ) := .of_addHom ⟨_, fun _ _ => List.length_append⟩ (fun _ _ _ _ h h' ↦ List.append_inj h h'.1)
.lake/packages/mathlib/Mathlib/Algebra/Lie/DirectSum.lean
import Mathlib.Algebra.DirectSum.Module import Mathlib.Algebra.Lie.OfAssociative import Mathlib.Algebra.Lie.Ideal import Mathlib.Algebra.Lie.Basic /-! # Direct sums of Lie algebras and Lie modules Direct sums of Lie algebras and Lie modules carry natural algebra and module structures. ## Tags lie algebra, lie module, direct sum -/ universe u v w w₁ namespace DirectSum open DFinsupp open scoped DirectSum variable {R : Type u} {ι : Type v} [CommRing R] section Modules /-! The direct sum of Lie modules over a fixed Lie algebra carries a natural Lie module structure. -/ variable {L : Type w₁} {M : ι → Type w} variable [LieRing L] [LieAlgebra R L] variable [∀ i, AddCommGroup (M i)] [∀ i, Module R (M i)] variable [∀ i, LieRingModule L (M i)] [∀ i, LieModule R L (M i)] instance : LieRingModule L (⨁ i, M i) where bracket x m := m.mapRange (fun _ m' => ⁅x, m'⁆) fun _ => lie_zero x add_lie x y m := by ext simp only [mapRange_apply, add_apply, add_lie] lie_add x m n := by ext simp only [mapRange_apply, add_apply, lie_add] leibniz_lie x y m := by ext simp only [mapRange_apply, lie_lie, add_apply, sub_add_cancel] @[simp] theorem lie_module_bracket_apply (x : L) (m : ⨁ i, M i) (i : ι) : ⁅x, m⁆ i = ⁅x, m i⁆ := mapRange_apply _ _ m i instance : LieModule R L (⨁ i, M i) where smul_lie t x m := by ext simp only [smul_lie, lie_module_bracket_apply, smul_apply] lie_smul t x m := by ext simp only [lie_smul, lie_module_bracket_apply, smul_apply] variable (R ι L M) /-- The inclusion of each component into a direct sum as a morphism of Lie modules. -/ def lieModuleOf [DecidableEq ι] (j : ι) : M j →ₗ⁅R,L⁆ ⨁ i, M i := { lof R ι M j with map_lie' := fun {x m} => by ext i by_cases h : j = i · rw [← h]; simp · -- This used to be the end of the proof before https://github.com/leanprover/lean4/pull/2644 -- old proof `simp [lof, lsingle, h]` simp only [lof, lsingle, AddHom.toFun_eq_coe, lie_module_bracket_apply] -- The coercion in the goal is `DFunLike.coe (β := fun x ↦ Π₀ (i : ι), M i)` -- but the lemma is expecting `DFunLike.coe (β := fun x ↦ ⨁ (i : ι), M i)` erw [AddHom.coe_mk] simp [h] } /-- The projection map onto one component, as a morphism of Lie modules. -/ def lieModuleComponent (j : ι) : (⨁ i, M i) →ₗ⁅R,L⁆ M j := { component R ι M j with map_lie' := fun {x m} => by simp [component, lapply] } end Modules section Algebras /-! The direct sum of Lie algebras carries a natural Lie algebra structure. -/ variable (L : ι → Type w) variable [∀ i, LieRing (L i)] [∀ i, LieAlgebra R (L i)] instance lieRing : LieRing (⨁ i, L i) := { (inferInstance : AddCommGroup _) with bracket := zipWith (fun _ => fun x y => ⁅x, y⁆) fun _ => lie_zero 0 add_lie := fun x y z => by ext simp only [zipWith_apply, add_apply, add_lie] lie_add := fun x y z => by ext simp only [zipWith_apply, add_apply, lie_add] lie_self := fun x => by ext simp only [zipWith_apply, lie_self, zero_apply] leibniz_lie := fun x y z => by ext simp only [zipWith_apply, add_apply] apply leibniz_lie } @[simp] theorem bracket_apply (x y : ⨁ i, L i) (i : ι) : ⁅x, y⁆ i = ⁅x i, y i⁆ := zipWith_apply _ _ x y i theorem lie_of_same [DecidableEq ι] {i : ι} (x y : L i) : ⁅of L i x, of L i y⁆ = of L i ⁅x, y⁆ := DFinsupp.zipWith_single_single _ _ _ _ theorem lie_of_of_ne [DecidableEq ι] {i j : ι} (hij : i ≠ j) (x : L i) (y : L j) : ⁅of L i x, of L j y⁆ = 0 := by ext k rw [bracket_apply] obtain rfl | hik := Decidable.eq_or_ne k i · rw [of_eq_of_ne _ _ _ hij, lie_zero, zero_apply] · rw [of_eq_of_ne _ _ _ hik, zero_lie, zero_apply] @[simp] theorem lie_of [DecidableEq ι] {i j : ι} (x : L i) (y : L j) : ⁅of L i x, of L j y⁆ = if hij : i = j then of L i ⁅x, hij.symm.recOn y⁆ else 0 := by obtain rfl | hij := Decidable.eq_or_ne i j · simp only [lie_of_same L x y, dif_pos] · simp only [lie_of_of_ne L hij x y, hij, dite_false] instance lieAlgebra : LieAlgebra R (⨁ i, L i) := { (inferInstance : Module R _) with lie_smul := fun c x y => by ext simp only [smul_apply, bracket_apply, lie_smul] } variable (R ι) /-- The inclusion of each component into the direct sum as morphism of Lie algebras. -/ @[simps] def lieAlgebraOf [DecidableEq ι] (j : ι) : L j →ₗ⁅R⁆ ⨁ i, L i := { lof R ι L j with toFun := of L j map_lie' := fun {x y} => (lie_of_same L x y).symm } /-- The projection map onto one component, as a morphism of Lie algebras. -/ @[simps] def lieAlgebraComponent (j : ι) : (⨁ i, L i) →ₗ⁅R⁆ L j := { component R ι L j with toFun := component R ι L j map_lie' := fun {x y} => by simp [component, lapply] } -- Note(kmill): `ext` cannot generate an iff theorem here since `x` and `y` do not determine `R`. @[ext (iff := false)] theorem lieAlgebra_ext {x y : ⨁ i, L i} (h : ∀ i, lieAlgebraComponent R ι L i x = lieAlgebraComponent R ι L i y) : x = y := DFinsupp.ext h variable {R L ι} /-- Given a family of Lie algebras `L i`, together with a family of morphisms of Lie algebras `f i : L i →ₗ⁅R⁆ L'` into a fixed Lie algebra `L'`, we have a natural linear map: `(⨁ i, L i) →ₗ[R] L'`. If in addition `⁅f i x, f j y⁆ = 0` for any `x ∈ L i` and `y ∈ L j` (`i ≠ j`) then this map is a morphism of Lie algebras. -/ @[simps] def toLieAlgebra [DecidableEq ι] (L' : Type w₁) [LieRing L'] [LieAlgebra R L'] (f : ∀ i, L i →ₗ⁅R⁆ L') (hf : Pairwise fun i j => ∀ (x : L i) (y : L j), ⁅f i x, f j y⁆ = 0) : (⨁ i, L i) →ₗ⁅R⁆ L' := { toModule R ι L' fun i => (f i : L i →ₗ[R] L') with toFun := toModule R ι L' fun i => (f i : L i →ₗ[R] L') map_lie' := fun {x y} => by let f' i := (f i : L i →ₗ[R] L') /- The goal is linear in `y`. We can use this to reduce to the case that `y` has only one non-zero component. -/ suffices ∀ (i : ι) (y : L i), toModule R ι L' f' ⁅x, of L i y⁆ = ⁅toModule R ι L' f' x, toModule R ι L' f' (of L i y)⁆ by simp only [← LieAlgebra.ad_apply R] rw [← LinearMap.comp_apply, ← LinearMap.comp_apply] congr; clear y; ext i y; exact this i y -- Similarly, we can reduce to the case that `x` has only one non-zero component. suffices ∀ (i j) (y : L i) (x : L j), toModule R ι L' f' ⁅of L j x, of L i y⁆ = ⁅toModule R ι L' f' (of L j x), toModule R ι L' f' (of L i y)⁆ by intro i y rw [← lie_skew x, ← lie_skew (toModule R ι L' f' x)] simp only [LinearMap.map_neg, neg_inj, ← LieAlgebra.ad_apply R] rw [← LinearMap.comp_apply, ← LinearMap.comp_apply] congr; clear x; ext j x; exact this j i x y intro i j y x simp only [f', coe_toModule_eq_coe_toAddMonoid, toAddMonoid_of] -- And finish with trivial case analysis. obtain rfl | hij := Decidable.eq_or_ne i j · simp_rw [lie_of_same, toAddMonoid_of, LinearMap.toAddMonoidHom_coe, LieHom.coe_toLinearMap, LieHom.map_lie] · simp_rw [lie_of_of_ne _ hij.symm, map_zero, LinearMap.toAddMonoidHom_coe, LieHom.coe_toLinearMap, hf hij.symm x y] } end Algebras section Ideals variable {L : Type w} [LieRing L] [LieAlgebra R L] (I : ι → LieIdeal R L) /-- The fact that this instance is necessary seems to be a bug in typeclass inference. See [this Zulip thread](https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/ Typeclass.20resolution.20under.20binders/near/245151099). -/ instance lieRingOfIdeals : LieRing (⨁ i, I i) := DirectSum.lieRing fun i => ↥(I i) /-- See `DirectSum.lieRingOfIdeals` comment. -/ instance lieAlgebraOfIdeals : LieAlgebra R (⨁ i, I i) := DirectSum.lieAlgebra fun i => ↥(I i) end Ideals end DirectSum
.lake/packages/mathlib/Mathlib/Algebra/Lie/Subalgebra.lean
import Mathlib.Algebra.Lie.Basic import Mathlib.RingTheory.Artinian.Module /-! # Lie subalgebras This file defines Lie subalgebras of a Lie algebra and provides basic related definitions and results. ## Main definitions * `LieSubalgebra` * `LieSubalgebra.incl` * `LieSubalgebra.map` * `LieHom.range` * `LieEquiv.ofInjective` * `LieEquiv.ofEq` * `LieEquiv.ofSubalgebras` ## Tags lie algebra, lie subalgebra -/ universe u v w w₁ w₂ section LieSubalgebra variable (R : Type u) (L : Type v) [CommRing R] [LieRing L] [LieAlgebra R L] /-- A Lie subalgebra of a Lie algebra is submodule that is closed under the Lie bracket. This is a sufficient condition for the subset itself to form a Lie algebra. -/ structure LieSubalgebra extends Submodule R L where /-- A Lie subalgebra is closed under Lie bracket. -/ lie_mem' : ∀ {x y}, x ∈ carrier → y ∈ carrier → ⁅x, y⁆ ∈ carrier /-- The zero algebra is a subalgebra of any Lie algebra. -/ instance : Zero (LieSubalgebra R L) := ⟨⟨0, @fun x y hx _hy ↦ by rw [(Submodule.mem_bot R).1 hx, zero_lie] exact Submodule.zero_mem 0⟩⟩ instance : Inhabited (LieSubalgebra R L) := ⟨0⟩ instance : Coe (LieSubalgebra R L) (Submodule R L) := ⟨LieSubalgebra.toSubmodule⟩ namespace LieSubalgebra instance : SetLike (LieSubalgebra R L) L where coe L' := L'.carrier coe_injective' L' L'' h := by rcases L' with ⟨⟨⟩⟩ rcases L'' with ⟨⟨⟩⟩ congr exact SetLike.coe_injective' h instance : AddSubgroupClass (LieSubalgebra R L) L where add_mem := Submodule.add_mem _ zero_mem L' := L'.zero_mem' neg_mem {L'} x hx := show -x ∈ (L' : Submodule R L) from neg_mem hx instance : SMulMemClass (LieSubalgebra R L) R L where smul_mem {s} := SMulMemClass.smul_mem (s := s.toSubmodule) /-- A Lie subalgebra forms a new Lie ring. -/ instance lieRing (L' : LieSubalgebra R L) : LieRing L' where bracket x y := ⟨⁅x.val, y.val⁆, L'.lie_mem' x.property y.property⟩ lie_add := by intros apply SetCoe.ext apply lie_add add_lie := by intros apply SetCoe.ext apply add_lie lie_self := by intros apply SetCoe.ext apply lie_self leibniz_lie := by intros apply SetCoe.ext apply leibniz_lie section variable {R₁ : Type*} [Semiring R₁] /-- A Lie subalgebra inherits module structures from `L`. -/ instance [SMul R₁ R] [Module R₁ L] [IsScalarTower R₁ R L] (L' : LieSubalgebra R L) : Module R₁ L' := L'.toSubmodule.module' instance [SMul R₁ R] [SMul R₁ᵐᵒᵖ R] [Module R₁ L] [Module R₁ᵐᵒᵖ L] [IsScalarTower R₁ R L] [IsScalarTower R₁ᵐᵒᵖ R L] [IsCentralScalar R₁ L] (L' : LieSubalgebra R L) : IsCentralScalar R₁ L' := L'.toSubmodule.isCentralScalar instance [SMul R₁ R] [Module R₁ L] [IsScalarTower R₁ R L] (L' : LieSubalgebra R L) : IsScalarTower R₁ R L' := L'.toSubmodule.isScalarTower instance (L' : LieSubalgebra R L) [IsNoetherian R L] : IsNoetherian R L' := isNoetherian_submodule' _ instance (L' : LieSubalgebra R L) [IsArtinian R L] : IsArtinian R L' := isArtinian_submodule' _ end /-- A Lie subalgebra forms a new Lie algebra. -/ instance lieAlgebra (L' : LieSubalgebra R L) : LieAlgebra R L' where lie_smul := by { intros apply SetCoe.ext apply lie_smul } variable {R L} variable (L' : LieSubalgebra R L) protected theorem zero_mem : (0 : L) ∈ L' := zero_mem L' protected theorem add_mem {x y : L} : x ∈ L' → y ∈ L' → (x + y : L) ∈ L' := add_mem protected theorem sub_mem {x y : L} : x ∈ L' → y ∈ L' → (x - y : L) ∈ L' := sub_mem protected theorem smul_mem (t : R) {x : L} (h : x ∈ L') : t • x ∈ L' := SMulMemClass.smul_mem _ h theorem lie_mem {x y : L} (hx : x ∈ L') (hy : y ∈ L') : (⁅x, y⁆ : L) ∈ L' := L'.lie_mem' hx hy theorem mem_carrier {x : L} : x ∈ L'.carrier ↔ x ∈ (L' : Set L) := Iff.rfl theorem mem_mk_iff (S : Set L) (h₁ h₂ h₃ h₄) {x : L} : x ∈ (⟨⟨⟨⟨S, h₁⟩, h₂⟩, h₃⟩, h₄⟩ : LieSubalgebra R L) ↔ x ∈ S := Iff.rfl @[simp] theorem mem_toSubmodule {x : L} : x ∈ (L' : Submodule R L) ↔ x ∈ L' := Iff.rfl @[simp] theorem mem_mk_iff' (p : Submodule R L) (h) {x : L} : x ∈ (⟨p, h⟩ : LieSubalgebra R L) ↔ x ∈ p := Iff.rfl theorem mem_coe {x : L} : x ∈ (L' : Set L) ↔ x ∈ L' := Iff.rfl @[simp, norm_cast] theorem coe_bracket (x y : L') : (↑⁅x, y⁆ : L) = ⁅(↑x : L), ↑y⁆ := rfl theorem ext_iff (x y : L') : x = y ↔ (x : L) = y := Subtype.ext_iff theorem coe_zero_iff_zero (x : L') : (x : L) = 0 ↔ x = 0 := (ext_iff L' x 0).symm @[ext] theorem ext (L₁' L₂' : LieSubalgebra R L) (h : ∀ x, x ∈ L₁' ↔ x ∈ L₂') : L₁' = L₂' := SetLike.ext h theorem ext_iff' (L₁' L₂' : LieSubalgebra R L) : L₁' = L₂' ↔ ∀ x, x ∈ L₁' ↔ x ∈ L₂' := SetLike.ext_iff @[simp] theorem mk_coe (S : Set L) (h₁ h₂ h₃ h₄) : ((⟨⟨⟨⟨S, h₁⟩, h₂⟩, h₃⟩, h₄⟩ : LieSubalgebra R L) : Set L) = S := rfl theorem toSubmodule_mk (p : Submodule R L) (h) : (({ p with lie_mem' := h } : LieSubalgebra R L) : Submodule R L) = p := rfl theorem coe_injective : Function.Injective ((↑) : LieSubalgebra R L → Set L) := SetLike.coe_injective @[norm_cast] theorem coe_set_eq (L₁' L₂' : LieSubalgebra R L) : (L₁' : Set L) = L₂' ↔ L₁' = L₂' := SetLike.coe_set_eq theorem toSubmodule_injective : Function.Injective ((↑) : LieSubalgebra R L → Submodule R L) := fun L₁' L₂' h ↦ by rw [SetLike.ext'_iff] at h rw [← coe_set_eq] exact h @[simp] theorem toSubmodule_inj (L₁' L₂' : LieSubalgebra R L) : (L₁' : Submodule R L) = (L₂' : Submodule R L) ↔ L₁' = L₂' := toSubmodule_injective.eq_iff theorem coe_toSubmodule : ((L' : Submodule R L) : Set L) = L' := rfl section LieModule variable {M : Type w} [AddCommGroup M] [LieRingModule L M] variable {N : Type w₁} [AddCommGroup N] [LieRingModule L N] [Module R N] instance : Bracket L' M where bracket x m := ⁅(x : L), m⁆ @[simp] theorem coe_bracket_of_module (x : L') (m : M) : ⁅x, m⁆ = ⁅(x : L), m⁆ := rfl instance : IsLieTower L' L M where leibniz_lie x y m := leibniz_lie x.val y m /-- Given a Lie algebra `L` containing a Lie subalgebra `L' ⊆ L`, together with a Lie ring module `M` of `L`, we may regard `M` as a Lie ring module of `L'` by restriction. -/ instance lieRingModule : LieRingModule L' M where add_lie x y m := add_lie (x : L) y m lie_add x y m := lie_add (x : L) y m leibniz_lie x y m := leibniz_lie x (y : L) m variable [Module R M] /-- Given a Lie algebra `L` containing a Lie subalgebra `L' ⊆ L`, together with a Lie module `M` of `L`, we may regard `M` as a Lie module of `L'` by restriction. -/ instance lieModule [LieModule R L M] : LieModule R L' M where smul_lie t x m := by rw [coe_bracket_of_module, Submodule.coe_smul_of_tower, smul_lie, coe_bracket_of_module] lie_smul t x m := by simp only [coe_bracket_of_module, lie_smul] /-- An `L`-equivariant map of Lie modules `M → N` is `L'`-equivariant for any Lie subalgebra `L' ⊆ L`. -/ def _root_.LieModuleHom.restrictLie (f : M →ₗ⁅R,L⁆ N) (L' : LieSubalgebra R L) : M →ₗ⁅R,L'⁆ N := { (f : M →ₗ[R] N) with map_lie' := @fun x m ↦ f.map_lie (↑x) m } @[simp] theorem _root_.LieModuleHom.coe_restrictLie (f : M →ₗ⁅R,L⁆ N) : ⇑(f.restrictLie L') = f := rfl end LieModule /-- The embedding of a Lie subalgebra into the ambient space as a morphism of Lie algebras. -/ def incl : L' →ₗ⁅R⁆ L := { (L' : Submodule R L).subtype with map_lie' := rfl } @[simp] theorem coe_incl : ⇑L'.incl = ((↑) : L' → L) := rfl /-- The embedding of a Lie subalgebra into the ambient space as a morphism of Lie modules. -/ def incl' : L' →ₗ⁅R,L'⁆ L := { (L' : Submodule R L).subtype with map_lie' := rfl } @[simp] theorem coe_incl' : ⇑L'.incl' = ((↑) : L' → L) := rfl end LieSubalgebra variable {R L} variable {L₂ : Type w} [LieRing L₂] [LieAlgebra R L₂] variable (f : L →ₗ⁅R⁆ L₂) namespace LieHom /-- The range of a morphism of Lie algebras is a Lie subalgebra. -/ def range : LieSubalgebra R L₂ := { LinearMap.range (f : L →ₗ[R] L₂) with lie_mem' := by rintro - - ⟨x, rfl⟩ ⟨y, rfl⟩ exact ⟨⁅x, y⁆, f.map_lie x y⟩ } @[simp] theorem coe_range : (f.range : Set L₂) = Set.range f := LinearMap.coe_range (f : L →ₗ[R] L₂) @[deprecated (since := "2025-08-31")] alias range_coe := coe_range @[simp] theorem mem_range (x : L₂) : x ∈ f.range ↔ ∃ y : L, f y = x := LinearMap.mem_range theorem mem_range_self (x : L) : f x ∈ f.range := LinearMap.mem_range_self (f : L →ₗ[R] L₂) x /-- We can restrict a morphism to a (surjective) map to its range. -/ def rangeRestrict : L →ₗ⁅R⁆ f.range := { (f : L →ₗ[R] L₂).rangeRestrict with map_lie' := @fun x y ↦ by apply Subtype.ext exact f.map_lie x y } @[simp] theorem rangeRestrict_apply (x : L) : f.rangeRestrict x = ⟨f x, f.mem_range_self x⟩ := rfl theorem surjective_rangeRestrict : Function.Surjective f.rangeRestrict := by rintro ⟨y, hy⟩ rw [mem_range] at hy; obtain ⟨x, rfl⟩ := hy use x simp only [rangeRestrict_apply] /-- A Lie algebra is equivalent to its range under an injective Lie algebra morphism. -/ noncomputable def equivRangeOfInjective (h : Function.Injective f) : L ≃ₗ⁅R⁆ f.range := LieEquiv.ofBijective f.rangeRestrict ⟨fun x y hxy ↦ by simp only [Subtype.mk_eq_mk, rangeRestrict_apply] at hxy exact h hxy, f.surjective_rangeRestrict⟩ @[simp] theorem equivRangeOfInjective_apply (h : Function.Injective f) (x : L) : f.equivRangeOfInjective h x = ⟨f x, mem_range_self f x⟩ := rfl end LieHom theorem Submodule.exists_lieSubalgebra_coe_eq_iff (p : Submodule R L) : (∃ K : LieSubalgebra R L, ↑K = p) ↔ ∀ x y : L, x ∈ p → y ∈ p → ⁅x, y⁆ ∈ p := by constructor · rintro ⟨K, rfl⟩ _ _ exact K.lie_mem' · intro h use { p with lie_mem' := h _ _ } namespace LieSubalgebra variable (K K' : LieSubalgebra R L) (K₂ : LieSubalgebra R L₂) @[simp] theorem incl_range : K.incl.range = K := by rw [← toSubmodule_inj] exact (K : Submodule R L).range_subtype /-- The image of a Lie subalgebra under a Lie algebra morphism is a Lie subalgebra of the codomain. -/ def map : LieSubalgebra R L₂ := { (K : Submodule R L).map (f : L →ₗ[R] L₂) with lie_mem' {x y} hx hy := by simp only [AddSubsemigroup.mem_carrier] at hx hy rcases hx with ⟨x', hx', rfl⟩ rcases hy with ⟨y', hy', rfl⟩ simpa using ⟨⁅x', y'⁆, K.lie_mem hx' hy', f.map_lie x' y'⟩ } @[simp] theorem mem_map (x : L₂) : x ∈ K.map f ↔ ∃ y : L, y ∈ K ∧ f y = x := Submodule.mem_map -- TODO Rename and state for homs instead of equivs. theorem mem_map_submodule (e : L ≃ₗ⁅R⁆ L₂) (x : L₂) : x ∈ K.map (e : L →ₗ⁅R⁆ L₂) ↔ x ∈ (K : Submodule R L).map (e : L →ₗ[R] L₂) := Iff.rfl /-- The preimage of a Lie subalgebra under a Lie algebra morphism is a Lie subalgebra of the domain. -/ def comap : LieSubalgebra R L := { (K₂ : Submodule R L₂).comap (f : L →ₗ[R] L₂) with lie_mem' := @fun x y hx hy ↦ by suffices ⁅f x, f y⁆ ∈ K₂ by simp [this] exact K₂.lie_mem hx hy } @[simp] lemma mem_comap {x : L} : x ∈ K₂.comap f ↔ f x ∈ K₂ := Iff.rfl section LatticeStructure open Set instance : PartialOrder (LieSubalgebra R L) := { PartialOrder.lift ((↑) : LieSubalgebra R L → Set L) coe_injective with le := fun N N' ↦ ∀ ⦃x⦄, x ∈ N → x ∈ N' } theorem le_def : K ≤ K' ↔ (K : Set L) ⊆ K' := Iff.rfl @[simp] theorem toSubmodule_le_toSubmodule : (K : Submodule R L) ≤ K' ↔ K ≤ K' := Iff.rfl instance : Bot (LieSubalgebra R L) := ⟨0⟩ @[simp] theorem bot_coe : ((⊥ : LieSubalgebra R L) : Set L) = {0} := rfl @[simp] theorem bot_toSubmodule : ((⊥ : LieSubalgebra R L) : Submodule R L) = ⊥ := rfl @[simp] theorem mem_bot (x : L) : x ∈ (⊥ : LieSubalgebra R L) ↔ x = 0 := mem_singleton_iff instance : Top (LieSubalgebra R L) := ⟨{ (⊤ : Submodule R L) with lie_mem' := @fun x y _ _ ↦ mem_univ ⁅x, y⁆ }⟩ @[simp] theorem top_coe : ((⊤ : LieSubalgebra R L) : Set L) = univ := rfl @[simp] theorem top_toSubmodule : ((⊤ : LieSubalgebra R L) : Submodule R L) = ⊤ := rfl @[simp] theorem mem_top (x : L) : x ∈ (⊤ : LieSubalgebra R L) := mem_univ x theorem _root_.LieHom.range_eq_map : f.range = map f ⊤ := by ext simp instance : Min (LieSubalgebra R L) := ⟨fun K K' ↦ { (K ⊓ K' : Submodule R L) with lie_mem' := fun hx hy ↦ mem_inter (K.lie_mem hx.1 hy.1) (K'.lie_mem hx.2 hy.2) }⟩ instance : InfSet (LieSubalgebra R L) := ⟨fun S ↦ { sInf {(s : Submodule R L) | s ∈ S} with lie_mem' := @fun x y hx hy ↦ by simp only [Submodule.mem_carrier, mem_iInter, Submodule.coe_sInf, mem_setOf_eq, forall_apply_eq_imp_iff₂, exists_imp, and_imp] at hx hy ⊢ intro K hK exact K.lie_mem (hx K hK) (hy K hK) }⟩ @[simp] theorem coe_inf : (↑(K ⊓ K') : Set L) = (K : Set L) ∩ (K' : Set L) := rfl @[deprecated (since := "2025-08-31")] alias inf_coe := coe_inf @[simp] theorem sInf_toSubmodule (S : Set (LieSubalgebra R L)) : (↑(sInf S) : Submodule R L) = sInf {(s : Submodule R L) | s ∈ S} := rfl @[simp] theorem coe_sInf (S : Set (LieSubalgebra R L)) : (↑(sInf S) : Set L) = ⋂ s ∈ S, (s : Set L) := by rw [← coe_toSubmodule, sInf_toSubmodule, Submodule.coe_sInf] ext x simp @[deprecated (since := "2025-08-31")] alias sInf_coe := coe_sInf theorem sInf_glb (S : Set (LieSubalgebra R L)) : IsGLB S (sInf S) := by have h : ∀ K K' : LieSubalgebra R L, (K : Set L) ≤ K' ↔ K ≤ K' := by intros exact Iff.rfl apply IsGLB.of_image @h simp only [coe_sInf] exact isGLB_biInf /-- The set of Lie subalgebras of a Lie algebra form a complete lattice. We provide explicit values for the fields `bot`, `top`, `inf` to get more convenient definitions than we would otherwise obtain from `completeLatticeOfInf`. -/ instance completeLattice : CompleteLattice (LieSubalgebra R L) := { completeLatticeOfInf _ sInf_glb with bot := ⊥ bot_le := fun N _ h ↦ by rw [mem_bot] at h rw [h] exact N.zero_mem' top := ⊤ le_top := fun _ _ _ ↦ trivial inf := (· ⊓ ·) le_inf := fun _ _ _ h₁₂ h₁₃ _ hm ↦ ⟨h₁₂ hm, h₁₃ hm⟩ inf_le_left := fun _ _ _ ↦ And.left inf_le_right := fun _ _ _ ↦ And.right } instance : Add (LieSubalgebra R L) where add := max instance : Zero (LieSubalgebra R L) where zero := ⊥ instance addCommMonoid : AddCommMonoid (LieSubalgebra R L) where add_assoc := sup_assoc zero_add := bot_sup_eq add_zero := sup_bot_eq add_comm := sup_comm nsmul := nsmulRec instance : IsOrderedAddMonoid (LieSubalgebra R L) where add_le_add_left _ _ := sup_le_sup_left instance : CanonicallyOrderedAdd (LieSubalgebra R L) where exists_add_of_le {_a b} h := ⟨b, (sup_eq_right.2 h).symm⟩ le_add_self _ _ := le_sup_right le_self_add _ _ := le_sup_left @[simp] theorem add_eq_sup : K + K' = K ⊔ K' := rfl @[simp] theorem inf_toSubmodule : (↑(K ⊓ K') : Submodule R L) = (K : Submodule R L) ⊓ (K' : Submodule R L) := rfl @[simp] theorem mem_inf (x : L) : x ∈ K ⊓ K' ↔ x ∈ K ∧ x ∈ K' := by rw [← mem_toSubmodule, ← mem_toSubmodule, ← mem_toSubmodule, inf_toSubmodule, Submodule.mem_inf] theorem eq_bot_iff : K = ⊥ ↔ ∀ x : L, x ∈ K → x = 0 := by rw [_root_.eq_bot_iff] exact Iff.rfl instance subsingleton_of_bot : Subsingleton (LieSubalgebra R (⊥ : LieSubalgebra R L)) := by apply subsingleton_of_bot_eq_top ext ⟨x, hx⟩; change x ∈ ⊥ at hx; rw [LieSubalgebra.mem_bot] at hx; subst hx simp only [mem_bot, mem_top, iff_true] rfl theorem subsingleton_bot : Subsingleton (⊥ : LieSubalgebra R L) := show Subsingleton ((⊥ : LieSubalgebra R L) : Set L) by simp variable (R L) instance wellFoundedGT_of_noetherian [IsNoetherian R L] : WellFoundedGT (LieSubalgebra R L) := RelHomClass.isWellFounded (⟨toSubmodule, @fun _ _ h ↦ h⟩ : _ →r (· > ·)) variable {R L K K' f} section NestedSubalgebras variable (h : K ≤ K') /-- Given two nested Lie subalgebras `K ⊆ K'`, the inclusion `K ↪ K'` is a morphism of Lie algebras. -/ def inclusion : K →ₗ⁅R⁆ K' := { Submodule.inclusion h with map_lie' := @fun _ _ ↦ rfl } @[simp] theorem coe_inclusion (x : K) : (inclusion h x : L) = x := rfl theorem inclusion_apply (x : K) : inclusion h x = ⟨x.1, h x.2⟩ := rfl theorem inclusion_injective : Function.Injective (inclusion h) := fun x y ↦ by simp only [inclusion_apply, imp_self, Subtype.mk_eq_mk, SetLike.coe_eq_coe] /-- Given two nested Lie subalgebras `K ⊆ K'`, we can view `K` as a Lie subalgebra of `K'`, regarded as Lie algebra in its own right. -/ def ofLe : LieSubalgebra R K' := (inclusion h).range @[simp] theorem mem_ofLe (x : K') : x ∈ ofLe h ↔ (x : L) ∈ K := by simp only [ofLe, inclusion_apply, LieHom.mem_range] constructor · rintro ⟨y, rfl⟩ exact y.property · intro h use ⟨(x : L), h⟩ theorem ofLe_eq_comap_incl : ofLe h = K.comap K'.incl := by ext rw [mem_ofLe] rfl @[simp] theorem coe_ofLe : (ofLe h : Submodule R K') = LinearMap.range (Submodule.inclusion h) := rfl /-- Given nested Lie subalgebras `K ⊆ K'`, there is a natural equivalence from `K` to its image in `K'`. -/ noncomputable def equivOfLe : K ≃ₗ⁅R⁆ ofLe h := (inclusion h).equivRangeOfInjective (inclusion_injective h) @[simp] theorem equivOfLe_apply (x : K) : equivOfLe h x = ⟨inclusion h x, (inclusion h).mem_range_self x⟩ := rfl end NestedSubalgebras theorem map_le_iff_le_comap {K : LieSubalgebra R L} {K' : LieSubalgebra R L₂} : map f K ≤ K' ↔ K ≤ comap f K' := Set.image_subset_iff theorem gc_map_comap : GaloisConnection (map f) (comap f) := fun _ _ ↦ map_le_iff_le_comap end LatticeStructure section LieSpan variable (R L) (s : Set L) /-- The Lie subalgebra of a Lie algebra `L` generated by a subset `s ⊆ L`. -/ def lieSpan : LieSubalgebra R L := sInf { N | s ⊆ N } variable {R L s} theorem mem_lieSpan {x : L} : x ∈ lieSpan R L s ↔ ∀ K : LieSubalgebra R L, s ⊆ K → x ∈ K := by rw [← SetLike.mem_coe, lieSpan, coe_sInf] exact Set.mem_iInter₂ theorem subset_lieSpan : s ⊆ lieSpan R L s := by intro m hm rw [SetLike.mem_coe, mem_lieSpan] intro K hK exact hK hm theorem submodule_span_le_lieSpan : Submodule.span R s ≤ lieSpan R L s := by rw [Submodule.span_le, coe_toSubmodule] apply subset_lieSpan theorem lieSpan_le {K} : lieSpan R L s ≤ K ↔ s ⊆ K := by constructor · exact Set.Subset.trans subset_lieSpan · intro hs m hm rw [mem_lieSpan] at hm exact hm _ hs theorem lieSpan_mono {t : Set L} (h : s ⊆ t) : lieSpan R L s ≤ lieSpan R L t := by rw [lieSpan_le] exact Set.Subset.trans h subset_lieSpan theorem lieSpan_eq : lieSpan R L (K : Set L) = K := le_antisymm (lieSpan_le.mpr rfl.subset) subset_lieSpan theorem coe_lieSpan_submodule_eq_iff {p : Submodule R L} : (lieSpan R L (p : Set L) : Submodule R L) = p ↔ ∃ K : LieSubalgebra R L, ↑K = p := by rw [p.exists_lieSubalgebra_coe_eq_iff]; constructor <;> intro h · intro x m hm rw [← h, mem_toSubmodule] exact lie_mem _ (subset_lieSpan hm) · rw [← toSubmodule_mk p @h, coe_toSubmodule, toSubmodule_inj, lieSpan_eq] open Submodule in theorem coe_lieSpan_eq_span_of_forall_lie_eq_zero {s : Set L} (hs : ∀ᵉ (x ∈ s) (y ∈ s), ⁅x, y⁆ = 0) : lieSpan R L s = span R s := by suffices ∀ {x y}, x ∈ span R s → y ∈ span R s → ⁅x, y⁆ ∈ span R s by refine le_antisymm ?_ submodule_span_le_lieSpan change _ ≤ ({ span R s with lie_mem' := this } : LieSubalgebra R L) rw [lieSpan_le] exact subset_span intro x y hx hy induction hx, hy using span_induction₂ with | mem_mem x y hx hy => simp [hs x hx y hy] | zero_left y hy => simp | zero_right x hx => simp | add_left x y z _ _ _ hx hy => simp [add_mem hx hy] | add_right x y z _ _ _ hx hy => simp [add_mem hx hy] | smul_left r x y _ _ h => simp [smul_mem _ r h] | smul_right r x y _ _ h => simp [smul_mem _ r h] variable (R L) /-- `lieSpan` forms a Galois insertion with the coercion from `LieSubalgebra` to `Set`. -/ protected def gi : GaloisInsertion (lieSpan R L : Set L → LieSubalgebra R L) (↑) where choice s _ := lieSpan R L s gc _ _ := lieSpan_le le_l_u _ := subset_lieSpan choice_eq _ _ := rfl @[simp] theorem span_empty : lieSpan R L (∅ : Set L) = ⊥ := (LieSubalgebra.gi R L).gc.l_bot @[simp] theorem span_univ : lieSpan R L (Set.univ : Set L) = ⊤ := eq_top_iff.2 <| SetLike.le_def.2 <| subset_lieSpan variable {L} theorem span_union (s t : Set L) : lieSpan R L (s ∪ t) = lieSpan R L s ⊔ lieSpan R L t := (LieSubalgebra.gi R L).gc.l_sup theorem span_iUnion {ι} (s : ι → Set L) : lieSpan R L (⋃ i, s i) = ⨆ i, lieSpan R L (s i) := (LieSubalgebra.gi R L).gc.l_iSup /-- An induction principle for span membership. If `p` holds for 0 and all elements of `s`, and is preserved under addition, scalar multiplication and the Lie bracket, then `p` holds for all elements of the Lie algebra spanned by `s`. -/ @[elab_as_elim] theorem lieSpan_induction {p : (x : L) → x ∈ lieSpan R L s → Prop} (mem : ∀ (x) (h : x ∈ s), p x (subset_lieSpan h)) (zero : p 0 (LieSubalgebra.zero_mem _)) (add : ∀ x y hx hy, p x hx → p y hy → p (x + y) (LieSubalgebra.add_mem _ ‹_› ‹_›)) (smul : ∀ (a : R) (x hx), p x hx → p (a • x) (LieSubalgebra.smul_mem _ _ ‹_›)) {x} (lie : ∀ x y hx hy, p x hx → p y hy → p (⁅x, y⁆) (LieSubalgebra.lie_mem _ ‹_› ‹_›)) (hx : x ∈ lieSpan R L s) : p x hx := by let p : LieSubalgebra R L := { carrier := { x | ∃ hx, p x hx } add_mem' := fun ⟨_, hpx⟩ ⟨_, hpy⟩ ↦ ⟨_, add _ _ _ _ hpx hpy⟩ zero_mem' := ⟨_, zero⟩ smul_mem' := fun r ↦ fun ⟨_, hpx⟩ ↦ ⟨_, smul r _ _ hpx⟩ lie_mem' := fun ⟨_, hpx⟩ ⟨_, hpy⟩ ↦ ⟨_, lie _ _ _ _ hpx hpy⟩ } exact lieSpan_le (K := p) |>.mpr (fun y hy ↦ ⟨subset_lieSpan hy, mem y hy⟩) hx |>.elim fun _ ↦ id end LieSpan end LieSubalgebra end LieSubalgebra namespace LieEquiv variable {R : Type u} {L₁ : Type v} {L₂ : Type w} variable [CommRing R] [LieRing L₁] [LieRing L₂] [LieAlgebra R L₁] [LieAlgebra R L₂] /-- An injective Lie algebra morphism is an equivalence onto its range. -/ noncomputable def ofInjective (f : L₁ →ₗ⁅R⁆ L₂) (h : Function.Injective f) : L₁ ≃ₗ⁅R⁆ f.range := { LinearEquiv.ofInjective (f : L₁ →ₗ[R] L₂) <| by rwa [LieHom.coe_toLinearMap] with map_lie' {x y} := SetCoe.ext <| f.map_lie x y } @[simp] theorem ofInjective_apply (f : L₁ →ₗ⁅R⁆ L₂) (h : Function.Injective f) (x : L₁) : ↑(ofInjective f h x) = f x := rfl variable (L₁' L₁'' : LieSubalgebra R L₁) (L₂' : LieSubalgebra R L₂) /-- Lie subalgebras that are equal as sets are equivalent as Lie algebras. -/ def ofEq (h : (L₁' : Set L₁) = L₁'') : L₁' ≃ₗ⁅R⁆ L₁'' := { LinearEquiv.ofEq (L₁' : Submodule R L₁) (L₁'' : Submodule R L₁) (by ext x change x ∈ (L₁' : Set L₁) ↔ x ∈ (L₁'' : Set L₁) rw [h]) with map_lie' {_ _} := rfl } @[simp] theorem ofEq_apply (L L' : LieSubalgebra R L₁) (h : (L : Set L₁) = L') (x : L) : (↑(ofEq L L' h x) : L₁) = x := rfl variable (e : L₁ ≃ₗ⁅R⁆ L₂) /-- An equivalence of Lie algebras restricts to an equivalence from any Lie subalgebra onto its image. -/ def lieSubalgebraMap : L₁'' ≃ₗ⁅R⁆ (L₁''.map e : LieSubalgebra R L₂) := { LinearEquiv.submoduleMap (e : L₁ ≃ₗ[R] L₂) ↑L₁'' with map_lie' := @fun x y ↦ by apply SetCoe.ext exact LieHom.map_lie (↑e : L₁ →ₗ⁅R⁆ L₂) ↑x ↑y } @[simp] theorem lieSubalgebraMap_apply (x : L₁'') : ↑(e.lieSubalgebraMap _ x) = e x := rfl /-- An equivalence of Lie algebras restricts to an equivalence from any Lie subalgebra onto its image. -/ def ofSubalgebras (h : L₁'.map ↑e = L₂') : L₁' ≃ₗ⁅R⁆ L₂' := { LinearEquiv.ofSubmodules (e : L₁ ≃ₗ[R] L₂) (↑L₁') (↑L₂') (by rw [← h] rfl) with map_lie' := @fun x y ↦ by apply SetCoe.ext exact LieHom.map_lie (↑e : L₁ →ₗ⁅R⁆ L₂) ↑x ↑y } @[simp] theorem ofSubalgebras_apply (h : L₁'.map ↑e = L₂') (x : L₁') : ↑(e.ofSubalgebras _ _ h x) = e x := rfl @[simp] theorem ofSubalgebras_symm_apply (h : L₁'.map ↑e = L₂') (x : L₂') : ↑((e.ofSubalgebras _ _ h).symm x) = e.symm x := rfl end LieEquiv
.lake/packages/mathlib/Mathlib/Algebra/Lie/Cochain.lean
import Mathlib.Algebra.Lie.Abelian /-! # Lie algebra cohomology in low degree This file defines low degree cochains of Lie algebras with coefficients given by a module. They are useful in the construction of central extensions, so we treat these easier cases separately from the general theory of Lie algebra cohomology. ## Main definitions * `LieAlgebra.oneCochain`: an abbreviation for a linear map. * `LieAlgebra.twoCochain`: a submodule of bilinear maps, giving 2-cochains. * `LieAlgebra.d₁₂`: The coboundary map taking 1-cochains to 2-cochains. * `LieAlgebra.d₂₃`: A coboundary map taking 2-cochains to a space containing 3-cochains. * `LieAlgebra.twoCocycle`: The submodule of 2-cocycles. ## TODO * coboundaries, cohomology * comparison to the Chevalley-Eilenberg complex. * construction and classification of central extensions ## References * [H. Cartan, S. Eilenberg, *Homological Algebra*](cartan-eilenberg-1956) -/ namespace LieModule.Cohomology variable (R : Type*) [CommRing R] variable (L : Type*) [LieRing L] [LieAlgebra R L] variable (M : Type*) [AddCommGroup M] [Module R M] /-- Lie algebra 1-cochains over `L` with coefficients in the module `M`. -/ abbrev oneCochain := L →ₗ[R] M /-- Lie algebra 2-cochains over `L` with coefficients in the module `M`. -/ def twoCochain : Submodule R (L →ₗ[R] L →ₗ[R] M) where carrier := {c | ∀ x, c x x = 0} add_mem' {a b} ha hb x := by simp [ha x, hb x] zero_mem' := by simp smul_mem' t {c} hc x := by simp [hc x] section variable {R L M} instance : FunLike (twoCochain R L M) L (L →ₗ[R] M) where coe := fun a x ↦ a.1 x coe_injective' _ _ h := by ext exact congrFun (congrArg DFunLike.coe (congrFun h _)) _ instance : LinearMapClass (twoCochain R L M) R L (L →ₗ[R] M) where map_add a := a.1.map_add map_smulₛₗ a := a.1.map_smul @[simp] lemma twoCochain_alt (a : twoCochain R L M) (x : L) : a x x = 0 := a.2 x lemma twoCochain_skew (a : twoCochain R L M) (x y : L) : - a x y = a y x := by rw [neg_eq_iff_add_eq_zero, add_comm] simpa [map_add, twoCochain_alt a x, twoCochain_alt a y] using twoCochain_alt a (x + y) @[simp] lemma twoCochain_val_apply (a : twoCochain R L M) (x : L) : a.val x = a x := rfl @[simp] lemma add_apply_apply (a b : twoCochain R L M) (x y : L) : (a + b) x y = a x y + b x y := by rfl @[simp] lemma smul_apply_apply (r : R) (a : twoCochain R L M) (x y : L) : (r • a) x y = r • (a x y) := by rfl end variable [LieRingModule L M] [LieModule R L M] /-- The coboundary operator taking degree 1 cochains to degree 2 cochains. -/ @[simps] def d₁₂ : oneCochain R L M →ₗ[R] twoCochain R L M where toFun f := { val := { toFun x := { toFun y := ⁅x, f y⁆ - ⁅y, f x⁆ - f ⁅x, y⁆ map_add' _ _ := by simp; abel map_smul' _ _ := by simp [smul_sub] } map_add' _ _ := by ext; simp; abel map_smul' _ _ := by ext; simp [smul_sub] } property x := by simp } map_add' _ _ := by ext; simp; abel map_smul' _ _ := by ext; simp [smul_sub] @[simp] lemma d₁₂_apply_apply (f : oneCochain R L M) (x y : L) : d₁₂ R L M f x y = ⁅x, f y⁆ - ⁅y, f x⁆ - f ⁅x, y⁆ := rfl lemma d₁₂_apply_apply_ofTrivial [LieModule.IsTrivial L M] (f : oneCochain R L M) (x y : L) : d₁₂ R L M f x y = - f ⁅x, y⁆ := by simp /-- The coboundary operator taking degree 2 cochains to a space containing degree 3 cochains. -/ private def d₂₃_aux (a : twoCochain R L M) : L →ₗ[R] L →ₗ[R] L →ₗ[R] M where toFun x := { toFun y := { toFun z := ⁅x, a y z⁆ - ⁅y, a x z⁆ + ⁅z, a x y⁆ - a ⁅x, y⁆ z + a ⁅x, z⁆ y - a ⁅y, z⁆ x map_add' _ _ := by simp; abel map_smul' _ _ := by abel_nf; simp } map_add' _ _ := by ext; simp; abel map_smul' _ _ := by ext; abel_nf; simp } map_add' _ _ := by ext; simp; abel map_smul' _ _ := by ext; abel_nf; simp /-- The coboundary operator taking degree 2 cochains to a space containing degree 3 cochains. -/ def d₂₃ : twoCochain R L M →ₗ[R] L →ₗ[R] L →ₗ[R] L →ₗ[R] M where toFun := d₂₃_aux R L M map_add' _ _ := by ext; simp [d₂₃_aux]; abel map_smul' _ _ := by ext; simp [d₂₃_aux]; abel_nf; simp @[simp] lemma d₂₃_apply (a : twoCochain R L M) (x y z : L) : d₂₃ R L M a x y z = ⁅x, a y z⁆ - ⁅y, a x z⁆ + ⁅z, a x y⁆ - a ⁅x, y⁆ z + a ⁅x, z⁆ y - a ⁅y, z⁆ x := rfl lemma d₂₃_comp_d₁₂ : (d₂₃ R L M) ∘ₗ (d₁₂ R L M) = 0 := by ext a x y z have (a : oneCochain R L M) (x : L) : d₁₂ R L M a x = (d₁₂ R L M a).val x := rfl simp only [LinearMap.comp_apply, d₂₃_apply, LinearMap.zero_apply, this, d₁₂_apply_coe_apply_apply R L M, lie_sub, lie_lie] rw [leibniz_lie y x, leibniz_lie z x, leibniz_lie z y] have : a ⁅y, ⁅z, x⁆⁆ = a ⁅x, ⁅z, y⁆⁆ + a ⁅z, ⁅y, x⁆⁆ := by rw [congr_arg a (leibniz_lie y z x), ← lie_skew, ← lie_skew z y, lie_neg, map_add] simp only [lie_lie, sub_add_cancel, map_sub, ← lie_skew x y, ← lie_skew x z, ← lie_skew y z, lie_neg, map_neg, this] abel /-- A Lie 2-cocycle is a 2-cochain that is annihilated by the coboundary map. -/ def twoCocycle : Submodule R (twoCochain R L M) := LinearMap.ker (d₂₃ R L M) lemma mem_twoCocycle_iff (a : twoCochain R L M) : a ∈ twoCocycle R L M ↔ d₂₃ R L M a = 0 := by simp [twoCocycle] lemma mem_twoCocycle_iff_of_trivial [LieModule.IsTrivial L M] (a : twoCochain R L M) : a ∈ twoCocycle R L M ↔ ∀ (x y z : L), a x ⁅y, z⁆ = a ⁅x, y⁆ z + a y ⁅x, z⁆ := by constructor · intro h x y z rw [mem_twoCocycle_iff] at h have : (d₂₃ R L M) a x y z = 0 := (congrArg (fun b ↦ b x y z = 0) h).mpr rfl simp only [d₂₃_apply, trivial_lie_zero, sub_self, add_zero, zero_sub] at this rw [sub_eq_zero] at this rw [← twoCochain_skew a _ x, ← twoCochain_skew a _ y, ← this] abel · intro h ext x y z simp only [d₂₃_apply, trivial_lie_zero, sub_self, add_zero, zero_sub, LinearMap.zero_apply] rw [← twoCochain_skew a x, ← twoCochain_skew a y, h x y z] abel end LieModule.Cohomology
.lake/packages/mathlib/Mathlib/Algebra/Lie/UniversalEnveloping.lean
import Mathlib.Algebra.Lie.OfAssociative import Mathlib.Algebra.RingQuot import Mathlib.LinearAlgebra.TensorAlgebra.Basic /-! # Universal enveloping algebra Given a commutative ring `R` and a Lie algebra `L` over `R`, we construct the universal enveloping algebra of `L`, together with its universal property. ## Main definitions * `UniversalEnvelopingAlgebra`: the universal enveloping algebra, endowed with an `R`-algebra structure. * `UniversalEnvelopingAlgebra.ι`: the Lie algebra morphism from `L` to its universal enveloping algebra. * `UniversalEnvelopingAlgebra.lift`: given an associative algebra `A`, together with a Lie algebra morphism `f : L →ₗ⁅R⁆ A`, `lift R L f : UniversalEnvelopingAlgebra R L →ₐ[R] A` is the unique morphism of algebras through which `f` factors. * `UniversalEnvelopingAlgebra.ι_comp_lift`: states that the lift of a morphism is indeed part of a factorisation. * `UniversalEnvelopingAlgebra.lift_unique`: states that lifts of morphisms are indeed unique. * `UniversalEnvelopingAlgebra.hom_ext`: a restatement of `lift_unique` as an extensionality lemma. ## Tags lie algebra, universal enveloping algebra, tensor algebra -/ universe u₁ u₂ u₃ variable (R : Type u₁) (L : Type u₂) variable [CommRing R] [LieRing L] [LieAlgebra R L] local notation "ιₜ" => TensorAlgebra.ι R namespace UniversalEnvelopingAlgebra /-- The quotient by the ideal generated by this relation is the universal enveloping algebra. Note that we have avoided using the more natural expression: | lie_compat (x y : L) : rel (ιₜ ⁅x, y⁆) ⁅ιₜ x, ιₜ y⁆ so that our construction needs only the semiring structure of the tensor algebra. -/ inductive Rel : TensorAlgebra R L → TensorAlgebra R L → Prop | lie_compat (x y : L) : Rel (ιₜ ⁅x, y⁆ + ιₜ y * ιₜ x) (ιₜ x * ιₜ y) end UniversalEnvelopingAlgebra /-- The universal enveloping algebra of a Lie algebra. -/ def UniversalEnvelopingAlgebra := RingQuot (UniversalEnvelopingAlgebra.Rel R L) deriving Inhabited, Ring, Algebra R namespace UniversalEnvelopingAlgebra /-- The quotient map from the tensor algebra to the universal enveloping algebra as a morphism of associative algebras. -/ def mkAlgHom : TensorAlgebra R L →ₐ[R] UniversalEnvelopingAlgebra R L := RingQuot.mkAlgHom R (Rel R L) variable {L} /-- The natural Lie algebra morphism from a Lie algebra to its universal enveloping algebra. -/ @[simps!] def ι : L →ₗ⁅R⁆ UniversalEnvelopingAlgebra R L := { (mkAlgHom R L).toLinearMap.comp ιₜ with map_lie' := fun {x y} => by suffices mkAlgHom R L (ιₜ ⁅x, y⁆ + ιₜ y * ιₜ x) = mkAlgHom R L (ιₜ x * ιₜ y) by rw [map_mul] at this; simp [LieRing.of_associative_ring_bracket, ← this] exact RingQuot.mkAlgHom_rel _ (Rel.lie_compat x y) } variable {A : Type u₃} [Ring A] [Algebra R A] (f : L →ₗ⁅R⁆ A) /-- The universal property of the universal enveloping algebra: Lie algebra morphisms into associative algebras lift to associative algebra morphisms from the universal enveloping algebra. -/ def lift : (L →ₗ⁅R⁆ A) ≃ (UniversalEnvelopingAlgebra R L →ₐ[R] A) where toFun f := RingQuot.liftAlgHom R ⟨TensorAlgebra.lift R (f : L →ₗ[R] A), by intro a b h; induction h simp only [LieRing.of_associative_ring_bracket, map_add, TensorAlgebra.lift_ι_apply, LieHom.coe_toLinearMap, LieHom.map_lie, map_mul, sub_add_cancel]⟩ invFun F := (F : UniversalEnvelopingAlgebra R L →ₗ⁅R⁆ A).comp (ι R) left_inv f := by ext -- Porting note: was -- simp only [ι, mkAlgHom, TensorAlgebra.lift_ι_apply, LieHom.coe_toLinearMap, -- LinearMap.toFun_eq_coe, LinearMap.coe_comp, LieHom.coe_comp, AlgHom.coe_toLieHom, -- LieHom.coe_mk, Function.comp_apply, AlgHom.toLinearMap_apply, -- RingQuot.liftAlgHom_mkAlgHom_apply] simp only [LieHom.coe_comp, Function.comp_apply, AlgHom.coe_toLieHom, UniversalEnvelopingAlgebra.ι_apply, mkAlgHom] simp only [UniversalEnvelopingAlgebra, RingQuot.liftAlgHom_mkAlgHom_apply, TensorAlgebra.lift_ι_apply, LieHom.coe_toLinearMap] right_inv F := by apply RingQuot.ringQuot_ext' ext -- Porting note: was -- simp only [ι, mkAlgHom, TensorAlgebra.lift_ι_apply, LieHom.coe_toLinearMap, -- LinearMap.toFun_eq_coe, LinearMap.coe_comp, LieHom.toLinearMap_comp, -- AlgHom.comp_toLinearMap, Function.comp_apply, AlgHom.toLinearMap_apply, -- RingQuot.liftAlgHom_mkAlgHom_apply, AlgHom.coe_toLieHom, LieHom.coe_mk] -- extra `rfl` after https://github.com/leanprover/lean4/pull/2644 simp [mkAlgHom]; rfl @[simp] theorem lift_symm_apply (F : UniversalEnvelopingAlgebra R L →ₐ[R] A) : (lift R).symm F = (F : UniversalEnvelopingAlgebra R L →ₗ⁅R⁆ A).comp (ι R) := rfl @[simp] theorem ι_comp_lift : lift R f ∘ ι R = f := funext <| LieHom.ext_iff.mp <| (lift R).symm_apply_apply f -- `simp`-normal form is `lift_ι_apply'`. theorem lift_ι_apply (x : L) : lift R f (ι R x) = f x := by rw [← Function.comp_apply (f := lift R f) (g := ι R) (x := x), ι_comp_lift] @[simp] theorem lift_ι_apply' (x : L) : lift R f ((UniversalEnvelopingAlgebra.mkAlgHom R L) (ιₜ x)) = f x := by simpa using lift_ι_apply R f x theorem lift_unique (g : UniversalEnvelopingAlgebra R L →ₐ[R] A) : g ∘ ι R = f ↔ g = lift R f := by refine Iff.trans ?_ (lift R).symm_apply_eq constructor <;> · intro h; ext; simp [← h] /-- See note [partially-applied ext lemmas]. -/ @[ext] theorem hom_ext {g₁ g₂ : UniversalEnvelopingAlgebra R L →ₐ[R] A} (h : (g₁ : UniversalEnvelopingAlgebra R L →ₗ⁅R⁆ A).comp (ι R) = (g₂ : UniversalEnvelopingAlgebra R L →ₗ⁅R⁆ A).comp (ι R)) : g₁ = g₂ := have h' : (lift R).symm g₁ = (lift R).symm g₂ := by simp [h] (lift R).symm.injective h' end UniversalEnvelopingAlgebra
.lake/packages/mathlib/Mathlib/Algebra/Lie/CartanSubalgebra.lean
import Mathlib.Algebra.Lie.Nilpotent import Mathlib.Algebra.Lie.Normalizer /-! # Cartan subalgebras Cartan subalgebras are one of the most important concepts in Lie theory. We define them here. The standard example is the set of diagonal matrices in the Lie algebra of matrices. ## Main definitions * `LieSubmodule.IsUcsLimit` * `LieSubalgebra.IsCartanSubalgebra` * `LieSubalgebra.isCartanSubalgebra_iff_isUcsLimit` ## Tags lie subalgebra, normalizer, idealizer, cartan subalgebra -/ universe u v w w₁ w₂ variable {R : Type u} {L : Type v} variable [CommRing R] [LieRing L] [LieAlgebra R L] (H : LieSubalgebra R L) /-- Given a Lie module `M` of a Lie algebra `L`, `LieSubmodule.IsUcsLimit` is the proposition that a Lie submodule `N ⊆ M` is the limiting value for the upper central series. This is a characteristic property of Cartan subalgebras with the roles of `L`, `M`, `N` played by `H`, `L`, `H`, respectively. See `LieSubalgebra.isCartanSubalgebra_iff_isUcsLimit`. -/ def LieSubmodule.IsUcsLimit {M : Type*} [AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M] (N : LieSubmodule R L M) : Prop := ∃ k, ∀ l, k ≤ l → (⊥ : LieSubmodule R L M).ucs l = N namespace LieSubalgebra /-- A Cartan subalgebra is a nilpotent, self-normalizing subalgebra. A _splitting_ Cartan subalgebra can be defined by mixing in `LieModule.IsTriangularizable R H L`. -/ class IsCartanSubalgebra : Prop where nilpotent : LieRing.IsNilpotent H self_normalizing : H.normalizer = H instance [H.IsCartanSubalgebra] : LieRing.IsNilpotent H := IsCartanSubalgebra.nilpotent @[simp] theorem normalizer_eq_self_of_isCartanSubalgebra (H : LieSubalgebra R L) [H.IsCartanSubalgebra] : H.toLieSubmodule.normalizer = H.toLieSubmodule := by rw [← LieSubmodule.toSubmodule_inj, coe_normalizer_eq_normalizer, IsCartanSubalgebra.self_normalizing, coe_toLieSubmodule] @[simp] theorem ucs_eq_self_of_isCartanSubalgebra (H : LieSubalgebra R L) [H.IsCartanSubalgebra] (k : ℕ) : H.toLieSubmodule.ucs k = H.toLieSubmodule := by induction k with | zero => simp | succ k ih => simp [ih] theorem isCartanSubalgebra_iff_isUcsLimit : H.IsCartanSubalgebra ↔ H.toLieSubmodule.IsUcsLimit := by constructor · intro h have h₁ : LieRing.IsNilpotent H := by infer_instance obtain ⟨k, hk⟩ := H.toLieSubmodule.isNilpotent_iff_exists_self_le_ucs.mp h₁ replace hk : H.toLieSubmodule = LieSubmodule.ucs k ⊥ := le_antisymm hk (LieSubmodule.ucs_le_of_normalizer_eq_self H.normalizer_eq_self_of_isCartanSubalgebra k) refine ⟨k, fun l hl => ?_⟩ rw [← Nat.sub_add_cancel hl, LieSubmodule.ucs_add, ← hk, LieSubalgebra.ucs_eq_self_of_isCartanSubalgebra] · rintro ⟨k, hk⟩ exact { nilpotent := by dsimp only [LieRing.IsNilpotent] -- The instance for the second `H` in the goal is `lieRingSelfModule` -- but `rw` expects it to be `H.toLieSubmodule.instLieRingModuleSubtypeMem`, -- and these are not reducibly defeq. erw [H.toLieSubmodule.isNilpotent_iff_exists_lcs_eq_bot] use k rw [_root_.eq_bot_iff, LieSubmodule.lcs_le_iff, hk k (le_refl k)] self_normalizing := by have hk' := hk (k + 1) k.le_succ rw [LieSubmodule.ucs_succ, hk k (le_refl k)] at hk' rw [← LieSubalgebra.toSubmodule_inj, ← LieSubalgebra.coe_normalizer_eq_normalizer, hk', LieSubalgebra.coe_toLieSubmodule] } lemma ne_bot_of_isCartanSubalgebra [Nontrivial L] (H : LieSubalgebra R L) [H.IsCartanSubalgebra] : H ≠ ⊥ := by intro e obtain ⟨x, hx⟩ := exists_ne (0 : L) have : x ∈ H.normalizer := by simp [LieSubalgebra.mem_normalizer_iff, e] exact hx (by rwa [LieSubalgebra.IsCartanSubalgebra.self_normalizing, e] at this) instance (priority := 500) [Nontrivial L] (H : LieSubalgebra R L) [H.IsCartanSubalgebra] : Nontrivial H := by refine (subsingleton_or_nontrivial H).elim (fun inst ↦ False.elim ?_) id apply ne_bot_of_isCartanSubalgebra H rw [eq_bot_iff] exact fun x hx ↦ congr_arg Subtype.val (Subsingleton.elim (⟨x, hx⟩ : H) 0) end LieSubalgebra @[simp] theorem LieIdeal.normalizer_eq_top {R : Type u} {L : Type v} [CommRing R] [LieRing L] [LieAlgebra R L] (I : LieIdeal R L) : (I : LieSubalgebra R L).normalizer = ⊤ := by ext x simpa only [LieSubalgebra.mem_normalizer_iff, LieSubalgebra.mem_top, iff_true] using fun y hy => I.lie_mem hy open LieIdeal /-- A nilpotent Lie algebra is its own Cartan subalgebra. -/ instance LieAlgebra.top_isCartanSubalgebra_of_nilpotent [LieRing.IsNilpotent L] : LieSubalgebra.IsCartanSubalgebra (⊤ : LieSubalgebra R L) where nilpotent := inferInstance self_normalizing := by rw [← top_toLieSubalgebra, normalizer_eq_top, top_toLieSubalgebra]
.lake/packages/mathlib/Mathlib/Algebra/Lie/EngelSubalgebra.lean
import Mathlib.Algebra.Lie.Engel import Mathlib.Algebra.Lie.Normalizer import Mathlib.Algebra.Lie.OfAssociative import Mathlib.Algebra.Lie.Subalgebra import Mathlib.Data.Finset.NatAntidiagonal /-! # Engel subalgebras This file defines Engel subalgebras of a Lie algebra and provides basic related properties. The Engel subalgebra `LieSubalgebra.Engel R x` consists of all `y : L` such that `(ad R L x)^n` kills `y` for some `n`. ## Main results Engel subalgebras are self-normalizing (`LieSubalgebra.normalizer_engel`), and minimal ones are nilpotent (TODO), hence Cartan subalgebras. * `LieSubalgebra.normalizer_eq_self_of_engel_le`: Lie subalgebras containing an Engel subalgebra are self-normalizing, provided the ambient Lie algebra is Artinian. * `LieSubalgebra.isNilpotent_of_forall_le_engel`: A Lie subalgebra of a Noetherian Lie algebra is nilpotent if it is contained in the Engel subalgebra of all its elements. -/ open LieAlgebra LieModule variable {R L M : Type*} [CommRing R] [LieRing L] [LieAlgebra R L] [AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M] namespace LieSubalgebra variable (R) /-- The Engel subalgebra `Engel R x` consists of all `y : L` such that `(ad R L x)^n` kills `y` for some `n`. Engel subalgebras are self-normalizing (`LieSubalgebra.normalizer_engel`), and minimal ones are nilpotent, hence Cartan subalgebras. -/ @[simps!] def engel (x : L) : LieSubalgebra R L := { (ad R L x).maxGenEigenspace 0 with lie_mem' := by simp only [AddSubsemigroup.mem_carrier, AddSubmonoid.mem_toSubsemigroup, Submodule.mem_toAddSubmonoid, Module.End.mem_maxGenEigenspace, zero_smul, sub_zero, forall_exists_index] intro y z m hm n hn refine ⟨m + n, ?_⟩ rw [ad_pow_lie] apply Finset.sum_eq_zero intro ij hij obtain (h|h) : m ≤ ij.1 ∨ n ≤ ij.2 := by rw [Finset.mem_antidiagonal] at hij; cutsat all_goals simp [Module.End.pow_map_zero_of_le h, hm, hn] } lemma mem_engel_iff (x y : L) : y ∈ engel R x ↔ ∃ n : ℕ, ((ad R L x) ^ n) y = 0 := (Module.End.mem_maxGenEigenspace _ _ _).trans <| by simp only [zero_smul, sub_zero] lemma self_mem_engel (x : L) : x ∈ engel R x := by simp only [mem_engel_iff] exact ⟨1, by simp⟩ @[simp] lemma engel_zero : engel R (0 : L) = ⊤ := by rw [eq_top_iff] rintro x - rw [mem_engel_iff, map_zero] use 1 simp only [pow_one, LinearMap.zero_apply] /-- Engel subalgebras are self-normalizing. See `LieSubalgebra.normalizer_eq_self_of_engel_le` for a proof that Lie-subalgebras containing an Engel subalgebra are also self-normalizing, provided that the ambient Lie algebra is artinina. -/ @[simp] lemma normalizer_engel (x : L) : normalizer (engel R x) = engel R x := by apply le_antisymm _ (le_normalizer _) intro y hy rw [mem_normalizer_iff] at hy specialize hy x (self_mem_engel R x) rw [← lie_skew, neg_mem_iff (G := L), mem_engel_iff] at hy rcases hy with ⟨n, hn⟩ rw [mem_engel_iff] use n + 1 rw [pow_succ, Module.End.mul_apply] exact hn variable {R} open Filter in /-- A Lie-subalgebra of an Artinian Lie algebra is self-normalizing if it contains an Engel subalgebra. See `LieSubalgebra.normalizer_engel` for a proof that Engel subalgebras are self-normalizing, avoiding the Artinian condition. -/ lemma normalizer_eq_self_of_engel_le [IsArtinian R L] (H : LieSubalgebra R L) (x : L) (h : engel R x ≤ H) : normalizer H = H := by set N := normalizer H apply le_antisymm _ (le_normalizer H) calc N.toSubmodule ≤ (engel R x).toSubmodule ⊔ H.toSubmodule := ?_ _ = H := by rwa [sup_eq_right] have aux₁ : ∀ n ∈ N, ⁅x, n⁆ ∈ H := by intro n hn rw [mem_normalizer_iff] at hn specialize hn x (h (self_mem_engel R x)) rwa [← lie_skew, neg_mem_iff (G := L)] have aux₂ : ∀ n ∈ N, ⁅x, n⁆ ∈ N := fun n hn ↦ le_normalizer H (aux₁ _ hn) let dx : N →ₗ[R] N := (ad R L x).restrict aux₂ obtain ⟨k, hk⟩ : ∃ a, ∀ b ≥ a, Codisjoint (LinearMap.ker (dx ^ b)) (LinearMap.range (dx ^ b)) := eventually_atTop.mp <| dx.eventually_codisjoint_ker_pow_range_pow specialize hk (k+1) (Nat.le_add_right k 1) rw [← Submodule.map_subtype_top N.toSubmodule, Submodule.map_le_iff_le_comap] apply hk · rw [← Submodule.map_le_iff_le_comap] apply le_sup_of_le_left rw [Submodule.map_le_iff_le_comap] intro y hy simp only [Submodule.mem_comap, mem_engel_iff, mem_toSubmodule] use k+1 clear hk; revert hy generalize k+1 = k induction k generalizing y with | zero => cases y; intro hy; simp only [pow_zero, Module.End.one_apply] exact (AddSubmonoid.mk_eq_zero N.toAddSubmonoid).mp hy | succ k ih => solve_by_elim · rw [← Submodule.map_le_iff_le_comap] apply le_sup_of_le_right rw [Submodule.map_le_iff_le_comap] rintro _ ⟨y, rfl⟩ simp only [pow_succ', Module.End.mul_apply, Submodule.mem_comap, mem_toSubmodule] apply aux₁ simp only [Submodule.coe_subtype, SetLike.coe_mem] /-- A Lie subalgebra of a Noetherian Lie algebra is nilpotent if it is contained in the Engel subalgebra of all its elements. -/ lemma isNilpotent_of_forall_le_engel [IsNoetherian R L] (H : LieSubalgebra R L) (h : ∀ x ∈ H, H ≤ engel R x) : LieRing.IsNilpotent H := by rw [LieAlgebra.isNilpotent_iff_forall (R := R)] intro x let K : ℕ →o Submodule R H := ⟨fun n ↦ LinearMap.ker ((ad R H x) ^ n), fun m n hmn ↦ ?mono⟩ case mono => intro y hy rw [LinearMap.mem_ker] at hy ⊢ exact Module.End.pow_map_zero_of_le hmn hy obtain ⟨n, hn⟩ := monotone_stabilizes_iff_noetherian.mpr inferInstance K use n ext y rw [coe_ad_pow] specialize h x x.2 y.2 rw [mem_engel_iff] at h obtain ⟨m, hm⟩ := h obtain (hmn|hmn) : m ≤ n ∨ n ≤ m := le_total m n · exact Module.End.pow_map_zero_of_le hmn hm · have : ∀ k : ℕ, ((ad R L) x ^ k) y = 0 ↔ y ∈ K k := by simp [K, Subtype.ext_iff, coe_ad_pow] rwa [this, ← hn m hmn, ← this] at hm end LieSubalgebra
.lake/packages/mathlib/Mathlib/Algebra/Lie/Matrix.lean
import Mathlib.Algebra.Lie.OfAssociative import Mathlib.LinearAlgebra.Matrix.Reindex import Mathlib.LinearAlgebra.Matrix.ToLinearEquiv /-! # Lie algebras of matrices An important class of Lie algebras are those arising from the associative algebra structure on square matrices over a commutative ring. This file provides some very basic definitions whose primary value stems from their utility when constructing the classical Lie algebras using matrices. ## Main definitions * `lieEquivMatrix'` * `Matrix.lieConj` * `Matrix.reindexLieEquiv` ## Tags lie algebra, matrix -/ universe u v w w₁ w₂ section Matrices open scoped Matrix variable {R : Type u} [CommRing R] variable {n : Type w} [DecidableEq n] [Fintype n] /-- The natural equivalence between linear endomorphisms of finite free modules and square matrices is compatible with the Lie algebra structures. -/ def lieEquivMatrix' : Module.End R (n → R) ≃ₗ⁅R⁆ Matrix n n R := { LinearMap.toMatrix' with map_lie' := fun {T S} => by let f := @LinearMap.toMatrix' R _ n n _ _ change f (T.comp S - S.comp T) = f T * f S - f S * f T have h : ∀ T S : Module.End R _, f (T.comp S) = f T * f S := LinearMap.toMatrix'_comp rw [map_sub, h, h] } @[simp] theorem lieEquivMatrix'_apply (f : Module.End R (n → R)) : lieEquivMatrix' f = LinearMap.toMatrix' f := rfl @[simp] theorem lieEquivMatrix'_symm_apply (A : Matrix n n R) : (@lieEquivMatrix' R _ n _ _).symm A = Matrix.toLin' A := rfl namespace Matrix /-- An invertible matrix induces a Lie algebra equivalence from the space of matrices to itself. -/ def lieConj (P : Matrix n n R) (h : Invertible P) : Matrix n n R ≃ₗ⁅R⁆ Matrix n n R := ((@lieEquivMatrix' R _ n _ _).symm.trans (P.toLinearEquiv' h).lieConj).trans lieEquivMatrix' @[simp] theorem lieConj_apply (P A : Matrix n n R) (h : Invertible P) : P.lieConj h A = P * A * P⁻¹ := by simp [LinearEquiv.conj_apply, Matrix.lieConj, LinearMap.toMatrix'_comp, LinearMap.toMatrix'_toLin'] @[simp] theorem lieConj_symm_apply (P A : Matrix n n R) (h : Invertible P) : (P.lieConj h).symm A = P⁻¹ * A * P := by simp [LinearEquiv.symm_conj_apply, Matrix.lieConj, LinearMap.toMatrix'_comp, LinearMap.toMatrix'_toLin'] variable {m : Type w₁} [DecidableEq m] [Fintype m] (e : n ≃ m) /-- For square matrices, the natural map that reindexes a matrix's rows and columns with equivalent types, `Matrix.reindex`, is an equivalence of Lie algebras. -/ def reindexLieEquiv : Matrix n n R ≃ₗ⁅R⁆ Matrix m m R := { Matrix.reindexLinearEquiv R R e e with toFun := Matrix.reindex e e map_lie' := fun {_ _} => by simp only [LieRing.of_associative_ring_bracket, Matrix.reindex_apply, Matrix.submatrix_mul_equiv, Matrix.submatrix_sub, Pi.sub_apply] } @[simp] theorem reindexLieEquiv_apply (M : Matrix n n R) : Matrix.reindexLieEquiv e M = Matrix.reindex e e M := rfl @[simp] theorem reindexLieEquiv_symm : (Matrix.reindexLieEquiv e : _ ≃ₗ⁅R⁆ _).symm = Matrix.reindexLieEquiv e.symm := rfl instance : LieRingModule (Matrix n n R) (n → R) where bracket := mulVec add_lie := add_mulVec lie_add := mulVec_add leibniz_lie x y v := by simp only [Ring.lie_def, mulVec_mulVec, sub_mulVec, sub_add_cancel] instance : LieModule R (Matrix n n R) (n → R) where smul_lie := smul_mulVec lie_smul t A := mulVec_smul A t @[simp] lemma lie_apply (A : Matrix n n R) (v : n → R) : ⁅A, v⁆ = A *ᵥ v := rfl end Matrix namespace LieModule @[simp] theorem toEnd_matrix : toEnd R (Matrix n n R) (n → R) = (lieEquivMatrix' (R := R) (n := n)).symm := by ext; simp instance : IsFaithful R (Matrix n n R) (n → R) where injective_toEnd := by simpa using EmbeddingLike.injective _ end LieModule end Matrices
.lake/packages/mathlib/Mathlib/Algebra/Lie/Nilpotent.lean
import Mathlib.Algebra.Lie.Solvable import Mathlib.Algebra.Lie.Quotient import Mathlib.Algebra.Lie.Normalizer import Mathlib.Algebra.Order.Archimedean.Basic import Mathlib.LinearAlgebra.Eigenspace.Basic import Mathlib.RingTheory.Artinian.Module import Mathlib.RingTheory.Nilpotent.Lemmas /-! # Nilpotent Lie algebras Like groups, Lie algebras admit a natural concept of nilpotency. More generally, any Lie module carries a natural concept of nilpotency. We define these here via the lower central series. ## Main definitions * `LieModule.lowerCentralSeries` * `LieModule.IsNilpotent` * `LieModule.maxNilpotentSubmodule` * `LieAlgebra.maxNilpotentIdeal` ## Tags lie algebra, lower central series, nilpotent, max nilpotent ideal -/ universe u v w w₁ w₂ section NilpotentModules variable {R : Type u} {L : Type v} {M : Type w} variable [CommRing R] [LieRing L] [LieAlgebra R L] [AddCommGroup M] [Module R M] variable [LieRingModule L M] variable (k : ℕ) (N : LieSubmodule R L M) namespace LieSubmodule /-- A generalisation of the lower central series. The zeroth term is a specified Lie submodule of a Lie module. In the case when we specify the top ideal `⊤` of the Lie algebra, regarded as a Lie module over itself, we get the usual lower central series of a Lie algebra. It can be more convenient to work with this generalisation when considering the lower central series of a Lie submodule, regarded as a Lie module in its own right, since it provides a type-theoretic expression of the fact that the terms of the Lie submodule's lower central series are also Lie submodules of the enclosing Lie module. See also `LieSubmodule.lowerCentralSeries_eq_lcs_comap` and `LieSubmodule.lowerCentralSeries_map_eq_lcs` below, as well as `LieSubmodule.ucs`. -/ def lcs : LieSubmodule R L M → LieSubmodule R L M := (fun N => ⁅(⊤ : LieIdeal R L), N⁆)^[k] @[simp] theorem lcs_zero (N : LieSubmodule R L M) : N.lcs 0 = N := rfl @[simp] theorem lcs_succ : N.lcs (k + 1) = ⁅(⊤ : LieIdeal R L), N.lcs k⁆ := Function.iterate_succ_apply' (fun N' => ⁅⊤, N'⁆) k N @[simp] lemma lcs_sup {N₁ N₂ : LieSubmodule R L M} {k : ℕ} : (N₁ ⊔ N₂).lcs k = N₁.lcs k ⊔ N₂.lcs k := by induction k with | zero => simp | succ k ih => simp only [LieSubmodule.lcs_succ, ih, LieSubmodule.lie_sup] end LieSubmodule namespace LieModule variable (R L M) /-- The lower central series of Lie submodules of a Lie module. -/ def lowerCentralSeries : LieSubmodule R L M := (⊤ : LieSubmodule R L M).lcs k @[simp] theorem lowerCentralSeries_zero : lowerCentralSeries R L M 0 = ⊤ := rfl @[simp] theorem lowerCentralSeries_succ : lowerCentralSeries R L M (k + 1) = ⁅(⊤ : LieIdeal R L), lowerCentralSeries R L M k⁆ := (⊤ : LieSubmodule R L M).lcs_succ k private theorem coe_lowerCentralSeries_eq_int_aux (R₁ R₂ L M : Type*) [CommRing R₁] [CommRing R₂] [AddCommGroup M] [LieRing L] [LieAlgebra R₁ L] [LieAlgebra R₂ L] [Module R₁ M] [Module R₂ M] [LieRingModule L M] [LieModule R₁ L M] (k : ℕ) : let I := lowerCentralSeries R₂ L M k; let S : Set M := {⁅a, b⁆ | (a : L) (b ∈ I)} (Submodule.span R₁ S : Set M) ≤ (Submodule.span R₂ S : Set M) := by intro I S x hx simp only [SetLike.mem_coe] at hx ⊢ induction hx using Submodule.closure_induction with | zero => exact Submodule.zero_mem _ | add y z hy₁ hz₁ hy₂ hz₂ => exact Submodule.add_mem _ hy₂ hz₂ | smul_mem c y hy => obtain ⟨a, b, hb, rfl⟩ := hy rw [← smul_lie] exact Submodule.subset_span ⟨c • a, b, hb, rfl⟩ theorem coe_lowerCentralSeries_eq_int [LieModule R L M] (k : ℕ) : (lowerCentralSeries R L M k : Set M) = (lowerCentralSeries ℤ L M k : Set M) := by rw [← LieSubmodule.coe_toSubmodule, ← LieSubmodule.coe_toSubmodule] induction k with | zero => rfl | succ k ih => rw [lowerCentralSeries_succ, lowerCentralSeries_succ] rw [LieSubmodule.lieIdeal_oper_eq_linear_span', LieSubmodule.lieIdeal_oper_eq_linear_span'] rw [Set.ext_iff] at ih simp only [SetLike.mem_coe, LieSubmodule.mem_toSubmodule] at ih simp only [LieSubmodule.mem_top, ih, true_and] apply le_antisymm · exact coe_lowerCentralSeries_eq_int_aux _ _ L M k · simp only [← ih] exact coe_lowerCentralSeries_eq_int_aux _ _ L M k end LieModule namespace LieSubmodule open LieModule theorem lcs_le_self : N.lcs k ≤ N := by induction k with | zero => simp | succ k ih => simp only [lcs_succ] exact (LieSubmodule.mono_lie_right ⊤ ih).trans (N.lie_le_right ⊤) variable [LieModule R L M] theorem lowerCentralSeries_eq_lcs_comap : lowerCentralSeries R L N k = (N.lcs k).comap N.incl := by induction k with | zero => simp | succ k ih => simp only [lcs_succ, lowerCentralSeries_succ] at ih ⊢ have : N.lcs k ≤ N.incl.range := by rw [N.range_incl] apply lcs_le_self rw [ih, LieSubmodule.comap_bracket_eq _ N.incl _ N.ker_incl this] theorem lowerCentralSeries_map_eq_lcs : (lowerCentralSeries R L N k).map N.incl = N.lcs k := by rw [lowerCentralSeries_eq_lcs_comap, LieSubmodule.map_comap_incl, inf_eq_right] apply lcs_le_self theorem lowerCentralSeries_eq_bot_iff_lcs_eq_bot : lowerCentralSeries R L N k = ⊥ ↔ lcs k N = ⊥ := by refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · rw [← N.lowerCentralSeries_map_eq_lcs, ← LieModuleHom.le_ker_iff_map] simpa · rw [N.lowerCentralSeries_eq_lcs_comap, comap_incl_eq_bot] simp [h] end LieSubmodule namespace LieModule variable {M₂ : Type w₁} [AddCommGroup M₂] [Module R M₂] [LieRingModule L M₂] [LieModule R L M₂] variable (R L M) theorem antitone_lowerCentralSeries : Antitone <| lowerCentralSeries R L M := by intro l k induction k generalizing l with | zero => exact fun h ↦ (Nat.le_zero.mp h).symm ▸ le_rfl | succ k ih => intro h rcases Nat.of_le_succ h with (hk | hk) · rw [lowerCentralSeries_succ] exact (LieSubmodule.mono_lie_right ⊤ (ih hk)).trans (LieSubmodule.lie_le_right _ _) · exact hk.symm ▸ le_rfl theorem eventually_iInf_lowerCentralSeries_eq [IsArtinian R M] : ∀ᶠ l in Filter.atTop, ⨅ k, lowerCentralSeries R L M k = lowerCentralSeries R L M l := by have h_wf : WellFoundedGT (LieSubmodule R L M)ᵒᵈ := LieSubmodule.wellFoundedLT_of_isArtinian R L M obtain ⟨n, hn : ∀ m, n ≤ m → lowerCentralSeries R L M n = lowerCentralSeries R L M m⟩ := h_wf.monotone_chain_condition ⟨_, antitone_lowerCentralSeries R L M⟩ refine Filter.eventually_atTop.mpr ⟨n, fun l hl ↦ le_antisymm (iInf_le _ _) (le_iInf fun m ↦ ?_)⟩ rcases le_or_gt l m with h | h · rw [← hn _ hl, ← hn _ (hl.trans h)] · exact antitone_lowerCentralSeries R L M (le_of_lt h) theorem trivial_iff_lower_central_eq_bot : IsTrivial L M ↔ lowerCentralSeries R L M 1 = ⊥ := by constructor <;> intro h · simp · rw [LieSubmodule.eq_bot_iff] at h; apply IsTrivial.mk; intro x m; apply h apply LieSubmodule.subset_lieSpan simp only [Subtype.exists, LieSubmodule.mem_top, exists_prop, true_and, Set.mem_setOf] exact ⟨x, m, rfl⟩ section variable [LieModule R L M] theorem iterate_toEnd_mem_lowerCentralSeries (x : L) (m : M) (k : ℕ) : (toEnd R L M x)^[k] m ∈ lowerCentralSeries R L M k := by induction k with | zero => simp only [Function.iterate_zero, lowerCentralSeries_zero, LieSubmodule.mem_top] | succ k ih => simp only [lowerCentralSeries_succ, Function.comp_apply, Function.iterate_succ', toEnd_apply_apply] exact LieSubmodule.lie_mem_lie (LieSubmodule.mem_top x) ih theorem iterate_toEnd_mem_lowerCentralSeries₂ (x y : L) (m : M) (k : ℕ) : (toEnd R L M x ∘ₗ toEnd R L M y)^[k] m ∈ lowerCentralSeries R L M (2 * k) := by induction k with | zero => simp | succ k ih => have hk : 2 * k.succ = (2 * k + 1) + 1 := rfl simp only [lowerCentralSeries_succ, Function.comp_apply, Function.iterate_succ', hk, toEnd_apply_apply, LinearMap.coe_comp, toEnd_apply_apply] refine LieSubmodule.lie_mem_lie (LieSubmodule.mem_top x) ?_ exact LieSubmodule.lie_mem_lie (LieSubmodule.mem_top y) ih variable {R L M} theorem map_lowerCentralSeries_le (f : M →ₗ⁅R,L⁆ M₂) : (lowerCentralSeries R L M k).map f ≤ lowerCentralSeries R L M₂ k := by induction k with | zero => simp only [lowerCentralSeries_zero, le_top] | succ k ih => simp only [LieModule.lowerCentralSeries_succ, LieSubmodule.map_bracket_eq] exact LieSubmodule.mono_lie_right ⊤ ih lemma map_lowerCentralSeries_eq {f : M →ₗ⁅R,L⁆ M₂} (hf : Function.Surjective f) : (lowerCentralSeries R L M k).map f = lowerCentralSeries R L M₂ k := by apply le_antisymm (map_lowerCentralSeries_le k f) induction k with | zero => rwa [lowerCentralSeries_zero, lowerCentralSeries_zero, top_le_iff, f.map_top, f.range_eq_top] | succ => simp only [lowerCentralSeries_succ, LieSubmodule.map_bracket_eq] apply LieSubmodule.mono_lie_right assumption end open LieAlgebra theorem derivedSeries_le_lowerCentralSeries (k : ℕ) : derivedSeries R L k ≤ lowerCentralSeries R L L k := by induction k with | zero => rw [derivedSeries_def, derivedSeriesOfIdeal_zero, lowerCentralSeries_zero] | succ k h => have h' : derivedSeries R L k ≤ ⊤ := by simp only [le_top] rw [derivedSeries_def, derivedSeriesOfIdeal_succ, lowerCentralSeries_succ] exact LieSubmodule.mono_lie h' h /-- A Lie module is nilpotent if its lower central series reaches 0 (in a finite number of steps). -/ @[mk_iff isNilpotent_iff_int] class IsNilpotent : Prop where mk_int :: nilpotent_int : ∃ k, lowerCentralSeries ℤ L M k = ⊥ section variable [LieModule R L M] /-- See also `LieModule.isNilpotent_iff_exists_ucs_eq_top`. -/ lemma isNilpotent_iff : IsNilpotent L M ↔ ∃ k, lowerCentralSeries R L M k = ⊥ := by simp [isNilpotent_iff_int, SetLike.ext'_iff, coe_lowerCentralSeries_eq_int R L M] lemma IsNilpotent.nilpotent [IsNilpotent L M] : ∃ k, lowerCentralSeries R L M k = ⊥ := (isNilpotent_iff R L M).mp ‹_› variable {R L} in lemma IsNilpotent.mk {k : ℕ} (h : lowerCentralSeries R L M k = ⊥) : IsNilpotent L M := (isNilpotent_iff R L M).mpr ⟨k, h⟩ @[simp] lemma iInf_lowerCentralSeries_eq_bot_of_isNilpotent [IsNilpotent L M] : ⨅ k, lowerCentralSeries R L M k = ⊥ := by obtain ⟨k, hk⟩ := IsNilpotent.nilpotent R L M rw [eq_bot_iff, ← hk] exact iInf_le _ _ end section variable {R L M} variable [LieModule R L M] theorem _root_.LieSubmodule.isNilpotent_iff_exists_lcs_eq_bot (N : LieSubmodule R L M) : LieModule.IsNilpotent L N ↔ ∃ k, N.lcs k = ⊥ := by rw [isNilpotent_iff R L N] refine exists_congr fun k => ?_ rw [N.lowerCentralSeries_eq_lcs_comap k, LieSubmodule.comap_incl_eq_bot, inf_eq_right.mpr (N.lcs_le_self k)] variable (R L M) instance (priority := 100) trivialIsNilpotent [IsTrivial L M] : IsNilpotent L M := ⟨by use 1; simp⟩ instance instIsNilpotentSup (M₁ M₂ : LieSubmodule R L M) [IsNilpotent L M₁] [IsNilpotent L M₂] : IsNilpotent L (M₁ ⊔ M₂ : LieSubmodule R L M) := by obtain ⟨k, hk⟩ := IsNilpotent.nilpotent R L M₁ obtain ⟨l, hl⟩ := IsNilpotent.nilpotent R L M₂ let lcs_eq_bot {m n} (N : LieSubmodule R L M) (le : m ≤ n) (hn : lowerCentralSeries R L N m = ⊥) : lowerCentralSeries R L N n = ⊥ := by simpa [hn] using antitone_lowerCentralSeries R L N le have h₁ : lowerCentralSeries R L M₁ (k ⊔ l) = ⊥ := lcs_eq_bot M₁ (Nat.le_max_left k l) hk have h₂ : lowerCentralSeries R L M₂ (k ⊔ l) = ⊥ := lcs_eq_bot M₂ (Nat.le_max_right k l) hl refine (isNilpotent_iff R L (M₁ + M₂)).mpr ⟨k ⊔ l, ?_⟩ simp [LieSubmodule.add_eq_sup, (M₁ ⊔ M₂).lowerCentralSeries_eq_lcs_comap, LieSubmodule.lcs_sup, (M₁.lowerCentralSeries_eq_bot_iff_lcs_eq_bot (k ⊔ l)).1 h₁, (M₂.lowerCentralSeries_eq_bot_iff_lcs_eq_bot (k ⊔ l)).1 h₂, LieSubmodule.comap_incl_eq_bot] theorem exists_forall_pow_toEnd_eq_zero [IsNilpotent L M] : ∃ k : ℕ, ∀ x : L, toEnd R L M x ^ k = 0 := by obtain ⟨k, hM⟩ := IsNilpotent.nilpotent R L M use k intro x; ext m rw [Module.End.pow_apply, LinearMap.zero_apply, ← @LieSubmodule.mem_bot R L M, ← hM] exact iterate_toEnd_mem_lowerCentralSeries R L M x m k theorem isNilpotent_toEnd_of_isNilpotent [IsNilpotent L M] (x : L) : _root_.IsNilpotent (toEnd R L M x) := by change ∃ k, toEnd R L M x ^ k = 0 have := exists_forall_pow_toEnd_eq_zero R L M tauto theorem isNilpotent_toEnd_of_isNilpotent₂ [IsNilpotent L M] (x y : L) : _root_.IsNilpotent (toEnd R L M x ∘ₗ toEnd R L M y) := by obtain ⟨k, hM⟩ := IsNilpotent.nilpotent R L M replace hM : lowerCentralSeries R L M (2 * k) = ⊥ := by rw [eq_bot_iff, ← hM]; exact antitone_lowerCentralSeries R L M (by cutsat) use k ext m rw [Module.End.pow_apply, LinearMap.zero_apply, ← LieSubmodule.mem_bot (R := R) (L := L), ← hM] exact iterate_toEnd_mem_lowerCentralSeries₂ R L M x y m k @[simp] lemma maxGenEigenSpace_toEnd_eq_top [IsNilpotent L M] (x : L) : ((toEnd R L M x).maxGenEigenspace 0) = ⊤ := by ext m simp only [Module.End.mem_maxGenEigenspace, zero_smul, sub_zero, Submodule.mem_top, iff_true] obtain ⟨k, hk⟩ := exists_forall_pow_toEnd_eq_zero R L M exact ⟨k, by simp [hk x]⟩ /-- If the quotient of a Lie module `M` by a Lie submodule on which the Lie algebra acts trivially is nilpotent then `M` is nilpotent. This is essentially the Lie module equivalent of the fact that a central extension of nilpotent Lie algebras is nilpotent. See `LieAlgebra.nilpotent_of_nilpotent_quotient` below for the corresponding result for Lie algebras. -/ theorem nilpotentOfNilpotentQuotient {N : LieSubmodule R L M} (h₁ : N ≤ maxTrivSubmodule R L M) (h₂ : IsNilpotent L (M ⧸ N)) : IsNilpotent L M := by rw [isNilpotent_iff R L] at h₂ ⊢ obtain ⟨k, hk⟩ := h₂ use k + 1 simp only [lowerCentralSeries_succ] suffices lowerCentralSeries R L M k ≤ N by replace this := LieSubmodule.mono_lie_right ⊤ (le_trans this h₁) rwa [ideal_oper_maxTrivSubmodule_eq_bot, le_bot_iff] at this rw [← LieSubmodule.Quotient.map_mk'_eq_bot_le, ← le_bot_iff, ← hk] exact map_lowerCentralSeries_le k (LieSubmodule.Quotient.mk' N) theorem isNilpotent_quotient_iff : IsNilpotent L (M ⧸ N) ↔ ∃ k, lowerCentralSeries R L M k ≤ N := by rw [isNilpotent_iff R L] refine exists_congr fun k ↦ ?_ rw [← LieSubmodule.Quotient.map_mk'_eq_bot_le, map_lowerCentralSeries_eq k (LieSubmodule.Quotient.surjective_mk' N)] theorem iInf_lcs_le_of_isNilpotent_quot (h : IsNilpotent L (M ⧸ N)) : ⨅ k, lowerCentralSeries R L M k ≤ N := by obtain ⟨k, hk⟩ := (isNilpotent_quotient_iff R L M N).mp h exact iInf_le_of_le k hk end /-- Given a nilpotent Lie module `M` with lower central series `M = C₀ ≥ C₁ ≥ ⋯ ≥ Cₖ = ⊥`, this is the natural number `k` (the number of inclusions). For a non-nilpotent module, we use the junk value 0. -/ noncomputable def nilpotencyLength : ℕ := sInf {k | lowerCentralSeries ℤ L M k = ⊥} @[simp] theorem nilpotencyLength_eq_zero_iff [IsNilpotent L M] : nilpotencyLength L M = 0 ↔ Subsingleton M := by let s := {k | lowerCentralSeries ℤ L M k = ⊥} have hs : s.Nonempty := by obtain ⟨k, hk⟩ := IsNilpotent.nilpotent ℤ L M exact ⟨k, hk⟩ change sInf s = 0 ↔ _ rw [← LieSubmodule.subsingleton_iff ℤ L M, ← subsingleton_iff_bot_eq_top, ← lowerCentralSeries_zero, @eq_comm (LieSubmodule ℤ L M)] refine ⟨fun h => h ▸ Nat.sInf_mem hs, fun h => ?_⟩ rw [Nat.sInf_eq_zero] exact Or.inl h section variable [LieModule R L M] theorem nilpotencyLength_eq_succ_iff (k : ℕ) : nilpotencyLength L M = k + 1 ↔ lowerCentralSeries R L M (k + 1) = ⊥ ∧ lowerCentralSeries R L M k ≠ ⊥ := by have aux (k : ℕ) : lowerCentralSeries R L M k = ⊥ ↔ lowerCentralSeries ℤ L M k = ⊥ := by simp [SetLike.ext'_iff, coe_lowerCentralSeries_eq_int R L M] let s := {k | lowerCentralSeries ℤ L M k = ⊥} rw [aux, ne_eq, aux] change sInf s = k + 1 ↔ k + 1 ∈ s ∧ k ∉ s have hs : ∀ k₁ k₂, k₁ ≤ k₂ → k₁ ∈ s → k₂ ∈ s := by rintro k₁ k₂ h₁₂ (h₁ : lowerCentralSeries ℤ L M k₁ = ⊥) exact eq_bot_iff.mpr (h₁ ▸ antitone_lowerCentralSeries ℤ L M h₁₂) exact Nat.sInf_upward_closed_eq_succ_iff hs k @[simp] theorem nilpotencyLength_eq_one_iff [Nontrivial M] : nilpotencyLength L M = 1 ↔ IsTrivial L M := by rw [nilpotencyLength_eq_succ_iff ℤ, ← trivial_iff_lower_central_eq_bot] simp theorem isTrivial_of_nilpotencyLength_le_one [IsNilpotent L M] (h : nilpotencyLength L M ≤ 1) : IsTrivial L M := by nontriviality M rcases Nat.le_one_iff_eq_zero_or_eq_one.mp h with h | h · rw [nilpotencyLength_eq_zero_iff] at h; infer_instance · rwa [nilpotencyLength_eq_one_iff] at h end /-- Given a non-trivial nilpotent Lie module `M` with lower central series `M = C₀ ≥ C₁ ≥ ⋯ ≥ Cₖ = ⊥`, this is the `k-1`th term in the lower central series (the last non-trivial term). For a trivial or non-nilpotent module, this is the bottom submodule, `⊥`. -/ noncomputable def lowerCentralSeriesLast : LieSubmodule R L M := match nilpotencyLength L M with | 0 => ⊥ | k + 1 => lowerCentralSeries R L M k theorem lowerCentralSeriesLast_le_max_triv [LieModule R L M] : lowerCentralSeriesLast R L M ≤ maxTrivSubmodule R L M := by rw [lowerCentralSeriesLast] rcases h : nilpotencyLength L M with - | k · exact bot_le · rw [le_max_triv_iff_bracket_eq_bot] rw [nilpotencyLength_eq_succ_iff R, lowerCentralSeries_succ] at h exact h.1 theorem nontrivial_lowerCentralSeriesLast [LieModule R L M] [Nontrivial M] [IsNilpotent L M] : Nontrivial (lowerCentralSeriesLast R L M) := by rw [LieSubmodule.nontrivial_iff_ne_bot, lowerCentralSeriesLast] cases h : nilpotencyLength L M · rw [nilpotencyLength_eq_zero_iff, ← not_nontrivial_iff_subsingleton] at h contradiction · rw [nilpotencyLength_eq_succ_iff R] at h exact h.2 theorem lowerCentralSeriesLast_le_of_not_isTrivial [IsNilpotent L M] (h : ¬ IsTrivial L M) : lowerCentralSeriesLast R L M ≤ lowerCentralSeries R L M 1 := by rw [lowerCentralSeriesLast] replace h : 1 < nilpotencyLength L M := by by_contra contra have := isTrivial_of_nilpotencyLength_le_one L M (not_lt.mp contra) contradiction rcases hk : nilpotencyLength L M with - | k <;> rw [hk] at h · contradiction · exact antitone_lowerCentralSeries _ _ _ (Nat.lt_succ.mp h) variable [LieModule R L M] /-- For a nilpotent Lie module `M` of a Lie algebra `L`, the first term in the lower central series of `M` contains a non-zero element on which `L` acts trivially unless the entire action is trivial. Taking `M = L`, this provides a useful characterisation of Abelian-ness for nilpotent Lie algebras. -/ lemma disjoint_lowerCentralSeries_maxTrivSubmodule_iff [IsNilpotent L M] : Disjoint (lowerCentralSeries R L M 1) (maxTrivSubmodule R L M) ↔ IsTrivial L M := by refine ⟨fun h ↦ ?_, fun h ↦ by simp⟩ nontriviality M by_contra contra have : lowerCentralSeriesLast R L M ≤ lowerCentralSeries R L M 1 ⊓ maxTrivSubmodule R L M := le_inf_iff.mpr ⟨lowerCentralSeriesLast_le_of_not_isTrivial R L M contra, lowerCentralSeriesLast_le_max_triv R L M⟩ suffices ¬ Nontrivial (lowerCentralSeriesLast R L M) by exact this (nontrivial_lowerCentralSeriesLast R L M) rw [h.eq_bot, le_bot_iff] at this exact this ▸ not_nontrivial _ theorem nontrivial_max_triv_of_isNilpotent [Nontrivial M] [IsNilpotent L M] : Nontrivial (maxTrivSubmodule R L M) := Set.nontrivial_mono (lowerCentralSeriesLast_le_max_triv R L M) (nontrivial_lowerCentralSeriesLast R L M) @[simp] theorem coe_lcs_range_toEnd_eq (k : ℕ) : (lowerCentralSeries R (toEnd R L M).range M k : Submodule R M) = lowerCentralSeries R L M k := by induction k with | zero => simp | succ k ih => simp only [lowerCentralSeries_succ, LieSubmodule.lieIdeal_oper_eq_linear_span', ← (lowerCentralSeries R (toEnd R L M).range M k).mem_toSubmodule, ih] simp @[simp] theorem isNilpotent_range_toEnd_iff : IsNilpotent (toEnd R L M).range M ↔ IsNilpotent L M := by simp only [isNilpotent_iff R _ M] constructor <;> rintro ⟨k, hk⟩ <;> use k <;> rw [← LieSubmodule.toSubmodule_inj] at hk ⊢ <;> simpa using hk end LieModule namespace LieSubmodule variable {N₁ N₂ : LieSubmodule R L M} variable [LieModule R L M] /-- The upper (aka ascending) central series. See also `LieSubmodule.lcs`. -/ def ucs (k : ℕ) : LieSubmodule R L M → LieSubmodule R L M := normalizer^[k] @[simp] theorem ucs_zero : N.ucs 0 = N := rfl @[simp] theorem ucs_succ (k : ℕ) : N.ucs (k + 1) = (N.ucs k).normalizer := Function.iterate_succ_apply' normalizer k N theorem ucs_add (k l : ℕ) : N.ucs (k + l) = (N.ucs l).ucs k := Function.iterate_add_apply normalizer k l N @[gcongr, mono] theorem ucs_mono (k : ℕ) (h : N₁ ≤ N₂) : N₁.ucs k ≤ N₂.ucs k := by induction k with | zero => simpa | succ k ih => simp only [ucs_succ] gcongr theorem ucs_eq_self_of_normalizer_eq_self (h : N₁.normalizer = N₁) (k : ℕ) : N₁.ucs k = N₁ := by induction k with | zero => simp | succ k ih => rwa [ucs_succ, ih] /-- If a Lie module `M` contains a self-normalizing Lie submodule `N`, then all terms of the upper central series of `M` are contained in `N`. An important instance of this situation arises from a Cartan subalgebra `H ⊆ L` with the roles of `L`, `M`, `N` played by `H`, `L`, `H`, respectively. -/ theorem ucs_le_of_normalizer_eq_self (h : N₁.normalizer = N₁) (k : ℕ) : (⊥ : LieSubmodule R L M).ucs k ≤ N₁ := by rw [← ucs_eq_self_of_normalizer_eq_self h k] gcongr simp theorem lcs_add_le_iff (l k : ℕ) : N₁.lcs (l + k) ≤ N₂ ↔ N₁.lcs l ≤ N₂.ucs k := by induction k generalizing l with | zero => simp | succ k ih => rw [(by abel : l + (k + 1) = l + 1 + k), ih, ucs_succ, lcs_succ, top_lie_le_iff_le_normalizer] theorem lcs_le_iff (k : ℕ) : N₁.lcs k ≤ N₂ ↔ N₁ ≤ N₂.ucs k := by convert lcs_add_le_iff (R := R) (L := L) (M := M) 0 k rw [zero_add] theorem gc_lcs_ucs (k : ℕ) : GaloisConnection (fun N : LieSubmodule R L M => N.lcs k) fun N : LieSubmodule R L M => N.ucs k := fun _ _ => lcs_le_iff k theorem ucs_eq_top_iff (k : ℕ) : N.ucs k = ⊤ ↔ LieModule.lowerCentralSeries R L M k ≤ N := by rw [eq_top_iff, ← lcs_le_iff]; rfl variable (R) in theorem _root_.LieModule.isNilpotent_iff_exists_ucs_eq_top : LieModule.IsNilpotent L M ↔ ∃ k, (⊥ : LieSubmodule R L M).ucs k = ⊤ := by rw [LieModule.isNilpotent_iff R]; exact exists_congr fun k => by simp [ucs_eq_top_iff] theorem ucs_comap_incl (k : ℕ) : ((⊥ : LieSubmodule R L M).ucs k).comap N.incl = (⊥ : LieSubmodule R L N).ucs k := by induction k with | zero => exact N.ker_incl | succ k ih => simp [← ih] theorem isNilpotent_iff_exists_self_le_ucs : LieModule.IsNilpotent L N ↔ ∃ k, N ≤ (⊥ : LieSubmodule R L M).ucs k := by simp_rw [LieModule.isNilpotent_iff_exists_ucs_eq_top R, ← ucs_comap_incl, comap_incl_eq_top] theorem ucs_bot_one : (⊥ : LieSubmodule R L M).ucs 1 = LieModule.maxTrivSubmodule R L M := by simp [LieSubmodule.normalizer_bot_eq_maxTrivSubmodule] end LieSubmodule section Morphisms open LieModule Function variable [LieModule R L M] variable {L₂ M₂ : Type*} [LieRing L₂] [LieAlgebra R L₂] variable [AddCommGroup M₂] [Module R M₂] [LieRingModule L₂ M₂] variable {f : L →ₗ⁅R⁆ L₂} {g : M →ₗ[R] M₂} variable (hfg : ∀ x m, ⁅f x, g m⁆ = g ⁅x, m⁆) include hfg in theorem lieModule_lcs_map_le (k : ℕ) : (lowerCentralSeries R L M k : Submodule R M).map g ≤ lowerCentralSeries R L₂ M₂ k := by induction k with | zero => simp [Submodule.map_top] | succ k ih => rw [lowerCentralSeries_succ, LieSubmodule.lieIdeal_oper_eq_linear_span', Submodule.map_span, Submodule.span_le] rintro m₂ ⟨m, ⟨x, n, m_n, ⟨h₁, h₂⟩⟩, rfl⟩ simp only [lowerCentralSeries_succ, SetLike.mem_coe, LieSubmodule.mem_toSubmodule] have : ∃ y : L₂, ∃ n : lowerCentralSeries R L₂ M₂ k, ⁅y, n⁆ = g m := by use f x, ⟨g m_n, ih (Submodule.mem_map_of_mem h₁)⟩ simp [hfg x m_n, h₂] obtain ⟨y, n, hn⟩ := this rw [← hn] apply LieSubmodule.lie_mem_lie · simp · exact SetLike.coe_mem n variable [LieModule R L₂ M₂] (hg_inj : Injective g) include hg_inj hfg in theorem Function.Injective.lieModuleIsNilpotent [IsNilpotent L₂ M₂] : IsNilpotent L M := by obtain ⟨k, hk⟩ := IsNilpotent.nilpotent R L₂ M₂ rw [isNilpotent_iff R] use k rw [← LieSubmodule.toSubmodule_inj] at hk ⊢ apply Submodule.map_injective_of_injective hg_inj simpa [hk] using lieModule_lcs_map_le hfg k variable (hf_surj : Surjective f) (hg_surj : Surjective g) include hf_surj hg_surj hfg in theorem Function.Surjective.lieModule_lcs_map_eq (k : ℕ) : (lowerCentralSeries R L M k : Submodule R M).map g = lowerCentralSeries R L₂ M₂ k := by refine le_antisymm (lieModule_lcs_map_le hfg k) ?_ induction k with | zero => simpa [LinearMap.range_eq_top] | succ k ih => suffices {m | ∃ (x : L₂) (n : _), n ∈ lowerCentralSeries R L M k ∧ ⁅x, g n⁆ = m} ⊆ g '' {m | ∃ (x : L) (n : _), n ∈ lowerCentralSeries R L M k ∧ ⁅x, n⁆ = m} by simp only [← LieSubmodule.mem_toSubmodule] at this simp_rw [lowerCentralSeries_succ, LieSubmodule.lieIdeal_oper_eq_linear_span', Submodule.map_span, LieSubmodule.mem_top, true_and, ← LieSubmodule.mem_toSubmodule] refine Submodule.span_mono (Set.Subset.trans ?_ this) rintro m₁ ⟨x, n, hn, rfl⟩ obtain ⟨n', hn', rfl⟩ := ih hn exact ⟨x, n', hn', rfl⟩ rintro m₂ ⟨x, n, hn, rfl⟩ obtain ⟨y, rfl⟩ := hf_surj x exact ⟨⁅y, n⁆, ⟨y, n, hn, rfl⟩, (hfg y n).symm⟩ include hf_surj hg_surj hfg in theorem Function.Surjective.lieModuleIsNilpotent [IsNilpotent L M] : IsNilpotent L₂ M₂ := by obtain ⟨k, hk⟩ := IsNilpotent.nilpotent R L M rw [isNilpotent_iff R] use k rw [← LieSubmodule.toSubmodule_inj] at hk ⊢ simp [← hf_surj.lieModule_lcs_map_eq hfg hg_surj k, hk] theorem Equiv.lieModule_isNilpotent_iff (f : L ≃ₗ⁅R⁆ L₂) (g : M ≃ₗ[R] M₂) (hfg : ∀ x m, ⁅f x, g m⁆ = g ⁅x, m⁆) : IsNilpotent L M ↔ IsNilpotent L₂ M₂ := by constructor <;> intro h · have hg : Surjective (g : M →ₗ[R] M₂) := g.surjective exact f.surjective.lieModuleIsNilpotent hfg hg · have hg : Surjective (g.symm : M₂ →ₗ[R] M) := g.symm.surjective refine f.symm.surjective.lieModuleIsNilpotent (fun x m => ?_) hg rw [LinearEquiv.coe_coe, LieEquiv.coe_toLieHom, ← g.symm_apply_apply ⁅f.symm x, g.symm m⁆, ← hfg, f.apply_symm_apply, g.apply_symm_apply] @[simp] theorem LieModule.isNilpotent_of_top_iff : IsNilpotent (⊤ : LieSubalgebra R L) M ↔ IsNilpotent L M := Equiv.lieModule_isNilpotent_iff LieSubalgebra.topEquiv (1 : M ≃ₗ[R] M) fun _ _ => rfl @[simp] lemma LieModule.isNilpotent_of_top_iff' : IsNilpotent L {x // x ∈ (⊤ : LieSubmodule R L M)} ↔ IsNilpotent L M := Equiv.lieModule_isNilpotent_iff 1 (LinearEquiv.ofTop ⊤ rfl) fun _ _ ↦ rfl end Morphisms namespace LieModule variable (R L M) variable [LieModule R L M] theorem isNilpotent_of_le (M₁ M₂ : LieSubmodule R L M) (h₁ : M₁ ≤ M₂) [IsNilpotent L M₂] : IsNilpotent L M₁ := by let f : L →ₗ⁅R⁆ L := LieHom.id let g : M₁ →ₗ[R] M₂ := Submodule.inclusion h₁ have hfg : ∀ x m, ⁅f x, g m⁆ = g ⁅x, m⁆ := by aesop exact (Submodule.inclusion_injective h₁).lieModuleIsNilpotent hfg /-- The max nilpotent submodule is the `sSup` of all nilpotent submodules. -/ def maxNilpotentSubmodule := sSup { N : LieSubmodule R L M | IsNilpotent L N } instance instMaxNilpotentSubmoduleIsNilpotent [IsNoetherian R M] : IsNilpotent L (maxNilpotentSubmodule R L M) := by have hwf := CompleteLattice.WellFoundedGT.isSupClosedCompact (LieSubmodule R L M) inferInstance refine hwf { N : LieSubmodule R L M | IsNilpotent L N } ⟨⊥, ?_⟩ fun N₁ h₁ N₂ h₂ => ?_ <;> simp_all <;> infer_instance theorem isNilpotent_iff_le_maxNilpotentSubmodule [IsNoetherian R M] (N : LieSubmodule R L M) : IsNilpotent L N ↔ N ≤ maxNilpotentSubmodule R L M := ⟨fun h ↦ le_sSup h, fun h ↦ isNilpotent_of_le R L M N (maxNilpotentSubmodule R L M) h⟩ @[simp] lemma maxNilpotentSubmodule_eq_top_of_isNilpotent [LieModule.IsNilpotent L M] : maxNilpotentSubmodule R L M = ⊤ := by rw [eq_top_iff] apply le_sSup simpa end LieModule end NilpotentModules instance (priority := 100) LieAlgebra.isSolvable_of_isNilpotent (L : Type v) [LieRing L] [hL : LieModule.IsNilpotent L L] : LieAlgebra.IsSolvable L := by obtain ⟨k, h⟩ : ∃ k, LieModule.lowerCentralSeries ℤ L L k = ⊥ := hL.nilpotent_int use k; rw [← le_bot_iff] at h ⊢ exact le_trans (LieModule.derivedSeries_le_lowerCentralSeries ℤ L k) h section NilpotentAlgebras variable (R : Type u) (L : Type v) (L' : Type w) variable [CommRing R] [LieRing L] [LieAlgebra R L] [LieRing L'] [LieAlgebra R L'] /-- We say a Lie ring is nilpotent when it is nilpotent as a Lie module over itself via the adjoint representation. -/ abbrev LieRing.IsNilpotent (L : Type v) [LieRing L] : Prop := LieModule.IsNilpotent L L open LieRing theorem LieAlgebra.nilpotent_ad_of_nilpotent_algebra [IsNilpotent L] : ∃ k : ℕ, ∀ x : L, ad R L x ^ k = 0 := LieModule.exists_forall_pow_toEnd_eq_zero R L L -- TODO Generalise the below to Lie modules if / when we define morphisms, equivs of Lie modules -- covering a Lie algebra morphism of (possibly different) Lie algebras. variable {R L L'} open LieModule (lowerCentralSeries) /-- Given an ideal `I` of a Lie algebra `L`, the lower central series of `L ⧸ I` is the same whether we regard `L ⧸ I` as an `L` module or an `L ⧸ I` module. TODO: This result obviously generalises but the generalisation requires the missing definition of morphisms between Lie modules over different Lie algebras. -/ -- Porting note: added `LieSubmodule.toSubmodule` in the statement theorem coe_lowerCentralSeries_ideal_quot_eq {I : LieIdeal R L} (k : ℕ) : LieSubmodule.toSubmodule (lowerCentralSeries R L (L ⧸ I) k) = LieSubmodule.toSubmodule (lowerCentralSeries R (L ⧸ I) (L ⧸ I) k) := by induction k with | zero => simp only [LieModule.lowerCentralSeries_zero, LieSubmodule.top_toSubmodule] | succ k ih => simp only [LieModule.lowerCentralSeries_succ, LieSubmodule.lieIdeal_oper_eq_linear_span] congr ext x constructor · rintro ⟨⟨y, -⟩, ⟨z, hz⟩, rfl : ⁅y, z⁆ = x⟩ rw [← LieSubmodule.mem_toSubmodule, ih, LieSubmodule.mem_toSubmodule] at hz exact ⟨⟨LieSubmodule.Quotient.mk y, LieSubmodule.mem_top _⟩, ⟨z, hz⟩, rfl⟩ · rintro ⟨⟨⟨y⟩, -⟩, ⟨z, hz⟩, rfl : ⁅y, z⁆ = x⟩ rw [← LieSubmodule.mem_toSubmodule, ← ih, LieSubmodule.mem_toSubmodule] at hz exact ⟨⟨y, LieSubmodule.mem_top _⟩, ⟨z, hz⟩, rfl⟩ /-- Note that the below inequality can be strict. For example the ideal of strictly-upper-triangular 2x2 matrices inside the Lie algebra of upper-triangular 2x2 matrices with `k = 1`. -/ -- Porting note: added `LieSubmodule.toSubmodule` in the statement theorem LieModule.coe_lowerCentralSeries_ideal_le {I : LieIdeal R L} (k : ℕ) : LieSubmodule.toSubmodule (lowerCentralSeries R I I k) ≤ lowerCentralSeries R L I k := by induction k with | zero => simp | succ k ih => simp only [LieModule.lowerCentralSeries_succ, LieSubmodule.lieIdeal_oper_eq_linear_span] apply Submodule.span_mono rintro x ⟨⟨y, -⟩, ⟨z, hz⟩, rfl : ⁅y, z⁆ = x⟩ exact ⟨⟨y.val, LieSubmodule.mem_top _⟩, ⟨z, ih hz⟩, rfl⟩ /-- A central extension of nilpotent Lie algebras is nilpotent. -/ theorem LieAlgebra.nilpotent_of_nilpotent_quotient {I : LieIdeal R L} (h₁ : I ≤ center R L) (h₂ : IsNilpotent (L ⧸ I)) : IsNilpotent L := by suffices LieModule.IsNilpotent L (L ⧸ I) by exact LieModule.nilpotentOfNilpotentQuotient R L L h₁ this simp only [LieRing.IsNilpotent, LieModule.isNilpotent_iff R] at h₂ ⊢ peel h₂ with k hk simp [← LieSubmodule.toSubmodule_inj, coe_lowerCentralSeries_ideal_quot_eq, hk] theorem LieAlgebra.non_trivial_center_of_isNilpotent [Nontrivial L] [IsNilpotent L] : Nontrivial <| center R L := LieModule.nontrivial_max_triv_of_isNilpotent R L L theorem LieIdeal.map_lowerCentralSeries_le (k : ℕ) {f : L →ₗ⁅R⁆ L'} : LieIdeal.map f (lowerCentralSeries R L L k) ≤ lowerCentralSeries R L' L' k := by induction k with | zero => simp only [LieModule.lowerCentralSeries_zero, le_top] | succ k ih => simp only [LieModule.lowerCentralSeries_succ] exact le_trans (LieIdeal.map_bracket_le f) (LieSubmodule.mono_lie le_top ih) theorem LieIdeal.lowerCentralSeries_map_eq (k : ℕ) {f : L →ₗ⁅R⁆ L'} (h : Function.Surjective f) : LieIdeal.map f (lowerCentralSeries R L L k) = lowerCentralSeries R L' L' k := by have h' : (⊤ : LieIdeal R L).map f = ⊤ := by rw [← f.idealRange_eq_map] exact f.idealRange_eq_top_of_surjective h induction k with | zero => simp only [LieModule.lowerCentralSeries_zero]; exact h' | succ k ih => simp only [LieModule.lowerCentralSeries_succ, LieIdeal.map_bracket_eq f h, ih, h'] theorem Function.Injective.lieAlgebra_isNilpotent [h₁ : IsNilpotent L'] {f : L →ₗ⁅R⁆ L'} (h₂ : Function.Injective f) : IsNilpotent L := by rw [LieRing.IsNilpotent, LieModule.isNilpotent_iff R] at h₁ ⊢ peel h₁ with k hk apply LieIdeal.bot_of_map_eq_bot h₂; rw [eq_bot_iff, ← hk] apply LieIdeal.map_lowerCentralSeries_le theorem Function.Surjective.lieAlgebra_isNilpotent [h₁ : IsNilpotent L] {f : L →ₗ⁅R⁆ L'} (h₂ : Function.Surjective f) : IsNilpotent L' := by rw [LieRing.IsNilpotent, LieModule.isNilpotent_iff R] at h₁ ⊢ peel h₁ with k hk rw [← LieIdeal.lowerCentralSeries_map_eq k h₂, hk] simp only [LieIdeal.map_eq_bot_iff, bot_le] theorem LieEquiv.nilpotent_iff_equiv_nilpotent (e : L ≃ₗ⁅R⁆ L') : IsNilpotent L ↔ IsNilpotent L' := by constructor <;> intro h · exact e.symm.injective.lieAlgebra_isNilpotent · exact e.injective.lieAlgebra_isNilpotent theorem LieHom.isNilpotent_range [IsNilpotent L] (f : L →ₗ⁅R⁆ L') : IsNilpotent f.range := f.surjective_rangeRestrict.lieAlgebra_isNilpotent /-- Note that this result is not quite a special case of `LieModule.isNilpotent_range_toEnd_iff` which concerns nilpotency of the `(ad R L).range`-module `L`, whereas this result concerns nilpotency of the `(ad R L).range`-module `(ad R L).range`. -/ @[simp] theorem LieAlgebra.isNilpotent_range_ad_iff : IsNilpotent (ad R L).range ↔ IsNilpotent L := by refine ⟨fun h => ?_, ?_⟩ · have : (ad R L).ker = center R L := by simp exact LieAlgebra.nilpotent_of_nilpotent_quotient (le_of_eq this) ((ad R L).quotKerEquivRange.nilpotent_iff_equiv_nilpotent.mpr h) · intro h exact (ad R L).isNilpotent_range instance [h : LieRing.IsNilpotent L] : LieRing.IsNilpotent (⊤ : LieSubalgebra R L) := LieSubalgebra.topEquiv.nilpotent_iff_equiv_nilpotent.mpr h end NilpotentAlgebras namespace LieIdeal open LieModule variable {R L : Type*} [CommRing R] [LieRing L] [LieAlgebra R L] (I : LieIdeal R L) variable (M : Type*) [AddCommGroup M] [Module R M] [LieRingModule L M] variable (k : ℕ) /-- Given a Lie module `M` over a Lie algebra `L` together with an ideal `I` of `L`, this is the lower central series of `M` as an `I`-module. The advantage of using this definition instead of `LieModule.lowerCentralSeries R I M` is that its terms are Lie submodules of `M` as an `L`-module, rather than just as an `I`-module. See also `LieIdeal.coe_lcs_eq`. -/ def lcs : LieSubmodule R L M := (fun N => ⁅I, N⁆)^[k] ⊤ @[simp] theorem lcs_zero : I.lcs M 0 = ⊤ := rfl @[simp] theorem lcs_succ : I.lcs M (k + 1) = ⁅I, I.lcs M k⁆ := Function.iterate_succ_apply' (fun N => ⁅I, N⁆) k ⊤ theorem lcs_top : (⊤ : LieIdeal R L).lcs M k = lowerCentralSeries R L M k := rfl -- Porting note: added `LieSubmodule.toSubmodule` in the statement theorem coe_lcs_eq [LieModule R L M] : LieSubmodule.toSubmodule (I.lcs M k) = lowerCentralSeries R I M k := by induction k with | zero => simp | succ k ih => simp_rw [lowerCentralSeries_succ, lcs_succ, LieSubmodule.lieIdeal_oper_eq_linear_span', ← (I.lcs M k).mem_toSubmodule, ih, LieSubmodule.mem_toSubmodule, LieSubmodule.mem_top, true_and, (I : LieSubalgebra R L).coe_bracket_of_module] simp instance [IsNilpotent L I] : LieRing.IsNilpotent I := by let f : I →ₗ⁅R⁆ L := I.incl let g : I →ₗ⁅R⁆ I := LieHom.id have hfg : ∀ x m, ⁅f x, g m⁆ = g ⁅x, m⁆ := by aesop exact Function.injective_id.lieModuleIsNilpotent hfg end LieIdeal section OfAssociative variable (R : Type u) {A : Type v} [CommRing R] [Ring A] [Algebra R A] theorem _root_.LieAlgebra.ad_nilpotent_of_nilpotent {a : A} (h : IsNilpotent a) : IsNilpotent (LieAlgebra.ad R A a) := by rw [LieAlgebra.ad_eq_lmul_left_sub_lmul_right] have hl : IsNilpotent (LinearMap.mulLeft R a) := by rwa [LinearMap.isNilpotent_mulLeft_iff] have hr : IsNilpotent (LinearMap.mulRight R a) := by rwa [LinearMap.isNilpotent_mulRight_iff] have := @LinearMap.commute_mulLeft_right R A _ _ _ _ _ a a exact this.isNilpotent_sub hl hr variable {R} theorem _root_.LieSubalgebra.isNilpotent_ad_of_isNilpotent_ad {L : Type v} [LieRing L] [LieAlgebra R L] (K : LieSubalgebra R L) {x : K} (h : IsNilpotent (LieAlgebra.ad R L ↑x)) : IsNilpotent (LieAlgebra.ad R K x) := by obtain ⟨n, hn⟩ := h use n exact Module.End.submodule_pow_eq_zero_of_pow_eq_zero (K.ad_comp_incl_eq x) hn theorem _root_.LieAlgebra.isNilpotent_ad_of_isNilpotent {L : LieSubalgebra R A} {x : L} (h : IsNilpotent (x : A)) : IsNilpotent (LieAlgebra.ad R L x) := L.isNilpotent_ad_of_isNilpotent_ad <| LieAlgebra.ad_nilpotent_of_nilpotent R h end OfAssociative section ExtendScalars open LieModule TensorProduct variable (R A L M : Type*) [CommRing R] [LieRing L] [LieAlgebra R L] [AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M] [CommRing A] [Algebra R A] @[simp] lemma LieSubmodule.lowerCentralSeries_tensor_eq_baseChange (k : ℕ) : lowerCentralSeries A (A ⊗[R] L) (A ⊗[R] M) k = (lowerCentralSeries R L M k).baseChange A := by induction k with | zero => simp | succ k ih => simp only [lowerCentralSeries_succ, ih, ← baseChange_top, lie_baseChange] instance LieModule.instIsNilpotentTensor [IsNilpotent L M] : IsNilpotent (A ⊗[R] L) (A ⊗[R] M) := by obtain ⟨k, hk⟩ := IsNilpotent.nilpotent R L M rw [isNilpotent_iff A] exact ⟨k, by simp [hk]⟩ end ExtendScalars namespace LieAlgebra open LieModule variable (R : Type u) (L : Type v) variable [CommRing R] [LieRing L] [LieAlgebra R L] /-- The max nilpotent ideal of a Lie algebra. It is defined as the max nilpotent Lie submodule of `L` under the adjoint action. -/ def maxNilpotentIdeal := maxNilpotentSubmodule R L L instance maxNilpotentIdealIsNilpotent [IsNoetherian R L] : IsNilpotent L (maxNilpotentIdeal R L) := instMaxNilpotentSubmoduleIsNilpotent R L L theorem LieIdeal.isNilpotent_iff_le_maxNilpotentIdeal [IsNoetherian R L] (I : LieIdeal R L) : IsNilpotent L I ↔ I ≤ maxNilpotentIdeal R L := isNilpotent_iff_le_maxNilpotentSubmodule R L L I theorem center_le_maxNilpotentIdeal : center R L ≤ maxNilpotentIdeal R L := le_sSup (trivialIsNilpotent L (center R L)) theorem maxNilpotentIdeal_le_radical : maxNilpotentIdeal R L ≤ radical R L := sSup_le_sSup fun I (_ : IsNilpotent L I) ↦ isSolvable_of_isNilpotent I @[simp] lemma maxNilpotentIdeal_eq_top_of_isNilpotent [LieRing.IsNilpotent L] : maxNilpotentIdeal R L = ⊤ := maxNilpotentSubmodule_eq_top_of_isNilpotent R L L end LieAlgebra
.lake/packages/mathlib/Mathlib/Algebra/Lie/Solvable.lean
import Mathlib.Algebra.Lie.Abelian import Mathlib.Algebra.Lie.BaseChange import Mathlib.Algebra.Lie.IdealOperations import Mathlib.Order.Hom.Basic import Mathlib.RingTheory.Flat.FaithfullyFlat.Basic /-! # Solvable Lie algebras Like groups, Lie algebras admit a natural concept of solvability. We define this here via the derived series and prove some related results. We also define the radical of a Lie algebra and prove that it is solvable when the Lie algebra is Noetherian. ## Main definitions * `LieAlgebra.derivedSeriesOfIdeal` * `LieAlgebra.derivedSeries` * `LieAlgebra.IsSolvable` * `LieAlgebra.isSolvableAdd` * `LieAlgebra.radical` * `LieAlgebra.radicalIsSolvable` * `LieAlgebra.derivedLengthOfIdeal` * `LieAlgebra.derivedLength` * `LieAlgebra.derivedAbelianOfIdeal` ## Tags lie algebra, derived series, derived length, solvable, radical -/ universe u v w w₁ w₂ variable (R : Type u) (L : Type v) (M : Type w) {L' : Type w₁} variable [CommRing R] [LieRing L] [LieAlgebra R L] [LieRing L'] [LieAlgebra R L'] variable (I J : LieIdeal R L) {f : L' →ₗ⁅R⁆ L} namespace LieAlgebra /-- A generalisation of the derived series of a Lie algebra, whose zeroth term is a specified ideal. It can be more convenient to work with this generalisation when considering the derived series of an ideal since it provides a type-theoretic expression of the fact that the terms of the ideal's derived series are also ideals of the enclosing algebra. See also `LieIdeal.derivedSeries_eq_derivedSeriesOfIdeal_comap` and `LieIdeal.derivedSeries_eq_derivedSeriesOfIdeal_map` below. -/ def derivedSeriesOfIdeal (k : ℕ) : LieIdeal R L → LieIdeal R L := (fun I => ⁅I, I⁆)^[k] @[simp] theorem derivedSeriesOfIdeal_zero : derivedSeriesOfIdeal R L 0 I = I := rfl @[simp] theorem derivedSeriesOfIdeal_succ (k : ℕ) : derivedSeriesOfIdeal R L (k + 1) I = ⁅derivedSeriesOfIdeal R L k I, derivedSeriesOfIdeal R L k I⁆ := Function.iterate_succ_apply' (fun I => ⁅I, I⁆) k I /-- The derived series of Lie ideals of a Lie algebra. -/ abbrev derivedSeries (k : ℕ) : LieIdeal R L := derivedSeriesOfIdeal R L k ⊤ theorem derivedSeries_def (k : ℕ) : derivedSeries R L k = derivedSeriesOfIdeal R L k ⊤ := rfl variable {R L} local notation "D" => derivedSeriesOfIdeal R L theorem derivedSeriesOfIdeal_add (k l : ℕ) : D (k + l) I = D k (D l I) := by induction k with | zero => rw [Nat.zero_add, derivedSeriesOfIdeal_zero] | succ k ih => rw [Nat.succ_add k l, derivedSeriesOfIdeal_succ, derivedSeriesOfIdeal_succ, ih] @[gcongr, mono] theorem derivedSeriesOfIdeal_le {I J : LieIdeal R L} {k l : ℕ} (h₁ : I ≤ J) (h₂ : l ≤ k) : D k I ≤ D l J := by induction k generalizing l with | zero => rw [le_zero_iff] at h₂; rw [h₂, derivedSeriesOfIdeal_zero]; exact h₁ | succ k ih => have h : l = k.succ ∨ l ≤ k := by rwa [le_iff_eq_or_lt, Nat.lt_succ_iff] at h₂ rcases h with h | h · rw [h, derivedSeriesOfIdeal_succ, derivedSeriesOfIdeal_succ] exact LieSubmodule.mono_lie (ih (le_refl k)) (ih (le_refl k)) · rw [derivedSeriesOfIdeal_succ]; exact le_trans (LieSubmodule.lie_le_left _ _) (ih h) theorem derivedSeriesOfIdeal_succ_le (k : ℕ) : D (k + 1) I ≤ D k I := derivedSeriesOfIdeal_le (le_refl I) k.le_succ theorem derivedSeriesOfIdeal_le_self (k : ℕ) : D k I ≤ I := derivedSeriesOfIdeal_le (le_refl I) (zero_le k) theorem derivedSeriesOfIdeal_mono {I J : LieIdeal R L} (h : I ≤ J) (k : ℕ) : D k I ≤ D k J := derivedSeriesOfIdeal_le h (le_refl k) theorem derivedSeriesOfIdeal_antitone {k l : ℕ} (h : l ≤ k) : D k I ≤ D l I := derivedSeriesOfIdeal_le (le_refl I) h theorem derivedSeriesOfIdeal_add_le_add (J : LieIdeal R L) (k l : ℕ) : D (k + l) (I + J) ≤ D k I + D l J := by let D₁ : LieIdeal R L →o LieIdeal R L := { toFun := fun I => ⁅I, I⁆ monotone' := fun I J h => LieSubmodule.mono_lie h h } have h₁ : ∀ I J : LieIdeal R L, D₁ (I ⊔ J) ≤ D₁ I ⊔ J := by simp [D₁, LieSubmodule.lie_le_right, LieSubmodule.lie_le_left, le_sup_of_le_right] rw [← D₁.iterate_sup_le_sup_iff] at h₁ exact h₁ k l I J theorem derivedSeries_of_bot_eq_bot (k : ℕ) : derivedSeriesOfIdeal R L k ⊥ = ⊥ := by rw [eq_bot_iff]; exact derivedSeriesOfIdeal_le_self ⊥ k theorem abelian_iff_derived_one_eq_bot : IsLieAbelian I ↔ derivedSeriesOfIdeal R L 1 I = ⊥ := by rw [derivedSeriesOfIdeal_succ, derivedSeriesOfIdeal_zero, LieSubmodule.lie_abelian_iff_lie_self_eq_bot] theorem abelian_iff_derived_succ_eq_bot (I : LieIdeal R L) (k : ℕ) : IsLieAbelian (derivedSeriesOfIdeal R L k I) ↔ derivedSeriesOfIdeal R L (k + 1) I = ⊥ := by rw [add_comm, derivedSeriesOfIdeal_add I 1 k, abelian_iff_derived_one_eq_bot] open TensorProduct in @[simp] theorem derivedSeriesOfIdeal_baseChange {A : Type*} [CommRing A] [Algebra R A] (k : ℕ) : derivedSeriesOfIdeal A (A ⊗[R] L) k (I.baseChange A) = (derivedSeriesOfIdeal R L k I).baseChange A := by induction k with | zero => simp | succ k ih => simp only [derivedSeriesOfIdeal_succ, ih, LieSubmodule.lie_baseChange] open TensorProduct in @[simp] theorem derivedSeries_baseChange {A : Type*} [CommRing A] [Algebra R A] (k : ℕ) : derivedSeries A (A ⊗[R] L) k = (derivedSeries R L k).baseChange A := by rw [derivedSeries_def, derivedSeries_def, ← derivedSeriesOfIdeal_baseChange, LieSubmodule.baseChange_top] end LieAlgebra namespace LieIdeal open LieAlgebra variable {R L} theorem derivedSeries_eq_derivedSeriesOfIdeal_comap (k : ℕ) : derivedSeries R I k = (derivedSeriesOfIdeal R L k I).comap I.incl := by induction k with | zero => simp only [derivedSeries_def, comap_incl_self, derivedSeriesOfIdeal_zero] | succ k ih => simp only [derivedSeries_def, derivedSeriesOfIdeal_succ] at ih ⊢; rw [ih] exact comap_bracket_incl_of_le I (derivedSeriesOfIdeal_le_self I k) (derivedSeriesOfIdeal_le_self I k) theorem derivedSeries_eq_derivedSeriesOfIdeal_map (k : ℕ) : (derivedSeries R I k).map I.incl = derivedSeriesOfIdeal R L k I := by rw [derivedSeries_eq_derivedSeriesOfIdeal_comap, map_comap_incl, inf_eq_right] apply derivedSeriesOfIdeal_le_self theorem derivedSeries_eq_bot_iff (k : ℕ) : derivedSeries R I k = ⊥ ↔ derivedSeriesOfIdeal R L k I = ⊥ := by rw [← derivedSeries_eq_derivedSeriesOfIdeal_map, map_eq_bot_iff, ker_incl, eq_bot_iff] theorem derivedSeries_add_eq_bot {k l : ℕ} {I J : LieIdeal R L} (hI : derivedSeries R I k = ⊥) (hJ : derivedSeries R J l = ⊥) : derivedSeries R (I + J) (k + l) = ⊥ := by rw [LieIdeal.derivedSeries_eq_bot_iff] at hI hJ ⊢ rw [← le_bot_iff] let D := derivedSeriesOfIdeal R L; change D k I = ⊥ at hI; change D l J = ⊥ at hJ calc D (k + l) (I + J) ≤ D k I + D l J := derivedSeriesOfIdeal_add_le_add I J k l _ ≤ ⊥ := by rw [hI, hJ]; simp theorem derivedSeries_map_le (k : ℕ) : (derivedSeries R L' k).map f ≤ derivedSeries R L k := by induction k with | zero => simp only [derivedSeries_def, derivedSeriesOfIdeal_zero, le_top] | succ k ih => simp only [derivedSeries_def, derivedSeriesOfIdeal_succ] at ih ⊢ exact le_trans (map_bracket_le f) (LieSubmodule.mono_lie ih ih) theorem derivedSeries_map_eq (k : ℕ) (h : Function.Surjective f) : (derivedSeries R L' k).map f = derivedSeries R L k := by induction k with | zero => change (⊤ : LieIdeal R L').map f = ⊤ rw [← f.idealRange_eq_map] exact f.idealRange_eq_top_of_surjective h | succ k ih => simp only [derivedSeries_def, map_bracket_eq f h, ih, derivedSeriesOfIdeal_succ] theorem derivedSeries_succ_eq_top_iff (n : ℕ) : derivedSeries R L (n + 1) = ⊤ ↔ derivedSeries R L 1 = ⊤ := by simp only [derivedSeries_def] induction n with | zero => simp | succ n ih => rw [derivedSeriesOfIdeal_succ] refine ⟨fun h ↦ ?_, fun h ↦ by rwa [ih.mpr h]⟩ rw [← ih, eq_top_iff] conv_lhs => rw [← h] exact LieSubmodule.lie_le_right _ _ theorem derivedSeries_eq_top (n : ℕ) (h : derivedSeries R L 1 = ⊤) : derivedSeries R L n = ⊤ := by cases n · rfl · rwa [derivedSeries_succ_eq_top_iff] private theorem coe_derivedSeries_eq_int_aux (R₁ R₂ L : Type*) [CommRing R₁] [CommRing R₂] [LieRing L] [LieAlgebra R₁ L] [LieAlgebra R₂ L] (k : ℕ) (ih : ∀ (x : L), x ∈ derivedSeriesOfIdeal R₁ L k ⊤ ↔ x ∈ derivedSeriesOfIdeal R₂ L k ⊤) : let I := derivedSeriesOfIdeal R₂ L k ⊤; let S : Set L := {⁅a, b⁆ | (a ∈ I) (b ∈ I)} (Submodule.span R₁ S : Set L) ≤ (Submodule.span R₂ S : Set L) := by intro I S x hx simp only [SetLike.mem_coe] at hx ⊢ induction hx using Submodule.closure_induction with | zero => exact Submodule.zero_mem _ | add y z hy₁ hz₁ hy₂ hz₂ => exact Submodule.add_mem _ hy₂ hz₂ | smul_mem c y hy => obtain ⟨a, ha, b, hb, rfl⟩ := hy rw [← smul_lie] refine Submodule.subset_span ⟨c • a, ?_, b, hb, rfl⟩ rw [← ih] at ha ⊢ exact Submodule.smul_mem _ _ ha theorem coe_derivedSeries_eq_int (k : ℕ) : (derivedSeries R L k : Set L) = (derivedSeries ℤ L k : Set L) := by rw [← LieSubmodule.coe_toSubmodule, ← LieSubmodule.coe_toSubmodule, derivedSeries_def, derivedSeries_def] induction k with | zero => rfl | succ k ih => rw [derivedSeriesOfIdeal_succ, derivedSeriesOfIdeal_succ] rw [LieSubmodule.lieIdeal_oper_eq_linear_span', LieSubmodule.lieIdeal_oper_eq_linear_span'] rw [Set.ext_iff] at ih simp only [SetLike.mem_coe, LieSubmodule.mem_toSubmodule] at ih simp only [ih] apply le_antisymm · exact coe_derivedSeries_eq_int_aux _ _ L k ih · simp end LieIdeal namespace LieAlgebra /-- A Lie algebra is solvable if its derived series reaches 0 (in a finite number of steps). -/ @[mk_iff isSolvable_iff_int] class IsSolvable : Prop where mk_int :: solvable_int : ∃ k, derivedSeries ℤ L k = ⊥ instance isSolvableBot : IsSolvable (⊥ : LieIdeal R L) := ⟨⟨0, Subsingleton.elim _ ⊥⟩⟩ lemma isSolvable_iff : IsSolvable L ↔ ∃ k, derivedSeries R L k = ⊥ := by simp [isSolvable_iff_int, SetLike.ext'_iff, LieIdeal.coe_derivedSeries_eq_int] lemma IsSolvable.solvable [IsSolvable L] : ∃ k, derivedSeries R L k = ⊥ := (isSolvable_iff R L).mp ‹_› variable {R L} in lemma IsSolvable.mk {k : ℕ} (h : derivedSeries R L k = ⊥) : IsSolvable L := (isSolvable_iff R L).mpr ⟨k, h⟩ instance isSolvableAdd {I J : LieIdeal R L} [IsSolvable I] [IsSolvable J] : IsSolvable (I + J) := by obtain ⟨k, hk⟩ := IsSolvable.solvable R I obtain ⟨l, hl⟩ := IsSolvable.solvable R J exact IsSolvable.mk (LieIdeal.derivedSeries_add_eq_bot hk hl) theorem derivedSeries_lt_top_of_solvable [IsSolvable L] [Nontrivial L] : derivedSeries R L 1 < ⊤ := by obtain ⟨n, hn⟩ := IsSolvable.solvable (R := R) (L := L) rw [lt_top_iff_ne_top] intro contra rw [LieIdeal.derivedSeries_eq_top n contra] at hn exact top_ne_bot hn open TensorProduct in instance {A : Type*} [CommRing A] [Algebra R A] [IsSolvable L] : IsSolvable (A ⊗[R] L) := by obtain ⟨k, hk⟩ := IsSolvable.solvable R L rw [isSolvable_iff A] use k rw [derivedSeries_baseChange, hk, LieSubmodule.baseChange_bot] open TensorProduct in variable {A : Type*} [CommRing A] [Algebra R A] [Module.FaithfullyFlat R A] in theorem isSolvable_tensorProduct_iff : IsSolvable (A ⊗[R] L) ↔ IsSolvable L := by refine ⟨?_, fun _ ↦ inferInstance⟩ rw [isSolvable_iff A, isSolvable_iff R] rintro ⟨k, h⟩ use k rw [eq_bot_iff] at h ⊢ intro x hx rw [derivedSeries_baseChange] at h specialize h <| Submodule.tmul_mem_baseChange_of_mem 1 hx rw [LieSubmodule.mem_bot] at h ⊢ rwa [Module.FaithfullyFlat.one_tmul_eq_zero_iff] at h end LieAlgebra variable {R L} namespace Function open LieAlgebra theorem Injective.lieAlgebra_isSolvable [hL : IsSolvable L] (h : Injective f) : IsSolvable L' := by rw [isSolvable_iff R] at hL ⊢ apply hL.imp intro k hk apply LieIdeal.bot_of_map_eq_bot h; rw [eq_bot_iff, ← hk] apply LieIdeal.derivedSeries_map_le instance (A : LieIdeal R L) [IsSolvable L] : IsSolvable A := A.incl_injective.lieAlgebra_isSolvable theorem Surjective.lieAlgebra_isSolvable [hL' : IsSolvable L'] (h : Surjective f) : IsSolvable L := by rw [isSolvable_iff R] at hL' ⊢ apply hL'.imp intro k hk rw [← LieIdeal.derivedSeries_map_eq k h, hk] simp only [LieIdeal.map_eq_bot_iff, bot_le] end Function instance LieHom.isSolvable_range (f : L' →ₗ⁅R⁆ L) [LieAlgebra.IsSolvable L'] : LieAlgebra.IsSolvable f.range := f.surjective_rangeRestrict.lieAlgebra_isSolvable namespace LieAlgebra theorem solvable_iff_equiv_solvable (e : L' ≃ₗ⁅R⁆ L) : IsSolvable L' ↔ IsSolvable L := by constructor <;> intro h · exact e.symm.injective.lieAlgebra_isSolvable · exact e.injective.lieAlgebra_isSolvable theorem le_solvable_ideal_solvable {I J : LieIdeal R L} (h₁ : I ≤ J) (_ : IsSolvable J) : IsSolvable I := (LieIdeal.inclusion_injective h₁).lieAlgebra_isSolvable variable (R L) instance (priority := 100) ofAbelianIsSolvable [IsLieAbelian L] : IsSolvable L := by use 1 rw [← abelian_iff_derived_one_eq_bot, lie_abelian_iff_equiv_lie_abelian LieIdeal.topEquiv] infer_instance /-- The (solvable) radical of Lie algebra is the `sSup` of all solvable ideals. -/ def radical := sSup { I : LieIdeal R L | IsSolvable I } /-- The radical of a Noetherian Lie algebra is solvable. -/ instance radicalIsSolvable [IsNoetherian R L] : IsSolvable (radical R L) := by have hwf := LieSubmodule.wellFoundedGT_of_noetherian R L L rw [← CompleteLattice.isSupClosedCompact_iff_wellFoundedGT] at hwf refine hwf { I : LieIdeal R L | IsSolvable I } ⟨⊥, ?_⟩ fun I hI J hJ => ?_ · exact LieAlgebra.isSolvableBot R L · rw [Set.mem_setOf_eq] at hI hJ ⊢ apply LieAlgebra.isSolvableAdd R L /-- The `→` direction of this lemma is actually true without the `IsNoetherian` assumption. -/ theorem LieIdeal.solvable_iff_le_radical [IsNoetherian R L] (I : LieIdeal R L) : IsSolvable I ↔ I ≤ radical R L := ⟨fun h => le_sSup h, fun h => le_solvable_ideal_solvable h inferInstance⟩ theorem center_le_radical : center R L ≤ radical R L := have h : IsSolvable (center R L) := inferInstance le_sSup h instance [IsSolvable L] : IsSolvable (⊤ : LieSubalgebra R L) := by rwa [solvable_iff_equiv_solvable LieSubalgebra.topEquiv] @[simp] lemma radical_eq_top_of_isSolvable [IsSolvable L] : radical R L = ⊤ := by rw [eq_top_iff] have h : IsSolvable (⊤ : LieSubalgebra R L) := inferInstance exact le_sSup h /-- Given a solvable Lie ideal `I` with derived series `I = D₀ ≥ D₁ ≥ ⋯ ≥ Dₖ = ⊥`, this is the natural number `k` (the number of inclusions). For a non-solvable ideal, the value is 0. -/ noncomputable def derivedLengthOfIdeal (I : LieIdeal R L) : ℕ := sInf { k | derivedSeriesOfIdeal R L k I = ⊥ } /-- The derived length of a Lie algebra is the derived length of its 'top' Lie ideal. See also `LieAlgebra.derivedLength_eq_derivedLengthOfIdeal`. -/ noncomputable abbrev derivedLength : ℕ := derivedLengthOfIdeal R L ⊤ theorem derivedSeries_of_derivedLength_succ (I : LieIdeal R L) (k : ℕ) : derivedLengthOfIdeal R L I = k + 1 ↔ IsLieAbelian (derivedSeriesOfIdeal R L k I) ∧ derivedSeriesOfIdeal R L k I ≠ ⊥ := by rw [abelian_iff_derived_succ_eq_bot] let s := { k | derivedSeriesOfIdeal R L k I = ⊥ } change sInf s = k + 1 ↔ k + 1 ∈ s ∧ k ∉ s have hs : ∀ k₁ k₂ : ℕ, k₁ ≤ k₂ → k₁ ∈ s → k₂ ∈ s := by intro k₁ k₂ h₁₂ h₁ suffices derivedSeriesOfIdeal R L k₂ I ≤ ⊥ by exact eq_bot_iff.mpr this change derivedSeriesOfIdeal R L k₁ I = ⊥ at h₁; rw [← h₁] exact derivedSeriesOfIdeal_antitone I h₁₂ exact Nat.sInf_upward_closed_eq_succ_iff hs k theorem derivedLength_eq_derivedLengthOfIdeal (I : LieIdeal R L) : derivedLength R I = derivedLengthOfIdeal R L I := by let s₁ := { k | derivedSeries R I k = ⊥ } let s₂ := { k | derivedSeriesOfIdeal R L k I = ⊥ } change sInf s₁ = sInf s₂ congr; ext k; exact I.derivedSeries_eq_bot_iff k variable {R L} /-- Given a solvable Lie ideal `I` with derived series `I = D₀ ≥ D₁ ≥ ⋯ ≥ Dₖ = ⊥`, this is the `k-1`th term in the derived series (and is therefore an Abelian ideal contained in `I`). For a non-solvable ideal, this is the zero ideal, `⊥`. -/ noncomputable def derivedAbelianOfIdeal (I : LieIdeal R L) : LieIdeal R L := match derivedLengthOfIdeal R L I with | 0 => ⊥ | k + 1 => derivedSeriesOfIdeal R L k I instance : Unique {x // x ∈ (⊥ : LieIdeal R L)} := inferInstanceAs <| Unique {x // x ∈ (⊥ : Submodule R L)} theorem abelian_derivedAbelianOfIdeal (I : LieIdeal R L) : IsLieAbelian (derivedAbelianOfIdeal I) := by dsimp only [derivedAbelianOfIdeal] rcases h : derivedLengthOfIdeal R L I with - | k · dsimp; infer_instance · rw [derivedSeries_of_derivedLength_succ] at h; exact h.1 theorem derivedLength_zero (I : LieIdeal R L) [IsSolvable I] : derivedLengthOfIdeal R L I = 0 ↔ I = ⊥ := by let s := { k | derivedSeriesOfIdeal R L k I = ⊥ } change sInf s = 0 ↔ _ have hne : s ≠ ∅ := by obtain ⟨k, hk⟩ := IsSolvable.solvable R I refine Set.Nonempty.ne_empty ⟨k, ?_⟩ rw [derivedSeries_def, LieIdeal.derivedSeries_eq_bot_iff] at hk; exact hk simp [s, hne] theorem abelian_of_solvable_ideal_eq_bot_iff (I : LieIdeal R L) [h : IsSolvable I] : derivedAbelianOfIdeal I = ⊥ ↔ I = ⊥ := by dsimp only [derivedAbelianOfIdeal] split · simp_all only [derivedLength_zero] · rename_i k h obtain ⟨_, h₂⟩ := (derivedSeries_of_derivedLength_succ R L I k).mp h have h₃ : I ≠ ⊥ := by rintro rfl; apply h₂; apply derivedSeries_of_bot_eq_bot simp only [h₂, h₃] end LieAlgebra
.lake/packages/mathlib/Mathlib/Algebra/Lie/IdealOperations.lean
import Mathlib.Algebra.Lie.Ideal /-! # Ideal operations for Lie algebras Given a Lie module `M` over a Lie algebra `L`, there is a natural action of the Lie ideals of `L` on the Lie submodules of `M`. In the special case that `M = L` with the adjoint action, this provides a pairing of Lie ideals which is especially important. For example, it can be used to define solvability / nilpotency of a Lie algebra via the derived / lower-central series. ## Main definitions * `LieSubmodule.hasBracket` * `LieSubmodule.lieIdeal_oper_eq_linear_span` * `LieIdeal.map_bracket_le` * `LieIdeal.comap_bracket_le` ## Notation Given a Lie module `M` over a Lie algebra `L`, together with a Lie submodule `N ⊆ M` and a Lie ideal `I ⊆ L`, we introduce the notation `⁅I, N⁆` for the Lie submodule of `M` corresponding to the action defined in this file. ## Tags lie algebra, ideal operation -/ universe u v w w₁ w₂ namespace LieSubmodule variable {R : Type u} {L : Type v} {M : Type w} {M₂ : Type w₁} variable [CommRing R] [LieRing L] variable [AddCommGroup M] [Module R M] [LieRingModule L M] variable [AddCommGroup M₂] [Module R M₂] [LieRingModule L M₂] variable (N N' : LieSubmodule R L M) (N₂ : LieSubmodule R L M₂) variable (f : M →ₗ⁅R,L⁆ M₂) section LieIdealOperations theorem map_comap_le : map f (comap f N₂) ≤ N₂ := (N₂ : Set M₂).image_preimage_subset f theorem map_comap_eq (hf : N₂ ≤ f.range) : map f (comap f N₂) = N₂ := by rw [SetLike.ext'_iff] exact Set.image_preimage_eq_of_subset hf theorem le_comap_map : N ≤ comap f (map f N) := (N : Set M).subset_preimage_image f theorem comap_map_eq (hf : f.ker = ⊥) : comap f (map f N) = N := by rw [SetLike.ext'_iff] exact (N : Set M).preimage_image_eq (f.ker_eq_bot.mp hf) @[simp] theorem map_comap_incl : map N.incl (comap N.incl N') = N ⊓ N' := by rw [← toSubmodule_inj] exact (N : Submodule R M).map_comap_subtype N' variable [LieAlgebra R L] [LieModule R L M₂] (I J : LieIdeal R L) /-- Given a Lie module `M` over a Lie algebra `L`, the set of Lie ideals of `L` acts on the set of submodules of `M`. -/ instance hasBracket : Bracket (LieIdeal R L) (LieSubmodule R L M) := ⟨fun I N => lieSpan R L { ⁅(x : L), (n : M)⁆ | (x : I) (n : N) }⟩ theorem lieIdeal_oper_eq_span : ⁅I, N⁆ = lieSpan R L { ⁅(x : L), (n : M)⁆ | (x : I) (n : N) } := rfl /-- See also `LieSubmodule.lieIdeal_oper_eq_linear_span'` and `LieSubmodule.lieIdeal_oper_eq_tensor_map_range`. -/ theorem lieIdeal_oper_eq_linear_span [LieModule R L M] : (↑⁅I, N⁆ : Submodule R M) = Submodule.span R { ⁅(x : L), (n : M)⁆ | (x : I) (n : N) } := by apply le_antisymm · let s := { ⁅(x : L), (n : M)⁆ | (x : I) (n : N) } have aux : ∀ (y : L), ∀ m' ∈ Submodule.span R s, ⁅y, m'⁆ ∈ Submodule.span R s := by intro y m' hm' refine Submodule.span_induction (R := R) (M := M) (s := s) (p := fun m' _ ↦ ⁅y, m'⁆ ∈ Submodule.span R s) ?_ ?_ ?_ ?_ hm' · rintro m'' ⟨x, n, hm''⟩; rw [← hm'', leibniz_lie] refine Submodule.add_mem _ ?_ ?_ <;> apply Submodule.subset_span · use ⟨⁅y, ↑x⁆, I.lie_mem x.property⟩, n · use x, ⟨⁅y, ↑n⁆, N.lie_mem n.property⟩ · simp only [lie_zero, Submodule.zero_mem] · intro m₁ m₂ _ _ hm₁ hm₂; rw [lie_add]; exact Submodule.add_mem _ hm₁ hm₂ · intro t m'' _ hm''; rw [lie_smul]; exact Submodule.smul_mem _ t hm'' change _ ≤ ({ Submodule.span R s with lie_mem := fun hm' => aux _ _ hm' } : LieSubmodule R L M) rw [lieIdeal_oper_eq_span, lieSpan_le] exact Submodule.subset_span · rw [lieIdeal_oper_eq_span]; apply submodule_span_le_lieSpan theorem lieIdeal_oper_eq_linear_span' [LieModule R L M] : (↑⁅I, N⁆ : Submodule R M) = Submodule.span R { ⁅x, n⁆ | (x ∈ I) (n ∈ N) } := by rw [lieIdeal_oper_eq_linear_span] congr ext m constructor · rintro ⟨⟨x, hx⟩, ⟨n, hn⟩, rfl⟩ exact ⟨x, hx, n, hn, rfl⟩ · rintro ⟨x, hx, n, hn, rfl⟩ exact ⟨⟨x, hx⟩, ⟨n, hn⟩, rfl⟩ theorem lie_le_iff : ⁅I, N⁆ ≤ N' ↔ ∀ x ∈ I, ∀ m ∈ N, ⁅x, m⁆ ∈ N' := by rw [lieIdeal_oper_eq_span, LieSubmodule.lieSpan_le] refine ⟨fun h x hx m hm => h ⟨⟨x, hx⟩, ⟨m, hm⟩, rfl⟩, ?_⟩ rintro h _ ⟨⟨x, hx⟩, ⟨m, hm⟩, rfl⟩ exact h x hx m hm variable {N I} in theorem lie_coe_mem_lie (x : I) (m : N) : ⁅(x : L), (m : M)⁆ ∈ ⁅I, N⁆ := by rw [lieIdeal_oper_eq_span]; apply subset_lieSpan; use x, m variable {N I} in theorem lie_mem_lie {x : L} {m : M} (hx : x ∈ I) (hm : m ∈ N) : ⁅x, m⁆ ∈ ⁅I, N⁆ := lie_coe_mem_lie ⟨x, hx⟩ ⟨m, hm⟩ theorem lie_comm : ⁅I, J⁆ = ⁅J, I⁆ := by suffices ∀ I J : LieIdeal R L, ⁅I, J⁆ ≤ ⁅J, I⁆ by exact le_antisymm (this I J) (this J I) clear! I J; intro I J rw [lieIdeal_oper_eq_span, lieSpan_le]; rintro x ⟨y, z, h⟩; rw [← h] rw [← lie_skew, ← lie_neg, ← LieSubmodule.coe_neg] apply lie_coe_mem_lie theorem lie_le_right : ⁅I, N⁆ ≤ N := by rw [lieIdeal_oper_eq_span, lieSpan_le]; rintro m ⟨x, n, hn⟩; rw [← hn] exact N.lie_mem n.property theorem lie_le_left : ⁅I, J⁆ ≤ I := by rw [lie_comm]; exact lie_le_right I J theorem lie_le_inf : ⁅I, J⁆ ≤ I ⊓ J := by rw [le_inf_iff]; exact ⟨lie_le_left I J, lie_le_right J I⟩ @[simp] theorem lie_bot : ⁅I, (⊥ : LieSubmodule R L M)⁆ = ⊥ := by rw [eq_bot_iff]; apply lie_le_right @[simp] theorem bot_lie : ⁅(⊥ : LieIdeal R L), N⁆ = ⊥ := by suffices ⁅(⊥ : LieIdeal R L), N⁆ ≤ ⊥ by exact le_bot_iff.mp this rw [lieIdeal_oper_eq_span, lieSpan_le]; rintro m ⟨⟨x, hx⟩, n, hn⟩; rw [← hn] change x ∈ (⊥ : LieIdeal R L) at hx; rw [mem_bot] at hx; simp [hx] theorem lie_eq_bot_iff : ⁅I, N⁆ = ⊥ ↔ ∀ x ∈ I, ∀ m ∈ N, ⁅(x : L), m⁆ = 0 := by rw [lieIdeal_oper_eq_span, LieSubmodule.lieSpan_eq_bot_iff] refine ⟨fun h x hx m hm => h ⁅x, m⁆ ⟨⟨x, hx⟩, ⟨m, hm⟩, rfl⟩, ?_⟩ rintro h - ⟨⟨x, hx⟩, ⟨⟨n, hn⟩, rfl⟩⟩ exact h x hx n hn variable {I J N N'} in @[gcongr] theorem mono_lie (h₁ : I ≤ J) (h₂ : N ≤ N') : ⁅I, N⁆ ≤ ⁅J, N'⁆ := by intro m h rw [lieIdeal_oper_eq_span, mem_lieSpan] at h; rw [lieIdeal_oper_eq_span, mem_lieSpan] intro N hN; apply h; rintro m' ⟨⟨x, hx⟩, ⟨n, hn⟩, hm⟩; rw [← hm]; apply hN use ⟨x, h₁ hx⟩, ⟨n, h₂ hn⟩ variable {I J} in theorem mono_lie_left (h : I ≤ J) : ⁅I, N⁆ ≤ ⁅J, N⁆ := mono_lie h (le_refl N) variable {N N'} in theorem mono_lie_right (h : N ≤ N') : ⁅I, N⁆ ≤ ⁅I, N'⁆ := mono_lie (le_refl I) h @[simp] theorem lie_sup : ⁅I, N ⊔ N'⁆ = ⁅I, N⁆ ⊔ ⁅I, N'⁆ := by have h : ⁅I, N⁆ ⊔ ⁅I, N'⁆ ≤ ⁅I, N ⊔ N'⁆ := by rw [sup_le_iff]; constructor <;> apply mono_lie_right <;> [exact le_sup_left; exact le_sup_right] suffices ⁅I, N ⊔ N'⁆ ≤ ⁅I, N⁆ ⊔ ⁅I, N'⁆ by exact le_antisymm this h rw [lieIdeal_oper_eq_span, lieSpan_le] rintro m ⟨x, ⟨n, hn⟩, h⟩ simp only [SetLike.mem_coe] rw [LieSubmodule.mem_sup] at hn ⊢ rcases hn with ⟨n₁, hn₁, n₂, hn₂, hn'⟩ use ⁅(x : L), (⟨n₁, hn₁⟩ : N)⁆; constructor; · apply lie_coe_mem_lie use ⁅(x : L), (⟨n₂, hn₂⟩ : N')⁆; constructor; · apply lie_coe_mem_lie simp [← h, ← hn'] @[simp] theorem sup_lie : ⁅I ⊔ J, N⁆ = ⁅I, N⁆ ⊔ ⁅J, N⁆ := by have h : ⁅I, N⁆ ⊔ ⁅J, N⁆ ≤ ⁅I ⊔ J, N⁆ := by rw [sup_le_iff]; constructor <;> apply mono_lie_left <;> [exact le_sup_left; exact le_sup_right] suffices ⁅I ⊔ J, N⁆ ≤ ⁅I, N⁆ ⊔ ⁅J, N⁆ by exact le_antisymm this h rw [lieIdeal_oper_eq_span, lieSpan_le] rintro m ⟨⟨x, hx⟩, n, h⟩ simp only [SetLike.mem_coe] rw [LieSubmodule.mem_sup] at hx ⊢ rcases hx with ⟨x₁, hx₁, x₂, hx₂, hx'⟩ use ⁅((⟨x₁, hx₁⟩ : I) : L), (n : N)⁆; constructor; · apply lie_coe_mem_lie use ⁅((⟨x₂, hx₂⟩ : J) : L), (n : N)⁆; constructor; · apply lie_coe_mem_lie simp [← h, ← hx'] theorem lie_inf : ⁅I, N ⊓ N'⁆ ≤ ⁅I, N⁆ ⊓ ⁅I, N'⁆ := by rw [le_inf_iff]; constructor <;> apply mono_lie_right <;> [exact inf_le_left; exact inf_le_right] theorem inf_lie : ⁅I ⊓ J, N⁆ ≤ ⁅I, N⁆ ⊓ ⁅J, N⁆ := by rw [le_inf_iff]; constructor <;> apply mono_lie_left <;> [exact inf_le_left; exact inf_le_right] theorem map_bracket_eq [LieModule R L M] : map f ⁅I, N⁆ = ⁅I, map f N⁆ := by rw [← toSubmodule_inj, toSubmodule_map, lieIdeal_oper_eq_linear_span, lieIdeal_oper_eq_linear_span, Submodule.map_span] congr ext m simp theorem comap_bracket_eq [LieModule R L M] (hf₁ : f.ker = ⊥) (hf₂ : N₂ ≤ f.range) : comap f ⁅I, N₂⁆ = ⁅I, comap f N₂⁆ := by conv_lhs => rw [← map_comap_eq N₂ f hf₂] rw [← map_bracket_eq, comap_map_eq _ f hf₁] end LieIdealOperations end LieSubmodule namespace LieIdeal open LieAlgebra variable {R : Type u} {L : Type v} {L' : Type w₂} variable [CommRing R] [LieRing L] [LieAlgebra R L] [LieRing L'] [LieAlgebra R L'] variable (f : L →ₗ⁅R⁆ L') (I : LieIdeal R L) (J : LieIdeal R L') /-- Note that the inequality can be strict; e.g., the inclusion of an Abelian subalgebra of a simple algebra. -/ theorem map_bracket_le {I₁ I₂ : LieIdeal R L} : map f ⁅I₁, I₂⁆ ≤ ⁅map f I₁, map f I₂⁆ := by rw [map_le_iff_le_comap, LieSubmodule.lieIdeal_oper_eq_span, LieSubmodule.lieSpan_le] intro x hx obtain ⟨⟨y₁, hy₁⟩, ⟨y₂, hy₂⟩, hx⟩ := hx rw [← hx] let fy₁ : ↥(map f I₁) := ⟨f y₁, mem_map hy₁⟩ let fy₂ : ↥(map f I₂) := ⟨f y₂, mem_map hy₂⟩ change _ ∈ comap f ⁅map f I₁, map f I₂⁆ simp only [mem_comap, LieHom.map_lie] exact LieSubmodule.lie_coe_mem_lie fy₁ fy₂ theorem map_bracket_eq {I₁ I₂ : LieIdeal R L} (h : Function.Surjective f) : map f ⁅I₁, I₂⁆ = ⁅map f I₁, map f I₂⁆ := by suffices ⁅map f I₁, map f I₂⁆ ≤ map f ⁅I₁, I₂⁆ by exact le_antisymm (map_bracket_le f) this rw [← LieSubmodule.toSubmodule_le_toSubmodule, coe_map_of_surjective h, LieSubmodule.lieIdeal_oper_eq_linear_span, LieSubmodule.lieIdeal_oper_eq_linear_span, LinearMap.map_span] apply Submodule.span_mono rintro x ⟨⟨z₁, h₁⟩, ⟨z₂, h₂⟩, rfl⟩ obtain ⟨y₁, rfl⟩ := mem_map_of_surjective h h₁ obtain ⟨y₂, rfl⟩ := mem_map_of_surjective h h₂ exact ⟨⁅(y₁ : L), (y₂ : L)⁆, ⟨y₁, y₂, rfl⟩, by apply f.map_lie⟩ theorem comap_bracket_le {J₁ J₂ : LieIdeal R L'} : ⁅comap f J₁, comap f J₂⁆ ≤ comap f ⁅J₁, J₂⁆ := by rw [← map_le_iff_le_comap] exact le_trans (map_bracket_le f) (LieSubmodule.mono_lie map_comap_le map_comap_le) variable {f} theorem map_comap_incl {I₁ I₂ : LieIdeal R L} : map I₁.incl (comap I₁.incl I₂) = I₁ ⊓ I₂ := by conv_rhs => rw [← I₁.incl_idealRange] rw [← map_comap_eq] exact I₁.incl_isIdealMorphism theorem comap_bracket_eq {J₁ J₂ : LieIdeal R L'} (h : f.IsIdealMorphism) : comap f ⁅f.idealRange ⊓ J₁, f.idealRange ⊓ J₂⁆ = ⁅comap f J₁, comap f J₂⁆ ⊔ f.ker := by rw [← LieSubmodule.toSubmodule_inj, comap_toSubmodule, LieSubmodule.sup_toSubmodule, f.ker_toSubmodule, ← Submodule.comap_map_eq, LieSubmodule.lieIdeal_oper_eq_linear_span, LieSubmodule.lieIdeal_oper_eq_linear_span, LinearMap.map_span] congr ext simp_all only [Subtype.exists, LieSubmodule.mem_inf, LieHom.mem_idealRange_iff, exists_prop, Set.mem_setOf_eq, LieHom.coe_toLinearMap, mem_comap, exists_exists_and_exists_and_eq_and, LieHom.map_lie] grind theorem map_comap_bracket_eq {J₁ J₂ : LieIdeal R L'} (h : f.IsIdealMorphism) : map f ⁅comap f J₁, comap f J₂⁆ = ⁅f.idealRange ⊓ J₁, f.idealRange ⊓ J₂⁆ := by rw [← map_sup_ker_eq_map, ← comap_bracket_eq h, map_comap_eq h, inf_eq_right] exact le_trans (LieSubmodule.lie_le_left _ _) inf_le_left theorem comap_bracket_incl {I₁ I₂ : LieIdeal R L} : ⁅comap I.incl I₁, comap I.incl I₂⁆ = comap I.incl ⁅I ⊓ I₁, I ⊓ I₂⁆ := by conv_rhs => congr next => skip rw [← I.incl_idealRange] rw [comap_bracket_eq] · simp only [ker_incl, sup_bot_eq] · exact I.incl_isIdealMorphism /-- This is a very useful result; it allows us to use the fact that inclusion distributes over the Lie bracket operation on ideals, subject to the conditions shown. -/ theorem comap_bracket_incl_of_le {I₁ I₂ : LieIdeal R L} (h₁ : I₁ ≤ I) (h₂ : I₂ ≤ I) : ⁅comap I.incl I₁, comap I.incl I₂⁆ = comap I.incl ⁅I₁, I₂⁆ := by rw [comap_bracket_incl]; rw [← inf_eq_right] at h₁ h₂; rw [h₁, h₂] end LieIdeal
.lake/packages/mathlib/Mathlib/Algebra/Lie/TensorProduct.lean
import Mathlib.Algebra.Lie.Abelian import Mathlib.LinearAlgebra.TensorProduct.Tower /-! # Tensor products of Lie modules Tensor products of Lie modules carry natural Lie module structures. ## Tags lie module, tensor product, universal property -/ universe u v w w₁ w₂ w₃ variable {R : Type u} [CommRing R] open LieModule namespace TensorProduct open scoped TensorProduct namespace LieModule variable {L : Type v} {M : Type w} {N : Type w₁} {P : Type w₂} {Q : Type w₃} variable [LieRing L] [LieAlgebra R L] variable [AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M] variable [AddCommGroup N] [Module R N] [LieRingModule L N] [LieModule R L N] variable [AddCommGroup P] [Module R P] [LieRingModule L P] [LieModule R L P] variable [AddCommGroup Q] [Module R Q] [LieRingModule L Q] [LieModule R L Q] attribute [local ext] TensorProduct.ext /-- It is useful to define the bracket via this auxiliary function so that we have a type-theoretic expression of the fact that `L` acts by linear endomorphisms. It simplifies the proofs in `lieRingModule` below. -/ def hasBracketAux (x : L) : Module.End R (M ⊗[R] N) := (toEnd R L M x).rTensor N + (toEnd R L N x).lTensor M /-- The tensor product of two Lie modules is a Lie ring module. -/ instance lieRingModule : LieRingModule L (M ⊗[R] N) where bracket x := hasBracketAux x add_lie x y t := by simp only [hasBracketAux, LinearMap.lTensor_add, LinearMap.rTensor_add, map_add, LinearMap.add_apply] abel lie_add _ := LinearMap.map_add _ leibniz_lie x y t := by suffices (hasBracketAux x).comp (hasBracketAux y) = hasBracketAux ⁅x, y⁆ + (hasBracketAux y).comp (hasBracketAux x) by rw [← LinearMap.comp_apply, this]; rfl ext m n simp only [hasBracketAux, AlgebraTensorModule.curry_apply, curry_apply, sub_tmul, tmul_sub, LinearMap.coe_restrictScalars, Function.comp_apply, LinearMap.coe_comp, LinearMap.rTensor_tmul, LieHom.map_lie, toEnd_apply_apply, LinearMap.add_apply, LinearMap.map_add, LieHom.lie_apply, Module.End.lie_apply, LinearMap.lTensor_tmul] abel /-- The tensor product of two Lie modules is a Lie module. -/ instance lieModule : LieModule R L (M ⊗[R] N) where smul_lie c x t := by change hasBracketAux (c • x) _ = c • hasBracketAux _ _ simp only [hasBracketAux, smul_add, LinearMap.rTensor_smul, LinearMap.smul_apply, LinearMap.lTensor_smul, map_smul, LinearMap.add_apply] lie_smul c _ := LinearMap.map_smul _ c @[simp] theorem lie_tmul_right (x : L) (m : M) (n : N) : ⁅x, m ⊗ₜ[R] n⁆ = ⁅x, m⁆ ⊗ₜ n + m ⊗ₜ ⁅x, n⁆ := show hasBracketAux x (m ⊗ₜ[R] n) = _ by simp only [hasBracketAux, LinearMap.rTensor_tmul, toEnd_apply_apply, LinearMap.add_apply, LinearMap.lTensor_tmul] variable (R L M N P Q) /-- The universal property for tensor product of modules of a Lie algebra: the `R`-linear tensor-hom adjunction is equivariant with respect to the `L` action. -/ def lift : (M →ₗ[R] N →ₗ[R] P) ≃ₗ⁅R,L⁆ M ⊗[R] N →ₗ[R] P := { TensorProduct.lift.equiv (.id R) M N P with map_lie' := fun {x f} => by ext m n simp only [AddHom.toFun_eq_coe, LinearMap.coe_toAddHom, LinearEquiv.coe_coe, AlgebraTensorModule.curry_apply, curry_apply, LinearMap.coe_restrictScalars, lift.equiv_apply, LieHom.lie_apply, LinearMap.sub_apply, lie_tmul_right, map_add] abel } @[simp] theorem lift_apply (f : M →ₗ[R] N →ₗ[R] P) (m : M) (n : N) : lift R L M N P f (m ⊗ₜ n) = f m n := rfl /-- A weaker form of the universal property for tensor product of modules of a Lie algebra. Note that maps `f` of type `M →ₗ⁅R,L⁆ N →ₗ[R] P` are exactly those `R`-bilinear maps satisfying `⁅x, f m n⁆ = f ⁅x, m⁆ n + f m ⁅x, n⁆` for all `x, m, n` (see e.g, `LieModuleHom.map_lie₂`). -/ def liftLie : (M →ₗ⁅R,L⁆ N →ₗ[R] P) ≃ₗ[R] M ⊗[R] N →ₗ⁅R,L⁆ P := maxTrivLinearMapEquivLieModuleHom.symm ≪≫ₗ ↑(maxTrivEquiv (lift R L M N P)) ≪≫ₗ maxTrivLinearMapEquivLieModuleHom @[simp] theorem coe_liftLie_eq_lift_coe (f : M →ₗ⁅R,L⁆ N →ₗ[R] P) : ⇑(liftLie R L M N P f) = lift R L M N P f := by tauto theorem liftLie_apply (f : M →ₗ⁅R,L⁆ N →ₗ[R] P) (m : M) (n : N) : liftLie R L M N P f (m ⊗ₜ n) = f m n := by simp only [coe_liftLie_eq_lift_coe, LieModuleHom.coe_toLinearMap, lift_apply] variable {R L M N P Q} /-- A pair of Lie module morphisms `f : M → P` and `g : N → Q`, induce a Lie module morphism: `M ⊗ N → P ⊗ Q`. -/ nonrec def map (f : M →ₗ⁅R,L⁆ P) (g : N →ₗ⁅R,L⁆ Q) : M ⊗[R] N →ₗ⁅R,L⁆ P ⊗[R] Q := { map (f : M →ₗ[R] P) (g : N →ₗ[R] Q) with map_lie' := fun {x t} => by simp only [LinearMap.toFun_eq_coe] refine t.induction_on ?_ ?_ ?_ · simp only [LinearMap.map_zero, lie_zero] · intro m n simp only [LieModuleHom.coe_toLinearMap, lie_tmul_right, LieModuleHom.map_lie, map_tmul, LinearMap.map_add] · intro t₁ t₂ ht₁ ht₂; simp only [ht₁, ht₂, lie_add, LinearMap.map_add] } @[simp] theorem toLinearMap_map (f : M →ₗ⁅R,L⁆ P) (g : N →ₗ⁅R,L⁆ Q) : (map f g : M ⊗[R] N →ₗ[R] P ⊗[R] Q) = TensorProduct.map (f : M →ₗ[R] P) (g : N →ₗ[R] Q) := rfl @[simp] nonrec theorem map_tmul (f : M →ₗ⁅R,L⁆ P) (g : N →ₗ⁅R,L⁆ Q) (m : M) (n : N) : map f g (m ⊗ₜ n) = f m ⊗ₜ g n := map_tmul _ _ _ _ /-- Given Lie submodules `M' ⊆ M` and `N' ⊆ N`, this is the natural map: `M' ⊗ N' → M ⊗ N`. -/ def mapIncl (M' : LieSubmodule R L M) (N' : LieSubmodule R L N) : M' ⊗[R] N' →ₗ⁅R,L⁆ M ⊗[R] N := map M'.incl N'.incl @[simp] theorem mapIncl_def (M' : LieSubmodule R L M) (N' : LieSubmodule R L N) : mapIncl M' N' = map M'.incl N'.incl := rfl end LieModule end TensorProduct namespace LieModule open scoped TensorProduct variable (R) (L : Type v) (M : Type w) variable [LieRing L] [LieAlgebra R L] variable [AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M] /-- The action of the Lie algebra on one of its modules, regarded as a morphism of Lie modules. -/ def toModuleHom : L ⊗[R] M →ₗ⁅R,L⁆ M := TensorProduct.LieModule.liftLie R L L M M { (toEnd R L M : L →ₗ[R] M →ₗ[R] M) with map_lie' := fun {x m} => by ext n; simp [LieRing.of_associative_ring_bracket] } @[simp] theorem toModuleHom_apply (x : L) (m : M) : toModuleHom R L M (x ⊗ₜ m) = ⁅x, m⁆ := by simp only [toModuleHom, TensorProduct.LieModule.liftLie_apply, LieModuleHom.coe_mk, LieHom.coe_toLinearMap, toEnd_apply_apply] end LieModule namespace LieSubmodule open scoped TensorProduct open TensorProduct.LieModule open LieModule variable {L : Type v} {M : Type w} variable [LieRing L] [LieAlgebra R L] variable [AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M] variable (I : LieIdeal R L) (N : LieSubmodule R L M) /-- A useful alternative characterisation of Lie ideal operations on Lie submodules. Given a Lie ideal `I ⊆ L` and a Lie submodule `N ⊆ M`, by tensoring the inclusion maps and then applying the action of `L` on `M`, we obtain morphism of Lie modules `f : I ⊗ N → L ⊗ M → M`. This lemma states that `⁅I, N⁆ = range f`. -/ theorem lieIdeal_oper_eq_tensor_map_range : ⁅I, N⁆ = ((toModuleHom R L M).comp (mapIncl I N : I ⊗[R] N →ₗ⁅R,L⁆ L ⊗[R] M)).range := by rw [← toSubmodule_inj, lieIdeal_oper_eq_linear_span, LieModuleHom.toSubmodule_range, LieModuleHom.toLinearMap_comp, LinearMap.range_comp, mapIncl_def, toLinearMap_map, TensorProduct.range_map_eq_span_tmul, Submodule.map_span] congr; ext m; constructor · rintro ⟨⟨x, hx⟩, ⟨n, hn⟩, rfl⟩; use x ⊗ₜ n; constructor · use ⟨x, hx⟩, ⟨n, hn⟩; rfl · simp · rintro ⟨t, ⟨⟨x, hx⟩, ⟨n, hn⟩, rfl⟩, h⟩; rw [← h]; use ⟨x, hx⟩, ⟨n, hn⟩; rfl end LieSubmodule
.lake/packages/mathlib/Mathlib/Algebra/Lie/Abelian.lean
import Mathlib.Algebra.Lie.OfAssociative import Mathlib.Algebra.Lie.IdealOperations /-! # Trivial Lie modules and Abelian Lie algebras The action of a Lie algebra `L` on a module `M` is trivial if `⁅x, m⁆ = 0` for all `x ∈ L` and `m ∈ M`. In the special case that `M = L` with the adjoint action, triviality corresponds to the concept of an Abelian Lie algebra. In this file we define these concepts and provide some related definitions and results. ## Main definitions * `LieModule.IsTrivial` * `IsLieAbelian` * `commutative_ring_iff_abelian_lie_ring` * `LieModule.ker` * `LieModule.maxTrivSubmodule` * `LieAlgebra.center` ## Tags lie algebra, abelian, commutative, center -/ universe u v w w₁ w₂ /-- A Lie (ring) module is trivial iff all brackets vanish. -/ class LieModule.IsTrivial (L : Type v) (M : Type w) [Bracket L M] [Zero M] : Prop where trivial : ∀ (x : L) (m : M), ⁅x, m⁆ = 0 @[simp] theorem trivial_lie_zero (L : Type v) (M : Type w) [Bracket L M] [Zero M] [LieModule.IsTrivial L M] (x : L) (m : M) : ⁅x, m⁆ = 0 := LieModule.IsTrivial.trivial x m instance LieModule.instIsTrivialOfSubsingleton {L M : Type*} [LieRing L] [AddCommGroup M] [LieRingModule L M] [Subsingleton L] : LieModule.IsTrivial L M := ⟨fun x m ↦ by rw [Subsingleton.eq_zero x, zero_lie]⟩ instance LieModule.instIsTrivialOfSubsingleton' {L M : Type*} [LieRing L] [AddCommGroup M] [LieRingModule L M] [Subsingleton M] : LieModule.IsTrivial L M := ⟨fun x m ↦ by simp_rw [Subsingleton.eq_zero m, lie_zero]⟩ /-- A Lie algebra is Abelian iff it is trivial as a Lie module over itself. -/ abbrev IsLieAbelian (L : Type v) [Bracket L L] [Zero L] : Prop := LieModule.IsTrivial L L instance LieIdeal.isLieAbelian_of_trivial (R : Type u) (L : Type v) [CommRing R] [LieRing L] [LieAlgebra R L] (I : LieIdeal R L) [h : LieModule.IsTrivial L I] : IsLieAbelian I where trivial x y := by apply h.trivial theorem Function.Injective.isLieAbelian {R : Type u} {L₁ : Type v} {L₂ : Type w} [CommRing R] [LieRing L₁] [LieRing L₂] [LieAlgebra R L₁] [LieAlgebra R L₂] {f : L₁ →ₗ⁅R⁆ L₂} (h₁ : Function.Injective f) (_ : IsLieAbelian L₂) : IsLieAbelian L₁ := { trivial := fun x y => h₁ <| calc f ⁅x, y⁆ = ⁅f x, f y⁆ := LieHom.map_lie f x y _ = 0 := trivial_lie_zero _ _ _ _ _ = f 0 := (map_zero _).symm} theorem Function.Surjective.isLieAbelian {R : Type u} {L₁ : Type v} {L₂ : Type w} [CommRing R] [LieRing L₁] [LieRing L₂] [LieAlgebra R L₁] [LieAlgebra R L₂] {f : L₁ →ₗ⁅R⁆ L₂} (h₁ : Function.Surjective f) (h₂ : IsLieAbelian L₁) : IsLieAbelian L₂ := { trivial := fun x y => by obtain ⟨u, rfl⟩ := h₁ x obtain ⟨v, rfl⟩ := h₁ y rw [← LieHom.map_lie, trivial_lie_zero, map_zero] } theorem lie_abelian_iff_equiv_lie_abelian {R : Type u} {L₁ : Type v} {L₂ : Type w} [CommRing R] [LieRing L₁] [LieRing L₂] [LieAlgebra R L₁] [LieAlgebra R L₂] (e : L₁ ≃ₗ⁅R⁆ L₂) : IsLieAbelian L₁ ↔ IsLieAbelian L₂ := ⟨e.symm.injective.isLieAbelian, e.injective.isLieAbelian⟩ theorem commutative_ring_iff_abelian_lie_ring {A : Type v} [Ring A] : Std.Commutative (α := A) (· * ·) ↔ IsLieAbelian A := by have h₁ : Std.Commutative (α := A) (· * ·) ↔ ∀ a b : A, a * b = b * a := ⟨fun h => h.1, fun h => ⟨h⟩⟩ have h₂ : IsLieAbelian A ↔ ∀ a b : A, ⁅a, b⁆ = 0 := ⟨fun h => h.1, fun h => ⟨h⟩⟩ simp only [h₁, h₂, LieRing.of_associative_ring_bracket, sub_eq_zero] @[simp] theorem LieSubalgebra.isLieAbelian_lieSpan_iff {R L : Type*} [CommRing R] [LieRing L] [LieAlgebra R L] {s : Set L} : IsLieAbelian (lieSpan R L s) ↔ ∀ᵉ (x ∈ s) (y ∈ s), ⁅x, y⁆ = 0 := by refine ⟨fun h x hx y hy ↦ ?_, fun h ↦ ⟨fun ⟨x, hx⟩ ⟨y, hy⟩ ↦ ?_⟩⟩ · let x' : lieSpan R L s := ⟨x, subset_lieSpan hx⟩ let y' : lieSpan R L s := ⟨y, subset_lieSpan hy⟩ suffices ⁅x', y'⁆ = 0 by simpa [x', y', Subtype.ext_iff, -trivial_lie_zero] using this simp · induction hx using lieSpan_induction with | mem w hw => induction hy using lieSpan_induction with | mem u hu => simpa [Subtype.ext_iff] using h w hw u hu | zero => simp [Subtype.ext_iff] | add u v _ _ hu hv => simp only [Subtype.ext_iff, coe_bracket, ZeroMemClass.coe_zero, lie_add] at hu hv ⊢ simp [hu, hv] | smul t u _ hu => simp only [Subtype.ext_iff, coe_bracket, ZeroMemClass.coe_zero] at hu simp [Subtype.ext_iff, hu] | lie u v _ _ hu hv => simp only [Subtype.ext_iff, coe_bracket, ZeroMemClass.coe_zero] at hu hv ⊢ rw [leibniz_lie] simp [hu, hv] | zero => simp [Subtype.ext_iff] | add u v _ _ hu hv => simp only [Subtype.ext_iff, coe_bracket, ZeroMemClass.coe_zero, add_lie] at hu hv ⊢ simp [hu, hv] | smul t u _ hu => simp only [Subtype.ext_iff, coe_bracket, ZeroMemClass.coe_zero] at hu simp [Subtype.ext_iff, hu] | lie u v _ _ hu hv => simp only [Subtype.ext_iff, coe_bracket, ZeroMemClass.coe_zero] at hu hv ⊢ simp [hu, hv] section Center variable (R : Type u) (L : Type v) (M : Type w) (N : Type w₁) variable [CommRing R] [LieRing L] [LieAlgebra R L] variable [AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M] variable [AddCommGroup N] [Module R N] [LieRingModule L N] [LieModule R L N] namespace LieModule /-- The kernel of the action of a Lie algebra `L` on a Lie module `M` as a Lie ideal in `L`. -/ protected def ker : LieIdeal R L := (toEnd R L M).ker @[simp] protected theorem mem_ker (x : L) : x ∈ LieModule.ker R L M ↔ ∀ m : M, ⁅x, m⁆ = 0 := by simp only [LieModule.ker, LieHom.mem_ker, LinearMap.ext_iff, LinearMap.zero_apply, toEnd_apply_apply] lemma isFaithful_iff_ker_eq_bot : IsFaithful R L M ↔ LieModule.ker R L M = ⊥ := by rw [isFaithful_iff', LieSubmodule.ext_iff] aesop @[simp] lemma ker_eq_bot [IsFaithful R L M] : LieModule.ker R L M = ⊥ := (isFaithful_iff_ker_eq_bot R L M).mp inferInstance /-- The largest submodule of a Lie module `M` on which the Lie algebra `L` acts trivially. -/ def maxTrivSubmodule : LieSubmodule R L M where carrier := { m | ∀ x : L, ⁅x, m⁆ = 0 } zero_mem' x := lie_zero x add_mem' {x y} hx hy z := by rw [lie_add, hx, hy, add_zero] smul_mem' c x hx y := by rw [lie_smul, hx, smul_zero] lie_mem {x m} hm y := by rw [hm, lie_zero] @[simp] theorem mem_maxTrivSubmodule (m : M) : m ∈ maxTrivSubmodule R L M ↔ ∀ x : L, ⁅x, m⁆ = 0 := Iff.rfl instance : IsTrivial L (maxTrivSubmodule R L M) where trivial x m := Subtype.ext (m.property x) @[simp] theorem ideal_oper_maxTrivSubmodule_eq_bot (I : LieIdeal R L) : ⁅I, maxTrivSubmodule R L M⁆ = ⊥ := by rw [← LieSubmodule.toSubmodule_inj, LieSubmodule.lieIdeal_oper_eq_linear_span, LieSubmodule.bot_toSubmodule, Submodule.span_eq_bot] rintro m ⟨⟨x, hx⟩, ⟨⟨m, hm⟩, rfl⟩⟩ exact hm x theorem le_max_triv_iff_bracket_eq_bot {N : LieSubmodule R L M} : N ≤ maxTrivSubmodule R L M ↔ ⁅(⊤ : LieIdeal R L), N⁆ = ⊥ := by refine ⟨fun h => ?_, fun h m hm => ?_⟩ · rw [← le_bot_iff, ← ideal_oper_maxTrivSubmodule_eq_bot R L M ⊤] exact LieSubmodule.mono_lie_right ⊤ h · rw [mem_maxTrivSubmodule] rw [LieSubmodule.lie_eq_bot_iff] at h exact fun x => h x (LieSubmodule.mem_top x) m hm theorem trivial_iff_le_maximal_trivial (N : LieSubmodule R L M) : IsTrivial L N ↔ N ≤ maxTrivSubmodule R L M := ⟨fun h m hm x => IsTrivial.casesOn h fun h => Subtype.ext_iff.mp (h x ⟨m, hm⟩), fun h => { trivial := fun x m => Subtype.ext (h m.2 x) }⟩ theorem isTrivial_iff_max_triv_eq_top : IsTrivial L M ↔ maxTrivSubmodule R L M = ⊤ := by constructor · rintro ⟨h⟩; ext; simp only [mem_maxTrivSubmodule, h, forall_const, LieSubmodule.mem_top] · intro h; constructor; intro x m; revert x rw [← mem_maxTrivSubmodule R L M, h]; exact LieSubmodule.mem_top m variable {R L M N} /-- `maxTrivSubmodule` is functorial. -/ def maxTrivHom (f : M →ₗ⁅R,L⁆ N) : maxTrivSubmodule R L M →ₗ⁅R,L⁆ maxTrivSubmodule R L N where toFun m := ⟨f m, fun x => (LieModuleHom.map_lie _ _ _).symm.trans <| (congr_arg f (m.property x)).trans (map_zero _)⟩ map_add' m n := by ext; simp map_smul' t m := by ext; simp map_lie' {x m} := by simp @[norm_cast, simp] theorem coe_maxTrivHom_apply (f : M →ₗ⁅R,L⁆ N) (m : maxTrivSubmodule R L M) : (maxTrivHom f m : N) = f m := rfl /-- The maximal trivial submodules of Lie-equivalent Lie modules are Lie-equivalent. -/ def maxTrivEquiv (e : M ≃ₗ⁅R,L⁆ N) : maxTrivSubmodule R L M ≃ₗ⁅R,L⁆ maxTrivSubmodule R L N := { maxTrivHom (e : M →ₗ⁅R,L⁆ N) with toFun := maxTrivHom (e : M →ₗ⁅R,L⁆ N) invFun := maxTrivHom (e.symm : N →ₗ⁅R,L⁆ M) left_inv := fun m => by ext; simp right_inv := fun n => by ext; simp } @[norm_cast, simp] theorem coe_maxTrivEquiv_apply (e : M ≃ₗ⁅R,L⁆ N) (m : maxTrivSubmodule R L M) : (maxTrivEquiv e m : N) = e ↑m := rfl @[simp] theorem maxTrivEquiv_of_refl_eq_refl : maxTrivEquiv (LieModuleEquiv.refl : M ≃ₗ⁅R,L⁆ M) = LieModuleEquiv.refl := by ext; simp only [coe_maxTrivEquiv_apply, LieModuleEquiv.refl_apply] @[simp] theorem maxTrivEquiv_of_equiv_symm_eq_symm (e : M ≃ₗ⁅R,L⁆ N) : (maxTrivEquiv e).symm = maxTrivEquiv e.symm := rfl /-- A linear map between two Lie modules is a morphism of Lie modules iff the Lie algebra action on it is trivial. -/ def maxTrivLinearMapEquivLieModuleHom : maxTrivSubmodule R L (M →ₗ[R] N) ≃ₗ[R] M →ₗ⁅R,L⁆ N where toFun f := { toLinearMap := f.val map_lie' := fun {x m} => by have hf : ⁅x, f.val⁆ m = 0 := by rw [f.property x, LinearMap.zero_apply] rw [LieHom.lie_apply, sub_eq_zero, ← LinearMap.toFun_eq_coe] at hf; exact hf.symm} map_add' f g := by ext; simp map_smul' F G := by ext; simp invFun F := ⟨F, fun x => by ext; simp⟩ left_inv f := by simp right_inv F := by simp @[simp] theorem coe_maxTrivLinearMapEquivLieModuleHom (f : maxTrivSubmodule R L (M →ₗ[R] N)) : (maxTrivLinearMapEquivLieModuleHom (M := M) (N := N) f : M → N) = f := by ext; rfl @[simp] theorem coe_maxTrivLinearMapEquivLieModuleHom_symm (f : M →ₗ⁅R,L⁆ N) : (maxTrivLinearMapEquivLieModuleHom (M := M) (N := N) |>.symm f : M → N) = f := rfl @[simp] theorem toLinearMap_maxTrivLinearMapEquivLieModuleHom (f : maxTrivSubmodule R L (M →ₗ[R] N)) : (maxTrivLinearMapEquivLieModuleHom (M := M) (N := N) f : M →ₗ[R] N) = (f : M →ₗ[R] N) := by ext; rfl @[simp] theorem toLinearMap_maxTrivLinearMapEquivLieModuleHom_symm (f : M →ₗ⁅R,L⁆ N) : (maxTrivLinearMapEquivLieModuleHom (M := M) (N := N) |>.symm f : M →ₗ[R] N) = (f : M →ₗ[R] N) := rfl end LieModule namespace LieAlgebra /-- The center of a Lie algebra is the set of elements that commute with everything. It can be viewed as the maximal trivial submodule of the Lie algebra as a Lie module over itself via the adjoint representation. -/ abbrev center : LieIdeal R L := LieModule.maxTrivSubmodule R L L instance : IsLieAbelian (center R L) := inferInstance @[simp] theorem ad_ker_eq_self_module_ker : (ad R L).ker = LieModule.ker R L L := rfl @[simp] theorem self_module_ker_eq_center : LieModule.ker R L L = center R L := by ext y simp only [LieModule.mem_maxTrivSubmodule, LieModule.mem_ker, ← lie_skew _ y, neg_eq_zero] theorem abelian_of_le_center (I : LieIdeal R L) (h : I ≤ center R L) : IsLieAbelian I := haveI : LieModule.IsTrivial L I := (LieModule.trivial_iff_le_maximal_trivial R L L I).mpr h LieIdeal.isLieAbelian_of_trivial R L I theorem isLieAbelian_iff_center_eq_top : IsLieAbelian L ↔ center R L = ⊤ := LieModule.isTrivial_iff_max_triv_eq_top R L L theorem isFaithful_self_iff : LieModule.IsFaithful R L L ↔ center R L = ⊥ := by rw [LieModule.isFaithful_iff_ker_eq_bot, self_module_ker_eq_center] @[simp] theorem center_eq_bot [LieModule.IsFaithful R L L] : center R L = ⊥ := (isFaithful_self_iff R L).mp inferInstance end LieAlgebra namespace LieModule variable {R L} variable {x : L} (hx : x ∈ LieAlgebra.center R L) (y : L) include hx lemma commute_toEnd_of_mem_center_left : Commute (toEnd R L M x) (toEnd R L M y) := by rw [Commute.symm_iff, commute_iff_lie_eq, ← LieHom.map_lie, hx y, map_zero] lemma commute_toEnd_of_mem_center_right : Commute (toEnd R L M y) (toEnd R L M x) := (LieModule.commute_toEnd_of_mem_center_left M hx y).symm end LieModule end Center section IdealOperations open LieSubmodule LieSubalgebra variable {R : Type u} {L : Type v} {M : Type w} variable [CommRing R] [LieRing L] [LieAlgebra R L] [AddCommGroup M] [Module R M] variable [LieRingModule L M] (N N' : LieSubmodule R L M) (I J : LieIdeal R L) @[simp] theorem LieSubmodule.trivial_lie_oper_zero [LieModule.IsTrivial L M] : ⁅I, N⁆ = ⊥ := by suffices ⁅I, N⁆ ≤ ⊥ from le_bot_iff.mp this rw [lieIdeal_oper_eq_span, LieSubmodule.lieSpan_le] rintro m ⟨x, n, h⟩; rw [trivial_lie_zero] at h; simp [← h] theorem LieSubmodule.lie_abelian_iff_lie_self_eq_bot : IsLieAbelian I ↔ ⁅I, I⁆ = ⊥ := by simp only [_root_.eq_bot_iff, lieIdeal_oper_eq_span, LieSubmodule.lieSpan_le, LieSubmodule.bot_coe, Set.subset_singleton_iff, Set.mem_setOf_eq, exists_imp] refine ⟨fun h z x y hz => hz.symm.trans (((I : LieSubalgebra R L).coe_bracket x y).symm.trans ((coe_zero_iff_zero _ _).mpr (by apply h.trivial))), fun h => ⟨fun x y => ((I : LieSubalgebra R L).coe_zero_iff_zero _).mp (h _ x y rfl)⟩⟩ variable {I N} in lemma lie_eq_self_of_isAtom_of_ne_bot (hN : IsAtom N) (h : ⁅I, N⁆ ≠ ⊥) : ⁅I, N⁆ = N := (hN.le_iff_eq h).mp <| LieSubmodule.lie_le_right N I -- TODO: introduce typeclass for perfect Lie algebras and use it here in the conclusion lemma lie_eq_self_of_isAtom_of_nonabelian {R L : Type*} [CommRing R] [LieRing L] [LieAlgebra R L] (I : LieIdeal R L) (hI : IsAtom I) (h : ¬IsLieAbelian I) : ⁅I, I⁆ = I := lie_eq_self_of_isAtom_of_ne_bot hI <| not_imp_not.mpr (lie_abelian_iff_lie_self_eq_bot I).mpr h end IdealOperations section TrivialLieModule set_option linter.unusedVariables false in /-- A type synonym for an `R`-module to have a trivial Lie module structure. -/ @[nolint unusedArguments] def TrivialLieModule (R L M : Type*) := M namespace TrivialLieModule variable (R L M : Type*) [CommRing R] [LieRing L] [LieAlgebra R L] [AddCommGroup M] [Module R M] instance : AddCommGroup (TrivialLieModule R L M) := inferInstanceAs (AddCommGroup M) instance : Module R (TrivialLieModule R L M) := inferInstanceAs (Module R M) /-- The linear equivalence between a trivial Lie module and its underlying `R`-module. -/ def equiv : (TrivialLieModule R L M) ≃ₗ[R] M := LinearEquiv.refl R M instance : LieRingModule L (TrivialLieModule R L M) where bracket x m := 0 add_lie := by simp lie_add := by simp leibniz_lie := by simp instance : LieModule.IsTrivial L (TrivialLieModule R L M) where trivial _ _ := rfl instance : LieModule R L (TrivialLieModule R L M) where smul_lie := by simp lie_smul := by simp end TrivialLieModule end TrivialLieModule
.lake/packages/mathlib/Mathlib/Algebra/Lie/LieTheorem.lean
import Mathlib.Algebra.Lie.Weights.Basic import Mathlib.RingTheory.Finiteness.Nilpotent /-! # Lie's theorem for Solvable Lie algebras. Lie's theorem asserts that Lie modules of solvable Lie algebras over fields of characteristic 0 have a common eigenvector for the action of all elements of the Lie algebra. This result is named `LieModule.exists_forall_lie_eq_smul_of_isSolvable`. -/ namespace LieModule section /- The following variables generalize the setting where: - `R` is a principal ideal domain of characteristic zero, - `L` is a Lie algebra over `R`, - `V` is a Lie algebra module over `L` - `A` is a Lie ideal of `L`. Besides generalizing, it also make the proof of `lie_stable` syntactically smoother. -/ variable {R L A V : Type*} [CommRing R] variable [IsPrincipalIdealRing R] [IsDomain R] [CharZero R] variable [LieRing L] [LieAlgebra R L] variable [LieRing A] [LieAlgebra R A] variable [Bracket L A] [Bracket A L] variable [AddCommGroup V] [Module R V] [Module.Free R V] [Module.Finite R V] variable [LieRingModule L V] [LieModule R L V] variable [LieRingModule A V] [LieModule R A V] variable [IsLieTower L A V] [IsLieTower A L V] variable (χ : A → R) open Module (finrank) open LieModule local notation "π" => LieModule.toEnd R _ V private abbrev T (w : A) : Module.End R V := (π w) - χ w • 1 /-- An auxiliary lemma used only in the definition `LieModule.weightSpaceOfIsLieTower` below. -/ private lemma weightSpaceOfIsLieTower_aux (z : L) (v : V) (hv : v ∈ weightSpace V χ) : ⁅z, v⁆ ∈ weightSpace V χ := by rw [mem_weightSpace] at hv ⊢ intro a rcases eq_or_ne v 0 with (rfl | hv') · simp only [lie_zero, smul_zero] suffices χ ⁅z, a⁆ = 0 by rw [leibniz_lie, hv a, lie_smul, lie_swap_lie, hv, this, zero_smul, neg_zero, zero_add] let U' : ℕ →o Submodule R V := { toFun n := Submodule.span R {((π z)^i) v | i < n}, monotone' i j h := Submodule.span_mono (fun _ ⟨c, hc, hw⟩ ↦ ⟨c, lt_of_lt_of_le hc h, hw⟩) } have map_U'_le (n : ℕ) : Submodule.map (π z) (U' n) ≤ U' (n + 1) := by simp only [OrderHom.coe_mk, Submodule.map_span, toEnd_apply_apply, U'] apply Submodule.span_mono suffices ∀ a < n, ∃ b < n + 1, ((π z) ^ b) v = ((π z) ^ (a + 1)) v by simpa [pow_succ'] aesop have T_apply_succ (w : A) (n : ℕ) : Submodule.map (T χ w) (U' (n + 1)) ≤ U' n := by simp only [OrderHom.coe_mk, U', Submodule.map_span, Submodule.span_le, Set.image_subset_iff] simp only [Set.subset_def, Set.mem_setOf_eq, Set.mem_preimage, SetLike.mem_coe, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂] induction n generalizing w · simp only [zero_add, Nat.lt_one_iff, LinearMap.sub_apply, LieModule.toEnd_apply_apply, LinearMap.smul_apply, Module.End.one_apply, forall_eq, pow_zero, hv w, sub_self, zero_mem] · next n hn => intro m hm obtain (hm | rfl) : m < n + 1 ∨ m = n + 1 := by cutsat · exact U'.mono (Nat.le_succ n) (hn w m hm) have H : ∀ w, ⁅w, (π z ^ n) v⁆ = (T χ w) ((π z ^ n) v) + χ w • ((π z ^ n) v) := by simp rw [T, LinearMap.sub_apply, pow_succ', Module.End.mul_apply, LieModule.toEnd_apply_apply, LieModule.toEnd_apply_apply, LinearMap.smul_apply, Module.End.one_apply, leibniz_lie, lie_swap_lie w z, H, H, lie_add, lie_smul, add_sub_assoc, add_sub_assoc, sub_self, add_zero] refine add_mem (neg_mem <| add_mem ?_ ?_) ?_ · exact U'.mono n.le_succ (hn _ n n.lt_succ_self) · exact Submodule.smul_mem _ _ (Submodule.subset_span ⟨n, n.lt_succ_self, rfl⟩) · exact map_U'_le _ <| Submodule.mem_map_of_mem <| hn w n n.lt_succ_self set U : LieSubmodule R A V := { toSubmodule := ⨆ k : ℕ, U' k lie_mem {w} x hx := by rw [show ⁅w, x⁆ = (T χ w) x + χ w • x by simp] apply add_mem _ (Submodule.smul_mem _ _ hx) set U := ⨆ k : ℕ, U' k suffices Submodule.map (T χ w) U ≤ U from this <| Submodule.mem_map_of_mem hx rw [Submodule.map_iSup, iSup_le_iff] rintro (_ | i) · simp [U'] · exact (T_apply_succ w i).trans (le_iSup _ _) } have hzU (x : V) (hx : x ∈ U) : (π z) x ∈ U := by suffices Submodule.map (π z) U ≤ U from this <| Submodule.mem_map_of_mem hx simp only [U, Submodule.map_iSup, iSup_le_iff] exact fun i ↦ (map_U'_le i).trans (le_iSup _ _) have trace_za_zero : (LieModule.toEnd R A _ ⁅z, a⁆).trace R U = 0 := by have hres : LieModule.toEnd R A U ⁅z, a⁆ = ⁅(π z).restrict hzU, LieModule.toEnd R A U a⁆ := by ext ⟨x, hx⟩ change ⁅⁅z, a⁆, x⁆ = ⁅z, ⁅a, x⁆⁆ - ⁅a, ⁅z, x⁆⁆ simp only [leibniz_lie z a, add_sub_cancel_right] rw [hres, LinearMap.trace_lie] have trace_T_U_zero (w : A) : (T χ w).trace R U = 0 := by have key (i : ℕ) (hi : i ≠ 0) : ∃ j < i, Submodule.map (T χ w) (U' i) ≤ U' j := by obtain ⟨j, rfl⟩ := Nat.exists_eq_succ_of_ne_zero hi exact ⟨j, j.lt_succ_self, T_apply_succ w j⟩ apply IsNilpotent.eq_zero apply LinearMap.isNilpotent_trace_of_isNilpotent rw [Module.End.isNilpotent_iff_of_finite] suffices ⨆ i, U' i ≤ Module.End.maxGenEigenspace (T χ w) 0 by intro x specialize this x.2 simp only [Module.End.mem_maxGenEigenspace, zero_smul, sub_zero] at this peel this with n hn ext simp only [ZeroMemClass.coe_zero, ← hn]; clear hn induction n <;> simp_all [pow_succ'] apply iSup_le intro i x hx simp only [Module.End.mem_maxGenEigenspace, zero_smul, sub_zero] induction i using Nat.strong_induction_on generalizing x next i ih => obtain rfl | hi := eq_or_ne i 0 · simp_all [U'] obtain ⟨j, hj, hj'⟩ := key i hi obtain ⟨k, hk⟩ := ih j hj (hj' <| Submodule.mem_map_of_mem hx) use k+1 rw [pow_succ, Module.End.mul_apply, hk] have trace_za : (toEnd R A _ ⁅z, a⁆).trace R U = χ ⁅z, a⁆ • (finrank R U) := by simpa [T, sub_eq_zero] using trace_T_U_zero ⁅z, a⁆ suffices finrank R U ≠ 0 by simp_all suffices Nontrivial U from Module.finrank_pos.ne' have hvU : v ∈ U := by apply Submodule.mem_iSup_of_mem 1 apply Submodule.subset_span use 0, zero_lt_one rw [pow_zero, Module.End.one_apply] exact nontrivial_of_ne ⟨v, hvU⟩ 0 <| by simp [hv'] variable (R V) in /-- The weight space of `V` with respect to `χ : A → R`, a priori a Lie submodule for `A`, is also a Lie submodule for `L`. -/ def weightSpaceOfIsLieTower (χ : A → R) : LieSubmodule R L V := { toSubmodule := weightSpace V χ lie_mem {z v} hv := weightSpaceOfIsLieTower_aux χ z v hv } end section variable {k : Type*} [Field k] variable {L : Type*} [LieRing L] [LieAlgebra k L] variable {V : Type*} [AddCommGroup V] [Module k V] [LieRingModule L V] [LieModule k L V] variable [CharZero k] [Module.Finite k V] open Submodule in theorem exists_nontrivial_weightSpace_of_lieIdeal [LieModule.IsTriangularizable k L V] (A : LieIdeal k L) (hA : IsCoatom A.toSubmodule) (χ₀ : Module.Dual k A) [Nontrivial (weightSpace V χ₀)] : ∃ (χ : Module.Dual k L), Nontrivial (weightSpace V χ) := by obtain ⟨z, -, hz⟩ := SetLike.exists_of_lt (hA.lt_top) let e : (k ∙ z) ≃ₗ[k] k := (LinearEquiv.toSpanNonzeroSingleton k L z <| by aesop).symm have he : ∀ x, e x • z = x := by simp [e] have hA : IsCompl A.toSubmodule (k ∙ z) := isCompl_span_singleton_of_isCoatom_of_notMem hA hz let π₁ : L →ₗ[k] A := A.toSubmodule.linearProjOfIsCompl (k ∙ z) hA let π₂ : L →ₗ[k] (k ∙ z) := (k ∙ z).linearProjOfIsCompl ↑A hA.symm set W : LieSubmodule k L V := weightSpaceOfIsLieTower k V χ₀ obtain ⟨c, hc⟩ : ∃ c, (toEnd k _ W z).HasEigenvalue c := by have : Nontrivial W := inferInstanceAs (Nontrivial (weightSpace V χ₀)) apply Module.End.exists_hasEigenvalue_of_genEigenspace_eq_top exact LieModule.IsTriangularizable.maxGenEigenspace_eq_top z obtain ⟨⟨v, hv⟩, hvc⟩ := hc.exists_hasEigenvector have hv' : ∀ (x : ↥A), ⁅x, v⁆ = χ₀ x • v := by simpa [W, weightSpaceOfIsLieTower, mem_weightSpace] using hv use (χ₀.comp π₁) + c • (e.comp π₂) refine nontrivial_of_ne ⟨v, ?_⟩ 0 ?_ · rw [mem_weightSpace] intro x have hπ : (π₁ x : L) + π₂ x = x := hA.projection_add_projection_eq_self x suffices ⁅hA.symm.projection x, v⁆ = (c • e (π₂ x)) • v by calc ⁅x, v⁆ = ⁅π₁ x, v⁆ + ⁅hA.symm.projection x, v⁆ := congr(⁅$hπ.symm, v⁆) ▸ add_lie _ _ _ _ = χ₀ (π₁ x) • v + (c • e (π₂ x)) • v := by rw [hv' (π₁ x), this] _ = _ := by simp [add_smul] calc ⁅hA.symm.projection x, v⁆ = e (π₂ x) • ↑(c • ⟨v, hv⟩ : W) := by rw [IsCompl.projection_apply, ← he, smul_lie, ← hvc.apply_eq_smul]; rfl _ = (c • e (π₂ x)) • v := by rw [smul_assoc, smul_comm]; rfl · simpa [ne_eq, LieSubmodule.mk_eq_zero] using hvc.right variable (k L V) variable [Nontrivial V] open LieAlgebra -- This lemma is the central inductive argument in the proof of Lie's theorem below. -- The statement is identical to `LieModule.exists_forall_lie_eq_smul_of_isSolvable` -- except that it additionally assumes a finiteness hypothesis. private lemma exists_forall_lie_eq_smul_of_isSolvable_of_finite (L : Type*) [LieRing L] [LieAlgebra k L] [LieRingModule L V] [LieModule k L V] [IsSolvable L] [LieModule.IsTriangularizable k L V] [Module.Finite k L] : ∃ χ : Module.Dual k L, Nontrivial (weightSpace V χ) := by obtain H|⟨A, hA, hAL⟩ := eq_top_or_exists_le_coatom (derivedSeries k L 1).toSubmodule · obtain _ | _ := subsingleton_or_nontrivial L · use 0 simpa [mem_weightSpace, nontrivial_iff] using exists_pair_ne V · rw [LieSubmodule.toSubmodule_eq_top] at H exact ((derivedSeries_lt_top_of_solvable k L).ne H).elim lift A to LieIdeal k L · intros exact hAL <| LieSubmodule.lie_mem_lie (LieSubmodule.mem_top _) (LieSubmodule.mem_top _) obtain ⟨χ', _⟩ := exists_forall_lie_eq_smul_of_isSolvable_of_finite A exact exists_nontrivial_weightSpace_of_lieIdeal A hA χ' termination_by Module.finrank k L decreasing_by simp_wf rw [← finrank_top k L] apply Submodule.finrank_lt_finrank_of_lt exact hA.lt_top /-- **Lie's theorem**: Lie modules of solvable Lie algebras over fields of characteristic 0 have a common eigenvector for the action of all elements of the Lie algebra. See `LieModule.exists_nontrivial_weightSpace_of_isNilpotent` for the variant that assumes that `L` is nilpotent and drops the condition that `k` is of characteristic zero. -/ theorem exists_nontrivial_weightSpace_of_isSolvable [IsSolvable L] [LieModule.IsTriangularizable k L V] : ∃ χ : Module.Dual k L, Nontrivial (weightSpace V χ) := by let imL := (toEnd k L V).range let toEndo : L →ₗ[k] imL := LinearMap.codRestrict imL.toSubmodule (toEnd k L V) (fun x ↦ LinearMap.mem_range.mpr ⟨x, rfl⟩ : ∀ x : L, (toEnd k L V) x ∈ imL) have ⟨χ, h⟩ := exists_forall_lie_eq_smul_of_isSolvable_of_finite k V imL use χ.comp toEndo obtain ⟨⟨v, hv⟩, hv0⟩ := exists_ne (0 : weightSpace V χ) refine nontrivial_of_ne ⟨v, ?_⟩ 0 ?_ · rw [mem_weightSpace] at hv ⊢ intro x apply hv (toEndo x) · simpa using hv0 end end LieModule
.lake/packages/mathlib/Mathlib/Algebra/Lie/Rank.lean
import Mathlib.Algebra.Lie.EngelSubalgebra import Mathlib.Algebra.Lie.OfAssociative import Mathlib.Algebra.Module.LinearMap.Polynomial import Mathlib.LinearAlgebra.Eigenspace.Zero /-! # Rank of a Lie algebra and regular elements Let `L` be a Lie algebra over a nontrivial commutative ring `R`, and assume that `L` is finite free as `R`-module. Then the coefficients of the characteristic polynomial of `ad R L x` are polynomial in `x`. The *rank* of `L` is the smallest `n` for which the `n`-th coefficient is not the zero polynomial. Continuing to write `n` for the rank of `L`, an element `x` of `L` is *regular* if the `n`-th coefficient of the characteristic polynomial of `ad R L x` is non-zero. ## Main declarations * `LieAlgebra.rank R L` is the rank of a Lie algebra `L` over a commutative ring `R`. * `LieAlgebra.IsRegular R x` is the predicate that an element `x` of a Lie algebra `L` is regular. ## References * [barnes1967]: "On Cartan subalgebras of Lie algebras" by D.W. Barnes. -/ open Module variable {R A L M ι ιₘ : Type*} variable [CommRing R] variable [CommRing A] [Algebra R A] variable [LieRing L] [LieAlgebra R L] [Module.Finite R L] [Module.Free R L] variable [AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M] variable [Module.Finite R M] [Module.Free R M] variable [Fintype ι] variable [Fintype ιₘ] variable (b : Basis ι R L) (bₘ : Basis ιₘ R M) (x : L) namespace LieModule open LieAlgebra LinearMap Module.Free variable (R L M) local notation "φ" => LieHom.toLinearMap (LieModule.toEnd R L M) /-- Let `M` be a representation of a Lie algebra `L` over a nontrivial commutative ring `R`, and assume that `L` and `M` are finite free as `R`-module. Then the coefficients of the characteristic polynomial of `⁅x, ·⁆` are polynomial in `x`. The *rank* of `M` is the smallest `n` for which the `n`-th coefficient is not the zero polynomial. -/ noncomputable def rank : ℕ := nilRank φ lemma polyCharpoly_coeff_rank_ne_zero [Nontrivial R] [DecidableEq ι] : (polyCharpoly φ b).coeff (rank R L M) ≠ 0 := polyCharpoly_coeff_nilRank_ne_zero _ _ lemma rank_eq_natTrailingDegree [Nontrivial R] [DecidableEq ι] : rank R L M = (polyCharpoly φ b).natTrailingDegree := by apply nilRank_eq_polyCharpoly_natTrailingDegree open Module include bₘ in lemma rank_le_card [Nontrivial R] : rank R L M ≤ Fintype.card ιₘ := nilRank_le_card _ bₘ open Module lemma rank_le_finrank [Nontrivial R] : rank R L M ≤ finrank R M := nilRank_le_finrank _ variable {L} lemma rank_le_natTrailingDegree_charpoly_ad [Nontrivial R] : rank R L M ≤ (toEnd R L M x).charpoly.natTrailingDegree := nilRank_le_natTrailingDegree_charpoly _ _ /-- Let `x` be an element of a Lie algebra `L` over `R`, and write `n` for `rank R L`. Then `x` is *regular* if the `n`-th coefficient of the characteristic polynomial of `ad R L x` is non-zero. -/ def IsRegular (x : L) : Prop := LinearMap.IsNilRegular φ x lemma isRegular_def : IsRegular R M x ↔ (toEnd R L M x).charpoly.coeff (rank R L M) ≠ 0 := Iff.rfl lemma isRegular_iff_coeff_polyCharpoly_rank_ne_zero [DecidableEq ι] : IsRegular R M x ↔ MvPolynomial.eval (b.repr x) ((polyCharpoly φ b).coeff (rank R L M)) ≠ 0 := LinearMap.isNilRegular_iff_coeff_polyCharpoly_nilRank_ne_zero _ _ _ lemma isRegular_iff_natTrailingDegree_charpoly_eq_rank [Nontrivial R] : IsRegular R M x ↔ (toEnd R L M x).charpoly.natTrailingDegree = rank R L M := LinearMap.isNilRegular_iff_natTrailingDegree_charpoly_eq_nilRank _ _ section IsDomain variable (L) variable [IsDomain R] open Cardinal Module MvPolynomial in lemma exists_isRegular_of_finrank_le_card (h : finrank R M ≤ #R) : ∃ x : L, IsRegular R M x := LinearMap.exists_isNilRegular_of_finrank_le_card _ h lemma exists_isRegular [Infinite R] : ∃ x : L, IsRegular R M x := LinearMap.exists_isNilRegular _ end IsDomain end LieModule namespace LieAlgebra open LieAlgebra LinearMap Module.Free variable (R L) /-- Let `L` be a Lie algebra over a nontrivial commutative ring `R`, and assume that `L` is finite free as `R`-module. Then the coefficients of the characteristic polynomial of `ad R L x` are polynomial in `x`. The *rank* of `L` is the smallest `n` for which the `n`-th coefficient is not the zero polynomial. -/ noncomputable abbrev rank : ℕ := LieModule.rank R L L lemma polyCharpoly_coeff_rank_ne_zero [Nontrivial R] [DecidableEq ι] : (polyCharpoly (ad R L).toLinearMap b).coeff (rank R L) ≠ 0 := polyCharpoly_coeff_nilRank_ne_zero _ _ lemma rank_eq_natTrailingDegree [Nontrivial R] [DecidableEq ι] : rank R L = (polyCharpoly (ad R L).toLinearMap b).natTrailingDegree := by apply nilRank_eq_polyCharpoly_natTrailingDegree open Module include b in lemma rank_le_card [Nontrivial R] : rank R L ≤ Fintype.card ι := nilRank_le_card _ b lemma rank_le_finrank [Nontrivial R] : rank R L ≤ finrank R L := nilRank_le_finrank _ variable {L} lemma rank_le_natTrailingDegree_charpoly_ad [Nontrivial R] : rank R L ≤ (ad R L x).charpoly.natTrailingDegree := nilRank_le_natTrailingDegree_charpoly _ _ /-- Let `x` be an element of a Lie algebra `L` over `R`, and write `n` for `rank R L`. Then `x` is *regular* if the `n`-th coefficient of the characteristic polynomial of `ad R L x` is non-zero. -/ abbrev IsRegular (x : L) : Prop := LieModule.IsRegular R L x lemma isRegular_def : IsRegular R x ↔ (Polynomial.coeff (ad R L x).charpoly (rank R L) ≠ 0) := Iff.rfl lemma isRegular_iff_coeff_polyCharpoly_rank_ne_zero [DecidableEq ι] : IsRegular R x ↔ MvPolynomial.eval (b.repr x) ((polyCharpoly (ad R L).toLinearMap b).coeff (rank R L)) ≠ 0 := LinearMap.isNilRegular_iff_coeff_polyCharpoly_nilRank_ne_zero _ _ _ lemma isRegular_iff_natTrailingDegree_charpoly_eq_rank [Nontrivial R] : IsRegular R x ↔ (ad R L x).charpoly.natTrailingDegree = rank R L := LinearMap.isNilRegular_iff_natTrailingDegree_charpoly_eq_nilRank _ _ section IsDomain variable (L) variable [IsDomain R] open Cardinal Module MvPolynomial in lemma exists_isRegular_of_finrank_le_card (h : finrank R L ≤ #R) : ∃ x : L, IsRegular R x := LinearMap.exists_isNilRegular_of_finrank_le_card _ h lemma exists_isRegular [Infinite R] : ∃ x : L, IsRegular R x := LinearMap.exists_isNilRegular _ end IsDomain end LieAlgebra namespace LieAlgebra variable (K : Type*) {L : Type*} [Field K] [LieRing L] [LieAlgebra K L] [Module.Finite K L] open Module LieSubalgebra lemma finrank_engel (x : L) : finrank K (engel K x) = (ad K L x).charpoly.natTrailingDegree := (ad K L x).finrank_maxGenEigenspace_zero_eq lemma rank_le_finrank_engel (x : L) : rank K L ≤ finrank K (engel K x) := (rank_le_natTrailingDegree_charpoly_ad K x).trans (finrank_engel K x).ge lemma isRegular_iff_finrank_engel_eq_rank (x : L) : IsRegular K x ↔ finrank K (engel K x) = rank K L := by rw [isRegular_iff_natTrailingDegree_charpoly_eq_rank, finrank_engel] end LieAlgebra
.lake/packages/mathlib/Mathlib/Algebra/Lie/NonUnitalNonAssocAlgebra.lean
import Mathlib.Algebra.Algebra.NonUnitalHom import Mathlib.Algebra.Lie.Basic /-! # Lie algebras as non-unital, non-associative algebras The definition of Lie algebras uses the `Bracket` typeclass for multiplication whereas we have a separate `Mul` typeclass used for general algebras. It is useful to have a special typeclass for Lie algebras because: * it enables us to use the traditional notation `⁅x, y⁆` for the Lie multiplication, * associative algebras carry a natural Lie algebra structure via the ring commutator and so we need them to carry both `Mul` and `Bracket` simultaneously, * more generally, Poisson algebras (not yet defined) need both typeclasses. However there are times when it is convenient to be able to regard a Lie algebra as a general algebra and we provide some basic definitions for doing so here. ## Main definitions * `CommutatorRing` turns a Lie ring into a `NonUnitalNonAssocRing` by turning its `Bracket` (denoted `⁅ , ⁆`) into a `Mul` (denoted `*`). * `LieHom.toNonUnitalAlgHom` ## Tags lie algebra, non-unital, non-associative -/ universe u v w variable (R : Type u) (L : Type v) [CommRing R] [LieRing L] [LieAlgebra R L] /-- Type synonym for turning a `LieRing` into a `NonUnitalNonAssocRing`. A `LieRing` can be regarded as a `NonUnitalNonAssocRing` by turning its `Bracket` (denoted `⁅, ⁆`) into a `Mul` (denoted `*`). -/ def CommutatorRing (L : Type v) : Type v := L instance : NonUnitalNonAssocRing (CommutatorRing L) := LieRing.toNonUnitalNonAssocRing L namespace LieAlgebra instance (L : Type v) [Nonempty L] : Nonempty (CommutatorRing L) := ‹Nonempty L› instance (L : Type v) [Inhabited L] : Inhabited (CommutatorRing L) := ‹Inhabited L› instance : LieRing (CommutatorRing L) := show LieRing L by infer_instance instance : LieAlgebra R (CommutatorRing L) := show LieAlgebra R L by infer_instance /-- Regarding the `LieRing` of a `LieAlgebra` as a `NonUnitalNonAssocRing`, we can reinterpret the `smul_lie` law as an `IsScalarTower`. -/ instance isScalarTower : IsScalarTower R (CommutatorRing L) (CommutatorRing L) := ⟨smul_lie⟩ /-- Regarding the `LieRing` of a `LieAlgebra` as a `NonUnitalNonAssocRing`, we can reinterpret the `lie_smul` law as an `SMulCommClass`. -/ instance smulCommClass : SMulCommClass R (CommutatorRing L) (CommutatorRing L) := ⟨fun t x y => (lie_smul t x y).symm⟩ end LieAlgebra namespace LieHom variable {R L} variable {L₂ : Type w} [LieRing L₂] [LieAlgebra R L₂] /-- Regarding the `LieRing` of a `LieAlgebra` as a `NonUnitalNonAssocRing`, we can regard a `LieHom` as a `NonUnitalAlgHom`. -/ @[simps] def toNonUnitalAlgHom (f : L →ₗ⁅R⁆ L₂) : CommutatorRing L →ₙₐ[R] CommutatorRing L₂ := { f with toFun := f map_zero' := f.toLinearMap.map_zero map_mul' := f.map_lie } theorem toNonUnitalAlgHom_injective : Function.Injective (toNonUnitalAlgHom : _ → CommutatorRing L →ₙₐ[R] CommutatorRing L₂) := fun _ _ h => ext <| NonUnitalAlgHom.congr_fun h end LieHom
.lake/packages/mathlib/Mathlib/Algebra/Lie/InvariantForm.lean
import Mathlib.Algebra.Lie.Semisimple.Defs import Mathlib.LinearAlgebra.BilinearForm.Orthogonal /-! # Lie algebras with non-degenerate invariant bilinear forms are semisimple In this file we prove that a finite-dimensional Lie algebra over a field is semisimple if it does not have non-trivial abelian ideals and it admits a non-degenerate reflexive invariant bilinear form. Here a form is *invariant* if it invariant under the Lie bracket in the sense that `⁅x, Φ⁆ = 0` for all `x` or equivalently, `Φ ⁅x, y⁆ z = Φ x ⁅y, z⁆`. ## Main results * `LieAlgebra.InvariantForm.orthogonal`: given a Lie submodule `N` of a Lie module `M`, we define its orthogonal complement with respect to a non-degenerate invariant bilinear form `Φ` as the Lie ideal of elements `x` such that `Φ n x = 0` for all `n ∈ N`. * `LieAlgebra.InvariantForm.isSemisimple_of_nondegenerate`: the main result of this file; a finite-dimensional Lie algebra over a field is semisimple if it does not have non-trivial abelian ideals and admits a non-degenerate invariant reflexive bilinear form. ## References We follow the short and excellent paper [dieudonne1953]. -/ namespace LieAlgebra namespace InvariantForm section ring variable {R L M : Type*} variable [CommRing R] [LieRing L] variable [AddCommGroup M] [Module R M] [LieRingModule L M] variable (Φ : LinearMap.BilinForm R M) (hΦ_nondeg : Φ.Nondegenerate) variable (L) in /-- A bilinear form on a Lie module `M` of a Lie algebra `L` is *invariant* if for all `x : L` and `y z : M` the condition `Φ ⁅x, y⁆ z = -Φ y ⁅x, z⁆` holds. -/ def _root_.LinearMap.BilinForm.lieInvariant : Prop := ∀ (x : L) (y z : M), Φ ⁅x, y⁆ z = -Φ y ⁅x, z⁆ lemma _root_.LinearMap.BilinForm.lieInvariant_iff [LieAlgebra R L] [LieModule R L M] : Φ.lieInvariant L ↔ Φ ∈ LieModule.maxTrivSubmodule R L (LinearMap.BilinForm R M) := by refine ⟨fun h x ↦ ?_, fun h x y z ↦ ?_⟩ · ext y z rw [LieHom.lie_apply, LinearMap.sub_apply, Module.Dual.lie_apply, LinearMap.zero_apply, LinearMap.zero_apply, h, sub_self] · replace h := LinearMap.congr_fun₂ (h x) y z simp only [LieHom.lie_apply, LinearMap.sub_apply, Module.Dual.lie_apply, LinearMap.zero_apply, sub_eq_zero] at h simp [← h] /-- The orthogonal complement of a Lie submodule `N` with respect to an invariant bilinear form `Φ` is the Lie submodule of elements `y` such that `Φ x y = 0` for all `x ∈ N`. -/ @[simps!] def orthogonal (hΦ_inv : Φ.lieInvariant L) (N : LieSubmodule R L M) : LieSubmodule R L M where __ := Φ.orthogonal N lie_mem {x y} := by suffices (∀ n ∈ N, Φ n y = 0) → ∀ n ∈ N, Φ n ⁅x, y⁆ = 0 by simpa only [LinearMap.BilinForm.isOrtho_def, -- and some default simp lemmas AddSubsemigroup.mem_carrier, AddSubmonoid.mem_toSubsemigroup, Submodule.mem_toAddSubmonoid, LinearMap.BilinForm.mem_orthogonal_iff, LieSubmodule.mem_toSubmodule] intro H a ha rw [← neg_eq_zero, ← hΦ_inv] exact H _ <| N.lie_mem ha variable (hΦ_inv : Φ.lieInvariant L) @[simp] lemma orthogonal_toSubmodule (N : LieSubmodule R L M) : (orthogonal Φ hΦ_inv N).toSubmodule = Φ.orthogonal N.toSubmodule := rfl lemma mem_orthogonal (N : LieSubmodule R L M) (y : M) : y ∈ orthogonal Φ hΦ_inv N ↔ ∀ x ∈ N, Φ x y = 0 := by simp [orthogonal, LinearMap.BilinForm.isOrtho_def, LinearMap.BilinForm.mem_orthogonal_iff] variable [LieAlgebra R L] lemma orthogonal_disjoint (Φ : LinearMap.BilinForm R L) (hΦ_nondeg : Φ.Nondegenerate) (hΦ_inv : Φ.lieInvariant L) -- TODO: replace the following assumption by a typeclass assumption `[HasNonAbelianAtoms]` (hL : ∀ I : LieIdeal R L, IsAtom I → ¬IsLieAbelian I) (I : LieIdeal R L) (hI : IsAtom I) : Disjoint I (orthogonal Φ hΦ_inv I) := by rw [disjoint_iff, ← hI.lt_iff, lt_iff_le_and_ne] suffices ¬I ≤ orthogonal Φ hΦ_inv I by simpa intro contra apply hI.1 rw [eq_bot_iff, ← lie_eq_self_of_isAtom_of_nonabelian I hI (hL I hI), LieSubmodule.lieIdeal_oper_eq_span, LieSubmodule.lieSpan_le] rintro _ ⟨x, y, rfl⟩ simp only [LieSubmodule.bot_coe, Set.mem_singleton_iff] apply hΦ_nondeg intro z rw [hΦ_inv, neg_eq_zero] have hyz : ⁅(x : L), z⁆ ∈ I := lie_mem_left _ _ _ _ _ x.2 exact contra hyz y y.2 end ring section field variable {K L M : Type*} variable [Field K] [LieRing L] [LieAlgebra K L] variable [AddCommGroup M] [Module K M] [LieRingModule L M] variable [Module.Finite K L] variable (Φ : LinearMap.BilinForm K L) (hΦ_nondeg : Φ.Nondegenerate) variable (hΦ_inv : Φ.lieInvariant L) (hΦ_refl : Φ.IsRefl) -- TODO: replace the following assumption by a typeclass assumption `[HasNonAbelianAtoms]` variable (hL : ∀ I : LieIdeal K L, IsAtom I → ¬IsLieAbelian I) include hΦ_nondeg hΦ_refl hL open Module Submodule in lemma orthogonal_isCompl_toSubmodule (I : LieIdeal K L) (hI : IsAtom I) : IsCompl I.toSubmodule (orthogonal Φ hΦ_inv I).toSubmodule := by rw [orthogonal_toSubmodule, LinearMap.BilinForm.isCompl_orthogonal_iff_disjoint hΦ_refl, ← orthogonal_toSubmodule _ hΦ_inv, LieSubmodule.disjoint_toSubmodule] exact orthogonal_disjoint Φ hΦ_nondeg hΦ_inv hL I hI open Module Submodule in lemma orthogonal_isCompl (I : LieIdeal K L) (hI : IsAtom I) : IsCompl I (orthogonal Φ hΦ_inv I) := by rw [← LieSubmodule.isCompl_toSubmodule] exact orthogonal_isCompl_toSubmodule Φ hΦ_nondeg hΦ_inv hΦ_refl hL I hI include hΦ_inv lemma restrict_nondegenerate (I : LieIdeal K L) (hI : IsAtom I) : (Φ.restrict I).Nondegenerate := by rw [LinearMap.BilinForm.restrict_nondegenerate_iff_isCompl_orthogonal hΦ_refl] exact orthogonal_isCompl_toSubmodule Φ hΦ_nondeg hΦ_inv hΦ_refl hL I hI lemma restrict_orthogonal_nondegenerate (I : LieIdeal K L) (hI : IsAtom I) : (Φ.restrict (orthogonal Φ hΦ_inv I)).Nondegenerate := by rw [LinearMap.BilinForm.restrict_nondegenerate_iff_isCompl_orthogonal hΦ_refl] simp only [LieIdeal.toLieSubalgebra_toSubmodule, orthogonal_toSubmodule, LinearMap.BilinForm.orthogonal_orthogonal hΦ_nondeg hΦ_refl] exact (orthogonal_isCompl_toSubmodule Φ hΦ_nondeg hΦ_inv hΦ_refl hL I hI).symm open Module Submodule in lemma atomistic : ∀ I : LieIdeal K L, sSup {J : LieIdeal K L | IsAtom J ∧ J ≤ I} = I := by intro I apply le_antisymm · apply sSup_le rintro J ⟨-, hJ'⟩ exact hJ' by_cases hI : I = ⊥ · exact hI.le.trans bot_le obtain ⟨J, hJ, hJI⟩ := (eq_bot_or_exists_atom_le I).resolve_left hI let J' := orthogonal Φ hΦ_inv J suffices I ≤ J ⊔ (J' ⊓ I) by refine this.trans ?_ apply sup_le · exact le_sSup ⟨hJ, hJI⟩ rw [← atomistic (J' ⊓ I)] apply sSup_le_sSup simp only [le_inf_iff, Set.setOf_subset_setOf, and_imp] tauto suffices J ⊔ J' = ⊤ by rw [← sup_inf_assoc_of_le _ hJI, this, top_inf_eq] exact (orthogonal_isCompl Φ hΦ_nondeg hΦ_inv hΦ_refl hL J hJ).codisjoint.eq_top termination_by I => finrank K I decreasing_by apply finrank_lt_finrank_of_lt suffices ¬I ≤ J' by simpa intro hIJ' apply hJ.1 rw [eq_bot_iff] exact orthogonal_disjoint Φ hΦ_nondeg hΦ_inv hL J hJ le_rfl (hJI.trans hIJ') open LieSubmodule in /-- A finite-dimensional Lie algebra over a field is semisimple if it does not have non-trivial abelian ideals and it admits a non-degenerate reflexive invariant bilinear form. Here a form is *invariant* if it is compatible with the Lie bracket: `Φ ⁅x, y⁆ z = Φ x ⁅y, z⁆`. -/ theorem isSemisimple_of_nondegenerate : IsSemisimple K L := by refine ⟨?_, ?_, hL⟩ · simpa using atomistic Φ hΦ_nondeg hΦ_inv hΦ_refl hL ⊤ intro I hI apply (orthogonal_disjoint Φ hΦ_nondeg hΦ_inv hL I hI).mono_right apply sSup_le simp only [Set.mem_diff, Set.mem_setOf_eq, Set.mem_singleton_iff, and_imp] intro J hJ hJI rw [← lie_eq_self_of_isAtom_of_nonabelian J hJ (hL J hJ), lieIdeal_oper_eq_span, lieSpan_le] rintro _ ⟨x, y, rfl⟩ simp only [orthogonal_carrier, Φ.isOrtho_def, Set.mem_setOf_eq] intro z hz rw [← neg_eq_zero, ← hΦ_inv] suffices ⁅(x : L), z⁆ = 0 by simp only [this, map_zero, LinearMap.zero_apply] rw [← LieSubmodule.mem_bot (R := K) (L := L), ← (hJ.disjoint_of_ne hI hJI).eq_bot] apply lie_le_inf exact lie_mem_lie x.2 hz end field end InvariantForm end LieAlgebra
.lake/packages/mathlib/Mathlib/Algebra/Lie/OfAssociative.lean
import Mathlib.Algebra.Lie.Basic import Mathlib.Algebra.Lie.Subalgebra import Mathlib.Algebra.Lie.Submodule import Mathlib.Algebra.Algebra.Subalgebra.Basic /-! # Lie algebras of associative algebras This file defines the Lie algebra structure that arises on an associative algebra via the ring commutator. Since the linear endomorphisms of a Lie algebra form an associative algebra, one can define the adjoint action as a morphism of Lie algebras from a Lie algebra to its linear endomorphisms. We make such a definition in this file. ## Main definitions * `LieAlgebra.ofAssociativeAlgebra` * `LieAlgebra.ofAssociativeAlgebraHom` * `LieModule.toEnd` * `LieAlgebra.ad` * `LinearEquiv.lieConj` * `AlgEquiv.toLieEquiv` ## Tags lie algebra, ring commutator, adjoint action -/ universe u v w w₁ w₂ section OfAssociative variable {A : Type v} [Ring A] namespace LieRing /-- An associative ring gives rise to a Lie ring by taking the bracket to be the ring commutator. -/ instance (priority := 100) ofAssociativeRing : LieRing A where add_lie _ _ _ := by simp only [Ring.lie_def, right_distrib, left_distrib]; abel lie_add _ _ _ := by simp only [Ring.lie_def, right_distrib, left_distrib]; abel lie_self := by simp only [Ring.lie_def, forall_const, sub_self] leibniz_lie _ _ _ := by simp only [Ring.lie_def, mul_sub_left_distrib, mul_sub_right_distrib, mul_assoc]; abel theorem of_associative_ring_bracket (x y : A) : ⁅x, y⁆ = x * y - y * x := rfl @[simp] theorem lie_apply {α : Type*} (f g : α → A) (a : α) : ⁅f, g⁆ a = ⁅f a, g a⁆ := rfl end LieRing section AssociativeModule variable {M : Type w} [AddCommGroup M] [Module A M] /-- We can regard a module over an associative ring `A` as a Lie ring module over `A` with Lie bracket equal to its ring commutator. Note that this cannot be a global instance because it would create a diamond when `M = A`, specifically we can build two mathematically-different `bracket A A`s: 1. `@Ring.bracket A _` which says `⁅a, b⁆ = a * b - b * a` 2. `(@LieRingModule.ofAssociativeModule A _ A _ _).toBracket` which says `⁅a, b⁆ = a • b` (and thus `⁅a, b⁆ = a * b`) See note [reducible non-instances] -/ abbrev LieRingModule.ofAssociativeModule : LieRingModule A M where bracket := (· • ·) add_lie := add_smul lie_add := smul_add leibniz_lie := by simp [LieRing.of_associative_ring_bracket, sub_smul, mul_smul, sub_add_cancel] attribute [local instance] LieRingModule.ofAssociativeModule theorem lie_eq_smul (a : A) (m : M) : ⁅a, m⁆ = a • m := rfl end AssociativeModule section LieAlgebra variable {R : Type u} [CommRing R] [Algebra R A] /-- An associative algebra gives rise to a Lie algebra by taking the bracket to be the ring commutator. -/ instance (priority := 100) LieAlgebra.ofAssociativeAlgebra : LieAlgebra R A where lie_smul t x y := by rw [LieRing.of_associative_ring_bracket, LieRing.of_associative_ring_bracket, Algebra.mul_smul_comm, Algebra.smul_mul_assoc, smul_sub] attribute [local instance] LieRingModule.ofAssociativeModule section AssociativeRepresentation variable {M : Type w} [AddCommGroup M] [Module R M] [Module A M] [IsScalarTower R A M] /-- A representation of an associative algebra `A` is also a representation of `A`, regarded as a Lie algebra via the ring commutator. See the comment at `LieRingModule.ofAssociativeModule` for why the possibility `M = A` means this cannot be a global instance. -/ theorem LieModule.ofAssociativeModule : LieModule R A M where smul_lie := smul_assoc lie_smul := smul_algebra_smul_comm instance Module.End.instLieRingModule : LieRingModule (Module.End R M) M := LieRingModule.ofAssociativeModule instance Module.End.instLieModule : LieModule R (Module.End R M) M := LieModule.ofAssociativeModule @[simp] lemma Module.End.lie_apply (f : Module.End R M) (m : M) : ⁅f, m⁆ = f m := rfl end AssociativeRepresentation namespace AlgHom variable {B : Type w} {C : Type w₁} [Ring B] [Ring C] [Algebra R B] [Algebra R C] variable (f : A →ₐ[R] B) (g : B →ₐ[R] C) /-- The map `ofAssociativeAlgebra` associating a Lie algebra to an associative algebra is functorial. -/ def toLieHom : A →ₗ⁅R⁆ B := { f.toLinearMap with map_lie' := fun {_ _} => by simp [LieRing.of_associative_ring_bracket] } instance : Coe (A →ₐ[R] B) (A →ₗ⁅R⁆ B) := ⟨toLieHom⟩ @[simp] theorem coe_toLieHom : ((f : A →ₗ⁅R⁆ B) : A → B) = f := rfl theorem toLieHom_apply (x : A) : f.toLieHom x = f x := rfl @[simp] theorem toLieHom_id : (AlgHom.id R A : A →ₗ⁅R⁆ A) = LieHom.id := rfl @[simp] theorem toLieHom_comp : (g.comp f : A →ₗ⁅R⁆ C) = (g : B →ₗ⁅R⁆ C).comp (f : A →ₗ⁅R⁆ B) := rfl theorem toLieHom_injective {f g : A →ₐ[R] B} (h : (f : A →ₗ⁅R⁆ B) = (g : A →ₗ⁅R⁆ B)) : f = g := by ext a; exact LieHom.congr_fun h a end AlgHom end LieAlgebra end OfAssociative section AdjointAction variable (R : Type u) (L : Type v) (M : Type w) variable [CommRing R] [LieRing L] [LieAlgebra R L] [AddCommGroup M] [Module R M] variable [LieRingModule L M] [LieModule R L M] /-- A Lie module yields a Lie algebra morphism into the linear endomorphisms of the module. See also `LieModule.toModuleHom`. -/ @[simps] def LieModule.toEnd : L →ₗ⁅R⁆ Module.End R M where toFun x := { toFun := fun m => ⁅x, m⁆ map_add' := lie_add x map_smul' := fun t => lie_smul t x } map_add' x y := by ext m; apply add_lie map_smul' t x := by ext m; apply smul_lie map_lie' {x y} := by ext m; apply lie_lie /-- The adjoint action of a Lie algebra on itself. -/ def LieAlgebra.ad : L →ₗ⁅R⁆ Module.End R L := LieModule.toEnd R L L @[simp] theorem LieAlgebra.ad_apply (x y : L) : LieAlgebra.ad R L x y = ⁅x, y⁆ := rfl @[simp] theorem LieModule.toEnd_module_end : LieModule.toEnd R (Module.End R M) M = LieHom.id := by ext g m; simp [lie_eq_smul] theorem LieSubalgebra.toEnd_eq (K : LieSubalgebra R L) {x : K} : LieModule.toEnd R K M x = LieModule.toEnd R L M x := rfl @[simp] theorem LieSubalgebra.toEnd_mk (K : LieSubalgebra R L) {x : L} (hx : x ∈ K) : LieModule.toEnd R K M ⟨x, hx⟩ = LieModule.toEnd R L M x := rfl section IsFaithful open Function namespace LieModule /-- A Lie module is *faithful* if the associated map `L → End M` is injective. -/ @[mk_iff] class IsFaithful : Prop where injective_toEnd : Injective <| toEnd R L M @[simp] lemma toEnd_eq_iff [IsFaithful R L M] {x y : L} : toEnd R L M x = toEnd R L M y ↔ x = y := IsFaithful.injective_toEnd.eq_iff variable {R L} in lemma ext_of_isFaithful [IsFaithful R L M] {x y : L} (h : ∀ m : M, ⁅x, m⁆ = ⁅y, m⁆) : x = y := (toEnd_eq_iff R L M).mp <| LinearMap.ext h @[simp] lemma toEnd_eq_zero_iff [IsFaithful R L M] {x : L} : toEnd R L M x = 0 ↔ x = 0 := by rw [← (toEnd R L M).toLinearMap.map_zero] exact toEnd_eq_iff R L M lemma isFaithful_iff' : IsFaithful R L M ↔ ∀ x : L, (∀ m : M, ⁅x, m⁆ = 0) → x = 0 := by refine ⟨fun h x hx ↦ ?_, fun h ↦ ⟨fun x y hxy ↦ ?_⟩⟩ · replace hx : toEnd R L M x = 0 := by ext m; simpa using hx m simpa using hx · rw [← sub_eq_zero] refine h _ fun m ↦ ?_ rw [sub_lie, sub_eq_zero, ← toEnd_apply_apply R, ← toEnd_apply_apply R, hxy] instance [IsFaithful R L M] {L' : LieSubalgebra R L} : IsFaithful R L' M := by refine ⟨(?_ : Injective (toEnd R L M ∘ ((↑) : L' → L)))⟩ exact IsFaithful.injective_toEnd.comp Subtype.val_injective instance : IsFaithful R (Module.End R M) M where injective_toEnd := by simpa using injective_id end LieModule end IsFaithful section open LieAlgebra LieModule lemma LieSubmodule.coe_toEnd (N : LieSubmodule R L M) (x : L) (y : N) : (toEnd R L N x y : M) = toEnd R L M x y := rfl lemma LieSubmodule.coe_toEnd_pow (N : LieSubmodule R L M) (x : L) (y : N) (n : ℕ) : ((toEnd R L N x ^ n) y : M) = (toEnd R L M x ^ n) y := by induction n generalizing y with | zero => rfl | succ n ih => simp only [pow_succ', Module.End.mul_apply, ih, LieSubmodule.coe_toEnd] lemma LieSubalgebra.coe_ad (H : LieSubalgebra R L) (x y : H) : (ad R H x y : L) = ad R L x y := rfl lemma LieSubalgebra.coe_ad_pow (H : LieSubalgebra R L) (x y : H) (n : ℕ) : ((ad R H x ^ n) y : L) = (ad R L x ^ n) y := LieSubmodule.coe_toEnd_pow R H L H.toLieSubmodule x y n variable {L M} local notation "φ" => LieModule.toEnd R L M lemma LieModule.toEnd_lie (x y : L) (z : M) : (φ x) ⁅y, z⁆ = ⁅ad R L x y, z⁆ + ⁅y, φ x z⁆ := by simp lemma LieAlgebra.ad_lie (x y z : L) : (ad R L x) ⁅y, z⁆ = ⁅ad R L x y, z⁆ + ⁅y, ad R L x z⁆ := toEnd_lie _ x y z open Finset in lemma LieModule.toEnd_pow_lie (x y : L) (z : M) (n : ℕ) : ((φ x) ^ n) ⁅y, z⁆ = ∑ ij ∈ antidiagonal n, n.choose ij.1 • ⁅((ad R L x) ^ ij.1) y, ((φ x) ^ ij.2) z⁆ := by induction n with | zero => simp | succ n ih => rw [Finset.sum_antidiagonal_choose_succ_nsmul (fun i j ↦ ⁅((ad R L x) ^ i) y, ((φ x) ^ j) z⁆) n] simp only [pow_succ', Module.End.mul_apply, ih, map_sum, map_nsmul, toEnd_lie, nsmul_add, sum_add_distrib] rw [add_comm, add_left_cancel_iff, sum_congr rfl] rintro ⟨i, j⟩ hij rw [mem_antidiagonal] at hij rw [Nat.choose_symm_of_eq_add hij.symm] open Finset in lemma LieAlgebra.ad_pow_lie (x y z : L) (n : ℕ) : ((ad R L x) ^ n) ⁅y, z⁆ = ∑ ij ∈ antidiagonal n, n.choose ij.1 • ⁅((ad R L x) ^ ij.1) y, ((ad R L x) ^ ij.2) z⁆ := toEnd_pow_lie _ x y z n end variable {R L M} namespace LieModule variable {M₂ : Type w₁} [AddCommGroup M₂] [Module R M₂] [LieRingModule L M₂] [LieModule R L M₂] (f : M →ₗ⁅R,L⁆ M₂) (k : ℕ) (x : L) lemma toEnd_pow_comp_lieHom : (toEnd R L M₂ x ^ k) ∘ₗ f = f ∘ₗ toEnd R L M x ^ k := by apply Module.End.commute_pow_left_of_commute ext simp lemma toEnd_pow_apply_map (m : M) : (toEnd R L M₂ x ^ k) (f m) = f ((toEnd R L M x ^ k) m) := LinearMap.congr_fun (toEnd_pow_comp_lieHom f k x) m end LieModule namespace LieSubmodule open LieModule Set variable {N : LieSubmodule R L M} {x : L} theorem coe_map_toEnd_le : (N : Submodule R M).map (LieModule.toEnd R L M x) ≤ N := by rintro n ⟨m, hm, rfl⟩ exact N.lie_mem hm variable (N x) theorem toEnd_comp_subtype_mem (m : M) (hm : m ∈ (N : Submodule R M)) : (toEnd R L M x).comp (N : Submodule R M).subtype ⟨m, hm⟩ ∈ (N : Submodule R M) := by simpa using N.lie_mem hm @[simp] theorem toEnd_restrict_eq_toEnd (h := N.toEnd_comp_subtype_mem x) : (toEnd R L M x).restrict h = toEnd R L N x := by rfl lemma mapsTo_pow_toEnd_sub_algebraMap {φ : R} {k : ℕ} {x : L} : MapsTo ((toEnd R L M x - algebraMap R (Module.End R M) φ) ^ k) N N := by rw [Module.End.coe_pow] exact MapsTo.iterate (fun m hm ↦ N.sub_mem (N.lie_mem hm) (N.smul_mem _ hm)) k end LieSubmodule open LieAlgebra theorem LieAlgebra.ad_eq_lmul_left_sub_lmul_right (A : Type v) [Ring A] [Algebra R A] : (ad R A : A → Module.End R A) = LinearMap.mulLeft R - LinearMap.mulRight R := by ext a b; simp [LieRing.of_associative_ring_bracket] theorem LieSubalgebra.ad_comp_incl_eq (K : LieSubalgebra R L) (x : K) : (ad R L ↑x).comp (K.incl : K →ₗ[R] L) = (K.incl : K →ₗ[R] L).comp (ad R K x) := by ext y simp only [ad_apply, LieHom.coe_toLinearMap, LieSubalgebra.coe_incl, LinearMap.coe_comp, LieSubalgebra.coe_bracket, Function.comp_apply] end AdjointAction /-- A subalgebra of an associative algebra is a Lie subalgebra of the associated Lie algebra. -/ def lieSubalgebraOfSubalgebra (R : Type u) [CommRing R] (A : Type v) [Ring A] [Algebra R A] (A' : Subalgebra R A) : LieSubalgebra R A := { Subalgebra.toSubmodule A' with lie_mem' := fun {x y} hx hy => by change ⁅x, y⁆ ∈ A'; change x ∈ A' at hx; change y ∈ A' at hy rw [LieRing.of_associative_ring_bracket] have hxy := A'.mul_mem hx hy have hyx := A'.mul_mem hy hx exact Submodule.sub_mem (Subalgebra.toSubmodule A') hxy hyx } namespace LinearEquiv variable {R : Type u} {M₁ : Type v} {M₂ : Type w} variable [CommRing R] [AddCommGroup M₁] [Module R M₁] [AddCommGroup M₂] [Module R M₂] variable (e : M₁ ≃ₗ[R] M₂) /-- A linear equivalence of two modules induces a Lie algebra equivalence of their endomorphisms. -/ def lieConj : Module.End R M₁ ≃ₗ⁅R⁆ Module.End R M₂ := { e.conj with map_lie' := fun {f g} => show e.conj ⁅f, g⁆ = ⁅e.conj f, e.conj g⁆ by simp only [LieRing.of_associative_ring_bracket, Module.End.mul_eq_comp, e.conj_comp, map_sub] } @[simp] theorem lieConj_apply (f : Module.End R M₁) : e.lieConj f = e.conj f := rfl @[simp] theorem lieConj_symm : e.lieConj.symm = e.symm.lieConj := rfl end LinearEquiv namespace AlgEquiv variable {R : Type u} {A₁ : Type v} {A₂ : Type w} variable [CommRing R] [Ring A₁] [Ring A₂] [Algebra R A₁] [Algebra R A₂] variable (e : A₁ ≃ₐ[R] A₂) /-- An equivalence of associative algebras is an equivalence of associated Lie algebras. -/ def toLieEquiv : A₁ ≃ₗ⁅R⁆ A₂ := { e.toLinearEquiv with toFun := e.toFun map_lie' := fun {x y} => by have : e.toEquiv.toFun = e := rfl simp_rw [LieRing.of_associative_ring_bracket, this, map_sub, map_mul] } @[simp] theorem toLieEquiv_apply (x : A₁) : e.toLieEquiv x = e x := rfl @[simp] theorem toLieEquiv_symm_apply (x : A₂) : e.toLieEquiv.symm x = e.symm x := rfl end AlgEquiv namespace LieAlgebra variable {R L L' : Type*} [CommRing R] [LieRing L] [LieAlgebra R L] [LieRing L'] [LieAlgebra R L'] open LieEquiv /-- Given an equivalence `e` of Lie algebras from `L` to `L'`, and an element `x : L`, the conjugate of the endomorphism `ad(x)` of `L` by `e` is the endomorphism `ad(e x)` of `L'`. -/ @[simp] lemma conj_ad_apply (e : L ≃ₗ⁅R⁆ L') (x : L) : e.toLinearEquiv.conj (ad R L x) = ad R L' (e x) := by ext y' rw [LinearEquiv.conj_apply_apply, ad_apply, ad_apply, coe_toLinearEquiv, map_lie, ← coe_toLinearEquiv, LinearEquiv.apply_symm_apply] end LieAlgebra
.lake/packages/mathlib/Mathlib/Algebra/Lie/Extension.lean
import Mathlib.Algebra.Exact import Mathlib.Algebra.Lie.Cochain import Mathlib.Algebra.Module.TransferInstance /-! # Extensions of Lie algebras This file defines extensions of Lie algebras, given by short exact sequences of Lie algebra homomorphisms. They are implemented in two ways: `IsExtension` is a `Prop`-valued class taking two homomorphisms as parameters, and `Extension` is a structure that includes the middle Lie algebra. Because our sign convention for differentials is opposite that of Chevalley-Eilenberg, there is a change of signs in the "action" part of the Lie bracket. ## Main definitions * `LieAlgebra.IsExtension`: A `Prop`-valued class characterizing an extension of Lie algebras. * `LieAlgebra.Extension`: A bundled structure giving an extension of Lie algebras. * `LieAlgebra.IsExtension.extension`: A function that builds the bundled structure from the class. * `LieAlgebra.ofTwoCocycle`: The Lie algebra built from a direct product, but whose bracket product is sheared by a 2-cocycle. * `LieAlgebra.Extension.ofTwoCocycle` - The Lie algebra extension constructed from a 2-cocycle. ## TODO * `IsCentral` - central extensions * `Equiv` - equivalence of extensions * The 2-cocycle given by a linear splitting of an extension. * The 2-coboundary from two linear splittings of an extension. ## References * [Chevalley, Eilenberg, *Cohomology Theory of Lie Groups and Lie Algebras*](chevalley_eilenberg_1948) * [N. Bourbaki, *Lie Groups and Lie Algebras, Chapters 1--3*](bourbaki1975) -/ namespace LieAlgebra variable {R N L M : Type*} section IsExtension variable [CommRing R] [LieRing L] [LieAlgebra R L] [LieRing N] [LieAlgebra R N] [LieRing M] [LieAlgebra R M] /-- A sequence of two Lie algebra homomorphisms is an extension if it is short exact. -/ class IsExtension (i : N →ₗ⁅R⁆ L) (p : L →ₗ⁅R⁆ M) : Prop where ker_eq_bot : i.ker = ⊥ range_eq_top : p.range = ⊤ exact : i.range = p.ker lemma _root_.LieHom.range_eq_ker_iff (i : N →ₗ⁅R⁆ L) (p : L →ₗ⁅R⁆ M) : i.range = p.ker ↔ Function.Exact i p := ⟨fun h x ↦ by simp [← LieHom.coe_range, h], fun h ↦ (p.ker.toLieSubalgebra.ext i.range h).symm⟩ variable (R N M) in /-- The type of all Lie extensions of `M` by `N`. That is, short exact sequences of `R`-Lie algebra homomorphisms `0 → N → L → M → 0` where `R`, `M`, and `N` are fixed. -/ structure Extension where /-- The middle object in the sequence. -/ L : Type* /-- `L` is a Lie ring. -/ instLieRing : LieRing L /-- `L` is a Lie algebra over `R`. -/ instLieAlgebra : LieAlgebra R L /-- The inclusion homomorphism `N →ₗ⁅R⁆ L` -/ incl : N →ₗ⁅R⁆ L /-- The projection homomorphism `L →ₗ⁅R⁆ M` -/ proj : L →ₗ⁅R⁆ M IsExtension : IsExtension incl proj /-- The bundled `LieAlgebra.Extension` corresponding to `LieAlgebra.IsExtension` -/ @[simps] def IsExtension.extension {i : N →ₗ⁅R⁆ L} {p : L →ₗ⁅R⁆ M} (h : IsExtension i p) : Extension R N M := ⟨L, _, _, i, p, h⟩ /-- A surjective Lie algebra homomorphism yields an extension. -/ theorem isExtension_of_surjective (f : L →ₗ⁅R⁆ M) (hf : Function.Surjective f) : IsExtension f.ker.incl f where ker_eq_bot := LieIdeal.ker_incl f.ker range_eq_top := (LieHom.range_eq_top f).mpr hf exact := LieIdeal.incl_range f.ker end IsExtension section Algebra variable [CommRing R] [LieRing L] [LieAlgebra R L] open LieModule.Cohomology /-- A one-field structure giving a type synonym for a direct product. We use this to describe an alternative Lie algebra structure on the product, where the bracket is shifted by a 2-cocycle. -/ structure ofTwoCocycle {R L M} [CommRing R] [LieRing L] [LieAlgebra R L] [AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M] (c : twoCocycle R L M) where /-- The underlying type. -/ carrier : L × M variable [AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M] (c : twoCocycle R L M) /-- An equivalence between the direct product and the corresponding one-field structure. This is used to transfer the additive and scalar-multiple structure on the direct product to the type synonym. -/ def ofProd : L × M ≃ ofTwoCocycle c where toFun a := ⟨ a ⟩ invFun a := a.carrier -- transport instances along the equivalence instance : AddCommGroup (ofTwoCocycle c) := (ofProd c).symm.addCommGroup instance : Module R (ofTwoCocycle c) := (ofProd c).symm.module R @[simp] lemma of_zero : ofProd c (0 : L × M) = 0 := rfl @[simp] lemma of_add (x y : L × M) : ofProd c (x + y) = ofProd c x + ofProd c y := rfl @[simp] lemma of_smul (r : R) (x : L × M) : (ofProd c) (r • x) = r • ofProd c x := rfl @[simp] lemma of_symm_zero : (ofProd c).symm (0 : ofTwoCocycle c) = 0 := rfl @[simp] lemma of_symm_add (x y : ofTwoCocycle c) : (ofProd c).symm (x + y) = (ofProd c).symm x + (ofProd c).symm y := rfl @[simp] lemma of_symm_smul (r : R) (x : ofTwoCocycle c) : (ofProd c).symm (r • x) = r • (ofProd c).symm x := rfl @[simp] lemma of_nsmul (n : ℕ) (x : L × M) : (ofProd c) (n • x) = n • (ofProd c) x := rfl @[simp] lemma of_symm_nsmul (n : ℕ) (x : ofTwoCocycle c) : (ofProd c).symm (n • x) = n • (ofProd c).symm x := rfl instance : LieRing (ofTwoCocycle c) where bracket x y := letI x₁ := ((ofProd c).symm x).1; letI x₂ := ((ofProd c).symm x).2 letI y₁ := ((ofProd c).symm y).1; letI y₂ := ((ofProd c).symm y).2 ofProd c (⁅x₁, y₁⁆, (c : L →ₗ[R] L →ₗ[R] M) x₁ y₁ + ⁅x₁, y₂⁆ - ⁅y₁, x₂⁆) add_lie x y z := by rw [← of_add] refine Equiv.congr_arg ?_ simp only [of_symm_add, Prod.fst_add, add_lie, twoCochain_val_apply, map_add, LinearMap.add_apply, Prod.snd_add, lie_add, Prod.mk_add_mk, Prod.mk.injEq, true_and] abel lie_add x y z := by rw [← of_add] exact Equiv.congr_arg (by simp; abel) lie_self x := by rw [← of_zero, c.1.2] exact Equiv.congr_arg (by simp) leibniz_lie x y z := by rw [← of_add] refine Equiv.congr_arg ?_ simp only [twoCochain_val_apply, Equiv.symm_apply_apply, lie_lie, Prod.mk_add_mk, sub_add_cancel, Prod.mk.injEq, true_and, lie_add, lie_sub] have hc := c.2 rw [mem_twoCocycle_iff] at hc have := d₂₃_apply R L M c ((ofProd c).symm x).1 ((ofProd c).symm y).1 ((ofProd c).symm z).1 simp only [hc, LinearMap.zero_apply] at this rw [← twoCochain_skew _ _ ⁅((ofProd c).symm x).1, ((ofProd c).symm z).1⁆, ← twoCochain_skew _ _ ⁅((ofProd c).symm y).1, ((ofProd c).symm z).1⁆, eq_sub_iff_add_eq, zero_add, neg_eq_iff_eq_neg] at this rw [this] abel lemma bracket_ofTwoCocycle {c : twoCocycle R L M} (x y : ofTwoCocycle c) : letI x₁ := ((ofProd c).symm x).1; letI x₂ := ((ofProd c).symm x).2 letI y₁ := ((ofProd c).symm y).1; letI y₂ := ((ofProd c).symm y).2 ⁅x, y⁆ = ofProd c (⁅x₁, y₁⁆, (c : L →ₗ[R] L →ₗ[R] M) x₁ y₁ + ⁅x₁, y₂⁆ - ⁅y₁, x₂⁆) := rfl instance : LieAlgebra R (ofTwoCocycle c) where lie_smul r x y := by simp only [bracket_ofTwoCocycle] exact Equiv.congr_arg (by simp [← smul_add, smul_sub]) end Algebra namespace Extension open LieModule.Cohomology variable [CommRing R] [LieRing L] [LieAlgebra R L] [LieRing M] [LieAlgebra R M] [IsLieAbelian M] [LieRingModule L M] [LieModule R L M] (c : twoCocycle R L M) /-- The extension of Lie algebras defined by a 2-cocycle. -/ def ofTwoCocycle : Extension R M L where L := LieAlgebra.ofTwoCocycle c instLieRing := inferInstance instLieAlgebra := inferInstance incl := { toFun x := ofProd c (0, x) map_add' _ _ := by simp [← of_add] map_smul' _ _ := by simp [← of_smul] map_lie' {_ _} := by simp [bracket_ofTwoCocycle] } proj := { toFun x := ((ofProd c).symm x).1 map_add' _ _ := by simp map_smul' _ _ := by simp map_lie' {_ _} := by simp [bracket_ofTwoCocycle] } IsExtension := { ker_eq_bot := by rw [LieHom.ker_eq_bot] intro x y simp range_eq_top := by rw [LieHom.range_eq_top] intro x use (ofProd c (x, 0)) simp exact := by ext x constructor · intro hx obtain ⟨n, h⟩ := hx rw [← h] rfl · intro hx have : ((ofProd c).symm x).1 = 0 := hx simp only [LieHom.mem_range, LieHom.coe_mk] use ((ofProd c).symm x).2 nth_rw 2 [← Equiv.apply_symm_apply (ofProd c) x] rw [← this] } instance : LieRing (ofTwoCocycle c).L := (ofTwoCocycle c).instLieRing instance : LieAlgebra R (ofTwoCocycle c).L := (ofTwoCocycle c).instLieAlgebra /-- The Lie algebra isomorphism given by the type synonym. -/ def ofAlg : LieAlgebra.ofTwoCocycle c ≃ₗ⁅R⁆ (ofTwoCocycle c).L := LieEquiv.refl lemma bracket (x y : (ofTwoCocycle c).L) : ⁅x, y⁆ = ofAlg c ⁅(ofAlg c).symm x, (ofAlg c).symm y⁆ := rfl end Extension end LieAlgebra