/- Copyright (c) 2024 Joseph Tooby-Smith. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Tooby-Smith -/ import HepLean.SpaceTime.LorentzTensor.MulActionTensor /-! # Contraction of indices We define a number of ways to contract indices of tensors: - `contrDualLeft`: Contracts vectors on the left as: `๐“ฃ.ColorModule ฮฝ โŠ—[R] ๐“ฃ.ColorModule (๐“ฃ.ฯ„ ฮฝ) โŠ—[R] ๐“ฃ.ColorModule ฮท โ†’โ‚—[R] ๐“ฃ.ColorModule ฮท` - `contrDualMid`: Contracts vectors in the middle as: `(๐“ฃ.ColorModule ฮผ โŠ—[R] ๐“ฃ.ColorModule ฮฝ) โŠ—[R] (๐“ฃ.ColorModule (๐“ฃ.ฯ„ ฮฝ) โŠ—[R] ๐“ฃ.ColorModule ฮท) โ†’โ‚—[R]` `๐“ฃ.ColorModule ฮผ โŠ—[R] ๐“ฃ.ColorModule ฮท` - `contrAll'`: Contracts all indices of manifestly tensors with manifestly dual colors as: `๐“ฃ.Tensor cX โŠ—[R] ๐“ฃ.Tensor (๐“ฃ.ฯ„ โˆ˜ cX) โ†’โ‚—[R] R` - `contrAll`: Contracts all indices of tensors with dual colors as: `๐“ฃ.Tensor cX โŠ—[R] ๐“ฃ.Tensor cY โ†’โ‚—[R] R` - `contrAllLeft`: Contracts all indices of tensors on the left as: `๐“ฃ.Tensor cX โŠ—[R] ๐“ฃ.Tensor cY โŠ—[R] ๐“ฃ.Tensor cZ โ†’โ‚—[R] ๐“ฃ.Tensor cZ` - `contrElim`: Contracting indices of tensors indexed by `Sum.elim _ _` as: `๐“ฃ.Tensor (Sum.elim cW cX) โŠ—[R] ๐“ฃ.Tensor (Sum.elim cY cZ) โ†’โ‚—[R] ๐“ฃ.Tensor (Sum.elim cW cZ)` -/ noncomputable section open TensorProduct open MulActionTensor variable {R : Type} [CommSemiring R] namespace TensorColor variable {d : โ„•} {X X' Y Y' Z W : Type} [Fintype X] [DecidableEq X] [Fintype Y] [DecidableEq Y] [Fintype Y'] [DecidableEq Y'] [Fintype Z] [DecidableEq Z] [Fintype W] [DecidableEq W] variable {d : โ„•} {X Y Y' Z W C P : Type} [Fintype X] [DecidableEq X] [Fintype Y] [DecidableEq Y] [Fintype Y'] [DecidableEq Y'] [Fintype Z] [DecidableEq Z] [Fintype W] [DecidableEq W] [Fintype C] [DecidableEq C] [Fintype P] [DecidableEq P] namespace ColorMap variable {๐“’ : TensorColor} [Fintype ๐“’.Color] [DecidableEq ๐“’.Color] variable (cX : ColorMap ๐“’ X) (cY : ColorMap ๐“’ Y) (cZ : ColorMap ๐“’ Z) /-- Given an equivalence `e` of types the condition that the color map `cX` is the dual to `cY` up to this equivalence. -/ def ContrAll (e : X โ‰ƒ Y) (cX : ColorMap ๐“’ X) (cY : ColorMap ๐“’ Y) : Prop := cX = ๐“’.ฯ„ โˆ˜ cY โˆ˜ e namespace ContrAll variable {e : X โ‰ƒ Y} {e' : Y โ‰ƒ Z} {cX : ColorMap ๐“’ X} {cY : ColorMap ๐“’ Y} {cZ : ColorMap ๐“’ Z} variable {cX' : ColorMap ๐“’ X'} {cY' : ColorMap ๐“’ Y'} lemma toMapIso (h : cX.ContrAll e cY) : cX.MapIso e cY.dual := by subst h rfl lemma symm (h : cX.ContrAll e cY) : cY.ContrAll e.symm cX := by subst h funext x simp only [Function.comp_apply, Equiv.apply_symm_apply] exact (๐“’.ฯ„_involutive (cY x)).symm lemma trans_mapIso {e : X โ‰ƒ Y} {e' : Z โ‰ƒ Y} (h : cX.ContrAll e cY) (h' : cZ.MapIso e' cY) : cX.ContrAll (e.trans e'.symm) cZ := by subst h h' funext x simp only [Function.comp_apply, Equiv.coe_trans, Equiv.apply_symm_apply] lemma mapIso_trans {e : X โ‰ƒ Y} {e' : Z โ‰ƒ X} (h : cX.ContrAll e cY) (h' : cZ.MapIso e' cX) : cZ.ContrAll (e'.trans e) cY := by subst h h' rfl end ContrAll /-- Given an equivalence `(C โŠ• C) โŠ• P โ‰ƒ X` the restriction of a color map `cX` on to `P`. -/ def contr (e : (C โŠ• C) โŠ• P โ‰ƒ X) (cX : ColorMap ๐“’ X) : ColorMap ๐“’ P := cX โˆ˜ e โˆ˜ Sum.inr /-- Given an equivalence `(C โŠ• C) โŠ• P โ‰ƒ X` the restriction of a color map `cX` on `X` to the first `C`. -/ def contrLeft (e : (C โŠ• C) โŠ• P โ‰ƒ X) (cX : ColorMap ๐“’ X) : ColorMap ๐“’ C := cX โˆ˜ e โˆ˜ Sum.inl โˆ˜ Sum.inl /-- Given an equivalence `(C โŠ• C) โŠ• P โ‰ƒ X` the restriction of a color map `cX` on `X` to the second `C`. -/ def contrRight (e : (C โŠ• C) โŠ• P โ‰ƒ X) (cX : ColorMap ๐“’ X) : ColorMap ๐“’ C := cX โˆ˜ e โˆ˜ Sum.inl โˆ˜ Sum.inr /-- Given an equivalence `(C โŠ• C) โŠ• P โ‰ƒ X` the condition on `cX` so that we contract the indices of the `C`'s under this equivalence. -/ def ContrCond (e : (C โŠ• C) โŠ• P โ‰ƒ X) (cX : ColorMap ๐“’ X) : Prop := cX โˆ˜ e โˆ˜ Sum.inl โˆ˜ Sum.inl = ๐“’.ฯ„ โˆ˜ cX โˆ˜ e โˆ˜ Sum.inl โˆ˜ Sum.inr namespace ContrCond variable {e : (C โŠ• C) โŠ• P โ‰ƒ X} {e' : Y โ‰ƒ Z} {cX : ColorMap ๐“’ X} {cY : ColorMap ๐“’ Y} {cZ : ColorMap ๐“’ Z} variable {cX' : ColorMap ๐“’ X'} {cY' : ColorMap ๐“’ Y'} lemma to_contrAll (h : cX.ContrCond e) : (cX.contrLeft e).ContrAll (Equiv.refl _) (cX.contrRight e) := h end ContrCond end ColorMap end TensorColor namespace TensorStructure variable (๐“ฃ : TensorStructure R) variable {d : โ„•} {X Y Y' Z W C P : Type} [Fintype X] [DecidableEq X] [Fintype Y] [DecidableEq Y] [Fintype Y'] [DecidableEq Y'] [Fintype Z] [DecidableEq Z] [Fintype W] [DecidableEq W] [Fintype C] [DecidableEq C] [Fintype P] [DecidableEq P] {cX cX2 : ๐“ฃ.ColorMap X} {cY : ๐“ฃ.ColorMap Y} {cZ : ๐“ฃ.ColorMap Z} {cW : ๐“ฃ.ColorMap W} {cY' : ๐“ฃ.ColorMap Y'} {ฮผ ฮฝ: ๐“ฃ.Color} variable {G H : Type} [Group G] [Group H] [MulActionTensor G ๐“ฃ] local infixl:101 " โ€ข " => ๐“ฃ.rep /-! # Contractions of vectors -/ /-- The contraction of a vector in `๐“ฃ.ColorModule ฮฝ` with a vector in `๐“ฃ.ColorModule (๐“ฃ.ฯ„ ฮฝ) โŠ—[R] ๐“ฃ.ColorModule ฮท` to form a vector in `๐“ฃ.ColorModule ฮท`. -/ def contrDualLeft {ฮฝ ฮท : ๐“ฃ.Color} : ๐“ฃ.ColorModule ฮฝ โŠ—[R] ๐“ฃ.ColorModule (๐“ฃ.ฯ„ ฮฝ) โŠ—[R] ๐“ฃ.ColorModule ฮท โ†’โ‚—[R] ๐“ฃ.ColorModule ฮท := contrLeftAux (๐“ฃ.contrDual ฮฝ) /-- The contraction of a vector in `๐“ฃ.ColorModule ฮผ โŠ—[R] ๐“ฃ.ColorModule ฮฝ` with a vector in `๐“ฃ.ColorModule (๐“ฃ.ฯ„ ฮฝ) โŠ—[R] ๐“ฃ.ColorModule ฮท` to form a vector in `๐“ฃ.ColorModule ฮผ โŠ—[R] ๐“ฃ.ColorModule ฮท`. -/ def contrDualMid {ฮผ ฮฝ ฮท : ๐“ฃ.Color} : (๐“ฃ.ColorModule ฮผ โŠ—[R] ๐“ฃ.ColorModule ฮฝ) โŠ—[R] (๐“ฃ.ColorModule (๐“ฃ.ฯ„ ฮฝ) โŠ—[R] ๐“ฃ.ColorModule ฮท) โ†’โ‚—[R] ๐“ฃ.ColorModule ฮผ โŠ—[R] ๐“ฃ.ColorModule ฮท := contrMidAux (๐“ฃ.contrDual ฮฝ) /-- A linear map taking tensors mapped with the same index set to the product of paired tensors. -/ def pairProd : ๐“ฃ.Tensor cX โŠ—[R] ๐“ฃ.Tensor cX2 โ†’โ‚—[R] โจ‚[R] x, ๐“ฃ.ColorModule (cX x) โŠ—[R] ๐“ฃ.ColorModule (cX2 x) := TensorProduct.lift ( PiTensorProduct.mapโ‚‚ (fun x => TensorProduct.mk R (๐“ฃ.ColorModule (cX x)) (๐“ฃ.ColorModule (cX2 x)))) lemma pairProd_tmul_tprod_tprod (fx : (i : X) โ†’ ๐“ฃ.ColorModule (cX i)) (fx2 : (i : X) โ†’ ๐“ฃ.ColorModule (cX2 i)) : ๐“ฃ.pairProd (PiTensorProduct.tprod R fx โŠ—โ‚œ[R] PiTensorProduct.tprod R fx2) = PiTensorProduct.tprod R (fun x => fx x โŠ—โ‚œ[R] fx2 x) := by simp [pairProd] erw [PiTensorProduct.mapโ‚‚_tprod_tprod] rfl lemma mkPiAlgebra_equiv (e : X โ‰ƒ Y) : (PiTensorProduct.lift (MultilinearMap.mkPiAlgebra R X R)) = (PiTensorProduct.lift (MultilinearMap.mkPiAlgebra R Y R)) โˆ˜โ‚— (PiTensorProduct.reindex R _ e).toLinearMap := by apply PiTensorProduct.ext apply MultilinearMap.ext intro x simp only [LinearMap.compMultilinearMap_apply, PiTensorProduct.lift.tprod, MultilinearMap.mkPiAlgebra_apply, LinearMap.coe_comp, LinearEquiv.coe_coe, Function.comp_apply, PiTensorProduct.reindex_tprod, Equiv.prod_comp] /-- Given a tensor in `๐“ฃ.Tensor cX` and a tensor in `๐“ฃ.Tensor (๐“ฃ.ฯ„ โˆ˜ cX)`, the element of `R` formed by contracting all of their indices. -/ def contrAll' : ๐“ฃ.Tensor cX โŠ—[R] ๐“ฃ.Tensor (๐“ฃ.ฯ„ โˆ˜ cX) โ†’โ‚—[R] R := (PiTensorProduct.lift (MultilinearMap.mkPiAlgebra R X R)) โˆ˜โ‚— (PiTensorProduct.map (fun x => ๐“ฃ.contrDual (cX x))) โˆ˜โ‚— (๐“ฃ.pairProd) lemma contrAll'_tmul_tprod_tprod (fx : (i : X) โ†’ ๐“ฃ.ColorModule (cX i)) (fy : (i : X) โ†’ ๐“ฃ.ColorModule (๐“ฃ.ฯ„ (cX i))) : ๐“ฃ.contrAll' (PiTensorProduct.tprod R fx โŠ—โ‚œ[R] PiTensorProduct.tprod R fy) = (PiTensorProduct.lift (MultilinearMap.mkPiAlgebra R X R)) (PiTensorProduct.tprod R (fun x => ๐“ฃ.contrDual (cX x) (fx x โŠ—โ‚œ[R] fy x))) := by simp only [contrAll', Function.comp_apply, LinearMap.coe_comp, PiTensorProduct.lift.tprod, MultilinearMap.mkPiAlgebra_apply] erw [pairProd_tmul_tprod_tprod] simp only [Function.comp_apply, PiTensorProduct.map_tprod, PiTensorProduct.lift.tprod, MultilinearMap.mkPiAlgebra_apply] @[simp] lemma contrAll'_isEmpty_tmul [IsEmpty X] (x : ๐“ฃ.Tensor cX) (y : ๐“ฃ.Tensor (๐“ฃ.ฯ„ โˆ˜ cX)) : ๐“ฃ.contrAll' (x โŠ—โ‚œ y) = ๐“ฃ.isEmptyEquiv x * ๐“ฃ.isEmptyEquiv y := by refine PiTensorProduct.induction_on' x ?_ (by intro a b hx hy simp [map_add, add_tmul, add_mul, hx, hy]) intro rx fx refine PiTensorProduct.induction_on' y ?_ (by intro a b hx hy simp at hx hy simp [map_add, tmul_add, mul_add, hx, hy]) intro ry fy simp [smul_tmul] ring_nf rw [mul_assoc, mul_assoc] apply congrArg apply congrArg simp [contrAll'] erw [pairProd_tmul_tprod_tprod] simp only [Function.comp_apply, PiTensorProduct.map_tprod, PiTensorProduct.lift.tprod, MultilinearMap.mkPiAlgebra_apply, Finset.univ_eq_empty, Finset.prod_empty] erw [isEmptyEquiv_tprod] @[simp] lemma contrAll'_mapIso (e : X โ‰ƒ Y) (h : cX.MapIso e cY) : ๐“ฃ.contrAll' โˆ˜โ‚— (TensorProduct.congr (๐“ฃ.mapIso e h) (LinearEquiv.refl R _)).toLinearMap = ๐“ฃ.contrAll' โˆ˜โ‚— (TensorProduct.congr (LinearEquiv.refl R _) (๐“ฃ.mapIso e.symm h.symm.dual)).toLinearMap := by apply TensorProduct.ext' refine fun x โ†ฆ PiTensorProduct.induction_on' x ?_ (by intro a b hx hy y simp [map_add, add_tmul, hx, hy]) intro rx fx refine fun y โ†ฆ PiTensorProduct.induction_on' y ?_ (by intro a b hx hy simp at hx hy simp [map_add, tmul_add, hx, hy]) intro ry fy simp only [PiTensorProduct.tprodCoeff_eq_smul_tprod, Function.comp_apply, tmul_smul, LinearMapClass.map_smul, LinearMap.coe_comp, LinearEquiv.coe_coe, congr_tmul, mapIso_tprod, LinearEquiv.refl_apply, smul_eq_mul, smul_tmul] apply congrArg apply congrArg erw [contrAll'_tmul_tprod_tprod] erw [TensorProduct.congr_tmul] simp only [PiTensorProduct.lift.tprod, LinearEquiv.refl_apply] erw [mapIso_tprod] erw [contrAll'_tmul_tprod_tprod] rw [mkPiAlgebra_equiv e] simp only [Equiv.symm_symm_apply, LinearMap.coe_comp, LinearEquiv.coe_coe, Function.comp_apply, PiTensorProduct.reindex_tprod, PiTensorProduct.lift.tprod] apply congrArg funext y rw [๐“ฃ.contrDual_cast (congrFun h.symm y)] apply congrArg congr 1 ยท exact (LinearEquiv.eq_symm_apply (๐“ฃ.colorModuleCast (congrFun (TensorColor.ColorMap.MapIso.symm h) y))).mp rfl ยท symm apply cast_eq_iff_heq.mpr simp [colorModuleCast, Equiv.apply_symm_apply] rw [Equiv.apply_symm_apply] exact HEq.symm (cast_heq _ _) @[simp] lemma contrAll'_mapIso_tmul (e : X โ‰ƒ Y) (h : cX.MapIso e cY) (x : ๐“ฃ.Tensor cX) (y : ๐“ฃ.Tensor (๐“ฃ.ฯ„ โˆ˜ cY)) : ๐“ฃ.contrAll' ((๐“ฃ.mapIso e h) x โŠ—โ‚œ[R] y) = ๐“ฃ.contrAll' (x โŠ—โ‚œ[R] (๐“ฃ.mapIso e.symm h.symm.dual y)) := by change (๐“ฃ.contrAll' โˆ˜โ‚— (TensorProduct.congr (๐“ฃ.mapIso e h) (LinearEquiv.refl R _)).toLinearMap) (x โŠ—โ‚œ[R] y) = _ rw [contrAll'_mapIso] rfl /-- The contraction of all the indices of two tensors with dual colors. -/ def contrAll (e : X โ‰ƒ Y) (h : cX.ContrAll e cY) : ๐“ฃ.Tensor cX โŠ—[R] ๐“ฃ.Tensor cY โ†’โ‚—[R] R := ๐“ฃ.contrAll' โˆ˜โ‚— (TensorProduct.congr (LinearEquiv.refl _ _) (๐“ฃ.mapIso e.symm h.symm.toMapIso)).toLinearMap lemma contrAll_tmul (e : X โ‰ƒ Y) (h : cX.ContrAll e cY) (x : ๐“ฃ.Tensor cX) (y : ๐“ฃ.Tensor cY) : ๐“ฃ.contrAll e h (x โŠ—โ‚œ[R] y) = ๐“ฃ.contrAll' (x โŠ—โ‚œ[R] ((๐“ฃ.mapIso e.symm h.symm.toMapIso) y)) := by rw [contrAll] rfl @[simp] lemma contrAll_mapIso_right_tmul (e : X โ‰ƒ Y) (e' : Z โ‰ƒ Y) (h : c.ContrAll e cY) (h' : cZ.MapIso e' cY) (x : ๐“ฃ.Tensor c) (z : ๐“ฃ.Tensor cZ) : ๐“ฃ.contrAll e h (x โŠ—โ‚œ[R] ๐“ฃ.mapIso e' h' z) = ๐“ฃ.contrAll (e.trans e'.symm) (h.trans_mapIso h') (x โŠ—โ‚œ[R] z) := by simp only [contrAll_tmul, mapIso_mapIso] rfl @[simp] lemma contrAll_comp_mapIso_right (e : X โ‰ƒ Y) (e' : Z โ‰ƒ Y) (h : c.ContrAll e cY) (h' : cZ.MapIso e' cY) : ๐“ฃ.contrAll e h โˆ˜โ‚— (TensorProduct.congr (LinearEquiv.refl R (๐“ฃ.Tensor c)) (๐“ฃ.mapIso e' h')).toLinearMap = ๐“ฃ.contrAll (e.trans e'.symm) (h.trans_mapIso h') := by apply TensorProduct.ext' intro x y exact ๐“ฃ.contrAll_mapIso_right_tmul e e' h h' x y @[simp] lemma contrAll_mapIso_left_tmul {e : X โ‰ƒ Y} {e' : Z โ‰ƒ X} (h : cX.ContrAll e cY) (h' : cZ.MapIso e' cX) (x : ๐“ฃ.Tensor cZ) (y : ๐“ฃ.Tensor cY) : ๐“ฃ.contrAll e h (๐“ฃ.mapIso e' h' x โŠ—โ‚œ[R] y) = ๐“ฃ.contrAll (e'.trans e) (h.mapIso_trans h') (x โŠ—โ‚œ[R] y) := by simp only [contrAll_tmul, contrAll'_mapIso_tmul, mapIso_mapIso] rfl @[simp] lemma contrAll_mapIso_left {e : X โ‰ƒ Y} {e' : Z โ‰ƒ X} (h : cX.ContrAll e cY) (h' : cZ.MapIso e' cX) : ๐“ฃ.contrAll e h โˆ˜โ‚— (TensorProduct.congr (๐“ฃ.mapIso e' h') (LinearEquiv.refl R (๐“ฃ.Tensor cY))).toLinearMap = ๐“ฃ.contrAll (e'.trans e) (h.mapIso_trans h') := by apply TensorProduct.ext' intro x y exact ๐“ฃ.contrAll_mapIso_left_tmul h h' x y /-- The linear map from `๐“ฃ.Tensor cX โŠ—[R] ๐“ฃ.Tensor cY โŠ—[R] ๐“ฃ.Tensor cZ` to `๐“ฃ.Tensor cZ` obtained by contracting all indices in `๐“ฃ.Tensor cX` and `๐“ฃ.Tensor cY`, given a proof that this is possible. -/ def contrAllLeft (e : X โ‰ƒ Y) (h : cX.ContrAll e cY) : ๐“ฃ.Tensor cX โŠ—[R] ๐“ฃ.Tensor cY โŠ—[R] ๐“ฃ.Tensor cZ โ†’โ‚—[R] ๐“ฃ.Tensor cZ := (TensorProduct.lid R _).toLinearMap โˆ˜โ‚— TensorProduct.map (๐“ฃ.contrAll e h) (LinearEquiv.refl R (๐“ฃ.Tensor cZ)).toLinearMap โˆ˜โ‚— (TensorProduct.assoc R _ _ _).symm.toLinearMap /-- The linear map from `(๐“ฃ.Tensor cW โŠ—[R] ๐“ฃ.Tensor cX) โŠ—[R] (๐“ฃ.Tensor cY โŠ—[R] ๐“ฃ.Tensor cZ)` to `๐“ฃ.Tensor cW โŠ—[R] ๐“ฃ.Tensor cZ` obtained by contracting all indices of the tensors in the middle. -/ def contrAllMid (e : X โ‰ƒ Y) (h : cX.ContrAll e cY) : (๐“ฃ.Tensor cW โŠ—[R] ๐“ฃ.Tensor cX) โŠ—[R] (๐“ฃ.Tensor cY โŠ—[R] ๐“ฃ.Tensor cZ) โ†’โ‚—[R] ๐“ฃ.Tensor cW โŠ—[R] ๐“ฃ.Tensor cZ := (TensorProduct.map (LinearEquiv.refl R _).toLinearMap (๐“ฃ.contrAllLeft e h)) โˆ˜โ‚— (TensorProduct.assoc R _ _ _).toLinearMap /-- The linear map from `๐“ฃ.Tensor (Sum.elim cW cX) โŠ—[R] ๐“ฃ.Tensor (Sum.elim cY cZ)` to `๐“ฃ.Tensor (Sum.elim cW cZ)` formed by contracting the indices specified by `cX` and `cY`, which are assumed to be dual. -/ def contrElim (e : X โ‰ƒ Y) (h : cX.ContrAll e cY) : ๐“ฃ.Tensor (Sum.elim cW cX) โŠ—[R] ๐“ฃ.Tensor (Sum.elim cY cZ) โ†’โ‚—[R] ๐“ฃ.Tensor (Sum.elim cW cZ) := (๐“ฃ.tensoratorEquiv cW cZ).toLinearMap โˆ˜โ‚— ๐“ฃ.contrAllMid e h โˆ˜โ‚— (TensorProduct.congr (๐“ฃ.tensoratorEquiv cW cX).symm (๐“ฃ.tensoratorEquiv cY cZ).symm).toLinearMap /-! ## Group acting on contraction -/ @[simp] lemma contrAll_rep (e : X โ‰ƒ Y) (h : cX.ContrAll e cY) (g : G) : ๐“ฃ.contrAll e h โˆ˜โ‚— (TensorProduct.map (๐“ฃ.rep g) (๐“ฃ.rep g)) = ๐“ฃ.contrAll e h := by apply TensorProduct.ext' refine fun x โ†ฆ PiTensorProduct.induction_on' x ?_ (by intro a b hx hy y simp [map_add, add_tmul, hx, hy]) intro rx fx refine fun y โ†ฆ PiTensorProduct.induction_on' y ?_ (by intro a b hx hy simp at hx hy simp [map_add, tmul_add, hx, hy]) intro ry fy simp only [contrAll_tmul, PiTensorProduct.tprodCoeff_eq_smul_tprod, tmul_smul, smul_tmul, LinearMapClass.map_smul, LinearMap.coe_comp, Function.comp_apply, map_tmul, rep_tprod, smul_eq_mul] apply congrArg apply congrArg simp only [contrAll', mapIso_tprod, Equiv.symm_symm_apply, colorModuleCast_equivariant_apply, LinearMap.coe_comp, Function.comp_apply] apply congrArg erw [pairProd_tmul_tprod_tprod, pairProd_tmul_tprod_tprod, PiTensorProduct.map_tprod, PiTensorProduct.map_tprod] apply congrArg funext x nth_rewrite 2 [โ† contrDual_inv (cX x) g] rfl @[simp] lemma contrAll_rep_apply {c : X โ†’ ๐“ฃ.Color} {d : Y โ†’ ๐“ฃ.Color} (e : X โ‰ƒ Y) (h : c = ๐“ฃ.ฯ„ โˆ˜ d โˆ˜ e) (g : G) (x : ๐“ฃ.Tensor c โŠ— ๐“ฃ.Tensor d) : ๐“ฃ.contrAll e h (TensorProduct.map (๐“ฃ.rep g) (๐“ฃ.rep g) x) = ๐“ฃ.contrAll e h x := by change (๐“ฃ.contrAll e h โˆ˜โ‚— (TensorProduct.map (๐“ฃ.rep g) (๐“ฃ.rep g))) x = _ rw [contrAll_rep] @[simp] lemma contrAll_rep_tmul {c : X โ†’ ๐“ฃ.Color} {d : Y โ†’ ๐“ฃ.Color} (e : X โ‰ƒ Y) (h : c = ๐“ฃ.ฯ„ โˆ˜ d โˆ˜ e) (g : G) (x : ๐“ฃ.Tensor c) (y : ๐“ฃ.Tensor d) : ๐“ฃ.contrAll e h ((g โ€ข x) โŠ—โ‚œ[R] (g โ€ข y)) = ๐“ฃ.contrAll e h (x โŠ—โ‚œ[R] y) := by nth_rewrite 2 [โ† @contrAll_rep_apply R _ ๐“ฃ _ _ _ G] rfl /-! ## Contraction based on specification -/ lemma contr_cond (e : (C โŠ• C) โŠ• P โ‰ƒ X) : cX.MapIso e.symm (Sum.elim (Sum.elim (cX.contrLeft e) (cX.contrRight e)) (cX.contr e)) := by rw [TensorColor.ColorMap.MapIso, Equiv.eq_comp_symm] funext x match x with | Sum.inl (Sum.inl x) => rfl | Sum.inl (Sum.inr x) => rfl | Sum.inr x => rfl /-- Contraction of indices based on an equivalence `(C โŠ• C) โŠ• P โ‰ƒ X`. The indices in `C` are contracted pair-wise, whilst the indices in `P` are preserved. -/ def contr (e : (C โŠ• C) โŠ• P โ‰ƒ X) (h : cX.ContrCond e) : ๐“ฃ.Tensor cX โ†’โ‚—[R] ๐“ฃ.Tensor (cX.contr e) := (TensorProduct.lid R _).toLinearMap โˆ˜โ‚— (TensorProduct.map (๐“ฃ.contrAll (Equiv.refl C) h.to_contrAll) LinearMap.id) โˆ˜โ‚— (TensorProduct.congr (๐“ฃ.tensoratorEquiv _ _).symm (LinearEquiv.refl R _)).toLinearMap โˆ˜โ‚— (๐“ฃ.tensoratorEquiv _ _).symm.toLinearMap โˆ˜โ‚— (๐“ฃ.mapIso e.symm (๐“ฃ.contr_cond e)).toLinearMap open PiTensorProduct in lemma contr_tprod (e : (C โŠ• C) โŠ• P โ‰ƒ X) (h : cX.ContrCond e) (f : (i : X) โ†’ ๐“ฃ.ColorModule (cX i)) : ๐“ฃ.contr e h (tprod R f) = (๐“ฃ.contrAll (Equiv.refl C) h.to_contrAll (tprod R (fun i => f (e (Sum.inl (Sum.inl i)))) โŠ—โ‚œ[R] tprod R (fun i => f (e (Sum.inl (Sum.inr i)))))) โ€ข tprod R (fun (p : P) => f (e (Sum.inr p))) := by simp only [contr, LinearEquiv.comp_coe, LinearMap.coe_comp, LinearEquiv.coe_coe, Function.comp_apply, LinearEquiv.trans_apply, mapIso_tprod, Equiv.symm_symm_apply, tensoratorEquiv_symm_tprod, congr_tmul, LinearEquiv.refl_apply, map_tmul, LinearMap.id_coe, id_eq, lid_tmul] rfl open PiTensorProduct in @[simp] lemma contr_tprod_isEmpty [IsEmpty C] (e : (C โŠ• C) โŠ• P โ‰ƒ X) (h : cX.ContrCond e) (f : (i : X) โ†’ ๐“ฃ.ColorModule (cX i)) : ๐“ฃ.contr e h (tprod R f) = tprod R (fun (p : P) => f (e (Sum.inr p))) := by rw [contr_tprod] rw [contrAll_tmul, contrAll'_isEmpty_tmul] simp only [isEmptyEquiv_tprod, Equiv.refl_symm, mapIso_tprod, Equiv.refl_apply, one_mul] erw [isEmptyEquiv_tprod] exact MulAction.one_smul ((tprod R) fun p => f (e (Sum.inr p))) /-- The contraction of indices via `contr` is equivariant. -/ @[simp] lemma contr_equivariant (e : (C โŠ• C) โŠ• P โ‰ƒ X) (h : cX.ContrCond e) (g : G) (x : ๐“ฃ.Tensor cX) : ๐“ฃ.contr e h (g โ€ข x) = g โ€ข ๐“ฃ.contr e h x := by simp only [TensorColor.ColorMap.contr, contr, TensorProduct.congr, LinearEquiv.refl_toLinearMap, LinearEquiv.symm_symm, LinearEquiv.refl_symm, LinearEquiv.ofLinear_toLinearMap, LinearEquiv.comp_coe, LinearMap.coe_comp, LinearEquiv.coe_coe, Function.comp_apply, LinearEquiv.trans_apply, rep_mapIso_apply, rep_tensoratorEquiv_symm_apply] rw [โ† LinearMap.comp_apply (TensorProduct.map _ _), โ† TensorProduct.map_comp] rw [โ† LinearMap.comp_apply (TensorProduct.map _ _), โ† TensorProduct.map_comp] rw [LinearMap.comp_assoc, rep_tensoratorEquiv_symm, โ† LinearMap.comp_assoc] simp only [contrAll_rep, LinearMap.comp_id, LinearMap.id_comp] have h1 {M N A B : Type} [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid A] [AddCommMonoid B] [Module R M] [Module R N] [Module R A] [Module R B] (f : M โ†’โ‚—[R] N) (g : A โ†’โ‚—[R] B) : TensorProduct.map f g = TensorProduct.map (LinearMap.id) g โˆ˜โ‚— TensorProduct.map f (LinearMap.id) := ext rfl rw [h1] simp only [LinearMap.coe_comp, Function.comp_apply, rep_lid_apply] rw [โ† LinearMap.comp_apply (TensorProduct.map _ _), โ† TensorProduct.map_comp] rfl end TensorStructure