math / data /lean /OAI /LinearAlgebra /MatrixMultiplication /FieldConstruction /NativeGroupedRates.lean
Download data/lean/OAI/LinearAlgebra/MatrixMultiplication/FieldConstruction/NativeGroupedRates.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 15.3 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/LinearAlgebra/MatrixMultiplication/FieldConstruction/NativeGroupedRates.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/LinearAlgebra/MatrixMultiplication/FieldConstruction/NativeGroupedRates.lean
-
curl -L -o NativeGroupedRates.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/LinearAlgebra/MatrixMultiplication/FieldConstruction/NativeGroupedRates.lean
15.3 kB
| import OAI.LinearAlgebra.MatrixMultiplication.JointExtraction.GroupedEntropyPartition | |
| import OAI.LinearAlgebra.MatrixMultiplication.FieldConstruction.PairConditionalEntropy | |
| import OAI.LinearAlgebra.MatrixMultiplication.FieldConstruction.ComplementSums | |
| import Mathlib.Data.List.NodupEquivFin | |
| namespace OAI | |
| /-! Tensor extraction over arbitrary fields and its asymptotic rate. -/ | |
| noncomputable section | |
| namespace MatrixMultiplication.AllFieldNativeGroupedRates | |
| open MatrixMultiplication.Foundation AllFieldParameters AllFieldHistory | |
| open JointNativeGroupedEntropy JointGroupedEntropyPartition | |
| open AllFieldNativeCapacity AllFieldPairConditionalEntropy | |
| open scoped BigOperators | |
| attribute [local instance] Classical.propDecidable Classical.decEq | |
| section Reindex | |
| variable {U K A : Type*} [Fintype U] [Fintype K] [Fintype A] | |
| omit [Fintype U] [Fintype K] in | |
| theorem singletonResidualGroup_transport (e : U β U) (c : K β K) | |
| (d : U β Prop) (weight : U β K) | |
| (hw : β u, c (weight u) = weight (e u)) : | |
| (Equiv.sumCongr e c) β singletonResidualGroup (d β e) weight = | |
| singletonResidualGroup d weight β e := by | |
| funext u | |
| by_cases hu : d (e u) <;> | |
| simp [singletonResidualGroup, Function.comp_apply, hu, hw] | |
| theorem singletonResidual_groupedEntropy_reindex (e : U β U) (c : K β K) | |
| (p : U β β) (d : U β Prop) (weight : U β K) (q : U β A β β) | |
| (hp : β u, p (e u) = p u) (hw : β u, c (weight u) = weight (e u)) : | |
| JointCompatibilityIncidence.groupedEntropy p | |
| (singletonResidualGroup (d β e) weight) (q β e) = | |
| JointCompatibilityIncidence.groupedEntropy p (singletonResidualGroup d weight) q := by | |
| calc | |
| _ = JointCompatibilityIncidence.groupedEntropy p | |
| ((Equiv.sumCongr e c) β singletonResidualGroup (d β e) weight) (q β e) := | |
| (JointCompatibilityIncidence.groupedEntropy_relabel (Equiv.sumCongr e c) p _ _).symm | |
| _ = JointCompatibilityIncidence.groupedEntropy p | |
| (singletonResidualGroup d weight β e) (q β e) := by | |
| rw [singletonResidualGroup_transport e c d weight hw] | |
| _ = _ := JointCompatibilityIncidence.groupedEntropy_reindex e p _ q hp | |
| theorem right_conditional_sum_eq (e : U β U) (c : K β K) | |
| (p : FiniteLaw U) (d : U β Prop) (weight : U β K) (q : U β A β β) | |
| (hp : β u, p.mass (e u) = p.mass u) | |
| (hw : β u, c (weight u) = weight (e u)) (hq : β u, β a, q u a = 1) : | |
| (β k, (p.map weight).mass k * | |
| JointCompatibilityIncidence.groupedEntropy (p.conditional weight k).mass | |
| (JointCompatibilityIncidence.designatedGroup (d β e)) (q β e)) = | |
| JointCompatibilityIncidence.groupedEntropy p.mass (singletonResidualGroup d weight) q := by | |
| rw [β groupedEntropy_conditional_partition p (d β e) weight (q β e) | |
| (fun u => hq (e u))] | |
| exact singletonResidual_groupedEntropy_reindex e c p.mass d weight q hp hw | |
| end Reindex | |
| def supportSubtypeEquiv {Ξ± : Type*} (xs : List Ξ±) (f : Ξ± β Ξ±) | |
| (hm : β x β xs, f x β xs) (hi : β x β xs, f (f x) = x) : | |
| Equiv.Perm {x // x β xs} where | |
| toFun x := β¨f x.val, hm x.val x.propertyβ© | |
| invFun x := β¨f x.val, hm x.val x.propertyβ© | |
| left_inv x := Subtype.ext (hi x.val x.property) | |
| right_inv x := Subtype.ext (hi x.val x.property) | |
| def supportIndexEquiv {Ξ± : Type*} [DecidableEq Ξ±] (xs : List Ξ±) (hn : xs.Nodup) | |
| (f : Ξ± β Ξ±) (hm : β x β xs, f x β xs) (hi : β x β xs, f (f x) = x) : | |
| Equiv.Perm (Fin xs.length) := | |
| ((hn.getEquiv xs).trans (supportSubtypeEquiv xs f hm hi)).trans (hn.getEquiv xs).symm | |
| theorem supportIndexEquiv_get {Ξ± : Type*} [DecidableEq Ξ±] (xs : List Ξ±) | |
| (hn : xs.Nodup) (f : Ξ± β Ξ±) (hm : β x β xs, f x β xs) | |
| (hi : β x β xs, f (f x) = x) (i : Fin xs.length) : | |
| xs.get (supportIndexEquiv xs hn f hm hi i) = f (xs.get i) := by | |
| exact congrArg Subtype.val ((hn.getEquiv xs).apply_symm_apply | |
| ((supportSubtypeEquiv xs f hm hi) ((hn.getEquiv xs) i))) | |
| def boundedComplement (s : β) (hs : s < 17) (k : Fin 17) : Fin 17 := | |
| β¨if k.val β€ s then s - k.val else k.val, by | |
| split_ifs | |
| Β· exact lt_of_le_of_lt (Nat.sub_le _ _) hs | |
| Β· exact k.isLtβ© | |
| theorem boundedComplement_involutive (s : β) (hs : s < 17) : | |
| Function.Involutive (boundedComplement s hs) := by | |
| intro k | |
| apply Fin.ext | |
| dsimp only [boundedComplement] | |
| split_ifs <;> omega | |
| def boundedComplementEquiv (s : β) (hs : s < 17) : Equiv.Perm (Fin 17) where | |
| toFun := boundedComplement s hs | |
| invFun := boundedComplement s hs | |
| left_inv := boundedComplement_involutive s hs | |
| right_inv := boundedComplement_involutive s hs | |
| section NativeSupport | |
| variable {A : Type*} [Fintype A] | |
| theorem native_right_conditional_sum_eq (support : List Shape) (s : Shape) | |
| (p : Shape β β) (priority : Placement) (position : Fin 3) (q : Shape β A β β) | |
| (hn : support.Nodup) (hm : β u β support, complement s u β support) | |
| (hsupp : β u β support, β side, u side β€ s side) | |
| (hs : s (priority position) < 17) | |
| (hbound : β i : SupportIndex support, support[i.val] (priority position) < 17) | |
| (law : FiniteLaw (SupportIndex support)) | |
| (hlaw : β i : SupportIndex support, law.mass i = p support[i.val]) | |
| (hp : β u β support, p (complement s u) = p u) | |
| (hq : β i : SupportIndex support, β a, q support[i.val] a = 1) : | |
| (β k : Fin 17, (law.map (ownWeight support priority position hbound)).mass k * | |
| JointCompatibilityIncidence.groupedEntropy | |
| (law.conditional (ownWeight support priority position hbound) k).mass | |
| (JointCompatibilityIncidence.designatedGroup (fun i => | |
| AllFieldNativeCapacity.designated priority position (complement s support[i.val]))) | |
| (fun i => q (complement s support[i.val]))) = | |
| AllFieldNativeCapacity.groupedEntropy support p priority position q := by | |
| let hi : β u β support, complement s (complement s u) = u := | |
| fun u hu => complement_involution_of_le s u (hsupp u hu) | |
| let e := supportIndexEquiv support hn (complement s) hm hi | |
| let c := boundedComplementEquiv (s (priority position)) hs | |
| let weight := ownWeight support priority position hbound | |
| let d : SupportIndex support β Prop := | |
| fun i => AllFieldNativeCapacity.designated priority position support[i.val] | |
| let qβ : SupportIndex support β A β β := fun i => q support[i.val] | |
| have he (i : SupportIndex support) : | |
| support[(e i).val] = complement s support[i.val] := by | |
| simpa only [List.get_eq_getElem] using | |
| supportIndexEquiv_get support hn (complement s) hm hi i | |
| have hmass (i : SupportIndex support) : law.mass (e i) = law.mass i := by | |
| simp only [hlaw, he] | |
| exact hp _ (List.getElem_mem i.isLt) | |
| have hw (i : SupportIndex support) : c (weight i) = weight (e i) := by | |
| apply Fin.ext | |
| change (if support[i.val] (priority position) β€ s (priority position) | |
| then s (priority position) - support[i.val] (priority position) | |
| else support[i.val] (priority position)) = support[(e i).val] (priority position) | |
| rw [ite_eq_left (hsupp _ (List.getElem_mem i.isLt) _), he] | |
| rfl | |
| have hright := right_conditional_sum_eq e c law d weight qβ hmass hw hq | |
| have hd : d β e = fun i => | |
| AllFieldNativeCapacity.designated priority position (complement s support[i.val]) := by | |
| funext i | |
| dsimp only [d, Function.comp_apply] | |
| rw [he] | |
| have hqr : qβ β e = fun i => q (complement s support[i.val]) := by | |
| funext i | |
| dsimp only [qβ, Function.comp_apply] | |
| rw [he] | |
| rw [hd, hqr] at hright | |
| have hnonneg (i : SupportIndex support) : 0 β€ p support[i.val] := by | |
| rw [β hlaw i] | |
| exact law.nonneg i | |
| have hmassfun : law.mass = fun i : SupportIndex support => p support[i.val] := funext hlaw | |
| calc | |
| _ = JointCompatibilityIncidence.groupedEntropy law.mass | |
| (nativeGroup support priority position hbound) (fun i => q support[i.val]) := by | |
| simpa only [d, qβ, weight, nativeGroup] using hright | |
| _ = _ := by | |
| rw [hmassfun] | |
| exact groupedEntropy_eq_native support p priority position q hbound hnonneg hq | |
| theorem native_two_conditional_sums_eq (support : List Shape) (s : Shape) | |
| (p : Shape β β) (priority : Placement) (position : Fin 3) (q : Shape β A β β) | |
| (hn : support.Nodup) (hm : β u β support, complement s u β support) | |
| (hsupp : β u β support, β side, u side β€ s side) | |
| (hs : s (priority position) < 17) | |
| (hbound : β i : SupportIndex support, support[i.val] (priority position) < 17) | |
| (law : FiniteLaw (SupportIndex support)) | |
| (hlaw : β i : SupportIndex support, law.mass i = p support[i.val]) | |
| (hp : β u β support, p (complement s u) = p u) | |
| (hq : β i : SupportIndex support, β a, q support[i.val] a = 1) : | |
| (β k : Fin 17, (law.map (ownWeight support priority position hbound)).mass k * | |
| (JointCompatibilityIncidence.groupedEntropy | |
| (law.conditional (ownWeight support priority position hbound) k).mass | |
| (JointCompatibilityIncidence.designatedGroup (fun i => | |
| AllFieldNativeCapacity.designated priority position support[i.val])) | |
| (fun i => q support[i.val]) + | |
| JointCompatibilityIncidence.groupedEntropy | |
| (law.conditional (ownWeight support priority position hbound) k).mass | |
| (JointCompatibilityIncidence.designatedGroup (fun i => | |
| AllFieldNativeCapacity.designated priority position (complement s support[i.val]))) | |
| (fun i => q (complement s support[i.val])))) = | |
| 2 * AllFieldNativeCapacity.groupedEntropy support p priority position q := by | |
| simp only [mul_add, Finset.sum_add_distrib] | |
| rw [β native_groupedEntropy_eq_sum_conditional support p priority position q hbound law hlaw hq, | |
| native_right_conditional_sum_eq support s p priority position q hn hm hsupp hs | |
| hbound law hlaw hp hq] | |
| ring | |
| end NativeSupport | |
| def twoHalfConditionalCost {A : Type*} [Fintype A] | |
| (support : List Shape) (s : Shape) (priority : Placement) (position : Fin 3) | |
| (q : Shape β A β β) (law : FiniteLaw (SupportIndex support)) | |
| (weight : SupportIndex support β Fin 17) : β := | |
| β k : Fin 17, (law.map weight).mass k * | |
| (JointCompatibilityIncidence.groupedEntropy (law.conditional weight k).mass | |
| (JointCompatibilityIncidence.designatedGroup (fun i => | |
| AllFieldNativeCapacity.designated priority position support[i.val])) | |
| (fun i => q support[i.val]) + | |
| JointCompatibilityIncidence.groupedEntropy (law.conditional weight k).mass | |
| (JointCompatibilityIncidence.designatedGroup (fun i => | |
| AllFieldNativeCapacity.designated priority position (complement s support[i.val]))) | |
| (fun i => q (complement s support[i.val]))) | |
| theorem stageA_twoHalfConditionalCost_eq (g : Shape) (hg : g β positiveInitial) | |
| (priority : Placement) (position : Fin 3) : | |
| twoHalfConditionalCost (below g) g priority position | |
| (fun u a => (halfLaw u (priority position) a : β)) (stageASplitLaw g hg) | |
| (stageASplitWeight g hg (priority position)) = | |
| 2 * AllFieldNativeCapacity.groupedEntropy (below g) | |
| (fun u => (stageALaw g u : β)) priority position | |
| (fun u a => (halfLaw u (priority position) a : β)) := by | |
| have hs : g (priority position) < 17 := | |
| Nat.lt_succ_of_le ((positiveInitial_shape_spec g hg).1 (priority position)) | |
| let hb : β i : SupportIndex (below g), (below g)[i.val] (priority position) < 17 := | |
| fun i => lt_of_le_of_lt (below_le (List.getElem_mem i.isLt) _) hs | |
| have hq (i : SupportIndex (below g)) : | |
| β a, (halfLaw (below g)[i.val] (priority position) a : β) = 1 := | |
| (halfFiniteLaw _ (stageA_children_size g hg _ (List.getElem_mem i.isLt)) | |
| (priority position)).total | |
| have hh := native_two_conditional_sums_eq (below g) g | |
| (fun u => (stageALaw g u : β)) priority position | |
| (fun u a => (halfLaw u (priority position) a : β)) | |
| (stageA_below_nodup g hg) (fun u hu => (stageA_support_complement g hg u hu).1) | |
| (fun _ hu => below_le hu) hs hb (stageASplitLaw g hg) (fun _ => rfl) | |
| (fun u hu => by rw [stageALaw_complement g u hg hu]) hq | |
| have hw : ownWeight (below g) priority position hb = | |
| stageASplitWeight g hg (priority position) := by | |
| funext i | |
| apply Fin.ext | |
| simp only [ownWeight, stageASplitWeight, List.get_eq_getElem] | |
| rw [hw] at hh | |
| simpa only [twoHalfConditionalCost] using hh | |
| theorem stageB_twoHalfConditionalCost_eq (t : Shape) (ht : t β positiveSecond) | |
| (priority : Placement) (position : Fin 3) : | |
| twoHalfConditionalCost (below t) t priority position | |
| (fun u a => (littleLaw t u (priority position) a : β)) (stageBSplitLaw t ht) | |
| (stageBSplitWeight t ht (priority position)) = | |
| 2 * AllFieldNativeCapacity.groupedEntropy (below t) | |
| (fun u => (stageBLaw t u : β)) priority position | |
| (fun u a => (littleLaw t u (priority position) a : β)) := by | |
| have hs : t (priority position) < 17 := | |
| Nat.lt_succ_of_le ((positiveSecond_shape_spec t ht).1 (priority position)) | |
| let hb : β i : SupportIndex (below t), (below t)[i.val] (priority position) < 17 := | |
| fun i => lt_of_le_of_lt (below_le (List.getElem_mem i.isLt) _) hs | |
| have hq (i : SupportIndex (below t)) : | |
| β a, (littleLaw t (below t)[i.val] (priority position) a : β) = 1 := | |
| (littleFiniteLaw t _ (priority position)).total | |
| have hh := native_two_conditional_sums_eq (below t) t | |
| (fun u => (stageBLaw t u : β)) priority position | |
| (fun u a => (littleLaw t u (priority position) a : β)) | |
| (stageB_below_nodup t ht) (fun u hu => (stageB_support_complement t ht u hu).1) | |
| (fun _ hu => below_le hu) hs hb (stageBSplitLaw t ht) (fun _ => rfl) | |
| (fun u hu => by rw [stageBLaw_complement t u ht hu]) hq | |
| have hw : ownWeight (below t) priority position hb = | |
| stageBSplitWeight t ht (priority position) := by | |
| funext i | |
| apply Fin.ext | |
| simp only [ownWeight, stageBSplitWeight, List.get_eq_getElem] | |
| rw [hw] at hh | |
| simpa only [twoHalfConditionalCost] using hh | |
| theorem stageA_twoHalfConditionalCost_eq_entropy_sub_capacity | |
| (g : Shape) (hg : g β positiveInitial) (side : Fin 3) (hside : side β 0) : | |
| twoHalfConditionalCost (below g) g (Equiv.refl (Fin 3)) side | |
| (fun u a => (halfLaw u side a : β)) (stageASplitLaw g hg) | |
| (stageASplitWeight g hg side) = | |
| finiteEntropy (stageAPairLaw g hg side).mass - stageACapacity g side := by | |
| rw [stageACapacity_sharing g hg side hside] | |
| have hh := stageA_twoHalfConditionalCost_eq g hg (Equiv.refl (Fin 3)) side | |
| simpa only [Equiv.refl_apply, sub_sub_cancel] using hh | |
| theorem stageB_twoHalfConditionalCost_eq_entropy_sub_capacity | |
| (t : Shape) (ht : t β positiveSecond) (side : Fin 3) (hside : side β 0) : | |
| twoHalfConditionalCost (below t) t (stageBPriority t) side | |
| (fun u a => (littleLaw t u (stageBPriority t side) a : β)) (stageBSplitLaw t ht) | |
| (stageBSplitWeight t ht (stageBPriority t side)) = | |
| finiteEntropy (stageBPairLaw t ht (stageBPriority t side)).mass - | |
| stageBCapacity t side := by | |
| rw [stageBCapacity_sharing t ht side hside] | |
| have hh := stageB_twoHalfConditionalCost_eq t ht (stageBPriority t) side | |
| simpa only [sub_sub_cancel] using hh | |
| end MatrixMultiplication.AllFieldNativeGroupedRates | |
| end | |
| end OAI | |