File size: 6,577 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
import OAI.Algorithms.SubexponentialSAT.LeanCompat
import OAI.Algorithms.SubexponentialSAT.Subexp.BlockSearchOuter

namespace OAI.Algorithms

/-! Quantitative bounds for the actual universal-block search loops. -/

namespace SubexponentialSAT.Subexp.BlockSearchCost

open BlockSearchNested BlockSearchOuter

theorem sum_lengths_le (records : List (List Bool)) (width : β„•)
    (hw : βˆ€ bits ∈ records, bits.length ≀ width) :
    (records.map List.length).sum ≀ records.length * width := by
  induction records with
  | nil => simp
  | cons bits records ih =>
      have hb := hw bits (by simp)
      have ht := ih (fun b h => hw b (by simp [h]))
      simp only [List.map_cons, List.sum_cons, List.length_cons]
      nlinarith

theorem encoded_length_le (records : List (List Bool)) (width : β„•)
    (hw : βˆ€ bits ∈ records, bits.length ≀ width) :
    (ProgramEncoding.encodeRecords records).length ≀ records.length * (2 * width + 2) + 1 := by
  rw [ProgramEncoding.encodeRecords_length]
  have h := sum_lengths_le records width hw
  nlinarith

theorem budget_le (cost : List Bool β†’ β„•) (records : List (List Bool)) (width bound : β„•)
    (hw : βˆ€ bits ∈ records, bits.length ≀ width)
    (hc : βˆ€ bits ∈ records, cost bits ≀ bound) :
    RecordPrograms.budget cost records ≀ records.length * (6 * width + bound + 7) := by
  induction records with
  | nil => simp [RecordPrograms.budget]
  | cons bits records ih =>
      have hb := hw bits (by simp)
      have hcb := hc bits (by simp)
      have ht := ih (fun b h => hw b (by simp [h])) (fun b h => hc b (by simp [h]))
      simp only [RecordPrograms.budget, List.length_cons]
      nlinarith

theorem coefficientScanCost_le (cost : List Bool β†’ β„•) (records : List (List Bool))
    (width bound : β„•) (hw : βˆ€ bits ∈ records, bits.length ≀ width)
    (hc : βˆ€ bits ∈ records, cost bits ≀ bound) :
    coefficientScanCost cost records ≀ records.length * (24 * width + bound + 27) + 23 := by
  have he := encoded_length_le records width hw
  have hb := budget_le (fun bits => cost bits + 2) records width (bound + 2)
    hw (fun bits h => Nat.add_le_add_right (hc bits h) 2)
  unfold coefficientScanCost
  calc
    _ ≀ 9 * (records.length * (2 * width + 2) + 1) +
        records.length * (6 * width + (bound + 2) + 7) + 14 := by omega
    _ = _ := by ring

theorem dimensionCost_le (limit width bound : β„•) (cost : List Bool β†’ β„•)
    (records : List (List Bool)) (split : List Bool)
    (hs : split.length ≀ limit) (hw : βˆ€ bits ∈ records, bits.length ≀ width)
    (hc : βˆ€ bits ∈ records, cost bits ≀ bound) :
    dimensionCost limit cost records split ≀
      records.length * (24 * width + bound + 27) + 11 * limit + 37 := by
  have h := coefficientScanCost_le cost records width bound hw hc
  unfold dimensionCost
  omega

theorem dimensionScanCost_le (limit width bound : β„•)
    (cost : List Bool β†’ List Bool β†’ β„•) (coefficients dimensions : List (List Bool))
    (hd : βˆ€ split ∈ dimensions, split.length ≀ limit)
    (hw : βˆ€ bits ∈ coefficients, bits.length ≀ width)
    (hc : βˆ€ split ∈ dimensions, βˆ€ bits ∈ coefficients, cost split bits ≀ bound) :
    dimensionScanCost limit cost coefficients dimensions ≀
      dimensions.length *
        (coefficients.length * (24 * width + bound + 27) + 35 * limit + 62) + 21 := by
  have he := encoded_length_le dimensions limit hd
  have hb := budget_le (fun split => dimensionCost limit (cost split) coefficients split)
    dimensions limit (coefficients.length * (24 * width + bound + 27) + 11 * limit + 37)
    hd (fun split h => dimensionCost_le limit width bound (cost split) coefficients split
      (hd split h) hw (hc split h))
  unfold dimensionScanCost
  calc
    _ ≀ 9 * (dimensions.length * (2 * limit + 2) + 1) +
        dimensions.length * (6 * limit +
          (coefficients.length * (24 * width + bound + 27) + 11 * limit + 37) + 7) + 12 := by
      omega
    _ = _ := by ring

theorem tableCost_le (limit tableWidth coefficientWidth bound : β„•)
    (cost : List Bool β†’ List Bool β†’ β„•) (coefficients dimensions : List (List Bool))
    (table : List Bool) (ht : table.length ≀ tableWidth)
    (hd : βˆ€ split ∈ dimensions, split.length ≀ limit)
    (hw : βˆ€ bits ∈ coefficients, bits.length ≀ coefficientWidth)
    (hc : βˆ€ split ∈ dimensions, βˆ€ bits ∈ coefficients, cost split bits ≀ bound) :
    tableCost tableWidth limit cost coefficients dimensions table ≀
      dimensions.length * (coefficients.length * (24 * coefficientWidth + bound + 27) +
        35 * limit + 62) + 5 * tableWidth + 30 := by
  have h := dimensionScanCost_le limit coefficientWidth bound cost coefficients dimensions hd hw hc
  unfold tableCost
  omega

/-- The three-loop instruction count is the number of tables times the
number of splits times the number of coefficients, times a local polynomial.
No ambient/global dimension occurs in this bound. -/
theorem searchCost_le (limit tableWidth coefficientWidth bound : β„•)
    (cost : List Bool β†’ List Bool β†’ List Bool β†’ β„•)
    (coefficients dimensions tables : List (List Bool))
    (ht : βˆ€ table ∈ tables, table.length ≀ tableWidth)
    (hd : βˆ€ split ∈ dimensions, split.length ≀ limit)
    (hw : βˆ€ bits ∈ coefficients, bits.length ≀ coefficientWidth)
    (hc : βˆ€ table ∈ tables, βˆ€ split ∈ dimensions, βˆ€ bits ∈ coefficients,
      cost table split bits ≀ bound) :
    searchCost limit tableWidth cost coefficients dimensions tables ≀
      tables.length * (dimensions.length *
        (coefficients.length * (24 * coefficientWidth + bound + 27) + 35 * limit + 62) +
        15 * tableWidth + 41) + 8 := by
  have he := encoded_length_le tables tableWidth ht
  have hb := budget_le
    (fun table => tableCost tableWidth limit (cost table) coefficients dimensions table)
    tables tableWidth
    (dimensions.length * (coefficients.length * (24 * coefficientWidth + bound + 27) +
      35 * limit + 62) + 5 * tableWidth + 30)
    ht (fun table h => tableCost_le limit tableWidth coefficientWidth bound (cost table)
      coefficients dimensions table (ht table h) hd hw (hc table h))
  unfold searchCost
  calc
    _ ≀ tables.length * (6 * tableWidth +
        (dimensions.length * (coefficients.length * (24 * coefficientWidth + bound + 27) +
          35 * limit + 62) + 5 * tableWidth + 30) + 7) +
        2 * (tables.length * (2 * tableWidth + 2) + 1) + 6 := by omega
    _ = _ := by ring

end SubexponentialSAT.Subexp.BlockSearchCost

end OAI.Algorithms