source
stringlengths
17
118
lean4
stringlengths
0
335k
.lake/packages/mathlib/Mathlib/LinearAlgebra/SymplecticGroup.lean
import Mathlib.LinearAlgebra.Matrix.NonsingularInverse /-! # The Symplectic Group This file defines the symplectic group and proves elementary properties. ## Main Definitions * `Matrix.J`: the canonical `2n × 2n` skew-symmetric matrix * `symplecticGroup`: the group of symplectic matrices ## TODO * Every symplectic matrix has determinant 1. * For `n = 1` the symplectic group coincides with the special linear group. -/ open Matrix variable {l R : Type*} namespace Matrix variable (l) [DecidableEq l] (R) [CommRing R] section JMatrixLemmas /-- The matrix defining the canonical skew-symmetric bilinear form. -/ def J : Matrix (l ⊕ l) (l ⊕ l) R := Matrix.fromBlocks 0 (-1) 1 0 @[simp] theorem J_transpose : (J l R)ᵀ = -J l R := by rw [J, fromBlocks_transpose, ← neg_one_smul R (fromBlocks _ _ _ _ : Matrix (l ⊕ l) (l ⊕ l) R), fromBlocks_smul, Matrix.transpose_zero, Matrix.transpose_one, transpose_neg] simp [fromBlocks] variable [Fintype l] theorem J_squared : J l R * J l R = -1 := by rw [J, fromBlocks_multiply] simp only [Matrix.zero_mul, Matrix.neg_mul, zero_add, neg_zero, Matrix.one_mul, add_zero] rw [← neg_zero, ← Matrix.fromBlocks_neg, ← fromBlocks_one] theorem J_inv : (J l R)⁻¹ = -J l R := by refine Matrix.inv_eq_right_inv ?_ rw [Matrix.mul_neg, J_squared] exact neg_neg 1 theorem J_det_mul_J_det : det (J l R) * det (J l R) = 1 := by rw [← det_mul, J_squared, ← one_smul R (-1 : Matrix _ _ R), smul_neg, ← neg_smul, det_smul, Fintype.card_sum, det_one, mul_one] apply Even.neg_one_pow exact Even.add_self _ theorem isUnit_det_J : IsUnit (det (J l R)) := isUnit_iff_exists_inv.mpr ⟨det (J l R), J_det_mul_J_det _ _⟩ end JMatrixLemmas variable [Fintype l] /-- The group of symplectic matrices over a ring `R`. -/ def symplecticGroup : Submonoid (Matrix (l ⊕ l) (l ⊕ l) R) where carrier := { A | A * J l R * Aᵀ = J l R } mul_mem' {a b} ha hb := by simp only [Set.mem_setOf_eq, transpose_mul] at * rw [← Matrix.mul_assoc, a.mul_assoc, a.mul_assoc, hb] exact ha one_mem' := by simp end Matrix namespace SymplecticGroup variable [DecidableEq l] [Fintype l] [CommRing R] open Matrix theorem mem_iff {A : Matrix (l ⊕ l) (l ⊕ l) R} : A ∈ symplecticGroup l R ↔ A * J l R * Aᵀ = J l R := by simp [symplecticGroup] instance coeMatrix : Coe (symplecticGroup l R) (Matrix (l ⊕ l) (l ⊕ l) R) := ⟨Subtype.val⟩ section SymplecticJ variable (l) (R) theorem J_mem : J l R ∈ symplecticGroup l R := by rw [mem_iff, J, fromBlocks_multiply, fromBlocks_transpose, fromBlocks_multiply] simp /-- The canonical skew-symmetric matrix as an element in the symplectic group. -/ def symJ : symplecticGroup l R := ⟨J l R, J_mem l R⟩ variable {l} {R} @[simp] theorem coe_J : ↑(symJ l R) = J l R := rfl end SymplecticJ variable {A : Matrix (l ⊕ l) (l ⊕ l) R} theorem neg_mem (h : A ∈ symplecticGroup l R) : -A ∈ symplecticGroup l R := by rw [mem_iff] at h ⊢ simp [h] theorem symplectic_det (hA : A ∈ symplecticGroup l R) : IsUnit <| det A := by rw [isUnit_iff_exists_inv] use A.det refine (isUnit_det_J l R).mul_left_cancel ?_ rw [mul_one] rw [mem_iff] at hA apply_fun det at hA simp only [det_mul, det_transpose] at hA rw [mul_comm A.det, mul_assoc] at hA exact hA theorem transpose_mem (hA : A ∈ symplecticGroup l R) : Aᵀ ∈ symplecticGroup l R := by rw [mem_iff] at hA ⊢ rw [transpose_transpose] have huA := symplectic_det hA have huAT : IsUnit Aᵀ.det := by rw [Matrix.det_transpose] exact huA calc Aᵀ * J l R * A = (-Aᵀ) * (J l R)⁻¹ * A := by rw [J_inv] simp _ = (-Aᵀ) * (A * J l R * Aᵀ)⁻¹ * A := by rw [hA] _ = -(Aᵀ * (Aᵀ⁻¹ * (J l R)⁻¹)) * A⁻¹ * A := by simp only [Matrix.mul_inv_rev, Matrix.mul_assoc, Matrix.neg_mul] _ = -(J l R)⁻¹ := by rw [mul_nonsing_inv_cancel_left _ _ huAT, nonsing_inv_mul_cancel_right _ _ huA] _ = J l R := by simp [J_inv] @[simp] theorem transpose_mem_iff : Aᵀ ∈ symplecticGroup l R ↔ A ∈ symplecticGroup l R := ⟨fun hA => by simpa using transpose_mem hA, transpose_mem⟩ theorem mem_iff' : A ∈ symplecticGroup l R ↔ Aᵀ * J l R * A = J l R := by rw [← transpose_mem_iff, mem_iff, transpose_transpose] instance hasInv : Inv (symplecticGroup l R) where inv A := ⟨(-J l R) * (A : Matrix (l ⊕ l) (l ⊕ l) R)ᵀ * J l R, mul_mem (mul_mem (neg_mem <| J_mem _ _) <| transpose_mem A.2) <| J_mem _ _⟩ theorem coe_inv (A : symplecticGroup l R) : (↑A⁻¹ : Matrix _ _ _) = (-J l R) * (↑A)ᵀ * J l R := rfl theorem inv_left_mul_aux (hA : A ∈ symplecticGroup l R) : -(J l R * Aᵀ * J l R * A) = 1 := calc -(J l R * Aᵀ * J l R * A) = (-J l R) * (Aᵀ * J l R * A) := by simp only [Matrix.mul_assoc, Matrix.neg_mul] _ = (-J l R) * J l R := by rw [mem_iff'] at hA rw [hA] _ = (-1 : R) • (J l R * J l R) := by simp only [Matrix.neg_mul, neg_smul, one_smul] _ = (-1 : R) • (-1 : Matrix _ _ _) := by rw [J_squared] _ = 1 := by simp only [neg_smul_neg, one_smul] theorem coe_inv' (A : symplecticGroup l R) : (↑A⁻¹ : Matrix (l ⊕ l) (l ⊕ l) R) = (↑A)⁻¹ := by refine (coe_inv A).trans (inv_eq_left_inv ?_).symm simp [inv_left_mul_aux] theorem inv_eq_symplectic_inv (A : Matrix (l ⊕ l) (l ⊕ l) R) (hA : A ∈ symplecticGroup l R) : A⁻¹ = (-J l R) * Aᵀ * J l R := inv_eq_left_inv (by simp only [Matrix.neg_mul, inv_left_mul_aux hA]) instance : Group (symplecticGroup l R) := { SymplecticGroup.hasInv, Submonoid.toMonoid _ with inv_mul_cancel := fun A => by apply Subtype.ext simp only [Submonoid.coe_one, Submonoid.coe_mul, Matrix.neg_mul, coe_inv] exact inv_left_mul_aux A.2 } end SymplecticGroup
.lake/packages/mathlib/Mathlib/LinearAlgebra/Prod.lean
import Mathlib.Algebra.Algebra.Prod import Mathlib.Algebra.Group.Graph import Mathlib.LinearAlgebra.Span.Basic /-! ### Products of modules This file defines constructors for linear maps whose domains or codomains are products. It contains theorems relating these to each other, as well as to `Submodule.prod`, `Submodule.map`, `Submodule.comap`, `LinearMap.range`, and `LinearMap.ker`. ## Main definitions - products in the domain: - `LinearMap.fst` - `LinearMap.snd` - `LinearMap.coprod` - `LinearMap.prod_ext` - products in the codomain: - `LinearMap.inl` - `LinearMap.inr` - `LinearMap.prod` - products in both domain and codomain: - `LinearMap.prodMap` - `LinearEquiv.prodMap` - `LinearEquiv.skewProd` - product with the trivial module: - `LinearEquiv.prodUnique` - `LinearEquiv.uniqueProd` -/ universe u v w x y z u' v' w' y' variable {R : Type u} {K : Type u'} {M : Type v} {V : Type v'} {M₂ : Type w} {V₂ : Type w'} variable {M₃ : Type y} {V₃ : Type y'} {M₄ : Type z} {ι : Type x} variable {M₅ M₆ : Type*} section Prod namespace LinearMap variable (S : Type*) [Semiring R] [Semiring S] variable [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] [AddCommMonoid M₄] variable [AddCommMonoid M₅] [AddCommMonoid M₆] variable [Module R M] [Module R M₂] [Module R M₃] [Module R M₄] variable [Module R M₅] [Module R M₆] variable (f : M →ₗ[R] M₂) section variable (R M M₂) /-- The first projection of a product is a linear map. -/ def fst : M × M₂ →ₗ[R] M where toFun := Prod.fst map_add' _x _y := rfl map_smul' _x _y := rfl /-- The second projection of a product is a linear map. -/ def snd : M × M₂ →ₗ[R] M₂ where toFun := Prod.snd map_add' _x _y := rfl map_smul' _x _y := rfl end @[simp] theorem fst_apply (x : M × M₂) : fst R M M₂ x = x.1 := rfl @[simp] theorem snd_apply (x : M × M₂) : snd R M M₂ x = x.2 := rfl @[simp, norm_cast] lemma coe_fst : ⇑(fst R M M₂) = Prod.fst := rfl @[simp, norm_cast] lemma coe_snd : ⇑(snd R M M₂) = Prod.snd := rfl theorem fst_surjective : Function.Surjective (fst R M M₂) := fun x => ⟨(x, 0), rfl⟩ theorem snd_surjective : Function.Surjective (snd R M M₂) := fun x => ⟨(0, x), rfl⟩ /-- The prod of two linear maps is a linear map. -/ @[simps] def prod (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) : M →ₗ[R] M₂ × M₃ where toFun := Pi.prod f g map_add' x y := by simp only [Pi.prod, Prod.mk_add_mk, map_add] map_smul' c x := by simp only [Pi.prod, Prod.smul_mk, map_smul, RingHom.id_apply] theorem coe_prod (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) : ⇑(f.prod g) = Pi.prod f g := rfl @[simp] theorem fst_prod (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) : (fst R M₂ M₃).comp (prod f g) = f := rfl @[simp] theorem snd_prod (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) : (snd R M₂ M₃).comp (prod f g) = g := rfl @[simp] theorem pair_fst_snd : prod (fst R M M₂) (snd R M M₂) = LinearMap.id := rfl theorem prod_comp (f : M₂ →ₗ[R] M₃) (g : M₂ →ₗ[R] M₄) (h : M →ₗ[R] M₂) : (f.prod g).comp h = (f.comp h).prod (g.comp h) := rfl /-- Taking the product of two maps with the same domain is equivalent to taking the product of their codomains. See note [bundled maps over different rings] for why separate `R` and `S` semirings are used. -/ @[simps] def prodEquiv [Module S M₂] [Module S M₃] [SMulCommClass R S M₂] [SMulCommClass R S M₃] : ((M →ₗ[R] M₂) × (M →ₗ[R] M₃)) ≃ₗ[S] M →ₗ[R] M₂ × M₃ where toFun f := f.1.prod f.2 invFun f := ((fst _ _ _).comp f, (snd _ _ _).comp f) map_add' _ _ := rfl map_smul' _ _ := rfl section variable (R M M₂) /-- The left injection into a product is a linear map. -/ def inl : M →ₗ[R] M × M₂ := prod LinearMap.id 0 /-- The right injection into a product is a linear map. -/ def inr : M₂ →ₗ[R] M × M₂ := prod 0 LinearMap.id theorem range_inl : range (inl R M M₂) = ker (snd R M M₂) := by ext x simp only [mem_ker, mem_range] constructor · rintro ⟨y, rfl⟩ rfl · intro h exact ⟨x.fst, Prod.ext rfl h.symm⟩ theorem ker_snd : ker (snd R M M₂) = range (inl R M M₂) := Eq.symm <| range_inl R M M₂ theorem range_inr : range (inr R M M₂) = ker (fst R M M₂) := by ext x simp only [mem_ker, mem_range] constructor · rintro ⟨y, rfl⟩ rfl · intro h exact ⟨x.snd, Prod.ext h.symm rfl⟩ theorem ker_fst : ker (fst R M M₂) = range (inr R M M₂) := Eq.symm <| range_inr R M M₂ @[simp] theorem fst_comp_inl : fst R M M₂ ∘ₗ inl R M M₂ = id := rfl @[simp] theorem snd_comp_inl : snd R M M₂ ∘ₗ inl R M M₂ = 0 := rfl @[simp] theorem fst_comp_inr : fst R M M₂ ∘ₗ inr R M M₂ = 0 := rfl @[simp] theorem snd_comp_inr : snd R M M₂ ∘ₗ inr R M M₂ = id := rfl end @[simp] theorem coe_inl : (inl R M M₂ : M → M × M₂) = fun x => (x, 0) := rfl theorem inl_apply (x : M) : inl R M M₂ x = (x, 0) := rfl @[simp] theorem coe_inr : (inr R M M₂ : M₂ → M × M₂) = Prod.mk 0 := rfl theorem inr_apply (x : M₂) : inr R M M₂ x = (0, x) := rfl theorem inl_eq_prod : inl R M M₂ = prod LinearMap.id 0 := rfl theorem inr_eq_prod : inr R M M₂ = prod 0 LinearMap.id := rfl theorem inl_injective : Function.Injective (inl R M M₂) := fun _ => by simp theorem inr_injective : Function.Injective (inr R M M₂) := fun _ => by simp /-- The coprod function `x : M × M₂ ↦ f x.1 + g x.2` is a linear map. -/ def coprod (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) : M × M₂ →ₗ[R] M₃ := f.comp (fst _ _ _) + g.comp (snd _ _ _) @[simp] theorem coprod_apply (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) (x : M × M₂) : coprod f g x = f x.1 + g x.2 := rfl @[simp] theorem coprod_inl (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) : (coprod f g).comp (inl R M M₂) = f := by ext; simp only [map_zero, add_zero, coprod_apply, inl_apply, comp_apply] @[simp] theorem coprod_inr (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) : (coprod f g).comp (inr R M M₂) = g := by ext; simp only [map_zero, coprod_apply, inr_apply, zero_add, comp_apply] @[simp] theorem coprod_inl_inr : coprod (inl R M M₂) (inr R M M₂) = LinearMap.id := by ext <;> simp only [Prod.mk_add_mk, add_zero, id_apply, coprod_apply, inl_apply, inr_apply, zero_add] theorem coprod_zero_left (g : M₂ →ₗ[R] M₃) : (0 : M →ₗ[R] M₃).coprod g = g.comp (snd R M M₂) := zero_add _ theorem coprod_zero_right (f : M →ₗ[R] M₃) : f.coprod (0 : M₂ →ₗ[R] M₃) = f.comp (fst R M M₂) := add_zero _ theorem comp_coprod (f : M₃ →ₗ[R] M₄) (g₁ : M →ₗ[R] M₃) (g₂ : M₂ →ₗ[R] M₃) : f.comp (g₁.coprod g₂) = (f.comp g₁).coprod (f.comp g₂) := ext fun x => f.map_add (g₁ x.1) (g₂ x.2) theorem fst_eq_coprod : fst R M M₂ = coprod LinearMap.id 0 := by ext; simp theorem snd_eq_coprod : snd R M M₂ = coprod 0 LinearMap.id := by ext; simp @[simp] theorem coprod_comp_prod (f : M₂ →ₗ[R] M₄) (g : M₃ →ₗ[R] M₄) (f' : M →ₗ[R] M₂) (g' : M →ₗ[R] M₃) : (f.coprod g).comp (f'.prod g') = f.comp f' + g.comp g' := rfl @[simp] theorem coprod_map_prod (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) (S : Submodule R M) (S' : Submodule R M₂) : (Submodule.prod S S').map (LinearMap.coprod f g) = S.map f ⊔ S'.map g := SetLike.coe_injective <| by simp only [LinearMap.coprod_apply, Submodule.coe_sup, Submodule.map_coe] rw [← Set.image2_add, Set.image2_image_left, Set.image2_image_right] exact Set.image_prod fun m m₂ => f m + g m₂ @[simp] theorem coprod_comp_inl_inr (f : M × M₂ →ₗ[R] M₃) : (f.comp (inl R M M₂)).coprod (f.comp (inr R M M₂)) = f := by rw [← comp_coprod, coprod_inl_inr, comp_id] /-- Taking the product of two maps with the same codomain is equivalent to taking the product of their domains. See note [bundled maps over different rings] for why separate `R` and `S` semirings are used. -/ @[simps] def coprodEquiv [Module S M₃] [SMulCommClass R S M₃] : ((M →ₗ[R] M₃) × (M₂ →ₗ[R] M₃)) ≃ₗ[S] M × M₂ →ₗ[R] M₃ where toFun f := f.1.coprod f.2 invFun f := (f.comp (inl _ _ _), f.comp (inr _ _ _)) left_inv f := by simp only [coprod_inl, coprod_inr] right_inv f := by simp only [← comp_coprod, comp_id, coprod_inl_inr] map_add' a b := by ext simp only [Prod.snd_add, add_apply, coprod_apply, Prod.fst_add, add_add_add_comm] map_smul' r a := by dsimp ext simp only [smul_add, smul_apply, coprod_apply] theorem prod_ext_iff {f g : M × M₂ →ₗ[R] M₃} : f = g ↔ f.comp (inl _ _ _) = g.comp (inl _ _ _) ∧ f.comp (inr _ _ _) = g.comp (inr _ _ _) := (coprodEquiv ℕ).symm.injective.eq_iff.symm.trans Prod.ext_iff /-- Split equality of linear maps from a product into linear maps over each component, to allow `ext` to apply lemmas specific to `M →ₗ M₃` and `M₂ →ₗ M₃`. See note [partially-applied ext lemmas]. -/ @[ext 1100] theorem prod_ext {f g : M × M₂ →ₗ[R] M₃} (hl : f.comp (inl _ _ _) = g.comp (inl _ _ _)) (hr : f.comp (inr _ _ _) = g.comp (inr _ _ _)) : f = g := prod_ext_iff.2 ⟨hl, hr⟩ /-- `Prod.map` of two linear maps. -/ def prodMap (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₄) : M × M₂ →ₗ[R] M₃ × M₄ := (f.comp (fst R M M₂)).prod (g.comp (snd R M M₂)) theorem coe_prodMap (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₄) : ⇑(f.prodMap g) = Prod.map f g := rfl @[simp] theorem prodMap_apply (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₄) (x) : f.prodMap g x = (f x.1, g x.2) := rfl theorem prodMap_comap_prod (f : M →ₗ[R] M₂) (g : M₃ →ₗ[R] M₄) (S : Submodule R M₂) (S' : Submodule R M₄) : (Submodule.prod S S').comap (LinearMap.prodMap f g) = (S.comap f).prod (S'.comap g) := SetLike.coe_injective <| Set.preimage_prod_map_prod f g _ _ theorem ker_prodMap (f : M →ₗ[R] M₂) (g : M₃ →ₗ[R] M₄) : ker (LinearMap.prodMap f g) = Submodule.prod (ker f) (ker g) := by dsimp only [ker] rw [← prodMap_comap_prod, Submodule.prod_bot] @[simp] theorem prodMap_id : (id : M →ₗ[R] M).prodMap (id : M₂ →ₗ[R] M₂) = id := rfl @[simp] theorem prodMap_one : (1 : M →ₗ[R] M).prodMap (1 : M₂ →ₗ[R] M₂) = 1 := rfl theorem prodMap_comp (f₁₂ : M →ₗ[R] M₂) (f₂₃ : M₂ →ₗ[R] M₃) (g₁₂ : M₄ →ₗ[R] M₅) (g₂₃ : M₅ →ₗ[R] M₆) : f₂₃.prodMap g₂₃ ∘ₗ f₁₂.prodMap g₁₂ = (f₂₃ ∘ₗ f₁₂).prodMap (g₂₃ ∘ₗ g₁₂) := rfl theorem prodMap_mul (f₁₂ : M →ₗ[R] M) (f₂₃ : M →ₗ[R] M) (g₁₂ : M₂ →ₗ[R] M₂) (g₂₃ : M₂ →ₗ[R] M₂) : f₂₃.prodMap g₂₃ * f₁₂.prodMap g₁₂ = (f₂₃ * f₁₂).prodMap (g₂₃ * g₁₂) := rfl theorem prodMap_add (f₁ : M →ₗ[R] M₃) (f₂ : M →ₗ[R] M₃) (g₁ : M₂ →ₗ[R] M₄) (g₂ : M₂ →ₗ[R] M₄) : (f₁ + f₂).prodMap (g₁ + g₂) = f₁.prodMap g₁ + f₂.prodMap g₂ := rfl @[simp] theorem prodMap_zero : (0 : M →ₗ[R] M₂).prodMap (0 : M₃ →ₗ[R] M₄) = 0 := rfl @[simp] theorem prodMap_smul [DistribMulAction S M₃] [DistribMulAction S M₄] [SMulCommClass R S M₃] [SMulCommClass R S M₄] (s : S) (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₄) : prodMap (s • f) (s • g) = s • prodMap f g := rfl variable (R M M₂ M₃ M₄) /-- `LinearMap.prodMap` as a `LinearMap` -/ @[simps] def prodMapLinear [Module S M₃] [Module S M₄] [SMulCommClass R S M₃] [SMulCommClass R S M₄] : (M →ₗ[R] M₃) × (M₂ →ₗ[R] M₄) →ₗ[S] M × M₂ →ₗ[R] M₃ × M₄ where toFun f := prodMap f.1 f.2 map_add' _ _ := rfl map_smul' _ _ := rfl /-- `LinearMap.prodMap` as a `RingHom` -/ @[simps] def prodMapRingHom : (M →ₗ[R] M) × (M₂ →ₗ[R] M₂) →+* M × M₂ →ₗ[R] M × M₂ where toFun f := prodMap f.1 f.2 map_one' := prodMap_one map_zero' := rfl map_add' _ _ := rfl map_mul' _ _ := rfl variable {R M M₂ M₃ M₄} section map_mul variable {A : Type*} [NonUnitalNonAssocSemiring A] [Module R A] variable {B : Type*} [NonUnitalNonAssocSemiring B] [Module R B] theorem inl_map_mul (a₁ a₂ : A) : LinearMap.inl R A B (a₁ * a₂) = LinearMap.inl R A B a₁ * LinearMap.inl R A B a₂ := Prod.ext rfl (by simp) theorem inr_map_mul (b₁ b₂ : B) : LinearMap.inr R A B (b₁ * b₂) = LinearMap.inr R A B b₁ * LinearMap.inr R A B b₂ := Prod.ext (by simp) rfl end map_mul end LinearMap end Prod namespace LinearMap variable (R M M₂) variable [CommSemiring R] variable [AddCommMonoid M] [AddCommMonoid M₂] variable [Module R M] [Module R M₂] /-- `LinearMap.prodMap` as an `AlgHom` -/ @[simps!] def prodMapAlgHom : Module.End R M × Module.End R M₂ →ₐ[R] Module.End R (M × M₂) := { prodMapRingHom R M M₂ with commutes' := fun _ => rfl } end LinearMap namespace LinearMap open Submodule variable [Semiring R] [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] [AddCommMonoid M₄] [Module R M] [Module R M₂] [Module R M₃] [Module R M₄] theorem range_coprod (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) : range (f.coprod g) = range f ⊔ range g := Submodule.ext fun x => by simp [mem_sup] theorem isCompl_range_inl_inr : IsCompl (range <| inl R M M₂) (range <| inr R M M₂) := by constructor · rw [disjoint_def] rintro ⟨_, _⟩ ⟨x, hx⟩ ⟨y, hy⟩ simp only [Prod.ext_iff, inl_apply, inr_apply] at hx hy ⊢ exact ⟨hy.1.symm, hx.2.symm⟩ · rw [codisjoint_iff_le_sup] rintro ⟨x, y⟩ - simp only [mem_sup, mem_range] refine ⟨(x, 0), ⟨x, rfl⟩, (0, y), ⟨y, rfl⟩, ?_⟩ simp theorem sup_range_inl_inr : (range <| inl R M M₂) ⊔ (range <| inr R M M₂) = ⊤ := IsCompl.sup_eq_top isCompl_range_inl_inr theorem disjoint_inl_inr : Disjoint (range <| inl R M M₂) (range <| inr R M M₂) := by simp +contextual [disjoint_def, @eq_comm M 0] theorem map_coprod_prod (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) (p : Submodule R M) (q : Submodule R M₂) : map (coprod f g) (p.prod q) = map f p ⊔ map g q := coprod_map_prod f g p q theorem comap_prod_prod (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) (p : Submodule R M₂) (q : Submodule R M₃) : comap (prod f g) (p.prod q) = comap f p ⊓ comap g q := Submodule.ext fun _x => Iff.rfl theorem prod_eq_inf_comap (p : Submodule R M) (q : Submodule R M₂) : p.prod q = p.comap (LinearMap.fst R M M₂) ⊓ q.comap (LinearMap.snd R M M₂) := Submodule.ext fun _x => Iff.rfl theorem prod_eq_sup_map (p : Submodule R M) (q : Submodule R M₂) : p.prod q = p.map (LinearMap.inl R M M₂) ⊔ q.map (LinearMap.inr R M M₂) := by rw [← map_coprod_prod, coprod_inl_inr, map_id] theorem span_inl_union_inr {s : Set M} {t : Set M₂} : span R (inl R M M₂ '' s ∪ inr R M M₂ '' t) = (span R s).prod (span R t) := by rw [span_union, prod_eq_sup_map, ← span_image, ← span_image] @[simp] theorem ker_prod (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) : ker (prod f g) = ker f ⊓ ker g := by rw [ker, ← prod_bot, comap_prod_prod]; rfl theorem range_prod_le (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) : range (prod f g) ≤ (range f).prod (range g) := by simp only [SetLike.le_def, prod_apply, mem_range, mem_prod, exists_imp] rintro _ x rfl exact ⟨⟨x, rfl⟩, ⟨x, rfl⟩⟩ theorem ker_prod_ker_le_ker_coprod {M₂ : Type*} [AddCommMonoid M₂] [Module R M₂] {M₃ : Type*} [AddCommMonoid M₃] [Module R M₃] (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) : (ker f).prod (ker g) ≤ ker (f.coprod g) := by rintro ⟨y, z⟩ simp +contextual theorem ker_coprod_of_disjoint_range {M₂ : Type*} [AddCommGroup M₂] [Module R M₂] {M₃ : Type*} [AddCommGroup M₃] [Module R M₃] (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) (hd : Disjoint (range f) (range g)) : ker (f.coprod g) = (ker f).prod (ker g) := by apply le_antisymm _ (ker_prod_ker_le_ker_coprod f g) rintro ⟨y, z⟩ h simp only [mem_ker, mem_prod, coprod_apply] at h ⊢ have : f y ∈ (range f) ⊓ (range g) := by simp only [true_and, mem_range, mem_inf, exists_apply_eq_apply] use -z rwa [eq_comm, map_neg, ← sub_eq_zero, sub_neg_eq_add] rw [hd.eq_bot, mem_bot] at this rw [this] at h simpa [this] using h end LinearMap namespace Submodule open LinearMap variable [Semiring R] variable [AddCommMonoid M] [AddCommMonoid M₂] variable [Module R M] [Module R M₂] theorem sup_eq_range (p q : Submodule R M) : p ⊔ q = range (p.subtype.coprod q.subtype) := Submodule.ext fun x => by simp [Submodule.mem_sup] variable (p : Submodule R M) (q : Submodule R M₂) @[simp] theorem map_inl : p.map (inl R M M₂) = prod p ⊥ := by ext ⟨x, y⟩ simp only [and_left_comm, eq_comm, mem_map, Prod.mk_inj, inl_apply, mem_bot, exists_eq_left', mem_prod] @[simp] theorem map_inr : q.map (inr R M M₂) = prod ⊥ q := by ext ⟨x, y⟩; simp [and_left_comm, eq_comm, and_comm] @[simp] theorem comap_fst : p.comap (fst R M M₂) = prod p ⊤ := by ext ⟨x, y⟩; simp @[simp] theorem comap_snd : q.comap (snd R M M₂) = prod ⊤ q := by ext ⟨x, y⟩; simp @[simp] theorem prod_comap_inl : (prod p q).comap (inl R M M₂) = p := by ext; simp @[simp] theorem prod_comap_inr : (prod p q).comap (inr R M M₂) = q := by ext; simp @[simp] theorem prod_map_fst : (prod p q).map (fst R M M₂) = p := by ext x; simp [(⟨0, zero_mem _⟩ : ∃ x, x ∈ q)] @[simp] theorem prod_map_snd : (prod p q).map (snd R M M₂) = q := by ext x; simp [(⟨0, zero_mem _⟩ : ∃ x, x ∈ p)] @[simp] theorem ker_inl : ker (inl R M M₂) = ⊥ := by rw [ker, ← prod_bot, prod_comap_inl] @[simp] theorem ker_inr : ker (inr R M M₂) = ⊥ := by rw [ker, ← prod_bot, prod_comap_inr] @[simp] theorem range_fst : range (fst R M M₂) = ⊤ := by rw [range_eq_map, ← prod_top, prod_map_fst] @[simp] theorem range_snd : range (snd R M M₂) = ⊤ := by rw [range_eq_map, ← prod_top, prod_map_snd] variable (R M M₂) /-- `M` as a submodule of `M × N`. -/ def fst : Submodule R (M × M₂) := (⊥ : Submodule R M₂).comap (LinearMap.snd R M M₂) /-- `M` as a submodule of `M × N` is isomorphic to `M`. -/ @[simps] def fstEquiv : Submodule.fst R M M₂ ≃ₗ[R] M where toFun x := x.1.1 invFun m := ⟨⟨m, 0⟩, by aesop⟩ map_add' := by simp map_smul' := by simp left_inv x := by aesop (add norm simp Submodule.fst) right_inv x := by simp theorem fst_map_fst : (Submodule.fst R M M₂).map (LinearMap.fst R M M₂) = ⊤ := by aesop theorem fst_map_snd : (Submodule.fst R M M₂).map (LinearMap.snd R M M₂) = ⊥ := by aesop (add simp fst) /-- `N` as a submodule of `M × N`. -/ def snd : Submodule R (M × M₂) := (⊥ : Submodule R M).comap (LinearMap.fst R M M₂) /-- `N` as a submodule of `M × N` is isomorphic to `N`. -/ @[simps] def sndEquiv : Submodule.snd R M M₂ ≃ₗ[R] M₂ where toFun x := x.1.2 invFun n := ⟨⟨0, n⟩, by aesop⟩ map_add' := by simp map_smul' := by simp left_inv x := by aesop (add norm simp Submodule.snd) theorem snd_map_fst : (Submodule.snd R M M₂).map (LinearMap.fst R M M₂) = ⊥ := by aesop (add simp snd) theorem snd_map_snd : (Submodule.snd R M M₂).map (LinearMap.snd R M M₂) = ⊤ := by aesop theorem fst_sup_snd : Submodule.fst R M M₂ ⊔ Submodule.snd R M M₂ = ⊤ := by rw [eq_top_iff] rintro ⟨m, n⟩ - rw [show (m, n) = (m, 0) + (0, n) by simp] apply Submodule.add_mem (Submodule.fst R M M₂ ⊔ Submodule.snd R M M₂) · exact Submodule.mem_sup_left (Submodule.mem_comap.mpr (by simp)) · exact Submodule.mem_sup_right (Submodule.mem_comap.mpr (by simp)) theorem fst_inf_snd : Submodule.fst R M M₂ ⊓ Submodule.snd R M M₂ = ⊥ := by aesop theorem le_prod_iff {p₁ : Submodule R M} {p₂ : Submodule R M₂} {q : Submodule R (M × M₂)} : q ≤ p₁.prod p₂ ↔ map (LinearMap.fst R M M₂) q ≤ p₁ ∧ map (LinearMap.snd R M M₂) q ≤ p₂ := by constructor · intro h constructor · rintro x ⟨⟨y1, y2⟩, ⟨hy1, rfl⟩⟩ exact (h hy1).1 · rintro x ⟨⟨y1, y2⟩, ⟨hy1, rfl⟩⟩ exact (h hy1).2 · rintro ⟨hH, hK⟩ ⟨x1, x2⟩ h exact ⟨hH ⟨_, h, rfl⟩, hK ⟨_, h, rfl⟩⟩ theorem prod_le_iff {p₁ : Submodule R M} {p₂ : Submodule R M₂} {q : Submodule R (M × M₂)} : p₁.prod p₂ ≤ q ↔ map (LinearMap.inl R M M₂) p₁ ≤ q ∧ map (LinearMap.inr R M M₂) p₂ ≤ q := by constructor · intro h constructor · rintro _ ⟨x, hx, rfl⟩ apply h exact ⟨hx, zero_mem p₂⟩ · rintro _ ⟨x, hx, rfl⟩ apply h exact ⟨zero_mem p₁, hx⟩ · rintro ⟨hH, hK⟩ ⟨x1, x2⟩ ⟨h1, h2⟩ have h1' : (LinearMap.inl R _ _) x1 ∈ q := by apply hH simpa using h1 have h2' : (LinearMap.inr R _ _) x2 ∈ q := by apply hK simpa using h2 simpa using add_mem h1' h2' theorem prod_eq_bot_iff {p₁ : Submodule R M} {p₂ : Submodule R M₂} : p₁.prod p₂ = ⊥ ↔ p₁ = ⊥ ∧ p₂ = ⊥ := by simp only [eq_bot_iff, prod_le_iff, (gc_map_comap _).le_iff_le, comap_bot, ker_inl, ker_inr] theorem prod_eq_top_iff {p₁ : Submodule R M} {p₂ : Submodule R M₂} : p₁.prod p₂ = ⊤ ↔ p₁ = ⊤ ∧ p₂ = ⊤ := by simp only [eq_top_iff, le_prod_iff, map_top, range_fst, range_snd] end Submodule namespace LinearEquiv /-- Product of modules is commutative up to linear isomorphism. -/ @[simps apply] def prodComm (R M N : Type*) [Semiring R] [AddCommMonoid M] [AddCommMonoid N] [Module R M] [Module R N] : (M × N) ≃ₗ[R] N × M := { AddEquiv.prodComm with toFun := Prod.swap map_smul' := fun _r ⟨_m, _n⟩ => rfl } section prodComm variable [Semiring R] [AddCommMonoid M] [AddCommMonoid M₂] [Module R M] [Module R M₂] theorem fst_comp_prodComm : (LinearMap.fst R M₂ M).comp (prodComm R M M₂).toLinearMap = (LinearMap.snd R M M₂) := by ext <;> simp theorem snd_comp_prodComm : (LinearMap.snd R M₂ M).comp (prodComm R M M₂).toLinearMap = (LinearMap.fst R M M₂) := by ext <;> simp end prodComm /-- Product of modules is associative up to linear isomorphism. -/ @[simps apply] def prodAssoc (R M₁ M₂ M₃ : Type*) [Semiring R] [AddCommMonoid M₁] [AddCommMonoid M₂] [AddCommMonoid M₃] [Module R M₁] [Module R M₂] [Module R M₃] : ((M₁ × M₂) × M₃) ≃ₗ[R] (M₁ × (M₂ × M₃)) := { AddEquiv.prodAssoc with map_smul' := fun _r ⟨_m, _n⟩ => rfl } section prodAssoc variable {M₁ : Type*} variable [Semiring R] [AddCommMonoid M₁] [AddCommMonoid M₂] [AddCommMonoid M₃] variable [Module R M₁] [Module R M₂] [Module R M₃] theorem fst_comp_prodAssoc : (LinearMap.fst R M₁ (M₂ × M₃)).comp (prodAssoc R M₁ M₂ M₃).toLinearMap = (LinearMap.fst R M₁ M₂).comp (LinearMap.fst R (M₁ × M₂) M₃) := by ext <;> simp theorem snd_comp_prodAssoc : (LinearMap.snd R M₁ (M₂ × M₃)).comp (prodAssoc R M₁ M₂ M₃).toLinearMap = (LinearMap.snd R M₁ M₂).prodMap (LinearMap.id : M₃ →ₗ[R] M₃) := by ext <;> simp end prodAssoc section SkewSwap variable (R M N) variable [Semiring R] variable [AddCommGroup M] [AddCommGroup N] variable [Module R M] [Module R N] /-- The map `(x, y) ↦ (-y, x)` as a linear equivalence. -/ protected def skewSwap : (M × N) ≃ₗ[R] (N × M) where toFun x := (-x.2, x.1) invFun x := (x.2, -x.1) map_add' _ _ := by simp [add_comm] map_smul' _ _ := by simp left_inv _ := by simp right_inv _ := by simp variable {R M N} @[simp] theorem skewSwap_apply (x : M × N) : LinearEquiv.skewSwap R M N x = (-x.2, x.1) := rfl @[simp] theorem skewSwap_symm_apply (x : N × M) : (LinearEquiv.skewSwap R M N).symm x = (x.2, -x.1) := rfl end SkewSwap section variable (R M M₂ M₃ M₄) variable [Semiring R] variable [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] [AddCommMonoid M₄] variable [Module R M] [Module R M₂] [Module R M₃] [Module R M₄] /-- Four-way commutativity of `prod`. The name matches `mul_mul_mul_comm`. -/ @[simps apply] def prodProdProdComm : ((M × M₂) × M₃ × M₄) ≃ₗ[R] (M × M₃) × M₂ × M₄ := { AddEquiv.prodProdProdComm M M₂ M₃ M₄ with toFun := fun mnmn => ((mnmn.1.1, mnmn.2.1), (mnmn.1.2, mnmn.2.2)) invFun := fun mmnn => ((mmnn.1.1, mmnn.2.1), (mmnn.1.2, mmnn.2.2)) map_smul' := fun _c _mnmn => rfl } @[simp] theorem prodProdProdComm_symm : (prodProdProdComm R M M₂ M₃ M₄).symm = prodProdProdComm R M M₃ M₂ M₄ := rfl @[simp] theorem prodProdProdComm_toAddEquiv : (prodProdProdComm R M M₂ M₃ M₄ : _ ≃+ _) = AddEquiv.prodProdProdComm M M₂ M₃ M₄ := rfl end section variable [Semiring R] variable [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] [AddCommMonoid M₄] variable {module_M : Module R M} {module_M₂ : Module R M₂} variable {module_M₃ : Module R M₃} {module_M₄ : Module R M₄} variable (e₁ : M ≃ₗ[R] M₂) (e₂ : M₃ ≃ₗ[R] M₄) /-- Product of linear equivalences; the maps come from `Equiv.prodCongr`. -/ protected def prodCongr : (M × M₃) ≃ₗ[R] M₂ × M₄ := { e₁.toAddEquiv.prodCongr e₂.toAddEquiv with map_smul' := fun c _x => Prod.ext (e₁.map_smulₛₗ c _) (e₂.map_smulₛₗ c _) } theorem prodCongr_symm : (e₁.prodCongr e₂).symm = e₁.symm.prodCongr e₂.symm := rfl @[simp] theorem prodCongr_apply (p) : e₁.prodCongr e₂ p = (e₁ p.1, e₂ p.2) := rfl @[simp, norm_cast] theorem coe_prodCongr : (e₁.prodCongr e₂ : M × M₃ →ₗ[R] M₂ × M₄) = (e₁ : M →ₗ[R] M₂).prodMap (e₂ : M₃ →ₗ[R] M₄) := rfl end section variable [Semiring R] variable [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] [AddCommGroup M₄] variable {module_M : Module R M} {module_M₂ : Module R M₂} variable {module_M₃ : Module R M₃} {module_M₄ : Module R M₄} variable (e₁ : M ≃ₗ[R] M₂) (e₂ : M₃ ≃ₗ[R] M₄) /-- Equivalence given by a block lower diagonal matrix. `e₁` and `e₂` are diagonal square blocks, and `f` is a rectangular block below the diagonal. -/ protected def skewProd (f : M →ₗ[R] M₄) : (M × M₃) ≃ₗ[R] M₂ × M₄ := { ((e₁ : M →ₗ[R] M₂).comp (LinearMap.fst R M M₃)).prod ((e₂ : M₃ →ₗ[R] M₄).comp (LinearMap.snd R M M₃) + f.comp (LinearMap.fst R M M₃)) with invFun := fun p : M₂ × M₄ => (e₁.symm p.1, e₂.symm (p.2 - f (e₁.symm p.1))) left_inv := fun p => by simp right_inv := fun p => by simp } @[simp] theorem skewProd_apply (f : M →ₗ[R] M₄) (x) : e₁.skewProd e₂ f x = (e₁ x.1, e₂ x.2 + f x.1) := rfl @[simp] theorem skewProd_symm_apply (f : M →ₗ[R] M₄) (x) : (e₁.skewProd e₂ f).symm x = (e₁.symm x.1, e₂.symm (x.2 - f (e₁.symm x.1))) := rfl end section Unique variable [Semiring R] variable [AddCommMonoid M] [AddCommMonoid M₂] variable [Module R M] [Module R M₂] [Unique M₂] /-- Multiplying by the trivial module from the left does not change the structure. This is the `LinearEquiv` version of `AddEquiv.uniqueProd`. -/ @[simps!] def uniqueProd : (M₂ × M) ≃ₗ[R] M := AddEquiv.uniqueProd.toLinearEquiv (by simp [AddEquiv.uniqueProd]) lemma coe_uniqueProd : (uniqueProd (R := R) (M := M) (M₂ := M₂) : (M₂ × M) ≃ M) = Equiv.uniqueProd M M₂ := rfl /-- Multiplying by the trivial module from the right does not change the structure. This is the `LinearEquiv` version of `AddEquiv.prodUnique`. -/ @[simps!] def prodUnique : (M × M₂) ≃ₗ[R] M := AddEquiv.prodUnique.toLinearEquiv (by simp [AddEquiv.prodUnique]) lemma coe_prodUnique : (prodUnique (R := R) (M := M) (M₂ := M₂) : (M × M₂) ≃ M) = Equiv.prodUnique M M₂ := rfl end Unique end LinearEquiv namespace LinearMap open Submodule variable [Ring R] variable [AddCommGroup M] [AddCommGroup M₂] [AddCommGroup M₃] variable [Module R M] [Module R M₂] [Module R M₃] /-- If the union of the kernels `ker f` and `ker g` spans the domain, then the range of `Prod f g` is equal to the product of `range f` and `range g`. -/ theorem range_prod_eq {f : M →ₗ[R] M₂} {g : M →ₗ[R] M₃} (h : ker f ⊔ ker g = ⊤) : range (prod f g) = (range f).prod (range g) := by refine le_antisymm (f.range_prod_le g) ?_ simp only [SetLike.le_def, prod_apply, mem_range, mem_prod, exists_imp, and_imp, Prod.forall, Pi.prod] rintro _ _ x rfl y rfl -- Note: https://github.com/leanprover-community/mathlib4/pull/8386 had to specify `(f := f)` simp only [Prod.mk_inj, ← sub_mem_ker_iff (f := f)] have : y - x ∈ ker f ⊔ ker g := by simp only [h, mem_top] rcases mem_sup.1 this with ⟨x', hx', y', hy', H⟩ refine ⟨x' + x, ?_, ?_⟩ · rwa [add_sub_cancel_right] · simp [← eq_sub_iff_add_eq.1 H, map_add, mem_ker.mp hy'] end LinearMap namespace LinearMap /-! ## Tunnels and tailings NOTE: The proof of strong rank condition for Noetherian rings is changed. `LinearMap.tunnel` and `LinearMap.tailing` are not used in mathlib anymore. These are marked as deprecated with no replacements. If you use them in external projects, please consider using other arguments instead. Some preliminary work for establishing the strong rank condition for Noetherian rings. Given a morphism `f : M × N →ₗ[R] M` which is `i : Injective f`, we can find an infinite decreasing `tunnel f i n` of copies of `M` inside `M`, and sitting beside these, an infinite sequence of copies of `N`. We picturesquely name these as `tailing f i n` for each individual copy of `N`, and `tailings f i n` for the supremum of the first `n + 1` copies: they are the pieces left behind, sitting inside the tunnel. By construction, each `tailing f i (n + 1)` is disjoint from `tailings f i n`; later, when we assume `M` is Noetherian, this implies that `N` must be trivial, and establishes the strong rank condition for any left-Noetherian ring. -/ section Graph variable [Semiring R] [AddCommMonoid M] [AddCommMonoid M₂] [AddCommGroup M₃] [AddCommGroup M₄] [Module R M] [Module R M₂] [Module R M₃] [Module R M₄] (f : M →ₗ[R] M₂) (g : M₃ →ₗ[R] M₄) /-- Graph of a linear map. -/ def graph : Submodule R (M × M₂) where carrier := { p | p.2 = f p.1 } add_mem' (ha : _ = _) (hb : _ = _) := by change _ + _ = f (_ + _) rw [map_add, ha, hb] zero_mem' := Eq.symm (map_zero f) smul_mem' c x (hx : _ = _) := by change _ • _ = f (_ • _) rw [map_smul, hx] @[simp] theorem mem_graph_iff (x : M × M₂) : x ∈ f.graph ↔ x.2 = f x.1 := Iff.rfl theorem graph_eq_ker_coprod : g.graph = ker ((-g).coprod LinearMap.id) := by ext x change _ = _ ↔ -g x.1 + x.2 = _ rw [add_comm, add_neg_eq_zero] theorem graph_eq_range_prod : f.graph = range (LinearMap.id.prod f) := by ext x exact ⟨fun hx => ⟨x.1, Prod.ext rfl hx.symm⟩, fun ⟨u, hu⟩ => hu ▸ rfl⟩ end Graph end LinearMap section LineTest open Set Function variable {R S G H I : Type*} [Semiring R] [Semiring S] {σ : R →+* S} [RingHomSurjective σ] [AddCommMonoid G] [Module R G] [AddCommMonoid H] [Module S H] [AddCommMonoid I] [Module S I] /-- **Vertical line test** for linear maps. Let `f : G → H × I` be a linear (or semilinear) map to a product. Assume that `f` is surjective on the first factor and that the image of `f` intersects every "vertical line" `{(h, i) | i : I}` at most once. Then the image of `f` is the graph of some linear map `f' : H → I`. -/ lemma LinearMap.exists_range_eq_graph {f : G →ₛₗ[σ] H × I} (hf₁ : Surjective (Prod.fst ∘ f)) (hf : ∀ g₁ g₂, (f g₁).1 = (f g₂).1 → (f g₁).2 = (f g₂).2) : ∃ f' : H →ₗ[S] I, LinearMap.range f = LinearMap.graph f' := by obtain ⟨f', hf'⟩ := AddMonoidHom.exists_mrange_eq_mgraph (G := G) (H := H) (I := I) (f := f) hf₁ hf simp only [SetLike.ext_iff, AddMonoidHom.mem_mrange, AddMonoidHom.coe_coe, AddMonoidHom.mem_mgraph] at hf' use { toFun := f'.toFun map_add' := f'.map_add' map_smul' := by intro s h simp only [ZeroHom.toFun_eq_coe, AddMonoidHom.toZeroHom_coe, RingHom.id_apply] refine (hf' (s • h, _)).mp ?_ rw [← Prod.smul_mk, ← LinearMap.mem_range] apply Submodule.smul_mem rw [LinearMap.mem_range, hf'] } ext x simpa only [mem_range, Eq.comm, ZeroHom.toFun_eq_coe, AddMonoidHom.toZeroHom_coe, mem_graph_iff, coe_mk, AddHom.coe_mk, AddMonoidHom.coe_coe, Set.mem_range] using hf' x /-- **Vertical line test** for linear maps. Let `G ≤ H × I` be a submodule of a product of modules. Assume that `G` maps bijectively to the first factor. Then `G` is the graph of some linear map `f : H →ₗ[R] I`. -/ lemma Submodule.exists_eq_graph {G : Submodule S (H × I)} (hf₁ : Bijective (Prod.fst ∘ G.subtype)) : ∃ f : H →ₗ[S] I, G = LinearMap.graph f := by simpa only [range_subtype] using LinearMap.exists_range_eq_graph hf₁.surjective (fun a b h ↦ congr_arg (Prod.snd ∘ G.subtype) (hf₁.injective h)) /-- **Line test** for module isomorphisms. Let `f : G → H × I` be a linear (or semilinear) map to a product of modules. Assume that `f` is surjective onto both factors and that the image of `f` intersects every "vertical line" `{(h, i) | i : I}` and every "horizontal line" `{(h, i) | h : H}` at most once. Then the image of `f` is the graph of some module isomorphism `f' : H ≃ I`. -/ lemma LinearMap.exists_linearEquiv_eq_graph {f : G →ₛₗ[σ] H × I} (hf₁ : Surjective (Prod.fst ∘ f)) (hf₂ : Surjective (Prod.snd ∘ f)) (hf : ∀ g₁ g₂, (f g₁).1 = (f g₂).1 ↔ (f g₁).2 = (f g₂).2) : ∃ e : H ≃ₗ[S] I, range f = e.toLinearMap.graph := by obtain ⟨e₁, he₁⟩ := f.exists_range_eq_graph hf₁ fun _ _ ↦ (hf _ _).1 obtain ⟨e₂, he₂⟩ := ((LinearEquiv.prodComm _ _ _).toLinearMap.comp f).exists_range_eq_graph (by simpa) <| by simp [hf] have he₁₂ h i : e₁ h = i ↔ e₂ i = h := by simp only [SetLike.ext_iff, LinearMap.mem_graph_iff] at he₁ he₂ rw [Eq.comm, ← he₁ (h, i), Eq.comm, ← he₂ (i, h)] simp only [mem_range, coe_comp, LinearEquiv.coe_coe, Function.comp_apply, LinearEquiv.prodComm_apply, Prod.swap_eq_iff_eq_swap, Prod.swap_prod_mk] exact ⟨ { toFun := e₁ map_smul' := e₁.map_smul' map_add' := e₁.map_add' invFun := e₂ left_inv := fun h ↦ by rw [← he₁₂] right_inv := fun i ↦ by rw [he₁₂] }, he₁⟩ /-- **Goursat's lemma** for module isomorphisms. Let `G ≤ H × I` be a submodule of a product of modules. Assume that the natural maps from `G` to both factors are bijective. Then `G` is the graph of some module isomorphism `f : H ≃ I`. -/ lemma Submodule.exists_equiv_eq_graph {G : Submodule S (H × I)} (hG₁ : Bijective (Prod.fst ∘ G.subtype)) (hG₂ : Bijective (Prod.snd ∘ G.subtype)) : ∃ e : H ≃ₗ[S] I, G = e.toLinearMap.graph := by simpa only [range_subtype] using LinearMap.exists_linearEquiv_eq_graph hG₁.surjective hG₂.surjective fun _ _ ↦ hG₁.injective.eq_iff.trans hG₂.injective.eq_iff.symm end LineTest
.lake/packages/mathlib/Mathlib/LinearAlgebra/PID.lean
import Mathlib.LinearAlgebra.Trace import Mathlib.LinearAlgebra.FreeModule.PID import Mathlib.LinearAlgebra.FreeModule.Finite.Basic /-! # Linear maps of modules with coefficients in a principal ideal domain Since a submodule of a free module over a PID is free, certain constructions which are often developed only for vector spaces may be generalised to any module with coefficients in a PID. This file is a location for such results and exists to avoid making large parts of the linear algebra import hierarchy have to depend on the theory of PIDs. ## Main results: * `LinearMap.trace_restrict_eq_of_forall_mem` -/ namespace LinearMap variable {R M : Type*} [CommRing R] [AddCommGroup M] [Module R M] [Module.Finite R M] [Module.Free R M] /-- If a linear endomorphism of a (finite, free) module `M` takes values in a submodule `p ⊆ M`, then the trace of its restriction to `p` is equal to its trace on `M`. -/ lemma trace_restrict_eq_of_forall_mem [IsDomain R] [IsPrincipalIdealRing R] (p : Submodule R M) (f : M →ₗ[R] M) (hf : ∀ x, f x ∈ p) (hf' : ∀ x ∈ p, f x ∈ p := fun x _ ↦ hf x) : trace R p (f.restrict hf') = trace R M f := by let ι := Module.Free.ChooseBasisIndex R M obtain ⟨n, snf⟩ := p.smithNormalForm (Module.Free.chooseBasis R M) rw [trace_eq_matrix_trace R snf.bM, trace_eq_matrix_trace R snf.bN] set A : Matrix (Fin n) (Fin n) R := toMatrix snf.bN snf.bN (f.restrict hf') set B : Matrix ι ι R := toMatrix snf.bM snf.bM f have aux : ∀ i, B i i ≠ 0 → i ∈ Set.range snf.f := fun i hi ↦ by contrapose! hi; exact snf.repr_eq_zero_of_notMem_range ⟨_, (hf _)⟩ hi change ∑ i, A i i = ∑ i, B i i rw [← Finset.sum_filter_of_ne (p := fun j ↦ j ∈ Set.range snf.f) (by simpa using aux)] simp [A, B, hf, Finset.sum_image snf.f.injective.injOn] end LinearMap
.lake/packages/mathlib/Mathlib/LinearAlgebra/Pi.lean
import Mathlib.Algebra.Group.Fin.Tuple import Mathlib.Algebra.BigOperators.GroupWithZero.Action import Mathlib.Algebra.BigOperators.Pi import Mathlib.Algebra.Module.Prod import Mathlib.Algebra.Module.Submodule.Ker import Mathlib.Algebra.Module.Submodule.Range import Mathlib.Algebra.Module.Equiv.Basic import Mathlib.Logic.Equiv.Fin.Basic import Mathlib.LinearAlgebra.Prod import Mathlib.Data.Fintype.Option /-! # Pi types of modules This file defines constructors for linear maps whose domains or codomains are pi types. It contains theorems relating these to each other, as well as to `LinearMap.ker`. ## Main definitions - pi types in the codomain: - `LinearMap.pi` - `LinearMap.single` - pi types in the domain: - `LinearMap.proj` - `LinearMap.diag` -/ universe u v w x y z u' v' w' x' y' variable {R : Type u} {K : Type u'} {M : Type v} {V : Type v'} {M₂ : Type w} {V₂ : Type w'} variable {M₃ : Type y} {V₃ : Type y'} {M₄ : Type z} {ι : Type x} {ι' : Type x'} open Function Submodule namespace LinearMap universe i variable [Semiring R] [AddCommMonoid M₂] [Module R M₂] [AddCommMonoid M₃] [Module R M₃] {φ : ι → Type i} [(i : ι) → AddCommMonoid (φ i)] [(i : ι) → Module R (φ i)] /-- `pi` construction for linear functions. From a family of linear functions it produces a linear function into a family of modules. -/ def pi (f : (i : ι) → M₂ →ₗ[R] φ i) : M₂ →ₗ[R] (i : ι) → φ i := { Pi.addHom fun i => (f i).toAddHom with toFun := fun c i => f i c map_smul' := fun _ _ => funext fun i => (f i).map_smul _ _ } @[simp] theorem pi_apply (f : (i : ι) → M₂ →ₗ[R] φ i) (c : M₂) (i : ι) : pi f c i = f i c := rfl theorem ker_pi (f : (i : ι) → M₂ →ₗ[R] φ i) : ker (pi f) = ⨅ i : ι, ker (f i) := by ext c; simp [funext_iff] theorem pi_eq_zero (f : (i : ι) → M₂ →ₗ[R] φ i) : pi f = 0 ↔ ∀ i, f i = 0 := by simp only [LinearMap.ext_iff, pi_apply, funext_iff] exact ⟨fun h a b => h b a, fun h a b => h b a⟩ theorem pi_zero : pi (fun _ => 0 : (i : ι) → M₂ →ₗ[R] φ i) = 0 := by ext; rfl theorem pi_comp (f : (i : ι) → M₂ →ₗ[R] φ i) (g : M₃ →ₗ[R] M₂) : (pi f).comp g = pi fun i => (f i).comp g := rfl /-- The constant linear map, taking `x` to `Function.const ι x`. -/ def const : M₂ →ₗ[R] (ι → M₂) := pi fun _ ↦ .id @[simp] lemma const_apply (x : M₂) : LinearMap.const (R := R) x = Function.const ι x := rfl /-- The projections from a family of modules are linear maps. Note: this definition would be called `Pi.evalLinearMap` if we followed the pattern established by `Pi.evalAddHom`, `Pi.evalMonoidHom`, `Pi.evalRingHom`, ... -/ def proj (i : ι) : ((i : ι) → φ i) →ₗ[R] φ i where toFun := Function.eval i map_add' _ _ := rfl map_smul' _ _ := rfl @[simp] theorem coe_proj (i : ι) : ⇑(proj i : ((i : ι) → φ i) →ₗ[R] φ i) = Function.eval i := rfl @[simp] theorem toAddMonoidHom_proj (i : ι) : (proj i).toAddMonoidHom (R := R) = Pi.evalAddMonoidHom φ i := rfl theorem proj_apply (i : ι) (b : (i : ι) → φ i) : (proj i : ((i : ι) → φ i) →ₗ[R] φ i) b = b i := rfl @[simp] theorem proj_pi (f : (i : ι) → M₂ →ₗ[R] φ i) (i : ι) : (proj i).comp (pi f) = f i := rfl @[simp] theorem pi_proj : pi proj = LinearMap.id (R := R) (M := ∀ i, φ i) := rfl @[simp] theorem pi_proj_comp (f : M₂ →ₗ[R] ∀ i, φ i) : pi (proj · ∘ₗ f) = f := rfl theorem proj_surjective (i : ι) : Surjective (proj i : ((i : ι) → φ i) →ₗ[R] φ i) := surjective_eval i theorem iInf_ker_proj : (⨅ i, ker (proj i : ((i : ι) → φ i) →ₗ[R] φ i) : Submodule R ((i : ι) → φ i)) = ⊥ := bot_unique <| SetLike.le_def.2 fun a h => by simp only [mem_iInf, mem_ker, proj_apply] at h exact (mem_bot _).2 (funext fun i => h i) instance CompatibleSMul.pi (R S M N ι : Type*) [Semiring S] [AddCommMonoid M] [AddCommMonoid N] [SMul R M] [SMul R N] [Module S M] [Module S N] [LinearMap.CompatibleSMul M N R S] : LinearMap.CompatibleSMul M (ι → N) R S where map_smul f r m := by ext i; apply ((LinearMap.proj i).comp f).map_smul_of_tower /-- Linear map between the function spaces `I → M₂` and `I → M₃`, induced by a linear map `f` between `M₂` and `M₃`. -/ @[simps] protected def compLeft (f : M₂ →ₗ[R] M₃) (I : Type*) : (I → M₂) →ₗ[R] I → M₃ := { f.toAddMonoidHom.compLeft I with toFun := fun h => f ∘ h map_smul' := fun c h => by ext x exact f.map_smul' c (h x) } theorem apply_single [AddCommMonoid M] [Module R M] [DecidableEq ι] (f : (i : ι) → φ i →ₗ[R] M) (i j : ι) (x : φ i) : f j (Pi.single i x j) = (Pi.single i (f i x) : ι → M) j := Pi.apply_single (fun i => f i) (fun i => (f i).map_zero) _ _ _ variable (R φ) /-- The `LinearMap` version of `AddMonoidHom.single` and `Pi.single`. -/ def single [DecidableEq ι] (i : ι) : φ i →ₗ[R] (i : ι) → φ i := { AddMonoidHom.single φ i with toFun := Pi.single i map_smul' := Pi.single_smul i } lemma single_apply [DecidableEq ι] {i : ι} (v : φ i) : single R φ i v = Pi.single i v := rfl lemma sum_single_apply [Fintype ι] [DecidableEq ι] (v : Π i, φ i) : ∑ i, Pi.single i (v i) = v := by ext; simp @[simp] theorem coe_single [DecidableEq ι] (i : ι) : ⇑(single R φ i : φ i →ₗ[R] (i : ι) → φ i) = Pi.single i := rfl variable [DecidableEq ι] theorem proj_comp_single_same (i : ι) : (proj i).comp (single R φ i) = id := LinearMap.ext <| Pi.single_eq_same i theorem proj_comp_single_ne (i j : ι) (h : i ≠ j) : (proj i).comp (single R φ j) = 0 := LinearMap.ext <| Pi.single_eq_of_ne h theorem iSup_range_single_le_iInf_ker_proj (I J : Set ι) (h : Disjoint I J) : ⨆ i ∈ I, range (single R φ i) ≤ ⨅ i ∈ J, ker (proj i : (∀ i, φ i) →ₗ[R] φ i) := by refine iSup_le fun i => iSup_le fun hi => range_le_iff_comap.2 ?_ simp only [← ker_comp, eq_top_iff, SetLike.le_def, mem_ker, comap_iInf, mem_iInf] rintro b - j hj rw [proj_comp_single_ne R φ j i, zero_apply] rintro rfl exact h.le_bot ⟨hi, hj⟩ theorem iInf_ker_proj_le_iSup_range_single {I : Finset ι} {J : Set ι} (hu : Set.univ ⊆ ↑I ∪ J) : ⨅ i ∈ J, ker (proj i : (∀ i, φ i) →ₗ[R] φ i) ≤ ⨆ i ∈ I, range (single R φ i) := SetLike.le_def.2 (by intro b hb simp only [mem_iInf, mem_ker, proj_apply] at hb rw [← show (∑ i ∈ I, Pi.single i (b i)) = b by ext i rw [Finset.sum_apply, ← Pi.single_eq_same i (b i)] refine Finset.sum_eq_single i (fun j _ ne => Pi.single_eq_of_ne ne.symm _) ?_ intro hiI rw [Pi.single_eq_same] exact hb _ ((hu trivial).resolve_left hiI)] exact sum_mem_biSup fun i _ => mem_range_self (single R φ i) (b i)) theorem iSup_range_single_eq_iInf_ker_proj {I J : Set ι} (hd : Disjoint I J) (hu : Set.univ ⊆ I ∪ J) (hI : Set.Finite I) : ⨆ i ∈ I, range (single R φ i) = ⨅ i ∈ J, ker (proj i : (∀ i, φ i) →ₗ[R] φ i) := by refine le_antisymm (iSup_range_single_le_iInf_ker_proj _ _ _ _ hd) ?_ have : Set.univ ⊆ ↑hI.toFinset ∪ J := by rwa [hI.coe_toFinset] refine le_trans (iInf_ker_proj_le_iSup_range_single R φ this) (iSup_mono fun i => ?_) rw [Set.Finite.mem_toFinset] theorem iSup_range_single [Finite ι] : ⨆ i, range (single R φ i) = ⊤ := by cases nonempty_fintype ι convert top_unique (iInf_emptyset.ge.trans <| iInf_ker_proj_le_iSup_range_single R φ _) · rename_i i exact ((@iSup_pos _ _ _ fun _ => range <| single R φ i) <| Finset.mem_univ i).symm · rw [Finset.coe_univ, Set.union_empty] theorem disjoint_single_single (I J : Set ι) (h : Disjoint I J) : Disjoint (⨆ i ∈ I, range (single R φ i)) (⨆ i ∈ J, range (single R φ i)) := by refine Disjoint.mono (iSup_range_single_le_iInf_ker_proj _ _ _ _ <| disjoint_compl_right) (iSup_range_single_le_iInf_ker_proj _ _ _ _ <| disjoint_compl_right) ?_ simp only [disjoint_iff_inf_le, SetLike.le_def, mem_iInf, mem_inf, mem_ker, mem_bot, proj_apply, funext_iff] rintro b ⟨hI, hJ⟩ i classical by_cases hiI : i ∈ I · by_cases hiJ : i ∈ J · exact (h.le_bot ⟨hiI, hiJ⟩).elim · exact hJ i hiJ · exact hI i hiI /-- The linear equivalence between linear functions on a finite product of modules and families of functions on these modules. See note [bundled maps over different rings]. -/ @[simps symm_apply] def lsum (S) [AddCommMonoid M] [Module R M] [Fintype ι] [Semiring S] [Module S M] [SMulCommClass R S M] : ((i : ι) → φ i →ₗ[R] M) ≃ₗ[S] ((i : ι) → φ i) →ₗ[R] M where toFun f := ∑ i : ι, (f i).comp (proj i) invFun f i := f.comp (single R φ i) map_add' f g := by simp only [Pi.add_apply, add_comp, Finset.sum_add_distrib] map_smul' c f := by simp only [Pi.smul_apply, smul_comp, Finset.smul_sum, RingHom.id_apply] left_inv f := by ext i x simp [apply_single] right_inv f := by ext x suffices f (∑ j, Pi.single j (x j)) = f x by simpa [apply_single] rw [Finset.univ_sum_single] @[simp] theorem lsum_apply (S) [AddCommMonoid M] [Module R M] [Fintype ι] [Semiring S] [Module S M] [SMulCommClass R S M] (f : (i : ι) → φ i →ₗ[R] M) : lsum R φ S f = ∑ i : ι, (f i).comp (proj i) := rfl theorem lsum_piSingle (S) [AddCommMonoid M] [Module R M] [Fintype ι] [Semiring S] [Module S M] [SMulCommClass R S M] (f : (i : ι) → φ i →ₗ[R] M) (i : ι) (x : φ i) : lsum R φ S f (Pi.single i x) = f i x := by simp_rw [lsum_apply, sum_apply, comp_apply, proj_apply, apply_single, Fintype.sum_pi_single'] @[simp high] theorem lsum_single (S) [Fintype ι] [Semiring S] [∀ i, Module S (φ i)] [∀ i, SMulCommClass R S (φ i)] : LinearMap.lsum R φ S (LinearMap.single R φ) = LinearMap.id := LinearMap.ext fun x => by simp [Finset.univ_sum_single] variable {R φ} section Ext variable [Finite ι] [AddCommMonoid M] [Module R M] {f g : ((i : ι) → φ i) →ₗ[R] M} theorem pi_ext (h : ∀ i x, f (Pi.single i x) = g (Pi.single i x)) : f = g := toAddMonoidHom_injective <| AddMonoidHom.functions_ext _ _ _ h theorem pi_ext_iff : f = g ↔ ∀ i x, f (Pi.single i x) = g (Pi.single i x) := ⟨fun h _ _ => h ▸ rfl, pi_ext⟩ /-- This is used as the ext lemma instead of `LinearMap.pi_ext` for reasons explained in note [partially-applied ext lemmas]. -/ @[ext] theorem pi_ext' (h : ∀ i, f.comp (single R φ i) = g.comp (single R φ i)) : f = g := by refine pi_ext fun i x => ?_ convert LinearMap.congr_fun (h i) x end Ext section variable (R φ) /-- If `I` and `J` are disjoint index sets, the product of the kernels of the `J`th projections of `φ` is linearly equivalent to the product over `I`. -/ def iInfKerProjEquiv {I J : Set ι} [DecidablePred fun i => i ∈ I] (hd : Disjoint I J) (hu : Set.univ ⊆ I ∪ J) : (⨅ i ∈ J, ker (proj i : ((i : ι) → φ i) →ₗ[R] φ i) : Submodule R ((i : ι) → φ i)) ≃ₗ[R] (i : I) → φ i := by refine LinearEquiv.ofLinear (pi fun i => (proj (i : ι)).comp (Submodule.subtype _)) (codRestrict _ (pi fun i => if h : i ∈ I then proj (⟨i, h⟩ : I) else 0) ?_) ?_ ?_ · intro b simp only [mem_iInf, mem_ker, proj_apply, pi_apply] intro j hjJ have : j ∉ I := fun hjI => hd.le_bot ⟨hjI, hjJ⟩ rw [dif_neg this, zero_apply] · simp only [pi_comp, comp_assoc, subtype_comp_codRestrict, proj_pi, Subtype.coe_prop] ext b ⟨j, hj⟩ simp only [dif_pos, LinearMap.coe_proj, LinearMap.pi_apply] rfl · ext1 ⟨b, hb⟩ apply Subtype.ext ext j have hb : ∀ i ∈ J, b i = 0 := by simpa only [mem_iInf, mem_ker, proj_apply] using (mem_iInf _).1 hb simp only [comp_apply, pi_apply, id_apply, codRestrict_apply] split_ifs with h · rfl · exact (hb _ <| (hu trivial).resolve_left h).symm end section /-- `diag i j` is the identity map if `i = j`. Otherwise it is the constant 0 map. -/ def diag (i j : ι) : φ i →ₗ[R] φ j := @Function.update ι (fun j => φ i →ₗ[R] φ j) _ 0 i id j theorem update_apply (f : (i : ι) → M₂ →ₗ[R] φ i) (c : M₂) (i j : ι) (b : M₂ →ₗ[R] φ i) : (update f i b j) c = update (fun i => f i c) i (b c) j := by by_cases h : j = i · rw [h, update_self, update_self] · rw [update_of_ne h, update_of_ne h] variable (R φ) theorem single_eq_pi_diag (i : ι) : single R φ i = pi (diag i) := by ext x j convert (update_apply 0 x i j _).symm rfl theorem ker_single (i : ι) : ker (single R φ i) = ⊥ := ker_eq_bot_of_injective <| Pi.single_injective _ theorem proj_comp_single (i j : ι) : (proj i).comp (single R φ j) = diag j i := by rw [single_eq_pi_diag, proj_pi] end /-- A linear map `f` applied to `x : ι → R` can be computed using the image under `f` of elements of the canonical basis. -/ theorem pi_apply_eq_sum_univ [Fintype ι] (f : (ι → R) →ₗ[R] M₂) (x : ι → R) : f x = ∑ i, x i • f fun j => if i = j then 1 else 0 := by conv_lhs => rw [pi_eq_sum_univ x, map_sum] refine Finset.sum_congr rfl (fun _ _ => ?_) rw [map_smul] end LinearMap namespace Submodule variable [Semiring R] {φ : ι → Type*} [(i : ι) → AddCommMonoid (φ i)] [(i : ι) → Module R (φ i)] open LinearMap /-- A version of `Set.pi` for submodules. Given an index set `I` and a family of submodules `p : (i : ι) → Submodule R (φ i)`, `pi I s` is the submodule of dependent functions `f : (i : ι) → φ i` such that `f i` belongs to `p a` whenever `i ∈ I`. -/ @[simps] def pi (I : Set ι) (p : (i : ι) → Submodule R (φ i)) : Submodule R ((i : ι) → φ i) where carrier := Set.pi I fun i => p i zero_mem' i _ := (p i).zero_mem add_mem' {_ _} hx hy i hi := (p i).add_mem (hx i hi) (hy i hi) smul_mem' c _ hx i hi := (p i).smul_mem c (hx i hi) attribute [norm_cast] coe_pi variable {I : Set ι} {p q : (i : ι) → Submodule R (φ i)} {x : (i : ι) → φ i} @[simp] theorem mem_pi : x ∈ pi I p ↔ ∀ i ∈ I, x i ∈ p i := Iff.rfl @[simp] theorem pi_empty (p : (i : ι) → Submodule R (φ i)) : pi ∅ p = ⊤ := SetLike.coe_injective <| Set.empty_pi _ @[simp] theorem pi_top (s : Set ι) : (pi s fun i : ι ↦ (⊤ : Submodule R (φ i))) = ⊤ := SetLike.coe_injective <| Set.pi_univ _ @[simp] theorem pi_univ_bot : (pi Set.univ fun i : ι ↦ (⊥ : Submodule R (φ i))) = ⊥ := le_bot_iff.mp fun _ h ↦ funext fun i ↦ h i trivial @[gcongr] theorem pi_mono {s : Set ι} (h : ∀ i ∈ s, p i ≤ q i) : pi s p ≤ pi s q := Set.pi_mono h theorem biInf_comap_proj : ⨅ i ∈ I, comap (proj i : ((i : ι) → φ i) →ₗ[R] φ i) (p i) = pi I p := by ext x simp theorem iInf_comap_proj : ⨅ i, comap (proj i : ((i : ι) → φ i) →ₗ[R] φ i) (p i) = pi Set.univ p := by ext x simp theorem le_comap_single_pi [DecidableEq ι] (p : (i : ι) → Submodule R (φ i)) {I i} : p i ≤ Submodule.comap (LinearMap.single R φ i : φ i →ₗ[R] _) (Submodule.pi I p) := by intro x hx rw [Submodule.mem_comap, Submodule.mem_pi] rintro j - rcases eq_or_ne j i with rfl | hne <;> simp [*] theorem iSup_map_single_le [DecidableEq ι] : ⨆ i, map (LinearMap.single R φ i) (p i) ≤ pi I p := iSup_le fun _ => map_le_iff_le_comap.mpr <| le_comap_single_pi _ theorem iSup_map_single [DecidableEq ι] [Finite ι] : ⨆ i, map (LinearMap.single R φ i : φ i →ₗ[R] (i : ι) → φ i) (p i) = pi Set.univ p := by cases nonempty_fintype ι refine iSup_map_single_le.antisymm fun x hx => ?_ rw [← Finset.univ_sum_single x] exact sum_mem_iSup fun i => mem_map_of_mem (hx i trivial) end Submodule namespace LinearMap variable [Semiring R] lemma ker_compLeft [AddCommMonoid M] [AddCommMonoid M₂] [Module R M] [Module R M₂] (f : M →ₗ[R] M₂) (I : Type*) : LinearMap.ker (f.compLeft I) = Submodule.pi (Set.univ : Set I) (fun _ => LinearMap.ker f) := Submodule.ext fun _ => ⟨fun (hx : _ = _) i _ => congr_fun hx i, fun hx => funext fun i => hx i trivial⟩ lemma range_compLeft [AddCommMonoid M] [AddCommMonoid M₂] [Module R M] [Module R M₂] (f : M →ₗ[R] M₂) (I : Type*) : LinearMap.range (f.compLeft I) = Submodule.pi (Set.univ : Set I) (fun _ => LinearMap.range f) := Submodule.ext fun _ => ⟨fun ⟨y, hy⟩ i _ => ⟨y i, congr_fun hy i⟩, fun hx => by choose y hy using hx exact ⟨fun i => y i trivial, funext fun i => hy i trivial⟩⟩ end LinearMap namespace LinearEquiv variable [Semiring R] {φ ψ χ : ι → Type*} variable [(i : ι) → AddCommMonoid (φ i)] [(i : ι) → Module R (φ i)] variable [(i : ι) → AddCommMonoid (ψ i)] [(i : ι) → Module R (ψ i)] variable [(i : ι) → AddCommMonoid (χ i)] [(i : ι) → Module R (χ i)] /-- Combine a family of linear equivalences into a linear equivalence of `pi`-types. This is `Equiv.piCongrRight` as a `LinearEquiv` -/ def piCongrRight (e : (i : ι) → φ i ≃ₗ[R] ψ i) : ((i : ι) → φ i) ≃ₗ[R] (i : ι) → ψ i := { AddEquiv.piCongrRight fun j => (e j).toAddEquiv with toFun := fun f i => e i (f i) invFun := fun f i => (e i).symm (f i) map_smul' := fun c f => by ext; simp } @[simp] theorem piCongrRight_apply (e : (i : ι) → φ i ≃ₗ[R] ψ i) (f i) : piCongrRight e f i = e i (f i) := rfl @[simp] theorem piCongrRight_refl : (piCongrRight fun j => refl R (φ j)) = refl _ _ := rfl @[simp] theorem piCongrRight_symm (e : (i : ι) → φ i ≃ₗ[R] ψ i) : (piCongrRight e).symm = piCongrRight fun i => (e i).symm := rfl @[simp] theorem piCongrRight_trans (e : (i : ι) → φ i ≃ₗ[R] ψ i) (f : (i : ι) → ψ i ≃ₗ[R] χ i) : (piCongrRight e).trans (piCongrRight f) = piCongrRight fun i => (e i).trans (f i) := rfl variable (R φ) /-- Transport dependent functions through an equivalence of the base space. This is `Equiv.piCongrLeft'` as a `LinearEquiv`. -/ @[simps +simpRhs] def piCongrLeft' (e : ι ≃ ι') : ((i' : ι) → φ i') ≃ₗ[R] (i : ι') → φ <| e.symm i := { Equiv.piCongrLeft' φ e with map_add' := fun _ _ => rfl map_smul' := fun _ _ => rfl } /-- Transporting dependent functions through an equivalence of the base, expressed as a "simplification". This is `Equiv.piCongrLeft` as a `LinearEquiv` -/ def piCongrLeft (e : ι' ≃ ι) : ((i' : ι') → φ (e i')) ≃ₗ[R] (i : ι) → φ i := (piCongrLeft' R φ e.symm).symm /-- `Equiv.piCurry` as a `LinearEquiv`. -/ def piCurry {ι : Type*} {κ : ι → Type*} (α : ∀ i, κ i → Type*) [∀ i k, AddCommMonoid (α i k)] [∀ i k, Module R (α i k)] : (Π i : Sigma κ, α i.1 i.2) ≃ₗ[R] Π i j, α i j where __ := Equiv.piCurry α map_add' _ _ := rfl map_smul' _ _ := rfl @[simp] theorem piCurry_apply {ι : Type*} {κ : ι → Type*} (α : ∀ i, κ i → Type*) [∀ i k, AddCommMonoid (α i k)] [∀ i k, Module R (α i k)] (f : ∀ x : Σ i, κ i, α x.1 x.2) : piCurry R α f = Sigma.curry f := rfl @[simp] theorem piCurry_symm_apply {ι : Type*} {κ : ι → Type*} (α : ∀ i, κ i → Type*) [∀ i k, AddCommMonoid (α i k)] [∀ i k, Module R (α i k)] (f : ∀ a b, α a b) : (piCurry R α).symm f = Sigma.uncurry f := rfl /-- This is `Equiv.piOptionEquivProd` as a `LinearEquiv` -/ def piOptionEquivProd {ι : Type*} {M : Option ι → Type*} [(i : Option ι) → AddCommMonoid (M i)] [(i : Option ι) → Module R (M i)] : ((i : Option ι) → M i) ≃ₗ[R] M none × ((i : ι) → M (some i)) := { Equiv.piOptionEquivProd with map_add' := by simp [funext_iff] map_smul' := by simp [funext_iff] } variable (ι M) (S : Type*) [Fintype ι] [DecidableEq ι] [Semiring S] [AddCommMonoid M] [Module R M] [Module S M] [SMulCommClass R S M] /-- Linear equivalence between linear functions `Rⁿ → M` and `Mⁿ`. The spaces `Rⁿ` and `Mⁿ` are represented as `ι → R` and `ι → M`, respectively, where `ι` is a finite type. This as an `S`-linear equivalence, under the assumption that `S` acts on `M` commuting with `R`. When `R` is commutative, we can take this to be the usual action with `S = R`. Otherwise, `S = ℕ` shows that the equivalence is additive. See note [bundled maps over different rings]. -/ def piRing : ((ι → R) →ₗ[R] M) ≃ₗ[S] ι → M := (LinearMap.lsum R (fun _ : ι => R) S).symm.trans (piCongrRight fun _ => LinearMap.ringLmapEquivSelf R S M) variable {ι R M} @[simp] theorem piRing_apply (f : (ι → R) →ₗ[R] M) (i : ι) : piRing R M ι S f i = f (Pi.single i 1) := rfl @[simp] theorem piRing_symm_apply (f : ι → M) (g : ι → R) : (piRing R M ι S).symm f g = ∑ i, g i • f i := by simp [piRing, LinearMap.lsum_apply] -- TODO additive version? /-- `Equiv.sumArrowEquivProdArrow` as a linear equivalence. -/ def sumArrowLequivProdArrow (α β R M : Type*) [Semiring R] [AddCommMonoid M] [Module R M] : (α ⊕ β → M) ≃ₗ[R] (α → M) × (β → M) := { Equiv.sumArrowEquivProdArrow α β M with map_add' := by intro f g ext <;> rfl map_smul' := by intro r f ext <;> rfl } @[simp] theorem sumArrowLequivProdArrow_apply_fst {α β} (f : α ⊕ β → M) (a : α) : (sumArrowLequivProdArrow α β R M f).1 a = f (Sum.inl a) := rfl @[simp] theorem sumArrowLequivProdArrow_apply_snd {α β} (f : α ⊕ β → M) (b : β) : (sumArrowLequivProdArrow α β R M f).2 b = f (Sum.inr b) := rfl @[simp] theorem sumArrowLequivProdArrow_symm_apply_inl {α β} (f : α → M) (g : β → M) (a : α) : ((sumArrowLequivProdArrow α β R M).symm (f, g)) (Sum.inl a) = f a := rfl @[simp] theorem sumArrowLequivProdArrow_symm_apply_inr {α β} (f : α → M) (g : β → M) (b : β) : ((sumArrowLequivProdArrow α β R M).symm (f, g)) (Sum.inr b) = g b := rfl /-- If `ι` has a unique element, then `ι → M` is linearly equivalent to `M`. -/ @[simps +simpRhs -fullyApplied symm_apply] def funUnique (ι R M : Type*) [Unique ι] [Semiring R] [AddCommMonoid M] [Module R M] : (ι → M) ≃ₗ[R] M := { Equiv.funUnique ι M with map_add' := fun _ _ => rfl map_smul' := fun _ _ => rfl } @[simp] theorem funUnique_apply (ι R M : Type*) [Unique ι] [Semiring R] [AddCommMonoid M] [Module R M] : (funUnique ι R M : (ι → M) → M) = eval default := rfl variable (R M) /-- Linear equivalence between dependent functions `(i : Fin 2) → M i` and `M 0 × M 1`. -/ @[simps +simpRhs -fullyApplied symm_apply] def piFinTwo (M : Fin 2 → Type v) [(i : Fin 2) → AddCommMonoid (M i)] [(i : Fin 2) → Module R (M i)] : ((i : Fin 2) → M i) ≃ₗ[R] M 0 × M 1 := { piFinTwoEquiv M with map_add' := fun _ _ => rfl map_smul' := fun _ _ => rfl } @[simp] theorem piFinTwo_apply (M : Fin 2 → Type v) [(i : Fin 2) → AddCommMonoid (M i)] [(i : Fin 2) → Module R (M i)] : (piFinTwo R M : ((i : Fin 2) → M i) → M 0 × M 1) = fun f => (f 0, f 1) := rfl /-- Linear equivalence between vectors in `M² = Fin 2 → M` and `M × M`. -/ @[simps! -fullyApplied] def finTwoArrow : (Fin 2 → M) ≃ₗ[R] M × M := { finTwoArrowEquiv M, piFinTwo R fun _ => M with } end LinearEquiv lemma Pi.mem_span_range_single_inl_iff [DecidableEq ι] [DecidableEq ι'] [Fintype ι] [Semiring R] {x : ι ⊕ ι' → R} : x ∈ span R (Set.range fun i ↦ single (Sum.inl i) 1) ↔ ∀ k, x (Sum.inr k) = 0 := by refine ⟨fun hx k ↦ ?_, fun hx ↦ ?_⟩ · induction hx using span_induction with | mem x h => obtain ⟨i, rfl⟩ := h; simp | zero => simp | add u v _ _ hu hv => simp [hu, hv] | smul t u _ hu => simp [hu] · suffices x = ∑ i : ι, x (Sum.inl i) • Pi.single (M := fun _ ↦ R) (Sum.inl i) (1 : R) by rw [this] exact sum_mem <| fun i _ ↦ SMulMemClass.smul_mem _ <| subset_span <| Set.mem_range_self i ext (i | i) · simp [single_apply] · simp [hx i] section Extend variable (R) {η : Type x} [Semiring R] (s : ι → η) /-- `Function.extend s f 0` as a bundled linear map. -/ @[simps] noncomputable def Function.ExtendByZero.linearMap : (ι → R) →ₗ[R] η → R := { Function.ExtendByZero.hom R s with toFun := fun f => Function.extend s f 0 map_smul' := fun r f => by simpa using Function.extend_smul r s f 0 } end Extend variable (R) in /-- `Fin.consEquiv` as a continuous linear equivalence. -/ @[simps] def Fin.consLinearEquiv {n : ℕ} (M : Fin n.succ → Type*) [Semiring R] [∀ i, AddCommMonoid (M i)] [∀ i, Module R (M i)] : (M 0 × Π i, M (Fin.succ i)) ≃ₗ[R] (Π i, M i) where __ := Fin.consEquiv M map_add' x y := funext <| Fin.cases rfl (by simp) map_smul' c x := funext <| Fin.cases rfl (by simp) /-! ### Bundled versions of `Matrix.vecCons` and `Matrix.vecEmpty` The idea of these definitions is to be able to define a map as `x ↦ ![f₁ x, f₂ x, f₃ x]`, where `f₁ f₂ f₃` are already linear maps, as `f₁.vecCons <| f₂.vecCons <| f₃.vecCons <| vecEmpty`. While the same thing could be achieved using `LinearMap.pi ![f₁, f₂, f₃]`, this is not definitionally equal to the result using `LinearMap.vecCons`, as `Fin.cases` and function application do not commute definitionally. Versions for when `f₁ f₂ f₃` are bilinear maps are also provided. -/ section Fin section Semiring variable [Semiring R] [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] variable [Module R M] [Module R M₂] [Module R M₃] /-- The linear map defeq to `Matrix.vecEmpty` -/ def LinearMap.vecEmpty : M →ₗ[R] Fin 0 → M₃ where toFun _ := Matrix.vecEmpty map_add' _ _ := Subsingleton.elim _ _ map_smul' _ _ := Subsingleton.elim _ _ @[simp] theorem LinearMap.vecEmpty_apply (m : M) : (LinearMap.vecEmpty : M →ₗ[R] Fin 0 → M₃) m = ![] := rfl /-- A linear map into `Fin n.succ → M₃` can be built out of a map into `M₃` and a map into `Fin n → M₃`. -/ def LinearMap.vecCons {n} (f : M →ₗ[R] M₂) (g : M →ₗ[R] Fin n → M₂) : M →ₗ[R] Fin n.succ → M₂ := Fin.consLinearEquiv R (fun _ : Fin n.succ => M₂) ∘ₗ f.prod g @[simp] theorem LinearMap.vecCons_apply {n} (f : M →ₗ[R] M₂) (g : M →ₗ[R] Fin n → M₂) (m : M) : f.vecCons g m = Matrix.vecCons (f m) (g m) := rfl variable (R) in /-- To show a property `motive` of modules holds for arbitrary finite products of modules, it suffices to show 1. `motive` is stable under isomorphism. 2. `motive` holds for the zero module. 3. `motive` holds for `M × N` if it holds for both `M` and `N`. Since we need to apply `motive` to modules in `Type u` and in `Type (max u v)`, there is a second `motive'` argument which is required to be equivalent to `motive` up to universe lifting by `equiv`. See `Module.pi_induction'` for a version where `motive` assumes `AddCommGroup` instead. -/ @[elab_as_elim] lemma Module.pi_induction {ι : Type v} [Finite ι] (motive : ∀ (N : Type u) [AddCommMonoid N] [Module R N], Prop) (motive' : ∀ (N : Type (max u v)) [AddCommMonoid N] [Module R N], Prop) (equiv : ∀ {N : Type u} {N' : Type (max u v)} [AddCommMonoid N] [AddCommMonoid N'] [Module R N] [Module R N'], (N ≃ₗ[R] N') → motive N → motive' N') (equiv' : ∀ {N N' : Type (max u v)} [AddCommMonoid N] [AddCommMonoid N'] [Module R N] [Module R N'], (N ≃ₗ[R] N') → motive' N → motive' N') (unit : motive PUnit) (prod : ∀ {N : Type u} {N' : Type (max u v)} [AddCommMonoid N] [AddCommMonoid N'] [Module R N] [Module R N'], motive N → motive' N' → motive' (N × N')) (M : ι → Type u) [∀ i, AddCommMonoid (M i)] [∀ i, Module R (M i)] (h : ∀ i, motive (M i)) : motive' (∀ i, M i) := by classical cases nonempty_fintype ι revert M refine Fintype.induction_empty_option (fun α β _ e h M _ _ hM ↦ equiv' (LinearEquiv.piCongrLeft R M e) <| h _ fun i ↦ hM _) (fun M _ _ _ ↦ equiv default unit) (fun α _ h M _ _ hn ↦ ?_) ι exact equiv' (LinearEquiv.piOptionEquivProd R).symm <| prod (hn _) (h _ fun i ↦ hn i) end Semiring section CommSemiring variable [CommSemiring R] [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] variable [Module R M] [Module R M₂] [Module R M₃] /-- The empty bilinear map defeq to `Matrix.vecEmpty` -/ @[simps] def LinearMap.vecEmpty₂ : M →ₗ[R] M₂ →ₗ[R] Fin 0 → M₃ where toFun _ := LinearMap.vecEmpty map_add' _ _ := LinearMap.ext fun _ => Subsingleton.elim _ _ map_smul' _ _ := LinearMap.ext fun _ => Subsingleton.elim _ _ /-- A bilinear map into `Fin n.succ → M₃` can be built out of a map into `M₃` and a map into `Fin n → M₃` -/ @[simps] def LinearMap.vecCons₂ {n} (f : M →ₗ[R] M₂ →ₗ[R] M₃) (g : M →ₗ[R] M₂ →ₗ[R] Fin n → M₃) : M →ₗ[R] M₂ →ₗ[R] Fin n.succ → M₃ where toFun m := LinearMap.vecCons (f m) (g m) map_add' x y := LinearMap.ext fun z => by simp only [f.map_add, g.map_add, LinearMap.add_apply, LinearMap.vecCons_apply, Matrix.cons_add_cons (f x z)] map_smul' r x := LinearMap.ext fun z => by simp [Matrix.smul_cons r (f x z)] end CommSemiring /-- A variant of `Module.pi_induction` that assumes `AddCommGroup` instead of `AddCommMonoid`. -/ @[elab_as_elim] lemma Module.pi_induction' {ι : Type v} [Finite ι] (R : Type*) [Ring R] (motive : ∀ (N : Type u) [AddCommGroup N] [Module R N], Prop) (motive' : ∀ (N : Type (max u v)) [AddCommGroup N] [Module R N], Prop) (equiv : ∀ {N : Type u} {N' : Type (max u v)} [AddCommGroup N] [AddCommGroup N'] [Module R N] [Module R N'], (N ≃ₗ[R] N') → motive N → motive' N') (equiv' : ∀ {N N' : Type (max u v)} [AddCommGroup N] [AddCommGroup N'] [Module R N] [Module R N'], (N ≃ₗ[R] N') → motive' N → motive' N') (unit : motive PUnit) (prod : ∀ {N : Type u} {N' : Type (max u v)} [AddCommGroup N] [AddCommGroup N'] [Module R N] [Module R N'], motive N → motive' N' → motive' (N × N')) (M : ι → Type u) [∀ i, AddCommGroup (M i)] [∀ i, Module R (M i)] (h : ∀ i, motive (M i)) : motive' (∀ i, M i) := by classical cases nonempty_fintype ι revert M refine Fintype.induction_empty_option (fun α β _ e h M _ _ hM ↦ equiv' (LinearEquiv.piCongrLeft R M e) <| h _ fun i ↦ hM _) (fun M _ _ _ ↦ equiv default unit) (fun α _ h M _ _ hn ↦ ?_) ι exact equiv' (LinearEquiv.piOptionEquivProd R).symm <| prod (hn _) (h _ fun i ↦ hn i) end Fin
.lake/packages/mathlib/Mathlib/LinearAlgebra/Orientation.lean
import Mathlib.LinearAlgebra.Ray import Mathlib.LinearAlgebra.Determinant /-! # Orientations of modules This file defines orientations of modules. ## Main definitions * `Orientation` is a type synonym for `Module.Ray` for the case where the module is that of alternating maps from a module to its underlying ring. An orientation may be associated with an alternating map or with a basis. * `Module.Oriented` is a type class for a choice of orientation of a module that is considered the positive orientation. ## Implementation notes `Orientation` is defined for an arbitrary index type, but the main intended use case is when that index type is a `Fintype` and there exists a basis of the same cardinality. ## References * https://en.wikipedia.org/wiki/Orientation_(vector_space) -/ noncomputable section open Module section OrderedCommSemiring variable (R : Type*) [CommSemiring R] [PartialOrder R] [IsStrictOrderedRing R] variable (M : Type*) [AddCommMonoid M] [Module R M] variable {N : Type*} [AddCommMonoid N] [Module R N] variable (ι ι' : Type*) /-- An orientation of a module, intended to be used when `ι` is a `Fintype` with the same cardinality as a basis. -/ abbrev Orientation := Module.Ray R (M [⋀^ι]→ₗ[R] R) /-- A type class fixing an orientation of a module. -/ class Module.Oriented where /-- Fix a positive orientation. -/ positiveOrientation : Orientation R M ι export Module.Oriented (positiveOrientation) variable {R M} /-- An equivalence between modules implies an equivalence between orientations. -/ def Orientation.map (e : M ≃ₗ[R] N) : Orientation R M ι ≃ Orientation R N ι := Module.Ray.map <| AlternatingMap.domLCongr R R ι R e @[simp] theorem Orientation.map_apply (e : M ≃ₗ[R] N) (v : M [⋀^ι]→ₗ[R] R) (hv : v ≠ 0) : Orientation.map ι e (rayOfNeZero _ v hv) = rayOfNeZero _ (v.compLinearMap e.symm) (mt (v.compLinearEquiv_eq_zero_iff e.symm).mp hv) := rfl @[simp] theorem Orientation.map_refl : (Orientation.map ι <| LinearEquiv.refl R M) = Equiv.refl _ := by rw [Orientation.map, AlternatingMap.domLCongr_refl, Module.Ray.map_refl] @[simp] theorem Orientation.map_symm (e : M ≃ₗ[R] N) : (Orientation.map ι e).symm = Orientation.map ι e.symm := rfl section Reindex variable (R M) {ι ι'} /-- An equivalence between indices implies an equivalence between orientations. -/ def Orientation.reindex (e : ι ≃ ι') : Orientation R M ι ≃ Orientation R M ι' := Module.Ray.map <| AlternatingMap.domDomCongrₗ R e @[simp] theorem Orientation.reindex_apply (e : ι ≃ ι') (v : M [⋀^ι]→ₗ[R] R) (hv : v ≠ 0) : Orientation.reindex R M e (rayOfNeZero _ v hv) = rayOfNeZero _ (v.domDomCongr e) (mt (v.domDomCongr_eq_zero_iff e).mp hv) := rfl @[simp] theorem Orientation.reindex_refl : (Orientation.reindex R M <| Equiv.refl ι) = Equiv.refl _ := by rw [Orientation.reindex, AlternatingMap.domDomCongrₗ_refl, Module.Ray.map_refl] @[simp] theorem Orientation.reindex_symm (e : ι ≃ ι') : (Orientation.reindex R M e).symm = Orientation.reindex R M e.symm := rfl end Reindex /-- A module is canonically oriented with respect to an empty index type. -/ instance (priority := 100) IsEmpty.oriented [IsEmpty ι] : Module.Oriented R M ι where positiveOrientation := rayOfNeZero R (AlternatingMap.constLinearEquivOfIsEmpty 1) <| AlternatingMap.constLinearEquivOfIsEmpty.injective.ne (by exact one_ne_zero) @[simp] theorem Orientation.map_positiveOrientation_of_isEmpty [IsEmpty ι] (f : M ≃ₗ[R] N) : Orientation.map ι f positiveOrientation = positiveOrientation := rfl @[simp] theorem Orientation.map_of_isEmpty [IsEmpty ι] (x : Orientation R M ι) (f : M ≃ₗ[R] M) : Orientation.map ι f x = x := by induction x using Module.Ray.ind with | h g hg => rw [Orientation.map_apply] congr ext i rw [AlternatingMap.compLinearMap_apply] congr simp only [LinearEquiv.coe_coe, eq_iff_true_of_subsingleton] end OrderedCommSemiring section OrderedCommRing variable {R : Type*} [CommRing R] [PartialOrder R] [IsStrictOrderedRing R] variable {M N : Type*} [AddCommGroup M] [AddCommGroup N] [Module R M] [Module R N] @[simp] protected theorem Orientation.map_neg {ι : Type*} (f : M ≃ₗ[R] N) (x : Orientation R M ι) : Orientation.map ι f (-x) = -Orientation.map ι f x := Module.Ray.map_neg _ x @[simp] protected theorem Orientation.reindex_neg {ι ι' : Type*} (e : ι ≃ ι') (x : Orientation R M ι) : Orientation.reindex R M e (-x) = -Orientation.reindex R M e x := Module.Ray.map_neg _ x namespace Module.Basis variable {ι ι' : Type*} /-- The value of `Orientation.map` when the index type has the cardinality of a basis, in terms of `f.det`. -/ theorem map_orientation_eq_det_inv_smul [Finite ι] (e : Basis ι R M) (x : Orientation R M ι) (f : M ≃ₗ[R] M) : Orientation.map ι f x = (LinearEquiv.det f)⁻¹ • x := by cases nonempty_fintype ι letI := Classical.decEq ι induction x using Module.Ray.ind with | h g hg => rw [Orientation.map_apply, smul_rayOfNeZero, ray_eq_iff, Units.smul_def, (g.compLinearMap f.symm).eq_smul_basis_det e, g.eq_smul_basis_det e, AlternatingMap.compLinearMap_apply, AlternatingMap.smul_apply, show (fun i ↦ (LinearEquiv.symm f).toLinearMap (e i)) = (LinearEquiv.symm f).toLinearMap ∘ e by rfl, Basis.det_comp, Basis.det_self, mul_one, smul_eq_mul, mul_comm, mul_smul, LinearEquiv.coe_inv_det] variable [Fintype ι] [DecidableEq ι] [Fintype ι'] [DecidableEq ι'] /-- The orientation given by a basis. -/ protected def orientation (e : Basis ι R M) : Orientation R M ι := rayOfNeZero R _ e.det_ne_zero theorem orientation_map (e : Basis ι R M) (f : M ≃ₗ[R] N) : (e.map f).orientation = Orientation.map ι f e.orientation := by simp_rw [Basis.orientation, Orientation.map_apply, Basis.det_map'] theorem orientation_reindex (e : Basis ι R M) (eι : ι ≃ ι') : (e.reindex eι).orientation = Orientation.reindex R M eι e.orientation := by simp_rw [Basis.orientation, Orientation.reindex_apply, Basis.det_reindex'] /-- The orientation given by a basis derived using `units_smul`, in terms of the product of those units. -/ theorem orientation_unitsSMul (e : Basis ι R M) (w : ι → Units R) : (e.unitsSMul w).orientation = (∏ i, w i)⁻¹ • e.orientation := by rw [Basis.orientation, Basis.orientation, smul_rayOfNeZero, ray_eq_iff, e.det.eq_smul_basis_det (e.unitsSMul w), det_unitsSMul_self, Units.smul_def, smul_smul] norm_cast simp only [inv_mul_cancel, Units.val_one, one_smul] exact SameRay.rfl @[simp] theorem orientation_isEmpty [IsEmpty ι] (b : Basis ι R M) : b.orientation = positiveOrientation := by rw [Basis.orientation] congr exact b.det_isEmpty end Module.Basis end OrderedCommRing section LinearOrderedCommRing variable {R : Type*} [CommRing R] [LinearOrder R] [IsStrictOrderedRing R] variable {M : Type*} [AddCommGroup M] [Module R M] variable {ι : Type*} namespace Orientation /-- A module `M` over a linearly ordered commutative ring has precisely two "orientations" with respect to an empty index type. (Note that these are only orientations of `M` of in the conventional mathematical sense if `M` is zero-dimensional.) -/ theorem eq_or_eq_neg_of_isEmpty [IsEmpty ι] (o : Orientation R M ι) : o = positiveOrientation ∨ o = -positiveOrientation := by induction o using Module.Ray.ind with | h x hx => dsimp [positiveOrientation] simp only [ray_eq_iff] rw [sameRay_or_sameRay_neg_iff_not_linearIndependent] intro h set f : (M [⋀^ι]→ₗ[R] R) ≃ₗ[R] R := AlternatingMap.constLinearEquivOfIsEmpty.symm have H : LinearIndependent R ![f x, 1] := by convert h.map' f.toLinearMap f.ker ext i fin_cases i <;> simp [f] rw [linearIndependent_iff'] at H simpa using H Finset.univ ![1, -f x] (by simp [Fin.sum_univ_succ]) 0 (by simp) end Orientation namespace Module.Basis variable [Fintype ι] [DecidableEq ι] /-- The orientations given by two bases are equal if and only if the determinant of one basis with respect to the other is positive. -/ theorem orientation_eq_iff_det_pos (e₁ e₂ : Basis ι R M) : e₁.orientation = e₂.orientation ↔ 0 < e₁.det e₂ := calc e₁.orientation = e₂.orientation ↔ SameRay R e₁.det e₂.det := ray_eq_iff _ _ _ ↔ SameRay R (e₁.det e₂ • e₂.det) e₂.det := by rw [← e₁.det.eq_smul_basis_det e₂] _ ↔ 0 < e₁.det e₂ := sameRay_smul_left_iff_of_ne e₂.det_ne_zero (e₁.isUnit_det e₂).ne_zero /-- Given a basis, any orientation equals the orientation given by that basis or its negation. -/ theorem orientation_eq_or_eq_neg (e : Basis ι R M) (x : Orientation R M ι) : x = e.orientation ∨ x = -e.orientation := by induction x using Module.Ray.ind with | h x hx => rw [← x.map_basis_ne_zero_iff e] at hx rwa [Basis.orientation, ray_eq_iff, neg_rayOfNeZero, ray_eq_iff, x.eq_smul_basis_det e, sameRay_neg_smul_left_iff_of_ne e.det_ne_zero hx, sameRay_smul_left_iff_of_ne e.det_ne_zero hx, lt_or_lt_iff_ne, ne_comm] /-- Given a basis, an orientation equals the negation of that given by that basis if and only if it does not equal that given by that basis. -/ theorem orientation_ne_iff_eq_neg (e : Basis ι R M) (x : Orientation R M ι) : x ≠ e.orientation ↔ x = -e.orientation := ⟨fun h => (e.orientation_eq_or_eq_neg x).resolve_left h, fun h => h.symm ▸ (Module.Ray.ne_neg_self e.orientation).symm⟩ /-- Composing a basis with a linear equiv gives the same orientation if and only if the determinant is positive. -/ theorem orientation_comp_linearEquiv_eq_iff_det_pos (e : Basis ι R M) (f : M ≃ₗ[R] M) : (e.map f).orientation = e.orientation ↔ 0 < LinearMap.det (f : M →ₗ[R] M) := by rw [orientation_map, e.map_orientation_eq_det_inv_smul, units_inv_smul, units_smul_eq_self_iff, LinearEquiv.coe_det] /-- Composing a basis with a linear equiv gives the negation of that orientation if and only if the determinant is negative. -/ theorem orientation_comp_linearEquiv_eq_neg_iff_det_neg (e : Basis ι R M) (f : M ≃ₗ[R] M) : (e.map f).orientation = -e.orientation ↔ LinearMap.det (f : M →ₗ[R] M) < 0 := by rw [orientation_map, e.map_orientation_eq_det_inv_smul, units_inv_smul, units_smul_eq_neg_iff, LinearEquiv.coe_det] /-- Negating a single basis vector (represented using `units_smul`) negates the corresponding orientation. -/ @[simp] theorem orientation_neg_single (e : Basis ι R M) (i : ι) : (e.unitsSMul (Function.update 1 i (-1))).orientation = -e.orientation := by rw [orientation_unitsSMul, Finset.prod_update_of_mem (Finset.mem_univ _)] simp /-- Given a basis and an orientation, return a basis giving that orientation: either the original basis, or one constructed by negating a single (arbitrary) basis vector. -/ def adjustToOrientation [Nonempty ι] (e : Basis ι R M) (x : Orientation R M ι) : Basis ι R M := haveI := Classical.decEq (Orientation R M ι) if e.orientation = x then e else e.unitsSMul (Function.update 1 (Classical.arbitrary ι) (-1)) /-- `adjust_to_orientation` gives a basis with the required orientation. -/ @[simp] theorem orientation_adjustToOrientation [Nonempty ι] (e : Basis ι R M) (x : Orientation R M ι) : (e.adjustToOrientation x).orientation = x := by rw [adjustToOrientation] split_ifs with h · exact h · rw [orientation_neg_single, eq_comm, ← orientation_ne_iff_eq_neg, ne_comm] exact h /-- Every basis vector from `adjust_to_orientation` is either that from the original basis or its negation. -/ theorem adjustToOrientation_apply_eq_or_eq_neg [Nonempty ι] (e : Basis ι R M) (x : Orientation R M ι) (i : ι) : e.adjustToOrientation x i = e i ∨ e.adjustToOrientation x i = -e i := by rw [adjustToOrientation] split_ifs with h · simp · by_cases hi : i = Classical.arbitrary ι <;> simp [unitsSMul_apply, hi] theorem det_adjustToOrientation [Nonempty ι] (e : Basis ι R M) (x : Orientation R M ι) : (e.adjustToOrientation x).det = e.det ∨ (e.adjustToOrientation x).det = -e.det := by dsimp [Basis.adjustToOrientation] split_ifs · left rfl · right simp only [e.det_unitsSMul, Finset.mem_univ, Finset.prod_update_of_mem, Pi.one_apply, Finset.prod_const_one, mul_one, inv_neg, inv_one, Units.val_neg, Units.val_one] ext simp @[simp] theorem abs_det_adjustToOrientation [Nonempty ι] (e : Basis ι R M) (x : Orientation R M ι) (v : ι → M) : |(e.adjustToOrientation x).det v| = |e.det v| := by rcases e.det_adjustToOrientation x with h | h <;> simp [h] end Module.Basis end LinearOrderedCommRing section LinearOrderedField variable {R : Type*} [Field R] [LinearOrder R] [IsStrictOrderedRing R] variable {M : Type*} [AddCommGroup M] [Module R M] variable {ι : Type*} namespace Orientation variable [Fintype ι] open FiniteDimensional Module /-- If the index type has cardinality equal to the finite dimension, any two orientations are equal or negations. -/ theorem eq_or_eq_neg [FiniteDimensional R M] (x₁ x₂ : Orientation R M ι) (h : Fintype.card ι = finrank R M) : x₁ = x₂ ∨ x₁ = -x₂ := by have e := (finBasis R M).reindex (Fintype.equivFinOfCardEq h).symm letI := Classical.decEq ι rcases e.orientation_eq_or_eq_neg x₁ with (h₁ | h₁) <;> rcases e.orientation_eq_or_eq_neg x₂ with (h₂ | h₂) <;> simp [h₁, h₂] /-- If the index type has cardinality equal to the finite dimension, an orientation equals the negation of another orientation if and only if they are not equal. -/ theorem ne_iff_eq_neg [FiniteDimensional R M] (x₁ x₂ : Orientation R M ι) (h : Fintype.card ι = finrank R M) : x₁ ≠ x₂ ↔ x₁ = -x₂ := ⟨fun hn => (eq_or_eq_neg x₁ x₂ h).resolve_left hn, fun he => he.symm ▸ (Module.Ray.ne_neg_self x₂).symm⟩ /-- The value of `Orientation.map` when the index type has cardinality equal to the finite dimension, in terms of `f.det`. -/ theorem map_eq_det_inv_smul [FiniteDimensional R M] (x : Orientation R M ι) (f : M ≃ₗ[R] M) (h : Fintype.card ι = finrank R M) : Orientation.map ι f x = (LinearEquiv.det f)⁻¹ • x := haveI e := (finBasis R M).reindex (Fintype.equivFinOfCardEq h).symm e.map_orientation_eq_det_inv_smul x f /-- If the index type has cardinality equal to the finite dimension, composing an alternating map with the same linear equiv on each argument gives the same orientation if and only if the determinant is positive. -/ theorem map_eq_iff_det_pos [FiniteDimensional R M] (x : Orientation R M ι) (f : M ≃ₗ[R] M) (h : Fintype.card ι = finrank R M) : Orientation.map ι f x = x ↔ 0 < LinearMap.det (f : M →ₗ[R] M) := by cases isEmpty_or_nonempty ι · have H : finrank R M = 0 := h.symm.trans Fintype.card_eq_zero simp [LinearMap.det_eq_one_of_finrank_eq_zero H] rw [map_eq_det_inv_smul _ _ h, units_inv_smul, units_smul_eq_self_iff, LinearEquiv.coe_det] /-- If the index type has cardinality equal to the finite dimension, composing an alternating map with the same linear equiv on each argument gives the negation of that orientation if and only if the determinant is negative. -/ theorem map_eq_neg_iff_det_neg (x : Orientation R M ι) (f : M ≃ₗ[R] M) (h : Fintype.card ι = finrank R M) : Orientation.map ι f x = -x ↔ LinearMap.det (f : M →ₗ[R] M) < 0 := by cases isEmpty_or_nonempty ι · have H : finrank R M = 0 := h.symm.trans Fintype.card_eq_zero simp [LinearMap.det_eq_one_of_finrank_eq_zero H, Module.Ray.ne_neg_self x] have H : 0 < finrank R M := by rw [← h] exact Fintype.card_pos haveI : FiniteDimensional R M := of_finrank_pos H rw [map_eq_det_inv_smul _ _ h, units_inv_smul, units_smul_eq_neg_iff, LinearEquiv.coe_det] /-- If the index type has cardinality equal to the finite dimension, a basis with the given orientation. -/ def someBasis [Nonempty ι] [DecidableEq ι] [FiniteDimensional R M] (x : Orientation R M ι) (h : Fintype.card ι = finrank R M) : Basis ι R M := ((finBasis R M).reindex (Fintype.equivFinOfCardEq h).symm).adjustToOrientation x /-- `some_basis` gives a basis with the required orientation. -/ @[simp] theorem someBasis_orientation [Nonempty ι] [DecidableEq ι] [FiniteDimensional R M] (x : Orientation R M ι) (h : Fintype.card ι = finrank R M) : (x.someBasis h).orientation = x := Basis.orientation_adjustToOrientation _ _ end Orientation end LinearOrderedField
.lake/packages/mathlib/Mathlib/LinearAlgebra/Isomorphisms.lean
import Mathlib.LinearAlgebra.Quotient.Basic import Mathlib.LinearAlgebra.Quotient.Card /-! # Isomorphism theorems for modules. * The Noether's first, second, and third isomorphism theorems for modules are proved as `LinearMap.quotKerEquivRange`, `LinearMap.quotientInfEquivSupQuotient` and `Submodule.quotientQuotientEquivQuotient`. -/ universe u v variable {R M M₂ M₃ : Type*} variable [Ring R] [AddCommGroup M] [AddCommGroup M₂] [AddCommGroup M₃] variable [Module R M] [Module R M₂] [Module R M₃] variable (f : M →ₗ[R] M₂) /-! The first and second isomorphism theorems for modules. -/ namespace LinearMap open Submodule section IsomorphismLaws /-- The **first isomorphism law for modules**. The quotient of `M` by the kernel of `f` is linearly equivalent to the range of `f`. -/ noncomputable def quotKerEquivRange : (M ⧸ LinearMap.ker f) ≃ₗ[R] LinearMap.range f := (LinearEquiv.ofInjective ((LinearMap.ker f).liftQ f <| le_rfl) <| ker_eq_bot.mp <| Submodule.ker_liftQ_eq_bot _ _ _ (le_refl (LinearMap.ker f))).trans (LinearEquiv.ofEq _ _ <| Submodule.range_liftQ _ _ _) /-- The **first isomorphism theorem for surjective linear maps**. -/ noncomputable def quotKerEquivOfSurjective (f : M →ₗ[R] M₂) (hf : Function.Surjective f) : (M ⧸ LinearMap.ker f) ≃ₗ[R] M₂ := f.quotKerEquivRange.trans <| .ofTop (LinearMap.range f) <| range_eq_top.2 hf @[simp] theorem quotKerEquivRange_apply_mk (x : M) : (f.quotKerEquivRange (Submodule.Quotient.mk x) : M₂) = f x := rfl @[simp] theorem quotKerEquivOfSurjective_apply_mk (hf : Function.Surjective f) (x : M) : (f.quotKerEquivOfSurjective hf (Submodule.Quotient.mk x) : M₂) = f x := rfl @[simp] theorem quotKerEquivRange_symm_apply_image (x : M) (h : f x ∈ LinearMap.range f) : f.quotKerEquivRange.symm ⟨f x, h⟩ = (LinearMap.ker f).mkQ x := f.quotKerEquivRange.symm_apply_apply ((LinearMap.ker f).mkQ x) @[simp] theorem quotKerEquivOfSurjective_symm_apply (hf : Function.Surjective f) (x : M) : (f.quotKerEquivOfSurjective hf).symm (f x) = Submodule.Quotient.mk x := by simp [LinearEquiv.symm_apply_eq] /-- Linear map from `p` to `p+p'/p'` where `p p'` are submodules of `R` -/ abbrev subToSupQuotient (p p' : Submodule R M) : { x // x ∈ p } →ₗ[R] { x // x ∈ p ⊔ p' } ⧸ comap (Submodule.subtype (p ⊔ p')) p' := (comap (p ⊔ p').subtype p').mkQ.comp (Submodule.inclusion le_sup_left) theorem comap_leq_ker_subToSupQuotient (p p' : Submodule R M) : comap (Submodule.subtype p) (p ⊓ p') ≤ ker (subToSupQuotient p p') := by rw [LinearMap.ker_comp, Submodule.inclusion, comap_codRestrict, ker_mkQ, map_comap_subtype] exact comap_mono (inf_le_inf_right _ le_sup_left) /-- Canonical linear map from the quotient `p/(p ∩ p')` to `(p+p')/p'`, mapping `x + (p ∩ p')` to `x + p'`, where `p` and `p'` are submodules of an ambient module. Note that in the following declaration the type of the domain is expressed using `comap p.subtype p ⊓ comap p.subtype p'` instead of `comap p.subtype (p ⊓ p')` because the former is the simp normal form (see also `Submodule.comap_inf`). -/ def quotientInfToSupQuotient (p p' : Submodule R M) : (↥p) ⧸ (comap p.subtype p ⊓ comap p.subtype p') →ₗ[R] (↥(p ⊔ p')) ⧸ (comap (p ⊔ p').subtype p') := (comap p.subtype (p ⊓ p')).liftQ (subToSupQuotient p p') (comap_leq_ker_subToSupQuotient p p') theorem quotientInfEquivSupQuotient_injective (p p' : Submodule R M) : Function.Injective (quotientInfToSupQuotient p p') := by rw [← ker_eq_bot, quotientInfToSupQuotient, ker_liftQ_eq_bot] rw [ker_comp, ker_mkQ] exact fun ⟨x, hx1⟩ hx2 => ⟨hx1, hx2⟩ theorem quotientInfEquivSupQuotient_surjective (p p' : Submodule R M) : Function.Surjective (quotientInfToSupQuotient p p') := by rw [← range_eq_top, quotientInfToSupQuotient, range_liftQ, eq_top_iff'] rintro ⟨x, hx⟩; rcases mem_sup.1 hx with ⟨y, hy, z, hz, rfl⟩ use ⟨y, hy⟩; apply (Submodule.Quotient.eq _).2 simp only [mem_comap, map_sub, coe_subtype, coe_inclusion, sub_add_cancel_left, neg_mem_iff, hz] /-- Second Isomorphism Law : the canonical map from `p/(p ∩ p')` to `(p+p')/p'` as a linear isomorphism. Note that in the following declaration the type of the domain is expressed using `comap p.subtype p ⊓ comap p.subtype p'` instead of `comap p.subtype (p ⊓ p')` because the former is the simp normal form (see also `Submodule.comap_inf`). -/ noncomputable def quotientInfEquivSupQuotient (p p' : Submodule R M) : (p ⧸ comap p.subtype p ⊓ comap p.subtype p') ≃ₗ[R] _ ⧸ comap (p ⊔ p').subtype p' := LinearEquiv.ofBijective (quotientInfToSupQuotient p p') ⟨quotientInfEquivSupQuotient_injective p p', quotientInfEquivSupQuotient_surjective p p'⟩ @[simp] theorem coe_quotientInfToSupQuotient (p p' : Submodule R M) : ⇑(quotientInfToSupQuotient p p') = quotientInfEquivSupQuotient p p' := rfl theorem quotientInfEquivSupQuotient_apply_mk (p p' : Submodule R M) (x : p) : let map := inclusion (le_sup_left : p ≤ p ⊔ p') quotientInfEquivSupQuotient p p' (Submodule.Quotient.mk x) = @Submodule.Quotient.mk R (p ⊔ p' : Submodule R M) _ _ _ (comap (p ⊔ p').subtype p') (map x) := rfl theorem quotientInfEquivSupQuotient_symm_apply_left (p p' : Submodule R M) (x : ↥(p ⊔ p')) (hx : (x : M) ∈ p) : (quotientInfEquivSupQuotient p p').symm (Submodule.Quotient.mk x) = Submodule.Quotient.mk ⟨x, hx⟩ := (LinearEquiv.symm_apply_eq _).2 <| by rw [quotientInfEquivSupQuotient_apply_mk, inclusion_apply] theorem quotientInfEquivSupQuotient_symm_apply_eq_zero_iff {p p' : Submodule R M} {x : ↥(p ⊔ p')} : (quotientInfEquivSupQuotient p p').symm (Submodule.Quotient.mk x) = 0 ↔ (x : M) ∈ p' := (LinearEquiv.symm_apply_eq _).trans <| by simp theorem quotientInfEquivSupQuotient_symm_apply_right (p p' : Submodule R M) {x : ↥(p ⊔ p')} (hx : (x : M) ∈ p') : (quotientInfEquivSupQuotient p p').symm (Submodule.Quotient.mk x) = 0 := quotientInfEquivSupQuotient_symm_apply_eq_zero_iff.2 hx end IsomorphismLaws end LinearMap /-! The third isomorphism theorem for modules. -/ namespace Submodule variable (S T : Submodule R M) (h : S ≤ T) /-- The map from the third isomorphism theorem for modules: `(M / S) / (T / S) → M / T`. -/ def quotientQuotientEquivQuotientAux (h : S ≤ T) : (M ⧸ S) ⧸ T.map S.mkQ →ₗ[R] M ⧸ T := liftQ _ (mapQ S T LinearMap.id h) (by rintro _ ⟨x, hx, rfl⟩ rw [LinearMap.mem_ker, mkQ_apply, mapQ_apply] exact (Quotient.mk_eq_zero _).mpr hx) @[simp] theorem quotientQuotientEquivQuotientAux_mk (x : M ⧸ S) : quotientQuotientEquivQuotientAux S T h (Quotient.mk x) = mapQ S T LinearMap.id h x := liftQ_apply _ _ _ -- @[simp] /- adaption note for https://github.com/leanprover/lean4/pull/8419: the simpNF complained -/ theorem quotientQuotientEquivQuotientAux_mk_mk (x : M) : quotientQuotientEquivQuotientAux S T h (Quotient.mk (Quotient.mk x)) = Quotient.mk x := rfl /-- **Noether's third isomorphism theorem** for modules: `(M / S) / (T / S) ≃ M / T`. -/ def quotientQuotientEquivQuotient : ((M ⧸ S) ⧸ T.map S.mkQ) ≃ₗ[R] M ⧸ T := { quotientQuotientEquivQuotientAux S T h with toFun := quotientQuotientEquivQuotientAux S T h invFun := mapQ _ _ (mkQ S) (le_comap_map _ _) left_inv := fun x => Submodule.Quotient.induction_on _ x fun x => Submodule.Quotient.induction_on _ x fun x => by simp right_inv := fun x => Submodule.Quotient.induction_on _ x fun x => by simp } /-- Essentially the same equivalence as in the third isomorphism theorem, except restated in terms of suprema/addition of submodules instead of `≤`. -/ def quotientQuotientEquivQuotientSup : ((M ⧸ S) ⧸ T.map S.mkQ) ≃ₗ[R] M ⧸ S ⊔ T := quotEquivOfEq _ _ (by rw [map_sup, mkQ_map_self, bot_sup_eq]) ≪≫ₗ quotientQuotientEquivQuotient S (S ⊔ T) le_sup_left /-- Corollary of the third isomorphism theorem: `[S : T] [M : S] = [M : T]` -/ theorem card_quotient_mul_card_quotient (S T : Submodule R M) (hST : T ≤ S) : Nat.card (S.map T.mkQ) * Nat.card (M ⧸ S) = Nat.card (M ⧸ T) := by rw [Submodule.card_eq_card_quotient_mul_card (map T.mkQ S), Nat.card_congr (quotientQuotientEquivQuotient T S hST).toEquiv] end Submodule
.lake/packages/mathlib/Mathlib/LinearAlgebra/JordanChevalley.lean
import Mathlib.Dynamics.Newton import Mathlib.LinearAlgebra.Semisimple import Mathlib.LinearAlgebra.FreeModule.Finite.Matrix /-! # Jordan-Chevalley-Dunford decomposition Given a finite-dimensional linear endomorphism `f`, the Jordan-Chevalley-Dunford theorem provides a sufficient condition for there to exist a nilpotent endomorphism `n` and a semisimple endomorphism `s`, such that `f = n + s` and both `n` and `s` are polynomial expressions in `f`. The condition is that there exists a separable polynomial `P` such that the endomorphism `P(f)` is nilpotent. This condition is always satisfied when the coefficients are a perfect field. The proof given here uses Newton's method and is taken from Chambert-Loir's notes: [Algebre](http://webusers.imj-prg.fr/~antoine.chambert-loir/enseignement/2022-23/agreg/algebre.pdf) ## Main definitions / results: * `Module.End.exists_isNilpotent_isSemisimple`: an endomorphism of a finite-dimensional vector space over a perfect field may be written as a sum of nilpotent and semisimple endomorphisms. Moreover these nilpotent and semisimple components are polynomial expressions in the original endomorphism. ## TODO * Uniqueness of decomposition (once we prove that the sum of commuting semisimple endomorphisms is semisimple, this will follow from `Module.End.eq_zero_of_isNilpotent_isSemisimple`). -/ open Algebra Polynomial namespace Module.End variable {K V : Type*} [Field K] [AddCommGroup V] [Module K V] {f : End K V} theorem exists_isNilpotent_isSemisimple_of_separable_of_dvd_pow {P : K[X]} {k : ℕ} (sep : P.Separable) (nil : minpoly K f ∣ P ^ k) : ∃ᵉ (n ∈ adjoin K {f}) (s ∈ adjoin K {f}), IsNilpotent n ∧ IsSemisimple s ∧ f = n + s := by set ff : adjoin K {f} := ⟨f, self_mem_adjoin_singleton K f⟩ set P' := derivative P have nil' : IsNilpotent (aeval ff P) := by use k obtain ⟨q, hq⟩ := nil rw [← map_pow, Subtype.ext_iff] simp [ff, hq] have sep' : IsUnit (aeval ff P') := by obtain ⟨a, b, h⟩ : IsCoprime (P ^ k) P' := sep.pow_left replace h : (aeval f b) * (aeval f P') = 1 := by simpa only [map_add, map_mul, map_one, minpoly.dvd_iff.mp nil, mul_zero, zero_add] using (aeval f).congr_arg h refine .of_mul_eq_one_right (aeval ff b) (Subtype.ext_iff.mpr ?_) simpa [ff, coe_aeval_mk_apply] using h obtain ⟨⟨s, mem⟩, ⟨⟨k, hk⟩, hss⟩, -⟩ := existsUnique_nilpotent_sub_and_aeval_eq_zero nil' sep' refine ⟨f - s, ?_, s, mem, ⟨k, ?_⟩, ?_, (sub_add_cancel f s).symm⟩ · exact sub_mem (self_mem_adjoin_singleton K f) mem · rw [Subtype.ext_iff] at hk simpa using hk · replace hss : aeval s P = 0 := by rwa [Subtype.ext_iff, coe_aeval_mk_apply] at hss exact isSemisimple_of_squarefree_aeval_eq_zero sep.squarefree hss variable [FiniteDimensional K V] /-- **Jordan-Chevalley-Dunford decomposition**: an endomorphism of a finite-dimensional vector space over a perfect field may be written as a sum of nilpotent and semisimple endomorphisms. Moreover these nilpotent and semisimple components are polynomial expressions in the original endomorphism. -/ theorem exists_isNilpotent_isSemisimple [PerfectField K] : ∃ᵉ (n ∈ adjoin K {f}) (s ∈ adjoin K {f}), IsNilpotent n ∧ IsSemisimple s ∧ f = n + s := by obtain ⟨g, k, sep, -, nil⟩ := exists_squarefree_dvd_pow_of_ne_zero (minpoly.ne_zero_of_finite K f) rw [← PerfectField.separable_iff_squarefree] at sep exact exists_isNilpotent_isSemisimple_of_separable_of_dvd_pow sep nil end Module.End
.lake/packages/mathlib/Mathlib/LinearAlgebra/Contraction.lean
import Mathlib.LinearAlgebra.Dual.Lemmas import Mathlib.LinearAlgebra.Matrix.ToLin /-! # Contractions Given modules $M, N$ over a commutative ring $R$, this file defines the natural linear maps: $M^* \otimes M \to R$, $M \otimes M^* \to R$, and $M^* \otimes N → Hom(M, N)$, as well as proving some basic properties of these maps. ## Tags contraction, dual module, tensor product -/ variable {ι : Type*} (R M N P Q : Type*) -- Enable extensionality of maps out of the tensor product. -- High priority so it takes precendence over `LinearMap.ext`. attribute [local ext high] TensorProduct.ext section Contraction open TensorProduct LinearMap Matrix Module open TensorProduct section CommSemiring variable [CommSemiring R] variable [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] [AddCommMonoid Q] variable [Module R M] [Module R N] [Module R P] [Module R Q] variable [DecidableEq ι] [Fintype ι] (b : Basis ι R M) /-- The natural left-handed pairing between a module and its dual. -/ def contractLeft : Module.Dual R M ⊗[R] M →ₗ[R] R := (uncurry _ _ _ _).toFun LinearMap.id /-- The natural right-handed pairing between a module and its dual. -/ def contractRight : M ⊗[R] Module.Dual R M →ₗ[R] R := (uncurry _ _ _ _).toFun (LinearMap.flip LinearMap.id) /-- The natural map associating a linear map to the tensor product of two modules. -/ def dualTensorHom : Module.Dual R M ⊗[R] N →ₗ[R] M →ₗ[R] N := let M' := Module.Dual R M (uncurry (.id R) M' N (M →ₗ[R] N) : _ → M' ⊗ N →ₗ[R] M →ₗ[R] N) LinearMap.smulRightₗ variable {R M N P Q} @[simp] theorem contractLeft_apply (f : Module.Dual R M) (m : M) : contractLeft R M (f ⊗ₜ m) = f m := rfl @[simp] theorem contractRight_apply (f : Module.Dual R M) (m : M) : contractRight R M (m ⊗ₜ f) = f m := rfl @[simp] theorem dualTensorHom_apply (f : Module.Dual R M) (m : M) (n : N) : dualTensorHom R M N (f ⊗ₜ n) m = f m • n := rfl @[simp] theorem transpose_dualTensorHom (f : Module.Dual R M) (m : M) : Dual.transpose (R := R) (dualTensorHom R M M (f ⊗ₜ m)) = dualTensorHom R _ _ (Dual.eval R M m ⊗ₜ f) := by ext f' m' simp only [Dual.transpose_apply, coe_comp, Function.comp_apply, dualTensorHom_apply, LinearMap.map_smulₛₗ, RingHom.id_apply, Algebra.id.smul_eq_mul, Dual.eval_apply, LinearMap.smul_apply] exact mul_comm _ _ @[simp] theorem dualTensorHom_prodMap_zero (f : Module.Dual R M) (p : P) : ((dualTensorHom R M P) (f ⊗ₜ[R] p)).prodMap (0 : N →ₗ[R] Q) = dualTensorHom R (M × N) (P × Q) ((f ∘ₗ fst R M N) ⊗ₜ inl R P Q p) := by ext <;> simp only [coe_comp, coe_inl, Function.comp_apply, prodMap_apply, dualTensorHom_apply, fst_apply, Prod.smul_mk, LinearMap.zero_apply, smul_zero] @[simp] theorem zero_prodMap_dualTensorHom (g : Module.Dual R N) (q : Q) : (0 : M →ₗ[R] P).prodMap ((dualTensorHom R N Q) (g ⊗ₜ[R] q)) = dualTensorHom R (M × N) (P × Q) ((g ∘ₗ snd R M N) ⊗ₜ inr R P Q q) := by ext <;> simp only [coe_comp, coe_inr, Function.comp_apply, prodMap_apply, dualTensorHom_apply, snd_apply, Prod.smul_mk, LinearMap.zero_apply, smul_zero] attribute [-ext] AlgebraTensorModule.curry_injective in theorem map_dualTensorHom (f : Module.Dual R M) (p : P) (g : Module.Dual R N) (q : Q) : TensorProduct.map (dualTensorHom R M P (f ⊗ₜ[R] p)) (dualTensorHom R N Q (g ⊗ₜ[R] q)) = dualTensorHom R (M ⊗[R] N) (P ⊗[R] Q) (dualDistrib R M N (f ⊗ₜ g) ⊗ₜ[R] (p ⊗ₜ[R] q)) := by ext m n simp only [compr₂ₛₗ_apply, mk_apply, map_tmul, dualTensorHom_apply, dualDistrib_apply, ← smul_tmul_smul] @[simp] theorem comp_dualTensorHom (f : Module.Dual R M) (n : N) (g : Module.Dual R N) (p : P) : dualTensorHom R N P (g ⊗ₜ[R] p) ∘ₗ dualTensorHom R M N (f ⊗ₜ[R] n) = g n • dualTensorHom R M P (f ⊗ₜ p) := by ext m simp only [coe_comp, Function.comp_apply, dualTensorHom_apply, LinearMap.map_smul, LinearMap.smul_apply] rw [smul_comm] /-- As a matrix, `dualTensorHom` evaluated on a basis element of `M* ⊗ N` is a matrix with a single one and zeros elsewhere -/ theorem toMatrix_dualTensorHom {m : Type*} {n : Type*} [Fintype m] [Finite n] [DecidableEq m] [DecidableEq n] (bM : Basis m R M) (bN : Basis n R N) (j : m) (i : n) : toMatrix bM bN (dualTensorHom R M N (bM.coord j ⊗ₜ bN i)) = single i j 1 := by ext i' j' by_cases hij : i = i' ∧ j = j' <;> simp [LinearMap.toMatrix_apply, Finsupp.single_eq_pi_single, hij] rw [and_iff_not_or_not, Classical.not_not] at hij rcases hij with hij | hij <;> simp [hij] attribute [-ext] AlgebraTensorModule.curry_injective in /-- If `M` is free, the natural linear map $M^* ⊗ N → Hom(M, N)$ is an equivalence. This function provides this equivalence in return for a basis of `M`. -/ -- We manually create simp-lemmas because `@[simps]` generates a malformed lemma noncomputable def dualTensorHomEquivOfBasis : Module.Dual R M ⊗[R] N ≃ₗ[R] M →ₗ[R] N := LinearEquiv.ofLinear (dualTensorHom R M N) (∑ i, TensorProduct.mk R _ N (b.dualBasis i) ∘ₗ (LinearMap.applyₗ (R := R) (b i))) (by ext f m simp only [applyₗ_apply_apply, coeFn_sum, dualTensorHom_apply, mk_apply, id_coe, _root_.id, Fintype.sum_apply, Function.comp_apply, Basis.coe_dualBasis, coe_comp, Basis.coord_apply, ← f.map_smul, _root_.map_sum (dualTensorHom R M N), ← _root_.map_sum f, b.sum_repr]) (by ext f m simp only [applyₗ_apply_apply, coeFn_sum, dualTensorHom_apply, mk_apply, id_coe, _root_.id, Fintype.sum_apply, Function.comp_apply, Basis.coe_dualBasis, coe_comp, compr₂ₛₗ_apply, tmul_smul, smul_tmul', ← sum_tmul, Basis.sum_dual_apply_smul_coord]) @[simp] theorem dualTensorHomEquivOfBasis_apply (x : Module.Dual R M ⊗[R] N) : dualTensorHomEquivOfBasis b x = dualTensorHom R M N x := by ext; rfl @[simp] theorem dualTensorHomEquivOfBasis_toLinearMap : (dualTensorHomEquivOfBasis b).toLinearMap = dualTensorHom R M N := rfl @[simp] theorem dualTensorHomEquivOfBasis_symm_cancel_left (x : Module.Dual R M ⊗[R] N) : (dualTensorHomEquivOfBasis b).symm (dualTensorHom R M N x) = x := by rw [← dualTensorHomEquivOfBasis_apply b, LinearEquiv.symm_apply_apply <| dualTensorHomEquivOfBasis (N := N) b] @[simp] theorem dualTensorHomEquivOfBasis_symm_cancel_right (x : M →ₗ[R] N) : dualTensorHom R M N ((dualTensorHomEquivOfBasis b).symm x) = x := by rw [← dualTensorHomEquivOfBasis_apply b, LinearEquiv.apply_symm_apply] variable (R M N P Q) variable [Module.Free R M] [Module.Finite R M] /-- If `M` is finite free, the natural map $M^* ⊗ N → Hom(M, N)$ is an equivalence. -/ @[simp] noncomputable def dualTensorHomEquiv : Module.Dual R M ⊗[R] N ≃ₗ[R] M →ₗ[R] N := dualTensorHomEquivOfBasis (Module.Free.chooseBasis R M) end CommSemiring end Contraction section HomTensorHom open TensorProduct open Module TensorProduct LinearMap section CommSemiring variable [CommSemiring R] variable [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] [AddCommMonoid Q] variable [Module R M] [Module R N] [Module R P] [Module R Q] variable [Free R M] [Module.Finite R M] [Free R N] [Module.Finite R N] /-- When `M` is a finite free module, the map `lTensorHomToHomLTensor` is an equivalence. Note that `lTensorHomEquivHomLTensor` is not defined directly in terms of `lTensorHomToHomLTensor`, but the equivalence between the two is given by `lTensorHomEquivHomLTensor_toLinearMap` and `lTensorHomEquivHomLTensor_apply`. -/ noncomputable def lTensorHomEquivHomLTensor : P ⊗[R] (M →ₗ[R] Q) ≃ₗ[R] M →ₗ[R] P ⊗[R] Q := congr (LinearEquiv.refl R P) (dualTensorHomEquiv R M Q).symm ≪≫ₗ TensorProduct.leftComm R P _ Q ≪≫ₗ dualTensorHomEquiv R M _ /-- When `M` is a finite free module, the map `rTensorHomToHomRTensor` is an equivalence. Note that `rTensorHomEquivHomRTensor` is not defined directly in terms of `rTensorHomToHomRTensor`, but the equivalence between the two is given by `rTensorHomEquivHomRTensor_toLinearMap` and `rTensorHomEquivHomRTensor_apply`. -/ noncomputable def rTensorHomEquivHomRTensor : (M →ₗ[R] P) ⊗[R] Q ≃ₗ[R] M →ₗ[R] P ⊗[R] Q := congr (dualTensorHomEquiv R M P).symm (LinearEquiv.refl R Q) ≪≫ₗ TensorProduct.assoc R _ P Q ≪≫ₗ dualTensorHomEquiv R M _ attribute [-ext] AlgebraTensorModule.curry_injective in @[simp] theorem lTensorHomEquivHomLTensor_toLinearMap : (lTensorHomEquivHomLTensor R M P Q).toLinearMap = lTensorHomToHomLTensor (.id R) M P Q := by let e := congr (LinearEquiv.refl R P) (dualTensorHomEquiv R M Q) have h : Function.Surjective e.toLinearMap := e.surjective refine (cancel_right h).1 ?_ ext f q m simp only [e, lTensorHomEquivHomLTensor, dualTensorHomEquiv, LinearEquiv.comp_coe, compr₂ₛₗ_apply, mk_apply, LinearEquiv.coe_coe, LinearEquiv.trans_apply, congr_tmul, LinearEquiv.refl_apply, dualTensorHomEquivOfBasis_apply, dualTensorHomEquivOfBasis_symm_cancel_left, leftComm_tmul, dualTensorHom_apply, coe_comp, Function.comp_apply, lTensorHomToHomLTensor_apply, tmul_smul] attribute [-ext] AlgebraTensorModule.curry_injective in @[simp] theorem rTensorHomEquivHomRTensor_toLinearMap : (rTensorHomEquivHomRTensor R M P Q).toLinearMap = rTensorHomToHomRTensor (.id R) M P Q := by let e := congr (dualTensorHomEquiv R M P) (LinearEquiv.refl R Q) have h : Function.Surjective e.toLinearMap := e.surjective refine (cancel_right h).1 ?_ ext f p q m simp only [e, rTensorHomEquivHomRTensor, dualTensorHomEquiv, compr₂ₛₗ_apply, mk_apply, coe_comp, LinearEquiv.coe_toLinearMap, Function.comp_apply, dualTensorHomEquivOfBasis_apply, LinearEquiv.trans_apply, congr_tmul, dualTensorHomEquivOfBasis_symm_cancel_left, LinearEquiv.refl_apply, assoc_tmul, dualTensorHom_apply, rTensorHomToHomRTensor_apply, smul_tmul'] variable {R M N P Q} @[simp] theorem lTensorHomEquivHomLTensor_apply (x : P ⊗[R] (M →ₗ[R] Q)) : lTensorHomEquivHomLTensor R M P Q x = lTensorHomToHomLTensor (.id R) M P Q x := by rw [← LinearEquiv.coe_toLinearMap, lTensorHomEquivHomLTensor_toLinearMap] @[simp] theorem rTensorHomEquivHomRTensor_apply (x : (M →ₗ[R] P) ⊗[R] Q) : rTensorHomEquivHomRTensor R M P Q x = rTensorHomToHomRTensor (.id R) M P Q x := by rw [← LinearEquiv.coe_toLinearMap, rTensorHomEquivHomRTensor_toLinearMap] variable (R M N P Q) /-- When `M` and `N` are free `R` modules, the map `homTensorHomMap` is an equivalence. Note that `homTensorHomEquiv` is not defined directly in terms of `homTensorHomMap`, but the equivalence between the two is given by `homTensorHomEquiv_toLinearMap` and `homTensorHomEquiv_apply`. -/ noncomputable def homTensorHomEquiv : (M →ₗ[R] P) ⊗[R] (N →ₗ[R] Q) ≃ₗ[R] M ⊗[R] N →ₗ[R] P ⊗[R] Q := rTensorHomEquivHomRTensor R M P _ ≪≫ₗ (LinearEquiv.refl R M).arrowCongr (lTensorHomEquivHomLTensor R N _ Q) ≪≫ₗ lift.equiv _ M N _ attribute [-ext] AlgebraTensorModule.curry_injective in @[simp] theorem homTensorHomEquiv_toLinearMap : (homTensorHomEquiv R M N P Q).toLinearMap = homTensorHomMap (.id R) M N P Q := by ext m n simp only [homTensorHomEquiv, compr₂ₛₗ_apply, mk_apply, LinearEquiv.coe_toLinearMap, LinearEquiv.trans_apply, lift.equiv_apply, LinearEquiv.arrowCongr_apply, LinearEquiv.refl_symm, LinearEquiv.refl_apply, rTensorHomEquivHomRTensor_apply, lTensorHomEquivHomLTensor_apply, lTensorHomToHomLTensor_apply, rTensorHomToHomRTensor_apply, homTensorHomMap_apply, map_tmul] variable {R M N P Q} @[simp] theorem homTensorHomEquiv_apply (x : (M →ₗ[R] P) ⊗[R] (N →ₗ[R] Q)) : homTensorHomEquiv R M N P Q x = homTensorHomMap (.id R) M N P Q x := by rw [← LinearEquiv.coe_toLinearMap, homTensorHomEquiv_toLinearMap] end CommSemiring end HomTensorHom
.lake/packages/mathlib/Mathlib/LinearAlgebra/Trace.lean
import Mathlib.LinearAlgebra.Contraction import Mathlib.LinearAlgebra.Matrix.Charpoly.Coeff import Mathlib.RingTheory.Finiteness.Prod import Mathlib.RingTheory.TensorProduct.Finite import Mathlib.RingTheory.TensorProduct.Free /-! # Trace of a linear map This file defines the trace of a linear map. See also `LinearAlgebra/Matrix/Trace.lean` for the trace of a matrix. ## Tags linear_map, trace, diagonal -/ noncomputable section universe u v w namespace LinearMap open scoped Matrix open Module TensorProduct section variable (R : Type u) [CommSemiring R] {M : Type v} [AddCommMonoid M] [Module R M] variable {ι : Type w} [DecidableEq ι] [Fintype ι] variable {κ : Type*} [DecidableEq κ] [Fintype κ] variable (b : Basis ι R M) (c : Basis κ R M) /-- The trace of an endomorphism given a basis. -/ def traceAux : (M →ₗ[R] M) →ₗ[R] R := Matrix.traceLinearMap ι R R ∘ₗ ↑(LinearMap.toMatrix b b) -- Can't be `simp` because it would cause a loop. theorem traceAux_def (b : Basis ι R M) (f : M →ₗ[R] M) : traceAux R b f = Matrix.trace (LinearMap.toMatrix b b f) := rfl theorem traceAux_eq : traceAux R b = traceAux R c := LinearMap.ext fun f => calc Matrix.trace (LinearMap.toMatrix b b f) = Matrix.trace (LinearMap.toMatrix b b ((LinearMap.id.comp f).comp LinearMap.id)) := by rw [LinearMap.id_comp, LinearMap.comp_id] _ = Matrix.trace (LinearMap.toMatrix c b LinearMap.id * LinearMap.toMatrix c c f * LinearMap.toMatrix b c LinearMap.id) := by rw [LinearMap.toMatrix_comp _ c, LinearMap.toMatrix_comp _ c] _ = Matrix.trace (LinearMap.toMatrix c c f * LinearMap.toMatrix b c LinearMap.id * LinearMap.toMatrix c b LinearMap.id) := by rw [Matrix.mul_assoc, Matrix.trace_mul_comm] _ = Matrix.trace (LinearMap.toMatrix c c ((f.comp LinearMap.id).comp LinearMap.id)) := by rw [LinearMap.toMatrix_comp _ b, LinearMap.toMatrix_comp _ c] _ = Matrix.trace (LinearMap.toMatrix c c f) := by rw [LinearMap.comp_id, LinearMap.comp_id] variable (M) in open Classical in /-- Trace of an endomorphism independent of basis. -/ def trace : (M →ₗ[R] M) →ₗ[R] R := if H : ∃ s : Finset M, Nonempty (Basis s R M) then traceAux R H.choose_spec.some else 0 open Classical in /-- Auxiliary lemma for `trace_eq_matrix_trace`. -/ theorem trace_eq_matrix_trace_of_finset {s : Finset M} (b : Basis s R M) (f : M →ₗ[R] M) : trace R M f = Matrix.trace (LinearMap.toMatrix b b f) := by have : ∃ s : Finset M, Nonempty (Basis s R M) := ⟨s, ⟨b⟩⟩ rw [trace, dif_pos this, ← traceAux_def] congr 1 apply traceAux_eq theorem trace_eq_matrix_trace (f : M →ₗ[R] M) : trace R M f = Matrix.trace (LinearMap.toMatrix b b f) := by classical rw [trace_eq_matrix_trace_of_finset R b.reindexFinsetRange, ← traceAux_def, ← traceAux_def, traceAux_eq R b b.reindexFinsetRange] variable {R} in @[simp] theorem _root_.Matrix.trace_toLin_eq (A : Matrix ι ι R) (b : Basis ι R M) : LinearMap.trace R _ (Matrix.toLin b b A) = A.trace := by simp [trace_eq_matrix_trace R b] variable {R} in @[simp] theorem _root_.Matrix.trace_toLin'_eq (A : Matrix ι ι R) : LinearMap.trace R _ A.toLin' = A.trace := A.trace_toLin_eq (Pi.basisFun R ι) theorem trace_mul_comm (f g : M →ₗ[R] M) : trace R M (f * g) = trace R M (g * f) := by classical by_cases H : ∃ s : Finset M, Nonempty (Basis s R M) · let ⟨s, ⟨b⟩⟩ := H simp_rw [trace_eq_matrix_trace R b, LinearMap.toMatrix_mul] apply Matrix.trace_mul_comm · rw [trace, dif_neg H, LinearMap.zero_apply, LinearMap.zero_apply] lemma trace_mul_cycle (f g h : M →ₗ[R] M) : trace R M (f * g * h) = trace R M (h * f * g) := by rw [LinearMap.trace_mul_comm, ← mul_assoc] lemma trace_mul_cycle' (f g h : M →ₗ[R] M) : trace R M (f * (g * h)) = trace R M (h * (f * g)) := by rw [← mul_assoc, LinearMap.trace_mul_comm] /-- The trace of an endomorphism is invariant under conjugation -/ @[simp] theorem trace_conj (g : M →ₗ[R] M) (f : (M →ₗ[R] M)ˣ) : trace R M (↑f * g * ↑f⁻¹) = trace R M g := by rw [trace_mul_comm] simp @[simp] lemma trace_lie {R M : Type*} [CommRing R] [AddCommGroup M] [Module R M] (f g : Module.End R M) : trace R M ⁅f, g⁆ = 0 := by rw [Ring.lie_def, map_sub, trace_mul_comm] exact sub_self _ end section variable {R : Type*} [CommRing R] {M : Type*} [AddCommGroup M] [Module R M] variable (N P : Type*) [AddCommGroup N] [Module R N] [AddCommGroup P] [Module R P] variable {ι : Type*} /-- The trace of a linear map correspond to the contraction pairing under the isomorphism `End(M) ≃ M* ⊗ M` -/ theorem trace_eq_contract_of_basis [Finite ι] (b : Basis ι R M) : LinearMap.trace R M ∘ₗ dualTensorHom R M M = contractLeft R M := by classical cases nonempty_fintype ι apply Basis.ext (Basis.tensorProduct (Basis.dualBasis b) b) rintro ⟨i, j⟩ simp only [Function.comp_apply, Basis.tensorProduct_apply, Basis.coe_dualBasis, coe_comp] rw [trace_eq_matrix_trace R b, toMatrix_dualTensorHom] obtain rfl | hij := eq_or_ne i j · simp rw [Matrix.trace_single_eq_of_ne j i (1 : R) hij.symm] simp [hij] /-- The trace of a linear map corresponds to the contraction pairing under the isomorphism `End(M) ≃ M* ⊗ M`. -/ theorem trace_eq_contract_of_basis' [Fintype ι] [DecidableEq ι] (b : Basis ι R M) : LinearMap.trace R M = contractLeft R M ∘ₗ (dualTensorHomEquivOfBasis b).symm.toLinearMap := by simp [LinearEquiv.eq_comp_toLinearMap_symm, trace_eq_contract_of_basis b] section variable (R M) variable [Module.Free R M] [Module.Finite R M] [Module.Free R N] [Module.Finite R N] /-- When `M` is finite free, the trace of a linear map corresponds to the contraction pairing under the isomorphism `End(M) ≃ M* ⊗ M`. -/ @[simp] theorem trace_eq_contract : LinearMap.trace R M ∘ₗ dualTensorHom R M M = contractLeft R M := trace_eq_contract_of_basis (Module.Free.chooseBasis R M) @[simp] theorem trace_eq_contract_apply (x : Module.Dual R M ⊗[R] M) : (LinearMap.trace R M) ((dualTensorHom R M M) x) = contractLeft R M x := by rw [← comp_apply, trace_eq_contract] /-- When `M` is finite free, the trace of a linear map corresponds to the contraction pairing under the isomorphism `End(M) ≃ M* ⊗ M`. -/ theorem trace_eq_contract' : LinearMap.trace R M = contractLeft R M ∘ₗ (dualTensorHomEquiv R M M).symm.toLinearMap := trace_eq_contract_of_basis' (Module.Free.chooseBasis R M) /-- The trace of the identity endomorphism is the dimension of the free module. -/ @[simp] theorem trace_one : trace R M 1 = (finrank R M : R) := by cases subsingleton_or_nontrivial R · simp [eq_iff_true_of_subsingleton] have b := Module.Free.chooseBasis R M rw [trace_eq_matrix_trace R b, toMatrix_one, finrank_eq_card_chooseBasisIndex] simp /-- The trace of the identity endomorphism is the dimension of the free module. -/ @[simp] theorem trace_id : trace R M id = (finrank R M : R) := by rw [← Module.End.one_eq_id, trace_one] @[simp] theorem trace_transpose : trace R (Module.Dual R M) ∘ₗ Module.Dual.transpose = trace R M := by let e := dualTensorHomEquiv R M M have h : Function.Surjective e.toLinearMap := e.surjective refine (cancel_right h).1 ?_ ext f m; simp [e] theorem trace_prodMap : trace R (M × N) ∘ₗ prodMapLinear R M N M N R = (coprod id id : R × R →ₗ[R] R) ∘ₗ prodMap (trace R M) (trace R N) := by let e := (dualTensorHomEquiv R M M).prodCongr (dualTensorHomEquiv R N N) have h : Function.Surjective e.toLinearMap := e.surjective refine (cancel_right h).1 ?_ ext · simp only [dualTensorHomEquiv, LinearEquiv.coe_prodCongr, dualTensorHomEquivOfBasis_toLinearMap, AlgebraTensorModule.curry_apply, restrictScalars_comp, curry_apply, coe_comp, coe_restrictScalars, coe_inl, Function.comp_apply, prodMap_apply, map_zero, prodMapLinear_apply, dualTensorHom_prodMap_zero, trace_eq_contract_apply, contractLeft_apply, coe_fst, coprod_apply, id_coe, id_eq, add_zero, e] · simp only [dualTensorHomEquiv, LinearEquiv.coe_prodCongr, dualTensorHomEquivOfBasis_toLinearMap, AlgebraTensorModule.curry_apply, restrictScalars_comp, curry_apply, coe_comp, coe_restrictScalars, coe_inr, Function.comp_apply, prodMap_apply, map_zero, prodMapLinear_apply, zero_prodMap_dualTensorHom, trace_eq_contract_apply, contractLeft_apply, coe_snd, coprod_apply, id_coe, id_eq, zero_add, e] variable {R M N P} theorem trace_prodMap' (f : M →ₗ[R] M) (g : N →ₗ[R] N) : trace R (M × N) (prodMap f g) = trace R M f + trace R N g := by have h := LinearMap.ext_iff.1 (trace_prodMap R M N) (f, g) simp only [coe_comp, Function.comp_apply, prodMap_apply, coprod_apply, id, prodMapLinear_apply] at h exact h variable (R M N P) open TensorProduct Function theorem trace_tensorProduct : compr₂ (mapBilinear (.id R) M N M N) (trace R (M ⊗ N)) = compl₁₂ (lsmul R R : R →ₗ[R] R →ₗ[R] R) (trace R M) (trace R N) := by apply (compl₁₂_inj (show Surjective (dualTensorHom R M M) from (dualTensorHomEquiv R M M).surjective) (show Surjective (dualTensorHom R N N) from (dualTensorHomEquiv R N N).surjective)).1 ext f m g n simp only [AlgebraTensorModule.curry_apply, TensorProduct.curry_apply, coe_restrictScalars, compl₁₂_apply, compr₂_apply, mapBilinear_apply, trace_eq_contract_apply, contractLeft_apply, lsmul_apply, Algebra.id.smul_eq_mul, map_dualTensorHom, dualDistrib_apply] theorem trace_comp_comm : compr₂ (llcomp R M N M) (trace R M) = compr₂ (llcomp R N M N).flip (trace R N) := by apply (compl₁₂_inj (show Surjective (dualTensorHom R N M) from (dualTensorHomEquiv R N M).surjective) (show Surjective (dualTensorHom R M N) from (dualTensorHomEquiv R M N).surjective)).1 ext g m f n simp only [AlgebraTensorModule.curry_apply, TensorProduct.curry_apply, coe_restrictScalars, compl₁₂_apply, compr₂_apply, flip_apply, llcomp_apply', comp_dualTensorHom, LinearMapClass.map_smul, trace_eq_contract_apply, contractLeft_apply, smul_eq_mul, mul_comm] variable {R M N P} @[simp] theorem trace_transpose' (f : M →ₗ[R] M) : trace R _ (Module.Dual.transpose (R := R) f) = trace R M f := by rw [← comp_apply, trace_transpose] theorem trace_tensorProduct' (f : M →ₗ[R] M) (g : N →ₗ[R] N) : trace R (M ⊗ N) (map f g) = trace R M f * trace R N g := by have h := LinearMap.ext_iff.1 (LinearMap.ext_iff.1 (trace_tensorProduct R M N) f) g simp only [compr₂_apply, mapBilinear_apply, compl₁₂_apply, lsmul_apply, Algebra.id.smul_eq_mul] at h exact h theorem trace_comp_comm' (f : M →ₗ[R] N) (g : N →ₗ[R] M) : trace R M (g ∘ₗ f) = trace R N (f ∘ₗ g) := by have h := LinearMap.ext_iff.1 (LinearMap.ext_iff.1 (trace_comp_comm R M N) g) f simp only [llcomp_apply', compr₂_apply, flip_apply] at h exact h @[simp] lemma trace_smulRight (f : M →ₗ[R] R) (x : M) : trace R M (f.smulRight x) = f x := by rw [trace_eq_matrix_trace _ (Free.chooseBasis R M), ← (Free.chooseBasis R M).sum_repr x] simp [- Basis.sum_repr, dotProduct] end variable {N P} variable [Module.Free R N] [Module.Finite R N] [Module.Free R P] [Module.Finite R P] in lemma trace_comp_cycle (f : M →ₗ[R] N) (g : N →ₗ[R] P) (h : P →ₗ[R] M) : trace R P (g ∘ₗ f ∘ₗ h) = trace R N (f ∘ₗ h ∘ₗ g) := by rw [trace_comp_comm', comp_assoc] variable [Module.Free R M] [Module.Finite R M] [Module.Free R P] [Module.Finite R P] in lemma trace_comp_cycle' (f : M →ₗ[R] N) (g : N →ₗ[R] P) (h : P →ₗ[R] M) : trace R P ((g ∘ₗ f) ∘ₗ h) = trace R M ((h ∘ₗ g) ∘ₗ f) := by rw [trace_comp_comm', ← comp_assoc] @[simp] theorem trace_conj' (f : M →ₗ[R] M) (e : M ≃ₗ[R] N) : trace R N (e.conj f) = trace R M f := by classical by_cases hM : ∃ s : Finset M, Nonempty (Basis s R M) · obtain ⟨s, ⟨b⟩⟩ := hM haveI := Module.Finite.of_basis b haveI := (Module.free_def R M).mpr ⟨_, ⟨b⟩⟩ haveI := Module.Finite.of_basis (b.map e) haveI := (Module.free_def R N).mpr ⟨_, ⟨(b.map e).reindex (e.toEquiv.image _)⟩⟩ rw [e.conj_apply, trace_comp_comm', ← comp_assoc, LinearEquiv.comp_coe, LinearEquiv.self_trans_symm, LinearEquiv.refl_toLinearMap, id_comp] · rw [trace, trace, dif_neg hM, dif_neg ?_, zero_apply, zero_apply] rintro ⟨s, ⟨b⟩⟩ exact hM ⟨s.image e.symm, ⟨(b.map e.symm).reindex ((e.symm.toEquiv.image s).trans (Equiv.setCongr Finset.coe_image.symm))⟩⟩ theorem IsProj.trace {p : Submodule R M} {f : M →ₗ[R] M} (h : IsProj p f) [Module.Free R p] [Module.Finite R p] [Module.Free R (ker f)] [Module.Finite R (ker f)] : trace R M f = (finrank R p : R) := by rw [h.eq_conj_prodMap, trace_conj', trace_prodMap', trace_id, map_zero, add_zero] lemma isNilpotent_trace_of_isNilpotent {f : M →ₗ[R] M} (hf : IsNilpotent f) : IsNilpotent (trace R M f) := by by_cases H : ∃ s : Finset M, Nonempty (Basis s R M) swap · rw [LinearMap.trace, dif_neg H] exact IsNilpotent.zero obtain ⟨s, ⟨b⟩⟩ := H classical rw [trace_eq_matrix_trace R b] apply Matrix.isNilpotent_trace_of_isNilpotent simpa lemma trace_comp_eq_mul_of_commute_of_isNilpotent [IsReduced R] {f g : Module.End R M} (μ : R) (h_comm : Commute f g) (hg : IsNilpotent (g - algebraMap R _ μ)) : trace R M (f ∘ₗ g) = μ * trace R M f := by set n := g - algebraMap R _ μ replace hg : trace R M (f ∘ₗ n) = 0 := by rw [← isNilpotent_iff_eq_zero, ← Module.End.mul_eq_comp] refine isNilpotent_trace_of_isNilpotent (Commute.isNilpotent_mul_left ?_ hg) exact h_comm.sub_right (Algebra.commute_algebraMap_right μ f) have hμ : g = algebraMap R _ μ + n := eq_add_of_sub_eq' rfl have : f ∘ₗ algebraMap R _ μ = μ • f := by ext; simp -- TODO Surely exists? rw [hμ, comp_add, map_add, hg, add_zero, this, LinearMap.map_smul, smul_eq_mul] -- This result requires `Mathlib/RingTheory/TensorProduct/Free.lean`. -- Maybe it should move elsewhere? @[simp] lemma trace_baseChange [Module.Free R M] [Module.Finite R M] (f : M →ₗ[R] M) (A : Type*) [CommRing A] [Algebra R A] : trace A _ (f.baseChange A) = algebraMap R A (trace R _ f) := by let b := Module.Free.chooseBasis R M let b' := Algebra.TensorProduct.basis A b change _ = (algebraMap R A : R →+ A) _ simp [b', trace_eq_matrix_trace R b, trace_eq_matrix_trace A b', AddMonoidHom.map_trace] end end LinearMap
.lake/packages/mathlib/Mathlib/LinearAlgebra/SModEq.lean
import Mathlib.LinearAlgebra.SModEq.Basic deprecated_module (since := "2025-10-28")
.lake/packages/mathlib/Mathlib/LinearAlgebra/Transvection.lean
import Mathlib.LinearAlgebra.DFinsupp import Mathlib.LinearAlgebra.Dual.Defs /-! # Transvections in a module * When `f : Module.Dual R V` and `v : V`, `LinearMap.transvection f v` is the linear map given by `x ↦ x + f x • v`, * If, moreover, `f v = 0`, then `LinearEquiv.transvection` shows that it is a linear equivalence. -/ namespace LinearMap variable {R V : Type*} [CommSemiring R] [AddCommMonoid V] [Module R V] /-- The transvection associated with a linear form `f` and a vector `v`. NB. It is only a transvection when `f v = 0`. See also `Module.preReflection`. -/ def transvection (f : Module.Dual R V) (v : V) : V →ₗ[R] V where toFun x := x + f x • v map_add' x y := by simp only [map_add]; module map_smul' r x := by simp only [map_smul, RingHom.id_apply, smul_eq_mul]; module namespace transvection theorem apply (f : Module.Dual R V) (v x : V) : transvection f v x = x + f x • v := rfl theorem comp_of_left_eq_apply {f : Module.Dual R V} {v w : V} {x : V} (hw : f w = 0) : transvection f v (transvection f w x) = transvection f (v + w) x := by simp only [transvection, coe_mk, AddHom.coe_mk, map_add, map_smul, hw, smul_add] module theorem comp_of_left_eq {f : Module.Dual R V} {v w : V} (hw : f w = 0) : (transvection f v) ∘ₗ (transvection f w) = transvection f (v + w) := by ext; simp [comp_of_left_eq_apply hw] theorem comp_of_right_eq_apply {f g : Module.Dual R V} {v : V} {x : V} (hf : f v = 0) : (transvection f v) (transvection g v x) = transvection (f + g) v x := by simp only [transvection, coe_mk, AddHom.coe_mk, map_add, map_smul, hf, add_apply] module theorem comp_of_right_eq {f g : Module.Dual R V} {v : V} (hf : f v = 0) : (transvection f v) ∘ₗ (transvection g v) = transvection (f + g) v := by ext; simp [comp_of_right_eq_apply hf] @[simp] theorem of_left_eq_zero (v : V) : transvection (0 : Module.Dual R V) v = LinearMap.id := by ext simp [transvection] @[simp] theorem of_right_eq_zero (f : Module.Dual R V) : transvection f 0 = LinearMap.id := by ext simp [transvection] theorem congr {W : Type*} [AddCommMonoid W] [Module R W] (f : Module.Dual R V) (v : V) (e : V ≃ₗ[R] W) : e ∘ₗ (transvection f v) ∘ₗ e.symm = transvection (f ∘ₗ e.symm) (e v) := by ext; simp [transvection.apply] end LinearMap.transvection variable {R V : Type*} [CommRing R] [AddCommGroup V] [Module R V] namespace LinearEquiv open LinearMap LinearMap.transvection /-- The transvection associated with a linear form `f` and a vector `v` such that `f v = 0`. -/ def transvection {f : Module.Dual R V} {v : V} (h : f v = 0) : V ≃ₗ[R] V where toFun := LinearMap.transvection f v invFun := LinearMap.transvection f (-v) map_add' x y := by simp [map_add] map_smul' r x := by simp left_inv x := by simp [comp_of_left_eq_apply h] right_inv x := by have h' : f (-v) = 0 := by simp [h] simp [comp_of_left_eq_apply h'] namespace transvection theorem apply {f : Module.Dual R V} {v : V} (h : f v = 0) (x : V) : transvection h x = x + f x • v := rfl @[simp] theorem coe_toLinearMap {f : Module.Dual R V} {v : V} (h : f v = 0) : LinearEquiv.transvection h = LinearMap.transvection f v := rfl @[simp] theorem coe_apply {f : Module.Dual R V} {v x : V} {h : f v = 0} : LinearEquiv.transvection h x = LinearMap.transvection f v x := rfl theorem trans_of_left_eq {f : Module.Dual R V} {v w : V} (hv : f v = 0) (hw : f w = 0) (hvw : f (v + w) = 0 := by simp [hv, hw]) : (transvection hw).trans (transvection hv) = transvection hvw := by ext; simp [comp_of_left_eq_apply hw] theorem trans_of_right_eq {f g : Module.Dual R V} {v : V} (hf : f v = 0) (hg : g v = 0) (hfg : (f + g) v = 0 := by simp [hf, hg]) : (transvection hg).trans (transvection hf) = transvection hfg := by ext; simp [comp_of_right_eq_apply hf] @[simp] theorem of_left_eq_zero (v : V) (hv := LinearMap.zero_apply v) : transvection hv = LinearEquiv.refl R V := by ext; simp [transvection] @[simp] theorem of_right_eq_zero (f : Module.Dual R V) (hf := f.map_zero) : transvection hf = LinearEquiv.refl R V := by ext; simp [transvection] theorem symm_eq {f : Module.Dual R V} {v : V} (hv : f v = 0) (hv' : f (-v) = 0 := by simp [hv]) : (transvection hv).symm = transvection hv' := by ext; simp [LinearEquiv.symm_apply_eq, comp_of_left_eq_apply hv'] theorem symm_eq' {f : Module.Dual R V} {v : V} (hf : f v = 0) (hf' : (-f) v = 0 := by simp [hf]) : (transvection hf).symm = transvection hf' := by ext; simp [LinearEquiv.symm_apply_eq, comp_of_right_eq_apply hf] end LinearEquiv.transvection
.lake/packages/mathlib/Mathlib/LinearAlgebra/Lagrange.lean
import Mathlib.Algebra.BigOperators.Group.Finset.Pi import Mathlib.Algebra.Polynomial.FieldDivision import Mathlib.LinearAlgebra.Vandermonde import Mathlib.RingTheory.Polynomial.Basic /-! # Lagrange interpolation ## Main definitions * In everything that follows, `s : Finset ι` is a finite set of indexes, with `v : ι → F` an indexing of the field over some type. We call the image of v on s the interpolation nodes, though strictly unique nodes are only defined when v is injective on s. * `Lagrange.basisDivisor x y`, with `x y : F`. These are the normalised irreducible factors of the Lagrange basis polynomials. They evaluate to `1` at `x` and `0` at `y` when `x` and `y` are distinct. * `Lagrange.basis v i` with `i : ι`: the Lagrange basis polynomial that evaluates to `1` at `v i` and `0` at `v j` for `i ≠ j`. * `Lagrange.interpolate v r` where `r : ι → F` is a function from the fintype to the field: the Lagrange interpolant that evaluates to `r i` at `x i` for all `i : ι`. The `r i` are the _values_ associated with the _nodes_`x i`. -/ open Polynomial section PolynomialDetermination namespace Polynomial variable {R : Type*} [CommRing R] [IsDomain R] {f g : R[X]} section Finset open Function Fintype open scoped Finset variable (s : Finset R) theorem eq_zero_of_degree_lt_of_eval_finset_eq_zero (degree_f_lt : f.degree < #s) (eval_f : ∀ x ∈ s, f.eval x = 0) : f = 0 := by rw [← mem_degreeLT] at degree_f_lt simp_rw [eval_eq_sum_degreeLTEquiv degree_f_lt] at eval_f rw [← degreeLTEquiv_eq_zero_iff_eq_zero degree_f_lt] exact Matrix.eq_zero_of_forall_index_sum_mul_pow_eq_zero (Injective.comp (Embedding.subtype _).inj' (equivFinOfCardEq (card_coe _)).symm.injective) fun _ => eval_f _ (Finset.coe_mem _) theorem eq_of_degree_sub_lt_of_eval_finset_eq (degree_fg_lt : (f - g).degree < #s) (eval_fg : ∀ x ∈ s, f.eval x = g.eval x) : f = g := by rw [← sub_eq_zero] refine eq_zero_of_degree_lt_of_eval_finset_eq_zero _ degree_fg_lt ?_ simp_rw [eval_sub, sub_eq_zero] exact eval_fg theorem eq_of_degrees_lt_of_eval_finset_eq (degree_f_lt : f.degree < #s) (degree_g_lt : g.degree < #s) (eval_fg : ∀ x ∈ s, f.eval x = g.eval x) : f = g := by rw [← mem_degreeLT] at degree_f_lt degree_g_lt refine eq_of_degree_sub_lt_of_eval_finset_eq _ ?_ eval_fg rw [← mem_degreeLT]; exact Submodule.sub_mem _ degree_f_lt degree_g_lt /-- Two polynomials, with the same degree and leading coefficient, which have the same evaluation on a set of distinct values with cardinality equal to the degree, are equal. -/ theorem eq_of_degree_le_of_eval_finset_eq (h_deg_le : f.degree ≤ #s) (h_deg_eq : f.degree = g.degree) (hlc : f.leadingCoeff = g.leadingCoeff) (h_eval : ∀ x ∈ s, f.eval x = g.eval x) : f = g := by rcases eq_or_ne f 0 with rfl | hf · rwa [degree_zero, eq_comm, degree_eq_bot, eq_comm] at h_deg_eq · exact eq_of_degree_sub_lt_of_eval_finset_eq s (lt_of_lt_of_le (degree_sub_lt h_deg_eq hf hlc) h_deg_le) h_eval end Finset section Indexed open Finset variable {ι : Type*} {v : ι → R} (s : Finset ι) theorem eq_zero_of_degree_lt_of_eval_index_eq_zero (hvs : Set.InjOn v s) (degree_f_lt : f.degree < #s) (eval_f : ∀ i ∈ s, f.eval (v i) = 0) : f = 0 := by classical rw [← card_image_of_injOn hvs] at degree_f_lt refine eq_zero_of_degree_lt_of_eval_finset_eq_zero _ degree_f_lt ?_ intro x hx rcases mem_image.mp hx with ⟨_, hj, rfl⟩ exact eval_f _ hj theorem eq_of_degree_sub_lt_of_eval_index_eq (hvs : Set.InjOn v s) (degree_fg_lt : (f - g).degree < #s) (eval_fg : ∀ i ∈ s, f.eval (v i) = g.eval (v i)) : f = g := by rw [← sub_eq_zero] refine eq_zero_of_degree_lt_of_eval_index_eq_zero _ hvs degree_fg_lt ?_ simp_rw [eval_sub, sub_eq_zero] exact eval_fg theorem eq_of_degrees_lt_of_eval_index_eq (hvs : Set.InjOn v s) (degree_f_lt : f.degree < #s) (degree_g_lt : g.degree < #s) (eval_fg : ∀ i ∈ s, f.eval (v i) = g.eval (v i)) : f = g := by refine eq_of_degree_sub_lt_of_eval_index_eq _ hvs ?_ eval_fg rw [← mem_degreeLT] at degree_f_lt degree_g_lt ⊢ exact Submodule.sub_mem _ degree_f_lt degree_g_lt theorem eq_of_degree_le_of_eval_index_eq (hvs : Set.InjOn v s) (h_deg_le : f.degree ≤ #s) (h_deg_eq : f.degree = g.degree) (hlc : f.leadingCoeff = g.leadingCoeff) (h_eval : ∀ i ∈ s, f.eval (v i) = g.eval (v i)) : f = g := by rcases eq_or_ne f 0 with rfl | hf · rwa [degree_zero, eq_comm, degree_eq_bot, eq_comm] at h_deg_eq · exact eq_of_degree_sub_lt_of_eval_index_eq s hvs (lt_of_lt_of_le (degree_sub_lt h_deg_eq hf hlc) h_deg_le) h_eval end Indexed end Polynomial end PolynomialDetermination noncomputable section namespace Lagrange open Polynomial section BasisDivisor variable {F : Type*} [Field F] variable {x y : F} /-- `basisDivisor x y` is the unique linear or constant polynomial such that when evaluated at `x` it gives `1` and `y` it gives `0` (where when `x = y` it is identically `0`). Such polynomials are the building blocks for the Lagrange interpolants. -/ def basisDivisor (x y : F) : F[X] := C (x - y)⁻¹ * (X - C y) theorem basisDivisor_self : basisDivisor x x = 0 := by simp only [basisDivisor, sub_self, inv_zero, map_zero, zero_mul] theorem basisDivisor_inj (hxy : basisDivisor x y = 0) : x = y := by simp_rw [basisDivisor, mul_eq_zero, X_sub_C_ne_zero, or_false, C_eq_zero, inv_eq_zero, sub_eq_zero] at hxy exact hxy @[simp] theorem basisDivisor_eq_zero_iff : basisDivisor x y = 0 ↔ x = y := ⟨basisDivisor_inj, fun H => H ▸ basisDivisor_self⟩ theorem basisDivisor_ne_zero_iff : basisDivisor x y ≠ 0 ↔ x ≠ y := by rw [Ne, basisDivisor_eq_zero_iff] theorem degree_basisDivisor_of_ne (hxy : x ≠ y) : (basisDivisor x y).degree = 1 := by rw [basisDivisor, degree_mul, degree_X_sub_C, degree_C, zero_add] exact inv_ne_zero (sub_ne_zero_of_ne hxy) @[simp] theorem degree_basisDivisor_self : (basisDivisor x x).degree = ⊥ := by rw [basisDivisor_self, degree_zero] theorem natDegree_basisDivisor_self : (basisDivisor x x).natDegree = 0 := by rw [basisDivisor_self, natDegree_zero] theorem natDegree_basisDivisor_of_ne (hxy : x ≠ y) : (basisDivisor x y).natDegree = 1 := natDegree_eq_of_degree_eq_some (degree_basisDivisor_of_ne hxy) @[simp] theorem eval_basisDivisor_right : eval y (basisDivisor x y) = 0 := by simp only [basisDivisor, eval_mul, eval_C, eval_sub, eval_X, sub_self, mul_zero] theorem eval_basisDivisor_left_of_ne (hxy : x ≠ y) : eval x (basisDivisor x y) = 1 := by simp only [basisDivisor, eval_mul, eval_C, eval_sub, eval_X] exact inv_mul_cancel₀ (sub_ne_zero_of_ne hxy) end BasisDivisor section Basis variable {F : Type*} [Field F] {ι : Type*} [DecidableEq ι] variable {s : Finset ι} {v : ι → F} {i j : ι} open Finset /-- Lagrange basis polynomials indexed by `s : Finset ι`, defined at nodes `v i` for a map `v : ι → F`. For `i, j ∈ s`, `basis s v i` evaluates to 0 at `v j` for `i ≠ j`. When `v` is injective on `s`, `basis s v i` evaluates to 1 at `v i`. -/ protected def basis (s : Finset ι) (v : ι → F) (i : ι) : F[X] := ∏ j ∈ s.erase i, basisDivisor (v i) (v j) @[simp] theorem basis_empty : Lagrange.basis ∅ v i = 1 := rfl @[simp] theorem basis_singleton (i : ι) : Lagrange.basis {i} v i = 1 := by rw [Lagrange.basis, erase_singleton, prod_empty] @[simp] theorem basis_pair_left (hij : i ≠ j) : Lagrange.basis {i, j} v i = basisDivisor (v i) (v j) := by simp only [Lagrange.basis, hij, erase_insert_eq_erase, erase_eq_of_notMem, mem_singleton, not_false_iff, prod_singleton] @[simp] theorem basis_pair_right (hij : i ≠ j) : Lagrange.basis {i, j} v j = basisDivisor (v j) (v i) := by rw [pair_comm] exact basis_pair_left hij.symm theorem basis_ne_zero (hvs : Set.InjOn v s) (hi : i ∈ s) : Lagrange.basis s v i ≠ 0 := by simp_rw [Lagrange.basis, prod_ne_zero_iff, Ne, mem_erase] rintro j ⟨hij, hj⟩ rw [basisDivisor_eq_zero_iff, hvs.eq_iff hi hj] exact hij.symm @[simp] theorem eval_basis_self (hvs : Set.InjOn v s) (hi : i ∈ s) : (Lagrange.basis s v i).eval (v i) = 1 := by rw [Lagrange.basis, eval_prod] refine prod_eq_one fun j H => ?_ rw [eval_basisDivisor_left_of_ne] rcases mem_erase.mp H with ⟨hij, hj⟩ exact mt (hvs hi hj) hij.symm @[simp] theorem eval_basis_of_ne (hij : i ≠ j) (hj : j ∈ s) : (Lagrange.basis s v i).eval (v j) = 0 := by simp_rw [Lagrange.basis, eval_prod, prod_eq_zero_iff] exact ⟨j, ⟨mem_erase.mpr ⟨hij.symm, hj⟩, eval_basisDivisor_right⟩⟩ @[simp] theorem natDegree_basis (hvs : Set.InjOn v s) (hi : i ∈ s) : (Lagrange.basis s v i).natDegree = #s - 1 := by have H : ∀ j, j ∈ s.erase i → basisDivisor (v i) (v j) ≠ 0 := by simp_rw [Ne, mem_erase, basisDivisor_eq_zero_iff] exact fun j ⟨hij₁, hj⟩ hij₂ => hij₁ (hvs hj hi hij₂.symm) rw [← card_erase_of_mem hi, card_eq_sum_ones] convert natDegree_prod _ _ H using 1 refine sum_congr rfl fun j hj => (natDegree_basisDivisor_of_ne ?_).symm rw [Ne, ← basisDivisor_eq_zero_iff] exact H _ hj theorem degree_basis (hvs : Set.InjOn v s) (hi : i ∈ s) : (Lagrange.basis s v i).degree = ↑(#s - 1) := by rw [degree_eq_natDegree (basis_ne_zero hvs hi), natDegree_basis hvs hi] theorem sum_basis (hvs : Set.InjOn v s) (hs : s.Nonempty) : ∑ j ∈ s, Lagrange.basis s v j = 1 := by refine eq_of_degrees_lt_of_eval_index_eq s hvs (lt_of_le_of_lt (degree_sum_le _ _) ?_) ?_ ?_ · rw [Nat.cast_withBot, Finset.sup_lt_iff (WithBot.bot_lt_coe #s)] intro i hi rw [degree_basis hvs hi, Nat.cast_withBot, WithBot.coe_lt_coe] exact Nat.pred_lt (card_ne_zero_of_mem hi) · rw [degree_one, ← WithBot.coe_zero, Nat.cast_withBot, WithBot.coe_lt_coe] exact Nonempty.card_pos hs · intro i hi rw [eval_finset_sum, eval_one, ← add_sum_erase _ _ hi, eval_basis_self hvs hi, add_eq_left] refine sum_eq_zero fun j hj => ?_ rcases mem_erase.mp hj with ⟨hij, _⟩ rw [eval_basis_of_ne hij hi] theorem basisDivisor_add_symm {x y : F} (hxy : x ≠ y) : basisDivisor x y + basisDivisor y x = 1 := by classical rw [← sum_basis Function.injective_id.injOn ⟨x, mem_insert_self _ {y}⟩, sum_insert (notMem_singleton.mpr hxy), sum_singleton, basis_pair_left hxy, basis_pair_right hxy, id, id] end Basis section Interpolate variable {F : Type*} [Field F] {ι : Type*} [DecidableEq ι] variable {s t : Finset ι} {i j : ι} {v : ι → F} (r r' : ι → F) open Finset /-- Lagrange interpolation: given a finset `s : Finset ι`, a nodal map `v : ι → F` injective on `s` and a value function `r : ι → F`, `interpolate s v r` is the unique polynomial of degree `< #s` that takes value `r i` on `v i` for all `i` in `s`. -/ @[simps] def interpolate (s : Finset ι) (v : ι → F) : (ι → F) →ₗ[F] F[X] where toFun r := ∑ i ∈ s, C (r i) * Lagrange.basis s v i map_add' f g := by simp_rw [← Finset.sum_add_distrib] have h : (fun x => C (f x) * Lagrange.basis s v x + C (g x) * Lagrange.basis s v x) = (fun x => C ((f + g) x) * Lagrange.basis s v x) := by simp_rw [← add_mul, ← C_add, Pi.add_apply] rw [h] map_smul' c f := by simp_rw [Finset.smul_sum, C_mul', smul_smul, Pi.smul_apply, RingHom.id_apply, smul_eq_mul] theorem interpolate_empty : interpolate ∅ v r = 0 := by rw [interpolate_apply, sum_empty] theorem interpolate_singleton : interpolate {i} v r = C (r i) := by rw [interpolate_apply, sum_singleton, basis_singleton, mul_one] theorem interpolate_one (hvs : Set.InjOn v s) (hs : s.Nonempty) : interpolate s v 1 = 1 := by simp_rw [interpolate_apply, Pi.one_apply, map_one, one_mul] exact sum_basis hvs hs theorem eval_interpolate_at_node (hvs : Set.InjOn v s) (hi : i ∈ s) : eval (v i) (interpolate s v r) = r i := by rw [interpolate_apply, eval_finset_sum, ← add_sum_erase _ _ hi] simp_rw [eval_mul, eval_C, eval_basis_self hvs hi, mul_one, add_eq_left] refine sum_eq_zero fun j H => ?_ rw [eval_basis_of_ne (mem_erase.mp H).1 hi, mul_zero] theorem degree_interpolate_le (hvs : Set.InjOn v s) : (interpolate s v r).degree ≤ ↑(#s - 1) := by refine (degree_sum_le _ _).trans ?_ rw [Finset.sup_le_iff] intro i hi rw [degree_mul, degree_basis hvs hi] by_cases hr : r i = 0 · simpa only [hr, map_zero, degree_zero, WithBot.bot_add] using bot_le · rw [degree_C hr, zero_add] theorem degree_interpolate_lt (hvs : Set.InjOn v s) : (interpolate s v r).degree < #s := by rw [Nat.cast_withBot] rcases eq_empty_or_nonempty s with (rfl | h) · rw [interpolate_empty, degree_zero, card_empty] exact WithBot.bot_lt_coe _ · refine lt_of_le_of_lt (degree_interpolate_le _ hvs) ?_ rw [Nat.cast_withBot, WithBot.coe_lt_coe] exact Nat.sub_lt (Nonempty.card_pos h) zero_lt_one theorem degree_interpolate_erase_lt (hvs : Set.InjOn v s) (hi : i ∈ s) : (interpolate (s.erase i) v r).degree < ↑(#s - 1) := by rw [← Finset.card_erase_of_mem hi] exact degree_interpolate_lt _ (Set.InjOn.mono (coe_subset.mpr (erase_subset _ _)) hvs) theorem values_eq_on_of_interpolate_eq (hvs : Set.InjOn v s) (hrr' : interpolate s v r = interpolate s v r') : ∀ i ∈ s, r i = r' i := fun _ hi => by rw [← eval_interpolate_at_node r hvs hi, hrr', eval_interpolate_at_node r' hvs hi] theorem interpolate_eq_of_values_eq_on (hrr' : ∀ i ∈ s, r i = r' i) : interpolate s v r = interpolate s v r' := sum_congr rfl fun i hi => by rw [hrr' _ hi] theorem interpolate_eq_iff_values_eq_on (hvs : Set.InjOn v s) : interpolate s v r = interpolate s v r' ↔ ∀ i ∈ s, r i = r' i := ⟨values_eq_on_of_interpolate_eq _ _ hvs, interpolate_eq_of_values_eq_on _ _⟩ theorem eq_interpolate {f : F[X]} (hvs : Set.InjOn v s) (degree_f_lt : f.degree < #s) : f = interpolate s v fun i => f.eval (v i) := eq_of_degrees_lt_of_eval_index_eq _ hvs degree_f_lt (degree_interpolate_lt _ hvs) fun _ hi => (eval_interpolate_at_node (fun x ↦ eval (v x) f) hvs hi).symm theorem eq_interpolate_of_eval_eq {f : F[X]} (hvs : Set.InjOn v s) (degree_f_lt : f.degree < #s) (eval_f : ∀ i ∈ s, f.eval (v i) = r i) : f = interpolate s v r := by rw [eq_interpolate hvs degree_f_lt] exact interpolate_eq_of_values_eq_on _ _ eval_f /-- This is the characteristic property of the interpolation: the interpolation is the unique polynomial of `degree < Fintype.card ι` which takes the value of the `r i` on the `v i`. -/ theorem eq_interpolate_iff {f : F[X]} (hvs : Set.InjOn v s) : (f.degree < #s ∧ ∀ i ∈ s, eval (v i) f = r i) ↔ f = interpolate s v r := by constructor <;> intro h · exact eq_interpolate_of_eval_eq _ hvs h.1 h.2 · rw [h] exact ⟨degree_interpolate_lt _ hvs, fun _ hi => eval_interpolate_at_node _ hvs hi⟩ /-- Lagrange interpolation induces isomorphism between functions from `s` and polynomials of degree less than `Fintype.card ι`. -/ def funEquivDegreeLT (hvs : Set.InjOn v s) : degreeLT F #s ≃ₗ[F] s → F where toFun f i := f.1.eval (v i) map_add' _ _ := funext fun _ => eval_add map_smul' c f := funext <| by simp invFun r := ⟨interpolate s v fun x => if hx : x ∈ s then r ⟨x, hx⟩ else 0, mem_degreeLT.2 <| degree_interpolate_lt _ hvs⟩ left_inv := by rintro ⟨f, hf⟩ simp only [Subtype.mk_eq_mk, dite_eq_ite] rw [mem_degreeLT] at hf conv => rhs; rw [eq_interpolate hvs hf] exact interpolate_eq_of_values_eq_on _ _ fun _ hi => if_pos hi right_inv := by intro f ext ⟨i, hi⟩ simp only [eval_interpolate_at_node _ hvs hi] exact dif_pos hi theorem interpolate_eq_sum_interpolate_insert_sdiff (hvt : Set.InjOn v t) (hs : s.Nonempty) (hst : s ⊆ t) : interpolate t v r = ∑ i ∈ s, interpolate (insert i (t \ s)) v r * Lagrange.basis s v i := by symm refine eq_interpolate_of_eval_eq _ hvt (lt_of_le_of_lt (degree_sum_le _ _) ?_) fun i hi => ?_ · simp_rw [Nat.cast_withBot, Finset.sup_lt_iff (WithBot.bot_lt_coe #t), degree_mul] intro i hi have hs : 1 ≤ #s := Nonempty.card_pos ⟨_, hi⟩ have hst' : #s ≤ #t := card_le_card hst have H : #t = 1 + (#t - #s) + (#s - 1) := by rw [add_assoc, tsub_add_tsub_cancel hst' hs, ← add_tsub_assoc_of_le (hs.trans hst'), Nat.succ_add_sub_one, zero_add] rw [degree_basis (Set.InjOn.mono hst hvt) hi, H, WithBot.coe_add, Nat.cast_withBot, WithBot.add_lt_add_iff_right (@WithBot.coe_ne_bot _ (#s - 1))] convert degree_interpolate_lt _ (hvt.mono (coe_subset.mpr (insert_subset_iff.mpr ⟨hst hi, sdiff_subset⟩))) rw [card_insert_of_notMem (notMem_sdiff_of_mem_right hi), card_sdiff_of_subset hst, add_comm] · simp_rw [eval_finset_sum, eval_mul] by_cases hi' : i ∈ s · rw [← add_sum_erase _ _ hi', eval_basis_self (hvt.mono hst) hi', eval_interpolate_at_node _ (hvt.mono (coe_subset.mpr (insert_subset_iff.mpr ⟨hi, sdiff_subset⟩))) (mem_insert_self _ _), mul_one, add_eq_left] refine sum_eq_zero fun j hj => ?_ rcases mem_erase.mp hj with ⟨hij, _⟩ rw [eval_basis_of_ne hij hi', mul_zero] · have H : (∑ j ∈ s, eval (v i) (Lagrange.basis s v j)) = 1 := by rw [← eval_finset_sum, sum_basis (hvt.mono hst) hs, eval_one] rw [← mul_one (r i), ← H, mul_sum] refine sum_congr rfl fun j hj => ?_ congr exact eval_interpolate_at_node _ (hvt.mono (insert_subset_iff.mpr ⟨hst hj, sdiff_subset⟩)) (mem_insert.mpr (Or.inr (mem_sdiff.mpr ⟨hi, hi'⟩))) theorem interpolate_eq_add_interpolate_erase (hvs : Set.InjOn v s) (hi : i ∈ s) (hj : j ∈ s) (hij : i ≠ j) : interpolate s v r = interpolate (s.erase j) v r * basisDivisor (v i) (v j) + interpolate (s.erase i) v r * basisDivisor (v j) (v i) := by rw [interpolate_eq_sum_interpolate_insert_sdiff _ hvs ⟨i, mem_insert_self i {j}⟩ _, sum_insert (notMem_singleton.mpr hij), sum_singleton, basis_pair_left hij, basis_pair_right hij, sdiff_insert_insert_of_mem_of_notMem hi (notMem_singleton.mpr hij), sdiff_singleton_eq_erase, pair_comm, sdiff_insert_insert_of_mem_of_notMem hj (notMem_singleton.mpr hij.symm), sdiff_singleton_eq_erase] exact insert_subset_iff.mpr ⟨hi, singleton_subset_iff.mpr hj⟩ end Interpolate section Nodal variable {R : Type*} [CommRing R] {ι : Type*} variable {s : Finset ι} {v : ι → R} open Finset Polynomial /-- `nodal s v` is the unique monic polynomial whose roots are the nodes defined by `v` and `s`. That is, the roots of `nodal s v` are exactly the image of `v` on `s`, with appropriate multiplicity. We can use `nodal` to define the barycentric forms of the evaluated interpolant. -/ def nodal (s : Finset ι) (v : ι → R) : R[X] := ∏ i ∈ s, (X - C (v i)) theorem nodal_eq (s : Finset ι) (v : ι → R) : nodal s v = ∏ i ∈ s, (X - C (v i)) := rfl @[simp] theorem nodal_empty : nodal ∅ v = 1 := by rfl @[simp] theorem natDegree_nodal [Nontrivial R] : (nodal s v).natDegree = #s := by simp_rw [nodal, natDegree_prod_of_monic (h := fun i _ => monic_X_sub_C (v i)), natDegree_X_sub_C, sum_const, smul_eq_mul, mul_one] theorem nodal_ne_zero [Nontrivial R] : nodal s v ≠ 0 := by rcases s.eq_empty_or_nonempty with (rfl | h) · exact one_ne_zero · apply ne_zero_of_natDegree_gt (n := 0) simp only [natDegree_nodal, h.card_pos] @[simp] theorem degree_nodal [Nontrivial R] : (nodal s v).degree = #s := by simp_rw [degree_eq_natDegree nodal_ne_zero, natDegree_nodal] theorem nodal_monic : (nodal s v).Monic := monic_prod_of_monic s (fun i ↦ X - C (v i)) fun i _ ↦ monic_X_sub_C (v i) theorem eval_nodal {x : R} : (nodal s v).eval x = ∏ i ∈ s, (x - v i) := by simp_rw [nodal, eval_prod, eval_sub, eval_X, eval_C] theorem eval_nodal_at_node {i : ι} (hi : i ∈ s) : eval (v i) (nodal s v) = 0 := by rw [eval_nodal] exact s.prod_eq_zero hi (sub_self (v i)) theorem eval_nodal_not_at_node [Nontrivial R] [NoZeroDivisors R] {x : R} (hx : ∀ i ∈ s, x ≠ v i) : eval x (nodal s v) ≠ 0 := by simp_rw [nodal, eval_prod, prod_ne_zero_iff, eval_sub, eval_X, eval_C, sub_ne_zero] exact hx theorem nodal_eq_mul_nodal_erase [DecidableEq ι] {i : ι} (hi : i ∈ s) : nodal s v = (X - C (v i)) * nodal (s.erase i) v := by simp_rw [nodal, Finset.mul_prod_erase _ (fun x => X - C (v x)) hi] theorem X_sub_C_dvd_nodal (v : ι → R) {i : ι} (hi : i ∈ s) : X - C (v i) ∣ nodal s v := by classical exact ⟨nodal (s.erase i) v, nodal_eq_mul_nodal_erase hi⟩ theorem nodal_insert_eq_nodal [DecidableEq ι] {i : ι} (hi : i ∉ s) : nodal (insert i s) v = (X - C (v i)) * nodal s v := by simp_rw [nodal, prod_insert hi] theorem derivative_nodal [DecidableEq ι] : derivative (nodal s v) = ∑ i ∈ s, nodal (s.erase i) v := by refine s.induction_on ?_ fun i t hit IH => ?_ · rw [nodal_empty, derivative_one, sum_empty] · rw [nodal_insert_eq_nodal hit, derivative_mul, IH, derivative_sub, derivative_X, derivative_C, sub_zero, one_mul, sum_insert hit, mul_sum, erase_insert hit, add_right_inj] refine sum_congr rfl fun j hjt => ?_ rw [t.erase_insert_of_ne (ne_of_mem_of_not_mem hjt hit).symm, nodal_insert_eq_nodal (mem_of_mem_erase.mt hit)] theorem eval_nodal_derivative_eval_node_eq [DecidableEq ι] {i : ι} (hi : i ∈ s) : eval (v i) (derivative (nodal s v)) = eval (v i) (nodal (s.erase i) v) := by rw [derivative_nodal, eval_finset_sum, ← add_sum_erase _ _ hi, add_eq_left] exact sum_eq_zero fun j hj => (eval_nodal_at_node (mem_erase.mpr ⟨(mem_erase.mp hj).1.symm, hi⟩)) /-- The vanishing polynomial on a multiplicative subgroup is of the form X ^ n - 1. -/ @[simp] theorem nodal_subgroup_eq_X_pow_card_sub_one [IsDomain R] (G : Subgroup Rˣ) [Fintype G] : nodal (G : Set Rˣ).toFinset ((↑) : Rˣ → R) = X ^ (Fintype.card G) - 1 := by have h : degree (1 : R[X]) < degree ((X : R[X]) ^ Fintype.card G) := by simp [Fintype.card_pos] apply eq_of_degree_le_of_eval_index_eq (v := ((↑) : Rˣ → R)) (G : Set Rˣ).toFinset · exact Units.val_injective.injOn · simp · rw [degree_sub_eq_left_of_degree_lt h, degree_nodal, Set.toFinset_card, degree_pow, degree_X, nsmul_eq_mul, mul_one, Nat.cast_inj] exact rfl · rw [nodal_monic, leadingCoeff_sub_of_degree_lt h, monic_X_pow] · intro i hi rw [eval_nodal_at_node hi] replace hi : i ∈ G := by simpa using hi obtain ⟨g, rfl⟩ : ∃ g : G, g.val = i := ⟨⟨i, hi⟩, rfl⟩ simp [← Units.val_pow_eq_pow_val, ← Subgroup.coe_pow G] end Nodal section NodalWeight variable {F : Type*} [Field F] {ι : Type*} [DecidableEq ι] variable {s : Finset ι} {v : ι → F} {i : ι} open Finset /-- This defines the nodal weight for a given set of node indexes and node mapping function `v`. -/ def nodalWeight (s : Finset ι) (v : ι → F) (i : ι) := ∏ j ∈ s.erase i, (v i - v j)⁻¹ theorem nodalWeight_eq_eval_nodal_erase_inv : nodalWeight s v i = (eval (v i) (nodal (s.erase i) v))⁻¹ := by rw [eval_nodal, nodalWeight, prod_inv_distrib] theorem nodal_erase_eq_nodal_div (hi : i ∈ s) : nodal (s.erase i) v = nodal s v / (X - C (v i)) := by rw [nodal_eq_mul_nodal_erase hi, mul_div_cancel_left₀] exact X_sub_C_ne_zero _ theorem nodalWeight_eq_eval_derivative_nodal (hi : i ∈ s) : nodalWeight s v i = (eval (v i) (Polynomial.derivative (nodal s v)))⁻¹ := by rw [eval_nodal_derivative_eval_node_eq hi, nodalWeight_eq_eval_nodal_erase_inv] @[deprecated (since := "2025-07-08")] alias nodalWeight_eq_eval_nodal_derative := nodalWeight_eq_eval_derivative_nodal theorem nodalWeight_ne_zero (hvs : Set.InjOn v s) (hi : i ∈ s) : nodalWeight s v i ≠ 0 := by rw [nodalWeight, prod_ne_zero_iff] intro j hj rcases mem_erase.mp hj with ⟨hij, hj⟩ exact inv_ne_zero (sub_ne_zero_of_ne (mt (hvs.eq_iff hi hj).mp hij.symm)) end NodalWeight section LagrangeBarycentric variable {F : Type*} [Field F] {ι : Type*} [DecidableEq ι] variable {s : Finset ι} {v : ι → F} (r : ι → F) {i : ι} {x : F} open Finset theorem basis_eq_prod_sub_inv_mul_nodal_div (hi : i ∈ s) : Lagrange.basis s v i = C (nodalWeight s v i) * (nodal s v / (X - C (v i))) := by simp_rw [Lagrange.basis, basisDivisor, nodalWeight, prod_mul_distrib, map_prod, ← nodal_erase_eq_nodal_div hi, nodal] theorem eval_basis_not_at_node (hi : i ∈ s) (hxi : x ≠ v i) : eval x (Lagrange.basis s v i) = eval x (nodal s v) * (nodalWeight s v i * (x - v i)⁻¹) := by rw [mul_comm, basis_eq_prod_sub_inv_mul_nodal_div hi, eval_mul, eval_C, ← nodal_erase_eq_nodal_div hi, eval_nodal, eval_nodal, mul_assoc, ← mul_prod_erase _ _ hi, ← mul_assoc (x - v i)⁻¹, inv_mul_cancel₀ (sub_ne_zero_of_ne hxi), one_mul] theorem interpolate_eq_nodalWeight_mul_nodal_div_X_sub_C : interpolate s v r = ∑ i ∈ s, C (nodalWeight s v i) * (nodal s v / (X - C (v i))) * C (r i) := sum_congr rfl fun j hj => by rw [mul_comm, basis_eq_prod_sub_inv_mul_nodal_div hj] /-- This is the first barycentric form of the Lagrange interpolant. -/ theorem eval_interpolate_not_at_node (hx : ∀ i ∈ s, x ≠ v i) : eval x (interpolate s v r) = eval x (nodal s v) * ∑ i ∈ s, nodalWeight s v i * (x - v i)⁻¹ * r i := by simp_rw [interpolate_apply, mul_sum, eval_finset_sum, eval_mul, eval_C] refine sum_congr rfl fun i hi => ?_ rw [← mul_assoc, mul_comm, eval_basis_not_at_node hi (hx _ hi)] theorem sum_nodalWeight_mul_inv_sub_ne_zero (hvs : Set.InjOn v s) (hx : ∀ i ∈ s, x ≠ v i) (hs : s.Nonempty) : (∑ i ∈ s, nodalWeight s v i * (x - v i)⁻¹) ≠ 0 := @right_ne_zero_of_mul_eq_one _ _ _ (eval x (nodal s v)) _ <| by simpa only [Pi.one_apply, interpolate_one hvs hs, eval_one, mul_one] using (eval_interpolate_not_at_node 1 hx).symm /-- This is the second barycentric form of the Lagrange interpolant. -/ theorem eval_interpolate_not_at_node' (hvs : Set.InjOn v s) (hs : s.Nonempty) (hx : ∀ i ∈ s, x ≠ v i) : eval x (interpolate s v r) = (∑ i ∈ s, nodalWeight s v i * (x - v i)⁻¹ * r i) / ∑ i ∈ s, nodalWeight s v i * (x - v i)⁻¹ := by rw [← div_one (eval x (interpolate s v r)), ← @eval_one _ _ x, ← interpolate_one hvs hs, eval_interpolate_not_at_node r hx, eval_interpolate_not_at_node 1 hx] simp only [mul_div_mul_left _ _ (eval_nodal_not_at_node hx), Pi.one_apply, mul_one] end LagrangeBarycentric end Lagrange
.lake/packages/mathlib/Mathlib/LinearAlgebra/Vandermonde.lean
import Mathlib.Data.Nat.Factorial.BigOperators import Mathlib.Data.Nat.Factorial.SuperFactorial import Mathlib.LinearAlgebra.Matrix.Block import Mathlib.LinearAlgebra.Matrix.Nondegenerate import Mathlib.RingTheory.Localization.FractionRing import Mathlib.RingTheory.Polynomial.Pochhammer /-! # Vandermonde matrix This file defines the `vandermonde` matrix and gives its determinant. For each `CommRing R`, and function `v : Fin n → R` the matrix `vandermonde v` is defined to be `Fin n` by `Fin n` matrix `V` whose `i`th row is `[1, (v i), (v i)^2, ...]`. This matrix has determinant equal to the product of `v i - v j` over all unordered pairs `i,j`, and therefore is nonsingular if and only if `v` is injective. `vandermonde v` is a special case of two more general matrices we also define. For a type `α` and functions `v w : α → R`, we write `rectVandermonde v w n` for the `α × Fin n` matrix with `i`th row `[(w i) ^ (n-1), (v i) * (w i)^(n-2), ..., (v i)^(n-1)]`. `projVandermonde v w = rectVandermonde v w n` is the square matrix case, where `α = Fin n`. The determinant of `projVandermonde v w` is the product of `v j * w i - v i * w j`, taken over all pairs `i,j` with `i < j`, which gives a similar characterization of when it is nonsingular. Since `vandermonde v w = projVandermonde v 1`, we can derive most of the API for the former in terms of the latter. These extensions of Vandermonde matrices arise in the study of complete arcs in finite geometry, coding theory, and representations of uniform matroids over finite fields. ## Main definitions * `vandermonde v`: a square matrix with the `i, j`th entry equal to `v i ^ j`. * `rectVandermonde v w n`: an `α × Fin n` matrix whose `i, j`-th entry is `(v i) ^ j * (w i) ^ (n-1-j)`. * `projVandermonde v w`: a square matrix whose `i, j`-th entry is `(v i) ^ j * (w i) ^ (n-1-j)`. ## Main results * `det_vandermonde`: `det (vandermonde v)` is the product of `v j - v i`, where `(i, j)` ranges over the set of pairs with `i < j`. * `det_projVandermonde`: `det (projVandermonde v w)` is the product of `v j * w i - v i * w j`, taken over all pairs with `i < j`. ## Implementation notes We derive the `det_vandermonde` formula from `det_projVandermonde`, which is proved using an induction argument involving row operations and division. To circumvent issues with non-invertible elements while still maintaining the generality of rings, we first prove it for fields using the private lemma `det_projVandermonde_of_field`, and then use an algebraic workaround to generalize to the ring case, stating the strictly more general form as `det_projVandermonde`. ## TODO Characterize when `rectVandermonde v w n` has linearly independent rows. -/ variable {R K : Type*} [CommRing R] [Field K] {n : ℕ} open Equiv Finset open Matrix Fin namespace Matrix /-- A matrix with rows all having the form `[b^(n-1), a * b^(n-2), ..., a ^ (n-1)]` -/ def rectVandermonde {α : Type*} (v w : α → R) (n : ℕ) : Matrix α (Fin n) R := .of fun i j ↦ (v i) ^ j.1 * (w i) ^ j.rev.1 /-- A square matrix with rows all having the form `[b^(n-1), a * b^(n-2), ..., a ^ (n-1)]` -/ def projVandermonde (v w : Fin n → R) : Matrix (Fin n) (Fin n) R := rectVandermonde v w n /-- `vandermonde v` is the square matrix with `i`th row equal to `1, v i, v i ^ 2, v i ^ 3, ...`. -/ def vandermonde (v : Fin n → R) : Matrix (Fin n) (Fin n) R := .of fun i j ↦ (v i) ^ j.1 lemma vandermonde_eq_projVandermonde (v : Fin n → R) : vandermonde v = projVandermonde v 1 := by simp [projVandermonde, rectVandermonde, vandermonde] /-- We don't mark this as `@[simp]` because the RHS is not simp-nf, and simplifying the RHS gives a bothersome `Nat` subtraction. -/ theorem projVandermonde_apply {v w : Fin n → R} {i j : Fin n} : projVandermonde v w i j = (v i) ^ j.1 * (w i) ^ j.rev.1 := rfl theorem rectVandermonde_apply {α : Type*} {v w : α → R} {i : α} {j : Fin n} : rectVandermonde v w n i j = (v i) ^ j.1 * (w i) ^ j.rev.1 := rfl @[simp] theorem vandermonde_apply (v : Fin n → R) (i j) : vandermonde v i j = v i ^ (j : ℕ) := rfl @[simp] theorem vandermonde_cons (v0 : R) (v : Fin n → R) : vandermonde (Fin.cons v0 v : Fin n.succ → R) = Fin.cons (fun (j : Fin n.succ) => v0 ^ (j : ℕ)) fun i => Fin.cons 1 fun j => v i * vandermonde v i j := by ext i j refine Fin.cases (by simp) (fun i => ?_) i refine Fin.cases (by simp) (fun j => ?_) j simp [pow_succ'] theorem vandermonde_succ (v : Fin n.succ → R) : vandermonde v = .of Fin.cons (fun (j : Fin n.succ) => v 0 ^ (j : ℕ)) fun i => Fin.cons 1 fun j => v i.succ * vandermonde (Fin.tail v) i j := by conv_lhs => rw [← Fin.cons_self_tail v, vandermonde_cons] rfl theorem vandermonde_mul_vandermonde_transpose (v w : Fin n → R) (i j) : (vandermonde v * (vandermonde w)ᵀ) i j = ∑ k : Fin n, (v i * w j) ^ (k : ℕ) := by simp only [vandermonde_apply, Matrix.mul_apply, Matrix.transpose_apply, mul_pow] theorem vandermonde_transpose_mul_vandermonde (v : Fin n → R) (i j) : ((vandermonde v)ᵀ * vandermonde v) i j = ∑ k : Fin n, v k ^ (i + j : ℕ) := by simp only [vandermonde_apply, Matrix.mul_apply, Matrix.transpose_apply, pow_add] theorem rectVandermonde_apply_zero_right {α : Type*} {v w : α → R} {i : α} (hw : w i = 0) : rectVandermonde v w (n + 1) i = Pi.single (Fin.last n) ((v i) ^ n) := by ext j obtain rfl | hlt := j.le_last.eq_or_lt · simp [rectVandermonde_apply] rw [rectVandermonde_apply, Pi.single_eq_of_ne hlt.ne, hw, zero_pow, mul_zero] simpa [Nat.sub_eq_zero_iff_le] using hlt theorem projVandermonde_apply_of_ne_zero {v w : Fin (n + 1) → K} {i j : Fin (n + 1)} (hw : w i ≠ 0) : projVandermonde v w i j = (v i) ^ j.1 * (w i) ^ n / (w i) ^ j.1 := by rw [projVandermonde_apply, eq_div_iff (by simp [hw]), mul_assoc, ← pow_add, rev_add_cast] theorem projVandermonde_apply_zero_right {v w : Fin (n + 1) → R} {i : Fin (n + 1)} (hw : w i = 0) : projVandermonde v w i = Pi.single (Fin.last n) ((v i) ^ n) := by ext j obtain rfl | hlt := j.le_last.eq_or_lt · simp [projVandermonde_apply] rw [projVandermonde_apply, Pi.single_eq_of_ne hlt.ne, hw, zero_pow, mul_zero] simpa [Nat.sub_eq_zero_iff_le] using hlt theorem projVandermonde_comp {v w : Fin n → R} (f : Fin n → Fin n) : projVandermonde (v ∘ f) (w ∘ f) = (projVandermonde v w).submatrix f id := rfl theorem projVandermonde_map {R' : Type*} [CommRing R'] (φ : R →+* R') (v w : Fin n → R) : projVandermonde (fun i ↦ φ (v i)) (fun i ↦ φ (w i)) = φ.mapMatrix (projVandermonde v w) := by ext i j simp [projVandermonde_apply] private theorem det_projVandermonde_of_field (v w : Fin n → K) : (projVandermonde v w).det = ∏ i : Fin n, ∏ j ∈ Finset.Ioi i, (v j * w i - v i * w j) := by induction n with | zero => simp | succ n ih => /- We can assume not all `w i` are zero, and therefore that `w 0 ≠ 0`, since otherwise we can swap row `0` with another nonzero row. -/ wlog h0 : w 0 ≠ 0 generalizing v w with aux · obtain h0' | ⟨i₀, hi₀ : w i₀ ≠ 0⟩ := forall_or_exists_not (w · = 0) · obtain rfl | hne := eq_or_ne n 0 · simp [projVandermonde_apply] rw [det_eq_zero_of_column_eq_zero 0 (fun i ↦ by simpa [projVandermonde_apply, h0']), Finset.prod_sigma', Finset.prod_eq_zero (i := ⟨0, Fin.last n⟩) (by simpa) (by simp [h0'])] rw [← mul_right_inj' (a := ((Equiv.swap 0 i₀).sign : K)) (by simp [show 0 ≠ i₀ by rintro rfl; contradiction]), ← det_permute, ← projVandermonde_comp, aux _ _ (by simpa), ← (Equiv.swap 0 i₀).prod_Ioi_comp_eq_sign_mul_prod (by simp)] rfl /- Let `W` be obtained from the matrix by subtracting `r = (v 0) / (w 0)` times each column from the next column, starting from the penultimate column. This doesn't change the determinant.-/ set r := v 0 / w 0 with hr set W : Matrix (Fin (n + 1)) (Fin (n + 1)) K := .of fun i ↦ (cons (projVandermonde v w i 0) (fun j ↦ projVandermonde v w i j.succ - r * projVandermonde v w i j.castSucc)) -- deleting the first row and column of `W` gives a row-scaling of a Vandermonde matrix. have hW_eq : (W.submatrix succ succ) = .of fun i j ↦ (v (succ i) - r * w (succ i)) * projVandermonde (v ∘ succ) (w ∘ succ) i j := by ext i j simp only [projVandermonde_apply, val_zero, rev_zero, val_last, val_succ, coe_castSucc, submatrix_apply, Function.comp_apply, rev_succ, W, r, rev_castSucc] simp ring /- The first row of `W` is `[(w 0)^n, 0, ..., 0]` - take a cofactor expansion along this row, and apply induction. -/ rw [det_eq_of_forall_col_eq_smul_add_pred (B := W) (c := fun _ ↦ r) (by simp [W]) (fun i j ↦ by simp [W, r, projVandermonde_apply]), det_succ_row_zero, Finset.sum_eq_single 0 _ (by simp)] · rw [succAbove_zero, hW_eq, det_mul_column, ih] simp only [Nat.succ_eq_add_one, coe_ofNat_eq_mod, Nat.zero_mod, pow_zero, show W 0 0 = w 0 ^ n by simp [W, projVandermonde_apply], one_mul, hr] field_simp simp only [Finset.prod_div_distrib, Finset.prod_const, Finset.card_fin, Function.comp_apply] field_simp simp only [prod_univ_succ, Ioi_zero_eq_map, Finset.prod_map, coe_succEmb, prod_Ioi_succ] intro j _ hj0 obtain ⟨j, rfl⟩ := j.eq_succ_of_ne_zero hj0 rw [mul_eq_zero, mul_eq_zero] refine .inl (.inr ?_) simp only [of_apply, projVandermonde_apply_of_ne_zero h0, val_succ, coe_castSucc, cons_succ, W, r] ring /-- The formula for the determinant of a projective Vandermonde matrix. -/ theorem det_projVandermonde (v w : Fin n → R) : (projVandermonde v w).det = ∏ i : Fin n, ∏ j ∈ Finset.Ioi i, (v j * w i - v i * w j) := by let u (b : Bool) (i : Fin n) := (algebraMap (MvPolynomial (Fin n × Bool) ℤ) (FractionRing (MvPolynomial (Fin n × Bool) ℤ))) (MvPolynomial.X ⟨i, b⟩) have hdet := det_projVandermonde_of_field (u true) (u false) simp only [u] at hdet norm_cast at hdet rw [projVandermonde_map, ← RingHom.map_det, IsFractionRing.coe_inj] at hdet apply_fun MvPolynomial.eval₂Hom (Int.castRingHom R) (fun x ↦ (if x.2 then v else w) x.1) at hdet rw [RingHom.map_det] at hdet convert hdet <;> simp [← Matrix.ext_iff, projVandermonde_apply] /-- The formula for the determinant of a Vandermonde matrix. -/ theorem det_vandermonde (v : Fin n → R) : det (vandermonde v) = ∏ i : Fin n, ∏ j ∈ Ioi i, (v j - v i) := by simp [vandermonde_eq_projVandermonde, det_projVandermonde] theorem det_vandermonde_eq_zero_iff [IsDomain R] {v : Fin n → R} : det (vandermonde v) = 0 ↔ ∃ i j : Fin n, v i = v j ∧ i ≠ j := by constructor · simp only [det_vandermonde v, Finset.prod_eq_zero_iff, sub_eq_zero, forall_exists_index] rintro i ⟨_, j, h₁, h₂⟩ exact ⟨j, i, h₂, (mem_Ioi.mp h₁).ne'⟩ · simp only [Ne, forall_exists_index, and_imp] refine fun i j h₁ h₂ => Matrix.det_zero_of_row_eq h₂ (funext fun k => ?_) rw [vandermonde_apply, vandermonde_apply, h₁] theorem det_vandermonde_ne_zero_iff [IsDomain R] {v : Fin n → R} : det (vandermonde v) ≠ 0 ↔ Function.Injective v := by unfold Function.Injective simp only [det_vandermonde_eq_zero_iff, Ne, not_exists, not_and, Classical.not_not] @[simp] theorem det_vandermonde_add (v : Fin n → R) (a : R) : (Matrix.vandermonde fun i ↦ v i + a).det = (Matrix.vandermonde v).det := by simp [Matrix.det_vandermonde] @[simp] theorem det_vandermonde_sub (v : Fin n → R) (a : R) : (Matrix.vandermonde fun i ↦ v i - a).det = (Matrix.vandermonde v).det := by rw [← det_vandermonde_add v (-a)] simp only [← sub_eq_add_neg] theorem eq_zero_of_forall_index_sum_pow_mul_eq_zero [IsDomain R] {f v : Fin n → R} (hf : Function.Injective f) (hfv : ∀ j, (∑ i : Fin n, f j ^ (i : ℕ) * v i) = 0) : v = 0 := eq_zero_of_mulVec_eq_zero (det_vandermonde_ne_zero_iff.mpr hf) (funext hfv) theorem eq_zero_of_forall_index_sum_mul_pow_eq_zero [IsDomain R] {f v : Fin n → R} (hf : Function.Injective f) (hfv : ∀ j, (∑ i, v i * f j ^ (i : ℕ)) = 0) : v = 0 := by apply eq_zero_of_forall_index_sum_pow_mul_eq_zero hf simp_rw [mul_comm] exact hfv theorem eq_zero_of_forall_pow_sum_mul_pow_eq_zero [IsDomain R] {f v : Fin n → R} (hf : Function.Injective f) (hfv : ∀ i : Fin n, (∑ j : Fin n, v j * f j ^ (i : ℕ)) = 0) : v = 0 := eq_zero_of_vecMul_eq_zero (det_vandermonde_ne_zero_iff.mpr hf) (funext hfv) open Polynomial theorem eval_matrixOfPolynomials_eq_vandermonde_mul_matrixOfPolynomials (v : Fin n → R) (p : Fin n → R[X]) (h_deg : ∀ i, (p i).natDegree ≤ i) : Matrix.of (fun i j => ((p j).eval (v i))) = (Matrix.vandermonde v) * (Matrix.of (fun (i j : Fin n) => (p j).coeff i)) := by ext i j simp_rw [Matrix.mul_apply, eval, Matrix.of_apply, eval₂] simp only [Matrix.vandermonde] have : (p j).support ⊆ range n := supp_subset_range <| Nat.lt_of_le_of_lt (h_deg j) <| Fin.prop j rw [sum_eq_of_subset _ (fun j => zero_mul ((v i) ^ j)) this, ← Fin.sum_univ_eq_sum_range] congr ext k rw [mul_comm, Matrix.of_apply, RingHom.id_apply] theorem det_eval_matrixOfPolynomials_eq_det_vandermonde (v : Fin n → R) (p : Fin n → R[X]) (h_deg : ∀ i, (p i).natDegree = i) (h_monic : ∀ i, Monic <| p i) : (Matrix.vandermonde v).det = (Matrix.of (fun i j => ((p j).eval (v i)))).det := by rw [Matrix.eval_matrixOfPolynomials_eq_vandermonde_mul_matrixOfPolynomials v p (fun i ↦ Nat.le_of_eq (h_deg i)), Matrix.det_mul, Matrix.det_matrixOfPolynomials p h_deg h_monic, mul_one] lemma det_vandermonde_id_eq_superFactorial (n : ℕ) : (vandermonde fun i : Fin (n + 1) ↦ (i : R)).det = n.superFactorial := by induction n with | zero => simp | succ n hn => rw [Nat.superFactorial, det_vandermonde, Fin.prod_univ_succAbove _ 0] push_cast congr · simp only [Fin.val_zero, Nat.cast_zero, sub_zero] norm_cast simp [Fin.prod_univ_eq_prod_range (fun i ↦ (↑i + 1)) (n + 1)] · rw [det_vandermonde] at hn simp [hn] private lemma of_eval_descPochhammer_eq_mul_of_choose {n : ℕ} (v : Fin n → ℕ) : (of fun i j : Fin n => (descPochhammer ℤ j).eval (v i : ℤ)).det = (∏ i : Fin n, Nat.factorial i) * (of fun i j : Fin n => (Nat.choose (v i) j : ℤ)).det := by convert det_mul_row (fun (i : Fin n) => ((Nat.factorial (i : ℕ)) : ℤ)) _ · rw [of_apply, descPochhammer_eval_eq_descFactorial ℤ _ _] congr exact Nat.descFactorial_eq_factorial_mul_choose _ _ · rw [Nat.cast_prod] lemma superFactorial_dvd_vandermonde_det {n : ℕ} (v : Fin (n + 1) → ℤ) : ↑n.superFactorial ∣ (vandermonde v).det := by let m := inf' univ ⟨0, mem_univ _⟩ v let w' := fun i ↦ (v i - m).toNat have hw' : ∀ i, (w' i : ℤ) = v i - m := fun i ↦ Int.toNat_sub_of_le (inf'_le _ (mem_univ _)) have h := det_eval_matrixOfPolynomials_eq_det_vandermonde (fun i ↦ ↑(w' i)) (fun i => descPochhammer ℤ i) (fun i => descPochhammer_natDegree ℤ i) (fun i => monic_descPochhammer ℤ i) conv_lhs at h => simp only [hw', det_vandermonde_sub] use (of (fun (i j : Fin (n + 1)) => (Nat.choose (w' i) (j : ℕ) : ℤ))).det simp [h, of_eval_descPochhammer_eq_mul_of_choose w', Fin.prod_univ_eq_prod_range] end Matrix
.lake/packages/mathlib/Mathlib/LinearAlgebra/StdBasis.lean
import Mathlib.Algebra.Algebra.Pi import Mathlib.LinearAlgebra.Finsupp.VectorSpace import Mathlib.LinearAlgebra.FreeModule.Basic import Mathlib.LinearAlgebra.LinearIndependent.Lemmas /-! # The standard basis This file defines the standard basis `Pi.basis (s : ∀ j, Basis (ι j) R (M j))`, which is the `Σ j, ι j`-indexed basis of `Π j, M j`. The basis vectors are given by `Pi.basis s ⟨j, i⟩ j' = Pi.single j' (s j) i = if j = j' then s i else 0`. The standard basis on `R^η`, i.e. `η → R` is called `Pi.basisFun`. To give a concrete example, `Pi.single (i : Fin 3) (1 : R)` gives the `i`th unit basis vector in `R³`, and `Pi.basisFun R (Fin 3)` proves this is a basis over `Fin 3 → R`. ## Main definitions - `Pi.basis s`: given a basis `s i` for each `M i`, the standard basis on `Π i, M i` - `Pi.basisFun R η`: the standard basis on `R^η`, i.e. `η → R`, given by `Pi.basisFun R η i j = Pi.single i 1 j = if i = j then 1 else 0`. - `Matrix.stdBasis R n m`: the standard basis on `Matrix n m R`, given by `Matrix.stdBasis R n m (i, j) i' j' = if (i, j) = (i', j') then 1 else 0`. -/ open Function Module Set Submodule namespace Pi open LinearMap open Set variable {R : Type*} section Module variable {η : Type*} {ιs : η → Type*} {Ms : η → Type*} theorem linearIndependent_single [Semiring R] [∀ i, AddCommMonoid (Ms i)] [∀ i, Module R (Ms i)] [DecidableEq η] (v : ∀ j, ιs j → Ms j) (hs : ∀ i, LinearIndependent R (v i)) : LinearIndependent R fun ji : Σ j, ιs j ↦ Pi.single ji.1 (v ji.1 ji.2) := by convert (DFinsupp.linearIndependent_single _ hs).map_injOn _ DFinsupp.injective_pi_lapply.injOn theorem linearIndependent_single_one (ι R : Type*) [Semiring R] [DecidableEq ι] : LinearIndependent R (fun i : ι ↦ Pi.single i (1 : R)) := by rw [← linearIndependent_equiv (Equiv.sigmaPUnit ι)] exact Pi.linearIndependent_single (fun (_ : ι) (_ : Unit) ↦ (1 : R)) <| by simp +contextual [Fintype.linearIndependent_iffₛ] lemma linearIndependent_single_of_ne_zero {ι R M : Type*} [Ring R] [AddCommGroup M] [Module R M] [NoZeroSMulDivisors R M] [DecidableEq ι] {v : ι → M} (hv : ∀ i, v i ≠ 0) : LinearIndependent R fun i : ι ↦ Pi.single i (v i) := by rw [← linearIndependent_equiv (Equiv.sigmaPUnit ι)] exact linearIndependent_single (fun i (_ : Unit) ↦ v i) <| by simp +contextual [Fintype.linearIndependent_iff, hv] variable [Semiring R] [∀ i, AddCommMonoid (Ms i)] [∀ i, Module R (Ms i)] section Fintype variable [Fintype η] open LinearEquiv /-- `Pi.basis (s : ∀ j, Basis (ιs j) R (Ms j))` is the `Σ j, ιs j`-indexed basis on `Π j, Ms j` given by `s j` on each component. For the standard basis over `R` on the finite-dimensional space `η → R` see `Pi.basisFun`. -/ protected noncomputable def basis (s : ∀ j, Basis (ιs j) R (Ms j)) : Basis (Σ j, ιs j) R (∀ j, Ms j) := Basis.ofRepr ((LinearEquiv.piCongrRight fun j => (s j).repr) ≪≫ₗ (Finsupp.sigmaFinsuppLEquivPiFinsupp R).symm) @[simp] theorem basis_repr_single [DecidableEq η] (s : ∀ j, Basis (ιs j) R (Ms j)) (j i) : (Pi.basis s).repr (Pi.single j (s j i)) = Finsupp.single ⟨j, i⟩ 1 := by classical ext ⟨j', i'⟩ by_cases hj : j = j' · subst hj simp only [Pi.basis, LinearEquiv.trans_apply, LinearEquiv.piCongrRight, Finsupp.sigmaFinsuppLEquivPiFinsupp_symm_apply, Basis.repr_symm_apply, LinearEquiv.coe_mk] symm simp [Finsupp.single_apply] simp only [Pi.basis, LinearEquiv.trans_apply, Finsupp.sigmaFinsuppLEquivPiFinsupp_symm_apply, LinearEquiv.piCongrRight] dsimp rw [Pi.single_eq_of_ne (Ne.symm hj), LinearEquiv.map_zero, Finsupp.zero_apply, Finsupp.single_eq_of_ne] rintro ⟨⟩ contradiction @[simp] theorem basis_apply [DecidableEq η] (s : ∀ j, Basis (ιs j) R (Ms j)) (ji) : Pi.basis s ji = Pi.single ji.1 (s ji.1 ji.2) := Basis.apply_eq_iff.mpr (by simp) @[simp] theorem basis_repr (s : ∀ j, Basis (ιs j) R (Ms j)) (x) (ji) : (Pi.basis s).repr x ji = (s ji.1).repr (x ji.1) ji.2 := rfl end Fintype section variable [Finite η] variable (R η) /-- The basis on `η → R` where the `i`th basis vector is `Function.update 0 i 1`. -/ noncomputable def basisFun : Basis η R (η → R) := Basis.ofEquivFun (LinearEquiv.refl _ _) @[simp] theorem basisFun_apply [DecidableEq η] (i) : basisFun R η i = Pi.single i 1 := by simp only [basisFun, Basis.coe_ofEquivFun, LinearEquiv.refl_symm, LinearEquiv.refl_apply] @[simp] theorem basisFun_repr (x : η → R) (i : η) : (Pi.basisFun R η).repr x i = x i := by simp [basisFun] @[simp] theorem basisFun_equivFun : (Pi.basisFun R η).equivFun = LinearEquiv.refl _ _ := Basis.equivFun_ofEquivFun _ end end Module end Pi /-- Let `k` be an integral domain and `G` an arbitrary finite set. Then any algebra morphism `φ : (G → k) →ₐ[k] k` is an evaluation map. -/ lemma AlgHom.eq_piEvalAlgHom {k G : Type*} [CommSemiring k] [NoZeroDivisors k] [Nontrivial k] [Finite G] (φ : (G → k) →ₐ[k] k) : ∃ (s : G), φ = Pi.evalAlgHom _ _ s := by have h1 := map_one φ classical have := Fintype.ofFinite G simp only [← Finset.univ_sum_single (1 : G → k), Pi.one_apply, map_sum] at h1 obtain ⟨s, hs⟩ : ∃ (s : G), φ (Pi.single s 1) ≠ 0 := by by_contra simp_all have h2 : ∀ t ≠ s, φ (Pi.single t 1) = 0 := by refine fun _ _ ↦ (eq_zero_or_eq_zero_of_mul_eq_zero ?_).resolve_left hs rw [← map_mul] convert map_zero φ ext u by_cases u = s <;> simp_all have h3 : φ (Pi.single s 1) = 1 := by rwa [Fintype.sum_eq_single s h2] at h1 use s refine AlgHom.toLinearMap_injective ((Pi.basisFun k G).ext fun t ↦ ?_) by_cases t = s <;> simp_all namespace Module variable (ι R M N : Type*) [Finite ι] [CommSemiring R] [AddCommMonoid M] [AddCommMonoid N] [Module R M] [Module R N] /-- The natural linear equivalence: `Mⁱ ≃ Hom(Rⁱ, M)` for an `R`-module `M`. -/ noncomputable def piEquiv : (ι → M) ≃ₗ[R] ((ι → R) →ₗ[R] M) := Basis.constr (Pi.basisFun R ι) R lemma piEquiv_apply_apply (ι R M : Type*) [Fintype ι] [CommSemiring R] [AddCommMonoid M] [Module R M] (v : ι → M) (w : ι → R) : piEquiv ι R M v w = ∑ i, w i • v i := by simp only [piEquiv, Basis.constr_apply_fintype, Basis.equivFun_apply] congr @[simp] lemma range_piEquiv (v : ι → M) : LinearMap.range (piEquiv ι R M v) = span R (range v) := Basis.constr_range _ _ @[simp] lemma surjective_piEquiv_apply_iff (v : ι → M) : Surjective (piEquiv ι R M v) ↔ span R (range v) = ⊤ := by rw [← LinearMap.range_eq_top, range_piEquiv] end Module namespace Module.Free variable {ι : Type*} (R : Type*) (M : Type*) [Semiring R] [AddCommMonoid M] [Module R M] /-- The product of finitely many free modules is free. -/ instance _root_.Module.Free.pi (M : ι → Type*) [Finite ι] [∀ i : ι, AddCommMonoid (M i)] [∀ i : ι, Module R (M i)] [∀ i : ι, Module.Free R (M i)] : Module.Free R (∀ i, M i) := let ⟨_⟩ := nonempty_fintype ι .of_basis <| Pi.basis fun i => Module.Free.chooseBasis R (M i) variable (ι) in /-- The product of finitely many free modules is free (non-dependent version to help with typeclass search). -/ instance _root_.Module.Free.function [Finite ι] [Module.Free R M] : Module.Free R (ι → M) := Free.pi _ _ end Module.Free
.lake/packages/mathlib/Mathlib/LinearAlgebra/InvariantBasisNumber.lean
import Mathlib.RingTheory.Ideal.Quotient.Basic import Mathlib.RingTheory.Noetherian.Orzech import Mathlib.RingTheory.OrzechProperty import Mathlib.RingTheory.PrincipalIdealDomain import Mathlib.LinearAlgebra.Finsupp.Pi /-! # Invariant basis number property ## Main definitions Let `R` be a (not necessary commutative) ring. - `InvariantBasisNumber R` is a type class stating that `(Fin n → R) ≃ₗ[R] (Fin m → R)` implies `n = m`, a property known as the *invariant basis number property.* This assumption implies that there is a well-defined notion of the rank of a finitely generated free (left) `R`-module. It is also useful to consider the following stronger conditions: - The *rank condition*, witnessed by the type class `RankCondition R`, states that the existence of a surjective linear map `(Fin n → R) →ₗ[R] (Fin m → R)` implies `m ≤ n`. - The *strong rank condition*, witnessed by the type class `StrongRankCondition R`, states that the existence of an injective linear map `(Fin n → R) →ₗ[R] (Fin m → R)` implies `n ≤ m`. - `OrzechProperty R`, defined in `Mathlib/RingTheory/OrzechProperty.lean`, states that for any finitely generated `R`-module `M`, any surjective homomorphism `f : N → M` from a submodule `N` of `M` to `M` is injective. ## Instances - `IsNoetherianRing.orzechProperty` (defined in `Mathlib/RingTheory/Noetherian.lean`) : any left-Noetherian ring satisfies the Orzech property. This applies in particular to division rings. - `strongRankCondition_of_orzechProperty` : the Orzech property implies the strong rank condition (for non-trivial rings). - `IsNoetherianRing.strongRankCondition` : every nontrivial left-Noetherian ring satisfies the strong rank condition (and so in particular every division ring or field). - `rankCondition_of_strongRankCondition` : the strong rank condition implies the rank condition. - `invariantBasisNumber_of_rankCondition` : the rank condition implies the invariant basis number property. - `invariantBasisNumber_of_nontrivial_of_commRing`: a nontrivial commutative ring satisfies the invariant basis number property. More generally, every commutative ring satisfies the Orzech property, hence the strong rank condition, which is proved in `Mathlib/RingTheory/FiniteType.lean`. We keep `invariantBasisNumber_of_nontrivial_of_commRing` here since it imports fewer files. ## Counterexamples to converse results The following examples can be found in the book of Lam [lam_1999] (see also <https://math.stackexchange.com/questions/4711904>): - Let `k` be a field, then the free (non-commutative) algebra `k⟨x, y⟩` satisfies the rank condition but not the strong rank condition. - The free (non-commutative) algebra `ℚ⟨a, b, c, d⟩` quotient by the two-sided ideal `(ac − 1, bd − 1, ab, cd)` satisfies the invariant basis number property but not the rank condition. ## Future work So far, there is no API at all for the `InvariantBasisNumber` class. There are several natural ways to formulate that a module `M` is finitely generated and free, for example `M ≃ₗ[R] (Fin n → R)`, `M ≃ₗ[R] (ι → R)`, where `ι` is a fintype, or providing a basis indexed by a finite type. There should be lemmas applying the invariant basis number property to each situation. The finite version of the invariant basis number property implies the infinite analogue, i.e., that `(ι →₀ R) ≃ₗ[R] (ι' →₀ R)` implies that `Cardinal.mk ι = Cardinal.mk ι'`. This fact (and its variants) should be formalized. ## References * https://en.wikipedia.org/wiki/Invariant_basis_number * https://mathoverflow.net/a/2574/ * [Lam, T. Y. *Lectures on Modules and Rings*][lam_1999] * [Orzech, Morris. *Onto endomorphisms are isomorphisms*][orzech1971] * [Djoković, D. Ž. *Epimorphisms of modules which must be isomorphisms*][djokovic1973] * [Ribenboim, Paulo. *Épimorphismes de modules qui sont nécessairement des isomorphismes*][ribenboim1971] ## Tags free module, rank, Orzech property, (strong) rank condition, invariant basis number, IBN -/ noncomputable section open Function universe u v w section variable (R : Type u) [Semiring R] /-- We say that `R` satisfies the strong rank condition if `(Fin n → R) →ₗ[R] (Fin m → R)` injective implies `n ≤ m`. -/ @[mk_iff] class StrongRankCondition : Prop where /-- Any injective linear map from `Rⁿ` to `Rᵐ` guarantees `n ≤ m`. -/ le_of_fin_injective : ∀ {n m : ℕ} (f : (Fin n → R) →ₗ[R] Fin m → R), Injective f → n ≤ m theorem le_of_fin_injective [StrongRankCondition R] {n m : ℕ} (f : (Fin n → R) →ₗ[R] Fin m → R) : Injective f → n ≤ m := StrongRankCondition.le_of_fin_injective f /-- A ring satisfies the strong rank condition if and only if, for all `n : ℕ`, any linear map `(Fin (n + 1) → R) →ₗ[R] (Fin n → R)` is not injective. -/ theorem strongRankCondition_iff_succ : StrongRankCondition R ↔ ∀ (n : ℕ) (f : (Fin (n + 1) → R) →ₗ[R] Fin n → R), ¬Function.Injective f := by refine ⟨fun h n => fun f hf => ?_, fun h => ⟨@fun n m f hf => ?_⟩⟩ · letI : StrongRankCondition R := h exact Nat.not_succ_le_self n (le_of_fin_injective R f hf) · by_contra H exact h m (f.comp (Function.ExtendByZero.linearMap R (Fin.castLE (not_le.1 H)))) (hf.comp (Function.extend_injective (Fin.strictMono_castLE _).injective _)) /-- Any nontrivial ring satisfying Orzech property also satisfies strong rank condition. -/ instance (priority := 100) strongRankCondition_of_orzechProperty [Nontrivial R] [OrzechProperty R] : StrongRankCondition R := by refine (strongRankCondition_iff_succ R).2 fun n i hi ↦ ?_ let f : (Fin (n + 1) → R) →ₗ[R] Fin n → R := { toFun := fun x ↦ x ∘ Fin.castSucc map_add' := fun _ _ ↦ rfl map_smul' := fun _ _ ↦ rfl } have h : (0 : Fin (n + 1) → R) = update (0 : Fin (n + 1) → R) (Fin.last n) 1 := by apply OrzechProperty.injective_of_surjective_of_injective i f hi (Fin.castSucc_injective _).surjective_comp_right ext m simp [f] simpa using congr_fun h (Fin.last n) theorem card_le_of_injective [StrongRankCondition R] {α β : Type*} [Fintype α] [Fintype β] (f : (α → R) →ₗ[R] β → R) (i : Injective f) : Fintype.card α ≤ Fintype.card β := by let P := LinearEquiv.funCongrLeft R R (Fintype.equivFin α) let Q := LinearEquiv.funCongrLeft R R (Fintype.equivFin β) exact le_of_fin_injective R ((Q.symm.toLinearMap.comp f).comp P.toLinearMap) (((LinearEquiv.symm Q).injective.comp i).comp (LinearEquiv.injective P)) theorem card_le_of_injective' [StrongRankCondition R] {α β : Type*} [Fintype α] [Fintype β] (f : (α →₀ R) →ₗ[R] β →₀ R) (i : Injective f) : Fintype.card α ≤ Fintype.card β := by let P := Finsupp.linearEquivFunOnFinite R R β let Q := (Finsupp.linearEquivFunOnFinite R R α).symm exact card_le_of_injective R ((P.toLinearMap.comp f).comp Q.toLinearMap) ((P.injective.comp i).comp Q.injective) /-- We say that `R` satisfies the rank condition if `(Fin n → R) →ₗ[R] (Fin m → R)` surjective implies `m ≤ n`. -/ class RankCondition : Prop where /-- Any surjective linear map from `Rⁿ` to `Rᵐ` guarantees `m ≤ n`. -/ le_of_fin_surjective : ∀ {n m : ℕ} (f : (Fin n → R) →ₗ[R] Fin m → R), Surjective f → m ≤ n theorem le_of_fin_surjective [RankCondition R] {n m : ℕ} (f : (Fin n → R) →ₗ[R] Fin m → R) : Surjective f → m ≤ n := RankCondition.le_of_fin_surjective f theorem card_le_of_surjective [RankCondition R] {α β : Type*} [Fintype α] [Fintype β] (f : (α → R) →ₗ[R] β → R) (i : Surjective f) : Fintype.card β ≤ Fintype.card α := by let P := LinearEquiv.funCongrLeft R R (Fintype.equivFin α) let Q := LinearEquiv.funCongrLeft R R (Fintype.equivFin β) exact le_of_fin_surjective R ((Q.symm.toLinearMap.comp f).comp P.toLinearMap) (((LinearEquiv.symm Q).surjective.comp i).comp (LinearEquiv.surjective P)) theorem card_le_of_surjective' [RankCondition R] {α β : Type*} [Fintype α] [Fintype β] (f : (α →₀ R) →ₗ[R] β →₀ R) (i : Surjective f) : Fintype.card β ≤ Fintype.card α := by let P := Finsupp.linearEquivFunOnFinite R R β let Q := (Finsupp.linearEquivFunOnFinite R R α).symm exact card_le_of_surjective R ((P.toLinearMap.comp f).comp Q.toLinearMap) ((P.surjective.comp i).comp Q.surjective) theorem Module.Finite.exists_nat_not_surjective [RankCondition R] (M) [AddCommMonoid M] [Module R M] [Module.Finite R M] : ∃ n : ℕ, ∀ f : M →ₗ[R] (Fin n → R), ¬Surjective f := have ⟨n, f, hf⟩ := Module.Finite.exists_fin' R M ⟨n + 1, fun g hg ↦ by simpa using le_of_fin_surjective R (g ∘ₗ f) (hg.comp hf)⟩ /-- By the universal property for free modules, any surjective map `(Fin n → R) →ₗ[R] (Fin m → R)` has an injective splitting `(Fin m → R) →ₗ[R] (Fin n → R)` from which the strong rank condition gives the necessary inequality for the rank condition. -/ instance (priority := 100) rankCondition_of_strongRankCondition [StrongRankCondition R] : RankCondition R where le_of_fin_surjective f s := le_of_fin_injective R _ (f.splittingOfFunOnFintypeSurjective_injective s) /-- We say that `R` has the invariant basis number property if `(Fin n → R) ≃ₗ[R] (Fin m → R)` implies `n = m`. This gives rise to a well-defined notion of rank of a finitely generated free module. -/ class InvariantBasisNumber : Prop where /-- Any linear equiv between `Rⁿ` and `Rᵐ` guarantees `m = n`. -/ eq_of_fin_equiv : ∀ {n m : ℕ}, ((Fin n → R) ≃ₗ[R] Fin m → R) → n = m instance (priority := 100) invariantBasisNumber_of_rankCondition [RankCondition R] : InvariantBasisNumber R where eq_of_fin_equiv e := le_antisymm (le_of_fin_surjective R e.symm.toLinearMap e.symm.surjective) (le_of_fin_surjective R e.toLinearMap e.surjective) end section variable (R : Type u) [Semiring R] [InvariantBasisNumber R] theorem eq_of_fin_equiv {n m : ℕ} : ((Fin n → R) ≃ₗ[R] Fin m → R) → n = m := InvariantBasisNumber.eq_of_fin_equiv theorem card_eq_of_linearEquiv {α β : Type*} [Fintype α] [Fintype β] (f : (α → R) ≃ₗ[R] β → R) : Fintype.card α = Fintype.card β := eq_of_fin_equiv R ((LinearEquiv.funCongrLeft R R (Fintype.equivFin α)).trans f ≪≫ₗ (LinearEquiv.funCongrLeft R R (Fintype.equivFin β)).symm) theorem nontrivial_of_invariantBasisNumber : Nontrivial R := by by_contra! h refine zero_ne_one (eq_of_fin_equiv R ?_) haveI : Subsingleton (Fin 1 → R) := Subsingleton.intro fun a b => funext fun x => Subsingleton.elim _ _ exact { toFun := 0 invFun := 0 map_add' := by simp map_smul' := by simp left_inv := fun _ => by simp [eq_iff_true_of_subsingleton] right_inv := fun _ => by simp [eq_iff_true_of_subsingleton] } end section variable (R : Type u) [Ring R] [Nontrivial R] [IsNoetherianRing R] /-- Any nontrivial Noetherian ring satisfies the strong rank condition, since it satisfies Orzech property. -/ instance (priority := 100) IsNoetherianRing.strongRankCondition : StrongRankCondition R := inferInstance end /-! We want to show that nontrivial commutative rings have invariant basis number. The idea is to take a maximal ideal `I` of `R` and use an isomorphism `R^n ≃ R^m` of `R` modules to produce an isomorphism `(R/I)^n ≃ (R/I)^m` of `R/I`-modules, which will imply `n = m` since `R/I` is a field and we know that fields have invariant basis number. We construct the isomorphism in two steps: 1. We construct the ring `R^n/I^n`, show that it is an `R/I`-module and show that there is an isomorphism of `R/I`-modules `R^n/I^n ≃ (R/I)^n`. This isomorphism is called `Ideal.piQuotEquiv` and is located in the file `RingTheory/Ideals.lean`. 2. We construct an isomorphism of `R/I`-modules `R^n/I^n ≃ R^m/I^m` using the isomorphism `R^n ≃ R^m`. -/ section variable {R : Type u} [CommRing R] (I : Ideal R) {ι : Type v} [Fintype ι] {ι' : Type w} /-- An `R`-linear map `R^n → R^m` induces a function `R^n/I^n → R^m/I^m`. -/ private def induced_map (I : Ideal R) (e : (ι → R) →ₗ[R] ι' → R) : (ι → R) ⧸ Ideal.pi (fun _ ↦ I) → (ι' → R) ⧸ Ideal.pi fun _ ↦ I := fun x => Quotient.liftOn' x (fun y => Ideal.Quotient.mk _ (e y)) (by refine fun a b hab => Ideal.Quotient.eq.2 fun h => ?_ rw [Submodule.quotientRel_def] at hab rw [← LinearMap.map_sub] exact Ideal.map_pi _ _ hab e h) /-- An isomorphism of `R`-modules `R^n ≃ R^m` induces an isomorphism of `R/I`-modules `R^n/I^n ≃ R^m/I^m`. -/ private def inducedEquiv [Fintype ι'] (I : Ideal R) (e : (ι → R) ≃ₗ[R] ι' → R) : ((ι → R) ⧸ Ideal.pi fun _ ↦ I) ≃ₗ[R ⧸ I] (ι' → R) ⧸ Ideal.pi fun _ ↦ I where toFun := induced_map I e invFun := induced_map I e.symm map_add' := by rintro ⟨a⟩ ⟨b⟩; exact congr_arg _ (map_add ..) map_smul' := by rintro ⟨a⟩ ⟨b⟩; exact congr_arg _ (map_smul ..) left_inv := by rintro ⟨a⟩; exact congr_arg _ (e.left_inv ..) right_inv := by rintro ⟨a⟩; exact congr_arg _ (e.right_inv ..) end section attribute [local instance] Ideal.Quotient.field /-- Nontrivial commutative rings have the invariant basis number property. There are two stronger results in mathlib: `commRing_strongRankCondition`, which says that any nontrivial commutative ring satisfies the strong rank condition, and `rankCondition_of_nontrivial_of_commSemiring`, which says that any nontrivial commutative semiring satisfies the rank condition. We prove this instance separately to avoid dependency on `Mathlib/LinearAlgebra/Charpoly/Basic.lean` or `Mathlib/LinearAlgebra/Matrix/ToLin.lean`. -/ instance (priority := 100) invariantBasisNumber_of_nontrivial_of_commRing {R : Type u} [CommRing R] [Nontrivial R] : InvariantBasisNumber R := ⟨fun e => let ⟨I, _hI⟩ := Ideal.exists_maximal R eq_of_fin_equiv (R ⧸ I) ((Ideal.piQuotEquiv _ _).symm ≪≫ₗ inducedEquiv _ e ≪≫ₗ Ideal.piQuotEquiv _ _)⟩ end
.lake/packages/mathlib/Mathlib/LinearAlgebra/LinearDisjoint.lean
import Mathlib.LinearAlgebra.TensorProduct.Tower import Mathlib.LinearAlgebra.TensorProduct.Finiteness import Mathlib.LinearAlgebra.TensorProduct.Submodule import Mathlib.LinearAlgebra.Dimension.Finite import Mathlib.RingTheory.Flat.Basic /-! # Linearly disjoint submodules This file contains basics about linearly disjoint submodules. ## Mathematical background We adapt the definitions in <https://en.wikipedia.org/wiki/Linearly_disjoint>. Let `R` be a commutative ring, `S` be an `R`-algebra (not necessarily commutative). Let `M` and `N` be `R`-submodules in `S` (`Submodule R S`). - `M` and `N` are linearly disjoint (`Submodule.LinearDisjoint M N` or simply `M.LinearDisjoint N`), if the natural `R`-linear map `M ⊗[R] N →ₗ[R] S` (`Submodule.mulMap M N`) induced by the multiplication in `S` is injective. The following is the first equivalent characterization of linear disjointness: - `Submodule.LinearDisjoint.linearIndependent_left_of_flat`: if `M` and `N` are linearly disjoint, if `N` is a flat `R`-module, then for any family of `R`-linearly independent elements `{ m_i }` of `M`, they are also `N`-linearly independent, in the sense that the `R`-linear map from `ι →₀ N` to `S` which maps `{ n_i }` to the sum of `m_i * n_i` (`Submodule.mulLeftMap N m`) is injective. - `Submodule.LinearDisjoint.of_basis_left`: conversely, if `{ m_i }` is an `R`-basis of `M`, which is also `N`-linearly independent, then `M` and `N` are linearly disjoint. Dually, we have: - `Submodule.LinearDisjoint.linearIndependent_right_of_flat`: if `M` and `N` are linearly disjoint, if `M` is a flat `R`-module, then for any family of `R`-linearly independent elements `{ n_i }` of `N`, they are also `M`-linearly independent, in the sense that the `R`-linear map from `ι →₀ M` to `S` which maps `{ m_i }` to the sum of `m_i * n_i` (`Submodule.mulRightMap M n`) is injective. - `Submodule.LinearDisjoint.of_basis_right`: conversely, if `{ n_i }` is an `R`-basis of `N`, which is also `M`-linearly independent, then `M` and `N` are linearly disjoint. The following is the second equivalent characterization of linear disjointness: - `Submodule.LinearDisjoint.linearIndependent_mul_of_flat`: if `M` and `N` are linearly disjoint, if one of `M` and `N` is flat, then for any family of `R`-linearly independent elements `{ m_i }` of `M`, and any family of `R`-linearly independent elements `{ n_j }` of `N`, the family `{ m_i * n_j }` in `S` is also `R`-linearly independent. - `Submodule.LinearDisjoint.of_basis_mul`: conversely, if `{ m_i }` is an `R`-basis of `M`, if `{ n_i }` is an `R`-basis of `N`, such that the family `{ m_i * n_j }` in `S` is `R`-linearly independent, then `M` and `N` are linearly disjoint. ## Other main results - `Submodule.LinearDisjoint.symm_of_commute`, `Submodule.linearDisjoint_comm_of_commute`: linear disjointness is symmetric under some commutative conditions. - `Submodule.LinearDisjoint.map`: linear disjointness is preserved by injective algebra homomorphisms. - `Submodule.linearDisjoint_op`: linear disjointness is preserved by taking multiplicative opposite. - `Submodule.LinearDisjoint.of_le_left_of_flat`, `Submodule.LinearDisjoint.of_le_right_of_flat`, `Submodule.LinearDisjoint.of_le_of_flat_left`, `Submodule.LinearDisjoint.of_le_of_flat_right`: linear disjointness is preserved by taking submodules under some flatness conditions. - `Submodule.LinearDisjoint.of_linearDisjoint_fg_left`, `Submodule.LinearDisjoint.of_linearDisjoint_fg_right`, `Submodule.LinearDisjoint.of_linearDisjoint_fg`: conversely, if any finitely generated submodules of `M` and `N` are linearly disjoint, then `M` and `N` themselves are linearly disjoint. - `Submodule.LinearDisjoint.bot_left`, `Submodule.LinearDisjoint.bot_right`: the zero module is linearly disjoint with any other submodules. - `Submodule.LinearDisjoint.one_left`, `Submodule.LinearDisjoint.one_right`: the image of `R` in `S` is linearly disjoint with any other submodules. - `Submodule.LinearDisjoint.of_left_le_one_of_flat`, `Submodule.LinearDisjoint.of_right_le_one_of_flat`: if a submodule is contained in the image of `R` in `S`, then it is linearly disjoint with any other submodules, under some flatness conditions. - `Submodule.LinearDisjoint.not_linearIndependent_pair_of_commute_of_flat`, `Submodule.LinearDisjoint.rank_inf_le_one_of_commute_of_flat`: if `M` and `N` are linearly disjoint, if one of `M` and `N` is flat, then any two commutative elements contained in the intersection of `M` and `N` are not `R`-linearly independent (namely, their span is not `R ^ 2`). In particular, if any two elements in the intersection of `M` and `N` are commutative, then the rank of the intersection of `M` and `N` is at most one. These results are stated using bundled version (i.e. `a : ↥(M ⊓ N)`). If you want a not bundled version (i.e. `a : S` with `ha : a ∈ M ⊓ N`), you may use `LinearIndependent.of_comp` and `FinVec.map_eq` (in `Mathlib/Data/Fin/Tuple/Reflection.lean`), see the following code snippet: ``` have h := H.not_linearIndependent_pair_of_commute_of_flat hf ⟨a, ha⟩ ⟨b, hb⟩ hc contrapose! h refine .of_comp (M ⊓ N).subtype ?_ convert h exact (FinVec.map_eq _ _).symm ``` - `Submodule.LinearDisjoint.rank_le_one_of_commute_of_flat_of_self`: if `M` and itself are linearly disjoint, if `M` is flat, if any two elements in `M` are commutative, then the rank of `M` is at most one. The results with name containing "of_commute" also have corresponding specialized versions assuming `S` is commutative. ## Tags linearly disjoint, linearly independent, tensor product -/ open Module open scoped TensorProduct noncomputable section universe u v w namespace Submodule variable {R : Type u} {S : Type v} section Semiring variable [CommSemiring R] [Semiring S] [Algebra R S] variable (M N : Submodule R S) /-- Two submodules `M` and `N` in an algebra `S` over `R` are linearly disjoint if the natural map `M ⊗[R] N →ₗ[R] S` induced by multiplication in `S` is injective. -/ @[mk_iff] protected structure LinearDisjoint : Prop where injective : Function.Injective (mulMap M N) variable {M N} /-- If `M` and `N` are linearly disjoint submodules, then there is the natural isomorphism `M ⊗[R] N ≃ₗ[R] M * N` induced by multiplication in `S`. -/ protected def LinearDisjoint.mulMap (H : M.LinearDisjoint N) : M ⊗[R] N ≃ₗ[R] M * N := LinearEquiv.ofInjective (M.mulMap N) H.injective ≪≫ₗ LinearEquiv.ofEq _ _ (mulMap_range M N) @[simp] theorem LinearDisjoint.val_mulMap_tmul (H : M.LinearDisjoint N) (m : M) (n : N) : (H.mulMap (m ⊗ₜ[R] n) : S) = m.1 * n.1 := rfl @[nontriviality] theorem LinearDisjoint.of_subsingleton [Subsingleton R] : M.LinearDisjoint N := haveI : Subsingleton S := Module.subsingleton R S ⟨Function.injective_of_subsingleton _⟩ @[nontriviality] theorem LinearDisjoint.of_subsingleton_top [Subsingleton S] : M.LinearDisjoint N := ⟨Function.injective_of_subsingleton _⟩ /-- Linear disjointness is preserved by taking multiplicative opposite. -/ theorem linearDisjoint_op : M.LinearDisjoint N ↔ (equivOpposite.symm (MulOpposite.op N)).LinearDisjoint (equivOpposite.symm (MulOpposite.op M)) := by simp only [linearDisjoint_iff, mulMap_op, LinearMap.coe_comp, LinearEquiv.coe_coe, EquivLike.comp_injective, EquivLike.injective_comp] alias ⟨LinearDisjoint.op, LinearDisjoint.of_op⟩ := linearDisjoint_op /-- Linear disjointness is symmetric if elements in the module commute. -/ theorem LinearDisjoint.symm_of_commute (H : M.LinearDisjoint N) (hc : ∀ (m : M) (n : N), Commute m.1 n.1) : N.LinearDisjoint M := by rw [linearDisjoint_iff, mulMap_comm_of_commute M N hc] exact ((TensorProduct.comm R N M).toEquiv.injective_comp _).2 H.injective /-- Linear disjointness is symmetric if elements in the module commute. -/ theorem linearDisjoint_comm_of_commute (hc : ∀ (m : M) (n : N), Commute m.1 n.1) : M.LinearDisjoint N ↔ N.LinearDisjoint M := ⟨fun H ↦ H.symm_of_commute hc, fun H ↦ H.symm_of_commute fun _ _ ↦ (hc _ _).symm⟩ namespace LinearDisjoint /-- Linear disjointness is preserved by injective algebra homomorphisms. -/ theorem map (H : M.LinearDisjoint N) {T : Type w} [Semiring T] [Algebra R T] {F : Type*} [FunLike F S T] [AlgHomClass F R S T] (f : F) (hf : Function.Injective f) : (M.map f).LinearDisjoint (N.map f) := by rw [linearDisjoint_iff] at H ⊢ have : _ ∘ₗ (TensorProduct.congr (M.equivMapOfInjective f hf) (N.equivMapOfInjective f hf)).toLinearMap = _ := M.mulMap_map_comp_eq N f replace H : Function.Injective ((f : S →ₗ[R] T) ∘ₗ mulMap M N) := hf.comp H simpa only [← this, LinearMap.coe_comp, LinearEquiv.coe_coe, EquivLike.injective_comp] using H variable (M N) /-- If `{ m_i }` is an `R`-basis of `M`, which is also `N`-linearly independent (in this result it is stated as `Submodule.mulLeftMap` is injective), then `M` and `N` are linearly disjoint. -/ theorem of_basis_left' {ι : Type*} (m : Basis ι R M) (H : Function.Injective (mulLeftMap N m)) : M.LinearDisjoint N := by classical simp_rw [mulLeftMap_eq_mulMap_comp, ← Basis.coe_repr_symm, ← LinearEquiv.coe_rTensor, LinearEquiv.comp_coe, LinearMap.coe_comp, LinearEquiv.coe_coe, EquivLike.injective_comp] at H exact ⟨H⟩ /-- If `{ n_i }` is an `R`-basis of `N`, which is also `M`-linearly independent (in this result it is stated as `Submodule.mulRightMap` is injective), then `M` and `N` are linearly disjoint. -/ theorem of_basis_right' {ι : Type*} (n : Basis ι R N) (H : Function.Injective (mulRightMap M n)) : M.LinearDisjoint N := by classical simp_rw [mulRightMap_eq_mulMap_comp, ← Basis.coe_repr_symm, ← LinearEquiv.coe_lTensor, LinearEquiv.comp_coe, LinearMap.coe_comp, LinearEquiv.coe_coe, EquivLike.injective_comp] at H exact ⟨H⟩ /-- If `{ m_i }` is an `R`-basis of `M`, if `{ n_i }` is an `R`-basis of `N`, such that the family `{ m_i * n_j }` in `S` is `R`-linearly independent (in this result it is stated as the relevant `Finsupp.linearCombination` is injective), then `M` and `N` are linearly disjoint. -/ theorem of_basis_mul' {κ ι : Type*} (m : Basis κ R M) (n : Basis ι R N) (H : Function.Injective (Finsupp.linearCombination R fun i : κ × ι ↦ (m i.1 * n i.2 : S))) : M.LinearDisjoint N := by let i0 := (finsuppTensorFinsupp' R κ ι).symm let i1 := TensorProduct.congr m.repr n.repr let i := mulMap M N ∘ₗ (i0.trans i1.symm).toLinearMap have : i = Finsupp.linearCombination R fun i : κ × ι ↦ (m i.1 * n i.2 : S) := by ext x simp [i, i0, i1, finsuppTensorFinsupp'_symm_single_eq_single_one_tmul] simp_rw [← this, i, LinearMap.coe_comp, LinearEquiv.coe_coe, EquivLike.injective_comp] at H exact ⟨H⟩ /-- The zero module is linearly disjoint with any other submodules. -/ theorem bot_left : (⊥ : Submodule R S).LinearDisjoint N := ⟨Function.injective_of_subsingleton _⟩ /-- The zero module is linearly disjoint with any other submodules. -/ theorem bot_right : M.LinearDisjoint (⊥ : Submodule R S) := ⟨Function.injective_of_subsingleton _⟩ /-- The image of `R` in `S` is linearly disjoint with any other submodules. -/ theorem one_left : (1 : Submodule R S).LinearDisjoint N := by rw [linearDisjoint_iff, ← Algebra.toSubmodule_bot, mulMap_one_left_eq] exact N.injective_subtype.comp N.lTensorOne.injective /-- The image of `R` in `S` is linearly disjoint with any other submodules. -/ theorem one_right : M.LinearDisjoint (1 : Submodule R S) := by rw [linearDisjoint_iff, ← Algebra.toSubmodule_bot, mulMap_one_right_eq] exact M.injective_subtype.comp M.rTensorOne.injective /-- If for any finitely generated submodules `M'` of `M`, `M'` and `N` are linearly disjoint, then `M` and `N` themselves are linearly disjoint. -/ theorem of_linearDisjoint_fg_left (H : ∀ M' : Submodule R S, M' ≤ M → M'.FG → M'.LinearDisjoint N) : M.LinearDisjoint N := (linearDisjoint_iff _ _).2 fun x y hxy ↦ by obtain ⟨M', hM, hFG, h⟩ := TensorProduct.exists_finite_submodule_left_of_setFinite' {x, y} (Set.toFinite _) rw [Module.Finite.iff_fg] at hFG obtain ⟨x', hx'⟩ := h (show x ∈ {x, y} by simp) obtain ⟨y', hy'⟩ := h (show y ∈ {x, y} by simp) rw [← hx', ← hy']; congr exact (H M' hM hFG).injective (by simp [← mulMap_comp_rTensor _ hM, hx', hy', hxy]) /-- If for any finitely generated submodules `N'` of `N`, `M` and `N'` are linearly disjoint, then `M` and `N` themselves are linearly disjoint. -/ theorem of_linearDisjoint_fg_right (H : ∀ N' : Submodule R S, N' ≤ N → N'.FG → M.LinearDisjoint N') : M.LinearDisjoint N := (linearDisjoint_iff _ _).2 fun x y hxy ↦ by obtain ⟨N', hN, hFG, h⟩ := TensorProduct.exists_finite_submodule_right_of_setFinite' {x, y} (Set.toFinite _) rw [Module.Finite.iff_fg] at hFG obtain ⟨x', hx'⟩ := h (show x ∈ {x, y} by simp) obtain ⟨y', hy'⟩ := h (show y ∈ {x, y} by simp) rw [← hx', ← hy']; congr exact (H N' hN hFG).injective (by simp [← mulMap_comp_lTensor _ hN, hx', hy', hxy]) /-- If for any finitely generated submodules `M'` and `N'` of `M` and `N`, respectively, `M'` and `N'` are linearly disjoint, then `M` and `N` themselves are linearly disjoint. -/ theorem of_linearDisjoint_fg (H : ∀ (M' N' : Submodule R S), M' ≤ M → N' ≤ N → M'.FG → N'.FG → M'.LinearDisjoint N') : M.LinearDisjoint N := of_linearDisjoint_fg_left _ _ fun _ hM hM' ↦ of_linearDisjoint_fg_right _ _ fun _ hN hN' ↦ H _ _ hM hN hM' hN' end LinearDisjoint end Semiring section CommSemiring variable [CommSemiring R] [CommSemiring S] [Algebra R S] variable {M N : Submodule R S} /-- Linear disjointness is symmetric in a commutative ring. -/ theorem LinearDisjoint.symm (H : M.LinearDisjoint N) : N.LinearDisjoint M := H.symm_of_commute fun _ _ ↦ mul_comm _ _ /-- Linear disjointness is symmetric in a commutative ring. -/ theorem linearDisjoint_comm : M.LinearDisjoint N ↔ N.LinearDisjoint M := ⟨LinearDisjoint.symm, LinearDisjoint.symm⟩ end CommSemiring section Ring namespace LinearDisjoint variable [CommRing R] [Ring S] [Algebra R S] variable (M N : Submodule R S) variable {M N} in /-- If `M` and `N` are linearly disjoint, if `N` is a flat `R`-module, then for any family of `R`-linearly independent elements `{ m_i }` of `M`, they are also `N`-linearly independent, in the sense that the `R`-linear map from `ι →₀ N` to `S` which maps `{ n_i }` to the sum of `m_i * n_i` (`Submodule.mulLeftMap N m`) has trivial kernel. -/ theorem linearIndependent_left_of_flat (H : M.LinearDisjoint N) [Module.Flat R N] {ι : Type*} {m : ι → M} (hm : LinearIndependent R m) : LinearMap.ker (mulLeftMap N m) = ⊥ := by refine LinearMap.ker_eq_bot_of_injective ?_ classical simp_rw [mulLeftMap_eq_mulMap_comp, LinearMap.coe_comp, LinearEquiv.coe_coe, ← Function.comp_assoc, EquivLike.injective_comp] rw [LinearIndependent] at hm exact H.injective.comp (Module.Flat.rTensor_preserves_injective_linearMap (M := N) _ hm) /-- If `{ m_i }` is an `R`-basis of `M`, which is also `N`-linearly independent, then `M` and `N` are linearly disjoint. -/ theorem of_basis_left {ι : Type*} (m : Basis ι R M) (H : LinearMap.ker (mulLeftMap N m) = ⊥) : M.LinearDisjoint N := by -- need this instance otherwise `LinearMap.ker_eq_bot` does not work letI : AddCommGroup (ι →₀ N) := Finsupp.instAddCommGroup exact of_basis_left' M N m (LinearMap.ker_eq_bot.1 H) variable {M N} in /-- If `M` and `N` are linearly disjoint, if `M` is a flat `R`-module, then for any family of `R`-linearly independent elements `{ n_i }` of `N`, they are also `M`-linearly independent, in the sense that the `R`-linear map from `ι →₀ M` to `S` which maps `{ m_i }` to the sum of `m_i * n_i` (`Submodule.mulRightMap M n`) has trivial kernel. -/ theorem linearIndependent_right_of_flat (H : M.LinearDisjoint N) [Module.Flat R M] {ι : Type*} {n : ι → N} (hn : LinearIndependent R n) : LinearMap.ker (mulRightMap M n) = ⊥ := by refine LinearMap.ker_eq_bot_of_injective ?_ classical simp_rw [mulRightMap_eq_mulMap_comp, LinearMap.coe_comp, LinearEquiv.coe_coe, ← Function.comp_assoc, EquivLike.injective_comp] rw [LinearIndependent] at hn exact H.injective.comp (Module.Flat.lTensor_preserves_injective_linearMap (M := M) _ hn) /-- If `{ n_i }` is an `R`-basis of `N`, which is also `M`-linearly independent, then `M` and `N` are linearly disjoint. -/ theorem of_basis_right {ι : Type*} (n : Basis ι R N) (H : LinearMap.ker (mulRightMap M n) = ⊥) : M.LinearDisjoint N := by -- need this instance otherwise `LinearMap.ker_eq_bot` does not work letI : AddCommGroup (ι →₀ M) := Finsupp.instAddCommGroup exact of_basis_right' M N n (LinearMap.ker_eq_bot.1 H) variable {M N} in /-- If `M` and `N` are linearly disjoint, if `M` is flat, then for any family of `R`-linearly independent elements `{ m_i }` of `M`, and any family of `R`-linearly independent elements `{ n_j }` of `N`, the family `{ m_i * n_j }` in `S` is also `R`-linearly independent. -/ theorem linearIndependent_mul_of_flat_left (H : M.LinearDisjoint N) [Module.Flat R M] {κ ι : Type*} {m : κ → M} {n : ι → N} (hm : LinearIndependent R m) (hn : LinearIndependent R n) : LinearIndependent R fun (i : κ × ι) ↦ (m i.1).1 * (n i.2).1 := by rw [LinearIndependent] at hm hn ⊢ let i0 := (finsuppTensorFinsupp' R κ ι).symm let i1 := LinearMap.rTensor (ι →₀ R) (Finsupp.linearCombination R m) let i2 := LinearMap.lTensor M (Finsupp.linearCombination R n) let i := mulMap M N ∘ₗ i2 ∘ₗ i1 ∘ₗ i0.toLinearMap have h1 : Function.Injective i1 := Module.Flat.rTensor_preserves_injective_linearMap _ hm have h2 : Function.Injective i2 := Module.Flat.lTensor_preserves_injective_linearMap _ hn have h : Function.Injective i := H.injective.comp h2 |>.comp h1 |>.comp i0.injective have : i = Finsupp.linearCombination R fun i ↦ (m i.1).1 * (n i.2).1 := by ext x simp [i, i0, i1, i2, finsuppTensorFinsupp'_symm_single_eq_single_one_tmul] rwa [this] at h variable {M N} in /-- If `M` and `N` are linearly disjoint, if `N` is flat, then for any family of `R`-linearly independent elements `{ m_i }` of `M`, and any family of `R`-linearly independent elements `{ n_j }` of `N`, the family `{ m_i * n_j }` in `S` is also `R`-linearly independent. -/ theorem linearIndependent_mul_of_flat_right (H : M.LinearDisjoint N) [Module.Flat R N] {κ ι : Type*} {m : κ → M} {n : ι → N} (hm : LinearIndependent R m) (hn : LinearIndependent R n) : LinearIndependent R fun (i : κ × ι) ↦ (m i.1).1 * (n i.2).1 := by rw [LinearIndependent] at hm hn ⊢ let i0 := (finsuppTensorFinsupp' R κ ι).symm let i1 := LinearMap.lTensor (κ →₀ R) (Finsupp.linearCombination R n) let i2 := LinearMap.rTensor N (Finsupp.linearCombination R m) let i := mulMap M N ∘ₗ i2 ∘ₗ i1 ∘ₗ i0.toLinearMap have h1 : Function.Injective i1 := Module.Flat.lTensor_preserves_injective_linearMap _ hn have h2 : Function.Injective i2 := Module.Flat.rTensor_preserves_injective_linearMap _ hm have h : Function.Injective i := H.injective.comp h2 |>.comp h1 |>.comp i0.injective have : i = Finsupp.linearCombination R fun i ↦ (m i.1).1 * (n i.2).1 := by ext x simp [i, i0, i1, i2, finsuppTensorFinsupp'_symm_single_eq_single_one_tmul] rwa [this] at h variable {M N} in /-- If `M` and `N` are linearly disjoint, if one of `M` and `N` is flat, then for any family of `R`-linearly independent elements `{ m_i }` of `M`, and any family of `R`-linearly independent elements `{ n_j }` of `N`, the family `{ m_i * n_j }` in `S` is also `R`-linearly independent. -/ theorem linearIndependent_mul_of_flat (H : M.LinearDisjoint N) (hf : Module.Flat R M ∨ Module.Flat R N) {κ ι : Type*} {m : κ → M} {n : ι → N} (hm : LinearIndependent R m) (hn : LinearIndependent R n) : LinearIndependent R fun (i : κ × ι) ↦ (m i.1).1 * (n i.2).1 := by rcases hf with _ | _ · exact H.linearIndependent_mul_of_flat_left hm hn · exact H.linearIndependent_mul_of_flat_right hm hn /-- If `{ m_i }` is an `R`-basis of `M`, if `{ n_j }` is an `R`-basis of `N`, such that the family `{ m_i * n_j }` in `S` is `R`-linearly independent, then `M` and `N` are linearly disjoint. -/ theorem of_basis_mul {κ ι : Type*} (m : Basis κ R M) (n : Basis ι R N) (H : LinearIndependent R fun (i : κ × ι) ↦ (m i.1).1 * (n i.2).1) : M.LinearDisjoint N := by rw [LinearIndependent] at H exact of_basis_mul' M N m n H variable {M N} in /-- If `M` and `N` are linearly disjoint, if `N` is flat, then for any submodule `M'` of `M`, `M'` and `N` are also linearly disjoint. -/ theorem of_le_left_of_flat (H : M.LinearDisjoint N) {M' : Submodule R S} (h : M' ≤ M) [Module.Flat R N] : M'.LinearDisjoint N := by let i := mulMap M N ∘ₗ (inclusion h).rTensor N have hi : Function.Injective i := H.injective.comp <| Module.Flat.rTensor_preserves_injective_linearMap _ <| inclusion_injective h have : i = mulMap M' N := by ext; simp [i] exact ⟨this ▸ hi⟩ variable {M N} in /-- If `M` and `N` are linearly disjoint, if `M` is flat, then for any submodule `N'` of `N`, `M` and `N'` are also linearly disjoint. -/ theorem of_le_right_of_flat (H : M.LinearDisjoint N) {N' : Submodule R S} (h : N' ≤ N) [Module.Flat R M] : M.LinearDisjoint N' := by let i := mulMap M N ∘ₗ (inclusion h).lTensor M have hi : Function.Injective i := H.injective.comp <| Module.Flat.lTensor_preserves_injective_linearMap _ <| inclusion_injective h have : i = mulMap M N' := by ext; simp [i] exact ⟨this ▸ hi⟩ variable {M N} in /-- If `M` and `N` are linearly disjoint, `M'` and `N'` are submodules of `M` and `N`, respectively, such that `N` and `M'` are flat, then `M'` and `N'` are also linearly disjoint. -/ theorem of_le_of_flat_right (H : M.LinearDisjoint N) {M' N' : Submodule R S} (hm : M' ≤ M) (hn : N' ≤ N) [Module.Flat R N] [Module.Flat R M'] : M'.LinearDisjoint N' := (H.of_le_left_of_flat hm).of_le_right_of_flat hn variable {M N} in /-- If `M` and `N` are linearly disjoint, `M'` and `N'` are submodules of `M` and `N`, respectively, such that `M` and `N'` are flat, then `M'` and `N'` are also linearly disjoint. -/ theorem of_le_of_flat_left (H : M.LinearDisjoint N) {M' N' : Submodule R S} (hm : M' ≤ M) (hn : N' ≤ N) [Module.Flat R M] [Module.Flat R N'] : M'.LinearDisjoint N' := (H.of_le_right_of_flat hn).of_le_left_of_flat hm /-- If `N` is flat, `M` is contained in `i(R)`, where `i : R → S` is the structure map, then `M` and `N` are linearly disjoint. -/ theorem of_left_le_one_of_flat (h : M ≤ 1) [Module.Flat R N] : M.LinearDisjoint N := (one_left N).of_le_left_of_flat h /-- If `M` is flat, `N` is contained in `i(R)`, where `i : R → S` is the structure map, then `M` and `N` are linearly disjoint. -/ theorem of_right_le_one_of_flat (h : N ≤ 1) [Module.Flat R M] : M.LinearDisjoint N := (one_right M).of_le_right_of_flat h section not_linearIndependent_pair variable {M N} section variable (H : M.LinearDisjoint N) include H section variable [Nontrivial R] /-- If `M` and `N` are linearly disjoint, if `M` is flat, then any two commutative elements of `↥(M ⊓ N)` are not `R`-linearly independent (namely, their span is not `R ^ 2`). -/ theorem not_linearIndependent_pair_of_commute_of_flat_left [Module.Flat R M] (a b : ↥(M ⊓ N)) (hc : Commute a.1 b.1) : ¬LinearIndependent R ![a, b] := fun h ↦ by let n : Fin 2 → N := (inclusion inf_le_right) ∘ ![a, b] have hn : LinearIndependent R n := h.map' _ (ker_inclusion _ _ _) -- need this instance otherwise it only has semigroup structure letI : AddCommGroup (Fin 2 →₀ M) := Finsupp.instAddCommGroup let m : Fin 2 →₀ M := .single 0 ⟨b.1, b.2.1⟩ - .single 1 ⟨a.1, a.2.1⟩ have hm : mulRightMap M n m = 0 := by simp [m, n, show _ * _ = _ * _ from hc] rw [← LinearMap.mem_ker, H.linearIndependent_right_of_flat hn, mem_bot] at hm simp only [Fin.isValue, sub_eq_zero, Finsupp.single_eq_single_iff, zero_ne_one, Subtype.mk.injEq, SetLike.coe_eq_coe, false_and, false_or, m] at hm repeat rw [AddSubmonoid.mk_eq_zero, ZeroMemClass.coe_eq_zero] at hm exact h.ne_zero 0 hm.2 /-- If `M` and `N` are linearly disjoint, if `N` is flat, then any two commutative elements of `↥(M ⊓ N)` are not `R`-linearly independent (namely, their span is not `R ^ 2`). -/ theorem not_linearIndependent_pair_of_commute_of_flat_right [Module.Flat R N] (a b : ↥(M ⊓ N)) (hc : Commute a.1 b.1) : ¬LinearIndependent R ![a, b] := fun h ↦ by let m : Fin 2 → M := (inclusion inf_le_left) ∘ ![a, b] have hm : LinearIndependent R m := h.map' _ (ker_inclusion _ _ _) -- need this instance otherwise it only has semigroup structure letI : AddCommGroup (Fin 2 →₀ N) := Finsupp.instAddCommGroup let n : Fin 2 →₀ N := .single 0 ⟨b.1, b.2.2⟩ - .single 1 ⟨a.1, a.2.2⟩ have hn : mulLeftMap N m n = 0 := by simp [m, n, show _ * _ = _ * _ from hc] rw [← LinearMap.mem_ker, H.linearIndependent_left_of_flat hm, mem_bot] at hn simp only [Fin.isValue, sub_eq_zero, Finsupp.single_eq_single_iff, zero_ne_one, Subtype.mk.injEq, SetLike.coe_eq_coe, false_and, false_or, n] at hn repeat rw [AddSubmonoid.mk_eq_zero, ZeroMemClass.coe_eq_zero] at hn exact h.ne_zero 0 hn.2 /-- If `M` and `N` are linearly disjoint, if one of `M` and `N` is flat, then any two commutative elements of `↥(M ⊓ N)` are not `R`-linearly independent (namely, their span is not `R ^ 2`). -/ theorem not_linearIndependent_pair_of_commute_of_flat (hf : Module.Flat R M ∨ Module.Flat R N) (a b : ↥(M ⊓ N)) (hc : Commute a.1 b.1) : ¬LinearIndependent R ![a, b] := by rcases hf with _ | _ · exact H.not_linearIndependent_pair_of_commute_of_flat_left a b hc · exact H.not_linearIndependent_pair_of_commute_of_flat_right a b hc end /-- If `M` and `N` are linearly disjoint, if one of `M` and `N` is flat, if any two elements of `↥(M ⊓ N)` are commutative, then the rank of `↥(M ⊓ N)` is at most one. -/ theorem rank_inf_le_one_of_commute_of_flat (hf : Module.Flat R M ∨ Module.Flat R N) (hc : ∀ (m n : ↥(M ⊓ N)), Commute m.1 n.1) : Module.rank R ↥(M ⊓ N) ≤ 1 := by nontriviality R refine _root_.rank_le fun s h ↦ ?_ by_contra hs rw [not_le, ← Fintype.card_coe, Fintype.one_lt_card_iff_nontrivial] at hs obtain ⟨a, b, hab⟩ := hs.exists_pair_ne refine H.not_linearIndependent_pair_of_commute_of_flat hf a.1 b.1 (hc a.1 b.1) ?_ have := h.comp ![a, b] fun i j hij ↦ by fin_cases i <;> fin_cases j · rfl · simp [hab] at hij · simp [hab.symm] at hij · rfl convert this ext i fin_cases i <;> simp /-- If `M` and `N` are linearly disjoint, if `M` is flat, if any two elements of `↥(M ⊓ N)` are commutative, then the rank of `↥(M ⊓ N)` is at most one. -/ theorem rank_inf_le_one_of_commute_of_flat_left [Module.Flat R M] (hc : ∀ (m n : ↥(M ⊓ N)), Commute m.1 n.1) : Module.rank R ↥(M ⊓ N) ≤ 1 := H.rank_inf_le_one_of_commute_of_flat (Or.inl ‹_›) hc /-- If `M` and `N` are linearly disjoint, if `N` is flat, if any two elements of `↥(M ⊓ N)` are commutative, then the rank of `↥(M ⊓ N)` is at most one. -/ theorem rank_inf_le_one_of_commute_of_flat_right [Module.Flat R N] (hc : ∀ (m n : ↥(M ⊓ N)), Commute m.1 n.1) : Module.rank R ↥(M ⊓ N) ≤ 1 := H.rank_inf_le_one_of_commute_of_flat (Or.inr ‹_›) hc end /-- If `M` and itself are linearly disjoint, if `M` is flat, if any two elements of `M` are commutative, then the rank of `M` is at most one. -/ theorem rank_le_one_of_commute_of_flat_of_self (H : M.LinearDisjoint M) [Module.Flat R M] (hc : ∀ (m n : M), Commute m.1 n.1) : Module.rank R M ≤ 1 := by rw [← inf_of_le_left (le_refl M)] at hc ⊢ exact H.rank_inf_le_one_of_commute_of_flat_left hc end not_linearIndependent_pair end LinearDisjoint end Ring section CommRing namespace LinearDisjoint variable [CommRing R] [CommRing S] [Algebra R S] variable (M N : Submodule R S) section not_linearIndependent_pair variable {M N} section variable (H : M.LinearDisjoint N) include H section variable [Nontrivial R] /-- The `Submodule.LinearDisjoint.not_linearIndependent_pair_of_commute_of_flat_left` for commutative rings. -/ theorem not_linearIndependent_pair_of_flat_left [Module.Flat R M] (a b : ↥(M ⊓ N)) : ¬LinearIndependent R ![a, b] := H.not_linearIndependent_pair_of_commute_of_flat_left a b (mul_comm _ _) /-- The `Submodule.LinearDisjoint.not_linearIndependent_pair_of_commute_of_flat_right` for commutative rings. -/ theorem not_linearIndependent_pair_of_flat_right [Module.Flat R N] (a b : ↥(M ⊓ N)) : ¬LinearIndependent R ![a, b] := H.not_linearIndependent_pair_of_commute_of_flat_right a b (mul_comm _ _) /-- The `Submodule.LinearDisjoint.not_linearIndependent_pair_of_commute_of_flat` for commutative rings. -/ theorem not_linearIndependent_pair_of_flat (hf : Module.Flat R M ∨ Module.Flat R N) (a b : ↥(M ⊓ N)) : ¬LinearIndependent R ![a, b] := H.not_linearIndependent_pair_of_commute_of_flat hf a b (mul_comm _ _) end /-- The `Submodule.LinearDisjoint.rank_inf_le_one_of_commute_of_flat` for commutative rings. -/ theorem rank_inf_le_one_of_flat (hf : Module.Flat R M ∨ Module.Flat R N) : Module.rank R ↥(M ⊓ N) ≤ 1 := H.rank_inf_le_one_of_commute_of_flat hf fun _ _ ↦ mul_comm _ _ /-- The `Submodule.LinearDisjoint.rank_inf_le_one_of_commute_of_flat_left` for commutative rings. -/ theorem rank_inf_le_one_of_flat_left [Module.Flat R M] : Module.rank R ↥(M ⊓ N) ≤ 1 := H.rank_inf_le_one_of_commute_of_flat_left fun _ _ ↦ mul_comm _ _ /-- The `Submodule.LinearDisjoint.rank_inf_le_one_of_commute_of_flat_right` for commutative rings. -/ theorem rank_inf_le_one_of_flat_right [Module.Flat R N] : Module.rank R ↥(M ⊓ N) ≤ 1 := H.rank_inf_le_one_of_commute_of_flat_right fun _ _ ↦ mul_comm _ _ end /-- The `Submodule.LinearDisjoint.rank_le_one_of_commute_of_flat_of_self` for commutative rings. -/ theorem rank_le_one_of_flat_of_self (H : M.LinearDisjoint M) [Module.Flat R M] : Module.rank R M ≤ 1 := H.rank_le_one_of_commute_of_flat_of_self fun _ _ ↦ mul_comm _ _ end not_linearIndependent_pair end LinearDisjoint end CommRing end Submodule
.lake/packages/mathlib/Mathlib/LinearAlgebra/SpecialLinearGroup.lean
import Mathlib.LinearAlgebra.Determinant import Mathlib.LinearAlgebra.Dual.Basis import Mathlib.LinearAlgebra.Matrix.Dual import Mathlib.LinearAlgebra.GeneralLinearGroup import Mathlib.LinearAlgebra.Charpoly.BaseChange /-! # The special linear group of a module If `R` is a commutative ring and `V` is an `R`-module, we define `SpecialLinearGroup R V` as the subtype of linear equivalences `V ≃ₗ[R] V` with determinant 1. When `V` doesn't have a finite basis, the determinant is defined by 1 and the definition gives `V ≃ₗ[R] V`. The interest of this definition is that `SpecialLinearGroup R V` has a group structure. (Starting from linear maps wouldn't have worked.) The file is constructed parallel to the one defining `Matrix.SpecialLinearGroup`. We provide `SpecialLinearGroup.toLinearEquiv`: the canonical map from `SpecialLinearGroup R V` to `V ≃ₗ[R] V`, as a monoid hom. When `V` is free and finite over `R`, we define * `SpecialLinearGroup.dualMap` * `SpecialLinearGroup.baseChange` We define `Matrix.SpecialLinaerGruop.toLin'_equiv`: the mul equivalence from `Matrix.SpecialLinearGroup n R` to `SpecialLinearGroup R (n → R)` and its variant `Matrix.SpecialLinearGroup.toLin_equiv`, from `Matrix.SpecialLinearGroup n R` to `SpecialLinearGroup R V`, associated with a finite basis of `V`. -/ variable {R V : Type*} [CommRing R] [AddCommGroup V] [Module R V] variable (R V) in /-- The special linear group of a module. This is only meaningful when the module is finite and free, for otherwise, it coincides with the group of linear equivalences. -/ abbrev SpecialLinearGroup := { u : V ≃ₗ[R] V // u.det = 1 } namespace SpecialLinearGroup theorem det_eq_one (u : SpecialLinearGroup R V) : LinearMap.det (u : V →ₗ[R] V) = 1 := by simp [← LinearEquiv.coe_det, u.prop] instance : CoeFun (SpecialLinearGroup R V) (fun _ ↦ V → V) where coe u x := u.val x theorem ext_iff (u v : SpecialLinearGroup R V) : u = v ↔ ∀ x : V, u x = v x := by simp only [← Subtype.coe_inj, LinearEquiv.ext_iff] @[ext] theorem ext (u v : SpecialLinearGroup R V) : (∀ x, u x = v x) → u = v := (SpecialLinearGroup.ext_iff u v).mpr section rankOne theorem subsingleton_of_finrank_eq_one [Module.Free R V] (d1 : Module.finrank R V = 1) : Subsingleton (SpecialLinearGroup R V) where allEq u v := by nontriviality R ext x by_cases hx : x = 0 · simp [hx] suffices ∀ (u : SpecialLinearGroup R V), (u : V →ₗ[R] V) = LinearMap.id by simp only [LinearMap.ext_iff, LinearEquiv.coe_coe, LinearMap.id_coe, id_eq] at this simp [this u, this v] intro u ext x set c := (LinearEquiv.smul_id_of_finrank_eq_one d1).symm u with hc rw [LinearEquiv.eq_symm_apply] at hc suffices c = 1 by simp [← hc, LinearEquiv.smul_id_of_finrank_eq_one, this] have hu := u.prop simpa [← Units.val_inj, LinearEquiv.coe_det, ← hc, LinearEquiv.smul_id_of_finrank_eq_one, d1] using hu end rankOne instance : Inv (SpecialLinearGroup R V) := ⟨fun A => ⟨A⁻¹, by simp [A.prop]⟩⟩ instance : Mul (SpecialLinearGroup R V) := ⟨fun A B => ⟨A * B, by simp [A.prop, B.prop]⟩⟩ instance : Div (SpecialLinearGroup R V) := ⟨fun A B => ⟨A / B, by simp [A.prop, B.prop]⟩⟩ instance : One (SpecialLinearGroup R V) := ⟨⟨1, by simp⟩⟩ instance : Pow (SpecialLinearGroup R V) ℕ where pow x n := ⟨x ^ n, by simp [x.prop]⟩ instance : Pow (SpecialLinearGroup R V) ℤ where pow x n := ⟨x ^ n, by simp [x.prop]⟩ instance : Inhabited (SpecialLinearGroup R V) := ⟨1⟩ /-- The transpose of an element in `SpecialLinearGroup R V`. -/ def dualMap [Module.Free R V] [Module.Finite R V] (A : SpecialLinearGroup R V) : SpecialLinearGroup R (Module.Dual R V) := ⟨LinearEquiv.dualMap (A : V ≃ₗ[R] V), by simp only [← Units.val_inj, LinearEquiv.coe_det, Units.val_one, LinearEquiv.dualMap, LinearMap.det_dualMap] simp [← LinearEquiv.coe_det, A.prop]⟩ @[inherit_doc] scoped postfix:1024 "ᵀ" => SpecialLinearGroup.dualMap section CoeLemmas variable (A B : SpecialLinearGroup R V) theorem coe_mk (A : V ≃ₗ[R] V) (h : A.det = 1) : ↑(⟨A, h⟩ : SpecialLinearGroup R V) = A := rfl @[simp] theorem coe_mul : (A * B : SpecialLinearGroup R V) = (A * B : V ≃ₗ[R] V) := rfl @[simp] theorem coe_div : (A / B : SpecialLinearGroup R V) = (A / B : V ≃ₗ[R] V) := rfl @[simp] theorem coe_inv : (A : SpecialLinearGroup R V)⁻¹ = (A⁻¹ : V ≃ₗ[R] V) := rfl @[simp] theorem coe_one : (1 : SpecialLinearGroup R V) = (1 : V ≃ₗ[R] V) := rfl @[simp] theorem det_coe : LinearEquiv.det (A : V ≃ₗ[R] V) = 1 := A.prop @[simp] theorem coe_pow (m : ℕ) : (A ^ m : SpecialLinearGroup R V) = (A : V ≃ₗ[R] V) ^ m := rfl @[simp] theorem coe_zpow (m : ℤ) : (A ^ m : SpecialLinearGroup R V) = (A : V ≃ₗ[R] V) ^ m := rfl @[simp] theorem coe_dualMap [Module.Free R V] [Module.Finite R V] : Aᵀ = (A : V ≃ₗ[R] V).dualMap := rfl end CoeLemmas instance : Group (SpecialLinearGroup R V) := fast_instance% Function.Injective.group _ Subtype.coe_injective coe_one coe_mul coe_inv coe_div coe_pow coe_zpow /-- A version of `Matrix.toLin' A` that produces linear equivalences. -/ def toLinearEquiv : SpecialLinearGroup R V →* V ≃ₗ[R] V where toFun A := A.val map_one' := coe_one map_mul' := coe_mul theorem toLinearEquiv_apply (A : SpecialLinearGroup R V) (v : V) : A.toLinearEquiv v = A v := rfl theorem toLinearEquiv_to_linearMap (A : SpecialLinearGroup R V) : (SpecialLinearGroup.toLinearEquiv A) = (A : V →ₗ[R] V) := rfl theorem toLinearEquiv_symm_apply (A : SpecialLinearGroup R V) (v : V) : A.toLinearEquiv.symm v = A⁻¹ v := rfl theorem toLinearEquiv_symm_to_linearMap (A : SpecialLinearGroup R V) : A.toLinearEquiv.symm = ((A⁻¹ : SpecialLinearGroup R V) : V →ₗ[R] V) := rfl theorem toLinearEquiv_injective : Function.Injective (toLinearEquiv : SpecialLinearGroup R V →* V ≃ₗ[R] V) := Subtype.val_injective /-- The canonical group morphism from the special linear group to the general linear group. -/ def toGeneralLinearGroup : SpecialLinearGroup R V →* LinearMap.GeneralLinearGroup R V := (LinearMap.GeneralLinearGroup.generalLinearEquiv R V).symm.toMonoidHom.comp toLinearEquiv lemma toGeneralLinearGroup_toLinearEquiv_apply (u : SpecialLinearGroup R V) : u.toGeneralLinearGroup.toLinearEquiv = u.toLinearEquiv := rfl lemma coe_toGeneralLinearGroup_apply (u : SpecialLinearGroup R V) : u.toGeneralLinearGroup.val = u.toLinearEquiv := rfl lemma toGeneralLinearGroup_injective : Function.Injective ⇑(toGeneralLinearGroup (R := R) (V := V)) := by simp [toGeneralLinearGroup, toLinearEquiv_injective] lemma mem_range_toGeneralLinearGroup_iff {u : LinearMap.GeneralLinearGroup R V} : u ∈ Set.range ⇑(toGeneralLinearGroup (R := R) (V := V)) ↔ u.toLinearEquiv.det = 1 := by constructor · rintro ⟨v, hv⟩ rw [← hv, toGeneralLinearGroup_toLinearEquiv_apply] exact v.prop · intro hu refine ⟨⟨u.toLinearEquiv, hu⟩, rfl⟩ section baseChange open TensorProduct variable {S : Type*} [CommRing S] [Algebra R S] [Module.Free R V] [Module.Finite R V] /-- By base change, an `R`-algebra `S` induces a group homomorphism from `SpecialLinearGroup R V` to `SpecialLinearGroup S (S ⊗[R] V)`. -/ @[simps] def baseChange : SpecialLinearGroup R V →* SpecialLinearGroup S (S ⊗[R] V) where toFun g := ⟨LinearEquiv.baseChange R S V V g, by rw [LinearEquiv.det_baseChange, g.prop, map_one]⟩ map_one' := Subtype.ext <| by simp map_mul' x y := Subtype.ext <| by simp [LinearEquiv.baseChange_mul] end baseChange variable {W X : Type*} [AddCommGroup W] [Module R W] [AddCommGroup X] [Module R X] /-- The isomorphism between special linear groups of isomorphic modules. -/ def congr_linearEquiv (e : V ≃ₗ[R] W) : SpecialLinearGroup R V ≃* SpecialLinearGroup R W where toFun f := ⟨e.symm ≪≫ₗ f ≪≫ₗ e, by simp [f.prop]⟩ invFun g := ⟨e ≪≫ₗ g ≪≫ₗ e.symm, by nth_rewrite 1 [← LinearEquiv.symm_symm e] rw [LinearEquiv.det_conj g e.symm, g.prop]⟩ left_inv f := Subtype.coe_injective <| by aesop right_inv g := Subtype.coe_injective <| by aesop map_mul' f g := Subtype.coe_injective <| by aesop @[simp] theorem congr_linearEquiv_coe_apply (e : V ≃ₗ[R] W) (f : SpecialLinearGroup R V) : (congr_linearEquiv e f : W ≃ₗ[R] W) = e.symm ≪≫ₗ f ≪≫ₗ e := rfl @[simp] theorem congr_linearEquiv_apply_apply (e : V ≃ₗ[R] W) (f : SpecialLinearGroup R V) (x : W) : congr_linearEquiv e f x = e (f (e.symm x)) := rfl theorem congr_linearEquiv_symm (e : V ≃ₗ[R] W) : (congr_linearEquiv e).symm = congr_linearEquiv e.symm := rfl theorem congr_linearEquiv_trans (e : V ≃ₗ[R] W) (f : W ≃ₗ[R] X) : (congr_linearEquiv e).trans (congr_linearEquiv f) = congr_linearEquiv (e.trans f) := by rfl theorem congr_linearEquiv_refl : congr_linearEquiv (LinearEquiv.refl R V) = MulEquiv.refl _ := by rfl end SpecialLinearGroup section Matrix variable {n : Type*} [Fintype n] [DecidableEq n] (b : Module.Basis n R V) /-- The canonical isomorphism from `SL(n, R)` to the special linear group of the module `n → R`. -/ def _root_.Matrix.SpecialLinearGroup.toLin'_equiv : Matrix.SpecialLinearGroup n R ≃* SpecialLinearGroup R (n → R) where toFun A := ⟨Matrix.SpecialLinearGroup.toLin' A, by simp [← Units.val_inj, LinearEquiv.coe_det, Units.val_one, Matrix.SpecialLinearGroup.toLin'_to_linearMap]⟩ invFun u := ⟨LinearMap.toMatrix' u, by simp [← LinearEquiv.coe_det, u.prop]⟩ left_inv A := Subtype.coe_injective <| by rw [← LinearEquiv.eq_symm_apply, LinearMap.toMatrix'_symm, Matrix.SpecialLinearGroup.toLin'_to_linearMap] right_inv u := Subtype.coe_injective <| by simp [← LinearEquiv.toLinearMap_inj, Matrix.SpecialLinearGroup.toLin'] map_mul' A B := Subtype.coe_injective (by simp) /-- The isomorphism from `Matrix.SpecialLinearGroup n R` to the special linear group of a module associated with a basis of that module. -/ noncomputable def _root_.Matrix.SpecialLinearGroup.toLin_equiv (b : Module.Basis n R V) : Matrix.SpecialLinearGroup n R ≃* SpecialLinearGroup R V := Matrix.SpecialLinearGroup.toLin'_equiv.trans (SpecialLinearGroup.congr_linearEquiv (b.repr.trans (Finsupp.linearEquivFunOnFinite R R n)).symm) end Matrix
.lake/packages/mathlib/Mathlib/LinearAlgebra/UnitaryGroup.lean
import Mathlib.Algebra.Star.Unitary import Mathlib.Data.Matrix.Reflection import Mathlib.LinearAlgebra.GeneralLinearGroup import Mathlib.LinearAlgebra.Matrix.ToLin import Mathlib.LinearAlgebra.Matrix.NonsingularInverse /-! # The Unitary Group This file defines elements of the unitary group `Matrix.unitaryGroup n α`, where `α` is a `StarRing`. This consists of all `n` by `n` matrices with entries in `α` such that the star-transpose is its inverse. In addition, we define the group structure on `Matrix.unitaryGroup n α`, and the embedding into the general linear group `LinearMap.GeneralLinearGroup α (n → α)`. We also define the orthogonal group `Matrix.orthogonalGroup n R`, where `R` is a `CommRing`. ## Main Definitions * `Matrix.unitaryGroup` is the submonoid of matrices where the star-transpose is the inverse; the group structure (under multiplication) is inherited from a more general `unitary` construction. * `Matrix.UnitaryGroup.embeddingGL` is the embedding `Matrix.unitaryGroup n α → GLₙ(α)`, where `GLₙ(α)` is `LinearMap.GeneralLinearGroup α (n → α)`. * `Matrix.orthogonalGroup` is the submonoid of matrices where the transpose is the inverse. ## References * https://en.wikipedia.org/wiki/Unitary_group ## Tags matrix group, group, unitary group, orthogonal group -/ universe u v namespace Matrix open LinearMap Matrix section variable (n : Type u) [DecidableEq n] [Fintype n] variable (α : Type v) [CommRing α] [StarRing α] /-- `Matrix.unitaryGroup n` is the group of `n` by `n` matrices where the star-transpose is the inverse. -/ abbrev unitaryGroup : Submonoid (Matrix n n α) := unitary (Matrix n n α) -- the group and star structure is already defined in another file example : Group (unitaryGroup n α) := inferInstance example : StarMul (unitaryGroup n α) := inferInstance end variable {n : Type u} [DecidableEq n] [Fintype n] variable {α : Type v} [CommRing α] [StarRing α] {A : Matrix n n α} theorem mem_unitaryGroup_iff : A ∈ Matrix.unitaryGroup n α ↔ A * star A = 1 := by refine ⟨And.right, fun hA => ⟨?_, hA⟩⟩ simpa only [mul_eq_one_comm] using hA theorem mem_unitaryGroup_iff' : A ∈ Matrix.unitaryGroup n α ↔ star A * A = 1 := by refine ⟨And.left, fun hA => ⟨hA, ?_⟩⟩ rwa [mul_eq_one_comm] at hA theorem det_of_mem_unitary {A : Matrix n n α} (hA : A ∈ Matrix.unitaryGroup n α) : A.det ∈ unitary α := by constructor · simpa [star, det_transpose] using congr_arg det hA.1 · simpa [star, det_transpose] using congr_arg det hA.2 open scoped Kronecker in /-- The kronecker product of two unitary matrices is unitary. This is stated for `unitary` instead of `unitaryGroup` as it holds even for non-commutative coefficients. -/ theorem kronecker_mem_unitary {R m : Type*} [Semiring R] [StarRing R] [Fintype m] [DecidableEq m] {U₁ : Matrix n n R} {U₂ : Matrix m m R} (hU₁ : U₁ ∈ unitary (Matrix n n R)) (hU₂ : U₂ ∈ unitary (Matrix m m R)) : U₁ ⊗ₖ U₂ ∈ unitary (Matrix (n × m) (n × m) R) := by simp_rw [Unitary.mem_iff, star_eq_conjTranspose, conjTranspose_kronecker'] constructor <;> ext <;> simp only [mul_apply, submatrix_apply, kroneckerMap_apply, Prod.fst_swap, conjTranspose_apply, ← star_apply, Prod.snd_swap, ← mul_assoc] · simp_rw [mul_assoc _ (star U₁ _ _), ← Finset.univ_product_univ, Finset.sum_product] rw [Finset.sum_comm] simp_rw [← Finset.sum_mul, ← Finset.mul_sum, ← Matrix.mul_apply, hU₁.1, Matrix.one_apply, mul_boole, ite_mul, zero_mul, Finset.sum_ite_irrel, ← Matrix.mul_apply, hU₂.1, Matrix.one_apply, Finset.sum_const_zero, ← ite_and, Prod.eq_iff_fst_eq_snd_eq] · simp_rw [mul_assoc _ _ (star U₂ _ _), ← Finset.univ_product_univ, Finset.sum_product, ← Finset.sum_mul, ← Finset.mul_sum, ← Matrix.mul_apply, hU₂.2, Matrix.one_apply, mul_boole, ite_mul, zero_mul, Finset.sum_ite_irrel, ← Matrix.mul_apply, hU₁.2, Matrix.one_apply, Finset.sum_const_zero, ← ite_and, and_comm, Prod.eq_iff_fst_eq_snd_eq] namespace UnitaryGroup instance coeMatrix : Coe (unitaryGroup n α) (Matrix n n α) := ⟨Subtype.val⟩ instance coeFun : CoeFun (unitaryGroup n α) fun _ => n → n → α where coe A := A.val /-- `Matrix.UnitaryGroup.toLin' A` is matrix multiplication of vectors by `A`, as a linear map. After the group structure on `Matrix.unitaryGroup n` is defined, we show in `Matrix.UnitaryGroup.toLinearEquiv` that this gives a linear equivalence. -/ def toLin' (A : unitaryGroup n α) := Matrix.toLin' A.1 theorem ext_iff (A B : unitaryGroup n α) : A = B ↔ ∀ i j, A i j = B i j := Subtype.ext_iff.trans ⟨fun h i j => congr_fun (congr_fun h i) j, Matrix.ext⟩ @[ext] theorem ext (A B : unitaryGroup n α) : (∀ i j, A i j = B i j) → A = B := (UnitaryGroup.ext_iff A B).mpr theorem star_mul_self (A : unitaryGroup n α) : star A.1 * A.1 = 1 := A.2.1 @[simp] theorem det_isUnit (A : unitaryGroup n α) : IsUnit (A : Matrix n n α).det := isUnit_iff_isUnit_det _ |>.mp <| (Unitary.toUnits A).isUnit section CoeLemmas variable (A B : unitaryGroup n α) @[simp] theorem inv_val : ↑A⁻¹ = (star A : Matrix n n α) := rfl @[simp] theorem inv_apply : ⇑A⁻¹ = (star A : Matrix n n α) := rfl @[simp] theorem mul_val : ↑(A * B) = A.1 * B.1 := rfl @[simp] theorem mul_apply : ⇑(A * B) = A.1 * B.1 := rfl @[simp] theorem one_val : ↑(1 : unitaryGroup n α) = (1 : Matrix n n α) := rfl @[simp] theorem one_apply : ⇑(1 : unitaryGroup n α) = (1 : Matrix n n α) := rfl @[simp] theorem toLin'_mul : toLin' (A * B) = (toLin' A).comp (toLin' B) := Matrix.toLin'_mul A.1 B.1 @[simp] theorem toLin'_one : toLin' (1 : unitaryGroup n α) = LinearMap.id := Matrix.toLin'_one end CoeLemmas -- TODO: redefine `toGL`/`embeddingGL` as in the following example, -- so that we can get `toLinearEquiv` from `GeneralLinearGroup.toLinearEquiv` example : unitaryGroup n α →* GeneralLinearGroup α (n → α) := .toHomUnits ⟨⟨toLin', toLin'_one⟩, toLin'_mul⟩ /-- `Matrix.unitaryGroup.toLinearEquiv A` is matrix multiplication of vectors by `A`, as a linear equivalence. -/ def toLinearEquiv (A : unitaryGroup n α) : (n → α) ≃ₗ[α] n → α := { Matrix.toLin' A.1 with invFun := toLin' A⁻¹ left_inv := fun x => calc (toLin' A⁻¹).comp (toLin' A) x = (toLin' (A⁻¹ * A)) x := by rw [← toLin'_mul] _ = x := by rw [inv_mul_cancel, toLin'_one, id_apply] right_inv := fun x => calc (toLin' A).comp (toLin' A⁻¹) x = toLin' (A * A⁻¹) x := by rw [← toLin'_mul] _ = x := by rw [mul_inv_cancel, toLin'_one, id_apply] } /-- `Matrix.unitaryGroup.toGL` is the map from the unitary group to the general linear group -/ def toGL (A : unitaryGroup n α) : GeneralLinearGroup α (n → α) := GeneralLinearGroup.ofLinearEquiv (toLinearEquiv A) theorem coe_toGL (A : unitaryGroup n α) : (toGL A).1 = toLin' A := rfl @[simp] theorem toGL_one : toGL (1 : unitaryGroup n α) = 1 := Units.ext <| by simp only [coe_toGL, toLin'_one] rfl @[simp] theorem toGL_mul (A B : unitaryGroup n α) : toGL (A * B) = toGL A * toGL B := Units.ext <| by simp only [coe_toGL, toLin'_mul] rfl /-- `Matrix.unitaryGroup.embeddingGL` is the embedding from `Matrix.unitaryGroup n α` to `LinearMap.GeneralLinearGroup n α`. -/ def embeddingGL : unitaryGroup n α →* GeneralLinearGroup α (n → α) := ⟨⟨fun A => toGL A, toGL_one⟩, toGL_mul⟩ end UnitaryGroup section specialUnitaryGroup variable (n) (α) /-- `Matrix.specialUnitaryGroup` is the group of unitary `n` by `n` matrices where the determinant is 1. (This definition is only correct if 2 is invertible.) -/ def specialUnitaryGroup : Submonoid (Matrix n n α) := unitaryGroup n α ⊓ MonoidHom.mker detMonoidHom variable {n} {α} theorem specialUnitaryGroup_le_unitaryGroup : specialUnitaryGroup n α ≤ unitaryGroup n α := inf_le_left theorem mem_specialUnitaryGroup_iff : A ∈ specialUnitaryGroup n α ↔ A ∈ unitaryGroup n α ∧ A.det = 1 := Iff.rfl instance : StarMul (specialUnitaryGroup n α) where star A := ⟨star A, by simpa using A.prop.1, by have := A.prop.2; simp_all [star_eq_conjTranspose]⟩ star_mul A B := Subtype.ext <| star_mul A.1 B.1 star_involutive A := Subtype.ext <| star_involutive A.1 @[simp, norm_cast] theorem specialUnitaryGroup.coe_star (A : specialUnitaryGroup n α) : (star A).1 = star A.1 := rfl instance : Inv (specialUnitaryGroup n α) where inv := star theorem star_eq_inv (A : specialUnitaryGroup n α) : star A = A⁻¹ := rfl instance : Group (specialUnitaryGroup n α) where inv_mul_cancel A := Subtype.ext A.prop.1.1 end specialUnitaryGroup section OrthogonalGroup variable (n) (R : Type v) [CommRing R] -- TODO: will lemmas about `Matrix.orthogonalGroup` work without making -- `starRingOfComm` a local instance? E.g., can we talk about unitary group and orthogonal group -- at the same time? attribute [local instance] starRingOfComm /-- `Matrix.orthogonalGroup n` is the group of `n` by `n` matrices where the transpose is the inverse. -/ abbrev orthogonalGroup := unitaryGroup n R theorem mem_orthogonalGroup_iff {A : Matrix n n R} : A ∈ Matrix.orthogonalGroup n R ↔ A * Aᵀ = 1 := mem_unitaryGroup_iff theorem mem_orthogonalGroup_iff' {A : Matrix n n R} : A ∈ Matrix.orthogonalGroup n R ↔ Aᵀ * A = 1 := mem_unitaryGroup_iff' end OrthogonalGroup section specialOrthogonalGroup variable (n) (R : Type v) [CommRing R] attribute [local instance] starRingOfComm /-- `Matrix.specialOrthogonalGroup n` is the group of orthogonal `n` by `n` where the determinant is one. (This definition is only correct if 2 is invertible.) -/ abbrev specialOrthogonalGroup : Submonoid (Matrix n n R) := specialUnitaryGroup n R variable {n} {R} {A : Matrix n n R} -- the group and star structure is automatic from `specialUnitaryGroup` example : Group (specialOrthogonalGroup n R) := inferInstance example : StarMul (specialOrthogonalGroup n R) := inferInstance theorem mem_specialOrthogonalGroup_iff : A ∈ specialOrthogonalGroup n R ↔ A ∈ orthogonalGroup n R ∧ A.det = 1 := Iff.rfl @[simp] lemma of_mem_specialOrthogonalGroup_fin_two_iff {a b c d : R} : !![a, b; c, d] ∈ Matrix.specialOrthogonalGroup (Fin 2) R ↔ a = d ∧ b = -c ∧ a ^ 2 + b ^ 2 = 1 := by trans ((a * a + b * b = 1 ∧ a * c + b * d = 0) ∧ c * a + d * b = 0 ∧ c * c + d * d = 1) ∧ a * d - b * c = 1 · simp [Matrix.mem_specialOrthogonalGroup_iff, Matrix.mem_orthogonalGroup_iff, ← Matrix.ext_iff, Fin.forall_fin_succ, Matrix.vecHead, Matrix.vecTail] grind lemma mem_specialOrthogonalGroup_fin_two_iff {M : Matrix (Fin 2) (Fin 2) R} : M ∈ Matrix.specialOrthogonalGroup (Fin 2) R ↔ M 0 0 = M 1 1 ∧ M 0 1 = - M 1 0 ∧ M 0 0 ^ 2 + M 0 1 ^ 2 = 1 := by rw [← M.etaExpand_eq] exact of_mem_specialOrthogonalGroup_fin_two_iff end specialOrthogonalGroup end Matrix
.lake/packages/mathlib/Mathlib/LinearAlgebra/LinearPMap.lean
import Mathlib.LinearAlgebra.Prod /-! # Partially defined linear maps A `LinearPMap R E F` or `E →ₗ.[R] F` is a linear map from a submodule of `E` to `F`. We define a `SemilatticeInf` with `OrderBot` instance on this, and define three operations: * `mkSpanSingleton` defines a partial linear map defined on the span of a singleton. * `sup` takes two partial linear maps `f`, `g` that agree on the intersection of their domains, and returns the unique partial linear map on `f.domain ⊔ g.domain` that extends both `f` and `g`. * `sSup` takes a `DirectedOn (· ≤ ·)` set of partial linear maps, and returns the unique partial linear map on the `sSup` of their domains that extends all these maps. Moreover, we define * `LinearPMap.graph` is the graph of the partial linear map viewed as a submodule of `E × F`. Partially defined maps are currently used in `Mathlib` to prove Hahn-Banach theorem and its variations. Namely, `LinearPMap.sSup` implies that every chain of `LinearPMap`s is bounded above. They are also the basis for the theory of unbounded operators. -/ universe u v w /-- A `LinearPMap R E F` or `E →ₗ.[R] F` is a linear map from a submodule of `E` to `F`. -/ structure LinearPMap (R : Type u) [Ring R] (E : Type v) [AddCommGroup E] [Module R E] (F : Type w) [AddCommGroup F] [Module R F] where domain : Submodule R E toFun : domain →ₗ[R] F @[inherit_doc] notation:25 E " →ₗ.[" R:25 "] " F:0 => LinearPMap R E F variable {R : Type*} [Ring R] {E : Type*} [AddCommGroup E] [Module R E] {F : Type*} [AddCommGroup F] [Module R F] {G : Type*} [AddCommGroup G] [Module R G] namespace LinearPMap open Submodule @[coe] def toFun' (f : E →ₗ.[R] F) : f.domain → F := f.toFun instance : CoeFun (E →ₗ.[R] F) fun f : E →ₗ.[R] F => f.domain → F := ⟨toFun'⟩ @[simp] theorem toFun_eq_coe (f : E →ₗ.[R] F) (x : f.domain) : f.toFun x = f x := rfl @[ext (iff := false)] theorem ext {f g : E →ₗ.[R] F} (h : f.domain = g.domain) (h' : ∀ ⦃x : E⦄ ⦃hf : x ∈ f.domain⦄ ⦃hg : x ∈ g.domain⦄, f ⟨x, hf⟩ = g ⟨x, hg⟩) : f = g := by rcases f with ⟨f_dom, f⟩ rcases g with ⟨g_dom, g⟩ obtain rfl : f_dom = g_dom := h congr apply LinearMap.ext intro x apply h' /-- A dependent version of `ext`. -/ theorem dExt {f g : E →ₗ.[R] F} (h : f.domain = g.domain) (h' : ∀ ⦃x : f.domain⦄ ⦃y : g.domain⦄ (_h : (x : E) = y), f x = g y) : f = g := ext h fun _ _ _ ↦ h' rfl @[simp] theorem map_zero (f : E →ₗ.[R] F) : f 0 = 0 := f.toFun.map_zero theorem ext_iff {f g : E →ₗ.[R] F} : f = g ↔ f.domain = g.domain ∧ ∀ ⦃x : E⦄ ⦃hf : x ∈ f.domain⦄ ⦃hg : x ∈ g.domain⦄, f ⟨x, hf⟩ = g ⟨x, hg⟩ := ⟨by rintro rfl; simp, fun ⟨deq, feq⟩ ↦ ext deq feq⟩ theorem dExt_iff {f g : E →ₗ.[R] F} : f = g ↔ ∃ _domain_eq : f.domain = g.domain, ∀ ⦃x : f.domain⦄ ⦃y : g.domain⦄ (_h : (x : E) = y), f x = g y := ⟨fun EQ => EQ ▸ ⟨rfl, fun x y h => by congr exact mod_cast h⟩, fun ⟨deq, feq⟩ => dExt deq feq⟩ theorem ext' {s : Submodule R E} {f g : s →ₗ[R] F} (h : f = g) : mk s f = mk s g := h ▸ rfl theorem map_add (f : E →ₗ.[R] F) (x y : f.domain) : f (x + y) = f x + f y := f.toFun.map_add x y theorem map_neg (f : E →ₗ.[R] F) (x : f.domain) : f (-x) = -f x := f.toFun.map_neg x theorem map_sub (f : E →ₗ.[R] F) (x y : f.domain) : f (x - y) = f x - f y := f.toFun.map_sub x y theorem map_smul (f : E →ₗ.[R] F) (c : R) (x : f.domain) : f (c • x) = c • f x := f.toFun.map_smul c x @[simp] theorem mk_apply (p : Submodule R E) (f : p →ₗ[R] F) (x : p) : mk p f x = f x := rfl /-- The unique `LinearPMap` on `R ∙ x` that sends `x` to `y`. This version works for modules over rings, and requires a proof of `∀ c, c • x = 0 → c • y = 0`. -/ noncomputable def mkSpanSingleton' (x : E) (y : F) (H : ∀ c : R, c • x = 0 → c • y = 0) : E →ₗ.[R] F where domain := R ∙ x toFun := have H : ∀ c₁ c₂ : R, c₁ • x = c₂ • x → c₁ • y = c₂ • y := by intro c₁ c₂ h rw [← sub_eq_zero, ← sub_smul] at h ⊢ exact H _ h { toFun z := Classical.choose (mem_span_singleton.1 z.prop) • y map_add' y z := by rw [← add_smul, H] have (w : R ∙ x) := Classical.choose_spec (mem_span_singleton.1 w.prop) simp only [add_smul, this, ← coe_add] map_smul' c z := by rw [smul_smul, H] have (w : R ∙ x) := Classical.choose_spec (mem_span_singleton.1 w.prop) simp only [mul_smul, this] apply coe_smul } @[simp] theorem domain_mkSpanSingleton (x : E) (y : F) (H : ∀ c : R, c • x = 0 → c • y = 0) : (mkSpanSingleton' x y H).domain = R ∙ x := rfl @[simp] theorem mkSpanSingleton'_apply (x : E) (y : F) (H : ∀ c : R, c • x = 0 → c • y = 0) (c : R) (h) : mkSpanSingleton' x y H ⟨c • x, h⟩ = c • y := by dsimp [mkSpanSingleton'] rw [← sub_eq_zero, ← sub_smul] apply H simp only [sub_smul, sub_eq_zero] apply Classical.choose_spec (mem_span_singleton.1 h) @[simp] theorem mkSpanSingleton'_apply_self (x : E) (y : F) (H : ∀ c : R, c • x = 0 → c • y = 0) (h) : mkSpanSingleton' x y H ⟨x, h⟩ = y := by conv_rhs => rw [← one_smul R y] rw [← mkSpanSingleton'_apply x y H 1 ?_] · congr rw [one_smul] · rwa [one_smul] /-- The unique `LinearPMap` on `span R {x}` that sends a non-zero vector `x` to `y`. This version works for modules over division rings. -/ noncomputable abbrev mkSpanSingleton {K E F : Type*} [DivisionRing K] [AddCommGroup E] [Module K E] [AddCommGroup F] [Module K F] (x : E) (y : F) (hx : x ≠ 0) : E →ₗ.[K] F := mkSpanSingleton' x y fun c hc => (smul_eq_zero.1 hc).elim (fun hc => by rw [hc, zero_smul]) fun hx' => absurd hx' hx theorem mkSpanSingleton_apply (K : Type*) {E F : Type*} [DivisionRing K] [AddCommGroup E] [Module K E] [AddCommGroup F] [Module K F] {x : E} (hx : x ≠ 0) (y : F) : mkSpanSingleton x y hx ⟨x, (Submodule.mem_span_singleton_self x : x ∈ Submodule.span K {x})⟩ = y := LinearPMap.mkSpanSingleton'_apply_self _ _ _ _ /-- Projection to the first coordinate as a `LinearPMap` -/ protected def fst (p : Submodule R E) (p' : Submodule R F) : E × F →ₗ.[R] E where domain := p.prod p' toFun := (LinearMap.fst R E F).comp (p.prod p').subtype @[simp] theorem fst_apply (p : Submodule R E) (p' : Submodule R F) (x : p.prod p') : LinearPMap.fst p p' x = (x : E × F).1 := rfl /-- Projection to the second coordinate as a `LinearPMap` -/ protected def snd (p : Submodule R E) (p' : Submodule R F) : E × F →ₗ.[R] F where domain := p.prod p' toFun := (LinearMap.snd R E F).comp (p.prod p').subtype @[simp] theorem snd_apply (p : Submodule R E) (p' : Submodule R F) (x : p.prod p') : LinearPMap.snd p p' x = (x : E × F).2 := rfl instance le : LE (E →ₗ.[R] F) := ⟨fun f g => f.domain ≤ g.domain ∧ ∀ ⦃x : f.domain⦄ ⦃y : g.domain⦄ (_h : (x : E) = y), f x = g y⟩ theorem apply_comp_inclusion {T S : E →ₗ.[R] F} (h : T ≤ S) (x : T.domain) : T x = S (Submodule.inclusion h.1 x) := h.2 rfl theorem exists_of_le {T S : E →ₗ.[R] F} (h : T ≤ S) (x : T.domain) : ∃ y : S.domain, (x : E) = y ∧ T x = S y := ⟨⟨x.1, h.1 x.2⟩, ⟨rfl, h.2 rfl⟩⟩ theorem eq_of_le_of_domain_eq {f g : E →ₗ.[R] F} (hle : f ≤ g) (heq : f.domain = g.domain) : f = g := dExt heq hle.2 /-- Given two partial linear maps `f`, `g`, the set of points `x` such that both `f` and `g` are defined at `x` and `f x = g x` form a submodule. -/ def eqLocus (f g : E →ₗ.[R] F) : Submodule R E where carrier := { x | ∃ (hf : x ∈ f.domain) (hg : x ∈ g.domain), f ⟨x, hf⟩ = g ⟨x, hg⟩ } zero_mem' := ⟨zero_mem _, zero_mem _, f.map_zero.trans g.map_zero.symm⟩ add_mem' {x y} := fun ⟨hfx, hgx, hx⟩ ⟨hfy, hgy, hy⟩ ↦ ⟨add_mem hfx hfy, add_mem hgx hgy, by simp_all [← AddMemClass.mk_add_mk, f.map_add, g.map_add]⟩ smul_mem' c x := fun ⟨hfx, hgx, hx⟩ ↦ ⟨smul_mem _ c hfx, smul_mem _ c hgx, by have {f : E →ₗ.[R] F} (hfx) : (⟨c • x, smul_mem _ c hfx⟩ : f.domain) = c • ⟨x, hfx⟩ := by simp rw [this hfx, this hgx, f.map_smul, g.map_smul, hx]⟩ instance bot : Bot (E →ₗ.[R] F) := ⟨⟨⊥, 0⟩⟩ instance inhabited : Inhabited (E →ₗ.[R] F) := ⟨⊥⟩ instance semilatticeInf : SemilatticeInf (E →ₗ.[R] F) where le_refl f := ⟨le_refl f.domain, fun _ _ h => Subtype.eq h ▸ rfl⟩ le_trans := fun _ _ _ ⟨fg_le, fg_eq⟩ ⟨gh_le, gh_eq⟩ => ⟨le_trans fg_le gh_le, fun x _ hxz => have hxy : (x : E) = inclusion fg_le x := rfl (fg_eq hxy).trans (gh_eq <| hxy.symm.trans hxz)⟩ le_antisymm _ _ fg gf := eq_of_le_of_domain_eq fg (le_antisymm fg.1 gf.1) inf f g := ⟨f.eqLocus g, f.toFun.comp <| inclusion fun _x hx => hx.fst⟩ le_inf := by intro f g h ⟨fg_le, fg_eq⟩ ⟨fh_le, fh_eq⟩ exact ⟨fun x hx => ⟨fg_le hx, fh_le hx, (fg_eq (x := ⟨x, hx⟩) rfl).symm.trans (fh_eq rfl)⟩, fun x ⟨y, yg, hy⟩ h => fg_eq h⟩ inf_le_left f _ := ⟨fun _ hx => hx.fst, fun _ _ h => congr_arg f <| Subtype.eq <| h⟩ inf_le_right _ g := ⟨fun _ hx => hx.snd.fst, fun ⟨_, _, _, hx⟩ _ h => hx.trans <| congr_arg g <| Subtype.eq <| h⟩ instance orderBot : OrderBot (E →ₗ.[R] F) where bot_le f := ⟨bot_le, fun x y h => by have hx : x = 0 := Subtype.eq ((mem_bot R).1 x.2) have hy : y = 0 := Subtype.eq (h.symm.trans (congr_arg _ hx)) rw [hx, hy, map_zero, map_zero]⟩ theorem le_of_eqLocus_ge {f g : E →ₗ.[R] F} (H : f.domain ≤ f.eqLocus g) : f ≤ g := suffices f ≤ f ⊓ g from le_trans this inf_le_right ⟨H, fun _x _y hxy => ((inf_le_left : f ⊓ g ≤ f).2 hxy.symm).symm⟩ theorem domain_mono : StrictMono (@domain R _ E _ _ F _ _) := fun _f _g hlt => lt_of_le_of_ne hlt.1.1 fun heq => ne_of_lt hlt <| eq_of_le_of_domain_eq (le_of_lt hlt) heq private theorem sup_aux (f g : E →ₗ.[R] F) (h : ∀ (x : f.domain) (y : g.domain), (x : E) = y → f x = g y) : ∃ fg : ↥(f.domain ⊔ g.domain) →ₗ[R] F, ∀ (x : f.domain) (y : g.domain) (z : ↥(f.domain ⊔ g.domain)), (x : E) + y = ↑z → fg z = f x + g y := by choose x hx y hy hxy using fun z : ↥(f.domain ⊔ g.domain) => mem_sup.1 z.prop set fg := fun z => f ⟨x z, hx z⟩ + g ⟨y z, hy z⟩ have fg_eq : ∀ (x' : f.domain) (y' : g.domain) (z' : ↥(f.domain ⊔ g.domain)) (_H : (x' : E) + y' = z'), fg z' = f x' + g y' := by intro x' y' z' H dsimp [fg] rw [add_comm, ← sub_eq_sub_iff_add_eq_add, eq_comm, ← map_sub, ← map_sub] apply h simp only [← eq_sub_iff_add_eq] at hxy simp only [AddSubgroupClass.coe_sub, hxy, ← sub_add, ← sub_sub, sub_self, zero_sub, ← H] apply neg_add_eq_sub use { toFun := fg, map_add' := ?_, map_smul' := ?_ }, fg_eq · rintro ⟨z₁, hz₁⟩ ⟨z₂, hz₂⟩ rw [← add_assoc, add_right_comm (f _), ← map_add, add_assoc, ← map_add] apply fg_eq simp only [coe_add, ← add_assoc] rw [add_right_comm (x _), hxy, add_assoc, hxy, coe_mk, coe_mk] · intro c z rw [smul_add, ← map_smul, ← map_smul] apply fg_eq simp only [coe_smul, ← smul_add, hxy, RingHom.id_apply] /-- Given two partial linear maps that agree on the intersection of their domains, `f.sup g h` is the unique partial linear map on `f.domain ⊔ g.domain` that agrees with `f` and `g`. -/ protected noncomputable def sup (f g : E →ₗ.[R] F) (h : ∀ (x : f.domain) (y : g.domain), (x : E) = y → f x = g y) : E →ₗ.[R] F := ⟨_, Classical.choose (sup_aux f g h)⟩ @[simp] theorem domain_sup (f g : E →ₗ.[R] F) (h : ∀ (x : f.domain) (y : g.domain), (x : E) = y → f x = g y) : (f.sup g h).domain = f.domain ⊔ g.domain := rfl theorem sup_apply {f g : E →ₗ.[R] F} (H : ∀ (x : f.domain) (y : g.domain), (x : E) = y → f x = g y) (x : f.domain) (y : g.domain) (z : ↥(f.domain ⊔ g.domain)) (hz : (↑x : E) + ↑y = ↑z) : f.sup g H z = f x + g y := Classical.choose_spec (sup_aux f g H) x y z hz protected theorem left_le_sup (f g : E →ₗ.[R] F) (h : ∀ (x : f.domain) (y : g.domain), (x : E) = y → f x = g y) : f ≤ f.sup g h := by refine ⟨le_sup_left, fun z₁ z₂ hz => ?_⟩ rw [← add_zero (f _), ← g.map_zero] refine (sup_apply h _ _ _ ?_).symm simpa protected theorem right_le_sup (f g : E →ₗ.[R] F) (h : ∀ (x : f.domain) (y : g.domain), (x : E) = y → f x = g y) : g ≤ f.sup g h := by refine ⟨le_sup_right, fun z₁ z₂ hz => ?_⟩ rw [← zero_add (g _), ← f.map_zero] refine (sup_apply h _ _ _ ?_).symm simpa protected theorem sup_le {f g h : E →ₗ.[R] F} (H : ∀ (x : f.domain) (y : g.domain), (x : E) = y → f x = g y) (fh : f ≤ h) (gh : g ≤ h) : f.sup g H ≤ h := have Hf : f ≤ f.sup g H ⊓ h := le_inf (f.left_le_sup g H) fh have Hg : g ≤ f.sup g H ⊓ h := le_inf (f.right_le_sup g H) gh le_of_eqLocus_ge <| sup_le Hf.1 Hg.1 /-- Hypothesis for `LinearPMap.sup` holds, if `f.domain` is disjoint with `g.domain`. -/ theorem sup_h_of_disjoint (f g : E →ₗ.[R] F) (h : Disjoint f.domain g.domain) (x : f.domain) (y : g.domain) (hxy : (x : E) = y) : f x = g y := by rw [disjoint_def] at h have hy : y = 0 := Subtype.eq (h y (hxy ▸ x.2) y.2) have hx : x = 0 := Subtype.eq (hxy.trans <| congr_arg _ hy) simp [*] /-! ### Algebraic operations -/ section Zero instance instZero : Zero (E →ₗ.[R] F) := ⟨⊤, 0⟩ @[simp] theorem zero_domain : (0 : E →ₗ.[R] F).domain = ⊤ := rfl @[simp] theorem zero_apply (x : (⊤ : Submodule R E)) : (0 : E →ₗ.[R] F) x = 0 := rfl end Zero section SMul variable {M N : Type*} [Monoid M] [DistribMulAction M F] [SMulCommClass R M F] variable [Monoid N] [DistribMulAction N F] [SMulCommClass R N F] instance instSMul : SMul M (E →ₗ.[R] F) := ⟨fun a f => { domain := f.domain toFun := a • f.toFun }⟩ @[simp] theorem smul_domain (a : M) (f : E →ₗ.[R] F) : (a • f).domain = f.domain := rfl theorem smul_apply (a : M) (f : E →ₗ.[R] F) (x : (a • f).domain) : (a • f) x = a • f x := rfl @[simp] theorem coe_smul (a : M) (f : E →ₗ.[R] F) : ⇑(a • f) = a • ⇑f := rfl instance instSMulCommClass [SMulCommClass M N F] : SMulCommClass M N (E →ₗ.[R] F) := ⟨fun a b f => ext' <| smul_comm a b f.toFun⟩ instance instIsScalarTower [SMul M N] [IsScalarTower M N F] : IsScalarTower M N (E →ₗ.[R] F) := ⟨fun a b f => ext' <| smul_assoc a b f.toFun⟩ instance instMulAction : MulAction M (E →ₗ.[R] F) where one_smul := fun ⟨_s, f⟩ => ext' <| one_smul M f mul_smul a b f := ext' <| mul_smul a b f.toFun end SMul instance instNeg : Neg (E →ₗ.[R] F) := ⟨fun f => ⟨f.domain, -f.toFun⟩⟩ @[simp] theorem neg_domain (f : E →ₗ.[R] F) : (-f).domain = f.domain := rfl @[simp] theorem neg_apply (f : E →ₗ.[R] F) (x) : (-f) x = -f x := rfl instance instInvolutiveNeg : InvolutiveNeg (E →ₗ.[R] F) := ⟨fun f => by ext x y hxy · rfl · simp only [neg_apply, neg_neg]⟩ section Add instance instAdd : Add (E →ₗ.[R] F) := ⟨fun f g => { domain := f.domain ⊓ g.domain toFun := f.toFun.comp (inclusion (inf_le_left : f.domain ⊓ g.domain ≤ _)) + g.toFun.comp (inclusion (inf_le_right : f.domain ⊓ g.domain ≤ _)) }⟩ theorem add_domain (f g : E →ₗ.[R] F) : (f + g).domain = f.domain ⊓ g.domain := rfl theorem add_apply (f g : E →ₗ.[R] F) (x : (f.domain ⊓ g.domain : Submodule R E)) : (f + g) x = f ⟨x, x.prop.1⟩ + g ⟨x, x.prop.2⟩ := rfl instance instAddSemigroup : AddSemigroup (E →ₗ.[R] F) := ⟨fun f g h => by ext x y hxy · simp only [add_domain, inf_assoc] · simp only [add_apply, add_assoc]⟩ instance instAddZeroClass : AddZeroClass (E →ₗ.[R] F) where zero_add := fun f => by ext x y hxy · simp [add_domain] · simp [add_apply] add_zero := fun f => by ext x y hxy · simp [add_domain] · simp [add_apply] instance instAddMonoid : AddMonoid (E →ₗ.[R] F) where zero_add f := by simp add_zero := by simp nsmul := nsmulRec instance instAddCommMonoid : AddCommMonoid (E →ₗ.[R] F) := ⟨fun f g => by ext x y hxy · simp only [add_domain, inf_comm] · simp only [add_apply, add_comm]⟩ end Add section VAdd instance instVAdd : VAdd (E →ₗ[R] F) (E →ₗ.[R] F) := ⟨fun f g => { domain := g.domain toFun := f.comp g.domain.subtype + g.toFun }⟩ @[simp] theorem vadd_domain (f : E →ₗ[R] F) (g : E →ₗ.[R] F) : (f +ᵥ g).domain = g.domain := rfl theorem vadd_apply (f : E →ₗ[R] F) (g : E →ₗ.[R] F) (x : (f +ᵥ g).domain) : (f +ᵥ g) x = f x + g x := rfl @[simp] theorem coe_vadd (f : E →ₗ[R] F) (g : E →ₗ.[R] F) : ⇑(f +ᵥ g) = ⇑(f.comp g.domain.subtype) + ⇑g := rfl instance instAddAction : AddAction (E →ₗ[R] F) (E →ₗ.[R] F) where vadd := (· +ᵥ ·) zero_vadd := fun ⟨_s, _f⟩ => ext' <| zero_add _ add_vadd := fun _f₁ _f₂ ⟨_s, _g⟩ => ext' <| LinearMap.ext fun _x => add_assoc _ _ _ end VAdd section Sub instance instSub : Sub (E →ₗ.[R] F) := ⟨fun f g => { domain := f.domain ⊓ g.domain toFun := f.toFun.comp (inclusion (inf_le_left : f.domain ⊓ g.domain ≤ _)) - g.toFun.comp (inclusion (inf_le_right : f.domain ⊓ g.domain ≤ _)) }⟩ theorem sub_domain (f g : E →ₗ.[R] F) : (f - g).domain = f.domain ⊓ g.domain := rfl theorem sub_apply (f g : E →ₗ.[R] F) (x : (f.domain ⊓ g.domain : Submodule R E)) : (f - g) x = f ⟨x, x.prop.1⟩ - g ⟨x, x.prop.2⟩ := rfl instance instSubtractionCommMonoid : SubtractionCommMonoid (E →ₗ.[R] F) where add_comm := add_comm sub_eq_add_neg f g := by ext x _ h · rfl simp [sub_apply, add_apply, neg_apply, ← sub_eq_add_neg] neg_neg := neg_neg neg_add_rev f g := by ext x _ h · simp [add_domain, neg_domain, And.comm] simp [add_apply, neg_apply, ← sub_eq_add_neg] neg_eq_of_add f g h' := by ext x hf hg · have : (0 : E →ₗ.[R] F).domain = ⊤ := zero_domain simp only [← h', add_domain, inf_eq_top_iff] at this rw [neg_domain, this.1, this.2] simp only [neg_domain, neg_apply, neg_eq_iff_add_eq_zero] rw [ext_iff] at h' rcases h' with ⟨hdom, h'⟩ rw [zero_domain] at hdom simp only [hdom, zero_domain, mem_top, zero_apply, forall_true_left] at h' apply h' zsmul := zsmulRec end Sub section variable {K : Type*} [DivisionRing K] [Module K E] [Module K F] /-- Extend a `LinearPMap` to `f.domain ⊔ K ∙ x`. -/ noncomputable def supSpanSingleton (f : E →ₗ.[K] F) (x : E) (y : F) (hx : x ∉ f.domain) : E →ₗ.[K] F := f.sup (mkSpanSingleton x y fun h₀ => hx <| h₀.symm ▸ f.domain.zero_mem) <| sup_h_of_disjoint _ _ <| by simpa [disjoint_span_singleton] using fun h ↦ False.elim <| hx h @[simp] theorem domain_supSpanSingleton (f : E →ₗ.[K] F) (x : E) (y : F) (hx : x ∉ f.domain) : (f.supSpanSingleton x y hx).domain = f.domain ⊔ K ∙ x := rfl @[simp] theorem supSpanSingleton_apply_mk (f : E →ₗ.[K] F) (x : E) (y : F) (hx : x ∉ f.domain) (x' : E) (hx' : x' ∈ f.domain) (c : K) : f.supSpanSingleton x y hx ⟨x' + c • x, mem_sup.2 ⟨x', hx', _, mem_span_singleton.2 ⟨c, rfl⟩, rfl⟩⟩ = f ⟨x', hx'⟩ + c • y := by unfold supSpanSingleton rw [sup_apply _ ⟨x', hx'⟩ ⟨c • x, _⟩, mkSpanSingleton'_apply] · rfl · exact mem_span_singleton.2 ⟨c, rfl⟩ @[simp] theorem supSpanSingleton_apply_smul_self (f : E →ₗ.[K] F) {x : E} (y : F) (hx : x ∉ f.domain) (c : K) : f.supSpanSingleton x y hx ⟨c • x, mem_sup_right <| mem_span_singleton.2 ⟨c, rfl⟩⟩ = c • y := by simpa [(mk_eq_zero _ _).mpr rfl] using supSpanSingleton_apply_mk f x y hx 0 (zero_mem _) c @[simp] theorem supSpanSingleton_apply_self (f : E →ₗ.[K] F) {x : E} (y : F) (hx : x ∉ f.domain) : f.supSpanSingleton x y hx ⟨x, mem_sup_right <| mem_span_singleton_self _⟩ = y := by simpa using supSpanSingleton_apply_smul_self f y hx 1 theorem supSpanSingleton_apply_of_mem (f : E →ₗ.[K] F) {x : E} (y : F) (hx : x ∉ f.domain) (x' : (f.supSpanSingleton x y hx).domain) (hx' : (x' : E) ∈ f.domain) : f.supSpanSingleton x y hx x' = f ⟨x', hx'⟩ := by simpa using supSpanSingleton_apply_mk f x y hx x' hx' 0 theorem supSpanSingleton_apply_mk_of_mem (f : E →ₗ.[K] F) {x : E} (y : F) (hx : x ∉ f.domain) {x' : E} (hx' : (x' : E) ∈ f.domain) : f.supSpanSingleton x y hx ⟨x', mem_sup_left hx'⟩ = f ⟨x', hx'⟩ := supSpanSingleton_apply_of_mem f y hx _ hx' end private theorem sSup_aux (c : Set (E →ₗ.[R] F)) (hc : DirectedOn (· ≤ ·) c) : ∃ f : ↥(sSup (domain '' c)) →ₗ[R] F, (⟨_, f⟩ : E →ₗ.[R] F) ∈ upperBounds c := by rcases c.eq_empty_or_nonempty with ceq | cne · subst c simp have hdir : DirectedOn (· ≤ ·) (domain '' c) := directedOn_image.2 (hc.mono @(domain_mono.monotone)) have P : ∀ x : ↥(sSup (domain '' c)), { p : c // (x : E) ∈ p.val.domain } := by rintro x apply Classical.indefiniteDescription have := (mem_sSup_of_directed (cne.image _) hdir).1 x.2 rwa [Set.exists_mem_image, ← bex_def, SetCoe.exists'] at this set f : ↥(sSup (domain '' c)) → F := fun x => (P x).val.val ⟨x, (P x).property⟩ have f_eq : ∀ (p : c) (x : ↥(sSup (domain '' c))) (y : p.1.1) (_hxy : (x : E) = y), f x = p.1 y := by intro p x y hxy rcases hc (P x).1.1 (P x).1.2 p.1 p.2 with ⟨q, _hqc, ⟨hxq1, hxq2⟩, ⟨hpq1, hpq2⟩⟩ exact (hxq2 (y := ⟨y, hpq1 y.2⟩) hxy).trans (hpq2 rfl).symm use { toFun := f, map_add' := ?_, map_smul' := ?_ }, ?_ · intro x y rcases hc (P x).1.1 (P x).1.2 (P y).1.1 (P y).1.2 with ⟨p, hpc, hpx, hpy⟩ set x' := inclusion hpx.1 ⟨x, (P x).2⟩ set y' := inclusion hpy.1 ⟨y, (P y).2⟩ rw [f_eq ⟨p, hpc⟩ x x' rfl, f_eq ⟨p, hpc⟩ y y' rfl, f_eq ⟨p, hpc⟩ (x + y) (x' + y') rfl, map_add] · intro c x simp only [RingHom.id_apply] rw [f_eq (P x).1 (c • x) (c • ⟨x, (P x).2⟩) rfl, ← map_smul] · intro p hpc refine ⟨le_sSup <| Set.mem_image_of_mem domain hpc, fun x y hxy => Eq.symm ?_⟩ exact f_eq ⟨p, hpc⟩ _ _ hxy.symm protected noncomputable def sSup (c : Set (E →ₗ.[R] F)) (hc : DirectedOn (· ≤ ·) c) : E →ₗ.[R] F := ⟨_, Classical.choose <| sSup_aux c hc⟩ theorem domain_sSup {c : Set (E →ₗ.[R] F)} (hc : DirectedOn (· ≤ ·) c) : (LinearPMap.sSup c hc).domain = sSup (LinearPMap.domain '' c) := rfl theorem mem_domain_sSup_iff {c : Set (E →ₗ.[R] F)} (hnonempty : c.Nonempty) (hc : DirectedOn (· ≤ ·) c) {x : E} : x ∈ (LinearPMap.sSup c hc).domain ↔ ∃ f ∈ c, x ∈ f.domain := by rw [domain_sSup, Submodule.mem_sSup_of_directed (hnonempty.image _) (DirectedOn.mono_comp LinearPMap.domain_mono.monotone hc)] simp protected theorem le_sSup {c : Set (E →ₗ.[R] F)} (hc : DirectedOn (· ≤ ·) c) {f : E →ₗ.[R] F} (hf : f ∈ c) : f ≤ LinearPMap.sSup c hc := Classical.choose_spec (sSup_aux c hc) hf protected theorem sSup_le {c : Set (E →ₗ.[R] F)} (hc : DirectedOn (· ≤ ·) c) {g : E →ₗ.[R] F} (hg : ∀ f ∈ c, f ≤ g) : LinearPMap.sSup c hc ≤ g := le_of_eqLocus_ge <| sSup_le fun _ ⟨f, hf, Eq⟩ => Eq ▸ have : f ≤ LinearPMap.sSup c hc ⊓ g := le_inf (LinearPMap.le_sSup _ hf) (hg f hf) this.1 protected theorem sSup_apply {c : Set (E →ₗ.[R] F)} (hc : DirectedOn (· ≤ ·) c) {l : E →ₗ.[R] F} (hl : l ∈ c) (x : l.domain) : (LinearPMap.sSup c hc) ⟨x, (LinearPMap.le_sSup hc hl).1 x.2⟩ = l x := by symm apply (Classical.choose_spec (sSup_aux c hc) hl).2 rfl end LinearPMap namespace LinearMap /-- Restrict a linear map to a submodule, reinterpreting the result as a `LinearPMap`. -/ def toPMap (f : E →ₗ[R] F) (p : Submodule R E) : E →ₗ.[R] F := ⟨p, f.comp p.subtype⟩ @[simp] theorem toPMap_apply (f : E →ₗ[R] F) (p : Submodule R E) (x : p) : f.toPMap p x = f x := rfl @[simp] theorem toPMap_domain (f : E →ₗ[R] F) (p : Submodule R E) : (f.toPMap p).domain = p := rfl /-- Compose a linear map with a `LinearPMap` -/ def compPMap (g : F →ₗ[R] G) (f : E →ₗ.[R] F) : E →ₗ.[R] G where domain := f.domain toFun := g.comp f.toFun @[simp] theorem compPMap_apply (g : F →ₗ[R] G) (f : E →ₗ.[R] F) (x) : g.compPMap f x = g (f x) := rfl end LinearMap namespace LinearPMap /-- Restrict codomain of a `LinearPMap` -/ def codRestrict (f : E →ₗ.[R] F) (p : Submodule R F) (H : ∀ x, f x ∈ p) : E →ₗ.[R] p where domain := f.domain toFun := f.toFun.codRestrict p H /-- Compose two `LinearPMap`s -/ def comp (g : F →ₗ.[R] G) (f : E →ₗ.[R] F) (H : ∀ x : f.domain, f x ∈ g.domain) : E →ₗ.[R] G := g.toFun.compPMap <| f.codRestrict _ H /-- `f.coprod g` is the partially defined linear map defined on `f.domain × g.domain`, and sending `p` to `f p.1 + g p.2`. -/ def coprod (f : E →ₗ.[R] G) (g : F →ₗ.[R] G) : E × F →ₗ.[R] G where domain := f.domain.prod g.domain toFun := (show f.domain.prod g.domain →ₗ[R] G from (f.comp (LinearPMap.fst f.domain g.domain) fun x => x.2.1).toFun) + (show f.domain.prod g.domain →ₗ[R] G from (g.comp (LinearPMap.snd f.domain g.domain) fun x => x.2.2).toFun) @[simp] theorem coprod_apply (f : E →ₗ.[R] G) (g : F →ₗ.[R] G) (x) : f.coprod g x = f ⟨(x : E × F).1, x.2.1⟩ + g ⟨(x : E × F).2, x.2.2⟩ := rfl /-- Restrict a partially defined linear map to a submodule of `E` contained in `f.domain`. -/ def domRestrict (f : E →ₗ.[R] F) (S : Submodule R E) : E →ₗ.[R] F := ⟨S ⊓ f.domain, f.toFun.comp (Submodule.inclusion (by simp))⟩ @[simp] theorem domRestrict_domain (f : E →ₗ.[R] F) {S : Submodule R E} : (f.domRestrict S).domain = S ⊓ f.domain := rfl theorem domRestrict_apply {f : E →ₗ.[R] F} {S : Submodule R E} ⦃x : ↥(S ⊓ f.domain)⦄ ⦃y : f.domain⦄ (h : (x : E) = y) : f.domRestrict S x = f y := by have : Submodule.inclusion (by simp) x = y := by ext simp [h] rw [← this] exact LinearPMap.mk_apply _ _ _ theorem domRestrict_le {f : E →ₗ.[R] F} {S : Submodule R E} : f.domRestrict S ≤ f := ⟨by simp, fun _ _ hxy => domRestrict_apply hxy⟩ /-! ### Graph -/ section Graph /-- The graph of a `LinearPMap` viewed as a submodule on `E × F`. -/ def graph (f : E →ₗ.[R] F) : Submodule R (E × F) := f.toFun.graph.map (f.domain.subtype.prodMap (LinearMap.id : F →ₗ[R] F)) theorem mem_graph_iff' (f : E →ₗ.[R] F) {x : E × F} : x ∈ f.graph ↔ ∃ y : f.domain, (↑y, f y) = x := by simp [graph] @[simp] theorem mem_graph_iff (f : E →ₗ.[R] F) {x : E × F} : x ∈ f.graph ↔ ∃ y : f.domain, (↑y : E) = x.1 ∧ f y = x.2 := by cases x simp_rw [mem_graph_iff', Prod.mk_inj] /-- The tuple `(x, f x)` is contained in the graph of `f`. -/ theorem mem_graph (f : E →ₗ.[R] F) (x : domain f) : ((x : E), f x) ∈ f.graph := by simp theorem graph_map_fst_eq_domain (f : E →ₗ.[R] F) : f.graph.map (LinearMap.fst R E F) = f.domain := by ext x simp only [Submodule.mem_map, mem_graph_iff, Subtype.exists, exists_and_left, exists_eq_left, LinearMap.fst_apply, Prod.exists, exists_and_right, exists_eq_right] constructor <;> intro h · rcases h with ⟨x, hx, _⟩ exact hx · use f ⟨x, h⟩ simp only [h, exists_const] theorem graph_map_snd_eq_range (f : E →ₗ.[R] F) : f.graph.map (LinearMap.snd R E F) = LinearMap.range f.toFun := by ext; simp variable {M : Type*} [Monoid M] [DistribMulAction M F] [SMulCommClass R M F] (y : M) /-- The graph of `z • f` as a pushforward. -/ theorem smul_graph (f : E →ₗ.[R] F) (z : M) : (z • f).graph = f.graph.map ((LinearMap.id : E →ₗ[R] E).prodMap (z • (LinearMap.id : F →ₗ[R] F))) := by ext ⟨x_fst, x_snd⟩ constructor <;> intro h · rw [mem_graph_iff] at h rcases h with ⟨y, hy, h⟩ rw [LinearPMap.smul_apply] at h rw [Submodule.mem_map] simp only [mem_graph_iff, LinearMap.prodMap_apply, LinearMap.id_coe, id, LinearMap.smul_apply, Prod.mk_inj, Prod.exists, exists_exists_and_eq_and] use x_fst, y, hy rw [Submodule.mem_map] at h rcases h with ⟨x', hx', h⟩ cases x' simp only [LinearMap.prodMap_apply, LinearMap.id_coe, id, LinearMap.smul_apply, Prod.mk_inj] at h rw [mem_graph_iff] at hx' ⊢ rcases hx' with ⟨y, hy, hx'⟩ use y rw [← h.1, ← h.2] simp [hy, hx'] /-- The graph of `-f` as a pushforward. -/ theorem neg_graph (f : E →ₗ.[R] F) : (-f).graph = f.graph.map ((LinearMap.id : E →ₗ[R] E).prodMap (-(LinearMap.id : F →ₗ[R] F))) := by ext ⟨x_fst, x_snd⟩ constructor <;> intro h · rw [mem_graph_iff] at h rcases h with ⟨y, hy, h⟩ rw [LinearPMap.neg_apply] at h rw [Submodule.mem_map] simp only [mem_graph_iff, LinearMap.prodMap_apply, LinearMap.id_coe, id, LinearMap.neg_apply, Prod.mk_inj, Prod.exists, exists_exists_and_eq_and] use x_fst, y, hy rw [Submodule.mem_map] at h rcases h with ⟨x', hx', h⟩ cases x' simp only [LinearMap.prodMap_apply, LinearMap.id_coe, id, LinearMap.neg_apply, Prod.mk_inj] at h rw [mem_graph_iff] at hx' ⊢ rcases hx' with ⟨y, hy, hx'⟩ use y rw [← h.1, ← h.2] simp [hy, hx'] theorem mem_graph_snd_inj (f : E →ₗ.[R] F) {x y : E} {x' y' : F} (hx : (x, x') ∈ f.graph) (hy : (y, y') ∈ f.graph) (hxy : x = y) : x' = y' := by grind [mem_graph_iff] theorem mem_graph_snd_inj' (f : E →ₗ.[R] F) {x y : E × F} (hx : x ∈ f.graph) (hy : y ∈ f.graph) (hxy : x.1 = y.1) : x.2 = y.2 := by cases x cases y exact f.mem_graph_snd_inj hx hy hxy /-- The property that `f 0 = 0` in terms of the graph. -/ theorem graph_fst_eq_zero_snd (f : E →ₗ.[R] F) {x : E} {x' : F} (h : (x, x') ∈ f.graph) (hx : x = 0) : x' = 0 := f.mem_graph_snd_inj h f.graph.zero_mem hx theorem mem_domain_iff {f : E →ₗ.[R] F} {x : E} : x ∈ f.domain ↔ ∃ y : F, (x, y) ∈ f.graph := by constructor <;> intro h · use f ⟨x, h⟩ exact f.mem_graph ⟨x, h⟩ grind [mem_graph_iff] theorem mem_domain_of_mem_graph {f : E →ₗ.[R] F} {x : E} {y : F} (h : (x, y) ∈ f.graph) : x ∈ f.domain := by rw [mem_domain_iff] exact ⟨y, h⟩ theorem image_iff {f : E →ₗ.[R] F} {x : E} {y : F} (hx : x ∈ f.domain) : y = f ⟨x, hx⟩ ↔ (x, y) ∈ f.graph := by grind [mem_graph_iff] theorem mem_range_iff {f : E →ₗ.[R] F} {y : F} : y ∈ Set.range f ↔ ∃ x : E, (x, y) ∈ f.graph := by constructor <;> intro h · rw [Set.mem_range] at h rcases h with ⟨⟨x, hx⟩, h⟩ use x rw [← h] exact f.mem_graph ⟨x, hx⟩ grind [mem_graph_iff] theorem mem_domain_iff_of_eq_graph {f g : E →ₗ.[R] F} (h : f.graph = g.graph) {x : E} : x ∈ f.domain ↔ x ∈ g.domain := by simp_rw [mem_domain_iff, h] theorem le_of_le_graph {f g : E →ₗ.[R] F} (h : f.graph ≤ g.graph) : f ≤ g := by constructor · intro x hx rw [mem_domain_iff] at hx ⊢ obtain ⟨y, hx⟩ := hx use y exact h hx rintro ⟨x, hx⟩ ⟨y, hy⟩ hxy rw [image_iff] refine h ?_ simp only at hxy rw [hxy] at hx rw [← image_iff hx] simp [hxy] theorem le_graph_of_le {f g : E →ₗ.[R] F} (h : f ≤ g) : f.graph ≤ g.graph := by intro x hx rw [mem_graph_iff] at hx ⊢ obtain ⟨y, hx⟩ := hx use ⟨y, h.1 y.2⟩ simp only [hx, true_and] convert hx.2 using 1 refine (h.2 ?_).symm simp only [hx.1] theorem le_graph_iff {f g : E →ₗ.[R] F} : f.graph ≤ g.graph ↔ f ≤ g := ⟨le_of_le_graph, le_graph_of_le⟩ theorem eq_of_eq_graph {f g : E →ₗ.[R] F} (h : f.graph = g.graph) : f = g := by apply dExt · ext exact mem_domain_iff_of_eq_graph h · apply (le_of_le_graph h.le).2 end Graph end LinearPMap namespace Submodule section SubmoduleToLinearPMap theorem existsUnique_from_graph {g : Submodule R (E × F)} (hg : ∀ {x : E × F} (_hx : x ∈ g) (_hx' : x.fst = 0), x.snd = 0) {a : E} (ha : a ∈ g.map (LinearMap.fst R E F)) : ∃! b : F, (a, b) ∈ g := by refine existsUnique_of_exists_of_unique ?_ ?_ · convert ha simp intro y₁ y₂ hy₁ hy₂ have hy : ((0 : E), y₁ - y₂) ∈ g := by convert g.sub_mem hy₁ hy₂ exact (sub_self _).symm exact sub_eq_zero.mp (hg hy (by simp)) /-- Auxiliary definition to unfold the existential quantifier. -/ noncomputable def valFromGraph {g : Submodule R (E × F)} (hg : ∀ (x : E × F) (_hx : x ∈ g) (_hx' : x.fst = 0), x.snd = 0) {a : E} (ha : a ∈ g.map (LinearMap.fst R E F)) : F := (ExistsUnique.exists (existsUnique_from_graph @hg ha)).choose theorem valFromGraph_mem {g : Submodule R (E × F)} (hg : ∀ (x : E × F) (_hx : x ∈ g) (_hx' : x.fst = 0), x.snd = 0) {a : E} (ha : a ∈ g.map (LinearMap.fst R E F)) : (a, valFromGraph hg ha) ∈ g := (ExistsUnique.exists (existsUnique_from_graph @hg ha)).choose_spec /-- Define a `LinearMap` from its graph. Helper definition for `LinearPMap`. -/ noncomputable def toLinearPMapAux (g : Submodule R (E × F)) (hg : ∀ (x : E × F) (_hx : x ∈ g) (_hx' : x.fst = 0), x.snd = 0) : g.map (LinearMap.fst R E F) →ₗ[R] F where toFun := fun x => valFromGraph hg x.2 map_add' := fun v w => by have hadd := (g.map (LinearMap.fst R E F)).add_mem v.2 w.2 have hvw := valFromGraph_mem hg hadd have hvw' := g.add_mem (valFromGraph_mem hg v.2) (valFromGraph_mem hg w.2) rw [Prod.mk_add_mk] at hvw' exact (existsUnique_from_graph @hg hadd).unique hvw hvw' map_smul' := fun a v => by have hsmul := (g.map (LinearMap.fst R E F)).smul_mem a v.2 have hav := valFromGraph_mem hg hsmul have hav' := g.smul_mem a (valFromGraph_mem hg v.2) rw [Prod.smul_mk] at hav' exact (existsUnique_from_graph @hg hsmul).unique hav hav' open scoped Classical in /-- Define a `LinearPMap` from its graph. In the case that the submodule is not a graph of a `LinearPMap` then the underlying linear map is just the zero map. -/ noncomputable def toLinearPMap (g : Submodule R (E × F)) : E →ₗ.[R] F where domain := g.map (LinearMap.fst R E F) toFun := if hg : ∀ (x : E × F) (_hx : x ∈ g) (_hx' : x.fst = 0), x.snd = 0 then g.toLinearPMapAux hg else 0 theorem toLinearPMap_domain (g : Submodule R (E × F)) : g.toLinearPMap.domain = g.map (LinearMap.fst R E F) := rfl theorem toLinearPMap_apply_aux {g : Submodule R (E × F)} (hg : ∀ (x : E × F) (_hx : x ∈ g) (_hx' : x.fst = 0), x.snd = 0) (x : g.map (LinearMap.fst R E F)) : g.toLinearPMap x = valFromGraph hg x.2 := by classical change (if hg : _ then g.toLinearPMapAux hg else 0) x = _ rw [dif_pos] · rfl · exact hg theorem mem_graph_toLinearPMap {g : Submodule R (E × F)} (hg : ∀ (x : E × F) (_hx : x ∈ g) (_hx' : x.fst = 0), x.snd = 0) (x : g.map (LinearMap.fst R E F)) : (x.val, g.toLinearPMap x) ∈ g := by rw [toLinearPMap_apply_aux hg] exact valFromGraph_mem hg x.2 @[simp] theorem toLinearPMap_graph_eq (g : Submodule R (E × F)) (hg : ∀ (x : E × F) (_hx : x ∈ g) (_hx' : x.fst = 0), x.snd = 0) : g.toLinearPMap.graph = g := by ext ⟨x_fst, x_snd⟩ constructor <;> intro hx · rw [LinearPMap.mem_graph_iff] at hx rcases hx with ⟨y, hx1, hx2⟩ convert g.mem_graph_toLinearPMap hg y using 1 exact Prod.ext hx1.symm hx2.symm rw [LinearPMap.mem_graph_iff] have hx_fst : x_fst ∈ g.map (LinearMap.fst R E F) := by simp only [mem_map, LinearMap.fst_apply, Prod.exists, exists_and_right, exists_eq_right] exact ⟨x_snd, hx⟩ refine ⟨⟨x_fst, hx_fst⟩, Subtype.coe_mk x_fst hx_fst, ?_⟩ rw [toLinearPMap_apply_aux hg] exact (existsUnique_from_graph @hg hx_fst).unique (valFromGraph_mem hg hx_fst) hx theorem toLinearPMap_range (g : Submodule R (E × F)) (hg : ∀ (x : E × F) (_hx : x ∈ g) (_hx' : x.fst = 0), x.snd = 0) : LinearMap.range g.toLinearPMap.toFun = g.map (LinearMap.snd R E F) := by rwa [← LinearPMap.graph_map_snd_eq_range, toLinearPMap_graph_eq] end SubmoduleToLinearPMap end Submodule namespace LinearPMap section inverse /-- The inverse of a `LinearPMap`. -/ noncomputable def inverse (f : E →ₗ.[R] F) : F →ₗ.[R] E := (f.graph.map (LinearEquiv.prodComm R E F)).toLinearPMap variable {f : E →ₗ.[R] F} theorem inverse_domain : (inverse f).domain = LinearMap.range f.toFun := by rw [inverse, Submodule.toLinearPMap_domain, ← graph_map_snd_eq_range, ← LinearEquiv.fst_comp_prodComm, Submodule.map_comp] rfl variable (hf : LinearMap.ker f.toFun = ⊥) include hf /-- The graph of the inverse generates a `LinearPMap`. -/ theorem mem_inverse_graph_snd_eq_zero (x : F × E) (hv : x ∈ (graph f).map (LinearEquiv.prodComm R E F)) (hv' : x.fst = 0) : x.snd = 0 := by simp only [Submodule.mem_map, mem_graph_iff, Subtype.exists, exists_and_left, exists_eq_left, LinearEquiv.prodComm_apply, Prod.exists, Prod.swap_prod_mk] at hv rcases hv with ⟨a, b, ⟨ha, h1⟩, ⟨h2, h3⟩⟩ simp only at hv' ⊢ rw [hv'] at h1 rw [LinearMap.ker_eq_bot'] at hf specialize hf ⟨a, ha⟩ h1 simp only [Submodule.mk_eq_zero] at hf exact hf theorem inverse_graph : (inverse f).graph = f.graph.map (LinearEquiv.prodComm R E F) := by rw [inverse, Submodule.toLinearPMap_graph_eq _ (mem_inverse_graph_snd_eq_zero hf)] theorem inverse_range : LinearMap.range (inverse f).toFun = f.domain := by rw [inverse, Submodule.toLinearPMap_range _ (mem_inverse_graph_snd_eq_zero hf), ← graph_map_fst_eq_domain, ← LinearEquiv.snd_comp_prodComm, Submodule.map_comp] rfl theorem mem_inverse_graph (x : f.domain) : (f x, (x : E)) ∈ (inverse f).graph := by simp only [inverse_graph hf, Submodule.mem_map, mem_graph_iff, Subtype.exists, exists_and_left, exists_eq_left, LinearEquiv.prodComm_apply, Prod.exists, Prod.swap_prod_mk, Prod.mk.injEq] exact ⟨(x : E), f x, ⟨x.2, Eq.refl _⟩, Eq.refl _, Eq.refl _⟩ theorem inverse_apply_eq {y : (inverse f).domain} {x : f.domain} (hxy : f x = y) : (inverse f) y = x := by have := mem_inverse_graph hf x grind [mem_graph_iff] end inverse end LinearPMap
.lake/packages/mathlib/Mathlib/LinearAlgebra/Projection.lean
import Mathlib.LinearAlgebra.Quotient.Basic import Mathlib.LinearAlgebra.Prod import Mathlib.Algebra.Module.Submodule.Invariant import Mathlib.LinearAlgebra.GeneralLinearGroup import Mathlib.Algebra.Ring.Idempotent /-! # Projection to a subspace In this file we define * `Submodule.linearProjOfIsCompl (p q : Submodule R E) (h : IsCompl p q)`: the projection of a module `E` to a submodule `p` along its complement `q`; it is the unique linear map `f : E → p` such that `f x = x` for `x ∈ p` and `f x = 0` for `x ∈ q`. * `Submodule.isComplEquivProj p`: equivalence between submodules `q` such that `IsCompl p q` and projections `f : E → p`, `∀ x ∈ p, f x = x`. We also provide some lemmas justifying correctness of our definitions. ## Tags projection, complement subspace -/ noncomputable section Ring variable {R : Type*} [Ring R] {E : Type*} [AddCommGroup E] [Module R E] variable {F : Type*} [AddCommGroup F] [Module R F] {G : Type*} [AddCommGroup G] [Module R G] variable (p q : Submodule R E) variable {S : Type*} [Semiring S] {M : Type*} [AddCommMonoid M] [Module S M] (m : Submodule S M) namespace LinearMap variable {p} open Submodule theorem ker_id_sub_eq_of_proj {f : E →ₗ[R] p} (hf : ∀ x : p, f x = x) : ker (id - p.subtype.comp f) = p := by ext x simp only [comp_apply, mem_ker, subtype_apply, sub_apply, id_apply, sub_eq_zero] exact ⟨fun h => h.symm ▸ Submodule.coe_mem _, fun hx => by rw [hf ⟨x, hx⟩, Subtype.coe_mk]⟩ theorem range_eq_of_proj {f : E →ₗ[R] p} (hf : ∀ x : p, f x = x) : range f = ⊤ := range_eq_top.2 fun x => ⟨x, hf x⟩ theorem isCompl_of_proj {f : E →ₗ[R] p} (hf : ∀ x : p, f x = x) : IsCompl p (ker f) := by constructor · rw [disjoint_iff_inf_le] rintro x ⟨hpx, hfx⟩ rw [SetLike.mem_coe, mem_ker, hf ⟨x, hpx⟩, mk_eq_zero] at hfx simp only [hfx, zero_mem] · rw [codisjoint_iff_le_sup] intro x _ rw [mem_sup'] refine ⟨f x, ⟨x - f x, ?_⟩, add_sub_cancel _ _⟩ rw [mem_ker, LinearMap.map_sub, hf, sub_self] end LinearMap namespace Submodule open LinearMap /-- If `q` is a complement of `p`, then `M/p ≃ q`. -/ def quotientEquivOfIsCompl (h : IsCompl p q) : (E ⧸ p) ≃ₗ[R] q := LinearEquiv.symm <| LinearEquiv.ofBijective (p.mkQ.comp q.subtype) ⟨by rw [← ker_eq_bot, ker_comp, ker_mkQ, disjoint_iff_comap_eq_bot.1 h.symm.disjoint], by rw [← range_eq_top, range_comp, range_subtype, map_mkQ_eq_top, h.sup_eq_top]⟩ @[simp] theorem quotientEquivOfIsCompl_symm_apply (h : IsCompl p q) (x : q) : -- Porting note: type ascriptions needed on the RHS (quotientEquivOfIsCompl p q h).symm x = (Quotient.mk x : E ⧸ p) := rfl @[simp] theorem quotientEquivOfIsCompl_apply_mk_coe (h : IsCompl p q) (x : q) : quotientEquivOfIsCompl p q h (Quotient.mk x) = x := (quotientEquivOfIsCompl p q h).apply_symm_apply x @[simp] theorem mk_quotientEquivOfIsCompl_apply (h : IsCompl p q) (x : E ⧸ p) : (Quotient.mk (quotientEquivOfIsCompl p q h x) : E ⧸ p) = x := (quotientEquivOfIsCompl p q h).symm_apply_apply x /-- If `q` is a complement of `p`, then `p × q` is isomorphic to `E`. -/ def prodEquivOfIsCompl (h : IsCompl p q) : (p × q) ≃ₗ[R] E := by apply LinearEquiv.ofBijective (p.subtype.coprod q.subtype) constructor · rw [← ker_eq_bot, ker_coprod_of_disjoint_range, ker_subtype, ker_subtype, prod_bot] rw [range_subtype, range_subtype] exact h.1 · rw [← range_eq_top, ← sup_eq_range, h.sup_eq_top] @[simp] theorem coe_prodEquivOfIsCompl (h : IsCompl p q) : (prodEquivOfIsCompl p q h : p × q →ₗ[R] E) = p.subtype.coprod q.subtype := rfl @[simp] theorem coe_prodEquivOfIsCompl' (h : IsCompl p q) (x : p × q) : prodEquivOfIsCompl p q h x = x.1 + x.2 := rfl @[simp] theorem prodEquivOfIsCompl_symm_apply_left (h : IsCompl p q) (x : p) : (prodEquivOfIsCompl p q h).symm x = (x, 0) := (prodEquivOfIsCompl p q h).symm_apply_eq.2 <| by simp @[simp] theorem prodEquivOfIsCompl_symm_apply_right (h : IsCompl p q) (x : q) : (prodEquivOfIsCompl p q h).symm x = (0, x) := (prodEquivOfIsCompl p q h).symm_apply_eq.2 <| by simp @[simp] theorem prodEquivOfIsCompl_symm_apply_fst_eq_zero (h : IsCompl p q) {x : E} : ((prodEquivOfIsCompl p q h).symm x).1 = 0 ↔ x ∈ q := by conv_rhs => rw [← (prodEquivOfIsCompl p q h).apply_symm_apply x] rw [coe_prodEquivOfIsCompl', Submodule.add_mem_iff_left _ (Submodule.coe_mem _), mem_right_iff_eq_zero_of_disjoint h.disjoint] @[simp] theorem prodEquivOfIsCompl_symm_apply_snd_eq_zero (h : IsCompl p q) {x : E} : ((prodEquivOfIsCompl p q h).symm x).2 = 0 ↔ x ∈ p := by conv_rhs => rw [← (prodEquivOfIsCompl p q h).apply_symm_apply x] rw [coe_prodEquivOfIsCompl', Submodule.add_mem_iff_right _ (Submodule.coe_mem _), mem_left_iff_eq_zero_of_disjoint h.disjoint] @[simp] theorem prodComm_trans_prodEquivOfIsCompl (h : IsCompl p q) : LinearEquiv.prodComm R q p ≪≫ₗ prodEquivOfIsCompl p q h = prodEquivOfIsCompl q p h.symm := LinearEquiv.ext fun _ => add_comm _ _ /-- Projection to a submodule along a complement. It is the unique linear map `f : E → p` such that `f x = x` for `x ∈ p` and `f x = 0` for `x ∈ q`. See also `LinearMap.linearProjOfIsCompl`. -/ def linearProjOfIsCompl (h : IsCompl p q) : E →ₗ[R] p := LinearMap.fst R p q ∘ₗ ↑(prodEquivOfIsCompl p q h).symm variable {p q} /-- The linear projection onto a subspace along its complement as a map from the full space to itself, as opposed to `Submodule.linearProjOfIsCompl`, which maps into the subtype. This version is important as it satisfies `IsIdempotentElem`. -/ noncomputable def IsCompl.projection (hpq : IsCompl p q) := p.subtype ∘ₗ p.linearProjOfIsCompl q hpq open Submodule theorem IsCompl.projection_apply (hpq : IsCompl p q) (x : E) : hpq.projection x = p.linearProjOfIsCompl q hpq x := rfl @[simp] theorem coe_linearProjOfIsCompl_apply (hpq : IsCompl p q) (x : E) : (p.linearProjOfIsCompl q hpq x : E) = hpq.projection x := rfl @[simp] theorem IsCompl.projection_apply_mem (hpq : IsCompl p q) (x : E) : hpq.projection x ∈ p := SetLike.coe_mem _ @[simp] theorem linearProjOfIsCompl_apply_left (h : IsCompl p q) (x : p) : linearProjOfIsCompl p q h x = x := by simp [linearProjOfIsCompl] @[simp] theorem IsCompl.projection_apply_left (hpq : IsCompl p q) (x : p) : hpq.projection x = x := by simp [projection] @[simp] theorem linearProjOfIsCompl_range (h : IsCompl p q) : range (linearProjOfIsCompl p q h) = ⊤ := range_eq_of_proj (linearProjOfIsCompl_apply_left h) @[simp] theorem IsCompl.projection_range (hpq : IsCompl p q) : range hpq.projection = p := by simp [projection, range_comp] theorem linearProjOfIsCompl_surjective (h : IsCompl p q) : Function.Surjective (linearProjOfIsCompl p q h) := range_eq_top.mp (linearProjOfIsCompl_range h) @[simp] theorem linearProjOfIsCompl_apply_eq_zero_iff (h : IsCompl p q) {x : E} : linearProjOfIsCompl p q h x = 0 ↔ x ∈ q := by simp [linearProjOfIsCompl] @[simp] theorem IsCompl.projection_apply_eq_zero_iff (hpq : IsCompl p q) {x : E} : hpq.projection x = 0 ↔ x ∈ q := by simp [projection, -coe_linearProjOfIsCompl_apply] theorem linearProjOfIsCompl_apply_right' (h : IsCompl p q) (x : E) (hx : x ∈ q) : linearProjOfIsCompl p q h x = 0 := (linearProjOfIsCompl_apply_eq_zero_iff h).2 hx @[simp] theorem linearProjOfIsCompl_apply_right (h : IsCompl p q) (x : q) : linearProjOfIsCompl p q h x = 0 := linearProjOfIsCompl_apply_right' h x x.2 @[simp] theorem linearProjOfIsCompl_ker (h : IsCompl p q) : ker (linearProjOfIsCompl p q h) = q := ext fun _ => mem_ker.trans (linearProjOfIsCompl_apply_eq_zero_iff h) @[simp] theorem IsCompl.projection_ker (hpq : IsCompl p q) : ker hpq.projection = q := by simp [projection, ker_comp] theorem linearProjOfIsCompl_comp_subtype (h : IsCompl p q) : (linearProjOfIsCompl p q h).comp p.subtype = LinearMap.id := LinearMap.ext <| linearProjOfIsCompl_apply_left h theorem linearProjOfIsCompl_isCompl_projection (h : IsCompl p q) (x : E) : linearProjOfIsCompl p q h (h.projection x) = linearProjOfIsCompl p q h x := linearProjOfIsCompl_apply_left h _ @[deprecated (since := "2025-07-29")] alias linearProjOfIsCompl_idempotent := linearProjOfIsCompl_isCompl_projection /-- The linear projection onto a subspace along its complement is an idempotent. -/ @[simp] theorem IsCompl.projection_isIdempotentElem (hpq : IsCompl p q) : IsIdempotentElem hpq.projection := LinearMap.ext fun _ ↦ congr($(linearProjOfIsCompl_isCompl_projection hpq _)) theorem existsUnique_add_of_isCompl_prod (hc : IsCompl p q) (x : E) : ∃! u : p × q, (u.fst : E) + u.snd = x := (prodEquivOfIsCompl _ _ hc).toEquiv.bijective.existsUnique _ theorem existsUnique_add_of_isCompl (hc : IsCompl p q) (x : E) : ∃ (u : p) (v : q), (u : E) + v = x ∧ ∀ (r : p) (s : q), (r : E) + s = x → r = u ∧ s = v := let ⟨u, hu₁, hu₂⟩ := existsUnique_add_of_isCompl_prod hc x ⟨u.1, u.2, hu₁, fun r s hrs => Prod.eq_iff_fst_eq_snd_eq.1 (hu₂ ⟨r, s⟩ hrs)⟩ theorem IsCompl.projection_add_projection_eq_self (hpq : IsCompl p q) (x : E) : hpq.projection x + hpq.symm.projection x = x := by dsimp only [IsCompl.projection, linearProjOfIsCompl] rw [← prodComm_trans_prodEquivOfIsCompl _ _ hpq] exact (prodEquivOfIsCompl _ _ hpq).apply_symm_apply x @[deprecated (since := "2025-07-29")] alias linearProjOfIsCompl_add_linearProjOfIsCompl_eq_self := IsCompl.projection_add_projection_eq_self @[deprecated (since := "2025-07-11")] alias linear_proj_add_linearProjOfIsCompl_eq_self := linearProjOfIsCompl_add_linearProjOfIsCompl_eq_self lemma IsCompl.projection_eq_self_sub_projection (hpq : IsCompl p q) (x : E) : hpq.symm.projection x = x - hpq.projection x := by rw [eq_sub_iff_add_eq, projection_add_projection_eq_self] @[deprecated (since := "2025-07-29")] alias linearProjOfIsCompl_eq_self_sub_linearProjOfIsCompl := IsCompl.projection_eq_self_sub_projection /-- The projection to `p` along `q` of `x` equals `x` if and only if `x ∈ p`. -/ @[simp] lemma IsCompl.projection_eq_self_iff (hpq : IsCompl p q) (x : E) : hpq.projection x = x ↔ x ∈ p := by rw [eq_comm, ← sub_eq_zero, ← projection_eq_self_sub_projection, projection_apply_eq_zero_iff] @[deprecated (since := "2025-07-29")] alias linearProjOfIsCompl_eq_self_iff := IsCompl.projection_eq_self_iff end Submodule namespace LinearMap open Submodule section /-- Projection to the image of an injection along a complement. This has an advantage over `Submodule.linearProjOfIsCompl` in that it allows the user better definitional control over the type. -/ def linearProjOfIsCompl {F : Type*} [AddCommGroup F] [Module R F] (i : F →ₗ[R] E) (hi : Function.Injective i) (h : IsCompl (LinearMap.range i) q) : E →ₗ[R] F := (LinearEquiv.ofInjective i hi).symm ∘ₗ (LinearMap.range i).linearProjOfIsCompl q h variable {F : Type*} [AddCommGroup F] [Module R F] (i : F →ₗ[R] E) (hi : Function.Injective i) (h : IsCompl (LinearMap.range i) q) @[simp] theorem linearProjOfIsCompl_apply_left (x : F) : linearProjOfIsCompl q i hi h (i x) = x := by obtain ⟨ix, rfl⟩ := (LinearEquiv.ofInjective i hi).symm.surjective x simp [linearProjOfIsCompl] lemma linearProjOfIsCompl_apply_right' (x : E) (hx : x ∈ q) : linearProjOfIsCompl q i hi h x = 0 := by simpa [LinearMap.linearProjOfIsCompl] @[simp] lemma linearProjOfIsCompl_apply_right (x : q) : linearProjOfIsCompl q i hi h x = 0 := by simp [LinearMap.linearProjOfIsCompl] @[simp] lemma ker_linearProjOfIsCompl : ker (linearProjOfIsCompl q i hi h) = q := by simp [LinearMap.linearProjOfIsCompl] end /-- Given linear maps `φ` and `ψ` from complement submodules, `LinearMap.ofIsCompl` is the induced linear map over the entire module. -/ def ofIsCompl {p q : Submodule R E} (h : IsCompl p q) (φ : p →ₗ[R] F) (ψ : q →ₗ[R] F) : E →ₗ[R] F := LinearMap.coprod φ ψ ∘ₗ ↑(Submodule.prodEquivOfIsCompl _ _ h).symm variable {p q} @[simp] theorem ofIsCompl_left_apply (h : IsCompl p q) {φ : p →ₗ[R] F} {ψ : q →ₗ[R] F} (u : p) : ofIsCompl h φ ψ (u : E) = φ u := by simp [ofIsCompl] @[simp] theorem ofIsCompl_right_apply (h : IsCompl p q) {φ : p →ₗ[R] F} {ψ : q →ₗ[R] F} (v : q) : ofIsCompl h φ ψ (v : E) = ψ v := by simp [ofIsCompl] theorem ofIsCompl_eq (h : IsCompl p q) {φ : p →ₗ[R] F} {ψ : q →ₗ[R] F} {χ : E →ₗ[R] F} (hφ : ∀ u, φ u = χ u) (hψ : ∀ u, ψ u = χ u) : ofIsCompl h φ ψ = χ := by ext x obtain ⟨_, _, rfl, _⟩ := existsUnique_add_of_isCompl h x simp [ofIsCompl, hφ, hψ] theorem ofIsCompl_eq' (h : IsCompl p q) {φ : p →ₗ[R] F} {ψ : q →ₗ[R] F} {χ : E →ₗ[R] F} (hφ : φ = χ.comp p.subtype) (hψ : ψ = χ.comp q.subtype) : ofIsCompl h φ ψ = χ := ofIsCompl_eq h (fun _ => hφ.symm ▸ rfl) fun _ => hψ.symm ▸ rfl theorem ofIsCompl_eq_add (hpq : IsCompl p q) {φ : p →ₗ[R] F} {ψ : q →ₗ[R] F} : ofIsCompl hpq φ ψ = (φ ∘ₗ p.linearProjOfIsCompl q hpq) + (ψ ∘ₗ q.linearProjOfIsCompl p hpq.symm) := by ext x obtain ⟨a, b, rfl, _⟩ := existsUnique_add_of_isCompl hpq x simp @[simp] theorem ofIsCompl_zero (h : IsCompl p q) : (ofIsCompl h 0 0 : E →ₗ[R] F) = 0 := ofIsCompl_eq _ (fun _ => rfl) fun _ => rfl @[simp] theorem ofIsCompl_add (h : IsCompl p q) {φ₁ φ₂ : p →ₗ[R] F} {ψ₁ ψ₂ : q →ₗ[R] F} : ofIsCompl h (φ₁ + φ₂) (ψ₁ + ψ₂) = ofIsCompl h φ₁ ψ₁ + ofIsCompl h φ₂ ψ₂ := ofIsCompl_eq _ (by simp) (by simp) @[simp] theorem ofIsCompl_smul {R : Type*} [CommRing R] {E : Type*} [AddCommGroup E] [Module R E] {F : Type*} [AddCommGroup F] [Module R F] {p q : Submodule R E} (h : IsCompl p q) {φ : p →ₗ[R] F} {ψ : q →ₗ[R] F} (c : R) : ofIsCompl h (c • φ) (c • ψ) = c • ofIsCompl h φ ψ := ofIsCompl_eq _ (by simp) (by simp) theorem surjective_comp_linearProjOfIsCompl (h : IsCompl p q) [Module R M] : Function.Surjective (comp (p.linearProjOfIsCompl q h) : (M →ₗ[R] E) → _) := fun f ↦ ⟨p.subtype ∘ₗ f, by ext; simp⟩ theorem surjective_comp_subtype_of_isComplemented (h : IsComplemented p) [Module R M] : Function.Surjective fun f : E →ₗ[R] M ↦ f ∘ₗ p.subtype := have ⟨q, h⟩ := h; fun f ↦ ⟨f ∘ₗ p.linearProjOfIsCompl q h, by ext; simp⟩ @[simp] theorem range_ofIsCompl (hpq : IsCompl p q) {φ : p →ₗ[R] F} {ψ : q →ₗ[R] F} : range (ofIsCompl hpq φ ψ) = range φ ⊔ range ψ := by rw [ofIsCompl_eq_add] apply le_antisymm · apply range_add_le _ _ |>.trans gcongr all_goals exact range_comp_le_range .. · apply sup_le all_goals rintro - ⟨x, rfl⟩; exact ⟨x, by simp⟩ theorem ofIsCompl_subtype_zero_eq (hpq : IsCompl p q) : ofIsCompl hpq p.subtype 0 = hpq.projection := by simp [ofIsCompl_eq_add, IsCompl.projection] theorem ofIsCompl_symm (hpq : IsCompl p q) {φ : p →ₗ[R] F} {ψ : q →ₗ[R] F} : ofIsCompl hpq.symm ψ φ = ofIsCompl hpq φ ψ := by simp [ofIsCompl_eq_add, add_comm] section variable {R₁ : Type*} [CommRing R₁] [Module R₁ E] [Module R₁ F] /-- The linear map from `(p →ₗ[R₁] F) × (q →ₗ[R₁] F)` to `E →ₗ[R₁] F`. -/ def ofIsComplProd {p q : Submodule R₁ E} (h : IsCompl p q) : (p →ₗ[R₁] F) × (q →ₗ[R₁] F) →ₗ[R₁] E →ₗ[R₁] F where toFun φ := ofIsCompl h φ.1 φ.2 map_add' := by intro φ ψ; rw [Prod.snd_add, Prod.fst_add, ofIsCompl_add] map_smul' := by intro c φ; simp [Prod.smul_snd, Prod.smul_fst, ofIsCompl_smul] @[simp] theorem ofIsComplProd_apply {p q : Submodule R₁ E} (h : IsCompl p q) (φ : (p →ₗ[R₁] F) × (q →ₗ[R₁] F)) : ofIsComplProd h φ = ofIsCompl h φ.1 φ.2 := rfl /-- The natural linear equivalence between `(p →ₗ[R₁] F) × (q →ₗ[R₁] F)` and `E →ₗ[R₁] F`. -/ def ofIsComplProdEquiv {p q : Submodule R₁ E} (h : IsCompl p q) : ((p →ₗ[R₁] F) × (q →ₗ[R₁] F)) ≃ₗ[R₁] E →ₗ[R₁] F := { ofIsComplProd h with invFun := fun φ => ⟨φ.domRestrict p, φ.domRestrict q⟩ left_inv := fun φ ↦ by ext x · exact ofIsCompl_left_apply h x · exact ofIsCompl_right_apply h x right_inv := fun φ ↦ by ext x obtain ⟨a, b, hab, _⟩ := existsUnique_add_of_isCompl h x rw [← hab]; simp } end @[simp] theorem linearProjOfIsCompl_of_proj (f : E →ₗ[R] p) (hf : ∀ x : p, f x = x) : p.linearProjOfIsCompl (ker f) (isCompl_of_proj hf) = f := by ext x have : x ∈ p ⊔ (ker f) := by simp only [(isCompl_of_proj hf).sup_eq_top, mem_top] rcases mem_sup'.1 this with ⟨x, y, rfl⟩ simp [hf] /-- If `f : E →ₗ[R] F` and `g : E →ₗ[R] G` are two surjective linear maps and their kernels are complement of each other, then `x ↦ (f x, g x)` defines a linear equivalence `E ≃ₗ[R] F × G`. -/ def equivProdOfSurjectiveOfIsCompl (f : E →ₗ[R] F) (g : E →ₗ[R] G) (hf : range f = ⊤) (hg : range g = ⊤) (hfg : IsCompl (ker f) (ker g)) : E ≃ₗ[R] F × G := LinearEquiv.ofBijective (f.prod g) ⟨by simp [← ker_eq_bot, hfg.inf_eq_bot], by rw [← range_eq_top] simp [range_prod_eq hfg.sup_eq_top, *]⟩ @[simp] theorem coe_equivProdOfSurjectiveOfIsCompl {f : E →ₗ[R] F} {g : E →ₗ[R] G} (hf : range f = ⊤) (hg : range g = ⊤) (hfg : IsCompl (ker f) (ker g)) : (equivProdOfSurjectiveOfIsCompl f g hf hg hfg : E →ₗ[R] F × G) = f.prod g := rfl @[simp] theorem equivProdOfSurjectiveOfIsCompl_apply {f : E →ₗ[R] F} {g : E →ₗ[R] G} (hf : range f = ⊤) (hg : range g = ⊤) (hfg : IsCompl (ker f) (ker g)) (x : E) : equivProdOfSurjectiveOfIsCompl f g hf hg hfg x = (f x, g x) := rfl end LinearMap namespace Submodule open LinearMap /-- Equivalence between submodules `q` such that `IsCompl p q` and linear maps `f : E →ₗ[R] p` such that `∀ x : p, f x = x`. -/ def isComplEquivProj : { q // IsCompl p q } ≃ { f : E →ₗ[R] p // ∀ x : p, f x = x } where toFun q := ⟨linearProjOfIsCompl p q q.2, linearProjOfIsCompl_apply_left q.2⟩ invFun f := ⟨ker (f : E →ₗ[R] p), isCompl_of_proj f.2⟩ left_inv := fun ⟨q, hq⟩ => by simp only [linearProjOfIsCompl_ker] right_inv := fun ⟨f, hf⟩ => Subtype.eq <| f.linearProjOfIsCompl_of_proj hf @[simp] theorem coe_isComplEquivProj_apply (q : { q // IsCompl p q }) : (p.isComplEquivProj q : E →ₗ[R] p) = linearProjOfIsCompl p q q.2 := rfl @[simp] theorem coe_isComplEquivProj_symm_apply (f : { f : E →ₗ[R] p // ∀ x : p, f x = x }) : (p.isComplEquivProj.symm f : Submodule R E) = ker (f : E →ₗ[R] p) := rfl /-- The idempotent endomorphisms of a module with range equal to a submodule are in 1-1 correspondence with linear maps to the submodule that restrict to the identity on the submodule. -/ @[simps] def isIdempotentElemEquiv : { f : Module.End R E // IsIdempotentElem f ∧ range f = p } ≃ { f : E →ₗ[R] p // ∀ x : p, f x = x } where toFun f := ⟨f.1.codRestrict _ fun x ↦ by simp_rw [← f.2.2]; exact mem_range_self f.1 x, fun ⟨x, hx⟩ ↦ Subtype.ext <| by obtain ⟨x, rfl⟩ := f.2.2.symm ▸ hx exact DFunLike.congr_fun f.2.1 x⟩ invFun f := ⟨p.subtype ∘ₗ f.1, LinearMap.ext fun x ↦ by simp [f.2], le_antisymm ((range_comp_le_range _ _).trans_eq p.range_subtype) fun x hx ↦ ⟨x, Subtype.ext_iff.1 <| f.2 ⟨x, hx⟩⟩⟩ end Submodule namespace LinearMap open Submodule /-- A linear endomorphism of a module `E` is a projection onto a submodule `p` if it sends every element of `E` to `p` and fixes every element of `p`. The definition allow more generally any `FunLike` type and not just linear maps, so that it can be used for example with `ContinuousLinearMap` or `Matrix`. -/ structure IsProj {F : Type*} [FunLike F M M] (f : F) : Prop where map_mem : ∀ x, f x ∈ m map_id : ∀ x ∈ m, f x = x theorem isProj_range_iff_isIdempotentElem (f : M →ₗ[S] M) : IsProj (range f) f ↔ IsIdempotentElem f := by refine ⟨fun ⟨h1, h2⟩ => ?_, fun hf => ⟨fun x => mem_range_self f x, fun x ⟨y, hy⟩ => by rw [← hy, ← Module.End.mul_apply, hf.eq]⟩⟩ ext x exact h2 (f x) (h1 x) alias ⟨_, IsIdempotentElem.isProj_range⟩ := isProj_range_iff_isIdempotentElem theorem isProj_iff_isIdempotentElem (f : M →ₗ[S] M) : (∃ p : Submodule S M, IsProj p f) ↔ IsIdempotentElem f := by refine ⟨fun ⟨p, hp⟩ => ?_, fun h => ⟨_, IsIdempotentElem.isProj_range _ h⟩⟩ ext x exact hp.map_id (f x) (hp.map_mem x) namespace IsProj variable {p m} theorem isIdempotentElem {f : M →ₗ[S] M} (h : IsProj m f) : IsIdempotentElem f := f.isProj_iff_isIdempotentElem.mp ⟨m, h⟩ theorem mem_iff_map_id {f : M →ₗ[S] M} (hf : IsProj m f) {x : M} : x ∈ m ↔ f x = x := ⟨hf.map_id x, fun h ↦ h ▸ hf.map_mem x⟩ /-- Restriction of the codomain of a projection of onto a subspace `p` to `p` instead of the whole space. -/ def codRestrict {f : M →ₗ[S] M} (h : IsProj m f) : M →ₗ[S] m := f.codRestrict m h.map_mem @[simp] theorem codRestrict_apply {f : M →ₗ[S] M} (h : IsProj m f) (x : M) : ↑(h.codRestrict x) = f x := f.codRestrict_apply m x @[simp] theorem codRestrict_apply_cod {f : M →ₗ[S] M} (h : IsProj m f) (x : m) : h.codRestrict x = x := by ext rw [codRestrict_apply] exact h.map_id x x.2 theorem codRestrict_ker {f : M →ₗ[S] M} (h : IsProj m f) : ker h.codRestrict = ker f := f.ker_codRestrict m _ theorem isCompl {f : E →ₗ[R] E} (h : IsProj p f) : IsCompl p (ker f) := by rw [← codRestrict_ker h] exact isCompl_of_proj h.codRestrict_apply_cod theorem eq_conj_prod_map' {f : E →ₗ[R] E} (h : IsProj p f) : f = (p.prodEquivOfIsCompl (ker f) h.isCompl).toLinearMap ∘ₗ prodMap id 0 ∘ₗ (p.prodEquivOfIsCompl (ker f) h.isCompl).symm.toLinearMap := by rw [← LinearMap.comp_assoc, LinearEquiv.eq_comp_toLinearMap_symm] ext x · simp only [coe_prodEquivOfIsCompl, comp_apply, coe_inl, coprod_apply, coe_subtype, map_zero, add_zero, h.map_id x x.2, prodMap_apply, id_apply] · simp only [coe_prodEquivOfIsCompl, comp_apply, coe_inr, coprod_apply, map_zero, coe_subtype, zero_add, map_coe_ker, prodMap_apply, zero_apply, add_zero] theorem submodule_unique {f : M →ₗ[S] M} {m₁ m₂ : Submodule S M} (hf₁ : IsProj m₁ f) (hf₂ : IsProj m₂ f) : m₁ = m₂ := by ext; simp [hf₁.mem_iff_map_id, hf₂.mem_iff_map_id] open LinearMap in protected theorem range {f : M →ₗ[S] M} (h : IsProj m f) : range f = m := h.isIdempotentElem.isProj_range.submodule_unique h variable (S M) in protected theorem bot : IsProj (⊥ : Submodule S M) (0 : M →ₗ[S] M) := ⟨congrFun rfl, by simp only [mem_bot, zero_apply, forall_eq]⟩ variable (S M) in protected theorem top : IsProj (⊤ : Submodule S M) (id (R := S)) := ⟨fun _ ↦ trivial, fun _ ↦ congrFun rfl⟩ theorem subtype_comp_codRestrict {U : Submodule S M} {f : M →ₗ[S] M} (hf : IsProj U f) : U.subtype ∘ₗ hf.codRestrict = f := rfl theorem submodule_eq_top_iff {f : M →ₗ[S] M} (hf : IsProj m f) : m = (⊤ : Submodule S M) ↔ f = LinearMap.id := by constructor <;> rintro rfl · ext simp [hf.map_id] · rw [← hf.range, range_id] theorem submodule_eq_bot_iff {f : M →ₗ[S] M} (hf : IsProj m f) : m = (⊥ : Submodule S M) ↔ f = 0 := by constructor <;> rintro rfl · ext simpa using hf.map_mem _ · rw [← hf.range, range_zero] end IsProj open LinearMap in lemma IsIdempotentElem.isCompl {f : E →ₗ[R] E} (hf : IsIdempotentElem f) : IsCompl (range f) (ker f) := hf.isProj_range.isCompl open LinearMap in /-- Given an idempotent linear operator `p`, we have `x ∈ range p` if and only if `p(x) = x` for all `x`. -/ theorem IsIdempotentElem.mem_range_iff {p : M →ₗ[S] M} (hp : IsIdempotentElem p) {x : M} : x ∈ range p ↔ p x = x := hp.isProj_range.mem_iff_map_id open LinearMap in /-- An idempotent linear operator is equal to the linear projection onto its range along its kernel. -/ theorem IsIdempotentElem.eq_isCompl_projection {T : E →ₗ[R] E} (hT : IsIdempotentElem T) : T = hT.isCompl.projection := by convert ofIsCompl_subtype_zero_eq hT.isCompl exact ofIsCompl_eq _ (by simp [hT.isProj_range.map_id]) (by simp) |>.symm open LinearMap in /-- A linear map is an idempotent if and only if it equals the projection onto its range along its kernel. -/ theorem isIdempotentElem_iff_eq_isCompl_projection_range_ker {T : E →ₗ[R] E} : IsIdempotentElem T ↔ ∃ (h : IsCompl (range T) (ker T)), T = h.projection := ⟨fun hT => ⟨hT.isProj_range.isCompl, hT.eq_isCompl_projection⟩, fun ⟨hT, h⟩ => h.symm ▸ hT.projection_isIdempotentElem⟩ open LinearMap in /-- Given an idempotent linear operator `q`, we have `q ∘ p = p` iff `range p ⊆ range q` for all `p`. -/ theorem IsIdempotentElem.comp_eq_right_iff {q : M →ₗ[S] M} (hq : IsIdempotentElem q) {E : Type*} [AddCommMonoid E] [Module S E] (p : E →ₗ[S] M) : q.comp p = p ↔ range p ≤ range q := by simp_rw [LinearMap.ext_iff, comp_apply, ← hq.mem_range_iff, SetLike.le_def, mem_range, forall_exists_index, forall_apply_eq_imp_iff] open LinearMap in /-- Idempotent operators are equal iff their range and kernels are. -/ lemma IsIdempotentElem.ext_iff {p q : E →ₗ[R] E} (hp : IsIdempotentElem p) (hq : IsIdempotentElem q) : p = q ↔ range p = range q ∧ ker p = ker q := by refine ⟨fun h => ⟨congrArg range h, congrArg ker h⟩, fun ⟨hr, hk⟩ => ?_⟩ ext x obtain ⟨⟨v, hv⟩, ⟨w, hw⟩, rfl, _⟩ := (ker p).existsUnique_add_of_isCompl hp.isCompl.symm x simp [mem_ker.mp, hv, (hk ▸ hv), (mem_range_iff hp).mp, hw, (mem_range_iff hq).mp, (hr ▸ hw)] alias ⟨_, IsIdempotentElem.ext⟩ := IsIdempotentElem.ext_iff theorem IsIdempotentElem.range_eq_ker {E : Type*} [AddCommGroup E] [Module S E] {p : E →ₗ[S] E} (hp : IsIdempotentElem p) : LinearMap.range p = LinearMap.ker (1 - p) := le_antisymm (LinearMap.range_le_ker_iff.mpr hp.one_sub_mul_self) fun x hx ↦ ⟨x, by simpa [sub_eq_zero, eq_comm (a := x)] using hx⟩ open LinearMap in theorem IsIdempotentElem.ker_eq_range {E : Type*} [AddCommGroup E] [Module S E] {p : E →ₗ[S] E} (hp : IsIdempotentElem p) : LinearMap.ker p = LinearMap.range (1 - p) := by simpa using hp.one_sub.range_eq_ker.symm open LinearMap in theorem IsIdempotentElem.comp_eq_left_iff {M : Type*} [AddCommGroup M] [Module S M] {q : M →ₗ[S] M} (hq : IsIdempotentElem q) {E : Type*} [AddCommGroup E] [Module S E] (p : M →ₗ[S] E) : p ∘ₗ q = p ↔ ker q ≤ ker p := by simp [hq.ker_eq_range, range_le_ker_iff, comp_sub, Module.End.one_eq_id, sub_eq_zero, eq_comm (a := p)] end LinearMap end Ring section CommRing namespace LinearMap variable {R : Type*} [CommRing R] {E : Type*} [AddCommGroup E] [Module R E] {p : Submodule R E} theorem IsProj.eq_conj_prodMap {f : E →ₗ[R] E} (h : IsProj p f) : f = (p.prodEquivOfIsCompl (ker f) h.isCompl).conj (prodMap id 0) := by rw [LinearEquiv.conj_apply] exact h.eq_conj_prod_map' end LinearMap end CommRing namespace LinearMap.IsIdempotentElem open Submodule LinearMap variable {E R : Type*} [Ring R] [AddCommGroup E] [Module R E] {T f : E →ₗ[R] E} /-- `range f` is invariant under `T` if and only if `f ∘ₗ T ∘ₗ f = T ∘ₗ f`, for idempotent `f`. -/ lemma range_mem_invtSubmodule_iff (hf : IsIdempotentElem f) : range f ∈ Module.End.invtSubmodule T ↔ f ∘ₗ T ∘ₗ f = T ∘ₗ f := by rw [hf.comp_eq_right_iff, range_comp, Module.End.mem_invtSubmodule_iff_map_le] alias ⟨conj_eq_of_range_mem_invtSubmodule, range_mem_invtSubmodule⟩ := range_mem_invtSubmodule_iff lemma _root_.LinearMap.IsProj.mem_invtSubmodule_iff {U : Submodule R E} (hf : IsProj U f) : U ∈ Module.End.invtSubmodule T ↔ f ∘ₗ T ∘ₗ f = T ∘ₗ f := hf.range ▸ hf.isIdempotentElem.range_mem_invtSubmodule_iff open LinearMap in /-- `ker f` is invariant under `T` if and only if `f ∘ₗ T ∘ₗ f = f ∘ₗ T`, for idempotent `f`. -/ lemma ker_mem_invtSubmodule_iff (hf : IsIdempotentElem f) : ker f ∈ Module.End.invtSubmodule T ↔ f ∘ₗ T ∘ₗ f = f ∘ₗ T := by rw [← comp_assoc, hf.comp_eq_left_iff, ker_comp, Module.End.mem_invtSubmodule] alias ⟨conj_eq_of_ker_mem_invtSubmodule, ker_mem_invtSubmodule⟩ := ker_mem_invtSubmodule_iff /-- An idempotent operator `f` commutes with a linear operator `T` if and only if both `range f` and `ker f` are invariant under `T`. -/ lemma commute_iff (hf : IsIdempotentElem f) : Commute f T ↔ (range f ∈ Module.End.invtSubmodule T ∧ ker f ∈ Module.End.invtSubmodule T) := by simp_rw [hf.range_mem_invtSubmodule_iff, hf.ker_mem_invtSubmodule_iff, ← Module.End.mul_eq_comp] exact ⟨fun h => (by simp [← h.eq, ← mul_assoc, hf.eq]), fun ⟨h1, h2⟩ => h2.symm.trans h1⟩ /-- An idempotent operator `f` commutes with an unit operator `T` if and only if `T (range f) = range f` and `T (ker f) = ker f`. -/ theorem commute_iff_of_isUnit (hT : IsUnit T) (hf : IsIdempotentElem f) : Commute f T ↔ (range f).map T = range f ∧ (ker f).map T = ker f := by lift T to GeneralLinearGroup R E using hT have {a : E ≃ₗ[R] E} {b : Submodule R E} : b ≤ b.map a.toLinearMap ↔ b ≤ b.map a := by rfl simp_rw [← GeneralLinearGroup.generalLinearEquiv_to_linearMap, le_antisymm_iff, ← Module.End.mem_invtSubmodule_iff_map_le, this, ← Module.End.mem_invtSubmodule_symm_iff_le_map, and_and_and_comm (c := (ker f ∈ _)), ← hf.commute_iff, GeneralLinearGroup.generalLinearEquiv_to_linearMap, iff_self_and] exact Commute.units_inv_right end LinearMap.IsIdempotentElem
.lake/packages/mathlib/Mathlib/LinearAlgebra/Goursat.lean
import Mathlib.GroupTheory.Goursat import Mathlib.LinearAlgebra.Prod import Mathlib.LinearAlgebra.Quotient.Basic /-! # Goursat's lemma for submodules Let `M, N` be modules over a ring `R`. If `L` is a submodule of `M × N` which projects fully on to both factors, then there exist submodules `M' ≤ M` and `N' ≤ N` such that `M' × N' ≤ L` and the image of `L` in `(M ⧸ M') × (N ⧸ N')` is the graph of an isomorphism `M ⧸ M' ≃ₗ[R] N ⧸ N'`. Equivalently, `L` is equal to the preimage in `M × N` of the graph of this isomorphism `M ⧸ M' ≃ₗ[R] N ⧸ N'`. `M'` and `N'` can be explicitly constructed as `Submodule.goursatFst L` and `Submodule.goursatSnd L` respectively. -/ open Function Set LinearMap namespace Submodule variable {R M N : Type*} [Ring R] [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N] {L : Submodule R (M × N)} (hL₁ : Surjective (Prod.fst ∘ L.subtype)) (hL₂ : Surjective (Prod.snd ∘ L.subtype)) variable (L) in /-- For `L` a submodule of `M × N`, `L.goursatFst` is the kernel of the projection map `L → N`, considered as a submodule of `M`. This is the first submodule appearing in Goursat's lemma. See `Subgroup.goursat`. -/ def goursatFst : Submodule R M := (LinearMap.ker <| (LinearMap.snd R M N).comp L.subtype).map ((LinearMap.fst R M N).comp L.subtype) variable (L) in /-- For `L` a subgroup of `M × N`, `L.goursatSnd` is the kernel of the projection map `L → M`, considered as a subgroup of `N`. This is the second subgroup appearing in Goursat's lemma. See `Subgroup.goursat`. -/ def goursatSnd : Submodule R N := (LinearMap.ker <| (LinearMap.fst R M N).comp L.subtype).map ((LinearMap.snd R M N).comp L.subtype) lemma goursatFst_toAddSubgroup : (goursatFst L).toAddSubgroup = L.toAddSubgroup.goursatFst := by ext x simp [mem_toAddSubgroup, goursatFst, AddSubgroup.mem_goursatFst] lemma goursatSnd_toAddSubgroup : (goursatSnd L).toAddSubgroup = L.toAddSubgroup.goursatSnd := by ext x simp [mem_toAddSubgroup, goursatSnd, AddSubgroup.mem_goursatSnd] variable (L) in lemma goursatFst_prod_goursatSnd_le : L.goursatFst.prod L.goursatSnd ≤ L := by simpa only [← toAddSubgroup_le, goursatFst_toAddSubgroup, goursatSnd_toAddSubgroup] using L.toAddSubgroup.goursatFst_prod_goursatSnd_le include hL₁ hL₂ in /-- **Goursat's lemma** for a submodule of a product with surjective projections. If `L` is a submodule of `M × N` which projects fully on both factors, then there exist submodules `M' ≤ M` and `N' ≤ N` such that `M' × N' ≤ L` and the image of `L` in `(M ⧸ M') × (N ⧸ N')` is the graph of an isomorphism of `R`-modules `(M ⧸ M') ≃ (N ⧸ N')`. `M` and `N` can be explicitly constructed as `L.goursatFst` and `L.goursatSnd` respectively. -/ lemma goursat_surjective : ∃ e : (M ⧸ L.goursatFst) ≃ₗ[R] N ⧸ L.goursatSnd, LinearMap.range ((L.goursatFst.mkQ.prodMap L.goursatSnd.mkQ).comp L.subtype) = e.graph := by -- apply add-group result obtain ⟨(e : M ⧸ L.goursatFst ≃+ N ⧸ L.goursatSnd), he⟩ := L.toAddSubgroup.goursat_surjective hL₁ hL₂ -- check R-linearity of the map have (r : R) (x : M ⧸ L.goursatFst) : e (r • x) = r • e x := by change (r • x, r • e x) ∈ e.toAddMonoidHom.graph rw [← he, ← Prod.smul_mk] have : (x, e x) ∈ e.toAddMonoidHom.graph := rfl rw [← he, AddMonoidHom.mem_range] at this rcases this with ⟨⟨l, hl⟩, hl'⟩ use ⟨r • l, L.smul_mem r hl⟩ rw [← hl'] rfl -- define the map as an R-linear equiv use { e with map_smul' := this } rw [← toAddSubgroup_injective.eq_iff] convert he using 1 ext v rw [mem_toAddSubgroup, mem_graph_iff, Eq.comm] rfl /-- **Goursat's lemma** for an arbitrary submodule of a product. If `L` is a submodule of `M × N`, then there exist submodules `M'' ≤ M' ≤ M` and `N'' ≤ N' ≤ N` such that `L ≤ M' × N'`, and `L` is (the image in `M × N` of) the preimage of the graph of an `R`-linear isomorphism `M' ⧸ M'' ≃ N' ⧸ N''`. -/ lemma goursat : ∃ (M' : Submodule R M) (N' : Submodule R N) (M'' : Submodule R M') (N'' : Submodule R N') (e : (M' ⧸ M'') ≃ₗ[R] N' ⧸ N''), L = (e.graph.comap <| M''.mkQ.prodMap N''.mkQ).map (M'.subtype.prodMap N'.subtype) := by let M' := L.map (LinearMap.fst ..) let N' := L.map (LinearMap.snd ..) let P : L →ₗ[R] M' := (LinearMap.fst ..).submoduleMap L let Q : L →ₗ[R] N' := (LinearMap.snd ..).submoduleMap L let L' : Submodule R (M' × N') := LinearMap.range (P.prod Q) have hL₁' : Surjective (Prod.fst ∘ L'.subtype) := by simp only [← coe_fst (R := R), ← coe_comp, ← range_eq_top, LinearMap.range_comp, range_subtype] simpa only [L', ← LinearMap.range_comp, fst_prod, range_eq_top] using (LinearMap.fst ..).submoduleMap_surjective L have hL₂' : Surjective (Prod.snd ∘ L'.subtype) := by simp only [← coe_snd (R := R), ← coe_comp, ← range_eq_top, LinearMap.range_comp, range_subtype] simpa only [L', ← LinearMap.range_comp, snd_prod, range_eq_top] using (LinearMap.snd ..).submoduleMap_surjective L obtain ⟨e, he⟩ := goursat_surjective hL₁' hL₂' use M', N', L'.goursatFst, L'.goursatSnd, e rw [← he] simp only [LinearMap.range_comp, Submodule.range_subtype, L'] rw [comap_map_eq_self] · ext ⟨m, n⟩ constructor · intro hmn simp only [mem_map, LinearMap.mem_range, prod_apply, Subtype.exists, Prod.exists, coe_prodMap, coe_subtype, Prod.map_apply, Prod.mk.injEq, exists_and_right, exists_eq_right_right, exists_eq_right, M', N', fst_apply, snd_apply] exact ⟨⟨n, hmn⟩, ⟨m, hmn⟩, ⟨m, n, hmn, rfl⟩⟩ · simp only [mem_map, LinearMap.mem_range, prod_apply, Subtype.exists, Prod.exists, coe_prodMap, coe_subtype, Prod.map_apply, Prod.mk.injEq, exists_and_right, exists_eq_right_right, exists_eq_right, forall_exists_index, Pi.prod] rintro hm hn m₁ n₁ hm₁n₁ ⟨hP, hQ⟩ simp only [Subtype.ext_iff] at hP hQ rwa [← hP, ← hQ] · convert goursatFst_prod_goursatSnd_le (range <| P.prod Q) ext ⟨m, n⟩ simp_rw [mem_ker, coe_prodMap, Prod.map_apply, Submodule.mem_prod, Prod.zero_eq_mk, Prod.ext_iff, ← mem_ker, ker_mkQ] end Submodule
.lake/packages/mathlib/Mathlib/LinearAlgebra/Determinant.lean
import Mathlib.LinearAlgebra.FreeModule.StrongRankCondition import Mathlib.LinearAlgebra.GeneralLinearGroup import Mathlib.LinearAlgebra.Matrix.Reindex import Mathlib.Tactic.FieldSimp import Mathlib.LinearAlgebra.Dual.Basis import Mathlib.LinearAlgebra.Matrix.Dual import Mathlib.LinearAlgebra.Matrix.NonsingularInverse import Mathlib.LinearAlgebra.Matrix.Basis import Mathlib.LinearAlgebra.Matrix.ToLinearEquiv import Mathlib.RingTheory.Finiteness.Cardinality /-! # Determinant of families of vectors This file defines the determinant of an endomorphism, and of a family of vectors with respect to some basis. For the determinant of a matrix, see the file `LinearAlgebra.Matrix.Determinant`. ## Main definitions In the list below, and in all this file, `R` is a commutative ring (semiring is sometimes enough), `M` and its variations are `R`-modules, `ι`, `κ`, `n` and `m` are finite types used for indexing. * `Basis.det`: the determinant of a family of vectors with respect to a basis, as a multilinear map * `LinearMap.det`: the determinant of an endomorphism `f : End R M` as a multiplicative homomorphism (if `M` does not have a finite `R`-basis, the result is `1` instead) * `LinearEquiv.det`: the determinant of an isomorphism `f : M ≃ₗ[R] M` as a multiplicative homomorphism (if `M` does not have a finite `R`-basis, the result is `1` instead) ## Tags basis, det, determinant -/ noncomputable section open Matrix Module LinearMap Submodule Set Function universe u v w variable {R : Type*} [CommRing R] variable {M : Type*} [AddCommGroup M] [Module R M] variable {M' : Type*} [AddCommGroup M'] [Module R M'] variable {ι : Type*} [DecidableEq ι] [Fintype ι] variable (e : Basis ι R M) section Conjugate variable {A : Type*} [CommRing A] variable {m n : Type*} /-- If `R^m` and `R^n` are linearly equivalent, then `m` and `n` are also equivalent. -/ def equivOfPiLEquivPi {R : Type*} [Finite m] [Finite n] [CommRing R] [Nontrivial R] (e : (m → R) ≃ₗ[R] n → R) : m ≃ n := Basis.indexEquiv (Basis.ofEquivFun e.symm) (Pi.basisFun _ _) namespace Matrix variable [Fintype m] [Fintype n] /-- If `M` and `M'` are each other's inverse matrices, they are square matrices up to equivalence of types. -/ def indexEquivOfInv [Nontrivial A] [DecidableEq m] [DecidableEq n] {M : Matrix m n A} {M' : Matrix n m A} (hMM' : M * M' = 1) (hM'M : M' * M = 1) : m ≃ n := equivOfPiLEquivPi (toLin'OfInv hMM' hM'M) theorem det_comm [DecidableEq n] (M N : Matrix n n A) : det (M * N) = det (N * M) := by rw [det_mul, det_mul, mul_comm] /-- If there exists a two-sided inverse `M'` for `M` (indexed differently), then `det (N * M) = det (M * N)`. -/ theorem det_comm' [DecidableEq m] [DecidableEq n] {M : Matrix n m A} {N : Matrix m n A} {M' : Matrix m n A} (hMM' : M * M' = 1) (hM'M : M' * M = 1) : det (M * N) = det (N * M) := by nontriviality A -- Although `m` and `n` are different a priori, we will show they have the same cardinality. -- This turns the problem into one for square matrices, which is easy. let e := indexEquivOfInv hMM' hM'M rw [← det_submatrix_equiv_self e, ← submatrix_mul_equiv _ _ _ (Equiv.refl n) _, det_comm, submatrix_mul_equiv, Equiv.coe_refl, submatrix_id_id] /-- If `M'` is a two-sided inverse for `M` (indexed differently), `det (M * N * M') = det N`. See `Matrix.det_conj` and `Matrix.det_conj'` for the case when `M' = M⁻¹` or vice versa. -/ theorem det_conj_of_mul_eq_one [DecidableEq m] [DecidableEq n] {M : Matrix m n A} {M' : Matrix n m A} {N : Matrix n n A} (hMM' : M * M' = 1) (hM'M : M' * M = 1) : det (M * N * M') = det N := by rw [← det_comm' hM'M hMM', ← Matrix.mul_assoc, hM'M, Matrix.one_mul] end Matrix end Conjugate namespace LinearMap /-! ### Determinant of a linear map -/ variable {A : Type*} [CommRing A] [Module A M] variable {κ : Type*} [Fintype κ] /-- The determinant of `LinearMap.toMatrix` does not depend on the choice of basis. -/ theorem det_toMatrix_eq_det_toMatrix [DecidableEq κ] (b : Basis ι A M) (c : Basis κ A M) (f : M →ₗ[A] M) : det (LinearMap.toMatrix b b f) = det (LinearMap.toMatrix c c f) := by rw [← linearMap_toMatrix_mul_basis_toMatrix c b c, ← basis_toMatrix_mul_linearMap_toMatrix b c b, Matrix.det_conj_of_mul_eq_one] <;> rw [Basis.toMatrix_mul_toMatrix, Basis.toMatrix_self] /-- The determinant of an endomorphism given a basis. See `LinearMap.det` for a version that populates the basis non-computably. Although the `Trunc (Basis ι A M)` parameter makes it slightly more convenient to switch bases, there is no good way to generalize over universe parameters, so we can't fully state in `detAux`'s type that it does not depend on the choice of basis. Instead you can use the `detAux_def''` lemma, or avoid mentioning a basis at all using `LinearMap.det`. -/ irreducible_def detAux : Trunc (Basis ι A M) → (M →ₗ[A] M) →* A := Trunc.lift (fun b : Basis ι A M => detMonoidHom.comp (toMatrixAlgEquiv b : (M →ₗ[A] M) →* Matrix ι ι A)) fun b c => MonoidHom.ext <| det_toMatrix_eq_det_toMatrix b c /-- Unfold lemma for `detAux`. See also `detAux_def''` which allows you to vary the basis. -/ theorem detAux_def' (b : Basis ι A M) (f : M →ₗ[A] M) : LinearMap.detAux (Trunc.mk b) f = Matrix.det (LinearMap.toMatrix b b f) := by rw [detAux] rfl theorem detAux_def'' {ι' : Type*} [Fintype ι'] [DecidableEq ι'] (tb : Trunc <| Basis ι A M) (b' : Basis ι' A M) (f : M →ₗ[A] M) : LinearMap.detAux tb f = Matrix.det (LinearMap.toMatrix b' b' f) := by induction tb using Trunc.induction_on with | h b => rw [detAux_def', det_toMatrix_eq_det_toMatrix b b'] @[simp] theorem detAux_id (b : Trunc <| Basis ι A M) : LinearMap.detAux b LinearMap.id = 1 := (LinearMap.detAux b).map_one @[simp] theorem detAux_comp (b : Trunc <| Basis ι A M) (f g : M →ₗ[A] M) : LinearMap.detAux b (f.comp g) = LinearMap.detAux b f * LinearMap.detAux b g := (LinearMap.detAux b).map_mul f g section open scoped Classical in -- Discourage the elaborator from unfolding `det` and producing a huge term by marking it -- as irreducible. /-- The determinant of an endomorphism independent of basis. If there is no finite basis on `M`, the result is `1` instead. -/ protected irreducible_def det : (M →ₗ[A] M) →* A := if H : ∃ s : Finset M, Nonempty (Basis s A M) then LinearMap.detAux (Trunc.mk H.choose_spec.some) else 1 open scoped Classical in theorem coe_det [DecidableEq M] : ⇑(LinearMap.det : (M →ₗ[A] M) →* A) = if H : ∃ s : Finset M, Nonempty (Basis s A M) then LinearMap.detAux (Trunc.mk H.choose_spec.some) else 1 := by ext rw [LinearMap.det_def] split_ifs · congr -- use the correct `DecidableEq` instance rfl end -- Auxiliary lemma, the `simp` normal form goes in the other direction -- (using `LinearMap.det_toMatrix`) theorem det_eq_det_toMatrix_of_finset [DecidableEq M] {s : Finset M} (b : Basis s A M) (f : M →ₗ[A] M) : LinearMap.det f = Matrix.det (LinearMap.toMatrix b b f) := by have : ∃ s : Finset M, Nonempty (Basis s A M) := ⟨s, ⟨b⟩⟩ rw [LinearMap.coe_det, dif_pos this, detAux_def'' _ b] @[simp] theorem det_toMatrix (b : Basis ι A M) (f : M →ₗ[A] M) : Matrix.det (toMatrix b b f) = LinearMap.det f := by haveI := Classical.decEq M rw [det_eq_det_toMatrix_of_finset b.reindexFinsetRange, det_toMatrix_eq_det_toMatrix b b.reindexFinsetRange] @[simp] theorem det_toMatrix' {ι : Type*} [Fintype ι] [DecidableEq ι] (f : (ι → A) →ₗ[A] ι → A) : Matrix.det (LinearMap.toMatrix' f) = LinearMap.det f := by simp [← toMatrix_eq_toMatrix'] @[simp] theorem det_toLin (b : Basis ι R M) (f : Matrix ι ι R) : LinearMap.det (Matrix.toLin b b f) = f.det := by rw [← LinearMap.det_toMatrix b, LinearMap.toMatrix_toLin] @[simp] theorem det_toLin' (f : Matrix ι ι R) : LinearMap.det (Matrix.toLin' f) = Matrix.det f := by simp only [← toLin_eq_toLin', det_toLin] /-- To show `P (LinearMap.det f)` it suffices to consider `P (Matrix.det (toMatrix _ _ f))` and `P 1`. -/ @[elab_as_elim] theorem det_cases [DecidableEq M] {P : A → Prop} (f : M →ₗ[A] M) (hb : ∀ (s : Finset M) (b : Basis s A M), P (Matrix.det (toMatrix b b f))) (h1 : P 1) : P (LinearMap.det f) := by classical if H : ∃ s : Finset M, Nonempty (Basis s A M) then obtain ⟨s, ⟨b⟩⟩ := H rw [← det_toMatrix b] exact hb s b else rwa [LinearMap.det_def, dif_neg H] @[simp] theorem det_comp (f g : M →ₗ[A] M) : LinearMap.det (f.comp g) = LinearMap.det f * LinearMap.det g := LinearMap.det.map_mul f g @[simp] theorem det_id : LinearMap.det (LinearMap.id : M →ₗ[A] M) = 1 := LinearMap.det.map_one /-- Multiplying a map by a scalar `c` multiplies its determinant by `c ^ dim M`. -/ @[simp] theorem det_smul [Module.Free A M] (c : A) (f : M →ₗ[A] M) : LinearMap.det (c • f) = c ^ Module.finrank A M * LinearMap.det f := by nontriviality A by_cases H : ∃ s : Finset M, Nonempty (Basis s A M) · have : Module.Finite A M := by rcases H with ⟨s, ⟨hs⟩⟩ exact Module.Finite.of_basis hs simp only [← det_toMatrix (Module.finBasis A M), LinearEquiv.map_smul, Fintype.card_fin, Matrix.det_smul] · classical have : Module.finrank A M = 0 := finrank_eq_zero_of_not_exists_basis H simp [coe_det, H, this] theorem det_zero' {ι : Type*} [Finite ι] [Nonempty ι] (b : Basis ι A M) : LinearMap.det (0 : M →ₗ[A] M) = 0 := by haveI := Classical.decEq ι cases nonempty_fintype ι rwa [← det_toMatrix b, LinearEquiv.map_zero, det_zero] /-- In a finite-dimensional vector space, the zero map has determinant `1` in dimension `0`, and `0` otherwise. We give a formula that also works in infinite dimension, where we define the determinant to be `1`. -/ @[simp] theorem det_zero [Module.Free A M] : LinearMap.det (0 : M →ₗ[A] M) = (0 : A) ^ Module.finrank A M := by simp only [← zero_smul A (1 : M →ₗ[A] M), det_smul, mul_one, MonoidHom.map_one] theorem det_eq_one_of_not_module_finite (h : ¬Module.Finite R M) (f : M →ₗ[R] M) : f.det = 1 := by rw [LinearMap.det, dif_neg, MonoidHom.one_apply] exact fun ⟨_, ⟨b⟩⟩ ↦ h (Module.Finite.of_basis b) @[nontriviality] theorem det_eq_one_of_subsingleton [Subsingleton M] (f : M →ₗ[R] M) : LinearMap.det (f : M →ₗ[R] M) = 1 := by have b : Basis (Fin 0) R M := Basis.empty M rw [← f.det_toMatrix b] exact Matrix.det_isEmpty theorem det_eq_one_of_finrank_eq_zero {𝕜 : Type*} [Field 𝕜] {M : Type*} [AddCommGroup M] [Module 𝕜 M] (h : Module.finrank 𝕜 M = 0) (f : M →ₗ[𝕜] M) : LinearMap.det (f : M →ₗ[𝕜] M) = 1 := by classical refine @LinearMap.det_cases M _ 𝕜 _ _ _ (fun t => t = 1) f ?_ rfl intro s b have : IsEmpty s := by rw [← Fintype.card_eq_zero_iff] exact (Module.finrank_eq_card_basis b).symm.trans h exact Matrix.det_isEmpty /-- Conjugating a linear map by a linear equiv does not change its determinant. -/ @[simp] theorem det_conj {N : Type*} [AddCommGroup N] [Module A N] (f : M →ₗ[A] M) (e : M ≃ₗ[A] N) : LinearMap.det ((e : M →ₗ[A] N) ∘ₗ f ∘ₗ (e.symm : N →ₗ[A] M)) = LinearMap.det f := by classical by_cases H : ∃ s : Finset M, Nonempty (Basis s A M) · rcases H with ⟨s, ⟨b⟩⟩ rw [← det_toMatrix b f, ← det_toMatrix (b.map e), toMatrix_comp (b.map e) b (b.map e), toMatrix_comp (b.map e) b b, ← Matrix.mul_assoc, Matrix.det_conj_of_mul_eq_one] · rw [← toMatrix_comp, LinearEquiv.comp_coe, e.symm_trans_self, LinearEquiv.refl_toLinearMap, toMatrix_id] · rw [← toMatrix_comp, LinearEquiv.comp_coe, e.self_trans_symm, LinearEquiv.refl_toLinearMap, toMatrix_id] · have H' : ¬∃ t : Finset N, Nonempty (Basis t A N) := by contrapose! H rcases H with ⟨s, ⟨b⟩⟩ exact ⟨_, ⟨(b.map e.symm).reindexFinsetRange⟩⟩ simp only [coe_det, H, H', MonoidHom.one_apply, dif_neg, not_false_eq_true] /-- If a linear map is invertible, so is its determinant. -/ theorem isUnit_det {A : Type*} [CommRing A] [Module A M] (f : M →ₗ[A] M) (hf : IsUnit f) : IsUnit (LinearMap.det f) := IsUnit.map LinearMap.det hf lemma isUnit_iff_isUnit_det [Module.Finite R M] [Module.Free R M] (f : M →ₗ[R] M) : IsUnit f ↔ IsUnit f.det := by let b := Module.Free.chooseBasis R M rw [← isUnit_toMatrix_iff b, ← det_toMatrix b, Matrix.isUnit_iff_isUnit_det (toMatrix b b f)] /-- If a linear map has determinant different from `1`, then the space is finite-dimensional. -/ theorem finite_of_det_ne_one {f : M →ₗ[R] M} (hf : f.det ≠ 1) : Module.Finite R M := by by_cases H : ∃ s : Finset M, Nonempty (Basis s R M) · rcases H with ⟨s, ⟨hs⟩⟩ exact Module.Finite.of_basis hs · classical simp [LinearMap.coe_det, H] at hf @[deprecated "use `finite_of_det_ne_one` instead" (since := "2025-09-15")] theorem finiteDimensional_of_det_ne_one {𝕜 : Type*} [Field 𝕜] [Module 𝕜 M] (f : M →ₗ[𝕜] M) (hf : LinearMap.det f ≠ 1) : FiniteDimensional 𝕜 M := finite_of_det_ne_one hf /-- If the determinant of a map vanishes, then the map is not injective. -/ theorem bot_lt_ker_of_det_eq_zero [IsDomain R] [Free R M] {f : M →ₗ[R] M} (hf : f.det = 0) : ⊥ < ker f := by have : Module.Finite R M := by simp [finite_of_det_ne_one (f := f), hf] let b := Module.finBasis R M suffices ∃ x, f x = 0 ∧ x ≠ 0 by simpa [bot_lt_iff_ne_bot, ker_eq_bot'] obtain ⟨v, hv_ne_zero, hv_zero⟩ := Matrix.exists_mulVec_eq_zero_iff.mpr (det_toMatrix b f ▸ hf) refine ⟨b.equivFun.symm v, ?_, b.equivFun.symm.map_ne_zero_iff.mpr hv_ne_zero⟩ rw [← b.equivFun.injective.eq_iff] simp_all [funext_iff, Matrix.mulVec, dotProduct, toMatrix_apply, mul_comm] /-- The determinant of a map vanishes iff the map is not injective. -/ theorem det_eq_zero_iff_ker_ne_bot [IsDomain R] [Free R M] [Module.Finite R M] {f : M →ₗ[R] M} : f.det = 0 ↔ ker f ≠ ⊥ := by constructor <;> intro h · exact bot_lt_iff_ne_bot.mp (bot_lt_ker_of_det_eq_zero h) · let b := Module.finBasis R M obtain ⟨v, ⟨_, hv_ne_zero⟩⟩ := (ker f).ne_bot_iff.mp h rw [← det_toMatrix b, ← Matrix.exists_mulVec_eq_zero_iff] refine ⟨fun i => b.repr v i, by simpa, by simpa [toMatrix_mulVec_repr]⟩ /-- If the determinant of a map vanishes, then the map is not onto. TODO: This should only require `[IsDomain R] [Free R M]`, which we get if we generalize `Mathlib/LinearAlgebra/FiniteDimensional/Basic.lean`, which includes `LinearMap.ker_eq_bot_iff_range_eq_top`. -/ theorem range_lt_top_of_det_eq_zero {𝕜 : Type*} [Field 𝕜] [Module 𝕜 M] {f : M →ₗ[𝕜] M} (hf : f.det = 0) : range f < ⊤ := by have : Module.Finite 𝕜 M := by simp [finite_of_det_ne_one (f := f), hf] rw [lt_top_iff_ne_top, ne_eq, ← ker_eq_bot_iff_range_eq_top, ← ne_eq, ← bot_lt_iff_ne_bot] exact bot_lt_ker_of_det_eq_zero hf /-- When the function is over the base ring, the determinant is the evaluation at `1`. -/ @[simp] lemma det_ring (f : R →ₗ[R] R) : f.det = f 1 := by simp [← det_toMatrix (Basis.singleton Unit R)] lemma det_mulLeft (a : R) : (mulLeft R a).det = a := by simp lemma det_mulRight (a : R) : (mulRight R a).det = a := by simp theorem det_prodMap [Module.Free R M] [Module.Free R M'] [Module.Finite R M] [Module.Finite R M'] (f : Module.End R M) (f' : Module.End R M') : (prodMap f f').det = f.det * f'.det := by let b := Module.Free.chooseBasis R M let b' := Module.Free.chooseBasis R M' rw [← det_toMatrix (b.prod b'), ← det_toMatrix b, ← det_toMatrix b', toMatrix_prodMap, det_fromBlocks_zero₂₁, det_toMatrix] omit [DecidableEq ι] in theorem det_pi [Module.Free R M] [Module.Finite R M] (f : ι → M →ₗ[R] M) : (LinearMap.pi (fun i ↦ (f i).comp (LinearMap.proj i))).det = ∏ i, (f i).det := by classical let b := Module.Free.chooseBasis R M let B := (Pi.basis (fun _ : ι ↦ b)).reindex <| (Equiv.sigmaEquivProd _ _).trans (Equiv.prodComm _ _) simp_rw [← LinearMap.det_toMatrix B, ← LinearMap.det_toMatrix b] have : ((LinearMap.toMatrix B B) (LinearMap.pi fun i ↦ f i ∘ₗ LinearMap.proj i)) = Matrix.blockDiagonal (fun i ↦ LinearMap.toMatrix b b (f i)) := by ext ⟨i₁, i₂⟩ ⟨j₁, j₂⟩ unfold B simp_rw [LinearMap.toMatrix_apply', Matrix.blockDiagonal_apply, Basis.coe_reindex, Function.comp_apply, Basis.repr_reindex_apply, Equiv.symm_trans_apply, Equiv.prodComm_symm, Equiv.prodComm_apply, Equiv.sigmaEquivProd_symm_apply, Prod.swap_prod_mk, Pi.basis_apply, Pi.basis_repr, LinearMap.pi_apply, LinearMap.coe_comp, Function.comp_apply, LinearMap.toMatrix_apply', LinearMap.coe_proj, Function.eval, Pi.single_apply] split_ifs with h · rw [h] · simp only [map_zero, Finsupp.coe_zero, Pi.zero_apply] rw [this, Matrix.det_blockDiagonal] end LinearMap namespace LinearEquiv /-- On a `LinearEquiv`, the domain of `LinearMap.det` can be promoted to `Rˣ`. -/ protected def det : (M ≃ₗ[R] M) →* Rˣ := (Units.map (LinearMap.det : (M →ₗ[R] M) →* R)).comp (LinearMap.GeneralLinearGroup.generalLinearEquiv R M).symm.toMonoidHom @[simp] theorem coe_det (f : M ≃ₗ[R] M) : ↑(LinearEquiv.det f) = LinearMap.det (f : M →ₗ[R] M) := rfl @[simp] theorem coe_inv_det (f : M ≃ₗ[R] M) : ↑(LinearEquiv.det f)⁻¹ = LinearMap.det (f.symm : M →ₗ[R] M) := rfl @[simp] theorem det_refl : LinearEquiv.det (LinearEquiv.refl R M) = 1 := Units.ext <| LinearMap.det_id @[simp] theorem det_trans (f g : M ≃ₗ[R] M) : LinearEquiv.det (f.trans g) = LinearEquiv.det g * LinearEquiv.det f := map_mul _ g f @[simp] theorem det_symm (f : M ≃ₗ[R] M) : LinearEquiv.det f.symm = LinearEquiv.det f⁻¹ := map_inv _ f /-- Conjugating a linear equiv by a linear equiv does not change its determinant. -/ @[simp] theorem det_conj (f : M ≃ₗ[R] M) (e : M ≃ₗ[R] M') : LinearEquiv.det ((e.symm.trans f).trans e) = LinearEquiv.det f := by rw [← Units.val_inj, coe_det, coe_det, ← comp_coe, ← comp_coe, LinearMap.det_conj] attribute [irreducible] LinearEquiv.det end LinearEquiv /-- The determinants of a `LinearEquiv` and its inverse multiply to 1. -/ @[simp] theorem LinearEquiv.det_mul_det_symm {A : Type*} [CommRing A] [Module A M] (f : M ≃ₗ[A] M) : LinearMap.det (f : M →ₗ[A] M) * LinearMap.det (f.symm : M →ₗ[A] M) = 1 := by simp [← LinearMap.det_comp] /-- The determinants of a `LinearEquiv` and its inverse multiply to 1. -/ @[simp] theorem LinearEquiv.det_symm_mul_det {A : Type*} [CommRing A] [Module A M] (f : M ≃ₗ[A] M) : LinearMap.det (f.symm : M →ₗ[A] M) * LinearMap.det (f : M →ₗ[A] M) = 1 := by simp [← LinearMap.det_comp] -- Cannot be stated using `LinearMap.det` because `f` is not an endomorphism. theorem LinearEquiv.isUnit_det (f : M ≃ₗ[R] M') (v : Basis ι R M) (v' : Basis ι R M') : IsUnit (LinearMap.toMatrix v v' f).det := by apply isUnit_det_of_left_inverse simpa using (LinearMap.toMatrix_comp v v' v f.symm f).symm /-- Specialization of `LinearEquiv.isUnit_det` -/ theorem LinearEquiv.isUnit_det' {A : Type*} [CommRing A] [Module A M] (f : M ≃ₗ[A] M) : IsUnit (LinearMap.det (f : M →ₗ[A] M)) := .of_mul_eq_one _ f.det_mul_det_symm -- see https://github.com/leanprover-community/mathlib4/issues/29041 set_option linter.unusedSimpArgs false in /-- The determinant of `f.symm` is the inverse of that of `f` when `f` is a linear equiv. -/ theorem LinearEquiv.det_coe_symm {𝕜 : Type*} [Field 𝕜] [Module 𝕜 M] (f : M ≃ₗ[𝕜] M) : LinearMap.det (f.symm : M →ₗ[𝕜] M) = (LinearMap.det (f : M →ₗ[𝕜] M))⁻¹ := by simp [field, IsUnit.ne_zero f.isUnit_det'] /-- Builds a linear equivalence from a linear map whose determinant in some bases is a unit. -/ @[simps] def LinearEquiv.ofIsUnitDet {f : M →ₗ[R] M'} {v : Basis ι R M} {v' : Basis ι R M'} (h : IsUnit (LinearMap.toMatrix v v' f).det) : M ≃ₗ[R] M' where toFun := f map_add' := f.map_add map_smul' := f.map_smul invFun := toLin v' v (toMatrix v v' f)⁻¹ left_inv x := calc toLin v' v (toMatrix v v' f)⁻¹ (f x) _ = toLin v v ((toMatrix v v' f)⁻¹ * toMatrix v v' f) x := by rw [toLin_mul v v' v, toLin_toMatrix, LinearMap.comp_apply] _ = x := by simp [h] right_inv x := calc f (toLin v' v (toMatrix v v' f)⁻¹ x) _ = toLin v' v' (toMatrix v v' f * (toMatrix v v' f)⁻¹) x := by rw [toLin_mul v' v v', LinearMap.comp_apply, toLin_toMatrix v v'] _ = x := by simp [h] @[simp] theorem LinearEquiv.coe_ofIsUnitDet {f : M →ₗ[R] M'} {v : Basis ι R M} {v' : Basis ι R M'} (h : IsUnit (LinearMap.toMatrix v v' f).det) : (LinearEquiv.ofIsUnitDet h : M →ₗ[R] M') = f := by ext x rfl /-- Builds a linear equivalence from an endomorphism whose determinant is a unit. -/ noncomputable def LinearMap.equivOfIsUnitDet [Module.Free R M] [Module.Finite R M] {f : M →ₗ[R] M} (h : IsUnit f.det) : M ≃ₗ[R] M := by by_cases hR : Nontrivial R · let ⟨ι, b⟩ := (Module.Free.exists_basis R M).some have : Finite ι := Module.Finite.finite_basis b have : Fintype ι := Fintype.ofFinite ι have : DecidableEq ι := Classical.typeDecidableEq ι exact LinearEquiv.ofIsUnitDet (by rwa [det_toMatrix b]) · exact 1 @[simp] theorem LinearMap.equivOfIsUnitDet_apply [Module.Free R M] [Module.Finite R M] {f : M →ₗ[R] M} (h : IsUnit f.det) (x : M) : (LinearMap.equivOfIsUnitDet h) x = f x := by nontriviality M simp [equivOfIsUnitDet, dif_pos (Module.nontrivial R M)] @[simp] theorem LinearMap.coe_equivOfIsUnitDet [Module.Free R M] [Module.Finite R M] {f : M →ₗ[R] M} (h : IsUnit f.det) : (LinearMap.equivOfIsUnitDet h : M →ₗ[R] M) = f := by ext apply LinearMap.equivOfIsUnitDet_apply /-- Builds a linear equivalence from a linear map on a finite-dimensional vector space whose determinant is nonzero. -/ abbrev LinearMap.equivOfDetNeZero {𝕜 : Type*} [Field 𝕜] {M : Type*} [AddCommGroup M] [Module 𝕜 M] [FiniteDimensional 𝕜 M] (f : M →ₗ[𝕜] M) (hf : LinearMap.det f ≠ 0) : M ≃ₗ[𝕜] M := have : IsUnit (LinearMap.toMatrix (Module.finBasis 𝕜 M) (Module.finBasis 𝕜 M) f).det := by rw [LinearMap.det_toMatrix] exact isUnit_iff_ne_zero.2 hf LinearEquiv.ofIsUnitDet this theorem LinearMap.associated_det_of_eq_comp (e : M ≃ₗ[R] M) (f f' : M →ₗ[R] M) (h : ∀ x, f x = f' (e x)) : Associated (LinearMap.det f) (LinearMap.det f') := by suffices Associated (LinearMap.det (f' ∘ₗ ↑e)) (LinearMap.det f') by convert this using 2 ext x exact h x rw [← mul_one (LinearMap.det f'), LinearMap.det_comp] exact Associated.mul_left _ (associated_one_iff_isUnit.mpr e.isUnit_det') theorem LinearMap.associated_det_comp_equiv {N : Type*} [AddCommGroup N] [Module R N] (f : N →ₗ[R] M) (e e' : M ≃ₗ[R] N) : Associated (LinearMap.det (f ∘ₗ ↑e)) (LinearMap.det (f ∘ₗ ↑e')) := by refine LinearMap.associated_det_of_eq_comp (e.trans e'.symm) _ _ ?_ intro x simp only [LinearMap.comp_apply, LinearEquiv.coe_coe, LinearEquiv.trans_apply, LinearEquiv.apply_symm_apply] namespace Module.Basis /-- The determinant of a family of vectors with respect to some basis, as an alternating multilinear map. -/ nonrec def det : M [⋀^ι]→ₗ[R] R where toMultilinearMap := MultilinearMap.mk' (fun v ↦ det (e.toMatrix v)) (fun v i x y ↦ by simp only [e.toMatrix_update, map_add, Finsupp.coe_add, det_updateCol_add]) (fun u i c x ↦ by simp only [e.toMatrix_update, Algebra.id.smul_eq_mul, LinearEquiv.map_smul] apply det_updateCol_smul) map_eq_zero_of_eq' := by intro v i j h hij dsimp rw [← Function.update_eq_self i v, h, ← det_transpose, e.toMatrix_update, ← updateRow_transpose, ← e.toMatrix_transpose_apply] apply det_zero_of_row_eq hij rw [updateRow_ne hij.symm, updateRow_self] theorem det_apply (v : ι → M) : e.det v = Matrix.det (e.toMatrix v) := rfl theorem det_self : e.det e = 1 := by simp [e.det_apply] @[simp] theorem det_isEmpty [IsEmpty ι] : e.det = AlternatingMap.constOfIsEmpty R M ι 1 := by ext v exact Matrix.det_isEmpty /-- `Basis.det` is not the zero map. -/ theorem det_ne_zero [Nontrivial R] : e.det ≠ 0 := fun h => by simpa [h] using e.det_self theorem smul_det {G} [Group G] [DistribMulAction G M] [SMulCommClass G R M] (g : G) (v : ι → M) : (g • e).det v = e.det (g⁻¹ • v) := by simp_rw [det_apply, toMatrix_smul_left] theorem is_basis_iff_det {v : ι → M} : LinearIndependent R v ∧ span R (Set.range v) = ⊤ ↔ IsUnit (e.det v) := by constructor · rintro ⟨hli, hspan⟩ set v' := Basis.mk hli hspan.ge rw [e.det_apply] convert LinearEquiv.isUnit_det (LinearEquiv.refl R M) v' e using 2 ext i j simp [v'] · intro h rw [Basis.det_apply, Basis.toMatrix_eq_toMatrix_constr] at h set v' := Basis.map e (LinearEquiv.ofIsUnitDet h) with v'_def have : ⇑v' = v := by ext i rw [v'_def, Basis.map_apply, LinearEquiv.ofIsUnitDet_apply, e.constr_basis] rw [← this] exact ⟨v'.linearIndependent, v'.span_eq⟩ theorem isUnit_det (e' : Basis ι R M) : IsUnit (e.det e') := (is_basis_iff_det e).mp ⟨e'.linearIndependent, e'.span_eq⟩ end Module.Basis /-- Any alternating map to `R` where `ι` has the cardinality of a basis equals the determinant map with respect to that basis, multiplied by the value of that alternating map on that basis. -/ theorem AlternatingMap.eq_smul_basis_det (f : M [⋀^ι]→ₗ[R] R) : f = f e • e.det := by refine Basis.ext_alternating e fun i h => ?_ let σ : Equiv.Perm ι := Equiv.ofBijective i (Finite.injective_iff_bijective.1 h) change f (e ∘ σ) = (f e • e.det) (e ∘ σ) simp [AlternatingMap.map_perm, Basis.det_self] @[simp] theorem AlternatingMap.map_basis_eq_zero_iff {ι : Type*} [Finite ι] (e : Basis ι R M) (f : M [⋀^ι]→ₗ[R] R) : f e = 0 ↔ f = 0 := ⟨fun h => by cases nonempty_fintype ι letI := Classical.decEq ι simpa [h] using f.eq_smul_basis_det e, fun h => h.symm ▸ AlternatingMap.zero_apply _⟩ theorem AlternatingMap.map_basis_ne_zero_iff {ι : Type*} [Finite ι] (e : Basis ι R M) (f : M [⋀^ι]→ₗ[R] R) : f e ≠ 0 ↔ f ≠ 0 := not_congr <| f.map_basis_eq_zero_iff e variable {A : Type*} [CommRing A] [Module A M] namespace Module.Basis @[simp] theorem det_comp (e : Basis ι A M) (f : M →ₗ[A] M) (v : ι → M) : e.det (f ∘ v) = (LinearMap.det f) * e.det v := by rw [det_apply, det_apply, ← f.det_toMatrix e, ← Matrix.det_mul, e.toMatrix_eq_toMatrix_constr (f ∘ v), e.toMatrix_eq_toMatrix_constr v, ← toMatrix_comp, e.constr_comp] @[simp] theorem det_comp_basis [Module A M'] (b : Basis ι A M) (b' : Basis ι A M') (f : M →ₗ[A] M') : b'.det (f ∘ b) = LinearMap.det (f ∘ₗ (b'.equiv b (Equiv.refl ι) : M' →ₗ[A] M)) := by rw [det_apply, ← LinearMap.det_toMatrix b', LinearMap.toMatrix_comp _ b, Matrix.det_mul, LinearMap.toMatrix_basis_equiv, Matrix.det_one, mul_one] congr 1; ext i j rw [toMatrix_apply, LinearMap.toMatrix_apply, Function.comp_apply] @[simp] theorem det_basis (b : Basis ι A M) (b' : Basis ι A M) : LinearMap.det (b'.equiv b (Equiv.refl ι)).toLinearMap = b'.det b := (b.det_comp_basis b' (LinearMap.id)).symm theorem det_mul_det (b b' b'' : Basis ι A M) : b.det b' * b'.det b'' = b.det b'' := by have : b'' = (b'.equiv b'' (Equiv.refl ι)).toLinearMap ∘ b' := by ext; simp conv_rhs => rw [this, Basis.det_comp, det_basis, mul_comm] theorem det_inv (b : Basis ι A M) (b' : Basis ι A M) : (b.isUnit_det b').unit⁻¹ = b'.det b := by rw [← Units.mul_eq_one_iff_inv_eq, IsUnit.unit_spec, ← det_basis, ← det_basis] exact LinearEquiv.det_mul_det_symm _ theorem det_reindex {ι' : Type*} [Fintype ι'] [DecidableEq ι'] (b : Basis ι R M) (v : ι' → M) (e : ι ≃ ι') : (b.reindex e).det v = b.det (v ∘ e) := by rw [det_apply, toMatrix_reindex', det_reindexAlgEquiv, det_apply] theorem det_reindex' {ι' : Type*} [Fintype ι'] [DecidableEq ι'] (b : Basis ι R M) (e : ι ≃ ι') : (b.reindex e).det = b.det.domDomCongr e := AlternatingMap.ext fun _ => det_reindex _ _ _ theorem det_reindex_symm {ι' : Type*} [Fintype ι'] [DecidableEq ι'] (b : Basis ι R M) (v : ι → M) (e : ι' ≃ ι) : (b.reindex e.symm).det (v ∘ e) = b.det v := by rw [det_reindex, Function.comp_assoc, e.self_comp_symm, Function.comp_id] @[simp] theorem det_map (b : Basis ι R M) (f : M ≃ₗ[R] M') (v : ι → M') : (b.map f).det v = b.det (f.symm ∘ v) := by rw [det_apply, toMatrix_map, det_apply] theorem det_map' (b : Basis ι R M) (f : M ≃ₗ[R] M') : (b.map f).det = b.det.compLinearMap f.symm := AlternatingMap.ext <| b.det_map f end Module.Basis @[simp] theorem Pi.basisFun_det : (Pi.basisFun R ι).det = Matrix.detRowAlternating := by ext M rw [Basis.det_apply, Basis.coePiBasisFun.toMatrix_eq_transpose, det_transpose] theorem Pi.basisFun_det_apply (v : ι → ι → R) : (Pi.basisFun R ι).det v = (Matrix.of v).det := by rw [Pi.basisFun_det] rfl namespace Module.Basis /-- If we fix a background basis `e`, then for any other basis `v`, we can characterise the coordinates provided by `v` in terms of determinants relative to `e`. -/ theorem det_smul_mk_coord_eq_det_update {v : ι → M} (hli : LinearIndependent R v) (hsp : ⊤ ≤ span R (range v)) (i : ι) : e.det v • (Basis.mk hli hsp).coord i = e.det.toMultilinearMap.toLinearMap v i := by apply (Basis.mk hli hsp).ext intro k rcases eq_or_ne k i with (rfl | hik) <;> simp only [Algebra.id.smul_eq_mul, coe_mk, LinearMap.smul_apply, MultilinearMap.toLinearMap_apply] · rw [mk_coord_apply_eq, mul_one, update_eq_self] congr · rw [mk_coord_apply_ne hik, mul_zero, eq_comm] exact e.det.map_eq_zero_of_eq _ (by simp [hik]) hik /-- If a basis is multiplied columnwise by scalars `w : ι → Rˣ`, then the determinant with respect to this basis is multiplied by the product of the inverse of these scalars. -/ theorem det_unitsSMul (e : Basis ι R M) (w : ι → Rˣ) : (e.unitsSMul w).det = (↑(∏ i, w i)⁻¹ : R) • e.det := by ext f change (Matrix.det fun i j => (e.unitsSMul w).repr (f j) i) = (↑(∏ i, w i)⁻¹ : R) • Matrix.det fun i j => e.repr (f j) i simp only [e.repr_unitsSMul] convert Matrix.det_mul_column (fun i => (↑(w i)⁻¹ : R)) fun i j => e.repr (f j) i simp [← Finset.prod_inv_distrib] /-- The determinant of a basis constructed by `unitsSMul` is the product of the given units. -/ @[simp] theorem det_unitsSMul_self (w : ι → Rˣ) : e.det (e.unitsSMul w) = ∏ i, (w i : R) := by simp [det_apply] /-- The determinant of a basis constructed by `isUnitSMul` is the product of the given units. -/ @[simp] theorem det_isUnitSMul {w : ι → R} (hw : ∀ i, IsUnit (w i)) : e.det (e.isUnitSMul hw) = ∏ i, w i := e.det_unitsSMul_self _ end Module.Basis section Dual /-- The determinant of the transpose of an endomorphism coincides with its determinant. -/ theorem _root_.LinearMap.det_dualMap [Module.Free R M] [Module.Finite R M] (f : M →ₗ[R] M) : f.dualMap.det = f.det := by set b := Module.Free.chooseBasis R M have : Fintype (Module.Free.ChooseBasisIndex R M) := Module.Free.ChooseBasisIndex.fintype R M rw [← LinearMap.det_toMatrix b, ← LinearMap.det_toMatrix b.dualBasis] simp [LinearMap.dualMap_def, LinearMap.toMatrix_transpose] end Dual
.lake/packages/mathlib/Mathlib/LinearAlgebra/Semisimple.lean
import Mathlib.Algebra.Module.Torsion.Basic import Mathlib.FieldTheory.Perfect import Mathlib.LinearAlgebra.AnnihilatingPolynomial import Mathlib.RingTheory.Artinian.Instances import Mathlib.RingTheory.Ideal.Quotient.Nilpotent import Mathlib.RingTheory.SimpleModule.Basic /-! # Semisimple linear endomorphisms Given an `R`-module `M` together with an `R`-linear endomorphism `f : M → M`, the following two conditions are equivalent: 1. Every `f`-invariant submodule of `M` has an `f`-invariant complement. 2. `M` is a semisimple `R[X]`-module, where the action of the polynomial ring is induced by `f`. A linear endomorphism `f` satisfying these equivalent conditions is known as a *semisimple* endomorphism. We provide basic definitions and results about such endomorphisms in this file. ## Main definitions / results: * `Module.End.IsSemisimple`: the definition that a linear endomorphism is semisimple * `Module.End.isSemisimple_iff`: the characterisation of semisimplicity in terms of invariant submodules. * `Module.End.eq_zero_of_isNilpotent_isSemisimple`: the zero endomorphism is the only endomorphism that is both nilpotent and semisimple. * `Module.End.isSemisimple_of_squarefree_aeval_eq_zero`: an endomorphism that is a root of a square-free polynomial is semisimple (in finite dimensions over a field). * `Module.End.IsSemisimple.minpoly_squarefree`: the minimal polynomial of a semisimple endomorphism is squarefree. * `IsSemisimple.of_mem_adjoin_pair`: every endomorphism in the subalgebra generated by two commuting semisimple endomorphisms is semisimple, if the base field is perfect. ## TODO In finite dimensions over a field: * Triangularizable iff diagonalisable for semisimple endomorphisms -/ open Set Function Polynomial variable {R M : Type*} [CommRing R] [AddCommGroup M] [Module R M] namespace Module.End section CommRing variable (f : End R M) /-- A linear endomorphism of an `R`-module `M` is called *semisimple* if the induced `R[X]`-module structure on `M` is semisimple. This is equivalent to saying that every `f`-invariant `R`-submodule of `M` has an `f`-invariant complement: see `Module.End.isSemisimple_iff`. -/ def IsSemisimple := IsSemisimpleModule R[X] (AEval' f) /-- A weaker version of semisimplicity that only prescribes behaviour on finitely-generated submodules. -/ def IsFinitelySemisimple : Prop := ∀ p (hp : p ∈ invtSubmodule f), Module.Finite R p → IsSemisimple (LinearMap.restrict f hp) variable {f} /-- A linear endomorphism is semisimple if every invariant submodule has in invariant complement. See also `Module.End.isSemisimple_iff`. -/ lemma isSemisimple_iff' : f.IsSemisimple ↔ ∀ p : invtSubmodule f, ∃ q : invtSubmodule f, IsCompl p q := by rw [IsSemisimple, isSemisimpleModule_iff, (AEval.mapSubmodule R M f).symm.complementedLattice_iff, complementedLattice_iff] rfl lemma isSemisimple_iff : f.IsSemisimple ↔ ∀ p ∈ invtSubmodule f, ∃ q ∈ invtSubmodule f, IsCompl p q := by simp [isSemisimple_iff'] lemma isSemisimple_restrict_iff (p) (hp : p ∈ invtSubmodule f) : IsSemisimple (LinearMap.restrict f hp) ↔ ∀ q ∈ f.invtSubmodule, q ≤ p → ∃ r ≤ p, r ∈ f.invtSubmodule ∧ Disjoint q r ∧ q ⊔ r = p := by let e : Submodule R[X] (AEval' (f.restrict hp)) ≃o Iic (AEval.mapSubmodule R M f ⟨p, hp⟩) := (Submodule.orderIsoMapComap <| AEval.restrict_equiv_mapSubmodule f p hp).trans (Submodule.mapIic _) simp_rw [IsSemisimple, isSemisimpleModule_iff, e.complementedLattice_iff, disjoint_iff, ← (OrderIso.Iic _ _).complementedLattice_iff, Iic.complementedLattice_iff, Subtype.forall, Subtype.exists, Subtype.mk_le_mk, Sublattice.mk_inf_mk, Sublattice.mk_sup_mk, Subtype.mk.injEq, exists_and_left, exists_and_right, invtSubmodule.mk_eq_bot_iff, exists_prop, and_assoc] rfl /-- A linear endomorphism is finitely semisimple if it is semisimple on every finitely-generated invariant submodule. See also `Module.End.isFinitelySemisimple_iff`. -/ lemma isFinitelySemisimple_iff' : f.IsFinitelySemisimple ↔ ∀ p (hp : p ∈ invtSubmodule f), Module.Finite R p → IsSemisimple (LinearMap.restrict f hp) := Iff.rfl /-- A characterisation of `Module.End.IsFinitelySemisimple` using only the lattice of submodules of `M` (thus avoiding submodules of submodules). -/ lemma isFinitelySemisimple_iff : f.IsFinitelySemisimple ↔ ∀ p ∈ invtSubmodule f, Module.Finite R p → ∀ q ∈ invtSubmodule f, q ≤ p → ∃ r, r ≤ p ∧ r ∈ invtSubmodule f ∧ Disjoint q r ∧ q ⊔ r = p := by simp_rw [isFinitelySemisimple_iff', isSemisimple_restrict_iff] @[simp] lemma isSemisimple_zero [IsSemisimpleModule R M] : IsSemisimple (0 : Module.End R M) := by simpa [isSemisimple_iff] using exists_isCompl @[simp] lemma isSemisimple_id [IsSemisimpleModule R M] : IsSemisimple (LinearMap.id : Module.End R M) := by simpa [isSemisimple_iff] using exists_isCompl @[simp] lemma isSemisimple_neg : (-f).IsSemisimple ↔ f.IsSemisimple := by simp [isSemisimple_iff, mem_invtSubmodule] variable (f) in protected lemma _root_.LinearEquiv.isSemisimple_iff {M₂ : Type*} [AddCommGroup M₂] [Module R M₂] (g : End R M₂) (e : M ≃ₗ[R] M₂) (he : e ∘ₗ f = g ∘ₗ e) : f.IsSemisimple ↔ g.IsSemisimple := by let e : AEval' f ≃ₗ[R[X]] AEval' g := LinearEquiv.ofAEval _ (e.trans (AEval'.of g)) fun x ↦ by simpa [AEval'.X_smul_of] using LinearMap.congr_fun he x simp_rw [IsSemisimple, isSemisimpleModule_iff, (Submodule.orderIsoMapComap e).complementedLattice_iff] lemma eq_zero_of_isNilpotent_isSemisimple (hn : IsNilpotent f) (hs : f.IsSemisimple) : f = 0 := by have ⟨n, h0⟩ := hn rw [← aeval_X (R := R) f]; rw [← aeval_X_pow (R := R) f] at h0 rw [← RingHom.mem_ker, ← AEval.annihilator_eq_ker_aeval (M := M)] at h0 ⊢ exact hs.annihilator_isRadical _ _ ⟨n, h0⟩ lemma eq_zero_of_isNilpotent_of_isFinitelySemisimple (hn : IsNilpotent f) (hs : IsFinitelySemisimple f) : f = 0 := by have (p) (hp₁ : p ∈ f.invtSubmodule) (hp₂ : Module.Finite R p) : f.restrict hp₁ = 0 := by specialize hs p hp₁ hp₂ replace hn : IsNilpotent (f.restrict hp₁) := isNilpotent.restrict hp₁ hn exact eq_zero_of_isNilpotent_isSemisimple hn hs ext x obtain ⟨k : ℕ, hk : f ^ k = 0⟩ := hn let p := Submodule.span R {(f ^ i) x | (i : ℕ) (_ : i ≤ k)} have hp₁ : p ∈ f.invtSubmodule := by simp only [mem_invtSubmodule, p, Submodule.span_le] rintro - ⟨i, hi, rfl⟩ apply Submodule.subset_span rcases lt_or_eq_of_le hi with hik | rfl · exact ⟨i + 1, hik, by simpa [Module.End.pow_apply] using iterate_succ_apply' f i x⟩ · exact ⟨i, by simp [hk]⟩ have hp₂ : Module.Finite R p := by let g : ℕ → M := fun i ↦ (f ^ i) x have hg : {(f ^ i) x | (i : ℕ) (_ : i ≤ k)} = g '' Iic k := by ext; simp [g] exact Module.Finite.span_of_finite _ <| hg ▸ toFinite (g '' Iic k) simpa [LinearMap.restrict_apply, Subtype.ext_iff] using LinearMap.congr_fun (this p hp₁ hp₂) ⟨x, Submodule.subset_span ⟨0, k.zero_le, rfl⟩⟩ @[simp] lemma isSemisimple_sub_algebraMap_iff {μ : R} : (f - algebraMap R (End R M) μ).IsSemisimple ↔ f.IsSemisimple := by suffices ∀ p : Submodule R M, p ≤ p.comap (f - algebraMap R (Module.End R M) μ) ↔ p ≤ p.comap f by simp [mem_invtSubmodule, isSemisimple_iff, this] refine fun p ↦ ⟨fun h x hx ↦ ?_, fun h x hx ↦ p.sub_mem (h hx) (p.smul_mem μ hx)⟩ simpa using p.add_mem (h hx) (p.smul_mem μ hx) lemma IsSemisimple.restrict {p : Submodule R M} (hp : p ∈ f.invtSubmodule) (hf : f.IsSemisimple) : IsSemisimple (f.restrict hp) := by rw [IsSemisimple] at hf ⊢ let e : Submodule R[X] (AEval' (LinearMap.restrict f hp)) ≃o Iic (AEval.mapSubmodule R M f ⟨p, hp⟩) := (Submodule.orderIsoMapComap <| AEval.restrict_equiv_mapSubmodule f p hp).trans <| Submodule.mapIic _ exact (isSemisimpleModule_iff ..).mpr (e.complementedLattice_iff.mpr inferInstance) lemma IsSemisimple.isFinitelySemisimple (hf : f.IsSemisimple) : f.IsFinitelySemisimple := isFinitelySemisimple_iff'.mp fun _ _ _ ↦ hf.restrict _ @[simp] lemma isFinitelySemisimple_iff_isSemisimple [Module.Finite R M] : f.IsFinitelySemisimple ↔ f.IsSemisimple := by refine ⟨fun hf ↦ isSemisimple_iff.mpr fun p hp ↦ ?_, IsSemisimple.isFinitelySemisimple⟩ obtain ⟨q, -, hq₁, hq₂, hq₃⟩ := isFinitelySemisimple_iff.mp hf ⊤ (invtSubmodule.top_mem f) inferInstance p hp le_top exact ⟨q, hq₁, hq₂, codisjoint_iff.mpr hq₃⟩ @[simp] lemma isFinitelySemisimple_sub_algebraMap_iff {μ : R} : (f - algebraMap R (End R M) μ).IsFinitelySemisimple ↔ f.IsFinitelySemisimple := by suffices ∀ p : Submodule R M, p ≤ p.comap (f - algebraMap R (Module.End R M) μ) ↔ p ≤ p.comap f by simp_rw [isFinitelySemisimple_iff, mem_invtSubmodule, this] refine fun p ↦ ⟨fun h x hx ↦ ?_, fun h x hx ↦ p.sub_mem (h hx) (p.smul_mem μ hx)⟩ simpa using p.add_mem (h hx) (p.smul_mem μ hx) lemma IsFinitelySemisimple.restrict {p : Submodule R M} (hp : p ∈ f.invtSubmodule) (hf : f.IsFinitelySemisimple) : IsFinitelySemisimple (f.restrict hp) := by intro q hq₁ hq₂ have := invtSubmodule.map_subtype_mem_of_mem_invtSubmodule f hp hq₁ let e : q ≃ₗ[R] q.map p.subtype := p.equivSubtypeMap q rw [e.isSemisimple_iff ((LinearMap.restrict f hp).restrict hq₁) (LinearMap.restrict f this) rfl] exact hf _ this (Finite.map q p.subtype) end CommRing section field variable {K : Type*} [Field K] [Module K M] {f g : End K M} lemma IsSemisimple_smul_iff {t : K} (ht : t ≠ 0) : (t • f).IsSemisimple ↔ f.IsSemisimple := by simp [isSemisimple_iff, mem_invtSubmodule, Submodule.comap_smul f (h := ht)] lemma IsSemisimple_smul (t : K) (h : f.IsSemisimple) : (t • f).IsSemisimple := by wlog ht : t ≠ 0; · simp [not_not.mp ht] rwa [IsSemisimple_smul_iff ht] theorem isSemisimple_of_squarefree_aeval_eq_zero {p : K[X]} (hp : Squarefree p) (hpf : aeval f p = 0) : f.IsSemisimple := by rw [← RingHom.mem_ker, ← AEval.annihilator_eq_ker_aeval (M := M), mem_annihilator, ← IsTorsionBy, ← isTorsionBySet_singleton_iff, isTorsionBySet_iff_is_torsion_by_span] at hpf let R := K[X] ⧸ Ideal.span {p} have : IsReduced R := (Ideal.isRadical_iff_quotient_reduced _).mp (isRadical_iff_span_singleton.mp hp.isRadical) have : FiniteDimensional K R := (AdjoinRoot.powerBasis hp.ne_zero).finite have : IsArtinianRing R := .of_finite K R have : IsSemisimpleRing R := IsArtinianRing.isSemisimpleRing_of_isReduced R letI : Module R (AEval' f) := Module.IsTorsionBySet.module hpf let e : AEval' f →ₛₗ[Ideal.Quotient.mk (Ideal.span {p})] AEval' f := { AddMonoidHom.id _ with map_smul' := fun _ _ ↦ rfl } exact (e.isSemisimpleModule_iff_of_bijective bijective_id).mpr inferInstance variable [FiniteDimensional K M] section variable (hf : f.IsSemisimple) include hf /-- The minimal polynomial of a semisimple endomorphism is square free -/ theorem IsSemisimple.minpoly_squarefree : Squarefree (minpoly K f) := IsRadical.squarefree (minpoly.ne_zero <| Algebra.IsIntegral.isIntegral _) <| by rw [isRadical_iff_span_singleton, span_minpoly_eq_annihilator]; exact hf.annihilator_isRadical protected theorem IsSemisimple.aeval (p : K[X]) : (aeval f p).IsSemisimple := let R := K[X] ⧸ Ideal.span {minpoly K f} have : Module.Finite K R := (AdjoinRoot.powerBasis' <| minpoly.monic <| Algebra.IsIntegral.isIntegral f).finite have : IsReduced R := (Ideal.isRadical_iff_quotient_reduced _).mp <| span_minpoly_eq_annihilator K f ▸ hf.annihilator_isRadical isSemisimple_of_squarefree_aeval_eq_zero ((minpoly.isRadical K _).squarefree <| minpoly.ne_zero <| .of_finite K <| Ideal.Quotient.mkₐ K (.span {minpoly K f}) p) <| by rw [← Ideal.Quotient.liftₐ_comp (.span {minpoly K f}) (aeval f) fun a h ↦ by rwa [Ideal.span, ← minpoly.ker_aeval_eq_span_minpoly] at h, aeval_algHom, AlgHom.comp_apply, AlgHom.comp_apply, ← aeval_algHom_apply, minpoly.aeval, map_zero] theorem IsSemisimple.of_mem_adjoin_singleton {a : End K M} (ha : a ∈ Algebra.adjoin K {f}) : a.IsSemisimple := by rw [Algebra.adjoin_singleton_eq_range_aeval] at ha; obtain ⟨p, rfl⟩ := ha; exact .aeval hf _ protected theorem IsSemisimple.pow (n : ℕ) : (f ^ n).IsSemisimple := .of_mem_adjoin_singleton hf (pow_mem (Algebra.self_mem_adjoin_singleton _ _) _) end section PerfectField variable [PerfectField K] (comm : Commute f g) (hf : f.IsSemisimple) (hg : g.IsSemisimple) include comm hf hg attribute [local simp] Submodule.Quotient.quot_mk_eq_mk in theorem IsSemisimple.of_mem_adjoin_pair {a : End K M} (ha : a ∈ Algebra.adjoin K {f, g}) : a.IsSemisimple := by let R := K[X] ⧸ Ideal.span {minpoly K f} let S := AdjoinRoot ((minpoly K g).map <| algebraMap K R) have : Module.Finite K R := (AdjoinRoot.powerBasis' <| minpoly.monic <| Algebra.IsIntegral.isIntegral f).finite have : Module.Finite R S := (AdjoinRoot.powerBasis' <| (minpoly.monic <| Algebra.IsIntegral.isIntegral g).map _).finite have : Module.Finite K S := .trans R S have : IsArtinianRing R := .of_finite K R have : IsReduced R := (Ideal.isRadical_iff_quotient_reduced _).mp <| span_minpoly_eq_annihilator K f ▸ hf.annihilator_isRadical have : IsReduced S := by simp_rw [S, AdjoinRoot, ← Ideal.isRadical_iff_quotient_reduced, ← isRadical_iff_span_singleton] exact (PerfectField.separable_iff_squarefree.mpr hg.minpoly_squarefree).map.squarefree.isRadical let φ : S →ₐ[K] End K M := Ideal.Quotient.liftₐ _ (eval₂AlgHom' (Ideal.Quotient.liftₐ _ (aeval f) fun a ↦ ?_) g ?_) ((Ideal.span_singleton_le_iff_mem _).mpr ?_ : _ ≤ RingHom.ker _) rotate_left 1 · rw [Ideal.span, ← minpoly.ker_aeval_eq_span_minpoly]; exact id · rintro ⟨p⟩; exact p.induction_on (fun k ↦ by simp [R, Algebra.commute_algebraMap_left]) (fun p q hp hq ↦ by simpa [R] using hp.add_left hq) fun n k ↦ by simpa [R, pow_succ, ← mul_assoc _ _ X] using (·.mul_left comm) · simpa only [RingHom.mem_ker, eval₂AlgHom'_apply, eval₂_map, AlgHom.comp_algebraMap_of_tower] using minpoly.aeval K g have : Algebra.adjoin K {f, g} ≤ φ.range := Algebra.adjoin_le fun x ↦ by rintro (hx | hx) <;> rw [hx] · exact ⟨AdjoinRoot.of _ (AdjoinRoot.root _), (eval₂_C _ _).trans (aeval_X f)⟩ · exact ⟨AdjoinRoot.root _, eval₂_X _ _⟩ obtain ⟨p, rfl⟩ := (AlgHom.mem_range _).mp (this ha) refine isSemisimple_of_squarefree_aeval_eq_zero ((minpoly.isRadical K p).squarefree <| minpoly.ne_zero <| .of_finite K p) ?_ rw [aeval_algHom, φ.comp_apply, minpoly.aeval, map_zero] theorem IsSemisimple.add_of_commute : (f + g).IsSemisimple := .of_mem_adjoin_pair comm hf hg <| add_mem (Algebra.subset_adjoin <| .inl rfl) (Algebra.subset_adjoin <| .inr rfl) theorem IsSemisimple.sub_of_commute : (f - g).IsSemisimple := .of_mem_adjoin_pair comm hf hg <| sub_mem (Algebra.subset_adjoin <| .inl rfl) (Algebra.subset_adjoin <| .inr rfl) theorem IsSemisimple.mul_of_commute : (f * g).IsSemisimple := .of_mem_adjoin_pair comm hf hg <| mul_mem (Algebra.subset_adjoin <| .inl rfl) (Algebra.subset_adjoin <| .inr rfl) end PerfectField end field end Module.End
.lake/packages/mathlib/Mathlib/LinearAlgebra/DFinsupp.lean
import Mathlib.Data.DFinsupp.Submonoid import Mathlib.Data.DFinsupp.Sigma import Mathlib.Data.Finsupp.ToDFinsupp import Mathlib.LinearAlgebra.Finsupp.SumProd import Mathlib.LinearAlgebra.LinearIndependent.Lemmas /-! # Properties of the module `Π₀ i, M i` Given an indexed collection of `R`-modules `M i`, the `R`-module structure on `Π₀ i, M i` is defined in `Mathlib/Data/DFinsupp/Module.lean`. In this file we define `LinearMap` versions of various maps: * `DFinsupp.lsingle a : M →ₗ[R] Π₀ i, M i`: `DFinsupp.single a` as a linear map; * `DFinsupp.lmk s : (Π i : (↑s : Set ι), M i) →ₗ[R] Π₀ i, M i`: `DFinsupp.mk` as a linear map; * `DFinsupp.lapply i : (Π₀ i, M i) →ₗ[R] M`: the map `fun f ↦ f i` as a linear map; * `DFinsupp.lsum`: `DFinsupp.sum` or `DFinsupp.liftAddHom` as a `LinearMap`. ## Implementation notes This file should try to mirror `LinearAlgebra.Finsupp` where possible. The API of `Finsupp` is much more developed, but many lemmas in that file should be eligible to copy over. ## Tags function with finite support, module, linear algebra -/ variable {ι ι' : Type*} {R : Type*} {S : Type*} {M : ι → Type*} {N : Type*} namespace DFinsupp variable [Semiring R] [∀ i, AddCommMonoid (M i)] [∀ i, Module R (M i)] variable [AddCommMonoid N] [Module R N] section DecidableEq variable [DecidableEq ι] /-- `DFinsupp.mk` as a `LinearMap`. -/ def lmk (s : Finset ι) : (∀ i : (↑s : Set ι), M i) →ₗ[R] Π₀ i, M i where toFun := mk s map_add' _ _ := mk_add map_smul' c x := mk_smul c x /-- `DFinsupp.single` as a `LinearMap` -/ def lsingle (i) : M i →ₗ[R] Π₀ i, M i := { DFinsupp.singleAddHom _ _ with toFun := single i map_smul' := single_smul } /-- Two `R`-linear maps from `Π₀ i, M i` which agree on each `single i x` agree everywhere. -/ theorem lhom_ext ⦃φ ψ : (Π₀ i, M i) →ₗ[R] N⦄ (h : ∀ i x, φ (single i x) = ψ (single i x)) : φ = ψ := LinearMap.toAddMonoidHom_injective <| addHom_ext h /-- Two `R`-linear maps from `Π₀ i, M i` which agree on each `single i x` agree everywhere. See note [partially-applied ext lemmas]. After applying this lemma, if `M = R` then it suffices to verify `φ (single a 1) = ψ (single a 1)`. -/ @[ext 1100] theorem lhom_ext' ⦃φ ψ : (Π₀ i, M i) →ₗ[R] N⦄ (h : ∀ i, φ.comp (lsingle i) = ψ.comp (lsingle i)) : φ = ψ := lhom_ext fun i => LinearMap.congr_fun (h i) theorem lmk_apply (s : Finset ι) (x) : (lmk s : _ →ₗ[R] Π₀ i, M i) x = mk s x := rfl @[simp] theorem lsingle_apply (i : ι) (x : M i) : (lsingle i : (M i) →ₗ[R] _) x = single i x := rfl end DecidableEq /-- Interpret `fun (f : Π₀ i, M i) ↦ f i` as a linear map. -/ def lapply (i : ι) : (Π₀ i, M i) →ₗ[R] M i where toFun f := f i map_add' f g := add_apply f g i map_smul' c f := smul_apply c f i @[simp] theorem lapply_apply (i : ι) (f : Π₀ i, M i) : (lapply i : (Π₀ i, M i) →ₗ[R] _) f = f i := rfl theorem injective_pi_lapply : Function.Injective (LinearMap.pi (R := R) <| lapply (M := M)) := fun _ _ h ↦ ext fun _ ↦ congr_fun h _ @[simp] theorem lapply_comp_lsingle_same [DecidableEq ι] (i : ι) : lapply i ∘ₗ lsingle i = (.id : M i →ₗ[R] M i) := by ext; simp @[simp] theorem lapply_comp_lsingle_of_ne [DecidableEq ι] (i i' : ι) (h : i ≠ i') : lapply i ∘ₗ lsingle i' = (0 : M i' →ₗ[R] M i) := by ext; simp [h.symm] section Lsum variable (S) variable [DecidableEq ι] instance {R : Type*} {S : Type*} [Semiring R] [Semiring S] (σ : R →+* S) {σ' : S →+* R} [RingHomInvPair σ σ'] [RingHomInvPair σ' σ] (M : Type*) (M₂ : Type*) [AddCommMonoid M] [AddCommMonoid M₂] [Module R M] [Module S M₂] : EquivLike (LinearEquiv σ M M₂) M M₂ := inferInstance /-- `DFinsupp.equivCongrLeft` as a linear equivalence. This is the `DFinsupp` version of `Finsupp.domLCongr`. -/ @[simps! apply] def domLCongr (e : ι ≃ ι') : (Π₀ i, M i) ≃ₗ[R] (Π₀ i, M (e.symm i)) where __ := DFinsupp.equivCongrLeft e map_add' _ _ := by ext; rfl map_smul' _ _ := by ext; rfl /-- `DFinsupp.sigmaCurryEquiv` as a linear equivalence. This is the `DFinsupp` version of `Finsupp.finsuppProdLEquiv`. -/ @[simps! apply symm_apply] def sigmaCurryLEquiv {α : ι → Type*} {M : (i : ι) → α i → Type*} [Π i j, AddCommMonoid (M i j)] [Π i j, Module R (M i j)] [DecidableEq ι] : (Π₀ (i : (x : ι) × α x), M i.fst i.snd) ≃ₗ[R] Π₀ (i : ι) (j : α i), M i j where __ := DFinsupp.sigmaCurryEquiv map_add' _ _ := by ext; rfl map_smul' _ _ := by ext; rfl /-- `DFinsupp.equivFunOnFintype` as a linear equivalence. This is the `DFinsupp` version of `Finsupp.linearEquivFunOnFintype`. -/ @[simps! apply symm_apply] def linearEquivFunOnFintype [Fintype ι] : (Π₀ i, M i) ≃ₗ[R] (Π i, M i) where __ := equivFunOnFintype map_add' _ _ := by ext; rfl map_smul' _ _ := by ext; rfl /-- The `DFinsupp` version of `Finsupp.lsum`. See note [bundled maps over different rings] for why separate `R` and `S` semirings are used. -/ @[simps] def lsum [Semiring S] [Module S N] [SMulCommClass R S N] : (∀ i, M i →ₗ[R] N) ≃ₗ[S] (Π₀ i, M i) →ₗ[R] N where toFun F := { toFun := sumAddHom fun i => (F i).toAddMonoidHom map_add' := (DFinsupp.liftAddHom fun (i : ι) => (F i).toAddMonoidHom).map_add map_smul' := fun c f => by dsimp apply DFinsupp.induction f · rw [smul_zero, AddMonoidHom.map_zero, smul_zero] · intro a b f _ _ hf rw [smul_add, AddMonoidHom.map_add, AddMonoidHom.map_add, smul_add, hf, ← single_smul, sumAddHom_single, sumAddHom_single, LinearMap.toAddMonoidHom_coe, LinearMap.map_smul] } invFun F i := F.comp (lsingle i) left_inv F := by ext simp right_inv F := by refine DFinsupp.lhom_ext' (fun i ↦ ?_) ext simp map_add' F G := by refine DFinsupp.lhom_ext' (fun i ↦ ?_) ext simp map_smul' c F := by refine DFinsupp.lhom_ext' (fun i ↦ ?_) ext simp /-- While `simp` can prove this, it is often convenient to avoid unfolding `lsum` into `sumAddHom` with `DFinsupp.lsum_apply_apply`. -/ theorem lsum_single [Semiring S] [Module S N] [SMulCommClass R S N] (F : ∀ i, M i →ₗ[R] N) (i) (x : M i) : lsum S F (single i x) = F i x := by simp theorem lsum_lsingle [Semiring S] [∀ i, Module S (M i)] [∀ i, SMulCommClass R S (M i)] : lsum S (lsingle (R := R) (M := M)) = .id := lhom_ext (lsum_single _ _) theorem iSup_range_lsingle : ⨆ i, LinearMap.range (lsingle (R := R) (M := M) i) = ⊤ := top_le_iff.mp fun m _ ↦ by rw [← LinearMap.id_apply (R := R) m, ← lsum_lsingle ℕ] exact dfinsuppSumAddHom_mem _ _ _ fun i _ ↦ Submodule.mem_iSup_of_mem i ⟨_, rfl⟩ end Lsum /-! ### Bundled versions of `DFinsupp.mapRange` The names should match the equivalent bundled `Finsupp.mapRange` definitions. -/ section mapRange variable {β β₁ β₂ : ι → Type*} section AddCommMonoid variable [∀ i, AddCommMonoid (β i)] [∀ i, AddCommMonoid (β₁ i)] [∀ i, AddCommMonoid (β₂ i)] variable [∀ i, Module R (β i)] [∀ i, Module R (β₁ i)] [∀ i, Module R (β₂ i)] lemma mker_mapRangeAddMonoidHom (f : ∀ i, β₁ i →+ β₂ i) : AddMonoidHom.mker (mapRange.addMonoidHom f) = (AddSubmonoid.pi Set.univ (fun i ↦ AddMonoidHom.mker (f i))).comap coeFnAddMonoidHom := by ext simp [AddSubmonoid.pi, DFinsupp.ext_iff] lemma mrange_mapRangeAddMonoidHom (f : ∀ i, β₁ i →+ β₂ i) : AddMonoidHom.mrange (mapRange.addMonoidHom f) = (AddSubmonoid.pi Set.univ (fun i ↦ AddMonoidHom.mrange (f i))).comap coeFnAddMonoidHom := by classical ext x simp only [AddSubmonoid.mem_comap, coeFnAddMonoidHom_apply] refine ⟨fun ⟨y, hy⟩ i hi ↦ ?_, fun h ↦ ?_⟩ · simp [← hy] · choose g hg using fun i => h i (Set.mem_univ _) use DFinsupp.mk x.support (g ·) ext i simp only [Finset.coe_sort_coe, mapRange.addMonoidHom_apply, mapRange_apply] by_cases mem : i ∈ x.support · rw [mk_of_mem mem, hg] · rw [DFinsupp.notMem_support_iff.mp mem, mk_of_notMem mem, map_zero] theorem mapRange_smul (f : ∀ i, β₁ i → β₂ i) (hf : ∀ i, f i 0 = 0) (r : R) (hf' : ∀ i x, f i (r • x) = r • f i x) (g : Π₀ i, β₁ i) : mapRange f hf (r • g) = r • mapRange f hf g := by ext simp only [mapRange_apply f, coe_smul, Pi.smul_apply, hf'] /-- `DFinsupp.mapRange` as a `LinearMap`. -/ @[simps! apply] def mapRange.linearMap (f : ∀ i, β₁ i →ₗ[R] β₂ i) : (Π₀ i, β₁ i) →ₗ[R] Π₀ i, β₂ i := { mapRange.addMonoidHom fun i => (f i).toAddMonoidHom with toFun := mapRange (fun i x => f i x) fun i => (f i).map_zero map_smul' := fun r => mapRange_smul _ (fun i => (f i).map_zero) _ fun i => (f i).map_smul r } @[simp] theorem mapRange.linearMap_id : (mapRange.linearMap fun i => (LinearMap.id : β₂ i →ₗ[R] _)) = LinearMap.id := by ext simp [linearMap] theorem mapRange.linearMap_comp (f : ∀ i, β₁ i →ₗ[R] β₂ i) (f₂ : ∀ i, β i →ₗ[R] β₁ i) : (mapRange.linearMap fun i => (f i).comp (f₂ i)) = (mapRange.linearMap f).comp (mapRange.linearMap f₂) := LinearMap.ext <| mapRange_comp (fun i x => f i x) (fun i x => f₂ i x) (fun i => (f i).map_zero) (fun i => (f₂ i).map_zero) (by simp) theorem sum_mapRange_index.linearMap [DecidableEq ι] {f : ∀ i, β₁ i →ₗ[R] β₂ i} {h : ∀ i, β₂ i →ₗ[R] N} {l : Π₀ i, β₁ i} : DFinsupp.lsum ℕ h (mapRange.linearMap f l) = DFinsupp.lsum ℕ (fun i => (h i).comp (f i)) l := by classical simpa [DFinsupp.sumAddHom_apply] using sum_mapRange_index fun i => by simp lemma ker_mapRangeLinearMap (f : ∀ i, β₁ i →ₗ[R] β₂ i) : LinearMap.ker (mapRange.linearMap f) = (Submodule.pi Set.univ (fun i ↦ LinearMap.ker (f i))).comap (coeFnLinearMap R) := Submodule.toAddSubmonoid_injective <| mker_mapRangeAddMonoidHom (f · |>.toAddMonoidHom) lemma range_mapRangeLinearMap (f : ∀ i, β₁ i →ₗ[R] β₂ i) : LinearMap.range (mapRange.linearMap f) = (Submodule.pi Set.univ (LinearMap.range <| f ·)).comap (coeFnLinearMap R) := Submodule.toAddSubmonoid_injective <| mrange_mapRangeAddMonoidHom (f · |>.toAddMonoidHom) /-- `DFinsupp.mapRange.linearMap` as a `LinearEquiv`. -/ @[simps apply] def mapRange.linearEquiv (e : ∀ i, β₁ i ≃ₗ[R] β₂ i) : (Π₀ i, β₁ i) ≃ₗ[R] Π₀ i, β₂ i := { mapRange.addEquiv fun i => (e i).toAddEquiv, mapRange.linearMap fun i => (e i).toLinearMap with toFun := mapRange (fun i x => e i x) fun i => (e i).map_zero invFun := mapRange (fun i x => (e i).symm x) fun i => (e i).symm.map_zero } @[simp] theorem mapRange.linearEquiv_refl : (mapRange.linearEquiv fun i => LinearEquiv.refl R (β₁ i)) = LinearEquiv.refl _ _ := LinearEquiv.ext mapRange_id theorem mapRange.linearEquiv_trans (f : ∀ i, β i ≃ₗ[R] β₁ i) (f₂ : ∀ i, β₁ i ≃ₗ[R] β₂ i) : (mapRange.linearEquiv fun i => (f i).trans (f₂ i)) = (mapRange.linearEquiv f).trans (mapRange.linearEquiv f₂) := LinearEquiv.ext <| mapRange_comp (fun i x => f₂ i x) (fun i x => f i x) (fun i => (f₂ i).map_zero) (fun i => (f i).map_zero) (by simp) @[simp] theorem mapRange.linearEquiv_symm (e : ∀ i, β₁ i ≃ₗ[R] β₂ i) : (mapRange.linearEquiv e).symm = mapRange.linearEquiv fun i => (e i).symm := rfl end AddCommMonoid section AddCommGroup lemma ker_mapRangeAddMonoidHom [∀ i, AddCommGroup (β₁ i)] [∀ i, AddCommMonoid (β₂ i)] (f : ∀ i, β₁ i →+ β₂ i) : (mapRange.addMonoidHom f).ker = (AddSubgroup.pi Set.univ (f · |>.ker)).comap coeFnAddMonoidHom := AddSubgroup.toAddSubmonoid_injective <| mker_mapRangeAddMonoidHom f lemma range_mapRangeAddMonoidHom [∀ i, AddCommGroup (β₁ i)] [∀ i, AddCommGroup (β₂ i)] (f : ∀ i, β₂ i →+ β₁ i) : (mapRange.addMonoidHom f).range = (AddSubgroup.pi Set.univ (f · |>.range)).comap coeFnAddMonoidHom := AddSubgroup.toAddSubmonoid_injective <| mrange_mapRangeAddMonoidHom f end AddCommGroup end mapRange section CoprodMap variable [DecidableEq ι] /-- Given a family of linear maps `f i : M i →ₗ[R] N`, we can form a linear map `(Π₀ i, M i) →ₗ[R] N` which sends `x : Π₀ i, M i` to the sum over `i` of `f i` applied to `x i`. This is the map coming from the universal property of `Π₀ i, M i` as the coproduct of the `M i`. See also `LinearMap.coprod` for the binary product version. -/ def coprodMap (f : ∀ i : ι, M i →ₗ[R] N) : (Π₀ i, M i) →ₗ[R] N := (DFinsupp.lsum ℕ fun _ : ι => LinearMap.id) ∘ₗ DFinsupp.mapRange.linearMap f theorem coprodMap_apply [∀ x : N, Decidable (x ≠ 0)] (f : ∀ i : ι, M i →ₗ[R] N) (x : Π₀ i, M i) : coprodMap f x = DFinsupp.sum (mapRange (fun i => f i) (fun _ => LinearMap.map_zero _) x) fun _ => id := DFinsupp.sumAddHom_apply _ _ theorem coprodMap_apply_single (f : ∀ i : ι, M i →ₗ[R] N) (i : ι) (x : M i) : coprodMap f (single i x) = f i x := by simp [coprodMap] end CoprodMap end DFinsupp namespace Submodule variable [Semiring R] [AddCommMonoid N] [Module R N] open DFinsupp section DecidableEq variable [DecidableEq ι] theorem dfinsuppSum_mem {β : ι → Type*} [∀ i, Zero (β i)] [∀ (i) (x : β i), Decidable (x ≠ 0)] (S : Submodule R N) (f : Π₀ i, β i) (g : ∀ i, β i → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ S) : f.sum g ∈ S := _root_.dfinsuppSum_mem S f g h theorem dfinsuppSumAddHom_mem {β : ι → Type*} [∀ i, AddZeroClass (β i)] (S : Submodule R N) (f : Π₀ i, β i) (g : ∀ i, β i →+ N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ S) : DFinsupp.sumAddHom g f ∈ S := _root_.dfinsuppSumAddHom_mem S f g h /-- The supremum of a family of submodules is equal to the range of `DFinsupp.lsum`; that is every element in the `iSup` can be produced from taking a finite number of non-zero elements of `p i`, coercing them to `N`, and summing them. -/ theorem iSup_eq_range_dfinsupp_lsum (p : ι → Submodule R N) : iSup p = LinearMap.range (DFinsupp.lsum ℕ fun i => (p i).subtype) := by apply le_antisymm · apply iSup_le _ intro i y hy simp only [LinearMap.mem_range, lsum_apply_apply] exact ⟨DFinsupp.single i ⟨y, hy⟩, DFinsupp.sumAddHom_single _ _ _⟩ · rintro x ⟨v, rfl⟩ exact dfinsuppSumAddHom_mem _ v _ fun i _ => (le_iSup p i : p i ≤ _) (v i).2 /-- The bounded supremum of a family of commutative additive submonoids is equal to the range of `DFinsupp.sumAddHom` composed with `DFinsupp.filter_add_monoid_hom`; that is, every element in the bounded `iSup` can be produced from taking a finite number of non-zero elements from the `S i` that satisfy `p i`, coercing them to `γ`, and summing them. -/ theorem biSup_eq_range_dfinsupp_lsum (p : ι → Prop) [DecidablePred p] (S : ι → Submodule R N) : ⨆ (i) (_ : p i), S i = LinearMap.range (LinearMap.comp (DFinsupp.lsum ℕ (fun i => (S i).subtype)) (DFinsupp.filterLinearMap R _ p)) := by apply le_antisymm · refine iSup₂_le fun i hi y hy => ⟨DFinsupp.single i ⟨y, hy⟩, ?_⟩ rw [LinearMap.comp_apply, filterLinearMap_apply, filter_single_pos _ _ hi] simp only [lsum_apply_apply, sumAddHom_single, LinearMap.toAddMonoidHom_coe, coe_subtype] · rintro x ⟨v, rfl⟩ refine dfinsuppSumAddHom_mem _ _ _ fun i _ => ?_ refine mem_iSup_of_mem i ?_ by_cases hp : p i · simp [hp] · simp [hp] /-- A characterisation of the span of a family of submodules. See also `Submodule.mem_iSup_iff_exists_finsupp`. -/ theorem mem_iSup_iff_exists_dfinsupp (p : ι → Submodule R N) (x : N) : x ∈ iSup p ↔ ∃ f : Π₀ i, p i, DFinsupp.lsum ℕ (fun i => (p i).subtype) f = x := SetLike.ext_iff.mp (iSup_eq_range_dfinsupp_lsum p) x /-- A variant of `Submodule.mem_iSup_iff_exists_dfinsupp` with the RHS fully unfolded. See also `Submodule.mem_iSup_iff_exists_finsupp`. -/ theorem mem_iSup_iff_exists_dfinsupp' (p : ι → Submodule R N) [∀ (i) (x : p i), Decidable (x ≠ 0)] (x : N) : x ∈ iSup p ↔ ∃ f : Π₀ i, p i, (f.sum fun _ xi => ↑xi) = x := by rw [mem_iSup_iff_exists_dfinsupp] simp_rw [DFinsupp.lsum_apply_apply, DFinsupp.sumAddHom_apply, LinearMap.toAddMonoidHom_coe, coe_subtype] theorem mem_biSup_iff_exists_dfinsupp (p : ι → Prop) [DecidablePred p] (S : ι → Submodule R N) (x : N) : (x ∈ ⨆ (i) (_ : p i), S i) ↔ ∃ f : Π₀ i, S i, DFinsupp.lsum ℕ (fun i => (S i).subtype) (f.filter p) = x := SetLike.ext_iff.mp (biSup_eq_range_dfinsupp_lsum p S) x end DecidableEq lemma mem_iSup_iff_exists_finsupp (p : ι → Submodule R N) (x : N) : x ∈ iSup p ↔ ∃ (f : ι →₀ N), (∀ i, f i ∈ p i) ∧ (f.sum fun _i xi ↦ xi) = x := by classical rw [mem_iSup_iff_exists_dfinsupp'] refine ⟨fun ⟨f, hf⟩ ↦ ⟨⟨f.support, fun i ↦ (f i : N), by simp⟩, by simp, hf⟩, ?_⟩ rintro ⟨f, hf, rfl⟩ refine ⟨DFinsupp.mk f.support fun i ↦ ⟨f i, hf i⟩, Finset.sum_congr ?_ fun i hi ↦ ?_⟩ · ext; simp [mk_eq_zero] · simp [Finsupp.mem_support_iff.mp hi] theorem mem_iSup_finset_iff_exists_sum {s : Finset ι} (p : ι → Submodule R N) (a : N) : (a ∈ ⨆ i ∈ s, p i) ↔ ∃ μ : ∀ i, p i, (∑ i ∈ s, (μ i : N)) = a := by classical rw [Submodule.mem_iSup_iff_exists_dfinsupp'] constructor <;> rintro ⟨μ, hμ⟩ · use fun i => ⟨μ i, (iSup_const_le : _ ≤ p i) (coe_mem <| μ i)⟩ rw [← hμ] symm apply Finset.sum_subset · intro x contrapose intro hx rw [mem_support_iff, not_ne_iff] ext rw [coe_zero, ← mem_bot R] suffices ⊥ = ⨆ (_ : x ∈ s), p x from this.symm ▸ coe_mem (μ x) exact (iSup_neg hx).symm · intro x _ hx rw [mem_support_iff, not_ne_iff] at hx rw [hx] rfl · refine ⟨DFinsupp.mk s ?_, ?_⟩ · rintro ⟨i, hi⟩ refine ⟨μ i, ?_⟩ rw [iSup_pos] · exact coe_mem _ · exact hi simp only [DFinsupp.sum] rw [Finset.sum_subset support_mk_subset, ← hμ] · exact Finset.sum_congr rfl fun x hx => by rw [mk_of_mem hx] · intro x _ hx rw [mem_support_iff, not_ne_iff] at hx rw [hx] rfl end Submodule open DFinsupp section Semiring variable [DecidableEq ι] [Semiring R] [AddCommMonoid N] [Module R N] /-- Independence of a family of submodules can be expressed as a quantifier over `DFinsupp`s. This is an intermediate result used to prove `iSupIndep_of_dfinsupp_lsum_injective` and `iSupIndep.dfinsupp_lsum_injective`. -/ theorem iSupIndep_iff_forall_dfinsupp (p : ι → Submodule R N) : iSupIndep p ↔ ∀ (i) (x : p i) (v : Π₀ i : ι, ↥(p i)), lsum ℕ (fun i => (p i).subtype) (erase i v) = x → x = 0 := by simp_rw [iSupIndep_def, Submodule.disjoint_def, Submodule.mem_biSup_iff_exists_dfinsupp, exists_imp, filter_ne_eq_erase] refine forall_congr' fun i => Subtype.forall'.trans ?_ simp_rw [Submodule.coe_eq_zero] /- If `DFinsupp.lsum` applied with `Submodule.subtype` is injective then the submodules are iSupIndep. -/ theorem iSupIndep_of_dfinsupp_lsum_injective (p : ι → Submodule R N) (h : Function.Injective (lsum ℕ fun i => (p i).subtype)) : iSupIndep p := by rw [iSupIndep_iff_forall_dfinsupp] intro i x v hv replace hv : lsum ℕ (fun i => (p i).subtype) (erase i v) = lsum ℕ (fun i => (p i).subtype) (single i x) := by simpa only [lsum_single] using hv have := DFunLike.ext_iff.mp (h hv) i simpa [eq_comm] using this /- If `DFinsupp.sumAddHom` applied with `AddSubmonoid.subtype` is injective then the additive submonoids are independent. -/ theorem iSupIndep_of_dfinsuppSumAddHom_injective (p : ι → AddSubmonoid N) (h : Function.Injective (sumAddHom fun i => (p i).subtype)) : iSupIndep p := by rw [← iSupIndep_map_orderIso_iff (AddSubmonoid.toNatSubmodule : AddSubmonoid N ≃o _)] exact iSupIndep_of_dfinsupp_lsum_injective _ h /-- Combining `DFinsupp.lsum` with `LinearMap.toSpanSingleton` is the same as `Finsupp.linearCombination` -/ theorem lsum_comp_mapRange_toSpanSingleton [∀ m : R, Decidable (m ≠ 0)] (p : ι → Submodule R N) {v : ι → N} (hv : ∀ i : ι, v i ∈ p i) : (lsum ℕ fun i => (p i).subtype : _ →ₗ[R] _).comp ((mapRange.linearMap fun i => LinearMap.toSpanSingleton R (↥(p i)) ⟨v i, hv i⟩ : _ →ₗ[R] _).comp (finsuppLequivDFinsupp R : (ι →₀ R) ≃ₗ[R] _).toLinearMap) = Finsupp.linearCombination R v := by ext simp end Semiring section Ring variable [DecidableEq ι] [Ring R] [AddCommGroup N] [Module R N] /-- If `DFinsupp.sumAddHom` applied with `AddSubmonoid.subtype` is injective then the additive subgroups are independent. -/ theorem iSupIndep_of_dfinsuppSumAddHom_injective' (p : ι → AddSubgroup N) (h : Function.Injective (sumAddHom fun i => (p i).subtype)) : iSupIndep p := by rw [← iSupIndep_map_orderIso_iff (AddSubgroup.toIntSubmodule : AddSubgroup N ≃o _)] exact iSupIndep_of_dfinsupp_lsum_injective _ h /-- The canonical map out of a direct sum of a family of submodules is injective when the submodules are `iSupIndep`. Note that this is not generally true for `[Semiring R]`, for instance when `A` is the `ℕ`-submodules of the positive and negative integers. See `Counterexamples/DirectSumIsInternal.lean` for a proof of this fact. -/ theorem iSupIndep.dfinsupp_lsum_injective {p : ι → Submodule R N} (h : iSupIndep p) : Function.Injective (lsum ℕ fun i => (p i).subtype) := by -- simplify everything down to binders over equalities in `N` rw [iSupIndep_iff_forall_dfinsupp] at h suffices LinearMap.ker (lsum ℕ fun i => (p i).subtype) = ⊥ by -- Lean can't find this without our help letI thisI : AddCommGroup (Π₀ i, p i) := inferInstance rw [LinearMap.ker_eq_bot] at this exact this rw [LinearMap.ker_eq_bot'] intro m hm ext i : 1 -- split `m` into the piece at `i` and the pieces elsewhere, to match `h` rw [DFinsupp.zero_apply, ← neg_eq_zero] refine h i (-m i) m ?_ rwa [← erase_add_single i m, LinearMap.map_add, lsum_single, Submodule.subtype_apply, add_eq_zero_iff_eq_neg, ← Submodule.coe_neg] at hm /-- The canonical map out of a direct sum of a family of additive subgroups is injective when the additive subgroups are `iSupIndep`. -/ theorem iSupIndep.dfinsuppSumAddHom_injective {p : ι → AddSubgroup N} (h : iSupIndep p) : Function.Injective (sumAddHom fun i => (p i).subtype) := by rw [← iSupIndep_map_orderIso_iff (AddSubgroup.toIntSubmodule : AddSubgroup N ≃o _)] at h exact h.dfinsupp_lsum_injective /-- A family of submodules over an additive group are independent if and only iff `DFinsupp.lsum` applied with `Submodule.subtype` is injective. Note that this is not generally true for `[Semiring R]`; see `iSupIndep.dfinsupp_lsum_injective` for details. -/ theorem iSupIndep_iff_dfinsupp_lsum_injective (p : ι → Submodule R N) : iSupIndep p ↔ Function.Injective (lsum ℕ fun i => (p i).subtype) := ⟨iSupIndep.dfinsupp_lsum_injective, iSupIndep_of_dfinsupp_lsum_injective p⟩ theorem iSupIndep_iff_finset_sum_eq_zero_imp_eq_zero (p : ι → Submodule R N) : iSupIndep p ↔ ∀ (s : Finset ι) (v : ι → N), (∀ i ∈ s, v i ∈ p i) → (∑ i ∈ s, v i = 0) → ∀ i ∈ s, v i = 0 := by simp_rw [iSupIndep_def, Submodule.disjoint_def] constructor · intro h s v hv hv0 i hi apply h _ _ (hv i hi) rw [← s.add_sum_erase _ hi, add_eq_zero_iff_neg_eq] at hv0 rw [← Submodule.neg_mem_iff, hv0] exact SetLike.le_def.mp (biSup_mono <| by grind) (Submodule.sum_mem_biSup <| by grind) · intro h i x hx hsup obtain ⟨f, hf, rfl⟩ := (Submodule.mem_iSup_iff_exists_finsupp ..).mp hsup contrapose! h use insert i f.support, fun j ↦ if j = i then -f.sum fun _ x ↦ x else f j refine ⟨fun j hj ↦ ?_, ?_, by grind [neg_eq_zero, Finsupp.mem_support_iff]⟩ · beta_reduce split_ifs with h · exact (p j).neg_mem (h ▸ hx) · simpa [h] using hf j · specialize hf i simp at hf grind [Finsupp.sum, Finset.sum_congr, Finsupp.mem_support_iff] theorem iSupIndep_iff_finset_sum_eq_imp_eq (p : ι → Submodule R N) : iSupIndep p ↔ ∀ (s : Finset ι) (v w : ι → N), (∀ i ∈ s, v i ∈ p i ∧ w i ∈ p i) → (∑ i ∈ s, v i = ∑ i ∈ s, w i) → ∀ i ∈ s, v i = w i := by rw [iSupIndep_iff_finset_sum_eq_zero_imp_eq_zero] constructor · intro h s v w hvw simpa [sub_eq_zero] using h s (v - w) fun i hi => (p i).sub_mem (hvw i hi).1 (hvw i hi).2 · intro h s v hv hv0 specialize h s v 0 simp_all /-- A family of additive subgroups over an additive group are independent if and only if `DFinsupp.sumAddHom` applied with `AddSubgroup.subtype` is injective. -/ theorem iSupIndep_iff_dfinsuppSumAddHom_injective (p : ι → AddSubgroup N) : iSupIndep p ↔ Function.Injective (sumAddHom fun i => (p i).subtype) := ⟨iSupIndep.dfinsuppSumAddHom_injective, iSupIndep_of_dfinsuppSumAddHom_injective' p⟩ /-- If `(pᵢ)ᵢ` is a family of independent submodules that generates the whole module `N`, then `N` is isomorphic to the direct sum of the submodules. -/ @[simps! apply] noncomputable def iSupIndep.linearEquiv {p : ι → Submodule R N} (ind : iSupIndep p) (iSup_top : ⨆ i, p i = ⊤) : (Π₀ i, p i) ≃ₗ[R] N := .ofBijective _ ⟨ind.dfinsupp_lsum_injective, by rwa [← LinearMap.range_eq_top, ← Submodule.iSup_eq_range_dfinsupp_lsum]⟩ theorem iSupIndep.linearEquiv_symm_apply {p : ι → Submodule R N} (ind : iSupIndep p) (iSup_top : ⨆ i, p i = ⊤) {i : ι} {x : N} (h : x ∈ p i) : (ind.linearEquiv iSup_top).symm x = .single i ⟨x, h⟩ := by simp [← LinearEquiv.eq_symm_apply, iSupIndep.linearEquiv] /-- If a family of submodules is independent, then a choice of nonzero vector from each submodule forms a linearly independent family. See also `iSupIndep.linearIndependent'`. -/ theorem iSupIndep.linearIndependent [NoZeroSMulDivisors R N] {ι} (p : ι → Submodule R N) (hp : iSupIndep p) {v : ι → N} (hv : ∀ i, v i ∈ p i) (hv' : ∀ i, v i ≠ 0) : LinearIndependent R v := by let _ := Classical.decEq ι let _ := Classical.decEq R rw [linearIndependent_iff] intro l hl let a := DFinsupp.mapRange.linearMap (fun i => LinearMap.toSpanSingleton R (p i) ⟨v i, hv i⟩) l.toDFinsupp have ha : a = 0 := by apply hp.dfinsupp_lsum_injective rwa [← lsum_comp_mapRange_toSpanSingleton _ hv] at hl ext i apply smul_left_injective R (hv' i) have : l i • v i = a i := rfl simp only [coe_zero, Pi.zero_apply, ZeroMemClass.coe_zero, smul_eq_zero, ha] at this simpa theorem iSupIndep_iff_linearIndependent_of_ne_zero [NoZeroSMulDivisors R N] {ι} {v : ι → N} (h_ne_zero : ∀ i, v i ≠ 0) : (iSupIndep fun i => R ∙ v i) ↔ LinearIndependent R v := let _ := Classical.decEq ι ⟨fun hv => hv.linearIndependent _ (fun i => Submodule.mem_span_singleton_self <| v i) h_ne_zero, fun hv => hv.iSupIndep_span_singleton⟩ end Ring namespace LinearMap section AddCommMonoid variable {R : Type*} {R₂ : Type*} variable {M : Type*} {M₂ : Type*} variable {ι : Type*} variable [Semiring R] [Semiring R₂] variable [AddCommMonoid M] [AddCommMonoid M₂] variable {σ₁₂ : R →+* R₂} variable [Module R M] [Module R₂ M₂] open Submodule section DFinsupp open DFinsupp variable {γ : ι → Type*} [DecidableEq ι] section Sum variable [∀ i, Zero (γ i)] [∀ (i) (x : γ i), Decidable (x ≠ 0)] theorem coe_dfinsuppSum (t : Π₀ i, γ i) (g : ∀ i, γ i → M →ₛₗ[σ₁₂] M₂) : ⇑(t.sum g) = t.sum fun i d => g i d := rfl @[simp] theorem dfinsuppSum_apply (t : Π₀ i, γ i) (g : ∀ i, γ i → M →ₛₗ[σ₁₂] M₂) (b : M) : (t.sum g) b = t.sum fun i d => g i d b := sum_apply _ _ _ end Sum section SumAddHom variable [∀ i, AddZeroClass (γ i)] @[simp] theorem map_dfinsuppSumAddHom (f : M →ₛₗ[σ₁₂] M₂) {t : Π₀ i, γ i} {g : ∀ i, γ i →+ M} : f (sumAddHom g t) = sumAddHom (fun i => f.toAddMonoidHom.comp (g i)) t := f.toAddMonoidHom.map_dfinsuppSumAddHom _ _ end SumAddHom end DFinsupp end AddCommMonoid end LinearMap namespace LinearEquiv variable {R : Type*} {R₂ : Type*} {M : Type*} {M₂ : Type*} {ι : Type*} section DFinsupp open DFinsupp variable [Semiring R] [Semiring R₂] variable [AddCommMonoid M] [AddCommMonoid M₂] variable [Module R M] [Module R₂ M₂] variable {τ₁₂ : R →+* R₂} {τ₂₁ : R₂ →+* R} variable [RingHomInvPair τ₁₂ τ₂₁] [RingHomInvPair τ₂₁ τ₁₂] variable {γ : ι → Type*} [DecidableEq ι] @[simp] theorem map_dfinsuppSumAddHom [∀ i, AddZeroClass (γ i)] (f : M ≃ₛₗ[τ₁₂] M₂) (t : Π₀ i, γ i) (g : ∀ i, γ i →+ M) : f (sumAddHom g t) = sumAddHom (fun i => f.toAddEquiv.toAddMonoidHom.comp (g i)) t := f.toAddEquiv.map_dfinsuppSumAddHom _ _ end DFinsupp end LinearEquiv
.lake/packages/mathlib/Mathlib/LinearAlgebra/Coevaluation.lean
import Mathlib.LinearAlgebra.Contraction /-! # The coevaluation map on finite-dimensional vector spaces Given a finite-dimensional vector space `V` over a field `K` this describes the canonical linear map from `K` to `V ⊗ Dual K V` which corresponds to the identity function on `V`. ## Tags coevaluation, dual module, tensor product ## Future work * Prove that this is independent of the choice of basis on `V`. -/ noncomputable section section coevaluation open TensorProduct Module open TensorProduct universe u v variable (K : Type u) [Field K] variable (V : Type v) [AddCommGroup V] [Module K V] [FiniteDimensional K V] /-- The coevaluation map is a linear map from a field `K` to a finite-dimensional vector space `V`. -/ def coevaluation : K →ₗ[K] V ⊗[K] Module.Dual K V := let bV := Basis.ofVectorSpace K V (Basis.singleton Unit K).constr K fun _ => ∑ i : Basis.ofVectorSpaceIndex K V, bV i ⊗ₜ[K] bV.coord i theorem coevaluation_apply_one : (coevaluation K V) (1 : K) = let bV := Basis.ofVectorSpace K V ∑ i : Basis.ofVectorSpaceIndex K V, bV i ⊗ₜ[K] bV.coord i := by simp only [coevaluation] rw [(Basis.singleton Unit K).constr_apply_fintype K] simp only [Fintype.univ_punit, Finset.sum_const, one_smul, Basis.singleton_repr, Basis.equivFun_apply, Basis.coe_ofVectorSpace, Finset.card_singleton] open TensorProduct /-- This lemma corresponds to one of the coherence laws for duals in rigid categories, see `CategoryTheory.Monoidal.Rigid`. -/ theorem contractLeft_assoc_coevaluation : (contractLeft K V).rTensor _ ∘ₗ (TensorProduct.assoc K _ _ _).symm.toLinearMap ∘ₗ (coevaluation K V).lTensor (Module.Dual K V) = (TensorProduct.lid K _).symm.toLinearMap ∘ₗ (TensorProduct.rid K _).toLinearMap := by letI := Classical.decEq (Basis.ofVectorSpaceIndex K V) apply TensorProduct.ext apply (Basis.ofVectorSpace K V).dualBasis.ext; intro j; apply LinearMap.ext_ring rw [LinearMap.compr₂ₛₗ_apply, LinearMap.compr₂ₛₗ_apply, TensorProduct.mk_apply] simp only [LinearMap.coe_comp, Function.comp_apply, LinearEquiv.coe_toLinearMap] rw [rid_tmul, one_smul, lid_symm_apply] simp only [LinearMap.lTensor_tmul, coevaluation_apply_one] rw [TensorProduct.tmul_sum, map_sum]; simp only [assoc_symm_tmul] rw [map_sum]; simp only [LinearMap.rTensor_tmul, contractLeft_apply] simp only [Basis.coe_dualBasis, Basis.coord_apply, Basis.repr_self_apply, TensorProduct.ite_tmul] rw [Finset.sum_ite_eq']; simp only [Finset.mem_univ, if_true] /-- This lemma corresponds to one of the coherence laws for duals in rigid categories, see `CategoryTheory.Monoidal.Rigid`. -/ theorem contractLeft_assoc_coevaluation' : (contractLeft K V).lTensor _ ∘ₗ (TensorProduct.assoc K _ _ _).toLinearMap ∘ₗ (coevaluation K V).rTensor V = (TensorProduct.rid K _).symm.toLinearMap ∘ₗ (TensorProduct.lid K _).toLinearMap := by letI := Classical.decEq (Basis.ofVectorSpaceIndex K V) apply TensorProduct.ext apply LinearMap.ext_ring; apply (Basis.ofVectorSpace K V).ext; intro j rw [LinearMap.compr₂ₛₗ_apply, LinearMap.compr₂ₛₗ_apply, TensorProduct.mk_apply] simp only [LinearMap.coe_comp, Function.comp_apply, LinearEquiv.coe_toLinearMap] rw [lid_tmul, one_smul, rid_symm_apply] simp only [LinearMap.rTensor_tmul, coevaluation_apply_one] rw [TensorProduct.sum_tmul, map_sum]; simp only [assoc_tmul] rw [map_sum]; simp only [LinearMap.lTensor_tmul, contractLeft_apply] simp only [Basis.coord_apply, Basis.repr_self_apply, TensorProduct.tmul_ite] rw [Finset.sum_ite_eq]; simp only [Finset.mem_univ, if_true] end coevaluation
.lake/packages/mathlib/Mathlib/LinearAlgebra/Countable.lean
import Mathlib.Data.Finsupp.Encodable import Mathlib.Data.Set.Countable import Mathlib.LinearAlgebra.Finsupp.LinearCombination /-! # Countable modules -/ noncomputable section namespace Finsupp variable {M : Type*} {R : Type*} [Semiring R] [AddCommMonoid M] [Module R M] /-- If `R` is countable, then any `R`-submodule spanned by a countable family of vectors is countable. -/ instance {ι : Type*} [Countable R] [Countable ι] (v : ι → M) : Countable (Submodule.span R (Set.range v)) := by refine Set.countable_coe_iff.mpr (Set.Countable.mono ?_ (Set.countable_range (fun c : (ι →₀ R) => c.sum fun i _ => (c i) • v i))) exact fun _ h => Finsupp.mem_span_range_iff_exists_finsupp.mp (SetLike.mem_coe.mp h) end Finsupp
.lake/packages/mathlib/Mathlib/LinearAlgebra/FreeAlgebra.lean
import Mathlib.Algebra.FreeAlgebra import Mathlib.LinearAlgebra.Basis.Cardinality import Mathlib.LinearAlgebra.Dimension.StrongRankCondition import Mathlib.LinearAlgebra.Dimension.Subsingleton import Mathlib.LinearAlgebra.Finsupp.VectorSpace import Mathlib.LinearAlgebra.FreeModule.Basic import Mathlib.LinearAlgebra.FreeModule.StrongRankCondition /-! # Linear algebra properties of `FreeAlgebra R X` This file provides a `FreeMonoid X` basis on the `FreeAlgebra R X`, and uses it to show the dimension of the algebra is the cardinality of `List X` -/ open Module universe u v namespace FreeAlgebra variable (R : Type u) (X : Type v) section variable [CommSemiring R] /-- The `FreeMonoid X` basis on the `FreeAlgebra R X`, mapping `[x₁, x₂, ..., xₙ]` to the "monomial" `1 • x₁ * x₂ * ⋯ * xₙ` -/ -- @[simps] noncomputable def basisFreeMonoid : Basis (FreeMonoid X) R (FreeAlgebra R X) := Finsupp.basisSingleOne.map (equivMonoidAlgebraFreeMonoid (R := R) (X := X)).symm.toLinearEquiv instance : Module.Free R (FreeAlgebra R X) := have : Module.Free R (MonoidAlgebra R (FreeMonoid X)) := Module.Free.finsupp _ _ _ Module.Free.of_equiv (equivMonoidAlgebraFreeMonoid (R := R) (X := X)).symm.toLinearEquiv end theorem rank_eq [CommRing R] [Nontrivial R] : Module.rank R (FreeAlgebra R X) = Cardinal.lift.{u} (Cardinal.mk (List X)) := by rw [← (Basis.mk_eq_rank'.{_,_,_,u} (basisFreeMonoid R X)).trans (Cardinal.lift_id _), Cardinal.lift_umax.{v, u}, FreeMonoid] end FreeAlgebra open Cardinal theorem Algebra.rank_adjoin_le {R : Type u} {S : Type v} [CommRing R] [Ring S] [Algebra R S] (s : Set S) : Module.rank R (adjoin R s) ≤ max #s ℵ₀ := by rw [adjoin_eq_range_freeAlgebra_lift] cases subsingleton_or_nontrivial R · rw [rank_subsingleton]; exact one_le_aleph0.trans (le_max_right _ _) rw [← lift_le.{max u v}] refine (lift_rank_range_le (FreeAlgebra.lift R ((↑) : s → S)).toLinearMap).trans ?_ rw [FreeAlgebra.rank_eq, lift_id'.{v,u}, lift_umax.{v,u}, lift_le, max_comm] exact mk_list_le_max _
.lake/packages/mathlib/Mathlib/LinearAlgebra/BilinearForm/TensorProduct.lean
import Mathlib.LinearAlgebra.BilinearForm.Hom import Mathlib.LinearAlgebra.Dual.Lemmas import Mathlib.LinearAlgebra.TensorProduct.Tower import Mathlib.RingTheory.TensorProduct.Finite /-! # The bilinear form on a tensor product ## Main definitions * `LinearMap.BilinMap.tensorDistrib (B₁ ⊗ₜ B₂)`: the bilinear form on `M₁ ⊗ M₂` constructed by applying `B₁` on `M₁` and `B₂` on `M₂`. * `LinearMap.BilinMap.tensorDistribEquiv`: `BilinForm.tensorDistrib` as an equivalence on finite free modules. -/ universe u v w uR uA uM₁ uM₂ uN₁ uN₂ variable {R : Type uR} {A : Type uA} {M₁ : Type uM₁} {M₂ : Type uM₂} {N₁ : Type uN₁} {N₂ : Type uN₂} open TensorProduct namespace LinearMap open LinearMap (BilinMap BilinForm) section CommSemiring variable [CommSemiring R] [CommSemiring A] variable [AddCommMonoid M₁] [AddCommMonoid M₂] [AddCommMonoid N₁] [AddCommMonoid N₂] variable [Algebra R A] [Module R M₁] [Module A M₁] [Module R N₁] [Module A N₁] variable [SMulCommClass R A M₁] [IsScalarTower R A M₁] variable [SMulCommClass R A N₁] [IsScalarTower R A N₁] variable [Module R M₂] [Module R N₂] namespace BilinMap variable (R A) in /-- The tensor product of two bilinear maps injects into bilinear maps on tensor products. Note this is heterobasic; the bilinear map on the left can take values in a module over a (commutative) algebra over the ring of the module in which the right bilinear map is valued. -/ def tensorDistrib : (BilinMap A M₁ N₁ ⊗[R] BilinMap R M₂ N₂) →ₗ[A] BilinMap A (M₁ ⊗[R] M₂) (N₁ ⊗[R] N₂) := (TensorProduct.lift.equiv (.id A) (M₁ ⊗[R] M₂) (M₁ ⊗[R] M₂) (N₁ ⊗[R] N₂)).symm.toLinearMap ∘ₗ ((LinearMap.llcomp A _ _ _).flip (TensorProduct.AlgebraTensorModule.tensorTensorTensorComm R R A A M₁ M₂ M₁ M₂).toLinearMap) ∘ₗ TensorProduct.AlgebraTensorModule.homTensorHomMap R _ _ _ _ _ _ ∘ₗ (TensorProduct.AlgebraTensorModule.congr (TensorProduct.lift.equiv (.id A) M₁ M₁ N₁) (TensorProduct.lift.equiv (.id R) _ _ _)).toLinearMap @[simp] theorem tensorDistrib_tmul (B₁ : BilinMap A M₁ N₁) (B₂ : BilinMap R M₂ N₂) (m₁ : M₁) (m₂ : M₂) (m₁' : M₁) (m₂' : M₂) : tensorDistrib R A (B₁ ⊗ₜ B₂) (m₁ ⊗ₜ m₂) (m₁' ⊗ₜ m₂') = B₁ m₁ m₁' ⊗ₜ B₂ m₂ m₂' := rfl /-- The tensor product of two bilinear forms, a shorthand for dot notation. -/ protected abbrev tmul (B₁ : BilinMap A M₁ N₁) (B₂ : BilinMap R M₂ N₂) : BilinMap A (M₁ ⊗[R] M₂) (N₁ ⊗[R] N₂) := tensorDistrib R A (B₁ ⊗ₜ[R] B₂) attribute [local ext] TensorProduct.ext in /-- A tensor product of symmetric bilinear maps is symmetric. -/ lemma tmul_isSymm {B₁ : BilinMap A M₁ N₁} {B₂ : BilinMap R M₂ N₂} (hB₁ : ∀ x y, B₁ x y = B₁ y x) (hB₂ : ∀ x y, B₂ x y = B₂ y x) (x y : M₁ ⊗[R] M₂) : B₁.tmul B₂ x y = B₁.tmul B₂ y x := by revert x y rw [isSymm_iff_eq_flip] aesop variable (A) in /-- The base change of a bilinear map (also known as "extension of scalars"). -/ protected def baseChange (B : BilinMap R M₂ N₂) : BilinMap A (A ⊗[R] M₂) (A ⊗[R] N₂) := BilinMap.tmul (R := R) (A := A) (M₁ := A) (M₂ := M₂) (LinearMap.mul A A) B @[simp] theorem baseChange_tmul (B₂ : BilinMap R M₂ N₂) (a : A) (m₂ : M₂) (a' : A) (m₂' : M₂) : B₂.baseChange A (a ⊗ₜ m₂) (a' ⊗ₜ m₂') = (a * a') ⊗ₜ (B₂ m₂ m₂') := rfl lemma baseChange_isSymm {B₂ : BilinMap R M₂ N₂} (hB₂ : ∀ x y, B₂ x y = B₂ y x) (x y : A ⊗[R] M₂) : B₂.baseChange A x y = B₂.baseChange A y x := tmul_isSymm mul_comm hB₂ x y end BilinMap namespace BilinForm variable (R A) in /-- The tensor product of two bilinear forms injects into bilinear forms on tensor products. Note this is heterobasic; the bilinear form on the left can take values in an (commutative) algebra over the ring in which the right bilinear form is valued. -/ def tensorDistrib : BilinForm A M₁ ⊗[R] BilinForm R M₂ →ₗ[A] BilinForm A (M₁ ⊗[R] M₂) := (AlgebraTensorModule.rid R A A).congrRight₂.toLinearMap ∘ₗ (BilinMap.tensorDistrib R A) variable (R A) in -- TODO: make the RHS `MulOpposite.op (B₂ m₂ m₂') • B₁ m₁ m₁'` so that this has a nicer defeq for -- `R = A` of `B₁ m₁ m₁' * B₂ m₂ m₂'`, as it did before the generalization in https://github.com/leanprover-community/mathlib4/pull/6306. @[simp] theorem tensorDistrib_tmul (B₁ : BilinForm A M₁) (B₂ : BilinForm R M₂) (m₁ : M₁) (m₂ : M₂) (m₁' : M₁) (m₂' : M₂) : tensorDistrib R A (B₁ ⊗ₜ B₂) (m₁ ⊗ₜ m₂) (m₁' ⊗ₜ m₂') = B₂ m₂ m₂' • B₁ m₁ m₁' := rfl /-- The tensor product of two bilinear forms, a shorthand for dot notation. -/ protected abbrev tmul (B₁ : BilinForm A M₁) (B₂ : BilinMap R M₂ R) : BilinMap A (M₁ ⊗[R] M₂) A := tensorDistrib R A (B₁ ⊗ₜ[R] B₂) attribute [local ext] TensorProduct.ext in /-- A tensor product of symmetric bilinear forms is symmetric. -/ lemma _root_.LinearMap.IsSymm.tmul {B₁ : BilinForm A M₁} {B₂ : BilinForm R M₂} (hB₁ : B₁.IsSymm) (hB₂ : B₂.IsSymm) : (B₁.tmul B₂).IsSymm := by rw [LinearMap.isSymm_iff_eq_flip] ext x₁ x₂ y₁ y₂ exact congr_arg₂ (HSMul.hSMul) (hB₂.eq x₂ y₂) (hB₁.eq x₁ y₁) variable (A) in /-- The base change of a bilinear form. -/ protected def baseChange (B : BilinForm R M₂) : BilinForm A (A ⊗[R] M₂) := BilinForm.tmul (R := R) (A := A) (M₁ := A) (M₂ := M₂) (LinearMap.mul A A) B @[simp] theorem baseChange_tmul (B₂ : BilinForm R M₂) (a : A) (m₂ : M₂) (a' : A) (m₂' : M₂) : B₂.baseChange A (a ⊗ₜ m₂) (a' ⊗ₜ m₂') = (B₂ m₂ m₂') • (a * a') := rfl variable (A) in /-- The base change of a symmetric bilinear form is symmetric. -/ lemma IsSymm.baseChange {B₂ : BilinForm R M₂} (hB₂ : B₂.IsSymm) : (B₂.baseChange A).IsSymm := IsSymm.tmul ⟨mul_comm⟩ hB₂ end BilinForm end CommSemiring section CommRing variable [CommRing R] variable [AddCommGroup M₁] [AddCommGroup M₂] variable [Module R M₁] [Module R M₂] variable [Module.Free R M₁] [Module.Finite R M₁] variable [Module.Free R M₂] [Module.Finite R M₂] namespace BilinForm variable (R) in /-- `tensorDistrib` as an equivalence. -/ noncomputable def tensorDistribEquiv : BilinForm R M₁ ⊗[R] BilinForm R M₂ ≃ₗ[R] BilinForm R (M₁ ⊗[R] M₂) := -- the same `LinearEquiv`s as from `tensorDistrib`, -- but with the inner linear map also as an equiv TensorProduct.congr (TensorProduct.lift.equiv (.id R) _ _ _) (TensorProduct.lift.equiv (.id R) _ _ _) ≪≫ₗ TensorProduct.dualDistribEquiv R (M₁ ⊗ M₁) (M₂ ⊗ M₂) ≪≫ₗ (TensorProduct.tensorTensorTensorComm R _ _ _ _).dualMap ≪≫ₗ (TensorProduct.lift.equiv (.id R) _ _ _).symm @[simp] theorem tensorDistribEquiv_tmul (B₁ : BilinForm R M₁) (B₂ : BilinForm R M₂) (m₁ : M₁) (m₂ : M₂) (m₁' : M₁) (m₂' : M₂) : tensorDistribEquiv R (M₁ := M₁) (M₂ := M₂) (B₁ ⊗ₜ[R] B₂) (m₁ ⊗ₜ m₂) (m₁' ⊗ₜ m₂') = B₁ m₁ m₁' * B₂ m₂ m₂' := rfl variable (R M₁ M₂) in -- TODO: make this `rfl` @[simp] theorem tensorDistribEquiv_toLinearMap : (tensorDistribEquiv R (M₁ := M₁) (M₂ := M₂)).toLinearMap = tensorDistrib R R := by ext B₁ B₂ : 3 ext exact mul_comm _ _ @[simp] theorem tensorDistribEquiv_apply (B : BilinForm R M₁ ⊗ BilinForm R M₂) : tensorDistribEquiv R (M₁ := M₁) (M₂ := M₂) B = tensorDistrib R R B := DFunLike.congr_fun (tensorDistribEquiv_toLinearMap R M₁ M₂) B end BilinForm end CommRing end LinearMap
.lake/packages/mathlib/Mathlib/LinearAlgebra/BilinearForm/DualLattice.lean
import Mathlib.LinearAlgebra.BilinearForm.Properties /-! # Dual submodule with respect to a bilinear form. ## Main definitions and results - `BilinForm.dualSubmodule`: The dual submodule with respect to a bilinear form. - `BilinForm.dualSubmodule_span_of_basis`: The dual of a lattice is spanned by the dual basis. ## TODO Properly develop the material in the context of lattices. -/ open LinearMap (BilinForm) open Module variable {R S M} [CommRing R] [Field S] [AddCommGroup M] variable [Algebra R S] [Module R M] [Module S M] [IsScalarTower R S M] namespace LinearMap namespace BilinForm variable (B : BilinForm S M) /-- The dual submodule of a submodule with respect to a bilinear form. -/ def dualSubmodule (N : Submodule R M) : Submodule R M where carrier := { x | ∀ y ∈ N, B x y ∈ (1 : Submodule R S) } add_mem' {a b} ha hb y hy := by simpa using add_mem (ha y hy) (hb y hy) zero_mem' y _ := by rw [B.zero_left]; exact zero_mem _ smul_mem' r a ha y hy := by convert (1 : Submodule R S).smul_mem r (ha y hy) rw [← IsScalarTower.algebraMap_smul S r a] simp only [algebraMap_smul, map_smul_of_tower, LinearMap.smul_apply] lemma mem_dualSubmodule {N : Submodule R M} {x} : x ∈ B.dualSubmodule N ↔ ∀ y ∈ N, B x y ∈ (1 : Submodule R S) := Iff.rfl lemma le_flip_dualSubmodule {N₁ N₂ : Submodule R M} : N₁ ≤ B.flip.dualSubmodule N₂ ↔ N₂ ≤ B.dualSubmodule N₁ := by change (∀ (x : M), x ∈ N₁ → _) ↔ ∀ (x : M), x ∈ N₂ → _ simp only [mem_dualSubmodule, Submodule.mem_one, flip_apply] exact forall₂_swap /-- The natural paring of `B.dualSubmodule N` and `N`. This is bundled as a bilinear map in `BilinForm.dualSubmoduleToDual`. -/ noncomputable def dualSubmoduleParing {N : Submodule R M} (x : B.dualSubmodule N) (y : N) : R := (Submodule.mem_one.mp <| x.prop y y.prop).choose @[simp] lemma dualSubmoduleParing_spec {N : Submodule R M} (x : B.dualSubmodule N) (y : N) : algebraMap R S (B.dualSubmoduleParing x y) = B x y := (Submodule.mem_one.mp <| x.prop y y.prop).choose_spec /-- The natural paring of `B.dualSubmodule N` and `N`. -/ -- TODO: Show that this is perfect when `N` is a lattice and `B` is nondegenerate. @[simps] noncomputable def dualSubmoduleToDual [NoZeroSMulDivisors R S] (N : Submodule R M) : B.dualSubmodule N →ₗ[R] Module.Dual R N := { toFun := fun x ↦ { toFun := B.dualSubmoduleParing x map_add' := fun x y ↦ FaithfulSMul.algebraMap_injective R S (by simp) map_smul' := fun r m ↦ FaithfulSMul.algebraMap_injective R S (by simp [← Algebra.smul_def]) } map_add' := fun x y ↦ LinearMap.ext fun z ↦ FaithfulSMul.algebraMap_injective R S (by simp) map_smul' := fun r x ↦ LinearMap.ext fun y ↦ FaithfulSMul.algebraMap_injective R S (by simp [← Algebra.smul_def]) } lemma dualSubmoduleToDual_injective (hB : B.Nondegenerate) [NoZeroSMulDivisors R S] (N : Submodule R M) (hN : Submodule.span S (N : Set M) = ⊤) : Function.Injective (B.dualSubmoduleToDual N) := by intro x y e ext apply LinearMap.ker_eq_bot.mp hB.ker_eq_bot apply LinearMap.ext_on hN intro z hz simpa using congr_arg (algebraMap R S) (LinearMap.congr_fun e ⟨z, hz⟩) lemma dualSubmodule_span_of_basis {ι} [Finite ι] [DecidableEq ι] (hB : B.Nondegenerate) (b : Basis ι S M) : B.dualSubmodule (Submodule.span R (Set.range b)) = Submodule.span R (Set.range <| B.dualBasis hB b) := by cases nonempty_fintype ι apply le_antisymm · intro x hx rw [← (B.dualBasis hB b).sum_repr x] apply sum_mem rintro i - obtain ⟨r, hr⟩ := Submodule.mem_one.mp <| hx (b i) (Submodule.subset_span ⟨_, rfl⟩) simp only [dualBasis_repr_apply, ← hr, algebraMap_smul] apply Submodule.smul_mem exact Submodule.subset_span ⟨_, rfl⟩ · rw [Submodule.span_le] rintro _ ⟨i, rfl⟩ y hy obtain ⟨f, rfl⟩ := (Submodule.mem_span_range_iff_exists_fun _).mp hy simp only [map_sum] apply sum_mem rintro j - rw [← IsScalarTower.algebraMap_smul S (f j), map_smul] simp_rw [apply_dualBasis_left] rw [smul_eq_mul, mul_ite, mul_one, mul_zero, ← (algebraMap R S).map_zero, ← apply_ite] exact Submodule.mem_one.mpr ⟨_, rfl⟩ lemma dualSubmodule_dualSubmodule_flip_of_basis {ι : Type*} [Finite ι] (hB : B.Nondegenerate) (b : Basis ι S M) : B.dualSubmodule (B.flip.dualSubmodule (Submodule.span R (Set.range b))) = Submodule.span R (Set.range b) := by classical letI := b.finiteDimensional_of_finite rw [dualSubmodule_span_of_basis _ hB.flip, dualSubmodule_span_of_basis B hB, dualBasis_dualBasis_flip hB] lemma dualSubmodule_flip_dualSubmodule_of_basis {ι : Type*} [Finite ι] (hB : B.Nondegenerate) (b : Basis ι S M) : B.flip.dualSubmodule (B.dualSubmodule (Submodule.span R (Set.range b))) = Submodule.span R (Set.range b) := by classical letI := b.finiteDimensional_of_finite rw [dualSubmodule_span_of_basis B hB, dualSubmodule_span_of_basis _ hB.flip, dualBasis_flip_dualBasis hB] lemma dualSubmodule_dualSubmodule_of_basis {ι} [Finite ι] (hB : B.Nondegenerate) (hB' : B.IsSymm) (b : Basis ι S M) : B.dualSubmodule (B.dualSubmodule (Submodule.span R (Set.range b))) = Submodule.span R (Set.range b) := by classical letI := b.finiteDimensional_of_finite rw [dualSubmodule_span_of_basis B hB, dualSubmodule_span_of_basis B hB, dualBasis_dualBasis hB hB'] end BilinForm end LinearMap
.lake/packages/mathlib/Mathlib/LinearAlgebra/BilinearForm/Basic.lean
import Mathlib.Algebra.Algebra.Tower import Mathlib.LinearAlgebra.BilinearMap /-! # Bilinear form This file defines a bilinear form over a module. Basic ideas such as orthogonality are also introduced, as well as reflexive, symmetric, non-degenerate and alternating bilinear forms. Adjoints of linear maps with respect to a bilinear form are also introduced. A bilinear form on an `R`-(semi)module `M`, is a function from `M × M` to `R`, that is linear in both arguments. Comments will typically abbreviate "(semi)module" as just "module", but the definitions should be as general as possible. The result that there exists an orthogonal basis with respect to a symmetric, nondegenerate bilinear form can be found in `QuadraticForm.lean` with `exists_orthogonal_basis`. ## Notation Given any term `B` of type `BilinForm`, due to a coercion, can use the notation `B x y` to refer to the function field, i.e. `B x y = B.bilin x y`. In this file we use the following type variables: - `M`, `M'`, ... are modules over the commutative semiring `R`, - `M₁`, `M₁'`, ... are modules over the commutative ring `R₁`, - `V`, ... is a vector space over the field `K`. ## References * <https://en.wikipedia.org/wiki/Bilinear_form> ## Tags Bilinear form, -/ export LinearMap (BilinForm) open LinearMap (BilinForm) universe u v w variable {R : Type*} {M : Type*} [CommSemiring R] [AddCommMonoid M] [Module R M] variable {S : Type*} [CommSemiring S] [Algebra S R] [Module S M] [IsScalarTower S R M] variable {R₁ : Type*} {M₁ : Type*} [CommRing R₁] [AddCommGroup M₁] [Module R₁ M₁] variable {V : Type*} {K : Type*} [Field K] [AddCommGroup V] [Module K V] variable {B : BilinForm R M} {B₁ : BilinForm R₁ M₁} namespace LinearMap namespace BilinForm theorem add_left (x y z : M) : B (x + y) z = B x z + B y z := map_add₂ _ _ _ _ theorem smul_left (a : R) (x y : M) : B (a • x) y = a * B x y := map_smul₂ _ _ _ _ theorem add_right (x y z : M) : B x (y + z) = B x y + B x z := map_add _ _ _ theorem smul_right (a : R) (x y : M) : B x (a • y) = a * B x y := map_smul _ _ _ theorem zero_left (x : M) : B 0 x = 0 := map_zero₂ _ _ theorem zero_right (x : M) : B x 0 = 0 := map_zero _ theorem neg_left (x y : M₁) : B₁ (-x) y = -B₁ x y := map_neg₂ _ _ _ theorem neg_right (x y : M₁) : B₁ x (-y) = -B₁ x y := map_neg _ _ theorem sub_left (x y z : M₁) : B₁ (x - y) z = B₁ x z - B₁ y z := map_sub₂ _ _ _ _ theorem sub_right (x y z : M₁) : B₁ x (y - z) = B₁ x y - B₁ x z := map_sub _ _ _ lemma smul_left_of_tower (r : S) (x y : M) : B (r • x) y = r • B x y := by rw [← IsScalarTower.algebraMap_smul R r, smul_left, Algebra.smul_def] lemma smul_right_of_tower (r : S) (x y : M) : B x (r • y) = r • B x y := by rw [← IsScalarTower.algebraMap_smul R r, smul_right, Algebra.smul_def] variable {D : BilinForm R M} {D₁ : BilinForm R₁ M₁} -- TODO: instantiate `FunLike` theorem coe_injective : Function.Injective ((fun B x y => B x y) : BilinForm R M → M → M → R) := fun B D h => by ext x y apply congrFun₂ h @[ext] theorem ext (H : ∀ x y : M, B x y = D x y) : B = D := ext₂ H theorem congr_fun (h : B = D) (x y : M) : B x y = D x y := congr_fun₂ h _ _ @[simp] theorem zero_apply (x y : M) : (0 : BilinForm R M) x y = 0 := rfl variable (B D B₁ D₁) @[simp] theorem add_apply (x y : M) : (B + D) x y = B x y + D x y := rfl @[simp] theorem neg_apply (x y : M₁) : (-B₁) x y = -B₁ x y := rfl @[simp] theorem sub_apply (x y : M₁) : (B₁ - D₁) x y = B₁ x y - D₁ x y := rfl /-- `coeFn` as an `AddMonoidHom` -/ @[simps] def coeFnAddMonoidHom : BilinForm R M →+ M → M → R where toFun := fun B x y => B x y map_zero' := rfl map_add' _ _ := rfl section flip /-- The flip of a bilinear form, obtained by exchanging the left and right arguments. -/ def flipHom : BilinForm R M ≃ₗ[R] BilinForm R M := LinearMap.lflip @[simp] theorem flip_apply (A : BilinForm R M) (x y : M) : flipHom A x y = A y x := rfl theorem flip_flip : flipHom.trans flipHom = LinearEquiv.refl R (BilinForm R M) := by ext A simp /-- The `flip` of a bilinear form over a commutative ring, obtained by exchanging the left and right arguments. -/ abbrev flip (B : BilinForm R M) := flipHom B end flip /-- The restriction of a bilinear form on a submodule. -/ @[simps! apply] def restrict (B : BilinForm R M) (W : Submodule R M) : BilinForm R W := LinearMap.domRestrict₁₂ B W W end BilinForm @[simp] theorem lsmul_flip_apply (m : M) : (lsmul R M).flip m = toSpanSingleton R M m := rfl end LinearMap
.lake/packages/mathlib/Mathlib/LinearAlgebra/BilinearForm/Orthogonal.lean
import Mathlib.Algebra.GroupWithZero.NonZeroDivisors import Mathlib.LinearAlgebra.BilinearForm.Properties /-! # Bilinear form This file defines orthogonal bilinear forms. ## Notation Given any term `B` of type `BilinForm`, due to a coercion, can use the notation `B x y` to refer to the function field, i.e. `B x y = B.bilin x y`. In this file we use the following type variables: - `M`, `M'`, ... are modules over the commutative semiring `R`, - `M₁`, `M₁'`, ... are modules over the commutative ring `R₁`, - `V`, ... is a vector space over the field `K`. ## References * <https://en.wikipedia.org/wiki/Bilinear_form> ## Tags Bilinear form, -/ open LinearMap (BilinForm) open Module universe u v w variable {R : Type*} {M : Type*} [CommSemiring R] [AddCommMonoid M] [Module R M] variable {R₁ : Type*} {M₁ : Type*} [CommRing R₁] [AddCommGroup M₁] [Module R₁ M₁] variable {V : Type*} {K : Type*} [Field K] [AddCommGroup V] [Module K V] variable {B : BilinForm R M} {B₁ : BilinForm R₁ M₁} namespace LinearMap namespace BilinForm /-- The proposition that two elements of a bilinear form space are orthogonal. For orthogonality of an indexed set of elements, use `BilinForm.iIsOrtho`. -/ def IsOrtho (B : BilinForm R M) (x y : M) : Prop := B x y = 0 theorem isOrtho_def {B : BilinForm R M} {x y : M} : B.IsOrtho x y ↔ B x y = 0 := Iff.rfl theorem isOrtho_zero_left (x : M) : IsOrtho B (0 : M) x := LinearMap.isOrtho_zero_left B x theorem isOrtho_zero_right (x : M) : IsOrtho B x (0 : M) := zero_right x theorem ne_zero_of_not_isOrtho_self {B : BilinForm K V} (x : V) (hx₁ : ¬B.IsOrtho x x) : x ≠ 0 := fun hx₂ => hx₁ (hx₂.symm ▸ isOrtho_zero_left _) theorem IsRefl.ortho_comm (H : B.IsRefl) {x y : M} : IsOrtho B x y ↔ IsOrtho B y x := ⟨eq_zero H, eq_zero H⟩ theorem IsAlt.ortho_comm (H : B₁.IsAlt) {x y : M₁} : IsOrtho B₁ x y ↔ IsOrtho B₁ y x := LinearMap.IsAlt.ortho_comm H theorem IsSymm.ortho_comm (H : B.IsSymm) {x y : M} : IsOrtho B x y ↔ IsOrtho B y x := LinearMap.IsSymm.ortho_comm (isSymm_iff.1 H) /-- A set of vectors `v` is orthogonal with respect to some bilinear form `B` if and only if for all `i ≠ j`, `B (v i) (v j) = 0`. For orthogonality between two elements, use `BilinForm.IsOrtho` -/ def iIsOrtho {n : Type w} (B : BilinForm R M) (v : n → M) : Prop := B.IsOrthoᵢ v theorem iIsOrtho_def {n : Type w} {B : BilinForm R M} {v : n → M} : B.iIsOrtho v ↔ ∀ i j : n, i ≠ j → B (v i) (v j) = 0 := Iff.rfl section variable {R₄ M₄ : Type*} [CommRing R₄] [IsDomain R₄] variable [AddCommGroup M₄] [Module R₄ M₄] {G : BilinForm R₄ M₄} @[simp] theorem isOrtho_smul_left {x y : M₄} {a : R₄} (ha : a ≠ 0) : IsOrtho G (a • x) y ↔ IsOrtho G x y := by dsimp only [IsOrtho] rw [map_smul] simp only [LinearMap.smul_apply, smul_eq_mul, mul_eq_zero, or_iff_right_iff_imp] exact fun a ↦ (ha a).elim @[simp] theorem isOrtho_smul_right {x y : M₄} {a : R₄} (ha : a ≠ 0) : IsOrtho G x (a • y) ↔ IsOrtho G x y := by dsimp only [IsOrtho] rw [map_smul] simp only [smul_eq_mul, mul_eq_zero, or_iff_right_iff_imp] exact fun a ↦ (ha a).elim /-- A set of orthogonal vectors `v` with respect to some bilinear form `B` is linearly independent if for all `i`, `B (v i) (v i) ≠ 0`. -/ theorem linearIndependent_of_iIsOrtho {n : Type w} {B : BilinForm K V} {v : n → V} (hv₁ : B.iIsOrtho v) (hv₂ : ∀ i, ¬B.IsOrtho (v i) (v i)) : LinearIndependent K v := by classical rw [linearIndependent_iff'] intro s w hs i hi have : B (s.sum fun i : n => w i • v i) (v i) = 0 := by rw [hs, zero_left] have hsum : (s.sum fun j : n => w j * B (v j) (v i)) = w i * B (v i) (v i) := by apply Finset.sum_eq_single_of_mem i hi intro j _ hij rw [iIsOrtho_def.1 hv₁ _ _ hij, mul_zero] simp_rw [sum_left, smul_left, hsum] at this exact eq_zero_of_ne_zero_of_mul_right_eq_zero (hv₂ i) this end section Orthogonal /-- The orthogonal complement of a submodule `N` with respect to some bilinear form is the set of elements `x` which are orthogonal to all elements of `N`; i.e., for all `y` in `N`, `B y x = 0`. Note that for general (neither symmetric nor antisymmetric) bilinear forms this definition has a chirality; in addition to this "right" orthogonal complement one could define a "left" orthogonal complement for which, for all `y` in `N`, `B x y = 0`. This variant definition is not currently provided in mathlib. -/ def orthogonal (B : BilinForm R M) (N : Submodule R M) : Submodule R M where carrier := { m | ∀ n ∈ N, IsOrtho B n m } zero_mem' x _ := isOrtho_zero_right x add_mem' {x y} hx hy n hn := by rw [IsOrtho, add_right, show B n x = 0 from hx n hn, show B n y = 0 from hy n hn, zero_add] smul_mem' c x hx n hn := by rw [IsOrtho, smul_right, show B n x = 0 from hx n hn, mul_zero] variable {N L : Submodule R M} @[simp] theorem mem_orthogonal_iff {N : Submodule R M} {m : M} : m ∈ B.orthogonal N ↔ ∀ n ∈ N, IsOrtho B n m := Iff.rfl @[simp] lemma orthogonal_bot : B.orthogonal ⊥ = ⊤ := by ext; simp [IsOrtho] theorem orthogonal_le (h : N ≤ L) : B.orthogonal L ≤ B.orthogonal N := fun _ hn l hl => hn l (h hl) theorem le_orthogonal_orthogonal (b : B.IsRefl) : N ≤ B.orthogonal (B.orthogonal N) := fun n hn _ hm => b _ _ (hm n hn) lemma orthogonal_top_eq_ker (hB : B.IsRefl) : B.orthogonal ⊤ = LinearMap.ker B := by ext; simp [LinearMap.BilinForm.IsOrtho, LinearMap.ext_iff, hB.eq_iff] lemma orthogonal_top_eq_bot (hB : B.Nondegenerate) (hB₀ : B.IsRefl) : B.orthogonal ⊤ = ⊥ := (Submodule.eq_bot_iff _).mpr fun _ hx ↦ hB _ fun y ↦ hB₀ _ _ <| hx y Submodule.mem_top -- ↓ This lemma only applies in fields as we require `a * b = 0 → a = 0 ∨ b = 0` theorem span_singleton_inf_orthogonal_eq_bot {B : BilinForm K V} {x : V} (hx : ¬B.IsOrtho x x) : (K ∙ x) ⊓ B.orthogonal (K ∙ x) = ⊥ := by rw [← Finset.coe_singleton] refine eq_bot_iff.2 fun y h => ?_ obtain ⟨μ, -, rfl⟩ := Submodule.mem_span_finset.1 h.1 have := h.2 x ?_ · rw [Finset.sum_singleton] at this ⊢ suffices hμzero : μ x = 0 by rw [hμzero, zero_smul, Submodule.mem_bot] change B x (μ x • x) = 0 at this rw [smul_right] at this exact eq_zero_of_ne_zero_of_mul_right_eq_zero hx this · rw [Submodule.mem_span] exact fun _ hp => hp <| Finset.mem_singleton_self _ -- ↓ This lemma only applies in fields since we use the `mul_eq_zero` theorem orthogonal_span_singleton_eq_toLin_ker {B : BilinForm K V} (x : V) : B.orthogonal (K ∙ x) = LinearMap.ker (LinearMap.BilinForm.toLinHomAux₁ B x) := by ext y simp_rw [mem_orthogonal_iff, LinearMap.mem_ker, Submodule.mem_span_singleton] constructor · exact fun h => h x ⟨1, one_smul _ _⟩ · rintro h _ ⟨z, rfl⟩ rw [IsOrtho, smul_left, mul_eq_zero] exact Or.intro_right _ h theorem span_singleton_sup_orthogonal_eq_top {B : BilinForm K V} {x : V} (hx : ¬B.IsOrtho x x) : (K ∙ x) ⊔ B.orthogonal (K ∙ x) = ⊤ := by rw [orthogonal_span_singleton_eq_toLin_ker] exact LinearMap.span_singleton_sup_ker_eq_top _ hx /-- Given a bilinear form `B` and some `x` such that `B x x ≠ 0`, the span of the singleton of `x` is complement to its orthogonal complement. -/ theorem isCompl_span_singleton_orthogonal {B : BilinForm K V} {x : V} (hx : ¬B.IsOrtho x x) : IsCompl (K ∙ x) (B.orthogonal <| K ∙ x) := { disjoint := disjoint_iff.2 <| span_singleton_inf_orthogonal_eq_bot hx codisjoint := codisjoint_iff.2 <| span_singleton_sup_orthogonal_eq_top hx } end Orthogonal variable {M₂' : Type*} variable [AddCommMonoid M₂'] [Module R M₂'] /-- The restriction of a reflexive bilinear form `B` onto a submodule `W` is nondegenerate if `Disjoint W (B.orthogonal W)`. -/ theorem nondegenerate_restrict_of_disjoint_orthogonal (B : BilinForm R₁ M₁) (b : B.IsRefl) {W : Submodule R₁ M₁} (hW : Disjoint W (B.orthogonal W)) : (B.restrict W).Nondegenerate := by rintro ⟨x, hx⟩ b₁ rw [Submodule.mk_eq_zero, ← Submodule.mem_bot R₁] refine hW.le_bot ⟨hx, fun y hy => ?_⟩ specialize b₁ ⟨y, hy⟩ simp only [restrict_apply, domRestrict_apply] at b₁ exact isOrtho_def.mpr (b x y b₁) /-- An orthogonal basis with respect to a nondegenerate bilinear form has no self-orthogonal elements. -/ theorem iIsOrtho.not_isOrtho_basis_self_of_nondegenerate {n : Type w} [Nontrivial R] {B : BilinForm R M} {v : Basis n R M} (h : B.iIsOrtho v) (hB : B.Nondegenerate) (i : n) : ¬B.IsOrtho (v i) (v i) := by intro ho refine v.ne_zero i (hB (v i) fun m => ?_) obtain ⟨vi, rfl⟩ := v.repr.symm.surjective m rw [Basis.repr_symm_apply, Finsupp.linearCombination_apply, Finsupp.sum, sum_right] apply Finset.sum_eq_zero rintro j - rw [smul_right] convert mul_zero (vi j) using 2 obtain rfl | hij := eq_or_ne i j · exact ho · exact h hij /-- Given an orthogonal basis with respect to a bilinear form, the bilinear form is nondegenerate iff the basis has no elements which are self-orthogonal. -/ theorem iIsOrtho.nondegenerate_iff_not_isOrtho_basis_self {n : Type w} [Nontrivial R] [NoZeroDivisors R] (B : BilinForm R M) (v : Basis n R M) (hO : B.iIsOrtho v) : B.Nondegenerate ↔ ∀ i, ¬B.IsOrtho (v i) (v i) := by refine ⟨hO.not_isOrtho_basis_self_of_nondegenerate, fun ho m hB => ?_⟩ obtain ⟨vi, rfl⟩ := v.repr.symm.surjective m rw [LinearEquiv.map_eq_zero_iff] ext i rw [Finsupp.zero_apply] specialize hB (v i) simp_rw [Basis.repr_symm_apply, Finsupp.linearCombination_apply, Finsupp.sum, sum_left, smul_left] at hB rw [Finset.sum_eq_single i] at hB · exact eq_zero_of_ne_zero_of_mul_right_eq_zero (ho i) hB · intro j _ hij convert mul_zero (vi j) using 2 exact hO hij · intro hi convert zero_mul (M₀ := R) _ using 2 exact Finsupp.notMem_support_iff.mp hi section theorem toLin_restrict_ker_eq_inf_orthogonal (B : BilinForm K V) (W : Subspace K V) (b : B.IsRefl) : (LinearMap.ker <| B.domRestrict W).map W.subtype = (W ⊓ B.orthogonal ⊤ : Subspace K V) := by ext x; constructor <;> intro hx · rcases hx with ⟨⟨x, hx⟩, hker, rfl⟩ constructor · simp [hx] · intro y _ rw [IsOrtho, b] change (B.domRestrict W) ⟨x, hx⟩ y = 0 rw [hker] rfl · simp_rw [Submodule.mem_map, LinearMap.mem_ker] refine ⟨⟨x, hx.1⟩, ?_, rfl⟩ ext y change B x y = 0 rw [b] exact hx.2 _ Submodule.mem_top theorem toLin_restrict_range_dualCoannihilator_eq_orthogonal (B : BilinForm K V) (W : Subspace K V) : (LinearMap.range (B.domRestrict W)).dualCoannihilator = B.orthogonal W := by ext x; constructor <;> rw [mem_orthogonal_iff] <;> intro hx · intro y hy rw [Submodule.mem_dualCoannihilator] at hx exact hx (B.domRestrict W ⟨y, hy⟩) ⟨⟨y, hy⟩, rfl⟩ · rw [Submodule.mem_dualCoannihilator] rintro _ ⟨⟨w, hw⟩, rfl⟩ exact hx w hw lemma ker_restrict_eq_of_codisjoint {p q : Submodule R M} (hpq : Codisjoint p q) {B : LinearMap.BilinForm R M} (hB : ∀ x ∈ p, ∀ y ∈ q, B x y = 0) : LinearMap.ker (B.restrict p) = (LinearMap.ker B).comap p.subtype := by ext ⟨z, hz⟩ simp only [LinearMap.mem_ker, Submodule.mem_comap, Submodule.coe_subtype] refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · ext w obtain ⟨x, y, hx, hy, rfl⟩ := Submodule.codisjoint_iff_exists_add_eq.mp hpq w simpa [hB z hz y hy] using LinearMap.congr_fun h ⟨x, hx⟩ · ext ⟨x, hx⟩ simpa using LinearMap.congr_fun h x lemma inf_orthogonal_self_le_ker_restrict {W : Submodule R M} (b₁ : B.IsRefl) : W ⊓ B.orthogonal W ≤ (LinearMap.ker <| B.restrict W).map W.subtype := by rintro v ⟨hv : v ∈ W, hv' : v ∈ B.orthogonal W⟩ simp only [Submodule.mem_map, mem_ker, restrict_apply, Submodule.coe_subtype, Subtype.exists, exists_and_left, exists_prop, exists_eq_right_right] refine ⟨?_, hv⟩ ext ⟨w, hw⟩ exact b₁ w v <| hv' w hw variable [FiniteDimensional K V] open Module Submodule variable {B : BilinForm K V} theorem finrank_add_finrank_orthogonal (b₁ : B.IsRefl) (W : Submodule K V) : finrank K W + finrank K (B.orthogonal W) = finrank K V + finrank K (W ⊓ B.orthogonal ⊤ : Subspace K V) := by rw [← toLin_restrict_ker_eq_inf_orthogonal _ _ b₁, ← toLin_restrict_range_dualCoannihilator_eq_orthogonal _ _, finrank_map_subtype_eq] conv_rhs => rw [← @Subspace.finrank_add_finrank_dualCoannihilator_eq K V _ _ _ _ (LinearMap.range (B.domRestrict W)), add_comm, ← add_assoc, add_comm (finrank K (LinearMap.ker (B.domRestrict W))), LinearMap.finrank_range_add_finrank_ker] lemma finrank_orthogonal (hB : B.Nondegenerate) (hB₀ : B.IsRefl) (W : Submodule K V) : finrank K (B.orthogonal W) = finrank K V - finrank K W := by have := finrank_add_finrank_orthogonal hB₀ (W := W) rw [B.orthogonal_top_eq_bot hB hB₀, inf_bot_eq, finrank_bot, add_zero] at this cutsat lemma orthogonal_orthogonal (hB : B.Nondegenerate) (hB₀ : B.IsRefl) (W : Submodule K V) : B.orthogonal (B.orthogonal W) = W := by apply (eq_of_le_of_finrank_le (LinearMap.BilinForm.le_orthogonal_orthogonal hB₀) _).symm simp only [finrank_orthogonal hB hB₀] omega variable {W : Submodule K V} lemma isCompl_orthogonal_iff_disjoint (hB₀ : B.IsRefl) : IsCompl W (B.orthogonal W) ↔ Disjoint W (B.orthogonal W) := by refine ⟨IsCompl.disjoint, fun h ↦ ⟨h, ?_⟩⟩ rw [codisjoint_iff] apply (eq_top_of_finrank_eq <| (finrank_le _).antisymm _) calc finrank K V ≤ finrank K V + finrank K ↥(W ⊓ B.orthogonal ⊤) := le_self_add _ ≤ finrank K ↥(W ⊔ B.orthogonal W) + finrank K ↥(W ⊓ B.orthogonal W) := ?_ _ ≤ finrank K ↥(W ⊔ B.orthogonal W) := by simp [h.eq_bot] rw [finrank_sup_add_finrank_inf_eq, finrank_add_finrank_orthogonal hB₀ W] /-- A subspace is complement to its orthogonal complement with respect to some reflexive bilinear form if that bilinear form restricted on to the subspace is nondegenerate. -/ theorem isCompl_orthogonal_of_restrict_nondegenerate (b₁ : B.IsRefl) (b₂ : (B.restrict W).Nondegenerate) : IsCompl W (B.orthogonal W) := by have : W ⊓ B.orthogonal W = ⊥ := by rw [eq_bot_iff] intro x hx obtain ⟨hx₁, hx₂⟩ := mem_inf.1 hx refine Subtype.mk_eq_mk.1 (b₂ ⟨x, hx₁⟩ ?_) rintro ⟨n, hn⟩ simp only [restrict_apply, domRestrict_apply] exact b₁ n x (b₁ x n (b₁ n x (hx₂ n hn))) refine IsCompl.of_eq this (eq_top_of_finrank_eq <| (finrank_le _).antisymm ?_) conv_rhs => rw [← add_zero (finrank K _)] rw [← finrank_bot K V, ← this, finrank_sup_add_finrank_inf_eq, finrank_add_finrank_orthogonal b₁] exact le_self_add /-- A subspace is complement to its orthogonal complement with respect to some reflexive bilinear form if and only if that bilinear form restricted on to the subspace is nondegenerate. -/ theorem restrict_nondegenerate_iff_isCompl_orthogonal (b₁ : B.IsRefl) : (B.restrict W).Nondegenerate ↔ IsCompl W (B.orthogonal W) := ⟨fun b₂ => isCompl_orthogonal_of_restrict_nondegenerate b₁ b₂, fun h => B.nondegenerate_restrict_of_disjoint_orthogonal b₁ h.1⟩ lemma orthogonal_eq_top_iff (b₁ : B.IsRefl) (b₂ : (B.restrict W).Nondegenerate) : B.orthogonal W = ⊤ ↔ W = ⊥ := by refine ⟨fun h ↦ ?_, fun h ↦ by simp [h]⟩ have := (B.isCompl_orthogonal_of_restrict_nondegenerate b₁ b₂).inf_eq_bot rwa [h, inf_top_eq] at this lemma eq_top_of_restrict_nondegenerate_of_orthogonal_eq_bot (b₁ : B.IsRefl) (b₂ : (B.restrict W).Nondegenerate) (b₃ : B.orthogonal W = ⊥) : W = ⊤ := by have := (B.isCompl_orthogonal_of_restrict_nondegenerate b₁ b₂).sup_eq_top rwa [b₃, sup_bot_eq] at this lemma orthogonal_eq_bot_iff (b₁ : B.IsRefl) (b₂ : (B.restrict W).Nondegenerate) (b₃ : B.Nondegenerate) : B.orthogonal W = ⊥ ↔ W = ⊤ := by refine ⟨eq_top_of_restrict_nondegenerate_of_orthogonal_eq_bot b₁ b₂, fun h ↦ ?_⟩ rw [h, eq_bot_iff] exact fun x hx ↦ b₃ x fun y ↦ b₁ y x <| by simpa using hx y end /-! We note that we cannot use `BilinForm.restrict_nondegenerate_iff_isCompl_orthogonal` for the lemma below since the below lemma does not require `V` to be finite dimensional. However, `BilinForm.restrict_nondegenerate_iff_isCompl_orthogonal` does not require `B` to be nondegenerate on the whole space. -/ /-- The restriction of a reflexive, non-degenerate bilinear form on the orthogonal complement of the span of a singleton is also non-degenerate. -/ theorem restrict_nondegenerate_orthogonal_spanSingleton (B : BilinForm K V) (b₁ : B.Nondegenerate) (b₂ : B.IsRefl) {x : V} (hx : ¬B.IsOrtho x x) : Nondegenerate <| B.restrict <| B.orthogonal (K ∙ x) := by refine fun m hm => Submodule.coe_eq_zero.1 (b₁ m.1 fun n => ?_) have : n ∈ (K ∙ x) ⊔ B.orthogonal (K ∙ x) := (span_singleton_sup_orthogonal_eq_top hx).symm ▸ Submodule.mem_top rcases Submodule.mem_sup.1 this with ⟨y, hy, z, hz, rfl⟩ specialize hm ⟨z, hz⟩ rw [restrict] at hm erw [add_right, show B m.1 y = 0 by rw [b₂]; exact m.2 y hy, hm, add_zero] end BilinForm end LinearMap
.lake/packages/mathlib/Mathlib/LinearAlgebra/BilinearForm/Properties.lean
import Mathlib.LinearAlgebra.BilinearForm.Hom import Mathlib.LinearAlgebra.Dual.Lemmas /-! # Bilinear form This file defines various properties of bilinear forms, including reflexivity, symmetry, alternativity, adjoint, and non-degeneracy. For orthogonality, see `Mathlib/LinearAlgebra/BilinearForm/Orthogonal.lean`. ## Notation Given any term `B` of type `BilinForm`, due to a coercion, can use the notation `B x y` to refer to the function field, i.e. `B x y = B.bilin x y`. In this file we use the following type variables: - `M`, `M'`, ... are modules over the commutative semiring `R`, - `M₁`, `M₁'`, ... are modules over the commutative ring `R₁`, - `V`, ... is a vector space over the field `K`. ## References * <https://en.wikipedia.org/wiki/Bilinear_form> ## Tags Bilinear form, -/ open LinearMap (BilinForm) open Module universe u v w variable {R : Type*} {M : Type*} [CommSemiring R] [AddCommMonoid M] [Module R M] variable {R₁ : Type*} {M₁ : Type*} [CommRing R₁] [AddCommGroup M₁] [Module R₁ M₁] variable {V : Type*} {K : Type*} [Field K] [AddCommGroup V] [Module K V] variable {M' : Type*} [AddCommMonoid M'] [Module R M'] variable {B : BilinForm R M} {B₁ : BilinForm R₁ M₁} namespace LinearMap namespace BilinForm /-! ### Reflexivity, symmetry, and alternativity -/ /-- The proposition that a bilinear form is reflexive -/ def IsRefl (B : BilinForm R M) : Prop := LinearMap.IsRefl B namespace IsRefl theorem eq_zero (H : B.IsRefl) : ∀ {x y : M}, B x y = 0 → B y x = 0 := fun {x y} => H x y protected theorem neg {B : BilinForm R₁ M₁} (hB : B.IsRefl) : (-B).IsRefl := fun x y => neg_eq_zero.mpr ∘ hB x y ∘ neg_eq_zero.mp protected theorem smul {α} [Semiring α] [Module α R] [SMulCommClass R α R] [NoZeroSMulDivisors α R] (a : α) {B : BilinForm R M} (hB : B.IsRefl) : (a • B).IsRefl := fun _ _ h => (smul_eq_zero.mp h).elim (fun ha => smul_eq_zero_of_left ha _) fun hBz => smul_eq_zero_of_right _ (hB _ _ hBz) protected theorem groupSMul {α} [Group α] [DistribMulAction α R] [SMulCommClass R α R] (a : α) {B : BilinForm R M} (hB : B.IsRefl) : (a • B).IsRefl := fun x y => (smul_eq_zero_iff_eq _).mpr ∘ hB x y ∘ (smul_eq_zero_iff_eq _).mp end IsRefl @[simp] theorem isRefl_zero : (0 : BilinForm R M).IsRefl := fun _ _ _ => rfl @[simp] theorem isRefl_neg {B : BilinForm R₁ M₁} : (-B).IsRefl ↔ B.IsRefl := ⟨fun h => neg_neg B ▸ h.neg, IsRefl.neg⟩ /-- The proposition that a bilinear form is symmetric -/ structure IsSymm (B : BilinForm R M) : Prop where protected eq : ∀ x y, B x y = B y x theorem isSymm_def : IsSymm B ↔ ∀ x y, B x y = B y x where mp := fun ⟨h⟩ ↦ h mpr h := ⟨h⟩ theorem isSymm_iff : IsSymm B ↔ LinearMap.IsSymm B := by simp [isSymm_def, LinearMap.isSymm_def] namespace IsSymm theorem isRefl (H : B.IsSymm) : B.IsRefl := fun x y H1 => H.eq x y ▸ H1 protected theorem add {B₁ B₂ : BilinForm R M} (hB₁ : B₁.IsSymm) (hB₂ : B₂.IsSymm) : (B₁ + B₂).IsSymm := ⟨fun x y => (congr_arg₂ (· + ·) (hB₁.eq x y) (hB₂.eq x y) :)⟩ protected theorem sub {B₁ B₂ : BilinForm R₁ M₁} (hB₁ : B₁.IsSymm) (hB₂ : B₂.IsSymm) : (B₁ - B₂).IsSymm := ⟨fun x y => (congr_arg₂ Sub.sub (hB₁.eq x y) (hB₂.eq x y) :)⟩ protected theorem neg {B : BilinForm R₁ M₁} (hB : B.IsSymm) : (-B).IsSymm := ⟨fun x y => congr_arg Neg.neg (hB.eq x y)⟩ protected theorem smul {α} [Monoid α] [DistribMulAction α R] [SMulCommClass R α R] (a : α) {B : BilinForm R M} (hB : B.IsSymm) : (a • B).IsSymm := ⟨fun x y => congr_arg (a • ·) (hB.eq x y)⟩ /-- The restriction of a symmetric bilinear form on a submodule is also symmetric. -/ theorem restrict {B : BilinForm R M} (b : B.IsSymm) (W : Submodule R M) : (B.restrict W).IsSymm := ⟨fun x y => b.eq x y⟩ end IsSymm @[simp] theorem isSymm_zero : (0 : BilinForm R M).IsSymm := ⟨fun _ _ => rfl⟩ @[simp] theorem isSymm_neg {B : BilinForm R₁ M₁} : (-B).IsSymm ↔ B.IsSymm := ⟨fun h => neg_neg B ▸ h.neg, IsSymm.neg⟩ theorem isSymm_iff_flip : B.IsSymm ↔ flipHom B = B where mp := fun ⟨h⟩ ↦ by ext; simp [h] mpr h := ⟨fun x y ↦ by rw [← flip_apply, h]⟩ section polarization variable {R : Type*} [Field R] [NeZero (2 : R)] [Module R M] {B C : BilinForm R M} /-- Polarization identity: a symmetric bilinear form can be expressed through the values it takes on the diagonal. -/ lemma IsSymm.polarization (x y : M) (hB : B.IsSymm) : B x y = (B (x + y) (x + y) - B x x - B y y) / 2 := by simp only [map_add, LinearMap.add_apply] rw [hB.eq y x] ring_nf rw [mul_assoc, inv_mul_cancel₀ two_ne_zero, mul_one] /-- A symmetric bilinear form is characterized by the values it takes on the diagonal. -/ lemma ext_of_isSymm (hB : IsSymm B) (hC : IsSymm C) (h : ∀ x, B x x = C x x) : B = C := by ext x y rw [hB.polarization, hC.polarization] simp_rw [h] /-- A symmetric bilinear form is characterized by the values it takes on the diagonal. -/ lemma ext_iff_of_isSymm (hB : IsSymm B) (hC : IsSymm C) : B = C ↔ ∀ x, B x x = C x x where mp h := by simp [h] mpr := ext_of_isSymm hB hC end polarization lemma isSymm_iff_basis {ι : Type*} (b : Basis ι R M) : IsSymm B ↔ ∀ i j, B (b i) (b j) = B (b j) (b i) where mp := fun ⟨h⟩ i j ↦ h _ _ mpr := by refine fun h ↦ ⟨fun x y ↦ ?_⟩ obtain ⟨fx, tx, ix, -, hx⟩ := Submodule.mem_span_iff_exists_finset_subset.1 (by simp : x ∈ Submodule.span R (Set.range b)) obtain ⟨fy, ty, iy, -, hy⟩ := Submodule.mem_span_iff_exists_finset_subset.1 (by simp : y ∈ Submodule.span R (Set.range b)) rw [← hx, ← hy] simp only [map_sum, map_smul, coeFn_sum, Finset.sum_apply, smul_apply, smul_eq_mul, Finset.mul_sum] rw [Finset.sum_comm] refine Finset.sum_congr rfl (fun b₁ h₁ ↦ Finset.sum_congr rfl fun b₂ h₂ ↦ ?_) rw [mul_left_comm] obtain ⟨i, rfl⟩ := ix h₁ obtain ⟨j, rfl⟩ := iy h₂ rw [h] /-! ### Positive semidefinite bilinear forms -/ section PositiveSemidefinite /-- A bilinear form `B` is **nonnegative** if for any `x` we have `0 ≤ B x x`. -/ structure IsNonneg [LE R] (B : BilinForm R M) where nonneg : ∀ x, 0 ≤ B x x lemma isNonneg_def [LE R] {B : BilinForm R M} : B.IsNonneg ↔ ∀ x, 0 ≤ B x x := ⟨fun ⟨h⟩ ↦ h, fun h ↦ ⟨h⟩⟩ /-- A bilinear form is nonnegative if and only if it is nonnegative as a sesquilinear form. -/ lemma isNonneg_iff [LE R] {B : BilinForm R M} : B.IsNonneg ↔ LinearMap.IsNonneg B := isNonneg_def.trans LinearMap.isNonneg_def.symm @[simp] lemma isNonneg_zero [Preorder R] : IsNonneg (0 : BilinForm R M) := isNonneg_iff.2 LinearMap.isNonneg_zero protected lemma IsNonneg.add [Preorder R] [AddLeftMono R] {B C : BilinForm R M} (hB : B.IsNonneg) (hC : C.IsNonneg) : (B + C).IsNonneg where nonneg x := add_nonneg (hB.nonneg x) (hC.nonneg x) protected lemma IsNonneg.smul [Preorder R] [PosMulMono R] {B : BilinForm R M} {c : R} (hB : B.IsNonneg) (hc : 0 ≤ c) : (c • B).IsNonneg where nonneg x := mul_nonneg hc (hB.nonneg x) /-- A bilinear form `B` is **positive semidefinite** if it is symmetric and nonnegative. -/ structure IsPosSemidef [LE R] (B : BilinForm R M) extends isSymm : B.IsSymm, isNonneg : B.IsNonneg variable {B : BilinForm R M} lemma isPosSemidef_def [LE R] : B.IsPosSemidef ↔ B.IsSymm ∧ B.IsNonneg := ⟨fun h ↦ ⟨h.isSymm, h.isNonneg⟩, fun ⟨h₁, h₂⟩ ↦ ⟨h₁, h₂⟩⟩ /-- A bilinear form is positive semidefinite if and only if it is positive semidefinite as a sesquilinear form. -/ lemma isPosSemidef_iff [LE R] {B : BilinForm R M} : B.IsPosSemidef ↔ LinearMap.IsPosSemidef B := isPosSemidef_def.trans <| (isSymm_iff.and isNonneg_iff).trans LinearMap.isPosSemidef_def.symm @[simp] lemma isPosSemidef_zero [Preorder R] : IsPosSemidef (0 : BilinForm R M) := isPosSemidef_iff.2 LinearMap.isPosSemidef_zero protected lemma IsPosSemidef.add [Preorder R] [AddLeftMono R] {B C : BilinForm R M} (hB : B.IsPosSemidef) (hC : C.IsPosSemidef) : (B + C).IsPosSemidef := isPosSemidef_iff.2 ((isPosSemidef_iff.1 hB).add (isPosSemidef_iff.1 hC)) protected lemma IsPosSemidef.smul [Preorder R] [PosMulMono R] {B : BilinForm R M} {c : R} (hB : B.IsPosSemidef) (hc : 0 ≤ c) : (c • B).IsPosSemidef := isPosSemidef_def.2 ⟨hB.isSymm.smul c, hB.isNonneg.smul hc⟩ end PositiveSemidefinite /-- The proposition that a bilinear form is alternating -/ def IsAlt (B : BilinForm R M) : Prop := LinearMap.IsAlt B namespace IsAlt theorem self_eq_zero (H : B.IsAlt) (x : M) : B x x = 0 := LinearMap.IsAlt.self_eq_zero H x theorem neg_eq (H : B₁.IsAlt) (x y : M₁) : -B₁ x y = B₁ y x := LinearMap.IsAlt.neg H x y theorem isRefl (H : B₁.IsAlt) : B₁.IsRefl := LinearMap.IsAlt.isRefl H theorem eq_of_add_add_eq_zero [IsCancelAdd R] {a b c : M} (H : B.IsAlt) (hAdd : a + b + c = 0) : B a b = B b c := LinearMap.IsAlt.eq_of_add_add_eq_zero H hAdd protected theorem add {B₁ B₂ : BilinForm R M} (hB₁ : B₁.IsAlt) (hB₂ : B₂.IsAlt) : (B₁ + B₂).IsAlt := fun x => (congr_arg₂ (· + ·) (hB₁ x) (hB₂ x) :).trans <| add_zero _ protected theorem sub {B₁ B₂ : BilinForm R₁ M₁} (hB₁ : B₁.IsAlt) (hB₂ : B₂.IsAlt) : (B₁ - B₂).IsAlt := fun x => (congr_arg₂ Sub.sub (hB₁ x) (hB₂ x)).trans <| sub_zero _ protected theorem neg {B : BilinForm R₁ M₁} (hB : B.IsAlt) : (-B).IsAlt := fun x => neg_eq_zero.mpr <| hB x protected theorem smul {α} [Monoid α] [DistribMulAction α R] [SMulCommClass R α R] (a : α) {B : BilinForm R M} (hB : B.IsAlt) : (a • B).IsAlt := fun x => (congr_arg (a • ·) (hB x)).trans <| smul_zero _ end IsAlt @[simp] theorem isAlt_zero : (0 : BilinForm R M).IsAlt := fun _ => rfl @[simp] theorem isAlt_neg {B : BilinForm R₁ M₁} : (-B).IsAlt ↔ B.IsAlt := ⟨fun h => neg_neg B ▸ h.neg, IsAlt.neg⟩ end BilinForm namespace BilinForm /-- A nondegenerate bilinear form is a bilinear form such that the only element that is orthogonal to every other element is `0`; i.e., for all nonzero `m` in `M`, there exists `n` in `M` with `B m n ≠ 0`. Note that for general (neither symmetric nor antisymmetric) bilinear forms this definition has a chirality; in addition to this "left" nondegeneracy condition one could define a "right" nondegeneracy condition that in the situation described, `B n m ≠ 0`. This variant definition is not currently provided in mathlib. In finite dimension either definition implies the other. -/ def Nondegenerate (B : BilinForm R M) : Prop := ∀ m : M, (∀ n : M, B m n = 0) → m = 0 section variable (R M) /-- In a non-trivial module, zero is not non-degenerate. -/ theorem not_nondegenerate_zero [Nontrivial M] : ¬(0 : BilinForm R M).Nondegenerate := let ⟨m, hm⟩ := exists_ne (0 : M) fun h => hm (h m fun _ => rfl) end variable {M' : Type*} variable [AddCommMonoid M'] [Module R M'] theorem Nondegenerate.ne_zero [Nontrivial M] {B : BilinForm R M} (h : B.Nondegenerate) : B ≠ 0 := fun h0 => not_nondegenerate_zero R M <| h0 ▸ h theorem Nondegenerate.congr {B : BilinForm R M} (e : M ≃ₗ[R] M') (h : B.Nondegenerate) : (congr e B).Nondegenerate := fun m hm => e.symm.map_eq_zero_iff.1 <| h (e.symm m) fun n => (congr_arg _ (e.symm_apply_apply n).symm).trans (hm (e n)) @[simp] theorem nondegenerate_congr_iff {B : BilinForm R M} (e : M ≃ₗ[R] M') : (congr e B).Nondegenerate ↔ B.Nondegenerate := ⟨fun h => by convert h.congr e.symm rw [congr_congr, e.self_trans_symm, congr_refl, LinearEquiv.refl_apply], Nondegenerate.congr e⟩ /-- A bilinear form is nondegenerate if and only if it has a trivial kernel. -/ theorem nondegenerate_iff_ker_eq_bot {B : BilinForm R M} : B.Nondegenerate ↔ LinearMap.ker B = ⊥ := by rw [LinearMap.ker_eq_bot'] simp [Nondegenerate, LinearMap.ext_iff] theorem Nondegenerate.ker_eq_bot {B : BilinForm R M} (h : B.Nondegenerate) : LinearMap.ker B = ⊥ := nondegenerate_iff_ker_eq_bot.mp h theorem compLeft_injective (B : BilinForm R₁ M₁) (b : B.Nondegenerate) : Function.Injective B.compLeft := fun φ ψ h => by ext w refine eq_of_sub_eq_zero (b _ ?_) intro v rw [sub_left, ← compLeft_apply, ← compLeft_apply, ← h, sub_self] theorem isAdjointPair_unique_of_nondegenerate (B : BilinForm R₁ M₁) (b : B.Nondegenerate) (φ ψ₁ ψ₂ : M₁ →ₗ[R₁] M₁) (hψ₁ : IsAdjointPair B B ψ₁ φ) (hψ₂ : IsAdjointPair B B ψ₂ φ) : ψ₁ = ψ₂ := B.compLeft_injective b <| ext fun v w => by rw [compLeft_apply, compLeft_apply, hψ₁, hψ₂] section FiniteDimensional variable [FiniteDimensional K V] /-- Given a nondegenerate bilinear form `B` on a finite-dimensional vector space, `B.toDual` is the linear equivalence between a vector space and its dual. -/ noncomputable def toDual (B : BilinForm K V) (b : B.Nondegenerate) : V ≃ₗ[K] Module.Dual K V := B.linearEquivOfInjective (LinearMap.ker_eq_bot.mp <| b.ker_eq_bot) Subspace.dual_finrank_eq.symm theorem toDual_def {B : BilinForm K V} (b : B.SeparatingLeft) {m n : V} : B.toDual b m n = B m n := rfl @[simp] lemma apply_toDual_symm_apply {B : BilinForm K V} {hB : B.Nondegenerate} (f : Module.Dual K V) (v : V) : B ((B.toDual hB).symm f) v = f v := by change B.toDual hB ((B.toDual hB).symm f) v = f v simp only [LinearEquiv.apply_symm_apply] lemma Nondegenerate.flip {B : BilinForm K V} (hB : B.Nondegenerate) : B.flip.Nondegenerate := by intro x hx apply (Module.evalEquiv K V).injective ext f obtain ⟨y, rfl⟩ := (B.toDual hB).surjective f simpa using hx y lemma nonDegenerateFlip_iff {B : BilinForm K V} : B.flip.Nondegenerate ↔ B.Nondegenerate := ⟨Nondegenerate.flip, Nondegenerate.flip⟩ end FiniteDimensional section DualBasis variable {ι : Type*} [DecidableEq ι] [Finite ι] /-- The `B`-dual basis `B.dualBasis hB b` to a finite basis `b` satisfies `B (B.dualBasis hB b i) (b j) = B (b i) (B.dualBasis hB b j) = if i = j then 1 else 0`, where `B` is a nondegenerate (symmetric) bilinear form and `b` is a finite basis. -/ noncomputable def dualBasis (B : BilinForm K V) (hB : B.Nondegenerate) (b : Basis ι K V) : Basis ι K V := haveI := b.finiteDimensional_of_finite b.dualBasis.map (B.toDual hB).symm variable {B : BilinForm K V} @[simp] theorem dualBasis_repr_apply (hB : B.Nondegenerate) (b : Basis ι K V) (x i) : (B.dualBasis hB b).repr x i = B x (b i) := by have := b.finiteDimensional_of_finite rw [dualBasis, Basis.map_repr, LinearEquiv.symm_symm, LinearEquiv.trans_apply, Basis.dualBasis_repr, toDual_def] theorem apply_dualBasis_left (hB : B.Nondegenerate) (b : Basis ι K V) (i j) : B (B.dualBasis hB b i) (b j) = if j = i then 1 else 0 := by have := b.finiteDimensional_of_finite rw [dualBasis, Basis.map_apply, Basis.coe_dualBasis, ← toDual_def hB, LinearEquiv.apply_symm_apply, Basis.coord_apply, Basis.repr_self, Finsupp.single_apply] theorem apply_dualBasis_right (hB : B.Nondegenerate) (sym : B.IsSymm) (b : Basis ι K V) (i j) : B (b i) (B.dualBasis hB b j) = if i = j then 1 else 0 := by rw [sym.eq, apply_dualBasis_left] @[simp] lemma dualBasis_dualBasis_flip [FiniteDimensional K V] (hB : B.Nondegenerate) (b : Basis ι K V) : B.dualBasis hB (B.flip.dualBasis hB.flip b) = b := by ext i refine LinearMap.ker_eq_bot.mp hB.ker_eq_bot ((B.flip.dualBasis hB.flip b).ext (fun j ↦ ?_)) simp_rw [apply_dualBasis_left, ← B.flip_apply, apply_dualBasis_left, @eq_comm _ i j] @[simp] lemma dualBasis_flip_dualBasis (hB : B.Nondegenerate) [FiniteDimensional K V] (b : Basis ι K V) : B.flip.dualBasis hB.flip (B.dualBasis hB b) = b := dualBasis_dualBasis_flip hB.flip b @[simp] lemma dualBasis_dualBasis (hB : B.Nondegenerate) (hB' : B.IsSymm) [FiniteDimensional K V] (b : Basis ι K V) : B.dualBasis hB (B.dualBasis hB b) = b := by convert dualBasis_dualBasis_flip hB.flip b rwa [eq_comm, ← isSymm_iff_flip] lemma dualBasis_involutive (hB : B.Nondegenerate) (hB' : B.IsSymm) [FiniteDimensional K V] : Function.Involutive (B.dualBasis hB : Basis ι K V → Basis ι K V) := fun b ↦ dualBasis_dualBasis hB hB' b lemma dualBasis_injective (hB : B.Nondegenerate) (hB' : B.IsSymm) [FiniteDimensional K V] : Function.Injective (B.dualBasis hB : Basis ι K V → Basis ι K V) := (B.dualBasis_involutive hB hB').injective @[simp] theorem dualBasis_eq_iff (hB : B.Nondegenerate) (b : Basis ι K V) (v : ι → V) : B.dualBasis hB b = v ↔ ∀ i j, B (v i) (b j) = if j = i then 1 else 0 := ⟨fun h _ _ ↦ by rw [← h, apply_dualBasis_left], fun h ↦ funext fun _ ↦ (B.dualBasis hB b).ext_elem_iff.mpr fun _ ↦ by rw [dualBasis_repr_apply, dualBasis_repr_apply, apply_dualBasis_left, h]⟩ end DualBasis section LinearAdjoints variable [FiniteDimensional K V] /-- Given bilinear forms `B₁, B₂` where `B₂` is nondegenerate, `symmCompOfNondegenerate` is the linear map `B₂ ∘ B₁`. -/ noncomputable def symmCompOfNondegenerate (B₁ B₂ : BilinForm K V) (b₂ : B₂.Nondegenerate) : V →ₗ[K] V := (B₂.toDual b₂).symm.toLinearMap.comp B₁ theorem comp_symmCompOfNondegenerate_apply (B₁ : BilinForm K V) {B₂ : BilinForm K V} (b₂ : B₂.Nondegenerate) (v : V) : B₂ (B₁.symmCompOfNondegenerate B₂ b₂ v) = B₁ v := by rw [symmCompOfNondegenerate] simp only [coe_comp, LinearEquiv.coe_coe, Function.comp_apply] erw [LinearEquiv.apply_symm_apply (B₂.toDual b₂)] @[simp] theorem symmCompOfNondegenerate_left_apply (B₁ : BilinForm K V) {B₂ : BilinForm K V} (b₂ : B₂.Nondegenerate) (v w : V) : B₂ (symmCompOfNondegenerate B₁ B₂ b₂ w) v = B₁ w v := by conv_lhs => rw [comp_symmCompOfNondegenerate_apply] /-- Given the nondegenerate bilinear form `B` and the linear map `φ`, `leftAdjointOfNondegenerate` provides the left adjoint of `φ` with respect to `B`. The lemma proving this property is `BilinForm.isAdjointPairLeftAdjointOfNondegenerate`. -/ noncomputable def leftAdjointOfNondegenerate (B : BilinForm K V) (b : B.Nondegenerate) (φ : V →ₗ[K] V) : V →ₗ[K] V := symmCompOfNondegenerate (B.compRight φ) B b theorem isAdjointPairLeftAdjointOfNondegenerate (B : BilinForm K V) (b : B.Nondegenerate) (φ : V →ₗ[K] V) : IsAdjointPair B B (B.leftAdjointOfNondegenerate b φ) φ := fun x y => (B.compRight φ).symmCompOfNondegenerate_left_apply b y x /-- Given the nondegenerate bilinear form `B`, the linear map `φ` has a unique left adjoint given by `BilinForm.leftAdjointOfNondegenerate`. -/ theorem isAdjointPair_iff_eq_of_nondegenerate (B : BilinForm K V) (b : B.Nondegenerate) (ψ φ : V →ₗ[K] V) : IsAdjointPair B B ψ φ ↔ ψ = B.leftAdjointOfNondegenerate b φ := ⟨fun h => B.isAdjointPair_unique_of_nondegenerate b φ ψ _ h (isAdjointPairLeftAdjointOfNondegenerate _ _ _), fun h => h.symm ▸ isAdjointPairLeftAdjointOfNondegenerate _ _ _⟩ end LinearAdjoints end BilinForm end LinearMap
.lake/packages/mathlib/Mathlib/LinearAlgebra/BilinearForm/Hom.lean
import Mathlib.Algebra.Algebra.Bilinear import Mathlib.LinearAlgebra.Basis.Defs import Mathlib.LinearAlgebra.BilinearForm.Basic import Mathlib.LinearAlgebra.BilinearMap /-! # Bilinear form and linear maps This file describes the relation between bilinear forms and linear maps. ## TODO A lot of this file is now redundant following the replacement of the dedicated `_root_.BilinForm` structure with `LinearMap.BilinForm`, which is just an alias for `M →ₗ[R] M →ₗ[R] R`. For example `LinearMap.BilinForm.toLinHom` is now just the identity map. This redundant code should be removed. ## Notation Given any term `B` of type `BilinForm`, due to a coercion, can use the notation `B x y` to refer to the function field, i.e. `B x y = B.bilin x y`. In this file we use the following type variables: - `M`, `M'`, ... are modules over the commutative semiring `R`, - `M₁`, `M₁'`, ... are modules over the commutative ring `R₁`, - `V`, ... is a vector space over the field `K`. ## References * <https://en.wikipedia.org/wiki/Bilinear_form> ## Tags Bilinear form, -/ open LinearMap (BilinForm) open LinearMap (BilinMap) open Module universe u v w variable {R : Type*} {M : Type*} [CommSemiring R] [AddCommMonoid M] [Module R M] variable {R₁ : Type*} {M₁ : Type*} [CommRing R₁] [AddCommGroup M₁] [Module R₁ M₁] variable {V : Type*} {K : Type*} [Field K] [AddCommGroup V] [Module K V] variable {B : BilinForm R M} {B₁ : BilinForm R₁ M₁} namespace LinearMap namespace BilinForm section ToLin' /-- Auxiliary definition to define `toLinHom`; see below. -/ def toLinHomAux₁ (A : BilinForm R M) (x : M) : M →ₗ[R] R := A x variable (B) theorem sum_left {α} (t : Finset α) (g : α → M) (w : M) : B (∑ i ∈ t, g i) w = ∑ i ∈ t, B (g i) w := B.map_sum₂ t g w variable (w : M) theorem sum_right {α} (t : Finset α) (w : M) (g : α → M) : B w (∑ i ∈ t, g i) = ∑ i ∈ t, B w (g i) := map_sum _ _ _ theorem sum_apply {α} (t : Finset α) (B : α → BilinForm R M) (v w : M) : (∑ i ∈ t, B i) v w = ∑ i ∈ t, B i v w := by simp only [coeFn_sum, Finset.sum_apply] variable {B} /-- The linear map obtained from a `BilinForm` by fixing the right co-ordinate and evaluating in the left. -/ def toLinHomFlip : BilinForm R M →ₗ[R] M →ₗ[R] M →ₗ[R] R := flipHom.toLinearMap theorem toLin'Flip_apply (A : BilinForm R M) (x : M) : toLinHomFlip (M := M) A x = fun y => A y x := rfl end ToLin' end BilinForm end LinearMap namespace LinearMap variable {R' : Type*} [CommSemiring R'] [Algebra R' R] [Module R' M] [IsScalarTower R' R M] /-- Apply a linear map on the output of a bilinear form. -/ @[simps!] def compBilinForm (f : R →ₗ[R'] R') (B : BilinForm R M) : BilinForm R' M := compr₂ (restrictScalars₁₂ R' R' B) f end LinearMap namespace LinearMap namespace BilinForm section Comp variable {M' : Type w} [AddCommMonoid M'] [Module R M'] /-- Apply a linear map on the left and right argument of a bilinear form. -/ def comp (B : BilinForm R M') (l r : M →ₗ[R] M') : BilinForm R M := B.compl₁₂ l r /-- Apply a linear map to the left argument of a bilinear form. -/ def compLeft (B : BilinForm R M) (f : M →ₗ[R] M) : BilinForm R M := B.comp f LinearMap.id /-- Apply a linear map to the right argument of a bilinear form. -/ def compRight (B : BilinForm R M) (f : M →ₗ[R] M) : BilinForm R M := B.comp LinearMap.id f theorem comp_comp {M'' : Type*} [AddCommMonoid M''] [Module R M''] (B : BilinForm R M'') (l r : M →ₗ[R] M') (l' r' : M' →ₗ[R] M'') : (B.comp l' r').comp l r = B.comp (l'.comp l) (r'.comp r) := rfl @[simp] theorem compLeft_compRight (B : BilinForm R M) (l r : M →ₗ[R] M) : (B.compLeft l).compRight r = B.comp l r := rfl @[simp] theorem compRight_compLeft (B : BilinForm R M) (l r : M →ₗ[R] M) : (B.compRight r).compLeft l = B.comp l r := rfl @[simp] theorem comp_apply (B : BilinForm R M') (l r : M →ₗ[R] M') (v w) : B.comp l r v w = B (l v) (r w) := rfl @[simp] theorem compLeft_apply (B : BilinForm R M) (f : M →ₗ[R] M) (v w) : B.compLeft f v w = B (f v) w := rfl @[simp] theorem compRight_apply (B : BilinForm R M) (f : M →ₗ[R] M) (v w) : B.compRight f v w = B v (f w) := rfl @[simp] theorem comp_id_left (B : BilinForm R M) (r : M →ₗ[R] M) : B.comp LinearMap.id r = B.compRight r := by ext rfl @[simp] theorem comp_id_right (B : BilinForm R M) (l : M →ₗ[R] M) : B.comp l LinearMap.id = B.compLeft l := by ext rfl @[simp] theorem compLeft_id (B : BilinForm R M) : B.compLeft LinearMap.id = B := by ext rfl @[simp] theorem compRight_id (B : BilinForm R M) : B.compRight LinearMap.id = B := by ext rfl -- Shortcut for `comp_id_{left,right}` followed by `comp{Right,Left}_id`, -- Needs higher priority to be applied @[simp high] theorem comp_id_id (B : BilinForm R M) : B.comp LinearMap.id LinearMap.id = B := by ext rfl theorem comp_inj (B₁ B₂ : BilinForm R M') {l r : M →ₗ[R] M'} (hₗ : Function.Surjective l) (hᵣ : Function.Surjective r) : B₁.comp l r = B₂.comp l r ↔ B₁ = B₂ := by constructor <;> intro h · -- B₁.comp l r = B₂.comp l r → B₁ = B₂ ext x y obtain ⟨x', hx⟩ := hₗ x subst hx obtain ⟨y', hy⟩ := hᵣ y subst hy rw [← comp_apply, ← comp_apply, h] · -- B₁ = B₂ → B₁.comp l r = B₂.comp l r rw [h] end Comp variable {M' M'' : Type*} variable [AddCommMonoid M'] [AddCommMonoid M''] [Module R M'] [Module R M''] section congr /-- Apply a linear equivalence on the arguments of a bilinear form. -/ def congr (e : M ≃ₗ[R] M') : BilinForm R M ≃ₗ[R] BilinForm R M' := LinearEquiv.congrRight (LinearEquiv.congrLeft _ _ e) ≪≫ₗ LinearEquiv.congrLeft _ _ e @[simp] theorem congr_apply (e : M ≃ₗ[R] M') (B : BilinForm R M) (x y : M') : congr e B x y = B (e.symm x) (e.symm y) := rfl @[simp] theorem congr_symm (e : M ≃ₗ[R] M') : (congr e).symm = congr e.symm := by rfl @[simp] theorem congr_refl : congr (LinearEquiv.refl R M) = LinearEquiv.refl R _ := LinearEquiv.ext fun _ => ext₂ fun _ _ => rfl theorem congr_trans (e : M ≃ₗ[R] M') (f : M' ≃ₗ[R] M'') : (congr e).trans (congr f) = congr (e.trans f) := rfl theorem congr_congr (e : M' ≃ₗ[R] M'') (f : M ≃ₗ[R] M') (B : BilinForm R M) : congr e (congr f B) = congr (f.trans e) B := rfl theorem congr_comp (e : M ≃ₗ[R] M') (B : BilinForm R M) (l r : M'' →ₗ[R] M') : (congr e B).comp l r = B.comp (LinearMap.comp (e.symm : M' →ₗ[R] M) l) (LinearMap.comp (e.symm : M' →ₗ[R] M) r) := rfl theorem comp_congr (e : M' ≃ₗ[R] M'') (B : BilinForm R M) (l r : M' →ₗ[R] M) : congr e (B.comp l r) = B.comp (l.comp (e.symm : M'' →ₗ[R] M')) (r.comp (e.symm : M'' →ₗ[R] M')) := rfl end congr section congrRight₂ variable {N₁ N₂ N₃ : Type*} variable [AddCommMonoid N₁] [AddCommMonoid N₂] [AddCommMonoid N₃] variable [Module R N₁] [Module R N₂] [Module R N₃] /-- When `N₁` and `N₂` are equivalent, bilinear maps on `M` into `N₁` are equivalent to bilinear maps into `N₂`. -/ def _root_.LinearEquiv.congrRight₂ (e : N₁ ≃ₗ[R] N₂) : BilinMap R M N₁ ≃ₗ[R] BilinMap R M N₂ := LinearEquiv.congrRight (LinearEquiv.congrRight e) @[simp] theorem _root_.LinearEquiv.congrRight₂_apply (e : N₁ ≃ₗ[R] N₂) (B : BilinMap R M N₁) : LinearEquiv.congrRight₂ e B = compr₂ B e := rfl @[simp] theorem _root_.LinearEquiv.congrRight₂_refl : LinearEquiv.congrRight₂ (.refl R N₁) = .refl R (BilinMap R M N₁) := rfl @[simp] theorem _root_.LinearEquiv.congrRight_symm (e : N₁ ≃ₗ[R] N₂) : (LinearEquiv.congrRight₂ e (M := M)).symm = LinearEquiv.congrRight₂ e.symm := rfl theorem _root_.LinearEquiv.congrRight₂_trans (e₁₂ : N₁ ≃ₗ[R] N₂) (e₂₃ : N₂ ≃ₗ[R] N₃) : LinearEquiv.congrRight₂ (M := M) (e₁₂ ≪≫ₗ e₂₃) = LinearEquiv.congrRight₂ e₁₂ ≪≫ₗ LinearEquiv.congrRight₂ e₂₃ := rfl end congrRight₂ section LinMulLin /-- `linMulLin f g` is the bilinear form mapping `x` and `y` to `f x * g y` -/ def linMulLin (f g : M →ₗ[R] R) : BilinForm R M := (LinearMap.mul R R).compl₁₂ f g variable {f g : M →ₗ[R] R} @[simp] theorem linMulLin_apply (x y) : linMulLin f g x y = f x * g y := rfl @[simp] theorem linMulLin_comp (l r : M' →ₗ[R] M) : (linMulLin f g).comp l r = linMulLin (f.comp l) (g.comp r) := rfl @[simp] theorem linMulLin_compLeft (l : M →ₗ[R] M) : (linMulLin f g).compLeft l = linMulLin (f.comp l) g := rfl @[simp] theorem linMulLin_compRight (r : M →ₗ[R] M) : (linMulLin f g).compRight r = linMulLin f (g.comp r) := rfl end LinMulLin section Basis variable {F₂ : BilinForm R M} variable {ι : Type*} (b : Basis ι R M) /-- Two bilinear forms are equal when they are equal on all basis vectors. -/ theorem ext_basis (h : ∀ i j, B (b i) (b j) = F₂ (b i) (b j)) : B = F₂ := b.ext fun i => b.ext fun j => h i j /-- Write out `B x y` as a sum over `B (b i) (b j)` if `b` is a basis. -/ theorem sum_repr_mul_repr_mul (x y : M) : ((b.repr x).sum fun i xi => (b.repr y).sum fun j yj => xi • yj • B (b i) (b j)) = B x y := by conv_rhs => rw [← b.linearCombination_repr x, ← b.linearCombination_repr y] simp_rw [Finsupp.linearCombination_apply, Finsupp.sum, sum_left, sum_right, smul_left, smul_right, smul_eq_mul] end Basis end BilinForm end LinearMap
.lake/packages/mathlib/Mathlib/LinearAlgebra/ExteriorAlgebra/Basic.lean
import Mathlib.LinearAlgebra.CliffordAlgebra.Basic import Mathlib.LinearAlgebra.Alternating.Curry /-! # Exterior Algebras We construct the exterior algebra of a module `M` over a commutative semiring `R`. ## Notation The exterior algebra of the `R`-module `M` is denoted as `ExteriorAlgebra R M`. It is endowed with the structure of an `R`-algebra. The `n`th exterior power of the `R`-module `M` is denoted by `exteriorPower R n M`; it is of type `Submodule R (ExteriorAlgebra R M)` and defined as `LinearMap.range (ExteriorAlgebra.ι R : M →ₗ[R] ExteriorAlgebra R M) ^ n`. We also introduce the notation `⋀[R]^n M` for `exteriorPower R n M`. Given a linear morphism `f : M → A` from a module `M` to another `R`-algebra `A`, such that `cond : ∀ m : M, f m * f m = 0`, there is a (unique) lift of `f` to an `R`-algebra morphism, which is denoted `ExteriorAlgebra.lift R f cond`. The canonical linear map `M → ExteriorAlgebra R M` is denoted `ExteriorAlgebra.ι R`. ## Theorems The main theorems proved ensure that `ExteriorAlgebra R M` satisfies the universal property of the exterior algebra. 1. `ι_comp_lift` is the fact that the composition of `ι R` with `lift R f cond` agrees with `f`. 2. `lift_unique` ensures the uniqueness of `lift R f cond` with respect to 1. ## Definitions * `ιMulti` is the `AlternatingMap` corresponding to the wedge product of `ι R m` terms. ## Implementation details The exterior algebra of `M` is constructed as simply `CliffordAlgebra (0 : QuadraticForm R M)`, as this avoids us having to duplicate API. -/ universe u1 u2 u3 u4 u5 variable (R : Type u1) [CommRing R] variable (M : Type u2) [AddCommGroup M] [Module R M] /-- The exterior algebra of an `R`-module `M`. -/ abbrev ExteriorAlgebra := CliffordAlgebra (0 : QuadraticForm R M) namespace ExteriorAlgebra variable {M} /-- The canonical linear map `M →ₗ[R] ExteriorAlgebra R M`. -/ abbrev ι : M →ₗ[R] ExteriorAlgebra R M := CliffordAlgebra.ι _ section exteriorPower -- New variables `n` and `M`, to get the correct order of variables in the notation. variable (n : ℕ) (M : Type u2) [AddCommGroup M] [Module R M] /-- Definition of the `n`th exterior power of a `R`-module `N`. We introduce the notation `⋀[R]^n M` for `exteriorPower R n M`. -/ abbrev exteriorPower : Submodule R (ExteriorAlgebra R M) := LinearMap.range (ι R : M →ₗ[R] ExteriorAlgebra R M) ^ n @[inherit_doc exteriorPower] notation:max "⋀[" R "]^" n:arg => exteriorPower R n end exteriorPower variable {R} /-- As well as being linear, `ι m` squares to zero. -/ theorem ι_sq_zero (m : M) : ι R m * ι R m = 0 := (CliffordAlgebra.ι_sq_scalar _ m).trans <| map_zero _ section variable {A : Type*} [Semiring A] [Algebra R A] theorem comp_ι_sq_zero (g : ExteriorAlgebra R M →ₐ[R] A) (m : M) : g (ι R m) * g (ι R m) = 0 := by rw [← map_mul, ι_sq_zero, map_zero] variable (R) /-- Given a linear map `f : M →ₗ[R] A` into an `R`-algebra `A`, which satisfies the condition: `cond : ∀ m : M, f m * f m = 0`, this is the canonical lift of `f` to a morphism of `R`-algebras from `ExteriorAlgebra R M` to `A`. -/ @[simps! symm_apply] def lift : { f : M →ₗ[R] A // ∀ m, f m * f m = 0 } ≃ (ExteriorAlgebra R M →ₐ[R] A) := Equiv.trans (Equiv.subtypeEquiv (Equiv.refl _) <| by simp) <| CliffordAlgebra.lift _ @[simp] theorem ι_comp_lift (f : M →ₗ[R] A) (cond : ∀ m, f m * f m = 0) : (lift R ⟨f, cond⟩).toLinearMap.comp (ι R) = f := CliffordAlgebra.ι_comp_lift f _ @[simp] theorem lift_ι_apply (f : M →ₗ[R] A) (cond : ∀ m, f m * f m = 0) (x) : lift R ⟨f, cond⟩ (ι R x) = f x := CliffordAlgebra.lift_ι_apply f _ x -- removing `@[simp]` because the LHS is not in simp normal form theorem lift_unique (f : M →ₗ[R] A) (cond : ∀ m, f m * f m = 0) (g : ExteriorAlgebra R M →ₐ[R] A) : g.toLinearMap.comp (ι R) = f ↔ g = lift R ⟨f, cond⟩ := CliffordAlgebra.lift_unique f _ _ variable {R} @[simp] theorem lift_comp_ι (g : ExteriorAlgebra R M →ₐ[R] A) : lift R ⟨g.toLinearMap.comp (ι R), comp_ι_sq_zero _⟩ = g := CliffordAlgebra.lift_comp_ι g /-- See note [partially-applied ext lemmas]. -/ @[ext] theorem hom_ext {f g : ExteriorAlgebra R M →ₐ[R] A} (h : f.toLinearMap.comp (ι R) = g.toLinearMap.comp (ι R)) : f = g := CliffordAlgebra.hom_ext h /-- If `C` holds for the `algebraMap` of `r : R` into `ExteriorAlgebra R M`, the `ι` of `x : M`, and is preserved under addition and multiplication, then it holds for all of `ExteriorAlgebra R M`. -/ @[elab_as_elim] theorem induction {C : ExteriorAlgebra R M → Prop} (algebraMap : ∀ r, C (algebraMap R (ExteriorAlgebra R M) r)) (ι : ∀ x, C (ι R x)) (mul : ∀ a b, C a → C b → C (a * b)) (add : ∀ a b, C a → C b → C (a + b)) (a : ExteriorAlgebra R M) : C a := CliffordAlgebra.induction algebraMap ι mul add a /-- The left-inverse of `algebraMap`. -/ def algebraMapInv : ExteriorAlgebra R M →ₐ[R] R := ExteriorAlgebra.lift R ⟨(0 : M →ₗ[R] R), fun _ => by simp⟩ variable (M) theorem algebraMap_leftInverse : Function.LeftInverse algebraMapInv (algebraMap R <| ExteriorAlgebra R M) := fun x => by simp [algebraMapInv] @[simp] theorem algebraMap_inj (x y : R) : algebraMap R (ExteriorAlgebra R M) x = algebraMap R (ExteriorAlgebra R M) y ↔ x = y := (algebraMap_leftInverse M).injective.eq_iff @[simp] theorem algebraMap_eq_zero_iff (x : R) : algebraMap R (ExteriorAlgebra R M) x = 0 ↔ x = 0 := map_eq_zero_iff (algebraMap _ _) (algebraMap_leftInverse _).injective @[simp] theorem algebraMap_eq_one_iff (x : R) : algebraMap R (ExteriorAlgebra R M) x = 1 ↔ x = 1 := map_eq_one_iff (algebraMap _ _) (algebraMap_leftInverse _).injective @[instance] theorem isLocalHom_algebraMap : IsLocalHom (algebraMap R (ExteriorAlgebra R M)) := isLocalHom_of_leftInverse _ (algebraMap_leftInverse M) theorem isUnit_algebraMap (r : R) : IsUnit (algebraMap R (ExteriorAlgebra R M) r) ↔ IsUnit r := isUnit_map_of_leftInverse _ (algebraMap_leftInverse M) /-- Invertibility in the exterior algebra is the same as invertibility of the base ring. -/ @[simps!] def invertibleAlgebraMapEquiv (r : R) : Invertible (algebraMap R (ExteriorAlgebra R M) r) ≃ Invertible r := invertibleEquivOfLeftInverse _ _ _ (algebraMap_leftInverse M) variable {M} /-- The canonical map from `ExteriorAlgebra R M` into `TrivSqZeroExt R M` that sends `ExteriorAlgebra.ι` to `TrivSqZeroExt.inr`. -/ def toTrivSqZeroExt [Module Rᵐᵒᵖ M] [IsCentralScalar R M] : ExteriorAlgebra R M →ₐ[R] TrivSqZeroExt R M := lift R ⟨TrivSqZeroExt.inrHom R M, fun m => TrivSqZeroExt.inr_mul_inr R m m⟩ @[simp] theorem toTrivSqZeroExt_ι [Module Rᵐᵒᵖ M] [IsCentralScalar R M] (x : M) : toTrivSqZeroExt (ι R x) = TrivSqZeroExt.inr x := lift_ι_apply _ _ _ _ /-- The left-inverse of `ι`. As an implementation detail, we implement this using `TrivSqZeroExt` which has a suitable algebra structure. -/ def ιInv : ExteriorAlgebra R M →ₗ[R] M := by letI : Module Rᵐᵒᵖ M := Module.compHom _ ((RingHom.id R).fromOpposite mul_comm) haveI : IsCentralScalar R M := ⟨fun r m => rfl⟩ exact (TrivSqZeroExt.sndHom R M).comp toTrivSqZeroExt.toLinearMap theorem ι_leftInverse : Function.LeftInverse ιInv (ι R : M → ExteriorAlgebra R M) := fun x => by simp [ιInv] variable (R) in @[simp] theorem ι_inj (x y : M) : ι R x = ι R y ↔ x = y := ι_leftInverse.injective.eq_iff @[simp] theorem ι_eq_zero_iff (x : M) : ι R x = 0 ↔ x = 0 := by rw [← ι_inj R x 0, LinearMap.map_zero] @[simp] theorem ι_eq_algebraMap_iff (x : M) (r : R) : ι R x = algebraMap R _ r ↔ x = 0 ∧ r = 0 := by refine ⟨fun h => ?_, ?_⟩ · letI : Module Rᵐᵒᵖ M := Module.compHom _ ((RingHom.id R).fromOpposite mul_comm) haveI : IsCentralScalar R M := ⟨fun r m => rfl⟩ have hf0 : toTrivSqZeroExt (ι R x) = (0, x) := toTrivSqZeroExt_ι _ rw [h, AlgHom.commutes] at hf0 have : r = 0 ∧ 0 = x := Prod.ext_iff.1 hf0 exact this.symm.imp_left Eq.symm · rintro ⟨rfl, rfl⟩ rw [LinearMap.map_zero, RingHom.map_zero] @[simp] theorem ι_ne_one [Nontrivial R] (x : M) : ι R x ≠ 1 := by rw [← (algebraMap R (ExteriorAlgebra R M)).map_one, Ne, ι_eq_algebraMap_iff] exact one_ne_zero ∘ And.right /-- The generators of the exterior algebra are disjoint from its scalars. -/ theorem ι_range_disjoint_one : Disjoint (LinearMap.range (ι R : M →ₗ[R] ExteriorAlgebra R M)) (1 : Submodule R (ExteriorAlgebra R M)) := by rw [Submodule.disjoint_def] rintro _ ⟨x, hx⟩ h obtain ⟨r, rfl : algebraMap R (ExteriorAlgebra R M) r = _⟩ := Submodule.mem_one.mp h rw [ι_eq_algebraMap_iff x] at hx rw [hx.2, RingHom.map_zero] @[simp] theorem ι_add_mul_swap (x y : M) : ι R x * ι R y + ι R y * ι R x = 0 := CliffordAlgebra.ι_mul_ι_add_swap_of_isOrtho <| .all _ _ theorem ι_mul_prod_list {n : ℕ} (f : Fin n → M) (i : Fin n) : (ι R <| f i) * (List.ofFn fun i => ι R <| f i).prod = 0 := by induction n with | zero => exact i.elim0 | succ n hn => rw [List.ofFn_succ, List.prod_cons, ← mul_assoc] by_cases h : i = 0 · rw [h, ι_sq_zero, zero_mul] · replace hn := congr_arg (ι R (f 0) * ·) <| hn (fun i => f <| Fin.succ i) (i.pred h) simp only at hn rw [Fin.succ_pred, ← mul_assoc, mul_zero] at hn refine (eq_zero_iff_eq_zero_of_add_eq_zero ?_).mp hn rw [← add_mul, ι_add_mul_swap, zero_mul] end variable (R) in /-- The product of `n` terms of the form `ι R m` is an alternating map. This is a special case of `MultilinearMap.mkPiAlgebraFin`, and the exterior algebra version of `TensorAlgebra.tprod`. -/ def ιMulti (n : ℕ) : M [⋀^Fin n]→ₗ[R] ExteriorAlgebra R M := let F := (MultilinearMap.mkPiAlgebraFin R n (ExteriorAlgebra R M)).compLinearMap fun _ => ι R { F with map_eq_zero_of_eq' := fun f x y hfxy hxy => by dsimp [F] clear F wlog h : x < y · exact this R n f y x hfxy.symm hxy.symm (hxy.lt_or_gt.resolve_left h) clear hxy induction n with | zero => exact x.elim0 | succ n hn => rw [List.ofFn_succ, List.prod_cons] by_cases hx : x = 0 -- one of the repeated terms is on the left · rw [hx] at hfxy h rw [hfxy, ← Fin.succ_pred y (ne_of_lt h).symm] exact ι_mul_prod_list (f ∘ Fin.succ) _ -- ignore the left-most term and induct on the remaining ones, decrementing indices · convert mul_zero (ι R (f 0)) refine hn (fun i => f <| Fin.succ i) (x.pred hx) (y.pred (ne_of_lt <| lt_of_le_of_lt x.zero_le h).symm) ?_ (Fin.pred_lt_pred_iff.mpr h) simp only [Fin.succ_pred] exact hfxy toFun := F } theorem ιMulti_apply {n : ℕ} (v : Fin n → M) : ιMulti R n v = (List.ofFn fun i => ι R (v i)).prod := rfl @[simp] theorem ιMulti_zero_apply (v : Fin 0 → M) : ιMulti R 0 v = 1 := by simp [ιMulti] @[simp] theorem ιMulti_succ_apply {n : ℕ} (v : Fin n.succ → M) : ιMulti R _ v = ι R (v 0) * ιMulti R _ (Matrix.vecTail v) := by simp [ιMulti, Matrix.vecTail] theorem ιMulti_succ_curryLeft {n : ℕ} (m : M) : (ιMulti R n.succ).curryLeft m = (LinearMap.mulLeft R (ι R m)).compAlternatingMap (ιMulti R n) := by ext; simp variable (R) /-- The image of `ExteriorAlgebra.ιMulti R n` is contained in the `n`th exterior power. -/ lemma ιMulti_range (n : ℕ) : Set.range (ιMulti R n (M := M)) ⊆ ↑(⋀[R]^n M) := by rw [Set.range_subset_iff] intro v rw [ιMulti_apply] apply Submodule.pow_subset_pow rw [Set.mem_pow] exact ⟨fun i => ⟨ι R (v i), LinearMap.mem_range_self _ _⟩, rfl⟩ /-- The image of `ExteriorAlgebra.ιMulti R n` spans the `n`th exterior power, as a submodule of the exterior algebra. -/ lemma ιMulti_span_fixedDegree (n : ℕ) : Submodule.span R (Set.range (ιMulti R n)) = ⋀[R]^n M := by refine le_antisymm (Submodule.span_le.2 (ιMulti_range R n)) ?_ rw [exteriorPower, Submodule.pow_eq_span_pow_set, Submodule.span_le] refine fun u hu ↦ Submodule.subset_span ?_ obtain ⟨f, rfl⟩ := Set.mem_pow.mp hu refine ⟨fun i => ιInv (f i).1, ?_⟩ rw [ιMulti_apply] congr with i obtain ⟨v, hv⟩ := (f i).prop rw [← hv, ι_leftInverse] /-- Given a linearly ordered family `v` of vectors of `M` and a natural number `n`, produce the family of `n`fold exterior products of elements of `v`, seen as members of the exterior algebra. -/ abbrev ιMulti_family (n : ℕ) {I : Type*} [LinearOrder I] (v : I → M) (s : {s : Finset I // Finset.card s = n}) : ExteriorAlgebra R M := ιMulti R n fun i => v (Finset.orderIsoOfFin _ s.prop i) variable {R} /-- An `ExteriorAlgebra` over a nontrivial ring is nontrivial. -/ instance [Nontrivial R] : Nontrivial (ExteriorAlgebra R M) := (algebraMap_leftInverse M).injective.nontrivial /-! Functoriality of the exterior algebra. -/ variable {N : Type u4} {N' : Type u5} [AddCommGroup N] [Module R N] [AddCommGroup N'] [Module R N'] /-- The morphism of exterior algebras induced by a linear map. -/ def map (f : M →ₗ[R] N) : ExteriorAlgebra R M →ₐ[R] ExteriorAlgebra R N := CliffordAlgebra.map { f with map_app' := fun _ => rfl } @[simp] theorem map_comp_ι (f : M →ₗ[R] N) : (map f).toLinearMap ∘ₗ ι R = ι R ∘ₗ f := CliffordAlgebra.map_comp_ι _ @[simp] theorem map_apply_ι (f : M →ₗ[R] N) (m : M) : map f (ι R m) = ι R (f m) := CliffordAlgebra.map_apply_ι _ m @[simp] theorem map_apply_ιMulti {n : ℕ} (f : M →ₗ[R] N) (m : Fin n → M) : map f (ιMulti R n m) = ιMulti R n (f ∘ m) := by rw [ιMulti_apply, ιMulti_apply, map_list_prod] simp only [List.map_ofFn, Function.comp_def, map_apply_ι] @[simp] theorem map_comp_ιMulti {n : ℕ} (f : M →ₗ[R] N) : (map f).toLinearMap.compAlternatingMap (ιMulti R n (M := M)) = (ιMulti R n (M := N)).compLinearMap f := by ext m exact map_apply_ιMulti _ _ @[simp] theorem map_id : map LinearMap.id = AlgHom.id R (ExteriorAlgebra R M) := CliffordAlgebra.map_id 0 @[simp] theorem map_comp_map (f : M →ₗ[R] N) (g : N →ₗ[R] N') : AlgHom.comp (map g) (map f) = map (LinearMap.comp g f) := CliffordAlgebra.map_comp_map _ _ @[simp] theorem ι_range_map_map (f : M →ₗ[R] N) : Submodule.map (AlgHom.toLinearMap (map f)) (LinearMap.range (ι R (M := M))) = Submodule.map (ι R) (LinearMap.range f) := CliffordAlgebra.ι_range_map_map _ theorem toTrivSqZeroExt_comp_map [Module Rᵐᵒᵖ M] [IsCentralScalar R M] [Module Rᵐᵒᵖ N] [IsCentralScalar R N] (f : M →ₗ[R] N) : toTrivSqZeroExt.comp (map f) = (TrivSqZeroExt.map f).comp toTrivSqZeroExt := by apply hom_ext apply LinearMap.ext simp only [AlgHom.comp_toLinearMap, LinearMap.coe_comp, Function.comp_apply, AlgHom.toLinearMap_apply, map_apply_ι, toTrivSqZeroExt_ι, TrivSqZeroExt.map_inr, forall_const] theorem ιInv_comp_map (f : M →ₗ[R] N) : ιInv.comp (map f).toLinearMap = f.comp ιInv := by letI : Module Rᵐᵒᵖ M := Module.compHom _ ((RingHom.id R).fromOpposite mul_comm) haveI : IsCentralScalar R M := ⟨fun r m => rfl⟩ letI : Module Rᵐᵒᵖ N := Module.compHom _ ((RingHom.id R).fromOpposite mul_comm) haveI : IsCentralScalar R N := ⟨fun r m => rfl⟩ unfold ιInv conv_lhs => rw [LinearMap.comp_assoc, ← AlgHom.comp_toLinearMap, toTrivSqZeroExt_comp_map, AlgHom.comp_toLinearMap, ← LinearMap.comp_assoc, TrivSqZeroExt.sndHom_comp_map] rfl open Function in /-- For a linear map `f` from `M` to `N`, `ExteriorAlgebra.map g` is a retraction of `ExteriorAlgebra.map f` iff `g` is a retraction of `f`. -/ @[simp] lemma leftInverse_map_iff {f : M →ₗ[R] N} {g : N →ₗ[R] M} : LeftInverse (map g) (map f) ↔ LeftInverse g f := by refine ⟨fun h x => ?_, fun h => CliffordAlgebra.leftInverse_map_of_leftInverse _ _ h⟩ simpa using h (ι _ x) /-- A morphism of modules that admits a linear retraction induces an injective morphism of exterior algebras. -/ lemma map_injective {f : M →ₗ[R] N} (hf : ∃ (g : N →ₗ[R] M), g.comp f = LinearMap.id) : Function.Injective (map f) := let ⟨_, hgf⟩ := hf; (leftInverse_map_iff.mpr (DFunLike.congr_fun hgf)).injective /-- A morphism of modules is surjective if and only the morphism of exterior algebras that it induces is surjective. -/ @[simp] lemma map_surjective_iff {f : M →ₗ[R] N} : Function.Surjective (map f) ↔ Function.Surjective f := by refine ⟨fun h y ↦ ?_, fun h ↦ CliffordAlgebra.map_surjective _ h⟩ obtain ⟨x, hx⟩ := h (ι R y) existsi ιInv x rw [← LinearMap.comp_apply, ← ιInv_comp_map, LinearMap.comp_apply] erw [hx, ExteriorAlgebra.ι_leftInverse] variable {K E F : Type*} [Field K] [AddCommGroup E] [Module K E] [AddCommGroup F] [Module K F] /-- An injective morphism of vector spaces induces an injective morphism of exterior algebras. -/ lemma map_injective_field {f : E →ₗ[K] F} (hf : LinearMap.ker f = ⊥) : Function.Injective (map f) := map_injective (LinearMap.exists_leftInverse_of_injective f hf) end ExteriorAlgebra namespace TensorAlgebra variable {R M} /-- The canonical image of the `TensorAlgebra` in the `ExteriorAlgebra`, which maps `TensorAlgebra.ι R x` to `ExteriorAlgebra.ι R x`. -/ def toExterior : TensorAlgebra R M →ₐ[R] ExteriorAlgebra R M := TensorAlgebra.lift R (ExteriorAlgebra.ι R : M →ₗ[R] ExteriorAlgebra R M) @[simp] theorem toExterior_ι (m : M) : TensorAlgebra.toExterior (TensorAlgebra.ι R m) = ExteriorAlgebra.ι R m := by simp [toExterior] end TensorAlgebra
.lake/packages/mathlib/Mathlib/LinearAlgebra/ExteriorAlgebra/Grading.lean
import Mathlib.LinearAlgebra.ExteriorAlgebra.Basic import Mathlib.RingTheory.GradedAlgebra.Basic /-! # Results about the grading structure of the exterior algebra Many of these results are copied with minimal modification from the tensor algebra. The main result is `ExteriorAlgebra.gradedAlgebra`, which says that the exterior algebra is a ℕ-graded algebra. -/ namespace ExteriorAlgebra variable {R M : Type*} [CommRing R] [AddCommGroup M] [Module R M] variable (R M) open scoped DirectSum /-- A version of `ExteriorAlgebra.ι` that maps directly into the graded structure. This is primarily an auxiliary construction used to provide `ExteriorAlgebra.gradedAlgebra`. -/ protected def GradedAlgebra.ι : M →ₗ[R] ⨁ i : ℕ, ⋀[R]^i M := DirectSum.lof R ℕ (fun i => ⋀[R]^i M) 1 ∘ₗ (ι R).codRestrict _ fun m => by simpa only [pow_one] using LinearMap.mem_range_self _ m theorem GradedAlgebra.ι_apply (m : M) : GradedAlgebra.ι R M m = DirectSum.of (fun i : ℕ => ⋀[R]^i M) 1 ⟨ι R m, by simpa only [pow_one] using LinearMap.mem_range_self _ m⟩ := rfl -- Defining this instance manually, because Lean doesn't seem to be able to synthesize it. -- Strangely, this problem only appears when we use the abbreviation or notation for the -- exterior powers. instance : SetLike.GradedMonoid fun i : ℕ ↦ ⋀[R]^i M := Submodule.nat_power_gradedMonoid (LinearMap.range (ι R : M →ₗ[R] ExteriorAlgebra R M)) theorem GradedAlgebra.ι_sq_zero (m : M) : GradedAlgebra.ι R M m * GradedAlgebra.ι R M m = 0 := by rw [GradedAlgebra.ι_apply, DirectSum.of_mul_of] exact DFinsupp.single_eq_zero.mpr (Subtype.ext <| ExteriorAlgebra.ι_sq_zero _) /-- `ExteriorAlgebra.GradedAlgebra.ι` lifted to exterior algebra. This is primarily an auxiliary construction used to provide `ExteriorAlgebra.gradedAlgebra`. -/ def GradedAlgebra.liftι : ExteriorAlgebra R M →ₐ[R] ⨁ i : ℕ, ⋀[R]^i M := lift R ⟨by apply GradedAlgebra.ι R M, GradedAlgebra.ι_sq_zero R M⟩ theorem GradedAlgebra.liftι_eq (i : ℕ) (x : ⋀[R]^i M) : GradedAlgebra.liftι R M x = DirectSum.of (fun i => ⋀[R]^i M) i x := by obtain ⟨x, hx⟩ := x dsimp only [Subtype.coe_mk, DirectSum.lof_eq_of] induction hx using Submodule.pow_induction_on_left' with | algebraMap => simp_rw [AlgHom.commutes, DirectSum.algebraMap_apply]; rfl | add _ _ _ _ _ ihx ihy => simp_rw [map_add, ihx, ihy, ← AddMonoidHom.map_add]; rfl | mem_mul _ hm _ _ _ ih => obtain ⟨_, rfl⟩ := hm simp_rw [map_mul, ih, GradedAlgebra.liftι, lift_ι_apply, GradedAlgebra.ι_apply R M, DirectSum.of_mul_of] exact DirectSum.of_eq_of_gradedMonoid_eq (Sigma.subtype_ext (add_comm _ _) rfl) /-- The exterior algebra is graded by the powers of the submodule `(ExteriorAlgebra.ι R).range`. -/ instance gradedAlgebra : GradedAlgebra (fun i : ℕ ↦ ⋀[R]^i M) := GradedAlgebra.ofAlgHom _ (-- while not necessary, the `by apply` makes this elaborate faster by apply GradedAlgebra.liftι R M) -- the proof from here onward is identical to the `TensorAlgebra` case (by ext m dsimp only [LinearMap.comp_apply, AlgHom.toLinearMap_apply, AlgHom.comp_apply, AlgHom.id_apply, GradedAlgebra.liftι] rw [lift_ι_apply, GradedAlgebra.ι_apply R M, DirectSum.coeAlgHom_of, Subtype.coe_mk]) (by apply GradedAlgebra.liftι_eq R M) /-- The union of the images of the maps `ExteriorAlgebra.ιMulti R n` for `n` running through all natural numbers spans the exterior algebra. -/ lemma ιMulti_span : Submodule.span R (Set.range fun x : Σ n, (Fin n → M) => ιMulti R x.1 x.2) = ⊤ := by rw [Submodule.eq_top_iff'] intro x induction x using DirectSum.Decomposition.inductionOn fun i => ⋀[R]^i M with | zero => exact Submodule.zero_mem _ | add _ _ hm hm' => exact Submodule.add_mem _ hm hm' | homogeneous hm => let ⟨m, hm⟩ := hm apply Set.mem_of_mem_of_subset hm rw [← ιMulti_span_fixedDegree] refine Submodule.span_mono fun _ hx ↦ ?_ obtain ⟨y, rfl⟩ := hx exact ⟨⟨_, y⟩, rfl⟩ end ExteriorAlgebra
.lake/packages/mathlib/Mathlib/LinearAlgebra/ExteriorAlgebra/OfAlternating.lean
import Mathlib.LinearAlgebra.CliffordAlgebra.Fold import Mathlib.LinearAlgebra.ExteriorAlgebra.Basic /-! # Extending an alternating map to the exterior algebra ## Main definitions * `ExteriorAlgebra.liftAlternating`: construct a linear map out of the exterior algebra given alternating maps (corresponding to maps out of the exterior powers). * `ExteriorAlgebra.liftAlternatingEquiv`: the above as a linear equivalence ## Main results * `ExteriorAlgebra.lhom_ext`: linear maps from the exterior algebra agree if they agree on the exterior powers. -/ variable {R M N N' : Type*} variable [CommRing R] [AddCommGroup M] [AddCommGroup N] [AddCommGroup N'] variable [Module R M] [Module R N] [Module R N'] -- This instance can't be found where it's needed if we don't remind lean that it exists. instance AlternatingMap.instModuleAddCommGroup {ι : Type*} : Module R (M [⋀^ι]→ₗ[R] N) := by infer_instance namespace ExteriorAlgebra open CliffordAlgebra hiding ι /-- Build a map out of the exterior algebra given a collection of alternating maps acting on each exterior power -/ def liftAlternating : (∀ i, M [⋀^Fin i]→ₗ[R] N) →ₗ[R] ExteriorAlgebra R M →ₗ[R] N := by suffices (∀ i, M [⋀^Fin i]→ₗ[R] N) →ₗ[R] ExteriorAlgebra R M →ₗ[R] ∀ i, M [⋀^Fin i]→ₗ[R] N by refine LinearMap.compr₂ this ?_ refine (LinearEquiv.toLinearMap ?_).comp (LinearMap.proj 0) exact AlternatingMap.constLinearEquivOfIsEmpty.symm refine CliffordAlgebra.foldl _ ?_ ?_ · refine LinearMap.mk₂ R (fun m f i => (f i.succ).curryLeft m) (fun m₁ m₂ f => ?_) (fun c m f => ?_) (fun m f₁ f₂ => ?_) fun c m f => ?_ all_goals ext i : 1 simp only [map_smul, map_add, Pi.add_apply, Pi.smul_apply, AlternatingMap.curryLeft_add, AlternatingMap.curryLeft_smul, map_add, map_smul, LinearMap.add_apply, LinearMap.smul_apply] · -- when applied twice with the same `m`, this recursive step produces 0 intro m x ext simp @[simp] theorem liftAlternating_ι (f : ∀ i, M [⋀^Fin i]→ₗ[R] N) (m : M) : liftAlternating (R := R) (M := M) (N := N) f (ι R m) = f 1 ![m] := by dsimp [liftAlternating] rw [foldl_ι, LinearMap.mk₂_apply, AlternatingMap.curryLeft_apply_apply] congr! theorem liftAlternating_ι_mul (f : ∀ i, M [⋀^Fin i]→ₗ[R] N) (m : M) (x : ExteriorAlgebra R M) : liftAlternating (R := R) (M := M) (N := N) f (ι R m * x) = liftAlternating (R := R) (M := M) (N := N) (fun i => (f i.succ).curryLeft m) x := by dsimp [liftAlternating] rw [foldl_mul, foldl_ι] rfl @[simp] theorem liftAlternating_one (f : ∀ i, M [⋀^Fin i]→ₗ[R] N) : liftAlternating (R := R) (M := M) (N := N) f (1 : ExteriorAlgebra R M) = f 0 0 := by dsimp [liftAlternating] rw [foldl_one] @[simp] theorem liftAlternating_algebraMap (f : ∀ i, M [⋀^Fin i]→ₗ[R] N) (r : R) : liftAlternating (R := R) (M := M) (N := N) f (algebraMap _ (ExteriorAlgebra R M) r) = r • f 0 0 := by rw [Algebra.algebraMap_eq_smul_one, map_smul, liftAlternating_one] @[simp] theorem liftAlternating_apply_ιMulti {n : ℕ} (f : ∀ i, M [⋀^Fin i]→ₗ[R] N) (v : Fin n → M) : liftAlternating (R := R) (M := M) (N := N) f (ιMulti R n v) = f n v := by rw [ιMulti_apply] induction n generalizing f with | zero => rw [List.ofFn_zero, List.prod_nil, liftAlternating_one, Subsingleton.elim 0 v] | succ n ih => rw [List.ofFn_succ, List.prod_cons, liftAlternating_ι_mul, ih, AlternatingMap.curryLeft_apply_apply] congr exact Matrix.cons_head_tail _ @[simp] theorem liftAlternating_comp_ιMulti {n : ℕ} (f : ∀ i, M [⋀^Fin i]→ₗ[R] N) : (liftAlternating (R := R) (M := M) (N := N) f).compAlternatingMap (ιMulti R n) = f n := AlternatingMap.ext <| liftAlternating_apply_ιMulti f @[simp] theorem liftAlternating_comp (g : N →ₗ[R] N') (f : ∀ i, M [⋀^Fin i]→ₗ[R] N) : (liftAlternating (R := R) (M := M) (N := N') fun i => g.compAlternatingMap (f i)) = g ∘ₗ liftAlternating (R := R) (M := M) (N := N) f := by ext v rw [LinearMap.comp_apply] induction v using CliffordAlgebra.left_induction generalizing f with | algebraMap => rw [liftAlternating_algebraMap, liftAlternating_algebraMap, map_smul, LinearMap.compAlternatingMap_apply] | add _ _ hx hy => rw [map_add, map_add, map_add, hx, hy] | ι_mul _ _ hx => rw [liftAlternating_ι_mul, liftAlternating_ι_mul, ← hx] simp_rw [AlternatingMap.curryLeft_compAlternatingMap] @[simp] theorem liftAlternating_ιMulti : liftAlternating (R := R) (M := M) (N := ExteriorAlgebra R M) (ιMulti R) = (LinearMap.id : ExteriorAlgebra R M →ₗ[R] ExteriorAlgebra R M) := by ext v dsimp induction v using CliffordAlgebra.left_induction with | algebraMap => rw [liftAlternating_algebraMap, ιMulti_zero_apply, Algebra.algebraMap_eq_smul_one] | add _ _ hx hy => rw [map_add, hx, hy] | ι_mul _ _ hx => simp_rw [liftAlternating_ι_mul, ιMulti_succ_curryLeft, liftAlternating_comp, LinearMap.comp_apply, LinearMap.mulLeft_apply, hx] /-- `ExteriorAlgebra.liftAlternating` is an equivalence. -/ @[simps apply symm_apply] def liftAlternatingEquiv : (∀ i, M [⋀^Fin i]→ₗ[R] N) ≃ₗ[R] ExteriorAlgebra R M →ₗ[R] N where toFun := liftAlternating (R := R) map_add' := map_add _ map_smul' := map_smul _ invFun F i := F.compAlternatingMap (ιMulti R i) left_inv _ := funext fun _ => liftAlternating_comp_ιMulti _ right_inv F := (liftAlternating_comp _ _).trans <| by rw [liftAlternating_ιMulti, LinearMap.comp_id] /-- To show that two linear maps from the exterior algebra agree, it suffices to show they agree on the exterior powers. See note [partially-applied ext lemmas] -/ @[ext] theorem lhom_ext ⦃f g : ExteriorAlgebra R M →ₗ[R] N⦄ (h : ∀ i, f.compAlternatingMap (ιMulti R i) = g.compAlternatingMap (ιMulti R i)) : f = g := liftAlternatingEquiv.symm.injective <| funext h end ExteriorAlgebra
.lake/packages/mathlib/Mathlib/LinearAlgebra/Projectivization/Independence.lean
import Mathlib.LinearAlgebra.Projectivization.Basic /-! # Independence in Projective Space In this file we define independence and dependence of families of elements in projective space. ## Implementation Details We use an inductive definition to define the independence of points in projective space, where the only constructor assumes an independent family of vectors from the ambient vector space. Similarly for the definition of dependence. ## Results - A family of elements is dependent if and only if it is not independent. - Two elements are dependent if and only if they are equal. ## Future Work - Define collinearity in projective space. - Prove the axioms of a projective geometry are satisfied by the dependence relation. - Define projective linear subspaces. -/ open scoped LinearAlgebra.Projectivization variable {ι K V : Type*} [DivisionRing K] [AddCommGroup V] [Module K V] {f : ι → ℙ K V} namespace Projectivization /-- A linearly independent family of nonzero vectors gives an independent family of points in projective space. -/ inductive Independent : (ι → ℙ K V) → Prop | mk (f : ι → V) (hf : ∀ i : ι, f i ≠ 0) (hl : LinearIndependent K f) : Independent fun i => mk K (f i) (hf i) /-- A family of points in a projective space is independent if and only if the representative vectors determined by the family are linearly independent. -/ theorem independent_iff : Independent f ↔ LinearIndependent K (Projectivization.rep ∘ f) := by refine ⟨?_, fun h => ?_⟩ · rintro ⟨ff, hff, hh⟩ choose a ha using fun i : ι => exists_smul_eq_mk_rep K (ff i) (hff i) convert hh.units_smul a ext i exact (ha i).symm · convert Independent.mk _ _ h · simp only [mk_rep, Function.comp_apply] · intro i apply rep_nonzero /-- A family of points in projective space is independent if and only if the family of submodules which the points determine is independent in the lattice-theoretic sense. -/ theorem independent_iff_iSupIndep : Independent f ↔ iSupIndep fun i => (f i).submodule := by refine ⟨?_, fun h => ?_⟩ · rintro ⟨f, hf, hi⟩ simp only [submodule_mk] exact (iSupIndep_iff_linearIndependent_of_ne_zero (R := K) hf).mpr hi · rw [independent_iff] refine h.linearIndependent (Projectivization.submodule ∘ f) (fun i => ?_) fun i => ?_ · simpa only [Function.comp_apply, submodule_eq] using Submodule.mem_span_singleton_self _ · exact rep_nonzero (f i) /-- A linearly dependent family of nonzero vectors gives a dependent family of points in projective space. -/ inductive Dependent : (ι → ℙ K V) → Prop | mk (f : ι → V) (hf : ∀ i : ι, f i ≠ 0) (h : ¬LinearIndependent K f) : Dependent fun i => mk K (f i) (hf i) /-- A family of points in a projective space is dependent if and only if their representatives are linearly dependent. -/ theorem dependent_iff : Dependent f ↔ ¬LinearIndependent K (Projectivization.rep ∘ f) := by refine ⟨?_, fun h => ?_⟩ · rintro ⟨ff, hff, hh1⟩ contrapose! hh1 choose a ha using fun i : ι => exists_smul_eq_mk_rep K (ff i) (hff i) convert hh1.units_smul a⁻¹ ext i simp only [← ha, inv_smul_smul, Pi.smul_apply', Pi.inv_apply, Function.comp_apply] · convert Dependent.mk _ _ h · simp only [mk_rep, Function.comp_apply] · exact fun i => rep_nonzero (f i) /-- Dependence is the negation of independence. -/ theorem dependent_iff_not_independent : Dependent f ↔ ¬Independent f := by rw [dependent_iff, independent_iff] /-- Independence is the negation of dependence. -/ theorem independent_iff_not_dependent : Independent f ↔ ¬Dependent f := by rw [dependent_iff_not_independent, Classical.not_not] /-- Two points in a projective space are dependent if and only if they are equal. -/ @[simp] theorem dependent_pair_iff_eq (u v : ℙ K V) : Dependent ![u, v] ↔ u = v := by rw [dependent_iff_not_independent, independent_iff, linearIndependent_fin2] dsimp only [Function.comp_def, Matrix.cons_val] simp only [not_and, not_forall, not_not, ← mk_eq_mk_iff' K _ _ (rep_nonzero u) (rep_nonzero v), mk_rep, Classical.imp_iff_right_iff] exact Or.inl (rep_nonzero v) /-- Two points in a projective space are independent if and only if the points are not equal. -/ @[simp] theorem independent_pair_iff_ne (u v : ℙ K V) : Independent ![u, v] ↔ u ≠ v := by rw [independent_iff_not_dependent, dependent_pair_iff_eq u v] @[deprecated (since := "2025-04-27")] alias independent_pair_iff_neq := independent_pair_iff_ne end Projectivization
.lake/packages/mathlib/Mathlib/LinearAlgebra/Projectivization/Basic.lean
import Mathlib.LinearAlgebra.Dimension.FreeAndStrongRankCondition import Mathlib.LinearAlgebra.FiniteDimensional.Basic /-! # Projective Spaces This file contains the definition of the projectivization of a vector space over a field, as well as the bijection between said projectivization and the collection of all one dimensional subspaces of the vector space. ## Notation `ℙ K V` is localized notation for `Projectivization K V`, the projectivization of a `K`-vector space `V`. ## Constructing terms of `ℙ K V`. We have three ways to construct terms of `ℙ K V`: - `Projectivization.mk K v hv` where `v : V` and `hv : v ≠ 0`. - `Projectivization.mk' K v` where `v : { w : V // w ≠ 0 }`. - `Projectivization.mk'' H h` where `H : Submodule K V` and `h : finrank H = 1`. ## Other definitions - For `v : ℙ K V`, `v.submodule` gives the corresponding submodule of `V`. - `Projectivization.equivSubmodule` is the equivalence between `ℙ K V` and `{ H : Submodule K V // finrank H = 1 }`. - For `v : ℙ K V`, `v.rep : V` is a representative of `v`. -/ variable (K V : Type*) [DivisionRing K] [AddCommGroup V] [Module K V] /-- The setoid whose quotient is the projectivization of `V`. -/ def projectivizationSetoid : Setoid { v : V // v ≠ 0 } := (MulAction.orbitRel Kˣ V).comap (↑) /-- The projectivization of the `K`-vector space `V`. The notation `ℙ K V` is preferred. -/ def Projectivization := Quotient (projectivizationSetoid K V) /-- We define notations `ℙ K V` for the projectivization of the `K`-vector space `V`. -/ scoped[LinearAlgebra.Projectivization] notation "ℙ" => Projectivization namespace Projectivization open scoped LinearAlgebra.Projectivization variable {V} /-- Construct an element of the projectivization from a nonzero vector. -/ def mk (v : V) (hv : v ≠ 0) : ℙ K V := Quotient.mk'' ⟨v, hv⟩ /-- A variant of `Projectivization.mk` in terms of a subtype. `mk` is preferred. -/ def mk' (v : { v : V // v ≠ 0 }) : ℙ K V := Quotient.mk'' v @[simp] theorem mk'_eq_mk (v : { v : V // v ≠ 0 }) : mk' K v = mk K ↑v v.2 := rfl instance [Nontrivial V] : Nonempty (ℙ K V) := let ⟨v, hv⟩ := exists_ne (0 : V) ⟨mk K v hv⟩ variable {K} /-- A function on non-zero vectors which is independent of scale, descends to a function on the projectivization. -/ protected def lift {α : Type*} (f : { v : V // v ≠ 0 } → α) (hf : ∀ (a b : { v : V // v ≠ 0 }) (t : K), a = t • (b : V) → f a = f b) (x : ℙ K V) : α := Quotient.lift f (by rintro ⟨-, hv⟩ ⟨w, hw⟩ ⟨⟨t, -⟩, rfl⟩; exact hf ⟨_, hv⟩ ⟨w, hw⟩ t rfl) x @[simp] protected lemma lift_mk {α : Type*} (f : { v : V // v ≠ 0 } → α) (hf : ∀ (a b : { v : V // v ≠ 0 }) (t : K), a = t • (b : V) → f a = f b) (v : V) (hv : v ≠ 0) : Projectivization.lift f hf (mk K v hv) = f ⟨v, hv⟩ := rfl /-- Choose a representative of `v : Projectivization K V` in `V`. -/ protected noncomputable def rep (v : ℙ K V) : V := v.out theorem rep_nonzero (v : ℙ K V) : v.rep ≠ 0 := v.out.2 @[simp] theorem mk_rep (v : ℙ K V) : mk K v.rep v.rep_nonzero = v := Quotient.out_eq' _ open Module /-- Consider an element of the projectivization as a submodule of `V`. -/ protected def submodule (v : ℙ K V) : Submodule K V := (Quotient.liftOn' v fun v => K ∙ (v : V)) <| by rintro ⟨a, ha⟩ ⟨b, hb⟩ ⟨x, rfl : x • b = a⟩ exact Submodule.span_singleton_group_smul_eq _ x _ variable (K) theorem mk_eq_mk_iff (v w : V) (hv : v ≠ 0) (hw : w ≠ 0) : mk K v hv = mk K w hw ↔ ∃ a : Kˣ, a • w = v := Quotient.eq'' /-- Two nonzero vectors go to the same point in projective space if and only if one is a scalar multiple of the other. -/ theorem mk_eq_mk_iff' (v w : V) (hv : v ≠ 0) (hw : w ≠ 0) : mk K v hv = mk K w hw ↔ ∃ a : K, a • w = v := by rw [mk_eq_mk_iff K v w hv hw] constructor · rintro ⟨a, ha⟩ exact ⟨a, ha⟩ · rintro ⟨a, ha⟩ refine ⟨Units.mk0 a fun c => hv.symm ?_, ha⟩ rwa [c, zero_smul] at ha theorem exists_smul_eq_mk_rep (v : V) (hv : v ≠ 0) : ∃ a : Kˣ, a • v = (mk K v hv).rep := (mk_eq_mk_iff K _ _ (rep_nonzero _) hv).1 (mk_rep _) variable {K} /-- An induction principle for `Projectivization`. Use as `induction v`. -/ @[elab_as_elim, cases_eliminator, induction_eliminator] theorem ind {P : ℙ K V → Prop} (h : ∀ (v : V) (h : v ≠ 0), P (mk K v h)) : ∀ p, P p := Quotient.ind' <| Subtype.rec <| h @[simp] theorem submodule_mk (v : V) (hv : v ≠ 0) : (mk K v hv).submodule = K ∙ v := rfl theorem submodule_eq (v : ℙ K V) : v.submodule = K ∙ v.rep := by conv_lhs => rw [← v.mk_rep] rfl theorem finrank_submodule (v : ℙ K V) : finrank K v.submodule = 1 := by rw [submodule_eq] exact finrank_span_singleton v.rep_nonzero instance (v : ℙ K V) : FiniteDimensional K v.submodule := by rw [← v.mk_rep] change FiniteDimensional K (K ∙ v.rep) infer_instance theorem submodule_injective : Function.Injective (Projectivization.submodule : ℙ K V → Submodule K V) := fun u v h ↦ by induction u using ind with | h u hu => induction v using ind with | h v hv => rw [submodule_mk, submodule_mk, Submodule.span_singleton_eq_span_singleton] at h exact ((mk_eq_mk_iff K v u hv hu).2 h).symm variable (K V) /-- The equivalence between the projectivization and the collection of subspaces of dimension 1. -/ noncomputable def equivSubmodule : ℙ K V ≃ { H : Submodule K V // finrank K H = 1 } := (Equiv.ofInjective _ submodule_injective).trans <| .subtypeEquiv (.refl _) fun H ↦ by refine ⟨fun ⟨v, hv⟩ ↦ hv ▸ v.finrank_submodule, fun h ↦ ?_⟩ rcases finrank_eq_one_iff'.1 h with ⟨v : H, hv₀, hv : ∀ w : H, _⟩ use mk K (v : V) (Subtype.coe_injective.ne hv₀) rw [submodule_mk, SetLike.ext'_iff, Submodule.span_singleton_eq_range] refine (Set.range_subset_iff.2 fun _ ↦ H.smul_mem _ v.2).antisymm fun x hx ↦ ?_ rcases hv ⟨x, hx⟩ with ⟨c, hc⟩ exact ⟨c, congr_arg Subtype.val hc⟩ variable {K V} /-- Construct an element of the projectivization from a subspace of dimension 1. -/ noncomputable def mk'' (H : Submodule K V) (h : finrank K H = 1) : ℙ K V := (equivSubmodule K V).symm ⟨H, h⟩ @[simp] theorem submodule_mk'' (H : Submodule K V) (h : finrank K H = 1) : (mk'' H h).submodule = H := congr_arg Subtype.val <| (equivSubmodule K V).apply_symm_apply ⟨H, h⟩ @[simp] theorem mk''_submodule (v : ℙ K V) : mk'' v.submodule v.finrank_submodule = v := (equivSubmodule K V).symm_apply_apply v section Map variable {L W : Type*} [DivisionRing L] [AddCommGroup W] [Module L W] /-- An injective semilinear map of vector spaces induces a map on projective spaces. -/ def map {σ : K →+* L} (f : V →ₛₗ[σ] W) (hf : Function.Injective f) : ℙ K V → ℙ L W := Quotient.map' (fun v => ⟨f v, fun c => v.2 (hf (by simp [c]))⟩) (by rintro ⟨u, hu⟩ ⟨v, hv⟩ ⟨a, ha⟩ use Units.map σ.toMonoidHom a dsimp at ha ⊢ erw [← f.map_smulₛₗ, ha]) theorem map_mk {σ : K →+* L} (f : V →ₛₗ[σ] W) (hf : Function.Injective f) (v : V) (hv : v ≠ 0) : map f hf (mk K v hv) = mk L (f v) (map_zero f ▸ hf.ne hv) := rfl /-- Mapping with respect to a semilinear map over an isomorphism of fields yields an injective map on projective spaces. -/ theorem map_injective {σ : K →+* L} {τ : L →+* K} [RingHomInvPair σ τ] (f : V →ₛₗ[σ] W) (hf : Function.Injective f) : Function.Injective (map f hf) := fun u v h ↦ by induction u using ind with | h u hu => induction v using ind with | h v hv => simp only [map_mk, mk_eq_mk_iff'] at h ⊢ rcases h with ⟨a, ha⟩ refine ⟨τ a, hf ?_⟩ rwa [f.map_smulₛₗ, RingHomInvPair.comp_apply_eq₂] @[simp] theorem map_id : map (LinearMap.id : V →ₗ[K] V) (LinearEquiv.refl K V).injective = id := by ext ⟨v⟩ rfl @[simp] theorem map_comp {F U : Type*} [DivisionRing F] [AddCommGroup U] [Module F U] {σ : K →+* L} {τ : L →+* F} {γ : K →+* F} [RingHomCompTriple σ τ γ] (f : V →ₛₗ[σ] W) (hf : Function.Injective f) (g : W →ₛₗ[τ] U) (hg : Function.Injective g) (hgf : Function.Injective (g.comp f) := hg.comp hf) : map (g.comp f) hgf = map g hg ∘ map f hf := by ext ⟨v⟩ rfl end Map end Projectivization
.lake/packages/mathlib/Mathlib/LinearAlgebra/Projectivization/Subspace.lean
import Mathlib.LinearAlgebra.Projectivization.Basic /-! # Subspaces of Projective Space In this file we define subspaces of a projective space, and show that the subspaces of a projective space form a complete lattice under inclusion. ## Implementation Details A subspace of a projective space ℙ K V is defined to be a structure consisting of a subset of ℙ K V such that if two nonzero vectors in V determine points in ℙ K V which are in the subset, and the sum of the two vectors is nonzero, then the point determined by the sum of the two vectors is also in the subset. ## Results - There is a Galois insertion between the subsets of points of a projective space and the subspaces of the projective space, which is given by taking the span of the set of points. - The subspaces of a projective space form a complete lattice under inclusion. - There is a one-to-one order-preserving correspondence between subspaces of a projective space and the submodules of the underlying vector space. -/ variable (K V : Type*) [Field K] [AddCommGroup V] [Module K V] namespace Projectivization open scoped LinearAlgebra.Projectivization /-- A subspace of a projective space is a structure consisting of a set of points such that: If two nonzero vectors determine points which are in the set, and the sum of the two vectors is nonzero, then the point determined by the sum is also in the set. -/ @[ext] structure Subspace where /-- The set of points. -/ carrier : Set (ℙ K V) /-- The addition rule. -/ mem_add' (v w : V) (hv : v ≠ 0) (hw : w ≠ 0) (hvw : v + w ≠ 0) : mk K v hv ∈ carrier → mk K w hw ∈ carrier → mk K (v + w) hvw ∈ carrier namespace Subspace variable {K V} instance : SetLike (Subspace K V) (ℙ K V) where coe := carrier coe_injective' A B := by cases A cases B simp @[simp] theorem mem_carrier_iff (A : Subspace K V) (x : ℙ K V) : x ∈ A.carrier ↔ x ∈ A := Iff.refl _ theorem mem_add (T : Subspace K V) (v w : V) (hv : v ≠ 0) (hw : w ≠ 0) (hvw : v + w ≠ 0) : Projectivization.mk K v hv ∈ T → Projectivization.mk K w hw ∈ T → Projectivization.mk K (v + w) hvw ∈ T := T.mem_add' v w hv hw hvw /-- The span of a set of points in a projective space is defined inductively to be the set of points which contains the original set, and contains all points determined by the (nonzero) sum of two nonzero vectors, each of which determine points in the span. -/ inductive spanCarrier (S : Set (ℙ K V)) : Set (ℙ K V) | of (x : ℙ K V) (hx : x ∈ S) : spanCarrier S x | mem_add (v w : V) (hv : v ≠ 0) (hw : w ≠ 0) (hvw : v + w ≠ 0) : spanCarrier S (Projectivization.mk K v hv) → spanCarrier S (Projectivization.mk K w hw) → spanCarrier S (Projectivization.mk K (v + w) hvw) /-- The span of a set of points in projective space is a subspace. -/ def span (S : Set (ℙ K V)) : Subspace K V where carrier := spanCarrier S mem_add' v w hv hw hvw := spanCarrier.mem_add v w hv hw hvw /-- The span of a set of points contains the set of points. -/ theorem subset_span (S : Set (ℙ K V)) : S ⊆ span S := fun _x hx => spanCarrier.of _ hx /-- The span of a set of points is a Galois insertion between sets of points of a projective space and subspaces of the projective space. -/ def gi : GaloisInsertion (span : Set (ℙ K V) → Subspace K V) SetLike.coe where choice S _hS := span S gc A B := ⟨fun h => le_trans (subset_span _) h, by intro h x hx induction hx with | of => apply h; assumption | mem_add => apply B.mem_add; assumption'⟩ le_l_u _ := subset_span _ choice_eq _ _ := rfl /-- The span of a subspace is the subspace. -/ @[simp] theorem span_coe (W : Subspace K V) : span ↑W = W := GaloisInsertion.l_u_eq gi W /-- The infimum of two subspaces exists. -/ instance instInf : Min (Subspace K V) := ⟨fun A B => ⟨A ⊓ B, fun _v _w hv hw _hvw h1 h2 => ⟨A.mem_add _ _ hv hw _ h1.1 h2.1, B.mem_add _ _ hv hw _ h1.2 h2.2⟩⟩⟩ /-- Infimums of arbitrary collections of subspaces exist. -/ instance instInfSet : InfSet (Subspace K V) := ⟨fun A => ⟨sInf (SetLike.coe '' A), fun v w hv hw hvw h1 h2 t => by rintro ⟨s, hs, rfl⟩ exact s.mem_add v w hv hw _ (h1 s ⟨s, hs, rfl⟩) (h2 s ⟨s, hs, rfl⟩)⟩⟩ /-- The subspaces of a projective space form a complete lattice. -/ instance : CompleteLattice (Subspace K V) := { __ := completeLatticeOfInf (Subspace K V) (by refine fun s => ⟨fun a ha x hx => hx _ ⟨a, ha, rfl⟩, fun a ha x hx E => ?_⟩ rintro ⟨E, hE, rfl⟩ exact ha hE hx) inf_le_left := fun A B _ hx => (@inf_le_left _ _ A B) hx inf_le_right := fun A B _ hx => (@inf_le_right _ _ A B) hx le_inf := fun _ _ _ h1 h2 _ hx => (le_inf h1 h2) hx } instance subspaceInhabited : Inhabited (Subspace K V) where default := ⊤ /-- The span of the empty set is the bottom of the lattice of subspaces. -/ @[simp] theorem span_empty : span (∅ : Set (ℙ K V)) = ⊥ := gi.gc.l_bot /-- The span of the entire projective space is the top of the lattice of subspaces. -/ @[simp] theorem span_univ : span (Set.univ : Set (ℙ K V)) = ⊤ := by rw [eq_top_iff, SetLike.le_def] intro x _hx exact subset_span _ (Set.mem_univ x) /-- The span of a set of points is contained in a subspace if and only if the set of points is contained in the subspace. -/ theorem span_le_subspace_iff {S : Set (ℙ K V)} {W : Subspace K V} : span S ≤ W ↔ S ⊆ W := gi.gc S W /-- If a set of points is a subset of another set of points, then its span will be contained in the span of that set. -/ @[mono] theorem monotone_span : Monotone (span : Set (ℙ K V) → Subspace K V) := gi.gc.monotone_l @[gcongr] lemma span_le_span {s t : Set (ℙ K V)} (hst : s ⊆ t) : span s ≤ span t := monotone_span hst theorem subset_span_trans {S T U : Set (ℙ K V)} (hST : S ⊆ span T) (hTU : T ⊆ span U) : S ⊆ span U := gi.gc.le_u_l_trans hST hTU /-- The supremum of two subspaces is equal to the span of their union. -/ theorem span_union (S T : Set (ℙ K V)) : span (S ∪ T) = span S ⊔ span T := (@gi K V _ _ _).gc.l_sup /-- The supremum of a collection of subspaces is equal to the span of the union of the collection. -/ theorem span_iUnion {ι} (s : ι → Set (ℙ K V)) : span (⋃ i, s i) = ⨆ i, span (s i) := (@gi K V _ _ _).gc.l_iSup /-- The supremum of a subspace and the span of a set of points is equal to the span of the union of the subspace and the set of points. -/ theorem sup_span {S : Set (ℙ K V)} {W : Subspace K V} : W ⊔ span S = span (W ∪ S) := by rw [span_union, span_coe] theorem span_sup {S : Set (ℙ K V)} {W : Subspace K V} : span S ⊔ W = span (S ∪ W) := by rw [span_union, span_coe] /-- A point in a projective space is contained in the span of a set of points if and only if the point is contained in all subspaces of the projective space which contain the set of points. -/ theorem mem_span {S : Set (ℙ K V)} (u : ℙ K V) : u ∈ span S ↔ ∀ W : Subspace K V, S ⊆ W → u ∈ W := by simp_rw [← span_le_subspace_iff] exact ⟨fun hu W hW => hW hu, fun W => W (span S) (le_refl _)⟩ /-- The span of a set of points in a projective space is equal to the infimum of the collection of subspaces which contain the set. -/ theorem span_eq_sInf {S : Set (ℙ K V)} : span S = sInf { W : Subspace K V| S ⊆ W } := by ext x simp_rw [mem_carrier_iff, mem_span x] refine ⟨fun hx => ?_, fun hx W hW => ?_⟩ · rintro W ⟨T, hT, rfl⟩ exact hx T hT · exact (@sInf_le _ _ { W : Subspace K V | S ⊆ ↑W } W hW) hx /-- If a set of points in projective space is contained in a subspace, and that subspace is contained in the span of the set of points, then the span of the set of points is equal to the subspace. -/ theorem span_eq_of_le {S : Set (ℙ K V)} {W : Subspace K V} (hS : S ⊆ W) (hW : W ≤ span S) : span S = W := le_antisymm (span_le_subspace_iff.mpr hS) hW /-- The spans of two sets of points in a projective space are equal if and only if each set of points is contained in the span of the other set. -/ theorem span_eq_span_iff {S T : Set (ℙ K V)} : span S = span T ↔ S ⊆ span T ∧ T ⊆ span S := ⟨fun h => ⟨h ▸ subset_span S, h.symm ▸ subset_span T⟩, fun h => le_antisymm (span_le_subspace_iff.2 h.1) (span_le_subspace_iff.2 h.2)⟩ /-- The submodule corresponding to a projective subspace `s`, consisting of the representatives of points in `s` together with zero. This is the inverse of `Submodule.projectivization`. -/ def submodule : Projectivization.Subspace K V ≃o Submodule K V where toFun s := { carrier := {x | (h : x ≠ 0) → Projectivization.mk K x h ∈ s.carrier} add_mem' {x y} hx₁ hy₁ := by rcases eq_or_ne x 0 with rfl | hx₂ · rwa [zero_add] rcases eq_or_ne y 0 with rfl | hy₂ · rwa [add_zero] intro hxy exact s.mem_add _ _ hx₂ hy₂ hxy (hx₁ hx₂) (hy₁ hy₂) zero_mem' h := h.irrefl.elim smul_mem' c x h₁ h₂ := by convert h₁ (right_ne_zero_of_smul h₂) using 1 rw [Projectivization.mk_eq_mk_iff'] exact ⟨c, rfl⟩ } invFun s := { carrier := setOf <| Projectivization.lift (↑· ∈ s) <| by rintro ⟨-, h⟩ ⟨y, -⟩ c rfl exact Iff.eq <| s.smul_mem_iff <| left_ne_zero_of_smul h mem_add' _ _ _ _ _ h₁ h₂ := s.add_mem h₁ h₂ } left_inv s := by ext ⟨x, hx⟩ exact ⟨fun h => h hx, fun h _ => h⟩ right_inv s := by ext x suffices x = 0 → x ∈ s by simpa [imp_iff_not_or] rintro rfl exact s.zero_mem map_rel_iff'.mp h₁ := Projectivization.ind fun _ hx h₂ => h₁ (fun _ => h₂) hx map_rel_iff'.mpr h₁ _ h₂ hx := h₁ <| h₂ hx @[simp] theorem mem_submodule_iff (s : Projectivization.Subspace K V) {v : V} (hv : v ≠ 0) : v ∈ submodule s ↔ Projectivization.mk K v hv ∈ s := ⟨fun h => h hv, fun h _ => h⟩ end Subspace end Projectivization namespace Submodule open scoped LinearAlgebra.Projectivization variable {K V} /-- The projective subspace corresponding to a submodule `s`, consisting of the one-dimensional subspaces of `s`. This is the inverse of `Projectivization.Subspace.submodule`. -/ abbrev projectivization : Submodule K V ≃o Projectivization.Subspace K V := Projectivization.Subspace.submodule.symm @[simp] theorem mk_mem_projectivization_iff (s : Submodule K V) {v : V} (hv : v ≠ 0) : Projectivization.mk K v hv ∈ s.projectivization ↔ v ∈ s := Iff.rfl theorem mem_projectivization_iff_submodule_le (s : Submodule K V) (x : ℙ K V) : x ∈ s.projectivization ↔ x.submodule ≤ s := by cases x rw [mk_mem_projectivization_iff, Projectivization.submodule_mk, Submodule.span_singleton_le_iff_mem] end Submodule
.lake/packages/mathlib/Mathlib/LinearAlgebra/Projectivization/Cardinality.lean
import Mathlib.Algebra.Ring.GeomSum import Mathlib.Data.Finite.Sum import Mathlib.Data.Fintype.Units import Mathlib.GroupTheory.GroupAction.Quotient import Mathlib.LinearAlgebra.Projectivization.Basic /-! # Cardinality of projective spaces We compute the cardinality of `ℙ k V` if `k` is a finite field. -/ namespace Projectivization open scoped LinearAlgebra.Projectivization section variable (k V : Type*) [DivisionRing k] [AddCommGroup V] [Module k V] /-- `ℙ k V` is equivalent to the quotient of the non-zero elements of `V` by `kˣ`. -/ def equivQuotientOrbitRel : ℙ k V ≃ Quotient (MulAction.orbitRel kˣ { v : V // v ≠ 0 }) := Quotient.congr (Equiv.refl _) (fun x y ↦ (Units.orbitRel_nonZero_iff k V x y).symm) /-- The non-zero elements of `V` are equivalent to the product of `ℙ k V` with the units of `k`. -/ noncomputable def nonZeroEquivProjectivizationProdUnits : { v : V // v ≠ 0 } ≃ ℙ k V × kˣ := let e := MulAction.selfEquivOrbitsQuotientProd <| fun b ↦ by rw [(Units.nonZeroSubMul k V).stabilizer_of_subMul, Module.stabilizer_units_eq_bot_of_ne_zero k b.property] e.trans (Equiv.prodCongrLeft (fun _ ↦ (equivQuotientOrbitRel k V).symm)) instance isEmpty_of_subsingleton [Subsingleton V] : IsEmpty (ℙ k V) := by have : IsEmpty { v : V // v ≠ 0 } := ⟨fun v ↦ v.2 (Subsingleton.elim v.1 0)⟩ simpa using (nonZeroEquivProjectivizationProdUnits k V).symm.isEmpty /-- If `V` is a finite `k`-module and `k` is finite, `ℙ k V` is finite. -/ instance finite_of_finite [Finite V] : Finite (ℙ k V) := have : Finite (ℙ k V × kˣ) := Finite.of_equiv _ (nonZeroEquivProjectivizationProdUnits k V) Finite.prod_left kˣ lemma finite_iff_of_finite [Finite k] : Finite (ℙ k V) ↔ Finite V := by classical refine ⟨fun h ↦ ?_, fun h ↦ inferInstance⟩ let e := nonZeroEquivProjectivizationProdUnits k V have : Finite { v : V // v ≠ 0 } := Finite.of_equiv _ e.symm let eq : { v : V // v ≠ 0 } ⊕ Unit ≃ V := ⟨(Sum.elim Subtype.val (fun _ ↦ 0)), fun v ↦ if h : v = 0 then Sum.inr () else Sum.inl ⟨v, h⟩, by intro x; aesop, by intro x; aesop⟩ exact Finite.of_equiv _ eq /-- Fraction free cardinality formula for the points of `ℙ k V` if `k` and `V` are finite (for silly reasons the formula also holds when `k` and `V` are infinite). See `Projectivization.card'` and `Projectivization.card''` for other spellings of the formula. -/ lemma card : Nat.card V - 1 = Nat.card (ℙ k V) * (Nat.card k - 1) := by nontriviality V cases finite_or_infinite k with | inr h => have : Infinite V := Module.Free.infinite k V simp | inl h => cases finite_or_infinite V with | inr h => have := not_iff_not.mpr (finite_iff_of_finite k V) push_neg at this have : Infinite (ℙ k V) := by rwa [this] simp | inl h => classical haveI : Fintype V := Fintype.ofFinite V haveI : Fintype (ℙ k V) := Fintype.ofFinite (ℙ k V) haveI : Fintype k := Fintype.ofFinite k have hV : Fintype.card { v : V // v ≠ 0 } = Fintype.card V - 1 := by simp simp_rw [← Fintype.card_eq_nat_card, ← Fintype.card_units (α := k), ← hV] rw [Fintype.card_congr (nonZeroEquivProjectivizationProdUnits k V), Fintype.card_prod] /-- Cardinality formula for the points of `ℙ k V` if `k` and `V` are finite with less natural subtraction. -/ lemma card' [Finite V] : Nat.card V = Nat.card (ℙ k V) * (Nat.card k - 1) + 1 := by rw [← card k V] have : Nat.card V > 0 := Nat.card_pos cutsat end variable (k V : Type*) [Field k] [AddCommGroup V] [Module k V] /-- Cardinality formula for the points of `ℙ k V` if `k` and `V` are finite expressed as a fraction. -/ lemma card'' [Finite k] : Nat.card (ℙ k V) = (Nat.card V - 1) / (Nat.card k - 1) := by have : 1 < Nat.card k := Finite.one_lt_card rw [card k, Nat.mul_div_cancel] cutsat lemma card_of_finrank [Finite k] {n : ℕ} (h : Module.finrank k V = n) : Nat.card (ℙ k V) = ∑ i ∈ Finset.range n, Nat.card k ^ i := by wlog hf : Finite V · have : Infinite (ℙ k V) := by contrapose! hf rwa [finite_iff_of_finite] at hf have : n = 0 := by rw [← h] apply Module.finrank_of_not_finite contrapose! hf simpa using Module.finite_of_finite k simp [this] have : 1 < Nat.card k := Finite.one_lt_card refine Nat.mul_right_cancel (m := Nat.card k - 1) (by cutsat) ?_ let e : V ≃ₗ[k] (Fin n → k) := LinearEquiv.ofFinrankEq _ _ (by simpa) have hc : Nat.card V = Nat.card k ^ n := by simp [Nat.card_congr e.toEquiv, Nat.card_fun] zify conv_rhs => rw [Int.natCast_sub this.le, Int.natCast_one, geom_sum_mul] rw [← Int.natCast_mul, ← card k V, hc] simp lemma card_of_finrank_two [Finite k] (h : Module.finrank k V = 2) : Nat.card (ℙ k V) = Nat.card k + 1 := by simp [card_of_finrank k V h] end Projectivization
.lake/packages/mathlib/Mathlib/LinearAlgebra/Projectivization/Constructions.lean
import Mathlib.LinearAlgebra.CrossProduct import Mathlib.LinearAlgebra.Matrix.DotProduct import Mathlib.LinearAlgebra.Projectivization.Basic /-! # Dot Product and Cross Product on Projective Spaces This file defines the dot product and cross product on projective spaces. ## Definitions - `Projectivization.orthogonal v w` is defined as vanishing of the dot product. - `Projectivization.cross v w` for `v w : ℙ F (Fin 3 → F)` is defined as the cross product of `v` and `w` provided that `v ≠ w`. If `v = w`, then the cross product would be zero, so we instead define `cross v v = v`. -/ variable {F : Type*} [Field F] {m : Type*} [Fintype m] namespace Projectivization open scoped LinearAlgebra.Projectivization section DotProduct /-- Orthogonality on the projective plane. -/ def orthogonal : ℙ F (m → F) → ℙ F (m → F) → Prop := Quotient.lift₂ (fun v w ↦ v.1 ⬝ᵥ w.1 = 0) (fun _ _ _ _ ⟨_, h1⟩ ⟨_, h2⟩ ↦ by simp_rw [← h1, ← h2, dotProduct_smul, smul_dotProduct, smul_smul, smul_eq_zero_iff_eq]) lemma orthogonal_mk {v w : m → F} (hv : v ≠ 0) (hw : w ≠ 0) : orthogonal (mk F v hv) (mk F w hw) ↔ v ⬝ᵥ w = 0 := Iff.rfl lemma orthogonal_comm {v w : ℙ F (m → F)} : orthogonal v w ↔ orthogonal w v := by induction v with | h v hv => induction w with | h w hw => rw [orthogonal_mk hv hw, orthogonal_mk hw hv, dotProduct_comm] lemma exists_not_self_orthogonal (v : ℙ F (m → F)) : ∃ w, ¬ orthogonal v w := by induction v with | h v hv => rw [ne_eq, ← dotProduct_eq_zero_iff, not_forall] at hv obtain ⟨w, hw⟩ := hv exact ⟨mk F w fun h ↦ hw (by rw [h, dotProduct_zero]), hw⟩ lemma exists_not_orthogonal_self (v : ℙ F (m → F)) : ∃ w, ¬ orthogonal w v := by simp only [orthogonal_comm] exact exists_not_self_orthogonal v end DotProduct section CrossProduct lemma mk_eq_mk_iff_crossProduct_eq_zero {v w : Fin 3 → F} (hv : v ≠ 0) (hw : w ≠ 0) : mk F v hv = mk F w hw ↔ crossProduct v w = 0 := by rw [← not_iff_not, mk_eq_mk_iff', not_exists, ← LinearIndependent.pair_iff' hw, ← crossProduct_ne_zero_iff_linearIndependent, ← cross_anticomm, neg_ne_zero] variable [DecidableEq F] /-- Cross product on the projective plane. -/ def cross : ℙ F (Fin 3 → F) → ℙ F (Fin 3 → F) → ℙ F (Fin 3 → F) := Quotient.map₂ (fun v w ↦ if h : crossProduct v.1 w.1 = 0 then v else ⟨crossProduct v.1 w.1, h⟩) (fun _ _ ⟨a, ha⟩ _ _ ⟨b, hb⟩ ↦ by simp_rw [← ha, ← hb, LinearMap.map_smul_of_tower, LinearMap.smul_apply, smul_smul, mul_comm b a, smul_eq_zero_iff_eq] split_ifs · use a · use a * b) lemma cross_mk {v w : Fin 3 → F} (hv : v ≠ 0) (hw : w ≠ 0) : cross (mk F v hv) (mk F w hw) = if h : crossProduct v w = 0 then mk F v hv else mk F (crossProduct v w) h := by change Quotient.mk'' _ = _ split_ifs with h <;> simp only [h] <;> rfl lemma cross_mk_of_cross_eq_zero {v w : Fin 3 → F} (hv : v ≠ 0) (hw : w ≠ 0) (h : crossProduct v w = 0) : cross (mk F v hv) (mk F w hw) = mk F v hv := by rw [cross_mk, dif_pos h] lemma cross_mk_of_cross_ne_zero {v w : Fin 3 → F} (hv : v ≠ 0) (hw : w ≠ 0) (h : crossProduct v w ≠ 0) : cross (mk F v hv) (mk F w hw) = mk F (crossProduct v w) h := by rw [cross_mk, dif_neg h] lemma cross_self (v : ℙ F (Fin 3 → F)) : cross v v = v := by induction v with | h v hv => rw [cross_mk_of_cross_eq_zero] rw [← mk_eq_mk_iff_crossProduct_eq_zero hv] lemma cross_mk_of_ne {v w : Fin 3 → F} (hv : v ≠ 0) (hw : w ≠ 0) (h : mk F v hv ≠ mk F w hw) : cross (mk F v hv) (mk F w hw) = mk F (crossProduct v w) (mt (mk_eq_mk_iff_crossProduct_eq_zero hv hw).mpr h) := by rw [cross_mk_of_cross_ne_zero] lemma cross_comm (v w : ℙ F (Fin 3 → F)) : cross v w = cross w v := by rcases eq_or_ne v w with rfl | h · rfl · induction v with | h v hv => induction w with | h w hw => rw [cross_mk_of_ne hv hw h, cross_mk_of_ne hw hv h.symm, mk_eq_mk_iff_crossProduct_eq_zero, ← cross_anticomm v w, map_neg, _root_.cross_self, neg_zero] theorem cross_orthogonal_left {v w : ℙ F (Fin 3 → F)} (h : v ≠ w) : (cross v w).orthogonal v := by induction v with | h v hv => induction w with | h w hw => rw [cross_mk_of_ne hv hw h, orthogonal_mk, dotProduct_comm, dot_self_cross] theorem cross_orthogonal_right {v w : ℙ F (Fin 3 → F)} (h : v ≠ w) : (cross v w).orthogonal w := by rw [cross_comm] exact cross_orthogonal_left h.symm theorem orthogonal_cross_left {v w : ℙ F (Fin 3 → F)} (h : v ≠ w) : v.orthogonal (cross v w) := by rw [orthogonal_comm] exact cross_orthogonal_left h lemma orthogonal_cross_right {v w : ℙ F (Fin 3 → F)} (h : v ≠ w) : w.orthogonal (cross v w) := by rw [orthogonal_comm] exact cross_orthogonal_right h end CrossProduct end Projectivization
.lake/packages/mathlib/Mathlib/LinearAlgebra/Projectivization/Action.lean
import Mathlib.LinearAlgebra.Projectivization.Basic import Mathlib.GroupTheory.GroupAction.Ring /-! # Group actions on projectivization Show that (among other groups), the general linear group of `V` acts on `ℙ K V`. -/ open scoped LinearAlgebra.Projectivization Matrix namespace Projectivization section DivisionRing variable {G K V : Type*} [AddCommGroup V] [DivisionRing K] [Module K V] [Group G] [DistribMulAction G V] [SMulCommClass G K V] /-- Any group acting `K`-linearly on `V` (such as the general linear group) acts on `ℙ V`. -/ @[simps -isSimp] instance : MulAction G (ℙ K V) where smul g x := x.map (DistribMulAction.toModuleEnd _ _ g) (DistribMulAction.toLinearEquiv _ _ g).injective one_smul x := show map _ _ _ = _ by simp [map_one, Module.End.one_eq_id] mul_smul g g' x := show map _ _ _ = map _ _ (map _ _ _) by simp_rw [map_mul, Module.End.mul_eq_comp] rw [map_comp, Function.comp_apply] lemma generalLinearGroup_smul_def (g : LinearMap.GeneralLinearGroup K V) (x : ℙ K V) : g • x = x.map g.toLinearEquiv.toLinearMap g.toLinearEquiv.injective := by rfl @[simp] lemma smul_mk (g : G) {v : V} (hv : v ≠ 0) : g • mk K v hv = mk K (g • v) ((smul_ne_zero_iff_ne g).mpr hv) := rfl end DivisionRing end Projectivization
.lake/packages/mathlib/Mathlib/LinearAlgebra/Finsupp/LSum.lean
import Mathlib.Algebra.BigOperators.GroupWithZero.Action import Mathlib.Algebra.Module.Equiv.Basic import Mathlib.Algebra.Module.Submodule.LinearMap import Mathlib.LinearAlgebra.Finsupp.Defs import Mathlib.Tactic.ApplyFun /-! # Sums as a linear map Given an `R`-module `M`, the `R`-module structure on `α →₀ M` is defined in `Data.Finsupp.Basic`. ## Main definitions * `Finsupp.lsum`: `Finsupp.sum` or `Finsupp.liftAddHom` as a `LinearMap`; ## Tags function with finite support, module, linear algebra -/ noncomputable section open Set LinearMap Submodule namespace Finsupp section SMul variable {α : Type*} {β : Type*} {R R₂ : Type*} {M M₂ : Type*} theorem smul_sum [Zero β] [AddCommMonoid M] [DistribSMul R M] {v : α →₀ β} {c : R} {h : α → β → M} : c • v.sum h = v.sum fun a b => c • h a b := Finset.smul_sum @[simp] theorem sum_smul_index_semilinearMap' [Semiring R] [Semiring R₂] [AddCommMonoid M] [Module R M] [AddCommMonoid M₂] [Module R₂ M₂] {σ : R →+* R₂} {v : α →₀ M} {c : R} {h : α → M →ₛₗ[σ] M₂} : ((c • v).sum fun a => h a) = σ c • v.sum fun a => h a := by rw [Finsupp.sum_smul_index', Finsupp.smul_sum] · simp only [map_smulₛₗ] · intro i exact (h i).map_zero theorem sum_smul_index_linearMap' [Semiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid M₂] [Module R M₂] {v : α →₀ M} {c : R} {h : α → M →ₗ[R] M₂} : ((c • v).sum fun a => h a) = c • v.sum fun a => h a := sum_smul_index_semilinearMap' end SMul variable {α : Type*} {M N P : Type*} {R R₂ R₃ : Type*} {S : Type*} variable [Semiring R] [Semiring R₂] [Semiring R₃] [Semiring S] variable [AddCommMonoid M] [Module R M] variable [AddCommMonoid N] [Module R₂ N] variable [AddCommMonoid P] [Module R₃ P] variable {σ : R →+* R₂} {σ_inv : R₂ →+* R} section CompatibleSMul variable (R S M N ι : Type*) variable [Semiring S] [AddCommMonoid M] [AddCommMonoid N] [Module S M] [Module S N] instance _root_.LinearMap.CompatibleSMul.finsupp_dom [SMulZeroClass R M] [DistribSMul R N] [LinearMap.CompatibleSMul M N R S] : LinearMap.CompatibleSMul (ι →₀ M) N R S where map_smul f r m := by conv_rhs => rw [← sum_single m, map_finsuppSum, smul_sum] erw [← sum_single (r • m), sum_mapRange_index single_zero, map_finsuppSum] congr; ext i m; exact (f.comp <| lsingle i).map_smul_of_tower r m instance _root_.LinearMap.CompatibleSMul.finsupp_cod [SMul R M] [SMulZeroClass R N] [LinearMap.CompatibleSMul M N R S] : LinearMap.CompatibleSMul M (ι →₀ N) R S where map_smul f r m := by ext i; apply ((lapply i).comp f).map_smul_of_tower end CompatibleSMul section LSum variable (S) variable [Module S N] [SMulCommClass R₂ S N] /-- Lift a family of linear maps `M →ₗ[R] N` indexed by `x : α` to a linear map from `α →₀ M` to `N` using `Finsupp.sum`. This is an upgraded version of `Finsupp.liftAddHom`. See note [bundled maps over different rings] for why separate `R` and `S` semirings are used. -/ def lsum : (α → M →ₛₗ[σ] N) ≃ₗ[S] (α →₀ M) →ₛₗ[σ] N where toFun F := { toFun := fun d => d.sum fun i => F i map_add' := (liftAddHom (α := α) (M := M) (N := N) fun x => (F x).toAddMonoidHom).map_add map_smul' := fun c f => by simp [sum_smul_index', smul_sum] } invFun F x := F.comp (lsingle x) left_inv F := by ext x y simp right_inv F := by ext x y simp map_add' F G := by ext x y simp map_smul' F G := by ext x y simp @[simp] theorem coe_lsum (f : α → M →ₛₗ[σ] N) : (lsum S f : (α →₀ M) → N) = fun d => d.sum fun i => f i := rfl theorem lsum_apply (f : α → M →ₛₗ[σ] N) (l : α →₀ M) : Finsupp.lsum S f l = l.sum fun b => f b := rfl theorem lsum_single (f : α → M →ₛₗ[σ] N) (i : α) (m : M) : Finsupp.lsum S f (Finsupp.single i m) = f i m := Finsupp.sum_single_index (f i).map_zero @[simp] theorem lsum_comp_lsingle (f : α → M →ₛₗ[σ] N) (i : α) : Finsupp.lsum S f ∘ₛₗ lsingle i = f i := by ext; simp theorem lsum_symm_apply (f : (α →₀ M) →ₛₗ[σ] N) (x : α) : (lsum S).symm f x = f.comp (lsingle x) := rfl end LSum section variable (M) (R) (X : Type*) (S) variable [Module S M] [SMulCommClass R S M] /-- A slight rearrangement from `lsum` gives us the bijection underlying the free-forgetful adjunction for R-modules. -/ noncomputable def lift : (X → M) ≃+ ((X →₀ R) →ₗ[R] M) := (AddEquiv.arrowCongr (Equiv.refl X) (ringLmapEquivSelf R ℕ M).toAddEquiv.symm).trans (lsum _ : _ ≃ₗ[ℕ] _).toAddEquiv @[simp] theorem lift_symm_apply (f) (x) : ((lift M R X).symm f) x = f (single x 1) := rfl @[simp] theorem lift_apply (f) (g) : ((lift M R X) f) g = g.sum fun x r => r • f x := rfl /-- Given compatible `S` and `R`-module structures on `M` and a type `X`, the set of functions `X → M` is `S`-linearly equivalent to the `R`-linear maps from the free `R`-module on `X` to `M`. -/ noncomputable def llift : (X → M) ≃ₗ[S] (X →₀ R) →ₗ[R] M := { lift M R X with map_smul' := by intros dsimp ext simp only [coe_comp, Function.comp_apply, lsingle_apply, lift_apply, Pi.smul_apply, sum_single_index, zero_smul, one_smul, LinearMap.smul_apply] } @[simp] theorem llift_apply (f : X → M) (x : X →₀ R) : llift M R S X f x = lift M R X f x := rfl @[simp] theorem llift_symm_apply (f : (X →₀ R) →ₗ[R] M) (x : X) : (llift M R S X).symm f x = f (single x 1) := rfl end /-- An equivalence of domains induces a linear equivalence of finitely supported functions. This is `Finsupp.domCongr` as a `LinearEquiv`. See also `LinearMap.funCongrLeft` for the case of arbitrary functions. -/ protected def domLCongr {α₁ α₂ : Type*} (e : α₁ ≃ α₂) : (α₁ →₀ M) ≃ₗ[R] α₂ →₀ M := (Finsupp.domCongr e : (α₁ →₀ M) ≃+ (α₂ →₀ M)).toLinearEquiv <| by simpa only [equivMapDomain_eq_mapDomain, domCongr_apply] using (lmapDomain M R e).map_smul @[simp] theorem domLCongr_apply {α₁ : Type*} {α₂ : Type*} (e : α₁ ≃ α₂) (v : α₁ →₀ M) : (Finsupp.domLCongr e : _ ≃ₗ[R] _) v = Finsupp.domCongr e v := rfl @[simp] theorem domLCongr_refl : Finsupp.domLCongr (Equiv.refl α) = LinearEquiv.refl R (α →₀ M) := LinearEquiv.ext fun _ => equivMapDomain_refl _ theorem domLCongr_trans {α₁ α₂ α₃ : Type*} (f : α₁ ≃ α₂) (f₂ : α₂ ≃ α₃) : (Finsupp.domLCongr f).trans (Finsupp.domLCongr f₂) = (Finsupp.domLCongr (f.trans f₂) : (_ →₀ M) ≃ₗ[R] _) := LinearEquiv.ext fun _ => (equivMapDomain_trans _ _ _).symm @[simp] theorem domLCongr_symm {α₁ α₂ : Type*} (f : α₁ ≃ α₂) : ((Finsupp.domLCongr f).symm : (_ →₀ M) ≃ₗ[R] _) = Finsupp.domLCongr f.symm := LinearEquiv.ext fun _ => rfl theorem domLCongr_single {α₁ : Type*} {α₂ : Type*} (e : α₁ ≃ α₂) (i : α₁) (m : M) : (Finsupp.domLCongr e : _ ≃ₗ[R] _) (Finsupp.single i m) = Finsupp.single (e i) m := by simp section Equiv variable [RingHomInvPair σ σ_inv] [RingHomInvPair σ_inv σ] /-- An equivalence of domain and a linear equivalence of codomain induce a linear equivalence of the corresponding finitely supported functions. -/ def lcongr {ι κ : Sort _} (e₁ : ι ≃ κ) (e₂ : M ≃ₛₗ[σ] N) : (ι →₀ M) ≃ₛₗ[σ] κ →₀ N := (Finsupp.domLCongr e₁).trans (mapRange.linearEquiv e₂) @[simp] theorem lcongr_single {ι κ : Sort _} (e₁ : ι ≃ κ) (e₂ : M ≃ₛₗ[σ] N) (i : ι) (m : M) : lcongr e₁ e₂ (Finsupp.single i m) = Finsupp.single (e₁ i) (e₂ m) := by simp [lcongr] @[simp] theorem lcongr_apply_apply {ι κ : Sort _} (e₁ : ι ≃ κ) (e₂ : M ≃ₛₗ[σ] N) (f : ι →₀ M) (k : κ) : lcongr e₁ e₂ f k = e₂ (f (e₁.symm k)) := rfl theorem lcongr_symm_single {ι κ : Sort _} (e₁ : ι ≃ κ) (e₂ : M ≃ₛₗ[σ] N) (k : κ) (n : N) : (lcongr e₁ e₂).symm (Finsupp.single k n) = Finsupp.single (e₁.symm k) (e₂.symm n) := by apply_fun (lcongr e₁ e₂ : (ι →₀ M) → (κ →₀ N)) using (lcongr e₁ e₂).injective simp @[simp] theorem lcongr_symm {ι κ : Sort _} (e₁ : ι ≃ κ) (e₂ : M ≃ₛₗ[σ] N) : (lcongr e₁ e₂).symm = lcongr e₁.symm e₂.symm := by ext rfl end Equiv end Finsupp variable {R : Type*} {M : Type*} {N : Type*} variable [Semiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N] open Finsupp section variable (R) protected theorem Submodule.finsuppSum_mem {ι β : Type*} [Zero β] (S : Submodule R M) (f : ι →₀ β) (g : ι → β → M) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ S) : f.sum g ∈ S := AddSubmonoidClass.finsuppSum_mem S f g h end namespace LinearMap variable {α : Type*} open Finsupp Function -- See also `LinearMap.splittingOfFunOnFintypeSurjective` /-- A surjective linear map to finitely supported functions has a splitting. -/ def splittingOfFinsuppSurjective (f : M →ₗ[R] α →₀ R) (s : Surjective f) : (α →₀ R) →ₗ[R] M := Finsupp.lift _ _ _ fun x : α => (s (Finsupp.single x 1)).choose theorem splittingOfFinsuppSurjective_splits (f : M →ₗ[R] α →₀ R) (s : Surjective f) : f.comp (splittingOfFinsuppSurjective f s) = LinearMap.id := by ext x dsimp [splittingOfFinsuppSurjective] congr rw [sum_single_index, one_smul] · exact (s (Finsupp.single x 1)).choose_spec · rw [zero_smul] theorem leftInverse_splittingOfFinsuppSurjective (f : M →ₗ[R] α →₀ R) (s : Surjective f) : LeftInverse f (splittingOfFinsuppSurjective f s) := fun g => LinearMap.congr_fun (splittingOfFinsuppSurjective_splits f s) g theorem splittingOfFinsuppSurjective_injective (f : M →ₗ[R] α →₀ R) (s : Surjective f) : Injective (splittingOfFinsuppSurjective f s) := (leftInverse_splittingOfFinsuppSurjective f s).injective end LinearMap namespace LinearMap section AddCommMonoid variable {R : Type*} {R₂ : Type*} {M : Type*} {M₂ : Type*} {ι : Type*} variable [Semiring R] [Semiring R₂] [AddCommMonoid M] [AddCommMonoid M₂] {σ₁₂ : R →+* R₂} variable [Module R M] [Module R₂ M₂] variable {γ : Type*} [Zero γ] section Finsupp theorem coe_finsupp_sum (t : ι →₀ γ) (g : ι → γ → M →ₛₗ[σ₁₂] M₂) : ⇑(t.sum g) = t.sum fun i d => g i d := rfl @[simp] theorem finsupp_sum_apply (t : ι →₀ γ) (g : ι → γ → M →ₛₗ[σ₁₂] M₂) (b : M) : (t.sum g) b = t.sum fun i d => g i d b := sum_apply _ _ _ end Finsupp end AddCommMonoid end LinearMap namespace Submodule variable {S : Type*} [Semiring S] [Module R S] [SMulCommClass R R S] section variable [SMulCommClass R S S] /-- If `M` and `N` are submodules of an `R`-algebra `S`, `m : ι → M` is a family of elements, then there is an `R`-linear map from `ι →₀ N` to `S` which maps `{ n_i }` to the sum of `m_i * n_i`. This is used in the definition of linearly disjointness. -/ def mulLeftMap {M : Submodule R S} (N : Submodule R S) {ι : Type*} (m : ι → M) : (ι →₀ N) →ₗ[R] S := Finsupp.lsum R fun i ↦ (m i).1 • N.subtype theorem mulLeftMap_apply {M N : Submodule R S} {ι : Type*} (m : ι → M) (n : ι →₀ N) : mulLeftMap N m n = Finsupp.sum n fun (i : ι) (n : N) ↦ (m i).1 * n.1 := rfl @[simp] theorem mulLeftMap_apply_single {M N : Submodule R S} {ι : Type*} (m : ι → M) (i : ι) (n : N) : mulLeftMap N m (Finsupp.single i n) = (m i).1 * n.1 := by simp [mulLeftMap] end variable [IsScalarTower R S S] /-- If `M` and `N` are submodules of an `R`-algebra `S`, `n : ι → N` is a family of elements, then there is an `R`-linear map from `ι →₀ M` to `S` which maps `{ m_i }` to the sum of `m_i * n_i`. This is used in the definition of linearly disjointness. -/ def mulRightMap (M : Submodule R S) {N : Submodule R S} {ι : Type*} (n : ι → N) : (ι →₀ M) →ₗ[R] S := Finsupp.lsum R fun i ↦ MulOpposite.op (n i).1 • M.subtype theorem mulRightMap_apply {M N : Submodule R S} {ι : Type*} (n : ι → N) (m : ι →₀ M) : mulRightMap M n m = Finsupp.sum m fun (i : ι) (m : M) ↦ m.1 * (n i).1 := rfl @[simp] theorem mulRightMap_apply_single {M N : Submodule R S} {ι : Type*} (n : ι → N) (i : ι) (m : M) : mulRightMap M n (Finsupp.single i m) = m.1 * (n i).1 := by simp [mulRightMap] theorem mulLeftMap_eq_mulRightMap_of_commute [SMulCommClass R S S] {M : Submodule R S} (N : Submodule R S) {ι : Type*} (m : ι → M) (hc : ∀ (i : ι) (n : N), Commute (m i).1 n.1) : mulLeftMap N m = mulRightMap N m := by ext i n; simp [(hc i n).eq] theorem mulLeftMap_eq_mulRightMap {S : Type*} [CommSemiring S] [Module R S] [SMulCommClass R R S] [SMulCommClass R S S] [IsScalarTower R S S] {M : Submodule R S} (N : Submodule R S) {ι : Type*} (m : ι → M) : mulLeftMap N m = mulRightMap N m := mulLeftMap_eq_mulRightMap_of_commute N m fun _ _ ↦ mul_comm _ _ end Submodule
.lake/packages/mathlib/Mathlib/LinearAlgebra/Finsupp/VectorSpace.lean
import Mathlib.Algebra.FreeAbelianGroup.Finsupp import Mathlib.Algebra.MonoidAlgebra.Defs import Mathlib.Algebra.Polynomial.Basic import Mathlib.LinearAlgebra.Basis.Defs import Mathlib.LinearAlgebra.DFinsupp import Mathlib.LinearAlgebra.FreeModule.Basic import Mathlib.LinearAlgebra.Finsupp.Span import Mathlib.LinearAlgebra.Projection /-! # Linear structures on function with finite support `ι →₀ M` This file contains results on the `R`-module structure on functions of finite support from a type `ι` to an `R`-module `M`, in particular in the case that `R` is a field. -/ noncomputable section open Set LinearMap Module Submodule universe u v w namespace DFinsupp variable {ι : Type*} {R : Type*} {M : ι → Type*} variable [Semiring R] [∀ i, AddCommMonoid (M i)] [∀ i, Module R (M i)] /-- The direct sum of free modules is free. Note that while this is stated for `DFinsupp` not `DirectSum`, the types are defeq. -/ noncomputable def basis {η : ι → Type*} (b : ∀ i, Basis (η i) R (M i)) : Basis (Σ i, η i) R (Π₀ i, M i) := .ofRepr ((mapRange.linearEquiv fun i => (b i).repr).trans (sigmaFinsuppLequivDFinsupp R).symm) variable (R M) in instance _root_.Module.Free.dfinsupp [∀ i : ι, Module.Free R (M i)] : Module.Free R (Π₀ i, M i) := .of_basis <| DFinsupp.basis fun i => Module.Free.chooseBasis R (M i) variable [DecidableEq ι] {φ : ι → Type*} (f : ∀ i, φ i → M i) open Finsupp (linearCombination) theorem linearIndependent_single (hf : ∀ i, LinearIndependent R (f i)) : LinearIndependent R fun ix : Σ i, φ i ↦ single ix.1 (f ix.1 ix.2) := by classical have : linearCombination R (fun ix : Σ i, φ i ↦ single ix.1 (f ix.1 ix.2)) = DFinsupp.mapRange.linearMap (fun i ↦ linearCombination R (f i)) ∘ₗ (sigmaFinsuppLequivDFinsupp R).toLinearMap := by ext; simp rw [LinearIndependent, this] exact ((DFinsupp.mapRange_injective _ fun _ ↦ map_zero _).mpr hf).comp (Equiv.injective _) lemma linearIndependent_single_iff : LinearIndependent R (fun ix : Σ i, φ i ↦ single ix.1 (f ix.1 ix.2)) ↔ ∀ i, LinearIndependent R (f i) := ⟨fun h i ↦ (h.comp _ sigma_mk_injective).of_comp (lsingle i), linearIndependent_single _⟩ end DFinsupp namespace Finsupp section Semiring variable {R : Type*} {M : Type*} {ι : Type*} variable [Semiring R] [AddCommMonoid M] [Module R M] theorem linearIndependent_single {φ : ι → Type*} (f : ∀ i, φ i → M) (hf : ∀ i, LinearIndependent R (f i)) : LinearIndependent R fun ix : Σ i, φ i ↦ single ix.1 (f ix.1 ix.2) := by classical convert (DFinsupp.linearIndependent_single _ hf).map_injOn _ (finsuppLequivDFinsupp R).symm.injective.injOn simp lemma linearIndependent_single_iff {φ : ι → Type*} {f : ∀ i, φ i → M} : LinearIndependent R (fun ix : Σ i, φ i ↦ single ix.1 (f ix.1 ix.2)) ↔ ∀ i, LinearIndependent R (f i) := ⟨fun h i ↦ (h.comp _ sigma_mk_injective).of_comp (lsingle i), linearIndependent_single _⟩ open LinearMap Submodule open scoped Classical in /-- The basis on `ι →₀ M` with basis vectors `fun ⟨i, x⟩ ↦ single i (b i x)`. -/ protected def basis {φ : ι → Type*} (b : ∀ i, Basis (φ i) R M) : Basis (Σ i, φ i) R (ι →₀ M) := .ofRepr <| (finsuppLequivDFinsupp R).trans <| (DFinsupp.mapRange.linearEquiv fun i ↦ (b i).repr).trans (sigmaFinsuppLequivDFinsupp R).symm @[simp] theorem basis_repr {φ : ι → Type*} (b : ∀ i, Basis (φ i) R M) (g : ι →₀ M) (ix) : (Finsupp.basis b).repr g ix = (b ix.1).repr (g ix.1) ix.2 := rfl @[simp] theorem coe_basis {φ : ι → Type*} (b : ∀ i, Basis (φ i) R M) : ⇑(Finsupp.basis b) = fun ix : Σ i, φ i => single ix.1 (b ix.1 ix.2) := funext fun ⟨i, x⟩ => Basis.apply_eq_iff.mpr <| by ext ⟨j, y⟩ by_cases h : i = j · cases h simp [Finsupp.single_apply_left sigma_mk_injective] · simp_all variable (ι R M) in instance _root_.Module.Free.finsupp [Module.Free R M] : Module.Free R (ι →₀ M) := .of_basis (Finsupp.basis fun _ => Module.Free.chooseBasis R M) /-- The basis on `ι →₀ R` with basis vectors `fun i ↦ single i 1`. -/ @[simps] protected def basisSingleOne : Basis ι R (ι →₀ R) := Basis.ofRepr (LinearEquiv.refl _ _) @[simp] theorem coe_basisSingleOne : (Finsupp.basisSingleOne : ι → ι →₀ R) = fun i => Finsupp.single i 1 := funext fun _ => Basis.apply_eq_iff.mpr rfl variable (ι R) in lemma linearIndependent_single_one : LinearIndependent R fun i : ι ↦ single i (1 : R) := Finsupp.basisSingleOne.linearIndependent lemma isCompl_range_lmapDomain_span {α β : Type*} {u : α → ι} {v : β → ι} (huv : IsCompl (Set.range u) (Set.range v)) : IsCompl (LinearMap.range (lmapDomain R R u)) (.span R (.range fun x ↦ single (v x) 1)) := by rw [range_lmapDomain] have := (Finsupp.basisSingleOne (R := R)).linearIndependent.isCompl_span_image (Module.Basis.span_eq _) huv rwa [← Set.range_comp, ← Set.range_comp, Function.comp_def] at this end Semiring section Ring variable {R : Type*} {M : Type*} {ι : Type*} variable [Ring R] [AddCommGroup M] [Module R M] lemma linearIndependent_single_of_ne_zero [NoZeroSMulDivisors R M] {v : ι → M} (hv : ∀ i, v i ≠ 0) : LinearIndependent R fun i : ι ↦ single i (v i) := by rw [← linearIndependent_equiv (Equiv.sigmaPUnit ι)] exact linearIndependent_single (f := fun i (_ : Unit) ↦ v i) <| by simp +contextual [Fintype.linearIndependent_iff, hv] lemma lcomapDomain_eq_linearProjOfIsCompl {α β : Type*} {u : α → ι} {v : β → ι} (hu : u.Injective) (h : IsCompl (Set.range u) (Set.range v)) : lcomapDomain u hu = LinearMap.linearProjOfIsCompl (.span R (Set.range fun x : β ↦ single (v x) (1 : R))) (lmapDomain _ _ u) (mapDomain_injective hu) (isCompl_range_lmapDomain_span h) := by classical refine Finsupp.basisSingleOne.ext fun i ↦ ?_ obtain ⟨i, rfl⟩ | ⟨i, rfl⟩ : i ∈ Set.range u ⊔ .range v := by rw [codisjoint_iff.mp h.2]; trivial · have : single (u i) 1 = lmapDomain R R u (.single i 1) := by simp simp only [coe_basisSingleOne, lcomapDomain_apply, comapDomain_single] rw [this, LinearMap.linearProjOfIsCompl_apply_left] · rw [LinearMap.linearProjOfIsCompl_apply_right'] · ext j simp only [coe_basisSingleOne, lcomapDomain_apply, comapDomain_apply, single_apply, coe_zero, Pi.zero_apply, ite_eq_right_iff] intro hij exact (Set.disjoint_range_iff.mp h.1 j i hij.symm).elim · exact Submodule.subset_span ⟨i, rfl⟩ end Ring end Finsupp lemma Module.Free.trans {R S M : Type*} [CommSemiring R] [Semiring S] [Algebra R S] [AddCommMonoid M] [Module R M] [Module S M] [IsScalarTower R S M] [Module.Free S M] [Module.Free R S] : Module.Free R M := let e : (ChooseBasisIndex S M →₀ S) ≃ₗ[R] ChooseBasisIndex S M →₀ (ChooseBasisIndex R S →₀ R) := Finsupp.mapRange.linearEquiv (chooseBasis R S).repr let e : M ≃ₗ[R] ChooseBasisIndex S M →₀ (ChooseBasisIndex R S →₀ R) := (chooseBasis S M).repr.restrictScalars R ≪≫ₗ e .of_equiv e.symm /-! TODO: move this section to an earlier file. -/ namespace Basis variable {R M n : Type*} variable [DecidableEq n] variable [Semiring R] [AddCommMonoid M] [Module R M] theorem _root_.Finset.sum_single_ite [Fintype n] (a : R) (i : n) : (∑ x : n, Finsupp.single x (if i = x then a else 0)) = Finsupp.single i a := by simp only [apply_ite (Finsupp.single _), Finsupp.single_zero, Finset.sum_ite_eq, if_pos (Finset.mem_univ _)] @[simp] theorem equivFun_symm_single [Finite n] (b : Basis n R M) (i : n) : b.equivFun.symm (Pi.single i 1) = b i := by cases nonempty_fintype n simp [Pi.single_apply] end Basis section Algebra variable {R S : Type*} [CommRing R] [Ring S] [Algebra R S] {ι : Type*} (B : Basis ι R S) /-- For any `r : R`, `s : S`, we have `B.repr ((algebra_map R S r) * s) i = r * (B.repr s i) `. -/ theorem Module.Basis.repr_smul' (i : ι) (r : R) (s : S) : B.repr (algebraMap R S r * s) i = r * B.repr s i := by rw [← smul_eq_mul, ← smul_eq_mul, algebraMap_smul, map_smul, Finsupp.smul_apply] end Algebra namespace FreeAbelianGroup instance {σ : Type*} : Module.Free ℤ (FreeAbelianGroup σ) where exists_basis := ⟨σ, ⟨(FreeAbelianGroup.equivFinsupp _).toIntLinearEquiv⟩⟩ end FreeAbelianGroup namespace AddMonoidAlgebra variable {ι R S : Type*} [Semiring R] [Semiring S] [Module R S] [Module.Free R S] instance : Module.Free R S[ι] := .finsupp .. end AddMonoidAlgebra namespace MonoidAlgebra variable {ι R S : Type*} [Semiring R] [Semiring S] [Module R S] [Module.Free R S] instance : Module.Free R (MonoidAlgebra S ι) := .finsupp .. end MonoidAlgebra namespace Polynomial variable {R S : Type*} [Semiring R] [Semiring S] [Module R S] [Module.Free R S] instance : Module.Free R R[X] := .of_equiv (Polynomial.toFinsuppIsoLinear _).symm end Polynomial
.lake/packages/mathlib/Mathlib/LinearAlgebra/Finsupp/Pi.lean
import Mathlib.LinearAlgebra.Finsupp.LSum import Mathlib.LinearAlgebra.Pi /-! # Properties of the module `α →₀ M` * `Finsupp.linearEquivFunOnFinite`: `α →₀ β` and `a → β` are equivalent if `α` is finite * `FunOnFinite.map`: the map `(X → M) → (Y → M)` induced by a map `f : X ⟶ Y` when `X` and `Y` are finite. * `FunOnFinite.linearMmap`: the linear map `(X → M) →ₗ[R] (Y → M)` induced by a map `f : X ⟶ Y` when `X` and `Y` are finite. ## Tags function with finite support, module, linear algebra -/ noncomputable section open Set LinearMap Submodule namespace Finsupp section LinearEquiv.finsuppUnique variable (R : Type*) {S : Type*} (M : Type*) variable [AddCommMonoid M] [Semiring R] [Module R M] variable (α : Type*) [Unique α] /-- If `α` has a unique term, then the type of finitely supported functions `α →₀ M` is `R`-linearly equivalent to `M`. -/ noncomputable def LinearEquiv.finsuppUnique : (α →₀ M) ≃ₗ[R] M := { Finsupp.equivFunOnFinite.trans (Equiv.funUnique α M) with map_add' := fun _ _ => rfl map_smul' := fun _ _ => rfl } variable {R M} @[simp] theorem LinearEquiv.finsuppUnique_apply (f : α →₀ M) : LinearEquiv.finsuppUnique R M α f = f default := rfl variable {α} @[simp] theorem LinearEquiv.finsuppUnique_symm_apply (m : M) : (LinearEquiv.finsuppUnique R M α).symm m = Finsupp.single default m := by ext; simp [LinearEquiv.finsuppUnique, Equiv.funUnique, single, Pi.single, equivFunOnFinite, Function.update] end LinearEquiv.finsuppUnique variable {α : Type*} {M : Type*} {N : Type*} {P : Type*} {R : Type*} {S : Type*} variable [Semiring R] [Semiring S] [AddCommMonoid M] [Module R M] variable [AddCommMonoid N] [Module R N] variable [AddCommMonoid P] [Module R P] /-- Forget that a function is finitely supported. This is the linear version of `Finsupp.toFun`. -/ @[simps] def lcoeFun : (α →₀ M) →ₗ[R] α → M where toFun := (⇑) map_add' x y := by ext simp map_smul' x y := by ext simp end Finsupp variable {R : Type*} {M : Type*} {N : Type*} variable [Semiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N] open Finsupp namespace LinearMap variable {α : Type*} open Finsupp Function -- See also `LinearMap.splittingOfFinsuppSurjective` /-- A surjective linear map to functions on a finite type has a splitting. -/ def splittingOfFunOnFintypeSurjective [Finite α] (f : M →ₗ[R] α → R) (s : Surjective f) : (α → R) →ₗ[R] M := (Finsupp.lift _ _ _ fun x : α => (s (Finsupp.single x 1)).choose).comp (linearEquivFunOnFinite R R α).symm.toLinearMap theorem splittingOfFunOnFintypeSurjective_splits [Finite α] (f : M →ₗ[R] α → R) (s : Surjective f) : f.comp (splittingOfFunOnFintypeSurjective f s) = LinearMap.id := by classical ext x y dsimp [splittingOfFunOnFintypeSurjective] rw [linearEquivFunOnFinite_symm_single, Finsupp.sum_single_index, one_smul, (s (Finsupp.single x 1)).choose_spec, Finsupp.single_eq_pi_single] rw [zero_smul] theorem leftInverse_splittingOfFunOnFintypeSurjective [Finite α] (f : M →ₗ[R] α → R) (s : Surjective f) : LeftInverse f (splittingOfFunOnFintypeSurjective f s) := fun g => LinearMap.congr_fun (splittingOfFunOnFintypeSurjective_splits f s) g theorem splittingOfFunOnFintypeSurjective_injective [Finite α] (f : M →ₗ[R] α → R) (s : Surjective f) : Injective (splittingOfFunOnFintypeSurjective f s) := (leftInverse_splittingOfFunOnFintypeSurjective f s).injective end LinearMap namespace Finsupp variable {α : Type*} /-- Given a family `Sᵢ` of `R`-submodules of `M` indexed by a type `α`, this is the `R`-submodule of `α →₀ M` of functions `f` such that `f i ∈ Sᵢ` for all `i : α`. -/ def submodule (S : α → Submodule R M) : Submodule R (α →₀ M) where carrier := { x | ∀ i, x i ∈ S i } add_mem' hx hy i := (S i).add_mem (hx i) (hy i) zero_mem' i := (S i).zero_mem smul_mem' r _ hx i := (S i).smul_mem r (hx i) @[simp] lemma mem_submodule_iff (S : α → Submodule R M) (x : α →₀ M) : x ∈ submodule S ↔ ∀ i, x i ∈ S i := by rfl theorem ker_mapRange (f : M →ₗ[R] N) (I : Type*) : LinearMap.ker (mapRange.linearMap (α := I) f) = submodule (fun _ => LinearMap.ker f) := by ext x simp [Finsupp.ext_iff] theorem range_mapRange_linearMap (f : M →ₗ[R] N) (hf : LinearMap.ker f = ⊥) (I : Type*) : LinearMap.range (mapRange.linearMap (α := I) f) = submodule (fun _ => LinearMap.range f) := by ext x constructor · rintro ⟨y, hy⟩ simp [← hy] · intro hx choose y hy using hx refine ⟨⟨x.support, y, fun i => ?_⟩, by ext; simp_all⟩ constructor <;> contrapose! <;> simp_all (config := {contextual := true}) [← hy, map_zero, LinearMap.ker_eq_bot'.1 hf] end Finsupp namespace FunOnFinite section variable {M : Type*} [AddCommMonoid M] {X Y Z : Type*} /-- The map `(X → M) → (Y → M)` induced by a map `X → Y` between finite types. -/ noncomputable def map [Finite X] [Finite Y] (f : X → Y) (s : X → M) : Y → M := Finsupp.equivFunOnFinite (Finsupp.mapDomain f (Finsupp.equivFunOnFinite.symm s)) lemma map_apply_apply [Fintype X] [Finite Y] [DecidableEq Y] (f : X → Y) (s : X → M) (y : Y) : map f s y = ∑ x with f x = y, s x := by obtain ⟨s, rfl⟩ := Finsupp.equivFunOnFinite.surjective s dsimp [map] simp only [Equiv.symm_apply_apply] nth_rw 1 [← Finsupp.univ_sum_single s] rw [Finsupp.mapDomain_finset_sum] simp [Finset.sum_filter] congr aesop @[simp] lemma map_piSingle [Finite X] [Finite Y] [DecidableEq X] [DecidableEq Y] (f : X → Y) (x : X) (m : M) : map f (Pi.single x m) = Pi.single (f x) m := by simp [map] variable (M) in lemma map_id [Finite X] : map (_root_.id : X → X) (M := M) = _root_.id := by ext s simp [map] lemma map_comp [Finite X] [Finite Y] [Finite Z] (g : Y → Z) (f : X → Y) : map (g.comp f) (M := M) = (map g).comp (map f) := by ext s simp [map, Finsupp.mapDomain_comp] end section variable (R M : Type*) [Semiring R] [AddCommMonoid M] [Module R M] {X Y Z : Type*} /-- The linear map `(X → M) →ₗ[R] (Y → M)` induced by a map `X → Y` between finite types. -/ noncomputable def linearMap [Finite X] [Finite Y] (f : X → Y) : (X → M) →ₗ[R] (Y → M) := (((Finsupp.linearEquivFunOnFinite R M Y)).comp (Finsupp.lmapDomain M R f)).comp (Finsupp.linearEquivFunOnFinite R M X).symm.toLinearMap lemma linearMap_apply_apply [Fintype X] [Finite Y] [DecidableEq Y] (f : X → Y) (s : X → M) (y : Y) : linearMap R M f s y = (Finset.univ.filter (fun (x : X) ↦ f x = y)).sum s := by apply map_apply_apply @[simp] lemma linearMap_piSingle [Finite X] [Finite Y] [DecidableEq X] [DecidableEq Y] (f : X → Y) (x : X) (m : M) : linearMap R M f (Pi.single x m) = Pi.single (f x) m := by apply map_piSingle variable (X) in @[simp] lemma linearMap_id [Finite X] : linearMap R M (_root_.id : X → X) = .id := by classical aesop lemma linearMap_comp [Finite X] [Finite Y] [Finite Z] (f : X → Y) (g : Y → Z) : linearMap R M (g.comp f) = (linearMap R M g).comp (linearMap R M f) := by classical aesop end end FunOnFinite
.lake/packages/mathlib/Mathlib/LinearAlgebra/Finsupp/Defs.lean
import Mathlib.Algebra.Module.Equiv.Defs import Mathlib.Algebra.Module.LinearMap.End import Mathlib.Algebra.Module.Pi import Mathlib.Data.Finsupp.SMul /-! # Properties of the module `α →₀ M` Given an `R`-module `M`, the `R`-module structure on `α →₀ M` is defined in `Mathlib/Data/Finsupp/SMul.lean`. In this file we define `LinearMap` versions of various maps: * `Finsupp.lsingle a : M →ₗ[R] ι →₀ M`: `Finsupp.single a` as a linear map; * `Finsupp.lapply a : (ι →₀ M) →ₗ[R] M`: the map `fun f ↦ f a` as a linear map; * `Finsupp.lsubtypeDomain (s : Set α) : (α →₀ M) →ₗ[R] (s →₀ M)`: restriction to a subtype as a linear map; * `Finsupp.restrictDom`: `Finsupp.filter` as a linear map to `Finsupp.supported s`; * `Finsupp.lmapDomain`: a linear map version of `Finsupp.mapDomain`; ## Tags function with finite support, module, linear algebra -/ assert_not_exists Submodule noncomputable section open Set LinearMap namespace Finsupp variable {α : Type*} {M : Type*} {N : Type*} {P : Type*} {R R₂ R₃ : Type*} {S : Type*} variable [Semiring R] [Semiring R₂] [Semiring R₃] [Semiring S] variable [AddCommMonoid M] [Module R M] variable [AddCommMonoid N] [Module R₂ N] variable [AddCommMonoid P] [Module R₃ P] variable {σ₁₂ : R →+* R₂} {σ₂₁ : R₂ →+* R} variable {σ₂₃ : R₂ →+* R₃} {σ₃₂ : R₃ →+* R₂} variable {σ₁₃ : R →+* R₃} {σ₃₁ : R₃ →+* R} variable [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃] [RingHomCompTriple σ₃₂ σ₂₁ σ₃₁] section LinearEquivFunOnFinite variable (R : Type*) {S : Type*} (M : Type*) (α : Type*) variable [Finite α] [AddCommMonoid M] [Semiring R] [Module R M] /-- Given `Finite α`, `linearEquivFunOnFinite R` is the natural `R`-linear equivalence between `α →₀ β` and `α → β`. -/ @[simps apply] noncomputable def linearEquivFunOnFinite : (α →₀ M) ≃ₗ[R] α → M := { equivFunOnFinite with toFun := (⇑) map_add' := fun _ _ => rfl map_smul' := fun _ _ => rfl } @[simp] theorem linearEquivFunOnFinite_single [DecidableEq α] (x : α) (m : M) : (linearEquivFunOnFinite R M α) (single x m) = Pi.single x m := equivFunOnFinite_single x m @[simp] theorem linearEquivFunOnFinite_symm_single [DecidableEq α] (x : α) (m : M) : (linearEquivFunOnFinite R M α).symm (Pi.single x m) = single x m := equivFunOnFinite_symm_single x m @[simp] theorem linearEquivFunOnFinite_symm_coe (f : α →₀ M) : (linearEquivFunOnFinite R M α).symm f = f := (linearEquivFunOnFinite R M α).symm_apply_apply f end LinearEquivFunOnFinite /-- Interpret `Finsupp.single a` as a linear map. -/ def lsingle (a : α) : M →ₗ[R] α →₀ M := { Finsupp.singleAddHom a with map_smul' := fun _ _ => (smul_single _ _ _).symm } /-- Two `R`-linear maps from `Finsupp X M` which agree on each `single x y` agree everywhere. -/ theorem lhom_ext ⦃φ ψ : (α →₀ M) →ₛₗ[σ₁₂] N⦄ (h : ∀ a b, φ (single a b) = ψ (single a b)) : φ = ψ := LinearMap.toAddMonoidHom_injective <| addHom_ext h /-- Two `R`-linear maps from `Finsupp X M` which agree on each `single x y` agree everywhere. We formulate this fact using equality of linear maps `φ.comp (lsingle a)` and `ψ.comp (lsingle a)` so that the `ext` tactic can apply a type-specific extensionality lemma to prove equality of these maps. E.g., if `M = R`, then it suffices to verify `φ (single a 1) = ψ (single a 1)`. -/ -- The priority should be higher than `LinearMap.ext`. @[ext high] theorem lhom_ext' ⦃φ ψ : (α →₀ M) →ₛₗ[σ₁₂] N⦄ (h : ∀ a, φ.comp (lsingle a) = ψ.comp (lsingle a)) : φ = ψ := lhom_ext fun a => LinearMap.congr_fun (h a) /-- Interpret `fun f : α →₀ M ↦ f a` as a linear map. -/ def lapply (a : α) : (α →₀ M) →ₗ[R] M := { Finsupp.applyAddHom a with map_smul' := fun _ _ => rfl } instance [Nonempty α] [FaithfulSMul R M] : FaithfulSMul R (α →₀ M) := .of_injective (Finsupp.lsingle <| Classical.arbitrary _) (Finsupp.single_injective _) section LSubtypeDomain variable (s : Set α) /-- Interpret `Finsupp.subtypeDomain s` as a linear map. -/ def lsubtypeDomain : (α →₀ M) →ₗ[R] s →₀ M where toFun := subtypeDomain fun x => x ∈ s map_add' _ _ := subtypeDomain_add map_smul' _ _ := ext fun _ => rfl theorem lsubtypeDomain_apply (f : α →₀ M) : (lsubtypeDomain s : (α →₀ M) →ₗ[R] s →₀ M) f = subtypeDomain (fun x => x ∈ s) f := rfl end LSubtypeDomain @[simp] theorem lsingle_apply (a : α) (b : M) : (lsingle a : M →ₗ[R] α →₀ M) b = single a b := rfl @[simp] theorem lapply_apply (a : α) (f : α →₀ M) : (lapply a : (α →₀ M) →ₗ[R] M) f = f a := rfl @[simp] theorem lapply_comp_lsingle_same (a : α) : lapply a ∘ₗ lsingle a = (.id : M →ₗ[R] M) := by ext; simp @[simp] theorem lapply_comp_lsingle_of_ne (a a' : α) (h : a ≠ a') : lapply a ∘ₗ lsingle a' = (0 : M →ₗ[R] M) := by ext; simp [h.symm] section LMapDomain variable {α' : Type*} {α'' : Type*} (M R) /-- Interpret `Finsupp.mapDomain` as a linear map. -/ def lmapDomain (f : α → α') : (α →₀ M) →ₗ[R] α' →₀ M where toFun := mapDomain f map_add' _ _ := mapDomain_add map_smul' := mapDomain_smul @[simp] theorem lmapDomain_apply (f : α → α') (l : α →₀ M) : (lmapDomain M R f : (α →₀ M) →ₗ[R] α' →₀ M) l = mapDomain f l := rfl lemma coe_lmapDomain (f : α → α') : ⇑(lmapDomain M R f) = Finsupp.mapDomain f := rfl @[simp] theorem lmapDomain_id : (lmapDomain M R _root_.id : (α →₀ M) →ₗ[R] α →₀ M) = LinearMap.id := LinearMap.ext fun _ => mapDomain_id theorem lmapDomain_comp (f : α → α') (g : α' → α'') : lmapDomain M R (g ∘ f) = (lmapDomain M R g).comp (lmapDomain M R f) := LinearMap.ext fun _ => mapDomain_comp /-- `Finsupp.mapDomain` as a `LinearEquiv`. -/ def mapDomain.linearEquiv (f : α ≃ α') : (α →₀ M) ≃ₗ[R] (α' →₀ M) where __ := lmapDomain M R f.toFun invFun := mapDomain f.symm left_inv _ := by simp [← mapDomain_comp] right_inv _ := by simp [← mapDomain_comp] @[simp] theorem mapDomain.coe_linearEquiv (f : α ≃ α') : ⇑(linearEquiv M R f) = mapDomain f := rfl @[simp] theorem mapDomain.toLinearMap_linearEquiv (f : α ≃ α') : (linearEquiv M R f : _ →ₗ[R] _) = lmapDomain M R f := rfl @[simp] theorem mapDomain.linearEquiv_symm (f : α ≃ α') : (linearEquiv M R f).symm = linearEquiv M R f.symm := rfl end LMapDomain section LComapDomain variable {β : Type*} /-- Given `f : α → β` and a proof `hf` that `f` is injective, `lcomapDomain f hf` is the linear map sending `l : β →₀ M` to the finitely supported function from `α` to `M` given by composing `l` with `f`. This is the linear version of `Finsupp.comapDomain`. -/ @[simps] def lcomapDomain (f : α → β) (hf : Function.Injective f) : (β →₀ M) →ₗ[R] α →₀ M where toFun l := Finsupp.comapDomain f l hf.injOn map_add' x y := by ext; simp map_smul' c x := by ext; simp theorem leftInverse_lcomapDomain_mapDomain (f : α → β) (hf : Function.Injective f) : Function.LeftInverse (lcomapDomain (R := R) (M := M) f hf) (mapDomain f) := comapDomain_mapDomain f hf end LComapDomain /-- `Finsupp.mapRange` as a `LinearMap`. -/ @[simps apply] def mapRange.linearMap (f : M →ₛₗ[σ₁₂] N) : (α →₀ M) →ₛₗ[σ₁₂] α →₀ N := { mapRange.addMonoidHom f.toAddMonoidHom with toFun := (mapRange f f.map_zero : (α →₀ M) → α →₀ N) map_smul' := fun c v => mapRange_smul' c (σ₁₂ c) v (f.map_smulₛₗ c) } @[simp] theorem mapRange.linearMap_id : mapRange.linearMap LinearMap.id = (LinearMap.id : (α →₀ M) →ₗ[R] _) := LinearMap.ext mapRange_id theorem mapRange.linearMap_comp (f : N →ₛₗ[σ₂₃] P) (f₂ : M →ₛₗ[σ₁₂] N) : (mapRange.linearMap (f.comp f₂) : (α →₀ _) →ₛₗ[σ₁₃] _) = (mapRange.linearMap f).comp (mapRange.linearMap f₂) := LinearMap.ext <| mapRange_comp f f.map_zero f₂ f₂.map_zero (comp f f₂).map_zero @[simp] theorem mapRange.linearMap_toAddMonoidHom (f : M →ₛₗ[σ₁₂] N) : (mapRange.linearMap f).toAddMonoidHom = (mapRange.addMonoidHom f.toAddMonoidHom : (α →₀ M) →+ _) := AddMonoidHom.ext fun _ => rfl section Equiv variable [RingHomInvPair σ₁₂ σ₂₁] [RingHomInvPair σ₂₁ σ₁₂] variable [RingHomInvPair σ₂₃ σ₃₂] [RingHomInvPair σ₃₂ σ₂₃] variable [RingHomInvPair σ₁₃ σ₃₁] [RingHomInvPair σ₃₁ σ₁₃] /-- `Finsupp.mapRange` as a `LinearEquiv`. -/ @[simps apply] def mapRange.linearEquiv (e : M ≃ₛₗ[σ₁₂] N) : (α →₀ M) ≃ₛₗ[σ₁₂] α →₀ N := { mapRange.linearMap e.toLinearMap, mapRange.addEquiv e.toAddEquiv with toFun := mapRange e e.map_zero invFun := mapRange e.symm e.symm.map_zero } @[simp] theorem mapRange.linearEquiv_refl : mapRange.linearEquiv (LinearEquiv.refl R M) = LinearEquiv.refl R (α →₀ M) := LinearEquiv.ext mapRange_id theorem mapRange.linearEquiv_trans (f : M ≃ₛₗ[σ₁₂] N) (f₂ : N ≃ₛₗ[σ₂₃] P) : (mapRange.linearEquiv (f.trans f₂) : (α →₀ _) ≃ₛₗ[σ₁₃] _) = (mapRange.linearEquiv f).trans (mapRange.linearEquiv f₂) := LinearEquiv.ext <| mapRange_comp f₂ f₂.map_zero f f.map_zero (f.trans f₂).map_zero @[simp] theorem mapRange.linearEquiv_symm (f : M ≃ₛₗ[σ₁₂] N) : ((mapRange.linearEquiv f).symm : (α →₀ _) ≃ₛₗ[σ₂₁] _) = mapRange.linearEquiv f.symm := LinearEquiv.ext fun _x => rfl @[simp] theorem mapRange.linearEquiv_toAddEquiv (f : M ≃ₛₗ[σ₁₂] N) : (mapRange.linearEquiv f).toAddEquiv = (mapRange.addEquiv f.toAddEquiv : (α →₀ M) ≃+ _) := AddEquiv.ext fun _ => rfl @[simp] theorem mapRange.linearEquiv_toLinearMap (f : M ≃ₛₗ[σ₁₂] N) : (mapRange.linearEquiv f).toLinearMap = (mapRange.linearMap f.toLinearMap : (α →₀ M) →ₛₗ[σ₁₂] _) := LinearMap.ext fun _ => rfl end Equiv section Prod variable {α β R M : Type*} [DecidableEq α] [Semiring R] [AddCommMonoid M] [Module R M] variable (R) in /-- The linear equivalence between `α × β →₀ M` and `α →₀ β →₀ M`. This is the `LinearEquiv` version of `Finsupp.finsuppProdEquiv`. -/ @[simps +simpRhs] noncomputable def finsuppProdLEquiv : (α × β →₀ M) ≃ₗ[R] α →₀ β →₀ M := { finsuppProdEquiv with map_add' f g := by ext; simp map_smul' c f := by ext; simp } theorem finsuppProdLEquiv_symm_apply_apply (f : α →₀ β →₀ M) (xy) : (finsuppProdLEquiv R).symm f xy = f xy.1 xy.2 := rfl end Prod end Finsupp variable {R : Type*} {M : Type*} {N : Type*} variable [Semiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N] open Finsupp section variable (R) /-- If `Subsingleton R`, then `M ≃ₗ[R] ι →₀ R` for any type `ι`. -/ @[simps] def Module.subsingletonEquiv (R M ι : Type*) [Semiring R] [Subsingleton R] [AddCommMonoid M] [Module R M] : M ≃ₗ[R] ι →₀ R where toFun _ := 0 invFun _ := 0 left_inv m := have := Module.subsingleton R M Subsingleton.elim _ _ right_inv f := by simp only [eq_iff_true_of_subsingleton] map_add' _ _ := (add_zero 0).symm map_smul' r _ := (smul_zero r).symm end namespace Module.End variable (ι : Type*) {R M : Type*} [Semiring R] [AddCommMonoid M] [Module R M] /-- If `M` is an `R`-module and `ι` is a type, then an additive endomorphism of `M` that commutes with all `R`-endomorphisms of `M` gives rise to an additive endomorphism of `ι →₀ M` that commutes with all `R`-endomorphisms of `ι →₀ M`. -/ @[simps] noncomputable def ringHomEndFinsupp : End (End R M) M →+* End (End R (ι →₀ M)) (ι →₀ M) where toFun f := { toFun := Finsupp.mapRange.addMonoidHom f map_add' := map_add _ map_smul' g x := x.induction_linear (by simp) (fun _ _ h h' ↦ by rw [smul_add, map_add, h, h', map_add, smul_add]) fun i m ↦ by ext j change f (Finsupp.lapply j ∘ₗ g ∘ₗ Finsupp.lsingle i • m) = _ rw [map_smul] simp } map_one' := by ext; simp map_mul' _ _ := by ext; simp map_zero' := by ext; simp map_add' _ _ := by ext; simp variable {ι} /-- If `M` is an `R`-module and `ι` is an nonempty type, then every additive endomorphism of `ι →₀ M` that commutes with all `R`-endomorphisms of `ι →₀ M` comes from an additive endomorphism of `M` that commutes with all `R`-endomorphisms of `M`. See (15) in F4 of §28 on p.131 of [Lorenz2008]. -/ @[simps!] noncomputable def ringEquivEndFinsupp (i : ι) : End (End R M) M ≃+* End (End R (ι →₀ M)) (ι →₀ M) where __ := ringHomEndFinsupp ι invFun f := { toFun m := f (Finsupp.single i m) i map_add' _ _ := by simp map_smul' g m := let g := Finsupp.mapRange.linearMap g show _ = g _ i by rw [← End.smul_def g, ← map_smul]; simp [g] } left_inv _ := by ext; simp right_inv f := by ext x j change f (Finsupp.lsingle (R := R) (M := M) i ∘ₗ Finsupp.lapply j • x) i = _ rw [map_smul] simp end Module.End
.lake/packages/mathlib/Mathlib/LinearAlgebra/Finsupp/Span.lean
import Mathlib.LinearAlgebra.Finsupp.Defs import Mathlib.LinearAlgebra.Span.Basic /-! # Finitely supported functions and spans ## Tags function with finite support, module, linear algebra -/ noncomputable section open Set LinearMap Submodule namespace Finsupp variable {α : Type*} {M : Type*} {N : Type*} {P : Type*} {R : Type*} {S : Type*} variable [Semiring R] [Semiring S] [AddCommMonoid M] [Module R M] variable [AddCommMonoid N] [Module R N] variable [AddCommMonoid P] [Module R P] @[simp] theorem ker_lsingle (a : α) : ker (lsingle a : M →ₗ[R] α →₀ M) = ⊥ := ker_eq_bot_of_injective (single_injective a) theorem lsingle_range_le_ker_lapply (s t : Set α) (h : Disjoint s t) : ⨆ a ∈ s, LinearMap.range (lsingle a : M →ₗ[R] α →₀ M) ≤ ⨅ a ∈ t, ker (lapply a : (α →₀ M) →ₗ[R] M) := by refine iSup_le fun a₁ => iSup_le fun h₁ => range_le_iff_comap.2 ?_ simp only [(ker_comp _ _).symm, eq_top_iff, SetLike.le_def, mem_ker, comap_iInf, mem_iInf] intro b _ a₂ h₂ have : a₂ ≠ a₁ := fun eq => h.le_bot ⟨h₁, eq.symm ▸ h₂⟩ exact single_eq_of_ne this theorem iInf_ker_lapply_le_bot : ⨅ a, ker (lapply a : (α →₀ M) →ₗ[R] M) ≤ ⊥ := by simp only [SetLike.le_def, mem_iInf, mem_ker, mem_bot, lapply_apply] exact fun a h => Finsupp.ext h theorem iSup_lsingle_range : ⨆ a, LinearMap.range (lsingle a : M →ₗ[R] α →₀ M) = ⊤ := by refine eq_top_iff.2 <| SetLike.le_def.2 fun f _ => ?_ rw [← sum_single f] exact sum_mem fun a _ => Submodule.mem_iSup_of_mem a ⟨_, rfl⟩ theorem disjoint_lsingle_lsingle (s t : Set α) (hs : Disjoint s t) : Disjoint (⨆ a ∈ s, LinearMap.range (lsingle a : M →ₗ[R] α →₀ M)) (⨆ a ∈ t, LinearMap.range (lsingle a : M →ₗ[R] α →₀ M)) := by refine (Disjoint.mono (lsingle_range_le_ker_lapply s sᶜ disjoint_compl_right) (lsingle_range_le_ker_lapply t tᶜ disjoint_compl_right)) ?_ rw [disjoint_iff_inf_le] refine le_trans (le_iInf fun i => ?_) iInf_ker_lapply_le_bot classical by_cases his : i ∈ s · by_cases hit : i ∈ t · exact (hs.le_bot ⟨his, hit⟩).elim exact inf_le_of_right_le (iInf_le_of_le i <| iInf_le _ hit) exact inf_le_of_left_le (iInf_le_of_le i <| iInf_le _ his) theorem span_single_image (s : Set M) (a : α) : Submodule.span R (single a '' s) = (Submodule.span R s).map (lsingle a : M →ₗ[R] α →₀ M) := by rw [← span_image]; rfl lemma range_lmapDomain {β : Type*} (u : α → β) : LinearMap.range (lmapDomain R R u) = .span R (.range fun x ↦ single (u x) 1) := by refine le_antisymm ?_ ?_ · rintro x ⟨x, rfl⟩ induction x using induction_linear with | single i s => rw [lmapDomain_apply, mapDomain_single, ← Finsupp.smul_single_one] exact Submodule.smul_mem _ _ (Submodule.subset_span ⟨i, rfl⟩) | zero => simp | add f g hf hg => rw [map_add] exact Submodule.add_mem _ hf hg · rw [Submodule.span_le, Set.range_subset_iff] intro i exact ⟨Finsupp.single i 1, by simp⟩ end Finsupp variable {R : Type*} {M : Type*} {N : Type*} variable [Semiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N] open Finsupp theorem Submodule.exists_finset_of_mem_iSup {ι : Sort _} (p : ι → Submodule R M) {m : M} (hm : m ∈ ⨆ i, p i) : ∃ s : Finset ι, m ∈ ⨆ i ∈ s, p i := by have := CompleteLattice.IsCompactElement.exists_finset_of_le_iSup (Submodule R M) (Submodule.singleton_span_isCompactElement m) p simp only [Submodule.span_singleton_le_iff_mem] at this exact this hm /-- `Submodule.exists_finset_of_mem_iSup` as an `iff` -/ theorem Submodule.mem_iSup_iff_exists_finset {ι : Sort _} {p : ι → Submodule R M} {m : M} : (m ∈ ⨆ i, p i) ↔ ∃ s : Finset ι, m ∈ ⨆ i ∈ s, p i := ⟨Submodule.exists_finset_of_mem_iSup p, fun ⟨_, hs⟩ => iSup_mono (fun i => (iSup_const_le : _ ≤ p i)) hs⟩ theorem Submodule.mem_sSup_iff_exists_finset {S : Set (Submodule R M)} {m : M} : m ∈ sSup S ↔ ∃ s : Finset (Submodule R M), ↑s ⊆ S ∧ m ∈ ⨆ i ∈ s, i := by rw [sSup_eq_iSup, iSup_subtype', Submodule.mem_iSup_iff_exists_finset] refine ⟨fun ⟨s, hs⟩ ↦ ⟨s.map (Function.Embedding.subtype S), ?_, ?_⟩, fun ⟨s, hsS, hs⟩ ↦ ⟨s.preimage (↑) Subtype.coe_injective.injOn, ?_⟩⟩ · simpa using fun x _ ↦ x.property · suffices m ∈ ⨆ (i) (hi : i ∈ S) (_ : ⟨i, hi⟩ ∈ s), i by simpa rwa [iSup_subtype'] · have : ⨆ (i) (_ : i ∈ S ∧ i ∈ s), i = ⨆ (i) (_ : i ∈ s), i := by convert rfl; aesop simpa only [Finset.mem_preimage, iSup_subtype, iSup_and', this]
.lake/packages/mathlib/Mathlib/LinearAlgebra/Finsupp/Supported.lean
import Mathlib.Algebra.Module.Submodule.Range import Mathlib.LinearAlgebra.Finsupp.LSum import Mathlib.LinearAlgebra.Span.Defs /-! # `Finsupp`s supported on a given submodule * `Finsupp.restrictDom`: `Finsupp.filter` as a linear map to `Finsupp.supported s`; `Finsupp.supported R R s` and codomain `Submodule.span R (v '' s)`; * `Finsupp.supportedEquivFinsupp`: a linear equivalence between the functions `α →₀ M` supported on `s` and the functions `s →₀ M`; * `Finsupp.domLCongr`: a `LinearEquiv` version of `Finsupp.domCongr`; * `Finsupp.congr`: if the sets `s` and `t` are equivalent, then `supported M R s` is equivalent to `supported M R t`; ## Tags function with finite support, module, linear algebra -/ noncomputable section open Set LinearMap Submodule namespace Finsupp variable {α : Type*} {M : Type*} {N : Type*} {P : Type*} {R : Type*} {S : Type*} variable [Semiring R] [Semiring S] [AddCommMonoid M] [Module R M] variable [AddCommMonoid N] [Module R N] variable [AddCommMonoid P] [Module R P] variable (M R) /-- `Finsupp.supported M R s` is the `R`-submodule of all `p : α →₀ M` such that `p.support ⊆ s`. -/ def supported (s : Set α) : Submodule R (α →₀ M) where carrier := { p | ↑p.support ⊆ s } add_mem' {p q} hp hq := by classical refine Subset.trans (Subset.trans (Finset.coe_subset.2 support_add) ?_) (union_subset hp hq) rw [Finset.coe_union] zero_mem' := by simp only [subset_def, Finset.mem_coe, Set.mem_setOf_eq, mem_support_iff, zero_apply] intro h ha exact (ha rfl).elim smul_mem' _ _ hp := Subset.trans (Finset.coe_subset.2 support_smul) hp variable {M} theorem mem_supported {s : Set α} (p : α →₀ M) : p ∈ supported M R s ↔ ↑p.support ⊆ s := Iff.rfl theorem mem_supported' {s : Set α} (p : α →₀ M) : p ∈ supported M R s ↔ ∀ x ∉ s, p x = 0 := by simp [mem_supported, Set.subset_def, not_imp_comm] theorem mem_supported_support (p : α →₀ M) : p ∈ Finsupp.supported M R (p.support : Set α) := by rw [Finsupp.mem_supported] theorem single_mem_supported {s : Set α} {a : α} (b : M) (h : a ∈ s) : single a b ∈ supported M R s := Set.Subset.trans support_single_subset (Finset.singleton_subset_set_iff.2 h) theorem supported_eq_span_single (s : Set α) : supported R R s = span R ((fun i => single i 1) '' s) := by refine (span_eq_of_le _ ?_ (SetLike.le_def.2 fun l hl => ?_)).symm · rintro _ ⟨_, hp, rfl⟩ exact single_mem_supported R 1 hp · rw [← l.sum_single] refine sum_mem fun i il => ?_ rw [show single i (l i) = l i • single i 1 by simp] exact smul_mem _ (l i) (subset_span (mem_image_of_mem _ (hl il))) theorem span_le_supported_biUnion_support (s : Set (α →₀ M)) : span R s ≤ supported M R (⋃ x ∈ s, x.support) := span_le.mpr fun _ h ↦ subset_biUnion_of_mem h (u := (SetLike.coe ·.support)) variable (M) /-- Interpret `Finsupp.filter s` as a linear map from `α →₀ M` to `supported M R s`. -/ def restrictDom (s : Set α) [DecidablePred (· ∈ s)] : (α →₀ M) →ₗ[R] supported M R s := LinearMap.codRestrict _ { toFun := filter (· ∈ s) map_add' := fun _ _ => filter_add map_smul' := fun _ _ => filter_smul } fun l => (mem_supported' _ _).2 fun _ => filter_apply_neg (· ∈ s) l variable {M R} section @[simp] theorem restrictDom_apply (s : Set α) (l : α →₀ M) [DecidablePred (· ∈ s)] : (restrictDom M R s l : α →₀ M) = Finsupp.filter (· ∈ s) l := rfl end theorem restrictDom_comp_subtype (s : Set α) [DecidablePred (· ∈ s)] : (restrictDom M R s).comp (Submodule.subtype _) = LinearMap.id := by ext l a by_cases h : a ∈ s · simp [h] simpa [h] using ((mem_supported' R l.1).1 l.2 a h).symm theorem range_restrictDom (s : Set α) [DecidablePred (· ∈ s)] : LinearMap.range (restrictDom M R s) = ⊤ := range_eq_top.2 <| Function.RightInverse.surjective <| LinearMap.congr_fun (restrictDom_comp_subtype s) theorem supported_mono {s t : Set α} (st : s ⊆ t) : supported M R s ≤ supported M R t := fun _ h => Set.Subset.trans h st @[simp] theorem supported_empty : supported M R (∅ : Set α) = ⊥ := eq_bot_iff.2 fun l h => (Submodule.mem_bot R).2 <| by ext; simp_all [mem_supported'] @[simp] theorem supported_univ : supported M R (Set.univ : Set α) = ⊤ := eq_top_iff.2 fun _ _ => Set.subset_univ _ theorem supported_iUnion {δ : Type*} (s : δ → Set α) : supported M R (⋃ i, s i) = ⨆ i, supported M R (s i) := by refine le_antisymm ?_ (iSup_le fun i => supported_mono <| Set.subset_iUnion _ _) haveI := Classical.decPred fun x => x ∈ ⋃ i, s i suffices LinearMap.range ((Submodule.subtype _).comp (restrictDom M R (⋃ i, s i))) ≤ ⨆ i, supported M R (s i) by rwa [LinearMap.range_comp, range_restrictDom, Submodule.map_top, range_subtype] at this rw [range_le_iff_comap, eq_top_iff] rintro l ⟨⟩ induction l using Finsupp.induction with | zero => exact zero_mem _ | single_add x a l _ _ ih => refine add_mem ?_ ih by_cases h : ∃ i, x ∈ s i · simp only [mem_comap, coe_comp, coe_subtype, Function.comp_apply, restrictDom_apply, mem_iUnion, h, filter_single_of_pos] obtain ⟨i, hi⟩ := h exact le_iSup (fun i => supported M R (s i)) i (single_mem_supported R _ hi) · simp [h] theorem supported_union (s t : Set α) : supported M R (s ∪ t) = supported M R s ⊔ supported M R t := by rw [Set.union_eq_iUnion, supported_iUnion, iSup_bool_eq, cond_true, cond_false] theorem supported_iInter {ι : Type*} (s : ι → Set α) : supported M R (⋂ i, s i) = ⨅ i, supported M R (s i) := Submodule.ext fun x => by simp [mem_supported, subset_iInter_iff] theorem supported_inter (s t : Set α) : supported M R (s ∩ t) = supported M R s ⊓ supported M R t := by rw [Set.inter_eq_iInter, supported_iInter, iInf_bool_eq]; rfl theorem disjoint_supported_supported {s t : Set α} (h : Disjoint s t) : Disjoint (supported M R s) (supported M R t) := disjoint_iff.2 <| by rw [← supported_inter, disjoint_iff_inter_eq_empty.1 h, supported_empty] theorem disjoint_supported_supported_iff [Nontrivial M] {s t : Set α} : Disjoint (supported M R s) (supported M R t) ↔ Disjoint s t := by refine ⟨fun h => Set.disjoint_left.mpr fun x hx1 hx2 => ?_, disjoint_supported_supported⟩ rcases exists_ne (0 : M) with ⟨y, hy⟩ have := h.le_bot ⟨single_mem_supported R y hx1, single_mem_supported R y hx2⟩ rw [mem_bot, single_eq_zero] at this exact hy this lemma codisjoint_supported_supported {s t : Set α} (h : Codisjoint s t) : Codisjoint (supported M R s) (supported M R t) := by rw [codisjoint_iff, eq_top_iff, ← supported_union, show s ∪ t = .univ from codisjoint_iff.mp h, supported_univ] lemma codisjoint_supported_supported_iff [Nontrivial M] {s t : Set α} : Codisjoint (supported M R s) (supported M R t) ↔ Codisjoint s t := by refine ⟨fun h ↦ codisjoint_iff.mpr (eq_top_iff.mpr fun a ↦ ?_), codisjoint_supported_supported⟩ obtain ⟨x, hx⟩ := exists_ne (0 : M) rw [codisjoint_iff, eq_top_iff, ← supported_union] at h have : Finsupp.single a x ∈ supported M R (s ∪ t) := h (show Finsupp.single a x ∈ _ from trivial) simpa [Finsupp.mem_supported, Finsupp.support_single_ne_zero _ hx] using this /-- Interpret `Finsupp.restrictSupportEquiv` as a linear equivalence between `supported M R s` and `s →₀ M`. -/ @[simps!] def supportedEquivFinsupp (s : Set α) : supported M R s ≃ₗ[R] s →₀ M := by let F : supported M R s ≃ (s →₀ M) := restrictSupportEquiv s M refine F.toLinearEquiv ?_ have : (F : supported M R s → ↥s →₀ M) = (lsubtypeDomain s : (α →₀ M) →ₗ[R] s →₀ M).comp (Submodule.subtype (supported M R s)) := rfl rw [this] exact LinearMap.isLinear _ @[simp] theorem supportedEquivFinsupp_symm_apply_coe (s : Set α) [DecidablePred (· ∈ s)] (f : s →₀ M) : (supportedEquivFinsupp (R := R) s).symm f = f.extendDomain := by convert restrictSupportEquiv_symm_apply_coe .. @[simp] theorem supportedEquivFinsupp_symm_single (s : Set α) (i : s) (a : M) : ((supportedEquivFinsupp (R := R) s).symm (single i a) : α →₀ M) = single ↑i a := by classical simp section LMapDomain variable {α' : Type*} {α'' : Type*} (M R) theorem supported_comap_lmapDomain (f : α → α') (s : Set α') : supported M R (f ⁻¹' s) ≤ (supported M R s).comap (lmapDomain M R f) := by classical intro l (hl : (l.support : Set α) ⊆ f ⁻¹' s) change ↑(mapDomain f l).support ⊆ s rw [← Set.image_subset_iff, ← Finset.coe_image] at hl exact Set.Subset.trans mapDomain_support hl theorem lmapDomain_supported (f : α → α') (s : Set α) : (supported M R s).map (lmapDomain M R f) = supported M R (f '' s) := by classical cases isEmpty_or_nonempty α · simp [s.eq_empty_of_isEmpty] refine le_antisymm (map_le_iff_le_comap.2 <| le_trans (supported_mono <| Set.subset_preimage_image _ _) (supported_comap_lmapDomain M R _ _)) ?_ intro l hl refine ⟨(lmapDomain M R (Function.invFunOn f s) : (α' →₀ M) →ₗ[R] α →₀ M) l, fun x hx => ?_, ?_⟩ · rcases Finset.mem_image.1 (mapDomain_support hx) with ⟨c, hc, rfl⟩ exact Function.invFunOn_mem (by simpa using hl hc) · rw [← LinearMap.comp_apply, ← lmapDomain_comp] refine (mapDomain_congr fun c hc => ?_).trans mapDomain_id exact Function.invFunOn_eq (by simpa using hl hc) theorem lmapDomain_disjoint_ker (f : α → α') {s : Set α} (H : ∀ a ∈ s, ∀ b ∈ s, f a = f b → a = b) : Disjoint (supported M R s) (ker (lmapDomain M R f)) := by rw [disjoint_iff_inf_le] rintro l ⟨h₁, h₂⟩ rw [SetLike.mem_coe, mem_ker, lmapDomain_apply, mapDomain] at h₂ simp only [mem_bot]; ext x haveI := Classical.decPred fun x => x ∈ s by_cases xs : x ∈ s · have : Finsupp.sum l (fun a => Finsupp.single (f a)) (f x) = 0 := by rw [h₂] rfl rw [Finsupp.sum_apply, Finsupp.sum_eq_single x, single_eq_same] at this · simpa · intro y hy xy simp only [SetLike.mem_coe, mem_supported, subset_def, mem_support_iff] at h₁ simp [mt (H _ (h₁ _ hy) _ xs) xy] · simp +contextual · by_contra h exact xs (h₁ <| Finsupp.mem_support_iff.2 h) end LMapDomain /-- An equivalence of sets induces a linear equivalence of `Finsupp`s supported on those sets. -/ noncomputable def congr {α' : Type*} (s : Set α) (t : Set α') (e : s ≃ t) : supported M R s ≃ₗ[R] supported M R t := by haveI := Classical.decPred fun x => x ∈ s haveI := Classical.decPred fun x => x ∈ t exact Finsupp.supportedEquivFinsupp s ≪≫ₗ (Finsupp.domLCongr e ≪≫ₗ (Finsupp.supportedEquivFinsupp t).symm) end Finsupp
.lake/packages/mathlib/Mathlib/LinearAlgebra/Finsupp/SumProd.lean
import Mathlib.Algebra.Module.Equiv.Defs import Mathlib.Algebra.Module.Pi import Mathlib.Algebra.Module.Prod import Mathlib.Data.Finsupp.SMul /-! # `Finsupp`s and sum/product types This file contains results about modules involving `Finsupp` and sum/product/sigma types. ## Tags function with finite support, module, linear algebra -/ noncomputable section open Set LinearMap namespace Finsupp variable {α : Type*} {M : Type*} {N : Type*} {P : Type*} {R : Type*} {S : Type*} variable [Semiring R] [Semiring S] [AddCommMonoid M] [Module R M] variable [AddCommMonoid N] [Module R N] variable [AddCommMonoid P] [Module R P] section Sum variable (R) /-- The linear equivalence between `(α ⊕ β) →₀ M` and `(α →₀ M) × (β →₀ M)`. This is the `LinearEquiv` version of `Finsupp.sumFinsuppEquivProdFinsupp`. -/ @[simps apply symm_apply] def sumFinsuppLEquivProdFinsupp {α β : Type*} : (α ⊕ β →₀ M) ≃ₗ[R] (α →₀ M) × (β →₀ M) := { sumFinsuppAddEquivProdFinsupp with map_smul' := by intros ext <;> simp only [AddEquiv.toFun_eq_coe, Prod.smul_fst, Prod.smul_snd, smul_apply, snd_sumFinsuppAddEquivProdFinsupp, fst_sumFinsuppAddEquivProdFinsupp, RingHom.id_apply] } theorem fst_sumFinsuppLEquivProdFinsupp {α β : Type*} (f : α ⊕ β →₀ M) (x : α) : (sumFinsuppLEquivProdFinsupp R f).1 x = f (Sum.inl x) := rfl theorem snd_sumFinsuppLEquivProdFinsupp {α β : Type*} (f : α ⊕ β →₀ M) (y : β) : (sumFinsuppLEquivProdFinsupp R f).2 y = f (Sum.inr y) := rfl theorem sumFinsuppLEquivProdFinsupp_symm_inl {α β : Type*} (fg : (α →₀ M) × (β →₀ M)) (x : α) : ((sumFinsuppLEquivProdFinsupp R).symm fg) (Sum.inl x) = fg.1 x := rfl theorem sumFinsuppLEquivProdFinsupp_symm_inr {α β : Type*} (fg : (α →₀ M) × (β →₀ M)) (y : β) : ((sumFinsuppLEquivProdFinsupp R).symm fg) (Sum.inr y) = fg.2 y := rfl end Sum section Sigma variable {η : Type*} [Fintype η] {ιs : η → Type*} [Zero α] variable (R) /-- On a `Fintype η`, `Finsupp.split` is a linear equivalence between `(Σ (j : η), ιs j) →₀ M` and `(j : η) → (ιs j →₀ M)`. This is the `LinearEquiv` version of `Finsupp.sigmaFinsuppAddEquivPiFinsupp`. -/ noncomputable def sigmaFinsuppLEquivPiFinsupp {M : Type*} {ιs : η → Type*} [AddCommMonoid M] [Module R M] : ((Σ j, ιs j) →₀ M) ≃ₗ[R] (j : _) → (ιs j →₀ M) := { sigmaFinsuppAddEquivPiFinsupp with map_smul' := fun c f => by ext simp } @[simp] theorem sigmaFinsuppLEquivPiFinsupp_apply {M : Type*} {ιs : η → Type*} [AddCommMonoid M] [Module R M] (f : (Σ j, ιs j) →₀ M) (j i) : sigmaFinsuppLEquivPiFinsupp R f j i = f ⟨j, i⟩ := rfl @[simp] theorem sigmaFinsuppLEquivPiFinsupp_symm_apply {M : Type*} {ιs : η → Type*} [AddCommMonoid M] [Module R M] (f : (j : _) → (ιs j →₀ M)) (ji) : (Finsupp.sigmaFinsuppLEquivPiFinsupp R).symm f ji = f ji.1 ji.2 := rfl end Sigma end Finsupp
.lake/packages/mathlib/Mathlib/LinearAlgebra/Finsupp/LinearCombination.lean
import Mathlib.Algebra.Module.Submodule.Equiv import Mathlib.Data.Finsupp.Option import Mathlib.LinearAlgebra.Finsupp.Supported /-! # `Finsupp.linearCombination` ## Main definitions * `Finsupp.linearCombination R (v : ι → M)`: sends `l : ι →₀ R` to the linear combination of `v i` with coefficients `l i`; * `Finsupp.linearCombinationOn`: a restricted version of `Finsupp.linearCombination` with domain * `Fintype.linearCombination R (v : ι → M)`: sends `l : ι → R` to the linear combination of `v i` with coefficients `l i` (for a finite type `ι`) * `Finsupp.bilinearCombination R S`, `Fintype.bilinearCombination R S`: a bilinear version of `Finsupp.linearCombination` and `Fintype.linearCombination`. It requires that `M` is both an `R`-module and an `S`-module, with `SMulCommClass R S M`; the case `S = R` typically requires that `R` is commutative. ## Tags function with finite support, module, linear algebra -/ noncomputable section open Set LinearMap Submodule namespace Finsupp variable {α : Type*} {M : Type*} {N : Type*} {P : Type*} {R : Type*} {S : Type*} variable [Semiring R] [Semiring S] [AddCommMonoid M] [Module R M] variable [AddCommMonoid N] [Module R N] variable [AddCommMonoid P] [Module R P] section LinearCombination variable (R) variable {α' : Type*} {M' : Type*} [AddCommMonoid M'] [Module R M'] (v : α → M) {v' : α' → M'} /-- Interprets (l : α →₀ R) as a linear combination of the elements in the family (v : α → M) and evaluates this linear combination. -/ def linearCombination : (α →₀ R) →ₗ[R] M := Finsupp.lsum ℕ fun i => LinearMap.id.smulRight (v i) variable {v} theorem linearCombination_apply (l : α →₀ R) : linearCombination R v l = l.sum fun i a => a • v i := rfl theorem linearCombination_apply_of_mem_supported {l : α →₀ R} {s : Finset α} (hs : l ∈ supported R R (↑s : Set α)) : linearCombination R v l = s.sum fun i => l i • v i := Finset.sum_subset hs fun x _ hxg => show l x • v x = 0 by rw [notMem_support_iff.1 hxg, zero_smul] @[simp] theorem linearCombination_single (c : R) (a : α) : linearCombination R v (single a c) = c • v a := by simp [linearCombination_apply, sum_single_index] theorem linearCombination_zero_apply (x : α →₀ R) : (linearCombination R (0 : α → M)) x = 0 := by simp [linearCombination_apply] variable (α M) @[simp] theorem linearCombination_zero : linearCombination R (0 : α → M) = 0 := LinearMap.ext (linearCombination_zero_apply R) @[simp] theorem linearCombination_single_index (c : M) (a : α) (f : α →₀ R) [DecidableEq α] : linearCombination R (Pi.single a c) f = f a • c := by rw [linearCombination_apply, sum_eq_single a, Pi.single_eq_same] · exact fun i _ hi ↦ by rw [Pi.single_eq_of_ne hi, smul_zero] · exact fun _ ↦ by simp only [zero_smul] variable {α M} theorem linearCombination_linear_comp (f : M →ₗ[R] M') : linearCombination R (f ∘ v) = f ∘ₗ linearCombination R v := by ext simp [linearCombination_apply] theorem apply_linearCombination (f : M →ₗ[R] M') (v) (l : α →₀ R) : f (linearCombination R v l) = linearCombination R (f ∘ v) l := congr($(linearCombination_linear_comp R f) l).symm theorem apply_linearCombination_id (f : M →ₗ[R] M') (l : M →₀ R) : f (linearCombination R _root_.id l) = linearCombination R f l := apply_linearCombination .. theorem linearCombination_unique [Unique α] (l : α →₀ R) (v : α → M) : linearCombination R v l = l default • v default := by rw [← linearCombination_single, ← unique_single l] theorem linearCombination_surjective (h : Function.Surjective v) : Function.Surjective (linearCombination R v) := by intro x obtain ⟨y, hy⟩ := h x exact ⟨single y 1, by simp [hy]⟩ theorem linearCombination_range (h : Function.Surjective v) : LinearMap.range (linearCombination R v) = ⊤ := range_eq_top.2 <| linearCombination_surjective R h /-- Any module is a quotient of a free module. This is stated as surjectivity of `Finsupp.linearCombination R id : (M →₀ R) →ₗ[R] M`. -/ theorem linearCombination_id_surjective (M) [AddCommMonoid M] [Module R M] : Function.Surjective (linearCombination R (id : M → M)) := linearCombination_surjective R Function.surjective_id theorem range_linearCombination : LinearMap.range (linearCombination R v) = span R (range v) := by ext x constructor · intro hx rw [LinearMap.mem_range] at hx rcases hx with ⟨l, hl⟩ rw [← hl] rw [linearCombination_apply] exact sum_mem fun i _ => Submodule.smul_mem _ _ (subset_span (mem_range_self i)) · apply span_le.2 intro x hx rcases hx with ⟨i, hi⟩ rw [SetLike.mem_coe, LinearMap.mem_range] use single i 1 simp [hi] theorem lmapDomain_linearCombination (f : α → α') (g : M →ₗ[R] M') (h : ∀ i, g (v i) = v' (f i)) : (linearCombination R v').comp (lmapDomain R R f) = g.comp (linearCombination R v) := by ext l simp [linearCombination_apply, h] theorem linearCombination_comp_lmapDomain (f : α → α') : (linearCombination R v').comp (Finsupp.lmapDomain R R f) = linearCombination R (v' ∘ f) := by ext simp @[simp] theorem linearCombination_embDomain (f : α ↪ α') (l : α →₀ R) : (linearCombination R v') (embDomain f l) = (linearCombination R (v' ∘ f)) l := by simp [linearCombination_apply, Finsupp.sum, support_embDomain, embDomain_apply] @[simp] theorem linearCombination_mapDomain (f : α → α') (l : α →₀ R) : (linearCombination R v') (mapDomain f l) = (linearCombination R (v' ∘ f)) l := LinearMap.congr_fun (linearCombination_comp_lmapDomain _ _) l @[simp] theorem linearCombination_equivMapDomain (f : α ≃ α') (l : α →₀ R) : (linearCombination R v') (equivMapDomain f l) = (linearCombination R (v' ∘ f)) l := by rw [equivMapDomain_eq_mapDomain, linearCombination_mapDomain] /-- A version of `Finsupp.range_linearCombination` which is useful for going in the other direction -/ theorem span_eq_range_linearCombination (s : Set M) : span R s = LinearMap.range (linearCombination R ((↑) : s → M)) := by rw [range_linearCombination, Subtype.range_coe_subtype, Set.setOf_mem_eq] theorem mem_span_iff_linearCombination (s : Set M) (x : M) : x ∈ span R s ↔ ∃ l : s →₀ R, linearCombination R (↑) l = x := (SetLike.ext_iff.1 <| span_eq_range_linearCombination _ _) x variable {R} in theorem mem_span_range_iff_exists_finsupp {v : α → M} {x : M} : x ∈ span R (range v) ↔ ∃ c : α →₀ R, (c.sum fun i a => a • v i) = x := by simp only [← Finsupp.range_linearCombination, LinearMap.mem_range, linearCombination_apply] theorem span_image_eq_map_linearCombination (s : Set α) : span R (v '' s) = Submodule.map (linearCombination R v) (supported R R s) := by apply span_eq_of_le · intro x hx rw [Set.mem_image] at hx apply Exists.elim hx intro i hi exact ⟨_, Finsupp.single_mem_supported R 1 hi.1, by simp [hi.2]⟩ · refine map_le_iff_le_comap.2 fun z hz => ?_ have : ∀ i, z i • v i ∈ span R (v '' s) := by intro c haveI := Classical.decPred fun x => x ∈ s by_cases h : c ∈ s · exact smul_mem _ _ (subset_span (Set.mem_image_of_mem _ h)) · simp [(Finsupp.mem_supported' R _).1 hz _ h] rw [mem_comap, linearCombination_apply] refine sum_mem ?_ simp [this] theorem mem_span_image_iff_linearCombination {s : Set α} {x : M} : x ∈ span R (v '' s) ↔ ∃ l ∈ supported R R s, linearCombination R v l = x := by rw [span_image_eq_map_linearCombination] simp theorem linearCombination_option (v : Option α → M) (f : Option α →₀ R) : linearCombination R v f = f none • v none + linearCombination R (v ∘ Option.some) f.some := by rw [linearCombination_apply, sum_option_index_smul, linearCombination_apply]; simp theorem linearCombination_linearCombination {α β : Type*} (A : α → M) (B : β → α →₀ R) (f : β →₀ R) : linearCombination R A (linearCombination R B f) = linearCombination R (fun b => linearCombination R A (B b)) f := by classical simp only [linearCombination_apply] induction f using induction_linear with | zero => simp only [sum_zero_index] | add f₁ f₂ h₁ h₂ => simp [sum_add_index, h₁, h₂, add_smul] | single => simp [sum_single_index, sum_smul_index, smul_sum, mul_smul] theorem linearCombination_smul [DecidableEq α] [Module R S] [Module S M] [IsScalarTower R S M] {w : α' → S} : linearCombination R (fun i : α × α' ↦ w i.2 • v i.1) = (linearCombination S v).restrictScalars R ∘ₗ mapRange.linearMap (linearCombination R w) ∘ₗ (finsuppProdLEquiv R).toLinearMap := by ext; simp @[simp] theorem linearCombination_fin_zero (f : Fin 0 → M) : linearCombination R f = 0 := by ext i apply finZeroElim i variable (α) (M) (v) /-- `Finsupp.linearCombinationOn M v s` interprets `p : α →₀ R` as a linear combination of a subset of the vectors in `v`, mapping it to the span of those vectors. The subset is indicated by a set `s : Set α` of indices. -/ def linearCombinationOn (s : Set α) : supported R R s →ₗ[R] span R (v '' s) := LinearMap.codRestrict _ ((linearCombination _ v).comp (Submodule.subtype (supported R R s))) fun ⟨l, hl⟩ => (mem_span_image_iff_linearCombination _).2 ⟨l, hl, rfl⟩ variable {α} {M} {v} theorem linearCombinationOn_range (s : Set α) : LinearMap.range (linearCombinationOn α M R v s) = ⊤ := by rw [linearCombinationOn, LinearMap.range_eq_map, LinearMap.map_codRestrict, ← LinearMap.range_le_iff_comap, range_subtype, Submodule.map_top, LinearMap.range_comp, range_subtype] exact (span_image_eq_map_linearCombination _ _).le theorem linearCombination_restrict (s : Set α) : linearCombination R (s.restrict v) = Submodule.subtype _ ∘ₗ linearCombinationOn α M R v s ∘ₗ (supportedEquivFinsupp s).symm.toLinearMap := by classical ext; simp [linearCombinationOn] theorem linearCombination_comp (f : α' → α) : linearCombination R (v ∘ f) = (linearCombination R v).comp (lmapDomain R R f) := by ext simp [linearCombination_apply] theorem linearCombination_comapDomain (f : α → α') (l : α' →₀ R) (hf : Set.InjOn f (f ⁻¹' ↑l.support)) : linearCombination R v (Finsupp.comapDomain f l hf) = (l.support.preimage f hf).sum fun i => l (f i) • v i := by rw [linearCombination_apply]; rfl theorem linearCombination_onFinset {s : Finset α} {f : α → R} (g : α → M) (hf : ∀ a, f a ≠ 0 → a ∈ s) : linearCombination R g (Finsupp.onFinset s f hf) = Finset.sum s fun x : α => f x • g x := by classical simp only [linearCombination_apply, Finsupp.sum, Finsupp.onFinset_apply, Finsupp.support_onFinset] rw [Finset.sum_filter_of_ne] intro x _ h contrapose! h simp [h] variable [Module S M] [SMulCommClass R S M] variable (S) in /-- `Finsupp.bilinearCombination R S v f` is the linear combination of vectors in `v` with weights in `f`, as a bilinear map of `v` and `f`. In the absence of `SMulCommClass R S M`, use `Finsupp.linearCombination`. See note [bundled maps over different rings] for why separate `R` and `S` semirings are used. -/ def bilinearCombination : (α → M) →ₗ[S] (α →₀ R) →ₗ[R] M where toFun v := linearCombination R v map_add' u v := by ext; simp [Pi.add_apply, smul_add] map_smul' r v := by ext; simp [smul_comm] @[simp] theorem bilinearCombination_apply : bilinearCombination R S v = linearCombination R v := rfl end LinearCombination end Finsupp section Fintype variable {α M : Type*} (R : Type*) [Fintype α] [Semiring R] [AddCommMonoid M] [Module R M] variable (S : Type*) [Semiring S] [Module S M] [SMulCommClass R S M] variable (v : α → M) /-- `Fintype.linearCombination R v f` is the linear combination of vectors in `v` with weights in `f`. This variant of `Finsupp.linearCombination` is defined on fintype indexed vectors. This map is linear in `v` if `R` is commutative, and always linear in `f`. See note [bundled maps over different rings] for why separate `R` and `S` semirings are used. -/ protected def Fintype.linearCombination : (α → R) →ₗ[R] M where toFun f := ∑ i, f i • v i map_add' f g := by simp_rw [← Finset.sum_add_distrib, ← add_smul]; rfl map_smul' r f := by simp_rw [Finset.smul_sum, smul_smul]; rfl theorem Fintype.linearCombination_apply (f) : Fintype.linearCombination R v f = ∑ i, f i • v i := rfl @[simp] theorem Fintype.linearCombination_apply_single [DecidableEq α] (i : α) (r : R) : Fintype.linearCombination R v (Pi.single i r) = r • v i := by simp_rw [Fintype.linearCombination_apply, Pi.single_apply, ite_smul, zero_smul] rw [Finset.sum_ite_eq', if_pos (Finset.mem_univ _)] theorem Finsupp.linearCombination_eq_fintype_linearCombination_apply (x : α → R) : linearCombination R v ((Finsupp.linearEquivFunOnFinite R R α).symm x) = Fintype.linearCombination R v x := by apply Finset.sum_subset · exact Finset.subset_univ _ · intro x _ hx rw [Finsupp.notMem_support_iff.mp hx] exact zero_smul _ _ theorem Finsupp.linearCombination_eq_fintype_linearCombination : (linearCombination R v).comp (Finsupp.linearEquivFunOnFinite R R α).symm.toLinearMap = Fintype.linearCombination R v := LinearMap.ext <| linearCombination_eq_fintype_linearCombination_apply R v @[simp] theorem Fintype.range_linearCombination : LinearMap.range (Fintype.linearCombination R v) = Submodule.span R (Set.range v) := by rw [← Finsupp.linearCombination_eq_fintype_linearCombination, LinearMap.range_comp, LinearEquiv.range, Submodule.map_top, Finsupp.range_linearCombination] /-- `Fintype.bilinearCombination R S v f` is the linear combination of vectors in `v` with weights in `f`. This variant of `Finsupp.linearCombination` is defined on fintype indexed vectors. This map is linear in `v` if `R` is commutative, and always linear in `f`. See note [bundled maps over different rings] for why separate `R` and `S` semirings are used. -/ protected def Fintype.bilinearCombination : (α → M) →ₗ[S] (α → R) →ₗ[R] M where toFun v := Fintype.linearCombination R v map_add' u v := by ext; simp [Fintype.linearCombination, Finset.sum_add_distrib, Pi.add_apply, smul_add] map_smul' r v := by ext; simp [Fintype.linearCombination, Finset.smul_sum, smul_comm] variable {S} @[simp] theorem Fintype.bilinearCombination_apply : Fintype.bilinearCombination R S v = Fintype.linearCombination R v := rfl theorem Fintype.bilinearCombination_apply_single [DecidableEq α] (i : α) (r : R) : Fintype.bilinearCombination R S v (Pi.single i r) = r • v i := by simp [Fintype.bilinearCombination] section SpanRange variable {v} {x : M} /-- An element `x` lies in the span of `v` iff it can be written as sum `∑ cᵢ • vᵢ = x`. -/ theorem Submodule.mem_span_range_iff_exists_fun : x ∈ span R (range v) ↔ ∃ c : α → R, ∑ i, c i • v i = x := by rw [Finsupp.equivFunOnFinite.surjective.exists] simp only [Finsupp.mem_span_range_iff_exists_finsupp, Finsupp.equivFunOnFinite_apply] exact exists_congr fun c => Eq.congr_left <| Finsupp.sum_fintype _ _ fun i => zero_smul _ _ /-- A family `v : α → V` is generating `V` iff every element `(x : V)` can be written as sum `∑ cᵢ • vᵢ = x`. -/ theorem Submodule.top_le_span_range_iff_forall_exists_fun : ⊤ ≤ span R (range v) ↔ ∀ x, ∃ c : α → R, ∑ i, c i • v i = x := by simp_rw [← mem_span_range_iff_exists_fun] exact ⟨fun h x => h trivial, fun h x _ => h x⟩ omit [Fintype α] theorem Submodule.mem_span_image_iff_exists_fun {s : Set α} : x ∈ span R (v '' s) ↔ ∃ t : Finset α, ↑t ⊆ s ∧ ∃ c : t → R, ∑ i, c i • v i = x := by refine ⟨fun h ↦ ?_, fun ⟨t, ht, c, hx⟩ ↦ ?_⟩ · obtain ⟨l, hl, hx⟩ := (Finsupp.mem_span_image_iff_linearCombination R).mp h refine ⟨l.support, hl, l ∘ (↑), ?_⟩ rw [← hx] exact l.support.sum_coe_sort fun a ↦ l a • v a · rw [← hx] exact sum_smul_mem (span R (v '' s)) c fun a _ ↦ subset_span <| by aesop theorem Fintype.mem_span_image_iff_exists_fun {s : Set α} [Fintype s] : x ∈ span R (v '' s) ↔ ∃ c : s → R, ∑ i, c i • v i = x := by rw [← mem_span_range_iff_exists_fun, image_eq_range] end SpanRange end Fintype variable {R : Type*} {M : Type*} {N : Type*} variable [Semiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N] open Finsupp section variable (R) /-- Pick some representation of `x : span R w` as a linear combination in `w`, ((Finsupp.mem_span_iff_linearCombination _ _ _).mp x.2).choose -/ irreducible_def Span.repr (w : Set M) (x : span R w) : w →₀ R := ((Finsupp.mem_span_iff_linearCombination _ _ _).mp x.2).choose @[simp] theorem Span.finsupp_linearCombination_repr {w : Set M} (x : span R w) : Finsupp.linearCombination R ((↑) : w → M) (Span.repr R w x) = x := by rw [Span.repr_def] exact ((Finsupp.mem_span_iff_linearCombination _ _ _).mp x.2).choose_spec end theorem LinearMap.map_finsupp_linearCombination (f : M →ₗ[R] N) {ι : Type*} {g : ι → M} (l : ι →₀ R) : f (linearCombination R g l) = linearCombination R (f ∘ g) l := apply_linearCombination _ _ _ _ lemma Submodule.mem_span_iff_exists_finset_subset {s : Set M} {x : M} : x ∈ span R s ↔ ∃ (f : M → R) (t : Finset M), ↑t ⊆ s ∧ f.support ⊆ t ∧ ∑ a ∈ t, f a • a = x where mp := by rw [← s.image_id, mem_span_image_iff_linearCombination] rintro ⟨l, hl, rfl⟩ exact ⟨l, l.support, by simpa [linearCombination, Finsupp.sum] using hl⟩ mpr := by rintro ⟨n, t, hts, -, rfl⟩; exact sum_mem fun x hx ↦ smul_mem _ _ <| subset_span <| hts hx lemma Submodule.mem_span_finset {s : Finset M} {x : M} : x ∈ span R s ↔ ∃ f : M → R, f.support ⊆ s ∧ ∑ a ∈ s, f a • a = x where mp := by rw [mem_span_iff_exists_finset_subset] rintro ⟨f, t, hts, hf, rfl⟩ refine ⟨f, hf.trans hts, .symm <| Finset.sum_subset hts ?_⟩ simp +contextual [Function.support_subset_iff'.1 hf] mpr := by rintro ⟨f, -, rfl⟩; exact sum_mem fun x hx ↦ smul_mem _ _ <| subset_span <| hx lemma Submodule.mem_span_iff_of_fintype {s : Set M} [Fintype s] {x : M} : x ∈ span R s ↔ ∃ f : s → R, ∑ a : s, f a • a.1 = x := by conv_lhs => rw [← Subtype.range_val (s := s)] exact mem_span_range_iff_exists_fun _ /-- A variant of `Submodule.mem_span_finset` using `s` as the index type. -/ lemma Submodule.mem_span_finset' {s : Finset M} {x : M} : x ∈ span R s ↔ ∃ f : s → R, ∑ a : s, f a • a.1 = x := mem_span_iff_of_fintype /-- An element `m ∈ M` is contained in the `R`-submodule spanned by a set `s ⊆ M`, if and only if `m` can be written as a finite `R`-linear combination of elements of `s`. The implementation uses `Finsupp.sum`. -/ theorem Submodule.mem_span_set {m : M} {s : Set M} : m ∈ Submodule.span R s ↔ ∃ c : M →₀ R, (c.support : Set M) ⊆ s ∧ (c.sum fun mi r => r • mi) = m := by conv_lhs => rw [← Set.image_id s] exact Finsupp.mem_span_image_iff_linearCombination R (v := _root_.id (α := M)) /-- An element `m ∈ M` is contained in the `R`-submodule spanned by a set `s ⊆ M`, if and only if `m` can be written as a finite `R`-linear combination of elements of `s`. The implementation uses a sum indexed by `Fin n` for some `n`. -/ lemma Submodule.mem_span_set' {m : M} {s : Set M} : m ∈ Submodule.span R s ↔ ∃ (n : ℕ) (f : Fin n → R) (g : Fin n → s), ∑ i, f i • (g i : M) = m := by refine ⟨fun h ↦ ?_, ?_⟩ · rcases mem_span_set.1 h with ⟨c, cs, rfl⟩ have A : c.support ≃ Fin c.support.card := Finset.equivFin _ refine ⟨_, fun i ↦ c (A.symm i), fun i ↦ ⟨A.symm i, cs (A.symm i).2⟩, ?_⟩ rw [Finsupp.sum, ← Finset.sum_coe_sort c.support] exact Fintype.sum_equiv A.symm _ (fun j ↦ c j • (j : M)) (fun i ↦ rfl) · rintro ⟨n, f, g, rfl⟩ exact Submodule.sum_mem _ (fun i _ ↦ Submodule.smul_mem _ _ (Submodule.subset_span (g i).2)) /-- The span of a subset `s` is the union over all `n` of the set of linear combinations of at most `n` terms belonging to `s`. -/ lemma Submodule.span_eq_iUnion_nat (s : Set M) : (Submodule.span R s : Set M) = ⋃ (n : ℕ), (fun (f : Fin n → (R × M)) ↦ ∑ i, (f i).1 • (f i).2) '' ({f | ∀ i, (f i).2 ∈ s}) := by ext m simp only [SetLike.mem_coe, mem_iUnion, mem_image, mem_setOf_eq, mem_span_set'] refine exists_congr (fun n ↦ ⟨?_, ?_⟩) · rintro ⟨f, g, rfl⟩ exact ⟨fun i ↦ (f i, g i), fun i ↦ (g i).2, rfl⟩ · rintro ⟨f, hf, rfl⟩ exact ⟨fun i ↦ (f i).1, fun i ↦ ⟨(f i).2, (hf i)⟩, rfl⟩ section Ring variable {R M ι : Type*} [Ring R] [AddCommGroup M] [Module R M] (i : ι) (c : ι → R) (h₀ : c i = 0) /-- Given `c : ι → R` and an index `i` such that `c i = 0`, this is the linear isomorphism sending the `j`-th standard basis vector to itself plus `c j` multiplied with the `i`-th standard basis vector (in particular, the `i`-th standard basis vector is kept invariant). -/ def Finsupp.addSingleEquiv : (ι →₀ R) ≃ₗ[R] (ι →₀ R) := by refine .ofLinear (linearCombination _ fun j ↦ single j 1 + single i (c j)) (linearCombination _ fun j ↦ single j 1 - single i (c j)) ?_ ?_ <;> ext j k <;> obtain rfl | hk := eq_or_ne i k · simp [h₀] · simp [hk] · simp [h₀] · simp [hk] theorem Finsupp.linearCombination_comp_addSingleEquiv (v : ι → M) : linearCombination R v ∘ₗ addSingleEquiv i c h₀ = linearCombination R (v + (c · • v i)) := by ext; simp [addSingleEquiv] end Ring
.lake/packages/mathlib/Mathlib/LinearAlgebra/SModEq/Basic.lean
import Mathlib.Algebra.Module.Submodule.Map import Mathlib.Algebra.Polynomial.Eval.Defs import Mathlib.RingTheory.Ideal.Quotient.Defs /-! # modular equivalence for submodule -/ open Submodule open Polynomial variable {R : Type*} [Ring R] variable {A : Type*} [CommRing A] variable {M : Type*} [AddCommGroup M] [Module R M] (U U₁ U₂ : Submodule R M) variable {x x₁ x₂ y y₁ y₂ z z₁ z₂ : M} variable {N : Type*} [AddCommGroup N] [Module R N] (V V₁ V₂ : Submodule R N) /-- A predicate saying two elements of a module are equivalent modulo a submodule. -/ def SModEq (x y : M) : Prop := (Submodule.Quotient.mk x : M ⧸ U) = Submodule.Quotient.mk y @[inherit_doc] notation:50 x " ≡ " y " [SMOD " N "]" => SModEq N x y variable {U U₁ U₂} protected theorem SModEq.def : x ≡ y [SMOD U] ↔ (Submodule.Quotient.mk x : M ⧸ U) = Submodule.Quotient.mk y := Iff.rfl namespace SModEq theorem sub_mem : x ≡ y [SMOD U] ↔ x - y ∈ U := by rw [SModEq.def, Submodule.Quotient.eq] @[simp] theorem top : x ≡ y [SMOD (⊤ : Submodule R M)] := (Submodule.Quotient.eq ⊤).2 mem_top @[simp] theorem bot : x ≡ y [SMOD (⊥ : Submodule R M)] ↔ x = y := by rw [SModEq.def, Submodule.Quotient.eq, mem_bot, sub_eq_zero] @[mono] theorem mono (HU : U₁ ≤ U₂) (hxy : x ≡ y [SMOD U₁]) : x ≡ y [SMOD U₂] := (Submodule.Quotient.eq U₂).2 <| HU <| (Submodule.Quotient.eq U₁).1 hxy @[refl] protected theorem refl (x : M) : x ≡ x [SMOD U] := @rfl _ _ protected theorem rfl : x ≡ x [SMOD U] := SModEq.refl _ instance : IsRefl _ (SModEq U) := ⟨SModEq.refl⟩ @[symm] nonrec theorem symm (hxy : x ≡ y [SMOD U]) : y ≡ x [SMOD U] := hxy.symm theorem comm : x ≡ y [SMOD U] ↔ y ≡ x [SMOD U] := ⟨symm, symm⟩ @[trans] nonrec theorem trans (hxy : x ≡ y [SMOD U]) (hyz : y ≡ z [SMOD U]) : x ≡ z [SMOD U] := hxy.trans hyz instance instTrans : Trans (SModEq U) (SModEq U) (SModEq U) where trans := trans @[gcongr] theorem add (hxy₁ : x₁ ≡ y₁ [SMOD U]) (hxy₂ : x₂ ≡ y₂ [SMOD U]) : x₁ + x₂ ≡ y₁ + y₂ [SMOD U] := by rw [SModEq.def] at hxy₁ hxy₂ ⊢ simp_rw [Quotient.mk_add, hxy₁, hxy₂] @[gcongr] theorem sum {ι} {s : Finset ι} {x y : ι → M} (hxy : ∀ i ∈ s, x i ≡ y i [SMOD U]) : ∑ i ∈ s, x i ≡ ∑ i ∈ s, y i [SMOD U] := by classical induction s using Finset.cons_induction with | empty => simp [SModEq.rfl] | cons i s _ ih => grw [Finset.sum_cons, Finset.sum_cons, hxy i (Finset.mem_cons_self i s), ih (fun j hj ↦ hxy j (Finset.mem_cons_of_mem hj))] @[gcongr] theorem smul (hxy : x ≡ y [SMOD U]) (c : R) : c • x ≡ c • y [SMOD U] := by rw [SModEq.def] at hxy ⊢ simp_rw [Quotient.mk_smul, hxy] @[gcongr] lemma nsmul (hxy : x ≡ y [SMOD U]) (n : ℕ) : n • x ≡ n • y [SMOD U] := by rw [SModEq.def] at hxy ⊢ simp_rw [Quotient.mk_smul, hxy] @[gcongr] lemma zsmul (hxy : x ≡ y [SMOD U]) (n : ℤ) : n • x ≡ n • y [SMOD U] := by rw [SModEq.def] at hxy ⊢ simp_rw [Quotient.mk_smul, hxy] @[gcongr] theorem mul {I : Ideal A} {x₁ x₂ y₁ y₂ : A} (hxy₁ : x₁ ≡ y₁ [SMOD I]) (hxy₂ : x₂ ≡ y₂ [SMOD I]) : x₁ * x₂ ≡ y₁ * y₂ [SMOD I] := by simp only [SModEq.def, Ideal.Quotient.mk_eq_mk, map_mul] at hxy₁ hxy₂ ⊢ rw [hxy₁, hxy₂] @[gcongr] theorem prod {I : Ideal A} {ι} {s : Finset ι} {x y : ι → A} (hxy : ∀ i ∈ s, x i ≡ y i [SMOD I]) : ∏ i ∈ s, x i ≡ ∏ i ∈ s, y i [SMOD I] := by classical induction s using Finset.cons_induction with | empty => simp [SModEq.rfl] | cons i s _ ih => grw [Finset.prod_cons, Finset.prod_cons, hxy i (Finset.mem_cons_self i s), ih (fun j hj ↦ hxy j (Finset.mem_cons_of_mem hj))] @[gcongr] lemma pow {I : Ideal A} {x y : A} (n : ℕ) (hxy : x ≡ y [SMOD I]) : x ^ n ≡ y ^ n [SMOD I] := by simp only [SModEq.def, Ideal.Quotient.mk_eq_mk, map_pow] at hxy ⊢ rw [hxy] @[gcongr] lemma neg (hxy : x ≡ y [SMOD U]) : - x ≡ - y [SMOD U] := by simpa only [SModEq.def, Quotient.mk_neg, neg_inj] @[gcongr] lemma sub (hxy₁ : x₁ ≡ y₁ [SMOD U]) (hxy₂ : x₂ ≡ y₂ [SMOD U]) : x₁ - x₂ ≡ y₁ - y₂ [SMOD U] := by rw [SModEq.def] at hxy₁ hxy₂ ⊢ simp_rw [Quotient.mk_sub, hxy₁, hxy₂] theorem zero : x ≡ 0 [SMOD U] ↔ x ∈ U := by rw [SModEq.def, Submodule.Quotient.eq, sub_zero] theorem _root_.sub_smodEq_zero : x - y ≡ 0 [SMOD U] ↔ x ≡ y [SMOD U] := by simp only [SModEq.sub_mem, sub_zero] theorem map (hxy : x ≡ y [SMOD U]) (f : M →ₗ[R] N) : f x ≡ f y [SMOD U.map f] := (Submodule.Quotient.eq _).2 <| f.map_sub x y ▸ mem_map_of_mem <| (Submodule.Quotient.eq _).1 hxy theorem comap {f : M →ₗ[R] N} (hxy : f x ≡ f y [SMOD V]) : x ≡ y [SMOD V.comap f] := (Submodule.Quotient.eq _).2 <| show f (x - y) ∈ V from (f.map_sub x y).symm ▸ (Submodule.Quotient.eq _).1 hxy @[gcongr] theorem eval {R : Type*} [CommRing R] {I : Ideal R} {x y : R} (h : x ≡ y [SMOD I]) (f : R[X]) : f.eval x ≡ f.eval y [SMOD I] := by simp_rw [Polynomial.eval_eq_sum, Polynomial.sum] gcongr end SModEq
.lake/packages/mathlib/Mathlib/LinearAlgebra/DirectSum/Finite.lean
import Mathlib.Algebra.DirectSum.Module import Mathlib.RingTheory.Finiteness.Basic /-! # A finite direct sum of finite modules is finite This file defines a `Module.Finite` instance for a finite direct sum of finite modules. -/ open DirectSum variable {R ι : Type*} [Semiring R] [Finite ι] (M : ι → Type*) [∀ i : ι, AddCommMonoid (M i)] [∀ i : ι, Module R (M i)] [∀ (i : ι), Module.Finite R (M i)] instance Module.Finite.instDFinsupp : Module.Finite R (Π₀ (i : ι), M i) := letI : Fintype ι := Fintype.ofFinite _ Module.Finite.equiv DFinsupp.linearEquivFunOnFintype.symm instance Module.Finite.instDirectSum : Module.Finite R (⨁ i, M i) := Module.Finite.instDFinsupp M
.lake/packages/mathlib/Mathlib/LinearAlgebra/DirectSum/TensorProduct.lean
import Mathlib.LinearAlgebra.TensorProduct.Tower import Mathlib.Algebra.DirectSum.Module /-! # Tensor products of direct sums This file shows that taking `TensorProduct`s commutes with taking `DirectSum`s in both arguments. ## Main results * `TensorProduct.directSum` * `TensorProduct.directSumLeft` * `TensorProduct.directSumRight` -/ universe u v₁ v₂ w₁ w₁' w₂ w₂' section Ring namespace TensorProduct open TensorProduct open DirectSum open LinearMap attribute [local ext] TensorProduct.ext variable (R : Type u) [CommSemiring R] (S) [Semiring S] [Algebra R S] variable {ι₁ : Type v₁} {ι₂ : Type v₂} variable [DecidableEq ι₁] [DecidableEq ι₂] variable (M₁ : ι₁ → Type w₁) (M₁' : Type w₁') (M₂ : ι₂ → Type w₂) (M₂' : Type w₂') variable [∀ i₁, AddCommMonoid (M₁ i₁)] [AddCommMonoid M₁'] variable [∀ i₂, AddCommMonoid (M₂ i₂)] [AddCommMonoid M₂'] variable [∀ i₁, Module R (M₁ i₁)] [Module R M₁'] [∀ i₂, Module R (M₂ i₂)] [Module R M₂'] variable [∀ i₁, Module S (M₁ i₁)] [∀ i₁, IsScalarTower R S (M₁ i₁)] /-- The linear equivalence `(⨁ i₁, M₁ i₁) ⊗ (⨁ i₂, M₂ i₂) ≃ (⨁ i₁, ⨁ i₂, M₁ i₁ ⊗ M₂ i₂)`, i.e. "tensor product distributes over direct sum". -/ protected def directSum : ((⨁ i₁, M₁ i₁) ⊗[R] ⨁ i₂, M₂ i₂) ≃ₗ[S] ⨁ i : ι₁ × ι₂, M₁ i.1 ⊗[R] M₂ i.2 := by refine LinearEquiv.ofLinear ?toFun ?invFun ?left ?right · exact AlgebraTensorModule.lift <| toModule S _ _ fun i₁ => flip <| toModule R _ _ fun i₂ => flip <| AlgebraTensorModule.curry <| DirectSum.lof S (ι₁ × ι₂) (fun i => M₁ i.1 ⊗[R] M₂ i.2) (i₁, i₂) · exact toModule S _ _ fun i => AlgebraTensorModule.map (lof S _ M₁ i.1) (lof R _ M₂ i.2) · ext ⟨i₁, i₂⟩ x₁ x₂ : 4 simp only [coe_comp, Function.comp_apply, toModule_lof, AlgebraTensorModule.map_tmul, AlgebraTensorModule.lift_apply, lift.tmul, coe_restrictScalars, flip_apply, AlgebraTensorModule.curry_apply, curry_apply, id_comp] · ext i₁ i₂ x₁ x₂ : 5 simp only [coe_comp, Function.comp_apply, AlgebraTensorModule.curry_apply, curry_apply, coe_restrictScalars, AlgebraTensorModule.lift_apply, lift.tmul, toModule_lof, flip_apply, AlgebraTensorModule.map_tmul, id_coe, id_eq] /-- Tensor products distribute over a direct sum on the left . -/ def directSumLeft : (⨁ i₁, M₁ i₁) ⊗[R] M₂' ≃ₗ[R] ⨁ i, M₁ i ⊗[R] M₂' := LinearEquiv.ofLinear (lift <| DirectSum.toModule R _ _ fun _ => (mk R _ _).compr₂ <| DirectSum.lof R ι₁ (fun i => M₁ i ⊗[R] M₂') _) (DirectSum.toModule R _ _ fun _ => rTensor _ (DirectSum.lof R ι₁ _ _)) (DirectSum.linearMap_ext R fun i => TensorProduct.ext <| LinearMap.ext₂ fun m₁ m₂ => by dsimp only [comp_apply, compr₂ₛₗ_apply, id_apply, mk_apply] simp_rw [DirectSum.toModule_lof, rTensor_tmul, lift.tmul, DirectSum.toModule_lof, compr₂_apply, mk_apply]) (TensorProduct.ext <| DirectSum.linearMap_ext R fun i => LinearMap.ext₂ fun m₁ m₂ => by dsimp only [comp_apply, compr₂ₛₗ_apply, id_apply, mk_apply] simp_rw [lift.tmul, DirectSum.toModule_lof, compr₂_apply, mk_apply, DirectSum.toModule_lof, rTensor_tmul]) /-- Tensor products distribute over a direct sum on the right. -/ def directSumRight : (M₁' ⊗[R] ⨁ i, M₂ i) ≃ₗ[R] ⨁ i, M₁' ⊗[R] M₂ i := TensorProduct.comm R _ _ ≪≫ₗ directSumLeft R M₂ M₁' ≪≫ₗ DFinsupp.mapRange.linearEquiv fun _ => TensorProduct.comm R _ _ variable {M₁ M₁' M₂ M₂'} @[simp] theorem directSum_lof_tmul_lof (i₁ : ι₁) (m₁ : M₁ i₁) (i₂ : ι₂) (m₂ : M₂ i₂) : TensorProduct.directSum R S M₁ M₂ (DirectSum.lof S ι₁ M₁ i₁ m₁ ⊗ₜ DirectSum.lof R ι₂ M₂ i₂ m₂) = DirectSum.lof S (ι₁ × ι₂) (fun i => M₁ i.1 ⊗[R] M₂ i.2) (i₁, i₂) (m₁ ⊗ₜ m₂) := by simp [TensorProduct.directSum] @[simp] theorem directSum_symm_lof_tmul (i₁ : ι₁) (m₁ : M₁ i₁) (i₂ : ι₂) (m₂ : M₂ i₂) : (TensorProduct.directSum R S M₁ M₂).symm (DirectSum.lof S (ι₁ × ι₂) (fun i => M₁ i.1 ⊗[R] M₂ i.2) (i₁, i₂) (m₁ ⊗ₜ m₂)) = (DirectSum.lof S ι₁ M₁ i₁ m₁ ⊗ₜ DirectSum.lof R ι₂ M₂ i₂ m₂) := by rw [LinearEquiv.symm_apply_eq, directSum_lof_tmul_lof] @[simp] theorem directSumLeft_tmul_lof (i : ι₁) (x : M₁ i) (y : M₂') : directSumLeft R M₁ M₂' (DirectSum.lof R _ _ i x ⊗ₜ[R] y) = DirectSum.lof R _ _ i (x ⊗ₜ[R] y) := by dsimp only [directSumLeft, LinearEquiv.ofLinear_apply, lift.tmul] rw [DirectSum.toModule_lof R i] rfl @[simp] theorem directSumLeft_symm_lof_tmul (i : ι₁) (x : M₁ i) (y : M₂') : (directSumLeft R M₁ M₂').symm (DirectSum.lof R _ _ i (x ⊗ₜ[R] y)) = DirectSum.lof R _ _ i x ⊗ₜ[R] y := by rw [LinearEquiv.symm_apply_eq, directSumLeft_tmul_lof] @[simp] theorem directSumRight_tmul_lof (x : M₁') (i : ι₂) (y : M₂ i) : directSumRight R M₁' M₂ (x ⊗ₜ[R] DirectSum.lof R _ _ i y) = DirectSum.lof R _ _ i (x ⊗ₜ[R] y) := by dsimp only [directSumRight, LinearEquiv.trans_apply, TensorProduct.comm_tmul] rw [directSumLeft_tmul_lof] exact DFinsupp.mapRange_single (hf := fun _ => rfl) @[simp] theorem directSumRight_symm_lof_tmul (x : M₁') (i : ι₂) (y : M₂ i) : (directSumRight R M₁' M₂).symm (DirectSum.lof R _ _ i (x ⊗ₜ[R] y)) = x ⊗ₜ[R] DirectSum.lof R _ _ i y := by rw [LinearEquiv.symm_apply_eq, directSumRight_tmul_lof] lemma directSumRight_comp_rTensor (f : M₁' →ₗ[R] M₂') : (directSumRight R M₂' M₁).toLinearMap ∘ₗ f.rTensor _ = (lmap fun _ ↦ f.rTensor _) ∘ₗ directSumRight R M₁' M₁ := by ext; simp end TensorProduct end Ring
.lake/packages/mathlib/Mathlib/LinearAlgebra/DirectSum/Finsupp.lean
import Mathlib.Algebra.DirectSum.Finsupp import Mathlib.LinearAlgebra.DirectSum.TensorProduct import Mathlib.LinearAlgebra.Finsupp.SumProd /-! # Results on finitely supported functions. * `TensorProduct.finsuppLeft`, the tensor product of `ι →₀ M` and `N` is linearly equivalent to `ι →₀ M ⊗[R] N` * `TensorProduct.finsuppScalarLeft`, the tensor product of `ι →₀ R` and `N` is linearly equivalent to `ι →₀ N` * `TensorProduct.finsuppRight`, the tensor product of `M` and `ι →₀ N` is linearly equivalent to `ι →₀ M ⊗[R] N` * `TensorProduct.finsuppScalarRight`, the tensor product of `M` and `ι →₀ R` is linearly equivalent to `ι →₀ N` * `TensorProduct.finsuppLeft'`, if `M` is an `S`-module, then the tensor product of `ι →₀ M` and `N` is `S`-linearly equivalent to `ι →₀ M ⊗[R] N` * `finsuppTensorFinsupp`, the tensor product of `ι →₀ M` and `κ →₀ N` is linearly equivalent to `(ι × κ) →₀ (M ⊗ N)`. ## Case of MvPolynomial These functions apply to `MvPolynomial`, one can define ``` noncomputable def MvPolynomial.rTensor' : MvPolynomial σ S ⊗[R] N ≃ₗ[S] (σ →₀ ℕ) →₀ (S ⊗[R] N) := TensorProduct.finsuppLeft' noncomputable def MvPolynomial.rTensor : MvPolynomial σ R ⊗[R] N ≃ₗ[R] (σ →₀ ℕ) →₀ N := TensorProduct.finsuppScalarLeft ``` However, to be actually usable, these definitions need lemmas to be given in companion PR. ## Case of `Polynomial` `Polynomial` is a structure containing a `Finsupp`, so these functions can't be applied directly to `Polynomial`. Some linear equivs need to be added to mathlib for that. This belongs to a companion PR. ## TODO * generalize to `MonoidAlgebra`, `AlgHom ` * reprove `TensorProduct.finsuppLeft'` using existing heterobasic version of `TensorProduct.congr` -/ noncomputable section open DirectSum TensorProduct open Set LinearMap Submodule section TensorProduct variable (R : Type*) [CommSemiring R] (M : Type*) [AddCommMonoid M] [Module R M] (N : Type*) [AddCommMonoid N] [Module R N] namespace TensorProduct variable (ι : Type*) [DecidableEq ι] /-- The tensor product of `ι →₀ M` and `N` is linearly equivalent to `ι →₀ M ⊗[R] N` -/ noncomputable def finsuppLeft : (ι →₀ M) ⊗[R] N ≃ₗ[R] ι →₀ M ⊗[R] N := congr (finsuppLEquivDirectSum R M ι) (.refl R N) ≪≫ₗ directSumLeft R (fun _ ↦ M) N ≪≫ₗ (finsuppLEquivDirectSum R _ ι).symm variable {R M N ι} lemma finsuppLeft_apply_tmul (p : ι →₀ M) (n : N) : finsuppLeft R M N ι (p ⊗ₜ[R] n) = p.sum fun i m ↦ Finsupp.single i (m ⊗ₜ[R] n) := by induction p using Finsupp.induction_linear with | zero => simp | add f g hf hg => simp [add_tmul, map_add, hf, hg, Finsupp.sum_add_index] | single => simp [finsuppLeft] @[simp] lemma finsuppLeft_apply_tmul_apply (p : ι →₀ M) (n : N) (i : ι) : finsuppLeft R M N ι (p ⊗ₜ[R] n) i = p i ⊗ₜ[R] n := by rw [finsuppLeft_apply_tmul, Finsupp.sum_apply, Finsupp.sum_eq_single i (fun _ _ ↦ Finsupp.single_eq_of_ne') (by simp), Finsupp.single_eq_same] theorem finsuppLeft_apply (t : (ι →₀ M) ⊗[R] N) (i : ι) : finsuppLeft R M N ι t i = rTensor N (Finsupp.lapply i) t := by induction t with | zero => simp | tmul f n => simp only [finsuppLeft_apply_tmul_apply, rTensor_tmul, Finsupp.lapply_apply] | add x y hx hy => simp [map_add, hx, hy] @[simp] lemma finsuppLeft_symm_apply_single (i : ι) (m : M) (n : N) : (finsuppLeft R M N ι).symm (Finsupp.single i (m ⊗ₜ[R] n)) = Finsupp.single i m ⊗ₜ[R] n := by simp [finsuppLeft] variable (R M N ι) /-- The tensor product of `M` and `ι →₀ N` is linearly equivalent to `ι →₀ M ⊗[R] N` -/ noncomputable def finsuppRight : M ⊗[R] (ι →₀ N) ≃ₗ[R] ι →₀ M ⊗[R] N := congr (.refl R M) (finsuppLEquivDirectSum R N ι) ≪≫ₗ directSumRight R M (fun _ : ι ↦ N) ≪≫ₗ (finsuppLEquivDirectSum R _ ι).symm variable {R M N ι} lemma finsuppRight_apply_tmul (m : M) (p : ι →₀ N) : finsuppRight R M N ι (m ⊗ₜ[R] p) = p.sum fun i n ↦ Finsupp.single i (m ⊗ₜ[R] n) := by induction p using Finsupp.induction_linear with | zero => simp | add f g hf hg => simp [tmul_add, map_add, hf, hg, Finsupp.sum_add_index] | single => simp [finsuppRight] @[simp] lemma finsuppRight_apply_tmul_apply (m : M) (p : ι →₀ N) (i : ι) : finsuppRight R M N ι (m ⊗ₜ[R] p) i = m ⊗ₜ[R] p i := by rw [finsuppRight_apply_tmul, Finsupp.sum_apply, Finsupp.sum_eq_single i (fun _ _ ↦ Finsupp.single_eq_of_ne') (by simp), Finsupp.single_eq_same] theorem finsuppRight_apply (t : M ⊗[R] (ι →₀ N)) (i : ι) : finsuppRight R M N ι t i = lTensor M (Finsupp.lapply i) t := by induction t with | zero => simp | tmul m f => simp [finsuppRight_apply_tmul_apply] | add x y hx hy => simp [map_add, hx, hy] @[simp] lemma finsuppRight_symm_apply_single (i : ι) (m : M) (n : N) : (finsuppRight R M N ι).symm (Finsupp.single i (m ⊗ₜ[R] n)) = m ⊗ₜ[R] Finsupp.single i n := by simp [finsuppRight] variable {S : Type*} [CommSemiring S] [Algebra R S] [Module S M] [IsScalarTower R S M] lemma finsuppLeft_smul' (s : S) (t : (ι →₀ M) ⊗[R] N) : finsuppLeft R M N ι (s • t) = s • finsuppLeft R M N ι t := by induction t with | zero => simp | add x y hx hy => simp [hx, hy] | tmul p n => ext; simp [smul_tmul', finsuppLeft_apply_tmul_apply] variable (R M N ι S) /-- When `M` is also an `S`-module, then `TensorProduct.finsuppLeft R M N` is an `S`-linear equiv -/ noncomputable def finsuppLeft' : (ι →₀ M) ⊗[R] N ≃ₗ[S] ι →₀ M ⊗[R] N where __ := finsuppLeft R M N ι map_smul' := finsuppLeft_smul' variable {R M N ι S} lemma finsuppLeft'_apply (x : (ι →₀ M) ⊗[R] N) : finsuppLeft' R M N ι S x = finsuppLeft R M N ι x := rfl /- -- TODO : reprove using the existing heterobasic lemmas noncomputable example : (ι →₀ M) ⊗[R] N ≃ₗ[S] ι →₀ (M ⊗[R] N) := by have f : (⨁ (i₁ : ι), M) ⊗[R] N ≃ₗ[S] ⨁ (i : ι), M ⊗[R] N := sorry exact (AlgebraTensorModule.congr (finsuppLEquivDirectSum S M ι) (.refl R N)).trans (f.trans (finsuppLEquivDirectSum S (M ⊗[R] N) ι).symm) -/ variable (R M N ι) /-- The tensor product of `ι →₀ R` and `N` is linearly equivalent to `ι →₀ N` -/ noncomputable def finsuppScalarLeft : (ι →₀ R) ⊗[R] N ≃ₗ[R] ι →₀ N := finsuppLeft R R N ι ≪≫ₗ (Finsupp.mapRange.linearEquiv (TensorProduct.lid R N)) variable {R M N ι} @[simp] lemma finsuppScalarLeft_apply_tmul_apply (p : ι →₀ R) (n : N) (i : ι) : finsuppScalarLeft R N ι (p ⊗ₜ[R] n) i = p i • n := by simp [finsuppScalarLeft] lemma finsuppScalarLeft_apply_tmul (p : ι →₀ R) (n : N) : finsuppScalarLeft R N ι (p ⊗ₜ[R] n) = p.sum fun i m ↦ Finsupp.single i (m • n) := by ext i rw [finsuppScalarLeft_apply_tmul_apply, Finsupp.sum_apply, Finsupp.sum_eq_single i (fun _ _ ↦ Finsupp.single_eq_of_ne') (by simp), Finsupp.single_eq_same] lemma finsuppScalarLeft_apply (pn : (ι →₀ R) ⊗[R] N) (i : ι) : finsuppScalarLeft R N ι pn i = TensorProduct.lid R N ((Finsupp.lapply i).rTensor N pn) := by simp [finsuppScalarLeft, finsuppLeft_apply] @[simp] lemma finsuppScalarLeft_symm_apply_single (i : ι) (n : N) : (finsuppScalarLeft R N ι).symm (Finsupp.single i n) = (Finsupp.single i 1) ⊗ₜ[R] n := by simp [finsuppScalarLeft, finsuppLeft_symm_apply_single] variable (R M N ι) /-- The tensor product of `M` and `ι →₀ R` is linearly equivalent to `ι →₀ M` -/ noncomputable def finsuppScalarRight : M ⊗[R] (ι →₀ R) ≃ₗ[R] ι →₀ M := finsuppRight R M R ι ≪≫ₗ Finsupp.mapRange.linearEquiv (TensorProduct.rid R M) variable {R M N ι} @[simp] lemma finsuppScalarRight_apply_tmul_apply (m : M) (p : ι →₀ R) (i : ι) : finsuppScalarRight R M ι (m ⊗ₜ[R] p) i = p i • m := by simp [finsuppScalarRight] lemma finsuppScalarRight_apply_tmul (m : M) (p : ι →₀ R) : finsuppScalarRight R M ι (m ⊗ₜ[R] p) = p.sum fun i n ↦ Finsupp.single i (n • m) := by ext i rw [finsuppScalarRight_apply_tmul_apply, Finsupp.sum_apply, Finsupp.sum_eq_single i (fun _ _ ↦ Finsupp.single_eq_of_ne') (by simp), Finsupp.single_eq_same] lemma finsuppScalarRight_apply (t : M ⊗[R] (ι →₀ R)) (i : ι) : finsuppScalarRight R M ι t i = TensorProduct.rid R M ((Finsupp.lapply i).lTensor M t) := by simp [finsuppScalarRight, finsuppRight_apply] @[simp] lemma finsuppScalarRight_symm_apply_single (i : ι) (m : M) : (finsuppScalarRight R M ι).symm (Finsupp.single i m) = m ⊗ₜ[R] (Finsupp.single i 1) := by simp [finsuppScalarRight, finsuppRight_symm_apply_single] end TensorProduct end TensorProduct variable (R S M N ι κ : Type*) [CommSemiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N] [Semiring S] [Algebra R S] theorem Finsupp.linearCombination_one_tmul [DecidableEq ι] {v : ι → M} : (linearCombination S ((1 : S) ⊗ₜ[R] v ·)).restrictScalars R = (linearCombination R v).lTensor S ∘ₗ (finsuppScalarRight R S ι).symm := by ext; simp [smul_tmul'] variable [Module S M] [IsScalarTower R S M] open scoped Classical in /-- The tensor product of `ι →₀ M` and `κ →₀ N` is linearly equivalent to `(ι × κ) →₀ (M ⊗ N)`. -/ def finsuppTensorFinsupp : (ι →₀ M) ⊗[R] (κ →₀ N) ≃ₗ[S] ι × κ →₀ M ⊗[R] N := TensorProduct.AlgebraTensorModule.congr (finsuppLEquivDirectSum S M ι) (finsuppLEquivDirectSum R N κ) ≪≫ₗ ((TensorProduct.directSum R S (fun _ : ι => M) fun _ : κ => N) ≪≫ₗ (finsuppLEquivDirectSum S (M ⊗[R] N) (ι × κ)).symm) @[simp] theorem finsuppTensorFinsupp_single (i : ι) (m : M) (k : κ) (n : N) : finsuppTensorFinsupp R S M N ι κ (Finsupp.single i m ⊗ₜ Finsupp.single k n) = Finsupp.single (i, k) (m ⊗ₜ n) := by simp [finsuppTensorFinsupp] @[simp] theorem finsuppTensorFinsupp_apply (f : ι →₀ M) (g : κ →₀ N) (i : ι) (k : κ) : finsuppTensorFinsupp R S M N ι κ (f ⊗ₜ g) (i, k) = f i ⊗ₜ g k := by induction f using Finsupp.induction_linear with | zero => simp | add f₁ f₂ hf₁ hf₂ => simp [add_tmul, hf₁, hf₂] | single i' m => induction g using Finsupp.induction_linear with | zero => simp | add g₁ g₂ hg₁ hg₂ => simp [tmul_add, hg₁, hg₂] | single k' n => classical simp_rw [finsuppTensorFinsupp_single, Finsupp.single_apply, Prod.mk_inj, ite_and] split_ifs <;> simp @[simp] theorem finsuppTensorFinsupp_symm_single (i : ι × κ) (m : M) (n : N) : (finsuppTensorFinsupp R S M N ι κ).symm (Finsupp.single i (m ⊗ₜ n)) = Finsupp.single i.1 m ⊗ₜ Finsupp.single i.2 n := Prod.casesOn i fun _ _ => (LinearEquiv.symm_apply_eq _).2 (finsuppTensorFinsupp_single _ _ _ _ _ _ _ _ _ _).symm /-- A variant of `finsuppTensorFinsupp` where the first module is the ground ring. -/ def finsuppTensorFinsuppLid : (ι →₀ R) ⊗[R] (κ →₀ N) ≃ₗ[R] ι × κ →₀ N := finsuppTensorFinsupp R R R N ι κ ≪≫ₗ Finsupp.lcongr (Equiv.refl _) (TensorProduct.lid R N) @[simp] theorem finsuppTensorFinsuppLid_apply_apply (f : ι →₀ R) (g : κ →₀ N) (a : ι) (b : κ) : finsuppTensorFinsuppLid R N ι κ (f ⊗ₜ[R] g) (a, b) = f a • g b := by simp [finsuppTensorFinsuppLid] @[simp] theorem finsuppTensorFinsuppLid_single_tmul_single (a : ι) (b : κ) (r : R) (n : N) : finsuppTensorFinsuppLid R N ι κ (Finsupp.single a r ⊗ₜ[R] Finsupp.single b n) = Finsupp.single (a, b) (r • n) := by simp [finsuppTensorFinsuppLid] @[simp] theorem finsuppTensorFinsuppLid_symm_single_smul (i : ι × κ) (r : R) (n : N) : (finsuppTensorFinsuppLid R N ι κ).symm (Finsupp.single i (r • n)) = Finsupp.single i.1 r ⊗ₜ Finsupp.single i.2 n := Prod.casesOn i fun _ _ => (LinearEquiv.symm_apply_eq _).2 (finsuppTensorFinsuppLid_single_tmul_single ..).symm /-- A variant of `finsuppTensorFinsupp` where the second module is the ground ring. -/ def finsuppTensorFinsuppRid : (ι →₀ M) ⊗[R] (κ →₀ R) ≃ₗ[R] ι × κ →₀ M := finsuppTensorFinsupp R R M R ι κ ≪≫ₗ Finsupp.lcongr (Equiv.refl _) (TensorProduct.rid R M) @[simp] theorem finsuppTensorFinsuppRid_apply_apply (f : ι →₀ M) (g : κ →₀ R) (a : ι) (b : κ) : finsuppTensorFinsuppRid R M ι κ (f ⊗ₜ[R] g) (a, b) = g b • f a := by simp [finsuppTensorFinsuppRid] @[simp] theorem finsuppTensorFinsuppRid_single_tmul_single (a : ι) (b : κ) (m : M) (r : R) : finsuppTensorFinsuppRid R M ι κ (Finsupp.single a m ⊗ₜ[R] Finsupp.single b r) = Finsupp.single (a, b) (r • m) := by simp [finsuppTensorFinsuppRid] @[simp] theorem finsuppTensorFinsuppRid_symm_single_smul (i : ι × κ) (m : M) (r : R) : (finsuppTensorFinsuppRid R M ι κ).symm (Finsupp.single i (r • m)) = Finsupp.single i.1 m ⊗ₜ Finsupp.single i.2 r := Prod.casesOn i fun _ _ => (LinearEquiv.symm_apply_eq _).2 (finsuppTensorFinsuppRid_single_tmul_single ..).symm /-- A variant of `finsuppTensorFinsupp` where both modules are the ground ring. -/ def finsuppTensorFinsupp' : (ι →₀ R) ⊗[R] (κ →₀ R) ≃ₗ[R] ι × κ →₀ R := finsuppTensorFinsuppLid R R ι κ @[simp] theorem finsuppTensorFinsupp'_apply_apply (f : ι →₀ R) (g : κ →₀ R) (a : ι) (b : κ) : finsuppTensorFinsupp' R ι κ (f ⊗ₜ[R] g) (a, b) = f a * g b := finsuppTensorFinsuppLid_apply_apply R R ι κ f g a b @[simp] theorem finsuppTensorFinsupp'_single_tmul_single (a : ι) (b : κ) (r₁ r₂ : R) : finsuppTensorFinsupp' R ι κ (Finsupp.single a r₁ ⊗ₜ[R] Finsupp.single b r₂) = Finsupp.single (a, b) (r₁ * r₂) := finsuppTensorFinsuppLid_single_tmul_single R R ι κ a b r₁ r₂ theorem finsuppTensorFinsupp'_symm_single_mul (i : ι × κ) (r₁ r₂ : R) : (finsuppTensorFinsupp' R ι κ).symm (Finsupp.single i (r₁ * r₂)) = Finsupp.single i.1 r₁ ⊗ₜ Finsupp.single i.2 r₂ := finsuppTensorFinsuppLid_symm_single_smul R R ι κ i r₁ r₂ theorem finsuppTensorFinsupp'_symm_single_eq_single_one_tmul (i : ι × κ) (r : R) : (finsuppTensorFinsupp' R ι κ).symm (Finsupp.single i r) = Finsupp.single i.1 1 ⊗ₜ Finsupp.single i.2 r := by nth_rw 1 [← one_mul r] exact finsuppTensorFinsupp'_symm_single_mul R ι κ i _ _ theorem finsuppTensorFinsupp'_symm_single_eq_tmul_single_one (i : ι × κ) (r : R) : (finsuppTensorFinsupp' R ι κ).symm (Finsupp.single i r) = Finsupp.single i.1 r ⊗ₜ Finsupp.single i.2 1 := by nth_rw 1 [← mul_one r] exact finsuppTensorFinsupp'_symm_single_mul R ι κ i _ _ theorem finsuppTensorFinsuppLid_self : finsuppTensorFinsuppLid R R ι κ = finsuppTensorFinsupp' R ι κ := rfl theorem finsuppTensorFinsuppRid_self : finsuppTensorFinsuppRid R R ι κ = finsuppTensorFinsupp' R ι κ := by rw [finsuppTensorFinsupp', finsuppTensorFinsuppLid, finsuppTensorFinsuppRid, TensorProduct.lid_eq_rid] end
.lake/packages/mathlib/Mathlib/LinearAlgebra/DirectSum/Basis.lean
import Mathlib.Algebra.DirectSum.Module import Mathlib.LinearAlgebra.Finsupp.VectorSpace /-! # Bases for direct sum of modules This file defines a `Module.Free` instance for the direct sum of modules. ## Implementation notes Currently, to get a basis on `⨁ i, M i` from a basis on each `M i`, use `DFinsupp.basis` (using that the types are defeq). -/ open DirectSum section Semiring variable (R : Type*) [Semiring R] {ι : Type*} (M : ι → Type*) [∀ i : ι, AddCommMonoid (M i)] variable [∀ i : ι, Module R (M i)] instance Module.Free.directSum [∀ i : ι, Module.Free R (M i)] : Module.Free R (⨁ i, M i) := Module.Free.dfinsupp R M end Semiring
.lake/packages/mathlib/Mathlib/LinearAlgebra/Multilinear/Curry.lean
import Mathlib.Data.Fintype.Sort import Mathlib.LinearAlgebra.Multilinear.Basic /-! # Currying of multilinear maps We register isomorphisms corresponding to currying or uncurrying variables, transforming a multilinear function `f` on `n+1` variables into a linear function taking values in multilinear functions in `n` variables, and into a multilinear function in `n` variables taking values in linear functions. These operations are called `f.curryLeft` and `f.curryRight` respectively (with inverses `f.uncurryLeft` and `f.uncurryRight`). These operations induce linear equivalences between spaces of multilinear functions in `n+1` variables and spaces of linear functions into multilinear functions in `n` variables (resp. multilinear functions in `n` variables taking values in linear functions), called respectively `multilinearCurryLeftEquiv` and `multilinearCurryRightEquiv`. -/ open Fin Function Finset Set universe uR uS uι uι' v v' v₁ v₂ v₃ variable {R : Type uR} {S : Type uS} {ι : Type uι} {ι' : Type uι'} {n : ℕ} {M : Fin n.succ → Type v} {M₁ : ι → Type v₁} {M₂ : Type v₂} {M₃ : Type v₃} {M' : Type v'} /-! ### Currying We associate to a multilinear map in `n+1` variables (i.e., based on `Fin n.succ`) two curried functions, named `f.curryLeft` (which is a linear map on `E 0` taking values in multilinear maps in `n` variables) and `f.curryRight` (which is a multilinear map in `n` variables taking values in linear maps on `E 0`). In both constructions, the variable that is singled out is `0`, to take advantage of the operations `cons` and `tail` on `Fin n`. The inverse operations are called `uncurryLeft` and `uncurryRight`. We also register linear equiv versions of these correspondences, in `multilinearCurryLeftEquiv` and `multilinearCurryRightEquiv`. -/ open MultilinearMap variable [CommSemiring R] [∀ i, AddCommMonoid (M i)] [AddCommMonoid M'] [AddCommMonoid M₂] [∀ i, Module R (M i)] [Module R M'] [Module R M₂] /-! #### Left currying -/ /-- Given a linear map `f` from `M 0` to multilinear maps on `n` variables, construct the corresponding multilinear map on `n+1` variables obtained by concatenating the variables, given by `m ↦ f (m 0) (tail m)` -/ def LinearMap.uncurryLeft (f : M 0 →ₗ[R] MultilinearMap R (fun i : Fin n => M i.succ) M₂) : MultilinearMap R M M₂ := MultilinearMap.mk' (fun m ↦ f (m 0) (tail m)) (fun m i x y ↦ by cases i using Fin.cases <;> simp [Ne.symm]) (fun m i c x ↦ by cases i using Fin.cases <;> simp [Ne.symm]) @[simp] theorem LinearMap.uncurryLeft_apply (f : M 0 →ₗ[R] MultilinearMap R (fun i : Fin n => M i.succ) M₂) (m : ∀ i, M i) : f.uncurryLeft m = f (m 0) (tail m) := rfl /-- Given a multilinear map `f` in `n+1` variables, split the first variable to obtain a linear map into multilinear maps in `n` variables, given by `x ↦ (m ↦ f (cons x m))`. -/ def MultilinearMap.curryLeft (f : MultilinearMap R M M₂) : M 0 →ₗ[R] MultilinearMap R (fun i : Fin n => M i.succ) M₂ where toFun x := MultilinearMap.mk' fun m => f (cons x m) map_add' x y := by ext m exact cons_add f m x y map_smul' c x := by ext m exact cons_smul f m c x @[simp] theorem MultilinearMap.curryLeft_apply (f : MultilinearMap R M M₂) (x : M 0) (m : ∀ i : Fin n, M i.succ) : f.curryLeft x m = f (cons x m) := rfl @[simp] theorem LinearMap.curry_uncurryLeft (f : M 0 →ₗ[R] MultilinearMap R (fun i : Fin n => M i.succ) M₂) : f.uncurryLeft.curryLeft = f := by rfl @[simp] theorem MultilinearMap.uncurry_curryLeft (f : MultilinearMap R M M₂) : f.curryLeft.uncurryLeft = f := by ext m simp variable (R M M₂) /-- The space of multilinear maps on `Π (i : Fin (n+1)), M i` is canonically isomorphic to the space of linear maps from `M 0` to the space of multilinear maps on `Π (i : Fin n), M i.succ`, by separating the first variable. We register this isomorphism as a linear isomorphism in `multilinearCurryLeftEquiv R M M₂`. The direct and inverse maps are given by `f.curryLeft` and `f.uncurryLeft`. Use these unless you need the full framework of linear equivs. -/ @[simps] def multilinearCurryLeftEquiv : MultilinearMap R M M₂ ≃ₗ[R] (M 0 →ₗ[R] MultilinearMap R (fun i : Fin n => M i.succ) M₂) where toFun := MultilinearMap.curryLeft map_add' _ _ := rfl map_smul' _ _ := rfl invFun := LinearMap.uncurryLeft left_inv := MultilinearMap.uncurry_curryLeft right_inv := LinearMap.curry_uncurryLeft variable {R M M₂} /-! #### Right currying -/ /-- Given a multilinear map `f` in `n` variables to the space of linear maps from `M (last n)` to `M₂`, construct the corresponding multilinear map on `n+1` variables obtained by concatenating the variables, given by `m ↦ f (init m) (m (last n))` -/ def MultilinearMap.uncurryRight (f : MultilinearMap R (fun i : Fin n => M (castSucc i)) (M (last n) →ₗ[R] M₂)) : MultilinearMap R M M₂ := MultilinearMap.mk' (fun m ↦ f (init m) (m (last n))) (fun m i x y ↦ by cases i using Fin.lastCases <;> simp [Ne.symm]) (fun m i c x ↦ by cases i using Fin.lastCases <;> simp [Ne.symm]) @[simp] theorem MultilinearMap.uncurryRight_apply (f : MultilinearMap R (fun i : Fin n => M (castSucc i)) (M (last n) →ₗ[R] M₂)) (m : ∀ i, M i) : f.uncurryRight m = f (init m) (m (last n)) := rfl /-- Given a multilinear map `f` in `n+1` variables, split the last variable to obtain a multilinear map in `n` variables taking values in linear maps from `M (last n)` to `M₂`, given by `m ↦ (x ↦ f (snoc m x))`. -/ def MultilinearMap.curryRight (f : MultilinearMap R M M₂) : MultilinearMap R (fun i : Fin n => M (Fin.castSucc i)) (M (last n) →ₗ[R] M₂) := MultilinearMap.mk' fun m ↦ { toFun := fun x => f (snoc m x) map_add' := fun x y => by simp_rw [f.snoc_add] map_smul' := fun c x => by simp only [f.snoc_smul, RingHom.id_apply] } @[simp] theorem MultilinearMap.curryRight_apply (f : MultilinearMap R M M₂) (m : ∀ i : Fin n, M (castSucc i)) (x : M (last n)) : f.curryRight m x = f (snoc m x) := rfl @[simp] theorem MultilinearMap.curry_uncurryRight (f : MultilinearMap R (fun i : Fin n => M (castSucc i)) (M (last n) →ₗ[R] M₂)) : f.uncurryRight.curryRight = f := by ext m x simp only [snoc_last, MultilinearMap.curryRight_apply, MultilinearMap.uncurryRight_apply] rw [init_snoc] @[simp] theorem MultilinearMap.uncurry_curryRight (f : MultilinearMap R M M₂) : f.curryRight.uncurryRight = f := by ext m simp variable (R M M₂) /-- The space of multilinear maps on `Π (i : Fin (n+1)), M i` is canonically isomorphic to the space of linear maps from the space of multilinear maps on `Π (i : Fin n), M (castSucc i)` to the space of linear maps on `M (last n)`, by separating the last variable. We register this isomorphism as a linear isomorphism in `multilinearCurryRightEquiv R M M₂`. The direct and inverse maps are given by `f.curryRight` and `f.uncurryRight`. Use these unless you need the full framework of linear equivs. -/ def multilinearCurryRightEquiv : MultilinearMap R M M₂ ≃ₗ[R] MultilinearMap R (fun i : Fin n => M (castSucc i)) (M (last n) →ₗ[R] M₂) where toFun := MultilinearMap.curryRight map_add' _ _ := rfl map_smul' _ _ := rfl invFun := MultilinearMap.uncurryRight left_inv := MultilinearMap.uncurry_curryRight right_inv := MultilinearMap.curry_uncurryRight variable {R M M₂} /-- Given a linear map from `M p` to the space of multilinear maps in `n` variables `M 0`, ..., `M n` with `M p` removed, returns a multilinear map in all `n + 1` variables. -/ @[simps!] def LinearMap.uncurryMid (p : Fin (n + 1)) (f : M p →ₗ[R] MultilinearMap R (fun i ↦ M (p.succAbove i)) M₂) : MultilinearMap R M M₂ := .mk' (fun m ↦ f (m p) (p.removeNth m)) (fun m i x y ↦ by cases i using Fin.succAboveCases p <;> simp) (fun m i x y ↦ by cases i using Fin.succAboveCases p <;> simp) /-- Interpret a multilinear map in `n + 1` variables as a linear map in `p`th variable with values in the multilinear maps in the other variables. -/ @[simps!] def MultilinearMap.curryMid (p : Fin (n + 1)) (f : MultilinearMap R M M₂) : M p →ₗ[R] MultilinearMap R (fun i ↦ M (p.succAbove i)) M₂ where toFun x := .mk' fun m ↦ f (p.insertNth x m) map_add' x y := by ext; simp [map_insertNth_add] map_smul' c x := by ext; simp [map_insertNth_smul] @[simp] theorem LinearMap.curryMid_uncurryMid (i : Fin (n + 1)) (f : M i →ₗ[R] MultilinearMap R (fun j ↦ M (i.succAbove j)) M₂) : (f.uncurryMid i).curryMid i = f := by ext; simp @[simp] theorem MultilinearMap.uncurryMid_curryMid (i : Fin (n + 1)) (f : MultilinearMap R M M₂) : (f.curryMid i).uncurryMid i = f := by ext; simp variable (R M M₂) /-- `MultilinearMap.curryMid` as a linear equivalence. -/ @[simps] def MultilinearMap.curryMidLinearEquiv (p : Fin (n + 1)) : MultilinearMap R M M₂ ≃ₗ[R] M p →ₗ[R] MultilinearMap R (fun i ↦ M (p.succAbove i)) M₂ where toFun := MultilinearMap.curryMid p map_add' _ _ := rfl map_smul' _ _ := rfl invFun := LinearMap.uncurryMid p left_inv := MultilinearMap.uncurryMid_curryMid p right_inv := LinearMap.curryMid_uncurryMid p namespace MultilinearMap variable {R M₂} {N : (ι ⊕ ι') → Type*} [∀ i, AddCommMonoid (N i)] [∀ i, Module R (N i)] /-- Given a family of modules `N : (ι ⊕ ι') → Type*`, a multilinear map on `(fun _ : ι ⊕ ι' => M')` induces a multilinear map on `(fun (i : ι) ↦ N (.inl i))` taking values in the space of linear maps on `(fun (i : ι') ↦ N (.inr i))`. -/ def currySum (f : MultilinearMap R N M₂) : MultilinearMap R (fun i : ι ↦ N (.inl i)) (MultilinearMap R (fun i : ι' ↦ N (.inr i)) M₂) where toFun u := { toFun v := f (Sum.rec u v) map_update_add' := by letI := Classical.decEq ι; aesop map_update_smul' := by letI := Classical.decEq ι; aesop } map_update_add' u i x y := ext fun _ ↦ by letI := Classical.decEq ι'; simp map_update_smul' u i c x := ext fun _ ↦ by letI := Classical.decEq ι'; simp @[simp low] theorem currySum_apply (f : MultilinearMap R N M₂) (u : (i : ι) → N (Sum.inl i)) (v : (i : ι') → N (Sum.inr i)) : currySum f u v = f (Sum.rec u v) := rfl @[simp] theorem currySum_apply' {N : Type*} [AddCommMonoid N] [Module R N] (f : MultilinearMap R (fun _ : ι ⊕ ι' ↦ N) M₂) (u : ι → N) (v : ι' → N) : currySum f u v = f (Sum.elim u v) := rfl @[simp] lemma currySum_add (f₁ f₂ : MultilinearMap R N M₂) : currySum (f₁ + f₂) = currySum f₁ + currySum f₂ := rfl @[simp] lemma currySum_smul (r : R) (f : MultilinearMap R N M₂) : currySum (r • f) = r • currySum f := rfl /-- Given a family of modules `N : (ι ⊕ ι') → Type*`, a multilinear map on `(fun (i : ι) ↦ N (.inl i))` taking values in the space of linear maps on `(fun (i : ι') ↦ N (.inr i))` induces a multilinear map on `(fun _ : ι ⊕ ι' => M')` induces. -/ def uncurrySum (g : MultilinearMap R (fun i : ι ↦ N (.inl i)) (MultilinearMap R (fun i : ι' ↦ N (.inr i)) M₂)) : MultilinearMap R N M₂ where toFun u := g (fun i ↦ u (.inl i)) (fun i' ↦ u (.inr i')) map_update_add' := by letI := Classical.decEq ι letI := Classical.decEq ι' rintro _ _ (_ | _) _ _ <;> simp map_update_smul' := by letI := Classical.decEq ι letI := Classical.decEq ι' rintro _ _ (_ | _) _ _ <;> simp @[simp] theorem uncurrySum_apply (g : MultilinearMap R (fun i : ι ↦ N (.inl i)) (MultilinearMap R (fun i : ι' ↦ N (.inr i)) M₂)) (u) : g.uncurrySum u = g (fun i ↦ u (.inl i)) (fun i' ↦ u (.inr i')) := rfl @[simp] lemma uncurrySum_add (g₁ g₂ : MultilinearMap R (fun i : ι ↦ N (.inl i)) (MultilinearMap R (fun i : ι' ↦ N (.inr i)) M₂)) : uncurrySum (g₁ + g₂) = uncurrySum g₁ + uncurrySum g₂ := rfl lemma uncurrySum_smul (r : R) (g : MultilinearMap R (fun i : ι ↦ N (.inl i)) (MultilinearMap R (fun i : ι' ↦ N (.inr i)) M₂)) : uncurrySum (r • g) = r • uncurrySum g := rfl @[deprecated (since := "2025-04-23")] alias uncurrySum_aux_apply := uncurrySum_apply @[simp] lemma uncurrySum_currySum (f : MultilinearMap R N M₂) : uncurrySum (currySum f) = f := by ext simp only [uncurrySum_apply, currySum_apply] congr ext (_ | _) <;> simp @[simp] lemma currySum_uncurrySum (g : MultilinearMap R (fun i : ι ↦ N (.inl i)) (MultilinearMap R (fun i : ι' ↦ N (.inr i)) M₂)) : currySum (uncurrySum g) = g := rfl /-- Multilinear maps on `N : (ι ⊕ ι') → Type*` identify to multilinear maps from `(fun (i : ι) ↦ N (.inl i))` taking values in the space of linear maps on `(fun (i : ι') ↦ N (.inr i))`. -/ @[simps] def currySumEquiv : MultilinearMap R N M₂ ≃ₗ[R] MultilinearMap R (fun i : ι ↦ N (.inl i)) (MultilinearMap R (fun i : ι' ↦ N (.inr i)) M₂) where toFun := currySum invFun := uncurrySum left_inv _ := by simp map_add' := by aesop map_smul' := by aesop @[simp] theorem coe_currySumEquiv : ⇑(currySumEquiv (R := R) (N := N) (M₂ := M₂)) = currySum := rfl @[simp] theorem coe_currySumEquiv_symm : ⇑(currySumEquiv (R := R) (N := N) (M₂ := M₂)).symm = uncurrySum := rfl variable (R M₂ M') /-- If `s : Finset (Fin n)` is a finite set of cardinality `k` and its complement has cardinality `l`, then the space of multilinear maps on `fun i : Fin n => M'` is isomorphic to the space of multilinear maps on `fun i : Fin k => M'` taking values in the space of multilinear maps on `fun i : Fin l => M'`. -/ def curryFinFinset {k l n : ℕ} {s : Finset (Fin n)} (hk : #s = k) (hl : #sᶜ = l) : MultilinearMap R (fun _ : Fin n => M') M₂ ≃ₗ[R] MultilinearMap R (fun _ : Fin k => M') (MultilinearMap R (fun _ : Fin l => M') M₂) := (domDomCongrLinearEquiv R R M' M₂ (finSumEquivOfFinset hk hl).symm).trans currySumEquiv variable {R M₂ M'} @[simp] theorem curryFinFinset_apply {k l n : ℕ} {s : Finset (Fin n)} (hk : #s = k) (hl : #sᶜ = l) (f : MultilinearMap R (fun _ : Fin n => M') M₂) (mk : Fin k → M') (ml : Fin l → M') : curryFinFinset R M₂ M' hk hl f mk ml = f fun i => Sum.elim mk ml ((finSumEquivOfFinset hk hl).symm i) := rfl @[simp] theorem curryFinFinset_symm_apply {k l n : ℕ} {s : Finset (Fin n)} (hk : #s = k) (hl : #sᶜ = l) (f : MultilinearMap R (fun _ : Fin k => M') (MultilinearMap R (fun _ : Fin l => M') M₂)) (m : Fin n → M') : (curryFinFinset R M₂ M' hk hl).symm f m = f (fun i => m <| finSumEquivOfFinset hk hl (Sum.inl i)) fun i => m <| finSumEquivOfFinset hk hl (Sum.inr i) := rfl theorem curryFinFinset_symm_apply_piecewise_const {k l n : ℕ} {s : Finset (Fin n)} (hk : #s = k) (hl : #sᶜ = l) (f : MultilinearMap R (fun _ : Fin k => M') (MultilinearMap R (fun _ : Fin l => M') M₂)) (x y : M') : (curryFinFinset R M₂ M' hk hl).symm f (s.piecewise (fun _ => x) fun _ => y) = f (fun _ => x) fun _ => y := by rw [curryFinFinset_symm_apply]; congr · ext rw [finSumEquivOfFinset_inl, Finset.piecewise_eq_of_mem] apply Finset.orderEmbOfFin_mem · ext rw [finSumEquivOfFinset_inr, Finset.piecewise_eq_of_notMem] exact Finset.mem_compl.1 (Finset.orderEmbOfFin_mem _ _ _) @[simp] theorem curryFinFinset_symm_apply_const {k l n : ℕ} {s : Finset (Fin n)} (hk : #s = k) (hl : #sᶜ = l) (f : MultilinearMap R (fun _ : Fin k => M') (MultilinearMap R (fun _ : Fin l => M') M₂)) (x : M') : ((curryFinFinset R M₂ M' hk hl).symm f fun _ => x) = f (fun _ => x) fun _ => x := rfl theorem curryFinFinset_apply_const {k l n : ℕ} {s : Finset (Fin n)} (hk : #s = k) (hl : #sᶜ = l) (f : MultilinearMap R (fun _ : Fin n => M') M₂) (x y : M') : (curryFinFinset R M₂ M' hk hl f (fun _ => x) fun _ => y) = f (s.piecewise (fun _ => x) fun _ => y) := by rw [← curryFinFinset_symm_apply_piecewise_const hk hl, LinearEquiv.symm_apply_apply] end MultilinearMap
.lake/packages/mathlib/Mathlib/LinearAlgebra/Multilinear/TensorProduct.lean
import Mathlib.LinearAlgebra.TensorProduct.Basic import Mathlib.LinearAlgebra.Multilinear.Basic /-! # Constructions relating multilinear maps and tensor products. -/ namespace MultilinearMap section DomCoprod open TensorProduct variable {R ι₁ ι₂ ι₃ ι₄ : Type*} variable [CommSemiring R] variable {N₁ : Type*} [AddCommMonoid N₁] [Module R N₁] variable {N₂ : Type*} [AddCommMonoid N₂] [Module R N₂] attribute [local simp] add_tmul tmul_add smul_tmul section variable {N : ι₁ ⊕ ι₂ → Type*} [∀ i, AddCommMonoid (N i)] [∀ i, Module R (N i)] /-- Given a family of modules `N` indexed by a type `ι₁ ⊕ ι₂`, a multilinear map from the modules `N (.inl i₁)` to `N₁` and a multilinear map from the modules `N (.inr i₁)` to `N₂`, this is the induced multilinear map from all the modules `N i` to `N₁ ⊗ N₂`. -/ @[simps apply] def domCoprodDep (a : MultilinearMap R (fun i₁ ↦ N (.inl i₁)) N₁) (b : MultilinearMap R (fun i₂ ↦ N (.inr i₂)) N₂) : MultilinearMap R N (N₁ ⊗[R] N₂) where toFun v := a (fun i₁ ↦ v (.inl i₁)) ⊗ₜ b (fun i₂ ↦ v (.inr i₂)) map_update_add' := by rintro _ _ (_ | _) _ _ · letI := Classical.decEq ι₁; simp · letI := Classical.decEq ι₂; simp map_update_smul' := by rintro _ m (i₁ | i₂) p q · letI := Classical.decEq ι₁; simp · letI := Classical.decEq ι₂; simp /-- A more bundled version of `MultilinearMap.domCoprodDep`, as a linear map from the tensor product of spaces of multilinear maps. -/ def domCoprodDep' : MultilinearMap R (fun i₁ ↦ N (.inl i₁)) N₁ ⊗[R] MultilinearMap R (fun i₂ ↦ N (.inr i₂)) N₂ →ₗ[R] MultilinearMap R N (N₁ ⊗[R] N₂) := TensorProduct.lift (LinearMap.mk₂ R domCoprodDep (by aesop) (by aesop) (by aesop) (by aesop)) @[simp] theorem domCoprodDep'_apply (a : MultilinearMap R (fun i₁ ↦ N (.inl i₁)) N₁) (b : MultilinearMap R (fun i₂ ↦ N (.inr i₂)) N₂) : domCoprodDep' (a ⊗ₜ b) = domCoprodDep a b := by rfl end variable {N : Type*} [AddCommMonoid N] [Module R N] /-- Given two multilinear maps `(ι₁ → N) → N₁` and `(ι₂ → N) → N₂`, this produces the map `(ι₁ ⊕ ι₂ → N) → N₁ ⊗ N₂` by taking the coproduct of the domain and the tensor product of the codomain. This can be thought of as combining `Equiv.sumArrowEquivProdArrow.symm` with `TensorProduct.map`, noting that the two operations can't be separated as the intermediate result is not a `MultilinearMap`. While this can be generalized to work for dependent `Π i : ι₁, N'₁ i` instead of `ι₁ → N`, doing so introduces `Sum.elim N'₁ N'₂` types in the result which are difficult to work with and not defeq to the simple case defined here. See [this zulip thread]( https://leanprover.zulipchat.com/#narrow/stream/217875-Is-there.20code.20for.20X.3F/topic/Instances.20on.20.60sum.2Eelim.20A.20B.20i.60/near/218484619). -/ @[simps! apply] def domCoprod (a : MultilinearMap R (fun _ : ι₁ => N) N₁) (b : MultilinearMap R (fun _ : ι₂ => N) N₂) : MultilinearMap R (fun _ : ι₁ ⊕ ι₂ => N) (N₁ ⊗[R] N₂) := domCoprodDep a b /-- A more bundled version of `MultilinearMap.domCoprod` that maps `((ι₁ → N) → N₁) ⊗ ((ι₂ → N) → N₂)` to `(ι₁ ⊕ ι₂ → N) → N₁ ⊗ N₂`. -/ def domCoprod' : MultilinearMap R (fun _ : ι₁ => N) N₁ ⊗[R] MultilinearMap R (fun _ : ι₂ => N) N₂ →ₗ[R] MultilinearMap R (fun _ : ι₁ ⊕ ι₂ => N) (N₁ ⊗[R] N₂) := domCoprodDep' (R := R) (N := fun (_ : ι₁ ⊕ ι₂) ↦ N) @[simp] theorem domCoprod'_apply (a : MultilinearMap R (fun _ : ι₁ => N) N₁) (b : MultilinearMap R (fun _ : ι₂ => N) N₂) : domCoprod' (a ⊗ₜ[R] b) = domCoprod a b := rfl /-- When passed an `Equiv.sumCongr`, `MultilinearMap.domDomCongr` distributes over `MultilinearMap.domCoprod`. -/ theorem domCoprod_domDomCongr_sumCongr (a : MultilinearMap R (fun _ : ι₁ => N) N₁) (b : MultilinearMap R (fun _ : ι₂ => N) N₂) (σa : ι₁ ≃ ι₃) (σb : ι₂ ≃ ι₄) : (a.domCoprod b).domDomCongr (σa.sumCongr σb) = (a.domDomCongr σa).domCoprod (b.domDomCongr σb) := rfl end DomCoprod end MultilinearMap
.lake/packages/mathlib/Mathlib/LinearAlgebra/Multilinear/Pi.lean
import Mathlib.LinearAlgebra.Pi import Mathlib.LinearAlgebra.Multilinear.Basic /-! # Interactions between (dependent) functions and multilinear maps ## Main definitions * `MultilinearMap.pi_ext`, a multilinear version of `LinearMap.pi_ext` * `MultilinearMap.piFamily`, which satisfies `piFamily f x p = f p (fun i => x i (p i))`. This is useful because all the intermediate results are bundled: - `MultilinearMap.piFamily f` is a `MultilinearMap` operating on functions `x`. - `MultilinearMap.piFamilyₗ` is a `LinearMap`, linear in the family of multilinear maps `f`. -/ universe uι uκ uS uR uM uN variable {ι : Type uι} {κ : ι → Type uκ} variable {S : Type uS} {R : Type uR} namespace MultilinearMap section Semiring variable {M : ∀ i, κ i → Type uM} {N : Type uN} variable [Semiring R] variable [∀ i k, AddCommMonoid (M i k)] [AddCommMonoid N] variable [∀ i k, Module R (M i k)] [Module R N] /-- Two multilinear maps from finite families are equal if they agree on the generators. This is a multilinear version of `LinearMap.pi_ext`. -/ @[ext] theorem pi_ext [Finite ι] [∀ i, Finite (κ i)] [∀ i, DecidableEq (κ i)] ⦃f g : MultilinearMap R (fun i ↦ Π j : κ i, M i j) N⦄ (h : ∀ p : Π i, κ i, f.compLinearMap (fun i => LinearMap.single R _ (p i)) = g.compLinearMap (fun i => LinearMap.single R _ (p i))) : f = g := by ext x change f (fun i ↦ x i) = g (fun i ↦ x i) obtain ⟨i⟩ := nonempty_fintype ι have (i : _) := (nonempty_fintype (κ i)).some have := Classical.decEq ι rw [funext (fun i ↦ Eq.symm (Finset.univ_sum_single (x i)))] simp_rw [MultilinearMap.map_sum_finset] congr! 1 with p simp_rw [MultilinearMap.ext_iff] at h exact h _ _ end Semiring section piFamily variable {M : ∀ i, κ i → Type uM} {N : (Π i, κ i) → Type uN} section Semiring variable [Semiring R] variable [∀ i k, AddCommMonoid (M i k)] [∀ p, AddCommMonoid (N p)] variable [∀ i k, Module R (M i k)] [∀ p, Module R (N p)] /-- Given a family of indices `κ` and a multilinear map `f p` for each way `p` to select one index from each family, `piFamily f` maps a family of functions (one for each domain `κ i`) into a function from each selection of indices (with domain `Π i, κ i`). -/ @[simps] def piFamily (f : Π (p : Π i, κ i), MultilinearMap R (fun i ↦ M i (p i)) (N p)) : MultilinearMap R (fun i => Π j : κ i, M i j) (Π t : Π i, κ i, N t) where toFun x := fun p => f p (fun i => x i (p i)) map_update_add' {dec} m i x y := funext fun p => by dsimp simp_rw [Function.apply_update (fun i m => m (p i)) m, Pi.add_apply, (f p).map_update_add] map_update_smul' {dec} m i c x := funext fun p => by dsimp simp_rw [Function.apply_update (fun i m => m (p i)) m, Pi.smul_apply, (f p).map_update_smul] /-- When applied to a family of finitely-supported functions each supported on a single element, `piFamily` is itself supported on a single element, with value equal to the map `f` applied at that point. -/ @[simp] theorem piFamily_single [Fintype ι] [∀ i, DecidableEq (κ i)] (f : Π (p : Π i, κ i), MultilinearMap R (fun i ↦ M i (p i)) (N p)) (p : ∀ i, κ i) (m : ∀ i, M i (p i)) : piFamily f (fun i => Pi.single (p i) (m i)) = Pi.single p (f p m) := by ext q obtain rfl | hpq := eq_or_ne p q · simp · rw [Pi.single_eq_of_ne' hpq] rw [Function.ne_iff] at hpq obtain ⟨i, hpqi⟩ := hpq apply (f q).map_coord_zero i simp_rw [Pi.single_eq_of_ne' hpqi] /-- When only one member of the family of multilinear maps is nonzero, the result consists only of the component from that member. -/ @[simp] theorem piFamily_single_left_apply [Fintype ι] [∀ i, DecidableEq (κ i)] (p : Π i, κ i) (f : MultilinearMap R (fun i ↦ M i (p i)) (N p)) (x : Π i j, M i j) : piFamily (Pi.single p f) x = Pi.single p (f fun i => x i (p i)) := by ext p' obtain rfl | hp := eq_or_ne p p' · simp · simp [hp] theorem piFamily_single_left [Fintype ι] [∀ i, DecidableEq (κ i)] (p : Π i, κ i) (f : MultilinearMap R (fun i ↦ M i (p i)) (N p)) : piFamily (Pi.single p f) = (LinearMap.single R _ p).compMultilinearMap (f.compLinearMap fun i => .proj (p i)) := ext <| piFamily_single_left_apply _ _ @[simp] theorem piFamily_compLinearMap_lsingle [Fintype ι] [∀ i, DecidableEq (κ i)] (f : Π (p : Π i, κ i), MultilinearMap R (fun i ↦ M i (p i)) (N p)) (p : ∀ i, κ i) : (piFamily f).compLinearMap (fun i => LinearMap.single _ _ (p i)) = (LinearMap.single _ _ p).compMultilinearMap (f p) := MultilinearMap.ext <| piFamily_single f p @[simp] theorem piFamily_zero : piFamily (0 : Π (p : Π i, κ i), MultilinearMap R (fun i ↦ M i (p i)) (N p)) = 0 := by ext; simp @[simp] theorem piFamily_add (f g : Π (p : Π i, κ i), MultilinearMap R (fun i ↦ M i (p i)) (N p)) : piFamily (f + g) = piFamily f + piFamily g := by ext; simp @[simp] theorem piFamily_smul [Monoid S] [∀ p, DistribMulAction S (N p)] [∀ p, SMulCommClass R S (N p)] (s : S) (f : Π (p : Π i, κ i), MultilinearMap R (fun i ↦ M i (p i)) (N p)) : piFamily (s • f) = s • piFamily f := by ext; simp end Semiring section CommSemiring variable [CommSemiring R] variable [∀ i k, AddCommMonoid (M i k)] [∀ p, AddCommMonoid (N p)] variable [∀ i k, Module R (M i k)] [∀ p, Module R (N p)] /-- `MultilinearMap.piFamily` as a linear map. -/ @[simps] def piFamilyₗ : (Π (p : Π i, κ i), MultilinearMap R (fun i ↦ M i (p i)) (N p)) →ₗ[R] MultilinearMap R (fun i => Π j : κ i, M i j) (Π t : Π i, κ i, N t) where toFun := piFamily map_add' := piFamily_add map_smul' := piFamily_smul end CommSemiring end piFamily end MultilinearMap
.lake/packages/mathlib/Mathlib/LinearAlgebra/Multilinear/Basic.lean
import Mathlib.Algebra.BigOperators.Group.Finset.Powerset import Mathlib.Algebra.NoZeroSMulDivisors.Pi import Mathlib.Data.Finset.Sort import Mathlib.Data.Fintype.BigOperators import Mathlib.Data.Fintype.Powerset import Mathlib.LinearAlgebra.Pi import Mathlib.Logic.Equiv.Fintype import Mathlib.Tactic.Abel /-! # Multilinear maps We define multilinear maps as maps from `∀ (i : ι), M₁ i` to `M₂` which are linear in each coordinate. Here, `M₁ i` and `M₂` are modules over a ring `R`, and `ι` is an arbitrary type (although some statements will require it to be a fintype). This space, denoted by `MultilinearMap R M₁ M₂`, inherits a module structure by pointwise addition and multiplication. ## Main definitions * `MultilinearMap R M₁ M₂` is the space of multilinear maps from `∀ (i : ι), M₁ i` to `M₂`. * `f.map_update_smul` is the multiplicativity of the multilinear map `f` along each coordinate. * `f.map_update_add` is the additivity of the multilinear map `f` along each coordinate. * `f.map_smul_univ` expresses the multiplicativity of `f` over all coordinates at the same time, writing `f (fun i => c i • m i)` as `(∏ i, c i) • f m`. * `f.map_add_univ` expresses the additivity of `f` over all coordinates at the same time, writing `f (m + m')` as the sum over all subsets `s` of `ι` of `f (s.piecewise m m')`. * `f.map_sum` expresses `f (Σ_{j₁} g₁ j₁, ..., Σ_{jₙ} gₙ jₙ)` as the sum of `f (g₁ (r 1), ..., gₙ (r n))` where `r` ranges over all possible functions. See `Mathlib/LinearAlgebra/Multilinear/Curry.lean` for the currying of multilinear maps. ## Implementation notes Expressing that a map is linear along the `i`-th coordinate when all other coordinates are fixed can be done in two (equivalent) different ways: * fixing a vector `m : ∀ (j : ι - i), M₁ j.val`, and then choosing separately the `i`-th coordinate * fixing a vector `m : ∀ j, M₁ j`, and then modifying its `i`-th coordinate The second way is more artificial as the value of `m` at `i` is not relevant, but it has the advantage of avoiding subtype inclusion issues. This is the definition we use, based on `Function.update` that allows to change the value of `m` at `i`. Note that the use of `Function.update` requires a `DecidableEq ι` term to appear somewhere in the statement of `MultilinearMap.map_update_add'` and `MultilinearMap.map_update_smul'`. Three possible choices are: 1. Requiring `DecidableEq ι` as an argument to `MultilinearMap` (as we did originally). 2. Using `Classical.decEq ι` in the statement of `map_add'` and `map_smul'`. 3. Quantifying over all possible `DecidableEq ι` instances in the statement of `map_add'` and `map_smul'`. Option 1 works fine, but puts unnecessary constraints on the user (the zero map certainly does not need decidability). Option 2 looks great at first, but in the common case when `ι = Fin n` it introduces non-defeq decidability instance diamonds within the context of proving `map_update_add'` and `map_update_smul'`, of the form `Fin.decidableEq n = Classical.decEq (Fin n)`. Option 3 of course does something similar, but of the form `Fin.decidableEq n = _inst`, which is much easier to clean up since `_inst` is a free variable and so the equality can just be substituted. -/ open Fin Function Finset Set universe uR uS uι v v' v₁ v₁' v₁'' v₂ v₃ v₄ variable {R : Type uR} {S : Type uS} {ι : Type uι} {n : ℕ} {M : Fin n.succ → Type v} {M₁ : ι → Type v₁} {M₁' : ι → Type v₁'} {M₁'' : ι → Type v₁''} variable {M₂ : Type v₂} {M₃ : Type v₃} {M₄ : Type v₄} {M' : Type v'} -- Don't generate injectivity lemmas, which the `simpNF` linter will time out on. set_option genInjectivity false in /-- Multilinear maps over the ring `R`, from `∀ i, M₁ i` to `M₂` where `M₁ i` and `M₂` are modules over `R`. -/ structure MultilinearMap (R : Type uR) {ι : Type uι} (M₁ : ι → Type v₁) (M₂ : Type v₂) [Semiring R] [∀ i, AddCommMonoid (M₁ i)] [AddCommMonoid M₂] [∀ i, Module R (M₁ i)] [Module R M₂] where /-- The underlying multivariate function of a multilinear map. -/ toFun : (∀ i, M₁ i) → M₂ /-- A multilinear map is additive in every argument. -/ map_update_add' : ∀ [DecidableEq ι] (m : ∀ i, M₁ i) (i : ι) (x y : M₁ i), toFun (update m i (x + y)) = toFun (update m i x) + toFun (update m i y) /-- A multilinear map is compatible with scalar multiplication in every argument. -/ map_update_smul' : ∀ [DecidableEq ι] (m : ∀ i, M₁ i) (i : ι) (c : R) (x : M₁ i), toFun (update m i (c • x)) = c • toFun (update m i x) namespace MultilinearMap section Semiring variable [Semiring R] [∀ i, AddCommMonoid (M i)] [∀ i, AddCommMonoid (M₁ i)] [AddCommMonoid M₂] [AddCommMonoid M₃] [AddCommMonoid M'] [∀ i, Module R (M i)] [∀ i, Module R (M₁ i)] [Module R M₂] [Module R M₃] [Module R M'] (f f' : MultilinearMap R M₁ M₂) instance : FunLike (MultilinearMap R M₁ M₂) (∀ i, M₁ i) M₂ where coe f := f.toFun coe_injective' f g h := by cases f; cases g; cases h; rfl initialize_simps_projections MultilinearMap (toFun → apply) /-- Constructor for `MultilinearMap R M₁ M₂` when the index type `ι` is already endowed with a `DecidableEq` instance. -/ @[simps] def mk' [DecidableEq ι] (f : (∀ i, M₁ i) → M₂) (h₁ : ∀ (m : ∀ i, M₁ i) (i : ι) (x y : M₁ i), f (update m i (x + y)) = f (update m i x) + f (update m i y) := by aesop) (h₂ : ∀ (m : ∀ i, M₁ i) (i : ι) (c : R) (x : M₁ i), f (update m i (c • x)) = c • f (update m i x) := by aesop) : MultilinearMap R M₁ M₂ where toFun := f map_update_add' m i x y := by convert h₁ m i x y map_update_smul' m i c x := by convert h₂ m i c x @[simp] theorem toFun_eq_coe : f.toFun = ⇑f := rfl @[simp] theorem coe_mk (f : (∀ i, M₁ i) → M₂) (h₁ h₂) : ⇑(⟨f, h₁, h₂⟩ : MultilinearMap R M₁ M₂) = f := rfl theorem congr_fun {f g : MultilinearMap R M₁ M₂} (h : f = g) (x : ∀ i, M₁ i) : f x = g x := DFunLike.congr_fun h x nonrec theorem congr_arg (f : MultilinearMap R M₁ M₂) {x y : ∀ i, M₁ i} (h : x = y) : f x = f y := DFunLike.congr_arg f h theorem coe_injective : Injective ((↑) : MultilinearMap R M₁ M₂ → (∀ i, M₁ i) → M₂) := DFunLike.coe_injective @[norm_cast] theorem coe_inj {f g : MultilinearMap R M₁ M₂} : (f : (∀ i, M₁ i) → M₂) = g ↔ f = g := DFunLike.coe_fn_eq @[ext] theorem ext {f f' : MultilinearMap R M₁ M₂} (H : ∀ x, f x = f' x) : f = f' := DFunLike.ext _ _ H @[simp] theorem mk_coe (f : MultilinearMap R M₁ M₂) (h₁ h₂) : (⟨f, h₁, h₂⟩ : MultilinearMap R M₁ M₂) = f := rfl @[simp] protected theorem map_update_add [DecidableEq ι] (m : ∀ i, M₁ i) (i : ι) (x y : M₁ i) : f (update m i (x + y)) = f (update m i x) + f (update m i y) := f.map_update_add' m i x y /-- Earlier, this name was used by what is now called `MultilinearMap.map_update_smul_left`. -/ @[simp] protected theorem map_update_smul [DecidableEq ι] (m : ∀ i, M₁ i) (i : ι) (c : R) (x : M₁ i) : f (update m i (c • x)) = c • f (update m i x) := f.map_update_smul' m i c x theorem map_coord_zero {m : ∀ i, M₁ i} (i : ι) (h : m i = 0) : f m = 0 := by classical have : (0 : R) • (0 : M₁ i) = 0 := by simp rw [← update_eq_self i m, h, ← this, f.map_update_smul, zero_smul] @[simp] theorem map_update_zero [DecidableEq ι] (m : ∀ i, M₁ i) (i : ι) : f (update m i 0) = 0 := f.map_coord_zero i (update_self i 0 m) @[simp] theorem map_zero [Nonempty ι] : f 0 = 0 := by obtain ⟨i, _⟩ : ∃ i : ι, i ∈ Set.univ := Set.exists_mem_of_nonempty ι exact map_coord_zero f i rfl instance : Add (MultilinearMap R M₁ M₂) := ⟨fun f f' => ⟨fun x => f x + f' x, fun m i x y => by simp [add_left_comm, add_assoc], fun m i c x => by simp [smul_add]⟩⟩ @[simp] theorem add_apply (m : ∀ i, M₁ i) : (f + f') m = f m + f' m := rfl instance : Zero (MultilinearMap R M₁ M₂) := ⟨⟨fun _ => 0, fun _ _ _ _ => by simp, fun _ _ c _ => by simp⟩⟩ instance : Inhabited (MultilinearMap R M₁ M₂) := ⟨0⟩ @[simp] theorem zero_apply (m : ∀ i, M₁ i) : (0 : MultilinearMap R M₁ M₂) m = 0 := rfl section SMul variable [DistribSMul S M₂] [SMulCommClass R S M₂] instance : SMul S (MultilinearMap R M₁ M₂) := ⟨fun c f => ⟨fun m => c • f m, fun m i x y => by simp [smul_add], fun l i x d => by simp [← smul_comm x c (_ : M₂)]⟩⟩ @[simp] theorem smul_apply (f : MultilinearMap R M₁ M₂) (c : S) (m : ∀ i, M₁ i) : (c • f) m = c • f m := rfl theorem coe_smul (c : S) (f : MultilinearMap R M₁ M₂) : ⇑(c • f) = c • (⇑f) := rfl end SMul instance addCommMonoid : AddCommMonoid (MultilinearMap R M₁ M₂) := coe_injective.addCommMonoid _ rfl (fun _ _ => rfl) fun _ _ => rfl /-- Coercion of a multilinear map to a function as an additive monoid homomorphism. -/ @[simps] def coeAddMonoidHom : MultilinearMap R M₁ M₂ →+ (((i : ι) → M₁ i) → M₂) where toFun := DFunLike.coe; map_zero' := rfl; map_add' _ _ := rfl @[simp] theorem coe_sum {α : Type*} (f : α → MultilinearMap R M₁ M₂) (s : Finset α) : ⇑(∑ a ∈ s, f a) = ∑ a ∈ s, ⇑(f a) := map_sum coeAddMonoidHom f s theorem sum_apply {α : Type*} (f : α → MultilinearMap R M₁ M₂) (m : ∀ i, M₁ i) {s : Finset α} : (∑ a ∈ s, f a) m = ∑ a ∈ s, f a m := by simp /-- If `f` is a multilinear map, then `f.toLinearMap m i` is the linear map obtained by fixing all coordinates but `i` equal to those of `m`, and varying the `i`-th coordinate. -/ @[simps] def toLinearMap [DecidableEq ι] (m : ∀ i, M₁ i) (i : ι) : M₁ i →ₗ[R] M₂ where toFun x := f (update m i x) map_add' x y := by simp map_smul' c x := by simp /-- The Cartesian product of two multilinear maps, as a multilinear map. -/ @[simps] def prod (f : MultilinearMap R M₁ M₂) (g : MultilinearMap R M₁ M₃) : MultilinearMap R M₁ (M₂ × M₃) where toFun m := (f m, g m) map_update_add' m i x y := by simp map_update_smul' m i c x := by simp /-- Combine a family of multilinear maps with the same domain and codomains `M' i` into a multilinear map taking values in the space of functions `∀ i, M' i`. -/ @[simps] def pi {ι' : Type*} {M' : ι' → Type*} [∀ i, AddCommMonoid (M' i)] [∀ i, Module R (M' i)] (f : ∀ i, MultilinearMap R M₁ (M' i)) : MultilinearMap R M₁ (∀ i, M' i) where toFun m i := f i m map_update_add' _ _ _ _ := funext fun j => (f j).map_update_add _ _ _ _ map_update_smul' _ _ _ _ := funext fun j => (f j).map_update_smul _ _ _ _ section variable (R M₂ M₃) /-- Equivalence between linear maps `M₂ →ₗ[R] M₃` and one-multilinear maps. -/ @[simps] def ofSubsingleton [Subsingleton ι] (i : ι) : (M₂ →ₗ[R] M₃) ≃ MultilinearMap R (fun _ : ι ↦ M₂) M₃ where toFun f := { toFun := fun x ↦ f (x i) map_update_add' := by intros; simp [update_eq_const_of_subsingleton] map_update_smul' := by intros; simp [update_eq_const_of_subsingleton] } invFun f := { toFun := fun x ↦ f fun _ ↦ x map_add' := fun x y ↦ by simpa [update_eq_const_of_subsingleton] using f.map_update_add 0 i x y map_smul' := fun c x ↦ by simpa [update_eq_const_of_subsingleton] using f.map_update_smul 0 i c x } right_inv f := by ext x; refine congr_arg f ?_; exact (eq_const_of_subsingleton _ _).symm variable (M₁) {M₂} /-- The constant map is multilinear when `ι` is empty. -/ @[simps -fullyApplied] def constOfIsEmpty [IsEmpty ι] (m : M₂) : MultilinearMap R M₁ M₂ where toFun := Function.const _ m map_update_add' _ := isEmptyElim map_update_smul' _ := isEmptyElim end /-- Given a multilinear map `f` on `n` variables (parameterized by `Fin n`) and a subset `s` of `k` of these variables, one gets a new multilinear map on `Fin k` by varying these variables, and fixing the other ones equal to a given value `z`. It is denoted by `f.restr s hk z`, where `hk` is a proof that the cardinality of `s` is `k`. The implicit identification between `Fin k` and `s` that we use is the canonical (increasing) bijection. -/ def restr {k n : ℕ} (f : MultilinearMap R (fun _ : Fin n => M') M₂) (s : Finset (Fin n)) (hk : #s = k) (z : M') : MultilinearMap R (fun _ : Fin k => M') M₂ where toFun v := f fun j => if h : j ∈ s then v ((s.orderIsoOfFin hk).symm ⟨j, h⟩) else z map_update_add' v i x y := by erw [dite_comp_equiv_update (s.orderIsoOfFin hk).toEquiv, dite_comp_equiv_update (s.orderIsoOfFin hk).toEquiv, dite_comp_equiv_update (s.orderIsoOfFin hk).toEquiv] simp map_update_smul' v i c x := by erw [dite_comp_equiv_update (s.orderIsoOfFin hk).toEquiv, dite_comp_equiv_update (s.orderIsoOfFin hk).toEquiv] simp /-- In the specific case of multilinear maps on spaces indexed by `Fin (n+1)`, where one can build an element of `∀ (i : Fin (n+1)), M i` using `cons`, one can express directly the additivity of a multilinear map along the first variable. -/ theorem cons_add (f : MultilinearMap R M M₂) (m : ∀ i : Fin n, M i.succ) (x y : M 0) : f (cons (x + y) m) = f (cons x m) + f (cons y m) := by simp_rw [← update_cons_zero x m (x + y), f.map_update_add, update_cons_zero] /-- In the specific case of multilinear maps on spaces indexed by `Fin (n+1)`, where one can build an element of `∀ (i : Fin (n+1)), M i` using `cons`, one can express directly the multiplicativity of a multilinear map along the first variable. -/ theorem cons_smul (f : MultilinearMap R M M₂) (m : ∀ i : Fin n, M i.succ) (c : R) (x : M 0) : f (cons (c • x) m) = c • f (cons x m) := by simp_rw [← update_cons_zero x m (c • x), f.map_update_smul, update_cons_zero] /-- In the specific case of multilinear maps on spaces indexed by `Fin (n+1)`, where one can build an element of `∀ (i : Fin (n+1)), M i` using `snoc`, one can express directly the additivity of a multilinear map along the first variable. -/ theorem snoc_add (f : MultilinearMap R M M₂) (m : ∀ i : Fin n, M (castSucc i)) (x y : M (last n)) : f (snoc m (x + y)) = f (snoc m x) + f (snoc m y) := by simp_rw [← update_snoc_last x m (x + y), f.map_update_add, update_snoc_last] /-- In the specific case of multilinear maps on spaces indexed by `Fin (n+1)`, where one can build an element of `∀ (i : Fin (n+1)), M i` using `cons`, one can express directly the multiplicativity of a multilinear map along the first variable. -/ theorem snoc_smul (f : MultilinearMap R M M₂) (m : ∀ i : Fin n, M (castSucc i)) (c : R) (x : M (last n)) : f (snoc m (c • x)) = c • f (snoc m x) := by simp_rw [← update_snoc_last x m (c • x), f.map_update_smul, update_snoc_last] theorem map_insertNth_add (f : MultilinearMap R M M₂) (p : Fin (n + 1)) (m : ∀ i, M (p.succAbove i)) (x y : M p) : f (p.insertNth (x + y) m) = f (p.insertNth x m) + f (p.insertNth y m) := by simpa using f.map_update_add (p.insertNth 0 m) p x y theorem map_insertNth_smul (f : MultilinearMap R M M₂) (p : Fin (n + 1)) (m : ∀ i, M (p.succAbove i)) (c : R) (x : M p) : f (p.insertNth (c • x) m) = c • f (p.insertNth x m) := by simpa using f.map_update_smul (p.insertNth 0 m) p c x section variable [∀ i, AddCommMonoid (M₁' i)] [∀ i, Module R (M₁' i)] variable [∀ i, AddCommMonoid (M₁'' i)] [∀ i, Module R (M₁'' i)] /-- If `g` is a multilinear map and `f` is a collection of linear maps, then `g (f₁ m₁, ..., fₙ mₙ)` is again a multilinear map, that we call `g.compLinearMap f`. -/ def compLinearMap (g : MultilinearMap R M₁' M₂) (f : ∀ i, M₁ i →ₗ[R] M₁' i) : MultilinearMap R M₁ M₂ where toFun m := g fun i => f i (m i) map_update_add' m i x y := by have : ∀ j z, f j (update m i z j) = update (fun k => f k (m k)) i (f i z) j := fun j z => Function.apply_update (fun k => f k) _ _ _ _ simp [this] map_update_smul' m i c x := by have : ∀ j z, f j (update m i z j) = update (fun k => f k (m k)) i (f i z) j := fun j z => Function.apply_update (fun k => f k) _ _ _ _ simp [this] @[simp] theorem compLinearMap_apply (g : MultilinearMap R M₁' M₂) (f : ∀ i, M₁ i →ₗ[R] M₁' i) (m : ∀ i, M₁ i) : g.compLinearMap f m = g fun i => f i (m i) := rfl /-- Composing a multilinear map twice with a linear map in each argument is the same as composing with their composition. -/ theorem compLinearMap_assoc (g : MultilinearMap R M₁'' M₂) (f₁ : ∀ i, M₁' i →ₗ[R] M₁'' i) (f₂ : ∀ i, M₁ i →ₗ[R] M₁' i) : (g.compLinearMap f₁).compLinearMap f₂ = g.compLinearMap fun i => f₁ i ∘ₗ f₂ i := rfl /-- Composing the zero multilinear map with a linear map in each argument. -/ @[simp] theorem zero_compLinearMap (f : ∀ i, M₁ i →ₗ[R] M₁' i) : (0 : MultilinearMap R M₁' M₂).compLinearMap f = 0 := ext fun _ => rfl /-- Composing a multilinear map with the identity linear map in each argument. -/ @[simp] theorem compLinearMap_id (g : MultilinearMap R M₁' M₂) : (g.compLinearMap fun _ => LinearMap.id) = g := ext fun _ => rfl /-- Composing with a family of surjective linear maps is injective. -/ theorem compLinearMap_injective (f : ∀ i, M₁ i →ₗ[R] M₁' i) (hf : ∀ i, Surjective (f i)) : Injective fun g : MultilinearMap R M₁' M₂ => g.compLinearMap f := fun g₁ g₂ h => ext fun x => by simpa [fun i => surjInv_eq (hf i)] using MultilinearMap.ext_iff.mp h fun i => surjInv (hf i) (x i) theorem compLinearMap_inj (f : ∀ i, M₁ i →ₗ[R] M₁' i) (hf : ∀ i, Surjective (f i)) (g₁ g₂ : MultilinearMap R M₁' M₂) : g₁.compLinearMap f = g₂.compLinearMap f ↔ g₁ = g₂ := (compLinearMap_injective _ hf).eq_iff /-- Composing a multilinear map with a linear equiv on each argument gives the zero map if and only if the multilinear map is the zero map. -/ @[simp] theorem comp_linearEquiv_eq_zero_iff (g : MultilinearMap R M₁' M₂) (f : ∀ i, M₁ i ≃ₗ[R] M₁' i) : (g.compLinearMap fun i => (f i : M₁ i →ₗ[R] M₁' i)) = 0 ↔ g = 0 := by set f' := fun i => (f i : M₁ i →ₗ[R] M₁' i) rw [← zero_compLinearMap f', compLinearMap_inj f' fun i => (f i).surjective] end /-- If one adds to a vector `m'` another vector `m`, but only for coordinates in a finset `t`, then the image under a multilinear map `f` is the sum of `f (s.piecewise m m')` along all subsets `s` of `t`. This is mainly an auxiliary statement to prove the result when `t = univ`, given in `map_add_univ`, although it can be useful in its own right as it does not require the index set `ι` to be finite. -/ theorem map_piecewise_add [DecidableEq ι] (m m' : ∀ i, M₁ i) (t : Finset ι) : f (t.piecewise (m + m') m') = ∑ s ∈ t.powerset, f (s.piecewise m m') := by revert m' refine Finset.induction_on t (by simp) ?_ intro i t hit Hrec m' have A : (insert i t).piecewise (m + m') m' = update (t.piecewise (m + m') m') i (m i + m' i) := t.piecewise_insert _ _ _ have B : update (t.piecewise (m + m') m') i (m' i) = t.piecewise (m + m') m' := by ext j by_cases h : j = i · rw [h] simp [hit] · simp [h] let m'' := update m' i (m i) have C : update (t.piecewise (m + m') m') i (m i) = t.piecewise (m + m'') m'' := by ext j by_cases h : j = i · rw [h] simp [m'', hit] · by_cases h' : j ∈ t <;> simp [m'', h, h'] rw [A, f.map_update_add, B, C, Finset.sum_powerset_insert hit, Hrec, Hrec, add_comm (_ : M₂)] congr 1 refine Finset.sum_congr rfl fun s hs => ?_ have : (insert i s).piecewise m m' = s.piecewise m m'' := by ext j by_cases h : j = i · rw [h] simp [m'', Finset.notMem_of_mem_powerset_of_notMem hs hit] · by_cases h' : j ∈ s <;> simp [m'', h, h'] rw [this] /-- Additivity of a multilinear map along all coordinates at the same time, writing `f (m + m')` as the sum of `f (s.piecewise m m')` over all sets `s`. -/ theorem map_add_univ [DecidableEq ι] [Fintype ι] (m m' : ∀ i, M₁ i) : f (m + m') = ∑ s : Finset ι, f (s.piecewise m m') := by simpa using f.map_piecewise_add m m' Finset.univ section ApplySum variable {α : ι → Type*} (g : ∀ i, α i → M₁ i) (A : ∀ i, Finset (α i)) open Fintype Finset /-- If `f` is multilinear, then `f (Σ_{j₁ ∈ A₁} g₁ j₁, ..., Σ_{jₙ ∈ Aₙ} gₙ jₙ)` is the sum of `f (g₁ (r 1), ..., gₙ (r n))` where `r` ranges over all functions with `r 1 ∈ A₁`, ..., `r n ∈ Aₙ`. This follows from multilinearity by expanding successively with respect to each coordinate. Here, we give an auxiliary statement tailored for an inductive proof. Use instead `map_sum_finset`. -/ theorem map_sum_finset_aux [DecidableEq ι] [Fintype ι] {n : ℕ} (h : (∑ i, #(A i)) = n) : (f fun i => ∑ j ∈ A i, g i j) = ∑ r ∈ piFinset A, f fun i => g i (r i) := by letI := fun i => Classical.decEq (α i) induction n using Nat.strong_induction_on generalizing A with | h n IH => -- If one of the sets is empty, then all the sums are zero by_cases! Ai_empty : ∃ i, A i = ∅ · obtain ⟨i, hi⟩ : ∃ i, ∑ j ∈ A i, g i j = 0 := Ai_empty.imp fun i hi ↦ by simp [hi] have hpi : piFinset A = ∅ := by simpa rw [f.map_coord_zero i hi, hpi, Finset.sum_empty] -- Otherwise, if all sets are at most singletons, then they are exactly singletons and the result -- is again straightforward by_cases! Ai_singleton : ∀ i, #(A i) ≤ 1 · have Ai_card : ∀ i, #(A i) = 1 := by intro i have pos : #(A i) ≠ 0 := by simp [Finset.card_eq_zero, Ai_empty i] have : #(A i) ≤ 1 := Ai_singleton i exact le_antisymm this (Nat.succ_le_of_lt (_root_.pos_iff_ne_zero.mpr pos)) have : ∀ r : ∀ i, α i, r ∈ piFinset A → (f fun i => g i (r i)) = f fun i => ∑ j ∈ A i, g i j := by intro r hr congr with i have : ∀ j ∈ A i, g i j = g i (r i) := by intro j hj congr apply Finset.card_le_one_iff.1 (Ai_singleton i) hj exact mem_piFinset.mp hr i simp only [Finset.sum_congr rfl this, Finset.sum_const, Ai_card i, one_nsmul] simp only [Finset.sum_congr rfl this, Ai_card, card_piFinset, prod_const_one, one_nsmul, Finset.sum_const] -- Remains the interesting case where one of the `A i`, say `A i₀`, has cardinality at least 2. -- We will split into two parts `B i₀` and `C i₀` of smaller cardinality, let `B i = C i = A i` -- for `i ≠ i₀`, apply the inductive assumption to `B` and `C`, and add up the corresponding -- parts to get the sum for `A`. obtain ⟨i₀, hi₀⟩ : ∃ i, 1 < #(A i) := Ai_singleton obtain ⟨j₁, j₂, _, hj₂, _⟩ : ∃ j₁ j₂, j₁ ∈ A i₀ ∧ j₂ ∈ A i₀ ∧ j₁ ≠ j₂ := Finset.one_lt_card_iff.1 hi₀ let B := Function.update A i₀ (A i₀ \ {j₂}) let C := Function.update A i₀ {j₂} have B_subset_A : ∀ i, B i ⊆ A i := by intro i by_cases hi : i = i₀ · rw [hi] simp only [B, sdiff_subset, update_self] · simp only [B, hi, update_of_ne, Ne, not_false_iff, Finset.Subset.refl] have C_subset_A : ∀ i, C i ⊆ A i := by intro i by_cases hi : i = i₀ · rw [hi] simp only [C, hj₂, Finset.singleton_subset_iff, update_self] · simp only [C, hi, update_of_ne, Ne, not_false_iff, Finset.Subset.refl] -- split the sum at `i₀` as the sum over `B i₀` plus the sum over `C i₀`, to use additivity. have A_eq_BC : (fun i => ∑ j ∈ A i, g i j) = Function.update (fun i => ∑ j ∈ A i, g i j) i₀ ((∑ j ∈ B i₀, g i₀ j) + ∑ j ∈ C i₀, g i₀ j) := by ext i by_cases hi : i = i₀ · rw [hi, update_self] have : A i₀ = B i₀ ∪ C i₀ := by simp only [B, C, Function.update_self, Finset.sdiff_union_self_eq_union] symm simp only [hj₂, Finset.singleton_subset_iff, Finset.union_eq_left] rw [this] refine Finset.sum_union <| Finset.disjoint_right.2 fun j hj => ?_ have : j = j₂ := by simpa [C] using hj rw [this] simp only [B, mem_sdiff, not_true, not_false_iff, Finset.mem_singleton, update_self, and_false] · simp [hi] have Beq : Function.update (fun i => ∑ j ∈ A i, g i j) i₀ (∑ j ∈ B i₀, g i₀ j) = fun i => ∑ j ∈ B i, g i j := by ext i by_cases hi : i = i₀ · rw [hi] simp only [update_self] · simp only [B, hi, update_of_ne, Ne, not_false_iff] have Ceq : Function.update (fun i => ∑ j ∈ A i, g i j) i₀ (∑ j ∈ C i₀, g i₀ j) = fun i => ∑ j ∈ C i, g i j := by ext i by_cases hi : i = i₀ · rw [hi] simp only [update_self] · simp only [C, hi, update_of_ne, Ne, not_false_iff] -- Express the inductive assumption for `B` have Brec : (f fun i => ∑ j ∈ B i, g i j) = ∑ r ∈ piFinset B, f fun i => g i (r i) := by have : ∑ i, #(B i) < ∑ i, #(A i) := by refine sum_lt_sum (fun i _ => card_le_card (B_subset_A i)) ⟨i₀, mem_univ _, ?_⟩ have : {j₂} ⊆ A i₀ := by simp [hj₂] simp only [B, Finset.card_sdiff_of_subset this, Function.update_self, Finset.card_singleton] exact Nat.pred_lt (ne_of_gt (lt_trans Nat.zero_lt_one hi₀)) rw [h] at this exact IH _ this B rfl -- Express the inductive assumption for `C` have Crec : (f fun i => ∑ j ∈ C i, g i j) = ∑ r ∈ piFinset C, f fun i => g i (r i) := by have : (∑ i, #(C i)) < ∑ i, #(A i) := Finset.sum_lt_sum (fun i _ => Finset.card_le_card (C_subset_A i)) ⟨i₀, Finset.mem_univ _, by simp [C, hi₀]⟩ rw [h] at this exact IH _ this C rfl have D : Disjoint (piFinset B) (piFinset C) := haveI : Disjoint (B i₀) (C i₀) := by simp [B, C] piFinset_disjoint_of_disjoint B C this have pi_BC : piFinset A = piFinset B ∪ piFinset C := by apply Finset.Subset.antisymm · intro r hr by_cases hri₀ : r i₀ = j₂ · apply Finset.mem_union_right refine mem_piFinset.2 fun i => ?_ by_cases hi : i = i₀ · have : r i₀ ∈ C i₀ := by simp [C, hri₀] rwa [hi] · simp [C, hi, mem_piFinset.1 hr i] · apply Finset.mem_union_left refine mem_piFinset.2 fun i => ?_ by_cases hi : i = i₀ · have : r i₀ ∈ B i₀ := by simp [B, hri₀, mem_piFinset.1 hr i₀] rwa [hi] · simp [B, hi, mem_piFinset.1 hr i] · exact Finset.union_subset (piFinset_subset _ _ fun i => B_subset_A i) (piFinset_subset _ _ fun i => C_subset_A i) rw [A_eq_BC] simp only [MultilinearMap.map_update_add, Beq, Ceq, Brec, Crec, pi_BC] rw [← Finset.sum_union D] /-- If `f` is multilinear, then `f (Σ_{j₁ ∈ A₁} g₁ j₁, ..., Σ_{jₙ ∈ Aₙ} gₙ jₙ)` is the sum of `f (g₁ (r 1), ..., gₙ (r n))` where `r` ranges over all functions with `r 1 ∈ A₁`, ..., `r n ∈ Aₙ`. This follows from multilinearity by expanding successively with respect to each coordinate. -/ theorem map_sum_finset [DecidableEq ι] [Fintype ι] : (f fun i => ∑ j ∈ A i, g i j) = ∑ r ∈ piFinset A, f fun i => g i (r i) := f.map_sum_finset_aux _ _ rfl /-- If `f` is multilinear, then `f (Σ_{j₁} g₁ j₁, ..., Σ_{jₙ} gₙ jₙ)` is the sum of `f (g₁ (r 1), ..., gₙ (r n))` where `r` ranges over all functions `r`. This follows from multilinearity by expanding successively with respect to each coordinate. -/ theorem map_sum [DecidableEq ι] [Fintype ι] [∀ i, Fintype (α i)] : (f fun i => ∑ j, g i j) = ∑ r : ∀ i, α i, f fun i => g i (r i) := f.map_sum_finset g fun _ => Finset.univ theorem map_update_sum {α : Type*} [DecidableEq ι] (t : Finset α) (i : ι) (g : α → M₁ i) (m : ∀ i, M₁ i) : f (update m i (∑ a ∈ t, g a)) = ∑ a ∈ t, f (update m i (g a)) := by classical induction t using Finset.induction with | empty => simp | insert _ _ has ih => simp [Finset.sum_insert has, ih] end ApplySum /-- Restrict the codomain of a multilinear map to a submodule. This is the multilinear version of `LinearMap.codRestrict`. -/ @[simps] def codRestrict (f : MultilinearMap R M₁ M₂) (p : Submodule R M₂) (h : ∀ v, f v ∈ p) : MultilinearMap R M₁ p where toFun v := ⟨f v, h v⟩ map_update_add' _ _ _ _ := Subtype.ext <| MultilinearMap.map_update_add _ _ _ _ _ map_update_smul' _ _ _ _ := Subtype.ext <| MultilinearMap.map_update_smul _ _ _ _ _ section RestrictScalar variable (R) variable {A : Type*} [Semiring A] [SMul R A] [∀ i : ι, Module A (M₁ i)] [Module A M₂] [∀ i, IsScalarTower R A (M₁ i)] [IsScalarTower R A M₂] /-- Reinterpret an `A`-multilinear map as an `R`-multilinear map, if `A` is an algebra over `R` and their actions on all involved modules agree with the action of `R` on `A`. -/ def restrictScalars (f : MultilinearMap A M₁ M₂) : MultilinearMap R M₁ M₂ where toFun := f map_update_add' := f.map_update_add map_update_smul' m i := (f.toLinearMap m i).map_smul_of_tower @[simp] theorem coe_restrictScalars (f : MultilinearMap A M₁ M₂) : ⇑(f.restrictScalars R) = f := rfl end RestrictScalar section variable {ι₁ ι₂ ι₃ : Type*} /-- Transfer the arguments to a map along an equivalence between argument indices. The naming is derived from `Finsupp.domCongr`, noting that here the permutation applies to the domain of the domain. -/ @[simps apply] def domDomCongr (σ : ι₁ ≃ ι₂) (m : MultilinearMap R (fun _ : ι₁ => M₂) M₃) : MultilinearMap R (fun _ : ι₂ => M₂) M₃ where toFun v := m fun i => v (σ i) map_update_add' v i a b := by letI := σ.injective.decidableEq simp_rw [Function.update_apply_equiv_apply v] rw [m.map_update_add] map_update_smul' v i a b := by letI := σ.injective.decidableEq simp_rw [Function.update_apply_equiv_apply v] rw [m.map_update_smul] theorem domDomCongr_trans (σ₁ : ι₁ ≃ ι₂) (σ₂ : ι₂ ≃ ι₃) (m : MultilinearMap R (fun _ : ι₁ => M₂) M₃) : m.domDomCongr (σ₁.trans σ₂) = (m.domDomCongr σ₁).domDomCongr σ₂ := rfl theorem domDomCongr_mul (σ₁ : Equiv.Perm ι₁) (σ₂ : Equiv.Perm ι₁) (m : MultilinearMap R (fun _ : ι₁ => M₂) M₃) : m.domDomCongr (σ₂ * σ₁) = (m.domDomCongr σ₁).domDomCongr σ₂ := rfl /-- `MultilinearMap.domDomCongr` as an equivalence. This is declared separately because it does not work with dot notation. -/ @[simps apply symm_apply] def domDomCongrEquiv (σ : ι₁ ≃ ι₂) : MultilinearMap R (fun _ : ι₁ => M₂) M₃ ≃+ MultilinearMap R (fun _ : ι₂ => M₂) M₃ where toFun := domDomCongr σ invFun := domDomCongr σ.symm left_inv m := by ext simp [domDomCongr] right_inv m := by ext simp [domDomCongr] map_add' a b := by ext simp [domDomCongr] /-- The results of applying `domDomCongr` to two maps are equal if and only if those maps are. -/ @[simp] theorem domDomCongr_eq_iff (σ : ι₁ ≃ ι₂) (f g : MultilinearMap R (fun _ : ι₁ => M₂) M₃) : f.domDomCongr σ = g.domDomCongr σ ↔ f = g := (domDomCongrEquiv σ : _ ≃+ MultilinearMap R (fun _ => M₂) M₃).apply_eq_iff_eq end /-! If `{a // P a}` is a subtype of `ι` and if we fix an element `z` of `(i : {a // ¬ P a}) → M₁ i`, then a multilinear map on `M₁` defines a multilinear map on the restriction of `M₁` to `{a // P a}`, by fixing the arguments out of `{a // P a}` equal to the values of `z`. -/ lemma domDomRestrict_aux {ι} [DecidableEq ι] (P : ι → Prop) [DecidablePred P] {M₁ : ι → Type*} [DecidableEq {a // P a}] (x : (i : {a // P a}) → M₁ i) (z : (i : {a // ¬ P a}) → M₁ i) (i : {a : ι // P a}) (c : M₁ i) : (fun j ↦ if h : P j then Function.update x i c ⟨j, h⟩ else z ⟨j, h⟩) = Function.update (fun j => if h : P j then x ⟨j, h⟩ else z ⟨j, h⟩) i c := by grind lemma domDomRestrict_aux_right {ι} [DecidableEq ι] (P : ι → Prop) [DecidablePred P] {M₁ : ι → Type*} [DecidableEq {a // ¬ P a}] (x : (i : {a // P a}) → M₁ i) (z : (i : {a // ¬ P a}) → M₁ i) (i : {a : ι // ¬ P a}) (c : M₁ i) : (fun j ↦ if h : P j then x ⟨j, h⟩ else Function.update z i c ⟨j, h⟩) = Function.update (fun j => if h : P j then x ⟨j, h⟩ else z ⟨j, h⟩) i c := by simpa only [dite_not] using domDomRestrict_aux _ z (fun j ↦ x ⟨j.1, not_not.mp j.2⟩) i c /-- Given a multilinear map `f` on `(i : ι) → M i`, a (decidable) predicate `P` on `ι` and an element `z` of `(i : {a // ¬ P a}) → M₁ i`, construct a multilinear map on `(i : {a // P a}) → M₁ i)` whose value at `x` is `f` evaluated at the vector with `i`th coordinate `x i` if `P i` and `z i` otherwise. The naming is similar to `MultilinearMap.domDomCongr`: here we are applying the restriction to the domain of the domain. For a linear map version, see `MultilinearMap.domDomRestrictₗ`. -/ def domDomRestrict (f : MultilinearMap R M₁ M₂) (P : ι → Prop) [DecidablePred P] (z : (i : {a : ι // ¬ P a}) → M₁ i) : MultilinearMap R (fun (i : {a : ι // P a}) => M₁ i) M₂ where toFun x := f (fun j ↦ if h : P j then x ⟨j, h⟩ else z ⟨j, h⟩) map_update_add' x i a b := by classical repeat (rw [domDomRestrict_aux]) simp only [MultilinearMap.map_update_add] map_update_smul' z i c a := by classical repeat (rw [domDomRestrict_aux]) simp only [MultilinearMap.map_update_smul] @[simp] lemma domDomRestrict_apply (f : MultilinearMap R M₁ M₂) (P : ι → Prop) [DecidablePred P] (x : (i : {a // P a}) → M₁ i) (z : (i : {a // ¬ P a}) → M₁ i) : f.domDomRestrict P z x = f (fun j => if h : P j then x ⟨j, h⟩ else z ⟨j, h⟩) := rfl -- TODO: Should add a ref here when available. /-- The "derivative" of a multilinear map, as a linear map from `(i : ι) → M₁ i` to `M₂`. For continuous multilinear maps, this will indeed be the derivative. -/ def linearDeriv [DecidableEq ι] [Fintype ι] (f : MultilinearMap R M₁ M₂) (x : (i : ι) → M₁ i) : ((i : ι) → M₁ i) →ₗ[R] M₂ := ∑ i : ι, (f.toLinearMap x i).comp (LinearMap.proj i) @[simp] lemma linearDeriv_apply [DecidableEq ι] [Fintype ι] (f : MultilinearMap R M₁ M₂) (x y : (i : ι) → M₁ i) : f.linearDeriv x y = ∑ i, f (update x i (y i)) := by unfold linearDeriv simp only [LinearMap.coeFn_sum, LinearMap.coe_comp, LinearMap.coe_proj, Finset.sum_apply, Function.comp_apply, Function.eval, toLinearMap_apply] end Semiring end MultilinearMap namespace LinearMap variable [Semiring R] variable [∀ i, AddCommMonoid (M₁ i)] [∀ i, AddCommMonoid (M₁' i)] [AddCommMonoid M₂] [AddCommMonoid M₃] [AddCommMonoid M₄] [AddCommMonoid M'] variable [∀ i, Module R (M₁ i)] [∀ i, Module R (M₁' i)] [Module R M₂] [Module R M₃] [Module R M₄] [Module R M'] /-- Composing a multilinear map with a linear map gives again a multilinear map. -/ def compMultilinearMap (g : M₂ →ₗ[R] M₃) (f : MultilinearMap R M₁ M₂) : MultilinearMap R M₁ M₃ where toFun := g ∘ f map_update_add' m i x y := by simp map_update_smul' m i c x := by simp @[simp] theorem coe_compMultilinearMap (g : M₂ →ₗ[R] M₃) (f : MultilinearMap R M₁ M₂) : ⇑(g.compMultilinearMap f) = g ∘ f := rfl @[simp] theorem compMultilinearMap_apply (g : M₂ →ₗ[R] M₃) (f : MultilinearMap R M₁ M₂) (m : ∀ i, M₁ i) : g.compMultilinearMap f m = g (f m) := rfl @[simp] theorem id_compMultilinearMap (f : MultilinearMap R M₁ M₂) : (id : M₂ →ₗ[R] M₂).compMultilinearMap f = f := rfl theorem comp_compMultilinearMap (g : M₃ →ₗ[R] M₄) (g' : M₂ →ₗ[R] M₃) (f : MultilinearMap R M₁ M₂) : (g.comp g').compMultilinearMap f = g.compMultilinearMap (g'.compMultilinearMap f) := rfl /-- The two types of composition are associative. -/ theorem compMultilinearMap_compLinearMap (g : M₂ →ₗ[R] M₃) (f : MultilinearMap R M₁ M₂) (f' : ∀ i, M₁' i →ₗ[R] M₁ i) : g.compMultilinearMap (f.compLinearMap f') = (g.compMultilinearMap f).compLinearMap f' := rfl @[simp] theorem compMultilinearMap_zero (g : M₂ →ₗ[R] M₃) : g.compMultilinearMap (0 : MultilinearMap R M₁ M₂) = 0 := MultilinearMap.ext fun _ => map_zero g @[simp] theorem zero_compMultilinearMap (f : MultilinearMap R M₁ M₂) : (0 : M₂ →ₗ[R] M₃).compMultilinearMap f = 0 := rfl @[simp] theorem compMultilinearMap_add (g : M₂ →ₗ[R] M₃) (f₁ f₂ : MultilinearMap R M₁ M₂) : g.compMultilinearMap (f₁ + f₂) = g.compMultilinearMap f₁ + g.compMultilinearMap f₂ := MultilinearMap.ext fun _ => map_add g _ _ @[simp] theorem add_compMultilinearMap (g₁ g₂ : M₂ →ₗ[R] M₃) (f : MultilinearMap R M₁ M₂) : (g₁ + g₂).compMultilinearMap f = g₁.compMultilinearMap f + g₂.compMultilinearMap f := rfl @[simp] theorem compMultilinearMap_smul [DistribSMul S M₂] [DistribSMul S M₃] [SMulCommClass R S M₂] [SMulCommClass R S M₃] [CompatibleSMul M₂ M₃ S R] (g : M₂ →ₗ[R] M₃) (s : S) (f : MultilinearMap R M₁ M₂) : g.compMultilinearMap (s • f) = s • g.compMultilinearMap f := MultilinearMap.ext fun _ => g.map_smul_of_tower _ _ @[simp] theorem smul_compMultilinearMap [Monoid S] [DistribMulAction S M₃] [SMulCommClass R S M₃] (g : M₂ →ₗ[R] M₃) (s : S) (f : MultilinearMap R M₁ M₂) : (s • g).compMultilinearMap f = s • g.compMultilinearMap f := rfl /-- The multilinear version of `LinearMap.subtype_comp_codRestrict` -/ @[simp] theorem subtype_compMultilinearMap_codRestrict (f : MultilinearMap R M₁ M₂) (p : Submodule R M₂) (h) : p.subtype.compMultilinearMap (f.codRestrict p h) = f := rfl /-- The multilinear version of `LinearMap.comp_codRestrict` -/ @[simp] theorem compMultilinearMap_codRestrict (g : M₂ →ₗ[R] M₃) (f : MultilinearMap R M₁ M₂) (p : Submodule R M₃) (h) : (g.codRestrict p h).compMultilinearMap f = (g.compMultilinearMap f).codRestrict p fun v => h (f v) := rfl variable {ι₁ ι₂ : Type*} @[simp] theorem compMultilinearMap_domDomCongr (σ : ι₁ ≃ ι₂) (g : M₂ →ₗ[R] M₃) (f : MultilinearMap R (fun _ : ι₁ => M') M₂) : (g.compMultilinearMap f).domDomCongr σ = g.compMultilinearMap (f.domDomCongr σ) := by ext simp [MultilinearMap.domDomCongr] end LinearMap namespace MultilinearMap section Semiring variable [Semiring R] [(i : ι) → AddCommMonoid (M₁ i)] [(i : ι) → Module R (M₁ i)] [AddCommMonoid M₂] [Module R M₂] instance [Monoid S] [DistribMulAction S M₂] [Module R M₂] [SMulCommClass R S M₂] : DistribMulAction S (MultilinearMap R M₁ M₂) := coe_injective.distribMulAction coeAddMonoidHom fun _ _ ↦ rfl section Module variable [Semiring S] [Module S M₂] [SMulCommClass R S M₂] /-- The space of multilinear maps over an algebra over `R` is a module over `R`, for the pointwise addition and scalar multiplication. -/ instance : Module S (MultilinearMap R M₁ M₂) := coe_injective.module _ coeAddMonoidHom fun _ _ ↦ rfl instance [NoZeroSMulDivisors S M₂] : NoZeroSMulDivisors S (MultilinearMap R M₁ M₂) := coe_injective.noZeroSMulDivisors _ rfl coe_smul variable [AddCommMonoid M₃] [Module S M₃] [Module R M₃] [SMulCommClass R S M₃] variable (S) in /-- `LinearMap.compMultilinearMap` as an `S`-linear map. -/ @[simps] def _root_.LinearMap.compMultilinearMapₗ [LinearMap.CompatibleSMul M₂ M₃ S R] (g : M₂ →ₗ[R] M₃) : MultilinearMap R M₁ M₂ →ₗ[S] MultilinearMap R M₁ M₃ where toFun := g.compMultilinearMap map_add' := g.compMultilinearMap_add map_smul' := g.compMultilinearMap_smul variable (S) in /-- An isomorphism of multilinear maps given an isomorphism between their codomains. This is `LinearMap.compMultilinearMap` as an `S`-linear equivalence, and the multilinear version of `LinearEquiv.congrRight`. -/ @[simps! apply symm_apply] def _root_.LinearEquiv.multilinearMapCongrRight [LinearMap.CompatibleSMul M₂ M₃ S R] [LinearMap.CompatibleSMul M₃ M₂ S R] (g : M₂ ≃ₗ[R] M₃) : MultilinearMap R M₁ M₂ ≃ₗ[S] MultilinearMap R M₁ M₃ where __ := g.toLinearMap.compMultilinearMapₗ S invFun := g.symm.toLinearMap.compMultilinearMapₗ S left_inv _ := by ext; simp right_inv _ := by ext; simp variable (R S M₁ M₂ M₃) section OfSubsingleton /-- Linear equivalence between linear maps `M₂ →ₗ[R] M₃` and one-multilinear maps `MultilinearMap R (fun _ : ι ↦ M₂) M₃`. -/ @[simps +simpRhs] def ofSubsingletonₗ [Subsingleton ι] (i : ι) : (M₂ →ₗ[R] M₃) ≃ₗ[S] MultilinearMap R (fun _ : ι ↦ M₂) M₃ := { ofSubsingleton R M₂ M₃ i with map_add' := fun _ _ ↦ rfl map_smul' := fun _ _ ↦ rfl } end OfSubsingleton /-- The dependent version of `MultilinearMap.domDomCongrLinearEquiv`. -/ @[simps apply symm_apply] def domDomCongrLinearEquiv' {ι' : Type*} (σ : ι ≃ ι') : MultilinearMap R M₁ M₂ ≃ₗ[S] MultilinearMap R (fun i => M₁ (σ.symm i)) M₂ where toFun f := { toFun := f ∘ (σ.piCongrLeft' M₁).symm map_update_add' := fun m i => by letI := σ.decidableEq rw [← σ.apply_symm_apply i] intro x y simp only [comp_apply, piCongrLeft'_symm_update, f.map_update_add] map_update_smul' := fun m i c => by letI := σ.decidableEq rw [← σ.apply_symm_apply i] intro x simp only [Function.comp, piCongrLeft'_symm_update, f.map_update_smul] } invFun f := { toFun := f ∘ σ.piCongrLeft' M₁ map_update_add' := fun m i => by letI := σ.symm.decidableEq rw [← σ.symm_apply_apply i] intro x y simp only [comp_apply, piCongrLeft'_update, f.map_update_add] map_update_smul' := fun m i c => by letI := σ.symm.decidableEq rw [← σ.symm_apply_apply i] intro x simp only [Function.comp, piCongrLeft'_update, f.map_update_smul] } map_add' f₁ f₂ := by ext simp only [Function.comp, coe_mk, add_apply] map_smul' c f := by ext simp only [Function.comp, coe_mk, smul_apply, RingHom.id_apply] left_inv f := by ext simp only [coe_mk, comp_apply, Equiv.symm_apply_apply] right_inv f := by ext simp only [coe_mk, comp_apply, Equiv.apply_symm_apply] /-- The space of constant maps is equivalent to the space of maps that are multilinear with respect to an empty family. -/ @[simps] def constLinearEquivOfIsEmpty [IsEmpty ι] : M₂ ≃ₗ[S] MultilinearMap R M₁ M₂ where toFun := MultilinearMap.constOfIsEmpty R _ map_add' _ _ := rfl map_smul' _ _ := rfl invFun f := f 0 right_inv f := ext fun _ => MultilinearMap.congr_arg f <| Subsingleton.elim _ _ /-- `MultilinearMap.domDomCongr` as a `LinearEquiv`. -/ @[simps apply symm_apply] def domDomCongrLinearEquiv {ι₁ ι₂} (σ : ι₁ ≃ ι₂) : MultilinearMap R (fun _ : ι₁ => M₂) M₃ ≃ₗ[S] MultilinearMap R (fun _ : ι₂ => M₂) M₃ := { (domDomCongrEquiv σ : MultilinearMap R (fun _ : ι₁ => M₂) M₃ ≃+ MultilinearMap R (fun _ : ι₂ => M₂) M₃) with map_smul' := fun c f => by ext simp [MultilinearMap.domDomCongr] } end Module end Semiring section CommSemiring variable [CommSemiring R] [∀ i, AddCommMonoid (M₁ i)] [∀ i, AddCommMonoid (M i)] [AddCommMonoid M₂] [∀ i, Module R (M i)] [∀ i, Module R (M₁ i)] [Module R M₂] (f f' : MultilinearMap R M₁ M₂) section variable [Π i, AddCommMonoid (M₁' i)] [Π i, Module R (M₁' i)] /-- Given a predicate `P`, one may associate to a multilinear map `f` a multilinear map from the elements satisfying `P` to the multilinear maps on elements not satisfying `P`. In other words, splitting the variables into two subsets one gets a multilinear map into multilinear maps. This is a linear map version of the function `MultilinearMap.domDomRestrict`. -/ def domDomRestrictₗ (f : MultilinearMap R M₁ M₂) (P : ι → Prop) [DecidablePred P] : MultilinearMap R (fun (i : {a : ι // ¬ P a}) => M₁ i) (MultilinearMap R (fun (i : {a : ι // P a}) => M₁ i) M₂) where toFun := fun z ↦ domDomRestrict f P z map_update_add' := by intro h m i x y classical ext v simp [domDomRestrict_aux_right] map_update_smul' := by intro h m i c x classical ext v simp [domDomRestrict_aux_right] lemma iteratedFDeriv_aux {ι} {M₁ : ι → Type*} {α : Type*} [DecidableEq α] (s : Set ι) [DecidableEq { x // x ∈ s }] (e : α ≃ s) (m : α → ((i : ι) → M₁ i)) (a : α) (z : (i : ι) → M₁ i) : (fun i ↦ update m a z (e.symm i) i) = (fun i ↦ update (fun j ↦ m (e.symm j) j) (e a) (z (e a)) i) := by ext i rcases eq_or_ne a (e.symm i) with rfl | hne · rw [Equiv.apply_symm_apply e i, update_self, update_self] · rw [update_of_ne hne.symm, update_of_ne fun h ↦ (Equiv.symm_apply_apply .. ▸ h ▸ hne) rfl] /-- One of the components of the iterated derivative of a multilinear map. Given a bijection `e` between a type `α` (typically `Fin k`) and a subset `s` of `ι`, this component is a multilinear map of `k` vectors `v₁, ..., vₖ`, mapping them to `f (x₁, (v_{e.symm 2})₂, x₃, ...)`, where at indices `i` in `s` one uses the `i`-th coordinate of the vector `v_{e.symm i}` and otherwise one uses the `i`-th coordinate of a reference vector `x`. This is multilinear in the components of `x` outside of `s`, and in the `v_j`. -/ noncomputable def iteratedFDerivComponent {α : Type*} (f : MultilinearMap R M₁ M₂) {s : Set ι} (e : α ≃ s) [DecidablePred (· ∈ s)] : MultilinearMap R (fun (i : {a : ι // a ∉ s}) ↦ M₁ i) (MultilinearMap R (fun (_ : α) ↦ (∀ i, M₁ i)) M₂) where toFun := fun z ↦ { toFun := fun v ↦ domDomRestrictₗ f (fun i ↦ i ∈ s) z (fun i ↦ v (e.symm i) i) map_update_add' := by classical simp [iteratedFDeriv_aux] map_update_smul' := by classical simp [iteratedFDeriv_aux] } map_update_add' := by intros; ext; simp map_update_smul' := by intros; ext; simp open Classical in /-- The `k`-th iterated derivative of a multilinear map `f` at the point `x`. It is a multilinear map of `k` vectors `v₁, ..., vₖ` (with the same type as `x`), mapping them to `∑ f (x₁, (v_{i₁})₂, x₃, ...)`, where at each index `j` one uses either `xⱼ` or one of the `(vᵢ)ⱼ`, and each `vᵢ` has to be used exactly once. The sum is parameterized by the embeddings of `Fin k` in the index type `ι` (or, equivalently, by the subsets `s` of `ι` of cardinality `k` and then the bijections between `Fin k` and `s`). For the continuous version, see `ContinuousMultilinearMap.iteratedFDeriv`. -/ protected noncomputable def iteratedFDeriv [Fintype ι] (f : MultilinearMap R M₁ M₂) (k : ℕ) (x : (i : ι) → M₁ i) : MultilinearMap R (fun (_ : Fin k) ↦ (∀ i, M₁ i)) M₂ := ∑ e : Fin k ↪ ι, iteratedFDerivComponent f e.toEquivRange (fun i ↦ x i) /-- If `f` is a collection of linear maps, then the construction `MultilinearMap.compLinearMap` sending a multilinear map `g` to `g (f₁ ⬝ , ..., fₙ ⬝ )` is linear in `g`. -/ @[simps] def compLinearMapₗ (f : Π (i : ι), M₁ i →ₗ[R] M₁' i) : (MultilinearMap R M₁' M₂) →ₗ[R] MultilinearMap R M₁ M₂ where toFun := fun g ↦ g.compLinearMap f map_add' := fun _ _ ↦ rfl map_smul' := fun _ _ ↦ rfl /-- An isomorphism of multilinear maps given an isomorphism between their domains. This is `MultilinearMap.compLinearMap` as a linear equivalence, and the multilinear version of `LinearEquiv.congrLeft`. -/ @[simps! apply symm_apply] def _root_.LinearEquiv.multilinearMapCongrLeft (e : Π (i : ι), M₁ i ≃ₗ[R] M₁' i) : (MultilinearMap R M₁' M₂) ≃ₗ[R] MultilinearMap R M₁ M₂ where __ := compLinearMapₗ (e · |>.toLinearMap) invFun := compLinearMapₗ (e · |>.symm.toLinearMap) left_inv _ := by ext; simp right_inv _ := by ext; simp /-- If `f` is a collection of linear maps, then the construction `MultilinearMap.compLinearMap` sending a multilinear map `g` to `g (f₁ ⬝ , ..., fₙ ⬝ )` is linear in `g` and multilinear in `f₁, ..., fₙ`. -/ @[simps] def compLinearMapMultilinear : @MultilinearMap R ι (fun i ↦ M₁ i →ₗ[R] M₁' i) ((MultilinearMap R M₁' M₂) →ₗ[R] MultilinearMap R M₁ M₂) _ _ _ (fun _ ↦ LinearMap.module) _ where toFun := MultilinearMap.compLinearMapₗ map_update_add' := by intro _ f i f₁ f₂ ext g x change (g fun j ↦ update f i (f₁ + f₂) j <| x j) = (g fun j ↦ update f i f₁ j <|x j) + g fun j ↦ update f i f₂ j (x j) let c : Π (i : ι), (M₁ i →ₗ[R] M₁' i) → M₁' i := fun i f ↦ f (x i) convert g.map_update_add (fun j ↦ f j (x j)) i (f₁ (x i)) (f₂ (x i)) with j j j · exact Function.apply_update c f i (f₁ + f₂) j · exact Function.apply_update c f i f₁ j · exact Function.apply_update c f i f₂ j map_update_smul' := by intro _ f i a f₀ ext g x change (g fun j ↦ update f i (a • f₀) j <| x j) = a • g fun j ↦ update f i f₀ j (x j) let c : Π (i : ι), (M₁ i →ₗ[R] M₁' i) → M₁' i := fun i f ↦ f (x i) convert g.map_update_smul (fun j ↦ f j (x j)) i a (f₀ (x i)) with j j j · exact Function.apply_update c f i (a • f₀) j · exact Function.apply_update c f i f₀ j /-- Let `M₁ᵢ` and `M₁ᵢ'` be two families of `R`-modules and `M₂` an `R`-module. Let us denote `Π i, M₁ᵢ` and `Π i, M₁ᵢ'` by `M` and `M'` respectively. If `g` is a multilinear map `M' → M₂`, then `g` can be reinterpreted as a multilinear map from `Π i, M₁ᵢ ⟶ M₁ᵢ'` to `M ⟶ M₂` via `(fᵢ) ↦ v ↦ g(fᵢ vᵢ)`. -/ @[simps!] def piLinearMap : MultilinearMap R M₁' M₂ →ₗ[R] MultilinearMap R (fun i ↦ M₁ i →ₗ[R] M₁' i) (MultilinearMap R M₁ M₂) where toFun g := (LinearMap.applyₗ g).compMultilinearMap compLinearMapMultilinear map_add' := by simp map_smul' := by simp end /-- If one multiplies by `c i` the coordinates in a finset `s`, then the image under a multilinear map is multiplied by `∏ i ∈ s, c i`. This is mainly an auxiliary statement to prove the result when `s = univ`, given in `map_smul_univ`, although it can be useful in its own right as it does not require the index set `ι` to be finite. -/ theorem map_piecewise_smul [DecidableEq ι] (c : ι → R) (m : ∀ i, M₁ i) (s : Finset ι) : f (s.piecewise (fun i => c i • m i) m) = (∏ i ∈ s, c i) • f m := by refine s.induction_on (by simp) ?_ intro j s j_notMem_s Hrec have A : Function.update (s.piecewise (fun i => c i • m i) m) j (m j) = s.piecewise (fun i => c i • m i) m := by ext i by_cases h : i = j · rw [h] simp [j_notMem_s] · simp [h] rw [s.piecewise_insert, f.map_update_smul, A, Hrec] simp [j_notMem_s, mul_smul] /-- Multiplicativity of a multilinear map along all coordinates at the same time, writing `f (fun i => c i • m i)` as `(∏ i, c i) • f m`. -/ theorem map_smul_univ [Fintype ι] (c : ι → R) (m : ∀ i, M₁ i) : (f fun i => c i • m i) = (∏ i, c i) • f m := by classical simpa using map_piecewise_smul f c m Finset.univ @[simp] theorem map_update_smul_left [DecidableEq ι] [Fintype ι] (m : ∀ i, M₁ i) (i : ι) (c : R) (x : M₁ i) : f (update (c • m) i x) = c ^ (Fintype.card ι - 1) • f (update m i x) := by have : f ((Finset.univ.erase i).piecewise (c • update m i x) (update m i x)) = (∏ _i ∈ Finset.univ.erase i, c) • f (update m i x) := map_piecewise_smul f _ _ _ simpa [← Function.update_smul c m] using this /-- If two `R`-multilinear maps from `R` are equal on 1, then they are equal. This is the multilinear version of `LinearMap.ext_ring`. -/ @[ext] theorem ext_ring [Finite ι] ⦃f g : MultilinearMap R (fun _ : ι => R) M₂⦄ (h : f (fun _ ↦ 1) = g (fun _ ↦ 1)) : f = g := by ext x obtain ⟨_⟩ := nonempty_fintype ι have hf := f.map_smul_univ x (fun _ ↦ 1) have hg := g.map_smul_univ x (fun _ ↦ 1) simp_all section variable (R ι) variable (A : Type*) [CommSemiring A] [Algebra R A] [Fintype ι] /-- Given an `R`-algebra `A`, `mkPiAlgebra` is the multilinear map on `A^ι` associating to `m` the product of all the `m i`. See also `MultilinearMap.mkPiAlgebraFin` for a version that works with a non-commutative algebra `A` but requires `ι = Fin n`. -/ protected def mkPiAlgebra : MultilinearMap R (fun _ : ι => A) A where toFun m := ∏ i, m i map_update_add' m i x y := by simp [Finset.prod_update_of_mem, add_mul] map_update_smul' m i c x := by simp [Finset.prod_update_of_mem] variable {R A ι} @[simp] theorem mkPiAlgebra_apply (m : ι → A) : MultilinearMap.mkPiAlgebra R ι A m = ∏ i, m i := rfl end section variable (R n) variable (A : Type*) [Semiring A] [Algebra R A] /-- Given an `R`-algebra `A`, `mkPiAlgebraFin` is the multilinear map on `A^n` associating to `m` the product of all the `m i`. See also `MultilinearMap.mkPiAlgebra` for a version that assumes `[CommSemiring A]` but works for `A^ι` with any finite type `ι`. -/ protected def mkPiAlgebraFin : MultilinearMap R (fun _ : Fin n => A) A := MultilinearMap.mk' (fun m ↦ (List.ofFn m).prod) (fun m i x y ↦ by simp [List.ofFn_eq_map, (List.nodup_finRange n).map_update, List.prod_set, add_mul, mul_add, add_mul]) (fun m i c x ↦ by simp [List.ofFn_eq_map, (List.nodup_finRange n).map_update, List.prod_set]) variable {R A n} @[simp] theorem mkPiAlgebraFin_apply (m : Fin n → A) : MultilinearMap.mkPiAlgebraFin R n A m = (List.ofFn m).prod := rfl theorem mkPiAlgebraFin_apply_const (a : A) : (MultilinearMap.mkPiAlgebraFin R n A fun _ => a) = a ^ n := by simp end /-- Given an `R`-multilinear map `f` taking values in `R`, `f.smulRight z` is the map sending `m` to `f m • z`. -/ def smulRight (f : MultilinearMap R M₁ R) (z : M₂) : MultilinearMap R M₁ M₂ := (LinearMap.smulRight LinearMap.id z).compMultilinearMap f @[simp] theorem smulRight_apply (f : MultilinearMap R M₁ R) (z : M₂) (m : ∀ i, M₁ i) : f.smulRight z m = f m • z := rfl variable (R ι) /-- The canonical multilinear map on `R^ι` when `ι` is finite, associating to `m` the product of all the `m i` (multiplied by a fixed reference element `z` in the target module). See also `mkPiAlgebra` for a more general version. -/ protected def mkPiRing [Fintype ι] (z : M₂) : MultilinearMap R (fun _ : ι => R) M₂ := (MultilinearMap.mkPiAlgebra R ι R).smulRight z variable {R ι} @[simp] theorem mkPiRing_apply [Fintype ι] (z : M₂) (m : ι → R) : (MultilinearMap.mkPiRing R ι z : (ι → R) → M₂) m = (∏ i, m i) • z := rfl theorem mkPiRing_apply_one_eq_self [Fintype ι] (f : MultilinearMap R (fun _ : ι => R) M₂) : MultilinearMap.mkPiRing R ι (f fun _ => 1) = f := by ext simp theorem mkPiRing_eq_iff [Fintype ι] {z₁ z₂ : M₂} : MultilinearMap.mkPiRing R ι z₁ = MultilinearMap.mkPiRing R ι z₂ ↔ z₁ = z₂ := by simp_rw [MultilinearMap.ext_iff, mkPiRing_apply] constructor <;> intro h · simpa using h fun _ => 1 · simp [h] theorem mkPiRing_zero [Fintype ι] : MultilinearMap.mkPiRing R ι (0 : M₂) = 0 := by ext; rw [mkPiRing_apply, smul_zero, MultilinearMap.zero_apply] theorem mkPiRing_eq_zero_iff [Fintype ι] (z : M₂) : MultilinearMap.mkPiRing R ι z = 0 ↔ z = 0 := by rw [← mkPiRing_zero, mkPiRing_eq_iff] end CommSemiring section RangeAddCommGroup variable [Semiring R] [∀ i, AddCommMonoid (M₁ i)] [AddCommGroup M₂] [∀ i, Module R (M₁ i)] [Module R M₂] (f g : MultilinearMap R M₁ M₂) instance : Neg (MultilinearMap R M₁ M₂) := ⟨fun f => ⟨fun m => -f m, fun m i x y => by simp [add_comm], fun m i c x => by simp⟩⟩ @[simp] theorem neg_apply (m : ∀ i, M₁ i) : (-f) m = -f m := rfl instance : Sub (MultilinearMap R M₁ M₂) := ⟨fun f g => ⟨fun m => f m - g m, fun m i x y => by simp only [MultilinearMap.map_update_add, sub_eq_add_neg, neg_add] abel, fun m i c x => by simp only [MultilinearMap.map_update_smul, smul_sub]⟩⟩ @[simp] theorem sub_apply (m : ∀ i, M₁ i) : (f - g) m = f m - g m := rfl instance : AddCommGroup (MultilinearMap R M₁ M₂) := { MultilinearMap.addCommMonoid with neg_add_cancel := fun _ => MultilinearMap.ext fun _ => neg_add_cancel _ sub_eq_add_neg := fun _ _ => MultilinearMap.ext fun _ => sub_eq_add_neg _ _ zsmul := fun n f => { toFun := fun m => n • f m map_update_add' := fun m i x y => by simp [smul_add] map_update_smul' := fun l i x d => by simp [← smul_comm x n (_ : M₂)] } zsmul_zero' := fun _ => MultilinearMap.ext fun _ => SubNegMonoid.zsmul_zero' _ zsmul_succ' := fun _ _ => MultilinearMap.ext fun _ => SubNegMonoid.zsmul_succ' _ _ zsmul_neg' := fun _ _ => MultilinearMap.ext fun _ => SubNegMonoid.zsmul_neg' _ _ } end RangeAddCommGroup section AddCommGroup variable [Semiring R] [∀ i, AddCommGroup (M₁ i)] [AddCommGroup M₂] [∀ i, Module R (M₁ i)] [Module R M₂] (f : MultilinearMap R M₁ M₂) @[simp] theorem map_update_neg [DecidableEq ι] (m : ∀ i, M₁ i) (i : ι) (x : M₁ i) : f (update m i (-x)) = -f (update m i x) := eq_neg_of_add_eq_zero_left <| by rw [← MultilinearMap.map_update_add, neg_add_cancel, f.map_coord_zero i (update_self i 0 m)] @[simp] theorem map_update_sub [DecidableEq ι] (m : ∀ i, M₁ i) (i : ι) (x y : M₁ i) : f (update m i (x - y)) = f (update m i x) - f (update m i y) := by rw [sub_eq_add_neg, sub_eq_add_neg, MultilinearMap.map_update_add, map_update_neg] lemma map_update [DecidableEq ι] (x : (i : ι) → M₁ i) (i : ι) (v : M₁ i) : f (update x i v) = f x - f (update x i (x i - v)) := by rw [map_update_sub, update_eq_self, sub_sub_cancel] open Finset in lemma map_sub_map_piecewise [LinearOrder ι] (a b : (i : ι) → M₁ i) (s : Finset ι) : f a - f (s.piecewise b a) = ∑ i ∈ s, f (fun j ↦ if j ∈ s → j < i then a j else if i = j then a j - b j else b j) := by refine s.induction_on_min ?_ fun k s hk ih ↦ ?_ · rw [Finset.piecewise_empty, sum_empty, sub_self] rw [Finset.piecewise_insert, map_update, ← sub_add, ih, add_comm, sum_insert (lt_irrefl _ <| hk k ·)] simp_rw [s.mem_insert] congr 1 · congr; ext i; split_ifs with h₁ h₂ · rw [update_of_ne, Finset.piecewise_eq_of_notMem] · exact fun h ↦ (hk i h).not_gt (h₁ <| .inr h) · exact fun h ↦ (h₁ <| .inl h).ne h · cases h₂ rw [update_self, s.piecewise_eq_of_notMem _ _ (lt_irrefl _ <| hk k ·)] · push_neg at h₁ rw [update_of_ne (Ne.symm h₂), s.piecewise_eq_of_mem _ _ (h₁.1.resolve_left <| Ne.symm h₂)] · apply sum_congr rfl grind /-- This calculates the differences between the values of a multilinear map at two arguments that differ on a finset `s` of `ι`. It requires a linear order on `ι` in order to express the result. -/ lemma map_piecewise_sub_map_piecewise [LinearOrder ι] (a b v : (i : ι) → M₁ i) (s : Finset ι) : f (s.piecewise a v) - f (s.piecewise b v) = ∑ i ∈ s, f fun j ↦ if j ∈ s then if j < i then a j else if j = i then a j - b j else b j else v j := by rw [← s.piecewise_idem_right b a, map_sub_map_piecewise] refine Finset.sum_congr rfl fun i hi ↦ congr_arg f <| funext fun j ↦ ?_ by_cases hjs : j ∈ s · rw [if_pos hjs]; by_cases hji : j < i · rw [if_pos fun _ ↦ hji, if_pos hji, s.piecewise_eq_of_mem _ _ hjs] rw [if_neg (Classical.not_imp.mpr ⟨hjs, hji⟩), if_neg hji] obtain rfl | hij := eq_or_ne i j · rw [if_pos rfl, if_pos rfl, s.piecewise_eq_of_mem _ _ hi] · rw [if_neg hij, if_neg hij.symm] · rw [if_neg hjs, if_pos fun h ↦ (hjs h).elim, s.piecewise_eq_of_notMem _ _ hjs] open Finset in lemma map_add_eq_map_add_linearDeriv_add [DecidableEq ι] [Fintype ι] (x h : (i : ι) → M₁ i) : f (x + h) = f x + f.linearDeriv x h + ∑ s with 2 ≤ #s, f (s.piecewise h x) := by rw [add_comm, map_add_univ, ← Finset.powerset_univ, ← sum_filter_add_sum_filter_not _ (2 ≤ #·)] simp_rw [not_le, Nat.lt_succ, le_iff_lt_or_eq (b := 1), Nat.lt_one_iff, filter_or, ← powersetCard_eq_filter, sum_union (univ.pairwise_disjoint_powersetCard zero_ne_one), powersetCard_zero, powersetCard_one, sum_singleton, Finset.piecewise_empty, sum_map, Function.Embedding.coeFn_mk, Finset.piecewise_singleton, linearDeriv_apply, add_comm] open Finset in /-- This expresses the difference between the values of a multilinear map at two points "close to `x`" in terms of the "derivative" of the multilinear map at `x` and of "second-order" terms. -/ lemma map_add_sub_map_add_sub_linearDeriv [DecidableEq ι] [Fintype ι] (x h h' : (i : ι) → M₁ i) : f (x + h) - f (x + h') - f.linearDeriv x (h - h') = ∑ s with 2 ≤ #s, (f (s.piecewise h x) - f (s.piecewise h' x)) := by simp_rw [map_add_eq_map_add_linearDeriv_add, add_assoc, add_sub_add_comm, sub_self, zero_add, ← LinearMap.map_sub, add_sub_cancel_left, sum_sub_distrib] end AddCommGroup section CommSemiring variable [CommSemiring R] [∀ i, AddCommMonoid (M₁ i)] [AddCommMonoid M₂] [∀ i, Module R (M₁ i)] [Module R M₂] /-- When `ι` is finite, multilinear maps on `R^ι` with values in `M₂` are in bijection with `M₂`, as such a multilinear map is completely determined by its value on the constant vector made of ones. We register this bijection as a linear equivalence in `MultilinearMap.piRingEquiv`. -/ protected def piRingEquiv [Fintype ι] : M₂ ≃ₗ[R] MultilinearMap R (fun _ : ι => R) M₂ where toFun z := MultilinearMap.mkPiRing R ι z invFun f := f fun _ => 1 map_add' z z' := by ext simp map_smul' c z := by ext simp left_inv z := by simp right_inv f := f.mkPiRing_apply_one_eq_self end CommSemiring section Submodule variable [Ring R] [∀ i, AddCommMonoid (M₁ i)] [AddCommMonoid M'] [AddCommMonoid M₂] [∀ i, Module R (M₁ i)] [Module R M'] [Module R M₂] /-- The pushforward of an indexed collection of submodule `p i ⊆ M₁ i` by `f : M₁ → M₂`. Note that this is not a submodule - it is not closed under addition. -/ def map [Nonempty ι] (f : MultilinearMap R M₁ M₂) (p : ∀ i, Submodule R (M₁ i)) : SubMulAction R M₂ where carrier := f '' { v | ∀ i, v i ∈ p i } smul_mem' := fun c _ ⟨x, hx, hf⟩ => by let ⟨i⟩ := ‹Nonempty ι› letI := Classical.decEq ι refine ⟨update x i (c • x i), fun j => if hij : j = i then ?_ else ?_, hf ▸ ?_⟩ · rw [hij, update_self] exact (p i).smul_mem _ (hx i) · rw [update_of_ne hij] exact hx j · rw [f.map_update_smul, update_eq_self] /-- The map is always nonempty. This lemma is needed to apply `SubMulAction.zero_mem`. -/ theorem map_nonempty [Nonempty ι] (f : MultilinearMap R M₁ M₂) (p : ∀ i, Submodule R (M₁ i)) : (map f p : Set M₂).Nonempty := ⟨f 0, 0, fun i => (p i).zero_mem, rfl⟩ /-- The range of a multilinear map, closed under scalar multiplication. -/ def range [Nonempty ι] (f : MultilinearMap R M₁ M₂) : SubMulAction R M₂ := f.map fun _ => ⊤ end Submodule end MultilinearMap
.lake/packages/mathlib/Mathlib/LinearAlgebra/Multilinear/Basis.lean
import Mathlib.LinearAlgebra.Basis.Defs import Mathlib.LinearAlgebra.Multilinear.Basic /-! # Multilinear maps in relation to bases. This file proves lemmas about the action of multilinear maps on basis vectors. -/ open MultilinearMap variable {ι R : Type*} [CommSemiring R] {M : ι → Type*} [∀ i, AddCommMonoid (M i)] [∀ i, Module R (M i)] {N : Type*} [AddCommMonoid N] [Module R N] /-- Two multilinear maps indexed by a `Fintype` are equal if they are equal when all arguments are basis vectors. -/ theorem Module.Basis.ext_multilinear [Finite ι] {f g : MultilinearMap R M N} {ιM : ι → Type*} (e : ∀ i, Basis (ιM i) R (M i)) (h : ∀ v : (i : ι) → ιM i, (f fun i ↦ e i (v i)) = g fun i ↦ e i (v i)) : f = g := by cases nonempty_fintype ι classical ext m rcases Function.Surjective.piMap (fun i ↦ (e i).repr.symm.surjective) m with ⟨x, rfl⟩ unfold Pi.map simp_rw [(e _).repr_symm_apply, Finsupp.linearCombination_apply, Finsupp.sum, map_sum_finset, map_smul_univ, h] @[deprecated (since := "2025-05-12")] alias Basis.ext_multilinear_fin := Module.Basis.ext_multilinear
.lake/packages/mathlib/Mathlib/LinearAlgebra/Multilinear/DFinsupp.lean
import Mathlib.Data.Fintype.Quotient import Mathlib.LinearAlgebra.DFinsupp import Mathlib.LinearAlgebra.Multilinear.Basic /-! # Interactions between finitely-supported functions and multilinear maps ## Main definitions * `MultilinearMap.dfinsupp_ext` * `MultilinearMap.dfinsuppFamily`, which satisfies `dfinsuppFamily f x p = f p (fun i => x i (p i))`. This is the finitely-supported version of `MultilinearMap.piFamily`. This is useful because all the intermediate results are bundled: - `MultilinearMap.dfinsuppFamily f x` is a `DFinsupp` supported by families of indices `p`. - `MultilinearMap.dfinsuppFamily f` is a `MultilinearMap` operating on finitely-supported functions `x`. - `MultilinearMap.dfinsuppFamilyₗ` is a `LinearMap`, linear in the family of multilinear maps `f`. -/ universe uι uκ uS uR uM uN variable {ι : Type uι} {κ : ι → Type uκ} variable {S : Type uS} {R : Type uR} namespace MultilinearMap section Semiring variable {M : ∀ i, κ i → Type uM} {N : Type uN} variable [Finite ι] [Semiring R] variable [∀ i k, AddCommMonoid (M i k)] [AddCommMonoid N] variable [∀ i k, Module R (M i k)] [Module R N] /-- Two multilinear maps from finitely supported functions are equal if they agree on the generators. This is a multilinear version of `DFinsupp.lhom_ext'`. -/ @[ext] theorem dfinsupp_ext [∀ i, DecidableEq (κ i)] ⦃f g : MultilinearMap R (fun i ↦ Π₀ j : κ i, M i j) N⦄ (h : ∀ p : Π i, κ i, f.compLinearMap (fun i => DFinsupp.lsingle (p i)) = g.compLinearMap (fun i => DFinsupp.lsingle (p i))) : f = g := by ext x change f (fun i ↦ x i) = g (fun i ↦ x i) classical cases nonempty_fintype ι rw [funext (fun i ↦ Eq.symm (DFinsupp.sum_single (f := x i)))] simp_rw [DFinsupp.sum, MultilinearMap.map_sum_finset] congr! 1 with p simp_rw [MultilinearMap.ext_iff] at h exact h _ _ end Semiring section dfinsuppFamily variable {M : ∀ i, κ i → Type uM} {N : (Π i, κ i) → Type uN} section Semiring variable [DecidableEq ι] [Fintype ι] [Semiring R] variable [∀ i k, AddCommMonoid (M i k)] [∀ p, AddCommMonoid (N p)] variable [∀ i k, Module R (M i k)] [∀ p, Module R (N p)] /-- Given a family of indices `κ` and a multilinear map `f p` for each way `p` to select one index from each family, `dfinsuppFamily f` maps a family of finitely-supported functions (one for each domain `κ i`) into a finitely-supported function from each selection of indices (with domain `Π i, κ i`). Strictly this doesn't need multilinearity, only the fact that `f p m = 0` whenever `m i = 0` for some `i`. This is the `DFinsupp` version of `MultilinearMap.piFamily`. -/ @[simps] def dfinsuppFamily (f : Π (p : Π i, κ i), MultilinearMap R (fun i ↦ M i (p i)) (N p)) : MultilinearMap R (fun i => Π₀ j : κ i, M i j) (Π₀ t : Π i, κ i, N t) where toFun x := { toFun := fun p => f p (fun i => x i (p i)) support' := (Trunc.finChoice fun i => (x i).support').map fun s => ⟨ Finset.univ.val.pi (fun i ↦ (s i).val) |>.map fun f i => f i (Finset.mem_univ _), fun p => by simp only [Multiset.mem_map, Multiset.mem_pi, Finset.mem_val, Finset.mem_univ, forall_true_left] simp_rw [or_iff_not_imp_right] intro h push_neg at h refine ⟨fun i _ => p i, fun i => (s i).prop _ |>.resolve_right ?_, rfl⟩ exact mt ((f p).map_coord_zero (m := fun i => x i _) i) h⟩} map_update_add' {dec} m i x y := DFinsupp.ext fun p => by dsimp simp_rw [Function.apply_update (fun i m => m (p i)) m, DFinsupp.add_apply, (f p).map_update_add] map_update_smul' {dec} m i c x := DFinsupp.ext fun p => by dsimp simp_rw [Function.apply_update (fun i m => m (p i)) m, DFinsupp.smul_apply, (f p).map_update_smul] theorem support_dfinsuppFamily_subset [∀ i, DecidableEq (κ i)] [∀ i j, (x : M i j) → Decidable (x ≠ 0)] [∀ i, (x : N i) → Decidable (x ≠ 0)] (f : Π (p : Π i, κ i), MultilinearMap R (fun i ↦ M i (p i)) (N p)) (x : ∀ i, Π₀ j : κ i, M i j) : (dfinsuppFamily f x).support ⊆ Fintype.piFinset fun i => (x i).support := by intro p hp simp only [DFinsupp.mem_support_toFun, dfinsuppFamily_apply_toFun, ne_eq, Fintype.mem_piFinset] at hp ⊢ intro i exact mt ((f p).map_coord_zero (m := fun i => x i _) i) hp /-- When applied to a family of finitely-supported functions each supported on a single element, `dfinsuppFamily` is itself supported on a single element, with value equal to the map `f` applied at that point. -/ @[simp] theorem dfinsuppFamily_single [∀ i, DecidableEq (κ i)] (f : Π (p : Π i, κ i), MultilinearMap R (fun i ↦ M i (p i)) (N p)) (p : ∀ i, κ i) (m : ∀ i, M i (p i)) : dfinsuppFamily f (fun i => .single (p i) (m i)) = DFinsupp.single p (f p m) := by ext q obtain rfl | hpq := eq_or_ne q p · simp · rw [DFinsupp.single_eq_of_ne hpq] rw [Function.ne_iff] at hpq obtain ⟨i, hpqi⟩ := hpq apply (f q).map_coord_zero i simp_rw [DFinsupp.single_eq_of_ne hpqi] /-- When only one member of the family of multilinear maps is nonzero, the result consists only of the component from that member. -/ @[simp] theorem dfinsuppFamily_single_left_apply [∀ i, DecidableEq (κ i)] (p : Π i, κ i) (f : MultilinearMap R (fun i ↦ M i (p i)) (N p)) (x : Π i, Π₀ j, M i j) : dfinsuppFamily (Pi.single p f) x = DFinsupp.single p (f fun i => x _ (p i)) := by ext p' obtain rfl | hp := eq_or_ne p p' · simp · simp [hp] theorem dfinsuppFamily_single_left [∀ i, DecidableEq (κ i)] (p : Π i, κ i) (f : MultilinearMap R (fun i ↦ M i (p i)) (N p)) : dfinsuppFamily (Pi.single p f) = (DFinsupp.lsingle p).compMultilinearMap (f.compLinearMap fun i => DFinsupp.lapply (p i)) := ext <| dfinsuppFamily_single_left_apply _ _ @[simp] theorem dfinsuppFamily_compLinearMap_lsingle [∀ i, DecidableEq (κ i)] (f : Π (p : Π i, κ i), MultilinearMap R (fun i ↦ M i (p i)) (N p)) (p : ∀ i, κ i) : (dfinsuppFamily f).compLinearMap (fun i => DFinsupp.lsingle (p i)) = (DFinsupp.lsingle p).compMultilinearMap (f p) := MultilinearMap.ext <| dfinsuppFamily_single f p @[simp] theorem dfinsuppFamily_zero : dfinsuppFamily (0 : Π (p : Π i, κ i), MultilinearMap R (fun i ↦ M i (p i)) (N p)) = 0 := by ext; simp @[simp] theorem dfinsuppFamily_add (f g : Π (p : Π i, κ i), MultilinearMap R (fun i ↦ M i (p i)) (N p)) : dfinsuppFamily (f + g) = dfinsuppFamily f + dfinsuppFamily g := by ext; simp @[simp] theorem dfinsuppFamily_smul [Monoid S] [∀ p, DistribMulAction S (N p)] [∀ p, SMulCommClass R S (N p)] (s : S) (f : Π (p : Π i, κ i), MultilinearMap R (fun i ↦ M i (p i)) (N p)) : dfinsuppFamily (s • f) = s • dfinsuppFamily f := by ext; simp end Semiring section CommSemiring variable [DecidableEq ι] [Fintype ι] [CommSemiring R] variable [∀ i k, AddCommMonoid (M i k)] [∀ p, AddCommMonoid (N p)] variable [∀ i k, Module R (M i k)] [∀ p, Module R (N p)] /-- `MultilinearMap.dfinsuppFamily` as a linear map. -/ @[simps] def dfinsuppFamilyₗ : (Π (p : Π i, κ i), MultilinearMap R (fun i ↦ M i (p i)) (N p)) →ₗ[R] MultilinearMap R (fun i => Π₀ j : κ i, M i j) (Π₀ t : Π i, κ i, N t) where toFun := dfinsuppFamily map_add' := dfinsuppFamily_add map_smul' := dfinsuppFamily_smul end CommSemiring end dfinsuppFamily end MultilinearMap
.lake/packages/mathlib/Mathlib/LinearAlgebra/Multilinear/FiniteDimensional.lean
import Mathlib.LinearAlgebra.Multilinear.Curry import Mathlib.LinearAlgebra.FreeModule.Finite.Matrix /-! # Multilinear maps over finite-dimensional spaces The main results are that multilinear maps over finitely-generated, free modules are finitely-generated and free. * `Module.Finite.multilinearMap` * `Module.Free.multilinearMap` We do not put this in `LinearAlgebra.Multilinear.Basic` to avoid making the imports too large there. -/ namespace MultilinearMap variable {ι R M₂ : Type*} {M₁ : ι → Type*} variable [Finite ι] variable [CommRing R] [AddCommGroup M₂] [Module R M₂] variable [Module.Finite R M₂] [Module.Free R M₂] private theorem free_and_finite_fin (n : ℕ) (N : Fin n → Type*) [∀ i, AddCommGroup (N i)] [∀ i, Module R (N i)] [∀ i, Module.Finite R (N i)] [∀ i, Module.Free R (N i)] : Module.Free R (MultilinearMap R N M₂) ∧ Module.Finite R (MultilinearMap R N M₂) := by induction n with | zero => haveI : IsEmpty (Fin Nat.zero) := inferInstanceAs (IsEmpty (Fin 0)) exact ⟨Module.Free.of_equiv (constLinearEquivOfIsEmpty R R N M₂), Module.Finite.equiv (constLinearEquivOfIsEmpty R R N M₂)⟩ | succ n ih => suffices Module.Free R (N 0 →ₗ[R] MultilinearMap R (fun i : Fin n => N i.succ) M₂) ∧ Module.Finite R (N 0 →ₗ[R] MultilinearMap R (fun i : Fin n => N i.succ) M₂) by cases this exact ⟨Module.Free.of_equiv (multilinearCurryLeftEquiv R N M₂).symm, Module.Finite.equiv (multilinearCurryLeftEquiv R N M₂).symm⟩ cases ih fun i => N i.succ exact ⟨Module.Free.linearMap _ _ _ _, Module.Finite.linearMap _ _ _ _⟩ variable [∀ i, AddCommGroup (M₁ i)] [∀ i, Module R (M₁ i)] variable [∀ i, Module.Finite R (M₁ i)] [∀ i, Module.Free R (M₁ i)] -- the induction requires us to show both at once private theorem free_and_finite : Module.Free R (MultilinearMap R M₁ M₂) ∧ Module.Finite R (MultilinearMap R M₁ M₂) := by cases nonempty_fintype ι have := @free_and_finite_fin R M₂ _ _ _ _ _ (Fintype.card ι) (fun x => M₁ ((Fintype.equivFin ι).symm x)) obtain ⟨l, r⟩ := this have e := domDomCongrLinearEquiv' R R M₁ M₂ (Fintype.equivFin ι) exact ⟨Module.Free.of_equiv e.symm, Module.Finite.equiv e.symm⟩ instance _root_.Module.Finite.multilinearMap : Module.Finite R (MultilinearMap R M₁ M₂) := free_and_finite.2 instance _root_.Module.Free.multilinearMap : Module.Free R (MultilinearMap R M₁ M₂) := free_and_finite.1 end MultilinearMap
.lake/packages/mathlib/Mathlib/LinearAlgebra/Complex/Module.lean
import Mathlib.Algebra.Algebra.RestrictScalars import Mathlib.Algebra.CharP.Invertible import Mathlib.Data.Complex.Basic import Mathlib.Data.Real.Star import Mathlib.LinearAlgebra.Matrix.ToLin /-! # Complex number as a vector space over `ℝ` This file contains the following instances: * Any `•`-structure (`SMul`, `MulAction`, `DistribMulAction`, `Module`, `Algebra`) on `ℝ` imbues a corresponding structure on `ℂ`. This includes the statement that `ℂ` is an `ℝ` algebra. * any complex vector space is a real vector space; * any finite-dimensional complex vector space is a finite-dimensional real vector space; * the space of `ℝ`-linear maps from a real vector space to a complex vector space is a complex vector space. It also defines bundled versions of four standard maps (respectively, the real part, the imaginary part, the embedding of `ℝ` in `ℂ`, and the complex conjugate): * `Complex.reLm` (`ℝ`-linear map); * `Complex.imLm` (`ℝ`-linear map); * `Complex.ofRealAm` (`ℝ`-algebra (homo)morphism); * `Complex.conjAe` (`ℝ`-algebra equivalence). It also provides a universal property of the complex numbers `Complex.lift`, which constructs a `ℂ →ₐ[ℝ] A` into any `ℝ`-algebra `A` given a square root of `-1`. In addition, this file provides a decomposition into `realPart` and `imaginaryPart` for any element of a `StarModule` over `ℂ`. ## Notation * `ℜ` and `ℑ` for the `realPart` and `imaginaryPart`, respectively, in the locale `ComplexStarModule`. -/ assert_not_exists NNReal namespace Complex open ComplexConjugate open scoped SMul variable {R : Type*} {S : Type*} attribute [local ext] Complex.ext /- The priority of the following instances has been manually lowered, as when they don't apply they lead Lean to a very costly path, and most often they don't apply (most actions on `ℂ` don't come from actions on `ℝ`). See https://github.com/leanprover-community/mathlib4/pull/11980 -/ -- priority manually adjusted in https://github.com/leanprover-community/mathlib4/pull/11980 instance (priority := 90) [SMul R ℝ] [SMul S ℝ] [SMulCommClass R S ℝ] : SMulCommClass R S ℂ where smul_comm r s x := by ext <;> simp [smul_re, smul_im, smul_comm] -- priority manually adjusted in https://github.com/leanprover-community/mathlib4/pull/11980 instance (priority := 90) [SMul R S] [SMul R ℝ] [SMul S ℝ] [IsScalarTower R S ℝ] : IsScalarTower R S ℂ where smul_assoc r s x := by ext <;> simp [smul_re, smul_im, smul_assoc] -- priority manually adjusted in https://github.com/leanprover-community/mathlib4/pull/11980 instance (priority := 90) [SMul R ℝ] [SMul Rᵐᵒᵖ ℝ] [IsCentralScalar R ℝ] : IsCentralScalar R ℂ where op_smul_eq_smul r x := by ext <;> simp [smul_re, smul_im, op_smul_eq_smul] -- priority manually adjusted in https://github.com/leanprover-community/mathlib4/pull/11980 instance (priority := 90) mulAction [Monoid R] [MulAction R ℝ] : MulAction R ℂ where one_smul x := by ext <;> simp [smul_re, smul_im, one_smul] mul_smul r s x := by ext <;> simp [smul_re, smul_im, mul_smul] -- priority manually adjusted in https://github.com/leanprover-community/mathlib4/pull/11980 instance (priority := 90) distribSMul [DistribSMul R ℝ] : DistribSMul R ℂ where smul_add r x y := by ext <;> simp [smul_re, smul_im, smul_add] smul_zero r := by ext <;> simp [smul_re, smul_im, smul_zero] -- priority manually adjusted in https://github.com/leanprover-community/mathlib4/pull/11980 instance (priority := 90) [Semiring R] [DistribMulAction R ℝ] : DistribMulAction R ℂ := { Complex.distribSMul, Complex.mulAction with } -- priority manually adjusted in https://github.com/leanprover-community/mathlib4/pull/11980 instance (priority := 100) instModule [Semiring R] [Module R ℝ] : Module R ℂ where add_smul r s x := by ext <;> simp [smul_re, smul_im, add_smul] zero_smul r := by ext <;> simp [smul_re, smul_im, zero_smul] -- priority manually adjusted in https://github.com/leanprover-community/mathlib4/pull/11980 instance (priority := 95) instAlgebraOfReal [CommSemiring R] [Algebra R ℝ] : Algebra R ℂ where algebraMap := Complex.ofRealHom.comp (algebraMap R ℝ) smul_def' := fun r x => by ext <;> simp [smul_re, smul_im, Algebra.smul_def] commutes' := fun r ⟨xr, xi⟩ => by ext <;> simp [Algebra.commutes] instance : StarModule ℝ ℂ := ⟨fun r x => by simp only [star_def, star_trivial, real_smul, map_mul, conj_ofReal]⟩ @[simp] theorem coe_algebraMap : (algebraMap ℝ ℂ : ℝ → ℂ) = ((↑) : ℝ → ℂ) := rfl section variable {A : Type*} [Semiring A] [Algebra ℝ A] /-- We need this lemma since `Complex.coe_algebraMap` diverts the simp-normal form away from `AlgHom.commutes`. -/ @[simp] theorem _root_.AlgHom.map_coe_real_complex (f : ℂ →ₐ[ℝ] A) (x : ℝ) : f x = algebraMap ℝ A x := f.commutes x /-- Two `ℝ`-algebra homomorphisms from `ℂ` are equal if they agree on `Complex.I`. -/ @[ext] theorem algHom_ext ⦃f g : ℂ →ₐ[ℝ] A⦄ (h : f I = g I) : f = g := by ext ⟨x, y⟩ simp only [mk_eq_add_mul_I, map_add, AlgHom.map_coe_real_complex, map_mul, h] end open Module Submodule /-- `ℂ` has a basis over `ℝ` given by `1` and `I`. -/ noncomputable def basisOneI : Basis (Fin 2) ℝ ℂ := .ofEquivFun { toFun := fun z => ![z.re, z.im] invFun := fun c => c 0 + c 1 • I left_inv := fun z => by simp right_inv := fun c => by ext i fin_cases i <;> simp map_add' := fun z z' => by simp map_smul' := fun c z => by simp } @[simp] theorem coe_basisOneI_repr (z : ℂ) : ⇑(basisOneI.repr z) = ![z.re, z.im] := rfl @[simp] theorem coe_basisOneI : ⇑basisOneI = ![1, I] := funext fun i => Basis.apply_eq_iff.mpr <| Finsupp.ext fun j => by fin_cases i <;> fin_cases j <;> simp end Complex /- Register as an instance (with low priority) the fact that a complex vector space is also a real vector space. -/ instance (priority := 900) Module.complexToReal (E : Type*) [AddCommGroup E] [Module ℂ E] : Module ℝ E := RestrictScalars.module ℝ ℂ E /- Register as an instance (with low priority) the fact that a complex algebra is also a real algebra. -/ instance (priority := 900) Algebra.complexToReal {A : Type*} [Semiring A] [Algebra ℂ A] : Algebra ℝ A := RestrictScalars.algebra ℝ ℂ A -- try to make sure we're not introducing diamonds but we will need -- `reducible_and_instances` which currently fails https://github.com/leanprover-community/mathlib4/issues/10906 example : Prod.algebra ℝ ℂ ℂ = (Prod.algebra ℂ ℂ ℂ).complexToReal := rfl -- try to make sure we're not introducing diamonds but we will need -- `reducible_and_instances` which currently fails https://github.com/leanprover-community/mathlib4/issues/10906 example {ι : Type*} [Fintype ι] : Pi.algebra (R := ℝ) ι (fun _ ↦ ℂ) = (Pi.algebra (R := ℂ) ι (fun _ ↦ ℂ)).complexToReal := rfl example {A : Type*} [Ring A] [inst : Algebra ℂ A] : (inst.complexToReal).toModule = (inst.toModule).complexToReal := by with_reducible_and_instances rfl @[simp, norm_cast] theorem Complex.coe_smul {E : Type*} [AddCommGroup E] [Module ℂ E] (x : ℝ) (y : E) : (x : ℂ) • y = x • y := rfl /-- The scalar action of `ℝ` on a `ℂ`-module `E` induced by `Module.complexToReal` commutes with another scalar action of `M` on `E` whenever the action of `ℂ` commutes with the action of `M`. -/ instance (priority := 900) SMulCommClass.complexToReal {M E : Type*} [AddCommGroup E] [Module ℂ E] [SMul M E] [SMulCommClass ℂ M E] : SMulCommClass ℝ M E where smul_comm r _ _ := smul_comm (r : ℂ) _ _ /-- The scalar action of `ℝ` on a `ℂ`-module `E` induced by `Module.complexToReal` associates with another scalar action of `M` on `E` whenever the action of `ℂ` associates with the action of `M`. -/ instance IsScalarTower.complexToReal {M E : Type*} [AddCommGroup M] [Module ℂ M] [AddCommGroup E] [Module ℂ E] [SMul M E] [IsScalarTower ℂ M E] : IsScalarTower ℝ M E where smul_assoc r _ _ := smul_assoc (r : ℂ) _ _ -- check that the following instance is implied by the one above. example (E : Type*) [AddCommGroup E] [Module ℂ E] : IsScalarTower ℝ ℂ E := inferInstance instance (priority := 900) StarModule.complexToReal {E : Type*} [AddCommGroup E] [Star E] [Module ℂ E] [StarModule ℂ E] : StarModule ℝ E := ⟨fun r a => by rw [← smul_one_smul ℂ r a, star_smul, star_smul, star_one, smul_one_smul]⟩ namespace Complex open ComplexConjugate /-- Linear map version of the real part function, from `ℂ` to `ℝ`. -/ def reLm : ℂ →ₗ[ℝ] ℝ where toFun x := x.re map_add' := add_re map_smul' := by simp @[simp] theorem reLm_coe : ⇑reLm = re := rfl /-- Linear map version of the imaginary part function, from `ℂ` to `ℝ`. -/ def imLm : ℂ →ₗ[ℝ] ℝ where toFun x := x.im map_add' := add_im map_smul' := by simp @[simp] theorem imLm_coe : ⇑imLm = im := rfl /-- `ℝ`-algebra morphism version of the canonical embedding of `ℝ` in `ℂ`. -/ def ofRealAm : ℝ →ₐ[ℝ] ℂ := Algebra.ofId ℝ ℂ @[simp] theorem ofRealAm_coe : ⇑ofRealAm = ((↑) : ℝ → ℂ) := rfl /-- `ℝ`-algebra isomorphism version of the complex conjugation function from `ℂ` to `ℂ` -/ def conjAe : ℂ ≃ₐ[ℝ] ℂ := { conj with invFun := conj left_inv := star_star right_inv := star_star commutes' := conj_ofReal } @[simp] theorem conjAe_coe : ⇑conjAe = conj := rfl /-- The matrix representation of `conjAe`. -/ @[simp] theorem toMatrix_conjAe : LinearMap.toMatrix basisOneI basisOneI conjAe.toLinearMap = !![1, 0; 0, -1] := by ext i j fin_cases i <;> fin_cases j <;> simp [LinearMap.toMatrix_apply] /-- The identity and the complex conjugation are the only two `ℝ`-algebra homomorphisms of `ℂ`. -/ theorem real_algHom_eq_id_or_conj (f : ℂ →ₐ[ℝ] ℂ) : f = AlgHom.id ℝ ℂ ∨ f = conjAe := by refine (eq_or_eq_neg_of_sq_eq_sq (f I) I <| by rw [← map_pow, I_sq, map_neg, map_one]).imp ?_ ?_ <;> refine fun h => algHom_ext ?_ exacts [h, conj_I.symm ▸ h] /-- The natural `LinearEquiv` from `ℂ` to `ℝ × ℝ`. -/ @[simps! +simpRhs apply symm_apply_re symm_apply_im] def equivRealProdLm : ℂ ≃ₗ[ℝ] ℝ × ℝ := { equivRealProdAddHom with map_smul' := fun r c => by simp } theorem equivRealProdLm_symm_apply (p : ℝ × ℝ) : Complex.equivRealProdLm.symm p = p.1 + p.2 * Complex.I := Complex.equivRealProd_symm_apply p section lift variable {A : Type*} [Ring A] [Algebra ℝ A] /-- There is an alg_hom from `ℂ` to any `ℝ`-algebra with an element that squares to `-1`. See `Complex.lift` for this as an equiv. -/ def liftAux (I' : A) (hf : I' * I' = -1) : ℂ →ₐ[ℝ] A := AlgHom.ofLinearMap ((Algebra.linearMap ℝ A).comp reLm + (LinearMap.toSpanSingleton _ _ I').comp imLm) (show algebraMap ℝ A 1 + (0 : ℝ) • I' = 1 by rw [RingHom.map_one, zero_smul, add_zero]) fun ⟨x₁, y₁⟩ ⟨x₂, y₂⟩ => show algebraMap ℝ A (x₁ * x₂ - y₁ * y₂) + (x₁ * y₂ + y₁ * x₂) • I' = (algebraMap ℝ A x₁ + y₁ • I') * (algebraMap ℝ A x₂ + y₂ • I') by rw [add_mul, mul_add, mul_add, add_comm _ (y₁ • I' * y₂ • I'), add_add_add_comm] congr 1 -- equate "real" and "imaginary" parts · rw [smul_mul_smul_comm, hf, smul_neg, ← Algebra.algebraMap_eq_smul_one, ← sub_eq_add_neg, ← RingHom.map_mul, ← RingHom.map_sub] · rw [Algebra.smul_def, Algebra.smul_def, Algebra.smul_def, ← Algebra.right_comm _ x₂, ← mul_assoc, ← add_mul, ← RingHom.map_mul, ← RingHom.map_mul, ← RingHom.map_add] @[simp] theorem liftAux_apply (I' : A) (hI') (z : ℂ) : liftAux I' hI' z = algebraMap ℝ A z.re + z.im • I' := rfl theorem liftAux_apply_I (I' : A) (hI') : liftAux I' hI' I = I' := by simp @[simp] theorem adjoin_I : Algebra.adjoin ℝ {I} = ⊤ := by refine top_unique fun x hx => ?_; clear hx rw [← x.re_add_im, ← smul_eq_mul, ← Complex.coe_algebraMap] exact add_mem (algebraMap_mem _ _) (Subalgebra.smul_mem _ (Algebra.subset_adjoin <| by simp) _) @[simp] theorem range_liftAux (I' : A) (hI') : (liftAux I' hI').range = Algebra.adjoin ℝ {I'} := by simp_rw [← Algebra.map_top, ← adjoin_I, AlgHom.map_adjoin, Set.image_singleton, liftAux_apply_I] /-- A universal property of the complex numbers, providing a unique `ℂ →ₐ[ℝ] A` for every element of `A` which squares to `-1`. This can be used to embed the complex numbers in the `Quaternion`s. This isomorphism is named to match the very similar `Zsqrtd.lift`. -/ @[simps +simpRhs] def lift : { I' : A // I' * I' = -1 } ≃ (ℂ →ₐ[ℝ] A) where toFun I' := liftAux I' I'.prop invFun F := ⟨F I, by rw [← map_mul, I_mul_I, map_neg, map_one]⟩ left_inv I' := Subtype.ext <| liftAux_apply_I (I' : A) I'.prop right_inv _ := algHom_ext <| liftAux_apply_I _ _ -- When applied to `Complex.I` itself, `lift` is the identity. @[simp] theorem liftAux_I : liftAux I I_mul_I = AlgHom.id ℝ ℂ := algHom_ext <| liftAux_apply_I _ _ -- When applied to `-Complex.I`, `lift` is conjugation, `conj`. @[simp] theorem liftAux_neg_I : liftAux (-I) ((neg_mul_neg _ _).trans I_mul_I) = conjAe := algHom_ext <| (liftAux_apply_I _ _).trans conj_I.symm end lift end Complex section RealImaginaryPart open Complex variable {A : Type*} [AddCommGroup A] [Module ℂ A] [StarAddMonoid A] [StarModule ℂ A] /-- Create a `selfAdjoint` element from a `skewAdjoint` element by multiplying by the scalar `-Complex.I`. -/ @[simps] def skewAdjoint.negISMul : skewAdjoint A →ₗ[ℝ] selfAdjoint A where toFun a := ⟨-I • ↑a, by simp only [neg_smul, neg_mem_iff, selfAdjoint.mem_iff, star_smul, star_def, conj_I, star_val_eq, smul_neg, neg_neg]⟩ map_add' a b := by ext simp only [AddSubgroup.coe_add, smul_add, AddMemClass.mk_add_mk] map_smul' a b := by ext simp only [neg_smul, skewAdjoint.val_smul, RingHom.id_apply, selfAdjoint.val_smul, smul_neg, neg_inj] rw [smul_comm] theorem skewAdjoint.I_smul_neg_I (a : skewAdjoint A) : I • (skewAdjoint.negISMul a : A) = a := by simp only [smul_smul, skewAdjoint.negISMul_apply_coe, neg_smul, smul_neg, I_mul_I, one_smul, neg_neg] /-- The real part `ℜ a` of an element `a` of a star module over `ℂ`, as a linear map. This is just `selfAdjointPart ℝ`, but we provide it as a separate definition in order to link it with lemmas concerning the `imaginaryPart`, which doesn't exist in star modules over other rings. -/ noncomputable def realPart : A →ₗ[ℝ] selfAdjoint A := selfAdjointPart ℝ /-- The imaginary part `ℑ a` of an element `a` of a star module over `ℂ`, as a linear map into the self adjoint elements. In a general star module, we have a decomposition into the `selfAdjoint` and `skewAdjoint` parts, but in a star module over `ℂ` we have `realPart_add_I_smul_imaginaryPart`, which allows us to decompose into a linear combination of `selfAdjoint`s. -/ noncomputable def imaginaryPart : A →ₗ[ℝ] selfAdjoint A := skewAdjoint.negISMul.comp (skewAdjointPart ℝ) @[inherit_doc] scoped[ComplexStarModule] notation "ℜ" => realPart @[inherit_doc] scoped[ComplexStarModule] notation "ℑ" => imaginaryPart open ComplexStarModule theorem realPart_apply_coe (a : A) : (ℜ a : A) = (2 : ℝ)⁻¹ • (a + star a) := by unfold realPart simp only [selfAdjointPart_apply_coe, invOf_eq_inv] theorem imaginaryPart_apply_coe (a : A) : (ℑ a : A) = -I • (2 : ℝ)⁻¹ • (a - star a) := by unfold imaginaryPart simp only [LinearMap.coe_comp, Function.comp_apply, skewAdjoint.negISMul_apply_coe, skewAdjointPart_apply_coe, invOf_eq_inv, neg_smul] /-- The standard decomposition of `ℜ a + Complex.I • ℑ a = a` of an element of a star module over `ℂ` into a linear combination of self adjoint elements. -/ theorem realPart_add_I_smul_imaginaryPart (a : A) : (ℜ a : A) + I • (ℑ a : A) = a := by simpa only [smul_smul, realPart_apply_coe, imaginaryPart_apply_coe, neg_smul, I_mul_I, one_smul, neg_sub, add_add_sub_cancel, smul_sub, smul_add, neg_sub_neg, invOf_eq_inv] using invOf_two_smul_add_invOf_two_smul ℝ a @[simp] theorem realPart_I_smul (a : A) : ℜ (I • a) = -ℑ a := by ext simp [realPart_apply_coe, imaginaryPart_apply_coe, smul_comm I, sub_eq_add_neg, add_comm] @[simp] theorem imaginaryPart_I_smul (a : A) : ℑ (I • a) = ℜ a := by ext simp [realPart_apply_coe, imaginaryPart_apply_coe, smul_comm I (2⁻¹ : ℝ), smul_smul I] theorem realPart_smul (z : ℂ) (a : A) : ℜ (z • a) = z.re • ℜ a - z.im • ℑ a := by have := by congrm (ℜ ($((re_add_im z).symm) • a)) simpa [-re_add_im, add_smul, ← smul_smul, sub_eq_add_neg] theorem imaginaryPart_smul (z : ℂ) (a : A) : ℑ (z • a) = z.re • ℑ a + z.im • ℜ a := by have := by congrm (ℑ ($((re_add_im z).symm) • a)) simpa [-re_add_im, add_smul, ← smul_smul] lemma skewAdjointPart_eq_I_smul_imaginaryPart (x : A) : (skewAdjointPart ℝ x : A) = I • (imaginaryPart x : A) := by simp [imaginaryPart_apply_coe, smul_smul] lemma imaginaryPart_eq_neg_I_smul_skewAdjointPart (x : A) : (imaginaryPart x : A) = -I • (skewAdjointPart ℝ x : A) := rfl lemma IsSelfAdjoint.coe_realPart {x : A} (hx : IsSelfAdjoint x) : (ℜ x : A) = x := hx.coe_selfAdjointPart_apply ℝ nonrec lemma IsSelfAdjoint.imaginaryPart {x : A} (hx : IsSelfAdjoint x) : ℑ x = 0 := by rw [imaginaryPart, LinearMap.comp_apply, hx.skewAdjointPart_apply _, map_zero] lemma realPart_comp_subtype_selfAdjoint : realPart.comp (selfAdjoint.submodule ℝ A).subtype = LinearMap.id := selfAdjointPart_comp_subtype_selfAdjoint ℝ lemma imaginaryPart_comp_subtype_selfAdjoint : imaginaryPart.comp (selfAdjoint.submodule ℝ A).subtype = 0 := by rw [imaginaryPart, LinearMap.comp_assoc, skewAdjointPart_comp_subtype_selfAdjoint, LinearMap.comp_zero] @[simp] lemma selfAdjoint.realPart_coe {x : selfAdjoint A} : ℜ (x : A) = x := Subtype.ext x.property.coe_realPart @[simp] lemma selfAdjoint.imaginaryPart_coe {x : selfAdjoint A} : ℑ (x : A) = 0 := x.property.imaginaryPart lemma imaginaryPart_realPart {x : A} : ℑ (ℜ x : A) = 0 := (ℜ x).property.imaginaryPart lemma imaginaryPart_imaginaryPart {x : A} : ℑ (ℑ x : A) = 0 := (ℑ x).property.imaginaryPart lemma realPart_idem {x : A} : ℜ (ℜ x : A) = ℜ x := Subtype.ext <| (ℜ x).property.coe_realPart lemma realPart_imaginaryPart {x : A} : ℜ (ℑ x : A) = ℑ x := Subtype.ext <| (ℑ x).property.coe_realPart lemma realPart_surjective : Function.Surjective (realPart (A := A)) := fun x ↦ ⟨(x : A), Subtype.ext x.property.coe_realPart⟩ lemma imaginaryPart_surjective : Function.Surjective (imaginaryPart (A := A)) := fun x ↦ ⟨I • (x : A), Subtype.ext <| by simp only [imaginaryPart_I_smul, x.property.coe_realPart]⟩ open Submodule lemma span_selfAdjoint : span ℂ (selfAdjoint A : Set A) = ⊤ := by refine eq_top_iff'.mpr fun x ↦ ?_ rw [← realPart_add_I_smul_imaginaryPart x] exact add_mem (subset_span (ℜ x).property) <| SMulMemClass.smul_mem _ <| subset_span (ℑ x).property /-- The natural `ℝ`-linear equivalence between `selfAdjoint ℂ` and `ℝ`. -/ @[simps apply symm_apply] def Complex.selfAdjointEquiv : selfAdjoint ℂ ≃ₗ[ℝ] ℝ where toFun := fun z ↦ (z : ℂ).re invFun := fun x ↦ ⟨x, conj_ofReal x⟩ left_inv := fun z ↦ Subtype.ext <| conj_eq_iff_re.mp z.property.star_eq map_add' := by simp map_smul' := by simp lemma Complex.coe_selfAdjointEquiv (z : selfAdjoint ℂ) : (selfAdjointEquiv z : ℂ) = z := by simpa [selfAdjointEquiv_symm_apply] using (congr_arg Subtype.val <| Complex.selfAdjointEquiv.left_inv z) @[simp] lemma realPart_ofReal (r : ℝ) : (ℜ (r : ℂ) : ℂ) = r := by rw [realPart_apply_coe, star_def, conj_ofReal, ← two_smul ℝ (r : ℂ)] simp @[simp] lemma imaginaryPart_ofReal (r : ℝ) : ℑ (r : ℂ) = 0 := by ext1; simp [imaginaryPart_apply_coe, conj_ofReal] lemma Complex.coe_realPart (z : ℂ) : (ℜ z : ℂ) = z.re := calc (ℜ z : ℂ) = (↑(ℜ (↑z.re + ↑z.im * I))) := by congrm (ℜ $((re_add_im z).symm)) _ = z.re := by rw [map_add, AddSubmonoid.coe_add, mul_comm, ← smul_eq_mul, realPart_I_smul] simp lemma star_mul_self_add_self_mul_star {A : Type*} [NonUnitalNonAssocRing A] [StarRing A] [Module ℂ A] [IsScalarTower ℂ A A] [SMulCommClass ℂ A A] [StarModule ℂ A] (a : A) : star a * a + a * star a = 2 • (ℜ a * ℜ a + ℑ a * ℑ a) := have a_eq := (realPart_add_I_smul_imaginaryPart a).symm calc star a * a + a * star a = _ := congr((star $(a_eq)) * $(a_eq) + $(a_eq) * (star $(a_eq))) _ = 2 • (ℜ a * ℜ a + ℑ a * ℑ a) := by simp [mul_add, add_mul, smul_smul, two_smul, mul_smul_comm, smul_mul_assoc] abel end RealImaginaryPart
.lake/packages/mathlib/Mathlib/LinearAlgebra/Complex/Orientation.lean
import Mathlib.LinearAlgebra.Complex.Module import Mathlib.LinearAlgebra.Orientation /-! # The standard orientation on `ℂ`. This had previously been in `LinearAlgebra.Orientation`, but keeping it separate results in a significant import reduction. -/ namespace Complex /-- The standard orientation on `ℂ`. -/ protected noncomputable def orientation : Orientation ℝ ℂ (Fin 2) := Complex.basisOneI.orientation end Complex
.lake/packages/mathlib/Mathlib/LinearAlgebra/Complex/Determinant.lean
import Mathlib.LinearAlgebra.Complex.Module import Mathlib.LinearAlgebra.Determinant /-! # Determinants of maps in the complex numbers as a vector space over `ℝ` This file provides results about the determinants of maps in the complex numbers as a vector space over `ℝ`. -/ namespace Complex /-- The determinant of `conjAe`, as a linear map. -/ @[simp] theorem det_conjAe : LinearMap.det conjAe.toLinearMap = -1 := by rw [← LinearMap.det_toMatrix basisOneI, toMatrix_conjAe, Matrix.det_fin_two_of] simp /-- The determinant of `conjAe`, as a linear equiv. -/ @[simp] theorem linearEquiv_det_conjAe : LinearEquiv.det conjAe.toLinearEquiv = -1 := by rw [← Units.val_inj, LinearEquiv.coe_det, AlgEquiv.toLinearEquiv_toLinearMap, det_conjAe, Units.coe_neg_one] end Complex
.lake/packages/mathlib/Mathlib/LinearAlgebra/Complex/FiniteDimensional.lean
import Mathlib.Algebra.Algebra.Rat import Mathlib.Analysis.Complex.Cardinality import Mathlib.LinearAlgebra.Complex.Module import Mathlib.LinearAlgebra.FiniteDimensional.Defs import Mathlib.Order.Interval.Set.Infinite /-! # Complex number as a finite-dimensional vector space over `ℝ` This file contains the `FiniteDimensional ℝ ℂ` instance, as well as some results about the rank (`finrank` and `Module.rank`). -/ open Module namespace Complex instance : FiniteDimensional ℝ ℂ := basisOneI.finiteDimensional_of_finite /-- `ℂ` is a finite extension of `ℝ` of degree 2, i.e `[ℂ : ℝ] = 2` -/ @[simp, stacks 09G4] theorem finrank_real_complex : finrank ℝ ℂ = 2 := by rw [finrank_eq_card_basis basisOneI, Fintype.card_fin] @[simp] theorem rank_real_complex : Module.rank ℝ ℂ = 2 := by simp [← finrank_eq_rank, finrank_real_complex] theorem rank_real_complex'.{u} : Cardinal.lift.{u} (Module.rank ℝ ℂ) = 2 := by rw [← finrank_eq_rank, finrank_real_complex, Cardinal.lift_natCast, Nat.cast_ofNat] /-- `Fact` version of the dimension of `ℂ` over `ℝ`, locally useful in the definition of the circle. -/ theorem finrank_real_complex_fact : Fact (finrank ℝ ℂ = 2) := ⟨finrank_real_complex⟩ end Complex instance (priority := 100) FiniteDimensional.complexToReal (E : Type*) [AddCommGroup E] [Module ℂ E] [FiniteDimensional ℂ E] : FiniteDimensional ℝ E := FiniteDimensional.trans ℝ ℂ E theorem rank_real_of_complex (E : Type*) [AddCommGroup E] [Module ℂ E] : Module.rank ℝ E = 2 * Module.rank ℂ E := Cardinal.lift_inj.{_,0}.1 <| by rw [← lift_rank_mul_lift_rank ℝ ℂ E, Complex.rank_real_complex'] simp only [Cardinal.lift_id'] theorem finrank_real_of_complex (E : Type*) [AddCommGroup E] [Module ℂ E] : Module.finrank ℝ E = 2 * Module.finrank ℂ E := by rw [← Module.finrank_mul_finrank ℝ ℂ E, Complex.finrank_real_complex] section Rational open Cardinal Module @[simp] lemma Real.rank_rat_real : Module.rank ℚ ℝ = continuum := by refine (Free.rank_eq_mk_of_infinite_lt ℚ ℝ ?_).trans mk_real simpa [mk_real] using aleph0_lt_continuum /-- `C` has an uncountable basis over `ℚ`. -/ @[simp, stacks 09G0] lemma Complex.rank_rat_complex : Module.rank ℚ ℂ = continuum := by refine (Free.rank_eq_mk_of_infinite_lt ℚ ℂ ?_).trans Cardinal.mk_complex simpa using aleph0_lt_continuum /-- `ℂ` and `ℝ` are isomorphic as vector spaces over `ℚ`, or equivalently, as additive groups. -/ theorem Complex.nonempty_linearEquiv_real : Nonempty (ℂ ≃ₗ[ℚ] ℝ) := LinearEquiv.nonempty_equiv_iff_rank_eq.mpr <| by simp end Rational
.lake/packages/mathlib/Mathlib/LinearAlgebra/SymmetricAlgebra/Basic.lean
import Mathlib.LinearAlgebra.TensorAlgebra.Basic /-! # Symmetric Algebras Given a commutative semiring `R`, and an `R`-module `M`, we construct the symmetric algebra of `M`. This is the free commutative `R`-algebra generated (`R`-linearly) by the module `M`. ## Notation * `SymmetricAlgebra R M`: a concrete construction of the symmetric algebra defined as a quotient of the tensor algebra. It is endowed with an R-algebra structure and a commutative ring structure. * `SymmetricAlgebra.ι R`: the canonical R-linear map `M →ₗ[R] SymmetricAlgebra R M`. ## Note See `SymAlg R` instead if you are looking for the symmetrized algebra, which gives a commutative multiplication on `R` by $a \circ b = \frac{1}{2}(ab + ba)$. -/ variable (R M : Type*) [CommSemiring R] [AddCommMonoid M] [Module R M] /-- Relation on the tensor algebra which will yield the symmetric algebra when quotiented out by. -/ inductive TensorAlgebra.SymRel : TensorAlgebra R M → TensorAlgebra R M → Prop where | mul_comm (x y : M) : SymRel (ι R x * ι R y) (ι R y * ι R x) open TensorAlgebra /-- Concrete construction of the symmetric algebra of `M` by quotienting out the tensor algebra by the commutativity relation. -/ abbrev SymmetricAlgebra := RingQuot (SymRel R M) namespace SymmetricAlgebra /-- Algebra homomorphism from the tensor algebra over `M` to the symmetric algebra over `M`. -/ abbrev algHom : TensorAlgebra R M →ₐ[R] SymmetricAlgebra R M := RingQuot.mkAlgHom R (SymRel R M) lemma algHom_surjective : Function.Surjective (algHom R M) := RingQuot.mkAlgHom_surjective _ _ /-- Canonical inclusion of `M` into the symmetric algebra `SymmetricAlgebra R M`. -/ def ι : M →ₗ[R] SymmetricAlgebra R M := algHom R M ∘ₗ TensorAlgebra.ι R @[elab_as_elim] theorem induction {motive : SymmetricAlgebra R M → Prop} (algebraMap : ∀ r, motive (algebraMap R (SymmetricAlgebra R M) r)) (ι : ∀ x, motive (ι R M x)) (mul : ∀ a b, motive a → motive b → motive (a * b)) (add : ∀ a b, motive a → motive b → motive (a + b)) (a : SymmetricAlgebra R M) : motive a := by rcases algHom_surjective _ _ a with ⟨a, rfl⟩ induction a using TensorAlgebra.induction with | algebraMap r => rw [AlgHom.commutes]; exact algebraMap r | ι x => exact ι x | mul x y hx hy => rw [map_mul]; exact mul _ _ hx hy | add x y hx hy => rw [map_add]; exact add _ _ hx hy open TensorAlgebra in instance : CommSemiring (SymmetricAlgebra R M) where mul_comm a b := by change Commute a b induction b using SymmetricAlgebra.induction with | algebraMap r => exact Algebra.commute_algebraMap_right _ _ | ι x => induction a using SymmetricAlgebra.induction with | algebraMap r => exact Algebra.commute_algebraMap_left _ _ | ι y => simp [commute_iff_eq, ι, ← map_mul, RingQuot.mkAlgHom_rel _ (SymRel.mul_comm x y)] | mul a b ha hb => exact ha.mul_left hb | add a b ha hb => exact ha.add_left hb | mul b c hb hc => exact hb.mul_right hc | add b c hb hc => exact hb.add_right hc instance (R M) [CommRing R] [AddCommMonoid M] [Module R M] : CommRing (SymmetricAlgebra R M) where __ := inferInstanceAs (CommSemiring (SymmetricAlgebra R M)) __ := inferInstanceAs (Ring (RingQuot (SymRel R M))) variable {R M} {A : Type*} [CommSemiring A] [Algebra R A] /-- For any linear map `f : M →ₗ[R] A`, `SymmetricAlgebra.lift f` lifts the linear map to an R-algebra homomorphism from `SymmetricAlgebra R M` to `A`. -/ def lift : (M →ₗ[R] A) ≃ (SymmetricAlgebra R M →ₐ[R] A) := by let equiv : (TensorAlgebra R M →ₐ[R] A) ≃ {f : TensorAlgebra R M →ₐ[R] A // ∀ {x y}, (TensorAlgebra.SymRel R M) x y → f x = f y} := by refine (Equiv.subtypeUnivEquiv fun h _ _ h' ↦ ?_).symm induction h' with | mul_comm x y => rw [map_mul, map_mul, mul_comm] exact (TensorAlgebra.lift R).trans <| equiv.trans <| RingQuot.liftAlgHom R variable (f : M →ₗ[R] A) @[simp] lemma lift_ι_apply (a : M) : lift f (ι R M a) = f a := by simp [lift, ι, algHom] @[simp] lemma lift_comp_ι : lift f ∘ₗ ι R M = f := LinearMap.ext <| lift_ι_apply f @[ext] theorem algHom_ext {F G : SymmetricAlgebra R M →ₐ[R] A} (h : F ∘ₗ ι R M = (G ∘ₗ ι R M : M →ₗ[R] A)) : F = G := by ext x exact congr($h x) @[simp] lemma lift_ι : lift (ι R M) = .id R (SymmetricAlgebra R M) := by apply algHom_ext rw [lift_comp_ι] ext simp /-- The left-inverse of `algebraMap`. -/ def algebraMapInv : SymmetricAlgebra R M →ₐ[R] R := lift (0 : M →ₗ[R] R) variable (M) theorem algebraMap_leftInverse : Function.LeftInverse algebraMapInv (algebraMap R <| SymmetricAlgebra R M) := fun x => by simp [algebraMapInv] @[simp] theorem algebraMap_inj (x y : R) : algebraMap R (SymmetricAlgebra R M) x = algebraMap R (SymmetricAlgebra R M) y ↔ x = y := (algebraMap_leftInverse M).injective.eq_iff @[simp] theorem algebraMap_eq_zero_iff (x : R) : algebraMap R (SymmetricAlgebra R M) x = 0 ↔ x = 0 := map_eq_zero_iff (algebraMap _ _) (algebraMap_leftInverse _).injective @[simp] theorem algebraMap_eq_one_iff (x : R) : algebraMap R (SymmetricAlgebra R M) x = 1 ↔ x = 1 := map_eq_one_iff (algebraMap _ _) (algebraMap_leftInverse _).injective /-- A `SymmetricAlgebra` over a nontrivial semiring is nontrivial. -/ instance [Nontrivial R] : Nontrivial (SymmetricAlgebra R M) := (algebraMap_leftInverse M).injective.nontrivial end SymmetricAlgebra
.lake/packages/mathlib/Mathlib/LinearAlgebra/SymmetricAlgebra/Basis.lean
import Mathlib.LinearAlgebra.SymmetricAlgebra.Basic import Mathlib.LinearAlgebra.Dimension.Basic import Mathlib.RingTheory.MvPolynomial /-! # A basis for `SymmetricAlgebra R M` ## Main definitions * `SymmetricAlgebra.equivMvPolynomial b : SymmetricAlgebra R M ≃ₐ[R] MvPolynomial I R`: the isomorphism given by a basis `b : Basis I R M`. * `Basis.symmetricAlgebra b : Basis (I →₀ ℕ) R (SymmetricAlgebra R M)`: the basis on the symmetric algebra given by a basis `b : Basis I R M`. ## Main results * `SymmetricAlgebra.instFreeModule`: the symmetric algebra over `M` is free when `M` is free. * `SymmetricAlgebra.rank_eq`: the rank of `SymmetricAlgebra R M` when `M` is a nontrivial free module is equal to `max (Module.rank R M) Cardinal.aleph0`. ## Implementation notes This file closely mirrors the corresponding file for `TensorAlgebra`. -/ open Module namespace SymmetricAlgebra universe uκ uR uM variable {κ : Type uκ} {R : Type uR} {M : Type uM} section CommSemiring variable [CommSemiring R] [AddCommMonoid M] [Module R M] /-- `SymmetricAlgebra.equivMvPolynomial` gives an algebra isomorphism between the symmetric algebra over a free module and multivariate polynomials over a basis. This is analogous to `TensorAlgebra.equivFreeAlgebra`. -/ noncomputable def equivMvPolynomial (b : Basis κ R M) : SymmetricAlgebra R M ≃ₐ[R] MvPolynomial κ R := .ofAlgHom (SymmetricAlgebra.lift <| Basis.constr b R .X) (MvPolynomial.aeval fun i ↦ ι R M (b i)) (MvPolynomial.algHom_ext fun i ↦ by simp) (algHom_ext <| b.ext fun i ↦ by simp) @[simp] lemma equivMvPolynomial_ι_apply (b : Basis κ R M) (i : κ) : equivMvPolynomial b (ι R M (b i)) = .X (R := R) i := (SymmetricAlgebra.lift_ι_apply _ _).trans <| by simp @[simp] lemma equivMvPolynomial_symm_X (b : Basis κ R M) (i : κ) : (equivMvPolynomial b).symm (MvPolynomial.X i) = ι R M (b i) := (equivMvPolynomial b).toEquiv.symm_apply_eq.mpr <| equivMvPolynomial_ι_apply b i |>.symm /-- A basis on `M` can be lifted to a basis on `SymmetricAlgebra R M`. -/ @[simps! repr_apply] noncomputable def _root_.Module.Basis.symmetricAlgebra (b : Basis κ R M) : Basis (κ →₀ ℕ) R (SymmetricAlgebra R M) := (MvPolynomial.basisMonomials κ R).map <| (SymmetricAlgebra.equivMvPolynomial b).symm.toLinearEquiv /-- `SymmetricAlgebra R M` is free when `M` is. -/ instance instModuleFree [Module.Free R M] : Module.Free R (SymmetricAlgebra R M) := let ⟨⟨_I, b⟩⟩ := Module.Free.exists_basis (R := R) (M := M) .of_basis b.symmetricAlgebra /-- The `SymmetricAlgebra` of a free module over a commutative semiring with no zero-divisors has no zero-divisors. -/ instance instNoZeroDivisors [NoZeroDivisors R] [Module.Free R M] : NoZeroDivisors (SymmetricAlgebra R M) := have ⟨⟨_, b⟩⟩ := ‹Module.Free R M› (equivMvPolynomial b).toMulEquiv.noZeroDivisors end CommSemiring section CommRing variable [CommRing R] [AddCommGroup M] [Module R M] /-- The `TensorAlgebra` of a free module over an integral domain is a domain. -/ instance instIsDomain [IsDomain R] [Module.Free R M] : IsDomain (SymmetricAlgebra R M) := NoZeroDivisors.to_isDomain _ attribute [pp_with_univ] Cardinal.lift open Cardinal in lemma rank_eq [Nontrivial M] [Module.Free R M] : Module.rank R (SymmetricAlgebra R M) = Cardinal.lift.{uR} (max (Module.rank R M) ℵ₀) := by let ⟨⟨κ, b⟩⟩ := Module.Free.exists_basis (R := R) (M := M) have : Nonempty κ := Basis.index_nonempty b have : Nontrivial R := Module.nontrivial R M rw [(equivMvPolynomial b).toLinearEquiv.rank_eq, MvPolynomial.rank_eq_lift, Cardinal.mk_finsupp_nat, Basis.mk_eq_rank'' b] end CommRing end SymmetricAlgebra
.lake/packages/mathlib/Mathlib/LinearAlgebra/Eigenspace/Triangularizable.lean
import Mathlib.LinearAlgebra.Eigenspace.Basic import Mathlib.FieldTheory.IsAlgClosed.Spectrum import Mathlib.LinearAlgebra.FreeModule.Finite.Matrix /-! # Triangularizable linear endomorphisms This file contains basic results relevant to the triangularizability of linear endomorphisms. ## Main definitions / results * `Module.End.exists_eigenvalue`: in finite dimensions, over an algebraically closed field, every linear endomorphism has an eigenvalue. * `Module.End.iSup_genEigenspace_eq_top`: in finite dimensions, over an algebraically closed field, the generalized eigenspaces of any linear endomorphism span the whole space. * `Module.End.iSup_genEigenspace_restrict_eq_top`: in finite dimensions, if the generalized eigenspaces of a linear endomorphism span the whole space then the same is true of its restriction to any invariant submodule. ## References * [Sheldon Axler, *Linear Algebra Done Right*][axler2015] * https://en.wikipedia.org/wiki/Eigenvalues_and_eigenvectors ## TODO Define triangularizable endomorphisms (e.g., as existence of a maximal chain of invariant subspaces) and prove that in finite dimensions over a field, this is equivalent to the property that the generalized eigenspaces span the whole space. ## Tags eigenspace, eigenvector, eigenvalue, eigen -/ open Set Function Module Module variable {K V : Type*} [Field K] [AddCommGroup V] [Module K V] {R M : Type*} [CommRing R] [AddCommGroup M] [Module R M] namespace Module.End theorem exists_hasEigenvalue_of_genEigenspace_eq_top [Nontrivial M] {f : End R M} (k : ℕ∞) (hf : ⨆ μ, f.genEigenspace μ k = ⊤) : ∃ μ, f.HasEigenvalue μ := by suffices ∃ μ, f.HasUnifEigenvalue μ k by peel this with μ hμ exact HasUnifEigenvalue.lt zero_lt_one hμ simp [HasUnifEigenvalue, ← not_forall, ← iSup_eq_bot, hf] -- This is Lemma 5.21 of [axler2015], although we are no longer following that proof. /-- In finite dimensions, over an algebraically closed field, every linear endomorphism has an eigenvalue. -/ theorem exists_eigenvalue [IsAlgClosed K] [FiniteDimensional K V] [Nontrivial V] (f : End K V) : ∃ c : K, f.HasEigenvalue c := by simp_rw [hasEigenvalue_iff_mem_spectrum] exact spectrum.nonempty_of_isAlgClosed_of_finiteDimensional K f noncomputable instance [IsAlgClosed K] [FiniteDimensional K V] [Nontrivial V] (f : End K V) : Inhabited f.Eigenvalues := ⟨⟨f.exists_eigenvalue.choose, f.exists_eigenvalue.choose_spec⟩⟩ -- Lemma 8.21 of [axler2015] /-- In finite dimensions, over an algebraically closed field, the generalized eigenspaces of any linear endomorphism span the whole space. -/ theorem iSup_maxGenEigenspace_eq_top [IsAlgClosed K] [FiniteDimensional K V] (f : End K V) : ⨆ (μ : K), f.maxGenEigenspace μ = ⊤ := by -- We prove the claim by strong induction on the dimension of the vector space. suffices ∀ n, finrank K V = n → ⨆ (μ : K), f.maxGenEigenspace μ = ⊤ by exact this _ rfl intro n h_dim induction n using Nat.strong_induction_on generalizing V with | h n ih => rcases n with - | n -- If the vector space is 0-dimensional, the result is trivial. · rw [← top_le_iff] simp only [Submodule.finrank_eq_zero.1 (Eq.trans (finrank_top _ _) h_dim), bot_le] -- Otherwise the vector space is nontrivial. · haveI : Nontrivial V := finrank_pos_iff.1 (by rw [h_dim]; apply Nat.zero_lt_succ) -- Hence, `f` has an eigenvalue `μ₀`. obtain ⟨μ₀, hμ₀⟩ : ∃ μ₀, f.HasEigenvalue μ₀ := exists_eigenvalue f -- We define `ES` to be the generalized eigenspace let ES := f.genEigenspace μ₀ (finrank K V) -- and `ER` to be the generalized eigenrange. let ER := f.genEigenrange μ₀ (finrank K V) -- `f` maps `ER` into itself. have h_f_ER : ∀ x : V, x ∈ ER → f x ∈ ER := fun x hx => map_genEigenrange_le (Submodule.mem_map_of_mem hx) -- Therefore, we can define the restriction `f'` of `f` to `ER`. let f' : End K ER := f.restrict h_f_ER -- The dimension of `ES` is positive have h_dim_ES_pos : 0 < finrank K ES := by dsimp only [ES] rw [h_dim] apply pos_finrank_genEigenspace_of_hasEigenvalue hμ₀ (Nat.zero_lt_succ n) -- and the dimensions of `ES` and `ER` add up to `finrank K V`. have h_dim_add : finrank K ER + finrank K ES = finrank K V := by dsimp only [ER, ES] rw [Module.End.genEigenspace_nat, Module.End.genEigenrange_nat] apply LinearMap.finrank_range_add_finrank_ker -- Therefore the dimension `ER` mus be smaller than `finrank K V`. have h_dim_ER : finrank K ER < n.succ := by omega -- This allows us to apply the induction hypothesis on `ER`: have ih_ER : ⨆ (μ : K), f'.maxGenEigenspace μ = ⊤ := ih (finrank K ER) h_dim_ER f' rfl -- The induction hypothesis gives us a statement about subspaces of `ER`. We can transfer this -- to a statement about subspaces of `V` via `Submodule.subtype`: have ih_ER' : ⨆ (μ : K), (f'.maxGenEigenspace μ).map ER.subtype = ER := by simp only [(Submodule.map_iSup _ _).symm, ih_ER, Submodule.map_subtype_top ER] -- Moreover, every generalized eigenspace of `f'` is contained in the corresponding generalized -- eigenspace of `f`. have hff' : ∀ μ, (f'.maxGenEigenspace μ).map ER.subtype ≤ f.maxGenEigenspace μ := by intros rw [maxGenEigenspace, genEigenspace_restrict] apply Submodule.map_comap_le -- It follows that `ER` is contained in the span of all generalized eigenvectors. have hER : ER ≤ ⨆ (μ : K), f.maxGenEigenspace μ := by rw [← ih_ER'] exact iSup_mono hff' -- `ES` is contained in this span by definition. have hES : ES ≤ ⨆ (μ : K), f.maxGenEigenspace μ := ((f.genEigenspace μ₀).mono le_top).trans (le_iSup f.maxGenEigenspace μ₀) -- Moreover, we know that `ER` and `ES` are disjoint. have h_disjoint : Disjoint ER ES := generalized_eigenvec_disjoint_range_ker f μ₀ -- Since the dimensions of `ER` and `ES` add up to the dimension of `V`, it follows that the -- span of all generalized eigenvectors is all of `V`. change ⨆ (μ : K), f.maxGenEigenspace μ = ⊤ rw [← top_le_iff, ← Submodule.eq_top_of_disjoint ER ES h_dim_add.ge h_disjoint] apply sup_le hER hES end Module.End namespace Submodule variable {p : Submodule K V} {f : Module.End K V} theorem inf_iSup_genEigenspace [FiniteDimensional K V] (h : ∀ x ∈ p, f x ∈ p) (k : ℕ∞) : p ⊓ ⨆ μ, f.genEigenspace μ k = ⨆ μ, p ⊓ f.genEigenspace μ k := by refine le_antisymm (fun m hm ↦ ?_) (le_inf_iff.mpr ⟨iSup_le fun μ ↦ inf_le_left, iSup_mono fun μ ↦ inf_le_right⟩) classical obtain ⟨hm₀ : m ∈ p, hm₁ : m ∈ ⨆ μ, f.genEigenspace μ k⟩ := hm obtain ⟨m, hm₂, rfl⟩ := (mem_iSup_iff_exists_finsupp _ _).mp hm₁ suffices ∀ μ, (m μ : V) ∈ p by exact (mem_iSup_iff_exists_finsupp _ _).mpr ⟨m, fun μ ↦ mem_inf.mp ⟨this μ, hm₂ μ⟩, rfl⟩ intro μ by_cases hμ : μ ∈ m.support; swap · simp only [Finsupp.notMem_support_iff.mp hμ, p.zero_mem] have hm₂_aux := hm₂ simp_rw [Module.End.mem_genEigenspace] at hm₂_aux choose l hlk hl using hm₂_aux let l₀ : ℕ := m.support.sup l have h_comm : ∀ (μ₁ μ₂ : K), Commute ((f - algebraMap K (End K V) μ₁) ^ l₀) ((f - algebraMap K (End K V) μ₂) ^ l₀) := fun μ₁ μ₂ ↦ ((Commute.sub_right rfl <| Algebra.commute_algebraMap_right _ _).sub_left (Algebra.commute_algebraMap_left _ _)).pow_pow _ _ let g : End K V := (m.support.erase μ).noncommProd _ fun μ₁ _ μ₂ _ _ ↦ h_comm μ₁ μ₂ have hfg : Commute f g := Finset.noncommProd_commute _ _ _ _ fun μ' _ ↦ (Commute.sub_right rfl <| Algebra.commute_algebraMap_right _ _).pow_right _ have hg₀ : g (m.sum fun _μ mμ ↦ mμ) = g (m μ) := by suffices ∀ μ' ∈ m.support, g (m μ') = if μ' = μ then g (m μ) else 0 by rw [map_finsuppSum, Finsupp.sum_congr (g2 := fun μ' _ ↦ if μ' = μ then g (m μ) else 0) this, Finsupp.sum_ite_eq', if_pos hμ] rintro μ' hμ' split_ifs with hμμ' · rw [hμμ'] have hl₀ : ((f - algebraMap K (End K V) μ') ^ l₀) (m μ') = 0 := by rw [← LinearMap.mem_ker, Algebra.algebraMap_eq_smul_one, ← End.mem_genEigenspace_nat] simp_rw [← End.mem_genEigenspace_nat] at hl suffices (l μ' : ℕ∞) ≤ l₀ from (f.genEigenspace μ').mono this (hl μ') simpa only [Nat.cast_le] using Finset.le_sup hμ' have : _ = g := (m.support.erase μ).noncommProd_erase_mul (Finset.mem_erase.mpr ⟨hμμ', hμ'⟩) (fun μ ↦ (f - algebraMap K (End K V) μ) ^ l₀) (fun μ₁ _ μ₂ _ _ ↦ h_comm μ₁ μ₂) rw [← this, Module.End.mul_apply, hl₀, _root_.map_zero] have hg₁ : MapsTo g p p := Finset.noncommProd_induction _ _ _ (fun g' : End K V ↦ MapsTo g' p p) (fun f₁ f₂ ↦ MapsTo.comp) (mapsTo_id _) fun μ' _ ↦ by suffices MapsTo (f - algebraMap K (End K V) μ') p p by simp only [Module.End.coe_pow, this.iterate l₀] intro x hx rw [LinearMap.sub_apply, algebraMap_end_apply] exact p.sub_mem (h _ hx) (smul_mem p μ' hx) have hg₂ : MapsTo g ↑(f.genEigenspace μ k) ↑(f.genEigenspace μ k) := f.mapsTo_genEigenspace_of_comm hfg μ k have hg₃ : InjOn g ↑(f.genEigenspace μ k) := by apply LinearMap.injOn_of_disjoint_ker subset_rfl have this := f.independent_genEigenspace k have aux (μ') (_hμ' : μ' ∈ m.support.erase μ) : (f.genEigenspace μ') ↑l₀ ≤ (f.genEigenspace μ') k := by apply (f.genEigenspace μ').mono obtain _ | k := k · exact le_top · exact Nat.cast_le.2 <| Finset.sup_le fun i _ ↦ Nat.cast_le.1 <| hlk i rw [LinearMap.ker_noncommProd_eq_of_supIndep_ker, ← Finset.sup_eq_iSup] · have := Finset.supIndep_iff_disjoint_erase.mp (this.supIndep' m.support) μ hμ apply this.mono_right apply Finset.sup_mono_fun intro μ' hμ' rw [Algebra.algebraMap_eq_smul_one, ← End.genEigenspace_nat] apply aux μ' hμ' · have := this.supIndep' (m.support.erase μ) apply this.antitone_fun intro μ' hμ' rw [Algebra.algebraMap_eq_smul_one, ← End.genEigenspace_nat] apply aux μ' hμ' have hg₄ : SurjOn g ↑(p ⊓ f.genEigenspace μ k) ↑(p ⊓ f.genEigenspace μ k) := by have : MapsTo g ↑(p ⊓ f.genEigenspace μ k) ↑(p ⊓ f.genEigenspace μ k) := hg₁.inter_inter hg₂ rw [← LinearMap.injOn_iff_surjOn this] exact hg₃.mono inter_subset_right specialize hm₂ μ obtain ⟨y, ⟨hy₀ : y ∈ p, hy₁ : y ∈ f.genEigenspace μ k⟩, hy₂ : g y = g (m μ)⟩ := hg₄ ⟨(hg₀ ▸ hg₁ hm₀), hg₂ hm₂⟩ rwa [← hg₃ hy₁ hm₂ hy₂] theorem eq_iSup_inf_genEigenspace [FiniteDimensional K V] (k : ℕ∞) (h : ∀ x ∈ p, f x ∈ p) (h' : ⨆ μ, f.genEigenspace μ k = ⊤) : p = ⨆ μ, p ⊓ f.genEigenspace μ k := by rw [← inf_iSup_genEigenspace h, h', inf_top_eq] end Submodule /-- In finite dimensions, if the generalized eigenspaces of a linear endomorphism span the whole space then the same is true of its restriction to any invariant submodule. -/ theorem Module.End.genEigenspace_restrict_eq_top {p : Submodule K V} {f : Module.End K V} [FiniteDimensional K V] {k : ℕ∞} (h : ∀ x ∈ p, f x ∈ p) (h' : ⨆ μ, f.genEigenspace μ k = ⊤) : ⨆ μ, Module.End.genEigenspace (LinearMap.restrict f h) μ k = ⊤ := by have := congr_arg (Submodule.comap p.subtype) (Submodule.eq_iSup_inf_genEigenspace k h h') have h_inj : Function.Injective p.subtype := Subtype.coe_injective simp_rw [Submodule.inf_genEigenspace f p h, Submodule.comap_subtype_self, ← Submodule.map_iSup, Submodule.comap_map_eq_of_injective h_inj] at this exact this.symm
.lake/packages/mathlib/Mathlib/LinearAlgebra/Eigenspace/Matrix.lean
import Mathlib.LinearAlgebra.Eigenspace.Basic /-! # Eigenvalues, Eigenvectors and Spectrum for Matrices This file collects results about eigenvectors, eigenvalues and spectrum specific to matrices over a nontrivial commutative ring, nontrivial commutative ring without zero divisors, or field. ## Tags eigenspace, eigenvector, eigenvalue, spectrum, matrix -/ section SpectrumDiagonal variable {R n M : Type*} [DecidableEq n] [Fintype n] open Matrix Module End section NontrivialCommRing variable [CommRing R] [Nontrivial R] [AddCommGroup M] [Module R M] /-- Basis vectors are eigenvectors of associated diagonal linear operator. -/ lemma hasEigenvector_toLin_diagonal (d : n → R) (i : n) (b : Basis n R M) : HasEigenvector (toLin b b (diagonal d)) (d i) (b i) := ⟨mem_eigenspace_iff.mpr <| by simp [diagonal], Basis.ne_zero b i⟩ /-- Standard basis vectors are eigenvectors of any associated diagonal linear operator. -/ lemma hasEigenvector_toLin'_diagonal (d : n → R) (i : n) : HasEigenvector (toLin' (diagonal d)) (d i) (Pi.basisFun R n i) := hasEigenvector_toLin_diagonal _ _ (Pi.basisFun R n) /-- Eigenvalues of a diagonal linear operator are the diagonal entries. -/ lemma hasEigenvalue_toLin_diagonal_iff (d : n → R) {μ : R} [NoZeroSMulDivisors R M] (b : Basis n R M) : HasEigenvalue (toLin b b (diagonal d)) μ ↔ ∃ i, d i = μ := by have (i : n) : HasEigenvalue (toLin b b (diagonal d)) (d i) := hasEigenvalue_of_hasEigenvector <| hasEigenvector_toLin_diagonal d i b constructor · contrapose! intro hμ h_eig have h_iSup : ⨆ μ ∈ Set.range d, eigenspace (toLin b b (diagonal d)) μ = ⊤ := by rw [eq_top_iff, ← b.span_eq, Submodule.span_le] rintro - ⟨i, rfl⟩ simp only [SetLike.mem_coe] apply Submodule.mem_iSup_of_mem (d i) apply Submodule.mem_iSup_of_mem ⟨i, rfl⟩ rw [mem_eigenspace_iff] exact (hasEigenvector_toLin_diagonal d i b).apply_eq_smul have hμ_notMem : μ ∉ Set.range d := by simpa using fun i ↦ (hμ i) have := eigenspaces_iSupIndep (toLin b b (diagonal d)) |>.disjoint_biSup hμ_notMem rw [h_iSup, disjoint_top] at this exact h_eig this · rintro ⟨i, rfl⟩ exact this i /-- Eigenvalues of a diagonal linear operator with respect to standard basis are the diagonal entries. -/ lemma hasEigenvalue_toLin'_diagonal_iff [NoZeroDivisors R] (d : n → R) {μ : R} : HasEigenvalue (toLin' (diagonal d)) μ ↔ (∃ i, d i = μ) := hasEigenvalue_toLin_diagonal_iff _ <| Pi.basisFun R n end NontrivialCommRing namespace Matrix variable [CommRing R] [AddCommGroup M] [Module R M] (d : n → R) {μ : R} (b : Basis n R M) @[simp] lemma iSup_eigenspace_toLin_diagonal_eq_top : ⨆ μ, eigenspace ((diagonal d).toLin b b) μ = ⊤ := by refine (Submodule.eq_top_iff_forall_basis_mem b).mpr fun j ↦ ?_ exact Submodule.mem_iSup_of_mem (d j) <| by simp [diagonal_apply] @[simp] lemma iSup_eigenspace_toLin'_diagonal_eq_top : ⨆ μ, eigenspace (diagonal d).toLin' μ = ⊤ := iSup_eigenspace_toLin_diagonal_eq_top d <| Pi.basisFun R n @[simp] lemma maxGenEigenspace_toLin_diagonal_eq_eigenspace [IsDomain R] : maxGenEigenspace ((diagonal d).toLin b b) μ = eigenspace ((diagonal d).toLin b b) μ := by refine le_antisymm (fun x hx ↦ ?_) eigenspace_le_maxGenEigenspace obtain ⟨k, hk⟩ := (mem_maxGenEigenspace _ _ _).mp hx replace hk (j : n) : b.repr x j = 0 ∨ d j = μ ∧ k ≠ 0 := by have aux : (diagonal d).toLin b b - μ • 1 = (diagonal (d - μ • 1)).toLin b b := by rw [Pi.sub_def, ← diagonal_sub]; simp [one_eq_id] rw [aux, ← toLin_pow, diagonal_pow, toLin_apply_eq_zero_iff] at hk simpa [mulVec_eq_sum, diagonal_apply, sub_eq_zero] using hk j have aux (j : n) : (b.repr x j * d j) • b j = μ • (b.repr x j • b j) := by rcases hk j with hj | hj · simp [hj] · rw [← hj.1, mul_comm, MulAction.mul_smul] simp [toLin_apply, mulVec_eq_sum, diagonal_apply, aux, ← Finset.smul_sum] @[simp] lemma maxGenEigenspace_toLin'_diagonal_eq_eigenspace [IsDomain R] : maxGenEigenspace (diagonal d).toLin' μ = eigenspace (diagonal d).toLin' μ := maxGenEigenspace_toLin_diagonal_eq_eigenspace d <| Pi.basisFun R n @[simp] theorem _root_.LinearMap.spectrum_toMatrix (f : M →ₗ[R] M) (b : Basis n R M) : spectrum R (f.toMatrix b b) = spectrum R f := AlgEquiv.spectrum_eq (LinearMap.toMatrixAlgEquiv b) f @[simp] theorem _root_.LinearMap.spectrum_toMatrix' (f : (n → R) →ₗ[R] (n → R)) : spectrum R f.toMatrix' = spectrum R f := AlgEquiv.spectrum_eq LinearMap.toMatrixAlgEquiv' f @[simp] theorem spectrum_toLin (A : Matrix n n R) (b : Basis n R M) : spectrum R (A.toLin b b) = spectrum R A := AlgEquiv.spectrum_eq (Matrix.toLinAlgEquiv b) A @[simp] theorem spectrum_toLin' (A : Matrix n n R) : spectrum R A.toLin' = spectrum R A := AlgEquiv.spectrum_eq Matrix.toLinAlgEquiv' A end Matrix /-- The spectrum of the diagonal operator is the range of the diagonal viewed as a function. -/ @[simp] lemma spectrum_diagonal [Field R] (d : n → R) : spectrum R (diagonal d) = Set.range d := by ext μ rw [← AlgEquiv.spectrum_eq (toLinAlgEquiv <| Pi.basisFun R n), ← hasEigenvalue_iff_mem_spectrum] exact hasEigenvalue_toLin'_diagonal_iff d end SpectrumDiagonal
.lake/packages/mathlib/Mathlib/LinearAlgebra/Eigenspace/Charpoly.lean
import Mathlib.LinearAlgebra.Charpoly.BaseChange import Mathlib.LinearAlgebra.Charpoly.ToMatrix import Mathlib.LinearAlgebra.Eigenspace.Basic /-! # Eigenvalues are the roots of the characteristic polynomial. ## Tags eigenvalue, characteristic polynomial -/ namespace Module namespace End open LinearMap variable {R M : Type*} [CommRing R] [IsDomain R] [AddCommGroup M] [Module R M] [Module.Free R M] [Module.Finite R M] variable {K V : Type*} [Field K] [AddCommGroup V] [Module K V] [Module.Finite K V] /-- The roots of the characteristic polynomial are exactly the eigenvalues. `R` is required to be an integral domain, otherwise there is the counterexample: R = M = Z/6Z, f(x) = 2x, v = 3, μ = 4, but p = X - 2. -/ lemma hasEigenvalue_iff_isRoot_charpoly (f : End R M) (μ : R) : f.HasEigenvalue μ ↔ f.charpoly.IsRoot μ := by rw [hasEigenvalue_iff, eigenspace_def, ← det_eq_zero_iff_ker_ne_bot, det_eq_sign_charpoly_coeff] simp [Polynomial.coeff_zero_eq_eval_zero, charpoly_sub_smul] lemma mem_spectrum_iff_isRoot_charpoly (f : End K V) (μ : K) : μ ∈ spectrum K f ↔ f.charpoly.IsRoot μ := by rw [← hasEigenvalue_iff_mem_spectrum, hasEigenvalue_iff_isRoot_charpoly] end End end Module
.lake/packages/mathlib/Mathlib/LinearAlgebra/Eigenspace/Pi.lean
import Mathlib.LinearAlgebra.Eigenspace.Triangularizable /-! # Simultaneous eigenvectors and eigenvalues for families of endomorphisms In finite dimensions, the theory of simultaneous eigenvalues for a family of linear endomorphisms `i ↦ f i` enjoys similar properties to that of a single endomorphism, provided the family obeys a compatibility condition. This condition is that the maximum generalised eigenspaces of each endomorphism are invariant under the action of all members of the family. It is trivially satisfied for commuting endomorphisms but there are important more general situations where it also holds (e.g., representations of nilpotent Lie algebras). ## Main definitions / results * `Module.End.independent_iInf_maxGenEigenspace_of_forall_mapsTo`: the simultaneous generalised eigenspaces of a compatible family of endomorphisms are independent. * `Module.End.iSup_iInf_maxGenEigenspace_eq_top_of_forall_mapsTo`: in finite dimensions, the simultaneous generalised eigenspaces of a compatible family of endomorphisms span if the same is true of each map individually. -/ open Function Set namespace Module.End variable {ι R K M : Type*} [CommRing R] [Field K] [AddCommGroup M] [Module R M] [Module K M] (f : ι → End R M) theorem mem_iInf_maxGenEigenspace_iff (χ : ι → R) (m : M) : m ∈ ⨅ i, (f i).maxGenEigenspace (χ i) ↔ ∀ j, ∃ k : ℕ, ((f j - χ j • ↑1) ^ k) m = 0 := by simp /-- Given a family of endomorphisms `i ↦ f i`, a family of candidate eigenvalues `i ↦ μ i`, and a submodule `p` which is invariant w.r.t. every `f i`, the intersection of `p` with the simultaneous maximal generalised eigenspace (taken over all `i`), is the same as the simultaneous maximal generalised eigenspace of the `f i` restricted to `p`. -/ lemma _root_.Submodule.inf_iInf_maxGenEigenspace_of_forall_mapsTo {μ : ι → R} (p : Submodule R M) (hfp : ∀ i, MapsTo (f i) p p) : p ⊓ ⨅ i, (f i).maxGenEigenspace (μ i) = (⨅ i, maxGenEigenspace ((f i).restrict (hfp i)) (μ i)).map p.subtype := by cases isEmpty_or_nonempty ι · simp [iInf_of_isEmpty] · simp_rw [inf_iInf, p.inf_genEigenspace _ (hfp _), Submodule.map_iInf _ p.injective_subtype] /-- Given a family of endomorphisms `i ↦ f i`, a family of candidate eigenvalues `i ↦ μ i`, and a distinguished index `i` whose maximal generalised `μ i`-eigenspace is invariant w.r.t. every `f j`, taking simultaneous maximal generalised eigenspaces is unaffected by first restricting to the distinguished generalised `μ i`-eigenspace. -/ lemma iInf_maxGenEigenspace_restrict_map_subtype_eq {μ : ι → R} (i : ι) (h : ∀ j, MapsTo (f j) ((f i).maxGenEigenspace (μ i)) ((f i).maxGenEigenspace (μ i))) : letI p := (f i).maxGenEigenspace (μ i) letI q (j : ι) := maxGenEigenspace ((f j).restrict (h j)) (μ j) (⨅ j, q j).map p.subtype = ⨅ j, (f j).maxGenEigenspace (μ j) := by have : Nonempty ι := ⟨i⟩ set p := (f i).maxGenEigenspace (μ i) have : ⨅ j, (f j).maxGenEigenspace (μ j) = p ⊓ ⨅ j, (f j).maxGenEigenspace (μ j) := by refine le_antisymm ?_ inf_le_right simpa only [le_inf_iff, le_refl, and_true] using iInf_le _ _ rw [Submodule.map_iInf _ p.injective_subtype, this, Submodule.inf_iInf] conv_rhs => enter [1] ext rw [p.inf_genEigenspace (f _) (h _)] variable [NoZeroSMulDivisors R M] lemma disjoint_iInf_maxGenEigenspace {χ₁ χ₂ : ι → R} (h : χ₁ ≠ χ₂) : Disjoint (⨅ i, (f i).maxGenEigenspace (χ₁ i)) (⨅ i, (f i).maxGenEigenspace (χ₂ i)) := by obtain ⟨j, hj⟩ : ∃ j, χ₁ j ≠ χ₂ j := Function.ne_iff.mp h exact (End.disjoint_genEigenspace (f j) hj ⊤ ⊤).mono (iInf_le _ j) (iInf_le _ j) lemma injOn_iInf_maxGenEigenspace : InjOn (fun χ : ι → R ↦ ⨅ i, (f i).maxGenEigenspace (χ i)) {χ | ⨅ i, (f i).maxGenEigenspace (χ i) ≠ ⊥} := by rintro χ₁ _ χ₂ hχ₂ (hχ₁₂ : ⨅ i, (f i).maxGenEigenspace (χ₁ i) = ⨅ i, (f i).maxGenEigenspace (χ₂ i)) contrapose! hχ₂ simpa [hχ₁₂] using disjoint_iInf_maxGenEigenspace f hχ₂ lemma independent_iInf_maxGenEigenspace_of_forall_mapsTo (h : ∀ i j φ, MapsTo (f i) ((f j).maxGenEigenspace φ) ((f j).maxGenEigenspace φ)) : iSupIndep fun χ : ι → R ↦ ⨅ i, (f i).maxGenEigenspace (χ i) := by replace h (l : ι) (χ : ι → R) : MapsTo (f l) (⨅ i, (f i).maxGenEigenspace (χ i)) (⨅ i, (f i).maxGenEigenspace (χ i)) := by intro x hx simp only [iInf_eq_iInter, mem_iInter, SetLike.mem_coe] at hx ⊢ exact fun i ↦ h l i (χ i) (hx i) classical suffices ∀ χ (s : Finset (ι → R)) (_ : χ ∉ s), Disjoint (⨅ i, (f i).maxGenEigenspace (χ i)) (s.sup fun (χ : ι → R) ↦ ⨅ i, (f i).maxGenEigenspace (χ i)) by simpa only [iSupIndep_iff_supIndep_of_injOn (injOn_iInf_maxGenEigenspace f), Finset.supIndep_iff_disjoint_erase] using fun s χ _ ↦ this _ _ (s.notMem_erase χ) intro χ₁ s induction s using Finset.induction_on with | empty => simp | insert χ₂ s _n ih => intro hχ₁₂ obtain ⟨hχ₁₂ : χ₁ ≠ χ₂, hχ₁ : χ₁ ∉ s⟩ := by rwa [Finset.mem_insert, not_or] at hχ₁₂ specialize ih hχ₁ rw [Finset.sup_insert, disjoint_iff, Submodule.eq_bot_iff] rintro x ⟨hx, hx'⟩ simp only [SetLike.mem_coe] at hx hx' suffices x ∈ ⨅ i, (f i).maxGenEigenspace (χ₂ i) by rw [← Submodule.mem_bot (R := R), ← (disjoint_iInf_maxGenEigenspace f hχ₁₂).eq_bot] exact ⟨hx, this⟩ obtain ⟨y, hy, z, hz, rfl⟩ := Submodule.mem_sup.mp hx'; clear hx' suffices ∀ l, ∃ (k : ℕ), ((f l - algebraMap R (Module.End R M) (χ₂ l)) ^ k) (y + z) ∈ (⨅ i, (f i).maxGenEigenspace (χ₁ i)) ⊓ Finset.sup s fun χ ↦ ⨅ i, (f i).maxGenEigenspace (χ i) by simpa [ih.eq_bot, Submodule.mem_bot] using this intro l let g : Module.End R M := f l - algebraMap R (Module.End R M) (χ₂ l) obtain ⟨k, hk : (g ^ k) y = 0⟩ := (mem_iInf_maxGenEigenspace_iff _ _ _).mp hy l have aux (f : End R M) (φ : R) (k : ℕ) (p : Submodule R M) (hp : MapsTo f p p) : MapsTo ((f - algebraMap R (Module.End R M) φ) ^ k) p p := by rw [Module.End.coe_pow] exact MapsTo.iterate (fun m hm ↦ p.sub_mem (hp hm) (p.smul_mem _ hm)) k refine ⟨k, Submodule.mem_inf.mp ⟨?_, ?_⟩⟩ · refine aux (f l) (χ₂ l) k (⨅ i, (f i).maxGenEigenspace (χ₁ i)) ?_ hx simp only [Submodule.coe_iInf] exact h l χ₁ · rw [map_add, hk, zero_add] suffices (s.sup fun χ ↦ (⨅ i, (f i).maxGenEigenspace (χ i))).map (g ^ k) ≤ s.sup fun χ ↦ (⨅ i, (f i).maxGenEigenspace (χ i)) from this (Submodule.mem_map_of_mem hz) simp_rw [Finset.sup_eq_iSup, Submodule.map_iSup (ι := ι → R), Submodule.map_iSup (ι := _ ∈ s)] refine iSup₂_mono fun χ _ ↦ ?_ rintro - ⟨u, hu, rfl⟩ refine aux (f l) (χ₂ l) k (⨅ i, (f i).maxGenEigenspace (χ i)) ?_ hu simp only [Submodule.coe_iInf] exact h l χ /-- Given a family of endomorphisms `i ↦ f i` which are compatible in the sense that every maximal generalised eigenspace of `f i` is invariant w.r.t. `f j`, if each `f i` is triangularizable, the family is simultaneously triangularizable. -/ lemma iSup_iInf_maxGenEigenspace_eq_top_of_forall_mapsTo [FiniteDimensional K M] (f : ι → End K M) (h : ∀ i j φ, MapsTo (f i) ((f j).maxGenEigenspace φ) ((f j).maxGenEigenspace φ)) (h' : ∀ i, ⨆ μ, (f i).maxGenEigenspace μ = ⊤) : ⨆ χ : ι → K, ⨅ i, (f i).maxGenEigenspace (χ i) = ⊤ := by generalize h_dim : finrank K M = n induction n using Nat.strongRecOn generalizing M with | ind n ih => ?_ obtain this | ⟨i : ι, hy : ¬ ∃ φ, (f i).maxGenEigenspace φ = ⊤⟩ := forall_or_exists_not (fun j : ι ↦ ∃ φ : K, (f j).maxGenEigenspace φ = ⊤) · choose χ hχ using this replace hχ : ⨅ i, (f i).maxGenEigenspace (χ i) = ⊤ := by simpa simp_rw [eq_top_iff] at hχ ⊢ exact le_trans hχ <| le_iSup (fun χ : ι → K ↦ ⨅ i, (f i).maxGenEigenspace (χ i)) χ · replace hy : ∀ φ, finrank K ((f i).maxGenEigenspace φ) < n := fun φ ↦ by simp_rw [not_exists, ← lt_top_iff_ne_top] at hy; exact h_dim ▸ Submodule.finrank_lt (hy φ).ne have hi (j : ι) (φ : K) : MapsTo (f j) ((f i).maxGenEigenspace φ) ((f i).maxGenEigenspace φ) := by exact h j i φ replace ih (φ : K) : ⨆ χ : ι → K, ⨅ j, maxGenEigenspace ((f j).restrict (hi j φ)) (χ j) = ⊤ := by apply ih _ (hy φ) · intro j k μ exact mapsTo_restrict_maxGenEigenspace_restrict_of_mapsTo (f j) (f k) _ _ (h j k μ) · exact fun j ↦ Module.End.genEigenspace_restrict_eq_top _ (h' j) · rfl replace ih (φ : K) : ⨆ (χ : ι → K) (_ : χ i = φ), ⨅ j, maxGenEigenspace ((f j).restrict (hi j φ)) (χ j) = ⊤ := by suffices ∀ χ : ι → K, χ i ≠ φ → ⨅ j, maxGenEigenspace ((f j).restrict (hi j φ)) (χ j) = ⊥ by specialize ih φ; rw [iSup_split, biSup_congr this] at ih; simpa using ih intro χ hχ rw [eq_bot_iff, ← ((f i).maxGenEigenspace φ).ker_subtype, LinearMap.ker, ← Submodule.map_le_iff_le_comap, ← Submodule.inf_iInf_maxGenEigenspace_of_forall_mapsTo, ← disjoint_iff_inf_le] exact ((f i).disjoint_genEigenspace hχ.symm _ _).mono_right (iInf_le _ i) replace ih (φ : K) : ⨆ (χ : ι → K) (_ : χ i = φ), ⨅ j, maxGenEigenspace (f j) (χ j) = maxGenEigenspace (f i) φ := by have (χ : ι → K) (hχ : χ i = φ) : ⨅ j, maxGenEigenspace (f j) (χ j) = (⨅ j, maxGenEigenspace ((f j).restrict (hi j φ)) (χ j)).map ((f i).maxGenEigenspace φ).subtype := by rw [← hχ, iInf_maxGenEigenspace_restrict_map_subtype_eq] simp_rw [biSup_congr this, ← Submodule.map_iSup, ih, Submodule.map_top, Submodule.range_subtype] simpa only [← ih, iSup_comm (ι := K), iSup_iSup_eq_right] using h' i /-- A commuting family of triangularizable endomorphisms is simultaneously triangularizable. -/ theorem iSup_iInf_maxGenEigenspace_eq_top_of_iSup_maxGenEigenspace_eq_top_of_commute [FiniteDimensional K M] (f : ι → Module.End K M) (h : Pairwise fun i j ↦ Commute (f i) (f j)) (h' : ∀ i, ⨆ μ, (f i).maxGenEigenspace μ = ⊤) : ⨆ χ : ι → K, ⨅ i, (f i).maxGenEigenspace (χ i) = ⊤ := by refine Module.End.iSup_iInf_maxGenEigenspace_eq_top_of_forall_mapsTo _ (fun i j ↦ Module.End.mapsTo_maxGenEigenspace_of_comm ?_) h' rcases eq_or_ne j i with rfl | hij <;> tauto end Module.End
.lake/packages/mathlib/Mathlib/LinearAlgebra/Eigenspace/Basic.lean
import Mathlib.Algebra.Algebra.Spectrum.Basic import Mathlib.Algebra.Module.LinearMap.Basic import Mathlib.LinearAlgebra.FiniteDimensional.Lemmas import Mathlib.LinearAlgebra.GeneralLinearGroup import Mathlib.RingTheory.Nilpotent.Basic import Mathlib.RingTheory.Nilpotent.Defs import Mathlib.RingTheory.Nilpotent.Lemmas import Mathlib.Tactic.Peel /-! # Eigenvectors and eigenvalues This file defines eigenspaces, eigenvalues, and eigenvectors, as well as their generalized counterparts. We follow Axler's approach [axler2015] because it allows us to derive many properties without choosing a basis and without using matrices. An eigenspace of a linear map `f` for a scalar `μ` is the kernel of the map `(f - μ • id)`. The nonzero elements of an eigenspace are eigenvectors `x`. They have the property `f x = μ • x`. If there are eigenvectors for a scalar `μ`, the scalar `μ` is called an eigenvalue. There is no consensus in the literature whether `0` is an eigenvector. Our definition of `HasEigenvector` permits only nonzero vectors. For an eigenvector `x` that may also be `0`, we write `x ∈ f.eigenspace μ`. A generalized eigenspace of a linear map `f` for a natural number `k` and a scalar `μ` is the kernel of the map `(f - μ • id) ^ k`. The nonzero elements of a generalized eigenspace are generalized eigenvectors `x`. If there are generalized eigenvectors for a natural number `k` and a scalar `μ`, the scalar `μ` is called a generalized eigenvalue. The fact that the eigenvalues are the roots of the minimal polynomial is proved in `LinearAlgebra.Eigenspace.Minpoly`. The existence of eigenvalues over an algebraically closed field (and the fact that the generalized eigenspaces then span) is deferred to `LinearAlgebra.Eigenspace.IsAlgClosed`. ## References * [Sheldon Axler, *Linear Algebra Done Right*][axler2015] * https://en.wikipedia.org/wiki/Eigenvalues_and_eigenvectors ## Tags eigenspace, eigenvector, eigenvalue, eigen -/ universe u v w namespace Module namespace End open Module Set variable {K R : Type v} {V M : Type w} [CommRing R] [AddCommGroup M] [Module R M] [Field K] [AddCommGroup V] [Module K V] /-- The submodule `genEigenspace f μ k` for a linear map `f`, a scalar `μ`, and a number `k : ℕ∞` is the kernel of `(f - μ • id) ^ k` if `k` is a natural number (see Def 8.10 of [axler2015]), or the union of all these kernels if `k = ∞`. A generalized eigenspace for some exponent `k` is contained in the generalized eigenspace for exponents larger than `k`. -/ def genEigenspace (f : End R M) (μ : R) : ℕ∞ →o Submodule R M where toFun k := ⨆ l : ℕ, ⨆ _ : l ≤ k, LinearMap.ker ((f - μ • 1) ^ l) monotone' _ _ hkl := biSup_mono fun _ hi ↦ hi.trans hkl lemma mem_genEigenspace {f : End R M} {μ : R} {k : ℕ∞} {x : M} : x ∈ f.genEigenspace μ k ↔ ∃ l : ℕ, l ≤ k ∧ x ∈ LinearMap.ker ((f - μ • 1) ^ l) := by have : Nonempty {l : ℕ // l ≤ k} := ⟨⟨0, zero_le _⟩⟩ have : Directed (ι := { i : ℕ // i ≤ k }) (· ≤ ·) fun i ↦ LinearMap.ker ((f - μ • 1) ^ (i : ℕ)) := Monotone.directed_le fun m n h ↦ by simpa using (f - μ • 1).iterateKer.monotone h simp_rw [genEigenspace, OrderHom.coe_mk, LinearMap.mem_ker, iSup_subtype', Submodule.mem_iSup_of_directed _ this, LinearMap.mem_ker, Subtype.exists, exists_prop] lemma genEigenspace_directed {f : End R M} {μ : R} {k : ℕ∞} : Directed (· ≤ ·) (fun l : {l : ℕ // l ≤ k} ↦ f.genEigenspace μ l) := by have aux : Monotone ((↑) : {l : ℕ // l ≤ k} → ℕ∞) := fun x y h ↦ by simpa using h exact ((genEigenspace f μ).monotone.comp aux).directed_le lemma mem_genEigenspace_nat {f : End R M} {μ : R} {k : ℕ} {x : M} : x ∈ f.genEigenspace μ k ↔ x ∈ LinearMap.ker ((f - μ • 1) ^ k) := by rw [mem_genEigenspace] constructor · rintro ⟨l, hl, hx⟩ simp only [Nat.cast_le] at hl exact (f - μ • 1).iterateKer.monotone hl hx · intro hx exact ⟨k, le_rfl, hx⟩ lemma mem_genEigenspace_top {f : End R M} {μ : R} {x : M} : x ∈ f.genEigenspace μ ⊤ ↔ ∃ k : ℕ, x ∈ LinearMap.ker ((f - μ • 1) ^ k) := by simp [mem_genEigenspace] lemma genEigenspace_nat {f : End R M} {μ : R} {k : ℕ} : f.genEigenspace μ k = LinearMap.ker ((f - μ • 1) ^ k) := by ext; simp [mem_genEigenspace_nat] lemma genEigenspace_eq_iSup_genEigenspace_nat (f : End R M) (μ : R) (k : ℕ∞) : f.genEigenspace μ k = ⨆ l : {l : ℕ // l ≤ k}, f.genEigenspace μ l := by simp_rw [genEigenspace_nat, genEigenspace, OrderHom.coe_mk, iSup_subtype] lemma genEigenspace_top (f : End R M) (μ : R) : f.genEigenspace μ ⊤ = ⨆ k : ℕ, f.genEigenspace μ k := by rw [genEigenspace_eq_iSup_genEigenspace_nat, iSup_subtype] simp only [le_top, iSup_pos] lemma genEigenspace_one {f : End R M} {μ : R} : f.genEigenspace μ 1 = LinearMap.ker (f - μ • 1) := by rw [← Nat.cast_one, genEigenspace_nat, pow_one] @[simp] lemma mem_genEigenspace_one {f : End R M} {μ : R} {x : M} : x ∈ f.genEigenspace μ 1 ↔ f x = μ • x := by rw [genEigenspace_one, LinearMap.mem_ker, LinearMap.sub_apply, sub_eq_zero, LinearMap.smul_apply, Module.End.one_apply] -- `simp` can prove this using `genEigenspace_zero` lemma mem_genEigenspace_zero {f : End R M} {μ : R} {x : M} : x ∈ f.genEigenspace μ 0 ↔ x = 0 := by rw [← Nat.cast_zero, mem_genEigenspace_nat, pow_zero, LinearMap.mem_ker, Module.End.one_apply] @[simp] lemma genEigenspace_zero {f : End R M} {μ : R} : f.genEigenspace μ 0 = ⊥ := by ext; apply mem_genEigenspace_zero @[simp] lemma genEigenspace_zero_nat (f : End R M) (k : ℕ) : f.genEigenspace 0 k = LinearMap.ker (f ^ k) := by ext; simp [mem_genEigenspace_nat] /-- Let `M` be an `R`-module, and `f` an `R`-linear endomorphism of `M`, and let `μ : R` and `k : ℕ∞` be given. Then `x : M` satisfies `HasUnifEigenvector f μ k x` if `x ∈ f.genEigenspace μ k` and `x ≠ 0`. For `k = 1`, this means that `x` is an eigenvector of `f` with eigenvalue `μ`. -/ def HasUnifEigenvector (f : End R M) (μ : R) (k : ℕ∞) (x : M) : Prop := x ∈ f.genEigenspace μ k ∧ x ≠ 0 /-- Let `M` be an `R`-module, and `f` an `R`-linear endomorphism of `M`. Then `μ : R` and `k : ℕ∞` satisfy `HasUnifEigenvalue f μ k` if `f.genEigenspace μ k ≠ ⊥`. For `k = 1`, this means that `μ` is an eigenvalue of `f`. -/ def HasUnifEigenvalue (f : End R M) (μ : R) (k : ℕ∞) : Prop := f.genEigenspace μ k ≠ ⊥ /-- Let `M` be an `R`-module, and `f` an `R`-linear endomorphism of `M`. For `k : ℕ∞`, we define `UnifEigenvalues f k` to be the type of all `μ : R` that satisfy `f.HasUnifEigenvalue μ k`. For `k = 1` this is the type of all eigenvalues of `f`. -/ def UnifEigenvalues (f : End R M) (k : ℕ∞) : Type _ := { μ : R // f.HasUnifEigenvalue μ k } /-- The underlying value of a bundled eigenvalue. -/ @[coe] def UnifEigenvalues.val (f : Module.End R M) (k : ℕ∞) : UnifEigenvalues f k → R := Subtype.val instance UnifEigenvalues.instCoeOut {f : Module.End R M} (k : ℕ∞) : CoeOut (UnifEigenvalues f k) R where coe := UnifEigenvalues.val f k instance UnivEigenvalues.instDecidableEq [DecidableEq R] (f : Module.End R M) (k : ℕ∞) : DecidableEq (UnifEigenvalues f k) := inferInstanceAs (DecidableEq (Subtype (fun x : R ↦ f.HasUnifEigenvalue x k))) lemma HasUnifEigenvector.hasUnifEigenvalue {f : End R M} {μ : R} {k : ℕ∞} {x : M} (h : f.HasUnifEigenvector μ k x) : f.HasUnifEigenvalue μ k := by rw [HasUnifEigenvalue, Submodule.ne_bot_iff] use x; exact h lemma HasUnifEigenvector.apply_eq_smul {f : End R M} {μ : R} {x : M} (hx : f.HasUnifEigenvector μ 1 x) : f x = μ • x := mem_genEigenspace_one.mp hx.1 lemma HasUnifEigenvector.pow_apply {f : End R M} {μ : R} {v : M} (hv : f.HasUnifEigenvector μ 1 v) (n : ℕ) : (f ^ n) v = μ ^ n • v := by induction n <;> simp [*, pow_succ f, hv.apply_eq_smul, smul_smul, pow_succ' μ] theorem HasUnifEigenvalue.exists_hasUnifEigenvector {f : End R M} {μ : R} {k : ℕ∞} (hμ : f.HasUnifEigenvalue μ k) : ∃ v, f.HasUnifEigenvector μ k v := Submodule.exists_mem_ne_zero_of_ne_bot hμ lemma HasUnifEigenvalue.pow {f : End R M} {μ : R} (h : f.HasUnifEigenvalue μ 1) (n : ℕ) : (f ^ n).HasUnifEigenvalue (μ ^ n) 1 := by rw [HasUnifEigenvalue, Submodule.ne_bot_iff] obtain ⟨m : M, hm⟩ := h.exists_hasUnifEigenvector exact ⟨m, by simpa [mem_genEigenspace_one] using hm.pow_apply n, hm.2⟩ /-- A nilpotent endomorphism has nilpotent eigenvalues. See also `LinearMap.isNilpotent_trace_of_isNilpotent`. -/ lemma HasUnifEigenvalue.isNilpotent_of_isNilpotent [NoZeroSMulDivisors R M] {f : End R M} (hfn : IsNilpotent f) {μ : R} (hf : f.HasUnifEigenvalue μ 1) : IsNilpotent μ := by obtain ⟨m : M, hm⟩ := hf.exists_hasUnifEigenvector obtain ⟨n : ℕ, hn : f ^ n = 0⟩ := hfn exact ⟨n, by simpa [hn, hm.2, eq_comm (a := (0 : M))] using hm.pow_apply n⟩ lemma HasUnifEigenvalue.mem_spectrum {f : End R M} {μ : R} (hμ : HasUnifEigenvalue f μ 1) : μ ∈ spectrum R f := by refine spectrum.mem_iff.mpr fun h_unit ↦ ?_ set f' := LinearMap.GeneralLinearGroup.toLinearEquiv h_unit.unit rcases hμ.exists_hasUnifEigenvector with ⟨v, hv⟩ refine hv.2 ((LinearMap.ker_eq_bot'.mp f'.ker) v (?_ : μ • v - f v = 0)) rw [hv.apply_eq_smul, sub_self] lemma hasUnifEigenvalue_iff_mem_spectrum [FiniteDimensional K V] {f : End K V} {μ : K} : f.HasUnifEigenvalue μ 1 ↔ μ ∈ spectrum K f := by rw [spectrum.mem_iff, IsUnit.sub_iff, LinearMap.isUnit_iff_ker_eq_bot, HasUnifEigenvalue, genEigenspace_one, ne_eq, not_iff_not] simp [Submodule.ext_iff, LinearMap.mem_ker] alias ⟨_, HasUnifEigenvalue.of_mem_spectrum⟩ := hasUnifEigenvalue_iff_mem_spectrum lemma genEigenspace_div (f : End K V) (a b : K) (hb : b ≠ 0) : genEigenspace f (a / b) 1 = LinearMap.ker (b • f - a • 1) := calc genEigenspace f (a / b) 1 = genEigenspace f (b⁻¹ * a) 1 := by rw [div_eq_mul_inv, mul_comm] _ = LinearMap.ker (f - (b⁻¹ * a) • 1) := by rw [genEigenspace_one] _ = LinearMap.ker (f - b⁻¹ • a • 1) := by rw [smul_smul] _ = LinearMap.ker (b • (f - b⁻¹ • a • 1)) := by rw [LinearMap.ker_smul _ b hb] _ = LinearMap.ker (b • f - a • 1) := by rw [smul_sub, smul_inv_smul₀ hb] /-- The generalized eigenrange for a linear map `f`, a scalar `μ`, and an exponent `k ∈ ℕ∞` is the range of `(f - μ • id) ^ k` if `k` is a natural number, or the infimum of these ranges if `k = ∞`. -/ def genEigenrange (f : End R M) (μ : R) (k : ℕ∞) : Submodule R M := ⨅ l : ℕ, ⨅ (_ : l ≤ k), LinearMap.range ((f - μ • 1) ^ l) lemma genEigenrange_nat {f : End R M} {μ : R} {k : ℕ} : f.genEigenrange μ k = LinearMap.range ((f - μ • 1) ^ k) := by ext x simp only [genEigenrange, Nat.cast_le, Submodule.mem_iInf, LinearMap.mem_range] constructor · intro h exact h _ le_rfl · rintro ⟨x, rfl⟩ i hi have : k = i + (k - i) := by omega rw [this, pow_add] exact ⟨_, rfl⟩ /-- The exponent of a generalized eigenvalue is never 0. -/ lemma HasUnifEigenvalue.exp_ne_zero {f : End R M} {μ : R} {k : ℕ} (h : f.HasUnifEigenvalue μ k) : k ≠ 0 := by rintro rfl simp [HasUnifEigenvalue, Nat.cast_zero, genEigenspace_zero] at h /-- If there exists a natural number `k` such that the kernel of `(f - μ • id) ^ k` is the maximal generalized eigenspace, then this value is the least such `k`. If not, this value is not meaningful. -/ noncomputable def maxUnifEigenspaceIndex (f : End R M) (μ : R) := monotonicSequenceLimitIndex <| (f.genEigenspace μ).comp <| WithTop.coeOrderHom.toOrderHom /-- For an endomorphism of a Noetherian module, the maximal eigenspace is always of the form kernel `(f - μ • id) ^ k` for some `k`. -/ lemma genEigenspace_top_eq_maxUnifEigenspaceIndex [IsNoetherian R M] (f : End R M) (μ : R) : genEigenspace f μ ⊤ = f.genEigenspace μ (maxUnifEigenspaceIndex f μ) := by have := WellFoundedGT.iSup_eq_monotonicSequenceLimit <| (f.genEigenspace μ).comp <| WithTop.coeOrderHom.toOrderHom convert this using 1 simp only [genEigenspace, OrderHom.coe_mk, le_top, iSup_pos, OrderHom.comp_coe, Function.comp_def] rw [iSup_prod', iSup_subtype', ← sSup_range, ← sSup_range] congr 1 aesop lemma genEigenspace_le_genEigenspace_maxUnifEigenspaceIndex [IsNoetherian R M] (f : End R M) (μ : R) (k : ℕ∞) : f.genEigenspace μ k ≤ f.genEigenspace μ (maxUnifEigenspaceIndex f μ) := by rw [← genEigenspace_top_eq_maxUnifEigenspaceIndex] exact (f.genEigenspace μ).monotone le_top /-- Generalized eigenspaces for exponents at least `finrank K V` are equal to each other. -/ theorem genEigenspace_eq_genEigenspace_maxUnifEigenspaceIndex_of_le [IsNoetherian R M] (f : End R M) (μ : R) {k : ℕ} (hk : maxUnifEigenspaceIndex f μ ≤ k) : f.genEigenspace μ k = f.genEigenspace μ (maxUnifEigenspaceIndex f μ) := le_antisymm (genEigenspace_le_genEigenspace_maxUnifEigenspaceIndex _ _ _) ((f.genEigenspace μ).monotone <| by simpa using hk) /-- A generalized eigenvalue for some exponent `k` is also a generalized eigenvalue for exponents larger than `k`. -/ lemma HasUnifEigenvalue.le {f : End R M} {μ : R} {k m : ℕ∞} (hm : k ≤ m) (hk : f.HasUnifEigenvalue μ k) : f.HasUnifEigenvalue μ m := by unfold HasUnifEigenvalue at * contrapose! hk rw [← le_bot_iff, ← hk] exact (f.genEigenspace _).monotone hm /-- A generalized eigenvalue for some exponent `k` is also a generalized eigenvalue for positive exponents. -/ lemma HasUnifEigenvalue.lt {f : End R M} {μ : R} {k m : ℕ∞} (hm : 0 < m) (hk : f.HasUnifEigenvalue μ k) : f.HasUnifEigenvalue μ m := by apply HasUnifEigenvalue.le (k := 1) (Order.one_le_iff_pos.mpr hm) intro contra; apply hk rw [genEigenspace_one, LinearMap.ker_eq_bot] at contra rw [eq_bot_iff] intro x hx rw [mem_genEigenspace] at hx rcases hx with ⟨l, -, hx⟩ rwa [LinearMap.ker_eq_bot.mpr] at hx rw [Module.End.coe_pow (f - μ • 1) l] exact Function.Injective.iterate contra l /-- Generalized eigenvalues are actually just eigenvalues. -/ @[simp] lemma hasUnifEigenvalue_iff_hasUnifEigenvalue_one {f : End R M} {μ : R} {k : ℕ∞} (hk : 0 < k) : f.HasUnifEigenvalue μ k ↔ f.HasUnifEigenvalue μ 1 := ⟨HasUnifEigenvalue.lt zero_lt_one, HasUnifEigenvalue.lt hk⟩ lemma maxUnifEigenspaceIndex_le_finrank [FiniteDimensional K V] (f : End K V) (μ : K) : maxUnifEigenspaceIndex f μ ≤ finrank K V := by apply Nat.sInf_le intro n hn apply le_antisymm · exact (f.genEigenspace μ).monotone <| WithTop.coeOrderHom.monotone hn · change (f.genEigenspace μ) n ≤ (f.genEigenspace μ) (finrank K V) rw [genEigenspace_nat, genEigenspace_nat] apply ker_pow_le_ker_pow_finrank /-- Every generalized eigenvector is a generalized eigenvector for exponent `finrank K V`. (Lemma 8.11 of [axler2015]) -/ lemma genEigenspace_le_genEigenspace_finrank [FiniteDimensional K V] (f : End K V) (μ : K) (k : ℕ∞) : f.genEigenspace μ k ≤ f.genEigenspace μ (finrank K V) := by calc f.genEigenspace μ k ≤ f.genEigenspace μ ⊤ := (f.genEigenspace _).monotone le_top _ ≤ f.genEigenspace μ (finrank K V) := by rw [genEigenspace_top_eq_maxUnifEigenspaceIndex] exact (f.genEigenspace _).monotone <| by simpa using maxUnifEigenspaceIndex_le_finrank f μ /-- Generalized eigenspaces for exponents at least `finrank K V` are equal to each other. -/ theorem genEigenspace_eq_genEigenspace_finrank_of_le [FiniteDimensional K V] (f : End K V) (μ : K) {k : ℕ} (hk : finrank K V ≤ k) : f.genEigenspace μ k = f.genEigenspace μ (finrank K V) := le_antisymm (genEigenspace_le_genEigenspace_finrank _ _ _) ((f.genEigenspace μ).monotone <| by simpa using hk) lemma mapsTo_genEigenspace_of_comm {f g : End R M} (h : Commute f g) (μ : R) (k : ℕ∞) : MapsTo g (f.genEigenspace μ k) (f.genEigenspace μ k) := by intro x hx simp only [SetLike.mem_coe, mem_genEigenspace, LinearMap.mem_ker] at hx ⊢ rcases hx with ⟨l, hl, hx⟩ replace h : Commute ((f - μ • (1 : End R M)) ^ l) g := (h.sub_left <| Algebra.commute_algebraMap_left μ g).pow_left l use l, hl rw [← LinearMap.comp_apply, ← Module.End.mul_eq_comp, h.eq, Module.End.mul_eq_comp, LinearMap.comp_apply, hx, map_zero] /-- The restriction of `f - μ • 1` to the `k`-fold generalized `μ`-eigenspace is nilpotent. -/ lemma isNilpotent_restrict_genEigenspace_nat (f : End R M) (μ : R) (k : ℕ) (h : MapsTo (f - μ • (1 : End R M)) (f.genEigenspace μ k) (f.genEigenspace μ k) := mapsTo_genEigenspace_of_comm (Algebra.mul_sub_algebraMap_commutes f μ) μ k) : IsNilpotent ((f - μ • 1).restrict h) := by use k ext ⟨x, hx⟩ rw [mem_genEigenspace_nat] at hx rw [LinearMap.zero_apply, ZeroMemClass.coe_zero, ZeroMemClass.coe_eq_zero, Module.End.pow_restrict, LinearMap.restrict_apply] ext simpa /-- The restriction of `f - μ • 1` to the generalized `μ`-eigenspace is nilpotent. -/ lemma isNilpotent_restrict_genEigenspace_top [IsNoetherian R M] (f : End R M) (μ : R) (h : MapsTo (f - μ • (1 : End R M)) (f.genEigenspace μ ⊤) (f.genEigenspace μ ⊤) := mapsTo_genEigenspace_of_comm (Algebra.mul_sub_algebraMap_commutes f μ) μ _) : IsNilpotent ((f - μ • 1).restrict h) := by apply isNilpotent_restrict_of_le on_goal 2 => apply isNilpotent_restrict_genEigenspace_nat f μ (maxUnifEigenspaceIndex f μ) rw [genEigenspace_top_eq_maxUnifEigenspaceIndex] /-- The submodule `eigenspace f μ` for a linear map `f` and a scalar `μ` consists of all vectors `x` such that `f x = μ • x`. (Def 5.36 of [axler2015]). -/ abbrev eigenspace (f : End R M) (μ : R) : Submodule R M := f.genEigenspace μ 1 lemma eigenspace_def {f : End R M} {μ : R} : f.eigenspace μ = LinearMap.ker (f - μ • 1) := by rw [eigenspace, genEigenspace_one] @[simp] theorem eigenspace_zero (f : End R M) : f.eigenspace 0 = LinearMap.ker f := by simp only [eigenspace, ← Nat.cast_one (R := ℕ∞), genEigenspace_zero_nat, pow_one] /-- A nonzero element of an eigenspace is an eigenvector. (Def 5.7 of [axler2015]) -/ abbrev HasEigenvector (f : End R M) (μ : R) (x : M) : Prop := HasUnifEigenvector f μ 1 x lemma hasEigenvector_iff {f : End R M} {μ : R} {x : M} : f.HasEigenvector μ x ↔ x ∈ f.eigenspace μ ∧ x ≠ 0 := Iff.rfl /-- A scalar `μ` is an eigenvalue for a linear map `f` if there are nonzero vectors `x` such that `f x = μ • x`. (Def 5.5 of [axler2015]). -/ abbrev HasEigenvalue (f : End R M) (a : R) : Prop := HasUnifEigenvalue f a 1 lemma hasEigenvalue_iff {f : End R M} {μ : R} : f.HasEigenvalue μ ↔ f.eigenspace μ ≠ ⊥ := Iff.rfl /-- The eigenvalues of the endomorphism `f`, as a subtype of `R`. -/ abbrev Eigenvalues (f : End R M) : Type _ := UnifEigenvalues f 1 @[coe] abbrev Eigenvalues.val (f : Module.End R M) : Eigenvalues f → R := UnifEigenvalues.val f 1 theorem hasEigenvalue_of_hasEigenvector {f : End R M} {μ : R} {x : M} (h : HasEigenvector f μ x) : HasEigenvalue f μ := h.hasUnifEigenvalue theorem mem_eigenspace_iff {f : End R M} {μ : R} {x : M} : x ∈ eigenspace f μ ↔ f x = μ • x := mem_genEigenspace_one nonrec theorem HasEigenvector.apply_eq_smul {f : End R M} {μ : R} {x : M} (hx : f.HasEigenvector μ x) : f x = μ • x := hx.apply_eq_smul nonrec theorem HasEigenvector.pow_apply {f : End R M} {μ : R} {v : M} (hv : f.HasEigenvector μ v) (n : ℕ) : (f ^ n) v = μ ^ n • v := hv.pow_apply n theorem HasEigenvalue.exists_hasEigenvector {f : End R M} {μ : R} (hμ : f.HasEigenvalue μ) : ∃ v, f.HasEigenvector μ v := Submodule.exists_mem_ne_zero_of_ne_bot hμ nonrec lemma HasEigenvalue.pow {f : End R M} {μ : R} (h : f.HasEigenvalue μ) (n : ℕ) : (f ^ n).HasEigenvalue (μ ^ n) := h.pow n /-- A nilpotent endomorphism has nilpotent eigenvalues. See also `LinearMap.isNilpotent_trace_of_isNilpotent`. -/ nonrec lemma HasEigenvalue.isNilpotent_of_isNilpotent [NoZeroSMulDivisors R M] {f : End R M} (hfn : IsNilpotent f) {μ : R} (hf : f.HasEigenvalue μ) : IsNilpotent μ := hf.isNilpotent_of_isNilpotent hfn nonrec theorem HasEigenvalue.mem_spectrum {f : End R M} {μ : R} (hμ : HasEigenvalue f μ) : μ ∈ spectrum R f := hμ.mem_spectrum theorem hasEigenvalue_iff_mem_spectrum [FiniteDimensional K V] {f : End K V} {μ : K} : f.HasEigenvalue μ ↔ μ ∈ spectrum K f := hasUnifEigenvalue_iff_mem_spectrum alias ⟨_, HasEigenvalue.of_mem_spectrum⟩ := hasEigenvalue_iff_mem_spectrum theorem eigenspace_div (f : End K V) (a b : K) (hb : b ≠ 0) : eigenspace f (a / b) = LinearMap.ker (b • f - algebraMap K (End K V) a) := genEigenspace_div f a b hb /-- A nonzero element of a generalized eigenspace is a generalized eigenvector. (Def 8.9 of [axler2015]) -/ abbrev HasGenEigenvector (f : End R M) (μ : R) (k : ℕ) (x : M) : Prop := HasUnifEigenvector f μ k x lemma hasGenEigenvector_iff {f : End R M} {μ : R} {k : ℕ} {x : M} : f.HasGenEigenvector μ k x ↔ x ∈ f.genEigenspace μ k ∧ x ≠ 0 := Iff.rfl /-- A scalar `μ` is a generalized eigenvalue for a linear map `f` and an exponent `k ∈ ℕ` if there are generalized eigenvectors for `f`, `k`, and `μ`. -/ abbrev HasGenEigenvalue (f : End R M) (μ : R) (k : ℕ) : Prop := HasUnifEigenvalue f μ k lemma hasGenEigenvalue_iff {f : End R M} {μ : R} {k : ℕ} : f.HasGenEigenvalue μ k ↔ f.genEigenspace μ k ≠ ⊥ := Iff.rfl /-- The exponent of a generalized eigenvalue is never 0. -/ theorem exp_ne_zero_of_hasGenEigenvalue {f : End R M} {μ : R} {k : ℕ} (h : f.HasGenEigenvalue μ k) : k ≠ 0 := HasUnifEigenvalue.exp_ne_zero h /-- The union of the kernels of `(f - μ • id) ^ k` over all `k`. -/ abbrev maxGenEigenspace (f : End R M) (μ : R) : Submodule R M := genEigenspace f μ ⊤ lemma iSup_genEigenspace_eq (f : End R M) (μ : R) : ⨆ k : ℕ, (f.genEigenspace μ) k = f.maxGenEigenspace μ := by simp_rw [maxGenEigenspace, genEigenspace_top] theorem genEigenspace_le_maximal (f : End R M) (μ : R) (k : ℕ) : f.genEigenspace μ k ≤ f.maxGenEigenspace μ := (f.genEigenspace μ).monotone le_top @[simp] theorem mem_maxGenEigenspace (f : End R M) (μ : R) (m : M) : m ∈ f.maxGenEigenspace μ ↔ ∃ k : ℕ, ((f - μ • (1 : End R M)) ^ k) m = 0 := mem_genEigenspace_top /-- If there exists a natural number `k` such that the kernel of `(f - μ • id) ^ k` is the maximal generalized eigenspace, then this value is the least such `k`. If not, this value is not meaningful. -/ noncomputable abbrev maxGenEigenspaceIndex (f : End R M) (μ : R) := maxUnifEigenspaceIndex f μ /-- For an endomorphism of a Noetherian module, the maximal eigenspace is always of the form kernel `(f - μ • id) ^ k` for some `k`. -/ theorem maxGenEigenspace_eq [IsNoetherian R M] (f : End R M) (μ : R) : maxGenEigenspace f μ = f.genEigenspace μ (maxGenEigenspaceIndex f μ) := genEigenspace_top_eq_maxUnifEigenspaceIndex _ _ theorem maxGenEigenspace_eq_maxGenEigenspace_zero (f : End R M) (μ : R) : maxGenEigenspace f μ = maxGenEigenspace (f - μ • 1) 0 := by ext; simp /-- A generalized eigenvalue for some exponent `k` is also a generalized eigenvalue for exponents larger than `k`. -/ theorem hasGenEigenvalue_of_hasGenEigenvalue_of_le {f : End R M} {μ : R} {k : ℕ} {m : ℕ} (hm : k ≤ m) (hk : f.HasGenEigenvalue μ k) : f.HasGenEigenvalue μ m := hk.le <| by simpa using hm /-- The eigenspace is a subspace of the generalized eigenspace. -/ theorem eigenspace_le_genEigenspace {f : End R M} {μ : R} {k : ℕ} (hk : 0 < k) : f.eigenspace μ ≤ f.genEigenspace μ k := (f.genEigenspace _).monotone <| by simpa using Nat.succ_le_of_lt hk theorem eigenspace_le_maxGenEigenspace {f : End R M} {μ : R} : f.eigenspace μ ≤ f.maxGenEigenspace μ := (f.genEigenspace _).monotone <| OrderTop.le_top _ /-- All eigenvalues are generalized eigenvalues. -/ theorem hasGenEigenvalue_of_hasEigenvalue {f : End R M} {μ : R} {k : ℕ} (hk : 0 < k) (hμ : f.HasEigenvalue μ) : f.HasGenEigenvalue μ k := hμ.lt <| by simpa using hk /-- All generalized eigenvalues are eigenvalues. -/ theorem hasEigenvalue_of_hasGenEigenvalue {f : End R M} {μ : R} {k : ℕ} (hμ : f.HasGenEigenvalue μ k) : f.HasEigenvalue μ := hμ.lt zero_lt_one /-- Generalized eigenvalues are actually just eigenvalues. -/ theorem hasGenEigenvalue_iff_hasEigenvalue {f : End R M} {μ : R} {k : ℕ} (hk : 0 < k) : f.HasGenEigenvalue μ k ↔ f.HasEigenvalue μ := by simp [hk] theorem maxGenEigenspace_eq_genEigenspace_finrank [FiniteDimensional K V] (f : End K V) (μ : K) : f.maxGenEigenspace μ = f.genEigenspace μ (finrank K V) := by apply le_antisymm _ <| (f.genEigenspace μ).monotone le_top rw [genEigenspace_top_eq_maxUnifEigenspaceIndex] apply genEigenspace_le_genEigenspace_finrank f μ lemma mapsTo_maxGenEigenspace_of_comm {f g : End R M} (h : Commute f g) (μ : R) : MapsTo g ↑(f.maxGenEigenspace μ) ↑(f.maxGenEigenspace μ) := mapsTo_genEigenspace_of_comm h μ ⊤ /-- The restriction of `f - μ • 1` to the `k`-fold generalized `μ`-eigenspace is nilpotent. -/ lemma isNilpotent_restrict_sub_algebraMap (f : End R M) (μ : R) (k : ℕ) (h : MapsTo (f - algebraMap R (End R M) μ) (f.genEigenspace μ k) (f.genEigenspace μ k) := mapsTo_genEigenspace_of_comm (Algebra.mul_sub_algebraMap_commutes f μ) μ k) : IsNilpotent ((f - algebraMap R (End R M) μ).restrict h) := isNilpotent_restrict_genEigenspace_nat _ _ _ /-- The restriction of `f - μ • 1` to the generalized `μ`-eigenspace is nilpotent. -/ lemma isNilpotent_restrict_maxGenEigenspace_sub_algebraMap [IsNoetherian R M] (f : End R M) (μ : R) (h : MapsTo (f - algebraMap R (End R M) μ) ↑(f.maxGenEigenspace μ) ↑(f.maxGenEigenspace μ) := mapsTo_maxGenEigenspace_of_comm (Algebra.mul_sub_algebraMap_commutes f μ) μ) : IsNilpotent ((f - algebraMap R (End R M) μ).restrict h) := by apply isNilpotent_restrict_of_le (q := f.genEigenspace μ (maxUnifEigenspaceIndex f μ)) _ (isNilpotent_restrict_genEigenspace_nat f μ (maxUnifEigenspaceIndex f μ)) rw [maxGenEigenspace_eq] lemma disjoint_genEigenspace [NoZeroSMulDivisors R M] (f : End R M) {μ₁ μ₂ : R} (hμ : μ₁ ≠ μ₂) (k l : ℕ∞) : Disjoint (f.genEigenspace μ₁ k) (f.genEigenspace μ₂ l) := by rw [genEigenspace_eq_iSup_genEigenspace_nat, genEigenspace_eq_iSup_genEigenspace_nat] simp_rw [genEigenspace_directed.disjoint_iSup_left, genEigenspace_directed.disjoint_iSup_right] rintro ⟨k, -⟩ ⟨l, -⟩ nontriviality M have := NoZeroSMulDivisors.isReduced R M rw [disjoint_iff] set p := f.genEigenspace μ₁ k ⊓ f.genEigenspace μ₂ l by_contra hp replace hp : Nontrivial p := Submodule.nontrivial_iff_ne_bot.mpr hp let f₁ : End R p := (f - algebraMap R (End R M) μ₁).restrict <| MapsTo.inter_inter (mapsTo_genEigenspace_of_comm (Algebra.mul_sub_algebraMap_commutes f μ₁) μ₁ k) (mapsTo_genEigenspace_of_comm (Algebra.mul_sub_algebraMap_commutes f μ₁) μ₂ l) let f₂ : End R p := (f - algebraMap R (End R M) μ₂).restrict <| MapsTo.inter_inter (mapsTo_genEigenspace_of_comm (Algebra.mul_sub_algebraMap_commutes f μ₂) μ₁ k) (mapsTo_genEigenspace_of_comm (Algebra.mul_sub_algebraMap_commutes f μ₂) μ₂ l) have : IsNilpotent (f₂ - f₁) := by apply Commute.isNilpotent_sub (x := f₂) (y := f₁) _ (isNilpotent_restrict_of_le inf_le_right _) (isNilpotent_restrict_of_le inf_le_left _) · ext; simp [f₁, f₂, smul_sub, sub_sub, smul_comm μ₁, add_sub_left_comm] · apply mapsTo_genEigenspace_of_comm (Algebra.mul_sub_algebraMap_commutes f _) · apply isNilpotent_restrict_genEigenspace_nat · apply mapsTo_genEigenspace_of_comm (Algebra.mul_sub_algebraMap_commutes f _) apply isNilpotent_restrict_genEigenspace_nat have hf₁₂ : f₂ - f₁ = algebraMap R (End R p) (μ₁ - μ₂) := by ext; simp [f₁, f₂] rw [hf₁₂, IsNilpotent.map_iff (FaithfulSMul.algebraMap_injective R (End R p)), isNilpotent_iff_eq_zero, sub_eq_zero] at this contradiction lemma injOn_genEigenspace [NoZeroSMulDivisors R M] (f : End R M) (k : ℕ∞) : InjOn (f.genEigenspace · k) {μ | f.genEigenspace μ k ≠ ⊥} := by rintro μ₁ _ μ₂ hμ₂ hμ₁₂ by_contra contra apply hμ₂ simpa only [hμ₁₂, disjoint_self] using f.disjoint_genEigenspace contra k k lemma injOn_maxGenEigenspace [NoZeroSMulDivisors R M] (f : End R M) : InjOn (f.maxGenEigenspace ·) {μ | f.maxGenEigenspace μ ≠ ⊥} := injOn_genEigenspace f ⊤ theorem independent_genEigenspace [NoZeroSMulDivisors R M] (f : End R M) (k : ℕ∞) : iSupIndep (f.genEigenspace · k) := by classical suffices ∀ μ₁ (s : Finset R), μ₁ ∉ s → Disjoint (f.genEigenspace μ₁ k) (s.sup fun μ ↦ f.genEigenspace μ k) by simp_rw [iSupIndep_iff_supIndep_of_injOn (injOn_genEigenspace f k), Finset.supIndep_iff_disjoint_erase] exact fun s μ _ ↦ this _ _ (s.notMem_erase μ) intro μ₁ s induction s using Finset.induction_on with | empty => simp | insert μ₂ s _ ih => intro hμ₁₂ obtain ⟨hμ₁₂ : μ₁ ≠ μ₂, hμ₁ : μ₁ ∉ s⟩ := by rwa [Finset.mem_insert, not_or] at hμ₁₂ specialize ih hμ₁ rw [Finset.sup_insert, disjoint_iff, Submodule.eq_bot_iff] rintro x ⟨hx, hx'⟩ simp only [SetLike.mem_coe] at hx hx' suffices x ∈ genEigenspace f μ₂ k by rw [← Submodule.mem_bot (R := R), ← (f.disjoint_genEigenspace hμ₁₂ k k).eq_bot] exact ⟨hx, this⟩ obtain ⟨y, hy, z, hz, rfl⟩ := Submodule.mem_sup.mp hx'; clear hx' let g := f - μ₂ • 1 simp_rw [mem_genEigenspace, ← exists_prop] at hy ⊢ peel hy with l hlk hl simp only [LinearMap.mem_ker] at hl have hyz : (g ^ l) (y + z) ∈ (f.genEigenspace μ₁ k) ⊓ s.sup fun μ ↦ f.genEigenspace μ k := by refine ⟨f.mapsTo_genEigenspace_of_comm (g := g ^ l) ?_ μ₁ k hx, ?_⟩ · exact Algebra.mul_sub_algebraMap_pow_commutes f μ₂ l · rw [SetLike.mem_coe, map_add, hl, zero_add] suffices (s.sup fun μ ↦ f.genEigenspace μ k).map (g ^ l) ≤ s.sup fun μ ↦ f.genEigenspace μ k by exact this (Submodule.mem_map_of_mem hz) simp_rw [Finset.sup_eq_iSup, Submodule.map_iSup (ι := R), Submodule.map_iSup (ι := _ ∈ s)] refine iSup₂_mono fun μ _ ↦ ?_ rintro - ⟨u, hu, rfl⟩ refine f.mapsTo_genEigenspace_of_comm ?_ μ k hu exact Algebra.mul_sub_algebraMap_pow_commutes f μ₂ l rwa [ih.eq_bot, Submodule.mem_bot] at hyz theorem independent_maxGenEigenspace [NoZeroSMulDivisors R M] (f : End R M) : iSupIndep f.maxGenEigenspace := by apply independent_genEigenspace /-- The eigenspaces of a linear operator form an independent family of subspaces of `M`. That is, any eigenspace has trivial intersection with the span of all the other eigenspaces. -/ theorem eigenspaces_iSupIndep [NoZeroSMulDivisors R M] (f : End R M) : iSupIndep f.eigenspace := f.independent_genEigenspace 1 /-- Eigenvectors corresponding to distinct eigenvalues of a linear operator are linearly independent. -/ theorem eigenvectors_linearIndependent' {ι : Type*} [NoZeroSMulDivisors R M] (f : End R M) (μ : ι → R) (hμ : Function.Injective μ) (v : ι → M) (h_eigenvec : ∀ i, f.HasEigenvector (μ i) (v i)) : LinearIndependent R v := f.eigenspaces_iSupIndep.comp hμ |>.linearIndependent _ (fun i ↦ h_eigenvec i |>.left) (fun i ↦ h_eigenvec i |>.right) /-- Eigenvectors corresponding to distinct eigenvalues of a linear operator are linearly independent. (Lemma 5.10 of [axler2015]) We use the eigenvalues as indexing set to ensure that there is only one eigenvector for each eigenvalue in the image of `xs`. See `Module.End.eigenvectors_linearIndependent'` for an indexed variant. -/ theorem eigenvectors_linearIndependent [NoZeroSMulDivisors R M] (f : End R M) (μs : Set R) (xs : μs → M) (h_eigenvec : ∀ μ : μs, f.HasEigenvector μ (xs μ)) : LinearIndependent R xs := f.eigenvectors_linearIndependent' (fun μ : μs ↦ μ) Subtype.coe_injective _ h_eigenvec /-- If `f` maps a subspace `p` into itself, then the generalized eigenspace of the restriction of `f` to `p` is the part of the generalized eigenspace of `f` that lies in `p`. -/ theorem genEigenspace_restrict (f : End R M) (p : Submodule R M) (k : ℕ∞) (μ : R) (hfp : ∀ x : M, x ∈ p → f x ∈ p) : genEigenspace (LinearMap.restrict f hfp) μ k = Submodule.comap p.subtype (f.genEigenspace μ k) := by ext x suffices ∀ l : ℕ, genEigenspace (LinearMap.restrict f hfp) μ l = Submodule.comap p.subtype (f.genEigenspace μ l) by simp_rw [mem_genEigenspace, ← mem_genEigenspace_nat, this, Submodule.mem_comap, mem_genEigenspace (k := k), mem_genEigenspace_nat] intro l simp only [genEigenspace_nat, ← LinearMap.ker_comp] induction l with | zero => rw [pow_zero, pow_zero, Module.End.one_eq_id] apply (Submodule.ker_subtype _).symm | succ l ih => erw [pow_succ, pow_succ, LinearMap.ker_comp, LinearMap.ker_comp, ih, ← LinearMap.ker_comp, LinearMap.comp_assoc] lemma _root_.Submodule.inf_genEigenspace (f : End R M) (p : Submodule R M) {k : ℕ∞} {μ : R} (hfp : ∀ x : M, x ∈ p → f x ∈ p) : p ⊓ f.genEigenspace μ k = (genEigenspace (LinearMap.restrict f hfp) μ k).map p.subtype := by rw [f.genEigenspace_restrict _ _ _ hfp, Submodule.map_comap_eq, Submodule.range_subtype] lemma mapsTo_restrict_maxGenEigenspace_restrict_of_mapsTo {p : Submodule R M} (f g : End R M) (hf : MapsTo f p p) (hg : MapsTo g p p) {μ₁ μ₂ : R} (h : MapsTo f (g.maxGenEigenspace μ₁) (g.maxGenEigenspace μ₂)) : MapsTo (f.restrict hf) (maxGenEigenspace (g.restrict hg) μ₁) (maxGenEigenspace (g.restrict hg) μ₂) := by intro x hx simp_rw [SetLike.mem_coe, mem_maxGenEigenspace, ← LinearMap.restrict_smul_one _, LinearMap.restrict_sub _, Module.End.pow_restrict _, LinearMap.restrict_apply, Submodule.mk_eq_zero, ← mem_maxGenEigenspace] at hx ⊢ exact h hx /-- If `p` is an invariant submodule of an endomorphism `f`, then the `μ`-eigenspace of the restriction of `f` to `p` is a submodule of the `μ`-eigenspace of `f`. -/ theorem eigenspace_restrict_le_eigenspace (f : End R M) {p : Submodule R M} (hfp : ∀ x ∈ p, f x ∈ p) (μ : R) : (eigenspace (f.restrict hfp) μ).map p.subtype ≤ f.eigenspace μ := by rintro a ⟨x, hx, rfl⟩ simp only [SetLike.mem_coe, mem_eigenspace_iff, LinearMap.restrict_apply] at hx ⊢ exact congr_arg Subtype.val hx /-- Generalized eigenrange and generalized eigenspace for exponent `finrank K V` are disjoint. -/ theorem generalized_eigenvec_disjoint_range_ker [FiniteDimensional K V] (f : End K V) (μ : K) : Disjoint (f.genEigenrange μ (finrank K V)) (f.genEigenspace μ (finrank K V)) := by have h := calc Submodule.comap ((f - μ • 1) ^ finrank K V) (f.genEigenspace μ (finrank K V)) = LinearMap.ker ((f - algebraMap _ _ μ) ^ finrank K V * (f - algebraMap K (End K V) μ) ^ finrank K V) := by rw [genEigenspace_nat, ← LinearMap.ker_comp]; rfl _ = f.genEigenspace μ (finrank K V + finrank K V : ℕ) := by simp_rw [← pow_add, genEigenspace_nat]; rfl _ = f.genEigenspace μ (finrank K V) := by rw [genEigenspace_eq_genEigenspace_finrank_of_le]; cutsat rw [disjoint_iff_inf_le, genEigenrange_nat, LinearMap.range_eq_map, Submodule.map_inf_eq_map_inf_comap, top_inf_eq, h, genEigenspace_nat] apply Submodule.map_comap_le /-- If an invariant subspace `p` of an endomorphism `f` is disjoint from the `μ`-eigenspace of `f`, then the restriction of `f` to `p` has trivial `μ`-eigenspace. -/ theorem eigenspace_restrict_eq_bot {f : End R M} {p : Submodule R M} (hfp : ∀ x ∈ p, f x ∈ p) {μ : R} (hμp : Disjoint (f.eigenspace μ) p) : eigenspace (f.restrict hfp) μ = ⊥ := by rw [eq_bot_iff] intro x hx simpa using hμp.le_bot ⟨eigenspace_restrict_le_eigenspace f hfp μ ⟨x, hx, rfl⟩, x.prop⟩ /-- The generalized eigenspace of an eigenvalue has positive dimension for positive exponents. -/ theorem pos_finrank_genEigenspace_of_hasEigenvalue [FiniteDimensional K V] {f : End K V} {k : ℕ} {μ : K} (hx : f.HasEigenvalue μ) (hk : 0 < k) : 0 < finrank K (f.genEigenspace μ k) := calc 0 = finrank K (⊥ : Submodule K V) := by rw [finrank_bot] _ < finrank K (f.eigenspace μ) := Submodule.finrank_lt_finrank_of_lt (bot_lt_iff_ne_bot.2 hx) _ ≤ finrank K (f.genEigenspace μ k) := Submodule.finrank_mono ((f.genEigenspace μ).monotone (by simpa using Nat.succ_le_of_lt hk)) /-- A linear map maps a generalized eigenrange into itself. -/ theorem map_genEigenrange_le {f : End K V} {μ : K} {n : ℕ} : Submodule.map f (f.genEigenrange μ n) ≤ f.genEigenrange μ n := calc Submodule.map f (f.genEigenrange μ n) = LinearMap.range (f * (f - algebraMap _ _ μ) ^ n) := by rw [genEigenrange_nat]; exact (LinearMap.range_comp _ _).symm _ = LinearMap.range ((f - algebraMap _ _ μ) ^ n * f) := by rw [Algebra.mul_sub_algebraMap_pow_commutes] _ = Submodule.map ((f - algebraMap _ _ μ) ^ n) (LinearMap.range f) := LinearMap.range_comp _ _ _ ≤ f.genEigenrange μ n := by rw [genEigenrange_nat]; apply LinearMap.map_le_range lemma genEigenspace_le_smul (f : Module.End R M) (μ t : R) (k : ℕ∞) : (f.genEigenspace μ k) ≤ (t • f).genEigenspace (t * μ) k := by intro m hm simp_rw [mem_genEigenspace, ← exists_prop, LinearMap.mem_ker] at hm ⊢ peel hm with l hlk hl rw [mul_smul, ← smul_sub, smul_pow, LinearMap.smul_apply, hl, smul_zero] lemma genEigenspace_inf_le_add (f₁ f₂ : End R M) (μ₁ μ₂ : R) (k₁ k₂ : ℕ∞) (h : Commute f₁ f₂) : (f₁.genEigenspace μ₁ k₁) ⊓ (f₂.genEigenspace μ₂ k₂) ≤ (f₁ + f₂).genEigenspace (μ₁ + μ₂) (k₁ + k₂) := by intro m hm simp only [Submodule.mem_inf, mem_genEigenspace, LinearMap.mem_ker] at hm ⊢ obtain ⟨⟨l₁, hlk₁, hl₁⟩, ⟨l₂, hlk₂, hl₂⟩⟩ := hm use l₁ + l₂ have : f₁ + f₂ - (μ₁ + μ₂) • 1 = (f₁ - μ₁ • 1) + (f₂ - μ₂ • 1) := by rw [add_smul]; exact add_sub_add_comm f₁ f₂ (μ₁ • 1) (μ₂ • 1) replace h : Commute (f₁ - μ₁ • 1) (f₂ - μ₂ • 1) := (h.sub_right <| Algebra.commute_algebraMap_right μ₂ f₁).sub_left (Algebra.commute_algebraMap_left μ₁ _) rw [this, h.add_pow', LinearMap.coeFn_sum, Finset.sum_apply] constructor · simpa only [Nat.cast_add] using add_le_add hlk₁ hlk₂ refine Finset.sum_eq_zero fun ⟨i, j⟩ hij ↦ ?_ suffices (((f₁ - μ₁ • 1) ^ i) * ((f₂ - μ₂ • 1) ^ j)) m = 0 by rw [LinearMap.smul_apply, this, smul_zero] rw [Finset.mem_antidiagonal] at hij obtain hi|hj : l₁ ≤ i ∨ l₂ ≤ j := by cutsat · rw [(h.pow_pow i j).eq, Module.End.mul_apply, Module.End.pow_map_zero_of_le hi hl₁, LinearMap.map_zero] · rw [Module.End.mul_apply, Module.End.pow_map_zero_of_le hj hl₂, LinearMap.map_zero] lemma map_smul_of_iInf_genEigenspace_ne_bot [NoZeroSMulDivisors R M] {L F : Type*} [SMul R L] [FunLike F L (End R M)] [MulActionHomClass F R L (End R M)] (f : F) (μ : L → R) (k : ℕ∞) (h_ne : ⨅ x, (f x).genEigenspace (μ x) k ≠ ⊥) (t : R) (x : L) : μ (t • x) = t • μ x := by by_contra contra let g : L → Submodule R M := fun x ↦ (f x).genEigenspace (μ x) k have : ⨅ x, g x ≤ g x ⊓ g (t • x) := le_inf_iff.mpr ⟨iInf_le g x, iInf_le g (t • x)⟩ refine h_ne <| eq_bot_iff.mpr (le_trans this (disjoint_iff_inf_le.mp ?_)) apply Disjoint.mono_left (genEigenspace_le_smul (f x) (μ x) t k) simp only [g, map_smul] exact disjoint_genEigenspace (t • f x) (Ne.symm contra) k k lemma map_add_of_iInf_genEigenspace_ne_bot_of_commute [NoZeroSMulDivisors R M] {L F : Type*} [Add L] [FunLike F L (End R M)] [AddHomClass F L (End R M)] (f : F) (μ : L → R) (k : ℕ∞) (h_ne : ⨅ x, (f x).genEigenspace (μ x) k ≠ ⊥) (h : ∀ x y, Commute (f x) (f y)) (x y : L) : μ (x + y) = μ x + μ y := by by_contra contra let g : L → Submodule R M := fun x ↦ (f x).genEigenspace (μ x) k have : ⨅ x, g x ≤ (g x ⊓ g y) ⊓ g (x + y) := le_inf_iff.mpr ⟨le_inf_iff.mpr ⟨iInf_le g x, iInf_le g y⟩, iInf_le g (x + y)⟩ refine h_ne <| eq_bot_iff.mpr (le_trans this (disjoint_iff_inf_le.mp ?_)) apply Disjoint.mono_left (genEigenspace_inf_le_add (f x) (f y) (μ x) (μ y) k k (h x y)) simp only [g, map_add] exact disjoint_genEigenspace (f x + f y) (Ne.symm contra) _ k end End end Module
.lake/packages/mathlib/Mathlib/LinearAlgebra/Eigenspace/Semisimple.lean
import Mathlib.LinearAlgebra.Eigenspace.Basic import Mathlib.LinearAlgebra.Semisimple /-! # Eigenspaces of semisimple linear endomorphisms This file contains basic results relevant to the study of eigenspaces of semisimple linear endomorphisms. ## Main definitions / results * `Module.End.IsSemisimple.genEigenspace_eq_eigenspace`: for a semisimple endomorphism, a generalized eigenspace is an eigenspace. -/ open Function Set namespace Module.End variable {R M : Type*} [CommRing R] [AddCommGroup M] [Module R M] {f g : End R M} lemma apply_eq_of_mem_of_comm_of_isFinitelySemisimple_of_isNil {μ : R} {k : ℕ∞} {m : M} (hm : m ∈ f.genEigenspace μ k) (hfg : Commute f g) (hss : g.IsFinitelySemisimple) (hnil : IsNilpotent (f - g)) : g m = μ • m := by rw [f.mem_genEigenspace] at hm obtain ⟨l, -, hm⟩ := hm rw [← f.mem_genEigenspace_nat] at hm set p := f.genEigenspace μ l have h₁ : MapsTo g p p := mapsTo_genEigenspace_of_comm hfg μ l have h₂ : MapsTo (g - algebraMap R (End R M) μ) p p := mapsTo_genEigenspace_of_comm (hfg.sub_right <| Algebra.commute_algebraMap_right μ f) μ l have h₃ : MapsTo (f - g) p p := mapsTo_genEigenspace_of_comm (Commute.sub_right rfl hfg) μ l have h₄ : MapsTo (f - algebraMap R (End R M) μ) p p := mapsTo_genEigenspace_of_comm (Algebra.mul_sub_algebraMap_commutes f μ) μ l replace hfg : Commute (f - algebraMap R (End R M) μ) (f - g) := (Commute.sub_right rfl hfg).sub_left <| Algebra.commute_algebraMap_left μ (f - g) suffices IsNilpotent ((g - algebraMap R (End R M) μ).restrict h₂) by replace this : g.restrict h₁ - algebraMap R (End R p) μ = 0 := eq_zero_of_isNilpotent_of_isFinitelySemisimple this (by simpa using hss.restrict _) simpa [LinearMap.restrict_apply, sub_eq_zero] using LinearMap.congr_fun this ⟨m, hm⟩ simpa [LinearMap.restrict_sub h₄ h₃] using (LinearMap.restrict_commute hfg h₄ h₃).isNilpotent_sub (f.isNilpotent_restrict_sub_algebraMap μ l) (Module.End.isNilpotent.restrict h₃ hnil) lemma IsFinitelySemisimple.genEigenspace_eq_eigenspace (hf : f.IsFinitelySemisimple) (μ : R) {k : ℕ∞} (hk : 0 < k) : f.genEigenspace μ k = f.eigenspace μ := by refine le_antisymm (fun m hm ↦ mem_eigenspace_iff.mpr ?_) (f.genEigenspace μ |>.mono ?_) · apply apply_eq_of_mem_of_comm_of_isFinitelySemisimple_of_isNil hm rfl hf simp · exact Order.one_le_iff_pos.mpr hk lemma IsFinitelySemisimple.maxGenEigenspace_eq_eigenspace (hf : f.IsFinitelySemisimple) (μ : R) : f.maxGenEigenspace μ = f.eigenspace μ := hf.genEigenspace_eq_eigenspace μ ENat.top_pos end Module.End
.lake/packages/mathlib/Mathlib/LinearAlgebra/Eigenspace/Zero.lean
import Mathlib.Algebra.Order.Archimedean.Basic import Mathlib.LinearAlgebra.Charpoly.ToMatrix import Mathlib.LinearAlgebra.Determinant import Mathlib.LinearAlgebra.Eigenspace.Minpoly import Mathlib.LinearAlgebra.FreeModule.StrongRankCondition import Mathlib.RingTheory.Artinian.Module /-! # Results on the eigenvalue 0 In this file we provide equivalent characterizations of properties related to the eigenvalue 0, such as being nilpotent, having determinant equal to 0, having a non-trivial kernel, etc... ## Main results * `LinearMap.charpoly_nilpotent_tfae`: equivalent characterizations of nilpotent endomorphisms * `LinearMap.hasEigenvalue_zero_tfae`: equivalent characterizations of endomorphisms with eigenvalue 0 * `LinearMap.not_hasEigenvalue_zero_tfae`: endomorphisms without eigenvalue 0 * `LinearMap.finrank_maxGenEigenspace`: the dimension of the maximal generalized eigenspace of an endomorphism is the trailing degree of its characteristic polynomial -/ variable {R K M : Type*} [CommRing R] [IsDomain R] [Field K] [AddCommGroup M] variable [Module R M] [Module.Finite R M] [Module.Free R M] variable [Module K M] [Module.Finite K M] open Module Module.Free Polynomial lemma IsNilpotent.charpoly_eq_X_pow_finrank {φ : Module.End R M} (h : IsNilpotent φ) : φ.charpoly = X ^ finrank R M := by rw [← sub_eq_zero] apply IsNilpotent.eq_zero rw [finrank_eq_card_chooseBasisIndex] apply Matrix.isNilpotent_charpoly_sub_pow_of_isNilpotent exact h.map (LinearMap.toMatrixAlgEquiv (chooseBasis R M)) namespace LinearMap lemma isNilpotent_iff_charpoly (φ : End R M) : IsNilpotent φ ↔ charpoly φ = X ^ finrank R M := ⟨IsNilpotent.charpoly_eq_X_pow_finrank, fun h ↦ ⟨finrank R M, by rw [← @aeval_X_pow R, ← h, aeval_self_charpoly φ]⟩⟩ open Module.Free in lemma charpoly_nilpotent_tfae [IsNoetherian R M] (φ : Module.End R M) : List.TFAE [ IsNilpotent φ, φ.charpoly = X ^ finrank R M, ∀ m : M, ∃ (n : ℕ), (φ ^ n) m = 0, natTrailingDegree φ.charpoly = finrank R M ] := by tfae_have 1 → 2 := IsNilpotent.charpoly_eq_X_pow_finrank tfae_have 2 → 3 | h, m => by use finrank R M suffices φ ^ finrank R M = 0 by simp only [this, LinearMap.zero_apply] simpa only [h, map_pow, aeval_X] using φ.aeval_self_charpoly tfae_have 3 → 1 | h => by obtain ⟨n, hn⟩ := Filter.eventually_atTop.mp <| φ.eventually_iSup_ker_pow_eq use n ext x rw [zero_apply, ← mem_ker, ← hn n le_rfl] obtain ⟨k, hk⟩ := h x rw [← mem_ker] at hk exact Submodule.mem_iSup_of_mem _ hk tfae_have 2 ↔ 4 := by rw [← φ.charpoly_natDegree, φ.charpoly_monic.eq_X_pow_iff_natTrailingDegree_eq_natDegree] tfae_finish lemma charpoly_eq_X_pow_iff [IsNoetherian R M] (φ : Module.End R M) : φ.charpoly = X ^ finrank R M ↔ ∀ m : M, ∃ (n : ℕ), (φ ^ n) m = 0 := (charpoly_nilpotent_tfae φ).out 1 2 open Module.Free in lemma hasEigenvalue_zero_tfae (φ : Module.End K M) : List.TFAE [ Module.End.HasEigenvalue φ 0, IsRoot (minpoly K φ) 0, constantCoeff φ.charpoly = 0, LinearMap.det φ = 0, ⊥ < ker φ, ∃ (m : M), m ≠ 0 ∧ φ m = 0 ] := by tfae_have 1 ↔ 2 := Module.End.hasEigenvalue_iff_isRoot tfae_have 2 → 3 := by obtain ⟨F, hF⟩ := minpoly_dvd_charpoly φ simp only [IsRoot.def, constantCoeff_apply, coeff_zero_eq_eval_zero, hF, eval_mul] intro h; rw [h, zero_mul] tfae_have 3 → 4 := by rw [← LinearMap.det_toMatrix (chooseBasis K M), Matrix.det_eq_sign_charpoly_coeff, constantCoeff_apply, charpoly] intro h; rw [h, mul_zero] tfae_have 4 → 5 := bot_lt_ker_of_det_eq_zero tfae_have 5 → 6 := by contrapose! simp only [not_bot_lt_iff, eq_bot_iff] intro h x simp only [mem_ker, Submodule.mem_bot] contrapose! apply h tfae_have 6 → 1 | ⟨x, h1, h2⟩ => by apply Module.End.hasEigenvalue_of_hasEigenvector ⟨_, h1⟩ simpa only [Module.End.eigenspace_zero, mem_ker] using h2 tfae_finish lemma charpoly_constantCoeff_eq_zero_iff (φ : Module.End K M) : constantCoeff φ.charpoly = 0 ↔ ∃ (m : M), m ≠ 0 ∧ φ m = 0 := (hasEigenvalue_zero_tfae φ).out 2 5 open Module.Free in lemma not_hasEigenvalue_zero_tfae (φ : Module.End K M) : List.TFAE [ ¬ Module.End.HasEigenvalue φ 0, ¬ IsRoot (minpoly K φ) 0, constantCoeff φ.charpoly ≠ 0, LinearMap.det φ ≠ 0, ker φ = ⊥, ∀ (m : M), φ m = 0 → m = 0 ] := by have := (hasEigenvalue_zero_tfae φ).not dsimp only [List.map] at this push_neg at this have aux₁ : ∀ m, (m ≠ 0 → φ m ≠ 0) ↔ (φ m = 0 → m = 0) := by intro m; apply not_imp_not have aux₂ : ker φ = ⊥ ↔ ¬ ⊥ < ker φ := by rw [bot_lt_iff_ne_bot, not_not] simpa only [aux₁, aux₂] using this open Module.Free in lemma finrank_maxGenEigenspace_zero_eq (φ : Module.End K M) : finrank K (φ.maxGenEigenspace 0) = natTrailingDegree (φ.charpoly) := by set V := φ.maxGenEigenspace 0 have hV : V = ⨆ (n : ℕ), ker (φ ^ n) := by simp [V, ← Module.End.iSup_genEigenspace_eq, Module.End.genEigenspace_nat] let W := ⨅ (n : ℕ), LinearMap.range (φ ^ n) have hVW : IsCompl V W := by rw [hV] exact LinearMap.isCompl_iSup_ker_pow_iInf_range_pow φ have hφV : ∀ x ∈ V, φ x ∈ V := by simp only [V, Module.End.mem_maxGenEigenspace, zero_smul, sub_zero, forall_exists_index] intro x n hx use n rw [← Module.End.mul_apply, ← pow_succ, pow_succ', Module.End.mul_apply, hx, map_zero] have hφW : ∀ x ∈ W, φ x ∈ W := by simp only [W, Submodule.mem_iInf, mem_range] intro x H n obtain ⟨y, rfl⟩ := H n use φ y rw [← Module.End.mul_apply, ← pow_succ, pow_succ', Module.End.mul_apply] let F := φ.restrict hφV let G := φ.restrict hφW let ψ := F.prodMap G let e := Submodule.prodEquivOfIsCompl V W hVW let bV := chooseBasis K V let bW := chooseBasis K W let b := bV.prod bW have hψ : ψ = e.symm.conj φ := by apply b.ext simp only [Basis.prod_apply, coe_inl, coe_inr, prodMap_apply, LinearEquiv.conj_apply, LinearEquiv.symm_symm, Submodule.coe_prodEquivOfIsCompl, coe_comp, LinearEquiv.coe_coe, Function.comp_apply, coprod_apply, Submodule.coe_subtype, map_add, Sum.forall, Sum.elim_inl, map_zero, ZeroMemClass.coe_zero, add_zero, LinearEquiv.eq_symm_apply, and_self, Submodule.coe_prodEquivOfIsCompl', restrict_coe_apply, implies_true, Sum.elim_inr, zero_add, e, V, W, ψ, F, G, b] rw [← e.symm.charpoly_conj φ, ← hψ, charpoly_prodMap, natTrailingDegree_mul (charpoly_monic _).ne_zero (charpoly_monic _).ne_zero] have hG : natTrailingDegree (charpoly G) = 0 := by apply Polynomial.natTrailingDegree_eq_zero_of_constantCoeff_ne_zero apply ((not_hasEigenvalue_zero_tfae G).out 2 5).mpr intro x hx apply Subtype.ext suffices x.1 ∈ V ⊓ W by rwa [hVW.inf_eq_bot, Submodule.mem_bot] at this suffices x.1 ∈ V from ⟨this, x.2⟩ simp only [Module.End.mem_maxGenEigenspace, zero_smul, sub_zero, V] use 1 rw [pow_one] rwa [Subtype.ext_iff] at hx rw [hG, add_zero, eq_comm] apply ((charpoly_nilpotent_tfae F).out 2 3).mp simp only [Subtype.forall, Module.End.mem_maxGenEigenspace, zero_smul, sub_zero, V, F] rintro x ⟨n, hx⟩ use n apply Subtype.ext rw [ZeroMemClass.coe_zero] refine .trans ?_ hx generalize_proofs h' clear hx induction n <;> simp [pow_succ', *] @[deprecated (since := "2025-09-07")] alias finrank_maxGenEigenspace := finrank_maxGenEigenspace_zero_eq lemma finrank_maxGenEigenspace_eq (φ : Module.End K M) (μ : K) : finrank K (φ.maxGenEigenspace μ) = φ.charpoly.rootMultiplicity μ := by rw [φ.maxGenEigenspace_eq_maxGenEigenspace_zero, finrank_maxGenEigenspace_zero_eq, Polynomial.rootMultiplicity_eq_natTrailingDegree, LinearMap.charpoly_sub_smul] lemma finrank_genEigenspace_le (φ : Module.End K M) (μ : K) (k : ℕ) : finrank K (φ.genEigenspace μ k) ≤ φ.charpoly.rootMultiplicity μ := by grw [Submodule.finrank_mono (φ.genEigenspace_le_maximal μ k), finrank_maxGenEigenspace_eq] /-- The geometric multiplicity of an eigenvalue is at most the algebraic multiplicity. -/ lemma finrank_eigenspace_le (φ : Module.End K M) (μ : K) : finrank K (φ.eigenspace μ) ≤ φ.charpoly.rootMultiplicity μ := finrank_genEigenspace_le .. end LinearMap
.lake/packages/mathlib/Mathlib/LinearAlgebra/Eigenspace/Minpoly.lean
import Mathlib.Algebra.Polynomial.Roots import Mathlib.FieldTheory.Minpoly.Basic import Mathlib.LinearAlgebra.Eigenspace.Basic import Mathlib.RingTheory.IntegralClosure.Algebra.Basic /-! # Eigenvalues are the roots of the minimal polynomial. ## Tags eigenvalue, minimal polynomial -/ universe u v w namespace Module namespace End open Polynomial Module open scoped Polynomial section CommSemiring variable {R : Type v} {M : Type w} [CommSemiring R] [AddCommMonoid M] [Module R M] theorem ker_aeval_ring_hom'_unit_polynomial (f : End R M) (c : R[X]ˣ) : LinearMap.ker (aeval f (c : R[X])) = ⊥ := LinearMap.ker_eq_bot'.mpr fun m hm ↦ by simpa [← mul_apply, ← aeval_mul] using congr(c⁻¹.1.aeval f $hm) end CommSemiring section CommRing variable {R : Type v} {M : Type w} [CommRing R] [AddCommGroup M] [Module R M] {f : End R M} {μ : R} theorem aeval_apply_of_hasEigenvector {f : End R M} {p : R[X]} {μ : R} {x : M} (h : f.HasEigenvector μ x) : aeval f p x = p.eval μ • x := by refine p.induction_on ?_ ?_ ?_ · intro a; simp [Module.algebraMap_end_apply] · intro p q hp hq; simp [hp, hq, add_smul] · intro n a hna rw [mul_comm, pow_succ', mul_assoc, map_mul, Module.End.mul_apply, mul_comm, hna] simp only [mem_eigenspace_iff.1 h.1, smul_smul, aeval_X, eval_mul, eval_C, eval_pow, eval_X, LinearMap.map_smulₛₗ, RingHom.id_apply, mul_comm] theorem isRoot_of_hasEigenvalue [NoZeroSMulDivisors R M] {f : End R M} {μ : R} (h : f.HasEigenvalue μ) : (minpoly R f).IsRoot μ := by rcases (Submodule.ne_bot_iff _).1 h with ⟨w, ⟨H, ne0⟩⟩ refine Or.resolve_right (smul_eq_zero.1 ?_) ne0 rw [← aeval_apply_of_hasEigenvector ⟨H, ne0⟩] simp section IsDomain variable [IsDomain R] [Module.Finite R M] theorem hasEigenvalue_of_isRoot (h : (minpoly R f).IsRoot μ) : f.HasEigenvalue μ := by obtain ⟨q, hq⟩ := dvd_iff_isRoot.mpr h obtain ⟨v, hv⟩ : ∃ v : M, q.aeval f v ≠ 0 := by by_contra! h_contra have := minpoly.min R f ((monic_X_sub_C μ).of_mul_monic_left (hq ▸ minpoly.monic (Algebra.IsIntegral.isIntegral f))) (LinearMap.ext h_contra) rw [hq, degree_mul, degree_X_sub_C, degree_eq_natDegree] at this · norm_cast at this; grind · rintro rfl exact minpoly.ne_zero (Algebra.IsIntegral.isIntegral f) (mul_zero (X - C μ) ▸ hq) refine Module.End.hasEigenvalue_of_hasEigenvector (hasEigenvector_iff.mpr ⟨?_, hv⟩) simpa [sub_eq_zero, hq] using congr($(minpoly.aeval R f) v) variable [NoZeroSMulDivisors R M] theorem hasEigenvalue_iff_isRoot : f.HasEigenvalue μ ↔ (minpoly R f).IsRoot μ := ⟨isRoot_of_hasEigenvalue, hasEigenvalue_of_isRoot⟩ variable (f) lemma finite_hasEigenvalue : Set.Finite f.HasEigenvalue := by have h : minpoly R f ≠ 0 := minpoly.ne_zero (Algebra.IsIntegral.isIntegral (R := R) f) convert (minpoly R f).rootSet_finite R ext μ change f.HasEigenvalue μ ↔ _ rw [hasEigenvalue_iff_isRoot, mem_rootSet_of_ne h, IsRoot, coe_aeval_eq_eval] /-- An endomorphism of a finite-dimensional vector space has finitely many eigenvalues. -/ noncomputable instance : Fintype f.Eigenvalues := Set.Finite.fintype f.finite_hasEigenvalue end IsDomain end CommRing section Field variable {K : Type v} {V : Type w} [Field K] [AddCommGroup V] [Module K V] theorem eigenspace_aeval_polynomial_degree_1 (f : End K V) (q : K[X]) (hq : degree q = 1) : eigenspace f (-q.coeff 0 / q.leadingCoeff) = LinearMap.ker (aeval f q) := calc eigenspace f (-q.coeff 0 / q.leadingCoeff) _ = LinearMap.ker (q.leadingCoeff • f - algebraMap K (End K V) (-q.coeff 0)) := by apply eigenspace_div rw [Ne, leadingCoeff_eq_zero_iff_deg_eq_bot, hq] exact WithBot.one_ne_bot _ = LinearMap.ker (aeval f (C q.leadingCoeff * X + C (q.coeff 0))) := by rw [C_mul', aeval_def]; simp [algebraMap, Algebra.algebraMap] _ = LinearMap.ker (aeval f q) := by rwa [← eq_X_add_C_of_degree_eq_one] end Field end End end Module section FiniteSpectrum /-- An endomorphism of a finite-dimensional vector space has a finite spectrum. -/ theorem Module.End.finite_spectrum {K : Type v} {V : Type w} [Field K] [AddCommGroup V] [Module K V] [FiniteDimensional K V] (f : Module.End K V) : Set.Finite (spectrum K f) := by convert f.finite_hasEigenvalue ext f x exact Module.End.hasEigenvalue_iff_mem_spectrum.symm variable {n R : Type*} [Field R] [Fintype n] [DecidableEq n] /-- An n x n matrix over a field has a finite spectrum. -/ theorem Matrix.finite_spectrum (A : Matrix n n R) : Set.Finite (spectrum R A) := by rw [← AlgEquiv.spectrum_eq (Matrix.toLinAlgEquiv <| Pi.basisFun R n) A] exact Module.End.finite_spectrum _ instance Matrix.instFiniteSpectrum (A : Matrix n n R) : Finite (spectrum R A) := Set.finite_coe_iff.mpr (Matrix.finite_spectrum A) end FiniteSpectrum
.lake/packages/mathlib/Mathlib/LinearAlgebra/TensorProduct/Opposite.lean
import Mathlib.RingTheory.TensorProduct.Maps import Mathlib.Algebra.Algebra.Opposite /-! # `MulOpposite` distributes over `⊗` The main result in this file is: * `Algebra.TensorProduct.opAlgEquiv R S A B : Aᵐᵒᵖ ⊗[R] Bᵐᵒᵖ ≃ₐ[S] (A ⊗[R] B)ᵐᵒᵖ` -/ open scoped TensorProduct variable (R S A B : Type*) variable [CommSemiring R] [CommSemiring S] [Semiring A] [Semiring B] variable [Algebra R S] [Algebra R A] [Algebra R B] [Algebra S A] variable [IsScalarTower R S A] namespace Algebra.TensorProduct open MulOpposite /-- `MulOpposite` distributes over `TensorProduct`. Note this is an `S`-algebra morphism, where `A/S/R` is a tower of algebras. -/ def opAlgEquiv : Aᵐᵒᵖ ⊗[R] Bᵐᵒᵖ ≃ₐ[S] (A ⊗[R] B)ᵐᵒᵖ := letI e₁ : Aᵐᵒᵖ ⊗[R] Bᵐᵒᵖ ≃ₗ[S] (A ⊗[R] B)ᵐᵒᵖ := TensorProduct.AlgebraTensorModule.congr (opLinearEquiv S).symm (opLinearEquiv R).symm ≪≫ₗ opLinearEquiv S letI e₂ : A ⊗[R] B ≃ₗ[S] (Aᵐᵒᵖ ⊗[R] Bᵐᵒᵖ)ᵐᵒᵖ := TensorProduct.AlgebraTensorModule.congr (opLinearEquiv S) (opLinearEquiv R) ≪≫ₗ opLinearEquiv S AlgEquiv.ofAlgHom (algHomOfLinearMapTensorProduct e₁.toLinearMap (fun a₁ a₂ b₁ b₂ => unop_injective (by with_unfolding_all rfl)) (unop_injective rfl)) (AlgHom.opComm <| algHomOfLinearMapTensorProduct e₂.toLinearMap (fun a₁ a₂ b₁ b₂ => unop_injective (by with_unfolding_all rfl)) (unop_injective rfl)) (AlgHom.op.symm.injective <| by ext <;> rfl) (by ext <;> rfl) theorem opAlgEquiv_apply (x : Aᵐᵒᵖ ⊗[R] Bᵐᵒᵖ) : opAlgEquiv R S A B x = op (_root_.TensorProduct.map (opLinearEquiv R).symm.toLinearMap (opLinearEquiv R).symm.toLinearMap x) := rfl theorem opAlgEquiv_symm_apply (x : (A ⊗[R] B)ᵐᵒᵖ) : (opAlgEquiv R S A B).symm x = _root_.TensorProduct.map (opLinearEquiv R).toLinearMap (opLinearEquiv R).toLinearMap x.unop := rfl @[simp] theorem opAlgEquiv_tmul (a : Aᵐᵒᵖ) (b : Bᵐᵒᵖ) : opAlgEquiv R S A B (a ⊗ₜ[R] b) = op (a.unop ⊗ₜ b.unop) := rfl @[simp] theorem opAlgEquiv_symm_tmul (a : A) (b : B) : (opAlgEquiv R S A B).symm (op <| a ⊗ₜ[R] b) = op a ⊗ₜ op b := rfl end Algebra.TensorProduct
.lake/packages/mathlib/Mathlib/LinearAlgebra/TensorProduct/Subalgebra.lean
import Mathlib.LinearAlgebra.TensorProduct.Submodule import Mathlib.RingTheory.TensorProduct.Maps /-! # Some results on tensor product of subalgebras ## Linear maps induced by multiplication for subalgebras Let `R` be a commutative ring, `S` be a commutative `R`-algebra. Let `A` and `B` be `R`-subalgebras in `S` (`Subalgebra R S`). We define some linear maps induced by the multiplication in `S`, which are mainly used in the definition of linearly disjointness. - `Subalgebra.mulMap`: the natural `R`-algebra homomorphism `A ⊗[R] B →ₐ[R] S` induced by the multiplication in `S`, whose image is `A ⊔ B` (`Subalgebra.mulMap_range`). - `Subalgebra.mulMap'`: the natural `R`-algebra homomorphism `A ⊗[R] B →ₗ[R] A ⊔ B` induced by multiplication in `S`, which is surjective (`Subalgebra.mulMap'_surjective`). - `Subalgebra.lTensorBot`, `Subalgebra.rTensorBot`: the natural isomorphism of `R`-algebras between `i(R) ⊗[R] A` and `A`, resp. `A ⊗[R] i(R)` and `A`, induced by multiplication in `S`, here `i : R → S` is the structure map. They generalize `Algebra.TensorProduct.lid` and `Algebra.TensorProduct.rid`, as `i(R)` is not necessarily isomorphic to `R`. They are `Subalgebra` versions of `Submodule.lTensorOne` and `Submodule.rTensorOne`. -/ open scoped TensorProduct open Module noncomputable section variable {R S T : Type*} section Semiring variable [CommSemiring R] [Semiring S] [Algebra R S] [Semiring T] [Algebra R T] namespace Subalgebra variable (A : Subalgebra R S) /-- If `A` is a subalgebra of `S/R`, there is the natural `R`-algebra isomorphism between `i(R) ⊗[R] A` and `A` induced by multiplication in `S`, here `i : R → S` is the structure map. This generalizes `Algebra.TensorProduct.lid` as `i(R)` is not necessarily isomorphic to `R`. This is the `Subalgebra` version of `Submodule.lTensorOne` -/ def lTensorBot : (⊥ : Subalgebra R S) ⊗[R] A ≃ₐ[R] A := by refine Algebra.TensorProduct.algEquivOfLinearEquivTensorProduct (toSubmodule A).lTensorOne ?_ ?_ · rintro x y a b obtain ⟨x', hx⟩ := Algebra.mem_bot.1 x.2 replace hx : algebraMap R _ x' = x := Subtype.val_injective hx obtain ⟨y', hy⟩ := Algebra.mem_bot.1 y.2 replace hy : algebraMap R _ y' = y := Subtype.val_injective hy rw [← hx, ← hy, ← map_mul] erw [(toSubmodule A).lTensorOne_tmul x' a, (toSubmodule A).lTensorOne_tmul y' b, (toSubmodule A).lTensorOne_tmul (x' * y') (a * b)] rw [Algebra.mul_smul_comm, Algebra.smul_mul_assoc, smul_smul, mul_comm x' y'] · exact Submodule.lTensorOne_one_tmul _ variable {A} @[simp] theorem lTensorBot_tmul (x : R) (a : A) : A.lTensorBot (algebraMap R _ x ⊗ₜ[R] a) = x • a := (toSubmodule A).lTensorOne_tmul x a @[simp] theorem lTensorBot_one_tmul (a : A) : A.lTensorBot (1 ⊗ₜ[R] a) = a := (toSubmodule A).lTensorOne_one_tmul a @[simp] theorem lTensorBot_symm_apply (a : A) : A.lTensorBot.symm a = 1 ⊗ₜ[R] a := rfl variable (A) in /-- If `A` is a subalgebra of `S/R`, there is the natural `R`-algebra isomorphism between `A ⊗[R] i(R)` and `A` induced by multiplication in `S`, here `i : R → S` is the structure map. This generalizes `Algebra.TensorProduct.rid` as `i(R)` is not necessarily isomorphic to `R`. This is the `Subalgebra` version of `Submodule.rTensorOne` -/ def rTensorBot : A ⊗[R] (⊥ : Subalgebra R S) ≃ₐ[R] A := by refine Algebra.TensorProduct.algEquivOfLinearEquivTensorProduct (toSubmodule A).rTensorOne ?_ ?_ · rintro a b x y obtain ⟨x', hx⟩ := Algebra.mem_bot.1 x.2 replace hx : algebraMap R _ x' = x := Subtype.val_injective hx obtain ⟨y', hy⟩ := Algebra.mem_bot.1 y.2 replace hy : algebraMap R _ y' = y := Subtype.val_injective hy rw [← hx, ← hy, ← map_mul] erw [(toSubmodule A).rTensorOne_tmul x' a, (toSubmodule A).rTensorOne_tmul y' b, (toSubmodule A).rTensorOne_tmul (x' * y') (a * b)] rw [Algebra.mul_smul_comm, Algebra.smul_mul_assoc, smul_smul, mul_comm x' y'] · exact Submodule.rTensorOne_tmul_one _ @[simp] theorem rTensorBot_tmul (x : R) (a : A) : A.rTensorBot (a ⊗ₜ[R] algebraMap R _ x) = x • a := (toSubmodule A).rTensorOne_tmul x a @[simp] theorem rTensorBot_tmul_one (a : A) : A.rTensorBot (a ⊗ₜ[R] 1) = a := (toSubmodule A).rTensorOne_tmul_one a @[simp] theorem rTensorBot_symm_apply (a : A) : A.rTensorBot.symm a = a ⊗ₜ[R] 1 := rfl variable (A) @[simp] theorem comm_trans_lTensorBot : (Algebra.TensorProduct.comm R _ _).trans A.lTensorBot = A.rTensorBot := AlgEquiv.toLinearEquiv_injective (toSubmodule A).comm_trans_lTensorOne @[simp] theorem comm_trans_rTensorBot : (Algebra.TensorProduct.comm R _ _).trans A.rTensorBot = A.lTensorBot := AlgEquiv.toLinearEquiv_injective (toSubmodule A).comm_trans_rTensorOne end Subalgebra namespace Algebra.TensorProduct variable (R S T) /-- Given `R`-algebras `S,T`, there is a natural `R`-linear isomorphism from `S ⊗[R] T` to `S' ⊗[R] T'` where `S',T'` are the images of `S,T` in `S ⊗[R] T` respectively. This is promoted to an `R`-algebra isomorphism `Algebra.TensorProduct.algEquivIncludeRange`. -/ def linearEquivIncludeRange : S ⊗[R] T ≃ₗ[R] (includeLeft : S →ₐ[R] S ⊗[R] T).range ⊗[R] (includeRight : T →ₐ[R] S ⊗[R] T).range := .ofLinear (_root_.TensorProduct.map includeLeft.toLinearMap.rangeRestrict includeRight.toLinearMap.rangeRestrict) ((LinearMap.range includeLeft).mulMap (LinearMap.range includeRight)) (_root_.TensorProduct.ext' <| by rintro ⟨x', x, rfl : x ⊗ₜ 1 = x'⟩ ⟨y', y, rfl : 1 ⊗ₜ y = y'⟩ rw [LinearMap.comp_apply, LinearMap.id_apply] erw [Submodule.mulMap_tmul] rw [tmul_mul_tmul, mul_one, one_mul, _root_.TensorProduct.map_tmul] rfl) (_root_.TensorProduct.ext' fun x y ↦ by rw [LinearMap.comp_apply, LinearMap.id_apply, _root_.TensorProduct.map_tmul] erw [Submodule.mulMap_tmul] change (x ⊗ₜ 1) * (1 ⊗ₜ y) = _ rw [tmul_mul_tmul, mul_one, one_mul]) theorem linearEquivIncludeRange_toLinearMap : (linearEquivIncludeRange R S T).toLinearMap = _root_.TensorProduct.map includeLeft.toLinearMap.rangeRestrict includeRight.toLinearMap.rangeRestrict := rfl theorem linearEquivIncludeRange_symm_toLinearMap : (linearEquivIncludeRange R S T).symm.toLinearMap = (LinearMap.range includeLeft).mulMap (LinearMap.range includeRight) := rfl @[simp] theorem linearEquivIncludeRange_tmul (x y) : linearEquivIncludeRange R S T (x ⊗ₜ[R] y) = ((includeLeft : S →ₐ[R] S ⊗[R] T).rangeRestrict x) ⊗ₜ[R] ((includeRight : T →ₐ[R] S ⊗[R] T).rangeRestrict y) := rfl @[simp] theorem linearEquivIncludeRange_symm_tmul (x y) : (linearEquivIncludeRange R S T).symm (x ⊗ₜ[R] y) = x.1 * y.1 := rfl /-- Given `R`-algebras `S,T`, there is a natural `R`-algebra isomorphism from `S ⊗[R] T` to `S' ⊗[R] T'` where `S',T'` are the images of `S,T` in `S ⊗[R] T` respectively. -/ def algEquivIncludeRange : S ⊗[R] T ≃ₐ[R] (includeLeft : S →ₐ[R] S ⊗[R] T).range ⊗[R] (includeRight : T →ₐ[R] S ⊗[R] T).range := algEquivOfLinearEquivTensorProduct (linearEquivIncludeRange R S T) (by simp) rfl theorem algEquivIncludeRange_toAlgHom : (algEquivIncludeRange R S T).toAlgHom = map includeLeft.rangeRestrict includeRight.rangeRestrict := rfl @[simp] theorem algEquivIncludeRange_tmul (x y) : algEquivIncludeRange R S T (x ⊗ₜ[R] y) = ((includeLeft : S →ₐ[R] S ⊗[R] T).rangeRestrict x) ⊗ₜ[R] ((includeRight : T →ₐ[R] S ⊗[R] T).rangeRestrict y) := rfl @[simp] theorem algEquivIncludeRange_symm_tmul (x y) : (algEquivIncludeRange R S T).symm (x ⊗ₜ[R] y) = x.1 * y.1 := rfl end Algebra.TensorProduct end Semiring section CommSemiring variable [CommSemiring R] [CommSemiring S] [Algebra R S] [CommSemiring T] [Algebra R T] variable (A B : Subalgebra R S) /-- If `A` and `B` are subalgebras in a commutative algebra `S` over `R`, there is the natural `R`-algebra homomorphism `A ⊗[R] B →ₐ[R] S` induced by multiplication in `S`. -/ def Subalgebra.mulMap : A ⊗[R] B →ₐ[R] S := Algebra.TensorProduct.productMap A.val B.val variable (R S T) in theorem Algebra.TensorProduct.algEquivIncludeRange_symm_toAlgHom : (algEquivIncludeRange R S T).symm.toAlgHom = (includeLeft : S →ₐ[R] S ⊗[R] T).range.mulMap includeRight.range := rfl namespace Subalgebra @[simp] theorem mulMap_tmul (a : A) (b : B) : mulMap A B (a ⊗ₜ[R] b) = a.1 * b.1 := rfl theorem mulMap_map_comp_eq (f : S →ₐ[R] T) : (mulMap (A.map f) (B.map f)).comp (Algebra.TensorProduct.map (f.subalgebraMap A) (f.subalgebraMap B)) = f.comp (mulMap A B) := by ext <;> simp theorem mulMap_toLinearMap : (A.mulMap B).toLinearMap = (toSubmodule A).mulMap (toSubmodule B) := rfl theorem mulMap_comm : mulMap B A = (mulMap A B).comp (Algebra.TensorProduct.comm R B A) := by ext <;> simp theorem mulMap_range : (A.mulMap B).range = A ⊔ B := by simp_rw [mulMap, Algebra.TensorProduct.productMap_range, Subalgebra.range_val] theorem mulMap_bot_left_eq : mulMap ⊥ A = A.val.comp A.lTensorBot.toAlgHom := AlgHom.toLinearMap_injective (toSubmodule A).mulMap_one_left_eq theorem mulMap_bot_right_eq : mulMap A ⊥ = A.val.comp A.rTensorBot.toAlgHom := AlgHom.toLinearMap_injective (toSubmodule A).mulMap_one_right_eq /-- If `A` and `B` are subalgebras in a commutative algebra `S` over `R`, there is the natural `R`-algebra homomorphism `A ⊗[R] B →ₐ[R] A ⊔ B` induced by multiplication in `S`, which is surjective (`Subalgebra.mulMap'_surjective`). -/ def mulMap' : A ⊗[R] B →ₐ[R] ↥(A ⊔ B) := (equivOfEq _ _ (mulMap_range A B)).toAlgHom.comp (mulMap A B).rangeRestrict variable {A B} in @[simp] theorem val_mulMap'_tmul (a : A) (b : B) : (mulMap' A B (a ⊗ₜ[R] b) : S) = a.1 * b.1 := rfl theorem mulMap'_surjective : Function.Surjective (mulMap' A B) := by simp_rw [mulMap', AlgEquiv.toAlgHom_eq_coe, AlgHom.coe_comp, AlgHom.coe_coe, EquivLike.comp_surjective, AlgHom.rangeRestrict_surjective] end Subalgebra end CommSemiring
.lake/packages/mathlib/Mathlib/LinearAlgebra/TensorProduct/Matrix.lean
import Mathlib.LinearAlgebra.Matrix.Kronecker import Mathlib.LinearAlgebra.Matrix.ToLin import Mathlib.LinearAlgebra.TensorProduct.Basis /-! # Connections between `TensorProduct` and `Matrix` This file contains results about the matrices corresponding to maps between tensor product types, where the correspondence is induced by `Basis.tensorProduct` Notably, `TensorProduct.toMatrix_map` shows that taking the tensor product of linear maps is equivalent to taking the Kronecker product of their matrix representations. -/ open Matrix Module LinearMap open scoped Kronecker variable {R : Type*} {M N P M' N' : Type*} {ι κ τ ι' κ' : Type*} variable [DecidableEq ι] [DecidableEq κ] [DecidableEq τ] variable [Fintype ι] [Fintype κ] [Fintype τ] [Finite ι'] [Finite κ'] variable [CommRing R] variable [AddCommGroup M] [AddCommGroup N] [AddCommGroup P] variable [AddCommGroup M'] [AddCommGroup N'] variable [Module R M] [Module R N] [Module R P] [Module R M'] [Module R N'] variable (bM : Basis ι R M) (bN : Basis κ R N) (bP : Basis τ R P) variable (bM' : Basis ι' R M') (bN' : Basis κ' R N') /-- The linear map built from `TensorProduct.map` corresponds to the matrix built from `Matrix.kronecker`. -/ theorem TensorProduct.toMatrix_map (f : M →ₗ[R] M') (g : N →ₗ[R] N') : toMatrix (bM.tensorProduct bN) (bM'.tensorProduct bN') (TensorProduct.map f g) = toMatrix bM bM' f ⊗ₖ toMatrix bN bN' g := by ext ⟨i, j⟩ ⟨i', j'⟩ simp_rw [Matrix.kroneckerMap_apply, toMatrix_apply, Basis.tensorProduct_apply, TensorProduct.map_tmul, Basis.tensorProduct_repr_tmul_apply] exact mul_comm _ _ /-- The matrix built from `Matrix.kronecker` corresponds to the linear map built from `TensorProduct.map`. -/ theorem Matrix.toLin_kronecker (A : Matrix ι' ι R) (B : Matrix κ' κ R) : toLin (bM.tensorProduct bN) (bM'.tensorProduct bN') (A ⊗ₖ B) = TensorProduct.map (toLin bM bM' A) (toLin bN bN' B) := by rw [← LinearEquiv.eq_symm_apply, toLin_symm, TensorProduct.toMatrix_map, toMatrix_toLin, toMatrix_toLin] /-- `TensorProduct.comm` corresponds to a permutation of the identity matrix. -/ theorem TensorProduct.toMatrix_comm : toMatrix (bM.tensorProduct bN) (bN.tensorProduct bM) (TensorProduct.comm R M N) = (1 : Matrix (ι × κ) (ι × κ) R).submatrix Prod.swap _root_.id := by ext ⟨i, j⟩ ⟨i', j'⟩ simp only [toMatrix_apply, Basis.tensorProduct_apply, LinearEquiv.coe_coe, comm_tmul, Basis.tensorProduct_repr_tmul_apply, Basis.repr_self, Finsupp.single_apply, @eq_comm _ i', @eq_comm _ j', smul_eq_mul, mul_ite, mul_one, mul_zero, ← ite_and, and_comm, submatrix_apply, Matrix.one_apply, Prod.swap_prod_mk, id_eq, Prod.mk.injEq] /-- `TensorProduct.assoc` corresponds to a permutation of the identity matrix. -/ theorem TensorProduct.toMatrix_assoc : toMatrix ((bM.tensorProduct bN).tensorProduct bP) (bM.tensorProduct (bN.tensorProduct bP)) (TensorProduct.assoc R M N P) = (1 : Matrix (ι × κ × τ) (ι × κ × τ) R).submatrix _root_.id (Equiv.prodAssoc _ _ _) := by ext ⟨i, j, k⟩ ⟨⟨i', j'⟩, k'⟩ simp only [toMatrix_apply, Basis.tensorProduct_apply, LinearEquiv.coe_coe, assoc_tmul, Basis.tensorProduct_repr_tmul_apply, Basis.repr_self, Finsupp.single_apply, @eq_comm _ k', @eq_comm _ j', smul_eq_mul, mul_ite, mul_one, mul_zero, ← ite_and, @eq_comm _ i', submatrix_apply, Matrix.one_apply, id_eq, Equiv.prodAssoc_apply, Prod.mk.injEq]
.lake/packages/mathlib/Mathlib/LinearAlgebra/TensorProduct/Vanishing.lean
import Mathlib.LinearAlgebra.TensorProduct.RightExactness import Mathlib.LinearAlgebra.TensorProduct.Finiteness import Mathlib.LinearAlgebra.DirectSum.Finsupp /-! # Vanishing of elements in a tensor product of two modules Let $M$ and $N$ be modules over a commutative ring $R$. Recall that every element of $M \otimes N$ can be written as a finite sum $\sum_{i} m_i \otimes n_i$ of pure tensors (`TensorProduct.exists_finset`). We would like to determine under what circumstances such an expression vanishes. Let us say that an expression $\sum_{i \in \iota} m_i \otimes n_i$ in $M \otimes N$ *vanishes trivially* (`TensorProduct.VanishesTrivially`) if there exist a finite index type $\kappa$ = `Fin k`, elements $(y_j)_{j \in \kappa}$ of $N$, and elements $(a_{ij})_{i \in \iota, j \in \kappa}$ of $R$ such that for all $i$, $$n_i = \sum_j a_{ij} y_j$$ and for all $j$, $$\sum_i a_{ij} m_i = 0.$$ (The terminology "trivial" comes from [Stacks 00HK](https://stacks.math.columbia.edu/tag/00HK).) It is not difficult to show (`TensorProduct.sum_tmul_eq_zero_of_vanishesTrivially`) that if $\sum_i m_i \otimes n_i$ vanishes trivially, then it vanishes; that is, $\sum_i m_i \otimes n_i = 0$. The *equational criterion for vanishing* (`TensorProduct.vanishesTrivially_iff_sum_tmul_eq_zero`), which appears as [A. Altman and S. Kleiman, *A term of commutative algebra* (Lemma 8.16)][altman2021term], states that if the elements $m_i$ generate the module $M$, then $\sum_i m_i \otimes n_i = 0$ if and only if the expression $\sum_i m_i \otimes n_i$ vanishes trivially. We also prove the following generalization (`TensorProduct.vanishesTrivially_iff_sum_tmul_eq_zero_of_rTensor_injective`). If the submodule $M' \subseteq M$ generated by the $m_i$ satisfies the property that the induced map $M' \otimes N \to M \otimes N$ is injective, then $\sum_i m_i \otimes n_i = 0$ if and only if the expression $\sum_i m_i \otimes n_i$ vanishes trivially. (In the case that $M = R$, this yields the *equational criterion for flatness* `Module.Flat.iff_forall_isTrivialRelation`.) Conversely (`TensorProduct.rTensor_injective_of_forall_vanishesTrivially`), suppose that for every equation $\sum_i m_i \otimes n_i = 0$, the expression $\sum_i m_i \otimes n_i$ vanishes trivially. Then the induced map $M' \otimes N \to M \otimes N$ is injective for every submodule $M' \subseteq M$. ## References * [A. Altman and S. Kleiman, *A term of commutative algebra* (Lemma 8.16)][altman2021term] ## TODO * Prove the same theorems with $M$ and $N$ swapped. -/ variable (R : Type*) [CommRing R] variable {M : Type*} [AddCommGroup M] [Module R M] variable {N : Type*} [AddCommGroup N] [Module R N] open DirectSum LinearMap Function Submodule Finsupp namespace TensorProduct variable {ι : Type*} [Fintype ι] {m : ι → M} {n : ι → N} variable (m n) in /-- An expression $\sum_i m_i \otimes n_i$ in $M \otimes N$ *vanishes trivially* if there exist a finite index type $\kappa$ = `Fin k`, elements $(y_j)_{j \in \kappa}$ of $N$, and elements $(a_{ij})_{i \in \iota, j \in \kappa}$ of $R$ such that for all $i$, $$n_i = \sum_j a_{ij} y_j$$ and for all $j$, $$\sum_i a_{ij} m_i = 0.$$ Note that this condition is not symmetric in $M$ and $N$. (The terminology "trivial" comes from [Stacks 00HK](https://stacks.math.columbia.edu/tag/00HK).) -/ abbrev VanishesTrivially : Prop := ∃ (k : ℕ) (a : ι → Fin k → R) (y : Fin k → N), (∀ i, n i = ∑ j, a i j • y j) ∧ ∀ j, ∑ i, a i j • m i = 0 variable {R} theorem VanishesTrivially.of_fintype {κ} [Fintype κ] (a : ι → κ → R) (y : κ → N) (hay : ∀ i, n i = ∑ j, a i j • y j) (ham : ∀ j, ∑ i, a i j • m i = 0) : VanishesTrivially R m n := have e := (Fintype.equivFin κ).symm ⟨Fintype.card κ, (a · ∘ e), y ∘ e, by simpa only [← e.sum_comp] using hay, by rwa [← e.forall_congr_right] at ham⟩ theorem _root_.Equiv.vanishesTrivially_comp {κ} [Fintype κ] (e : κ ≃ ι) : VanishesTrivially R (m ∘ e) (n ∘ e) ↔ VanishesTrivially R m n := by simp [VanishesTrivially, ← e.forall_congr_right, ← (e.arrowCongr (.refl _)).exists_congr_right, ← e.sum_comp] variable (R) /-- **Equational criterion for vanishing** [A. Altman and S. Kleiman, *A term of commutative algebra* (Lemma 8.16)][altman2021term], backward direction. If the expression $\sum_i m_i \otimes n_i$ vanishes trivially, then it vanishes. That is, $\sum_i m_i \otimes n_i = 0$. -/ theorem sum_tmul_eq_zero_of_vanishesTrivially (hmn : VanishesTrivially R m n) : ∑ i, m i ⊗ₜ n i = (0 : M ⊗[R] N) := by obtain ⟨k, a, y, h₁, h₂⟩ := hmn simp_rw [h₁, tmul_sum, tmul_smul] rw [Finset.sum_comm] simp_rw [← tmul_smul, ← smul_tmul, ← sum_tmul, h₂, zero_tmul, Finset.sum_const_zero] /-- **Equational criterion for vanishing** [A. Altman and S. Kleiman, *A term of commutative algebra* (Lemma 8.16)][altman2021term], forward direction. Assume that the $m_i$ generate $M$. If the expression $\sum_i m_i \otimes n_i$ vanishes, then it vanishes trivially. -/ theorem vanishesTrivially_of_sum_tmul_eq_zero (hm : Submodule.span R (Set.range m) = ⊤) (hmn : ∑ i, m i ⊗ₜ n i = (0 : M ⊗[R] N)) : VanishesTrivially R m n := by -- Define a map $G \colon R^\iota \to M$ whose matrix entries are the $m_i$. It is surjective. set G : (ι →₀ R) →ₗ[R] M := Finsupp.linearCombination R m with hG have G_basis_eq (i : ι) : G (Finsupp.single i 1) = m i := by simp [hG] have G_surjective : Surjective G := by apply LinearMap.range_eq_top.mp apply top_le_iff.mp rw [← hm] apply Submodule.span_le.mpr rintro _ ⟨i, rfl⟩ use Finsupp.single i 1, G_basis_eq i /- Consider the element $\sum_i e_i \otimes n_i$ of $R^\iota \otimes N$. It is in the kernel of $R^\iota \otimes N \to M \otimes N$. -/ set en : (ι →₀ R) ⊗[R] N := ∑ i, Finsupp.single i 1 ⊗ₜ n i with hen have en_mem_ker : en ∈ ker (rTensor N G) := by simp [hen, G_basis_eq, hmn] -- We have an exact sequence $\ker G \to R^\iota \to M \to 0$. have exact_ker_subtype : Exact (ker G).subtype G := G.exact_subtype_ker_map -- Tensor the exact sequence with $N$. have exact_rTensor_ker_subtype : Exact (rTensor N (ker G).subtype) (rTensor N G) := rTensor_exact (M := ↥(ker G)) N exact_ker_subtype G_surjective /- We conclude that $\sum_i e_i \otimes n_i$ is in the range of $\ker G \otimes N \to R^\iota \otimes N$. -/ have en_mem_range : en ∈ range (rTensor N (ker G).subtype) := exact_rTensor_ker_subtype.linearMap_ker_eq ▸ en_mem_ker /- There is an element of in $\ker G \otimes N$ that maps to $\sum_i e_i \otimes n_i$. Write it as a finite sum of pure tensors. -/ obtain ⟨kn, hkn⟩ := en_mem_range obtain ⟨ma, rfl : kn = ∑ kj ∈ ma, kj.1 ⊗ₜ[R] kj.2⟩ := exists_finset kn /- Let $\sum_j k_j \otimes y_j$ be the sum obtained in the previous step. In order to show that $\sum_i m_i \otimes n_i$ vanishes trivially, it suffices to prove that there exist $(a_{ij})_{i, j}$ such that for all $i$, $$n_i = \sum_j a_{ij} y_j$$ and for all $j$, $$\sum_i a_{ij} m_i = 0.$$ For this, take $a_{ij}$ to be the coefficient of $e_i$ in $k_j$. -/ refine .of_fintype (κ := ma) (fun i ⟨⟨kj, _⟩, _⟩ ↦ (kj : ι →₀ R) i) (fun ⟨⟨_, yj⟩, _⟩ ↦ yj) ?_ ?_ · intro i classical apply_fun finsuppScalarLeft R N ι at hkn apply_fun (· i) at hkn symm at hkn simp only [map_sum, finsuppScalarLeft_apply_tmul, zero_smul, Finsupp.single_zero, Finsupp.sum_single_index, one_smul, Finsupp.finset_sum_apply, Finsupp.single_apply, Finset.sum_ite_eq', Finset.mem_univ, ↓reduceIte, rTensor_tmul, coe_subtype, Finsupp.sum_apply, Finsupp.sum_ite_eq', Finsupp.mem_support_iff, ne_eq, ite_not, en] at hkn simp only [Finset.univ_eq_attach, Finset.sum_attach ma (fun x ↦ (x.1 : ι →₀ R) i • x.2)] convert hkn using 2 with x _ split · next h'x => rw [h'x, zero_smul] · rfl · rintro ⟨⟨⟨k, hk⟩, _⟩, _⟩ simpa only [hG, linearCombination_apply, zero_smul, implies_true, Finsupp.sum_fintype] using mem_ker.mp hk /-- **Equational criterion for vanishing** [A. Altman and S. Kleiman, *A term of commutative algebra* (Lemma 8.16)][altman2021term]. Assume that the $m_i$ generate $M$. Then the expression $\sum_i m_i \otimes n_i$ vanishes trivially if and only if it vanishes. -/ theorem vanishesTrivially_iff_sum_tmul_eq_zero (hm : Submodule.span R (Set.range m) = ⊤) : VanishesTrivially R m n ↔ ∑ i, m i ⊗ₜ n i = (0 : M ⊗[R] N) := ⟨sum_tmul_eq_zero_of_vanishesTrivially R, vanishesTrivially_of_sum_tmul_eq_zero R hm⟩ /-- **Equational criterion for vanishing** [A. Altman and S. Kleiman, *A term of commutative algebra* (Lemma 8.16)][altman2021term], forward direction, generalization. Assume that the submodule $M' \subseteq M$ generated by the $m_i$ satisfies the property that the map $M' \otimes N \to M \otimes N$ is injective. If the expression $\sum_i m_i \otimes n_i$ vanishes, then it vanishes trivially. -/ theorem vanishesTrivially_of_sum_tmul_eq_zero_of_rTensor_injective (hm : Injective (rTensor N (span R (Set.range m)).subtype)) (hmn : ∑ i, m i ⊗ₜ n i = (0 : M ⊗[R] N)) : VanishesTrivially R m n := by -- Restrict `m` on the codomain to $M'$, then apply `vanishesTrivially_of_sum_tmul_eq_zero`. have mem_M' i : m i ∈ span R (Set.range m) := subset_span ⟨i, rfl⟩ set m' : ι → span R (Set.range m) := Subtype.coind m mem_M' with m'_eq have hm' : span R (Set.range m') = ⊤ := by apply map_injective_of_injective (injective_subtype (span R (Set.range m))) rw [Submodule.map_span, Submodule.map_top, range_subtype, coe_subtype, ← Set.range_comp] rfl have hm'n : ∑ i, m' i ⊗ₜ n i = (0 : span R (Set.range m) ⊗[R] N) := by apply hm simp only [m'_eq, map_sum, rTensor_tmul, coe_subtype, Subtype.coind_coe, map_zero, hmn] have : VanishesTrivially R m' n := vanishesTrivially_of_sum_tmul_eq_zero R hm' hm'n unfold VanishesTrivially at this ⊢ convert this with κ _ a y j convert (injective_iff_map_eq_zero' _).mp (injective_subtype (span R (Set.range m))) _ simp [m'_eq] /-- **Equational criterion for vanishing** [A. Altman and S. Kleiman, *A term of commutative algebra* (Lemma 8.16)][altman2021term], generalization. Assume that the submodule $M' \subseteq M$ generated by the $m_i$ satisfies the property that the map $M' \otimes N \to M \otimes N$ is injective. Then the expression $\sum_i m_i \otimes n_i$ vanishes trivially if and only if it vanishes. -/ theorem vanishesTrivially_iff_sum_tmul_eq_zero_of_rTensor_injective (hm : Injective (rTensor N (span R (Set.range m)).subtype)) : VanishesTrivially R m n ↔ ∑ i, m i ⊗ₜ n i = (0 : M ⊗[R] N) := ⟨sum_tmul_eq_zero_of_vanishesTrivially R, vanishesTrivially_of_sum_tmul_eq_zero_of_rTensor_injective R hm⟩ /-- Converse of `TensorProduct.vanishesTrivially_of_sum_tmul_eq_zero_of_rTensor_injective`. Assume that every expression $\sum_i m_i \otimes n_i$ which vanishes also vanishes trivially. Then, for every submodule $M' \subseteq M$, the map $M' \otimes N \to M \otimes N$ is injective. -/ theorem rTensor_injective_of_forall_vanishesTrivially (hMN : ∀ {l : ℕ} {m : Fin l → M} {n : Fin l → N}, ∑ i, m i ⊗ₜ n i = (0 : M ⊗[R] N) → VanishesTrivially R m n) (M' : Submodule R M) : Injective (rTensor N M'.subtype) := by apply (injective_iff_map_eq_zero _).mpr rintro x hx obtain ⟨s, rfl⟩ := exists_finset x rw [← Finset.sum_attach] apply sum_tmul_eq_zero_of_vanishesTrivially simp only [map_sum, rTensor_tmul, coe_subtype] at hx have e := (Fintype.equivFin s).symm rw [← Finset.sum_coe_sort, ← e.sum_comp] at hx have := hMN hx rw [← e.vanishesTrivially_comp] unfold VanishesTrivially at this ⊢ convert this symm convert (injective_iff_map_eq_zero' _).mp (injective_subtype M') _ simp /-- Every expression $\sum_i m_i \otimes n_i$ which vanishes also vanishes trivially if and only if for every submodule $M' \subseteq M$, the map $M' \otimes N \to M \otimes N$ is injective. -/ theorem forall_vanishesTrivially_iff_forall_rTensor_injective : (∀ {l : ℕ} {m : Fin l → M} {n : Fin l → N}, ∑ i, m i ⊗ₜ n i = (0 : M ⊗[R] N) → VanishesTrivially R m n) ↔ ∀ M' : Submodule R M, Injective (rTensor N M'.subtype) := by constructor · intro h exact rTensor_injective_of_forall_vanishesTrivially R h · intro h k m n hmn exact vanishesTrivially_of_sum_tmul_eq_zero_of_rTensor_injective R (h _) hmn /-- Every expression $\sum_i m_i \otimes n_i$ which vanishes also vanishes trivially if and only if for every finitely generated submodule $M' \subseteq M$, the map $M' \otimes N \to M \otimes N$ is injective. -/ theorem forall_vanishesTrivially_iff_forall_fg_rTensor_injective : (∀ {l : ℕ} {m : Fin l → M} {n : Fin l → N}, ∑ i, m i ⊗ₜ n i = (0 : M ⊗[R] N) → VanishesTrivially R m n) ↔ ∀ (M' : Submodule R M) (_ : M'.FG), Injective (rTensor N M'.subtype) := by constructor · intro h M' _ exact rTensor_injective_of_forall_vanishesTrivially R h M' · intro h k m n hmn exact vanishesTrivially_of_sum_tmul_eq_zero_of_rTensor_injective R (h _ (fg_span (Set.finite_range _))) hmn /-- If the map $M' \otimes N \to M \otimes N$ is injective for every finitely generated submodule $M' \subseteq M$, then it is in fact injective for every submodule $M' \subseteq M$. -/ theorem rTensor_injective_of_forall_fg_rTensor_injective (hMN : ∀ (M' : Submodule R M) (_ : M'.FG), Injective (rTensor N M'.subtype)) (M' : Submodule R M) : Injective (rTensor N M'.subtype) := (forall_vanishesTrivially_iff_forall_rTensor_injective R).mp ((forall_vanishesTrivially_iff_forall_fg_rTensor_injective R).mpr hMN) M' end TensorProduct
.lake/packages/mathlib/Mathlib/LinearAlgebra/TensorProduct/Prod.lean
import Mathlib.LinearAlgebra.Prod import Mathlib.LinearAlgebra.TensorProduct.Tower /-! # Tensor products of products This file shows that taking `TensorProduct`s commutes with taking `Prod`s in both arguments. ## Main results * `TensorProduct.prodLeft` * `TensorProduct.prodRight` ## Notes See `Mathlib/LinearAlgebra/TensorProduct/Pi.lean` for arbitrary products. -/ variable (R S M₁ M₂ M₃ : Type*) namespace TensorProduct variable [CommSemiring R] [Semiring S] [AddCommMonoid M₁] [AddCommMonoid M₂] [AddCommMonoid M₃] variable [Algebra R S] variable [Module R M₁] [Module S M₁] [IsScalarTower R S M₁] [Module R M₂] [Module R M₃] attribute [ext] TensorProduct.ext /-- Tensor products distribute over a product on the right. -/ def prodRight : M₁ ⊗[R] (M₂ × M₃) ≃ₗ[S] (M₁ ⊗[R] M₂) × (M₁ ⊗[R] M₃) := LinearEquiv.ofLinear (TensorProduct.AlgebraTensorModule.lift <| LinearMap.prodMapLinear R M₂ M₃ (M₁ ⊗[R] M₂) (M₁ ⊗[R] M₃) S ∘ₗ LinearMap.prod (AlgebraTensorModule.mk R S M₁ M₂) (AlgebraTensorModule.mk R S M₁ M₃)) (LinearMap.coprod (AlgebraTensorModule.lTensor _ _ <| LinearMap.inl _ _ _) (AlgebraTensorModule.lTensor _ _ <| LinearMap.inr _ _ _)) (by ext <;> simp) (by ext <;> simp) @[simp] theorem prodRight_tmul (m₁ : M₁) (m : M₂ × M₃) : prodRight R S M₁ M₂ M₃ (m₁ ⊗ₜ m) = (m₁ ⊗ₜ m.1, m₁ ⊗ₜ m.2) := rfl @[simp] theorem prodRight_symm_tmul (m₁ : M₁) (m₂ : M₂) (m₃ : M₃) : (prodRight R S M₁ M₂ M₃).symm (m₁ ⊗ₜ m₂, m₁ ⊗ₜ m₃) = (m₁ ⊗ₜ (m₂, m₃)) := (LinearEquiv.symm_apply_eq _).mpr rfl variable [Module S M₂] [IsScalarTower R S M₂] /-- Tensor products distribute over a product on the left . -/ def prodLeft : (M₁ × M₂) ⊗[R] M₃ ≃ₗ[S] (M₁ ⊗[R] M₃) × (M₂ ⊗[R] M₃) := AddEquiv.toLinearEquiv (TensorProduct.comm _ _ _ ≪≫ₗ TensorProduct.prodRight R R _ _ _ ≪≫ₗ (TensorProduct.comm R _ _).prodCongr (TensorProduct.comm R _ _)).toAddEquiv fun c x ↦ x.induction_on (by simp) (by simp [TensorProduct.smul_tmul']) (by simp_all) @[simp] theorem prodLeft_tmul (m₁ : M₁) (m₂ : M₂) (m₃ : M₃) : prodLeft R S M₁ M₂ M₃ ((m₁, m₂) ⊗ₜ m₃) = (m₁ ⊗ₜ m₃, m₂ ⊗ₜ m₃) := rfl @[simp] theorem prodLeft_symm_tmul (m₁ : M₁) (m₂ : M₂) (m₃ : M₃) : (prodLeft R S M₁ M₂ M₃).symm (m₁ ⊗ₜ m₃, m₂ ⊗ₜ m₃) = ((m₁, m₂) ⊗ₜ m₃) := (LinearEquiv.symm_apply_eq _).mpr rfl end TensorProduct
.lake/packages/mathlib/Mathlib/LinearAlgebra/TensorProduct/Tower.lean
import Mathlib.Algebra.Algebra.Tower import Mathlib.LinearAlgebra.TensorProduct.Associator /-! # The `A`-module structure on `M ⊗[R] N` When `M` is both an `R`-module and an `A`-module, and `Algebra R A`, then many of the morphisms preserve the actions by `A`. The `Module` instance itself is provided elsewhere as `TensorProduct.leftModule`. This file provides more general versions of the definitions already in `LinearAlgebra/TensorProduct`. In this file, we use the convention that `M`, `N`, `P`, `Q` are all `R`-modules, but only `M` and `P` are simultaneously `A`-modules. ## Main definitions * `TensorProduct.AlgebraTensorModule.curry` * `TensorProduct.AlgebraTensorModule.uncurry` * `TensorProduct.AlgebraTensorModule.lcurry` * `TensorProduct.AlgebraTensorModule.lift` * `TensorProduct.AlgebraTensorModule.lift.equiv` * `TensorProduct.AlgebraTensorModule.mk` * `TensorProduct.AlgebraTensorModule.map` * `TensorProduct.AlgebraTensorModule.mapBilinear` * `TensorProduct.AlgebraTensorModule.congr` * `TensorProduct.AlgebraTensorModule.rid` * `TensorProduct.AlgebraTensorModule.homTensorHomMap` * `TensorProduct.AlgebraTensorModule.assoc` * `TensorProduct.AlgebraTensorModule.leftComm` * `TensorProduct.AlgebraTensorModule.rightComm` * `TensorProduct.AlgebraTensorModule.tensorTensorTensorComm` * `LinearMap.baseChange A f` is the `A`-linear map `A ⊗ f`, for an `R`-linear map `f`. ## Implementation notes We could thus consider replacing the less general definitions with these ones. If we do this, we probably should still implement the less general ones as abbreviations to the more general ones with fewer type arguments. -/ namespace TensorProduct namespace AlgebraTensorModule universe uR uS uA uB uM uN uP uQ uP' uQ' variable {R : Type uR} {S : Type uS} {A : Type uA} {B : Type uB} variable {M : Type uM} {N : Type uN} {P : Type uP} {Q : Type uQ} {P' : Type uP'} {Q' : Type uQ'} open LinearMap open Algebra (lsmul) section Semiring variable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B] variable [AddCommMonoid M] [Module R M] [Module A M] variable [IsScalarTower R A M] variable [AddCommMonoid N] [Module R N] variable [AddCommMonoid P] [Module R P] [Module A P] variable [IsScalarTower R A P] variable [AddCommMonoid Q] [Module R Q] variable [AddCommMonoid P'] [Module R P'] [Module A P'] [Module B P'] variable [IsScalarTower R A P'] [IsScalarTower R B P'] [SMulCommClass A B P'] variable [AddCommMonoid Q'] [Module R Q'] theorem smul_eq_lsmul_rTensor (a : A) (x : M ⊗[R] N) : a • x = (lsmul R R M a).rTensor N x := rfl /-- Heterobasic version of `TensorProduct.curry`: Given a linear map `M ⊗[R] N →[A] P`, compose it with the canonical bilinear map `M →[A] N →[R] M ⊗[R] N` to form a bilinear map `M →[A] N →[R] P`. -/ @[simps] nonrec def curry (f : M ⊗[R] N →ₗ[A] P) : M →ₗ[A] N →ₗ[R] P := { curry (f.restrictScalars R) with toFun := curry (f.restrictScalars R) map_smul' := fun c x => LinearMap.ext fun y => f.map_smul c (x ⊗ₜ y) } theorem restrictScalars_curry (f : M ⊗[R] N →ₗ[A] P) : restrictScalars R (curry f) = TensorProduct.curry (f.restrictScalars R) := rfl /-- Just as `TensorProduct.ext` is marked `ext` instead of `TensorProduct.ext'`, this is a better `ext` lemma than `TensorProduct.AlgebraTensorModule.ext` below. See note [partially-applied ext lemmas]. -/ @[ext high] nonrec theorem curry_injective : Function.Injective (curry : (M ⊗ N →ₗ[A] P) → M →ₗ[A] N →ₗ[R] P) := fun _ _ h => LinearMap.restrictScalars_injective R <| curry_injective <| (congr_arg (LinearMap.restrictScalars R) h :) theorem ext {g h : M ⊗[R] N →ₗ[A] P} (H : ∀ x y, g (x ⊗ₜ y) = h (x ⊗ₜ y)) : g = h := curry_injective <| LinearMap.ext₂ H /-- Heterobasic version of `TensorProduct.lift`: Constructing a linear map `M ⊗[R] N →[A] P` given a bilinear map `M →[A] N →[R] P` with the property that its composition with the canonical bilinear map `M →[A] N →[R] M ⊗[R] N` is the given bilinear map `M →[A] N →[R] P`. -/ nonrec def lift (f : M →ₗ[A] N →ₗ[R] P) : M ⊗[R] N →ₗ[A] P := { lift (f.restrictScalars R) with map_smul' := fun c => show ∀ x : M ⊗[R] N, (lift (f.restrictScalars R)).comp (lsmul R R _ c) x = (lsmul R R _ c).comp (lift (f.restrictScalars R)) x from LinearMap.ext_iff.1 <| TensorProduct.ext' fun x y => by simp only [comp_apply, Algebra.lsmul_coe, smul_tmul', lift.tmul, coe_restrictScalars, f.map_smul, smul_apply] } @[simp] theorem lift_apply (f : M →ₗ[A] N →ₗ[R] P) (a : M ⊗[R] N) : AlgebraTensorModule.lift f a = TensorProduct.lift (LinearMap.restrictScalars R f) a := rfl @[simp] theorem lift_tmul (f : M →ₗ[A] N →ₗ[R] P) (x : M) (y : N) : lift f (x ⊗ₜ y) = f x y := rfl variable (R A B M N P Q) section variable [Module B P] [IsScalarTower R B P] [SMulCommClass A B P] /-- Heterobasic version of `TensorProduct.uncurry`: Linearly constructing a linear map `M ⊗[R] N →[A] P` given a bilinear map `M →[A] N →[R] P` with the property that its composition with the canonical bilinear map `M →[A] N →[R] M ⊗[R] N` is the given bilinear map `M →[A] N →[R] P`. -/ @[simps] def uncurry : (M →ₗ[A] N →ₗ[R] P) →ₗ[B] M ⊗[R] N →ₗ[A] P where toFun := lift map_add' _ _ := ext fun x y => by simp only [lift_tmul, add_apply] map_smul' _ _ := ext fun x y => by simp only [lift_tmul, smul_apply, RingHom.id_apply] /-- Heterobasic version of `TensorProduct.lcurry`: Given a linear map `M ⊗[R] N →[A] P`, compose it with the canonical bilinear map `M →[A] N →[R] M ⊗[R] N` to form a bilinear map `M →[A] N →[R] P`. -/ @[simps] def lcurry : (M ⊗[R] N →ₗ[A] P) →ₗ[B] M →ₗ[A] N →ₗ[R] P where toFun := curry map_add' _ _ := rfl map_smul' _ _ := rfl /-- Heterobasic version of `TensorProduct.lift.equiv`: A linear equivalence constructing a linear map `M ⊗[R] N →[A] P` given a bilinear map `M →[A] N →[R] P` with the property that its composition with the canonical bilinear map `M →[A] N →[R] M ⊗[R] N` is the given bilinear map `M →[A] N →[R] P`. -/ def lift.equiv : (M →ₗ[A] N →ₗ[R] P) ≃ₗ[B] M ⊗[R] N →ₗ[A] P := LinearEquiv.ofLinear (uncurry R A B M N P) (lcurry R A B M N P) (LinearMap.ext fun _ => ext fun x y => lift_tmul _ x y) (LinearMap.ext fun f => LinearMap.ext fun x => LinearMap.ext fun y => lift_tmul f x y) /-- Heterobasic version of `TensorProduct.mk`: The canonical bilinear map `M →[A] N →[R] M ⊗[R] N`. -/ @[simps! apply] nonrec def mk (A M N : Type*) [Semiring A] [AddCommMonoid M] [Module R M] [Module A M] [SMulCommClass R A M] [AddCommMonoid N] [Module R N] : M →ₗ[A] N →ₗ[R] M ⊗[R] N := { mk R M N with map_smul' := fun _ _ => rfl } variable {R A B M N P Q} /-- Heterobasic version of `TensorProduct.map` -/ def map (f : M →ₗ[A] P) (g : N →ₗ[R] Q) : M ⊗[R] N →ₗ[A] P ⊗[R] Q := lift <| { toFun := fun h => h ∘ₗ g, map_add' := fun h₁ h₂ => LinearMap.add_comp g h₂ h₁, map_smul' := fun c h => LinearMap.smul_comp c h g } ∘ₗ mk R A P Q ∘ₗ f @[simp] theorem map_tmul (f : M →ₗ[A] P) (g : N →ₗ[R] Q) (m : M) (n : N) : map f g (m ⊗ₜ n) = f m ⊗ₜ g n := rfl @[simp] theorem map_id : map (id : M →ₗ[A] M) (id : N →ₗ[R] N) = .id := ext fun _ _ => rfl theorem map_comp (f₂ : P →ₗ[A] P') (f₁ : M →ₗ[A] P) (g₂ : Q →ₗ[R] Q') (g₁ : N →ₗ[R] Q) : map (f₂.comp f₁) (g₂.comp g₁) = (map f₂ g₂).comp (map f₁ g₁) := ext fun _ _ => rfl @[simp] protected theorem map_one : map (1 : M →ₗ[A] M) (1 : N →ₗ[R] N) = 1 := map_id protected theorem map_mul (f₁ f₂ : M →ₗ[A] M) (g₁ g₂ : N →ₗ[R] N) : map (f₁ * f₂) (g₁ * g₂) = map f₁ g₁ * map f₂ g₂ := map_comp _ _ _ _ theorem map_add_left (f₁ f₂ : M →ₗ[A] P) (g : N →ₗ[R] Q) : map (f₁ + f₂) g = map f₁ g + map f₂ g := by ext simp_rw [curry_apply, TensorProduct.curry_apply, restrictScalars_apply, add_apply, map_tmul, add_apply, add_tmul] theorem map_add_right (f : M →ₗ[A] P) (g₁ g₂ : N →ₗ[R] Q) : map f (g₁ + g₂) = map f g₁ + map f g₂ := by ext simp_rw [curry_apply, TensorProduct.curry_apply, restrictScalars_apply, add_apply, map_tmul, add_apply, tmul_add] theorem map_smul_right (r : R) (f : M →ₗ[A] P) (g : N →ₗ[R] Q) : map f (r • g) = r • map f g := by ext simp_rw [curry_apply, TensorProduct.curry_apply, restrictScalars_apply, smul_apply, map_tmul, smul_apply, tmul_smul] theorem map_smul_left (b : B) (f : M →ₗ[A] P) (g : N →ₗ[R] Q) : map (b • f) g = b • map f g := by ext simp_rw [curry_apply, TensorProduct.curry_apply, restrictScalars_apply, smul_apply, map_tmul, smul_apply, smul_tmul'] /-- The heterobasic version of `map` coincides with the regular version. -/ theorem map_eq (f : M →ₗ[R] P) (g : N →ₗ[R] Q) : map f g = TensorProduct.map f g := rfl variable (A M) in /-- Heterobasic version of `LinearMap.lTensor` -/ def lTensor : (N →ₗ[R] Q) →ₗ[R] M ⊗[R] N →ₗ[A] M ⊗[R] Q where toFun f := map LinearMap.id f map_add' f₁ f₂ := map_add_right _ f₁ f₂ map_smul' _ _ := map_smul_right _ _ _ @[simp] lemma coe_lTensor (f : N →ₗ[R] Q) : (lTensor A M f : M ⊗[R] N → M ⊗[R] Q) = f.lTensor M := rfl @[simp] lemma restrictScalars_lTensor (f : N →ₗ[R] Q) : (lTensor A M f).restrictScalars R = f.lTensor M := rfl @[simp] lemma lTensor_tmul (f : N →ₗ[R] Q) (m : M) (n : N) : lTensor A M f (m ⊗ₜ[R] n) = m ⊗ₜ f n := rfl @[simp] lemma lTensor_id : lTensor A M (id : N →ₗ[R] N) = .id := ext fun _ _ => rfl lemma lTensor_comp (f₂ : Q →ₗ[R] Q') (f₁ : N →ₗ[R] Q) : lTensor A M (f₂.comp f₁) = (lTensor A M f₂).comp (lTensor A M f₁) := ext fun _ _ => rfl @[simp] lemma lTensor_one : lTensor A M (1 : N →ₗ[R] N) = 1 := map_id lemma lTensor_mul (f₁ f₂ : N →ₗ[R] N) : lTensor A M (f₁ * f₂) = lTensor A M f₁ * lTensor A M f₂ := lTensor_comp _ _ variable (R N) in /-- Heterobasic version of `LinearMap.rTensor` -/ def rTensor : (M →ₗ[A] P) →ₗ[R] M ⊗[R] N →ₗ[A] P ⊗[R] N where toFun f := map f LinearMap.id map_add' f₁ f₂ := map_add_left f₁ f₂ _ map_smul' _ _ := map_smul_left _ _ _ @[simp] lemma coe_rTensor (f : M →ₗ[A] P) : (rTensor R N f : M ⊗[R] N → P ⊗[R] N) = f.rTensor N := rfl @[simp] lemma restrictScalars_rTensor (f : M →ₗ[A] P) : (rTensor R N f).restrictScalars R = f.rTensor N := rfl @[simp] lemma rTensor_tmul (f : M →ₗ[A] P) (m : M) (n : N) : rTensor R N f (m ⊗ₜ[R] n) = f m ⊗ₜ n := rfl @[simp] lemma rTensor_id : rTensor R N (id : M →ₗ[A] M) = .id := ext fun _ _ => rfl lemma rTensor_comp (f₂ : P →ₗ[A] P') (f₁ : M →ₗ[A] P) : rTensor R N (f₂.comp f₁) = (rTensor R N f₂).comp (rTensor R N f₁) := ext fun _ _ => rfl @[simp] lemma rTensor_one : rTensor R N (1 : M →ₗ[A] M) = 1 := map_id lemma rTensor_mul (f₁ f₂ : M →ₗ[A] M) : rTensor R M (f₁ * f₂) = rTensor R M f₁ * rTensor R M f₂ := rTensor_comp _ _ variable (R A B M N P Q) /-- Heterobasic version of `TensorProduct.map_bilinear` -/ def mapBilinear : (M →ₗ[A] P) →ₗ[B] (N →ₗ[R] Q) →ₗ[R] (M ⊗[R] N →ₗ[A] P ⊗[R] Q) := LinearMap.mk₂' _ _ map map_add_left map_smul_left map_add_right map_smul_right variable {R A B M N P Q} @[simp] theorem mapBilinear_apply (f : M →ₗ[A] P) (g : N →ₗ[R] Q) : mapBilinear R A B M N P Q f g = map f g := rfl variable (R A B M N P Q) /-- Heterobasic version of `TensorProduct.homTensorHomMap` -/ def homTensorHomMap : ((M →ₗ[A] P) ⊗[R] (N →ₗ[R] Q)) →ₗ[B] (M ⊗[R] N →ₗ[A] P ⊗[R] Q) := lift <| mapBilinear R A B M N P Q variable {R A B M N P Q} @[simp] theorem homTensorHomMap_apply (f : M →ₗ[A] P) (g : N →ₗ[R] Q) : homTensorHomMap R A B M N P Q (f ⊗ₜ g) = map f g := rfl /-- Heterobasic version of `TensorProduct.congr` -/ def congr (f : M ≃ₗ[A] P) (g : N ≃ₗ[R] Q) : (M ⊗[R] N) ≃ₗ[A] (P ⊗[R] Q) := LinearEquiv.ofLinear (map f g) (map f.symm g.symm) (ext fun _m _n => congr_arg₂ (· ⊗ₜ ·) (f.apply_symm_apply _) (g.apply_symm_apply _)) (ext fun _m _n => congr_arg₂ (· ⊗ₜ ·) (f.symm_apply_apply _) (g.symm_apply_apply _)) @[simp] theorem congr_refl : congr (.refl A M) (.refl R N) = .refl A _ := LinearEquiv.toLinearMap_injective <| map_id theorem congr_trans (f₁ : M ≃ₗ[A] P) (f₂ : P ≃ₗ[A] P') (g₁ : N ≃ₗ[R] Q) (g₂ : Q ≃ₗ[R] Q') : congr (f₁.trans f₂) (g₁.trans g₂) = (congr f₁ g₁).trans (congr f₂ g₂) := LinearEquiv.toLinearMap_injective <| map_comp _ _ _ _ theorem congr_symm (f : M ≃ₗ[A] P) (g : N ≃ₗ[R] Q) : congr f.symm g.symm = (congr f g).symm := rfl @[simp] theorem congr_one : congr (1 : M ≃ₗ[A] M) (1 : N ≃ₗ[R] N) = 1 := congr_refl theorem congr_mul (f₁ f₂ : M ≃ₗ[A] M) (g₁ g₂ : N ≃ₗ[R] N) : congr (f₁ * f₂) (g₁ * g₂) = congr f₁ g₁ * congr f₂ g₂ := congr_trans _ _ _ _ @[simp] theorem congr_tmul (f : M ≃ₗ[A] P) (g : N ≃ₗ[R] Q) (m : M) (n : N) : congr f g (m ⊗ₜ n) = f m ⊗ₜ g n := rfl @[simp] theorem congr_symm_tmul (f : M ≃ₗ[A] P) (g : N ≃ₗ[R] Q) (p : P) (q : Q) : (congr f g).symm (p ⊗ₜ q) = f.symm p ⊗ₜ g.symm q := rfl variable (R A M) /-- Heterobasic version of `TensorProduct.rid`. -/ protected def rid : M ⊗[R] R ≃ₗ[A] M := LinearEquiv.ofLinear (lift <| Algebra.lsmul _ _ _ |>.toLinearMap |>.flip) (mk R A M R |>.flip 1) (LinearMap.ext <| one_smul _) (ext fun _ _ => smul_tmul _ _ _ |>.trans <| congr_arg _ <| mul_one _) /-- The heterobasic version of `rid` coincides with the regular version. -/ theorem rid_eq_rid : AlgebraTensorModule.rid R R M = TensorProduct.rid R M := rfl variable {R M} in @[simp] theorem rid_tmul (r : R) (m : M) : AlgebraTensorModule.rid R A M (m ⊗ₜ r) = r • m := rfl variable {M} in @[simp] theorem rid_symm_apply (m : M) : (AlgebraTensorModule.rid R A M).symm m = m ⊗ₜ 1 := rfl end end Semiring section CommSemiring variable [CommSemiring R] [CommSemiring A] [Semiring B] [Algebra R A] [Algebra R B] variable [AddCommMonoid M] [Module R M] [Module A M] [Module B M] variable [IsScalarTower R A M] [IsScalarTower R B M] [SMulCommClass A B M] variable [AddCommMonoid N] [Module R N] variable [AddCommMonoid P] [Module A P] variable [AddCommMonoid P'] [Module A P'] variable [AddCommMonoid Q] [Module R Q] variable (R A B M N P P' Q) attribute [local ext high] TensorProduct.ext section assoc variable [Module R P] [IsScalarTower R A P] variable [Algebra A B] [IsScalarTower A B M] /-- Heterobasic version of `TensorProduct.assoc`: `B`-linear equivalence between `(M ⊗[A] P) ⊗[R] Q` and `M ⊗[A] (P ⊗[R] Q)`. Note this is especially useful with `A = R` (where it is a "more linear" version of `TensorProduct.assoc`), or with `B = A`. -/ def assoc : (M ⊗[A] P) ⊗[R] Q ≃ₗ[B] M ⊗[A] (P ⊗[R] Q) := LinearEquiv.ofLinear (lift <| lift <| lcurry R A B P Q _ ∘ₗ mk A B M (P ⊗[R] Q)) (lift <| uncurry R A B P Q _ ∘ₗ curry (mk R B _ Q)) (by ext; rfl) (by ext; rfl) variable {M P N Q} @[simp] theorem assoc_tmul (m : M) (p : P) (q : Q) : assoc R A B M P Q ((m ⊗ₜ p) ⊗ₜ q) = m ⊗ₜ (p ⊗ₜ q) := rfl @[simp] theorem assoc_symm_tmul (m : M) (p : P) (q : Q) : (assoc R A B M P Q).symm (m ⊗ₜ (p ⊗ₜ q)) = (m ⊗ₜ p) ⊗ₜ q := rfl /-- The heterobasic version of `assoc` coincides with the regular version. -/ theorem assoc_eq : assoc R R R M P Q = TensorProduct.assoc R M P Q := rfl theorem rTensor_tensor [Module R P'] [IsScalarTower R A P'] (g : P →ₗ[A] P') : g.rTensor (M ⊗[R] N) = assoc R A A P' M N ∘ₗ map (g.rTensor M) id ∘ₗ (assoc R A A P M N).symm.toLinearMap := TensorProduct.ext <| LinearMap.ext fun _ ↦ ext fun _ _ ↦ rfl end assoc section cancelBaseChange variable [Algebra A B] [IsScalarTower A B M] /-- `B`-linear equivalence between `M ⊗[A] (A ⊗[R] N)` and `M ⊗[R] N`. In particular useful with `B = A`. -/ def cancelBaseChange : M ⊗[A] (A ⊗[R] N) ≃ₗ[B] M ⊗[R] N := letI g : (M ⊗[A] A) ⊗[R] N ≃ₗ[B] M ⊗[R] N := congr (AlgebraTensorModule.rid A B M) (.refl R N) (assoc R A B M A N).symm ≪≫ₗ g /-- Base change distributes over tensor product. -/ def distribBaseChange : A ⊗[R] (M ⊗[R] N) ≃ₗ[A] (A ⊗[R] M) ⊗[A] (A ⊗[R] N) := (cancelBaseChange _ _ _ _ _ ≪≫ₗ assoc _ _ _ _ _ _).symm variable {M P N Q} @[simp] theorem cancelBaseChange_tmul (m : M) (n : N) (a : A) : cancelBaseChange R A B M N (m ⊗ₜ (a ⊗ₜ n)) = (a • m) ⊗ₜ n := rfl @[simp] theorem cancelBaseChange_symm_tmul (m : M) (n : N) : (cancelBaseChange R A B M N).symm (m ⊗ₜ n) = m ⊗ₜ (1 ⊗ₜ n) := rfl theorem lTensor_comp_cancelBaseChange (f : N →ₗ[R] Q) : lTensor _ _ f ∘ₗ cancelBaseChange R A B M N = (cancelBaseChange R A B M Q).toLinearMap ∘ₗ lTensor _ _ (lTensor _ _ f) := by ext; simp end cancelBaseChange section leftComm variable [Module R P] [IsScalarTower R A P] /-- Heterobasic version of `TensorProduct.leftComm` -/ def leftComm : M ⊗[A] (P ⊗[R] Q) ≃ₗ[A] P ⊗[A] (M ⊗[R] Q) := let e₁ := (assoc R A A M P Q).symm let e₂ := congr (TensorProduct.comm A M P) (1 : Q ≃ₗ[R] Q) let e₃ := assoc R A A P M Q e₁ ≪≫ₗ e₂ ≪≫ₗ e₃ variable {M N P Q} @[simp] theorem leftComm_tmul (m : M) (p : P) (q : Q) : leftComm R A M P Q (m ⊗ₜ (p ⊗ₜ q)) = p ⊗ₜ (m ⊗ₜ q) := rfl @[simp] theorem leftComm_symm_tmul (m : M) (p : P) (q : Q) : (leftComm R A M P Q).symm (p ⊗ₜ (m ⊗ₜ q)) = m ⊗ₜ (p ⊗ₜ q) := rfl /-- The heterobasic version of `leftComm` coincides with the regular version. -/ theorem leftComm_eq : leftComm R R M P Q = TensorProduct.leftComm R M P Q := rfl end leftComm section rightComm variable [CommSemiring S] [Module S M] [Module S P] [Algebra S B] [IsScalarTower S B M] [SMulCommClass R S M] [SMulCommClass S R M] variable (S) in /-- A tensor product analogue of `mul_right_comm`. Suppose we have a diagram of algebras `R → B ← S`, and a `B`-module `M`, `S`-module `P`, `R`-module `Q`, then ``` (M ⊗ˢ P) ⎛ M ⎞ ⊗ˢ P ⊗ᴿ ≅ᴮ ⎜ ⊗ᴿ⎟ Q ⎝ Q ⎠ ``` -/ def rightComm : (M ⊗[S] P) ⊗[R] Q ≃ₗ[B] (M ⊗[R] Q) ⊗[S] P := LinearEquiv.ofLinear (lift (lift (LinearMap.lflip.toLinearMap ∘ₗ (AlgebraTensorModule.mk _ _ _ _).compr₂ (AlgebraTensorModule.mk _ _ _ _)))) (lift (lift (LinearMap.lflip.toLinearMap ∘ₗ (AlgebraTensorModule.mk _ _ _ _).compr₂ (AlgebraTensorModule.mk _ _ _ _)))) (by ext; simp) (by ext; simp) variable {M N P Q} @[simp] theorem rightComm_tmul (m : M) (p : P) (q : Q) : rightComm R S B M P Q ((m ⊗ₜ p) ⊗ₜ q) = (m ⊗ₜ q) ⊗ₜ p := rfl @[simp] theorem rightComm_symm : (rightComm R S B M P Q).symm = rightComm S R B M Q P := rfl theorem rightComm_symm_tmul (m : M) (p : P) (q : Q) : (rightComm R S B M P Q).symm ((m ⊗ₜ q) ⊗ₜ p) = (m ⊗ₜ p) ⊗ₜ q := rfl /-- The heterobasic version of `leftComm` coincides with the regular version. -/ theorem rightComm_eq [Module R P] : rightComm R R R M P Q = TensorProduct.rightComm R M P Q := rfl end rightComm section tensorTensorTensorComm variable [Module R P] [IsScalarTower R A P] variable [Algebra A B] [IsScalarTower A B M] variable [CommSemiring S] [Algebra R S] [Algebra S B] [Module S M] [Module S N] variable [IsScalarTower R S M] [SMulCommClass A S M] [SMulCommClass S A M] [IsScalarTower S B M] [IsScalarTower R S N] variable (S) /-- Heterobasic version of `tensorTensorTensorComm`. Suppose we have towers of algebras `R → S → B` and `R → A → B`, and a `B`-module `M`, `S`-module `N`, `A`-module `P`, `R`-module `Q`, then ``` (M ⊗ˢ N) ⎛ M ⎞ ⊗ˢ ⎛ N ⎞ ⊗ᴬ ≅ᴮ ⎜ ⊗ᴬ⎟ ⎜ ⊗ᴿ⎟ (P ⊗ᴿ Q) ⎝ P ⎠ ⎝ Q ⎠ ``` -/ def tensorTensorTensorComm : (M ⊗[S] N) ⊗[A] (P ⊗[R] Q) ≃ₗ[B] (M ⊗[A] P) ⊗[S] (N ⊗[R] Q) := (assoc R A B (M ⊗[S] N) P Q).symm ≪≫ₗ congr (rightComm A S B M N P) (.refl R Q) ≪≫ₗ assoc R _ _ (M ⊗[A] P) N Q variable {M N P Q} @[simp] theorem tensorTensorTensorComm_tmul (m : M) (n : N) (p : P) (q : Q) : tensorTensorTensorComm R S A B M N P Q ((m ⊗ₜ n) ⊗ₜ (p ⊗ₜ q)) = (m ⊗ₜ p) ⊗ₜ (n ⊗ₜ q) := rfl @[simp] theorem tensorTensorTensorComm_symm : (tensorTensorTensorComm R S A B M N P Q).symm = tensorTensorTensorComm R A S B M P N Q := rfl theorem tensorTensorTensorComm_symm_tmul (m : M) (n : N) (p : P) (q : Q) : (tensorTensorTensorComm R S A B M N P Q).symm ((m ⊗ₜ p) ⊗ₜ (n ⊗ₜ q)) = (m ⊗ₜ n) ⊗ₜ (p ⊗ₜ q) := rfl /-- The heterobasic version of `tensorTensorTensorComm` coincides with the regular version. -/ theorem tensorTensorTensorComm_eq : tensorTensorTensorComm R R R R M N P Q = TensorProduct.tensorTensorTensorComm R M N P Q := rfl end tensorTensorTensorComm end CommSemiring end AlgebraTensorModule end TensorProduct namespace LinearMap open TensorProduct /-! ### The base-change of a linear map of `R`-modules to a linear map of `A`-modules -/ section Semiring variable {R A B M N P : Type*} [CommSemiring R] variable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] variable [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] variable [Module R M] [Module R N] [Module R P] variable (r : R) (f g : M →ₗ[R] N) variable (A) in /-- `baseChange A f` for `f : M →ₗ[R] N` is the `A`-linear map `A ⊗[R] M →ₗ[A] A ⊗[R] N`. This "base change" operation is also known as "extension of scalars". -/ def baseChange (f : M →ₗ[R] N) : A ⊗[R] M →ₗ[A] A ⊗[R] N := AlgebraTensorModule.map (LinearMap.id : A →ₗ[A] A) f @[simp] theorem baseChange_tmul (a : A) (x : M) : f.baseChange A (a ⊗ₜ x) = a ⊗ₜ f x := rfl theorem baseChange_eq_ltensor : (f.baseChange A : A ⊗ M → A ⊗ N) = f.lTensor A := rfl @[simp] theorem baseChange_add : (f + g).baseChange A = f.baseChange A + g.baseChange A := by ext simp [baseChange_eq_ltensor, -baseChange_tmul] @[simp] theorem baseChange_zero : baseChange A (0 : M →ₗ[R] N) = 0 := by ext simp @[simp] theorem baseChange_smul : (r • f).baseChange A = r • f.baseChange A := by ext simp @[simp] lemma baseChange_id : (.id : M →ₗ[R] M).baseChange A = .id := by ext; simp lemma baseChange_comp (g : N →ₗ[R] P) : (g ∘ₗ f).baseChange A = g.baseChange A ∘ₗ f.baseChange A := by ext; simp variable (R M) in @[simp] lemma baseChange_one : (1 : Module.End R M).baseChange A = 1 := baseChange_id lemma baseChange_mul (f g : Module.End R M) : (f * g).baseChange A = f.baseChange A * g.baseChange A := by ext; simp variable (R A M N) /-- `baseChange` as a linear map. When `M = N`, this is true more strongly as `Module.End.baseChangeHom`. -/ @[simps] def baseChangeHom : (M →ₗ[R] N) →ₗ[R] A ⊗[R] M →ₗ[A] A ⊗[R] N where toFun := baseChange A map_add' := baseChange_add map_smul' := baseChange_smul /-- `baseChange` as an `AlgHom`. -/ @[simps!] def _root_.Module.End.baseChangeHom : Module.End R M →ₐ[R] Module.End A (A ⊗[R] M) := .ofLinearMap (LinearMap.baseChangeHom _ _ _ _) (baseChange_one _ _) baseChange_mul lemma baseChange_pow (f : Module.End R M) (n : ℕ) : (f ^ n).baseChange A = f.baseChange A ^ n := map_pow (Module.End.baseChangeHom _ _ _) f n /-- `baseChange A e` for `e : M ≃ₗ[R] N` is the `A`-linear map `A ⊗[R] M ≃ₗ[A] A ⊗[R] N`. -/ def _root_.LinearEquiv.baseChange (e : M ≃ₗ[R] N) : A ⊗[R] M ≃ₗ[A] A ⊗[R] N := AlgebraTensorModule.congr (.refl _ _) e @[simp] theorem _root_.LinearEquiv.coe_baseChange (e : M ≃ₗ[R] N) : (e.baseChange R A M N : (A ⊗[R] M →ₗ[A] A ⊗[R] N)) = e.toLinearMap.baseChange A := rfl @[simp] theorem _root_.LinearEquiv.baseChange_one : (1 : M ≃ₗ[R] M).baseChange R A M M = 1 := by ext x simp [← LinearEquiv.coe_toLinearMap] theorem _root_.LinearEquiv.baseChange_trans (e : M ≃ₗ[R] N) (f : N ≃ₗ[R] P) : (e.trans f).baseChange R A M P = (e.baseChange R A M N).trans (f.baseChange R A N P) := by ext x simp only [← LinearEquiv.coe_toLinearMap, LinearEquiv.coe_baseChange, LinearEquiv.trans_apply, LinearEquiv.coe_trans, baseChange_eq_ltensor, lTensor_comp_apply] theorem _root_.LinearEquiv.baseChange_mul (e : M ≃ₗ[R] M) (f : M ≃ₗ[R] M) : (e * f).baseChange R A M M = (e.baseChange R A M M) * (f.baseChange R A M M) := by simp [LinearEquiv.mul_eq_trans, LinearEquiv.baseChange_trans] theorem _root_.LinearEquiv.baseChange_symm (e : M ≃ₗ[R] N) : e.symm.baseChange R A N M = (e.baseChange R A M N).symm := by ext x rw [LinearEquiv.eq_symm_apply] simp [← LinearEquiv.coe_toLinearMap, LinearEquiv.coe_baseChange, baseChange_eq_ltensor, ← lTensor_comp_apply] theorem _root_.LinearEquiv.baseChange_inv (e : M ≃ₗ[R] M) : (e⁻¹).baseChange R A M M = (e.baseChange R A M M)⁻¹ := LinearEquiv.baseChange_symm R A M M e lemma _root_.LinearEquiv.baseChange_pow (f : M ≃ₗ[R] M) (n : ℕ) : (f ^ n).baseChange R A M M = f.baseChange R A M M ^ n := by induction n with | zero => simp | succ n h => simp [pow_succ, LinearEquiv.baseChange_mul, h] lemma _root_.LinearEquiv.baseChange_zpow (f : M ≃ₗ[R] M) (n : ℤ) : (f ^ n).baseChange R A M M = f.baseChange R A M M ^ n := by induction n with | zero => simp | succ n h => simp only [zpow_add_one, LinearEquiv.baseChange_mul, h] | pred n h => simp only [zpow_sub_one, LinearEquiv.baseChange_mul, h, LinearEquiv.baseChange_inv] variable {R A M N} in theorem rTensor_baseChange (φ : A →ₐ[R] B) (t : A ⊗[R] M) (f : M →ₗ[R] N) : (φ.toLinearMap.rTensor N) (f.baseChange A t) = (f.baseChange B) (φ.toLinearMap.rTensor M t) := by simp [LinearMap.baseChange_eq_ltensor, ← LinearMap.comp_apply] end Semiring section Ring variable {R A B M N : Type*} [CommRing R] variable [Ring A] [Algebra R A] [Ring B] [Algebra R B] variable [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N] variable (f g : M →ₗ[R] N) @[simp] theorem baseChange_sub : (f - g).baseChange A = f.baseChange A - g.baseChange A := by ext simp [tmul_sub] @[simp] theorem baseChange_neg : (-f).baseChange A = -f.baseChange A := by ext simp [tmul_neg] end Ring end LinearMap namespace Submodule open TensorProduct variable {R M : Type*} (A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] [AddCommMonoid M] [Module R M] (p : Submodule R M) /-- If `A` is an `R`-algebra, any `R`-submodule `p` of an `R`-module `M` may be pushed forward to an `A`-submodule of `A ⊗ M`. This "base change" operation is also known as "extension of scalars". -/ def baseChange : Submodule A (A ⊗[R] M) := LinearMap.range (p.subtype.baseChange A) variable {A p} in lemma tmul_mem_baseChange_of_mem (a : A) {m : M} (hm : m ∈ p) : a ⊗ₜ[R] m ∈ p.baseChange A := ⟨a ⊗ₜ[R] ⟨m, hm⟩, rfl⟩ lemma baseChange_eq_span : p.baseChange A = span A (p.map (TensorProduct.mk R A M 1)) := by refine le_antisymm ?_ ?_ · rw [baseChange, LinearMap.range_le_iff_comap, eq_top_iff, ← span_eq_top_of_span_eq_top R A _ (span_tmul_eq_top R ..), span_le] refine fun _ ⟨a, m, h⟩ ↦ ?_ rw [← h, SetLike.mem_coe, mem_comap, LinearMap.baseChange_tmul, ← mul_one a, ← smul_eq_mul, ← smul_tmul'] exact smul_mem _ a (subset_span ⟨m, m.2, rfl⟩) · refine span_le.2 fun _ ⟨m, hm, h⟩ ↦ h ▸ ⟨1 ⊗ₜ[R] ⟨m, hm⟩, rfl⟩ @[simp] lemma baseChange_bot : (⊥ : Submodule R M).baseChange A = ⊥ := by simp [baseChange_eq_span] @[simp] lemma baseChange_top : (⊤ : Submodule R M).baseChange A = ⊤ := by rw [eq_top_iff, ← span_eq_top_of_span_eq_top R A _ (span_tmul_eq_top R ..)] exact span_le.2 fun _ ⟨a, m, h⟩ ↦ h ▸ tmul_mem_baseChange_of_mem _ trivial @[simp] lemma baseChange_span (s : Set M) : (span R s).baseChange A = span A (TensorProduct.mk R A M 1 '' s) := by rw [baseChange_eq_span, map_span, span_span_of_tower] end Submodule
.lake/packages/mathlib/Mathlib/LinearAlgebra/TensorProduct/DirectLimit.lean
import Mathlib.Algebra.Colimit.Module import Mathlib.LinearAlgebra.TensorProduct.Basic /-! # Tensor product and direct limits commute with each other. Given a family of `R`-modules `Gᵢ` with a family of compatible `R`-linear maps `fᵢⱼ : Gᵢ → Gⱼ` for every `i ≤ j` and another `R`-module `M`, we have `(limᵢ Gᵢ) ⊗ M` and `lim (Gᵢ ⊗ M)` are isomorphic as `R`-modules. ## Main definitions: * `TensorProduct.directLimitLeft : DirectLimit G f ⊗[R] M ≃ₗ[R] DirectLimit (G · ⊗[R] M) (f ▷ M)` * `TensorProduct.directLimitRight : M ⊗[R] DirectLimit G f ≃ₗ[R] DirectLimit (M ⊗[R] G ·) (M ◁ f)` -/ open TensorProduct Module Module.DirectLimit variable {R : Type*} [CommSemiring R] variable {ι : Type*} variable [DecidableEq ι] [Preorder ι] variable {G : ι → Type*} variable [∀ i, AddCommMonoid (G i)] [∀ i, Module R (G i)] variable (f : ∀ i j, i ≤ j → G i →ₗ[R] G j) variable (M : Type*) [AddCommMonoid M] [Module R M] -- alluding to the notation in `CategoryTheory.Monoidal` local notation M " ◁ " f => fun i j h ↦ LinearMap.lTensor M (f _ _ h) local notation f " ▷ " N => fun i j h ↦ LinearMap.rTensor N (f _ _ h) namespace TensorProduct /-- the map `limᵢ (Gᵢ ⊗ M) → (limᵢ Gᵢ) ⊗ M` induced by the family of maps `Gᵢ ⊗ M → (limᵢ Gᵢ) ⊗ M` given by `gᵢ ⊗ m ↦ [gᵢ] ⊗ m`. -/ noncomputable def fromDirectLimit : DirectLimit (G · ⊗[R] M) (f ▷ M) →ₗ[R] DirectLimit G f ⊗[R] M := Module.DirectLimit.lift _ _ _ _ (fun _ ↦ (of _ _ _ _ _).rTensor M) fun _ _ _ x ↦ by refine x.induction_on ?_ ?_ ?_ <;> aesop variable {M} in @[simp] lemma fromDirectLimit_of_tmul {i : ι} (g : G i) (m : M) : fromDirectLimit f M (of _ _ _ _ i (g ⊗ₜ m)) = (of _ _ _ f i g) ⊗ₜ m := lift_of (G := (G · ⊗[R] M)) _ _ (g ⊗ₜ m) /-- the map `(limᵢ Gᵢ) ⊗ M → limᵢ (Gᵢ ⊗ M)` from the bilinear map `limᵢ Gᵢ → M → limᵢ (Gᵢ ⊗ M)` given by the family of maps `Gᵢ → M → limᵢ (Gᵢ ⊗ M)` where `gᵢ ↦ m ↦ [gᵢ ⊗ m]` -/ noncomputable def toDirectLimit : DirectLimit G f ⊗[R] M →ₗ[R] DirectLimit (G · ⊗[R] M) (f ▷ M) := TensorProduct.lift <| Module.DirectLimit.lift _ _ _ _ (fun i ↦ (TensorProduct.mk R _ _).compr₂ (of R ι _ (fun _i _j h ↦ (f _ _ h).rTensor M) i)) fun _ _ _ g ↦ DFunLike.ext _ _ (of_f (G := (G · ⊗[R] M)) (x := g ⊗ₜ ·)) variable {M} in @[simp] lemma toDirectLimit_tmul_of {i : ι} (g : G i) (m : M) : (toDirectLimit f M <| (of _ _ G f i g) ⊗ₜ m) = (of _ _ _ _ i (g ⊗ₜ m)) := by rw [toDirectLimit, lift.tmul, lift_of] rfl attribute [local ext] TensorProduct.ext in /-- `limᵢ (Gᵢ ⊗ M)` and `(limᵢ Gᵢ) ⊗ M` are isomorphic as modules -/ noncomputable def directLimitLeft : DirectLimit G f ⊗[R] M ≃ₗ[R] DirectLimit (G · ⊗[R] M) (f ▷ M) := LinearEquiv.ofLinear (toDirectLimit f M) (fromDirectLimit f M) (by ext; simp) (by ext; simp) @[simp] lemma directLimitLeft_tmul_of {i : ι} (g : G i) (m : M) : directLimitLeft f M (of _ _ _ _ _ g ⊗ₜ m) = of _ _ _ (f ▷ M) _ (g ⊗ₜ m) := toDirectLimit_tmul_of f g m @[simp] lemma directLimitLeft_symm_of_tmul {i : ι} (g : G i) (m : M) : (directLimitLeft f M).symm (of _ _ _ _ _ (g ⊗ₜ m)) = of _ _ _ f _ g ⊗ₜ m := fromDirectLimit_of_tmul f g m lemma directLimitLeft_rTensor_of {i : ι} (x : G i ⊗[R] M) : directLimitLeft f M (LinearMap.rTensor M (of ..) x) = of _ _ _ (f ▷ M) _ x := x.induction_on (by simp) (by simp+contextual) (by simp+contextual) /-- `M ⊗ (limᵢ Gᵢ)` and `limᵢ (M ⊗ Gᵢ)` are isomorphic as modules -/ noncomputable def directLimitRight : M ⊗[R] DirectLimit G f ≃ₗ[R] DirectLimit (M ⊗[R] G ·) (M ◁ f) := TensorProduct.comm _ _ _ ≪≫ₗ directLimitLeft f M ≪≫ₗ Module.DirectLimit.congr (fun _ ↦ TensorProduct.comm _ _ _) (fun i j h ↦ TensorProduct.ext <| DFunLike.ext _ _ <| by aesop) @[simp] lemma directLimitRight_tmul_of {i : ι} (m : M) (g : G i) : directLimitRight f M (m ⊗ₜ of _ _ _ _ _ g) = of _ _ _ _ i (m ⊗ₜ g) := by simp [directLimitRight, congr_apply_of] @[simp] lemma directLimitRight_symm_of_tmul {i : ι} (m : M) (g : G i) : (directLimitRight f M).symm (of _ _ _ _ _ (m ⊗ₜ g)) = m ⊗ₜ of _ _ _ f _ g := by simp [directLimitRight, congr_symm_apply_of] variable [DirectedSystem G (f · · ·)] instance : DirectedSystem (G · ⊗[R] M) (f ▷ M) where map_self i x := by convert LinearMap.rTensor_id_apply M (G i) x; ext; apply DirectedSystem.map_self' map_map _ _ _ _ _ x := by convert ← (LinearMap.rTensor_comp_apply M _ _ x).symm; ext; apply DirectedSystem.map_map' f instance : DirectedSystem (M ⊗[R] G ·) (M ◁ f) where map_self i x := by convert LinearMap.lTensor_id_apply M _ x; ext; apply DirectedSystem.map_self' map_map _ _ _ h₁ h₂ x := by convert ← (LinearMap.lTensor_comp_apply M _ _ x).symm; ext; apply DirectedSystem.map_map' f end TensorProduct
.lake/packages/mathlib/Mathlib/LinearAlgebra/TensorProduct/Pi.lean
import Mathlib.LinearAlgebra.TensorProduct.Tower import Mathlib.LinearAlgebra.Pi /-! # Tensor product and products In this file we examine the behaviour of the tensor product with arbitrary and finite products. Let `S` be an `R`-algebra, `N` an `S`-module, `ι` an index type and `Mᵢ` a family of `R`-modules. We then have a natural map `TensorProduct.piRightHom`: `N ⊗[R] (∀ i, M i) →ₗ[S] ∀ i, N ⊗[R] M i` In general, this is not an isomorphism, but if `ι` is finite, then it is and it is packaged as `TensorProduct.piRight`. Also a special case for when `Mᵢ = R` is given. ## Notes See `Mathlib/LinearAlgebra/TensorProduct/Prod.lean` for binary products. -/ variable (R : Type*) [CommSemiring R] variable (S : Type*) [CommSemiring S] [Algebra R S] variable (N : Type*) [AddCommMonoid N] [Module R N] [Module S N] [IsScalarTower R S N] variable (ι : Type*) open LinearMap namespace TensorProduct section variable {ι} (M : ι → Type*) [∀ i, AddCommMonoid (M i)] [∀ i, Module R (M i)] private def piRightHomBil : N →ₗ[S] (∀ i, M i) →ₗ[R] ∀ i, N ⊗[R] M i where toFun n := LinearMap.pi (fun i ↦ mk R N (M i) n ∘ₗ LinearMap.proj i) map_add' _ _ := by ext simp map_smul' _ _ := rfl /-- For any `R`-module `N`, index type `ι` and family of `R`-modules `Mᵢ`, there is a natural linear map `N ⊗[R] (∀ i, M i) →ₗ ∀ i, N ⊗[R] M i`. This map is an isomorphism if `ι` is finite. -/ def piRightHom : N ⊗[R] (∀ i, M i) →ₗ[S] ∀ i, N ⊗[R] M i := AlgebraTensorModule.lift <| piRightHomBil R S N M @[simp] lemma piRightHom_tmul (x : N) (f : ∀ i, M i) : piRightHom R S N M (x ⊗ₜ f) = (fun j ↦ x ⊗ₜ f j) := rfl variable [Fintype ι] [DecidableEq ι] private def piRightInv : (∀ i, N ⊗[R] M i) →ₗ[S] N ⊗[R] ∀ i, M i := LinearMap.lsum S (fun i ↦ N ⊗[R] M i) S <| fun i ↦ AlgebraTensorModule.map LinearMap.id (single R M i) @[simp] private lemma piRightInv_apply (x : N) (m : ∀ i, M i) : piRightInv R S N M (fun i ↦ x ⊗ₜ m i) = x ⊗ₜ m := by simp only [piRightInv, lsum_apply, coeFn_sum, coe_comp, coe_proj, Finset.sum_apply, Function.comp_apply, Function.eval, AlgebraTensorModule.map_tmul, id_coe, id_eq, coe_single] rw [← tmul_sum] congr ext j simp @[simp] private lemma piRightInv_single (x : N) (i : ι) (m : M i) : piRightInv R S N M (Pi.single i (x ⊗ₜ m)) = x ⊗ₜ Pi.single i m := by have : Pi.single i (x ⊗ₜ m) = fun j ↦ x ⊗ₜ[R] (Pi.single i m j) := by ext j rw [← tmul_single] rw [this] simp /-- Tensor product commutes with finite products on the right. -/ def piRight : N ⊗[R] (∀ i, M i) ≃ₗ[S] ∀ i, N ⊗[R] M i := LinearEquiv.ofLinear (piRightHom R S N M) (piRightInv R S N M) (by ext i x m j; simp [tmul_single]) (by ext x j m; simp) @[simp] lemma piRight_apply (x : N ⊗[R] (∀ i, M i)) : piRight R S N M x = piRightHom R S N M x := by rfl @[simp] lemma piRight_symm_apply (x : N) (m : ∀ i, M i) : (piRight R S N M).symm (fun i ↦ x ⊗ₜ m i) = x ⊗ₜ m := by simp [piRight] @[simp] lemma piRight_symm_single (x : N) (i : ι) (m : M i) : (piRight R S N M).symm (Pi.single i (x ⊗ₜ m)) = x ⊗ₜ Pi.single i m := by simp [piRight] /-- Tensor product commutes with finite products on the left. TODO: generalize to `S`-linear. -/ @[simp] def piLeft : (∀ i, M i) ⊗[R] N ≃ₗ[R] ∀ i, M i ⊗[R] N := TensorProduct.comm .. ≪≫ₗ piRight .. ≪≫ₗ .piCongrRight fun _ ↦ TensorProduct.comm .. end private def piScalarRightHomBil : N →ₗ[S] (ι → R) →ₗ[R] (ι → N) where toFun n := LinearMap.compLeft (toSpanSingleton R N n) ι map_add' x y := by ext i j simp map_smul' s x := by ext i j dsimp only [coe_comp, coe_single, Function.comp_apply, compLeft_apply, toSpanSingleton_apply, RingHom.id_apply, smul_apply, Pi.smul_apply] rw [← IsScalarTower.smul_assoc, _root_.Algebra.smul_def, mul_comm, mul_smul] simp /-- For any `R`-module `N` and index type `ι`, there is a natural linear map `N ⊗[R] (ι → R) →ₗ (ι → N)`. This map is an isomorphism if `ι` is finite. -/ def piScalarRightHom : N ⊗[R] (ι → R) →ₗ[S] (ι → N) := AlgebraTensorModule.lift <| piScalarRightHomBil R S N ι @[simp] lemma piScalarRightHom_tmul (x : N) (f : ι → R) : piScalarRightHom R S N ι (x ⊗ₜ f) = (fun j ↦ f j • x) := by ext j simp [piScalarRightHom, piScalarRightHomBil] variable [Fintype ι] [DecidableEq ι] private def piScalarRightInv : (ι → N) →ₗ[S] N ⊗[R] (ι → R) := LinearMap.lsum S (fun _ ↦ N) S <| fun i ↦ { toFun := fun n ↦ n ⊗ₜ Pi.single i 1 map_add' := fun x y ↦ by simp [add_tmul] map_smul' := fun _ _ ↦ rfl } @[simp] private lemma piScalarRightInv_single (x : N) (i : ι) : piScalarRightInv R S N ι (Pi.single i x) = x ⊗ₜ Pi.single i 1 := by simp [piScalarRightInv, Pi.single_apply, TensorProduct.ite_tmul] /-- For any `R`-module `N` and finite index type `ι`, `N ⊗[R] (ι → R)` is canonically isomorphic to `ι → N`. -/ def piScalarRight : N ⊗[R] (ι → R) ≃ₗ[S] (ι → N) := LinearEquiv.ofLinear (piScalarRightHom R S N ι) (piScalarRightInv R S N ι) (by ext i x j; simp [Pi.single_apply]) (by ext x i; simp [Pi.single_apply_smul]) @[simp] lemma piScalarRight_apply (x : N ⊗[R] (ι → R)) : piScalarRight R S N ι x = piScalarRightHom R S N ι x := by rfl @[simp] lemma piScalarRight_symm_single (x : N) (i : ι) : (piScalarRight R S N ι).symm (Pi.single i x) = x ⊗ₜ Pi.single i 1 := by simp [piScalarRight] -- See also `TensorProduct.piScalarRight_symm_algebraMap` in -- `Mathlib/RingTheory/TensorProduct/Pi.lean`. end TensorProduct
.lake/packages/mathlib/Mathlib/LinearAlgebra/TensorProduct/Basic.lean
import Mathlib.Algebra.Module.Equiv.Basic import Mathlib.Algebra.Module.Shrink import Mathlib.Algebra.Module.Submodule.Bilinear import Mathlib.GroupTheory.Congruence.Hom import Mathlib.Tactic.Abel /-! # Tensor product of modules over commutative semirings. This file constructs the tensor product of modules over commutative semirings. Given a semiring `R` and modules over it `M` and `N`, the standard construction of the tensor product is `TensorProduct R M N`. It is also a module over `R`. It comes with a canonical bilinear map `TensorProduct.mk R M N : M →ₗ[R] N →ₗ[R] TensorProduct R M N`. Given any bilinear map `f : M →ₛₗ[σ₁₂] N →ₛₗ[σ₁₂] P₂`, there is a unique semilinear map `TensorProduct.lift f : TensorProduct R M N →ₛₗ[σ₁₂] P₂` whose composition with the canonical bilinear map `TensorProduct.mk` is the given bilinear map `f`. Uniqueness is shown in the theorem `TensorProduct.lift.unique`. ## Notation * This file introduces the notation `M ⊗ N` and `M ⊗[R] N` for the tensor product space `TensorProduct R M N`. * It introduces the notation `m ⊗ₜ n` and `m ⊗ₜ[R] n` for the tensor product of two elements, otherwise written as `TensorProduct.tmul R m n`. ## Tags bilinear, tensor, tensor product -/ section Semiring variable {R R₂ R₃ R' R'' : Type*} variable [CommSemiring R] [CommSemiring R₂] [CommSemiring R₃] [Monoid R'] [Semiring R''] variable {σ₁₂ : R →+* R₂} {σ₂₃ : R₂ →+* R₃} {σ₁₃ : R →+* R₃} variable {A M N P Q S : Type*} variable {M₂ M₃ N₂ N₃ P' P₂ P₃ Q' Q₂ Q₃ : Type*} variable [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] [AddCommMonoid Q] [AddCommMonoid S] variable [AddCommMonoid P'] [AddCommMonoid Q'] variable [AddCommMonoid M₂] [AddCommMonoid N₂] [AddCommMonoid P₂] [AddCommMonoid Q₂] variable [AddCommMonoid M₃] [AddCommMonoid N₃] [AddCommMonoid P₃] [AddCommMonoid Q₃] variable [DistribMulAction R' M] variable [Module R'' M] variable [Module R M] [Module R N] [Module R S] variable [Module R P'] [Module R Q'] variable [Module R₂ M₂] [Module R₂ N₂] [Module R₂ P₂] [Module R₂ Q₂] variable [Module R₃ M₃] [Module R₃ N₃] [Module R₃ P₃] [Module R₃ Q₃] variable (M N) namespace TensorProduct section variable (R) /-- The relation on `FreeAddMonoid (M × N)` that generates a congruence whose quotient is the tensor product. -/ inductive Eqv : FreeAddMonoid (M × N) → FreeAddMonoid (M × N) → Prop | of_zero_left : ∀ n : N, Eqv (.of (0, n)) 0 | of_zero_right : ∀ m : M, Eqv (.of (m, 0)) 0 | of_add_left : ∀ (m₁ m₂ : M) (n : N), Eqv (.of (m₁, n) + .of (m₂, n)) (.of (m₁ + m₂, n)) | of_add_right : ∀ (m : M) (n₁ n₂ : N), Eqv (.of (m, n₁) + .of (m, n₂)) (.of (m, n₁ + n₂)) | of_smul : ∀ (r : R) (m : M) (n : N), Eqv (.of (r • m, n)) (.of (m, r • n)) | add_comm : ∀ x y, Eqv (x + y) (y + x) end end TensorProduct variable (R) in /-- The tensor product of two modules `M` and `N` over the same commutative semiring `R`. The localized notations are `M ⊗ N` and `M ⊗[R] N`, accessed by `open scoped TensorProduct`. -/ def TensorProduct : Type _ := (addConGen (TensorProduct.Eqv R M N)).Quotient set_option quotPrecheck false in @[inherit_doc TensorProduct] scoped[TensorProduct] infixl:100 " ⊗ " => TensorProduct _ @[inherit_doc] scoped[TensorProduct] notation:100 M:100 " ⊗[" R "] " N:101 => TensorProduct R M N namespace TensorProduct section Module protected instance zero : Zero (M ⊗[R] N) := (addConGen (TensorProduct.Eqv R M N)).zero protected instance add : Add (M ⊗[R] N) := (addConGen (TensorProduct.Eqv R M N)).hasAdd instance addZeroClass : AddZeroClass (M ⊗[R] N) := { (addConGen (TensorProduct.Eqv R M N)).addMonoid with /- The `toAdd` field is given explicitly as `TensorProduct.add` for performance reasons. This avoids any need to unfold `Con.addMonoid` when the type checker is checking that instance diagrams commute -/ toAdd := TensorProduct.add _ _ toZero := TensorProduct.zero _ _ } instance addSemigroup : AddSemigroup (M ⊗[R] N) := { (addConGen (TensorProduct.Eqv R M N)).addMonoid with toAdd := TensorProduct.add _ _ } instance addCommSemigroup : AddCommSemigroup (M ⊗[R] N) := { (addConGen (TensorProduct.Eqv R M N)).addMonoid with toAddSemigroup := TensorProduct.addSemigroup _ _ add_comm := fun x y => AddCon.induction_on₂ x y fun _ _ => Quotient.sound' <| AddConGen.Rel.of _ _ <| Eqv.add_comm _ _ } instance : Inhabited (M ⊗[R] N) := ⟨0⟩ variable {M N} variable (R) in /-- The canonical function `M → N → M ⊗ N`. The localized notations are `m ⊗ₜ n` and `m ⊗ₜ[R] n`, accessed by `open scoped TensorProduct`. -/ def tmul (m : M) (n : N) : M ⊗[R] N := AddCon.mk' _ <| FreeAddMonoid.of (m, n) /-- The canonical function `M → N → M ⊗ N`. -/ infixl:100 " ⊗ₜ " => tmul _ /-- The canonical function `M → N → M ⊗ N`. -/ notation:100 x:100 " ⊗ₜ[" R "] " y:101 => tmul R x y /-- Produces an arbitrary representation of the form `mₒ ⊗ₜ n₀ + ...`. -/ unsafe instance [Repr M] [Repr N] : Repr (M ⊗[R] N) where reprPrec mn p := let parts := mn.unquot.toList.map fun (mi, ni) => Std.Format.group f!"{reprPrec mi 100} ⊗ₜ {reprPrec ni 101}" match parts with | [] => f!"0" | [part] => if p > 100 then Std.Format.bracketFill "(" part ")" else .fill part | parts => (if p > 65 then (Std.Format.bracketFill "(" · ")") else (.fill ·)) <| .joinSep parts f!" +{Std.Format.line}" @[elab_as_elim, induction_eliminator] protected theorem induction_on {motive : M ⊗[R] N → Prop} (z : M ⊗[R] N) (zero : motive 0) (tmul : ∀ x y, motive <| x ⊗ₜ[R] y) (add : ∀ x y, motive x → motive y → motive (x + y)) : motive z := AddCon.induction_on z fun x => FreeAddMonoid.recOn x zero fun ⟨m, n⟩ y ih => by rw [AddCon.coe_add] exact add _ _ (tmul ..) ih /-- Lift an `R`-balanced map to the tensor product. A map `f : M →+ N →+ P` additive in both components is `R`-balanced, or middle linear with respect to `R`, if scalar multiplication in either argument is equivalent, `f (r • m) n = f m (r • n)`. Note that strictly the first action should be a right-action by `R`, but for now `R` is commutative so it doesn't matter. -/ -- TODO: use this to implement `lift` and `SMul.aux`. For now we do not do this as it causes -- performance issues elsewhere. def liftAddHom (f : M →+ N →+ P) (hf : ∀ (r : R) (m : M) (n : N), f (r • m) n = f m (r • n)) : M ⊗[R] N →+ P := (addConGen (TensorProduct.Eqv R M N)).lift (FreeAddMonoid.lift (fun mn : M × N => f mn.1 mn.2)) <| AddCon.addConGen_le fun x y hxy => match x, y, hxy with | _, _, .of_zero_left n => (AddCon.ker_rel _).2 <| by simp_rw [map_zero, FreeAddMonoid.lift_eval_of, map_zero, AddMonoidHom.zero_apply] | _, _, .of_zero_right m => (AddCon.ker_rel _).2 <| by simp_rw [map_zero, FreeAddMonoid.lift_eval_of, map_zero] | _, _, .of_add_left m₁ m₂ n => (AddCon.ker_rel _).2 <| by simp_rw [map_add, FreeAddMonoid.lift_eval_of, map_add, AddMonoidHom.add_apply] | _, _, .of_add_right m n₁ n₂ => (AddCon.ker_rel _).2 <| by simp_rw [map_add, FreeAddMonoid.lift_eval_of, map_add] | _, _, .of_smul s m n => (AddCon.ker_rel _).2 <| by rw [FreeAddMonoid.lift_eval_of, FreeAddMonoid.lift_eval_of, hf] | _, _, .add_comm x y => (AddCon.ker_rel _).2 <| by simp_rw [map_add, add_comm] @[simp] theorem liftAddHom_tmul (f : M →+ N →+ P) (hf : ∀ (r : R) (m : M) (n : N), f (r • m) n = f m (r • n)) (m : M) (n : N) : liftAddHom f hf (m ⊗ₜ n) = f m n := rfl variable (M) in @[simp] theorem zero_tmul (n : N) : (0 : M) ⊗ₜ[R] n = 0 := Quotient.sound' <| AddConGen.Rel.of _ _ <| Eqv.of_zero_left _ theorem add_tmul (m₁ m₂ : M) (n : N) : (m₁ + m₂) ⊗ₜ n = m₁ ⊗ₜ n + m₂ ⊗ₜ[R] n := Eq.symm <| Quotient.sound' <| AddConGen.Rel.of _ _ <| Eqv.of_add_left _ _ _ variable (N) in @[simp] theorem tmul_zero (m : M) : m ⊗ₜ[R] (0 : N) = 0 := Quotient.sound' <| AddConGen.Rel.of _ _ <| Eqv.of_zero_right _ theorem tmul_add (m : M) (n₁ n₂ : N) : m ⊗ₜ (n₁ + n₂) = m ⊗ₜ n₁ + m ⊗ₜ[R] n₂ := Eq.symm <| Quotient.sound' <| AddConGen.Rel.of _ _ <| Eqv.of_add_right _ _ _ instance uniqueLeft [Subsingleton M] : Unique (M ⊗[R] N) where default := 0 uniq z := z.induction_on rfl (fun x y ↦ by rw [Subsingleton.elim x 0, zero_tmul]) <| by rintro _ _ rfl rfl; apply add_zero instance uniqueRight [Subsingleton N] : Unique (M ⊗[R] N) where default := 0 uniq z := z.induction_on rfl (fun x y ↦ by rw [Subsingleton.elim y 0, tmul_zero]) <| by rintro _ _ rfl rfl; apply add_zero section variable (R R' M N) /-- A typeclass for `SMul` structures which can be moved across a tensor product. This typeclass is generated automatically from an `IsScalarTower` instance, but exists so that we can also add an instance for `AddCommGroup.toIntModule`, allowing `z •` to be moved even if `R` does not support negation. Note that `Module R' (M ⊗[R] N)` is available even without this typeclass on `R'`; it's only needed if `TensorProduct.smul_tmul`, `TensorProduct.smul_tmul'`, or `TensorProduct.tmul_smul` is used. -/ class CompatibleSMul [DistribMulAction R' N] : Prop where smul_tmul : ∀ (r : R') (m : M) (n : N), (r • m) ⊗ₜ n = m ⊗ₜ[R] (r • n) end /-- Note that this provides the default `CompatibleSMul R R M N` instance through `IsScalarTower.left`. -/ instance (priority := 100) CompatibleSMul.isScalarTower [SMul R' R] [IsScalarTower R' R M] [DistribMulAction R' N] [IsScalarTower R' R N] : CompatibleSMul R R' M N := ⟨fun r m n => by conv_lhs => rw [← one_smul R m] conv_rhs => rw [← one_smul R n] rw [← smul_assoc, ← smul_assoc] exact Quotient.sound' <| AddConGen.Rel.of _ _ <| Eqv.of_smul _ _ _⟩ /-- `smul` can be moved from one side of the product to the other . -/ theorem smul_tmul [DistribMulAction R' N] [CompatibleSMul R R' M N] (r : R') (m : M) (n : N) : (r • m) ⊗ₜ n = m ⊗ₜ[R] (r • n) := CompatibleSMul.smul_tmul _ _ _ private def addMonoidWithWrongNSMul : AddMonoid (M ⊗[R] N) := { (addConGen (TensorProduct.Eqv R M N)).addMonoid with } attribute [local instance] addMonoidWithWrongNSMul in /-- Auxiliary function to defining scalar multiplication on tensor product. -/ def SMul.aux {R' : Type*} [SMul R' M] (r : R') : FreeAddMonoid (M × N) →+ M ⊗[R] N := FreeAddMonoid.lift fun p : M × N => (r • p.1) ⊗ₜ p.2 theorem SMul.aux_of {R' : Type*} [SMul R' M] (r : R') (m : M) (n : N) : SMul.aux r (.of (m, n)) = (r • m) ⊗ₜ[R] n := rfl variable [SMulCommClass R R' M] [SMulCommClass R R'' M] /-- Given two modules over a commutative semiring `R`, if one of the factors carries a (distributive) action of a second type of scalars `R'`, which commutes with the action of `R`, then the tensor product (over `R`) carries an action of `R'`. This instance defines this `R'` action in the case that it is the left module which has the `R'` action. Two natural ways in which this situation arises are: * Extension of scalars * A tensor product of a group representation with a module not carrying an action Note that in the special case that `R = R'`, since `R` is commutative, we just get the usual scalar action on a tensor product of two modules. This special case is important enough that, for performance reasons, we define it explicitly below. -/ instance leftHasSMul : SMul R' (M ⊗[R] N) := ⟨fun r => (addConGen (TensorProduct.Eqv R M N)).lift (SMul.aux r : _ →+ M ⊗[R] N) <| AddCon.addConGen_le fun x y hxy => match x, y, hxy with | _, _, .of_zero_left n => (AddCon.ker_rel _).2 <| by simp_rw [map_zero, SMul.aux_of, smul_zero, zero_tmul] | _, _, .of_zero_right m => (AddCon.ker_rel _).2 <| by simp_rw [map_zero, SMul.aux_of, tmul_zero] | _, _, .of_add_left m₁ m₂ n => (AddCon.ker_rel _).2 <| by simp_rw [map_add, SMul.aux_of, smul_add, add_tmul] | _, _, .of_add_right m n₁ n₂ => (AddCon.ker_rel _).2 <| by simp_rw [map_add, SMul.aux_of, tmul_add] | _, _, .of_smul s m n => (AddCon.ker_rel _).2 <| by rw [SMul.aux_of, SMul.aux_of, ← smul_comm, smul_tmul] | _, _, .add_comm x y => (AddCon.ker_rel _).2 <| by simp_rw [map_add, add_comm]⟩ instance : SMul R (M ⊗[R] N) := TensorProduct.leftHasSMul protected theorem smul_zero (r : R') : r • (0 : M ⊗[R] N) = 0 := AddMonoidHom.map_zero _ protected theorem smul_add (r : R') (x y : M ⊗[R] N) : r • (x + y) = r • x + r • y := AddMonoidHom.map_add _ _ _ protected theorem zero_smul (x : M ⊗[R] N) : (0 : R'') • x = 0 := have : ∀ (r : R'') (m : M) (n : N), r • m ⊗ₜ[R] n = (r • m) ⊗ₜ n := fun _ _ _ => rfl x.induction_on (by rw [TensorProduct.smul_zero]) (fun m n => by rw [this, zero_smul, zero_tmul]) fun x y ihx ihy => by rw [TensorProduct.smul_add, ihx, ihy, add_zero] protected theorem one_smul (x : M ⊗[R] N) : (1 : R') • x = x := have : ∀ (r : R') (m : M) (n : N), r • m ⊗ₜ[R] n = (r • m) ⊗ₜ n := fun _ _ _ => rfl x.induction_on (by rw [TensorProduct.smul_zero]) (fun m n => by rw [this, one_smul]) fun x y ihx ihy => by rw [TensorProduct.smul_add, ihx, ihy] protected theorem add_smul (r s : R'') (x : M ⊗[R] N) : (r + s) • x = r • x + s • x := have : ∀ (r : R'') (m : M) (n : N), r • m ⊗ₜ[R] n = (r • m) ⊗ₜ n := fun _ _ _ => rfl x.induction_on (by simp_rw [TensorProduct.smul_zero, add_zero]) (fun m n => by simp_rw [this, add_smul, add_tmul]) fun x y ihx ihy => by simp_rw [TensorProduct.smul_add] rw [ihx, ihy, add_add_add_comm] instance addMonoid : AddMonoid (M ⊗[R] N) := { TensorProduct.addZeroClass _ _ with toAddSemigroup := TensorProduct.addSemigroup _ _ toZero := TensorProduct.zero _ _ nsmul := fun n v => n • v nsmul_zero := by simp [TensorProduct.zero_smul] nsmul_succ := by simp only [TensorProduct.one_smul, TensorProduct.add_smul, add_comm, forall_const] } instance addCommMonoid : AddCommMonoid (M ⊗[R] N) := { TensorProduct.addCommSemigroup _ _ with toAddMonoid := TensorProduct.addMonoid } variable (R) theorem _root_.IsAddUnit.tmul_left {n : N} (hn : IsAddUnit n) (m : M) : IsAddUnit (m ⊗ₜ[R] n) := by rw [isAddUnit_iff_exists_neg] at hn ⊢ have ⟨b, eq⟩ := hn exact ⟨m ⊗ₜ[R] b, by rw [← tmul_add, eq, tmul_zero]⟩ theorem _root_.IsAddUnit.tmul_right {m : M} (hm : IsAddUnit m) (n : N) : IsAddUnit (m ⊗ₜ[R] n) := by rw [isAddUnit_iff_exists_neg] at hm ⊢ have ⟨b, eq⟩ := hm exact ⟨b ⊗ₜ[R] n, by rw [← add_tmul, eq, zero_tmul]⟩ variable {R} instance leftDistribMulAction : DistribMulAction R' (M ⊗[R] N) := have : ∀ (r : R') (m : M) (n : N), r • m ⊗ₜ[R] n = (r • m) ⊗ₜ n := fun _ _ _ => rfl { smul_add := fun r x y => TensorProduct.smul_add r x y mul_smul := fun r s x => x.induction_on (by simp_rw [TensorProduct.smul_zero]) (fun m n => by simp_rw [this, mul_smul]) fun x y ihx ihy => by simp_rw [TensorProduct.smul_add] rw [ihx, ihy] one_smul := TensorProduct.one_smul smul_zero := TensorProduct.smul_zero } instance : DistribMulAction R (M ⊗[R] N) := TensorProduct.leftDistribMulAction theorem smul_tmul' (r : R') (m : M) (n : N) : r • m ⊗ₜ[R] n = (r • m) ⊗ₜ n := rfl @[simp] theorem tmul_smul [DistribMulAction R' N] [CompatibleSMul R R' M N] (r : R') (x : M) (y : N) : x ⊗ₜ (r • y) = r • x ⊗ₜ[R] y := (smul_tmul _ _ _).symm theorem smul_tmul_smul (r s : R) (m : M) (n : N) : (r • m) ⊗ₜ[R] (s • n) = (r * s) • m ⊗ₜ[R] n := by simp_rw [smul_tmul, tmul_smul, mul_smul] theorem tmul_eq_smul_one_tmul {S : Type*} [Semiring S] [Module R S] [SMulCommClass R S S] (s : S) (m : M) : s ⊗ₜ[R] m = s • (1 ⊗ₜ[R] m) := by nth_rw 1 [← mul_one s, ← smul_eq_mul, smul_tmul'] @[deprecated (since := "2025-07-08")] alias tsmul_eq_smul_one_tuml := tmul_eq_smul_one_tmul instance leftModule : Module R'' (M ⊗[R] N) := { add_smul := TensorProduct.add_smul zero_smul := TensorProduct.zero_smul } instance : Module R (M ⊗[R] N) := TensorProduct.leftModule instance [Module R''ᵐᵒᵖ M] [IsCentralScalar R'' M] : IsCentralScalar R'' (M ⊗[R] N) where op_smul_eq_smul r x := x.induction_on (by rw [smul_zero, smul_zero]) (fun x y => by rw [smul_tmul', smul_tmul', op_smul_eq_smul]) fun x y hx hy => by rw [smul_add, smul_add, hx, hy] section -- Like `R'`, `R'₂` provides a `DistribMulAction R'₂ (M ⊗[R] N)` variable {R'₂ : Type*} [Monoid R'₂] [DistribMulAction R'₂ M] variable [SMulCommClass R R'₂ M] /-- `SMulCommClass R' R'₂ M` implies `SMulCommClass R' R'₂ (M ⊗[R] N)` -/ instance smulCommClass_left [SMulCommClass R' R'₂ M] : SMulCommClass R' R'₂ (M ⊗[R] N) where smul_comm r' r'₂ x := TensorProduct.induction_on x (by simp_rw [TensorProduct.smul_zero]) (fun m n => by simp_rw [smul_tmul', smul_comm]) fun x y ihx ihy => by simp_rw [TensorProduct.smul_add]; rw [ihx, ihy] variable [SMul R'₂ R'] /-- `IsScalarTower R'₂ R' M` implies `IsScalarTower R'₂ R' (M ⊗[R] N)` -/ instance isScalarTower_left [IsScalarTower R'₂ R' M] : IsScalarTower R'₂ R' (M ⊗[R] N) := ⟨fun s r x => x.induction_on (by simp) (fun m n => by rw [smul_tmul', smul_tmul', smul_tmul', smul_assoc]) fun x y ihx ihy => by rw [smul_add, smul_add, smul_add, ihx, ihy]⟩ variable [DistribMulAction R'₂ N] [DistribMulAction R' N] variable [CompatibleSMul R R'₂ M N] [CompatibleSMul R R' M N] /-- `IsScalarTower R'₂ R' N` implies `IsScalarTower R'₂ R' (M ⊗[R] N)` -/ instance isScalarTower_right [IsScalarTower R'₂ R' N] : IsScalarTower R'₂ R' (M ⊗[R] N) := ⟨fun s r x => x.induction_on (by simp) (fun m n => by rw [← tmul_smul, ← tmul_smul, ← tmul_smul, smul_assoc]) fun x y ihx ihy => by rw [smul_add, smul_add, smul_add, ihx, ihy]⟩ end /-- A short-cut instance for the common case, where the requirements for the `compatible_smul` instances are sufficient. -/ instance isScalarTower [SMul R' R] [IsScalarTower R' R M] : IsScalarTower R' R (M ⊗[R] N) := TensorProduct.isScalarTower_left -- or right variable (R M N) in /-- The canonical bilinear map `M → N → M ⊗[R] N`. -/ def mk : M →ₗ[R] N →ₗ[R] M ⊗[R] N := LinearMap.mk₂ R (· ⊗ₜ ·) add_tmul (fun c m n => by simp_rw [smul_tmul, tmul_smul]) tmul_add tmul_smul @[simp] theorem mk_apply (m : M) (n : N) : mk R M N m n = m ⊗ₜ n := rfl theorem ite_tmul (x₁ : M) (x₂ : N) (P : Prop) [Decidable P] : (if P then x₁ else 0) ⊗ₜ[R] x₂ = if P then x₁ ⊗ₜ x₂ else 0 := by split_ifs <;> simp theorem tmul_ite (x₁ : M) (x₂ : N) (P : Prop) [Decidable P] : (x₁ ⊗ₜ[R] if P then x₂ else 0) = if P then x₁ ⊗ₜ x₂ else 0 := by split_ifs <;> simp lemma tmul_single {ι : Type*} [DecidableEq ι] {M : ι → Type*} [∀ i, AddCommMonoid (M i)] [∀ i, Module R (M i)] (i : ι) (x : N) (m : M i) (j : ι) : x ⊗ₜ[R] Pi.single i m j = (Pi.single i (x ⊗ₜ[R] m) : ∀ i, N ⊗[R] M i) j := by by_cases h : i = j <;> aesop lemma single_tmul {ι : Type*} [DecidableEq ι] {M : ι → Type*} [∀ i, AddCommMonoid (M i)] [∀ i, Module R (M i)] (i : ι) (x : N) (m : M i) (j : ι) : Pi.single i m j ⊗ₜ[R] x = (Pi.single i (m ⊗ₜ[R] x) : ∀ i, M i ⊗[R] N) j := by by_cases h : i = j <;> aesop section theorem sum_tmul {α : Type*} (s : Finset α) (m : α → M) (n : N) : (∑ a ∈ s, m a) ⊗ₜ[R] n = ∑ a ∈ s, m a ⊗ₜ[R] n := by classical induction s using Finset.induction with | empty => simp | insert _ _ has ih => simp [Finset.sum_insert has, add_tmul, ih] theorem tmul_sum (m : M) {α : Type*} (s : Finset α) (n : α → N) : (m ⊗ₜ[R] ∑ a ∈ s, n a) = ∑ a ∈ s, m ⊗ₜ[R] n a := by classical induction s using Finset.induction with | empty => simp | insert _ _ has ih => simp [Finset.sum_insert has, tmul_add, ih] end variable (R M N) /-- The simple (aka pure) elements span the tensor product. -/ theorem span_tmul_eq_top : Submodule.span R { t : M ⊗[R] N | ∃ m n, m ⊗ₜ n = t } = ⊤ := by ext t; simp only [Submodule.mem_top, iff_true] refine t.induction_on ?_ ?_ ?_ · exact Submodule.zero_mem _ · intro m n apply Submodule.subset_span use m, n · intro t₁ t₂ ht₁ ht₂ exact Submodule.add_mem _ ht₁ ht₂ @[simp] theorem map₂_mk_top_top_eq_top : Submodule.map₂ (mk R M N) ⊤ ⊤ = ⊤ := by rw [← top_le_iff, ← span_tmul_eq_top, Submodule.map₂_eq_span_image2] exact Submodule.span_mono fun _ ⟨m, n, h⟩ => ⟨m, trivial, n, trivial, h⟩ theorem exists_eq_tmul_of_forall (x : TensorProduct R M N) (h : ∀ (m₁ m₂ : M) (n₁ n₂ : N), ∃ m n, m₁ ⊗ₜ n₁ + m₂ ⊗ₜ n₂ = m ⊗ₜ[R] n) : ∃ m n, x = m ⊗ₜ n := by induction x with | zero => use 0, 0 rw [TensorProduct.zero_tmul] | tmul m n => use m, n | add x y h₁ h₂ => obtain ⟨m₁, n₁, rfl⟩ := h₁ obtain ⟨m₂, n₂, rfl⟩ := h₂ apply h end Module variable [Module R P] [Module R Q] section UniversalProperty variable {M N} variable (f : M →ₗ[R] N →ₗ[R] P) variable (f' : M →ₛₗ[σ₁₂] N →ₛₗ[σ₁₂] P₂) /-- Auxiliary function to constructing a linear map `M ⊗ N → P` given a bilinear map `M → N → P` with the property that its composition with the canonical bilinear map `M → N → M ⊗ N` is the given bilinear map `M → N → P`. -/ def liftAux : M ⊗[R] N →+ P₂ := liftAddHom (LinearMap.toAddMonoidHom'.comp <| f'.toAddMonoidHom) fun r m n => by dsimp; rw [LinearMap.map_smulₛₗ₂, map_smulₛₗ] theorem liftAux_tmul (m n) : liftAux f' (m ⊗ₜ n) = f' m n := rfl variable {f f'} @[simp] theorem liftAux.smulₛₗ (r : R) (x) : liftAux f' (r • x) = σ₁₂ r • liftAux f' x := TensorProduct.induction_on x (smul_zero _).symm (fun p q => by simp_rw [← tmul_smul, liftAux_tmul, (f' p).map_smulₛₗ]) fun p q ih1 ih2 => by simp_rw [smul_add, (liftAux f').map_add, ih1, ih2, smul_add] theorem liftAux.smul (r : R) (x) : liftAux f (r • x) = r • liftAux f x := liftAux.smulₛₗ _ _ variable (f') in /-- Constructing a linear map `M ⊗ N → P` given a bilinear map `M → N → P` with the property that its composition with the canonical bilinear map `M → N → M ⊗ N` is the given bilinear map `M → N → P`. This works for semilinear maps. -/ def lift : M ⊗[R] N →ₛₗ[σ₁₂] P₂ := { liftAux f' with map_smul' := liftAux.smulₛₗ } @[simp] theorem lift.tmul (x y) : lift f' (x ⊗ₜ y) = f' x y := rfl @[simp] theorem lift.tmul' (x y) : (lift f').1 (x ⊗ₜ y) = f' x y := rfl theorem ext' {g h : M ⊗[R] N →ₛₗ[σ₁₂] P₂} (H : ∀ x y, g (x ⊗ₜ y) = h (x ⊗ₜ y)) : g = h := LinearMap.ext fun z => TensorProduct.induction_on z (by simp_rw [LinearMap.map_zero]) H fun x y ihx ihy => by rw [g.map_add, h.map_add, ihx, ihy] theorem lift.unique {g : M ⊗[R] N →ₛₗ[σ₁₂] P₂} (H : ∀ x y, g (x ⊗ₜ y) = f' x y) : g = lift f' := ext' fun m n => by rw [H, lift.tmul] theorem lift_mk : lift (mk R M N) = LinearMap.id := Eq.symm <| lift.unique fun _ _ => rfl theorem lift_compr₂ₛₗ [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃] (h : P₂ →ₛₗ[σ₂₃] P₃) : lift (f'.compr₂ₛₗ h) = h.comp (lift f') := Eq.symm <| lift.unique fun _ _ => by simp theorem lift_compr₂ (g : P →ₗ[R] Q) : lift (f.compr₂ g) = g.comp (lift f) := Eq.symm <| lift.unique fun _ _ => by simp theorem lift_mk_compr₂ₛₗ (g : M ⊗ N →ₛₗ[σ₁₂] P₂) : lift ((mk R M N).compr₂ₛₗ g) = g := by rw [lift_compr₂ₛₗ g, lift_mk, LinearMap.comp_id] theorem lift_mk_compr₂ (f : M ⊗ N →ₗ[R] P) : lift ((mk R M N).compr₂ f) = f := by rw [lift_compr₂ f, lift_mk, LinearMap.comp_id] /-- This used to be an `@[ext]` lemma, but it fails very slowly when the `ext` tactic tries to apply it in some cases, notably when one wants to show equality of two linear maps. The `@[ext]` attribute is now added locally where it is needed. Using this as the `@[ext]` lemma instead of `TensorProduct.ext'` allows `ext` to apply lemmas specific to `M →ₗ _` and `N →ₗ _`. See note [partially-applied ext lemmas]. -/ theorem ext {g h : M ⊗ N →ₛₗ[σ₁₂] P₂} (H : (mk R M N).compr₂ₛₗ g = (mk R M N).compr₂ₛₗ h) : g = h := by rw [← lift_mk_compr₂ₛₗ g, H, lift_mk_compr₂ₛₗ] attribute [local ext high] ext variable (M N P₂ σ₁₂) in /-- Linearly constructing a semilinear map `M ⊗ N → P` given a bilinear map `M → N → P` with the property that its composition with the canonical bilinear map `M → N → M ⊗ N` is the given bilinear map `M → N → P`. -/ def uncurry : (M →ₛₗ[σ₁₂] N →ₛₗ[σ₁₂] P₂) →ₗ[R₂] M ⊗[R] N →ₛₗ[σ₁₂] P₂ where toFun := lift map_add' f g := by ext; rfl map_smul' _ _ := by ext; rfl @[simp] theorem uncurry_apply (f : M →ₛₗ[σ₁₂] N →ₛₗ[σ₁₂] P₂) (m : M) (n : N) : uncurry σ₁₂ M N P₂ f (m ⊗ₜ n) = f m n := rfl variable (M N P₂ σ₁₂) /-- A linear equivalence constructing a semilinear map `M ⊗ N → P` given a bilinear map `M → N → P` with the property that its composition with the canonical bilinear map `M → N → M ⊗ N` is the given bilinear map `M → N → P`. -/ def lift.equiv : (M →ₛₗ[σ₁₂] N →ₛₗ[σ₁₂] P₂) ≃ₗ[R₂] M ⊗[R] N →ₛₗ[σ₁₂] P₂ := { uncurry σ₁₂ M N P₂ with invFun := fun f => (mk R M N).compr₂ₛₗ f } @[simp] theorem lift.equiv_apply (f : M →ₛₗ[σ₁₂] N →ₛₗ[σ₁₂] P₂) (m : M) (n : N) : lift.equiv σ₁₂ M N P₂ f (m ⊗ₜ n) = f m n := uncurry_apply f m n @[simp] theorem lift.equiv_symm_apply (f : M ⊗[R] N →ₛₗ[σ₁₂] P₂) (m : M) (n : N) : (lift.equiv σ₁₂ M N P₂).symm f m n = f (m ⊗ₜ n) := rfl /-- Given a semilinear map `M ⊗ N → P`, compose it with the canonical bilinear map `M → N → M ⊗ N` to form a bilinear map `M → N → P`. -/ def lcurry : (M ⊗[R] N →ₛₗ[σ₁₂] P₂) →ₗ[R₂] M →ₛₗ[σ₁₂] N →ₛₗ[σ₁₂] P₂ := (lift.equiv σ₁₂ M N P₂).symm variable {M N P₂ σ₁₂} @[simp] theorem lcurry_apply (f : M ⊗[R] N →ₛₗ[σ₁₂] P₂) (m : M) (n : N) : lcurry σ₁₂ M N P₂ f m n = f (m ⊗ₜ n) := rfl /-- Given a semilinear map `M ⊗ N → P`, compose it with the canonical bilinear map `M → N → M ⊗ N` to form a bilinear map `M → N → P`. -/ def curry (f : M ⊗[R] N →ₛₗ[σ₁₂] P₂) : M →ₛₗ[σ₁₂] N →ₛₗ[σ₁₂] P₂ := lcurry σ₁₂ M N P₂ f @[simp] theorem curry_apply (f : M ⊗[R] N →ₛₗ[σ₁₂] P₂) (m : M) (n : N) : curry f m n = f (m ⊗ₜ n) := rfl theorem curry_injective : Function.Injective (curry : (M ⊗[R] N →ₛₗ[σ₁₂] P₂) → M →ₛₗ[σ₁₂] N →ₛₗ[σ₁₂] P₂) := fun _ _ H => ext H theorem ext_threefold {g h : M ⊗[R] N ⊗[R] P →ₛₗ[σ₁₂] P₂} (H : ∀ x y z, g (x ⊗ₜ y ⊗ₜ z) = h (x ⊗ₜ y ⊗ₜ z)) : g = h := by ext x y z exact H x y z theorem ext_threefold' {g h : M ⊗[R] (N ⊗[R] P) →ₛₗ[σ₁₂] P₂} (H : ∀ x y z, g (x ⊗ₜ (y ⊗ₜ z)) = h (x ⊗ₜ (y ⊗ₜ z))) : g = h := by ext x y z exact H x y z -- We'll need this one for checking the pentagon identity! theorem ext_fourfold {g h : M ⊗[R] N ⊗[R] P ⊗[R] Q →ₛₗ[σ₁₂] P₂} (H : ∀ w x y z, g (w ⊗ₜ x ⊗ₜ y ⊗ₜ z) = h (w ⊗ₜ x ⊗ₜ y ⊗ₜ z)) : g = h := by ext w x y z exact H w x y z /-- Two semilinear maps `(M ⊗ N) ⊗ (P ⊗ Q) → P₂` which agree on all elements of the form `(m ⊗ₜ n) ⊗ₜ (p ⊗ₜ q)` are equal. -/ theorem ext_fourfold' {φ ψ : M ⊗[R] N ⊗[R] (P ⊗[R] Q) →ₛₗ[σ₁₂] P₂} (H : ∀ w x y z, φ (w ⊗ₜ x ⊗ₜ (y ⊗ₜ z)) = ψ (w ⊗ₜ x ⊗ₜ (y ⊗ₜ z))) : φ = ψ := by ext m n p q exact H m n p q /-- Two semilinear maps `M ⊗ (N ⊗ P) ⊗ Q → P₂` which agree on all elements of the form `m ⊗ₜ (n ⊗ₜ p) ⊗ₜ q` are equal. -/ theorem ext_fourfold'' {φ ψ : M ⊗[R] (N ⊗[R] P) ⊗[R] Q →ₛₗ[σ₁₂] P₂} (H : ∀ w x y z, φ (w ⊗ₜ (x ⊗ₜ y) ⊗ₜ z) = ψ (w ⊗ₜ (x ⊗ₜ y) ⊗ₜ z)) : φ = ψ := by ext m n p q exact H m n p q end UniversalProperty variable {M N} section variable (R M N) /-- The tensor product of modules is commutative, up to linear equivalence. -/ protected def comm : M ⊗[R] N ≃ₗ[R] N ⊗[R] M := LinearEquiv.ofLinear (lift (mk R N M).flip) (lift (mk R M N).flip) (ext' fun _ _ => rfl) (ext' fun _ _ => rfl) @[simp] theorem comm_tmul (m : M) (n : N) : (TensorProduct.comm R M N) (m ⊗ₜ n) = n ⊗ₜ m := rfl @[simp] theorem comm_symm_tmul (m : M) (n : N) : (TensorProduct.comm R M N).symm (n ⊗ₜ m) = m ⊗ₜ n := rfl -- Why is the `toLinearMap` necessary ? And why is this slow ? lemma lift_comp_comm_eq (f : M →ₛₗ[σ₁₂] N →ₛₗ[σ₁₂] P₂) : lift f ∘ₛₗ (TensorProduct.comm R N M).toLinearMap = lift f.flip := ext rfl end section CompatibleSMul variable (R A M N) [CommSemiring A] [Module A M] [Module A N] [SMulCommClass R A M] [CompatibleSMul R A M N] /-- If M and N are both R- and A-modules and their actions on them commute, and if the A-action on `M ⊗[R] N` can switch between the two factors, then there is a canonical A-linear map from `M ⊗[A] N` to `M ⊗[R] N`. -/ def mapOfCompatibleSMul : M ⊗[A] N →ₗ[A] M ⊗[R] N := lift { toFun := fun m ↦ { __ := mk R M N m map_smul' := fun _ _ ↦ (smul_tmul _ _ _).symm } map_add' := fun _ _ ↦ LinearMap.ext <| by simp map_smul' := fun _ _ ↦ rfl } @[simp] theorem mapOfCompatibleSMul_tmul (m n) : mapOfCompatibleSMul R A M N (m ⊗ₜ n) = m ⊗ₜ n := rfl theorem mapOfCompatibleSMul_surjective : Function.Surjective (mapOfCompatibleSMul R A M N) := fun x ↦ x.induction_on (⟨0, map_zero _⟩) (fun m n ↦ ⟨_, mapOfCompatibleSMul_tmul ..⟩) fun _ _ ⟨x, hx⟩ ⟨y, hy⟩ ↦ ⟨x + y, by simpa using congr($hx + $hy)⟩ attribute [local instance] SMulCommClass.symm /-- `mapOfCompatibleSMul R A M N` is also R-linear. -/ def mapOfCompatibleSMul' : M ⊗[A] N →ₗ[R] M ⊗[R] N where __ := mapOfCompatibleSMul R A M N map_smul' _ x := x.induction_on (map_zero _) (fun _ _ ↦ by simp [smul_tmul']) fun _ _ h h' ↦ by simpa using congr($h + $h') /-- If the R- and A-actions on M and N satisfy `CompatibleSMul` both ways, then `M ⊗[A] N` is canonically isomorphic to `M ⊗[R] N`. -/ def equivOfCompatibleSMul [CompatibleSMul A R M N] : M ⊗[A] N ≃ₗ[A] M ⊗[R] N where __ := mapOfCompatibleSMul R A M N invFun := mapOfCompatibleSMul A R M N left_inv x := x.induction_on (map_zero _) (fun _ _ ↦ rfl) fun _ _ h h' ↦ by simpa using congr($h + $h') right_inv x := x.induction_on (map_zero _) (fun _ _ ↦ rfl) fun _ _ h h' ↦ by simpa using congr($h + $h') omit [SMulCommClass R A M] end CompatibleSMul open LinearMap /-- The tensor product of a pair of linear maps between modules. -/ def map (f : M →ₛₗ[σ₁₂] M₂) (g : N →ₛₗ[σ₁₂] N₂) : M ⊗[R] N →ₛₗ[σ₁₂] M₂ ⊗[R₂] N₂ := lift <| comp (compl₂ (mk _ _ _) g) f @[inherit_doc] scoped[RingTheory.LinearMap] infix:70 " ⊗ₘ " => TensorProduct.map @[simp] theorem map_tmul (f : M →ₛₗ[σ₁₂] M₂) (g : N →ₛₗ[σ₁₂] N₂) (m : M) (n : N) : map f g (m ⊗ₜ n) = f m ⊗ₜ g n := rfl /-- Given semilinear maps `f : M → P`, `g : N → Q`, if we identify `M ⊗ N` with `N ⊗ M` and `P ⊗ Q` with `Q ⊗ P`, then this lemma states that `f ⊗ g = g ⊗ f`. -/ lemma map_comp_comm_eq (f : M →ₛₗ[σ₁₂] M₂) (g : N →ₛₗ[σ₁₂] N₂) : map f g ∘ₛₗ (TensorProduct.comm R N M).toLinearMap = (TensorProduct.comm R₂ N₂ M₂).toLinearMap ∘ₛₗ map g f := ext rfl lemma map_comm (f : M →ₛₗ[σ₁₂] M₂) (g : N →ₛₗ[σ₁₂] N₂) (x : N ⊗[R] M) : map f g (TensorProduct.comm R N M x) = TensorProduct.comm R₂ N₂ M₂ (map g f x) := DFunLike.congr_fun (map_comp_comm_eq _ _) _ theorem range_map (f : M →ₗ[R] P) (g : N →ₗ[R] Q) : range (map f g) = .map₂ (mk R _ _) (range f) (range g) := by simp_rw [← Submodule.map_top, Submodule.map₂_map_map, ← map₂_mk_top_top_eq_top, Submodule.map_map₂] rfl theorem range_map_eq_span_tmul (f : M →ₗ[R] P) (g : N →ₗ[R] Q) : range (map f g) = Submodule.span R { t | ∃ m n, f m ⊗ₜ g n = t } := by simp only [← Submodule.map_top, ← span_tmul_eq_top, Submodule.map_span] congr; ext t simp @[deprecated (since := "2025-09-07")] alias map_range_eq_span_tmul := range_map_eq_span_tmul /-- Given submodules `p ⊆ P` and `q ⊆ Q`, this is the natural map: `p ⊗ q → P ⊗ Q`. -/ @[simp] def mapIncl (p : Submodule R P) (q : Submodule R Q) : p ⊗[R] q →ₗ[R] P ⊗[R] Q := map p.subtype q.subtype lemma range_mapIncl (p : Submodule R P) (q : Submodule R Q) : LinearMap.range (mapIncl p q) = .map₂ (mk R _ _) p q := by simp_rw [mapIncl, range_map, Submodule.range_subtype] theorem map₂_eq_range_lift_comp_mapIncl (f : P →ₗ[R] Q →ₗ[R] M) (p : Submodule R P) (q : Submodule R Q) : Submodule.map₂ f p q = LinearMap.range (lift f ∘ₗ mapIncl p q) := by simp_rw [LinearMap.range_comp, range_mapIncl, Submodule.map_map₂] rfl section variable {P' Q' : Type*} variable [AddCommMonoid P'] [Module R P'] variable [AddCommMonoid Q'] [Module R Q'] variable [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃] theorem map_comp (f₂ : M₂ →ₛₗ[σ₂₃] M₃) (g₂ : N₂ →ₛₗ[σ₂₃] N₃) (f₁ : M →ₛₗ[σ₁₂] M₂) (g₁ : N →ₛₗ[σ₁₂] N₂) : map (f₂ ∘ₛₗ f₁) (g₂ ∘ₛₗ g₁) = (map f₂ g₂) ∘ₛₗ (map f₁ g₁) := ext' fun _ _ => rfl theorem map_map (f₂ : M₂ →ₛₗ[σ₂₃] M₃) (g₂ : N₂ →ₛₗ[σ₂₃] N₃) (f₁ : M →ₛₗ[σ₁₂] M₂) (g₁ : N →ₛₗ[σ₁₂] N₂) (x : M ⊗[R] N) : map f₂ g₂ (map f₁ g₁ x) = map (f₂ ∘ₛₗ f₁) (g₂ ∘ₛₗ g₁) x := DFunLike.congr_fun (map_comp ..).symm x lemma range_map_mono [Module R M₂] [Module R M₃] [Module R N₂] [Module R N₃] {a : M →ₗ[R] M₂} {b : M₃ →ₗ[R] M₂} {c : N →ₗ[R] N₂} {d : N₃ →ₗ[R] N₂} (hab : range a ≤ range b) (hcd : range c ≤ range d) : range (map a c) ≤ range (map b d) := by simp_rw [range_map] exact Submodule.map₂_le_map₂ hab hcd lemma range_mapIncl_mono {p p' : Submodule R P} {q q' : Submodule R Q} (hp : p ≤ p') (hq : q ≤ q') : LinearMap.range (mapIncl p q) ≤ LinearMap.range (mapIncl p' q') := range_map_mono (by simpa) (by simpa) theorem lift_comp_map (i : M₂ →ₛₗ[σ₂₃] N₂ →ₛₗ[σ₂₃] P₃) (f : M →ₛₗ[σ₁₂] M₂) (g : N →ₛₗ[σ₁₂] N₂) : (lift i).comp (map f g) = lift ((i.comp f).compl₂ g) := ext' fun _ _ => rfl attribute [local ext high] ext @[simp] theorem map_id : map (id : M →ₗ[R] M) (id : N →ₗ[R] N) = .id := by ext simp only [mk_apply, id_coe, compr₂ₛₗ_apply, _root_.id, map_tmul] @[simp] protected theorem map_one : map (1 : M →ₗ[R] M) (1 : N →ₗ[R] N) = 1 := map_id protected theorem map_mul (f₁ f₂ : M →ₗ[R] M) (g₁ g₂ : N →ₗ[R] N) : map (f₁ * f₂) (g₁ * g₂) = map f₁ g₁ * map f₂ g₂ := map_comp .. @[simp] protected theorem map_pow (f : M →ₗ[R] M) (g : N →ₗ[R] N) (n : ℕ) : map f g ^ n = map (f ^ n) (g ^ n) := by induction n with | zero => simp only [pow_zero, TensorProduct.map_one] | succ n ih => simp only [pow_succ', ih, TensorProduct.map_mul] theorem map_add_left (f₁ f₂ : M →ₛₗ[σ₁₂] M₂) (g : N →ₛₗ[σ₁₂] N₂) : map (f₁ + f₂) g = map f₁ g + map f₂ g := by ext simp only [add_tmul, compr₂ₛₗ_apply, mk_apply, map_tmul, add_apply] theorem map_add_right (f : M →ₛₗ[σ₁₂] M₂) (g₁ g₂ : N →ₛₗ[σ₁₂] N₂) : map f (g₁ + g₂) = map f g₁ + map f g₂ := by ext simp only [tmul_add, compr₂ₛₗ_apply, mk_apply, map_tmul, add_apply] theorem map_smul_left (r : R₂) (f : M →ₛₗ[σ₁₂] M₂) (g : N →ₛₗ[σ₁₂] N₂) : map (r • f) g = r • map f g := by ext simp only [smul_tmul, compr₂ₛₗ_apply, mk_apply, map_tmul, smul_apply, tmul_smul] theorem map_smul_right (r : R₂) (f : M →ₛₗ[σ₁₂] M₂) (g : N →ₛₗ[σ₁₂] N₂) : map f (r • g) = r • map f g := by ext simp only [compr₂ₛₗ_apply, mk_apply, map_tmul, smul_apply, tmul_smul] variable (M N P M₂ N₂ σ₁₂) /-- The tensor product of a pair of semilinear maps between modules, bilinear in both maps. -/ def mapBilinear : (M →ₛₗ[σ₁₂] M₂) →ₗ[R₂] (N →ₛₗ[σ₁₂] N₂) →ₗ[R₂] M ⊗[R] N →ₛₗ[σ₁₂] M₂ ⊗[R₂] N₂ := LinearMap.mk₂ R₂ map map_add_left map_smul_left map_add_right map_smul_right /-- The canonical linear map from `M₂ ⊗[R₂] (P →ₛₗ[σ₁₂] N₂)` to `P →ₛₗ[σ₁₂] M₂ ⊗[R₂] N₂`. -/ def lTensorHomToHomLTensor : M₂ ⊗[R₂] (P →ₛₗ[σ₁₂] N₂) →ₗ[R₂] P →ₛₗ[σ₁₂] M₂ ⊗[R₂] N₂ := TensorProduct.lift (llcomp _ P N₂ _ ∘ₛₗ mk R₂ M₂ N₂) /-- The canonical linear map from `(P →ₛₗ[σ₁₂] M₂) ⊗[R₂] N₂` to `P →ₛₗ[σ₁₂] M₂ ⊗[R₂] N₂`. -/ def rTensorHomToHomRTensor : (P →ₛₗ[σ₁₂] M₂) ⊗[R₂] N₂ →ₗ[R₂] P →ₛₗ[σ₁₂] M₂ ⊗[R₂] N₂ := TensorProduct.lift (llcomp _ P M₂ _ ∘ₗ (mk R₂ M₂ N₂).flip).flip /-- The linear map from `(M →ₛₗ[σ₁₂] M₂) ⊗ (N →ₛₗ[σ₁₂] N₂)` to `M ⊗ N →ₛₗ[σ₁₂] M₂ ⊗ N₂` sending `f ⊗ₜ g` to `TensorProduct.map f g`, the tensor product of the two maps. -/ def homTensorHomMap : (M →ₛₗ[σ₁₂] M₂) ⊗[R₂] (N →ₛₗ[σ₁₂] N₂) →ₗ[R₂] M ⊗[R] N →ₛₗ[σ₁₂] M₂ ⊗[R₂] N₂ := lift (mapBilinear σ₁₂ M N M₂ N₂) variable {M N P M₂ N₂ σ₁₂} /-- This is a binary version of `TensorProduct.map`: Given a bilinear map `f : M ⟶ P ⟶ Q` and a bilinear map `g : N ⟶ S ⟶ T`, if we think `f` and `g` as semilinear maps with two inputs, then `map₂ f g` is a bilinear map taking two inputs `M ⊗ N → P ⊗ S → Q ⊗ S` defined by `map₂ f g (m ⊗ n) (p ⊗ s) = f m p ⊗ g n s`. Mathematically, `TensorProduct.map₂` is defined as the composition `M ⊗ N -map→ Hom(P, Q) ⊗ Hom(S, T) -homTensorHomMap→ Hom(P ⊗ S, Q ⊗ T)`. -/ def map₂ (f : M →ₛₗ[σ₁₃] M₂ →ₛₗ[σ₂₃] M₃) (g : N →ₛₗ[σ₁₃] N₂ →ₛₗ[σ₂₃] N₃) : M ⊗[R] N →ₛₗ[σ₁₃] M₂ ⊗[R₂] N₂ →ₛₗ[σ₂₃] M₃ ⊗[R₃] N₃ := homTensorHomMap σ₂₃ _ _ _ _ ∘ₛₗ map f g @[simp] theorem mapBilinear_apply (f : M →ₛₗ[σ₁₂] M₂) (g : N →ₛₗ[σ₁₂] N₂) : mapBilinear σ₁₂ M N M₂ N₂ f g = map f g := rfl @[simp] theorem lTensorHomToHomLTensor_apply (m₂ : M₂) (f : P →ₛₗ[σ₁₂] N₂) (p : P) : lTensorHomToHomLTensor _ P M₂ N₂ (m₂ ⊗ₜ f) p = m₂ ⊗ₜ f p := rfl @[simp] theorem rTensorHomToHomRTensor_apply (f : P →ₛₗ[σ₁₂] M₂) (n₂ : N₂) (p : P) : rTensorHomToHomRTensor _ P M₂ N₂ (f ⊗ₜ n₂) p = f p ⊗ₜ n₂ := rfl @[simp] theorem homTensorHomMap_apply (f : M →ₛₗ[σ₁₂] M₂) (g : N →ₛₗ[σ₁₂] N₂) : homTensorHomMap _ M N M₂ N₂ (f ⊗ₜ g) = map f g := rfl @[simp] theorem map₂_apply_tmul (f : M →ₛₗ[σ₁₃] M₂ →ₛₗ[σ₂₃] M₃) (g : N →ₛₗ[σ₁₃] N₂ →ₛₗ[σ₂₃] N₃) (m : M) (n : N) : map₂ f g (m ⊗ₜ n) = map (f m) (g n) := rfl @[simp] theorem map_zero_left (g : N →ₛₗ[σ₁₂] N₂) : map (0 : M →ₛₗ[σ₁₂] M₂) g = 0 := (mapBilinear _ M N M₂ N₂).map_zero₂ _ @[simp] theorem map_zero_right (f : M →ₛₗ[σ₁₂] M₂) : map f (0 : N →ₛₗ[σ₁₂] N₂) = 0 := (mapBilinear _ M N M₂ N₂ f).map_zero end variable {σ₂₁ : R₂ →+* R} [RingHomInvPair σ₁₂ σ₂₁] [RingHomInvPair σ₂₁ σ₁₂] /-- If `M` and `P` are semilinearly equivalent and `N` and `Q` are semilinearly equivalent then `M ⊗ N` and `P ⊗ Q` are semilinearly equivalent. -/ def congr (f : M ≃ₛₗ[σ₁₂] M₂) (g : N ≃ₛₗ[σ₁₂] N₂) : M ⊗[R] N ≃ₛₗ[σ₁₂] M₂ ⊗[R₂] N₂ := LinearEquiv.ofLinear (map f g) (map f.symm g.symm) (ext' fun m n => by simp) (ext' fun m n => by simp) @[simp] lemma toLinearMap_congr (f : M ≃ₛₗ[σ₁₂] M₂) (g : N ≃ₛₗ[σ₁₂] N₂) : (congr f g).toLinearMap = map f g := rfl @[simp] theorem congr_tmul (f : M ≃ₛₗ[σ₁₂] M₂) (g : N ≃ₛₗ[σ₁₂] N₂) (m : M) (n : N) : congr f g (m ⊗ₜ n) = f m ⊗ₜ g n := rfl @[simp] theorem congr_symm_tmul (f : M ≃ₛₗ[σ₁₂] M₂) (g : N ≃ₛₗ[σ₁₂] N₂) (p : M₂) (q : N₂) : (congr f g).symm (p ⊗ₜ q) = f.symm p ⊗ₜ g.symm q := rfl theorem congr_symm (f : M ≃ₛₗ[σ₁₂] M₂) (g : N ≃ₛₗ[σ₁₂] N₂) : (congr f g).symm = congr f.symm g.symm := rfl @[simp] theorem congr_refl_refl : congr (.refl R M) (.refl R N) = .refl R _ := LinearEquiv.toLinearMap_injective <| ext' fun _ _ ↦ rfl section congr_congr variable {σ₃₂ : R₃ →+* R₂} [RingHomInvPair σ₂₃ σ₃₂] [RingHomInvPair σ₃₂ σ₂₃] {σ₃₁ : R₃ →+* R} [RingHomInvPair σ₁₃ σ₃₁] [RingHomInvPair σ₃₁ σ₁₃] [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃] [RingHomCompTriple σ₃₂ σ₂₁ σ₃₁] (f₂ : M₂ ≃ₛₗ[σ₂₃] M₃) (g₂ : N₂ ≃ₛₗ[σ₂₃] N₃) (f₁ : M ≃ₛₗ[σ₁₂] M₂) (g₁ : N ≃ₛₗ[σ₁₂] N₂) theorem congr_trans : congr (f₁.trans f₂) (g₁.trans g₂) = (congr f₁ g₁).trans (congr f₂ g₂) := LinearEquiv.toLinearMap_injective <| map_comp _ _ _ _ theorem congr_congr (x : M ⊗[R] N) : congr f₂ g₂ (congr f₁ g₁ x) = congr (f₁.trans f₂) (g₁.trans g₂) x := DFunLike.congr_fun (congr_trans ..).symm x end congr_congr theorem congr_mul (f : M ≃ₗ[R] M) (g : N ≃ₗ[R] N) (f' : M ≃ₗ[R] M) (g' : N ≃ₗ[R] N) : congr (f * f') (g * g') = congr f g * congr f' g' := congr_trans _ _ _ _ @[simp] theorem congr_pow (f : M ≃ₗ[R] M) (g : N ≃ₗ[R] N) (n : ℕ) : congr f g ^ n = congr (f ^ n) (g ^ n) := by induction n with | zero => exact congr_refl_refl.symm | succ n ih => simp_rw [pow_succ, ih, congr_mul] @[simp] theorem congr_zpow (f : M ≃ₗ[R] M) (g : N ≃ₗ[R] N) (n : ℤ) : congr f g ^ n = congr (f ^ n) (g ^ n) := by cases n with | ofNat n => exact congr_pow _ _ _ | negSucc n => simp_rw [zpow_negSucc, congr_pow]; exact congr_symm _ _ lemma map_bijective {f : M →ₗ[R] N} {g : P →ₗ[R] Q} (hf : Function.Bijective f) (hg : Function.Bijective g) : Function.Bijective (map f g) := (TensorProduct.congr (.ofBijective f hf) (.ofBijective g hg)).bijective universe u in instance {R M N : Type*} [CommSemiring R] [AddCommMonoid M] [AddCommMonoid N] [Module R M] [Module R N] [Small.{u} M] [Small.{u} N] : Small.{u} (M ⊗[R] N) := ⟨_, ⟨(TensorProduct.congr (Shrink.linearEquiv R M) (Shrink.linearEquiv R N)).symm.toEquiv⟩⟩ end TensorProduct open scoped TensorProduct variable [Module R P] [Module R Q] namespace LinearMap variable {N} /-- `LinearMap.lTensor M f : M ⊗ N →ₗ M ⊗ P` is the natural linear map induced by `f : N →ₗ P`. -/ def lTensor (f : N →ₗ[R] P) : M ⊗[R] N →ₗ[R] M ⊗[R] P := TensorProduct.map id f /-- `LinearMap.rTensor M f : N ⊗ M →ₗ P ⊗ M` is the natural linear map induced by `f : N →ₗ P`. -/ def rTensor (f : N →ₗ[R] P) : N ⊗[R] M →ₗ[R] P ⊗[R] M := TensorProduct.map f id variable (g : P →ₗ[R] Q) (f : N →ₗ[R] P) theorem lTensor_def : f.lTensor M = TensorProduct.map LinearMap.id f := rfl theorem rTensor_def : f.rTensor M = TensorProduct.map f LinearMap.id := rfl @[simp] theorem lTensor_tmul (m : M) (n : N) : f.lTensor M (m ⊗ₜ n) = m ⊗ₜ f n := rfl @[simp] theorem rTensor_tmul (m : M) (n : N) : f.rTensor M (n ⊗ₜ m) = f n ⊗ₜ m := rfl @[simp] theorem lTensor_comp_mk (m : M) : f.lTensor M ∘ₗ TensorProduct.mk R M N m = TensorProduct.mk R M P m ∘ₗ f := rfl @[simp] theorem rTensor_comp_flip_mk (m : M) : f.rTensor M ∘ₗ (TensorProduct.mk R N M).flip m = (TensorProduct.mk R P M).flip m ∘ₗ f := rfl lemma comm_comp_rTensor_comp_comm_eq (g : N →ₗ[R] P) : TensorProduct.comm R P Q ∘ₗ rTensor Q g ∘ₗ TensorProduct.comm R Q N = lTensor Q g := TensorProduct.ext rfl lemma comm_comp_lTensor_comp_comm_eq (g : N →ₗ[R] P) : TensorProduct.comm R Q P ∘ₗ lTensor Q g ∘ₗ TensorProduct.comm R N Q = rTensor Q g := TensorProduct.ext rfl /-- Given a linear map `f : N → P`, `f ⊗ M` is injective if and only if `M ⊗ f` is injective. -/ theorem lTensor_inj_iff_rTensor_inj : Function.Injective (lTensor M f) ↔ Function.Injective (rTensor M f) := by simp [← comm_comp_rTensor_comp_comm_eq] /-- Given a linear map `f : N → P`, `f ⊗ M` is surjective if and only if `M ⊗ f` is surjective. -/ theorem lTensor_surj_iff_rTensor_surj : Function.Surjective (lTensor M f) ↔ Function.Surjective (rTensor M f) := by simp [← comm_comp_rTensor_comp_comm_eq] /-- Given a linear map `f : N → P`, `f ⊗ M` is bijective if and only if `M ⊗ f` is bijective. -/ theorem lTensor_bij_iff_rTensor_bij : Function.Bijective (lTensor M f) ↔ Function.Bijective (rTensor M f) := by simp [← comm_comp_rTensor_comp_comm_eq] variable {M} in theorem smul_lTensor {S : Type*} [CommSemiring S] [SMul R S] [Module S M] [IsScalarTower R S M] [SMulCommClass R S M] (s : S) (m : M ⊗[R] N) : s • (f.lTensor M) m = (f.lTensor M) (s • m) := have h : s • (f.lTensor M) = f.lTensor M ∘ₗ (LinearMap.lsmul S (M ⊗[R] N) s).restrictScalars R := TensorProduct.ext rfl congrFun (congrArg DFunLike.coe h) m open TensorProduct attribute [local ext high] TensorProduct.ext /-- `lTensorHom M` is the natural linear map that sends a linear map `f : N →ₗ P` to `M ⊗ f`. See also `Module.End.lTensorAlgHom`. -/ def lTensorHom : (N →ₗ[R] P) →ₗ[R] M ⊗[R] N →ₗ[R] M ⊗[R] P where toFun := lTensor M map_add' f g := by ext x y simp only [compr₂ₛₗ_apply, mk_apply, add_apply, lTensor_tmul, tmul_add] map_smul' r f := by dsimp ext x y simp only [compr₂ₛₗ_apply, mk_apply, tmul_smul, smul_apply, lTensor_tmul] /-- `rTensorHom M` is the natural linear map that sends a linear map `f : N →ₗ P` to `f ⊗ M`. See also `Module.End.rTensorAlgHom`. -/ def rTensorHom : (N →ₗ[R] P) →ₗ[R] N ⊗[R] M →ₗ[R] P ⊗[R] M where toFun f := f.rTensor M map_add' f g := by ext x y simp only [compr₂ₛₗ_apply, mk_apply, add_apply, rTensor_tmul, add_tmul] map_smul' r f := by dsimp ext x y simp only [compr₂ₛₗ_apply, mk_apply, smul_tmul, tmul_smul, smul_apply, rTensor_tmul] @[simp] theorem coe_lTensorHom : (lTensorHom M : (N →ₗ[R] P) → M ⊗[R] N →ₗ[R] M ⊗[R] P) = lTensor M := rfl @[simp] theorem coe_rTensorHom : (rTensorHom M : (N →ₗ[R] P) → N ⊗[R] M →ₗ[R] P ⊗[R] M) = rTensor M := rfl @[simp] theorem lTensor_add (f g : N →ₗ[R] P) : (f + g).lTensor M = f.lTensor M + g.lTensor M := (lTensorHom M).map_add f g @[simp] theorem rTensor_add (f g : N →ₗ[R] P) : (f + g).rTensor M = f.rTensor M + g.rTensor M := (rTensorHom M).map_add f g @[simp] theorem lTensor_zero : lTensor M (0 : N →ₗ[R] P) = 0 := (lTensorHom M).map_zero @[simp] theorem rTensor_zero : rTensor M (0 : N →ₗ[R] P) = 0 := (rTensorHom M).map_zero @[simp] theorem lTensor_smul (r : R) (f : N →ₗ[R] P) : (r • f).lTensor M = r • f.lTensor M := (lTensorHom M).map_smul r f @[simp] theorem rTensor_smul (r : R) (f : N →ₗ[R] P) : (r • f).rTensor M = r • f.rTensor M := (rTensorHom M).map_smul r f theorem lTensor_comp : (g.comp f).lTensor M = (g.lTensor M).comp (f.lTensor M) := by ext m n simp only [compr₂ₛₗ_apply, mk_apply, comp_apply, lTensor_tmul] theorem lTensor_comp_apply (x : M ⊗[R] N) : (g.comp f).lTensor M x = (g.lTensor M) ((f.lTensor M) x) := by rw [lTensor_comp, coe_comp]; rfl theorem rTensor_comp : (g.comp f).rTensor M = (g.rTensor M).comp (f.rTensor M) := by ext m n simp only [compr₂ₛₗ_apply, mk_apply, comp_apply, rTensor_tmul] theorem rTensor_comp_apply (x : N ⊗[R] M) : (g.comp f).rTensor M x = (g.rTensor M) ((f.rTensor M) x) := by rw [rTensor_comp, coe_comp]; rfl theorem lTensor_mul (f g : Module.End R N) : (f * g).lTensor M = f.lTensor M * g.lTensor M := lTensor_comp M f g theorem rTensor_mul (f g : Module.End R N) : (f * g).rTensor M = f.rTensor M * g.rTensor M := rTensor_comp M f g variable (N) @[simp] theorem lTensor_id : (id : N →ₗ[R] N).lTensor M = id := map_id -- `simp` can prove this. theorem lTensor_id_apply (x : M ⊗[R] N) : (LinearMap.id : N →ₗ[R] N).lTensor M x = x := by rw [lTensor_id, id_coe, _root_.id] @[simp] theorem rTensor_id : (id : N →ₗ[R] N).rTensor M = id := map_id -- `simp` can prove this. theorem rTensor_id_apply (x : N ⊗[R] M) : (LinearMap.id : N →ₗ[R] N).rTensor M x = x := by rw [rTensor_id, id_coe, _root_.id] @[simp] theorem lTensor_smul_action (r : R) : (DistribMulAction.toLinearMap R N r).lTensor M = DistribMulAction.toLinearMap R (M ⊗[R] N) r := (lTensor_smul M r LinearMap.id).trans (congrArg _ (lTensor_id M N)) @[simp] theorem rTensor_smul_action (r : R) : (DistribMulAction.toLinearMap R N r).rTensor M = DistribMulAction.toLinearMap R (N ⊗[R] M) r := (rTensor_smul M r LinearMap.id).trans (congrArg _ (rTensor_id M N)) variable {N} @[simp] theorem lTensor_comp_rTensor (f : M →ₗ[R] P) (g : N →ₗ[R] Q) : (g.lTensor P).comp (f.rTensor N) = map f g := by simp only [lTensor, rTensor, ← map_comp, id_comp, comp_id] @[simp] theorem rTensor_comp_lTensor (f : M →ₗ[R] P) (g : N →ₗ[R] Q) : (f.rTensor Q).comp (g.lTensor M) = map f g := by simp only [lTensor, rTensor, ← map_comp, id_comp, comp_id] @[simp] theorem map_comp_rTensor (f : M →ₗ[R] P) (g : N →ₗ[R] Q) (f' : S →ₗ[R] M) : (map f g).comp (f'.rTensor _) = map (f.comp f') g := by simp only [rTensor, ← map_comp, comp_id] @[simp] theorem map_rTensor (f : M →ₗ[R] P) (g : N →ₗ[R] Q) (f' : S →ₗ[R] M) (x : S ⊗[R] N) : map f g (f'.rTensor _ x) = map (f.comp f') g x := LinearMap.congr_fun (map_comp_rTensor _ _ _ _) x @[simp] theorem map_comp_lTensor (f : M →ₗ[R] P) (g : N →ₗ[R] Q) (g' : S →ₗ[R] N) : (map f g).comp (g'.lTensor _) = map f (g.comp g') := by simp only [lTensor, ← map_comp, comp_id] @[simp] lemma map_lTensor (f : M →ₗ[R] P) (g : N →ₗ[R] Q) (g' : S →ₗ[R] N) (x : M ⊗[R] S) : map f g (g'.lTensor M x) = map f (g ∘ₗ g') x := LinearMap.congr_fun (map_comp_lTensor _ _ _ _) x @[simp] theorem rTensor_comp_map (f' : P →ₗ[R] S) (f : M →ₗ[R] P) (g : N →ₗ[R] Q) : (f'.rTensor _).comp (map f g) = map (f'.comp f) g := by simp only [rTensor, ← map_comp, id_comp] @[simp] lemma rTensor_map (f' : P →ₗ[R] S) (f : M →ₗ[R] P) (g : N →ₗ[R] Q) (x : M ⊗[R] N) : f'.rTensor Q (map f g x) = map (f' ∘ₗ f) g x := LinearMap.congr_fun (rTensor_comp_map _ _ f g) x @[simp] theorem lTensor_comp_map (g' : Q →ₗ[R] S) (f : M →ₗ[R] P) (g : N →ₗ[R] Q) : (g'.lTensor _).comp (map f g) = map f (g'.comp g) := by simp only [lTensor, ← map_comp, id_comp] @[simp] lemma lTensor_map (g' : Q →ₗ[R] S) (f : M →ₗ[R] P) (g : N →ₗ[R] Q) (x : M ⊗[R] N) : g'.lTensor P (map f g x) = map f (g' ∘ₗ g) x := LinearMap.congr_fun (lTensor_comp_map _ _ f g) x variable {M} @[simp] theorem rTensor_pow (f : M →ₗ[R] M) (n : ℕ) : f.rTensor N ^ n = (f ^ n).rTensor N := by have h := TensorProduct.map_pow f (id : N →ₗ[R] N) n rwa [Module.End.id_pow] at h @[simp] theorem lTensor_pow (f : N →ₗ[R] N) (n : ℕ) : f.lTensor M ^ n = (f ^ n).lTensor M := by have h := TensorProduct.map_pow (id : M →ₗ[R] M) f n rwa [Module.End.id_pow] at h end LinearMap namespace LinearEquiv variable {N} /-- `LinearEquiv.lTensor M f : M ⊗ N ≃ₗ M ⊗ P` is the natural linear equivalence induced by `f : N ≃ₗ P`. -/ def lTensor (f : N ≃ₗ[R] P) : M ⊗[R] N ≃ₗ[R] M ⊗[R] P := TensorProduct.congr (refl R M) f /-- `LinearEquiv.rTensor M f : N₁ ⊗ M ≃ₗ N₂ ⊗ M` is the natural linear equivalence induced by `f : N₁ ≃ₗ N₂`. -/ def rTensor (f : N ≃ₗ[R] P) : N ⊗[R] M ≃ₗ[R] P ⊗[R] M := TensorProduct.congr f (refl R M) variable (g : P ≃ₗ[R] Q) (f : N ≃ₗ[R] P) (m : M) (n : N) (p : P) (x : M ⊗[R] N) (y : N ⊗[R] M) @[simp] theorem coe_lTensor : lTensor M f = (f : N →ₗ[R] P).lTensor M := rfl @[simp] theorem coe_lTensor_symm : (lTensor M f).symm = (f.symm : P →ₗ[R] N).lTensor M := rfl @[simp] theorem coe_rTensor : rTensor M f = (f : N →ₗ[R] P).rTensor M := rfl @[simp] theorem coe_rTensor_symm : (rTensor M f).symm = (f.symm : P →ₗ[R] N).rTensor M := rfl @[simp] theorem lTensor_tmul : f.lTensor M (m ⊗ₜ n) = m ⊗ₜ f n := rfl @[simp] theorem lTensor_symm_tmul : (f.lTensor M).symm (m ⊗ₜ p) = m ⊗ₜ f.symm p := rfl @[simp] theorem rTensor_tmul : f.rTensor M (n ⊗ₜ m) = f n ⊗ₜ m := rfl @[simp] theorem rTensor_symm_tmul : (f.rTensor M).symm (p ⊗ₜ m) = f.symm p ⊗ₜ m := rfl lemma comm_trans_rTensor_trans_comm_eq (g : N ≃ₗ[R] P) : TensorProduct.comm R Q N ≪≫ₗ rTensor Q g ≪≫ₗ TensorProduct.comm R P Q = lTensor Q g := toLinearMap_injective <| TensorProduct.ext rfl lemma comm_trans_lTensor_trans_comm_eq (g : N ≃ₗ[R] P) : TensorProduct.comm R N Q ≪≫ₗ lTensor Q g ≪≫ₗ TensorProduct.comm R Q P = rTensor Q g := toLinearMap_injective <| TensorProduct.ext rfl theorem lTensor_trans : (f ≪≫ₗ g).lTensor M = f.lTensor M ≪≫ₗ g.lTensor M := toLinearMap_injective <| LinearMap.lTensor_comp M _ _ theorem lTensor_trans_apply : (f ≪≫ₗ g).lTensor M x = g.lTensor M (f.lTensor M x) := LinearMap.lTensor_comp_apply M _ _ x theorem rTensor_trans : (f ≪≫ₗ g).rTensor M = f.rTensor M ≪≫ₗ g.rTensor M := toLinearMap_injective <| LinearMap.rTensor_comp M _ _ theorem rTensor_trans_apply : (f ≪≫ₗ g).rTensor M y = g.rTensor M (f.rTensor M y) := LinearMap.rTensor_comp_apply M _ _ y theorem lTensor_mul (f g : N ≃ₗ[R] N) : (f * g).lTensor M = f.lTensor M * g.lTensor M := lTensor_trans M f g theorem rTensor_mul (f g : N ≃ₗ[R] N) : (f * g).rTensor M = f.rTensor M * g.rTensor M := rTensor_trans M f g variable (N) @[simp] theorem lTensor_refl : (refl R N).lTensor M = refl R _ := TensorProduct.congr_refl_refl theorem lTensor_refl_apply : (refl R N).lTensor M x = x := by rw [lTensor_refl, refl_apply] @[simp] theorem rTensor_refl : (refl R N).rTensor M = refl R _ := TensorProduct.congr_refl_refl theorem rTensor_refl_apply : (refl R N).rTensor M y = y := by rw [rTensor_refl, refl_apply] variable {N} @[simp] theorem rTensor_trans_lTensor (f : M ≃ₗ[R] P) (g : N ≃ₗ[R] Q) : f.rTensor N ≪≫ₗ g.lTensor P = TensorProduct.congr f g := toLinearMap_injective <| LinearMap.lTensor_comp_rTensor M _ _ @[simp] theorem lTensor_trans_rTensor (f : M ≃ₗ[R] P) (g : N ≃ₗ[R] Q) : g.lTensor M ≪≫ₗ f.rTensor Q = TensorProduct.congr f g := toLinearMap_injective <| LinearMap.rTensor_comp_lTensor M _ _ @[simp] theorem rTensor_trans_congr (f : M ≃ₗ[R] P) (g : N ≃ₗ[R] Q) (f' : S ≃ₗ[R] M) : f'.rTensor _ ≪≫ₗ TensorProduct.congr f g = TensorProduct.congr (f' ≪≫ₗ f) g := toLinearMap_injective <| LinearMap.map_comp_rTensor M _ _ _ @[simp] theorem lTensor_trans_congr (f : M ≃ₗ[R] P) (g : N ≃ₗ[R] Q) (g' : S ≃ₗ[R] N) : g'.lTensor _ ≪≫ₗ TensorProduct.congr f g = TensorProduct.congr f (g' ≪≫ₗ g) := toLinearMap_injective <| LinearMap.map_comp_lTensor M _ _ _ @[simp] theorem congr_trans_rTensor (f' : P ≃ₗ[R] S) (f : M ≃ₗ[R] P) (g : N ≃ₗ[R] Q) : TensorProduct.congr f g ≪≫ₗ f'.rTensor _ = TensorProduct.congr (f ≪≫ₗ f') g := toLinearMap_injective <| LinearMap.rTensor_comp_map M _ _ _ @[simp] theorem congr_trans_lTensor (g' : Q ≃ₗ[R] S) (f : M ≃ₗ[R] P) (g : N ≃ₗ[R] Q) : TensorProduct.congr f g ≪≫ₗ g'.lTensor _ = TensorProduct.congr f (g ≪≫ₗ g') := toLinearMap_injective <| LinearMap.lTensor_comp_map M _ _ _ variable {M} @[simp] theorem rTensor_pow (f : M ≃ₗ[R] M) (n : ℕ) : f.rTensor N ^ n = (f ^ n).rTensor N := by simpa only [one_pow] using TensorProduct.congr_pow f (1 : N ≃ₗ[R] N) n @[simp] theorem rTensor_zpow (f : M ≃ₗ[R] M) (n : ℤ) : f.rTensor N ^ n = (f ^ n).rTensor N := by simpa only [one_zpow] using TensorProduct.congr_zpow f (1 : N ≃ₗ[R] N) n @[simp] theorem lTensor_pow (f : N ≃ₗ[R] N) (n : ℕ) : f.lTensor M ^ n = (f ^ n).lTensor M := by simpa only [one_pow] using TensorProduct.congr_pow (1 : M ≃ₗ[R] M) f n @[simp] theorem lTensor_zpow (f : N ≃ₗ[R] N) (n : ℤ) : f.lTensor M ^ n = (f ^ n).lTensor M := by simpa only [one_zpow] using TensorProduct.congr_zpow (1 : M ≃ₗ[R] M) f n end LinearEquiv end Semiring section Ring variable {R : Type*} [CommSemiring R] variable {M : Type*} {N : Type*} {P : Type*} {Q : Type*} {S : Type*} variable [AddCommGroup M] [AddCommMonoid N] [AddCommGroup P] [AddCommMonoid Q] variable [Module R M] [Module R N] [Module R P] [Module R Q] namespace TensorProduct open TensorProduct open LinearMap variable (R) in /-- Auxiliary function to defining negation multiplication on tensor product. -/ def Neg.aux : M ⊗[R] N →ₗ[R] M ⊗[R] N := lift <| (mk R M N).comp (-LinearMap.id) instance neg : Neg (M ⊗[R] N) where neg := Neg.aux R protected theorem neg_add_cancel (x : M ⊗[R] N) : -x + x = 0 := x.induction_on (by rw [add_zero]; apply (Neg.aux R).map_zero) (fun x y => by convert (add_tmul (R := R) (-x) x y).symm; rw [neg_add_cancel, zero_tmul]) fun x y hx hy => by suffices -x + x + (-y + y) = 0 by rw [← this] unfold Neg.neg neg simp only rw [map_add] abel rw [hx, hy, add_zero] instance addCommGroup : AddCommGroup (M ⊗[R] N) := { TensorProduct.addCommMonoid with neg_add_cancel := fun x => TensorProduct.neg_add_cancel x zsmul := (· • ·) zsmul_zero' := by simp zsmul_succ' := by simp [add_comm, TensorProduct.add_smul] zsmul_neg' := fun n x => by change (-n.succ : ℤ) • x = -(((n : ℤ) + 1) • x) rw [← zero_add (_ • x), ← TensorProduct.neg_add_cancel ((n.succ : ℤ) • x), add_assoc, ← add_smul, ← sub_eq_add_neg, sub_self, zero_smul, add_zero] rfl } theorem neg_tmul (m : M) (n : N) : (-m) ⊗ₜ n = -m ⊗ₜ[R] n := rfl theorem tmul_neg (m : M) (p : P) : m ⊗ₜ (-p) = -m ⊗ₜ[R] p := (mk R M P _).map_neg _ theorem tmul_sub (m : M) (p₁ p₂ : P) : m ⊗ₜ (p₁ - p₂) = m ⊗ₜ[R] p₁ - m ⊗ₜ[R] p₂ := (mk R M P _).map_sub _ _ theorem sub_tmul (m₁ m₂ : M) (n : N) : (m₁ - m₂) ⊗ₜ n = m₁ ⊗ₜ[R] n - m₂ ⊗ₜ[R] n := (mk R M N).map_sub₂ _ _ _ /-- While the tensor product will automatically inherit a ℤ-module structure from `AddCommGroup.toIntModule`, that structure won't be compatible with lemmas like `tmul_smul` unless we use a `ℤ-Module` instance provided by `TensorProduct.left_module`. When `R` is a `Ring` we get the required `TensorProduct.compatible_smul` instance through `IsScalarTower`, but when it is only a `Semiring` we need to build it from scratch. The instance diamond in `compatible_smul` doesn't matter because it's in `Prop`. -/ instance CompatibleSMul.int : CompatibleSMul R ℤ M P := ⟨fun r m p => Int.induction_on r (by simp) (fun r ih => by simpa [add_smul, tmul_add, add_tmul] using ih) fun r ih => by simpa [sub_smul, tmul_sub, sub_tmul] using ih⟩ instance CompatibleSMul.unit {S} [Monoid S] [DistribMulAction S M] [DistribMulAction S N] [CompatibleSMul R S M N] : CompatibleSMul R Sˣ M N := ⟨fun s m n => CompatibleSMul.smul_tmul (s : S) m n⟩ end TensorProduct namespace LinearMap @[simp] theorem lTensor_sub (f g : N →ₗ[R] P) : (f - g).lTensor M = f.lTensor M - g.lTensor M := by simp_rw [← coe_lTensorHom] exact (lTensorHom (R := R) (N := N) (P := P) M).map_sub f g @[simp] theorem rTensor_sub (f g : N →ₗ[R] P) : (f - g).rTensor Q = f.rTensor Q - g.rTensor Q := by simp only [← coe_rTensorHom] exact (rTensorHom (R := R) (N := N) (P := P) Q).map_sub f g @[simp] theorem lTensor_neg (f : N →ₗ[R] P) : (-f).lTensor M = -f.lTensor M := by simp only [← coe_lTensorHom] exact (lTensorHom (R := R) (N := N) (P := P) M).map_neg f @[simp] theorem rTensor_neg (f : N →ₗ[R] P) : (-f).rTensor Q = -f.rTensor Q := by simp only [← coe_rTensorHom] exact (rTensorHom (R := R) (N := N) (P := P) Q).map_neg f end LinearMap end Ring
.lake/packages/mathlib/Mathlib/LinearAlgebra/TensorProduct/Quotient.lean
import Mathlib.LinearAlgebra.Quotient.Basic import Mathlib.LinearAlgebra.TensorProduct.Tower import Mathlib.RingTheory.Ideal.Maps import Mathlib.RingTheory.Ideal.Quotient.Defs /-! # Interaction between Quotients and Tensor Products This file contains constructions that relate quotients and tensor products. Let `M, N` be `R`-modules, `m ≤ M` and `n ≤ N` be an `R`-submodules and `I ≤ R` an ideal. We prove the following isomorphisms: ## Main results - `TensorProduct.quotientTensorQuotientEquiv`: `(M ⧸ m) ⊗[R] (N ⧸ n) ≃ₗ[R] (M ⊗[R] N) ⧸ (m ⊗ N ⊔ M ⊗ n)` - `TensorProduct.quotientTensorEquiv`: `(M ⧸ m) ⊗[R] N ≃ₗ[R] (M ⊗[R] N) ⧸ (m ⊗ N)` - `TensorProduct.tensorQuotientEquiv`: `M ⊗[R] (N ⧸ n) ≃ₗ[R] (M ⊗[R] N) ⧸ (M ⊗ n)` - `TensorProduct.quotTensorEquivQuotSMul`: `(R ⧸ I) ⊗[R] M ≃ₗ[R] M ⧸ (I • M)` - `TensorProduct.tensorQuotEquivQuotSMul`: `M ⊗[R] (R ⧸ I) ≃ₗ[R] M ⧸ (I • M)` ## Tags Quotient, Tensor Product -/ assert_not_exists Cardinal namespace TensorProduct variable {R M N : Type*} [CommRing R] variable [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N] attribute [local ext high] ext LinearMap.prod_ext /-- Let `M, N` be `R`-modules, `m ≤ M` and `n ≤ N` be an `R`-submodules. Then we have a linear isomorphism between tensor products of the quotients and the quotient of the tensor product: `(M ⧸ m) ⊗[R] (N ⧸ n) ≃ₗ[R] (M ⊗[R] N) ⧸ (m ⊗ N ⊔ M ⊗ n)`. -/ noncomputable def quotientTensorQuotientEquiv (m : Submodule R M) (n : Submodule R N) : (M ⧸ (m : Submodule R M)) ⊗[R] (N ⧸ (n : Submodule R N)) ≃ₗ[R] (M ⊗[R] N) ⧸ (LinearMap.range (map m.subtype LinearMap.id) ⊔ LinearMap.range (map LinearMap.id n.subtype)) := LinearEquiv.ofLinear (lift <| Submodule.liftQ _ (LinearMap.flip <| Submodule.liftQ _ ((mk R (M := M) (N := N)).flip.compr₂ (Submodule.mkQ _)) fun x hx => by ext y simp only [LinearMap.compr₂_apply, LinearMap.flip_apply, mk_apply, Submodule.mkQ_apply, LinearMap.zero_apply, Submodule.Quotient.mk_eq_zero] exact Submodule.mem_sup_right ⟨y ⊗ₜ ⟨x, hx⟩, rfl⟩) fun x hx => by ext y simp only [LinearMap.coe_comp, Function.comp_apply, Submodule.mkQ_apply, LinearMap.flip_apply, Submodule.liftQ_apply, LinearMap.compr₂_apply, mk_apply, LinearMap.zero_comp, LinearMap.zero_apply, Submodule.Quotient.mk_eq_zero] exact Submodule.mem_sup_left ⟨⟨x, hx⟩ ⊗ₜ y, rfl⟩) (Submodule.liftQ _ (map (Submodule.mkQ _) (Submodule.mkQ _)) fun x hx => by rw [Submodule.mem_sup] at hx rcases hx with ⟨_, ⟨a, rfl⟩, _, ⟨b, rfl⟩, rfl⟩ simp only [LinearMap.mem_ker, map_add] set f := (map m.mkQ n.mkQ) ∘ₗ (map m.subtype LinearMap.id) set g := (map m.mkQ n.mkQ) ∘ₗ (map LinearMap.id n.subtype) have eq : LinearMap.coprod f g = 0 := by ext x y · simp [f, Submodule.Quotient.mk_eq_zero _ |>.2 x.2] · simp [g, Submodule.Quotient.mk_eq_zero _ |>.2 y.2] exact congr($eq (a, b))) (by ext; simp) (by ext; simp) @[simp] lemma quotientTensorQuotientEquiv_apply_tmul_mk_tmul_mk (m : Submodule R M) (n : Submodule R N) (x : M) (y : N) : quotientTensorQuotientEquiv m n (Submodule.Quotient.mk x ⊗ₜ[R] Submodule.Quotient.mk y) = Submodule.Quotient.mk (x ⊗ₜ y) := rfl @[simp] lemma quotientTensorQuotientEquiv_symm_apply_mk_tmul (m : Submodule R M) (n : Submodule R N) (x : M) (y : N) : (quotientTensorQuotientEquiv m n).symm (Submodule.Quotient.mk (x ⊗ₜ y)) = Submodule.Quotient.mk x ⊗ₜ[R] Submodule.Quotient.mk y := rfl variable (N) in /-- Let `M, N` be `R`-modules, `m ≤ M` be an `R`-submodule. Then we have a linear isomorphism between tensor products of the quotient and the quotient of the tensor product: `(M ⧸ m) ⊗[R] N ≃ₗ[R] (M ⊗[R] N) ⧸ (m ⊗ N)`. -/ noncomputable def quotientTensorEquiv (m : Submodule R M) : (M ⧸ (m : Submodule R M)) ⊗[R] N ≃ₗ[R] (M ⊗[R] N) ⧸ (LinearMap.range (map m.subtype (LinearMap.id : N →ₗ[R] N))) := congr (LinearEquiv.refl _ _) ((Submodule.quotEquivOfEqBot _ rfl).symm) ≪≫ₗ quotientTensorQuotientEquiv (N := N) m ⊥ ≪≫ₗ Submodule.Quotient.equiv _ _ (LinearEquiv.refl _ _) (by simp only [Submodule.map_sup] erw [Submodule.map_id, Submodule.map_id] simp only [sup_eq_left] rw [range_map_eq_span_tmul, range_map_eq_span_tmul] simp) @[simp] lemma quotientTensorEquiv_apply_tmul_mk (m : Submodule R M) (x : M) (y : N) : quotientTensorEquiv N m (Submodule.Quotient.mk x ⊗ₜ[R] y) = Submodule.Quotient.mk (x ⊗ₜ y) := rfl @[simp] lemma quotientTensorEquiv_symm_apply_mk_tmul (m : Submodule R M) (x : M) (y : N) : (quotientTensorEquiv N m).symm (Submodule.Quotient.mk (x ⊗ₜ y)) = Submodule.Quotient.mk x ⊗ₜ[R] y := rfl variable (M) in /-- Let `M, N` be `R`-modules, `n ≤ N` be an `R`-submodule. Then we have a linear isomorphism between tensor products of the quotient and the quotient of the tensor product: `M ⊗[R] (N ⧸ n) ≃ₗ[R] (M ⊗[R] N) ⧸ (M ⊗ n)`. -/ noncomputable def tensorQuotientEquiv (n : Submodule R N) : M ⊗[R] (N ⧸ (n : Submodule R N)) ≃ₗ[R] (M ⊗[R] N) ⧸ (LinearMap.range (map (LinearMap.id : M →ₗ[R] M) n.subtype)) := congr ((Submodule.quotEquivOfEqBot _ rfl).symm) (LinearEquiv.refl _ _) ≪≫ₗ quotientTensorQuotientEquiv (⊥ : Submodule R M) n ≪≫ₗ Submodule.Quotient.equiv _ _ (LinearEquiv.refl _ _) (by simp only [Submodule.map_sup] erw [Submodule.map_id, Submodule.map_id] simp only [sup_eq_right] rw [range_map_eq_span_tmul, range_map_eq_span_tmul] simp) @[simp] lemma tensorQuotientEquiv_apply_mk_tmul (n : Submodule R N) (x : M) (y : N) : tensorQuotientEquiv M n (x ⊗ₜ[R] Submodule.Quotient.mk y) = Submodule.Quotient.mk (x ⊗ₜ y) := rfl @[simp] lemma tensorQuotientEquiv_symm_apply_tmul_mk (n : Submodule R N) (x : M) (y : N) : (tensorQuotientEquiv M n).symm (Submodule.Quotient.mk (x ⊗ₜ y)) = x ⊗ₜ[R] Submodule.Quotient.mk y := rfl variable (M) in /-- Left tensoring a module with a quotient of the ring is the same as quotienting that module by the corresponding submodule. -/ noncomputable def quotTensorEquivQuotSMul (I : Ideal R) : ((R ⧸ I) ⊗[R] M) ≃ₗ[R] M ⧸ (I • (⊤ : Submodule R M)) := quotientTensorEquiv M I ≪≫ₗ (Submodule.Quotient.equiv _ _ (TensorProduct.lid R M) <| by rw [← Submodule.map_coe_toLinearMap, ← LinearMap.range_comp, ← (Submodule.topEquiv.lTensor I).range_comp, Submodule.smul_eq_map₂, map₂_eq_range_lift_comp_mapIncl] exact congr_arg _ (TensorProduct.ext' fun _ _ ↦ rfl)) variable (M) in /-- Right tensoring a module with a quotient of the ring is the same as quotienting that module by the corresponding submodule. -/ noncomputable def tensorQuotEquivQuotSMul (I : Ideal R) : (M ⊗[R] (R ⧸ I)) ≃ₗ[R] M ⧸ (I • (⊤ : Submodule R M)) := TensorProduct.comm _ _ _ ≪≫ₗ quotTensorEquivQuotSMul M I @[simp] lemma quotTensorEquivQuotSMul_mk_tmul (I : Ideal R) (r : R) (x : M) : quotTensorEquivQuotSMul M I (Ideal.Quotient.mk I r ⊗ₜ[R] x) = Submodule.Quotient.mk (r • x) := (quotTensorEquivQuotSMul M I).eq_symm_apply.mp <| Eq.trans (congrArg (· ⊗ₜ[R] x) <| Eq.trans (congrArg (Ideal.Quotient.mk I) (Eq.trans (smul_eq_mul ..) (mul_one r))).symm <| Submodule.Quotient.mk_smul I r 1) <| smul_tmul r _ x lemma quotTensorEquivQuotSMul_comp_mkQ_rTensor (I : Ideal R) : quotTensorEquivQuotSMul M I ∘ₗ I.mkQ.rTensor M = (I • ⊤ : Submodule R M).mkQ ∘ₗ TensorProduct.lid R M := TensorProduct.ext' (quotTensorEquivQuotSMul_mk_tmul I) @[simp] lemma quotTensorEquivQuotSMul_symm_mk (I : Ideal R) (x : M) : (quotTensorEquivQuotSMul M I).symm (Submodule.Quotient.mk x) = 1 ⊗ₜ[R] x := rfl lemma quotTensorEquivQuotSMul_symm_comp_mkQ (I : Ideal R) : (quotTensorEquivQuotSMul M I).symm ∘ₗ (I • ⊤ : Submodule R M).mkQ = TensorProduct.mk R (R ⧸ I) M 1 := LinearMap.ext (quotTensorEquivQuotSMul_symm_mk I) lemma quotTensorEquivQuotSMul_comp_mk (I : Ideal R) : quotTensorEquivQuotSMul M I ∘ₗ TensorProduct.mk R (R ⧸ I) M 1 = Submodule.mkQ (I • ⊤) := Eq.symm <| (LinearEquiv.toLinearMap_symm_comp_eq _ _).mp <| quotTensorEquivQuotSMul_symm_comp_mkQ I @[simp] lemma tensorQuotEquivQuotSMul_tmul_mk (I : Ideal R) (x : M) (r : R) : tensorQuotEquivQuotSMul M I (x ⊗ₜ[R] Ideal.Quotient.mk I r) = Submodule.Quotient.mk (r • x) := quotTensorEquivQuotSMul_mk_tmul I r x lemma tensorQuotEquivQuotSMul_comp_mkQ_lTensor (I : Ideal R) : tensorQuotEquivQuotSMul M I ∘ₗ I.mkQ.lTensor M = (I • ⊤ : Submodule R M).mkQ ∘ₗ TensorProduct.rid R M := TensorProduct.ext' (tensorQuotEquivQuotSMul_tmul_mk I) @[simp] lemma tensorQuotEquivQuotSMul_symm_mk (I : Ideal R) (x : M) : (tensorQuotEquivQuotSMul M I).symm (Submodule.Quotient.mk x) = x ⊗ₜ[R] 1 := rfl lemma tensorQuotEquivQuotSMul_symm_comp_mkQ (I : Ideal R) : (tensorQuotEquivQuotSMul M I).symm ∘ₗ (I • ⊤ : Submodule R M).mkQ = (TensorProduct.mk R M (R ⧸ I)).flip 1 := LinearMap.ext (tensorQuotEquivQuotSMul_symm_mk I) lemma tensorQuotEquivQuotSMul_comp_mk (I : Ideal R) : tensorQuotEquivQuotSMul M I ∘ₗ (TensorProduct.mk R M (R ⧸ I)).flip 1 = Submodule.mkQ (I • ⊤) := Eq.symm <| (LinearEquiv.toLinearMap_symm_comp_eq _ _).mp <| tensorQuotEquivQuotSMul_symm_comp_mkQ I variable (S : Type*) [CommRing S] [Algebra R S] /-- Let `R` be a commutative ring, `S` be an `R`-algebra, `I` is be ideal of `R`, then `S ⧸ IS` is isomorphic to `S ⊗[R] (R ⧸ I)` as `S` modules. -/ noncomputable def _root_.Ideal.qoutMapEquivTensorQout {I : Ideal R} : (S ⧸ I.map (algebraMap R S)) ≃ₗ[S] S ⊗[R] (R ⧸ I) where __ := LinearEquiv.symm <| tensorQuotEquivQuotSMul S I ≪≫ₗ Submodule.quotEquivOfEq _ _ (by simp) ≪≫ₗ Submodule.Quotient.restrictScalarsEquiv R _ map_smul' := by rintro _ ⟨_⟩ congr variable (M) in /-- Let `R` be a commutative ring, `S` be an `R`-algebra, `I` is be ideal of `R`, then `S ⊗[R] M ⧸ I(S ⊗[R] M)` is isomorphic to `S ⊗[R] (M ⧸ IM)` as `S` modules. -/ noncomputable def tensorQuotMapSMulEquivTensorQuot (I : Ideal R) : ((S ⊗[R] M) ⧸ I.map (algebraMap R S) • (⊤ : Submodule S (S ⊗[R] M))) ≃ₗ[S] S ⊗[R] (M ⧸ (I • (⊤ : Submodule R M))) := (tensorQuotEquivQuotSMul (S ⊗[R] M) (I.map (algebraMap R S))).symm ≪≫ₗ TensorProduct.comm S (S ⊗[R] M) _ ≪≫ₗ AlgebraTensorModule.cancelBaseChange R S S _ M ≪≫ₗ AlgebraTensorModule.congr (I.qoutMapEquivTensorQout S) (LinearEquiv.refl R M) ≪≫ₗ AlgebraTensorModule.assoc R R S S _ M ≪≫ₗ (TensorProduct.comm R _ M).baseChange R S _ _ ≪≫ₗ (tensorQuotEquivQuotSMul M I).baseChange R S _ _ end TensorProduct
.lake/packages/mathlib/Mathlib/LinearAlgebra/TensorProduct/RightExactness.lean
import Mathlib.Algebra.Exact import Mathlib.RingTheory.Ideal.Maps import Mathlib.RingTheory.Ideal.Quotient.Defs import Mathlib.RingTheory.TensorProduct.Maps /-! # Right-exactness properties of tensor product ## Modules * `LinearMap.rTensor_surjective` asserts that when one tensors a surjective map on the right, one still gets a surjective linear map. More generally, `LinearMap.rTensor_range` computes the range of `LinearMap.rTensor` * `LinearMap.lTensor_surjective` asserts that when one tensors a surjective map on the left, one still gets a surjective linear map. More generally, `LinearMap.lTensor_range` computes the range of `LinearMap.lTensor` * `TensorProduct.rTensor_exact` says that when one tensors a short exact sequence on the right, one still gets a short exact sequence (right-exactness of `TensorProduct.rTensor`), and `rTensor.equiv` gives the LinearEquiv that follows from this combined with `LinearMap.rTensor_surjective`. * `TensorProduct.lTensor_exact` says that when one tensors a short exact sequence on the left, one still gets a short exact sequence (right-exactness of `TensorProduct.rTensor`) and `lTensor.equiv` gives the LinearEquiv that follows from this combined with `LinearMap.lTensor_surjective`. * For `N : Submodule R M`, `LinearMap.exact_subtype_mkQ N` says that the inclusion of the submodule and the quotient map form an exact pair, and `lTensor_mkQ` compute `ker (lTensor Q (N.mkQ))` and similarly for `rTensor_mkQ` * `TensorProduct.map_ker` computes the kernel of `TensorProduct.map f g'` in the presence of two short exact sequences. The proofs are those of [bourbaki1989] (chap. 2, §3, n°6) ## Algebras In the case of a tensor product of algebras, these results can be particularized to compute some kernels. * `Algebra.TensorProduct.ker_map` computes the kernel of `Algebra.TensorProduct.map f g` * `Algebra.TensorProduct.lTensor_ker` and `Algebra.TensorProduct.rTensor_ker` compute the kernels of `Algebra.TensorProduct.map f id` and `Algebra.TensorProduct.map id g` ## Note on implementation * All kernels are computed by applying the first isomorphism theorem and establishing some isomorphisms. * The proofs are essentially done twice, once for `lTensor` and then for `rTensor`. It is possible to apply `TensorProduct.flip` to deduce one of them from the other. However, this approach will lead to different isomorphisms, and it is not quicker. * The proofs of `Ideal.map_includeLeft_eq` and `Ideal.map_includeRight_eq` could be easier if `I ⊗[R] B` was naturally an `A ⊗[R] B` module, and the map to `A ⊗[R] B` was known to be linear. This depends on the B-module structure on a tensor product whose use rapidly conflicts with everything… ## TODO * Treat the noncommutative case * Treat the case of modules over semirings (For a possible definition of an exact sequence of commutative semigroups, see [Grillet-1969b], Pierre-Antoine Grillet, *The tensor product of commutative semigroups*, Trans. Amer. Math. Soc. 138 (1969), 281-293, doi:10.1090/S0002-9947-1969-0237688-1 .) -/ assert_not_exists Cardinal section Modules open TensorProduct LinearMap section Semiring variable {R : Type*} [CommSemiring R] {M N P Q : Type*} [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] [AddCommMonoid Q] [Module R M] [Module R N] [Module R P] [Module R Q] {f : M →ₗ[R] N} (g : N →ₗ[R] P) lemma le_comap_range_lTensor (q : Q) : LinearMap.range g ≤ (LinearMap.range (lTensor Q g)).comap (TensorProduct.mk R Q P q) := by rintro x ⟨n, rfl⟩ exact ⟨q ⊗ₜ[R] n, rfl⟩ lemma le_comap_range_rTensor (q : Q) : LinearMap.range g ≤ (LinearMap.range (rTensor Q g)).comap ((TensorProduct.mk R P Q).flip q) := by rintro x ⟨n, rfl⟩ exact ⟨n ⊗ₜ[R] q, rfl⟩ variable (Q) {g} /-- If `g` is surjective, then `lTensor Q g` is surjective -/ theorem LinearMap.lTensor_surjective (hg : Function.Surjective g) : Function.Surjective (lTensor Q g) := by intro z induction z with | zero => exact ⟨0, map_zero _⟩ | tmul q p => obtain ⟨n, rfl⟩ := hg p exact ⟨q ⊗ₜ[R] n, rfl⟩ | add x y hx hy => obtain ⟨x, rfl⟩ := hx obtain ⟨y, rfl⟩ := hy exact ⟨x + y, map_add _ _ _⟩ theorem LinearMap.lTensor_range : range (lTensor Q g) = range (lTensor Q (Submodule.subtype (range g))) := by have : g = (Submodule.subtype _).comp g.rangeRestrict := rfl nth_rewrite 1 [this] rw [lTensor_comp] apply range_comp_of_range_eq_top rw [range_eq_top] apply lTensor_surjective rw [← range_eq_top, range_rangeRestrict] /-- If `g` is surjective, then `rTensor Q g` is surjective -/ theorem LinearMap.rTensor_surjective (hg : Function.Surjective g) : Function.Surjective (rTensor Q g) := by intro z induction z with | zero => exact ⟨0, map_zero _⟩ | tmul p q => obtain ⟨n, rfl⟩ := hg p exact ⟨n ⊗ₜ[R] q, rfl⟩ | add x y hx hy => obtain ⟨x, rfl⟩ := hx obtain ⟨y, rfl⟩ := hy exact ⟨x + y, map_add _ _ _⟩ theorem LinearMap.rTensor_range : range (rTensor Q g) = range (rTensor Q (Submodule.subtype (range g))) := by have : g = (Submodule.subtype _).comp g.rangeRestrict := rfl nth_rewrite 1 [this] rw [rTensor_comp] apply range_comp_of_range_eq_top rw [range_eq_top] apply rTensor_surjective rw [← range_eq_top, range_rangeRestrict] lemma LinearMap.rTensor_exact_iff_lTensor_exact : Function.Exact (f.rTensor Q) (g.rTensor Q) ↔ Function.Exact (f.lTensor Q) (g.lTensor Q) := Function.Exact.iff_of_ladder_linearEquiv (e₁ := TensorProduct.comm _ _ _) (e₂ := TensorProduct.comm _ _ _) (e₃ := TensorProduct.comm _ _ _) (by ext; simp) (by ext; simp) variable (hg : Function.Surjective g) {N' P' : Type*} [AddCommMonoid N'] [AddCommMonoid P'] [Module R N'] [Module R P'] {g' : N' →ₗ[R] P'} (hg' : Function.Surjective g') include hg hg' in theorem TensorProduct.map_surjective : Function.Surjective (TensorProduct.map g g') := by rw [← lTensor_comp_rTensor, coe_comp] exact Function.Surjective.comp (lTensor_surjective _ hg') (rTensor_surjective _ hg) end Semiring variable {R M N P : Type*} [CommRing R] [AddCommGroup M] [AddCommGroup N] [AddCommGroup P] [Module R M] [Module R N] [Module R P] open Function variable {f : M →ₗ[R] N} {g : N →ₗ[R] P} (Q : Type*) [AddCommGroup Q] [Module R Q] (hfg : Exact f g) (hg : Function.Surjective g) /-- The direct map in `lTensor.equiv` -/ noncomputable def lTensor.toFun (hfg : Exact f g) : Q ⊗[R] N ⧸ LinearMap.range (lTensor Q f) →ₗ[R] Q ⊗[R] P := Submodule.liftQ _ (lTensor Q g) <| by rw [LinearMap.range_le_iff_comap, ← LinearMap.ker_comp, ← lTensor_comp, hfg.linearMap_comp_eq_zero, lTensor_zero, ker_zero] /-- The inverse map in `lTensor.equiv_of_rightInverse` (computably, given a right inverse) -/ noncomputable def lTensor.inverse_of_rightInverse {h : P → N} (hfg : Exact f g) (hgh : Function.RightInverse h g) : Q ⊗[R] P →ₗ[R] Q ⊗[R] N ⧸ LinearMap.range (lTensor Q f) := TensorProduct.lift <| LinearMap.flip <| { toFun := fun p ↦ Submodule.mkQ _ ∘ₗ ((TensorProduct.mk R _ _).flip (h p)) map_add' := fun p p' => LinearMap.ext fun q => (Submodule.Quotient.eq _).mpr <| by change q ⊗ₜ[R] (h (p + p')) - (q ⊗ₜ[R] (h p) + q ⊗ₜ[R] (h p')) ∈ range (lTensor Q f) rw [← TensorProduct.tmul_add, ← TensorProduct.tmul_sub] apply le_comap_range_lTensor f rw [exact_iff] at hfg simp only [← hfg, mem_ker, map_sub, map_add, hgh _, sub_self] map_smul' := fun r p => LinearMap.ext fun q => (Submodule.Quotient.eq _).mpr <| by change q ⊗ₜ[R] (h (r • p)) - r • q ⊗ₜ[R] (h p) ∈ range (lTensor Q f) rw [← TensorProduct.tmul_smul, ← TensorProduct.tmul_sub] apply le_comap_range_lTensor f rw [exact_iff] at hfg simp only [← hfg, mem_ker, map_sub, map_smul, hgh _, sub_self] } lemma lTensor.inverse_of_rightInverse_apply {h : P → N} (hgh : Function.RightInverse h g) (y : Q ⊗[R] N) : (lTensor.inverse_of_rightInverse Q hfg hgh) ((lTensor Q g) y) = Submodule.Quotient.mk (p := (LinearMap.range (lTensor Q f))) y := by simp only [← LinearMap.comp_apply, ← Submodule.mkQ_apply] rw [exact_iff] at hfg apply LinearMap.congr_fun apply TensorProduct.ext' intro n q suffices Submodule.Quotient.mk (n ⊗ₜ[R] h (g q)) = Submodule.Quotient.mk (n ⊗ₜ[R] q) by simpa rw [Submodule.Quotient.eq, ← TensorProduct.tmul_sub] apply le_comap_range_lTensor f n rw [← hfg, mem_ker, map_sub, sub_eq_zero, hgh] lemma lTensor.inverse_of_rightInverse_comp_lTensor {h : P → N} (hgh : Function.RightInverse h g) : (lTensor.inverse_of_rightInverse Q hfg hgh).comp (lTensor Q g) = Submodule.mkQ (p := LinearMap.range (lTensor Q f)) := by rw [LinearMap.ext_iff] intro y simp only [coe_comp, Function.comp_apply, Submodule.mkQ_apply, lTensor.inverse_of_rightInverse_apply] /-- The inverse map in `lTensor.equiv` -/ noncomputable def lTensor.inverse : Q ⊗[R] P →ₗ[R] Q ⊗[R] N ⧸ LinearMap.range (lTensor Q f) := lTensor.inverse_of_rightInverse Q hfg (Function.rightInverse_surjInv hg) lemma lTensor.inverse_apply (y : Q ⊗[R] N) : (lTensor.inverse Q hfg hg) ((lTensor Q g) y) = Submodule.Quotient.mk (p := (LinearMap.range (lTensor Q f))) y := by rw [lTensor.inverse, lTensor.inverse_of_rightInverse_apply] lemma lTensor.inverse_comp_lTensor : (lTensor.inverse Q hfg hg).comp (lTensor Q g) = Submodule.mkQ (p := LinearMap.range (lTensor Q f)) := by rw [lTensor.inverse, lTensor.inverse_of_rightInverse_comp_lTensor] /-- For a surjective `f : N →ₗ[R] P`, the natural equivalence between `Q ⊗ N ⧸ (image of ker f)` to `Q ⊗ P` (computably, given a right inverse) -/ noncomputable def lTensor.linearEquiv_of_rightInverse {h : P → N} (hgh : Function.RightInverse h g) : ((Q ⊗[R] N) ⧸ (LinearMap.range (lTensor Q f))) ≃ₗ[R] (Q ⊗[R] P) := { toLinearMap := lTensor.toFun Q hfg invFun := lTensor.inverse_of_rightInverse Q hfg hgh left_inv := fun y ↦ by simp only [lTensor.toFun, AddHom.toFun_eq_coe, coe_toAddHom] obtain ⟨y, rfl⟩ := Submodule.mkQ_surjective _ y simp only [Submodule.mkQ_apply, Submodule.liftQ_apply, lTensor.inverse_of_rightInverse_apply] right_inv := fun z ↦ by simp only [AddHom.toFun_eq_coe, coe_toAddHom] obtain ⟨y, rfl⟩ := lTensor_surjective Q (hgh.surjective) z rw [lTensor.inverse_of_rightInverse_apply] simp only [lTensor.toFun, Submodule.liftQ_apply] } /-- For a surjective `f : N →ₗ[R] P`, the natural equivalence between `Q ⊗ N ⧸ (image of ker f)` to `Q ⊗ P` -/ noncomputable def lTensor.equiv : ((Q ⊗[R] N) ⧸ (LinearMap.range (lTensor Q f))) ≃ₗ[R] (Q ⊗[R] P) := lTensor.linearEquiv_of_rightInverse Q hfg (Function.rightInverse_surjInv hg) include hfg hg in /-- Tensoring an exact pair on the left gives an exact pair -/ theorem lTensor_exact : Exact (lTensor Q f) (lTensor Q g) := by rw [exact_iff, ← Submodule.ker_mkQ (p := range (lTensor Q f)), ← lTensor.inverse_comp_lTensor Q hfg hg] apply symm apply LinearMap.ker_comp_of_ker_eq_bot rw [LinearMap.ker_eq_bot] exact (lTensor.equiv Q hfg hg).symm.injective /-- Right-exactness of tensor product -/ lemma lTensor_mkQ (N : Submodule R M) : ker (lTensor Q N.mkQ) = range (lTensor Q N.subtype) := by rw [← exact_iff] exact lTensor_exact Q (LinearMap.exact_subtype_mkQ N) (Submodule.mkQ_surjective N) /-- The direct map in `rTensor.equiv` -/ noncomputable def rTensor.toFun (hfg : Exact f g) : N ⊗[R] Q ⧸ range (rTensor Q f) →ₗ[R] P ⊗[R] Q := Submodule.liftQ _ (rTensor Q g) <| by rw [range_le_iff_comap, ← ker_comp, ← rTensor_comp, hfg.linearMap_comp_eq_zero, rTensor_zero, ker_zero] /-- The inverse map in `rTensor.equiv_of_rightInverse` (computably, given a right inverse) -/ noncomputable def rTensor.inverse_of_rightInverse {h : P → N} (hfg : Exact f g) (hgh : Function.RightInverse h g) : P ⊗[R] Q →ₗ[R] N ⊗[R] Q ⧸ LinearMap.range (rTensor Q f) := TensorProduct.lift { toFun := fun p ↦ Submodule.mkQ _ ∘ₗ TensorProduct.mk R _ _ (h p) map_add' := fun p p' => LinearMap.ext fun q => (Submodule.Quotient.eq _).mpr <| by change h (p + p') ⊗ₜ[R] q - (h p ⊗ₜ[R] q + h p' ⊗ₜ[R] q) ∈ range (rTensor Q f) rw [← TensorProduct.add_tmul, ← TensorProduct.sub_tmul] apply le_comap_range_rTensor f rw [exact_iff] at hfg simp only [← hfg, mem_ker, map_sub, map_add, hgh _, sub_self] map_smul' := fun r p => LinearMap.ext fun q => (Submodule.Quotient.eq _).mpr <| by change h (r • p) ⊗ₜ[R] q - r • h p ⊗ₜ[R] q ∈ range (rTensor Q f) rw [TensorProduct.smul_tmul', ← TensorProduct.sub_tmul] apply le_comap_range_rTensor f rw [exact_iff] at hfg simp only [← hfg, mem_ker, map_sub, map_smul, hgh _, sub_self] } lemma rTensor.inverse_of_rightInverse_apply {h : P → N} (hgh : Function.RightInverse h g) (y : N ⊗[R] Q) : (rTensor.inverse_of_rightInverse Q hfg hgh) ((rTensor Q g) y) = Submodule.Quotient.mk (p := LinearMap.range (rTensor Q f)) y := by simp only [← LinearMap.comp_apply, ← Submodule.mkQ_apply] rw [exact_iff] at hfg apply LinearMap.congr_fun apply TensorProduct.ext' intro n q suffices Submodule.Quotient.mk (h (g n) ⊗ₜ[R] q) = Submodule.Quotient.mk (n ⊗ₜ[R] q) by simpa rw [Submodule.Quotient.eq, ← TensorProduct.sub_tmul] apply le_comap_range_rTensor f rw [← hfg, mem_ker, map_sub, sub_eq_zero, hgh] lemma rTensor.inverse_of_rightInverse_comp_rTensor {h : P → N} (hgh : Function.RightInverse h g) : (rTensor.inverse_of_rightInverse Q hfg hgh).comp (rTensor Q g) = Submodule.mkQ (p := LinearMap.range (rTensor Q f)) := by rw [LinearMap.ext_iff] intro y simp only [coe_comp, Function.comp_apply, Submodule.mkQ_apply, rTensor.inverse_of_rightInverse_apply] /-- The inverse map in `rTensor.equiv` -/ noncomputable def rTensor.inverse : P ⊗[R] Q →ₗ[R] N ⊗[R] Q ⧸ LinearMap.range (rTensor Q f) := rTensor.inverse_of_rightInverse Q hfg (Function.rightInverse_surjInv hg) lemma rTensor.inverse_apply (y : N ⊗[R] Q) : (rTensor.inverse Q hfg hg) ((rTensor Q g) y) = Submodule.Quotient.mk (p := LinearMap.range (rTensor Q f)) y := by rw [rTensor.inverse, rTensor.inverse_of_rightInverse_apply] lemma rTensor.inverse_comp_rTensor : (rTensor.inverse Q hfg hg).comp (rTensor Q g) = Submodule.mkQ (p := LinearMap.range (rTensor Q f)) := by rw [rTensor.inverse, rTensor.inverse_of_rightInverse_comp_rTensor] /-- For a surjective `f : N →ₗ[R] P`, the natural equivalence between `N ⊗[R] Q ⧸ (range (rTensor Q f))` and `P ⊗[R] Q` (computably, given a right inverse) -/ noncomputable def rTensor.linearEquiv_of_rightInverse {h : P → N} (hgh : Function.RightInverse h g) : ((N ⊗[R] Q) ⧸ (range (rTensor Q f))) ≃ₗ[R] (P ⊗[R] Q) := { toLinearMap := rTensor.toFun Q hfg invFun := rTensor.inverse_of_rightInverse Q hfg hgh left_inv := fun y ↦ by simp only [rTensor.toFun, AddHom.toFun_eq_coe, coe_toAddHom] obtain ⟨y, rfl⟩ := Submodule.mkQ_surjective _ y simp only [Submodule.mkQ_apply, Submodule.liftQ_apply, rTensor.inverse_of_rightInverse_apply] right_inv := fun z ↦ by simp only [AddHom.toFun_eq_coe, coe_toAddHom] obtain ⟨y, rfl⟩ := rTensor_surjective Q hgh.surjective z rw [rTensor.inverse_of_rightInverse_apply] simp only [rTensor.toFun, Submodule.liftQ_apply] } /-- For a surjective `f : N →ₗ[R] P`, the natural equivalence between `N ⊗[R] Q ⧸ (range (rTensor Q f))` and `P ⊗[R] Q` -/ noncomputable def rTensor.equiv : ((N ⊗[R] Q) ⧸ (LinearMap.range (rTensor Q f))) ≃ₗ[R] (P ⊗[R] Q) := rTensor.linearEquiv_of_rightInverse Q hfg (Function.rightInverse_surjInv hg) include hfg hg in /-- Tensoring an exact pair on the right gives an exact pair -/ theorem rTensor_exact : Exact (rTensor Q f) (rTensor Q g) := by rw [rTensor_exact_iff_lTensor_exact] exact lTensor_exact Q hfg hg /-- Right-exactness of tensor product (`rTensor`) -/ lemma rTensor_mkQ (N : Submodule R M) : ker (rTensor Q N.mkQ) = range (rTensor Q N.subtype) := by rw [← exact_iff] exact rTensor_exact Q (LinearMap.exact_subtype_mkQ N) (Submodule.mkQ_surjective N) open Submodule LinearEquiv in lemma LinearMap.ker_tensorProductMk {I : Ideal R} : ker (TensorProduct.mk R (R ⧸ I) Q 1) = I • ⊤ := by apply comap_injective_of_surjective (TensorProduct.lid R Q).surjective rw [← comap_coe_toLinearMap, ← ker_comp] convert rTensor_mkQ Q I · ext; simp rw [← comap_coe_toLinearMap, ← toLinearMap_eq_coe, comap_equiv_eq_map_symm, toLinearMap_eq_coe, map_coe_toLinearMap, map_symm_eq_iff, map_range_rTensor_subtype_lid] variable {M' N' P' : Type*} [AddCommGroup M'] [AddCommGroup N'] [AddCommGroup P'] [Module R M'] [Module R N'] [Module R P'] {f' : M' →ₗ[R] N'} {g' : N' →ₗ[R] P'} (hfg' : Exact f' g') (hg' : Function.Surjective g') include hg hg' hfg hfg' in /-- Kernel of a product map (right-exactness of tensor product) -/ theorem TensorProduct.map_ker : ker (TensorProduct.map g g') = range (lTensor N f') ⊔ range (rTensor N' f) := by rw [← lTensor_comp_rTensor] rw [ker_comp] rw [← Exact.linearMap_ker_eq (rTensor_exact N' hfg hg)] rw [← Submodule.comap_map_eq] apply congr_arg₂ _ rfl rw [range_eq_map, ← Submodule.map_comp, rTensor_comp_lTensor, Submodule.map_top] rw [← lTensor_comp_rTensor, range_eq_map, Submodule.map_comp, Submodule.map_top] rw [range_eq_top.mpr (rTensor_surjective M' hg), Submodule.map_top] rw [Exact.linearMap_ker_eq (lTensor_exact P hfg' hg')] end Modules section Algebras open Algebra.TensorProduct open scoped TensorProduct variable {R : Type*} [CommSemiring R] {A B : Type*} [Semiring A] [Semiring B] [Algebra R A] [Algebra R B] /-- The ideal of `A ⊗[R] B` generated by `I` is the image of `I ⊗[R] B` -/ lemma Ideal.map_includeLeft_eq (I : Ideal A) : (I.map (Algebra.TensorProduct.includeLeft : A →ₐ[R] A ⊗[R] B)).restrictScalars R = LinearMap.range (LinearMap.rTensor B (Submodule.subtype (I.restrictScalars R))) := by rw [← SetLike.coe_set_eq] apply le_antisymm · intro x hx simp only [SetLike.mem_coe, LinearMap.mem_range] rw [Ideal.map, ← submodule_span_eq] at hx refine Submodule.span_induction ?_ ?_ ?_ ?_ hx · intro x simp only [includeLeft_apply, Set.mem_image, SetLike.mem_coe] rintro ⟨y, hy, rfl⟩ use ⟨y, hy⟩ ⊗ₜ[R] 1 rfl · use 0 simp only [map_zero] · rintro x y - - ⟨x, hx, rfl⟩ ⟨y, hy, rfl⟩ use x + y simp only [map_add] · rintro a x - ⟨x, hx, rfl⟩ induction a with | zero => use 0 simp only [map_zero, smul_eq_mul, zero_mul] | tmul a b => induction x with | zero => use 0 simp only [map_zero, smul_eq_mul, mul_zero] | tmul x y => use (a • x) ⊗ₜ[R] (b * y) simp only [smul_eq_mul] with_unfolding_all rfl | add x y hx hy => obtain ⟨x', hx'⟩ := hx obtain ⟨y', hy'⟩ := hy use x' + y' simp only [map_add, hx', smul_add, hy'] | add a b ha hb => obtain ⟨x', ha'⟩ := ha obtain ⟨y', hb'⟩ := hb use x' + y' simp only [map_add, ha', add_smul, hb'] · rintro x ⟨y, rfl⟩ induction y with | zero => rw [map_zero] apply zero_mem | tmul a b => simp only [LinearMap.rTensor_tmul, Submodule.coe_subtype] suffices (a : A) ⊗ₜ[R] b = ((1 : A) ⊗ₜ[R] b) * ((a : A) ⊗ₜ[R] (1 : B)) by simp only [Submodule.coe_restrictScalars, SetLike.mem_coe] rw [this] apply Ideal.mul_mem_left -- Note: adding `includeLeft` as a hint fixes a timeout https://github.com/leanprover-community/mathlib4/pull/8386 apply Ideal.mem_map_of_mem includeLeft exact Submodule.coe_mem a simp only [Algebra.TensorProduct.tmul_mul_tmul, mul_one, one_mul] | add x y hx hy => rw [map_add] apply Submodule.add_mem _ hx hy /-- The ideal of `A ⊗[R] B` generated by `I` is the image of `A ⊗[R] I` -/ lemma Ideal.map_includeRight_eq (I : Ideal B) : (I.map (Algebra.TensorProduct.includeRight : B →ₐ[R] A ⊗[R] B)).restrictScalars R = LinearMap.range (LinearMap.lTensor A (Submodule.subtype (I.restrictScalars R))) := by rw [← SetLike.coe_set_eq] apply le_antisymm · intro x hx simp only [SetLike.mem_coe, LinearMap.mem_range] rw [Ideal.map, ← submodule_span_eq] at hx refine Submodule.span_induction ?_ ?_ ?_ ?_ hx · intro x simp only [includeRight_apply, Set.mem_image, SetLike.mem_coe] rintro ⟨y, hy, rfl⟩ use 1 ⊗ₜ[R] ⟨y, hy⟩ rfl · use 0 simp only [map_zero] · rintro x y - - ⟨x, hx, rfl⟩ ⟨y, hy, rfl⟩ use x + y simp only [map_add] · rintro a x - ⟨x, hx, rfl⟩ induction a with | zero => use 0 simp only [map_zero, smul_eq_mul, zero_mul] | tmul a b => induction x with | zero => use 0 simp only [map_zero, smul_eq_mul, mul_zero] | tmul x y => use (a * x) ⊗ₜ[R] (b •y) simp only [LinearMap.lTensor_tmul, Submodule.coe_subtype, smul_eq_mul, tmul_mul_tmul] rfl | add x y hx hy => obtain ⟨x', hx'⟩ := hx obtain ⟨y', hy'⟩ := hy use x' + y' simp only [map_add, hx', smul_add, hy'] | add a b ha hb => obtain ⟨x', ha'⟩ := ha obtain ⟨y', hb'⟩ := hb use x' + y' simp only [map_add, ha', add_smul, hb'] · rintro x ⟨y, rfl⟩ induction y with | zero => rw [map_zero] apply zero_mem | tmul a b => simp only [LinearMap.lTensor_tmul, Submodule.coe_subtype] suffices a ⊗ₜ[R] (b : B) = (a ⊗ₜ[R] (1 : B)) * ((1 : A) ⊗ₜ[R] (b : B)) by rw [this] simp only [Submodule.coe_restrictScalars, SetLike.mem_coe] apply Ideal.mul_mem_left -- Note: adding `includeRight` as a hint fixes a timeout https://github.com/leanprover-community/mathlib4/pull/8386 apply Ideal.mem_map_of_mem includeRight exact Submodule.coe_mem b simp only [Algebra.TensorProduct.tmul_mul_tmul, mul_one, one_mul] | add x y hx hy => rw [map_add] apply Submodule.add_mem _ hx hy -- Now, we can prove the right exactness properties of the tensor product, -- in its versions for algebras variable {R : Type*} [CommRing R] {A B C D : Type*} [Ring A] [Ring B] [Ring C] [Ring D] [Algebra R A] [Algebra R B] [Algebra R C] [Algebra R D] (f : A →ₐ[R] B) (g : C →ₐ[R] D) /-- If `g` is surjective, then the kernel of `(id A) ⊗ g` is generated by the kernel of `g` -/ lemma Algebra.TensorProduct.lTensor_ker (hg : Function.Surjective g) : RingHom.ker (map (AlgHom.id R A) g) = (RingHom.ker g).map (Algebra.TensorProduct.includeRight : C →ₐ[R] A ⊗[R] C) := by rw [← Submodule.restrictScalars_inj R] have : (RingHom.ker (map (AlgHom.id R A) g)).restrictScalars R = LinearMap.ker (LinearMap.lTensor A (AlgHom.toLinearMap g)) := rfl rw [this, Ideal.map_includeRight_eq] rw [(lTensor_exact A g.toLinearMap.exact_subtype_ker_map hg).linearMap_ker_eq] rfl /-- If `f` is surjective, then the kernel of `f ⊗ (id B)` is generated by the kernel of `f` -/ lemma Algebra.TensorProduct.rTensor_ker (hf : Function.Surjective f) : RingHom.ker (map f (AlgHom.id R C)) = (RingHom.ker f).map (Algebra.TensorProduct.includeLeft : A →ₐ[R] A ⊗[R] C) := by rw [← Submodule.restrictScalars_inj R] have : (RingHom.ker (map f (AlgHom.id R C))).restrictScalars R = LinearMap.ker (LinearMap.rTensor C (AlgHom.toLinearMap f)) := rfl rw [this, Ideal.map_includeLeft_eq] rw [(rTensor_exact C f.toLinearMap.exact_subtype_ker_map hf).linearMap_ker_eq] rfl /-- If `f` and `g` are surjective morphisms of algebras, then the kernel of `Algebra.TensorProduct.map f g` is generated by the kernels of `f` and `g` -/ theorem Algebra.TensorProduct.map_ker (hf : Function.Surjective f) (hg : Function.Surjective g) : RingHom.ker (map f g) = (RingHom.ker f).map (Algebra.TensorProduct.includeLeft : A →ₐ[R] A ⊗[R] C) ⊔ (RingHom.ker g).map (Algebra.TensorProduct.includeRight : C →ₐ[R] A ⊗[R] C) := by -- rewrite map f g as the composition of two maps have : map f g = (map f (AlgHom.id R D)).comp (map (AlgHom.id R A) g) := ext rfl rfl rw [this] -- this needs some rewriting to RingHom -- TODO: can `RingHom.comap_ker` take an arbitrary `RingHomClass`, rather than just `RingHom`? simp only [AlgHom.ker_coe, AlgHom.comp_toRingHom] rw [← RingHom.comap_ker] simp only [← AlgHom.ker_coe] -- apply one step of exactness rw [← Algebra.TensorProduct.lTensor_ker _ hg, RingHom.ker_eq_comap_bot (map (AlgHom.id R A) g)] rw [← Ideal.comap_map_of_surjective (map (AlgHom.id R A) g) (LinearMap.lTensor_surjective A hg)] -- apply the other step of exactness rw [Algebra.TensorProduct.rTensor_ker _ hf] apply congr_arg₂ _ rfl simp only [AlgHom.coe_ideal_map, Ideal.map_map] rw [← AlgHom.comp_toRingHom, Algebra.TensorProduct.map_comp_includeLeft] rfl end Algebras
.lake/packages/mathlib/Mathlib/LinearAlgebra/TensorProduct/Submodule.lean
import Mathlib.Algebra.Algebra.Operations import Mathlib.Algebra.Algebra.Subalgebra.Lattice import Mathlib.LinearAlgebra.DirectSum.Finsupp /-! # Some results on tensor product of submodules ## Linear maps induced by multiplication for submodules Let `R` be a commutative ring, `S` be an `R`-algebra (not necessarily commutative). Let `M` and `N` be `R`-submodules in `S` (`Submodule R S`). We define some linear maps induced by the multiplication in `S` (see also `LinearMap.mul'`), which are mainly used in the definition of linearly disjointness (`Submodule.LinearDisjoint`). - `Submodule.mulMap`: the natural `R`-linear map `M ⊗[R] N →ₗ[R] S` induced by the multiplication in `S`, whose image is `M * N` (`Submodule.mulMap_range`). - `Submodule.mulMap'`: the natural map `M ⊗[R] N →ₗ[R] M * N` induced by multiplication in `S`, which is surjective (`Submodule.mulMap'_surjective`). - `Submodule.lTensorOne`, `Submodule.rTensorOne`: the natural isomorphism of `R`-modules between `i(R) ⊗[R] N` and `N`, resp. `M ⊗[R] i(R)` and `M`, induced by multiplication in `S`, here `i : R → S` is the structure map. They generalize `TensorProduct.lid` and `TensorProduct.rid`, as `i(R)` is not necessarily isomorphic to `R`. Note that we use `⊥ : Subalgebra R S` instead of `1 : Submodule R S`, since the map `R →ₗ[R] (1 : Submodule R S)` is not defined directly in mathlib yet. There are also `Submodule.mulLeftMap` and `Submodule.mulRightMap`, defined in earlier files. -/ open scoped TensorProduct noncomputable section universe u v w namespace Submodule variable {R : Type u} {S : Type v} section Semiring variable [CommSemiring R] [Semiring S] [Algebra R S] variable (M N : Submodule R S) -- can't use `LinearMap.mul' R S ∘ₗ TensorProduct.mapIncl M N` since it is not defeq to -- `Subalgebra.mulMap` which is `(Algebra.TensorProduct.productMap A.val B.val).toLinearMap` /-- If `M` and `N` are submodules in an algebra `S` over `R`, there is the natural `R`-linear map `M ⊗[R] N →ₗ[R] S` induced by multiplication in `S`. -/ def mulMap : M ⊗[R] N →ₗ[R] S := TensorProduct.lift ((LinearMap.mul R S).domRestrict₁₂ M N) @[simp] theorem mulMap_tmul (m : M) (n : N) : mulMap M N (m ⊗ₜ[R] n) = m.1 * n.1 := rfl theorem mulMap_map_comp_eq {T : Type w} [Semiring T] [Algebra R T] {F : Type*} [FunLike F S T] [AlgHomClass F R S T] (f : F) : mulMap (M.map f) (N.map f) ∘ₗ TensorProduct.map ((f : S →ₗ[R] T).submoduleMap M) ((f : S →ₗ[R] T).submoduleMap N) = f ∘ₗ mulMap M N := by ext simp only [TensorProduct.AlgebraTensorModule.curry_apply, LinearMap.restrictScalars_comp, TensorProduct.curry_apply, LinearMap.coe_comp, LinearMap.coe_restrictScalars, Function.comp_apply, TensorProduct.map_tmul, mulMap_tmul, LinearMap.coe_coe, map_mul] rfl theorem mulMap_op : mulMap (equivOpposite.symm (MulOpposite.op M)) (equivOpposite.symm (MulOpposite.op N)) = (MulOpposite.opLinearEquiv R).toLinearMap ∘ₗ mulMap N M ∘ₗ (TensorProduct.congr (LinearEquiv.ofSubmodule' (MulOpposite.opLinearEquiv R).symm M) (LinearEquiv.ofSubmodule' (MulOpposite.opLinearEquiv R).symm N) ≪≫ₗ TensorProduct.comm R M N).toLinearMap := TensorProduct.ext' fun _ _ ↦ rfl theorem mulMap_comm_of_commute (hc : ∀ (m : M) (n : N), Commute m.1 n.1) : mulMap N M = mulMap M N ∘ₗ TensorProduct.comm R N M := by refine TensorProduct.ext' fun n m ↦ ?_ simp_rw [LinearMap.comp_apply, LinearEquiv.coe_coe, TensorProduct.comm_tmul, mulMap_tmul] exact (hc m n).symm variable {M} in theorem mulMap_comp_rTensor {M' : Submodule R S} (hM : M' ≤ M) : mulMap M N ∘ₗ (inclusion hM).rTensor N = mulMap M' N := TensorProduct.ext' fun _ _ ↦ rfl variable {N} in theorem mulMap_comp_lTensor {N' : Submodule R S} (hN : N' ≤ N) : mulMap M N ∘ₗ (inclusion hN).lTensor M = mulMap M N' := TensorProduct.ext' fun _ _ ↦ rfl variable {M N} in theorem mulMap_comp_map_inclusion {M' N' : Submodule R S} (hM : M' ≤ M) (hN : N' ≤ N) : mulMap M N ∘ₗ TensorProduct.map (inclusion hM) (inclusion hN) = mulMap M' N' := TensorProduct.ext' fun _ _ ↦ rfl theorem mulMap_eq_mul'_comp_mapIncl : mulMap M N = .mul' R S ∘ₗ TensorProduct.mapIncl M N := TensorProduct.ext' fun _ _ ↦ rfl theorem mulMap_range : LinearMap.range (mulMap M N) = M * N := by refine le_antisymm ?_ (mul_le.2 fun m hm n hn ↦ ⟨⟨m, hm⟩ ⊗ₜ[R] ⟨n, hn⟩, rfl⟩) rintro _ ⟨x, rfl⟩ induction x with | zero => rw [map_zero]; exact zero_mem _ | tmul a b => exact mul_mem_mul a.2 b.2 | add a b ha hb => rw [map_add]; exact add_mem ha hb /-- If `M` and `N` are submodules in an algebra `S` over `R`, there is the natural `R`-linear map `M ⊗[R] N →ₗ[R] M * N` induced by multiplication in `S`, which is surjective (`Submodule.mulMap'_surjective`). -/ def mulMap' : M ⊗[R] N →ₗ[R] ↥(M * N) := (LinearEquiv.ofEq _ _ (mulMap_range M N)).toLinearMap ∘ₗ (mulMap M N).rangeRestrict variable {M N} in @[simp] theorem val_mulMap'_tmul (m : M) (n : N) : (mulMap' M N (m ⊗ₜ[R] n) : S) = m.1 * n.1 := rfl theorem mulMap'_surjective : Function.Surjective (mulMap' M N) := by simp_rw [mulMap', LinearMap.coe_comp, LinearEquiv.coe_coe, EquivLike.comp_surjective, LinearMap.surjective_rangeRestrict] /-- If `N` is a submodule in an algebra `S` over `R`, there is the natural `R`-linear map `i(R) ⊗[R] N →ₗ[R] N` induced by multiplication in `S`, here `i : R → S` is the structure map. This is promoted to an isomorphism of `R`-modules as `Submodule.lTensorOne`. Use that instead. -/ def lTensorOne' : (⊥ : Subalgebra R S) ⊗[R] N →ₗ[R] N := show Subalgebra.toSubmodule ⊥ ⊗[R] N →ₗ[R] N from (LinearEquiv.ofEq _ _ (by rw [Algebra.toSubmodule_bot, mulMap_range, one_mul])).toLinearMap ∘ₗ (mulMap _ N).rangeRestrict variable {N} in @[simp] theorem lTensorOne'_tmul (y : R) (n : N) : N.lTensorOne' (algebraMap R _ y ⊗ₜ[R] n) = y • n := Subtype.val_injective <| by simp_rw [lTensorOne', LinearMap.coe_comp, LinearEquiv.coe_coe, Function.comp_apply, LinearEquiv.coe_ofEq_apply, LinearMap.codRestrict_apply, SetLike.val_smul, Algebra.smul_def] exact mulMap_tmul _ N _ _ variable {N} in @[simp] theorem lTensorOne'_one_tmul (n : N) : N.lTensorOne' (1 ⊗ₜ[R] n) = n := by simpa using lTensorOne'_tmul 1 n /-- If `N` is a submodule in an algebra `S` over `R`, there is the natural isomorphism of `R`-modules between `i(R) ⊗[R] N` and `N` induced by multiplication in `S`, here `i : R → S` is the structure map. This generalizes `TensorProduct.lid` as `i(R)` is not necessarily isomorphic to `R`. -/ def lTensorOne : (⊥ : Subalgebra R S) ⊗[R] N ≃ₗ[R] N := LinearEquiv.ofLinear N.lTensorOne' (TensorProduct.mk R (⊥ : Subalgebra R S) N 1) (by ext; simp) <| TensorProduct.ext' fun r n ↦ by change 1 ⊗ₜ[R] lTensorOne' N _ = r ⊗ₜ[R] n obtain ⟨x, h⟩ := Algebra.mem_bot.1 r.2 replace h : algebraMap R _ x = r := Subtype.val_injective h rw [← h, lTensorOne'_tmul, ← TensorProduct.smul_tmul, Algebra.smul_def, mul_one] variable {N} in @[simp] theorem lTensorOne_tmul (y : R) (n : N) : N.lTensorOne (algebraMap R _ y ⊗ₜ[R] n) = y • n := N.lTensorOne'_tmul y n variable {N} in @[simp] theorem lTensorOne_one_tmul (n : N) : N.lTensorOne (1 ⊗ₜ[R] n) = n := N.lTensorOne'_one_tmul n variable {N} in @[simp] theorem lTensorOne_symm_apply (n : N) : N.lTensorOne.symm n = 1 ⊗ₜ[R] n := rfl theorem mulMap_one_left_eq : mulMap (Subalgebra.toSubmodule ⊥) N = N.subtype ∘ₗ N.lTensorOne.toLinearMap := TensorProduct.ext' fun _ _ ↦ rfl /-- If `M` is a submodule in an algebra `S` over `R`, there is the natural `R`-linear map `M ⊗[R] i(R) →ₗ[R] M` induced by multiplication in `S`, here `i : R → S` is the structure map. This is promoted to an isomorphism of `R`-modules as `Submodule.rTensorOne`. Use that instead. -/ def rTensorOne' : M ⊗[R] (⊥ : Subalgebra R S) →ₗ[R] M := show M ⊗[R] Subalgebra.toSubmodule ⊥ →ₗ[R] M from (LinearEquiv.ofEq _ _ (by rw [Algebra.toSubmodule_bot, mulMap_range, mul_one])).toLinearMap ∘ₗ (mulMap M _).rangeRestrict variable {M} in @[simp] theorem rTensorOne'_tmul (y : R) (m : M) : M.rTensorOne' (m ⊗ₜ[R] algebraMap R _ y) = y • m := Subtype.val_injective <| by simp_rw [rTensorOne', LinearMap.coe_comp, LinearEquiv.coe_coe, Function.comp_apply, LinearEquiv.coe_ofEq_apply, LinearMap.codRestrict_apply, SetLike.val_smul] rw [Algebra.smul_def, Algebra.commutes] exact mulMap_tmul M _ _ _ variable {M} in @[simp] theorem rTensorOne'_tmul_one (m : M) : M.rTensorOne' (m ⊗ₜ[R] 1) = m := by simpa using rTensorOne'_tmul 1 m /-- If `M` is a submodule in an algebra `S` over `R`, there is the natural isomorphism of `R`-modules between `M ⊗[R] i(R)` and `M` induced by multiplication in `S`, here `i : R → S` is the structure map. This generalizes `TensorProduct.rid` as `i(R)` is not necessarily isomorphic to `R`. -/ def rTensorOne : M ⊗[R] (⊥ : Subalgebra R S) ≃ₗ[R] M := LinearEquiv.ofLinear M.rTensorOne' ((TensorProduct.comm R _ _).toLinearMap ∘ₗ TensorProduct.mk R (⊥ : Subalgebra R S) M 1) (by ext; simp) <| TensorProduct.ext' fun n r ↦ by change rTensorOne' M _ ⊗ₜ[R] 1 = n ⊗ₜ[R] r obtain ⟨x, h⟩ := Algebra.mem_bot.1 r.2 replace h : algebraMap R _ x = r := Subtype.val_injective h rw [← h, rTensorOne'_tmul, TensorProduct.smul_tmul, Algebra.smul_def, mul_one] variable {M} in @[simp] theorem rTensorOne_tmul (y : R) (m : M) : M.rTensorOne (m ⊗ₜ[R] algebraMap R _ y) = y • m := M.rTensorOne'_tmul y m variable {M} in @[simp] theorem rTensorOne_tmul_one (m : M) : M.rTensorOne (m ⊗ₜ[R] 1) = m := M.rTensorOne'_tmul_one m variable {M} in @[simp] theorem rTensorOne_symm_apply (m : M) : M.rTensorOne.symm m = m ⊗ₜ[R] 1 := rfl theorem mulMap_one_right_eq : mulMap M (Subalgebra.toSubmodule ⊥) = M.subtype ∘ₗ M.rTensorOne.toLinearMap := TensorProduct.ext' fun _ _ ↦ rfl @[simp] theorem comm_trans_lTensorOne : (TensorProduct.comm R _ _).trans M.lTensorOne = M.rTensorOne := by refine LinearEquiv.toLinearMap_injective <| TensorProduct.ext' fun m r ↦ ?_ obtain ⟨x, h⟩ := Algebra.mem_bot.1 r.2 replace h : algebraMap R _ x = r := Subtype.val_injective h rw [← h]; simp @[simp] theorem comm_trans_rTensorOne : (TensorProduct.comm R _ _).trans M.rTensorOne = M.lTensorOne := by refine LinearEquiv.toLinearMap_injective <| TensorProduct.ext' fun r m ↦ ?_ obtain ⟨x, h⟩ := Algebra.mem_bot.1 r.2 replace h : algebraMap R _ x = r := Subtype.val_injective h rw [← h]; simp variable {M} in theorem mulLeftMap_eq_mulMap_comp {ι : Type*} [DecidableEq ι] (m : ι → M) : mulLeftMap N m = mulMap M N ∘ₗ LinearMap.rTensor N (Finsupp.linearCombination R m) ∘ₗ (TensorProduct.finsuppScalarLeft R N ι).symm.toLinearMap := by ext; simp variable {N} in theorem mulRightMap_eq_mulMap_comp {ι : Type*} [DecidableEq ι] (n : ι → N) : mulRightMap M n = mulMap M N ∘ₗ LinearMap.lTensor M (Finsupp.linearCombination R n) ∘ₗ (TensorProduct.finsuppScalarRight R M ι).symm.toLinearMap := by ext; simp end Semiring section CommSemiring variable [CommSemiring R] [CommSemiring S] [Algebra R S] variable (M N : Submodule R S) theorem mulMap_comm : mulMap N M = (mulMap M N).comp (TensorProduct.comm R N M).toLinearMap := mulMap_comm_of_commute M N fun _ _ ↦ mul_comm _ _ end CommSemiring end Submodule
.lake/packages/mathlib/Mathlib/LinearAlgebra/TensorProduct/Associator.lean
import Mathlib.Algebra.Algebra.Hom import Mathlib.LinearAlgebra.TensorProduct.Basic /-! # Associators and unitors for tensor products of modules over a commutative ring. -/ variable {R : Type*} [CommSemiring R] variable {R' : Type*} [Monoid R'] variable {R'' : Type*} [Semiring R''] variable {A M N P Q S T : Type*} variable [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] variable [AddCommMonoid Q] [AddCommMonoid S] [AddCommMonoid T] variable [Module R M] [Module R N] [Module R Q] [Module R S] [Module R T] variable [DistribMulAction R' M] variable [Module R'' M] variable (M N) namespace TensorProduct variable [Module R P] variable {M N} section variable (R M) /-- The base ring is a left identity for the tensor product of modules, up to linear equivalence. -/ protected def lid : R ⊗[R] M ≃ₗ[R] M := LinearEquiv.ofLinear (lift <| LinearMap.lsmul R M) (mk R R M 1) (LinearMap.ext fun _ => by simp) (ext' fun r m => by simp [← tmul_smul, ← smul_tmul, smul_eq_mul, mul_one]) end @[simp] theorem lid_tmul (m : M) (r : R) : (TensorProduct.lid R M : R ⊗ M → M) (r ⊗ₜ m) = r • m := rfl @[simp] theorem lid_symm_apply (m : M) : (TensorProduct.lid R M).symm m = 1 ⊗ₜ m := rfl lemma includeRight_lid {S : Type*} [Semiring S] [Algebra R S] (m : R ⊗[R] M) : (1 : S) ⊗ₜ[R] (TensorProduct.lid R M) m = (LinearMap.rTensor M (Algebra.algHom R R S).toLinearMap) m := by suffices ∀ m, (LinearMap.rTensor M (Algebra.algHom R R S).toLinearMap).comp (TensorProduct.lid R M).symm.toLinearMap m = 1 ⊗ₜ[R] m by simp [← this] intros; simp section variable (R M) /-- The base ring is a right identity for the tensor product of modules, up to linear equivalence. -/ protected def rid : M ⊗[R] R ≃ₗ[R] M := LinearEquiv.ofLinear (lift <| .flip (LinearMap.lsmul R M)) (mk R M R |>.flip 1) (LinearMap.ext <| one_smul _) (ext <| by ext; simp) end @[simp] theorem rid_tmul (m : M) (r : R) : (TensorProduct.rid R M) (m ⊗ₜ r) = r • m := rfl @[simp] theorem rid_symm_apply (m : M) : (TensorProduct.rid R M).symm m = m ⊗ₜ 1 := rfl @[simp] theorem comm_trans_lid : TensorProduct.comm R M R ≪≫ₗ TensorProduct.lid R M = TensorProduct.rid R M := LinearEquiv.toLinearMap_injective (ext (by ext; rfl)) @[simp] theorem comm_trans_rid : TensorProduct.comm R R M ≪≫ₗ TensorProduct.rid R M = TensorProduct.lid R M := LinearEquiv.toLinearMap_injective (ext (by ext; rfl)) variable (R) in theorem lid_eq_rid : TensorProduct.lid R R = TensorProduct.rid R R := LinearEquiv.toLinearMap_injective <| ext' mul_comm section CompatibleSMul variable (R A M N) [CommSemiring A] [Module A M] [Module A N] [CompatibleSMul R A M N] [Module R A] [SMulCommClass R A A] [CompatibleSMul R A A M] [CompatibleSMul A R A M] /-- If the R- and A- action on A and M satisfy `CompatibleSMul` both ways, then `A ⊗[R] M` is canonically isomorphic to `M`. -/ def lidOfCompatibleSMul : A ⊗[R] M ≃ₗ[A] M := (equivOfCompatibleSMul R A A M).symm ≪≫ₗ TensorProduct.lid _ _ theorem lidOfCompatibleSMul_tmul (a m) : lidOfCompatibleSMul R A M (a ⊗ₜ[R] m) = a • m := rfl end CompatibleSMul open LinearMap section variable (R M N P) attribute [local ext high] ext in /-- The associator for tensor product of R-modules, as a linear equivalence. -/ protected def assoc : M ⊗[R] N ⊗[R] P ≃ₗ[R] M ⊗[R] (N ⊗[R] P) := LinearEquiv.ofLinear (lift <| lift <| lcurry _ _ _ _ ∘ₗ mk _ _ _) (lift <| uncurry _ _ _ _ ∘ₗ curry (mk R _ _)) (by ext; rfl) (by ext; rfl) end @[simp] theorem assoc_tmul (m : M) (n : N) (p : P) : (TensorProduct.assoc R M N P) (m ⊗ₜ n ⊗ₜ p) = m ⊗ₜ (n ⊗ₜ p) := rfl @[simp] theorem assoc_symm_tmul (m : M) (n : N) (p : P) : (TensorProduct.assoc R M N P).symm (m ⊗ₜ (n ⊗ₜ p)) = m ⊗ₜ n ⊗ₜ p := rfl /-- Given linear maps `f : M → Q`, `g : N → S`, and `h : P → T`, if we identify `(M ⊗ N) ⊗ P` with `M ⊗ (N ⊗ P)` and `(Q ⊗ S) ⊗ T` with `Q ⊗ (S ⊗ T)`, then this lemma states that `f ⊗ (g ⊗ h) = (f ⊗ g) ⊗ h`. -/ lemma map_map_comp_assoc_eq (f : M →ₗ[R] Q) (g : N →ₗ[R] S) (h : P →ₗ[R] T) : map f (map g h) ∘ₗ TensorProduct.assoc R M N P = TensorProduct.assoc R Q S T ∘ₗ map (map f g) h := ext <| ext <| LinearMap.ext fun _ => LinearMap.ext fun _ => LinearMap.ext fun _ => rfl lemma map_map_assoc (f : M →ₗ[R] Q) (g : N →ₗ[R] S) (h : P →ₗ[R] T) (x : M ⊗[R] N ⊗[R] P) : map f (map g h) (TensorProduct.assoc R M N P x) = TensorProduct.assoc R Q S T (map (map f g) h x) := DFunLike.congr_fun (map_map_comp_assoc_eq _ _ _) _ /-- Given linear maps `f : M → Q`, `g : N → S`, and `h : P → T`, if we identify `M ⊗ (N ⊗ P)` with `(M ⊗ N) ⊗ P` and `Q ⊗ (S ⊗ T)` with `(Q ⊗ S) ⊗ T`, then this lemma states that `(f ⊗ g) ⊗ h = f ⊗ (g ⊗ h)`. -/ lemma map_map_comp_assoc_symm_eq (f : M →ₗ[R] Q) (g : N →ₗ[R] S) (h : P →ₗ[R] T) : map (map f g) h ∘ₗ (TensorProduct.assoc R M N P).symm = (TensorProduct.assoc R Q S T).symm ∘ₗ map f (map g h) := ext <| LinearMap.ext fun _ => ext <| LinearMap.ext fun _ => LinearMap.ext fun _ => rfl lemma map_map_assoc_symm (f : M →ₗ[R] Q) (g : N →ₗ[R] S) (h : P →ₗ[R] T) (x : M ⊗[R] (N ⊗[R] P)) : map (map f g) h ((TensorProduct.assoc R M N P).symm x) = (TensorProduct.assoc R Q S T).symm (map f (map g h) x) := DFunLike.congr_fun (map_map_comp_assoc_symm_eq _ _ _) _ lemma assoc_tensor : TensorProduct.assoc R (M ⊗[R] N) Q S = .rTensor S (TensorProduct.assoc R M N Q) ≪≫ₗ TensorProduct.assoc R M (N ⊗[R] Q) S ≪≫ₗ .lTensor M (TensorProduct.assoc R N Q S) ≪≫ₗ (TensorProduct.assoc R M N (Q ⊗[R] S)).symm := LinearEquiv.toLinearMap_inj.mp <| ext_fourfold fun _ _ _ => congrFun rfl lemma assoc_tensor' : TensorProduct.assoc R M (N ⊗[R] Q) S = .rTensor S (TensorProduct.assoc R M N Q).symm ≪≫ₗ (TensorProduct.assoc R (M ⊗[R] N) Q S) ≪≫ₗ TensorProduct.assoc R M N (Q ⊗[R] S) ≪≫ₗ .lTensor M (TensorProduct.assoc R N Q S).symm := LinearEquiv.toLinearMap_inj.mp <| ext_fourfold'' fun _ _ _ => congrFun rfl lemma assoc_tensor'' : TensorProduct.assoc R M N (Q ⊗[R] S) = (TensorProduct.assoc R (M ⊗[R] N) Q S).symm ≪≫ₗ .rTensor S (TensorProduct.assoc R M N Q) ≪≫ₗ TensorProduct.assoc R M (N ⊗[R] Q) S ≪≫ₗ .lTensor M (TensorProduct.assoc R N Q S) := LinearEquiv.toLinearMap_inj.mp <| ext_fourfold' fun _ _ _ => congrFun rfl lemma lid_tensor : TensorProduct.lid R (M ⊗[R] N) = (TensorProduct.assoc R R M N).symm ≪≫ₗ .rTensor N (TensorProduct.lid R M) := LinearEquiv.toLinearMap_inj.mp <| ext_threefold' fun _ _ => congrFun rfl section variable {P' Q' : Type*} variable [AddCommMonoid P'] [Module R P'] variable [AddCommMonoid Q'] [Module R Q'] variable (R M N P Q) /-- A tensor product analogue of `mul_left_comm`. -/ def leftComm : M ⊗[R] (N ⊗[R] P) ≃ₗ[R] N ⊗[R] (M ⊗[R] P) := let e₁ := (TensorProduct.assoc R M N P).symm let e₂ := congr (TensorProduct.comm R M N) (1 : P ≃ₗ[R] P) let e₃ := TensorProduct.assoc R N M P e₁ ≪≫ₗ (e₂ ≪≫ₗ e₃) variable {M N P Q} @[simp] theorem leftComm_tmul (m : M) (n : N) (p : P) : leftComm R M N P (m ⊗ₜ (n ⊗ₜ p)) = n ⊗ₜ (m ⊗ₜ p) := rfl @[simp] theorem leftComm_symm_tmul (m : M) (n : N) (p : P) : (leftComm R M N P).symm (n ⊗ₜ (m ⊗ₜ p)) = m ⊗ₜ (n ⊗ₜ p) := rfl variable (M N P) in attribute [local ext high] ext in /-- A tensor product analogue of `mul_right_comm`. -/ def rightComm : M ⊗[R] N ⊗[R] P ≃ₗ[R] M ⊗[R] P ⊗[R] N := LinearEquiv.ofLinear (lift (lift (LinearMap.lflip.toLinearMap ∘ₗ (mk _ _ _).compr₂ (mk _ _ _)))) (lift (lift (LinearMap.lflip.toLinearMap ∘ₗ (mk _ _ _).compr₂ (mk _ _ _)))) (by ext; rfl) (by ext; rfl) @[simp] theorem rightComm_tmul (m : M) (n : N) (p : P) : rightComm R M N P ((m ⊗ₜ n) ⊗ₜ p) = (m ⊗ₜ p) ⊗ₜ n := rfl @[simp] theorem rightComm_symm : (rightComm R M N P).symm = rightComm R M P N := rfl variable (M N P Q) /-- This special case is worth defining explicitly since it is useful for defining multiplication on tensor products of modules carrying multiplications (e.g., associative rings, Lie rings, ...). E.g., suppose `M = P` and `N = Q` and that `M` and `N` carry bilinear multiplications: `M ⊗ M → M` and `N ⊗ N → N`. Using `map`, we can define `(M ⊗ M) ⊗ (N ⊗ N) → M ⊗ N` which, when combined with this definition, yields a bilinear multiplication on `M ⊗ N`: `(M ⊗ N) ⊗ (M ⊗ N) → M ⊗ N`. In particular we could use this to define the multiplication in the `TensorProduct.semiring` instance (currently defined "by hand" using `TensorProduct.mul`). See also `mul_mul_mul_comm`. -/ def tensorTensorTensorComm : M ⊗[R] N ⊗[R] (P ⊗[R] Q) ≃ₗ[R] M ⊗[R] P ⊗[R] (N ⊗[R] Q) := (TensorProduct.assoc R (M ⊗[R] N) P Q).symm ≪≫ₗ congr (TensorProduct.rightComm R M N P) (.refl R Q) ≪≫ₗ TensorProduct.assoc R (M ⊗[R] P) N Q variable {M N P Q} @[simp] theorem tensorTensorTensorComm_tmul (m : M) (n : N) (p : P) (q : Q) : tensorTensorTensorComm R M N P Q (m ⊗ₜ n ⊗ₜ (p ⊗ₜ q)) = m ⊗ₜ p ⊗ₜ (n ⊗ₜ q) := rfl @[simp] theorem tensorTensorTensorComm_symm : (tensorTensorTensorComm R M N P Q).symm = tensorTensorTensorComm R M P N Q := rfl @[simp] theorem tensorTensorTensorComm_trans_tensorTensorTensorComm : tensorTensorTensorComm R M N P Q ≪≫ₗ tensorTensorTensorComm R M P N Q = .refl R _ := by rw [← tensorTensorTensorComm_symm] exact LinearEquiv.symm_trans_self _ theorem tensorTensorTensorComm_comp_map {V W : Type*} [AddCommMonoid V] [AddCommMonoid W] [Module R V] [Module R W] (f : M →ₗ[R] S) (g : N →ₗ[R] T) (h : P →ₗ[R] V) (j : Q →ₗ[R] W) : tensorTensorTensorComm R S T V W ∘ₗ map (map f g) (map h j) = map (map f h) (map g j) ∘ₗ tensorTensorTensorComm R M N P Q := ext_fourfold' fun _ _ _ _ => rfl variable (M N P Q) /-- This special case is useful for describing the interplay between `dualTensorHomEquiv` and composition of linear maps. E.g., composition of linear maps gives a map `(M → N) ⊗ (N → P) → (M → P)`, and applying `dual_tensor_hom_equiv.symm` to the three hom-modules gives a map `(M.dual ⊗ N) ⊗ (N.dual ⊗ P) → (M.dual ⊗ P)`, which agrees with the application of `contractRight` on `N ⊗ N.dual` after the suitable rebracketing. -/ def tensorTensorTensorAssoc : M ⊗[R] N ⊗[R] (P ⊗[R] Q) ≃ₗ[R] M ⊗[R] (N ⊗[R] P) ⊗[R] Q := (TensorProduct.assoc R (M ⊗[R] N) P Q).symm ≪≫ₗ congr (TensorProduct.assoc R M N P) (1 : Q ≃ₗ[R] Q) variable {M N P Q} @[simp] theorem tensorTensorTensorAssoc_tmul (m : M) (n : N) (p : P) (q : Q) : tensorTensorTensorAssoc R M N P Q (m ⊗ₜ n ⊗ₜ (p ⊗ₜ q)) = m ⊗ₜ (n ⊗ₜ p) ⊗ₜ q := rfl @[simp] theorem tensorTensorTensorAssoc_symm_tmul (m : M) (n : N) (p : P) (q : Q) : (tensorTensorTensorAssoc R M N P Q).symm (m ⊗ₜ (n ⊗ₜ p) ⊗ₜ q) = m ⊗ₜ n ⊗ₜ (p ⊗ₜ q) := rfl end end TensorProduct open scoped TensorProduct variable [Module R P] namespace LinearMap variable {N} variable (g : P →ₗ[R] Q) (f : N →ₗ[R] P) open TensorProduct (assoc lid rid) lemma lTensor_tensor (f : P →ₗ[R] Q) : lTensor (M ⊗[R] N) f = (assoc R M N Q).symm ∘ₗ (f.lTensor N).lTensor M ∘ₗ assoc R M N P := TensorProduct.ext <| TensorProduct.ext rfl theorem rTensor_tensor : rTensor (M ⊗[R] N) g = assoc R Q M N ∘ₗ rTensor N (rTensor M g) ∘ₗ (assoc R P M N).symm := TensorProduct.ext <| LinearMap.ext fun _ ↦ TensorProduct.ext rfl open TensorProduct theorem lid_comp_rTensor (f : N →ₗ[R] R) : (lid R M).comp (rTensor M f) = lift ((lsmul R M).comp f) := ext' fun _ _ ↦ rfl lemma rid_comp_lTensor (f : M →ₗ[R] R) : (rid R N).comp (lTensor N f) = lift ((lsmul R N).flip.compl₂ f) := ext' fun _ _ ↦ rfl lemma lTensor_rTensor_comp_assoc (x : M →ₗ[R] N) : lTensor P (rTensor Q x) ∘ₗ TensorProduct.assoc R P M Q = TensorProduct.assoc R P N Q ∘ₗ rTensor Q (lTensor P x) := by simp_rw [rTensor, lTensor, map_map_comp_assoc_eq] lemma rTensor_lTensor_comp_assoc_symm (x : M →ₗ[R] N) : rTensor Q (lTensor P x) ∘ₗ (TensorProduct.assoc R P M Q).symm = (TensorProduct.assoc R P N Q).symm ∘ₗ lTensor P (rTensor Q x) := by simp_rw [rTensor, lTensor, map_map_comp_assoc_symm_eq] end LinearMap
.lake/packages/mathlib/Mathlib/LinearAlgebra/TensorProduct/Basis.lean
import Mathlib.LinearAlgebra.Basis.Basic import Mathlib.LinearAlgebra.DirectSum.Finsupp import Mathlib.LinearAlgebra.Finsupp.VectorSpace import Mathlib.LinearAlgebra.FreeModule.Basic /-! # Bases and dimensionality of tensor products of modules This file defines various bases on the tensor product of modules, and shows that the tensor product of free modules is again free. -/ noncomputable section open LinearMap Module Set Submodule open scoped TensorProduct section CommSemiring variable {R : Type*} {S : Type*} {M : Type*} {N : Type*} {ι : Type*} {κ : Type*} [CommSemiring R] [Semiring S] [Algebra R S] [AddCommMonoid M] [Module R M] [Module S M] [IsScalarTower R S M] [AddCommMonoid N] [Module R N] namespace Module.Basis /-- If `b : ι → M` and `c : κ → N` are bases then so is `fun i ↦ b i.1 ⊗ₜ c i.2 : ι × κ → M ⊗ N`. -/ def tensorProduct (b : Basis ι S M) (c : Basis κ R N) : Basis (ι × κ) S (M ⊗[R] N) := Finsupp.basisSingleOne.map ((TensorProduct.AlgebraTensorModule.congr b.repr c.repr).trans <| (finsuppTensorFinsupp R S _ _ _ _).trans <| Finsupp.lcongr (Equiv.refl _) (TensorProduct.AlgebraTensorModule.rid R S S)).symm @[simp] theorem tensorProduct_apply (b : Basis ι S M) (c : Basis κ R N) (i : ι) (j : κ) : tensorProduct b c (i, j) = b i ⊗ₜ c j := by simp [tensorProduct] theorem tensorProduct_apply' (b : Basis ι S M) (c : Basis κ R N) (i : ι × κ) : tensorProduct b c i = b i.1 ⊗ₜ c i.2 := by simp [tensorProduct] @[simp] theorem tensorProduct_repr_tmul_apply (b : Basis ι S M) (c : Basis κ R N) (m : M) (n : N) (i : ι) (j : κ) : (tensorProduct b c).repr (m ⊗ₜ n) (i, j) = c.repr n j • b.repr m i := by simp [tensorProduct] variable (S : Type*) [Semiring S] [Algebra R S] /-- The lift of an `R`-basis of `M` to an `S`-basis of the base change `S ⊗[R] M`. -/ noncomputable def baseChange (b : Basis ι R M) : Basis ι S (S ⊗[R] M) := (tensorProduct (.singleton Unit S) b).reindex (Equiv.punitProd ι) @[simp] lemma baseChange_repr_tmul (b : Basis ι R M) (x y i) : (b.baseChange S).repr (x ⊗ₜ y) i = b.repr y i • x := by simp [baseChange, tensorProduct] @[simp] lemma baseChange_apply (b : Basis ι R M) (i) : b.baseChange S i = 1 ⊗ₜ b i := by simp [baseChange, tensorProduct] end Module.Basis section variable [DecidableEq ι] [DecidableEq κ] variable (ℬ : Basis ι R M) (𝒞 : Basis κ R N) (x : M ⊗[R] N) /-- If `{𝒞ᵢ}` is a basis for the module `N`, then every elements of `x ∈ M ⊗ N` can be uniquely written as `∑ᵢ mᵢ ⊗ 𝒞ᵢ` for some `mᵢ ∈ M`. -/ def TensorProduct.equivFinsuppOfBasisRight : M ⊗[R] N ≃ₗ[R] κ →₀ M := LinearEquiv.lTensor M 𝒞.repr ≪≫ₗ TensorProduct.finsuppScalarRight R M κ @[simp] lemma TensorProduct.equivFinsuppOfBasisRight_apply_tmul (m : M) (n : N) : (TensorProduct.equivFinsuppOfBasisRight 𝒞) (m ⊗ₜ n) = (𝒞.repr n).mapRange (· • m) (zero_smul _ _) := by ext; simp [equivFinsuppOfBasisRight] lemma TensorProduct.equivFinsuppOfBasisRight_apply_tmul_apply (m : M) (n : N) (i : κ) : (TensorProduct.equivFinsuppOfBasisRight 𝒞) (m ⊗ₜ n) i = 𝒞.repr n i • m := by simp only [equivFinsuppOfBasisRight_apply_tmul, Finsupp.mapRange_apply] lemma TensorProduct.equivFinsuppOfBasisRight_symm : (TensorProduct.equivFinsuppOfBasisRight 𝒞).symm.toLinearMap = Finsupp.lsum R fun i ↦ (TensorProduct.mk R M N).flip (𝒞 i) := by ext; simp [equivFinsuppOfBasisRight] @[simp] lemma TensorProduct.equivFinsuppOfBasisRight_symm_apply (b : κ →₀ M) : (TensorProduct.equivFinsuppOfBasisRight 𝒞).symm b = b.sum fun i m ↦ m ⊗ₜ 𝒞 i := congr($(TensorProduct.equivFinsuppOfBasisRight_symm 𝒞) b) omit [DecidableEq κ] in lemma TensorProduct.sum_tmul_basis_right_injective : Function.Injective (Finsupp.lsum R fun i ↦ (TensorProduct.mk R M N).flip (𝒞 i)) := have := Classical.decEq κ (equivFinsuppOfBasisRight_symm (M := M) 𝒞).symm ▸ (TensorProduct.equivFinsuppOfBasisRight 𝒞).symm.injective omit [DecidableEq κ] in lemma TensorProduct.sum_tmul_basis_right_eq_zero (b : κ →₀ M) (h : (b.sum fun i m ↦ m ⊗ₜ[R] 𝒞 i) = 0) : b = 0 := have := Classical.decEq κ (TensorProduct.equivFinsuppOfBasisRight 𝒞).symm.injective (a₂ := 0) <| by simpa /-- If `{ℬᵢ}` is a basis for the module `M`, then every elements of `x ∈ M ⊗ N` can be uniquely written as `∑ᵢ ℬᵢ ⊗ nᵢ` for some `nᵢ ∈ N`. -/ def TensorProduct.equivFinsuppOfBasisLeft : M ⊗[R] N ≃ₗ[R] ι →₀ N := TensorProduct.comm R M N ≪≫ₗ TensorProduct.equivFinsuppOfBasisRight ℬ @[simp] lemma TensorProduct.equivFinsuppOfBasisLeft_apply_tmul (m : M) (n : N) : (TensorProduct.equivFinsuppOfBasisLeft ℬ) (m ⊗ₜ n) = (ℬ.repr m).mapRange (· • n) (zero_smul _ _) := by simp [equivFinsuppOfBasisLeft] lemma TensorProduct.equivFinsuppOfBasisLeft_apply_tmul_apply (m : M) (n : N) (i : ι) : (TensorProduct.equivFinsuppOfBasisLeft ℬ) (m ⊗ₜ n) i = ℬ.repr m i • n := by simp only [equivFinsuppOfBasisLeft_apply_tmul, Finsupp.mapRange_apply] lemma TensorProduct.equivFinsuppOfBasisLeft_symm : (TensorProduct.equivFinsuppOfBasisLeft ℬ).symm.toLinearMap = Finsupp.lsum R fun i ↦ (TensorProduct.mk R M N) (ℬ i) := by ext; simp [equivFinsuppOfBasisLeft] @[simp] lemma TensorProduct.equivFinsuppOfBasisLeft_symm_apply (b : ι →₀ N) : (TensorProduct.equivFinsuppOfBasisLeft ℬ).symm b = b.sum fun i n ↦ ℬ i ⊗ₜ n := congr($(TensorProduct.equivFinsuppOfBasisLeft_symm ℬ) b) omit [DecidableEq κ] in /-- Elements in `M ⊗ N` can be represented by sum of elements in `M` tensor elements of basis of `N`. -/ lemma TensorProduct.eq_repr_basis_right : ∃ b : κ →₀ M, b.sum (fun i m ↦ m ⊗ₜ 𝒞 i) = x := by classical simpa using (TensorProduct.equivFinsuppOfBasisRight 𝒞).symm.surjective x omit [DecidableEq ι] in /-- Elements in `M ⊗ N` can be represented by sum of elements of basis of `M` tensor elements of `N`. -/ lemma TensorProduct.eq_repr_basis_left : ∃ (c : ι →₀ N), (c.sum fun i n ↦ ℬ i ⊗ₜ n) = x := by classical obtain ⟨c, rfl⟩ := (TensorProduct.equivFinsuppOfBasisLeft ℬ).symm.surjective x exact ⟨c, (TensorProduct.comm R M N).injective <| by simp [Finsupp.sum]⟩ omit [DecidableEq ι] in lemma TensorProduct.sum_tmul_basis_left_injective : Function.Injective (Finsupp.lsum R fun i ↦ (TensorProduct.mk R M N) (ℬ i)) := have := Classical.decEq ι (equivFinsuppOfBasisLeft_symm (N := N) ℬ).symm ▸ (TensorProduct.equivFinsuppOfBasisLeft ℬ).symm.injective omit [DecidableEq ι] in lemma TensorProduct.sum_tmul_basis_left_eq_zero (b : ι →₀ N) (h : (b.sum fun i n ↦ ℬ i ⊗ₜ[R] n) = 0) : b = 0 := have := Classical.decEq ι (TensorProduct.equivFinsuppOfBasisLeft ℬ).symm.injective (a₂ := 0) <| by simpa end variable [CommSemiring R] [Semiring S] [Algebra R S] [AddCommMonoid M] [Module R M] [Module S M] [IsScalarTower R S M] [Module.Free S M] [AddCommMonoid N] [Module R N] [Module.Free R N] instance Module.Free.tensor : Module.Free S (M ⊗[R] N) := let ⟨bM⟩ := exists_basis (R := S) (M := M) let ⟨bN⟩ := exists_basis (R := R) (M := N) of_basis (bM.2.tensorProduct bN.2) end CommSemiring end
.lake/packages/mathlib/Mathlib/LinearAlgebra/TensorProduct/Finiteness.lean
import Mathlib.LinearAlgebra.DFinsupp import Mathlib.RingTheory.Finiteness.Basic import Mathlib.LinearAlgebra.TensorProduct.Basic /-! # Some finiteness results of tensor product This file contains some finiteness results of tensor product. - `TensorProduct.exists_multiset`, `TensorProduct.exists_finsupp_left`, `TensorProduct.exists_finsupp_right`, `TensorProduct.exists_finset`: any element of `M ⊗[R] N` can be written as a finite sum of pure tensors. See also `TensorProduct.span_tmul_eq_top`. - `TensorProduct.exists_finite_submodule_left_of_setFinite`, `TensorProduct.exists_finite_submodule_right_of_setFinite`, `TensorProduct.exists_finite_submodule_of_setFinite`: any finite subset of `M ⊗[R] N` is contained in `M' ⊗[R] N`, resp. `M ⊗[R] N'`, resp. `M' ⊗[R] N'`, for some finitely generated submodules `M'` and `N'` of `M` and `N`, respectively. - `TensorProduct.exists_finite_submodule_left_of_setFinite'`, `TensorProduct.exists_finite_submodule_right_of_setFinite'`, `TensorProduct.exists_finite_submodule_of_setFinite'`: variation of the above results where `M` and `N` are already submodules. ## Tags tensor product, finitely generated -/ open scoped TensorProduct open Submodule variable {R M N : Type*} variable [CommSemiring R] [AddCommMonoid M] [AddCommMonoid N] [Module R M] [Module R N] variable {M₁ M₂ : Submodule R M} {N₁ N₂ : Submodule R N} namespace TensorProduct /-- For any element `x` of `M ⊗[R] N`, there exists a (finite) multiset `{ (m_i, n_i) }` of `M × N`, such that `x` is equal to the sum of `m_i ⊗ₜ[R] n_i`. -/ theorem exists_multiset (x : M ⊗[R] N) : ∃ S : Multiset (M × N), x = (S.map fun i ↦ i.1 ⊗ₜ[R] i.2).sum := by induction x with | zero => exact ⟨0, by simp⟩ | tmul x y => exact ⟨{(x, y)}, by simp⟩ | add x y hx hy => obtain ⟨Sx, hx⟩ := hx obtain ⟨Sy, hy⟩ := hy exact ⟨Sx + Sy, by rw [Multiset.map_add, Multiset.sum_add, hx, hy]⟩ /-- For any element `x` of `M ⊗[R] N`, there exists a finite subset `{ (m_i, n_i) }` of `M × N` such that each `m_i` is distinct (we represent it as an element of `M →₀ N`), such that `x` is equal to the sum of `m_i ⊗ₜ[R] n_i`. -/ theorem exists_finsupp_left (x : M ⊗[R] N) : ∃ S : M →₀ N, x = S.sum fun m n ↦ m ⊗ₜ[R] n := by induction x with | zero => exact ⟨0, by simp⟩ | tmul x y => exact ⟨Finsupp.single x y, by simp⟩ | add x y hx hy => obtain ⟨Sx, hx⟩ := hx obtain ⟨Sy, hy⟩ := hy use Sx + Sy rw [hx, hy] exact (Finsupp.sum_add_index' (by simp) TensorProduct.tmul_add).symm /-- For any element `x` of `M ⊗[R] N`, there exists a finite subset `{ (m_i, n_i) }` of `M × N` such that each `n_i` is distinct (we represent it as an element of `N →₀ M`), such that `x` is equal to the sum of `m_i ⊗ₜ[R] n_i`. -/ theorem exists_finsupp_right (x : M ⊗[R] N) : ∃ S : N →₀ M, x = S.sum fun n m ↦ m ⊗ₜ[R] n := by obtain ⟨S, h⟩ := exists_finsupp_left (TensorProduct.comm R M N x) refine ⟨S, (TensorProduct.comm R M N).injective ?_⟩ simp_rw [h, Finsupp.sum, map_sum, comm_tmul] /-- For any element `x` of `M ⊗[R] N`, there exists a finite subset `{ (m_i, n_i) }` of `M × N`, such that `x` is equal to the sum of `m_i ⊗ₜ[R] n_i`. -/ theorem exists_finset (x : M ⊗[R] N) : ∃ S : Finset (M × N), x = S.sum fun i ↦ i.1 ⊗ₜ[R] i.2 := by obtain ⟨S, h⟩ := exists_finsupp_left x use S.graph rw [h, Finsupp.sum] apply Finset.sum_nbij' (fun m ↦ ⟨m, S m⟩) Prod.fst <;> simp /-- For a finite subset `s` of `M ⊗[R] N`, there are finitely generated submodules `M'` and `N'` of `M` and `N`, respectively, such that `s` is contained in the image of `M' ⊗[R] N'` in `M ⊗[R] N`. In particular, every element of a tensor product lies in the tensor product of some finite submodules. -/ theorem exists_finite_submodule_of_setFinite (s : Set (M ⊗[R] N)) (hs : s.Finite) : ∃ (M' : Submodule R M) (N' : Submodule R N), Module.Finite R M' ∧ Module.Finite R N' ∧ s ⊆ LinearMap.range (mapIncl M' N') := by simp_rw [Module.Finite.iff_fg] induction s, hs using Set.Finite.induction_on with | empty => exact ⟨_, _, fg_bot, fg_bot, Set.empty_subset _⟩ | @insert a s _ _ ih => obtain ⟨M', N', hM', hN', h⟩ := ih refine TensorProduct.induction_on a ?_ (fun x y ↦ ?_) fun x y hx hy ↦ ?_ · exact ⟨M', N', hM', hN', Set.insert_subset (zero_mem _) h⟩ · refine ⟨_, _, hM'.sup (fg_span_singleton x), hN'.sup (fg_span_singleton y), Set.insert_subset ?_ fun z hz ↦ ?_⟩ · exact ⟨⟨x, mem_sup_right (mem_span_singleton_self x)⟩ ⊗ₜ ⟨y, mem_sup_right (mem_span_singleton_self y)⟩, rfl⟩ · exact range_mapIncl_mono le_sup_left le_sup_left (h hz) · obtain ⟨M₁', N₁', hM₁', hN₁', h₁⟩ := hx obtain ⟨M₂', N₂', hM₂', hN₂', h₂⟩ := hy refine ⟨_, _, hM₁'.sup hM₂', hN₁'.sup hN₂', Set.insert_subset (add_mem ?_ ?_) fun z hz ↦ ?_⟩ · exact range_mapIncl_mono le_sup_left le_sup_left (h₁ (Set.mem_insert x s)) · exact range_mapIncl_mono le_sup_right le_sup_right (h₂ (Set.mem_insert y s)) · exact range_mapIncl_mono le_sup_left le_sup_left (h₁ (Set.subset_insert x s hz)) @[deprecated (since := "2025-10-11")] alias exists_finite_submodule_of_finite := exists_finite_submodule_of_setFinite /-- For a finite subset `s` of `M ⊗[R] N`, there exists a finitely generated submodule `M'` of `M`, such that `s` is contained in the image of `M' ⊗[R] N` in `M ⊗[R] N`. -/ theorem exists_finite_submodule_left_of_setFinite (s : Set (M ⊗[R] N)) (hs : s.Finite) : ∃ M' : Submodule R M, Module.Finite R M' ∧ s ⊆ LinearMap.range (M'.subtype.rTensor N) := by obtain ⟨M', _, hfin, _, h⟩ := exists_finite_submodule_of_setFinite s hs refine ⟨M', hfin, ?_⟩ rw [mapIncl, ← LinearMap.rTensor_comp_lTensor] at h exact h.trans (LinearMap.range_comp_le_range _ _) @[deprecated (since := "2025-10-11")] alias exists_finite_submodule_left_of_finite := exists_finite_submodule_left_of_setFinite /-- For a finite subset `s` of `M ⊗[R] N`, there exists a finitely generated submodule `N'` of `N`, such that `s` is contained in the image of `M ⊗[R] N'` in `M ⊗[R] N`. -/ theorem exists_finite_submodule_right_of_setFinite (s : Set (M ⊗[R] N)) (hs : s.Finite) : ∃ N' : Submodule R N, Module.Finite R N' ∧ s ⊆ LinearMap.range (N'.subtype.lTensor M) := by obtain ⟨_, N', _, hfin, h⟩ := exists_finite_submodule_of_setFinite s hs refine ⟨N', hfin, ?_⟩ rw [mapIncl, ← LinearMap.lTensor_comp_rTensor] at h exact h.trans (LinearMap.range_comp_le_range _ _) @[deprecated (since := "2025-10-11")] alias exists_finite_submodule_right_of_finite := exists_finite_submodule_right_of_setFinite /-- Variation of `TensorProduct.exists_finite_submodule_of_setFinite` where `M` and `N` are already submodules. -/ theorem exists_finite_submodule_of_setFinite' (s : Set (M₁ ⊗[R] N₁)) (hs : s.Finite) : ∃ (M' : Submodule R M) (N' : Submodule R N) (hM : M' ≤ M₁) (hN : N' ≤ N₁), Module.Finite R M' ∧ Module.Finite R N' ∧ s ⊆ LinearMap.range (TensorProduct.map (inclusion hM) (inclusion hN)) := by obtain ⟨M', N', _, _, h⟩ := exists_finite_submodule_of_setFinite s hs have hM := map_subtype_le M₁ M' have hN := map_subtype_le N₁ N' refine ⟨_, _, hM, hN, .map _ _, .map _ _, ?_⟩ rw [mapIncl, show M'.subtype = inclusion hM ∘ₗ M₁.subtype.submoduleMap M' by ext; simp, show N'.subtype = inclusion hN ∘ₗ N₁.subtype.submoduleMap N' by ext; simp, map_comp] at h exact h.trans (LinearMap.range_comp_le_range _ _) @[deprecated (since := "2025-10-11")] alias exists_finite_submodule_of_finite' := exists_finite_submodule_of_setFinite' /-- Variation of `TensorProduct.exists_finite_submodule_left_of_setFinite` where `M` and `N` are already submodules. -/ theorem exists_finite_submodule_left_of_setFinite' (s : Set (M₁ ⊗[R] N₁)) (hs : s.Finite) : ∃ (M' : Submodule R M) (hM : M' ≤ M₁), Module.Finite R M' ∧ s ⊆ LinearMap.range ((inclusion hM).rTensor N₁) := by obtain ⟨M', _, hM, _, hfin, _, h⟩ := exists_finite_submodule_of_setFinite' s hs refine ⟨M', hM, hfin, ?_⟩ rw [← LinearMap.rTensor_comp_lTensor] at h exact h.trans (LinearMap.range_comp_le_range _ _) @[deprecated (since := "2025-10-11")] alias exists_finite_submodule_left_of_finite' := exists_finite_submodule_left_of_setFinite' /-- Variation of `TensorProduct.exists_finite_submodule_right_of_setFinite` where `M` and `N` are already submodules. -/ theorem exists_finite_submodule_right_of_setFinite' (s : Set (M₁ ⊗[R] N₁)) (hs : s.Finite) : ∃ (N' : Submodule R N) (hN : N' ≤ N₁), Module.Finite R N' ∧ s ⊆ LinearMap.range ((inclusion hN).lTensor M₁) := by obtain ⟨_, N', _, hN, _, hfin, h⟩ := exists_finite_submodule_of_setFinite' s hs refine ⟨N', hN, hfin, ?_⟩ rw [← LinearMap.lTensor_comp_rTensor] at h exact h.trans (LinearMap.range_comp_le_range _ _) @[deprecated (since := "2025-10-11")] alias exists_finite_submodule_right_of_finite' := exists_finite_submodule_right_of_setFinite' end TensorProduct
.lake/packages/mathlib/Mathlib/LinearAlgebra/TensorProduct/Graded/External.lean
import Mathlib.Data.Int.Order.Units import Mathlib.Data.ZMod.IntUnitsPower import Mathlib.RingTheory.TensorProduct.Basic import Mathlib.LinearAlgebra.DirectSum.TensorProduct import Mathlib.Algebra.DirectSum.Algebra /-! # Graded tensor products over graded algebras The graded tensor product $A \hat\otimes_R B$ is imbued with a multiplication defined on homogeneous tensors by: $$(a \otimes b) \cdot (a' \otimes b') = (-1)^{\deg a' \deg b} (a \cdot a') \otimes (b \cdot b')$$ where $A$ and $B$ are algebras graded by `ℕ`, `ℤ`, or `ZMod 2` (or more generally, any index that satisfies `Module ι (Additive ℤˣ)`). The results for internally-graded algebras (via `GradedAlgebra`) are elsewhere, as is the type `GradedTensorProduct`. ## Main results * `TensorProduct.gradedComm`: the symmetric braiding operator on the tensor product of externally-graded rings. * `TensorProduct.gradedMul`: the previously-described multiplication on externally-graded rings, as a bilinear map. ## Implementation notes Rather than implementing the multiplication directly as above, we first implement the canonical non-trivial braiding sending $a \otimes b$ to $(-1)^{\deg a' \deg b} (b \otimes a)$, as the multiplication follows trivially from this after some point-free nonsense. ## References * https://math.stackexchange.com/q/202718/1896 * [*Algebra I*, Bourbaki : Chapter III, §4.7, example (2)][bourbaki1989] -/ open scoped TensorProduct DirectSum variable {R ι : Type*} namespace TensorProduct variable [CommSemiring ι] [Module ι (Additive ℤˣ)] [DecidableEq ι] variable (𝒜 : ι → Type*) (ℬ : ι → Type*) variable [CommRing R] variable [∀ i, AddCommGroup (𝒜 i)] [∀ i, AddCommGroup (ℬ i)] variable [∀ i, Module R (𝒜 i)] [∀ i, Module R (ℬ i)] -- this helps with performance instance (i : ι × ι) : Module R (𝒜 (Prod.fst i) ⊗[R] ℬ (Prod.snd i)) := TensorProduct.leftModule open DirectSum (lof) variable (R) section gradedComm local notation "𝒜ℬ" => (fun i : ι × ι => 𝒜 (Prod.fst i) ⊗[R] ℬ (Prod.snd i)) local notation "ℬ𝒜" => (fun i : ι × ι => ℬ (Prod.fst i) ⊗[R] 𝒜 (Prod.snd i)) /-- Auxiliary construction used to build `TensorProduct.gradedComm`. This operates on direct sums of tensors instead of tensors of direct sums. -/ def gradedCommAux : DirectSum _ 𝒜ℬ →ₗ[R] DirectSum _ ℬ𝒜 := by refine DirectSum.toModule R _ _ fun i => ?_ have o := DirectSum.lof R _ ℬ𝒜 i.swap have s : ℤˣ := ((-1 : ℤˣ) ^ (i.1 * i.2 : ι) : ℤˣ) exact (s • o) ∘ₗ (TensorProduct.comm R _ _).toLinearMap @[simp] theorem gradedCommAux_lof_tmul (i j : ι) (a : 𝒜 i) (b : ℬ j) : gradedCommAux R 𝒜 ℬ (lof R _ 𝒜ℬ (i, j) (a ⊗ₜ b)) = (-1 : ℤˣ) ^ (j * i) • lof R _ ℬ𝒜 (j, i) (b ⊗ₜ a) := by rw [gradedCommAux] simp [mul_comm i j] @[simp] theorem gradedCommAux_comp_gradedCommAux : gradedCommAux R 𝒜 ℬ ∘ₗ gradedCommAux R ℬ 𝒜 = LinearMap.id := by ext i a b dsimp rw [gradedCommAux_lof_tmul, LinearMap.map_smul_of_tower, gradedCommAux_lof_tmul, smul_smul, mul_comm i.2 i.1, Int.units_mul_self, one_smul] /-- The braiding operation for tensor products of externally `ι`-graded algebras. This sends $a ⊗ b$ to $(-1)^{\deg a' \deg b} (b ⊗ a)$. -/ def gradedComm : (⨁ i, 𝒜 i) ⊗[R] (⨁ i, ℬ i) ≃ₗ[R] (⨁ i, ℬ i) ⊗[R] (⨁ i, 𝒜 i) := by refine TensorProduct.directSum R R 𝒜 ℬ ≪≫ₗ ?_ ≪≫ₗ (TensorProduct.directSum R R ℬ 𝒜).symm exact LinearEquiv.ofLinear (gradedCommAux _ _ _) (gradedCommAux _ _ _) (gradedCommAux_comp_gradedCommAux _ _ _) (gradedCommAux_comp_gradedCommAux _ _ _) /-- The braiding is symmetric. -/ @[simp] theorem gradedComm_symm : (gradedComm R 𝒜 ℬ).symm = gradedComm R ℬ 𝒜 := by rfl theorem gradedComm_of_tmul_of (i j : ι) (a : 𝒜 i) (b : ℬ j) : gradedComm R 𝒜 ℬ (lof R _ 𝒜 i a ⊗ₜ lof R _ ℬ j b) = (-1 : ℤˣ) ^ (j * i) • (lof R _ ℬ _ b ⊗ₜ lof R _ 𝒜 _ a) := by rw [gradedComm] dsimp only [LinearEquiv.trans_apply, LinearEquiv.ofLinear_apply] rw [TensorProduct.directSum_lof_tmul_lof, gradedCommAux_lof_tmul, Units.smul_def, -- Note: https://github.com/leanprover-community/mathlib4/pull/8386 specialized `map_smul` to `LinearEquiv.map_smul` to avoid timeouts. ← Int.cast_smul_eq_zsmul R, LinearEquiv.map_smul, TensorProduct.directSum_symm_lof_tmul, Int.cast_smul_eq_zsmul, ← Units.smul_def] theorem gradedComm_tmul_of_zero (a : ⨁ i, 𝒜 i) (b : ℬ 0) : gradedComm R 𝒜 ℬ (a ⊗ₜ lof R _ ℬ 0 b) = lof R _ ℬ _ b ⊗ₜ a := by suffices (gradedComm R 𝒜 ℬ).toLinearMap ∘ₗ (TensorProduct.mk R (⨁ i, 𝒜 i) (⨁ i, ℬ i)).flip (lof R _ ℬ 0 b) = TensorProduct.mk R _ _ (lof R _ ℬ 0 b) from DFunLike.congr_fun this a ext i a dsimp rw [gradedComm_of_tmul_of, zero_mul, uzpow_zero, one_smul] theorem gradedComm_of_zero_tmul (a : 𝒜 0) (b : ⨁ i, ℬ i) : gradedComm R 𝒜 ℬ (lof R _ 𝒜 0 a ⊗ₜ b) = b ⊗ₜ lof R _ 𝒜 _ a := by suffices (gradedComm R 𝒜 ℬ).toLinearMap ∘ₗ (TensorProduct.mk R (⨁ i, 𝒜 i) (⨁ i, ℬ i)) (lof R _ 𝒜 0 a) = (TensorProduct.mk R _ _).flip (lof R _ 𝒜 0 a) from DFunLike.congr_fun this b ext i b dsimp rw [gradedComm_of_tmul_of, mul_zero, uzpow_zero, one_smul] theorem gradedComm_tmul_one [GradedMonoid.GOne ℬ] (a : ⨁ i, 𝒜 i) : gradedComm R 𝒜 ℬ (a ⊗ₜ 1) = 1 ⊗ₜ a := gradedComm_tmul_of_zero _ _ _ _ _ theorem gradedComm_one_tmul [GradedMonoid.GOne 𝒜] (b : ⨁ i, ℬ i) : gradedComm R 𝒜 ℬ (1 ⊗ₜ b) = b ⊗ₜ 1 := gradedComm_of_zero_tmul _ _ _ _ _ @[simp] theorem gradedComm_one [DirectSum.GSemiring 𝒜] [DirectSum.GSemiring ℬ] : gradedComm R 𝒜 ℬ 1 = 1 := gradedComm_one_tmul _ _ _ _ theorem gradedComm_tmul_algebraMap [DirectSum.GSemiring ℬ] [DirectSum.GAlgebra R ℬ] (a : ⨁ i, 𝒜 i) (r : R) : gradedComm R 𝒜 ℬ (a ⊗ₜ algebraMap R _ r) = algebraMap R _ r ⊗ₜ a := gradedComm_tmul_of_zero _ _ _ _ _ theorem gradedComm_algebraMap_tmul [DirectSum.GSemiring 𝒜] [DirectSum.GAlgebra R 𝒜] (r : R) (b : ⨁ i, ℬ i) : gradedComm R 𝒜 ℬ (algebraMap R _ r ⊗ₜ b) = b ⊗ₜ algebraMap R _ r := gradedComm_of_zero_tmul _ _ _ _ _ theorem gradedComm_algebraMap [DirectSum.GSemiring 𝒜] [DirectSum.GSemiring ℬ] [DirectSum.GAlgebra R 𝒜] [DirectSum.GAlgebra R ℬ] (r : R) : gradedComm R 𝒜 ℬ (algebraMap R _ r) = algebraMap R _ r := (gradedComm_algebraMap_tmul R 𝒜 ℬ r 1).trans (Algebra.TensorProduct.algebraMap_apply' r).symm end gradedComm variable [DirectSum.GRing 𝒜] [DirectSum.GRing ℬ] variable [DirectSum.GAlgebra R 𝒜] [DirectSum.GAlgebra R ℬ] open TensorProduct (assoc map) in /-- The multiplication operation for tensor products of externally `ι`-graded algebras. -/ noncomputable irreducible_def gradedMul : letI AB := DirectSum _ 𝒜 ⊗[R] DirectSum _ ℬ letI : Module R AB := TensorProduct.leftModule AB →ₗ[R] AB →ₗ[R] AB := by refine TensorProduct.curry ?_ refine map (LinearMap.mul' R (⨁ i, 𝒜 i)) (LinearMap.mul' R (⨁ i, ℬ i)) ∘ₗ ?_ refine (assoc R _ _ _).symm.toLinearMap ∘ₗ .lTensor _ ?_ ∘ₗ (assoc R _ _ _).toLinearMap refine (assoc R _ _ _).toLinearMap ∘ₗ .rTensor _ ?_ ∘ₗ (assoc R _ _ _).symm.toLinearMap exact (gradedComm _ _ _).toLinearMap theorem tmul_of_gradedMul_of_tmul (j₁ i₂ : ι) (a₁ : ⨁ i, 𝒜 i) (b₁ : ℬ j₁) (a₂ : 𝒜 i₂) (b₂ : ⨁ i, ℬ i) : gradedMul R 𝒜 ℬ (a₁ ⊗ₜ lof R _ ℬ j₁ b₁) (lof R _ 𝒜 i₂ a₂ ⊗ₜ b₂) = (-1 : ℤˣ) ^ (j₁ * i₂) • ((a₁ * lof R _ 𝒜 _ a₂) ⊗ₜ (lof R _ ℬ _ b₁ * b₂)) := by rw [gradedMul] dsimp only [curry_apply, LinearMap.coe_comp, LinearEquiv.coe_coe, Function.comp_apply, assoc_tmul, map_tmul, LinearMap.id_coe, id_eq, assoc_symm_tmul, LinearMap.rTensor_tmul, LinearMap.lTensor_tmul] rw [mul_comm j₁ i₂, gradedComm_of_tmul_of] -- the tower smul lemmas elaborate too slowly rw [Units.smul_def, Units.smul_def, ← Int.cast_smul_eq_zsmul R, ← Int.cast_smul_eq_zsmul R] -- Note: https://github.com/leanprover-community/mathlib4/pull/8386 had to specialize `map_smul` to avoid timeouts. rw [← smul_tmul', LinearEquiv.map_smul, tmul_smul, LinearEquiv.map_smul, LinearMap.map_smul] dsimp variable {R} theorem algebraMap_gradedMul (r : R) (x : (⨁ i, 𝒜 i) ⊗[R] (⨁ i, ℬ i)) : gradedMul R 𝒜 ℬ (algebraMap R _ r ⊗ₜ 1) x = r • x := by suffices gradedMul R 𝒜 ℬ (algebraMap R _ r ⊗ₜ 1) = DistribMulAction.toLinearMap R _ r by exact DFunLike.congr_fun this x ext ia a ib b dsimp erw [tmul_of_gradedMul_of_tmul] rw [zero_mul, uzpow_zero, one_smul, smul_tmul'] erw [one_mul, _root_.Algebra.smul_def] theorem one_gradedMul (x : (⨁ i, 𝒜 i) ⊗[R] (⨁ i, ℬ i)) : gradedMul R 𝒜 ℬ 1 x = x := by -- Note: https://github.com/leanprover-community/mathlib4/pull/8386 had to specialize `map_one` to avoid timeouts. simpa only [RingHom.map_one, one_smul] using algebraMap_gradedMul 𝒜 ℬ 1 x theorem gradedMul_algebraMap (x : (⨁ i, 𝒜 i) ⊗[R] (⨁ i, ℬ i)) (r : R) : gradedMul R 𝒜 ℬ x (algebraMap R _ r ⊗ₜ 1) = r • x := by suffices (gradedMul R 𝒜 ℬ).flip (algebraMap R _ r ⊗ₜ 1) = DistribMulAction.toLinearMap R _ r by exact DFunLike.congr_fun this x ext dsimp erw [tmul_of_gradedMul_of_tmul] rw [mul_zero, uzpow_zero, one_smul, smul_tmul', mul_one, _root_.Algebra.smul_def, Algebra.commutes] rfl theorem gradedMul_one (x : (⨁ i, 𝒜 i) ⊗[R] (⨁ i, ℬ i)) : gradedMul R 𝒜 ℬ x 1 = x := by -- Note: https://github.com/leanprover-community/mathlib4/pull/8386 had to specialize `map_one` to avoid timeouts. simpa only [RingHom.map_one, one_smul] using gradedMul_algebraMap 𝒜 ℬ x 1 theorem gradedMul_assoc (x y z : DirectSum _ 𝒜 ⊗[R] DirectSum _ ℬ) : gradedMul R 𝒜 ℬ (gradedMul R 𝒜 ℬ x y) z = gradedMul R 𝒜 ℬ x (gradedMul R 𝒜 ℬ y z) := by let mA := gradedMul R 𝒜 ℬ -- restate as an equality of morphisms so that we can use `ext` suffices LinearMap.llcomp R _ _ _ mA ∘ₗ mA = (LinearMap.llcomp R _ _ _ LinearMap.lflip.toLinearMap <| LinearMap.llcomp R _ _ _ mA.flip ∘ₗ mA).flip by exact DFunLike.congr_fun (DFunLike.congr_fun (DFunLike.congr_fun this x) y) z ext ixa xa ixb xb iya ya iyb yb iza za izb zb dsimp [mA] simp_rw [tmul_of_gradedMul_of_tmul, Units.smul_def, ← Int.cast_smul_eq_zsmul R, LinearMap.map_smul₂, LinearMap.map_smul, DirectSum.lof_eq_of, DirectSum.of_mul_of, ← DirectSum.lof_eq_of R, tmul_of_gradedMul_of_tmul, DirectSum.lof_eq_of, ← DirectSum.of_mul_of, ← DirectSum.lof_eq_of R, mul_assoc] simp_rw [Int.cast_smul_eq_zsmul R, ← Units.smul_def, smul_smul, ← uzpow_add, add_mul, mul_add] congr 2 abel theorem gradedComm_gradedMul (x y : DirectSum _ 𝒜 ⊗[R] DirectSum _ ℬ) : gradedComm R 𝒜 ℬ (gradedMul R 𝒜 ℬ x y) = gradedMul R ℬ 𝒜 (gradedComm R 𝒜 ℬ x) (gradedComm R 𝒜 ℬ y) := by suffices (gradedMul R 𝒜 ℬ).compr₂ (gradedComm R 𝒜 ℬ).toLinearMap = (gradedMul R ℬ 𝒜 ∘ₗ (gradedComm R 𝒜 ℬ).toLinearMap).compl₂ (gradedComm R 𝒜 ℬ).toLinearMap from LinearMap.congr_fun₂ this x y ext i₁ a₁ j₁ b₁ i₂ a₂ j₂ b₂ dsimp rw [gradedComm_of_tmul_of, gradedComm_of_tmul_of, tmul_of_gradedMul_of_tmul] -- Note: https://github.com/leanprover-community/mathlib4/pull/8386 had to specialize `map_smul` to avoid timeouts. simp_rw [Units.smul_def, ← Int.cast_smul_eq_zsmul R, LinearEquiv.map_smul, LinearMap.map_smul, LinearMap.smul_apply] simp_rw [Int.cast_smul_eq_zsmul R, ← Units.smul_def, DirectSum.lof_eq_of, DirectSum.of_mul_of, ← DirectSum.lof_eq_of R, gradedComm_of_tmul_of, tmul_of_gradedMul_of_tmul, smul_smul, DirectSum.lof_eq_of, ← DirectSum.of_mul_of, ← DirectSum.lof_eq_of R] simp_rw [← uzpow_add, mul_add, add_mul, mul_comm i₁ j₂] congr 1 abel_nf rw [two_nsmul, uzpow_add, uzpow_add, Int.units_mul_self, one_mul] end TensorProduct
.lake/packages/mathlib/Mathlib/LinearAlgebra/TensorProduct/Graded/Internal.lean
import Mathlib.LinearAlgebra.TensorProduct.Graded.External import Mathlib.RingTheory.GradedAlgebra.Basic /-! # Graded tensor products over graded algebras The graded tensor product $A \hat\otimes_R B$ is imbued with a multiplication defined on homogeneous tensors by: $$(a \otimes b) \cdot (a' \otimes b') = (-1)^{\deg a' \deg b} (a \cdot a') \otimes (b \cdot b')$$ where $A$ and $B$ are algebras graded by `ℕ`, `ℤ`, or `ι` (or more generally, any index that satisfies `Module ι (Additive ℤˣ)`). ## Main results * `GradedTensorProduct R 𝒜 ℬ`: for families of submodules of `A` and `B` that form a graded algebra, this is a type alias for `A ⊗[R] B` with the appropriate multiplication. * `GradedTensorProduct.instAlgebra`: the ring structure induced by this multiplication. * `GradedTensorProduct.liftEquiv`: a universal property for graded tensor products ## Notation * `𝒜 ᵍ⊗[R] ℬ` is notation for `GradedTensorProduct R 𝒜 ℬ`. * `a ᵍ⊗ₜ b` is notation for `GradedTensorProduct.tmul _ a b`. ## References * https://math.stackexchange.com/q/202718/1896 * [*Algebra I*, Bourbaki : Chapter III, §4.7, example (2)][bourbaki1989] ## Implementation notes We cannot put the multiplication on `A ⊗[R] B` directly as it would conflict with the existing multiplication defined without the $(-1)^{\deg a' \deg b}$ term. Furthermore, the ring `A` may not have a unique graduation, and so we need the chosen graduation `𝒜` to appear explicitly in the type. ## TODO * Show that the tensor product of graded algebras is itself a graded algebra. * Determine if replacing the synonym with a single-field structure improves performance. -/ suppress_compilation open scoped TensorProduct variable {R ι A B : Type*} variable [CommSemiring ι] [DecidableEq ι] variable [CommRing R] [Ring A] [Ring B] [Algebra R A] [Algebra R B] variable (𝒜 : ι → Submodule R A) (ℬ : ι → Submodule R B) variable [GradedAlgebra 𝒜] [GradedAlgebra ℬ] open DirectSum variable (R) in /-- A Type synonym for `A ⊗[R] B`, but with multiplication as `TensorProduct.gradedMul`. This has notation `𝒜 ᵍ⊗[R] ℬ`. -/ @[nolint unusedArguments] def GradedTensorProduct (𝒜 : ι → Submodule R A) (ℬ : ι → Submodule R B) [GradedAlgebra 𝒜] [GradedAlgebra ℬ] : Type _ := A ⊗[R] B namespace GradedTensorProduct open TensorProduct @[inherit_doc GradedTensorProduct] scoped[TensorProduct] notation:100 𝒜 " ᵍ⊗[" R "] " ℬ:100 => GradedTensorProduct R 𝒜 ℬ instance instAddCommGroupWithOne : AddCommGroupWithOne (𝒜 ᵍ⊗[R] ℬ) := Algebra.TensorProduct.instAddCommGroupWithOne instance : Module R (𝒜 ᵍ⊗[R] ℬ) := TensorProduct.leftModule variable (R) in /-- The casting equivalence to move between regular and graded tensor products. -/ def of : A ⊗[R] B ≃ₗ[R] 𝒜 ᵍ⊗[R] ℬ := LinearEquiv.refl _ _ @[simp] theorem of_one : of R 𝒜 ℬ 1 = 1 := rfl @[simp] theorem of_symm_one : (of R 𝒜 ℬ).symm 1 = 1 := rfl @[simp] theorem of_symm_of (x : A ⊗[R] B) : (of R 𝒜 ℬ).symm (of R 𝒜 ℬ x) = x := rfl @[simp] theorem symm_of_of (x : 𝒜 ᵍ⊗[R] ℬ) : of R 𝒜 ℬ ((of R 𝒜 ℬ).symm x) = x := rfl /-- Two linear maps from the graded tensor product agree if they agree on the underlying tensor product. -/ @[ext] theorem hom_ext {M} [AddCommMonoid M] [Module R M] ⦃f g : 𝒜 ᵍ⊗[R] ℬ →ₗ[R] M⦄ (h : f ∘ₗ of R 𝒜 ℬ = (g ∘ₗ of R 𝒜 ℬ : A ⊗[R] B →ₗ[R] M)) : f = g := h variable (R) {𝒜 ℬ} in /-- The graded tensor product of two elements of graded rings. -/ abbrev tmul (a : A) (b : B) : 𝒜 ᵍ⊗[R] ℬ := of R 𝒜 ℬ (a ⊗ₜ b) @[inherit_doc] notation:100 x " ᵍ⊗ₜ " y:100 => tmul _ x y @[inherit_doc] notation:100 x " ᵍ⊗ₜ[" R "] " y:100 => tmul R x y variable (R) in /-- An auxiliary construction to move between the graded tensor product of internally-graded objects and the tensor product of direct sums. -/ noncomputable def auxEquiv : (𝒜 ᵍ⊗[R] ℬ) ≃ₗ[R] (⨁ i, 𝒜 i) ⊗[R] (⨁ i, ℬ i) := let fA := (decomposeAlgEquiv 𝒜).toLinearEquiv let fB := (decomposeAlgEquiv ℬ).toLinearEquiv (of R 𝒜 ℬ).symm.trans (TensorProduct.congr fA fB) theorem auxEquiv_tmul (a : A) (b : B) : auxEquiv R 𝒜 ℬ (a ᵍ⊗ₜ b) = decompose 𝒜 a ⊗ₜ decompose ℬ b := rfl theorem auxEquiv_one : auxEquiv R 𝒜 ℬ 1 = 1 := by rw [← of_one, Algebra.TensorProduct.one_def, auxEquiv_tmul 𝒜 ℬ, DirectSum.decompose_one, DirectSum.decompose_one, Algebra.TensorProduct.one_def] theorem auxEquiv_symm_one : (auxEquiv R 𝒜 ℬ).symm 1 = 1 := (LinearEquiv.symm_apply_eq _).mpr (auxEquiv_one _ _).symm variable [Module ι (Additive ℤˣ)] /-- Auxiliary construction used to build the `Mul` instance and get distributivity of `+` and `\smul`. -/ noncomputable def mulHom : (𝒜 ᵍ⊗[R] ℬ) →ₗ[R] (𝒜 ᵍ⊗[R] ℬ) →ₗ[R] (𝒜 ᵍ⊗[R] ℬ) := by letI fAB1 := auxEquiv R 𝒜 ℬ have := ((gradedMul R (𝒜 ·) (ℬ ·)).compl₁₂ fAB1.toLinearMap fAB1.toLinearMap).compr₂ fAB1.symm.toLinearMap exact this theorem mulHom_apply (x y : 𝒜 ᵍ⊗[R] ℬ) : mulHom 𝒜 ℬ x y = (auxEquiv R 𝒜 ℬ).symm (gradedMul R (𝒜 ·) (ℬ ·) (auxEquiv R 𝒜 ℬ x) (auxEquiv R 𝒜 ℬ y)) := rfl /-- The multiplication on the graded tensor product. See `GradedTensorProduct.coe_mul_coe` for a characterization on pure tensors. -/ instance : Mul (𝒜 ᵍ⊗[R] ℬ) where mul x y := mulHom 𝒜 ℬ x y theorem mul_def (x y : 𝒜 ᵍ⊗[R] ℬ) : x * y = mulHom 𝒜 ℬ x y := rfl -- Before https://github.com/leanprover-community/mathlib4/pull/8386 this was `@[simp]` but it times out when we try to apply it. theorem auxEquiv_mul (x y : 𝒜 ᵍ⊗[R] ℬ) : auxEquiv R 𝒜 ℬ (x * y) = gradedMul R (𝒜 ·) (ℬ ·) (auxEquiv R 𝒜 ℬ x) (auxEquiv R 𝒜 ℬ y) := LinearEquiv.eq_symm_apply _ |>.mp rfl instance instMonoid : Monoid (𝒜 ᵍ⊗[R] ℬ) where mul_one x := by rw [mul_def, mulHom_apply, auxEquiv_one, gradedMul_one, LinearEquiv.symm_apply_apply] one_mul x := by rw [mul_def, mulHom_apply, auxEquiv_one, one_gradedMul, LinearEquiv.symm_apply_apply] mul_assoc x y z := by simp_rw [mul_def, mulHom_apply, LinearEquiv.apply_symm_apply] rw [gradedMul_assoc] instance instRing : Ring (𝒜 ᵍ⊗[R] ℬ) where __ := instAddCommGroupWithOne 𝒜 ℬ __ := instMonoid 𝒜 ℬ right_distrib x y z := by simp_rw [mul_def, LinearMap.map_add₂] left_distrib x y z := by simp_rw [mul_def, map_add] mul_zero x := by simp_rw [mul_def, map_zero] zero_mul x := by simp_rw [mul_def, LinearMap.map_zero₂] /-- The characterization of this multiplication on partially homogeneous elements. -/ theorem tmul_coe_mul_coe_tmul {j₁ i₂ : ι} (a₁ : A) (b₁ : ℬ j₁) (a₂ : 𝒜 i₂) (b₂ : B) : (a₁ ᵍ⊗ₜ[R] (b₁ : B) * (a₂ : A) ᵍ⊗ₜ[R] b₂ : 𝒜 ᵍ⊗[R] ℬ) = (-1 : ℤˣ) ^ (j₁ * i₂) • ((a₁ * a₂ : A) ᵍ⊗ₜ (b₁ * b₂ : B)) := by dsimp only [mul_def, mulHom_apply, of_symm_of] dsimp [auxEquiv, tmul] rw [decompose_coe, decompose_coe] simp_rw [← lof_eq_of R] rw [tmul_of_gradedMul_of_tmul] simp_rw [lof_eq_of R] -- Note: https://github.com/leanprover-community/mathlib4/pull/8386 had to specialize `map_smul` to `LinearEquiv.map_smul` rw [@Units.smul_def _ _ (_) (_), ← Int.cast_smul_eq_zsmul R, LinearEquiv.map_smul, map_smul, Int.cast_smul_eq_zsmul R, ← @Units.smul_def _ _ (_) (_)] rw [congr_symm_tmul] dsimp simp_rw [decompose_symm_mul, decompose_symm_of, Equiv.symm_apply_apply] /-- A special case for when `b₁` has grade 0. -/ theorem tmul_zero_coe_mul_coe_tmul {i₂ : ι} (a₁ : A) (b₁ : ℬ 0) (a₂ : 𝒜 i₂) (b₂ : B) : (a₁ ᵍ⊗ₜ[R] (b₁ : B) * (a₂ : A) ᵍ⊗ₜ[R] b₂ : 𝒜 ᵍ⊗[R] ℬ) = ((a₁ * a₂ : A) ᵍ⊗ₜ (b₁ * b₂ : B)) := by rw [tmul_coe_mul_coe_tmul, zero_mul, uzpow_zero, one_smul] /-- A special case for when `a₂` has grade 0. -/ theorem tmul_coe_mul_zero_coe_tmul {j₁ : ι} (a₁ : A) (b₁ : ℬ j₁) (a₂ : 𝒜 0) (b₂ : B) : (a₁ ᵍ⊗ₜ[R] (b₁ : B) * (a₂ : A) ᵍ⊗ₜ[R] b₂ : 𝒜 ᵍ⊗[R] ℬ) = ((a₁ * a₂ : A) ᵍ⊗ₜ (b₁ * b₂ : B)) := by rw [tmul_coe_mul_coe_tmul, mul_zero, uzpow_zero, one_smul] theorem tmul_one_mul_coe_tmul {i₂ : ι} (a₁ : A) (a₂ : 𝒜 i₂) (b₂ : B) : (a₁ ᵍ⊗ₜ[R] (1 : B) * (a₂ : A) ᵍ⊗ₜ[R] b₂ : 𝒜 ᵍ⊗[R] ℬ) = (a₁ * a₂ : A) ᵍ⊗ₜ (b₂ : B) := by convert tmul_zero_coe_mul_coe_tmul 𝒜 ℬ a₁ (@GradedMonoid.GOne.one _ (ℬ ·) _ _) a₂ b₂ rw [SetLike.coe_gOne, one_mul] theorem tmul_coe_mul_one_tmul {j₁ : ι} (a₁ : A) (b₁ : ℬ j₁) (b₂ : B) : (a₁ ᵍ⊗ₜ[R] (b₁ : B) * (1 : A) ᵍ⊗ₜ[R] b₂ : 𝒜 ᵍ⊗[R] ℬ) = (a₁ : A) ᵍ⊗ₜ (b₁ * b₂ : B) := by convert tmul_coe_mul_zero_coe_tmul 𝒜 ℬ a₁ b₁ (@GradedMonoid.GOne.one _ (𝒜 ·) _ _) b₂ rw [SetLike.coe_gOne, mul_one] theorem tmul_one_mul_one_tmul (a₁ : A) (b₂ : B) : (a₁ ᵍ⊗ₜ[R] (1 : B) * (1 : A) ᵍ⊗ₜ[R] b₂ : 𝒜 ᵍ⊗[R] ℬ) = (a₁ : A) ᵍ⊗ₜ (b₂ : B) := by convert tmul_coe_mul_zero_coe_tmul 𝒜 ℬ a₁ (GradedMonoid.GOne.one (A := (ℬ ·))) (GradedMonoid.GOne.one (A := (𝒜 ·))) b₂ · rw [SetLike.coe_gOne, mul_one] · rw [SetLike.coe_gOne, one_mul] /-- The ring morphism `A →+* A ⊗[R] B` sending `a` to `a ⊗ₜ 1`. -/ @[simps] def includeLeftRingHom : A →+* 𝒜 ᵍ⊗[R] ℬ where toFun a := a ᵍ⊗ₜ 1 map_zero' := by simp map_add' := by simp [tmul, TensorProduct.add_tmul] map_one' := rfl map_mul' a₁ a₂ := by classical rw [← DirectSum.sum_support_decompose 𝒜 a₂, Finset.mul_sum] simp_rw [tmul, sum_tmul, map_sum, Finset.mul_sum] congr ext i rw [← SetLike.coe_gOne ℬ, tmul_coe_mul_coe_tmul, zero_mul, uzpow_zero, one_smul, SetLike.coe_gOne, one_mul] instance instAlgebra : Algebra R (𝒜 ᵍ⊗[R] ℬ) where algebraMap := (includeLeftRingHom 𝒜 ℬ).comp (algebraMap R A) commutes' r x := by dsimp [mul_def, mulHom_apply, auxEquiv_tmul] simp_rw [DirectSum.decompose_algebraMap, DirectSum.decompose_one, algebraMap_gradedMul, gradedMul_algebraMap] smul_def' r x := by dsimp [mul_def, mulHom_apply, auxEquiv_tmul] simp_rw [DirectSum.decompose_algebraMap, DirectSum.decompose_one, algebraMap_gradedMul] -- Qualified `map_smul` to avoid a TC timeout https://github.com/leanprover-community/mathlib4/pull/8386 rw [LinearEquiv.map_smul] simp lemma algebraMap_def (r : R) : algebraMap R (𝒜 ᵍ⊗[R] ℬ) r = algebraMap R A r ᵍ⊗ₜ[R] 1 := rfl theorem tmul_algebraMap_mul_coe_tmul {i₂ : ι} (a₁ : A) (r : R) (a₂ : 𝒜 i₂) (b₂ : B) : (a₁ ᵍ⊗ₜ[R] algebraMap R B r * (a₂ : A) ᵍ⊗ₜ[R] b₂ : 𝒜 ᵍ⊗[R] ℬ) = (a₁ * a₂ : A) ᵍ⊗ₜ (algebraMap R B r * b₂ : B) := tmul_zero_coe_mul_coe_tmul 𝒜 ℬ a₁ (GAlgebra.toFun (A := (ℬ ·)) r) a₂ b₂ theorem tmul_coe_mul_algebraMap_tmul {j₁ : ι} (a₁ : A) (b₁ : ℬ j₁) (r : R) (b₂ : B) : (a₁ ᵍ⊗ₜ[R] (b₁ : B) * algebraMap R A r ᵍ⊗ₜ[R] b₂ : 𝒜 ᵍ⊗[R] ℬ) = (a₁ * algebraMap R A r : A) ᵍ⊗ₜ (b₁ * b₂ : B) := tmul_coe_mul_zero_coe_tmul 𝒜 ℬ a₁ b₁ (GAlgebra.toFun (A := (𝒜 ·)) r) b₂ /-- The algebra morphism `A →ₐ[R] A ⊗[R] B` sending `a` to `a ⊗ₜ 1`. -/ @[simps!] def includeLeft : A →ₐ[R] 𝒜 ᵍ⊗[R] ℬ where toRingHom := includeLeftRingHom 𝒜 ℬ commutes' _ := rfl /-- The algebra morphism `B →ₐ[R] A ⊗[R] B` sending `b` to `1 ⊗ₜ b`. -/ @[simps!] def includeRight : B →ₐ[R] (𝒜 ᵍ⊗[R] ℬ) := AlgHom.ofLinearMap (R := R) (A := B) (B := 𝒜 ᵍ⊗[R] ℬ) (f := { toFun := fun b => 1 ᵍ⊗ₜ b map_add' := by simp [tmul, TensorProduct.tmul_add] map_smul' := by simp [tmul, TensorProduct.tmul_smul] }) (map_one := rfl) (map_mul := by rw [LinearMap.map_mul_iff] refine DirectSum.decompose_lhom_ext ℬ fun i₁ => ?_ ext b₁ b₂ : 2 dsimp rw [tmul_coe_mul_one_tmul]) lemma algebraMap_def' (r : R) : algebraMap R (𝒜 ᵍ⊗[R] ℬ) r = 1 ᵍ⊗ₜ[R] algebraMap R B r := (includeRight 𝒜 ℬ).commutes r |>.symm variable {C} [Ring C] [Algebra R C] /-- The forwards direction of the universal property; an algebra morphism out of the graded tensor product can be assembled from maps on each component that (anti)commute on pure elements of the corresponding graded algebras. -/ def lift (f : A →ₐ[R] C) (g : B →ₐ[R] C) (h_anti_commutes : ∀ ⦃i j⦄ (a : 𝒜 i) (b : ℬ j), f a * g b = (-1 : ℤˣ) ^ (j * i) • (g b * f a)) : (𝒜 ᵍ⊗[R] ℬ) →ₐ[R] C := AlgHom.ofLinearMap (LinearMap.mul' R C ∘ₗ (TensorProduct.map f.toLinearMap g.toLinearMap) ∘ₗ ((of R 𝒜 ℬ).symm : 𝒜 ᵍ⊗[R] ℬ →ₗ[R] A ⊗[R] B)) (by dsimp [Algebra.TensorProduct.one_def] simp only [map_one, mul_one]) (by rw [LinearMap.map_mul_iff] ext a₁ : 3 refine DirectSum.decompose_lhom_ext ℬ fun j₁ => ?_ ext b₁ : 3 refine DirectSum.decompose_lhom_ext 𝒜 fun i₂ => ?_ ext a₂ b₂ : 2 dsimp rw [tmul_coe_mul_coe_tmul] rw [@Units.smul_def _ _ (_) (_), ← Int.cast_smul_eq_zsmul R, map_smul, map_smul, map_smul] rw [Int.cast_smul_eq_zsmul R, ← @Units.smul_def _ _ (_) (_)] rw [of_symm_of, map_tmul, LinearMap.mul'_apply] simp_rw [AlgHom.toLinearMap_apply, map_mul] simp_rw [mul_assoc (f a₁), ← mul_assoc _ _ (g b₂), h_anti_commutes, mul_smul_comm, smul_mul_assoc, smul_smul, Int.units_mul_self, one_smul]) @[simp] theorem lift_tmul (f : A →ₐ[R] C) (g : B →ₐ[R] C) (h_anti_commutes : ∀ ⦃i j⦄ (a : 𝒜 i) (b : ℬ j), f a * g b = (-1 : ℤˣ) ^ (j * i) • (g b * f a)) (a : A) (b : B) : lift 𝒜 ℬ f g h_anti_commutes (a ᵍ⊗ₜ b) = f a * g b := rfl /-- The universal property of the graded tensor product; every algebra morphism uniquely factors as a pair of algebra morphisms that anticommute with respect to the grading. -/ def liftEquiv : { fg : (A →ₐ[R] C) × (B →ₐ[R] C) // ∀ ⦃i j⦄ (a : 𝒜 i) (b : ℬ j), fg.1 a * fg.2 b = (-1 : ℤˣ)^(j * i) • (fg.2 b * fg.1 a)} ≃ ((𝒜 ᵍ⊗[R] ℬ) →ₐ[R] C) where toFun fg := lift 𝒜 ℬ _ _ fg.prop invFun F := ⟨(F.comp (includeLeft 𝒜 ℬ), F.comp (includeRight 𝒜 ℬ)), fun i j a b => by dsimp rw [← map_mul, ← map_mul F, tmul_coe_mul_coe_tmul, one_mul, mul_one, AlgHom.map_smul_of_tower, tmul_one_mul_one_tmul, smul_smul, Int.units_mul_self, one_smul]⟩ left_inv fg := by ext <;> (dsimp; simp only [map_one, mul_one, one_mul]) right_inv F := by apply AlgHom.toLinearMap_injective ext dsimp rw [← map_mul, tmul_one_mul_one_tmul] /-- Two algebra morphism from the graded tensor product agree if their compositions with the left and right inclusions agree. -/ @[ext] lemma algHom_ext ⦃f g : (𝒜 ᵍ⊗[R] ℬ) →ₐ[R] C⦄ (ha : f.comp (includeLeft 𝒜 ℬ) = g.comp (includeLeft 𝒜 ℬ)) (hb : f.comp (includeRight 𝒜 ℬ) = g.comp (includeRight 𝒜 ℬ)) : f = g := (liftEquiv 𝒜 ℬ).symm.injective <| Subtype.ext <| Prod.ext ha hb /-- The non-trivial symmetric braiding, sending $a \otimes b$ to $(-1)^{\deg a' \deg b} (b \otimes a)$. -/ def comm : (𝒜 ᵍ⊗[R] ℬ) ≃ₐ[R] (ℬ ᵍ⊗[R] 𝒜) := AlgEquiv.ofLinearEquiv (auxEquiv R 𝒜 ℬ ≪≫ₗ gradedComm R _ _ ≪≫ₗ (auxEquiv R ℬ 𝒜).symm) (by dsimp simp_rw [auxEquiv_one, gradedComm_one, auxEquiv_symm_one]) (fun x y => by dsimp simp_rw [auxEquiv_mul, gradedComm_gradedMul, LinearEquiv.symm_apply_eq, ← gradedComm_gradedMul, auxEquiv_mul, LinearEquiv.apply_symm_apply, gradedComm_gradedMul]) lemma auxEquiv_comm (x : 𝒜 ᵍ⊗[R] ℬ) : auxEquiv R ℬ 𝒜 (comm 𝒜 ℬ x) = gradedComm R (𝒜 ·) (ℬ ·) (auxEquiv R 𝒜 ℬ x) := LinearEquiv.eq_symm_apply _ |>.mp rfl @[simp] lemma comm_coe_tmul_coe {i j : ι} (a : 𝒜 i) (b : ℬ j) : comm 𝒜 ℬ (a ᵍ⊗ₜ b) = (-1 : ℤˣ) ^ (j * i) • (b ᵍ⊗ₜ a : ℬ ᵍ⊗[R] 𝒜) := (auxEquiv R ℬ 𝒜).injective <| by simp_rw [auxEquiv_comm, auxEquiv_tmul, decompose_coe, ← lof_eq_of R, gradedComm_of_tmul_of, @Units.smul_def _ _ (_) (_), ← Int.cast_smul_eq_zsmul R] -- Qualified `map_smul` to avoid a TC timeout https://github.com/leanprover-community/mathlib4/pull/8386 rw [LinearEquiv.map_smul, auxEquiv_tmul] simp_rw [decompose_coe, lof_eq_of] end GradedTensorProduct
.lake/packages/mathlib/Mathlib/LinearAlgebra/Charpoly/Basic.lean
import Mathlib.LinearAlgebra.FreeModule.Finite.Basic import Mathlib.LinearAlgebra.Matrix.Charpoly.Coeff import Mathlib.LinearAlgebra.Determinant import Mathlib.FieldTheory.Minpoly.Field /-! # Characteristic polynomial We define the characteristic polynomial of `f : M →ₗ[R] M`, where `M` is a finite and free `R`-module. The proof that `f.charpoly` is the characteristic polynomial of the matrix of `f` in any basis is in `LinearAlgebra/Charpoly/ToMatrix`. ## Main definition * `LinearMap.charpoly f` : the characteristic polynomial of `f : M →ₗ[R] M`. -/ universe u v w variable {R : Type u} {M : Type v} [CommRing R] variable [AddCommGroup M] [Module R M] [Module.Free R M] [Module.Finite R M] (f : M →ₗ[R] M) open Matrix Polynomial noncomputable section open Module.Free Polynomial Matrix namespace LinearMap section Basic /-- The characteristic polynomial of `f : M →ₗ[R] M`. -/ def charpoly : R[X] := (toMatrix (chooseBasis R M) (chooseBasis R M) f).charpoly theorem charpoly_def : f.charpoly = (toMatrix (chooseBasis R M) (chooseBasis R M) f).charpoly := rfl theorem eval_charpoly (t : R) : f.charpoly.eval t = (algebraMap _ _ t - f).det := by rw [charpoly, Matrix.eval_charpoly, ← LinearMap.det_toMatrix (chooseBasis R M), map_sub, scalar_apply, toMatrix_algebraMap, scalar_apply] @[simp] theorem charpoly_zero [StrongRankCondition R] : (0 : M →ₗ[R] M).charpoly = X ^ Module.finrank R M := by simp [charpoly, Module.finrank_eq_card_chooseBasisIndex] theorem charpoly_one [StrongRankCondition R] : (1 : M →ₗ[R] M).charpoly = (X - 1) ^ Module.finrank R M := by simp [charpoly, Module.finrank_eq_card_chooseBasisIndex, Matrix.charpoly_one] theorem charpoly_sub_smul (f : Module.End R M) (μ : R) : (f - μ • 1).charpoly = f.charpoly.comp (X + C μ) := by simpa [LinearMap.charpoly, smul_eq_mul_diagonal] using Matrix.charpoly_sub_scalar .. end Basic section Coeff theorem charpoly_monic : f.charpoly.Monic := Matrix.charpoly_monic _ open Module in lemma charpoly_natDegree [Nontrivial R] [StrongRankCondition R] : natDegree (charpoly f) = finrank R M := by rw [charpoly, Matrix.charpoly_natDegree_eq_dim, finrank_eq_card_chooseBasisIndex] end Coeff section CayleyHamilton /-- The **Cayley-Hamilton Theorem**, that the characteristic polynomial of a linear map, applied to the linear map itself, is zero. See `Matrix.aeval_self_charpoly` for the equivalent statement about matrices. -/ theorem aeval_self_charpoly : aeval f f.charpoly = 0 := by apply (LinearEquiv.map_eq_zero_iff (algEquivMatrix (chooseBasis R M)).toLinearEquiv).1 rw [AlgEquiv.toLinearEquiv_apply, ← AlgEquiv.coe_algHom, ← Polynomial.aeval_algHom_apply _ _ _, charpoly_def] exact Matrix.aeval_self_charpoly _ theorem isIntegral : IsIntegral R f := ⟨f.charpoly, ⟨charpoly_monic f, aeval_self_charpoly f⟩⟩ theorem minpoly_dvd_charpoly {K : Type u} {M : Type v} [Field K] [AddCommGroup M] [Module K M] [FiniteDimensional K M] (f : M →ₗ[K] M) : minpoly K f ∣ f.charpoly := minpoly.dvd _ _ (aeval_self_charpoly f) /-- Any endomorphism polynomial `p` is equivalent under evaluation to `p %ₘ f.charpoly`; that is, `p` is equivalent to a polynomial with degree less than the dimension of the module. -/ theorem aeval_eq_aeval_mod_charpoly (p : R[X]) : aeval f p = aeval f (p %ₘ f.charpoly) := (aeval_modByMonic_eq_self_of_root f.charpoly_monic f.aeval_self_charpoly).symm /-- Any endomorphism power can be computed as the sum of endomorphism powers less than the dimension of the module. -/ theorem pow_eq_aeval_mod_charpoly (k : ℕ) : f ^ k = aeval f (X ^ k %ₘ f.charpoly) := by rw [← aeval_eq_aeval_mod_charpoly, map_pow, aeval_X] variable {f} theorem minpoly_coeff_zero_of_injective [Nontrivial R] (hf : Function.Injective f) : (minpoly R f).coeff 0 ≠ 0 := by intro h obtain ⟨P, hP⟩ := X_dvd_iff.2 h have hdegP : P.degree < (minpoly R f).degree := by rw [hP, mul_comm] refine degree_lt_degree_mul_X fun h => ?_ rw [h, mul_zero] at hP exact minpoly.ne_zero (isIntegral f) hP have hPmonic : P.Monic := by suffices (minpoly R f).Monic by rwa [Monic.def, hP, mul_comm, leadingCoeff_mul_X, ← Monic.def] at this exact minpoly.monic (isIntegral f) have hzero : aeval f (minpoly R f) = 0 := minpoly.aeval _ _ simp only [hP, Module.End.mul_eq_comp, LinearMap.ext_iff, hf, aeval_X, map_eq_zero_iff, coe_comp, map_mul, zero_apply, Function.comp_apply] at hzero exact not_le.2 hdegP (minpoly.min _ _ hPmonic (LinearMap.ext hzero)) end CayleyHamilton end LinearMap
.lake/packages/mathlib/Mathlib/LinearAlgebra/Charpoly/ToMatrix.lean
import Mathlib.LinearAlgebra.Charpoly.Basic import Mathlib.LinearAlgebra.Matrix.Basis import Mathlib.RingTheory.Finiteness.Prod /-! # Characteristic polynomial ## Main result * `LinearMap.charpoly_toMatrix f` : `charpoly f` is the characteristic polynomial of the matrix of `f` in any basis. -/ noncomputable section open Module Free Polynomial Matrix universe u v w variable {R M M₁ M₂ : Type*} [CommRing R] variable [AddCommGroup M] [Module R M] [Module.Free R M] [Module.Finite R M] variable [AddCommGroup M₁] [Module R M₁] [Module.Finite R M₁] [Module.Free R M₁] variable [AddCommGroup M₂] [Module R M₂] [Module.Finite R M₂] [Module.Free R M₂] variable (f : M →ₗ[R] M) namespace LinearMap section Basic /-- `charpoly f` is the characteristic polynomial of the matrix of `f` in any basis. -/ @[simp] theorem charpoly_toMatrix {ι : Type w} [DecidableEq ι] [Fintype ι] (b : Basis ι R M) : (toMatrix b b f).charpoly = f.charpoly := by nontriviality R unfold LinearMap.charpoly set b' := chooseBasis R M rw [← basis_toMatrix_mul_linearMap_toMatrix_mul_basis_toMatrix b b' b b'] set P := b.toMatrix b' set A := toMatrix b' b' f set Q := b'.toMatrix b let e := Basis.indexEquiv b b' let ι' := ChooseBasisIndex R M let φ := reindexLinearEquiv R R e e let φ₁ := reindexLinearEquiv R R e (Equiv.refl ι') let φ₂ := reindexLinearEquiv R R (Equiv.refl ι') (Equiv.refl ι') let φ₃ := reindexLinearEquiv R R (Equiv.refl ι') e calc (P * A * Q).charpoly = (φ (P * A * Q)).charpoly := (charpoly_reindex ..).symm _ = (φ₁ P * φ₂ A * φ₃ Q).charpoly := by rw [reindexLinearEquiv_mul, reindexLinearEquiv_mul] _ = A.charpoly := by rw [charpoly_mul_comm, ← mul_assoc]; simp [P, Q, φ₁, φ₂, φ₃] lemma charpoly_prodMap (f₁ : M₁ →ₗ[R] M₁) (f₂ : M₂ →ₗ[R] M₂) : (f₁.prodMap f₂).charpoly = f₁.charpoly * f₂.charpoly := by let b₁ := chooseBasis R M₁ let b₂ := chooseBasis R M₂ let b := b₁.prod b₂ rw [← charpoly_toMatrix f₁ b₁, ← charpoly_toMatrix f₂ b₂, ← charpoly_toMatrix (f₁.prodMap f₂) b, toMatrix_prodMap b₁ b₂ f₁ f₂, Matrix.charpoly_fromBlocks_zero₁₂] end Basic end LinearMap @[simp] lemma LinearEquiv.charpoly_conj (e : M₁ ≃ₗ[R] M₂) (φ : Module.End R M₁) : (e.conj φ).charpoly = φ.charpoly := by let b := chooseBasis R M₁ rw [← LinearMap.charpoly_toMatrix φ b, ← LinearMap.charpoly_toMatrix (e.conj φ) (b.map e)] congr 1 ext i j : 1 simp [LinearMap.toMatrix, LinearEquiv.conj_apply] namespace Matrix variable {n : Type*} [Fintype n] [DecidableEq n] @[simp] theorem charpoly_toLin (A : Matrix n n R) (b : Basis n R M) : (A.toLin b b).charpoly = A.charpoly := by simp [← LinearMap.charpoly_toMatrix (A.toLin b b) b] @[simp] theorem charpoly_toLin' (A : Matrix n n R) : A.toLin'.charpoly = A.charpoly := by rw [← Matrix.toLin_eq_toLin', charpoly_toLin] @[simp] theorem charpoly_mulVecLin (A : Matrix n n R) : A.mulVecLin.charpoly = A.charpoly := charpoly_toLin' A end Matrix
.lake/packages/mathlib/Mathlib/LinearAlgebra/Charpoly/BaseChange.lean
import Mathlib.LinearAlgebra.Charpoly.ToMatrix import Mathlib.LinearAlgebra.Determinant import Mathlib.RingTheory.TensorProduct.Finite import Mathlib.LinearAlgebra.TensorProduct.Tower /-! # The characteristic polynomial of base change -/ variable {R M} [CommRing R] [AddCommGroup M] [Module R M] [Module.Free R M] [Module.Finite R M] (f : M →ₗ[R] M) (A) [CommRing A] [Algebra R A] @[simp] lemma LinearMap.charpoly_baseChange : (f.baseChange A).charpoly = f.charpoly.map (algebraMap R A) := by nontriviality A have := (algebraMap R A).domain_nontrivial let I := Module.Free.ChooseBasisIndex R M let b : Module.Basis I R M := Module.Free.chooseBasis R M rw [← f.charpoly_toMatrix b, ← (f.baseChange A).charpoly_toMatrix (b.baseChange A), ← Matrix.charpoly_map] congr 1 ext i j simp [LinearMap.toMatrix_apply, ← Algebra.algebraMap_eq_smul_one] lemma LinearMap.det_eq_sign_charpoly_coeff : LinearMap.det f = (-1) ^ Module.finrank R M * f.charpoly.coeff 0 := by nontriviality R rw [← LinearMap.det_toMatrix (Module.Free.chooseBasis R M), Matrix.det_eq_sign_charpoly_coeff, ← Module.finrank_eq_card_chooseBasisIndex, charpoly_def] variable {A} in lemma LinearMap.det_baseChange : LinearMap.det (f.baseChange A) = algebraMap R A (LinearMap.det f) := by nontriviality A have := (algebraMap R A).domain_nontrivial rw [LinearMap.det_eq_sign_charpoly_coeff, LinearMap.det_eq_sign_charpoly_coeff] simp lemma LinearEquiv.det_baseChange (f : M ≃ₗ[R] M) : LinearEquiv.det (f.baseChange R A _ _) = (LinearEquiv.det f).map (algebraMap R A) := by ext simp [LinearMap.det_baseChange] /-! Also see `LinearMap.trace_baseChange` in `Mathlib/LinearAlgebra/Trace` -/
.lake/packages/mathlib/Mathlib/LinearAlgebra/ExteriorPower/Basic.lean
import Mathlib.Algebra.Module.Presentation.Basic import Mathlib.LinearAlgebra.ExteriorAlgebra.OfAlternating /-! # Exterior powers We study the exterior powers of a module `M` over a commutative ring `R`. ## Definitions * `exteriorPower.ιMulti` is the canonical alternating map on `M` with values in `⋀[R]^n M`. * `exteriorPower.presentation R n M` is the standard presentation of the `R`-module `⋀[R]^n M`. * `exteriorPower.map n f : ⋀[R]^n M →ₗ[R] ⋀[R]^n N` is the linear map on `nth` exterior powers induced by a linear map `f : M →ₗ[R] N`. (See the file `Algebra.Category.ModuleCat.ExteriorPower` for the corresponding functor `ModuleCat R ⥤ ModuleCat R`.) ## Theorems * `exteriorPower.ιMulti_span`: The image of `exteriorPower.ιMulti` spans `⋀[R]^n M`. * We construct `exteriorPower.alternatingMapLinearEquiv` which expresses the universal property of the exterior power as a linear equivalence `(M [⋀^Fin n]→ₗ[R] N) ≃ₗ[R] ⋀[R]^n M →ₗ[R] N` between alternating maps and linear maps from the exterior power. -/ open scoped TensorProduct universe u variable (R : Type u) [CommRing R] (n : ℕ) {M N N' : Type*} [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N] [AddCommGroup N'] [Module R N'] namespace exteriorPower open Function /-! The canonical alternating map from `Fin n → M` to `⋀[R]^n M`. -/ /-- `exteriorAlgebra.ιMulti` is the alternating map from `Fin n → M` to `⋀[r]^n M` induced by `exteriorAlgebra.ιMulti`, i.e. sending a family of vectors `m : Fin n → M` to the product of its entries. -/ def ιMulti : M [⋀^Fin n]→ₗ[R] (⋀[R]^n M) := (ExteriorAlgebra.ιMulti R n).codRestrict (⋀[R]^n M) fun _ => ExteriorAlgebra.ιMulti_range R n <| Set.mem_range_self _ @[simp] lemma ιMulti_apply_coe (a : Fin n → M) : ιMulti R n a = ExteriorAlgebra.ιMulti R n a := rfl /-- Given a linearly ordered family `v` of vectors of `M` and a natural number `n`, produce the family of `n`fold exterior products of elements of `v`, seen as members of the `n`th exterior power. -/ noncomputable def ιMulti_family {I : Type*} [LinearOrder I] (v : I → M) (s : {s : Finset I // Finset.card s = n}) : ⋀[R]^n M := ιMulti R n fun i ↦ v <| Finset.orderIsoOfFin s.val s.property i @[simp] lemma ιMulti_family_apply_coe {I : Type*} [LinearOrder I] (v : I → M) (s : {s : Finset I // Finset.card s = n}) : ιMulti_family R n v s = ExteriorAlgebra.ιMulti_family R n v s := rfl variable (M) /-- The image of `ExteriorAlgebra.ιMulti R n` spans the `n`th exterior power. Variant of `ExteriorAlgebra.ιMulti_span_fixedDegree`, useful in rewrites. -/ lemma ιMulti_span_fixedDegree : Submodule.span R (Set.range (ExteriorAlgebra.ιMulti R n)) = ⋀[R]^n M := ExteriorAlgebra.ιMulti_span_fixedDegree R n /-- The image of `exteriorPower.ιMulti` spans `⋀[R]^n M`. -/ lemma ιMulti_span : Submodule.span R (Set.range (ιMulti R n)) = (⊤ : Submodule R (⋀[R]^n M)) := by apply LinearMap.map_injective (Submodule.ker_subtype (⋀[R]^n M)) rw [LinearMap.map_span, ← Set.image_univ, Set.image_image] simp only [Submodule.coe_subtype, ιMulti_apply_coe, Set.image_univ, Submodule.map_top, Submodule.range_subtype] exact ExteriorAlgebra.ιMulti_span_fixedDegree R n namespace presentation /-- The index type for the relations in the standard presentation of `⋀[R]^n M`, in the particular case `ι` is `Fin n`. -/ inductive Rels (ι : Type*) (M : Type*) | add (m : ι → M) (i : ι) (x y : M) | smul (m : ι → M) (i : ι) (r : R) (x : M) | alt (m : ι → M) (i j : ι) (hm : m i = m j) (hij : i ≠ j) /-- The relations in the standard presentation of `⋀[R]^n M` with generators and relations. -/ @[simps] noncomputable def relations (ι : Type*) [DecidableEq ι] (M : Type*) [AddCommGroup M] [Module R M] : Module.Relations R where G := ι → M R := Rels R ι M relation | .add m i x y => Finsupp.single (update m i x) 1 + Finsupp.single (update m i y) 1 - Finsupp.single (update m i (x + y)) 1 | .smul m i r x => Finsupp.single (update m i (r • x)) 1 - r • Finsupp.single (update m i x) 1 | .alt m _ _ _ _ => Finsupp.single m 1 variable {R} in /-- The solutions in a module `N` to the linear equations given by `exteriorPower.relations R ι M` identify to alternating maps to `N`. -/ @[simps!] noncomputable def relationsSolutionEquiv {ι : Type*} [DecidableEq ι] {M : Type*} [AddCommGroup M] [Module R M] : (relations R ι M).Solution N ≃ AlternatingMap R M N ι where toFun s := { toFun := fun m ↦ s.var m map_update_add' := fun m i x y ↦ by have := s.linearCombination_var_relation (.add m i x y) dsimp at this ⊢ rw [map_sub, map_add, Finsupp.linearCombination_single, one_smul, Finsupp.linearCombination_single, one_smul, Finsupp.linearCombination_single, one_smul, sub_eq_zero] at this convert this.symm -- `convert` is necessary due to the implementation of `MultilinearMap` map_update_smul' := fun m i r x ↦ by have := s.linearCombination_var_relation (.smul m i r x) dsimp at this ⊢ rw [Finsupp.smul_single, smul_eq_mul, mul_one, map_sub, Finsupp.linearCombination_single, one_smul, Finsupp.linearCombination_single, sub_eq_zero] at this convert this map_eq_zero_of_eq' := fun v i j hm hij ↦ by simpa using s.linearCombination_var_relation (.alt v i j hm hij) } invFun f := { var := fun m ↦ f m linearCombination_var_relation := by rintro (⟨m, i, x, y⟩ | ⟨m, i, r, x⟩ | ⟨v, i, j, hm, hij⟩) · simp · simp · simpa using f.map_eq_zero_of_eq v hm hij } /-- The universal property of the exterior power. -/ noncomputable def isPresentationCore : (relationsSolutionEquiv.symm (ιMulti R n (M := M))).IsPresentationCore where desc s := LinearMap.comp (ExteriorAlgebra.liftAlternating (Function.update 0 n (relationsSolutionEquiv s))) (Submodule.subtype _) postcomp_desc s := by aesop postcomp_injective {N _ _ f f' h} := by rw [Submodule.linearMap_eq_iff_of_span_eq_top _ _ (ιMulti_span R n M)] rintro ⟨_, ⟨f, rfl⟩⟩ exact Module.Relations.Solution.congr_var h f end presentation /-- The standard presentation of the `R`-module `⋀[R]^n M`. -/ @[simps! G R relation var] noncomputable def presentation : Module.Presentation R (⋀[R]^n M) := .ofIsPresentation (presentation.isPresentationCore R n M).isPresentation variable {R M n} /-- Two linear maps on `⋀[R]^n M` that agree on the image of `exteriorPower.ιMulti` are equal. -/ @[ext] lemma linearMap_ext {f : ⋀[R]^n M →ₗ[R] N} {g : ⋀[R]^n M →ₗ[R] N} (heq : f.compAlternatingMap (ιMulti R n) = g.compAlternatingMap (ιMulti R n)) : f = g := (presentation R n M).postcomp_injective (by ext f; apply DFunLike.congr_fun heq ) /-- The linear equivalence between `n`-fold alternating maps from `M` to `N` and linear maps from `⋀[R]^n M` to `N`: this is the universal property of the `n`th exterior power of `M`. -/ noncomputable def alternatingMapLinearEquiv : (M [⋀^Fin n]→ₗ[R] N) ≃ₗ[R] ⋀[R]^n M →ₗ[R] N := LinearEquiv.symm (Equiv.toLinearEquiv ((presentation R n M).linearMapEquiv.trans presentation.relationsSolutionEquiv) { map_add := fun _ _ => rfl map_smul := fun _ _ => rfl }) @[simp] lemma alternatingMapLinearEquiv_comp_ιMulti (f : M [⋀^Fin n]→ₗ[R] N) : (alternatingMapLinearEquiv f).compAlternatingMap (ιMulti R n) = f := by obtain ⟨φ, rfl⟩ := alternatingMapLinearEquiv.symm.surjective f dsimp [alternatingMapLinearEquiv] simp only [LinearEquiv.symm_apply_apply] rfl @[simp] lemma alternatingMapLinearEquiv_apply_ιMulti (f : M [⋀^Fin n]→ₗ[R] N) (a : Fin n → M) : alternatingMapLinearEquiv f (ιMulti R n a) = f a := DFunLike.congr_fun (alternatingMapLinearEquiv_comp_ιMulti f) a @[simp] lemma alternatingMapLinearEquiv_symm_apply (F : ⋀[R]^n M →ₗ[R] N) (m : Fin n → M) : alternatingMapLinearEquiv.symm F m = F.compAlternatingMap (ιMulti R n) m := by obtain ⟨f, rfl⟩ := alternatingMapLinearEquiv.surjective F simp only [LinearEquiv.symm_apply_apply, alternatingMapLinearEquiv_comp_ιMulti] @[simp] lemma alternatingMapLinearEquiv_ιMulti : alternatingMapLinearEquiv (ιMulti R n (M := M)) = LinearMap.id := by ext simp only [alternatingMapLinearEquiv_comp_ιMulti, ιMulti_apply_coe, LinearMap.compAlternatingMap_apply, LinearMap.id_coe, id_eq] /-- If `f` is an alternating map from `M` to `N`, `alternatingMapLinearEquiv f` is the corresponding linear map from `⋀[R]^n M` to `N`, and if `g` is a linear map from `N` to `N'`, then the alternating map `g.compAlternatingMap f` from `M` to `N'` corresponds to the linear map `g.comp (alternatingMapLinearEquiv f)` on `⋀[R]^n M`. -/ lemma alternatingMapLinearEquiv_comp (g : N →ₗ[R] N') (f : M [⋀^Fin n]→ₗ[R] N) : alternatingMapLinearEquiv (g.compAlternatingMap f) = g.comp (alternatingMapLinearEquiv f) := by ext simp only [alternatingMapLinearEquiv_comp_ιMulti, LinearMap.compAlternatingMap_apply, LinearMap.coe_comp, comp_apply, alternatingMapLinearEquiv_apply_ιMulti] /-! Functoriality of the exterior powers. -/ variable (n) in /-- The linear map between `n`th exterior powers induced by a linear map between the modules. -/ noncomputable def map (f : M →ₗ[R] N) : ⋀[R]^n M →ₗ[R] ⋀[R]^n N := alternatingMapLinearEquiv ((ιMulti R n).compLinearMap f) @[simp] lemma alternatingMapLinearEquiv_symm_map (f : M →ₗ[R] N) : alternatingMapLinearEquiv.symm (map n f) = (ιMulti R n).compLinearMap f := by simp only [map, LinearEquiv.symm_apply_apply] @[simp] theorem map_comp_ιMulti (f : M →ₗ[R] N) : (map n f).compAlternatingMap (ιMulti R n) = (ιMulti R n).compLinearMap f := by simp only [map, alternatingMapLinearEquiv_comp_ιMulti] @[simp] theorem map_apply_ιMulti (f : M →ₗ[R] N) (m : Fin n → M) : map n f (ιMulti R n m) = ιMulti R n (f ∘ m) := by simp only [map, alternatingMapLinearEquiv_apply_ιMulti, AlternatingMap.compLinearMap_apply, Function.comp_def] @[simp] lemma map_comp_ιMulti_family {I : Type*} [LinearOrder I] (v : I → M) (f : M →ₗ[R] N) : (map n f) ∘ (ιMulti_family R n v) = ιMulti_family R n (f ∘ v) := by ext ⟨s, hs⟩ simp only [ιMulti_family, Function.comp_apply, map_apply_ιMulti] rfl @[simp] lemma map_apply_ιMulti_family {I : Type*} [LinearOrder I] (v : I → M) (f : M →ₗ[R] N) (s : {s : Finset I // s.card = n}) : (map n f) (ιMulti_family R n v s) = ιMulti_family R n (f ∘ v) s := by simp only [ιMulti_family, map, alternatingMapLinearEquiv_apply_ιMulti] rfl @[simp] theorem map_id : map n (LinearMap.id (R := R) (M := M)) = LinearMap.id := by aesop @[simp] theorem map_comp (f : M →ₗ[R] N) (g : N →ₗ[R] N') : map n (g ∘ₗ f) = map n g ∘ₗ map n f := by aesop /-! Linear equivalences in degrees 0 and 1. -/ variable (R M) in /-- The linear equivalence ` ⋀[R]^0 M ≃ₗ[R] R`. -/ @[simps! -isSimp symm_apply] noncomputable def zeroEquiv : ⋀[R]^0 M ≃ₗ[R] R := LinearEquiv.ofLinear (alternatingMapLinearEquiv (AlternatingMap.constOfIsEmpty R _ _ 1)) { toFun := fun r ↦ r • (ιMulti _ _ (by rintro ⟨i, hi⟩; simp at hi)) map_add' := by intros; simp only [add_smul] map_smul' := by intros; simp only [smul_eq_mul, mul_smul, RingHom.id_apply]} (by aesop) (by aesop) @[simp] lemma zeroEquiv_ιMulti (f : Fin 0 → M) : zeroEquiv R M (ιMulti _ _ f) = 1 := by simp [zeroEquiv] lemma zeroEquiv_naturality (f : M →ₗ[R] N) : (zeroEquiv R N).comp (map 0 f) = zeroEquiv R M := by aesop variable (R M) in /-- The linear equivalence `M ≃ₗ[R] ⋀[R]^1 M`. -/ @[simps! -isSimp symm_apply] noncomputable def oneEquiv : ⋀[R]^1 M ≃ₗ[R] M := LinearEquiv.ofLinear (alternatingMapLinearEquiv (AlternatingMap.ofSubsingleton R M M (0 : Fin 1) .id)) (by have h (m : M) : (fun (_ : Fin 1) ↦ m) = update (fun _ ↦ 0) 0 m := by ext i fin_cases i rfl exact { toFun := fun m ↦ ιMulti _ _ (fun _ ↦ m) map_add' := fun m₁ m₂ ↦ by rw [h]; nth_rw 2 [h]; nth_rw 3 [h] simp only [Fin.isValue, AlternatingMap.map_update_add] map_smul' := fun r m ↦ by dsimp rw [h]; nth_rw 2 [h] simp only [Fin.isValue, AlternatingMap.map_update_smul] }) (by aesop) (by aesop) @[simp] lemma oneEquiv_ιMulti (f : Fin 1 → M) : oneEquiv R M (ιMulti _ _ f) = f 0 := by simp [oneEquiv] lemma oneEquiv_naturality (f : M →ₗ[R] N) : (oneEquiv R N).comp (map 1 f) = f.comp (oneEquiv R M).toLinearMap := by aesop end exteriorPower
.lake/packages/mathlib/Mathlib/LinearAlgebra/ExteriorPower/Pairing.lean
import Mathlib.LinearAlgebra.ExteriorPower.Basic import Mathlib.LinearAlgebra.TensorPower.Pairing /-! # The pairing between the exterior power of the dual and the exterior power We construct the pairing `exteriorPower.pairingDual : ⋀[R]^n (Module.Dual R M) →ₗ[R] (Module.Dual R (⋀[R]^n M))`. -/ namespace exteriorPower open TensorProduct PiTensorProduct variable (R : Type*) (M : Type*) [CommRing R] [AddCommGroup M] [Module R M] /-- The linear map from the `n`th exterior power to the `n`th tensor power obtained by `MultilinearMap.alternatization`. -/ noncomputable def toTensorPower (n : ℕ) : ⋀[R]^n M →ₗ[R] ⨂[R]^n M := alternatingMapLinearEquiv (MultilinearMap.alternatization (PiTensorProduct.tprod R)) variable {M} in open Equiv in @[simp] lemma toTensorPower_apply_ιMulti {n : ℕ} (v : Fin n → M) : toTensorPower R M n (ιMulti R n v) = ∑ σ : Perm (Fin n), Perm.sign σ • PiTensorProduct.tprod R (fun i ↦ v (σ i)) := by dsimp [toTensorPower] simp only [alternatingMapLinearEquiv_apply_ιMulti, MultilinearMap.alternatization_apply, MultilinearMap.domDomCongr_apply] /-- The canonical `n`-alternating map from the dual of the `R`-module `M` to the dual of `⨂[R]^n M`. -/ noncomputable def alternatingMapToDual (n : ℕ) : AlternatingMap R (Module.Dual R M) (Module.Dual R (⋀[R]^n M)) (Fin n) where toMultilinearMap := (toTensorPower R M n).dualMap.compMultilinearMap (TensorPower.multilinearMapToDual R M n) map_eq_zero_of_eq' f i j hf hij := by ext v suffices Matrix.det (n := Fin n) (.of (fun i j ↦ f j (v i))) = 0 by simpa [Matrix.det_apply] using this exact Matrix.det_zero_of_column_eq hij (by simp [hf]) variable {R M} in open Equiv in @[simp] theorem alternatingMapToDual_apply_ιMulti {n : ℕ} (f : (_ : Fin n) → Module.Dual R M) (v : Fin n → M) : alternatingMapToDual R M n f (ιMulti _ _ v) = Matrix.det (n := Fin n) (.of (fun i j ↦ f j (v i))) := by simp [alternatingMapToDual, Matrix.det_apply] /-- The linear map from the exterior power of the dual to the dual of the exterior power. -/ noncomputable def pairingDual (n : ℕ) : ⋀[R]^n (Module.Dual R M) →ₗ[R] Module.Dual R (⋀[R]^n M) := alternatingMapLinearEquiv (alternatingMapToDual R M n) variable {R M} in open Equiv in @[simp] lemma pairingDual_ιMulti_ιMulti {n : ℕ} (f : (_ : Fin n) → Module.Dual R M) (v : Fin n → M) : pairingDual R M n (ιMulti _ _ f) (ιMulti _ _ v) = Matrix.det (n := Fin n) (.of (fun i j ↦ f j (v i))) := by simp [pairingDual] section /-! If a `R`-module `M` has a family of vectors `x : ι → M` and linear maps `f : ι → M` such that `f i (x j)` is `1` or `0` depending on `i = j` or `i ≠ j`, then if `ι` has a linear order, then a similar property regarding `pairingDual R M n` applies to the family of vectors indexed by `Fin n ↪o ι` in `⋀[R]^n M` and in `⋀[R]^n (Module.Dual R M)` that are obtained by taking exterior products of the `x i` and the `f j`. (This shall be used in order to construct a basis of `⋀[R]^n M` when `M` is a free module.) -/ variable {R M} {ι : Type*} [LinearOrder ι] (x : ι → M) (f : ι → Module.Dual R M) (h₁ : ∀ i, f i (x i) = 1) (h₀ : ∀ ⦃i j⦄, i ≠ j → f i (x j) = 0) (n : ℕ) include h₁ h₀ in lemma pairingDual_apply_apply_eq_one (a : Fin n ↪o ι) : pairingDual R M n (ιMulti _ _ (f ∘ a)) (ιMulti _ _ (x ∘ a)) = 1 := by simp only [pairingDual_ιMulti_ιMulti, Function.comp_apply] rw [← Matrix.det_one (n := Fin n)] congr ext i j dsimp by_cases hij : i = j · subst hij simp only [h₁, Matrix.one_apply_eq] · rw [h₀ (by simpa using Ne.symm hij), Matrix.one_apply_ne hij] include h₀ in lemma pairingDual_apply_apply_eq_one_zero (a b : Fin n ↪o ι) (h : a ≠ b) : pairingDual R M n (ιMulti _ _ (f ∘ a)) (ιMulti _ _ (x ∘ b)) = 0 := by simp only [pairingDual_ιMulti_ιMulti, Function.comp_apply, Matrix.det_apply] refine Finset.sum_eq_zero (fun σ _ ↦ ?_) simp only [Matrix.of_apply, smul_eq_iff_eq_inv_smul, smul_zero] by_contra h' apply h have : a = b ∘ σ := by ext i by_contra hi exact h' (Finset.prod_eq_zero (i := i) (by simp) (h₀ hi)) have hσ : Monotone σ := fun i j hij ↦ by have h'' := congr_fun this dsimp at h'' rw [← a.map_rel_iff] at hij simpa only [← b.map_rel_iff, ← h''] have hσ' : Monotone σ.symm := fun i j hij ↦ by obtain ⟨i, rfl⟩ := σ.surjective i obtain ⟨j, rfl⟩ := σ.surjective j simp only [Equiv.symm_apply_apply] by_contra! h obtain rfl : i = j := σ.injective (le_antisymm hij (hσ h.le)) simp only [lt_self_iff_false] at h obtain rfl : σ = 1 := by ext i : 1 exact DFunLike.congr_fun (Subsingleton.elim (σ.toOrderIso hσ hσ') (OrderIso.refl _)) i ext apply congr_fun this end end exteriorPower
.lake/packages/mathlib/Mathlib/LinearAlgebra/AffineSpace/Midpoint.lean
import Mathlib.Algebra.Module.Basic import Mathlib.LinearAlgebra.AffineSpace.AffineEquiv /-! # Midpoint of a segment ## Main definitions * `midpoint R x y`: midpoint of the segment `[x, y]`. We define it for `x` and `y` in a module over a ring `R` with invertible `2`. * `AddMonoidHom.ofMapMidpoint`: construct an `AddMonoidHom` given a map `f` such that `f` sends zero to zero and midpoints to midpoints. ## Main theorems * `midpoint_eq_iff`: `z` is the midpoint of `[x, y]` if and only if `x + y = z + z`, * `midpoint_unique`: `midpoint R x y` does not depend on `R`; * `midpoint x y` is linear both in `x` and `y`; * `pointReflection_midpoint_left`, `pointReflection_midpoint_right`: `Equiv.pointReflection (midpoint R x y)` swaps `x` and `y`. We do not mark most lemmas as `@[simp]` because it is hard to tell which side is simpler. ## Tags midpoint, AddMonoidHom -/ open AffineMap AffineEquiv section variable (R : Type*) {V V' P P' : Type*} [Ring R] [Invertible (2 : R)] [AddCommGroup V] [Module R V] [AddTorsor V P] [AddCommGroup V'] [Module R V'] [AddTorsor V' P'] /-- `midpoint x y` is the midpoint of the segment `[x, y]`. -/ def midpoint (x y : P) : P := lineMap x y (⅟2 : R) variable {R} {x y z : P} @[simp] theorem AffineMap.map_midpoint (f : P →ᵃ[R] P') (a b : P) : f (midpoint R a b) = midpoint R (f a) (f b) := f.apply_lineMap a b _ @[simp] theorem AffineEquiv.map_midpoint (f : P ≃ᵃ[R] P') (a b : P) : f (midpoint R a b) = midpoint R (f a) (f b) := f.apply_lineMap a b _ theorem AffineEquiv.pointReflection_midpoint_left (x y : P) : pointReflection R (midpoint R x y) x = y := by rw [midpoint, pointReflection_apply, lineMap_apply, vadd_vsub, vadd_vadd, ← add_smul, ← two_mul, mul_invOf_self, one_smul, vsub_vadd] @[simp] theorem Equiv.pointReflection_midpoint_left (x y : P) : (Equiv.pointReflection (midpoint R x y)) x = y := by rw [midpoint, pointReflection_apply, lineMap_apply, vadd_vsub, vadd_vadd, ← add_smul, ← two_mul, mul_invOf_self, one_smul, vsub_vadd] theorem midpoint_comm (x y : P) : midpoint R x y = midpoint R y x := by rw [midpoint, ← lineMap_apply_one_sub, one_sub_invOf_two, midpoint] theorem AffineEquiv.pointReflection_midpoint_right (x y : P) : pointReflection R (midpoint R x y) y = x := by rw [midpoint_comm, AffineEquiv.pointReflection_midpoint_left] @[simp] theorem Equiv.pointReflection_midpoint_right (x y : P) : (Equiv.pointReflection (midpoint R x y)) y = x := by rw [midpoint_comm, Equiv.pointReflection_midpoint_left] theorem midpoint_vsub_midpoint (p₁ p₂ p₃ p₄ : P) : midpoint R p₁ p₂ -ᵥ midpoint R p₃ p₄ = midpoint R (p₁ -ᵥ p₃) (p₂ -ᵥ p₄) := lineMap_vsub_lineMap _ _ _ _ _ theorem midpoint_vadd_midpoint (v v' : V) (p p' : P) : midpoint R v v' +ᵥ midpoint R p p' = midpoint R (v +ᵥ p) (v' +ᵥ p') := lineMap_vadd_lineMap _ _ _ _ _ theorem midpoint_eq_iff {x y z : P} : midpoint R x y = z ↔ pointReflection R z x = y := eq_comm.trans ((injective_pointReflection_left_of_module R x).eq_iff' (AffineEquiv.pointReflection_midpoint_left x y)).symm @[simp] theorem midpoint_pointReflection_left (x y : P) : midpoint R (Equiv.pointReflection x y) y = x := midpoint_eq_iff.2 <| Equiv.pointReflection_involutive _ _ @[simp] theorem midpoint_pointReflection_right (x y : P) : midpoint R y (Equiv.pointReflection x y) = x := midpoint_eq_iff.2 rfl nonrec lemma AffineEquiv.midpoint_pointReflection_left (x y : P) : midpoint R (pointReflection R x y) y = x := midpoint_pointReflection_left x y nonrec lemma AffineEquiv.midpoint_pointReflection_right (x y : P) : midpoint R y (pointReflection R x y) = x := midpoint_pointReflection_right x y @[simp] theorem midpoint_vsub_left (p₁ p₂ : P) : midpoint R p₁ p₂ -ᵥ p₁ = (⅟2 : R) • (p₂ -ᵥ p₁) := lineMap_vsub_left _ _ _ @[simp] theorem midpoint_vsub_right (p₁ p₂ : P) : midpoint R p₁ p₂ -ᵥ p₂ = (⅟2 : R) • (p₁ -ᵥ p₂) := by rw [midpoint_comm, midpoint_vsub_left] @[simp] theorem left_vsub_midpoint (p₁ p₂ : P) : p₁ -ᵥ midpoint R p₁ p₂ = (⅟2 : R) • (p₁ -ᵥ p₂) := left_vsub_lineMap _ _ _ @[simp] theorem right_vsub_midpoint (p₁ p₂ : P) : p₂ -ᵥ midpoint R p₁ p₂ = (⅟2 : R) • (p₂ -ᵥ p₁) := by rw [midpoint_comm, left_vsub_midpoint] theorem midpoint_vsub (p₁ p₂ p : P) : midpoint R p₁ p₂ -ᵥ p = (⅟2 : R) • (p₁ -ᵥ p) + (⅟2 : R) • (p₂ -ᵥ p) := by rw [← vsub_sub_vsub_cancel_right p₁ p p₂, smul_sub, sub_eq_add_neg, ← smul_neg, neg_vsub_eq_vsub_rev, add_assoc, invOf_two_smul_add_invOf_two_smul, ← vadd_vsub_assoc, midpoint_comm, midpoint, lineMap_apply] theorem vsub_midpoint (p₁ p₂ p : P) : p -ᵥ midpoint R p₁ p₂ = (⅟2 : R) • (p -ᵥ p₁) + (⅟2 : R) • (p -ᵥ p₂) := by rw [← neg_vsub_eq_vsub_rev, midpoint_vsub, neg_add, ← smul_neg, ← smul_neg, neg_vsub_eq_vsub_rev, neg_vsub_eq_vsub_rev] @[simp] theorem midpoint_sub_left (v₁ v₂ : V) : midpoint R v₁ v₂ - v₁ = (⅟2 : R) • (v₂ - v₁) := midpoint_vsub_left v₁ v₂ @[simp] theorem midpoint_sub_right (v₁ v₂ : V) : midpoint R v₁ v₂ - v₂ = (⅟2 : R) • (v₁ - v₂) := midpoint_vsub_right v₁ v₂ @[simp] theorem left_sub_midpoint (v₁ v₂ : V) : v₁ - midpoint R v₁ v₂ = (⅟2 : R) • (v₁ - v₂) := left_vsub_midpoint v₁ v₂ @[simp] theorem right_sub_midpoint (v₁ v₂ : V) : v₂ - midpoint R v₁ v₂ = (⅟2 : R) • (v₂ - v₁) := right_vsub_midpoint v₁ v₂ variable (R) @[simp] theorem midpoint_eq_left_iff {x y : P} : midpoint R x y = x ↔ x = y := by rw [midpoint_eq_iff, pointReflection_self] @[simp] theorem left_eq_midpoint_iff {x y : P} : x = midpoint R x y ↔ x = y := by rw [eq_comm, midpoint_eq_left_iff] @[simp] theorem midpoint_eq_right_iff {x y : P} : midpoint R x y = y ↔ x = y := by rw [midpoint_comm, midpoint_eq_left_iff, eq_comm] @[simp] theorem right_eq_midpoint_iff {x y : P} : y = midpoint R x y ↔ x = y := by rw [eq_comm, midpoint_eq_right_iff] theorem midpoint_eq_midpoint_iff_vsub_eq_vsub {x x' y y' : P} : midpoint R x y = midpoint R x' y' ↔ x -ᵥ x' = y' -ᵥ y := by rw [← @vsub_eq_zero_iff_eq V, midpoint_vsub_midpoint, midpoint_eq_iff, pointReflection_apply, vsub_eq_sub, zero_sub, vadd_eq_add, add_zero, neg_eq_iff_eq_neg, neg_vsub_eq_vsub_rev] theorem midpoint_eq_iff' {x y z : P} : midpoint R x y = z ↔ Equiv.pointReflection z x = y := midpoint_eq_iff /-- `midpoint` does not depend on the ring `R`. -/ theorem midpoint_unique (R' : Type*) [Ring R'] [Invertible (2 : R')] [Module R' V] (x y : P) : midpoint R x y = midpoint R' x y := (midpoint_eq_iff' R).2 <| (midpoint_eq_iff' R').1 rfl @[simp] theorem midpoint_self (x : P) : midpoint R x x = x := lineMap_same_apply _ _ @[simp] theorem midpoint_add_self (x y : V) : midpoint R x y + midpoint R x y = x + y := calc midpoint R x y +ᵥ midpoint R x y = midpoint R x y +ᵥ midpoint R y x := by rw [midpoint_comm] _ = x + y := by rw [midpoint_vadd_midpoint, vadd_eq_add, vadd_eq_add, add_comm, midpoint_self] theorem midpoint_zero_add (x y : V) : midpoint R 0 (x + y) = midpoint R x y := (midpoint_eq_midpoint_iff_vsub_eq_vsub R).2 <| by simp theorem midpoint_eq_smul_add (x y : V) : midpoint R x y = (⅟2 : R) • (x + y) := by rw [midpoint_eq_iff, pointReflection_apply, vsub_eq_sub, vadd_eq_add, sub_add_eq_add_sub, ← two_smul R, smul_smul, mul_invOf_self, one_smul, add_sub_cancel_left] @[simp] theorem midpoint_self_neg (x : V) : midpoint R x (-x) = 0 := by rw [midpoint_eq_smul_add, add_neg_cancel, smul_zero] @[simp] theorem midpoint_neg_self (x : V) : midpoint R (-x) x = 0 := by simpa using midpoint_self_neg R (-x) @[simp] theorem midpoint_sub_add (x y : V) : midpoint R (x - y) (x + y) = x := by rw [sub_eq_add_neg, ← vadd_eq_add, ← vadd_eq_add, ← midpoint_vadd_midpoint]; simp @[simp] theorem midpoint_add_sub (x y : V) : midpoint R (x + y) (x - y) = x := by rw [midpoint_comm]; simp theorem midpoint_vsub_midpoint_same_left (p₁ p₂ p₃ : P) : midpoint R p₁ p₂ -ᵥ midpoint R p₁ p₃ = (⅟ 2 : R) • (p₂ -ᵥ p₃) := by rw [midpoint_vsub_midpoint, vsub_self, midpoint_eq_smul_add, zero_add] theorem midpoint_vsub_midpoint_same_right (p₁ p₂ p₃ : P) : midpoint R p₁ p₃ -ᵥ midpoint R p₂ p₃ = (⅟ 2 : R) • (p₁ -ᵥ p₂) := by rw [midpoint_vsub_midpoint, vsub_self, midpoint_eq_smul_add, add_zero] end namespace AddMonoidHom variable (R R' : Type*) {E F : Type*} [Ring R] [Invertible (2 : R)] [AddCommGroup E] [Module R E] [Ring R'] [Invertible (2 : R')] [AddCommGroup F] [Module R' F] /-- A map `f : E → F` sending zero to zero and midpoints to midpoints is an `AddMonoidHom`. -/ def ofMapMidpoint (f : E → F) (h0 : f 0 = 0) (hm : ∀ x y, f (midpoint R x y) = midpoint R' (f x) (f y)) : E →+ F where toFun := f map_zero' := h0 map_add' x y := calc f (x + y) = f 0 + f (x + y) := by rw [h0, zero_add] _ = midpoint R' (f 0) (f (x + y)) + midpoint R' (f 0) (f (x + y)) := (midpoint_add_self _ _ _).symm _ = f (midpoint R x y) + f (midpoint R x y) := by rw [← hm, midpoint_zero_add] _ = f x + f y := by rw [hm, midpoint_add_self] @[simp] theorem coe_ofMapMidpoint (f : E → F) (h0 : f 0 = 0) (hm : ∀ x y, f (midpoint R x y) = midpoint R' (f x) (f y)) : ⇑(ofMapMidpoint R R' f h0 hm) = f := rfl end AddMonoidHom
.lake/packages/mathlib/Mathlib/LinearAlgebra/AffineSpace/Matrix.lean
import Mathlib.LinearAlgebra.AffineSpace.Basis import Mathlib.LinearAlgebra.Matrix.NonsingularInverse /-! # Matrix results for barycentric co-ordinates Results about the matrix of barycentric co-ordinates for a family of points in an affine space, with respect to some affine basis. -/ open Affine Matrix open Set universe u₁ u₂ u₃ u₄ variable {ι : Type u₁} {k : Type u₂} {V : Type u₃} {P : Type u₄} variable [AddCommGroup V] [AffineSpace V P] namespace AffineBasis section Ring variable [Ring k] [Module k V] (b : AffineBasis ι k P) /-- Given an affine basis `p`, and a family of points `q : ι' → P`, this is the matrix whose rows are the barycentric coordinates of `q` with respect to `p`. It is an affine equivalent of `Basis.toMatrix`. -/ noncomputable def toMatrix {ι' : Type*} (q : ι' → P) : Matrix ι' ι k := fun i j => b.coord j (q i) @[simp] theorem toMatrix_apply {ι' : Type*} (q : ι' → P) (i : ι') (j : ι) : b.toMatrix q i j = b.coord j (q i) := rfl @[simp] theorem toMatrix_self [DecidableEq ι] : b.toMatrix b = (1 : Matrix ι ι k) := by ext i j rw [toMatrix_apply, coord_apply, Matrix.one_eq_pi_single, Pi.single_apply] variable {ι' : Type*} theorem toMatrix_row_sum_one [Fintype ι] (q : ι' → P) (i : ι') : ∑ j, b.toMatrix q i j = 1 := by simp /-- Given a family of points `p : ι' → P` and an affine basis `b`, if the matrix whose rows are the coordinates of `p` with respect `b` has a right inverse, then `p` is affine independent. -/ theorem affineIndependent_of_toMatrix_right_inv [Fintype ι] [Finite ι'] [DecidableEq ι'] (p : ι' → P) {A : Matrix ι ι' k} (hA : b.toMatrix p * A = 1) : AffineIndependent k p := by cases nonempty_fintype ι' rw [affineIndependent_iff_eq_of_fintype_affineCombination_eq] intro w₁ w₂ hw₁ hw₂ hweq have hweq' : w₁ ᵥ* b.toMatrix p = w₂ ᵥ* b.toMatrix p := by ext j change (∑ i, w₁ i • b.coord j (p i)) = ∑ i, w₂ i • b.coord j (p i) rw [← Finset.univ.affineCombination_eq_linear_combination _ _ hw₁, ← Finset.univ.affineCombination_eq_linear_combination _ _ hw₂, ← Function.comp_def (b.coord j) p, ← Finset.univ.map_affineCombination p w₁ hw₁, ← Finset.univ.map_affineCombination p w₂ hw₂, hweq] replace hweq' := congr_arg (fun w => w ᵥ* A) hweq' simpa only [Matrix.vecMul_vecMul, hA, Matrix.vecMul_one] using hweq' /-- Given a family of points `p : ι' → P` and an affine basis `b`, if the matrix whose rows are the coordinates of `p` with respect `b` has a left inverse, then `p` spans the entire space. -/ theorem affineSpan_eq_top_of_toMatrix_left_inv [Finite ι] [Fintype ι'] [DecidableEq ι] [Nontrivial k] (p : ι' → P) {A : Matrix ι ι' k} (hA : A * b.toMatrix p = 1) : affineSpan k (range p) = ⊤ := by cases nonempty_fintype ι suffices ∀ i, b i ∈ affineSpan k (range p) by rw [eq_top_iff, ← b.tot, affineSpan_le] rintro q ⟨i, rfl⟩ exact this i intro i have hAi : ∑ j, A i j = 1 := by calc ∑ j, A i j = ∑ j, A i j * ∑ l, b.toMatrix p j l := by simp _ = ∑ j, ∑ l, A i j * b.toMatrix p j l := by simp_rw [Finset.mul_sum] _ = ∑ l, ∑ j, A i j * b.toMatrix p j l := by rw [Finset.sum_comm] _ = ∑ l, (A * b.toMatrix p) i l := rfl _ = 1 := by simp [hA, Matrix.one_apply] have hbi : b i = Finset.univ.affineCombination k p (A i) := by apply b.ext_elem intro j rw [b.coord_apply, Finset.univ.map_affineCombination _ _ hAi, Finset.univ.affineCombination_eq_linear_combination _ _ hAi] change _ = (A * b.toMatrix p) i j simp_rw [hA, Matrix.one_apply, @eq_comm _ i j] rw [hbi] exact affineCombination_mem_affineSpan hAi p variable [Fintype ι] (b₂ : AffineBasis ι k P) /-- A change of basis formula for barycentric coordinates. See also `AffineBasis.toMatrix_inv_vecMul_toMatrix`. -/ @[simp] theorem toMatrix_vecMul_coords (x : P) : b₂.coords x ᵥ* b.toMatrix b₂ = b.coords x := by ext j change _ = b.coord j x conv_rhs => rw [← b₂.affineCombination_coord_eq_self x] rw [Finset.map_affineCombination _ _ _ (b₂.sum_coord_apply_eq_one x)] simp [Matrix.vecMul, dotProduct, toMatrix_apply, coords] variable [DecidableEq ι] theorem toMatrix_mul_toMatrix : b.toMatrix b₂ * b₂.toMatrix b = 1 := by ext l m change (b.coords (b₂ l) ᵥ* b₂.toMatrix b) m = _ rw [toMatrix_vecMul_coords, coords_apply, ← toMatrix_apply, toMatrix_self] theorem isUnit_toMatrix : IsUnit (b.toMatrix b₂) := ⟨{ val := b.toMatrix b₂ inv := b₂.toMatrix b val_inv := b.toMatrix_mul_toMatrix b₂ inv_val := b₂.toMatrix_mul_toMatrix b }, rfl⟩ theorem isUnit_toMatrix_iff [Nontrivial k] (p : ι → P) : IsUnit (b.toMatrix p) ↔ AffineIndependent k p ∧ affineSpan k (range p) = ⊤ := by constructor · rintro ⟨⟨B, A, hA, hA'⟩, rfl : B = b.toMatrix p⟩ exact ⟨b.affineIndependent_of_toMatrix_right_inv p hA, b.affineSpan_eq_top_of_toMatrix_left_inv p hA'⟩ · rintro ⟨h_tot, h_ind⟩ let b' : AffineBasis ι k P := ⟨p, h_tot, h_ind⟩ change IsUnit (b.toMatrix b') exact b.isUnit_toMatrix b' end Ring section CommRing variable [CommRing k] [Module k V] [DecidableEq ι] [Fintype ι] variable (b b₂ : AffineBasis ι k P) /-- A change of basis formula for barycentric coordinates. See also `AffineBasis.toMatrix_vecMul_coords`. -/ @[simp] theorem toMatrix_inv_vecMul_toMatrix (x : P) : b.coords x ᵥ* (b.toMatrix b₂)⁻¹ = b₂.coords x := by have hu := b.isUnit_toMatrix b₂ rw [Matrix.isUnit_iff_isUnit_det] at hu rw [← b.toMatrix_vecMul_coords b₂, Matrix.vecMul_vecMul, Matrix.mul_nonsing_inv _ hu, Matrix.vecMul_one] /-- If we fix a background affine basis `b`, then for any other basis `b₂`, we can characterise the barycentric coordinates provided by `b₂` in terms of determinants relative to `b`. -/ theorem det_smul_coords_eq_cramer_coords (x : P) : (b.toMatrix b₂).det • b₂.coords x = (b.toMatrix b₂)ᵀ.cramer (b.coords x) := by have hu := b.isUnit_toMatrix b₂ rw [Matrix.isUnit_iff_isUnit_det] at hu rw [← b.toMatrix_inv_vecMul_toMatrix, Matrix.det_smul_inv_vecMul_eq_cramer_transpose _ _ hu] end CommRing end AffineBasis