File size: 4,848 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
import OAI.Algorithms.SubexponentialSAT.LeanCompat
import OAI.Algorithms.SubexponentialSAT.SqrtLog.AsymptoticLayoutBounds

namespace OAI.Algorithms

namespace SubexponentialSAT.SqrtLog.Asymptotic

open Filter
open scoped Topology

theorem eventually_w_sq_le_s : βˆ€αΆ  n : β„• in atTop, w n ^ 2 ≀ s n := by
  filter_upwards [eventually_w_power_le_L 8 (show (0 : ℝ) < 1 by norm_num)] with n hn
  apply (le_s_iff n (w n ^ 2)).2
  simp only [one_mul] at hn
  have hnat : w n ^ 8 ≀ L n := by exact_mod_cast hn
  convert hnat using 1 ; ring

theorem eventually_w_le_log_r :
    βˆ€αΆ  n : β„• in atTop, w n ≀ 7 * (Nat.log2 (layoutR n) + 1) := by
  filter_upwards [eventually_w_sq_le_s] with n hn
  have hr : s n ≀ layoutR n := le_max_right _ _
  have hr2 := layoutR_ge_two n
  have hw : w n ^ 2 ≀ layoutR n := hn.trans hr
  have hw4 : w n ^ 4 ≀ layoutR n ^ 2 := by
    have h := Nat.pow_le_pow_left hw 2
    convert h using 1 ; ring
  have hsp : s n + 1 ≀ 2 * layoutR n := by omega
  have hL : L n ≀ 4 * layoutR n ^ 4 := by
    calc
      L n ≀ (s n + 1) ^ 2 * w n ^ 4 := (schedule_maximal n).le
      _ ≀ (2 * layoutR n) ^ 2 * layoutR n ^ 2 := by gcongr
      _ = _ := by ring
  have hpow : L n ≀ 2 ^ (2 + 4 * (Nat.log2 (layoutR n) + 1)) := by
    calc
      L n ≀ 4 * layoutR n ^ 4 := hL
      _ ≀ 4 * (2 ^ (Nat.log2 (layoutR n) + 1)) ^ 4 := by
        exact Nat.mul_le_mul_left 4 (Nat.pow_le_pow_left Nat.lt_log2_self.le 4)
      _ = _ := by rw [← pow_mul]; norm_num [pow_add, Nat.mul_comm]
  have hlog := Nat.log_mono_right (b := 2) hpow
  rw [Nat.log_pow (by norm_num : 1 < (2 : β„•))] at hlog
  unfold w
  rw [Nat.log2_eq_log_two]
  nlinarith

theorem eventually_layoutCutoff_sq_le (b : β„• β†’ β„•) (q : β„•)
    (hb : βˆ€αΆ  n : β„• in atTop, b n ≀ L n ^ q) :
    βˆ€αΆ  n : β„• in atTop, layoutCutoff n (b n) ^ 2 ≀ (28 * q + 312) * L n := by
  filter_upwards [hb, eventually_w_le_log_r] with n hn hw
  have he := layoutEnergy_le n (b n) q hn
  have hbudget : 64 * (Nat.log2 (layoutR n) + 1) * layoutQ n ≀ L n :=
    Nat.mul_div_le (L n) (layoutDen n)
  have hQE : 64 * layoutQ n * layoutEnergy n (b n) ≀ 7 * (q + 10) * L n := by
    calc
      64 * layoutQ n * layoutEnergy n (b n) ≀ 64 * layoutQ n * ((q + 10) * w n) := by gcongr
      _ ≀ 64 * layoutQ n * ((q + 10) * (7 * (Nat.log2 (layoutR n) + 1))) := by gcongr
      _ = 7 * (q + 10) * (64 * (Nat.log2 (layoutR n) + 1) * layoutQ n) := by ring
      _ ≀ _ := Nat.mul_le_mul_left _ hbudget
  have hroot := Nat.sqrt_le' (128 * layoutQ n * layoutEnergy n (b n))
  have hL := L_pos n
  have hsmall (x : β„•) : (x + 4) ^ 2 ≀ 2 * x ^ 2 + 32 := by
    have hi : ((x : β„€) + 4) ^ 2 ≀ 2 * (x : β„€) ^ 2 + 32 := by
      nlinarith [sq_nonneg ((x : β„€) - 4)]
    exact_mod_cast hi
  unfold layoutCutoff
  calc
    _ ≀ 2 * Nat.sqrt (128 * layoutQ n * layoutEnergy n (b n)) ^ 2 + 32 := hsmall _
    _ ≀ 256 * layoutQ n * layoutEnergy n (b n) + 32 := by nlinarith
    _ ≀ (28 * q + 312) * L n := by nlinarith

theorem eventually_layoutQ_comparison :
    βˆ€αΆ  n : β„• in atTop,
      L n ≀ 128 * layoutQ n * w n ∧ 64 * layoutQ n * w n ≀ 7 * L n := by
  filter_upwards [eventually_layoutQ_ge 1, eventually_w_le_log_r] with n hQ hw
  have hb : 64 * (Nat.log2 (layoutR n) + 1) * layoutQ n ≀ L n :=
    Nat.mul_div_le (L n) (layoutDen n)
  have hd := layoutDen_le n
  have hdiv := Nat.div_add_mod (L n) (layoutDen n)
  have hmod := Nat.mod_lt (L n) (layoutDen_pos n)
  change layoutDen n * layoutQ n + L n % layoutDen n = L n at hdiv
  constructor
  Β· have hm := Nat.mul_le_mul_left (layoutQ n + 1) hd
    nlinarith
  Β· have hm := Nat.mul_le_mul_left (64 * layoutQ n) hw
    nlinarith

theorem eventually_L_ge (a : β„•) : βˆ€αΆ  n : β„• in atTop, a ≀ L n := by
  filter_upwards [eventually_le_s a] with n hn
  exact hn.trans (s_le_L n)

theorem eventually_absorb_L_coefficient (b : β„• β†’ β„•) (C q : β„•)
    (hb : βˆ€αΆ  n : β„• in atTop, b n ≀ C * L n ^ q) :
    βˆ€αΆ  n : β„• in atTop, b n ≀ L n ^ (q + 1) := by
  filter_upwards [hb, eventually_L_ge C] with n hn hC
  exact hn.trans (by simpa [pow_succ, mul_comm] using Nat.mul_le_mul_right (L n ^ q) hC)

theorem polynomial_schedule_has_L_power (b : β„• β†’ β„•)
    (hb : SparsificationConstants.PolynomialBound b) :
    βˆƒ q : β„•, βˆ€αΆ  n : β„• in atTop, b (s n) ≀ L n ^ q := by
  obtain ⟨q, hq⟩ := QuantitativeSparsify.polynomialBound_shift_power hb
  refine ⟨q + 1, eventually_absorb_L_coefficient (fun n => b (s n)) (3 ^ q) q ?_⟩
  apply Filter.Eventually.of_forall
  intro n
  have hs : s n + 2 ≀ 3 * L n := by have := s_le_L n; have := L_pos n; omega
  calc
    b (s n) ≀ (s n + 2) ^ q := hq (s n)
    _ ≀ (3 * L n) ^ q := Nat.pow_le_pow_left hs q
    _ = 3 ^ q * L n ^ q := mul_pow _ _ _

end SubexponentialSAT.SqrtLog.Asymptotic

end OAI.Algorithms