File size: 13,965 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 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | import OAI.Algorithms.SubexponentialSAT.SqrtLog.StatementScale
import Mathlib.Analysis.SpecialFunctions.Log.Base
import Mathlib.Data.Nat.Sqrt
/-! Numerical parameters for the disjoint counting reduction. -/
namespace OAI.Algorithms.SubexponentialSAT.SqrtLogSpace
/-- The literal base-two exponent in the counting manuscript. -/
noncomputable def rho (n : β) : β :=
(n : β) * (Real.logb 2 (Real.logb 2 n)) ^ 2 / Real.sqrt (Real.logb 2 n)
/-- Exact ceiling logarithms, computed with natural-number arithmetic. -/
def sparsifyLambda (n : β) : β := Nat.clog 2 n
def sparsifyNu (n : β) : β := Nat.clog 2 (sparsifyLambda n)
def sparsifySchedule (n : β) : β :=
Nat.sqrt (sparsifyLambda n) / sparsifyNu n ^ 2
theorem sparsifyLambda_eq_ceil (n : β) :
sparsifyLambda n = βReal.logb 2 nββ :=
(Real.natCeil_logb_natCast 2 n).symm
theorem sparsifyNu_eq_ceil (n : β) :
sparsifyNu n = βReal.logb 2 (sparsifyLambda n)ββ :=
(Real.natCeil_logb_natCast 2 (sparsifyLambda n)).symm
theorem sparsifyNu_pos {n : β} (hn : 20 β€ n) : 0 < sparsifyNu n := by
have hLambda : 2 β€ sparsifyLambda n := by
have h := (Nat.pow_lt_iff_lt_clog (by norm_num : 1 < (2 : β))).mp
(show 2 ^ 1 < n by omega)
exact h
exact Nat.clog_pos (by norm_num) hLambda
theorem le_sparsifySchedule_iff {n : β} (hn : 20 β€ n) (a : β) :
a β€ sparsifySchedule n β a ^ 2 * sparsifyNu n ^ 4 β€ sparsifyLambda n := by
rw [sparsifySchedule, Nat.le_div_iff_mul_le (pow_pos (sparsifyNu_pos hn) 2),
Nat.le_sqrt']
ring_nf
theorem sparsifySchedule_feasible {n : β} (hn : 20 β€ n) :
sparsifySchedule n ^ 2 * sparsifyNu n ^ 4 β€ sparsifyLambda n :=
(le_sparsifySchedule_iff hn _).mp le_rfl
theorem sparsifySchedule_maximal {n : β} (hn : 20 β€ n) :
sparsifyLambda n < (sparsifySchedule n + 1) ^ 2 * sparsifyNu n ^ 4 := by
have h := (le_sparsifySchedule_iff hn (sparsifySchedule n + 1)).not
exact Nat.lt_of_not_ge (h.mp (by omega))
theorem sparsifySchedule_le_lambda (n : β) : sparsifySchedule n β€ sparsifyLambda n :=
(Nat.div_le_self _ _).trans (Nat.sqrt_le_self _)
theorem sparsifyLambda_le_log2_shift (n : β) :
sparsifyLambda n β€ Nat.log2 (n + 16) + 1 := by
apply (Nat.le_pow_iff_clog_le (by norm_num : 1 < (2 : β))).mp
exact (Nat.le_add_right n 16).trans Nat.lt_log2_self.le
theorem sparsify_parameters_le_input (n : β) :
sparsifyLambda n β€ n β§ sparsifyNu n β€ n β§ sparsifySchedule n β€ n := by
have hLambda : sparsifyLambda n β€ n :=
(Nat.le_pow_iff_clog_le (by norm_num : 1 < (2 : β))).mp Nat.lt_two_pow_self.le
have hNu : sparsifyNu n β€ sparsifyLambda n :=
(Nat.le_pow_iff_clog_le (by norm_num : 1 < (2 : β))).mp Nat.lt_two_pow_self.le
exact β¨hLambda, hNu.trans hLambda, (sparsifySchedule_le_lambda n).trans hLambdaβ©
theorem four_le_logb {n : β} (hn : 20 β€ n) : 4 β€ Real.logb 2 n := by
apply (Real.le_logb_iff_rpow_le (by norm_num : (1 : β) < 2)
(by exact_mod_cast (show 0 < n by omega))).mpr
norm_num
exact_mod_cast (show 16 β€ n by omega)
theorem sparsifyLambda_bounds {n : β} (hn : 20 β€ n) :
Real.logb 2 n β€ (sparsifyLambda n : β) β§
(sparsifyLambda n : β) β€ 2 * Real.logb 2 n := by
rw [sparsifyLambda_eq_ceil]
have h := four_le_logb hn
exact β¨Nat.le_ceil _, by
have := Nat.ceil_lt_add_one (by linarith : 0 β€ Real.logb 2 n)
linarithβ©
theorem sparsifyNu_le {n : β} (hn : 20 β€ n) :
(sparsifyNu n : β) β€ 2 * Real.logb 2 (Real.logb 2 n) := by
have hl := four_le_logb hn
have hl0 : 0 < Real.logb 2 n := by linarith
have hLambda := sparsifyLambda_bounds hn
have hLambda0 : 0 < (sparsifyLambda n : β) := by linarith
have hv : 2 β€ Real.logb 2 (Real.logb 2 n) := by
apply (Real.le_logb_iff_rpow_le (by norm_num : (1 : β) < 2) hl0).mpr
norm_num
exact hl
have hlog : Real.logb 2 (sparsifyLambda n) β€ 1 + Real.logb 2 (Real.logb 2 n) := by
calc
_ β€ Real.logb 2 (2 * Real.logb 2 n) :=
Real.logb_le_logb_of_le (by norm_num) hLambda0 hLambda.2
_ = _ := by rw [Real.logb_mul (by norm_num : (2 : β) β 0) hl0.ne']; norm_num
have hlog0 : 0 β€ Real.logb 2 (sparsifyLambda n) :=
Real.logb_nonneg (by norm_num) (by linarith)
rw [sparsifyNu_eq_ceil]
have := Nat.ceil_lt_add_one hlog0
linarith
theorem inverse_sparsifySchedule_le {n : β} (hn : 20 β€ n)
(hs : 1 β€ sparsifySchedule n) : (n : β) / sparsifySchedule n β€ 8 * rho n := by
have hl := four_le_logb hn
have hl0 : 0 < Real.logb 2 n := by linarith
have hLambda := (sparsifyLambda_bounds hn).1
have hm : (sparsifyLambda n : β) <
((sparsifySchedule n : β) + 1) ^ 2 * (sparsifyNu n : β) ^ 4 := by
exact_mod_cast sparsifySchedule_maximal hn
have hroot : Real.sqrt (Real.logb 2 n) β€
((sparsifySchedule n : β) + 1) * (sparsifyNu n : β) ^ 2 := by
apply Real.sqrt_le_iff.2
refine β¨by positivity, ?_β©
calc
_ β€ (sparsifyLambda n : β) := hLambda
_ β€ ((sparsifySchedule n : β) + 1) ^ 2 * (sparsifyNu n : β) ^ 4 := hm.le
_ = _ := by ring_nf
have hv : 0 β€ Real.logb 2 (Real.logb 2 n) :=
Real.logb_nonneg (by norm_num) (by linarith)
have hnu := sparsifyNu_le hn
have hnu2 : (sparsifyNu n : β) ^ 2 β€
4 * (Real.logb 2 (Real.logb 2 n)) ^ 2 := by
nlinarith [Nat.cast_nonneg (Ξ± := β) (sparsifyNu n)]
have hs' : (1 : β) β€ sparsifySchedule n := by exact_mod_cast hs
have hroot' : Real.sqrt (Real.logb 2 n) β€
8 * (sparsifySchedule n : β) * (Real.logb 2 (Real.logb 2 n)) ^ 2 := by
have hmul := mul_le_mul_of_nonneg_left hnu2
(show 0 β€ (sparsifySchedule n : β) + 1 by positivity)
nlinarith [sq_nonneg (Real.logb 2 (Real.logb 2 n))]
unfold rho
rw [show 8 * ((n : β) * (Real.logb 2 (Real.logb 2 n)) ^ 2 /
Real.sqrt (Real.logb 2 n)) =
(8 * (n : β) * (Real.logb 2 (Real.logb 2 n)) ^ 2) /
Real.sqrt (Real.logb 2 n) by ring_nf]
apply (div_le_div_iffβ (by linarith : (0 : β) < sparsifySchedule n)
(Real.sqrt_pos.2 hl0)).2
have := mul_le_mul_of_nonneg_left hroot' (Nat.cast_nonneg n)
nlinarith
theorem sparsifySchedule_tendsto :
Filter.Tendsto sparsifySchedule Filter.atTop Filter.atTop := by
apply Filter.tendsto_atTop.2
intro a
have hc : 0 < Real.log (2 : β) := Real.log_pos (by norm_num)
have he : 0 < Real.log (2 : β) ^ 4 / (16 * ((a : β) + 1) ^ 2) := by positivity
have hsmall := (Real.isLittleO_pow_log_id_atTop (n := 4)).bound he
have ht : Filter.Tendsto (fun n : β => Real.logb 2 (n : β))
Filter.atTop Filter.atTop :=
(Real.tendsto_logb_atTop (by norm_num : (1 : β) < 2)).comp
(tendsto_natCast_atTop_atTop (R := β))
filter_upwards [ht.eventually hsmall, Filter.eventually_ge_atTop (20 : β)] with n hb hn
have hl := four_le_logb hn
have hl0 : 0 β€ Real.logb 2 n := by linarith
have hlog0 : 0 β€ Real.log (Real.logb 2 n) := Real.log_nonneg (by linarith)
have hb' : Real.log (Real.logb 2 n) ^ 4 β€
Real.log (2 : β) ^ 4 / (16 * ((a : β) + 1) ^ 2) * Real.logb 2 n := by
simpa only [Function.id_def, Real.norm_eq_abs,
abs_of_nonneg (pow_nonneg hlog0 4), abs_of_nonneg hl0] using hb
have hnu := sparsifyNu_le hn
have hnu4 := pow_le_pow_leftβ (Nat.cast_nonneg (Ξ± := β) (sparsifyNu n)) hnu 4
have heq : (2 * Real.logb 2 (Real.logb 2 n)) ^ 4 =
16 * Real.log (Real.logb 2 n) ^ 4 / Real.log (2 : β) ^ 4 := by
unfold Real.logb
ring_nf
rw [heq] at hnu4
have hmul : 16 * ((a : β) + 1) ^ 2 * Real.log (Real.logb 2 n) ^ 4 β€
Real.log (2 : β) ^ 4 * Real.logb 2 n := by
have := (le_div_iffβ (by positivity :
0 < 16 * ((a : β) + 1) ^ 2)).mp
(show Real.log (Real.logb 2 n) ^ 4 β€
(Real.log (2 : β) ^ 4 * Real.logb 2 n) /
(16 * ((a : β) + 1) ^ 2) by convert hb' using 1; ring_nf)
nlinarith
have ha : (a : β) ^ 2 * (sparsifyNu n : β) ^ 4 β€ Real.logb 2 n := by
apply (mul_le_mul_iff_rightβ (pow_pos hc 4)).mp
have hp := mul_le_mul_of_nonneg_left
((le_div_iffβ (pow_pos hc 4)).mp hnu4) (sq_nonneg (a : β))
have haa : (a : β) ^ 2 β€ ((a : β) + 1) ^ 2 := by
nlinarith [Nat.cast_nonneg (Ξ± := β) a]
nlinarith [mul_le_mul_of_nonneg_right haa
(pow_nonneg hlog0 4)]
apply (le_sparsifySchedule_iff hn a).2
exact_mod_cast ha.trans (sparsifyLambda_bounds hn).1
theorem rho_nonneg (n : β) : 0 β€ rho n := by
unfold rho
positivity
theorem runtimeScale_le_four_rho {n : β} (hn : 20 β€ n) :
SqrtLog.Statement.runtimeScale n β€ 4 * rho n := by
let c : β := Real.log 2
let l : β := Real.logb 2 n
let v : β := Real.logb 2 l
let y : β := Real.log ((n : β) + 16)
have hc : 0 < c := Real.log_pos (by norm_num)
have hc1 : c β€ 1 := by
simpa [c] using (Real.log_le_sub_one_of_pos (by norm_num : (0 : β) < 2) |>.trans (by norm_num))
have hl : 4 β€ l := four_le_logb hn
have hl0 : 0 < l := by linarith
have hv : 2 β€ v := by
apply (Real.le_logb_iff_rpow_le (by norm_num : (1 : β) < 2) hl0).mpr
norm_num
exact hl
have hn0 : (0 : β) < n := by exact_mod_cast (show 0 < n by omega)
have hn16 : (16 : β) β€ n := by exact_mod_cast (show 16 β€ n by omega)
have hcl : c * l = Real.log n := by dsimp [c, l, Real.logb]; field_simp
have hcv : c * v = Real.log l := by dsimp [c, v, Real.logb]; field_simp
have hyl : c * l β€ y := by
rw [hcl]
exact Real.log_le_log hn0 (by linarith)
have hyu : y β€ 2 * l := by
have hm : y β€ Real.log ((2 : β) * n) :=
Real.log_le_log (by positivity) (by nlinarith)
rw [Real.log_mul (by norm_num : (2 : β) β 0) hn0.ne', β hcl] at hm
change y β€ c + c * l at hm
nlinarith
have hlogy : Real.log y β€ 2 * c * v := by
have h : Real.log y β€ Real.log (2 * l) :=
Real.log_le_log (SqrtLog.Statement.log_shift_pos n) hyu
rw [Real.log_mul (by norm_num : (2 : β) β 0) hl0.ne', β hcv] at h
change Real.log y β€ c + c * v at h
nlinarith
have hlogy0 : 0 β€ Real.log y := (SqrtLog.Statement.log_log_shift_pos n).le
have hroot : c * Real.sqrt l β€ Real.sqrt y := by
apply (Real.le_sqrt (by positivity) (SqrtLog.Statement.log_shift_pos n).le).2
rw [mul_pow, Real.sq_sqrt hl0.le]
have hcc : c ^ 2 β€ c := by nlinarith
exact (mul_le_mul_of_nonneg_right hcc hl0.le).trans hyl
have hden : 0 < c * Real.sqrt l := mul_pos hc (Real.sqrt_pos.2 hl0)
have hsq : Real.log y ^ 2 β€ (2 * c * v) ^ 2 :=
pow_le_pow_leftβ hlogy0 hlogy 2
change (n : β) * Real.log y ^ 2 / Real.sqrt y β€
4 * ((n : β) * v ^ 2 / Real.sqrt l)
calc
(n : β) * Real.log y ^ 2 / Real.sqrt y β€
(n : β) * (2 * c * v) ^ 2 / (c * Real.sqrt l) := by gcongr
_ = 4 * c * ((n : β) * v ^ 2 / Real.sqrt l) := by
field_simp
ring_nf
_ β€ 4 * ((n : β) * v ^ 2 / Real.sqrt l) :=
mul_le_mul_of_nonneg_right (by nlinarith : 4 * c β€ 4) (by positivity)
theorem rho_le_thirtyTwo_runtimeScale {n : β} (hn : 20 β€ n) :
rho n β€ 32 * SqrtLog.Statement.runtimeScale n := by
let c : β := Real.log 2
let l : β := Real.logb 2 n
let v : β := Real.logb 2 l
let y : β := Real.log ((n : β) + 16)
have hc : 0 < c := Real.log_pos (by norm_num)
have hc1 : c β€ 1 := by
simpa [c] using (Real.log_le_sub_one_of_pos (by norm_num : (0 : β) < 2)
|>.trans (by norm_num))
have hc2 : (1 : β) / 2 β€ c := by
have := Real.one_sub_inv_le_log_of_pos (by norm_num : (0 : β) < 2)
norm_num at this
dsimp [c]
linarith
have hl : 4 β€ l := four_le_logb hn
have hl0 : 0 < l := by linarith
have hy0 : 0 < y := SqrtLog.Statement.log_shift_pos n
have hy2 : 2 β€ y := SqrtLog.Statement.two_le_log_shift n
have hn0 : (0 : β) < n := by exact_mod_cast (show 0 < n by omega)
have hn16 : (16 : β) β€ n := by exact_mod_cast (show 16 β€ n by omega)
have hcl : c * l = Real.log n := by dsimp [c, l, Real.logb]; field_simp
have hcv : c * v = Real.log l := by dsimp [c, v, Real.logb]; field_simp
have hyl : c * l β€ y := by
rw [hcl]
exact Real.log_le_log hn0 (by linarith)
have hly : l β€ 2 * y := by nlinarith
have hyu : y β€ 2 * l := by
have hm : y β€ Real.log ((2 : β) * n) :=
Real.log_le_log (by positivity) (by nlinarith)
rw [Real.log_mul (by norm_num : (2 : β) β 0) hn0.ne', β hcl] at hm
change y β€ c + c * l at hm
nlinarith
have hlogyc : c β€ Real.log y := Real.log_le_log (by norm_num) hy2
have hlogy0 : 0 β€ Real.log y := (SqrtLog.Statement.log_log_shift_pos n).le
have hv : 0 β€ v := Real.logb_nonneg (by norm_num) (by linarith)
have hvu : v β€ 4 * Real.log y := by
have h : Real.log l β€ Real.log (2 * y) := Real.log_le_log hl0 hly
rw [Real.log_mul (by norm_num : (2 : β) β 0) hy0.ne', β hcv] at h
change c * v β€ c + Real.log y at h
nlinarith
have hroot : Real.sqrt y β€ 2 * Real.sqrt l := by
apply Real.sqrt_le_iff.2
refine β¨by positivity, ?_β©
rw [mul_pow, Real.sq_sqrt hl0.le]
nlinarith
have hvsq : v ^ 2 β€ 16 * Real.log y ^ 2 := by nlinarith
change (n : β) * v ^ 2 / Real.sqrt l β€
32 * ((n : β) * Real.log y ^ 2 / Real.sqrt y)
rw [show 32 * ((n : β) * Real.log y ^ 2 / Real.sqrt y) =
(32 * (n : β) * Real.log y ^ 2) / Real.sqrt y by ring_nf]
apply (div_le_div_iffβ (Real.sqrt_pos.2 hl0) (Real.sqrt_pos.2 hy0)).2
calc
(n : β) * v ^ 2 * Real.sqrt y β€
(n : β) * (16 * Real.log y ^ 2) * (2 * Real.sqrt l) := by gcongr
_ = _ := by ring_nf
theorem inverse_sparsifySchedule_target {n : β} (hn : 20 β€ n)
(hs : 1 β€ sparsifySchedule n) :
(n : β) / sparsifySchedule n β€ 256 * SqrtLog.Statement.runtimeScale n := by
have := inverse_sparsifySchedule_le hn hs
have := rho_le_thirtyTwo_runtimeScale hn
linarith
end OAI.Algorithms.SubexponentialSAT.SqrtLogSpace
|