Documentation

CslibFrontier.Foundations.LinearAlgebra.Tensor.Basic

Finite tensors, restrictions and rank #

A tensor of order three over a commutative semiring R with finite index types X, Y, Z is given by its structure constants T : X → Y → Z → R (Cslib.Tensor). It is the bilinear map Tensor.bil T A B = fun z => ∑ x, ∑ y, T x y z * A x * B y, with A and B the coefficient lists of the two inputs. This is the model of bilinear computation of Bürgisser, Clausen and Shokrollahi, Chapter 14, and the selected products of Pass, Definition 2.1, in which the monomials of a shape are replaced by their index sets.

A restriction of S by the matrices α, β, γ (Tensor.restrict) computes T from S by linear encoding of the two inputs and linear decoding of the output (Tensor.bil_restrict): T.bil A B = γ *ᵥ S.bil (α *ᵥ A) (β *ᵥ B). This is a polynomial packing of one target by one source in the sense of Pass, Definition 2.2. The rank of T is at most r (Tensor.Rank) when T is a restriction of the unit tensor unit r, the r independent scalar multiplications: a bilinear algorithm with r multiplications.

Restrictions compose (Tensor.restrict_restrict), and they are compatible with the tensor product Tensor.tprod and its finite form Tensor.tprodPi, with the direct sum Tensor.dsum and the shared-left sum Tensor.slSum, with the three leg exchanges Tensor.swap12, Tensor.swap23, Tensor.swap13, and with reindexing by equivalences Tensor.reindex. These are the elementary operations on packings of Pass, Observation 2.5 and Lemmas 2.7–2.10, in which renaming the variables of a shape is reindexing.

Matrix multiplication of p × q by q × r matrices is the tensor Tensor.mm p q r.

Main definitions #

Main results #

References #

@[reducible, inline]
abbrev Cslib.Tensor (R : Type u_1) (X : Type u_2) (Y : Type u_3) (Z : Type u_4) :
Type (max (max (max u_1 u_2) u_3) u_4)

A tensor of order three over R with index types X, Y and Z, by its structure constants.

Structural operations #

def Cslib.Tensor.map {R : Type u_1} {R' : Type u_2} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} (f : R → R') (T : Tensor R X Y Z) :
Tensor R' X Y Z

The entries of a tensor, mapped by f.

@[simp]
theorem Cslib.Tensor.map_apply {R : Type u_1} {R' : Type u_2} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} (f : R → R') (T : Tensor R X Y Z) (x : X) (y : Y) (z : Z) :
map f T x y z = f (T x y z)
def Cslib.Tensor.swap12 {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} (T : Tensor R X Y Z) :
Tensor R Y X Z

Exchange the two input legs.

def Cslib.Tensor.swap23 {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} (T : Tensor R X Y Z) :
Tensor R X Z Y

Exchange the right input leg and the output leg.

def Cslib.Tensor.swap13 {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} (T : Tensor R X Y Z) :
Tensor R Z Y X

Exchange the left input leg and the output leg.

@[simp]
theorem Cslib.Tensor.swap12_apply {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} (T : Tensor R X Y Z) (y : Y) (x : X) (z : Z) :
T.swap12 y x z = T x y z
@[simp]
theorem Cslib.Tensor.swap23_apply {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} (T : Tensor R X Y Z) (x : X) (z : Z) (y : Y) :
T.swap23 x z y = T x y z
@[simp]
theorem Cslib.Tensor.swap13_apply {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} (T : Tensor R X Y Z) (z : Z) (y : Y) (x : X) :
T.swap13 z y x = T x y z
@[simp]
theorem Cslib.Tensor.swap12_swap12 {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} (T : Tensor R X Y Z) :
@[simp]
theorem Cslib.Tensor.swap23_swap23 {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} (T : Tensor R X Y Z) :
@[simp]
theorem Cslib.Tensor.swap13_swap13 {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} (T : Tensor R X Y Z) :
def Cslib.Tensor.reindex {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} {X' : Type u_6} {Y' : Type u_7} {Z' : Type u_8} (e₁ : X ≃ X') (e₂ : Y ≃ Y') (e₃ : Z ≃ Z') (T : Tensor R X Y Z) :
Tensor R X' Y' Z'

Reindex a tensor along equivalences of its index types.

