math / data /lean /OAI /LinearAlgebra /MatrixMultiplication /JointExtraction /CompatibilityEntropyBound.lean
Download data/lean/OAI/LinearAlgebra/MatrixMultiplication/JointExtraction/CompatibilityEntropyBound.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 10.8 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/LinearAlgebra/MatrixMultiplication/JointExtraction/CompatibilityEntropyBound.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/LinearAlgebra/MatrixMultiplication/JointExtraction/CompatibilityEntropyBound.lean
-
curl -L -o CompatibilityEntropyBound.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/LinearAlgebra/MatrixMultiplication/JointExtraction/CompatibilityEntropyBound.lean
10.8 kB
| import OAI.LinearAlgebra.MatrixMultiplication.JointExtraction.CompatibilityIncidence | |
| namespace OAI | |
| /-! Joint tensor extraction, compatibility and entropy estimates. -/ | |
| noncomputable section | |
| open MatrixMultiplication.Foundation | |
| open MatrixMultiplication.JointTypeCounts MatrixMultiplication.JointCompatibilityIncidence | |
| open scoped BigOperators | |
| namespace MatrixMultiplication.JointCompatibilityEntropyBound | |
| attribute [local instance] Classical.propDecidable | |
| section ClassCounts | |
| variable {C : Type*} [Fintype C] [DecidableEq C] | |
| variable (Pos A : C β Type*) | |
| [β c, Fintype (Pos c)] [β c, DecidableEq (Pos c)] | |
| [β c, Fintype (A c)] [β c, DecidableEq (A c)] | |
| def classEntropy (counts : β c, A c β β) : β := | |
| β c, (Fintype.card (Pos c) : β) * | |
| finiteEntropy (fun a => (counts c a : β) / Fintype.card (Pos c)) | |
| def classTypeError : β := | |
| β c, ((Fintype.card (A c) : β) + 1) * | |
| (1 + Real.log (Fintype.card (Pos c) + 1 : β)) | |
| omit [Fintype C] [DecidableEq C] [β index, DecidableEq (Pos index)] in | |
| theorem fixedClassWords_size (counts : β c, A c β β) | |
| (w : FixedClassWords Pos A counts) (c : C) : | |
| Fintype.card (Pos c) = β a, counts c a := by | |
| calc | |
| Fintype.card (Pos c) = β a, wordPopulation (w c).val a := | |
| (wordPopulation_sum (w c).val).symm | |
| _ = β a, counts c a := Finset.sum_congr rfl fun a _ => (w c).property a | |
| theorem abs_log_card_sub_classEntropy_le (counts : β c, A c β β) | |
| (w : FixedClassWords Pos A counts) : | |
| |Real.log (Fintype.card (FixedClassWords Pos A counts) : β) - | |
| classEntropy Pos A counts| β€ classTypeError Pos A := by | |
| have hsize := fixedClassWords_size Pos A counts w | |
| simpa only [classEntropy, classTypeError, β hsize] using | |
| abs_log_fixedClassWords_card_sub_entropy_le Pos A counts hsize | |
| theorem fixedClassWords_card_le_exp (counts : β c, A c β β) | |
| (w : FixedClassWords Pos A counts) : | |
| (Fintype.card (FixedClassWords Pos A counts) : β) β€ | |
| Real.exp (classEntropy Pos A counts + classTypeError Pos A) := by | |
| have hpos : 0 < (Fintype.card (FixedClassWords Pos A counts) : β) := by | |
| exact_mod_cast (Fintype.card_pos_iff.mpr β¨wβ©) | |
| have h := (abs_le.mp (abs_log_card_sub_classEntropy_le Pos A counts w)).2 | |
| calc | |
| (Fintype.card (FixedClassWords Pos A counts) : β) = | |
| Real.exp (Real.log (Fintype.card (FixedClassWords Pos A counts) : β)) := | |
| (Real.exp_log hpos).symm | |
| _ β€ Real.exp (classEntropy Pos A counts + classTypeError Pos A) := | |
| Real.exp_le_exp.mpr (by linarith) | |
| theorem exp_le_fixedClassWords_card (counts : β c, A c β β) | |
| (w : FixedClassWords Pos A counts) : | |
| Real.exp (classEntropy Pos A counts - classTypeError Pos A) β€ | |
| (Fintype.card (FixedClassWords Pos A counts) : β) := by | |
| have hpos : 0 < (Fintype.card (FixedClassWords Pos A counts) : β) := by | |
| exact_mod_cast (Fintype.card_pos_iff.mpr β¨wβ©) | |
| have h := (abs_le.mp (abs_log_card_sub_classEntropy_le Pos A counts w)).1 | |
| calc | |
| Real.exp (classEntropy Pos A counts - classTypeError Pos A) β€ | |
| Real.exp (Real.log (Fintype.card (FixedClassWords Pos A counts) : β)) := | |
| Real.exp_le_exp.mpr (by linarith) | |
| _ = (Fintype.card (FixedClassWords Pos A counts) : β) := Real.exp_log hpos | |
| end ClassCounts | |
| section GroupCounts | |
| def wordTypeError (I A : Type*) [Fintype I] [Fintype A] : β := | |
| ((Fintype.card A : β) + 1) * (1 + Real.log (Fintype.card I + 1 : β)) + | |
| (Fintype.card A : β) * Real.log (Fintype.card I + 1 : β) | |
| theorem wordEntropyBound_eq_exp (I A : Type*) [Fintype I] [Fintype A] (H : β) : | |
| wordEntropyBound I A H = | |
| Real.exp ((Fintype.card I : β) * H + wordTypeError I A) := by | |
| unfold wordEntropyBound wordTypeError | |
| rw [show (Fintype.card I : β) * H + | |
| (((Fintype.card A : β) + 1) * (1 + Real.log (Fintype.card I + 1 : β)) + | |
| (Fintype.card A : β) * Real.log (Fintype.card I + 1 : β)) = | |
| (Fintype.card A : β) * Real.log (Fintype.card I + 1 : β) + | |
| ((Fintype.card I : β) * H + ((Fintype.card A : β) + 1) * | |
| (1 + Real.log (Fintype.card I + 1 : β))) by ring] | |
| conv_rhs => rw [Real.exp_add, Real.exp_nat_mul, Real.exp_log (by positivity)] | |
| simp only [Nat.cast_add, Nat.cast_one] | |
| variable {C : Type*} [Fintype C] [DecidableEq C] | |
| variable (Pos Shape A : C β Type*) | |
| [β c, Fintype (Pos c)] [β c, DecidableEq (Pos c)] | |
| [β c, Fintype (Shape c)] [β c, DecidableEq (Shape c)] | |
| [β c, Fintype (A c)] [β c, DecidableEq (A c)] | |
| variable (counts : β c, Shape c β β) | |
| (designated : β c, Shape c β Prop) | |
| (H : (Ξ£ c, Option (Shape c)) β β) | |
| (w : FixedClassWords Pos Shape counts) | |
| def groupedEntropy : β := | |
| β g : Ξ£ c, Option (Shape c), | |
| (Fintype.card (GroupPos (w g.1).val (designated g.1) g.2) : β) * H g | |
| def groupedTypeError : β := | |
| β g : Ξ£ c, Option (Shape c), | |
| wordTypeError (GroupPos (w g.1).val (designated g.1) g.2) (A g.1) | |
| omit [DecidableEq C] [β index, DecidableEq (Pos index)] | |
| [β index, DecidableEq (A index)] in | |
| theorem prod_wordEntropyBound_eq_exp : | |
| (β g : Ξ£ c, Option (Shape c), wordEntropyBound | |
| (GroupPos (w g.1).val (designated g.1) g.2) (A g.1) (H g)) = | |
| Real.exp (groupedEntropy Pos Shape counts designated H w + | |
| groupedTypeError Pos Shape A counts designated w) := by | |
| simp only [wordEntropyBound_eq_exp, groupedEntropy, groupedTypeError, | |
| β Real.exp_sum, Finset.sum_add_distrib] | |
| end GroupCounts | |
| section Compatibility | |
| variable {C : Type*} [Fintype C] [DecidableEq C] | |
| variable (Pos Shape Pair Left Right : C β Type*) | |
| [β c, Fintype (Pos c)] [β c, DecidableEq (Pos c)] | |
| [β c, Fintype (Shape c)] [β c, DecidableEq (Shape c)] | |
| [β c, Fintype (Pair c)] [β c, DecidableEq (Pair c)] | |
| [β c, Fintype (Left c)] [β c, DecidableEq (Left c)] | |
| [β c, Fintype (Right c)] [β c, DecidableEq (Right c)] | |
| variable (shapeCounts : β c, Shape c β β) (pairCounts : β c, Pair c β β) | |
| (leftPart : β c, Pair c β Left c) (rightPart : β c, Pair c β Right c) | |
| (designatedLeft designatedRight : β c, Shape c β Prop) | |
| (leftLaw : β c, Shape c β Left c β β) | |
| (rightLaw : β c, Shape c β Right c β β) (Ο : β) | |
| def compatibilityExponent (HL HR : (Ξ£ c, Option (Shape c)) β β) | |
| (w : FixedClassWords Pos Shape shapeCounts) : β := | |
| classEntropy Pos Shape shapeCounts - classEntropy Pos Pair pairCounts + | |
| groupedEntropy Pos Shape shapeCounts designatedLeft HL w + | |
| groupedEntropy Pos Shape shapeCounts designatedRight HR w + | |
| classTypeError Pos Shape + classTypeError Pos Pair + | |
| groupedTypeError Pos Shape Left shapeCounts designatedLeft w + | |
| groupedTypeError Pos Shape Right shapeCounts designatedRight w | |
| theorem compatibleCandidateCount_le_exp | |
| (w : FixedClassWords Pos Shape shapeCounts) | |
| (z : FixedClassWords Pos Pair pairCounts) | |
| (hpair : β c, Function.Injective (fun s : Pair c => (leftPart c s, rightPart c s))) | |
| (HL HR : (Ξ£ c, Option (Shape c)) β β) | |
| (controlLeft : SideEntropyControl Pos Shape Pair Left shapeCounts pairCounts | |
| leftPart designatedLeft leftLaw Ο HL w) | |
| (controlRight : SideEntropyControl Pos Shape Pair Right shapeCounts pairCounts | |
| rightPart designatedRight rightLaw Ο HR w) : | |
| (compatibleCandidateCount Pos Shape Pair Left Right shapeCounts pairCounts | |
| leftPart rightPart designatedLeft designatedRight leftLaw rightLaw Ο z : β) β€ | |
| Real.exp (compatibilityExponent Pos Shape Pair Left Right shapeCounts pairCounts | |
| designatedLeft designatedRight HL HR w) := by | |
| have h := compatibleCandidateCount_le_of_controls Pos Shape Pair Left Right | |
| shapeCounts pairCounts leftPart rightPart designatedLeft designatedRight | |
| leftLaw rightLaw Ο w z hpair HL HR controlLeft controlRight | |
| rw [prod_wordEntropyBound_eq_exp, prod_wordEntropyBound_eq_exp] at h | |
| let E := groupedEntropy Pos Shape shapeCounts designatedLeft HL w + | |
| groupedTypeError Pos Shape Left shapeCounts designatedLeft w + | |
| (groupedEntropy Pos Shape shapeCounts designatedRight HR w + | |
| groupedTypeError Pos Shape Right shapeCounts designatedRight w) | |
| rw [β Real.exp_add] at h | |
| have hnum : (Fintype.card (FixedClassWords Pos Shape shapeCounts) : β) * Real.exp E β€ | |
| Real.exp (classEntropy Pos Shape shapeCounts + classTypeError Pos Shape + E) := by | |
| conv_rhs => rw [Real.exp_add] | |
| exact mul_le_mul_of_nonneg_right | |
| (fixedClassWords_card_le_exp Pos Shape shapeCounts w) (Real.exp_pos E).le | |
| calc | |
| (compatibleCandidateCount Pos Shape Pair Left Right shapeCounts pairCounts | |
| leftPart rightPart designatedLeft designatedRight leftLaw rightLaw Ο z : β) β€ | |
| (Fintype.card (FixedClassWords Pos Shape shapeCounts) : β) * Real.exp E / | |
| Fintype.card (FixedClassWords Pos Pair pairCounts) := h | |
| _ β€ Real.exp (classEntropy Pos Shape shapeCounts + classTypeError Pos Shape + E) / | |
| Real.exp (classEntropy Pos Pair pairCounts - classTypeError Pos Pair) := | |
| div_le_divβ (Real.exp_pos _).le hnum (Real.exp_pos _) | |
| (exp_le_fixedClassWords_card Pos Pair pairCounts z) | |
| _ = Real.exp (compatibilityExponent Pos Shape Pair Left Right shapeCounts pairCounts | |
| designatedLeft designatedRight HL HR w) := by | |
| rw [β Real.exp_sub] | |
| congr 1 | |
| dsimp [E, compatibilityExponent] | |
| ring | |
| theorem log_compatibleCandidateCount_le | |
| (w : FixedClassWords Pos Shape shapeCounts) | |
| (z : FixedClassWords Pos Pair pairCounts) | |
| (hpair : β c, Function.Injective (fun s : Pair c => (leftPart c s, rightPart c s))) | |
| (HL HR : (Ξ£ c, Option (Shape c)) β β) | |
| (controlLeft : SideEntropyControl Pos Shape Pair Left shapeCounts pairCounts | |
| leftPart designatedLeft leftLaw Ο HL w) | |
| (controlRight : SideEntropyControl Pos Shape Pair Right shapeCounts pairCounts | |
| rightPart designatedRight rightLaw Ο HR w) | |
| (hpos : 0 < compatibleCandidateCount Pos Shape Pair Left Right shapeCounts pairCounts | |
| leftPart rightPart designatedLeft designatedRight leftLaw rightLaw Ο z) : | |
| Real.log (compatibleCandidateCount Pos Shape Pair Left Right shapeCounts pairCounts | |
| leftPart rightPart designatedLeft designatedRight leftLaw rightLaw Ο z : β) β€ | |
| compatibilityExponent Pos Shape Pair Left Right shapeCounts pairCounts | |
| designatedLeft designatedRight HL HR w := by | |
| have h := Real.log_le_log (Nat.cast_pos.mpr hpos) | |
| (compatibleCandidateCount_le_exp Pos Shape Pair Left Right shapeCounts pairCounts | |
| leftPart rightPart designatedLeft designatedRight leftLaw rightLaw Ο | |
| w z hpair HL HR controlLeft controlRight) | |
| simpa only [Real.log_exp] using h | |
| end Compatibility | |
| end MatrixMultiplication.JointCompatibilityEntropyBound | |
| end | |
| end OAI | |