introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
3.56 kB
import OAI.LinearAlgebra.MatrixMultiplication.Tensor.ComplexMatrixTensor
import Mathlib.Data.Fintype.Pi
namespace OAI
/-! Division-free arithmetic programs over a field and their operation counts. -/
open scoped BigOperators
open MatrixMultiplication.Foundation
namespace MatrixMultiplication.CommonDimensions
variable {K H : Type*} [CommSemiring K] [Fintype H] [DecidableEq H]
def familyProduct {X Y Z : H β†’ Type*} (T : βˆ€ h, Tensor K (X h) (Y h) (Z h)) :
Tensor K (βˆ€ h, X h) (βˆ€ h, Y h) (βˆ€ h, Z h) :=
fun x y z => ∏ h, T h (x h) (y h) (z h)
def pairWords (A B : H β†’ Type*) :
((βˆ€ h, A h) Γ— (βˆ€ h, B h)) ≃ (βˆ€ h, A h Γ— B h) where
toFun x h := (x.1 h, x.2 h)
invFun x := (fun h => (x h).1, fun h => (x h).2)
left_inv _ := rfl
right_inv _ := rfl
omit [DecidableEq H] in
theorem matrix_familyProduct (A B C : H β†’ Type*)
[βˆ€ h, DecidableEq (A h)] [βˆ€ h, DecidableEq (B h)] [βˆ€ h, DecidableEq (C h)] :
Tensor.pullback (pairWords A B) (pairWords B C) (pairWords C A)
(familyProduct (fun h => Tensor.matrixCoefficients (K := K) (A h) (B h) (C h))) =
Tensor.matrixCoefficients (βˆ€ h, A h) (βˆ€ h, B h) (βˆ€ h, C h) := by
classical
funext x y z
simp only [Tensor.pullback, pairWords, familyProduct, Tensor.matrixCoefficients,
Equiv.coe_fn_mk]
by_cases h : x.2 = y.1 ∧ y.2 = z.1 ∧ z.2 = x.1
Β· rw [ite_eq_left h]
apply Finset.prod_eq_one
intro i _
exact ite_eq_left ⟨congrFun h.1 i, congrFun h.2.1 i, congrFun h.2.2 i⟩
Β· rw [ite_eq_right h]
have hn : Β¬ βˆ€ i, x.2 i = y.1 i ∧ y.2 i = z.1 i ∧ z.2 i = x.1 i := by
intro hi
exact h ⟨funext (fun i => (hi i).1), funext (fun i => (hi i).2.1),
funext (fun i => (hi i).2.2)⟩
obtain ⟨i, hi⟩ := not_forall.mp hn
apply Finset.prod_eq_zero (Finset.mem_univ i)
exact ite_eq_right hi
theorem matrix_familyProduct_restrict (A B C : H β†’ Type*)
[βˆ€ h, Fintype (A h)] [βˆ€ h, Fintype (B h)] [βˆ€ h, Fintype (C h)]
[βˆ€ h, DecidableEq (A h)] [βˆ€ h, DecidableEq (B h)] [βˆ€ h, DecidableEq (C h)] :
βˆƒ (a : ((βˆ€ h, A h) Γ— (βˆ€ h, B h)) β†’ (βˆ€ h, A h Γ— B h) β†’ K)
(b : ((βˆ€ h, B h) Γ— (βˆ€ h, C h)) β†’ (βˆ€ h, B h Γ— C h) β†’ K)
(c : ((βˆ€ h, C h) Γ— (βˆ€ h, A h)) β†’ (βˆ€ h, C h Γ— A h) β†’ K),
Tensor.restrict a b c
(familyProduct (fun h => Tensor.matrixCoefficients (K := K) (A h) (B h) (C h))) =
Tensor.matrixCoefficients (βˆ€ h, A h) (βˆ€ h, B h) (βˆ€ h, C h) := by
classical
refine ⟨(fun x s => if s = pairWords A B x then 1 else 0),
(fun y s => if s = pairWords B C y then 1 else 0),
(fun z s => if s = pairWords C A z then 1 else 0), ?_⟩
rw [← Tensor.pullback_eq_restrict]
exact matrix_familyProduct A B C
theorem dimension_card (a : H β†’ β„•) :
Fintype.card (βˆ€ h, Fin (a h)) = ∏ h, a h := by simp
theorem volume_card (a b c : H β†’ β„•) :
Fintype.card (βˆ€ h, Fin (a h)) * Fintype.card (βˆ€ h, Fin (b h)) *
Fintype.card (βˆ€ h, Fin (c h)) = ∏ h, a h * b h * c h := by
simp [Finset.prod_mul_distrib]
theorem common_oriented_dimensions {S : Type*}
(a b c : S β†’ H β†’ β„•) (aβ‚€ bβ‚€ cβ‚€ : H β†’ β„•)
(ha : βˆ€ s h, a s h = aβ‚€ h) (hb : βˆ€ s h, b s h = bβ‚€ h)
(hc : βˆ€ s h, c s h = cβ‚€ h) (s : S) :
(Fintype.card (βˆ€ h, Fin (a s h)), Fintype.card (βˆ€ h, Fin (b s h)),
Fintype.card (βˆ€ h, Fin (c s h))) =
(∏ h, aβ‚€ h, ∏ h, bβ‚€ h, ∏ h, cβ‚€ h) := by
simp [ha, hb, hc]
end MatrixMultiplication.CommonDimensions
end OAI