source
stringlengths
17
118
lean4
stringlengths
0
335k
.lake/packages/mathlib/Mathlib/Algebra/Lie/SkewAdjoint.lean
import Mathlib.Algebra.Lie.Matrix import Mathlib.LinearAlgebra.Matrix.SesquilinearForm import Mathlib.Tactic.NoncommRing /-! # Lie algebras of skew-adjoint endomorphisms of a bilinear form When a module carries a bilinear form, the Lie algebra of endomorphisms of the module contains a distinguished Lie subalgebra: the skew-adjoint endomorphisms. Such subalgebras are important because they provide a simple, explicit construction of the so-called classical Lie algebras. This file defines the Lie subalgebra of skew-adjoint endomorphisms cut out by a bilinear form on a module and proves some basic related results. It also provides the corresponding definitions and results for the Lie algebra of square matrices. ## Main definitions * `skewAdjointLieSubalgebra` * `skewAdjointLieSubalgebraEquiv` * `skewAdjointMatricesLieSubalgebra` * `skewAdjointMatricesLieSubalgebraEquiv` ## Tags lie algebra, skew-adjoint, bilinear form -/ universe u v w w₁ section SkewAdjointEndomorphisms open LinearMap (BilinForm) variable {R : Type u} {M : Type v} [CommRing R] [AddCommGroup M] [Module R M] variable (B : BilinForm R M) theorem LinearMap.BilinForm.isSkewAdjoint_bracket {f g : Module.End R M} (hf : f ∈ B.skewAdjointSubmodule) (hg : g ∈ B.skewAdjointSubmodule) : ⁅f, g⁆ ∈ B.skewAdjointSubmodule := by rw [mem_skewAdjointSubmodule] at * have hfg : IsAdjointPair B B (f * g) (g * f) := by rw [← neg_mul_neg g f]; exact hg.comp hf have hgf : IsAdjointPair B B (g * f) (f * g) := by rw [← neg_mul_neg f g]; exact hf.comp hg change IsAdjointPair B B (f * g - g * f) (-(f * g - g * f)); rw [neg_sub] exact hfg.sub hgf /-- Given an `R`-module `M`, equipped with a bilinear form, the skew-adjoint endomorphisms form a Lie subalgebra of the Lie algebra of endomorphisms. -/ def skewAdjointLieSubalgebra : LieSubalgebra R (Module.End R M) := { B.skewAdjointSubmodule with lie_mem' := B.isSkewAdjoint_bracket } variable {N : Type w} [AddCommGroup N] [Module R N] (e : N ≃ₗ[R] M) /-- An equivalence of modules with bilinear forms gives equivalence of Lie algebras of skew-adjoint endomorphisms. -/ def skewAdjointLieSubalgebraEquiv : skewAdjointLieSubalgebra (B.compl₁₂ (e : N →ₗ[R] M) e) ≃ₗ⁅R⁆ skewAdjointLieSubalgebra B := by apply LieEquiv.ofSubalgebras _ _ e.lieConj ext f simp only [Submodule.mem_map_equiv, LieSubalgebra.mem_map_submodule] exact (LinearMap.isPairSelfAdjoint_equiv (B := -B) (F := B) e f).symm @[simp] theorem skewAdjointLieSubalgebraEquiv_apply (f : skewAdjointLieSubalgebra (B.compl₁₂ (Qₗ := N) (Qₗ' := N) ↑e ↑e)) : ↑(skewAdjointLieSubalgebraEquiv B e f) = e.lieConj f := by simp [skewAdjointLieSubalgebraEquiv] @[simp] theorem skewAdjointLieSubalgebraEquiv_symm_apply (f : skewAdjointLieSubalgebra B) : ↑((skewAdjointLieSubalgebraEquiv B e).symm f) = e.symm.lieConj f := by simp [skewAdjointLieSubalgebraEquiv] end SkewAdjointEndomorphisms section SkewAdjointMatrices open scoped Matrix variable {R : Type u} {n : Type w} [CommRing R] [DecidableEq n] [Fintype n] variable (J : Matrix n n R) theorem Matrix.lie_transpose (A B : Matrix n n R) : ⁅A, B⁆ᵀ = ⁅Bᵀ, Aᵀ⁆ := show (A * B - B * A)ᵀ = Bᵀ * Aᵀ - Aᵀ * Bᵀ by simp theorem Matrix.isSkewAdjoint_bracket {A B : Matrix n n R} (hA : A ∈ skewAdjointMatricesSubmodule J) (hB : B ∈ skewAdjointMatricesSubmodule J) : ⁅A, B⁆ ∈ skewAdjointMatricesSubmodule J := by simp only [mem_skewAdjointMatricesSubmodule] at * change ⁅A, B⁆ᵀ * J = J * (-⁅A, B⁆) change Aᵀ * J = J * (-A) at hA change Bᵀ * J = J * (-B) at hB rw [Matrix.lie_transpose, LieRing.of_associative_ring_bracket, LieRing.of_associative_ring_bracket, sub_mul, mul_assoc, mul_assoc, hA, hB, ← mul_assoc, ← mul_assoc, hA, hB] noncomm_ring /-- The Lie subalgebra of skew-adjoint square matrices corresponding to a square matrix `J`. -/ def skewAdjointMatricesLieSubalgebra : LieSubalgebra R (Matrix n n R) := { skewAdjointMatricesSubmodule J with lie_mem' := J.isSkewAdjoint_bracket } @[simp] theorem mem_skewAdjointMatricesLieSubalgebra (A : Matrix n n R) : A ∈ skewAdjointMatricesLieSubalgebra J ↔ A ∈ skewAdjointMatricesSubmodule J := Iff.rfl /-- An invertible matrix `P` gives a Lie algebra equivalence between those endomorphisms that are skew-adjoint with respect to a square matrix `J` and those with respect to `PᵀJP`. -/ def skewAdjointMatricesLieSubalgebraEquiv (P : Matrix n n R) (h : Invertible P) : skewAdjointMatricesLieSubalgebra J ≃ₗ⁅R⁆ skewAdjointMatricesLieSubalgebra (Pᵀ * J * P) := LieEquiv.ofSubalgebras _ _ (P.lieConj h).symm <| by ext A suffices P.lieConj h A ∈ skewAdjointMatricesSubmodule J ↔ A ∈ skewAdjointMatricesSubmodule (Pᵀ * J * P) by simp only [Submodule.mem_map_equiv, LieSubalgebra.mem_map_submodule] exact this simp [Matrix.IsSkewAdjoint, J.isAdjointPair_equiv _ _ P (isUnit_of_invertible P)] theorem skewAdjointMatricesLieSubalgebraEquiv_apply (P : Matrix n n R) (h : Invertible P) (A : skewAdjointMatricesLieSubalgebra J) : ↑(skewAdjointMatricesLieSubalgebraEquiv J P h A) = P⁻¹ * A * P := by simp [skewAdjointMatricesLieSubalgebraEquiv] /-- An equivalence of matrix algebras commuting with the transpose endomorphisms restricts to an equivalence of Lie algebras of skew-adjoint matrices. -/ def skewAdjointMatricesLieSubalgebraEquivTranspose {m : Type w} [DecidableEq m] [Fintype m] (e : Matrix n n R ≃ₐ[R] Matrix m m R) (h : ∀ A, (e A)ᵀ = e Aᵀ) : skewAdjointMatricesLieSubalgebra J ≃ₗ⁅R⁆ skewAdjointMatricesLieSubalgebra (e J) := LieEquiv.ofSubalgebras _ _ e.toLieEquiv <| by ext A suffices J.IsSkewAdjoint (e.symm A) ↔ (e J).IsSkewAdjoint A by simpa [- LieSubalgebra.mem_map, LieSubalgebra.mem_map_submodule] simp only [Matrix.IsSkewAdjoint, Matrix.IsAdjointPair, ← h, ← Function.Injective.eq_iff e.injective, map_mul, AlgEquiv.apply_symm_apply, map_neg] @[simp] theorem skewAdjointMatricesLieSubalgebraEquivTranspose_apply {m : Type w} [DecidableEq m] [Fintype m] (e : Matrix n n R ≃ₐ[R] Matrix m m R) (h : ∀ A, (e A)ᵀ = e Aᵀ) (A : skewAdjointMatricesLieSubalgebra J) : (skewAdjointMatricesLieSubalgebraEquivTranspose J e h A : Matrix m m R) = e A := rfl theorem mem_skewAdjointMatricesLieSubalgebra_unit_smul (u : Rˣ) (J A : Matrix n n R) : A ∈ skewAdjointMatricesLieSubalgebra (u • J) ↔ A ∈ skewAdjointMatricesLieSubalgebra J := by change A ∈ skewAdjointMatricesSubmodule (u • J) ↔ A ∈ skewAdjointMatricesSubmodule J simp only [mem_skewAdjointMatricesSubmodule, Matrix.IsSkewAdjoint, Matrix.IsAdjointPair] constructor <;> intro h · simpa using congr_arg (fun B => u⁻¹ • B) h · simp [h] end SkewAdjointMatrices
.lake/packages/mathlib/Mathlib/Algebra/Lie/Basic.lean
import Mathlib.Algebra.Module.Submodule.Equiv import Mathlib.Algebra.Module.Equiv.Basic import Mathlib.Algebra.Module.Rat import Mathlib.Data.Bracket import Mathlib.Tactic.Abel /-! # Lie algebras This file defines Lie rings and Lie algebras over a commutative ring together with their modules, morphisms and equivalences, as well as various lemmas to make these definitions usable. ## Main definitions * `LieRing` * `LieAlgebra` * `LieRingModule` * `LieModule` * `LieHom` * `LieEquiv` * `LieModuleHom` * `LieModuleEquiv` ## Notation Working over a fixed commutative ring `R`, we introduce the notations: * `L →ₗ⁅R⁆ L'` for a morphism of Lie algebras, * `L ≃ₗ⁅R⁆ L'` for an equivalence of Lie algebras, * `M →ₗ⁅R,L⁆ N` for a morphism of Lie algebra modules `M`, `N` over a Lie algebra `L`, * `M ≃ₗ⁅R,L⁆ N` for an equivalence of Lie algebra modules `M`, `N` over a Lie algebra `L`. ## Implementation notes Lie algebras are defined as modules with a compatible Lie ring structure and thus, like modules, are partially unbundled. ## References * [N. Bourbaki, *Lie Groups and Lie Algebras, Chapters 1--3*](bourbaki1975) ## Tags lie bracket, jacobi identity, lie ring, lie algebra, lie module -/ universe u v w w₁ w₂ open Function /-- A Lie ring is an additive group with compatible product, known as the bracket, satisfying the Jacobi identity. -/ class LieRing (L : Type v) extends AddCommGroup L, Bracket L L where /-- A Lie ring bracket is additive in its first component. -/ protected add_lie : ∀ x y z : L, ⁅x + y, z⁆ = ⁅x, z⁆ + ⁅y, z⁆ /-- A Lie ring bracket is additive in its second component. -/ protected lie_add : ∀ x y z : L, ⁅x, y + z⁆ = ⁅x, y⁆ + ⁅x, z⁆ /-- A Lie ring bracket vanishes on the diagonal in L × L. -/ protected lie_self : ∀ x : L, ⁅x, x⁆ = 0 /-- A Lie ring bracket satisfies a Leibniz / Jacobi identity. -/ protected leibniz_lie : ∀ x y z : L, ⁅x, ⁅y, z⁆⁆ = ⁅⁅x, y⁆, z⁆ + ⁅y, ⁅x, z⁆⁆ /-- A Lie algebra is a module with compatible product, known as the bracket, satisfying the Jacobi identity. Forgetting the scalar multiplication, every Lie algebra is a Lie ring. -/ @[ext] class LieAlgebra (R : Type u) (L : Type v) [CommRing R] [LieRing L] extends Module R L where /-- A Lie algebra bracket is compatible with scalar multiplication in its second argument. The compatibility in the first argument is not a class property, but follows since every Lie algebra has a natural Lie module action on itself, see `LieModule`. -/ protected lie_smul : ∀ (t : R) (x y : L), ⁅x, t • y⁆ = t • ⁅x, y⁆ /-- A Lie ring module is an additive group, together with an additive action of a Lie ring on this group, such that the Lie bracket acts as the commutator of endomorphisms. (For representations of Lie *algebras* see `LieModule`.) -/ class LieRingModule (L : Type v) (M : Type w) [LieRing L] [AddCommGroup M] extends Bracket L M where /-- A Lie ring module bracket is additive in its first component. -/ protected add_lie : ∀ (x y : L) (m : M), ⁅x + y, m⁆ = ⁅x, m⁆ + ⁅y, m⁆ /-- A Lie ring module bracket is additive in its second component. -/ protected lie_add : ∀ (x : L) (m n : M), ⁅x, m + n⁆ = ⁅x, m⁆ + ⁅x, n⁆ /-- A Lie ring module bracket satisfies a Leibniz / Jacobi identity. -/ protected leibniz_lie : ∀ (x y : L) (m : M), ⁅x, ⁅y, m⁆⁆ = ⁅⁅x, y⁆, m⁆ + ⁅y, ⁅x, m⁆⁆ /-- A Lie module is a module over a commutative ring, together with a linear action of a Lie algebra on this module, such that the Lie bracket acts as the commutator of endomorphisms. -/ class LieModule (R : Type u) (L : Type v) (M : Type w) [CommRing R] [LieRing L] [LieAlgebra R L] [AddCommGroup M] [Module R M] [LieRingModule L M] : Prop where /-- A Lie module bracket is compatible with scalar multiplication in its first argument. -/ protected smul_lie : ∀ (t : R) (x : L) (m : M), ⁅t • x, m⁆ = t • ⁅x, m⁆ /-- A Lie module bracket is compatible with scalar multiplication in its second argument. -/ protected lie_smul : ∀ (t : R) (x : L) (m : M), ⁅x, t • m⁆ = t • ⁅x, m⁆ /-- A tower of Lie bracket actions encapsulates the Leibniz rule for Lie bracket actions. More precisely, it does so in a relative setting: Let `L₁` and `L₂` be two types with Lie bracket actions on a type `M` endowed with an addition, and additionally assume a Lie bracket action of `L₁` on `L₂`. Then the Leibniz rule asserts for all `x : L₁`, `y : L₂`, and `m : M` that `⁅x, ⁅y, m⁆⁆ = ⁅⁅x, y⁆, m⁆ + ⁅y, ⁅x, m⁆⁆` holds. Common examples include the case where `L₁` is a Lie subalgebra of `L₂` and the case where `L₂` is a Lie ideal of `L₁`. -/ class IsLieTower (L₁ L₂ M : Type*) [Bracket L₁ L₂] [Bracket L₁ M] [Bracket L₂ M] [Add M] where protected leibniz_lie (x : L₁) (y : L₂) (m : M) : ⁅x, ⁅y, m⁆⁆ = ⁅⁅x, y⁆, m⁆ + ⁅y, ⁅x, m⁆⁆ section IsLieTower variable {L₁ L₂ M : Type*} [Bracket L₁ L₂] [Bracket L₁ M] [Bracket L₂ M] lemma leibniz_lie [Add M] [IsLieTower L₁ L₂ M] (x : L₁) (y : L₂) (m : M) : ⁅x, ⁅y, m⁆⁆ = ⁅⁅x, y⁆, m⁆ + ⁅y, ⁅x, m⁆⁆ := IsLieTower.leibniz_lie x y m lemma lie_swap_lie [Bracket L₂ L₁] [AddCommGroup M] [IsLieTower L₁ L₂ M] [IsLieTower L₂ L₁ M] (x : L₁) (y : L₂) (m : M) : ⁅⁅x, y⁆, m⁆ = -⁅⁅y, x⁆, m⁆ := by have h1 := leibniz_lie x y m have h2 := leibniz_lie y x m convert congr($h1.symm - $h2) using 1 <;> simp only [add_sub_cancel_right, sub_add_cancel_right] end IsLieTower section BasicProperties theorem LieAlgebra.toModule_injective (L : Type*) [LieRing L] : Function.Injective (@LieAlgebra.toModule _ _ _ _ : LieAlgebra ℚ L → Module ℚ L) := by rintro ⟨h₁⟩ ⟨h₂⟩ heq congr instance (L : Type*) [LieRing L] : Subsingleton (LieAlgebra ℚ L) := LieAlgebra.toModule_injective L |>.subsingleton 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] variable (t : R) (x y z : L) (m n : M) @[simp] theorem add_lie : ⁅x + y, m⁆ = ⁅x, m⁆ + ⁅y, m⁆ := LieRingModule.add_lie x y m @[simp] theorem lie_add : ⁅x, m + n⁆ = ⁅x, m⁆ + ⁅x, n⁆ := LieRingModule.lie_add x m n @[simp] theorem smul_lie : ⁅t • x, m⁆ = t • ⁅x, m⁆ := LieModule.smul_lie t x m @[simp] theorem lie_smul : ⁅x, t • m⁆ = t • ⁅x, m⁆ := LieModule.lie_smul t x m instance : IsLieTower L L M where leibniz_lie x y m := LieRingModule.leibniz_lie x y m @[simp] theorem lie_zero : ⁅x, 0⁆ = (0 : M) := (AddMonoidHom.mk' _ (lie_add x)).map_zero @[simp] theorem zero_lie : ⁅(0 : L), m⁆ = 0 := (AddMonoidHom.mk' (fun x : L => ⁅x, m⁆) fun x y => add_lie x y m).map_zero @[simp] theorem lie_self : ⁅x, x⁆ = 0 := LieRing.lie_self x instance lieRingSelfModule : LieRingModule L L := { (inferInstance : LieRing L) with } @[simp] theorem lie_skew : -⁅y, x⁆ = ⁅x, y⁆ := by have h : ⁅x + y, x⁆ + ⁅x + y, y⁆ = 0 := by rw [← lie_add]; apply lie_self simpa [neg_eq_iff_add_eq_zero] using h /-- Every Lie algebra is a module over itself. -/ instance lieAlgebraSelfModule : LieModule R L L where smul_lie t x m := by rw [← lie_skew, ← lie_skew x m, LieAlgebra.lie_smul, smul_neg] lie_smul := by apply LieAlgebra.lie_smul @[simp] theorem neg_lie : ⁅-x, m⁆ = -⁅x, m⁆ := by rw [← sub_eq_zero, sub_neg_eq_add, ← add_lie] simp @[simp] theorem lie_neg : ⁅x, -m⁆ = -⁅x, m⁆ := by rw [← sub_eq_zero, sub_neg_eq_add, ← lie_add] simp @[simp] theorem sub_lie : ⁅x - y, m⁆ = ⁅x, m⁆ - ⁅y, m⁆ := by simp [sub_eq_add_neg] @[simp] theorem lie_sub : ⁅x, m - n⁆ = ⁅x, m⁆ - ⁅x, n⁆ := by simp [sub_eq_add_neg] @[simp] theorem nsmul_lie (n : ℕ) : ⁅n • x, m⁆ = n • ⁅x, m⁆ := AddMonoidHom.map_nsmul { toFun := fun x : L => ⁅x, m⁆, map_zero' := zero_lie m, map_add' := fun _ _ => add_lie _ _ _ } _ _ @[simp] theorem lie_nsmul (n : ℕ) : ⁅x, n • m⁆ = n • ⁅x, m⁆ := AddMonoidHom.map_nsmul { toFun := fun m : M => ⁅x, m⁆, map_zero' := lie_zero x, map_add' := fun _ _ => lie_add _ _ _} _ _ theorem zsmul_lie (a : ℤ) : ⁅a • x, m⁆ = a • ⁅x, m⁆ := AddMonoidHom.map_zsmul { toFun := fun x : L => ⁅x, m⁆, map_zero' := zero_lie m, map_add' := fun _ _ => add_lie _ _ _ } _ _ theorem lie_zsmul (a : ℤ) : ⁅x, a • m⁆ = a • ⁅x, m⁆ := AddMonoidHom.map_zsmul { toFun := fun m : M => ⁅x, m⁆, map_zero' := lie_zero x, map_add' := fun _ _ => lie_add _ _ _ } _ _ @[simp] lemma lie_lie : ⁅⁅x, y⁆, m⁆ = ⁅x, ⁅y, m⁆⁆ - ⁅y, ⁅x, m⁆⁆ := by rw [leibniz_lie, add_sub_cancel_right] theorem lie_jacobi : ⁅x, ⁅y, z⁆⁆ + ⁅y, ⁅z, x⁆⁆ + ⁅z, ⁅x, y⁆⁆ = 0 := by rw [← neg_neg ⁅x, y⁆, lie_neg z, lie_skew y x, ← lie_skew, lie_lie] abel variable (L M) in /-- The Lie bracket as a biadditive map. Usually one will have coefficients and `LieModule.toEnd` will be more useful. -/ @[simps] def LieRingModule.toEnd : L →+ M →+ M where toFun x := ⟨⟨fun m ↦ ⁅x, m⁆, lie_zero x⟩, LieRingModule.lie_add x⟩ map_zero' := by ext n; exact zero_lie n map_add' y z := by ext n; exact add_lie y z n instance LieRing.instLieAlgebra : LieAlgebra ℤ L where lie_smul n x y := lie_zsmul x y n instance : LieModule ℤ L M where smul_lie n x m := zsmul_lie x m n lie_smul n x m := lie_zsmul x m n instance LinearMap.instLieRingModule : LieRingModule L (M →ₗ[R] N) where bracket x f := { toFun := fun m => ⁅x, f m⁆ - f ⁅x, m⁆ map_add' := fun m n => by simp only [lie_add, LinearMap.map_add] abel map_smul' := fun t m => by simp only [smul_sub, LinearMap.map_smul, lie_smul, RingHom.id_apply] } add_lie x y f := by ext n simp only [add_lie, LinearMap.coe_mk, AddHom.coe_mk, LinearMap.add_apply, LinearMap.map_add] abel lie_add x f g := by ext n simp only [LinearMap.coe_mk, AddHom.coe_mk, lie_add, LinearMap.add_apply] abel leibniz_lie x y f := by ext n simp only [lie_lie, LinearMap.coe_mk, AddHom.coe_mk, LinearMap.map_sub, LinearMap.add_apply, lie_sub] abel @[simp] theorem LieHom.lie_apply (f : M →ₗ[R] N) (x : L) (m : M) : ⁅x, f⁆ m = ⁅x, f m⁆ - f ⁅x, m⁆ := rfl instance LinearMap.instLieModule : LieModule R L (M →ₗ[R] N) where smul_lie t x f := by ext n simp only [smul_sub, smul_lie, LinearMap.smul_apply, LieHom.lie_apply, LinearMap.map_smul] lie_smul t x f := by ext n simp only [smul_sub, LinearMap.smul_apply, LieHom.lie_apply, lie_smul] /-- We could avoid defining this by instead defining a `LieRingModule L R` instance with a zero bracket and relying on `LinearMap.instLieRingModule`. We do not do this because in the case that `L = R` we would have a non-defeq diamond via `Ring.instBracket`. -/ instance Module.Dual.instLieRingModule : LieRingModule L (M →ₗ[R] R) where bracket := fun x f ↦ { toFun := fun m ↦ - f ⁅x, m⁆ map_add' := by simp [-neg_add_rev, neg_add] map_smul' := by simp } add_lie := fun x y m ↦ by ext n; simp [-neg_add_rev, neg_add] lie_add := fun x m n ↦ by ext p; simp [-neg_add_rev, neg_add] leibniz_lie := fun x m n ↦ by ext p; simp @[simp] lemma Module.Dual.lie_apply (f : M →ₗ[R] R) : ⁅x, f⁆ m = - f ⁅x, m⁆ := rfl instance Module.Dual.instLieModule : LieModule R L (M →ₗ[R] R) where smul_lie := fun t x m ↦ by ext n; simp lie_smul := fun t x m ↦ by ext n; simp variable (L) in /-- It is sometimes useful to regard a `LieRing` as a `NonUnitalNonAssocRing`. -/ def LieRing.toNonUnitalNonAssocRing : NonUnitalNonAssocRing L := { mul := Bracket.bracket left_distrib := lie_add right_distrib := add_lie zero_mul := zero_lie mul_zero := lie_zero } variable {ι κ : Type*} theorem sum_lie (s : Finset ι) (f : ι → L) (m : M) : ⁅∑ i ∈ s, f i, m⁆ = ∑ i ∈ s, ⁅f i, m⁆ := map_sum ((LieRingModule.toEnd L M).flip m) f s theorem lie_sum (s : Finset ι) (f : ι → M) (a : L) : ⁅a, ∑ i ∈ s, f i⁆ = ∑ i ∈ s, ⁅a, f i⁆ := map_sum (LieRingModule.toEnd L M a) f s theorem sum_lie_sum {κ : Type*} (s : Finset ι) (t : Finset κ) (f : ι → L) (g : κ → M) : ⁅(∑ i ∈ s, f i), ∑ j ∈ t, g j⁆ = ∑ i ∈ s, ∑ j ∈ t, ⁅f i, g j⁆ := by simp_rw [sum_lie, lie_sum] end BasicProperties /-- A morphism of Lie algebras (denoted as `L₁ →ₗ⁅R⁆ L₂`) is a linear map respecting the bracket operations. -/ structure LieHom (R L L' : Type*) [CommRing R] [LieRing L] [LieAlgebra R L] [LieRing L'] [LieAlgebra R L'] extends L →ₗ[R] L' where /-- A morphism of Lie algebras is compatible with brackets. -/ map_lie' : ∀ {x y : L}, toFun ⁅x, y⁆ = ⁅toFun x, toFun y⁆ @[inherit_doc] notation:25 L " →ₗ⁅" R:25 "⁆ " L':0 => LieHom R L L' namespace LieHom variable {R : Type u} {L₁ : Type v} {L₂ : Type w} {L₃ : Type w₁} variable [CommRing R] variable [LieRing L₁] [LieAlgebra R L₁] variable [LieRing L₂] [LieAlgebra R L₂] variable [LieRing L₃] [LieAlgebra R L₃] attribute [coe] LieHom.toLinearMap instance : Coe (L₁ →ₗ⁅R⁆ L₂) (L₁ →ₗ[R] L₂) := ⟨LieHom.toLinearMap⟩ instance : FunLike (L₁ →ₗ⁅R⁆ L₂) L₁ L₂ where coe f := f.toFun coe_injective' x y h := by cases x; cases y; simp at h; simp [h] initialize_simps_projections LieHom (toFun → apply) @[simp, norm_cast] theorem coe_toLinearMap (f : L₁ →ₗ⁅R⁆ L₂) : ⇑(f : L₁ →ₗ[R] L₂) = f := rfl @[simp] theorem toFun_eq_coe (f : L₁ →ₗ⁅R⁆ L₂) : f.toFun = ⇑f := rfl instance : LinearMapClass (L₁ →ₗ⁅R⁆ L₂) R L₁ L₂ where map_add _ _ _ := by rw [← coe_toLinearMap, map_add] map_smulₛₗ _ _ _ := by rw [← coe_toLinearMap, map_smulₛₗ] @[deprecated (since := "2025-10-12")] alias map_smul := _root_.map_smul @[deprecated (since := "2025-10-12")] alias map_add := _root_.map_add @[deprecated (since := "2025-10-12")] alias map_sub := _root_.map_sub @[deprecated (since := "2025-10-12")] alias map_neg := _root_.map_neg @[deprecated (since := "2025-10-12")] alias map_zero := _root_.map_zero @[simp] theorem map_lie (f : L₁ →ₗ⁅R⁆ L₂) (x y : L₁) : f ⁅x, y⁆ = ⁅f x, f y⁆ := LieHom.map_lie' f /-- The identity map is a morphism of Lie algebras. -/ def id : L₁ →ₗ⁅R⁆ L₁ := { (LinearMap.id : L₁ →ₗ[R] L₁) with map_lie' := rfl } @[simp, norm_cast] theorem coe_id : ⇑(id : L₁ →ₗ⁅R⁆ L₁) = _root_.id := rfl theorem id_apply (x : L₁) : (id : L₁ →ₗ⁅R⁆ L₁) x = x := rfl /-- The constant 0 map is a Lie algebra morphism. -/ instance : Zero (L₁ →ₗ⁅R⁆ L₂) := ⟨{ (0 : L₁ →ₗ[R] L₂) with map_lie' := by simp }⟩ @[norm_cast, simp] theorem coe_zero : ((0 : L₁ →ₗ⁅R⁆ L₂) : L₁ → L₂) = 0 := rfl theorem zero_apply (x : L₁) : (0 : L₁ →ₗ⁅R⁆ L₂) x = 0 := rfl /-- The identity map is a Lie algebra morphism. -/ instance : One (L₁ →ₗ⁅R⁆ L₁) := ⟨id⟩ @[simp] theorem coe_one : ((1 : L₁ →ₗ⁅R⁆ L₁) : L₁ → L₁) = _root_.id := rfl theorem one_apply (x : L₁) : (1 : L₁ →ₗ⁅R⁆ L₁) x = x := rfl instance : Inhabited (L₁ →ₗ⁅R⁆ L₂) := ⟨0⟩ theorem coe_injective : @Function.Injective (L₁ →ₗ⁅R⁆ L₂) (L₁ → L₂) (↑) := by rintro ⟨⟨⟨f, _⟩, _⟩, _⟩ ⟨⟨⟨g, _⟩, _⟩, _⟩ h congr @[ext] theorem ext {f g : L₁ →ₗ⁅R⁆ L₂} (h : ∀ x, f x = g x) : f = g := coe_injective <| funext h theorem congr_fun {f g : L₁ →ₗ⁅R⁆ L₂} (h : f = g) (x : L₁) : f x = g x := h ▸ rfl @[simp] theorem mk_coe (f : L₁ →ₗ⁅R⁆ L₂) (h₁ h₂ h₃) : (⟨⟨⟨f, h₁⟩, h₂⟩, h₃⟩ : L₁ →ₗ⁅R⁆ L₂) = f := by ext rfl @[simp] theorem coe_mk (f : L₁ → L₂) (h₁ h₂ h₃) : ((⟨⟨⟨f, h₁⟩, h₂⟩, h₃⟩ : L₁ →ₗ⁅R⁆ L₂) : L₁ → L₂) = f := rfl /-- The composition of morphisms is a morphism. -/ def comp (f : L₂ →ₗ⁅R⁆ L₃) (g : L₁ →ₗ⁅R⁆ L₂) : L₁ →ₗ⁅R⁆ L₃ := { LinearMap.comp f.toLinearMap g.toLinearMap with map_lie' := by simp } theorem comp_apply (f : L₂ →ₗ⁅R⁆ L₃) (g : L₁ →ₗ⁅R⁆ L₂) (x : L₁) : f.comp g x = f (g x) := rfl @[norm_cast, simp] theorem coe_comp (f : L₂ →ₗ⁅R⁆ L₃) (g : L₁ →ₗ⁅R⁆ L₂) : (f.comp g : L₁ → L₃) = f ∘ g := rfl @[norm_cast, simp] theorem toLinearMap_comp (f : L₂ →ₗ⁅R⁆ L₃) (g : L₁ →ₗ⁅R⁆ L₂) : (f.comp g : L₁ →ₗ[R] L₃) = (f : L₂ →ₗ[R] L₃).comp (g : L₁ →ₗ[R] L₂) := rfl @[simp] theorem comp_id (f : L₁ →ₗ⁅R⁆ L₂) : f.comp (id : L₁ →ₗ⁅R⁆ L₁) = f := rfl @[simp] theorem id_comp (f : L₁ →ₗ⁅R⁆ L₂) : (id : L₂ →ₗ⁅R⁆ L₂).comp f = f := rfl /-- The inverse of a bijective morphism is a morphism. -/ def inverse (f : L₁ →ₗ⁅R⁆ L₂) (g : L₂ → L₁) (h₁ : Function.LeftInverse g f) (h₂ : Function.RightInverse g f) : L₂ →ₗ⁅R⁆ L₁ := { LinearMap.inverse f.toLinearMap g h₁ h₂ with map_lie' := by intro x y calc g ⁅x, y⁆ = g ⁅f (g x), f (g y)⁆ := by conv_lhs => rw [← h₂ x, ← h₂ y] _ = g (f ⁅g x, g y⁆) := by rw [map_lie] _ = ⁅g x, g y⁆ := h₁ _ } end LieHom section ModulePullBack variable {R : Type u} {L₁ : Type v} {L₂ : Type w} (M : Type w₁) variable [CommRing R] [LieRing L₁] [LieAlgebra R L₁] [LieRing L₂] [LieAlgebra R L₂] variable [AddCommGroup M] [LieRingModule L₂ M] variable (f : L₁ →ₗ⁅R⁆ L₂) /-- A Lie ring module may be pulled back along a morphism of Lie algebras. See note [reducible non-instances]. -/ def LieRingModule.compLieHom : LieRingModule L₁ M where bracket x m := ⁅f x, m⁆ lie_add x := lie_add (f x) add_lie x y m := by simp only [map_add, add_lie] leibniz_lie x y m := by simp only [lie_lie, sub_add_cancel, LieHom.map_lie] theorem LieRingModule.compLieHom_apply (x : L₁) (m : M) : haveI := LieRingModule.compLieHom M f ⁅x, m⁆ = ⁅f x, m⁆ := rfl /-- A Lie module may be pulled back along a morphism of Lie algebras. -/ theorem LieModule.compLieHom [Module R M] [LieModule R L₂ M] : @LieModule R L₁ M _ _ _ _ _ (LieRingModule.compLieHom M f) := { __ := LieRingModule.compLieHom M f smul_lie := fun t x m => by simp only [LieRingModule.compLieHom_apply, smul_lie, map_smul] lie_smul := fun t x m => by simp only [LieRingModule.compLieHom_apply, lie_smul] } end ModulePullBack /-- An equivalence of Lie algebras (denoted as `L₁ ≃ₗ⁅R⁆ L₂`) is a morphism which is also a linear equivalence. We could instead define an equivalence to be a morphism which is also a (plain) equivalence. However, it is more convenient to define via linear equivalence to get `.toLinearEquiv` for free. -/ structure LieEquiv (R : Type u) (L : Type v) (L' : Type w) [CommRing R] [LieRing L] [LieAlgebra R L] [LieRing L'] [LieAlgebra R L'] extends L →ₗ⁅R⁆ L' where /-- The inverse function of an equivalence of Lie algebras -/ invFun : L' → L /-- The inverse function of an equivalence of Lie algebras is a left inverse of the underlying function. -/ left_inv : Function.LeftInverse invFun toLieHom.toFun := by intro; first | rfl | ext <;> rfl /-- The inverse function of an equivalence of Lie algebras is a right inverse of the underlying function. -/ right_inv : Function.RightInverse invFun toLieHom.toFun := by intro; first | rfl | ext <;> rfl @[inherit_doc] notation:50 L " ≃ₗ⁅" R "⁆ " L' => LieEquiv R L L' namespace LieEquiv variable {R : Type u} {L₁ : Type v} {L₂ : Type w} {L₃ : Type w₁} variable [CommRing R] [LieRing L₁] [LieRing L₂] [LieRing L₃] variable [LieAlgebra R L₁] [LieAlgebra R L₂] [LieAlgebra R L₃] /-- Consider an equivalence of Lie algebras as a linear equivalence. -/ def toLinearEquiv (f : L₁ ≃ₗ⁅R⁆ L₂) : L₁ ≃ₗ[R] L₂ := { f.toLieHom, f with } instance hasCoeToLieHom : Coe (L₁ ≃ₗ⁅R⁆ L₂) (L₁ →ₗ⁅R⁆ L₂) := ⟨toLieHom⟩ instance hasCoeToLinearEquiv : Coe (L₁ ≃ₗ⁅R⁆ L₂) (L₁ ≃ₗ[R] L₂) := ⟨toLinearEquiv⟩ instance : EquivLike (L₁ ≃ₗ⁅R⁆ L₂) L₁ L₂ 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 cases f; cases g; simp at h₁ h₂; simp [*] theorem coe_toLieHom (e : L₁ ≃ₗ⁅R⁆ L₂) : ⇑(e : L₁ →ₗ⁅R⁆ L₂) = e := rfl @[simp] theorem coe_toLinearEquiv (e : L₁ ≃ₗ⁅R⁆ L₂) : ⇑(e : L₁ ≃ₗ[R] L₂) = e := rfl @[simp] theorem coe_coe (e : L₁ ≃ₗ⁅R⁆ L₂) : ⇑e.toLieHom = e := rfl @[simp] theorem toLinearEquiv_mk (f : L₁ →ₗ⁅R⁆ L₂) (g h₁ h₂) : (mk f g h₁ h₂ : L₁ ≃ₗ[R] L₂) = { f with invFun := g left_inv := h₁ right_inv := h₂ } := rfl theorem toLinearEquiv_injective : Injective ((↑) : (L₁ ≃ₗ⁅R⁆ L₂) → L₁ ≃ₗ[R] L₂) := by rintro ⟨⟨⟨⟨f, -⟩, -⟩, -⟩, f_inv⟩ ⟨⟨⟨⟨g, -⟩, -⟩, -⟩, g_inv⟩ simp theorem coe_injective : @Injective (L₁ ≃ₗ⁅R⁆ L₂) (L₁ → L₂) (↑) := LinearEquiv.coe_injective.comp toLinearEquiv_injective instance : LinearEquivClass (L₁ ≃ₗ⁅R⁆ L₂) R L₁ L₂ where map_add _ _ _ := by rw [← coe_toLinearEquiv, map_add] map_smulₛₗ _ _ _ := by rw [← coe_toLinearEquiv, map_smul, RingHom.id_apply] @[ext] theorem ext {f g : L₁ ≃ₗ⁅R⁆ L₂} (h : ∀ x, f x = g x) : f = g := coe_injective <| funext h instance : One (L₁ ≃ₗ⁅R⁆ L₁) := ⟨{ (1 : L₁ ≃ₗ[R] L₁) with map_lie' := rfl }⟩ @[simp] theorem one_apply (x : L₁) : (1 : L₁ ≃ₗ⁅R⁆ L₁) x = x := rfl instance : Inhabited (L₁ ≃ₗ⁅R⁆ L₁) := ⟨1⟩ lemma map_lie (e : L₁ ≃ₗ⁅R⁆ L₂) (x y : L₁) : e ⁅x, y⁆ = ⁅e x, e y⁆ := LieHom.map_lie e.toLieHom x y /-- Lie algebra equivalences are reflexive. -/ def refl : L₁ ≃ₗ⁅R⁆ L₁ := 1 @[simp] theorem refl_apply (x : L₁) : (refl : L₁ ≃ₗ⁅R⁆ L₁) x = x := rfl /-- Lie algebra equivalences are symmetric. -/ @[symm] def symm (e : L₁ ≃ₗ⁅R⁆ L₂) : L₂ ≃ₗ⁅R⁆ L₁ := { LieHom.inverse e.toLieHom e.invFun e.left_inv e.right_inv, e.toLinearEquiv.symm with } @[simp] theorem symm_symm (e : L₁ ≃ₗ⁅R⁆ L₂) : e.symm.symm = e := rfl theorem symm_bijective : Function.Bijective (LieEquiv.symm : (L₁ ≃ₗ⁅R⁆ L₂) → L₂ ≃ₗ⁅R⁆ L₁) := Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩ @[simp] theorem apply_symm_apply (e : L₁ ≃ₗ⁅R⁆ L₂) : ∀ x, e (e.symm x) = x := e.toLinearEquiv.apply_symm_apply @[simp] theorem symm_apply_apply (e : L₁ ≃ₗ⁅R⁆ L₂) : ∀ x, e.symm (e x) = x := e.toLinearEquiv.symm_apply_apply @[simp] theorem refl_symm : (refl : L₁ ≃ₗ⁅R⁆ L₁).symm = refl := rfl /-- Lie algebra equivalences are transitive. -/ @[trans] def trans (e₁ : L₁ ≃ₗ⁅R⁆ L₂) (e₂ : L₂ ≃ₗ⁅R⁆ L₃) : L₁ ≃ₗ⁅R⁆ L₃ := { LieHom.comp e₂.toLieHom e₁.toLieHom, LinearEquiv.trans e₁.toLinearEquiv e₂.toLinearEquiv with } @[simp] theorem self_trans_symm (e : L₁ ≃ₗ⁅R⁆ L₂) : e.trans e.symm = refl := ext e.symm_apply_apply @[simp] theorem symm_trans_self (e : L₁ ≃ₗ⁅R⁆ L₂) : e.symm.trans e = refl := e.symm.self_trans_symm @[simp] theorem trans_apply (e₁ : L₁ ≃ₗ⁅R⁆ L₂) (e₂ : L₂ ≃ₗ⁅R⁆ L₃) (x : L₁) : (e₁.trans e₂) x = e₂ (e₁ x) := rfl @[simp] theorem symm_trans (e₁ : L₁ ≃ₗ⁅R⁆ L₂) (e₂ : L₂ ≃ₗ⁅R⁆ L₃) : (e₁.trans e₂).symm = e₂.symm.trans e₁.symm := rfl protected theorem bijective (e : L₁ ≃ₗ⁅R⁆ L₂) : Function.Bijective ((e : L₁ →ₗ⁅R⁆ L₂) : L₁ → L₂) := e.toLinearEquiv.bijective protected theorem injective (e : L₁ ≃ₗ⁅R⁆ L₂) : Function.Injective ((e : L₁ →ₗ⁅R⁆ L₂) : L₁ → L₂) := e.toLinearEquiv.injective protected theorem surjective (e : L₁ ≃ₗ⁅R⁆ L₂) : Function.Surjective ((e : L₁ →ₗ⁅R⁆ L₂) : L₁ → L₂) := e.toLinearEquiv.surjective /-- A bijective morphism of Lie algebras yields an equivalence of Lie algebras. -/ @[simps!] noncomputable def ofBijective (f : L₁ →ₗ⁅R⁆ L₂) (h : Function.Bijective f) : L₁ ≃ₗ⁅R⁆ L₂ := { LinearEquiv.ofBijective (f : L₁ →ₗ[R] L₂) h with toFun := f map_lie' := by intro x y; exact f.map_lie x y } end LieEquiv section LieModuleMorphisms variable (R : Type u) (L : Type v) (M : Type w) (N : Type w₁) (P : Type w₂) variable [CommRing R] [LieRing L] variable [AddCommGroup M] [AddCommGroup N] [AddCommGroup P] variable [Module R M] [Module R N] [Module R P] variable [LieRingModule L M] [LieRingModule L N] [LieRingModule L P] /-- A morphism of Lie algebra modules (denoted as `M →ₗ⁅R,L⁆ N`) is a linear map which commutes with the action of the Lie algebra. -/ structure LieModuleHom extends M →ₗ[R] N where /-- A module of Lie algebra modules is compatible with the action of the Lie algebra on the modules. -/ map_lie' : ∀ {x : L} {m : M}, toFun ⁅x, m⁆ = ⁅x, toFun m⁆ @[inherit_doc] notation:25 M " →ₗ⁅" R "," L:25 "⁆ " N:0 => LieModuleHom R L M N namespace LieModuleHom variable {R L M N P} attribute [coe] LieModuleHom.toLinearMap instance : CoeOut (M →ₗ⁅R,L⁆ N) (M →ₗ[R] N) := ⟨LieModuleHom.toLinearMap⟩ instance : FunLike (M →ₗ⁅R, L⁆ N) M N where coe f := f.toFun coe_injective' x y h := by cases x; cases y; simp at h; simp [h] initialize_simps_projections LieModuleHom (toFun → apply) @[simp, norm_cast] theorem coe_toLinearMap (f : M →ₗ⁅R,L⁆ N) : ((f : M →ₗ[R] N) : M → N) = f := rfl instance : LinearMapClass (M →ₗ⁅R, L⁆ N) R M N where map_add _ _ _ := by rw [← coe_toLinearMap, map_add] map_smulₛₗ _ _ _ := by rw [← coe_toLinearMap, map_smulₛₗ] @[deprecated (since := "2025-10-12")] alias map_smul := _root_.map_smul @[deprecated (since := "2025-10-12")] alias map_add := _root_.map_add @[deprecated (since := "2025-10-12")] alias map_sub := _root_.map_sub @[deprecated (since := "2025-10-12")] alias map_neg := _root_.map_neg @[deprecated (since := "2025-10-12")] alias map_zero := _root_.map_zero @[simp] theorem map_lie (f : M →ₗ⁅R,L⁆ N) (x : L) (m : M) : f ⁅x, m⁆ = ⁅x, f m⁆ := LieModuleHom.map_lie' f variable [LieAlgebra R L] [LieModule R L N] [LieModule R L P] in theorem map_lie₂ (f : M →ₗ⁅R,L⁆ N →ₗ[R] P) (x : L) (m : M) (n : N) : ⁅x, f m n⁆ = f ⁅x, m⁆ n + f m ⁅x, n⁆ := by simp only [sub_add_cancel, map_lie, LieHom.lie_apply] /-- The identity map is a morphism of Lie modules. -/ def id : M →ₗ⁅R,L⁆ M := { (LinearMap.id : M →ₗ[R] M) with map_lie' := rfl } @[simp, norm_cast] theorem coe_id : ((id : M →ₗ⁅R,L⁆ M) : M → M) = _root_.id := rfl theorem id_apply (x : M) : (id : M →ₗ⁅R,L⁆ M) x = x := rfl /-- The constant 0 map is a Lie module morphism. -/ instance : Zero (M →ₗ⁅R,L⁆ N) := ⟨{ (0 : M →ₗ[R] N) with map_lie' := by simp }⟩ @[norm_cast, simp] theorem coe_zero : ⇑(0 : M →ₗ⁅R,L⁆ N) = 0 := rfl theorem zero_apply (m : M) : (0 : M →ₗ⁅R,L⁆ N) m = 0 := rfl /-- The identity map is a Lie module morphism. -/ instance : One (M →ₗ⁅R,L⁆ M) := ⟨id⟩ instance : Inhabited (M →ₗ⁅R,L⁆ N) := ⟨0⟩ theorem coe_injective : @Function.Injective (M →ₗ⁅R,L⁆ N) (M → N) (↑) := by rintro ⟨⟨⟨f, _⟩⟩⟩ ⟨⟨⟨g, _⟩⟩⟩ h congr @[ext] theorem ext {f g : M →ₗ⁅R,L⁆ N} (h : ∀ m, f m = g m) : f = g := coe_injective <| funext h theorem congr_fun {f g : M →ₗ⁅R,L⁆ N} (h : f = g) (x : M) : f x = g x := h ▸ rfl @[simp] theorem mk_coe (f : M →ₗ⁅R,L⁆ N) (h) : (⟨f, h⟩ : M →ₗ⁅R,L⁆ N) = f := by rfl @[simp] theorem coe_mk (f : M →ₗ[R] N) (h) : ((⟨f, h⟩ : M →ₗ⁅R,L⁆ N) : M → N) = f := by rfl @[norm_cast] theorem coe_linear_mk (f : M →ₗ[R] N) (h) : ((⟨f, h⟩ : M →ₗ⁅R,L⁆ N) : M →ₗ[R] N) = f := by rfl /-- The composition of Lie module morphisms is a morphism. -/ def comp (f : N →ₗ⁅R,L⁆ P) (g : M →ₗ⁅R,L⁆ N) : M →ₗ⁅R,L⁆ P := { LinearMap.comp f.toLinearMap g.toLinearMap with map_lie' := by simp } theorem comp_apply (f : N →ₗ⁅R,L⁆ P) (g : M →ₗ⁅R,L⁆ N) (m : M) : f.comp g m = f (g m) := rfl @[norm_cast, simp] theorem coe_comp (f : N →ₗ⁅R,L⁆ P) (g : M →ₗ⁅R,L⁆ N) : ⇑(f.comp g) = f ∘ g := rfl @[norm_cast, simp] theorem toLinearMap_comp (f : N →ₗ⁅R,L⁆ P) (g : M →ₗ⁅R,L⁆ N) : (f.comp g : M →ₗ[R] P) = (f : N →ₗ[R] P).comp (g : M →ₗ[R] N) := rfl /-- The inverse of a bijective morphism of Lie modules is a morphism of Lie modules. -/ def inverse (f : M →ₗ⁅R,L⁆ N) (g : N → M) (h₁ : Function.LeftInverse g f) (h₂ : Function.RightInverse g f) : N →ₗ⁅R,L⁆ M := { LinearMap.inverse f.toLinearMap g h₁ h₂ with map_lie' := by intro x n calc g ⁅x, n⁆ = g ⁅x, f (g n)⁆ := by rw [h₂] _ = g (f ⁅x, g n⁆) := by rw [map_lie] _ = ⁅x, g n⁆ := h₁ _ } instance : Add (M →ₗ⁅R,L⁆ N) where add f g := { (f : M →ₗ[R] N) + (g : M →ₗ[R] N) with map_lie' := by simp } instance : Sub (M →ₗ⁅R,L⁆ N) where sub f g := { (f : M →ₗ[R] N) - (g : M →ₗ[R] N) with map_lie' := by simp } instance : Neg (M →ₗ⁅R,L⁆ N) where neg f := { -(f : M →ₗ[R] N) with map_lie' := by simp } @[norm_cast, simp] theorem coe_add (f g : M →ₗ⁅R,L⁆ N) : ⇑(f + g) = f + g := rfl theorem add_apply (f g : M →ₗ⁅R,L⁆ N) (m : M) : (f + g) m = f m + g m := rfl @[norm_cast, simp] theorem coe_sub (f g : M →ₗ⁅R,L⁆ N) : ⇑(f - g) = f - g := rfl theorem sub_apply (f g : M →ₗ⁅R,L⁆ N) (m : M) : (f - g) m = f m - g m := rfl @[norm_cast, simp] theorem coe_neg (f : M →ₗ⁅R,L⁆ N) : ⇑(-f) = -f := rfl theorem neg_apply (f : M →ₗ⁅R,L⁆ N) (m : M) : (-f) m = -f m := rfl instance hasNSMul : SMul ℕ (M →ₗ⁅R,L⁆ N) where smul n f := { n • (f : M →ₗ[R] N) with map_lie' := by simp } @[norm_cast, simp] theorem coe_nsmul (n : ℕ) (f : M →ₗ⁅R,L⁆ N) : ⇑(n • f) = n • (⇑f) := rfl theorem nsmul_apply (n : ℕ) (f : M →ₗ⁅R,L⁆ N) (m : M) : (n • f) m = n • f m := rfl instance hasZSMul : SMul ℤ (M →ₗ⁅R,L⁆ N) where smul z f := { z • (f : M →ₗ[R] N) with map_lie' := by simp } @[norm_cast, simp] theorem coe_zsmul (z : ℤ) (f : M →ₗ⁅R,L⁆ N) : ⇑(z • f) = z • (⇑f) := rfl theorem zsmul_apply (z : ℤ) (f : M →ₗ⁅R,L⁆ N) (m : M) : (z • f) m = z • f m := rfl instance : AddCommGroup (M →ₗ⁅R,L⁆ N) := coe_injective.addCommGroup _ coe_zero coe_add coe_neg coe_sub (fun _ _ => coe_nsmul _ _) (fun _ _ => coe_zsmul _ _) variable [LieAlgebra R L] [LieModule R L N] instance : SMul R (M →ₗ⁅R,L⁆ N) where smul t f := { t • (f : M →ₗ[R] N) with map_lie' := by simp } @[norm_cast, simp] theorem coe_smul (t : R) (f : M →ₗ⁅R,L⁆ N) : ⇑(t • f) = t • (⇑f) := rfl theorem smul_apply (t : R) (f : M →ₗ⁅R,L⁆ N) (m : M) : (t • f) m = t • f m := rfl instance : Module R (M →ₗ⁅R,L⁆ N) := Function.Injective.module R { toFun := fun f => f.toLinearMap.toFun, map_zero' := rfl, map_add' := coe_add } coe_injective coe_smul end LieModuleHom /-- An equivalence of Lie algebra modules (denoted as `M ≃ₗ⁅R,L⁆ N`) is a linear equivalence which is also a morphism of Lie algebra modules. -/ structure LieModuleEquiv extends M →ₗ⁅R,L⁆ N where /-- The inverse function of an equivalence of Lie modules -/ invFun : N → M /-- The inverse function of an equivalence of Lie modules is a left inverse of the underlying function. -/ left_inv : Function.LeftInverse invFun toFun /-- The inverse function of an equivalence of Lie modules is a right inverse of the underlying function. -/ right_inv : Function.RightInverse invFun toFun attribute [nolint docBlame] LieModuleEquiv.toLieModuleHom @[inherit_doc] notation:25 M " ≃ₗ⁅" R "," L:25 "⁆ " N:0 => LieModuleEquiv R L M N namespace LieModuleEquiv variable {R L M N P} /-- View an equivalence of Lie modules as a linear equivalence. -/ def toLinearEquiv (e : M ≃ₗ⁅R,L⁆ N) : M ≃ₗ[R] N := { e with } /-- View an equivalence of Lie modules as a type level equivalence. -/ def toEquiv (e : M ≃ₗ⁅R,L⁆ N) : M ≃ N := { e with } instance hasCoeToEquiv : CoeOut (M ≃ₗ⁅R,L⁆ N) (M ≃ N) := ⟨toEquiv⟩ instance hasCoeToLieModuleHom : Coe (M ≃ₗ⁅R,L⁆ N) (M →ₗ⁅R,L⁆ N) := ⟨toLieModuleHom⟩ instance hasCoeToLinearEquiv : CoeOut (M ≃ₗ⁅R,L⁆ N) (M ≃ₗ[R] N) := ⟨toLinearEquiv⟩ instance : EquivLike (M ≃ₗ⁅R,L⁆ N) M N 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 cases f; cases g; simp at h₁ h₂; simp [*] @[simp] lemma coe_coe (e : M ≃ₗ⁅R,L⁆ N) : ⇑(e : M →ₗ⁅R,L⁆ N) = e := rfl theorem injective (e : M ≃ₗ⁅R,L⁆ N) : Function.Injective e := e.toEquiv.injective theorem surjective (e : M ≃ₗ⁅R,L⁆ N) : Function.Surjective e := e.toEquiv.surjective @[simp] theorem toEquiv_mk (f : M →ₗ⁅R,L⁆ N) (g : N → M) (h₁ h₂) : toEquiv (mk f g h₁ h₂ : M ≃ₗ⁅R,L⁆ N) = Equiv.mk f g h₁ h₂ := rfl @[simp] theorem coe_mk (f : M →ₗ⁅R,L⁆ N) (invFun h₁ h₂) : ((⟨f, invFun, h₁, h₂⟩ : M ≃ₗ⁅R,L⁆ N) : M → N) = f := rfl theorem coe_toLieModuleHom (e : M ≃ₗ⁅R,L⁆ N) : ⇑(e : M →ₗ⁅R,L⁆ N) = e := rfl @[simp] theorem coe_toLinearEquiv (e : M ≃ₗ⁅R,L⁆ N) : ((e : M ≃ₗ[R] N) : M → N) = e := rfl theorem toEquiv_injective : Function.Injective (toEquiv : (M ≃ₗ⁅R,L⁆ N) → M ≃ N) := by rintro ⟨⟨⟨⟨f, -⟩, -⟩, -⟩, f_inv⟩ ⟨⟨⟨⟨g, -⟩, -⟩, -⟩, g_inv⟩ simp @[ext] theorem ext (e₁ e₂ : M ≃ₗ⁅R,L⁆ N) (h : ∀ m, e₁ m = e₂ m) : e₁ = e₂ := toEquiv_injective (Equiv.ext h) instance : LinearEquivClass (M ≃ₗ⁅R,L⁆ N) R M N where map_add _ _ _ := by rw [← coe_toLinearEquiv, map_add] map_smulₛₗ _ _ _ := by rw [← coe_toLinearEquiv, map_smul, RingHom.id_apply] instance : One (M ≃ₗ⁅R,L⁆ M) := ⟨{ (1 : M ≃ₗ[R] M) with map_lie' := rfl }⟩ @[simp] theorem one_apply (m : M) : (1 : M ≃ₗ⁅R,L⁆ M) m = m := rfl instance : Inhabited (M ≃ₗ⁅R,L⁆ M) := ⟨1⟩ /-- Lie module equivalences are reflexive. -/ @[refl] def refl : M ≃ₗ⁅R,L⁆ M := 1 @[simp] theorem refl_apply (m : M) : (refl : M ≃ₗ⁅R,L⁆ M) m = m := rfl /-- Lie module equivalences are symmetric. -/ @[symm] def symm (e : M ≃ₗ⁅R,L⁆ N) : N ≃ₗ⁅R,L⁆ M := { LieModuleHom.inverse e.toLieModuleHom e.invFun e.left_inv e.right_inv, (e : M ≃ₗ[R] N).symm with } @[simp] theorem apply_symm_apply (e : M ≃ₗ⁅R,L⁆ N) : ∀ x, e (e.symm x) = x := e.toLinearEquiv.apply_symm_apply @[simp] theorem symm_apply_apply (e : M ≃ₗ⁅R,L⁆ N) : ∀ x, e.symm (e x) = x := e.toLinearEquiv.symm_apply_apply theorem apply_eq_iff_eq_symm_apply {m : M} {n : N} (e : M ≃ₗ⁅R,L⁆ N) : e m = n ↔ m = e.symm n := (e : M ≃ N).apply_eq_iff_eq_symm_apply @[simp] theorem symm_symm (e : M ≃ₗ⁅R,L⁆ N) : e.symm.symm = e := rfl theorem symm_bijective : Function.Bijective (LieModuleEquiv.symm : (M ≃ₗ⁅R,L⁆ N) → N ≃ₗ⁅R,L⁆ M) := Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩ /-- Lie module equivalences are transitive. -/ @[trans] def trans (e₁ : M ≃ₗ⁅R,L⁆ N) (e₂ : N ≃ₗ⁅R,L⁆ P) : M ≃ₗ⁅R,L⁆ P := { LieModuleHom.comp e₂.toLieModuleHom e₁.toLieModuleHom, LinearEquiv.trans e₁.toLinearEquiv e₂.toLinearEquiv with } @[simp] theorem trans_apply (e₁ : M ≃ₗ⁅R,L⁆ N) (e₂ : N ≃ₗ⁅R,L⁆ P) (m : M) : (e₁.trans e₂) m = e₂ (e₁ m) := rfl @[simp] theorem symm_trans (e₁ : M ≃ₗ⁅R,L⁆ N) (e₂ : N ≃ₗ⁅R,L⁆ P) : (e₁.trans e₂).symm = e₂.symm.trans e₁.symm := rfl @[simp] theorem self_trans_symm (e : M ≃ₗ⁅R,L⁆ N) : e.trans e.symm = refl := ext _ _ e.symm_apply_apply @[simp] theorem symm_trans_self (e : M ≃ₗ⁅R,L⁆ N) : e.symm.trans e = refl := ext _ _ e.apply_symm_apply end LieModuleEquiv end LieModuleMorphisms
.lake/packages/mathlib/Mathlib/Algebra/Lie/Quotient.lean
import Mathlib.Algebra.Lie.Ideal import Mathlib.Algebra.Lie.OfAssociative import Mathlib.LinearAlgebra.Isomorphisms import Mathlib.RingTheory.Noetherian.Basic /-! # Quotients of Lie algebras and Lie modules Given a Lie submodule of a Lie module, the quotient carries a natural Lie module structure. In the special case that the Lie module is the Lie algebra itself via the adjoint action, the submodule is a Lie ideal and the quotient carries a natural Lie algebra structure. We define these quotient structures here. A notable omission at the time of writing (February 2021) is a statement and proof of the universal property of these quotients. ## Main definitions * `LieSubmodule.Quotient.lieQuotientLieModule` * `LieSubmodule.Quotient.lieQuotientLieAlgebra` ## Tags lie algebra, quotient -/ universe u v w w₁ w₂ namespace LieSubmodule variable {R : Type u} {L : Type v} {M : Type w} variable [CommRing R] [LieRing L] [AddCommGroup M] [Module R M] variable [LieRingModule L M] variable (N N' : LieSubmodule R L M) /-- The quotient of a Lie module by a Lie submodule. It is a Lie module. -/ instance : HasQuotient M (LieSubmodule R L M) := ⟨fun N => M ⧸ N.toSubmodule⟩ namespace Quotient variable {N} instance addCommGroup : AddCommGroup (M ⧸ N) := Submodule.Quotient.addCommGroup _ instance module' {S : Type*} [Semiring S] [SMul S R] [Module S M] [IsScalarTower S R M] : Module S (M ⧸ N) := Submodule.Quotient.module' _ instance module : Module R (M ⧸ N) := Submodule.Quotient.module _ instance isCentralScalar {S : Type*} [Semiring S] [SMul S R] [Module S M] [IsScalarTower S R M] [SMul Sᵐᵒᵖ R] [Module Sᵐᵒᵖ M] [IsScalarTower Sᵐᵒᵖ R M] [IsCentralScalar S M] : IsCentralScalar S (M ⧸ N) := Submodule.Quotient.isCentralScalar _ instance inhabited : Inhabited (M ⧸ N) := ⟨0⟩ /-- Map sending an element of `M` to the corresponding element of `M/N`, when `N` is a lie_submodule of the lie_module `N`. -/ abbrev mk : M → M ⧸ N := Submodule.Quotient.mk @[simp] theorem mk_eq_zero' {m : M} : mk (N := N) m = 0 ↔ m ∈ N := Submodule.Quotient.mk_eq_zero N.toSubmodule theorem is_quotient_mk (m : M) : Quotient.mk'' m = (mk m : M ⧸ N) := rfl variable [LieAlgebra R L] [LieModule R L M] (I J : LieIdeal R L) /-- Given a Lie module `M` over a Lie algebra `L`, together with a Lie submodule `N ⊆ M`, there is a natural linear map from `L` to the endomorphisms of `M` leaving `N` invariant. -/ def lieSubmoduleInvariant : L →ₗ[R] Submodule.compatibleMaps N.toSubmodule N.toSubmodule := LinearMap.codRestrict _ (LieModule.toEnd R L M) fun _ _ => N.lie_mem variable (N) /-- Given a Lie module `M` over a Lie algebra `L`, together with a Lie submodule `N ⊆ M`, there is a natural Lie algebra morphism from `L` to the linear endomorphism of the quotient `M/N`. -/ def actionAsEndoMap : L →ₗ⁅R⁆ Module.End R (M ⧸ N) := { LinearMap.comp (Submodule.mapQLinear (N : Submodule R M) (N : Submodule R M)) lieSubmoduleInvariant with map_lie' := fun {_ _} => Submodule.linearMap_qext _ <| LinearMap.ext fun _ => congr_arg mk <| lie_lie _ _ _ } /-- Given a Lie module `M` over a Lie algebra `L`, together with a Lie submodule `N ⊆ M`, there is a natural bracket action of `L` on the quotient `M/N`. -/ instance actionAsEndoMapBracket : Bracket L (M ⧸ N) := ⟨fun x n => actionAsEndoMap N x n⟩ instance lieQuotientLieRingModule : LieRingModule L (M ⧸ N) := { LieRingModule.compLieHom _ (actionAsEndoMap N) with bracket := Bracket.bracket } /-- The quotient of a Lie module by a Lie submodule, is a Lie module. -/ instance lieQuotientLieModule : LieModule R L (M ⧸ N) := LieModule.compLieHom _ (actionAsEndoMap N) instance lieQuotientHasBracket : Bracket (L ⧸ I) (L ⧸ I) := ⟨by intro x y apply Quotient.liftOn₂' x y fun x' y' => mk ⁅x', y'⁆ intro x₁ x₂ y₁ y₂ h₁ h₂ apply (Submodule.Quotient.eq I.toSubmodule).2 rw [Submodule.quotientRel_def] at h₁ h₂ have h : ⁅x₁, x₂⁆ - ⁅y₁, y₂⁆ = ⁅x₁, x₂ - y₂⁆ + ⁅x₁ - y₁, y₂⁆ := by simp [-lie_skew, sub_eq_add_neg, add_assoc] rw [h] apply Submodule.add_mem · apply lie_mem_right R L I x₁ (x₂ - y₂) h₂ · apply lie_mem_left R L I (x₁ - y₁) y₂ h₁⟩ @[simp] theorem mk_bracket (x y : L) : mk ⁅x, y⁆ = ⁅(mk x : L ⧸ I), (mk y : L ⧸ I)⁆ := rfl instance lieQuotientLieRing : LieRing (L ⧸ I) where add_lie := by intro x' y' z'; refine Quotient.inductionOn₃' x' y' z' ?_; intro x y z repeat' first | rw [is_quotient_mk] | rw [← mk_bracket] | rw [← Submodule.Quotient.mk_add (R := R) (M := L)] apply congr_arg; apply add_lie lie_add := by intro x' y' z'; refine Quotient.inductionOn₃' x' y' z' ?_; intro x y z repeat' first | rw [is_quotient_mk] | rw [← mk_bracket] | rw [← Submodule.Quotient.mk_add (R := R) (M := L)] apply congr_arg; apply lie_add lie_self := by intro x'; refine Quotient.inductionOn' x' ?_; intro x rw [is_quotient_mk, ← mk_bracket] apply congr_arg; apply lie_self leibniz_lie := by intro x' y' z'; refine Quotient.inductionOn₃' x' y' z' ?_; intro x y z repeat' first | rw [is_quotient_mk] | rw [← mk_bracket] | rw [← Submodule.Quotient.mk_add (R := R) (M := L)] apply congr_arg; apply leibniz_lie instance lieQuotientLieAlgebra : LieAlgebra R (L ⧸ I) where lie_smul := by intro t x' y'; refine Quotient.inductionOn₂' x' y' ?_; intro x y repeat' first | rw [is_quotient_mk] | rw [← mk_bracket] | rw [← Submodule.Quotient.mk_smul (R := R) (M := L)] apply congr_arg; apply lie_smul /-- `LieSubmodule.Quotient.mk` as a `LieModuleHom`. -/ @[simps] def mk' : M →ₗ⁅R,L⁆ M ⧸ N := { N.toSubmodule.mkQ with toFun := mk map_lie' := fun {_ _} => rfl } @[simp] theorem surjective_mk' : Function.Surjective (mk' N) := Quot.mk_surjective @[simp] theorem range_mk' : LieModuleHom.range (mk' N) = ⊤ := by simp [LieModuleHom.range_eq_top] instance isNoetherian [IsNoetherian R M] : IsNoetherian R (M ⧸ N) := inferInstanceAs (IsNoetherian R (M ⧸ (N : Submodule R M))) theorem mk_eq_zero {m : M} : mk' N m = 0 ↔ m ∈ N := Submodule.Quotient.mk_eq_zero N.toSubmodule @[simp] theorem mk'_ker : (mk' N).ker = N := by ext; simp @[simp] theorem map_mk'_eq_bot_le : map (mk' N) N' = ⊥ ↔ N' ≤ N := by rw [← LieModuleHom.le_ker_iff_map, mk'_ker] /-- Two `LieModuleHom`s from a quotient lie module are equal if their compositions with `LieSubmodule.Quotient.mk'` are equal. See note [partially-applied ext lemmas]. -/ @[ext] theorem lieModuleHom_ext ⦃f g : M ⧸ N →ₗ⁅R,L⁆ M⦄ (h : f.comp (mk' N) = g.comp (mk' N)) : f = g := LieModuleHom.ext fun x => Quotient.inductionOn' x <| LieModuleHom.congr_fun h lemma toEnd_comp_mk' (x : L) : LieModule.toEnd R L (M ⧸ N) x ∘ₗ mk' N = mk' N ∘ₗ LieModule.toEnd R L M x := rfl end Quotient end LieSubmodule namespace LieHom variable {R L L' : Type*} variable [CommRing R] [LieRing L] [LieAlgebra R L] [LieRing L'] [LieAlgebra R L'] variable (f : L →ₗ⁅R⁆ L') /-- The first isomorphism theorem for morphisms of Lie algebras. -/ @[simps] noncomputable def quotKerEquivRange : (L ⧸ f.ker) ≃ₗ⁅R⁆ f.range := { (f : L →ₗ[R] L').quotKerEquivRange with toFun := (f : L →ₗ[R] L').quotKerEquivRange map_lie' := by intro x y induction x using Submodule.Quotient.induction_on induction y using Submodule.Quotient.induction_on rw [← SetLike.coe_eq_coe, LieSubalgebra.coe_bracket f.range] simp only [← LieSubmodule.Quotient.mk_bracket, LinearMap.quotKerEquivRange_apply_mk, coe_toLinearMap, map_lie] } end LieHom
.lake/packages/mathlib/Mathlib/Algebra/Lie/Ideal.lean
import Mathlib.Algebra.Lie.Submodule /-! # Lie Ideals This file defines Lie ideals, which are Lie submodules of a Lie algebra over itself. They are defined as a special case of `LieSubmodule`, and inherit much of their structure from it. We also prove some basic properties of Lie ideals, including how they behave under Lie algebra homomorphisms (`map`, `comap`) and how they relate to the lattice structure on Lie submodules. ## Main definitions * `LieIdeal` * `LieIdeal.map` * `LieIdeal.comap` ## Tags Lie algebra, ideal, submodule, Lie submodule -/ universe u v w w₁ w₂ section LieSubmodule variable (R : Type u) (L : Type v) (M : Type w) variable [CommRing R] [LieRing L] [AddCommGroup M] [Module R M] variable [LieRingModule L M] section LieIdeal variable [LieAlgebra R L] [LieModule R L M] /-- An ideal of a Lie algebra is a Lie submodule of the Lie algebra as a Lie module over itself. -/ abbrev LieIdeal := LieSubmodule R L L theorem lie_mem_right (I : LieIdeal R L) (x y : L) (h : y ∈ I) : ⁅x, y⁆ ∈ I := I.lie_mem h theorem lie_mem_left (I : LieIdeal R L) (x y : L) (h : x ∈ I) : ⁅x, y⁆ ∈ I := by rw [← lie_skew, ← neg_lie]; apply lie_mem_right; assumption /-- An ideal of a Lie algebra is a Lie subalgebra. -/ def LieIdeal.toLieSubalgebra (I : LieIdeal R L) : LieSubalgebra R L := { I.toSubmodule with lie_mem' := by intro x y _ hy; apply lie_mem_right; exact hy } instance : Coe (LieIdeal R L) (LieSubalgebra R L) := ⟨LieIdeal.toLieSubalgebra R L⟩ @[simp] theorem LieIdeal.coe_toLieSubalgebra (I : LieIdeal R L) : ((I : LieSubalgebra R L) : Set L) = I := rfl @[simp] theorem LieIdeal.toLieSubalgebra_toSubmodule (I : LieIdeal R L) : ((I : LieSubalgebra R L) : Submodule R L) = LieSubmodule.toSubmodule I := rfl /-- An ideal of `L` is a Lie subalgebra of `L`, so it is a Lie ring. -/ instance LieIdeal.lieRing (I : LieIdeal R L) : LieRing I := LieSubalgebra.lieRing R L ↑I /-- Transfer the `LieAlgebra` instance from the coercion `LieIdeal → LieSubalgebra`. -/ instance LieIdeal.lieAlgebra (I : LieIdeal R L) : LieAlgebra R I := LieSubalgebra.lieAlgebra R L ↑I /-- Transfer the `LieRingModule` instance from the coercion `LieIdeal → LieSubalgebra`. -/ instance LieIdeal.lieRingModule {R L : Type*} [CommRing R] [LieRing L] [LieAlgebra R L] (I : LieIdeal R L) [LieRingModule L M] : LieRingModule I M := LieSubalgebra.lieRingModule (I : LieSubalgebra R L) @[simp] theorem LieIdeal.coe_bracket_of_module {R L : Type*} [CommRing R] [LieRing L] [LieAlgebra R L] (I : LieIdeal R L) [LieRingModule L M] (x : I) (m : M) : ⁅x, m⁆ = ⁅(↑x : L), m⁆ := LieSubalgebra.coe_bracket_of_module (I : LieSubalgebra R L) x m /-- Transfer the `LieModule` instance from the coercion `LieIdeal → LieSubalgebra`. -/ instance LieIdeal.lieModule (I : LieIdeal R L) : LieModule R I M := LieSubalgebra.lieModule (I : LieSubalgebra R L) instance (I : LieIdeal R L) : IsLieTower I L M where leibniz_lie x y m := leibniz_lie x.val y m instance (I : LieIdeal R L) : IsLieTower L I M where leibniz_lie x y m := leibniz_lie x y.val m end LieIdeal namespace LieSubalgebra variable {L} variable [LieAlgebra R L] variable (K : LieSubalgebra R L) theorem exists_lieIdeal_coe_eq_iff : (∃ I : LieIdeal R L, ↑I = K) ↔ ∀ x y : L, y ∈ K → ⁅x, y⁆ ∈ K := by simp only [← toSubmodule_inj, LieIdeal.toLieSubalgebra_toSubmodule, Submodule.exists_lieSubmodule_coe_eq_iff L, mem_toSubmodule] theorem exists_nested_lieIdeal_coe_eq_iff {K' : LieSubalgebra R L} (h : K ≤ K') : (∃ I : LieIdeal R K', ↑I = ofLe h) ↔ ∀ x y : L, x ∈ K' → y ∈ K → ⁅x, y⁆ ∈ K := by simp only [exists_lieIdeal_coe_eq_iff, coe_bracket, mem_ofLe] constructor · intro h' x y hx hy; exact h' ⟨x, hx⟩ ⟨y, h hy⟩ hy · rintro h' ⟨x, hx⟩ ⟨y, hy⟩ hy'; exact h' x y hx hy' end LieSubalgebra end LieSubmodule section LieSubmoduleMapAndComap variable {R : Type u} {L : Type v} {L' : Type w₂} {M : Type w} {M' : Type w₁} variable [CommRing R] [LieRing L] [LieRing L'] [LieAlgebra R L'] variable [AddCommGroup M] [Module R M] [LieRingModule L M] variable [AddCommGroup M'] [Module R M'] [LieRingModule L M'] namespace LieIdeal variable [LieAlgebra R L] [LieModule R L M] [LieModule R L M'] variable (f : L →ₗ⁅R⁆ L') (I I₂ : LieIdeal R L) (J : LieIdeal R L') @[simp] theorem top_toLieSubalgebra : ((⊤ : LieIdeal R L) : LieSubalgebra R L) = ⊤ := rfl /-- A morphism of Lie algebras `f : L → L'` pushes forward Lie ideals of `L` to Lie ideals of `L'`. Note that unlike `LieSubmodule.map`, we must take the `lieSpan` of the image. Mathematically this is because although `f` makes `L'` into a Lie module over `L`, in general the `L` submodules of `L'` are not the same as the ideals of `L'`. -/ def map : LieIdeal R L' := LieSubmodule.lieSpan R L' <| (I : Submodule R L).map (f : L →ₗ[R] L') /-- A morphism of Lie algebras `f : L → L'` pulls back Lie ideals of `L'` to Lie ideals of `L`. Note that `f` makes `L'` into a Lie module over `L` (turning `f` into a morphism of Lie modules) and so this is a special case of `LieSubmodule.comap` but we do not exploit this fact. -/ def comap : LieIdeal R L := { (J : Submodule R L').comap (f : L →ₗ[R] L') with lie_mem := fun {x y} h ↦ by suffices ⁅f x, f y⁆ ∈ J by simp only [AddSubsemigroup.mem_carrier, AddSubmonoid.mem_toSubsemigroup, Submodule.mem_toAddSubmonoid, Submodule.mem_comap, LieHom.coe_toLinearMap, LieHom.map_lie, LieSubalgebra.mem_toSubmodule] exact this apply J.lie_mem h } @[simp] theorem map_toSubmodule (h : ↑(map f I) = f '' I) : LieSubmodule.toSubmodule (map f I) = (LieSubmodule.toSubmodule I).map (f : L →ₗ[R] L') := by rw [SetLike.ext'_iff, LieSubmodule.coe_toSubmodule, h, Submodule.map_coe]; rfl @[simp] theorem comap_toSubmodule : (LieSubmodule.toSubmodule (comap f J)) = (LieSubmodule.toSubmodule J).comap (f : L →ₗ[R] L') := rfl theorem map_le : map f I ≤ J ↔ f '' I ⊆ J := LieSubmodule.lieSpan_le variable {f I I₂ J} theorem mem_map {x : L} (hx : x ∈ I) : f x ∈ map f I := by apply LieSubmodule.subset_lieSpan use x exact ⟨hx, rfl⟩ @[simp] theorem mem_comap {x : L} : x ∈ comap f J ↔ f x ∈ J := Iff.rfl theorem map_le_iff_le_comap : map f I ≤ J ↔ I ≤ comap f J := by rw [map_le] exact Set.image_subset_iff variable (f) in theorem gc_map_comap : GaloisConnection (map f) (comap f) := fun _ _ ↦ map_le_iff_le_comap @[simp] theorem map_sup : (I ⊔ I₂).map f = I.map f ⊔ I₂.map f := (gc_map_comap f).l_sup theorem map_comap_le : map f (comap f J) ≤ J := by rw [map_le_iff_le_comap] /-- See also `LieIdeal.map_comap_eq`. -/ theorem comap_map_le : I ≤ comap f (map f I) := by rw [← map_le_iff_le_comap] @[mono] theorem map_mono : Monotone (map f) := fun I₁ I₂ h ↦ by unfold map gcongr; exact h @[mono] theorem comap_mono : Monotone (comap f) := fun J₁ J₂ h ↦ by rw [← SetLike.coe_subset_coe] at h ⊢ dsimp only [SetLike.coe] exact Set.preimage_mono h theorem map_of_image (h : f '' I = J) : I.map f = J := by apply le_antisymm · rw [map, LieSubmodule.lieSpan_le, Submodule.map_coe] /- I'm uncertain how to best resolve this `erw`. ``` have : (↑(toLieSubalgebra R L I).toSubmodule : Set L) = I := rfl rw [this] simp [h] ``` works, but still feels awkward. There are missing `simp` lemmas here.` -/ erw [h] · rw [← SetLike.coe_subset_coe, ← h]; exact LieSubmodule.subset_lieSpan /-- Note that this is not a special case of `LieSubmodule.subsingleton_of_bot`. Indeed, given `I : LieIdeal R L`, in general the two lattices `LieIdeal R I` and `LieSubmodule R L I` are different (though the latter does naturally inject into the former). In other words, in general, ideals of `I`, regarded as a Lie algebra in its own right, are not the same as ideals of `L` contained in `I`. -/ instance subsingleton_of_bot : Subsingleton (LieIdeal R (⊥ : LieIdeal R L)) := by apply subsingleton_of_bot_eq_top subsingleton end LieIdeal namespace LieHom variable [LieAlgebra R L] [LieModule R L M] [LieModule R L M'] variable (f : L →ₗ⁅R⁆ L') (I : LieIdeal R L) (J : LieIdeal R L') /-- The kernel of a morphism of Lie algebras, as an ideal in the domain. -/ def ker : LieIdeal R L := LieIdeal.comap f ⊥ /-- The range of a morphism of Lie algebras as an ideal in the codomain. -/ def idealRange : LieIdeal R L' := LieSubmodule.lieSpan R L' f.range theorem idealRange_eq_lieSpan_range : f.idealRange = LieSubmodule.lieSpan R L' f.range := rfl theorem idealRange_eq_map : f.idealRange = LieIdeal.map f ⊤ := by ext simp only [idealRange, range_eq_map] rfl /-- The condition that the range of a morphism of Lie algebras is an ideal. -/ def IsIdealMorphism : Prop := (f.idealRange : LieSubalgebra R L') = f.range theorem isIdealMorphism_def : f.IsIdealMorphism ↔ (f.idealRange : LieSubalgebra R L') = f.range := Iff.rfl variable {f} in theorem IsIdealMorphism.eq (hf : f.IsIdealMorphism) : f.idealRange = f.range := hf theorem isIdealMorphism_iff : f.IsIdealMorphism ↔ ∀ (x : L') (y : L), ∃ z : L, ⁅x, f y⁆ = f z := by simp only [isIdealMorphism_def, idealRange_eq_lieSpan_range, ← LieSubalgebra.toSubmodule_inj, ← f.range.coe_toSubmodule, LieIdeal.toLieSubalgebra_toSubmodule, LieSubmodule.coe_lieSpan_submodule_eq_iff, LieSubalgebra.mem_toSubmodule, mem_range, exists_imp, Submodule.exists_lieSubmodule_coe_eq_iff] constructor · intro h x y; obtain ⟨z, hz⟩ := h x (f y) y rfl; use z; exact hz.symm · intro h x y z hz; obtain ⟨w, hw⟩ := h x z; use w; rw [← hw, hz] theorem range_subset_idealRange : (f.range : Set L') ⊆ f.idealRange := LieSubmodule.subset_lieSpan theorem map_le_idealRange : I.map f ≤ f.idealRange := by rw [f.idealRange_eq_map] exact LieIdeal.map_mono le_top theorem ker_le_comap : f.ker ≤ J.comap f := LieIdeal.comap_mono bot_le @[simp] theorem ker_toSubmodule : LieSubmodule.toSubmodule (ker f) = LinearMap.ker (f : L →ₗ[R] L') := rfl variable {f} in @[simp] theorem mem_ker {x : L} : x ∈ ker f ↔ f x = 0 := show x ∈ LieSubmodule.toSubmodule (f.ker) ↔ _ by simp only [ker_toSubmodule, LinearMap.mem_ker, coe_toLinearMap] theorem mem_idealRange (x : L) : f x ∈ idealRange f := by rw [idealRange_eq_map] exact LieIdeal.mem_map (LieSubmodule.mem_top x) @[simp] theorem mem_idealRange_iff (h : IsIdealMorphism f) {y : L'} : y ∈ idealRange f ↔ ∃ x : L, f x = y := by rw [f.isIdealMorphism_def] at h rw [← LieSubmodule.mem_coe, ← LieIdeal.coe_toLieSubalgebra, h, f.coe_range, Set.mem_range] theorem le_ker_iff : I ≤ f.ker ↔ ∀ x, x ∈ I → f x = 0 := by constructor <;> intro h x hx · specialize h hx; rw [mem_ker] at h; exact h · rw [mem_ker]; apply h x hx theorem ker_eq_bot : f.ker = ⊥ ↔ Function.Injective f := by rw [← LieSubmodule.toSubmodule_inj, ker_toSubmodule, LieSubmodule.bot_toSubmodule, LinearMap.ker_eq_bot, coe_toLinearMap] @[simp] theorem range_toSubmodule : (f.range : Submodule R L') = LinearMap.range (f : L →ₗ[R] L') := rfl theorem range_eq_top : f.range = ⊤ ↔ Function.Surjective f := by rw [← LieSubalgebra.toSubmodule_inj, range_toSubmodule, LieSubalgebra.top_toSubmodule] exact LinearMap.range_eq_top @[simp] theorem idealRange_eq_top_of_surjective (h : Function.Surjective f) : f.idealRange = ⊤ := by rw [← f.range_eq_top] at h rw [idealRange_eq_lieSpan_range, h, ← LieSubalgebra.coe_toSubmodule, ← LieSubmodule.toSubmodule_inj, LieSubmodule.top_toSubmodule, LieSubalgebra.top_toSubmodule, LieSubmodule.coe_lieSpan_submodule_eq_iff] use ⊤ exact LieSubmodule.top_toSubmodule theorem isIdealMorphism_of_surjective (h : Function.Surjective f) : f.IsIdealMorphism := by rw [isIdealMorphism_def, f.idealRange_eq_top_of_surjective h, f.range_eq_top.mpr h, LieIdeal.top_toLieSubalgebra] end LieHom namespace LieIdeal variable [LieAlgebra R L] [LieModule R L M] [LieModule R L M'] variable {f : L →ₗ⁅R⁆ L'} {I I₂ : LieIdeal R L} {J : LieIdeal R L'} @[simp] theorem map_eq_bot_iff : I.map f = ⊥ ↔ I ≤ f.ker := by rw [← le_bot_iff] exact LieIdeal.map_le_iff_le_comap theorem coe_map_of_surjective (h : Function.Surjective f) : LieSubmodule.toSubmodule (I.map f) = (LieSubmodule.toSubmodule I).map (f : L →ₗ[R] L') := by let J : LieIdeal R L' := { (I : Submodule R L).map (f : L →ₗ[R] L') with lie_mem := fun {x y} hy ↦ by have hy' : ∃ x : L, x ∈ I ∧ f x = y := by simpa [hy] obtain ⟨z₂, hz₂, rfl⟩ := hy' obtain ⟨z₁, rfl⟩ := h x simp only [LieHom.coe_toLinearMap, SetLike.mem_coe, Set.mem_image, Submodule.mem_carrier, Submodule.map_coe] use ⁅z₁, z₂⁆ exact ⟨I.lie_mem hz₂, f.map_lie z₁ z₂⟩ } rw [map, toLieSubalgebra_toSubmodule, LieSubmodule.coe_lieSpan_submodule_eq_iff] exact ⟨J, rfl⟩ theorem mem_map_of_surjective {y : L'} (h₁ : Function.Surjective f) (h₂ : y ∈ I.map f) : ∃ x : I, f x = y := by rw [← LieSubmodule.mem_toSubmodule, coe_map_of_surjective h₁, Submodule.mem_map] at h₂ obtain ⟨x, hx, rfl⟩ := h₂ use ⟨x, hx⟩ rw [LieHom.coe_toLinearMap] theorem bot_of_map_eq_bot {I : LieIdeal R L} (h₁ : Function.Injective f) (h₂ : I.map f = ⊥) : I = ⊥ := by rw [← f.ker_eq_bot, LieHom.ker] at h₁ rw [eq_bot_iff, map_le_iff_le_comap, h₁] at h₂ rw [eq_bot_iff]; exact h₂ /-- Given two nested Lie ideals `I₁ ⊆ I₂`, the inclusion `I₁ ↪ I₂` is a morphism of Lie algebras. -/ def inclusion {I₁ I₂ : LieIdeal R L} (h : I₁ ≤ I₂) : I₁ →ₗ⁅R⁆ I₂ where __ := Submodule.inclusion (show I₁.toSubmodule ≤ I₂.toSubmodule from h) map_lie' := rfl @[simp] theorem coe_inclusion {I₁ I₂ : LieIdeal R L} (h : I₁ ≤ I₂) (x : I₁) : (inclusion h x : L) = x := rfl theorem inclusion_apply {I₁ I₂ : LieIdeal R L} (h : I₁ ≤ I₂) (x : I₁) : inclusion h x = ⟨x.1, h x.2⟩ := rfl theorem inclusion_injective {I₁ I₂ : LieIdeal R L} (h : I₁ ≤ I₂) : Function.Injective (inclusion h) := fun x y ↦ by simp only [inclusion_apply, imp_self, Subtype.mk_eq_mk, SetLike.coe_eq_coe] theorem map_sup_ker_eq_map : LieIdeal.map f (I ⊔ f.ker) = LieIdeal.map f I := by refine le_antisymm ?_ (LieIdeal.map_mono le_sup_left) apply LieSubmodule.lieSpan_mono rintro x ⟨y, hy₁, hy₂⟩ rw [← hy₂] erw [LieSubmodule.mem_sup] at hy₁ obtain ⟨z₁, hz₁, z₂, hz₂, hy⟩ := hy₁ rw [← hy] rw [map_add, f.coe_toLinearMap, LieHom.mem_ker.mp hz₂, add_zero]; exact ⟨z₁, hz₁, rfl⟩ @[simp] theorem map_sup_ker_eq_map' : LieIdeal.map f I ⊔ LieIdeal.map f (LieHom.ker f) = LieIdeal.map f I := by simpa using map_sup_ker_eq_map (f := f) @[simp] theorem map_comap_eq (h : f.IsIdealMorphism) : map f (comap f J) = f.idealRange ⊓ J := by apply le_antisymm · rw [le_inf_iff]; exact ⟨f.map_le_idealRange _, map_comap_le⟩ · rw [f.isIdealMorphism_def] at h rw [← SetLike.coe_subset_coe, LieSubmodule.coe_inf, ← coe_toLieSubalgebra, h] rintro y ⟨⟨x, h₁⟩, h₂⟩; rw [← h₁] at h₂ ⊢; exact mem_map h₂ @[simp] theorem comap_map_eq (h : ↑(map f I) = f '' I) : comap f (map f I) = I ⊔ f.ker := by rw [← LieSubmodule.toSubmodule_inj, comap_toSubmodule, I.map_toSubmodule f h, LieSubmodule.sup_toSubmodule, f.ker_toSubmodule, Submodule.comap_map_eq] variable (f I J) /-- Regarding an ideal `I` as a subalgebra, the inclusion map into its ambient space is a morphism of Lie algebras. -/ def incl : I →ₗ⁅R⁆ L := (I : LieSubalgebra R L).incl @[simp] theorem incl_range : I.incl.range = I := (I : LieSubalgebra R L).incl_range @[simp] theorem incl_apply (x : I) : I.incl x = x := rfl @[simp] theorem incl_coe : (I.incl.toLinearMap : I →ₗ[R] L) = (I : Submodule R L).subtype := rfl lemma incl_injective (I : LieIdeal R L) : Function.Injective I.incl := Subtype.val_injective @[simp] theorem comap_incl_self : comap I.incl I = ⊤ := by ext; simp @[simp] theorem ker_incl : I.incl.ker = ⊥ := by ext; simp @[simp] theorem incl_idealRange : I.incl.idealRange = I := by rw [LieHom.idealRange_eq_lieSpan_range, ← LieSubalgebra.coe_toSubmodule, ← LieSubmodule.toSubmodule_inj, incl_range, toLieSubalgebra_toSubmodule, LieSubmodule.coe_lieSpan_submodule_eq_iff] use I theorem incl_isIdealMorphism : I.incl.IsIdealMorphism := by rw [I.incl.isIdealMorphism_def, incl_idealRange] exact (I : LieSubalgebra R L).incl_range.symm variable {I} @[simp] theorem comap_incl_eq_top : I₂.comap I.incl = ⊤ ↔ I ≤ I₂ := by rw [← LieSubmodule.toSubmodule_inj, LieIdeal.comap_toSubmodule, LieSubmodule.top_toSubmodule, incl_coe] simp_rw [toLieSubalgebra_toSubmodule] rw [Submodule.comap_subtype_eq_top, LieSubmodule.toSubmodule_le_toSubmodule] @[simp] theorem comap_incl_eq_bot : I₂.comap I.incl = ⊥ ↔ Disjoint I I₂ := by rw [disjoint_iff, ←LieSubmodule.toSubmodule_inj, LieIdeal.comap_toSubmodule, LieSubmodule.bot_toSubmodule, ← LieSubmodule.toSubmodule_inj, LieSubmodule.inf_toSubmodule, LieSubmodule.bot_toSubmodule, incl_coe] simp_rw [toLieSubalgebra_toSubmodule] rw [← Submodule.disjoint_iff_comap_eq_bot, disjoint_iff] end LieIdeal end LieSubmoduleMapAndComap section TopEquiv variable (R : Type u) (L : Type v) variable [CommRing R] [LieRing L] variable (M : Type*) [AddCommGroup M] [Module R M] [LieRingModule L M] variable {R L} variable [LieAlgebra R L] [LieModule R L M] /-- The natural equivalence between the 'top' Lie ideal and the enclosing Lie algebra. This is the Lie ideal version of `Submodule.topEquiv`. -/ def LieIdeal.topEquiv : (⊤ : LieIdeal R L) ≃ₗ⁅R⁆ L := LieSubalgebra.topEquiv theorem LieIdeal.topEquiv_apply (x : (⊤ : LieIdeal R L)) : LieIdeal.topEquiv x = x := rfl end TopEquiv
.lake/packages/mathlib/Mathlib/Algebra/Lie/Sl2.lean
import Mathlib.Algebra.Lie.OfAssociative import Mathlib.LinearAlgebra.Eigenspace.Basic import Mathlib.LinearAlgebra.FreeModule.StrongRankCondition /-! # The Lie algebra `sl₂` and its representations The Lie algebra `sl₂` is the unique simple Lie algebra of minimal rank, 1, and as such occupies a distinguished position in the general theory. This file provides some basic definitions and results about `sl₂`. ## Main definitions: * `IsSl2Triple`: a structure representing a triple of elements in a Lie algebra which satisfy the standard relations for `sl₂`. * `IsSl2Triple.HasPrimitiveVectorWith`: a structure representing a primitive vector in a representation of a Lie algebra relative to a distinguished `sl₂` triple. * `IsSl2Triple.HasPrimitiveVectorWith.exists_nat`: the eigenvalue of a primitive vector must be a natural number if the representation is finite-dimensional. -/ variable (R L M : Type*) [CommRing R] [LieRing L] [LieAlgebra R L] [AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M] open LieModule Set variable {L} in /-- An `sl₂` triple within a Lie ring `L` is a triple of elements `h`, `e`, `f` obeying relations which ensure that the Lie subalgebra they generate is equivalent to `sl₂`. -/ structure IsSl2Triple (h e f : L) : Prop where h_ne_zero : h ≠ 0 lie_e_f : ⁅e, f⁆ = h lie_h_e_nsmul : ⁅h, e⁆ = 2 • e lie_h_f_nsmul : ⁅h, f⁆ = - (2 • f) namespace IsSl2Triple variable {L M} variable {h e f : L} lemma symm (ht : IsSl2Triple h e f) : IsSl2Triple (-h) f e where h_ne_zero := by simpa using ht.h_ne_zero lie_e_f := by rw [← neg_eq_iff_eq_neg, lie_skew, ht.lie_e_f] lie_h_e_nsmul := by rw [neg_lie, neg_eq_iff_eq_neg, ht.lie_h_f_nsmul] lie_h_f_nsmul := by rw [neg_lie, neg_inj, ht.lie_h_e_nsmul] @[simp] lemma symm_iff : IsSl2Triple (-h) f e ↔ IsSl2Triple h e f := ⟨fun t ↦ neg_neg h ▸ t.symm, symm⟩ lemma lie_h_e_smul (t : IsSl2Triple h e f) : ⁅h, e⁆ = (2 : R) • e := by simp [t.lie_h_e_nsmul, two_smul] lemma lie_lie_smul_f (t : IsSl2Triple h e f) : ⁅h, f⁆ = -((2 : R) • f) := by simp [t.lie_h_f_nsmul, two_smul] lemma e_ne_zero (t : IsSl2Triple h e f) : e ≠ 0 := by have := t.h_ne_zero contrapose! this simpa [this] using t.lie_e_f.symm lemma f_ne_zero (t : IsSl2Triple h e f) : f ≠ 0 := by have := t.h_ne_zero contrapose! this simpa [this] using t.lie_e_f.symm variable {R} /-- Given a representation of a Lie algebra with distinguished `sl₂` triple, a vector is said to be primitive if it is a simultaneous eigenvector for the action of both `h`, `e`, and the eigenvalue for `e` is zero. -/ structure HasPrimitiveVectorWith (t : IsSl2Triple h e f) (m : M) (μ : R) : Prop where ne_zero : m ≠ 0 lie_h : ⁅h, m⁆ = μ • m lie_e : ⁅e, m⁆ = 0 /-- Given a representation of a Lie algebra with distinguished `sl₂` triple, a simultaneous eigenvector for the action of both `h` and `e` necessarily has eigenvalue zero for `e`. -/ lemma HasPrimitiveVectorWith.mk' [IsAddTorsionFree M] (t : IsSl2Triple h e f) (m : M) (μ ρ : R) (hm : m ≠ 0) (hm' : ⁅h, m⁆ = μ • m) (he : ⁅e, m⁆ = ρ • m) : HasPrimitiveVectorWith t m μ where ne_zero := hm lie_h := hm' lie_e := by suffices 2 • ⁅e, m⁆ = 0 by simpa using this rw [← nsmul_lie, ← t.lie_h_e_nsmul, lie_lie, hm', lie_smul, he, lie_smul, hm', smul_smul, smul_smul, mul_comm ρ μ, sub_self] variable (R) in open Submodule in /-- The subalgebra associated to an `sl₂` triple. -/ def toLieSubalgebra (t : IsSl2Triple h e f) : LieSubalgebra R L where __ := span R {e, f, h} lie_mem' {x y} hx hy := by simp only [carrier_eq_coe, SetLike.mem_coe] at hx hy ⊢ induction hx using span_induction with | zero => simp | add u v hu hv hu' hv' => simpa only [add_lie] using add_mem hu' hv' | smul t u hu hu' => simpa only [smul_lie] using smul_mem _ t hu' | mem u hu => induction hy using span_induction with | zero => simp | add u v hu hv hu' hv' => simpa only [lie_add] using add_mem hu' hv' | smul t u hv hv' => simpa only [lie_smul] using smul_mem _ t hv' | mem v hv => simp only [mem_insert_iff, mem_singleton_iff] at hu hv rcases hu with rfl | rfl | rfl <;> rcases hv with rfl | rfl | rfl <;> (try simp only [lie_self, zero_mem]) · rw [t.lie_e_f] apply subset_span simp · rw [← lie_skew, t.lie_h_e_nsmul, neg_mem_iff] apply nsmul_mem <| subset_span _ simp · rw [← lie_skew, t.lie_e_f, neg_mem_iff] apply subset_span simp · rw [← lie_skew, t.lie_h_f_nsmul, neg_neg] apply nsmul_mem <| subset_span _ simp · rw [t.lie_h_e_nsmul] apply nsmul_mem <| subset_span _ simp · rw [t.lie_h_f_nsmul, neg_mem_iff] apply nsmul_mem <| subset_span _ simp lemma mem_toLieSubalgebra_iff {x : L} {t : IsSl2Triple h e f} : x ∈ t.toLieSubalgebra R ↔ ∃ c₁ c₂ c₃ : R, x = c₁ • e + c₂ • f + c₃ • ⁅e, f⁆ := by simp_rw [t.lie_e_f, toLieSubalgebra, ← LieSubalgebra.mem_toSubmodule, Submodule.mem_span_triple, eq_comm] namespace HasPrimitiveVectorWith variable {m : M} {μ : R} {t : IsSl2Triple h e f} local notation "ψ" n => ((toEnd R L M f) ^ n) m -- Although this is true by definition, we include this lemma (and the assumption) to mirror the API -- for `lie_h_pow_toEnd_f` and `lie_e_pow_succ_toEnd_f`. set_option linter.unusedVariables false in @[nolint unusedArguments] lemma lie_f_pow_toEnd_f (P : HasPrimitiveVectorWith t m μ) (n : ℕ) : ⁅f, ψ n⁆ = ψ (n + 1) := by simp [pow_succ'] variable (P : HasPrimitiveVectorWith t m μ) include P lemma lie_h_pow_toEnd_f (n : ℕ) : ⁅h, ψ n⁆ = (μ - 2 * n) • ψ n := by induction n with | zero => simpa using P.lie_h | succ n ih => rw [pow_succ', Module.End.mul_apply, toEnd_apply_apply, Nat.cast_add, Nat.cast_one, leibniz_lie h, t.lie_lie_smul_f R, ← neg_smul, ih, lie_smul, smul_lie, ← add_smul] congr ring lemma lie_e_pow_succ_toEnd_f (n : ℕ) : ⁅e, ψ (n + 1)⁆ = ((n + 1) * (μ - n)) • ψ n := by induction n with | zero => simp only [zero_add, pow_one, toEnd_apply_apply, Nat.cast_zero, sub_zero, one_mul, pow_zero, Module.End.one_apply, leibniz_lie e, t.lie_e_f, P.lie_e, P.lie_h, lie_zero, add_zero] | succ n ih => rw [pow_succ', Module.End.mul_apply, toEnd_apply_apply, leibniz_lie e, t.lie_e_f, lie_h_pow_toEnd_f P, ih, lie_smul, lie_f_pow_toEnd_f P, ← add_smul, Nat.cast_add, Nat.cast_one] congr ring /-- The eigenvalue of a primitive vector must be a natural number if the representation is finite-dimensional. -/ lemma exists_nat [IsNoetherian R M] [NoZeroSMulDivisors R M] [IsDomain R] [CharZero R] : ∃ n : ℕ, μ = n := by suffices ∃ n : ℕ, (ψ n) = 0 by obtain ⟨n, hn₁, hn₂⟩ := Nat.exists_not_and_succ_of_not_zero_of_exists P.ne_zero this refine ⟨n, ?_⟩ have := lie_e_pow_succ_toEnd_f P n rw [hn₂, lie_zero, eq_comm, smul_eq_zero_iff_left hn₁, mul_eq_zero, sub_eq_zero] at this exact this.resolve_left <| Nat.cast_add_one_ne_zero n have hs : (range <| fun (n : ℕ) ↦ μ - 2 * n).Infinite := by rw [infinite_range_iff (fun n m ↦ by simp)]; infer_instance by_contra! contra exact hs ((toEnd R L M h).eigenvectors_linearIndependent {μ - 2 * n | n : ℕ} (fun ⟨s, hs⟩ ↦ ψ Classical.choose hs) (fun ⟨r, hr⟩ ↦ by simp [lie_h_pow_toEnd_f P, Classical.choose_spec hr, contra, Module.End.hasEigenvector_iff])).finite lemma pow_toEnd_f_ne_zero_of_eq_nat [CharZero R] [NoZeroSMulDivisors R M] {n : ℕ} (hn : μ = n) {i} (hi : i ≤ n) : (ψ i) ≠ 0 := by intro H induction i · exact P.ne_zero (by simpa using H) · next i IH => have : ((i + 1) * (n - i) : ℤ) • (toEnd R L M f ^ i) m = 0 := by have := congr_arg (⁅e, ·⁆) H simpa [← Int.cast_smul_eq_zsmul R, P.lie_e_pow_succ_toEnd_f, hn] using this rw [← Int.cast_smul_eq_zsmul R, smul_eq_zero, Int.cast_eq_zero, mul_eq_zero, sub_eq_zero, Nat.cast_inj, ← @Nat.cast_one ℤ, ← Nat.cast_add, Nat.cast_eq_zero] at this simp only [add_eq_zero, one_ne_zero, and_false, false_or] at this exact (hi.trans_eq (this.resolve_right (IH (i.le_succ.trans hi)))).not_gt i.lt_succ_self lemma pow_toEnd_f_eq_zero_of_eq_nat [IsNoetherian R M] [NoZeroSMulDivisors R M] [IsDomain R] [CharZero R] {n : ℕ} (hn : μ = n) : (ψ (n + 1)) = 0 := by by_contra h have : t.HasPrimitiveVectorWith (ψ (n + 1)) (n - 2 * (n + 1) : R) := { ne_zero := h lie_h := (P.lie_h_pow_toEnd_f _).trans (by simp [hn]) lie_e := (P.lie_e_pow_succ_toEnd_f _).trans (by simp [hn]) } obtain ⟨m, hm⟩ := this.exists_nat have : (n : ℤ) < m + 2 * (n + 1) := by omega exact this.ne (Int.cast_injective (α := R) <| by simpa [sub_eq_iff_eq_add] using hm) end HasPrimitiveVectorWith end IsSl2Triple
.lake/packages/mathlib/Mathlib/Algebra/Lie/CartanExists.lean
import Mathlib.Algebra.Lie.CartanSubalgebra import Mathlib.Algebra.Lie.Rank /-! # Existence of Cartan subalgebras In this file we prove existence of Cartan subalgebras in finite-dimensional Lie algebras, following [barnes1967]. ## Main results * `exists_isCartanSubalgebra_of_finrank_le_card`: A Lie algebra `L` over a field `K` has a Cartan subalgebra, provided that the dimension of `L` over `K` is less than or equal to the cardinality of `K`. * `exists_isCartanSubalgebra`: A finite-dimensional Lie algebra `L` over an infinite field `K` has a Cartan subalgebra. ## References * [barnes1967]: "On Cartan subalgebras of Lie algebras" by D.W. Barnes. -/ namespace LieAlgebra section CommRing variable {K R L M : Type*} variable [Field K] [CommRing R] variable [LieRing L] [LieAlgebra K L] [LieAlgebra R L] variable [AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M] variable [Module.Finite K L] variable [Module.Finite R L] [Module.Free R L] variable [Module.Finite R M] [Module.Free R M] open Module LieSubalgebra Module.Free Polynomial variable (K) namespace engel_isBot_of_isMin /-! ## Implementation details for the proof of `LieAlgebra.engel_isBot_of_isMin` In this section we provide some auxiliary definitions and lemmas that are used in the proof of `LieAlgebra.engel_isBot_of_isMin`, which is the following statement: Let `L` be a Lie algebra of dimension `n` over a field `K` with at least `n` elements. Given a Lie subalgebra `U` of `L`, and an element `x ∈ U` such that `U ≤ engel K x`. Suppose that `engel K x` is minimal amongst the Engel subalgebras `engel K y` for `y ∈ U`. Then `engel K x ≤ engel K y` for all `y ∈ U`. We follow the proof strategy of Lemma 2 in [barnes1967]. -/ variable (R M) variable (x y : L) open LieModule LinearMap local notation "φ" => LieModule.toEnd R L M /-- Let `x` and `y` be elements of a Lie `R`-algebra `L`, and `M` a Lie module over `L`. Then the characteristic polynomials of the family of endomorphisms `⁅r • y + x, _⁆` of `M` have coefficients that are polynomial in `r : R`. In other words, we obtain a polynomial over `R[X]` that specializes to the characteristic polynomial of `⁅r • y + x, _⁆` under the map `X ↦ r`. This polynomial is captured in `lieCharpoly R M x y`. -/ private noncomputable def lieCharpoly : Polynomial R[X] := letI bL := chooseBasis R L (polyCharpoly (LieHom.toLinearMap φ) bL).map <| RingHomClass.toRingHom <| MvPolynomial.aeval fun i ↦ C (bL.repr y i) * X + C (bL.repr x i) lemma lieCharpoly_monic : (lieCharpoly R M x y).Monic := (polyCharpoly_monic _ _).map _ lemma lieCharpoly_natDegree [Nontrivial R] : (lieCharpoly R M x y).natDegree = finrank R M := by rw [lieCharpoly, (polyCharpoly_monic _ _).natDegree_map, polyCharpoly_natDegree] variable {R} in lemma lieCharpoly_map_eval (r : R) : (lieCharpoly R M x y).map (evalRingHom r) = (φ (r • y + x)).charpoly := by rw [lieCharpoly, map_map] set b := chooseBasis R L have aux : (fun i ↦ (b.repr y) i * r + (b.repr x) i) = b.repr (r • y + x) := by ext i; simp [mul_comm r] simp_rw [← coe_aeval_eq_evalRingHom, ← AlgHom.comp_toRingHom, MvPolynomial.comp_aeval, map_add, map_mul, aeval_C, Algebra.algebraMap_self, RingHom.id_apply, aeval_X, aux, MvPolynomial.coe_aeval_eq_eval, polyCharpoly_map_eq_charpoly, LieHom.coe_toLinearMap, map_add] lemma lieCharpoly_coeff_natDegree [Nontrivial R] (i j : ℕ) (hij : i + j = finrank R M) : ((lieCharpoly R M x y).coeff i).natDegree ≤ j := by classical rw [← mul_one j, lieCharpoly, coeff_map] apply MvPolynomial.aeval_natDegree_le · apply (polyCharpoly_coeff_isHomogeneous φ (chooseBasis R L) _ _ hij).totalDegree_le intro k apply Polynomial.natDegree_add_le_of_degree_le · apply (Polynomial.natDegree_C_mul_le _ _).trans simp only [natDegree_X, le_rfl] · simp only [natDegree_C, zero_le] end engel_isBot_of_isMin end CommRing section Field variable {K L : Type*} [Field K] [LieRing L] [LieAlgebra K L] [Module.Finite K L] open Module LieSubalgebra LieSubmodule Polynomial Cardinal LieModule engel_isBot_of_isMin /-- Let `L` be a Lie algebra of dimension `n` over a field `K` with at least `n` elements. Given a Lie subalgebra `U` of `L`, and an element `x ∈ U` such that `U ≤ engel K x`. Suppose that `engel K x` is minimal amongst the Engel subalgebras `engel K y` for `y ∈ U`. Then `engel K x ≤ engel K y` for all `y ∈ U`. Lemma 2 in [barnes1967]. -/ lemma engel_isBot_of_isMin (hLK : finrank K L ≤ #K) (U : LieSubalgebra K L) (E : {engel K x | x ∈ U}) (hUle : U ≤ E) (hmin : IsMin E) : IsBot E := by rcases E with ⟨_, x, hxU, rfl⟩ rintro ⟨_, y, hyU, rfl⟩ -- It will be useful to repackage the Engel subalgebras set Ex : {engel K x | x ∈ U} := ⟨engel K x, x, hxU, rfl⟩ set Ey : {engel K y | y ∈ U} := ⟨engel K y, y, hyU, rfl⟩ replace hUle : U ≤ Ex := hUle replace hmin : ∀ E, E ≤ Ex → Ex ≤ E := @hmin -- We also repackage the Engel subalgebra `engel K x` -- as Lie submodule `E` of `L` over the Lie algebra `U`. let E : LieSubmodule K U L := { engel K x with lie_mem := by rintro ⟨u, hu⟩ y hy; exact (engel K x).lie_mem (hUle hu) hy } -- We may and do assume that `x ≠ 0`, since otherwise the statement is trivial. obtain rfl | hx₀ := eq_or_ne x 0 · simpa [Ex, Ey] using hmin Ey -- We denote by `Q` the quotient `L / E`, and by `r` the dimension of `E`. let Q := L ⧸ E let r := finrank K E -- If `r = finrank K L`, then `E = L`, and the statement is trivial. obtain hr|hr : r = finrank K L ∨ r < finrank K L := (Submodule.finrank_le _).eq_or_lt · suffices engel K y ≤ engel K x from hmin Ey this suffices engel K x = ⊤ by simp_rw [this, le_top] apply LieSubalgebra.toSubmodule_injective apply Submodule.eq_top_of_finrank_eq hr -- So from now on, we assume that `r < finrank K L`. -- We denote by `x'` and `y'` the elements `x` and `y` viewed as terms of `U`. set x' : U := ⟨x, hxU⟩ set y' : U := ⟨y, hyU⟩ -- Let `u : U` denote `y - x`. let u : U := y' - x' -- We denote by `χ r` the characteristic polynomial of `⁅r • u + x, _⁆` -- viewed as endomorphism of `E`. Note that `χ` is polynomial in its argument `r`. -- Similarly: `ψ r` is the characteristic polynomial of `⁅r • u + x, _⁆` -- viewed as endomorphism of `Q`. Note that `ψ` is polynomial in its argument `r`. let χ : Polynomial (K[X]) := lieCharpoly K E x' u let ψ : Polynomial (K[X]) := lieCharpoly K Q x' u -- It suffices to show that `χ` is the monomial `X ^ r`. suffices χ = X ^ r by -- Indeed, by evaluating the coefficients at `1` apply_fun (fun p ↦ p.map (evalRingHom 1)) at this -- we find that the characteristic polynomial `χ 1` of `⁅y, _⁆` is equal to `X ^ r` simp_rw [Polynomial.map_pow, map_X, χ, lieCharpoly_map_eval, one_smul, u, sub_add_cancel, -- and therefore the endomorphism `⁅y, _⁆` acts nilpotently on `E`. r, LinearMap.charpoly_eq_X_pow_iff, Subtype.ext_iff, coe_toEnd_pow _ _ _ E, ZeroMemClass.coe_zero] at this -- We ultimately want to show `engel K x ≤ engel K y` intro z hz -- which holds by definition of Engel subalgebra and the nilpotency that we just established. rw [mem_engel_iff] exact this ⟨z, hz⟩ -- To show that `χ = X ^ r`, it suffices to show that all coefficients in degrees `< r` are `0`. suffices ∀ i < r, χ.coeff i = 0 by simp_rw [r, ← lieCharpoly_natDegree K E x' u] at this ⊢ rw [(lieCharpoly_monic K E x' u).eq_X_pow_iff_natDegree_le_natTrailingDegree] exact le_natTrailingDegree (lieCharpoly_monic K E x' u).ne_zero this -- Let us consider the `i`-th coefficient of `χ`, for `i < r`. intro i hi -- We separately consider the case `i = 0`. obtain rfl | hi0 := eq_or_ne i 0 · -- `The polynomial `coeff χ 0` is zero if it evaluates to zero on all elements of `K`, -- provided that its degree is stictly less than `#K`. apply eq_zero_of_forall_eval_zero_of_natDegree_lt_card _ _ ?deg case deg => -- We need to show `(natDegree (coeff χ 0)) < #K` and know that `finrank K L ≤ #K` apply lt_of_lt_of_le _ hLK rw [Nat.cast_lt] -- So we are left with showing `natDegree (coeff χ 0) < finrank K L` apply lt_of_le_of_lt _ hr apply lieCharpoly_coeff_natDegree _ _ _ _ 0 r (zero_add r) -- Fix an element of `K`. intro α -- We want to show that `α` is a root of `coeff χ 0`. -- So we need to show that there is a `z ≠ 0` in `E` satisfying `⁅α • u + x, z⁆ = 0`. rw [← coe_evalRingHom, ← coeff_map, lieCharpoly_map_eval, ← constantCoeff_apply, LinearMap.charpoly_constantCoeff_eq_zero_iff] -- We consider `z = α • u + x`, and split into the cases `z = 0` and `z ≠ 0`. let z := α • u + x' obtain hz₀|hz₀ := eq_or_ne z 0 · -- If `z = 0`, then `⁅α • u + x, x⁆` vanishes and we use our assumption `x ≠ 0`. refine ⟨⟨x, self_mem_engel K x⟩, ?_, ?_⟩ · exact Subtype.coe_ne_coe.mp hx₀ · dsimp only [z] at hz₀ simp only [hz₀, map_zero, LinearMap.zero_apply] -- If `z ≠ 0`, then `⁅α • u + x, z⁆` vanishes per axiom of Lie algebras refine ⟨⟨z, hUle z.2⟩, ?_, ?_⟩ · simpa only [coe_bracket_of_module, ne_eq, Submodule.mk_eq_zero, Subtype.ext_iff] using hz₀ · change ⁅z, _⁆ = (0 : E) ext exact lie_self z.1 -- We are left with the case `i ≠ 0`, and want to show `coeff χ i = 0`. -- We will do this once again by showing that `coeff χ i` vanishes -- on a sufficiently large subset `s` of `K`. -- But we first need to get our hands on that subset `s`. -- We start by observing that `ψ` has non-trivial constant coefficient. have hψ : constantCoeff ψ ≠ 0 := by -- Suppose that `ψ` in fact has trivial constant coefficient. intro H -- Then there exists a `z ≠ 0` in `Q` such that `⁅x, z⁆ = 0`. obtain ⟨z, hz0, hxz⟩ : ∃ z : Q, z ≠ 0 ∧ ⁅x', z⁆ = 0 := by -- Indeed, if the constant coefficient of `ψ` is trivial, -- then `0` is a root of the characteristic polynomial of `⁅0 • u + x, _⁆` acting on `Q`, -- and hence we find an eigenvector `z` as desired. apply_fun (evalRingHom 0) at H rw [constantCoeff_apply, ← coeff_map, lieCharpoly_map_eval, ← constantCoeff_apply, map_zero, LinearMap.charpoly_constantCoeff_eq_zero_iff] at H simpa only [coe_bracket_of_module, ne_eq, zero_smul, zero_add, toEnd_apply_apply] using H -- It suffices to show `z = 0` (in `Q`) to obtain a contradiction. apply hz0 -- We replace `z : Q` by a representative in `L`. obtain ⟨z, rfl⟩ := LieSubmodule.Quotient.surjective_mk' E z -- The assumption `⁅x, z⁆ = 0` is equivalent to `⁅x, z⁆ ∈ E`. have : ⁅x, z⁆ ∈ E := by rwa [← LieSubmodule.Quotient.mk_eq_zero'] -- From this we deduce that there exists an `n` such that `⁅x, _⁆ ^ n` vanishes on `⁅x, z⁆`. -- On the other hand, our goal is to show `z = 0` in `Q`, -- which is equivalent to showing that `⁅x, _⁆ ^ n` vanishes on `z`, for some `n`. simp only [LieSubmodule.mem_mk_iff', LieSubalgebra.mem_toSubmodule, mem_engel_iff, LieSubmodule.Quotient.mk'_apply, LieSubmodule.Quotient.mk_eq_zero', E, Q] at this ⊢ -- Hence we win. obtain ⟨n, hn⟩ := this use n + 1 rwa [pow_succ] -- Now we find a subset `s` of `K` of size `≥ r` -- such that `constantCoeff ψ` takes non-zero values on all of `s`. -- This turns out to be the subset that we alluded to earlier. obtain ⟨s, hs, hsψ⟩ : ∃ s : Finset K, r ≤ s.card ∧ ∀ α ∈ s, (constantCoeff ψ).eval α ≠ 0 := by classical -- Let `t` denote the set of roots of `constantCoeff ψ`. let t := (constantCoeff ψ).roots.toFinset -- We show that `t` has cardinality at most `finrank K L - r`. have ht : t.card ≤ finrank K L - r := by refine (Multiset.toFinset_card_le _).trans ?_ refine (card_roots' _).trans ?_ rw [constantCoeff_apply] -- Indeed, `constantCoeff ψ` has degree at most `finrank K Q = finrank K L - r`. apply lieCharpoly_coeff_natDegree suffices finrank K Q + r = finrank K L by rw [← this, zero_add, Nat.add_sub_cancel] apply Submodule.finrank_quotient_add_finrank -- Hence there exists a subset of size `≥ r` in the complement of `t`, -- and `constantCoeff ψ` takes non-zero values on all of this subset. obtain ⟨s, hs⟩ := exists_finset_le_card K _ hLK use s \ t refine ⟨?_, ?_⟩ · refine le_trans ?_ (Finset.le_card_sdiff _ _) cutsat · intro α hα simp only [Finset.mem_sdiff, Multiset.mem_toFinset, mem_roots', IsRoot.def, not_and, t] at hα exact hα.2 hψ -- So finally we can continue our proof strategy by showing that `coeff χ i` vanishes on `s`. apply eq_zero_of_natDegree_lt_card_of_eval_eq_zero' _ s _ ?hcard case hcard => -- We need to show that `natDegree (coeff χ i) < s.card` -- Which follows from our assumptions `i < r` and `r ≤ s.card` -- and the fact that the degree of `coeff χ i` is less than or equal to `r - i`. apply lt_of_le_of_lt (lieCharpoly_coeff_natDegree _ _ _ _ i (r - i) _) · cutsat · dsimp only [r] at hi ⊢ rw [Nat.add_sub_cancel' hi.le] -- We need to show that for all `α ∈ s`, the polynomial `coeff χ i` evaluates to zero at `α`. intro α hα -- Once again, we are left with showing that `⁅y, _⁆` acts nilpotently on `E`. rw [← coe_evalRingHom, ← coeff_map, lieCharpoly_map_eval, (LinearMap.charpoly_eq_X_pow_iff _).mpr, coeff_X_pow, if_neg hi.ne] -- To do so, it suffices to show that the Engel subalgebra of `v = a • u + x` is contained in `E`. let v := α • u + x' suffices engel K (v : L) ≤ engel K x by -- Indeed, in that case the minimality assumption on `E` implies -- that `E` is contained in the Engel subalgebra of `v`. replace this : engel K x ≤ engel K (v : L) := (hmin ⟨_, v, v.2, rfl⟩ this).ge intro z -- And so we are done, by the definition of Engel subalgebra. simpa only [mem_engel_iff, Subtype.ext_iff, coe_toEnd_pow _ _ _ E] using this z.2 -- Now we are in good shape. -- Fix an element `z` in the Engel subalgebra of `y`. intro z hz -- We need to show that `z` is in `E`, or alternatively that `z = 0` in `Q`. change z ∈ E rw [← LieSubmodule.Quotient.mk_eq_zero] -- We denote the image of `z` in `Q` by `z'`. set z' : Q := LieSubmodule.Quotient.mk' E z -- First we observe that `z'` is killed by a power of `⁅v, _⁆`. have hz' : ∃ n : ℕ, (toEnd K U Q v ^ n) z' = 0 := by rw [mem_engel_iff] at hz obtain ⟨n, hn⟩ := hz use n apply_fun LieSubmodule.Quotient.mk' E at hn rw [map_zero] at hn rw [← hn] clear hn induction n with | zero => simp only [z', pow_zero, Module.End.one_apply] | succ n ih => rw [pow_succ', pow_succ', Module.End.mul_apply, ih]; rfl classical -- Now let `n` be the smallest power such that `⁅v, _⁆ ^ n` kills `z'`. set n := Nat.find hz' with _hn have hn : (toEnd K U Q v ^ n) z' = 0 := Nat.find_spec hz' -- If `n = 0`, then we are done. obtain hn₀|⟨k, hk⟩ : n = 0 ∨ ∃ k, n = k + 1 := by cases n <;> simp · simpa only [hn₀, pow_zero, Module.End.one_apply] using hn -- If `n = k + 1`, then we can write `⁅v, _⁆ ^ n = ⁅v, _⁆ ∘ ⁅v, _⁆ ^ k`. -- Recall that `constantCoeff ψ` is non-zero on `α`, and `v = α • u + x`. specialize hsψ α hα -- Hence `⁅v, _⁆` acts injectively on `Q`. rw [← coe_evalRingHom, constantCoeff_apply, ← coeff_map, lieCharpoly_map_eval, ← constantCoeff_apply, ne_eq, LinearMap.charpoly_constantCoeff_eq_zero_iff] at hsψ -- We deduce from this that `z' = 0`, arguing by contraposition. contrapose! hsψ -- Indeed `⁅v, _⁆` kills `⁅v, _⁆ ^ k` applied to `z'`. use (toEnd K U Q v ^ k) z' refine ⟨?_, ?_⟩ · -- And `⁅v, _⁆ ^ k` applied to `z'` is non-zero by definition of `n`. apply Nat.find_min hz'; cutsat · rw [← hn, hk, pow_succ', Module.End.mul_apply] variable (K L) lemma exists_isCartanSubalgebra_engel_of_finrank_le_card (h : finrank K L ≤ #K) : ∃ x : L, IsCartanSubalgebra (engel K x) := by obtain ⟨x, hx⟩ := exists_isRegular_of_finrank_le_card K L h use x refine ⟨?_, normalizer_engel _ _⟩ apply isNilpotent_of_forall_le_engel intro y hy set Ex : {engel K z | z ∈ engel K x} := ⟨engel K x, x, self_mem_engel _ _, rfl⟩ suffices IsBot Ex from @this ⟨engel K y, y, hy, rfl⟩ apply engel_isBot_of_isMin h (engel K x) Ex le_rfl rintro ⟨_, y, hy, rfl⟩ hyx suffices finrank K (engel K x) ≤ finrank K (engel K y) by suffices engel K y = engel K x from this.ge apply LieSubalgebra.toSubmodule_injective exact Submodule.eq_of_le_of_finrank_le hyx this rw [(isRegular_iff_finrank_engel_eq_rank K x).mp hx] apply rank_le_finrank_engel lemma exists_isCartanSubalgebra_engel [Infinite K] : ∃ x : L, IsCartanSubalgebra (engel K x) := by apply exists_isCartanSubalgebra_engel_of_finrank_le_card exact (Cardinal.nat_lt_aleph0 _).le.trans <| Cardinal.infinite_iff.mp ‹Infinite K› end Field end LieAlgebra
.lake/packages/mathlib/Mathlib/Algebra/Lie/Killing.lean
import Mathlib.Algebra.Lie.InvariantForm import Mathlib.Algebra.Lie.Semisimple.Basic import Mathlib.Algebra.Lie.TraceForm /-! # Lie algebras with non-degenerate Killing forms. In characteristic zero, the following three conditions are equivalent: 1. The solvable radical of a Lie algebra is trivial 2. A Lie algebra is a direct sum of its simple ideals 3. A Lie algebra has non-degenerate Killing form In positive characteristic, it is still true that 3 implies 2, and that 2 implies 1, but there are counterexamples to the remaining implications. Thus condition 3 is the strongest assumption. Furthermore, much of the Cartan-Killing classification of semisimple Lie algebras in characteristic zero, continues to hold in positive characteristic (over a perfect field) if the Lie algebra has a non-degenerate Killing form. This file contains basic definitions and results for such Lie algebras. ## Main declarations * `LieAlgebra.IsKilling`: a typeclass encoding the fact that a Lie algebra has a non-singular Killing form. * `LieAlgebra.IsKilling.instSemisimple`: if a finite-dimensional Lie algebra over a field has non-singular Killing form then it is semisimple. * `LieAlgebra.IsKilling.instHasTrivialRadical`: if a Lie algebra over a PID has non-singular Killing form then it has trivial radical. ## TODO * Prove that in characteristic zero, a semisimple Lie algebra has non-singular Killing form. -/ variable (R K L : Type*) [CommRing R] [Field K] [LieRing L] [LieAlgebra R L] [LieAlgebra K L] namespace LieAlgebra /-- We say a Lie algebra is Killing if its Killing form is non-singular. NB: This is not standard terminology (the literature does not seem to name Lie algebras with this property). -/ class IsKilling : Prop where /-- We say a Lie algebra is Killing if its Killing form is non-singular. -/ killingCompl_top_eq_bot : LieIdeal.killingCompl R L ⊤ = ⊥ attribute [simp] IsKilling.killingCompl_top_eq_bot namespace IsKilling variable [IsKilling R L] @[simp] lemma ker_killingForm_eq_bot : LinearMap.ker (killingForm R L) = ⊥ := by simp [← LieIdeal.coe_killingCompl_top, killingCompl_top_eq_bot] lemma killingForm_nondegenerate : (killingForm R L).Nondegenerate := by simp [LinearMap.BilinForm.nondegenerate_iff_ker_eq_bot] variable {R L} in lemma ideal_eq_bot_of_isLieAbelian [Module.Free R L] [Module.Finite R L] [IsDomain R] [IsPrincipalIdealRing R] (I : LieIdeal R L) [IsLieAbelian I] : I = ⊥ := by rw [eq_bot_iff, ← killingCompl_top_eq_bot] exact I.le_killingCompl_top_of_isLieAbelian instance instSemisimple [IsKilling K L] [Module.Finite K L] : IsSemisimple K L := by apply InvariantForm.isSemisimple_of_nondegenerate (Φ := killingForm K L) · exact IsKilling.killingForm_nondegenerate _ _ · exact LieModule.traceForm_lieInvariant _ _ _ · exact (LieModule.traceForm_isSymm K L L).isRefl · intro I h₁ h₂ exact h₁.1 <| IsKilling.ideal_eq_bot_of_isLieAbelian I /-- The converse of this is true over a field of characteristic zero. There are counterexamples over fields with positive characteristic. Note that when the coefficients are a field this instance is redundant since we have `LieAlgebra.IsKilling.instSemisimple` and `LieAlgebra.IsSemisimple.instHasTrivialRadical`. -/ instance instHasTrivialRadical [Module.Free R L] [Module.Finite R L] [IsDomain R] [IsPrincipalIdealRing R] : HasTrivialRadical R L := (hasTrivialRadical_iff_no_abelian_ideals R L).mpr IsKilling.ideal_eq_bot_of_isLieAbelian end IsKilling section LieEquiv variable {R L} variable {L' : Type*} [LieRing L'] [LieAlgebra R L'] /-- Given an equivalence `e` of Lie algebras from `L` to `L'`, and elements `x y : L`, the respective Killing forms of `L` and `L'` satisfy `κ'(e x, e y) = κ(x, y)`. -/ @[simp] lemma killingForm_of_equiv_apply (e : L ≃ₗ⁅R⁆ L') (x y : L) : killingForm R L' (e x) (e y) = killingForm R L x y := by simp_rw [killingForm_apply_apply, ← LieAlgebra.conj_ad_apply, ← LinearEquiv.conj_comp, LinearMap.trace_conj'] /-- Given a Killing Lie algebra `L`, if `L'` is isomorphic to `L`, then `L'` is Killing too. -/ lemma isKilling_of_equiv [IsKilling R L] (e : L ≃ₗ⁅R⁆ L') : IsKilling R L' := by constructor ext x' simp_rw [LieIdeal.mem_killingCompl, LieModule.traceForm_comm] refine ⟨fun hx' ↦ ?_, fun hx y _ ↦ hx ▸ LinearMap.map_zero₂ (killingForm R L') y⟩ suffices e.symm x' ∈ LinearMap.ker (killingForm R L) by rw [IsKilling.ker_killingForm_eq_bot] at this simpa [map_zero] using (e : L ≃ₗ[R] L').congr_arg this ext y replace hx' : ∀ y', killingForm R L' x' y' = 0 := by simpa using hx' specialize hx' (e y) rwa [← e.apply_symm_apply x', killingForm_of_equiv_apply] at hx' alias _root_.LieEquiv.isKilling := LieAlgebra.isKilling_of_equiv end LieEquiv end LieAlgebra
.lake/packages/mathlib/Mathlib/Algebra/Lie/Engel.lean
import Mathlib.Algebra.Lie.Nilpotent import Mathlib.Algebra.Lie.Normalizer /-! # Engel's theorem This file contains a proof of Engel's theorem providing necessary and sufficient conditions for Lie algebras and Lie modules to be nilpotent. The key result `LieModule.isNilpotent_iff_forall` says that if `M` is a Lie module of a Noetherian Lie algebra `L`, then `M` is nilpotent iff the image of `L → End(M)` consists of nilpotent elements. In the special case that we have the adjoint representation `M = L`, this says that a Lie algebra is nilpotent iff `ad x : End(L)` is nilpotent for all `x : L`. Engel's theorem is true for any coefficients (i.e., it is really a theorem about Lie rings) and so we work with coefficients in any commutative ring `R` throughout. On the other hand, Engel's theorem is not true for infinite-dimensional Lie algebras and so a finite-dimensionality assumption is required. We prove the theorem subject to the assumption that the Lie algebra is Noetherian as an `R`-module, though actually we only need the slightly weaker property that the relation `>` is well-founded on the complete lattice of Lie subalgebras. ## Remarks about the proof Engel's theorem is usually proved in the special case that the coefficients are a field, and uses an inductive argument on the dimension of the Lie algebra. One begins by choosing either a maximal proper Lie subalgebra (in some proofs) or a maximal nilpotent Lie subalgebra (in other proofs, at the cost of obtaining a weaker end result). Since we work with general coefficients, we cannot induct on dimension and an alternate approach must be taken. The key ingredient is the concept of nilpotency, not just for Lie algebras, but for Lie modules. Using this concept, we define an _Engelian Lie algebra_ `LieAlgebra.IsEngelian` to be one for which a Lie module is nilpotent whenever the action consists of nilpotent endomorphisms. The argument then proceeds by selecting a maximal Engelian Lie subalgebra and showing that it cannot be proper. The first part of the traditional statement of Engel's theorem consists of the statement that if `M` is a non-trivial `R`-module and `L ⊆ End(M)` is a finite-dimensional Lie subalgebra of nilpotent elements, then there exists a non-zero element `m : M` that is annihilated by every element of `L`. This follows trivially from the result established here `LieModule.isNilpotent_iff_forall`, that `M` is a nilpotent Lie module over `L`, since the last non-zero term in the lower central series will consist of such elements `m` (see: `LieModule.nontrivial_max_triv_of_isNilpotent`). It seems that this result has not previously been established at this level of generality. The second part of the traditional statement of Engel's theorem concerns nilpotency of the Lie algebra and a proof of this for general coefficients appeared in the literature as long ago [as 1937](zorn1937). This also follows trivially from `LieModule.isNilpotent_iff_forall` simply by taking `M = L`. It is pleasing that the two parts of the traditional statements of Engel's theorem are thus unified into a single statement about nilpotency of Lie modules. This is not usually emphasised. ## Main definitions * `LieAlgebra.IsEngelian` * `LieAlgebra.isEngelian_of_isNoetherian` * `LieModule.isNilpotent_iff_forall` * `LieAlgebra.isNilpotent_iff_forall` -/ universe u₁ u₂ u₃ u₄ variable {R : Type u₁} {L : Type u₂} {L₂ : Type u₃} {M : Type u₄} variable [CommRing R] [LieRing L] [LieAlgebra R L] [LieRing L₂] [LieAlgebra R L₂] variable [AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M] namespace LieSubmodule open LieModule variable {I : LieIdeal R L} {x : L} (hxI : (R ∙ x) ⊔ I = ⊤) include hxI theorem exists_smul_add_of_span_sup_eq_top (y : L) : ∃ t : R, ∃ z ∈ I, y = t • x + z := by have hy : y ∈ (⊤ : Submodule R L) := Submodule.mem_top simp only [← hxI, Submodule.mem_sup, Submodule.mem_span_singleton] at hy obtain ⟨-, ⟨t, rfl⟩, z, hz, rfl⟩ := hy exact ⟨t, z, hz, rfl⟩ theorem lie_top_eq_of_span_sup_eq_top (N : LieSubmodule R L M) : (↑⁅(⊤ : LieIdeal R L), N⁆ : Submodule R M) = (N : Submodule R M).map (toEnd R L M x) ⊔ (↑⁅I, N⁆ : Submodule R M) := by simp only [lieIdeal_oper_eq_linear_span', Submodule.sup_span, mem_top, true_and, Submodule.map_coe, toEnd_apply_apply] refine le_antisymm (Submodule.span_le.mpr ?_) (Submodule.span_mono fun z hz => ?_) · rintro z ⟨y, n, hn : n ∈ N, rfl⟩ obtain ⟨t, z, hz, rfl⟩ := exists_smul_add_of_span_sup_eq_top hxI y simp only [SetLike.mem_coe, Submodule.span_union, Submodule.mem_sup] exact ⟨t • ⁅x, n⁆, Submodule.subset_span ⟨t • n, N.smul_mem' t hn, lie_smul t x n⟩, ⁅z, n⁆, Submodule.subset_span ⟨z, hz, n, hn, rfl⟩, by simp⟩ · rcases hz with (⟨m, hm, rfl⟩ | ⟨y, -, m, hm, rfl⟩) exacts [⟨x, m, hm, rfl⟩, ⟨y, m, hm, rfl⟩] theorem lcs_le_lcs_of_is_nilpotent_span_sup_eq_top {n i j : ℕ} (hxn : toEnd R L M x ^ n = 0) (hIM : lowerCentralSeries R L M i ≤ I.lcs M j) : lowerCentralSeries R L M (i + n) ≤ I.lcs M (j + 1) := by suffices ∀ l, ((⊤ : LieIdeal R L).lcs M (i + l) : Submodule R M) ≤ (I.lcs M j : Submodule R M).map (toEnd R L M x ^ l) ⊔ (I.lcs M (j + 1) : Submodule R M) by simpa only [bot_sup_eq, LieIdeal.incl_coe, Submodule.map_zero, hxn] using this n intro l induction l with | zero => simp only [add_zero, LieIdeal.lcs_succ, pow_zero, Module.End.one_eq_id, Submodule.map_id] exact le_sup_of_le_left hIM | succ l ih => simp only [LieIdeal.lcs_succ, i.add_succ l, lie_top_eq_of_span_sup_eq_top hxI, sup_le_iff] refine ⟨(Submodule.map_mono ih).trans ?_, le_sup_of_le_right ?_⟩ · rw [Submodule.map_sup, ← Submodule.map_comp, ← Module.End.mul_eq_comp, ← pow_succ', ← I.lcs_succ] grw [coe_map_toEnd_le] · norm_cast gcongr exact le_trans (antitone_lowerCentralSeries R L M le_self_add) hIM theorem isNilpotentOfIsNilpotentSpanSupEqTop (hnp : IsNilpotent <| toEnd R L M x) (hIM : IsNilpotent I M) : IsNilpotent L M := by obtain ⟨n, hn⟩ := hnp obtain ⟨k, hk⟩ := IsNilpotent.nilpotent R I M have hk' : I.lcs M k = ⊥ := by simp only [← toSubmodule_inj, I.coe_lcs_eq, hk, bot_toSubmodule] suffices ∀ l, lowerCentralSeries R L M (l * n) ≤ I.lcs M l by rw [isNilpotent_iff R] use k * n simpa [hk'] using this k intro l induction l with | zero => simp | succ l ih => exact (l.succ_mul n).symm ▸ lcs_le_lcs_of_is_nilpotent_span_sup_eq_top hxI hn ih end LieSubmodule section LieAlgebra open LieModule hiding IsNilpotent variable (R L) /-- A Lie algebra `L` is said to be Engelian if a sufficient condition for any `L`-Lie module `M` to be nilpotent is that the image of the map `L → End(M)` consists of nilpotent elements. Engel's theorem `LieAlgebra.isEngelian_of_isNoetherian` states that any Noetherian Lie algebra is Engelian. -/ def LieAlgebra.IsEngelian : Prop := ∀ (M : Type u₄) [AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M], (∀ x : L, IsNilpotent (toEnd R L M x)) → LieModule.IsNilpotent L M variable {R L} theorem LieAlgebra.isEngelian_of_subsingleton [Subsingleton L] : LieAlgebra.IsEngelian R L := by intro M _i1 _i2 _i3 _i4 _h use 1 simp theorem Function.Surjective.isEngelian {f : L →ₗ⁅R⁆ L₂} (hf : Function.Surjective f) (h : LieAlgebra.IsEngelian.{u₁, u₂, u₄} R L) : LieAlgebra.IsEngelian.{u₁, u₃, u₄} R L₂ := by intro M _i1 _i2 _i3 _i4 h' letI : LieRingModule L M := LieRingModule.compLieHom M f letI : LieModule R L M := compLieHom M f have hnp : ∀ x, IsNilpotent (toEnd R L M x) := fun x => h' (f x) have surj_id : Function.Surjective (LinearMap.id : M →ₗ[R] M) := Function.surjective_id haveI : LieModule.IsNilpotent L M := h M hnp apply hf.lieModuleIsNilpotent _ surj_id aesop theorem LieEquiv.isEngelian_iff (e : L ≃ₗ⁅R⁆ L₂) : LieAlgebra.IsEngelian.{u₁, u₂, u₄} R L ↔ LieAlgebra.IsEngelian.{u₁, u₃, u₄} R L₂ := ⟨e.surjective.isEngelian, e.symm.surjective.isEngelian⟩ theorem LieAlgebra.exists_engelian_lieSubalgebra_of_lt_normalizer {K : LieSubalgebra R L} (hK₁ : LieAlgebra.IsEngelian.{u₁, u₂, u₄} R K) (hK₂ : K < K.normalizer) : ∃ (K' : LieSubalgebra R L), LieAlgebra.IsEngelian.{u₁, u₂, u₄} R K' ∧ K < K' := by obtain ⟨x, hx₁, hx₂⟩ := SetLike.exists_of_lt hK₂ let K' : LieSubalgebra R L := { (R ∙ x) ⊔ (K : Submodule R L) with lie_mem' := fun {y z} => LieSubalgebra.lie_mem_sup_of_mem_normalizer hx₁ } have hxK' : x ∈ K' := Submodule.mem_sup_left (Submodule.subset_span (Set.mem_singleton _)) have hKK' : K ≤ K' := (LieSubalgebra.toSubmodule_le_toSubmodule K K').mp le_sup_right have hK' : K' ≤ K.normalizer := by rw [← LieSubalgebra.toSubmodule_le_toSubmodule] exact sup_le ((Submodule.span_singleton_le_iff_mem _ _).mpr hx₁) hK₂.le refine ⟨K', ?_, lt_iff_le_and_ne.mpr ⟨hKK', fun contra => hx₂ (contra.symm ▸ hxK')⟩⟩ intro M _i1 _i2 _i3 _i4 h obtain ⟨I, hI₁ : (I : LieSubalgebra R K') = LieSubalgebra.ofLe hKK'⟩ := LieSubalgebra.exists_nested_lieIdeal_ofLe_normalizer hKK' hK' have hI₂ : (R ∙ (⟨x, hxK'⟩ : K')) ⊔ (LieSubmodule.toSubmodule I) = ⊤ := by rw [← LieIdeal.toLieSubalgebra_toSubmodule R K' I, hI₁] apply Submodule.map_injective_of_injective (K' : Submodule R L).injective_subtype simp only [LieSubalgebra.coe_ofLe, Submodule.map_sup, Submodule.map_subtype_range_inclusion, Submodule.map_top, Submodule.range_subtype] rw [Submodule.map_subtype_span_singleton] have e : K ≃ₗ⁅R⁆ I := (LieSubalgebra.equivOfLe hKK').trans (LieEquiv.ofEq _ _ ((LieSubalgebra.coe_set_eq _ _).mpr hI₁.symm)) have hI₃ : LieAlgebra.IsEngelian R I := e.isEngelian_iff.mp hK₁ exact LieSubmodule.isNilpotentOfIsNilpotentSpanSupEqTop hI₂ (h _) (hI₃ _ fun x => h x) attribute [local instance] LieSubalgebra.subsingleton_bot /-- *Engel's theorem*. Note that this implies all traditional forms of Engel's theorem via `LieModule.nontrivial_max_triv_of_isNilpotent`, `LieModule.isNilpotent_iff_forall`, `LieAlgebra.isNilpotent_iff_forall`. -/ theorem LieAlgebra.isEngelian_of_isNoetherian [IsNoetherian R L] : LieAlgebra.IsEngelian R L := by intro M _i1 _i2 _i3 _i4 h rw [← isNilpotent_range_toEnd_iff R] let L' := (toEnd R L M).range replace h : ∀ y : L', IsNilpotent (y : Module.End R M) := by rintro ⟨-, ⟨y, rfl⟩⟩ simp [h] change LieModule.IsNilpotent L' M let s := {K : LieSubalgebra R L' | LieAlgebra.IsEngelian R K} have hs : s.Nonempty := ⟨⊥, LieAlgebra.isEngelian_of_subsingleton⟩ suffices ⊤ ∈ s by rw [← isNilpotent_of_top_iff (R := R)] apply this M simp [LieSubalgebra.toEnd_eq, h] have : ∀ K ∈ s, K ≠ ⊤ → ∃ K' ∈ s, K < K' := by rintro K (hK₁ : LieAlgebra.IsEngelian R K) hK₂ apply LieAlgebra.exists_engelian_lieSubalgebra_of_lt_normalizer hK₁ apply lt_of_le_of_ne K.le_normalizer rw [Ne, eq_comm, K.normalizer_eq_self_iff, ← Ne, ← LieSubmodule.nontrivial_iff_ne_bot R K] have : Nontrivial (L' ⧸ K.toLieSubmodule) := by replace hK₂ : K.toLieSubmodule ≠ ⊤ := by rwa [Ne, ← LieSubmodule.toSubmodule_inj, K.coe_toLieSubmodule, LieSubmodule.top_toSubmodule, ← LieSubalgebra.top_toSubmodule, K.toSubmodule_inj] exact Submodule.Quotient.nontrivial_of_lt_top _ hK₂.lt_top have : LieModule.IsNilpotent K (L' ⧸ K.toLieSubmodule) := by refine hK₁ _ fun x => ?_ have hx := LieAlgebra.isNilpotent_ad_of_isNilpotent (h x) apply Module.End.IsNilpotent.mapQ ?_ hx intro X HX simp only [LieSubalgebra.coe_toLieSubmodule, LieSubalgebra.mem_toSubmodule] at HX simp only [LieSubalgebra.coe_toLieSubmodule, Submodule.mem_comap, ad_apply, LieSubalgebra.mem_toSubmodule] exact LieSubalgebra.lie_mem K x.prop HX exact nontrivial_max_triv_of_isNilpotent R K (L' ⧸ K.toLieSubmodule) haveI _i5 : IsNoetherian R L' := by refine isNoetherian_of_surjective L (LieHom.rangeRestrict (toEnd R L M)) ?_ simp only [LinearMap.range_eq_top] exact LieHom.surjective_rangeRestrict (toEnd R L M) obtain ⟨K, hK₁, hK₂⟩ := (LieSubalgebra.wellFoundedGT_of_noetherian R L').wf.has_min s hs obtain rfl : K = ⊤ := by grind exact hK₁ /-- Engel's theorem. See also `LieModule.isNilpotent_iff_forall'` which assumes that `M` is Noetherian instead of `L`. -/ theorem LieModule.isNilpotent_iff_forall [IsNoetherian R L] : LieModule.IsNilpotent L M ↔ ∀ x, _root_.IsNilpotent <| toEnd R L M x := ⟨fun _ ↦ isNilpotent_toEnd_of_isNilpotent R L M, fun h => LieAlgebra.isEngelian_of_isNoetherian M h⟩ /-- Engel's theorem. -/ theorem LieModule.isNilpotent_iff_forall' [IsNoetherian R M] : LieModule.IsNilpotent L M ↔ ∀ x, _root_.IsNilpotent <| toEnd R L M x := by rw [← isNilpotent_range_toEnd_iff (R := R), LieModule.isNilpotent_iff_forall (R := R)]; simp /-- Engel's theorem. -/ theorem LieAlgebra.isNilpotent_iff_forall [IsNoetherian R L] : LieRing.IsNilpotent L ↔ ∀ x, IsNilpotent <| LieAlgebra.ad R L x := LieModule.isNilpotent_iff_forall end LieAlgebra
.lake/packages/mathlib/Mathlib/Algebra/Lie/Submodule.lean
import Mathlib.Algebra.Lie.Subalgebra import Mathlib.LinearAlgebra.Finsupp.Span /-! # Lie submodules of a Lie algebra In this file we define Lie submodules, we construct the lattice structure on Lie submodules and we use it to define various important operations, notably the Lie span of a subset of a Lie module. ## Main definitions * `LieSubmodule` * `LieSubmodule.wellFounded_of_noetherian` * `LieSubmodule.lieSpan` * `LieSubmodule.map` * `LieSubmodule.comap` ## Tags lie algebra, lie submodule, lie ideal, lattice structure -/ universe u v w w₁ w₂ section LieSubmodule variable (R : Type u) (L : Type v) (M : Type w) variable [CommRing R] [LieRing L] [AddCommGroup M] [Module R M] variable [LieRingModule L M] /-- A Lie submodule of a Lie module is a submodule that is closed under the Lie bracket. This is a sufficient condition for the subset itself to form a Lie module. -/ structure LieSubmodule extends Submodule R M where lie_mem : ∀ {x : L} {m : M}, m ∈ carrier → ⁅x, m⁆ ∈ carrier attribute [nolint docBlame] LieSubmodule.toSubmodule attribute [coe] LieSubmodule.toSubmodule namespace LieSubmodule variable {R L M} variable (N N' : LieSubmodule R L M) instance : SetLike (LieSubmodule R L M) M where coe s := s.carrier coe_injective' N O h := by cases N; cases O; congr; exact SetLike.coe_injective' h instance : AddSubgroupClass (LieSubmodule R L M) M where add_mem {N} _ _ := N.add_mem' zero_mem N := N.zero_mem' neg_mem {N} x hx := show -x ∈ N.toSubmodule from neg_mem hx instance instSMulMemClass : SMulMemClass (LieSubmodule R L M) R M where smul_mem {s} c _ h := s.smul_mem' c h /-- The zero module is a Lie submodule of any Lie module. -/ instance : Zero (LieSubmodule R L M) := ⟨{ (0 : Submodule R M) with lie_mem := fun {x m} h ↦ by rw [(Submodule.mem_bot R).1 h]; apply lie_zero }⟩ instance : Inhabited (LieSubmodule R L M) := ⟨0⟩ instance (priority := high) coeSort : CoeSort (LieSubmodule R L M) (Type w) where coe N := { x : M // x ∈ N } instance (priority := mid) coeSubmodule : CoeOut (LieSubmodule R L M) (Submodule R M) := ⟨toSubmodule⟩ instance : CanLift (Submodule R M) (LieSubmodule R L M) (·) (fun N ↦ ∀ {x : L} {m : M}, m ∈ N → ⁅x, m⁆ ∈ N) where prf N hN := ⟨⟨N, hN⟩, rfl⟩ @[norm_cast] theorem coe_toSubmodule : ((N : Submodule R M) : Set M) = N := rfl theorem mem_carrier {x : M} : x ∈ N.carrier ↔ x ∈ (N : Set M) := Iff.rfl theorem mem_mk_iff (S : Set M) (h₁ h₂ h₃ h₄) {x : M} : x ∈ (⟨⟨⟨⟨S, h₁⟩, h₂⟩, h₃⟩, h₄⟩ : LieSubmodule R L M) ↔ x ∈ S := Iff.rfl @[simp] theorem mem_mk_iff' (p : Submodule R M) (h) {x : M} : x ∈ (⟨p, h⟩ : LieSubmodule R L M) ↔ x ∈ p := Iff.rfl @[simp] theorem mem_toSubmodule {x : M} : x ∈ (N : Submodule R M) ↔ x ∈ N := Iff.rfl theorem mem_coe {x : M} : x ∈ (N : Set M) ↔ x ∈ N := Iff.rfl protected theorem zero_mem : (0 : M) ∈ N := zero_mem N @[simp] theorem mk_eq_zero {x} (h : x ∈ N) : (⟨x, h⟩ : N) = 0 ↔ x = 0 := Subtype.ext_iff @[simp] theorem coe_toSet_mk (S : Set M) (h₁ h₂ h₃ h₄) : ((⟨⟨⟨⟨S, h₁⟩, h₂⟩, h₃⟩, h₄⟩ : LieSubmodule R L M) : Set M) = S := rfl theorem toSubmodule_mk (p : Submodule R M) (h) : (({ p with lie_mem := h } : LieSubmodule R L M) : Submodule R M) = p := by cases p; rfl theorem toSubmodule_injective : Function.Injective (toSubmodule : LieSubmodule R L M → Submodule R M) := fun x y h ↦ by cases x; cases y; congr @[ext] theorem ext (h : ∀ m, m ∈ N ↔ m ∈ N') : N = N' := SetLike.ext h @[simp] theorem toSubmodule_inj : (N : Submodule R M) = (N' : Submodule R M) ↔ N = N' := toSubmodule_injective.eq_iff /-- Copy of a `LieSubmodule` with a new `carrier` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (s : Set M) (hs : s = ↑N) : LieSubmodule R L M where carrier := s zero_mem' := by simp [hs] add_mem' x y := by rw [hs] at x y ⊢; exact N.add_mem' x y smul_mem' := by exact hs.symm ▸ N.smul_mem' lie_mem := by exact hs.symm ▸ N.lie_mem @[simp, norm_cast] theorem coe_copy (S : LieSubmodule R L M) (s : Set M) (hs : s = ↑S) : (S.copy s hs : Set M) = s := rfl theorem copy_eq (S : LieSubmodule R L M) (s : Set M) (hs : s = ↑S) : S.copy s hs = S := SetLike.coe_injective hs instance : LieRingModule L N where bracket (x : L) (m : N) := ⟨⁅x, m.val⁆, N.lie_mem m.property⟩ add_lie := by intro x y m; apply SetCoe.ext; apply add_lie lie_add := by intro x m n; apply SetCoe.ext; apply lie_add leibniz_lie := by intro x y m; apply SetCoe.ext; apply leibniz_lie @[simp, norm_cast] theorem coe_zero : ((0 : N) : M) = (0 : M) := rfl @[simp, norm_cast] theorem coe_add (m m' : N) : (↑(m + m') : M) = (m : M) + (m' : M) := rfl @[simp, norm_cast] theorem coe_neg (m : N) : (↑(-m) : M) = -(m : M) := rfl @[simp, norm_cast] theorem coe_sub (m m' : N) : (↑(m - m') : M) = (m : M) - (m' : M) := rfl @[simp, norm_cast] theorem coe_smul (t : R) (m : N) : (↑(t • m) : M) = t • (m : M) := rfl @[simp, norm_cast] theorem coe_bracket (x : L) (m : N) : (↑⁅x, m⁆ : M) = ⁅x, ↑m⁆ := rfl -- Copying instances from `Submodule` for correct discrimination keys instance [IsNoetherian R M] (N : LieSubmodule R L M) : IsNoetherian R N := inferInstanceAs <| IsNoetherian R N.toSubmodule instance [IsArtinian R M] (N : LieSubmodule R L M) : IsArtinian R N := inferInstanceAs <| IsArtinian R N.toSubmodule instance [NoZeroSMulDivisors R M] : NoZeroSMulDivisors R N := inferInstanceAs <| NoZeroSMulDivisors R N.toSubmodule variable [LieAlgebra R L] [LieModule R L M] instance instLieModule : LieModule R L N where lie_smul := by intro t x y; apply SetCoe.ext; apply lie_smul smul_lie := by intro t x y; apply SetCoe.ext; apply smul_lie instance [Subsingleton M] : Unique (LieSubmodule R L M) := ⟨⟨0⟩, fun _ ↦ (toSubmodule_inj _ _).mp (Subsingleton.elim _ _)⟩ end LieSubmodule variable {R M} theorem Submodule.exists_lieSubmodule_coe_eq_iff (p : Submodule R M) : (∃ N : LieSubmodule R L M, ↑N = p) ↔ ∀ (x : L) (m : M), m ∈ p → ⁅x, m⁆ ∈ p := by constructor · rintro ⟨N, rfl⟩ _ _; exact N.lie_mem · intro h; use { p with lie_mem := @h } namespace LieSubalgebra variable {L} variable [LieAlgebra R L] variable (K : LieSubalgebra R L) /-- Given a Lie subalgebra `K ⊆ L`, if we view `L` as a `K`-module by restriction, it contains a distinguished Lie submodule for the action of `K`, namely `K` itself. -/ def toLieSubmodule : LieSubmodule R K L := { (K : Submodule R L) with lie_mem := fun {x _} hy ↦ K.lie_mem x.property hy } @[simp] theorem coe_toLieSubmodule : (K.toLieSubmodule : Submodule R L) = K := rfl variable {K} @[simp] theorem mem_toLieSubmodule (x : L) : x ∈ K.toLieSubmodule ↔ x ∈ K := Iff.rfl end LieSubalgebra end LieSubmodule namespace LieSubmodule variable {R : Type u} {L : Type v} {M : Type w} variable [CommRing R] [LieRing L] [AddCommGroup M] [Module R M] variable [LieRingModule L M] variable (N N' : LieSubmodule R L M) section LatticeStructure open Set theorem coe_injective : Function.Injective ((↑) : LieSubmodule R L M → Set M) := SetLike.coe_injective @[simp, norm_cast] theorem toSubmodule_le_toSubmodule : (N : Submodule R M) ≤ N' ↔ N ≤ N' := Iff.rfl instance : Bot (LieSubmodule R L M) := ⟨0⟩ instance instUniqueBot : Unique (⊥ : LieSubmodule R L M) := inferInstanceAs <| Unique (⊥ : Submodule R M) @[simp] theorem bot_coe : ((⊥ : LieSubmodule R L M) : Set M) = {0} := rfl @[simp] theorem bot_toSubmodule : ((⊥ : LieSubmodule R L M) : Submodule R M) = ⊥ := rfl @[simp] theorem toSubmodule_eq_bot : (N : Submodule R M) = ⊥ ↔ N = ⊥ := by rw [← toSubmodule_inj, bot_toSubmodule] @[simp] theorem mk_eq_bot_iff {N : Submodule R M} {h} : (⟨N, h⟩ : LieSubmodule R L M) = ⊥ ↔ N = ⊥ := by rw [← toSubmodule_inj, bot_toSubmodule] @[simp] theorem mem_bot (x : M) : x ∈ (⊥ : LieSubmodule R L M) ↔ x = 0 := mem_singleton_iff instance : Top (LieSubmodule R L M) := ⟨{ (⊤ : Submodule R M) with lie_mem := fun {x m} _ ↦ mem_univ ⁅x, m⁆ }⟩ @[simp] theorem top_coe : ((⊤ : LieSubmodule R L M) : Set M) = univ := rfl @[simp] theorem top_toSubmodule : ((⊤ : LieSubmodule R L M) : Submodule R M) = ⊤ := rfl @[simp] theorem toSubmodule_eq_top : (N : Submodule R M) = ⊤ ↔ N = ⊤ := by rw [← toSubmodule_inj, top_toSubmodule] @[simp] theorem mk_eq_top_iff {N : Submodule R M} {h} : (⟨N, h⟩ : LieSubmodule R L M) = ⊤ ↔ N = ⊤ := by rw [← toSubmodule_inj, top_toSubmodule] @[simp] theorem mem_top (x : M) : x ∈ (⊤ : LieSubmodule R L M) := mem_univ x instance : Min (LieSubmodule R L M) := ⟨fun N N' ↦ { (N ⊓ N' : Submodule R M) with lie_mem := fun h ↦ mem_inter (N.lie_mem h.1) (N'.lie_mem h.2) }⟩ instance : InfSet (LieSubmodule R L M) := ⟨fun S ↦ { toSubmodule := sInf {(s : Submodule R M) | s ∈ S} lie_mem := fun {x m} h ↦ by simp only [Submodule.mem_carrier, mem_iInter, Submodule.coe_sInf, mem_setOf_eq, forall_apply_eq_imp_iff₂, forall_exists_index, and_imp] at h ⊢ intro N hN; apply N.lie_mem (h N hN) }⟩ @[simp] theorem coe_inf : (↑(N ⊓ N') : Set M) = ↑N ∩ ↑N' := rfl @[deprecated (since := "2025-08-31")] alias inf_coe := coe_inf @[norm_cast, simp] theorem inf_toSubmodule : (↑(N ⊓ N') : Submodule R M) = (N : Submodule R M) ⊓ (N' : Submodule R M) := rfl @[simp] theorem sInf_toSubmodule (S : Set (LieSubmodule R L M)) : (↑(sInf S) : Submodule R M) = sInf {(s : Submodule R M) | s ∈ S} := rfl theorem sInf_toSubmodule_eq_iInf (S : Set (LieSubmodule R L M)) : (↑(sInf S) : Submodule R M) = ⨅ N ∈ S, (N : Submodule R M) := by rw [sInf_toSubmodule, ← Set.image, sInf_image] @[simp] theorem iInf_toSubmodule {ι} (p : ι → LieSubmodule R L M) : (↑(⨅ i, p i) : Submodule R M) = ⨅ i, (p i : Submodule R M) := by rw [iInf, sInf_toSubmodule]; ext; simp @[simp] theorem coe_sInf (S : Set (LieSubmodule R L M)) : (↑(sInf S) : Set M) = ⋂ s ∈ S, (s : Set M) := by rw [← LieSubmodule.coe_toSubmodule, sInf_toSubmodule, Submodule.coe_sInf] ext m simp only [mem_iInter, mem_setOf_eq, forall_apply_eq_imp_iff₂, exists_imp, and_imp, SetLike.mem_coe, mem_toSubmodule] @[deprecated (since := "2025-08-31")] alias sInf_coe := coe_sInf @[simp] theorem coe_iInf {ι} (p : ι → LieSubmodule R L M) : (↑(⨅ i, p i) : Set M) = ⋂ i, ↑(p i) := by rw [iInf, coe_sInf]; simp only [Set.mem_range, Set.iInter_exists, Set.iInter_iInter_eq'] @[deprecated (since := "2025-08-31")] alias iInf_coe := coe_iInf @[simp] theorem mem_iInf {ι} (p : ι → LieSubmodule R L M) {x} : (x ∈ ⨅ i, p i) ↔ ∀ i, x ∈ p i := by rw [← SetLike.mem_coe, coe_iInf, Set.mem_iInter]; rfl instance : Max (LieSubmodule R L M) where max N N' := { toSubmodule := (N : Submodule R M) ⊔ (N' : Submodule R M) lie_mem := by rintro x m (hm : m ∈ (N : Submodule R M) ⊔ (N' : Submodule R M)) change ⁅x, m⁆ ∈ (N : Submodule R M) ⊔ (N' : Submodule R M) rw [Submodule.mem_sup] at hm ⊢ obtain ⟨y, hy, z, hz, rfl⟩ := hm exact ⟨⁅x, y⁆, N.lie_mem hy, ⁅x, z⁆, N'.lie_mem hz, (lie_add _ _ _).symm⟩ } instance : SupSet (LieSubmodule R L M) where sSup S := { toSubmodule := sSup {(p : Submodule R M) | p ∈ S} lie_mem := by intro x m (hm : m ∈ sSup {(p : Submodule R M) | p ∈ S}) change ⁅x, m⁆ ∈ sSup {(p : Submodule R M) | p ∈ S} obtain ⟨s, hs, hsm⟩ := Submodule.mem_sSup_iff_exists_finset.mp hm clear hm classical induction s using Finset.induction_on generalizing m with | empty => replace hsm : m = 0 := by simpa using hsm simp [hsm] | insert q t hqt ih => rw [Finset.iSup_insert] at hsm obtain ⟨m', hm', u, hu, rfl⟩ := Submodule.mem_sup.mp hsm rw [lie_add] refine add_mem ?_ (ih (Subset.trans (by simp) hs) hu) obtain ⟨p, hp, rfl⟩ : ∃ p ∈ S, ↑p = q := hs (Finset.mem_insert_self q t) suffices p ≤ sSup {(p : Submodule R M) | p ∈ S} by exact this (p.lie_mem hm') exact le_sSup ⟨p, hp, rfl⟩ } @[norm_cast, simp] theorem sup_toSubmodule : (↑(N ⊔ N') : Submodule R M) = (N : Submodule R M) ⊔ (N' : Submodule R M) := by rfl @[simp] theorem sSup_toSubmodule (S : Set (LieSubmodule R L M)) : (↑(sSup S) : Submodule R M) = sSup {(s : Submodule R M) | s ∈ S} := rfl theorem sSup_toSubmodule_eq_iSup (S : Set (LieSubmodule R L M)) : (↑(sSup S) : Submodule R M) = ⨆ N ∈ S, (N : Submodule R M) := by rw [sSup_toSubmodule, ← Set.image, sSup_image] @[simp] theorem iSup_toSubmodule {ι} (p : ι → LieSubmodule R L M) : (↑(⨆ i, p i) : Submodule R M) = ⨆ i, (p i : Submodule R M) := by rw [iSup, sSup_toSubmodule]; ext; simp [Submodule.mem_sSup, Submodule.mem_iSup] /-- The set of Lie submodules of a Lie module form a complete lattice. -/ instance : CompleteLattice (LieSubmodule R L M) := { toSubmodule_injective.completeLattice toSubmodule sup_toSubmodule inf_toSubmodule sSup_toSubmodule_eq_iSup sInf_toSubmodule_eq_iInf rfl rfl with toPartialOrder := SetLike.instPartialOrder } theorem mem_iSup_of_mem {ι} {b : M} {N : ι → LieSubmodule R L M} (i : ι) (h : b ∈ N i) : b ∈ ⨆ i, N i := (le_iSup N i) h @[elab_as_elim] lemma iSup_induction {ι} (N : ι → LieSubmodule R L M) {motive : M → Prop} {x : M} (hx : x ∈ ⨆ i, N i) (mem : ∀ i, ∀ y ∈ N i, motive y) (zero : motive 0) (add : ∀ y z, motive y → motive z → motive (y + z)) : motive x := by rw [← LieSubmodule.mem_toSubmodule, LieSubmodule.iSup_toSubmodule] at hx exact Submodule.iSup_induction (motive := motive) (fun i ↦ (N i : Submodule R M)) hx mem zero add @[elab_as_elim] theorem iSup_induction' {ι} (N : ι → LieSubmodule R L M) {motive : (x : M) → (x ∈ ⨆ i, N i) → Prop} (mem : ∀ (i) (x) (hx : x ∈ N i), motive x (mem_iSup_of_mem i hx)) (zero : motive 0 (zero_mem _)) (add : ∀ x y hx hy, motive x hx → motive y hy → motive (x + y) (add_mem ‹_› ‹_›)) {x : M} (hx : x ∈ ⨆ i, N i) : motive x hx := by refine Exists.elim ?_ fun (hx : x ∈ ⨆ i, N i) (hc : motive x hx) => hc refine iSup_induction N (motive := fun x : M ↦ ∃ (hx : x ∈ ⨆ i, N i), motive x hx) hx (fun i x hx => ?_) ?_ fun x y => ?_ · exact ⟨_, mem _ _ hx⟩ · exact ⟨_, zero⟩ · rintro ⟨_, Cx⟩ ⟨_, Cy⟩ exact ⟨_, add _ _ _ _ Cx Cy⟩ variable {N N'} @[simp] lemma disjoint_toSubmodule : Disjoint (N : Submodule R M) (N' : Submodule R M) ↔ Disjoint N N' := by rw [disjoint_iff, disjoint_iff, ← toSubmodule_inj, inf_toSubmodule, bot_toSubmodule, ← disjoint_iff] @[simp] lemma codisjoint_toSubmodule : Codisjoint (N : Submodule R M) (N' : Submodule R M) ↔ Codisjoint N N' := by rw [codisjoint_iff, codisjoint_iff, ← toSubmodule_inj, sup_toSubmodule, top_toSubmodule, ← codisjoint_iff] @[simp] lemma isCompl_toSubmodule : IsCompl (N : Submodule R M) (N' : Submodule R M) ↔ IsCompl N N' := by simp [isCompl_iff] @[simp] lemma iSupIndep_toSubmodule {ι : Type*} {N : ι → LieSubmodule R L M} : iSupIndep (fun i ↦ (N i : Submodule R M)) ↔ iSupIndep N := by simp [iSupIndep_def, ← disjoint_toSubmodule] @[simp] lemma iSup_toSubmodule_eq_top {ι : Sort*} {N : ι → LieSubmodule R L M} : ⨆ i, (N i : Submodule R M) = ⊤ ↔ ⨆ i, N i = ⊤ := by rw [← iSup_toSubmodule, ← top_toSubmodule (L := L), toSubmodule_inj] instance : Add (LieSubmodule R L M) where add := max instance : Zero (LieSubmodule R L M) where zero := ⊥ instance : AddCommMonoid (LieSubmodule R L M) where add_assoc := sup_assoc zero_add := bot_sup_eq add_zero := sup_bot_eq add_comm := sup_comm nsmul := nsmulRec variable (N N') @[simp] theorem add_eq_sup : N + N' = N ⊔ N' := rfl @[simp] theorem mem_inf (x : M) : x ∈ N ⊓ N' ↔ x ∈ N ∧ x ∈ N' := by rw [← mem_toSubmodule, ← mem_toSubmodule, ← mem_toSubmodule, inf_toSubmodule, Submodule.mem_inf] theorem mem_sup (x : M) : x ∈ N ⊔ N' ↔ ∃ y ∈ N, ∃ z ∈ N', y + z = x := by rw [← mem_toSubmodule, sup_toSubmodule, Submodule.mem_sup]; exact Iff.rfl nonrec theorem eq_bot_iff : N = ⊥ ↔ ∀ m : M, m ∈ N → m = 0 := by rw [eq_bot_iff]; exact Iff.rfl instance subsingleton_of_bot : Subsingleton (LieSubmodule R L (⊥ : LieSubmodule R L M)) := by apply subsingleton_of_bot_eq_top subsingleton instance : IsModularLattice (LieSubmodule R L M) where sup_inf_le_assoc_of_le _ _ := by simp only [← toSubmodule_le_toSubmodule, sup_toSubmodule, inf_toSubmodule] exact IsModularLattice.sup_inf_le_assoc_of_le _ variable (R L M) /-- The natural functor that forgets the action of `L` as an order embedding. -/ @[simps] def toSubmodule_orderEmbedding : LieSubmodule R L M ↪o Submodule R M := { toFun := (↑) inj' := toSubmodule_injective map_rel_iff' := Iff.rfl } instance wellFoundedGT_of_noetherian [IsNoetherian R M] : WellFoundedGT (LieSubmodule R L M) := RelHomClass.isWellFounded (toSubmodule_orderEmbedding R L M).dual.ltEmbedding theorem wellFoundedLT_of_isArtinian [IsArtinian R M] : WellFoundedLT (LieSubmodule R L M) := RelHomClass.isWellFounded (toSubmodule_orderEmbedding R L M).ltEmbedding instance [IsArtinian R M] : IsAtomic (LieSubmodule R L M) := isAtomic_of_orderBot_wellFounded_lt <| (wellFoundedLT_of_isArtinian R L M).wf @[simp] theorem subsingleton_iff : Subsingleton (LieSubmodule R L M) ↔ Subsingleton M := have h : Subsingleton (LieSubmodule R L M) ↔ Subsingleton (Submodule R M) := by rw [← subsingleton_iff_bot_eq_top, ← subsingleton_iff_bot_eq_top, ← toSubmodule_inj, top_toSubmodule, bot_toSubmodule] h.trans <| Submodule.subsingleton_iff R @[simp] theorem nontrivial_iff : Nontrivial (LieSubmodule R L M) ↔ Nontrivial M := not_iff_not.mp ((not_nontrivial_iff_subsingleton.trans <| subsingleton_iff R L M).trans not_nontrivial_iff_subsingleton.symm) instance [Nontrivial M] : Nontrivial (LieSubmodule R L M) := (nontrivial_iff R L M).mpr ‹_› theorem nontrivial_iff_ne_bot {N : LieSubmodule R L M} : Nontrivial N ↔ N ≠ ⊥ := by constructor <;> contrapose! · rintro rfl by_contra! h; rcases h with ⟨⟨m₁, h₁ : m₁ ∈ (⊥ : LieSubmodule R L M)⟩, ⟨m₂, h₂ : m₂ ∈ (⊥ : LieSubmodule R L M)⟩, h₁₂⟩ simp [(LieSubmodule.mem_bot _).mp h₁, (LieSubmodule.mem_bot _).mp h₂] at h₁₂ · rw [LieSubmodule.eq_bot_iff] rintro ⟨h⟩ m hm simpa using h ⟨m, hm⟩ ⟨_, N.zero_mem⟩ variable {R L M} section InclusionMaps /-- The inclusion of a Lie submodule into its ambient space is a morphism of Lie modules. -/ def incl : N →ₗ⁅R,L⁆ M := { Submodule.subtype (N : Submodule R M) with map_lie' := fun {_ _} ↦ rfl } @[simp] theorem incl_coe : (N.incl : N →ₗ[R] M) = (N : Submodule R M).subtype := rfl @[simp] theorem incl_apply (m : N) : N.incl m = m := rfl theorem incl_eq_val : (N.incl : N → M) = Subtype.val := rfl theorem injective_incl : Function.Injective N.incl := Subtype.coe_injective variable {N N'} variable (h : N ≤ N') /-- Given two nested Lie submodules `N ⊆ N'`, the inclusion `N ↪ N'` is a morphism of Lie modules. -/ def inclusion : N →ₗ⁅R,L⁆ N' where __ := Submodule.inclusion (show N.toSubmodule ≤ N'.toSubmodule from h) map_lie' := rfl @[simp] theorem coe_inclusion (m : N) : (inclusion h m : M) = m := rfl theorem inclusion_apply (m : N) : inclusion h m = ⟨m.1, h m.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] end InclusionMaps section LieSpan variable (R L) (s : Set M) /-- The `lieSpan` of a set `s ⊆ M` is the smallest Lie submodule of `M` that contains `s`. -/ def lieSpan : LieSubmodule R L M := sInf { N | s ⊆ N } variable {R L s} theorem mem_lieSpan {x : M} : x ∈ lieSpan R L s ↔ ∀ N : LieSubmodule R L M, s ⊆ N → x ∈ N := by rw [← SetLike.mem_coe, lieSpan, coe_sInf] exact mem_iInter₂ theorem subset_lieSpan : s ⊆ lieSpan R L s := by intro m hm rw [SetLike.mem_coe, mem_lieSpan] intro N hN exact hN hm theorem submodule_span_le_lieSpan : Submodule.span R s ≤ lieSpan R L s := by rw [Submodule.span_le] apply subset_lieSpan @[simp] theorem lieSpan_le {N} : lieSpan R L s ≤ N ↔ s ⊆ N := by constructor · exact Subset.trans subset_lieSpan · intro hs m hm; rw [mem_lieSpan] at hm; exact hm _ hs @[gcongr] theorem lieSpan_mono {t : Set M} (h : s ⊆ t) : lieSpan R L s ≤ lieSpan R L t := by rw [lieSpan_le] exact Subset.trans h subset_lieSpan theorem lieSpan_eq (N : LieSubmodule R L M) : lieSpan R L (N : Set M) = N := le_antisymm (lieSpan_le.mpr rfl.subset) subset_lieSpan theorem coe_lieSpan_submodule_eq_iff {p : Submodule R M} : (lieSpan R L (p : Set M) : Submodule R M) = p ↔ ∃ N : LieSubmodule R L M, ↑N = p := by rw [p.exists_lieSubmodule_coe_eq_iff L]; 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] variable (R L M) /-- `lieSpan` forms a Galois insertion with the coercion from `LieSubmodule` to `Set`. -/ protected def gi : GaloisInsertion (lieSpan R L : Set M → LieSubmodule R L M) (↑) 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 M) = ⊥ := (LieSubmodule.gi R L M).gc.l_bot @[simp] theorem span_univ : lieSpan R L (Set.univ : Set M) = ⊤ := eq_top_iff.2 <| SetLike.le_def.2 <| subset_lieSpan theorem lieSpan_eq_bot_iff : lieSpan R L s = ⊥ ↔ ∀ m ∈ s, m = (0 : M) := by rw [_root_.eq_bot_iff, lieSpan_le, bot_coe, subset_singleton_iff] variable {M} theorem span_union (s t : Set M) : lieSpan R L (s ∪ t) = lieSpan R L s ⊔ lieSpan R L t := (LieSubmodule.gi R L M).gc.l_sup theorem span_iUnion {ι} (s : ι → Set M) : lieSpan R L (⋃ i, s i) = ⨆ i, lieSpan R L (s i) := (LieSubmodule.gi R L M).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 submodule spanned by `s`. -/ @[elab_as_elim] theorem lieSpan_induction {p : (x : M) → x ∈ lieSpan R L s → Prop} (mem : ∀ (x) (h : x ∈ s), p x (subset_lieSpan h)) (zero : p 0 (LieSubmodule.zero_mem _)) (add : ∀ x y hx hy, p x hx → p y hy → p (x + y) (add_mem ‹_› ‹_›)) (smul : ∀ (a : R) (x hx), p x hx → p (a • x) (SMulMemClass.smul_mem _ hx)) {x} (lie : ∀ (x : L) (y hy), p y hy → p (⁅x, y⁆) (LieSubmodule.lie_mem _ ‹_›)) (hx : x ∈ lieSpan R L s) : p x hx := by let p : LieSubmodule R L M := { 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 ⟨_, hpy⟩ ↦ ⟨_, lie _ _ _ hpy⟩ } exact lieSpan_le (N := p) |>.mpr (fun y hy ↦ ⟨subset_lieSpan hy, mem y hy⟩) hx |>.elim fun _ ↦ id lemma isCompactElement_lieSpan_singleton (m : M) : CompleteLattice.IsCompactElement (lieSpan R L {m}) := by rw [CompleteLattice.isCompactElement_iff_le_of_directed_sSup_le] intro s hne hdir hsup replace hsup : m ∈ (↑(sSup s) : Set M) := (SetLike.le_def.mp hsup) (subset_lieSpan rfl) suffices (↑(sSup s) : Set M) = ⋃ N ∈ s, ↑N by simp_all replace hne : Nonempty s := Set.nonempty_coe_sort.mpr hne have := Submodule.coe_iSup_of_directed _ hdir.directed_val simp_rw [← iSup_toSubmodule, Set.iUnion_coe_set, coe_toSubmodule] at this rw [← this, SetLike.coe_set_eq, sSup_eq_iSup, iSup_subtype] @[simp] lemma sSup_image_lieSpan_singleton : sSup ((fun x ↦ lieSpan R L {x}) '' N) = N := by refine le_antisymm (sSup_le <| by simp) ?_ simp_rw [← toSubmodule_le_toSubmodule, sSup_toSubmodule, Set.mem_image, SetLike.mem_coe] refine fun m hm ↦ Submodule.mem_sSup.mpr fun N' hN' ↦ ?_ replace hN' : ∀ m ∈ N, lieSpan R L {m} ≤ N' := by simpa using hN' exact hN' _ hm (subset_lieSpan rfl) instance instIsCompactlyGenerated : IsCompactlyGenerated (LieSubmodule R L M) := ⟨fun N ↦ ⟨(fun x ↦ lieSpan R L {x}) '' N, fun _ ⟨m, _, hm⟩ ↦ hm ▸ isCompactElement_lieSpan_singleton R L m, N.sSup_image_lieSpan_singleton⟩⟩ end LieSpan end LatticeStructure end LieSubmodule section LieSubmoduleMapAndComap variable {R : Type u} {L : Type v} {L' : Type w₂} {M : Type w} {M' : Type w₁} variable [CommRing R] [LieRing L] [LieRing L'] [LieAlgebra R L'] variable [AddCommGroup M] [Module R M] [LieRingModule L M] variable [AddCommGroup M'] [Module R M'] [LieRingModule L M'] namespace LieSubmodule variable (f : M →ₗ⁅R,L⁆ M') (N N₂ : LieSubmodule R L M) (N' : LieSubmodule R L M') /-- A morphism of Lie modules `f : M → M'` pushes forward Lie submodules of `M` to Lie submodules of `M'`. -/ def map : LieSubmodule R L M' := { (N : Submodule R M).map (f : M →ₗ[R] M') with lie_mem := fun {x m'} h ↦ by rcases h with ⟨m, hm, hfm⟩; use ⁅x, m⁆; constructor · apply N.lie_mem hm · norm_cast at hfm; simp [hfm] } @[simp] theorem coe_map : (N.map f : Set M') = f '' N := rfl @[simp] theorem toSubmodule_map : (N.map f : Submodule R M') = (N : Submodule R M).map (f : M →ₗ[R] M') := rfl /-- A morphism of Lie modules `f : M → M'` pulls back Lie submodules of `M'` to Lie submodules of `M`. -/ def comap : LieSubmodule R L M := { (N' : Submodule R M').comap (f : M →ₗ[R] M') with lie_mem := fun {x m} h ↦ by suffices ⁅x, f m⁆ ∈ N' by simp [this] apply N'.lie_mem h } @[simp] theorem toSubmodule_comap : (N'.comap f : Submodule R M) = (N' : Submodule R M').comap (f : M →ₗ[R] M') := rfl variable {f N N₂ N'} theorem map_le_iff_le_comap : map f N ≤ N' ↔ N ≤ comap f N' := Set.image_subset_iff variable (f) in theorem gc_map_comap : GaloisConnection (map f) (comap f) := fun _ _ ↦ map_le_iff_le_comap theorem map_inf_le : (N ⊓ N₂).map f ≤ N.map f ⊓ N₂.map f := Set.image_inter_subset f N N₂ theorem map_inf (hf : Function.Injective f) : (N ⊓ N₂).map f = N.map f ⊓ N₂.map f := SetLike.coe_injective <| Set.image_inter hf @[simp] theorem map_sup : (N ⊔ N₂).map f = N.map f ⊔ N₂.map f := (gc_map_comap f).l_sup @[simp] theorem comap_inf {N₂' : LieSubmodule R L M'} : (N' ⊓ N₂').comap f = N'.comap f ⊓ N₂'.comap f := rfl @[simp] theorem map_iSup {ι : Sort*} (N : ι → LieSubmodule R L M) : (⨆ i, N i).map f = ⨆ i, (N i).map f := (gc_map_comap f : GaloisConnection (map f) (comap f)).l_iSup @[simp] theorem mem_map (m' : M') : m' ∈ N.map f ↔ ∃ m, m ∈ N ∧ f m = m' := Submodule.mem_map theorem mem_map_of_mem {m : M} (h : m ∈ N) : f m ∈ N.map f := Set.mem_image_of_mem _ h @[simp] theorem mem_comap {m : M} : m ∈ comap f N' ↔ f m ∈ N' := Iff.rfl theorem comap_incl_eq_top : N₂.comap N.incl = ⊤ ↔ N ≤ N₂ := by rw [← LieSubmodule.toSubmodule_inj, LieSubmodule.toSubmodule_comap, LieSubmodule.incl_coe, LieSubmodule.top_toSubmodule, Submodule.comap_subtype_eq_top, toSubmodule_le_toSubmodule] theorem comap_incl_eq_bot : N₂.comap N.incl = ⊥ ↔ N ⊓ N₂ = ⊥ := by simp only [← toSubmodule_inj, toSubmodule_comap, incl_coe, bot_toSubmodule, inf_toSubmodule] rw [← Submodule.disjoint_iff_comap_eq_bot, disjoint_iff] @[gcongr, mono] theorem map_mono (h : N ≤ N₂) : N.map f ≤ N₂.map f := Set.image_mono h theorem map_comp {M'' : Type*} [AddCommGroup M''] [Module R M''] [LieRingModule L M''] {g : M' →ₗ⁅R,L⁆ M''} : N.map (g.comp f) = (N.map f).map g := SetLike.coe_injective <| by simp only [← Set.image_comp, coe_map, LieModuleHom.coe_comp] @[simp] theorem map_id : N.map LieModuleHom.id = N := by ext; simp @[simp] theorem map_bot : (⊥ : LieSubmodule R L M).map f = ⊥ := by ext m; simp [eq_comm] lemma map_le_map_iff (hf : Function.Injective f) : N.map f ≤ N₂.map f ↔ N ≤ N₂ := Set.image_subset_image_iff hf lemma map_injective_of_injective (hf : Function.Injective f) : Function.Injective (map f) := fun {N N'} h ↦ SetLike.coe_injective <| hf.image_injective <| by simp only [← coe_map, h] /-- An injective morphism of Lie modules embeds the lattice of submodules of the domain into that of the target. -/ @[simps] def mapOrderEmbedding {f : M →ₗ⁅R,L⁆ M'} (hf : Function.Injective f) : LieSubmodule R L M ↪o LieSubmodule R L M' where toFun := LieSubmodule.map f inj' := map_injective_of_injective hf map_rel_iff' := Set.image_subset_image_iff hf variable (N) in /-- For an injective morphism of Lie modules, any Lie submodule is equivalent to its image. -/ noncomputable def equivMapOfInjective (hf : Function.Injective f) : N ≃ₗ⁅R,L⁆ N.map f := { Submodule.equivMapOfInjective (f : M →ₗ[R] M') hf N with -- Note: https://github.com/leanprover-community/mathlib4/pull/8386 had to specify `invFun` explicitly this way, otherwise we'd get a type mismatch invFun := by exact DFunLike.coe (Submodule.equivMapOfInjective (f : M →ₗ[R] M') hf N).symm map_lie' := by rintro x ⟨m, hm : m ∈ N⟩; ext; exact f.map_lie x m } /-- An equivalence of Lie modules yields an order-preserving equivalence of their lattices of Lie Submodules. -/ @[simps] def orderIsoMapComap (e : M ≃ₗ⁅R,L⁆ M') : LieSubmodule R L M ≃o LieSubmodule R L M' where toFun := map e invFun := comap e left_inv := fun N ↦ by ext; simp right_inv := fun N ↦ by ext; simp [e.apply_eq_iff_eq_symm_apply] map_rel_iff' := fun {_ _} ↦ Set.image_subset_image_iff e.injective end LieSubmodule end LieSubmoduleMapAndComap namespace LieModuleHom variable {R : Type u} {L : Type v} {M : Type w} {N : Type w₁} variable [CommRing R] [LieRing L] variable [AddCommGroup M] [Module R M] [LieRingModule L M] variable [AddCommGroup N] [Module R N] [LieRingModule L N] variable (f : M →ₗ⁅R,L⁆ N) /-- The kernel of a morphism of Lie algebras, as an ideal in the domain. -/ def ker : LieSubmodule R L M := LieSubmodule.comap f ⊥ @[simp] theorem ker_toSubmodule : (f.ker : Submodule R M) = LinearMap.ker (f : M →ₗ[R] N) := rfl theorem ker_eq_bot : f.ker = ⊥ ↔ Function.Injective f := by rw [← LieSubmodule.toSubmodule_inj, ker_toSubmodule, LieSubmodule.bot_toSubmodule, LinearMap.ker_eq_bot, coe_toLinearMap] variable {f} @[simp] theorem mem_ker {m : M} : m ∈ f.ker ↔ f m = 0 := Iff.rfl @[simp] theorem ker_id : (LieModuleHom.id : M →ₗ⁅R,L⁆ M).ker = ⊥ := rfl @[simp] theorem comp_ker_incl : f.comp f.ker.incl = 0 := by ext ⟨m, hm⟩; exact mem_ker.mp hm theorem le_ker_iff_map (M' : LieSubmodule R L M) : M' ≤ f.ker ↔ LieSubmodule.map f M' = ⊥ := by rw [ker, eq_bot_iff, LieSubmodule.map_le_iff_le_comap] variable (f) /-- The range of a morphism of Lie modules `f : M → N` is a Lie submodule of `N`. See Note [range copy pattern]. -/ def range : LieSubmodule R L N := (LieSubmodule.map f ⊤).copy (Set.range f) Set.image_univ.symm @[simp] theorem coe_range : f.range = Set.range f := rfl @[simp] theorem toSubmodule_range : f.range = LinearMap.range (f : M →ₗ[R] N) := rfl @[simp] theorem mem_range (n : N) : n ∈ f.range ↔ ∃ m, f m = n := Iff.rfl @[simp] theorem map_top : LieSubmodule.map f ⊤ = f.range := by ext; simp [LieSubmodule.mem_map] theorem range_eq_top : f.range = ⊤ ↔ Function.Surjective f := by rw [SetLike.ext'_iff, coe_range, LieSubmodule.top_coe, Set.range_eq_univ] /-- A morphism of Lie modules `f : M → N` whose values lie in a Lie submodule `P ⊆ N` can be restricted to a morphism of Lie modules `M → P`. -/ def codRestrict (P : LieSubmodule R L N) (f : M →ₗ⁅R,L⁆ N) (h : ∀ m, f m ∈ P) : M →ₗ⁅R,L⁆ P where toFun := f.toLinearMap.codRestrict P h __ := f.toLinearMap.codRestrict P h map_lie' {x m} := by ext; simp @[simp] lemma codRestrict_apply (P : LieSubmodule R L N) (f : M →ₗ⁅R,L⁆ N) (h : ∀ m, f m ∈ P) (m : M) : (f.codRestrict P h m : N) = f m := rfl end LieModuleHom namespace LieSubmodule variable {R : Type u} {L : Type v} {M : Type w} variable [CommRing R] [LieRing L] variable [AddCommGroup M] [Module R M] [LieRingModule L M] variable (N : LieSubmodule R L M) @[simp] theorem ker_incl : N.incl.ker = ⊥ := (LieModuleHom.ker_eq_bot N.incl).mpr <| injective_incl N @[simp] theorem range_incl : N.incl.range = N := by simp only [← toSubmodule_inj, LieModuleHom.toSubmodule_range, incl_coe] rw [Submodule.range_subtype] @[simp] theorem comap_incl_self : comap N.incl N = ⊤ := by simp only [← toSubmodule_inj, toSubmodule_comap, incl_coe, top_toSubmodule] rw [Submodule.comap_subtype_self] theorem map_incl_top : (⊤ : LieSubmodule R L N).map N.incl = N := by simp variable {N} @[simp] lemma map_le_range {M' : Type*} [AddCommGroup M'] [Module R M'] [LieRingModule L M'] (f : M →ₗ⁅R,L⁆ M') : N.map f ≤ f.range := by rw [← LieModuleHom.map_top] exact LieSubmodule.map_mono le_top @[simp] lemma map_incl_lt_iff_lt_top {N' : LieSubmodule R L N} : N'.map (LieSubmodule.incl N) < N ↔ N' < ⊤ := by convert (LieSubmodule.mapOrderEmbedding (f := N.incl) Subtype.coe_injective).lt_iff_lt simp @[simp] lemma map_incl_le {N' : LieSubmodule R L N} : N'.map N.incl ≤ N := by conv_rhs => rw [← N.map_incl_top] exact LieSubmodule.map_mono le_top end LieSubmodule section TopEquiv variable (R : Type u) (L : Type v) variable [CommRing R] [LieRing L] variable (M : Type*) [AddCommGroup M] [Module R M] [LieRingModule L M] /-- The natural equivalence between the 'top' Lie submodule and the enclosing Lie module. -/ def LieModuleEquiv.ofTop : (⊤ : LieSubmodule R L M) ≃ₗ⁅R,L⁆ M := { LinearEquiv.ofTop ⊤ rfl with map_lie' := rfl } variable {R L} lemma LieModuleEquiv.ofTop_apply (x : (⊤ : LieSubmodule R L M)) : LieModuleEquiv.ofTop R L M x = x := rfl @[simp] lemma LieModuleEquiv.range_coe {M' : Type*} [AddCommGroup M'] [Module R M'] [LieRingModule L M'] (e : M ≃ₗ⁅R,L⁆ M') : LieModuleHom.range (e : M →ₗ⁅R,L⁆ M') = ⊤ := by rw [LieModuleHom.range_eq_top] exact e.surjective variable [LieAlgebra R L] [LieModule R L M] /-- The natural equivalence between the 'top' Lie subalgebra and the enclosing Lie algebra. This is the Lie subalgebra version of `Submodule.topEquiv`. -/ def LieSubalgebra.topEquiv : (⊤ : LieSubalgebra R L) ≃ₗ⁅R⁆ L := { (⊤ : LieSubalgebra R L).incl with invFun := fun x ↦ ⟨x, Set.mem_univ x⟩ } @[simp] theorem LieSubalgebra.topEquiv_apply (x : (⊤ : LieSubalgebra R L)) : LieSubalgebra.topEquiv x = x := rfl end TopEquiv
.lake/packages/mathlib/Mathlib/Algebra/Lie/CartanMatrix.lean
import Mathlib.Algebra.Lie.Free import Mathlib.Algebra.Lie.Quotient import Mathlib.LinearAlgebra.Matrix.Notation /-! # Lie algebras from Cartan matrices Split semi-simple Lie algebras are uniquely determined by their Cartan matrix. Indeed, if `A` is an `l × l` Cartan matrix, the corresponding Lie algebra may be obtained as the Lie algebra on `3l` generators: $H_1, H_2, \ldots H_l, E_1, E_2, \ldots, E_l, F_1, F_2, \ldots, F_l$ subject to the following relations: $$ \begin{align} [H_i, H_j] &= 0\\ [E_i, F_i] &= H_i\\ [E_i, F_j] &= 0 \quad\text{if $i \ne j$}\\ [H_i, E_j] &= A_{ij}E_j\\ [H_i, F_j] &= -A_{ij}F_j\\ ad(E_i)^{1 - A_{ij}}(E_j) &= 0 \quad\text{if $i \ne j$}\\ ad(F_i)^{1 - A_{ij}}(F_j) &= 0 \quad\text{if $i \ne j$}\\ \end{align} $$ In this file we provide the above construction. It is defined for any square matrix of integers but the results for non-Cartan matrices should be regarded as junk. Recall that a Cartan matrix is a square matrix of integers `A` such that: * For diagonal values we have: `A i i = 2`. * For off-diagonal values (`i ≠ j`) we have: `A i j ∈ {-3, -2, -1, 0}`. * `A i j = 0 ↔ A j i = 0`. * There exists a diagonal matrix `D` over ℝ such that `D * A * D⁻¹` is symmetric positive definite. ## Alternative construction This construction is sometimes performed within the free unital associative algebra `FreeAlgebra R X`, rather than within the free Lie algebra `FreeLieAlgebra R X`, as we do here. However the difference is illusory since the construction stays inside the Lie subalgebra of `FreeAlgebra R X` generated by `X`, and this is naturally isomorphic to `FreeLieAlgebra R X` (though the proof of this seems to require Poincaré–Birkhoff–Witt). ## Definitions of exceptional Lie algebras This file also contains the Cartan matrices of the exceptional Lie algebras. By using these in the above construction, it thus provides definitions of the exceptional Lie algebras. These definitions make sense over any commutative ring. When the ring is ℝ, these are the split real forms of the exceptional semisimple Lie algebras. ## References * [N. Bourbaki, *Lie Groups and Lie Algebras, Chapters 4--6*](bourbaki1968) plates V -- IX, pages 275--290 * [N. Bourbaki, *Lie Groups and Lie Algebras, Chapters 7--9*](bourbaki1975b) chapter VIII, §4.3 * [J.P. Serre, *Complex Semisimple Lie Algebras*](serre1965) chapter VI, appendix ## Main definitions * `Matrix.ToLieAlgebra` * `CartanMatrix.E₆` * `CartanMatrix.E₇` * `CartanMatrix.E₈` * `CartanMatrix.F₄` * `CartanMatrix.G₂` * `LieAlgebra.e₆` * `LieAlgebra.e₇` * `LieAlgebra.e₈` * `LieAlgebra.f₄` * `LieAlgebra.g₂` ## Tags lie algebra, semi-simple, cartan matrix -/ universe u v w noncomputable section variable (R : Type u) {B : Type v} [CommRing R] variable (A : Matrix B B ℤ) namespace CartanMatrix variable (B) /-- The generators of the free Lie algebra from which we construct the Lie algebra of a Cartan matrix as a quotient. -/ inductive Generators | H : B → Generators | E : B → Generators | F : B → Generators instance [Inhabited B] : Inhabited (Generators B) := ⟨Generators.H default⟩ variable {B} namespace Relations open Function local notation "H" => FreeLieAlgebra.of R ∘ Generators.H local notation "E" => FreeLieAlgebra.of R ∘ Generators.E local notation "F" => FreeLieAlgebra.of R ∘ Generators.F local notation "ad" => LieAlgebra.ad R (FreeLieAlgebra R (Generators B)) /-- The terms corresponding to the `⁅H, H⁆`-relations. -/ def HH : B × B → FreeLieAlgebra R (Generators B) := uncurry fun i j => ⁅H i, H j⁆ /-- The terms corresponding to the `⁅E, F⁆`-relations. -/ def EF [DecidableEq B] : B × B → FreeLieAlgebra R (Generators B) := uncurry fun i j => if i = j then ⁅E i, F i⁆ - H i else ⁅E i, F j⁆ /-- The terms corresponding to the `⁅H, E⁆`-relations. -/ def HE : B × B → FreeLieAlgebra R (Generators B) := uncurry fun i j => ⁅H i, E j⁆ - A i j • E j /-- The terms corresponding to the `⁅H, F⁆`-relations. -/ def HF : B × B → FreeLieAlgebra R (Generators B) := uncurry fun i j => ⁅H i, F j⁆ + A i j • F j /-- The terms corresponding to the `ad E`-relations. Note that we use `Int.toNat` so that we can take the power and that we do not bother restricting to the case `i ≠ j` since these relations are zero anyway. We also defensively ensure this with `adE_of_eq_eq_zero`. -/ def adE : B × B → FreeLieAlgebra R (Generators B) := uncurry fun i j => ad (E i) ^ (-A i j).toNat <| ⁅E i, E j⁆ /-- The terms corresponding to the `ad F`-relations. See also `adE` docstring. -/ def adF : B × B → FreeLieAlgebra R (Generators B) := uncurry fun i j => ad (F i) ^ (-A i j).toNat <| ⁅F i, F j⁆ private theorem adE_of_eq_eq_zero (i : B) (h : A i i = 2) : adE R A ⟨i, i⟩ = 0 := by have h' : (-2 : ℤ).toNat = 0 := rfl simp [adE, h, h'] private theorem adF_of_eq_eq_zero (i : B) (h : A i i = 2) : adF R A ⟨i, i⟩ = 0 := by have h' : (-2 : ℤ).toNat = 0 := rfl simp [adF, h, h'] /-- The union of all the relations as a subset of the free Lie algebra. -/ def toSet [DecidableEq B] : Set (FreeLieAlgebra R (Generators B)) := (Set.range <| HH R) ∪ (Set.range <| EF R) ∪ (Set.range <| HE R A) ∪ (Set.range <| HF R A) ∪ (Set.range <| adE R A) ∪ (Set.range <| adF R A) /-- The ideal of the free Lie algebra generated by the relations. -/ def toIdeal [DecidableEq B] : LieIdeal R (FreeLieAlgebra R (Generators B)) := LieSubmodule.lieSpan R _ <| toSet R A end Relations end CartanMatrix variable [DecidableEq B] /-- The Lie algebra corresponding to a Cartan matrix. Note that it is defined for any matrix of integers. Its value for non-Cartan matrices should be regarded as junk. -/ def Matrix.ToLieAlgebra := FreeLieAlgebra R _ ⧸ CartanMatrix.Relations.toIdeal R A deriving LieRing, Inhabited, LieAlgebra R namespace CartanMatrix /-- The Cartan matrix of type e₆. See [bourbaki1968] plate V, page 277. The corresponding Dynkin diagram is: ``` o | o --- o --- o --- o --- o ``` -/ def E₆ : Matrix (Fin 6) (Fin 6) ℤ := !![2, 0, -1, 0, 0, 0; 0, 2, 0, -1, 0, 0; -1, 0, 2, -1, 0, 0; 0, -1, -1, 2, -1, 0; 0, 0, 0, -1, 2, -1; 0, 0, 0, 0, -1, 2] /-- The Cartan matrix of type e₇. See [bourbaki1968] plate VI, page 281. The corresponding Dynkin diagram is: ``` o | o --- o --- o --- o --- o --- o ``` -/ def E₇ : Matrix (Fin 7) (Fin 7) ℤ := !![2, 0, -1, 0, 0, 0, 0; 0, 2, 0, -1, 0, 0, 0; -1, 0, 2, -1, 0, 0, 0; 0, -1, -1, 2, -1, 0, 0; 0, 0, 0, -1, 2, -1, 0; 0, 0, 0, 0, -1, 2, -1; 0, 0, 0, 0, 0, -1, 2] /-- The Cartan matrix of type e₈. See [bourbaki1968] plate VII, page 285. The corresponding Dynkin diagram is: ``` o | o --- o --- o --- o --- o --- o --- o ``` -/ def E₈ : Matrix (Fin 8) (Fin 8) ℤ := !![2, 0, -1, 0, 0, 0, 0, 0; 0, 2, 0, -1, 0, 0, 0, 0; -1, 0, 2, -1, 0, 0, 0, 0; 0, -1, -1, 2, -1, 0, 0, 0; 0, 0, 0, -1, 2, -1, 0, 0; 0, 0, 0, 0, -1, 2, -1, 0; 0, 0, 0, 0, 0, -1, 2, -1; 0, 0, 0, 0, 0, 0, -1, 2] /-- The Cartan matrix of type f₄. See [bourbaki1968] plate VIII, page 288. The corresponding Dynkin diagram is: ``` o --- o =>= o --- o ``` -/ def F₄ : Matrix (Fin 4) (Fin 4) ℤ := !![2, -1, 0, 0; -1, 2, -2, 0; 0, -1, 2, -1; 0, 0, -1, 2] /-- The Cartan matrix of type g₂. See [bourbaki1968] plate IX, page 290. The corresponding Dynkin diagram is: ``` o ≡>≡ o ``` Actually we are using the transpose of Bourbaki's matrix. This is to make this matrix consistent with `CartanMatrix.F₄`, in the sense that all non-zero values below the diagonal are -1. -/ def G₂ : Matrix (Fin 2) (Fin 2) ℤ := !![2, -3; -1, 2] end CartanMatrix namespace LieAlgebra /-- The exceptional split Lie algebra of type e₆. -/ abbrev e₆ := CartanMatrix.E₆.ToLieAlgebra R /-- The exceptional split Lie algebra of type e₇. -/ abbrev e₇ := CartanMatrix.E₇.ToLieAlgebra R /-- The exceptional split Lie algebra of type e₈. -/ abbrev e₈ := CartanMatrix.E₈.ToLieAlgebra R /-- The exceptional split Lie algebra of type f₄. -/ abbrev f₄ := CartanMatrix.F₄.ToLieAlgebra R /-- The exceptional split Lie algebra of type g₂. -/ abbrev g₂ := CartanMatrix.G₂.ToLieAlgebra R end LieAlgebra
.lake/packages/mathlib/Mathlib/Algebra/Lie/TraceForm.lean
import Mathlib.Algebra.DirectSum.LinearMap import Mathlib.Algebra.Lie.InvariantForm import Mathlib.Algebra.Lie.Weights.Cartan import Mathlib.Algebra.Lie.Weights.Linear import Mathlib.FieldTheory.IsAlgClosed.AlgebraicClosure import Mathlib.LinearAlgebra.PID /-! # The trace and Killing forms of a Lie algebra. Let `L` be a Lie algebra with coefficients in a commutative ring `R`. Suppose `M` is a finite, free `R`-module and we have a representation `φ : L → End M`. This data induces a natural bilinear form `B` on `L`, called the trace form associated to `M`; it is defined as `B(x, y) = Tr (φ x) (φ y)`. In the special case that `M` is `L` itself and `φ` is the adjoint representation, the trace form is known as the Killing form. We define the trace / Killing form in this file and prove some basic properties. ## Main definitions * `LieModule.traceForm`: a finite, free representation of a Lie algebra `L` induces a bilinear form on `L` called the trace Form. * `LieModule.traceForm_eq_zero_of_isNilpotent`: the trace form induced by a nilpotent representation of a Lie algebra vanishes. * `killingForm`: the adjoint representation of a (finite, free) Lie algebra `L` induces a bilinear form on `L` via the trace form construction. -/ variable (R K L M : Type*) [CommRing R] [LieRing L] [LieAlgebra R L] [AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M] local notation "φ" => LieModule.toEnd R L M open LinearMap (trace) open Set Module namespace LieModule /-- A finite, free representation of a Lie algebra `L` induces a bilinear form on `L` called the trace Form. See also `killingForm`. -/ noncomputable def traceForm : LinearMap.BilinForm R L := ((LinearMap.mul _ _).compl₁₂ (φ).toLinearMap (φ).toLinearMap).compr₂ (trace R M) lemma traceForm_apply_apply (x y : L) : traceForm R L M x y = trace R _ (φ x ∘ₗ φ y) := rfl lemma traceForm_comm (x y : L) : traceForm R L M x y = traceForm R L M y x := LinearMap.trace_mul_comm R (φ x) (φ y) lemma traceForm_isSymm : LinearMap.IsSymm (traceForm R L M) := ⟨LieModule.traceForm_comm R L M⟩ @[simp] lemma traceForm_flip : LinearMap.flip (traceForm R L M) = traceForm R L M := Eq.symm <| LinearMap.ext₂ <| traceForm_comm R L M /-- The trace form of a Lie module is compatible with the action of the Lie algebra. See also `LieModule.traceForm_apply_lie_apply'`. -/ lemma traceForm_apply_lie_apply (x y z : L) : traceForm R L M ⁅x, y⁆ z = traceForm R L M x ⁅y, z⁆ := by calc traceForm R L M ⁅x, y⁆ z = trace R _ (φ ⁅x, y⁆ ∘ₗ φ z) := by simp only [traceForm_apply_apply] _ = trace R _ ((φ x * φ y - φ y * φ x) * φ z) := ?_ _ = trace R _ (φ x * (φ y * φ z)) - trace R _ (φ y * (φ x * φ z)) := ?_ _ = trace R _ (φ x * (φ y * φ z)) - trace R _ (φ x * (φ z * φ y)) := ?_ _ = traceForm R L M x ⁅y, z⁆ := ?_ · simp only [LieHom.map_lie, Ring.lie_def, ← Module.End.mul_eq_comp] · simp only [sub_mul, map_sub, mul_assoc] · simp only [LinearMap.trace_mul_cycle' R (φ x) (φ z) (φ y)] · simp only [traceForm_apply_apply, LieHom.map_lie, Ring.lie_def, mul_sub, map_sub, ← Module.End.mul_eq_comp] /-- Given a representation `M` of a Lie algebra `L`, the action of any `x : L` is skew-adjoint w.r.t. the trace form. -/ lemma traceForm_apply_lie_apply' (x y z : L) : traceForm R L M ⁅x, y⁆ z = - traceForm R L M y ⁅x, z⁆ := calc traceForm R L M ⁅x, y⁆ z = - traceForm R L M ⁅y, x⁆ z := by rw [← lie_skew x y, map_neg, LinearMap.neg_apply] _ = - traceForm R L M y ⁅x, z⁆ := by rw [traceForm_apply_lie_apply] lemma traceForm_lieInvariant : (traceForm R L M).lieInvariant L := by intro x y z rw [← lie_skew, map_neg, LinearMap.neg_apply, LieModule.traceForm_apply_lie_apply R L M] /-- This lemma justifies the terminology "invariant" for trace forms. -/ @[simp] lemma lie_traceForm_eq_zero (x : L) : ⁅x, traceForm R L M⁆ = 0 := by ext y z rw [LieHom.lie_apply, LinearMap.sub_apply, Module.Dual.lie_apply, LinearMap.zero_apply, LinearMap.zero_apply, traceForm_apply_lie_apply', sub_self] @[simp] lemma traceForm_eq_zero_of_isNilpotent [IsReduced R] [IsNilpotent L M] : traceForm R L M = 0 := by ext x y simp only [traceForm_apply_apply, LinearMap.zero_apply, ← isNilpotent_iff_eq_zero] apply LinearMap.isNilpotent_trace_of_isNilpotent exact isNilpotent_toEnd_of_isNilpotent₂ R L M x y @[simp] lemma traceForm_genWeightSpace_eq [Module.Free R M] [IsDomain R] [IsPrincipalIdealRing R] [LieRing.IsNilpotent L] [IsNoetherian R M] [LinearWeights R L M] (χ : L → R) (x y : L) : traceForm R L (genWeightSpace M χ) x y = finrank R (genWeightSpace M χ) • (χ x * χ y) := by set d := finrank R (genWeightSpace M χ) have h₁ : χ y • d • χ x - χ y • χ x • (d : R) = 0 := by simp [mul_comm (χ x)] have h₂ : χ x • d • χ y = d • (χ x * χ y) := by simpa [nsmul_eq_mul, smul_eq_mul] using mul_left_comm (χ x) d (χ y) have := traceForm_eq_zero_of_isNilpotent R L (shiftedGenWeightSpace R L M χ) replace this := LinearMap.congr_fun (LinearMap.congr_fun this x) y rwa [LinearMap.zero_apply, LinearMap.zero_apply, traceForm_apply_apply, shiftedGenWeightSpace.toEnd_eq, shiftedGenWeightSpace.toEnd_eq, ← LinearEquiv.conj_comp, LinearMap.trace_conj', LinearMap.comp_sub, LinearMap.sub_comp, LinearMap.sub_comp, map_sub, map_sub, map_sub, LinearMap.comp_smul, LinearMap.smul_comp, LinearMap.comp_id, LinearMap.id_comp, LinearMap.map_smul, LinearMap.map_smul, trace_toEnd_genWeightSpace, trace_toEnd_genWeightSpace, LinearMap.comp_smul, LinearMap.smul_comp, LinearMap.id_comp, map_smul, map_smul, LinearMap.trace_id, ← traceForm_apply_apply, h₁, h₂, sub_zero, sub_eq_zero] at this /-- The upper and lower central series of `L` are orthogonal w.r.t. the trace form of any Lie module `M`. -/ lemma traceForm_eq_zero_if_mem_lcs_of_mem_ucs {x y : L} (k : ℕ) (hx : x ∈ (⊤ : LieIdeal R L).lcs L k) (hy : y ∈ (⊥ : LieIdeal R L).ucs k) : traceForm R L M x y = 0 := by induction k generalizing x y with | zero => replace hy : y = 0 := by simpa using hy simp [hy] | succ k ih => rw [LieSubmodule.ucs_succ, LieSubmodule.mem_normalizer] at hy simp_rw [LieIdeal.lcs_succ, ← LieSubmodule.mem_toSubmodule, LieSubmodule.lieIdeal_oper_eq_linear_span', LieSubmodule.mem_top, true_and] at hx refine Submodule.span_induction ?_ ?_ (fun z w _ _ hz hw ↦ ?_) (fun t z _ hz ↦ ?_) hx · rintro - ⟨z, w, hw, rfl⟩ rw [← lie_skew, map_neg, LinearMap.neg_apply, neg_eq_zero, traceForm_apply_lie_apply] exact ih hw (hy _) · simp · simp [hz, hw] · simp [hz] lemma traceForm_apply_eq_zero_of_mem_lcs_of_mem_center {x y : L} (hx : x ∈ lowerCentralSeries R L L 1) (hy : y ∈ LieAlgebra.center R L) : traceForm R L M x y = 0 := by apply traceForm_eq_zero_if_mem_lcs_of_mem_ucs R L M 1 · simpa using hx · simpa using hy -- This is barely worth having: it usually follows from `LieModule.traceForm_eq_zero_of_isNilpotent` @[simp] lemma traceForm_eq_zero_of_isTrivial [IsTrivial L M] : traceForm R L M = 0 := by ext x y suffices φ x ∘ₗ φ y = 0 by simp [traceForm_apply_apply, this] ext m simp /-- Given a bilinear form `B` on a representation `M` of a nilpotent Lie algebra `L`, if `B` is invariant (in the sense that the action of `L` is skew-adjoint w.r.t. `B`) then components of the Fitting decomposition of `M` are orthogonal w.r.t. `B`. -/ lemma eq_zero_of_mem_genWeightSpace_mem_posFitting [LieRing.IsNilpotent L] {B : LinearMap.BilinForm R M} (hB : ∀ (x : L) (m n : M), B ⁅x, m⁆ n = -B m ⁅x, n⁆) {m₀ m₁ : M} (hm₀ : m₀ ∈ genWeightSpace M (0 : L → R)) (hm₁ : m₁ ∈ posFittingComp R L M) : B m₀ m₁ = 0 := by replace hB : ∀ x (k : ℕ) m n, B m ((φ x ^ k) n) = (- 1 : R) ^ k • B ((φ x ^ k) m) n := by intro x k induction k with | zero => simp | succ k ih => intro m n replace hB : ∀ m, B m (φ x n) = (- 1 : R) • B (φ x m) n := by simp [hB] have : (-1 : R) ^ k • (-1 : R) = (-1 : R) ^ (k + 1) := by rw [pow_succ (-1 : R), smul_eq_mul] conv_lhs => rw [pow_succ, Module.End.mul_eq_comp, LinearMap.comp_apply, ih, hB, ← (φ x).comp_apply, ← Module.End.mul_eq_comp, ← pow_succ', ← smul_assoc, this] suffices ∀ (x : L) m, m ∈ posFittingCompOf R M x → B m₀ m = 0 by refine LieSubmodule.iSup_induction (motive := fun m ↦ (B m₀) m = 0) _ hm₁ this (map_zero _) ?_ simp_all clear hm₁ m₁; intro x m₁ hm₁ simp only [mem_genWeightSpace, Pi.zero_apply, zero_smul, sub_zero] at hm₀ obtain ⟨k, hk⟩ := hm₀ x obtain ⟨m, rfl⟩ := (mem_posFittingCompOf R x m₁).mp hm₁ k simp [hB, hk] lemma trace_toEnd_eq_zero_of_mem_lcs {k : ℕ} {x : L} (hk : 1 ≤ k) (hx : x ∈ lowerCentralSeries R L L k) : trace R _ (toEnd R L M x) = 0 := by replace hx : x ∈ lowerCentralSeries R L L 1 := antitone_lowerCentralSeries _ _ _ hk hx replace hx : x ∈ Submodule.span R {m | ∃ u v : L, ⁅u, v⁆ = m} := by rw [lowerCentralSeries_succ, ← LieSubmodule.mem_toSubmodule, LieSubmodule.lieIdeal_oper_eq_linear_span'] at hx simpa using hx refine Submodule.span_induction (p := fun x _ ↦ trace R _ (toEnd R L M x) = 0) ?_ ?_ (fun u v _ _ hu hv ↦ ?_) (fun t u _ hu ↦ ?_) hx · intro y ⟨u, v, huv⟩ simp [← huv] · simp · simp [hu, hv] · simp [hu] @[simp] lemma traceForm_lieSubalgebra_mk_left (L' : LieSubalgebra R L) {x : L} (hx : x ∈ L') (y : L') : traceForm R L' M ⟨x, hx⟩ y = traceForm R L M x y := rfl @[simp] lemma traceForm_lieSubalgebra_mk_right (L' : LieSubalgebra R L) {x : L'} {y : L} (hy : y ∈ L') : traceForm R L' M x ⟨y, hy⟩ = traceForm R L M x y := rfl open TensorProduct variable [LieRing.IsNilpotent L] [IsDomain R] [IsPrincipalIdealRing R] lemma traceForm_eq_sum_genWeightSpaceOf [NoZeroSMulDivisors R M] [IsNoetherian R M] [IsTriangularizable R L M] (z : L) : traceForm R L M = ∑ χ ∈ (finite_genWeightSpaceOf_ne_bot R L M z).toFinset, traceForm R L (genWeightSpaceOf M χ z) := by ext x y have hxy : ∀ χ : R, MapsTo ((toEnd R L M x).comp (toEnd R L M y)) (genWeightSpaceOf M χ z) (genWeightSpaceOf M χ z) := fun χ m hm ↦ LieSubmodule.lie_mem _ <| LieSubmodule.lie_mem _ hm have hfin : {χ : R | (genWeightSpaceOf M χ z : Submodule R M) ≠ ⊥}.Finite := by convert finite_genWeightSpaceOf_ne_bot R L M z exact LieSubmodule.toSubmodule_eq_bot (genWeightSpaceOf M _ _) classical have h := LieSubmodule.iSupIndep_toSubmodule.mpr <| iSupIndep_genWeightSpaceOf R L M z have hds := DirectSum.isInternal_submodule_of_iSupIndep_of_iSup_eq_top h <| by simp [← LieSubmodule.iSup_toSubmodule] simp only [LinearMap.coeFn_sum, Finset.sum_apply, traceForm_apply_apply, LinearMap.trace_eq_sum_trace_restrict' hds hfin hxy] exact Finset.sum_congr (by simp) (fun χ _ ↦ rfl) -- In characteristic zero (or even just `LinearWeights R L M`) a stronger result holds (no -- `⊓ LieAlgebra.center R L`) TODO prove this using `LieModule.traceForm_eq_sum_finrank_nsmul_mul`. lemma lowerCentralSeries_one_inf_center_le_ker_traceForm [Module.Free R M] [Module.Finite R M] : lowerCentralSeries R L L 1 ⊓ LieAlgebra.center R L ≤ LinearMap.ker (traceForm R L M) := by /- Sketch of proof (due to Zassenhaus): Let `z ∈ lowerCentralSeries R L L 1 ⊓ LieAlgebra.center R L` and `x : L`. We must show that `trace (φ x ∘ φ z) = 0` where `φ z : End R M` indicates the action of `z` on `M` (and likewise for `φ x`). Because `z` belongs to the indicated intersection, it has two key properties: (a) the trace of the action of `z` vanishes on any Lie module of `L` (see `LieModule.trace_toEnd_eq_zero_of_mem_lcs`), (b) `z` commutes with all elements of `L`. If `φ x` were triangularizable, we could write `M` as a direct sum of generalized eigenspaces of `φ x`. Because `L` is nilpotent these are all Lie submodules, thus Lie modules in their own right, and thus by (a) above we learn that `trace (φ z) = 0` restricted to each generalized eigenspace. Because `z` commutes with `x`, this forces `trace (φ x ∘ φ z) = 0` on each generalized eigenspace, and so by summing the traces on each generalized eigenspace we learn the total trace is zero, as required (see `LinearMap.trace_comp_eq_zero_of_commute_of_trace_restrict_eq_zero`). To cater for the fact that `φ x` may not be triangularizable, we first extend the scalars from `R` to `AlgebraicClosure (FractionRing R)` and argue using the action of `A ⊗ L` on `A ⊗ M`. -/ rintro z ⟨hz : z ∈ lowerCentralSeries R L L 1, hzc : z ∈ LieAlgebra.center R L⟩ ext x rw [traceForm_apply_apply, LinearMap.zero_apply] let A := AlgebraicClosure (FractionRing R) suffices algebraMap R A (trace R _ ((φ z).comp (φ x))) = 0 by have _i : NoZeroSMulDivisors R A := NoZeroSMulDivisors.trans_faithfulSMul R (FractionRing R) A rw [← map_zero (algebraMap R A)] at this exact FaithfulSMul.algebraMap_injective R A this rw [← LinearMap.trace_baseChange, LinearMap.baseChange_comp, ← toEnd_baseChange, ← toEnd_baseChange] replace hz : 1 ⊗ₜ z ∈ lowerCentralSeries A (A ⊗[R] L) (A ⊗[R] L) 1 := by simp only [lowerCentralSeries_succ, lowerCentralSeries_zero] at hz ⊢ rw [← LieSubmodule.baseChange_top, ← LieSubmodule.lie_baseChange] exact Submodule.tmul_mem_baseChange_of_mem 1 hz replace hzc : 1 ⊗ₜ[R] z ∈ LieAlgebra.center A (A ⊗[R] L) := by simp only [mem_maxTrivSubmodule] at hzc ⊢ intro y exact y.induction_on rfl (fun a u ↦ by simp [hzc u]) (fun u v hu hv ↦ by simp [A, hu, hv]) apply LinearMap.trace_comp_eq_zero_of_commute_of_trace_restrict_eq_zero · exact IsTriangularizable.maxGenEigenspace_eq_top (1 ⊗ₜ[R] x) · exact fun μ ↦ trace_toEnd_eq_zero_of_mem_lcs A (A ⊗[R] L) (genWeightSpaceOf (A ⊗[R] M) μ ((1:A) ⊗ₜ[R] x)) (le_refl 1) hz · exact commute_toEnd_of_mem_center_right (A ⊗[R] M) hzc (1 ⊗ₜ x) /-- A nilpotent Lie algebra with a representation whose trace form is non-singular is Abelian. -/ lemma isLieAbelian_of_ker_traceForm_eq_bot [Module.Free R M] [Module.Finite R M] (h : LinearMap.ker (traceForm R L M) = ⊥) : IsLieAbelian L := by simpa only [← disjoint_lowerCentralSeries_maxTrivSubmodule_iff R L L, disjoint_iff_inf_le, LieIdeal.toLieSubalgebra_toSubmodule, LieSubmodule.toSubmodule_eq_bot, h] using lowerCentralSeries_one_inf_center_le_ker_traceForm R L M end LieModule namespace LieSubmodule open LieModule (traceForm) variable {R L M} variable [Module.Free R M] [Module.Finite R M] variable [IsDomain R] [IsPrincipalIdealRing R] (N : LieSubmodule R L M) (I : LieIdeal R L) (h : I ≤ N.idealizer) (x : L) {y : L} (hy : y ∈ I) lemma trace_eq_trace_restrict_of_le_idealizer (hy' : ∀ m ∈ N, (φ x ∘ₗ φ y) m ∈ N := fun m _ ↦ N.lie_mem (N.mem_idealizer.mp (h hy) m)) : trace R M (φ x ∘ₗ φ y) = trace R N ((φ x ∘ₗ φ y).restrict hy') := by suffices ∀ m, ⁅x, ⁅y, m⁆⁆ ∈ N by have : (trace R { x // x ∈ N }) ((φ x ∘ₗ φ y).restrict _) = (trace R M) (φ x ∘ₗ φ y) := (φ x ∘ₗ φ y).trace_restrict_eq_of_forall_mem _ this simp [this] exact fun m ↦ N.lie_mem (h hy m) include h in lemma traceForm_eq_of_le_idealizer : traceForm R I N = (traceForm R L M).restrict I := by ext ⟨x, hx⟩ ⟨y, hy⟩ change _ = trace R M (φ x ∘ₗ φ y) rw [N.trace_eq_trace_restrict_of_le_idealizer I h x hy] rfl include h hy in /-- Note that this result is slightly stronger than it might look at first glance: we only assume that `N` is trivial over `I` rather than all of `L`. This means that it applies in the important case of an Abelian ideal (which has `M = L` and `N = I`). -/ lemma traceForm_eq_zero_of_isTrivial [LieModule.IsTrivial I N] : trace R M (φ x ∘ₗ φ y) = 0 := by let hy' : ∀ m ∈ N, (φ x ∘ₗ φ y) m ∈ N := fun m _ ↦ N.lie_mem (N.mem_idealizer.mp (h hy) m) suffices (φ x ∘ₗ φ y).restrict hy' = 0 by simp [this, N.trace_eq_trace_restrict_of_le_idealizer I h x hy] ext (n : N) suffices ⁅y, (n : M)⁆ = 0 by simp [this] exact Submodule.coe_eq_zero.mpr (LieModule.IsTrivial.trivial (⟨y, hy⟩ : I) n) end LieSubmodule section LieAlgebra /-- A finite, free (as an `R`-module) Lie algebra `L` carries a bilinear form on `L`. This is a specialisation of `LieModule.traceForm` to the adjoint representation of `L`. -/ noncomputable abbrev killingForm : LinearMap.BilinForm R L := LieModule.traceForm R L L open LieAlgebra in lemma killingForm_apply_apply (x y : L) : killingForm R L x y = trace R L (ad R L x ∘ₗ ad R L y) := LieModule.traceForm_apply_apply R L L x y lemma killingForm_eq_zero_of_mem_zeroRoot_mem_posFitting (H : LieSubalgebra R L) [LieRing.IsNilpotent H] {x₀ x₁ : L} (hx₀ : x₀ ∈ LieAlgebra.zeroRootSubalgebra R L H) (hx₁ : x₁ ∈ LieModule.posFittingComp R H L) : killingForm R L x₀ x₁ = 0 := LieModule.eq_zero_of_mem_genWeightSpace_mem_posFitting R H L (fun x y z ↦ LieModule.traceForm_apply_lie_apply' R L L x y z) hx₀ hx₁ namespace LieIdeal variable (I : LieIdeal R L) /-- The orthogonal complement of an ideal with respect to the killing form is an ideal. -/ noncomputable def killingCompl : LieIdeal R L := LieAlgebra.InvariantForm.orthogonal (killingForm R L) (LieModule.traceForm_lieInvariant R L L) I @[simp] lemma toSubmodule_killingCompl : LieSubmodule.toSubmodule I.killingCompl = (killingForm R L).orthogonal I.toSubmodule := rfl @[simp] lemma mem_killingCompl {x : L} : x ∈ I.killingCompl ↔ ∀ y ∈ I, killingForm R L y x = 0 := by rfl lemma coe_killingCompl_top : killingCompl R L ⊤ = LinearMap.ker (killingForm R L) := by ext x simp [LinearMap.ext_iff, LinearMap.BilinForm.IsOrtho, LieModule.traceForm_comm R L L x] lemma restrict_killingForm : (killingForm R L).restrict I = LieModule.traceForm R I L := rfl variable [Module.Free R L] [Module.Finite R L] [IsDomain R] [IsPrincipalIdealRing R] lemma killingForm_eq : killingForm R I = (killingForm R L).restrict I := LieSubmodule.traceForm_eq_of_le_idealizer I I <| by simp @[simp] lemma le_killingCompl_top_of_isLieAbelian [IsLieAbelian I] : I ≤ LieIdeal.killingCompl R L ⊤ := by intro x (hx : x ∈ I) simp only [mem_killingCompl, LieSubmodule.mem_top, forall_true_left] intro y rw [LieModule.traceForm_apply_apply] exact LieSubmodule.traceForm_eq_zero_of_isTrivial I I (by simp) _ hx end LieIdeal open LieModule Module open Submodule (span subset_span) namespace LieModule variable [Field K] [LieAlgebra K L] [Module K M] [LieModule K L M] [FiniteDimensional K M] variable [LieRing.IsNilpotent L] [LinearWeights K L M] [IsTriangularizable K L M] lemma traceForm_eq_sum_finrank_nsmul_mul (x y : L) : traceForm K L M x y = ∑ χ : Weight K L M, finrank K (genWeightSpace M χ) • (χ x * χ y) := by have hxy : ∀ χ : Weight K L M, MapsTo (toEnd K L M x ∘ₗ toEnd K L M y) (genWeightSpace M χ) (genWeightSpace M χ) := fun χ m hm ↦ LieSubmodule.lie_mem _ <| LieSubmodule.lie_mem _ hm classical have hds := DirectSum.isInternal_submodule_of_iSupIndep_of_iSup_eq_top (LieSubmodule.iSupIndep_toSubmodule.mpr <| iSupIndep_genWeightSpace' K L M) (LieSubmodule.iSup_toSubmodule_eq_top.mpr <| iSup_genWeightSpace_eq_top' K L M) simp_rw [traceForm_apply_apply, LinearMap.trace_eq_sum_trace_restrict hds hxy, ← traceForm_genWeightSpace_eq K L M _ x y] rfl /-- See also `LieModule.traceForm_eq_sum_finrank_nsmul'` for an expression omitting the zero weights. -/ lemma traceForm_eq_sum_finrank_nsmul : traceForm K L M = ∑ χ : Weight K L M, finrank K (genWeightSpace M χ) • (χ : L →ₗ[K] K).smulRight (χ : L →ₗ[K] K) := by ext rw [traceForm_eq_sum_finrank_nsmul_mul, ← Finset.sum_attach] simp /-- A variant of `LieModule.traceForm_eq_sum_finrank_nsmul` in which the sum is taken only over the non-zero weights. -/ lemma traceForm_eq_sum_finrank_nsmul' : traceForm K L M = ∑ χ ∈ {χ : Weight K L M | χ.IsNonZero}, finrank K (genWeightSpace M χ) • (χ : L →ₗ[K] K).smulRight (χ : L →ₗ[K] K) := by classical suffices ∑ χ ∈ {χ : Weight K L M | χ.IsZero}, finrank K (genWeightSpace M χ) • (χ : L →ₗ[K] K).smulRight (χ : L →ₗ[K] K) = 0 by rw [traceForm_eq_sum_finrank_nsmul, ← Finset.sum_filter_add_sum_filter_not (p := fun χ : Weight K L M ↦ χ.IsNonZero)] simp [this] refine Finset.sum_eq_zero fun χ hχ ↦ ?_ replace hχ : (χ : L →ₗ[K] K) = 0 := by simpa [← Weight.coe_toLinear_eq_zero_iff] using hχ simp [hχ] -- The reverse inclusion should also hold: TODO prove this! lemma range_traceForm_le_span_weight : LinearMap.range (traceForm K L M) ≤ span K (range (Weight.toLinear K L M)) := by rintro - ⟨x, rfl⟩ rw [LieModule.traceForm_eq_sum_finrank_nsmul, LinearMap.coeFn_sum, Finset.sum_apply] refine Submodule.sum_mem _ fun χ _ ↦ ?_ simp_rw [LinearMap.smul_apply, LinearMap.coe_smulRight, Weight.toLinear_apply, ← Nat.cast_smul_eq_nsmul K] exact Submodule.smul_mem _ _ <| Submodule.smul_mem _ _ <| subset_span <| mem_range_self χ end LieModule end LieAlgebra
.lake/packages/mathlib/Mathlib/Algebra/Lie/Classical.lean
import Mathlib.Data.Matrix.Basis import Mathlib.Data.Matrix.DMatrix import Mathlib.Algebra.Lie.Abelian import Mathlib.LinearAlgebra.Matrix.Trace import Mathlib.Algebra.Lie.SkewAdjoint import Mathlib.LinearAlgebra.SymplecticGroup /-! # Classical Lie algebras This file is the place to find definitions and basic properties of the classical Lie algebras: * Aₗ = sl(l+1) * Bₗ ≃ so(l+1, l) ≃ so(2l+1) * Cₗ = sp(l) * Dₗ ≃ so(l, l) ≃ so(2l) ## Main definitions * `LieAlgebra.SpecialLinear.sl` * `LieAlgebra.Symplectic.sp` * `LieAlgebra.Orthogonal.so` * `LieAlgebra.Orthogonal.so'` * `LieAlgebra.Orthogonal.soIndefiniteEquiv` * `LieAlgebra.Orthogonal.typeD` * `LieAlgebra.Orthogonal.typeB` * `LieAlgebra.Orthogonal.typeDEquivSo'` * `LieAlgebra.Orthogonal.typeBEquivSo'` ## Implementation notes ### Matrices or endomorphisms Given a finite type and a commutative ring, the corresponding square matrices are equivalent to the endomorphisms of the corresponding finite-rank free module as Lie algebras, see `lieEquivMatrix'`. We can thus define the classical Lie algebras as Lie subalgebras either of matrices or of endomorphisms. We have opted for the former. At the time of writing (August 2020) it is unclear which approach should be preferred so the choice should be assumed to be somewhat arbitrary. ### Diagonal quadratic form or diagonal Cartan subalgebra For the algebras of type `B` and `D`, there are two natural definitions. For example since the `2l × 2l` matrix: $$ J = \left[\begin{array}{cc} 0_l & 1_l\\ 1_l & 0_l \end{array}\right] $$ defines a symmetric bilinear form equivalent to that defined by the identity matrix `I`, we can define the algebras of type `D` to be the Lie subalgebra of skew-adjoint matrices either for `J` or for `I`. Both definitions have their advantages (in particular the `J`-skew-adjoint matrices define a Lie algebra for which the diagonal matrices form a Cartan subalgebra) and so we provide both. We thus also provide equivalences `typeDEquivSo'`, `soIndefiniteEquiv` which show the two definitions are equivalent. Similarly for the algebras of type `B`. ## Tags classical lie algebra, special linear, symplectic, orthogonal -/ universe u₁ u₂ namespace LieAlgebra open Matrix open scoped Matrix variable (n p q l : Type*) (R : Type u₂) variable [DecidableEq n] [DecidableEq p] [DecidableEq q] [DecidableEq l] variable [CommRing R] @[simp] theorem matrix_trace_commutator_zero [Fintype n] (X Y : Matrix n n R) : Matrix.trace ⁅X, Y⁆ = 0 := calc _ = Matrix.trace (X * Y) - Matrix.trace (Y * X) := trace_sub _ _ _ = Matrix.trace (X * Y) - Matrix.trace (X * Y) := (congr_arg (fun x => _ - x) (Matrix.trace_mul_comm Y X)) _ = 0 := sub_self _ namespace SpecialLinear /-- The special linear Lie algebra: square matrices of trace zero. -/ def sl [Fintype n] : LieSubalgebra R (Matrix n n R) := { LinearMap.ker (Matrix.traceLinearMap n R R) with lie_mem' := fun _ _ => LinearMap.mem_ker.2 <| matrix_trace_commutator_zero _ _ _ _ } theorem sl_bracket [Fintype n] (A B : sl n R) : ⁅A, B⁆.val = A.val * B.val - B.val * A.val := rfl section ElementaryBasis variable {n R} [Fintype n] (i j k : n) /-- When `i ≠ j`, the single-element matrices are elements of `sl n R`. Along with some elements produced by `singleSubSingle`, these form a natural basis of `sl n R`. -/ def single (h : i ≠ j) : R →ₗ[R] sl n R := Matrix.singleLinearMap R i j |>.codRestrict _ fun r => Matrix.trace_single_eq_of_ne i j r h @[deprecated (since := "2025-05-06")] alias Eb := single @[simp] theorem val_single (h : i ≠ j) (r : R) : (single i j h r).val = Matrix.single i j r := rfl @[deprecated (since := "2025-05-06")] alias eb_val := val_single /-- The matrices with matching positive and negative elements on the diagonal are elements of `sl n R`. Along with `single`, a subset of these form a basis for `sl n R`. -/ def singleSubSingle : R →ₗ[R] sl n R := LinearMap.codRestrict _ (Matrix.singleLinearMap R i i - Matrix.singleLinearMap R j j) fun r => LinearMap.sub_mem_ker_iff.mpr <| by simp @[simp] theorem val_singleSubSingle (r : R) : (singleSubSingle i j r).val = Matrix.single i i r - Matrix.single j j r := rfl @[simp] theorem singleSubSingle_add_singleSubSingle (r : R) : singleSubSingle i j r + singleSubSingle j k r = singleSubSingle i k r := by ext : 1; simp @[simp] theorem singleSubSingle_sub_singleSubSingle (r : R) : singleSubSingle i k r - singleSubSingle i j r = singleSubSingle j k r := by ext : 1; simp @[simp] theorem singleSubSingle_sub_singleSubSingle' (r : R) : singleSubSingle i k r - singleSubSingle j k r = singleSubSingle i j r := by ext : 1; simp end ElementaryBasis theorem sl_non_abelian [Fintype n] [Nontrivial R] (h : 1 < Fintype.card n) : ¬IsLieAbelian (sl n R) := by rcases Fintype.exists_pair_of_one_lt_card h with ⟨i, j, hij⟩ let A := single i j hij (1 : R) let B := single j i hij.symm (1 : R) intro c have c' : A.val * B.val = B.val * A.val := by rw [← sub_eq_zero, ← sl_bracket, c.trivial, ZeroMemClass.coe_zero] simpa [A, B, Matrix.single, Matrix.mul_apply, hij.symm] using congr_fun (congr_fun c' i) i end SpecialLinear namespace Symplectic /-- The symplectic Lie algebra: skew-adjoint matrices with respect to the canonical skew-symmetric bilinear form. -/ def sp [Fintype l] : LieSubalgebra R (Matrix (l ⊕ l) (l ⊕ l) R) := skewAdjointMatricesLieSubalgebra (Matrix.J l R) end Symplectic namespace Orthogonal /-- The definite orthogonal Lie subalgebra: skew-adjoint matrices with respect to the symmetric bilinear form defined by the identity matrix. -/ def so [Fintype n] : LieSubalgebra R (Matrix n n R) := skewAdjointMatricesLieSubalgebra (1 : Matrix n n R) @[simp] theorem mem_so [Fintype n] (A : Matrix n n R) : A ∈ so n R ↔ Aᵀ = -A := by rw [so, mem_skewAdjointMatricesLieSubalgebra, mem_skewAdjointMatricesSubmodule] simp only [Matrix.IsSkewAdjoint, Matrix.IsAdjointPair, Matrix.mul_one, Matrix.one_mul] /-- The indefinite diagonal matrix with `p` 1s and `q` -1s. -/ def indefiniteDiagonal : Matrix (p ⊕ q) (p ⊕ q) R := Matrix.diagonal <| Sum.elim (fun _ => 1) fun _ => -1 /-- The indefinite orthogonal Lie subalgebra: skew-adjoint matrices with respect to the symmetric bilinear form defined by the indefinite diagonal matrix. -/ def so' [Fintype p] [Fintype q] : LieSubalgebra R (Matrix (p ⊕ q) (p ⊕ q) R) := skewAdjointMatricesLieSubalgebra <| indefiniteDiagonal p q R /-- A matrix for transforming the indefinite diagonal bilinear form into the definite one, provided the parameter `i` is a square root of -1. -/ def Pso (i : R) : Matrix (p ⊕ q) (p ⊕ q) R := Matrix.diagonal <| Sum.elim (fun _ => 1) fun _ => i variable [Fintype p] [Fintype q] theorem pso_inv {i : R} (hi : i * i = -1) : Pso p q R i * Pso p q R (-i) = 1 := by ext (x y); rcases x with ⟨x⟩|⟨x⟩ <;> rcases y with ⟨y⟩|⟨y⟩ · -- x y : p by_cases h : x = y <;> simp [Pso, h, one_apply] · -- x : p, y : q simp [Pso] · -- x : q, y : p simp [Pso] · -- x y : q by_cases h : x = y <;> simp [Pso, h, hi, one_apply] /-- There is a constructive inverse of `Pso p q R i`. -/ def invertiblePso {i : R} (hi : i * i = -1) : Invertible (Pso p q R i) := invertibleOfRightInverse _ _ (pso_inv p q R hi) theorem indefiniteDiagonal_transform {i : R} (hi : i * i = -1) : (Pso p q R i)ᵀ * indefiniteDiagonal p q R * Pso p q R i = 1 := by ext (x y); rcases x with ⟨x⟩|⟨x⟩ <;> rcases y with ⟨y⟩|⟨y⟩ · -- x y : p by_cases h : x = y <;> simp [Pso, indefiniteDiagonal, h, one_apply] · -- x : p, y : q simp [Pso, indefiniteDiagonal] · -- x : q, y : p simp [Pso, indefiniteDiagonal] · -- x y : q by_cases h : x = y <;> simp [Pso, indefiniteDiagonal, h, hi, one_apply] /-- An equivalence between the indefinite and definite orthogonal Lie algebras, over a ring containing a square root of -1. -/ noncomputable def soIndefiniteEquiv {i : R} (hi : i * i = -1) : so' p q R ≃ₗ⁅R⁆ so (p ⊕ q) R := by apply (skewAdjointMatricesLieSubalgebraEquiv (indefiniteDiagonal p q R) (Pso p q R i) (invertiblePso p q R hi)).trans apply LieEquiv.ofEq ext A; rw [indefiniteDiagonal_transform p q R hi]; rfl theorem soIndefiniteEquiv_apply {i : R} (hi : i * i = -1) (A : so' p q R) : (soIndefiniteEquiv p q R hi A : Matrix (p ⊕ q) (p ⊕ q) R) = (Pso p q R i)⁻¹ * (A : Matrix (p ⊕ q) (p ⊕ q) R) * Pso p q R i := by rw [soIndefiniteEquiv, LieEquiv.trans_apply, LieEquiv.ofEq_apply] grind [skewAdjointMatricesLieSubalgebraEquiv_apply] /-- A matrix defining a canonical even-rank symmetric bilinear form. It looks like this as a `2l x 2l` matrix of `l x l` blocks: [ 0 1 ] [ 1 0 ] -/ def JD : Matrix (l ⊕ l) (l ⊕ l) R := Matrix.fromBlocks 0 1 1 0 /-- The classical Lie algebra of type D as a Lie subalgebra of matrices associated to the matrix `JD`. -/ def typeD [Fintype l] := skewAdjointMatricesLieSubalgebra (JD l R) /-- A matrix transforming the bilinear form defined by the matrix `JD` into a split-signature diagonal matrix. It looks like this as a `2l x 2l` matrix of `l x l` blocks: [ 1 -1 ] [ 1 1 ] -/ def PD : Matrix (l ⊕ l) (l ⊕ l) R := Matrix.fromBlocks 1 (-1) 1 1 /-- The split-signature diagonal matrix. -/ def S := indefiniteDiagonal l l R theorem s_as_blocks : S l R = Matrix.fromBlocks 1 0 0 (-1) := by rw [← Matrix.diagonal_one, Matrix.diagonal_neg, Matrix.fromBlocks_diagonal] rfl theorem jd_transform [Fintype l] : (PD l R)ᵀ * JD l R * PD l R = (2 : R) • S l R := by have h : (PD l R)ᵀ * JD l R = Matrix.fromBlocks 1 1 1 (-1) := by simp [PD, JD, Matrix.fromBlocks_transpose, Matrix.fromBlocks_multiply] rw [h, PD, s_as_blocks, Matrix.fromBlocks_multiply, Matrix.fromBlocks_smul] simp [two_smul] theorem pd_inv [Fintype l] [Invertible (2 : R)] : PD l R * ⅟(2 : R) • (PD l R)ᵀ = 1 := by rw [PD, Matrix.fromBlocks_transpose, Matrix.fromBlocks_smul, Matrix.fromBlocks_multiply] simp instance invertiblePD [Fintype l] [Invertible (2 : R)] : Invertible (PD l R) := invertibleOfRightInverse _ _ (pd_inv l R) /-- An equivalence between two possible definitions of the classical Lie algebra of type D. -/ noncomputable def typeDEquivSo' [Fintype l] [Invertible (2 : R)] : typeD l R ≃ₗ⁅R⁆ so' l l R := by apply (skewAdjointMatricesLieSubalgebraEquiv (JD l R) (PD l R) (by infer_instance)).trans apply LieEquiv.ofEq ext A rw [jd_transform, ← val_unitOfInvertible (2 : R), ← Units.smul_def, LieSubalgebra.mem_coe, mem_skewAdjointMatricesLieSubalgebra_unit_smul] rfl /-- A matrix defining a canonical odd-rank symmetric bilinear form. It looks like this as a `(2l+1) x (2l+1)` matrix of blocks: [ 2 0 0 ] [ 0 0 1 ] [ 0 1 0 ] where sizes of the blocks are: [`1 x 1` `1 x l` `1 x l`] [`l x 1` `l x l` `l x l`] [`l x 1` `l x l` `l x l`] -/ def JB := Matrix.fromBlocks ((2 : R) • (1 : Matrix Unit Unit R)) 0 0 (JD l R) /-- The classical Lie algebra of type B as a Lie subalgebra of matrices associated to the matrix `JB`. -/ def typeB [Fintype l] := skewAdjointMatricesLieSubalgebra (JB l R) /-- A matrix transforming the bilinear form defined by the matrix `JB` into an almost-split-signature diagonal matrix. It looks like this as a `(2l+1) x (2l+1)` matrix of blocks: [ 1 0 0 ] [ 0 1 -1 ] [ 0 1 1 ] where sizes of the blocks are: [`1 x 1` `1 x l` `1 x l`] [`l x 1` `l x l` `l x l`] [`l x 1` `l x l` `l x l`] -/ def PB := Matrix.fromBlocks (1 : Matrix Unit Unit R) 0 0 (PD l R) variable [Fintype l] theorem pb_inv [Invertible (2 : R)] : PB l R * Matrix.fromBlocks 1 0 0 (⅟(PD l R)) = 1 := by rw [PB, Matrix.fromBlocks_multiply, mul_invOf_self] simp only [Matrix.mul_zero, Matrix.mul_one, Matrix.zero_mul, zero_add, add_zero, Matrix.fromBlocks_one] instance invertiblePB [Invertible (2 : R)] : Invertible (PB l R) := invertibleOfRightInverse _ _ (pb_inv l R) theorem jb_transform : (PB l R)ᵀ * JB l R * PB l R = (2 : R) • Matrix.fromBlocks 1 0 0 (S l R) := by simp [PB, JB, jd_transform, Matrix.fromBlocks_transpose, Matrix.fromBlocks_multiply, Matrix.fromBlocks_smul] theorem indefiniteDiagonal_assoc : indefiniteDiagonal (Unit ⊕ l) l R = Matrix.reindexLieEquiv (Equiv.sumAssoc Unit l l).symm (Matrix.fromBlocks 1 0 0 (indefiniteDiagonal l l R)) := by ext ⟨⟨i₁ | i₂⟩ | i₃⟩ ⟨⟨j₁ | j₂⟩ | j₃⟩ <;> simp only [indefiniteDiagonal, Matrix.diagonal_apply, Equiv.sumAssoc_apply_inl_inl, Matrix.reindexLieEquiv_apply, Matrix.submatrix_apply, Equiv.symm_symm, Matrix.reindex_apply, Sum.elim_inl, if_true, Matrix.one_apply_eq, Matrix.fromBlocks_apply₁₁, Equiv.sumAssoc_apply_inl_inr, if_false, Matrix.fromBlocks_apply₁₂, Matrix.fromBlocks_apply₂₁, Matrix.fromBlocks_apply₂₂, Equiv.sumAssoc_apply_inr, Sum.elim_inr, Sum.inl_injective.eq_iff, Sum.inr_injective.eq_iff, reduceCtorEq] <;> congr 1 /-- An equivalence between two possible definitions of the classical Lie algebra of type B. -/ noncomputable def typeBEquivSo' [Invertible (2 : R)] : typeB l R ≃ₗ⁅R⁆ so' (Unit ⊕ l) l R := by apply (skewAdjointMatricesLieSubalgebraEquiv (JB l R) (PB l R) (by infer_instance)).trans symm apply (skewAdjointMatricesLieSubalgebraEquivTranspose (indefiniteDiagonal (Sum Unit l) l R) (Matrix.reindexAlgEquiv _ _ (Equiv.sumAssoc PUnit l l)) (Matrix.transpose_reindex _ _)).trans apply LieEquiv.ofEq ext A rw [jb_transform, ← val_unitOfInvertible (2 : R), ← Units.smul_def, LieSubalgebra.mem_coe, LieSubalgebra.mem_coe, mem_skewAdjointMatricesLieSubalgebra_unit_smul] simp [indefiniteDiagonal_assoc, S] end Orthogonal end LieAlgebra
.lake/packages/mathlib/Mathlib/Algebra/Lie/BaseChange.lean
import Mathlib.Algebra.Algebra.RestrictScalars import Mathlib.Algebra.Lie.TensorProduct /-! # Extension and restriction of scalars for Lie algebras and Lie modules Lie algebras and their representations have a well-behaved theory of extension and restriction of scalars. ## Main definitions * `LieAlgebra.ExtendScalars.instLieAlgebra` * `LieAlgebra.ExtendScalars.instLieModule` * `LieAlgebra.RestrictScalars.lieAlgebra` ## Tags lie ring, lie algebra, extension of scalars, restriction of scalars, base change -/ open scoped TensorProduct variable (R A L M : Type*) namespace LieAlgebra namespace ExtendScalars variable [CommRing R] [CommRing A] [Algebra R A] [LieRing L] [LieAlgebra R L] [AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M] /-- The Lie bracket on the extension of a Lie algebra `L` over `R` by an algebra `A` over `R`. -/ private def bracket' : A ⊗[R] L →ₗ[A] A ⊗[R] M →ₗ[A] A ⊗[R] M := TensorProduct.curry <| TensorProduct.AlgebraTensorModule.map (LinearMap.mul' A A) (LieModule.toModuleHom R L M : L ⊗[R] M →ₗ[R] M) ∘ₗ (TensorProduct.AlgebraTensorModule.tensorTensorTensorComm R R A A A L A M).toLinearMap @[simp] private theorem bracket'_tmul (s t : A) (x : L) (m : M) : bracket' R A L M (s ⊗ₜ[R] x) (t ⊗ₜ[R] m) = (s * t) ⊗ₜ ⁅x, m⁆ := rfl instance : Bracket (A ⊗[R] L) (A ⊗[R] M) where bracket x m := bracket' R A L M x m private theorem bracket_def (x : A ⊗[R] L) (m : A ⊗[R] M) : ⁅x, m⁆ = bracket' R A L M x m := rfl @[simp] theorem bracket_tmul (s t : A) (x : L) (y : M) : ⁅s ⊗ₜ[R] x, t ⊗ₜ[R] y⁆ = (s * t) ⊗ₜ ⁅x, y⁆ := rfl private theorem bracket_lie_self (x : A ⊗[R] L) : ⁅x, x⁆ = 0 := by simp only [bracket_def] refine x.induction_on ?_ ?_ ?_ · simp only [LinearMap.map_zero] · intro a l simp only [bracket'_tmul, TensorProduct.tmul_zero, lie_self] · intro z₁ z₂ h₁ h₂ suffices bracket' R A L L z₁ z₂ + bracket' R A L L z₂ z₁ = 0 by rw [LinearMap.map_add, LinearMap.map_add, LinearMap.add_apply, LinearMap.add_apply, h₁, h₂, zero_add, add_zero, add_comm, this] refine z₁.induction_on ?_ ?_ ?_ · simp only [LinearMap.map_zero, add_zero, LinearMap.zero_apply] · intro a₁ l₁; refine z₂.induction_on ?_ ?_ ?_ · simp only [LinearMap.map_zero, add_zero, LinearMap.zero_apply] · intro a₂ l₂ simp only [← lie_skew l₂ l₁, mul_comm a₁ a₂, TensorProduct.tmul_neg, bracket'_tmul, add_neg_cancel] · intro y₁ y₂ hy₁ hy₂ simp only [hy₁, hy₂, add_add_add_comm, add_zero, LinearMap.add_apply, LinearMap.map_add] · intro y₁ y₂ hy₁ hy₂ simp only [add_add_add_comm, hy₁, hy₂, add_zero, LinearMap.add_apply, LinearMap.map_add] private theorem bracket_leibniz_lie (x y : A ⊗[R] L) (z : A ⊗[R] M) : ⁅x, ⁅y, z⁆⁆ = ⁅⁅x, y⁆, z⁆ + ⁅y, ⁅x, z⁆⁆ := by simp only [bracket_def] refine x.induction_on ?_ ?_ ?_ · simp only [LinearMap.map_zero, add_zero, LinearMap.zero_apply] · intro a₁ l₁ refine y.induction_on ?_ ?_ ?_ · simp only [LinearMap.map_zero, add_zero, LinearMap.zero_apply] · intro a₂ l₂ refine z.induction_on ?_ ?_ ?_ · simp only [LinearMap.map_zero, add_zero] · intro a₃ l₃; simp only [bracket'_tmul] rw [mul_left_comm a₂ a₁ a₃, mul_assoc, leibniz_lie, TensorProduct.tmul_add] · grind · grind [LinearMap.add_apply] · grind [LinearMap.add_apply] instance instLieRing : LieRing (A ⊗[R] L) where add_lie x y z := by simp only [bracket_def, LinearMap.add_apply, LinearMap.map_add] lie_add x y z := by simp only [bracket_def, LinearMap.map_add] lie_self := bracket_lie_self R A L leibniz_lie := bracket_leibniz_lie R A L L instance instLieAlgebra : LieAlgebra A (A ⊗[R] L) where lie_smul _a _x _y := map_smul _ _ _ instance instLieRingModule : LieRingModule (A ⊗[R] L) (A ⊗[R] M) where add_lie x y z := by simp only [bracket_def, LinearMap.add_apply, LinearMap.map_add] lie_add x y z := by simp only [bracket_def, LinearMap.map_add] leibniz_lie := bracket_leibniz_lie R A L M instance instLieModule : LieModule A (A ⊗[R] L) (A ⊗[R] M) where smul_lie t x m := by simp only [bracket_def, map_smul, LinearMap.smul_apply] lie_smul _ _ _ := map_smul _ _ _ end ExtendScalars namespace RestrictScalars open RestrictScalars variable [h : LieRing L] instance : LieRing (RestrictScalars R A L) := h variable [CommRing A] [LieAlgebra A L] instance lieAlgebra [CommRing R] [Algebra R A] : LieAlgebra R (RestrictScalars R A L) where lie_smul t x y := (lie_smul (algebraMap R A t) (RestrictScalars.addEquiv R A L x) (RestrictScalars.addEquiv R A L y) :) end RestrictScalars end LieAlgebra section ExtendScalars variable [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 LieModule.toEnd_baseChange (x : L) : toEnd A (A ⊗[R] L) (A ⊗[R] M) (1 ⊗ₜ x) = (toEnd R L M x).baseChange A := by ext; simp namespace LieSubmodule variable (N : LieSubmodule R L M) open LieModule variable {R L M} in /-- If `A` is an `R`-algebra, any Lie submodule of a Lie module `M` with coefficients in `R` may be pushed forward to a Lie submodule of `A ⊗ M` with coefficients in `A`. This "base change" operation is also known as "extension of scalars". -/ def baseChange : LieSubmodule A (A ⊗[R] L) (A ⊗[R] M) := { (N : Submodule R M).baseChange A with lie_mem := by intro x m hm rw [Submodule.mem_carrier, SetLike.mem_coe] at hm ⊢ rw [Submodule.baseChange_eq_span] at hm obtain ⟨c, rfl⟩ := (Finsupp.mem_span_iff_linearCombination _ _ _).mp hm refine x.induction_on (by simp) (fun a y ↦ ?_) (fun y z hy hz ↦ ?_) · change toEnd A (A ⊗[R] L) (A ⊗[R] M) _ _ ∈ _ simp_rw [Finsupp.linearCombination_apply, Finsupp.sum, map_sum, map_smul, toEnd_apply_apply] refine Submodule.sum_mem _ fun ⟨_, n, hn, h⟩ _ ↦ Submodule.smul_mem _ _ ?_ rw [Subtype.coe_mk, ← h] exact Submodule.tmul_mem_baseChange_of_mem _ (N.lie_mem hn) · rw [add_lie] exact ((N : Submodule R M).baseChange A).add_mem hy hz } @[simp] lemma coe_baseChange : (N.baseChange A : Submodule A (A ⊗[R] M)) = (N : Submodule R M).baseChange A := rfl variable {N} variable {R A L M} in lemma tmul_mem_baseChange_of_mem (a : A) {m : M} (hm : m ∈ N) : a ⊗ₜ[R] m ∈ N.baseChange A := (N : Submodule R M).tmul_mem_baseChange_of_mem a hm lemma mem_baseChange_iff {m : A ⊗[R] M} : m ∈ N.baseChange A ↔ m ∈ Submodule.span A ((N : Submodule R M).map (TensorProduct.mk R A M 1)) := by rw [← Submodule.baseChange_eq_span]; rfl @[simp] lemma baseChange_bot : (⊥ : LieSubmodule R L M).baseChange A = ⊥ := by simp only [baseChange, bot_toSubmodule, Submodule.baseChange_bot] rfl @[simp] lemma baseChange_top : (⊤ : LieSubmodule R L M).baseChange A = ⊤ := by simp only [baseChange, top_toSubmodule, Submodule.baseChange_top] rfl lemma lie_baseChange {I : LieIdeal R L} {N : LieSubmodule R L M} : ⁅I, N⁆.baseChange A = ⁅I.baseChange A, N.baseChange A⁆ := by set s : Set (A ⊗[R] M) := { m | ∃ x ∈ I, ∃ n ∈ N, 1 ⊗ₜ ⁅x, n⁆ = m} have : (TensorProduct.mk R A M 1) '' {m | ∃ x ∈ I, ∃ n ∈ N, ⁅x, n⁆ = m} = s := by ext; simp [s] rw [← toSubmodule_inj, coe_baseChange, lieIdeal_oper_eq_linear_span', Submodule.baseChange_span, this, lieIdeal_oper_eq_linear_span'] refine le_antisymm (Submodule.span_mono ?_) (Submodule.span_le.mpr ?_) · rintro - ⟨x, hx, m, hm, rfl⟩ exact ⟨1 ⊗ₜ x, tmul_mem_baseChange_of_mem 1 hx, 1 ⊗ₜ m, tmul_mem_baseChange_of_mem 1 hm, by simp⟩ · rintro - ⟨x, hx, m, hm, rfl⟩ rw [mem_baseChange_iff] at hx hm refine Submodule.span_induction₂ (p := fun x m _ _ ↦ ⁅x, m⁆ ∈ Submodule.span A s) ?_ (by simp) (by simp) ?_ ?_ ?_ ?_ hx hm · rintro - - ⟨x, hx, rfl⟩ ⟨y, hy, rfl⟩; exact Submodule.subset_span ⟨x, hx, y, hy, by simp⟩ all_goals { intros; simp [add_mem, Submodule.smul_mem, *] } end LieSubmodule end ExtendScalars
.lake/packages/mathlib/Mathlib/Algebra/Lie/Free.lean
import Mathlib.Algebra.FreeNonUnitalNonAssocAlgebra import Mathlib.Algebra.Lie.NonUnitalNonAssocAlgebra import Mathlib.Algebra.Lie.UniversalEnveloping import Mathlib.GroupTheory.GroupAction.Ring /-! # Free Lie algebras Given a commutative ring `R` and a type `X` we construct the free Lie algebra on `X` with coefficients in `R` together with its universal property. ## Main definitions * `FreeLieAlgebra` * `FreeLieAlgebra.lift` * `FreeLieAlgebra.of` * `FreeLieAlgebra.universalEnvelopingEquivFreeAlgebra` ## Implementation details ### Quotient of free non-unital, non-associative algebra We follow [N. Bourbaki, *Lie Groups and Lie Algebras, Chapters 1--3*](bourbaki1975) and construct the free Lie algebra as a quotient of the free non-unital, non-associative algebra. Since we do not currently have definitions of ideals, lattices of ideals, and quotients for `NonUnitalNonAssocSemiring`, we construct our quotient using the low-level `Quot` function on an inductively-defined relation. ### Alternative construction (needs PBW) An alternative construction of the free Lie algebra on `X` is to start with the free unital associative algebra on `X`, regard it as a Lie algebra via the ring commutator, and take its smallest Lie subalgebra containing `X`. I.e.: `LieSubalgebra.lieSpan R (FreeAlgebra R X) (Set.range (FreeAlgebra.ι R))`. However with this definition there does not seem to be an easy proof that the required universal property holds, and I don't know of a proof that avoids invoking the Poincaré–Birkhoff–Witt theorem. A related MathOverflow question is [this one](https://mathoverflow.net/questions/396680/). ## Tags lie algebra, free algebra, non-unital, non-associative, universal property, forgetful functor, adjoint functor -/ universe u v w noncomputable section variable (R : Type u) (X : Type v) [CommRing R] /- We save characters by using Bourbaki's name `lib` (as in «libre») for `FreeNonUnitalNonAssocAlgebra` in this file. -/ local notation "lib" => FreeNonUnitalNonAssocAlgebra local notation "lib.lift" => FreeNonUnitalNonAssocAlgebra.lift local notation "lib.of" => FreeNonUnitalNonAssocAlgebra.of local notation "lib.lift_of_apply" => FreeNonUnitalNonAssocAlgebra.lift_of_apply local notation "lib.lift_comp_of" => FreeNonUnitalNonAssocAlgebra.lift_comp_of namespace FreeLieAlgebra /-- The quotient of `lib R X` by the equivalence relation generated by this relation will give us the free Lie algebra. -/ inductive Rel : lib R X → lib R X → Prop | lie_self (a : lib R X) : Rel (a * a) 0 | leibniz_lie (a b c : lib R X) : Rel (a * (b * c)) (a * b * c + b * (a * c)) | smul (t : R) {a b : lib R X} : Rel a b → Rel (t • a) (t • b) | add_right {a b : lib R X} (c : lib R X) : Rel a b → Rel (a + c) (b + c) | mul_left (a : lib R X) {b c : lib R X} : Rel b c → Rel (a * b) (a * c) | mul_right {a b : lib R X} (c : lib R X) : Rel a b → Rel (a * c) (b * c) variable {R X} theorem Rel.addLeft (a : lib R X) {b c : lib R X} (h : Rel R X b c) : Rel R X (a + b) (a + c) := by rw [add_comm _ b, add_comm _ c]; exact h.add_right _ theorem Rel.neg {a b : lib R X} (h : Rel R X a b) : Rel R X (-a) (-b) := by simpa only [neg_one_smul] using h.smul (-1) theorem Rel.subLeft (a : lib R X) {b c : lib R X} (h : Rel R X b c) : Rel R X (a - b) (a - c) := by simpa only [sub_eq_add_neg] using h.neg.addLeft a theorem Rel.subRight {a b : lib R X} (c : lib R X) (h : Rel R X a b) : Rel R X (a - c) (b - c) := by simpa only [sub_eq_add_neg] using h.add_right (-c) theorem Rel.smulOfTower {S : Type*} [Monoid S] [DistribMulAction S R] [IsScalarTower S R R] (t : S) (a b : lib R X) (h : Rel R X a b) : Rel R X (t • a) (t • b) := by rw [← smul_one_smul R t a, ← smul_one_smul R t b] exact h.smul _ end FreeLieAlgebra /-- If `α` is a type, and `R` is a commutative ring, then `FreeLieAlgebra R α` is the free Lie algebra over `R` generated by `α`. This is a Lie algebra over `R` equipped with a function `FreeLieAlgebra.of R : α → FreeLieAlgebra R α` which has the following universal property: if `L` is any Lie algebra over `R`, and `f : α → L` is any function, then this function is the composite of `FreeLieAlgebra.of R` and a unique Lie algebra homomorphism `FreeLieAlgebra.lift R f : FreeLieAlgebra R α →ₗ⁅R⁆ L`. A typical element of `FreeLieAlgebra R α` is a `R`-linear combination of formal brackets of elements of `α`. For example if `x` and `y` are terms of type `α` and `a` and `b` are term of type `R` then `(3 * a * a) • ⁅⁅x, y⁆, x⁆ - (2 * b - 1) • ⁅y, x⁆` is a "typical" element of `FreeLieAlgebra R α`. -/ def FreeLieAlgebra := Quot (FreeLieAlgebra.Rel R X) instance : Inhabited (FreeLieAlgebra R X) := by rw [FreeLieAlgebra]; infer_instance namespace FreeLieAlgebra instance {S : Type*} [Monoid S] [DistribMulAction S R] [IsScalarTower S R R] : SMul S (FreeLieAlgebra R X) where smul t := Quot.map (t • ·) (Rel.smulOfTower t) instance {S : Type*} [Monoid S] [DistribMulAction S R] [DistribMulAction Sᵐᵒᵖ R] [IsScalarTower S R R] [IsCentralScalar S R] : IsCentralScalar S (FreeLieAlgebra R X) where op_smul_eq_smul t := Quot.ind fun a => congr_arg (Quot.mk _) (op_smul_eq_smul t a) instance : Zero (FreeLieAlgebra R X) where zero := Quot.mk _ 0 instance : Add (FreeLieAlgebra R X) where add := Quot.map₂ (· + ·) (fun _ _ _ => Rel.addLeft _) fun _ _ _ => Rel.add_right _ instance : Neg (FreeLieAlgebra R X) where neg := Quot.map Neg.neg fun _ _ => Rel.neg instance : Sub (FreeLieAlgebra R X) where sub := Quot.map₂ Sub.sub (fun _ _ _ => Rel.subLeft _) fun _ _ _ => Rel.subRight _ instance : AddGroup (FreeLieAlgebra R X) := Function.Surjective.addGroup (Quot.mk _) Quot.mk_surjective rfl (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl instance : AddCommSemigroup (FreeLieAlgebra R X) := Function.Surjective.addCommSemigroup (Quot.mk _) Quot.mk_surjective fun _ _ => rfl instance : AddCommGroup (FreeLieAlgebra R X) := { (inferInstance : AddGroup (FreeLieAlgebra R X)), (inferInstance : AddCommSemigroup (FreeLieAlgebra R X)) with } instance {S : Type*} [Semiring S] [Module S R] [IsScalarTower S R R] : Module S (FreeLieAlgebra R X) := Function.Surjective.module S ⟨⟨Quot.mk (Rel R X), rfl⟩, fun _ _ => rfl⟩ Quot.mk_surjective (fun _ _ => rfl) /-- Note that here we turn the `Mul` coming from the `NonUnitalNonAssocSemiring` structure on `lib R X` into a `Bracket` on `FreeLieAlgebra`. -/ instance : LieRing (FreeLieAlgebra R X) where bracket := Quot.map₂ (· * ·) (fun _ _ _ => Rel.mul_left _) fun _ _ _ => Rel.mul_right _ add_lie := by rintro ⟨a⟩ ⟨b⟩ ⟨c⟩; change Quot.mk _ _ = Quot.mk _ _; simp_rw [add_mul] lie_add := by rintro ⟨a⟩ ⟨b⟩ ⟨c⟩; change Quot.mk _ _ = Quot.mk _ _; simp_rw [mul_add] lie_self := by rintro ⟨a⟩; exact Quot.sound (Rel.lie_self a) leibniz_lie := by rintro ⟨a⟩ ⟨b⟩ ⟨c⟩; exact Quot.sound (Rel.leibniz_lie a b c) instance : LieAlgebra R (FreeLieAlgebra R X) where lie_smul := by rintro t ⟨a⟩ ⟨c⟩ change Quot.mk _ (a • t • c) = Quot.mk _ (t • a • c) rw [← smul_comm] variable {X} /-- The embedding of `X` into the free Lie algebra of `X` with coefficients in the commutative ring `R`. -/ def of : X → FreeLieAlgebra R X := fun x => Quot.mk _ (lib.of R x) variable {L : Type w} [LieRing L] [LieAlgebra R L] /-- An auxiliary definition used to construct the equivalence `lift` below. -/ def liftAux (f : X → CommutatorRing L) := lib.lift R f theorem liftAux_map_smul (f : X → L) (t : R) (a : lib R X) : liftAux R f (t • a) = t • liftAux R f a := NonUnitalAlgHom.map_smul _ t a theorem liftAux_map_add (f : X → L) (a b : lib R X) : liftAux R f (a + b) = liftAux R f a + liftAux R f b := NonUnitalAlgHom.map_add _ a b theorem liftAux_map_mul (f : X → L) (a b : lib R X) : liftAux R f (a * b) = ⁅liftAux R f a, liftAux R f b⁆ := NonUnitalAlgHom.map_mul _ a b theorem liftAux_spec (f : X → L) (a b : lib R X) (h : FreeLieAlgebra.Rel R X a b) : liftAux R f a = liftAux R f b := by induction h with | lie_self a' => simp only [liftAux_map_mul, NonUnitalAlgHom.map_zero, lie_self] | leibniz_lie a' b' c' => simp only [liftAux_map_mul, liftAux_map_add, sub_add_cancel, lie_lie] | smul b' _ h₂ => simp only [liftAux_map_smul, h₂] | add_right c' _ h₂ => simp only [liftAux_map_add, h₂] | mul_left c' _ h₂ => simp only [liftAux_map_mul, h₂] | mul_right c' _ h₂ => simp only [liftAux_map_mul, h₂] /-- The quotient map as a `NonUnitalAlgHom`. -/ def mk : lib R X →ₙₐ[R] CommutatorRing (FreeLieAlgebra R X) where toFun := Quot.mk (Rel R X) map_smul' _ _ := rfl map_zero' := rfl map_add' _ _ := rfl map_mul' _ _ := rfl /-- The functor `X ↦ FreeLieAlgebra R X` from the category of types to the category of Lie algebras over `R` is adjoint to the forgetful functor in the other direction. -/ def lift : (X → L) ≃ (FreeLieAlgebra R X →ₗ⁅R⁆ L) where toFun f := { toFun := fun c => Quot.liftOn c (liftAux R f) (liftAux_spec R f) map_add' := by rintro ⟨a⟩ ⟨b⟩; rw [← liftAux_map_add]; rfl map_smul' := by rintro t ⟨a⟩; rw [← liftAux_map_smul]; rfl map_lie' := by rintro ⟨a⟩ ⟨b⟩; rw [← liftAux_map_mul]; rfl } invFun F := F ∘ of R left_inv f := by ext x simp only [liftAux, of, LieHom.coe_mk, Function.comp_apply, lib.lift_of_apply] right_inv F := by ext ⟨a⟩ let F' := F.toNonUnitalAlgHom.comp (mk R) exact NonUnitalAlgHom.congr_fun (lib.lift_comp_of R F') a @[simp] theorem lift_symm_apply (F : FreeLieAlgebra R X →ₗ⁅R⁆ L) : (lift R).symm F = F ∘ of R := rfl variable {R} @[simp] theorem of_comp_lift (f : X → L) : lift R f ∘ of R = f := (lift R).left_inv f @[simp] theorem lift_unique (f : X → L) (g : FreeLieAlgebra R X →ₗ⁅R⁆ L) : g ∘ of R = f ↔ g = lift R f := (lift R).symm_apply_eq @[simp] theorem lift_of_apply (f : X → L) (x) : lift R f (of R x) = f x := by rw [← @Function.comp_apply _ _ _ (lift R f) (of R) x, of_comp_lift] @[simp] theorem lift_comp_of (F : FreeLieAlgebra R X →ₗ⁅R⁆ L) : lift R (F ∘ of R) = F := by rw [← lift_symm_apply]; exact (lift R).apply_symm_apply F @[ext] theorem hom_ext {F₁ F₂ : FreeLieAlgebra R X →ₗ⁅R⁆ L} (h : ∀ x, F₁ (of R x) = F₂ (of R x)) : F₁ = F₂ := have h' : (lift R).symm F₁ = (lift R).symm F₂ := by ext; simp [h] (lift R).symm.injective h' variable (R X) /-- The universal enveloping algebra of the free Lie algebra is just the free unital associative algebra. -/ @[simps!] def universalEnvelopingEquivFreeAlgebra : UniversalEnvelopingAlgebra R (FreeLieAlgebra R X) ≃ₐ[R] FreeAlgebra R X := AlgEquiv.ofAlgHom (UniversalEnvelopingAlgebra.lift R <| FreeLieAlgebra.lift R <| FreeAlgebra.ι R) (FreeAlgebra.lift R <| UniversalEnvelopingAlgebra.ι R ∘ FreeLieAlgebra.of R) (by ext; simp) (by ext; simp) end FreeLieAlgebra
.lake/packages/mathlib/Mathlib/Algebra/Lie/Character.lean
import Mathlib.Algebra.Lie.Abelian import Mathlib.Algebra.Lie.Solvable import Mathlib.LinearAlgebra.Dual.Defs /-! # Characters of Lie algebras A character of a Lie algebra `L` over a commutative ring `R` is a morphism of Lie algebras `L → R`, where `R` is regarded as a Lie algebra over itself via the ring commutator. For an Abelian Lie algebra (e.g., a Cartan subalgebra of a semisimple Lie algebra) a character is just a linear form. ## Main definitions * `LieAlgebra.LieCharacter` * `LieAlgebra.lieCharacterEquivLinearDual` ## Tags lie algebra, lie character -/ universe u v w w₁ namespace LieAlgebra variable (R : Type u) (L : Type v) [CommRing R] [LieRing L] [LieAlgebra R L] /-- A character of a Lie algebra is a morphism to the scalars. -/ abbrev LieCharacter := L →ₗ⁅R⁆ R variable {R L} theorem lieCharacter_apply_lie (χ : LieCharacter R L) (x y : L) : χ ⁅x, y⁆ = 0 := by rw [LieHom.map_lie, LieRing.of_associative_ring_bracket, mul_comm, sub_self] @[simp] theorem lieCharacter_apply_lie' (χ : LieCharacter R L) (x y : L) : ⁅χ x, χ y⁆ = 0 := by rw [LieRing.of_associative_ring_bracket, mul_comm, sub_self] theorem lieCharacter_apply_of_mem_derived (χ : LieCharacter R L) {x : L} (h : x ∈ derivedSeries R L 1) : χ x = 0 := by rw [derivedSeries_def, derivedSeriesOfIdeal_succ, derivedSeriesOfIdeal_zero, ← LieSubmodule.mem_toSubmodule, LieSubmodule.lieIdeal_oper_eq_linear_span] at h induction h using Submodule.span_induction with | mem y h => simp only [Subtype.exists, LieSubmodule.mem_top, exists_const, Set.mem_setOf_eq] at h obtain ⟨z, w, rfl⟩ := h exact lieCharacter_apply_lie .. | zero => exact map_zero _ | add y z _ _ hy hz => rw [map_add, hy, hz, add_zero] | smul t y _ hy => rw [map_smul, hy, smul_zero] /-- For an Abelian Lie algebra, characters are just linear forms. -/ @[simps! apply symm_apply] def lieCharacterEquivLinearDual [IsLieAbelian L] : LieCharacter R L ≃ Module.Dual R L where toFun χ := (χ : L →ₗ[R] R) invFun ψ := { ψ with map_lie' := fun {x y} => by rw [LieModule.IsTrivial.trivial, LieRing.of_associative_ring_bracket, mul_comm, sub_self, LinearMap.toFun_eq_coe, LinearMap.map_zero] } end LieAlgebra
.lake/packages/mathlib/Mathlib/Algebra/Lie/Normalizer.lean
import Mathlib.Algebra.Lie.Abelian import Mathlib.Algebra.Lie.IdealOperations import Mathlib.Algebra.Lie.Quotient /-! # The normalizer of Lie submodules and subalgebras. Given a Lie module `M` over a Lie subalgebra `L`, the normalizer of a Lie submodule `N ⊆ M` is the Lie submodule with underlying set `{ m | ∀ (x : L), ⁅x, m⁆ ∈ N }`. The lattice of Lie submodules thus has two natural operations, the normalizer: `N ↦ N.normalizer` and the ideal operation: `N ↦ ⁅⊤, N⁆`; these are adjoint, i.e., they form a Galois connection. This adjointness is the reason that we may define nilpotency in terms of either the upper or lower central series. Given a Lie subalgebra `H ⊆ L`, we may regard `H` as a Lie submodule of `L` over `H`, and thus consider the normalizer. This turns out to be a Lie subalgebra. ## Main definitions * `LieSubmodule.normalizer` * `LieSubalgebra.normalizer` * `LieSubmodule.gc_top_lie_normalizer` ## Tags lie algebra, normalizer -/ variable {R L M M' : Type*} variable [CommRing R] [LieRing L] [LieAlgebra R L] variable [AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M] variable [AddCommGroup M'] [Module R M'] [LieRingModule L M'] [LieModule R L M'] namespace LieSubmodule variable (N : LieSubmodule R L M) {N₁ N₂ : LieSubmodule R L M} /-- The normalizer of a Lie submodule. See also `LieSubmodule.idealizer`. -/ def normalizer : LieSubmodule R L M where carrier := {m | ∀ x : L, ⁅x, m⁆ ∈ N} add_mem' hm₁ hm₂ x := by rw [lie_add]; exact N.add_mem' (hm₁ x) (hm₂ x) zero_mem' x := by simp smul_mem' t m hm x := by rw [lie_smul]; exact N.smul_mem' t (hm x) lie_mem {x m} hm y := by rw [leibniz_lie]; exact N.add_mem' (hm ⁅y, x⁆) (N.lie_mem (hm y)) @[simp] theorem mem_normalizer (m : M) : m ∈ N.normalizer ↔ ∀ x : L, ⁅x, m⁆ ∈ N := Iff.rfl @[simp] theorem le_normalizer : N ≤ N.normalizer := by intro m hm rw [mem_normalizer] exact fun x => N.lie_mem hm theorem normalizer_inf : (N₁ ⊓ N₂).normalizer = N₁.normalizer ⊓ N₂.normalizer := by ext; simp [← forall_and] @[gcongr, mono] theorem normalizer_mono (h : N₁ ≤ N₂) : normalizer N₁ ≤ normalizer N₂ := by intro m hm rw [mem_normalizer] at hm ⊢ exact fun x ↦ h (hm x) theorem monotone_normalizer : Monotone (normalizer : LieSubmodule R L M → LieSubmodule R L M) := fun _ _ ↦ normalizer_mono @[simp] theorem comap_normalizer (f : M' →ₗ⁅R,L⁆ M) : N.normalizer.comap f = (N.comap f).normalizer := by ext; simp theorem top_lie_le_iff_le_normalizer (N' : LieSubmodule R L M) : ⁅(⊤ : LieIdeal R L), N⁆ ≤ N' ↔ N ≤ N'.normalizer := by rw [lie_le_iff]; tauto theorem gc_top_lie_normalizer : GaloisConnection (fun N : LieSubmodule R L M => ⁅(⊤ : LieIdeal R L), N⁆) normalizer := top_lie_le_iff_le_normalizer variable (R L M) in theorem normalizer_bot_eq_maxTrivSubmodule : (⊥ : LieSubmodule R L M).normalizer = LieModule.maxTrivSubmodule R L M := rfl /-- The idealizer of a Lie submodule. See also `LieSubmodule.normalizer`. -/ def idealizer : LieIdeal R L where carrier := {x : L | ∀ m : M, ⁅x, m⁆ ∈ N} add_mem' := fun {x} {y} hx hy m ↦ by rw [add_lie]; exact N.add_mem (hx m) (hy m) zero_mem' := by simp smul_mem' := fun t {x} hx m ↦ by rw [smul_lie]; exact N.smul_mem t (hx m) lie_mem := fun {x} {y} hy m ↦ by rw [lie_lie]; exact sub_mem (N.lie_mem (hy m)) (hy ⁅x, m⁆) @[simp] lemma mem_idealizer {x : L} : x ∈ N.idealizer ↔ ∀ m : M, ⁅x, m⁆ ∈ N := Iff.rfl @[simp] lemma _root_.LieIdeal.idealizer_eq_normalizer (I : LieIdeal R L) : I.idealizer = I.normalizer := by ext x; exact forall_congr' fun y ↦ by simp only [← lie_skew x y, neg_mem_iff] end LieSubmodule namespace LieSubalgebra variable (H : LieSubalgebra R L) /-- Regarding a Lie subalgebra `H ⊆ L` as a module over itself, its normalizer is in fact a Lie subalgebra. -/ def normalizer : LieSubalgebra R L := { H.toLieSubmodule.normalizer with lie_mem' := fun {y z} hy hz x => by rw [coe_bracket_of_module, mem_toLieSubmodule, leibniz_lie, ← lie_skew y, ← sub_eq_add_neg] exact H.sub_mem (hz ⟨_, hy x⟩) (hy ⟨_, hz x⟩) } theorem mem_normalizer_iff' (x : L) : x ∈ H.normalizer ↔ ∀ y : L, y ∈ H → ⁅y, x⁆ ∈ H := by rw [Subtype.forall']; rfl theorem mem_normalizer_iff (x : L) : x ∈ H.normalizer ↔ ∀ y : L, y ∈ H → ⁅x, y⁆ ∈ H := by rw [mem_normalizer_iff'] refine forall₂_congr fun y hy => ?_ rw [← lie_skew, neg_mem_iff (G := L)] theorem le_normalizer : H ≤ H.normalizer := H.toLieSubmodule.le_normalizer theorem coe_normalizer_eq_normalizer : (H.toLieSubmodule.normalizer : Submodule R L) = H.normalizer := rfl variable {H} theorem lie_mem_sup_of_mem_normalizer {x y z : L} (hx : x ∈ H.normalizer) (hy : y ∈ (R ∙ x) ⊔ ↑H) (hz : z ∈ (R ∙ x) ⊔ ↑H) : ⁅y, z⁆ ∈ (R ∙ x) ⊔ ↑H := by rw [Submodule.mem_sup] at hy hz obtain ⟨u₁, hu₁, v, hv : v ∈ H, rfl⟩ := hy obtain ⟨u₂, hu₂, w, hw : w ∈ H, rfl⟩ := hz obtain ⟨t, rfl⟩ := Submodule.mem_span_singleton.mp hu₁ obtain ⟨s, rfl⟩ := Submodule.mem_span_singleton.mp hu₂ apply Submodule.mem_sup_right simp only [LieSubalgebra.mem_toSubmodule, smul_lie, add_lie, zero_add, lie_add, smul_zero, lie_smul, lie_self] refine H.add_mem (H.smul_mem s ?_) (H.add_mem (H.smul_mem t ?_) (H.lie_mem hv hw)) exacts [(H.mem_normalizer_iff' x).mp hx v hv, (H.mem_normalizer_iff x).mp hx w hw] /-- A Lie subalgebra is an ideal of its normalizer. -/ theorem ideal_in_normalizer {x y : L} (hx : x ∈ H.normalizer) (hy : y ∈ H) : ⁅x, y⁆ ∈ H := by rw [← lie_skew, neg_mem_iff (G := L)] exact hx ⟨y, hy⟩ /-- A Lie subalgebra `H` is an ideal of any Lie subalgebra `K` containing `H` and contained in the normalizer of `H`. -/ theorem exists_nested_lieIdeal_ofLe_normalizer {K : LieSubalgebra R L} (h₁ : H ≤ K) (h₂ : K ≤ H.normalizer) : ∃ I : LieIdeal R K, (I : LieSubalgebra R K) = ofLe h₁ := by rw [exists_nested_lieIdeal_coe_eq_iff] exact fun x y hx hy => ideal_in_normalizer (h₂ hx) hy variable (H) theorem normalizer_eq_self_iff : H.normalizer = H ↔ (LieModule.maxTrivSubmodule R H <| L ⧸ H.toLieSubmodule) = ⊥ := by rw [LieSubmodule.eq_bot_iff] refine ⟨fun h => ?_, fun h => le_antisymm ?_ H.le_normalizer⟩ · rintro ⟨x⟩ hx suffices x ∈ H by rwa [Submodule.Quotient.quot_mk_eq_mk, Submodule.Quotient.mk_eq_zero, coe_toLieSubmodule, mem_toSubmodule] rw [← h, H.mem_normalizer_iff'] intro y hy replace hx : ⁅_, LieSubmodule.Quotient.mk' _ x⁆ = 0 := hx ⟨y, hy⟩ rwa [← LieModuleHom.map_lie, LieSubmodule.Quotient.mk_eq_zero] at hx · intro x hx let y := LieSubmodule.Quotient.mk' H.toLieSubmodule x have hy : y ∈ LieModule.maxTrivSubmodule R H (L ⧸ H.toLieSubmodule) := by rintro ⟨z, hz⟩ rw [← LieModuleHom.map_lie, LieSubmodule.Quotient.mk_eq_zero, coe_bracket_of_module, Submodule.coe_mk, mem_toLieSubmodule] exact (H.mem_normalizer_iff' x).mp hx z hz simpa [y] using h y hy end LieSubalgebra
.lake/packages/mathlib/Mathlib/Algebra/Lie/Semisimple/Lemmas.lean
import Mathlib.Algebra.Lie.LieTheorem import Mathlib.Algebra.Lie.Semisimple.Basic /-! # Lemmas about semisimple Lie algebras This file is a home for lemmas about semisimple and reductive Lie algebras. ## Main definitions / results: * `LieAlgebra.hasCentralRadical_and_of_isIrreducible_of_isFaithful`: a finite-dimensional Lie algebra with a irreducible faithful finite-dimensional representation is reductive. * `LieAlgebra.hasTrivialRadical_of_isIrreducible_of_isFaithful`: a finite-dimensional Lie algebra with a irreducible faithful finite-dimensional trace-free representation is semisimple. ## TODO * Introduce a `Prop`-valued typeclass `LieModule.IsTracefree` stating `(toEnd R L M).range ≤ LieAlgebra.derivedSeries R (Module.End R M) 1`, prove `f ∈ LieAlgebra.derivedSeries k (Module.End k V) 1 ↔ LinearMap.trace k _ f = 0`, and restate `LieAlgebra.hasTrivialRadical_of_isIrreducible_of_isFaithful` using `LieModule.IsTracefree`. -/ namespace LieAlgebra open LieModule LieSubmodule Module Set variable (k L M : Type*) [Field k] [CharZero k] [LieRing L] [LieAlgebra k L] [Module.Finite k L] [AddCommGroup M] [Module k M] [LieRingModule L M] [LieModule k L M] [Module.Finite k M] [IsIrreducible k L M] [IsFaithful k L M] [IsTriangularizable k L M] lemma hasCentralRadical_and_of_isIrreducible_of_isFaithful : HasCentralRadical k L ∧ (∀ x, x ∈ center k L ↔ toEnd k L M x ∈ k ∙ LinearMap.id) := by have _i := nontrivial_of_isIrreducible k L M obtain ⟨χ, hχ⟩ : ∃ χ : Module.Dual k (radical k L), Nontrivial (weightSpace M χ) := exists_nontrivial_weightSpace_of_isSolvable k (radical k L) M let N : LieSubmodule k L M := weightSpaceOfIsLieTower k M χ replace hχ : Nontrivial N := hχ replace hχ : N = ⊤ := N.eq_top_of_isIrreducible k L M replace hχ (x : L) (hx : x ∈ radical k L) : toEnd k _ M x = χ ⟨x, hx⟩ • LinearMap.id := by ext m have hm : ∀ (y : L) (hy : y ∈ radical k L), ⁅y, m⁆ = χ ⟨y, hy⟩ • m := by simpa [N, weightSpaceOfIsLieTower, mem_weightSpace] using (hχ ▸ mem_top _ : m ∈ N) simpa using hm x hx have aux : radical k L = center k L := by refine le_antisymm (fun x hx ↦ (mem_maxTrivSubmodule k L L x).mpr ?_) (center_le_radical k L) intro y simp [← toEnd_eq_zero_iff (R := k) (L := L) (M := M), LieHom.map_lie, hχ _ hx, lie_smul, (toEnd k L M y).commute_id_right.lie_eq] refine ⟨⟨aux⟩, fun x ↦ ⟨fun hx ↦ ?_, fun hx ↦ (mem_maxTrivSubmodule k L L x).mpr fun y ↦ ?_⟩⟩ · rw [← aux] at hx exact Submodule.mem_span_singleton.mpr ⟨χ ⟨x, hx⟩, (hχ x hx).symm⟩ · obtain ⟨t, ht⟩ := Submodule.mem_span_singleton.mp hx simp [← toEnd_eq_zero_iff (R := k) (L := L) (M := M), LieHom.map_lie, ← ht, lie_smul, (toEnd k L M y).commute_id_right.lie_eq] theorem hasTrivialRadical_of_isIrreducible_of_isFaithful (h : ∀ x, LinearMap.trace k _ (toEnd k L M x) = 0) : HasTrivialRadical k L := by have : finrank k M ≠ 0 := ((finrank_pos_iff).mpr <| nontrivial_of_isIrreducible k L M).ne' obtain ⟨_i, h'⟩ := hasCentralRadical_and_of_isIrreducible_of_isFaithful k L M rw [hasTrivialRadical_iff, (hasCentralRadical_iff k L).mp inferInstance, LieSubmodule.eq_bot_iff] intro x hx specialize h x rw [h' x] at hx obtain ⟨t, ht⟩ := Submodule.mem_span_singleton.mp hx suffices t = 0 by simp [← toEnd_eq_zero_iff (R := k) (L := L) (M := M), ← ht, this] simpa [this, ← ht] using h variable {k L M} variable {R : Type*} [CommRing R] [LieAlgebra R L] [Module R M] [LieModule R L M] open LinearMap in lemma trace_toEnd_eq_zero {s : Set L} (hs : ∀ x ∈ s, LinearMap.trace R _ (toEnd R _ M x) = 0) {x : L} (hx : x ∈ LieSubalgebra.lieSpan R L s) : trace R _ (toEnd R _ M x) = 0 := by induction hx using LieSubalgebra.lieSpan_induction with | mem u hu => simpa using hs u hu | zero => simp | add u v _ _ hu hv => simp [hu, hv] | smul t u _ hu => simp [hu] | lie u v _ _ _ _ => simp end LieAlgebra
.lake/packages/mathlib/Mathlib/Algebra/Lie/Semisimple/Basic.lean
import Mathlib.Algebra.Lie.Semisimple.Defs import Mathlib.Order.BooleanGenerators /-! # Semisimple Lie algebras The famous Cartan-Dynkin-Killing classification of semisimple Lie algebras renders them one of the most important classes of Lie algebras. In this file we prove basic results about simple and semisimple Lie algebras. ## Main declarations * `LieAlgebra.IsSemisimple.instHasTrivialRadical`: A semisimple Lie algebra has trivial radical. * `LieAlgebra.IsSemisimple.instBooleanAlgebra`: The lattice of ideals in a semisimple Lie algebra is a Boolean algebra. In particular, this implies that the lattice of ideals is atomistic: every ideal is a direct sum of atoms (simple ideals) in a unique way. * `LieAlgebra.hasTrivialRadical_iff_no_solvable_ideals` * `LieAlgebra.hasTrivialRadical_iff_no_abelian_ideals` * `LieAlgebra.abelian_radical_iff_solvable_is_abelian` ## Tags lie algebra, radical, simple, semisimple -/ section Irreducible variable (R L M : Type*) [CommRing R] [LieRing L] [AddCommGroup M] [Module R M] [LieRingModule L M] lemma LieModule.nontrivial_of_isIrreducible [LieModule.IsIrreducible R L M] : Nontrivial M where exists_pair_ne := by have aux : (⊥ : LieSubmodule R L M) ≠ ⊤ := bot_ne_top contrapose! aux ext m simpa using aux m 0 end Irreducible namespace LieAlgebra variable (R L : Type*) [CommRing R] [LieRing L] [LieAlgebra R L] variable {R L} in theorem HasTrivialRadical.eq_bot_of_isSolvable [HasTrivialRadical R L] (I : LieIdeal R L) [hI : IsSolvable I] : I = ⊥ := sSup_eq_bot.mp radical_eq_bot _ hI instance [HasTrivialRadical R L] : LieModule.IsFaithful R L L := by rw [isFaithful_self_iff] exact HasTrivialRadical.eq_bot_of_isSolvable _ variable {R L} in theorem hasTrivialRadical_of_no_solvable_ideals (h : ∀ I : LieIdeal R L, IsSolvable I → I = ⊥) : HasTrivialRadical R L := ⟨sSup_eq_bot.mpr h⟩ theorem hasTrivialRadical_iff_no_solvable_ideals : HasTrivialRadical R L ↔ ∀ I : LieIdeal R L, IsSolvable I → I = ⊥ := ⟨@HasTrivialRadical.eq_bot_of_isSolvable _ _ _ _ _, hasTrivialRadical_of_no_solvable_ideals⟩ theorem hasTrivialRadical_iff_no_abelian_ideals : HasTrivialRadical R L ↔ ∀ I : LieIdeal R L, IsLieAbelian I → I = ⊥ := by rw [hasTrivialRadical_iff_no_solvable_ideals] constructor <;> intro h₁ I h₂ · exact h₁ _ <| LieAlgebra.ofAbelianIsSolvable I · rw [← abelian_of_solvable_ideal_eq_bot_iff] exact h₁ _ <| abelian_derivedAbelianOfIdeal I namespace IsSimple variable [IsSimple R L] instance : LieModule.IsIrreducible R L L := by suffices Nontrivial (LieIdeal R L) from ⟨IsSimple.eq_bot_or_eq_top⟩ rw [LieSubmodule.nontrivial_iff, ← not_subsingleton_iff_nontrivial] have _i : ¬ IsLieAbelian L := IsSimple.non_abelian R contrapose! _i infer_instance protected lemma isAtom_top : IsAtom (⊤ : LieIdeal R L) := isAtom_top variable {R L} in protected lemma isAtom_iff_eq_top (I : LieIdeal R L) : IsAtom I ↔ I = ⊤ := isAtom_iff_eq_top variable {R L} in lemma eq_top_of_isAtom (I : LieIdeal R L) (hI : IsAtom I) : I = ⊤ := isAtom_iff_eq_top.mp hI instance : HasTrivialRadical R L := by rw [hasTrivialRadical_iff_no_abelian_ideals] intro I hI apply (IsSimple.eq_bot_or_eq_top I).resolve_right rintro rfl rw [lie_abelian_iff_equiv_lie_abelian LieIdeal.topEquiv] at hI exact IsSimple.non_abelian R (L := L) hI end IsSimple namespace IsSemisimple open CompleteLattice IsCompactlyGenerated variable {R L} variable [IsSemisimple R L] lemma isSimple_of_isAtom (I : LieIdeal R L) (hI : IsAtom I) : IsSimple R I where non_abelian := IsSemisimple.non_abelian_of_isAtom I hI eq_bot_or_eq_top := by -- Suppose that `J` is an ideal of `I`. intro J -- We first show that `J` is also an ideal of the ambient Lie algebra `L`. let J' : LieIdeal R L := { __ := J.toSubmodule.map I.incl.toLinearMap lie_mem := by rintro x _ ⟨y, hy, rfl⟩ -- We need to show that `⁅x, y⁆ ∈ J` for any `x ∈ L` and `y ∈ J`. -- Since `L` is semisimple, `x` is contained -- in the supremum of `I` and the atoms not equal to `I`. have hx : x ∈ I ⊔ sSup ({I' : LieIdeal R L | IsAtom I'} \ {I}) := by nth_rewrite 1 [← sSup_singleton (a := I)] rw [← sSup_union, Set.union_diff_self, Set.union_eq_self_of_subset_left, IsSemisimple.sSup_atoms_eq_top] · apply LieSubmodule.mem_top · simp only [Set.singleton_subset_iff, Set.mem_setOf_eq, hI] -- Hence we can write `x` as `a + b` with `a ∈ I` -- and `b` in the supremum of the atoms not equal to `I`. rw [LieSubmodule.mem_sup] at hx obtain ⟨a, ha, b, hb, rfl⟩ := hx -- Therefore it suffices to show that `⁅a, y⁆ ∈ J` and `⁅b, y⁆ ∈ J`. simp only [Submodule.carrier_eq_coe, add_lie, SetLike.mem_coe] apply add_mem -- Now `⁅a, y⁆ ∈ J` since `a ∈ I`, `y ∈ J`, and `J` is an ideal of `I`. · simp only [Submodule.mem_map, LieSubmodule.mem_toSubmodule, Subtype.exists] erw [Submodule.coe_subtype] simp only [exists_and_right, exists_eq_right, ha, lie_mem_left, exists_true_left] exact lie_mem_right R I J ⟨a, ha⟩ y hy -- Finally `⁅b, y⁆ = 0`, by the independence of the atoms. · suffices ⁅b, y.val⁆ = 0 by erw [this]; simp only [zero_mem] rw [← LieSubmodule.mem_bot (R := R) (L := L), ← (IsSemisimple.sSupIndep_isAtom hI).eq_bot] exact ⟨lie_mem_right R L I b y y.2, lie_mem_left _ _ _ _ _ hb⟩ } -- Now that we know that `J` is an ideal of `L`, -- we start with the proof that `I` is a simple Lie algebra. -- Assume that `J ≠ ⊤`. rw [or_iff_not_imp_right] intro hJ suffices J' = ⊥ by rw [eq_bot_iff] at this ⊢ intro x hx suffices x ∈ J → x = 0 from this hx have := @this x.1 simp only [LieIdeal.incl_coe, LieIdeal.toLieSubalgebra_toSubmodule, LieSubmodule.mem_mk_iff', Submodule.mem_map, LieSubmodule.mem_toSubmodule, Subtype.exists, LieSubmodule.mem_bot, ZeroMemClass.coe_eq_zero, forall_exists_index, and_imp, J'] at this exact fun _ ↦ this (↑x) x.property hx rfl -- We need to show that `J = ⊥`. -- Since `J` is an ideal of `L`, and `I` is an atom, -- it suffices to show that `J < I`. apply hI.2 rw [lt_iff_le_and_ne] constructor -- We know that `J ≤ I` since `J` is an ideal of `I`. · rintro _ ⟨x, -, rfl⟩ exact x.2 -- So we need to show `J ≠ I` as ideals of `L`. -- This follows from our assumption that `J ≠ ⊤` as ideals of `I`. contrapose! hJ rw [eq_top_iff] rintro ⟨x, hx⟩ - rw [← hJ] at hx rcases hx with ⟨y, hy, rfl⟩ exact hy /-- In a semisimple Lie algebra, Lie ideals that are contained in the supremum of a finite collection of atoms are themselves the supremum of a finite subcollection of those atoms. By a compactness argument, this statement can be extended to arbitrary sets of atoms. See `atomistic`. The proof is by induction on the finite set of atoms. -/ private lemma finitelyAtomistic : ∀ s : Finset (LieIdeal R L), ↑s ⊆ {I : LieIdeal R L | IsAtom I} → ∀ I : LieIdeal R L, I ≤ s.sup id → ∃ t ⊆ s, I = t.sup id := by intro s hs I hI let S := {I : LieIdeal R L | IsAtom I} obtain rfl | hI := hI.eq_or_lt · exact ⟨s, Finset.Subset.rfl, rfl⟩ -- We assume that `I` is strictly smaller than the supremum of `s`. -- Hence there must exist an atom `J` that is not contained in `I`. obtain ⟨J, hJs, hJI⟩ : ∃ J ∈ s, ¬ J ≤ I := by by_contra! H exact hI.ne (le_antisymm hI.le (s.sup_le H)) classical let s' := s.erase J have hs' : s' ⊂ s := Finset.erase_ssubset hJs have hs'S : ↑s' ⊆ S := Set.Subset.trans (Finset.coe_subset.mpr hs'.subset) hs -- If we show that `I` is contained in the supremum `K` of the complement of `J` in `s`, -- then we are done by recursion. set K := s'.sup id suffices I ≤ K by obtain ⟨t, hts', htI⟩ := finitelyAtomistic s' hs'S I this exact ⟨t, hts'.trans hs'.subset, htI⟩ -- Since `I` is contained in the supremum of `J` with the supremum of `s'`, -- any element `x` of `I` can be written as `y + z` for some `y ∈ J` and `z ∈ K`. intro x hx obtain ⟨y, hy, z, hz, rfl⟩ : ∃ y ∈ id J, ∃ z ∈ K, y + z = x := by rw [← LieSubmodule.mem_sup, ← Finset.sup_insert, Finset.insert_erase hJs] exact hI.le hx -- If we show that `y` is contained in the center of `J`, -- then we find `x = z`, and hence `x` is contained in the supremum of `s'`. -- Since `x` was arbitrary, we have shown that `I` is contained in the supremum of `s'`. suffices ⟨y, hy⟩ ∈ LieAlgebra.center R J by have _inst := isSimple_of_isAtom J (hs hJs) simp_all -- To show that `y` is in the center of `J`, -- we show that any `j ∈ J` brackets to `0` with `z` and with `x = y + z`. -- By a simple computation, that implies `⁅j, y⁆ = 0`, for all `j`, as desired. intro j suffices ⁅(j : L), z⁆ = 0 ∧ ⁅(j : L), y + z⁆ = 0 by rw [lie_add, this.1, add_zero] at this ext exact this.2 rw [← LieSubmodule.mem_bot (R := R) (L := L), ← LieSubmodule.mem_bot (R := R) (L := L)] constructor -- `j` brackets to `0` with `z`, since `⁅j, z⁆` is contained in `⁅J, K⁆ ≤ J ⊓ K`, -- and `J ⊓ K = ⊥` by the independence of the atoms. · apply (sSupIndep_isAtom.disjoint_sSup (hs hJs) hs'S (Finset.notMem_erase _ _)).le_bot apply LieSubmodule.lie_le_inf apply LieSubmodule.lie_mem_lie j.2 simpa only [K, Finset.sup_id_eq_sSup] using hz -- By similar reasoning, `j` brackets to `0` with `x = y + z ∈ I`, if we show `J ⊓ I = ⊥`. suffices J ⊓ I = ⊥ by apply this.le apply LieSubmodule.lie_le_inf exact LieSubmodule.lie_mem_lie j.2 hx -- Indeed `J ⊓ I = ⊥`, since `J` is an atom that is not contained in `I`. apply ((hs hJs).le_iff.mp _).resolve_right · contrapose! hJI rw [← hJI] exact inf_le_right exact inf_le_left termination_by s => s.card decreasing_by exact Finset.card_lt_card hs' variable (R L) in lemma booleanGenerators : BooleanGenerators {I : LieIdeal R L | IsAtom I} where isAtom _ hI := hI finitelyAtomistic _ _ hs _ hIs := finitelyAtomistic _ hs _ hIs instance (priority := 100) instDistribLattice : DistribLattice (LieIdeal R L) := (booleanGenerators R L).distribLattice_of_sSup_eq_top sSup_atoms_eq_top noncomputable instance (priority := 100) instBooleanAlgebra : BooleanAlgebra (LieIdeal R L) := (booleanGenerators R L).booleanAlgebra_of_sSup_eq_top sSup_atoms_eq_top /-- A semisimple Lie algebra has trivial radical. -/ instance (priority := 100) instHasTrivialRadical : HasTrivialRadical R L := by rw [hasTrivialRadical_iff_no_abelian_ideals] intro I hI apply (eq_bot_or_exists_atom_le I).resolve_right rintro ⟨J, hJ, hJ'⟩ apply IsSemisimple.non_abelian_of_isAtom J hJ constructor intro x y ext simp only [LieIdeal.coe_bracket_of_module, LieSubmodule.coe_bracket, ZeroMemClass.coe_zero] have : (⁅(⟨x, hJ' x.2⟩ : I), ⟨y, hJ' y.2⟩⁆ : I) = 0 := trivial_lie_zero _ _ _ _ apply_fun Subtype.val at this exact this end IsSemisimple /-- A simple Lie algebra is semisimple. -/ instance (priority := 100) IsSimple.instIsSemisimple [IsSimple R L] : IsSemisimple R L := by constructor · simp · simpa using sSupIndep_singleton _ · intro I hI₁ hI₂ apply IsSimple.non_abelian (R := R) (L := L) rw [IsSimple.isAtom_iff_eq_top] at hI₁ rwa [hI₁, lie_abelian_iff_equiv_lie_abelian LieIdeal.topEquiv] at hI₂ /-- An abelian Lie algebra with trivial radical is trivial. -/ theorem subsingleton_of_hasTrivialRadical_lie_abelian [HasTrivialRadical R L] [h : IsLieAbelian L] : Subsingleton L := by rw [isLieAbelian_iff_center_eq_top R L, center_eq_bot] at h exact (LieSubmodule.subsingleton_iff R L L).mp (subsingleton_of_bot_eq_top h) theorem abelian_radical_of_hasTrivialRadical [HasTrivialRadical R L] : IsLieAbelian (radical R L) := by rw [HasTrivialRadical.radical_eq_bot]; exact LieIdeal.isLieAbelian_of_trivial .. theorem abelian_radical_iff_solvable_is_abelian [IsNoetherian R L] : IsLieAbelian (radical R L) ↔ ∀ I : LieIdeal R L, IsSolvable I → IsLieAbelian I := by constructor · rintro h₁ I h₂ rw [LieIdeal.solvable_iff_le_radical] at h₂ exact (LieIdeal.inclusion_injective h₂).isLieAbelian h₁ · intro h; apply h; infer_instance theorem ad_ker_eq_bot_of_hasTrivialRadical [HasTrivialRadical R L] : (ad R L).ker = ⊥ := by simp end LieAlgebra
.lake/packages/mathlib/Mathlib/Algebra/Lie/Semisimple/Defs.lean
import Mathlib.Algebra.Lie.Solvable /-! # Semisimple Lie algebras In this file we define simple and semisimple Lie algebras, together with related concepts. ## Main declarations * `LieModule.IsIrreducible` * `LieAlgebra.IsSimple` * `LieAlgebra.HasTrivialRadical` * `LieAlgebra.IsSemisimple` ## Tags lie algebra, radical, simple, semisimple -/ variable (R L M : Type*) variable [CommRing R] [LieRing L] [AddCommGroup M] [Module R M] [LieRingModule L M] /-- A nontrivial Lie module is *irreducible* if its only Lie submodules are `⊥` and `⊤`. -/ abbrev LieModule.IsIrreducible : Prop := IsSimpleOrder (LieSubmodule R L M) variable {R L M} in lemma LieModule.IsIrreducible.mk [Nontrivial M] (h : ∀ N : LieSubmodule R L M, N ≠ ⊥ → N = ⊤) : IsIrreducible R L M := IsSimpleOrder.of_forall_eq_top h lemma LieSubmodule.eq_top_of_isIrreducible [LieModule.IsIrreducible R L M] (N : LieSubmodule R L M) [Nontrivial N] : N = ⊤ := (IsSimpleOrder.eq_bot_or_eq_top N).resolve_left <| (nontrivial_iff_ne_bot R L M).mp inferInstance namespace LieAlgebra variable [LieAlgebra R L] /-- A Lie algebra *has trivial radical* if its radical is trivial. This is equivalent to having no non-trivial solvable ideals, and further equivalent to having no non-trivial abelian ideals. In characteristic zero, it is also equivalent to `LieAlgebra.IsSemisimple`. Note that the label 'semisimple' is apparently not universally agreed [upon](https://mathoverflow.net/questions/149391/on-radicals-of-a-lie-algebra#comment383669_149391) for general coefficients. For example [Seligman, page 15](seligman1967) uses the label for `LieAlgebra.HasTrivialRadical`, whereas we reserve it for Lie algebras that are a direct sum of simple Lie algebras. -/ @[mk_iff] class HasTrivialRadical : Prop where radical_eq_bot : radical R L = ⊥ export HasTrivialRadical (radical_eq_bot) attribute [simp] radical_eq_bot /-- A Lie algebra *has central radical* if its radical coincides with its center. Such Lie algebras are called *reductive*, if the coefficients are a field of characteristic zero. Note that there is absolutely [no agreement](https://mathoverflow.net/questions/284713/) on what the label 'reductive' should mean when the coefficients are not a field of characteristic zero. -/ @[mk_iff] class HasCentralRadical : Prop where radical_eq_center : radical R L = center R L lemma hasCentralRadical_of_radical_le (h : radical R L ≤ center R L) : LieAlgebra.HasCentralRadical R L where radical_eq_center := le_antisymm h (center_le_radical R L) instance [Subsingleton L] : HasTrivialRadical R L := ⟨by simpa only [radical_eq_top_of_isSolvable] using Subsingleton.elim ⊤ ⊥⟩ export HasCentralRadical (radical_eq_center) attribute [simp] radical_eq_center /-- A Lie algebra is simple if it is irreducible as a Lie module over itself via the adjoint action, and it is non-Abelian. -/ class IsSimple : Prop where eq_bot_or_eq_top : ∀ I : LieIdeal R L, I = ⊥ ∨ I = ⊤ non_abelian : ¬IsLieAbelian L /-- A *semisimple* Lie algebra is one that is a direct sum of non-abelian atomic ideals. These ideals are simple Lie algebras, by `LieAlgebra.IsSemisimple.isSimple_of_isAtom`. Note that the label 'semisimple' is apparently not universally agreed [upon](https://mathoverflow.net/questions/149391/on-radicals-of-a-lie-algebra#comment383669_149391) for general coefficients. For example [Seligman, page 15](seligman1967) uses the label for `LieAlgebra.HasTrivialRadical`, the weakest of the various properties which are all equivalent over a field of characteristic zero. -/ class IsSemisimple : Prop where /-- In a semisimple Lie algebra, the supremum of the atoms is the whole Lie algebra. -/ sSup_atoms_eq_top : sSup {I : LieIdeal R L | IsAtom I} = ⊤ /-- In a semisimple Lie algebra, the atoms are independent. -/ sSupIndep_isAtom : sSupIndep {I : LieIdeal R L | IsAtom I} /-- In a semisimple Lie algebra, the atoms are non-abelian. -/ non_abelian_of_isAtom : ∀ I : LieIdeal R L, IsAtom I → ¬ IsLieAbelian I end LieAlgebra
.lake/packages/mathlib/Mathlib/Algebra/Lie/Derivation/AdjointAction.lean
import Mathlib.Algebra.Lie.Abelian import Mathlib.Algebra.Lie.Derivation.Basic import Mathlib.Algebra.Lie.OfAssociative /-! # Adjoint action of a Lie algebra on itself This file defines the *adjoint action* of a Lie algebra on itself, and establishes basic properties. ## Main definitions - `LieDerivation.ad`: The adjoint action of a Lie algebra `L` on itself, seen as a morphism of Lie algebras from `L` to the Lie algebra of its derivations. The adjoint action is also defined in the `Mathlib/Algebra/Lie/OfAssociative.lean` file, under the name `LieAlgebra.ad`, as the morphism with values in the endormophisms of `L`. ## Main statements - `LieDerivation.coe_ad_apply_eq_ad_apply`: when seen as endomorphisms, both definitions coincide, - `LieDerivation.ad_ker_eq_center`: the kernel of the adjoint action is the center of `L`, - `LieDerivation.lie_der_ad_eq_ad_der`: the commutator of a derivation `D` and `ad x` is `ad (D x)`, - `LieDerivation.ad_isIdealMorphism`: the range of the adjoint action is an ideal of the derivations. -/ namespace LieDerivation section AdjointAction variable (R L : Type*) [CommRing R] [LieRing L] [LieAlgebra R L] /-- The adjoint action of a Lie algebra `L` on itself, seen as a morphism of Lie algebras from `L` to its derivations. Note the minus sign: this is chosen to so that `ad ⁅x, y⁆ = ⁅ad x, ad y⁆`. -/ @[simps!] def ad : L →ₗ⁅R⁆ LieDerivation R L L := { __ := - inner R L L map_lie' := by intro x y ext z simp only [AddHom.toFun_eq_coe, LinearMap.coe_toAddHom, LinearMap.neg_apply, coe_neg, Pi.neg_apply, inner_apply_apply, commutator_apply] rw [leibniz_lie, neg_lie, neg_lie, ← lie_skew x] abel } variable {R L} /-- The definitions `LieDerivation.ad` and `LieAlgebra.ad` agree. -/ @[simp] lemma coe_ad_apply_eq_ad_apply (x : L) : ad R L x = LieAlgebra.ad R L x := by ext; simp lemma ad_apply_lieDerivation (x : L) (D : LieDerivation R L L) : ad R L (D x) = - ⁅x, D⁆ := rfl lemma lie_ad (x : L) (D : LieDerivation R L L) : ⁅ad R L x, D⁆ = ⁅x, D⁆ := by ext; simp variable (R L) in /-- The kernel of the adjoint action on a Lie algebra is equal to its center. -/ lemma ad_ker_eq_center : (ad R L).ker = LieAlgebra.center R L := by ext x rw [← LieAlgebra.self_module_ker_eq_center, LieHom.mem_ker, LieModule.mem_ker] simp [DFunLike.ext_iff] /-- If the center of a Lie algebra is trivial, then the adjoint action is injective. -/ lemma injective_ad_of_center_eq_bot (h : LieAlgebra.center R L = ⊥) : Function.Injective (ad R L) := by rw [← LieHom.ker_eq_bot, ad_ker_eq_center, h] /-- The commutator of a derivation `D` and a derivation of the form `ad x` is `ad (D x)`. -/ lemma lie_der_ad_eq_ad_der (D : LieDerivation R L L) (x : L) : ⁅D, ad R L x⁆ = ad R L (D x) := by rw [ad_apply_lieDerivation, ← lie_ad, lie_skew] variable (R L) in /-- The range of the adjoint action homomorphism from a Lie algebra `L` to the Lie algebra of its derivations is an ideal of the latter. -/ lemma ad_isIdealMorphism : (ad R L).IsIdealMorphism := by simp_rw [LieHom.isIdealMorphism_iff, lie_der_ad_eq_ad_der] tauto /-- A derivation `D` belongs to the ideal range of the adjoint action iff it is of the form `ad x` for some `x` in the Lie algebra `L`. -/ lemma mem_ad_idealRange_iff {D : LieDerivation R L L} : D ∈ (ad R L).idealRange ↔ ∃ x : L, ad R L x = D := (ad R L).mem_idealRange_iff (ad_isIdealMorphism R L) lemma maxTrivSubmodule_eq_bot_of_center_eq_bot (h : LieAlgebra.center R L = ⊥) : LieModule.maxTrivSubmodule R L (LieDerivation R L L) = ⊥ := by refine (LieSubmodule.eq_bot_iff _).mpr fun D hD ↦ ext fun x ↦ ?_ have : ad R L (D x) = 0 := by rw [LieModule.mem_maxTrivSubmodule] at hD simp [ad_apply_lieDerivation, hD] rw [← LieHom.mem_ker, ad_ker_eq_center, h, LieSubmodule.mem_bot] at this simp [this] end AdjointAction end LieDerivation
.lake/packages/mathlib/Mathlib/Algebra/Lie/Derivation/Basic.lean
import Mathlib.Algebra.Lie.NonUnitalNonAssocAlgebra import Mathlib.Algebra.Lie.OfAssociative import Mathlib.Algebra.Lie.Subalgebra import Mathlib.RingTheory.Nilpotent.Exp import Mathlib.RingTheory.Noetherian.Basic /-! # Lie derivations This file defines *Lie derivations* and establishes some basic properties. ## Main definitions - `LieDerivation`: A Lie derivation `D` from the Lie `R`-algebra `L` to the `L`-module `M` is an `R`-linear map that satisfies the Leibniz rule `D [a, b] = [a, D b] - [b, D a]`. - `LieDerivation.inner`: The natural map from a Lie module to the derivations taking values in it. ## Main statements - `LieDerivation.eqOn_lieSpan`: two Lie derivations equal on a set are equal on its Lie span. - `LieDerivation.instLieAlgebra`: the set of Lie derivations from a Lie algebra to itself is a Lie algebra. ## Implementation notes - Mathematically, a Lie derivation is just a derivation on a Lie algebra. However, the current implementation of `RingTheory.Derivation` requires a commutative associative algebra, so is incompatible with the setting of Lie algebras. Initially, this file is a copy-pasted adaptation of the `RingTheory.Derivation.Basic.lean` file. - Since we don't have right actions of Lie algebras, the second term in the Leibniz rule is written as `- [b, D a]`. Within Lie algebras, skew symmetry restores the expected definition `[D a, b]`. -/ /-- A Lie derivation `D` from the Lie `R`-algebra `L` to the `L`-module `M` is an `R`-linear map that satisfies the Leibniz rule `D [a, b] = [a, D b] - [b, D a]`. -/ structure LieDerivation (R L M : Type*) [CommRing R] [LieRing L] [LieAlgebra R L] [AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M] extends L →ₗ[R] M where protected leibniz' (a b : L) : toLinearMap ⁅a, b⁆ = ⁅a, toLinearMap b⁆ - ⁅b, toLinearMap a⁆ /-- The `LinearMap` underlying a `LieDerivation`. -/ add_decl_doc LieDerivation.toLinearMap namespace LieDerivation section variable {R L M : Type*} [CommRing R] [LieRing L] [LieAlgebra R L] [AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M] variable (D : LieDerivation R L M) {D1 D2 : LieDerivation R L M} (a b : L) instance : FunLike (LieDerivation R L M) L M where coe D := D.toFun coe_injective' D1 D2 h := by cases D1; cases D2; congr; exact DFunLike.coe_injective h instance instLinearMapClass : LinearMapClass (LieDerivation R L M) R L M where map_add D := D.toLinearMap.map_add' map_smulₛₗ D := D.toLinearMap.map_smul theorem toFun_eq_coe : D.toFun = ⇑D := rfl /-- See Note [custom simps projection] -/ def Simps.apply (D : LieDerivation R L M) : L → M := D initialize_simps_projections LieDerivation (toFun → apply) attribute [coe] toLinearMap instance instCoeToLinearMap : Coe (LieDerivation R L M) (L →ₗ[R] M) := ⟨fun D => D.toLinearMap⟩ @[simp] theorem mk_coe (f : L →ₗ[R] M) (h₁) : ((⟨f, h₁⟩ : LieDerivation R L M) : L → M) = f := rfl @[simp, norm_cast] theorem coeFn_coe (f : LieDerivation R L M) : ⇑(f : L →ₗ[R] M) = f := rfl theorem coe_injective : @Function.Injective (LieDerivation R L M) (L → M) DFunLike.coe := DFunLike.coe_injective @[ext] theorem ext (H : ∀ a, D1 a = D2 a) : D1 = D2 := DFunLike.ext _ _ H theorem congr_fun (h : D1 = D2) (a : L) : D1 a = D2 a := DFunLike.congr_fun h a @[simp] lemma apply_lie_eq_sub (D : LieDerivation R L M) (a b : L) : D ⁅a, b⁆ = ⁅a, D b⁆ - ⁅b, D a⁆ := D.leibniz' a b /-- For a Lie derivation from a Lie algebra to itself, the usual Leibniz rule holds. -/ lemma apply_lie_eq_add (D : LieDerivation R L L) (a b : L) : D ⁅a, b⁆ = ⁅a, D b⁆ + ⁅D a, b⁆ := by rw [LieDerivation.apply_lie_eq_sub, sub_eq_add_neg, lie_skew] /-- Two Lie derivations equal on a set are equal on its Lie span. -/ theorem eqOn_lieSpan {s : Set L} (h : Set.EqOn D1 D2 s) : Set.EqOn D1 D2 (LieSubalgebra.lieSpan R L s) := by intro _ hx induction hx using LieSubalgebra.lieSpan_induction with | mem x hx => exact h hx | zero => simp | add x y _ _ hx hy => simp [hx, hy] | smul t x _ hx => simp [hx] | lie x y _ _ hx hy => simp [hx, hy] /-- If the Lie span of a set is the whole Lie algebra, then two Lie derivations equal on this set are equal on the whole Lie algebra. -/ theorem ext_of_lieSpan_eq_top (s : Set L) (hs : LieSubalgebra.lieSpan R L s = ⊤) (h : Set.EqOn D1 D2 s) : D1 = D2 := ext fun _ => eqOn_lieSpan h <| hs.symm ▸ trivial section open Finset Nat /-- The general Leibniz rule for Lie derivatives. -/ theorem iterate_apply_lie (D : LieDerivation R L L) (n : ℕ) (a b : L) : D^[n] ⁅a, b⁆ = ∑ ij ∈ antidiagonal n, choose n ij.1 • ⁅D^[ij.1] a, D^[ij.2] b⁆ := by induction n with | zero => simp | succ n ih => rw [sum_antidiagonal_choose_succ_nsmul (M := L) (fun i j => ⁅D^[i] a, D^[j] b⁆) n] simp only [Function.iterate_succ_apply', ih, map_sum, map_nsmul, apply_lie_eq_add, smul_add, sum_add_distrib, add_right_inj] refine sum_congr rfl fun ⟨i, j⟩ hij ↦ ?_ rw [n.choose_symm_of_eq_add (mem_antidiagonal.1 hij).symm] /-- Alternate version of the general Leibniz rule for Lie derivatives. -/ theorem iterate_apply_lie' (D : LieDerivation R L L) (n : ℕ) (a b : L) : D^[n] ⁅a, b⁆ = ∑ i ∈ range (n + 1), n.choose i • ⁅D^[i] a, D^[n - i] b⁆ := by rw [iterate_apply_lie D n a b] exact sum_antidiagonal_eq_sum_range_succ (fun i j ↦ n.choose i • ⁅D^[i] a, D^[j] b⁆) n end instance instZero : Zero (LieDerivation R L M) where zero := { toLinearMap := 0 leibniz' := fun a b => by simp only [LinearMap.zero_apply, lie_zero, sub_self] } @[simp] theorem coe_zero : ⇑(0 : LieDerivation R L M) = 0 := rfl @[simp] theorem coe_zero_linearMap : ↑(0 : LieDerivation R L M) = (0 : L →ₗ[R] M) := rfl theorem zero_apply (a : L) : (0 : LieDerivation R L M) a = 0 := rfl instance : Inhabited (LieDerivation R L M) := ⟨0⟩ instance instAdd : Add (LieDerivation R L M) where add D1 D2 := { toLinearMap := D1 + D2 leibniz' := fun a b ↦ by simp only [LinearMap.add_apply, coeFn_coe, apply_lie_eq_sub, lie_add, add_sub_add_comm] } @[simp] theorem coe_add (D1 D2 : LieDerivation R L M) : ⇑(D1 + D2) = D1 + D2 := rfl @[simp] theorem coe_add_linearMap (D1 D2 : LieDerivation R L M) : ↑(D1 + D2) = (D1 + D2 : L →ₗ[R] M) := rfl theorem add_apply : (D1 + D2) a = D1 a + D2 a := rfl protected theorem map_neg : D (-a) = -D a := map_neg D a protected theorem map_sub : D (a - b) = D a - D b := map_sub D a b instance instNeg : Neg (LieDerivation R L M) := ⟨fun D => mk (-D) fun a b => by simp only [LinearMap.neg_apply, coeFn_coe, apply_lie_eq_sub, neg_sub, lie_neg, sub_neg_eq_add, add_comm, ← sub_eq_add_neg] ⟩ @[simp] theorem coe_neg (D : LieDerivation R L M) : ⇑(-D) = -D := rfl @[simp] theorem coe_neg_linearMap (D : LieDerivation R L M) : ↑(-D) = (-D : L →ₗ[R] M) := rfl theorem neg_apply : (-D) a = -D a := rfl instance instSub : Sub (LieDerivation R L M) := ⟨fun D1 D2 => mk (D1 - D2 : L →ₗ[R] M) fun a b => by simp only [LinearMap.sub_apply, coeFn_coe, apply_lie_eq_sub, lie_sub, sub_sub_sub_comm]⟩ @[simp] theorem coe_sub (D1 D2 : LieDerivation R L M) : ⇑(D1 - D2) = D1 - D2 := rfl @[simp] theorem coe_sub_linearMap (D1 D2 : LieDerivation R L M) : ↑(D1 - D2) = (D1 - D2 : L →ₗ[R] M) := rfl theorem sub_apply {D1 D2 : LieDerivation R L M} : (D1 - D2) a = D1 a - D2 a := rfl section Scalar /-- A typeclass mixin saying that scalar multiplication and Lie bracket are left commutative. -/ class SMulBracketCommClass (S L α : Type*) [SMul S α] [LieRing L] [AddCommGroup α] [LieRingModule L α] : Prop where /-- `•` and `⁅⬝, ⬝⁆` are left commutative -/ smul_bracket_comm : ∀ (s : S) (l : L) (a : α), s • ⁅l, a⁆ = ⁅l, s • a⁆ variable {S T : Type*} variable [Monoid S] [DistribMulAction S M] [SMulCommClass R S M] [SMulBracketCommClass S L M] variable [Monoid T] [DistribMulAction T M] [SMulCommClass R T M] [SMulBracketCommClass T L M] instance instSMul : SMul S (LieDerivation R L M) where smul r D := { toLinearMap := r • D leibniz' := fun a b => by simp only [LinearMap.smul_apply, coeFn_coe, apply_lie_eq_sub, smul_sub, SMulBracketCommClass.smul_bracket_comm] } @[simp] theorem coe_smul (r : S) (D : LieDerivation R L M) : ⇑(r • D) = r • ⇑D := rfl @[simp] theorem coe_smul_linearMap (r : S) (D : LieDerivation R L M) : ↑(r • D) = r • (D : L →ₗ[R] M) := rfl theorem smul_apply (r : S) (D : LieDerivation R L M) : (r • D) a = r • D a := rfl instance instSMulBase : SMulBracketCommClass R L M := ⟨fun s l a ↦ (lie_smul s l a).symm⟩ instance instSMulNat : SMulBracketCommClass ℕ L M := ⟨fun s l a => (lie_nsmul l a s).symm⟩ instance instSMulInt : SMulBracketCommClass ℤ L M := ⟨fun s l a => (lie_zsmul l a s).symm⟩ instance instAddCommGroup : AddCommGroup (LieDerivation R L M) := coe_injective.addCommGroup _ coe_zero coe_add coe_neg coe_sub (fun _ _ => rfl) fun _ _ => rfl /-- `coe_fn` as an `AddMonoidHom`. -/ def coeFnAddMonoidHom : LieDerivation R L M →+ L → M where toFun := (↑) map_zero' := coe_zero map_add' := coe_add @[simp] lemma coeFnAddMonoidHom_apply (D : LieDerivation R L M) : coeFnAddMonoidHom D = D := rfl instance : DistribMulAction S (LieDerivation R L M) := Function.Injective.distribMulAction coeFnAddMonoidHom coe_injective coe_smul instance [SMul S T] [IsScalarTower S T M] : IsScalarTower S T (LieDerivation R L M) := ⟨fun _ _ _ => ext fun _ => smul_assoc _ _ _⟩ instance [SMulCommClass S T M] : SMulCommClass S T (LieDerivation R L M) := ⟨fun _ _ _ => ext fun _ => smul_comm _ _ _⟩ end Scalar instance instModule {S : Type*} [Semiring S] [Module S M] [SMulCommClass R S M] [SMulBracketCommClass S L M] : Module S (LieDerivation R L M) := Function.Injective.module S coeFnAddMonoidHom coe_injective coe_smul end section variable {R L : Type*} [CommRing R] [LieRing L] [LieAlgebra R L] /-- The commutator of two Lie derivations on a Lie algebra is a Lie derivation. -/ instance instBracket : Bracket (LieDerivation R L L) (LieDerivation R L L) where bracket D1 D2 := LieDerivation.mk ⁅(D1 : Module.End R L), (D2 : Module.End R L)⁆ (fun a b => by simp only [Ring.lie_def, apply_lie_eq_add, coeFn_coe, LinearMap.sub_apply, Module.End.mul_apply, map_add, sub_lie, lie_sub, ← lie_skew b] abel) variable {D1 D2 : LieDerivation R L L} @[simp] lemma commutator_coe_linear_map : ↑⁅D1, D2⁆ = ⁅(D1 : Module.End R L), (D2 : Module.End R L)⁆ := rfl lemma commutator_apply (a : L) : ⁅D1, D2⁆ a = D1 (D2 a) - D2 (D1 a) := rfl instance : LieRing (LieDerivation R L L) where add_lie d e f := by ext a; simp only [commutator_apply, add_apply, map_add]; abel lie_add d e f := by ext a; simp only [commutator_apply, add_apply, map_add]; abel lie_self d := by ext a; simp only [commutator_apply, zero_apply]; abel leibniz_lie d e f := by ext a; simp only [commutator_apply, add_apply, map_sub]; abel /-- The set of Lie derivations from a Lie algebra `L` to itself is a Lie algebra. -/ instance instLieAlgebra : LieAlgebra R (LieDerivation R L L) where lie_smul := fun r d e => by ext a; simp only [commutator_apply, map_smul, smul_sub, smul_apply] @[simp] lemma lie_apply (D₁ D₂ : LieDerivation R L L) (x : L) : ⁅D₁, D₂⁆ x = D₁ (D₂ x) - D₂ (D₁ x) := rfl end section variable (R L : Type*) [CommRing R] [LieRing L] [LieAlgebra R L] /-- The Lie algebra morphism from Lie derivations into linear endormophisms. -/ def toLinearMapLieHom : LieDerivation R L L →ₗ⁅R⁆ L →ₗ[R] L where toFun := toLinearMap map_add' := by intro D1 D2; dsimp map_smul' := by intro D1 D2; dsimp map_lie' := by intro D1 D2; dsimp /-- The map from Lie derivations to linear endormophisms is injective. -/ lemma toLinearMapLieHom_injective : Function.Injective (toLinearMapLieHom R L) := fun _ _ h ↦ ext fun a ↦ congrFun (congrArg DFunLike.coe h) a /-- Lie derivations over a Noetherian Lie algebra form a Noetherian module. -/ instance instNoetherian [IsNoetherian R L] : IsNoetherian R (LieDerivation R L L) := isNoetherian_of_linearEquiv (LinearEquiv.ofInjective _ (toLinearMapLieHom_injective R L)).symm end section Inner variable (R L M : Type*) [CommRing R] [LieRing L] [LieAlgebra R L] [AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M] /-- The natural map from a Lie module to the derivations taking values in it. -/ @[simps!] def inner : M →ₗ[R] LieDerivation R L M where toFun m := { __ := (LieModule.toEnd R L M : L →ₗ[R] Module.End R M).flip m leibniz' := by simp } map_add' m n := by ext; simp map_smul' t m := by ext; simp instance instLieRingModule : LieRingModule L (LieDerivation R L M) where bracket x D := inner R L M (D x) add_lie x y D := by simp lie_add x D₁ D₂ := by simp leibniz_lie x y D := by simp @[simp] lemma lie_lieDerivation_apply (x y : L) (D : LieDerivation R L M) : ⁅x, D⁆ y = ⁅y, D x⁆ := rfl @[simp] lemma lie_coe_lieDerivation_apply (x : L) (D : LieDerivation R L M) : ⁅x, (D : L →ₗ[R] M)⁆ = ⁅x, D⁆ := by ext; simp instance instLieModule : LieModule R L (LieDerivation R L M) where smul_lie t x D := by ext; simp lie_smul t x D := by ext; simp protected lemma leibniz_lie (x : L) (D₁ D₂ : LieDerivation R L L) : ⁅x, ⁅D₁, D₂⁆⁆ = ⁅⁅x, D₁⁆, D₂⁆ + ⁅D₁, ⁅x, D₂⁆⁆ := by ext y simp [-lie_skew, ← lie_skew (D₁ x) (D₂ y), ← lie_skew (D₂ x) (D₁ y), sub_eq_neg_add] end Inner section ExpNilpotent variable {R L : Type*} [CommRing R] [LieRing L] [LieAlgebra R L] [LieAlgebra ℚ L] (D : LieDerivation R L L) /-- In characteristic zero, the exponential of a nilpotent derivation is a Lie algebra automorphism. -/ noncomputable def exp (h : IsNilpotent D.toLinearMap) : L ≃ₗ⁅R⁆ L := { toLinearMap := IsNilpotent.exp D.toLinearMap map_lie' := by let _i := LieRing.toNonUnitalNonAssocRing L have : SMulCommClass R L L := LieAlgebra.smulCommClass R L have : IsScalarTower R L L := LieAlgebra.isScalarTower R L exact Module.End.exp_mul_of_derivation R L D.toLinearMap D.apply_lie_eq_add h invFun x := IsNilpotent.exp (- D.toLinearMap) x left_inv x := by simp only [AddHom.toFun_eq_coe, LinearMap.coe_toAddHom, ← LinearMap.comp_apply, ← Module.End.mul_eq_comp, h.exp_neg_mul_exp_self, Module.End.one_apply] right_inv x := by simp only [AddHom.toFun_eq_coe, LinearMap.coe_toAddHom, ← LinearMap.comp_apply, ← Module.End.mul_eq_comp, h.exp_mul_exp_neg_self, Module.End.one_apply] } lemma exp_apply (h : IsNilpotent D.toLinearMap) : exp D h = IsNilpotent.exp D.toLinearMap := rfl lemma exp_map_apply (h : IsNilpotent D.toLinearMap) (l : L) : exp D h l = IsNilpotent.exp D.toLinearMap l := DFunLike.congr_fun (exp_apply D h) l end ExpNilpotent end LieDerivation
.lake/packages/mathlib/Mathlib/Algebra/Lie/Derivation/Killing.lean
import Mathlib.Algebra.Lie.Derivation.AdjointAction import Mathlib.Algebra.Lie.Killing import Mathlib.LinearAlgebra.BilinearForm.Orthogonal /-! # Derivations of finite-dimensional Killing Lie algebras This file establishes that all derivations of finite-dimensional Killing Lie algebras are inner. ## Main statements - `LieDerivation.Killing.ad_mem_orthogonal_of_mem_orthogonal`: if a derivation `D` is in the Killing orthogonal of the range of the adjoint action, then, for any `x : L`, `ad (D x)` is also in this orthogonal. - `LieDerivation.Killing.range_ad_eq_top`: in a finite-dimensional Lie algebra with non-degenerate Killing form, the range of the adjoint action is full, - `LieDerivation.Killing.exists_eq_ad`: in a finite-dimensional Lie algebra with non-degenerate Killing form, any derivation is an inner derivation. -/ namespace LieDerivation.IsKilling section variable (R L : Type*) [Field R] [LieRing L] [LieAlgebra R L] /-- A local notation for the set of (Lie) derivations on `L`. -/ local notation "𝔻" => (LieDerivation R L L) /-- A local notation for the range of `ad`. -/ local notation "𝕀" => (LieHom.range (ad R L)) /-- A local notation for the Killing complement of the ideal range of `ad`. -/ local notation "𝕀ᗮ" => LinearMap.BilinForm.orthogonal (killingForm R 𝔻) 𝕀 lemma killingForm_restrict_range_ad [Module.Finite R L] : (killingForm R 𝔻).restrict 𝕀 = killingForm R 𝕀 := by rw [← (ad_isIdealMorphism R L).eq, ← LieIdeal.killingForm_eq] rfl /-- The orthogonal complement of the inner derivations is a Lie submodule of all derivations. -/ @[simps!] noncomputable def rangeAdOrthogonal : LieSubmodule R L (LieDerivation R L L) where __ := 𝕀ᗮ lie_mem := by intro x D hD have : 𝕀ᗮ = (ad R L).idealRange.killingCompl := by simp [← (ad_isIdealMorphism R L).eq] change D ∈ 𝕀ᗮ at hD change ⁅x, D⁆ ∈ 𝕀ᗮ rw [this] at hD ⊢ rw [← lie_ad] exact lie_mem_right _ _ (ad R L).idealRange.killingCompl _ _ hD variable {R L} /-- If a derivation `D` is in the Killing orthogonal of the range of the adjoint action, then, for any `x : L`, `ad (D x)` is also in this orthogonal. -/ lemma ad_mem_orthogonal_of_mem_orthogonal {D : LieDerivation R L L} (hD : D ∈ 𝕀ᗮ) (x : L) : ad R L (D x) ∈ 𝕀ᗮ := by simp only [ad_apply_lieDerivation, LieHom.range_toSubmodule, neg_mem_iff] exact (rangeAdOrthogonal R L).lie_mem hD variable [Module.Finite R L] lemma ad_mem_ker_killingForm_ad_range_of_mem_orthogonal {D : LieDerivation R L L} (hD : D ∈ 𝕀ᗮ) (x : L) : ad R L (D x) ∈ (LinearMap.ker (killingForm R 𝕀)).map (LieHom.range (ad R L)).subtype := by rw [← killingForm_restrict_range_ad] exact LinearMap.BilinForm.inf_orthogonal_self_le_ker_restrict (LieModule.traceForm_isSymm R 𝔻 𝔻).isRefl ⟨by simp, ad_mem_orthogonal_of_mem_orthogonal hD x⟩ variable (R L) variable [LieAlgebra.IsKilling R L] @[simp] lemma ad_apply_eq_zero_iff (x : L) : ad R L x = 0 ↔ x = 0 := by refine ⟨fun h ↦ ?_, fun h ↦ by simp [h]⟩ rwa [← LieHom.mem_ker, ad_ker_eq_center, LieAlgebra.center_eq_bot, LieSubmodule.mem_bot] at h instance instIsKilling_range_ad : LieAlgebra.IsKilling R 𝕀 := (LieEquiv.ofInjective (ad R L) (injective_ad_of_center_eq_bot <| by simp)).isKilling /-- The restriction of the Killing form of a finite-dimensional Killing Lie algebra to the range of the adjoint action is nondegenerate. -/ lemma killingForm_restrict_range_ad_nondegenerate : ((killingForm R 𝔻).restrict 𝕀).Nondegenerate := by convert LieAlgebra.IsKilling.killingForm_nondegenerate R 𝕀 exact killingForm_restrict_range_ad R L /-- The range of the adjoint action on a finite-dimensional Killing Lie algebra is full. -/ @[simp] lemma range_ad_eq_top : 𝕀 = ⊤ := by rw [← LieSubalgebra.toSubmodule_inj] apply LinearMap.BilinForm.eq_top_of_restrict_nondegenerate_of_orthogonal_eq_bot (LieModule.traceForm_isSymm R 𝔻 𝔻).isRefl (killingForm_restrict_range_ad_nondegenerate R L) refine (Submodule.eq_bot_iff _).mpr fun D hD ↦ ext fun x ↦ ?_ simpa using ad_mem_ker_killingForm_ad_range_of_mem_orthogonal hD x variable {R L} in /-- Every derivation of a finite-dimensional Killing Lie algebra is an inner derivation. -/ lemma exists_eq_ad (D : 𝔻) : ∃ x, ad R L x = D := by change D ∈ 𝕀 rw [range_ad_eq_top R L] exact Submodule.mem_top end end IsKilling end LieDerivation
.lake/packages/mathlib/Mathlib/Algebra/Lie/Weights/Chain.lean
import Mathlib.Algebra.DirectSum.LinearMap import Mathlib.Algebra.Lie.Weights.Cartan import Mathlib.Algebra.Order.Group.Pointwise.Interval import Mathlib.RingTheory.Finiteness.Nilpotent import Mathlib.Data.Int.Interval import Mathlib.Order.Filter.Cofinite /-! # Chains of roots and weights Given roots `α` and `β` of a Lie algebra, together with elements `x` in the `α`-root space and `y` in the `β`-root space, it follows from the Leibniz identity that `⁅x, y⁆` is either zero or belongs to the `α + β`-root space. Iterating this operation leads to the study of families of roots of the form `k • α + β`. Such a family is known as the `α`-chain through `β` (or sometimes, the `α`-string through `β`) and the study of the sum of the corresponding root spaces is an important technique. More generally if `α` is a root and `χ` is a weight of a representation, it is useful to study the `α`-chain through `χ`. We provide basic definitions and results to support `α`-chain techniques in this file. ## Main definitions / results * `LieModule.exists₂_genWeightSpace_smul_add_eq_bot`: given weights `χ₁`, `χ₂` if `χ₁ ≠ 0`, we can find `p < 0` and `q > 0` such that the weight spaces `p • χ₁ + χ₂` and `q • χ₁ + χ₂` are both trivial. * `LieModule.genWeightSpaceChain`: given weights `χ₁`, `χ₂` together with integers `p` and `q`, this is the sum of the weight spaces `k • χ₁ + χ₂` for `p < k < q`. * `LieModule.trace_toEnd_genWeightSpaceChain_eq_zero`: given a root `α` relative to a Cartan subalgebra `H`, there is a natural ideal `corootSpace α` in `H`. This lemma states that this ideal acts by trace-zero endomorphisms on the sum of root spaces of any `α`-chain, provided the weight spaces at the endpoints are both trivial. * `LieModule.exists_forall_mem_corootSpace_smul_add_eq_zero`: given a (potential) root `α` relative to a Cartan subalgebra `H`, if we restrict to the ideal `corootSpace α` of `H`, we may find an integral linear combination between `α` and any weight `χ` of a representation. ## TODO It should be possible to unify some of the definitions here such as `LieModule.chainBotCoeff`, `LieModule.chainTopCoeff` with corresponding definitions such as `RootPairing.chainBotCoeff`, `RootPairing.chainTopCoeff`. This is not quite trivial since: * The definitions here allow for chains in representations of Lie algebras. * The proof that the roots of a Lie algebra are a root system currently depends on these results. (This can be resolved by proving the root reflection formula using the approach outlined in Bourbaki Ch. VIII §2.2 Lemma 1 (page 80 of English translation, 88 of English PDF).) -/ open Module Function Set variable {R L : Type*} [CommRing R] [LieRing L] [LieAlgebra R L] (M : Type*) [AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M] namespace LieModule section IsNilpotent variable [LieRing.IsNilpotent L] (χ₁ χ₂ : L → R) (p q : ℤ) section variable [IsAddTorsionFree R] [NoZeroSMulDivisors R M] [IsNoetherian R M] (hχ₁ : χ₁ ≠ 0) include hχ₁ lemma eventually_genWeightSpace_smul_add_eq_bot : ∀ᶠ (k : ℕ) in Filter.atTop, genWeightSpace M (k • χ₁ + χ₂) = ⊥ := by let f : ℕ → L → R := fun k ↦ k • χ₁ + χ₂ suffices Injective f by rw [← Nat.cofinite_eq_atTop, Filter.eventually_cofinite, ← finite_image_iff this.injOn] apply (finite_genWeightSpace_ne_bot R L M).subset simp [f] intro k l hkl replace hkl : (k : ℤ) • χ₁ = (l : ℤ) • χ₁ := by simpa only [f, add_left_inj, natCast_zsmul] using hkl exact Nat.cast_inj.mp <| smul_left_injective ℤ hχ₁ hkl lemma exists_genWeightSpace_smul_add_eq_bot : ∃ k > 0, genWeightSpace M (k • χ₁ + χ₂) = ⊥ := (Nat.eventually_pos.and <| eventually_genWeightSpace_smul_add_eq_bot M χ₁ χ₂ hχ₁).exists lemma exists₂_genWeightSpace_smul_add_eq_bot : ∃ᵉ (p < (0 : ℤ)) (q > (0 : ℤ)), genWeightSpace M (p • χ₁ + χ₂) = ⊥ ∧ genWeightSpace M (q • χ₁ + χ₂) = ⊥ := by obtain ⟨q, hq₀, hq⟩ := exists_genWeightSpace_smul_add_eq_bot M χ₁ χ₂ hχ₁ obtain ⟨p, hp₀, hp⟩ := exists_genWeightSpace_smul_add_eq_bot M (-χ₁) χ₂ (neg_ne_zero.mpr hχ₁) refine ⟨-(p : ℤ), by simpa, q, by simpa, ?_, ?_⟩ · rw [neg_smul, ← smul_neg, natCast_zsmul] exact hp · rw [natCast_zsmul] exact hq end /-- Given two (potential) weights `χ₁` and `χ₂` together with integers `p` and `q`, it is often useful to study the sum of weight spaces associated to the family of weights `k • χ₁ + χ₂` for `p < k < q`. -/ def genWeightSpaceChain : LieSubmodule R L M := ⨆ k ∈ Ioo p q, genWeightSpace M (k • χ₁ + χ₂) lemma genWeightSpaceChain_def : genWeightSpaceChain M χ₁ χ₂ p q = ⨆ k ∈ Ioo p q, genWeightSpace M (k • χ₁ + χ₂) := rfl lemma genWeightSpaceChain_def' : genWeightSpaceChain M χ₁ χ₂ p q = ⨆ k ∈ Finset.Ioo p q, genWeightSpace M (k • χ₁ + χ₂) := by have : ∀ (k : ℤ), k ∈ Ioo p q ↔ k ∈ Finset.Ioo p q := by simp simp_rw [genWeightSpaceChain_def, this] @[simp] lemma genWeightSpaceChain_neg : genWeightSpaceChain M (-χ₁) χ₂ (-q) (-p) = genWeightSpaceChain M χ₁ χ₂ p q := by let e : ℤ ≃ ℤ := neg_involutive.toPerm simp_rw [genWeightSpaceChain, ← e.biSup_comp (Ioo p q)] simp [e, -mem_Ioo] lemma genWeightSpace_le_genWeightSpaceChain {k : ℤ} (hk : k ∈ Ioo p q) : genWeightSpace M (k • χ₁ + χ₂) ≤ genWeightSpaceChain M χ₁ χ₂ p q := le_biSup (fun i ↦ genWeightSpace M (i • χ₁ + χ₂)) hk end IsNilpotent section LieSubalgebra open LieAlgebra variable {H : LieSubalgebra R L} (α χ : H → R) (p q : ℤ) lemma lie_mem_genWeightSpaceChain_of_genWeightSpace_eq_bot_right [LieRing.IsNilpotent H] (hq : genWeightSpace M (q • α + χ) = ⊥) {x : L} (hx : x ∈ rootSpace H α) {y : M} (hy : y ∈ genWeightSpaceChain M α χ p q) : ⁅x, y⁆ ∈ genWeightSpaceChain M α χ p q := by rw [genWeightSpaceChain, iSup_subtype'] at hy induction hy using LieSubmodule.iSup_induction' with | mem k z hz => obtain ⟨k, hk⟩ := k suffices genWeightSpace M ((k + 1) • α + χ) ≤ genWeightSpaceChain M α χ p q by apply this -- was `simpa using [...]` and very slow -- (https://github.com/leanprover-community/mathlib4/issues/19751) simpa only [zsmul_eq_mul, Int.cast_add, Pi.intCast_def, Int.cast_one] using (rootSpaceWeightSpaceProduct R L H M α (k • α + χ) ((k + 1) • α + χ) (by rw [add_smul]; abel) (⟨x, hx⟩ ⊗ₜ ⟨z, hz⟩)).property rw [genWeightSpaceChain] rcases eq_or_ne (k + 1) q with rfl | hk'; · simp only [hq, bot_le] replace hk' : k + 1 ∈ Ioo p q := ⟨by linarith [hk.1], lt_of_le_of_ne hk.2 hk'⟩ exact le_biSup (fun k ↦ genWeightSpace M (k • α + χ)) hk' | zero => simp | add _ _ _ _ hz₁ hz₂ => rw [lie_add]; exact add_mem hz₁ hz₂ lemma lie_mem_genWeightSpaceChain_of_genWeightSpace_eq_bot_left [LieRing.IsNilpotent H] (hp : genWeightSpace M (p • α + χ) = ⊥) {x : L} (hx : x ∈ rootSpace H (-α)) {y : M} (hy : y ∈ genWeightSpaceChain M α χ p q) : ⁅x, y⁆ ∈ genWeightSpaceChain M α χ p q := by replace hp : genWeightSpace M ((-p) • (-α) + χ) = ⊥ := by rwa [smul_neg, neg_smul, neg_neg] rw [← genWeightSpaceChain_neg] at hy ⊢ exact lie_mem_genWeightSpaceChain_of_genWeightSpace_eq_bot_right M (-α) χ (-q) (-p) hp hx hy section IsCartanSubalgebra variable [H.IsCartanSubalgebra] [IsNoetherian R L] lemma trace_toEnd_genWeightSpaceChain_eq_zero (hp : genWeightSpace M (p • α + χ) = ⊥) (hq : genWeightSpace M (q • α + χ) = ⊥) {x : H} (hx : x ∈ corootSpace α) : LinearMap.trace R _ (toEnd R H (genWeightSpaceChain M α χ p q) x) = 0 := by rw [LieAlgebra.mem_corootSpace'] at hx induction hx using Submodule.span_induction with | mem u hu => obtain ⟨y, hy, z, hz, hyz⟩ := hu let f : Module.End R (genWeightSpaceChain M α χ p q) := { toFun := fun ⟨m, hm⟩ ↦ ⟨⁅(y : L), m⁆, lie_mem_genWeightSpaceChain_of_genWeightSpace_eq_bot_right M α χ p q hq hy hm⟩ map_add' := fun _ _ ↦ by simp map_smul' := fun t m ↦ by simp } let g : Module.End R (genWeightSpaceChain M α χ p q) := { toFun := fun ⟨m, hm⟩ ↦ ⟨⁅(z : L), m⁆, lie_mem_genWeightSpaceChain_of_genWeightSpace_eq_bot_left M α χ p q hp hz hm⟩ map_add' := fun _ _ ↦ by simp map_smul' := fun t m ↦ by simp } have hfg : toEnd R H _ u = ⁅f, g⁆ := by ext rw [toEnd_apply_apply, LieSubmodule.coe_bracket, LieSubalgebra.coe_bracket_of_module, ← hyz] simp only [lie_lie, LieHom.lie_apply, LinearMap.coe_mk, AddHom.coe_mk, Module.End.lie_apply, AddSubgroupClass.coe_sub, f, g] simp [hfg] | zero => simp | add => simp_all | smul => simp_all /-- Given a (potential) root `α` relative to a Cartan subalgebra `H`, if we restrict to the ideal `I = corootSpace α` of `H` (informally, `I = ⁅H(α), H(-α)⁆`), we may find an integral linear combination between `α` and any weight `χ` of a representation. This is Proposition 4.4 from [carter2005] and is a key step in the proof that the roots of a semisimple Lie algebra form a root system. It shows that the restriction of `α` to `I` vanishes iff the restriction of every root to `I` vanishes (which cannot happen in a semisimple Lie algebra). -/ lemma exists_forall_mem_corootSpace_smul_add_eq_zero [IsDomain R] [IsPrincipalIdealRing R] [CharZero R] [NoZeroSMulDivisors R M] [IsNoetherian R M] (hα : α ≠ 0) (hχ : genWeightSpace M χ ≠ ⊥) : ∃ a b : ℤ, 0 < b ∧ ∀ x ∈ corootSpace α, (a • α + b • χ) x = 0 := by obtain ⟨p, hp₀, q, hq₀, hp, hq⟩ := exists₂_genWeightSpace_smul_add_eq_bot M α χ hα let a := ∑ i ∈ Finset.Ioo p q, finrank R (genWeightSpace M (i • α + χ)) • i let b := ∑ i ∈ Finset.Ioo p q, finrank R (genWeightSpace M (i • α + χ)) have hb : 0 < b := by replace hχ : Nontrivial (genWeightSpace M χ) := by rwa [LieSubmodule.nontrivial_iff_ne_bot] refine Finset.sum_pos' (fun _ _ ↦ zero_le _) ⟨0, Finset.mem_Ioo.mpr ⟨hp₀, hq₀⟩, ?_⟩ rw [zero_smul, zero_add] exact finrank_pos refine ⟨a, b, Int.natCast_pos.mpr hb, fun x hx ↦ ?_⟩ let N : ℤ → Submodule R M := fun k ↦ genWeightSpace M (k • α + χ) have h₁ : iSupIndep fun (i : Finset.Ioo p q) ↦ N i := by rw [LieSubmodule.iSupIndep_toSubmodule] refine (iSupIndep_genWeightSpace R H M).comp fun i j hij ↦ ?_ exact SetCoe.ext <| smul_left_injective ℤ hα <| by rwa [add_left_inj] at hij have h₂ : ∀ i, MapsTo (toEnd R H M x) ↑(N i) ↑(N i) := fun _ _ ↦ LieSubmodule.lie_mem _ have h₃ : genWeightSpaceChain M α χ p q = ⨆ i ∈ Finset.Ioo p q, N i := by simp_rw [N, genWeightSpaceChain_def', LieSubmodule.iSup_toSubmodule] rw [← trace_toEnd_genWeightSpaceChain_eq_zero M α χ p q hp hq hx, ← LieSubmodule.toEnd_restrict_eq_toEnd] -- The lines below illustrate the cost of treating `LieSubmodule` as both a -- `Submodule` and a `LieSubmodule` simultaneously. #adaptation_note /-- 2025-06-18 (https://github.com/leanprover/lean4/issues/8804). The `erw` causes a kernel timeout if there is no `subst`. -/ subst a b N erw [LinearMap.trace_eq_sum_trace_restrict_of_eq_biSup _ h₁ h₂ (genWeightSpaceChain M α χ p q) h₃] simp_rw [LieSubmodule.toEnd_restrict_eq_toEnd] convert_to _ = ∑ k ∈ Finset.Ioo p q, (LinearMap.trace R { x // x ∈ (genWeightSpace M (k • α + χ)) }) ((toEnd R { x // x ∈ H } { x // x ∈ genWeightSpace M (k • α + χ) }) x) simp_rw [trace_toEnd_genWeightSpace, Pi.add_apply, Pi.smul_apply, smul_add, ← smul_assoc, Finset.sum_add_distrib, ← Finset.sum_smul, natCast_zsmul] end IsCartanSubalgebra end LieSubalgebra section variable {M} variable [LieRing.IsNilpotent L] variable [IsAddTorsionFree R] [NoZeroSMulDivisors R M] [IsNoetherian R M] variable (α : L → R) (β : Weight R L M) /-- This is the largest `n : ℕ` such that `i • α + β` is a weight for all `0 ≤ i ≤ n`. -/ noncomputable def chainTopCoeff : ℕ := letI := Classical.propDecidable if hα : α = 0 then 0 else Nat.pred <| Nat.find (show ∃ n, genWeightSpace M (n • α + β : L → R) = ⊥ from (eventually_genWeightSpace_smul_add_eq_bot M α β hα).exists) /-- This is the largest `n : ℕ` such that `-i • α + β` is a weight for all `0 ≤ i ≤ n`. -/ noncomputable def chainBotCoeff : ℕ := chainTopCoeff (-α) β @[simp] lemma chainTopCoeff_neg : chainTopCoeff (-α) β = chainBotCoeff α β := rfl @[simp] lemma chainBotCoeff_neg : chainBotCoeff (-α) β = chainTopCoeff α β := by rw [← chainTopCoeff_neg, neg_neg] @[simp] lemma chainTopCoeff_zero : chainTopCoeff 0 β = 0 := dif_pos rfl @[simp] lemma chainBotCoeff_zero : chainBotCoeff 0 β = 0 := dif_pos neg_zero section variable (hα : α ≠ 0) include hα lemma chainTopCoeff_add_one : letI := Classical.propDecidable chainTopCoeff α β + 1 = Nat.find (eventually_genWeightSpace_smul_add_eq_bot M α β hα).exists := by classical rw [chainTopCoeff, dif_neg hα] apply Nat.succ_pred_eq_of_pos rw [zero_lt_iff] intro e have : genWeightSpace M (0 • α + β : L → R) = ⊥ := by rw [← e] exact Nat.find_spec (eventually_genWeightSpace_smul_add_eq_bot M α β hα).exists exact β.genWeightSpace_ne_bot _ (by simpa only [zero_smul, zero_add] using this) lemma genWeightSpace_chainTopCoeff_add_one_nsmul_add : genWeightSpace M ((chainTopCoeff α β + 1) • α + β : L → R) = ⊥ := by classical rw [chainTopCoeff_add_one _ _ hα] exact Nat.find_spec (eventually_genWeightSpace_smul_add_eq_bot M α β hα).exists lemma genWeightSpace_chainTopCoeff_add_one_zsmul_add : genWeightSpace M ((chainTopCoeff α β + 1 : ℤ) • α + β : L → R) = ⊥ := by rw [← genWeightSpace_chainTopCoeff_add_one_nsmul_add α β hα, ← Nat.cast_smul_eq_nsmul ℤ, Nat.cast_add, Nat.cast_one] lemma genWeightSpace_chainBotCoeff_sub_one_zsmul_sub : genWeightSpace M ((-chainBotCoeff α β - 1 : ℤ) • α + β : L → R) = ⊥ := by rw [sub_eq_add_neg, ← neg_add, neg_smul, ← smul_neg, chainBotCoeff, genWeightSpace_chainTopCoeff_add_one_zsmul_add _ _ (by simpa using hα)] end lemma genWeightSpace_nsmul_add_ne_bot_of_le {n} (hn : n ≤ chainTopCoeff α β) : genWeightSpace M (n • α + β : L → R) ≠ ⊥ := by by_cases hα : α = 0 · rw [hα, smul_zero, zero_add]; exact β.genWeightSpace_ne_bot classical rw [← Nat.lt_succ, Nat.succ_eq_add_one, chainTopCoeff_add_one _ _ hα] at hn exact Nat.find_min (eventually_genWeightSpace_smul_add_eq_bot M α β hα).exists hn lemma genWeightSpace_zsmul_add_ne_bot {n : ℤ} (hn : -chainBotCoeff α β ≤ n) (hn' : n ≤ chainTopCoeff α β) : genWeightSpace M (n • α + β : L → R) ≠ ⊥ := by rcases n with (n | n) · simp only [Int.ofNat_eq_coe, Nat.cast_le, Nat.cast_smul_eq_nsmul] at hn' ⊢ exact genWeightSpace_nsmul_add_ne_bot_of_le α β hn' · simp only [Int.negSucc_eq, ← Nat.cast_succ, neg_le_neg_iff, Nat.cast_le] at hn ⊢ rw [neg_smul, ← smul_neg, Nat.cast_smul_eq_nsmul] exact genWeightSpace_nsmul_add_ne_bot_of_le (-α) β hn lemma genWeightSpace_neg_zsmul_add_ne_bot {n : ℕ} (hn : n ≤ chainBotCoeff α β) : genWeightSpace M ((-n : ℤ) • α + β : L → R) ≠ ⊥ := by apply genWeightSpace_zsmul_add_ne_bot α β <;> omega /-- The last weight in an `α`-chain through `β`. -/ noncomputable def chainTop (α : L → R) (β : Weight R L M) : Weight R L M := ⟨chainTopCoeff α β • α + β, genWeightSpace_nsmul_add_ne_bot_of_le α β le_rfl⟩ /-- The first weight in an `α`-chain through `β`. -/ noncomputable def chainBot (α : L → R) (β : Weight R L M) : Weight R L M := ⟨(- chainBotCoeff α β : ℤ) • α + β, genWeightSpace_neg_zsmul_add_ne_bot α β le_rfl⟩ lemma coe_chainTop' : (chainTop α β : L → R) = chainTopCoeff α β • α + β := rfl @[simp] lemma coe_chainTop : (chainTop α β : L → R) = (chainTopCoeff α β : ℤ) • α + β := by rw [Nat.cast_smul_eq_nsmul ℤ]; rfl @[simp] lemma coe_chainBot : (chainBot α β : L → R) = (-chainBotCoeff α β : ℤ) • α + β := rfl @[simp] lemma chainTop_neg : chainTop (-α) β = chainBot α β := by ext; simp @[simp] lemma chainBot_neg : chainBot (-α) β = chainTop α β := by ext; simp @[simp] lemma chainTop_zero : chainTop 0 β = β := by ext; simp @[simp] lemma chainBot_zero : chainBot 0 β = β := by ext; simp section variable (hα : α ≠ 0) include hα lemma genWeightSpace_add_chainTop : genWeightSpace M (α + chainTop α β : L → R) = ⊥ := by rw [coe_chainTop', ← add_assoc, ← succ_nsmul', genWeightSpace_chainTopCoeff_add_one_nsmul_add _ _ hα] lemma genWeightSpace_neg_add_chainBot : genWeightSpace M (-α + chainBot α β : L → R) = ⊥ := by rw [← chainTop_neg, genWeightSpace_add_chainTop _ _ (by simpa using hα)] lemma chainTop_isNonZero' (hα' : genWeightSpace M α ≠ ⊥) : (chainTop α β).IsNonZero := by by_contra e apply hα' rw [← add_zero (α : L → R), ← e, genWeightSpace_add_chainTop _ _ hα] end lemma chainTop_isNonZero (α β : Weight R L M) (hα : α.IsNonZero) : (chainTop α β).IsNonZero := chainTop_isNonZero' α β hα α.2 end end LieModule section Field open LieAlgebra LieModule variable {K : Type*} [Field K] [CharZero K] [LieAlgebra K L] (H : LieSubalgebra K L) [LieRing.IsNilpotent H] [Module K M] [LieModule K L M] [IsTriangularizable K H M] [FiniteDimensional K M] lemma LieModule.isNilpotent_toEnd_of_mem_rootSpace {x : L} {χ : H → K} (hχ : χ ≠ 0) (hx : x ∈ rootSpace H χ) : _root_.IsNilpotent (toEnd K L M x) := by refine Module.End.isNilpotent_iff_of_finite.mpr fun m ↦ ?_ have hm : m ∈ ⨆ χ : LieModule.Weight K H M, genWeightSpace M χ := by simp [iSup_genWeightSpace_eq_top' K H M] induction hm using LieSubmodule.iSup_induction' with | zero => exact ⟨0, map_zero _⟩ | mem χ₂ m₂ hm₂ => obtain ⟨n, -, hn⟩ := exists_genWeightSpace_smul_add_eq_bot M χ χ₂ hχ use n have := toEnd_pow_apply_mem hx hm₂ n rwa [hn, LieSubmodule.mem_bot] at this | add m₁ m₂ hm₁ hm₂ hm₁' hm₂' => obtain ⟨n₁, hn₁⟩ := hm₁' obtain ⟨n₂, hn₂⟩ := hm₂' refine ⟨max n₁ n₂, ?_⟩ rw [map_add, Module.End.pow_map_zero_of_le le_sup_left hn₁, Module.End.pow_map_zero_of_le le_sup_right hn₂, add_zero] lemma LieAlgebra.isNilpotent_ad_of_mem_rootSpace [IsTriangularizable K H L] [FiniteDimensional K L] {x : L} {χ : H → K} (hχ : χ ≠ 0) (hx : x ∈ rootSpace H χ) : _root_.IsNilpotent (ad K L x) := isNilpotent_toEnd_of_mem_rootSpace (M := L) H hχ hx end Field
.lake/packages/mathlib/Mathlib/Algebra/Lie/Weights/Cartan.lean
import Mathlib.Algebra.Lie.CartanSubalgebra import Mathlib.Algebra.Lie.Weights.Basic /-! # Weights and roots of Lie modules and Lie algebras with respect to Cartan subalgebras Given a Lie algebra `L` which is not necessarily nilpotent, it may be useful to study its representations by restricting them to a nilpotent subalgebra (e.g., a Cartan subalgebra). In the particular case when we view `L` as a module over itself via the adjoint action, the weight spaces of `L` restricted to a nilpotent subalgebra are known as root spaces. Basic definitions and properties of the above ideas are provided in this file. ## Main definitions * `LieAlgebra.rootSpace` * `LieAlgebra.corootSpace` * `LieAlgebra.rootSpaceWeightSpaceProduct` * `LieAlgebra.rootSpaceProduct` * `LieAlgebra.zeroRootSubalgebra_eq_iff_is_cartan` -/ open Set variable {R L : Type*} [CommRing R] [LieRing L] [LieAlgebra R L] (H : LieSubalgebra R L) [LieRing.IsNilpotent H] {M : Type*} [AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M] namespace LieAlgebra open scoped TensorProduct open TensorProduct.LieModule LieModule /-- Given a nilpotent Lie subalgebra `H ⊆ L`, the root space of a map `χ : H → R` is the weight space of `L` regarded as a module of `H` via the adjoint action. -/ abbrev rootSpace (χ : H → R) : LieSubmodule R H L := genWeightSpace L χ theorem zero_rootSpace_eq_top_of_nilpotent [LieRing.IsNilpotent L] : rootSpace (⊤ : LieSubalgebra R L) 0 = ⊤ := zero_genWeightSpace_eq_top_of_nilpotent L @[simp] theorem rootSpace_comap_eq_genWeightSpace (χ : H → R) : (rootSpace H χ).comap H.incl' = genWeightSpace H χ := comap_genWeightSpace_eq_of_injective Subtype.coe_injective variable {H} theorem lie_mem_genWeightSpace_of_mem_genWeightSpace {χ₁ χ₂ : H → R} {x : L} {m : M} (hx : x ∈ rootSpace H χ₁) (hm : m ∈ genWeightSpace M χ₂) : ⁅x, m⁆ ∈ genWeightSpace M (χ₁ + χ₂) := by rw [genWeightSpace, LieSubmodule.mem_iInf] intro y replace hx : x ∈ genWeightSpaceOf L (χ₁ y) y := by rw [rootSpace, genWeightSpace, LieSubmodule.mem_iInf] at hx; exact hx y replace hm : m ∈ genWeightSpaceOf M (χ₂ y) y := by rw [genWeightSpace, LieSubmodule.mem_iInf] at hm; exact hm y exact lie_mem_maxGenEigenspace_toEnd hx hm lemma toEnd_pow_apply_mem {χ₁ χ₂ : H → R} {x : L} {m : M} (hx : x ∈ rootSpace H χ₁) (hm : m ∈ genWeightSpace M χ₂) (n) : (toEnd R L M x ^ n : Module.End R M) m ∈ genWeightSpace M (n • χ₁ + χ₂) := by induction n with | zero => simpa using hm | succ n IH => simp only [pow_succ', Module.End.mul_apply, toEnd_apply_apply] convert lie_mem_genWeightSpace_of_mem_genWeightSpace hx IH using 2 rw [succ_nsmul, ← add_assoc, add_comm (n • _)] variable (R L H M) /-- Auxiliary definition for `rootSpaceWeightSpaceProduct`, which is close to the deterministic timeout limit. -/ def rootSpaceWeightSpaceProductAux {χ₁ χ₂ χ₃ : H → R} (hχ : χ₁ + χ₂ = χ₃) : rootSpace H χ₁ →ₗ[R] genWeightSpace M χ₂ →ₗ[R] genWeightSpace M χ₃ where toFun x := { toFun := fun m => ⟨⁅(x : L), (m : M)⁆, hχ ▸ lie_mem_genWeightSpace_of_mem_genWeightSpace x.property m.property⟩ map_add' := fun m n => by simp only [LieSubmodule.coe_add, lie_add, AddMemClass.mk_add_mk] map_smul' := fun t m => by simp } map_add' x y := by ext m simp only [LieSubmodule.coe_add, add_lie, LinearMap.coe_mk, AddHom.coe_mk, LinearMap.add_apply, AddMemClass.mk_add_mk] map_smul' t x := by simp only [RingHom.id_apply] ext m simp only [SetLike.val_smul, smul_lie, LinearMap.coe_mk, AddHom.coe_mk, LinearMap.smul_apply, SetLike.mk_smul_mk] /-- Given a nilpotent Lie subalgebra `H ⊆ L` together with `χ₁ χ₂ : H → R`, there is a natural `R`-bilinear product of root vectors and weight vectors, compatible with the actions of `H`. -/ def rootSpaceWeightSpaceProduct (χ₁ χ₂ χ₃ : H → R) (hχ : χ₁ + χ₂ = χ₃) : rootSpace H χ₁ ⊗[R] genWeightSpace M χ₂ →ₗ⁅R,H⁆ genWeightSpace M χ₃ := liftLie R H (rootSpace H χ₁) (genWeightSpace M χ₂) (genWeightSpace M χ₃) { toLinearMap := rootSpaceWeightSpaceProductAux R L H M hχ map_lie' := fun {x y} => by ext m simp only [rootSpaceWeightSpaceProductAux] dsimp simp only [lie_lie] } @[simp] theorem coe_rootSpaceWeightSpaceProduct_tmul (χ₁ χ₂ χ₃ : H → R) (hχ : χ₁ + χ₂ = χ₃) (x : rootSpace H χ₁) (m : genWeightSpace M χ₂) : (rootSpaceWeightSpaceProduct R L H M χ₁ χ₂ χ₃ hχ (x ⊗ₜ m) : M) = ⁅(x : L), (m : M)⁆ := by simp only [rootSpaceWeightSpaceProduct, rootSpaceWeightSpaceProductAux, coe_liftLie_eq_lift_coe, lift_apply, LinearMap.coe_mk, AddHom.coe_mk, Submodule.coe_mk] theorem mapsTo_toEnd_genWeightSpace_add_of_mem_rootSpace (α χ : H → R) {x : L} (hx : x ∈ rootSpace H α) : MapsTo (toEnd R L M x) (genWeightSpace M χ) (genWeightSpace M (α + χ)) := by intro m hm let x' : rootSpace H α := ⟨x, hx⟩ let m' : genWeightSpace M χ := ⟨m, hm⟩ exact (rootSpaceWeightSpaceProduct R L H M α χ (α + χ) rfl (x' ⊗ₜ m')).property /-- Given a nilpotent Lie subalgebra `H ⊆ L` together with `χ₁ χ₂ : H → R`, there is a natural `R`-bilinear product of root vectors, compatible with the actions of `H`. -/ def rootSpaceProduct (χ₁ χ₂ χ₃ : H → R) (hχ : χ₁ + χ₂ = χ₃) : rootSpace H χ₁ ⊗[R] rootSpace H χ₂ →ₗ⁅R,H⁆ rootSpace H χ₃ := rootSpaceWeightSpaceProduct R L H L χ₁ χ₂ χ₃ hχ @[simp] theorem rootSpaceProduct_def : rootSpaceProduct R L H = rootSpaceWeightSpaceProduct R L H L := rfl theorem rootSpaceProduct_tmul (χ₁ χ₂ χ₃ : H → R) (hχ : χ₁ + χ₂ = χ₃) (x : rootSpace H χ₁) (y : rootSpace H χ₂) : (rootSpaceProduct R L H χ₁ χ₂ χ₃ hχ (x ⊗ₜ y) : L) = ⁅(x : L), (y : L)⁆ := by simp only [rootSpaceProduct_def, coe_rootSpaceWeightSpaceProduct_tmul] /-- Given a nilpotent Lie subalgebra `H ⊆ L`, the root space of the zero map `0 : H → R` is a Lie subalgebra of `L`. -/ def zeroRootSubalgebra : LieSubalgebra R L := { toSubmodule := (rootSpace H 0 : Submodule R L) lie_mem' := fun {x y hx hy} => by let xy : rootSpace H 0 ⊗[R] rootSpace H 0 := ⟨x, hx⟩ ⊗ₜ ⟨y, hy⟩ suffices (rootSpaceProduct R L H 0 0 0 (add_zero 0) xy : L) ∈ rootSpace H 0 by rwa [rootSpaceProduct_tmul, Subtype.coe_mk, Subtype.coe_mk] at this exact (rootSpaceProduct R L H 0 0 0 (add_zero 0) xy).property } @[simp] theorem coe_zeroRootSubalgebra : (zeroRootSubalgebra R L H : Submodule R L) = rootSpace H 0 := rfl theorem mem_zeroRootSubalgebra (x : L) : x ∈ zeroRootSubalgebra R L H ↔ ∀ y : H, ∃ k : ℕ, (toEnd R H L y ^ k) x = 0 := by change x ∈ rootSpace H 0 ↔ _ simp only [mem_genWeightSpace, Pi.zero_apply, zero_smul, sub_zero] theorem toLieSubmodule_le_rootSpace_zero : H.toLieSubmodule ≤ rootSpace H 0 := by intro x hx simp only [LieSubalgebra.mem_toLieSubmodule] at hx simp only [mem_genWeightSpace, Pi.zero_apply, sub_zero, zero_smul] intro y obtain ⟨k, hk⟩ := IsNilpotent.nilpotent R H H use k let f : Module.End R H := toEnd R H H y let g : Module.End R L := toEnd R H L y have hfg : g.comp (H : Submodule R L).subtype = (H : Submodule R L).subtype.comp f := rfl change (g ^ k).comp (H : Submodule R L).subtype ⟨x, hx⟩ = 0 rw [Module.End.commute_pow_left_of_commute hfg k] have h := iterate_toEnd_mem_lowerCentralSeries R H H y ⟨x, hx⟩ k rw [hk, LieSubmodule.mem_bot] at h simp only [Submodule.subtype_apply, Function.comp_apply, Module.End.pow_apply, LinearMap.coe_comp, Submodule.coe_eq_zero] exact h /-- This enables the instance `Zero (Weight R H L)`. -/ instance [Nontrivial H] : Nontrivial (genWeightSpace L (0 : H → R)) := by obtain ⟨⟨x, hx⟩, ⟨y, hy⟩, e⟩ := exists_pair_ne H exact ⟨⟨x, toLieSubmodule_le_rootSpace_zero R L H hx⟩, ⟨y, toLieSubmodule_le_rootSpace_zero R L H hy⟩, by simpa using e⟩ theorem le_zeroRootSubalgebra : H ≤ zeroRootSubalgebra R L H := by rw [← LieSubalgebra.toSubmodule_le_toSubmodule, ← H.coe_toLieSubmodule, coe_zeroRootSubalgebra, LieSubmodule.toSubmodule_le_toSubmodule] exact toLieSubmodule_le_rootSpace_zero R L H @[simp] theorem zeroRootSubalgebra_normalizer_eq_self : (zeroRootSubalgebra R L H).normalizer = zeroRootSubalgebra R L H := by refine le_antisymm ?_ (LieSubalgebra.le_normalizer _) intro x hx rw [LieSubalgebra.mem_normalizer_iff] at hx rw [mem_zeroRootSubalgebra] rintro ⟨y, hy⟩ specialize hx y (le_zeroRootSubalgebra R L H hy) rw [mem_zeroRootSubalgebra] at hx obtain ⟨k, hk⟩ := hx ⟨y, hy⟩ rw [← lie_skew, LinearMap.map_neg, neg_eq_zero] at hk use k + 1 rw [Module.End.iterate_succ, LinearMap.coe_comp, Function.comp_apply, toEnd_apply_apply, LieSubalgebra.coe_bracket_of_module, Submodule.coe_mk, hk] /-- If the zero root subalgebra of a nilpotent Lie subalgebra `H` is just `H` then `H` is a Cartan subalgebra. When `L` is Noetherian, it follows from Engel's theorem that the converse holds. See `LieAlgebra.zeroRootSubalgebra_eq_iff_is_cartan` -/ theorem is_cartan_of_zeroRootSubalgebra_eq (h : zeroRootSubalgebra R L H = H) : H.IsCartanSubalgebra := { nilpotent := inferInstance self_normalizing := by rw [← h]; exact zeroRootSubalgebra_normalizer_eq_self R L H } @[simp] theorem zeroRootSubalgebra_eq_of_is_cartan (H : LieSubalgebra R L) [H.IsCartanSubalgebra] [IsNoetherian R L] : zeroRootSubalgebra R L H = H := by refine le_antisymm ?_ (le_zeroRootSubalgebra R L H) suffices rootSpace H 0 ≤ H.toLieSubmodule by exact fun x hx => this hx obtain ⟨k, hk⟩ := (rootSpace H 0).isNilpotent_iff_exists_self_le_ucs.mp (by infer_instance) exact hk.trans (LieSubmodule.ucs_le_of_normalizer_eq_self (by simp) k) theorem zeroRootSubalgebra_eq_iff_is_cartan [IsNoetherian R L] : zeroRootSubalgebra R L H = H ↔ H.IsCartanSubalgebra := ⟨is_cartan_of_zeroRootSubalgebra_eq R L H, by intros; simp⟩ @[simp] theorem rootSpace_zero_eq (H : LieSubalgebra R L) [H.IsCartanSubalgebra] [IsNoetherian R L] : rootSpace H 0 = H.toLieSubmodule := by rw [← LieSubmodule.toSubmodule_inj, ← coe_zeroRootSubalgebra, zeroRootSubalgebra_eq_of_is_cartan R L H, LieSubalgebra.coe_toLieSubmodule] variable {R L H} variable [H.IsCartanSubalgebra] [IsNoetherian R L] (α : H → R) /-- Given a root `α` relative to a Cartan subalgebra `H`, this is the span of all products of an element of the `α` root space and an element of the `-α` root space. Informally it is often denoted `⁅H(α), H(-α)⁆`. If the Killing form is non-degenerate and the coefficients are a perfect field, this space is one-dimensional. See `LieAlgebra.IsKilling.coe_corootSpace_eq_span_singleton` and `LieAlgebra.IsKilling.coe_corootSpace_eq_span_singleton'`. Note that the name "coroot space" is not standard as this space does not seem to have a name in the informal literature. -/ def corootSpace : LieIdeal R H := LieModuleHom.range <| ((rootSpace H 0).incl.comp <| rootSpaceProduct R L H α (-α) 0 (add_neg_cancel α)).codRestrict H.toLieSubmodule (by rw [← rootSpace_zero_eq] exact fun p ↦ (rootSpaceProduct R L H α (-α) 0 (add_neg_cancel α) p).property) lemma mem_corootSpace {x : H} : x ∈ corootSpace α ↔ (x : L) ∈ Submodule.span R {⁅y, z⁆ | (y ∈ rootSpace H α) (z ∈ rootSpace H (-α))} := by have : x ∈ corootSpace α ↔ (x : L) ∈ LieSubmodule.map H.toLieSubmodule.incl (corootSpace α) := by rw [corootSpace] simp only [rootSpaceProduct_def, LieModuleHom.mem_range, LieSubmodule.mem_map, LieSubmodule.incl_apply, SetLike.coe_eq_coe, exists_eq_right] rfl simp_rw [this, corootSpace, ← LieModuleHom.map_top, ← LieSubmodule.mem_toSubmodule, LieSubmodule.toSubmodule_map, LieSubmodule.top_toSubmodule, ← TensorProduct.span_tmul_eq_top, LinearMap.map_span, Set.image, Set.mem_setOf_eq, exists_exists_exists_and_eq] change (x : L) ∈ Submodule.span R {x | ∃ (a : rootSpace H α) (b : rootSpace H (-α)), ⁅(a : L), (b : L)⁆ = x} ↔ _ simp lemma mem_corootSpace' {x : H} : x ∈ corootSpace α ↔ x ∈ Submodule.span R ({⁅y, z⁆ | (y ∈ rootSpace H α) (z ∈ rootSpace H (-α))} : Set H) := by set s : Set H := ({⁅y, z⁆ | (y ∈ rootSpace H α) (z ∈ rootSpace H (-α))} : Set H) suffices H.subtype '' s = {⁅y, z⁆ | (y ∈ rootSpace H α) (z ∈ rootSpace H (-α))} by erw [← (H : Submodule R L).injective_subtype.mem_set_image (s := Submodule.span R s)] rw [mem_image] simp_rw [SetLike.mem_coe] rw [← Submodule.mem_map, Submodule.coe_subtype, Submodule.map_span, mem_corootSpace, ← this] ext u simp only [Submodule.coe_subtype, mem_image, Subtype.exists, LieSubalgebra.mem_toSubmodule, exists_and_right, exists_eq_right, mem_setOf_eq, s] refine ⟨fun ⟨_, y, hy, z, hz, hyz⟩ ↦ ⟨y, hy, z, hz, hyz⟩, fun ⟨y, hy, z, hz, hyz⟩ ↦ ⟨?_, y, hy, z, hz, hyz⟩⟩ convert (rootSpaceProduct R L H α (-α) 0 (add_neg_cancel α) (⟨y, hy⟩ ⊗ₜ[R] ⟨z, hz⟩)).property using 0 simp [hyz] end LieAlgebra
.lake/packages/mathlib/Mathlib/Algebra/Lie/Weights/Linear.lean
import Mathlib.Algebra.Lie.Weights.Basic import Mathlib.LinearAlgebra.Trace import Mathlib.LinearAlgebra.FreeModule.PID /-! # Lie modules with linear weights Given a Lie module `M` over a nilpotent Lie algebra `L` with coefficients in `R`, one frequently studies `M` via its weights. These are functions `χ : L → R` whose corresponding weight space `LieModule.genWeightSpace M χ`, is non-trivial. If `L` is Abelian or if `R` has characteristic zero (and `M` is finite-dimensional) then such `χ` are necessarily `R`-linear. However in general non-linear weights do exist. For example if we take: * `R`: the field with two elements (or indeed any perfect field of characteristic two), * `L`: `sl₂` (this is nilpotent in characteristic two), * `M`: the natural two-dimensional representation of `L`, then there is a single weight and it is non-linear. (See remark following Proposition 9 of chapter VII, §1.3 in [N. Bourbaki, Chapters 7--9](bourbaki1975b).) We thus introduce a typeclass `LieModule.LinearWeights` to encode the fact that a Lie module does have linear weights and provide typeclass instances in the two important cases that `L` is Abelian or `R` has characteristic zero. ## Main definitions * `LieModule.LinearWeights`: a typeclass encoding the fact that a given Lie module has linear weights, and furthermore that the weights vanish on the derived ideal. * `LieModule.instLinearWeightsOfCharZero`: a typeclass instance encoding the fact that for an Abelian Lie algebra, the weights of any Lie module are linear. * `LieModule.instLinearWeightsOfIsLieAbelian`: a typeclass instance encoding the fact that in characteristic zero, the weights of any finite-dimensional Lie module are linear. * `LieModule.exists_forall_lie_eq_smul`: existence of simultaneous eigenvectors from existence of simultaneous generalized eigenvectors for Noetherian Lie modules with linear weights. -/ open Set variable (k R L M : Type*) [CommRing R] [LieRing L] [LieAlgebra R L] [AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M] namespace LieModule /-- A typeclass encoding the fact that a given Lie module has linear weights, vanishing on the derived ideal. -/ class LinearWeights [LieRing.IsNilpotent L] : Prop where map_add : ∀ χ : L → R, genWeightSpace M χ ≠ ⊥ → ∀ x y, χ (x + y) = χ x + χ y map_smul : ∀ χ : L → R, genWeightSpace M χ ≠ ⊥ → ∀ (t : R) x, χ (t • x) = t • χ x map_lie : ∀ χ : L → R, genWeightSpace M χ ≠ ⊥ → ∀ x y : L, χ ⁅x, y⁆ = 0 namespace Weight variable [LieRing.IsNilpotent L] [LinearWeights R L M] (χ : Weight R L M) /-- A weight of a Lie module, bundled as a linear map. -/ @[simps] def toLinear : L →ₗ[R] R where toFun := χ map_add' := LinearWeights.map_add χ χ.genWeightSpace_ne_bot map_smul' := LinearWeights.map_smul χ χ.genWeightSpace_ne_bot instance instCoeLinearMap : CoeOut (Weight R L M) (L →ₗ[R] R) where coe := Weight.toLinear R L M instance instLinearMapClass : LinearMapClass (Weight R L M) R L R where map_add χ := LinearWeights.map_add χ χ.genWeightSpace_ne_bot map_smulₛₗ χ := LinearWeights.map_smul χ χ.genWeightSpace_ne_bot variable {R L M χ} @[simp] lemma apply_lie (x y : L) : χ ⁅x, y⁆ = 0 := LinearWeights.map_lie χ χ.genWeightSpace_ne_bot x y @[simp] lemma coe_coe : (↑(χ : L →ₗ[R] R) : L → R) = (χ : L → R) := rfl @[simp] lemma coe_toLinear_eq_zero_iff : (χ : L →ₗ[R] R) = 0 ↔ χ.IsZero := ⟨fun h ↦ funext fun x ↦ LinearMap.congr_fun h x, fun h ↦ by ext; simp [h.eq]⟩ lemma coe_toLinear_ne_zero_iff : (χ : L →ₗ[R] R) ≠ 0 ↔ χ.IsNonZero := by simp /-- The kernel of a weight of a Lie module with linear weights. -/ abbrev ker := LinearMap.ker (χ : L →ₗ[R] R) end Weight /-- For an Abelian Lie algebra, the weights of any Lie module are linear. -/ instance instLinearWeightsOfIsLieAbelian [IsLieAbelian L] [NoZeroSMulDivisors R M] : LinearWeights R L M := have aux : ∀ (χ : L → R), genWeightSpace M χ ≠ ⊥ → ∀ (x y : L), χ (x + y) = χ x + χ y := by have h : ∀ x y, Commute (toEnd R L M x) (toEnd R L M y) := fun x y ↦ by rw [commute_iff_lie_eq, ← LieHom.map_lie, trivial_lie_zero, map_zero] intro χ hχ x y simp_rw [Ne, ← LieSubmodule.toSubmodule_inj, genWeightSpace, genWeightSpaceOf, LieSubmodule.iInf_toSubmodule, LieSubmodule.bot_toSubmodule] at hχ exact Module.End.map_add_of_iInf_genEigenspace_ne_bot_of_commute (toEnd R L M).toLinearMap χ _ hχ h x y { map_add := aux map_smul := fun χ hχ t x ↦ by simp_rw [Ne, ← LieSubmodule.toSubmodule_inj, genWeightSpace, genWeightSpaceOf, LieSubmodule.iInf_toSubmodule, LieSubmodule.bot_toSubmodule] at hχ exact Module.End.map_smul_of_iInf_genEigenspace_ne_bot (toEnd R L M).toLinearMap χ _ hχ t x map_lie := fun χ hχ t x ↦ by rw [trivial_lie_zero, ← add_left_inj (χ 0), ← aux χ hχ, zero_add, zero_add] } section FiniteDimensional open Module variable [IsDomain R] [IsPrincipalIdealRing R] [Module.Free R M] [Module.Finite R M] [LieRing.IsNilpotent L] lemma trace_comp_toEnd_genWeightSpace_eq (χ : L → R) : LinearMap.trace R _ ∘ₗ (toEnd R L (genWeightSpace M χ)).toLinearMap = finrank R (genWeightSpace M χ) • χ := by ext x simp variable {R L M} in lemma zero_lt_finrank_genWeightSpace {χ : L → R} (hχ : genWeightSpace M χ ≠ ⊥) : 0 < finrank R (genWeightSpace M χ) := by rwa [← LieSubmodule.nontrivial_iff_ne_bot, ← rank_pos_iff_nontrivial (R := R), ← finrank_eq_rank, Nat.cast_pos] at hχ /-- In characteristic zero, the weights of any finite-dimensional Lie module are linear and vanish on the derived ideal. -/ instance instLinearWeightsOfCharZero [CharZero R] : LinearWeights R L M where map_add χ hχ x y := by rw [← smul_right_inj (zero_lt_finrank_genWeightSpace hχ).ne', smul_add, ← Pi.smul_apply, ← Pi.smul_apply, ← Pi.smul_apply, ← trace_comp_toEnd_genWeightSpace_eq, map_add] map_smul χ hχ t x := by rw [← smul_right_inj (zero_lt_finrank_genWeightSpace hχ).ne', smul_comm, ← Pi.smul_apply, ← Pi.smul_apply (finrank R _), ← trace_comp_toEnd_genWeightSpace_eq, map_smul] map_lie χ hχ x y := by rw [← smul_right_inj (zero_lt_finrank_genWeightSpace hχ).ne', nsmul_zero, ← Pi.smul_apply, ← trace_comp_toEnd_genWeightSpace_eq, LinearMap.comp_apply, LieHom.coe_toLinearMap, LieHom.map_lie, Ring.lie_def, map_sub, LinearMap.trace_mul_comm, sub_self] end FiniteDimensional variable [LieRing.IsNilpotent L] (χ : L → R) /-- A type synonym for the `χ`-weight space but with the action of `x : L` on `m : genWeightSpace M χ`, shifted to act as `⁅x, m⁆ - χ x • m`. -/ def shiftedGenWeightSpace := genWeightSpace M χ namespace shiftedGenWeightSpace private lemma aux [h : Nontrivial (shiftedGenWeightSpace R L M χ)] : genWeightSpace M χ ≠ ⊥ := (LieSubmodule.nontrivial_iff_ne_bot _ _ _).mp h variable [LinearWeights R L M] instance : LieRingModule L (shiftedGenWeightSpace R L M χ) where bracket x m := ⁅x, m⁆ - χ x • m add_lie x y m := by nontriviality shiftedGenWeightSpace R L M χ simp only [add_lie, LinearWeights.map_add χ (aux R L M χ), add_smul] abel lie_add x m n := by nontriviality shiftedGenWeightSpace R L M χ simp only [lie_add, smul_add] abel leibniz_lie x y m := by nontriviality shiftedGenWeightSpace R L M χ simp only [lie_sub, lie_smul, lie_lie, LinearWeights.map_lie χ (aux R L M χ), zero_smul, sub_zero, smul_sub, smul_comm (χ x)] abel @[simp] lemma coe_lie_shiftedGenWeightSpace_apply (x : L) (m : shiftedGenWeightSpace R L M χ) : letI : Bracket L (shiftedGenWeightSpace R L M χ) := LieRingModule.toBracket ⁅x, m⁆ = ⁅x, (m : M)⁆ - χ x • m := rfl instance : LieModule R L (shiftedGenWeightSpace R L M χ) where smul_lie t x m := by nontriviality shiftedGenWeightSpace R L M χ apply Subtype.ext rw [coe_lie_shiftedGenWeightSpace_apply] simp only [smul_lie, LinearWeights.map_smul χ (aux R L M χ), smul_assoc t, SetLike.val_smul] rw [← smul_sub] congr lie_smul t x m := by nontriviality shiftedGenWeightSpace R L M χ apply Subtype.ext rw [coe_lie_shiftedGenWeightSpace_apply] simp only [SetLike.val_smul, lie_smul] rw [smul_comm (χ x), ← smul_sub] congr /-- Forgetting the action of `L`, the spaces `genWeightSpace M χ` and `shiftedGenWeightSpace R L M χ` are equivalent. -/ @[simps!] def shift : genWeightSpace M χ ≃ₗ[R] shiftedGenWeightSpace R L M χ := LinearEquiv.refl R _ lemma toEnd_eq (x : L) : toEnd R L (shiftedGenWeightSpace R L M χ) x = (shift R L M χ).conj (toEnd R L (genWeightSpace M χ) x - χ x • LinearMap.id) := by tauto /-- By Engel's theorem, if `M` is Noetherian, the shifted action `⁅x, m⁆ - χ x • m` makes the `χ`-weight space into a nilpotent Lie module. -/ instance [IsNoetherian R M] : IsNilpotent L (shiftedGenWeightSpace R L M χ) := LieModule.isNilpotent_iff_forall'.mpr fun x ↦ isNilpotent_toEnd_sub_algebraMap M χ x end shiftedGenWeightSpace open shiftedGenWeightSpace in /-- Given a Lie module `M` of a nilpotent Lie algebra `L` with coefficients in `R`, if a function `χ : L → R` has a simultaneous generalized eigenvector for the action of `L` then it has a simultaneous true eigenvector, provided `M` is Noetherian and has linear weights. -/ lemma exists_forall_lie_eq_smul [LinearWeights R L M] [IsNoetherian R M] (χ : Weight R L M) : ∃ m : M, m ≠ 0 ∧ ∀ x : L, ⁅x, m⁆ = χ x • m := by replace hχ : Nontrivial (shiftedGenWeightSpace R L M χ) := (LieSubmodule.nontrivial_iff_ne_bot R L M).mpr χ.genWeightSpace_ne_bot obtain ⟨⟨⟨m, _⟩, hm₁⟩, hm₂⟩ := @exists_ne _ (nontrivial_max_triv_of_isNilpotent R L (shiftedGenWeightSpace R L M χ)) 0 simp_rw [mem_maxTrivSubmodule, Subtype.ext_iff, ZeroMemClass.coe_zero] at hm₁ refine ⟨m, by simpa [LieSubmodule.mk_eq_zero] using hm₂, ?_⟩ intro x have := hm₁ x rwa [coe_lie_shiftedGenWeightSpace_apply, sub_eq_zero] at this /-- See `LieModule.exists_nontrivial_weightSpace_of_isSolvable` for the variant that only assumes that `L` is solvable but additionally requires `k` to be of characteristic zero. -/ lemma exists_nontrivial_weightSpace_of_isNilpotent [Field k] [LieAlgebra k L] [Module k M] [Module.Finite k M] [LieModule k L M] [LinearWeights k L M] [IsTriangularizable k L M] [Nontrivial M] : ∃ χ : Module.Dual k L, Nontrivial (weightSpace M χ) := by obtain ⟨χ⟩ : Nonempty (Weight k L M) := by by_contra! contra simpa only [iSup_of_empty, bot_ne_top] using LieModule.iSup_genWeightSpace_eq_top' k L M obtain ⟨m, hm₀, hm⟩ := exists_forall_lie_eq_smul k L M χ simp only [LieSubmodule.nontrivial_iff_ne_bot, LieSubmodule.eq_bot_iff, ne_eq, not_forall] exact ⟨χ.toLinear, m, by simpa [mem_weightSpace], hm₀⟩ end LieModule
.lake/packages/mathlib/Mathlib/Algebra/Lie/Weights/Basic.lean
import Mathlib.Algebra.Ring.Divisibility.Lemmas import Mathlib.Algebra.Lie.Nilpotent import Mathlib.Algebra.Lie.Engel import Mathlib.LinearAlgebra.Eigenspace.Pi import Mathlib.RingTheory.Artinian.Module import Mathlib.LinearAlgebra.Trace import Mathlib.LinearAlgebra.FreeModule.PID /-! # Weight spaces of Lie modules of nilpotent Lie algebras Just as a key tool when studying the behaviour of a linear operator is to decompose the space on which it acts into a sum of (generalised) eigenspaces, a key tool when studying a representation `M` of Lie algebra `L` is to decompose `M` into a sum of simultaneous eigenspaces of `x` as `x` ranges over `L`. These simultaneous generalised eigenspaces are known as the weight spaces of `M`. When `L` is nilpotent, it follows from the binomial theorem that weight spaces are Lie submodules. Basic definitions and properties of the above ideas are provided in this file. ## Main definitions * `LieModule.genWeightSpaceOf` * `LieModule.genWeightSpace` * `LieModule.Weight` * `LieModule.posFittingCompOf` * `LieModule.posFittingComp` * `LieModule.iSup_ucs_eq_genWeightSpace_zero` * `LieModule.iInf_lowerCentralSeries_eq_posFittingComp` * `LieModule.isCompl_genWeightSpace_zero_posFittingComp` * `LieModule.iSupIndep_genWeightSpace` * `LieModule.iSup_genWeightSpace_eq_top` ## References * [N. Bourbaki, *Lie Groups and Lie Algebras, Chapters 7--9*](bourbaki1975b) ## Tags lie character, eigenvalue, eigenspace, weight, weight vector, root, root vector -/ variable {K R L M : Type*} [CommRing R] [LieRing L] [LieAlgebra R L] [AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M] namespace LieModule open Set Function TensorProduct LieModule variable (M) in /-- If `M` is a representation of a Lie algebra `L` and `χ : L → R` is a family of scalars, then `weightSpace M χ` is the intersection of the `χ x`-eigenspaces of the action of `x` on `M` as `x` ranges over `L`. -/ def weightSpace (χ : L → R) : LieSubmodule R L M where __ := ⨅ x : L, (toEnd R L M x).eigenspace (χ x) lie_mem {x m} hm := by simp_all [smul_comm (χ x)] lemma mem_weightSpace (χ : L → R) (m : M) : m ∈ weightSpace M χ ↔ ∀ x, ⁅x, m⁆ = χ x • m := by simp [weightSpace] section notation_genWeightSpaceOf /-- Until we define `LieModule.genWeightSpaceOf`, it is useful to have some notation as follows: -/ local notation3 "𝕎("M", " χ", " x")" => (toEnd R L M x).maxGenEigenspace χ /-- See also `bourbaki1975b` Chapter VII §1.1, Proposition 2 (ii). -/ protected theorem weight_vector_multiplication (M₁ M₂ M₃ : Type*) [AddCommGroup M₁] [Module R M₁] [LieRingModule L M₁] [LieModule R L M₁] [AddCommGroup M₂] [Module R M₂] [LieRingModule L M₂] [LieModule R L M₂] [AddCommGroup M₃] [Module R M₃] [LieRingModule L M₃] [LieModule R L M₃] (g : M₁ ⊗[R] M₂ →ₗ⁅R,L⁆ M₃) (χ₁ χ₂ : R) (x : L) : LinearMap.range ((g : M₁ ⊗[R] M₂ →ₗ[R] M₃).comp (mapIncl 𝕎(M₁, χ₁, x) 𝕎(M₂, χ₂, x))) ≤ 𝕎(M₃, χ₁ + χ₂, x) := by -- Unpack the statement of the goal. intro m₃ simp only [TensorProduct.mapIncl, LinearMap.mem_range, LinearMap.coe_comp, LieModuleHom.coe_toLinearMap, Function.comp_apply, exists_imp, Module.End.mem_maxGenEigenspace] rintro t rfl -- Set up some notation. let F : Module.End R M₃ := toEnd R L M₃ x - (χ₁ + χ₂) • ↑1 -- The goal is linear in `t` so use induction to reduce to the case that `t` is a pure tensor. refine t.induction_on ?_ ?_ ?_ · use 0; simp only [map_zero] swap · rintro t₁ t₂ ⟨k₁, hk₁⟩ ⟨k₂, hk₂⟩; use max k₁ k₂ simp only [map_add, Module.End.pow_map_zero_of_le (le_max_left k₁ k₂) hk₁, Module.End.pow_map_zero_of_le (le_max_right k₁ k₂) hk₂, add_zero] -- Now the main argument: pure tensors. rintro ⟨m₁, hm₁⟩ ⟨m₂, hm₂⟩ change ∃ k, (F ^ k) ((g : M₁ ⊗[R] M₂ →ₗ[R] M₃) (m₁ ⊗ₜ m₂)) = (0 : M₃) -- Eliminate `g` from the picture. let f₁ : Module.End R (M₁ ⊗[R] M₂) := (toEnd R L M₁ x - χ₁ • ↑1).rTensor M₂ let f₂ : Module.End R (M₁ ⊗[R] M₂) := (toEnd R L M₂ x - χ₂ • ↑1).lTensor M₁ have h_comm_square : F ∘ₗ ↑g = (g : M₁ ⊗[R] M₂ →ₗ[R] M₃).comp (f₁ + f₂) := by ext m₁ m₂ simp only [f₁, f₂, F, ← g.map_lie x (m₁ ⊗ₜ m₂), add_smul, sub_tmul, tmul_sub, smul_tmul, lie_tmul_right, tmul_smul, toEnd_apply_apply, map_smul, Module.End.one_apply, LieModuleHom.coe_toLinearMap, LinearMap.smul_apply, Function.comp_apply, LinearMap.coe_comp, LinearMap.rTensor_tmul, map_add, LinearMap.add_apply, map_sub, LinearMap.sub_apply, LinearMap.lTensor_tmul, AlgebraTensorModule.curry_apply, TensorProduct.curry_apply, LinearMap.coe_restrictScalars] abel rsuffices ⟨k, hk⟩ : ∃ k : ℕ, ((f₁ + f₂) ^ k) (m₁ ⊗ₜ m₂) = 0 · use k change (F ^ k) (g.toLinearMap (m₁ ⊗ₜ[R] m₂)) = 0 rw [← LinearMap.comp_apply, Module.End.commute_pow_left_of_commute h_comm_square, LinearMap.comp_apply, hk, LinearMap.map_zero] -- Unpack the information we have about `m₁`, `m₂`. simp only [Module.End.mem_maxGenEigenspace] at hm₁ hm₂ obtain ⟨k₁, hk₁⟩ := hm₁ obtain ⟨k₂, hk₂⟩ := hm₂ have hf₁ : (f₁ ^ k₁) (m₁ ⊗ₜ m₂) = 0 := by simp only [f₁, hk₁, zero_tmul, LinearMap.rTensor_tmul, LinearMap.rTensor_pow] have hf₂ : (f₂ ^ k₂) (m₁ ⊗ₜ m₂) = 0 := by simp only [f₂, hk₂, tmul_zero, LinearMap.lTensor_tmul, LinearMap.lTensor_pow] -- It's now just an application of the binomial theorem. use k₁ + k₂ - 1 have hf_comm : Commute f₁ f₂ := by ext m₁ m₂ simp only [f₁, f₂, Module.End.mul_apply, LinearMap.rTensor_tmul, LinearMap.lTensor_tmul, AlgebraTensorModule.curry_apply, LinearMap.lTensor_tmul, TensorProduct.curry_apply, LinearMap.coe_restrictScalars] rw [hf_comm.add_pow'] simp only [Finset.sum_apply, LinearMap.coeFn_sum, LinearMap.smul_apply] -- The required sum is zero because each individual term is zero. apply Finset.sum_eq_zero rintro ⟨i, j⟩ hij -- Eliminate the binomial coefficients from the picture. suffices (f₁ ^ i * f₂ ^ j) (m₁ ⊗ₜ m₂) = 0 by rw [this]; apply smul_zero -- Finish off with appropriate case analysis. rcases Nat.le_or_le_of_add_eq_add_pred (Finset.mem_antidiagonal.mp hij) with hi | hj · rw [(hf_comm.pow_pow i j).eq, Module.End.mul_apply, Module.End.pow_map_zero_of_le hi hf₁, LinearMap.map_zero] · rw [Module.End.mul_apply, Module.End.pow_map_zero_of_le hj hf₂, LinearMap.map_zero] lemma lie_mem_maxGenEigenspace_toEnd {χ₁ χ₂ : R} {x y : L} {m : M} (hy : y ∈ 𝕎(L, χ₁, x)) (hm : m ∈ 𝕎(M, χ₂, x)) : ⁅y, m⁆ ∈ 𝕎(M, χ₁ + χ₂, x) := by apply LieModule.weight_vector_multiplication L M M (toModuleHom R L M) χ₁ χ₂ simp only [LieModuleHom.coe_toLinearMap, Function.comp_apply, LinearMap.coe_comp, TensorProduct.mapIncl, LinearMap.mem_range] use ⟨y, hy⟩ ⊗ₜ ⟨m, hm⟩ simp only [Submodule.subtype_apply, toModuleHom_apply, TensorProduct.map_tmul] variable (M) /-- If `M` is a representation of a nilpotent Lie algebra `L`, `χ` is a scalar, and `x : L`, then `genWeightSpaceOf M χ x` is the maximal generalized `χ`-eigenspace of the action of `x` on `M`. It is a Lie submodule because `L` is nilpotent. -/ def genWeightSpaceOf [LieRing.IsNilpotent L] (χ : R) (x : L) : LieSubmodule R L M := { 𝕎(M, χ, x) with lie_mem := by intro y m hm simp only [AddSubsemigroup.mem_carrier, AddSubmonoid.mem_toSubsemigroup, Submodule.mem_toAddSubmonoid] at hm ⊢ rw [← zero_add χ] exact lie_mem_maxGenEigenspace_toEnd (by simp) hm } end notation_genWeightSpaceOf variable (M) variable [LieRing.IsNilpotent L] theorem mem_genWeightSpaceOf (χ : R) (x : L) (m : M) : m ∈ genWeightSpaceOf M χ x ↔ ∃ k : ℕ, ((toEnd R L M x - χ • ↑1) ^ k) m = 0 := by simp [genWeightSpaceOf] theorem coe_genWeightSpaceOf_zero (x : L) : ↑(genWeightSpaceOf M (0 : R) x) = ⨆ k, LinearMap.ker (toEnd R L M x ^ k) := by simp [genWeightSpaceOf, ← Module.End.iSup_genEigenspace_eq] /-- If `M` is a representation of a nilpotent Lie algebra `L` and `χ : L → R` is a family of scalars, then `genWeightSpace M χ` is the intersection of the maximal generalized `χ x`-eigenspaces of the action of `x` on `M` as `x` ranges over `L`. It is a Lie submodule because `L` is nilpotent. -/ def genWeightSpace (χ : L → R) : LieSubmodule R L M := ⨅ x, genWeightSpaceOf M (χ x) x theorem mem_genWeightSpace (χ : L → R) (m : M) : m ∈ genWeightSpace M χ ↔ ∀ x, ∃ k : ℕ, ((toEnd R L M x - χ x • ↑1) ^ k) m = 0 := by simp [genWeightSpace, mem_genWeightSpaceOf] lemma genWeightSpace_le_genWeightSpaceOf (x : L) (χ : L → R) : genWeightSpace M χ ≤ genWeightSpaceOf M (χ x) x := iInf_le _ x lemma weightSpace_le_genWeightSpace (χ : L → R) : weightSpace M χ ≤ genWeightSpace M χ := by apply le_iInf intro x rw [← (LieSubmodule.toSubmodule_orderEmbedding R L M).le_iff_le] apply (iInf_le _ x).trans exact ((toEnd R L M x).genEigenspace (χ x)).monotone le_top variable (R L) in /-- A weight of a Lie module is a map `L → R` such that the corresponding weight space is non-trivial. -/ structure Weight where /-- The family of eigenvalues corresponding to a weight. -/ toFun : L → R genWeightSpace_ne_bot' : genWeightSpace M toFun ≠ ⊥ namespace Weight instance instFunLike : FunLike (Weight R L M) L R where coe χ := χ.1 coe_injective' χ₁ χ₂ h := by cases χ₁; cases χ₂; simp_all @[simp] lemma coe_weight_mk (χ : L → R) (h) : (↑(⟨χ, h⟩ : Weight R L M) : L → R) = χ := rfl lemma genWeightSpace_ne_bot (χ : Weight R L M) : genWeightSpace M χ ≠ ⊥ := χ.genWeightSpace_ne_bot' variable {M} @[ext] lemma ext {χ₁ χ₂ : Weight R L M} (h : ∀ x, χ₁ x = χ₂ x) : χ₁ = χ₂ := by obtain ⟨f₁, _⟩ := χ₁; obtain ⟨f₂, _⟩ := χ₂; aesop lemma ext_iff' {χ₁ χ₂ : Weight R L M} : (χ₁ : L → R) = χ₂ ↔ χ₁ = χ₂ := by simp lemma exists_ne_zero (χ : Weight R L M) : ∃ x ∈ genWeightSpace M χ, x ≠ 0 := by simpa [LieSubmodule.eq_bot_iff] using χ.genWeightSpace_ne_bot instance [Subsingleton M] : IsEmpty (Weight R L M) := ⟨fun h ↦ h.2 (Subsingleton.elim _ _)⟩ instance [Nontrivial (genWeightSpace M (0 : L → R))] : Zero (Weight R L M) := ⟨0, fun e ↦ not_nontrivial (⊥ : LieSubmodule R L M) (e ▸ ‹_›)⟩ @[simp] lemma coe_zero [Nontrivial (genWeightSpace M (0 : L → R))] : ((0 : Weight R L M) : L → R) = 0 := rfl lemma zero_apply [Nontrivial (genWeightSpace M (0 : L → R))] (x) : (0 : Weight R L M) x = 0 := rfl /-- The proposition that a weight of a Lie module is zero. We make this definition because we cannot define a `Zero (Weight R L M)` instance since the weight space of the zero function can be trivial. -/ def IsZero (χ : Weight R L M) := (χ : L → R) = 0 @[simp] lemma IsZero.eq {χ : Weight R L M} (hχ : χ.IsZero) : (χ : L → R) = 0 := hχ @[simp] lemma coe_eq_zero_iff (χ : Weight R L M) : (χ : L → R) = 0 ↔ χ.IsZero := Iff.rfl lemma isZero_iff_eq_zero [Nontrivial (genWeightSpace M (0 : L → R))] {χ : Weight R L M} : χ.IsZero ↔ χ = 0 := Weight.ext_iff' (χ₂ := 0) lemma isZero_zero [Nontrivial (genWeightSpace M (0 : L → R))] : IsZero (0 : Weight R L M) := rfl /-- The proposition that a weight of a Lie module is non-zero. -/ abbrev IsNonZero (χ : Weight R L M) := ¬ IsZero (χ : Weight R L M) lemma isNonZero_iff_ne_zero [Nontrivial (genWeightSpace M (0 : L → R))] {χ : Weight R L M} : χ.IsNonZero ↔ χ ≠ 0 := isZero_iff_eq_zero.not noncomputable instance : DecidablePred (IsNonZero (R := R) (L := L) (M := M)) := Classical.decPred _ variable (R L M) in /-- The set of weights is equivalent to a subtype. -/ def equivSetOf : Weight R L M ≃ {χ : L → R | genWeightSpace M χ ≠ ⊥} where toFun w := ⟨w.1, w.2⟩ invFun w := ⟨w.1, w.2⟩ left_inv w := by simp right_inv w := by simp lemma genWeightSpaceOf_ne_bot (χ : Weight R L M) (x : L) : genWeightSpaceOf M (χ x) x ≠ ⊥ := by have : ⨅ x, genWeightSpaceOf M (χ x) x ≠ ⊥ := χ.genWeightSpace_ne_bot contrapose! this rw [eq_bot_iff] exact le_of_le_of_eq (iInf_le _ _) this lemma hasEigenvalueAt (χ : Weight R L M) (x : L) : (toEnd R L M x).HasEigenvalue (χ x) := by obtain ⟨k : ℕ, hk : (toEnd R L M x).genEigenspace (χ x) k ≠ ⊥⟩ := by simpa [genWeightSpaceOf, ← Module.End.iSup_genEigenspace_eq] using χ.genWeightSpaceOf_ne_bot x exact Module.End.hasEigenvalue_of_hasGenEigenvalue hk lemma apply_eq_zero_of_isNilpotent [NoZeroSMulDivisors R M] [IsReduced R] (x : L) (h : _root_.IsNilpotent (toEnd R L M x)) (χ : Weight R L M) : χ x = 0 := ((χ.hasEigenvalueAt x).isNilpotent_of_isNilpotent h).eq_zero end Weight /-- See also the more useful form `LieModule.zero_genWeightSpace_eq_top_of_nilpotent`. -/ @[simp] theorem zero_genWeightSpace_eq_top_of_nilpotent' [IsNilpotent L M] : genWeightSpace M (0 : L → R) = ⊤ := by simp [genWeightSpace, genWeightSpaceOf] theorem coe_genWeightSpace_of_top (χ : L → R) : (genWeightSpace M (χ ∘ (⊤ : LieSubalgebra R L).incl) : Submodule R M) = genWeightSpace M χ := by ext m simp only [mem_genWeightSpace, LieSubmodule.mem_toSubmodule, Subtype.forall] apply forall_congr' simp @[simp] theorem zero_genWeightSpace_eq_top_of_nilpotent [IsNilpotent L M] : genWeightSpace M (0 : (⊤ : LieSubalgebra R L) → R) = ⊤ := by simp_all theorem exists_genWeightSpace_le_ker_of_isNoetherian [IsNoetherian R M] (χ : L → R) (x : L) : ∃ k : ℕ, genWeightSpace M χ ≤ LinearMap.ker ((toEnd R L M x - algebraMap R _ (χ x)) ^ k) := by use (toEnd R L M x).maxGenEigenspaceIndex (χ x) intro m hm replace hm : m ∈ (toEnd R L M x).maxGenEigenspace (χ x) := genWeightSpace_le_genWeightSpaceOf M x χ hm rwa [Module.End.maxGenEigenspace_eq, Module.End.genEigenspace_nat] at hm variable (R) in theorem exists_genWeightSpace_zero_le_ker_of_isNoetherian [IsNoetherian R M] (x : L) : ∃ k : ℕ, genWeightSpace M (0 : L → R) ≤ LinearMap.ker (toEnd R L M x ^ k) := by simpa using exists_genWeightSpace_le_ker_of_isNoetherian M (0 : L → R) x lemma isNilpotent_toEnd_sub_algebraMap [IsNoetherian R M] (χ : L → R) (x : L) : _root_.IsNilpotent <| toEnd R L (genWeightSpace M χ) x - algebraMap R _ (χ x) := by have : toEnd R L (genWeightSpace M χ) x - algebraMap R _ (χ x) = (toEnd R L M x - algebraMap R _ (χ x)).restrict (fun m hm ↦ sub_mem (LieSubmodule.lie_mem _ hm) (Submodule.smul_mem _ _ hm)) := by rfl obtain ⟨k, hk⟩ := exists_genWeightSpace_le_ker_of_isNoetherian M χ x use k ext ⟨m, hm⟩ simp only [this, Module.End.pow_restrict _, LinearMap.zero_apply, ZeroMemClass.coe_zero, ZeroMemClass.coe_eq_zero] exact ZeroMemClass.coe_eq_zero.mp (hk hm) /-- A (nilpotent) Lie algebra acts nilpotently on the zero weight space of a Noetherian Lie module. -/ theorem isNilpotent_toEnd_genWeightSpace_zero [IsNoetherian R M] (x : L) : _root_.IsNilpotent <| toEnd R L (genWeightSpace M (0 : L → R)) x := by simpa using isNilpotent_toEnd_sub_algebraMap M (0 : L → R) x /-- By Engel's theorem, the zero weight space of a Noetherian Lie module is nilpotent. -/ instance [IsNoetherian R M] : IsNilpotent L (genWeightSpace M (0 : L → R)) := isNilpotent_iff_forall'.mpr <| isNilpotent_toEnd_genWeightSpace_zero M variable (R L) @[simp] lemma genWeightSpace_zero_normalizer_eq_self : (genWeightSpace M (0 : L → R)).normalizer = genWeightSpace M 0 := by refine le_antisymm ?_ (LieSubmodule.le_normalizer _) intro m hm rw [LieSubmodule.mem_normalizer] at hm simp only [mem_genWeightSpace, Pi.zero_apply, zero_smul, sub_zero] at hm ⊢ intro y obtain ⟨k, hk⟩ := hm y y use k + 1 simpa [pow_succ, Module.End.mul_eq_comp] lemma iSup_ucs_le_genWeightSpace_zero : ⨆ k, (⊥ : LieSubmodule R L M).ucs k ≤ genWeightSpace M (0 : L → R) := by simpa using LieSubmodule.ucs_le_of_normalizer_eq_self (genWeightSpace_zero_normalizer_eq_self R L M) /-- See also `LieModule.iInf_lowerCentralSeries_eq_posFittingComp`. -/ lemma iSup_ucs_eq_genWeightSpace_zero [IsNoetherian R M] : ⨆ k, (⊥ : LieSubmodule R L M).ucs k = genWeightSpace M (0 : L → R) := by obtain ⟨k, hk⟩ := (LieSubmodule.isNilpotent_iff_exists_self_le_ucs <| genWeightSpace M (0 : L → R)).mp inferInstance refine le_antisymm (iSup_ucs_le_genWeightSpace_zero R L M) (le_trans hk ?_) exact le_iSup (fun k ↦ (⊥ : LieSubmodule R L M).ucs k) k variable {L} /-- If `M` is a representation of a nilpotent Lie algebra `L`, and `x : L`, then `posFittingCompOf R M x` is the infimum of the decreasing system `range φₓ ⊇ range φₓ² ⊇ range φₓ³ ⊇ ⋯` where `φₓ : End R M := toEnd R L M x`. We call this the "positive Fitting component" because with appropriate assumptions (e.g., `R` is a field and `M` is finite-dimensional) `φₓ` induces the so-called Fitting decomposition: `M = M₀ ⊕ M₁` where `M₀ = genWeightSpaceOf M 0 x` and `M₁ = posFittingCompOf R M x`. It is a Lie submodule because `L` is nilpotent. -/ def posFittingCompOf (x : L) : LieSubmodule R L M := { toSubmodule := ⨅ k, LinearMap.range (toEnd R L M x ^ k) lie_mem := by set φ := toEnd R L M x intro y m hm simp only [AddSubsemigroup.mem_carrier, AddSubmonoid.mem_toSubsemigroup, Submodule.mem_toAddSubmonoid, Submodule.mem_iInf, LinearMap.mem_range] at hm ⊢ intro k obtain ⟨N, hN⟩ := LieAlgebra.nilpotent_ad_of_nilpotent_algebra R L obtain ⟨m, rfl⟩ := hm (N + k) let f₁ : Module.End R (L ⊗[R] M) := (LieAlgebra.ad R L x).rTensor M let f₂ : Module.End R (L ⊗[R] M) := φ.lTensor L replace hN : f₁ ^ N = 0 := by ext; simp [f₁, hN] have h₁ : Commute f₁ f₂ := by ext; simp [f₁, f₂] have h₂ : φ ∘ₗ toModuleHom R L M = toModuleHom R L M ∘ₗ (f₁ + f₂) := by ext; simp [φ, f₁, f₂] obtain ⟨q, hq⟩ := h₁.add_pow_dvd_pow_of_pow_eq_zero_right (N + k).le_succ hN use toModuleHom R L M (q (y ⊗ₜ m)) change (φ ^ k).comp ((toModuleHom R L M : L ⊗[R] M →ₗ[R] M)) _ = _ simp [φ, f₁, f₂, Module.End.commute_pow_left_of_commute h₂, LinearMap.comp_apply (g := (f₁ + f₂) ^ k), ← LinearMap.comp_apply (g := q), ← Module.End.mul_eq_comp, ← hq] } variable {M} in lemma mem_posFittingCompOf (x : L) (m : M) : m ∈ posFittingCompOf R M x ↔ ∀ (k : ℕ), ∃ n, (toEnd R L M x ^ k) n = m := by simp [posFittingCompOf] @[simp] lemma posFittingCompOf_le_lowerCentralSeries (x : L) (k : ℕ) : posFittingCompOf R M x ≤ lowerCentralSeries R L M k := by suffices ∀ m l, (toEnd R L M x ^ l) m ∈ lowerCentralSeries R L M l by intro m hm obtain ⟨n, rfl⟩ := (mem_posFittingCompOf R x m).mp hm k exact this n k intro m l induction l with | zero => simp | succ l ih => simp only [lowerCentralSeries_succ, pow_succ', Module.End.mul_apply] exact LieSubmodule.lie_mem_lie (LieSubmodule.mem_top x) ih @[simp] lemma posFittingCompOf_eq_bot_of_isNilpotent [IsNilpotent L M] (x : L) : posFittingCompOf R M x = ⊥ := by simp_rw [eq_bot_iff, ← iInf_lowerCentralSeries_eq_bot_of_isNilpotent, le_iInf_iff, posFittingCompOf_le_lowerCentralSeries, forall_const] variable (L) /-- If `M` is a representation of a nilpotent Lie algebra `L` with coefficients in `R`, then `posFittingComp R L M` is the span of the positive Fitting components of the action of `x` on `M`, as `x` ranges over `L`. It is a Lie submodule because `L` is nilpotent. -/ def posFittingComp : LieSubmodule R L M := ⨆ x, posFittingCompOf R M x lemma mem_posFittingComp (m : M) : m ∈ posFittingComp R L M ↔ m ∈ ⨆ (x : L), posFittingCompOf R M x := by rfl lemma posFittingCompOf_le_posFittingComp (x : L) : posFittingCompOf R M x ≤ posFittingComp R L M := by rw [posFittingComp]; exact le_iSup (posFittingCompOf R M) x lemma posFittingComp_le_iInf_lowerCentralSeries : posFittingComp R L M ≤ ⨅ k, lowerCentralSeries R L M k := by simp [posFittingComp] /-- See also `LieModule.iSup_ucs_eq_genWeightSpace_zero`. -/ @[simp] lemma iInf_lowerCentralSeries_eq_posFittingComp [IsNoetherian R M] [IsArtinian R M] : ⨅ k, lowerCentralSeries R L M k = posFittingComp R L M := by refine le_antisymm ?_ (posFittingComp_le_iInf_lowerCentralSeries R L M) apply iInf_lcs_le_of_isNilpotent_quot rw [LieModule.isNilpotent_iff_forall' (R := R)] intro x obtain ⟨k, hk⟩ := Filter.eventually_atTop.mp (toEnd R L M x).eventually_iInf_range_pow_eq use k ext ⟨m⟩ set F := posFittingComp R L M replace hk : (toEnd R L M x ^ k) m ∈ F := by apply posFittingCompOf_le_posFittingComp R L M x simp_rw [← LieSubmodule.mem_toSubmodule, posFittingCompOf, hk k (le_refl k)] apply LinearMap.mem_range_self suffices (toEnd R L (M ⧸ F) x ^ k) (LieSubmodule.Quotient.mk (N := F) m) = LieSubmodule.Quotient.mk (N := F) ((toEnd R L M x ^ k) m) by simpa [Submodule.Quotient.quot_mk_eq_mk, this] have := LinearMap.congr_fun (Module.End.commute_pow_left_of_commute (LieSubmodule.Quotient.toEnd_comp_mk' F x) k) m simpa using this @[simp] lemma posFittingComp_eq_bot_of_isNilpotent [IsNilpotent L M] : posFittingComp R L M = ⊥ := by simp [posFittingComp] section map_comap variable {R L M} variable {M₂ : Type*} [AddCommGroup M₂] [Module R M₂] [LieRingModule L M₂] [LieModule R L M₂] {χ : L → R} (f : M →ₗ⁅R,L⁆ M₂) lemma map_posFittingComp_le : (posFittingComp R L M).map f ≤ posFittingComp R L M₂ := by rw [posFittingComp, posFittingComp, LieSubmodule.map_iSup] refine iSup_mono fun y ↦ LieSubmodule.map_le_iff_le_comap.mpr fun m hm ↦ ?_ simp only [mem_posFittingCompOf] at hm simp only [LieSubmodule.mem_comap, mem_posFittingCompOf] intro k obtain ⟨n, hn⟩ := hm k use f n rw [LieModule.toEnd_pow_apply_map, hn] lemma map_genWeightSpace_le : (genWeightSpace M χ).map f ≤ genWeightSpace M₂ χ := by rw [LieSubmodule.map_le_iff_le_comap] intro m hm simp only [LieSubmodule.mem_comap, mem_genWeightSpace] intro x have : (toEnd R L M₂ x - χ x • ↑1) ∘ₗ f = f ∘ₗ (toEnd R L M x - χ x • ↑1) := by ext; simp obtain ⟨k, h⟩ := (mem_genWeightSpace _ _ _).mp hm x refine ⟨k, ?_⟩ simpa [h] using LinearMap.congr_fun (Module.End.commute_pow_left_of_commute this k) m variable {f} lemma comap_genWeightSpace_eq_of_injective (hf : Injective f) : (genWeightSpace M₂ χ).comap f = genWeightSpace M χ := by refine le_antisymm (fun m hm ↦ ?_) ?_ · simp only [LieSubmodule.mem_comap, mem_genWeightSpace] at hm simp only [mem_genWeightSpace] intro x have h : (toEnd R L M₂ x - χ x • ↑1) ∘ₗ f = f ∘ₗ (toEnd R L M x - χ x • ↑1) := by ext; simp obtain ⟨k, hk⟩ := hm x use k suffices f (((toEnd R L M x - χ x • ↑1) ^ k) m) = 0 by rw [← map_zero f] at this; exact hf this simpa [hk] using (LinearMap.congr_fun (Module.End.commute_pow_left_of_commute h k) m).symm · rw [← LieSubmodule.map_le_iff_le_comap] exact map_genWeightSpace_le f lemma map_genWeightSpace_eq_of_injective (hf : Injective f) : (genWeightSpace M χ).map f = genWeightSpace M₂ χ ⊓ f.range := by refine le_antisymm (le_inf_iff.mpr ⟨map_genWeightSpace_le f, LieSubmodule.map_le_range f⟩) ?_ rintro - ⟨hm, ⟨m, rfl⟩⟩ simp only [← comap_genWeightSpace_eq_of_injective hf, LieSubmodule.mem_map, LieSubmodule.mem_comap] exact ⟨m, hm, rfl⟩ lemma map_genWeightSpace_eq (e : M ≃ₗ⁅R,L⁆ M₂) : (genWeightSpace M χ).map e = genWeightSpace M₂ χ := by simp [map_genWeightSpace_eq_of_injective e.injective] lemma map_posFittingComp_eq (e : M ≃ₗ⁅R,L⁆ M₂) : (posFittingComp R L M).map e = posFittingComp R L M₂ := by refine le_antisymm (map_posFittingComp_le _) ?_ suffices posFittingComp R L M₂ = ((posFittingComp R L M₂).map (e.symm : M₂ →ₗ⁅R,L⁆ M)).map e by rw [this] exact LieSubmodule.map_mono (map_posFittingComp_le _) rw [← LieSubmodule.map_comp] convert LieSubmodule.map_id ext simp lemma posFittingComp_map_incl_sup_of_codisjoint [IsNoetherian R M] [IsArtinian R M] {N₁ N₂ : LieSubmodule R L M} (h : Codisjoint N₁ N₂) : (posFittingComp R L N₁).map N₁.incl ⊔ (posFittingComp R L N₂).map N₂.incl = posFittingComp R L M := by obtain ⟨l, hl⟩ := Filter.eventually_atTop.mp <| (eventually_iInf_lowerCentralSeries_eq R L N₁).and <| (eventually_iInf_lowerCentralSeries_eq R L N₂).and (eventually_iInf_lowerCentralSeries_eq R L M) obtain ⟨hl₁, hl₂, hl₃⟩ := hl l (le_refl _) simp_rw [← iInf_lowerCentralSeries_eq_posFittingComp, hl₁, hl₂, hl₃, LieSubmodule.lowerCentralSeries_map_eq_lcs, ← LieSubmodule.lcs_sup, lowerCentralSeries, h.eq_top] lemma genWeightSpace_genWeightSpaceOf_map_incl (x : L) (χ : L → R) : (genWeightSpace (genWeightSpaceOf M (χ x) x) χ).map (genWeightSpaceOf M (χ x) x).incl = genWeightSpace M χ := by simpa [map_genWeightSpace_eq_of_injective (genWeightSpaceOf M (χ x) x).injective_incl] using genWeightSpace_le_genWeightSpaceOf M x χ end map_comap section fitting_decomposition variable [IsNoetherian R M] [IsArtinian R M] lemma isCompl_genWeightSpaceOf_zero_posFittingCompOf (x : L) : IsCompl (genWeightSpaceOf M 0 x) (posFittingCompOf R M x) := by simpa only [isCompl_iff, codisjoint_iff, disjoint_iff, ← LieSubmodule.toSubmodule_inj, LieSubmodule.sup_toSubmodule, LieSubmodule.inf_toSubmodule, LieSubmodule.top_toSubmodule, LieSubmodule.bot_toSubmodule, coe_genWeightSpaceOf_zero] using (toEnd R L M x).isCompl_iSup_ker_pow_iInf_range_pow /-- This lemma exists only to simplify the proof of `LieModule.isCompl_genWeightSpace_zero_posFittingComp`. -/ private lemma isCompl_genWeightSpace_zero_posFittingComp_aux (h : ∀ N < (⊤ : LieSubmodule R L M), IsCompl (genWeightSpace N 0) (posFittingComp R L N)) : IsCompl (genWeightSpace M 0) (posFittingComp R L M) := by set M₀ := genWeightSpace M (0 : L → R) set M₁ := posFittingComp R L M rcases forall_or_exists_not (fun (x : L) ↦ genWeightSpaceOf M (0 : R) x = ⊤) with h | ⟨x, hx : genWeightSpaceOf M (0 : R) x ≠ ⊤⟩ · suffices IsNilpotent L M by simp [M₀, M₁, isCompl_top_bot] replace h : M₀ = ⊤ := by simpa [M₀, genWeightSpace] rw [← LieModule.isNilpotent_of_top_iff' (R := R), ← h] infer_instance · set M₀ₓ := genWeightSpaceOf M (0 : R) x set M₁ₓ := posFittingCompOf R M x set M₀ₓ₀ := genWeightSpace M₀ₓ (0 : L → R) set M₀ₓ₁ := posFittingComp R L M₀ₓ have h₁ : IsCompl M₀ₓ M₁ₓ := isCompl_genWeightSpaceOf_zero_posFittingCompOf R L M x have h₂ : IsCompl M₀ₓ₀ M₀ₓ₁ := h M₀ₓ hx.lt_top have h₃ : M₀ₓ₀.map M₀ₓ.incl = M₀ := by rw [map_genWeightSpace_eq_of_injective M₀ₓ.injective_incl, inf_eq_left, LieSubmodule.range_incl] exact iInf_le _ x have h₄ : M₀ₓ₁.map M₀ₓ.incl ⊔ M₁ₓ = M₁ := by apply le_antisymm <| sup_le_iff.mpr ⟨map_posFittingComp_le _, posFittingCompOf_le_posFittingComp R L M x⟩ rw [← posFittingComp_map_incl_sup_of_codisjoint h₁.codisjoint] exact sup_le_sup_left LieSubmodule.map_incl_le _ rw [← h₃, ← h₄] apply Disjoint.isCompl_sup_right_of_isCompl_sup_left · rw [disjoint_iff, ← LieSubmodule.map_inf M₀ₓ.injective_incl, h₂.inf_eq_bot, LieSubmodule.map_bot] · rwa [← LieSubmodule.map_sup, h₂.sup_eq_top, LieModuleHom.map_top, LieSubmodule.range_incl] /-- This is the Fitting decomposition of the Lie module `M`. -/ lemma isCompl_genWeightSpace_zero_posFittingComp : IsCompl (genWeightSpace M 0) (posFittingComp R L M) := by let P : LieSubmodule R L M → Prop := fun N ↦ IsCompl (genWeightSpace N 0) (posFittingComp R L N) suffices P ⊤ by let e := LieModuleEquiv.ofTop R L M rw [← map_genWeightSpace_eq e, ← map_posFittingComp_eq e] exact (LieSubmodule.orderIsoMapComap e).isCompl_iff.mp this refine (LieSubmodule.wellFoundedLT_of_isArtinian R L M).induction (C := P) _ fun N hN ↦ ?_ refine isCompl_genWeightSpace_zero_posFittingComp_aux R L N fun N' hN' ↦ ?_ suffices IsCompl (genWeightSpace (N'.map N.incl) 0) (posFittingComp R L (N'.map N.incl)) by let e := LieSubmodule.equivMapOfInjective N' N.injective_incl rw [← map_genWeightSpace_eq e, ← map_posFittingComp_eq e] at this exact (LieSubmodule.orderIsoMapComap e).isCompl_iff.mpr this exact hN _ (LieSubmodule.map_incl_lt_iff_lt_top.mpr hN') end fitting_decomposition lemma disjoint_genWeightSpaceOf [NoZeroSMulDivisors R M] {x : L} {φ₁ φ₂ : R} (h : φ₁ ≠ φ₂) : Disjoint (genWeightSpaceOf M φ₁ x) (genWeightSpaceOf M φ₂ x) := by rw [← LieSubmodule.disjoint_toSubmodule] dsimp [genWeightSpaceOf] exact Module.End.disjoint_genEigenspace _ h _ _ lemma disjoint_genWeightSpace [NoZeroSMulDivisors R M] {χ₁ χ₂ : L → R} (h : χ₁ ≠ χ₂) : Disjoint (genWeightSpace M χ₁) (genWeightSpace M χ₂) := by obtain ⟨x, hx⟩ : ∃ x, χ₁ x ≠ χ₂ x := Function.ne_iff.mp h exact (disjoint_genWeightSpaceOf R L M hx).mono (genWeightSpace_le_genWeightSpaceOf M x χ₁) (genWeightSpace_le_genWeightSpaceOf M x χ₂) lemma injOn_genWeightSpace [NoZeroSMulDivisors R M] : InjOn (fun (χ : L → R) ↦ genWeightSpace M χ) {χ | genWeightSpace M χ ≠ ⊥} := by rintro χ₁ _ χ₂ hχ₂ (hχ₁₂ : genWeightSpace M χ₁ = genWeightSpace M χ₂) contrapose! hχ₂ simpa [hχ₁₂] using disjoint_genWeightSpace R L M hχ₂ /-- Lie module weight spaces are independent. See also `LieModule.iSupIndep_genWeightSpace'`. -/ lemma iSupIndep_genWeightSpace [NoZeroSMulDivisors R M] : iSupIndep fun χ : L → R ↦ genWeightSpace M χ := by simp only [← LieSubmodule.iSupIndep_toSubmodule, genWeightSpace, LieSubmodule.iInf_toSubmodule] exact Module.End.independent_iInf_maxGenEigenspace_of_forall_mapsTo (toEnd R L M) (fun x y φ z ↦ (genWeightSpaceOf M φ y).lie_mem) lemma iSupIndep_genWeightSpace' [NoZeroSMulDivisors R M] : iSupIndep fun χ : Weight R L M ↦ genWeightSpace M χ := (iSupIndep_genWeightSpace R L M).comp <| Subtype.val_injective.comp (Weight.equivSetOf R L M).injective lemma iSupIndep_genWeightSpaceOf [NoZeroSMulDivisors R M] (x : L) : iSupIndep fun (χ : R) ↦ genWeightSpaceOf M χ x := by rw [← LieSubmodule.iSupIndep_toSubmodule] dsimp [genWeightSpaceOf] exact (toEnd R L M x).independent_genEigenspace _ lemma finite_genWeightSpaceOf_ne_bot [NoZeroSMulDivisors R M] [IsNoetherian R M] (x : L) : {χ : R | genWeightSpaceOf M χ x ≠ ⊥}.Finite := WellFoundedGT.finite_ne_bot_of_iSupIndep (iSupIndep_genWeightSpaceOf R L M x) lemma finite_genWeightSpace_ne_bot [NoZeroSMulDivisors R M] [IsNoetherian R M] : {χ : L → R | genWeightSpace M χ ≠ ⊥}.Finite := WellFoundedGT.finite_ne_bot_of_iSupIndep (iSupIndep_genWeightSpace R L M) instance Weight.instFinite [NoZeroSMulDivisors R M] [IsNoetherian R M] : Finite (Weight R L M) := by have : Finite {χ : L → R | genWeightSpace M χ ≠ ⊥} := finite_genWeightSpace_ne_bot R L M exact Finite.of_injective (equivSetOf R L M) (equivSetOf R L M).injective noncomputable instance Weight.instFintype [NoZeroSMulDivisors R M] [IsNoetherian R M] : Fintype (Weight R L M) := Fintype.ofFinite _ /-- A Lie module `M` of a Lie algebra `L` is triangularizable if the endomorphism of `M` defined by any `x : L` is triangularizable. -/ class IsTriangularizable : Prop where maxGenEigenspace_eq_top : ∀ x, ⨆ φ, (toEnd R L M x).maxGenEigenspace φ = ⊤ instance (L' : LieSubalgebra R L) [IsTriangularizable R L M] : IsTriangularizable R L' M where maxGenEigenspace_eq_top x := IsTriangularizable.maxGenEigenspace_eq_top (x : L) instance (I : LieIdeal R L) [IsTriangularizable R L M] : IsTriangularizable R I M where maxGenEigenspace_eq_top x := IsTriangularizable.maxGenEigenspace_eq_top (x : L) instance [IsTriangularizable R L M] : IsTriangularizable R (LieModule.toEnd R L M).range M where maxGenEigenspace_eq_top := by rintro ⟨-, x, rfl⟩ exact IsTriangularizable.maxGenEigenspace_eq_top x @[simp] lemma iSup_genWeightSpaceOf_eq_top [IsTriangularizable R L M] (x : L) : ⨆ (φ : R), genWeightSpaceOf M φ x = ⊤ := by rw [← LieSubmodule.toSubmodule_inj, LieSubmodule.iSup_toSubmodule, LieSubmodule.top_toSubmodule] dsimp [genWeightSpaceOf] exact IsTriangularizable.maxGenEigenspace_eq_top x open LinearMap Module in @[simp] lemma trace_toEnd_genWeightSpace [IsDomain R] [IsPrincipalIdealRing R] [Module.Free R M] [Module.Finite R M] (χ : L → R) (x : L) : trace R _ (toEnd R L (genWeightSpace M χ) x) = finrank R (genWeightSpace M χ) • χ x := by suffices _root_.IsNilpotent ((toEnd R L (genWeightSpace M χ) x) - χ x • LinearMap.id) by replace this := (isNilpotent_trace_of_isNilpotent this).eq_zero rwa [map_sub, map_smul, trace_id, sub_eq_zero, smul_eq_mul, mul_comm, ← nsmul_eq_mul] at this rw [← Module.algebraMap_end_eq_smul_id] exact isNilpotent_toEnd_sub_algebraMap M χ x section field open Module variable (K) variable [Field K] [LieAlgebra K L] [Module K M] [LieModule K L M] [FiniteDimensional K M] instance instIsTriangularizableOfIsAlgClosed [IsAlgClosed K] : IsTriangularizable K L M := ⟨fun _ ↦ Module.End.iSup_maxGenEigenspace_eq_top _⟩ instance (N : LieSubmodule K L M) [IsTriangularizable K L M] : IsTriangularizable K L N := by refine ⟨fun y ↦ ?_⟩ rw [← N.toEnd_restrict_eq_toEnd y] exact Module.End.genEigenspace_restrict_eq_top _ (IsTriangularizable.maxGenEigenspace_eq_top y) /-- For a triangularizable Lie module in finite dimensions, the weight spaces span the entire space. See also `LieModule.iSup_genWeightSpace_eq_top'`. -/ lemma iSup_genWeightSpace_eq_top [IsTriangularizable K L M] : ⨆ χ : L → K, genWeightSpace M χ = ⊤ := by simp only [← LieSubmodule.toSubmodule_inj, LieSubmodule.iSup_toSubmodule, LieSubmodule.iInf_toSubmodule, LieSubmodule.top_toSubmodule, genWeightSpace] refine Module.End.iSup_iInf_maxGenEigenspace_eq_top_of_forall_mapsTo (toEnd K L M) (fun x y φ z ↦ (genWeightSpaceOf M φ y).lie_mem) ?_ apply IsTriangularizable.maxGenEigenspace_eq_top lemma iSup_genWeightSpace_eq_top' [IsTriangularizable K L M] : ⨆ χ : Weight K L M, genWeightSpace M χ = ⊤ := by have := iSup_genWeightSpace_eq_top K L M erw [← iSup_ne_bot_subtype, ← (Weight.equivSetOf K L M).iSup_comp] at this exact this end field end LieModule
.lake/packages/mathlib/Mathlib/Algebra/Lie/Weights/RootSystem.lean
import Mathlib.Algebra.Algebra.Rat import Mathlib.Algebra.Lie.Weights.Killing import Mathlib.Algebra.Module.Torsion.Free import Mathlib.LinearAlgebra.RootSystem.Basic import Mathlib.LinearAlgebra.RootSystem.Finite.CanonicalBilinear import Mathlib.LinearAlgebra.RootSystem.Reduced /-! # The root system associated with a Lie algebra We show that the roots of a finite-dimensional splitting semisimple Lie algebra over a field of characteristic 0 form a root system. We achieve this by studying root chains. ## Main results - `LieAlgebra.IsKilling.apply_coroot_eq_cast`: If `β - qα ... β ... β + rα` is the `α`-chain through `β`, then `β (coroot α) = q - r`. In particular, it is an integer. - `LieAlgebra.IsKilling.rootSpace_zsmul_add_ne_bot_iff`: The `α`-chain through `β` (`β - qα ... β ... β + rα`) are the only roots of the form `β + kα`. - `LieAlgebra.IsKilling.eq_neg_or_eq_of_eq_smul`: `±α` are the only `K`-multiples of a root `α` that are also (non-zero) roots. - `LieAlgebra.IsKilling.rootSystem`: The root system of a finite-dimensional Lie algebra with non-degenerate Killing form over a field of characteristic zero, relative to a splitting Cartan subalgebra. -/ noncomputable section namespace LieAlgebra.IsKilling open LieModule Module variable {K L : Type*} [Field K] [CharZero K] [LieRing L] [LieAlgebra K L] [IsKilling K L] [FiniteDimensional K L] {H : LieSubalgebra K L} [H.IsCartanSubalgebra] [IsTriangularizable K H L] variable (α β : Weight K H L) private lemma chainLength_aux (hα : α.IsNonZero) {x} (hx : x ∈ rootSpace H (chainTop α β)) : ∃ n : ℕ, n • x = ⁅coroot α, x⁆ := by by_cases hx' : x = 0 · exact ⟨0, by simp [hx']⟩ obtain ⟨h, e, f, isSl2, he, hf⟩ := exists_isSl2Triple_of_weight_isNonZero hα obtain rfl := isSl2.h_eq_coroot hα he hf have : isSl2.HasPrimitiveVectorWith x (chainTop α β (coroot α)) := have := lie_mem_genWeightSpace_of_mem_genWeightSpace he hx ⟨hx', by rw [← lie_eq_smul_of_mem_rootSpace hx]; rfl, by rwa [genWeightSpace_add_chainTop α β hα] at this⟩ obtain ⟨μ, hμ⟩ := this.exists_nat exact ⟨μ, by rw [← Nat.cast_smul_eq_nsmul K, ← hμ, lie_eq_smul_of_mem_rootSpace hx]⟩ /-- The length of the `α`-chain through `β`. See `chainBotCoeff_add_chainTopCoeff`. -/ def chainLength (α β : Weight K H L) : ℕ := letI := Classical.propDecidable if hα : α.IsZero then 0 else (chainLength_aux α β hα (chainTop α β).exists_ne_zero.choose_spec.1).choose lemma chainLength_of_isZero (hα : α.IsZero) : chainLength α β = 0 := dif_pos hα lemma chainLength_nsmul {x} (hx : x ∈ rootSpace H (chainTop α β)) : chainLength α β • x = ⁅coroot α, x⁆ := by by_cases hα : α.IsZero · rw [coroot_eq_zero_iff.mpr hα, chainLength_of_isZero _ _ hα, zero_smul, zero_lie] let x' := (chainTop α β).exists_ne_zero.choose have h : x' ∈ rootSpace H (chainTop α β) ∧ x' ≠ 0 := (chainTop α β).exists_ne_zero.choose_spec obtain ⟨k, rfl⟩ : ∃ k : K, k • x' = x := by simpa using (finrank_eq_one_iff_of_nonzero' ⟨x', h.1⟩ (by simpa using h.2)).mp (finrank_rootSpace_eq_one _ (chainTop_isNonZero α β hα)) ⟨_, hx⟩ rw [lie_smul, smul_comm, chainLength, dif_neg hα, (chainLength_aux α β hα h.1).choose_spec] lemma chainLength_smul {x} (hx : x ∈ rootSpace H (chainTop α β)) : (chainLength α β : K) • x = ⁅coroot α, x⁆ := by rw [Nat.cast_smul_eq_nsmul, chainLength_nsmul _ _ hx] lemma apply_coroot_eq_cast' : β (coroot α) = ↑(chainLength α β - 2 * chainTopCoeff α β : ℤ) := by by_cases hα : α.IsZero · rw [coroot_eq_zero_iff.mpr hα, chainLength, dif_pos hα, hα.eq, chainTopCoeff_zero, map_zero, CharP.cast_eq_zero, mul_zero, sub_self, Int.cast_zero] obtain ⟨x, hx, x_ne0⟩ := (chainTop α β).exists_ne_zero have := chainLength_smul _ _ hx rw [lie_eq_smul_of_mem_rootSpace hx, ← sub_eq_zero, ← sub_smul, smul_eq_zero_iff_left x_ne0, sub_eq_zero, coe_chainTop', nsmul_eq_mul, Pi.natCast_def, Pi.add_apply, Pi.mul_apply, root_apply_coroot hα] at this simp only [Int.cast_sub, Int.cast_natCast, Int.cast_mul, Int.cast_ofNat, eq_sub_iff_add_eq', this, mul_comm (2 : K)] lemma rootSpace_neg_nsmul_add_chainTop_of_le {n : ℕ} (hn : n ≤ chainLength α β) : rootSpace H (- (n • α) + chainTop α β) ≠ ⊥ := by by_cases hα : α.IsZero · simpa only [hα.eq, smul_zero, neg_zero, chainTop_zero, zero_add, ne_eq] using β.2 obtain ⟨x, hx, x_ne0⟩ := (chainTop α β).exists_ne_zero obtain ⟨h, e, f, isSl2, he, hf⟩ := exists_isSl2Triple_of_weight_isNonZero hα obtain rfl := isSl2.h_eq_coroot hα he hf have prim : isSl2.HasPrimitiveVectorWith x (chainLength α β : K) := have := lie_mem_genWeightSpace_of_mem_genWeightSpace he hx ⟨x_ne0, (chainLength_smul _ _ hx).symm, by rwa [genWeightSpace_add_chainTop _ _ hα] at this⟩ simp only [← smul_neg, ne_eq, LieSubmodule.eq_bot_iff, not_forall] exact ⟨_, toEnd_pow_apply_mem hf hx n, prim.pow_toEnd_f_ne_zero_of_eq_nat rfl hn⟩ lemma rootSpace_neg_nsmul_add_chainTop_of_lt (hα : α.IsNonZero) {n : ℕ} (hn : chainLength α β < n) : rootSpace H (- (n • α) + chainTop α β) = ⊥ := by by_contra e let W : Weight K H L := ⟨_, e⟩ have hW : (W : H → K) = - (n • α) + chainTop α β := rfl have H₁ : 1 + n + chainTopCoeff (-α) W ≤ chainLength (-α) W := by have := apply_coroot_eq_cast' (-α) W simp only [coroot_neg, map_neg, hW, nsmul_eq_mul, Pi.natCast_def, coe_chainTop, zsmul_eq_mul, Int.cast_natCast, Pi.add_apply, Pi.neg_apply, Pi.mul_apply, root_apply_coroot hα, mul_two, apply_coroot_eq_cast' α β, Int.cast_sub, Int.cast_mul, Int.cast_ofNat, mul_comm (2 : K), add_sub_cancel, add_sub, Nat.cast_inj, eq_sub_iff_add_eq, ← Nat.cast_add, ← sub_eq_neg_add, sub_eq_iff_eq_add] at this omega have H₂ : ((1 + n + chainTopCoeff (-α) W) • α + chainTop (-α) W : H → K) = (chainTopCoeff α β + 1) • α + β := by simp only [Weight.coe_neg, ← Nat.cast_smul_eq_nsmul ℤ, Nat.cast_add, Nat.cast_one, coe_chainTop, smul_neg, ← neg_smul, hW, ← add_assoc, ← add_smul, ← sub_eq_add_neg] congr 2 ring have := rootSpace_neg_nsmul_add_chainTop_of_le (-α) W H₁ rw [Weight.coe_neg, ← smul_neg, neg_neg, ← Weight.coe_neg, H₂] at this exact this (genWeightSpace_chainTopCoeff_add_one_nsmul_add α β hα) lemma chainTopCoeff_le_chainLength : chainTopCoeff α β ≤ chainLength α β := by by_cases hα : α.IsZero · simp only [hα.eq, chainTopCoeff_zero, zero_le] rw [← not_lt, ← Nat.succ_le] intro e apply genWeightSpace_nsmul_add_ne_bot_of_le α β (Nat.sub_le (chainTopCoeff α β) (chainLength α β).succ) rw [← Nat.cast_smul_eq_nsmul ℤ, Nat.cast_sub e, sub_smul, sub_eq_neg_add, add_assoc, ← coe_chainTop, Nat.cast_smul_eq_nsmul] exact rootSpace_neg_nsmul_add_chainTop_of_lt α β hα (Nat.lt_succ_self _) lemma chainBotCoeff_add_chainTopCoeff : chainBotCoeff α β + chainTopCoeff α β = chainLength α β := by by_cases hα : α.IsZero · rw [hα.eq, chainTopCoeff_zero, chainBotCoeff_zero, zero_add, chainLength_of_isZero α β hα] apply le_antisymm · rw [← Nat.le_sub_iff_add_le (chainTopCoeff_le_chainLength α β), ← not_lt, ← Nat.succ_le, chainBotCoeff, ← Weight.coe_neg] intro e apply genWeightSpace_nsmul_add_ne_bot_of_le _ _ e rw [← Nat.cast_smul_eq_nsmul ℤ, Nat.cast_succ, Nat.cast_sub (chainTopCoeff_le_chainLength α β), LieModule.Weight.coe_neg, smul_neg, ← neg_smul, neg_add_rev, neg_sub, sub_eq_neg_add, ← add_assoc, ← neg_add_rev, add_smul, add_assoc, ← coe_chainTop, neg_smul, ← @Nat.cast_one ℤ, ← Nat.cast_add, Nat.cast_smul_eq_nsmul] exact rootSpace_neg_nsmul_add_chainTop_of_lt α β hα (Nat.lt_succ_self _) · rw [← not_lt] intro e apply rootSpace_neg_nsmul_add_chainTop_of_le α β e rw [← Nat.succ_add, ← Nat.cast_smul_eq_nsmul ℤ, ← neg_smul, coe_chainTop, ← add_assoc, ← add_smul, Nat.cast_add, neg_add, add_assoc, neg_add_cancel, add_zero, neg_smul, ← smul_neg, Nat.cast_smul_eq_nsmul] exact genWeightSpace_chainTopCoeff_add_one_nsmul_add (-α) β (Weight.IsNonZero.neg hα) lemma chainTopCoeff_add_chainBotCoeff : chainTopCoeff α β + chainBotCoeff α β = chainLength α β := by rw [add_comm, chainBotCoeff_add_chainTopCoeff] lemma chainBotCoeff_le_chainLength : chainBotCoeff α β ≤ chainLength α β := (Nat.le_add_left _ _).trans_eq (chainTopCoeff_add_chainBotCoeff α β) @[simp] lemma chainLength_neg : chainLength (-α) β = chainLength α β := by rw [← chainBotCoeff_add_chainTopCoeff, ← chainBotCoeff_add_chainTopCoeff, add_comm, Weight.coe_neg, chainTopCoeff_neg, chainBotCoeff_neg] @[simp] lemma chainLength_zero [Nontrivial L] : chainLength 0 β = 0 := by simp [← chainBotCoeff_add_chainTopCoeff] /-- If `β - qα ... β ... β + rα` is the `α`-chain through `β`, then `β (coroot α) = q - r`. In particular, it is an integer. -/ lemma apply_coroot_eq_cast : β (coroot α) = (chainBotCoeff α β - chainTopCoeff α β : ℤ) := by rw [apply_coroot_eq_cast', ← chainTopCoeff_add_chainBotCoeff]; congr 1; cutsat lemma le_chainBotCoeff_of_rootSpace_ne_top (hα : α.IsNonZero) (n : ℤ) (hn : rootSpace H (-n • α + β) ≠ ⊥) : n ≤ chainBotCoeff α β := by contrapose! hn lift n to ℕ using (Nat.cast_nonneg _).trans hn.le rw [Nat.cast_lt, ← @Nat.add_lt_add_iff_right (chainTopCoeff α β), chainBotCoeff_add_chainTopCoeff] at hn have := rootSpace_neg_nsmul_add_chainTop_of_lt α β hα hn rwa [← Nat.cast_smul_eq_nsmul ℤ, ← neg_smul, coe_chainTop, ← add_assoc, ← add_smul, Nat.cast_add, neg_add, add_assoc, neg_add_cancel, add_zero] at this /-- Members of the `α`-chain through `β` are the only roots of the form `β - kα`. -/ lemma rootSpace_zsmul_add_ne_bot_iff (hα : α.IsNonZero) (n : ℤ) : rootSpace H (n • α + β) ≠ ⊥ ↔ n ≤ chainTopCoeff α β ∧ -n ≤ chainBotCoeff α β := by constructor · refine (fun hn ↦ ⟨?_, le_chainBotCoeff_of_rootSpace_ne_top α β hα _ (by rwa [neg_neg])⟩) rw [← chainBotCoeff_neg, ← Weight.coe_neg] apply le_chainBotCoeff_of_rootSpace_ne_top _ _ hα.neg rwa [neg_smul, Weight.coe_neg, smul_neg, neg_neg] · rintro ⟨h₁, h₂⟩ set k := chainTopCoeff α β - n with hk; clear_value k lift k to ℕ using (by rw [hk, le_sub_iff_add_le, zero_add]; exact h₁) rw [eq_sub_iff_add_eq, ← eq_sub_iff_add_eq'] at hk subst hk simp only [neg_sub, tsub_le_iff_right, ← Nat.cast_add, Nat.cast_le, chainBotCoeff_add_chainTopCoeff] at h₂ have := rootSpace_neg_nsmul_add_chainTop_of_le α β h₂ rwa [coe_chainTop, ← Nat.cast_smul_eq_nsmul ℤ, ← neg_smul, ← add_assoc, ← add_smul, ← sub_eq_neg_add] at this lemma rootSpace_zsmul_add_ne_bot_iff_mem (hα : α.IsNonZero) (n : ℤ) : rootSpace H (n • α + β) ≠ ⊥ ↔ n ∈ Finset.Icc (-chainBotCoeff α β : ℤ) (chainTopCoeff α β) := by rw [rootSpace_zsmul_add_ne_bot_iff α β hα n, Finset.mem_Icc, and_comm, neg_le] lemma chainTopCoeff_of_eq_zsmul_add (hα : α.IsNonZero) (β' : Weight K H L) (n : ℤ) (hβ' : (β' : H → K) = n • α + β) : chainTopCoeff α β' = chainTopCoeff α β - n := by apply le_antisymm · refine le_sub_iff_add_le.mpr ((rootSpace_zsmul_add_ne_bot_iff α β hα _).mp ?_).1 rw [add_smul, add_assoc, ← hβ', ← coe_chainTop] exact (chainTop α β').2 · refine ((rootSpace_zsmul_add_ne_bot_iff α β' hα _).mp ?_).1 rw [hβ', ← add_assoc, ← add_smul, sub_add_cancel, ← coe_chainTop] exact (chainTop α β).2 lemma chainBotCoeff_of_eq_zsmul_add (hα : α.IsNonZero) (β' : Weight K H L) (n : ℤ) (hβ' : (β' : H → K) = n • α + β) : chainBotCoeff α β' = chainBotCoeff α β + n := by have : (β' : H → K) = -n • (-α) + β := by rwa [neg_smul, smul_neg, neg_neg] rw [chainBotCoeff, chainBotCoeff, ← Weight.coe_neg, chainTopCoeff_of_eq_zsmul_add (-α) β hα.neg β' (-n) this, sub_neg_eq_add] lemma chainLength_of_eq_zsmul_add (β' : Weight K H L) (n : ℤ) (hβ' : (β' : H → K) = n • α + β) : chainLength α β' = chainLength α β := by by_cases hα : α.IsZero · rw [chainLength_of_isZero _ _ hα, chainLength_of_isZero _ _ hα] · apply Nat.cast_injective (R := ℤ) rw [← chainTopCoeff_add_chainBotCoeff, ← chainTopCoeff_add_chainBotCoeff, Nat.cast_add, Nat.cast_add, chainTopCoeff_of_eq_zsmul_add α β hα β' n hβ', chainBotCoeff_of_eq_zsmul_add α β hα β' n hβ', sub_eq_add_neg, add_add_add_comm, neg_add_cancel, add_zero] lemma chainTopCoeff_zero_right [Nontrivial L] (hα : α.IsNonZero) : chainTopCoeff α (0 : Weight K H L) = 1 := by symm apply eq_of_le_of_not_lt · rw [Nat.one_le_iff_ne_zero] intro e exact α.2 (by simpa [e, Weight.coe_zero] using genWeightSpace_chainTopCoeff_add_one_nsmul_add α (0 : Weight K H L) hα) obtain ⟨x, hx, x_ne0⟩ := (chainTop α (0 : Weight K H L)).exists_ne_zero obtain ⟨h, e, f, isSl2, he, hf⟩ := exists_isSl2Triple_of_weight_isNonZero hα obtain rfl := isSl2.h_eq_coroot hα he hf have prim : isSl2.HasPrimitiveVectorWith x (chainLength α (0 : Weight K H L) : K) := have := lie_mem_genWeightSpace_of_mem_genWeightSpace he hx ⟨x_ne0, (chainLength_smul _ _ hx).symm, by rwa [genWeightSpace_add_chainTop _ _ hα] at this⟩ obtain ⟨k, hk⟩ : ∃ k : K, k • f = (toEnd K L L f ^ (chainTopCoeff α (0 : Weight K H L) + 1)) x := by have : (toEnd K L L f ^ (chainTopCoeff α (0 : Weight K H L) + 1)) x ∈ rootSpace H (-α) := by convert toEnd_pow_apply_mem hf hx (chainTopCoeff α (0 : Weight K H L) + 1) using 2 rw [coe_chainTop', Weight.coe_zero, add_zero, succ_nsmul', add_assoc, smul_neg, neg_add_cancel, add_zero] simpa using (finrank_eq_one_iff_of_nonzero' ⟨f, hf⟩ (by simpa using isSl2.f_ne_zero)).mp (finrank_rootSpace_eq_one _ hα.neg) ⟨_, this⟩ apply_fun (⁅f, ·⁆) at hk simp only [lie_smul, lie_self, smul_zero, prim.lie_f_pow_toEnd_f] at hk intro e refine prim.pow_toEnd_f_ne_zero_of_eq_nat rfl ?_ hk.symm have := (apply_coroot_eq_cast' α 0).symm simp only [← @Nat.cast_two ℤ, ← Nat.cast_mul, Weight.zero_apply, Int.cast_eq_zero, sub_eq_zero, Nat.cast_inj] at this rwa [this, Nat.succ_le, two_mul, add_lt_add_iff_left] lemma chainBotCoeff_zero_right [Nontrivial L] (hα : α.IsNonZero) : chainBotCoeff α (0 : Weight K H L) = 1 := chainTopCoeff_zero_right (-α) hα.neg lemma chainLength_zero_right [Nontrivial L] (hα : α.IsNonZero) : chainLength α 0 = 2 := by rw [← chainBotCoeff_add_chainTopCoeff, chainTopCoeff_zero_right α hα, chainBotCoeff_zero_right α hα] lemma rootSpace_two_smul (hα : α.IsNonZero) : rootSpace H (2 • α) = ⊥ := by cases subsingleton_or_nontrivial L · exact IsEmpty.elim inferInstance α simpa [chainTopCoeff_zero_right α hα] using genWeightSpace_chainTopCoeff_add_one_nsmul_add α (0 : Weight K H L) hα lemma rootSpace_one_div_two_smul (hα : α.IsNonZero) : rootSpace H ((2⁻¹ : K) • α) = ⊥ := by by_contra h let W : Weight K H L := ⟨_, h⟩ have hW : 2 • (W : H → K) = α := by change 2 • (2⁻¹ : K) • (α : H → K) = α rw [← Nat.cast_smul_eq_nsmul K, smul_smul]; simp apply α.genWeightSpace_ne_bot have := rootSpace_two_smul W (fun (e : (W : H → K) = 0) ↦ hα <| by apply_fun (2 • ·) at e; simpa [hW] using e) rwa [hW] at this lemma eq_neg_one_or_eq_zero_or_eq_one_of_eq_smul (hα : α.IsNonZero) (k : K) (h : (β : H → K) = k • α) : k = -1 ∨ k = 0 ∨ k = 1 := by cases subsingleton_or_nontrivial L · exact IsEmpty.elim inferInstance α have H := apply_coroot_eq_cast' α β rw [h] at H simp only [Pi.smul_apply, root_apply_coroot hα] at H rcases (chainLength α β).even_or_odd with (⟨n, hn⟩|⟨n, hn⟩) · rw [hn, ← two_mul] at H simp only [smul_eq_mul, Nat.cast_mul, Nat.cast_ofNat, ← mul_sub, ← mul_comm (2 : K), Int.cast_sub, Int.cast_mul, Int.cast_ofNat, Int.cast_natCast, mul_eq_mul_left_iff, OfNat.ofNat_ne_zero, or_false] at H rw [← Int.cast_natCast, ← Int.cast_natCast (chainTopCoeff α β), ← Int.cast_sub] at H have := (rootSpace_zsmul_add_ne_bot_iff_mem α 0 hα (n - chainTopCoeff α β)).mp (by rw [← Int.cast_smul_eq_zsmul K, ← H, ← h, Weight.coe_zero, add_zero]; exact β.2) rw [chainTopCoeff_zero_right α hα, chainBotCoeff_zero_right α hα, Nat.cast_one] at this set k' : ℤ := n - chainTopCoeff α β subst H have : k' ∈ ({-1, 0, 1} : Finset ℤ) := by change k' ∈ Finset.Icc (-1 : ℤ) (1 : ℤ) exact this simpa only [Int.reduceNeg, Finset.mem_insert, Finset.mem_singleton, ← @Int.cast_inj K, Int.cast_zero, Int.cast_neg, Int.cast_one] using this · apply_fun (· / 2) at H rw [hn, smul_eq_mul] at H have hk : k = n + 2⁻¹ - chainTopCoeff α β := by simpa [sub_div, add_div] using H have := (rootSpace_zsmul_add_ne_bot_iff α β hα (chainTopCoeff α β - n)).mpr ?_ swap · simp only [tsub_le_iff_right, le_add_iff_nonneg_right, Nat.cast_nonneg, neg_sub, true_and] rw [← Nat.cast_add, chainBotCoeff_add_chainTopCoeff, hn] cutsat rw [h, hk, ← Int.cast_smul_eq_zsmul K, ← add_smul] at this simp only [Int.cast_sub, Int.cast_natCast, sub_add_sub_cancel', add_sub_cancel_left, ne_eq] at this cases this (rootSpace_one_div_two_smul α hα) /-- `±α` are the only `K`-multiples of a root `α` that are also (non-zero) roots. -/ lemma eq_neg_or_eq_of_eq_smul (hβ : β.IsNonZero) (k : K) (h : (β : H → K) = k • α) : β = -α ∨ β = α := by by_cases hα : α.IsZero · rw [hα, smul_zero] at h; cases hβ h rcases eq_neg_one_or_eq_zero_or_eq_one_of_eq_smul α β hα k h with (rfl | rfl | rfl) · exact .inl (by ext; rw [h, neg_one_smul]; rfl) · cases hβ (by rwa [zero_smul] at h) · exact .inr (by ext; rw [h, one_smul]) /-- The reflection of a root along another. -/ def reflectRoot (α β : Weight K H L) : Weight K H L where toFun := β - β (coroot α) • α genWeightSpace_ne_bot' := by by_cases hα : α.IsZero · simpa [hα.eq] using β.genWeightSpace_ne_bot rw [sub_eq_neg_add, apply_coroot_eq_cast α β, ← neg_smul, ← Int.cast_neg, Int.cast_smul_eq_zsmul, rootSpace_zsmul_add_ne_bot_iff α β hα] omega lemma reflectRoot_isNonZero (α β : Weight K H L) (hβ : β.IsNonZero) : (reflectRoot α β).IsNonZero := by intro e have : β (coroot α) = 0 := by by_cases hα : α.IsZero · simp [coroot_eq_zero_iff.mpr hα] simpa [root_apply_coroot hα, mul_two] using congr_fun (sub_eq_zero.mp e) (coroot α) have : reflectRoot α β = β := by ext; simp [reflectRoot, this] exact hβ (this ▸ e) variable (H) /-- The root system of a finite-dimensional Lie algebra with non-degenerate Killing form over a field of characteristic zero, relative to a splitting Cartan subalgebra. -/ def rootSystem : RootSystem H.root K (Dual K H) H := RootSystem.mk' .id { toFun := (↑) inj' := by intro α β h; ext x; simpa using LinearMap.congr_fun h x } { toFun := coroot ∘ (↑) inj' := by rintro ⟨α, hα⟩ ⟨β, hβ⟩ h; simpa using h } (fun ⟨α, hα⟩ ↦ by simpa using root_apply_coroot <| by simpa using hα) (by rintro ⟨α, hα⟩ - ⟨⟨β, hβ⟩, rfl⟩ simpa using ⟨reflectRoot α β, by simpa using reflectRoot_isNonZero α β <| by simpa using hβ, rfl⟩) (by convert span_weight_isNonZero_eq_top K L H; ext; simp) (fun α β ↦ ⟨chainBotCoeff β.1 α.1 - chainTopCoeff β.1 α.1, by simp [apply_coroot_eq_cast β.1 α.1]⟩) @[simp] lemma corootForm_rootSystem_eq_killing : (rootSystem H).CorootForm = (killingForm K L).restrict H := by rw [restrict_killingForm_eq_sum, RootPairing.CorootForm, ← Finset.sum_coe_sort (s := H.root)] rfl @[simp] lemma rootSystem_toLinearMap_apply (f x) : (rootSystem H).toLinearMap f x = f x := rfl @[simp] lemma rootSystem_pairing_apply (α β) : (rootSystem H).pairing β α = β.1 (coroot α.1) := rfl @[simp] lemma rootSystem_root_apply (α) : (rootSystem H).root α = α := rfl @[simp] lemma rootSystem_coroot_apply (α) : (rootSystem H).coroot α = coroot α := rfl instance : (rootSystem H).IsCrystallographic where exists_value α β := ⟨chainBotCoeff β.1 α.1 - chainTopCoeff β.1 α.1, by simp [apply_coroot_eq_cast β.1 α.1]⟩ instance : (rootSystem H).IsReduced where eq_or_eq_neg := by intro ⟨α, hα⟩ ⟨β, hβ⟩ e rw [LinearIndependent.pair_iff' ((rootSystem H).ne_zero _), not_forall] at e simp only [rootSystem_root_apply, ne_eq, not_not] at e obtain ⟨u, hu⟩ := e obtain (h | h) := eq_neg_or_eq_of_eq_smul α β (by simpa using hβ) u (by ext x; exact DFunLike.congr_fun hu.symm x) · right; ext x; simpa [neg_eq_iff_eq_neg] using DFunLike.congr_fun h.symm x · left; ext x; simpa using DFunLike.congr_fun h.symm x end LieAlgebra.IsKilling
.lake/packages/mathlib/Mathlib/Algebra/Lie/Weights/Killing.lean
import Mathlib.Algebra.Lie.Derivation.Killing import Mathlib.Algebra.Lie.Killing import Mathlib.Algebra.Lie.Sl2 import Mathlib.Algebra.Lie.Weights.Chain import Mathlib.LinearAlgebra.Eigenspace.Semisimple import Mathlib.LinearAlgebra.JordanChevalley /-! # Roots of Lie algebras with non-degenerate Killing forms The file contains definitions and results about roots of Lie algebras with non-degenerate Killing forms. ## Main definitions * `LieAlgebra.IsKilling.ker_restrict_eq_bot_of_isCartanSubalgebra`: if the Killing form of a Lie algebra is non-singular, it remains non-singular when restricted to a Cartan subalgebra. * `LieAlgebra.IsKilling.instIsLieAbelianOfIsCartanSubalgebra`: if the Killing form of a Lie algebra is non-singular, then its Cartan subalgebras are Abelian. * `LieAlgebra.IsKilling.isSemisimple_ad_of_mem_isCartanSubalgebra`: over a perfect field, if a Lie algebra has non-degenerate Killing form, Cartan subalgebras contain only semisimple elements. * `LieAlgebra.IsKilling.span_weight_eq_top`: given a splitting Cartan subalgebra `H` of a finite-dimensional Lie algebra with non-singular Killing form, the corresponding roots span the dual space of `H`. * `LieAlgebra.IsKilling.coroot`: the coroot corresponding to a root. * `LieAlgebra.IsKilling.isCompl_ker_weight_span_coroot`: given a root `α` with respect to a Cartan subalgebra `H`, we have a natural decomposition of `H` as the kernel of `α` and the span of the coroot corresponding to `α`. * `LieAlgebra.IsKilling.finrank_rootSpace_eq_one`: root spaces are one-dimensional. -/ variable (R K L : Type*) [CommRing R] [LieRing L] [LieAlgebra R L] [Field K] [LieAlgebra K L] namespace LieAlgebra lemma restrict_killingForm (H : LieSubalgebra R L) : (killingForm R L).restrict H = LieModule.traceForm R H L := rfl namespace IsKilling variable [IsKilling R L] /-- If the Killing form of a Lie algebra is non-singular, it remains non-singular when restricted to a Cartan subalgebra. -/ lemma ker_restrict_eq_bot_of_isCartanSubalgebra [IsNoetherian R L] [IsArtinian R L] (H : LieSubalgebra R L) [H.IsCartanSubalgebra] : LinearMap.ker ((killingForm R L).restrict H) = ⊥ := by have h : Codisjoint (rootSpace H 0) (LieModule.posFittingComp R H L) := (LieModule.isCompl_genWeightSpace_zero_posFittingComp R H L).codisjoint replace h : Codisjoint (H : Submodule R L) (LieModule.posFittingComp R H L : Submodule R L) := by rwa [codisjoint_iff, ← LieSubmodule.toSubmodule_inj, LieSubmodule.sup_toSubmodule, LieSubmodule.top_toSubmodule, rootSpace_zero_eq R L H, LieSubalgebra.coe_toLieSubmodule, ← codisjoint_iff] at h suffices this : ∀ m₀ ∈ H, ∀ m₁ ∈ LieModule.posFittingComp R H L, killingForm R L m₀ m₁ = 0 by simp [LinearMap.BilinForm.ker_restrict_eq_of_codisjoint h this] intro m₀ h₀ m₁ h₁ exact killingForm_eq_zero_of_mem_zeroRoot_mem_posFitting R L H (le_zeroRootSubalgebra R L H h₀) h₁ @[simp] lemma ker_traceForm_eq_bot_of_isCartanSubalgebra [IsNoetherian R L] [IsArtinian R L] (H : LieSubalgebra R L) [H.IsCartanSubalgebra] : LinearMap.ker (LieModule.traceForm R H L) = ⊥ := ker_restrict_eq_bot_of_isCartanSubalgebra R L H lemma traceForm_cartan_nondegenerate [IsNoetherian R L] [IsArtinian R L] (H : LieSubalgebra R L) [H.IsCartanSubalgebra] : (LieModule.traceForm R H L).Nondegenerate := by simp [LinearMap.BilinForm.nondegenerate_iff_ker_eq_bot] variable [Module.Free R L] [Module.Finite R L] instance instIsLieAbelianOfIsCartanSubalgebra [IsDomain R] [IsPrincipalIdealRing R] [IsArtinian R L] (H : LieSubalgebra R L) [H.IsCartanSubalgebra] : IsLieAbelian H := LieModule.isLieAbelian_of_ker_traceForm_eq_bot R H L <| ker_restrict_eq_bot_of_isCartanSubalgebra R L H end IsKilling section Field open Module LieModule Set open Submodule (span subset_span) variable [FiniteDimensional K L] (H : LieSubalgebra K L) [H.IsCartanSubalgebra] section variable [IsTriangularizable K H L] /-- For any `α` and `β`, the corresponding root spaces are orthogonal with respect to the Killing form, provided `α + β ≠ 0`. -/ lemma killingForm_apply_eq_zero_of_mem_rootSpace_of_add_ne_zero {α β : H → K} {x y : L} (hx : x ∈ rootSpace H α) (hy : y ∈ rootSpace H β) (hαβ : α + β ≠ 0) : killingForm K L x y = 0 := by /- If `ad R L z` is semisimple for all `z ∈ H` then writing `⟪x, y⟫ = killingForm K L x y`, there is a slick proof of this lemma that requires only invariance of the Killing form as follows. For any `z ∈ H`, we have: `α z • ⟪x, y⟫ = ⟪α z • x, y⟫ = ⟪⁅z, x⁆, y⟫ = - ⟪x, ⁅z, y⁆⟫ = - ⟪x, β z • y⟫ = - β z • ⟪x, y⟫`. Since this is true for any `z`, we thus have: `(α + β) • ⟪x, y⟫ = 0`, and hence the result. However the semisimplicity of `ad R L z` is (a) non-trivial and (b) requires the assumption that `K` is a perfect field and `L` has non-degenerate Killing form. -/ let σ : (H → K) → (H → K) := fun γ ↦ α + (β + γ) have hσ : ∀ γ, σ γ ≠ γ := fun γ ↦ by simpa only [σ, ← add_assoc] using add_ne_right.mpr hαβ let f : Module.End K L := (ad K L x) ∘ₗ (ad K L y) have hf : ∀ γ, MapsTo f (rootSpace H γ) (rootSpace H (σ γ)) := fun γ ↦ (mapsTo_toEnd_genWeightSpace_add_of_mem_rootSpace K L H L α (β + γ) hx).comp <| mapsTo_toEnd_genWeightSpace_add_of_mem_rootSpace K L H L β γ hy classical have hds := DirectSum.isInternal_submodule_of_iSupIndep_of_iSup_eq_top (LieSubmodule.iSupIndep_toSubmodule.mpr <| iSupIndep_genWeightSpace K H L) (LieSubmodule.iSup_toSubmodule_eq_top.mpr <| iSup_genWeightSpace_eq_top K H L) exact LinearMap.trace_eq_zero_of_mapsTo_ne hds σ hσ hf /-- Elements of the `α` root space which are Killing-orthogonal to the `-α` root space are Killing-orthogonal to all of `L`. -/ lemma mem_ker_killingForm_of_mem_rootSpace_of_forall_rootSpace_neg {α : H → K} {x : L} (hx : x ∈ rootSpace H α) (hx' : ∀ y ∈ rootSpace H (-α), killingForm K L x y = 0) : x ∈ LinearMap.ker (killingForm K L) := by rw [LinearMap.mem_ker] ext y have hy : y ∈ ⨆ β, rootSpace H β := by simp [iSup_genWeightSpace_eq_top K H L] induction hy using LieSubmodule.iSup_induction' with | mem β y hy => by_cases hαβ : α + β = 0 · exact hx' _ (add_eq_zero_iff_neg_eq.mp hαβ ▸ hy) · exact killingForm_apply_eq_zero_of_mem_rootSpace_of_add_ne_zero K L H hx hy hαβ | zero => simp | add => simp_all end end Field end LieAlgebra namespace LieModule namespace Weight open LieAlgebra IsKilling variable {K L} variable [FiniteDimensional K L] [IsKilling K L] {H : LieSubalgebra K L} [H.IsCartanSubalgebra] [IsTriangularizable K H L] {α : Weight K H L} instance : InvolutiveNeg (Weight K H L) where neg α := ⟨-α, by by_cases hα : α.IsZero · convert α.genWeightSpace_ne_bot; rw [hα, neg_zero] · intro e obtain ⟨x, hx, x_ne0⟩ := α.exists_ne_zero have := mem_ker_killingForm_of_mem_rootSpace_of_forall_rootSpace_neg K L H hx (fun y hy ↦ by rw [rootSpace, e] at hy; rw [hy, map_zero]) rw [ker_killingForm_eq_bot] at this exact x_ne0 this⟩ neg_neg α := by ext; simp @[simp] lemma coe_neg : ((-α : Weight K H L) : H → K) = -α := rfl lemma IsZero.neg (h : α.IsZero) : (-α).IsZero := by ext; rw [coe_neg, h, neg_zero] @[simp] lemma isZero_neg : (-α).IsZero ↔ α.IsZero := ⟨fun h ↦ neg_neg α ▸ h.neg, fun h ↦ h.neg⟩ lemma IsNonZero.neg (h : α.IsNonZero) : (-α).IsNonZero := fun e ↦ h (by simpa using e.neg) @[simp] lemma isNonZero_neg {α : Weight K H L} : (-α).IsNonZero ↔ α.IsNonZero := isZero_neg.not @[simp] lemma toLinear_neg {α : Weight K H L} : (-α).toLinear = -α.toLinear := rfl end Weight end LieModule namespace LieAlgebra open Module LieModule Set open Submodule renaming span → span open Submodule renaming subset_span → subset_span namespace IsKilling variable [FiniteDimensional K L] (H : LieSubalgebra K L) [H.IsCartanSubalgebra] variable [IsKilling K L] /-- If a Lie algebra `L` has non-degenerate Killing form, the only element of a Cartan subalgebra whose adjoint action on `L` is nilpotent, is the zero element. Over a perfect field a much stronger result is true, see `LieAlgebra.IsKilling.isSemisimple_ad_of_mem_isCartanSubalgebra`. -/ lemma eq_zero_of_isNilpotent_ad_of_mem_isCartanSubalgebra {x : L} (hx : x ∈ H) (hx' : _root_.IsNilpotent (ad K L x)) : x = 0 := by suffices ⟨x, hx⟩ ∈ LinearMap.ker (traceForm K H L) by simp only [ker_traceForm_eq_bot_of_isCartanSubalgebra, Submodule.mem_bot] at this exact (AddSubmonoid.mk_eq_zero H.toAddSubmonoid).mp this simp only [LinearMap.mem_ker] ext y have comm : Commute (toEnd K H L ⟨x, hx⟩) (toEnd K H L y) := by rw [commute_iff_lie_eq, ← LieHom.map_lie, trivial_lie_zero, map_zero] rw [traceForm_apply_apply, ← Module.End.mul_eq_comp, LinearMap.zero_apply] exact (LinearMap.isNilpotent_trace_of_isNilpotent (comm.isNilpotent_mul_right hx')).eq_zero @[simp] lemma corootSpace_zero_eq_bot : corootSpace (0 : H → K) = ⊥ := by refine eq_bot_iff.mpr fun x hx ↦ ?_ suffices {x | ∃ y ∈ H, ∃ z ∈ H, ⁅y, z⁆ = x} = {0} by simpa [mem_corootSpace, this] using hx refine eq_singleton_iff_unique_mem.mpr ⟨⟨0, H.zero_mem, 0, H.zero_mem, zero_lie 0⟩, ?_⟩ rintro - ⟨y, hy, z, hz, rfl⟩ suffices ⁅(⟨y, hy⟩ : H), (⟨z, hz⟩ : H)⁆ = 0 by simpa only [Subtype.ext_iff, LieSubalgebra.coe_bracket, ZeroMemClass.coe_zero] using this simp variable {K L} in /-- The restriction of the Killing form to a Cartan subalgebra, as a linear equivalence to the dual. -/ @[simps! apply_apply] noncomputable def cartanEquivDual : H ≃ₗ[K] Module.Dual K H := (traceForm K H L).toDual <| traceForm_cartan_nondegenerate K L H variable {K L H} /-- The coroot corresponding to a root. -/ noncomputable def coroot (α : Weight K H L) : H := 2 • (α <| (cartanEquivDual H).symm α)⁻¹ • (cartanEquivDual H).symm α lemma traceForm_coroot (α : Weight K H L) (x : H) : traceForm K H L (coroot α) x = 2 • (α <| (cartanEquivDual H).symm α)⁻¹ • α x := by have : cartanEquivDual H ((cartanEquivDual H).symm α) x = α x := by rw [LinearEquiv.apply_symm_apply, Weight.toLinear_apply] rw [coroot, map_nsmul, map_smul, LinearMap.smul_apply, LinearMap.smul_apply] congr 2 @[simp] lemma coroot_neg [IsTriangularizable K H L] (α : Weight K H L) : coroot (-α) = -coroot α := by simp [coroot] variable [IsTriangularizable K H L] lemma lie_eq_killingForm_smul_of_mem_rootSpace_of_mem_rootSpace_neg_aux {α : Weight K H L} {e f : L} (heα : e ∈ rootSpace H α) (hfα : f ∈ rootSpace H (-α)) (aux : ∀ (h : H), ⁅h, e⁆ = α h • e) : ⁅e, f⁆ = killingForm K L e f • (cartanEquivDual H).symm α := by set α' := (cartanEquivDual H).symm α rw [← sub_eq_zero, ← Submodule.mem_bot (R := K), ← ker_killingForm_eq_bot] apply mem_ker_killingForm_of_mem_rootSpace_of_forall_rootSpace_neg (α := (0 : H → K)) · simp only [rootSpace_zero_eq, LieSubalgebra.mem_toLieSubmodule] refine sub_mem ?_ (H.smul_mem _ α'.property) simpa using mapsTo_toEnd_genWeightSpace_add_of_mem_rootSpace K L H L α (-α) heα hfα · intro z hz replace hz : z ∈ H := by simpa using hz have he : ⁅z, e⁆ = α ⟨z, hz⟩ • e := aux ⟨z, hz⟩ have hαz : killingForm K L α' (⟨z, hz⟩ : H) = α ⟨z, hz⟩ := LinearMap.BilinForm.apply_toDual_symm_apply (hB := traceForm_cartan_nondegenerate K L H) _ _ simp [traceForm_comm K L L ⁅e, f⁆, ← traceForm_apply_lie_apply, he, mul_comm _ (α ⟨z, hz⟩), hαz] /-- This is Proposition 4.18 from [carter2005] except that we use `LieModule.exists_forall_lie_eq_smul` instead of Lie's theorem (and so avoid assuming `K` has characteristic zero). -/ lemma cartanEquivDual_symm_apply_mem_corootSpace (α : Weight K H L) : (cartanEquivDual H).symm α ∈ corootSpace α := by obtain ⟨e : L, he₀ : e ≠ 0, he : ∀ x, ⁅x, e⁆ = α x • e⟩ := exists_forall_lie_eq_smul K H L α have heα : e ∈ rootSpace H α := (mem_genWeightSpace L α e).mpr fun x ↦ ⟨1, by simp [← he x]⟩ obtain ⟨f, hfα, hf⟩ : ∃ f ∈ rootSpace H (-α), killingForm K L e f ≠ 0 := by contrapose! he₀ simpa using mem_ker_killingForm_of_mem_rootSpace_of_forall_rootSpace_neg K L H heα he₀ suffices ⁅e, f⁆ = killingForm K L e f • ((cartanEquivDual H).symm α : L) from (mem_corootSpace α).mpr <| Submodule.subset_span ⟨(killingForm K L e f)⁻¹ • e, Submodule.smul_mem _ _ heα, f, hfα, by simpa [inv_smul_eq_iff₀ hf]⟩ exact lie_eq_killingForm_smul_of_mem_rootSpace_of_mem_rootSpace_neg_aux heα hfα he @[simp] lemma coroot_mem_corootSpace (α : Weight K H L) : coroot α ∈ corootSpace α := nsmul_mem (Submodule.smul_mem _ _ <| cartanEquivDual_symm_apply_mem_corootSpace α) _ /-- Given a splitting Cartan subalgebra `H` of a finite-dimensional Lie algebra with non-singular Killing form, the corresponding roots span the dual space of `H`. -/ @[simp] lemma span_weight_eq_top : span K (range (Weight.toLinear K H L)) = ⊤ := by refine eq_top_iff.mpr (le_trans ?_ (LieModule.range_traceForm_le_span_weight K H L)) rw [← traceForm_flip K H L, ← LinearMap.dualAnnihilator_ker_eq_range_flip, ker_traceForm_eq_bot_of_isCartanSubalgebra, Submodule.dualAnnihilator_bot] variable (K L H) in @[simp] lemma span_weight_isNonZero_eq_top : span K ({α : Weight K H L | α.IsNonZero}.image (Weight.toLinear K H L)) = ⊤ := by rw [← span_weight_eq_top] refine le_antisymm (Submodule.span_mono <| by simp) ?_ suffices range (Weight.toLinear K H L) ⊆ insert 0 ({α : Weight K H L | α.IsNonZero}.image (Weight.toLinear K H L)) by simpa only [Submodule.span_insert_zero] using Submodule.span_mono this rintro - ⟨α, rfl⟩ simp only [mem_insert_iff, Weight.coe_toLinear_eq_zero_iff, mem_image, mem_setOf_eq] tauto @[simp] lemma iInf_ker_weight_eq_bot : ⨅ α : Weight K H L, α.ker = ⊥ := by rw [← Subspace.dualAnnihilator_inj, Subspace.dualAnnihilator_iInf_eq, Submodule.dualAnnihilator_bot] simp [← LinearMap.range_dualMap_eq_dualAnnihilator_ker, ← Submodule.span_range_eq_iSup] section PerfectField variable [PerfectField K] open Module.End in lemma isSemisimple_ad_of_mem_isCartanSubalgebra {x : L} (hx : x ∈ H) : (ad K L x).IsSemisimple := by /- Using Jordan-Chevalley, write `ad K L x` as a sum of its semisimple and nilpotent parts. -/ obtain ⟨N, -, S, hS₀, hN, hS, hSN⟩ := (ad K L x).exists_isNilpotent_isSemisimple replace hS₀ : Commute (ad K L x) S := Algebra.commute_of_mem_adjoin_self hS₀ set x' : H := ⟨x, hx⟩ rw [eq_sub_of_add_eq hSN.symm] at hN /- Note that the semisimple part `S` is just a scalar action on each root space. -/ have aux {α : H → K} {y : L} (hy : y ∈ rootSpace H α) : S y = α x' • y := by replace hy : y ∈ (ad K L x).maxGenEigenspace (α x') := (genWeightSpace_le_genWeightSpaceOf L x' α) hy rw [maxGenEigenspace_eq] at hy set k := maxGenEigenspaceIndex (ad K L x) (α x') rw [apply_eq_of_mem_of_comm_of_isFinitelySemisimple_of_isNil hy hS₀ hS.isFinitelySemisimple hN] /- So `S` obeys the derivation axiom if we restrict to root spaces. -/ have h_der (y z : L) (α β : H → K) (hy : y ∈ rootSpace H α) (hz : z ∈ rootSpace H β) : S ⁅y, z⁆ = ⁅S y, z⁆ + ⁅y, S z⁆ := by have hyz : ⁅y, z⁆ ∈ rootSpace H (α + β) := mapsTo_toEnd_genWeightSpace_add_of_mem_rootSpace K L H L α β hy hz rw [aux hy, aux hz, aux hyz, smul_lie, lie_smul, ← add_smul, ← Pi.add_apply] /- Thus `S` is a derivation since root spaces span. -/ replace h_der (y z : L) : S ⁅y, z⁆ = ⁅S y, z⁆ + ⁅y, S z⁆ := by have hy : y ∈ ⨆ α : H → K, rootSpace H α := by simp [iSup_genWeightSpace_eq_top] have hz : z ∈ ⨆ α : H → K, rootSpace H α := by simp [iSup_genWeightSpace_eq_top] induction hy using LieSubmodule.iSup_induction' with | mem α y hy => induction hz using LieSubmodule.iSup_induction' with | mem β z hz => exact h_der y z α β hy hz | zero => simp | add _ _ _ _ h h' => simp only [lie_add, map_add, h, h']; abel | zero => simp | add _ _ _ _ h h' => simp only [add_lie, map_add, h, h']; abel /- An equivalent form of the derivation axiom used in `LieDerivation`. -/ replace h_der : ∀ y z : L, S ⁅y, z⁆ = ⁅y, S z⁆ - ⁅z, S y⁆ := by simp_rw [← lie_skew (S _) _, add_comm, ← sub_eq_add_neg] at h_der; assumption /- Bundle `S` as a `LieDerivation`. -/ let S' : LieDerivation K L L := ⟨S, h_der⟩ /- Since `L` has non-degenerate Killing form, `S` must be inner, corresponding to some `y : L`. -/ obtain ⟨y, hy⟩ := LieDerivation.IsKilling.exists_eq_ad S' /- `y` commutes with all elements of `H` because `S` has eigenvalue 0 on `H`, `S = ad K L y`. -/ have hy' (z : L) (hz : z ∈ H) : ⁅y, z⁆ = 0 := by rw [← LieSubalgebra.mem_toLieSubmodule, ← rootSpace_zero_eq] at hz simp [S', ← ad_apply (R := K), ← LieDerivation.coe_ad_apply_eq_ad_apply, hy, aux hz] /- Thus `y` belongs to `H` since `H` is self-normalizing. -/ replace hy' : y ∈ H := by suffices y ∈ H.normalizer by rwa [LieSubalgebra.IsCartanSubalgebra.self_normalizing] at this exact (H.mem_normalizer_iff y).mpr fun z hz ↦ hy' z hz ▸ LieSubalgebra.zero_mem H /- It suffices to show `x = y` since `S = ad K L y` is semisimple. -/ suffices x = y by rwa [this, ← LieDerivation.coe_ad_apply_eq_ad_apply y, hy] rw [← sub_eq_zero] /- This will follow if we can show that `ad K L (x - y)` is nilpotent. -/ apply eq_zero_of_isNilpotent_ad_of_mem_isCartanSubalgebra K L H (H.sub_mem hx hy') /- Which is true because `ad K L (x - y) = N`. -/ replace hy : S = ad K L y := by rw [← LieDerivation.coe_ad_apply_eq_ad_apply y, hy] rwa [map_sub, hSN, hy, add_sub_cancel_right, eq_sub_of_add_eq hSN.symm] lemma lie_eq_smul_of_mem_rootSpace {α : H → K} {x : L} (hx : x ∈ rootSpace H α) (h : H) : ⁅h, x⁆ = α h • x := by replace hx : x ∈ (ad K L h).maxGenEigenspace (α h) := genWeightSpace_le_genWeightSpaceOf L h α hx rw [(isSemisimple_ad_of_mem_isCartanSubalgebra h.property).isFinitelySemisimple.maxGenEigenspace_eq_eigenspace, Module.End.mem_eigenspace_iff] at hx simpa using hx lemma lie_eq_killingForm_smul_of_mem_rootSpace_of_mem_rootSpace_neg {α : Weight K H L} {e f : L} (heα : e ∈ rootSpace H α) (hfα : f ∈ rootSpace H (-α)) : ⁅e, f⁆ = killingForm K L e f • (cartanEquivDual H).symm α := by apply lie_eq_killingForm_smul_of_mem_rootSpace_of_mem_rootSpace_neg_aux heα hfα exact lie_eq_smul_of_mem_rootSpace heα lemma coe_corootSpace_eq_span_singleton' (α : Weight K H L) : (corootSpace α).toSubmodule = K ∙ (cartanEquivDual H).symm α := by refine le_antisymm ?_ ?_ · intro ⟨x, hx⟩ hx' have : {⁅y, z⁆ | (y ∈ rootSpace H α) (z ∈ rootSpace H (-α))} ⊆ K ∙ ((cartanEquivDual H).symm α : L) := by rintro - ⟨e, heα, f, hfα, rfl⟩ rw [lie_eq_killingForm_smul_of_mem_rootSpace_of_mem_rootSpace_neg heα hfα, SetLike.mem_coe, Submodule.mem_span_singleton] exact ⟨killingForm K L e f, rfl⟩ simp only [LieSubmodule.mem_toSubmodule, mem_corootSpace] at hx' replace this := Submodule.span_mono this hx' rw [Submodule.span_span] at this rw [Submodule.mem_span_singleton] at this ⊢ obtain ⟨t, rfl⟩ := this solve_by_elim · simp only [Submodule.span_singleton_le_iff_mem, LieSubmodule.mem_toSubmodule] exact cartanEquivDual_symm_apply_mem_corootSpace α end PerfectField section CharZero variable [CharZero K] /-- The contrapositive of this result is very useful, taking `x` to be the element of `H` corresponding to a root `α` under the identification between `H` and `H^*` provided by the Killing form. -/ lemma eq_zero_of_apply_eq_zero_of_mem_corootSpace (x : H) (α : H → K) (hαx : α x = 0) (hx : x ∈ corootSpace α) : x = 0 := by rcases eq_or_ne α 0 with rfl | hα; · simpa using hx replace hx : x ∈ ⨅ β : Weight K H L, β.ker := by refine (Submodule.mem_iInf _).mpr fun β ↦ ?_ obtain ⟨a, b, hb, hab⟩ := exists_forall_mem_corootSpace_smul_add_eq_zero L α β hα β.genWeightSpace_ne_bot simpa [hαx, hb.ne'] using hab _ hx simpa using hx lemma disjoint_ker_weight_corootSpace (α : Weight K H L) : Disjoint α.ker (corootSpace α) := by rw [disjoint_iff] refine (Submodule.eq_bot_iff _).mpr fun x ⟨hαx, hx⟩ ↦ ?_ replace hαx : α x = 0 := by simpa using hαx exact eq_zero_of_apply_eq_zero_of_mem_corootSpace x α hαx hx lemma root_apply_cartanEquivDual_symm_ne_zero {α : Weight K H L} (hα : α.IsNonZero) : α ((cartanEquivDual H).symm α) ≠ 0 := by contrapose! hα suffices (cartanEquivDual H).symm α ∈ α.ker ⊓ corootSpace α by rw [(disjoint_ker_weight_corootSpace α).eq_bot] at this simpa using this exact Submodule.mem_inf.mp ⟨hα, cartanEquivDual_symm_apply_mem_corootSpace α⟩ lemma root_apply_coroot {α : Weight K H L} (hα : α.IsNonZero) : α (coroot α) = 2 := by rw [← Weight.coe_coe] simpa [coroot] using inv_mul_cancel₀ (root_apply_cartanEquivDual_symm_ne_zero hα) @[simp] lemma coroot_eq_zero_iff {α : Weight K H L} : coroot α = 0 ↔ α.IsZero := by refine ⟨fun hα ↦ ?_, fun hα ↦ ?_⟩ · by_contra contra simpa [hα, ← α.coe_coe, map_zero] using root_apply_coroot contra · simp [coroot, Weight.coe_toLinear_eq_zero_iff.mpr hα] @[simp] lemma coroot_zero [Nontrivial L] : coroot (0 : Weight K H L) = 0 := by simp [Weight.isZero_zero] lemma coe_corootSpace_eq_span_singleton (α : Weight K H L) : (corootSpace α).toSubmodule = K ∙ coroot α := by if hα : α.IsZero then simp [hα.eq, coroot_eq_zero_iff.mpr hα] else set α' := (cartanEquivDual H).symm α suffices (K ∙ coroot α) = K ∙ α' by rw [coe_corootSpace_eq_span_singleton']; exact this.symm have : IsUnit (2 * (α α')⁻¹) := by simpa using root_apply_cartanEquivDual_symm_ne_zero hα change (K ∙ (2 • (α α')⁻¹ • α')) = _ simpa [← Nat.cast_smul_eq_nsmul K, smul_smul] using Submodule.span_singleton_smul_eq this _ @[simp] lemma corootSpace_eq_bot_iff {α : Weight K H L} : corootSpace α = ⊥ ↔ α.IsZero := by simp [← LieSubmodule.toSubmodule_eq_bot, coe_corootSpace_eq_span_singleton α] lemma isCompl_ker_weight_span_coroot (α : Weight K H L) : IsCompl α.ker (K ∙ coroot α) := by if hα : α.IsZero then simpa [Weight.coe_toLinear_eq_zero_iff.mpr hα, coroot_eq_zero_iff.mpr hα, Weight.ker] using isCompl_top_bot else rw [← coe_corootSpace_eq_span_singleton] apply Module.Dual.isCompl_ker_of_disjoint_of_ne_bot (by simp_all) (disjoint_ker_weight_corootSpace α) replace hα : corootSpace α ≠ ⊥ := by simpa using hα rwa [ne_eq, ← LieSubmodule.toSubmodule_inj] at hα lemma traceForm_eq_zero_of_mem_ker_of_mem_span_coroot {α : Weight K H L} {x y : H} (hx : x ∈ α.ker) (hy : y ∈ K ∙ coroot α) : traceForm K H L x y = 0 := by rw [← coe_corootSpace_eq_span_singleton, LieSubmodule.mem_toSubmodule, mem_corootSpace'] at hy induction hy using Submodule.span_induction with | mem z hz => obtain ⟨u, hu, v, -, huv⟩ := hz change killingForm K L (x : L) (z : L) = 0 replace hx : α x = 0 := by simpa using hx rw [← huv, ← traceForm_apply_lie_apply, ← LieSubalgebra.coe_bracket_of_module, lie_eq_smul_of_mem_rootSpace hu, hx, zero_smul, map_zero, LinearMap.zero_apply] | zero => simp | add _ _ _ _ hx hy => simp [hx, hy] | smul _ _ _ hz => simp [hz] @[simp] lemma orthogonal_span_coroot_eq_ker (α : Weight K H L) : (traceForm K H L).orthogonal (K ∙ coroot α) = α.ker := by if hα : α.IsZero then have hα' : coroot α = 0 := by simpa replace hα : α.ker = ⊤ := by ext; simp [hα] simp [hα, hα'] else refine le_antisymm (fun x hx ↦ ?_) (fun x hx y hy ↦ ?_) · simp only [LinearMap.BilinForm.mem_orthogonal_iff] at hx specialize hx (coroot α) (Submodule.mem_span_singleton_self _) simp only [LinearMap.BilinForm.isOrtho_def, traceForm_coroot, smul_eq_mul, nsmul_eq_mul, Nat.cast_ofNat, mul_eq_zero, OfNat.ofNat_ne_zero, inv_eq_zero, false_or] at hx simpa using hx.resolve_left (root_apply_cartanEquivDual_symm_ne_zero hα) · have := traceForm_eq_zero_of_mem_ker_of_mem_span_coroot hx hy rwa [traceForm_comm] at this @[simp] lemma coroot_eq_iff (α β : Weight K H L) : coroot α = coroot β ↔ α = β := by refine ⟨fun hyp ↦ ?_, fun h ↦ by rw [h]⟩ if hα : α.IsZero then have hβ : β.IsZero := by rw [← coroot_eq_zero_iff] at hα ⊢ rwa [← hyp] ext simp [hα.eq, hβ.eq] else have hβ : β.IsNonZero := by contrapose! hα simp only [← coroot_eq_zero_iff] at hα ⊢ rwa [hyp] have : α.ker = β.ker := by rw [← orthogonal_span_coroot_eq_ker α, hyp, orthogonal_span_coroot_eq_ker] suffices (α : H →ₗ[K] K) = β by ext x; simpa using LinearMap.congr_fun this x apply Module.Dual.eq_of_ker_eq_of_apply_eq (coroot α) this · rw [Weight.toLinear_apply, root_apply_coroot hα, hyp, Weight.toLinear_apply, root_apply_coroot hβ] · simp [root_apply_coroot hα] lemma exists_isSl2Triple_of_weight_isNonZero {α : Weight K H L} (hα : α.IsNonZero) : ∃ h e f : L, IsSl2Triple h e f ∧ e ∈ rootSpace H α ∧ f ∈ rootSpace H (- α) := by obtain ⟨e, heα : e ∈ rootSpace H α, he₀ : e ≠ 0⟩ := α.exists_ne_zero obtain ⟨f', hfα, hf⟩ : ∃ f ∈ rootSpace H (-α), killingForm K L e f ≠ 0 := by contrapose! he₀ simpa using mem_ker_killingForm_of_mem_rootSpace_of_forall_rootSpace_neg K L H heα he₀ have hef := lie_eq_killingForm_smul_of_mem_rootSpace_of_mem_rootSpace_neg heα hfα let h : H := ⟨⁅e, f'⁆, hef ▸ Submodule.smul_mem _ _ (Submodule.coe_mem _)⟩ have hh : α h ≠ 0 := by have : h = killingForm K L e f' • (cartanEquivDual H).symm α := by simp only [h, Subtype.ext_iff, hef] rw [Submodule.coe_smul_of_tower] rw [this, map_smul, smul_eq_mul, ne_eq, mul_eq_zero, not_or] exact ⟨hf, root_apply_cartanEquivDual_symm_ne_zero hα⟩ let f := (2 * (α h)⁻¹) • f' replace hef : ⁅⁅e, f⁆, e⁆ = 2 • e := by have : ⁅⁅e, f'⁆, e⁆ = α h • e := lie_eq_smul_of_mem_rootSpace heα h rw [lie_smul, smul_lie, this, ← smul_assoc, smul_eq_mul, mul_assoc, inv_mul_cancel₀ hh, mul_one, two_smul, two_smul] refine ⟨⁅e, f⁆, e, f, ⟨fun contra ↦ ?_, rfl, hef, ?_⟩, heα, Submodule.smul_mem _ _ hfα⟩ · rw [contra] at hef have : IsAddTorsionFree L := .of_noZeroSMulDivisors K L simp only [zero_lie, eq_comm (a := (0 : L)), smul_eq_zero, OfNat.ofNat_ne_zero, false_or] at hef contradiction · have : ⁅⁅e, f'⁆, f'⁆ = - α h • f' := lie_eq_smul_of_mem_rootSpace hfα h rw [lie_smul, lie_smul, smul_lie, this] simp [← smul_assoc, f, hh, mul_comm _ (2 * (α h)⁻¹)] lemma _root_.IsSl2Triple.h_eq_coroot {α : Weight K H L} (hα : α.IsNonZero) {h e f : L} (ht : IsSl2Triple h e f) (heα : e ∈ rootSpace H α) (hfα : f ∈ rootSpace H (-α)) : h = coroot α := by have hef := lie_eq_killingForm_smul_of_mem_rootSpace_of_mem_rootSpace_neg heα hfα lift h to H using by simpa only [← ht.lie_e_f, hef] using H.smul_mem _ (Submodule.coe_mem _) congr 1 have key : α h = 2 := by have := lie_eq_smul_of_mem_rootSpace heα h rw [LieSubalgebra.coe_bracket_of_module, ht.lie_h_e_smul K] at this exact smul_left_injective K ht.e_ne_zero this.symm suffices ∃ s : K, s • h = coroot α by obtain ⟨s, hs⟩ := this replace this : s = 1 := by simpa [root_apply_coroot hα, key] using congr_arg α hs rwa [this, one_smul] at hs set α' := (cartanEquivDual H).symm α with hα' have h_eq : h = killingForm K L e f • α' := by simp only [hα', Subtype.ext_iff, ← ht.lie_e_f, hef] rw [Submodule.coe_smul_of_tower] use (2 • (α α')⁻¹) * (killingForm K L e f)⁻¹ have hef₀ : killingForm K L e f ≠ 0 := by have := ht.h_ne_zero contrapose! this simpa [this] using h_eq rw [h_eq, smul_smul, mul_assoc, inv_mul_cancel₀ hef₀, mul_one, smul_assoc, coroot] lemma finrank_rootSpace_eq_one (α : Weight K H L) (hα : α.IsNonZero) : finrank K (rootSpace H α) = 1 := by suffices ¬ 1 < finrank K (rootSpace H α) by have h₀ : finrank K (rootSpace H α) ≠ 0 := by convert_to finrank K (rootSpace H α).toSubmodule ≠ 0 simpa using α.genWeightSpace_ne_bot cutsat intro contra obtain ⟨h, e, f, ht, heα, hfα⟩ := exists_isSl2Triple_of_weight_isNonZero hα let F : rootSpace H α →ₗ[K] K := killingForm K L f ∘ₗ (rootSpace H α).subtype have hF : LinearMap.ker F ≠ ⊥ := F.ker_ne_bot_of_finrank_lt <| by rwa [finrank_self] obtain ⟨⟨y, hyα⟩, hy, hy₀⟩ := (Submodule.ne_bot_iff _).mp hF replace hy : ⁅y, f⁆ = 0 := by have : killingForm K L y f = 0 := by simpa [F, traceForm_comm] using hy simpa [this] using lie_eq_killingForm_smul_of_mem_rootSpace_of_mem_rootSpace_neg hyα hfα have P : ht.symm.HasPrimitiveVectorWith y (-2 : K) := { ne_zero := by simpa [LieSubmodule.mk_eq_zero] using hy₀ lie_h := by simp only [neg_smul, neg_lie, ht.h_eq_coroot hα heα hfα, ← H.coe_bracket_of_module, lie_eq_smul_of_mem_rootSpace hyα (coroot α), root_apply_coroot hα] lie_e := by rw [← lie_skew, hy, neg_zero] } obtain ⟨n, hn⟩ := P.exists_nat assumption_mod_cast /-- The embedded `sl₂` associated to a root. -/ noncomputable def sl2SubalgebraOfRoot {α : Weight K H L} (hα : α.IsNonZero) : LieSubalgebra K L := by choose h e f t ht using exists_isSl2Triple_of_weight_isNonZero hα exact t.toLieSubalgebra K lemma mem_sl2SubalgebraOfRoot_iff {α : Weight K H L} (hα : α.IsNonZero) {h e f : L} (t : IsSl2Triple h e f) (hte : e ∈ rootSpace H α) (htf : f ∈ rootSpace H (-α)) {x : L} : x ∈ sl2SubalgebraOfRoot hα ↔ ∃ c₁ c₂ c₃ : K, x = c₁ • e + c₂ • f + c₃ • ⁅e, f⁆ := by simp only [sl2SubalgebraOfRoot, IsSl2Triple.mem_toLieSubalgebra_iff] generalize_proofs _ _ _ he hf obtain ⟨ce, hce⟩ : ∃ c : K, he.choose = c • e := by obtain ⟨c, hc⟩ := (finrank_eq_one_iff_of_nonzero' ⟨e, hte⟩ (by simpa using t.e_ne_zero)).mp (finrank_rootSpace_eq_one α hα) ⟨_, he.choose_spec.choose_spec.2.1⟩ exact ⟨c, by simpa using hc.symm⟩ obtain ⟨cf, hcf⟩ : ∃ c : K, hf.choose = c • f := by obtain ⟨c, hc⟩ := (finrank_eq_one_iff_of_nonzero' ⟨f, htf⟩ (by simpa using t.f_ne_zero)).mp (finrank_rootSpace_eq_one (-α) (by simpa)) ⟨_, hf.choose_spec.2.2⟩ exact ⟨c, by simpa using hc.symm⟩ have hce₀ : ce ≠ 0 := by rintro rfl simp only [zero_smul] at hce exact he.choose_spec.choose_spec.1.e_ne_zero hce have hcf₀ : cf ≠ 0 := by rintro rfl simp only [zero_smul] at hcf exact he.choose_spec.choose_spec.1.f_ne_zero hcf simp_rw [hcf, hce] refine ⟨fun ⟨c₁, c₂, c₃, hx⟩ ↦ ⟨c₁ * ce, c₂ * cf, c₃ * cf * ce, ?_⟩, fun ⟨c₁, c₂, c₃, hx⟩ ↦ ⟨c₁ * ce⁻¹, c₂ * cf⁻¹, c₃ * ce⁻¹ * cf⁻¹, ?_⟩⟩ · simp [hx, mul_smul] · simp [hx, mul_smul, hce₀, hcf₀] /-- The `sl₂` subalgebra associated to a root, regarded as a Lie submodule over the Cartan subalgebra. -/ noncomputable def sl2SubmoduleOfRoot {α : Weight K H L} (hα : α.IsNonZero) : LieSubmodule K H L where __ := sl2SubalgebraOfRoot hα lie_mem {h} x hx := by suffices ⁅(h : L), x⁆ ∈ sl2SubalgebraOfRoot hα by simpa obtain ⟨h', e, f, ht, heα, hfα⟩ := exists_isSl2Triple_of_weight_isNonZero hα replace hx : x ∈ sl2SubalgebraOfRoot hα := hx obtain ⟨c₁, c₂, c₃, rfl⟩ := (mem_sl2SubalgebraOfRoot_iff hα ht heα hfα).mp hx rw [mem_sl2SubalgebraOfRoot_iff hα ht heα hfα, lie_add, lie_add, lie_smul, lie_smul, lie_smul] have he_wt : ⁅(h : L), e⁆ = α h • e := lie_eq_smul_of_mem_rootSpace heα h have hf_wt : ⁅(h : L), f⁆ = (-α) h • f := lie_eq_smul_of_mem_rootSpace hfα h have hef_zero : ⁅(h : L), ⁅e, f⁆⁆ = 0 := by suffices h_coroot_in_zero : ⁅e, f⁆ ∈ rootSpace H (0 : H → K) from lie_eq_smul_of_mem_rootSpace h_coroot_in_zero h ▸ (zero_smul K ⁅e, f⁆) rw [ht.lie_e_f, IsSl2Triple.h_eq_coroot hα ht heα hfα, rootSpace_zero_eq K L H] exact (coroot α).property exact ⟨c₁ * α h, c₂ * (-α h), 0, by simp [he_wt, hf_wt, hef_zero, smul_smul]⟩ /-- The coroot space of `α` viewed as a submodule of the ambient Lie algebra `L`. This represents the image of the coroot space under the inclusion `H ↪ L`. -/ noncomputable abbrev corootSubmodule (α : Weight K H L) : LieSubmodule K H L := LieSubmodule.map H.toLieSubmodule.incl (corootSpace α) open Submodule in lemma sl2SubmoduleOfRoot_eq_sup (α : Weight K H L) (hα : α.IsNonZero) : sl2SubmoduleOfRoot hα = genWeightSpace L α ⊔ genWeightSpace L (-α) ⊔ corootSubmodule α := by ext x obtain ⟨h', e, f, ht, heα, hfα⟩ := exists_isSl2Triple_of_weight_isNonZero hα refine ⟨fun hx ↦ ?_, fun hx ↦ ?_⟩ · replace hx : x ∈ sl2SubalgebraOfRoot hα := hx obtain ⟨c₁, c₂, c₃, rfl⟩ := (mem_sl2SubalgebraOfRoot_iff hα ht heα hfα).mp hx refine add_mem (add_mem ?_ ?_) ?_ · exact mem_sup_left <| mem_sup_left <| smul_mem _ _ heα · exact mem_sup_left <| mem_sup_right <| smul_mem _ _ hfα · suffices ∃ y ∈ corootSpace α, H.subtype y = c₃ • h' from mem_sup_right <| by simpa [ht.lie_e_f, -Subtype.exists] refine ⟨c₃ • coroot α, smul_mem _ _ <| by simp, ?_⟩ rw [IsSl2Triple.h_eq_coroot hα ht heα hfα, map_smul, subtype_apply] · have aux {β : Weight K H L} (hβ : β.IsNonZero) {y g : L} (hy : y ∈ genWeightSpace L β) (hg : g ∈ rootSpace H β) (hg_ne_zero : g ≠ 0) : ∃ c : K, y = c • g := by obtain ⟨c, hc⟩ := (finrank_eq_one_iff_of_nonzero' ⟨g, hg⟩ (by rwa [ne_eq, LieSubmodule.mk_eq_zero])).mp (finrank_rootSpace_eq_one β hβ) ⟨y, hy⟩ exact ⟨c, by simpa using hc.symm⟩ obtain ⟨x_αneg, hx_αneg, x_h, ⟨y, hy_coroot, rfl⟩, rfl⟩ := mem_sup.mp hx obtain ⟨x_pos, hx_pos, x_neg, hx_neg, rfl⟩ := mem_sup.mp hx_αneg obtain ⟨c₁, rfl⟩ := aux hα hx_pos heα ht.e_ne_zero obtain ⟨c₂, rfl⟩ := aux (Weight.IsNonZero.neg hα) hx_neg hfα ht.f_ne_zero obtain ⟨c₃, rfl⟩ : ∃ c₃ : K, c₃ • coroot α = y := by simpa [← mem_span_singleton, ← coe_corootSpace_eq_span_singleton α] change _ ∈ sl2SubalgebraOfRoot hα rw [mem_sl2SubalgebraOfRoot_iff hα ht heα hfα] use c₁, c₂, c₃ simp [ht.lie_e_f, IsSl2Triple.h_eq_coroot hα ht heα hfα, -LieSubmodule.incl_coe] /-- The collection of roots as a `Finset`. -/ noncomputable abbrev _root_.LieSubalgebra.root : Finset (Weight K H L) := {α | α.IsNonZero} lemma restrict_killingForm_eq_sum : (killingForm K L).restrict H = ∑ α ∈ H.root, (α : H →ₗ[K] K).smulRight (α : H →ₗ[K] K) := by rw [restrict_killingForm, traceForm_eq_sum_finrank_nsmul' K H L] refine Finset.sum_congr rfl fun χ hχ ↦ ?_ replace hχ : χ.IsNonZero := by simpa [LieSubalgebra.root] using hχ simp [finrank_rootSpace_eq_one _ hχ] end CharZero end IsKilling end LieAlgebra
.lake/packages/mathlib/Mathlib/Algebra/Lie/Weights/IsSimple.lean
import Mathlib.Algebra.Lie.Weights.RootSystem import Mathlib.LinearAlgebra.RootSystem.Finite.Lemmas /-! # Simple Lie algebras We show the irreducibility of root systems of simple Lie algebras. ## Main definitions * `LieAlgebra.IsKilling.invtSubmoduleToLieIdeal`: constructs a Lie ideal from an invariant submodule of the dual space ## Main results * `LieAlgebra.IsKilling.instIsIrreducible`: the root system of a simple Lie algebra is irreducible -/ namespace LieAlgebra.IsKilling variable {K L : Type*} [Field K] [CharZero K] [LieRing L] [LieAlgebra K L] [FiniteDimensional K L] open LieAlgebra LieModule Module variable {H : LieSubalgebra K L} [H.IsCartanSubalgebra] -- Note that after https://github.com/leanprover-community/mathlib4/issues/10068 (Cartan's criterion) is complete we can omit `[IsKilling K L]` variable [IsKilling K L] [IsTriangularizable K H L] section aux variable (q : Submodule K (Dual K H)) (hq : ∀ i, q ∈ End.invtSubmodule ((rootSystem H).reflection i)) (χ : Weight K H L) (x_χ m_α : L) (hx_χ : x_χ ∈ genWeightSpace L χ) (α : Weight K H L) (hαq : ↑α ∈ q) (hα₀ : α.IsNonZero) section variable (w_plus : χ.toLinear + α.toLinear ≠ 0) (w_minus : χ.toLinear - α.toLinear ≠ 0) (w_chi : χ.toLinear ≠ 0) (m_pos m_neg : L) (y : H) (hy : y ∈ corootSpace α) (h_bracket_sum : ⁅x_χ, m_α⁆ = ⁅x_χ, m_pos⁆ + ⁅x_χ, m_neg⁆ + ⁅x_χ, (y : L)⁆) (h_pos_containment : ⁅x_χ, m_pos⁆ ∈ genWeightSpace L (⇑χ + ⇑α)) (h_neg_containment : ⁅x_χ, m_neg⁆ ∈ genWeightSpace L (⇑χ - ⇑α)) include hx_χ w_plus w_minus w_chi h_bracket_sum h_pos_containment h_neg_containment hαq private theorem chi_in_q_aux (h_chi_in_q : ↑χ ∈ q) : ⁅x_χ, m_α⁆ ∈ ⨆ α : {α : Weight K H L // ↑α ∈ q ∧ α.IsNonZero}, sl2SubmoduleOfRoot α.2.2 := by have h_h_containment : ⁅x_χ, (y : L)⁆ ∈ genWeightSpace L χ := by have h_zero_weight : H.toLieSubmodule.incl y ∈ genWeightSpace L (0 : H → K) := by apply toLieSubmodule_le_rootSpace_zero exact y.property convert lie_mem_genWeightSpace_of_mem_genWeightSpace hx_χ h_zero_weight ext h; simp have h_bracket_decomp : ⁅x_χ, m_α⁆ ∈ genWeightSpace L (χ.toLinear + α.toLinear) ⊔ genWeightSpace L (χ.toLinear - α.toLinear) ⊔ genWeightSpace L χ := by rw [h_bracket_sum] exact add_mem (add_mem (Submodule.mem_sup_left (Submodule.mem_sup_left h_pos_containment)) (Submodule.mem_sup_left (Submodule.mem_sup_right h_neg_containment))) (Submodule.mem_sup_right h_h_containment) let I := ⨆ β : {β : Weight K H L // ↑β ∈ q ∧ β.IsNonZero}, sl2SubmoduleOfRoot β.2.2 have genWeightSpace_le_I (β_lin : H →ₗ[K] K) (hβ_in_q : β_lin ∈ q) (hβ_ne_zero : β_lin ≠ 0) : genWeightSpace L β_lin ≤ I := by by_cases h_trivial : genWeightSpace L β_lin = ⊥ · simp [h_trivial] · let β : Weight K H L := ⟨β_lin, h_trivial⟩ have hβ_nonzero : β.IsNonZero := Weight.coe_toLinear_ne_zero_iff.mp hβ_ne_zero refine le_trans ?_ (le_iSup _ ⟨β, hβ_in_q, hβ_nonzero⟩) rw [sl2SubmoduleOfRoot_eq_sup] exact le_sup_of_le_left (le_sup_of_le_left le_rfl) have h_plus_contain : genWeightSpace L (χ.toLinear + α.toLinear) ≤ I := genWeightSpace_le_I _ (q.add_mem h_chi_in_q hαq) w_plus have h_minus_contain : genWeightSpace L (χ.toLinear - α.toLinear) ≤ I := genWeightSpace_le_I _ (by have : -α.toLinear = (-1 : K) • α.toLinear := by simp rw [sub_eq_add_neg, this] exact q.add_mem h_chi_in_q (q.smul_mem (-1) hαq)) w_minus have h_chi_contain : genWeightSpace L χ.toLinear ≤ I := genWeightSpace_le_I _ h_chi_in_q (fun h_eq => (w_chi h_eq).elim) exact sup_le (sup_le h_plus_contain h_minus_contain) h_chi_contain h_bracket_decomp include hq hα₀ hy private theorem chi_not_in_q_aux (h_chi_not_in_q : ↑χ ∉ q) : ⁅x_χ, m_α⁆ ∈ ⨆ α : {α : Weight K H L // ↑α ∈ q ∧ α.IsNonZero}, sl2SubmoduleOfRoot α.2.2 := by let S := rootSystem H have exists_root_index (γ : Weight K H L) (hγ : γ.IsNonZero) : ∃ i, S.root i = ↑γ := ⟨⟨γ, by simp [LieSubalgebra.root]; exact hγ⟩, rfl⟩ have h_plus_bot : genWeightSpace L (χ.toLinear + α.toLinear) = ⊥ := by by_contra h_plus_ne_bot let γ : Weight K H L := ⟨χ.toLinear + α.toLinear, h_plus_ne_bot⟩ have hγ_nonzero : γ.IsNonZero := Weight.coe_toLinear_ne_zero_iff.mp w_plus obtain ⟨i, hi⟩ := exists_root_index χ (Weight.coe_toLinear_ne_zero_iff.mp w_chi) obtain ⟨j, hj⟩ := exists_root_index α hα₀ have h_sum_in_range : S.root i + S.root j ∈ Set.range S.root := by rw [hi, hj] exact ⟨⟨γ, by simp [LieSubalgebra.root]; exact hγ_nonzero⟩, rfl⟩ have h_equiv := RootPairing.root_mem_submodule_iff_of_add_mem_invtSubmodule ⟨q, by rw [RootPairing.mem_invtRootSubmodule_iff]; exact hq⟩ h_sum_in_range rw [hi] at h_equiv exact h_chi_not_in_q (h_equiv.mpr (by rw [hj]; exact hαq)) have h_minus_bot : genWeightSpace L (χ.toLinear - α.toLinear) = ⊥ := by by_contra h_minus_ne_bot let γ : Weight K H L := ⟨χ.toLinear - α.toLinear, h_minus_ne_bot⟩ have hγ_nonzero : γ.IsNonZero := Weight.coe_toLinear_ne_zero_iff.mp w_minus obtain ⟨i, hi⟩ := exists_root_index χ (Weight.coe_toLinear_ne_zero_iff.mp w_chi) obtain ⟨j, hj⟩ := exists_root_index (-α) (Weight.IsNonZero.neg hα₀) have h_sum_in_range : S.root i + S.root j ∈ Set.range S.root := by rw [hi, hj, Weight.toLinear_neg, ← sub_eq_add_neg] exact ⟨⟨γ, by simp [LieSubalgebra.root]; exact hγ_nonzero⟩, rfl⟩ have h_equiv := RootPairing.root_mem_submodule_iff_of_add_mem_invtSubmodule ⟨q, by rw [RootPairing.mem_invtRootSubmodule_iff]; exact hq⟩ h_sum_in_range rw [hi] at h_equiv exact h_chi_not_in_q (h_equiv.mpr (by rw [hj, Weight.toLinear_neg] convert q.smul_mem (-1) hαq using 1 rw [neg_smul, one_smul])) obtain ⟨i, hi⟩ := exists_root_index χ (Weight.coe_toLinear_ne_zero_iff.mp w_chi) obtain ⟨j, hj⟩ := exists_root_index α hα₀ have h_pairing_zero : S.pairing i j = 0 := by apply RootPairing.pairing_eq_zero_of_add_notMem_of_sub_notMem S.toRootPairing · intro h_eq; exact w_minus (by rw [← hi, ← hj, h_eq, sub_self]) · intro h_eq; exact w_plus (by rw [← hi, ← hj, h_eq, neg_add_cancel]) · intro ⟨idx, hidx⟩ have : genWeightSpace L (S.root idx) ≠ ⊥ := idx.val.genWeightSpace_ne_bot rw [hidx, hi, hj] at this exact this h_plus_bot · intro ⟨idx, hidx⟩ have : genWeightSpace L (S.root idx) ≠ ⊥ := idx.val.genWeightSpace_ne_bot rw [hidx, hi, hj] at this exact this h_minus_bot have h_pos_zero : ⁅x_χ, m_pos⁆ = 0 := by have h_in_bot : ⁅x_χ, m_pos⁆ ∈ (⊥ : LieSubmodule K H L) := by rw [← h_plus_bot] exact h_pos_containment rwa [LieSubmodule.mem_bot] at h_in_bot have h_neg_zero : ⁅x_χ, m_neg⁆ = 0 := by have h_in_bot : ⁅x_χ, m_neg⁆ ∈ (⊥ : LieSubmodule K H L) := by rw [← h_minus_bot] exact h_neg_containment rwa [LieSubmodule.mem_bot] at h_in_bot have h_bracket_zero : ⁅x_χ, (y : L)⁆ = 0 := by have h_chi_coroot_zero : χ (coroot α) = 0 := by have h_pairing_eq : S.pairing i j = i.1 (coroot j.1) := by rw [rootSystem_pairing_apply] rw [h_pairing_zero] at h_pairing_eq have w_eq {w₁ w₂ : Weight K H L} (h : w₁.toLinear = w₂.toLinear) : w₁ = w₂ := by apply Weight.ext; intro x; exact LinearMap.ext_iff.mp h x have hi_val : i.1 = χ := w_eq (by rw [← hi]; rfl) have hj_val : j.1 = α := w_eq (by rw [← hj]; rfl) rw [hi_val, hj_val] at h_pairing_eq exact h_pairing_eq.symm have h_lie_eq_smul : ⁅(y : L), x_χ⁆ = χ y • x_χ := lie_eq_smul_of_mem_rootSpace hx_χ y have h_chi_h_zero : χ y = 0 := by obtain ⟨c, hc⟩ := Submodule.mem_span_singleton.mp <| by rw [← coe_corootSpace_eq_span_singleton α, LieSubmodule.mem_toSubmodule] exact hy rw [← hc, map_smul, h_chi_coroot_zero, smul_zero] have h_bracket_elem : ⁅x_χ, (y : L)⁆ = 0 := by rw [← lie_skew, h_lie_eq_smul, h_chi_h_zero, zero_smul, neg_zero] exact h_bracket_elem rw [h_bracket_sum, h_pos_zero, h_neg_zero, h_bracket_zero] simp only [add_zero, zero_mem] end include hq hx_χ hαq in private theorem invtSubmoduleToLieIdeal_aux (hm_α : m_α ∈ sl2SubmoduleOfRoot hα₀) : ⁅x_χ, m_α⁆ ∈ ⨆ α : {α : Weight K H L // ↑α ∈ q ∧ α.IsNonZero}, sl2SubmoduleOfRoot α.2.2 := by have hm_α_original : m_α ∈ sl2SubmoduleOfRoot hα₀ := hm_α rw [sl2SubmoduleOfRoot_eq_sup] at hm_α obtain ⟨m_αneg, hm_αneg, m_h, hm_h, hm_eq⟩ := Submodule.mem_sup.mp hm_α obtain ⟨m_pos, hm_pos, m_neg, hm_neg, hm_αneg_eq⟩ := Submodule.mem_sup.mp hm_αneg have hm_α_decomp : m_α = m_pos + m_neg + m_h := by rw [← hm_eq, ← hm_αneg_eq] have h_bracket_sum : ⁅x_χ, m_α⁆ = ⁅x_χ, m_pos⁆ + ⁅x_χ, m_neg⁆ + ⁅x_χ, m_h⁆ := by rw [hm_α_decomp, lie_add, lie_add] by_cases w_plus : χ.toLinear + α.toLinear = 0 · apply LieSubmodule.mem_iSup_of_mem ⟨α, hαq, hα₀⟩ have hx_χ_in_sl2 : x_χ ∈ sl2SubalgebraOfRoot hα₀ := by obtain ⟨h, e, f, ht, he, hf⟩ := exists_isSl2Triple_of_weight_isNonZero hα₀ rw [mem_sl2SubalgebraOfRoot_iff hα₀ ht he hf] have hx_χ_neg : x_χ ∈ genWeightSpace L (-α.toLinear) := by rw [← (add_eq_zero_iff_eq_neg.mp w_plus)] exact hx_χ obtain ⟨c, hc⟩ := (finrank_eq_one_iff_of_nonzero' ⟨f, hf⟩ (by simp [ht.f_ne_zero])).mp (finrank_rootSpace_eq_one (-α) (by simpa using hα₀)) ⟨x_χ, hx_χ_neg⟩ exact ⟨0, c, 0, by simpa using hc.symm⟩ apply LieSubalgebra.lie_mem <;> [exact hx_χ_in_sl2; exact hm_α_original] by_cases w_minus : χ.toLinear - α.toLinear = 0 · apply LieSubmodule.mem_iSup_of_mem ⟨α, hαq, hα₀⟩ have hx_χ_in_sl2 : x_χ ∈ sl2SubalgebraOfRoot hα₀ := by obtain ⟨h, e, f, ht, he, hf⟩ := exists_isSl2Triple_of_weight_isNonZero hα₀ rw [mem_sl2SubalgebraOfRoot_iff hα₀ ht he hf] have hx_χ_pos : x_χ ∈ genWeightSpace L α.toLinear := by rw [← (sub_eq_zero.mp w_minus)] exact hx_χ obtain ⟨c, hc⟩ := (finrank_eq_one_iff_of_nonzero' ⟨e, he⟩ (by simp [ht.e_ne_zero])).mp (finrank_rootSpace_eq_one α hα₀) ⟨x_χ, hx_χ_pos⟩ exact ⟨c, 0, 0, by simpa using hc.symm⟩ apply LieSubalgebra.lie_mem <;> [exact hx_χ_in_sl2; exact hm_α_original] by_cases w_chi : χ.toLinear = 0 · have hx_χ_in_H : x_χ ∈ H.toLieSubmodule := by rw [← rootSpace_zero_eq K L H] convert hx_χ; ext h; simp only [Pi.zero_apply] have h_apply : (χ.toLinear : H → K) h = 0 := by rw [w_chi, LinearMap.zero_apply] exact h_apply.symm apply LieSubmodule.mem_iSup_of_mem ⟨α, hαq, hα₀⟩ rw [← (by rfl : ⁅(⟨x_χ, hx_χ_in_H⟩ : H), m_α⁆ = ⁅x_χ, m_α⁆)] exact (sl2SubmoduleOfRoot hα₀).lie_mem hm_α_original have h_pos_containment : ⁅x_χ, m_pos⁆ ∈ genWeightSpace L (χ.toLinear + α.toLinear) := lie_mem_genWeightSpace_of_mem_genWeightSpace hx_χ hm_pos have h_neg_containment : ⁅x_χ, m_neg⁆ ∈ genWeightSpace L (χ.toLinear - α.toLinear) := by rw [sub_eq_add_neg]; exact lie_mem_genWeightSpace_of_mem_genWeightSpace hx_χ hm_neg obtain ⟨y, hy, rfl⟩ := hm_h by_cases h_chi_in_q : ↑χ ∈ q · exact chi_in_q_aux q χ x_χ m_α hx_χ α hαq w_plus w_minus w_chi m_pos m_neg y h_bracket_sum h_pos_containment h_neg_containment h_chi_in_q · exact chi_not_in_q_aux q hq χ x_χ m_α hx_χ α hαq hα₀ w_plus w_minus w_chi m_pos m_neg y hy h_bracket_sum h_pos_containment h_neg_containment h_chi_in_q end aux /-- Constructs a Lie ideal from an invariant submodule of the dual space of a Cartan subalgebra. Given a submodule `q` of the dual space `Dual K H` that is invariant under all root reflections, this produces a Lie ideal by taking the sum of all `sl₂` subalgebras corresponding to roots whose linear forms lie in `q`. -/ noncomputable def invtSubmoduleToLieIdeal (q : Submodule K (Dual K H)) (hq : ∀ i, q ∈ End.invtSubmodule ((rootSystem H).reflection i)) : LieIdeal K L where __ := ⨆ α : {α : Weight K H L // ↑α ∈ q ∧ α.IsNonZero}, sl2SubmoduleOfRoot α.2.2 lie_mem := by intro x m hm have hx : x ∈ ⨆ χ : Weight K H L, genWeightSpace L χ := by simp [LieModule.iSup_genWeightSpace_eq_top'] induction hx using LieSubmodule.iSup_induction' with | mem χ x_χ hx_χ => induction hm using LieSubmodule.iSup_induction' with | mem α m_α hm_α => exact invtSubmoduleToLieIdeal_aux q hq χ x_χ m_α hx_χ α.1 α.2.1 α.2.2 hm_α | zero => simp only [ Submodule.carrier_eq_coe, lie_zero, SetLike.mem_coe, zero_mem] | add m₁ m₂ _ _ ih₁ ih₂ => simp only [lie_add, Submodule.carrier_eq_coe, SetLike.mem_coe] at ih₁ ih₂ ⊢ exact add_mem ih₁ ih₂ | zero => simp only [Submodule.carrier_eq_coe, zero_lie, SetLike.mem_coe, zero_mem] | add x₁ x₂ _ _ ih₁ ih₂ => simp only [add_lie, Submodule.carrier_eq_coe, SetLike.mem_coe] at ih₁ ih₂ ⊢ exact add_mem ih₁ ih₂ section IsSimple variable [IsSimple K L] -- TODO Golf the below proof using `LieAlgebra.IsKilling.invtSubmoduleToLieIdeal` above open Weight in lemma eq_top_of_invtSubmodule_ne_bot (q : Submodule K (Dual K H)) (h₀ : ∀ (i : H.root), q ∈ End.invtSubmodule ((rootSystem H).reflection i)) (h₁ : q ≠ ⊥) : q = ⊤ := by have _i := nontrivial_of_isIrreducible K L L let S := rootSystem H by_contra h₃ suffices h₂ : ∀ Φ, Φ.Nonempty → S.root '' Φ ⊆ q → (∀ i ∉ Φ, q ≤ LinearMap.ker (S.coroot' i)) → Φ = Set.univ by have := (S.eq_top_of_mem_invtSubmodule_of_forall_eq_univ q h₁ h₀) h₂ apply False.elim (h₃ this) intro Φ hΦ₁ hΦ₂ hΦ₃ by_contra hc have hΦ₂' : ∀ i ∈ Φ, (S.root i) ∈ q := by intro i hi apply hΦ₂ exact Set.mem_image_of_mem S.root hi have s₁ (i j : H.root) (h₁ : i ∈ Φ) (h₂ : j ∉ Φ) : S.root i (S.coroot j) = 0 := (hΦ₃ j h₂) (hΦ₂' i h₁) have s₁' (i j : H.root) (h₁ : i ∈ Φ) (h₂ : j ∉ Φ) : S.root j (S.coroot i) = 0 := (S.pairing_eq_zero_iff (i := i) (j := j)).1 (s₁ i j h₁ h₂) have s₂ (i j : H.root) (h₁ : i ∈ Φ) (h₂ : j ∉ Φ) : i.1 (coroot j) = 0 := s₁ i j h₁ h₂ have s₂' (i j : H.root) (h₁ : i ∈ Φ) (h₂ : j ∉ Φ) : j.1 (coroot i) = 0 := s₁' i j h₁ h₂ have s₃ (i j : H.root) (h₁ : i ∈ Φ) (h₂ : j ∉ Φ) : genWeightSpace L (i.1.1 + j.1.1) = ⊥ := by by_contra h have i_non_zero : i.1.IsNonZero := by grind have j_non_zero : j.1.IsNonZero := by grind let r := Weight.mk (R := K) (L := H) (M := L) (i.1.1 + j.1.1) h have r₁ : r ≠ 0 := by intro a have h_eq : i.1 = -j.1 := Weight.ext <| congrFun (eq_neg_of_add_eq_zero_left (congr_arg Weight.toFun a)) have := s₂ i j h₁ h₂ rw [h_eq, coe_neg, Pi.neg_apply, root_apply_coroot j_non_zero] at this simp at this have r₂ : r ∈ H.root := by simp [isNonZero_iff_ne_zero, r₁] cases Classical.em (⟨r, r₂⟩ ∈ Φ) with | inl hl => have e₁ : i.1.1 (coroot j) = 0 := s₂ i j h₁ h₂ have e₂ : j.1.1 (coroot j) = 2 := root_apply_coroot j_non_zero have : (0 : K) = 2 := calc 0 = (i.1.1 + j.1.1) (coroot j) := (s₂ ⟨r, r₂⟩ j hl h₂).symm _ = i.1.1 (coroot j) + j.1.1 (coroot j) := rfl _ = 2 := by rw [e₁, e₂, zero_add] simp at this | inr hr => have e₁ : j.1.1 (coroot i) = 0 := s₂' i j h₁ h₂ have e₂ : i.1.1 (coroot i) = 2 := root_apply_coroot i_non_zero have : (0 : K) = 2 := calc 0 = (i.1.1 + j.1.1) (coroot i) := (s₂' i ⟨r, r₂⟩ h₁ hr).symm _ = i.1.1 (coroot i) + j.1.1 (coroot i) := rfl _ = 2 := by rw [e₁, e₂, add_zero] simp at this have s₄ (i j : H.root) (h1 : i ∈ Φ) (h2 : j ∉ Φ) (li : rootSpace H i.1.1) (lj : rootSpace H j.1.1) : ⁅li.1, lj.1⁆ = 0 := by have h₃ := lie_mem_genWeightSpace_of_mem_genWeightSpace li.2 lj.2 rw [s₃ i j h1 h2] at h₃ exact h₃ let g := ⋃ i ∈ Φ, (rootSpace H i : Set L) let I := LieSubalgebra.lieSpan K L g have s₅ : I ≠ ⊤ := by obtain ⟨j, hj⟩ := (Set.ne_univ_iff_exists_notMem Φ).mp hc obtain ⟨z, hz₁, hz₂⟩ := exists_ne_zero (R := K) (L := H) (M := L) j by_contra! hI have center_element : z ∈ center K L := by have commutes_with_all (x : L) : ⁅x, z⁆ = 0 := by have x_mem_I : x ∈ I := by rw [hI]; exact trivial induction x_mem_I using LieSubalgebra.lieSpan_induction with | mem x hx => obtain ⟨i, hi, hx1_mem⟩ := Set.mem_iUnion₂.mp hx have := s₄ i j hi hj simp only [Subtype.forall] at this exact (this x hx1_mem) z hz₁ | zero => exact zero_lie z | add _ _ _ _ e f => rw [add_lie, e, f, add_zero] | smul _ _ _ d => simp only [smul_lie, smul_eq_zero] right exact d | lie _ _ _ _ e f => rw [lie_lie, e, f, lie_zero, lie_zero, sub_self] exact commutes_with_all rw [center_eq_bot] at center_element exact hz₂ center_element have s₆ : I ≠ ⊥ := by obtain ⟨r, hr⟩ := Set.nonempty_def.mp hΦ₁ obtain ⟨x, hx₁, hx₂⟩ := exists_ne_zero (R := K) (L := H) (M := L) r have x_in_g : x ∈ g := by apply Set.mem_iUnion_of_mem r simp only [Set.mem_iUnion] exact ⟨hr, hx₁⟩ have x_mem_I : x ∈ I := LieSubalgebra.mem_lieSpan.mpr (fun _ a ↦ a x_in_g) by_contra h exact hx₂ (I.eq_bot_iff.mp h x x_mem_I) have s₇ : ∀ x y : L, y ∈ I → ⁅x, y⁆ ∈ I := by have gen : ⨆ χ : Weight K H L, (genWeightSpace L χ).toSubmodule = ⊤ := by simp only [LieSubmodule.iSup_toSubmodule_eq_top] exact iSup_genWeightSpace_eq_top' K H L intro x y hy have hx : x ∈ ⨆ χ : Weight K H L, (genWeightSpace L χ).toSubmodule := by simp only [gen, Submodule.mem_top] induction hx using Submodule.iSup_induction' with | mem j x hx => induction hy using LieSubalgebra.lieSpan_induction with | mem x₁ hx₁ => obtain ⟨i, hi, x₁_mem⟩ := Set.mem_iUnion₂.mp hx₁ have r₁ (j : Weight K H L) : j = 0 ∨ j ∈ H.root := by rcases (eq_or_ne j 0) with h | h · left exact h · right refine Finset.mem_filter.mpr ?_ exact ⟨Finset.mem_univ j, isNonZero_iff_ne_zero.mpr h⟩ rcases (r₁ j) with h | h · have h₁ : ⁅x, x₁⁆ ∈ g := by have h₂ := lie_mem_genWeightSpace_of_mem_genWeightSpace hx x₁_mem rw [h, coe_zero, zero_add] at h₂ exact Set.mem_biUnion hi h₂ exact LieSubalgebra.mem_lieSpan.mpr fun _ a ↦ a h₁ rcases (Classical.em (⟨j, h⟩ ∈ Φ)) with h₁ | h₁ · exact I.lie_mem (LieSubalgebra.mem_lieSpan.mpr fun _ a ↦ a (Set.mem_biUnion h₁ hx)) (LieSubalgebra.mem_lieSpan.mpr fun _ a ↦ a hx₁) have : ⁅x, x₁⁆ = 0 := by rw [← neg_eq_zero, lie_skew x₁ x, (s₄ i ⟨j, h⟩ hi h₁ ⟨x₁, x₁_mem⟩ ⟨x, hx⟩)] rw [this] exact I.zero_mem | zero => simp only [lie_zero, zero_mem, I] | add _ _ _ _ e f => simp only [lie_add] exact add_mem e f | smul a _ _ d => simp only [lie_smul] exact I.smul_mem a d | lie a b c d e f => have : ⁅x, ⁅a, b⁆⁆ = ⁅⁅x, a⁆, b⁆ + ⁅a, ⁅x, b⁆⁆ := by simp only [lie_lie, sub_add_cancel] rw [this] exact add_mem (I.lie_mem e d) (I.lie_mem c f) | zero => simp only [zero_lie, zero_mem] | add x1 y1 _ _ hx hy => simp only [add_lie] exact add_mem hx hy obtain ⟨I', h⟩ := (LieSubalgebra.exists_lieIdeal_coe_eq_iff (K := I)).2 s₇ have : IsSimple K L := inferInstance have : I' = ⊥ ∨ I' = ⊤ := this.eq_bot_or_eq_top I' have c₁ : I' ≠ ⊤ := by rw [← h] at s₅ exact ne_of_apply_ne (LieIdeal.toLieSubalgebra K L) s₅ have c₂ : I' ≠ ⊥ := by rw [← h] at s₆ exact ne_of_apply_ne (LieIdeal.toLieSubalgebra K L) s₆ grind instance : (rootSystem H).IsIrreducible := by have _i := nontrivial_of_isIrreducible K L L exact RootPairing.IsIrreducible.mk' (rootSystem H).toRootPairing <| eq_top_of_invtSubmodule_ne_bot end IsSimple end LieAlgebra.IsKilling
.lake/packages/mathlib/Mathlib/Algebra/AddConstMap/Basic.lean
import Mathlib.Algebra.Group.Action.Pi import Mathlib.Algebra.Group.End import Mathlib.Algebra.Module.NatInt import Mathlib.Algebra.Order.Archimedean.Basic /-! # Maps (semi)conjugating a shift to a shift Denote by $S^1$ the unit circle `UnitAddCircle`. A common way to study a self-map $f\colon S^1\to S^1$ of degree `1` is to lift it to a map $\tilde f\colon \mathbb R\to \mathbb R$ such that $\tilde f(x + 1) = \tilde f(x)+1$ for all `x`. In this file we define a structure and a typeclass for bundled maps satisfying `f (x + a) = f x + b`. We use parameters `a` and `b` instead of `1` to accommodate for two use cases: - maps between circles of different lengths; - self-maps $f\colon S^1\to S^1$ of degree other than one, including orientation-reversing maps. -/ assert_not_exists Finset open Function Set /-- A bundled map `f : G → H` such that `f (x + a) = f x + b` for all `x`, denoted as `f: G →+c[a, b] H`. One can think about `f` as a lift to `G` of a map between two `AddCircle`s. -/ structure AddConstMap (G H : Type*) [Add G] [Add H] (a : G) (b : H) where /-- The underlying function of an `AddConstMap`. Use automatic coercion to function instead. -/ protected toFun : G → H /-- An `AddConstMap` satisfies `f (x + a) = f x + b`. Use `map_add_const` instead. -/ map_add_const' (x : G) : toFun (x + a) = toFun x + b @[inherit_doc] scoped [AddConstMap] notation:25 G " →+c[" a ", " b "] " H => AddConstMap G H a b /-- Typeclass for maps satisfying `f (x + a) = f x + b`. Note that `a` and `b` are `outParam`s, so one should not add instances like `[AddConstMapClass F G H a b] : AddConstMapClass F G H (-a) (-b)`. -/ class AddConstMapClass (F : Type*) (G H : outParam Type*) [Add G] [Add H] (a : outParam G) (b : outParam H) [FunLike F G H] : Prop where /-- A map of `AddConstMapClass` class semiconjugates shift by `a` to the shift by `b`: `∀ x, f (x + a) = f x + b`. -/ map_add_const (f : F) (x : G) : f (x + a) = f x + b namespace AddConstMapClass /-! ### Properties of `AddConstMapClass` maps In this section we prove properties like `f (x + n • a) = f x + n • b`. -/ scoped [AddConstMapClass] attribute [simp] map_add_const variable {F G H : Type*} [FunLike F G H] {a : G} {b : H} protected theorem semiconj [Add G] [Add H] [AddConstMapClass F G H a b] (f : F) : Semiconj f (· + a) (· + b) := map_add_const f @[scoped simp] theorem map_add_nsmul [AddMonoid G] [AddMonoid H] [AddConstMapClass F G H a b] (f : F) (x : G) (n : ℕ) : f (x + n • a) = f x + n • b := by simpa using (AddConstMapClass.semiconj f).iterate_right n x @[scoped simp] theorem map_add_nat' [AddMonoidWithOne G] [AddMonoid H] [AddConstMapClass F G H 1 b] (f : F) (x : G) (n : ℕ) : f (x + n) = f x + n • b := by simp [← map_add_nsmul] theorem map_add_one [AddMonoidWithOne G] [Add H] [AddConstMapClass F G H 1 b] (f : F) (x : G) : f (x + 1) = f x + b := map_add_const f x @[scoped simp] theorem map_add_ofNat' [AddMonoidWithOne G] [AddMonoid H] [AddConstMapClass F G H 1 b] (f : F) (x : G) (n : ℕ) [n.AtLeastTwo] : f (x + ofNat(n)) = f x + (ofNat(n) : ℕ) • b := map_add_nat' f x n theorem map_add_nat [AddMonoidWithOne G] [AddMonoidWithOne H] [AddConstMapClass F G H 1 1] (f : F) (x : G) (n : ℕ) : f (x + n) = f x + n := by simp theorem map_add_ofNat [AddMonoidWithOne G] [AddMonoidWithOne H] [AddConstMapClass F G H 1 1] (f : F) (x : G) (n : ℕ) [n.AtLeastTwo] : f (x + ofNat(n)) = f x + ofNat(n) := map_add_nat f x n @[scoped simp] theorem map_const [AddZeroClass G] [Add H] [AddConstMapClass F G H a b] (f : F) : f a = f 0 + b := by simpa using map_add_const f 0 theorem map_one [AddZeroClass G] [One G] [Add H] [AddConstMapClass F G H 1 b] (f : F) : f 1 = f 0 + b := map_const f @[scoped simp] theorem map_nsmul_const [AddMonoid G] [AddMonoid H] [AddConstMapClass F G H a b] (f : F) (n : ℕ) : f (n • a) = f 0 + n • b := by simpa using map_add_nsmul f 0 n @[scoped simp] theorem map_nat' [AddMonoidWithOne G] [AddMonoid H] [AddConstMapClass F G H 1 b] (f : F) (n : ℕ) : f n = f 0 + n • b := by simpa using map_add_nat' f 0 n theorem map_ofNat' [AddMonoidWithOne G] [AddMonoid H] [AddConstMapClass F G H 1 b] (f : F) (n : ℕ) [n.AtLeastTwo] : f (ofNat(n)) = f 0 + (ofNat(n) : ℕ) • b := map_nat' f n theorem map_nat [AddMonoidWithOne G] [AddMonoidWithOne H] [AddConstMapClass F G H 1 1] (f : F) (n : ℕ) : f n = f 0 + n := by simp theorem map_ofNat [AddMonoidWithOne G] [AddMonoidWithOne H] [AddConstMapClass F G H 1 1] (f : F) (n : ℕ) [n.AtLeastTwo] : f ofNat(n) = f 0 + ofNat(n) := map_nat f n @[scoped simp] theorem map_const_add [AddCommMagma G] [Add H] [AddConstMapClass F G H a b] (f : F) (x : G) : f (a + x) = f x + b := by rw [add_comm, map_add_const] theorem map_one_add [AddCommMonoidWithOne G] [Add H] [AddConstMapClass F G H 1 b] (f : F) (x : G) : f (1 + x) = f x + b := map_const_add f x @[scoped simp] theorem map_nsmul_add [AddCommMonoid G] [AddMonoid H] [AddConstMapClass F G H a b] (f : F) (n : ℕ) (x : G) : f (n • a + x) = f x + n • b := by rw [add_comm, map_add_nsmul] @[scoped simp] theorem map_nat_add' [AddCommMonoidWithOne G] [AddMonoid H] [AddConstMapClass F G H 1 b] (f : F) (n : ℕ) (x : G) : f (↑n + x) = f x + n • b := by simpa using map_nsmul_add f n x theorem map_ofNat_add' [AddCommMonoidWithOne G] [AddMonoid H] [AddConstMapClass F G H 1 b] (f : F) (n : ℕ) [n.AtLeastTwo] (x : G) : f (ofNat(n) + x) = f x + ofNat(n) • b := map_nat_add' f n x theorem map_nat_add [AddCommMonoidWithOne G] [AddMonoidWithOne H] [AddConstMapClass F G H 1 1] (f : F) (n : ℕ) (x : G) : f (↑n + x) = f x + n := by simp theorem map_ofNat_add [AddCommMonoidWithOne G] [AddMonoidWithOne H] [AddConstMapClass F G H 1 1] (f : F) (n : ℕ) [n.AtLeastTwo] (x : G) : f (ofNat(n) + x) = f x + ofNat(n) := map_nat_add f n x @[scoped simp] theorem map_sub_nsmul [AddGroup G] [AddGroup H] [AddConstMapClass F G H a b] (f : F) (x : G) (n : ℕ) : f (x - n • a) = f x - n • b := by conv_rhs => rw [← sub_add_cancel x (n • a), map_add_nsmul, add_sub_cancel_right] @[scoped simp] theorem map_sub_const [AddGroup G] [AddGroup H] [AddConstMapClass F G H a b] (f : F) (x : G) : f (x - a) = f x - b := by simpa using map_sub_nsmul f x 1 theorem map_sub_one [AddGroup G] [One G] [AddGroup H] [AddConstMapClass F G H 1 b] (f : F) (x : G) : f (x - 1) = f x - b := map_sub_const f x @[scoped simp] theorem map_sub_nat' [AddGroupWithOne G] [AddGroup H] [AddConstMapClass F G H 1 b] (f : F) (x : G) (n : ℕ) : f (x - n) = f x - n • b := by simpa using map_sub_nsmul f x n @[scoped simp] theorem map_sub_ofNat' [AddGroupWithOne G] [AddGroup H] [AddConstMapClass F G H 1 b] (f : F) (x : G) (n : ℕ) [n.AtLeastTwo] : f (x - ofNat(n)) = f x - ofNat(n) • b := map_sub_nat' f x n @[scoped simp] theorem map_add_zsmul [AddGroup G] [AddGroup H] [AddConstMapClass F G H a b] (f : F) (x : G) : ∀ n : ℤ, f (x + n • a) = f x + n • b | (n : ℕ) => by simp | .negSucc n => by simp [← sub_eq_add_neg] @[scoped simp] theorem map_zsmul_const [AddGroup G] [AddGroup H] [AddConstMapClass F G H a b] (f : F) (n : ℤ) : f (n • a) = f 0 + n • b := by simpa using map_add_zsmul f 0 n @[scoped simp] theorem map_add_int' [AddGroupWithOne G] [AddGroup H] [AddConstMapClass F G H 1 b] (f : F) (x : G) (n : ℤ) : f (x + n) = f x + n • b := by rw [← map_add_zsmul f x n, zsmul_one] theorem map_add_int [AddGroupWithOne G] [AddGroupWithOne H] [AddConstMapClass F G H 1 1] (f : F) (x : G) (n : ℤ) : f (x + n) = f x + n := by simp @[scoped simp] theorem map_sub_zsmul [AddGroup G] [AddGroup H] [AddConstMapClass F G H a b] (f : F) (x : G) (n : ℤ) : f (x - n • a) = f x - n • b := by simpa [sub_eq_add_neg] using map_add_zsmul f x (-n) @[scoped simp] theorem map_sub_int' [AddGroupWithOne G] [AddGroup H] [AddConstMapClass F G H 1 b] (f : F) (x : G) (n : ℤ) : f (x - n) = f x - n • b := by rw [← map_sub_zsmul, zsmul_one] theorem map_sub_int [AddGroupWithOne G] [AddGroupWithOne H] [AddConstMapClass F G H 1 1] (f : F) (x : G) (n : ℤ) : f (x - n) = f x - n := by simp @[scoped simp] theorem map_zsmul_add [AddCommGroup G] [AddGroup H] [AddConstMapClass F G H a b] (f : F) (n : ℤ) (x : G) : f (n • a + x) = f x + n • b := by rw [add_comm, map_add_zsmul] @[scoped simp] theorem map_int_add' [AddCommGroupWithOne G] [AddGroup H] [AddConstMapClass F G H 1 b] (f : F) (n : ℤ) (x : G) : f (↑n + x) = f x + n • b := by rw [← map_zsmul_add, zsmul_one] theorem map_int_add [AddCommGroupWithOne G] [AddGroupWithOne H] [AddConstMapClass F G H 1 1] (f : F) (n : ℤ) (x : G) : f (↑n + x) = f x + n := by simp theorem map_fract {R : Type*} [Ring R] [LinearOrder R] [FloorRing R] [AddGroup H] [FunLike F R H] [AddConstMapClass F R H 1 b] (f : F) (x : R) : f (Int.fract x) = f x - ⌊x⌋ • b := map_sub_int' .. open scoped Relator in /-- Auxiliary lemmas for the "monotonicity on a fundamental interval implies monotonicity" lemmas. We formulate it for any relation so that the proof works both for `Monotone` and `StrictMono`. -/ protected theorem rel_map_of_Icc [AddCommGroup G] [LinearOrder G] [IsOrderedAddMonoid G] [Archimedean G] [AddGroup H] [AddConstMapClass F G H a b] {f : F} {R : H → H → Prop} [IsTrans H R] [hR : CovariantClass H H (fun x y ↦ y + x) R] (ha : 0 < a) {l : G} (hf : ∀ x ∈ Icc l (l + a), ∀ y ∈ Icc l (l + a), x < y → R (f x) (f y)) : ((· < ·) ⇒ R) f f := fun x y hxy ↦ by replace hR := hR.elim have ha' : 0 ≤ a := ha.le -- Shift both points by `m • a` so that `l ≤ x < l + a` wlog hx : x ∈ Ico l (l + a) generalizing x y · rcases existsUnique_sub_zsmul_mem_Ico ha x l with ⟨m, hm, -⟩ suffices R (f (x - m • a)) (f (y - m • a)) by simpa using hR (m • b) this exact this _ _ (by simpa) hm · -- Now find `n` such that `l + n • a < y ≤ l + (n + 1) • a` rcases existsUnique_sub_zsmul_mem_Ioc ha y l with ⟨n, hny, -⟩ rcases lt_trichotomy n 0 with hn | rfl | hn · -- Since `l ≤ x ≤ y`, the case `n < 0` is impossible refine absurd ?_ hxy.not_ge calc y ≤ l + a + n • a := sub_le_iff_le_add.1 hny.2 _ = l + (n + 1) • a := by rw [add_comm n, add_smul, one_smul, add_assoc] _ ≤ l + (0 : ℤ) • a := by gcongr; cutsat _ ≤ x := by simpa using hx.1 · -- If `n = 0`, then `l < y ≤ l + a`, hence we can apply the assumption exact hf x (Ico_subset_Icc_self hx) y (by simpa using Ioc_subset_Icc_self hny) hxy · -- In the remaining case `0 < n` we use transitivity. -- If `R = (· < ·)`, then the proof looks like -- `f x < f (l + a) ≤ f (l + n • a) < f y` trans f (l + (1 : ℤ) • a) · grind have hy : R (f (l + n • a)) (f y) := by rw [← sub_add_cancel y (n • a), map_add_zsmul, map_add_zsmul] refine hR _ <| hf _ ?_ _ (Ioc_subset_Icc_self hny) hny.1; simpa rw [← Int.add_one_le_iff, zero_add] at hn rcases hn.eq_or_lt with rfl | hn; · assumption trans f (l + n • a) · refine Int.rel_of_forall_rel_succ_of_lt R (f := (f <| l + · • a)) (fun k ↦ ?_) hn simp_rw [add_comm k 1, add_zsmul, ← add_assoc, one_zsmul, map_add_zsmul] refine hR (k • b) (hf _ ?_ _ ?_ ?_) <;> simpa · assumption theorem monotone_iff_Icc [AddCommGroup G] [LinearOrder G] [IsOrderedAddMonoid G] [Archimedean G] [AddCommGroup H] [PartialOrder H] [IsOrderedAddMonoid H] [AddConstMapClass F G H a b] {f : F} (ha : 0 < a) (l : G) : Monotone f ↔ MonotoneOn f (Icc l (l + a)) := ⟨(Monotone.monotoneOn · _), fun hf ↦ monotone_iff_forall_lt.2 <| AddConstMapClass.rel_map_of_Icc ha fun _x hx _y hy hxy ↦ hf hx hy hxy.le⟩ theorem antitone_iff_Icc [AddCommGroup G] [LinearOrder G] [IsOrderedAddMonoid G] [Archimedean G] [AddCommGroup H] [PartialOrder H] [IsOrderedAddMonoid H] [AddConstMapClass F G H a b] {f : F} (ha : 0 < a) (l : G) : Antitone f ↔ AntitoneOn f (Icc l (l + a)) := monotone_iff_Icc (H := Hᵒᵈ) ha l theorem strictMono_iff_Icc [AddCommGroup G] [LinearOrder G] [IsOrderedAddMonoid G] [Archimedean G] [AddCommGroup H] [PartialOrder H] [IsOrderedAddMonoid H] [AddConstMapClass F G H a b] {f : F} (ha : 0 < a) (l : G) : StrictMono f ↔ StrictMonoOn f (Icc l (l + a)) := ⟨(StrictMono.strictMonoOn · _), AddConstMapClass.rel_map_of_Icc ha⟩ theorem strictAnti_iff_Icc [AddCommGroup G] [LinearOrder G] [IsOrderedAddMonoid G] [Archimedean G] [AddCommGroup H] [PartialOrder H] [IsOrderedAddMonoid H] [AddConstMapClass F G H a b] {f : F} (ha : 0 < a) (l : G) : StrictAnti f ↔ StrictAntiOn f (Icc l (l + a)) := strictMono_iff_Icc (H := Hᵒᵈ) ha l end AddConstMapClass open AddConstMapClass namespace AddConstMap section Add variable {G H : Type*} [Add G] [Add H] {a : G} {b : H} /-! ### Coercion to function -/ instance : FunLike (G →+c[a, b] H) G H where coe := AddConstMap.toFun coe_injective' | ⟨_, _⟩, ⟨_, _⟩, rfl => rfl @[simp, push_cast] theorem coe_mk (f : G → H) (hf) : ⇑(mk f hf : G →+c[a, b] H) = f := rfl @[simp] theorem mk_coe (f : G →+c[a, b] H) : mk f f.2 = f := rfl @[simp] theorem toFun_eq_coe (f : G →+c[a, b] H) : f.toFun = f := rfl instance : AddConstMapClass (G →+c[a, b] H) G H a b where map_add_const f := f.map_add_const' @[ext] protected theorem ext {f g : G →+c[a, b] H} (h : ∀ x, f x = g x) : f = g := DFunLike.ext _ _ h initialize_simps_projections AddConstMap (toFun → coe, as_prefix coe) /-! ### Constructions about `G →+c[a, b] H` -/ /-- The identity map as `G →+c[a, a] G`. -/ @[simps -fullyApplied] protected def id : G →+c[a, a] G := ⟨id, fun _ ↦ rfl⟩ instance : Inhabited (G →+c[a, a] G) := ⟨.id⟩ /-- Composition of two `AddConstMap`s. -/ @[simps -fullyApplied] def comp {K : Type*} [Add K] {c : K} (g : H →+c[b, c] K) (f : G →+c[a, b] H) : G →+c[a, c] K := ⟨g ∘ f, by simp⟩ @[simp] theorem comp_id (f : G →+c[a, b] H) : f.comp .id = f := rfl @[simp] theorem id_comp (f : G →+c[a, b] H) : .comp .id f = f := rfl /-- Change constants `a` and `b` in `(f : G →+c[a, b] H)` to improve definitional equalities. -/ @[simps -fullyApplied] def replaceConsts (f : G →+c[a, b] H) (a' b') (ha : a = a') (hb : b = b') : G →+c[a', b'] H where toFun := f map_add_const' := ha ▸ hb ▸ f.map_add_const' /-! ### Additive action on `G →+c[a, b] H` -/ /-- If `f` is an `AddConstMap`, then so is `(c +ᵥ f ·)`. -/ instance {K : Type*} [VAdd K H] [VAddAssocClass K H H] : VAdd K (G →+c[a, b] H) := ⟨fun c f ↦ ⟨c +ᵥ ⇑f, fun x ↦ by simp [vadd_add_assoc]⟩⟩ @[simp, norm_cast] theorem coe_vadd {K : Type*} [VAdd K H] [VAddAssocClass K H H] (c : K) (f : G →+c[a, b] H) : ⇑(c +ᵥ f) = c +ᵥ ⇑f := rfl instance {K : Type*} [AddMonoid K] [AddAction K H] [VAddAssocClass K H H] : AddAction K (G →+c[a, b] H) := DFunLike.coe_injective.addAction _ coe_vadd /-! ### Monoid structure on endomorphisms `G →+c[a, a] G` -/ instance : Mul (G →+c[a, a] G) := ⟨comp⟩ instance : One (G →+c[a, a] G) := ⟨.id⟩ instance : Pow (G →+c[a, a] G) ℕ where pow f n := ⟨f^[n], Commute.iterate_left (AddConstMapClass.semiconj f) _⟩ instance : Monoid (G →+c[a, a] G) := DFunLike.coe_injective.monoid (M₂ := Function.End G) _ rfl (fun _ _ ↦ rfl) fun _ _ ↦ rfl theorem mul_def (f g : G →+c[a, a] G) : f * g = f.comp g := rfl @[simp, push_cast] theorem coe_mul (f g : G →+c[a, a] G) : ⇑(f * g) = f ∘ g := rfl theorem one_def : (1 : G →+c[a, a] G) = .id := rfl @[simp, push_cast] theorem coe_one : ⇑(1 : G →+c[a, a] G) = id := rfl @[simp, push_cast] theorem coe_pow (f : G →+c[a, a] G) (n : ℕ) : ⇑(f ^ n) = f^[n] := rfl theorem pow_apply (f : G →+c[a, a] G) (n : ℕ) (x : G) : (f ^ n) x = f^[n] x := rfl /-- Coercion to functions as a monoid homomorphism to `Function.End G`. -/ @[simps -fullyApplied] def toEnd : (G →+c[a, a] G) →* Function.End G where toFun := DFunLike.coe map_mul' _ _ := rfl map_one' := rfl end Add section AddZeroClass variable {G H K : Type*} [Add G] [AddZeroClass H] {a : G} {b : H} /-! ### Multiplicative action on `(b : H) × (G →+c[a, b] H)` If `K` acts distributively on `H`, then for each `f : G →+c[a, b] H` we define `(AddConstMap.smul c f : G →+c[a, c • b] H)`. One can show that this defines a multiplicative action of `K` on `(b : H) × (G →+c[a, b] H)` but we don't do this at the moment because we don't need this. -/ /-- Pointwise scalar multiplication of `f : G →+c[a, b] H` as a map `G →+c[a, c • b] H`. -/ @[simps -fullyApplied] def smul [DistribSMul K H] (c : K) (f : G →+c[a, b] H) : G →+c[a, c • b] H where toFun := c • ⇑f map_add_const' x := by simp [smul_add] end AddZeroClass section AddMonoid variable {G : Type*} [AddMonoid G] {a : G} /-- The map that sends `c` to a translation by `c` as a monoid homomorphism from `Multiplicative G` to `G →+c[a, a] G`. -/ @[simps! -fullyApplied] def addLeftHom : Multiplicative G →* (G →+c[a, a] G) where toFun c := c.toAdd +ᵥ .id map_one' := by ext; apply zero_add map_mul' _ _ := by ext; apply add_assoc end AddMonoid section AddCommGroup variable {G H : Type*} [AddCommGroup G] [AddCommGroup H] {a : G} {b : H} /-- If `f : G → H` is an `AddConstMap`, then so is `fun x ↦ -f (-x)`. -/ @[simps! apply_coe] def conjNeg : (G →+c[a, b] H) ≃ (G →+c[a, b] H) := Involutive.toPerm (fun f ↦ ⟨fun x ↦ - f (-x), fun _ ↦ by simp [neg_add_eq_sub]⟩) fun _ ↦ AddConstMap.ext fun _ ↦ by simp @[simp] theorem conjNeg_symm : (conjNeg (a := a) (b := b)).symm = conjNeg := rfl end AddCommGroup section FloorRing variable {R G : Type*} [Ring R] [LinearOrder R] [IsStrictOrderedRing R] [FloorRing R] [AddGroup G] (a : G) /-- A map `f : R →+c[1, a] G` is defined by its values on `Set.Ico 0 1`. -/ def mkFract : (Ico (0 : R) 1 → G) ≃ (R →+c[1, a] G) where toFun f := ⟨fun x ↦ f ⟨Int.fract x, Int.fract_nonneg _, Int.fract_lt_one _⟩ + ⌊x⌋ • a, fun x ↦ by simp [add_one_zsmul, add_assoc]⟩ invFun f x := f x left_inv _ := by ext x; simp [Int.fract_eq_self.2 x.2, Int.floor_eq_zero_iff.2 x.2] right_inv f := by ext x; simp [map_fract] end FloorRing end AddConstMap
.lake/packages/mathlib/Mathlib/Algebra/AddConstMap/Equiv.lean
import Mathlib.Algebra.AddConstMap.Basic /-! # Equivalences conjugating `(· + a)` to `(· + b)` In this file we define `AddConstEquiv G H a b` (notation: `G ≃+c[a, b] H`) to be the type of equivalences such that `∀ x, f (x + a) = f x + b`. We also define the corresponding typeclass and prove some basic properties. -/ assert_not_exists Finset open Function open scoped AddConstMap /-- An equivalence between `G` and `H` conjugating `(· + a)` to `(· + b)`, denoted as `G ≃+c[a, b] H`. -/ structure AddConstEquiv (G H : Type*) [Add G] [Add H] (a : G) (b : H) extends G ≃ H, G →+c[a, b] H /-- Interpret an `AddConstEquiv` as an `Equiv`. -/ add_decl_doc AddConstEquiv.toEquiv /-- Interpret an `AddConstEquiv` as an `AddConstMap`. -/ add_decl_doc AddConstEquiv.toAddConstMap @[inherit_doc] scoped[AddConstMap] notation:25 G " ≃+c[" a ", " b "] " H => AddConstEquiv G H a b namespace AddConstEquiv variable {G H K : Type*} [Add G] [Add H] [Add K] {a : G} {b : H} {c : K} lemma toEquiv_injective : Injective (toEquiv : (G ≃+c[a, b] H) → G ≃ H) | ⟨_, _⟩, ⟨_, _⟩, rfl => rfl instance {G H : Type*} [Add G] [Add H] {a : G} {b : H} : EquivLike (G ≃+c[a, b] H) G H where coe f := f.toEquiv inv f := f.toEquiv.symm left_inv f := f.left_inv right_inv f := f.right_inv coe_injective' _ _ h _ := toEquiv_injective <| DFunLike.ext' h instance {G H : Type*} [Add G] [Add H] {a : G} {b : H} : AddConstMapClass (G ≃+c[a, b] H) G H a b where map_add_const f x := f.map_add_const' x @[ext] lemma ext {e₁ e₂ : G ≃+c[a, b] H} (h : ∀ x, e₁ x = e₂ x) : e₁ = e₂ := DFunLike.ext _ _ h @[simp] lemma toEquiv_inj {e₁ e₂ : G ≃+c[a, b] H} : e₁.toEquiv = e₂.toEquiv ↔ e₁ = e₂ := toEquiv_injective.eq_iff @[simp] lemma coe_toEquiv (e : G ≃+c[a, b] H) : ⇑e.toEquiv = e := rfl /-- Inverse map of an `AddConstEquiv`, as an `AddConstEquiv`. -/ def symm (e : G ≃+c[a, b] H) : H ≃+c[b, a] G where toEquiv := e.toEquiv.symm map_add_const' := (AddConstMapClass.semiconj e).inverse_left e.left_inv e.right_inv /-- A custom projection for `simps`. -/ def Simps.symm_apply (e : G ≃+c[a, b] H) : H → G := e.symm initialize_simps_projections AddConstEquiv (toFun → apply, invFun → symm_apply) @[simp] lemma symm_symm (e : G ≃+c[a, b] H) : e.symm.symm = e := rfl /-- The identity map as an `AddConstEquiv`. -/ @[simps! toEquiv apply] def refl (a : G) : G ≃+c[a, a] G where toEquiv := .refl G map_add_const' _ := rfl @[simp] lemma symm_refl (a : G) : (refl a).symm = refl a := rfl /-- Composition of `AddConstEquiv`s, as an `AddConstEquiv`. -/ @[simps! +simpRhs toEquiv apply] def trans (e₁ : G ≃+c[a, b] H) (e₂ : H ≃+c[b, c] K) : G ≃+c[a, c] K where toEquiv := e₁.toEquiv.trans e₂.toEquiv map_add_const' := (AddConstMapClass.semiconj e₁).trans (AddConstMapClass.semiconj e₂) @[simp] lemma trans_refl (e : G ≃+c[a, b] H) : e.trans (.refl b) = e := rfl @[simp] lemma refl_trans (e : G ≃+c[a, b] H) : (refl a).trans e = e := rfl @[simp] lemma self_trans_symm (e : G ≃+c[a, b] H) : e.trans e.symm = .refl a := toEquiv_injective e.toEquiv.self_trans_symm @[simp] lemma symm_trans_self (e : G ≃+c[a, b] H) : e.symm.trans e = .refl b := toEquiv_injective e.toEquiv.symm_trans_self @[simp] lemma coe_symm_toEquiv (e : G ≃+c[a, b] H) : ⇑e.toEquiv.symm = e.symm := rfl @[simp] lemma toEquiv_symm (e : G ≃+c[a, b] H) : e.symm.toEquiv = e.toEquiv.symm := rfl @[simp] lemma toEquiv_trans (e₁ : G ≃+c[a, b] H) (e₂ : H ≃+c[b, c] K) : (e₁.trans e₂).toEquiv = e₁.toEquiv.trans e₂.toEquiv := rfl instance instOne : One (G ≃+c[a, a] G) := ⟨.refl _⟩ instance instMul : Mul (G ≃+c[a, a] G) := ⟨fun f g ↦ g.trans f⟩ instance instInv : Inv (G ≃+c[a, a] G) := ⟨.symm⟩ instance instDiv : Div (G ≃+c[a, a] G) := ⟨fun f g ↦ f * g⁻¹⟩ instance instPowNat : Pow (G ≃+c[a, a] G) ℕ where pow e n := ⟨e^n, (e.toAddConstMap^n).map_add_const'⟩ instance instPowInt : Pow (G ≃+c[a, a] G) ℤ where pow e n := ⟨e^n, match n with | .ofNat n => (e^n).map_add_const' | .negSucc n => (e.symm^(n + 1)).map_add_const'⟩ instance instGroup : Group (G ≃+c[a, a] G) := toEquiv_injective.group _ rfl (fun _ _ ↦ rfl) (fun _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ _ ↦ rfl) fun _ _ ↦ rfl /-- Projection from `G ≃+c[a, a] G` to permutations `G ≃ G`, as a monoid homomorphism. -/ @[simps! apply] def toPerm : (G ≃+c[a, a] G) →* Equiv.Perm G := .mk' toEquiv fun _ _ ↦ rfl /-- Projection from `G ≃+c[a, a] G` to `G →+c[a, a] G`, as a monoid homomorphism. -/ @[simps! apply] def toAddConstMapHom : (G ≃+c[a, a] G) →* (G →+c[a, a] G) where toFun := toAddConstMap map_mul' _ _ := rfl map_one' := rfl /-- Group equivalence between `G ≃+c[a, a] G` and the units of `G →+c[a, a] G`. -/ @[simps!] def equivUnits : (G ≃+c[a, a] G) ≃* (G →+c[a, a] G)ˣ where toFun := toAddConstMapHom.toHomUnits invFun u := { toEquiv := Equiv.Perm.equivUnitsEnd.symm <| Units.map AddConstMap.toEnd u map_add_const' := u.1.2 } map_mul' _ _ := rfl end AddConstEquiv
.lake/packages/mathlib/Mathlib/Algebra/Colimit/Module.lean
import Mathlib.Algebra.Colimit.DirectLimit import Mathlib.Algebra.DirectSum.Module import Mathlib.Algebra.Module.Congruence.Defs import Mathlib.Data.Finset.Order import Mathlib.Tactic.SuppressCompilation /-! # Direct limit of modules and abelian groups See Atiyah-Macdonald PP.32-33, Matsumura PP.269-270 Generalizes the notion of "union", or "gluing", of incomparable modules over the same ring, or incomparable abelian groups. It is constructed as a quotient of the free module instead of a quotient of the disjoint union so as to make the operations (addition etc.) "computable". ## Main definitions * `Module.DirectLimit G f` * `AddCommGroup.DirectLimit G f` -/ suppress_compilation variable {R : Type*} [Semiring R] {ι : Type*} [Preorder ι] {G : ι → Type*} open Submodule namespace Module alias DirectedSystem.map_self := DirectedSystem.map_self' alias DirectedSystem.map_map := DirectedSystem.map_map' variable [DecidableEq ι] variable [∀ i, AddCommMonoid (G i)] [∀ i, Module R (G i)] (f : ∀ i j, i ≤ j → G i →ₗ[R] G j) /-- The relation on the direct sum that generates the additive congruence that defines the colimit as a quotient. -/ inductive DirectLimit.Eqv : DirectSum ι G → DirectSum ι G → Prop | of_map {i j} (h : i ≤ j) (x : G i) : Eqv (DirectSum.lof R ι G i x) (DirectSum.lof R ι G j <| f i j h x) /-- The congruence relation to quotient the direct sum by to obtain the direct limit. -/ def DirectLimit.moduleCon [DecidableEq ι] : ModuleCon R (DirectSum ι G) := SMulCon.addConGen' (Eqv f) <| by rintro _ _ _ ⟨⟩; simpa only [← map_smul] using .of_map .. variable (G) /-- The direct limit of a directed system is the modules glued together along the maps. -/ def DirectLimit [DecidableEq ι] : Type _ := (DirectLimit.moduleCon f).Quotient namespace DirectLimit section Basic instance addCommMonoid : AddCommMonoid (DirectLimit G f) := inferInstanceAs (AddCommMonoid (moduleCon f).Quotient) instance module : Module R (DirectLimit G f) := inferInstanceAs (Module R (moduleCon f).Quotient) instance addCommGroup (G : ι → Type*) [∀ i, AddCommGroup (G i)] [∀ i, Module R (G i)] (f : ∀ i j, i ≤ j → G i →ₗ[R] G j) : AddCommGroup (DirectLimit G f) := inferInstanceAs (AddCommGroup (moduleCon f).Quotient) instance inhabited : Inhabited (DirectLimit G f) := ⟨0⟩ instance unique [IsEmpty ι] : Unique (DirectLimit G f) := inferInstanceAs <| Unique (Quotient _) variable (R ι) /-- The canonical map from a component to the direct limit. -/ def of (i) : G i →ₗ[R] DirectLimit G f := .comp { __ := AddCon.mk' _, map_smul' := fun _ _ ↦ rfl } <| DirectSum.lof R ι G i variable {R ι G f} theorem quotMk_of (i x) : Quot.mk _ (.of G i x) = of R ι G f i x := rfl @[simp] theorem of_f {i j hij x} : of R ι G f j (f i j hij x) = of R ι G f i x := (AddCon.eq _).mpr <| .symm <| .of _ _ (.of_map _ _) /-- Every element of the direct limit corresponds to some element in some component of the directed system. -/ theorem exists_of [Nonempty ι] [IsDirected ι (· ≤ ·)] (z : DirectLimit G f) : ∃ i x, of R ι G f i x = z := Nonempty.elim (by infer_instance) fun ind : ι ↦ Quotient.inductionOn' z fun z ↦ DirectSum.induction_on z ⟨ind, 0, LinearMap.map_zero _⟩ (fun i x ↦ ⟨i, x, rfl⟩) fun p q ⟨i, x, ihx⟩ ⟨j, y, ihy⟩ ↦ let ⟨k, hik, hjk⟩ := exists_ge_ge i j ⟨k, f i k hik x + f j k hjk y, by rw [LinearMap.map_add, of_f, of_f, ihx, ihy] rfl ⟩ theorem exists_of₂ [Nonempty ι] [IsDirected ι (· ≤ ·)] (z w : DirectLimit G f) : ∃ i x y, of R ι G f i x = z ∧ of R ι G f i y = w := have ⟨i, x, hx⟩ := exists_of z have ⟨j, y, hy⟩ := exists_of w have ⟨k, hik, hjk⟩ := exists_ge_ge i j ⟨k, f i k hik x, f j k hjk y, by rw [of_f, hx], by rw [of_f, hy]⟩ @[elab_as_elim] protected theorem induction_on [Nonempty ι] [IsDirected ι (· ≤ ·)] {C : DirectLimit G f → Prop} (z : DirectLimit G f) (ih : ∀ i x, C (of R ι G f i x)) : C z := let ⟨i, x, h⟩ := exists_of z h ▸ ih i x variable {P : Type*} [AddCommMonoid P] [Module R P] variable (R ι G f) in /-- The universal property of the direct limit: maps from the components to another module that respect the directed system structure (i.e. make some diagram commute) give rise to a unique map out of the direct limit. -/ def lift (g : ∀ i, G i →ₗ[R] P) (Hg : ∀ i j hij x, g j (f i j hij x) = g i x) : DirectLimit G f →ₗ[R] P where __ := AddCon.lift _ (DirectSum.toModule R ι P g) <| AddCon.addConGen_le fun _ _ ⟨_, _⟩ ↦ by simpa using (Hg _ _ _ _).symm map_smul' r := by rintro ⟨x⟩; exact map_smul (DirectSum.toModule R ι P g) r x variable (g : ∀ i, G i →ₗ[R] P) (Hg : ∀ i j hij x, g j (f i j hij x) = g i x) @[simp] theorem lift_of {i} (x) : lift R ι G f g Hg (of R ι G f i x) = g i x := DirectSum.toModule_lof R _ _ @[ext] theorem hom_ext {g₁ g₂ : DirectLimit G f →ₗ[R] P} (h : ∀ i, g₁ ∘ₗ of R ι G f i = g₂ ∘ₗ of R ι G f i) : g₁ = g₂ := LinearMap.toAddMonoidHom_injective <| AddCon.hom_ext <| DirectSum.addHom_ext' fun i => congr($(h i).toAddMonoidHom) @[simp] theorem lift_comp_of (F : DirectLimit G f →ₗ[R] P) : lift R ι G f (fun i ↦ F.comp <| of R ι G f i) (fun i j hij x ↦ by simp) = F := by ext; simp @[deprecated lift_comp_of (since := "2025-08-11")] theorem lift_unique (F : DirectLimit G f →ₗ[R] P) (x) : F x = lift R ι G f (fun i ↦ F.comp <| of R ι G f i) (fun i j hij x ↦ by simp) x := by rw [lift_comp_of] @[simp] theorem lift_of' : lift R ι G f (of R ι G f) (fun i j hij x ↦ by simp) = .id := by ext; simp lemma lift_injective [IsDirected ι (· ≤ ·)] (injective : ∀ i, Function.Injective <| g i) : Function.Injective (lift R ι G f g Hg) := by cases isEmpty_or_nonempty ι · apply Function.injective_of_subsingleton intro z w eq obtain ⟨i, x, y, rfl, rfl⟩ := exists_of₂ z w simp_rw [lift_of] at eq rw [injective _ eq] section functorial variable {G' : ι → Type*} [∀ i, AddCommMonoid (G' i)] [∀ i, Module R (G' i)] variable {f' : ∀ i j, i ≤ j → G' i →ₗ[R] G' j} variable {G'' : ι → Type*} [∀ i, AddCommMonoid (G'' i)] [∀ i, Module R (G'' i)] variable {f'' : ∀ i j, i ≤ j → G'' i →ₗ[R] G'' j} /-- Consider direct limits `lim G` and `lim G'` with direct system `f` and `f'` respectively, any family of linear maps `gᵢ : Gᵢ ⟶ G'ᵢ` such that `g ∘ f = f' ∘ g` induces a linear map `lim G ⟶ lim G'`. -/ def map (g : (i : ι) → G i →ₗ[R] G' i) (hg : ∀ i j h, g j ∘ₗ f i j h = f' i j h ∘ₗ g i) : DirectLimit G f →ₗ[R] DirectLimit G' f' := lift _ _ _ _ (fun i ↦ of _ _ _ _ _ ∘ₗ g i) fun i j h g ↦ by have eq1 := LinearMap.congr_fun (hg i j h) g simp only [LinearMap.coe_comp, Function.comp_apply] at eq1 ⊢ rw [eq1, of_f] @[simp] lemma map_apply_of (g : (i : ι) → G i →ₗ[R] G' i) (hg : ∀ i j h, g j ∘ₗ f i j h = f' i j h ∘ₗ g i) {i : ι} (x : G i) : map g hg (of _ _ G f _ x) = of R ι G' f' i (g i x) := lift_of _ _ _ @[simp] lemma map_id : map (fun _ ↦ LinearMap.id) (fun _ _ _ ↦ rfl) = LinearMap.id (M := DirectLimit G f) := by ext; simp lemma map_comp (g₁ : (i : ι) → G i →ₗ[R] G' i) (g₂ : (i : ι) → G' i →ₗ[R] G'' i) (hg₁ : ∀ i j h, g₁ j ∘ₗ f i j h = f' i j h ∘ₗ g₁ i) (hg₂ : ∀ i j h, g₂ j ∘ₗ f' i j h = f'' i j h ∘ₗ g₂ i) : (map g₂ hg₂ ∘ₗ map g₁ hg₁ : DirectLimit G f →ₗ[R] DirectLimit G'' f'') = (map (fun i ↦ g₂ i ∘ₗ g₁ i) fun i j h ↦ by rw [LinearMap.comp_assoc, hg₁ i, ← LinearMap.comp_assoc, hg₂ i, LinearMap.comp_assoc] : DirectLimit G f →ₗ[R] DirectLimit G'' f'') := by ext; simp open LinearEquiv LinearMap in /-- Consider direct limits `lim G` and `lim G'` with direct system `f` and `f'` respectively, any family of equivalences `eᵢ : Gᵢ ≅ G'ᵢ` such that `e ∘ f = f' ∘ e` induces an equivalence `lim G ≅ lim G'`. -/ def congr (e : (i : ι) → G i ≃ₗ[R] G' i) (he : ∀ i j h, e j ∘ₗ f i j h = f' i j h ∘ₗ e i) : DirectLimit G f ≃ₗ[R] DirectLimit G' f' := LinearEquiv.ofLinear (map (e ·) he) (map (fun i ↦ (e i).symm) fun i j h ↦ by rw [toLinearMap_symm_comp_eq, ← comp_assoc, he i, comp_assoc, comp_coe, symm_trans_self, refl_toLinearMap, comp_id]) (by simp [map_comp]) (by simp [map_comp]) lemma congr_apply_of (e : (i : ι) → G i ≃ₗ[R] G' i) (he : ∀ i j h, e j ∘ₗ f i j h = f' i j h ∘ₗ e i) {i : ι} (g : G i) : congr e he (of _ _ G f i g) = of _ _ G' f' i (e i g) := map_apply_of _ he _ open LinearEquiv LinearMap in lemma congr_symm_apply_of (e : (i : ι) → G i ≃ₗ[R] G' i) (he : ∀ i j h, e j ∘ₗ f i j h = f' i j h ∘ₗ e i) {i : ι} (g : G' i) : (congr e he).symm (of _ _ G' f' i g) = of _ _ G f i ((e i).symm g) := map_apply_of _ (fun i j h ↦ by rw [toLinearMap_symm_comp_eq, ← comp_assoc, he i, comp_assoc, comp_coe, symm_trans_self, refl_toLinearMap, comp_id]) _ end functorial end Basic section equiv variable [Nonempty ι] [IsDirected ι (· ≤ ·)] [DirectedSystem G (f · · ·)] open _root_.DirectLimit /-- The direct limit constructed as a quotient of the direct sum is isomorphic to the direct limit constructed as a quotient of the disjoint union. -/ def linearEquiv : DirectLimit G f ≃ₗ[R] _root_.DirectLimit G f := .ofLinear (lift _ _ _ _ (Module.of _ _ _ _) fun _ _ _ _ ↦ .symm <| eq_of_le ..) (Module.lift _ _ _ _ (of _ _ _ _) fun _ _ _ _ ↦ of_f ..) (by ext; simp) (by ext; simp) theorem linearEquiv_of {i g} : linearEquiv _ _ (of _ _ G f i g) = ⟦⟨i, g⟩⟧ := by simp [linearEquiv]; rfl theorem linearEquiv_symm_mk {g} : (linearEquiv _ _).symm ⟦g⟧ = of _ _ G f g.1 g.2 := rfl end equiv variable {G f} [DirectedSystem G (f · · ·)] [IsDirected ι (· ≤ ·)] theorem exists_eq_of_of_eq {i x y} (h : of R ι G f i x = of R ι G f i y) : ∃ j hij, f i j hij x = f i j hij y := by have := Nonempty.intro i apply_fun linearEquiv _ _ at h simp_rw [linearEquiv_of] at h have ⟨j, h⟩ := Quotient.exact h exact ⟨j, h.1, h.2.2⟩ /-- A component that corresponds to zero in the direct limit is already zero in some bigger module in the directed system. -/ theorem of.zero_exact {i x} (H : of R ι G f i x = 0) : ∃ j hij, f i j hij x = (0 : G j) := by convert exists_eq_of_of_eq (H.trans (map_zero <| _).symm) rw [map_zero] end DirectLimit end Module namespace AddCommGroup variable (G) [∀ i, AddCommMonoid (G i)] /-- The direct limit of a directed system is the abelian groups glued together along the maps. -/ def DirectLimit [DecidableEq ι] (f : ∀ i j, i ≤ j → G i →+ G j) : Type _ := @Module.DirectLimit ℕ _ ι _ G _ _ (fun i j hij ↦ (f i j hij).toNatLinearMap) _ namespace DirectLimit variable (f : ∀ i j, i ≤ j → G i →+ G j) local instance directedSystem [h : DirectedSystem G fun i j h ↦ f i j h] : DirectedSystem G fun i j hij ↦ (f i j hij).toNatLinearMap := h variable [DecidableEq ι] instance : AddCommMonoid (DirectLimit G f) := Module.DirectLimit.addCommMonoid G fun i j hij ↦ (f i j hij).toNatLinearMap instance addCommGroup (G : ι → Type*) [∀ i, AddCommGroup (G i)] (f : ∀ i j, i ≤ j → G i →+ G j) : AddCommGroup (DirectLimit G f) := Module.DirectLimit.addCommGroup G fun i j hij ↦ (f i j hij).toNatLinearMap instance : Inhabited (DirectLimit G f) := ⟨0⟩ instance [IsEmpty ι] : Unique (DirectLimit G f) := Module.DirectLimit.unique _ _ /-- The canonical map from a component to the direct limit. -/ def of (i) : G i →+ DirectLimit G f := (Module.DirectLimit.of ℕ ι G _ i).toAddMonoidHom variable {G f} @[simp] theorem of_f {i j} (hij) (x) : of G f j (f i j hij x) = of G f i x := Module.DirectLimit.of_f @[elab_as_elim] protected theorem induction_on [Nonempty ι] [IsDirected ι (· ≤ ·)] {C : DirectLimit G f → Prop} (z : DirectLimit G f) (ih : ∀ i x, C (of G f i x)) : C z := Module.DirectLimit.induction_on z ih /-- A component that corresponds to zero in the direct limit is already zero in some bigger module in the directed system. -/ theorem of.zero_exact [IsDirected ι (· ≤ ·)] [DirectedSystem G fun i j h ↦ f i j h] (i x) (h : of G f i x = 0) : ∃ j hij, f i j hij x = 0 := Module.DirectLimit.of.zero_exact h variable (P : Type*) [AddCommMonoid P] variable (g : ∀ i, G i →+ P) variable (Hg : ∀ i j hij x, g j (f i j hij x) = g i x) variable (G f) /-- The universal property of the direct limit: maps from the components to another abelian group that respect the directed system structure (i.e. make some diagram commute) give rise to a unique map out of the direct limit. -/ def lift : DirectLimit G f →+ P := (Module.DirectLimit.lift ℕ ι G (fun i j hij ↦ (f i j hij).toNatLinearMap) (fun i ↦ (g i).toNatLinearMap) Hg).toAddMonoidHom variable {G f} @[simp] theorem lift_of (i x) : lift G f P g Hg (of G f i x) = g i x := Module.DirectLimit.lift_of -- Note: had to make these arguments explicit https://github.com/leanprover-community/mathlib4/pull/8386 (f := fun i j hij ↦ (f i j hij).toNatLinearMap) (fun i ↦ (g i).toNatLinearMap) Hg x @[ext] theorem hom_ext {g₁ g₂ : DirectLimit G f →+ P} (h : ∀ i, g₁.comp (of G f i) = g₂.comp (of G f i)) : g₁ = g₂ := AddCon.hom_ext <| DirectSum.addHom_ext' h @[simp] theorem lift_comp_of (F : DirectLimit G f →+ P) : lift G f _ (fun i ↦ F.comp <| of G f i) (fun i j hij x ↦ by simp) = F := by ext; simp @[deprecated lift_comp_of (since := "2025-08-11")] theorem lift_unique (F : DirectLimit G f →+ P) (x) : F x = lift G f P (fun i ↦ F.comp (of G f i)) (fun i j hij x ↦ by simp) x := by rw [lift_comp_of] @[simp] theorem lift_of' : lift G f _ (of G f) (fun i j hij x ↦ by simp) = .id _ := by ext; simp lemma lift_injective [IsDirected ι (· ≤ ·)] (injective : ∀ i, Function.Injective <| g i) : Function.Injective (lift G f P g Hg) := Module.DirectLimit.lift_injective (f := fun i j hij ↦ (f i j hij).toNatLinearMap) _ Hg injective section functorial variable {G' : ι → Type*} [∀ i, AddCommMonoid (G' i)] variable {f' : ∀ i j, i ≤ j → G' i →+ G' j} variable {G'' : ι → Type*} [∀ i, AddCommMonoid (G'' i)] variable {f'' : ∀ i j, i ≤ j → G'' i →+ G'' j} /-- Consider direct limits `lim G` and `lim G'` with direct system `f` and `f'` respectively, any family of group homomorphisms `gᵢ : Gᵢ ⟶ G'ᵢ` such that `g ∘ f = f' ∘ g` induces a group homomorphism `lim G ⟶ lim G'`. -/ def map (g : (i : ι) → G i →+ G' i) (hg : ∀ i j h, (g j).comp (f i j h) = (f' i j h).comp (g i)) : DirectLimit G f →+ DirectLimit G' f' := lift _ _ _ (fun i ↦ (of _ _ _).comp (g i)) fun i j h g ↦ by have eq1 := DFunLike.congr_fun (hg i j h) g simp only [AddMonoidHom.coe_comp, Function.comp_apply] at eq1 ⊢ rw [eq1, of_f] @[simp] lemma map_apply_of (g : (i : ι) → G i →+ G' i) (hg : ∀ i j h, (g j).comp (f i j h) = (f' i j h).comp (g i)) {i : ι} (x : G i) : map g hg (of G f _ x) = of G' f' i (g i x) := lift_of _ _ _ _ _ @[simp] lemma map_id : map (fun _ ↦ AddMonoidHom.id _) (fun _ _ _ ↦ rfl) = AddMonoidHom.id (DirectLimit G f) := by ext; simp lemma map_comp (g₁ : (i : ι) → G i →+ G' i) (g₂ : (i : ι) → G' i →+ G'' i) (hg₁ : ∀ i j h, (g₁ j).comp (f i j h) = (f' i j h).comp (g₁ i)) (hg₂ : ∀ i j h, (g₂ j).comp (f' i j h) = (f'' i j h).comp (g₂ i)) : ((map g₂ hg₂).comp (map g₁ hg₁) : DirectLimit G f →+ DirectLimit G'' f'') = (map (fun i ↦ (g₂ i).comp (g₁ i)) fun i j h ↦ by rw [AddMonoidHom.comp_assoc, hg₁ i, ← AddMonoidHom.comp_assoc, hg₂ i, AddMonoidHom.comp_assoc] : DirectLimit G f →+ DirectLimit G'' f'') := by ext; simp /-- Consider direct limits `lim G` and `lim G'` with direct system `f` and `f'` respectively, any family of equivalences `eᵢ : Gᵢ ≅ G'ᵢ` such that `e ∘ f = f' ∘ e` induces an equivalence `lim G ⟶ lim G'`. -/ def congr (e : (i : ι) → G i ≃+ G' i) (he : ∀ i j h, (e j).toAddMonoidHom.comp (f i j h) = (f' i j h).comp (e i)) : DirectLimit G f ≃+ DirectLimit G' f' := AddMonoidHom.toAddEquiv (map (e ·) he) (map (fun i ↦ (e i).symm) fun i j h ↦ DFunLike.ext _ _ fun x ↦ by have eq1 := DFunLike.congr_fun (he i j h) ((e i).symm x) simp only [AddMonoidHom.coe_comp, AddEquiv.coe_toAddMonoidHom, Function.comp_apply, AddMonoidHom.coe_coe, AddEquiv.apply_symm_apply] at eq1 ⊢ simp [← eq1]) (by simp [map_comp]) (by simp [map_comp]) lemma congr_apply_of (e : (i : ι) → G i ≃+ G' i) (he : ∀ i j h, (e j).toAddMonoidHom.comp (f i j h) = (f' i j h).comp (e i)) {i : ι} (g : G i) : congr e he (of G f i g) = of G' f' i (e i g) := map_apply_of _ he _ lemma congr_symm_apply_of (e : (i : ι) → G i ≃+ G' i) (he : ∀ i j h, (e j).toAddMonoidHom.comp (f i j h) = (f' i j h).comp (e i)) {i : ι} (g : G' i) : (congr e he).symm (of G' f' i g) = of G f i ((e i).symm g) := by simp only [congr, AddMonoidHom.toAddEquiv_symm_apply, map_apply_of, AddMonoidHom.coe_coe] end functorial end DirectLimit end AddCommGroup
.lake/packages/mathlib/Mathlib/Algebra/Colimit/Ring.lean
import Mathlib.Algebra.Colimit.DirectLimit import Mathlib.Data.Finset.Order import Mathlib.RingTheory.FreeCommRing import Mathlib.RingTheory.Ideal.Maps import Mathlib.RingTheory.Ideal.Quotient.Defs import Mathlib.Tactic.SuppressCompilation /-! # Direct limit of rings, and fields See Atiyah-Macdonald PP.32-33, Matsumura PP.269-270 Generalizes the notion of "union", or "gluing", of incomparable rings or fields. It is constructed as a quotient of the free commutative ring instead of a quotient of the disjoint union so as to make the operations (addition etc.) "computable". ## Main definition * `Ring.DirectLimit G f` -/ assert_not_exists Cardinal suppress_compilation variable {ι : Type*} [Preorder ι] (G : ι → Type*) open Submodule namespace Ring variable [∀ i, CommRing (G i)] section variable (f : ∀ i j, i ≤ j → G i → G j) open FreeCommRing /-- The direct limit of a directed system is the ring obtained by gluing the components along the maps. -/ def DirectLimit : Type _ := FreeCommRing (Σ i, G i) ⧸ Ideal.span { a | (∃ i j H x, of (⟨j, f i j H x⟩ : Σ i, G i) - of ⟨i, x⟩ = a) ∨ (∃ i, of (⟨i, 1⟩ : Σ i, G i) - 1 = a) ∨ (∃ i x y, of (⟨i, x + y⟩ : Σ i, G i) - (of ⟨i, x⟩ + of ⟨i, y⟩) = a) ∨ ∃ i x y, of (⟨i, x * y⟩ : Σ i, G i) - of ⟨i, x⟩ * of ⟨i, y⟩ = a } namespace DirectLimit instance commRing : CommRing (DirectLimit G f) := Ideal.Quotient.commRing _ instance ring : Ring (DirectLimit G f) := CommRing.toRing -- Porting note: Added a `Zero` instance to get rid of `0` errors. instance zero : Zero (DirectLimit G f) := by unfold DirectLimit exact ⟨0⟩ instance : Inhabited (DirectLimit G f) := ⟨0⟩ /-- The canonical map from a component to the direct limit. -/ nonrec def of (i) : G i →+* DirectLimit G f := RingHom.mk' { toFun := fun x ↦ Ideal.Quotient.mk _ (of (⟨i, x⟩ : Σ i, G i)) map_one' := Ideal.Quotient.eq.2 <| subset_span <| Or.inr <| Or.inl ⟨i, rfl⟩ map_mul' := fun x y ↦ Ideal.Quotient.eq.2 <| subset_span <| Or.inr <| Or.inr <| Or.inr ⟨i, x, y, rfl⟩ } fun x y ↦ Ideal.Quotient.eq.2 <| subset_span <| Or.inr <| Or.inr <| Or.inl ⟨i, x, y, rfl⟩ variable {G f} theorem quotientMk_of (i x) : Ideal.Quotient.mk _ (.of ⟨i, x⟩) = of G f i x := rfl @[simp] theorem of_f {i j} (hij) (x) : of G f j (f i j hij x) = of G f i x := Ideal.Quotient.eq.2 <| subset_span <| Or.inl ⟨i, j, hij, x, rfl⟩ /-- Every element of the direct limit corresponds to some element in some component of the directed system. -/ theorem exists_of [Nonempty ι] [IsDirected ι (· ≤ ·)] (z : DirectLimit G f) : ∃ i x, of G f i x = z := by obtain ⟨z, rfl⟩ := Ideal.Quotient.mk_surjective z refine z.induction_on ⟨Classical.arbitrary ι, -1, by simp⟩ (fun ⟨i, x⟩ ↦ ⟨i, x, rfl⟩) ?_ ?_ <;> rintro x' y' ⟨i, x, hx⟩ ⟨j, y, hy⟩ <;> have ⟨k, hik, hjk⟩ := exists_ge_ge i j · exact ⟨k, f i k hik x + f j k hjk y, by rw [map_add, of_f, of_f, hx, hy]; rfl⟩ · exact ⟨k, f i k hik x * f j k hjk y, by rw [map_mul, of_f, of_f, hx, hy]; rfl⟩ section open Polynomial variable {f' : ∀ i j, i ≤ j → G i →+* G j} nonrec theorem Polynomial.exists_of [Nonempty ι] [IsDirected ι (· ≤ ·)] (q : Polynomial (DirectLimit G fun i j h ↦ f' i j h)) : ∃ i p, Polynomial.map (of G (fun i j h ↦ f' i j h) i) p = q := Polynomial.induction_on q (fun z ↦ let ⟨i, x, h⟩ := exists_of z ⟨i, C x, by rw [map_C, h]⟩) (fun q₁ q₂ ⟨i₁, p₁, ih₁⟩ ⟨i₂, p₂, ih₂⟩ ↦ let ⟨i, h1, h2⟩ := exists_ge_ge i₁ i₂ ⟨i, p₁.map (f' i₁ i h1) + p₂.map (f' i₂ i h2), by rw [Polynomial.map_add, map_map, map_map, ← ih₁, ← ih₂] congr 2 <;> ext x <;> simp_rw [RingHom.comp_apply, of_f]⟩) fun n z _ ↦ let ⟨i, x, h⟩ := exists_of z ⟨i, C x * X ^ (n + 1), by rw [Polynomial.map_mul, map_C, h, Polynomial.map_pow, map_X]⟩ end @[elab_as_elim] theorem induction_on [Nonempty ι] [IsDirected ι (· ≤ ·)] {C : DirectLimit G f → Prop} (z : DirectLimit G f) (ih : ∀ i x, C (of G f i x)) : C z := let ⟨i, x, hx⟩ := exists_of z hx ▸ ih i x variable (P : Type*) [CommRing P] open FreeCommRing variable (G f) in /-- The universal property of the direct limit: maps from the components to another ring that respect the directed system structure (i.e. make some diagram commute) give rise to a unique map out of the direct limit. -/ def lift (g : ∀ i, G i →+* P) (Hg : ∀ i j hij x, g j (f i j hij x) = g i x) : DirectLimit G f →+* P := Ideal.Quotient.lift _ (FreeCommRing.lift fun x : Σ i, G i ↦ g x.1 x.2) (by suffices Ideal.span _ ≤ Ideal.comap (FreeCommRing.lift fun x : Σ i : ι, G i ↦ g x.fst x.snd) ⊥ by intro x hx exact (mem_bot P).1 (this hx) rw [Ideal.span_le] intro x hx rw [SetLike.mem_coe, Ideal.mem_comap, mem_bot] rcases hx with (⟨i, j, hij, x, rfl⟩ | ⟨i, rfl⟩ | ⟨i, x, y, rfl⟩ | ⟨i, x, y, rfl⟩) <;> simp only [RingHom.map_sub, lift_of, Hg, RingHom.map_one, RingHom.map_add, RingHom.map_mul, (g i).map_one, (g i).map_add, (g i).map_mul, sub_self]) variable (g : ∀ i, G i →+* P) (Hg : ∀ i j hij x, g j (f i j hij x) = g i x) @[simp] theorem lift_of (i x) : lift G f P g Hg (of G f i x) = g i x := FreeCommRing.lift_of _ _ @[ext] theorem hom_ext {g₁ g₂ : DirectLimit G f →+* P} (h : ∀ i, g₁.comp (of G f i) = g₂.comp (of G f i)) : g₁ = g₂ := Ideal.Quotient.ringHom_ext <| FreeCommRing.hom_ext fun ⟨i, x⟩ => congr($(h i) x) @[simp] theorem lift_comp_of (F : DirectLimit G f →+* P) : lift G f _ (fun i ↦ F.comp <| of G f i) (fun i j hij x ↦ by simp) = F := by ext; simp @[deprecated lift_comp_of (since := "2025-08-11")] theorem lift_unique (F : DirectLimit G f →+* P) (x) : F x = lift G f P (fun i ↦ F.comp <| of G f i) (fun i j hij x ↦ by simp) x := by rw [lift_comp_of] @[simp] theorem lift_of' : lift G f _ (of G f) (fun i j hij x ↦ by simp) = .id _ := by ext; simp lemma lift_injective [Nonempty ι] [IsDirected ι (· ≤ ·)] (injective : ∀ i, Function.Injective <| g i) : Function.Injective (lift G f P g Hg) := by simp_rw [injective_iff_map_eq_zero] at injective ⊢ intro z hz induction z using DirectLimit.induction_on with | ih _ g => rw [lift_of] at hz; rw [injective _ g hz, map_zero] section OfZeroExact variable (f' : ∀ i j, i ≤ j → G i →+* G j) variable [DirectedSystem G fun i j h ↦ f' i j h] [IsDirected ι (· ≤ ·)] variable (G f) open _root_.DirectLimit in /-- The direct limit constructed as a quotient of the free commutative ring is isomorphic to the direct limit constructed as a quotient of the disjoint union. -/ def ringEquiv [Nonempty ι] : DirectLimit G (f' · · ·) ≃+* _root_.DirectLimit G f' := .ofRingHom (lift _ _ _ (Ring.of _ _) fun _ _ _ _ ↦ .symm <| eq_of_le ..) (Ring.lift _ _ _ (of _ _) fun _ _ _ _ ↦ of_f ..) (by ext; simp) (by ext; simp) theorem ringEquiv_of [Nonempty ι] {i g} : ringEquiv G f' (of _ _ i g) = ⟦⟨i, g⟩⟧ := by simp [ringEquiv]; rfl theorem ringEquiv_symm_mk [Nonempty ι] {g} : (ringEquiv G f').symm ⟦g⟧ = of _ _ g.1 g.2 := rfl variable {G f'} /-- A component that corresponds to zero in the direct limit is already zero in some bigger module in the directed system. -/ theorem of.zero_exact {i x} (hix : of G (f' · · ·) i x = 0) : ∃ (j : _) (hij : i ≤ j), f' i j hij x = 0 := by have := Nonempty.intro i apply_fun ringEquiv _ _ at hix rwa [map_zero, ringEquiv_of, DirectLimit.exists_eq_zero] at hix end OfZeroExact variable (f' : ∀ i j, i ≤ j → G i →+* G j) /-- If the maps in the directed system are injective, then the canonical maps from the components to the direct limits are injective. -/ theorem of_injective [IsDirected ι (· ≤ ·)] [DirectedSystem G fun i j h ↦ f' i j h] (hf : ∀ i j hij, Function.Injective (f' i j hij)) (i) : Function.Injective (of G (fun i j h ↦ f' i j h) i) := have := Nonempty.intro i ((ringEquiv _ _).comp_injective _).mp fun _ _ eq ↦ DirectLimit.mk_injective f' hf _ (by simpa only [← ringEquiv_of]) section functorial variable {f : ∀ i j, i ≤ j → G i →+* G j} variable {G' : ι → Type*} [∀ i, CommRing (G' i)] variable {f' : ∀ i j, i ≤ j → G' i →+* G' j} variable {G'' : ι → Type*} [∀ i, CommRing (G'' i)] variable {f'' : ∀ i j, i ≤ j → G'' i →+* G'' j} /-- Consider direct limits `lim G` and `lim G'` with direct system `f` and `f'` respectively, any family of ring homomorphisms `gᵢ : Gᵢ ⟶ G'ᵢ` such that `g ∘ f = f' ∘ g` induces a ring homomorphism `lim G ⟶ lim G'`. -/ def map (g : (i : ι) → G i →+* G' i) (hg : ∀ i j h, (g j).comp (f i j h) = (f' i j h).comp (g i)) : DirectLimit G (fun _ _ h ↦ f _ _ h) →+* DirectLimit G' fun _ _ h ↦ f' _ _ h := lift _ _ _ (fun i ↦ (of _ _ _).comp (g i)) fun i j h g ↦ by have eq1 := DFunLike.congr_fun (hg i j h) g simp only [RingHom.coe_comp, Function.comp_apply] at eq1 ⊢ rw [eq1, of_f] @[simp] lemma map_apply_of (g : (i : ι) → G i →+* G' i) (hg : ∀ i j h, (g j).comp (f i j h) = (f' i j h).comp (g i)) {i : ι} (x : G i) : map g hg (of G _ _ x) = of G' (fun _ _ h ↦ f' _ _ h) i (g i x) := lift_of _ _ _ _ _ @[simp] lemma map_id : map (fun _ ↦ RingHom.id _) (fun _ _ _ ↦ rfl) = .id (DirectLimit G fun _ _ h ↦ f _ _ h) := by ext; simp lemma map_comp (g₁ : (i : ι) → G i →+* G' i) (g₂ : (i : ι) → G' i →+* G'' i) (hg₁ : ∀ i j h, (g₁ j).comp (f i j h) = (f' i j h).comp (g₁ i)) (hg₂ : ∀ i j h, (g₂ j).comp (f' i j h) = (f'' i j h).comp (g₂ i)) : ((map g₂ hg₂).comp (map g₁ hg₁) : DirectLimit G (fun _ _ h ↦ f _ _ h) →+* DirectLimit G'' fun _ _ h ↦ f'' _ _ h) = (map (fun i ↦ (g₂ i).comp (g₁ i)) fun i j h ↦ by rw [RingHom.comp_assoc, hg₁ i, ← RingHom.comp_assoc, hg₂ i, RingHom.comp_assoc] : DirectLimit G (fun _ _ h ↦ f _ _ h) →+* DirectLimit G'' fun _ _ h ↦ f'' _ _ h) := by ext; simp /-- Consider direct limits `lim G` and `lim G'` with direct system `f` and `f'` respectively, any family of equivalences `eᵢ : Gᵢ ≅ G'ᵢ` such that `e ∘ f = f' ∘ e` induces an equivalence `lim G ⟶ lim G'`. -/ def congr (e : (i : ι) → G i ≃+* G' i) (he : ∀ i j h, (e j).toRingHom.comp (f i j h) = (f' i j h).comp (e i)) : DirectLimit G (fun _ _ h ↦ f _ _ h) ≃+* DirectLimit G' fun _ _ h ↦ f' _ _ h := RingEquiv.ofRingHom (map (e ·) he) (map (fun i ↦ (e i).symm) fun i j h ↦ DFunLike.ext _ _ fun x ↦ by have eq1 := DFunLike.congr_fun (he i j h) ((e i).symm x) simp only [RingEquiv.toRingHom_eq_coe, RingHom.coe_comp, RingHom.coe_coe, Function.comp_apply, RingEquiv.apply_symm_apply] at eq1 ⊢ simp [← eq1]) (by simp [map_comp]) (by simp [map_comp]) lemma congr_apply_of (e : (i : ι) → G i ≃+* G' i) (he : ∀ i j h, (e j).toRingHom.comp (f i j h) = (f' i j h).comp (e i)) {i : ι} (g : G i) : congr e he (of G _ i g) = of G' (fun _ _ h ↦ f' _ _ h) i (e i g) := map_apply_of _ he _ lemma congr_symm_apply_of (e : (i : ι) → G i ≃+* G' i) (he : ∀ i j h, (e j).toRingHom.comp (f i j h) = (f' i j h).comp (e i)) {i : ι} (g : G' i) : (congr e he).symm (of G' _ i g) = of G (fun _ _ h ↦ f _ _ h) i ((e i).symm g) := by simp only [congr, RingEquiv.ofRingHom_symm_apply, map_apply_of, RingHom.coe_coe] end functorial end DirectLimit end end Ring namespace Field variable [Nonempty ι] [IsDirected ι (· ≤ ·)] [∀ i, Field (G i)] variable (f : ∀ i j, i ≤ j → G i → G j) variable (f' : ∀ i j, i ≤ j → G i →+* G j) namespace DirectLimit instance nontrivial [DirectedSystem G (f' · · ·)] : Nontrivial (Ring.DirectLimit G (f' · · ·)) := ⟨⟨0, 1, Nonempty.elim (by infer_instance) fun i : ι ↦ by change (0 : Ring.DirectLimit G (f' · · ·)) ≠ 1 rw [← (Ring.DirectLimit.of _ _ _).map_one] · intro H; rcases Ring.DirectLimit.of.zero_exact H.symm with ⟨j, hij, hf⟩ rw [(f' i j hij).map_one] at hf exact one_ne_zero hf⟩⟩ theorem exists_inv {p : Ring.DirectLimit G f} : p ≠ 0 → ∃ y, p * y = 1 := Ring.DirectLimit.induction_on p fun i x H ↦ ⟨Ring.DirectLimit.of G f i x⁻¹, by rw [← (Ring.DirectLimit.of _ _ _).map_mul, mul_inv_cancel₀ fun h : x = 0 ↦ H <| by rw [h, (Ring.DirectLimit.of _ _ _).map_zero], (Ring.DirectLimit.of _ _ _).map_one]⟩ section open Classical in /-- Noncomputable multiplicative inverse in a direct limit of fields. -/ noncomputable def inv (p : Ring.DirectLimit G f) : Ring.DirectLimit G f := if H : p = 0 then 0 else Classical.choose (DirectLimit.exists_inv G f H) protected theorem mul_inv_cancel {p : Ring.DirectLimit G f} (hp : p ≠ 0) : p * inv G f p = 1 := by rw [inv, dif_neg hp, Classical.choose_spec (DirectLimit.exists_inv G f hp)] protected theorem inv_mul_cancel {p : Ring.DirectLimit G f} (hp : p ≠ 0) : inv G f p * p = 1 := by rw [_root_.mul_comm, DirectLimit.mul_inv_cancel G f hp] /-- Noncomputable field structure on the direct limit of fields. See note [reducible non-instances]. -/ protected noncomputable abbrev field [DirectedSystem G (f' · · ·)] : Field (Ring.DirectLimit G (f' · · ·)) where -- This used to include the parent CommRing and Nontrivial instances, -- but leaving them implicit avoids a very expensive (2-3 minutes!) eta expansion. inv := inv G (f' · · ·) mul_inv_cancel := fun _ ↦ DirectLimit.mul_inv_cancel G (f' · · ·) inv_zero := dif_pos rfl nnqsmul := _ nnqsmul_def _ _ := rfl qsmul := _ qsmul_def _ _ := rfl end end DirectLimit end Field
.lake/packages/mathlib/Mathlib/Algebra/Colimit/TensorProduct.lean
import Mathlib.Algebra.Colimit.Finiteness import Mathlib.LinearAlgebra.TensorProduct.DirectLimit /-! # Tensor product with direct limit of finitely generated submodules We show that if `M` and `P` are arbitrary modules and `N` is a finitely generated submodule of a module `P`, then two elements of `N ⊗ M` have the same image in `P ⊗ M` if and only if they already have the same image in `N' ⊗ M` for some finitely generated submodule `N' ≥ N`. This is the theorem `Submodule.FG.exists_rTensor_fg_inclusion_eq`. The key facts used are that every module is the direct limit of its finitely generated submodules and that tensor product preserves colimits. -/ open TensorProduct variable {R M P : Type*} [CommSemiring R] variable [AddCommMonoid M] [Module R M] [AddCommMonoid P] [Module R P] theorem Submodule.FG.exists_rTensor_fg_inclusion_eq {N : Submodule R P} (hN : N.FG) {x y : N ⊗[R] M} (eq : N.subtype.rTensor M x = N.subtype.rTensor M y) : ∃ N', N'.FG ∧ ∃ h : N ≤ N', (N.inclusion h).rTensor M x = (N.inclusion h).rTensor M y := by classical lift N to {N : Submodule R P // N.FG} using hN apply_fun (Module.fgSystem.equiv R P).symm.toLinearMap.rTensor M at eq apply_fun directLimitLeft _ _ at eq simp_rw [← LinearMap.rTensor_comp_apply, ← (LinearEquiv.eq_toLinearMap_symm_comp _ _).mpr (Module.fgSystem.equiv_comp_of N), directLimitLeft_rTensor_of] at eq have ⟨N', le, eq⟩ := Module.DirectLimit.exists_eq_of_of_eq eq exact ⟨_, N'.2, le, eq⟩
.lake/packages/mathlib/Mathlib/Algebra/Colimit/DirectLimit.lean
import Mathlib.Algebra.Module.LinearMap.Defs import Mathlib.Data.Rat.Cast.Defs import Mathlib.Order.DirectedInverseSystem import Mathlib.Tactic.SuppressCompilation /-! # Direct limit of algebraic structures We introduce all kinds of algebraic instances on `DirectLimit`, and specialize to the cases of modules and rings, showing that they are indeed colimits in the respective categories. ## Implementation notes The first 400 lines are boilerplate code that defines algebraic instances on `DirectLimit` from magma (`Mul`) to `Field`. To make everything "hom-polymorphic", we work with `DirectedSystem`s of `FunLike`s rather than plain unbundled functions, and we use algebraic hom typeclasses (e.g. `LinearMapClass`, `RingHomClass`) everywhere. In `Mathlib/Algebra/Colimit/Module.lean` and `Mathlib/Algebra/Colimit/Ring.lean`, `Module.DirectLimit`, `AddCommGroup.DirectLimit` and `Ring.DirectLimit` are defined as quotients of the universal objects (`DirectSum` and `FreeCommRing`). These definitions are more general and suitable for arbitrary colimits, but do not immediately provide criteria to determine when two elements in a component are equal in the direct limit. On the other hand, the `DirectLimit` in this file is only defined for directed systems and does not work for general colimits, but the equivalence relation defining `DirectLimit` is very explicit. For colimits of directed systems there is no need to construct the universal object for each type of algebraic structure; the same type `DirectLimit` simply works for all of them. This file is therefore more general than the `Module` and `Ring` files in terms of the variety of algebraic structures supported. So far we only show that `DirectLimit` is the colimit in the categories of modules and rings, but for the other algebraic structures the constructions and proofs will be easy following the same pattern. Since any two colimits are isomorphic, this allows us to golf proofs of equality criteria for `Module/AddCommGroup/Ring.DirectLimit`. -/ suppress_compilation variable {R ι : Type*} [Preorder ι] {G : ι → Type*} variable {T : ∀ ⦃i j : ι⦄, i ≤ j → Type*} {f : ∀ _ _ h, T h} variable [∀ i j (h : i ≤ j), FunLike (T h) (G i) (G j)] [DirectedSystem G (f · · ·)] variable [IsDirected ι (· ≤ ·)] namespace DirectLimit section ZeroOne variable [Nonempty ι] [∀ i, One (G i)] @[to_additive] instance : One (DirectLimit G f) where one := map₀ f fun _ ↦ 1 variable [∀ i j h, OneHomClass (T h) (G i) (G j)] @[to_additive] theorem one_def (i) : (1 : DirectLimit G f) = ⟦⟨i, 1⟩⟧ := map₀_def _ _ (fun _ _ _ ↦ map_one _) _ @[to_additive] theorem exists_eq_one (x) : ⟦x⟧ = (1 : DirectLimit G f) ↔ ∃ i h, f x.1 i h x.2 = 1 := by rw [one_def x.1, Quotient.eq] exact ⟨fun ⟨i, h, _, eq⟩ ↦ ⟨i, h, eq.trans (map_one _)⟩, fun ⟨i, h, eq⟩ ↦ ⟨i, h, h, eq.trans (map_one _).symm⟩⟩ end ZeroOne section AddMul variable [∀ i, Mul (G i)] [∀ i j h, MulHomClass (T h) (G i) (G j)] @[to_additive] instance : Mul (DirectLimit G f) where mul := map₂ f f f (fun _ ↦ (· * ·)) fun _ _ _ ↦ map_mul _ @[to_additive] theorem mul_def (i) (x y : G i) : ⟦⟨i, x⟩⟧ * ⟦⟨i, y⟩⟧ = (⟦⟨i, x * y⟩⟧ : DirectLimit G f) := map₂_def .. end AddMul @[to_additive] instance [∀ i, CommMagma (G i)] [∀ i j h, MulHomClass (T h) (G i) (G j)] : CommMagma (DirectLimit G f) where mul_comm := DirectLimit.induction₂ _ fun i _ _ ↦ by simp_rw [mul_def, mul_comm] @[to_additive] instance [∀ i, Semigroup (G i)] [∀ i j h, MulHomClass (T h) (G i) (G j)] : Semigroup (DirectLimit G f) where mul_assoc := DirectLimit.induction₃ _ fun i _ _ _ ↦ by simp_rw [mul_def, mul_assoc] @[to_additive] instance [∀ i, CommSemigroup (G i)] [∀ i j h, MulHomClass (T h) (G i) (G j)] : CommSemigroup (DirectLimit G f) where mul_comm := mul_comm section SMul variable [∀ i, SMul R (G i)] [∀ i j h, MulActionHomClass (T h) R (G i) (G j)] @[to_additive] instance : SMul R (DirectLimit G f) where smul r := map _ _ (fun _ ↦ (r • ·)) fun _ _ _ ↦ map_smul _ r @[to_additive] theorem smul_def (i x) (r : R) : r • ⟦⟨i, x⟩⟧ = (⟦⟨i, r • x⟩⟧ : DirectLimit G f) := rfl end SMul @[to_additive] instance [Monoid R] [∀ i, MulAction R (G i)] [∀ i j h, MulActionHomClass (T h) R (G i) (G j)] : MulAction R (DirectLimit G f) where one_smul := DirectLimit.induction _ fun i _ ↦ by rw [smul_def, one_smul] mul_smul _ _ := DirectLimit.induction _ fun i _ ↦ by simp_rw [smul_def, mul_smul] variable [Nonempty ι] @[to_additive] instance [∀ i, MulOneClass (G i)] [∀ i j h, MonoidHomClass (T h) (G i) (G j)] : MulOneClass (DirectLimit G f) where one_mul := DirectLimit.induction _ fun i _ ↦ by simp_rw [one_def i, mul_def, one_mul] mul_one := DirectLimit.induction _ fun i _ ↦ by simp_rw [one_def i, mul_def, mul_one] section Monoid variable [∀ i, Monoid (G i)] [∀ i j h, MonoidHomClass (T h) (G i) (G j)] @[to_additive] instance : Monoid (DirectLimit G f) where one_mul := one_mul mul_one := mul_one npow n := map _ _ (fun _ ↦ (· ^ n)) fun _ _ _ x ↦ map_pow _ x n npow_zero := DirectLimit.induction _ fun i _ ↦ by simp_rw [map_def, pow_zero, one_def i] npow_succ n := DirectLimit.induction _ fun i _ ↦ by simp_rw [map_def, pow_succ, mul_def] @[to_additive] theorem npow_def (i x) (n : ℕ) : ⟦⟨i, x⟩⟧ ^ n = (⟦⟨i, x ^ n⟩⟧ : DirectLimit G f) := rfl end Monoid @[to_additive] instance [∀ i, CommMonoid (G i)] [∀ i j h, MonoidHomClass (T h) (G i) (G j)] : CommMonoid (DirectLimit G f) where mul_comm := mul_comm section Group variable [∀ i, Group (G i)] [∀ i j h, MonoidHomClass (T h) (G i) (G j)] @[to_additive] instance : Group (DirectLimit G f) where inv := map _ _ (fun _ ↦ (·⁻¹)) fun _ _ _ ↦ map_inv _ div := map₂ _ _ _ (fun _ ↦ (· / ·)) fun _ _ _ ↦ map_div _ zpow n := map _ _ (fun _ ↦ (· ^ n)) fun _ _ _ x ↦ map_zpow _ x n div_eq_mul_inv := DirectLimit.induction₂ _ fun i _ _ ↦ show map₂ .. = _ * map .. by simp_rw [map₂_def, map_def, div_eq_mul_inv, mul_def] zpow_zero' := DirectLimit.induction _ fun i _ ↦ by simp_rw [map_def, zpow_zero, one_def i] zpow_succ' n := DirectLimit.induction _ fun i x ↦ by simp_rw [map_def, mul_def]; congr; apply DivInvMonoid.zpow_succ' zpow_neg' n := DirectLimit.induction _ fun i x ↦ by simp_rw [map_def]; congr; apply DivInvMonoid.zpow_neg' inv_mul_cancel := DirectLimit.induction _ fun i _ ↦ by simp_rw [map_def, mul_def, inv_mul_cancel, one_def i] @[to_additive] theorem inv_def (i x) : (⟦⟨i, x⟩⟧)⁻¹ = (⟦⟨i, x⁻¹⟩⟧ : DirectLimit G f) := rfl @[to_additive] theorem div_def (i x y) : ⟦⟨i, x⟩⟧ / ⟦⟨i, y⟩⟧ = (⟦⟨i, x / y⟩⟧ : DirectLimit G f) := map₂_def .. @[to_additive] theorem zpow_def (i x) (n : ℤ) : ⟦⟨i, x⟩⟧ ^ n = (⟦⟨i, x ^ n⟩⟧ : DirectLimit G f) := rfl end Group @[to_additive] instance [∀ i, CommGroup (G i)] [∀ i j h, MonoidHomClass (T h) (G i) (G j)] : CommGroup (DirectLimit G f) where mul_comm := mul_comm instance [∀ i, MulZeroClass (G i)] [∀ i j h, MulHomClass (T h) (G i) (G j)] [∀ i j h, ZeroHomClass (T h) (G i) (G j)] : MulZeroClass (DirectLimit G f) where zero_mul := DirectLimit.induction _ fun i _ ↦ by simp_rw [zero_def i, mul_def, zero_mul] mul_zero := DirectLimit.induction _ fun i _ ↦ by simp_rw [zero_def i, mul_def, mul_zero] section MulZeroOneClass variable [∀ i, MulZeroOneClass (G i)] [∀ i j h, MonoidWithZeroHomClass (T h) (G i) (G j)] instance : MulZeroOneClass (DirectLimit G f) where zero_mul := zero_mul mul_zero := mul_zero instance [∀ i, Nontrivial (G i)] : Nontrivial (DirectLimit G f) where exists_pair_ne := ⟨0, 1, fun h ↦ have ⟨i, _, _, eq⟩ := Quotient.eq.mp h; by simp at eq⟩ end MulZeroOneClass instance [∀ i, SemigroupWithZero (G i)] [∀ i j h, MulHomClass (T h) (G i) (G j)] [∀ i j h, ZeroHomClass (T h) (G i) (G j)] : SemigroupWithZero (DirectLimit G f) where zero_mul := zero_mul mul_zero := mul_zero instance [∀ i, MonoidWithZero (G i)] [∀ i j h, MonoidWithZeroHomClass (T h) (G i) (G j)] : MonoidWithZero (DirectLimit G f) where zero_mul := zero_mul mul_zero := mul_zero instance [∀ i, CommMonoidWithZero (G i)] [∀ i j h, MonoidWithZeroHomClass (T h) (G i) (G j)] : CommMonoidWithZero (DirectLimit G f) where zero_mul := zero_mul mul_zero := mul_zero section GroupWithZero variable [∀ i, GroupWithZero (G i)] [∀ i j h, MonoidWithZeroHomClass (T h) (G i) (G j)] instance : GroupWithZero (DirectLimit G f) where inv := map _ _ (fun _ ↦ (·⁻¹)) fun _ _ _ ↦ map_inv₀ _ div := map₂ _ _ _ (fun _ ↦ (· / ·)) fun _ _ _ ↦ map_div₀ _ zpow n := map _ _ (fun _ ↦ (· ^ n)) fun _ _ _ x ↦ map_zpow₀ _ x n div_eq_mul_inv := DirectLimit.induction₂ _ fun i _ _ ↦ show map₂ .. = _ * map .. by simp_rw [map₂_def, map_def, div_eq_mul_inv, mul_def] zpow_zero' := DirectLimit.induction _ fun i _ ↦ by simp_rw [map_def, zpow_zero, one_def i] zpow_succ' n := DirectLimit.induction _ fun i x ↦ by simp_rw [map_def, mul_def]; congr; apply DivInvMonoid.zpow_succ' zpow_neg' n := DirectLimit.induction _ fun i x ↦ by simp_rw [map_def]; congr; apply DivInvMonoid.zpow_neg' inv_zero := show ⟦_⟧ = ⟦_⟧ by simp_rw [inv_zero] mul_inv_cancel := DirectLimit.induction _ fun i x ne ↦ by have : x ≠ 0 := by rintro rfl; exact ne (zero_def i).symm simp_rw [map_def, mul_def, mul_inv_cancel₀ this, one_def i] theorem inv₀_def (i x) : (⟦⟨i, x⟩⟧)⁻¹ = (⟦⟨i, x⁻¹⟩⟧ : DirectLimit G f) := rfl theorem div₀_def (i x y) : ⟦⟨i, x⟩⟧ / ⟦⟨i, y⟩⟧ = (⟦⟨i, x / y⟩⟧ : DirectLimit G f) := map₂_def .. theorem zpow₀_def (i x) (n : ℤ) : ⟦⟨i, x⟩⟧ ^ n = (⟦⟨i, x ^ n⟩⟧ : DirectLimit G f) := rfl end GroupWithZero instance [∀ i, CommGroupWithZero (G i)] [∀ i j h, MonoidWithZeroHomClass (T h) (G i) (G j)] : CommGroupWithZero (DirectLimit G f) where __ : GroupWithZero _ := inferInstance mul_comm := mul_comm section AddMonoidWithOne variable [∀ i, AddMonoidWithOne (G i)] [∀ i j h, AddMonoidHomClass (T h) (G i) (G j)] instance : AddMonoidWithOne (DirectLimit G f) where natCast n := map₀ _ fun _ ↦ n natCast_zero := show ⟦_⟧ = ⟦_⟧ by simp_rw [Nat.cast_zero] natCast_succ n := show ⟦_⟧ = ⟦_⟧ + ⟦_⟧ by simp_rw [Nat.cast_succ, add_def] theorem natCast_def [∀ i j h, OneHomClass (T h) (G i) (G j)] (n : ℕ) (i) : (n : DirectLimit G f) = ⟦⟨i, n⟩⟧ := map₀_def _ _ (fun _ _ _ ↦ map_natCast' _ (map_one _) _) _ end AddMonoidWithOne section AddGroupWithOne variable [∀ i, AddGroupWithOne (G i)] [∀ i j h, AddMonoidHomClass (T h) (G i) (G j)] instance : AddGroupWithOne (DirectLimit G f) where __ : AddGroup _ := inferInstance intCast n := map₀ _ fun _ ↦ n intCast_ofNat n := show ⟦_⟧ = ⟦_⟧ by simp_rw [Int.cast_natCast] intCast_negSucc n := show ⟦_⟧ = ⟦_⟧ by simp natCast_zero := Nat.cast_zero natCast_succ := Nat.cast_succ theorem intCast_def [∀ i j h, OneHomClass (T h) (G i) (G j)] (n : ℤ) (i) : (n : DirectLimit G f) = ⟦⟨i, n⟩⟧ := map₀_def _ _ (fun _ _ _ ↦ map_intCast' _ (map_one _) _) _ end AddGroupWithOne instance [∀ i, AddCommMonoidWithOne (G i)] [∀ i j h, AddMonoidHomClass (T h) (G i) (G j)] : AddCommMonoidWithOne (DirectLimit G f) where add_comm := add_comm instance [∀ i, AddCommGroupWithOne (G i)] [∀ i j h, AddMonoidHomClass (T h) (G i) (G j)] : AddCommGroupWithOne (DirectLimit G f) where __ : AddGroupWithOne _ := inferInstance add_comm := add_comm instance [∀ i, NonUnitalNonAssocSemiring (G i)] [∀ i j h, NonUnitalRingHomClass (T h) (G i) (G j)] : NonUnitalNonAssocSemiring (DirectLimit G f) where left_distrib := DirectLimit.induction₃ _ fun i _ _ _ ↦ by simp_rw [add_def, mul_def, left_distrib, add_def] right_distrib := DirectLimit.induction₃ _ fun i _ _ _ ↦ by simp_rw [add_def, mul_def, right_distrib, add_def] zero_mul := zero_mul mul_zero := mul_zero instance [∀ i, NonUnitalNonAssocCommSemiring (G i)] [∀ i j h, NonUnitalRingHomClass (T h) (G i) (G j)] : NonUnitalNonAssocCommSemiring (DirectLimit G f) where mul_comm := mul_comm instance [∀ i, NonUnitalSemiring (G i)] [∀ i j h, NonUnitalRingHomClass (T h) (G i) (G j)] : NonUnitalSemiring (DirectLimit G f) where mul_assoc := mul_assoc instance [∀ i, NonUnitalCommSemiring (G i)] [∀ i j h, NonUnitalRingHomClass (T h) (G i) (G j)] : NonUnitalCommSemiring (DirectLimit G f) where mul_comm := mul_comm instance [∀ i, NonAssocSemiring (G i)] [∀ i j h, RingHomClass (T h) (G i) (G j)] : NonAssocSemiring (DirectLimit G f) where one_mul := one_mul mul_one := mul_one natCast_zero := Nat.cast_zero natCast_succ := Nat.cast_succ -- There is no NonAssocCommSemiring instance [∀ i, Semiring (G i)] [∀ i j h, RingHomClass (T h) (G i) (G j)] : Semiring (DirectLimit G f) where __ : NonAssocSemiring _ := inferInstance __ : Monoid _ := inferInstance instance [∀ i, CommSemiring (G i)] [∀ i j h, RingHomClass (T h) (G i) (G j)] : CommSemiring (DirectLimit G f) where mul_comm := mul_comm instance [∀ i, Ring (G i)] [∀ i j h, RingHomClass (T h) (G i) (G j)] : Ring (DirectLimit G f) where __ : Semiring _ := inferInstance __ : AddCommGroupWithOne _ := inferInstance instance [∀ i, CommRing (G i)] [∀ i j h, RingHomClass (T h) (G i) (G j)] : CommRing (DirectLimit G f) where mul_comm := mul_comm section Action instance [∀ i, Zero (G i)] [∀ i, SMulZeroClass R (G i)] [∀ i j h, MulActionHomClass (T h) R (G i) (G j)] : SMulZeroClass R (DirectLimit G f) where smul_zero r := (smul_def _ _ _).trans <| by rw [smul_zero]; rfl instance [Zero R] [∀ i, Zero (G i)] [∀ i, SMulWithZero R (G i)] [∀ i j h, MulActionHomClass (T h) R (G i) (G j)] [∀ i j h, ZeroHomClass (T h) (G i) (G j)] : SMulWithZero R (DirectLimit G f) where zero_smul := DirectLimit.induction _ fun i _ ↦ by simp_rw [smul_def, zero_smul, zero_def i] instance [∀ i, AddZeroClass (G i)] [∀ i, DistribSMul R (G i)] [∀ i j h, AddMonoidHomClass (T h) (G i) (G j)] [∀ i j h, MulActionHomClass (T h) R (G i) (G j)] : DistribSMul R (DirectLimit G f) where smul_add r := DirectLimit.induction₂ _ fun i _ _ ↦ by simp_rw [add_def, smul_def, smul_add, add_def] instance [Monoid R] [∀ i, AddMonoid (G i)] [∀ i, DistribMulAction R (G i)] [∀ i j h, DistribMulActionHomClass (T h) R (G i) (G j)] : DistribMulAction R (DirectLimit G f) := have _ i j h : MulActionHomClass (T h) R (G i) (G j) := inferInstance { smul_zero := smul_zero, smul_add := smul_add } instance [Monoid R] [∀ i, Monoid (G i)] [∀ i, MulDistribMulAction R (G i)] [∀ i j h, MonoidHomClass (T h) (G i) (G j)] [∀ i j h, MulActionHomClass (T h) R (G i) (G j)] : MulDistribMulAction R (DirectLimit G f) where smul_mul r := DirectLimit.induction₂ _ fun i _ _ ↦ by simp_rw [mul_def, smul_def, MulDistribMulAction.smul_mul, mul_def] smul_one r := (smul_def _ _ _).trans <| by rw [smul_one]; rfl instance [Semiring R] [∀ i, AddCommMonoid (G i)] [∀ i, Module R (G i)] [∀ i j h, LinearMapClass (T h) R (G i) (G j)] : Module R (DirectLimit G f) := have _ i j h : DistribMulActionHomClass (T h) R (G i) (G j) := inferInstance { add_smul _ _ := DirectLimit.induction _ fun i _ ↦ by simp_rw [smul_def, add_smul, add_def], zero_smul := DirectLimit.induction _ fun i _ ↦ by simp_rw [smul_def, zero_smul, zero_def i] } end Action section DivisionSemiring variable [∀ i, DivisionSemiring (G i)] [∀ i j h, RingHomClass (T h) (G i) (G j)] instance : DivisionSemiring (DirectLimit G f) where __ : GroupWithZero _ := inferInstance __ : Semiring _ := inferInstance nnratCast q := map₀ _ fun _ ↦ q nnratCast_def q := show ⟦_⟧ = ⟦_⟧ / ⟦_⟧ by simp_rw [div₀_def]; rw [NNRat.cast_def] nnqsmul q := map _ _ (fun _ ↦ (q • ·)) fun _ _ _ x ↦ by simp_rw [NNRat.smul_def, map_mul, map_nnratCast] nnqsmul_def _ := DirectLimit.induction _ fun i x ↦ show ⟦_⟧ = map₀ .. * _ by simp_rw [map₀_def _ _ (fun _ _ _ ↦ map_nnratCast _ _) i, mul_def, NNRat.smul_def] theorem nnratCast_def (q : ℚ≥0) (i) : (q : DirectLimit G f) = ⟦⟨i, q⟩⟧ := map₀_def _ _ (fun _ _ _ ↦ map_nnratCast _ _) _ end DivisionSemiring instance [∀ i, Semifield (G i)] [∀ i j h, RingHomClass (T h) (G i) (G j)] : Semifield (DirectLimit G f) where __ : DivisionSemiring _ := inferInstance mul_comm := mul_comm section DivisionRing variable [∀ i, DivisionRing (G i)] [∀ i j h, RingHomClass (T h) (G i) (G j)] instance : DivisionRing (DirectLimit G f) where __ : DivisionSemiring _ := inferInstance __ : Ring _ := inferInstance ratCast q := map₀ _ fun _ ↦ q ratCast_def q := show ⟦_⟧ = ⟦_⟧ / ⟦_⟧ by simp_rw [div₀_def]; rw [Rat.cast_def] qsmul q := map _ _ (fun _ ↦ (q • ·)) fun _ _ _ x ↦ by simp_rw [Rat.smul_def, map_mul, map_ratCast] qsmul_def _ := DirectLimit.induction _ fun i x ↦ show ⟦_⟧ = map₀ .. * _ by simp_rw [map₀_def _ _ (fun _ _ _ ↦ map_ratCast _ _) i, mul_def, Rat.smul_def] theorem ratCast_def (q : ℚ) (i) : (q : DirectLimit G f) = ⟦⟨i, q⟩⟧ := map₀_def _ _ (fun _ _ _ ↦ map_ratCast _ _) _ end DivisionRing instance [∀ i, Field (G i)] [∀ i j h, RingHomClass (T h) (G i) (G j)] : Field (DirectLimit G f) where __ : DivisionRing _ := inferInstance mul_comm := mul_comm end DirectLimit namespace DirectLimit namespace Module variable [Semiring R] [∀ i, AddCommMonoid (G i)] [∀ i, Module R (G i)] variable [∀ i j h, LinearMapClass (T h) R (G i) (G j)] variable (R ι G f) [Nonempty ι] /-- The canonical map from a component to the direct limit. -/ def of (i) : G i →ₗ[R] DirectLimit G f where toFun x := ⟦⟨i, x⟩⟧ map_add' _ _ := (add_def ..).symm map_smul' _ _ := (smul_def ..).symm variable {R ι G f} @[simp] theorem of_f {i j hij x} : of R ι G f j (f i j hij x) = of R ι G f i x := .symm <| eq_of_le .. variable {P : Type*} [AddCommMonoid P] [Module R P] variable (R ι G f) in /-- The universal property of the direct limit: maps from the components to another module that respect the directed system structure (i.e. make some diagram commute) give rise to a unique map out of the direct limit. -/ @[simps -isSimp] def lift (g : ∀ i, G i →ₗ[R] P) (Hg : ∀ i j hij x, g j (f i j hij x) = g i x) : DirectLimit G f →ₗ[R] P where toFun := _root_.DirectLimit.lift _ (g · ·) fun i j h x ↦ (Hg i j h x).symm map_add' := DirectLimit.induction₂ _ fun i x y ↦ by simp_rw [add_def, lift_def, map_add] map_smul' r := DirectLimit.induction _ fun i x ↦ by simp_rw [smul_def, lift_def, map_smul, RingHom.id_apply] variable (g : ∀ i, G i →ₗ[R] P) (Hg : ∀ i j hij x, g j (f i j hij x) = g i x) @[simp] theorem lift_of {i} (x) : lift R ι G f g Hg (of R ι G f i x) = g i x := rfl @[ext] theorem hom_ext {g₁ g₂ : DirectLimit G f →ₗ[R] P} (h : ∀ i, g₁ ∘ₗ of R ι G f i = g₂ ∘ₗ of R ι G f i) : g₁ = g₂ := by ext x induction x using DirectLimit.induction with | _ i x exact congr($(h i) x) end Module namespace Ring variable [∀ i, NonAssocSemiring (G i)] [∀ i j h, RingHomClass (T h) (G i) (G j)] [Nonempty ι] variable (G f) in /-- The canonical map from a component to the direct limit. -/ nonrec def of (i) : G i →+* DirectLimit G f where toFun x := ⟦⟨i, x⟩⟧ map_one' := (one_def i).symm map_mul' _ _ := (mul_def ..).symm map_zero' := (zero_def i).symm map_add' _ _ := (add_def ..).symm @[simp] theorem of_f {i j} (hij) (x) : of G f j (f i j hij x) = of G f i x := .symm <| eq_of_le .. variable (P : Type*) [NonAssocSemiring P] variable (G f) in /-- The universal property of the direct limit: maps from the components to another ring that respect the directed system structure (i.e. make some diagram commute) give rise to a unique map out of the direct limit. -/ def lift (g : ∀ i, G i →+* P) (Hg : ∀ i j hij x, g j (f i j hij x) = g i x) : DirectLimit G f →+* P where toFun := _root_.DirectLimit.lift _ (g · ·) fun i j h x ↦ (Hg i j h x).symm map_one' := by rw [one_def (Classical.arbitrary ι), lift_def, map_one] map_mul' := DirectLimit.induction₂ _ fun i x y ↦ by simp_rw [mul_def, lift_def, map_mul] map_zero' := by simp_rw [zero_def (Classical.arbitrary ι), lift_def, map_zero] map_add' := DirectLimit.induction₂ _ fun i x y ↦ by simp_rw [add_def, lift_def, map_add] variable (g : ∀ i, G i →+* P) (Hg : ∀ i j hij x, g j (f i j hij x) = g i x) @[simp] theorem lift_of (i x) : lift G f P g Hg (of G f i x) = g i x := rfl @[ext] theorem hom_ext {g₁ g₂ : DirectLimit G f →+* P} (h : ∀ i, g₁.comp (of G f i) = g₂.comp (of G f i)) : g₁ = g₂ := by ext x induction x using DirectLimit.induction with | _ i x exact congr($(h i) x) end Ring end DirectLimit
.lake/packages/mathlib/Mathlib/Algebra/Colimit/Finiteness.lean
import Mathlib.Algebra.Colimit.Module import Mathlib.RingTheory.Finiteness.Basic /-! # Modules as direct limits of finitely generated submodules We show that every module is the direct limit of its finitely generated submodules. ## Main definitions * `Module.fgSystem`: the directed system of finitely generated submodules of a module. * `Module.fgSystem.equiv`: the isomorphism between a module and the direct limit of its finitely generated submodules. -/ namespace Module variable (R M : Type*) [Semiring R] [AddCommMonoid M] [Module R M] /-- The directed system of finitely generated submodules of a module. -/ def fgSystem (N₁ N₂ : {N : Submodule R M // N.FG}) (le : N₁ ≤ N₂) : N₁ →ₗ[R] N₂ := Submodule.inclusion le open DirectLimit namespace fgSystem instance : IsDirected {N : Submodule R M // N.FG} (· ≤ ·) where directed N₁ N₂ := ⟨⟨_, N₁.2.sup N₂.2⟩, Subtype.coe_le_coe.mp le_sup_left, Subtype.coe_le_coe.mp le_sup_right⟩ instance : DirectedSystem _ (fgSystem R M · · · ·) where map_self _ _ := rfl map_map _ _ _ _ _ _ := rfl variable [DecidableEq (Submodule R M)] open Submodule in /-- Every module is the direct limit of its finitely generated submodules. -/ noncomputable def equiv : DirectLimit _ (fgSystem R M) ≃ₗ[R] M := .ofBijective (lift _ _ _ _ (fun _ ↦ Submodule.subtype _) fun _ _ _ _ ↦ rfl) ⟨lift_injective _ _ fun _ ↦ Subtype.val_injective, fun x ↦ ⟨of _ _ _ _ ⟨_, fg_span_singleton x⟩ ⟨x, subset_span <| by rfl⟩, lift_of ..⟩⟩ variable {R M} lemma equiv_comp_of (N : {N : Submodule R M // N.FG}) : (equiv R M).toLinearMap ∘ₗ of _ _ _ _ N = N.1.subtype := by ext; simp [equiv] end fgSystem end Module
.lake/packages/mathlib/Mathlib/Algebra/BrauerGroup/Defs.lean
import Mathlib.Algebra.Category.AlgCat.Basic import Mathlib.Algebra.Central.Defs import Mathlib.LinearAlgebra.FiniteDimensional.Defs import Mathlib.LinearAlgebra.Matrix.Reindex /-! # Definition of Brauer group of a field K We introduce the definition of Brauer group of a field K, which is the quotient of the set of all finite-dimensional central simple algebras over K modulo the Brauer Equivalence where two central simple algebras `A` and `B` are Brauer Equivalent if there exist `n, m ∈ ℕ+` such that `Mₙ(A) ≃ₐ[K] Mₘ(B)`. ## TODOs 1. Prove that the Brauer group is an abelian group where multiplication is defined as tensor product. 2. Prove that the Brauer group is a functor from the category of fields to the category of groups. 3. Prove that over a field, being Brauer equivalent is the same as being Morita equivalent. ## References * [Algebraic Number Theory, *J.W.S Cassels*][cassels1967algebraic] ## Tags Brauer group, Central simple algebra, Galois Cohomology -/ universe u v /-- `CSA` is the set of all finite-dimensional central simple algebras over a field `K`. For the generalization to a `CommRing`, see `IsAzumaya` in `Mathlib/Algebra/Azumaya/Defs.lean`. -/ structure CSA (K : Type u) [Field K] extends AlgCat.{v} K where /-- Any member of `CSA` is central. -/ [isCentral : Algebra.IsCentral K carrier] /-- Any member of `CSA` is simple. -/ [isSimple : IsSimpleRing carrier] /-- Any member of `CSA` is finite-dimensional. -/ [fin_dim : FiniteDimensional K carrier] variable {K : Type u} [Field K] instance : CoeSort (CSA.{u, v} K) (Type v) := ⟨(·.carrier)⟩ attribute [instance] CSA.isCentral CSA.isSimple CSA.fin_dim /-- Two finite-dimensional central simple algebras `A` and `B` are Brauer Equivalent if there exist `n, m ∈ ℕ+` such that the `Mₙ(A) ≃ₐ[K] Mₘ(B)`. -/ abbrev IsBrauerEquivalent (A B : CSA K) : Prop := ∃ n m : ℕ, n ≠ 0 ∧ m ≠ 0 ∧ (Nonempty <| Matrix (Fin n) (Fin n) A ≃ₐ[K] Matrix (Fin m) (Fin m) B) namespace IsBrauerEquivalent @[refl] lemma refl (A : CSA K) : IsBrauerEquivalent A A := ⟨1, 1, one_ne_zero, one_ne_zero, ⟨AlgEquiv.refl⟩⟩ @[symm] lemma symm {A B : CSA K} (h : IsBrauerEquivalent A B) : IsBrauerEquivalent B A := let ⟨n, m, hn, hm, ⟨iso⟩⟩ := h ⟨m, n, hm, hn, ⟨iso.symm⟩⟩ open Matrix in @[trans] lemma trans {A B C : CSA K} (hAB : IsBrauerEquivalent A B) (hBC : IsBrauerEquivalent B C) : IsBrauerEquivalent A C := by obtain ⟨n, m, hn, hm, ⟨iso1⟩⟩ := hAB obtain ⟨p, q, hp, hq, ⟨iso2⟩⟩ := hBC exact ⟨p * n, m * q, by simp_all, by simp_all, ⟨reindexAlgEquiv _ _ finProdFinEquiv |>.symm.trans <| compAlgEquiv _ _ _ _|>.symm.trans <| iso1.mapMatrix (m := Fin p)|>.trans <| compAlgEquiv _ _ _ _|>.trans <| reindexAlgEquiv K B (.prodComm (Fin p) (Fin m))|>.trans <| compAlgEquiv _ _ _ _|>.symm.trans <| iso2.mapMatrix.trans <| compAlgEquiv _ _ _ _|>.trans <| reindexAlgEquiv _ _ finProdFinEquiv⟩⟩ lemma is_eqv : Equivalence (IsBrauerEquivalent (K := K)) where refl := refl symm := symm trans := trans end IsBrauerEquivalent variable (K) /-- `CSA` equipped with Brauer Equivalence is indeed a setoid. -/ def Brauer.CSA_Setoid : Setoid (CSA K) where r := IsBrauerEquivalent iseqv := IsBrauerEquivalent.is_eqv /-- `BrauerGroup` is the set of all finite-dimensional central simple algebras quotient by Brauer Equivalence. -/ abbrev BrauerGroup := Quotient (Brauer.CSA_Setoid K)
.lake/packages/mathlib/Mathlib/Algebra/Notation/Indicator.lean
import Mathlib.Algebra.Notation.Support import Mathlib.Data.Set.Piecewise /-! # Indicator function This file defines the indicator function of a set. More lemmas can be found in `Mathlib/Algebra/Group/Indicator.lean`. ## Main declarations - `Set.indicator (s : Set α) (f : α → β) (a : α)` is `f a` if `a ∈ s` and is `0` otherwise. - `Set.mulIndicator (s : Set α) (f : α → β) (a : α)` is `f a` if `a ∈ s` and is `1` otherwise. ## Implementation note In mathematics, an indicator function or a characteristic function is a function used to indicate membership of an element in a set `s`, having the value `1` for all elements of `s` and the value `0` otherwise. But since it is usually used to restrict a function to a certain set `s`, we let the indicator function take the value `f x` for some function `f`, instead of `1`. If the usual indicator function is needed, just set `f` to be the constant function `fun _ ↦ 1`. The indicator function is implemented non-computably, to avoid having to pass around `Decidable` arguments. This is in contrast with the design of `Pi.single` or `Set.piecewise`. ## Tags indicator, characteristic -/ assert_not_exists Monoid open Function variable {α β M N : Type*} namespace Set variable [One M] [One N] {s t : Set α} {f g : α → M} {a : α} /-- `Set.mulIndicator s f a` is `f a` if `a ∈ s`, `1` otherwise. -/ @[to_additive /-- `Set.indicator s f a` is `f a` if `a ∈ s`, `0` otherwise. -/] noncomputable def mulIndicator (s : Set α) (f : α → M) (x : α) : M := haveI := Classical.decPred (· ∈ s) if x ∈ s then f x else 1 @[to_additive (attr := simp)] lemma piecewise_eq_mulIndicator [DecidablePred (· ∈ s)] : s.piecewise f 1 = s.mulIndicator f := funext fun _ => @if_congr _ _ _ _ (id _) _ _ _ _ Iff.rfl rfl rfl @[to_additive] lemma mulIndicator_apply (s : Set α) (f : α → M) (a : α) [Decidable (a ∈ s)] : mulIndicator s f a = if a ∈ s then f a else 1 := by unfold mulIndicator congr @[to_additive (attr := simp)] lemma mulIndicator_of_mem (h : a ∈ s) (f : α → M) : mulIndicator s f a = f a := if_pos h @[to_additive (attr := simp)] lemma mulIndicator_of_notMem (h : a ∉ s) (f : α → M) : mulIndicator s f a = 1 := if_neg h @[deprecated (since := "2025-05-23")] alias indicator_of_not_mem := indicator_of_notMem @[to_additive existing, deprecated (since := "2025-05-23")] alias mulIndicator_of_not_mem := mulIndicator_of_notMem @[to_additive] lemma mulIndicator_eq_one_or_self (s : Set α) (f : α → M) (a : α) : mulIndicator s f a = 1 ∨ mulIndicator s f a = f a := by by_cases h : a ∈ s · exact Or.inr (mulIndicator_of_mem h f) · exact Or.inl (mulIndicator_of_notMem h f) @[to_additive (attr := simp)] lemma mulIndicator_apply_eq_self : s.mulIndicator f a = f a ↔ a ∉ s → f a = 1 := letI := Classical.dec (a ∈ s) ite_eq_left_iff.trans (by rw [@eq_comm _ (f a)]) @[to_additive (attr := simp)] lemma mulIndicator_eq_self : s.mulIndicator f = f ↔ mulSupport f ⊆ s := by simp only [funext_iff, subset_def, mem_mulSupport, mulIndicator_apply_eq_self, not_imp_comm] @[to_additive] lemma mulIndicator_eq_self_of_superset (h1 : s.mulIndicator f = f) (h2 : s ⊆ t) : t.mulIndicator f = f := by rw [mulIndicator_eq_self] at h1 ⊢ exact Subset.trans h1 h2 @[to_additive (attr := simp)] lemma mulIndicator_apply_eq_one : mulIndicator s f a = 1 ↔ a ∈ s → f a = 1 := letI := Classical.dec (a ∈ s) ite_eq_right_iff @[to_additive (attr := simp)] lemma mulIndicator_eq_one : (mulIndicator s f = fun _ => 1) ↔ Disjoint (mulSupport f) s := by simp only [funext_iff, mulIndicator_apply_eq_one, Set.disjoint_left, mem_mulSupport, not_imp_not] @[to_additive (attr := simp)] lemma mulIndicator_eq_one' : mulIndicator s f = 1 ↔ Disjoint (mulSupport f) s := mulIndicator_eq_one @[to_additive] lemma mulIndicator_apply_ne_one {a : α} : s.mulIndicator f a ≠ 1 ↔ a ∈ s ∩ mulSupport f := by simp only [Ne, mulIndicator_apply_eq_one, Classical.not_imp, mem_inter_iff, mem_mulSupport] @[to_additive (attr := simp)] lemma mulSupport_mulIndicator : Function.mulSupport (s.mulIndicator f) = s ∩ Function.mulSupport f := ext fun x => by simp [Function.mem_mulSupport, mulIndicator_apply_eq_one] /-- If a multiplicative indicator function is not equal to `1` at a point, then that point is in the set. -/ @[to_additive /-- If an additive indicator function is not equal to `0` at a point, then that point is in the set. -/] lemma mem_of_mulIndicator_ne_one (h : mulIndicator s f a ≠ 1) : a ∈ s := not_imp_comm.1 (fun hn => mulIndicator_of_notMem hn f) h /-- See `Set.eqOn_mulIndicator'` for the version with `sᶜ`. -/ @[to_additive /-- See `Set.eqOn_indicator'` for the version with `sᶜ`. -/] lemma eqOn_mulIndicator : EqOn (mulIndicator s f) f s := fun _ hx => mulIndicator_of_mem hx f /-- See `Set.eqOn_mulIndicator` for the version with `s`. -/ @[to_additive /-- See `Set.eqOn_indicator` for the version with `s`. -/] lemma eqOn_mulIndicator' : EqOn (mulIndicator s f) 1 sᶜ := fun _ hx => mulIndicator_of_notMem hx f @[to_additive] lemma mulSupport_mulIndicator_subset : mulSupport (s.mulIndicator f) ⊆ s := fun _ hx => hx.imp_symm fun h => mulIndicator_of_notMem h f @[to_additive (attr := simp)] lemma mulIndicator_mulSupport : mulIndicator (mulSupport f) f = f := mulIndicator_eq_self.2 Subset.rfl @[to_additive (attr := simp)] lemma mulIndicator_range_comp {ι : Sort*} (f : ι → α) (g : α → M) : mulIndicator (range f) g ∘ f = g ∘ f := letI := Classical.decPred (· ∈ range f) piecewise_range_comp _ _ _ @[to_additive] lemma mulIndicator_congr (h : EqOn f g s) : mulIndicator s f = mulIndicator s g := funext fun x => by simp only [mulIndicator] split_ifs with h_1 · exact h h_1 rfl @[to_additive] lemma mulIndicator_eq_mulIndicator {t : Set β} {g : β → M} {b : β} (h1 : a ∈ s ↔ b ∈ t) (h2 : f a = g b) : s.mulIndicator f a = t.mulIndicator g b := by by_cases a ∈ s <;> simp_all @[to_additive] lemma mulIndicator_const_eq_mulIndicator_const {t : Set β} {b : β} {c : M} (h : a ∈ s ↔ b ∈ t) : s.mulIndicator (fun _ ↦ c) a = t.mulIndicator (fun _ ↦ c) b := mulIndicator_eq_mulIndicator h rfl @[to_additive (attr := simp)] lemma mulIndicator_univ (f : α → M) : mulIndicator (univ : Set α) f = f := mulIndicator_eq_self.2 <| subset_univ _ @[to_additive (attr := simp)] lemma mulIndicator_empty (f : α → M) : mulIndicator (∅ : Set α) f = fun _ => 1 := mulIndicator_eq_one.2 <| disjoint_empty _ @[to_additive] lemma mulIndicator_empty' (f : α → M) : mulIndicator (∅ : Set α) f = 1 := mulIndicator_empty f variable (M) @[to_additive (attr := simp)] lemma mulIndicator_one (s : Set α) : (mulIndicator s fun _ => (1 : M)) = fun _ => (1 : M) := mulIndicator_eq_one.2 <| by simp only [mulSupport_fun_one, empty_disjoint] @[to_additive (attr := simp)] lemma mulIndicator_one' {s : Set α} : s.mulIndicator (1 : α → M) = 1 := mulIndicator_one M s variable {M} @[to_additive] lemma mulIndicator_mulIndicator (s t : Set α) (f : α → M) : mulIndicator s (mulIndicator t f) = mulIndicator (s ∩ t) f := funext fun x => by simp only [mulIndicator] split_ifs <;> simp_all +contextual @[to_additive (attr := simp)] lemma mulIndicator_inter_mulSupport (s : Set α) (f : α → M) : mulIndicator (s ∩ mulSupport f) f = mulIndicator s f := by rw [← mulIndicator_mulIndicator, mulIndicator_mulSupport] @[to_additive] lemma comp_mulIndicator (h : M → β) (f : α → M) {s : Set α} {x : α} [DecidablePred (· ∈ s)] : h (s.mulIndicator f x) = s.piecewise (h ∘ f) (const α (h 1)) x := by letI := Classical.decPred (· ∈ s) convert s.apply_piecewise f (const α 1) (fun _ => h) (x := x) using 2 @[to_additive] lemma mulIndicator_comp_right {s : Set α} (f : β → α) {g : α → M} {x : β} : mulIndicator (f ⁻¹' s) (g ∘ f) x = mulIndicator s g (f x) := by tauto @[to_additive] lemma mulIndicator_image {s : Set α} {f : β → M} {g : α → β} (hg : Injective g) {x : α} : mulIndicator (g '' s) f (g x) = mulIndicator s (f ∘ g) x := by rw [← mulIndicator_comp_right, preimage_image_eq _ hg] @[to_additive] lemma mulIndicator_comp_of_one {g : M → N} (hg : g 1 = 1) : mulIndicator s (g ∘ f) = g ∘ mulIndicator s f := by funext simp only [mulIndicator] split_ifs <;> simp [*] @[to_additive] lemma comp_mulIndicator_const (c : M) (f : M → N) (hf : f 1 = 1) : (fun x => f (s.mulIndicator (fun _ => c) x)) = s.mulIndicator fun _ => f c := (mulIndicator_comp_of_one hf).symm @[to_additive] lemma mulIndicator_preimage (s : Set α) (f : α → M) (B : Set M) : mulIndicator s f ⁻¹' B = s.ite (f ⁻¹' B) (1 ⁻¹' B) := letI := Classical.decPred (· ∈ s) piecewise_preimage s f 1 B @[to_additive] lemma mulIndicator_one_preimage (s : Set M) : t.mulIndicator 1 ⁻¹' s ∈ ({Set.univ, ∅} : Set (Set α)) := by classical rw [mulIndicator_one', Pi.one_def, Set.preimage_const] split_ifs <;> simp @[to_additive] lemma mulIndicator_const_preimage_eq_union (U : Set α) (s : Set M) (a : M) [Decidable (a ∈ s)] [Decidable ((1 : M) ∈ s)] : (U.mulIndicator fun _ => a) ⁻¹' s = (if a ∈ s then U else ∅) ∪ if (1 : M) ∈ s then Uᶜ else ∅ := by rw [mulIndicator_preimage, Pi.one_def, Set.preimage_const, preimage_const] split_ifs <;> simp [← compl_eq_univ_diff] @[to_additive] lemma mulIndicator_const_preimage (U : Set α) (s : Set M) (a : M) : (U.mulIndicator fun _ => a) ⁻¹' s ∈ ({Set.univ, U, Uᶜ, ∅} : Set (Set α)) := by classical rw [mulIndicator_const_preimage_eq_union] split_ifs <;> simp @[to_additive] lemma mulIndicator_preimage_of_notMem (s : Set α) (f : α → M) {t : Set M} (ht : (1 : M) ∉ t) : mulIndicator s f ⁻¹' t = f ⁻¹' t ∩ s := by simp [mulIndicator_preimage, Pi.one_def, Set.preimage_const_of_notMem ht] @[deprecated (since := "2025-05-23")] alias indicator_preimage_of_not_mem := indicator_preimage_of_notMem @[to_additive existing, deprecated (since := "2025-05-23")] alias mulIndicator_preimage_of_not_mem := mulIndicator_preimage_of_notMem @[to_additive] lemma mem_range_mulIndicator {r : M} {s : Set α} {f : α → M} : r ∈ range (mulIndicator s f) ↔ r = 1 ∧ s ≠ univ ∨ r ∈ f '' s := by simp [mulIndicator, ite_eq_iff, exists_or, eq_univ_iff_forall, and_comm, or_comm, @eq_comm _ r 1] @[to_additive] lemma mulIndicator_rel_mulIndicator {r : M → M → Prop} (h1 : r 1 1) (ha : a ∈ s → r (f a) (g a)) : r (mulIndicator s f a) (mulIndicator s g a) := by simp only [mulIndicator] split_ifs with has exacts [ha has, h1] lemma indicator_one_preimage [Zero M] (U : Set α) (s : Set M) : U.indicator 1 ⁻¹' s ∈ ({Set.univ, U, Uᶜ, ∅} : Set (Set α)) := indicator_const_preimage _ _ 1 end Set
.lake/packages/mathlib/Mathlib/Algebra/Notation/Lemmas.lean
import Batteries.Tactic.Init import Mathlib.Tactic.ToAdditive import Mathlib.Tactic.Lemma import Mathlib.Tactic.TypeStar import Mathlib.Util.AssertExists /-! # Lemmas about inequalities with `1`. -/ assert_not_exists Monoid variable {α : Type*} section dite variable [One α] {p : Prop} [Decidable p] {a : p → α} {b : ¬p → α} @[to_additive dite_nonneg] lemma one_le_dite [LE α] (ha : ∀ h, 1 ≤ a h) (hb : ∀ h, 1 ≤ b h) : 1 ≤ dite p a b := by split; exacts [ha ‹_›, hb ‹_›] @[to_additive] lemma dite_le_one [LE α] (ha : ∀ h, a h ≤ 1) (hb : ∀ h, b h ≤ 1) : dite p a b ≤ 1 := by split; exacts [ha ‹_›, hb ‹_›] @[to_additive dite_pos] lemma one_lt_dite [LT α] (ha : ∀ h, 1 < a h) (hb : ∀ h, 1 < b h) : 1 < dite p a b := by split; exacts [ha ‹_›, hb ‹_›] @[to_additive] lemma dite_lt_one [LT α] (ha : ∀ h, a h < 1) (hb : ∀ h, b h < 1) : dite p a b < 1 := by split; exacts [ha ‹_›, hb ‹_›] end dite section variable [One α] {p : Prop} [Decidable p] {a b : α} @[to_additive ite_nonneg] lemma one_le_ite [LE α] (ha : 1 ≤ a) (hb : 1 ≤ b) : 1 ≤ ite p a b := by split <;> assumption @[to_additive] lemma ite_le_one [LE α] (ha : a ≤ 1) (hb : b ≤ 1) : ite p a b ≤ 1 := by split <;> assumption @[to_additive ite_pos] lemma one_lt_ite [LT α] (ha : 1 < a) (hb : 1 < b) : 1 < ite p a b := by split <;> assumption @[to_additive] lemma ite_lt_one [LT α] (ha : a < 1) (hb : b < 1) : ite p a b < 1 := by split <;> assumption end
.lake/packages/mathlib/Mathlib/Algebra/Notation/Support.lean
import Mathlib.Algebra.Notation.Pi.Basic import Mathlib.Algebra.Notation.Prod import Mathlib.Data.Set.Image /-! # Support of a function In this file we define `Function.support f = {x | f x ≠ 0}` and prove its basic properties. We also define `Function.mulSupport f = {x | f x ≠ 1}`. -/ assert_not_exists Monoid CompleteLattice open Function Set variable {ι κ M N P : Type*} namespace Function variable [One M] [One N] [One P] {f g : ι → M} {s : Set ι} {x : ι} /-- `mulSupport` of a function is the set of points `x` such that `f x ≠ 1`. -/ @[to_additive /-- `support` of a function is the set of points `x` such that `f x ≠ 0`. -/] def mulSupport (f : ι → M) : Set ι := {x | f x ≠ 1} @[to_additive] lemma mulSupport_eq_preimage (f : ι → M) : mulSupport f = f ⁻¹' {1}ᶜ := rfl @[to_additive] lemma notMem_mulSupport : x ∉ mulSupport f ↔ f x = 1 := not_not @[deprecated (since := "2025-05-24")] alias nmem_support := notMem_support @[to_additive existing, deprecated (since := "2025-05-24")] alias nmem_mulSupport := notMem_mulSupport @[to_additive] lemma compl_mulSupport : (mulSupport f)ᶜ = {x | f x = 1} := ext fun _ ↦ notMem_mulSupport @[to_additive (attr := simp)] lemma mem_mulSupport : x ∈ mulSupport f ↔ f x ≠ 1 := .rfl @[to_additive (attr := simp)] lemma mulSupport_subset_iff : mulSupport f ⊆ s ↔ ∀ x, f x ≠ 1 → x ∈ s := .rfl @[to_additive] lemma mulSupport_subset_iff' : mulSupport f ⊆ s ↔ ∀ x ∉ s, f x = 1 := forall_congr' fun _ ↦ not_imp_comm @[to_additive] lemma mulSupport_eq_iff : mulSupport f = s ↔ (∀ x, x ∈ s → f x ≠ 1) ∧ ∀ x, x ∉ s → f x = 1 := by simp +contextual only [Set.ext_iff, mem_mulSupport, ne_eq, iff_def, not_imp_comm, and_comm, forall_and] @[to_additive] lemma ext_iff_mulSupport : f = g ↔ f.mulSupport = g.mulSupport ∧ ∀ x ∈ f.mulSupport, f x = g x where mp h := h ▸ ⟨rfl, fun _ _ ↦ rfl⟩ mpr := fun ⟨h₁, h₂⟩ ↦ funext fun x ↦ by if hx : x ∈ f.mulSupport then exact h₂ x hx else rw [notMem_mulSupport.1 hx, notMem_mulSupport.1 (mt (Set.ext_iff.1 h₁ x).2 hx)] @[to_additive] lemma mulSupport_update_of_ne_one [DecidableEq ι] (f : ι → M) (x : ι) {y : M} (hy : y ≠ 1) : mulSupport (update f x y) = insert x (mulSupport f) := by ext a; obtain rfl | hne := eq_or_ne a x <;> simp [*] @[to_additive] lemma mulSupport_update_one [DecidableEq ι] (f : ι → M) (x : ι) : mulSupport (update f x 1) = mulSupport f \ {x} := by ext a; obtain rfl | hne := eq_or_ne a x <;> simp [*] @[to_additive] lemma mulSupport_update_eq_ite [DecidableEq ι] [DecidableEq M] (f : ι → M) (x : ι) (y : M) : mulSupport (update f x y) = if y = 1 then mulSupport f \ {x} else insert x (mulSupport f) := by rcases eq_or_ne y 1 with rfl | hy <;> simp [mulSupport_update_one, mulSupport_update_of_ne_one, *] @[to_additive] lemma mulSupport_extend_one_subset {f : ι → κ} {g : ι → N} : mulSupport (f.extend g 1) ⊆ f '' mulSupport g := mulSupport_subset_iff'.mpr fun x hfg ↦ by by_cases hf : ∃ a, f a = x · rw [extend, dif_pos hf, ← notMem_mulSupport] rw [← Classical.choose_spec hf] at hfg exact fun hg ↦ hfg ⟨_, hg, rfl⟩ · rw [extend_apply' _ _ _ hf]; rfl @[to_additive] lemma mulSupport_extend_one {f : ι → κ} {g : ι → N} (hf : f.Injective) : mulSupport (f.extend g 1) = f '' mulSupport g := mulSupport_extend_one_subset.antisymm <| by rintro _ ⟨x, hx, rfl⟩; rwa [mem_mulSupport, hf.extend_apply] @[to_additive] lemma mulSupport_disjoint_iff : Disjoint (mulSupport f) s ↔ EqOn f 1 s := by simp_rw [← subset_compl_iff_disjoint_right, mulSupport_subset_iff', notMem_compl_iff, EqOn, Pi.one_apply] @[to_additive] lemma disjoint_mulSupport_iff : Disjoint s (mulSupport f) ↔ EqOn f 1 s := by rw [disjoint_comm, mulSupport_disjoint_iff] @[to_additive (attr := simp)] lemma mulSupport_eq_empty_iff : mulSupport f = ∅ ↔ f = 1 := by rw [← subset_empty_iff, mulSupport_subset_iff', funext_iff] simp @[to_additive (attr := simp)] lemma mulSupport_nonempty_iff : (mulSupport f).Nonempty ↔ f ≠ 1 := by rw [nonempty_iff_ne_empty, Ne, mulSupport_eq_empty_iff] @[to_additive] lemma range_subset_insert_image_mulSupport (f : ι → M) : range f ⊆ insert 1 (f '' mulSupport f) := by simpa only [range_subset_iff, mem_insert_iff, or_iff_not_imp_left] using fun x (hx : x ∈ mulSupport f) ↦ mem_image_of_mem f hx @[to_additive] lemma range_eq_image_or_of_mulSupport_subset {k : Set ι} (h : mulSupport f ⊆ k) : range f = f '' k ∨ range f = insert 1 (f '' k) := by have : range f ⊆ insert 1 (f '' k) := (range_subset_insert_image_mulSupport f).trans (insert_subset_insert (image_mono h)) grind @[to_additive (attr := simp)] lemma mulSupport_one : mulSupport (1 : ι → M) = ∅ := mulSupport_eq_empty_iff.2 rfl @[to_additive (attr := simp)] lemma mulSupport_fun_one : mulSupport (fun _ ↦ 1 : ι → M) = ∅ := mulSupport_one @[deprecated (since := "2025-07-31")] alias support_zero' := support_zero @[deprecated (since := "2025-07-31")] alias mulSupport_one' := mulSupport_one @[to_additive] lemma mulSupport_const {c : M} (hc : c ≠ 1) : (mulSupport fun _ : ι ↦ c) = Set.univ := by ext x; simp [hc] @[to_additive] lemma mulSupport_binop_subset (op : M → N → P) (op1 : op 1 1 = 1) (f : ι → M) (g : ι → N) : mulSupport (fun x ↦ op (f x) (g x)) ⊆ mulSupport f ∪ mulSupport g := fun x hx ↦ not_or_of_imp fun hf hg ↦ hx <| by simp only [hf, hg, op1] @[to_additive] lemma mulSupport_comp_subset {g : M → N} (hg : g 1 = 1) (f : ι → M) : mulSupport (g ∘ f) ⊆ mulSupport f := fun x ↦ mt fun h ↦ by simp only [(· ∘ ·), *] @[to_additive] lemma mulSupport_subset_comp {g : M → N} (hg : ∀ {x}, g x = 1 → x = 1) (f : ι → M) : mulSupport f ⊆ mulSupport (g ∘ f) := fun _ ↦ mt hg @[to_additive] lemma mulSupport_comp_eq (g : M → N) (hg : ∀ {x}, g x = 1 ↔ x = 1) (f : ι → M) : mulSupport (g ∘ f) = mulSupport f := Set.ext fun _ ↦ not_congr hg @[to_additive] lemma mulSupport_comp_eq_of_range_subset {g : M → N} {f : ι → M} (hg : ∀ {x}, x ∈ range f → (g x = 1 ↔ x = 1)) : mulSupport (g ∘ f) = mulSupport f := Set.ext fun x ↦ not_congr <| by rw [Function.comp, hg (mem_range_self x)] @[to_additive] lemma mulSupport_comp_eq_preimage (g : κ → M) (f : ι → κ) : mulSupport (g ∘ f) = f ⁻¹' mulSupport g := rfl @[to_additive support_prodMk] lemma mulSupport_prodMk (f : ι → M) (g : ι → N) : mulSupport (fun x ↦ (f x, g x)) = mulSupport f ∪ mulSupport g := Set.ext fun x ↦ by simp only [mulSupport, not_and_or, mem_union, mem_setOf_eq, Prod.mk_eq_one, Ne] @[to_additive support_prodMk'] lemma mulSupport_prodMk' (f : ι → M × N) : mulSupport f = (mulSupport fun x ↦ (f x).1) ∪ mulSupport fun x ↦ (f x).2 := by simp only [← mulSupport_prodMk] @[deprecated (since := "2025-07-31")] alias support_prod_mk := support_prodMk @[deprecated (since := "2025-07-31")] alias mulSupport_prod_mk := mulSupport_prodMk @[deprecated (since := "2025-07-31")] alias support_prod_mk' := support_prodMk' @[deprecated (since := "2025-07-31")] alias mulSupport_prod_mk' := mulSupport_prodMk' @[to_additive] lemma mulSupport_along_fiber_subset (f : ι × κ → M) (i : ι) : (mulSupport fun j ↦ f (i, j)) ⊆ (mulSupport f).image Prod.snd := fun j hj ↦ ⟨(i, j), by simpa using hj⟩ @[to_additive] lemma mulSupport_curry (f : ι × κ → M) : (mulSupport f.curry) = (mulSupport f).image Prod.fst := by simp [mulSupport, funext_iff, image] @[to_additive] lemma mulSupport_fun_curry (f : ι × κ → M) : mulSupport (fun i j ↦ f (i, j)) = (mulSupport f).image Prod.fst := mulSupport_curry f @[deprecated (since := "2025-07-31")] alias support_curry' := support_fun_curry @[deprecated (since := "2025-07-31")] alias mulSupport_curry' := mulSupport_fun_curry end Function namespace Set variable [One M] {f : ι → M} {s : Set κ} {g : κ → ι} @[to_additive] lemma image_inter_mulSupport_eq : g '' s ∩ mulSupport f = g '' (s ∩ mulSupport (f ∘ g)) := by rw [mulSupport_comp_eq_preimage f g, image_inter_preimage] end Set namespace Pi variable [DecidableEq ι] [One M] {i j : ι} {a b : M} @[to_additive] lemma mulSupport_mulSingle_subset : mulSupport (mulSingle i a) ⊆ {i} := fun _ hx ↦ by_contra fun hx' ↦ hx <| mulSingle_eq_of_ne hx' _ @[to_additive] lemma mulSupport_mulSingle_one : mulSupport (mulSingle i (1 : M)) = ∅ := by simp @[to_additive (attr := simp)] lemma mulSupport_mulSingle_of_ne (h : a ≠ 1) : mulSupport (mulSingle i a) = {i} := mulSupport_mulSingle_subset.antisymm fun x hx ↦ by rwa [mem_mulSupport, hx, mulSingle_eq_same] @[to_additive] lemma mulSupport_mulSingle [DecidableEq M] : mulSupport (mulSingle i a) = if a = 1 then ∅ else {i} := by split_ifs with h <;> simp [h] @[to_additive] lemma mulSupport_mulSingle_disjoint (ha : a ≠ 1) (hb : b ≠ 1) : Disjoint (mulSupport (mulSingle i a)) (mulSupport (mulSingle j b)) ↔ i ≠ j := by rw [mulSupport_mulSingle_of_ne ha, mulSupport_mulSingle_of_ne hb, disjoint_singleton] end Pi
.lake/packages/mathlib/Mathlib/Algebra/Notation/Prod.lean
import Mathlib.Util.AssertExists import Mathlib.Algebra.Notation.Defs import Mathlib.Data.Prod.Basic /-! # Arithmetic operators on (pairwise) product types This file provides only the notation for (componentwise) `0`, `1`, `+`, `*`, `•`, `^`, `⁻¹` on (pairwise) product types. See `Mathlib/Algebra/Group/Prod.lean` for the `Monoid` and `Group` instances. There is also an instance of the `Star` notation typeclass, but no default notation is included. -/ assert_not_exists Monoid DenselyOrdered variable {G H M N P R S : Type*} namespace Prod section One variable [One M] [One N] @[to_additive] instance instOne : One (M × N) := ⟨(1, 1)⟩ @[to_additive (attr := simp)] theorem fst_one : (1 : M × N).1 = 1 := rfl @[to_additive (attr := simp)] theorem snd_one : (1 : M × N).2 = 1 := rfl @[to_additive] theorem one_eq_mk : (1 : M × N) = (1, 1) := rfl @[to_additive] theorem mk_one_one : ((1 : M), (1 : N)) = 1 := rfl @[to_additive (attr := simp)] theorem mk_eq_one {x : M} {y : N} : (x, y) = 1 ↔ x = 1 ∧ y = 1 := mk_inj @[to_additive (attr := simp)] theorem swap_one : (1 : M × N).swap = 1 := rfl end One section Mul variable {M N : Type*} [Mul M] [Mul N] @[to_additive] instance instMul : Mul (M × N) := ⟨fun p q => ⟨p.1 * q.1, p.2 * q.2⟩⟩ @[to_additive (attr := simp)] theorem fst_mul (p q : M × N) : (p * q).1 = p.1 * q.1 := rfl @[to_additive (attr := simp)] theorem snd_mul (p q : M × N) : (p * q).2 = p.2 * q.2 := rfl @[to_additive (attr := simp)] theorem mk_mul_mk (a₁ a₂ : M) (b₁ b₂ : N) : (a₁, b₁) * (a₂, b₂) = (a₁ * a₂, b₁ * b₂) := rfl @[to_additive (attr := simp)] theorem swap_mul (p q : M × N) : (p * q).swap = p.swap * q.swap := rfl @[to_additive] theorem mul_def (p q : M × N) : p * q = (p.1 * q.1, p.2 * q.2) := rfl end Mul section Inv variable {G H : Type*} [Inv G] [Inv H] @[to_additive] instance instInv : Inv (G × H) := ⟨fun p => (p.1⁻¹, p.2⁻¹)⟩ @[to_additive (attr := simp)] theorem fst_inv (p : G × H) : p⁻¹.1 = p.1⁻¹ := rfl @[to_additive (attr := simp)] theorem snd_inv (p : G × H) : p⁻¹.2 = p.2⁻¹ := rfl @[to_additive (attr := simp)] theorem inv_mk (a : G) (b : H) : (a, b)⁻¹ = (a⁻¹, b⁻¹) := rfl @[to_additive (attr := simp)] theorem swap_inv (p : G × H) : p⁻¹.swap = p.swap⁻¹ := rfl end Inv section Div variable {G H : Type*} [Div G] [Div H] @[to_additive] instance instDiv : Div (G × H) := ⟨fun p q => ⟨p.1 / q.1, p.2 / q.2⟩⟩ @[to_additive (attr := simp)] theorem fst_div (a b : G × H) : (a / b).1 = a.1 / b.1 := rfl @[to_additive (attr := simp)] theorem snd_div (a b : G × H) : (a / b).2 = a.2 / b.2 := rfl @[to_additive (attr := simp)] theorem mk_div_mk (x₁ x₂ : G) (y₁ y₂ : H) : (x₁, y₁) / (x₂, y₂) = (x₁ / x₂, y₁ / y₂) := rfl @[to_additive (attr := simp)] theorem swap_div (a b : G × H) : (a / b).swap = a.swap / b.swap := rfl @[to_additive] lemma div_def (a b : G × H) : a / b = (a.1 / b.1, a.2 / b.2) := rfl end Div section SMul variable {M α β : Type*} [SMul M α] [SMul M β] @[to_additive] instance instSMul : SMul M (α × β) where smul a p := (a • p.1, a • p.2) @[to_additive (attr := simp)] lemma smul_fst (a : M) (x : α × β) : (a • x).1 = a • x.1 := rfl @[to_additive (attr := simp)] lemma smul_snd (a : M) (x : α × β) : (a • x).2 = a • x.2 := rfl @[to_additive (attr := simp)] lemma smul_mk (a : M) (b : α) (c : β) : a • (b, c) = (a • b, a • c) := rfl @[to_additive] lemma smul_def (a : M) (x : α × β) : a • x = (a • x.1, a • x.2) := rfl @[to_additive (attr := simp)] lemma smul_swap (a : M) (x : α × β) : (a • x).swap = a • x.swap := rfl end SMul section Pow variable {E α β : Type*} [Pow α E] [Pow β E] @[to_additive existing instSMul] instance instPow : Pow (α × β) E where pow p c := (p.1 ^ c, p.2 ^ c) @[to_additive existing (attr := simp) (reorder := 6 7) smul_fst] lemma pow_fst (p : α × β) (c : E) : (p ^ c).fst = p.fst ^ c := rfl @[to_additive existing (attr := simp) (reorder := 6 7) smul_snd] lemma pow_snd (p : α × β) (c : E) : (p ^ c).snd = p.snd ^ c := rfl @[to_additive existing (attr := simp) (reorder := 6 7 8) smul_mk] lemma pow_mk (a : α) (b : β) (c : E) : Prod.mk a b ^ c = Prod.mk (a ^ c) (b ^ c) := rfl @[to_additive existing (reorder := 6 7) smul_def] lemma pow_def (p : α × β) (c : E) : p ^ c = (p.1 ^ c, p.2 ^ c) := rfl @[to_additive existing (attr := simp) (reorder := 6 7) smul_swap] lemma pow_swap (p : α × β) (c : E) : (p ^ c).swap = p.swap ^ c := rfl end Pow section Star variable [Star R] [Star S] instance : Star (R × S) where star x := (star x.1, star x.2) @[simp] theorem fst_star (x : R × S) : (star x).1 = star x.1 := rfl @[simp] theorem snd_star (x : R × S) : (star x).2 = star x.2 := rfl theorem star_def (x : R × S) : star x = (star x.1, star x.2) := rfl end Star end Prod
.lake/packages/mathlib/Mathlib/Algebra/Notation/README.md
# Basic algebraic notation This subfolder contains definitions and very minimal theory related to the basic algebraic operators like `0`, `1`, `+`, `-`, `*`, `/`, `+ᵥ`, `•`, `-ᵥ`. The files in this subfolder should stay extremely early in the import hierarchy, and in particular are forbidden from importing anything from `Algebra` outside of that subfolder.
.lake/packages/mathlib/Mathlib/Algebra/Notation/Defs.lean
import Mathlib.Tactic.Lemma import Mathlib.Tactic.TypeStar import Mathlib.Tactic.ToAdditive import Mathlib.Util.AssertExists /-! # Typeclasses for algebraic operations Notation typeclass for `Inv`, the multiplicative analogue of `Neg`. We also introduce notation classes `SMul` and `VAdd` for multiplicative and additive actions. We introduce the notation typeclass `Star` for algebraic structures with a star operation. Note: to accommodate diverse notational preferences, no default notation is provided for `Star.star`. `SMul` is typically, but not exclusively, used for scalar multiplication-like operators. See the module `Algebra.AddTorsor` for a motivating example for the name `VAdd` (vector addition). Note `Zero` has already been defined in core Lean. ## Notation - `a • b` is used as notation for `HSMul.hSMul a b`. - `a +ᵥ b` is used as notation for `HVAdd.hVAdd a b`. -/ assert_not_exists Function.Bijective universe u v w /-- The notation typeclass for heterogeneous additive actions. This enables the notation `a +ᵥ b : γ` where `a : α`, `b : β`. -/ class HVAdd (α : Type u) (β : Type v) (γ : outParam (Type w)) where /-- `a +ᵥ b` computes the sum of `a` and `b`. The meaning of this notation is type-dependent. -/ hVAdd : α → β → γ attribute [notation_class smul Simps.copySecond] HSMul attribute [notation_class nsmul Simps.nsmulArgs] HSMul attribute [notation_class zsmul Simps.zsmulArgs] HSMul /-- Type class for the `+ᵥ` notation. -/ class VAdd (G : Type u) (P : Type v) where /-- `a +ᵥ b` computes the sum of `a` and `b`. The meaning of this notation is type-dependent, but it is intended to be used for left actions. -/ vadd : G → P → P /-- Type class for the `-ᵥ` notation. -/ class VSub (G : outParam Type*) (P : Type*) where /-- `a -ᵥ b` computes the difference of `a` and `b`. The meaning of this notation is type-dependent, but it is intended to be used for additive torsors. -/ vsub : P → P → G attribute [to_additive] SMul attribute [ext] SMul VAdd @[inherit_doc] infixr:65 " +ᵥ " => HVAdd.hVAdd @[inherit_doc] infixl:65 " -ᵥ " => VSub.vsub attribute [to_additive existing] Mul Div HMul instHMul HDiv instHDiv HSMul attribute [to_additive (reorder := 1 2) SMul] Pow attribute [to_additive (reorder := 1 2)] HPow attribute [to_additive existing (reorder := 1 2, 5 6) hSMul] HPow.hPow attribute [to_additive existing (reorder := 1 2, 4 5) smul] Pow.pow attribute [to_additive (attr := default_instance)] instHSMul attribute [to_additive existing (reorder := 1 2)] instHPow variable {G : Type*} attribute [to_additive, notation_class] Inv section Star /-- Notation typeclass (with no default notation!) for an algebraic structure with a star operation. -/ class Star (R : Type u) where star : R → R export Star (star) /-- A star operation (e.g. complex conjugate). -/ add_decl_doc star end Star section ite variable {α : Type*} (P : Prop) [Decidable P] section Mul variable [Mul α] @[to_additive] lemma mul_dite (a : α) (b : P → α) (c : ¬P → α) : (a * if h : P then b h else c h) = if h : P then a * b h else a * c h := by split <;> rfl @[to_additive] lemma mul_ite (a b c : α) : (a * if P then b else c) = if P then a * b else a * c := mul_dite .. @[to_additive] lemma dite_mul (a : P → α) (b : ¬P → α) (c : α) : (if h : P then a h else b h) * c = if h : P then a h * c else b h * c := by split <;> rfl @[to_additive] lemma ite_mul (a b c : α) : (if P then a else b) * c = if P then a * c else b * c := dite_mul .. -- We make `mul_ite` and `ite_mul` simp lemmas, but not `add_ite` or `ite_add`. -- The problem we're trying to avoid is dealing with sums of the form `∑ x ∈ s, (f x + ite P 1 0)`, -- in which `add_ite` followed by `sum_ite` would needlessly slice up -- the `f x` terms according to whether `P` holds at `x`. -- There doesn't appear to be a corresponding difficulty so far with `mul_ite` and `ite_mul`. attribute [simp] mul_dite dite_mul mul_ite ite_mul @[to_additive] lemma dite_mul_dite (a : P → α) (b : ¬P → α) (c : P → α) (d : ¬P → α) : ((if h : P then a h else b h) * if h : P then c h else d h) = if h : P then a h * c h else b h * d h := by split <;> rfl @[to_additive] lemma ite_mul_ite (a b c d : α) : ((if P then a else b) * if P then c else d) = if P then a * c else b * d := by split <;> rfl end Mul section Div variable [Div α] @[to_additive] lemma div_dite (a : α) (b : P → α) (c : ¬P → α) : (a / if h : P then b h else c h) = if h : P then a / b h else a / c h := by split <;> rfl @[to_additive] lemma div_ite (a b c : α) : (a / if P then b else c) = if P then a / b else a / c := div_dite .. @[to_additive] lemma dite_div (a : P → α) (b : ¬P → α) (c : α) : (if h : P then a h else b h) / c = if h : P then a h / c else b h / c := by split <;> rfl @[to_additive] lemma ite_div (a b c : α) : (if P then a else b) / c = if P then a / c else b / c := dite_div .. @[to_additive] lemma dite_div_dite (a : P → α) (b : ¬P → α) (c : P → α) (d : ¬P → α) : ((if h : P then a h else b h) / if h : P then c h else d h) = if h : P then a h / c h else b h / d h := by split <;> rfl @[to_additive] lemma ite_div_ite (a b c d : α) : ((if P then a else b) / if P then c else d) = if P then a / c else b / d := dite_div_dite .. end Div end ite variable {α : Type u} instance (priority := 20) Zero.instNonempty [Zero α] : Nonempty α := ⟨0⟩ instance (priority := 20) One.instNonempty [One α] : Nonempty α := ⟨1⟩ @[to_additive] theorem Subsingleton.eq_one [One α] [Subsingleton α] (a : α) : a = 1 := Subsingleton.elim _ _
.lake/packages/mathlib/Mathlib/Algebra/Notation/FiniteSupport.lean
import Mathlib.Algebra.Notation.Support import Mathlib.Data.Set.Finite.Basic /-! # Finiteness of support -/ assert_not_exists Monoid namespace Function variable {α β γ : Type*} [One γ] @[to_additive (attr := simp)] lemma mulSupport_along_fiber_finite_of_finite (f : α × β → γ) (a : α) (h : (mulSupport f).Finite) : (mulSupport fun b ↦ f (a, b)).Finite := (h.image Prod.snd).subset (mulSupport_along_fiber_subset f a) end Function
.lake/packages/mathlib/Mathlib/Algebra/Notation/Pi/Basic.lean
import Mathlib.Algebra.Notation.Pi.Defs import Mathlib.Logic.Function.Basic /-! # Very basic algebraic operations on pi types This file provides very basic algebraic operations on functions. -/ assert_not_exists Monoid Preorder open Function variable {ι ι' α β : Type*} {G M N O : ι → Type*} namespace Pi variable [∀ i, One (M i)] [∀ i, One (N i)] [∀ i, One (O i)] [DecidableEq ι] {i : ι} {x : M i} /-- The function supported at `i`, with value `x` there, and `1` elsewhere. -/ @[to_additive /-- The function supported at `i`, with value `x` there, and `0` elsewhere. -/] def mulSingle (i : ι) (x : M i) : ∀ j, M j := Function.update 1 i x @[to_additive (attr := simp)] lemma mulSingle_eq_same (i : ι) (x : M i) : mulSingle i x i = x := Function.update_self i x _ @[to_additive (attr := simp)] lemma mulSingle_eq_of_ne {i i' : ι} (h : i' ≠ i) (x : M i) : mulSingle i x i' = 1 := Function.update_of_ne h x _ /-- Abbreviation for `mulSingle_eq_of_ne h.symm`, for ease of use by `simp`. -/ @[to_additive (attr := simp) /-- Abbreviation for `single_eq_of_ne h.symm`, for ease of use by `simp`. -/] lemma mulSingle_eq_of_ne' {i i' : ι} (h : i ≠ i') (x : M i) : mulSingle i x i' = 1 := mulSingle_eq_of_ne h.symm x @[to_additive (attr := simp)] lemma mulSingle_one (i : ι) : mulSingle i (1 : M i) = 1 := Function.update_eq_self _ _ @[to_additive (attr := simp)] lemma mulSingle_eq_one_iff : mulSingle i x = 1 ↔ x = 1 := by refine ⟨fun h => ?_, fun h => h.symm ▸ mulSingle_one i⟩ rw [← mulSingle_eq_same i x, h, one_apply] @[to_additive] lemma mulSingle_ne_one_iff : mulSingle i x ≠ 1 ↔ x ≠ 1 := mulSingle_eq_one_iff.ne @[to_additive] lemma apply_mulSingle (f' : ∀ i, M i → N i) (hf' : ∀ i, f' i 1 = 1) (i : ι) (x : M i) (j : ι) : f' j (mulSingle i x j) = mulSingle i (f' i x) j := by simpa only [Pi.one_apply, hf', mulSingle] using Function.apply_update f' 1 i x j @[to_additive apply_single₂] lemma apply_mulSingle₂ (f' : ∀ i, M i → N i → O i) (hf' : ∀ i, f' i 1 1 = 1) (i : ι) (x : M i) (y : N i) (j : ι) : f' j (mulSingle i x j) (mulSingle i y j) = mulSingle i (f' i x y) j := by by_cases h : j = i · subst h simp only [mulSingle_eq_same] · simp only [mulSingle_eq_of_ne h, hf'] @[to_additive] lemma mulSingle_op (op : ∀ i, M i → N i) (h : ∀ i, op i 1 = 1) (i : ι) (x : M i) : mulSingle i (op i x) = fun j => op j (mulSingle i x j) := .symm <| funext <| apply_mulSingle op h i x @[to_additive] lemma mulSingle_op₂ (op : ∀ i, M i → N i → O i) (h : ∀ i, op i 1 1 = 1) (i : ι) (x : M i) (y : N i) : mulSingle i (op i x y) = fun j ↦ op j (mulSingle i x j) (mulSingle i y j) := .symm <| funext <| apply_mulSingle₂ op h i x y @[to_additive] lemma mulSingle_injective (i : ι) : Function.Injective (mulSingle i : M i → ∀ i, M i) := Function.update_injective _ i @[to_additive (attr := simp)] lemma mulSingle_inj (i : ι) {x y : M i} : mulSingle i x = mulSingle i y ↔ x = y := (mulSingle_injective _).eq_iff variable {M : Type*} [One M] /-- On non-dependent functions, `Pi.mulSingle` can be expressed as an `ite` -/ @[to_additive /-- On non-dependent functions, `Pi.single` can be expressed as an `ite` -/] lemma mulSingle_apply (i : ι) (x : M) (i' : ι) : (mulSingle i x : ι → M) i' = if i' = i then x else 1 := Function.update_apply (1 : ι → M) i x i' -- Porting note: added type ascription (_ : ι → M) /-- On non-dependent functions, `Pi.mulSingle` is symmetric in the two indices. -/ @[to_additive /-- On non-dependent functions, `Pi.single` is symmetric in the two indices. -/] lemma mulSingle_comm (i : ι) (x : M) (j : ι) : (mulSingle i x : ι → M) j = (mulSingle j x : ι → M) i := by simp [mulSingle_apply, eq_comm] variable [DecidableEq ι'] @[to_additive (attr := simp)] theorem curry_mulSingle (i : ι × ι') (b : M) : curry (Pi.mulSingle i b) = Pi.mulSingle i.1 (Pi.mulSingle i.2 b) := curry_update _ _ _ @[to_additive (attr := simp)] theorem uncurry_mulSingle_mulSingle (i : ι) (i' : ι') (b : M) : uncurry (Pi.mulSingle i (Pi.mulSingle i' b)) = Pi.mulSingle (i, i') b := uncurry_update_update _ _ _ _ end Pi
.lake/packages/mathlib/Mathlib/Algebra/Notation/Pi/Defs.lean
import Mathlib.Algebra.Notation.Defs import Mathlib.Util.AssertExists import Mathlib.Tactic.Push.Attr /-! # Notation for algebraic operators on pi types This file provides only the notation for (pointwise) `0`, `1`, `+`, `*`, `•`, `^`, `⁻¹` on pi types. See `Mathlib/Algebra/Group/Pi/Basic.lean` for the `Monoid` and `Group` instances. There is also an instance of the `Star` notation typeclass, but no default notation is included. -/ assert_not_exists Set.range Monoid Preorder open Function variable {ι α β : Type*} {G M R : ι → Type*} namespace Pi -- TODO: Do we really need this definition? If so, where to put it? /-- The mapping into a product type built from maps into each component. -/ @[simp] protected def prod {α β : ι → Type*} (f : ∀ i, α i) (g : ∀ i, β i) (i : ι) : α i × β i := (f i, g i) lemma prod_fst_snd : Pi.prod (Prod.fst : α × β → α) (Prod.snd : α × β → β) = id := rfl lemma prod_snd_fst : Pi.prod (Prod.snd : α × β → β) (Prod.fst : α × β → α) = .swap := rfl /-! `1`, `0`, `+`, `*`, `+ᵥ`, `•`, `^`, `-`, `⁻¹`, and `/` are defined pointwise. -/ section One variable [∀ i, One (M i)] @[to_additive] instance instOne : One (∀ i, M i) where one _ := 1 @[to_additive (attr := simp high)] lemma one_apply (i : ι) : (1 : ∀ i, M i) i = 1 := rfl @[to_additive (attr := push ← high)] lemma one_def : (1 : ∀ i, M i) = fun _ ↦ 1 := rfl variable {M : Type*} [One M] @[to_additive (attr := simp)] lemma _root_.Function.const_one : const α (1 : M) = 1 := rfl @[to_additive (attr := simp)] lemma one_comp (f : α → β) : (1 : β → M) ∘ f = 1 := rfl @[to_additive (attr := simp)] lemma comp_one (f : M → β) : f ∘ (1 : α → M) = const α (f 1) := rfl end One section Mul variable [∀ i, Mul (M i)] @[to_additive] instance instMul : Mul (∀ i, M i) where mul f g i := f i * g i @[to_additive (attr := simp)] lemma mul_apply (f g : ∀ i, M i) (i : ι) : (f * g) i = f i * g i := rfl @[to_additive (attr := push ←)] lemma mul_def (f g : ∀ i, M i) : f * g = fun i ↦ f i * g i := rfl variable {M : Type*} [Mul M] @[to_additive (attr := simp)] lemma _root_.Function.const_mul (a b : M) : const ι a * const ι b = const ι (a * b) := rfl @[to_additive] lemma mul_comp (f g : β → M) (z : α → β) : (f * g) ∘ z = f ∘ z * g ∘ z := rfl end Mul section Inv variable [∀ i, Inv (G i)] @[to_additive] instance instInv : Inv (∀ i, G i) where inv f i := (f i)⁻¹ @[to_additive (attr := simp)] lemma inv_apply (f : ∀ i, G i) (i : ι) : f⁻¹ i = (f i)⁻¹ := rfl @[to_additive (attr := push ←)] lemma inv_def (f : ∀ i, G i) : f⁻¹ = fun i ↦ (f i)⁻¹ := rfl variable {G : Type*} [Inv G] @[to_additive] lemma _root_.Function.const_inv (a : G) : (const ι a)⁻¹ = const ι a⁻¹ := rfl @[to_additive] lemma inv_comp (f : β → G) (g : α → β) : f⁻¹ ∘ g = (f ∘ g)⁻¹ := rfl end Inv section Div variable [∀ i, Div (G i)] @[to_additive] instance instDiv : Div (∀ i, G i) where div f g i := f i / g i @[to_additive (attr := simp)] lemma div_apply (f g : ∀ i, G i) (i : ι) : (f / g) i = f i / g i := rfl @[to_additive (attr := push ←)] lemma div_def (f g : ∀ i, G i) : f / g = fun i ↦ f i / g i := rfl variable {G : Type*} [Div G] @[to_additive] lemma div_comp (f g : β → G) (z : α → β) : (f / g) ∘ z = f ∘ z / g ∘ z := rfl @[to_additive (attr := simp)] lemma _root_.Function.const_div (a b : G) : const ι a / const ι b = const ι (a / b) := rfl end Div section Pow @[to_additive] instance instSMul [∀ i, SMul α (M i)] : SMul α (∀ i, M i) where smul a f i := a • f i variable [∀ i, Pow (M i) α] @[to_additive existing instSMul] instance instPow : Pow (∀ i, M i) α where pow f a i := f i ^ a @[to_additive (attr := simp, to_additive) (reorder := 5 6) smul_apply] lemma pow_apply (f : ∀ i, M i) (a : α) (i : ι) : (f ^ a) i = f i ^ a := rfl @[to_additive (attr := push ←, to_additive) (reorder := 5 6) smul_def] lemma pow_def (f : ∀ i, M i) (a : α) : f ^ a = fun i ↦ f i ^ a := rfl variable {M : Type*} [Pow M α] @[to_additive (attr := simp, to_additive) (reorder := 2 3, 5 6) smul_const] lemma _root_.Function.const_pow (a : M) (b : α) : const ι a ^ b = const ι (a ^ b) := rfl @[to_additive (attr := to_additive) (reorder := 6 7) smul_comp] lemma pow_comp (f : β → M) (a : α) (g : ι → β) : (f ^ a) ∘ g = f ∘ g ^ a := rfl end Pow section Star variable [∀ i, Star (R i)] instance : Star (∀ i, R i) where star x i := star (x i) @[simp] theorem star_apply (x : ∀ i, R i) (i : ι) : star x i = star (x i) := rfl @[push ←] theorem star_def (x : ∀ i, R i) : star x = fun i => star (x i) := rfl end Star end Pi
.lake/packages/mathlib/Mathlib/Algebra/SkewMonoidAlgebra/Support.lean
import Mathlib.Algebra.Group.Pointwise.Finset.Basic import Mathlib.Algebra.SkewMonoidAlgebra.Basic /-! # Lemmas about the support of an element of a skew monoid algebra For `f : SkewMonoidAlgebra k G`, `f.support` is the set of all `a ∈ G` such that `f.coeff a ≠ 0`. -/ open scoped Pointwise namespace SkewMonoidAlgebra open Finset Finsupp variable {k G : Type*} section AddCommMonoid variable [AddCommMonoid k] {a : G} {b : k} theorem support_single_ne_zero (a : G) (h : b ≠ 0) : (single a b).support = {a} := Finsupp.support_single_ne_zero _ h theorem support_single_subset : (single a b).support ⊆ {a} := Finsupp.support_single_subset theorem support_sum {k' G' : Type*} [DecidableEq G'] [AddCommMonoid k'] {f : SkewMonoidAlgebra k G} {g : G → k → SkewMonoidAlgebra k' G'} : (f.sum g).support ⊆ f.support.biUnion fun a ↦ (g a (f.coeff a)).support := by simp_rw [support, toFinsupp_sum'] apply Finsupp.support_sum end AddCommMonoid section AddCommGroup variable [AddCommGroup k] theorem support_neg (p : SkewMonoidAlgebra k G) : (-p).support = p.support := by rw [support, toFinsupp_neg, Finsupp.support_neg, support_toFinsupp] end AddCommGroup section AddCommMonoidWithOne variable [One G] [AddCommMonoidWithOne k] lemma support_one_subset : (1 : SkewMonoidAlgebra k G).support ⊆ 1 := Finsupp.support_single_subset @[simp] lemma support_one [NeZero (1 : k)] : (1 : SkewMonoidAlgebra k G).support = 1 := Finsupp.support_single_ne_zero _ one_ne_zero end AddCommMonoidWithOne section Semiring variable [Monoid G] [Semiring k] [MulSemiringAction G k] variable (f g : SkewMonoidAlgebra k G) section DecidableEq variable [DecidableEq G] theorem support_mul : (f * g).support ⊆ f.support * g.support := support_sum.trans <| biUnion_subset.2 fun _x hx ↦ support_sum.trans <| biUnion_subset.2 fun _y hy ↦ support_single_subset.trans <| singleton_subset_iff.2 <| mem_image₂_of_mem hx hy theorem support_single_mul_subset (r : k) (a : G) : (single a r * f : SkewMonoidAlgebra k G).support ⊆ Finset.image (a * ·) f.support := (support_mul _ _).trans <| (Finset.image₂_subset_right support_single_subset).trans <| by rw [Finset.image₂_singleton_left] theorem support_mul_single_subset (r : k) (a : G) : (f * single a r).support ⊆ Finset.image (· * a) f.support := (support_mul _ _).trans <| (Finset.image₂_subset_left support_single_subset).trans <| by rw [Finset.image₂_singleton_right] theorem support_single_mul_eq_image {r : k} {x : G} (lx : IsLeftRegular x) (hrx : ∀ y, r * x • y = 0 ↔ y = 0) : (single x r * f : SkewMonoidAlgebra k G).support = Finset.image (x * ·) f.support := by refine subset_antisymm (support_single_mul_subset f _ _) fun y hy ↦ ?_ obtain ⟨y, yf, rfl⟩ : ∃ a : G, a ∈ f.support ∧ x * a = y := by simpa only [Finset.mem_image, exists_prop] using hy simp [coeff_mul, mem_support_iff.mp yf, hrx, mem_support_iff, sum_single_index, Ne, zero_mul, ite_self, sum_zero, lx.eq_iff] theorem support_mul_single_eq_image {r : k} {x : G} (rx : IsRightRegular x) (hrx : ∀ g : G, ∀ y, y * g • r = 0 ↔ y = 0) : (f * single x r).support = Finset.image (· * x) f.support := by refine subset_antisymm (support_mul_single_subset f _ _) fun y hy ↦ ?_ obtain ⟨y, yf, rfl⟩ : ∃ a : G, a ∈ f.support ∧ a * x = y := by simpa only [Finset.mem_image, exists_prop] using hy simp [coeff_mul, mem_support_iff.mp yf, hrx, mem_support_iff, sum_single_index, mul_zero, ite_self, rx.eq_iff] end DecidableEq theorem support_mul_single [IsRightCancelMul G] (r : k) (x : G) (hrx : ∀ g : G, ∀ y, y * g • r = 0 ↔ y = 0) : (f * single x r).support = f.support.map (mulRightEmbedding x) := by classical ext a simp [support_mul_single_eq_image f (IsRightRegular.all x) hrx] theorem support_single_mul [IsLeftCancelMul G] (r : k) (x : G) (hrx : ∀ y, r * x • y = 0 ↔ y = 0) : (single x r * f : SkewMonoidAlgebra k G).support = f.support.map (mulLeftEmbedding x) := by classical ext a simp [support_single_mul_eq_image f (IsLeftRegular.all x) hrx] section Span /-- An element of `SkewMonoidAlgebra k G` is in the subalgebra generated by its support. -/ theorem mem_span_support (f : SkewMonoidAlgebra k G) : f ∈ Submodule.span k (of k G '' (f.support : Set G)) := by rw [Fintype.mem_span_image_iff_exists_fun k] use Finset.restrict f.support f.coeff simp [smul_single, ← sum_def', sum_single] end Span end Semiring end SkewMonoidAlgebra
.lake/packages/mathlib/Mathlib/Algebra/SkewMonoidAlgebra/Single.lean
import Mathlib.Algebra.SkewMonoidAlgebra.Basic /-! # Modifying skew monoid algebra at exactly one point This file contains basic results on updating/erasing an element of a skew monoid algebras using one point of the domain. -/ noncomputable section namespace SkewMonoidAlgebra variable {k G H : Type*} section erase variable {M α : Type*} [AddCommMonoid M] (a a' : α) (b : M) (f : SkewMonoidAlgebra M α) /-- Given an element `f` of a skew monoid algebra, `erase a f` is an element with the same coefficients as `f` except at `a` where the coefficient is `0`. If `a` is not in the support of `f` then `erase a f = f`. -/ @[simps] def erase : SkewMonoidAlgebra M α →+ SkewMonoidAlgebra M α where toFun f := ⟨f.toFinsupp.erase a⟩ map_zero' := by simp map_add' := by simp @[simp] theorem support_erase [DecidableEq α] : (f.erase a).support = f.support.erase a := by ext; simp [erase] @[simp] theorem coeff_erase_same : (f.erase a).coeff a = 0 := by simp [erase] variable {a a'} in @[simp] theorem coeff_erase_ne (h : a' ≠ a) : (f.erase a).coeff a' = f.coeff a' := by simp [erase, h] @[simp] theorem erase_single : erase a (single a b) = 0 := by simp [erase] theorem coeff_erase_apply [DecidableEq α] : (f.erase a).coeff a' = if a' = a then 0 else f.coeff a' := ite_congr rfl (fun _ ↦ rfl) (fun _ ↦ rfl) theorem single_add_erase (a : α) (f : SkewMonoidAlgebra M α) : single a (f.coeff a) + f.erase a = f := by apply toFinsupp_injective rw [single, ← toFinsupp_apply, toFinsupp_add, erase_apply_toFinsupp, Finsupp.single_add_erase] @[elab_as_elim] theorem induction {p : SkewMonoidAlgebra M α → Prop} (f : SkewMonoidAlgebra M α) (h0 : p 0) (ha : ∀ (a b) (f : SkewMonoidAlgebra M α), a ∉ f.support → b ≠ 0 → p f → p (single a b + f)) : p f := suffices ∀ (s) (f : SkewMonoidAlgebra M α), f.support = s → p f from this _ _ rfl fun s ↦ Finset.cons_induction_on s (fun f hf ↦ by rwa [support_eq_empty.1 hf]) fun a s has ih f hf ↦ by suffices p (single a (f.coeff a) + f.erase a) by rwa [single_add_erase] at this classical apply ha · rw [support_erase, Finset.mem_erase] exact fun H ↦ H.1 rfl · simp only [← mem_support_iff, hf, Finset.mem_cons_self] · apply ih rw [support_erase, hf, Finset.erase_cons] end erase section update variable {M α : Type*} [AddCommMonoid M] (f : SkewMonoidAlgebra M α) (a a' : α) (b : M) /-- Replace the coefficent of an element `f` of a skew monoid algebra at a given point `a : α` by a given value `b : M`. If `b = 0`, this amounts to removing `a` from the support of `f`. Otherwise, if `a` was not in the `support` of `f`, it is added to it. -/ @[simps] def update : SkewMonoidAlgebra M α := ⟨f.toFinsupp.update a b⟩ @[simp] theorem update_self : f.update a (f.coeff a) = f := by rcases f with ⟨f⟩ apply toFinsupp_injective simp @[simp] theorem zero_update : update 0 a b = single a b := by simp [update] theorem support_update [DecidableEq α] [DecidableEq M] : support (f.update a b) = if b = 0 then f.support.erase a else insert a f.support := by aesop (add norm [update, Finsupp.support_update_ne_zero]) theorem coeff_update [DecidableEq α] : (f.update a b).coeff = Function.update f.coeff a b := by simp only [coeff, update, Finsupp.update, Finsupp.coe_mk] congr! theorem coeff_update_apply [DecidableEq α] : (f.update a b).coeff a' = if a' = a then b else f.coeff a' := by rw [coeff_update, Function.update_apply] @[simp] theorem coeff_update_same : (f.update a b).coeff a = b := by classical rw [f.coeff_update_apply, if_pos rfl] variable {a a'} in @[simp] theorem coeff_update_ne (h : a' ≠ a) : (f.update a b).coeff a' = f.coeff a' := by classical rw [f.coeff_update_apply, if_neg h] theorem update_eq_erase_add_single : f.update a b = f.erase a + single a b := by classical ext x; by_cases hx : x = a <;> aesop (add norm coeff_single_apply) @[simp] theorem update_zero_eq_erase : f.update a 0 = f.erase a := by classical ext; simp [coeff_update_apply, coeff_erase_apply] end update end SkewMonoidAlgebra
.lake/packages/mathlib/Mathlib/Algebra/SkewMonoidAlgebra/Basic.lean
import Mathlib.LinearAlgebra.FreeModule.Basic import Mathlib.Algebra.Algebra.NonUnitalHom /-! # Skew Monoid Algebras Given a monoid `G` acting on a ring `k`, the skew monoid algebra of `G` over `k` is the set of finitely supported functions `f : G → k` for which addition is defined pointwise and multiplication of two elements `f` and `g` is given by the finitely supported function whose value at `a` is the sum of `f x * (x • g y)` over all pairs `x, y` such that `x * y = a`, where `•` denotes the action of `G` on `k`. When this action is trivial, this product is the usual convolution product. In fact the construction of the skew monoid algebra makes sense when `G` is not even a monoid, but merely a magma, i.e., when `G` carries a multiplication which is not required to satisfy any conditions at all, and `k` is a not-necessarily-associative semiring. In this case the construction yields a not-necessarily-unital, not-necessarily-associative algebra. ## Main Definitions - `SkewMonoidAlgebra k G`: the skew monoid algebra of `G` over `k` is the type of finite formal `k`-linear combinations of terms of `G`, endowed with a skewed convolution product. -/ noncomputable section /-- The skew monoid algebra of `G` over `k` is the type of finite formal `k`-linear combinations of terms of `G`, endowed with a skewed convolution product. -/ structure SkewMonoidAlgebra (k : Type*) (G : Type*) [Zero k] where /-- The natural map from `G →₀ k` to `SkewMonoidAlgebra k G`. -/ ofFinsupp :: /-- The natural map from `SkewMonoidAlgebra k G` to `G →₀ k`. -/ toFinsupp : G →₀ k open Function namespace SkewMonoidAlgebra variable {k G : Type*} section AddMonoid variable [AddMonoid k] @[simp] theorem eta (f : SkewMonoidAlgebra k G) : ofFinsupp f.toFinsupp = f := rfl @[irreducible] private def add : SkewMonoidAlgebra k G → SkewMonoidAlgebra k G → SkewMonoidAlgebra k G | ⟨a⟩, ⟨b⟩ => ⟨a + b⟩ private def smul {S : Type*} [SMulZeroClass S k] : S → SkewMonoidAlgebra k G → SkewMonoidAlgebra k G | s, ⟨b⟩ => ⟨s • b⟩ instance : Zero (SkewMonoidAlgebra k G) := ⟨⟨0⟩⟩ instance : Add (SkewMonoidAlgebra k G) := ⟨add⟩ instance {S : Type*} [SMulZeroClass S k] : SMulZeroClass S (SkewMonoidAlgebra k G) where smul s f := smul s f smul_zero a := by exact congr_arg ofFinsupp (smul_zero a) @[simp] theorem ofFinsupp_zero : (⟨0⟩ : SkewMonoidAlgebra k G) = 0 := rfl @[simp] theorem ofFinsupp_add {a b} : (⟨a + b⟩ : SkewMonoidAlgebra k G) = ⟨a⟩ + ⟨b⟩ := show _ = add _ _ by rw [add] @[simp] theorem ofFinsupp_smul {S : Type*} [SMulZeroClass S k] (a : S) (b : G →₀ k) : (⟨a • b⟩ : SkewMonoidAlgebra k G) = (a • ⟨b⟩ : SkewMonoidAlgebra k G) := show _ = smul _ _ by rw [smul] @[simp] theorem toFinsupp_zero : (0 : SkewMonoidAlgebra k G).toFinsupp = 0 := rfl @[simp] theorem toFinsupp_add (a b : SkewMonoidAlgebra k G) : (a + b).toFinsupp = a.toFinsupp + b.toFinsupp := by rw [← ofFinsupp_add] @[simp] theorem toFinsupp_smul {S : Type*} [SMulZeroClass S k] (a : S) (b : SkewMonoidAlgebra k G) : (a • b).toFinsupp = a • b.toFinsupp := by rw [← ofFinsupp_smul] theorem _root_.IsSMulRegular.skewMonoidAlgebra {S : Type*} [Monoid S] [DistribMulAction S k] {a : S} (ha : IsSMulRegular k a) : IsSMulRegular (SkewMonoidAlgebra k G) a | ⟨_⟩, ⟨_⟩, h => by exact congr_arg _ <| ha.finsupp (ofFinsupp.inj h) theorem toFinsupp_injective : Function.Injective (toFinsupp : SkewMonoidAlgebra k G → Finsupp _ _) := fun ⟨_⟩ _ ↦ congr_arg _ @[simp] theorem toFinsupp_inj {a b : SkewMonoidAlgebra k G} : a.toFinsupp = b.toFinsupp ↔ a = b := toFinsupp_injective.eq_iff theorem ofFinsupp_injective : Function.Injective (ofFinsupp : Finsupp _ _ → SkewMonoidAlgebra k G) := fun _ _ ↦ congr_arg toFinsupp /-- A variant of `SkewMonoidAlgebra.ofFinsupp_injective` in terms of `Iff`. -/ theorem ofFinsupp_inj {a b} : (⟨a⟩ : SkewMonoidAlgebra k G) = ⟨b⟩ ↔ a = b := ofFinsupp_injective.eq_iff @[simp] theorem toFinsupp_eq_zero {a : SkewMonoidAlgebra k G} : a.toFinsupp = 0 ↔ a = 0 := toFinsupp_inj @[simp] theorem ofFinsupp_eq_zero {a} : (⟨a⟩ : SkewMonoidAlgebra k G) = 0 ↔ a = 0 := ofFinsupp_inj instance : Inhabited (SkewMonoidAlgebra k G) := ⟨0⟩ instance [Nontrivial k] [Nonempty G] : Nontrivial (SkewMonoidAlgebra k G) := Function.Injective.nontrivial ofFinsupp_injective instance [Subsingleton k] : Unique (SkewMonoidAlgebra k G) := Function.Injective.unique toFinsupp_injective instance : AddMonoid (SkewMonoidAlgebra k G) where __ := toFinsupp_injective.addMonoid _ toFinsupp_zero toFinsupp_add (fun _ _ ↦ toFinsupp_smul _ _) section Support /-- For `f : SkewMonoidAlgebra k G`, `f.support` is the set of all `a ∈ G` such that `f.coeff a ≠ 0`. -/ def support (p : SkewMonoidAlgebra k G) : Finset G := p.toFinsupp.support @[simp] theorem support_ofFinsupp (p) : support (⟨p⟩ : SkewMonoidAlgebra k G) = p.support := by rw [support] theorem support_toFinsupp (p : SkewMonoidAlgebra k G) : p.toFinsupp.support = p.support := by rw [support] @[simp] theorem support_zero : (0 : SkewMonoidAlgebra k G).support = ∅ := rfl @[simp] theorem support_eq_empty {p} : p.support = ∅ ↔ (p : SkewMonoidAlgebra k G) = 0 := by rcases p simp only [support, Finsupp.support_eq_empty, ofFinsupp_eq_zero] lemma support_add [DecidableEq G] {p q : SkewMonoidAlgebra k G} : (p + q).support ⊆ p.support ∪ q.support := by simp [support] exact Finsupp.support_add end Support section Coeff /-- `coeff f a` (often denoted `f.coeff a`) is the coefficient of `a` in `f`. -/ def coeff : SkewMonoidAlgebra k G → G → k | ⟨p⟩ => p @[simp] theorem coeff_ofFinsupp (p) : coeff (⟨p⟩ : SkewMonoidAlgebra k G) = p := rfl theorem coeff_injective : Injective (coeff : SkewMonoidAlgebra k G → G → k) := by rintro ⟨p⟩ ⟨q⟩ simp only [coeff, DFunLike.coe_fn_eq, imp_self, ofFinsupp.injEq] @[simp] theorem coeff_inj (p q : SkewMonoidAlgebra k G) : p.coeff = q.coeff ↔ p = q := coeff_injective.eq_iff @[simp] theorem toFinsupp_apply (f : SkewMonoidAlgebra k G) (g) : f.toFinsupp g = f.coeff g := rfl @[simp] theorem coeff_zero (g : G) : coeff (0 : SkewMonoidAlgebra k G) g = 0 := rfl @[simp] theorem mem_support_iff {f : SkewMonoidAlgebra k G} {a : G} : a ∈ f.support ↔ f.coeff a ≠ 0 := by rcases f with ⟨⟩ simp only [coeff, support_ofFinsupp, Finsupp.mem_support_iff, ne_eq] theorem notMem_support_iff {f : SkewMonoidAlgebra k G} {a : G} : a ∉ f.support ↔ f.coeff a = 0 := by simp only [mem_support_iff, ne_eq, not_not] @[deprecated (since := "2025-05-23")] alias not_mem_support_iff := notMem_support_iff theorem ext_iff {p q : SkewMonoidAlgebra k G} : p = q ↔ ∀ n, coeff p n = coeff q n := by rcases p with ⟨f : G →₀ k⟩ rcases q with ⟨g : G →₀ k⟩ simpa [coeff] using DFunLike.ext_iff (f := f) (g := g) @[ext] theorem ext {p q : SkewMonoidAlgebra k G} : (∀ a, coeff p a = coeff q a) → p = q := ext_iff.2 @[simp] theorem coeff_add (p q : SkewMonoidAlgebra k G) (a : G) : coeff (p + q) a = coeff p a + coeff q a := by rcases p rcases q simp_rw [← ofFinsupp_add, coeff] exact Finsupp.add_apply _ _ _ @[simp] theorem coeff_smul {S} [SMulZeroClass S k] (r : S) (p : SkewMonoidAlgebra k G) (a : G) : coeff (r • p) a = r • coeff p a := by rfl end Coeff section Single /-- `single a b` is the finitely supported function with value `b` at `a` and zero otherwise. -/ def single (a : G) (b : k) : SkewMonoidAlgebra k G := ⟨Finsupp.single a b⟩ @[simp] theorem toFinsupp_single (a : G) (b : k) : (single a b).toFinsupp = Finsupp.single a b := rfl @[simp] theorem ofFinsupp_single (a : G) (b : k) : ⟨Finsupp.single a b⟩ = single a b := rfl theorem coeff_single (a : G) (b : k) [DecidableEq G] : coeff (single a b) = Pi.single a b := by simp [coeff, Finsupp.single_eq_pi_single] theorem coeff_single_apply {a a' : G} {b : k} [Decidable (a = a')] : coeff (single a b) a' = if a = a' then b else 0 := by simp [coeff, Finsupp.single_apply] theorem single_zero_right (a : G) : single a (0 : k) = 0 := by simp [← toFinsupp_inj] @[simp] theorem single_add (a : G) (b₁ b₂ : k) : single a (b₁ + b₂) = single a b₁ + single a b₂ := by simp [← toFinsupp_inj] @[simp] theorem single_zero (a : G) : (single a 0 : SkewMonoidAlgebra k G) = 0 := by simp [← toFinsupp_inj] theorem single_eq_zero {a : G} {b : k} : single a b = 0 ↔ b = 0 := by simp [← toFinsupp_inj] /-- Group isomorphism between `SkewMonoidAlgebra k G` and `G →₀ k`. -/ @[simps apply symm_apply] def toFinsuppAddEquiv : SkewMonoidAlgebra k G ≃+ (G →₀ k) where toFun := toFinsupp invFun := ofFinsupp map_add' := toFinsupp_add theorem smul_single {S} [SMulZeroClass S k] (s : S) (a : G) (b : k) : s • single a b = single a (s • b) := toFinsupp_injective <| by simp; theorem single_injective (a : G) : Function.Injective (single a : k → SkewMonoidAlgebra k G) := toFinsuppAddEquiv.symm.injective.comp (Finsupp.single_injective a) theorem single_left_inj {a a' : G} {b : k} (h : b ≠ 0) : single a b = single a' b ↔ a = a' := by rw [← toFinsupp_inj] exact Finsupp.single_left_inj h theorem _root_.IsSMulRegular.skewMonoidAlgebra_iff {S : Type*} [Monoid S] [DistribMulAction S k] {a : S} [Nonempty G] : IsSMulRegular k a ↔ IsSMulRegular (SkewMonoidAlgebra k G) a := by inhabit G refine ⟨IsSMulRegular.skewMonoidAlgebra, fun ha b₁ b₂ inj ↦ ?_⟩ rw [← (single_injective _).eq_iff, ← smul_single, ← smul_single] at inj exact single_injective (default) (ha inj) end Single end AddMonoid section AddMonoidWithOne section One variable [One G] [AddMonoidWithOne k] /-- The unit of the multiplication is `single 1 1`, i.e. the function that is `1` at `1` and zero elsewhere. -/ instance : One (SkewMonoidAlgebra k G) where one := single 1 1 instance : AddMonoidWithOne (SkewMonoidAlgebra k G) where theorem ofFinsupp_one : (⟨Finsupp.single 1 1⟩ : SkewMonoidAlgebra k G) = 1 := rfl @[simp] theorem toFinsupp_one : (1 : SkewMonoidAlgebra k G).toFinsupp = Finsupp.single 1 1 := rfl @[simp] theorem toFinsupp_eq_single_one_one_iff {a : SkewMonoidAlgebra k G} : a.toFinsupp = Finsupp.single 1 1 ↔ a = 1 := by simp [← toFinsupp_inj] @[simp] theorem ofFinsupp_eq_one {a} : (⟨a⟩ : SkewMonoidAlgebra k G) = 1 ↔ a = Finsupp.single 1 1 := by simp [← toFinsupp_inj] @[simp] theorem single_one_one : single (1 : G) (1 : k) = 1 := rfl theorem one_def : (1 : SkewMonoidAlgebra k G) = single 1 1 := rfl @[simp] theorem coeff_one_one : coeff (1 : SkewMonoidAlgebra k G) 1 = 1 := by simp only [coeff, toFinsupp_single, Finsupp.single_eq_same] theorem coeff_one {a : G} [Decidable (a = 1)] : (1 : SkewMonoidAlgebra k G).coeff a = if a = 1 then 1 else 0 := by classical simpa [eq_comm (a := a)] using coeff_single_apply theorem natCast_def (n : ℕ) : (n : SkewMonoidAlgebra k G) = single (1 : G) (n : k) := by induction n <;> simp_all @[simp] lemma single_nat (n : ℕ) : (single 1 n : SkewMonoidAlgebra k G) = n := (natCast_def _).symm end One end AddMonoidWithOne section AddCommMonoid variable [AddCommMonoid k] instance : AddCommMonoid (SkewMonoidAlgebra k G) where __ := toFinsupp_injective.addCommMonoid _ toFinsupp_zero toFinsupp_add (fun _ _ ↦ toFinsupp_smul _ _) section sum instance [DecidableEq G] [DecidableEq k] : DecidableEq (SkewMonoidAlgebra k G) := Equiv.decidableEq toFinsuppAddEquiv.toEquiv /-- `sum f g` is the sum of `g a (f.coeff a)` over the support of `f`. -/ def sum {N : Type*} [AddCommMonoid N] (f : SkewMonoidAlgebra k G) (g : G → k → N) : N := f.toFinsupp.sum g theorem sum_def {N : Type*} [AddCommMonoid N] (f : SkewMonoidAlgebra k G) (g : G → k → N) : sum f g = f.toFinsupp.sum g := rfl /-- Unfolded version of `sum_def` in terms of `Finset.sum`. -/ theorem sum_def' {N : Type*} [AddCommMonoid N] (f : SkewMonoidAlgebra k G) (g : G → k → N) : sum f g = ∑ a ∈ f.support, g a (f.coeff a) := rfl @[simp] theorem sum_single_index {N} [AddCommMonoid N] {a : G} {b : k} {h : G → k → N} (h_zero : h a 0 = 0) : (SkewMonoidAlgebra.single a b).sum h = h a b := Finsupp.sum_single_index h_zero theorem map_sum {N P : Type*} [AddCommMonoid N] [AddCommMonoid P] {H : Type*} [FunLike H N P] [AddMonoidHomClass H N P] (h : H) (f : SkewMonoidAlgebra k G) (g : G → k → N) : h (sum f g) = sum f fun a b ↦ h (g a b) := _root_.map_sum h _ _ /-- Variant where the image of `g` is a `SkewMonoidAlgebra`. -/ theorem toFinsupp_sum' {k' G' : Type*} [AddCommMonoid k'] (f : SkewMonoidAlgebra k G) (g : G → k → SkewMonoidAlgebra k' G') : (sum f g).toFinsupp = Finsupp.sum f.toFinsupp (toFinsupp <| g · ·) := _root_.map_sum toFinsuppAddEquiv (fun a ↦ g a (f.coeff a)) f.toFinsupp.support theorem ofFinsupp_sum {k' G' : Type*} [AddCommMonoid k'] (f : G →₀ k) (g : G → k → G' →₀ k') : (⟨Finsupp.sum f g⟩ : SkewMonoidAlgebra k' G') = sum ⟨f⟩ (⟨g · ·⟩) := by apply toFinsupp_injective; simp only [toFinsupp_sum'] theorem sum_single (f : SkewMonoidAlgebra k G) : f.sum single = f := by apply toFinsupp_injective; simp only [toFinsupp_sum', toFinsupp_single, Finsupp.sum_single] /-- Taking the `sum` under `h` is an additive homomorphism, if `h` is an additive homomorphism. This is a more specific version of `SkewMonoidAlgebra.sum_add_index` with simpler hypotheses. -/ theorem sum_add_index' {S : Type*} [AddCommMonoid S] {f g : SkewMonoidAlgebra k G} {h : G → k → S} (hf : ∀ i, h i 0 = 0) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ + h a b₂) : (f + g).sum h = f.sum h + g.sum h := by rw [show f + g = ⟨f.toFinsupp + g.toFinsupp⟩ by rw [ofFinsupp_add, eta]] exact Finsupp.sum_add_index' hf h_add /-- Taking the `sum` under `h` is an additive homomorphism, if `h` is an additive homomorphism. This is a more general version of `SkewMonoidAlgebra.sum_add_index'`; the latter has simpler hypotheses. -/ theorem sum_add_index {S : Type*} [DecidableEq G] [AddCommMonoid S] {f g : SkewMonoidAlgebra k G} {h : G → k → S} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 0) (h_add : ∀ a ∈ f.support ∪ g.support, ∀ b₁ b₂, h a (b₁ + b₂) = h a b₁ + h a b₂) : (f + g).sum h = f.sum h + g.sum h := by rw [show f + g = ⟨f.toFinsupp + g.toFinsupp⟩ by rw [ofFinsupp_add, eta]] exact Finsupp.sum_add_index h_zero h_add @[simp] theorem sum_add {S : Type*} [AddCommMonoid S] (p : SkewMonoidAlgebra k G) (f g : G → k → S) : (p.sum fun n x ↦ f n x + g n x) = p.sum f + p.sum g := Finsupp.sum_add @[simp] theorem sum_zero_index {S : Type*} [AddCommMonoid S] {f : G → k → S} : (0 : SkewMonoidAlgebra k G).sum f = 0 := by simp [sum] @[simp] theorem sum_zero {N : Type*} [AddCommMonoid N] {f : SkewMonoidAlgebra k G} : (f.sum fun _ _ ↦ (0 : N)) = 0 := Finset.sum_const_zero theorem sum_sum_index {α β M N P : Type*} [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] {f : SkewMonoidAlgebra M α} {g : α → M → SkewMonoidAlgebra N β} {h : β → N → P} (h_zero : ∀ (a : β), h a 0 = 0) (h_add : ∀ (a : β) (b₁ b₂ : N), h a (b₁ + b₂) = h a b₁ + h a b₂) : sum (sum f g) h = sum f fun a b ↦ sum (g a b) h := by rw [sum_def, toFinsupp_sum' f g, Finsupp.sum_sum_index h_zero h_add]; simp [sum_def] @[simp] theorem coeff_sum {k' G' : Type*} [AddCommMonoid k'] {f : SkewMonoidAlgebra k G} {g : G → k → SkewMonoidAlgebra k' G'} {a₂ : G'} : (f.sum g).coeff a₂ = f.sum fun a₁ b ↦ (g a₁ b).coeff a₂ := by simp_rw [coeff, toFinsupp_sum', sum_def, Finsupp.sum_apply] theorem sum_mul {S : Type*} [NonUnitalNonAssocSemiring S] (b : S) (s : SkewMonoidAlgebra k G) {f : G → k → S} : s.sum f * b = s.sum fun a c ↦ f a c * b := by simp only [sum, Finsupp.sum, Finset.sum_mul] theorem mul_sum {S : Type*} [NonUnitalNonAssocSemiring S] (b : S) (s : SkewMonoidAlgebra k G) {f : G → k → S} : b * s.sum f = s.sum fun a c ↦ b * f a c := by simp only [sum, Finsupp.sum, Finset.mul_sum] /-- Analogue of `Finsupp.sum_ite_eq'` for `SkewMonoidAlgebra`. -/ @[simp] theorem sum_ite_eq' {N : Type*} [AddCommMonoid N] [DecidableEq G] (f : SkewMonoidAlgebra k G) (a : G) (b : G → k → N) : (f.sum fun (x : G) (v : k) ↦ if x = a then b x v else 0) = if a ∈ f.support then b a (f.coeff a) else 0 := by simp only [sum_def', f.toFinsupp.support.sum_ite_eq', support] theorem smul_sum {M : Type*} {R : Type*} [AddCommMonoid M] [DistribSMul R M] {v : SkewMonoidAlgebra k G} {c : R} {h : G → k → M} : c • v.sum h = v.sum fun a b ↦ c • h a b := Finsupp.smul_sum theorem sum_congr {f : SkewMonoidAlgebra k G} {M : Type*} [AddCommMonoid M] {g₁ g₂ : G → k → M} (h : ∀ x ∈ f.support, g₁ x (f.coeff x) = g₂ x (f.coeff x)) : f.sum g₁ = f.sum g₂ := Finset.sum_congr rfl h @[elab_as_elim] theorem induction_on {p : SkewMonoidAlgebra k G → Prop} (f : SkewMonoidAlgebra k G) (zero : p 0) (single : ∀ g a, p (single g a)) (add : ∀ f g : SkewMonoidAlgebra k G, p f → p g → p (f + g)) : p f := by rw [← sum_single f, sum_def'] exact Finset.sum_induction _ _ add zero (by simp_all) /-- Slightly less general but more convenient version of `SkewMonoidAlgebra.induction_on`. -/ @[induction_eliminator] theorem induction_on' [instNonempty : Nonempty G] {p : SkewMonoidAlgebra k G → Prop} (f : SkewMonoidAlgebra k G) (single : ∀ g a, p (single g a)) (add : ∀ f g : SkewMonoidAlgebra k G, p f → p g → p (f + g)) : p f := induction_on f (by simpa using single (Classical.choice instNonempty) 0) single add /-- If two additive homomorphisms from `SkewMonoidAlgebra k G ` are equal on each `single a b`, then they are equal. -/ @[ext high] theorem addHom_ext {M : Type*} [AddZeroClass M] {f g : SkewMonoidAlgebra k G →+ M} (h : ∀ a b, f (single a b) = g (single a b)) : f = g := by ext p; induction p using SkewMonoidAlgebra.induction_on <;> simp_all end sum section mapDomain variable {G' G'' : Type*} (f : G → G') {g : G' → G''} (v : SkewMonoidAlgebra k G) /-- Given `f : G → G'` and `v : SkewMonoidAlgebra k G`, `mapDomain f v : SkewMonoidAlgebra k G'` is the finitely supported additive homomorphism whose value at `a : G'` is the sum of `v x` over all `x` such that `f x = a`. Note that `SkewMonoidAlgebra.mapDomain` is defined as an `AddHom`, while `MonoidAlgebra.mapDomain` is defined as a function. -/ @[simps] def mapDomain : SkewMonoidAlgebra k G →+ SkewMonoidAlgebra k G' where toFun v := v.sum fun a ↦ single (f a) map_zero' := sum_zero_index map_add' _ _ := sum_add_index' (fun _ ↦ single_zero _) fun _ ↦ single_add _ lemma toFinsupp_mapDomain : (mapDomain f v).toFinsupp = Finsupp.mapDomain f v.toFinsupp := by simp_rw [mapDomain_apply, Finsupp.mapDomain, toFinsupp_sum', single] variable {f v} theorem mapDomain_id : mapDomain id v = v := sum_single _ theorem mapDomain_comp : mapDomain (g ∘ f) v = mapDomain g (mapDomain f v) := ((sum_sum_index (single_zero <| g ·) (single_add <| g ·)).trans (sum_congr fun _ _ ↦ sum_single_index (single_zero _))).symm theorem sum_mapDomain_index {k' : Type*} [AddCommMonoid k'] {h : G' → k → k'} (h_zero : ∀ (b : G'), h b 0 = 0) (h_add : ∀ (b : G') (m₁ m₂ : k), h b (m₁ + m₂) = h b m₁ + h b m₂) : sum (mapDomain f v) h = sum v fun a m ↦ h (f a) m := (sum_sum_index h_zero h_add).trans <| sum_congr fun _ _ ↦ sum_single_index (h_zero _) theorem mapDomain_single {a : G} {b : k} : mapDomain f (single a b) = single (f a) b := sum_single_index <| single_zero _ theorem mapDomain_smul {R : Type*} [Monoid R] [DistribMulAction R k] {b : R} : mapDomain f (b • v) = b • mapDomain f v := by simp_rw [← toFinsupp_inj, toFinsupp_smul, toFinsupp_mapDomain] simp [Finsupp.mapDomain_smul] /-- A non-commutative version of `SkewMonoidAlgebra.lift`: given an additive homomorphism `f : k →+ R` and a homomorphism `g : G → R`, returns the additive homomorphism from `SkewMonoidAlgebra k G` such that `liftNC f g (single a b) = f b * g a`. If `k` is a semiring and `f` is a ring homomorphism and for all `x : R`, `y : G` the equality `(f (y • x)) * g y = (g y) * (f x))` holds, then the result is a ring homomorphism (see `SkewMonoidAlgebra.liftNCRingHom`). If `R` is a `k`-algebra and `f = algebraMap k R`, then the result is an algebra homomorphism called `SkewMonoidAlgebra.lift`. -/ def liftNC {R : Type*} [NonUnitalNonAssocSemiring R] (f : k →+ R) (g : G → R) : SkewMonoidAlgebra k G →+ R := (Finsupp.liftAddHom fun x ↦ (AddMonoidHom.mulRight (g x)).comp f).comp (AddEquiv.toAddMonoidHom toFinsuppAddEquiv) @[simp] theorem liftNC_single {R : Type*} [NonUnitalNonAssocSemiring R] (f : k →+ R) (g : G → R) (a : G) (b : k) : liftNC f g (single a b) = f b * g a := Finsupp.liftAddHom_apply_single _ _ _ theorem eq_liftNC {R : Type*} [NonUnitalNonAssocSemiring R] (f : k →+ R) (g : G → R) (l : SkewMonoidAlgebra k G →+ R) (h : ∀ a b, l (single a b) = f b * g a) : l = liftNC f g := by ext a b; simp_all end mapDomain end AddCommMonoid section AddGroup variable [AddGroup k] private irreducible_def neg : SkewMonoidAlgebra k G → SkewMonoidAlgebra k G | ⟨a⟩ => ⟨-a⟩ instance : Neg (SkewMonoidAlgebra k G) := ⟨neg⟩ @[simp] theorem ofFinsupp_neg {a} : (⟨-a⟩ : SkewMonoidAlgebra k G) = -⟨a⟩ := show _ = neg _ by rw [neg_def] instance : AddGroup (SkewMonoidAlgebra k G) where zsmul := zsmulRec neg_add_cancel a := by cases a; simp [← ofFinsupp_neg, ← ofFinsupp_add] @[simp] theorem toFinsupp_neg (a : SkewMonoidAlgebra k G) : (-a).toFinsupp = -a.toFinsupp := toFinsuppAddEquiv.map_neg a @[simp] theorem ofFinsupp_sub {a b} : (⟨a - b⟩ : SkewMonoidAlgebra k G) = ⟨a⟩ - ⟨b⟩ := toFinsuppAddEquiv.symm.map_sub a b @[simp] theorem toFinsupp_sub (a b : SkewMonoidAlgebra k G) : (a - b).toFinsupp = a.toFinsupp - b.toFinsupp := toFinsuppAddEquiv.map_sub a b @[simp] theorem single_neg (a : G) (b : k) : single a (-b) = -single a b := by simp [← ofFinsupp_single] end AddGroup section AddCommGroup variable [AddCommGroup k] instance : AddCommGroup (SkewMonoidAlgebra k G) where add_comm end AddCommGroup section AddGroupWithOne variable [AddGroupWithOne k] [One G] instance : AddGroupWithOne (SkewMonoidAlgebra k G) where __ := instAddGroup theorem intCast_def (z : ℤ) : (z : SkewMonoidAlgebra k G) = single (1 : G) (z : k) := by cases z <;> simp end AddGroupWithOne section Mul /- Interaction of `sum` and `•` assuming some multiplication structure. -/ theorem sum_smul_index {N : Type*} [AddCommMonoid N] [NonUnitalNonAssocSemiring k] {g : SkewMonoidAlgebra k G} {b : k} {h : G → k → N} (h0 : ∀ i, h i 0 = 0) : (b • g).sum h = g.sum (h · <| b * ·) := by simp [sum_def, Finsupp.sum_smul_index' h0] /- Variant of the interaction of `sum` and `•` assuming some scalar multiplication structure. -/ theorem sum_smul_index' {N R : Type*} [AddCommMonoid k] [DistribSMul R k] [AddCommMonoid N] {g : SkewMonoidAlgebra k G} {b : R} {h : G → k → N} (h0 : ∀ i, h i 0 = 0) : (b • g).sum h = g.sum (h · <| b • ·) := by simp only [sum_def, toFinsupp_smul, Finsupp.sum_smul_index' h0] @[simp] theorem liftNC_one {g_hom R : Type*} [NonAssocSemiring k] [One G] [Semiring R] [FunLike g_hom G R] [OneHomClass g_hom G R] (f : k →+* R) (g : g_hom) : liftNC (f : k →+ R) g 1 = 1 := by simp only [one_def, liftNC_single, AddMonoidHom.coe_coe, map_one, mul_one] end Mul section Mul variable [Mul G] section SMul variable [SMul G k] [NonUnitalNonAssocSemiring k] /-- The product of `f g : SkewMonoidAlgebra k G` is the finitely supported function whose value at `a` is the sum of `f x * (x • g y)` over all pairs `x, y` such that `x * y = a`. (Think of a skew group ring.) -/ instance : Mul (SkewMonoidAlgebra k G) := ⟨fun f g ↦ f.sum fun a₁ b₁ ↦ g.sum fun a₂ b₂ ↦ single (a₁ * a₂) (b₁ * (a₁ • b₂))⟩ theorem mul_def {f g : SkewMonoidAlgebra k G} : f * g = f.sum fun a₁ b₁ ↦ g.sum fun a₂ b₂ ↦ single (a₁ * a₂) (b₁ * (a₁ • b₂)) := rfl end SMul section DistribSMul instance instNonUnitalNonAssocSemiring [NonUnitalNonAssocSemiring k] [DistribSMul G k] : NonUnitalNonAssocSemiring (SkewMonoidAlgebra k G) where left_distrib f g h := by classical simp only [mul_def] refine Eq.trans (congr_arg (sum f) (funext₂ fun _ _ ↦ sum_add_index ?_ ?_)) ?_ <;> simp only [smul_zero, smul_add, mul_add, mul_zero, single_zero, single_add, forall_true_iff, sum_add] right_distrib f g h := by classical simp only [mul_def] refine Eq.trans (sum_add_index ?_ ?_) ?_ <;> simp only [add_mul, zero_mul, single_zero, single_add, forall_true_iff, sum_zero, sum_add] zero_mul f := sum_zero_index mul_zero f := Eq.trans (congr_arg (sum f) (funext₂ fun _ _ ↦ sum_zero_index)) sum_zero variable {R : Type*} [Semiring R] [NonAssocSemiring k] [SMul G k] theorem liftNC_mul {g_hom : Type*} [FunLike g_hom G R] [MulHomClass g_hom G R] (f : k →+* R) (g : g_hom) (a b : SkewMonoidAlgebra k G) (h_comm : ∀ {x y}, y ∈ a.support → (f (y • b.coeff x)) * g y = (g y) * (f (b.coeff x))) : liftNC (f : k →+ R) g (a * b) = liftNC (f : k →+ R) g a * liftNC (f : k →+ R) g b := by conv_rhs => rw [← sum_single a, ← sum_single b] simp_rw [mul_def, map_sum, liftNC_single, sum_mul, mul_sum] refine sum_congr fun y hy ↦ sum_congr fun x _hx ↦ ?_ simp only [AddMonoidHom.coe_coe, map_mul] rw [mul_assoc, ← mul_assoc (f (y • b.coeff x)), h_comm hy, mul_assoc, mul_assoc] end DistribSMul end Mul /-! #### Semiring structure -/ section Semiring variable [Semiring k] [Monoid G] [MulSemiringAction G k] open MulSemiringAction instance : NonUnitalSemiring (SkewMonoidAlgebra k G) where mul_assoc f g h := by induction f with | single x a => induction g with | single y b => induction h with | single z c => simp [mul_assoc, mul_smul, mul_def] | add => simp_all [mul_add] | add => simp_all [add_mul, mul_add] | add => simp_all [add_mul] instance : NonAssocSemiring (SkewMonoidAlgebra k G) where one_mul f := by induction f with | single g a => rw [one_def, mul_def, sum_single_index] <;> simp | add f g _ _ => simp_all [mul_add] mul_one f := by induction f with | single g a => rw [one_def, mul_def, sum_single_index, sum_single_index] <;> simp | add f g _ _ => simp_all [add_mul] instance : Semiring (SkewMonoidAlgebra k G) where __ := instNonUnitalSemiring __ := instNonAssocSemiring variable {R : Type*} [Semiring R] /-- `liftNC` as a `RingHom`, for when `f x` and `g y` commute -/ def liftNCRingHom (f : k →+* R) (g : G →* R) (h_comm : ∀ {x y}, (f (y • x)) * g y = (g y) * (f x)) : SkewMonoidAlgebra k G →+* R where __ := liftNC (f : k →+ R) g map_one' := liftNC_one _ _ map_mul' _ _ := liftNC_mul _ _ _ _ fun {_ _} _ ↦ h_comm end Semiring /-! #### Derived instances -/ section DerivedInstances instance instNonUnitalNonAssocRing [Ring k] [Monoid G] [MulSemiringAction G k] : NonUnitalNonAssocRing (SkewMonoidAlgebra k G) where __ := instAddCommGroup __ := instNonUnitalNonAssocSemiring instance instNonUnitalRing [Ring k] [Monoid G] [MulSemiringAction G k] : NonUnitalRing (SkewMonoidAlgebra k G) where __ := instAddCommGroup __ := instNonUnitalSemiring instance instNonAssocRing [Ring k] [Monoid G] [MulSemiringAction G k] : NonAssocRing (SkewMonoidAlgebra k G) where __ := instAddCommGroup __ := instNonAssocSemiring instance instCommSemiring [CommSemiring k] [CommMonoid G] [MulSemiringAction G k] [SMulCommClass G k k] : CommSemiring (SkewMonoidAlgebra k G) where mul_comm a b := by have hgk (g : G) (r : k) : g • r = r := by rw [← Algebra.algebraMap_self_apply r, smul_algebraMap g r] simp only [mul_def, hgk, sum_def] rw [Finsupp.sum_comm] exact Finsupp.sum_congr (fun x _ ↦ Finsupp.sum_congr (fun y _ ↦ by rw [mul_comm, mul_comm (a.toFinsupp y) _])) instance instRing [Ring k] [Monoid G] [MulSemiringAction G k] : Ring (SkewMonoidAlgebra k G) where __ := instNonAssocRing __ := instSemiring variable {S S₁ S₂ : Type*} instance [AddMonoid k] [DistribSMul S k] : DistribSMul S (SkewMonoidAlgebra k G) where __ := toFinsupp_injective.distribSMul ⟨⟨toFinsupp, toFinsupp_zero⟩, toFinsupp_add⟩ toFinsupp_smul instance [Monoid S] [AddMonoid k] [DistribMulAction S k] : DistribMulAction S (SkewMonoidAlgebra k G) where __ := toFinsupp_injective.distribMulAction ⟨⟨toFinsupp, toFinsupp_zero (k := k)⟩, toFinsupp_add⟩ toFinsupp_smul instance [Semiring S] [AddCommMonoid k] [Module S k] : Module S (SkewMonoidAlgebra k G) where __ := toFinsupp_injective.module _ ⟨⟨toFinsupp, toFinsupp_zero⟩, toFinsupp_add⟩ toFinsupp_smul instance instFaithfulSMul [AddMonoid k] [SMulZeroClass S k] [FaithfulSMul S k] [Nonempty G] : FaithfulSMul S (SkewMonoidAlgebra k G) where eq_of_smul_eq_smul {_s₁ _s₂} h := by apply eq_of_smul_eq_smul fun a : G →₀ k ↦ congr_arg toFinsupp _ intro a simp_rw [ofFinsupp_smul, h] instance [AddMonoid k] [SMul S₁ S₂] [SMulZeroClass S₁ k] [SMulZeroClass S₂ k] [IsScalarTower S₁ S₂ k] : IsScalarTower S₁ S₂ (SkewMonoidAlgebra k G) := ⟨fun _ _ ⟨_⟩ ↦ by simp_rw [← ofFinsupp_smul, smul_assoc]⟩ instance [AddMonoid k] [SMulZeroClass S₁ k] [SMulZeroClass S₂ k] [SMulCommClass S₁ S₂ k] : SMulCommClass S₁ S₂ (SkewMonoidAlgebra k G) := ⟨fun _ _ ⟨_⟩ ↦ by simp_rw [← ofFinsupp_smul, smul_comm _ _ _]⟩ instance [AddMonoid k] [SMulZeroClass S k] [SMulZeroClass Sᵐᵒᵖ k] [IsCentralScalar S k] : IsCentralScalar S (SkewMonoidAlgebra k G) := ⟨fun _ ⟨_⟩ ↦ by simp_rw [← ofFinsupp_smul, op_smul_eq_smul]⟩ section Module.Free variable [Semiring S] /-- Linear equivalence between `SkewMonoidAlgebra k G` and `G →₀ k`. -/ def toFinsuppLinearEquiv [AddCommMonoid k] [Module S k] : SkewMonoidAlgebra k G ≃ₗ[S] (G →₀ k) := AddEquiv.toLinearEquiv toFinsuppAddEquiv (by simp) /-- The basis on `SkewMonoidAlgebra k G` with basis vectors `fun i ↦ single i 1` -/ def basisSingleOne [Semiring k] : Module.Basis G k (SkewMonoidAlgebra k G) where repr := toFinsuppLinearEquiv instance [Semiring k] : Module.Free k (SkewMonoidAlgebra k G) := Module.Free.of_basis basisSingleOne end Module.Free variable {M α : Type*} [Monoid G] [AddCommMonoid M] [MulAction G α] /-- Scalar multiplication acting on the domain. This is not an instance as it would conflict with the action on the range. See the file `test/instance_diamonds.lean` for examples of such conflicts. -/ def comapSMul [AddCommMonoid M] : SMul G (SkewMonoidAlgebra M α) where smul g := mapDomain (g • ·) attribute [local instance] comapSMul theorem comapSMul_def (g : G) (f : SkewMonoidAlgebra M α) : g • f = mapDomain (g • ·) f := rfl @[simp] theorem comapSMul_single (g : G) (a : α) (b : M) : g • single a b = single (g • a) b := mapDomain_single /-- `comapSMul` is multiplicative -/ def comapMulAction : MulAction G (SkewMonoidAlgebra M α) where one_smul f := by rw [comapSMul_def, one_smul_eq_id, mapDomain_id] mul_smul g g' f := by rw [comapSMul_def, comapSMul_def, comapSMul_def, ← comp_smul_left, mapDomain_comp] attribute [local instance] comapMulAction /-- This is not an instance as it conflicts with `SkewMonoidAlgebra.distribMulAction` when `G = kˣ`. -/ def comapDistribMulActionSelf [AddCommMonoid k] : DistribMulAction G (SkewMonoidAlgebra k G) where smul_zero g := by ext simp [comapSMul_def, mapDomain] smul_add g f f' := by ext simp [comapSMul_def, map_add] end DerivedInstances section coeff_mul variable [Semiring k] section Monoid variable [Monoid G] [MulSemiringAction G k] theorem coeff_mul [DecidableEq G] (f g : SkewMonoidAlgebra k G) (x : G) : (f * g).coeff x = f.sum fun a₁ b₁ ↦ g.sum fun a₂ b₂ ↦ if a₁ * a₂ = x then b₁ * a₁ • b₂ else 0 := by rw [mul_def, coeff_sum]; congr; ext rw [coeff_sum]; congr; ext exact coeff_single_apply theorem coeff_mul_antidiagonal_of_finset (f g : SkewMonoidAlgebra k G) (x : G) (s : Finset (G × G)) (hs : ∀ {p : G × G}, p ∈ s ↔ p.1 * p.2 = x) : (f * g).coeff x = ∑ p ∈ s, f.coeff p.1 * p.1 • g.coeff p.2 := by classical let F : G × G → k := fun p ↦ if p.1 * p.2 = x then f.coeff p.1 * p.1 • g.coeff p.2 else 0 calc (f * g).coeff x = ∑ a₁ ∈ f.support, ∑ a₂ ∈ g.support, F (a₁, a₂) := coeff_mul f g x _ = ∑ p ∈ f.support ×ˢ g.support, F p := by rw [← Finset.sum_product _ _ _] _ = ∑ p ∈ (f.support ×ˢ g.support).filter fun p : G × G ↦ p.1 * p.2 = x, f.coeff p.1 * p.1 • g.coeff p.2 := (Finset.sum_filter _ _).symm _ = ∑ p ∈ s.filter fun p : G × G ↦ p.1 ∈ f.support ∧ p.2 ∈ g.support, f.coeff p.1 * p.1 • g.coeff p.2 := (Finset.sum_congr (by ext; simp [Finset.mem_filter, Finset.mem_product, hs, and_comm]) fun _ _ ↦ rfl) _ = ∑ p ∈ s, f.coeff p.1 * p.1 • g.coeff p.2 := Finset.sum_subset (Finset.filter_subset _ _) fun p hps hp ↦ by simp only [Finset.mem_filter, mem_support_iff, not_and, Classical.not_not] at hp ⊢ by_cases h1 : f.coeff p.1 = 0 <;> simp_all theorem coeff_mul_antidiagonal_finsum (f g : SkewMonoidAlgebra k G) (x : G) : (f * g).coeff x = ∑ᶠ p ∈ {p : G × G | p.1 * p.2 = x}, f.coeff p.1 * p.1 • g.coeff p.2 := by have : ({p : G × G | p.1 * p.2 = x} ∩ Function.support fun p ↦ f.coeff p.1 * p.1 • g.coeff p.2).Finite := by apply Set.Finite.inter_of_right apply Set.Finite.subset (Finset.finite_toSet ((f.support).product (g.support))) aesop rw [← finsum_mem_inter_support, finsum_mem_eq_finite_toFinset_sum _ this] classical let s := Set.Finite.toFinset (s := ({p : G × G | p.1 * p.2 = x} ∩ Function.support fun p ↦ f.coeff p.1 * p.1 • g.coeff p.2)) this let F : G × G → k := fun p ↦ if p.1 * p.2 = x then f.coeff p.1 * p.1 • g.coeff p.2 else 0 calc (f * g).coeff x = ∑ a₁ ∈ f.support, ∑ a₂ ∈ g.support, F (a₁, a₂) := coeff_mul f g x _ = ∑ p ∈ f.support ×ˢ g.support, F p := by rw [← Finset.sum_product _ _ _] _ = ∑ p ∈ (f.support ×ˢ g.support).filter fun p : G × G ↦ p.1 * p.2 = x, f.coeff p.1 * p.1 • g.coeff p.2 := (Finset.sum_filter _ _).symm _ = ∑ p ∈ s.filter fun p : G × G ↦ p.1 ∈ f.support ∧ p.2 ∈ g.support, f.coeff p.1 * p.1 • g.coeff p.2 := by apply Finset.sum_congr_of_eq_on_inter <;> aesop _ = ∑ p ∈ s, f.coeff p.1 * p.1 • g.coeff p.2 := Finset.sum_subset (Finset.filter_subset _ _) fun p hps hp ↦ by simp only [Finset.mem_filter, mem_support_iff, not_and, Classical.not_not] at hp ⊢ by_cases h1 : f.coeff p.1 = 0 <;> simp_all theorem coeff_mul_single_aux (f : SkewMonoidAlgebra k G) {r : k} {x y z : G} (H : ∀ a, a * x = z ↔ a = y) : (f * single x r).coeff z = f.coeff y * y • r := by classical have A : ∀ a₁ b₁, ((single x r).sum fun a₂ b₂ ↦ ite (a₁ * a₂ = z) (b₁ * a₁ • b₂) 0) = ite (a₁ * x = z) (b₁ * a₁ • r) 0 := fun a₁ b₁ ↦ sum_single_index <| by simp calc (f * (single x r)).coeff z = sum f fun a b ↦ if a = y then b * y • r else 0 := by simp [coeff_mul, A, H, sum_ite_eq'] _ = if y ∈ f.support then f.coeff y * y • r else 0 := (f.support.sum_ite_eq' _ _) _ = f.coeff y * y • r := by split_ifs with h <;> simp [support] at h <;> simp [h] theorem coeff_mul_single_one (f : SkewMonoidAlgebra k G) (r : k) (x : G) : (f * single 1 r).coeff x = f.coeff x * x • r := f.coeff_mul_single_aux fun a ↦ by rw [mul_one] theorem coeff_mul_single_of_not_exists_mul (r : k) {g g' : G} (x : SkewMonoidAlgebra k G) (h : ∀ x, ¬g' = x * g) : (x * single g r).coeff g' = 0 := by classical simp only [coeff_mul, smul_zero, mul_zero, ite_self, sum_single_index] apply Finset.sum_eq_zero simp_rw [ite_eq_right_iff] rintro _ _ rfl exact False.elim (h _ rfl) theorem coeff_single_mul_aux (f : SkewMonoidAlgebra k G) {r : k} {x y z : G} (H : ∀ a, x * a = y ↔ a = z) : (single x r * f).coeff y = r * x • f.coeff z := by classical have : (f.sum fun a b ↦ ite (x * a = y) (0 * x • b) 0) = 0 := by simp calc ((single x r) * f).coeff y = sum f fun a b ↦ ite (x * a = y) (r * x • b) 0 := (coeff_mul _ _ _).trans <| sum_single_index this _ = f.sum fun a b ↦ ite (a = z) (r * x • b) 0 := by simp [H] _ = if z ∈ f.support then r * x • f.coeff z else 0 := (f.support.sum_ite_eq' _ _) _ = _ := by split_ifs with h <;> simp [support] at h <;> simp [h] theorem coeff_single_one_mul (f : SkewMonoidAlgebra k G) (r : k) (x : G) : (single (1 : G) r * f).coeff x = r * f.coeff x := by simp [coeff_single_mul_aux, one_smul] theorem coeff_single_mul_of_not_exists_mul (r : k) {g g' : G} (x : SkewMonoidAlgebra k G) (h : ¬∃ d, g' = g * d) : (single g r * x).coeff g' = 0 := by classical rw [coeff_mul, sum_single_index] · apply Finset.sum_eq_zero simp_rw [ite_eq_right_iff] rintro g'' _hg'' rfl exact absurd ⟨_, rfl⟩ h · simp end Monoid section Group -- We now prove some additional statements that hold for group algebras. variable [Group G] [MulSemiringAction G k] @[simp] theorem coeff_mul_single (f : SkewMonoidAlgebra k G) (r : k) (x y : G) : (f * single x r).coeff y = f.coeff (y * x⁻¹) * (y * x⁻¹) • r := f.coeff_mul_single_aux fun _a ↦ eq_mul_inv_iff_mul_eq.symm @[simp] theorem coeff_single_mul (r : k) (x : G) (f : SkewMonoidAlgebra k G) (y : G) : (single x r * f).coeff y = r * x • f.coeff (x⁻¹ * y) := f.coeff_single_mul_aux fun _z ↦ eq_inv_mul_iff_mul_eq.symm theorem coeff_mul_left (f g : SkewMonoidAlgebra k G) (x : G) : (f * g).coeff x = f.sum fun a b ↦ b * a • g.coeff (a⁻¹ * x) := calc (f * g).coeff x = sum f fun a b ↦ (single a b * g).coeff x := by rw [← coeff_sum, ← sum_mul g f, f.sum_single] _ = _ := by simp theorem coeff_mul_right (f g : SkewMonoidAlgebra k G) (x : G) : (f * g).coeff x = g.sum fun a b ↦ f.coeff (x * a⁻¹) * (x * a⁻¹) • b := calc (f * g).coeff x = sum g fun a b ↦ (f * single a b).coeff x := by rw [← coeff_sum, ← mul_sum f g, g.sum_single] _ = _ := by simp end Group end coeff_mul section AddHom variable [AddCommMonoid k] /-- `single` as an `AddMonoidHom`. See `lsingle` for the stronger version as a linear map. -/ @[simps] def singleAddHom (a : G) : k →+ SkewMonoidAlgebra k G where toFun := single a map_zero' := single_zero a map_add' _ := single_add a _ @[ext high] theorem addHom_ext' {N : Type*} [AddZeroClass N] ⦃f g : SkewMonoidAlgebra k G →+ N⦄ (H : ∀ x, f.comp (singleAddHom x) = g.comp (singleAddHom x)) : f = g := addHom_ext fun x ↦ DFunLike.congr_fun (H x) end AddHom section Semiring variable [Semiring k] section singleOneRingHom variable [Monoid G] [MulSemiringAction G k] @[simp] theorem single_mul_single {a₁ a₂ : G} {b₁ b₂ : k} : (single a₁ b₁) * (single a₂ b₂) = single (a₁ * a₂) (b₁ * a₁ • b₂) := (sum_single_index (by simp [zero_mul, single_zero, sum_zero])).trans (sum_single_index (by simp [smul_zero, mul_zero, single_zero])) /-- `single 1` as a `RingHom` -/ def singleOneRingHom : k →+* SkewMonoidAlgebra k G where __ := singleAddHom 1 map_one' := rfl map_mul' x y := by simp [ZeroHom.toFun_eq_coe, AddMonoidHom.toZeroHom_coe, singleAddHom_apply, single_mul_single, mul_one, one_smul] /-- If two ring homomorphisms from `SkewMonoidAlgebra k G` are equal on all `single a 1` and `single 1 b`, then they are equal. -/ theorem ringHom_ext {f g : SkewMonoidAlgebra k G →+* k} (h₁ : ∀ b, f (single 1 b) = g (single 1 b)) (h_of : ∀ a, f (single a 1) = g (single a 1)) : f = g := have {a : G} {b₁ b₂ : k} : (single 1 b₁) * (single a b₂) = single a (b₁ * b₂) := by simp [single_mul_single, one_mul, one_smul] RingHom.coe_addMonoidHom_injective <| addHom_ext fun a b ↦ by rw [← mul_one b, ← this, AddMonoidHom.coe_coe f, AddMonoidHom.coe_coe g, f.map_mul, g.map_mul, h₁, h_of] end singleOneRingHom section MapDomain variable {α α₂ β F : Type*} [Semiring β] [Monoid α] [Monoid α₂] [FunLike F α α₂] /-- Like `mapDomain_zero`, but for the `1` we define in this file -/ theorem mapDomain_one [MonoidHomClass F α α₂] (f : F) : (mapDomain f (1 : SkewMonoidAlgebra β α) : SkewMonoidAlgebra β α₂) = (1 : SkewMonoidAlgebra β α₂) := by simp_rw [one_def, mapDomain_single, map_one] /- Like `mapDomain_add`, but for the skewed convolutive multiplication we define in this file. This theorem holds assuming that `(hf : ∀ (a : α) (x : β), a • x = (f a) • x)`. -/ theorem mapDomain_mul [MulSemiringAction α β] [MulSemiringAction α₂ β] [MulHomClass F α α₂] {f : F} (x y : SkewMonoidAlgebra β α) (hf : ∀ (a : α) (x : β), a • x = (f a) • x) : mapDomain f (x * y) = mapDomain f x * mapDomain f y := by rw [mul_def, map_sum] have : (sum x fun a b ↦ sum y fun a₂ b₂ ↦ mapDomain (↑f) (single (a * a₂) (b * a • b₂))) = sum (mapDomain (↑f) x) fun a₁ b₁ ↦ sum (mapDomain (↑f) y) fun a₂ b₂ ↦ single (a₁ * a₂) (b₁ * a₁ • b₂) := by simp_rw [mapDomain_single, map_mul] rw [sum_mapDomain_index (by simp) (by simp [add_mul, single_add, sum_add])] congr ext a b c rw [sum_mapDomain_index (by simp) (by simp [smul_add, mul_add, single_add])] simp_rw [hf] convert this using 4 rw [map_sum] /-- If f : G → H is a multiplicative homomorphism between two monoids and `∀ (a : G) (x : k), a • x = (f a) • x`, then `mapDomain f` is a ring homomorphism between their skew monoid algebras. -/ def mapDomainRingHom [MulSemiringAction α β] [MulSemiringAction α₂ β] [MonoidHomClass F α α₂] {f : F} (hf : ∀ (a : α) (x : β), a • x = (f a) • x) : SkewMonoidAlgebra β α →+* SkewMonoidAlgebra β α₂ where __ := (mapDomain f : SkewMonoidAlgebra β α →+ SkewMonoidAlgebra β α₂) map_one' := mapDomain_one f map_mul' x y := mapDomain_mul x y hf end MapDomain section of variable (k G) variable [Monoid G] [MulSemiringAction G k] /-- The embedding of a monoid into its skew monoid algebra. -/ def of : G →* SkewMonoidAlgebra k G where toFun a := single a 1 map_one' := rfl map_mul' a b := by simp @[simp] lemma of_apply (a : G) : (of k G) a = single a 1 := by simp [of, MonoidHom.coe_mk, OneHom.coe_mk] theorem smul_of (g : G) (r : k) : r • of k G g = single g r := by rw [of_apply, smul_single, smul_eq_mul, mul_one] theorem of_injective [Nontrivial k] : Function.Injective (of k G) := fun a b h ↦ by simp_rw [of_apply, ← toFinsupp_inj] at h simpa using (Finsupp.single_eq_single_iff _ _ _ _).mp h /-- If two ring homomorphisms from `SkewMonoidAlgebra k G` are equal on all `single a 1` and `single 1 b`, then they are equal. See note [partially-applied ext lemmas]. -/ @[ext high] theorem ringHom_ext' {f g : SkewMonoidAlgebra k G →+* k} (h₁ : f.comp singleOneRingHom = g.comp singleOneRingHom) (h_of : (f : SkewMonoidAlgebra k G →* k).comp (of k G) = (g : SkewMonoidAlgebra k G →* k).comp (of k G)) : f = g := ringHom_ext (RingHom.congr_fun h₁) (DFunLike.congr_fun h_of) end of /-! #### Non-unital, non-associative algebra structure -/ section NonUnitalNonAssocAlgebra theorem liftNC_smul [MulOneClass G] {R : Type*} [Semiring R] (f : k →+* R) (g : G →* R) (c : k) (φ : SkewMonoidAlgebra k G) : liftNC (f : k →+ R) g (c • φ) = f c * liftNC (f : k →+ R) g φ := by suffices this : (liftNC ↑f g).comp (smulAddHom k (SkewMonoidAlgebra k G) c) = (AddMonoidHom.mulLeft (f c)).comp (liftNC ↑f g) by simpa using congr($this φ) refine addHom_ext' fun a => AddMonoidHom.ext fun b => ?_ simp [smul_single, mul_assoc] variable (k G) [Monoid G] [MulSemiringAction G k] instance isScalarTower_self [IsScalarTower k k k] : IsScalarTower k (SkewMonoidAlgebra k G) (SkewMonoidAlgebra k G) := ⟨fun t a b ↦ by classical simp only [smul_eq_mul] refine Eq.trans (sum_smul_index' (g := a) (b := t) ?_) ?_ <;> simp only [← smul_sum, smul_mul_assoc, ← smul_single, zero_mul, imp_true_iff, sum_zero, single_zero]; rfl⟩ end NonUnitalNonAssocAlgebra end Semiring section DistribMulActionHom variable {R M N : Type*} [Semiring R] [AddCommMonoid M] [AddCommMonoid N] /-- `single` as a `DistribMulActionSemiHom`. See also `lsingle` for the version as a linear map. -/ @[simps] def DistribMulActionHom.single [DistribMulAction R M] {α : Type*} (a : α) : M →+[R] SkewMonoidAlgebra M α where __ := singleAddHom a map_smul' k m := by simp [singleAddHom, smul_single, MonoidHom.id_apply] theorem distribMulActionHom_ext [DistribMulAction R M] [DistribMulAction R N] {α : Type*} {f g : SkewMonoidAlgebra M α →+[R] N} (h : ∀ (a : α) (m : M), f (single a m) = g (single a m)) : f = g := DistribMulActionHom.toAddMonoidHom_injective <| addHom_ext h /-- See note [partially-applied ext lemmas]. -/ @[ext] theorem distribMulActionHom_ext' [DistribMulAction R M] [DistribMulAction R N] {α : Type*} {f g : SkewMonoidAlgebra M α →+[R] N} (h : ∀ a : α, f.comp (DistribMulActionHom.single a) = g.comp (DistribMulActionHom.single a)) : f = g := distribMulActionHom_ext fun a ↦ DistribMulActionHom.congr_fun (h a) /-- Interpret `single a` as a linear map. -/ def lsingle {α : Type*} (a : α) [Module R M] : M →ₗ[R] (SkewMonoidAlgebra M α) where __ := singleAddHom a map_smul' _ _ := (smul_single _ _ _).symm /-- Two `R`-linear maps from `SkewMonoidAlgebra M α` which agree on each `single x y` agree everywhere. -/ theorem lhom_ext {α : Type*} [Module R M] [Module R N] ⦃φ ψ : SkewMonoidAlgebra M α →ₗ[R] N⦄ (h : ∀ a b, φ (single a b) = ψ (single a b)) : φ = ψ := LinearMap.toAddMonoidHom_injective <| addHom_ext h @[ext high] theorem lhom_ext' {α : Type*} [Module R M] [Module R N] ⦃φ ψ : SkewMonoidAlgebra M α →ₗ[R] N⦄ (h : ∀ a, φ.comp (lsingle a) = ψ.comp (lsingle a)) : φ = ψ := lhom_ext fun a ↦ LinearMap.congr_fun (h a) variable {A : Type*} [NonUnitalNonAssocSemiring A] [Monoid G] [Semiring k] [MulSemiringAction G k] open NonUnitalAlgHom /-- A non_unital `k`-algebra homomorphism from `SkewMonoidAlgebra k G` is uniquely defined by its values on the functions `single a 1`. -/ theorem nonUnitalAlgHom_ext [DistribMulAction k A] {φ₁ φ₂ : SkewMonoidAlgebra k G →ₙₐ[k] A} (h : ∀ x, φ₁ (single x 1) = φ₂ (single x 1)) : φ₁ = φ₂ := by apply NonUnitalAlgHom.to_distribMulActionHom_injective apply distribMulActionHom_ext' intro a ext simp [singleAddHom_apply, h] /-- See note [partially-applied ext lemmas]. -/ @[ext high] theorem nonUnitalAlgHom_ext' [DistribMulAction k A] {φ₁ φ₂ : SkewMonoidAlgebra k G →ₙₐ[k] A} (h : φ₁.toMulHom.comp (of k G).toMulHom = φ₂.toMulHom.comp (of k G).toMulHom) : φ₁ = φ₂ := nonUnitalAlgHom_ext <| DFunLike.congr_fun h end DistribMulActionHom section CommSemiring variable [Monoid G] [CommSemiring k] variable {A : Type*} [Semiring A] [Algebra k A] /-- The instance `Algebra k (SkewMonoidAlgebra A G)` whenever we have `Algebra k A`. In particular this provides the instance `Algebra k (SkewMonoidAlgebra k G)`. -/ instance [MulSemiringAction G A] [SMulCommClass G k A] : Algebra k (SkewMonoidAlgebra A G) where algebraMap := singleOneRingHom.comp (algebraMap k A) smul_def' r a := by ext simp only [RingHom.coe_comp, comp_apply, coeff_smul, Algebra.smul_def, singleOneRingHom, singleAddHom, ZeroHom.toFun_eq_coe, ZeroHom.coe_mk, RingHom.coe_mk, MonoidHom.coe_mk, OneHom.coe_mk, coeff_single_one_mul] commutes' r f := by ext simp only [singleOneRingHom, singleAddHom, ZeroHom.toFun_eq_coe, ZeroHom.coe_mk, RingHom.coe_mk, MonoidHom.coe_mk, OneHom.coe_mk, coeff_single_one_mul, Algebra.commutes, coeff_mul_single_one, smul_algebraMap, RingHom.coe_comp, comp_apply] @[simp] theorem coe_algebraMap [MulSemiringAction G A] [SMulCommClass G k A] : ⇑(algebraMap k (SkewMonoidAlgebra A G)) = single 1 ∘ algebraMap k A := rfl theorem single_eq_algebraMap_mul_of [MulSemiringAction G k] [SMulCommClass G k k] (a : G) (b : k) : single a b = algebraMap k (SkewMonoidAlgebra k G) b * of k G a := by simp [coe_algebraMap, comp_apply, of_apply, single_mul_single, one_mul, smul_one, mul_one] theorem single_algebraMap_eq_algebraMap_mul_of (a : G) (b : k) [MulSemiringAction G A] [SMulCommClass G k A] : single a (algebraMap k A b) = algebraMap k (SkewMonoidAlgebra A G) b * of A G a := by simp [coe_algebraMap, comp_apply, of_apply, single_mul_single, one_mul, smul_one, mul_one] /- Hypotheses needed for `k`-algebra homomorphism from `SkewMonoidAlgebra k G`-/ variable [MulSemiringAction G k] [SMulCommClass G k k] /-- A `k`-algebra homomorphism from `SkewMonoidAlgebra k G` is uniquely defined by its values on the functions `single a 1`. -/ theorem algHom_ext ⦃φ₁ φ₂ : AlgHom k (SkewMonoidAlgebra k G) A⦄ (h : ∀ x, φ₁ (single x 1) = φ₂ (single x 1)) : φ₁ = φ₂ := AlgHom.toLinearMap_injective (lhom_ext' fun a ↦ (LinearMap.ext_ring (h a))) @[ext high] theorem algHom_ext' ⦃φ₁ φ₂ : AlgHom k (SkewMonoidAlgebra k G) A⦄ (h : (φ₁ : SkewMonoidAlgebra k G →* A).comp (of k G) = (φ₂ : SkewMonoidAlgebra k G →* A).comp (of k G)) : φ₁ = φ₂ := algHom_ext <| DFunLike.congr_fun h end CommSemiring end SkewMonoidAlgebra
.lake/packages/mathlib/Mathlib/Algebra/SkewMonoidAlgebra/Lift.lean
import Mathlib.Algebra.SkewMonoidAlgebra.Basic import Mathlib.Algebra.Module.BigOperators import Mathlib.Algebra.Algebra.Equiv /-! # Lemmas about different kinds of "lifts" to `SkewMonoidAlgebra`. -/ noncomputable section namespace SkewMonoidAlgebra variable {k G H : Type*} section lift variable [CommSemiring k] [Monoid G] [Monoid H] variable {A B : Type*} [Semiring A] [Algebra k A] [Semiring B] [Algebra k B] /-- `liftNCRingHom` as an `AlgHom`, for when `f` is an `AlgHom` -/ def liftNCAlgHom [MulSemiringAction G A] [SMulCommClass G k A] (f : A →ₐ[k] B) (g : G →* B) (h_comm : ∀ {x y}, (f (y • x)) * g y = (g y) * (f x)) : SkewMonoidAlgebra A G →ₐ[k] B where __ := liftNCRingHom (f : A →+* B) g h_comm commutes' := by simp [liftNCRingHom] /- Hypotheses needed for `k`-algebra homomorphism from `SkewMonoidAlgebra k G`-/ variable [MulSemiringAction G k] [SMulCommClass G k k] variable (k G A) /-- Any monoid homomorphism `G →* A` can be lifted to an algebra homomorphism `SkewMonoidAlgebra k G →ₐ[k] A`. -/ def lift : (G →* A) ≃ (AlgHom k (SkewMonoidAlgebra k G) A) where invFun f := (f : SkewMonoidAlgebra k G →* A).comp (of k G) toFun F := by apply liftNCAlgHom (Algebra.ofId k A) F simp_rw [show ∀ (g : G) (r : k), g • r = r by exact fun _ _ ↦ smul_algebraMap _ (algebraMap k k _)] exact Algebra.commutes _ _ left_inv f := by ext simp [liftNCAlgHom, liftNCRingHom] right_inv F := by ext simp [liftNCAlgHom, liftNCRingHom] variable {k G A} theorem lift_apply' (F : G →* A) (f : SkewMonoidAlgebra k G) : lift k G A F f = f.sum fun a b ↦ algebraMap k A b * F a := rfl theorem lift_apply (F : G →* A) (f : SkewMonoidAlgebra k G) : lift k G A F f = f.sum fun a b ↦ b • F a := by simp [lift_apply', Algebra.smul_def] theorem lift_def (F : G →* A) : (lift k G A F : SkewMonoidAlgebra k G → A) = liftNC ((algebraMap k A : k →+* A) : k →+ A) F := rfl @[simp] theorem lift_symm_apply (F : AlgHom k (SkewMonoidAlgebra k G) A) (x : G) : (lift k G A).symm F x = F (single x 1) := rfl theorem lift_of (F : G →* A) (x) : lift k G A F (of k G x) = F x := by rw [of_apply, ← lift_symm_apply, Equiv.symm_apply_apply] @[simp] theorem lift_single (F : G →* A) (a b) : lift k G A F (single a b) = b • F a := by rw [lift_def, liftNC_single, Algebra.smul_def, AddMonoidHom.coe_coe] theorem lift_unique' (F : AlgHom k (SkewMonoidAlgebra k G) A) : F = lift k G A ((F : SkewMonoidAlgebra k G →* A).comp (of k G)) := ((lift k G A).apply_symm_apply F).symm /-- Decomposition of a `k`-algebra homomorphism from `SkewMonoidAlgebra k G` by its values on `F (single a 1)`. -/ theorem lift_unique (F : AlgHom k (SkewMonoidAlgebra k G) A) (f : SkewMonoidAlgebra k G) : F f = f.sum fun a b ↦ b • F (single a 1) := by conv_lhs => rw [lift_unique' F] simp [lift_apply] /-- If `f : G → H` is a multiplicative homomorphism between two monoids, then `mapDomain f` is an algebra homomorphism between their monoid algebras. -/ @[simps!] def mapDomainAlgHom (k A : Type*) [CommSemiring k] [Semiring A] [Algebra k A] {H F : Type*} [Monoid H] [FunLike F G H] [MonoidHomClass F G H] [MulSemiringAction G A] [MulSemiringAction H A] [SMulCommClass G k A] [SMulCommClass H k A] {f : F} (hf : ∀ (a : G) (x : A), a • x = (f a) • x) : SkewMonoidAlgebra A G →ₐ[k] SkewMonoidAlgebra A H where __ := mapDomainRingHom hf commutes' := by simp [mapDomainRingHom] end lift section equivMapDomain variable [AddCommMonoid k] /-- Given `f : G ≃ H`, we can map `l : SkewMonoidAlgebra k G` to `equivMapDomain f l : SkewMonoidAlgebra k H` (computably) by mapping the support forwards and the function backwards. -/ def equivMapDomain (f : G ≃ H) (l : SkewMonoidAlgebra k G) : SkewMonoidAlgebra k H where toFinsupp := ⟨l.support.map f.toEmbedding, fun a ↦ l.coeff (f.symm a), by simp⟩ @[simp] theorem coeff_equivMapDomain (f : G ≃ H) (l : SkewMonoidAlgebra k G) (b : H) : (equivMapDomain f l).coeff b = l.coeff (f.symm b) := rfl lemma toFinsupp_equivMapDomain (f : G ≃ H) (l : SkewMonoidAlgebra k G) : (equivMapDomain f l).toFinsupp = Finsupp.equivMapDomain f l.toFinsupp := rfl theorem equivMapDomain_eq_mapDomain (f : G ≃ H) (l : SkewMonoidAlgebra k G) : equivMapDomain f l = mapDomain f l := by apply toFinsupp_injective ext x simp_rw [toFinsupp_equivMapDomain, Finsupp.equivMapDomain_apply, toFinsupp_mapDomain, Finsupp.mapDomain_equiv_apply] theorem equivMapDomain_trans {G' G'' : Type*} (f : G ≃ G') (g : G' ≃ G'') (l : SkewMonoidAlgebra k G) : equivMapDomain (f.trans g) l = equivMapDomain g (equivMapDomain f l) := by ext x; rfl @[simp] theorem equivMapDomain_refl (l : SkewMonoidAlgebra k G) : equivMapDomain (Equiv.refl _) l = l := by ext x; rfl @[simp] theorem equivMapDomain_single (f : G ≃ H) (a : G) (b : k) : equivMapDomain f (single a b) = single (f a) b := by classical apply toFinsupp_injective simp_rw [toFinsupp_equivMapDomain, single, Finsupp.equivMapDomain_single] end equivMapDomain section domCongr variable {A : Type*} /-- Given `AddCommMonoid A` and `e : G ≃ H`, `domCongr e` is the corresponding `Equiv` between `SkewMonoidAlgebra A G` and `SkewMonoidAlgebra A H`. -/ @[simps apply] def domCongr [AddCommMonoid A] (e : G ≃ H) : SkewMonoidAlgebra A G ≃+ SkewMonoidAlgebra A H where toFun := equivMapDomain e invFun := equivMapDomain e.symm left_inv v := by simp [← equivMapDomain_trans] right_inv v := by simp [← equivMapDomain_trans] map_add' a b := by simp [equivMapDomain_eq_mapDomain, map_add] /-- An equivalence of domains induces a linear equivalence of finitely supported functions. This is `domCongr` as a `LinearEquiv`. -/ def domLCongr [Semiring k] [AddCommMonoid A] [Module k A] (e : G ≃ H) : SkewMonoidAlgebra A G ≃ₗ[k] SkewMonoidAlgebra A H := (domCongr e : SkewMonoidAlgebra A G ≃+ SkewMonoidAlgebra A H).toLinearEquiv <| by simp only [domCongr_apply] intro c x simp_rw [equivMapDomain_eq_mapDomain, mapDomain_smul] variable (k A) variable [Monoid G] [Monoid H] [Semiring A] [CommSemiring k] [Algebra k A] [MulSemiringAction G A] [MulSemiringAction H A] [SMulCommClass G k A] [SMulCommClass H k A] /-- If `e : G ≃* H` is a multiplicative equivalence between two monoids and ` ∀ (a : G) (x : A), a • x = (e a) • x`, then `SkewMonoidAlgebra.domCongr e` is an algebra equivalence between their skew monoid algebras. -/ def domCongrAlg {e : G ≃* H} (he : ∀ (a : G) (x : A), a • x = (e a) • x) : SkewMonoidAlgebra A G ≃ₐ[k] SkewMonoidAlgebra A H := AlgEquiv.ofLinearEquiv (domLCongr e : SkewMonoidAlgebra A G ≃ₗ[k] SkewMonoidAlgebra A H) ((equivMapDomain_eq_mapDomain _ _).trans <| mapDomain_one e) (fun f g ↦ (equivMapDomain_eq_mapDomain _ _).trans <| (mapDomain_mul f g he).trans <| congr_arg₂ _ (equivMapDomain_eq_mapDomain _ _).symm (equivMapDomain_eq_mapDomain _ _).symm) theorem domCongrAlg_toAlgHom {e : G ≃* H} (he : ∀ (a : G) (x : A), a • x = (e a) • x) : (domCongrAlg k A he).toAlgHom = mapDomainAlgHom k A he := AlgHom.ext <| fun _ ↦ equivMapDomain_eq_mapDomain _ _ @[simp] theorem domCongrAlg_apply {e : G ≃* H} (he : ∀ (a : G) (x : A), a • x = (e a) • x) (f : SkewMonoidAlgebra A G) (h : H) : (domCongrAlg k A he f).coeff h = f.coeff (e.symm h) := rfl @[simp] theorem domCongr_support {e : G ≃* H} (he : ∀ (a : G) (x : A), a • x = (e a) • x) (f : SkewMonoidAlgebra A G) : (domCongrAlg k A he f).support = f.support.map e := rfl @[simp] theorem domCongr_single {e : G ≃* H} (he : ∀ (a : G) (x : A), a • x = (e a) • x) (g : G) (a : A) : domCongrAlg k A he (single g a) = single (e g) a := equivMapDomain_single .. theorem domCongr_refl : domCongrAlg k A (e := MulEquiv.refl G) (fun _ _ ↦ rfl) = AlgEquiv.refl := by apply AlgEquiv.ext aesop @[simp] theorem domCongr_symm {e : G ≃* H} (he : ∀ (a : G) (x : A), a • x = (e a) • x) : (domCongrAlg k A he).symm = domCongrAlg _ _ (fun a x ↦ by rw [he, MulEquiv.apply_symm_apply]) := rfl end domCongr section Submodule variable [Semiring k] [Monoid G] [MulSemiringAction G k] variable {V : Type*} [AddCommMonoid V] [Module k V] [Module (SkewMonoidAlgebra k G) V] [IsScalarTower k (SkewMonoidAlgebra k G) V] /-- A submodule over `k` which is stable under scalar multiplication by elements of `G` is a submodule over `SkewMonoidAlgebra k G` -/ def submoduleOfSmulMem (W : Submodule k V) (h : ∀ (g : G) (v : V), v ∈ W → of k G g • v ∈ W) : Submodule (SkewMonoidAlgebra k G) V where carrier := W zero_mem' := W.zero_mem' add_mem' := W.add_mem' smul_mem' := by intro f v hv rw [← sum_single f, sum_def, Finsupp.sum, Finset.sum_smul] simp_rw [← smul_of, smul_assoc] exact Submodule.sum_smul_mem W _ fun g _ ↦ h g v hv end Submodule end SkewMonoidAlgebra
.lake/packages/mathlib/Mathlib/Algebra/Ring/SumsOfSquares.lean
import Mathlib.Algebra.Group.Subgroup.Even import Mathlib.Algebra.Order.Ring.Basic import Mathlib.Algebra.Ring.Parity -- Algebra.Group.Even can't prove `IsSquare 0` by simp import Mathlib.Algebra.Ring.Subsemiring.Basic import Mathlib.Tactic.ApplyFun /-! # Sums of squares We introduce a predicate for sums of squares in a ring. ## Main declarations - `IsSumSq : R → Prop`: for a type `R` with addition, multiplication and a zero, an inductive predicate defining the property of being a sum of squares in `R`. `0 : R` is a sum of squares and if `S` is a sum of squares, then, for all `a : R`, `a * a + s` is a sum of squares. - `AddMonoid.sumSq R` and `Subsemiring.sumSq R`: respectively the submonoid or subsemiring of sums of squares in an additive monoid or semiring `R` with multiplication. -/ variable {R : Type*} /-- The property of being a sum of squares is defined inductively by: `0 : R` is a sum of squares and if `s : R` is a sum of squares, then for all `a : R`, `a * a + s` is a sum of squares in `R`. -/ @[mk_iff] inductive IsSumSq [Mul R] [Add R] [Zero R] : R → Prop | zero : IsSumSq 0 | sq_add (a : R) {s : R} (hs : IsSumSq s) : IsSumSq (a * a + s) /-- Alternative induction scheme for `IsSumSq` which uses `IsSquare`. -/ theorem IsSumSq.rec' [Mul R] [Add R] [Zero R] {motive : (s : R) → (h : IsSumSq s) → Prop} (zero : motive 0 zero) (sq_add : ∀ {x s}, (hx : IsSquare x) → (hs : IsSumSq s) → motive s hs → motive (x + s) (by rcases hx with ⟨_, rfl⟩; exact sq_add _ hs)) {s : R} (h : IsSumSq s) : motive s h := match h with | .zero => zero | .sq_add _ hs => sq_add (.mul_self _) hs (rec' zero sq_add _) /-- In an additive monoid with multiplication, if `s₁` and `s₂` are sums of squares, then `s₁ + s₂` is a sum of squares. -/ @[aesop unsafe 90% apply] theorem IsSumSq.add [AddMonoid R] [Mul R] {s₁ s₂ : R} (h₁ : IsSumSq s₁) (h₂ : IsSumSq s₂) : IsSumSq (s₁ + s₂) := by induction h₁ <;> simp_all [add_assoc, sq_add] namespace AddSubmonoid variable {T : Type*} [AddMonoid T] [Mul T] {s : T} variable (T) in /-- In an additive monoid with multiplication `R`, `AddSubmonoid.sumSq R` is the submonoid of sums of squares in `R`. -/ @[simps] def sumSq [AddMonoid T] : AddSubmonoid T where carrier := {s : T | IsSumSq s} zero_mem' := .zero add_mem' := .add attribute [norm_cast] coe_sumSq @[simp] theorem mem_sumSq : s ∈ sumSq T ↔ IsSumSq s := Iff.rfl end AddSubmonoid /-- In an additive unital magma with multiplication, `x * x` is a sum of squares for all `x`. -/ @[simp] theorem IsSumSq.mul_self [AddZeroClass R] [Mul R] (a : R) : IsSumSq (a * a) := by simpa using sq_add a zero /-- In an additive unital magma with multiplication, squares are sums of squares (see Mathlib.Algebra.Group.Even). -/ @[aesop unsafe 80% apply] theorem IsSquare.isSumSq [AddZeroClass R] [Mul R] {x : R} (hx : IsSquare x) : IsSumSq x := by aesop attribute [simp, aesop safe] IsSumSq.zero @[simp, aesop safe] theorem IsSumSq.one [AddZeroClass R] [MulOneClass R] : IsSumSq (1 : R) := by aesop /-- In an additive monoid with multiplication `R`, the submonoid generated by the squares is the set of sums of squares in `R`. -/ @[simp] theorem AddSubmonoid.closure_isSquare [AddMonoid R] [Mul R] : closure {x : R | IsSquare x} = sumSq R := by refine closure_eq_of_le (fun x hx ↦ IsSquare.isSumSq hx) (fun x hx ↦ ?_) induction hx <;> aesop /-- In an additive commutative monoid with multiplication, a finite sum of sums of squares is a sum of squares. -/ @[aesop unsafe 90% apply] theorem IsSumSq.sum [AddCommMonoid R] [Mul R] {ι : Type*} {I : Finset ι} {s : ι → R} (hs : ∀ i ∈ I, IsSumSq <| s i) : IsSumSq (∑ i ∈ I, s i) := by simpa using sum_mem (S := AddSubmonoid.sumSq _) hs /-- In an additive commutative monoid with multiplication, `∑ i ∈ I, x i`, where each `x i` is a square, is a sum of squares. -/ theorem IsSumSq.sum_isSquare [AddCommMonoid R] [Mul R] {ι : Type*} (I : Finset ι) {x : ι → R} (hx : ∀ i ∈ I, IsSquare <| x i) : IsSumSq (∑ i ∈ I, x i) := by aesop /-- In an additive commutative monoid with multiplication, `∑ i ∈ I, a i * a i` is a sum of squares. -/ @[simp↓] theorem IsSumSq.sum_mul_self [AddCommMonoid R] [Mul R] {ι : Type*} (I : Finset ι) (a : ι → R) : IsSumSq (∑ i ∈ I, a i * a i) := by aesop @[simp↓] theorem IsSumSq.sum_sq [CommSemiring R] {ι : Type*} (I : Finset ι) (a : ι → R) : IsSumSq (∑ i ∈ I, a i ^ 2) := by aesop namespace NonUnitalSubsemiring variable {T : Type*} [NonUnitalCommSemiring T] variable (T) in /-- In a commutative (possibly non-unital) semiring `R`, `NonUnitalSubsemiring.sumSq R` is the (possibly non-unital) subsemiring of sums of squares in `R`. -/ def sumSq : NonUnitalSubsemiring T := (Subsemigroup.square T).nonUnitalSubsemiringClosure @[simp] theorem sumSq_toAddSubmonoid : (sumSq T).toAddSubmonoid = .sumSq T := by simp [sumSq, ← AddSubmonoid.closure_isSquare, Subsemigroup.nonUnitalSubsemiringClosure_toAddSubmonoid] @[simp] theorem mem_sumSq {s : T} : s ∈ sumSq T ↔ IsSumSq s := by simp [← NonUnitalSubsemiring.mem_toAddSubmonoid] @[simp, norm_cast] theorem coe_sumSq : sumSq T = {s : T | IsSumSq s} := by ext; simp @[simp] theorem closure_isSquare : closure {x : T | IsSquare x} = sumSq T := by simp [sumSq, Subsemigroup.nonUnitalSubsemiringClosure_eq_closure] end NonUnitalSubsemiring /-- In a commutative (possibly non-unital) semiring, if `s₁` and `s₂` are sums of squares, then `s₁ * s₂` is a sum of squares. -/ @[aesop unsafe 90% apply] theorem IsSumSq.mul [NonUnitalCommSemiring R] {s₁ s₂ : R} (h₁ : IsSumSq s₁) (h₂ : IsSumSq s₂) : IsSumSq (s₁ * s₂) := by simpa using mul_mem (by simpa : _ ∈ NonUnitalSubsemiring.sumSq R) (by simpa) private theorem Submonoid.square_subsemiringClosure {T : Type*} [CommSemiring T] : (Submonoid.square T).subsemiringClosure = .closure {x : T | IsSquare x} := by simp [Submonoid.subsemiringClosure_eq_closure] namespace Subsemiring variable {T : Type*} [CommSemiring T] variable (T) in /-- In a commutative semiring `R`, `Subsemiring.sumSq R` is the subsemiring of sums of squares in `R`. -/ def sumSq : Subsemiring T where __ := NonUnitalSubsemiring.sumSq T one_mem' := by simp @[simp] theorem sumSq_toNonUnitalSubsemiring : (sumSq T).toNonUnitalSubsemiring = .sumSq T := rfl @[simp] theorem mem_sumSq {s : T} : s ∈ sumSq T ↔ IsSumSq s := by simp [← Subsemiring.mem_toNonUnitalSubsemiring] @[simp, norm_cast] theorem coe_sumSq : sumSq T = {s : T | IsSumSq s} := by ext; simp @[simp] theorem closure_isSquare : closure {x : T | IsSquare x} = sumSq T := by apply_fun toNonUnitalSubsemiring using toNonUnitalSubsemiring_injective simp [← Submonoid.square_subsemiringClosure] end Subsemiring /-- In a commutative semiring, a finite product of sums of squares is a sum of squares. -/ @[aesop unsafe 50% apply] theorem IsSumSq.prod [CommSemiring R] {ι : Type*} {I : Finset ι} {x : ι → R} (hx : ∀ i ∈ I, IsSumSq <| x i) : IsSumSq (∏ i ∈ I, x i) := by simpa using prod_mem (S := Subsemiring.sumSq R) (by simpa) /-- In a linearly ordered semiring with the property `a ≤ b → ∃ c, a + c = b` (e.g. `ℕ`), sums of squares are non-negative. -/ theorem IsSumSq.nonneg {R : Type*} [Semiring R] [LinearOrder R] [IsStrictOrderedRing R] [ExistsAddOfLE R] {s : R} (hs : IsSumSq s) : 0 ≤ s := by induction hs using IsSumSq.rec' with | zero => simp | sq_add hx _ h => exact add_nonneg (IsSquare.nonneg hx) h
.lake/packages/mathlib/Mathlib/Algebra/Ring/Idempotent.lean
import Mathlib.Algebra.GroupWithZero.Idempotent import Mathlib.Algebra.Ring.Defs import Mathlib.Order.Notation import Mathlib.Tactic.Convert import Mathlib.Algebra.Group.Torsion /-! # Idempotent elements of a ring This file proves result about idempotent elements of a ring, like: * `IsIdempotentElem.one_sub_iff`: In a (non-associative) ring, `a` is an idempotent if and only if `1 - a` is an idempotent. -/ variable {R : Type*} namespace IsIdempotentElem section NonAssocRing variable [NonAssocRing R] {a : R} lemma one_sub (h : IsIdempotentElem a) : IsIdempotentElem (1 - a) := by rw [IsIdempotentElem, mul_sub, mul_one, sub_mul, one_mul, h.eq, sub_self, sub_zero] @[simp] lemma one_sub_iff : IsIdempotentElem (1 - a) ↔ IsIdempotentElem a := ⟨fun h => sub_sub_cancel 1 a ▸ h.one_sub, IsIdempotentElem.one_sub⟩ @[simp] lemma mul_one_sub_self (h : IsIdempotentElem a) : a * (1 - a) = 0 := by rw [mul_sub, mul_one, h.eq, sub_self] @[simp] lemma one_sub_mul_self (h : IsIdempotentElem a) : (1 - a) * a = 0 := by rw [sub_mul, one_mul, h.eq, sub_self] lemma _root_.isIdempotentElem_iff_mul_one_sub_self : IsIdempotentElem a ↔ a * (1 - a) = 0 := by rw [mul_sub, mul_one, sub_eq_zero, eq_comm, IsIdempotentElem] lemma _root_.isIdempotentElem_iff_one_sub_mul_self : IsIdempotentElem a ↔ (1 - a) * a = 0 := by rw [sub_mul, one_mul, sub_eq_zero, eq_comm, IsIdempotentElem] instance : HasCompl {a : R // IsIdempotentElem a} where compl a := ⟨1 - a, a.prop.one_sub⟩ @[simp] lemma coe_compl (a : {a : R // IsIdempotentElem a}) : ↑aᶜ = (1 : R) - ↑a := rfl @[simp] lemma compl_compl (a : {a : R // IsIdempotentElem a}) : aᶜᶜ = a := by ext; simp @[simp] lemma zero_compl : (0 : {a : R // IsIdempotentElem a})ᶜ = 1 := by ext; simp @[simp] lemma one_compl : (1 : {a : R // IsIdempotentElem a})ᶜ = 0 := by ext; simp end NonAssocRing section Semiring variable [Semiring R] {a b : R} lemma of_mul_add (mul : a * b = 0) (add : a + b = 1) : IsIdempotentElem a ∧ IsIdempotentElem b := by simp_rw [IsIdempotentElem]; constructor · conv_rhs => rw [← mul_one a, ← add, mul_add, mul, add_zero] · conv_rhs => rw [← one_mul b, ← add, add_mul, mul, zero_add] end Semiring section NonUnitalRing variable [NonUnitalRing R] {a b : R} lemma add_sub_mul_of_commute (h : Commute a b) (ha : IsIdempotentElem a) (hb : IsIdempotentElem b) : IsIdempotentElem (a + b - a * b) := by simp only [IsIdempotentElem, h.eq, mul_sub, mul_add, sub_mul, add_mul, ha.eq, mul_assoc, add_sub_cancel_right, hb.eq, hb.mul_self_mul, add_sub_cancel_left, sub_right_inj] rw [← h.eq, ha.mul_self_mul, h.eq, hb.mul_self_mul, add_sub_cancel_right] end NonUnitalRing section CommRing variable [CommRing R] {a b : R} lemma add_sub_mul (hp : IsIdempotentElem a) (hq : IsIdempotentElem b) : IsIdempotentElem (a + b - a * b) := add_sub_mul_of_commute (.all ..) hp hq end CommRing /-- `a + b` is idempotent when `a` and `b` anti-commute. -/ theorem add [NonUnitalNonAssocSemiring R] {a b : R} (ha : IsIdempotentElem a) (hb : IsIdempotentElem b) (hab : a * b + b * a = 0) : IsIdempotentElem (a + b) := by simp_rw [IsIdempotentElem, mul_add, add_mul, ha.eq, hb.eq, add_add_add_comm, ← add_assoc, add_assoc a, hab, zero_add] /-- `a + b` is idempotent if and only if `a` and `b` anti-commute. -/ theorem add_iff [NonUnitalNonAssocSemiring R] [IsCancelAdd R] {a b : R} (ha : IsIdempotentElem a) (hb : IsIdempotentElem b) : IsIdempotentElem (a + b) ↔ a * b + b * a = 0 := by refine ⟨fun h ↦ ?_, ha.add hb⟩ rw [← add_right_cancel_iff (a := b), add_assoc, ← add_left_cancel_iff (a := a), ← add_assoc, add_add_add_comm] simpa [add_mul, mul_add, ha.eq, hb.eq] using h.eq /-- `b - a` is idempotent when `a * b = a` and `b * a = a`. -/ lemma sub [NonUnitalNonAssocRing R] {a b : R} (ha : IsIdempotentElem a) (hb : IsIdempotentElem b) (hab : a * b = a) (hba : b * a = a) : IsIdempotentElem (b - a) := by simp_rw [IsIdempotentElem, sub_mul, mul_sub, hab, hba, ha.eq, hb.eq, sub_self, sub_zero] /-- If idempotent `a` and element `b` anti-commute, then their product is zero. -/ theorem mul_eq_zero_of_anticommute {a b : R} [NonUnitalSemiring R] [IsAddTorsionFree R] (ha : IsIdempotentElem a) (hab : a * b + b * a = 0) : a * b = 0 := by have h : a * b * a = 0 := by rw [← nsmul_right_inj ((Nat.zero_ne_add_one 1).symm), nsmul_zero] have : a * (a * b + b * a) * a = 0 := by rw [hab, mul_zero, zero_mul] simp_rw [mul_add, add_mul, mul_assoc, ha.eq, ← mul_assoc, ha.eq, ← two_nsmul] at this exact this suffices a * a * b + a * b * a = 0 by rwa [h, add_zero, ha.eq] at this rw [mul_assoc, mul_assoc, ← mul_add, hab, mul_zero] /-- If idempotent `a` and element `b` anti-commute, then they commute. So anti-commutativity implies commutativity when one of them is idempotent. -/ lemma commute_of_anticommute {a b : R} [NonUnitalSemiring R] [IsAddTorsionFree R] (ha : IsIdempotentElem a) (hab : a * b + b * a = 0) : Commute a b := by have := mul_eq_zero_of_anticommute ha hab rw [this, zero_add] at hab rw [Commute, SemiconjBy, hab, this] theorem sub_iff [NonUnitalRing R] [IsAddTorsionFree R] {p q : R} (hp : IsIdempotentElem p) (hq : IsIdempotentElem q) : IsIdempotentElem (q - p) ↔ p * q = p ∧ q * p = p := by refine ⟨fun hqp ↦ ?_, fun ⟨h1, h2⟩ => hp.sub hq h1 h2⟩ have h : p * (q - p) + (q - p) * p = 0 := hp.add_iff hqp |>.mp ((add_sub_cancel p q).symm ▸ hq) have hpq : Commute p q := by simp_rw [IsIdempotentElem, mul_sub, sub_mul, hp.eq, hq.eq, ← sub_add_eq_sub_sub, sub_right_inj, add_sub] at hqp have h1 := congr_arg (q * ·) hqp have h2 := congr_arg (· * q) hqp simp_rw [mul_sub, mul_add, ← mul_assoc, hq.eq, add_sub_cancel_right] at h1 simp_rw [sub_mul, add_mul, mul_assoc, hq.eq, add_sub_cancel_left, ← mul_assoc] at h2 exact h2.symm.trans h1 rw [hpq.eq, and_self, ← nsmul_right_inj (by simp : 2 ≠ 0), ← zero_add (2 • p)] convert congrArg (· + 2 • p) h using 1 simp [sub_mul, mul_sub, hp.eq, hpq.eq, two_nsmul, sub_add, sub_sub] end IsIdempotentElem
.lake/packages/mathlib/Mathlib/Algebra/Ring/Fin.lean
import Mathlib.Algebra.Ring.Equiv import Mathlib.Data.Fin.Tuple.Basic /-! # Rings and `Fin` This file collects some basic results involving rings and the `Fin` type ## Main results * `RingEquiv.piFinTwo`: The product over `Fin 2` of some rings is the Cartesian product -/ /-- The product over `Fin 2` of some rings is just the Cartesian product of these rings. -/ @[simps] def RingEquiv.piFinTwo (R : Fin 2 → Type*) [∀ i, Semiring (R i)] : (∀ i : Fin 2, R i) ≃+* R 0 × R 1 := { piFinTwoEquiv R with toFun := piFinTwoEquiv R map_add' := fun _ _ => rfl map_mul' := fun _ _ => rfl }
.lake/packages/mathlib/Mathlib/Algebra/Ring/Opposite.lean
import Mathlib.Algebra.Group.Equiv.Opposite import Mathlib.Algebra.GroupWithZero.Opposite import Mathlib.Algebra.Ring.Hom.Defs import Mathlib.Data.Int.Cast.Basic /-! # Ring structures on the multiplicative opposite -/ variable {R : Type*} namespace MulOpposite instance instDistrib [Distrib R] : Distrib Rᵐᵒᵖ where left_distrib _ _ _ := unop_injective <| add_mul _ _ _ right_distrib _ _ _ := unop_injective <| mul_add _ _ _ @[to_additive] instance instNatCast [NatCast R] : NatCast Rᵐᵒᵖ where natCast n := op n @[to_additive] instance instIntCast [IntCast R] : IntCast Rᵐᵒᵖ where intCast n := op n @[to_additive (attr := simp, norm_cast)] theorem op_natCast [NatCast R] (n : ℕ) : op (n : R) = n := rfl @[to_additive (attr := simp)] theorem op_ofNat [NatCast R] (n : ℕ) [n.AtLeastTwo] : op (ofNat(n) : R) = ofNat(n) := rfl @[to_additive (attr := simp, norm_cast)] theorem op_intCast [IntCast R] (n : ℤ) : op (n : R) = n := rfl @[to_additive (attr := simp, norm_cast)] theorem unop_natCast [NatCast R] (n : ℕ) : unop (n : Rᵐᵒᵖ) = n := rfl @[to_additive (attr := simp)] theorem unop_ofNat [NatCast R] (n : ℕ) [n.AtLeastTwo] : unop (ofNat(n) : Rᵐᵒᵖ) = ofNat(n) := rfl @[to_additive (attr := simp, norm_cast)] theorem unop_intCast [IntCast R] (n : ℤ) : unop (n : Rᵐᵒᵖ) = n := rfl instance instAddMonoidWithOne [AddMonoidWithOne R] : AddMonoidWithOne Rᵐᵒᵖ where toNatCast := instNatCast toAddMonoid := instAddMonoid toOne := instOne natCast_zero := show op ((0 : ℕ) : R) = 0 by rw [Nat.cast_zero, op_zero] natCast_succ := show ∀ n, op ((n + 1 : ℕ) : R) = op ↑(n : ℕ) + 1 by simp instance instAddCommMonoidWithOne [AddCommMonoidWithOne R] : AddCommMonoidWithOne Rᵐᵒᵖ where toAddMonoidWithOne := instAddMonoidWithOne __ := instAddCommMonoid instance instAddGroupWithOne [AddGroupWithOne R] : AddGroupWithOne Rᵐᵒᵖ where toAddMonoidWithOne := instAddMonoidWithOne toIntCast := instIntCast __ := instAddGroup intCast_ofNat n := show op ((n : ℤ) : R) = op (n : R) by rw [Int.cast_natCast] intCast_negSucc n := show op _ = op (-unop (op ((n + 1 : ℕ) : R))) by simp instance instAddCommGroupWithOne [AddCommGroupWithOne R] : AddCommGroupWithOne Rᵐᵒᵖ where toAddCommGroup := instAddCommGroup __ := instAddGroupWithOne instance instNonUnitalNonAssocSemiring [NonUnitalNonAssocSemiring R] : NonUnitalNonAssocSemiring Rᵐᵒᵖ where __ := instAddCommMonoid __ := instDistrib __ := instMulZeroClass instance instNonUnitalSemiring [NonUnitalSemiring R] : NonUnitalSemiring Rᵐᵒᵖ where __ := instNonUnitalNonAssocSemiring __ := instSemigroupWithZero instance instNonAssocSemiring [NonAssocSemiring R] : NonAssocSemiring Rᵐᵒᵖ where __ := instNonUnitalNonAssocSemiring __ := instMulZeroOneClass __ := instAddCommMonoidWithOne instance instSemiring [Semiring R] : Semiring Rᵐᵒᵖ where __ := instNonUnitalSemiring __ := instNonAssocSemiring __ := instMonoidWithZero instance instNonUnitalCommSemiring [NonUnitalCommSemiring R] : NonUnitalCommSemiring Rᵐᵒᵖ where __ := instNonUnitalSemiring __ := instCommSemigroup instance instCommSemiring [CommSemiring R] : CommSemiring Rᵐᵒᵖ where __ := instSemiring __ := instCommMonoid instance instNonUnitalNonAssocRing [NonUnitalNonAssocRing R] : NonUnitalNonAssocRing Rᵐᵒᵖ where __ := instAddCommGroup __ := instNonUnitalNonAssocSemiring instance instNonUnitalRing [NonUnitalRing R] : NonUnitalRing Rᵐᵒᵖ where __ := instNonUnitalNonAssocRing __ := instNonUnitalSemiring instance instNonAssocRing [NonAssocRing R] : NonAssocRing Rᵐᵒᵖ where __ := instNonUnitalNonAssocRing __ := instNonAssocSemiring __ := instAddCommGroupWithOne instance instRing [Ring R] : Ring Rᵐᵒᵖ where __ := instSemiring __ := instAddCommGroupWithOne instance instNonUnitalCommRing [NonUnitalCommRing R] : NonUnitalCommRing Rᵐᵒᵖ where __ := instNonUnitalRing __ := instNonUnitalCommSemiring instance instCommRing [CommRing R] : CommRing Rᵐᵒᵖ where __ := instRing __ := instCommMonoid instance instIsDomain [Ring R] [IsDomain R] : IsDomain Rᵐᵒᵖ := NoZeroDivisors.to_isDomain _ end MulOpposite namespace AddOpposite instance instDistrib [Distrib R] : Distrib Rᵃᵒᵖ where left_distrib _ _ _ := unop_injective <| mul_add _ _ _ right_distrib _ _ _ := unop_injective <| add_mul _ _ _ -- NOTE: `addMonoidWithOne R → addMonoidWithOne Rᵃᵒᵖ` does not hold instance instAddCommMonoidWithOne [AddCommMonoidWithOne R] : AddCommMonoidWithOne Rᵃᵒᵖ where toNatCast := instNatCast toOne := instOne __ := instAddCommMonoid natCast_zero := show op ((0 : ℕ) : R) = 0 by rw [Nat.cast_zero, op_zero] natCast_succ := show ∀ n, op ((n + 1 : ℕ) : R) = op ↑(n : ℕ) + 1 by simp [add_comm] instance instAddCommGroupWithOne [AddCommGroupWithOne R] : AddCommGroupWithOne Rᵃᵒᵖ where toIntCast := instIntCast toAddCommGroup := instAddCommGroup __ := instAddCommMonoidWithOne intCast_ofNat _ := congr_arg op <| Int.cast_natCast _ intCast_negSucc _ := congr_arg op <| Int.cast_negSucc _ instance instNonUnitalNonAssocSemiring [NonUnitalNonAssocSemiring R] : NonUnitalNonAssocSemiring Rᵃᵒᵖ where __ := instAddCommMonoid __ := instDistrib __ := instMulZeroClass instance instNonUnitalSemiring [NonUnitalSemiring R] : NonUnitalSemiring Rᵃᵒᵖ where __ := instNonUnitalNonAssocSemiring __ := instSemigroupWithZero instance instNonAssocSemiring [NonAssocSemiring R] : NonAssocSemiring Rᵃᵒᵖ where __ := instNonUnitalNonAssocSemiring __ := instMulZeroOneClass __ := instAddCommMonoidWithOne instance instSemiring [Semiring R] : Semiring Rᵃᵒᵖ where __ := instNonUnitalSemiring __ := instNonAssocSemiring __ := instMonoidWithZero instance instNonUnitalCommSemiring [NonUnitalCommSemiring R] : NonUnitalCommSemiring Rᵃᵒᵖ where __ := instNonUnitalSemiring __ := instCommSemigroup instance instCommSemiring [CommSemiring R] : CommSemiring Rᵃᵒᵖ where __ := instSemiring __ := instCommMonoid instance instNonUnitalNonAssocRing [NonUnitalNonAssocRing R] : NonUnitalNonAssocRing Rᵃᵒᵖ where __ := instAddCommGroup __ := instNonUnitalNonAssocSemiring instance instNonUnitalRing [NonUnitalRing R] : NonUnitalRing Rᵃᵒᵖ where __ := instNonUnitalNonAssocRing __ := instNonUnitalSemiring instance instNonAssocRing [NonAssocRing R] : NonAssocRing Rᵃᵒᵖ where __ := instNonUnitalNonAssocRing __ := instNonAssocSemiring __ := instAddCommGroupWithOne instance instRing [Ring R] : Ring Rᵃᵒᵖ where __ := instSemiring __ := instAddCommGroupWithOne instance instNonUnitalCommRing [NonUnitalCommRing R] : NonUnitalCommRing Rᵃᵒᵖ where __ := instNonUnitalRing __ := instNonUnitalCommSemiring instance instCommRing [CommRing R] : CommRing Rᵃᵒᵖ where __ := instRing __ := instCommMonoid instance instIsDomain [Ring R] [IsDomain R] : IsDomain Rᵃᵒᵖ := NoZeroDivisors.to_isDomain _ end AddOpposite open MulOpposite /-- A non-unital ring homomorphism `f : R →ₙ+* S` such that `f x` commutes with `f y` for all `x, y` defines a non-unital ring homomorphism to `Sᵐᵒᵖ`. -/ @[simps -fullyApplied] def NonUnitalRingHom.toOpposite {R S : Type*} [NonUnitalNonAssocSemiring R] [NonUnitalNonAssocSemiring S] (f : R →ₙ+* S) (hf : ∀ x y, Commute (f x) (f y)) : R →ₙ+* Sᵐᵒᵖ := { ((opAddEquiv : S ≃+ Sᵐᵒᵖ).toAddMonoidHom.comp ↑f : R →+ Sᵐᵒᵖ), f.toMulHom.toOpposite hf with toFun := MulOpposite.op ∘ f } /-- A non-unital ring homomorphism `f : R →ₙ* S` such that `f x` commutes with `f y` for all `x, y` defines a non-unital ring homomorphism from `Rᵐᵒᵖ`. -/ @[simps -fullyApplied] def NonUnitalRingHom.fromOpposite {R S : Type*} [NonUnitalNonAssocSemiring R] [NonUnitalNonAssocSemiring S] (f : R →ₙ+* S) (hf : ∀ x y, Commute (f x) (f y)) : Rᵐᵒᵖ →ₙ+* S := { (f.toAddMonoidHom.comp (opAddEquiv : R ≃+ Rᵐᵒᵖ).symm.toAddMonoidHom : Rᵐᵒᵖ →+ S), f.toMulHom.fromOpposite hf with toFun := f ∘ MulOpposite.unop } /-- A non-unital ring hom `R →ₙ+* S` can equivalently be viewed as a non-unital ring hom `Rᵐᵒᵖ →+* Sᵐᵒᵖ`. This is the action of the (fully faithful) `ᵐᵒᵖ`-functor on morphisms. -/ @[simps] def NonUnitalRingHom.op {R S} [NonUnitalNonAssocSemiring R] [NonUnitalNonAssocSemiring S] : (R →ₙ+* S) ≃ (Rᵐᵒᵖ →ₙ+* Sᵐᵒᵖ) where toFun f := { AddMonoidHom.mulOp f.toAddMonoidHom, MulHom.op f.toMulHom with } invFun f := { AddMonoidHom.mulUnop f.toAddMonoidHom, MulHom.unop f.toMulHom with } /-- The 'unopposite' of a non-unital ring hom `Rᵐᵒᵖ →ₙ+* Sᵐᵒᵖ`. Inverse to `NonUnitalRingHom.op`. -/ @[simp] def NonUnitalRingHom.unop {R S} [NonUnitalNonAssocSemiring R] [NonUnitalNonAssocSemiring S] : (Rᵐᵒᵖ →ₙ+* Sᵐᵒᵖ) ≃ (R →ₙ+* S) := NonUnitalRingHom.op.symm /-- A ring homomorphism `f : R →+* S` such that `f x` commutes with `f y` for all `x, y` defines a ring homomorphism to `Sᵐᵒᵖ`. -/ @[simps -fullyApplied] def RingHom.toOpposite {R S : Type*} [Semiring R] [Semiring S] (f : R →+* S) (hf : ∀ x y, Commute (f x) (f y)) : R →+* Sᵐᵒᵖ := { ((opAddEquiv : S ≃+ Sᵐᵒᵖ).toAddMonoidHom.comp ↑f : R →+ Sᵐᵒᵖ), f.toMonoidHom.toOpposite hf with toFun := MulOpposite.op ∘ f } /-- A ring homomorphism `f : R →+* S` such that `f x` commutes with `f y` for all `x, y` defines a ring homomorphism from `Rᵐᵒᵖ`. -/ @[simps -fullyApplied] def RingHom.fromOpposite {R S : Type*} [Semiring R] [Semiring S] (f : R →+* S) (hf : ∀ x y, Commute (f x) (f y)) : Rᵐᵒᵖ →+* S := { (f.toAddMonoidHom.comp (opAddEquiv : R ≃+ Rᵐᵒᵖ).symm.toAddMonoidHom : Rᵐᵒᵖ →+ S), f.toMonoidHom.fromOpposite hf with toFun := f ∘ MulOpposite.unop } /-- A ring hom `R →+* S` can equivalently be viewed as a ring hom `Rᵐᵒᵖ →+* Sᵐᵒᵖ`. This is the action of the (fully faithful) `ᵐᵒᵖ`-functor on morphisms. -/ @[simps!] def RingHom.op {R S} [NonAssocSemiring R] [NonAssocSemiring S] : (R →+* S) ≃ (Rᵐᵒᵖ →+* Sᵐᵒᵖ) where toFun f := { AddMonoidHom.mulOp f.toAddMonoidHom, MonoidHom.op f.toMonoidHom with } invFun f := { AddMonoidHom.mulUnop f.toAddMonoidHom, MonoidHom.unop f.toMonoidHom with } /-- The 'unopposite' of a ring hom `Rᵐᵒᵖ →+* Sᵐᵒᵖ`. Inverse to `RingHom.op`. -/ @[simp] def RingHom.unop {R S} [NonAssocSemiring R] [NonAssocSemiring S] : (Rᵐᵒᵖ →+* Sᵐᵒᵖ) ≃ (R →+* S) := RingHom.op.symm
.lake/packages/mathlib/Mathlib/Algebra/Ring/GrindInstances.lean
import Mathlib.Algebra.Ring.Defs import Mathlib.Data.Int.Cast.Basic /-! # Instances for `grind`. -/ open Lean variable (α : Type*) -- This is a low priority instance so that the built-in `Lean.Grind.Semiring Nat` instance -- (which has a non-defeq `ofNat` instance) is used preferentially. instance (priority := 100) Semiring.toGrindSemiring [s : Semiring α] : Grind.Semiring α := { s with nsmul := ⟨s.nsmul⟩ npow := ⟨fun a n => a^n⟩ ofNat | 0 | 1 | n + 2 => inferInstance natCast := inferInstance add_zero := by simp [add_zero] mul_one := by simp [mul_one] zero_mul := by simp [zero_mul] pow_zero a := by simp pow_succ a n := by simp [pow_succ] ofNat_eq_natCast | 0 => Nat.cast_zero.symm | 1 => Nat.cast_one.symm | n + 2 => rfl ofNat_succ | 0 => by simp [zero_add] | 1 => by change Nat.cast 2 = 1 + 1 rw [one_add_one_eq_two] rfl | n + 2 => by change Nat.cast (n + 2 + 1) = Nat.cast (n + 2) + 1 rw [← AddMonoidWithOne.natCast_succ] nsmul_eq_natCast_mul n a := nsmul_eq_mul n a } instance (priority := 100) CommSemiring.toGrindCommSemiring [s : CommSemiring α] : Grind.CommSemiring α := { Semiring.toGrindSemiring α with mul_comm := s.mul_comm } instance (priority := 100) Ring.toGrindRing [s : Ring α] : Grind.Ring α := { s, Semiring.toGrindSemiring α with nsmul := ⟨s.nsmul⟩ npow := ⟨fun a n => a^n⟩ zsmul := ⟨s.zsmul⟩ natCast := inferInstance intCast := inferInstance neg_zsmul i a := neg_zsmul a i neg_add_cancel := by simp [neg_add_cancel] intCast_ofNat | 0 => Int.cast_zero | 1 => Int.cast_one | _ + 2 => Int.cast_ofNat _ intCast_neg := Int.cast_neg zsmul_natCast_eq_nsmul n a := natCast_zsmul a n } instance (priority := 100) CommRing.toGrindCommRing [s : CommRing α] : Grind.CommRing α := { Ring.toGrindRing α with mul_comm := s.mul_comm } theorem Semiring.toGrindSemiring_ofNat [Semiring α] (n : ℕ) : @OfNat.ofNat α n (Lean.Grind.Semiring.ofNat n) = n.cast := by match n with | 0 => simp | 1 => simp | n + 2 => rfl attribute [local instance] Grind.Semiring.natCast Grind.Ring.intCast in -- Verify that we can construct a `CommRing` from a `Lean.Grind.CommRing`. -- This is not an instance (or even a `def`) because this direction should never be used. -- There is no reason to expect that using `CommRing.toGrindCommRing` and then this construction -- will give a result defeq to the original `CommRing α`. example (s : Grind.CommRing α) : CommRing α := { s with zero_add := Grind.AddCommMonoid.zero_add right_distrib := Grind.Semiring.right_distrib mul_zero := Grind.Semiring.mul_zero one_mul := Grind.Semiring.one_mul nsmul := nsmulRec zsmul := zsmulRec npow := npowRec natCast := Nat.cast natCast_zero := Grind.Semiring.natCast_zero natCast_succ n := Grind.Semiring.natCast_succ n intCast := Int.cast intCast_ofNat := Grind.Ring.intCast_natCast intCast_negSucc n := by rw [Int.negSucc_eq, Grind.Ring.intCast_neg, Grind.Ring.intCast_natCast_add_one, Grind.Semiring.natCast_succ] } -- Verify that we do not have a defeq problems in `Lean.Grind.Semiring` instances. example : (inferInstance : Lean.Grind.Semiring Nat) = (Lean.Grind.CommSemiring.toSemiring : Lean.Grind.Semiring Nat) := rfl example : (inferInstance : Lean.Grind.Semiring UInt8) = (Lean.Grind.CommSemiring.toSemiring : Lean.Grind.Semiring UInt8) := rfl
.lake/packages/mathlib/Mathlib/Algebra/Ring/Semiconj.lean
import Mathlib.Algebra.Group.Semiconj.Defs import Mathlib.Algebra.Ring.Defs /-! # Semirings and rings This file gives lemmas about semirings, rings and domains. This is analogous to `Mathlib/Algebra/Group/Basic.lean`, the difference being that the former is about `+` and `*` separately, while the present file is about their interaction. For the definitions of semirings and rings see `Mathlib/Algebra/Ring/Defs.lean`. -/ universe u variable {R : Type u} open Function namespace SemiconjBy @[simp] theorem add_right [Distrib R] {a x y x' y' : R} (h : SemiconjBy a x y) (h' : SemiconjBy a x' y') : SemiconjBy a (x + x') (y + y') := by simp only [SemiconjBy, left_distrib, right_distrib, h.eq, h'.eq] @[simp] theorem add_left [Distrib R] {a b x y : R} (ha : SemiconjBy a x y) (hb : SemiconjBy b x y) : SemiconjBy (a + b) x y := by simp only [SemiconjBy, left_distrib, right_distrib, ha.eq, hb.eq] section variable [Mul R] [HasDistribNeg R] {a x y : R} theorem neg_right (h : SemiconjBy a x y) : SemiconjBy a (-x) (-y) := by simp only [SemiconjBy, h.eq, neg_mul, mul_neg] @[simp] theorem neg_right_iff : SemiconjBy a (-x) (-y) ↔ SemiconjBy a x y := ⟨fun h => neg_neg x ▸ neg_neg y ▸ h.neg_right, SemiconjBy.neg_right⟩ theorem neg_left (h : SemiconjBy a x y) : SemiconjBy (-a) x y := by simp only [SemiconjBy, h.eq, neg_mul, mul_neg] @[simp] theorem neg_left_iff : SemiconjBy (-a) x y ↔ SemiconjBy a x y := ⟨fun h => neg_neg a ▸ h.neg_left, SemiconjBy.neg_left⟩ end section variable [MulOneClass R] [HasDistribNeg R] theorem neg_one_right (a : R) : SemiconjBy a (-1) (-1) := by simp theorem neg_one_left (x : R) : SemiconjBy (-1) x x := by simp end section variable [NonUnitalNonAssocRing R] {a b x y x' y' : R} @[simp] theorem sub_right (h : SemiconjBy a x y) (h' : SemiconjBy a x' y') : SemiconjBy a (x - x') (y - y') := by simpa only [sub_eq_add_neg] using h.add_right h'.neg_right @[simp] theorem sub_left (ha : SemiconjBy a x y) (hb : SemiconjBy b x y) : SemiconjBy (a - b) x y := by simpa only [sub_eq_add_neg] using ha.add_left hb.neg_left end end SemiconjBy
.lake/packages/mathlib/Mathlib/Algebra/Ring/WithZero.lean
import Mathlib.Algebra.GroupWithZero.WithZero import Mathlib.Algebra.Ring.Defs /-! # Adjoining a zero to a semiring -/ namespace WithZero variable {α : Type*} instance instLeftDistribClass [Mul α] [Add α] [LeftDistribClass α] : LeftDistribClass (WithZero α) where left_distrib a b c := by cases a; · rfl cases b <;> cases c <;> try rfl exact congr_arg some (left_distrib _ _ _) instance instRightDistribClass [Mul α] [Add α] [RightDistribClass α] : RightDistribClass (WithZero α) where right_distrib a b c := by cases c; · simp cases a <;> cases b <;> try rfl exact congr_arg some (right_distrib _ _ _) instance instDistrib [Distrib α] : Distrib (WithZero α) where left_distrib := left_distrib right_distrib := right_distrib instance instSemiring [Semiring α] : Semiring (WithZero α) where end WithZero
.lake/packages/mathlib/Mathlib/Algebra/Ring/Regular.lean
import Mathlib.Algebra.Group.Basic import Mathlib.Algebra.GroupWithZero.Regular import Mathlib.Algebra.Ring.Defs /-! # Lemmas about regular elements in rings. -/ variable {α : Type*} /-- Left `Mul` by a `k : α` over `[Ring α]` is injective, if `k` is not a zero divisor. The typeclass that restricts all terms of `α` to have this property is `NoZeroDivisors`. -/ theorem isLeftRegular_of_non_zero_divisor [NonUnitalNonAssocRing α] (k : α) (h : ∀ x : α, k * x = 0 → x = 0) : IsLeftRegular k := by refine fun x y (h' : k * x = k * y) => sub_eq_zero.mp (h _ ?_) rw [mul_sub, sub_eq_zero, h'] /-- Right `Mul` by a `k : α` over `[Ring α]` is injective, if `k` is not a zero divisor. The typeclass that restricts all terms of `α` to have this property is `NoZeroDivisors`. -/ theorem isRightRegular_of_non_zero_divisor [NonUnitalNonAssocRing α] (k : α) (h : ∀ x : α, x * k = 0 → x = 0) : IsRightRegular k := by refine fun x y (h' : x * k = y * k) => sub_eq_zero.mp (h _ ?_) rw [sub_mul, sub_eq_zero, h'] theorem isRegular_of_ne_zero' [NonUnitalNonAssocRing α] [NoZeroDivisors α] {k : α} (hk : k ≠ 0) : IsRegular k := ⟨isLeftRegular_of_non_zero_divisor k fun _ h => (NoZeroDivisors.eq_zero_or_eq_zero_of_mul_eq_zero h).resolve_left hk, isRightRegular_of_non_zero_divisor k fun _ h => (NoZeroDivisors.eq_zero_or_eq_zero_of_mul_eq_zero h).resolve_right hk⟩ theorem isRegular_iff_ne_zero' [Nontrivial α] [NonUnitalNonAssocRing α] [NoZeroDivisors α] {k : α} : IsRegular k ↔ k ≠ 0 := ⟨fun h => by rintro rfl exact not_not.mpr h.left not_isLeftRegular_zero, isRegular_of_ne_zero'⟩ /-- A ring with no zero divisors is a `CancelMonoidWithZero`. Note this is not an instance as it forms a typeclass loop. -/ abbrev NoZeroDivisors.toCancelMonoidWithZero [Ring α] [NoZeroDivisors α] : CancelMonoidWithZero α where mul_left_cancel_of_ne_zero ha := (isRegular_of_ne_zero' ha).1 mul_right_cancel_of_ne_zero hb := (isRegular_of_ne_zero' hb).2 /-- A commutative ring with no zero divisors is a `CancelCommMonoidWithZero`. Note this is not an instance as it forms a typeclass loop. -/ abbrev NoZeroDivisors.toCancelCommMonoidWithZero [CommRing α] [NoZeroDivisors α] : CancelCommMonoidWithZero α := { NoZeroDivisors.toCancelMonoidWithZero, ‹CommRing α› with } section IsDomain -- see Note [lower instance priority] instance (priority := 100) IsDomain.toCancelMonoidWithZero [Semiring α] [IsDomain α] : CancelMonoidWithZero α where variable [CommSemiring α] [IsDomain α] -- see Note [lower instance priority] instance (priority := 100) IsDomain.toCancelCommMonoidWithZero : CancelCommMonoidWithZero α := { mul_left_cancel_of_ne_zero := IsLeftCancelMulZero.mul_left_cancel_of_ne_zero } end IsDomain
.lake/packages/mathlib/Mathlib/Algebra/Ring/Rat.lean
import Mathlib.Algebra.GroupWithZero.Units.Basic import Mathlib.Algebra.Ring.Basic import Mathlib.Algebra.Ring.Int.Defs import Mathlib.Data.Rat.Defs import Mathlib.Algebra.Group.Nat.Defs /-! # The rational numbers are a commutative ring This file contains the commutative ring instance on the rational numbers. See note [foundational algebra order theory]. -/ assert_not_exists IsOrderedMonoid Field PNat Nat.gcd_greatest IsDomain.toCancelMonoidWithZero namespace Rat /-! ### Instances -/ instance commRing : CommRing ℚ where __ := addCommGroup __ := commMonoid zero_mul := Rat.zero_mul mul_zero := Rat.mul_zero left_distrib := Rat.mul_add right_distrib := Rat.add_mul intCast := fun n => n natCast n := Int.cast n natCast_zero := rfl natCast_succ n := by simp only [intCast_eq_divInt, divInt_add_divInt _ _ Int.one_ne_zero Int.one_ne_zero, ← divInt_one_one, Int.natCast_add, Int.natCast_one, mul_one] instance commGroupWithZero : CommGroupWithZero ℚ := { exists_pair_ne := ⟨0, 1, Rat.zero_ne_one⟩ inv_zero := Rat.inv_zero mul_inv_cancel := Rat.mul_inv_cancel mul_zero := mul_zero zero_mul := zero_mul zpow z q := q ^ z zpow_zero' := Rat.zpow_zero zpow_succ' _ _ := by rw [Rat.zpow_natCast, Rat.zpow_natCast, Rat.pow_succ] } instance isDomain : IsDomain ℚ := NoZeroDivisors.to_isDomain _ /-- The characteristic of `ℚ` is 0. -/ @[stacks 09FS "Second part."] instance instCharZero : CharZero ℚ where cast_injective a b hab := by simpa using congr_arg num hab /-! ### Extra instances to short-circuit type class resolution These also prevent non-computable instances being used to construct these instances non-computably. -/ instance commSemiring : CommSemiring ℚ := by infer_instance instance semiring : Semiring ℚ := by infer_instance /-! ### Miscellaneous lemmas -/ lemma divInt_div_divInt_cancel_left {x : ℤ} (hx : x ≠ 0) (n d : ℤ) : n /. x / (d /. x) = n /. d := by rw [div_eq_mul_inv, inv_divInt, divInt_mul_divInt_cancel hx] lemma divInt_div_divInt_cancel_right {x : ℤ} (hx : x ≠ 0) (n d : ℤ) : x /. n / (x /. d) = d /. n := by rw [div_eq_mul_inv, inv_divInt, mul_comm, divInt_mul_divInt_cancel hx] lemma num_div_den (r : ℚ) : (r.num : ℚ) / (r.den : ℚ) = r := by rw [← Int.cast_natCast, ← divInt_eq_div, num_divInt_den] @[simp] lemma divInt_pow (num : ℕ) (den : ℤ) (n : ℕ) : (num /. den) ^ n = num ^ n /. den ^ n := by simp [divInt_eq_div, div_pow] @[simp] lemma mkRat_pow (num den : ℕ) (n : ℕ) : mkRat num den ^ n = mkRat (num ^ n) (den ^ n) := by rw [mkRat_eq_divInt, mkRat_eq_divInt, divInt_pow, Int.natCast_pow] lemma natCast_eq_divInt (n : ℕ) : ↑n = n /. 1 := by rw [← Int.cast_natCast, intCast_eq_divInt] @[simp] lemma mul_den_eq_num (q : ℚ) : q * q.den = q.num := by suffices (q.num /. ↑q.den) * (↑q.den /. 1) = q.num /. 1 by simp_all have : (q.den : ℤ) ≠ 0 := mod_cast q.den_ne_zero rw [divInt_mul_divInt, mul_comm (q.den : ℤ) 1, divInt_mul_right this] @[simp] lemma den_mul_eq_num (q : ℚ) : q.den * q = q.num := by rw [mul_comm, mul_den_eq_num] end Rat
.lake/packages/mathlib/Mathlib/Algebra/Ring/TransferInstance.lean
import Mathlib.Algebra.Group.TransferInstance import Mathlib.Algebra.Ring.Equiv import Mathlib.Algebra.Ring.Hom.InjSurj import Mathlib.Algebra.Ring.InjSurj /-! # Transfer algebraic structures across `Equiv`s This continues the pattern set in `Mathlib/Algebra/Group/TransferInstance.lean`. -/ assert_not_exists Field Module namespace Equiv variable {α β : Type*} (e : α ≃ β) /-- An equivalence `e : α ≃ β` gives a ring equivalence `α ≃+* β` where the ring structure on `α` is the one obtained by transporting a ring structure on `β` back along `e`. -/ def ringEquiv (e : α ≃ β) [Add β] [Mul β] : by let add := Equiv.add e let mul := Equiv.mul e exact α ≃+* β := by intros exact { e with map_add' := fun x y => by simp [add_def] map_mul' := fun x y => by simp [mul_def] } @[simp] lemma ringEquiv_apply (e : α ≃ β) [Add β] [Mul β] (a : α) : ringEquiv e a = e a := rfl lemma ringEquiv_symm_apply (e : α ≃ β) [Add β] [Mul β] (b : β) : by letI := Equiv.add e letI := Equiv.mul e exact (ringEquiv e).symm b = e.symm b := rfl /-- Transfer `NonUnitalNonAssocSemiring` across an `Equiv` -/ protected abbrev nonUnitalNonAssocSemiring [NonUnitalNonAssocSemiring β] : NonUnitalNonAssocSemiring α := by let zero := e.zero let add := e.add let mul := e.mul let nsmul := e.smul ℕ apply e.injective.nonUnitalNonAssocSemiring _ <;> intros <;> exact e.apply_symm_apply _ /-- Transfer `NonUnitalSemiring` across an `Equiv` -/ protected abbrev nonUnitalSemiring [NonUnitalSemiring β] : NonUnitalSemiring α := by let zero := e.zero let add := e.add let mul := e.mul let nsmul := e.smul ℕ apply e.injective.nonUnitalSemiring _ <;> intros <;> exact e.apply_symm_apply _ /-- Transfer `AddMonoidWithOne` across an `Equiv` -/ protected abbrev addMonoidWithOne [AddMonoidWithOne β] : AddMonoidWithOne α := { e.addMonoid, e.one with natCast := fun n => e.symm n natCast_zero := e.injective (by simp [zero_def]) natCast_succ := fun n => e.injective (by simp [add_def, one_def]) } /-- Transfer `AddGroupWithOne` across an `Equiv` -/ protected abbrev addGroupWithOne [AddGroupWithOne β] : AddGroupWithOne α := { e.addMonoidWithOne, e.addGroup with intCast := fun n => e.symm n intCast_ofNat := fun n => by simp only [Int.cast_natCast]; rfl intCast_negSucc := fun _ => congr_arg e.symm <| (Int.cast_negSucc _).trans <| congr_arg _ (e.apply_symm_apply _).symm } /-- Transfer `NonAssocSemiring` across an `Equiv` -/ protected abbrev nonAssocSemiring [NonAssocSemiring β] : NonAssocSemiring α := by let mul := e.mul let add_monoid_with_one := e.addMonoidWithOne apply e.injective.nonAssocSemiring _ <;> intros <;> exact e.apply_symm_apply _ /-- Transfer `Semiring` across an `Equiv` -/ protected abbrev semiring [Semiring β] : Semiring α := by let mul := e.mul let add_monoid_with_one := e.addMonoidWithOne let npow := e.pow ℕ apply e.injective.semiring _ <;> intros <;> exact e.apply_symm_apply _ /-- Transfer `NonUnitalCommSemiring` across an `Equiv` -/ protected abbrev nonUnitalCommSemiring [NonUnitalCommSemiring β] : NonUnitalCommSemiring α := by let zero := e.zero let add := e.add let mul := e.mul let nsmul := e.smul ℕ apply e.injective.nonUnitalCommSemiring _ <;> intros <;> exact e.apply_symm_apply _ /-- Transfer `CommSemiring` across an `Equiv` -/ protected abbrev commSemiring [CommSemiring β] : CommSemiring α := by let mul := e.mul let add_monoid_with_one := e.addMonoidWithOne let npow := e.pow ℕ apply e.injective.commSemiring _ <;> intros <;> exact e.apply_symm_apply _ /-- Transfer `NonUnitalNonAssocRing` across an `Equiv` -/ protected abbrev nonUnitalNonAssocRing [NonUnitalNonAssocRing β] : NonUnitalNonAssocRing α := by let zero := e.zero let add := e.add let mul := e.mul let neg := e.Neg let sub := e.sub let nsmul := e.smul ℕ let zsmul := e.smul ℤ apply e.injective.nonUnitalNonAssocRing _ <;> intros <;> exact e.apply_symm_apply _ /-- Transfer `NonUnitalRing` across an `Equiv` -/ protected abbrev nonUnitalRing [NonUnitalRing β] : NonUnitalRing α := by let zero := e.zero let add := e.add let mul := e.mul let neg := e.Neg let sub := e.sub let nsmul := e.smul ℕ let zsmul := e.smul ℤ apply e.injective.nonUnitalRing _ <;> intros <;> exact e.apply_symm_apply _ /-- Transfer `NonAssocRing` across an `Equiv` -/ protected abbrev nonAssocRing [NonAssocRing β] : NonAssocRing α := by let add_group_with_one := e.addGroupWithOne let mul := e.mul apply e.injective.nonAssocRing _ <;> intros <;> exact e.apply_symm_apply _ /-- Transfer `Ring` across an `Equiv` -/ protected abbrev ring [Ring β] : Ring α := by let mul := e.mul let add_group_with_one := e.addGroupWithOne let npow := e.pow ℕ apply e.injective.ring _ <;> intros <;> exact e.apply_symm_apply _ /-- Transfer `NonUnitalCommRing` across an `Equiv` -/ protected abbrev nonUnitalCommRing [NonUnitalCommRing β] : NonUnitalCommRing α := by let zero := e.zero let add := e.add let mul := e.mul let neg := e.Neg let sub := e.sub let nsmul := e.smul ℕ let zsmul := e.smul ℤ apply e.injective.nonUnitalCommRing _ <;> intros <;> exact e.apply_symm_apply _ /-- Transfer `CommRing` across an `Equiv` -/ protected abbrev commRing [CommRing β] : CommRing α := by let mul := e.mul let add_group_with_one := e.addGroupWithOne let npow := e.pow ℕ apply e.injective.commRing _ <;> intros <;> exact e.apply_symm_apply _ /-- Transfer `IsDomain` across an `Equiv` -/ protected lemma isDomain [Semiring β] [IsDomain β] (e : α ≃ β) : letI := e.semiring IsDomain α := letI := e.semiring; e.injective.isDomain e.ringEquiv end Equiv
.lake/packages/mathlib/Mathlib/Algebra/Ring/PUnit.lean
import Mathlib.Algebra.Group.PUnit import Mathlib.Algebra.Ring.Defs /-! # `PUnit` is a commutative ring This file collects facts about algebraic structures on the one-element type, e.g. that it is a commutative ring. -/ assert_not_exists Field namespace PUnit instance commRing : CommRing PUnit where __ := PUnit.commGroup __ := PUnit.addCommGroup left_distrib := by intros; rfl right_distrib := by intros; rfl zero_mul := by intros; rfl mul_zero := by intros; rfl natCast _ := unit instance cancelCommMonoidWithZero : CancelCommMonoidWithZero PUnit where mul_left_cancel_of_ne_zero := by simp end PUnit
.lake/packages/mathlib/Mathlib/Algebra/Ring/Aut.lean
import Mathlib.Algebra.Group.End import Mathlib.Algebra.Ring.Equiv /-! # Ring automorphisms This file defines the automorphism group structure on `RingAut R := RingEquiv R R`. ## Implementation notes The definition of multiplication in the automorphism group agrees with function composition, multiplication in `Equiv.Perm`, and multiplication in `CategoryTheory.End`, but not with `CategoryTheory.comp`. ## Tags ring aut -/ variable (R : Type*) [Mul R] [Add R] /-- The group of ring automorphisms. -/ abbrev RingAut := RingEquiv R R namespace RingAut /-- The group operation on automorphisms of a ring is defined by `fun g h => RingEquiv.trans h g`. This means that multiplication agrees with composition, `(g*h)(x) = g (h x)`. -/ instance : Group (RingAut R) where mul g h := RingEquiv.trans h g one := RingEquiv.refl R inv := RingEquiv.symm mul_assoc _ _ _ := rfl one_mul _ := rfl mul_one _ := rfl inv_mul_cancel := RingEquiv.self_trans_symm instance : Inhabited (RingAut R) := ⟨1⟩ /-- Monoid homomorphism from ring automorphisms to additive automorphisms. -/ def toAddAut : RingAut R →* AddAut R where toFun := RingEquiv.toAddEquiv map_one' := rfl map_mul' _ _ := rfl /-- Monoid homomorphism from ring automorphisms to multiplicative automorphisms. -/ def toMulAut : RingAut R →* MulAut R where toFun := RingEquiv.toMulEquiv map_one' := rfl map_mul' _ _ := rfl /-- Monoid homomorphism from ring automorphisms to permutations. -/ def toPerm : RingAut R →* Equiv.Perm R where toFun := RingEquiv.toEquiv map_one' := rfl map_mul' _ _ := rfl variable {R} theorem one_eq_refl : (1 : R ≃+* R) = RingEquiv.refl R := rfl @[simp] theorem one_apply (x : R) : (1 : R ≃+* R) x = x := rfl @[simp] theorem coe_one : ⇑(1 : R ≃+* R) = id := rfl @[simp] theorem mul_apply (f g : R ≃+* R) (x : R) : (f * g) x = f (g x) := rfl @[simp] theorem inv_apply (f : R ≃+* R) (x : R) : f⁻¹ x = f.symm x := rfl @[simp] theorem coe_pow (f : R ≃+* R) (n : ℕ) : ⇑(f ^ n) = f^[n] := by induction n with | zero => simp | succ n ih => ext simp [pow_succ, ih] end RingAut
.lake/packages/mathlib/Mathlib/Algebra/Ring/NegOnePow.lean
import Mathlib.Algebra.Ring.Int.Parity import Mathlib.Algebra.Ring.Int.Units import Mathlib.Data.ZMod.IntUnitsPower /-! # Integer powers of (-1) This file defines the map `negOnePow : ℤ → ℤˣ` which sends `n` to `(-1 : ℤˣ) ^ n`. The definition of `negOnePow` and some lemmas first appeared in contributions by Johan Commelin to the Liquid Tensor Experiment. -/ assert_not_exists Field assert_not_exists TwoSidedIdeal namespace Int /-- The map `ℤ → ℤˣ` which sends `n` to `(-1 : ℤˣ) ^ n`. -/ def negOnePow (n : ℤ) : ℤˣ := (-1 : ℤˣ) ^ n lemma negOnePow_def (n : ℤ) : n.negOnePow = (-1 : ℤˣ) ^ n := rfl lemma negOnePow_add (n₁ n₂ : ℤ) : (n₁ + n₂).negOnePow = n₁.negOnePow * n₂.negOnePow := zpow_add _ _ _ @[simp] lemma negOnePow_zero : negOnePow 0 = 1 := rfl @[simp] lemma negOnePow_one : negOnePow 1 = -1 := rfl lemma negOnePow_succ (n : ℤ) : (n + 1).negOnePow = - n.negOnePow := by rw [negOnePow_add, negOnePow_one, mul_neg, mul_one] lemma negOnePow_even (n : ℤ) (hn : Even n) : n.negOnePow = 1 := by obtain ⟨k, rfl⟩ := hn rw [negOnePow_add, units_mul_self] @[simp] lemma negOnePow_two_mul (n : ℤ) : (2 * n).negOnePow = 1 := negOnePow_even _ ⟨n, two_mul n⟩ lemma negOnePow_odd (n : ℤ) (hn : Odd n) : n.negOnePow = -1 := by obtain ⟨k, rfl⟩ := hn simp only [negOnePow_add, negOnePow_two_mul, negOnePow_one, mul_neg, mul_one] @[simp] lemma negOnePow_two_mul_add_one (n : ℤ) : (2 * n + 1).negOnePow = -1 := negOnePow_odd _ ⟨n, rfl⟩ lemma negOnePow_eq_one_iff (n : ℤ) : n.negOnePow = 1 ↔ Even n := by constructor · intro h rw [← Int.not_odd_iff_even] intro h' simp only [negOnePow_odd _ h'] at h contradiction · exact negOnePow_even n lemma negOnePow_eq_neg_one_iff (n : ℤ) : n.negOnePow = -1 ↔ Odd n := by constructor · intro h rw [← Int.not_even_iff_odd] intro h' rw [negOnePow_even _ h'] at h contradiction · exact negOnePow_odd n @[simp] theorem abs_negOnePow (n : ℤ) : |(n.negOnePow : ℤ)| = 1 := by rw [abs_eq_natAbs, Int.units_natAbs, Nat.cast_one] @[simp] lemma negOnePow_neg (n : ℤ) : (-n).negOnePow = n.negOnePow := by dsimp [negOnePow] simp only [zpow_neg, ← inv_zpow, inv_neg, inv_one] @[simp] lemma negOnePow_abs (n : ℤ) : |n|.negOnePow = n.negOnePow := by obtain h|h := abs_choice n <;> simp only [h, negOnePow_neg] lemma negOnePow_sub (n₁ n₂ : ℤ) : (n₁ - n₂).negOnePow = n₁.negOnePow * n₂.negOnePow := by simp only [sub_eq_add_neg, negOnePow_add, negOnePow_neg] lemma negOnePow_eq_iff (n₁ n₂ : ℤ) : n₁.negOnePow = n₂.negOnePow ↔ Even (n₁ - n₂) := by by_cases h₂ : Even n₂ · rw [negOnePow_even _ h₂, Int.even_sub, negOnePow_eq_one_iff] tauto · rw [Int.not_even_iff_odd] at h₂ rw [negOnePow_odd _ h₂, Int.even_sub, negOnePow_eq_neg_one_iff, ← Int.not_odd_iff_even, ← Int.not_odd_iff_even] tauto @[simp] lemma negOnePow_mul_self (n : ℤ) : (n * n).negOnePow = n.negOnePow := by simpa [mul_sub, negOnePow_eq_iff] using n.even_mul_pred_self lemma cast_negOnePow_natCast (R : Type*) [Ring R] (n : ℕ) : negOnePow n = (-1 : R) ^ n := by obtain ⟨k, rfl | rfl⟩ := Nat.even_or_odd' n <;> simp [pow_succ, pow_mul] lemma coe_negOnePow_natCast (n : ℕ) : negOnePow n = (-1 : ℤ) ^ n := cast_negOnePow_natCast .. end Int
.lake/packages/mathlib/Mathlib/Algebra/Ring/Prod.lean
import Mathlib.Data.Int.Cast.Prod import Mathlib.Algebra.GroupWithZero.Prod import Mathlib.Algebra.Ring.CompTypeclasses import Mathlib.Algebra.Ring.Equiv /-! # Semiring, ring etc. structures on `R × S` In this file we define two-binop (`Semiring`, `Ring` etc) structures on `R × S`. We also prove trivial `simp` lemmas, and define the following operations on `RingHom`s and similarly for `NonUnitalRingHom`s: * `fst R S : R × S →+* R`, `snd R S : R × S →+* S`: projections `Prod.fst` and `Prod.snd` as `RingHom`s; * `f.prod g : R →+* S × T`: sends `x` to `(f x, g x)`; * `f.prod_map g : R × S → R' × S'`: `Prod.map f g` as a `RingHom`, sends `(x, y)` to `(f x, g y)`. -/ variable {R R' S S' T : Type*} namespace Prod /-- Product of two distributive types is distributive. -/ instance instDistrib [Distrib R] [Distrib S] : Distrib (R × S) where left_distrib _ _ _ := by ext <;> exact left_distrib .. right_distrib _ _ _ := by ext <;> exact right_distrib .. /-- Product of two `NonUnitalNonAssocSemiring`s is a `NonUnitalNonAssocSemiring`. -/ instance instNonUnitalNonAssocSemiring [NonUnitalNonAssocSemiring R] [NonUnitalNonAssocSemiring S] : NonUnitalNonAssocSemiring (R × S) := { inferInstanceAs (AddCommMonoid (R × S)), inferInstanceAs (Distrib (R × S)), inferInstanceAs (MulZeroClass (R × S)) with } /-- Product of two `NonUnitalSemiring`s is a `NonUnitalSemiring`. -/ instance instNonUnitalSemiring [NonUnitalSemiring R] [NonUnitalSemiring S] : NonUnitalSemiring (R × S) := { inferInstanceAs (NonUnitalNonAssocSemiring (R × S)), inferInstanceAs (SemigroupWithZero (R × S)) with } /-- Product of two `NonAssocSemiring`s is a `NonAssocSemiring`. -/ instance instNonAssocSemiring [NonAssocSemiring R] [NonAssocSemiring S] : NonAssocSemiring (R × S) := { inferInstanceAs (NonUnitalNonAssocSemiring (R × S)), inferInstanceAs (MulZeroOneClass (R × S)), inferInstanceAs (AddMonoidWithOne (R × S)) with } /-- Product of two semirings is a semiring. -/ instance instSemiring [Semiring R] [Semiring S] : Semiring (R × S) := { inferInstanceAs (NonUnitalSemiring (R × S)), inferInstanceAs (NonAssocSemiring (R × S)), inferInstanceAs (MonoidWithZero (R × S)) with } /-- Product of two `NonUnitalCommSemiring`s is a `NonUnitalCommSemiring`. -/ instance instNonUnitalCommSemiring [NonUnitalCommSemiring R] [NonUnitalCommSemiring S] : NonUnitalCommSemiring (R × S) := { inferInstanceAs (NonUnitalSemiring (R × S)), inferInstanceAs (CommSemigroup (R × S)) with } /-- Product of two commutative semirings is a commutative semiring. -/ instance instCommSemiring [CommSemiring R] [CommSemiring S] : CommSemiring (R × S) := { inferInstanceAs (Semiring (R × S)), inferInstanceAs (CommMonoid (R × S)) with } instance instNonUnitalNonAssocRing [NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S] : NonUnitalNonAssocRing (R × S) := { inferInstanceAs (AddCommGroup (R × S)), inferInstanceAs (NonUnitalNonAssocSemiring (R × S)) with } instance instNonUnitalRing [NonUnitalRing R] [NonUnitalRing S] : NonUnitalRing (R × S) := { inferInstanceAs (NonUnitalNonAssocRing (R × S)), inferInstanceAs (NonUnitalSemiring (R × S)) with } instance instNonAssocRing [NonAssocRing R] [NonAssocRing S] : NonAssocRing (R × S) := { inferInstanceAs (NonUnitalNonAssocRing (R × S)), inferInstanceAs (NonAssocSemiring (R × S)), inferInstanceAs (AddGroupWithOne (R × S)) with } /-- Product of two rings is a ring. -/ instance instRing [Ring R] [Ring S] : Ring (R × S) := { inferInstanceAs (Semiring (R × S)), inferInstanceAs (AddCommGroup (R × S)), inferInstanceAs (AddGroupWithOne (R × S)) with } /-- Product of two `NonUnitalCommRing`s is a `NonUnitalCommRing`. -/ instance instNonUnitalCommRing [NonUnitalCommRing R] [NonUnitalCommRing S] : NonUnitalCommRing (R × S) := { inferInstanceAs (NonUnitalRing (R × S)), inferInstanceAs (CommSemigroup (R × S)) with } /-- Product of two commutative rings is a commutative ring. -/ instance instCommRing [CommRing R] [CommRing S] : CommRing (R × S) := { inferInstanceAs (Ring (R × S)), inferInstanceAs (CommMonoid (R × S)) with } end Prod namespace NonUnitalRingHom variable (R S) [NonUnitalNonAssocSemiring R] [NonUnitalNonAssocSemiring S] /-- Given non-unital semirings `R`, `S`, the natural projection homomorphism from `R × S` to `R`. -/ def fst : R × S →ₙ+* R := { MulHom.fst R S, AddMonoidHom.fst R S with toFun := Prod.fst } /-- Given non-unital semirings `R`, `S`, the natural projection homomorphism from `R × S` to `S`. -/ def snd : R × S →ₙ+* S := { MulHom.snd R S, AddMonoidHom.snd R S with toFun := Prod.snd } variable {R S} @[simp] theorem coe_fst : ⇑(fst R S) = Prod.fst := rfl @[simp] theorem coe_snd : ⇑(snd R S) = Prod.snd := rfl section Prod variable [NonUnitalNonAssocSemiring T] (f : R →ₙ+* S) (g : R →ₙ+* T) /-- Combine two non-unital ring homomorphisms `f : R →ₙ+* S`, `g : R →ₙ+* T` into `f.prod g : R →ₙ+* S × T` given by `(f.prod g) x = (f x, g x)` -/ protected def prod (f : R →ₙ+* S) (g : R →ₙ+* T) : R →ₙ+* S × T := { MulHom.prod (f : MulHom R S) (g : MulHom R T), AddMonoidHom.prod (f : R →+ S) (g : R →+ T) with toFun := fun x => (f x, g x) } @[simp] theorem prod_apply (x) : f.prod g x = (f x, g x) := rfl @[simp] theorem fst_comp_prod : (fst S T).comp (f.prod g) = f := ext fun _ => rfl @[simp] theorem snd_comp_prod : (snd S T).comp (f.prod g) = g := ext fun _ => rfl theorem prod_unique (f : R →ₙ+* S × T) : ((fst S T).comp f).prod ((snd S T).comp f) = f := ext fun x => by simp only [prod_apply, coe_fst, coe_snd, comp_apply] end Prod section prodMap variable [NonUnitalNonAssocSemiring R'] [NonUnitalNonAssocSemiring S'] [NonUnitalNonAssocSemiring T] variable (f : R →ₙ+* R') (g : S →ₙ+* S') /-- `Prod.map` as a `NonUnitalRingHom`. -/ def prodMap : R × S →ₙ+* R' × S' := (f.comp (fst R S)).prod (g.comp (snd R S)) theorem prodMap_def : prodMap f g = (f.comp (fst R S)).prod (g.comp (snd R S)) := rfl @[simp] theorem coe_prodMap : ⇑(prodMap f g) = Prod.map f g := rfl theorem prod_comp_prodMap (f : T →ₙ+* R) (g : T →ₙ+* S) (f' : R →ₙ+* R') (g' : S →ₙ+* S') : (f'.prodMap g').comp (f.prod g) = (f'.comp f).prod (g'.comp g) := rfl end prodMap end NonUnitalRingHom namespace RingHom variable (R S) [NonAssocSemiring R] [NonAssocSemiring S] /-- Given semirings `R`, `S`, the natural projection homomorphism from `R × S` to `R`. -/ def fst : R × S →+* R := { MonoidHom.fst R S, AddMonoidHom.fst R S with toFun := Prod.fst } /-- Given semirings `R`, `S`, the natural projection homomorphism from `R × S` to `S`. -/ def snd : R × S →+* S := { MonoidHom.snd R S, AddMonoidHom.snd R S with toFun := Prod.snd } instance (R S) [Semiring R] [Semiring S] : RingHomSurjective (fst R S) := ⟨(⟨⟨·, 0⟩, rfl⟩)⟩ instance (R S) [Semiring R] [Semiring S] : RingHomSurjective (snd R S) := ⟨(⟨⟨0, ·⟩, rfl⟩)⟩ variable {R S} @[simp] theorem coe_fst : ⇑(fst R S) = Prod.fst := rfl @[simp] theorem coe_snd : ⇑(snd R S) = Prod.snd := rfl section Prod variable [NonAssocSemiring T] (f : R →+* S) (g : R →+* T) /-- Combine two ring homomorphisms `f : R →+* S`, `g : R →+* T` into `f.prod g : R →+* S × T` given by `(f.prod g) x = (f x, g x)` -/ protected def prod (f : R →+* S) (g : R →+* T) : R →+* S × T := { MonoidHom.prod (f : R →* S) (g : R →* T), AddMonoidHom.prod (f : R →+ S) (g : R →+ T) with toFun := fun x => (f x, g x) } @[simp] theorem prod_apply (x) : f.prod g x = (f x, g x) := rfl @[simp] theorem fst_comp_prod : (fst S T).comp (f.prod g) = f := ext fun _ => rfl @[simp] theorem snd_comp_prod : (snd S T).comp (f.prod g) = g := ext fun _ => rfl theorem prod_unique (f : R →+* S × T) : ((fst S T).comp f).prod ((snd S T).comp f) = f := ext fun x => by simp only [prod_apply, coe_fst, coe_snd, comp_apply] end Prod section prodMap variable [NonAssocSemiring R'] [NonAssocSemiring S'] [NonAssocSemiring T] variable (f : R →+* R') (g : S →+* S') /-- `Prod.map` as a `RingHom`. -/ def prodMap : R × S →+* R' × S' := (f.comp (fst R S)).prod (g.comp (snd R S)) theorem prodMap_def : prodMap f g = (f.comp (fst R S)).prod (g.comp (snd R S)) := rfl @[simp] theorem coe_prodMap : ⇑(prodMap f g) = Prod.map f g := rfl theorem prod_comp_prodMap (f : T →+* R) (g : T →+* S) (f' : R →+* R') (g' : S →+* S') : (f'.prodMap g').comp (f.prod g) = (f'.comp f).prod (g'.comp g) := rfl end prodMap end RingHom namespace RingEquiv variable [NonAssocSemiring R] [NonAssocSemiring S] [NonAssocSemiring R'] [NonAssocSemiring S'] /-- Swapping components as an equivalence of (semi)rings. -/ def prodComm : R × S ≃+* S × R := { AddEquiv.prodComm, MulEquiv.prodComm with } @[simp] theorem coe_prodComm : ⇑(prodComm : R × S ≃+* S × R) = Prod.swap := rfl @[simp] theorem coe_prodComm_symm : ⇑(prodComm : R × S ≃+* S × R).symm = Prod.swap := rfl @[simp] theorem fst_comp_coe_prodComm : (RingHom.fst S R).comp ↑(prodComm : R × S ≃+* S × R) = RingHom.snd R S := RingHom.ext fun _ => rfl @[simp] theorem snd_comp_coe_prodComm : (RingHom.snd S R).comp ↑(prodComm : R × S ≃+* S × R) = RingHom.fst R S := RingHom.ext fun _ => rfl section variable (R R' S S') /-- Four-way commutativity of `Prod`. The name matches `mul_mul_mul_comm`. -/ @[simps apply] def prodProdProdComm : (R × R') × S × S' ≃+* (R × S) × R' × S' := { AddEquiv.prodProdProdComm R R' S S', MulEquiv.prodProdProdComm R R' S S' with toFun := fun rrss => ((rrss.1.1, rrss.2.1), (rrss.1.2, rrss.2.2)) invFun := fun rsrs => ((rsrs.1.1, rsrs.2.1), (rsrs.1.2, rsrs.2.2)) } @[simp] theorem prodProdProdComm_symm : (prodProdProdComm R R' S S').symm = prodProdProdComm R S R' S' := rfl @[simp] theorem prodProdProdComm_toAddEquiv : (prodProdProdComm R R' S S' : _ ≃+ _) = AddEquiv.prodProdProdComm R R' S S' := rfl @[simp] theorem prodProdProdComm_toMulEquiv : (prodProdProdComm R R' S S' : _ ≃* _) = MulEquiv.prodProdProdComm R R' S S' := rfl @[simp] theorem prodProdProdComm_toEquiv : (prodProdProdComm R R' S S' : _ ≃ _) = Equiv.prodProdProdComm R R' S S' := rfl end variable (R S) [Subsingleton S] /-- A ring `R` is isomorphic to `R × S` when `S` is the zero ring -/ @[simps] def prodZeroRing : R ≃+* R × S where toFun x := (x, 0) invFun := Prod.fst map_add' := by simp map_mul' := by simp right_inv x := by cases x; simp [eq_iff_true_of_subsingleton] /-- A ring `R` is isomorphic to `S × R` when `S` is the zero ring -/ @[simps] def zeroRingProd : R ≃+* S × R where toFun x := (0, x) invFun := Prod.snd map_add' := by simp map_mul' := by simp right_inv x := by cases x; simp [eq_iff_true_of_subsingleton] end RingEquiv /-- The product of two nontrivial rings is not a domain -/ theorem false_of_nontrivial_of_product_domain (R S : Type*) [Semiring R] [Semiring S] [IsDomain (R × S)] [Nontrivial R] [Nontrivial S] : False := by have := NoZeroDivisors.eq_zero_or_eq_zero_of_mul_eq_zero (show ((0 : R), (1 : S)) * (1, 0) = 0 by simp) rw [Prod.mk_eq_zero, Prod.mk_eq_zero] at this rcases this with (⟨_, h⟩ | ⟨h, _⟩) · exact zero_ne_one h.symm · exact zero_ne_one h.symm
.lake/packages/mathlib/Mathlib/Algebra/Ring/Nat.lean
import Mathlib.Algebra.CharZero.Defs import Mathlib.Algebra.GroupWithZero.Nat import Mathlib.Algebra.Ring.Defs import Mathlib.Data.Nat.Basic /-! # The natural numbers form a semiring This file contains the commutative semiring instance on the natural numbers. See note [foundational algebra order theory]. -/ namespace Nat instance instAddMonoidWithOne : AddMonoidWithOne ℕ where natCast n := n natCast_zero := rfl natCast_succ _ := rfl instance instAddCommMonoidWithOne : AddCommMonoidWithOne ℕ where __ := instAddMonoidWithOne __ := instAddCommMonoid instance instDistrib : Distrib ℕ where left_distrib := Nat.left_distrib right_distrib := Nat.right_distrib instance instNonUnitalNonAssocSemiring : NonUnitalNonAssocSemiring ℕ where __ := instAddCommMonoid __ := instDistrib __ := instMulZeroClass instance instNonUnitalSemiring : NonUnitalSemiring ℕ where __ := instNonUnitalNonAssocSemiring __ := instSemigroupWithZero instance instNonAssocSemiring : NonAssocSemiring ℕ where __ := instNonUnitalNonAssocSemiring __ := instMulZeroOneClass __ := instAddCommMonoidWithOne instance instSemiring : Semiring ℕ where __ := instNonUnitalSemiring __ := instNonAssocSemiring __ := instMonoidWithZero instance instCommSemiring : CommSemiring ℕ where __ := instSemiring __ := instCommMonoid instance instCharZero : CharZero ℕ where cast_injective := Function.injective_id instance instIsDomain : IsDomain ℕ where end Nat
.lake/packages/mathlib/Mathlib/Algebra/Ring/Invertible.lean
import Mathlib.Algebra.GroupWithZero.Invertible import Mathlib.Algebra.Ring.Defs /-! # Theorems about additively and multiplicatively invertible elements in rings -/ variable {R : Type*} section NonUnitalNonAssocSemiring variable [NonUnitalNonAssocSemiring R] (x : AddUnits R) (y : R) /-- Multiplying an additive unit from the left produces another additive unit. -/ @[simps] def AddUnits.mulLeft : AddUnits R where val := y * x.val neg := y * x.neg val_neg := by simp [← mul_add] neg_val := by simp [← mul_add] /-- Multiplying an additive unit from the right produces another additive unit. -/ @[simps] def AddUnits.mulRight : AddUnits R where val := x.val * y neg := x.neg * y val_neg := by simp [← add_mul] neg_val := by simp [← add_mul] variable {x y} theorem AddUnits.neg_mulLeft : -(x.mulLeft y) = (-x).mulLeft y := rfl theorem AddUnits.neg_mulRight : -(x.mulRight y) = (-x).mulRight y := rfl @[deprecated (since := "2025-10-03")] alias AddUnits.neg_mul_left := AddUnits.neg_mulLeft @[deprecated (since := "2025-10-03")] alias AddUnits.neg_mul_right := AddUnits.neg_mulRight theorem AddUnits.neg_mul_eq_mul_neg {x y : AddUnits R} : (↑(-x) * y : R) = x * ↑(-y) := by rw [← neg_eq_val_neg, ← val_neg_mulRight] apply AddUnits.neg_eq_of_add_eq_zero_left simp [← mul_add] theorem AddUnits.neg_mul_neg {x y : AddUnits R} : ↑(-x) * ↑(-y) = (x * y : R) := by rw [← val_mulLeft, ← val_mulLeft, ← AddUnits.ext_iff, ← neg_inj, ← y.neg_mulLeft, neg_neg] apply AddUnits.ext simp [neg_mul_eq_mul_neg] theorem IsAddUnit.mul_left {x : R} (h : IsAddUnit x) (y : R) : IsAddUnit (y * x) := (h.addUnit.mulLeft y).isAddUnit theorem IsAddUnit.mul_right {x : R} (h : IsAddUnit x) (y : R) : IsAddUnit (x * y) := (h.addUnit.mulRight y).isAddUnit end NonUnitalNonAssocSemiring /-- `-⅟a` is the inverse of `-a` -/ def invertibleNeg [Mul R] [One R] [HasDistribNeg R] (a : R) [Invertible a] : Invertible (-a) := ⟨-⅟a, by simp, by simp⟩ @[simp] theorem invOf_neg [Monoid R] [HasDistribNeg R] (a : R) [Invertible a] [Invertible (-a)] : ⅟(-a) = -⅟a := invOf_eq_right_inv (by simp) @[simp] theorem one_sub_invOf_two [Ring R] [Invertible (2 : R)] : 1 - (⅟2 : R) = ⅟2 := (isUnit_of_invertible (2 : R)).mul_right_inj.1 <| by rw [mul_sub, mul_invOf_self, mul_one, ← one_add_one_eq_two, add_sub_cancel_right] @[simp] theorem invOf_two_add_invOf_two [NonAssocSemiring R] [Invertible (2 : R)] : (⅟2 : R) + (⅟2 : R) = 1 := by rw [← two_mul, mul_invOf_self] theorem pos_of_invertible_cast [NonAssocSemiring R] [Nontrivial R] (n : ℕ) [Invertible (n : R)] : 0 < n := Nat.zero_lt_of_ne_zero fun h => Invertible.ne_zero (n : R) (h ▸ Nat.cast_zero) theorem invOf_add_invOf [Semiring R] (a b : R) [Invertible a] [Invertible b] : ⅟a + ⅟b = ⅟a * (a + b) * ⅟b := by rw [mul_add, invOf_mul_self, add_mul, one_mul, mul_assoc, mul_invOf_self, mul_one, add_comm] /-- A version of `inv_sub_inv'` for `invOf`. -/ theorem invOf_sub_invOf [Ring R] (a b : R) [Invertible a] [Invertible b] : ⅟a - ⅟b = ⅟a * (b - a) * ⅟b := by rw [mul_sub, invOf_mul_self, sub_mul, one_mul, mul_assoc, mul_invOf_self, mul_one] lemma neg_add_eq_mul_invOf_mul_same_iff [Ring R] {a b : R} [Invertible a] [Invertible b] : -(b + a) = a * ⅟b * a ↔ -1 = ⅟a * b + ⅟b * a := calc -(b + a) = a * ⅟b * a ↔ -a = b + a * ⅟b * a := ⟨by grind, fun h ↦ by simp [h]⟩ _ ↔ -a = a * ⅟a * b + a * ⅟b * a := by rw [mul_invOf_self, one_mul] _ ↔ -a = a * (⅟a * b + ⅟b * a) := by simp only [mul_add, mul_assoc] _ ↔ -1 = ⅟a * b + ⅟b * a := ⟨fun h ↦ by simpa using congr_arg (⅟a * ·) h, fun h ↦ by simp [← h]⟩ lemma neg_one_eq_invOf_mul_add_invOf_mul_iff [Ring R] {a b : R} [Invertible a] [Invertible b] [Invertible (a + b)] : ⅟(a + b) = ⅟a + ⅟b ↔ -1 = ⅟a * b + ⅟b * a := by calc ⅟(a + b) = ⅟a + ⅟b ↔ ⅟(a + b) * (a + b) = (⅟a + ⅟b) * (a + b) := by rw [mul_left_inj_of_invertible] _ ↔ 1 = ⅟a * a + ⅟b * a + (⅟a * b + ⅟b * b) := by rw [invOf_mul_self, mul_add, add_mul, add_mul] _ ↔ 1 = 1 + ⅟b * a + (1 + ⅟a * b) := by rw [invOf_mul_self, invOf_mul_self, add_comm _ 1] _ ↔ 1 = 1 + 1 + ⅟b * a + ⅟a * b := by rw [← add_assoc, add_comm _ 1, ← add_assoc] _ ↔ -2 + 1 = -2 + (2 + ⅟b * a + ⅟a * b) := by rw [one_add_one_eq_two, add_right_inj] _ ↔ -2 + 1 = ⅟b * a + ⅟a * b := by rw [← add_assoc, ← add_assoc, neg_add_cancel, zero_add] _ ↔ -1 + 0 = ⅟b * a + ⅟a * b := by rw [← one_add_one_eq_two, neg_add, add_assoc, neg_add_cancel] _ ↔ -1 = ⅟a * b + ⅟b * a := by rw [add_zero, add_comm] theorem eq_of_invOf_add_eq_invOf_add_invOf [Ring R] {a b : R} [Invertible a] [Invertible b] [Invertible (a + b)] (h : ⅟(a + b) = ⅟a + ⅟b) : a * ⅟b * a = b * ⅟a * b := by have h' := neg_one_eq_invOf_mul_add_invOf_mul_iff.mp h have h_a_binv_a : -(b + a) = a * ⅟b * a := neg_add_eq_mul_invOf_mul_same_iff.mpr h' have h_b_ainv_b : -(a + b) = b * ⅟a * b := by rw [add_comm] at h' exact neg_add_eq_mul_invOf_mul_same_iff.mpr h' rw [← h_a_binv_a, ← h_b_ainv_b, add_comm] /-- A version of `inv_add_inv'` for `Ring.inverse`. -/ theorem Ring.inverse_add_inverse [Semiring R] {a b : R} (h : IsUnit a ↔ IsUnit b) : Ring.inverse a + Ring.inverse b = Ring.inverse a * (a + b) * Ring.inverse b := by by_cases ha : IsUnit a · have hb := h.mp ha obtain ⟨ia⟩ := ha.nonempty_invertible obtain ⟨ib⟩ := hb.nonempty_invertible simp_rw [inverse_invertible, invOf_add_invOf] · have hb := h.not.mp ha simp [inverse_non_unit, ha, hb] /-- A version of `inv_sub_inv'` for `Ring.inverse`. -/ theorem Ring.inverse_sub_inverse [Ring R] {a b : R} (h : IsUnit a ↔ IsUnit b) : Ring.inverse a - Ring.inverse b = Ring.inverse a * (b - a) * Ring.inverse b := by by_cases ha : IsUnit a · have hb := h.mp ha obtain ⟨ia⟩ := ha.nonempty_invertible obtain ⟨ib⟩ := hb.nonempty_invertible simp_rw [inverse_invertible, invOf_sub_invOf] · have hb := h.not.mp ha simp [inverse_non_unit, ha, hb]
.lake/packages/mathlib/Mathlib/Algebra/Ring/Pi.lean
import Mathlib.Algebra.Group.Pi.Lemmas import Mathlib.Algebra.GroupWithZero.Pi import Mathlib.Algebra.Ring.CompTypeclasses import Mathlib.Algebra.Ring.Hom.Defs /-! # Pi instances for ring This file defines instances for ring, semiring and related structures on Pi Types -/ -- Porting note: used to import `tactic.pi_instances` namespace Pi universe u v w variable {I : Type u} -- The indexing type variable {f : I → Type v} variable (i : I) instance distrib [∀ i, Distrib <| f i] : Distrib (∀ i : I, f i) where left_distrib := by intros; ext; exact mul_add _ _ _ right_distrib := by intros; ext; exact add_mul _ _ _ instance hasDistribNeg [∀ i, Mul (f i)] [∀ i, HasDistribNeg (f i)] : HasDistribNeg (∀ i, f i) where neg_mul _ _ := funext fun _ ↦ neg_mul _ _ mul_neg _ _ := funext fun _ ↦ mul_neg _ _ instance addMonoidWithOne [∀ i, AddMonoidWithOne (f i)] : AddMonoidWithOne (∀ i, f i) where natCast n _ := n natCast_zero := funext fun _ ↦ AddMonoidWithOne.natCast_zero natCast_succ n := funext fun _ ↦ AddMonoidWithOne.natCast_succ n instance addGroupWithOne [∀ i, AddGroupWithOne (f i)] : AddGroupWithOne (∀ i, f i) where __ := addGroup __ := addMonoidWithOne intCast n _ := n intCast_ofNat n := funext fun _ ↦ AddGroupWithOne.intCast_ofNat n intCast_negSucc n := funext fun _ ↦ AddGroupWithOne.intCast_negSucc n instance nonUnitalNonAssocSemiring [∀ i, NonUnitalNonAssocSemiring <| f i] : NonUnitalNonAssocSemiring (∀ i : I, f i) := { Pi.distrib, Pi.addCommMonoid, Pi.mulZeroClass with } instance nonUnitalSemiring [∀ i, NonUnitalSemiring <| f i] : NonUnitalSemiring (∀ i : I, f i) := { Pi.nonUnitalNonAssocSemiring, Pi.semigroupWithZero with } instance nonAssocSemiring [∀ i, NonAssocSemiring <| f i] : NonAssocSemiring (∀ i : I, f i) := { Pi.nonUnitalNonAssocSemiring, Pi.mulZeroOneClass, Pi.addMonoidWithOne with } instance semiring [∀ i, Semiring <| f i] : Semiring (∀ i : I, f i) := { Pi.nonUnitalSemiring, Pi.nonAssocSemiring, Pi.monoidWithZero with } instance nonUnitalCommSemiring [∀ i, NonUnitalCommSemiring <| f i] : NonUnitalCommSemiring (∀ i : I, f i) := { Pi.nonUnitalSemiring, Pi.commSemigroup with } instance commSemiring [∀ i, CommSemiring <| f i] : CommSemiring (∀ i : I, f i) := { Pi.semiring, Pi.commMonoid with } instance nonUnitalNonAssocRing [∀ i, NonUnitalNonAssocRing <| f i] : NonUnitalNonAssocRing (∀ i : I, f i) := { Pi.addCommGroup, Pi.nonUnitalNonAssocSemiring with } instance nonUnitalRing [∀ i, NonUnitalRing <| f i] : NonUnitalRing (∀ i : I, f i) := { Pi.nonUnitalNonAssocRing, Pi.nonUnitalSemiring with } instance nonAssocRing [∀ i, NonAssocRing <| f i] : NonAssocRing (∀ i : I, f i) := { Pi.nonUnitalNonAssocRing, Pi.nonAssocSemiring, Pi.addGroupWithOne with } instance ring [∀ i, Ring <| f i] : Ring (∀ i : I, f i) := { Pi.semiring, Pi.addCommGroup, Pi.addGroupWithOne with } instance nonUnitalCommRing [∀ i, NonUnitalCommRing <| f i] : NonUnitalCommRing (∀ i : I, f i) := { Pi.nonUnitalRing, Pi.commSemigroup with } instance commRing [∀ i, CommRing <| f i] : CommRing (∀ i : I, f i) := { Pi.ring, Pi.commSemiring with } /-- A family of non-unital ring homomorphisms `f a : γ →ₙ+* β a` defines a non-unital ring homomorphism `Pi.nonUnitalRingHom f : γ →+* Π a, β a` given by `Pi.nonUnitalRingHom f x b = f b x`. -/ @[simps] protected def nonUnitalRingHom {γ : Type w} [∀ i, NonUnitalNonAssocSemiring (f i)] [NonUnitalNonAssocSemiring γ] (g : ∀ i, γ →ₙ+* f i) : γ →ₙ+* ∀ i, f i := { Pi.mulHom fun i => (g i).toMulHom, Pi.addMonoidHom fun i => (g i).toAddMonoidHom with toFun := fun x b => g b x } theorem nonUnitalRingHom_injective {γ : Type w} [Nonempty I] [∀ i, NonUnitalNonAssocSemiring (f i)] [NonUnitalNonAssocSemiring γ] (g : ∀ i, γ →ₙ+* f i) (hg : ∀ i, Function.Injective (g i)) : Function.Injective (Pi.nonUnitalRingHom g) := mulHom_injective (fun i => (g i).toMulHom) hg /-- A family of ring homomorphisms `f a : γ →+* β a` defines a ring homomorphism `Pi.ringHom f : γ →+* Π a, β a` given by `Pi.ringHom f x b = f b x`. -/ @[simps] protected def ringHom {γ : Type w} [∀ i, NonAssocSemiring (f i)] [NonAssocSemiring γ] (g : ∀ i, γ →+* f i) : γ →+* ∀ i, f i := { Pi.monoidHom fun i => (g i).toMonoidHom, Pi.addMonoidHom fun i => (g i).toAddMonoidHom with toFun := fun x b => g b x } theorem ringHom_injective {γ : Type w} [Nonempty I] [∀ i, NonAssocSemiring (f i)] [NonAssocSemiring γ] (g : ∀ i, γ →+* f i) (hg : ∀ i, Function.Injective (g i)) : Function.Injective (Pi.ringHom g) := monoidHom_injective (fun i => (g i).toMonoidHom) hg end Pi section NonUnitalRingHom universe u v variable {I : Type u} /-- Evaluation of functions into an indexed collection of non-unital rings at a point is a non-unital ring homomorphism. This is `Function.eval` as a `NonUnitalRingHom`. -/ @[simps!] def Pi.evalNonUnitalRingHom (f : I → Type v) [∀ i, NonUnitalNonAssocSemiring (f i)] (i : I) : (∀ i, f i) →ₙ+* f i := { Pi.evalMulHom f i, Pi.evalAddMonoidHom f i with } /-- `Function.const` as a `NonUnitalRingHom`. -/ @[simps] def Pi.constNonUnitalRingHom (α β : Type*) [NonUnitalNonAssocSemiring β] : β →ₙ+* α → β := { Pi.nonUnitalRingHom fun _ => NonUnitalRingHom.id β with toFun := Function.const _ } /-- Non-unital ring homomorphism between the function spaces `I → α` and `I → β`, induced by a non-unital ring homomorphism `f` between `α` and `β`. -/ @[simps] protected def NonUnitalRingHom.compLeft {α β : Type*} [NonUnitalNonAssocSemiring α] [NonUnitalNonAssocSemiring β] (f : α →ₙ+* β) (I : Type*) : (I → α) →ₙ+* I → β := { f.toMulHom.compLeft I, f.toAddMonoidHom.compLeft I with toFun := fun h => f ∘ h } end NonUnitalRingHom section RingHom universe u v variable {I : Type u} /-- Evaluation of functions into an indexed collection of rings at a point is a ring homomorphism. This is `Function.eval` as a `RingHom`. -/ @[simps!] def Pi.evalRingHom (f : I → Type v) [∀ i, NonAssocSemiring (f i)] (i : I) : (∀ i, f i) →+* f i := { Pi.evalMonoidHom f i, Pi.evalAddMonoidHom f i with } instance (f : I → Type*) [∀ i, Semiring (f i)] (i) : RingHomSurjective (Pi.evalRingHom f i) where is_surjective x := ⟨by classical exact (if h : · = i then h ▸ x else 0), by simp⟩ /-- `Function.const` as a `RingHom`. -/ @[simps] def Pi.constRingHom (α β : Type*) [NonAssocSemiring β] : β →+* α → β := { Pi.ringHom fun _ => RingHom.id β with toFun := Function.const _ } /-- Ring homomorphism between the function spaces `I → α` and `I → β`, induced by a ring homomorphism `f` between `α` and `β`. -/ @[simps] protected def RingHom.compLeft {α β : Type*} [NonAssocSemiring α] [NonAssocSemiring β] (f : α →+* β) (I : Type*) : (I → α) →+* I → β := { f.toMonoidHom.compLeft I, f.toAddMonoidHom.compLeft I with toFun := fun h => f ∘ h } end RingHom
.lake/packages/mathlib/Mathlib/Algebra/Ring/Center.lean
import Mathlib.Algebra.Group.Center import Mathlib.Data.Int.Cast.Lemmas /-! # Centers of rings -/ assert_not_exists RelIso Finset Subsemigroup Field variable {M : Type*} namespace Set variable (M) @[simp] theorem natCast_mem_center [NonAssocSemiring M] (n : ℕ) : (n : M) ∈ Set.center M where comm _ := by rw [commute_iff_eq, Nat.commute_cast] left_assoc _ _ := by induction n with | zero => rw [Nat.cast_zero, zero_mul, zero_mul, zero_mul] | succ n ihn => rw [Nat.cast_succ, add_mul, one_mul, ihn, add_mul, add_mul, one_mul] right_assoc _ _ := by induction n with | zero => rw [Nat.cast_zero, mul_zero, mul_zero, mul_zero] | succ n ihn => rw [Nat.cast_succ, mul_add, ihn, mul_add, mul_add, mul_one, mul_one] @[simp] theorem ofNat_mem_center [NonAssocSemiring M] (n : ℕ) [n.AtLeastTwo] : ofNat(n) ∈ Set.center M := natCast_mem_center M n @[simp] theorem intCast_mem_center [NonAssocRing M] (n : ℤ) : (n : M) ∈ Set.center M where comm _ := by rw [commute_iff_eq, Int.commute_cast] left_assoc _ _ := match n with | (n : ℕ) => by rw [Int.cast_natCast, (natCast_mem_center _ n).left_assoc _ _] | Int.negSucc n => by rw [Int.cast_negSucc, Nat.cast_add, Nat.cast_one, neg_add_rev, add_mul, add_mul, add_mul, neg_mul, one_mul, neg_mul 1, one_mul, ← neg_mul, add_right_inj, neg_mul, (natCast_mem_center _ n).left_assoc _ _, neg_mul, neg_mul] right_assoc _ _ := match n with | (n : ℕ) => by rw [Int.cast_natCast, (natCast_mem_center _ n).right_assoc _ _] | Int.negSucc n => by simp only [Int.cast_negSucc, Nat.cast_add, Nat.cast_one, neg_add_rev] rw [mul_add, mul_add, mul_add, mul_neg, mul_one, mul_neg, mul_neg, mul_one, mul_neg, add_right_inj, (natCast_mem_center _ n).right_assoc _ _, mul_neg, mul_neg] variable {M} @[simp] theorem add_mem_center [Distrib M] {a b : M} (ha : a ∈ Set.center M) (hb : b ∈ Set.center M) : a + b ∈ Set.center M where comm _ := by rw [commute_iff_eq, add_mul, mul_add, ha.comm, hb.comm] left_assoc _ _ := by rw [add_mul, ha.left_assoc, hb.left_assoc, ← add_mul, ← add_mul] right_assoc _ _ := by rw [mul_add, ha.right_assoc, hb.right_assoc, ← mul_add, ← mul_add] @[simp] theorem neg_mem_center [NonUnitalNonAssocRing M] {a : M} (ha : a ∈ Set.center M) : -a ∈ Set.center M where comm _ := by rw [commute_iff_eq, ← neg_mul_comm, ← ha.comm, neg_mul_comm] left_assoc _ _ := by rw [neg_mul, ha.left_assoc, neg_mul, neg_mul] right_assoc _ _ := by rw [mul_neg, ha.right_assoc, mul_neg, mul_neg] end Set
.lake/packages/mathlib/Mathlib/Algebra/Ring/Commute.lean
import Mathlib.Algebra.Ring.Semiconj import Mathlib.Algebra.Ring.Units import Mathlib.Algebra.Group.Commute.Defs import Mathlib.Data.Bracket /-! # Semirings and rings This file gives lemmas about semirings, rings and domains. This is analogous to `Mathlib/Algebra/Group/Basic.lean`, the difference being that the former is about `+` and `*` separately, while the present file is about their interaction. For the definitions of semirings and rings see `Mathlib/Algebra/Ring/Defs.lean`. -/ universe u variable {R : Type u} open Function namespace Commute @[simp] theorem add_right [Distrib R] {a b c : R} : Commute a b → Commute a c → Commute a (b + c) := SemiconjBy.add_right -- for some reason mathport expected `Semiring` instead of `Distrib`? @[simp] theorem add_left [Distrib R] {a b c : R} : Commute a c → Commute b c → Commute (a + b) c := SemiconjBy.add_left -- for some reason mathport expected `Semiring` instead of `Distrib`? /-- Representation of a difference of two squares of commuting elements as a product. -/ theorem mul_self_sub_mul_self_eq [NonUnitalNonAssocRing R] {a b : R} (h : Commute a b) : a * a - b * b = (a + b) * (a - b) := by rw [add_mul, mul_sub, mul_sub, h.eq, sub_add_sub_cancel] theorem mul_self_sub_mul_self_eq' [NonUnitalNonAssocRing R] {a b : R} (h : Commute a b) : a * a - b * b = (a - b) * (a + b) := by rw [mul_add, sub_mul, sub_mul, h.eq, sub_add_sub_cancel] theorem mul_self_eq_mul_self_iff [NonUnitalNonAssocRing R] [NoZeroDivisors R] {a b : R} (h : Commute a b) : a * a = b * b ↔ a = b ∨ a = -b := by rw [← sub_eq_zero, h.mul_self_sub_mul_self_eq, mul_eq_zero, or_comm, sub_eq_zero, add_eq_zero_iff_eq_neg] section variable [Mul R] [HasDistribNeg R] {a b : R} theorem neg_right : Commute a b → Commute a (-b) := SemiconjBy.neg_right @[simp] theorem neg_right_iff : Commute a (-b) ↔ Commute a b := SemiconjBy.neg_right_iff theorem neg_left : Commute a b → Commute (-a) b := SemiconjBy.neg_left @[simp] theorem neg_left_iff : Commute (-a) b ↔ Commute a b := SemiconjBy.neg_left_iff end section variable [MulOneClass R] [HasDistribNeg R] theorem neg_one_right (a : R) : Commute a (-1) := SemiconjBy.neg_one_right a theorem neg_one_left (a : R) : Commute (-1) a := SemiconjBy.neg_one_left a end section variable [NonUnitalNonAssocRing R] {a b c : R} @[simp] theorem sub_right : Commute a b → Commute a c → Commute a (b - c) := SemiconjBy.sub_right @[simp] theorem sub_left : Commute a c → Commute b c → Commute (a - b) c := SemiconjBy.sub_left end section Semiring variable [Semiring R] protected lemma add_sq {a b : R} (h : Commute a b) : (a + b) ^ 2 = a ^ 2 + 2 * a * b + b ^ 2 := by simp [sq, add_mul, mul_add, two_mul, h.eq, add_assoc] end Semiring section Ring variable [Ring R] {a b : R} protected lemma sq_sub_sq (h : Commute a b) : a ^ 2 - b ^ 2 = (a + b) * (a - b) := by rw [sq, sq, h.mul_self_sub_mul_self_eq] protected lemma sub_sq {a b : R} (h : Commute a b) : (a - b) ^ 2 = a ^ 2 - 2 * a * b + b ^ 2 := by simp [sq, add_mul, sub_mul, mul_sub, two_mul, h.eq, ← sub_add, ← sub_sub] variable [NoZeroDivisors R] protected lemma sq_eq_sq_iff_eq_or_eq_neg (h : Commute a b) : a ^ 2 = b ^ 2 ↔ a = b ∨ a = -b := by rw [← sub_eq_zero, h.sq_sub_sq, mul_eq_zero, add_eq_zero_iff_eq_neg, sub_eq_zero, or_comm] end Ring end Commute section HasDistribNeg variable (R) variable [Monoid R] [HasDistribNeg R] lemma neg_one_pow_eq_or : ∀ n : ℕ, (-1 : R) ^ n = 1 ∨ (-1 : R) ^ n = -1 | 0 => Or.inl (pow_zero _) | n + 1 => (neg_one_pow_eq_or n).symm.imp (fun h ↦ by rw [pow_succ, h, neg_one_mul, neg_neg]) (fun h ↦ by rw [pow_succ, h, one_mul]) variable {R} lemma neg_pow (a : R) (n : ℕ) : (-a) ^ n = (-1) ^ n * a ^ n := neg_one_mul a ▸ (Commute.neg_one_left a).mul_pow n lemma neg_pow' (a : R) (n : ℕ) : (-a) ^ n = a ^ n * (-1) ^ n := mul_neg_one a ▸ (Commute.neg_one_right a).mul_pow n lemma neg_sq (a : R) : (-a) ^ 2 = a ^ 2 := by simp [sq] lemma neg_one_sq : (-1 : R) ^ 2 = 1 := by simp [neg_sq, one_pow] alias neg_pow_two := neg_sq alias neg_one_pow_two := neg_one_sq end HasDistribNeg section Ring variable [Ring R] {a : R} {n : ℕ} @[simp] lemma neg_one_pow_mul_eq_zero_iff : (-1) ^ n * a = 0 ↔ a = 0 := by rcases neg_one_pow_eq_or R n with h | h <;> simp [h] @[simp] lemma mul_neg_one_pow_eq_zero_iff : a * (-1) ^ n = 0 ↔ a = 0 := by obtain h | h := neg_one_pow_eq_or R n <;> simp [h] lemma neg_one_pow_eq_pow_mod_two (n : ℕ) : (-1 : R) ^ n = (-1) ^ (n % 2) := by rw [← Nat.mod_add_div n 2, pow_add, pow_mul]; simp [sq] variable [NoZeroDivisors R] @[simp] lemma sq_eq_one_iff : a ^ 2 = 1 ↔ a = 1 ∨ a = -1 := by rw [← (Commute.one_right a).sq_eq_sq_iff_eq_or_eq_neg, one_pow] lemma sq_ne_one_iff : a ^ 2 ≠ 1 ↔ a ≠ 1 ∧ a ≠ -1 := sq_eq_one_iff.not.trans not_or end Ring /-- Representation of a difference of two squares in a commutative ring as a product. -/ theorem mul_self_sub_mul_self [NonUnitalNonAssocCommRing R] (a b : R) : a * a - b * b = (a + b) * (a - b) := (Commute.all a b).mul_self_sub_mul_self_eq theorem mul_self_sub_one [NonAssocRing R] (a : R) : a * a - 1 = (a + 1) * (a - 1) := by rw [← (Commute.one_right a).mul_self_sub_mul_self_eq, mul_one] theorem mul_self_eq_mul_self_iff [NonUnitalNonAssocCommRing R] [NoZeroDivisors R] {a b : R} : a * a = b * b ↔ a = b ∨ a = -b := (Commute.all a b).mul_self_eq_mul_self_iff theorem mul_self_eq_one_iff [NonAssocRing R] [NoZeroDivisors R] {a : R} : a * a = 1 ↔ a = 1 ∨ a = -1 := by rw [← (Commute.one_right a).mul_self_eq_mul_self_iff, mul_one] section CommRing variable [CommRing R] lemma sq_sub_sq (a b : R) : a ^ 2 - b ^ 2 = (a + b) * (a - b) := (Commute.all a b).sq_sub_sq alias pow_two_sub_pow_two := sq_sub_sq lemma sub_sq (a b : R) : (a - b) ^ 2 = a ^ 2 - 2 * a * b + b ^ 2 := by rw [sub_eq_add_neg, add_sq, neg_sq, mul_neg, ← sub_eq_add_neg] alias sub_pow_two := sub_sq lemma sub_sq' (a b : R) : (a - b) ^ 2 = a ^ 2 + b ^ 2 - 2 * a * b := by rw [sub_eq_add_neg, add_sq', neg_sq, mul_neg, ← sub_eq_add_neg] lemma sub_sq_comm (a b : R) : (a - b) ^ 2 = (b - a) ^ 2 := by rw [sub_sq', mul_right_comm, add_comm, sub_sq'] variable [NoZeroDivisors R] {a b : R} lemma sq_eq_sq_iff_eq_or_eq_neg : a ^ 2 = b ^ 2 ↔ a = b ∨ a = -b := (Commute.all a b).sq_eq_sq_iff_eq_or_eq_neg lemma eq_or_eq_neg_of_sq_eq_sq (a b : R) : a ^ 2 = b ^ 2 → a = b ∨ a = -b := sq_eq_sq_iff_eq_or_eq_neg.1 -- Copies of the above CommRing lemmas for `Units R`. namespace Units protected lemma sq_eq_sq_iff_eq_or_eq_neg {a b : Rˣ} : a ^ 2 = b ^ 2 ↔ a = b ∨ a = -b := by simp_rw [Units.ext_iff, val_pow_eq_pow_val, sq_eq_sq_iff_eq_or_eq_neg, Units.val_neg] protected lemma eq_or_eq_neg_of_sq_eq_sq (a b : Rˣ) (h : a ^ 2 = b ^ 2) : a = b ∨ a = -b := Units.sq_eq_sq_iff_eq_or_eq_neg.1 h end Units end CommRing namespace Units /-- In the unit group of an integral domain, a unit is its own inverse iff the unit is one or one's additive inverse. -/ theorem inv_eq_self_iff [Ring R] [NoZeroDivisors R] (u : Rˣ) : u⁻¹ = u ↔ u = 1 ∨ u = -1 := by rw [inv_eq_iff_mul_eq_one] simp only [Units.ext_iff] push_cast exact mul_self_eq_one_iff end Units section Bracket variable [NonUnitalNonAssocRing R] namespace Ring instance (priority := 100) instBracket : Bracket R R := ⟨fun x y => x * y - y * x⟩ theorem lie_def (x y : R) : ⁅x, y⁆ = x * y - y * x := rfl end Ring theorem commute_iff_lie_eq {x y : R} : Commute x y ↔ ⁅x, y⁆ = 0 := sub_eq_zero.symm theorem Commute.lie_eq {x y : R} (h : Commute x y) : ⁅x, y⁆ = 0 := sub_eq_zero_of_eq h end Bracket
.lake/packages/mathlib/Mathlib/Algebra/Ring/Basic.lean
import Mathlib.Algebra.Group.Commute.Defs import Mathlib.Algebra.Group.Hom.Instances import Mathlib.Algebra.GroupWithZero.NeZero import Mathlib.Algebra.Opposites import Mathlib.Algebra.Ring.Defs import Mathlib.Tactic.TFAE /-! # Semirings and rings This file gives lemmas about semirings, rings and domains. This is analogous to `Mathlib/Algebra/Group/Basic.lean`, the difference being that the former is about `+` and `*` separately, while the present file is about their interaction. For the definitions of semirings and rings see `Mathlib/Algebra/Ring/Defs.lean`. -/ assert_not_exists Nat.cast_sub variable {R S : Type*} open Function namespace AddHom /-- Left multiplication by an element of a type with distributive multiplication is an `AddHom`. -/ @[simps -fullyApplied] def mulLeft [Distrib R] (r : R) : AddHom R R where toFun := (r * ·) map_add' := mul_add r /-- Right multiplication by an element of a type with distributive multiplication is an `AddHom`. -/ @[simps -fullyApplied] def mulRight [Distrib R] (r : R) : AddHom R R where toFun a := a * r map_add' _ _ := add_mul _ _ r end AddHom namespace AddMonoidHom variable [NonUnitalNonAssocSemiring R] [NonUnitalNonAssocSemiring S] {a b : R} /-- Left multiplication by an element of a (semi)ring is an `AddMonoidHom` -/ def mulLeft (r : R) : R →+ R where toFun := (r * ·) map_zero' := mul_zero r map_add' := mul_add r @[simp, norm_cast] lemma coe_mulLeft (r : R) : (mulLeft r : R → R) = HMul.hMul r := rfl /-- Right multiplication by an element of a (semi)ring is an `AddMonoidHom` -/ def mulRight (r : R) : R →+ R where toFun a := a * r map_zero' := zero_mul r map_add' _ _ := add_mul _ _ r @[simp, norm_cast] lemma coe_mulRight (r : R) : (mulRight r) = (· * r) := rfl lemma mulRight_apply (a r : R) : mulRight r a = a * r := rfl /-- Multiplication of an element of a (semi)ring is an `AddMonoidHom` in both arguments. This is a more-strongly bundled version of `AddMonoidHom.mulLeft` and `AddMonoidHom.mulRight`. Stronger versions of this exists for algebras as `LinearMap.mul`, `NonUnitalAlgHom.mul` and `Algebra.lmul`. -/ def mul : R →+ R →+ R where toFun := mulLeft map_zero' := ext <| zero_mul map_add' a b := ext <| add_mul a b lemma mul_apply (x y : R) : mul x y = x * y := rfl @[simp, norm_cast] lemma coe_mul : ⇑(mul : R →+ R →+ R) = mulLeft := rfl @[simp, norm_cast] lemma coe_flip_mul : ⇑(mul : R →+ R →+ R).flip = mulRight := rfl /-- An `AddMonoidHom` preserves multiplication if pre- and post- composition with `mul` are equivalent. By converting the statement into an equality of `AddMonoidHom`s, this lemma allows various specialized `ext` lemmas about `→+` to then be applied. -/ lemma map_mul_iff (f : R →+ S) : (∀ x y, f (x * y) = f x * f y) ↔ (mul : R →+ R →+ R).compr₂ f = (mul.comp f).compl₂ f := Iff.symm ext_iff₂ lemma mulLeft_eq_mulRight_iff_forall_commute : mulLeft a = mulRight a ↔ ∀ b, Commute a b := DFunLike.ext_iff lemma mulRight_eq_mulLeft_iff_forall_commute : mulRight b = mulLeft b ↔ ∀ a, Commute a b := DFunLike.ext_iff end AddMonoidHom namespace AddMonoid.End section NonUnitalNonAssocSemiring variable [NonUnitalNonAssocSemiring R] /-- The left multiplication map: `(a, b) ↦ a * b`. See also `AddMonoidHom.mulLeft`. -/ @[simps!] def mulLeft : R →+ AddMonoid.End R := .mul /-- The right multiplication map: `(a, b) ↦ b * a`. See also `AddMonoidHom.mulRight`. -/ @[simps!] def mulRight : R →+ AddMonoid.End R := (.mul : R →+ AddMonoid.End R).flip end NonUnitalNonAssocSemiring section NonUnitalNonAssocCommSemiring variable [NonUnitalNonAssocCommSemiring R] lemma mulRight_eq_mulLeft : mulRight = (mulLeft : R →+ AddMonoid.End R) := AddMonoidHom.ext fun _ => Eq.symm <| AddMonoidHom.mulLeft_eq_mulRight_iff_forall_commute.2 (.all _) end NonUnitalNonAssocCommSemiring end AddMonoid.End section HasDistribNeg section Mul variable {α : Type*} [Mul α] [HasDistribNeg α] open MulOpposite instance MulOpposite.instHasDistribNeg : HasDistribNeg αᵐᵒᵖ where neg_mul _ _ := unop_injective <| mul_neg _ _ mul_neg _ _ := unop_injective <| neg_mul _ _ end Mul end HasDistribNeg section NonUnitalCommRing variable {α : Type*} [NonUnitalCommRing α] attribute [local simp] add_assoc add_comm add_left_comm mul_comm /-- Vieta's formula for a quadratic equation, relating the coefficients of the polynomial with its roots. This particular version states that if we have a root `x` of a monic quadratic polynomial, then there is another root `y` such that `x + y` is negative the `a_1` coefficient and `x * y` is the `a_0` coefficient. -/ theorem vieta_formula_quadratic {b c x : α} (h : x * x - b * x + c = 0) : ∃ y : α, y * y - b * y + c = 0 ∧ x + y = b ∧ x * y = c := by have : c = x * (b - x) := (eq_neg_of_add_eq_zero_right h).trans (by simp [mul_sub, mul_comm]) refine ⟨b - x, ?_, by simp, by rw [this]⟩ rw [this, sub_add, ← sub_mul, sub_self] end NonUnitalCommRing theorem succ_ne_self {α : Type*} [NonAssocRing α] [Nontrivial α] (a : α) : a + 1 ≠ a := fun h => one_ne_zero ((add_right_inj a).mp (by simp [h])) theorem pred_ne_self {α : Type*} [NonAssocRing α] [Nontrivial α] (a : α) : a - 1 ≠ a := fun h ↦ one_ne_zero (neg_injective ((add_right_inj a).mp (by simp [← sub_eq_add_neg, h]))) section NoZeroDivisors variable (α) lemma IsLeftCancelMulZero.to_noZeroDivisors [MulZeroClass α] [IsLeftCancelMulZero α] : NoZeroDivisors α where eq_zero_or_eq_zero_of_mul_eq_zero {x _} h := or_iff_not_imp_left.mpr fun ne ↦ mul_left_cancel₀ ne ((mul_zero x).symm ▸ h) lemma IsRightCancelMulZero.to_noZeroDivisors [MulZeroClass α] [IsRightCancelMulZero α] : NoZeroDivisors α where eq_zero_or_eq_zero_of_mul_eq_zero {_ y} h := or_iff_not_imp_right.mpr fun ne ↦ mul_right_cancel₀ ne ((zero_mul y).symm ▸ h) section NonUnitalNonAssocRing variable {R : Type*} [NonUnitalNonAssocRing R] {r : R} lemma isLeftRegular_iff_right_eq_zero_of_mul : IsLeftRegular r ↔ ∀ x, r * x = 0 → x = 0 where mp h r' eq := h (by simp_rw [eq, mul_zero]) mpr h r₁ r₂ eq := sub_eq_zero.mp <| h _ <| by simp_rw [mul_sub, eq, sub_self] lemma isRightRegular_iff_left_eq_zero_of_mul : IsRightRegular r ↔ ∀ x, x * r = 0 → x = 0 where mp h r' eq := h (by simp_rw [eq, zero_mul]) mpr h r₁ r₂ eq := sub_eq_zero.mp <| h _ <| by simp_rw [sub_mul, eq, sub_self] lemma isRegular_iff_eq_zero_of_mul : IsRegular r ↔ (∀ x, r * x = 0 → x = 0) ∧ (∀ x, x * r = 0 → x = 0) := by rw [isRegular_iff, isLeftRegular_iff_right_eq_zero_of_mul, isRightRegular_iff_left_eq_zero_of_mul] /-- A (not necessarily unital or associative) ring with no zero divisors has cancellative multiplication on both sides. Since either left or right cancellative multiplication implies the absence of zero divisors, the four conditions are equivalent to each other. -/ lemma noZeroDivisors_tfae : List.TFAE [NoZeroDivisors R, IsLeftCancelMulZero R, IsRightCancelMulZero R, IsCancelMulZero R] := by simp_rw [isLeftCancelMulZero_iff, isRightCancelMulZero_iff, isCancelMulZero_iff_forall_isRegular, isLeftRegular_iff_right_eq_zero_of_mul, isRightRegular_iff_left_eq_zero_of_mul, isRegular_iff_eq_zero_of_mul] tfae_have 1 ↔ 2 := noZeroDivisors_iff_right_eq_zero_of_mul tfae_have 1 ↔ 3 := noZeroDivisors_iff_left_eq_zero_of_mul tfae_have 1 ↔ 4 := noZeroDivisors_iff_eq_zero_of_mul tfae_finish /-- In a ring, `IsCancelMulZero` and `NoZeroDivisors` are equivalent. -/ lemma isCancelMulZero_iff_noZeroDivisors : IsCancelMulZero R ↔ NoZeroDivisors R := noZeroDivisors_tfae.out 3 0 variable (R) in instance (priority := 100) NoZeroDivisors.to_isCancelMulZero [NoZeroDivisors R] : IsCancelMulZero R := isCancelMulZero_iff_noZeroDivisors.mpr ‹_› end NonUnitalNonAssocRing lemma NoZeroDivisors.to_isDomain [Ring α] [h : Nontrivial α] [NoZeroDivisors α] : IsDomain α := { NoZeroDivisors.to_isCancelMulZero α, h with .. } instance (priority := 100) IsDomain.to_noZeroDivisors [Semiring α] [IsDomain α] : NoZeroDivisors α := IsRightCancelMulZero.to_noZeroDivisors α instance Subsingleton.to_isCancelMulZero [Mul α] [Zero α] [Subsingleton α] : IsCancelMulZero α where mul_right_cancel_of_ne_zero hb := (hb <| Subsingleton.eq_zero _).elim mul_left_cancel_of_ne_zero hb := (hb <| Subsingleton.eq_zero _).elim -- This was previously a global instance, -- but it has been implicated in slow typeclass resolutions, -- so we scope it to the `Subsingleton` namespace. lemma Subsingleton.to_noZeroDivisors [Mul α] [Zero α] [Subsingleton α] : NoZeroDivisors α where eq_zero_or_eq_zero_of_mul_eq_zero _ := .inl (Subsingleton.eq_zero _) scoped[Subsingleton] attribute [instance] Subsingleton.to_noZeroDivisors lemma isDomain_iff_cancelMulZero_and_nontrivial [Semiring α] : IsDomain α ↔ IsCancelMulZero α ∧ Nontrivial α := ⟨fun _ ↦ ⟨inferInstance, inferInstance⟩, fun ⟨_, _⟩ ↦ {}⟩ lemma isCancelMulZero_iff_isDomain_or_subsingleton [Semiring α] : IsCancelMulZero α ↔ IsDomain α ∨ Subsingleton α := by refine ⟨fun t ↦ ?_, fun h ↦ h.elim (fun _ ↦ inferInstance) (fun _ ↦ inferInstance)⟩ rw [or_iff_not_imp_right, not_subsingleton_iff_nontrivial] exact fun _ ↦ {} lemma isDomain_iff_noZeroDivisors_and_nontrivial [Ring α] : IsDomain α ↔ NoZeroDivisors α ∧ Nontrivial α := by rw [← isCancelMulZero_iff_noZeroDivisors, isDomain_iff_cancelMulZero_and_nontrivial] lemma noZeroDivisors_iff_isDomain_or_subsingleton [Ring α] : NoZeroDivisors α ↔ IsDomain α ∨ Subsingleton α := by rw [← isCancelMulZero_iff_noZeroDivisors, isCancelMulZero_iff_isDomain_or_subsingleton] end NoZeroDivisors section DivisionMonoid variable [DivisionMonoid R] [HasDistribNeg R] {a b : R} lemma one_div_neg_one_eq_neg_one : (1 : R) / -1 = -1 := have : -1 * -1 = (1 : R) := by rw [neg_mul_neg, one_mul] Eq.symm (eq_one_div_of_mul_eq_one_right this) lemma one_div_neg_eq_neg_one_div (a : R) : 1 / -a = -(1 / a) := calc 1 / -a = 1 / (-1 * a) := by rw [neg_eq_neg_one_mul] _ = 1 / a * (1 / -1) := by rw [one_div_mul_one_div_rev] _ = 1 / a * -1 := by rw [one_div_neg_one_eq_neg_one] _ = -(1 / a) := by rw [mul_neg, mul_one] lemma div_neg_eq_neg_div (a b : R) : b / -a = -(b / a) := calc b / -a = b * (1 / -a) := by rw [← inv_eq_one_div, division_def] _ = b * -(1 / a) := by rw [one_div_neg_eq_neg_one_div] _ = -(b * (1 / a)) := by rw [neg_mul_eq_mul_neg] _ = -(b / a) := by rw [mul_one_div] lemma neg_div (a b : R) : -b / a = -(b / a) := by rw [neg_eq_neg_one_mul, mul_div_assoc, ← neg_eq_neg_one_mul] lemma neg_div' (a b : R) : -(b / a) = -b / a := by rw [neg_div] @[simp] lemma neg_div_neg_eq (a b : R) : -a / -b = a / b := by rw [div_neg_eq_neg_div, neg_div, neg_neg] lemma neg_inv : -a⁻¹ = (-a)⁻¹ := by rw [inv_eq_one_div, inv_eq_one_div, div_neg_eq_neg_div] lemma div_neg (a : R) : a / -b = -(a / b) := by rw [← div_neg_eq_neg_div] lemma div_neg_eq_neg_div' (a : R) : a / -b = -a / b := neg_div b a ▸ div_neg _ @[simp] lemma inv_neg : (-a)⁻¹ = -a⁻¹ := by rw [neg_inv] @[deprecated (since := "2025-04-24")] alias inv_neg' := inv_neg lemma inv_neg_one : (-1 : R)⁻¹ = -1 := by rw [← neg_inv, inv_one] end DivisionMonoid
.lake/packages/mathlib/Mathlib/Algebra/Ring/ULift.lean
import Mathlib.Algebra.Group.ULift import Mathlib.Algebra.Ring.Equiv import Mathlib.Data.Int.Cast.Basic /-! # `ULift` instances for ring This file defines instances for ring, semiring and related structures on `ULift` types. (Recall `ULift R` is just a "copy" of a type `R` in a higher universe.) We also provide `ULift.ringEquiv : ULift R ≃+* R`. -/ universe u variable {R : Type u} namespace ULift instance mulZeroClass {M₀ : Type*} [MulZeroClass M₀] : MulZeroClass (ULift M₀) where zero_mul _ := (Equiv.ulift).injective (by simp) mul_zero _ := (Equiv.ulift).injective (by simp) instance distrib [Distrib R] : Distrib (ULift R) where left_distrib _ _ _ := (Equiv.ulift).injective (by simp [left_distrib]) right_distrib _ _ _ := (Equiv.ulift).injective (by simp [right_distrib]) instance instNatCast [NatCast R] : NatCast (ULift R) := ⟨(up ·)⟩ instance instIntCast [IntCast R] : IntCast (ULift R) := ⟨(up ·)⟩ @[simp, norm_cast] theorem up_natCast [NatCast R] (n : ℕ) : up (n : R) = n := rfl @[simp] theorem up_ofNat [NatCast R] (n : ℕ) [n.AtLeastTwo] : up (ofNat(n) : R) = ofNat(n) := rfl @[simp, norm_cast] theorem up_intCast [IntCast R] (n : ℤ) : up (n : R) = n := rfl @[simp, norm_cast] theorem down_natCast [NatCast R] (n : ℕ) : down (n : ULift R) = n := rfl @[simp] theorem down_ofNat [NatCast R] (n : ℕ) [n.AtLeastTwo] : down (ofNat(n) : ULift R) = ofNat(n) := rfl @[simp, norm_cast] theorem down_intCast [IntCast R] (n : ℤ) : down (n : ULift R) = n := rfl instance addMonoidWithOne [AddMonoidWithOne R] : AddMonoidWithOne (ULift R) where natCast_zero := congr_arg ULift.up Nat.cast_zero natCast_succ _ := congr_arg ULift.up (Nat.cast_succ _) instance addCommMonoidWithOne [AddCommMonoidWithOne R] : AddCommMonoidWithOne (ULift R) where instance addGroupWithOne [AddGroupWithOne R] : AddGroupWithOne (ULift R) where intCast_ofNat _ := congr_arg ULift.up (Int.cast_natCast _) intCast_negSucc _ := congr_arg ULift.up (Int.cast_negSucc _) instance addCommGroupWithOne [AddCommGroupWithOne R] : AddCommGroupWithOne (ULift R) where instance nonUnitalNonAssocSemiring [NonUnitalNonAssocSemiring R] : NonUnitalNonAssocSemiring (ULift R) where instance nonAssocSemiring [NonAssocSemiring R] : NonAssocSemiring (ULift R) where instance nonUnitalSemiring [NonUnitalSemiring R] : NonUnitalSemiring (ULift R) where instance semiring [Semiring R] : Semiring (ULift R) where /-- The ring equivalence between `ULift R` and `R`. -/ def ringEquiv [NonUnitalNonAssocSemiring R] : ULift R ≃+* R where toFun := ULift.down invFun := ULift.up map_mul' _ _ := rfl map_add' _ _ := rfl left_inv _ := rfl right_inv _ := rfl instance nonUnitalCommSemiring [NonUnitalCommSemiring R] : NonUnitalCommSemiring (ULift R) where instance commSemiring [CommSemiring R] : CommSemiring (ULift R) where instance nonUnitalNonAssocRing [NonUnitalNonAssocRing R] : NonUnitalNonAssocRing (ULift R) where instance nonUnitalRing [NonUnitalRing R] : NonUnitalRing (ULift R) where instance nonAssocRing [NonAssocRing R] : NonAssocRing (ULift R) where instance ring [Ring R] : Ring (ULift R) where instance nonUnitalCommRing [NonUnitalCommRing R] : NonUnitalCommRing (ULift R) where instance commRing [CommRing R] : CommRing (ULift R) where end ULift
.lake/packages/mathlib/Mathlib/Algebra/Ring/Ext.lean
import Mathlib.Algebra.Ring.Defs import Mathlib.Algebra.Group.Ext /-! # Extensionality lemmas for rings and similar structures In this file we prove extensionality lemmas for the ring-like structures defined in `Mathlib/Algebra/Ring/Defs.lean`, ranging from `NonUnitalNonAssocSemiring` to `CommRing`. These extensionality lemmas take the form of asserting that two algebraic structures on a type are equal whenever the addition and multiplication defined by them are both the same. ## Implementation details We follow `Mathlib/Algebra/Group/Ext.lean` in using the term `(letI := i; HMul.hMul : R → R → R)` to refer to the multiplication specified by a typeclass instance `i` on a type `R` (and similarly for addition). We abbreviate these using some local notations. Since `Mathlib/Algebra/Group/Ext.lean` proved several injectivity lemmas, we do so as well — even if sometimes we don't need them to prove extensionality. ## Tags semiring, ring, extensionality -/ local macro:max "local_hAdd[" type:term ", " inst:term "]" : term => `(term| (letI := $inst; HAdd.hAdd : $type → $type → $type)) local macro:max "local_hMul[" type:term ", " inst:term "]" : term => `(term| (letI := $inst; HMul.hMul : $type → $type → $type)) universe u variable {R : Type u} /-! ### Distrib -/ namespace Distrib @[ext] theorem ext ⦃inst₁ inst₂ : Distrib R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := by -- Split into `add` and `mul` functions and properties. rcases inst₁ with @⟨⟨⟩, ⟨⟩⟩ rcases inst₂ with @⟨⟨⟩, ⟨⟩⟩ -- Prove equality of parts using function extensionality. congr end Distrib /-! ### NonUnitalNonAssocSemiring -/ namespace NonUnitalNonAssocSemiring @[ext] theorem ext ⦃inst₁ inst₂ : NonUnitalNonAssocSemiring R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := by -- Split into `AddMonoid` instance, `mul` function and properties. rcases inst₁ with @⟨_, ⟨⟩⟩ rcases inst₂ with @⟨_, ⟨⟩⟩ -- Prove equality of parts using already-proved extensionality lemmas. congr; ext : 1; assumption theorem toDistrib_injective : Function.Injective (@toDistrib R) := by intro _ _ h ext x y · exact congrArg (·.toAdd.add x y) h · exact congrArg (·.toMul.mul x y) h end NonUnitalNonAssocSemiring /-! ### NonUnitalSemiring -/ namespace NonUnitalSemiring theorem toNonUnitalNonAssocSemiring_injective : Function.Injective (@toNonUnitalNonAssocSemiring R) := by rintro ⟨⟩ ⟨⟩ _; congr @[ext] theorem ext ⦃inst₁ inst₂ : NonUnitalSemiring R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := toNonUnitalNonAssocSemiring_injective <| NonUnitalNonAssocSemiring.ext h_add h_mul end NonUnitalSemiring /-! ### NonAssocSemiring and its ancestors This section also includes results for `AddMonoidWithOne`, `AddCommMonoidWithOne`, etc. as these are considered implementation detail of the ring classes. TODO consider relocating these lemmas. -/ /- TODO consider relocating these lemmas. -/ @[ext] theorem AddMonoidWithOne.ext ⦃inst₁ inst₂ : AddMonoidWithOne R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_one : (letI := inst₁; One.one : R) = (letI := inst₂; One.one : R)) : inst₁ = inst₂ := by have h_monoid : inst₁.toAddMonoid = inst₂.toAddMonoid := by ext : 1; exact h_add have h_zero' : inst₁.toZero = inst₂.toZero := congrArg (·.toZero) h_monoid have h_one' : inst₁.toOne = inst₂.toOne := congrArg One.mk h_one have h_natCast : inst₁.toNatCast.natCast = inst₂.toNatCast.natCast := by funext n; induction n with | zero => rewrite [inst₁.natCast_zero, inst₂.natCast_zero] exact congrArg (@Zero.zero R) h_zero' | succ n h => rw [inst₁.natCast_succ, inst₂.natCast_succ, h_add] exact congrArg₂ _ h h_one rcases inst₁ with @⟨⟨⟩⟩; rcases inst₂ with @⟨⟨⟩⟩ congr theorem AddCommMonoidWithOne.toAddMonoidWithOne_injective : Function.Injective (@AddCommMonoidWithOne.toAddMonoidWithOne R) := by rintro ⟨⟩ ⟨⟩ _; congr @[ext] theorem AddCommMonoidWithOne.ext ⦃inst₁ inst₂ : AddCommMonoidWithOne R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_one : (letI := inst₁; One.one : R) = (letI := inst₂; One.one : R)) : inst₁ = inst₂ := AddCommMonoidWithOne.toAddMonoidWithOne_injective <| AddMonoidWithOne.ext h_add h_one namespace NonAssocSemiring /- The best place to prove that the `NatCast` is determined by the other operations is probably in an extensionality lemma for `AddMonoidWithOne`, in which case we may as well do the typeclasses defined in `Mathlib/Algebra/GroupWithZero/Defs.lean` as well. -/ @[ext] theorem ext ⦃inst₁ inst₂ : NonAssocSemiring R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := by have h : inst₁.toNonUnitalNonAssocSemiring = inst₂.toNonUnitalNonAssocSemiring := by ext : 1 <;> assumption have h_zero : (inst₁.toMulZeroClass).toZero.zero = (inst₂.toMulZeroClass).toZero.zero := congrArg (fun inst => (inst.toMulZeroClass).toZero.zero) h have h_one' : (inst₁.toMulZeroOneClass).toMulOneClass.toOne = (inst₂.toMulZeroOneClass).toMulOneClass.toOne := by congr 2; ext : 1; exact h_mul have h_one : (inst₁.toMulZeroOneClass).toMulOneClass.toOne.one = (inst₂.toMulZeroOneClass).toMulOneClass.toOne.one := congrArg (@One.one R) h_one' have : inst₁.toAddCommMonoidWithOne = inst₂.toAddCommMonoidWithOne := by ext : 1 <;> assumption have : inst₁.toNatCast = inst₂.toNatCast := congrArg (·.toNatCast) this -- Split into `NonUnitalNonAssocSemiring`, `One` and `natCast` instances. cases inst₁; cases inst₂ congr theorem toNonUnitalNonAssocSemiring_injective : Function.Injective (@toNonUnitalNonAssocSemiring R) := by intro _ _ _ ext <;> congr end NonAssocSemiring /-! ### NonUnitalNonAssocRing -/ namespace NonUnitalNonAssocRing @[ext] theorem ext ⦃inst₁ inst₂ : NonUnitalNonAssocRing R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := by -- Split into `AddCommGroup` instance, `mul` function and properties. rcases inst₁ with @⟨_, ⟨⟩⟩; rcases inst₂ with @⟨_, ⟨⟩⟩ congr; (ext : 1; assumption) theorem toNonUnitalNonAssocSemiring_injective : Function.Injective (@toNonUnitalNonAssocSemiring R) := by intro _ _ h -- Use above extensionality lemma to prove injectivity by showing that `h_add` and `h_mul` hold. ext x y · exact congrArg (·.toAdd.add x y) h · exact congrArg (·.toMul.mul x y) h end NonUnitalNonAssocRing /-! ### NonUnitalRing -/ namespace NonUnitalRing @[ext] theorem ext ⦃inst₁ inst₂ : NonUnitalRing R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := by have : inst₁.toNonUnitalNonAssocRing = inst₂.toNonUnitalNonAssocRing := by ext : 1 <;> assumption -- Split into fields and prove they are equal using the above. cases inst₁; cases inst₂ congr theorem toNonUnitalSemiring_injective : Function.Injective (@toNonUnitalSemiring R) := by intro _ _ h ext x y · exact congrArg (·.toAdd.add x y) h · exact congrArg (·.toMul.mul x y) h theorem toNonUnitalNonAssocring_injective : Function.Injective (@toNonUnitalNonAssocRing R) := by intro _ _ _ ext <;> congr end NonUnitalRing /-! ### NonAssocRing and its ancestors This section also includes results for `AddGroupWithOne`, `AddCommGroupWithOne`, etc. as these are considered implementation detail of the ring classes. TODO consider relocating these lemmas. -/ @[ext] theorem AddGroupWithOne.ext ⦃inst₁ inst₂ : AddGroupWithOne R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_one : (letI := inst₁; One.one : R) = (letI := inst₂; One.one)) : inst₁ = inst₂ := by have : inst₁.toAddMonoidWithOne = inst₂.toAddMonoidWithOne := AddMonoidWithOne.ext h_add h_one have : inst₁.toNatCast = inst₂.toNatCast := congrArg (·.toNatCast) this have h_group : inst₁.toAddGroup = inst₂.toAddGroup := by ext : 1; exact h_add -- Extract equality of necessary substructures from h_group injection h_group with h_group; injection h_group have : inst₁.toIntCast.intCast = inst₂.toIntCast.intCast := by funext n; cases n with | ofNat n => rewrite [Int.ofNat_eq_coe, inst₁.intCast_ofNat, inst₂.intCast_ofNat]; congr | negSucc n => rewrite [inst₁.intCast_negSucc, inst₂.intCast_negSucc]; congr rcases inst₁ with @⟨⟨⟩⟩; rcases inst₂ with @⟨⟨⟩⟩ congr @[ext] theorem AddCommGroupWithOne.ext ⦃inst₁ inst₂ : AddCommGroupWithOne R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_one : (letI := inst₁; One.one : R) = (letI := inst₂; One.one)) : inst₁ = inst₂ := by have : inst₁.toAddCommGroup = inst₂.toAddCommGroup := AddCommGroup.ext h_add have : inst₁.toAddGroupWithOne = inst₂.toAddGroupWithOne := AddGroupWithOne.ext h_add h_one injection this with _ h_addMonoidWithOne; injection h_addMonoidWithOne cases inst₁; cases inst₂ congr namespace NonAssocRing @[ext] theorem ext ⦃inst₁ inst₂ : NonAssocRing R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := by have h₁ : inst₁.toNonUnitalNonAssocRing = inst₂.toNonUnitalNonAssocRing := by ext : 1 <;> assumption have h₂ : inst₁.toNonAssocSemiring = inst₂.toNonAssocSemiring := by ext : 1 <;> assumption -- Mathematically non-trivial fact: `intCast` is determined by the rest. have h₃ : inst₁.toAddCommGroupWithOne = inst₂.toAddCommGroupWithOne := AddCommGroupWithOne.ext h_add (congrArg (·.toOne.one) h₂) cases inst₁; cases inst₂ congr <;> solve | injection h₁ | injection h₂ | injection h₃ theorem toNonAssocSemiring_injective : Function.Injective (@toNonAssocSemiring R) := by intro _ _ h ext x y · exact congrArg (·.toAdd.add x y) h · exact congrArg (·.toMul.mul x y) h theorem toNonUnitalNonAssocring_injective : Function.Injective (@toNonUnitalNonAssocRing R) := by intro _ _ _ ext <;> congr end NonAssocRing /-! ### Semiring -/ namespace Semiring @[ext] theorem ext ⦃inst₁ inst₂ : Semiring R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := by -- Show that enough substructures are equal. have h₁ : inst₁.toNonUnitalSemiring = inst₂.toNonUnitalSemiring := by ext : 1 <;> assumption have h₂ : inst₁.toNonAssocSemiring = inst₂.toNonAssocSemiring := by ext : 1 <;> assumption have h₃ : (inst₁.toMonoidWithZero).toMonoid = (inst₂.toMonoidWithZero).toMonoid := by ext : 1; exact h_mul -- Split into fields and prove they are equal using the above. cases inst₁; cases inst₂ congr <;> solve | injection h₁ | injection h₂ | injection h₃ theorem toNonUnitalSemiring_injective : Function.Injective (@toNonUnitalSemiring R) := by intro _ _ h ext x y · exact congrArg (·.toAdd.add x y) h · exact congrArg (·.toMul.mul x y) h theorem toNonAssocSemiring_injective : Function.Injective (@toNonAssocSemiring R) := by intro _ _ h ext x y · exact congrArg (·.toAdd.add x y) h · exact congrArg (·.toMul.mul x y) h end Semiring /-! ### Ring -/ namespace Ring @[ext] theorem ext ⦃inst₁ inst₂ : Ring R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := by -- Show that enough substructures are equal. have h₁ : inst₁.toSemiring = inst₂.toSemiring := by ext : 1 <;> assumption have h₂ : inst₁.toNonAssocRing = inst₂.toNonAssocRing := by ext : 1 <;> assumption /- We prove that the `SubNegMonoid`s are equal because they are one field away from `Sub` and `Neg`, enabling use of `injection`. -/ have h₃ : (inst₁.toAddCommGroup).toAddGroup.toSubNegMonoid = (inst₂.toAddCommGroup).toAddGroup.toSubNegMonoid := congrArg (@AddGroup.toSubNegMonoid R) <| by ext : 1; exact h_add -- Split into fields and prove they are equal using the above. cases inst₁; cases inst₂ congr <;> solve | injection h₂ | injection h₃ theorem toNonUnitalRing_injective : Function.Injective (@toNonUnitalRing R) := by intro _ _ h ext x y · exact congrArg (·.toAdd.add x y) h · exact congrArg (·.toMul.mul x y) h theorem toNonAssocRing_injective : Function.Injective (@toNonAssocRing R) := by intro _ _ _ ext <;> congr theorem toSemiring_injective : Function.Injective (@toSemiring R) := by intro _ _ h ext x y · exact congrArg (·.toAdd.add x y) h · exact congrArg (·.toMul.mul x y) h end Ring /-! ### NonUnitalNonAssocCommSemiring -/ namespace NonUnitalNonAssocCommSemiring theorem toNonUnitalNonAssocSemiring_injective : Function.Injective (@toNonUnitalNonAssocSemiring R) := by rintro ⟨⟩ ⟨⟩ _; congr @[ext] theorem ext ⦃inst₁ inst₂ : NonUnitalNonAssocCommSemiring R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := toNonUnitalNonAssocSemiring_injective <| NonUnitalNonAssocSemiring.ext h_add h_mul end NonUnitalNonAssocCommSemiring /-! ### NonUnitalCommSemiring -/ namespace NonUnitalCommSemiring theorem toNonUnitalSemiring_injective : Function.Injective (@toNonUnitalSemiring R) := by rintro ⟨⟩ ⟨⟩ _; congr @[ext] theorem ext ⦃inst₁ inst₂ : NonUnitalCommSemiring R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := toNonUnitalSemiring_injective <| NonUnitalSemiring.ext h_add h_mul end NonUnitalCommSemiring -- At present, there is no `NonAssocCommSemiring` in Mathlib. /-! ### NonUnitalNonAssocCommRing -/ namespace NonUnitalNonAssocCommRing theorem toNonUnitalNonAssocRing_injective : Function.Injective (@toNonUnitalNonAssocRing R) := by rintro ⟨⟩ ⟨⟩ _; congr @[ext] theorem ext ⦃inst₁ inst₂ : NonUnitalNonAssocCommRing R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := toNonUnitalNonAssocRing_injective <| NonUnitalNonAssocRing.ext h_add h_mul end NonUnitalNonAssocCommRing /-! ### NonUnitalCommRing -/ namespace NonUnitalCommRing theorem toNonUnitalRing_injective : Function.Injective (@toNonUnitalRing R) := by rintro ⟨⟩ ⟨⟩ _; congr @[ext] theorem ext ⦃inst₁ inst₂ : NonUnitalCommRing R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := toNonUnitalRing_injective <| NonUnitalRing.ext h_add h_mul end NonUnitalCommRing -- At present, there is no `NonAssocCommRing` in Mathlib. /-! ### CommSemiring -/ namespace CommSemiring theorem toSemiring_injective : Function.Injective (@toSemiring R) := by rintro ⟨⟩ ⟨⟩ _; congr @[ext] theorem ext ⦃inst₁ inst₂ : CommSemiring R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := toSemiring_injective <| Semiring.ext h_add h_mul end CommSemiring /-! ### CommRing -/ namespace CommRing theorem toRing_injective : Function.Injective (@toRing R) := by rintro ⟨⟩ ⟨⟩ _; congr @[ext] theorem ext ⦃inst₁ inst₂ : CommRing R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := toRing_injective <| Ring.ext h_add h_mul end CommRing
.lake/packages/mathlib/Mathlib/Algebra/Ring/InjSurj.lean
import Mathlib.Algebra.Ring.Defs import Mathlib.Algebra.Opposites import Mathlib.Algebra.GroupWithZero.InjSurj import Mathlib.Data.Int.Cast.Basic /-! # Pulling back rings along injective maps, and pushing them forward along surjective maps ## Implementation note The `nsmul` and `zsmul` assumptions on any transfer definition for an algebraic structure involving both addition and multiplication (e.g. `AddMonoidWithOne`) is `∀ n x, f (n • x) = n • f x`, which is what we would expect. However, we cannot do the same for transfer definitions built using `to_additive` (e.g. `AddMonoid`) as we want the multiplicative versions to be `∀ x n, f (x ^ n) = f x ^ n`. As a result, we must use `Function.swap` when using additivised transfer definitions in non-additivised ones. -/ variable {R S : Type*} namespace Function.Injective variable (f : S → R) (hf : Injective f) include hf variable [Add S] [Mul S] /-- Pullback a `LeftDistribClass` instance along an injective function. -/ theorem leftDistribClass [Mul R] [Add R] [LeftDistribClass R] (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) : LeftDistribClass S where left_distrib x y z := hf <| by simp only [*, left_distrib] /-- Pullback a `RightDistribClass` instance along an injective function. -/ theorem rightDistribClass [Mul R] [Add R] [RightDistribClass R] (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) : RightDistribClass S where right_distrib x y z := hf <| by simp only [*, right_distrib] variable [Zero S] [One S] [Neg S] [Sub S] [SMul ℕ S] [SMul ℤ S] [Pow S ℕ] [NatCast S] [IntCast S] /-- Pullback a `Distrib` instance along an injective function. -/ -- See note [reducible non-instances] protected abbrev distrib [Distrib R] (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) : Distrib S where __ := hf.leftDistribClass f add mul __ := hf.rightDistribClass f add mul /-- A type endowed with `-` and `*` has distributive negation, if it admits an injective map that preserves `-` and `*` to a type which has distributive negation. -/ -- -- See note [reducible non-instances] protected abbrev hasDistribNeg (f : S → R) (hf : Injective f) [Mul R] [HasDistribNeg R] (neg : ∀ a, f (-a) = -f a) (mul : ∀ a b, f (a * b) = f a * f b) : HasDistribNeg S := { hf.involutiveNeg _ neg, ‹Mul S› with neg_mul := fun x y => hf <| by rw [neg, mul, neg, neg_mul, mul], mul_neg := fun x y => hf <| by rw [neg, mul, neg, mul_neg, mul] } /-- A type endowed with `0`, `1` and `+` is an additive monoid with one, if it admits an injective map that preserves `0`, `1` and `+` to an additive monoid with one. See note [reducible non-instances]. -/ protected abbrev addMonoidWithOne [Zero S] [One S] [Add S] [SMul ℕ S] [NatCast S] [AddMonoidWithOne R] (f : S → R) (hf : Injective f) (zero : f 0 = 0) (one : f 1 = 1) (add : ∀ x y, f (x + y) = f x + f y) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (natCast : ∀ n : ℕ, f n = n) : AddMonoidWithOne S := { hf.addMonoid f zero add (swap nsmul) with natCast := Nat.cast, natCast_zero := hf (by rw [natCast, Nat.cast_zero, zero]), natCast_succ := fun n => hf (by rw [natCast, Nat.cast_succ, add, one, natCast]) } /-- A type endowed with `0`, `1` and `+` is an additive commutative monoid with one, if it admits an injective map that preserves `0`, `1` and `+` to an additive commutative monoid with one. See note [reducible non-instances]. -/ protected abbrev addCommMonoidWithOne {S} [Zero S] [One S] [Add S] [SMul ℕ S] [NatCast S] [AddCommMonoidWithOne R] (f : S → R) (hf : Injective f) (zero : f 0 = 0) (one : f 1 = 1) (add : ∀ x y, f (x + y) = f x + f y) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (natCast : ∀ n : ℕ, f n = n) : AddCommMonoidWithOne S where __ := hf.addMonoidWithOne f zero one add nsmul natCast __ := hf.addCommMonoid _ zero add (swap nsmul) /-- A type endowed with `0`, `1` and `+` is an additive group with one, if it admits an injective map that preserves `0`, `1` and `+` to an additive group with one. See note [reducible non-instances]. -/ protected abbrev addGroupWithOne {S} [Zero S] [One S] [Add S] [SMul ℕ S] [Neg S] [Sub S] [SMul ℤ S] [NatCast S] [IntCast S] [AddGroupWithOne R] (f : S → R) (hf : Injective f) (zero : f 0 = 0) (one : f 1 = 1) (add : ∀ 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) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (zsmul : ∀ (n : ℤ) (x), f (n • x) = n • f x) (natCast : ∀ n : ℕ, f n = n) (intCast : ∀ n : ℤ, f n = n) : AddGroupWithOne S := { hf.addGroup f zero add neg sub (swap nsmul) (swap zsmul), hf.addMonoidWithOne f zero one add nsmul natCast with intCast := Int.cast, intCast_ofNat := fun n => hf (by rw [natCast, intCast, Int.cast_natCast]), intCast_negSucc := fun n => hf (by rw [intCast, neg, natCast, Int.cast_negSucc] ) } /-- A type endowed with `0`, `1` and `+` is an additive commutative group with one, if it admits an injective map that preserves `0`, `1` and `+` to an additive commutative group with one. See note [reducible non-instances]. -/ protected abbrev addCommGroupWithOne {S} [Zero S] [One S] [Add S] [SMul ℕ S] [Neg S] [Sub S] [SMul ℤ S] [NatCast S] [IntCast S] [AddCommGroupWithOne R] (f : S → R) (hf : Injective f) (zero : f 0 = 0) (one : f 1 = 1) (add : ∀ 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) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (zsmul : ∀ (n : ℤ) (x), f (n • x) = n • f x) (natCast : ∀ n : ℕ, f n = n) (intCast : ∀ n : ℤ, f n = n) : AddCommGroupWithOne S := { hf.addGroupWithOne f zero one add neg sub nsmul zsmul natCast intCast, hf.addCommMonoid _ zero add (swap nsmul) with } /-- Pullback a `NonUnitalNonAssocSemiring` instance along an injective function. -/ -- See note [reducible non-instances] protected abbrev nonUnitalNonAssocSemiring [NonUnitalNonAssocSemiring R] (zero : f 0 = 0) (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) : NonUnitalNonAssocSemiring S where toAddCommMonoid := hf.addCommMonoid f zero add (swap nsmul) __ := hf.distrib f add mul __ := hf.mulZeroClass f zero mul /-- Pullback a `NonUnitalSemiring` instance along an injective function. -/ -- See note [reducible non-instances] protected abbrev nonUnitalSemiring [NonUnitalSemiring R] (zero : f 0 = 0) (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) : NonUnitalSemiring S where toNonUnitalNonAssocSemiring := hf.nonUnitalNonAssocSemiring f zero add mul nsmul __ := hf.semigroupWithZero f zero mul /-- Pullback a `NonAssocSemiring` instance along an injective function. -/ -- See note [reducible non-instances] protected abbrev nonAssocSemiring [NonAssocSemiring R] (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) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (natCast : ∀ n : ℕ, f n = n) : NonAssocSemiring S where toNonUnitalNonAssocSemiring := hf.nonUnitalNonAssocSemiring f zero add mul nsmul __ := hf.mulZeroOneClass f zero one mul __ := hf.addMonoidWithOne f zero one add nsmul natCast /-- Pullback a `Semiring` instance along an injective function. -/ -- See note [reducible non-instances] protected abbrev semiring [Semiring R] (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) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) (natCast : ∀ n : ℕ, f n = n) : Semiring S where toNonUnitalSemiring := hf.nonUnitalSemiring f zero add mul nsmul __ := hf.nonAssocSemiring f zero one add mul nsmul natCast __ := hf.monoidWithZero f zero one mul npow /-- Pullback a `NonUnitalNonAssocRing` instance along an injective function. -/ -- See note [reducible non-instances] protected abbrev nonUnitalNonAssocRing [NonUnitalNonAssocRing R] (f : S → R) (hf : Injective f) (zero : f 0 = 0) (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) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (zsmul : ∀ (n : ℤ) (x), f (n • x) = n • f x) : NonUnitalNonAssocRing S where toAddCommGroup := hf.addCommGroup f zero add neg sub (swap nsmul) (swap zsmul) __ := hf.nonUnitalNonAssocSemiring f zero add mul nsmul /-- Pullback a `NonUnitalRing` instance along an injective function. -/ -- See note [reducible non-instances] protected abbrev nonUnitalRing [NonUnitalRing R] (zero : f 0 = 0) (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) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (zsmul : ∀ (n : ℤ) (x), f (n • x) = n • f x) : NonUnitalRing S where toNonUnitalNonAssocRing := hf.nonUnitalNonAssocRing f zero add mul neg sub nsmul zsmul __ := hf.nonUnitalSemiring f zero add mul nsmul /-- Pullback a `NonAssocRing` instance along an injective function. -/ -- See note [reducible non-instances] protected abbrev nonAssocRing [NonAssocRing R] (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) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (zsmul : ∀ (n : ℤ) (x), f (n • x) = n • f x) (natCast : ∀ n : ℕ, f n = n) (intCast : ∀ n : ℤ, f n = n) : NonAssocRing S where toNonUnitalNonAssocRing := hf.nonUnitalNonAssocRing f zero add mul neg sub nsmul zsmul __ := hf.nonAssocSemiring f zero one add mul nsmul natCast __ := hf.addCommGroupWithOne f zero one add neg sub nsmul zsmul natCast intCast /-- Pullback a `Ring` instance along an injective function. -/ -- See note [reducible non-instances] protected abbrev ring [Ring R] (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) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (zsmul : ∀ (n : ℤ) (x), f (n • x) = n • f x) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) (natCast : ∀ n : ℕ, f n = n) (intCast : ∀ n : ℤ, f n = n) : Ring S where toSemiring := hf.semiring f zero one add mul nsmul npow natCast -- zsmul included here explicitly to make sure it's picked correctly by `fast_instance%`. zsmul := fun n x ↦ n • x __ := hf.addGroupWithOne f zero one add neg sub nsmul zsmul natCast intCast __ := hf.addCommGroup f zero add neg sub (swap nsmul) (swap zsmul) /-- Pullback a `NonUnitalNonAssocCommSemiring` instance along an injective function. -/ -- See note [reducible non-instances] protected abbrev nonUnitalNonAssocCommSemiring [NonUnitalNonAssocCommSemiring R] (zero : f 0 = 0) (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) : NonUnitalNonAssocCommSemiring S where toNonUnitalNonAssocSemiring := hf.nonUnitalNonAssocSemiring f zero add mul nsmul __ := hf.commMagma f mul /-- Pullback a `NonUnitalCommSemiring` instance along an injective function. -/ -- See note [reducible non-instances] protected abbrev nonUnitalCommSemiring [NonUnitalCommSemiring R] (f : S → R) (hf : Injective f) (zero : f 0 = 0) (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) : NonUnitalCommSemiring S where toNonUnitalSemiring := hf.nonUnitalSemiring f zero add mul nsmul __ := hf.commSemigroup f mul -- `NonAssocCommSemiring` currently doesn't exist /-- Pullback a `CommSemiring` instance along an injective function. -/ -- See note [reducible non-instances] protected abbrev commSemiring [CommSemiring R] (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) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) (natCast : ∀ n : ℕ, f n = n) : CommSemiring S where toSemiring := hf.semiring f zero one add mul nsmul npow natCast __ := hf.commSemigroup f mul /-- Pullback a `NonUnitalNonAssocCommRing` instance along an injective function. -/ -- See note [reducible non-instances] protected abbrev nonUnitalNonAssocCommRing [NonUnitalNonAssocCommRing R] (f : S → R) (hf : Injective f) (zero : f 0 = 0) (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) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (zsmul : ∀ (n : ℤ) (x), f (n • x) = n • f x) : NonUnitalNonAssocCommRing S where toNonUnitalNonAssocRing := hf.nonUnitalNonAssocRing f zero add mul neg sub nsmul zsmul __ := hf.nonUnitalNonAssocCommSemiring f zero add mul nsmul /-- Pullback a `NonUnitalCommRing` instance along an injective function. -/ -- -- See note [reducible non-instances] protected abbrev nonUnitalCommRing [NonUnitalCommRing R] (f : S → R) (hf : Injective f) (zero : f 0 = 0) (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) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (zsmul : ∀ (n : ℤ) (x), f (n • x) = n • f x) : NonUnitalCommRing S where toNonUnitalRing := hf.nonUnitalRing f zero add mul neg sub nsmul zsmul __ := hf.nonUnitalNonAssocCommRing f zero add mul neg sub nsmul zsmul /-- Pullback a `CommRing` instance along an injective function. -/ -- -- See note [reducible non-instances] protected abbrev commRing [CommRing R] (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) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (zsmul : ∀ (n : ℤ) (x), f (n • x) = n • f x) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) (natCast : ∀ n : ℕ, f n = n) (intCast : ∀ n : ℤ, f n = n) : CommRing S where toRing := hf.ring f zero one add mul neg sub nsmul zsmul npow natCast intCast __ := hf.commMonoid f one mul npow end Function.Injective namespace Function.Surjective variable (f : R → S) (hf : Surjective f) include hf variable [Add S] [Mul S] /-- Pushforward a `LeftDistribClass` instance along a surjective function. -/ theorem leftDistribClass [Mul R] [Add R] [LeftDistribClass R] (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) : LeftDistribClass S where left_distrib := hf.forall₃.2 fun x y z => by simp only [← add, ← mul, left_distrib] /-- Pushforward a `RightDistribClass` instance along a surjective function. -/ theorem rightDistribClass [Mul R] [Add R] [RightDistribClass R] (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) : RightDistribClass S where right_distrib := hf.forall₃.2 fun x y z => by simp only [← add, ← mul, right_distrib] /-- Pushforward a `Distrib` instance along a surjective function. -/ -- See note [reducible non-instances] protected abbrev distrib [Distrib R] (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) : Distrib S where __ := hf.leftDistribClass f add mul __ := hf.rightDistribClass f add mul variable [Zero S] [One S] [Neg S] [Sub S] [SMul ℕ S] [SMul ℤ S] [Pow S ℕ] [NatCast S] [IntCast S] /-- A type endowed with `-` and `*` has distributive negation, if it admits a surjective map that preserves `-` and `*` from a type which has distributive negation. -/ -- See note [reducible non-instances] protected abbrev hasDistribNeg [Mul R] [HasDistribNeg R] (neg : ∀ a, f (-a) = -f a) (mul : ∀ a b, f (a * b) = f a * f b) : HasDistribNeg S := { hf.involutiveNeg _ neg, ‹Mul S› with neg_mul := hf.forall₂.2 fun x y => by rw [← neg, ← mul, neg_mul, neg, mul] mul_neg := hf.forall₂.2 fun x y => by rw [← neg, ← mul, mul_neg, neg, mul] } /-- A type endowed with `0`, `1` and `+` is an additive monoid with one, if it admits a surjective map that preserves `0`, `1` and `*` from an additive monoid with one. See note [reducible non-instances]. -/ protected abbrev addMonoidWithOne [AddMonoidWithOne R] (zero : f 0 = 0) (one : f 1 = 1) (add : ∀ x y, f (x + y) = f x + f y) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (natCast : ∀ n : ℕ, f n = n) : AddMonoidWithOne S := { hf.addMonoid f zero add (swap nsmul) with natCast := Nat.cast, natCast_zero := by rw [← natCast, Nat.cast_zero, zero] natCast_succ := fun n => by rw [← natCast, Nat.cast_succ, add, one, natCast] } /-- A type endowed with `0`, `1` and `+` is an additive monoid with one, if it admits a surjective map that preserves `0`, `1` and `*` from an additive monoid with one. See note [reducible non-instances]. -/ protected abbrev addCommMonoidWithOne [AddCommMonoidWithOne R] (zero : f 0 = 0) (one : f 1 = 1) (add : ∀ x y, f (x + y) = f x + f y) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (natCast : ∀ n : ℕ, f n = n) : AddCommMonoidWithOne S where __ := hf.addMonoidWithOne f zero one add nsmul natCast __ := hf.addCommMonoid _ zero add (swap nsmul) /-- A type endowed with `0`, `1`, `+` is an additive group with one, if it admits a surjective map that preserves `0`, `1`, and `+` to an additive group with one. See note [reducible non-instances]. -/ protected abbrev addGroupWithOne [AddGroupWithOne R] (zero : f 0 = 0) (one : f 1 = 1) (add : ∀ 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) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (zsmul : ∀ (n : ℤ) (x), f (n • x) = n • f x) (natCast : ∀ n : ℕ, f n = n) (intCast : ∀ n : ℤ, f n = n) : AddGroupWithOne S := { hf.addMonoidWithOne f zero one add nsmul natCast, hf.addGroup f zero add neg sub (swap nsmul) (swap zsmul) with intCast := Int.cast, intCast_ofNat := fun n => by rw [← intCast, Int.cast_natCast, natCast], intCast_negSucc := fun n => by rw [← intCast, Int.cast_negSucc, neg, natCast] } /-- A type endowed with `0`, `1`, `+` is an additive commutative group with one, if it admits a surjective map that preserves `0`, `1`, and `+` to an additive commutative group with one. See note [reducible non-instances]. -/ protected abbrev addCommGroupWithOne [AddCommGroupWithOne R] (zero : f 0 = 0) (one : f 1 = 1) (add : ∀ 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) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (zsmul : ∀ (n : ℤ) (x), f (n • x) = n • f x) (natCast : ∀ n : ℕ, f n = n) (intCast : ∀ n : ℤ, f n = n) : AddCommGroupWithOne S := { hf.addGroupWithOne f zero one add neg sub nsmul zsmul natCast intCast, hf.addCommMonoid _ zero add (swap nsmul) with } /-- Pushforward a `NonUnitalNonAssocSemiring` instance along a surjective function. See note [reducible non-instances]. -/ protected abbrev nonUnitalNonAssocSemiring [NonUnitalNonAssocSemiring R] (zero : f 0 = 0) (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) : NonUnitalNonAssocSemiring S where toAddCommMonoid := hf.addCommMonoid f zero add (swap nsmul) __ := hf.distrib f add mul __ := hf.mulZeroClass f zero mul /-- Pushforward a `NonUnitalSemiring` instance along a surjective function. -/ -- See note [reducible non-instances] protected abbrev nonUnitalSemiring [NonUnitalSemiring R] (zero : f 0 = 0) (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) : NonUnitalSemiring S where toNonUnitalNonAssocSemiring := hf.nonUnitalNonAssocSemiring f zero add mul nsmul __ := hf.semigroupWithZero f zero mul /-- Pushforward a `NonAssocSemiring` instance along a surjective function. -/ -- See note [reducible non-instances] protected abbrev nonAssocSemiring [NonAssocSemiring R] (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) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (natCast : ∀ n : ℕ, f n = n) : NonAssocSemiring S where toNonUnitalNonAssocSemiring := hf.nonUnitalNonAssocSemiring f zero add mul nsmul __ := hf.mulZeroOneClass f zero one mul __ := hf.addMonoidWithOne f zero one add nsmul natCast /-- Pushforward a `Semiring` instance along a surjective function. -/ -- See note [reducible non-instances] protected abbrev semiring [Semiring R] (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) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) (natCast : ∀ n : ℕ, f n = n) : Semiring S where toNonUnitalSemiring := hf.nonUnitalSemiring f zero add mul nsmul __ := hf.nonAssocSemiring f zero one add mul nsmul natCast __ := hf.monoidWithZero f zero one mul npow /-- Pushforward a `NonUnitalNonAssocRing` instance along a surjective function. -/ -- See note [reducible non-instances] protected abbrev nonUnitalNonAssocRing [NonUnitalNonAssocRing R] (zero : f 0 = 0) (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) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (zsmul : ∀ (n : ℤ) (x), f (n • x) = n • f x) : NonUnitalNonAssocRing S where toAddCommGroup := hf.addCommGroup f zero add neg sub (swap nsmul) (swap zsmul) __ := hf.nonUnitalNonAssocSemiring f zero add mul nsmul /-- Pushforward a `NonUnitalRing` instance along a surjective function. -/ -- See note [reducible non-instances] protected abbrev nonUnitalRing [NonUnitalRing R] (zero : f 0 = 0) (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) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (zsmul : ∀ (n : ℤ) (x), f (n • x) = n • f x) : NonUnitalRing S where toNonUnitalNonAssocRing := hf.nonUnitalNonAssocRing f zero add mul neg sub nsmul zsmul __ := hf.nonUnitalSemiring f zero add mul nsmul /-- Pushforward a `NonAssocRing` instance along a surjective function. -/ -- See note [reducible non-instances] protected abbrev nonAssocRing [NonAssocRing R] (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) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (zsmul : ∀ (n : ℤ) (x), f (n • x) = n • f x) (natCast : ∀ n : ℕ, f n = n) (intCast : ∀ n : ℤ, f n = n) : NonAssocRing S where toNonUnitalNonAssocRing := hf.nonUnitalNonAssocRing f zero add mul neg sub nsmul zsmul __ := hf.nonAssocSemiring f zero one add mul nsmul natCast __ := hf.addCommGroupWithOne f zero one add neg sub nsmul zsmul natCast intCast /-- Pushforward a `Ring` instance along a surjective function. -/ -- See note [reducible non-instances] protected abbrev ring [Ring R] (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) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (zsmul : ∀ (n : ℤ) (x), f (n • x) = n • f x) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) (natCast : ∀ n : ℕ, f n = n) (intCast : ∀ n : ℤ, f n = n) : Ring S where toSemiring := hf.semiring f zero one add mul nsmul npow natCast __ := hf.addGroupWithOne f zero one add neg sub nsmul zsmul natCast intCast __ := hf.addCommGroup f zero add neg sub (swap nsmul) (swap zsmul) /-- Pushforward a `NonUnitalNonAssocCommSemiring` instance along a surjective function. -/ -- See note [reducible non-instances] protected abbrev nonUnitalNonAssocCommSemiring [NonUnitalNonAssocCommSemiring R] (zero : f 0 = 0) (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) : NonUnitalNonAssocCommSemiring S where toNonUnitalNonAssocSemiring := hf.nonUnitalNonAssocSemiring f zero add mul nsmul __ := hf.commMagma f mul /-- Pushforward a `NonUnitalCommSemiring` instance along a surjective function. -/ -- See note [reducible non-instances] protected abbrev nonUnitalCommSemiring [NonUnitalCommSemiring R] (zero : f 0 = 0) (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) : NonUnitalCommSemiring S where toNonUnitalSemiring := hf.nonUnitalSemiring f zero add mul nsmul __ := hf.commSemigroup f mul /-- Pushforward a `CommSemiring` instance along a surjective function. -/ -- See note [reducible non-instances] protected abbrev commSemiring [CommSemiring R] (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) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) (natCast : ∀ n : ℕ, f n = n) : CommSemiring S where toSemiring := hf.semiring f zero one add mul nsmul npow natCast __ := hf.commSemigroup f mul /-- Pushforward a `NonUnitalNonAssocCommRing` instance along a surjective function. -/ -- See note [reducible non-instances] protected abbrev nonUnitalNonAssocCommRing [NonUnitalNonAssocCommRing R] (zero : f 0 = 0) (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) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (zsmul : ∀ (n : ℤ) (x), f (n • x) = n • f x) : NonUnitalNonAssocCommRing S where toNonUnitalNonAssocRing := hf.nonUnitalNonAssocRing f zero add mul neg sub nsmul zsmul __ := hf.nonUnitalNonAssocCommSemiring f zero add mul nsmul /-- Pushforward a `NonUnitalCommRing` instance along a surjective function. -/ -- See note [reducible non-instances] protected abbrev nonUnitalCommRing [NonUnitalCommRing R] (zero : f 0 = 0) (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) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (zsmul : ∀ (n : ℤ) (x), f (n • x) = n • f x) : NonUnitalCommRing S where toNonUnitalRing := hf.nonUnitalRing f zero add mul neg sub nsmul zsmul __ := hf.nonUnitalNonAssocCommRing f zero add mul neg sub nsmul zsmul /-- Pushforward a `CommRing` instance along a surjective function. -/ -- See note [reducible non-instances] protected abbrev commRing [CommRing R] (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) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (zsmul : ∀ (n : ℤ) (x), f (n • x) = n • f x) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) (natCast : ∀ n : ℕ, f n = n) (intCast : ∀ n : ℤ, f n = n) : CommRing S where toRing := hf.ring f zero one add mul neg sub nsmul zsmul npow natCast intCast __ := hf.commMonoid f one mul npow end Function.Surjective variable [Mul R] [HasDistribNeg R] instance AddOpposite.instHasDistribNeg : HasDistribNeg Rᵃᵒᵖ := unop_injective.hasDistribNeg _ unop_neg unop_mul
.lake/packages/mathlib/Mathlib/Algebra/Ring/Defs.lean
import Mathlib.Algebra.GroupWithZero.Defs import Mathlib.Data.Int.Cast.Defs import Mathlib.Tactic.Spread import Mathlib.Tactic.StacksAttribute /-! # Semirings and rings This file defines semirings, rings and domains. This is analogous to `Mathlib/Algebra/Group/Defs.lean` and `Mathlib/Algebra/Group/Basic.lean`, the difference being that those are about `+` and `*` separately, while the present file is about their interaction. the present file is about their interaction. ## Main definitions * `Distrib`: Typeclass for distributivity of multiplication over addition. * `HasDistribNeg`: Typeclass for commutativity of negation and multiplication. This is useful when dealing with multiplicative submonoids which are closed under negation without being closed under addition, for example `Units`. * `(NonUnital)(NonAssoc)(Semi)Ring`: Typeclasses for possibly non-unital or non-associative rings and semirings. Some combinations are not defined yet because they haven't found use. For Lie Rings, there is a type synonym `CommutatorRing` defined in `Mathlib/Algebra/Algebra/NonUnitalHom.lean` turning the bracket into a multiplication so that the instance `instNonUnitalNonAssocSemiringCommutatorRing` can be defined. ## Tags `Semiring`, `CommSemiring`, `Ring`, `CommRing`, domain, `IsDomain`, nonzero, units -/ /-! Previously an import dependency on `Mathlib/Algebra/Group/Basic.lean` had crept in. In general, the `.Defs` files in the basic algebraic hierarchy should only depend on earlier `.Defs` files, without importing `.Basic` theory development. These `assert_not_exists` statements guard against this returning. -/ assert_not_exists DivisionMonoid.toDivInvOneMonoid mul_rotate universe u v variable {α : Type u} {R : Type v} open Function /-! ### `Distrib` class -/ /-- A typeclass stating that multiplication is left and right distributive over addition. -/ class Distrib (R : Type*) extends Mul R, Add R where /-- Multiplication is left distributive over addition -/ protected left_distrib : ∀ a b c : R, a * (b + c) = a * b + a * c /-- Multiplication is right distributive over addition -/ protected right_distrib : ∀ a b c : R, (a + b) * c = a * c + b * c /-- A typeclass stating that multiplication is left distributive over addition. -/ class LeftDistribClass (R : Type*) [Mul R] [Add R] : Prop where /-- Multiplication is left distributive over addition -/ protected left_distrib : ∀ a b c : R, a * (b + c) = a * b + a * c /-- A typeclass stating that multiplication is right distributive over addition. -/ class RightDistribClass (R : Type*) [Mul R] [Add R] : Prop where /-- Multiplication is right distributive over addition -/ protected right_distrib : ∀ a b c : R, (a + b) * c = a * c + b * c -- see Note [lower instance priority] instance (priority := 100) Distrib.leftDistribClass (R : Type*) [Distrib R] : LeftDistribClass R := ⟨Distrib.left_distrib⟩ -- see Note [lower instance priority] instance (priority := 100) Distrib.rightDistribClass (R : Type*) [Distrib R] : RightDistribClass R := ⟨Distrib.right_distrib⟩ theorem left_distrib [Mul R] [Add R] [LeftDistribClass R] (a b c : R) : a * (b + c) = a * b + a * c := LeftDistribClass.left_distrib a b c alias mul_add := left_distrib theorem right_distrib [Mul R] [Add R] [RightDistribClass R] (a b c : R) : (a + b) * c = a * c + b * c := RightDistribClass.right_distrib a b c alias add_mul := right_distrib theorem distrib_three_right [Mul R] [Add R] [RightDistribClass R] (a b c d : R) : (a + b + c) * d = a * d + b * d + c * d := by simp [right_distrib] /-! ### Classes of semirings and rings We make sure that the canonical path from `NonAssocSemiring` to `Ring` passes through `Semiring`, as this is a path which is followed all the time in linear algebra where the defining semilinear map `σ : R →+* S` depends on the `NonAssocSemiring` structure of `R` and `S` while the module definition depends on the `Semiring` structure. It is not currently possible to adjust priorities by hand (see https://github.com/leanprover/lean4/issues/2115). Instead, the last declared instance is used, so we make sure that `Semiring` is declared after `NonAssocRing`, so that `Semiring -> NonAssocSemiring` is tried before `NonAssocRing -> NonAssocSemiring`. TODO: clean this once https://github.com/leanprover/lean4/issues/2115 is fixed -/ /-- A not-necessarily-unital, not-necessarily-associative semiring. See `CommutatorRing` and the documentation thereof in case you need a `NonUnitalNonAssocSemiring` instance on a Lie ring or a Lie algebra. -/ class NonUnitalNonAssocSemiring (α : Type u) extends AddCommMonoid α, Distrib α, MulZeroClass α /-- An associative but not-necessarily unital semiring. -/ class NonUnitalSemiring (α : Type u) extends NonUnitalNonAssocSemiring α, SemigroupWithZero α /-- A unital but not-necessarily-associative semiring. -/ class NonAssocSemiring (α : Type u) extends NonUnitalNonAssocSemiring α, MulZeroOneClass α, AddCommMonoidWithOne α /-- A not-necessarily-unital, not-necessarily-associative ring. -/ class NonUnitalNonAssocRing (α : Type u) extends AddCommGroup α, NonUnitalNonAssocSemiring α /-- An associative but not-necessarily unital ring. -/ class NonUnitalRing (α : Type*) extends NonUnitalNonAssocRing α, NonUnitalSemiring α /-- A unital but not-necessarily-associative ring. -/ class NonAssocRing (α : Type*) extends NonUnitalNonAssocRing α, NonAssocSemiring α, AddCommGroupWithOne α /-- A `Semiring` is a type with addition, multiplication, a `0` and a `1` where addition is commutative and associative, multiplication is associative and left and right distributive over addition, and `0` and `1` are additive and multiplicative identities. -/ class Semiring (α : Type u) extends NonUnitalSemiring α, NonAssocSemiring α, MonoidWithZero α /-- A `Ring` is a `Semiring` with negation making it an additive group. -/ class Ring (R : Type u) extends Semiring R, AddCommGroup R, AddGroupWithOne R /-! ### Semirings -/ section DistribMulOneClass variable [Add α] [MulOneClass α] theorem add_one_mul [RightDistribClass α] (a b : α) : (a + 1) * b = a * b + b := by rw [add_mul, one_mul] theorem mul_add_one [LeftDistribClass α] (a b : α) : a * (b + 1) = a * b + a := by rw [mul_add, mul_one] theorem one_add_mul [RightDistribClass α] (a b : α) : (1 + a) * b = b + a * b := by rw [add_mul, one_mul] theorem mul_one_add [LeftDistribClass α] (a b : α) : a * (1 + b) = a + a * b := by rw [mul_add, mul_one] end DistribMulOneClass section NonAssocSemiring variable [NonAssocSemiring α] theorem two_mul (n : α) : 2 * n = n + n := (congrArg₂ _ one_add_one_eq_two.symm rfl).trans <| (right_distrib 1 1 n).trans (by rw [one_mul]) theorem mul_two (n : α) : n * 2 = n + n := (congrArg₂ _ rfl one_add_one_eq_two.symm).trans <| (left_distrib n 1 1).trans (by rw [mul_one]) @[simp] lemma nsmul_eq_mul (n : ℕ) (a : α) : n • a = n * a := by induction n with | zero => rw [zero_nsmul, Nat.cast_zero, zero_mul] | succ n ih => rw [succ_nsmul, ih, Nat.cast_succ, add_mul, one_mul] end NonAssocSemiring section MulZeroClass variable [MulZeroClass α] (P Q : Prop) [Decidable P] [Decidable Q] (a b : α) lemma ite_zero_mul : ite P a 0 * b = ite P (a * b) 0 := by simp lemma mul_ite_zero : a * ite P b 0 = ite P (a * b) 0 := by simp lemma ite_zero_mul_ite_zero : ite P a 0 * ite Q b 0 = ite (P ∧ Q) (a * b) 0 := by simp only [← ite_and, ite_mul, mul_ite, mul_zero, zero_mul, and_comm] end MulZeroClass theorem mul_boole {α} [MulZeroOneClass α] (P : Prop) [Decidable P] (a : α) : (a * if P then 1 else 0) = if P then a else 0 := by simp theorem boole_mul {α} [MulZeroOneClass α] (P : Prop) [Decidable P] (a : α) : (if P then 1 else 0) * a = if P then a else 0 := by simp /-- A not-necessarily-unital, not-necessarily-associative, but commutative semiring. -/ class NonUnitalNonAssocCommSemiring (α : Type u) extends NonUnitalNonAssocSemiring α, CommMagma α /-- A non-unital commutative semiring is a `NonUnitalSemiring` with commutative multiplication. In other words, it is a type with the following structures: additive commutative monoid (`AddCommMonoid`), commutative semigroup (`CommSemigroup`), distributive laws (`Distrib`), and multiplication by zero law (`MulZeroClass`). -/ class NonUnitalCommSemiring (α : Type u) extends NonUnitalSemiring α, CommSemigroup α /-- A commutative semiring is a semiring with commutative multiplication. -/ class CommSemiring (R : Type u) extends Semiring R, CommMonoid R -- see Note [lower instance priority] instance (priority := 100) CommSemiring.toNonUnitalCommSemiring [CommSemiring α] : NonUnitalCommSemiring α := { inferInstanceAs (CommMonoid α), inferInstanceAs (CommSemiring α) with } -- see Note [lower instance priority] instance (priority := 100) CommSemiring.toCommMonoidWithZero [CommSemiring α] : CommMonoidWithZero α := { inferInstanceAs (CommMonoid α), inferInstanceAs (CommSemiring α) with } section CommSemiring variable [CommSemiring α] theorem add_mul_self_eq (a b : α) : (a + b) * (a + b) = a * a + 2 * a * b + b * b := by simp only [two_mul, add_mul, mul_add, add_assoc, mul_comm b] lemma add_sq (a b : α) : (a + b) ^ 2 = a ^ 2 + 2 * a * b + b ^ 2 := by simp only [sq, add_mul_self_eq] lemma add_sq' (a b : α) : (a + b) ^ 2 = a ^ 2 + b ^ 2 + 2 * a * b := by rw [add_sq, add_assoc, add_comm _ (b ^ 2), add_assoc] alias add_pow_two := add_sq end CommSemiring section HasDistribNeg /-- Typeclass for a negation operator that distributes across multiplication. This is useful for dealing with submonoids of a ring that contain `-1` without having to duplicate lemmas. -/ class HasDistribNeg (α : Type*) [Mul α] extends InvolutiveNeg α where /-- Negation is left distributive over multiplication -/ neg_mul : ∀ x y : α, -x * y = -(x * y) /-- Negation is right distributive over multiplication -/ mul_neg : ∀ x y : α, x * -y = -(x * y) section Mul variable [Mul α] [HasDistribNeg α] @[simp] theorem neg_mul (a b : α) : -a * b = -(a * b) := HasDistribNeg.neg_mul _ _ @[simp] theorem mul_neg (a b : α) : a * -b = -(a * b) := HasDistribNeg.mul_neg _ _ theorem neg_mul_neg (a b : α) : -a * -b = a * b := by simp theorem neg_mul_eq_neg_mul (a b : α) : -(a * b) = -a * b := (neg_mul _ _).symm theorem neg_mul_eq_mul_neg (a b : α) : -(a * b) = a * -b := (mul_neg _ _).symm theorem neg_mul_comm (a b : α) : -a * b = a * -b := by simp end Mul section MulOneClass variable [MulOneClass α] [HasDistribNeg α] theorem neg_eq_neg_one_mul (a : α) : -a = -1 * a := by simp /-- An element of a ring multiplied by the additive inverse of one is the element's additive inverse. -/ theorem mul_neg_one (a : α) : a * -1 = -a := by simp /-- The additive inverse of one multiplied by an element of a ring is the element's additive inverse. -/ theorem neg_one_mul (a : α) : -1 * a = -a := by simp end MulOneClass section MulZeroClass variable [MulZeroClass α] [HasDistribNeg α] instance (priority := 100) MulZeroClass.negZeroClass : NegZeroClass α where __ := inferInstanceAs (Zero α); __ := inferInstanceAs (InvolutiveNeg α) neg_zero := by rw [← zero_mul (0 : α), ← neg_mul, mul_zero, mul_zero] end MulZeroClass end HasDistribNeg /-! ### Rings -/ section NonUnitalNonAssocRing variable [NonUnitalNonAssocRing α] instance (priority := 100) NonUnitalNonAssocRing.toHasDistribNeg : HasDistribNeg α where neg_neg := neg_neg neg_mul a b := eq_neg_of_add_eq_zero_left <| by rw [← right_distrib, neg_add_cancel, zero_mul] mul_neg a b := eq_neg_of_add_eq_zero_left <| by rw [← left_distrib, neg_add_cancel, mul_zero] theorem mul_sub_left_distrib (a b c : α) : a * (b - c) = a * b - a * c := by simpa only [sub_eq_add_neg, neg_mul_eq_mul_neg] using mul_add a b (-c) alias mul_sub := mul_sub_left_distrib theorem mul_sub_right_distrib (a b c : α) : (a - b) * c = a * c - b * c := by simpa only [sub_eq_add_neg, neg_mul_eq_neg_mul] using add_mul a (-b) c alias sub_mul := mul_sub_right_distrib end NonUnitalNonAssocRing section NonAssocRing variable [NonAssocRing α] theorem sub_one_mul (a b : α) : (a - 1) * b = a * b - b := by rw [sub_mul, one_mul] theorem mul_sub_one (a b : α) : a * (b - 1) = a * b - a := by rw [mul_sub, mul_one] theorem one_sub_mul (a b : α) : (1 - a) * b = b - a * b := by rw [sub_mul, one_mul] theorem mul_one_sub (a b : α) : a * (1 - b) = a - a * b := by rw [mul_sub, mul_one] end NonAssocRing section Ring variable [Ring α] -- A (unital, associative) ring is a not-necessarily-unital ring -- see Note [lower instance priority] instance (priority := 100) Ring.toNonUnitalRing : NonUnitalRing α := { ‹Ring α› with } -- A (unital, associative) ring is a not-necessarily-associative ring -- see Note [lower instance priority] instance (priority := 100) Ring.toNonAssocRing : NonAssocRing α := { ‹Ring α› with } end Ring /-- A non-unital non-associative commutative ring is a `NonUnitalNonAssocRing` with commutative multiplication. -/ class NonUnitalNonAssocCommRing (α : Type u) extends NonUnitalNonAssocRing α, NonUnitalNonAssocCommSemiring α /-- A non-unital commutative ring is a `NonUnitalRing` with commutative multiplication. -/ class NonUnitalCommRing (α : Type u) extends NonUnitalRing α, NonUnitalNonAssocCommRing α -- see Note [lower instance priority] instance (priority := 100) NonUnitalCommRing.toNonUnitalCommSemiring [s : NonUnitalCommRing α] : NonUnitalCommSemiring α := { s with } /-- A commutative ring is a ring with commutative multiplication. -/ class CommRing (α : Type u) extends Ring α, CommMonoid α instance (priority := 100) CommRing.toCommSemiring [s : CommRing α] : CommSemiring α := { s with } -- see Note [lower instance priority] instance (priority := 100) CommRing.toNonUnitalCommRing [s : CommRing α] : NonUnitalCommRing α := { s with } -- see Note [lower instance priority] instance (priority := 100) CommRing.toAddCommGroupWithOne [s : CommRing α] : AddCommGroupWithOne α := { s with } /-- A domain is a nontrivial semiring such that multiplication by a nonzero element is cancellative on both sides. In other words, a nontrivial semiring `R` satisfying `∀ {a b c : R}, a ≠ 0 → a * b = a * c → b = c` and `∀ {a b c : R}, b ≠ 0 → a * b = c * b → a = c`. This is implemented as a mixin for `Semiring α`. To obtain an integral domain use `[CommRing α] [IsDomain α]`. -/ @[stacks 09FE] class IsDomain (α : Type u) [Semiring α] : Prop extends IsCancelMulZero α, Nontrivial α
.lake/packages/mathlib/Mathlib/Algebra/Ring/Shrink.lean
import Mathlib.Algebra.Group.Shrink import Mathlib.Algebra.Ring.TransferInstance /-! # Transfer ring structures from `α` to `Shrink α` -/ noncomputable section namespace Shrink universe v variable {α : Type*} [Small.{v} α] variable (α) in /-- Shrink `α` to a smaller universe preserves ring structure. -/ def ringEquiv [Add α] [Mul α] : Shrink.{v} α ≃+* α := (equivShrink α).symm.ringEquiv instance [NonUnitalNonAssocSemiring α] : NonUnitalNonAssocSemiring (Shrink.{v} α) := (equivShrink α).symm.nonUnitalNonAssocSemiring instance [NonUnitalSemiring α] : NonUnitalSemiring (Shrink.{v} α) := (equivShrink α).symm.nonUnitalSemiring instance [AddMonoidWithOne α] : AddMonoidWithOne (Shrink.{v} α) := (equivShrink α).symm.addMonoidWithOne instance [AddGroupWithOne α] : AddGroupWithOne (Shrink.{v} α) := (equivShrink α).symm.addGroupWithOne instance [NonAssocSemiring α] : NonAssocSemiring (Shrink.{v} α) := (equivShrink α).symm.nonAssocSemiring instance [Semiring α] : Semiring (Shrink.{v} α) := (equivShrink α).symm.semiring instance [NonUnitalCommSemiring α] : NonUnitalCommSemiring (Shrink.{v} α) := (equivShrink α).symm.nonUnitalCommSemiring instance [CommSemiring α] : CommSemiring (Shrink.{v} α) := (equivShrink α).symm.commSemiring instance [NonUnitalNonAssocRing α] : NonUnitalNonAssocRing (Shrink.{v} α) := (equivShrink α).symm.nonUnitalNonAssocRing instance [NonUnitalRing α] : NonUnitalRing (Shrink.{v} α) := (equivShrink α).symm.nonUnitalRing instance [NonAssocRing α] : NonAssocRing (Shrink.{v} α) := (equivShrink α).symm.nonAssocRing instance [Ring α] : Ring (Shrink.{v} α) := (equivShrink α).symm.ring instance [NonUnitalCommRing α] : NonUnitalCommRing (Shrink.{v} α) := (equivShrink α).symm.nonUnitalCommRing instance [CommRing α] : CommRing (Shrink.{v} α) := (equivShrink α).symm.commRing instance [Semiring α] [IsDomain α] : IsDomain (Shrink.{v} α) := (Shrink.ringEquiv α).isDomain end Shrink
.lake/packages/mathlib/Mathlib/Algebra/Ring/Submonoid.lean
import Mathlib.Algebra.Group.Submonoid.Basic import Mathlib.Algebra.Ring.Defs import Mathlib.Tactic.MinImports import Mathlib.Tactic.Linter.DeprecatedModule deprecated_module (since := "2025-04-09")
.lake/packages/mathlib/Mathlib/Algebra/Ring/NonZeroDivisors.lean
import Mathlib.Algebra.GroupWithZero.NonZeroDivisors import Mathlib.Algebra.Regular.Basic import Mathlib.Algebra.Regular.Opposite import Mathlib.Algebra.Ring.Basic /-! # Non-zero divisors in a ring -/ assert_not_exists Field open scoped nonZeroDivisors section Monoid variable {R : Type*} [Monoid R] {r : R} @[to_additive] theorem IsLeftRegular.pow_injective [IsMulTorsionFree R] (hx : IsLeftRegular r) (hx' : r ≠ 1) : Function.Injective (fun n ↦ r ^ n) := by intro n m hnm have main {n m} (h₁ : n ≤ m) (h₂ : r ^ n = r ^ m) : n = m := by obtain ⟨l, rfl⟩ := Nat.exists_eq_add_of_le h₁ rw [pow_add, eq_comm, IsLeftRegular.mul_left_eq_self_iff (hx.pow n), IsMulTorsionFree.pow_eq_one_iff_right hx'] at h₂ rw [h₂, Nat.add_zero] obtain h | h := Nat.le_or_le n m · exact main h hnm · exact (main h hnm.symm).symm @[to_additive] theorem IsRightRegular.pow_injective {M : Type*} [Monoid M] [IsMulTorsionFree M] {x : M} (hx : IsRightRegular x) (hx' : x ≠ 1) : Function.Injective (fun n ↦ x ^ n) := MulOpposite.unop_injective.comp <| (isLeftRegular_op.mpr hx).pow_injective <| (MulOpposite.op_eq_one_iff x).not.mpr hx' theorem IsMulTorsionFree.pow_right_injective {M : Type*} [CancelMonoid M] [IsMulTorsionFree M] {x : M} (hx : x ≠ 1) : Function.Injective (fun n ↦ x ^ n) := IsLeftRegular.pow_injective (IsLeftRegular.all x) hx @[simp] theorem IsMulTorsionFree.pow_right_inj {M : Type*} [CancelMonoid M] [IsMulTorsionFree M] {x : M} (hx : x ≠ 1) {n m : ℕ} : x ^ n = x ^ m ↔ n = m := (pow_right_injective hx).eq_iff theorem IsMulTorsionFree.pow_right_injective₀ {M : Type*} [CancelMonoidWithZero M] [IsMulTorsionFree M] {x : M} (hx : x ≠ 1) (hx' : x ≠ 0) : Function.Injective (fun n ↦ x ^ n) := IsLeftRegular.pow_injective (IsLeftCancelMulZero.mul_left_cancel_of_ne_zero hx') hx @[simp] theorem IsMulTorsionFree.pow_right_inj₀ {M : Type*} [CancelMonoidWithZero M] [IsMulTorsionFree M] {x : M} (hx : x ≠ 1) (hx' : x ≠ 0) {n m : ℕ} : x ^ n = x ^ m ↔ n = m := (pow_right_injective₀ hx hx').eq_iff variable [Finite R] theorem IsLeftRegular.isUnit_of_finite (h : IsLeftRegular r) : IsUnit r := by rwa [IsUnit.isUnit_iff_mulLeft_bijective, ← Finite.injective_iff_bijective] theorem IsRightRegular.isUnit_of_finite (h : IsRightRegular r) : IsUnit r := by rwa [IsUnit.isUnit_iff_mulRight_bijective, ← Finite.injective_iff_bijective] theorem isRegular_iff_isUnit_of_finite : IsRegular r ↔ IsUnit r where mp h := h.1.isUnit_of_finite mpr h := h.isRegular end Monoid section Ring variable {R : Type*} [Ring R] {a x y r : R} lemma isLeftRegular_iff_mem_nonZeroDivisorsLeft : IsLeftRegular r ↔ r ∈ nonZeroDivisorsLeft R := isLeftRegular_iff_right_eq_zero_of_mul lemma isRightRegular_iff_mem_nonZeroDivisorsRight : IsRightRegular r ↔ r ∈ nonZeroDivisorsRight R := isRightRegular_iff_left_eq_zero_of_mul lemma isRegular_iff_mem_nonZeroDivisors : IsRegular r ↔ r ∈ R⁰ := isRegular_iff_eq_zero_of_mul lemma le_nonZeroDivisorsLeft_iff_isLeftRegular {S : Submonoid R} : S ≤ nonZeroDivisorsLeft R ↔ ∀ s : S, IsLeftRegular (s : R) := by simp_rw [SetLike.le_def, isLeftRegular_iff_mem_nonZeroDivisorsLeft, Subtype.forall] lemma le_nonZeroDivisorsRight_iff_isRightRegular {S : Submonoid R} : S ≤ nonZeroDivisorsRight R ↔ ∀ s : S, IsRightRegular (s : R) := by simp_rw [SetLike.le_def, isRightRegular_iff_mem_nonZeroDivisorsRight, Subtype.forall] lemma le_nonZeroDivisors_iff_isRegular {S : Submonoid R} : S ≤ R⁰ ↔ ∀ s : S, IsRegular (s : R) := by simp_rw [nonZeroDivisors, le_inf_iff, le_nonZeroDivisorsLeft_iff_isLeftRegular, le_nonZeroDivisorsRight_iff_isRightRegular, isRegular_iff, forall_and] @[deprecated (since := "2025-07-16")] alias isLeftRegular_iff_mem_nonZeroDivisorsRight := isLeftRegular_iff_mem_nonZeroDivisorsLeft @[deprecated (since := "2025-07-16")] alias isRightRegular_iff_mem_nonZeroDivisorsLeft := isRightRegular_iff_mem_nonZeroDivisorsRight @[deprecated (since := "2025-07-16")] alias le_nonZeroDivisors_iff_isRightRegular := le_nonZeroDivisorsRight_iff_isRightRegular lemma mul_cancel_left_mem_nonZeroDivisorsLeft (hr : r ∈ nonZeroDivisorsLeft R) : r * x = r * y ↔ x = y := ⟨(isLeftRegular_iff_mem_nonZeroDivisorsLeft.mpr hr ·), congr_arg (r * ·)⟩ lemma mul_cancel_right_mem_nonZeroDivisorsRight (hr : r ∈ nonZeroDivisorsRight R) : x * r = y * r ↔ x = y := ⟨(isRightRegular_iff_mem_nonZeroDivisorsRight.mpr hr ·), congr_arg (· * r)⟩ @[simp] lemma mul_cancel_left_mem_nonZeroDivisors (hr : r ∈ R⁰) : r * x = r * y ↔ x = y := mul_cancel_left_mem_nonZeroDivisorsLeft hr.1 lemma mul_cancel_left_coe_nonZeroDivisors {c : R⁰} : (c : R) * x = c * y ↔ x = y := mul_cancel_left_mem_nonZeroDivisors c.prop lemma mul_cancel_right_mem_nonZeroDivisors (hr : r ∈ R⁰) : x * r = y * r ↔ x = y := mul_cancel_right_mem_nonZeroDivisorsRight hr.2 lemma mul_cancel_right_coe_nonZeroDivisors {c : R⁰} : x * c = y * c ↔ x = y := mul_cancel_right_mem_nonZeroDivisors c.prop /-- In a finite ring, an element is a unit iff it is a non-zero-divisor. -/ lemma isUnit_iff_mem_nonZeroDivisors_of_finite [Finite R] : IsUnit a ↔ a ∈ nonZeroDivisors R := by rw [← isRegular_iff_mem_nonZeroDivisors, isRegular_iff_isUnit_of_finite] lemma dvd_cancel_left_mem_nonZeroDivisors (hr : r ∈ R⁰) : r * x ∣ r * y ↔ x ∣ y := (isLeftRegular_iff_mem_nonZeroDivisorsLeft.mpr hr.1).dvd_cancel_left lemma dvd_cancel_left_coe_nonZeroDivisors {c : R⁰} : c * x ∣ c * y ↔ x ∣ y := dvd_cancel_left_mem_nonZeroDivisors c.prop end Ring section CommRing variable {R : Type*} [CommRing R] {r x y : R} lemma dvd_cancel_right_mem_nonZeroDivisors (hr : r ∈ R⁰) : x * r ∣ y * r ↔ x ∣ y := by simp_rw [← mul_comm r, dvd_cancel_left_mem_nonZeroDivisors hr] lemma dvd_cancel_right_coe_nonZeroDivisors {c : R⁰} : x * c ∣ y * c ↔ x ∣ y := dvd_cancel_right_mem_nonZeroDivisors c.prop end CommRing
.lake/packages/mathlib/Mathlib/Algebra/Ring/Subgroup.lean
import Mathlib.Algebra.GroupWithZero.Subgroup import Mathlib.Algebra.Ring.Submonoid.Pointwise import Mathlib.Algebra.Module.Defs /-! # Additive subgroups of rings -/ open scoped Pointwise variable {R M : Type*} namespace AddSubgroup section NonUnitalNonAssocRing variable [NonUnitalNonAssocRing R] /-- For additive subgroups `S` and `T` of a ring, the product of `S` and `T` as submonoids is automatically a subgroup, which we define as the product of `S` and `T` as subgroups. -/ protected def mul : Mul (AddSubgroup R) where mul M N := { __ := M.toAddSubmonoid * N.toAddSubmonoid neg_mem' := fun h ↦ AddSubmonoid.mul_induction_on h (fun m hm n hn ↦ by rw [← neg_mul]; exact AddSubmonoid.mul_mem_mul (M.neg_mem hm) hn) fun r₁ r₂ h₁ h₂ ↦ by rw [neg_add]; exact (M.1 * N.1).add_mem h₁ h₂ } scoped[Pointwise] attribute [instance] AddSubgroup.mul lemma mul_toAddSubmonoid (M N : AddSubgroup R) : (M * N).toAddSubmonoid = M.toAddSubmonoid * N.toAddSubmonoid := rfl end NonUnitalNonAssocRing section Semiring variable [Semiring R] [AddCommGroup M] [Module R M] @[simp] protected lemma zero_smul (s : AddSubgroup M) : (0 : R) • s = ⊥ := by simp [eq_bot_iff_forall, pointwise_smul_def] end Semiring end AddSubgroup
.lake/packages/mathlib/Mathlib/Algebra/Ring/Torsion.lean
import Mathlib.Algebra.CharZero.Defs import Mathlib.Algebra.GroupWithZero.Basic import Mathlib.Algebra.Ring.Regular /-! # Torsion-free rings A characteristic zero domain is torsion-free. -/ namespace IsDomain -- This instance is potentially expensive, and is known to slow down grind. -- Please keep it as a scoped instance. scoped instance (R : Type*) [Semiring R] [IsDomain R] [CharZero R] : IsAddTorsionFree R where nsmul_right_injective n h a b w := by simp only [nsmul_eq_mul, mul_eq_mul_left_iff, Nat.cast_eq_zero] at w grind end IsDomain
.lake/packages/mathlib/Mathlib/Algebra/Ring/CentroidHom.lean
import Mathlib.Algebra.Algebra.Defs import Mathlib.Algebra.Group.Action.Pi import Mathlib.Algebra.Module.Hom import Mathlib.GroupTheory.GroupAction.Ring import Mathlib.RingTheory.NonUnitalSubsemiring.Basic import Mathlib.Algebra.Ring.Subsemiring.Basic /-! # Centroid homomorphisms Let `A` be a (nonunital, non-associative) algebra. The centroid of `A` is the set of linear maps `T` on `A` such that `T` commutes with left and right multiplication, that is to say, for all `a` and `b` in `A`, $$ T(ab) = (Ta)b, T(ab) = a(Tb). $$ In mathlib we call elements of the centroid "centroid homomorphisms" (`CentroidHom`) in keeping with `AddMonoidHom` etc. We use the `DFunLike` design, so each type of morphisms has a companion typeclass which is meant to be satisfied by itself and all stricter types. ## Types of morphisms * `CentroidHom`: Maps which preserve left and right multiplication. ## Typeclasses * `CentroidHomClass` ## References * [Jacobson, Structure of Rings][Jacobson1956] * [McCrimmon, A taste of Jordan algebras][mccrimmon2004] ## Tags centroid -/ assert_not_exists Field open Function variable {F M N R α : Type*} /-- The type of centroid homomorphisms from `α` to `α`. -/ structure CentroidHom (α : Type*) [NonUnitalNonAssocSemiring α] extends α →+ α where /-- Commutativity of centroid homomorphims with left multiplication. -/ map_mul_left' (a b : α) : toFun (a * b) = a * toFun b /-- Commutativity of centroid homomorphims with right multiplication. -/ map_mul_right' (a b : α) : toFun (a * b) = toFun a * b attribute [nolint docBlame] CentroidHom.toAddMonoidHom /-- `CentroidHomClass F α` states that `F` is a type of centroid homomorphisms. You should extend this class when you extend `CentroidHom`. -/ class CentroidHomClass (F : Type*) (α : outParam Type*) [NonUnitalNonAssocSemiring α] [FunLike F α α] : Prop extends AddMonoidHomClass F α α where /-- Commutativity of centroid homomorphims with left multiplication. -/ map_mul_left (f : F) (a b : α) : f (a * b) = a * f b /-- Commutativity of centroid homomorphims with right multiplication. -/ map_mul_right (f : F) (a b : α) : f (a * b) = f a * b export CentroidHomClass (map_mul_left map_mul_right) instance [NonUnitalNonAssocSemiring α] [FunLike F α α] [CentroidHomClass F α] : CoeTC F (CentroidHom α) := ⟨fun f ↦ { (f : α →+ α) with toFun := f map_mul_left' := map_mul_left f map_mul_right' := map_mul_right f }⟩ /-! ### Centroid homomorphisms -/ namespace CentroidHom section NonUnitalNonAssocSemiring variable [NonUnitalNonAssocSemiring α] instance : FunLike (CentroidHom α) α α where coe f := f.toFun coe_injective' f g h := by cases f cases g congr with x exact congrFun h x instance : CentroidHomClass (CentroidHom α) α where map_zero f := f.map_zero' map_add f := f.map_add' map_mul_left f := f.map_mul_left' map_mul_right f := f.map_mul_right' theorem toFun_eq_coe {f : CentroidHom α} : f.toFun = f := rfl @[ext] theorem ext {f g : CentroidHom α} (h : ∀ a, f a = g a) : f = g := DFunLike.ext f g h @[simp, norm_cast] theorem coe_toAddMonoidHom (f : CentroidHom α) : ⇑(f : α →+ α) = f := rfl @[simp] theorem toAddMonoidHom_eq_coe (f : CentroidHom α) : f.toAddMonoidHom = f := rfl theorem coe_toAddMonoidHom_injective : Injective ((↑) : CentroidHom α → α →+ α) := fun _f _g h => ext fun a ↦ haveI := DFunLike.congr_fun h a this /-- Turn a centroid homomorphism into an additive monoid endomorphism. -/ def toEnd (f : CentroidHom α) : AddMonoid.End α := (f : α →+ α) theorem toEnd_injective : Injective (CentroidHom.toEnd : CentroidHom α → AddMonoid.End α) := coe_toAddMonoidHom_injective /-- Copy of a `CentroidHom` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (f : CentroidHom α) (f' : α → α) (h : f' = f) : CentroidHom α := { f.toAddMonoidHom.copy f' <| h with toFun := f' map_mul_left' := fun a b ↦ by simp_rw [h, map_mul_left] map_mul_right' := fun a b ↦ by simp_rw [h, map_mul_right] } @[simp] theorem coe_copy (f : CentroidHom α) (f' : α → α) (h : f' = f) : ⇑(f.copy f' h) = f' := rfl theorem copy_eq (f : CentroidHom α) (f' : α → α) (h : f' = f) : f.copy f' h = f := DFunLike.ext' h variable (α) /-- `id` as a `CentroidHom`. -/ protected def id : CentroidHom α := { AddMonoidHom.id α with map_mul_left' := fun _ _ ↦ rfl map_mul_right' := fun _ _ ↦ rfl } instance : Inhabited (CentroidHom α) := ⟨CentroidHom.id α⟩ @[simp, norm_cast] theorem coe_id : ⇑(CentroidHom.id α) = id := rfl @[simp, norm_cast] theorem toAddMonoidHom_id : (CentroidHom.id α : α →+ α) = AddMonoidHom.id α := rfl variable {α} @[simp] theorem id_apply (a : α) : CentroidHom.id α a = a := rfl /-- Composition of `CentroidHom`s as a `CentroidHom`. -/ def comp (g f : CentroidHom α) : CentroidHom α := { g.toAddMonoidHom.comp f.toAddMonoidHom with map_mul_left' := fun _a _b ↦ (congr_arg g <| f.map_mul_left' _ _).trans <| g.map_mul_left' _ _ map_mul_right' := fun _a _b ↦ (congr_arg g <| f.map_mul_right' _ _).trans <| g.map_mul_right' _ _ } @[simp, norm_cast] theorem coe_comp (g f : CentroidHom α) : ⇑(g.comp f) = g ∘ f := rfl @[simp] theorem comp_apply (g f : CentroidHom α) (a : α) : g.comp f a = g (f a) := rfl @[simp, norm_cast] theorem coe_comp_addMonoidHom (g f : CentroidHom α) : (g.comp f : α →+ α) = (g : α →+ α).comp f := rfl @[simp] theorem comp_assoc (h g f : CentroidHom α) : (h.comp g).comp f = h.comp (g.comp f) := rfl @[simp] theorem comp_id (f : CentroidHom α) : f.comp (CentroidHom.id α) = f := rfl @[simp] theorem id_comp (f : CentroidHom α) : (CentroidHom.id α).comp f = f := rfl @[simp] theorem cancel_right {g₁ g₂ f : CentroidHom α} (hf : Surjective f) : g₁.comp f = g₂.comp f ↔ g₁ = g₂ := ⟨fun h ↦ ext <| hf.forall.2 <| DFunLike.ext_iff.1 h, fun a ↦ congrFun (congrArg comp a) f⟩ @[simp] theorem cancel_left {g f₁ f₂ : CentroidHom α} (hg : Injective g) : g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ := ⟨fun h ↦ ext fun a ↦ hg <| by rw [← comp_apply, h, comp_apply], congr_arg _⟩ instance : Zero (CentroidHom α) := ⟨{ (0 : α →+ α) with map_mul_left' := fun _a _b ↦ (mul_zero _).symm map_mul_right' := fun _a _b ↦ (zero_mul _).symm }⟩ instance : One (CentroidHom α) := ⟨CentroidHom.id α⟩ instance : Add (CentroidHom α) := ⟨fun f g ↦ { (f + g : α →+ α) with map_mul_left' := fun a b ↦ by simp [map_mul_left, mul_add] map_mul_right' := fun a b ↦ by simp [map_mul_right, add_mul] }⟩ instance : Mul (CentroidHom α) := ⟨comp⟩ variable [Monoid M] [Monoid N] [Semiring R] variable [DistribMulAction M α] [SMulCommClass M α α] [IsScalarTower M α α] variable [DistribMulAction N α] [SMulCommClass N α α] [IsScalarTower N α α] variable [Module R α] [SMulCommClass R α α] [IsScalarTower R α α] instance instSMul : SMul M (CentroidHom α) where smul n f := { (n • f : α →+ α) with map_mul_left' := fun a b ↦ by change n • f (a * b) = a * n • f b rw [map_mul_left f, ← mul_smul_comm] map_mul_right' := fun a b ↦ by change n • f (a * b) = n • f a * b rw [map_mul_right f, ← smul_mul_assoc] } instance [SMul M N] [IsScalarTower M N α] : IsScalarTower M N (CentroidHom α) where smul_assoc _ _ _ := ext fun _ => smul_assoc _ _ _ instance [SMulCommClass M N α] : SMulCommClass M N (CentroidHom α) where smul_comm _ _ _ := ext fun _ => smul_comm _ _ _ instance [DistribMulAction Mᵐᵒᵖ α] [IsCentralScalar M α] : IsCentralScalar M (CentroidHom α) where op_smul_eq_smul _ _ := ext fun _ => op_smul_eq_smul _ _ instance isScalarTowerRight : IsScalarTower M (CentroidHom α) (CentroidHom α) where smul_assoc _ _ _ := rfl instance hasNPowNat : Pow (CentroidHom α) ℕ := ⟨fun f n ↦ { toAddMonoidHom := (f.toEnd ^ n : AddMonoid.End α) map_mul_left' := fun a b ↦ by induction n with | zero => rfl | succ n ih => rw [pow_succ'] exact (congr_arg f.toEnd ih).trans (f.map_mul_left' _ _) map_mul_right' := fun a b ↦ by induction n with | zero => rfl | succ n ih => rw [pow_succ'] exact (congr_arg f.toEnd ih).trans (f.map_mul_right' _ _)}⟩ @[simp, norm_cast] theorem coe_zero : ⇑(0 : CentroidHom α) = 0 := rfl @[simp, norm_cast] theorem coe_one : ⇑(1 : CentroidHom α) = id := rfl @[simp, norm_cast] theorem coe_add (f g : CentroidHom α) : ⇑(f + g) = f + g := rfl @[simp, norm_cast] theorem coe_mul (f g : CentroidHom α) : ⇑(f * g) = f ∘ g := rfl @[simp, norm_cast] theorem coe_smul (n : M) (f : CentroidHom α) : ⇑(n • f) = n • ⇑f := rfl @[simp] theorem zero_apply (a : α) : (0 : CentroidHom α) a = 0 := rfl @[simp] theorem one_apply (a : α) : (1 : CentroidHom α) a = a := rfl @[simp] theorem add_apply (f g : CentroidHom α) (a : α) : (f + g) a = f a + g a := rfl @[simp] theorem mul_apply (f g : CentroidHom α) (a : α) : (f * g) a = f (g a) := rfl @[simp] theorem smul_apply (n : M) (f : CentroidHom α) (a : α) : (n • f) a = n • f a := rfl example : SMul ℕ (CentroidHom α) := instSMul @[simp] theorem toEnd_zero : (0 : CentroidHom α).toEnd = 0 := rfl @[simp] theorem toEnd_add (x y : CentroidHom α) : (x + y).toEnd = x.toEnd + y.toEnd := rfl theorem toEnd_smul (m : M) (x : CentroidHom α) : (m • x).toEnd = m • x.toEnd := rfl instance : AddCommMonoid (CentroidHom α) := coe_toAddMonoidHom_injective.addCommMonoid _ toEnd_zero toEnd_add (swap toEnd_smul) instance : NatCast (CentroidHom α) where natCast n := n • (1 : CentroidHom α) @[simp, norm_cast] theorem coe_natCast (n : ℕ) : ⇑(n : CentroidHom α) = n • (CentroidHom.id α) := rfl theorem natCast_apply (n : ℕ) (m : α) : (n : CentroidHom α) m = n • m := rfl @[simp] theorem toEnd_one : (1 : CentroidHom α).toEnd = 1 := rfl @[simp] theorem toEnd_mul (x y : CentroidHom α) : (x * y).toEnd = x.toEnd * y.toEnd := rfl @[simp] theorem toEnd_pow (x : CentroidHom α) (n : ℕ) : (x ^ n).toEnd = x.toEnd ^ n := rfl @[simp, norm_cast] theorem toEnd_natCast (n : ℕ) : (n : CentroidHom α).toEnd = ↑n := rfl -- cf `add_monoid.End.semiring` instance : Semiring (CentroidHom α) := toEnd_injective.semiring _ toEnd_zero toEnd_one toEnd_add toEnd_mul toEnd_smul toEnd_pow toEnd_natCast variable (α) in /-- `CentroidHom.toEnd` as a `RingHom`. -/ @[simps] def toEndRingHom : CentroidHom α →+* AddMonoid.End α where toFun := toEnd map_zero' := toEnd_zero map_one' := toEnd_one map_add' := toEnd_add map_mul' := toEnd_mul theorem comp_mul_comm (T S : CentroidHom α) (a b : α) : (T ∘ S) (a * b) = (S ∘ T) (a * b) := by simp only [Function.comp_apply] rw [map_mul_right, map_mul_left, ← map_mul_right, ← map_mul_left] instance : DistribMulAction M (CentroidHom α) := toEnd_injective.distribMulAction (toEndRingHom α).toAddMonoidHom toEnd_smul instance : Module R (CentroidHom α) := toEnd_injective.module R (toEndRingHom α).toAddMonoidHom toEnd_smul /-! The following instances show that `α` is a non-unital and non-associative algebra over `CentroidHom α`. -/ /-- The tautological action by `CentroidHom α` on `α`. This generalizes `Function.End.applyMulAction`. -/ instance applyModule : Module (CentroidHom α) α where smul T a := T a add_smul _ _ _ := rfl zero_smul _ := rfl one_smul _ := rfl mul_smul _ _ _ := rfl smul_zero := map_zero smul_add := map_add @[simp] lemma smul_def (T : CentroidHom α) (a : α) : T • a = T a := rfl instance : SMulCommClass (CentroidHom α) α α where smul_comm _ _ _ := map_mul_left _ _ _ instance : SMulCommClass α (CentroidHom α) α := SMulCommClass.symm _ _ _ instance : IsScalarTower (CentroidHom α) α α where smul_assoc _ _ _ := (map_mul_right _ _ _).symm /-! Let `α` be an algebra over `R`, such that the canonical ring homomorphism of `R` into `CentroidHom α` lies in the center of `CentroidHom α`. Then `CentroidHom α` is an algebra over `R` -/ variable {R : Type*} variable [CommSemiring R] variable [Module R α] [SMulCommClass R α α] [IsScalarTower R α α] /-- The natural ring homomorphism from `R` into `CentroidHom α`. This is a stronger version of `Module.toAddMonoidEnd`. -/ @[simps! apply_toFun] def _root_.Module.toCentroidHom : R →+* CentroidHom α := RingHom.smulOneHom open Module in /-- `CentroidHom α` as an algebra over `R`. -/ example (h : ∀ (r : R) (T : CentroidHom α), toCentroidHom r * T = T * toCentroidHom r) : Algebra R (CentroidHom α) := toCentroidHom.toAlgebra' h local notation "L" => AddMonoid.End.mulLeft local notation "R" => AddMonoid.End.mulRight lemma centroid_eq_centralizer_mulLeftRight : RingHom.rangeS (toEndRingHom α) = Subsemiring.centralizer (Set.range L ∪ Set.range R) := by ext T refine ⟨?_, fun h ↦ ?_⟩ · rintro ⟨f, rfl⟩ S (⟨a, rfl⟩ | ⟨b, rfl⟩) · exact AddMonoidHom.ext fun b ↦ (map_mul_left f a b).symm · exact AddMonoidHom.ext fun a ↦ (map_mul_right f a b).symm · rw [Subsemiring.mem_centralizer_iff] at h refine ⟨⟨T, fun a b ↦ ?_, fun a b ↦ ?_⟩, rfl⟩ · exact congr($(h (L a) (.inl ⟨a, rfl⟩)) b).symm · exact congr($(h (R b) (.inr ⟨b, rfl⟩)) a).symm /-- The canonical homomorphism from the center into the center of the centroid -/ def centerToCentroidCenter : NonUnitalSubsemiring.center α →ₙ+* Subsemiring.center (CentroidHom α) where toFun z := { L (z : α) with val := ⟨L z, z.prop.left_comm, z.prop.left_assoc ⟩ property := by rw [Subsemiring.mem_center_iff] intro g ext a exact map_mul_left g (↑z) a } map_zero' := by simp only [ZeroMemClass.coe_zero, map_zero] exact rfl map_add' := fun _ _ => by dsimp simp only [map_add] rfl map_mul' z₁ z₂ := by ext a; exact (z₁.prop.left_assoc z₂ a).symm instance : FunLike (Subsemiring.center (CentroidHom α)) α α where coe f := f.val.toFun coe_injective' f g h := by cases f cases g congr with x exact congrFun h x lemma centerToCentroidCenter_apply (z : NonUnitalSubsemiring.center α) (a : α) : (centerToCentroidCenter z) a = z * a := rfl /-- The canonical homomorphism from the center into the centroid -/ def centerToCentroid : NonUnitalSubsemiring.center α →ₙ+* CentroidHom α := NonUnitalRingHom.comp (SubsemiringClass.subtype (Subsemiring.center (CentroidHom α))).toNonUnitalRingHom centerToCentroidCenter lemma centerToCentroid_apply (z : NonUnitalSubsemiring.center α) (a : α) : (centerToCentroid z) a = z * a := rfl lemma _root_.NonUnitalNonAssocSemiring.mem_center_iff (a : α) : a ∈ NonUnitalSubsemiring.center α ↔ R a = L a ∧ (L a) ∈ RingHom.rangeS (toEndRingHom α) := by constructor · exact fun ha ↦ ⟨AddMonoidHom.ext <| fun _ => (IsMulCentral.comm ha _).symm, ⟨centerToCentroid ⟨a, ha⟩, rfl⟩⟩ · rintro ⟨hc, ⟨T, hT⟩⟩ have e1 (d : α) : T d = a * d := congr($hT d) have e2 (d : α) : T d = d * a := congr($(hT.trans hc.symm) d) constructor case comm => exact (congr($hc.symm ·)) case left_assoc => simpa [e1] using (map_mul_right T · ·) case right_assoc => simpa [e2] using (map_mul_left T · ·) end NonUnitalNonAssocSemiring section NonUnitalNonAssocCommSemiring variable [NonUnitalNonAssocCommSemiring α] /- Left and right multiplication coincide as α is commutative -/ local notation "L" => AddMonoid.End.mulLeft lemma _root_.NonUnitalNonAssocCommSemiring.mem_center_iff (a : α) : a ∈ NonUnitalSubsemiring.center α ↔ ∀ b : α, Commute (L b) (L a) := by rw [NonUnitalNonAssocSemiring.mem_center_iff, CentroidHom.centroid_eq_centralizer_mulLeftRight, Subsemiring.mem_centralizer_iff, AddMonoid.End.mulRight_eq_mulLeft, Set.union_self] aesop end NonUnitalNonAssocCommSemiring section NonAssocSemiring variable [NonAssocSemiring α] /-- The canonical isomorphism from the center of a (non-associative) semiring onto its centroid. -/ def centerIsoCentroid : Subsemiring.center α ≃+* CentroidHom α := { centerToCentroid with invFun := fun T ↦ ⟨T 1, by constructor <;> simp [commute_iff_eq, ← map_mul_left, ← map_mul_right]⟩ left_inv := fun z ↦ Subtype.ext <| by simp only [MulHom.toFun_eq_coe, NonUnitalRingHom.coe_toMulHom, centerToCentroid_apply, mul_one] right_inv := fun T ↦ CentroidHom.ext <| fun _ => by rw [MulHom.toFun_eq_coe, NonUnitalRingHom.coe_toMulHom, centerToCentroid_apply, ← map_mul_right, one_mul] } end NonAssocSemiring section NonUnitalNonAssocRing variable [NonUnitalNonAssocRing α] /-- Negation of `CentroidHom`s as a `CentroidHom`. -/ instance : Neg (CentroidHom α) := ⟨fun f ↦ { (-f : α →+ α) with map_mul_left' := fun a b ↦ by simp [map_mul_left] map_mul_right' := fun a b ↦ by simp [map_mul_right] }⟩ instance : Sub (CentroidHom α) := ⟨fun f g ↦ { (f - g : α →+ α) with map_mul_left' := fun a b ↦ by simp [map_mul_left, mul_sub] map_mul_right' := fun a b ↦ by simp [map_mul_right, sub_mul] }⟩ instance : IntCast (CentroidHom α) where intCast z := z • (1 : CentroidHom α) @[simp, norm_cast] theorem coe_intCast (z : ℤ) : ⇑(z : CentroidHom α) = z • (CentroidHom.id α) := rfl theorem intCast_apply (z : ℤ) (m : α) : (z : CentroidHom α) m = z • m := rfl @[simp] theorem toEnd_neg (x : CentroidHom α) : (-x).toEnd = -x.toEnd := rfl @[simp] theorem toEnd_sub (x y : CentroidHom α) : (x - y).toEnd = x.toEnd - y.toEnd := rfl instance : AddCommGroup (CentroidHom α) := toEnd_injective.addCommGroup _ toEnd_zero toEnd_add toEnd_neg toEnd_sub (swap toEnd_smul) (swap toEnd_smul) @[simp, norm_cast] theorem coe_neg (f : CentroidHom α) : ⇑(-f) = -f := rfl @[simp, norm_cast] theorem coe_sub (f g : CentroidHom α) : ⇑(f - g) = f - g := rfl @[simp] theorem neg_apply (f : CentroidHom α) (a : α) : (-f) a = -f a := rfl @[simp] theorem sub_apply (f g : CentroidHom α) (a : α) : (f - g) a = f a - g a := rfl @[simp, norm_cast] theorem toEnd_intCast (z : ℤ) : (z : CentroidHom α).toEnd = ↑z := rfl instance instRing : Ring (CentroidHom α) := toEnd_injective.ring _ toEnd_zero toEnd_one toEnd_add toEnd_mul toEnd_neg toEnd_sub toEnd_smul toEnd_smul toEnd_pow toEnd_natCast toEnd_intCast end NonUnitalNonAssocRing section NonUnitalRing variable [NonUnitalRing α] -- See note [reducible non-instances] /-- A prime associative ring has commutative centroid. -/ abbrev commRing (h : ∀ a b : α, (∀ r : α, a * r * b = 0) → a = 0 ∨ b = 0) : CommRing (CentroidHom α) := { CentroidHom.instRing with mul_comm := fun f g ↦ by ext refine sub_eq_zero.1 (or_self_iff.1 <| (h _ _) fun r ↦ ?_) rw [mul_assoc, sub_mul, sub_eq_zero, ← map_mul_right, ← map_mul_right, coe_mul, coe_mul, comp_mul_comm] } end NonUnitalRing end CentroidHom
.lake/packages/mathlib/Mathlib/Algebra/Ring/GeomSum.lean
import Mathlib.Algebra.BigOperators.Intervals import Mathlib.Algebra.BigOperators.Ring.Finset import Mathlib.Algebra.Ring.Opposite /-! # Partial sums of geometric series in a ring 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. Several variants are recorded, generalising in particular to the case of a noncommutative ring in which `x` and `y` commute. Even versions not using division or subtraction, valid in each semiring, are recorded. -/ assert_not_exists Field IsOrderedRing open Finset MulOpposite variable {R S : Type*} section Semiring variable [Semiring R] [Semiring S] {x y : R} lemma geom_sum_succ {x : R} {n : ℕ} : ∑ i ∈ range (n + 1), x ^ i = (x * ∑ i ∈ range n, x ^ i) + 1 := by simp only [mul_sum, ← pow_succ', sum_range_succ', pow_zero] lemma geom_sum_succ' {x : R} {n : ℕ} : ∑ i ∈ range (n + 1), x ^ i = x ^ n + ∑ i ∈ range n, x ^ i := (sum_range_succ _ _).trans (add_comm _ _) lemma geom_sum_zero (x : R) : ∑ i ∈ range 0, x ^ i = 0 := rfl lemma geom_sum_one (x : R) : ∑ i ∈ range 1, x ^ i = 1 := by simp @[simp] lemma geom_sum_two {x : R} : ∑ i ∈ range 2, x ^ i = x + 1 := by simp [geom_sum_succ'] @[simp] lemma zero_geom_sum : ∀ {n}, ∑ i ∈ range n, (0 : R) ^ i = if n = 0 then 0 else 1 | 0 => by simp | 1 => by simp | n + 2 => by rw [geom_sum_succ'] simp [zero_geom_sum] lemma one_geom_sum (n : ℕ) : ∑ i ∈ range n, (1 : R) ^ i = n := by simp lemma op_geom_sum (x : R) (n : ℕ) : op (∑ i ∈ range n, x ^ i) = ∑ i ∈ range n, op x ^ i := by simp @[simp] lemma op_geom_sum₂ (x y : R) (n : ℕ) : ∑ i ∈ range n, op y ^ (n - 1 - i) * op x ^ i = ∑ i ∈ range n, op y ^ i * op x ^ (n - 1 - i) := by rw [← sum_range_reflect] refine sum_congr rfl fun j j_in => ?_ grind lemma geom_sum₂_with_one (x : R) (n : ℕ) : ∑ i ∈ range n, x ^ i * 1 ^ (n - 1 - i) = ∑ i ∈ range n, x ^ i := sum_congr rfl fun i _ => by rw [one_pow, mul_one] /-- $x^n-y^n = (x-y) \sum x^ky^{n-1-k}$ reformulated without `-` signs. -/ protected lemma Commute.geom_sum₂_mul_add {x y : R} (h : Commute x y) (n : ℕ) : (∑ i ∈ range n, (x + y) ^ i * y ^ (n - 1 - i)) * x + y ^ n = (x + y) ^ n := by let f : ℕ → ℕ → R := fun m i : ℕ => (x + y) ^ i * y ^ (m - 1 - i) change (∑ i ∈ range n, (f n) i) * x + y ^ n = (x + y) ^ n induction n with | zero => rw [range_zero, sum_empty, zero_mul, zero_add, pow_zero, pow_zero] | succ n ih => have f_last : f (n + 1) n = (x + y) ^ n := by dsimp only [f] rw [← tsub_add_eq_tsub_tsub, Nat.add_comm, tsub_self, pow_zero, mul_one] have f_succ : ∀ i, i ∈ range n → f (n + 1) i = y * f n i := fun i hi => by dsimp only [f] have : Commute y ((x + y) ^ i) := (h.symm.add_right (Commute.refl y)).pow_right i rw [← mul_assoc, this.eq, mul_assoc, ← pow_succ' y (n - 1 - i), add_tsub_cancel_right, ← tsub_add_eq_tsub_tsub, add_comm 1 i] have : i + 1 + (n - (i + 1)) = n := add_tsub_cancel_of_le (mem_range.mp hi) rw [add_comm (i + 1)] at this rw [← this, add_tsub_cancel_right, add_comm i 1, ← add_assoc, add_tsub_cancel_right] rw [pow_succ' (x + y), add_mul, sum_range_succ_comm, add_mul, f_last, add_assoc, (((Commute.refl x).add_right h).pow_right n).eq, sum_congr rfl f_succ, ← mul_sum, pow_succ' y, mul_assoc, ← mul_add y, ih] lemma geom_sum₂_self (x : R) (n : ℕ) : ∑ i ∈ range n, x ^ i * x ^ (n - 1 - i) = n * x ^ (n - 1) := calc ∑ i ∈ Finset.range n, x ^ i * x ^ (n - 1 - i) = ∑ i ∈ Finset.range n, x ^ (i + (n - 1 - i)) := by simp_rw [← pow_add] _ = ∑ _i ∈ Finset.range n, x ^ (n - 1) := Finset.sum_congr rfl fun _ hi => congr_arg _ <| add_tsub_cancel_of_le <| Nat.le_sub_one_of_lt <| Finset.mem_range.1 hi _ = #(range n) • x ^ (n - 1) := sum_const _ _ = n * x ^ (n - 1) := by rw [Finset.card_range, nsmul_eq_mul] lemma geom_sum_mul_add (x : R) (n : ℕ) : (∑ i ∈ range n, (x + 1) ^ i) * x + 1 = (x + 1) ^ n := by have := (Commute.one_right x).geom_sum₂_mul_add n rw [one_pow, geom_sum₂_with_one] at this exact this protected lemma Commute.geom_sum₂_comm (n : ℕ) (h : Commute x y) : ∑ i ∈ range n, x ^ i * y ^ (n - 1 - i) = ∑ i ∈ range n, y ^ i * x ^ (n - 1 - i) := by cases n; · simp simp only [Nat.add_sub_cancel] rw [← Finset.sum_flip] refine Finset.sum_congr rfl fun i hi => ?_ simpa [Nat.sub_sub_self (Nat.succ_le_succ_iff.mp (Finset.mem_range.mp hi))] using h.pow_pow _ _ -- TODO: for consistency, the next two lemmas should be moved to the root namespace lemma RingHom.map_geom_sum (x : R) (n : ℕ) (f : R →+* S) : f (∑ i ∈ range n, x ^ i) = ∑ i ∈ range n, f x ^ i := by simp [map_sum f] lemma RingHom.map_geom_sum₂ (x y : R) (n : ℕ) (f : R →+* S) : f (∑ i ∈ range n, x ^ i * y ^ (n - 1 - i)) = ∑ i ∈ range n, f x ^ i * f y ^ (n - 1 - i) := by simp [map_sum f] end Semiring section CommSemiring variable [CommSemiring R] /-- $x^n-y^n = (x-y) \sum x^ky^{n-1-k}$ reformulated without `-` signs. -/ lemma geom_sum₂_mul_add (x y : R) (n : ℕ) : (∑ i ∈ range n, (x + y) ^ i * y ^ (n - 1 - i)) * x + y ^ n = (x + y) ^ n := (Commute.all x y).geom_sum₂_mul_add n lemma geom_sum₂_comm (x y : R) (n : ℕ) : ∑ i ∈ range n, x ^ i * y ^ (n - 1 - i) = ∑ i ∈ range n, y ^ i * x ^ (n - 1 - i) := (Commute.all x y).geom_sum₂_comm n variable [PartialOrder R] [AddLeftReflectLE R] [AddLeftMono R] [ExistsAddOfLE R] [Sub R] [OrderedSub R] {x y : R} lemma geom_sum₂_mul_of_ge (hxy : y ≤ x) (n : ℕ) : (∑ i ∈ range n, x ^ i * y ^ (n - 1 - i)) * (x - y) = x ^ n - y ^ n := by apply eq_tsub_of_add_eq simpa only [tsub_add_cancel_of_le hxy] using geom_sum₂_mul_add (x - y) y n lemma geom_sum₂_mul_of_le (hxy : x ≤ y) (n : ℕ) : (∑ i ∈ range n, x ^ i * y ^ (n - 1 - i)) * (y - x) = y ^ n - x ^ n := by rw [← Finset.sum_range_reflect] convert geom_sum₂_mul_of_ge hxy n using 3 simp_all only [Finset.mem_range] rw [mul_comm] congr cutsat lemma geom_sum_mul_of_one_le (hx : 1 ≤ x) (n : ℕ) : (∑ i ∈ range n, x ^ i) * (x - 1) = x ^ n - 1 := by simpa using geom_sum₂_mul_of_ge hx n lemma geom_sum_mul_of_le_one (hx : x ≤ 1) (n : ℕ) : (∑ i ∈ range n, x ^ i) * (1 - x) = 1 - x ^ n := by simpa using geom_sum₂_mul_of_le hx n end CommSemiring section Ring variable [Ring R] {x y : R} @[simp] lemma neg_one_geom_sum {n : ℕ} : ∑ i ∈ range n, (-1 : R) ^ i = if Even n then 0 else 1 := by induction n with | zero => simp | succ k hk => simp only [geom_sum_succ', Nat.even_add_one, hk] split_ifs with h · rw [h.neg_one_pow, add_zero] · rw [(Nat.not_even_iff_odd.1 h).neg_one_pow, neg_add_cancel] protected lemma Commute.geom_sum₂_mul (h : Commute x y) (n : ℕ) : (∑ i ∈ range n, x ^ i * y ^ (n - 1 - i)) * (x - y) = x ^ n - y ^ n := by have := (h.sub_left (Commute.refl y)).geom_sum₂_mul_add n rw [sub_add_cancel] at this rw [← this, add_sub_cancel_right] lemma Commute.mul_neg_geom_sum₂ (h : Commute x y) (n : ℕ) : ((y - x) * ∑ i ∈ range n, x ^ i * y ^ (n - 1 - i)) = y ^ n - x ^ n := by apply op_injective simp only [op_mul, op_sub, op_pow] simp [(Commute.op h.symm).geom_sum₂_mul n] lemma Commute.mul_geom_sum₂ (h : Commute x y) (n : ℕ) : ((x - y) * ∑ i ∈ range n, x ^ i * y ^ (n - 1 - i)) = x ^ n - y ^ n := by rw [← neg_sub (y ^ n), ← h.mul_neg_geom_sum₂, ← neg_mul, neg_sub] lemma Commute.sub_dvd_pow_sub_pow (h : Commute x y) (n : ℕ) : x - y ∣ x ^ n - y ^ n := Dvd.intro _ <| h.mul_geom_sum₂ _ lemma one_sub_dvd_one_sub_pow (x : R) (n : ℕ) : 1 - x ∣ 1 - x ^ n := by conv_rhs => rw [← one_pow n] exact (Commute.one_left x).sub_dvd_pow_sub_pow n lemma sub_one_dvd_pow_sub_one (x : R) (n : ℕ) : x - 1 ∣ x ^ n - 1 := by conv_rhs => rw [← one_pow n] exact (Commute.one_right x).sub_dvd_pow_sub_pow n lemma pow_one_sub_dvd_pow_mul_sub_one (x : R) (m n : ℕ) : x ^ m - 1 ∣ x ^ (m * n) - 1 := by rw [pow_mul]; exact sub_one_dvd_pow_sub_one (x ^ m) n theorem dvd_pow_sub_one_of_dvd {r : R} {a b : ℕ} (h : a ∣ b) : r ^ a - 1 ∣ r ^ b - 1 := by obtain ⟨n, rfl⟩ := h exact pow_one_sub_dvd_pow_mul_sub_one r a n theorem dvd_pow_pow_sub_self_of_dvd {r : R} {p a b : ℕ} (h : a ∣ b) : r ^ p ^ a - r ∣ r ^ p ^ b - r := by by_cases hp₀ : p = 0 · by_cases hb₀ : b = 0 · rw [hp₀, hb₀, pow_zero, pow_one, sub_self] exact dvd_zero _ have ha₀ : a ≠ 0 := by rintro rfl; rw [zero_dvd_iff] at h; tauto rw [hp₀, zero_pow ha₀, zero_pow hb₀] have hp (c) : 1 ≤ p ^ c := Nat.pow_pos <| pos_of_ne_zero hp₀ rw [← Nat.sub_add_cancel (hp a), ← Nat.sub_add_cancel (hp b), pow_succ', pow_succ', ← mul_sub_one, ← mul_sub_one] refine mul_dvd_mul_left _ <| dvd_pow_sub_one_of_dvd <| Int.natCast_dvd_natCast.mp ?_ rw [Nat.cast_sub (hp a), Nat.cast_sub (hp b), Nat.cast_pow, Nat.cast_pow] exact dvd_pow_sub_one_of_dvd h lemma geom_sum_mul (x : R) (n : ℕ) : (∑ i ∈ range n, x ^ i) * (x - 1) = x ^ n - 1 := by have := (Commute.one_right x).geom_sum₂_mul n rw [one_pow, geom_sum₂_with_one] at this exact this lemma mul_geom_sum (x : R) (n : ℕ) : ((x - 1) * ∑ i ∈ range n, x ^ i) = x ^ n - 1 := op_injective <| by simpa using geom_sum_mul (op x) n lemma geom_sum_mul_neg (x : R) (n : ℕ) : (∑ i ∈ range n, x ^ i) * (1 - x) = 1 - x ^ n := by have := congr_arg Neg.neg (geom_sum_mul x n) rw [neg_sub, ← mul_neg, neg_sub] at this exact this lemma mul_neg_geom_sum (x : R) (n : ℕ) : ((1 - x) * ∑ i ∈ range n, x ^ i) = 1 - x ^ n := op_injective <| by simpa using geom_sum_mul_neg (op x) n protected lemma Commute.mul_geom_sum₂_Ico (h : Commute x y) {m n : ℕ} (hmn : m ≤ n) : ((x - y) * ∑ i ∈ Finset.Ico m n, x ^ i * y ^ (n - 1 - i)) = x ^ n - x ^ m * y ^ (n - m) := by rw [sum_Ico_eq_sub _ hmn] have : ∑ k ∈ range m, x ^ k * y ^ (n - 1 - k) = ∑ k ∈ range m, x ^ k * (y ^ (n - m) * y ^ (m - 1 - k)) := by refine sum_congr rfl fun j j_in => ?_ rw [← pow_add] congr rw [mem_range] at j_in omega rw [this] simp_rw [pow_mul_comm y (n - m) _] simp_rw [← mul_assoc] rw [← sum_mul, mul_sub, h.mul_geom_sum₂, ← mul_assoc, h.mul_geom_sum₂, sub_mul, ← pow_add, add_tsub_cancel_of_le hmn, sub_sub_sub_cancel_right (x ^ n) (x ^ m * y ^ (n - m)) (y ^ n)] protected lemma Commute.geom_sum₂_succ_eq (h : Commute x y) {n : ℕ} : ∑ i ∈ range (n + 1), x ^ i * y ^ (n - i) = x ^ n + y * ∑ i ∈ range n, x ^ i * y ^ (n - 1 - i) := by simp_rw [mul_sum, sum_range_succ_comm, tsub_self, pow_zero, mul_one, add_right_inj, ← mul_assoc, (h.symm.pow_right _).eq, mul_assoc, ← pow_succ'] refine sum_congr rfl fun i hi => ?_ suffices n - 1 - i + 1 = n - i by rw [this] rw [Finset.mem_range] at hi cutsat protected lemma Commute.geom_sum₂_Ico_mul (h : Commute x y) {m n : ℕ} (hmn : m ≤ n) : (∑ i ∈ Finset.Ico m n, x ^ i * y ^ (n - 1 - i)) * (x - y) = x ^ n - y ^ (n - m) * x ^ m := by apply op_injective simp only [op_sub, op_mul, op_pow, op_sum] have : (∑ k ∈ Ico m n, MulOpposite.op y ^ (n - 1 - k) * MulOpposite.op x ^ k) = ∑ k ∈ Ico m n, MulOpposite.op x ^ k * MulOpposite.op y ^ (n - 1 - k) := by refine sum_congr rfl fun k _ => ?_ have hp := Commute.pow_pow (Commute.op h.symm) (n - 1 - k) k simpa [Commute, SemiconjBy] using hp simp only [this] convert (Commute.op h).mul_geom_sum₂_Ico hmn lemma geom_sum_Ico_mul (x : R) {m n : ℕ} (hmn : m ≤ n) : (∑ i ∈ Finset.Ico m n, x ^ i) * (x - 1) = x ^ n - x ^ m := by rw [sum_Ico_eq_sub _ hmn, sub_mul, geom_sum_mul, geom_sum_mul, sub_sub_sub_cancel_right] lemma geom_sum_Ico_mul_neg (x : R) {m n : ℕ} (hmn : m ≤ n) : (∑ i ∈ Finset.Ico m n, x ^ i) * (1 - x) = x ^ m - x ^ n := by rw [sum_Ico_eq_sub _ hmn, sub_mul, geom_sum_mul_neg, geom_sum_mul_neg, sub_sub_sub_cancel_left] end Ring section CommRing variable [CommRing R] theorem pow_sub_one_mul_geom_sum_eq_pow_sub_one_mul_geom_sum {x : R} {m n : ℕ} : (x ^ m - 1) * ∑ k ∈ range n, x ^ k = (x ^ n - 1) * ∑ k ∈ range m, x ^ k := by grind [geom_sum_mul] @[deprecated (since := "2025-10-31")] protected alias IsPrimitiveRoot.pow_sub_one_mul_geom_sum_eq_pow_sub_one_mul_geom_sum := pow_sub_one_mul_geom_sum_eq_pow_sub_one_mul_geom_sum lemma geom_sum₂_mul (x y : R) (n : ℕ) : (∑ i ∈ range n, x ^ i * y ^ (n - 1 - i)) * (x - y) = x ^ n - y ^ n := (Commute.all x y).geom_sum₂_mul n lemma sub_dvd_pow_sub_pow (x y : R) (n : ℕ) : x - y ∣ x ^ n - y ^ n := (Commute.all x y).sub_dvd_pow_sub_pow n lemma Odd.add_dvd_pow_add_pow (x y : R) {n : ℕ} (h : Odd n) : x + y ∣ x ^ n + y ^ n := by have h₁ := geom_sum₂_mul x (-y) n rw [Odd.neg_pow h y, sub_neg_eq_add, sub_neg_eq_add] at h₁ exact Dvd.intro_left _ h₁ lemma geom_sum₂_succ_eq (x y : R) {n : ℕ} : ∑ i ∈ range (n + 1), x ^ i * y ^ (n - i) = x ^ n + y * ∑ i ∈ range n, x ^ i * y ^ (n - 1 - i) := (Commute.all x y).geom_sum₂_succ_eq lemma mul_geom_sum₂_Ico (x y : R) {m n : ℕ} (hmn : m ≤ n) : ((x - y) * ∑ i ∈ Finset.Ico m n, x ^ i * y ^ (n - 1 - i)) = x ^ n - x ^ m * y ^ (n - m) := (Commute.all x y).mul_geom_sum₂_Ico hmn end CommRing namespace Nat variable {m k : ℕ} (x y n : ℕ) protected lemma sub_dvd_pow_sub_pow : x - y ∣ x ^ n - y ^ n := by rcases le_or_gt y x with h | h · have : y ^ n ≤ x ^ n := Nat.pow_le_pow_left h _ exact mod_cast sub_dvd_pow_sub_pow (x : ℤ) (↑y) n · have : x ^ n ≤ y ^ n := Nat.pow_le_pow_left h.le _ exact (Nat.sub_eq_zero_of_le this).symm ▸ dvd_zero (x - y) @[deprecated (since := "2025-08-23")] alias nat_sub_dvd_pow_sub_pow := Nat.sub_dvd_pow_sub_pow lemma sub_one_dvd_pow_sub_one : x - 1 ∣ x ^ n - 1 := by simpa using x.sub_dvd_pow_sub_pow 1 n @[deprecated (since := "2025-08-23")] alias nat_pow_one_sub_dvd_pow_mul_sub_one := Nat.sub_one_dvd_pow_sub_one lemma pow_sub_pow_dvd_pow_sub_pow (hmk : m ∣ k) : x ^ m - y ^ m ∣ x ^ k - y ^ k := by obtain ⟨n, rfl⟩ := hmk; simpa [pow_mul] using (x ^ m).sub_dvd_pow_sub_pow (y ^ m) n lemma pow_sub_one_dvd_pow_sub_one (hmk : m ∣ k) : x ^ m - 1 ∣ x ^ k - 1 := by simpa using pow_sub_pow_dvd_pow_sub_pow x 1 hmk lemma _root_.Odd.nat_add_dvd_pow_add_pow {n : ℕ} (h : Odd n) : x + y ∣ x ^ n + y ^ n := mod_cast Odd.add_dvd_pow_add_pow (x : ℤ) (↑y) h /-- Value of a geometric sum over the naturals. Note: see `geom_sum_mul_add` for a formulation that avoids division and subtraction. -/ lemma geomSum_eq (hm : 2 ≤ m) (n : ℕ) : ∑ k ∈ range n, m ^ k = (m ^ n - 1) / (m - 1) := by refine (Nat.div_eq_of_eq_mul_left (tsub_pos_iff_lt.2 hm) <| tsub_eq_of_eq_add ?_).symm simpa only [tsub_add_cancel_of_le (by cutsat : 1 ≤ m), eq_comm] using geom_sum_mul_add (m - 1) n end Nat
.lake/packages/mathlib/Mathlib/Algebra/Ring/Centralizer.lean
import Mathlib.Algebra.Group.Center import Mathlib.Algebra.Ring.Defs /-! # Centralizers of rings -/ assert_not_exists RelIso variable {M : Type*} {S : Set M} namespace Set variable {a b} @[simp] theorem add_mem_centralizer [Distrib M] (ha : a ∈ centralizer S) (hb : b ∈ centralizer S) : a + b ∈ centralizer S := fun c hc => by rw [add_mul, mul_add, ha c hc, hb c hc] @[simp] theorem neg_mem_centralizer [Mul M] [HasDistribNeg M] (ha : a ∈ centralizer S) : -a ∈ centralizer S := fun c hc => by rw [mul_neg, ha c hc, neg_mul] end Set
.lake/packages/mathlib/Mathlib/Algebra/Ring/CharZero.lean
import Mathlib.Algebra.GroupWithZero.Units.Basic import Mathlib.Algebra.Notation.Support import Mathlib.Algebra.Ring.Units import Mathlib.Data.Nat.Cast.Basic import Mathlib.Logic.Embedding.Basic /-! # Characteristic zero rings -/ assert_not_exists Field open Function Set variable {α R S : Type*} {n : ℕ} section AddMonoidWithOne variable [AddMonoidWithOne R] [CharZero R] /-- `Nat.cast` as an embedding into monoids of characteristic `0`. -/ @[simps] def Nat.castEmbedding : ℕ ↪ R := ⟨Nat.cast, cast_injective⟩ instance CharZero.NeZero.two : NeZero (2 : R) where out := by rw [← Nat.cast_two, Nat.cast_ne_zero]; decide namespace Function lemma support_natCast (hn : n ≠ 0) : support (n : α → R) = univ := support_const <| Nat.cast_ne_zero.2 hn lemma mulSupport_natCast (hn : n ≠ 1) : mulSupport (n : α → R) = univ := mulSupport_const <| Nat.cast_ne_one.2 hn end Function end AddMonoidWithOne section NonAssocSemiring variable [NonAssocSemiring R] [NonAssocSemiring S] namespace RingHom lemma charZero (ϕ : R →+* S) [CharZero S] : CharZero R where cast_injective a b h := CharZero.cast_injective (R := S) <| by rw [← map_natCast ϕ, ← map_natCast ϕ, h] lemma charZero_iff {ϕ : R →+* S} (hϕ : Injective ϕ) : CharZero R ↔ CharZero S := ⟨fun hR => ⟨by intro a b h; rwa [← @Nat.cast_inj R, ← hϕ.eq_iff, map_natCast ϕ, map_natCast ϕ]⟩, fun _ => ϕ.charZero⟩ lemma injective_nat (f : ℕ →+* R) [CharZero R] : Injective f := Subsingleton.elim (Nat.castRingHom _) f ▸ Nat.cast_injective end RingHom variable [NoZeroDivisors R] [CharZero R] {a : R} @[simp] theorem add_self_eq_zero {a : R} : a + a = 0 ↔ a = 0 := by simp only [(two_mul a).symm, mul_eq_zero, two_ne_zero, false_or] end NonAssocSemiring section Semiring variable [Semiring R] [CharZero R] @[simp] lemma Nat.cast_pow_eq_one {a : ℕ} (hn : n ≠ 0) : (a : R) ^ n = 1 ↔ a = 1 := by simp [← cast_pow, cast_eq_one, hn] variable [IsCancelMulZero R] /-- A characteristic zero domain is torsion-free. -/ instance (priority := 100) IsAddTorsionFree.of_isCancelMulZero_charZero : IsAddTorsionFree R where nsmul_right_injective n hn a b hab := by let : CancelMonoidWithZero R := {}; simpa [hn] using hab end Semiring section NonAssocRing variable [NonAssocRing R] [NoZeroDivisors R] [CharZero R] @[scoped simp] theorem CharZero.neg_eq_self_iff {a : R} : -a = a ↔ a = 0 := neg_eq_iff_add_eq_zero.trans add_self_eq_zero @[scoped simp] theorem CharZero.eq_neg_self_iff {a : R} : a = -a ↔ a = 0 := eq_neg_iff_add_eq_zero.trans add_self_eq_zero theorem nat_mul_inj {n : ℕ} {a b : R} (h : (n : R) * a = (n : R) * b) : n = 0 ∨ a = b := by rw [← sub_eq_zero, ← mul_sub, mul_eq_zero, sub_eq_zero] at h exact mod_cast h theorem nat_mul_inj' {n : ℕ} {a b : R} (h : (n : R) * a = (n : R) * b) (w : n ≠ 0) : a = b := by simpa [w] using nat_mul_inj h end NonAssocRing section Ring variable [Ring R] [CharZero R] @[simp] theorem units_ne_neg_self (u : Rˣ) : u ≠ -u := by simp_rw [ne_eq, Units.ext_iff, Units.val_neg, eq_neg_iff_add_eq_zero, ← two_mul, Units.mul_left_eq_zero, two_ne_zero, not_false_iff] @[simp] theorem neg_units_ne_self (u : Rˣ) : -u ≠ u := (units_ne_neg_self u).symm end Ring
.lake/packages/mathlib/Mathlib/Algebra/Ring/Equiv.lean
import Mathlib.Algebra.Group.Equiv.Opposite import Mathlib.Algebra.GroupWithZero.Equiv import Mathlib.Algebra.GroupWithZero.InjSurj import Mathlib.Algebra.Notation.Prod import Mathlib.Algebra.Ring.Hom.Defs import Mathlib.Logic.Equiv.Set /-! # (Semi)ring equivs In this file we define an extension of `Equiv` called `RingEquiv`, which is a datatype representing an isomorphism of `Semiring`s, `Ring`s, `DivisionRing`s, or `Field`s. ## Notation * ``infixl ` ≃+* `:25 := RingEquiv`` The extended equiv have coercions to functions, and the coercion is the canonical notation when treating the isomorphism as maps. ## Implementation notes The fields for `RingEquiv` now avoid the unbundled `isMulHom` and `isAddHom`, as these are deprecated. Definition of multiplication in the groups of automorphisms agrees with function composition, multiplication in `Equiv.Perm`, and multiplication in `CategoryTheory.End`, not with `CategoryTheory.CategoryStruct.comp`. ## Tags Equiv, MulEquiv, AddEquiv, RingEquiv, MulAut, AddAut, RingAut -/ -- guard against import creep assert_not_exists Field Fintype variable {F α β R S S' : Type*} /-- makes a `NonUnitalRingHom` from the bijective inverse of a `NonUnitalRingHom` -/ @[simps] def NonUnitalRingHom.inverse [NonUnitalNonAssocSemiring R] [NonUnitalNonAssocSemiring S] (f : R →ₙ+* S) (g : S → R) (h₁ : Function.LeftInverse g f) (h₂ : Function.RightInverse g f) : S →ₙ+* R := { (f : R →+ S).inverse g h₁ h₂, (f : R →ₙ* S).inverse g h₁ h₂ with toFun := g } /-- makes a `RingHom` from the bijective inverse of a `RingHom` -/ @[simps] def RingHom.inverse [NonAssocSemiring R] [NonAssocSemiring S] (f : RingHom R S) (g : S → R) (h₁ : Function.LeftInverse g f) (h₂ : Function.RightInverse g f) : S →+* R := { (f : OneHom R S).inverse g h₁, (f : MulHom R S).inverse g h₁ h₂, (f : R →+ S).inverse g h₁ h₂ with toFun := g } /-- An equivalence between two (non-unital non-associative semi)rings that preserves the algebraic structure. -/ structure RingEquiv (R S : Type*) [Mul R] [Mul S] [Add R] [Add S] extends R ≃ S, R ≃* S, R ≃+ S /-- Notation for `RingEquiv`. -/ infixl:25 " ≃+* " => RingEquiv /-- The "plain" equivalence of types underlying an equivalence of (semi)rings. -/ add_decl_doc RingEquiv.toEquiv /-- The equivalence of additive monoids underlying an equivalence of (semi)rings. -/ add_decl_doc RingEquiv.toAddEquiv /-- The equivalence of multiplicative monoids underlying an equivalence of (semi)rings. -/ add_decl_doc RingEquiv.toMulEquiv /-- `RingEquivClass F R S` states that `F` is a type of ring structure preserving equivalences. You should extend this class when you extend `RingEquiv`. -/ class RingEquivClass (F R S : Type*) [Mul R] [Add R] [Mul S] [Add S] [EquivLike F R S] : Prop extends MulEquivClass F R S where /-- By definition, a ring isomorphism preserves the additive structure. -/ map_add : ∀ (f : F) (a b), f (a + b) = f a + f b namespace RingEquivClass variable [EquivLike F R S] -- See note [lower instance priority] instance (priority := 100) toAddEquivClass [Mul R] [Add R] [Mul S] [Add S] [h : RingEquivClass F R S] : AddEquivClass F R S := { h with } -- See note [lower instance priority] instance (priority := 100) toRingHomClass [NonAssocSemiring R] [NonAssocSemiring S] [h : RingEquivClass F R S] : RingHomClass F R S := { h with map_zero := map_zero map_one := map_one } -- See note [lower instance priority] instance (priority := 100) toNonUnitalRingHomClass [NonUnitalNonAssocSemiring R] [NonUnitalNonAssocSemiring S] [h : RingEquivClass F R S] : NonUnitalRingHomClass F R S := { h with map_zero := map_zero } /-- Turn an element of a type `F` satisfying `RingEquivClass F α β` into an actual `RingEquiv`. This is declared as the default coercion from `F` to `α ≃+* β`. -/ @[coe] def toRingEquiv [Mul α] [Add α] [Mul β] [Add β] [EquivLike F α β] [RingEquivClass F α β] (f : F) : α ≃+* β := { (f : α ≃* β), (f : α ≃+ β) with } end RingEquivClass /-- Any type satisfying `RingEquivClass` can be cast into `RingEquiv` via `RingEquivClass.toRingEquiv`. -/ instance [Mul α] [Add α] [Mul β] [Add β] [EquivLike F α β] [RingEquivClass F α β] : CoeTC F (α ≃+* β) := ⟨RingEquivClass.toRingEquiv⟩ namespace RingEquiv section Basic variable [Mul R] [Mul S] [Add R] [Add S] [Mul S'] [Add S'] section coe instance : EquivLike (R ≃+* S) R S where coe f := f.toFun inv f := f.invFun coe_injective' e f h₁ h₂ := by cases e cases f congr apply Equiv.coe_fn_injective h₁ left_inv f := f.left_inv right_inv f := f.right_inv instance : RingEquivClass (R ≃+* S) R S where map_add f := f.map_add' map_mul f := f.map_mul' /-- Two ring isomorphisms agree if they are defined by the same underlying function. -/ @[ext] theorem ext {f g : R ≃+* S} (h : ∀ x, f x = g x) : f = g := DFunLike.ext f g h protected theorem congr_arg {f : R ≃+* S} {x x' : R} : x = x' → f x = f x' := DFunLike.congr_arg f protected theorem congr_fun {f g : R ≃+* S} (h : f = g) (x : R) : f x = g x := DFunLike.congr_fun h x @[simp] theorem coe_mk (e h₃ h₄) : ⇑(⟨e, h₃, h₄⟩ : R ≃+* S) = e := rfl @[simp] theorem mk_coe (e : R ≃+* S) (e' h₁ h₂ h₃ h₄) : (⟨⟨e, e', h₁, h₂⟩, h₃, h₄⟩ : R ≃+* S) = e := ext fun _ => rfl @[simp] theorem toEquiv_eq_coe (f : R ≃+* S) : f.toEquiv = f := rfl @[simp] theorem coe_toEquiv (f : R ≃+* S) : ⇑(f : R ≃ S) = f := rfl @[simp] theorem toAddEquiv_eq_coe (f : R ≃+* S) : f.toAddEquiv = ↑f := rfl @[simp] theorem toMulEquiv_eq_coe (f : R ≃+* S) : f.toMulEquiv = ↑f := rfl @[simp, norm_cast] theorem coe_toMulEquiv (f : R ≃+* S) : ⇑(f : R ≃* S) = f := rfl @[simp] theorem coe_toAddEquiv (f : R ≃+* S) : ⇑(f : R ≃+ S) = f := rfl end coe section map /-- A ring isomorphism preserves multiplication. -/ protected theorem map_mul (e : R ≃+* S) (x y : R) : e (x * y) = e x * e y := map_mul e x y /-- A ring isomorphism preserves addition. -/ protected theorem map_add (e : R ≃+* S) (x y : R) : e (x + y) = e x + e y := map_add e x y end map section bijective protected theorem bijective (e : R ≃+* S) : Function.Bijective e := EquivLike.bijective e protected theorem injective (e : R ≃+* S) : Function.Injective e := EquivLike.injective e protected theorem surjective (e : R ≃+* S) : Function.Surjective e := EquivLike.surjective e end bijective variable (R) section refl /-- The identity map is a ring isomorphism. -/ @[refl] def refl : R ≃+* R := { MulEquiv.refl R, AddEquiv.refl R with } instance : Inhabited (R ≃+* R) := ⟨RingEquiv.refl R⟩ @[simp] theorem refl_apply (x : R) : RingEquiv.refl R x = x := rfl @[simp] theorem coe_refl (R : Type*) [Mul R] [Add R] : ⇑(RingEquiv.refl R) = id := rfl @[simp] theorem coe_addEquiv_refl : (RingEquiv.refl R : R ≃+ R) = AddEquiv.refl R := rfl @[simp] theorem coe_mulEquiv_refl : (RingEquiv.refl R : R ≃* R) = MulEquiv.refl R := rfl end refl variable {R} section symm /-- The inverse of a ring isomorphism is a ring isomorphism. -/ @[symm] protected def symm (e : R ≃+* S) : S ≃+* R := { e.toMulEquiv.symm, e.toAddEquiv.symm with } @[simp] theorem invFun_eq_symm (f : R ≃+* S) : EquivLike.inv f = f.symm := rfl @[simp] theorem symm_symm (e : R ≃+* S) : e.symm.symm = e := rfl theorem symm_bijective : Function.Bijective (RingEquiv.symm : (R ≃+* S) → S ≃+* R) := Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩ @[simp] theorem mk_coe' (e : R ≃+* S) (f h₁ h₂ h₃ h₄) : (⟨⟨f, ⇑e, h₁, h₂⟩, h₃, h₄⟩ : S ≃+* R) = e.symm := symm_bijective.injective <| ext fun _ => rfl /-- Auxiliary definition to avoid looping in `dsimp` with `RingEquiv.symm_mk`. -/ protected def symm_mk.aux (f : R → S) (g h₁ h₂ h₃ h₄) := (mk ⟨f, g, h₁, h₂⟩ h₃ h₄).symm @[simp] theorem symm_mk (f : R → S) (g h₁ h₂ h₃ h₄) : (mk ⟨f, g, h₁, h₂⟩ h₃ h₄).symm = { symm_mk.aux f g h₁ h₂ h₃ h₄ with toFun := g invFun := f } := rfl @[simp] theorem symm_refl : (RingEquiv.refl R).symm = RingEquiv.refl R := rfl @[simp] theorem coe_toEquiv_symm (e : R ≃+* S) : (e.symm : S ≃ R) = (e : R ≃ S).symm := rfl @[simp] theorem coe_toMulEquiv_symm (e : R ≃+* S) : (e.symm : S ≃* R) = (e : R ≃* S).symm := rfl @[simp] theorem coe_toAddEquiv_symm (e : R ≃+* S) : (e.symm : S ≃+ R) = (e : R ≃+ S).symm := rfl @[simp] theorem apply_symm_apply (e : R ≃+* S) : ∀ x, e (e.symm x) = x := e.toEquiv.apply_symm_apply @[simp] theorem symm_apply_apply (e : R ≃+* S) : ∀ x, e.symm (e x) = x := e.toEquiv.symm_apply_apply lemma image_symm_eq_preimage (e : R ≃+* S) (s : Set S) : e.symm '' s = e ⁻¹' s := e.toEquiv.image_symm_eq_preimage _ lemma image_eq_preimage_symm (e : R ≃+* S) (s : Set R) : e '' s = e.symm ⁻¹' s := e.toEquiv.image_eq_preimage_symm _ @[deprecated (since := "2025-11-05")] alias image_eq_preimage := image_eq_preimage_symm theorem symm_apply_eq (e : R ≃+* S) {x : S} {y : R} : e.symm x = y ↔ x = e y := Equiv.symm_apply_eq _ theorem eq_symm_apply (e : R ≃+* S) {x : S} {y : R} : y = e.symm x ↔ e y = x := Equiv.eq_symm_apply _ end symm section simps /-- See Note [custom simps projection] -/ def Simps.symm_apply (e : R ≃+* S) : S → R := e.symm initialize_simps_projections RingEquiv (toFun → apply, invFun → symm_apply) end simps section trans /-- Transitivity of `RingEquiv`. -/ @[trans] protected def trans (e₁ : R ≃+* S) (e₂ : S ≃+* S') : R ≃+* S' := { e₁.toMulEquiv.trans e₂.toMulEquiv, e₁.toAddEquiv.trans e₂.toAddEquiv with } @[simp] theorem coe_trans (e₁ : R ≃+* S) (e₂ : S ≃+* S') : (e₁.trans e₂ : R → S') = e₂ ∘ e₁ := rfl theorem trans_apply (e₁ : R ≃+* S) (e₂ : S ≃+* S') (a : R) : e₁.trans e₂ a = e₂ (e₁ a) := rfl @[simp] theorem symm_trans_apply (e₁ : R ≃+* S) (e₂ : S ≃+* S') (a : S') : (e₁.trans e₂).symm a = e₁.symm (e₂.symm a) := rfl theorem symm_trans (e₁ : R ≃+* S) (e₂ : S ≃+* S') : (e₁.trans e₂).symm = e₂.symm.trans e₁.symm := rfl @[simp] theorem coe_mulEquiv_trans (e₁ : R ≃+* S) (e₂ : S ≃+* S') : (e₁.trans e₂ : R ≃* S') = (e₁ : R ≃* S).trans ↑e₂ := rfl @[simp] theorem coe_addEquiv_trans (e₁ : R ≃+* S) (e₂ : S ≃+* S') : (e₁.trans e₂ : R ≃+ S') = (e₁ : R ≃+ S).trans ↑e₂ := rfl end trans section unique /-- The `RingEquiv` between two semirings with a unique element. -/ def ofUnique {M N} [Unique M] [Unique N] [Add M] [Mul M] [Add N] [Mul N] : M ≃+* N := { AddEquiv.ofUnique, MulEquiv.ofUnique with } instance {M N} [Unique M] [Unique N] [Add M] [Mul M] [Add N] [Mul N] : Unique (M ≃+* N) where default := .ofUnique uniq _ := ext fun _ => Subsingleton.elim _ _ end unique end Basic section Opposite open MulOpposite /-- A ring iso `α ≃+* β` can equivalently be viewed as a ring iso `αᵐᵒᵖ ≃+* βᵐᵒᵖ`. -/ @[simps! symm_apply_apply symm_apply_symm_apply apply_apply apply_symm_apply] protected def op {α β} [Add α] [Mul α] [Add β] [Mul β] : α ≃+* β ≃ (αᵐᵒᵖ ≃+* βᵐᵒᵖ) where toFun f := { AddEquiv.mulOp f.toAddEquiv, MulEquiv.op f.toMulEquiv with } invFun f := { AddEquiv.mulOp.symm f.toAddEquiv, MulEquiv.op.symm f.toMulEquiv with } /-- The 'unopposite' of a ring iso `αᵐᵒᵖ ≃+* βᵐᵒᵖ`. Inverse to `RingEquiv.op`. -/ @[simp] protected def unop {α β} [Add α] [Mul α] [Add β] [Mul β] : αᵐᵒᵖ ≃+* βᵐᵒᵖ ≃ (α ≃+* β) := RingEquiv.op.symm /-- A ring is isomorphic to the opposite of its opposite. -/ @[simps!] def opOp (R : Type*) [Add R] [Mul R] : R ≃+* Rᵐᵒᵖᵐᵒᵖ where __ := MulEquiv.opOp R map_add' _ _ := rfl section NonUnitalCommSemiring variable (R) [NonUnitalCommSemiring R] /-- A non-unital commutative ring is isomorphic to its opposite. -/ def toOpposite : R ≃+* Rᵐᵒᵖ := { MulOpposite.opEquiv with map_add' := fun _ _ => rfl map_mul' := fun x y => mul_comm (op y) (op x) } @[simp] theorem toOpposite_apply (r : R) : toOpposite R r = op r := rfl @[simp] theorem toOpposite_symm_apply (r : Rᵐᵒᵖ) : (toOpposite R).symm r = unop r := rfl end NonUnitalCommSemiring end Opposite section NonUnitalSemiring variable [NonUnitalNonAssocSemiring R] [NonUnitalNonAssocSemiring S] (f : R ≃+* S) (x : R) /-- A ring isomorphism sends zero to zero. -/ protected theorem map_zero : f 0 = 0 := map_zero f variable {x} protected theorem map_eq_zero_iff : f x = 0 ↔ x = 0 := EmbeddingLike.map_eq_zero_iff theorem map_ne_zero_iff : f x ≠ 0 ↔ x ≠ 0 := EmbeddingLike.map_ne_zero_iff variable [FunLike F R S] /-- Produce a ring isomorphism from a bijective ring homomorphism. -/ noncomputable def ofBijective [NonUnitalRingHomClass F R S] (f : F) (hf : Function.Bijective f) : R ≃+* S := { Equiv.ofBijective f hf with map_mul' := map_mul f map_add' := map_add f } @[simp] theorem coe_ofBijective [NonUnitalRingHomClass F R S] (f : F) (hf : Function.Bijective f) : (ofBijective f hf : R → S) = f := rfl theorem ofBijective_apply [NonUnitalRingHomClass F R S] (f : F) (hf : Function.Bijective f) (x : R) : ofBijective f hf x = f x := rfl @[simp] lemma ofBijective_symm_comp (f : R →ₙ+* S) (hf : Function.Bijective f) : ((RingEquiv.ofBijective f hf).symm : _ →ₙ+* _).comp f = NonUnitalRingHom.id R := by ext exact (RingEquiv.ofBijective f hf).injective <| RingEquiv.apply_symm_apply .. @[simp] lemma comp_ofBijective_symm (f : R →ₙ+* S) (hf : Function.Bijective f) : f.comp ((RingEquiv.ofBijective f hf).symm : _ →ₙ+* _) = NonUnitalRingHom.id S := by ext exact (RingEquiv.ofBijective f hf).symm.injective <| RingEquiv.apply_symm_apply .. /-- Product of a singleton family of (non-unital non-associative semi)rings is isomorphic to the only member of this family. -/ @[simps! -fullyApplied] def piUnique {ι : Type*} (R : ι → Type*) [Unique ι] [∀ i, NonUnitalNonAssocSemiring (R i)] : (∀ i, R i) ≃+* R default where __ := Equiv.piUnique R map_add' _ _ := rfl map_mul' _ _ := rfl /-- `Equiv.cast (congrArg _ h)` as a ring equiv. Note that unlike `Equiv.cast`, this takes an equality of indices rather than an equality of types, to avoid having to deal with an equality of the algebraic structure itself. -/ @[simps!] protected def cast {ι : Type*} {R : ι → Type*} [∀ i, Mul (R i)] [∀ i, Add (R i)] {i j : ι} (h : i = j) : R i ≃+* R j where __ := AddEquiv.cast h __ := MulEquiv.cast h /-- A family of ring isomorphisms `∀ j, (R j ≃+* S j)` generates a ring isomorphisms between `∀ j, R j` and `∀ j, S j`. This is the `RingEquiv` version of `Equiv.piCongrRight`, and the dependent version of `RingEquiv.arrowCongr`. -/ @[simps apply] def piCongrRight {ι : Type*} {R S : ι → Type*} [∀ i, NonUnitalNonAssocSemiring (R i)] [∀ i, NonUnitalNonAssocSemiring (S i)] (e : ∀ i, R i ≃+* S i) : (∀ i, R i) ≃+* ∀ i, S i := { @MulEquiv.piCongrRight ι R S _ _ fun i => (e i).toMulEquiv, @AddEquiv.piCongrRight ι R S _ _ fun i => (e i).toAddEquiv with toFun := fun x j => e j (x j) invFun := fun x j => (e j).symm (x j) } @[simp] theorem piCongrRight_refl {ι : Type*} {R : ι → Type*} [∀ i, NonUnitalNonAssocSemiring (R i)] : (piCongrRight fun i => RingEquiv.refl (R i)) = RingEquiv.refl _ := rfl @[simp] theorem piCongrRight_symm {ι : Type*} {R S : ι → Type*} [∀ i, NonUnitalNonAssocSemiring (R i)] [∀ i, NonUnitalNonAssocSemiring (S i)] (e : ∀ i, R i ≃+* S i) : (piCongrRight e).symm = piCongrRight fun i => (e i).symm := rfl @[simp] theorem piCongrRight_trans {ι : Type*} {R S T : ι → Type*} [∀ i, NonUnitalNonAssocSemiring (R i)] [∀ i, NonUnitalNonAssocSemiring (S i)] [∀ i, NonUnitalNonAssocSemiring (T i)] (e : ∀ i, R i ≃+* S i) (f : ∀ i, S i ≃+* T i) : (piCongrRight e).trans (piCongrRight f) = piCongrRight fun i => (e i).trans (f i) := rfl /-- Transport dependent functions through an equivalence of the base space. This is `Equiv.piCongrLeft'` as a `RingEquiv`. -/ @[simps!] def piCongrLeft' {ι ι' : Type*} (R : ι → Type*) (e : ι ≃ ι') [∀ i, NonUnitalNonAssocSemiring (R i)] : ((i : ι) → R i) ≃+* ((i : ι') → R (e.symm i)) where toEquiv := Equiv.piCongrLeft' R e map_mul' _ _ := rfl map_add' _ _ := rfl @[simp] theorem piCongrLeft'_symm {R : Type*} [NonUnitalNonAssocSemiring R] (e : α ≃ β) : (RingEquiv.piCongrLeft' (fun _ => R) e).symm = RingEquiv.piCongrLeft' _ e.symm := by simp only [piCongrLeft', RingEquiv.symm, MulEquiv.symm, Equiv.piCongrLeft'_symm] /-- Transport dependent functions through an equivalence of the base space. This is `Equiv.piCongrLeft` as a `RingEquiv`. -/ @[simps!] def piCongrLeft {ι ι' : Type*} (S : ι' → Type*) (e : ι ≃ ι') [∀ i, NonUnitalNonAssocSemiring (S i)] : ((i : ι) → S (e i)) ≃+* ((i : ι') → S i) := (RingEquiv.piCongrLeft' S e.symm).symm /-- Splits the indices of ring `∀ (i : ι), Y i` along the predicate `p`. This is `Equiv.piEquivPiSubtypeProd` as a `RingEquiv`. -/ @[simps!] def piEquivPiSubtypeProd {ι : Type*} (p : ι → Prop) [DecidablePred p] (Y : ι → Type*) [∀ i, NonUnitalNonAssocSemiring (Y i)] : ((i : ι) → Y i) ≃+* ((i : { x : ι // p x }) → Y i) × ((i : { x : ι // ¬p x }) → Y i) where toEquiv := Equiv.piEquivPiSubtypeProd p Y map_mul' _ _ := rfl map_add' _ _ := rfl /-- The opposite of a direct product is isomorphic to the direct product of the opposites as rings. -/ def piMulOpposite {ι : Type*} (S : ι → Type*) [∀ i, NonUnitalNonAssocSemiring (S i)] : (Π i, S i)ᵐᵒᵖ ≃+* Π i, (S i)ᵐᵒᵖ where toFun f i := .op (f.unop i) invFun f := .op fun i ↦ (f i).unop left_inv _ := rfl right_inv _ := rfl map_mul' _ _ := rfl map_add' _ _ := rfl /-- Product of ring equivalences. This is `Equiv.prodCongr` as a `RingEquiv`. -/ @[simps!] def prodCongr {R R' S S' : Type*} [NonUnitalNonAssocSemiring R] [NonUnitalNonAssocSemiring R'] [NonUnitalNonAssocSemiring S] [NonUnitalNonAssocSemiring S'] (f : R ≃+* R') (g : S ≃+* S') : R × S ≃+* R' × S' where toEquiv := Equiv.prodCongr f g map_mul' _ _ := by simp only [Equiv.toFun_as_coe, Equiv.prodCongr_apply, EquivLike.coe_coe, Prod.map, map_mul, Prod.mk_mul_mk] map_add' _ _ := by simp only [Equiv.toFun_as_coe, Equiv.prodCongr_apply, EquivLike.coe_coe, Prod.map, map_add, Prod.mk_add_mk] @[simp] theorem coe_prodCongr {R R' S S' : Type*} [NonUnitalNonAssocSemiring R] [NonUnitalNonAssocSemiring R'] [NonUnitalNonAssocSemiring S] [NonUnitalNonAssocSemiring S'] (f : R ≃+* R') (g : S ≃+* S') : ⇑(RingEquiv.prodCongr f g) = Prod.map f g := rfl /-- This is `Equiv.piOptionEquivProd` as a `RingEquiv`. -/ @[simps!] def piOptionEquivProd {ι : Type*} {R : Option ι → Type*} [Π i, NonUnitalNonAssocSemiring (R i)] : (Π i, R i) ≃+* R none × (Π i, R (some i)) where toEquiv := Equiv.piOptionEquivProd map_add' _ _ := rfl map_mul' _ _ := rfl end NonUnitalSemiring section Semiring variable [NonAssocSemiring R] [NonAssocSemiring S] (f : R ≃+* S) (x : R) /-- A ring isomorphism sends one to one. -/ protected theorem map_one : f 1 = 1 := map_one f variable {x} protected theorem map_eq_one_iff : f x = 1 ↔ x = 1 := EmbeddingLike.map_eq_one_iff theorem map_ne_one_iff : f x ≠ 1 ↔ x ≠ 1 := EmbeddingLike.map_ne_one_iff theorem coe_monoidHom_refl : (RingEquiv.refl R : R →* R) = MonoidHom.id R := rfl @[simp] theorem coe_addMonoidHom_refl : (RingEquiv.refl R : R →+ R) = AddMonoidHom.id R := rfl /-! `RingEquiv.coe_mulEquiv_refl` and `RingEquiv.coe_addEquiv_refl` are proved above in higher generality -/ @[simp] theorem coe_ringHom_refl : (RingEquiv.refl R : R →+* R) = RingHom.id R := rfl @[simp] theorem coe_monoidHom_trans [NonAssocSemiring S'] (e₁ : R ≃+* S) (e₂ : S ≃+* S') : (e₁.trans e₂ : R →* S') = (e₂ : S →* S').comp ↑e₁ := rfl @[simp] theorem coe_addMonoidHom_trans [NonUnitalNonAssocSemiring S'] (e₁ : R ≃+* S) (e₂ : S ≃+* S') : (e₁.trans e₂ : R →+ S') = (e₂ : S →+ S').comp ↑e₁ := rfl /-! `RingEquiv.coe_mulEquiv_trans` and `RingEquiv.coe_addEquiv_trans` are proved above in higher generality -/ @[simp] theorem coe_ringHom_trans [NonAssocSemiring S'] (e₁ : R ≃+* S) (e₂ : S ≃+* S') : (e₁.trans e₂ : R →+* S') = (e₂ : S →+* S').comp ↑e₁ := rfl @[simp] theorem comp_symm (e : R ≃+* S) : (e : R →+* S).comp (e.symm : S →+* R) = RingHom.id S := RingHom.ext e.apply_symm_apply @[simp] theorem symm_comp (e : R ≃+* S) : (e.symm : S →+* R).comp (e : R →+* S) = RingHom.id R := RingHom.ext e.symm_apply_apply end Semiring section NonUnitalRing variable [NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S] (f : R ≃+* S) (x y : R) protected theorem map_neg : f (-x) = -f x := map_neg f x protected theorem map_sub : f (x - y) = f x - f y := map_sub f x y end NonUnitalRing section Ring variable [NonAssocRing R] [NonAssocRing S] (f : R ≃+* S) @[simp] theorem map_neg_one : f (-1) = -1 := f.map_one ▸ f.map_neg 1 theorem map_eq_neg_one_iff {x : R} : f x = -1 ↔ x = -1 := by rw [← neg_eq_iff_eq_neg, ← neg_eq_iff_eq_neg, ← map_neg, RingEquiv.map_eq_one_iff] end Ring section NonUnitalSemiringHom variable [NonUnitalNonAssocSemiring R] [NonUnitalNonAssocSemiring S] [NonUnitalNonAssocSemiring S'] /-- Reinterpret a ring equivalence as a non-unital ring homomorphism. -/ def toNonUnitalRingHom (e : R ≃+* S) : R →ₙ+* S := { e.toMulEquiv.toMulHom, e.toAddEquiv.toAddMonoidHom with } theorem toNonUnitalRingHom_injective : Function.Injective (toNonUnitalRingHom : R ≃+* S → R →ₙ+* S) := fun _ _ h => RingEquiv.ext (NonUnitalRingHom.ext_iff.1 h) theorem toNonUnitalRingHom_eq_coe (f : R ≃+* S) : f.toNonUnitalRingHom = ↑f := rfl @[simp, norm_cast] theorem coe_toNonUnitalRingHom (f : R ≃+* S) : ⇑(f : R →ₙ+* S) = f := rfl theorem coe_nonUnitalRingHom_inj_iff {R S : Type*} [NonUnitalNonAssocSemiring R] [NonUnitalNonAssocSemiring S] (f g : R ≃+* S) : f = g ↔ (f : R →ₙ+* S) = g := ⟨fun h => by rw [h], fun h => ext <| NonUnitalRingHom.ext_iff.mp h⟩ @[simp] theorem toNonUnitalRingHom_refl : (RingEquiv.refl R).toNonUnitalRingHom = NonUnitalRingHom.id R := rfl @[simp] theorem toNonUnitalRingHom_apply_symm_toNonUnitalRingHom_apply (e : R ≃+* S) : ∀ y : S, e.toNonUnitalRingHom (e.symm.toNonUnitalRingHom y) = y := e.toEquiv.apply_symm_apply @[simp] theorem symm_toNonUnitalRingHom_apply_toNonUnitalRingHom_apply (e : R ≃+* S) : ∀ x : R, e.symm.toNonUnitalRingHom (e.toNonUnitalRingHom x) = x := Equiv.symm_apply_apply e.toEquiv @[simp] theorem toNonUnitalRingHom_trans (e₁ : R ≃+* S) (e₂ : S ≃+* S') : (e₁.trans e₂).toNonUnitalRingHom = e₂.toNonUnitalRingHom.comp e₁.toNonUnitalRingHom := rfl @[simp] theorem toNonUnitalRingHomm_comp_symm_toNonUnitalRingHom (e : R ≃+* S) : e.toNonUnitalRingHom.comp e.symm.toNonUnitalRingHom = NonUnitalRingHom.id _ := by ext simp @[simp] theorem symm_toNonUnitalRingHom_comp_toNonUnitalRingHom (e : R ≃+* S) : e.symm.toNonUnitalRingHom.comp e.toNonUnitalRingHom = NonUnitalRingHom.id _ := by ext simp end NonUnitalSemiringHom section SemiringHom variable [NonAssocSemiring R] [NonAssocSemiring S] [NonAssocSemiring S'] /-- Reinterpret a ring equivalence as a ring homomorphism. -/ def toRingHom (e : R ≃+* S) : R →+* S := { e.toMulEquiv.toMonoidHom, e.toAddEquiv.toAddMonoidHom with } theorem toRingHom_injective : Function.Injective (toRingHom : R ≃+* S → R →+* S) := fun _ _ h => RingEquiv.ext (RingHom.ext_iff.1 h) @[simp] theorem toRingHom_eq_coe (f : R ≃+* S) : f.toRingHom = ↑f := rfl @[simp, norm_cast] theorem coe_toRingHom (f : R ≃+* S) : ⇑(f : R →+* S) = f := rfl theorem coe_ringHom_inj_iff {R S : Type*} [NonAssocSemiring R] [NonAssocSemiring S] (f g : R ≃+* S) : f = g ↔ (f : R →+* S) = g := ⟨fun h => by rw [h], fun h => ext <| RingHom.ext_iff.mp h⟩ /-- The two paths coercion can take to a `NonUnitalRingEquiv` are equivalent -/ @[simp, norm_cast] theorem toNonUnitalRingHom_commutes (f : R ≃+* S) : ((f : R →+* S) : R →ₙ+* S) = (f : R →ₙ+* S) := rfl /-- Reinterpret a ring equivalence as a monoid homomorphism. -/ abbrev toMonoidHom (e : R ≃+* S) : R →* S := e.toRingHom.toMonoidHom /-- Reinterpret a ring equivalence as an `AddMonoid` homomorphism. -/ abbrev toAddMonoidHom (e : R ≃+* S) : R →+ S := e.toRingHom.toAddMonoidHom /-- The two paths coercion can take to an `AddMonoidHom` are equivalent -/ theorem toAddMonoidMom_commutes (f : R ≃+* S) : (f : R →+* S).toAddMonoidHom = (f : R ≃+ S).toAddMonoidHom := rfl /-- The two paths coercion can take to a `MonoidHom` are equivalent -/ theorem toMonoidHom_commutes (f : R ≃+* S) : (f : R →+* S).toMonoidHom = (f : R ≃* S).toMonoidHom := rfl /-- The two paths coercion can take to an `Equiv` are equivalent -/ theorem toEquiv_commutes (f : R ≃+* S) : (f : R ≃+ S).toEquiv = (f : R ≃* S).toEquiv := rfl @[simp] theorem toRingHom_refl : (RingEquiv.refl R).toRingHom = RingHom.id R := rfl @[simp] theorem toMonoidHom_refl : (RingEquiv.refl R).toMonoidHom = MonoidHom.id R := rfl @[simp] theorem toAddMonoidHom_refl : (RingEquiv.refl R).toAddMonoidHom = AddMonoidHom.id R := rfl theorem toRingHom_apply_symm_toRingHom_apply (e : R ≃+* S) : ∀ y : S, e.toRingHom (e.symm.toRingHom y) = y := e.toEquiv.apply_symm_apply theorem symm_toRingHom_apply_toRingHom_apply (e : R ≃+* S) : ∀ x : R, e.symm.toRingHom (e.toRingHom x) = x := Equiv.symm_apply_apply e.toEquiv @[simp] theorem toRingHom_trans (e₁ : R ≃+* S) (e₂ : S ≃+* S') : (e₁.trans e₂).toRingHom = e₂.toRingHom.comp e₁.toRingHom := rfl theorem toRingHom_comp_symm_toRingHom (e : R ≃+* S) : e.toRingHom.comp e.symm.toRingHom = RingHom.id _ := by simp theorem symm_toRingHom_comp_toRingHom (e : R ≃+* S) : e.symm.toRingHom.comp e.toRingHom = RingHom.id _ := by simp /-- Construct an equivalence of rings from homomorphisms in both directions, which are inverses. -/ @[simps] def ofHomInv' {R S F G : Type*} [NonUnitalNonAssocSemiring R] [NonUnitalNonAssocSemiring S] [FunLike F R S] [FunLike G S R] [NonUnitalRingHomClass F R S] [NonUnitalRingHomClass G S R] (hom : F) (inv : G) (hom_inv_id : (inv : S →ₙ+* R).comp (hom : R →ₙ+* S) = NonUnitalRingHom.id R) (inv_hom_id : (hom : R →ₙ+* S).comp (inv : S →ₙ+* R) = NonUnitalRingHom.id S) : R ≃+* S where toFun := hom invFun := inv left_inv := DFunLike.congr_fun hom_inv_id right_inv := DFunLike.congr_fun inv_hom_id map_mul' := map_mul hom map_add' := map_add hom /-- Construct an equivalence of rings from unital homomorphisms in both directions, which are inverses. -/ @[simps] def ofHomInv {R S F G : Type*} [NonAssocSemiring R] [NonAssocSemiring S] [FunLike F R S] [FunLike G S R] [RingHomClass F R S] [RingHomClass G S R] (hom : F) (inv : G) (hom_inv_id : (inv : S →+* R).comp (hom : R →+* S) = RingHom.id R) (inv_hom_id : (hom : R →+* S).comp (inv : S →+* R) = RingHom.id S) : R ≃+* S where toFun := hom invFun := inv left_inv := DFunLike.congr_fun hom_inv_id right_inv := DFunLike.congr_fun inv_hom_id map_mul' := map_mul hom map_add' := map_add hom end SemiringHom variable [Semiring R] [Semiring S] section GroupPower protected theorem map_pow (f : R ≃+* S) (a) : ∀ n : ℕ, f (a ^ n) = f a ^ n := map_pow f a end GroupPower end RingEquiv namespace MulEquiv /-- Gives a `RingEquiv` from an element of a `MulEquivClass` preserving addition. -/ def toRingEquiv {R S F : Type*} [Add R] [Add S] [Mul R] [Mul S] [EquivLike F R S] [MulEquivClass F R S] (f : F) (H : ∀ x y : R, f (x + y) = f x + f y) : R ≃+* S := { (f : R ≃* S).toEquiv, (f : R ≃* S), AddEquiv.mk' (f : R ≃* S).toEquiv H with } end MulEquiv namespace AddEquiv /-- Gives a `RingEquiv` from an element of an `AddEquivClass` preserving addition. -/ def toRingEquiv {R S F : Type*} [Add R] [Add S] [Mul R] [Mul S] [EquivLike F R S] [AddEquivClass F R S] (f : F) (H : ∀ x y : R, f (x * y) = f x * f y) : R ≃+* S := { (f : R ≃+ S).toEquiv, (f : R ≃+ S), MulEquiv.mk' (f : R ≃+ S).toEquiv H with } end AddEquiv namespace RingEquiv variable [Add R] [Add S] [Mul R] [Mul S] @[simp] theorem self_trans_symm (e : R ≃+* S) : e.trans e.symm = RingEquiv.refl R := ext e.left_inv @[simp] theorem symm_trans_self (e : R ≃+* S) : e.symm.trans e = RingEquiv.refl S := ext e.right_inv end RingEquiv namespace RingEquiv variable [NonAssocSemiring R] [NonAssocSemiring S] /-- If a ring homomorphism has an inverse, it is a ring isomorphism. -/ @[simps] def ofRingHom (f : R →+* S) (g : S →+* R) (h₁ : f.comp g = RingHom.id S) (h₂ : g.comp f = RingHom.id R) : R ≃+* S := { f with toFun := f invFun := g left_inv := RingHom.ext_iff.1 h₂ right_inv := RingHom.ext_iff.1 h₁ } theorem coe_ringHom_ofRingHom (f : R →+* S) (g : S →+* R) (h₁ h₂) : ofRingHom f g h₁ h₂ = f := rfl @[simp] theorem ofRingHom_coe_ringHom (f : R ≃+* S) (g : S →+* R) (h₁ h₂) : ofRingHom (↑f) g h₁ h₂ = f := ext fun _ ↦ rfl theorem ofRingHom_symm (f : R →+* S) (g : S →+* R) (h₁ h₂) : (ofRingHom f g h₁ h₂).symm = ofRingHom g f h₂ h₁ := rfl variable (α β R) in /-- `Equiv.sumArrowEquivProdArrow` as a ring isomorphism. -/ def sumArrowEquivProdArrow : (α ⊕ β → R) ≃+* (α → R) × (β → R) where __ := Equiv.sumArrowEquivProdArrow α β R map_mul' _ _ := rfl map_add' _ _ := rfl -- Priority `low` to ensure generic `map_{add, mul, zero, one}` lemmas are applied first @[simp low] lemma sumArrowEquivProdArrow_apply (x) : sumArrowEquivProdArrow α β R x = Equiv.sumArrowEquivProdArrow α β R x := rfl -- Priority `low` to ensure generic `map_{add, mul, zero, one}` lemmas are applied first @[simp low] lemma sumArrowEquivProdArrow_symm_apply (x : (α → R) × (β → R)) : (sumArrowEquivProdArrow α β R).symm x = (Equiv.sumArrowEquivProdArrow α β R).symm x := rfl end RingEquiv namespace MulEquiv /-- If two rings are isomorphic, and the second doesn't have zero divisors, then so does the first. -/ protected theorem noZeroDivisors {A : Type*} (B : Type*) [MulZeroClass A] [MulZeroClass B] [NoZeroDivisors B] (e : A ≃* B) : NoZeroDivisors A := e.injective.noZeroDivisors e (map_zero e) (map_mul e) /-- If two rings are isomorphic, and the second is a domain, then so is the first. -/ protected theorem isDomain {A : Type*} (B : Type*) [Semiring A] [Semiring B] [IsDomain B] (e : A ≃* B) : IsDomain A := { e.injective.isLeftCancelMulZero e (map_zero e) (map_mul e), e.injective.isRightCancelMulZero e (map_zero e) (map_mul e) with exists_pair_ne := ⟨e.symm 0, e.symm 1, e.symm.injective.ne zero_ne_one⟩ } theorem isDomain_iff {A B : Type*} [Semiring A] [Semiring B] (e : A ≃* B) : IsDomain A ↔ IsDomain B where mp _ := e.symm.isDomain mpr _ := e.isDomain variable {A B : Type*} [MulZeroClass A] [MulZeroClass B] theorem noZeroDivisors_iff (e : A ≃* B) : NoZeroDivisors A ↔ NoZeroDivisors B where mp _ := e.symm.noZeroDivisors mpr _ := e.noZeroDivisors theorem isLeftCancelMulZero_iff (e : A ≃* B) : IsLeftCancelMulZero A ↔ IsLeftCancelMulZero B where mp _ := e.symm.injective.isLeftCancelMulZero _ (map_zero _) (map_mul _) mpr _ := e.injective.isLeftCancelMulZero _ (map_zero _) (map_mul _) theorem isRightCancelMulZero_iff (e : A ≃* B) : IsRightCancelMulZero A ↔ IsRightCancelMulZero B where mp _ := e.symm.injective.isRightCancelMulZero _ (map_zero _) (map_mul _) mpr _ := e.injective.isRightCancelMulZero _ (map_zero _) (map_mul _) theorem isCancelMulZero_iff (e : A ≃* B) : IsCancelMulZero A ↔ IsCancelMulZero B where mp _ := e.symm.injective.isCancelMulZero _ (map_zero _) (map_mul _) mpr _ := e.injective.isCancelMulZero _ (map_zero _) (map_mul _) end MulEquiv
.lake/packages/mathlib/Mathlib/Algebra/Ring/Periodic.lean
import Mathlib.Algebra.Ring.NegOnePow /-! # Periodicity In this file we define and then prove facts about periodic and antiperiodic functions. ## 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 Field variable {α β γ : Type*} {f g : α → β} {c c₁ c₂ x : α} open Set namespace Function /-! ### Periodicity -/ /-- A function `f` is said to be `Periodic` with period `c` if for all `x`, `f (x + c) = f x`. -/ @[simp] def Periodic [Add α] (f : α → β) (c : α) : Prop := ∀ x : α, f (x + c) = f x protected theorem Periodic.funext [Add α] (h : Periodic f c) : (fun x => f (x + c)) = f := funext h protected theorem Periodic.comp [Add α] (h : Periodic f c) (g : β → γ) : Periodic (g ∘ f) c := by simp_all theorem Periodic.comp_addHom [Add α] [Add γ] (h : Periodic f c) (g : AddHom γ α) (g_inv : α → γ) (hg : RightInverse g_inv g) : Periodic (f ∘ g) (g_inv c) := fun x => by simp only [hg c, h (g x), map_add, comp_apply] @[to_additive] protected theorem Periodic.mul [Add α] [Mul β] (hf : Periodic f c) (hg : Periodic g c) : Periodic (f * g) c := by simp_all @[to_additive] protected theorem Periodic.div [Add α] [Div β] (hf : Periodic f c) (hg : Periodic g c) : Periodic (f / g) c := by simp_all @[to_additive] theorem _root_.List.periodic_prod [Add α] [MulOneClass β] (l : List (α → β)) (hl : ∀ f ∈ l, Periodic f c) : Periodic l.prod c := by induction l with | nil => simp | cons g l ih => rw [List.forall_mem_cons] at hl simpa only [List.prod_cons] using hl.1.mul (ih hl.2) @[to_additive] theorem _root_.Multiset.periodic_prod [Add α] [CommMonoid β] (s : Multiset (α → β)) (hs : ∀ f ∈ s, Periodic f c) : Periodic s.prod c := (s.prod_toList ▸ s.toList.periodic_prod) fun f hf => hs f <| Multiset.mem_toList.mp hf @[to_additive] theorem _root_.Finset.periodic_prod [Add α] [CommMonoid β] {ι : Type*} {f : ι → α → β} (s : Finset ι) (hs : ∀ i ∈ s, Periodic (f i) c) : Periodic (∏ i ∈ s, f i) c := s.prod_map_toList f ▸ (s.toList.map f).periodic_prod (by simpa [-Periodic] ) @[to_additive] protected theorem Periodic.smul [Add α] [SMul γ β] (h : Periodic f c) (a : γ) : Periodic (a • f) c := by simp_all protected theorem Periodic.const_smul [AddMonoid α] [Group γ] [DistribMulAction γ α] (h : Periodic f c) (a : γ) : Periodic (fun x => f (a • x)) (a⁻¹ • c) := fun x => by simpa only [smul_add, smul_inv_smul] using h (a • x) theorem Periodic.const_inv_smul [AddMonoid α] [Group γ] [DistribMulAction γ α] (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.add_period [AddSemigroup α] (h1 : Periodic f c₁) (h2 : Periodic f c₂) : Periodic f (c₁ + c₂) := by simp_all [← add_assoc] theorem Periodic.sub_eq [AddGroup α] (h : Periodic f c) (x : α) : f (x - c) = f x := by simpa only [sub_add_cancel] using (h (x - c)).symm theorem Periodic.sub_eq' [SubtractionCommMonoid α] (h : Periodic f c) : f (c - x) = f (-x) := by simpa only [sub_eq_neg_add] using h (-x) protected theorem Periodic.neg [AddGroup α] (h : Periodic f c) : Periodic f (-c) := by simpa only [sub_eq_add_neg, Periodic] using h.sub_eq theorem Periodic.sub_period [AddGroup α] (h1 : Periodic f c₁) (h2 : Periodic f c₂) : Periodic f (c₁ - c₂) := fun x => by rw [sub_eq_add_neg, ← add_assoc, h2.neg, h1] theorem Periodic.const_add [AddSemigroup α] (h : Periodic f c) (a : α) : Periodic (fun x => f (a + x)) c := fun x => by simpa [add_assoc] using h (a + x) theorem Periodic.add_const [AddCommSemigroup α] (h : Periodic f c) (a : α) : Periodic (fun x => f (x + a)) c := fun x => by simpa only [add_right_comm] using h (x + a) theorem Periodic.const_sub [AddCommGroup α] (h : Periodic f c) (a : α) : Periodic (fun x => f (a - x)) c := fun x => by simp only [← sub_sub, h.sub_eq] theorem Periodic.sub_const [SubtractionCommMonoid α] (h : Periodic f c) (a : α) : Periodic (fun x => f (x - a)) c := by simpa only [sub_eq_add_neg] using h.add_const (-a) theorem Periodic.nsmul [AddMonoid α] (h : Periodic f c) (n : ℕ) : Periodic f (n • c) := by induction n <;> simp_all [add_nsmul, ← add_assoc] theorem Periodic.nat_mul [NonAssocSemiring α] (h : Periodic f c) (n : ℕ) : Periodic f (n * c) := by simpa only [nsmul_eq_mul] using h.nsmul n theorem Periodic.neg_nsmul [AddGroup α] (h : Periodic f c) (n : ℕ) : Periodic f (-(n • c)) := (h.nsmul n).neg theorem Periodic.neg_nat_mul [NonAssocRing α] (h : Periodic f c) (n : ℕ) : Periodic f (-(n * c)) := (h.nat_mul n).neg theorem Periodic.sub_nsmul_eq [AddGroup α] (h : Periodic f c) (n : ℕ) : f (x - n • c) = f x := by simpa only [sub_eq_add_neg] using h.neg_nsmul n x theorem Periodic.sub_nat_mul_eq [NonAssocRing α] (h : Periodic f c) (n : ℕ) : f (x - n * c) = f x := by simpa only [nsmul_eq_mul] using h.sub_nsmul_eq n theorem Periodic.nsmul_sub_eq [SubtractionCommMonoid α] (h : Periodic f c) (n : ℕ) : f (n • c - x) = f (-x) := (h.nsmul n).sub_eq' theorem Periodic.nat_mul_sub_eq [NonAssocRing α] (h : Periodic f c) (n : ℕ) : f (n * c - x) = f (-x) := by simpa only [sub_eq_neg_add] using h.nat_mul n (-x) protected theorem Periodic.zsmul [AddGroup α] (h : Periodic f c) (n : ℤ) : Periodic f (n • c) := by rcases n with n | n · simpa only [Int.ofNat_eq_coe, natCast_zsmul] using h.nsmul n · simpa only [negSucc_zsmul] using (h.nsmul (n + 1)).neg protected theorem Periodic.int_mul [NonAssocRing α] (h : Periodic f c) (n : ℤ) : Periodic f (n * c) := by simpa only [zsmul_eq_mul] using h.zsmul n theorem Periodic.sub_zsmul_eq [AddGroup α] (h : Periodic f c) (n : ℤ) : f (x - n • c) = f x := (h.zsmul n).sub_eq x theorem Periodic.sub_int_mul_eq [NonAssocRing α] (h : Periodic f c) (n : ℤ) : f (x - n * c) = f x := (h.int_mul n).sub_eq x theorem Periodic.zsmul_sub_eq [AddCommGroup α] (h : Periodic f c) (n : ℤ) : f (n • c - x) = f (-x) := (h.zsmul _).sub_eq' theorem Periodic.int_mul_sub_eq [NonAssocRing α] (h : Periodic f c) (n : ℤ) : f (n * c - x) = f (-x) := (h.int_mul _).sub_eq' protected theorem Periodic.eq [AddZeroClass α] (h : Periodic f c) : f c = f 0 := by simpa only [zero_add] using h 0 protected theorem Periodic.neg_eq [AddGroup α] (h : Periodic f c) : f (-c) = f 0 := h.neg.eq protected theorem Periodic.nsmul_eq [AddMonoid α] (h : Periodic f c) (n : ℕ) : f (n • c) = f 0 := (h.nsmul n).eq theorem Periodic.nat_mul_eq [NonAssocSemiring α] (h : Periodic f c) (n : ℕ) : f (n * c) = f 0 := (h.nat_mul n).eq theorem Periodic.zsmul_eq [AddGroup α] (h : Periodic f c) (n : ℤ) : f (n • c) = f 0 := (h.zsmul n).eq theorem Periodic.int_mul_eq [NonAssocRing α] (h : Periodic f c) (n : ℤ) : f (n * c) = f 0 := (h.int_mul n).eq theorem periodic_with_period_zero [AddZeroClass α] (f : α → β) : Periodic f 0 := fun x => by rw [add_zero] /-- The iterates `a`, `f a`, `f^[2] a` etc form a periodic sequence with period `n` iff `a` is a periodic point for `f`. -/ theorem periodic_iterate_iff {f : α → α} {n : ℕ} {a : α} : Periodic (f^[·] a) n ↔ IsPeriodicPt f n a := by refine ⟨fun h ↦ h.eq, fun h k ↦ ?_⟩ simp only [Function.iterate_add_apply, h.eq] alias ⟨Periodic.isPeriodicPt, IsPeriodicPt.periodic_iterate⟩ := periodic_iterate_iff theorem Periodic.map_vadd_zmultiples [AddCommGroup α] (hf : Periodic f c) (a : AddSubgroup.zmultiples c) (x : α) : f (a +ᵥ x) = f x := by rcases a with ⟨_, m, rfl⟩ simp [AddSubgroup.vadd_def, add_comm _ x, hf.zsmul m x] theorem Periodic.map_vadd_multiples [AddCommMonoid α] (hf : Periodic f c) (a : AddSubmonoid.multiples c) (x : α) : f (a +ᵥ x) = f x := by rcases a with ⟨_, m, rfl⟩ simp [AddSubmonoid.vadd_def, add_comm _ x, hf.nsmul m x] /-- Lift a periodic function to a function from the quotient group. -/ def Periodic.lift [AddGroup α] (h : Periodic f c) (x : α ⧸ AddSubgroup.zmultiples c) : β := Quotient.liftOn' x f fun a b h' => by rw [QuotientAddGroup.leftRel_apply] at h' obtain ⟨k, hk⟩ := h' exact (h.zsmul k _).symm.trans (congr_arg f (add_eq_of_eq_neg_add hk)) @[simp] theorem Periodic.lift_coe [AddGroup α] (h : Periodic f c) (a : α) : h.lift (a : α ⧸ AddSubgroup.zmultiples c) = f a := rfl /-- A periodic function `f : R → X` on a semiring (or, more generally, `AddZeroClass`) of non-zero period is not injective. -/ lemma Periodic.not_injective {R X : Type*} [AddZeroClass R] {f : R → X} {c : R} (hf : Periodic f c) (hc : c ≠ 0) : ¬ Injective f := fun h ↦ hc <| h hf.eq /-! ### Antiperiodicity -/ /-- A function `f` is said to be `antiperiodic` with antiperiod `c` if for all `x`, `f (x + c) = -f x`. -/ @[simp] def Antiperiodic [Add α] [Neg β] (f : α → β) (c : α) : Prop := ∀ x : α, f (x + c) = -f x protected theorem Antiperiodic.funext [Add α] [Neg β] (h : Antiperiodic f c) : (fun x => f (x + c)) = -f := funext h protected theorem Antiperiodic.funext' [Add α] [InvolutiveNeg β] (h : Antiperiodic f c) : (fun x => -f (x + c)) = f := neg_eq_iff_eq_neg.mpr h.funext /-- If a function is `antiperiodic` with antiperiod `c`, then it is also `Periodic` with period `2 • c`. -/ protected theorem Antiperiodic.periodic [AddMonoid α] [InvolutiveNeg β] (h : Antiperiodic f c) : Periodic f (2 • c) := by simp [two_nsmul, ← add_assoc, h _] /-- If a function is `antiperiodic` with antiperiod `c`, then it is also `Periodic` with period `2 * c`. -/ protected theorem Antiperiodic.periodic_two_mul [NonAssocSemiring α] [InvolutiveNeg β] (h : Antiperiodic f c) : Periodic f (2 * c) := nsmul_eq_mul 2 c ▸ h.periodic protected theorem Antiperiodic.eq [AddZeroClass α] [Neg β] (h : Antiperiodic f c) : f c = -f 0 := by simpa only [zero_add] using h 0 theorem Antiperiodic.even_nsmul_periodic [AddMonoid α] [InvolutiveNeg β] (h : Antiperiodic f c) (n : ℕ) : Periodic f ((2 * n) • c) := mul_nsmul c 2 n ▸ h.periodic.nsmul n theorem Antiperiodic.nat_even_mul_periodic [NonAssocSemiring α] [InvolutiveNeg β] (h : Antiperiodic f c) (n : ℕ) : Periodic f (n * (2 * c)) := h.periodic_two_mul.nat_mul n theorem Antiperiodic.odd_nsmul_antiperiodic [AddMonoid α] [InvolutiveNeg β] (h : Antiperiodic f c) (n : ℕ) : Antiperiodic f ((2 * n + 1) • c) := fun x => by rw [add_nsmul, one_nsmul, ← add_assoc, h, h.even_nsmul_periodic] theorem Antiperiodic.nat_odd_mul_antiperiodic [NonAssocSemiring α] [InvolutiveNeg β] (h : Antiperiodic f c) (n : ℕ) : Antiperiodic f (n * (2 * c) + c) := fun x => by rw [← add_assoc, h, h.nat_even_mul_periodic] theorem Antiperiodic.even_zsmul_periodic [AddGroup α] [InvolutiveNeg β] (h : Antiperiodic f c) (n : ℤ) : Periodic f ((2 * n) • c) := by rw [mul_comm, mul_zsmul, two_zsmul, ← two_nsmul] exact h.periodic.zsmul n theorem Antiperiodic.int_even_mul_periodic [NonAssocRing α] [InvolutiveNeg β] (h : Antiperiodic f c) (n : ℤ) : Periodic f (n * (2 * c)) := h.periodic_two_mul.int_mul n theorem Antiperiodic.odd_zsmul_antiperiodic [AddGroup α] [InvolutiveNeg β] (h : Antiperiodic f c) (n : ℤ) : Antiperiodic f ((2 * n + 1) • c) := by intro x rw [add_zsmul, one_zsmul, ← add_assoc, h, h.even_zsmul_periodic] theorem Antiperiodic.int_odd_mul_antiperiodic [NonAssocRing α] [InvolutiveNeg β] (h : Antiperiodic f c) (n : ℤ) : Antiperiodic f (n * (2 * c) + c) := fun x => by rw [← add_assoc, h, h.int_even_mul_periodic] theorem Antiperiodic.sub_eq [AddGroup α] [InvolutiveNeg β] (h : Antiperiodic f c) (x : α) : f (x - c) = -f x := by simp only [← neg_eq_iff_eq_neg, ← h (x - c), sub_add_cancel] theorem Antiperiodic.sub_eq' [SubtractionCommMonoid α] [Neg β] (h : Antiperiodic f c) : f (c - x) = -f (-x) := by simpa only [sub_eq_neg_add] using h (-x) protected theorem Antiperiodic.neg [AddGroup α] [InvolutiveNeg β] (h : Antiperiodic f c) : Antiperiodic f (-c) := by simpa only [sub_eq_add_neg, Antiperiodic] using h.sub_eq theorem Antiperiodic.neg_eq [AddGroup α] [InvolutiveNeg β] (h : Antiperiodic f c) : f (-c) = -f 0 := by simpa only [zero_add] using h.neg 0 theorem Antiperiodic.nat_mul_eq_of_eq_zero [NonAssocSemiring α] [NegZeroClass β] (h : Antiperiodic f c) (hi : f 0 = 0) : ∀ n : ℕ, f (n * c) = 0 | 0 => by rwa [Nat.cast_zero, zero_mul] | n + 1 => by simp [add_mul, h _, Antiperiodic.nat_mul_eq_of_eq_zero h hi n] theorem Antiperiodic.int_mul_eq_of_eq_zero [NonAssocRing α] [SubtractionMonoid β] (h : Antiperiodic f c) (hi : f 0 = 0) : ∀ n : ℤ, f (n * c) = 0 | (n : ℕ) => by rw [Int.cast_natCast, h.nat_mul_eq_of_eq_zero hi n] | .negSucc n => by rw [Int.cast_negSucc, neg_mul, ← mul_neg, h.neg.nat_mul_eq_of_eq_zero hi] theorem Antiperiodic.add_zsmul_eq [AddGroup α] [SubtractionMonoid β] (h : Antiperiodic f c) (n : ℤ) : f (x + n • c) = (n.negOnePow : ℤ) • f x := by rcases Int.even_or_odd' n with ⟨k, rfl | rfl⟩ · rw [h.even_zsmul_periodic, Int.negOnePow_two_mul, Units.val_one, one_zsmul] · rw [h.odd_zsmul_antiperiodic, Int.negOnePow_two_mul_add_one, Units.val_neg, Units.val_one, neg_zsmul, one_zsmul] theorem Antiperiodic.sub_zsmul_eq [AddGroup α] [SubtractionMonoid β] (h : Antiperiodic f c) (n : ℤ) : f (x - n • c) = (n.negOnePow : ℤ) • f x := by simpa only [sub_eq_add_neg, neg_zsmul, Int.negOnePow_neg] using h.add_zsmul_eq (-n) theorem Antiperiodic.zsmul_sub_eq [AddCommGroup α] [SubtractionMonoid β] (h : Antiperiodic f c) (n : ℤ) : f (n • c - x) = (n.negOnePow : ℤ) • f (-x) := by rw [sub_eq_add_neg, add_comm] exact h.add_zsmul_eq n theorem Antiperiodic.add_int_mul_eq [NonAssocRing α] [NonAssocRing β] (h : Antiperiodic f c) (n : ℤ) : f (x + n * c) = (n.negOnePow : ℤ) * f x := by simpa only [zsmul_eq_mul] using h.add_zsmul_eq n theorem Antiperiodic.sub_int_mul_eq [NonAssocRing α] [NonAssocRing β] (h : Antiperiodic f c) (n : ℤ) : f (x - n * c) = (n.negOnePow : ℤ) * f x := by simpa only [zsmul_eq_mul] using h.sub_zsmul_eq n theorem Antiperiodic.int_mul_sub_eq [NonAssocRing α] [NonAssocRing β] (h : Antiperiodic f c) (n : ℤ) : f (n * c - x) = (n.negOnePow : ℤ) * f (-x) := by simpa only [zsmul_eq_mul] using h.zsmul_sub_eq n theorem Antiperiodic.add_nsmul_eq [AddMonoid α] [SubtractionMonoid β] (h : Antiperiodic f c) (n : ℕ) : f (x + n • c) = (-1) ^ n • f x := by rcases Nat.even_or_odd' n with ⟨k, rfl | rfl⟩ · rw [h.even_nsmul_periodic] simp · rw [h.odd_nsmul_antiperiodic] simp [pow_add] theorem Antiperiodic.sub_nsmul_eq [AddGroup α] [SubtractionMonoid β] (h : Antiperiodic f c) (n : ℕ) : f (x - n • c) = (-1) ^ n • f x := by simpa only [Int.reduceNeg, natCast_zsmul] using h.sub_zsmul_eq n theorem Antiperiodic.nsmul_sub_eq [AddCommGroup α] [SubtractionMonoid β] (h : Antiperiodic f c) (n : ℕ) : f (n • c - x) = (-1) ^ n • f (-x) := by simpa only [Int.reduceNeg, natCast_zsmul] using h.zsmul_sub_eq n theorem Antiperiodic.const_add [AddSemigroup α] [Neg β] (h : Antiperiodic f c) (a : α) : Antiperiodic (fun x => f (a + x)) c := fun x => by simpa [add_assoc] using h (a + x) theorem Antiperiodic.add_const [AddCommSemigroup α] [Neg β] (h : Antiperiodic f c) (a : α) : Antiperiodic (fun x => f (x + a)) c := fun x => by simpa only [add_right_comm] using h (x + a) theorem Antiperiodic.const_sub [AddCommGroup α] [InvolutiveNeg β] (h : Antiperiodic f c) (a : α) : Antiperiodic (fun x => f (a - x)) c := fun x => by simp only [← sub_sub, h.sub_eq] theorem Antiperiodic.sub_const [SubtractionCommMonoid α] [Neg β] (h : Antiperiodic f c) (a : α) : Antiperiodic (fun x => f (x - a)) c := by simpa only [sub_eq_add_neg] using h.add_const (-a) theorem Antiperiodic.smul [Add α] [Monoid γ] [AddGroup β] [DistribMulAction γ β] (h : Antiperiodic f c) (a : γ) : Antiperiodic (a • f) c := by simp_all theorem Antiperiodic.const_smul [AddMonoid α] [Neg β] [Group γ] [DistribMulAction γ α] (h : Antiperiodic f c) (a : γ) : Antiperiodic (fun x => f (a • x)) (a⁻¹ • c) := fun x => by simpa only [smul_add, smul_inv_smul] using h (a • x) theorem Antiperiodic.const_inv_smul [AddMonoid α] [Neg β] [Group γ] [DistribMulAction γ α] (h : Antiperiodic f c) (a : γ) : Antiperiodic (fun x => f (a⁻¹ • x)) (a • c) := by simpa only [inv_inv] using h.const_smul a⁻¹ theorem Antiperiodic.add [AddSemigroup α] [InvolutiveNeg β] (h1 : Antiperiodic f c₁) (h2 : Antiperiodic f c₂) : Periodic f (c₁ + c₂) := by simp_all [← add_assoc] theorem Antiperiodic.sub [AddGroup α] [InvolutiveNeg β] (h1 : Antiperiodic f c₁) (h2 : Antiperiodic f c₂) : Periodic f (c₁ - c₂) := by simpa only [sub_eq_add_neg] using h1.add h2.neg theorem Periodic.add_antiperiod [AddSemigroup α] [Neg β] (h1 : Periodic f c₁) (h2 : Antiperiodic f c₂) : Antiperiodic f (c₁ + c₂) := by simp_all [← add_assoc] theorem Periodic.sub_antiperiod [AddGroup α] [InvolutiveNeg β] (h1 : Periodic f c₁) (h2 : Antiperiodic f c₂) : Antiperiodic f (c₁ - c₂) := by simpa only [sub_eq_add_neg] using h1.add_antiperiod h2.neg theorem Periodic.add_antiperiod_eq [AddMonoid α] [Neg β] (h1 : Periodic f c₁) (h2 : Antiperiodic f c₂) : f (c₁ + c₂) = -f 0 := (h1.add_antiperiod h2).eq theorem Periodic.sub_antiperiod_eq [AddGroup α] [InvolutiveNeg β] (h1 : Periodic f c₁) (h2 : Antiperiodic f c₂) : f (c₁ - c₂) = -f 0 := (h1.sub_antiperiod h2).eq theorem Antiperiodic.mul [Add α] [Mul β] [HasDistribNeg β] (hf : Antiperiodic f c) (hg : Antiperiodic g c) : Periodic (f * g) c := by simp_all theorem Antiperiodic.div [Add α] [DivisionMonoid β] [HasDistribNeg β] (hf : Antiperiodic f c) (hg : Antiperiodic g c) : Periodic (f / g) c := by simp_all [neg_div_neg_eq] end Function
.lake/packages/mathlib/Mathlib/Algebra/Ring/Parity.lean
import Mathlib.Algebra.Group.Nat.Even import Mathlib.Data.Nat.Cast.Basic import Mathlib.Data.Nat.Cast.Commute import Mathlib.Data.Set.Operations import Mathlib.Logic.Function.Iterate /-! # Even and odd elements in rings This file defines odd elements and proves some general facts about even and odd elements of rings. As opposed to `Even`, `Odd` does not have a multiplicative counterpart. ## TODO Try to generalize `Even` lemmas further. For example, there are still a few lemmas whose `Semiring` assumptions I (DT) am not convinced are necessary. If that turns out to be true, they could be moved to `Mathlib/Algebra/Group/Even.lean`. ## See also `Mathlib/Algebra/Group/Even.lean` for the definition of even elements. -/ assert_not_exists DenselyOrdered IsOrderedRing open MulOpposite variable {F α β : Type*} section Monoid variable [Monoid α] [HasDistribNeg α] {n : ℕ} {a : α} @[simp] lemma Even.neg_pow : Even n → ∀ a : α, (-a) ^ n = a ^ n := by rintro ⟨c, rfl⟩ a simp_rw [← two_mul, pow_mul, neg_sq] lemma Even.neg_one_pow (h : Even n) : (-1 : α) ^ n = 1 := by rw [h.neg_pow, one_pow] end Monoid section DivisionMonoid variable [DivisionMonoid α] [HasDistribNeg α] {a : α} {n : ℤ} lemma Even.neg_zpow : Even n → ∀ a : α, (-a) ^ n = a ^ n := by rintro ⟨c, rfl⟩ a; simp_rw [← Int.two_mul, zpow_mul, zpow_two, neg_mul_neg] lemma Even.neg_one_zpow (h : Even n) : (-1 : α) ^ n = 1 := by rw [h.neg_zpow, one_zpow] end DivisionMonoid @[simp] lemma IsSquare.zero [MulZeroClass α] : IsSquare (0 : α) := ⟨0, (mul_zero _).symm⟩ section Semiring variable [Semiring α] [Semiring β] {a b : α} {m n : ℕ} lemma even_iff_exists_two_mul : Even a ↔ ∃ b, a = 2 * b := by simp [even_iff_exists_two_nsmul] lemma even_iff_two_dvd : Even a ↔ 2 ∣ a := by simp [Even, Dvd.dvd, two_mul] alias ⟨Even.two_dvd, _⟩ := even_iff_two_dvd lemma Even.trans_dvd (ha : Even a) (hab : a ∣ b) : Even b := even_iff_two_dvd.2 <| ha.two_dvd.trans hab lemma Dvd.dvd.even (hab : a ∣ b) (ha : Even a) : Even b := ha.trans_dvd hab @[simp] lemma range_two_mul (α) [NonAssocSemiring α] : Set.range (fun x : α ↦ 2 * x) = {a | Even a} := by ext x simp [eq_comm, two_mul, Even] @[simp] lemma even_two : Even (2 : α) := ⟨1, by rw [one_add_one_eq_two]⟩ @[simp] lemma Even.mul_left (ha : Even a) (b) : Even (b * a) := ha.map (AddMonoidHom.mulLeft _) @[simp] lemma Even.mul_right (ha : Even a) (b) : Even (a * b) := ha.map (AddMonoidHom.mulRight _) lemma even_two_mul (a : α) : Even (2 * a) := ⟨a, two_mul _⟩ lemma Even.pow_of_ne_zero (ha : Even a) : ∀ {n : ℕ}, n ≠ 0 → Even (a ^ n) | n + 1, _ => by rw [pow_succ]; exact ha.mul_left _ /-- An element `a` of a semiring is odd if there exists `k` such `a = 2*k + 1`. -/ def Odd (a : α) : Prop := ∃ k, a = 2 * k + 1 lemma odd_iff_exists_bit1 : Odd a ↔ ∃ b, a = 2 * b + 1 := exists_congr fun b ↦ by rw [two_mul] alias ⟨Odd.exists_bit1, _⟩ := odd_iff_exists_bit1 @[simp] lemma range_two_mul_add_one (α : Type*) [Semiring α] : Set.range (fun x : α ↦ 2 * x + 1) = {a | Odd a} := by ext x; simp [Odd, eq_comm] lemma Even.add_odd : Even a → Odd b → Odd (a + b) := by rintro ⟨a, rfl⟩ ⟨b, rfl⟩; exact ⟨a + b, by rw [mul_add, ← two_mul, add_assoc]⟩ lemma Even.odd_add (ha : Even a) (hb : Odd b) : Odd (b + a) := add_comm a b ▸ ha.add_odd hb lemma Odd.add_even (ha : Odd a) (hb : Even b) : Odd (a + b) := add_comm a b ▸ hb.add_odd ha lemma Odd.add_odd : Odd a → Odd b → Even (a + b) := by rintro ⟨a, rfl⟩ ⟨b, rfl⟩ refine ⟨a + b + 1, ?_⟩ rw [two_mul, two_mul] ac_rfl @[simp] lemma odd_one : Odd (1 : α) := ⟨0, (zero_add _).symm.trans (congr_arg (· + (1 : α)) (mul_zero _).symm)⟩ @[simp] lemma Even.add_one (h : Even a) : Odd (a + 1) := h.add_odd odd_one @[simp] lemma Even.one_add (h : Even a) : Odd (1 + a) := h.odd_add odd_one @[simp] lemma Odd.add_one (h : Odd a) : Even (a + 1) := h.add_odd odd_one @[simp] lemma Odd.one_add (h : Odd a) : Even (1 + a) := odd_one.add_odd h lemma odd_two_mul_add_one (a : α) : Odd (2 * a + 1) := ⟨_, rfl⟩ @[simp] lemma odd_add_self_one' : Odd (a + (a + 1)) := by simp [← add_assoc] @[simp] lemma odd_add_one_self : Odd (a + 1 + a) := by simp [add_comm _ a] @[simp] lemma odd_add_one_self' : Odd (a + (1 + a)) := by simp [add_comm 1 a] lemma Odd.map [FunLike F α β] [RingHomClass F α β] (f : F) : Odd a → Odd (f a) := by rintro ⟨a, rfl⟩; exact ⟨f a, by simp [two_mul]⟩ lemma Odd.natCast {R : Type*} [Semiring R] {n : ℕ} (hn : Odd n) : Odd (n : R) := hn.map <| Nat.castRingHom R @[simp] lemma Odd.mul : Odd a → Odd b → Odd (a * b) := by rintro ⟨a, rfl⟩ ⟨b, rfl⟩ refine ⟨2 * a * b + b + a, ?_⟩ rw [mul_add, add_mul, mul_one, ← add_assoc, one_mul, mul_assoc, ← mul_add, ← mul_add, ← mul_assoc, ← Nat.cast_two, ← Nat.cast_comm] lemma Odd.pow {n : ℕ} (ha : Odd a) : Odd (a ^ n) := by induction n with | zero => simp [pow_zero] | succ n hrec => rw [pow_succ]; exact hrec.mul ha lemma Odd.pow_add_pow_eq_zero [IsCancelAdd α] (hn : Odd n) (hab : a + b = 0) : a ^ n + b ^ n = 0 := by obtain ⟨k, rfl⟩ := hn induction k with | zero => simpa | succ k ih => ?_ have : a ^ 2 = b ^ 2 := add_right_cancel <| calc a ^ 2 + a * b = 0 := by rw [sq, ← mul_add, hab, mul_zero] _ = b ^ 2 + a * b := by rw [sq, ← add_mul, add_comm, hab, zero_mul] refine add_right_cancel (b := b ^ (2 * k + 1) * a ^ 2) ?_ calc _ = (a ^ (2 * k + 1) + b ^ (2 * k + 1)) * a ^ 2 + b ^ (2 * k + 3) := by rw [add_mul, ← pow_add, add_right_comm]; rfl _ = _ := by rw [ih, zero_mul, zero_add, zero_add, this, ← pow_add] theorem Even.of_isUnit_two (h : IsUnit (2 : α)) (a : α) : Even a := let ⟨u, hu⟩ := h; ⟨u⁻¹ * a, by rw [← mul_add, ← two_mul, ← hu, Units.inv_mul_cancel_left]⟩ theorem isUnit_two_iff_forall_even : IsUnit (2 : α) ↔ ∀ a : α, Even a := by refine ⟨Even.of_isUnit_two, fun h => ?_⟩ obtain ⟨a, ha⟩ := h 1 rw [← two_mul, eq_comm] at ha exact ⟨⟨2, a, ha, .trans (Commute.ofNat_right _ _).eq ha⟩, rfl⟩ end Semiring section Ring variable [Ring α] theorem Odd.of_isUnit_two (h : IsUnit (2 : α)) (a : α) : Odd a := by rw [← sub_add_cancel a 1] exact (Even.of_isUnit_two h _).add_one end Ring section Monoid variable [Monoid α] [HasDistribNeg α] {n : ℕ} lemma Odd.neg_pow : Odd n → ∀ a : α, (-a) ^ n = -a ^ n := by rintro ⟨c, rfl⟩ a; simp_rw [pow_add, pow_mul, neg_sq, pow_one, mul_neg] @[simp] lemma Odd.neg_one_pow (h : Odd n) : (-1 : α) ^ n = -1 := by rw [h.neg_pow, one_pow] end Monoid section Ring variable [Ring α] {a b : α} {n : ℕ} lemma even_neg_two : Even (-2 : α) := by simp only [even_neg, even_two] lemma Odd.neg (hp : Odd a) : Odd (-a) := by obtain ⟨k, hk⟩ := hp use -(k + 1) rw [mul_neg, mul_add, neg_add, add_assoc, two_mul (1 : α), neg_add, neg_add_cancel_right, ← neg_add, hk] @[simp] lemma odd_neg : Odd (-a) ↔ Odd a := ⟨fun h ↦ neg_neg a ▸ h.neg, Odd.neg⟩ lemma odd_neg_one : Odd (-1 : α) := by simp lemma Odd.sub_even (ha : Odd a) (hb : Even b) : Odd (a - b) := by rw [sub_eq_add_neg]; exact ha.add_even hb.neg lemma Even.sub_odd (ha : Even a) (hb : Odd b) : Odd (a - b) := by rw [sub_eq_add_neg]; exact ha.add_odd hb.neg lemma Odd.sub_odd (ha : Odd a) (hb : Odd b) : Even (a - b) := by rw [sub_eq_add_neg]; exact ha.add_odd hb.neg end Ring namespace Nat variable {m n : ℕ} @[grind =] lemma odd_iff : Odd n ↔ n % 2 = 1 := ⟨fun ⟨m, hm⟩ ↦ by cutsat, fun h ↦ ⟨n / 2, by cutsat⟩⟩ instance : DecidablePred (Odd : ℕ → Prop) := fun _ ↦ decidable_of_iff _ odd_iff.symm lemma not_odd_iff : ¬Odd n ↔ n % 2 = 0 := by grind @[simp, grind =] lemma not_odd_iff_even : ¬Odd n ↔ Even n := by grind @[simp] lemma not_even_iff_odd : ¬Even n ↔ Odd n := by grind @[simp] lemma not_odd_zero : ¬Odd 0 := by grind lemma _root_.Odd.not_two_dvd_nat (h : Odd n) : ¬(2 ∣ n) := by grind lemma even_xor_odd (n : ℕ) : Xor' (Even n) (Odd n) := by grind lemma even_or_odd (n : ℕ) : Even n ∨ Odd n := (even_xor_odd n).or lemma even_or_odd' (n : ℕ) : ∃ k, n = 2 * k ∨ n = 2 * k + 1 := by simpa only [← two_mul, exists_or, Odd, Even] using even_or_odd n lemma even_xor_odd' (n : ℕ) : ∃ k, Xor' (n = 2 * k) (n = 2 * k + 1) := by obtain ⟨k, rfl⟩ | ⟨k, rfl⟩ := even_or_odd n <;> · use k grind lemma odd_add_one {n : ℕ} : Odd (n + 1) ↔ ¬ Odd n := by grind lemma mod_two_add_add_odd_mod_two (m : ℕ) {n : ℕ} (hn : Odd n) : m % 2 + (m + n) % 2 = 1 := by grind @[simp] lemma mod_two_add_succ_mod_two (m : ℕ) : m % 2 + (m + 1) % 2 = 1 := by cutsat @[simp] lemma succ_mod_two_add_mod_two (m : ℕ) : (m + 1) % 2 + m % 2 = 1 := by cutsat lemma even_add' : Even (m + n) ↔ (Odd m ↔ Odd n) := by grind @[simp] lemma not_even_bit1 (n : ℕ) : ¬Even (2 * n + 1) := by simp [parity_simps] lemma not_even_two_mul_add_one (n : ℕ) : ¬ Even (2 * n + 1) := by grind lemma even_sub' (h : n ≤ m) : Even (m - n) ↔ (Odd m ↔ Odd n) := by grind lemma Odd.sub_odd (hm : Odd m) (hn : Odd n) : Even (m - n) := by grind alias _root_.Odd.tsub_odd := Nat.Odd.sub_odd lemma odd_mul : Odd (m * n) ↔ Odd m ∧ Odd n := by grind lemma Odd.of_mul_left (h : Odd (m * n)) : Odd m := (odd_mul.mp h).1 lemma Odd.of_mul_right (h : Odd (m * n)) : Odd n := (odd_mul.mp h).2 lemma odd_pow_iff {e : ℕ} (he : e ≠ 0) : Odd (n ^ e) ↔ Odd n := by grind lemma even_div : Even (m / n) ↔ m % (2 * n) / n = 0 := by rw [even_iff_two_dvd, dvd_iff_mod_eq_zero, ← Nat.mod_mul_right_div_self, mul_comm] @[parity_simps] lemma odd_add : Odd (m + n) ↔ (Odd m ↔ Even n) := by grind lemma odd_add' : Odd (m + n) ↔ (Odd n ↔ Even m) := by grind lemma ne_of_odd_add (h : Odd (m + n)) : m ≠ n := by grind @[parity_simps] lemma odd_sub (h : n ≤ m) : Odd (m - n) ↔ (Odd m ↔ Even n) := by grind lemma Odd.sub_even (h : n ≤ m) (hm : Odd m) (hn : Even n) : Odd (m - n) := by grind lemma odd_sub' (h : n ≤ m) : Odd (m - n) ↔ (Odd n ↔ Even m) := by grind lemma Even.sub_odd (h : n ≤ m) (hm : Even m) (hn : Odd n) : Odd (m - n) := by grind lemma two_mul_div_two_add_one_of_odd (h : Odd n) : 2 * (n / 2) + 1 = n := by grind lemma div_two_mul_two_add_one_of_odd (h : Odd n) : n / 2 * 2 + 1 = n := by grind lemma one_add_div_two_mul_two_of_odd (h : Odd n) : 1 + n / 2 * 2 = n := by grind lemma two_dvd_mul_add_one (k : ℕ) : 2 ∣ k * (k + 1) := even_iff_two_dvd.mp (even_mul_succ_self k) -- Here are examples of how `parity_simps` can be used with `Nat`. example (m n : ℕ) (h : Even m) : ¬Even (n + 3) ↔ Even (m ^ 2 + m + n) := by simp [*, parity_simps] example : ¬Even 25394535 := by decide end Nat open Nat namespace Function namespace Involutive variable {α : Type*} {f : α → α} {n : ℕ} lemma iterate_two_mul (hf : Involutive f) (n : ℕ) : f^[2 * n] = id := by rw [iterate_mul, involutive_iff_iter_2_eq_id.1 hf, iterate_id] @[deprecated (since := "2025-10-28")] alias iterate_bit0 := iterate_two_mul lemma iterate_two_mul_add_one (hf : Involutive f) (n : ℕ) : f^[2 * n + 1] = f := by rw [iterate_succ, hf.iterate_two_mul, id_comp] @[deprecated (since := "2025-10-28")] alias iterate_bit1 := iterate_two_mul_add_one lemma iterate_even (hf : Involutive f) (hn : Even n) : f^[n] = id := by obtain ⟨m, rfl⟩ := hn rw [← two_mul, hf.iterate_two_mul] lemma iterate_odd (hf : Involutive f) (hn : Odd n) : f^[n] = f := by obtain ⟨m, rfl⟩ := hn rw [iterate_add, hf.iterate_two_mul, id_comp, iterate_one] lemma iterate_eq_self (hf : Involutive f) (hne : f ≠ id) : f^[n] = f ↔ Odd n := ⟨fun H ↦ not_even_iff_odd.1 fun hn ↦ hne <| by rwa [hf.iterate_even hn, eq_comm] at H, hf.iterate_odd⟩ lemma iterate_eq_id (hf : Involutive f) (hne : f ≠ id) : f^[n] = id ↔ Even n := ⟨fun H ↦ not_odd_iff_even.1 fun hn ↦ hne <| by rwa [hf.iterate_odd hn] at H, hf.iterate_even⟩ end Involutive end Function section DistribNeg variable {R : Type*} [Monoid R] [HasDistribNeg R] {m n : ℕ} lemma neg_one_pow_eq_ite : (-1 : R) ^ n = if Even n then 1 else (-1) := by cases even_or_odd n with | inl h => rw [h.neg_one_pow, if_pos h] | inr h => rw [h.neg_one_pow, if_neg (by simpa using h)] lemma neg_one_pow_congr (h : Even m ↔ Even n) : (-1 : R) ^ m = (-1) ^ n := by simp [h, neg_one_pow_eq_ite] lemma neg_one_pow_eq_one_iff_even (h : (-1 : R) ≠ 1) : (-1 : R) ^ n = 1 ↔ Even n := by simp [neg_one_pow_eq_ite, h] lemma neg_one_pow_eq_neg_one_iff_odd (h : (-1 : R) ≠ 1) : (-1 : R) ^ n = -1 ↔ Odd n := by simp [neg_one_pow_eq_ite, h.symm] end DistribNeg section CharTwo -- We state the following theorems in terms of the slightly more general `2 = 0` hypothesis. variable {R : Type*} [AddMonoidWithOne R] private theorem natCast_eq_zero_or_one_of_two_eq_zero' (n : ℕ) (h : (2 : R) = 0) : (Even n → (n : R) = 0) ∧ (Odd n → (n : R) = 1) := by induction n using Nat.twoStepInduction with | zero => simp | one => simp | more n _ _ => simpa [add_assoc, Nat.even_add_one, Nat.odd_add_one, h] theorem natCast_eq_zero_of_even_of_two_eq_zero {n : ℕ} (hn : Even n) (h : (2 : R) = 0) : (n : R) = 0 := (natCast_eq_zero_or_one_of_two_eq_zero' n h).1 hn theorem natCast_eq_one_of_odd_of_two_eq_zero {n : ℕ} (hn : Odd n) (h : (2 : R) = 0) : (n : R) = 1 := (natCast_eq_zero_or_one_of_two_eq_zero' n h).2 hn theorem natCast_eq_zero_or_one_of_two_eq_zero (n : ℕ) (h : (2 : R) = 0) : (n : R) = 0 ∨ (n : R) = 1 := by obtain hn | hn := Nat.even_or_odd n · exact Or.inl <| natCast_eq_zero_of_even_of_two_eq_zero hn h · exact Or.inr <| natCast_eq_one_of_odd_of_two_eq_zero hn h end CharTwo
.lake/packages/mathlib/Mathlib/Algebra/Ring/Associator.lean
import Mathlib.Algebra.Ring.Basic import Mathlib.Algebra.Ring.Opposite import Mathlib.Tactic.Abel /-! # Associator in a ring If `R` is a non-associative ring, then `(x * y) * z - x * (y * z)` is called the `associator` of ring elements `x y z : R`. The associator vanishes exactly when `R` is associative. We prove variants of this statement also for the `AddMonoidHom` bundled version of the associator, as well as the bundled version of `mulLeft₃` and `mulRight₃`, the multiplications `(x * y) * z` and `x * (y * z)`. -/ variable {R : Type*} section NonUnitalNonAssocRing variable [NonUnitalNonAssocRing R] /-- The associator `(x * y) * z - x * (y * z)` -/ def associator (x y z : R) : R := (x * y) * z - x * (y * z) theorem associator_apply (x y z : R) : associator x y z = (x * y) * z - x * (y * z) := rfl theorem associator_eq_zero_iff_associative : associator (R := R) = 0 ↔ Std.Associative (fun (x y : R) ↦ x * y) where mp h := ⟨fun x y z ↦ sub_eq_zero.mp <| congr_fun₃ h x y z⟩ mpr h := by ext x y z; simp [associator, Std.Associative.assoc] theorem associator_cocycle (a b c d : R) : a * associator b c d - associator (a * b) c d + associator a (b * c) d - associator a b (c * d) + (associator a b c) * d = 0 := by simp only [associator, mul_sub, sub_mul] abel1 open MulOpposite in @[simp] lemma associator_op (x y z : Rᵐᵒᵖ) : associator x y z = -op (associator (unop z) (unop y) (unop x)) := by simp only [associator_apply, ← unop_mul, ← unop_sub, op_unop, neg_sub] end NonUnitalNonAssocRing section NonUnitalRing variable [NonUnitalRing R] @[simp] theorem associator_eq_zero : associator (R := R) = 0 := associator_eq_zero_iff_associative.mpr inferInstance end NonUnitalRing namespace AddMonoidHom section NonUnitalNonAssocSemiring variable [NonUnitalNonAssocSemiring R] /-- The multiplication `(x * y) * z` of three elements of a (non-associative) (semi)-ring is an `AddMonoidHom` in each argument. See also `LinearMap.mulLeftRight` for a related functions realized as a linear map. -/ def mulLeft₃ : R →+ R →+ R →+ R where toFun x := comp mul (mulLeft x) map_zero' := by ext; simp map_add' x y := by ext; simp [add_mul] @[simp] theorem mulLeft₃_apply (x y z : R) : mulLeft₃ x y z = (x * y) * z := rfl /-- The multiplication `x * (y * z)` of three elements of a (non-associative) (semi)-ring is an `AddMonoidHom` in each argument. -/ def mulRight₃ : R →+ R →+ R →+ R where toFun x := compr₂ mul (mulLeft x) map_zero' := by ext; simp map_add' x y := by ext; simp [add_mul] @[simp] theorem mulRight₃_apply (x y z : R) : mulRight₃ x y z = x * (y * z) := rfl /-- An a priori non-associative semiring is associative if the `AddMonoidHom` versions of the multiplications `(x * y) * z` and `x * (y * z)` agree. -/ theorem mulLeft₃_eq_mulRight₃_iff_associative : mulLeft₃ (R := R) = mulRight₃ ↔ Std.Associative (fun (x y : R) ↦ x * y) where mp h := ⟨fun x y z ↦ by rw [← mulLeft₃_apply, ← mulRight₃_apply, h]⟩ mpr h := by ext x y z; simp [Std.Associative.assoc] end NonUnitalNonAssocSemiring section NonUnitalSemiring variable [NonUnitalSemiring R] theorem mulLeft₃_eq_mulRight₃ : mulLeft₃ (R := R) = mulRight₃ := mulLeft₃_eq_mulRight₃_iff_associative.2 inferInstance end NonUnitalSemiring section NonUnitalNonAssocRing variable [NonUnitalNonAssocRing R] (a b c : R) /-- The associator for a non-associative ring is `(x * y) * z - x * (y * z)`. It is an `AddMonoidHom` in each argument. -/ def associator : R →+ R →+ R →+ R := mulLeft₃ - mulRight₃ @[simp] theorem associator_apply : associator a b c = _root_.associator a b c := rfl /-- An a priori non-associative ring is associative iff the `AddMonoidHom` version of the associator vanishes. -/ theorem associator_eq_zero_iff_associative : associator (R := R) = 0 ↔ Std.Associative (fun (x y : R) ↦ x * y) := by simp [mulLeft₃_eq_mulRight₃_iff_associative, associator, sub_eq_zero] end NonUnitalNonAssocRing section NonUnitalRing variable [NonUnitalRing R] @[simp] theorem associator_eq_zero : associator (R := R) = 0 := associator_eq_zero_iff_associative.mpr inferInstance end NonUnitalRing end AddMonoidHom
.lake/packages/mathlib/Mathlib/Algebra/Ring/BooleanRing.lean
import Mathlib.Algebra.Group.Idempotent import Mathlib.Algebra.Ring.Equiv import Mathlib.Algebra.Ring.PUnit import Mathlib.Order.Hom.BoundedLattice import Mathlib.Tactic.Abel import Mathlib.Tactic.Ring /-! # Boolean rings A Boolean ring is a ring where multiplication is idempotent. They are equivalent to Boolean algebras. ## Main declarations * `BooleanRing`: a typeclass for rings where multiplication is idempotent. * `BooleanRing.toBooleanAlgebra`: Turn a Boolean ring into a Boolean algebra. * `BooleanAlgebra.toBooleanRing`: Turn a Boolean algebra into a Boolean ring. * `AsBoolAlg`: Type-synonym for the Boolean algebra associated to a Boolean ring. * `AsBoolRing`: Type-synonym for the Boolean ring associated to a Boolean algebra. ## Implementation notes We provide two ways of turning a Boolean algebra/ring into a Boolean ring/algebra: * Instances on the same type accessible in locales `BooleanAlgebraOfBooleanRing` and `BooleanRingOfBooleanAlgebra`. * Type-synonyms `AsBoolAlg` and `AsBoolRing`. At this point in time, it is not clear the first way is useful, but we keep it for educational purposes and because it is easier than dealing with `ofBoolAlg`/`toBoolAlg`/`ofBoolRing`/`toBoolRing` explicitly. ## Tags boolean ring, boolean algebra -/ open scoped symmDiff variable {α β γ : Type*} /-- A Boolean ring is a ring where multiplication is idempotent. -/ class BooleanRing (α) extends Ring α where /-- Multiplication in a Boolean ring is idempotent. -/ isIdempotentElem (a : α) : IsIdempotentElem a namespace BooleanRing variable [BooleanRing α] (a b : α) @[scoped simp] lemma mul_self : a * a = a := IsIdempotentElem.eq (isIdempotentElem a) instance : Std.IdempotentOp (α := α) (· * ·) := ⟨BooleanRing.mul_self⟩ @[scoped simp] theorem add_self : a + a = 0 := by have : a + a = a + a + (a + a) := calc a + a = (a + a) * (a + a) := by rw [mul_self] _ = a * a + a * a + (a * a + a * a) := by rw [add_mul, mul_add] _ = a + a + (a + a) := by rw [mul_self] rwa [right_eq_add] at this @[scoped simp] theorem neg_eq : -a = a := calc -a = -a + 0 := by rw [add_zero] _ = -a + -a + a := by rw [← neg_add_cancel, add_assoc] _ = a := by rw [add_self, zero_add] theorem add_eq_zero' : a + b = 0 ↔ a = b := calc a + b = 0 ↔ a = -b := add_eq_zero_iff_eq_neg _ ↔ a = b := by rw [neg_eq] @[simp] theorem mul_add_mul : a * b + b * a = 0 := by have : a + b = a + b + (a * b + b * a) := calc a + b = (a + b) * (a + b) := by rw [mul_self] _ = a * a + a * b + (b * a + b * b) := by rw [add_mul, mul_add, mul_add] _ = a + a * b + (b * a + b) := by simp only [mul_self] _ = a + b + (a * b + b * a) := by abel rwa [left_eq_add] at this @[scoped simp] theorem sub_eq_add : a - b = a + b := by rw [sub_eq_add_neg, add_right_inj, neg_eq] @[simp] theorem mul_one_add_self : a * (1 + a) = 0 := by rw [mul_add, mul_one, mul_self, add_self] -- Note [lower instance priority] instance (priority := 100) toCommRing : CommRing α := { (inferInstance : BooleanRing α) with mul_comm := fun a b => by rw [← add_eq_zero', mul_add_mul] } end BooleanRing instance : BooleanRing PUnit := ⟨fun _ => Subsingleton.elim _ _⟩ /-! ### Turning a Boolean ring into a Boolean algebra -/ section RingToAlgebra /-- Type synonym to view a Boolean ring as a Boolean algebra. -/ def AsBoolAlg (α : Type*) := α /-- The "identity" equivalence between `AsBoolAlg α` and `α`. -/ def toBoolAlg : α ≃ AsBoolAlg α := Equiv.refl _ /-- The "identity" equivalence between `α` and `AsBoolAlg α`. -/ def ofBoolAlg : AsBoolAlg α ≃ α := Equiv.refl _ @[simp] theorem toBoolAlg_symm_eq : (@toBoolAlg α).symm = ofBoolAlg := rfl @[simp] theorem ofBoolAlg_symm_eq : (@ofBoolAlg α).symm = toBoolAlg := rfl @[simp] theorem toBoolAlg_ofBoolAlg (a : AsBoolAlg α) : toBoolAlg (ofBoolAlg a) = a := rfl @[simp] theorem ofBoolAlg_toBoolAlg (a : α) : ofBoolAlg (toBoolAlg a) = a := rfl theorem toBoolAlg_inj {a b : α} : toBoolAlg a = toBoolAlg b ↔ a = b := Iff.rfl theorem ofBoolAlg_inj {a b : AsBoolAlg α} : ofBoolAlg a = ofBoolAlg b ↔ a = b := Iff.rfl instance [Inhabited α] : Inhabited (AsBoolAlg α) := ‹Inhabited α› variable [BooleanRing α] [BooleanRing β] [BooleanRing γ] namespace BooleanRing /-- The join operation in a Boolean ring is `x + y + x * y`. -/ def sup : Max α := ⟨fun x y => x + y + x * y⟩ /-- The meet operation in a Boolean ring is `x * y`. -/ def inf : Min α := ⟨(· * ·)⟩ scoped [BooleanAlgebraOfBooleanRing] attribute [instance 100] BooleanRing.sup scoped [BooleanAlgebraOfBooleanRing] attribute [instance 100] BooleanRing.inf open BooleanAlgebraOfBooleanRing theorem sup_comm (a b : α) : a ⊔ b = b ⊔ a := by dsimp only [(· ⊔ ·)] ring theorem inf_comm (a b : α) : a ⊓ b = b ⊓ a := by dsimp only [(· ⊓ ·)] ring theorem sup_assoc (a b c : α) : a ⊔ b ⊔ c = a ⊔ (b ⊔ c) := by dsimp only [(· ⊔ ·)] ring theorem inf_assoc (a b c : α) : a ⊓ b ⊓ c = a ⊓ (b ⊓ c) := by dsimp only [(· ⊓ ·)] ring theorem sup_inf_self (a b : α) : a ⊔ a ⊓ b = a := by dsimp only [(· ⊔ ·), (· ⊓ ·)] rw [← mul_assoc, mul_self, add_assoc, add_self, add_zero] theorem inf_sup_self (a b : α) : a ⊓ (a ⊔ b) = a := by dsimp only [(· ⊔ ·), (· ⊓ ·)] rw [mul_add, mul_add, mul_self, ← mul_assoc, mul_self, add_assoc, add_self, add_zero] theorem le_sup_inf_aux (a b c : α) : (a + b + a * b) * (a + c + a * c) = a + b * c + a * (b * c) := calc (a + b + a * b) * (a + c + a * c) = a * a + b * c + a * (b * c) + (a * b + a * a * b) + (a * c + a * a * c) + (a * b * c + a * a * b * c) := by ring _ = a + b * c + a * (b * c) := by simp only [mul_self, add_self, add_zero] theorem le_sup_inf (a b c : α) : (a ⊔ b) ⊓ (a ⊔ c) ⊔ (a ⊔ b ⊓ c) = a ⊔ b ⊓ c := by dsimp only [(· ⊔ ·), (· ⊓ ·)] rw [le_sup_inf_aux, add_self, mul_self, zero_add] /-- The Boolean algebra structure on a Boolean ring. The data is defined so that: * `a ⊔ b` unfolds to `a + b + a * b` * `a ⊓ b` unfolds to `a * b` * `a ≤ b` unfolds to `a + b + a * b = b` * `⊥` unfolds to `0` * `⊤` unfolds to `1` * `aᶜ` unfolds to `1 + a` * `a \ b` unfolds to `a * (1 + b)` -/ def toBooleanAlgebra : BooleanAlgebra α := { Lattice.mk' sup_comm sup_assoc inf_comm inf_assoc sup_inf_self inf_sup_self with le_sup_inf := le_sup_inf top := 1 le_top := fun a => show a + 1 + a * 1 = 1 by rw [mul_one, add_comm a 1, add_assoc, add_self, add_zero] bot := 0 bot_le := fun a => show 0 + a + 0 * a = a by rw [zero_mul, zero_add, add_zero] compl := fun a => 1 + a inf_compl_le_bot := fun a => show a * (1 + a) + 0 + a * (1 + a) * 0 = 0 by simp [mul_add, mul_self, add_self] top_le_sup_compl := fun a => by change 1 + (a + (1 + a) + a * (1 + a)) + 1 * (a + (1 + a) + a * (1 + a)) = a + (1 + a) + a * (1 + a) norm_num [mul_add, mul_self, add_self] rw [← add_assoc, add_self] } scoped[BooleanAlgebraOfBooleanRing] attribute [instance 100] BooleanRing.toBooleanAlgebra end BooleanRing open BooleanRing instance : BooleanAlgebra (AsBoolAlg α) := @BooleanRing.toBooleanAlgebra α _ @[simp] theorem ofBoolAlg_top : ofBoolAlg (⊤ : AsBoolAlg α) = 1 := rfl @[simp] theorem ofBoolAlg_bot : ofBoolAlg (⊥ : AsBoolAlg α) = 0 := rfl @[simp] theorem ofBoolAlg_sup (a b : AsBoolAlg α) : ofBoolAlg (a ⊔ b) = ofBoolAlg a + ofBoolAlg b + ofBoolAlg a * ofBoolAlg b := rfl @[simp] theorem ofBoolAlg_inf (a b : AsBoolAlg α) : ofBoolAlg (a ⊓ b) = ofBoolAlg a * ofBoolAlg b := rfl @[simp] theorem ofBoolAlg_compl (a : AsBoolAlg α) : ofBoolAlg aᶜ = 1 + ofBoolAlg a := rfl @[simp] theorem ofBoolAlg_sdiff (a b : AsBoolAlg α) : ofBoolAlg (a \ b) = ofBoolAlg a * (1 + ofBoolAlg b) := rfl private theorem of_boolalg_symmDiff_aux (a b : α) : (a + b + a * b) * (1 + a * b) = a + b := calc (a + b + a * b) * (1 + a * b) _ = a + b + (a * b + a * b * (a * b)) + (a * (b * b) + a * a * b) := by ring _ = a + b := by simp only [mul_self, add_self, add_zero] @[simp] theorem ofBoolAlg_symmDiff (a b : AsBoolAlg α) : ofBoolAlg (a ∆ b) = ofBoolAlg a + ofBoolAlg b := by rw [symmDiff_eq_sup_sdiff_inf] exact of_boolalg_symmDiff_aux _ _ @[simp] theorem ofBoolAlg_mul_ofBoolAlg_eq_left_iff {a b : AsBoolAlg α} : ofBoolAlg a * ofBoolAlg b = ofBoolAlg a ↔ a ≤ b := @inf_eq_left (AsBoolAlg α) _ _ _ @[simp] theorem toBoolAlg_zero : toBoolAlg (0 : α) = ⊥ := rfl @[simp] theorem toBoolAlg_one : toBoolAlg (1 : α) = ⊤ := rfl @[simp] theorem toBoolAlg_mul (a b : α) : toBoolAlg (a * b) = toBoolAlg a ⊓ toBoolAlg b := rfl @[simp] theorem toBoolAlg_add_add_mul (a b : α) : toBoolAlg (a + b + a * b) = toBoolAlg a ⊔ toBoolAlg b := rfl @[simp] theorem toBoolAlg_add (a b : α) : toBoolAlg (a + b) = toBoolAlg a ∆ toBoolAlg b := (ofBoolAlg_symmDiff a b).symm /-- Turn a ring homomorphism from Boolean rings `α` to `β` into a bounded lattice homomorphism from `α` to `β` considered as Boolean algebras. -/ @[simps] protected def RingHom.asBoolAlg (f : α →+* β) : BoundedLatticeHom (AsBoolAlg α) (AsBoolAlg β) where toFun := toBoolAlg ∘ f ∘ ofBoolAlg map_sup' a b := by dsimp simp_rw [map_add f, map_mul f, toBoolAlg_add_add_mul] map_inf' := f.map_mul' map_top' := f.map_one' map_bot' := f.map_zero' @[simp] theorem RingHom.asBoolAlg_id : (RingHom.id α).asBoolAlg = BoundedLatticeHom.id _ := rfl @[simp] theorem RingHom.asBoolAlg_comp (g : β →+* γ) (f : α →+* β) : (g.comp f).asBoolAlg = g.asBoolAlg.comp f.asBoolAlg := rfl end RingToAlgebra /-! ### Turning a Boolean algebra into a Boolean ring -/ section AlgebraToRing /-- Type synonym to view a Boolean ring as a Boolean algebra. -/ def AsBoolRing (α : Type*) := α /-- The "identity" equivalence between `AsBoolRing α` and `α`. -/ def toBoolRing : α ≃ AsBoolRing α := Equiv.refl _ /-- The "identity" equivalence between `α` and `AsBoolRing α`. -/ def ofBoolRing : AsBoolRing α ≃ α := Equiv.refl _ @[simp] theorem toBoolRing_symm_eq : (@toBoolRing α).symm = ofBoolRing := rfl @[simp] theorem ofBoolRing_symm_eq : (@ofBoolRing α).symm = toBoolRing := rfl @[simp] theorem toBoolRing_ofBoolRing (a : AsBoolRing α) : toBoolRing (ofBoolRing a) = a := rfl @[simp] theorem ofBoolRing_toBoolRing (a : α) : ofBoolRing (toBoolRing a) = a := rfl theorem toBoolRing_inj {a b : α} : toBoolRing a = toBoolRing b ↔ a = b := Iff.rfl theorem ofBoolRing_inj {a b : AsBoolRing α} : ofBoolRing a = ofBoolRing b ↔ a = b := Iff.rfl instance [Inhabited α] : Inhabited (AsBoolRing α) := ‹Inhabited α› -- See note [reducible non-instances] /-- Every generalized Boolean algebra has the structure of a nonunital commutative ring with the following data: * `a + b` unfolds to `a ∆ b` (symmetric difference) * `a * b` unfolds to `a ⊓ b` * `-a` unfolds to `a` * `0` unfolds to `⊥` -/ abbrev GeneralizedBooleanAlgebra.toNonUnitalCommRing [GeneralizedBooleanAlgebra α] : NonUnitalCommRing α where add := (· ∆ ·) add_assoc := symmDiff_assoc zero := ⊥ zero_add := bot_symmDiff add_zero := symmDiff_bot zero_mul := bot_inf_eq mul_zero := inf_bot_eq neg := id neg_add_cancel := symmDiff_self add_comm := symmDiff_comm mul := (· ⊓ ·) mul_assoc := inf_assoc mul_comm := inf_comm left_distrib := inf_symmDiff_distrib_left right_distrib := inf_symmDiff_distrib_right nsmul := letI : Zero α := ⟨⊥⟩; letI : Add α := ⟨(· ∆ ·)⟩; nsmulRec zsmul := letI : Zero α := ⟨⊥⟩; letI : Add α := ⟨(· ∆ ·)⟩; letI : Neg α := ⟨id⟩; zsmulRec instance [GeneralizedBooleanAlgebra α] : NonUnitalCommRing (AsBoolRing α) := @GeneralizedBooleanAlgebra.toNonUnitalCommRing α _ variable [BooleanAlgebra α] [BooleanAlgebra β] [BooleanAlgebra γ] -- See note [reducible non-instances] /-- Every Boolean algebra has the structure of a Boolean ring with the following data: * `a + b` unfolds to `a ∆ b` (symmetric difference) * `a * b` unfolds to `a ⊓ b` * `-a` unfolds to `a` * `0` unfolds to `⊥` * `1` unfolds to `⊤` -/ abbrev BooleanAlgebra.toBooleanRing : BooleanRing α where __ := GeneralizedBooleanAlgebra.toNonUnitalCommRing one := ⊤ one_mul := top_inf_eq mul_one := inf_top_eq isIdempotentElem := inf_idem scoped[BooleanRingOfBooleanAlgebra] attribute [instance] GeneralizedBooleanAlgebra.toNonUnitalCommRing BooleanAlgebra.toBooleanRing instance : BooleanRing (AsBoolRing α) := @BooleanAlgebra.toBooleanRing α _ @[simp] theorem ofBoolRing_zero : ofBoolRing (0 : AsBoolRing α) = ⊥ := rfl @[simp] theorem ofBoolRing_one : ofBoolRing (1 : AsBoolRing α) = ⊤ := rfl @[simp] theorem ofBoolRing_neg (a : AsBoolRing α) : ofBoolRing (-a) = ofBoolRing a := rfl @[simp] theorem ofBoolRing_add (a b : AsBoolRing α) : ofBoolRing (a + b) = ofBoolRing a ∆ ofBoolRing b := rfl @[simp] theorem ofBoolRing_sub (a b : AsBoolRing α) : ofBoolRing (a - b) = ofBoolRing a ∆ ofBoolRing b := rfl @[simp] theorem ofBoolRing_mul (a b : AsBoolRing α) : ofBoolRing (a * b) = ofBoolRing a ⊓ ofBoolRing b := rfl @[simp] theorem ofBoolRing_le_ofBoolRing_iff {a b : AsBoolRing α} : ofBoolRing a ≤ ofBoolRing b ↔ a * b = a := inf_eq_left.symm @[simp] theorem toBoolRing_bot : toBoolRing (⊥ : α) = 0 := rfl @[simp] theorem toBoolRing_top : toBoolRing (⊤ : α) = 1 := rfl @[simp] theorem toBoolRing_inf (a b : α) : toBoolRing (a ⊓ b) = toBoolRing a * toBoolRing b := rfl @[simp] theorem toBoolRing_symmDiff (a b : α) : toBoolRing (a ∆ b) = toBoolRing a + toBoolRing b := rfl /-- Turn a bounded lattice homomorphism from Boolean algebras `α` to `β` into a ring homomorphism from `α` to `β` considered as Boolean rings. -/ @[simps] protected def BoundedLatticeHom.asBoolRing (f : BoundedLatticeHom α β) : AsBoolRing α →+* AsBoolRing β where toFun := toBoolRing ∘ f ∘ ofBoolRing map_zero' := f.map_bot' map_one' := f.map_top' map_add' := map_symmDiff' f map_mul' := f.map_inf' @[simp] theorem BoundedLatticeHom.asBoolRing_id : (BoundedLatticeHom.id α).asBoolRing = RingHom.id _ := rfl @[simp] theorem BoundedLatticeHom.asBoolRing_comp (g : BoundedLatticeHom β γ) (f : BoundedLatticeHom α β) : (g.comp f).asBoolRing = g.asBoolRing.comp f.asBoolRing := rfl end AlgebraToRing /-! ### Equivalence between Boolean rings and Boolean algebras -/ /-- Order isomorphism between `α` considered as a Boolean ring considered as a Boolean algebra and `α`. -/ @[simps!] def OrderIso.asBoolAlgAsBoolRing (α : Type*) [BooleanAlgebra α] : AsBoolAlg (AsBoolRing α) ≃o α := ⟨ofBoolAlg.trans ofBoolRing, ofBoolRing_le_ofBoolRing_iff.trans ofBoolAlg_mul_ofBoolAlg_eq_left_iff⟩ /-- Ring isomorphism between `α` considered as a Boolean algebra considered as a Boolean ring and `α`. -/ @[simps!] def RingEquiv.asBoolRingAsBoolAlg (α : Type*) [BooleanRing α] : AsBoolRing (AsBoolAlg α) ≃+* α := { ofBoolRing.trans ofBoolAlg with map_mul' := fun _a _b => rfl map_add' := ofBoolAlg_symmDiff } open Bool instance : Zero Bool where zero := false instance : One Bool where one := true instance : Add Bool where add := xor instance : Neg Bool where neg := id instance : Sub Bool where sub := xor instance : Mul Bool where mul := and instance : BooleanRing Bool where add_assoc := xor_assoc zero_add := Bool.false_xor add_zero := Bool.xor_false neg_add_cancel := Bool.xor_self add_comm := xor_comm mul_assoc := and_assoc one_mul := Bool.true_and mul_one := Bool.and_true left_distrib := and_xor_distrib_left right_distrib := and_xor_distrib_right isIdempotentElem := Bool.and_self zero_mul _ := rfl mul_zero a := by cases a <;> rfl nsmul := nsmulRec zsmul := zsmulRec
.lake/packages/mathlib/Mathlib/Algebra/Ring/Identities.lean
import Mathlib.Tactic.Ring /-! # Identities This file contains some "named" commutative ring identities. -/ variable {R : Type*} [CommRing R] {a b x₁ x₂ x₃ x₄ x₅ x₆ x₇ x₈ y₁ y₂ y₃ y₄ y₅ y₆ y₇ y₈ n : R} /-- Brahmagupta-Fibonacci identity or Diophantus identity, see <https://en.wikipedia.org/wiki/Brahmagupta%E2%80%93Fibonacci_identity>. This sign choice here corresponds to the signs obtained by multiplying two complex numbers. -/ theorem sq_add_sq_mul_sq_add_sq : (x₁ ^ 2 + x₂ ^ 2) * (y₁ ^ 2 + y₂ ^ 2) = (x₁ * y₁ - x₂ * y₂) ^ 2 + (x₁ * y₂ + x₂ * y₁) ^ 2 := by ring /-- Brahmagupta's identity, see <https://en.wikipedia.org/wiki/Brahmagupta%27s_identity> -/ theorem sq_add_mul_sq_mul_sq_add_mul_sq : (x₁ ^ 2 + n * x₂ ^ 2) * (y₁ ^ 2 + n * y₂ ^ 2) = (x₁ * y₁ - n * x₂ * y₂) ^ 2 + n * (x₁ * y₂ + x₂ * y₁) ^ 2 := by ring /-- Sophie Germain's identity, see <https://www.cut-the-knot.org/blue/SophieGermainIdentity.shtml>. -/ theorem pow_four_add_four_mul_pow_four : a ^ 4 + 4 * b ^ 4 = ((a - b) ^ 2 + b ^ 2) * ((a + b) ^ 2 + b ^ 2) := by ring /-- Sophie Germain's identity, see <https://www.cut-the-knot.org/blue/SophieGermainIdentity.shtml>. -/ theorem pow_four_add_four_mul_pow_four' : a ^ 4 + 4 * b ^ 4 = (a ^ 2 - 2 * a * b + 2 * b ^ 2) * (a ^ 2 + 2 * a * b + 2 * b ^ 2) := by ring /-- Euler's four-square identity, see <https://en.wikipedia.org/wiki/Euler%27s_four-square_identity>. This sign choice here corresponds to the signs obtained by multiplying two quaternions. -/ theorem sum_four_sq_mul_sum_four_sq : (x₁ ^ 2 + x₂ ^ 2 + x₃ ^ 2 + x₄ ^ 2) * (y₁ ^ 2 + y₂ ^ 2 + y₃ ^ 2 + y₄ ^ 2) = (x₁ * y₁ - x₂ * y₂ - x₃ * y₃ - x₄ * y₄) ^ 2 + (x₁ * y₂ + x₂ * y₁ + x₃ * y₄ - x₄ * y₃) ^ 2 + (x₁ * y₃ - x₂ * y₄ + x₃ * y₁ + x₄ * y₂) ^ 2 + (x₁ * y₄ + x₂ * y₃ - x₃ * y₂ + x₄ * y₁) ^ 2 := by ring /-- Degen's eight squares identity, see <https://en.wikipedia.org/wiki/Degen%27s_eight-square_identity>. This sign choice here corresponds to the signs obtained by multiplying two octonions. -/ theorem sum_eight_sq_mul_sum_eight_sq : (x₁ ^ 2 + x₂ ^ 2 + x₃ ^ 2 + x₄ ^ 2 + x₅ ^ 2 + x₆ ^ 2 + x₇ ^ 2 + x₈ ^ 2) * (y₁ ^ 2 + y₂ ^ 2 + y₃ ^ 2 + y₄ ^ 2 + y₅ ^ 2 + y₆ ^ 2 + y₇ ^ 2 + y₈ ^ 2) = (x₁ * y₁ - x₂ * y₂ - x₃ * y₃ - x₄ * y₄ - x₅ * y₅ - x₆ * y₆ - x₇ * y₇ - x₈ * y₈) ^ 2 + (x₁ * y₂ + x₂ * y₁ + x₃ * y₄ - x₄ * y₃ + x₅ * y₆ - x₆ * y₅ - x₇ * y₈ + x₈ * y₇) ^ 2 + (x₁ * y₃ - x₂ * y₄ + x₃ * y₁ + x₄ * y₂ + x₅ * y₇ + x₆ * y₈ - x₇ * y₅ - x₈ * y₆) ^ 2 + (x₁ * y₄ + x₂ * y₃ - x₃ * y₂ + x₄ * y₁ + x₅ * y₈ - x₆ * y₇ + x₇ * y₆ - x₈ * y₅) ^ 2 + (x₁ * y₅ - x₂ * y₆ - x₃ * y₇ - x₄ * y₈ + x₅ * y₁ + x₆ * y₂ + x₇ * y₃ + x₈ * y₄) ^ 2 + (x₁ * y₆ + x₂ * y₅ - x₃ * y₈ + x₄ * y₇ - x₅ * y₂ + x₆ * y₁ - x₇ * y₄ + x₈ * y₃) ^ 2 + (x₁ * y₇ + x₂ * y₈ + x₃ * y₅ - x₄ * y₆ - x₅ * y₃ + x₆ * y₄ + x₇ * y₁ - x₈ * y₂) ^ 2 + (x₁ * y₈ - x₂ * y₇ + x₃ * y₆ + x₄ * y₅ - x₅ * y₄ - x₆ * y₃ + x₇ * y₂ + x₈ * y₁) ^ 2 := by ring
.lake/packages/mathlib/Mathlib/Algebra/Ring/MinimalAxioms.lean
import Mathlib.Algebra.Ring.Defs import Mathlib.Algebra.Group.Basic import Mathlib.Algebra.Group.MinimalAxioms /-! # Minimal Axioms for a Ring This file defines constructors to define a `Ring` or `CommRing` structure on a Type, while proving a minimum number of equalities. ## Main Definitions * `Ring.ofMinimalAxioms`: Define a `Ring` structure on a Type by proving a minimized set of axioms * `CommRing.ofMinimalAxioms`: Define a `CommRing` structure on a Type by proving a minimized set of axioms -/ universe u /-- Define a `Ring` structure on a Type by proving a minimized set of axioms. Note that this uses the default definitions for `npow`, `nsmul`, `zsmul` and `sub` See note [reducible non-instances]. -/ abbrev Ring.ofMinimalAxioms {R : Type u} [Add R] [Mul R] [Neg R] [Zero R] [One R] (add_assoc : ∀ a b c : R, a + b + c = a + (b + c)) (zero_add : ∀ a : R, 0 + a = a) (neg_add_cancel : ∀ a : R, -a + a = 0) (mul_assoc : ∀ a b c : R, a * b * c = a * (b * c)) (one_mul : ∀ a : R, 1 * a = a) (mul_one : ∀ a : R, a * 1 = a) (left_distrib : ∀ a b c : R, a * (b + c) = a * b + a * c) (right_distrib : ∀ a b c : R, (a + b) * c = a * c + b * c) : Ring R := letI := AddGroup.ofLeftAxioms add_assoc zero_add neg_add_cancel haveI add_comm : ∀ a b, a + b = b + a := by intro a b have h₁ : (1 + 1 : R) * (a + b) = a + (a + b) + b := by rw [left_distrib] simp only [right_distrib, one_mul, add_assoc] have h₂ : (1 + 1 : R) * (a + b) = a + (b + a) + b := by rw [right_distrib] simp only [left_distrib, one_mul, add_assoc] have := h₁.symm.trans h₂ rwa [add_left_inj, add_right_inj] at this haveI zero_mul : ∀ a, (0 : R) * a = 0 := fun a => by have : 0 * a = 0 * a + 0 * a := calc 0 * a = (0 + 0) * a := by rw [zero_add] _ = 0 * a + 0 * a := by rw [right_distrib] rwa [left_eq_add] at this haveI mul_zero : ∀ a, a * (0 : R) = 0 := fun a => by have : a * 0 = a * 0 + a * 0 := calc a * 0 = a * (0 + 0) := by rw [zero_add] _ = a * 0 + a * 0 := by rw [left_distrib] rwa [left_eq_add] at this { add_comm := add_comm left_distrib := left_distrib right_distrib := right_distrib zero_mul := zero_mul mul_zero := mul_zero mul_assoc := mul_assoc one_mul := one_mul mul_one := mul_one neg_add_cancel := neg_add_cancel zsmul := (· • ·) } /-- Define a `CommRing` structure on a Type by proving a minimized set of axioms. Note that this uses the default definitions for `npow`, `nsmul`, `zsmul` and `sub` See note [reducible non-instances]. -/ abbrev CommRing.ofMinimalAxioms {R : Type u} [Add R] [Mul R] [Neg R] [Zero R] [One R] (add_assoc : ∀ a b c : R, a + b + c = a + (b + c)) (zero_add : ∀ a : R, 0 + a = a) (neg_add_cancel : ∀ a : R, -a + a = 0) (mul_assoc : ∀ a b c : R, a * b * c = a * (b * c)) (mul_comm : ∀ a b : R, a * b = b * a) (one_mul : ∀ a : R, 1 * a = a) (left_distrib : ∀ a b c : R, a * (b + c) = a * b + a * c) : CommRing R := haveI mul_one : ∀ a : R, a * 1 = a := fun a => by rw [mul_comm, one_mul] haveI right_distrib : ∀ a b c : R, (a + b) * c = a * c + b * c := fun a b c => by rw [mul_comm, left_distrib, mul_comm, mul_comm b c] letI := Ring.ofMinimalAxioms add_assoc zero_add neg_add_cancel mul_assoc one_mul mul_one left_distrib right_distrib { mul_comm := mul_comm }
.lake/packages/mathlib/Mathlib/Algebra/Ring/Units.lean
import Mathlib.Algebra.Ring.InjSurj import Mathlib.Algebra.Group.Units.Hom import Mathlib.Algebra.Ring.Hom.Defs /-! # Units in semirings and rings -/ universe u v w x variable {α : Type u} {β : Type v} {R : Type x} open Function namespace Units section HasDistribNeg variable [Monoid α] [HasDistribNeg α] /-- Each element of the group of units of a ring has an additive inverse. -/ instance : Neg αˣ := ⟨fun u => ⟨-↑u, -↑u⁻¹, by simp, by simp⟩⟩ /-- Representing an element of a ring's unit group as an element of the ring commutes with mapping this element to its additive inverse. -/ @[simp, norm_cast] protected theorem val_neg (u : αˣ) : (↑(-u) : α) = -u := rfl @[simp, norm_cast] protected theorem coe_neg_one : ((-1 : αˣ) : α) = -1 := rfl instance : HasDistribNeg αˣ := val_injective.hasDistribNeg _ Units.val_neg val_mul theorem neg_divp (a : α) (u : αˣ) : -(a /ₚ u) = -a /ₚ u := by simp only [divp, neg_mul] end HasDistribNeg section Semiring variable [Semiring α] theorem divp_add_divp_same (a b : α) (u : αˣ) : a /ₚ u + b /ₚ u = (a + b) /ₚ u := by simp only [divp, add_mul] theorem add_divp (a b : α) (u : αˣ) : a + b /ₚ u = (a * u + b) /ₚ u := by simp only [divp, add_mul, Units.mul_inv_cancel_right] theorem divp_add (a b : α) (u : αˣ) : a /ₚ u + b = (a + b * u) /ₚ u := by simp only [divp, add_mul, Units.mul_inv_cancel_right] end Semiring section Ring variable [Ring α] theorem divp_sub_divp_same (a b : α) (u : αˣ) : a /ₚ u - b /ₚ u = (a - b) /ₚ u := by rw [sub_eq_add_neg, sub_eq_add_neg, neg_divp, divp_add_divp_same] theorem sub_divp (a b : α) (u : αˣ) : a - b /ₚ u = (a * u - b) /ₚ u := by simp only [divp, sub_mul, Units.mul_inv_cancel_right] theorem divp_sub (a b : α) (u : αˣ) : a /ₚ u - b = (a - b * u) /ₚ u := by simp only [divp, sub_mul, sub_right_inj] rw [mul_assoc, Units.mul_inv, mul_one] @[simp] protected theorem map_neg {F : Type*} [Ring β] [FunLike F α β] [RingHomClass F α β] (f : F) (u : αˣ) : map (f : α →* β) (-u) = -map (f : α →* β) u := ext (by simp only [coe_map, Units.val_neg, MonoidHom.coe_coe, map_neg]) protected theorem map_neg_one {F : Type*} [Ring β] [FunLike F α β] [RingHomClass F α β] (f : F) : map (f : α →* β) (-1) = -1 := by simp only [Units.map_neg, map_one] end Ring end Units theorem IsUnit.neg [Monoid α] [HasDistribNeg α] {a : α} : IsUnit a → IsUnit (-a) | ⟨x, hx⟩ => hx ▸ (-x).isUnit @[simp] theorem IsUnit.neg_iff [Monoid α] [HasDistribNeg α] (a : α) : IsUnit (-a) ↔ IsUnit a := ⟨fun h => neg_neg a ▸ h.neg, IsUnit.neg⟩ theorem isUnit_neg_one [Monoid α] [HasDistribNeg α] : IsUnit (-1 : α) := isUnit_one.neg theorem IsUnit.sub_iff [Ring α] {x y : α} : IsUnit (x - y) ↔ IsUnit (y - x) := (IsUnit.neg_iff _).symm.trans <| neg_sub x y ▸ Iff.rfl namespace Units theorem divp_add_divp [CommSemiring α] (a b : α) (u₁ u₂ : αˣ) : a /ₚ u₁ + b /ₚ u₂ = (a * u₂ + u₁ * b) /ₚ (u₁ * u₂) := by simp only [divp, add_mul, mul_inv_rev, val_mul] rw [mul_comm (↑u₁ * b), mul_comm b] rw [← mul_assoc, ← mul_assoc, mul_assoc a, mul_assoc (↑u₂⁻¹ : α), mul_inv, inv_mul, mul_one, mul_one] -- Porting note: `assoc_rw` not ported: `assoc_rw [mul_inv, mul_inv, mul_one, mul_one]` theorem divp_sub_divp [CommRing α] (a b : α) (u₁ u₂ : αˣ) : a /ₚ u₁ - b /ₚ u₂ = (a * u₂ - u₁ * b) /ₚ (u₁ * u₂) := by simp only [sub_eq_add_neg, neg_divp, divp_add_divp, mul_neg] theorem add_eq_mul_one_add_div [Semiring R] {a : Rˣ} {b : R} : ↑a + b = a * (1 + ↑a⁻¹ * b) := by rw [mul_add, mul_one, ← mul_assoc, Units.mul_inv, one_mul] end Units namespace RingHom section Semiring variable [Semiring α] [Semiring β] theorem isUnit_map (f : α →+* β) {a : α} : IsUnit a → IsUnit (f a) := IsUnit.map f end Semiring end RingHom variable [Semiring α] [Semiring β]
.lake/packages/mathlib/Mathlib/Algebra/Ring/CompTypeclasses.lean
import Mathlib.Algebra.Ring.Equiv /-! # Propositional typeclasses on several ring homs This file contains three typeclasses used in the definition of (semi)linear maps: * `RingHomId σ`, which expresses the fact that `σ₂₃ = id` * `RingHomCompTriple σ₁₂ σ₂₃ σ₁₃`, which expresses the fact that `σ₂₃.comp σ₁₂ = σ₁₃` * `RingHomInvPair σ₁₂ σ₂₁`, which states that `σ₁₂` and `σ₂₁` are inverses of each other * `RingHomSurjective σ`, which states that `σ` is surjective These typeclasses ensure that objects such as `σ₂₃.comp σ₁₂` never end up in the type of a semilinear map; instead, the typeclass system directly finds the appropriate `RingHom` to use. A typical use-case is conjugate-linear maps, i.e. when `σ = Complex.conj`; this system ensures that composing two conjugate-linear maps is a linear map, and not a `conj.comp conj`-linear map. Instances of these typeclasses mostly involving `RingHom.id` are also provided: * `RingHomInvPair (RingHom.id R) (RingHom.id R)` * `[RingHomInvPair σ₁₂ σ₂₁] : RingHomCompTriple σ₁₂ σ₂₁ (RingHom.id R₁)` * `RingHomCompTriple (RingHom.id R₁) σ₁₂ σ₁₂` * `RingHomCompTriple σ₁₂ (RingHom.id R₂) σ₁₂` * `RingHomSurjective (RingHom.id R)` * `[RingHomInvPair σ₁ σ₂] : RingHomSurjective σ₁` ## Implementation notes * For the typeclass `RingHomInvPair σ₁₂ σ₂₁`, `σ₂₁` is marked as an `outParam`, as it must typically be found via the typeclass inference system. * Likewise, for `RingHomCompTriple σ₁₂ σ₂₃ σ₁₃`, `σ₁₃` is marked as an `outParam`, for the same reason. ## Tags `RingHomCompTriple`, `RingHomInvPair`, `RingHomSurjective` -/ variable {R₁ : Type*} {R₂ : Type*} {R₃ : Type*} variable [Semiring R₁] [Semiring R₂] [Semiring R₃] /-- Class that expresses that a ring homomorphism is in fact the identity. -/ -- This at first seems not very useful. However we need this when considering -- modules over some diagram in the category of rings, -- e.g. when defining presheaves over a presheaf of rings. -- See `Mathlib/Algebra/Category/ModuleCat/Presheaf.lean`. class RingHomId {R : Type*} [Semiring R] (σ : R →+* R) : Prop where eq_id : σ = RingHom.id R instance {R : Type*} [Semiring R] : RingHomId (RingHom.id R) where eq_id := rfl /-- Class that expresses the fact that three ring homomorphisms form a composition triple. This is used to handle composition of semilinear maps. -/ class RingHomCompTriple (σ₁₂ : R₁ →+* R₂) (σ₂₃ : R₂ →+* R₃) (σ₁₃ : outParam (R₁ →+* R₃)) : Prop where /-- The morphisms form a commutative triangle -/ comp_eq : σ₂₃.comp σ₁₂ = σ₁₃ attribute [simp] RingHomCompTriple.comp_eq variable {σ₁₂ : R₁ →+* R₂} {σ₂₃ : R₂ →+* R₃} {σ₁₃ : R₁ →+* R₃} namespace RingHomCompTriple @[simp] theorem comp_apply [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃] {x : R₁} : σ₂₃ (σ₁₂ x) = σ₁₃ x := RingHom.congr_fun comp_eq x end RingHomCompTriple /-- Class that expresses the fact that two ring homomorphisms are inverses of each other. This is used to handle `symm` for semilinear equivalences. -/ class RingHomInvPair (σ : R₁ →+* R₂) (σ' : outParam (R₂ →+* R₁)) : Prop where /-- `σ'` is a left inverse of `σ` -/ comp_eq : σ'.comp σ = RingHom.id R₁ /-- `σ'` is a left inverse of `σ'` -/ comp_eq₂ : σ.comp σ' = RingHom.id R₂ variable {σ : R₁ →+* R₂} {σ' : R₂ →+* R₁} namespace RingHomInvPair variable [RingHomInvPair σ σ'] theorem comp_apply_eq {x : R₁} : σ' (σ x) = x := by rw [← RingHom.comp_apply, comp_eq] simp theorem comp_apply_eq₂ {x : R₂} : σ (σ' x) = x := by rw [← RingHom.comp_apply, comp_eq₂] simp instance ids : RingHomInvPair (RingHom.id R₁) (RingHom.id R₁) := ⟨rfl, rfl⟩ instance triples {σ₂₁ : R₂ →+* R₁} [RingHomInvPair σ₁₂ σ₂₁] : RingHomCompTriple σ₁₂ σ₂₁ (RingHom.id R₁) := ⟨by simp only [comp_eq]⟩ instance triples₂ {σ₂₁ : R₂ →+* R₁} [RingHomInvPair σ₁₂ σ₂₁] : RingHomCompTriple σ₂₁ σ₁₂ (RingHom.id R₂) := ⟨by simp only [comp_eq₂]⟩ /-- Construct a `RingHomInvPair` from both directions of a ring equiv. This is not an instance, as for equivalences that are involutions, a better instance would be `RingHomInvPair e e`. Indeed, this declaration is not currently used in mathlib. -/ theorem of_ringEquiv (e : R₁ ≃+* R₂) : RingHomInvPair (↑e : R₁ →+* R₂) ↑e.symm := ⟨e.symm_toRingHom_comp_toRingHom, e.symm.symm_toRingHom_comp_toRingHom⟩ /-- Swap the direction of a `RingHomInvPair`. This is not an instance as it would loop, and better instances are often available and may often be preferable to using this one. Indeed, this declaration is not currently used in mathlib. -/ theorem symm (σ₁₂ : R₁ →+* R₂) (σ₂₁ : R₂ →+* R₁) [RingHomInvPair σ₁₂ σ₂₁] : RingHomInvPair σ₂₁ σ₁₂ := ⟨RingHomInvPair.comp_eq₂, RingHomInvPair.comp_eq⟩ end RingHomInvPair namespace RingHomCompTriple instance ids : RingHomCompTriple (RingHom.id R₁) σ₁₂ σ₁₂ := ⟨by simp⟩ instance right_ids : RingHomCompTriple σ₁₂ (RingHom.id R₂) σ₁₂ := ⟨by simp⟩ end RingHomCompTriple /-- Class expressing the fact that a `RingHom` is surjective. This is needed in the context of semilinear maps, where some lemmas require this. -/ class RingHomSurjective (σ : R₁ →+* R₂) : Prop where /-- The ring homomorphism is surjective -/ is_surjective : Function.Surjective σ theorem RingHom.surjective (σ : R₁ →+* R₂) [t : RingHomSurjective σ] : Function.Surjective σ := t.is_surjective namespace RingHomSurjective instance (priority := 100) invPair {σ₁ : R₁ →+* R₂} {σ₂ : R₂ →+* R₁} [RingHomInvPair σ₁ σ₂] : RingHomSurjective σ₁ := ⟨fun x => ⟨σ₂ x, RingHomInvPair.comp_apply_eq₂⟩⟩ instance ids : RingHomSurjective (RingHom.id R₁) := ⟨is_surjective⟩ /-- This cannot be an instance as there is no way to infer `σ₁₂` and `σ₂₃`. -/ theorem comp [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃] [RingHomSurjective σ₁₂] [RingHomSurjective σ₂₃] : RingHomSurjective σ₁₃ := { is_surjective := by have := σ₂₃.surjective.comp σ₁₂.surjective rwa [← RingHom.coe_comp, RingHomCompTriple.comp_eq] at this } instance (σ : R₁ ≃+* R₂) : RingHomSurjective (σ : R₁ →+* R₂) := ⟨σ.surjective⟩ end RingHomSurjective
.lake/packages/mathlib/Mathlib/Algebra/Ring/Associated.lean
import Mathlib.Algebra.GroupWithZero.Associated import Mathlib.Algebra.Ring.Units /-! # Associated elements in rings -/ assert_not_exists IsOrderedMonoid Multiset Field namespace Associated variable {M : Type*} [Monoid M] [HasDistribNeg M] {a b : M} lemma neg_left (h : Associated a b) : Associated (-a) b := let ⟨u, hu⟩ := h; ⟨-u, by simp [hu]⟩ lemma neg_right (h : Associated a b) : Associated a (-b) := h.symm.neg_left.symm lemma neg_neg (h : Associated a b) : Associated (-a) (-b) := h.neg_left.neg_right @[simp] lemma neg_left_iff : Associated (-a) b ↔ Associated a b := ⟨fun h ↦ _root_.neg_neg a ▸ h.neg_left, fun h ↦ h.neg_left⟩ @[simp] lemma neg_right_iff : Associated a (-b) ↔ Associated a b := ⟨fun h ↦ _root_.neg_neg b ▸ h.neg_right, fun h ↦ h.neg_right⟩ end Associated
.lake/packages/mathlib/Mathlib/Algebra/Ring/AddAut.lean
import Mathlib.Algebra.GroupWithZero.Action.Basic import Mathlib.Algebra.GroupWithZero.Action.Units import Mathlib.Algebra.Group.Units.Opposite import Mathlib.Algebra.Module.Opposite /-! # Multiplication on the left/right as additive automorphisms In this file we define `AddAut.mulLeft` and `AddAut.mulRight`. See also `AddMonoidHom.mulLeft`, `AddMonoidHom.mulRight`, `AddMonoid.End.mulLeft`, and `AddMonoid.End.mulRight` for multiplication by `R` as an endomorphism instead of multiplication by `Rˣ` as an automorphism. -/ namespace AddAut variable {R : Type*} [Semiring R] /-- Left multiplication by a unit of a semiring as an additive automorphism. -/ @[simps! +simpRhs] def mulLeft : Rˣ →* AddAut R := DistribMulAction.toAddAut _ _ /-- Right multiplication by a unit of a semiring as an additive automorphism. -/ def mulRight (u : Rˣ) : AddAut R := DistribMulAction.toAddAut Rᵐᵒᵖˣ R (Units.opEquiv.symm <| MulOpposite.op u) @[simp] theorem mulRight_apply (u : Rˣ) (x : R) : mulRight u x = x * u := rfl @[simp] theorem mulRight_symm_apply (u : Rˣ) (x : R) : (mulRight u).symm x = x * u⁻¹ := rfl end AddAut
.lake/packages/mathlib/Mathlib/Algebra/Ring/Hom/Basic.lean
import Mathlib.Algebra.Ring.Hom.InjSurj import Mathlib.Deprecated.RingHom import Mathlib.Tactic.Linter.DeprecatedModule deprecated_module (since := "2025-06-09")
.lake/packages/mathlib/Mathlib/Algebra/Ring/Hom/InjSurj.lean
import Mathlib.Algebra.GroupWithZero.Hom import Mathlib.Algebra.GroupWithZero.InjSurj import Mathlib.Algebra.Ring.Defs /-! # Pulling back rings along injective maps, and pushing them forward along surjective maps -/ open Function variable {α β : Type*} /-- Pullback `IsDomain` instance along an injective function. -/ protected theorem Function.Injective.isDomain [Semiring α] [IsDomain α] [Semiring β] {F} [FunLike F β α] [MonoidWithZeroHomClass F β α] (f : F) (hf : Injective f) : IsDomain β where __ := domain_nontrivial f (map_zero _) (map_one _) __ := hf.isCancelMulZero f (map_zero _) (map_mul _)
.lake/packages/mathlib/Mathlib/Algebra/Ring/Hom/Defs.lean
import Mathlib.Algebra.GroupWithZero.Hom import Mathlib.Algebra.Ring.Defs import Mathlib.Algebra.Ring.Basic /-! # Homomorphisms of semirings and rings This file defines bundled homomorphisms of (non-unital) semirings and rings. As with monoid and groups, we use the same structure `RingHom a β`, a.k.a. `α →+* β`, for both types of homomorphisms. ## Main definitions * `NonUnitalRingHom`: Non-unital (semi)ring homomorphisms. Additive monoid homomorphism which preserve multiplication. * `RingHom`: (Semi)ring homomorphisms. Monoid homomorphisms which are also additive monoid homomorphism. ## Notation * `→ₙ+*`: Non-unital (semi)ring homs * `→+*`: (Semi)ring homs ## Implementation notes * There's a coercion from bundled homs to fun, and the canonical notation is to use the bundled hom as a function via this coercion. * There is no `SemiringHom` -- the idea is that `RingHom` is used. The constructor for a `RingHom` between semirings needs a proof of `map_zero`, `map_one` and `map_add` as well as `map_mul`; a separate constructor `RingHom.mk'` will construct ring homs between rings from monoid homs given only a proof that addition is preserved. ## Tags `RingHom`, `SemiringHom` -/ assert_not_exists Function.Injective.mulZeroClass semigroupDvd Units.map open Function variable {F α β γ : Type*} /-- Bundled non-unital semiring homomorphisms `α →ₙ+* β`; use this for bundled non-unital ring homomorphisms too. When possible, instead of parametrizing results over `(f : α →ₙ+* β)`, you should parametrize over `(F : Type*) [NonUnitalRingHomClass F α β] (f : F)`. When you extend this structure, make sure to extend `NonUnitalRingHomClass`. -/ structure NonUnitalRingHom (α β : Type*) [NonUnitalNonAssocSemiring α] [NonUnitalNonAssocSemiring β] extends α →ₙ* β, α →+ β /-- `α →ₙ+* β` denotes the type of non-unital ring homomorphisms from `α` to `β`. -/ infixr:25 " →ₙ+* " => NonUnitalRingHom /-- Reinterpret a non-unital ring homomorphism `f : α →ₙ+* β` as a semigroup homomorphism `α →ₙ* β`. The `simp`-normal form is `(f : α →ₙ* β)`. -/ add_decl_doc NonUnitalRingHom.toMulHom /-- Reinterpret a non-unital ring homomorphism `f : α →ₙ+* β` as an additive monoid homomorphism `α →+ β`. The `simp`-normal form is `(f : α →+ β)`. -/ add_decl_doc NonUnitalRingHom.toAddMonoidHom section NonUnitalRingHomClass /-- `NonUnitalRingHomClass F α β` states that `F` is a type of non-unital (semi)ring homomorphisms. You should extend this class when you extend `NonUnitalRingHom`. -/ class NonUnitalRingHomClass (F : Type*) (α β : outParam Type*) [NonUnitalNonAssocSemiring α] [NonUnitalNonAssocSemiring β] [FunLike F α β] : Prop extends MulHomClass F α β, AddMonoidHomClass F α β variable [NonUnitalNonAssocSemiring α] [NonUnitalNonAssocSemiring β] [FunLike F α β] variable [NonUnitalRingHomClass F α β] /-- Turn an element of a type `F` satisfying `NonUnitalRingHomClass F α β` into an actual `NonUnitalRingHom`. This is declared as the default coercion from `F` to `α →ₙ+* β`. -/ @[coe] def NonUnitalRingHomClass.toNonUnitalRingHom (f : F) : α →ₙ+* β := { (f : α →ₙ* β), (f : α →+ β) with } /-- Any type satisfying `NonUnitalRingHomClass` can be cast into `NonUnitalRingHom` via `NonUnitalRingHomClass.toNonUnitalRingHom`. -/ instance : CoeTC F (α →ₙ+* β) := ⟨NonUnitalRingHomClass.toNonUnitalRingHom⟩ end NonUnitalRingHomClass namespace NonUnitalRingHom section coe variable [NonUnitalNonAssocSemiring α] [NonUnitalNonAssocSemiring β] instance : FunLike (α →ₙ+* β) α β where coe f := f.toFun coe_injective' f g h := by cases f cases g congr apply DFunLike.coe_injective' exact h instance : NonUnitalRingHomClass (α →ₙ+* β) α β where map_add := NonUnitalRingHom.map_add' map_zero := NonUnitalRingHom.map_zero' map_mul f := f.map_mul' initialize_simps_projections NonUnitalRingHom (toFun → apply) @[simp] theorem coe_toMulHom (f : α →ₙ+* β) : ⇑f.toMulHom = f := rfl @[simp] theorem coe_mulHom_mk (f : α → β) (h₁ h₂ h₃) : ((⟨⟨f, h₁⟩, h₂, h₃⟩ : α →ₙ+* β) : α →ₙ* β) = ⟨f, h₁⟩ := rfl theorem coe_toAddMonoidHom (f : α →ₙ+* β) : ⇑f.toAddMonoidHom = f := rfl @[simp] theorem coe_addMonoidHom_mk (f : α → β) (h₁ h₂ h₃) : ((⟨⟨f, h₁⟩, h₂, h₃⟩ : α →ₙ+* β) : α →+ β) = ⟨⟨f, h₂⟩, h₃⟩ := rfl /-- Copy of a `RingHom` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (f : α →ₙ+* β) (f' : α → β) (h : f' = f) : α →ₙ+* β := { f.toMulHom.copy f' h, f.toAddMonoidHom.copy f' h with } @[simp] theorem coe_copy (f : α →ₙ+* β) (f' : α → β) (h : f' = f) : ⇑(f.copy f' h) = f' := rfl theorem copy_eq (f : α →ₙ+* β) (f' : α → β) (h : f' = f) : f.copy f' h = f := DFunLike.ext' h end coe section variable [NonUnitalNonAssocSemiring α] [NonUnitalNonAssocSemiring β] @[ext] theorem ext ⦃f g : α →ₙ+* β⦄ : (∀ x, f x = g x) → f = g := DFunLike.ext _ _ @[simp] theorem mk_coe (f : α →ₙ+* β) (h₁ h₂ h₃) : NonUnitalRingHom.mk (MulHom.mk f h₁) h₂ h₃ = f := ext fun _ => rfl theorem coe_addMonoidHom_injective : Injective fun f : α →ₙ+* β => (f : α →+ β) := Injective.of_comp (f := DFunLike.coe) DFunLike.coe_injective theorem coe_mulHom_injective : Injective fun f : α →ₙ+* β => (f : α →ₙ* β) := Injective.of_comp (f := DFunLike.coe) DFunLike.coe_injective end variable [NonUnitalNonAssocSemiring α] [NonUnitalNonAssocSemiring β] /-- The identity non-unital ring homomorphism from a non-unital semiring to itself. -/ protected def id (α : Type*) [NonUnitalNonAssocSemiring α] : α →ₙ+* α where toFun := id map_mul' _ _ := rfl map_zero' := rfl map_add' _ _ := rfl instance : Zero (α →ₙ+* β) := ⟨{ toFun := 0, map_mul' := fun _ _ => (mul_zero (0 : β)).symm, map_zero' := rfl, map_add' := fun _ _ => (add_zero (0 : β)).symm }⟩ instance : Inhabited (α →ₙ+* β) := ⟨0⟩ @[simp] theorem coe_zero : ⇑(0 : α →ₙ+* β) = 0 := rfl @[simp] theorem zero_apply (x : α) : (0 : α →ₙ+* β) x = 0 := rfl @[simp] theorem id_apply (x : α) : NonUnitalRingHom.id α x = x := rfl @[simp] theorem coe_addMonoidHom_id : (NonUnitalRingHom.id α : α →+ α) = AddMonoidHom.id α := rfl @[simp] theorem coe_mulHom_id : (NonUnitalRingHom.id α : α →ₙ* α) = MulHom.id α := rfl variable [NonUnitalNonAssocSemiring γ] /-- Composition of non-unital ring homomorphisms is a non-unital ring homomorphism. -/ def comp (g : β →ₙ+* γ) (f : α →ₙ+* β) : α →ₙ+* γ := { g.toMulHom.comp f.toMulHom, g.toAddMonoidHom.comp f.toAddMonoidHom with } /-- Composition of non-unital ring homomorphisms is associative. -/ theorem comp_assoc {δ} {_ : NonUnitalNonAssocSemiring δ} (f : α →ₙ+* β) (g : β →ₙ+* γ) (h : γ →ₙ+* δ) : (h.comp g).comp f = h.comp (g.comp f) := rfl @[simp] theorem coe_comp (g : β →ₙ+* γ) (f : α →ₙ+* β) : ⇑(g.comp f) = g ∘ f := rfl @[simp] theorem comp_apply (g : β →ₙ+* γ) (f : α →ₙ+* β) (x : α) : g.comp f x = g (f x) := rfl @[simp] theorem coe_comp_addMonoidHom (g : β →ₙ+* γ) (f : α →ₙ+* β) : AddMonoidHom.mk ⟨g ∘ f, (g.comp f).map_zero'⟩ (g.comp f).map_add' = (g : β →+ γ).comp f := rfl @[simp] theorem coe_comp_mulHom (g : β →ₙ+* γ) (f : α →ₙ+* β) : MulHom.mk (g ∘ f) (g.comp f).map_mul' = (g : β →ₙ* γ).comp f := rfl @[simp] theorem comp_zero (g : β →ₙ+* γ) : g.comp (0 : α →ₙ+* β) = 0 := by ext simp @[simp] theorem zero_comp (f : α →ₙ+* β) : (0 : β →ₙ+* γ).comp f = 0 := by ext rfl @[simp] theorem comp_id (f : α →ₙ+* β) : f.comp (NonUnitalRingHom.id α) = f := ext fun _ => rfl @[simp] theorem id_comp (f : α →ₙ+* β) : (NonUnitalRingHom.id β).comp f = f := ext fun _ => rfl instance : MonoidWithZero (α →ₙ+* α) where one := NonUnitalRingHom.id α mul := comp mul_one := comp_id one_mul := id_comp mul_assoc _ _ _ := comp_assoc _ _ _ mul_zero := comp_zero zero_mul := zero_comp theorem one_def : (1 : α →ₙ+* α) = NonUnitalRingHom.id α := rfl @[simp] theorem coe_one : ⇑(1 : α →ₙ+* α) = id := rfl theorem mul_def (f g : α →ₙ+* α) : f * g = f.comp g := rfl @[simp] theorem coe_mul (f g : α →ₙ+* α) : ⇑(f * g) = f ∘ g := rfl @[simp] theorem cancel_right {g₁ g₂ : β →ₙ+* γ} {f : α →ₙ+* β} (hf : Surjective f) : g₁.comp f = g₂.comp f ↔ g₁ = g₂ := ⟨fun h => ext <| hf.forall.2 (NonUnitalRingHom.ext_iff.1 h), fun h => h ▸ rfl⟩ @[simp] theorem 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⟩ end NonUnitalRingHom /-- Bundled semiring homomorphisms; use this for bundled ring homomorphisms too. This extends from both `MonoidHom` and `MonoidWithZeroHom` in order to put the fields in a sensible order, even though `MonoidWithZeroHom` already extends `MonoidHom`. -/ structure RingHom (α : Type*) (β : Type*) [NonAssocSemiring α] [NonAssocSemiring β] extends α →* β, α →+ β, α →ₙ+* β, α →*₀ β /-- `α →+* β` denotes the type of ring homomorphisms from `α` to `β`. -/ infixr:25 " →+* " => RingHom /-- Reinterpret a ring homomorphism `f : α →+* β` as a monoid with zero homomorphism `α →*₀ β`. The `simp`-normal form is `(f : α →*₀ β)`. -/ add_decl_doc RingHom.toMonoidWithZeroHom /-- Reinterpret a ring homomorphism `f : α →+* β` as a monoid homomorphism `α →* β`. The `simp`-normal form is `(f : α →* β)`. -/ add_decl_doc RingHom.toMonoidHom /-- Reinterpret a ring homomorphism `f : α →+* β` as an additive monoid homomorphism `α →+ β`. The `simp`-normal form is `(f : α →+ β)`. -/ add_decl_doc RingHom.toAddMonoidHom /-- Reinterpret a ring homomorphism `f : α →+* β` as a non-unital ring homomorphism `α →ₙ+* β`. The `simp`-normal form is `(f : α →ₙ+* β)`. -/ add_decl_doc RingHom.toNonUnitalRingHom section RingHomClass /-- `RingHomClass F α β` states that `F` is a type of (semi)ring homomorphisms. You should extend this class when you extend `RingHom`. This extends from both `MonoidHomClass` and `MonoidWithZeroHomClass` in order to put the fields in a sensible order, even though `MonoidWithZeroHomClass` already extends `MonoidHomClass`. -/ class RingHomClass (F : Type*) (α β : outParam Type*) [NonAssocSemiring α] [NonAssocSemiring β] [FunLike F α β] : Prop extends MonoidHomClass F α β, AddMonoidHomClass F α β, MonoidWithZeroHomClass F α β variable [FunLike F α β] -- See note [implicit instance arguments]. variable {_ : NonAssocSemiring α} {_ : NonAssocSemiring β} [RingHomClass F α β] /-- Turn an element of a type `F` satisfying `RingHomClass F α β` into an actual `RingHom`. This is declared as the default coercion from `F` to `α →+* β`. -/ @[coe] def RingHomClass.toRingHom (f : F) : α →+* β := { (f : α →* β), (f : α →+ β) with } /-- Any type satisfying `RingHomClass` can be cast into `RingHom` via `RingHomClass.toRingHom`. -/ instance : CoeTC F (α →+* β) := ⟨RingHomClass.toRingHom⟩ instance (priority := 100) RingHomClass.toNonUnitalRingHomClass : NonUnitalRingHomClass F α β := { ‹RingHomClass F α β› with } end RingHomClass namespace RingHom section coe /-! Throughout this section, some `Semiring` arguments are specified with `{}` instead of `[]`. See note [implicit instance arguments]. -/ variable {_ : NonAssocSemiring α} {_ : NonAssocSemiring β} instance instFunLike : FunLike (α →+* β) α β where coe f := f.toFun coe_injective' f g h := by cases f cases g congr apply DFunLike.coe_injective' exact h instance instRingHomClass : RingHomClass (α →+* β) α β where map_add := RingHom.map_add' map_zero := RingHom.map_zero' map_mul f := f.map_mul' map_one f := f.map_one' initialize_simps_projections RingHom (toFun → apply) theorem toFun_eq_coe (f : α →+* β) : f.toFun = f := rfl @[simp] theorem coe_mk (f : α →* β) (h₁ h₂) : ((⟨f, h₁, h₂⟩ : α →+* β) : α → β) = f := rfl @[simp] theorem coe_coe {F : Type*} [FunLike F α β] [RingHomClass F α β] (f : F) : ((f : α →+* β) : α → β) = f := rfl attribute [coe] RingHom.toMonoidHom instance coeToMonoidHom : Coe (α →+* β) (α →* β) := ⟨RingHom.toMonoidHom⟩ @[simp] theorem toMonoidHom_eq_coe (f : α →+* β) : f.toMonoidHom = f := rfl theorem toMonoidWithZeroHom_eq_coe (f : α →+* β) : (f.toMonoidWithZeroHom : α → β) = f := by rfl @[simp] theorem coe_monoidHom_mk (f : α →* β) (h₁ h₂) : ((⟨f, h₁, h₂⟩ : α →+* β) : α →* β) = f := rfl @[simp] theorem toAddMonoidHom_eq_coe (f : α →+* β) : f.toAddMonoidHom = f := rfl @[simp] theorem coe_addMonoidHom_mk (f : α → β) (h₁ h₂ h₃ h₄) : ((⟨⟨⟨f, h₁⟩, h₂⟩, h₃, h₄⟩ : α →+* β) : α →+ β) = ⟨⟨f, h₃⟩, h₄⟩ := rfl /-- Copy of a `RingHom` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ def copy (f : α →+* β) (f' : α → β) (h : f' = f) : α →+* β := { f.toMonoidWithZeroHom.copy f' h, f.toAddMonoidHom.copy f' h with } @[simp] theorem coe_copy (f : α →+* β) (f' : α → β) (h : f' = f) : ⇑(f.copy f' h) = f' := rfl theorem copy_eq (f : α →+* β) (f' : α → β) (h : f' = f) : f.copy f' h = f := DFunLike.ext' h end coe section variable {_ : NonAssocSemiring α} {_ : NonAssocSemiring β} (f : α →+* β) protected theorem congr_fun {f g : α →+* β} (h : f = g) (x : α) : f x = g x := DFunLike.congr_fun h x protected theorem congr_arg (f : α →+* β) {x y : α} (h : x = y) : f x = f y := DFunLike.congr_arg f h theorem coe_inj ⦃f g : α →+* β⦄ (h : (f : α → β) = g) : f = g := DFunLike.coe_injective h @[ext] theorem ext ⦃f g : α →+* β⦄ : (∀ x, f x = g x) → f = g := DFunLike.ext _ _ @[simp] theorem mk_coe (f : α →+* β) (h₁ h₂ h₃ h₄) : RingHom.mk ⟨⟨f, h₁⟩, h₂⟩ h₃ h₄ = f := ext fun _ => rfl theorem coe_addMonoidHom_injective : Injective (fun f : α →+* β => (f : α →+ β)) := fun _ _ h => ext <| DFunLike.congr_fun (F := α →+ β) h theorem coe_monoidHom_injective : Injective (fun f : α →+* β => (f : α →* β)) := Injective.of_comp (f := DFunLike.coe) DFunLike.coe_injective /-- Ring homomorphisms map zero to zero. -/ protected theorem map_zero (f : α →+* β) : f 0 = 0 := map_zero f /-- Ring homomorphisms map one to one. -/ protected theorem map_one (f : α →+* β) : f 1 = 1 := map_one f /-- Ring homomorphisms preserve addition. -/ protected theorem map_add (f : α →+* β) : ∀ a b, f (a + b) = f a + f b := map_add f /-- Ring homomorphisms preserve multiplication. -/ protected theorem map_mul (f : α →+* β) : ∀ a b, f (a * b) = f a * f b := map_mul f /-- `f : α →+* β` has a trivial codomain iff `f 1 = 0`. -/ theorem codomain_trivial_iff_map_one_eq_zero : (0 : β) = 1 ↔ f 1 = 0 := by rw [map_one, eq_comm] /-- `f : α →+* β` has a trivial codomain iff it has a trivial range. -/ theorem codomain_trivial_iff_range_trivial : (0 : β) = 1 ↔ ∀ x, f x = 0 := f.codomain_trivial_iff_map_one_eq_zero.trans ⟨fun h x => by rw [← mul_one x, map_mul, h, mul_zero], fun h => h 1⟩ /-- `f : α →+* β` doesn't map `1` to `0` if `β` is nontrivial -/ theorem map_one_ne_zero [Nontrivial β] : f 1 ≠ 0 := mt f.codomain_trivial_iff_map_one_eq_zero.mpr zero_ne_one include f in /-- If there is a homomorphism `f : α →+* β` and `β` is nontrivial, then `α` is nontrivial. -/ theorem domain_nontrivial [Nontrivial β] : Nontrivial α := ⟨⟨1, 0, mt (fun h => show f 1 = 0 by rw [h, map_zero]) f.map_one_ne_zero⟩⟩ theorem codomain_trivial (f : α →+* β) [h : Subsingleton α] : Subsingleton β := (subsingleton_or_nontrivial β).resolve_right fun _ => not_nontrivial_iff_subsingleton.mpr h f.domain_nontrivial end /-- Ring homomorphisms preserve additive inverse. -/ protected theorem map_neg [NonAssocRing α] [NonAssocRing β] (f : α →+* β) (x : α) : f (-x) = -f x := map_neg f x /-- Ring homomorphisms preserve subtraction. -/ protected theorem map_sub [NonAssocRing α] [NonAssocRing β] (f : α →+* β) (x y : α) : f (x - y) = f x - f y := map_sub f x y /-- Makes a ring homomorphism from a monoid homomorphism of rings which preserves addition. -/ def mk' [NonAssocSemiring α] [NonAssocRing β] (f : α →* β) (map_add : ∀ a b, f (a + b) = f a + f b) : α →+* β := { AddMonoidHom.mk' f map_add, f with } variable {_ : NonAssocSemiring α} {_ : NonAssocSemiring β} /-- The identity ring homomorphism from a semiring to itself. -/ def id (α : Type*) [NonAssocSemiring α] : α →+* α where toFun := _root_.id map_zero' := rfl map_one' := rfl map_add' _ _ := rfl map_mul' _ _ := rfl instance : Inhabited (α →+* α) := ⟨id α⟩ @[simp, norm_cast] theorem coe_id : ⇑(RingHom.id α) = _root_.id := rfl @[simp] theorem id_apply (x : α) : RingHom.id α x = x := rfl @[simp] theorem coe_addMonoidHom_id : (id α : α →+ α) = AddMonoidHom.id α := rfl @[simp] theorem coe_monoidHom_id : (id α : α →* α) = MonoidHom.id α := rfl variable {_ : NonAssocSemiring γ} /-- Composition of ring homomorphisms is a ring homomorphism. -/ def comp (g : β →+* γ) (f : α →+* β) : α →+* γ := { g.toNonUnitalRingHom.comp f.toNonUnitalRingHom with toFun := g ∘ f, map_one' := by simp } /-- Composition of semiring homomorphisms is associative. -/ theorem comp_assoc {δ} {_ : NonAssocSemiring δ} (f : α →+* β) (g : β →+* γ) (h : γ →+* δ) : (h.comp g).comp f = h.comp (g.comp f) := rfl @[simp] theorem coe_comp (hnp : β →+* γ) (hmn : α →+* β) : (hnp.comp hmn : α → γ) = hnp ∘ hmn := rfl theorem comp_apply (hnp : β →+* γ) (hmn : α →+* β) (x : α) : (hnp.comp hmn : α → γ) x = hnp (hmn x) := rfl @[simp] theorem comp_id (f : α →+* β) : f.comp (id α) = f := ext fun _ => rfl @[simp] theorem id_comp (f : α →+* β) : (id β).comp f = f := ext fun _ => rfl instance instOne : One (α →+* α) where one := id _ instance instMul : Mul (α →+* α) where mul := comp lemma one_def : (1 : α →+* α) = id α := rfl lemma mul_def (f g : α →+* α) : f * g = f.comp g := rfl @[simp, norm_cast] lemma coe_one : ⇑(1 : α →+* α) = _root_.id := rfl @[simp, norm_cast] lemma coe_mul (f g : α →+* α) : ⇑(f * g) = f ∘ g := rfl instance instMonoid : Monoid (α →+* α) where mul_one := comp_id one_mul := id_comp mul_assoc _ _ _ := comp_assoc _ _ _ npow n f := (npowRec n f).copy f^[n] <| by induction n <;> simp [npowRec, *] npow_succ _ _ := DFunLike.coe_injective <| Function.iterate_succ _ _ @[simp, norm_cast] lemma coe_pow (f : α →+* α) (n : ℕ) : ⇑(f ^ n) = f^[n] := rfl @[simp] theorem cancel_right {g₁ g₂ : β →+* γ} {f : α →+* β} (hf : Surjective f) : g₁.comp f = g₂.comp f ↔ g₁ = g₂ := ⟨fun h => RingHom.ext <| hf.forall.2 (RingHom.ext_iff.1 h), fun h => h ▸ rfl⟩ @[simp] theorem cancel_left {g : β →+* γ} {f₁ f₂ : α →+* β} (hg : Injective g) : g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ := ⟨fun h => RingHom.ext fun x => hg <| by rw [← comp_apply, h, comp_apply], fun h => h ▸ rfl⟩ end RingHom section Semiring variable [Semiring α] [Semiring β] protected lemma RingHom.map_pow (f : α →+* β) (a) : ∀ n : ℕ, f (a ^ n) = f a ^ n := map_pow f a end Semiring namespace AddMonoidHom variable [CommRing α] [IsDomain α] [CommRing β] (f : β →+ α) /-- Make a ring homomorphism from an additive group homomorphism from a commutative ring to an integral domain that commutes with self multiplication, assumes that two is nonzero and `1` is sent to `1`. -/ def mkRingHomOfMulSelfOfTwoNeZero (h : ∀ x, f (x * x) = f x * f x) (h_two : (2 : α) ≠ 0) (h_one : f 1 = 1) : β →+* α := { f with map_one' := h_one, map_mul' := fun x y => by have hxy := h (x + y) rw [mul_add, add_mul, add_mul, f.map_add, f.map_add, f.map_add, f.map_add, h x, h y, add_mul, mul_add, mul_add, ← sub_eq_zero, add_comm (f x * f x + f (y * x)), ← sub_sub, ← sub_sub, ← sub_sub, mul_comm y x, mul_comm (f y) (f x)] at hxy simp only [add_assoc, add_sub_assoc, add_sub_cancel] at hxy rw [sub_sub, ← two_mul, ← add_sub_assoc, ← two_mul, ← mul_sub, mul_eq_zero (M₀ := α), sub_eq_zero, or_iff_not_imp_left] at hxy exact hxy h_two } @[simp] theorem coe_fn_mkRingHomOfMulSelfOfTwoNeZero (h h_two h_one) : (f.mkRingHomOfMulSelfOfTwoNeZero h h_two h_one : β → α) = f := rfl @[simp] theorem coe_addMonoidHom_mkRingHomOfMulSelfOfTwoNeZero (h h_two h_one) : (f.mkRingHomOfMulSelfOfTwoNeZero h h_two h_one : β →+ α) = f := by ext rfl end AddMonoidHom
.lake/packages/mathlib/Mathlib/Algebra/Ring/Submonoid/Pointwise.lean
import Mathlib.Algebra.Group.Submonoid.Pointwise import Mathlib.Algebra.Module.Defs import Mathlib.Data.Nat.Cast.Basic /-! # Elementwise monoid structure of additive submonoids These definitions are a cut-down versions of the ones around `Submodule.mul`, as that API is usually more useful. `SMul (AddSubmonoid R) (AddSubmonoid A)` is also provided given `DistribSMul R A`, and when `R = A` it is definitionally equal to the multiplication on `AddSubmonoid R`. These are all available in the `Pointwise` locale. Additionally, it provides various degrees of monoid structure: * `AddSubmonoid.one` * `AddSubmonoid.mul` * `AddSubmonoid.mulOneClass` * `AddSubmonoid.semigroup` * `AddSubmonoid.monoid` which is available globally to match the monoid structure implied by `Submodule.idemSemiring`. ## Implementation notes Many results about multiplication are derived from the corresponding results about scalar multiplication, but results requiring right distributivity do not have SMul versions, due to the lack of a suitable typeclass (unless one goes all the way to `Module`). -/ open AddSubmonoid Set open scoped Pointwise variable {M R A : Type*} namespace AddSubmonoid section AddMonoidWithOne variable [AddMonoidWithOne R] /-- If `R` is an additive monoid with one (e.g., a semiring), then `1 : AddSubmonoid R` is the range of `Nat.cast : ℕ → R`. -/ protected def one : One (AddSubmonoid R) := ⟨AddMonoidHom.mrange (Nat.castAddMonoidHom R)⟩ scoped[Pointwise] attribute [instance] AddSubmonoid.one lemma one_eq_mrange : (1 : AddSubmonoid R) = AddMonoidHom.mrange (Nat.castAddMonoidHom R) := rfl lemma natCast_mem_one (n : ℕ) : (n : R) ∈ (1 : AddSubmonoid R) := ⟨_, rfl⟩ @[simp] lemma mem_one {x : R} : x ∈ (1 : AddSubmonoid R) ↔ ∃ n : ℕ, ↑n = x := .rfl lemma one_eq_closure : (1 : AddSubmonoid R) = closure {1} := by rw [closure_singleton_eq, one_eq_mrange]; congr 1; ext; simp lemma one_eq_closure_one_set : (1 : AddSubmonoid R) = closure 1 := one_eq_closure end AddMonoidWithOne section SMul variable [AddMonoid R] [AddMonoid A] [DistribSMul R A] /-- For `M : Submonoid R` and `N : AddSubmonoid A`, `M • N` is the additive submonoid generated by all `m • n` where `m ∈ M` and `n ∈ N`. -/ protected def smul : SMul (AddSubmonoid R) (AddSubmonoid A) where smul M N := ⨆ s : M, N.map (DistribSMul.toAddMonoidHom A s.1) scoped[Pointwise] attribute [instance] AddSubmonoid.smul variable {M M' : AddSubmonoid R} {N P : AddSubmonoid A} {m : R} {n : A} lemma smul_mem_smul (hm : m ∈ M) (hn : n ∈ N) : m • n ∈ M • N := (le_iSup _ ⟨m, hm⟩ : _ ≤ M • N) ⟨n, hn, by rfl⟩ lemma smul_le : M • N ≤ P ↔ ∀ m ∈ M, ∀ n ∈ N, m • n ∈ P := ⟨fun H _m hm _n hn => H <| smul_mem_smul hm hn, fun H => iSup_le fun ⟨m, hm⟩ => map_le_iff_le_comap.2 fun n hn => H m hm n hn⟩ @[elab_as_elim] protected lemma smul_induction_on {C : A → Prop} {a : A} (ha : a ∈ M • N) (hm : ∀ m ∈ M, ∀ n ∈ N, C (m • n)) (hadd : ∀ x y, C x → C y → C (x + y)) : C a := (@smul_le _ _ _ _ _ _ _ ⟨⟨setOf C, hadd _ _⟩, by simpa only [smul_zero] using hm _ (zero_mem _) _ (zero_mem _)⟩).2 hm ha @[simp] lemma addSubmonoid_smul_bot (S : AddSubmonoid R) : S • (⊥ : AddSubmonoid A) = ⊥ := eq_bot_iff.2 <| smul_le.2 fun m _ n hn => by rw [AddSubmonoid.mem_bot] at hn ⊢; rw [hn, smul_zero] lemma smul_le_smul (h : M ≤ M') (hnp : N ≤ P) : M • N ≤ M' • P := smul_le.2 fun _m hm _n hn => smul_mem_smul (h hm) (hnp hn) lemma smul_le_smul_left (h : M ≤ M') : M • P ≤ M' • P := smul_le_smul h le_rfl lemma smul_le_smul_right (h : N ≤ P) : M • N ≤ M • P := smul_le_smul le_rfl h lemma smul_subset_smul : (↑M : Set R) • (↑N : Set A) ⊆ (↑(M • N) : Set A) := smul_subset_iff.2 fun _i hi _j hj ↦ smul_mem_smul hi hj lemma addSubmonoid_smul_sup : M • (N ⊔ P) = M • N ⊔ M • P := le_antisymm (smul_le.mpr fun m hm np hnp ↦ by refine closure_induction (motive := (fun _ ↦ _ • · ∈ _)) ?_ ?_ ?_ (sup_eq_closure N P ▸ hnp) · rintro x (hx | hx) exacts [le_sup_left (a := M • N) (smul_mem_smul hm hx), le_sup_right (a := M • N) (smul_mem_smul hm hx)] · apply (smul_zero (A := A) m).symm ▸ (M • N ⊔ M • P).zero_mem · intro _ _ _ _ h1 h2; rw [smul_add]; exact add_mem h1 h2) (sup_le (smul_le_smul_right le_sup_left) <| smul_le_smul_right le_sup_right) variable {ι : Sort*} lemma smul_iSup (T : AddSubmonoid R) (S : ι → AddSubmonoid A) : (T • ⨆ i, S i) = ⨆ i, T • S i := le_antisymm (smul_le.mpr fun t ht s hs ↦ iSup_induction _ (motive := (t • · ∈ _)) hs (fun i s hs ↦ mem_iSup_of_mem i <| smul_mem_smul ht hs) (by simp_rw [smul_zero]; apply zero_mem) fun x y ↦ by simp_rw [smul_add]; apply add_mem) (iSup_le fun i ↦ smul_le_smul_right <| le_iSup _ i) end SMul section NonUnitalNonAssocSemiring variable [NonUnitalNonAssocSemiring R] {M N P : AddSubmonoid R} /-- Multiplication of additive submonoids of a semiring R. The additive submonoid `S * T` is the smallest R-submodule of `R` containing the elements `s * t` for `s ∈ S` and `t ∈ T`. -/ protected def mul : Mul (AddSubmonoid R) := ⟨fun M N => ⨆ s : M, N.map (AddMonoidHom.mul s.1)⟩ scoped[Pointwise] attribute [instance] AddSubmonoid.mul lemma mul_mem_mul {m n : R} (hm : m ∈ M) (hn : n ∈ N) : m * n ∈ M * N := smul_mem_smul hm hn lemma mul_le : M * N ≤ P ↔ ∀ m ∈ M, ∀ n ∈ N, m * n ∈ P := smul_le @[elab_as_elim] protected lemma mul_induction_on {C : R → Prop} {r : R} (hr : r ∈ M * N) (hm : ∀ m ∈ M, ∀ n ∈ N, C (m * n)) (ha : ∀ x y, C x → C y → C (x + y)) : C r := AddSubmonoid.smul_induction_on hr hm ha -- need `add_smul` to generalize to `SMul` lemma closure_mul_closure (S T : Set R) : closure S * closure T = closure (S * T) := by apply le_antisymm · refine mul_le.2 fun a ha b hb => ?_ rw [← AddMonoidHom.mulRight_apply, ← AddSubmonoid.mem_comap] refine (closure_le.2 fun a' ha' => ?_) ha change b ∈ (closure (S * T)).comap (AddMonoidHom.mulLeft a') refine (closure_le.2 fun b' hb' => ?_) hb change a' * b' ∈ closure (S * T) exact subset_closure (Set.mul_mem_mul ha' hb') · rw [closure_le] rintro _ ⟨a, ha, b, hb, rfl⟩ exact mul_mem_mul (subset_closure ha) (subset_closure hb) lemma mul_eq_closure_mul_set (M N : AddSubmonoid R) : M * N = closure (M * N : Set R) := by rw [← closure_mul_closure, closure_eq, closure_eq] @[simp] lemma mul_bot (S : AddSubmonoid R) : S * ⊥ = ⊥ := addSubmonoid_smul_bot S -- need `zero_smul` to generalize to `SMul` @[simp] lemma bot_mul (S : AddSubmonoid R) : ⊥ * S = ⊥ := eq_bot_iff.2 <| mul_le.2 fun m hm n _ => by rw [AddSubmonoid.mem_bot] at hm ⊢; rw [hm, zero_mul] variable {M N P Q : AddSubmonoid R} @[mono, gcongr] lemma mul_le_mul (hmp : M ≤ P) (hnq : N ≤ Q) : M * N ≤ P * Q := smul_le_smul hmp hnq lemma mul_le_mul_left (h : M ≤ N) : M * P ≤ N * P := smul_le_smul_left h lemma mul_le_mul_right (h : N ≤ P) : M * N ≤ M * P := smul_le_smul_right h lemma mul_subset_mul : (↑M : Set R) * (↑N : Set R) ⊆ (↑(M * N) : Set R) := smul_subset_smul lemma mul_sup : M * (N ⊔ P) = M * N ⊔ M * P := addSubmonoid_smul_sup -- need `zero_smul` and `add_smul` to generalize to `SMul` lemma sup_mul : (M ⊔ N) * P = M * P ⊔ N * P := le_antisymm (mul_le.mpr fun mn hmn p hp ↦ by obtain ⟨m, hm, n, hn, rfl⟩ := mem_sup.mp hmn rw [right_distrib]; exact add_mem_sup (mul_mem_mul hm hp) <| mul_mem_mul hn hp) (sup_le (mul_le_mul_left le_sup_left) <| mul_le_mul_left le_sup_right) variable {ι : Sort*} -- need `zero_smul` and `add_smul` to generalize to `SMul` lemma iSup_mul (S : ι → AddSubmonoid R) (T : AddSubmonoid R) : (⨆ i, S i) * T = ⨆ i, S i * T := le_antisymm (mul_le.mpr fun s hs t ht ↦ iSup_induction _ (motive := (· * t ∈ _)) hs (fun i s hs ↦ mem_iSup_of_mem i <| mul_mem_mul hs ht) (by simp_rw [zero_mul]; apply zero_mem) fun _ _ ↦ by simp_rw [right_distrib]; apply add_mem) <| iSup_le fun i ↦ mul_le_mul_left (le_iSup _ i) lemma mul_iSup (T : AddSubmonoid R) (S : ι → AddSubmonoid R) : (T * ⨆ i, S i) = ⨆ i, T * S i := smul_iSup T S lemma mul_comm_of_commute (h : ∀ m ∈ M, ∀ n ∈ N, Commute m n) : M * N = N * M := le_antisymm (mul_le.mpr fun m hm n hn ↦ h m hm n hn ▸ mul_mem_mul hn hm) (mul_le.mpr fun n hn m hm ↦ h m hm n hn ▸ mul_mem_mul hm hn) end NonUnitalNonAssocSemiring section NonUnitalNonAssocRing variable [NonUnitalNonAssocRing R] /-- `AddSubmonoid.neg` distributes over multiplication. This is available as an instance in the `Pointwise` locale. -/ protected def hasDistribNeg : HasDistribNeg (AddSubmonoid R) where neg_mul x y := by refine le_antisymm (mul_le.2 fun m hm n hn => ?_) ((AddSubmonoid.neg_le _ _).2 <| mul_le.2 fun m hm n hn => ?_) <;> simp only [AddSubmonoid.mem_neg, ← neg_mul] at * · exact mul_mem_mul hm hn · exact mul_mem_mul (neg_mem_neg.2 hm) hn mul_neg x y := by refine le_antisymm (mul_le.2 fun m hm n hn => ?_) ((AddSubmonoid.neg_le _ _).2 <| mul_le.2 fun m hm n hn => ?_) <;> simp only [AddSubmonoid.mem_neg, ← mul_neg] at * · exact mul_mem_mul hm hn · exact mul_mem_mul hm (neg_mem_neg.2 hn) scoped[Pointwise] attribute [instance] AddSubmonoid.hasDistribNeg end NonUnitalNonAssocRing section NonAssocSemiring variable [NonAssocSemiring R] /-- A `MulOneClass` structure on additive submonoids of a (possibly, non-associative) semiring. -/ protected def mulOneClass : MulOneClass (AddSubmonoid R) where one_mul M := by rw [one_eq_closure_one_set, ← closure_eq M, closure_mul_closure, one_mul] mul_one M := by rw [one_eq_closure_one_set, ← closure_eq M, closure_mul_closure, mul_one] scoped[Pointwise] attribute [instance] AddSubmonoid.mulOneClass end NonAssocSemiring section NonUnitalSemiring variable [NonUnitalSemiring R] /-- Semigroup structure on additive submonoids of a (possibly, non-unital) semiring. -/ protected def semigroup : Semigroup (AddSubmonoid R) where mul_assoc _M _N _P := le_antisymm (mul_le.2 fun _mn hmn p hp => AddSubmonoid.mul_induction_on hmn (fun m hm n hn ↦ mul_assoc m n p ▸ mul_mem_mul hm <| mul_mem_mul hn hp) fun x y ↦ (add_mul x y p).symm ▸ add_mem) (mul_le.2 fun m hm _np hnp => AddSubmonoid.mul_induction_on hnp (fun n hn p hp ↦ mul_assoc m n p ▸ mul_mem_mul (mul_mem_mul hm hn) hp) fun x y ↦ (mul_add m x y) ▸ add_mem) scoped[Pointwise] attribute [instance] AddSubmonoid.semigroup end NonUnitalSemiring section Semiring variable [Semiring R] /-- Monoid structure on additive submonoids of a semiring. -/ protected def monoid : Monoid (AddSubmonoid R) where scoped[Pointwise] attribute [instance] AddSubmonoid.monoid lemma closure_pow (s : Set R) : ∀ n : ℕ, closure s ^ n = closure (s ^ n) | 0 => by rw [pow_zero, pow_zero, one_eq_closure_one_set] | n + 1 => by rw [pow_succ, pow_succ, closure_pow s n, closure_mul_closure] lemma pow_eq_closure_pow_set (s : AddSubmonoid R) (n : ℕ) : s ^ n = closure ((s : Set R) ^ n) := by rw [← closure_pow, closure_eq] lemma pow_subset_pow {s : AddSubmonoid R} {n : ℕ} : (↑s : Set R) ^ n ⊆ ↑(s ^ n) := (pow_eq_closure_pow_set s n).symm ▸ subset_closure end Semiring end AddSubmonoid
.lake/packages/mathlib/Mathlib/Algebra/Ring/Submonoid/Basic.lean
import Mathlib.Algebra.Group.Submonoid.Basic import Mathlib.Algebra.Ring.Defs /-! # Lemmas about additive closures of `Subsemigroup`. -/ open AddSubmonoid namespace MulMemClass variable {M R : Type*} [NonUnitalNonAssocSemiring R] [SetLike M R] [MulMemClass M R] {S : M} {a b : R} /-- The product of an element of the additive closure of a multiplicative subsemigroup `M` and an element of `M` is contained in the additive closure of `M`. -/ lemma mul_right_mem_add_closure (ha : a ∈ closure (S : Set R)) (hb : b ∈ S) : a * b ∈ closure (S : Set R) := by induction ha using closure_induction with | mem r hr => exact mem_closure.mpr fun y hy => hy (mul_mem hr hb) | zero => simp only [zero_mul, zero_mem _] | add r s _ _ hr hs => simpa only [add_mul] using add_mem hr hs /-- The product of two elements of the additive closure of a submonoid `M` is an element of the additive closure of `M`. -/ lemma mul_mem_add_closure (ha : a ∈ closure (S : Set R)) (hb : b ∈ closure (S : Set R)) : a * b ∈ closure (S : Set R) := by induction hb using closure_induction with | mem r hr => exact MulMemClass.mul_right_mem_add_closure ha hr | zero => simp only [mul_zero, zero_mem _] | add r s _ _ hr hs => simpa only [mul_add] using add_mem hr hs /-- The product of an element of `S` and an element of the additive closure of a multiplicative submonoid `S` is contained in the additive closure of `S`. -/ lemma mul_left_mem_add_closure (ha : a ∈ S) (hb : b ∈ closure (S : Set R)) : a * b ∈ closure (S : Set R) := mul_mem_add_closure (mem_closure.mpr fun _sT hT => hT ha) hb end MulMemClass
.lake/packages/mathlib/Mathlib/Algebra/Ring/Divisibility/Lemmas.lean
import Mathlib.Algebra.GroupWithZero.Divisibility import Mathlib.Algebra.Ring.Divisibility.Basic import Mathlib.Data.Nat.Choose.Sum import Mathlib.GroupTheory.GroupAction.Ring import Mathlib.Algebra.GCDMonoid.Basic /-! # Lemmas about divisibility in rings ## Main results: * `dvd_smul_of_dvd`: stating that `x ∣ y → x ∣ m • y` for any scalar `m`. * `Commute.pow_dvd_add_pow_of_pow_eq_zero_right`: stating that if `y` is nilpotent then `x ^ m ∣ (x + y) ^ p` for sufficiently large `p` (together with many variations for convenience). -/ variable {R : Type*} lemma dvd_smul_of_dvd {M : Type*} [SMul M R] [Semigroup R] [SMulCommClass M R R] {x y : R} (m : M) (h : x ∣ y) : x ∣ m • y := let ⟨k, hk⟩ := h; ⟨m • k, by rw [mul_smul_comm, ← hk]⟩ lemma dvd_nsmul_of_dvd [NonUnitalSemiring R] {x y : R} (n : ℕ) (h : x ∣ y) : x ∣ n • y := dvd_smul_of_dvd n h lemma dvd_zsmul_of_dvd [NonUnitalRing R] {x y : R} (z : ℤ) (h : x ∣ y) : x ∣ z • y := dvd_smul_of_dvd z h namespace Commute variable {x y : R} {n m p : ℕ} section Semiring variable [Semiring R] lemma pow_dvd_add_pow_of_pow_eq_zero_right (hp : n + m ≤ p + 1) (h_comm : Commute x y) (hy : y ^ n = 0) : x ^ m ∣ (x + y) ^ p := by rw [h_comm.add_pow'] refine Finset.dvd_sum fun ⟨i, j⟩ hij ↦ ?_ replace hij : i + j = p := by simpa using hij apply dvd_nsmul_of_dvd rcases le_or_gt m i with (hi : m ≤ i) | (hi : i + 1 ≤ m) · exact dvd_mul_of_dvd_left (pow_dvd_pow x hi) _ · simp [pow_eq_zero_of_le (by cutsat : n ≤ j) hy] lemma pow_dvd_add_pow_of_pow_eq_zero_left (hp : n + m ≤ p + 1) (h_comm : Commute x y) (hx : x ^ n = 0) : y ^ m ∣ (x + y) ^ p := add_comm x y ▸ h_comm.symm.pow_dvd_add_pow_of_pow_eq_zero_right hp hx end Semiring section Ring variable [Ring R] lemma pow_dvd_pow_of_sub_pow_eq_zero (hp : n + m ≤ p + 1) (h_comm : Commute x y) (h : (x - y) ^ n = 0) : x ^ m ∣ y ^ p := by rw [← sub_add_cancel y x] apply (h_comm.symm.sub_left rfl).pow_dvd_add_pow_of_pow_eq_zero_left hp _ rw [← neg_sub x y, neg_pow, h, mul_zero] lemma pow_dvd_pow_of_add_pow_eq_zero (hp : n + m ≤ p + 1) (h_comm : Commute x y) (h : (x + y) ^ n = 0) : x ^ m ∣ y ^ p := by rw [← neg_neg y, neg_pow'] apply dvd_mul_of_dvd_left apply h_comm.neg_right.pow_dvd_pow_of_sub_pow_eq_zero hp simpa lemma pow_dvd_sub_pow_of_pow_eq_zero_right (hp : n + m ≤ p + 1) (h_comm : Commute x y) (hy : y ^ n = 0) : x ^ m ∣ (x - y) ^ p := (sub_right rfl h_comm).pow_dvd_pow_of_sub_pow_eq_zero hp (by simpa) lemma pow_dvd_sub_pow_of_pow_eq_zero_left (hp : n + m ≤ p + 1) (h_comm : Commute x y) (hx : x ^ n = 0) : y ^ m ∣ (x - y) ^ p := by rw [← neg_sub y x, neg_pow'] apply dvd_mul_of_dvd_left exact h_comm.symm.pow_dvd_sub_pow_of_pow_eq_zero_right hp hx lemma add_pow_dvd_pow_of_pow_eq_zero_right (hp : n + m ≤ p + 1) (h_comm : Commute x y) (hx : x ^ n = 0) : (x + y) ^ m ∣ y ^ p := (h_comm.add_left rfl).pow_dvd_pow_of_sub_pow_eq_zero hp (by simpa) lemma add_pow_dvd_pow_of_pow_eq_zero_left (hp : n + m ≤ p + 1) (h_comm : Commute x y) (hy : y ^ n = 0) : (x + y) ^ m ∣ x ^ p := add_comm x y ▸ h_comm.symm.add_pow_dvd_pow_of_pow_eq_zero_right hp hy end Ring end Commute section CommRing variable [CommRing R] lemma dvd_mul_sub_mul_mul_left_of_dvd {p a b c d x y : R} (h1 : p ∣ a * x + b * y) (h2 : p ∣ c * x + d * y) : p ∣ (a * d - b * c) * x := by obtain ⟨k1, hk1⟩ := h1 obtain ⟨k2, hk2⟩ := h2 refine ⟨d * k1 - b * k2, ?_⟩ grind lemma dvd_mul_sub_mul_mul_right_of_dvd {p a b c d x y : R} (h1 : p ∣ a * x + b * y) (h2 : p ∣ c * x + d * y) : p ∣ (a * d - b * c) * y := (mul_comm a _ ▸ mul_comm c _ ▸ dvd_mul_sub_mul_mul_left_of_dvd (add_comm (c * x) _ ▸ h2) (add_comm (a * x) _ ▸ h1)) lemma dvd_mul_sub_mul_mul_gcd_of_dvd {p a b c d x y : R} [IsDomain R] [GCDMonoid R] (h1 : p ∣ a * x + b * y) (h2 : p ∣ c * x + d * y) : p ∣ (a * d - b * c) * gcd x y := by rw [← (gcd_mul_left' (a*d - b*c) x y).dvd_iff_dvd_right] exact (dvd_gcd_iff _ _ _).2 ⟨dvd_mul_sub_mul_mul_left_of_dvd h1 h2, dvd_mul_sub_mul_mul_right_of_dvd h1 h2⟩ end CommRing section misc variable [Ring R] [LinearOrder R] {x y : R} @[simp] theorem associated_abs_left_iff : Associated |x| y ↔ Associated x y := by obtain h | h := abs_choice x <;> simp [h] @[simp] theorem associated_abs_right_iff : Associated x |y| ↔ Associated x y := by rw [Associated.comm, associated_abs_left_iff, Associated.comm] alias ⟨_, Associated.abs_left⟩ := associated_abs_left_iff alias ⟨_, Associated.abs_right⟩ := associated_abs_right_iff end misc