diff --git a/Physlib.lean b/Physlib.lean index aaf3ca2edb..5296ada76e 100644 --- a/Physlib.lean +++ b/Physlib.lean @@ -167,6 +167,8 @@ public import Physlib.Mathematics.ForMathlib.List.InsertionSort public import Physlib.Mathematics.ForMathlib.OneParameterSubgroups.Basic public import Physlib.Mathematics.ForMathlib.OneParameterSubgroups.Unitary public import Physlib.Mathematics.ForMathlib.OrthogonalMatrix +public import Physlib.Mathematics.ForMathlib.PiTensorProduct +public import Physlib.Mathematics.ForMathlib.Representation public import Physlib.Mathematics.ForMathlib.SchurTriangulation public import Physlib.Mathematics.ForMathlib.SesquilinearForm public import Physlib.Mathematics.ForMathlib.Trigonometry.SinSq @@ -194,6 +196,7 @@ public import Physlib.Mathematics.SpecialFunctions.EllipticIntegral public import Physlib.Mathematics.SpecialFunctions.PhysHermite public import Physlib.Mathematics.Tensors.Color public import Physlib.Mathematics.Tensors.Species +public import Physlib.Mathematics.Tensors.Tensor public import Physlib.Mathematics.VariationalCalculus.Basic public import Physlib.Mathematics.VariationalCalculus.HasVarAdjDeriv public import Physlib.Mathematics.VariationalCalculus.HasVarAdjoint diff --git a/Physlib/Mathematics/ForMathlib/PiTensorProduct.lean b/Physlib/Mathematics/ForMathlib/PiTensorProduct.lean new file mode 100644 index 0000000000..6aec4d301c --- /dev/null +++ b/Physlib/Mathematics/ForMathlib/PiTensorProduct.lean @@ -0,0 +1,184 @@ +/- +Copyright (c) 2026 Andrea Pari. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Andrea Pari +-/ +module + +public import Mathlib.LinearAlgebra.Matrix.ToLin +public import Mathlib.LinearAlgebra.Dimension.Free +public import Mathlib.LinearAlgebra.FreeModule.StrongRankCondition +public import Mathlib.LinearAlgebra.PiTensorProduct.Dual + +/-! + +# Matrices of `PiTensorProduct.map`, dimension and contraction of `PiTensorProduct` + +This file extends Mathlib's results on the tensor product of two spaces to the tensor product of a +family, and adds the contraction of its factors in pairs. + +## i. Overview + +A tensor with several indices lies in the tensor product `⨂[R] i, M i` of a family of spaces, one +space `M i` for each index `i`. Here `R` is the scalars, `ℝ` or `ℂ` in physics. The results hold for +any commutative semiring, except the dimension (B), which needs a commutative ring. Mathlib proves +several facts about the tensor product of two spaces, `M ⊗ N`, that it does not prove for a family. +This file proves them for a family: the matrix of a map applied at every index (A) and the +dimension (B). It also treats the case with no indices (C), and defines contraction, which pairs +indices and removes them (D). + +For example, `T^μ_ν` has `4 · 4 = 16` components, so its space has dimension `16`. A Lorentz +transformation acts on it index by index, by `Λ` at the up index and by `(Λ⁻¹)ᵀ` at the down index. +On the `16` components it is one `16 × 16` matrix, the Kronecker product `Λ ⊗ (Λ⁻¹)ᵀ`, whose entry +at `((μ, ν), (σ, τ))` is `Λ^μ_σ (Λ⁻¹)^τ_ν`. This gives the textbook formula +`T^μ_ν ↦ Λ^μ_σ (Λ⁻¹)^τ_ν T^σ_τ` from the action index by index. A tensor with no indices is a +scalar, which no transformation changes. The trace `T^μ_μρ` contracts the first two indices and +keeps `ρ`. + +## ii. Key results + +- `PiTensorProduct.toMatrix_map_apply` : the matrix of `PiTensorProduct.map f` in the product + bases is the product of the matrices of the `f i`. +- `Module.finrank_piTensorProduct` : the dimension of `⨂[R] i, M i` is `∏ i, finrank R (M i)`. +- `PiTensorProduct.map_eq_id_of_isEmpty` : with no indices, `PiTensorProduct.map f` is the identity. +- `PiTensorProduct.contrPairs` : the contraction of pairs of factors by a family of pairings, with + `PiTensorProduct.contrPairs_tprod` : its value on a pure tensor. + +## iii. Table of contents + +- A. Matrices in the product basis +- B. Dimension +- C. Empty index types +- D. Contraction of pairs of factors + +## iv. References + +* None. + +-/ + +@[expose] public section + +open TensorProduct PiTensorProduct + +variable {ι R : Type*} {M N : ι → Type*} + +/-! + +## A. Matrices in the product basis + +`PiTensorProduct.map f` applies the map `f i` at every index `i`. It is defined without bases, so +its definition does not give its matrix. In the product bases `Basis.piTensorProduct b`, its matrix +is the Kronecker product of the matrices of the `f i`, whose entry at `(φ, ψ)` is the product over +`i` of the entries of the matrix of `f i` at `(φ i, ψ i)`. So the large matrix on the whole tensor +product is fixed by one small matrix per index. Mathlib proves this for the tensor product of two +spaces, `TensorProduct.toMatrix_map`, and this section proves it for a family. + +For example, a Lorentz transformation of `T^μ_ν` is `map` of `Λ` and `(Λ⁻¹)ᵀ`. Its entry at +`((μ, ν), (σ, τ))` is `Λ^μ_σ (Λ⁻¹)^τ_ν`, so the components transform as +`T^μ_ν ↦ Λ^μ_σ (Λ⁻¹)^τ_ν T^σ_τ`. + +-/ + +/-- The matrix of `PiTensorProduct.map f` in the product bases is the n-ary Kronecker product of +the matrices of the `f i`. -/ +lemma PiTensorProduct.toMatrix_map_apply [CommSemiring R] [∀ i, AddCommMonoid (M i)] + [∀ i, Module R (M i)] [∀ i, AddCommMonoid (N i)] [∀ i, Module R (N i)] [Fintype ι] + [DecidableEq ι] {κ κ' : ι → Type*} [∀ i, Fintype (κ i)] [∀ i, DecidableEq (κ i)] + [∀ i, Fintype (κ' i)] + (b : Π i, Module.Basis (κ i) R (M i)) (b' : Π i, Module.Basis (κ' i) R (N i)) + (f : Π i, M i →ₗ[R] N i) (φ : Π i, κ' i) (ψ : Π i, κ i) : + LinearMap.toMatrix (Basis.piTensorProduct b) (Basis.piTensorProduct b') + (PiTensorProduct.map f) φ ψ = ∏ i, LinearMap.toMatrix (b i) (b' i) (f i) (φ i) (ψ i) := by + simp [LinearMap.toMatrix_apply, Basis.piTensorProduct_apply, + Basis.piTensorProduct_repr_tprod_apply] + +/-! + +## B. Dimension + +The dimension of `⨂[R] i, M i` is the product of the dimensions of the `M i`. For example, `T^μ_νρ` +in four dimensions has `4 · 4 · 4 = 64` components. Mathlib proves this for the tensor product of +two spaces, `Module.finrank_tensorProduct`, and this section proves it for a family. + +-/ + +/-- The dimension of `⨂[R] i, M i` is the product of the dimensions of the `M i`. -/ +lemma Module.finrank_piTensorProduct [CommRing R] [Fintype ι] + [∀ i, AddCommGroup (M i)] [∀ i, Module R (M i)] [∀ i, Module.Free R (M i)] + [∀ i, Module.Finite R (M i)] : + Module.finrank R (⨂[R] i, M i) = ∏ i, Module.finrank R (M i) := by + classical + nontriviality R + rw [Module.finrank_eq_card_basis (Basis.piTensorProduct fun i => Module.Free.chooseBasis R (M i)), + Fintype.card_pi] + simp [Module.finrank_eq_card_chooseBasisIndex] + +/-! + +## C. Empty index types + +A tensor with no indices is a scalar. Mathlib identifies `⨂[R] i, M i` over an empty index type +with `R`, by `PiTensorProduct.isEmptyEquiv`. Then a map applied at every index has no index to act +on, so `PiTensorProduct.map f` is the identity (`map_eq_id_of_isEmpty`). For example, a Lorentz +transformation leaves every scalar unchanged. + +-/ + +/-- With no indices, `PiTensorProduct.map f` is the identity. -/ +lemma PiTensorProduct.map_eq_id_of_isEmpty [CommSemiring R] [∀ i, AddCommMonoid (M i)] + [∀ i, Module R (M i)] [IsEmpty ι] (f : Π i, M i →ₗ[R] M i) : + PiTensorProduct.map f = LinearMap.id := by + ext x + simp [Subsingleton.elim (fun i => f i (x i)) x] + +/-! + +## D. Contraction of pairs of factors + +Contraction pairs some indices of a tensor, turns each pair into a scalar, and keeps the other +indices. The index type `κ ⊕ (J ⊕ J)` says which indices are paired, with Mathlib's tags `Sum.inl` +and `Sum.inr` for the left and the right side of `⊕`. The indices `inl x`, for `x` in `κ`, are kept. +Each `j` in `J` is a pair, with first index `inr (inl j)` and second index `inr (inr j)`, contracted +by the pairing `p j`. On a pure tensor, `contrPairs p` multiplies the kept vectors by the product of +the pairings (`contrPairs_tprod`). The nesting follows the construction. Mathlib's +`PiTensorProduct.tmulEquivDep` splits a tensor product over `A ⊕ B` into the tensor product over `A` +times the tensor product over `B`. Splitting at the outer `⊕` separates the kept factors from the +paired ones. Splitting at the inner `⊕` separates the first factor of each pair from the second, so +that `p j` can contract them. `contrPairs` takes only this arrangement. A tensor whose indices are +in another order is reordered into it first, with `PiTensorProduct.reindex`. + +For example, the Ricci tensor `R_μν = R^ρ_μρν` pairs the first and third indices and keeps the +second and fourth. Reordering takes `u ⊗ α ⊗ β ⊗ γ` to `α ⊗ γ ⊗ u ⊗ β`, with `α ⊗ γ` at the kept +indices and `u`, `β` the pair. The contraction then gives `(β_ρ u^ρ) α ⊗ γ`. The Ricci scalar +`R = R^μν_μν` has two pairs and no kept index, so the result is the scalar `(α_μ u^μ) (β_ν v^ν)` on +`u ⊗ v ⊗ α ⊗ β`. + +-/ + +section + +variable [CommSemiring R] {κ J : Type*} [Fintype J] {M : κ ⊕ (J ⊕ J) → Type*} + [∀ i, AddCommMonoid (M i)] [∀ i, Module R (M i)] + +/-- The contraction of `⨂ i, M i` on `κ ⊕ (J ⊕ J)` that pairs the factors at `inr (inl j)` and +`inr (inr j)` by `p j` and keeps the factors at `inl x`. -/ +noncomputable def PiTensorProduct.contrPairs + (p : Π j, M (.inr (.inl j)) ⊗[R] M (.inr (.inr j)) →ₗ[R] R) : + (⨂[R] i, M i) →ₗ[R] ⨂[R] x, M (.inl x) := + -- The factors of each pair are split into two tensor products, and the second is read as a + -- linear form on the first through the `p j` and Mathlib's `PiTensorProduct.dualDistrib`. + (TensorProduct.rid R _).toLinearMap ∘ₗ + (TensorProduct.lift (PiTensorProduct.dualDistrib ∘ₗ + PiTensorProduct.map fun j => (TensorProduct.curry (p j)).flip).flip ∘ₗ + (tmulEquivDep R fun i => M (.inr i)).symm.toLinearMap).lTensor _ ∘ₗ + (tmulEquivDep R M).symm.toLinearMap + +/-- On a pure tensor the contraction multiplies the kept factors by the pairings of each pair. -/ +lemma PiTensorProduct.contrPairs_tprod + (p : Π j, M (.inr (.inl j)) ⊗[R] M (.inr (.inr j)) →ₗ[R] R) (f : Π i, M i) : + contrPairs p (⨂ₜ[R] i, f i) = + (∏ j, p j (f (.inr (.inl j)) ⊗ₜ f (.inr (.inr j)))) • ⨂ₜ[R] x, f (.inl x) := by + simp [contrPairs, tmulEquivDep_symm_apply] + +end diff --git a/Physlib/Mathematics/ForMathlib/Representation.lean b/Physlib/Mathematics/ForMathlib/Representation.lean new file mode 100644 index 0000000000..13b0fec4b1 --- /dev/null +++ b/Physlib/Mathematics/ForMathlib/Representation.lean @@ -0,0 +1,283 @@ +/- +Copyright (c) 2026 Andrea Pari. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Andrea Pari +-/ +module + +public import Mathlib.RepresentationTheory.Intertwining +public import Physlib.Mathematics.ForMathlib.PiTensorProduct + +/-! + +# Tensor products of representations + +This file gives the representation on the tensor product of a family of representations, and makes +Mathlib's linear maps of such products into maps of representations. + +## i. Overview + +A representation `ρ` of a group or monoid `G` on a space `V` says how each element `g` of `G` acts +on `V`, by the linear map `ρ g`. A map of representations from `ρ` to `σ` on `W` is a linear map +`φ : V → W` that commutes with the group, `φ ∘ ρ g = σ g ∘ φ` for every `g`, where `∘` applies the +right-hand map first. So transforming and then mapping is the same as mapping and then transforming, +and the square + +``` + ρ g + V ──────► V + │ │ + φ │ │ φ + ▼ ▼ + W ──────► W + σ g +``` + +commutes. Mathlib calls it an `IntertwiningMap`, and an `Equiv` when it is invertible. + +For example, let `G` be the Lorentz group, and let `Λ` be the matrix of a Lorentz transformation +`g`. Then `g` acts on the vectors `V` by `ρ g = Λ`, and on the covectors `W` by `σ g = (Λ⁻¹)ᵀ`, so +that `α_μ v^μ` is invariant. The map `φ` is lowering an index with the metric, `φ v = η v`, from +vectors to covectors. Composing maps is multiplying their matrices, so the two routes in the square +are `φ ∘ ρ g = η Λ` and `σ g ∘ φ = (Λ⁻¹)ᵀ η`. They agree because `Λᵀ η Λ = η`, the defining +property of a Lorentz transformation. + +A tensor with several indices has one representation for each index, a family `ρ i` of +representations of `G` on spaces `M i`. For `T^μ_ν` the family is `Λ` on the vectors at the up index +and `(Λ⁻¹)ᵀ` on the covectors at the down index. The tensor lies in the tensor product `⨂[k] i, M i` +of the family. Mathlib has the representation `ρ.tprod τ` on the tensor product of two +representations, and the tensor product `IntertwiningMap.tensor` of two intertwining maps, but no +representation on the tensor product of a family. So Mathlib's linear maps of `⨂`, such as +`PiTensorProduct.reindex`, are not stated as maps of representations. This file defines that +representation, `piTprod ρ`, and proves that applying maps at the factors, reordering, grouping and +contracting factors commute with it, so that they are maps of representations (B). + +In the same way, the Lorentz tensors `T^μ_νρ` lie in `V ⊗ V* ⊗ V*`, with `Λ` on the vectors `V` and +`(Λ⁻¹)ᵀ` on the covectors `V*`. Reordering the factors to `V* ⊗ V ⊗ V*`, grouping them as +`V ⊗ (V* ⊗ V*)`, and contracting `V` with the first `V*`, `T^μ_μρ`, all commute with `g`. So each +one sends an invariant tensor to an invariant tensor, and a tensor built from invariant ones by +these maps is invariant with no further proof. + +## ii. Key results + +- `Representation.Equiv.tprodCongr` : the tensor product of two equivalences of representations. +- `Representation.piTprod` : the representation on `⨂[k] i, M i` of a family of representations. +- `Representation.IsIntertwiningMap.piTprodMap` and `Representation.Equiv.piTprodCongr` : + `PiTensorProduct.map` and `PiTensorProduct.congr` of maps of representations. +- `Representation.Equiv.piTprodReindex`, `Representation.Equiv.piTprodSum` and + `Representation.Equiv.piTprodOfSubsingleton` : Mathlib's `reindex`, `tmulEquivDep` and + `subsingletonEquiv` as equivalences of representations. +- `Representation.map_piTprod_of_tprod` : a map that commutes with `piTprod ρ` on pure tensors + commutes with it on all tensors. + +## iii. Table of contents + +- A. Tensor products of equivalences +- B. Tensor products of families + - B.1. The representation on a tensor product of a family + - B.2. Maps of representations + +## iv. References + +* None. + +-/ + +@[expose] public section + +open TensorProduct + +variable {k G V W U X : Type*} [CommSemiring k] [Monoid G] [AddCommMonoid V] [Module k V] + [AddCommMonoid W] [Module k W] [AddCommMonoid U] [Module k U] [AddCommMonoid X] [Module k X] + {ρ : Representation k G V} {σ : Representation k G W} {τ : Representation k G U} + {π : Representation k G X} + +/-! + +## A. Tensor products of equivalences + +Let `φ` be a map of representations from `ρ` on `V` to `σ` on `W`, and `ψ` one from `τ` on `U` to +`π` on `X`. Their tensor product applies each map to its own factor, `v ⊗ u ↦ φ v ⊗ ψ u`, from +`V ⊗ U` to `W ⊗ X`. It commutes with the group because each factor does. For example, if `φ` and `ψ` +both lower an index with the metric, their tensor product lowers both indices, `T^μν ↦ T_μν`. + +Mathlib has this tensor product for intertwining maps, `IntertwiningMap.tensor`, and for invertible +linear maps, `TensorProduct.congr`, but not for equivalences of representations. `tprodCongr` gives +it, so the tensor product of two invertible maps of representations is again invertible. In the +example, raising both indices undoes the lowering. + +-/ + +/-- The tensor product of two equivalences of representations, `v ⊗ u ↦ φ v ⊗ ψ u`, Mathlib's +`TensorProduct.congr` with the actions `ρ ⊗ τ` and `σ ⊗ π`. -/ +noncomputable def Representation.Equiv.tprodCongr (φ : ρ.Equiv σ) (ψ : τ.Equiv π) : + (ρ.tprod τ).Equiv (σ.tprod π) := + .mk (TensorProduct.congr φ.toLinearEquiv ψ.toLinearEquiv) + (φ.toIntertwiningMap.tensor ψ.toIntertwiningMap).isIntertwining' + +@[simp] +lemma Representation.Equiv.tprodCongr_tmul (φ : ρ.Equiv σ) (ψ : τ.Equiv π) (v : V) (u : U) : + φ.tprodCongr ψ (v ⊗ₜ u) = φ v ⊗ₜ ψ u := rfl + +/-! + +## B. Tensor products of families + +### B.1. The representation on a tensor product of a family + +Given how the group acts at each index, by the family `ρ`, the representation `piTprod ρ` acts on +the whole tensor by transforming every index by its own rule, `g ↦ ⨂ i, ρ i g` on `⨂[k] i, M i`. +For `T^μ_ν`, with `Λ` at the up index and `(Λ⁻¹)ᵀ` at the down index, it is +`T^μ_ν ↦ Λ^μ_σ (Λ⁻¹)^τ_ν T^σ_τ`, and on a pure tensor `u ⊗ α ↦ Λu ⊗ (Λ⁻¹)ᵀ α` (`piTprod_tprod`). +It is Mathlib's `Representation.tprod` on `V ⊗ W` for a family of factors, through +`PiTensorProduct.map`. + +A semilinear map out of `⨂ i, M i` that commutes with `piTprod ρ g` on pure tensors `⨂ₜ i, m i` +commutes with it on all tensors (`map_piTprod_of_tprod`), since pure tensors span `⨂ i, M i`. + +-/ + +section + +variable {ι : Type*} {M N : ι → Type*} [∀ i, AddCommMonoid (M i)] [∀ i, Module k (M i)] + [∀ i, AddCommMonoid (N i)] [∀ i, Module k (N i)] + +/-- The tensor product of a family of representations, `g ↦ ⨂ i, ρ i g` on `⨂[k] i, M i`. It is +the n-ary `Representation.tprod`. -/ +noncomputable def Representation.piTprod (ρ : Π i, Representation k G (M i)) : + Representation k G (⨂[k] i, M i) := + PiTensorProduct.mapMonoidHom.comp (MonoidHom.pi ρ) + +lemma Representation.piTprod_apply (ρ : Π i, Representation k G (M i)) (g : G) : + Representation.piTprod ρ g = PiTensorProduct.map fun i => ρ i g := rfl + +@[simp] +lemma Representation.piTprod_tprod (ρ : Π i, Representation k G (M i)) (g : G) (m : Π i, M i) : + Representation.piTprod ρ g (⨂ₜ[k] i, m i) = ⨂ₜ[k] i, ρ i g (m i) := + PiTensorProduct.map_tprod _ _ + +/-- A semilinear map out of `⨂ i, M i` that commutes with `piTprod ρ g` on pure tensors commutes +with it on all tensors. -/ +lemma Representation.map_piTprod_of_tprod {φ : k →+* k} {ρ : Π i, Representation k G (M i)} + (f : (⨂[k] i, M i) →ₛₗ[φ] U) (g : G) + (h : ∀ m : Π i, M i, f (Representation.piTprod ρ g (⨂ₜ[k] i, m i)) = τ g (f (⨂ₜ[k] i, m i))) + (t : ⨂[k] i, M i) : f (Representation.piTprod ρ g t) = τ g (f t) := by + induction t using PiTensorProduct.induction_on with + | smul_tprod r m => rw [map_smul, map_smulₛₗ, h, map_smulₛₗ, map_smul] + | add x y hx hy => rw [map_add, map_add, hx, hy, map_add, map_add] + +/-! + +### B.2. Maps of representations + +Not all linear maps out of `⨂` commute with the group action `piTprod`. Keeping only the +component `T^00` of `T^μν` does not, since a boost mixes `T^00` with the other components. The +following do, so they are maps of representations. Each acts index by index, or pairs indices in an +invariant way, as the examples on Lorentz tensors show: +- `piTprodMap` applies a map at every index, such as lowering every index, `T^μν ↦ T_μν`. It + commutes with the group when each of the maps does, and `piTprodCongr` is the same for + equivalences of representations. +- `piTprodReindex` reorders the indices along `e : ι ≃ ι'`, as `T^μ_νρ ↦ T_ν^μ_ρ`. +- `piTprodSum` joins two tensors into one, `T^μ_ν` and `U^ρ` into `T^μ_ν U^ρ`, with the indices of + the first over `ι₁` and those of the second over `ι₂`. +- `piTprodOfSubsingleton` identifies a tensor with one index with its vector, `v^μ` with `v`. +- `IsIntertwiningMap.contrPairs` contracts indices in pairs, as in `T^μ_μρ`, when every pairing, + such as `α_μ v^μ`, is invariant. + +-/ + +/-- `PiTensorProduct.map f` intertwines `piTprod ρ` and `piTprod σ` when every `f i` intertwines +`ρ i` and `σ i`. -/ +lemma Representation.IsIntertwiningMap.piTprodMap {ρ : Π i, Representation k G (M i)} + {σ : Π i, Representation k G (N i)} {f : Π i, M i →ₗ[k] N i} + (hf : ∀ i, (ρ i).IsIntertwiningMap (σ i) (f i)) : + (Representation.piTprod ρ).IsIntertwiningMap (Representation.piTprod σ) + (PiTensorProduct.map f) where + isIntertwining g v := by + rw [Representation.piTprod_apply, Representation.piTprod_apply, ← LinearMap.comp_apply, + ← PiTensorProduct.map_comp, ← LinearMap.comp_apply, ← PiTensorProduct.map_comp] + exact congr(PiTensorProduct.map $(funext fun i => LinearMap.ext ((hf i).isIntertwining g)) v) + +/-- The tensor product of a family of equivalences of representations, `⨂ i, v i ↦ ⨂ i, φ i (v i)`. +It is Mathlib's `PiTensorProduct.congr` with the actions `piTprod ρ` and `piTprod σ`. -/ +noncomputable def Representation.Equiv.piTprodCongr {ρ : Π i, Representation k G (M i)} + {σ : Π i, Representation k G (N i)} (φ : Π i, (ρ i).Equiv (σ i)) : + (Representation.piTprod ρ).Equiv (Representation.piTprod σ) := + .mk (PiTensorProduct.congr fun i => (φ i).toLinearEquiv) fun g => LinearMap.ext + ((Representation.IsIntertwiningMap.piTprodMap fun i => + ⟨(φ i).toIntertwiningMap.isIntertwining⟩).isIntertwining g) + +@[simp] +lemma Representation.Equiv.piTprodCongr_tprod {ρ : Π i, Representation k G (M i)} + {σ : Π i, Representation k G (N i)} (φ : Π i, (ρ i).Equiv (σ i)) (m : Π i, M i) : + Representation.Equiv.piTprodCongr φ (⨂ₜ[k] i, m i) = ⨂ₜ[k] i, φ i (m i) := + PiTensorProduct.congr_tprod _ _ + +/-- Reindexing the factors of a tensor product of representations along `e : ι ≃ ι'`, +`⨂ i, v i ↦ ⨂ j, v (e.symm j)`. It is Mathlib's `PiTensorProduct.reindex` with the actions +`piTprod ρ` and `piTprod (ρ ∘ e.symm)`. -/ +noncomputable def Representation.Equiv.piTprodReindex {ι' : Type*} + (ρ : Π i, Representation k G (M i)) (e : ι ≃ ι') : + (Representation.piTprod ρ).Equiv (Representation.piTprod fun j => ρ (e.symm j)) := + .mk (PiTensorProduct.reindex k M e) fun g => PiTensorProduct.ext <| MultilinearMap.ext fun m => by + simp [PiTensorProduct.reindex_tprod] + +@[simp] +lemma Representation.Equiv.piTprodReindex_tprod {ι' : Type*} (ρ : Π i, Representation k G (M i)) + (e : ι ≃ ι') (m : Π i, M i) : + Representation.Equiv.piTprodReindex ρ e (⨂ₜ[k] i, m i) = ⨂ₜ[k] j, m (e.symm j) := + PiTensorProduct.reindex_tprod _ _ + +/-- The tensor product of the two halves of a family of representations indexed by `ι₁ ⊕ ι₂`, +`(⨂ i, v i) ⊗ (⨂ j, w j) ↦ ⨂ s, Sum.rec v w s`. It is Mathlib's `PiTensorProduct.tmulEquivDep` +with the actions. -/ +noncomputable def Representation.Equiv.piTprodSum {ι₁ ι₂ : Type*} {M : ι₁ ⊕ ι₂ → Type*} + [∀ i, AddCommMonoid (M i)] [∀ i, Module k (M i)] (ρ : Π i, Representation k G (M i)) : + ((Representation.piTprod fun i => ρ (.inl i)).tprod + (Representation.piTprod fun j => ρ (.inr j))).Equiv (Representation.piTprod ρ) := + .mk (PiTensorProduct.tmulEquivDep k M) fun g => by + ext f₁ f₂ + simp only [Representation.tprod_apply, LinearMap.compMultilinearMap_apply, + TensorProduct.AlgebraTensorModule.curry_apply, LinearMap.restrictScalars_self, + TensorProduct.curry_apply, LinearMap.coe_comp, LinearEquiv.coe_coe, Function.comp_apply, + TensorProduct.map_tmul, Representation.piTprod_tprod, PiTensorProduct.tmulEquivDep_apply] + exact congrArg (PiTensorProduct.tprod k) (funext fun s => by rcases s with _ | _ <;> rfl) + +@[simp] +lemma Representation.Equiv.piTprodSum_tmul {ι₁ ι₂ : Type*} {M : ι₁ ⊕ ι₂ → Type*} + [∀ i, AddCommMonoid (M i)] [∀ i, Module k (M i)] (ρ : Π i, Representation k G (M i)) + (f₁ : Π i, M (.inl i)) (f₂ : Π j, M (.inr j)) : + Representation.Equiv.piTprodSum ρ ((⨂ₜ[k] i, f₁ i) ⊗ₜ (⨂ₜ[k] j, f₂ j)) = + ⨂ₜ[k] s, Sum.rec f₁ f₂ s := + PiTensorProduct.tmulEquivDep_apply k M f₁ f₂ + +/-- A representation `ρ i₀` as the tensor product of a family `ρ` over a subsingleton index type, +`v ↦ ⨂ i, v`. It is Mathlib's `PiTensorProduct.subsingletonEquiv` with the actions. -/ +noncomputable def Representation.Equiv.piTprodOfSubsingleton [Subsingleton ι] + (ρ : Π i, Representation k G (M i)) (i₀ : ι) : + (ρ i₀).Equiv (Representation.piTprod ρ) := + .mk (PiTensorProduct.subsingletonEquiv i₀).symm fun g => LinearMap.ext fun v => by + simp only [LinearMap.comp_apply, LinearEquiv.coe_coe, + PiTensorProduct.subsingletonEquiv_symm_apply, Representation.piTprod_tprod] + congr 1 + ext i + obtain rfl := Subsingleton.elim i i₀ + simp + +/-- `PiTensorProduct.contrPairs p` intertwines `piTprod ρ` and `piTprod` of the kept factors when +every pairing `p j` is invariant. -/ +lemma Representation.IsIntertwiningMap.contrPairs {κ J : Type*} [Fintype J] + {M : κ ⊕ (J ⊕ J) → Type*} [∀ i, AddCommMonoid (M i)] [∀ i, Module k (M i)] + {ρ : Π i, Representation k G (M i)} + {p : Π j, M (.inr (.inl j)) ⊗[k] M (.inr (.inr j)) →ₗ[k] k} + (hp : ∀ j g x y, p j (ρ _ g x ⊗ₜ ρ _ g y) = p j (x ⊗ₜ y)) : + (Representation.piTprod ρ).IsIntertwiningMap (Representation.piTprod fun x => ρ (.inl x)) + (PiTensorProduct.contrPairs p) where + isIntertwining g v := by + induction v using PiTensorProduct.induction_on with + | smul_tprod r f => + simp only [map_smul, Representation.piTprod_tprod, PiTensorProduct.contrPairs_tprod, hp, + smul_comm r] + | add x y hx hy => simp only [map_add, hx, hy] + +end diff --git a/Physlib/Mathematics/Tensors/Tensor.lean b/Physlib/Mathematics/Tensors/Tensor.lean new file mode 100644 index 0000000000..3d721e3158 --- /dev/null +++ b/Physlib/Mathematics/Tensors/Tensor.lean @@ -0,0 +1,552 @@ +/- +Copyright (c) 2026 Andrea Pari. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Andrea Pari +-/ +module + +public import Mathlib.LinearAlgebra.PiTensorProduct.Finite +public import Physlib.Mathematics.Tensors.Species +public import Physlib.Mathematics.ForMathlib.Representation +/-! + +# Tensors of a species + +The tensors of a species `S` with colors `c : ι → Color K`, on Mathlib's `⨂[k] i, S.V (c i)` for +any index type `ι`, and the group action on them index by index. + +## i. Overview + +A tensor `T : Tensor S c` lies in Mathlib's space `⨂[k] i, S.V (c i)`, and its type also fixes how +each index transforms, by the representation `S.rep (c i)` of the color of that index. Mathlib's +`⨂` is only a vector space, with no rule for how its factors transform. The index type `ι` is any +type, such as `Fin n`. The product of tensors on the indices `ι₁` and `ι₂` lives on `ι₁ ⊕ ι₂`, so +the indices of each factor keep their names. The colors of the product are those of the factors, +with no renumbering into `Fin (n + m)`. + +For example, the Lorentz colors `![⟨vec, up⟩, ⟨vec, up⟩]` give the tensors `T = T^μν e_μ ⊗ e_ν`, +and for two vectors `u` and `v` the pure tensor `u ⊗ v` has the components `u^μ v^ν`. + +Many operations on tensors are built from two kinds of linear map defined here. A map at every index +(D.1) acts on each index, as a Lorentz transformation does, `(ΛT)^μν = Λ^μ_σ Λ^ν_τ T^στ`, by the +representation of the color of each index. A map at one index (D.2) changes that index and keeps the +others, as lowering the index `ν` with the metric does, `T^μ_ν = η_νρ T^μρ`, which changes its color +to `⟨vec, down⟩`. Since the metric is invertible and invariant under the group, lowering is an +equivalence of representations, with raising as its inverse (D.4). Reindexing uses the map at every +index, and contracting an index with a tensor on two indices, `T^…μ… F_μ^ν`, is a map at that index. + +Each map is fixed by its values on pure tensors such as `u ⊗ v`. So its laws, such as composition +and commuting with the group (B.2), are proved once here, and not again for each operation. The +components of a tensor are its coordinates in the product basis (C), and a map at one index acts on +the components through that index alone, `(f T)^…ν… = ∑ μ, f^ν_μ T^…μ…` (D.3). + +## ii. Key results + +- `Tensor` is the space of tensors, and `Species.pure` is a pure tensor. +- `Species.ext_pure` proves that linear maps out of tensors that agree on pure tensors are equal. +- `Species.tensorRep` is the group action on tensors, and `Species.smul_pure` gives it on a pure + tensor. +- `Species.map_smul_of_pure` proves that a map that commutes with the group on pure tensors + commutes with it on all tensors. +- `Species.tensorBasis` is the basis of tensors, and `Species.tensorBasis_repr_smul` gives the + components of `Λ • T`. +- `Species.mapAt` and `Species.congrAt` apply a map at one index. + +## iii. Table of contents + +- A. Tensors +- B. The group action + - B.1. The action on tensors + - B.2. Maps that commute with the group +- C. The basis of tensors +- D. Linear maps at the indices + - D.1. A linear map at every index + - D.2. A linear map at one index + - D.3. Components + - D.4. An equivalence of representations at one index + +## iv. References + +* None. + +-/ + +@[expose] public section + +open TensorProduct PiTensorProduct + +variable {k : Type} [RCLike k] {K : Type} {G : Type} [Group G] {basisIdx : K → Type} + [∀ κ, Fintype (basisIdx κ)] [∀ κ, DecidableEq (basisIdx κ)] + +/-! + +## A. Tensors + +`Tensor S c` is `⨂[k] i, S.V (c i)`. A pure tensor `S.pure f` is given by a family `f` of vectors, +one vector `f i` in `S.V (c i)` at each index `i`, as `u ⊗ α` with the vector `u` at an up index +and the covector `α` at a down index. Most tensors are not pure, but every tensor is a linear +combination of pure tensors. So a linear map out of tensors, to any space, is fixed by its values +on pure tensors (`ext_pure`), and a property of all tensors follows from the pure case +(`inductionOn_pure`). `ext_pure` is an `ext` lemma, so the tactic `ext` applies it, together with +Mathlib's `ext` lemma for intertwining maps. An equality of two intertwining maps out of tensors +becomes an equality of their values on `S.pure p`, for any family of vectors `p`. + +-/ + +/-- The tensors with colors `c : ι → Color K`, the space `⨂[k] i, S.V (c i)`. It is a `def`, not an +`abbrev`, so that goals show `Tensor S c` instead of the product. Mathlib's results on `⨂` apply to +it by unfolding, and its instances are copied from `⨂`. -/ +def Tensor (S : Tensor.Species k G K basisIdx) {ι : Type} (c : ι → Tensor.Color K) : Type := + ⨂[k] i, S.V (c i) + +/-- Tensors add as elements of `⨂[k] i, S.V (c i)`. -/ +noncomputable instance {S : Tensor.Species k G K basisIdx} {ι : Type} {c : ι → Tensor.Color K} : + AddCommGroup (Tensor S c) := + inferInstanceAs (AddCommGroup (⨂[k] i, S.V (c i))) + +/-- Tensors are a vector space over `k`, as `⨂[k] i, S.V (c i)` is. -/ +noncomputable instance {S : Tensor.Species k G K basisIdx} {ι : Type} {c : ι → Tensor.Color K} : + Module k (Tensor S c) := + inferInstanceAs (Module k (⨂[k] i, S.V (c i))) + +namespace Tensor + +variable {ι : Type} {c : ι → Color K} + +namespace Species + +/-- The pure tensor `⨂ₜ i, f i` of a family `f` of vectors, with `f i` in `S.V (c i)` at each +index `i`, such as `u ⊗ α` with the components `u^μ α_ν`. Not every tensor is pure, but every +tensor is a linear combination of pure tensors. -/ +noncomputable def pure (S : Species k G K basisIdx) (f : Π i, S.V (c i)) : Tensor S c := + ⨂ₜ[k] i, f i + +variable {S : Species k G K basisIdx} + +/-- Induction on tensors through pure tensors: every tensor is a linear combination of pure +tensors. -/ +lemma inductionOn_pure {P : Tensor S c → Prop} + (h : ∀ f : Π i, S.V (c i), P (S.pure f)) (hsmul : ∀ (r : k) t, P t → P (r • t)) + (hadd : ∀ t₁ t₂, P t₁ → P t₂ → P (t₁ + t₂)) (t : Tensor S c) : P t := + PiTensorProduct.induction_on (motive := P) t (fun r f => hsmul r _ (h f)) hadd + +/-- Two linear maps out of tensors are equal when they agree on pure tensors. -/ +@[ext] +lemma ext_pure {E : Type*} [AddCommMonoid E] [Module k E] {f g : Tensor S c →ₗ[k] E} + (h : ∀ p : Π i, S.V (c i), f (S.pure p) = g (S.pure p)) : f = g := + PiTensorProduct.ext (MultilinearMap.ext h) + +/-! + +## B. The group action + +### B.1. The action on tensors + +A group element `Λ` acts on every index by the representation of its color, +`Λ • (u ⊗ α) = Λu ⊗ (Λ⁻¹)ᵀα` (`smul_pure`). This is the representation `S.tensorRep c`, +`Representation.piTprod` on `⨂[k] i, S.V (c i)`. It is written `Λ • T` under `open scoped Tensor`. + +-/ + +variable (S) in +/-- The action of the group on tensors, on every index by the representation of its color, +`Λ • (u ⊗ α ⊗ …) = Λu ⊗ (Λ⁻¹)ᵀα ⊗ …`. It is `Representation.piTprod` of the representations of the +colors. Maps of tensors that commute with the action are Mathlib's `Representation.Equiv` and +`Representation.IntertwiningMap` for it. -/ +noncomputable abbrev tensorRep (c : ι → Color K) : Representation k G (Tensor S c) := + Representation.piTprod fun i => S.rep (c i) + +end Species + +variable {S : Species k G K basisIdx} + +-- A `Circle` element `z` is a complex number, and Mathlib lets it act on every complex vector space +-- as multiplication by `z`. So the instances below are scoped to `Tensor`, and the two actions have +-- priority 1100, above the default 1000. Under `open scoped Tensor`, `z • T` is then the action of +-- the species. + +/-- The action `Λ • T` of the group on tensors, `S.tensorRep c Λ T`, available under +`open scoped Tensor`, where it takes priority over Mathlib's scalar actions. -/ +noncomputable scoped instance (priority := 1100) distribMulAction : + DistribMulAction G (Tensor S c) := + DistribMulAction.compHom (M := Module.End k (Tensor S c)) _ (S.tensorRep c) + +/-- The scalar multiplication of `distribMulAction`, found before any scalar action of Mathlib. -/ +noncomputable scoped instance (priority := 1100) smul : SMul G (Tensor S c) := + distribMulAction.toSMul + +/-- The action of the group commutes with the scalars. -/ +scoped instance smulCommClass : SMulCommClass G k (Tensor S c) where + smul_comm g r t := map_smul (S.tensorRep c g) r t + +/-- The scalars commute with the action of the group. -/ +scoped instance smulCommClass' : SMulCommClass k G (Tensor S c) := + .symm _ _ _ + +namespace Species + +/-- On a pure tensor the group acts on each vector by the representation of its color. -/ +@[simp] +lemma smul_pure (g : G) (f : Π i, S.V (c i)) : + g • S.pure f = S.pure fun i => S.rep (c i) g (f i) := + Representation.piTprod_tprod _ _ _ + +/-! + +### B.2. Maps that commute with the group + +A map `φ` of tensors commutes with the group when `φ (Λ • T) = Λ • φ T`, as reindexing, products, +contraction, lowering and raising do. Such maps are Mathlib's `Representation.IntertwiningMap` for +`tensorRep`, or `Representation.Equiv` when they are invertible, so they compose and send invariant +tensors to invariant tensors. For example, lowering the index `ν` of `T^μν` is an equivalence +`(S.tensorRep c).Equiv (S.tensorRep c')` from the colors `c = ![⟨vec, up⟩, ⟨vec, up⟩]` to +`c' = ![⟨vec, up⟩, ⟨vec, down⟩]`, built by `congrAt` (D.4). The contraction `T^μ_ν ↦ T^μ_μ` is an +intertwining map to the tensors with no indices, and it has no inverse. + +The commutation is checked on pure tensors only, where `Λ` acts on each vector. `map_smul_of_pure` +extends the check to all tensors, and `equivOfPure` turns a linear equivalence with this check into +an equivalence of representations. `equiv_smul` and `intertwiningMap_smul` state the commutation +with `•`. A tensor with no indices, a scalar, is invariant (`smul_eq_self_of_isEmpty`). + +-/ + +/-- An intertwining map between tensors commutes with the actions, `φ (Λ T) = Λ φ T`. -/ +lemma intertwiningMap_smul {ι' : Type} {c' : ι' → Color K} + (φ : (S.tensorRep c).IntertwiningMap (S.tensorRep c')) (g : G) (t : Tensor S c) : + φ (g • t) = g • φ t := + Representation.IntertwiningMap.isIntertwining _ _ φ g t + +/-- An equivalence of representations of tensors commutes with the actions, `φ (Λ T) = Λ φ T`. -/ +lemma equiv_smul {ι' : Type} {c' : ι' → Color K} + (φ : (S.tensorRep c).Equiv (S.tensorRep c')) (g : G) (t : Tensor S c) : + φ (g • t) = g • φ t := + Representation.IntertwiningMap.isIntertwining _ _ φ.toIntertwiningMap g t + +/-- A linear or conjugate-linear map of tensors that commutes with `Λ` on pure tensors commutes +with `Λ` on all tensors. -/ +lemma map_smul_of_pure {ι' : Type} {c' : ι' → Color K} {σ : k →+* k} {F : Type} + [FunLike F (Tensor S c) (Tensor S c')] [SemilinearMapClass F σ (Tensor S c) (Tensor S c')] + (f : F) (g : G) (h : ∀ p : Π i, S.V (c i), f (g • S.pure p) = g • f (S.pure p)) + (t : Tensor S c) : f (g • t) = g • f t := + Representation.map_piTprod_of_tprod (τ := Representation.piTprod fun i => S.rep (c' i)) + (f : Tensor S c →ₛₗ[σ] Tensor S c') g h t + +variable {ι' : Type} {c' : ι' → Color K} in +/-- A linear equivalence of tensors that commutes with `Λ` on pure tensors, as an equivalence of +representations. -/ +noncomputable def equivOfPure (e : Tensor S c ≃ₗ[k] Tensor S c') + (h : ∀ (g : G) (p : Π i, S.V (c i)), e (g • S.pure p) = g • e (S.pure p)) : + (S.tensorRep c).Equiv (S.tensorRep c') := + .mk e fun g => LinearMap.ext fun t => map_smul_of_pure e g (h g) t + +variable {ι' : Type} {c' : ι' → Color K} in +@[simp] +lemma equivOfPure_apply (e : Tensor S c ≃ₗ[k] Tensor S c') + (h : ∀ (g : G) (p : Π i, S.V (c i)), e (g • S.pure p) = g • e (S.pure p)) (t : Tensor S c) : + equivOfPure e h t = e t := rfl + +/-- Two equivalences of representations out of tensors are equal when they agree on pure +tensors. -/ +lemma equiv_ext_pure {W : Type*} [AddCommMonoid W] [Module k W] {ρ : Representation k G W} + {φ ψ : (S.tensorRep c).Equiv ρ} (h : ∀ p : Π i, S.V (c i), φ (S.pure p) = ψ (S.pure p)) : + φ = ψ := + Representation.Equiv.ext <| + funext <| LinearMap.congr_fun (ext_pure (f := φ.toLinearMap) (g := ψ.toLinearMap) h) + +/-- A tensor with no indices is invariant, `Λ s = s`. -/ +lemma smul_eq_self_of_isEmpty [IsEmpty ι] (g : G) (t : Tensor S c) : g • t = t := + LinearMap.congr_fun (PiTensorProduct.map_eq_id_of_isEmpty _) t + +/-! + +## C. The basis of tensors + +The components `T^μ_ν` of a tensor are its coordinates in the basis `e_μ ⊗ e^ν` (`tensorBasis`), +Mathlib's `Basis.piTensorProduct` of the bases of the colors. Each basis tensor is a pure tensor of +basis vectors, and the components of a pure tensor are products, `(u ⊗ α)^μ_ν = u^μ α_ν` +(`tensorBasis_repr_pure`). The dimension is the product of the dimensions (`finrank_tensor`). + +The components of `Λ • T` take one matrix of `Λ` per index (`tensorBasis_repr_smul`), as in +`(ΛT)^μ_ν = Λ^μ_σ (Λ⁻¹)^τ_ν T^σ_τ`. Lower indices transform with `Λ⁻¹`, which keeps `u^μ α_μ` +invariant. + +-/ + +/-- The basis `e_μ ⊗ e^ν ⊗ …` of tensors, Mathlib's `Basis.piTensorProduct` of the bases of the +colors. -/ +noncomputable def tensorBasis (S : Species k G K basisIdx) [Fintype ι] (c : ι → Color K) : + Module.Basis (Π i, basisIdx (c i).kind) k (Tensor S c) := + Basis.piTensorProduct fun i => S.basis (c i) + +/-- A basis tensor is the pure tensor of basis vectors, `e_μ ⊗ e^ν ⊗ …`. -/ +lemma tensorBasis_apply [Fintype ι] (x : Π i, basisIdx (c i).kind) : + S.tensorBasis c x = S.pure fun i => S.basis (c i) (x i) := + Basis.piTensorProduct_apply _ _ + +/-- The components of a pure tensor are products, `(u ⊗ α)^μ_ν = u^μ α_ν`. -/ +lemma tensorBasis_repr_pure [Fintype ι] (f : Π i, S.V (c i)) + (x : Π i, basisIdx (c i).kind) : + (S.tensorBasis c).repr (S.pure f) x = ∏ i, (S.basis (c i)).repr (f i) (x i) := + Basis.piTensorProduct_repr_tprod_apply _ _ _ + +/-- Tensors on finitely many indices are a finite-dimensional space, from Mathlib's +`PiTensorProduct.finite`. -/ +instance [Finite ι] : Module.Finite k (Tensor S c) := + inferInstanceAs (Module.Finite k (⨂[k] i, S.V (c i))) + +/-- The dimension of tensors is the product of the dimensions of their indices. -/ +lemma finrank_tensor [Fintype ι] (c : ι → Color K) : + Module.finrank k (Tensor S c) = ∏ i, Fintype.card (basisIdx (c i).kind) := + Module.finrank_piTensorProduct.trans + (Finset.prod_congr rfl fun i _ => Module.finrank_eq_card_basis (S.basis (c i))) + +/-- The components of `g • t`, `(g t)^φ = ∑ ψ, (∏ i, M_i (φ i) (ψ i)) t^ψ`, where `M_i` is the +matrix of `g` in the color of the index `i`. For the colors `![⟨vec, up⟩, ⟨vec, down⟩]` this is +`(ΛT)^μ_ν = Λ^μ_σ (Λ⁻¹)^τ_ν T^σ_τ`. -/ +lemma tensorBasis_repr_smul [Fintype ι] [DecidableEq ι] (g : G) (t : Tensor S c) + (φ : Π i, basisIdx (c i).kind) : + (S.tensorBasis c).repr (g • t) φ = ∑ ψ, (∏ i, LinearMap.toMatrix (S.basis (c i)) + (S.basis (c i)) (S.rep (c i) g) (φ i) (ψ i)) * (S.tensorBasis c).repr t ψ := by + simp_rw [← PiTensorProduct.toMatrix_map_apply] + exact congrFun (LinearMap.toMatrix_mulVec_repr (Basis.piTensorProduct fun i => S.basis (c i)) _ + (Representation.piTprod (fun i => S.rep (c i)) g) t).symm φ + +/-! + +## D. Linear maps at the indices + +Many operations change one index of a tensor and keep the others, such as contracting the index +with a tensor on two indices, `T^…μ… F_μ^ν`, and lowering or raising it with a metric, +`T^μν ↦ T^μ_ν`. They are linear maps at one index (D.2), built from linear maps at every index +(D.1). When the map at the index is an equivalence of representations, so is the map of tensors +(D.4). + +### D.1. A linear map at every index + +`mapIndices f` applies a linear map `f x` at every index `x`, `u ⊗ v ↦ f₀ u ⊗ f₁ v`. It is +Mathlib's `PiTensorProduct.map`, and it commutes with the group when every `f x` does +(`mapIndices_smul`). `congrIndices` is the same for equivalences of representations. + +-/ + +section + +variable {c' : ι → Color K} + +variable (S) in +/-- A linear map `f x` at every index `x`, as in `u ⊗ v ↦ f₀ u ⊗ f₁ v`. It is Mathlib's +`PiTensorProduct.map`. -/ +noncomputable def mapIndices (f : Π x, S.V (c x) →ₗ[k] S.V (c' x)) : Tensor S c →ₗ[k] Tensor S c' := + PiTensorProduct.map f + +/-- On a pure tensor, `mapIndices` applies `f x` to the vector at each index `x`. -/ +lemma mapIndices_pure (f : Π x, S.V (c x) →ₗ[k] S.V (c' x)) (p : Π x, S.V (c x)) : + S.mapIndices f (S.pure p) = S.pure fun x => f x (p x) := + PiTensorProduct.map_tprod _ _ + +/-- Two index-wise maps in sequence are the index-wise map of the composites. -/ +lemma mapIndices_comp {c'' : ι → Color K} (f : Π x, S.V (c x) →ₗ[k] S.V (c' x)) + (g : Π x, S.V (c' x) →ₗ[k] S.V (c'' x)) : + S.mapIndices g ∘ₗ S.mapIndices f = S.mapIndices fun x => g x ∘ₗ f x := + (PiTensorProduct.map_comp g f).symm + +/-- Two index-wise maps in sequence are the index-wise map of the composites, on a tensor. -/ +lemma mapIndices_mapIndices {c'' : ι → Color K} (f : Π x, S.V (c x) →ₗ[k] S.V (c' x)) + (g : Π x, S.V (c' x) →ₗ[k] S.V (c'' x)) (t : Tensor S c) : + S.mapIndices g (S.mapIndices f t) = S.mapIndices (fun x => g x ∘ₗ f x) t := + LinearMap.congr_fun (mapIndices_comp f g) t + +/-- The index-wise map of the identities is the identity. -/ +lemma mapIndices_id : S.mapIndices (c := c) (fun _ => LinearMap.id) = LinearMap.id := + PiTensorProduct.map_id + +/-- The index-wise map of the identities is the identity, on a tensor. -/ +lemma mapIndices_id_apply (t : Tensor S c) : S.mapIndices (fun _ => LinearMap.id) t = t := + LinearMap.congr_fun mapIndices_id t + +/-- Linear maps that commute with the group action at every index commute with it on tensors, +`f (Λ T) = Λ f T`. -/ +lemma mapIndices_smul {f : Π x, S.V (c x) →ₗ[k] S.V (c' x)} + (hf : ∀ x g v, f x (S.rep (c x) g v) = S.rep (c' x) g (f x v)) (g : G) (t : Tensor S c) : + S.mapIndices f (g • t) = g • S.mapIndices f t := + (Representation.IsIntertwiningMap.piTprodMap fun x => ⟨hf x⟩).isIntertwining g t + +variable (S) in +/-- Equivalences of representations `f x` at every index `x`, as an equivalence of representations +of tensors, `u ⊗ v ↦ f₀ u ⊗ f₁ v`. It is `Representation.Equiv.piTprodCongr`. -/ +noncomputable def congrIndices (f : Π x, (S.rep (c x)).Equiv (S.rep (c' x))) : + (S.tensorRep c).Equiv (S.tensorRep c') := + Representation.Equiv.piTprodCongr f + +/-- On a pure tensor, `congrIndices` applies `f x` to the vector at each index `x`. -/ +lemma congrIndices_pure (f : Π x, (S.rep (c x)).Equiv (S.rep (c' x))) (p : Π x, S.V (c x)) : + S.congrIndices f (S.pure p) = S.pure fun x => f x (p x) := + Representation.Equiv.piTprodCongr_tprod f p + +/-! + +### D.2. A linear map at one index + +`mapAt i f h` applies a linear map `f` at the index `i` and keeps the others, `u ⊗ v ↦ u ⊗ f v`. The +map `f` may change the color at `i`, as lowering turns `⟨vec, up⟩` into `⟨vec, down⟩`. So the result +has other colors `c'`, and `h : ∀ x, x ≠ i → c x = c' x` says that they agree with `c` at the other +indices. There the vectors are moved along `h` by `S.cast`. `indexMapsAt i f h` is the family with +`f` at `i` and `S.cast` elsewhere, and `mapAt` is `mapIndices` of it. Contracting with a tensor `F` +on two indices is `mapAt` of `F` read as a linear map. + +-/ + +section + +variable [DecidableEq ι] + +variable (S) in +/-- The family of linear maps with `f` at the index `i` and the identity, moved along `h x`, at +every other index `x`. `mapAt` applies it index by index. -/ +noncomputable def indexMapsAt (i : ι) (f : S.V (c i) →ₗ[k] S.V (c' i)) + (h : ∀ x, x ≠ i → c x = c' x) : Π x, S.V (c x) →ₗ[k] S.V (c' x) := + Function.update (fun x => if hx : x = i then 0 else (S.cast (h x hx)).toLinearMap) i f + +@[simp] +lemma indexMapsAt_apply_self (i : ι) (f : S.V (c i) →ₗ[k] S.V (c' i)) + (h : ∀ x, x ≠ i → c x = c' x) : S.indexMapsAt i f h i = f := + Function.update_self _ _ _ + +@[simp] +lemma indexMapsAt_apply_ne (i : ι) (f : S.V (c i) →ₗ[k] S.V (c' i)) + (h : ∀ x, x ≠ i → c x = c' x) {x : ι} (hx : x ≠ i) : + S.indexMapsAt i f h x = (S.cast (h x hx)).toLinearMap := by + rw [indexMapsAt, Function.update_of_ne hx, dite_eq_right hx] + +/-- A family with `f` at the index `i` and the moves along `h x` at the other indices is +`indexMapsAt i f h`. -/ +lemma eq_indexMapsAt {F : Π x, S.V (c x) →ₗ[k] S.V (c' x)} (i : ι) + (f : S.V (c i) →ₗ[k] S.V (c' i)) (h : ∀ x, x ≠ i → c x = c' x) (hi : F i = f) + (hne : ∀ x (hx : x ≠ i), F x = (S.cast (h x hx)).toLinearMap) : F = S.indexMapsAt i f h := + Function.eq_update_iff.2 ⟨hi, fun x hx => by rw [hne x hx, dite_eq_right hx]⟩ + +/-- `indexMapsAt i f h` commutes with the group action at every index when `f` does. -/ +lemma indexMapsAt_rep (i : ι) (f : S.V (c i) →ₗ[k] S.V (c' i)) (h : ∀ x, x ≠ i → c x = c' x) + (hf : ∀ g v, f (S.rep (c i) g v) = S.rep (c' i) g (f v)) (x : ι) (g : G) (v : S.V (c x)) : + S.indexMapsAt i f h x (S.rep (c x) g v) = S.rep (c' x) g (S.indexMapsAt i f h x v) := by + by_cases hx : x = i + · subst hx + simpa using hf g v + · simpa [hx] using cast_rep (h x hx) g v + +variable (S) in +/-- The linear map `f` at the index `i`, and the identity, moved along `h x`, at every other index +`x`, as in `u ⊗ v ⊗ w ↦ u ⊗ f v ⊗ w`. -/ +noncomputable def mapAt (i : ι) (f : S.V (c i) →ₗ[k] S.V (c' i)) + (h : ∀ x, x ≠ i → c x = c' x) : Tensor S c →ₗ[k] Tensor S c' := + S.mapIndices (S.indexMapsAt i f h) + +/-- On a pure tensor, `mapAt` applies `f` to the vector at `i` and keeps the others, +`u ⊗ v ⊗ w ↦ u ⊗ f v ⊗ w`. -/ +lemma mapAt_pure (i : ι) (f : S.V (c i) →ₗ[k] S.V (c' i)) (h : ∀ x, x ≠ i → c x = c' x) + (p : Π x, S.V (c x)) (q : Π x, S.V (c' x)) (hqi : q i = f (p i)) + (hq : ∀ x (hx : x ≠ i), q x = S.cast (h x hx) (p x)) : + S.mapAt i f h (S.pure p) = S.pure q := by + rw [mapAt, mapIndices_pure] + refine congrArg S.pure (funext fun x => ?_) + by_cases hx : x = i + · subst hx + rw [indexMapsAt_apply_self, hqi] + · rw [indexMapsAt_apply_ne _ _ _ hx, hq x hx] + rfl + +/-- `mapAt` of `f` and then of `g` at the same index is `mapAt` of `g ∘ₗ f`. -/ +lemma mapAt_comp {c'' : ι → Color K} (i : ι) (f : S.V (c i) →ₗ[k] S.V (c' i)) + (g : S.V (c' i) →ₗ[k] S.V (c'' i)) (h : ∀ x, x ≠ i → c x = c' x) + (h' : ∀ x, x ≠ i → c' x = c'' x) : + S.mapAt i g h' ∘ₗ S.mapAt i f h = S.mapAt i (g ∘ₗ f) fun x hx => (h x hx).trans (h' x hx) := by + rw [mapAt, mapAt, mapAt, mapIndices_comp] + refine congrArg _ (eq_indexMapsAt i _ _ (by simp) fun x hx => LinearMap.ext fun v => ?_) + simp [hx] + +/-- `mapAt` of the identity is the identity. -/ +lemma mapAt_id (i : ι) (h : ∀ x, x ≠ i → c x = c x) : + S.mapAt i LinearMap.id h = LinearMap.id := by + rw [mapAt, ← eq_indexMapsAt (F := fun _ => LinearMap.id) i _ h rfl + fun _ _ => LinearMap.ext fun _ => rfl, mapIndices_id] + +/-! + +### D.3. Components + +In components, `mapAt` acts on the one index, `(f T)^…ν… = ∑ μ, f^ν_μ T^…μ…` +(`tensorBasis_repr_mapAt`). + +-/ + +/-- `mapAt` in components, `(f T)^…ν… = ∑ μ, f^ν_μ T^…μ…`, with `f^ν_μ` the matrix of `f`. -/ +lemma tensorBasis_repr_mapAt [Fintype ι] (i : ι) (f : S.V (c i) →ₗ[k] S.V (c' i)) + (h : ∀ x, x ≠ i → c x = c' x) (t : Tensor S c) (φ : Π x, basisIdx (c' x).kind) + (ψ : Π x, basisIdx (c x).kind) + (hψ : ∀ x (hx : x ≠ i), ψ x = cast (congrArg (basisIdx ∘ Color.kind) (h x hx).symm) (φ x)) : + (S.tensorBasis c').repr (S.mapAt i f h t) φ = ∑ μ : basisIdx (c i).kind, + LinearMap.toMatrix (S.basis (c i)) (S.basis (c' i)) f (φ i) μ * + (S.tensorBasis c).repr t (Function.update ψ i μ) := by + induction t using inductionOn_pure with + | hsmul r t ht => + simp only [map_smul, Finsupp.smul_apply, ht, smul_eq_mul, Finset.mul_sum, mul_left_comm r] + | hadd t t' ht ht' => + simp only [map_add, Finsupp.add_apply, ht, ht', mul_add, Finset.sum_add_distrib] + | h p => + -- Split off the index `i`, where `f` acts, from the indices where the label is only moved. + rw [mapAt, mapIndices_pure, tensorBasis_repr_pure, + ← Finset.mul_prod_erase _ _ (Finset.mem_univ i), indexMapsAt_apply_self, + ← LinearMap.toMatrix_mulVec_repr (S.basis (c i)) (S.basis (c' i)), Matrix.mulVec, dotProduct, + Finset.sum_mul] + refine Finset.sum_congr rfl fun μ _ => ?_ + rw [tensorBasis_repr_pure, ← Finset.mul_prod_erase _ _ (Finset.mem_univ i), + Function.update_self, mul_assoc] + refine congrArg _ (congrArg _ (Finset.prod_congr rfl fun x hx => ?_)) + have hx := Finset.ne_of_mem_erase hx + rw [indexMapsAt_apply_ne _ _ _ hx, Function.update_of_ne hx, hψ x hx] + exact basis_repr_cast _ _ _ + +/-! + +### D.4. An equivalence of representations at one index + +`congrAt i f h` applies an equivalence of representations `f` at the index `i`, as `mapAt` does. +The result is again an equivalence of representations, so it commutes with the group and has an +inverse, `congrAt` of `f.symm` (`congrAt_symm`). It is built by `equivOfPure` (B.2), with the +check on pure tensors from `mapIndices_smul`. Lowering with a metric is `congrAt` of the map +`v^μ ↦ η_νμ v^μ`, and raising is its inverse. + +-/ + +variable (S) in +/-- The equivalence of representations `f` at the index `i`, and the identity, moved along `h x`, +at every other index `x`. On a pure tensor, `u ⊗ v ⊗ w ↦ u ⊗ f v ⊗ w`. Its linear map is `mapAt` +of `f`. -/ +noncomputable def congrAt (i : ι) (f : (S.rep (c i)).Equiv (S.rep (c' i))) + (h : ∀ x, x ≠ i → c x = c' x) : (S.tensorRep c).Equiv (S.tensorRep c') := + equivOfPure (.ofLinearMap (S.mapAt i f.toLinearMap h) + (S.mapAt i f.symm.toLinearMap fun x hx => (h x hx).symm) + (by rw [mapAt_comp, show f.toLinearMap ∘ₗ f.symm.toLinearMap = LinearMap.id from + LinearMap.ext f.apply_symm_apply, mapAt_id]) + (by rw [mapAt_comp, show f.symm.toLinearMap ∘ₗ f.toLinearMap = LinearMap.id from + LinearMap.ext f.symm_apply_apply, mapAt_id])) fun g p => + mapIndices_smul (indexMapsAt_rep i _ h (f.toIntertwiningMap.isIntertwining _ _)) g (S.pure p) + +/-- `congrAt` is `mapAt` of the underlying linear map. -/ +lemma congrAt_eq_mapAt (i : ι) (f : (S.rep (c i)).Equiv (S.rep (c' i))) + (h : ∀ x, x ≠ i → c x = c' x) (t : Tensor S c) : + S.congrAt i f h t = S.mapAt i f.toLinearMap h t := rfl + +/-- The inverse of `congrAt` of `f` is `congrAt` of `f.symm`. -/ +lemma congrAt_symm (i : ι) (f : (S.rep (c i)).Equiv (S.rep (c' i))) + (h : ∀ x, x ≠ i → c x = c' x) : + (S.congrAt i f h).symm = S.congrAt i f.symm (fun x hx => (h x hx).symm) := + Representation.Equiv.ext rfl + +end + +end + +end Species + +end Tensor