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