Download data/lean/OAI/Combinatorics/EditApproximation/Geometry/BandEnvelopeBits.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 5.26 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/EditApproximation/Geometry/BandEnvelopeBits.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/EditApproximation/Geometry/BandEnvelopeBits.lean
-
curl -L -o BandEnvelopeBits.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/EditApproximation/Geometry/BandEnvelopeBits.lean
5.26 kB
| import OAI.Combinatorics.EditApproximation.Geometry.BandNumericalBits | |
| import OAI.Combinatorics.EditApproximation.Geometry.BandEnvelopes | |
| namespace OAI | |
| /-! Encoding lengths of the actual finite maxima and dyadic envelopes. | |
| These estimates include the scales below one and require no good seed. -/ | |
| namespace EditApproximation | |
| theorem positive_rational_binary_bounds (r : β) (B : β) | |
| (hr : 0 < r) (hbits : rationalEncodingBits r β€ B) : | |
| (2 : β) ^ (-(B : β€)) β€ r β§ r β€ (2 : β) ^ (B : β€) := by | |
| have hnumSize : Nat.size r.num.natAbs β€ B := by unfold rationalEncodingBits at hbits; omega | |
| have hdenSize : Nat.size r.den β€ B := by unfold rationalEncodingBits at hbits; omega | |
| have hnum : r.num.natAbs β€ 2 ^ B := | |
| (Nat.lt_size_self _).le.trans (Nat.pow_le_pow_right (by decide) hnumSize) | |
| have hden : r.den β€ 2 ^ B := | |
| (Nat.lt_size_self _).le.trans (Nat.pow_le_pow_right (by decide) hdenSize) | |
| have hnumPos : 0 < r.num := Rat.num_pos.mpr hr | |
| have hnumOne : 1 β€ r.num.natAbs := Int.natAbs_pos.mpr (ne_of_gt hnumPos) | |
| have hrep : r = (r.num.natAbs : β) / r.den := by | |
| rw [β Int.cast_natCast, Int.natCast_natAbs, abs_of_pos hnumPos] | |
| exact r.num_div_den.symm | |
| have hd : (0 : β) < r.den := by exact_mod_cast r.den_pos | |
| have hp : (0 : β) < (2 : β) ^ B := pow_pos (by norm_num) _ | |
| simp only [zpow_neg, zpow_natCast] | |
| rw [hrep] | |
| constructor | |
| Β· rw [inv_eq_one_div, div_le_div_iffβ hp hd, one_mul] | |
| exact_mod_cast (hden.trans (Nat.le_mul_of_pos_left _ (by omega : 0 < r.num.natAbs))) | |
| Β· apply (div_le_iffβ hd).mpr | |
| exact_mod_cast (hnum.trans (Nat.le_mul_of_pos_right _ r.den_pos)) | |
| theorem rationalDyadicCeiling_encoding (r : β) (B : β) | |
| (hr : 0 < r) (hbits : rationalEncodingBits r β€ B) : | |
| rationalEncodingBits (rationalDyadicCeiling r) β€ 5 * B + 5 := by | |
| have hrange := positive_rational_binary_bounds r B hr hbits | |
| have hlo := Int.clog_mono_right (b := 2) (zpow_pos (by norm_num : (0 : β) < 2) (-(B : β€))) hrange.1 | |
| have hhi := Int.clog_mono_right (b := 2) hr hrange.2 | |
| have hclog (z : β€) : Int.clog 2 ((2 : β) ^ z) = z := by | |
| simpa only [Nat.cast_ofNat] using (Int.clog_zpow (R := β) (b := 2) (by decide) z) | |
| rw [hclog] at hlo hhi | |
| have htwo : rationalEncodingBits (2 : β) = 4 := by | |
| rw [show (2 : β) = (2 : β) by norm_num, rationalEncodingBits_natCast] | |
| rfl | |
| unfold rationalDyadicCeiling | |
| cases he : Int.clog 2 r with | |
| | ofNat n => | |
| rw [he, Int.ofNat_eq_natCast] at hlo hhi | |
| have hn : n β€ B := by omega | |
| rw [Int.ofNat_eq_natCast, zpow_natCast] | |
| have h := rationalEncodingBits_pow (2 : β) n | |
| rw [htwo] at h | |
| omega | |
| | negSucc n => | |
| rw [he, Int.negSucc_eq] at hlo hhi | |
| have hn : n + 1 β€ B := by omega | |
| rw [zpow_negSucc] | |
| have hp := rationalEncodingBits_pow (2 : β) (n + 1) | |
| have hi := rationalEncodingBits_inv ((2 : β) ^ (n + 1)) | |
| rw [htwo] at hp | |
| omega | |
| theorem rationalMaximum_encoding (fallback : β) (values : List β) (B : β) | |
| (hfallback : rationalEncodingBits fallback β€ B) | |
| (hvalues : β value β values, rationalEncodingBits value β€ B) : | |
| rationalEncodingBits (rationalMaximum fallback values) β€ B := by | |
| induction values with | |
| | nil => exact hfallback | |
| | cons value rest ih => | |
| have hv := hvalues value List.mem_cons_self | |
| have ht := ih (fun q hq => hvalues q (List.mem_cons_of_mem _ hq)) | |
| change rationalEncodingBits (max value (rationalMaximum fallback rest)) β€ B | |
| rcases le_total value (rationalMaximum fallback rest) with h | h | |
| Β· simpa only [max_eq_right h] using ht | |
| Β· simpa only [max_eq_left h] using hv | |
| def bandEnvelopeEncodingBudget (M b initialBits : β) : β := | |
| 5 * max (Nat.size b + Nat.size M + 7) (initialBits + 2) + 5 | |
| theorem bandChildEnvelope_encoding {ny M : β} (b : β) | |
| (band : List (Fin M β TargetInterval ny)) | |
| (initial : Fin M β TargetInterval ny β β) (B : β) (hb : 0 < b) (hM : 0 < M) | |
| (hinitial : β action β band, β i, rationalEncodingBits (initial i (action i)) β€ B) | |
| (i : Fin M) : | |
| rationalEncodingBits (bandChildEnvelope b band initial i) β€ bandEnvelopeEncodingBudget M b B := by | |
| have hmax := rationalMaximum_encoding 0 (band.map fun action => initial i (action i)) (B + 2) | |
| (by norm_num [rationalEncodingBits]) (by | |
| intro q hq | |
| obtain β¨action, ha, rflβ© := List.mem_map.mp hq | |
| exact (hinitial action ha i).trans (by omega)) | |
| have hfloor := rationalEncodingBits_div (b : β) (M : β) | |
| rw [rationalEncodingBits_natCast, rationalEncodingBits_natCast] at hfloor | |
| have hbits : rationalEncodingBits (max ((b : β) / M) | |
| (rationalMaximum 0 (band.map fun action => initial i (action i)))) β€ | |
| max (Nat.size b + Nat.size M + 7) (B + 2) := by | |
| rcases le_total ((b : β) / M) (rationalMaximum 0 (band.map fun action => initial i (action i))) with h | h | |
| Β· rw [max_eq_right h] | |
| exact hmax.trans (Nat.le_max_right _ _) | |
| Β· rw [max_eq_left h] | |
| exact hfloor.trans (by have h := Nat.le_max_left (Nat.size b + Nat.size M + 7) (B + 2); omega) | |
| exact rationalDyadicCeiling_encoding _ _ | |
| ((div_pos (by exact_mod_cast hb) (by exact_mod_cast hM)).trans_le (le_max_left _ _)) hbits | |
| end EditApproximation | |
| end OAI | |