Download data/lean/OAI/LinearAlgebra/MatrixFields/Tensors/TerminalRelabel.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 23 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/LinearAlgebra/MatrixFields/Tensors/TerminalRelabel.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/LinearAlgebra/MatrixFields/Tensors/TerminalRelabel.lean
-
curl -L -o TerminalRelabel.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/LinearAlgebra/MatrixFields/Tensors/TerminalRelabel.lean
23 kB
| import Mathlib | |
| import OAI.LinearAlgebra.MatrixFields.Arithmetic.ComplexArithmeticLowerBound | |
| namespace OAI | |
| namespace MatrixAllFields | |
| open scoped BigOperators Topology Polynomial | |
| section | |
| open scoped BigOperators | |
| namespace MatrixMultiplication.Foundation | |
| namespace Tensor | |
| variable {K A B C D E F : Type*} [CommSemiring K] | |
| def matrixCoefficients (A B C : Type*) [DecidableEq A] [DecidableEq B] [DecidableEq C] : | |
| Tensor K (A Γ B) (B Γ C) (C Γ A) := | |
| fun x y z => if x.2 = y.1 β§ y.2 = z.1 β§ z.2 = x.1 then 1 else 0 | |
| theorem matrixMultiplication_eq_matrixCoefficients (a b c : β) : | |
| matrixMultiplication a b c = matrixCoefficients (K := β) (Fin a) (Fin b) (Fin c) := rfl | |
| theorem contract_matrixCoefficients [Fintype A] [Fintype B] [Fintype C] | |
| [DecidableEq A] [DecidableEq B] [DecidableEq C] | |
| (left : A Γ B β K) (right : B Γ C β K) (i : A) (k : C) : | |
| contract (matrixCoefficients A B C) left right (k, i) = | |
| β j, left (i, j) * right (j, k) := by | |
| simp [contract, matrixCoefficients, Fintype.sum_prod_type, ite_and, ite_mul] | |
| theorem matrixCoefficients_product [DecidableEq A] [DecidableEq B] [DecidableEq C] | |
| [DecidableEq D] [DecidableEq E] [DecidableEq F] | |
| (x : (A Γ D) Γ (B Γ E)) (y : (B Γ E) Γ (C Γ F)) (z : (C Γ F) Γ (A Γ D)) : | |
| product (matrixCoefficients (K := K) A B C) (matrixCoefficients D E F) | |
| ((x.1.1, x.2.1), (x.1.2, x.2.2)) | |
| ((y.1.1, y.2.1), (y.1.2, y.2.2)) | |
| ((z.1.1, z.2.1), (z.1.2, z.2.2)) = | |
| matrixCoefficients (A Γ D) (B Γ E) (C Γ F) x y z := by | |
| simp only [product, matrixCoefficients, Prod.ext_iff] | |
| split_ifs <;> simp_all | |
| theorem matrixCoefficients_cyclic [DecidableEq A] [DecidableEq B] [DecidableEq C] | |
| (x : B Γ C) (y : C Γ A) (z : A Γ B) : | |
| matrixCoefficients (K := K) A B C z x y = matrixCoefficients B C A x y z := by | |
| have h : (z.2 = x.1 β§ x.2 = y.1 β§ y.2 = z.1) β | |
| (x.2 = y.1 β§ y.2 = z.1 β§ z.2 = x.1) := | |
| β¨fun h => β¨h.2.1, h.2.2, h.1β©, fun h => β¨h.2.2, h.1, h.2.1β©β© | |
| simp only [matrixCoefficients, h] | |
| theorem matrixCoefficients_rank_of_product [DecidableEq A] [DecidableEq B] [DecidableEq C] | |
| [DecidableEq D] [DecidableEq E] [DecidableEq F] {r : β} | |
| (hproduct : RankAtMost (product (matrixCoefficients (K := K) A B C) | |
| (matrixCoefficients D E F)) r) : | |
| RankAtMost (matrixCoefficients (K := K) (A Γ D) (B Γ E) (C Γ F)) r := by | |
| have h := hproduct.pullback | |
| (fun x : (A Γ D) Γ (B Γ E) => ((x.1.1, x.2.1), (x.1.2, x.2.2))) | |
| (fun y : (B Γ E) Γ (C Γ F) => ((y.1.1, y.2.1), (y.1.2, y.2.2))) | |
| (fun z : (C Γ F) Γ (A Γ D) => ((z.1.1, z.2.1), (z.1.2, z.2.2))) | |
| have heq : pullback | |
| (fun x : (A Γ D) Γ (B Γ E) => ((x.1.1, x.2.1), (x.1.2, x.2.2))) | |
| (fun y : (B Γ E) Γ (C Γ F) => ((y.1.1, y.2.1), (y.1.2, y.2.2))) | |
| (fun z : (C Γ F) Γ (A Γ D) => ((z.1.1, z.2.1), (z.1.2, z.2.2))) | |
| (product (matrixCoefficients (K := K) A B C) (matrixCoefficients D E F)) = | |
| matrixCoefficients (K := K) (A Γ D) (B Γ E) (C Γ F) := by | |
| funext x y z | |
| exact matrixCoefficients_product x y z | |
| rw [heq] at h | |
| exact h | |
| theorem matrixCoefficients_product_rank [DecidableEq A] [DecidableEq B] [DecidableEq C] | |
| [DecidableEq D] [DecidableEq E] [DecidableEq F] {r s : β} | |
| (hT : RankAtMost (matrixCoefficients (K := K) A B C) r) | |
| (hS : RankAtMost (matrixCoefficients (K := K) D E F) s) : | |
| RankAtMost (matrixCoefficients (K := K) (A Γ D) (B Γ E) (C Γ F)) (r * s) := | |
| matrixCoefficients_rank_of_product (hT.product hS) | |
| theorem matrixCoefficients_batch_rank [DecidableEq A] [DecidableEq B] [Fintype B] | |
| {R k r batches : β} | |
| (houter : RankAtMost (matrixCoefficients (K := K) A A A) R) | |
| (hbatch : RankAtMost (directSum (fun _ : Fin k => matrixCoefficients (K := K) B B B)) r) | |
| (hfit : R β€ batches * k) : | |
| RankAtMost (matrixCoefficients (K := K) (A Γ B) (A Γ B) (A Γ B)) (batches * r) := | |
| matrixCoefficients_rank_of_product (houter.batch_product hbatch hfit) | |
| theorem matrixCoefficients_power [DecidableEq A] [DecidableEq B] [DecidableEq C] | |
| (n : β) (x : (Fin n β A) Γ (Fin n β B)) | |
| (y : (Fin n β B) Γ (Fin n β C)) (z : (Fin n β C) Γ (Fin n β A)) : | |
| Tensor.power (matrixCoefficients (K := K) A B C) n | |
| (fun i => (x.1 i, x.2 i)) (fun i => (y.1 i, y.2 i)) (fun i => (z.1 i, z.2 i)) = | |
| matrixCoefficients (Fin n β A) (Fin n β B) (Fin n β C) x y z := by | |
| simp only [Tensor.power, matrixCoefficients, Fintype.prod_boole, forall_and, β funext_iff] | |
| theorem matrixCoefficients_cyclic_rank [DecidableEq A] [DecidableEq B] [DecidableEq C] | |
| {r : β} (h : RankAtMost (matrixCoefficients (K := K) A B C) r) : | |
| RankAtMost (matrixCoefficients (K := K) B C A) r := by | |
| rcases h with β¨a, b, c, heqβ© | |
| refine β¨b, c, a, ?_β© | |
| funext x y z | |
| rw [β matrixCoefficients_cyclic (K := K) x y z] | |
| rw [congrFun (congrFun (congrFun heq z) x) y] | |
| apply Finset.sum_congr rfl | |
| intro i hi | |
| simp only [rankOne] | |
| ring | |
| end Tensor | |
| namespace Tensor | |
| variable {K X Y Z U V W : Type*} [CommSemiring K] | |
| def cyclic (T : Tensor K X Y Z) : Tensor K Y Z X := | |
| fun y z x => T x y z | |
| theorem RankAtMost.cyclic {T : Tensor K X Y Z} {r : β} | |
| (h : RankAtMost T r) : RankAtMost (Tensor.cyclic T) r := by | |
| rcases h with β¨a, b, c, rflβ© | |
| refine β¨b, c, a, ?_β© | |
| funext y z x | |
| simp only [Tensor.cyclic, rankOne] | |
| apply Finset.sum_congr rfl | |
| intro i hi | |
| ring | |
| def directSumProductEquiv (ΞΉ ΞΊ X U : Type*) : | |
| ((ΞΉ Γ ΞΊ) Γ (X Γ U)) β ((ΞΉ Γ X) Γ (ΞΊ Γ U)) where | |
| toFun x := ((x.1.1, x.2.1), (x.1.2, x.2.2)) | |
| invFun x := ((x.1.1, x.2.1), (x.1.2, x.2.2)) | |
| left_inv _ := rfl | |
| right_inv _ := rfl | |
| theorem directSum_product {ΞΉ ΞΊ : Type*} [DecidableEq ΞΉ] [DecidableEq ΞΊ] | |
| (T : ΞΉ β Tensor K X Y Z) (S : ΞΊ β Tensor K U V W) : | |
| pullback (directSumProductEquiv ΞΉ ΞΊ X U) | |
| (directSumProductEquiv ΞΉ ΞΊ Y V) (directSumProductEquiv ΞΉ ΞΊ Z W) | |
| (product (directSum T) (directSum S)) = | |
| directSum (fun i : ΞΉ Γ ΞΊ => product (T i.1) (S i.2)) := by | |
| funext x y z | |
| change | |
| (if x.1.1 = y.1.1 β§ x.1.1 = z.1.1 then | |
| T x.1.1 x.2.1 y.2.1 z.2.1 else 0) * | |
| (if x.1.2 = y.1.2 β§ x.1.2 = z.1.2 then | |
| S x.1.2 x.2.2 y.2.2 z.2.2 else 0) = | |
| if x.1 = y.1 β§ x.1 = z.1 then | |
| T x.1.1 x.2.1 y.2.1 z.2.1 * S x.1.2 x.2.2 y.2.2 z.2.2 else 0 | |
| have hguard : (x.1 = y.1 β§ x.1 = z.1) β | |
| (x.1.1 = y.1.1 β§ x.1.1 = z.1.1) β§ | |
| (x.1.2 = y.1.2 β§ x.1.2 = z.1.2) := by | |
| constructor | |
| Β· intro h | |
| exact β¨β¨congrArg Prod.fst h.1, congrArg Prod.fst h.2β©, | |
| β¨congrArg Prod.snd h.1, congrArg Prod.snd h.2β©β© | |
| Β· intro h | |
| exact β¨Prod.ext h.1.1 h.2.1, Prod.ext h.1.2 h.2.2β© | |
| by_cases hi : x.1.1 = y.1.1 β§ x.1.1 = z.1.1 | |
| Β· by_cases hk : x.1.2 = y.1.2 β§ x.1.2 = z.1.2 | |
| Β· simp only [ite_eq_left hi, ite_eq_left hk, ite_eq_left (hguard.mpr β¨hi, hkβ©)] | |
| Β· have hfull : Β¬ (x.1 = y.1 β§ x.1 = z.1) := fun h => hk (hguard.mp h).2 | |
| simp only [ite_eq_left hi, ite_eq_right hk, ite_eq_right hfull, mul_zero] | |
| Β· have hfull : Β¬ (x.1 = y.1 β§ x.1 = z.1) := fun h => hi (hguard.mp h).1 | |
| simp only [ite_eq_right hi, ite_eq_right hfull, zero_mul] | |
| theorem RankAtMost.directSum_product {ΞΉ ΞΊ : Type*} [DecidableEq ΞΉ] [DecidableEq ΞΊ] | |
| {T : ΞΉ β Tensor K X Y Z} {S : ΞΊ β Tensor K U V W} {r s : β} | |
| (hT : RankAtMost (directSum T) r) (hS : RankAtMost (directSum S) s) : | |
| RankAtMost (directSum (fun i : ΞΉ Γ ΞΊ => Tensor.product (T i.1) (S i.2))) (r * s) := by | |
| have h := (hT.product hS).pullback (directSumProductEquiv ΞΉ ΞΊ X U) | |
| (directSumProductEquiv ΞΉ ΞΊ Y V) (directSumProductEquiv ΞΉ ΞΊ Z W) | |
| rw [Tensor.directSum_product] at h | |
| exact h | |
| theorem directSum_pullback {ΞΉ X' Y' Z' : Type*} [DecidableEq ΞΉ] | |
| (T : ΞΉ β Tensor K X Y Z) (fx : X' β X) (fy : Y' β Y) (fz : Z' β Z) : | |
| pullback (fun x : ΞΉ Γ X' => (x.1, fx x.2)) | |
| (fun y : ΞΉ Γ Y' => (y.1, fy y.2)) (fun z : ΞΉ Γ Z' => (z.1, fz z.2)) | |
| (directSum T) = directSum (fun i => pullback fx fy fz (T i)) := rfl | |
| theorem RankAtMost.directSum_pullback {ΞΉ X' Y' Z' : Type*} [DecidableEq ΞΉ] | |
| {T : ΞΉ β Tensor K X Y Z} {r : β} (h : RankAtMost (directSum T) r) | |
| (fx : X' β X) (fy : Y' β Y) (fz : Z' β Z) : | |
| RankAtMost (directSum (fun i => Tensor.pullback fx fy fz (T i))) r := | |
| h.pullback (fun x : ΞΉ Γ X' => (x.1, fx x.2)) | |
| (fun y : ΞΉ Γ Y' => (y.1, fy y.2)) (fun z : ΞΉ Γ Z' => (z.1, fz z.2)) | |
| theorem cyclic_directSum {ΞΉ : Type*} [DecidableEq ΞΉ] | |
| (T : ΞΉ β Tensor K X Y Z) : | |
| cyclic (directSum T) = directSum (fun i => cyclic (T i)) := by | |
| funext x y z | |
| rcases x with β¨i, xβ© | |
| rcases y with β¨j, yβ© | |
| rcases z with β¨k, zβ© | |
| by_cases hij : i = j | |
| Β· subst j | |
| by_cases hik : i = k | |
| Β· subst k | |
| simp [cyclic, directSum] | |
| Β· simp [cyclic, directSum, hik, Ne.symm hik] | |
| Β· by_cases hki : k = i | |
| Β· subst k | |
| simp [cyclic, directSum, hij] | |
| Β· simp [cyclic, directSum, hij, hki] | |
| theorem RankAtMost.directSum_cyclic {ΞΉ : Type*} [DecidableEq ΞΉ] | |
| {T : ΞΉ β Tensor K X Y Z} {r : β} (h : RankAtMost (directSum T) r) : | |
| RankAtMost (directSum (fun i => Tensor.cyclic (T i))) r := by | |
| rw [β Tensor.cyclic_directSum] | |
| exact h.cyclic | |
| def directSumPowerEquiv (ΞΉ X : Type*) (n : β) : | |
| ((Fin n β ΞΉ) Γ (Fin n β X)) β (Fin n β ΞΉ Γ X) where | |
| toFun x i := (x.1 i, x.2 i) | |
| invFun x := (fun i => (x i).1, fun i => (x i).2) | |
| left_inv _ := rfl | |
| right_inv _ := rfl | |
| theorem directSum_power {ΞΉ : Type*} [DecidableEq ΞΉ] | |
| (T : ΞΉ β Tensor K X Y Z) (n : β) : | |
| pullback (directSumPowerEquiv ΞΉ X n) (directSumPowerEquiv ΞΉ Y n) | |
| (directSumPowerEquiv ΞΉ Z n) (power (directSum T) n) = | |
| directSum (fun f : Fin n β ΞΉ => | |
| fun x y z => β i, T (f i) (x i) (y i) (z i)) := by | |
| funext x y z | |
| change (β i, if x.1 i = y.1 i β§ x.1 i = z.1 i then | |
| T (x.1 i) (x.2 i) (y.2 i) (z.2 i) else 0) = | |
| if x.1 = y.1 β§ x.1 = z.1 then | |
| β i, T (x.1 i) (x.2 i) (y.2 i) (z.2 i) else 0 | |
| simp only [Fintype.prod_ite_zero, forall_and, β funext_iff] | |
| theorem directSum_const_power {ΞΉ : Type*} [DecidableEq ΞΉ] | |
| (T : Tensor K X Y Z) (n : β) : | |
| pullback (directSumPowerEquiv ΞΉ X n) (directSumPowerEquiv ΞΉ Y n) | |
| (directSumPowerEquiv ΞΉ Z n) (power (directSum (fun _ : ΞΉ => T)) n) = | |
| directSum (fun _ : Fin n β ΞΉ => power T n) := | |
| directSum_power (fun _ : ΞΉ => T) n | |
| theorem RankAtMost.directSum_const_of_power {ΞΉ : Type*} [DecidableEq ΞΉ] | |
| {T : Tensor K X Y Z} {n R : β} | |
| (h : RankAtMost (Tensor.power (directSum (fun _ : ΞΉ => T)) n) R) : | |
| RankAtMost (directSum (fun _ : Fin n β ΞΉ => Tensor.power T n)) R := by | |
| have h' := h.pullback (directSumPowerEquiv ΞΉ X n) | |
| (directSumPowerEquiv ΞΉ Y n) (directSumPowerEquiv ΞΉ Z n) | |
| rw [Tensor.directSum_const_power] at h' | |
| exact h' | |
| theorem RankAtMost.directSum_const_power {ΞΉ : Type*} [DecidableEq ΞΉ] | |
| {T : Tensor K X Y Z} {r : β} (h : RankAtMost (directSum (fun _ : ΞΉ => T)) r) | |
| (n : β) : RankAtMost (directSum (fun _ : Fin n β ΞΉ => Tensor.power T n)) (r ^ n) := | |
| (h.power n).directSum_const_of_power | |
| section Rectangular | |
| variable {A B C : Type*} | |
| def rectangularSquareX (A B C : Type*) : | |
| ((A Γ B Γ C) Γ (A Γ B Γ C)) β (((A Γ B) Γ (B Γ C)) Γ (C Γ A)) where | |
| toFun x := (((x.1.1, x.2.2.1), (x.1.2.1, x.2.2.2)), (x.1.2.2, x.2.1)) | |
| invFun x := ((x.1.1.1, x.1.2.1, x.2.1), (x.2.2, x.1.1.2, x.1.2.2)) | |
| left_inv _ := rfl | |
| right_inv _ := rfl | |
| def rectangularSquareY (A B C : Type*) : | |
| ((A Γ B Γ C) Γ (A Γ B Γ C)) β (((B Γ C) Γ (C Γ A)) Γ (A Γ B)) where | |
| toFun y := (((y.1.2.1, y.2.2.2), (y.1.2.2, y.2.1)), (y.1.1, y.2.2.1)) | |
| invFun y := ((y.2.1, y.1.1.1, y.1.2.1), (y.1.2.2, y.2.2, y.1.1.2)) | |
| left_inv _ := rfl | |
| right_inv _ := rfl | |
| def rectangularSquareZ (A B C : Type*) : | |
| ((A Γ B Γ C) Γ (A Γ B Γ C)) β (((C Γ A) Γ (A Γ B)) Γ (B Γ C)) where | |
| toFun z := (((z.1.2.2, z.2.1), (z.1.1, z.2.2.1)), (z.1.2.1, z.2.2.2)) | |
| invFun z := ((z.1.2.1, z.2.1, z.1.1.1), (z.1.1.2, z.1.2.2, z.2.2)) | |
| left_inv _ := rfl | |
| right_inv _ := rfl | |
| variable [DecidableEq A] [DecidableEq B] [DecidableEq C] | |
| theorem matrixCoefficients_directSum_rank_of_power | |
| {ΞΉ : Type*} [DecidableEq ΞΉ] {n R : β} | |
| (h : RankAtMost | |
| (power (directSum (fun _ : ΞΉ => matrixCoefficients (K := K) A B C)) n) R) : | |
| RankAtMost (directSum (fun _ : Fin n β ΞΉ => | |
| matrixCoefficients (K := K) (Fin n β A) (Fin n β B) (Fin n β C))) R := by | |
| have h' := h.directSum_const_of_power.directSum_pullback | |
| (fun x : (Fin n β A) Γ (Fin n β B) => fun i => (x.1 i, x.2 i)) | |
| (fun y : (Fin n β B) Γ (Fin n β C) => fun i => (y.1 i, y.2 i)) | |
| (fun z : (Fin n β C) Γ (Fin n β A) => fun i => (z.1 i, z.2 i)) | |
| have heq : pullback | |
| (fun x : (Fin n β A) Γ (Fin n β B) => fun i => (x.1 i, x.2 i)) | |
| (fun y : (Fin n β B) Γ (Fin n β C) => fun i => (y.1 i, y.2 i)) | |
| (fun z : (Fin n β C) Γ (Fin n β A) => fun i => (z.1 i, z.2 i)) | |
| (power (matrixCoefficients (K := K) A B C) n) = | |
| matrixCoefficients (Fin n β A) (Fin n β B) (Fin n β C) := by | |
| funext x y z | |
| exact matrixCoefficients_power n x y z | |
| simpa only [heq] using h' | |
| theorem matrixCoefficients_cyclic_product_square : | |
| pullback (rectangularSquareX A B C) (rectangularSquareY A B C) | |
| (rectangularSquareZ A B C) | |
| (product (product (matrixCoefficients (K := K) A B C) | |
| (matrixCoefficients B C A)) (matrixCoefficients C A B)) = | |
| matrixCoefficients (A Γ B Γ C) (A Γ B Γ C) (A Γ B Γ C) := by | |
| funext x y z | |
| dsimp only [pullback, rectangularSquareX, rectangularSquareY, rectangularSquareZ, | |
| product, matrixCoefficients] | |
| simp only [Prod.ext_iff, ite_mul, one_mul, zero_mul, β ite_and] | |
| congr 1 | |
| apply propext | |
| tauto | |
| theorem cyclic_matrixCoefficients : | |
| cyclic (matrixCoefficients (K := K) A B C) = matrixCoefficients B C A := by | |
| funext x y z | |
| exact matrixCoefficients_cyclic x y z | |
| theorem matrixCoefficients_symmetrized_rank {r : β} | |
| (h : RankAtMost (matrixCoefficients (K := K) A B C) r) : | |
| RankAtMost (matrixCoefficients (K := K) | |
| (A Γ B Γ C) (A Γ B Γ C) (A Γ B Γ C)) (r ^ 3) := by | |
| have h' := ((h.product (matrixCoefficients_cyclic_rank h)).product | |
| (matrixCoefficients_cyclic_rank (matrixCoefficients_cyclic_rank h))).pullback | |
| (rectangularSquareX A B C) (rectangularSquareY A B C) (rectangularSquareZ A B C) | |
| rw [matrixCoefficients_cyclic_product_square] at h' | |
| simpa only [pow_succ, pow_zero, one_mul] using h' | |
| theorem matrixCoefficients_directSum_symmetrized_rank | |
| {ΞΉ : Type*} [DecidableEq ΞΉ] {r : β} | |
| (h : RankAtMost (directSum (fun _ : ΞΉ => matrixCoefficients (K := K) A B C)) r) : | |
| RankAtMost (directSum (fun _ : (ΞΉ Γ ΞΉ) Γ ΞΉ => | |
| matrixCoefficients (K := K) (A Γ B Γ C) (A Γ B Γ C) (A Γ B Γ C))) (r ^ 3) := by | |
| have hβ : RankAtMost (directSum (fun _ : ΞΉ => matrixCoefficients (K := K) B C A)) r := by | |
| simpa only [cyclic_matrixCoefficients] using h.directSum_cyclic | |
| have hβ : RankAtMost (directSum (fun _ : ΞΉ => matrixCoefficients (K := K) C A B)) r := by | |
| simpa only [cyclic_matrixCoefficients] using hβ.directSum_cyclic | |
| have hβ := ((h.directSum_product hβ).directSum_product hβ).directSum_pullback | |
| (rectangularSquareX A B C) (rectangularSquareY A B C) (rectangularSquareZ A B C) | |
| simpa only [matrixCoefficients_cyclic_product_square, pow_succ, pow_zero, one_mul] using hβ | |
| theorem symmetrized_tag_card (ΞΉ : Type*) [Fintype ΞΉ] : | |
| Fintype.card ((ΞΉ Γ ΞΉ) Γ ΞΉ) = Fintype.card ΞΉ ^ 3 := by | |
| simp [Fintype.card_prod, pow_succ] | |
| omit [DecidableEq A] [DecidableEq B] [DecidableEq C] in | |
| theorem symmetrized_index_card [Fintype A] [Fintype B] [Fintype C] : | |
| Fintype.card (A Γ B Γ C) = Fintype.card A * Fintype.card B * Fintype.card C := by | |
| simp [Fintype.card_prod, mul_assoc] | |
| end Rectangular | |
| end Tensor | |
| end MatrixMultiplication.Foundation | |
| end | |
| section | |
| noncomputable section | |
| open scoped BigOperators | |
| namespace MatrixMultiplication.Foundation | |
| namespace Tensor | |
| variable {K X Y Z : Type*} [Field K] | |
| theorem RankAtMost.card_le_of_identity {ΞΉ : Type*} [Fintype ΞΉ] [DecidableEq ΞΉ] | |
| {T : Tensor K X Y Z} {r : β} (hT : RankAtMost T r) | |
| (x : ΞΉ β X) (y : ΞΉ β Y) (z : ΞΉ β Z) | |
| (hidentity : β i j, T (x i) (y i) (z j) = if i = j then 1 else 0) : | |
| Fintype.card ΞΉ β€ r := by | |
| rcases hT with β¨a, b, c, heqβ© | |
| let L : Matrix ΞΉ (Fin r) K := fun i q => a q (x i) * b q (y i) | |
| let R : Matrix (Fin r) ΞΉ K := fun q j => c q (z j) | |
| have hmul : L * R = (1 : Matrix ΞΉ ΞΉ K) := by | |
| funext i j | |
| change (β q, (a q (x i) * b q (y i)) * c q (z j)) = if i = j then 1 else 0 | |
| calc | |
| (β q, (a q (x i) * b q (y i)) * c q (z j)) = T (x i) (y i) (z j) := | |
| (congrFun (congrFun (congrFun heq (x i)) (y i)) (z j)).symm | |
| _ = _ := hidentity i j | |
| have hle : (1 : Matrix ΞΉ ΞΉ K).rank β€ r := by | |
| rw [β hmul] | |
| exact (Matrix.rank_mul_le_left L R).trans (by | |
| simpa only [Fintype.card_fin] using Matrix.rank_le_card_width L) | |
| simpa only [Matrix.rank_one] using hle | |
| theorem directSum_matrixCoefficients_rank_lower | |
| {Label A B C : Type*} [Fintype Label] [Fintype A] [Fintype C] | |
| [DecidableEq Label] [DecidableEq A] [DecidableEq B] [DecidableEq C] | |
| [Nonempty B] {r : β} | |
| (h : RankAtMost (directSum (fun _ : Label => matrixCoefficients (K := K) A B C)) r) : | |
| Fintype.card Label * (Fintype.card C * Fintype.card A) β€ r := by | |
| classical | |
| let bβ : B := Classical.choice inferInstance | |
| have hminor : β i j : Label Γ (C Γ A), | |
| directSum (fun _ : Label => matrixCoefficients (K := K) A B C) | |
| (i.1, (i.2.2, bβ)) (i.1, (bβ, i.2.1)) j = if i = j then 1 else 0 := by | |
| intro i j | |
| simp only [directSum, matrixCoefficients] | |
| split_ifs <;> simp_all [Prod.ext_iff] | |
| have hlower := h.card_le_of_identity | |
| (fun i : Label Γ (C Γ A) => (i.1, (i.2.2, bβ))) | |
| (fun i : Label Γ (C Γ A) => (i.1, (bβ, i.2.1))) | |
| (fun i : Label Γ (C Γ A) => i) hminor | |
| simpa only [Fintype.card_prod] using hlower | |
| theorem directSum_square_rank_lower (k n r : β) (hn : 0 < n) | |
| (h : RankAtMost (directSum (fun _ : Fin k => | |
| matrixCoefficients (K := K) (Fin n) (Fin n) (Fin n))) r) : | |
| k * n ^ 2 β€ r := by | |
| let : Nonempty (Fin n) := β¨β¨0, hnβ©β© | |
| simpa only [Fintype.card_fin, pow_two] using directSum_matrixCoefficients_rank_lower h | |
| end Tensor | |
| end MatrixMultiplication.Foundation | |
| end | |
| noncomputable section | |
| open MatrixMultiplication.Foundation | |
| namespace MatrixMultiplication.TerminalRelabel | |
| variable {K I A B C I' A' B' C' : Type*} [CommSemiring K] | |
| def taggedPair (eI : I' β I) (eA : A' β A) (eB : B' β B) : | |
| I' Γ (A' Γ B') β I Γ (A Γ B) := | |
| fun x => (eI x.1, (eA x.2.1, eB x.2.2)) | |
| theorem directSum_matrix_pullback | |
| [DecidableEq I] [DecidableEq A] [DecidableEq B] [DecidableEq C] | |
| [DecidableEq I'] [DecidableEq A'] [DecidableEq B'] [DecidableEq C'] | |
| (eI : I' β I) (eA : A' β A) (eB : B' β B) (eC : C' β C) : | |
| Tensor.pullback (taggedPair eI eA eB) (taggedPair eI eB eC) (taggedPair eI eC eA) | |
| (Tensor.directSum (fun _ : I => Tensor.matrixCoefficients (K := K) A B C)) = | |
| Tensor.directSum (fun _ : I' => Tensor.matrixCoefficients (K := K) A' B' C') := by | |
| funext x y z | |
| simp only [Tensor.pullback, taggedPair, Tensor.directSum, Tensor.matrixCoefficients, | |
| eI.injective.eq_iff, eA.injective.eq_iff, eB.injective.eq_iff, eC.injective.eq_iff] | |
| theorem directSum_matrix_restrict_equiv | |
| [Fintype I] [Fintype A] [Fintype B] [Fintype C] | |
| [DecidableEq I] [DecidableEq A] [DecidableEq B] [DecidableEq C] | |
| [DecidableEq I'] [DecidableEq A'] [DecidableEq B'] [DecidableEq C'] | |
| (eI : I' β I) (eA : A' β A) (eB : B' β B) (eC : C' β C) : | |
| Tensor.restrict | |
| (fun x s => if s = taggedPair eI eA eB x then (1 : K) else 0) | |
| (fun y s => if s = taggedPair eI eB eC y then (1 : K) else 0) | |
| (fun z s => if s = taggedPair eI eC eA z then (1 : K) else 0) | |
| (Tensor.directSum (fun _ : I => Tensor.matrixCoefficients (K := K) A B C)) = | |
| Tensor.directSum (fun _ : I' => Tensor.matrixCoefficients (K := K) A' B' C') := by | |
| rw [β Tensor.pullback_eq_restrict] | |
| exact directSum_matrix_pullback eI eA eB eC | |
| theorem exists_directSum_matrix_restrict_equiv | |
| [Fintype I] [Fintype A] [Fintype B] [Fintype C] | |
| [DecidableEq I] [DecidableEq A] [DecidableEq B] [DecidableEq C] | |
| [DecidableEq I'] [DecidableEq A'] [DecidableEq B'] [DecidableEq C'] | |
| (eI : I' β I) (eA : A' β A) (eB : B' β B) (eC : C' β C) : | |
| β (a : (I' Γ (A' Γ B')) β (I Γ (A Γ B)) β K) | |
| (b : (I' Γ (B' Γ C')) β (I Γ (B Γ C)) β K) | |
| (c : (I' Γ (C' Γ A')) β (I Γ (C Γ A)) β K), | |
| Tensor.restrict a b c | |
| (Tensor.directSum (fun _ : I => Tensor.matrixCoefficients (K := K) A B C)) = | |
| Tensor.directSum (fun _ : I' => Tensor.matrixCoefficients (K := K) A' B' C') := | |
| β¨_, _, _, directSum_matrix_restrict_equiv eI eA eB eCβ© | |
| theorem directSum_matrix_restrict_of_card_eq | |
| (I A B C : Type*) [Fintype I] [Fintype A] [Fintype B] [Fintype C] | |
| [DecidableEq I] [DecidableEq A] [DecidableEq B] [DecidableEq C] | |
| {L a b c : β} (hI : Fintype.card I = L) (hA : Fintype.card A = a) | |
| (hB : Fintype.card B = b) (hC : Fintype.card C = c) : | |
| β (aa : (Fin L Γ (Fin a Γ Fin b)) β (I Γ (A Γ B)) β K) | |
| (bb : (Fin L Γ (Fin b Γ Fin c)) β (I Γ (B Γ C)) β K) | |
| (cc : (Fin L Γ (Fin c Γ Fin a)) β (I Γ (C Γ A)) β K), | |
| Tensor.restrict aa bb cc | |
| (Tensor.directSum (fun _ : I => Tensor.matrixCoefficients (K := K) A B C)) = | |
| Tensor.directSum (fun _ : Fin L => | |
| Tensor.matrixCoefficients (K := K) (Fin a) (Fin b) (Fin c)) := | |
| exists_directSum_matrix_restrict_equiv | |
| (Fintype.equivFinOfCardEq hI).symm (Fintype.equivFinOfCardEq hA).symm | |
| (Fintype.equivFinOfCardEq hB).symm (Fintype.equivFinOfCardEq hC).symm | |
| theorem directSum_matrix_restrict_fin | |
| (I A B C : Type*) [Fintype I] [Fintype A] [Fintype B] [Fintype C] | |
| [DecidableEq I] [DecidableEq A] [DecidableEq B] [DecidableEq C] : | |
| β (a : (Fin (Fintype.card I) Γ (Fin (Fintype.card A) Γ Fin (Fintype.card B))) β | |
| (I Γ (A Γ B)) β K) | |
| (b : (Fin (Fintype.card I) Γ (Fin (Fintype.card B) Γ Fin (Fintype.card C))) β | |
| (I Γ (B Γ C)) β K) | |
| (c : (Fin (Fintype.card I) Γ (Fin (Fintype.card C) Γ Fin (Fintype.card A))) β | |
| (I Γ (C Γ A)) β K), | |
| Tensor.restrict a b c | |
| (Tensor.directSum (fun _ : I => Tensor.matrixCoefficients (K := K) A B C)) = | |
| Tensor.directSum (fun _ : Fin (Fintype.card I) => | |
| Tensor.matrixCoefficients (K := K) | |
| (Fin (Fintype.card A)) (Fin (Fintype.card B)) (Fin (Fintype.card C))) := | |
| directSum_matrix_restrict_of_card_eq I A B C rfl rfl rfl rfl | |
| end MatrixMultiplication.TerminalRelabel | |
| end | |
| end | |
| end MatrixAllFields | |
| end OAI | |