File size: 5,340 Bytes
4a56cd6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | import OAI.Algorithms.SubexponentialSAT.LeanCompat
import OAI.Algorithms.SubexponentialSAT.SqrtLog.AsymptoticLayoutParameters
namespace OAI.Algorithms
namespace SubexponentialSAT.SqrtLog.Asymptotic
open Filter
open scoped Topology
theorem layoutR_le_L (n : β) : layoutR n β€ L n := by
have h : (4 : β) < L n := (four_le_logSize n).trans_lt (logSize_lt_L n)
have hnat : 4 < L n := by exact_mod_cast h
exact max_le (by omega) (s_le_L n)
theorem layoutDen_le (n : β) : layoutDen n β€ 64 * w n := by
have h := Nat.log_mono_right (b := 2) (layoutR_le_L n)
simpa only [layoutDen, w, Nat.log2_eq_log_two] using Nat.mul_le_mul_left 64
(Nat.add_le_add_right h 1)
theorem layoutEnergy_le (n b q : β) (hb : b β€ L n ^ q) :
layoutEnergy n b β€ (q + 10) * w n := by
have hL : L n β€ 2 ^ w n := (Nat.lt_log2_self (n := L n)).le
have hr := layoutR_le_L n
have hz : 64 * b * layoutR n * L n ^ 2 β€ 2 ^ (6 + w n * (q + 3)) := by
calc
64 * b * layoutR n * L n ^ 2 β€ 64 * (L n ^ q) * L n * L n ^ 2 := by gcongr
_ = 64 * L n ^ (q + 3) := by ring
_ β€ 64 * (2 ^ w n) ^ (q + 3) := by gcongr
_ = 2 ^ (6 + w n * (q + 3)) := by rw [β pow_mul]; norm_num [pow_add]
have hlog := Nat.log_mono_right (b := 2) hz
rw [Nat.log_pow (by norm_num : 1 < (2 : β))] at hlog
have hw := w_pos n
unfold layoutEnergy
rw [Nat.log2_eq_log_two]
nlinarith
theorem eventually_layoutQ_ge (a : β) : βαΆ n : β in atTop, a β€ layoutQ n := by
have hh := eventually_w_power_le_L 1 (show (0 : β) < 64 * ((a : β) + 1) by positivity)
filter_upwards [hh] with n hn
simp only [pow_one] at hn
have hh' : 64 * (a + 1) * w n β€ L n := by exact_mod_cast hn
have hd := layoutDen_le n
apply (Nat.le_div_iff_mul_le (layoutDen_pos n)).2
nlinarith
theorem eventually_layoutQ_energy_ratio (b : β β β) (q A : β)
(hb : βαΆ n : β in atTop, b n β€ L n ^ q) :
βαΆ n : β in atTop, A * layoutEnergy n (b n) β€ layoutQ n := by
have hh := eventually_w_power_le_L 2
(show (0 : β) < 64 * ((A : β) + 1) * ((q : β) + 10) by positivity)
filter_upwards [hb, hh] with n hn hpow
have hp : 64 * (A + 1) * (q + 10) * w n ^ 2 β€ L n := by exact_mod_cast hpow
have he := layoutEnergy_le n (b n) q hn
have hd := layoutDen_le n
apply (Nat.le_div_iff_mul_le (layoutDen_pos n)).2
calc
A * layoutEnergy n (b n) * layoutDen n β€ A * ((q + 10) * w n) * (64 * w n) := by gcongr
_ β€ 64 * (A + 1) * (q + 10) * w n ^ 2 := by nlinarith
_ β€ L n := hp
theorem layout_fits_of_ratio (n b : β)
(hQ : 64 β€ layoutQ n) (he : 32768 * layoutEnergy n b β€ layoutQ n) :
4 * layoutCutoff n b β€ layoutQ n := by
have hs := Nat.sqrt_le' (128 * layoutQ n * layoutEnergy n b)
unfold layoutCutoff
nlinarith
theorem eventually_layout_fits (b : β β β) (q : β)
(hb : βαΆ n : β in atTop, b n β€ L n ^ q) :
βαΆ n : β in atTop, 4 * layoutCutoff n (b n) β€ layoutQ n := by
filter_upwards [eventually_layoutQ_ge 64,
eventually_layoutQ_energy_ratio b q 32768 hb] with n hn he
exact layout_fits_of_ratio n (b n) hn he
theorem layout_grid_square (n : β) :
(layoutR n ^ (4 * layoutQ n)) ^ 2 β€ n + 16 := by
have hbudget : 64 * (Nat.log2 (layoutR n) + 1) * layoutQ n β€ L n := by
exact Nat.mul_div_le (L n) (layoutDen n)
have hlog : 1 β€ Nat.log2 (n + 16) :=
(Nat.le_log2 (by omega)).2 (by norm_num)
have hexp : (Nat.log2 (layoutR n) + 1) * (4 * layoutQ n * 2) β€ Nat.log2 (n + 16) := by
unfold L at hbudget
nlinarith
calc
(layoutR n ^ (4 * layoutQ n)) ^ 2 = layoutR n ^ (4 * layoutQ n * 2) :=
(pow_mul _ _ _).symm
_ β€ (2 ^ (Nat.log2 (layoutR n) + 1)) ^ (4 * layoutQ n * 2) :=
Nat.pow_le_pow_left (Nat.lt_log2_self.le) _
_ = 2 ^ ((Nat.log2 (layoutR n) + 1) * (4 * layoutQ n * 2)) :=
(pow_mul _ _ _).symm
_ β€ 2 ^ Nat.log2 (n + 16) := Nat.pow_le_pow_right (by omega) hexp
_ β€ n + 16 := Nat.log2_self_le (by omega)
/-- The exponentially many grid cells still leave room for every fixed
polylogarithmic factor. The exponent 4Q is the actual squared grid factor. -/
theorem eventually_polylog_grid_le_n (f : β β β) (q : β) {C : β} (hC : 0 < C)
(hf0 : β n, 0 β€ f n)
(hf : βαΆ n : β in atTop, f n β€ C * (L n : β) ^ q) :
βαΆ n : β in atTop, f n * (layoutR n : β) ^ (4 * layoutQ n) β€ n := by
have hh := eventually_L_power_le_n (2 * q) (show 0 < 2 * C ^ 2 by positivity)
filter_upwards [hf, hh, eventually_ge_atTop (16 : β)] with n hn hp hn16
have hgrid : ((layoutR n : β) ^ (4 * layoutQ n)) ^ 2 β€ (n : β) + 16 := by
exact_mod_cast layout_grid_square n
have hsq : 2 * (f n) ^ 2 β€ n := by
have hpow := pow_le_pow_leftβ (hf0 n) hn 2
have heq : (C * (L n : β) ^ q) ^ 2 = C ^ 2 * (L n : β) ^ (2 * q) := by
rw [mul_pow, β pow_mul]
congr 2
omega
rw [heq] at hpow
nlinarith
have hn16' : (16 : β) β€ n := by exact_mod_cast hn16
have hmul := mul_le_mul hsq hgrid (sq_nonneg _) (by positivity : (0 : β) β€ n)
have hfpos := hf0 n
have hgpos : 0 β€ (layoutR n : β) ^ (4 * layoutQ n) := by positivity
nlinarith [sq_nonneg ((n : β) - f n * (layoutR n : β) ^ (4 * layoutQ n))]
end SubexponentialSAT.SqrtLog.Asymptotic
end OAI.Algorithms
|