Download data/lean/OAI/Combinatorics/EditDistance/LowerParameters.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 10.2 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/EditDistance/LowerParameters.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/EditDistance/LowerParameters.lean
-
curl -L -o LowerParameters.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/EditDistance/LowerParameters.lean
10.2 kB
| import OAI.Combinatorics.EditDistance.PrimePool | |
| import OAI.Combinatorics.EditDistance.FamilyRecursion | |
| namespace OAI | |
| /-! | |
| # Recursive parameter bounds and exponential lower scales | |
| -/ | |
| namespace EditParameters | |
| open EditFamily | |
| def b (k : β) := 100*k | |
| def P (k : β) := (b k)^2 | |
| def h (k : β) := 10*k | |
| noncomputable def eta (k : β) : β := 2 * (2 * (P k : β)) ^ (2 * h k) / ((P k) ^ (b k / 2) : β) | |
| lemma prime_parameter_pos {k : β} (hk : 0 < k) : 0 < P k := by | |
| unfold P b | |
| positivity | |
| lemma eta_numerator_bound {k : β} (hk : 0 < k) : | |
| 2 * (2 * P k) ^ (2 * h k) * (h k)^k β€ (P k) ^ (b k / 2) := by | |
| have hp : 4 β€ P k := by dsimp [P,b]; nlinarith | |
| have hh : h k β€ P k := by dsimp [h,P,b]; nlinarith | |
| have hpow : (2 * P k)^2 β€ (P k)^3 := by nlinarith | |
| have he1 : 2*h k = 2*(10*k) := by rfl | |
| have he2 : b k / 2 = 50*k := by dsimp [b]; omega | |
| have htwo : 2 β€ (P k)^k := le_trans (by omega : 2 β€ P k) | |
| (Nat.le_self_pow (by omega) _) | |
| calc | |
| 2 * (2*P k)^(2*h k) * (h k)^k β€ | |
| (P k)^k * ((P k)^3)^(10*k) * (P k)^k := by | |
| rw [he1,pow_mul] | |
| gcongr | |
| _ = (P k)^(32*k) := by rw [βpow_mul,βpow_add,βpow_add]; congr 1; omega | |
| _ β€ (P k)^(b k / 2) := Nat.pow_le_pow_right (by omega) (by rw [he2]; omega) | |
| lemma eta_le {k : β} (hk : 0 < k) : eta k β€ 1 / (h k : β)^k := by | |
| have hp : (0 : β) < ((P k)^(b k/2) : β) := by | |
| exact_mod_cast pow_pos (prime_parameter_pos hk) _ | |
| have hh : (0 : β) < (h k : β)^k := by dsimp [h]; positivity | |
| apply (div_le_div_iffβ hp hh).mpr | |
| simpa only [one_mul,Nat.cast_mul,Nat.cast_pow,Nat.cast_ofNat] using | |
| (show (2 : β) * (2*(P k : β))^(2*h k) * (h k : β)^k β€ ((P k)^(b k/2) : β) by | |
| exact_mod_cast eta_numerator_bound hk) | |
| lemma budget_bound {k : β} (hk : 0 < k) (s : β) : | |
| familyBudget (b k) (P k) (h k) s β€ 2/(h k : β)^s + 2*eta k := by | |
| have hp : (0 : β) < h k := by dsimp [h]; positivity | |
| have htwo : (2 : β) β€ h k := by exact_mod_cast (show 2 β€ h k by dsimp [h]; omega) | |
| have he : 0 β€ eta k := by dsimp [eta]; positivity | |
| induction s with | |
| | zero => simp only [familyBudget,pow_zero,div_one]; linarith | |
| | succ s ih => | |
| change eta k + familyBudget (b k) (P k) (h k) s / h k β€ _ | |
| calc | |
| _ β€ eta k + (2/(h k : β)^s+2*eta k)/(h k) := by gcongr | |
| _ = 2/(h k : β)^(s+1) + (eta k + 2*eta k/(h k)) := by | |
| rw [pow_succ]; field_simp; ring | |
| _ β€ 2/(h k : β)^(s+1) + 2*eta k := by | |
| have ht : 2*eta k/(h k) β€ eta k := (div_le_iffβ hp).mpr (by nlinarith) | |
| linarith | |
| theorem budget_small {k : β} (hk : 0 < k) : | |
| familyBudget (b k) (P k) (h k) k β€ 4/(h k : β)^k := by | |
| have h1 := budget_bound hk k | |
| have h2 := eta_le hk | |
| simp only [div_eq_mul_inv,one_mul] at * | |
| linarith | |
| def codeBits (k : β) := Nat.clog 2 (familyAlphabet (b k) (P k) k) | |
| def codeWidth (k : β) := 2*codeBits k+3 | |
| def encodedLength (k : β) := codeWidth k * familyLength (b k) (P k) k | |
| lemma alphabet_power_bound {k : β} (hk : 0 < k) : | |
| familyAlphabet (b k) (P k) k β€ 2^(30*k^2) := by | |
| have hb : 0 < b k := by dsimp [b]; omega | |
| have hp : 0 < P k := prime_parameter_pos hk | |
| have hkb : k β€ 2^k := Nat.lt_two_pow_self.le | |
| have hbpow : 2*b k β€ 2^(k+8) := by | |
| simp only [pow_add] | |
| norm_num only [show 2^8=256 by norm_num] | |
| dsimp [b] | |
| nlinarith | |
| have hppow : 2*P k+1 β€ 2^(2*k+16) := by | |
| calc | |
| 2*P k+1 β€ (2*b k)^2 := by dsimp [P]; nlinarith | |
| _ β€ (2^(k+8))^2 := Nat.pow_le_pow_left hbpow 2 | |
| _ = _ := by rw [βpow_mul]; congr 1; ring | |
| calc | |
| familyAlphabet (b k) (P k) k β€ (2*P k+1)*(2*b k)^k := familyAlphabet_le hb hp k | |
| _ β€ 2^(2*k+16)*(2^(k+8))^k := Nat.mul_le_mul hppow (Nat.pow_le_pow_left hbpow k) | |
| _ = 2^(k^2+10*k+16) := by rw [βpow_mul,βpow_add]; congr 1; ring | |
| _ β€ 2^(30*k^2) := Nat.pow_le_pow_right (by omega) (by nlinarith) | |
| lemma bits_poly {k : β} (hk : 0 < k) : codeBits k β€ 30*k^2 := | |
| (Nat.clog_le_iff_le_pow (by norm_num)).mpr (alphabet_power_bound hk) | |
| lemma width_poly {k : β} (hk : 0 < k) : codeWidth k β€ 63*k^2 := by | |
| have ht := bits_poly hk | |
| dsimp [codeWidth] | |
| nlinarith | |
| lemma width_pos (k : β) : 0 < codeWidth k := by dsimp [codeWidth]; omega | |
| lemma encodedLength_pos {k : β} (hk : 0 < k) : 0 < encodedLength k := | |
| Nat.mul_pos (width_pos k) (familyLength_pos (by dsimp [b]; omega) (prime_parameter_pos hk) k) | |
| lemma length_power_bound (k : β) : familyLength (b k) (P k) k β€ | |
| (4*(b k)^(100*k+1))^k := by | |
| have he : b k / 2 = 50*k := by dsimp [b]; omega | |
| unfold familyLength | |
| apply Nat.pow_le_pow_left | |
| calc | |
| 2*(2*b k-1)*(P k)^(b k/2) β€ 4*b k*(P k)^(b k/2) := | |
| Nat.mul_le_mul_right _ (by have := Nat.sub_le (2*b k) 1; omega) | |
| _ = 4*(b k)^(100*k+1) := by | |
| dsimp [P] | |
| rw [he,βpow_mul,pow_succ] | |
| have he' : 2*(50*k)=100*k := by omega | |
| rw [he'] | |
| ring | |
| theorem log_length_bound {k : β} (hk : 2 β€ k) : | |
| Real.log (encodedLength k : β) β€ 1000*(k : β)^2*Real.log (k : β) := by | |
| have hkpos : 0 < k := by omega | |
| have kr : (2 : β) β€ k := by exact_mod_cast hk | |
| have kp : (0 : β) < k := by positivity | |
| have bp : (0 : β) < b k := by dsimp [b]; positivity | |
| have wp : (0 : β) < codeWidth k := by exact_mod_cast width_pos k | |
| have np : (0 : β) < familyLength (b k) (P k) k := by | |
| exact_mod_cast familyLength_pos (by dsimp [b]; omega) (prime_parameter_pos hkpos) k | |
| have lk : 0 β€ Real.log (k : β) := Real.log_nonneg (by linarith) | |
| have l2 : Real.log (2 : β) β€ Real.log (k : β) := Real.log_le_log (by norm_num) kr | |
| have l63 : Real.log (63 : β) β€ 6*Real.log (2 : β) := by | |
| have ht := Real.log_le_log (by norm_num : (0 : β)<63) (by norm_num : (63 : β) β€ 2^6) | |
| simpa only [Real.log_pow,Nat.cast_ofNat] using ht | |
| have l100 : Real.log (100 : β) β€ 7*Real.log (2 : β) := by | |
| have ht := Real.log_le_log (by norm_num : (0 : β)<100) (by norm_num : (100 : β) β€ 2^7) | |
| simpa only [Real.log_pow,Nat.cast_ofNat] using ht | |
| have l4 : Real.log (4 : β) = 2*Real.log (2 : β) := by | |
| rw [show (4 : β)=2^2 by norm_num,Real.log_pow]; norm_num | |
| have lb : Real.log (b k : β) β€ 8*Real.log (k : β) := by | |
| simp only [b,Nat.cast_mul,Nat.cast_ofNat,Real.log_mul (by norm_num : (100 : β) β 0) kp.ne'] | |
| linarith | |
| have lw : Real.log (codeWidth k : β) β€ 8*Real.log (k : β) := by | |
| have hw : (codeWidth k : β) β€ 63*(k : β)^2 := by exact_mod_cast width_poly hkpos | |
| have hl := Real.log_le_log wp hw | |
| rw [Real.log_mul (by norm_num) (by positivity),Real.log_pow] at hl | |
| norm_num only [Nat.cast_ofNat] at hl | |
| linarith | |
| have ln : Real.log (familyLength (b k) (P k) k : β) β€ | |
| (k : β)*(Real.log (4 : β)+(100*(k : β)+1)*Real.log (b k : β)) := by | |
| have hn : (familyLength (b k) (P k) k : β) β€ | |
| (4*(b k : β)^(100*k+1))^k := by exact_mod_cast length_power_bound k | |
| have hl := Real.log_le_log np hn | |
| rw [Real.log_pow,Real.log_mul (by norm_num) (by positivity),Real.log_pow] at hl | |
| push_cast at hl | |
| exact hl | |
| have he : Real.log (encodedLength k : β) = | |
| Real.log (codeWidth k : β)+Real.log (familyLength (b k) (P k) k : β) := by | |
| simp only [encodedLength,Nat.cast_mul,Real.log_mul wp.ne' np.ne'] | |
| rw [he] | |
| calc | |
| _ β€ 8*Real.log (k : β)+(k : β)*(2*Real.log (k : β)+ | |
| (100*(k : β)+1)*(8*Real.log (k : β))) := by | |
| apply add_le_add lw | |
| apply ln.trans | |
| gcongr | |
| linarith | |
| _ = (800*(k : β)^2+10*(k : β)+8)*Real.log (k : β) := by ring | |
| _ β€ 1000*(k : β)^2*Real.log (k : β) := by | |
| gcongr | |
| nlinarith | |
| noncomputable def lowerRatio (k : β) : β := ((h k : β)/24)^k/(16*(codeWidth k : β)) | |
| lemma log_width_le {k : β} (hk : 0 < k) : | |
| Real.log (codeWidth k : β) β€ Real.log (63 : β)+2*Real.log (k : β) := by | |
| have hw : (codeWidth k : β) β€ 63*(k : β)^2 := by exact_mod_cast width_poly hk | |
| have wp : (0 : β) < codeWidth k := by exact_mod_cast width_pos k | |
| have kp : (0 : β) < k := by exact_mod_cast hk | |
| have hh := Real.log_le_log wp hw | |
| rw [Real.log_mul (by norm_num) (by positivity),Real.log_pow] at hh | |
| norm_num only [Nat.cast_ofNat] at hh | |
| exact hh | |
| theorem ratio_exponential {k : β} (hk : 24^4 β€ k) : | |
| Real.exp ((1/2 : β)*(k : β)*Real.log (k : β)) β€ lowerRatio k := by | |
| have hk0 : 0 < k := by norm_num at hk; omega | |
| have kp : (0 : β) < k := by exact_mod_cast hk0 | |
| have k12 : (12 : β) β€ k := by exact_mod_cast (show 12 β€ k by norm_num at hk; omega) | |
| have k1008 : (1008 : β) β€ k := by exact_mod_cast (show 1008 β€ k by norm_num at hk; omega) | |
| have hn : (0 : β) < h k := by dsimp [h]; positivity | |
| have wp : (0 : β) < codeWidth k := by exact_mod_cast width_pos k | |
| have rp : 0 < lowerRatio k := by dsimp [lowerRatio]; positivity | |
| apply (Real.le_log_iff_exp_le rp).mp | |
| have lkp : 0 β€ Real.log (k : β) := Real.log_nonneg (by linarith) | |
| have l24 : 4*Real.log (24 : β) β€ Real.log (k : β) := by | |
| have ht := Real.log_le_log (by norm_num : (0 : β)<24^4) | |
| (show (24 : β)^4 β€ k by exact_mod_cast hk) | |
| simpa only [Real.log_pow,Nat.cast_ofNat] using ht | |
| have lh : Real.log (k : β) β€ Real.log (h k : β) := by | |
| apply Real.log_le_log kp | |
| dsimp [h]; push_cast; nlinarith | |
| have lw := log_width_le hk0 | |
| have lconst : Real.log (16 : β)+Real.log (63 : β) β€ Real.log (k : β) := by | |
| rw [βReal.log_mul (by norm_num) (by norm_num)] | |
| norm_num only [show (16 : β)*63=1008 by norm_num] | |
| exact Real.log_le_log (by norm_num) k1008 | |
| have logeq : Real.log (lowerRatio k) = | |
| (k : β)*(Real.log (h k : β)-Real.log (24 : β))- | |
| (Real.log (16 : β)+Real.log (codeWidth k : β)) := by | |
| dsimp [lowerRatio] | |
| rw [Real.log_div (by positivity) (by positivity),Real.log_pow, | |
| Real.log_div hn.ne' (by norm_num),Real.log_mul (by norm_num) wp.ne'] | |
| rw [logeq] | |
| have h1 := mul_le_mul_of_nonneg_left lh kp.le | |
| have h2 := mul_le_mul_of_nonneg_left l24 kp.le | |
| have h3 : 12*Real.log (k : β) β€ (k : β)*Real.log (k : β) := | |
| mul_le_mul_of_nonneg_right k12 lkp | |
| nlinarith | |
| end EditParameters | |
| end OAI | |