math / data /lean /OAI /Combinatorics /LowSpaceSubsetSum /Representation /RepresentationAllocation.lean
Download data/lean/OAI/Combinatorics/LowSpaceSubsetSum/Representation/RepresentationAllocation.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 8.26 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/LowSpaceSubsetSum/Representation/RepresentationAllocation.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/LowSpaceSubsetSum/Representation/RepresentationAllocation.lean
-
curl -L -o RepresentationAllocation.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/LowSpaceSubsetSum/Representation/RepresentationAllocation.lean
8.26 kB
| import OAI.Combinatorics.LowSpaceSubsetSum.Counting.BalancedLeafEntropy | |
| namespace OAI | |
| /-! # Feasibility of the executable representation allocation -/ | |
| noncomputable section | |
| namespace LowSpaceSubsetSum | |
| open scoped BigOperators | |
| open RepresentationSetup | |
| def representationCount (n : β) (g : Guesses n) (complement : Bool) (j : Fin 3) : β := | |
| if complement then mixerSize n / 2 - (g j).val else (g j).val | |
| def representationBits (n : β) (g : Guesses n) (complement : Bool) (j : Fin 3) : β := | |
| binomialBits (mixerSize n) (representationCount n g complement j) | |
| def representationBackgroundSize (n : β) : β := n - 3 * mixerSize n | |
| def representationParentSize (n : β) (g : Guesses n) (j : Fin 2) : β := | |
| allocateSide (j != 0) (representationBackgroundSize n) | |
| (representationBits n g false 0) (representationBits n g true 0) | |
| def representationChildSize (n : β) (g : Guesses n) (j : Fin 2) (right : Bool) : β := | |
| allocateSide right (representationParentSize n g j) | |
| (representationBits n g false j.succ) (representationBits n g true j.succ) | |
| def representationLeafCounts (n : β) (g : Guesses n) : Fin 8 β β := | |
| computedLeafCounts (representationBackgroundSize n) | |
| (representationBits n g false 0) (representationBits n g true 0) | |
| (representationBits n g false 1) (representationBits n g true 1) | |
| (representationBits n g false 2) (representationBits n g true 2) | |
| def representationEntropy (n : β) (g : Guesses n) (complement : Bool) (j : Fin 3) : β := | |
| (mixerSize n : β) * binaryEntropy | |
| (orientedDensity complement (((g j).val : β) / mixerSize n)) | |
| /-- The main-branch input-scale test supplies the small allocation error. -/ | |
| theorem representation_log_budget {n : β} {u : β} (hn : 10000 β€ n) | |
| (hmu : (mixerSize n : β) + 1 β€ u) (hlog : Real.logb 2 u β€ (n : β) / 1000000000) : | |
| Real.logb 2 ((mixerSize n : β) + 1) + 1 β€ (n : β) / 1000 := by | |
| have hmono := Real.logb_le_logb_of_le (by norm_num : (1 : β) < 2) | |
| (by positivity : (0 : β) < (mixerSize n : β) + 1) hmu | |
| have hnR : (10000 : β) β€ n := by exact_mod_cast hn | |
| linarith | |
| theorem representationCount_le (n : β) (g : Guesses n) (complement : Bool) (j : Fin 3) : | |
| representationCount n g complement j β€ mixerSize n := by | |
| have hg := (Finset.mem_Icc.mp (g j).property).2 | |
| change (g j).val β€ mixerSize n / 4 at hg | |
| cases complement <;> simp only [representationCount, Bool.false_eq_true, βreduceIte] <;> omega | |
| theorem representationCount_fraction {n : β} (g : Guesses n) (complement : Bool) | |
| (hm : 0 < mixerSize n) (j : Fin 3) : | |
| (representationCount n g complement j : β) / mixerSize n = | |
| orientedDensity complement (((g j).val : β) / mixerSize n) := by | |
| have hg := (Finset.mem_Icc.mp (g j).property).2 | |
| change (g j).val β€ mixerSize n / 4 at hg | |
| have hk : (g j).val β€ mixerSize n / 2 := by omega | |
| have he : 2 * (mixerSize n / 2) = mixerSize n := by unfold mixerSize; omega | |
| have heR : (2 : β) * (mixerSize n / 2 : β) = mixerSize n := by exact_mod_cast he | |
| have hmR : (mixerSize n : β) β 0 := by positivity | |
| cases complement | |
| Β· rfl | |
| Β· simp only [representationCount, orientedDensity, βreduceIte, Nat.cast_sub hk] | |
| rw [sub_div] | |
| congr 1 | |
| apply (div_eq_iff hmR).mpr | |
| nlinarith | |
| theorem representationBits_entropy_error {n : β} (g : Guesses n) (complement : Bool) | |
| (hm : 0 < mixerSize n) (j : Fin 3) : | |
| |(representationBits n g complement j : β) - representationEntropy n g complement j| < | |
| Real.logb 2 ((mixerSize n : β) + 1) + 1 := by | |
| have h := binomialBits_entropy_error (mixerSize n) (representationCount n g complement j) | |
| (representationCount_le n g complement j) | |
| rw [representationCount_fraction g complement hm j] at h | |
| exact h | |
| theorem representationBits_difference {n : β} (g : Guesses n) | |
| (hm : 0 < mixerSize n) (j : Fin 3) : | |
| |(representationBits n g true j : β) - representationBits n g false j| < | |
| (3 / 8 : β) * mixerSize n + 2 * (Real.logb 2 ((mixerSize n : β) + 1) + 1) := by | |
| apply binomialBits_difference (mixerSize n) (representationCount n g false j) | |
| (representationCount n g true j) | |
| (representationCount_le n g false j) (representationCount_le n g true j) | |
| Β· rw [representationCount_fraction g false hm] | |
| exact orientedDensity_mem (guess_density g hm j) false | |
| Β· rw [representationCount_fraction g true hm] | |
| exact orientedDensity_mem (guess_density g hm j) true | |
| theorem allocation_guards_of_error (r a b : β) {d : β} | |
| (hd : |(b : β) - a| β€ d) (hdr : d β€ r) : a β€ r + b β§ b β€ r + a := by | |
| have h := abs_le.mp hd | |
| constructor | |
| Β· have he : (a : β) β€ r + b := by linarith | |
| exact_mod_cast he | |
| Β· have he : (b : β) β€ r + a := by linarith | |
| exact_mod_cast he | |
| theorem weighted_parent_allocation_bound (side : Bool) (r a b : β) | |
| (ha : a β€ r + b) (hb : b β€ r + a) {A B e : β} | |
| (hA : |(a : β) - A| β€ e) (hB : |(b : β) - B| β€ e) : | |
| (if side then B else A) + (allocateSide side r a b : β) β€ | |
| (r : β) / 2 + (A + B) / 2 + e + 1 := by | |
| have h := (abs_lt.mp (allocateSide_error side r a b ha hb hA hB)).2 | |
| cases side <;> simp only [idealSide, Bool.false_eq_true, βreduceIte] at h β’ <;> linarith | |
| theorem allocation_three_levels_feasible (r : β) (a b : Fin 3 β β) {d : β} | |
| (hd0 : 0 β€ d) (hd : β j, |(b j : β) - a j| β€ d) (hr : 3 * d + 2 β€ r) : | |
| (a 0 β€ r + b 0 β§ b 0 β€ r + a 0) β§ | |
| β j : Fin 2, a j.succ β€ allocateSide (j != 0) r (a 0) (b 0) + b j.succ β§ | |
| b j.succ β€ allocateSide (j != 0) r (a 0) (b 0) + a j.succ := by | |
| have hdr : d β€ r := by linarith | |
| have hbase := allocation_guards_of_error r (a 0) (b 0) (hd 0) hdr | |
| have hparents := allocated_sides_lower r (a 0) (b 0) (hd 0) hdr | |
| refine β¨hbase, fun j => ?_β© | |
| apply allocation_guards_of_error _ _ _ (hd j.succ) | |
| fin_cases j | |
| Β· change d β€ (allocateLeft r (a 0) (b 0) : β) | |
| linarith [hparents.1] | |
| Β· change d β€ (allocateRight r (a 0) (b 0) : β) | |
| linarith [hparents.2] | |
| theorem representationAllocation_feasible {n : β} (g : Guesses n) (hn : 10000 β€ n) | |
| (hlog : Real.logb 2 ((mixerSize n : β) + 1) + 1 β€ (n : β) / 1000) : | |
| (representationBits n g false 0 β€ representationBackgroundSize n + | |
| representationBits n g true 0 β§ | |
| representationBits n g true 0 β€ representationBackgroundSize n + | |
| representationBits n g false 0) β§ | |
| β j : Fin 2, representationBits n g false j.succ β€ | |
| representationParentSize n g j + representationBits n g true j.succ β§ | |
| representationBits n g true j.succ β€ | |
| representationParentSize n g j + representationBits n g false j.succ := by | |
| have hm : 0 < mixerSize n := by unfold mixerSize; omega | |
| have hmbound := (mixerSize_bounds n).2 | |
| have hthreeR : (3 : β) * mixerSize n β€ n := by linarith | |
| have hthree : 3 * mixerSize n β€ n := by exact_mod_cast hthreeR | |
| have hr : (representationBackgroundSize n : β) = n - 3 * (mixerSize n : β) := by | |
| simp only [representationBackgroundSize, Nat.cast_sub hthree, Nat.cast_mul, Nat.cast_ofNat] | |
| let d : β := (3 / 8 : β) * mixerSize n + | |
| 2 * (Real.logb 2 ((mixerSize n : β) + 1) + 1) | |
| have hd : β j, |(representationBits n g true j : β) - representationBits n g false j| β€ d := | |
| fun j => (representationBits_difference g hm j).le | |
| have hd0 : 0 β€ d := (abs_nonneg _).trans (hd 0) | |
| have hmargin : 3 * d + 2 β€ (representationBackgroundSize n : β) := by | |
| have hnR : (10000 : β) β€ n := by exact_mod_cast hn | |
| dsimp only [d] | |
| rw [hr] | |
| linarith | |
| exact allocation_three_levels_feasible (representationBackgroundSize n) | |
| (representationBits n g false) (representationBits n g true) hd0 hd hmargin | |
| theorem representationLeafCounts_sum {n : β} (g : Guesses n) (hn : 10000 β€ n) | |
| (hlog : Real.logb 2 ((mixerSize n : β) + 1) + 1 β€ (n : β) / 1000) : | |
| β i, representationLeafCounts n g i = representationBackgroundSize n := by | |
| obtain β¨h0, hchildrenβ© := representationAllocation_feasible g hn hlog | |
| exact computedLeafCounts_sum _ _ _ _ _ _ _ h0.1 h0.2 | |
| (hchildren 0).1 (hchildren 0).2 (hchildren 1).1 (hchildren 1).2 | |
| end LowSpaceSubsetSum | |
| end | |
| end OAI | |