Download data/lean/OAI/Algorithms/SubexponentialSAT/SqrtLog/AsymptoticSchedule.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 8.65 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Algorithms/SubexponentialSAT/SqrtLog/AsymptoticSchedule.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Algorithms/SubexponentialSAT/SqrtLog/AsymptoticSchedule.lean
-
curl -L -o AsymptoticSchedule.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Algorithms/SubexponentialSAT/SqrtLog/AsymptoticSchedule.lean
8.65 kB
| import OAI.Algorithms.SubexponentialSAT.LeanCompat | |
| import OAI.Algorithms.SubexponentialSAT.SubexpRuntime | |
| namespace OAI.Algorithms | |
| /-! Exact, computable square-root-log scheduling. No algorithmic assertion is | |
| hidden in these numerical lemmas. Small inputs may have schedule zero. -/ | |
| namespace SubexponentialSAT.SqrtLog.Asymptotic | |
| open Filter | |
| open scoped Topology | |
| noncomputable def logSize (n : β) : β := Real.logb 2 ((n : β) + 16) | |
| noncomputable def logLogSize (n : β) : β := Real.logb 2 (logSize n) | |
| noncomputable def binaryScale (n : β) : β := | |
| (n : β) * logLogSize n ^ 2 / Real.sqrt (logSize n) | |
| def L (n : β) : β := Nat.log2 (n + 16) + 1 | |
| def w (n : β) : β := Nat.log2 (L n) + 1 | |
| def s (n : β) : β := Nat.sqrt (L n) / w n ^ 2 | |
| theorem w_pos (n : β) : 0 < w n := by unfold w; omega | |
| theorem L_pos (n : β) : 0 < L n := by unfold L; omega | |
| theorem le_s_iff (n a : β) : a β€ s n β a ^ 2 * w n ^ 4 β€ L n := by | |
| rw [s, Nat.le_div_iff_mul_le (pow_pos (w_pos n) 2), Nat.le_sqrt'] | |
| ring_nf | |
| theorem schedule_feasible (n : β) : s n ^ 2 * w n ^ 4 β€ L n := | |
| (le_s_iff n (s n)).mp le_rfl | |
| theorem schedule_maximal (n : β) : L n < (s n + 1) ^ 2 * w n ^ 4 := by | |
| have h := (le_s_iff n (s n + 1)).not | |
| exact Nat.lt_of_not_ge (h.mp (by omega)) | |
| theorem s_le_L (n : β) : s n β€ L n := | |
| (Nat.div_le_self _ _).trans (Nat.sqrt_le_self _) | |
| theorem four_le_logSize (n : β) : 4 β€ logSize n := by | |
| apply (Real.le_logb_iff_rpow_le (by norm_num : (1 : β) < 2) | |
| (by positivity : 0 < (n : β) + 16)).mpr | |
| norm_num | |
| theorem two_le_logLogSize (n : β) : 2 β€ logLogSize n := by | |
| apply (Real.le_logb_iff_rpow_le (by norm_num : (1 : β) < 2) | |
| (by have := four_le_logSize n; linarith : 0 < logSize n)).mpr | |
| norm_num | |
| exact four_le_logSize n | |
| theorem logSize_lt_L (n : β) : logSize n < (L n : β) := by | |
| simpa [logSize, L, Nat.cast_add, Nat.cast_ofNat] using | |
| SubexpExponentArithmetic.logb_lt_natLog2_add_one (n + 16) | |
| theorem L_le_logSize_add_one (n : β) : (L n : β) β€ logSize n + 1 := by | |
| have h := Real.natLog_le_logb (n + 16) 2 | |
| simpa [L, logSize, Nat.log2_eq_log_two, Nat.cast_add] using add_le_add_right h 1 | |
| theorem L_le_twice_logSize (n : β) : (L n : β) β€ 2 * logSize n := by | |
| have := L_le_logSize_add_one n | |
| have := four_le_logSize n | |
| linarith | |
| theorem logLogSize_lt_w (n : β) : logLogSize n < (w n : β) := by | |
| have h := SubexpExponentArithmetic.logb_lt_natLog2_add_one (L n) | |
| have hm : logLogSize n β€ Real.logb 2 (L n : β) := | |
| Real.logb_le_logb_of_le (by norm_num) (by have := four_le_logSize n; linarith) | |
| (logSize_lt_L n).le | |
| exact hm.trans_lt (by simpa [w] using h) | |
| theorem w_le_twice_logLogSize (n : β) : (w n : β) β€ 2 * logLogSize n := by | |
| have hp : (0 : β) < logSize n := by have := four_le_logSize n; linarith | |
| have hL : (0 : β) < L n := by exact_mod_cast L_pos n | |
| have hn := Real.natLog_le_logb (L n) 2 | |
| have hlog : Real.logb 2 (L n : β) β€ 1 + logLogSize n := by | |
| calc | |
| Real.logb 2 (L n : β) β€ Real.logb 2 (2 * logSize n) := | |
| Real.logb_le_logb_of_le (by norm_num) hL (L_le_twice_logSize n) | |
| _ = 1 + logLogSize n := by | |
| rw [Real.logb_mul (by norm_num : (2 : β) β 0) hp.ne'] | |
| norm_num [logLogSize] | |
| have hw : (w n : β) β€ Real.logb 2 (L n : β) + 1 := by | |
| simpa [w, Nat.log2_eq_log_two] using add_le_add_right hn 1 | |
| have := two_le_logLogSize n | |
| linarith | |
| theorem logSize_tendsto : Tendsto logSize atTop atTop := by | |
| exact (Real.tendsto_logb_atTop (by norm_num : (1 : β) < 2)).comp | |
| ((tendsto_natCast_atTop_atTop (R := β)).atTop_add tendsto_const_nhds) | |
| theorem eventually_le_s (a : β) : βαΆ n : β in atTop, a β€ s n := by | |
| have hb := logSize_tendsto.eventually | |
| (SubexpRuntime.eventually_logb_power_le 4 | |
| (show (0 : β) < ((a : β) + 1) ^ 2 * 16 by positivity)) | |
| filter_upwards [hb] with n hn | |
| have hw : (w n : β) β€ 2 * Real.logb 2 (logSize n + 16) := by | |
| have hm : logLogSize n β€ Real.logb 2 (logSize n + 16) := | |
| Real.logb_le_logb_of_le (by norm_num) | |
| (by have := four_le_logSize n; linarith) (by linarith) | |
| exact (w_le_twice_logLogSize n).trans (by linarith) | |
| have hp := pow_le_pow_leftβ (show (0 : β) β€ w n by positivity) hw 4 | |
| have ha : (a : β) ^ 2 * (w n : β) ^ 4 β€ (L n : β) := by | |
| calc | |
| (a : β) ^ 2 * (w n : β) ^ 4 β€ | |
| ((a : β) + 1) ^ 2 * (2 * Real.logb 2 (logSize n + 16)) ^ 4 := by | |
| apply mul_le_mul | |
| Β· nlinarith [Nat.cast_nonneg (Ξ± := β) a] | |
| Β· exact hp | |
| Β· positivity | |
| Β· positivity | |
| _ = (((a : β) + 1) ^ 2 * 16) * Real.logb 2 (logSize n + 16) ^ 4 := by ring_nf | |
| _ β€ logSize n := hn | |
| _ β€ (L n : β) := (logSize_lt_L n).le | |
| exact (le_s_iff n a).mpr (by exact_mod_cast ha) | |
| theorem s_tendsto : Tendsto s atTop atTop := tendsto_atTop.2 eventually_le_s | |
| theorem schedule_upper (n : β) : | |
| (s n : β) β€ 2 * Real.sqrt (logSize n) / logLogSize n ^ 2 := by | |
| have ht := four_le_logSize n | |
| have hW := two_le_logLogSize n | |
| have hs0 : (0 : β) β€ s n := by positivity | |
| have hw0 : (0 : β) β€ w n := by positivity | |
| have hfeas : (s n : β) ^ 2 * (w n : β) ^ 4 β€ (L n : β) := by | |
| exact_mod_cast schedule_feasible n | |
| have hw := logLogSize_lt_w n | |
| have hsq : logLogSize n ^ 2 β€ (w n : β) ^ 2 := by nlinarith | |
| have hr0 := Real.sqrt_nonneg (logSize n) | |
| have hroot := Real.sq_sqrt (show 0 β€ logSize n by linarith) | |
| have hprod : (s n : β) * (w n : β) ^ 2 β€ 2 * Real.sqrt (logSize n) := by | |
| have hprod0 : 0 β€ (s n : β) * (w n : β) ^ 2 := by positivity | |
| have hp : ((s n : β) * (w n : β) ^ 2) ^ 2 β€ 2 * logSize n := by | |
| calc | |
| _ = (s n : β) ^ 2 * (w n : β) ^ 4 := by ring_nf | |
| _ β€ (L n : β) := hfeas | |
| _ β€ 2 * logSize n := L_le_twice_logSize n | |
| nlinarith | |
| apply (le_div_iffβ (sq_pos_of_pos (show 0 < logLogSize n by linarith))).2 | |
| exact (mul_le_mul_of_nonneg_left hsq hs0).trans hprod | |
| /-- An explicit lower-bound comparison, with the only small-input condition | |
| being positivity of the actual integer schedule. -/ | |
| theorem sqrt_logSize_le (n : β) (hs : 1 β€ s n) : | |
| Real.sqrt (logSize n) β€ 8 * (s n : β) * logLogSize n ^ 2 := by | |
| have ht := four_le_logSize n | |
| have hW := two_le_logLogSize n | |
| have hs' : (1 : β) β€ s n := by exact_mod_cast hs | |
| have hm : (L n : β) < ((s n : β) + 1) ^ 2 * (w n : β) ^ 4 := by | |
| exact_mod_cast schedule_maximal n | |
| have hroot := Real.sq_sqrt (show 0 β€ logSize n by linarith) | |
| have hr0 := Real.sqrt_nonneg (logSize n) | |
| have hw0 : (0 : β) β€ w n := by positivity | |
| have hw := w_le_twice_logLogSize n | |
| have hw2 : (w n : β) ^ 2 β€ 4 * logLogSize n ^ 2 := by nlinarith | |
| have hfirst : Real.sqrt (logSize n) β€ ((s n : β) + 1) * (w n : β) ^ 2 := by | |
| apply Real.sqrt_le_iff.2 | |
| refine β¨by positivity, ?_β© | |
| calc | |
| logSize n β€ (L n : β) := (logSize_lt_L n).le | |
| _ β€ ((s n : β) + 1) ^ 2 * (w n : β) ^ 4 := hm.le | |
| _ = (((s n : β) + 1) * (w n : β) ^ 2) ^ 2 := by ring_nf | |
| have hmul := mul_le_mul_of_nonneg_left hw2 (show 0 β€ (s n : β) + 1 by positivity) | |
| nlinarith [sq_nonneg (logLogSize n)] | |
| theorem inverse_schedule_le (n : β) (hs : 1 β€ s n) : | |
| (n : β) / s n β€ 8 * binaryScale n := by | |
| have hs' : (0 : β) < s n := by exact_mod_cast (by omega : 0 < s n) | |
| have ht : 0 < Real.sqrt (logSize n) := | |
| Real.sqrt_pos.2 (by have := four_le_logSize n; linarith) | |
| have h := mul_le_mul_of_nonneg_left (sqrt_logSize_le n hs) (Nat.cast_nonneg n) | |
| unfold binaryScale | |
| rw [show 8 * ((n : β) * logLogSize n ^ 2 / Real.sqrt (logSize n)) = | |
| (8 * (n : β) * logLogSize n ^ 2) / Real.sqrt (logSize n) by ring_nf] | |
| apply (div_le_div_iffβ hs' ht).2 | |
| convert h using 1 | |
| ring_nf | |
| theorem eventually_inverse_schedule_le : | |
| βαΆ n : β in atTop, (n : β) / s n β€ 8 * binaryScale n := by | |
| filter_upwards [eventually_le_s 1] with n hn | |
| exact inverse_schedule_le n hn | |
| /-- Both comparisons have absolute constants; the lower bound is eventual | |
| because the exact integer schedule is deliberately allowed to be zero. -/ | |
| theorem eventually_schedule_comparison : | |
| βαΆ n : β in atTop, | |
| Real.sqrt (logSize n) / (8 * logLogSize n ^ 2) β€ (s n : β) β§ | |
| (s n : β) β€ 2 * Real.sqrt (logSize n) / logLogSize n ^ 2 := by | |
| filter_upwards [eventually_le_s 1] with n hn | |
| refine β¨?_, schedule_upper nβ© | |
| have hW := two_le_logLogSize n | |
| apply (div_le_iffβ (show 0 < 8 * logLogSize n ^ 2 by positivity)).2 | |
| nlinarith [sqrt_logSize_le n hn] | |
| end SubexponentialSAT.SqrtLog.Asymptotic | |
| end OAI.Algorithms | |