Download data/lean/OAI/LinearAlgebra/MatrixMultiplication/Recovery/InheritedMasks.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 6.29 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/LinearAlgebra/MatrixMultiplication/Recovery/InheritedMasks.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/LinearAlgebra/MatrixMultiplication/Recovery/InheritedMasks.lean
-
curl -L -o InheritedMasks.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/LinearAlgebra/MatrixMultiplication/Recovery/InheritedMasks.lean
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 | |