Download data/lean/OAI/LinearAlgebra/MatrixMultiplication/JointExtraction/AmbientDegree.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 10.3 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/LinearAlgebra/MatrixMultiplication/JointExtraction/AmbientDegree.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/LinearAlgebra/MatrixMultiplication/JointExtraction/AmbientDegree.lean
-
curl -L -o AmbientDegree.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/LinearAlgebra/MatrixMultiplication/JointExtraction/AmbientDegree.lean
10.3 kB
| import OAI.LinearAlgebra.MatrixMultiplication.JointExtraction.Population | |
| import OAI.LinearAlgebra.MatrixMultiplication.JointExtraction.TypeCounts | |
| namespace OAI | |
| /-! Joint tensor extraction, compatibility and entropy estimates. -/ | |
| noncomputable section | |
| namespace MatrixMultiplication.JointAmbientDegree | |
| open MatrixMultiplication.Foundation JointPopulation | |
| open scoped BigOperators | |
| attribute [local instance] Classical.propDecidable | |
| variable {H : Type*} [Fintype H] [DecidableEq H] | |
| (counts : H β Shape β β) | |
| def localWord (t : JointCoarseHashing.Triple (Position counts)) (h : H) : | |
| Positions counts h β Shape := | |
| fun i => (t.1 β¨h, iβ©, t.2.1 β¨h, iβ©, t.2.2 β¨h, iβ©) | |
| omit [Fintype H] [DecidableEq H] in | |
| theorem localWord_injective : Function.Injective (localWord counts) := by | |
| intro t u he | |
| apply Prod.ext | |
| Β· funext p | |
| exact congrArg (fun w => (w p.1 p.2).1) he | |
| Β· apply Prod.ext | |
| Β· funext p | |
| exact congrArg (fun w => (w p.1 p.2).2.1) he | |
| Β· funext p | |
| exact congrArg (fun w => (w p.1 p.2).2.2) he | |
| def localAllowed (sum : H β β) (h : H) (w : Positions counts h β Shape) : Prop := | |
| (β i, (w i).1.val + (w i).2.1.val + (w i).2.2.val = sum h) β§ | |
| β s a, wordPopulation (shapeSide s β w) a = | |
| wordPopulation (sideWord counts s (triple counts (canonicalTarget counts)) h) a | |
| theorem localAllowed_of_mem_ambient (sum : H β β) | |
| (t : JointCoarseHashing.Triple (Position counts)) | |
| (ht : t β ambientSet counts sum) (h : H) : | |
| localAllowed counts sum h (localWord counts t h) := by | |
| obtain β¨hs, hmβ© := (Finset.mem_filter.mp ht).2 | |
| exact β¨fun i => hs β¨h, iβ©, fun s a => hm h s aβ© | |
| def sameSide (s : Fin 3) (t e : JointCoarseHashing.Triple (Position counts)) : Prop := | |
| β h, sideWord counts s t h = sideWord counts s e h | |
| def sharedAmbient (sum : H β β) (s : Fin 3) | |
| (e : JointCoarseHashing.Triple (Position counts)) : | |
| Finset (JointCoarseHashing.Triple (Position counts)) := | |
| (ambientSet counts sum).filter (sameSide counts s Β· e) | |
| def classBound (s : Fin 3) (e : JointCoarseHashing.Triple (Position counts)) | |
| (h : H) (entropyCap : β) : β := | |
| ((Fintype.card (Positions counts h) : β) + 1) ^ Fintype.card Shape * | |
| Real.exp ((Fintype.card (Positions counts h) : β) * | |
| (entropyCap - finiteEntropy (fun a => | |
| (wordPopulation (sideWord counts s e h) a : β) / | |
| Fintype.card (Positions counts h))) + | |
| ((Fintype.card Shape : β) + (Fintype.card (Fin 17) : β) + 2) * | |
| (1 + Real.log (Fintype.card (Positions counts h) + 1 : β))) | |
| def classExponent (s : Fin 3) (e : JointCoarseHashing.Triple (Position counts)) | |
| (h : H) (entropyCap : β) : β := | |
| (Fintype.card (Positions counts h) : β) * | |
| (entropyCap - finiteEntropy (fun a => | |
| (wordPopulation (sideWord counts s e h) a : β) / | |
| Fintype.card (Positions counts h))) + | |
| ((Fintype.card Shape : β) + (Fintype.card (Fin 17) : β) + 2) * | |
| (1 + Real.log (Fintype.card (Positions counts h) + 1 : β)) + | |
| (Fintype.card Shape : β) * Real.log (Fintype.card (Positions counts h) + 1 : β) | |
| omit [Fintype H] [DecidableEq H] in | |
| theorem classBound_eq_exp (s : Fin 3) | |
| (e : JointCoarseHashing.Triple (Position counts)) (h : H) (entropyCap : β) : | |
| classBound counts s e h entropyCap = Real.exp (classExponent counts s e h entropyCap) := by | |
| unfold classBound classExponent | |
| conv_rhs => rw [Real.exp_add, Real.exp_nat_mul, Real.exp_log (by positivity)] | |
| simp only [Nat.cast_add, Nat.cast_one] | |
| exact mul_comm _ _ | |
| omit [Fintype H] [DecidableEq H] in | |
| theorem classExponent_target_eq (s : Fin 3) (e : Target counts) (h : H) | |
| (entropyCap : β) : | |
| classExponent counts s (triple counts e) h entropyCap = | |
| classExponent counts s (triple counts (canonicalTarget counts)) h entropyCap := by | |
| simp_rw [classExponent, marginal_population_eq counts e (canonicalTarget counts)] | |
| theorem sharedAmbient_card_le (sum : H β β) (s : Fin 3) | |
| (e : JointCoarseHashing.Triple (Position counts)) (entropyCap : H β β) | |
| (hentropy : β h w, localAllowed counts sum h w β | |
| finiteEntropy (fun a => (wordPopulation w a : β) / | |
| Fintype.card (Positions counts h)) β€ entropyCap h) : | |
| ((sharedAmbient counts sum s e).card : β) β€ | |
| β h, classBound counts s e h (entropyCap h) := by | |
| classical | |
| let Allowed := fun h (w : Positions counts h β Shape) => | |
| localAllowed counts sum h w β§ β i, shapeSide s (w i) = sideWord counts s e h i | |
| let Local := fun h => {w : Positions counts h β Shape // Allowed h w} | |
| let encode : {t // t β sharedAmbient counts sum s e} β β h, Local h := fun t h => | |
| β¨localWord counts t.val h, localAllowed_of_mem_ambient counts sum t.val | |
| (Finset.mem_filter.mp t.property).1 h, | |
| fun i => congrFun ((Finset.mem_filter.mp t.property).2 h) iβ© | |
| have hinj : Function.Injective encode := by | |
| intro t u he | |
| apply Subtype.ext | |
| apply localWord_injective counts | |
| funext h | |
| exact congrArg Subtype.val (congrFun he h) | |
| have hcard : (sharedAmbient counts sum s e).card β€ β h, Fintype.card (Local h) := by | |
| simpa only [Fintype.card_coe, Fintype.card_pi] using | |
| Fintype.card_le_of_injective encode hinj | |
| have hlocal (h : H) : (Fintype.card (Local h) : β) β€ | |
| classBound counts s e h (entropyCap h) := by | |
| exact JointTypeCounts.card_allowed_over_coarse_le (shapeSide s) | |
| (sideWord counts s e h) (Allowed h) (entropyCap h) | |
| (fun w hw => hw.2) (fun w hw => hentropy h w hw.1) | |
| calc | |
| ((sharedAmbient counts sum s e).card : β) β€ | |
| β h, (Fintype.card (Local h) : β) := by exact_mod_cast hcard | |
| _ β€ _ := Finset.prod_le_prodβ (fun _ _ => Nat.cast_nonneg _) (fun h _ => hlocal h) | |
| omit [Fintype H] [DecidableEq H] in | |
| theorem sharesSide_iff (t e : JointCoarseHashing.Triple (Position counts)) : | |
| JointCoarseHashing.SharesSide t e β β s : Fin 3, sameSide counts s t e := by | |
| constructor | |
| Β· rintro (hx | hy | hz) | |
| Β· refine β¨0, fun h => ?_β© | |
| funext i | |
| change t.1 β¨h, iβ© = e.1 β¨h, iβ© | |
| exact congrFun hx.symm β¨h, iβ© | |
| Β· refine β¨1, fun h => ?_β© | |
| funext i | |
| change t.2.1 β¨h, iβ© = e.2.1 β¨h, iβ© | |
| exact congrFun hy.symm β¨h, iβ© | |
| Β· refine β¨2, fun h => ?_β© | |
| funext i | |
| change t.2.2 β¨h, iβ© = e.2.2 β¨h, iβ© | |
| exact congrFun hz.symm β¨h, iβ© | |
| Β· rintro β¨s, hsβ© | |
| fin_cases s | |
| Β· apply Or.inl | |
| funext p | |
| simpa [sideWord, shapeSide] using (congrFun (hs p.1) p.2).symm | |
| Β· apply Or.inr β Or.inl | |
| funext p | |
| simpa [sideWord, shapeSide] using (congrFun (hs p.1) p.2).symm | |
| Β· apply Or.inr β Or.inr | |
| funext p | |
| simpa [sideWord, shapeSide] using (congrFun (hs p.1) p.2).symm | |
| def neighbors (sum : H β β) (e : JointCoarseHashing.Triple (Position counts)) : | |
| Finset (JointCoarseHashing.Triple (Position counts)) := | |
| (ambientSet counts sum).filter (fun t => t β e β§ JointCoarseHashing.SharesSide t e) | |
| theorem neighbors_card_le_sum (sum : H β β) | |
| (e : JointCoarseHashing.Triple (Position counts)) : | |
| (neighbors counts sum e).card β€ β s : Fin 3, (sharedAmbient counts sum s e).card := by | |
| classical | |
| have hsub : neighbors counts sum e β | |
| (Finset.univ : Finset (Fin 3)).biUnion (fun s => sharedAmbient counts sum s e) := by | |
| intro t ht | |
| obtain β¨ha, _, hsβ© := Finset.mem_filter.mp ht | |
| obtain β¨s, hsβ© := (sharesSide_iff counts t e).mp hs | |
| exact Finset.mem_biUnion.mpr | |
| β¨s, Finset.mem_univ _, Finset.mem_filter.mpr β¨ha, hsβ©β© | |
| exact (Finset.card_le_card hsub).trans Finset.card_biUnion_le | |
| theorem neighbors_card_le (sum : H β β) | |
| (e : JointCoarseHashing.Triple (Position counts)) (entropyCap : H β β) | |
| (hentropy : β h w, localAllowed counts sum h w β | |
| finiteEntropy (fun a => (wordPopulation w a : β) / | |
| Fintype.card (Positions counts h)) β€ entropyCap h) : | |
| ((neighbors counts sum e).card : β) β€ | |
| β s : Fin 3, β h, classBound counts s e h (entropyCap h) := by | |
| calc | |
| ((neighbors counts sum e).card : β) β€ | |
| β s : Fin 3, ((sharedAmbient counts sum s e).card : β) := by | |
| exact_mod_cast neighbors_card_le_sum counts sum e | |
| _ β€ _ := Finset.sum_le_sum fun s _ => sharedAmbient_card_le counts sum s e entropyCap hentropy | |
| theorem neighbors_card_le_three_exp (sum : H β β) | |
| (e : JointCoarseHashing.Triple (Position counts)) (entropyCap : H β β) | |
| (hentropy : β h w, localAllowed counts sum h w β | |
| finiteEntropy (fun a => (wordPopulation w a : β) / | |
| Fintype.card (Positions counts h)) β€ entropyCap h) | |
| (exponent : β) | |
| (hupper : β s : Fin 3, β h, classExponent counts s e h (entropyCap h) β€ exponent) : | |
| ((neighbors counts sum e).card : β) β€ 3 * Real.exp exponent := by | |
| have hprod (s : Fin 3) : (β h, classBound counts s e h (entropyCap h)) β€ | |
| Real.exp exponent := by | |
| simp_rw [classBound_eq_exp] | |
| rw [β Real.exp_sum] | |
| exact Real.exp_le_exp.mpr (hupper s) | |
| calc | |
| ((neighbors counts sum e).card : β) β€ | |
| β s : Fin 3, β h, classBound counts s e h (entropyCap h) := | |
| neighbors_card_le counts sum e entropyCap hentropy | |
| _ β€ β _s : Fin 3, Real.exp exponent := Finset.sum_le_sum fun s _ => hprod s | |
| _ = _ := by simp | |
| theorem log_neighbors_card_le (sum : H β β) | |
| (e : JointCoarseHashing.Triple (Position counts)) (entropyCap : H β β) | |
| (hentropy : β h w, localAllowed counts sum h w β | |
| finiteEntropy (fun a => (wordPopulation w a : β) / | |
| Fintype.card (Positions counts h)) β€ entropyCap h) | |
| (exponent : β) | |
| (hupper : β s : Fin 3, β h, classExponent counts s e h (entropyCap h) β€ exponent) | |
| (hne : 0 < (neighbors counts sum e).card) : | |
| Real.log ((neighbors counts sum e).card : β) β€ Real.log 3 + exponent := by | |
| have hb := Real.log_le_log (by exact_mod_cast hne : | |
| (0 : β) < (neighbors counts sum e).card) | |
| (neighbors_card_le_three_exp counts sum e entropyCap hentropy exponent hupper) | |
| simpa only [Real.log_mul (by norm_num : (3 : β) β 0) (Real.exp_ne_zero _), | |
| Real.log_exp] using hb | |
| end MatrixMultiplication.JointAmbientDegree | |
| end | |
| end OAI | |