@[simp]
theorem Cslib.Tensor.reindex_apply {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} {X' : Type u_6} {Y' : Type u_7} {Z' : Type u_8} (e₁ : X ≃ X') (e₂ : Y ≃ Y') (e₃ : Z ≃ Z') (T : Tensor R X Y Z) (x' : X') (y' : Y') (z' : Z') :
reindex e₁ e₂ e₃ T x' y' z' = T (e₁.symm x') (e₂.symm y') (e₃.symm z')
@[simp]
theorem Cslib.Tensor.reindex_refl {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} (T : Tensor R X Y Z) :
theorem Cslib.Tensor.reindex_reindex {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} {X' : Type u_6} {Y' : Type u_7} {Z' : Type u_8} {X'' : Type u_9} {Y'' : Type u_10} {Z'' : Type u_11} (e₁ : X ≃ X') (e₂ : Y ≃ Y') (e₃ : Z ≃ Z') (f₁ : X' ≃ X'') (f₂ : Y' ≃ Y'') (f₃ : Z' ≃ Z'') (T : Tensor R X Y Z) :
reindex f₁ f₂ f₃ (reindex e₁ e₂ e₃ T) = reindex (e₁.trans f₁) (e₂.trans f₂) (e₃.trans f₃) T
@[simp]
theorem Cslib.Tensor.reindex_symm_reindex {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} {X' : Type u_6} {Y' : Type u_7} {Z' : Type u_8} (e₁ : X ≃ X') (e₂ : Y ≃ Y') (e₃ : Z ≃ Z') (T : Tensor R X Y Z) :
reindex e₁.symm e₂.symm e₃.symm (reindex e₁ e₂ e₃ T) = T
def Cslib.Tensor.tprod {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} {X' : Type u_6} {Y' : Type u_7} {Z' : Type u_8} [Mul R] (T : Tensor R X Y Z) (T' : Tensor R X' Y' Z') :
Tensor R (X × X') (Y × Y') (Z × Z')

The tensor product of two tensors, on product index types.

@[simp]
theorem Cslib.Tensor.tprod_apply {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} {X' : Type u_6} {Y' : Type u_7} {Z' : Type u_8} [Mul R] (T : Tensor R X Y Z) (T' : Tensor R X' Y' Z') (x : X × X') (y : Y × Y') (z : Z × Z') :
T.tprod T' x y z = T x.1 y.1 z.1 * T' x.2 y.2 z.2
def Cslib.Tensor.tprodPi {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} [CommMonoid R] {ι : Type u_12} [Fintype ι] (T : ι → Tensor R X Y Z) :
Tensor R (ι → X) (ι → Y) (ι → Z)

The tensor product of a finite family of tensors on common index types, on function index types.

@[simp]
theorem Cslib.Tensor.tprodPi_apply {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} [CommMonoid R] {ι : Type u_12} [Fintype ι] (T : ι → Tensor R X Y Z) (x : ι → X) (y : ι → Y) (z : ι → Z) :
tprodPi T x y z = ∏ i : ι, T i (x i) (y i) (z i)
def Cslib.Tensor.tpow {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} [CommMonoid R] (d : ℕ) (T : Tensor R X Y Z) :
Tensor R (Fin d → X) (Fin d → Y) (Fin d → Z)

The d-th tensor power.

@[simp]
theorem Cslib.Tensor.tpow_apply {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} [CommMonoid R] (d : ℕ) (T : Tensor R X Y Z) (x : Fin d → X) (y : Fin d → Y) (z : Fin d → Z) :
tpow d T x y z = ∏ i : Fin d, T (x i) (y i) (z i)
def Cslib.Tensor.dsum {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} [Zero R] {ι : Type u_12} [DecidableEq ι] (G : ι → Tensor R X Y Z) :
Tensor R (ι × X) (ι × Y) (ι × Z)

The direct sum of a family of tensors: block diagonal on all three legs.

def Cslib.Tensor.slSum {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} [Zero R] {ι : Type u_12} [DecidableEq ι] (G : ι → Tensor R X Y Z) :
Tensor R X (ι × Y) (ι × Z)

The shared-left sum of a family of tensors with a common left leg: block diagonal on the right input and output legs, the same left input for every summand.

@[simp]
theorem Cslib.Tensor.dsum_apply {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} [Zero R] {ι : Type u_12} [DecidableEq ι] (G : ι → Tensor R X Y Z) (x : ι × X) (y : ι × Y) (z : ι × Z) :
dsum G x y z = if x.1 = y.1 ∧ y.1 = z.1 then G x.1 x.2 y.2 z.2 else 0
@[simp]
theorem Cslib.Tensor.slSum_apply {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} [Zero R] {ι : Type u_12} [DecidableEq ι] (G : ι → Tensor R X Y Z) (x : X) (y : ι × Y) (z : ι × Z) :
slSum G x y z = if y.1 = z.1 then G y.1 x y.2 z.2 else 0
theorem Cslib.Tensor.swap23_slSum {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} [Zero R] {ι : Type u_12} [DecidableEq ι] (G : ι → Tensor R X Y Z) :
(slSum G).swap23 = slSum fun (i : ι) => (G i).swap23

Exchanging the right input and output legs of a shared-left sum exchanges them in every summand.

def Cslib.Tensor.unit {R : Type u_1} [Zero R] [One R] (n : ℕ) :
Tensor R (Fin n) (Fin n) (Fin n)

The unit tensor ⟨n⟩: n independent scalar multiplications.

@[simp]
theorem Cslib.Tensor.unit_apply {R : Type u_1} [Zero R] [One R] (n : ℕ) (i j k : Fin n) :
unit n i j k = if i = j ∧ j = k then 1 else 0
def Cslib.Tensor.mm {R : Type u_1} [Zero R] [One R] (p q r : ℕ) :
Tensor R (Fin p × Fin q) (Fin q × Fin r) (Fin p × Fin r)

The matrix multiplication tensor ⟨p, q, r⟩: multiply a p × q matrix by a q × r matrix. The left input is indexed by (i, j), the right by (j, k), the output by (i, k).

@[simp]
theorem Cslib.Tensor.mm_apply {R : Type u_1} [Zero R] [One R] (p q r : ℕ) (a : Fin p × Fin q) (b : Fin q × Fin r) (c : Fin p × Fin r) :
mm p q r a b c = if a.1 = c.1 ∧ a.2 = b.1 ∧ b.2 = c.2 then 1 else 0
theorem Cslib.Tensor.dsum_const {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} [MulZeroOneClass R] (n : ℕ) (T : Tensor R X Y Z) :
(dsum fun (x : Fin n) => T) = (unit n).tprod T

n independent copies of T are its tensor product with unit n.

Bilinear maps and restrictions #

def Cslib.Tensor.bil {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} [CommSemiring R] [Fintype X] [Fintype Y] (T : Tensor R X Y Z) (A : X → R) (B : Y → R) :
Z → R

The bilinear map of a tensor on coefficient lists.

def Cslib.Tensor.restrict {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} {X' : Type u_6} {Y' : Type u_7} {Z' : Type u_8} [CommSemiring R] [Fintype X'] [Fintype Y'] [Fintype Z'] (α : Matrix X' X R) (β : Matrix Y' Y R) (γ : Matrix Z Z' R) (S : Tensor R X' Y' Z') :
Tensor R X Y Z

Restriction of S along the encoders α, β and the decoder γ: T x y z = ∑ α x' x * β y' y * γ z z' * S x' y' z'.

def Cslib.Tensor.IsRestriction {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} {X' : Type u_6} {Y' : Type u_7} {Z' : Type u_8} [CommSemiring R] [Fintype X'] [Fintype Y'] [Fintype Z'] (T : Tensor R X Y Z) (S : Tensor R X' Y' Z') :

T is a restriction of S: a bilinear algorithm computes T from one evaluation of S.

def Cslib.Tensor.incl {R : Type u_1} {X : Type u_3} {X' : Type u_6} [CommSemiring R] [DecidableEq X'] (f : X → X') :
Matrix X' X R

The inclusion matrix of a map f : X → X': the column x is the unit vector at f x.

@[simp]
theorem Cslib.Tensor.incl_apply {R : Type u_1} {X : Type u_3} {X' : Type u_6} [CommSemiring R] [DecidableEq X'] (f : X → X') (x' : X') (x : X) :
incl f x' x = if f x = x' then 1 else 0
theorem Cslib.Tensor.incl_id {R : Type u_1} {X : Type u_3} [CommSemiring R] [DecidableEq X] :

The inclusion of the identity is the identity matrix.

theorem Cslib.Tensor.bil_restrict {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} {X' : Type u_6} {Y' : Type u_7} {Z' : Type u_8} [CommSemiring R] [Fintype X] [Fintype Y] [Fintype X'] [Fintype Y'] [Fintype Z'] (α : Matrix X' X R) (β : Matrix Y' Y R) (γ : Matrix Z Z' R) (S : Tensor R X' Y' Z') (A : X → R) (B : Y → R) :
(restrict α β γ S).bil A B = γ.mulVec (S.bil (α.mulVec A) (β.mulVec B))

Restriction computes the bilinear map of T from the bilinear map of S: encode the inputs by α and β, evaluate S, decode by γ.

theorem Cslib.Tensor.ext_of_bil {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} [CommSemiring R] [Fintype X] [Fintype Y] {T T' : Tensor R X Y Z} (h : ∀ (A : X → R) (B : Y → R), T.bil A B = T'.bil A B) :
T = T'

Two tensors with the same bilinear map are equal.

theorem Cslib.Tensor.restrict_add {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} {X' : Type u_6} {Y' : Type u_7} {Z' : Type u_8} [CommSemiring R] [Fintype X'] [Fintype Y'] [Fintype Z'] (α : Matrix X' X R) (β : Matrix Y' Y R) (γ : Matrix Z Z' R) (S S' : Tensor R X' Y' Z') :
restrict α β γ (S + S') = restrict α β γ S + restrict α β γ S'

Restriction is linear in the source tensor.

theorem Cslib.Tensor.restrict_smul {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} {X' : Type u_6} {Y' : Type u_7} {Z' : Type u_8} [CommSemiring R] [Fintype X'] [Fintype Y'] [Fintype Z'] (α : Matrix X' X R) (β : Matrix Y' Y R) (γ : Matrix Z Z' R) (c : R) (S : Tensor R X' Y' Z') :
restrict α β γ (c • S) = c • restrict α β γ S

Restriction is linear in the source tensor.

theorem Cslib.Tensor.restrict_one {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} [CommSemiring R] [Fintype X] [Fintype Y] [Fintype Z] [DecidableEq X] [DecidableEq Y] [DecidableEq Z] (S : Tensor R X Y Z) :
restrict 1 1 1 S = S

Restriction by identity matrices is the identity.

theorem Cslib.Tensor.restrict_restrict {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} {X' : Type u_6} {Y' : Type u_7} {Z' : Type u_8} {X'' : Type u_9} {Y'' : Type u_10} {Z'' : Type u_11} [CommSemiring R] [Fintype X'] [Fintype Y'] [Fintype Z'] [Fintype X''] [Fintype Y''] [Fintype Z''] (α : Matrix X' X R) (β : Matrix Y' Y R) (γ : Matrix Z Z' R) (α' : Matrix X'' X' R) (β' : Matrix Y'' Y' R) (γ' : Matrix Z' Z'' R) (U : Tensor R X'' Y'' Z'') :
restrict α β γ (restrict α' β' γ' U) = restrict (α' * α) (β' * β) (γ * γ') U

Composition of restrictions: the matrices multiply.

theorem Cslib.Tensor.IsRestriction.refl {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} [CommSemiring R] [Fintype X] [Fintype Y] [Fintype Z] (T : Tensor R X Y Z) :

A tensor is a restriction of itself.

theorem Cslib.Tensor.IsRestriction.trans {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} {X' : Type u_6} {Y' : Type u_7} {Z' : Type u_8} {X'' : Type u_9} {Y'' : Type u_10} {Z'' : Type u_11} [CommSemiring R] [Fintype X'] [Fintype Y'] [Fintype Z'] [Fintype X''] [Fintype Y''] [Fintype Z''] {T : Tensor R X Y Z} {S : Tensor R X' Y' Z'} {U : Tensor R X'' Y'' Z''} (hT : T.IsRestriction S) (hS : S.IsRestriction U) :

Restrictions compose.

Leg exchanges and reindexing of restrictions #

theorem Cslib.Tensor.swap12_restrict {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} {X' : Type u_6} {Y' : Type u_7} {Z' : Type u_8} [CommSemiring R] [Fintype X'] [Fintype Y'] [Fintype Z'] (α : Matrix X' X R) (β : Matrix Y' Y R) (γ : Matrix Z Z' R) (S : Tensor R X' Y' Z') :
(restrict α β γ S).swap12 = restrict β α γ S.swap12

Exchanging the inputs of a restriction exchanges the encoders.

theorem Cslib.Tensor.swap23_restrict {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} {X' : Type u_6} {Y' : Type u_7} {Z' : Type u_8} [CommSemiring R] [Fintype X'] [Fintype Y'] [Fintype Z'] (α : Matrix X' X R) (β : Matrix Y' Y R) (γ : Matrix Z Z' R) (S : Tensor R X' Y' Z') :

Exchanging the right input and the output of a restriction transposes the right encoder and the decoder and exchanges them (the transposition principle).

theorem Cslib.Tensor.swap13_restrict {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} {X' : Type u_6} {Y' : Type u_7} {Z' : Type u_8} [CommSemiring R] [Fintype X'] [Fintype Y'] [Fintype Z'] (α : Matrix X' X R) (β : Matrix Y' Y R) (γ : Matrix Z Z' R) (S : Tensor R X' Y' Z') :

Exchanging the left input and the output of a restriction transposes the left encoder and the decoder and exchanges them.

theorem Cslib.Tensor.IsRestriction.swap12 {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} {X' : Type u_6} {Y' : Type u_7} {Z' : Type u_8} [CommSemiring R] [Fintype X'] [Fintype Y'] [Fintype Z'] {T : Tensor R X Y Z} {S : Tensor R X' Y' Z'} (h : T.IsRestriction S) :
theorem Cslib.Tensor.IsRestriction.swap23 {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} {X' : Type u_6} {Y' : Type u_7} {Z' : Type u_8} [CommSemiring R] [Fintype X'] [Fintype Y'] [Fintype Z'] {T : Tensor R X Y Z} {S : Tensor R X' Y' Z'} (h : T.IsRestriction S) :
theorem Cslib.Tensor.IsRestriction.swap13 {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} {X' : Type u_6} {Y' : Type u_7} {Z' : Type u_8} [CommSemiring R] [Fintype X'] [Fintype Y'] [Fintype Z'] {T : Tensor R X Y Z} {S : Tensor R X' Y' Z'} (h : T.IsRestriction S) :
theorem Cslib.Tensor.restrict_incl {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} {X' : Type u_6} {Y' : Type u_7} {Z' : Type u_8} [CommSemiring R] [Fintype X'] [Fintype Y'] [Fintype Z'] [DecidableEq X'] [DecidableEq Y'] [DecidableEq Z'] (f : X → X') (g : Y → Y') (h : Z → Z') (S : Tensor R X' Y' Z') :
restrict (incl f) (incl g) (incl h).transpose S = fun (x : X) (y : Y) (z : Z) => S (f x) (g y) (h z)

Restriction along inclusion matrices is precomposition with the maps.

theorem Cslib.Tensor.isRestriction_reindex {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} {X' : Type u_6} {Y' : Type u_7} {Z' : Type u_8} [CommSemiring R] [Fintype X] [Fintype Y] [Fintype Z] (e₁ : X ≃ X') (e₂ : Y ≃ Y') (e₃ : Z ≃ Z') (T : Tensor R X Y Z) :
(reindex e₁ e₂ e₃ T).IsRestriction T

A reindexed tensor is a restriction of the original, by permutation matrices.

theorem Cslib.Tensor.isRestriction_of_reindex {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} {X' : Type u_6} {Y' : Type u_7} {Z' : Type u_8} [CommSemiring R] [Fintype X'] [Fintype Y'] [Fintype Z'] (e₁ : X ≃ X') (e₂ : Y ≃ Y') (e₃ : Z ≃ Z') (T : Tensor R X Y Z) :
T.IsRestriction (reindex e₁ e₂ e₃ T)

A tensor is a restriction of its reindexing.

theorem Cslib.Tensor.IsRestriction.reindex_source {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} {X' : Type u_6} {Y' : Type u_7} {Z' : Type u_8} {X'' : Type u_9} {Y'' : Type u_10} {Z'' : Type u_11} [CommSemiring R] [Fintype X'] [Fintype Y'] [Fintype Z'] [Fintype X''] [Fintype Y''] [Fintype Z''] {T : Tensor R X Y Z} {S : Tensor R X' Y' Z'} (e₁ : X' ≃ X'') (e₂ : Y' ≃ Y'') (e₃ : Z' ≃ Z'') (h : T.IsRestriction S) :
T.IsRestriction (reindex e₁ e₂ e₃ S)

Restriction transfers along reindexings of the source.

theorem Cslib.Tensor.reindex_restrict {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} {X' : Type u_6} {Y' : Type u_7} {Z' : Type u_8} {X'' : Type u_9} {Y'' : Type u_10} {Z'' : Type u_11} [CommSemiring R] [Fintype X'] [Fintype Y'] [Fintype Z'] (α : Matrix X' X R) (β : Matrix Y' Y R) (γ : Matrix Z Z' R) (S : Tensor R X' Y' Z') (e₁ : X ≃ X'') (e₂ : Y ≃ Y'') (e₃ : Z ≃ Z'') :
reindex e₁ e₂ e₃ (restrict α β γ S) = restrict (α.submatrix id ⇑e₁.symm) (β.submatrix id ⇑e₂.symm) (γ.submatrix (⇑e₃.symm) id) S

Reindexing a restriction reindexes the target-side indices of its matrices.

theorem Cslib.Tensor.IsRestriction.reindex_target {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} {X' : Type u_6} {Y' : Type u_7} {Z' : Type u_8} {X'' : Type u_9} {Y'' : Type u_10} {Z'' : Type u_11} [CommSemiring R] [Fintype X'] [Fintype Y'] [Fintype Z'] {T : Tensor R X Y Z} {S : Tensor R X' Y' Z'} (e₁ : X ≃ X'') (e₂ : Y ≃ Y'') (e₃ : Z ≃ Z'') (h : T.IsRestriction S) :
(reindex e₁ e₂ e₃ T).IsRestriction S

Restriction transfers along reindexings of the target.

Tensor products of restrictions #

theorem Cslib.Tensor.restrict_tprod {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} {X' : Type u_6} {Y' : Type u_7} {Z' : Type u_8} {X'' : Type u_9} {Y'' : Type u_10} {Z'' : Type u_11} [CommSemiring R] [Fintype X'] [Fintype Y'] [Fintype Z'] [Fintype X''] [Fintype Y''] [Fintype Z''] (α : Matrix X' X R) (β : Matrix Y' Y R) (γ : Matrix Z Z' R) (S : Tensor R X' Y' Z') {X₂ : Type u_12} {Y₂ : Type u_13} {Z₂ : Type u_14} (α' : Matrix X'' X₂ R) (β' : Matrix Y'' Y₂ R) (γ' : Matrix Z₂ Z'' R) (S' : Tensor R X'' Y'' Z'') :
(restrict α β γ S).tprod (restrict α' β' γ' S') = restrict (Matrix.kroneckerMap (fun (x1 x2 : R) => x1 * x2) α α') (Matrix.kroneckerMap (fun (x1 x2 : R) => x1 * x2) β β') (Matrix.kroneckerMap (fun (x1 x2 : R) => x1 * x2) γ γ') (S.tprod S')

Restriction is compatible with tensor products: the matrices multiply as Kronecker products.

theorem Cslib.Tensor.IsRestriction.tprod {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} {X' : Type u_6} {Y' : Type u_7} {Z' : Type u_8} {X'' : Type u_9} {Y'' : Type u_10} {Z'' : Type u_11} [CommSemiring R] [Fintype X'] [Fintype Y'] [Fintype Z'] [Fintype X''] [Fintype Y''] [Fintype Z''] {X₂ : Type u_12} {Y₂ : Type u_13} {Z₂ : Type u_14} {T : Tensor R X Y Z} {S : Tensor R X' Y' Z'} {T' : Tensor R X₂ Y₂ Z₂} {S' : Tensor R X'' Y'' Z''} (h : T.IsRestriction S) (h' : T'.IsRestriction S') :
(T.tprod T').IsRestriction (S.tprod S')
def Cslib.Tensor.piKronecker {R : Type u_1} {X : Type u_3} {X' : Type u_6} [CommSemiring R] {ι : Type u_12} [Fintype ι] (α : ι → Matrix X' X R) :
Matrix (ι → X') (ι → X) R

The Kronecker product of a family of matrices, on function index types.

@[simp]
theorem Cslib.Tensor.piKronecker_apply {R : Type u_1} {X : Type u_3} {X' : Type u_6} [CommSemiring R] {ι : Type u_12} [Fintype ι] (α : ι → Matrix X' X R) (x' : ι → X') (x : ι → X) :
piKronecker α x' x = ∏ i : ι, α i (x' i) (x i)
theorem Cslib.Tensor.restrict_tprodPi {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} {X' : Type u_6} {Y' : Type u_7} {Z' : Type u_8} [CommSemiring R] {ι : Type u_12} [Fintype ι] [DecidableEq ι] [Fintype X'] [Fintype Y'] [Fintype Z'] (α : ι → Matrix X' X R) (β : ι → Matrix Y' Y R) (γ : ι → Matrix Z Z' R) (S : ι → Tensor R X' Y' Z') :
(tprodPi fun (i : ι) => restrict (α i) (β i) (γ i) (S i)) = restrict (piKronecker α) (piKronecker β) (piKronecker γ) (tprodPi S)

Restriction is compatible with finite tensor products.

theorem Cslib.Tensor.IsRestriction.tprodPi {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} {X' : Type u_6} {Y' : Type u_7} {Z' : Type u_8} [CommSemiring R] {ι : Type u_12} [Fintype ι] [DecidableEq ι] [Fintype X'] [Fintype Y'] [Fintype Z'] {T : ι → Tensor R X Y Z} {S : ι → Tensor R X' Y' Z'} (h : ∀ (i : ι), (T i).IsRestriction (S i)) :
theorem Cslib.Tensor.IsRestriction.tpow {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} {X' : Type u_6} {Y' : Type u_7} {Z' : Type u_8} [CommSemiring R] [Fintype X'] [Fintype Y'] [Fintype Z'] {T : Tensor R X Y Z} {S : Tensor R X' Y' Z'} (h : T.IsRestriction S) (d : ℕ) :
theorem Cslib.Tensor.tprod_tprodPi {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} [CommSemiring R] {ι : Type u_12} {κ : Type u_13} [Fintype ι] [Fintype κ] (T : ι → Tensor R X Y Z) (T' : κ → Tensor R X Y Z) :

The tensor product of two finite tensor products is a finite tensor product over the sum of the index types.

theorem Cslib.Tensor.tprodPi_comp_equiv {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} [CommSemiring R] {ι : Type u_12} {κ : Type u_13} [Fintype ι] [Fintype κ] (e : κ ≃ ι) (T : ι → Tensor R X Y Z) :

A finite tensor product reindexed along a bijection of the index set.

Direct sums and shared-left sums of restrictions #

def Cslib.Tensor.blockDiag {R : Type u_1} {X : Type u_3} {X' : Type u_6} [CommSemiring R] {ι : Type u_12} [DecidableEq ι] (M : ι → Matrix X' X R) :
Matrix (ι × X') (ι × X) R

The block diagonal matrix of a family of matrices.

@[simp]
theorem Cslib.Tensor.blockDiag_apply {R : Type u_1} {X : Type u_3} {X' : Type u_6} [CommSemiring R] {ι : Type u_12} [DecidableEq ι] (M : ι → Matrix X' X R) (x' : ι × X') (x : ι × X) :
blockDiag M x' x = if x'.1 = x.1 then M x.1 x'.2 x.2 else 0
theorem Cslib.Tensor.restrict_dsum {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} {X' : Type u_6} {Y' : Type u_7} {Z' : Type u_8} [CommSemiring R] {ι : Type u_12} [Fintype ι] [DecidableEq ι] [Fintype X'] [Fintype Y'] [Fintype Z'] (α : ι → Matrix X' X R) (β : ι → Matrix Y' Y R) (γ : ι → Matrix Z Z' R) (S : ι → Tensor R X' Y' Z') :
(dsum fun (i : ι) => restrict (α i) (β i) (γ i) (S i)) = restrict (blockDiag α) (blockDiag β) (blockDiag γ) (dsum S)

Restriction is compatible with direct sums, by block diagonal matrices.

theorem Cslib.Tensor.IsRestriction.dsum {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} {X' : Type u_6} {Y' : Type u_7} {Z' : Type u_8} [CommSemiring R] {ι : Type u_12} [Fintype ι] [DecidableEq ι] [Fintype X'] [Fintype Y'] [Fintype Z'] {T : ι → Tensor R X Y Z} {S : ι → Tensor R X' Y' Z'} (h : ∀ (i : ι), (T i).IsRestriction (S i)) :
theorem Cslib.Tensor.restrict_slSum {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} {X' : Type u_6} {Y' : Type u_7} {Z' : Type u_8} [CommSemiring R] {ι : Type u_12} [Fintype ι] [DecidableEq ι] [Fintype X'] [Fintype Y'] [Fintype Z'] (α : Matrix X' X R) (β : ι → Matrix Y' Y R) (γ : ι → Matrix Z Z' R) (S : ι → Tensor R X' Y' Z') :
(slSum fun (i : ι) => restrict α (β i) (γ i) (S i)) = restrict α (blockDiag β) (blockDiag γ) (slSum S)

Restriction is compatible with shared-left sums: the left encoder is common, the right encoders and decoders are block diagonal.

theorem Cslib.Tensor.isRestriction_dsum_comp {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} [CommSemiring R] {ι : Type u_12} {κ : Type u_13} [Fintype ι] [DecidableEq ι] [DecidableEq κ] [Fintype X] [Fintype Y] [Fintype Z] (G : ι → Tensor R X Y Z) (e : κ → ι) (he : Function.Injective e) :

Deleting and reordering summands of a direct sum is a restriction, along an injection of the index sets.

theorem Cslib.Tensor.slSum_comp_eq_restrict {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} [CommSemiring R] {ι : Type u_12} {κ : Type u_13} [Fintype ι] [DecidableEq ι] [DecidableEq κ] [Fintype X] [Fintype Y] [Fintype Z] [DecidableEq X] [DecidableEq Y] [DecidableEq Z] (G : ι → Tensor R X Y Z) (e : κ → ι) (he : Function.Injective e) :

Deleting and reordering summands of a shared-left sum is a restriction with the identity on the left leg.

theorem Cslib.Tensor.isRestriction_slSum_comp {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} [CommSemiring R] {ι : Type u_12} {κ : Type u_13} [Fintype ι] [DecidableEq ι] [DecidableEq κ] [Fintype X] [Fintype Y] [Fintype Z] (G : ι → Tensor R X Y Z) (e : κ → ι) (he : Function.Injective e) :
theorem Cslib.Tensor.tprod_slSum {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} {X' : Type u_6} {Y' : Type u_7} {Z' : Type u_8} [CommSemiring R] {ι : Type u_12} {κ : Type u_13} [DecidableEq ι] [DecidableEq κ] (G : ι → Tensor R X Y Z) (G' : κ → Tensor R X' Y' Z') :
(slSum G).tprod (slSum G') = reindex (Equiv.refl (X × X')) (Equiv.prodProdProdComm ι κ Y Y') (Equiv.prodProdProdComm ι κ Z Z') (slSum fun (p : ι × κ) => (G p.1).tprod (G' p.2))

The tensor product of two shared-left sums is a shared-left sum over pairs of summands.

theorem Cslib.Tensor.tpow_slSum {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} [CommSemiring R] {ι : Type u_12} [DecidableEq ι] (d : ℕ) (G : ι → Tensor R X Y Z) :
tpow d (slSum G) = reindex (Equiv.refl (Fin d → X)) (Equiv.arrowProdEquivProdArrow (Fin d) (fun (x : Fin d) => ι) fun (x : Fin d) => Y).symm (Equiv.arrowProdEquivProdArrow (Fin d) (fun (x : Fin d) => ι) fun (x : Fin d) => Z).symm (slSum fun (w : Fin d → ι) => tprodPi fun (i : Fin d) => G (w i))

A tensor power of a shared-left sum is the shared-left sum, over words, of the finite tensor products of the summands along the word.

Rearranging tensor products and direct sums #

The isomorphisms of Pass, Lemma 2.10, as equalities up to reindexing.

theorem Cslib.Tensor.tprod_comm {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} {X' : Type u_6} {Y' : Type u_7} {Z' : Type u_8} [CommSemiring R] (T : Tensor R X Y Z) (T' : Tensor R X' Y' Z') :

The tensor product is commutative up to reindexing.

theorem Cslib.Tensor.tprod_assoc {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} {X' : Type u_6} {Y' : Type u_7} {Z' : Type u_8} {X'' : Type u_9} {Y'' : Type u_10} {Z'' : Type u_11} [CommSemiring R] (T : Tensor R X Y Z) (T' : Tensor R X' Y' Z') (T'' : Tensor R X'' Y'' Z'') :
(T.tprod T').tprod T'' = reindex (Equiv.prodAssoc X X' X'').symm (Equiv.prodAssoc Y Y' Y'').symm (Equiv.prodAssoc Z Z' Z'').symm (T.tprod (T'.tprod T''))

The tensor product is associative up to reindexing.

theorem Cslib.Tensor.tprod_reindex_right {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} {X' : Type u_6} {Y' : Type u_7} {Z' : Type u_8} {X'' : Type u_9} {Y'' : Type u_10} {Z'' : Type u_11} [CommSemiring R] (T : Tensor R X Y Z) (e₁ : X' ≃ X'') (e₂ : Y' ≃ Y'') (e₃ : Z' ≃ Z'') (T' : Tensor R X' Y' Z') :
T.tprod (reindex e₁ e₂ e₃ T') = reindex ((Equiv.refl X).prodCongr e₁) ((Equiv.refl Y).prodCongr e₂) ((Equiv.refl Z).prodCongr e₃) (T.tprod T')

Reindexing the second factor of a tensor product.

theorem Cslib.Tensor.tprod_tprod_tprod_comm {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} {X' : Type u_6} {Y' : Type u_7} {Z' : Type u_8} {X'' : Type u_9} {Y'' : Type u_10} {Z'' : Type u_11} [CommSemiring R] {X₂ : Type u_12} {Y₂ : Type u_13} {Z₂ : Type u_14} {X₃ : Type u_15} {Y₃ : Type u_16} {Z₃ : Type u_17} {X₄ : Type u_18} {Y₄ : Type u_19} {Z₄ : Type u_20} (A : Tensor R X Y Z) (B : Tensor R X' Y' Z') (A' : Tensor R X'' Y'' Z'') (B' : Tensor R X₂ Y₂ Z₂) (A'' : Tensor R X₃ Y₃ Z₃) (B'' : Tensor R X₄ Y₄ Z₄) :
(A.tprod B).tprod ((A'.tprod B').tprod (A''.tprod B'')) = reindex ((Equiv.prodProdProdComm X (X'' × X₃) X' (X₂ × X₄)).trans ((Equiv.refl (X × X')).prodCongr (Equiv.prodProdProdComm X'' X₃ X₂ X₄))) ((Equiv.prodProdProdComm Y (Y'' × Y₃) Y' (Y₂ × Y₄)).trans ((Equiv.refl (Y × Y')).prodCongr (Equiv.prodProdProdComm Y'' Y₃ Y₂ Y₄))) ((Equiv.prodProdProdComm Z (Z'' × Z₃) Z' (Z₂ × Z₄)).trans ((Equiv.refl (Z × Z')).prodCongr (Equiv.prodProdProdComm Z'' Z₃ Z₂ Z₄))) ((A.tprod (A'.tprod A'')).tprod (B.tprod (B'.tprod B'')))

Regrouping three tensor products of pairs into a tensor product of two triples.

theorem Cslib.Tensor.swap12_tprod {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} {X' : Type u_6} {Y' : Type u_7} {Z' : Type u_8} [CommSemiring R] (T : Tensor R X Y Z) (T' : Tensor R X' Y' Z') :

The leg exchanges distribute over tensor products.

theorem Cslib.Tensor.swap13_tprod {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} {X' : Type u_6} {Y' : Type u_7} {Z' : Type u_8} [CommSemiring R] (T : Tensor R X Y Z) (T' : Tensor R X' Y' Z') :
theorem Cslib.Tensor.swap23_tprod {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} {X' : Type u_6} {Y' : Type u_7} {Z' : Type u_8} [CommSemiring R] (T : Tensor R X Y Z) (T' : Tensor R X' Y' Z') :
theorem Cslib.Tensor.swap12_dsum {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} [CommSemiring R] {ι : Type u_12} [DecidableEq ι] (G : ι → Tensor R X Y Z) :
(dsum G).swap12 = dsum fun (i : ι) => (G i).swap12

The leg exchanges distribute over direct sums.

theorem Cslib.Tensor.swap13_dsum {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} [CommSemiring R] {ι : Type u_12} [DecidableEq ι] (G : ι → Tensor R X Y Z) :
(dsum G).swap13 = dsum fun (i : ι) => (G i).swap13
theorem Cslib.Tensor.tprod_dsum {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} {X' : Type u_6} {Y' : Type u_7} {Z' : Type u_8} [CommSemiring R] {ι : Type u_12} {κ : Type u_13} [DecidableEq ι] [DecidableEq κ] (G : ι → Tensor R X Y Z) (G' : κ → Tensor R X' Y' Z') :
(dsum G).tprod (dsum G') = reindex (Equiv.prodProdProdComm ι κ X X') (Equiv.prodProdProdComm ι κ Y Y') (Equiv.prodProdProdComm ι κ Z Z') (dsum fun (p : ι × κ) => (G p.1).tprod (G' p.2))

The tensor product of two direct sums is a direct sum over pairs of summands.

theorem Cslib.Tensor.tprod_dsum_left {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} {X' : Type u_6} {Y' : Type u_7} {Z' : Type u_8} [CommSemiring R] {ι : Type u_12} [DecidableEq ι] (G : ι → Tensor R X Y Z) (S : Tensor R X' Y' Z') :
(dsum G).tprod S = reindex (Equiv.prodAssoc ι X X').symm (Equiv.prodAssoc ι Y Y').symm (Equiv.prodAssoc ι Z Z').symm (dsum fun (i : ι) => (G i).tprod S)

A tensor product with a direct sum on the left is a direct sum of tensor products.

theorem Cslib.Tensor.dsum_dsum {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} [CommSemiring R] {ι : Type u_12} {κ : Type u_13} [DecidableEq ι] [DecidableEq κ] (G : ι → κ → Tensor R X Y Z) :
(dsum fun (i : ι) => dsum (G i)) = reindex (Equiv.prodAssoc ι κ X) (Equiv.prodAssoc ι κ Y) (Equiv.prodAssoc ι κ Z) (dsum fun (p : ι × κ) => G p.1 p.2)

A direct sum of direct sums is a direct sum over pairs.

theorem Cslib.Tensor.isRestriction_dsum_const {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} [CommSemiring R] [Fintype X] [Fintype Y] [Fintype Z] {ι : Type u_12} [Fintype ι] [DecidableEq ι] (i : ι) (T : Tensor R X Y Z) :
T.IsRestriction (dsum fun (x : ι) => T)

A summand of a direct sum of copies of T is a restriction of the sum.

theorem Cslib.Tensor.isRestriction_dsum_const_of_card_le {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} [CommSemiring R] [Fintype X] [Fintype Y] [Fintype Z] {ι : Type u_12} {κ : Type u_13} [Fintype ι] [DecidableEq ι] [Fintype κ] [DecidableEq κ] (h : Fintype.card ι ≤ Fintype.card κ) (T : Tensor R X Y Z) :
(dsum fun (x : ι) => T).IsRestriction (dsum fun (x : κ) => T)

Fewer copies of T are a restriction of more copies.

Rank #

def Cslib.Tensor.Rank {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} [CommSemiring R] (r : ℕ) (T : Tensor R X Y Z) :

T has rank at most r: it is a restriction of unit r, so a bilinear algorithm with r scalar multiplications computes it.

theorem Cslib.Tensor.restrict_unit {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} [CommSemiring R] {n : ℕ} (α : Matrix (Fin n) X R) (β : Matrix (Fin n) Y R) (γ : Matrix Z (Fin n) R) (x : X) (y : Y) (z : Z) :
restrict α β γ (unit n) x y z = ∑ k : Fin n, α k x * β k y * γ z k

A restriction of the unit tensor is a sum of r rank-one tensors.

The tensor product of two unit tensors is a unit tensor.

The direct sum of n unit tensors unit m is unit (n * m).

theorem Cslib.Tensor.Rank.of_isRestriction {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} {X' : Type u_6} {Y' : Type u_7} {Z' : Type u_8} [CommSemiring R] [Fintype X'] [Fintype Y'] [Fintype Z'] {T : Tensor R X Y Z} {S : Tensor R X' Y' Z'} {r : ℕ} (h : T.IsRestriction S) (hS : Rank r S) :
Rank r T
theorem Cslib.Tensor.isRestriction_unit_of_le {R : Type u_1} [CommSemiring R] {r r' : ℕ} (h : r ≤ r') :

unit r is a restriction of unit r' for r ≤ r'.

theorem Cslib.Tensor.Rank.mono {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} [CommSemiring R] {T : Tensor R X Y Z} {r r' : ℕ} (h : Rank r T) (hr : r ≤ r') :
Rank r' T
theorem Cslib.Tensor.Rank.tprod {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} [CommSemiring R] {X₂ : Type u_12} {Y₂ : Type u_13} {Z₂ : Type u_14} {T : Tensor R X Y Z} {T' : Tensor R X₂ Y₂ Z₂} {r r' : ℕ} (h : Rank r T) (h' : Rank r' T') :
Rank (r * r') (T.tprod T')
theorem Cslib.Tensor.Rank.dsum {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} [CommSemiring R] {T : Tensor R X Y Z} {r : ℕ} (n : ℕ) (h : Rank r T) :
Rank (n * r) (Tensor.dsum fun (x : Fin n) => T)
theorem Cslib.Tensor.Rank.swap12 {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} [CommSemiring R] {T : Tensor R X Y Z} {r : ℕ} (h : Rank r T) :
theorem Cslib.Tensor.Rank.swap23 {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} [CommSemiring R] {T : Tensor R X Y Z} {r : ℕ} (h : Rank r T) :
theorem Cslib.Tensor.Rank.swap13 {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} [CommSemiring R] {T : Tensor R X Y Z} {r : ℕ} (h : Rank r T) :
theorem Cslib.Tensor.Rank.reindex {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} {X' : Type u_6} {Y' : Type u_7} {Z' : Type u_8} [CommSemiring R] {T : Tensor R X Y Z} {r : ℕ} (h : Rank r T) (e₁ : X ≃ X') (e₂ : Y ≃ Y') (e₃ : Z ≃ Z') :
Rank r (Tensor.reindex e₁ e₂ e₃ T)
theorem Cslib.Tensor.Rank.tprodPi {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} [CommSemiring R] {ι : Type u_12} [Fintype ι] {T : ι → Tensor R X Y Z} {r : ι → ℕ} (h : ∀ (i : ι), Rank (r i) (T i)) :
Rank (∏ i : ι, r i) (Tensor.tprodPi T)
theorem Cslib.Tensor.Rank.tpow {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} [CommSemiring R] {T : Tensor R X Y Z} {r : ℕ} (h : Rank r T) (d : ℕ) :
Rank (r ^ d) (Tensor.tpow d T)

Matrix multiplication #

theorem Cslib.Tensor.bil_mm {R : Type u_1} [CommSemiring R] (p q r : ℕ) (A : Fin p × Fin q → R) (B : Fin q × Fin r → R) (c : Fin p × Fin r) :
(mm p q r).bil A B c = ∑ j : Fin q, A (c.1, j) * B (j, c.2)

The bilinear map of mm p q r is matrix multiplication.

theorem Cslib.Tensor.rank_mm {R : Type u_1} [CommSemiring R] (p q r : ℕ) :
Rank (p * q * r) (mm p q r)

The trivial algorithm: p q r scalar multiplications.

Matrix multiplication tensors multiply as block matrix multiplication.

theorem Cslib.Tensor.swap12_mm {R : Type u_1} [CommSemiring R] (p q r : ℕ) :
(mm p q r).swap12 = reindex (Equiv.prodComm (Fin r) (Fin q)) (Equiv.prodComm (Fin q) (Fin p)) (Equiv.prodComm (Fin r) (Fin p)) (mm r q p)

Exchanging the inputs of matrix multiplication exchanges the outer dimensions (Pass, §2.1, role exchanges).

theorem Cslib.Tensor.swap13_mm {R : Type u_1} [CommSemiring R] (p q r : ℕ) :
(mm p q r).swap13 = reindex (Equiv.refl (Fin p × Fin r)) (Equiv.prodComm (Fin r) (Fin q)) (Equiv.refl (Fin p × Fin q)) (mm p r q)

Exchanging the left input and the output of matrix multiplication exchanges the inner dimension with the right one.

theorem Cslib.Tensor.isRestriction_mm_tprod_swaps {R : Type u_1} [CommSemiring R] (k : ℕ) :
(mm k k k).IsRestriction ((mm 1 1 k).tprod ((mm 1 1 k).swap12.tprod (mm 1 1 k).swap13))

mm 1 1 k tensored with its two role exchanges computes mm k k k (Pass, proof of Lemma 4.2).

theorem Cslib.Tensor.isRestriction_tprod_swaps_mm {R : Type u_1} [CommSemiring R] (k : ℕ) :
((mm 1 1 k).tprod ((mm 1 1 k).swap12.tprod (mm 1 1 k).swap13)).IsRestriction (mm k k k)

mm k k k computes mm 1 1 k tensored with its two role exchanges.

theorem Cslib.Tensor.isRestriction_mm_of_eq {R : Type u_1} [CommSemiring R] {p q r p' q' r' : ℕ} (hp : p = p') (hq : q = q') (hr : r = r') :
(mm p q r).IsRestriction (mm p' q' r')

Matrix multiplication tensors with equal dimensions restrict to each other.

theorem Cslib.Tensor.isRestriction_mm_of_le {R : Type u_1} [CommSemiring R] {n n' : ℕ} (h : n ≤ n') :
(mm n n n).IsRestriction (mm n' n' n')

Zero padding of matrices: mm n n n is a restriction of mm n' n' n' for n ≤ n'.

theorem Cslib.Tensor.isRestriction_mm_pow_tpow {R : Type u_1} [CommSemiring R] (v m : ℕ) :
(mm (v ^ m) (v ^ m) (v ^ m)).IsRestriction (tpow m (mm v v v))

Tensor powers of matrix multiplication are matrix multiplication of the power.

mm 1 1 1 is the unit tensor unit 1, up to reindexing.

theorem Cslib.Tensor.slSum_const {R : Type u_1} {X : Type u_3} {Y : Type u_4} {Z : Type u_5} [CommSemiring R] (n : ℕ) (T : Tensor R X Y Z) :

The shared-left sum of n copies of T is T tensored with mm 1 1 n.