introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
6.29 kB
import OAI.LinearAlgebra.MatrixMultiplication.Separation.ComplexTypeCounting
import OAI.LinearAlgebra.MatrixMultiplication.Tensor.ComplexTensor
import Mathlib.Analysis.SpecialFunctions.Log.Basic
import Mathlib.Tactic.Linarith
namespace OAI
/-! Finite orbit symmetries, masks and exact recovery operations. -/
namespace MatrixMultiplication.InheritedMasks
open MatrixMultiplication.Foundation
open scoped BigOperators
section ClassWords
variable {C : Type*} (P A : C β†’ Type*)
[βˆ€ c, Fintype (P c)]
[βˆ€ c, Fintype (A c)] [βˆ€ c, DecidableEq (A c)]
abbrev ClassWords := βˆ€ c, P c β†’ A c
def SameClassOrbit (w v : ClassWords P A) : Prop :=
βˆƒ e : βˆ€ c, Equiv.Perm (P c), βˆ€ c, w c ∘ e c = v c
omit [βˆ€ label, Fintype (A label)] in
theorem sameClassOrbit_iff (w v : ClassWords P A) :
SameClassOrbit P A w v ↔
βˆ€ c a, wordPopulation (v c) a = wordPopulation (w c) a := by
constructor
· rintro ⟨e, he⟩ c a
rw [← he c]
exact wordPopulation_reindex (w c) (e c) a
Β· intro h
have he : βˆ€ c, βˆƒ e : Equiv.Perm (P c), w c ∘ e = v c :=
fun c => (samePopulation_iff_permutation (w c) (v c)).mp (h c)
choose e he using he
exact ⟨e, he⟩
abbrev Profile := βˆ€ c, A c β†’ Fin (Fintype.card (P c) + 1)
noncomputable def profile (w : ClassWords P A) : Profile P A :=
fun c a => ⟨wordPopulation (w c) a,
Nat.lt_succ_of_le (Fintype.card_subtype_le _)⟩
omit [βˆ€ label, Fintype (A label)] in
theorem profile_eq_iff (w v : ClassWords P A) :
profile P A w = profile P A v ↔ SameClassOrbit P A w v := by
rw [sameClassOrbit_iff]
constructor
Β· intro h c a
have hh := congrArg (fun f : Profile P A => (f c a).val) h
exact hh.symm
Β· intro h
funext c a
apply Fin.ext
exact (h c a).symm
theorem card_profile [Fintype C] [DecidableEq C] :
Fintype.card (Profile P A) =
∏ c, (Fintype.card (P c) + 1) ^ Fintype.card (A c) := by
simp [Profile, Fintype.card_pi]
end ClassWords
section TensorAction
variable {F C : Type*} [CommSemiring F] [Fintype C]
{P X Y Z : C β†’ Type*} [βˆ€ c, Fintype (P c)]
def classProduct (T : βˆ€ c, Tensor F (X c) (Y c) (Z c)) :
Tensor F (βˆ€ c, P c β†’ X c) (βˆ€ c, P c β†’ Y c) (βˆ€ c, P c β†’ Z c) :=
fun x y z => ∏ c, ∏ i, T c (x c i) (y c i) (z c i)
theorem classProduct_permutation
(T : βˆ€ c, Tensor F (X c) (Y c) (Z c))
(e : βˆ€ c, Equiv.Perm (P c))
(x : βˆ€ c, P c β†’ X c) (y : βˆ€ c, P c β†’ Y c) (z : βˆ€ c, P c β†’ Z c) :
classProduct T (fun c => x c ∘ e c) (fun c => y c ∘ e c)
(fun c => z c ∘ e c) = classProduct T x y z := by
apply Finset.prod_congr rfl
intro c _
exact Equiv.prod_comp (e c) (fun i => T c (x c i) (y c i) (z c i))
end TensorAction
theorem statisticPopulation_permutation {P A B : Type*}
[Fintype P] [DecidableEq P] [Fintype B] [DecidableEq B]
(w : P β†’ A) (statistic : A β†’ B) (e : Equiv.Perm P) (b : B) :
wordPopulation (statistic ∘ w ∘ e) b = wordPopulation (statistic ∘ w) b :=
wordPopulation_reindex (statistic ∘ w) e b
section EmpiricalWindows
variable {P A B : Type*} [Fintype P] [DecidableEq A] [DecidableEq B]
noncomputable def empiricalLaw (w : P β†’ A) (a : A) : ℝ :=
(wordPopulation w a : ℝ) / Fintype.card P
def typeWindow (Ξ½ : A β†’ ℝ) (Ξ· : ℝ) (w : P β†’ A) : Prop :=
βˆ€ a, |empiricalLaw w a - Ξ½ a| ≀ Ξ·
theorem typeWindow_permutation (Ξ½ : A β†’ ℝ) (Ξ· : ℝ) (w : P β†’ A)
(e : Equiv.Perm P) : typeWindow Ξ½ Ξ· (w ∘ e) ↔ typeWindow Ξ½ Ξ· w := by
simp [typeWindow, empiricalLaw, wordPopulation_reindex]
theorem wordPopulation_equiv (w : P β†’ A) (e : A ≃ B) (a : A) :
wordPopulation (e ∘ w) (e a) = wordPopulation w a := by
apply Fintype.card_congr
exact Equiv.subtypeEquivRight fun i => e.injective.eq_iff
theorem typeWindow_equiv (Ξ½ : A β†’ ℝ) (Ξ· : ℝ) (w : P β†’ A) (e : A ≃ B) :
typeWindow (Ξ½ ∘ e.symm) Ξ· (e ∘ w) ↔ typeWindow Ξ½ Ξ· w := by
constructor
Β· intro h a
have hh := h (e a)
simpa [empiricalLaw, wordPopulation_equiv] using hh
Β· intro h b
obtain ⟨a, rfl⟩ := e.surjective b
simpa [empiricalLaw, wordPopulation_equiv] using h a
end EmpiricalWindows
section Windows
variable {I : Type*} [Fintype I]
theorem weighted_window (w x : I β†’ ℝ) (ΞΌ Ξ· : ℝ)
(hw : βˆ€ i, 0 ≀ w i) (hsum : βˆ‘ i, w i = 1)
(hx : βˆ€ i, |x i - ΞΌ| ≀ Ξ·) :
|(βˆ‘ i, w i * x i) - ΞΌ| ≀ Ξ· := by
have heq : (βˆ‘ i, w i * x i) - ΞΌ = βˆ‘ i, w i * (x i - ΞΌ) := by
simp only [mul_sub, Finset.sum_sub_distrib, ← Finset.sum_mul, hsum, one_mul]
rw [heq]
calc
|βˆ‘ i, w i * (x i - ΞΌ)| ≀ βˆ‘ i, |w i * (x i - ΞΌ)| :=
Finset.abs_sum_le_sum_abs _ _
_ = βˆ‘ i, w i * |x i - ΞΌ| := by
apply Finset.sum_congr rfl
intro i _
rw [abs_mul, abs_of_nonneg (hw i)]
_ ≀ βˆ‘ i, w i * Ξ· := Finset.sum_le_sum fun i _ => mul_le_mul_of_nonneg_left (hx i) (hw i)
_ = Ξ· := by rw [← Finset.sum_mul, hsum, one_mul]
theorem product_coordinate_error {a b a' b' Ο„ : ℝ}
(ha : 0 ≀ a) (ha1 : a ≀ 1) (hb' : 0 ≀ b') (hb1' : b' ≀ 1)
(hea : |a - a'| ≀ Ο„) (heb : |b - b'| ≀ Ο„) :
|a * b - a' * b'| ≀ 2 * Ο„ := by
have ht : 0 ≀ Ο„ := le_trans (abs_nonneg _) hea
have heq : a * b - a' * b' = a * (b - b') + (a - a') * b' := by ring
rw [heq]
calc
|a * (b - b') + (a - a') * b'| ≀ |a * (b - b')| + |(a - a') * b'| := abs_add_le _ _
_ = a * |b - b'| + |a - a'| * b' := by rw [abs_mul, abs_mul, abs_of_nonneg ha, abs_of_nonneg hb']
_ ≀ a * Ο„ + Ο„ * b' := add_le_add
(mul_le_mul_of_nonneg_left heb ha) (mul_le_mul_of_nonneg_right hea hb')
_ ≀ 2 * Ο„ := by nlinarith
theorem inherited_margin {actual expected prescribed Ξ· Ο„ Ξ± : ℝ}
(hchild : |expected - prescribed| ≀ 2 * Ο„)
(happrox : |actual - expected| ≀ Ξ±)
(hΟ„ : Ο„ ≀ Ξ· / 8) (hΞ± : Ξ± ≀ Ξ· / 4) :
|actual - prescribed| ≀ Ξ· / 2 := by
calc
|actual - prescribed| = |(actual - expected) + (expected - prescribed)| := by ring_nf
_ ≀ |actual - expected| + |expected - prescribed| := abs_add_le _ _
_ ≀ Ξ± + 2 * Ο„ := add_le_add happrox hchild
_ ≀ Ξ· / 2 := by linarith
end Windows
end MatrixMultiplication.InheritedMasks
end OAI