File size: 9,303 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 | import OAI.Algorithms.SubexponentialSAT.LeanCompat
import OAI.Algorithms.SubexponentialSAT.Subexp.BlockSearchPredicate
import OAI.Algorithms.SubexponentialSAT.Subexp.BlockSearchOuter
import OAI.Algorithms.SubexponentialSAT.Subexp.BlockSearchCost
namespace OAI.Algorithms
/-! Coverage and algebraic soundness of the actual generated search lists. -/
namespace SubexponentialSAT.Subexp.BlockSearchCoverage
open BitProgram StructuredCalls BlockSearch BlockSearchEncoding BlockSearchPredicate
open SubexpTupleRefinement BlockSearchLoop BlockSearchOuter
variable {K : Type*} [Field K] [DecidableEq K]
def tables (code : StackEncoding.BlockCode K) (alphabet : List K) (N : β) :=
TupleProgram.powerRows (alphabet.map code.block) (N * N) [[]]
def coefficients (code : StackEncoding.BlockCode K) (alphabet : List K) (N : β) :=
TupleProgram.powerRows (alphabet.map code.block) N [[]]
def dimensions (N : β) := DimensionProgram.dimensionRows 0 N
def ValidTable (code : StackEncoding.BlockCode K) (N : β) (bits : List Bool) : Prop :=
β C : Fin N β Fin N β K, bits = encodeTuple code (flattenTable C)
def ValidCoefficient (code : StackEncoding.BlockCode K) (N : β) (bits : List Bool) : Prop :=
β x : Fin N β K, bits = encodeTuple code x
def ValidSplit (N : β) (bits : List Bool) : Prop :=
β d : Fin (N + 1), bits = splitCode d
omit [Field K] [DecidableEq K] in
theorem valid_table (code : StackEncoding.BlockCode K) (alphabet : List K) (N : β)
(bits : List Bool) (h : bits β tables code alphabet N) : ValidTable code N bits := by
obtain β¨x, hx, heβ© := (mem_powerRows_encoded code alphabet (N * N) bits).mp h
exact β¨unflattenTable x, by simpa using he.symmβ©
omit [Field K] [DecidableEq K] in
theorem valid_coefficient (code : StackEncoding.BlockCode K) (alphabet : List K) (N : β)
(bits : List Bool) (h : bits β coefficients code alphabet N) : ValidCoefficient code N bits := by
obtain β¨x, hx, heβ© := (mem_powerRows_encoded code alphabet N bits).mp h
exact β¨x, he.symmβ©
theorem dimension_payload (k n : β) (bits : List Bool)
(h : bits β DimensionProgram.dimensionRows k n) :
β d, k β€ d β§ d β€ k + n β§ bits = List.replicate d true := by
induction n generalizing k bits with
| zero =>
have he : bits = List.replicate k true := by simpa [DimensionProgram.dimensionRows] using h
exact β¨k, le_rfl, by omega, heβ©
| succ n ih =>
simp only [DimensionProgram.dimensionRows, List.mem_append, List.mem_singleton] at h
rcases h with h | h
Β· obtain β¨d, hl, hu, heβ© := ih (k + 1) bits h
exact β¨d, by omega, by omega, heβ©
Β· exact β¨k, le_rfl, by omega, hβ©
theorem valid_split (N : β) (bits : List Bool) (h : bits β dimensions N) :
ValidSplit N bits := by
obtain β¨d, hl, hu, heβ© := dimension_payload 0 N bits h
exact β¨β¨d, by omegaβ©, heβ©
theorem valid_split_reverse (N : β) (bits : List Bool) (h : ValidSplit N bits) :
bits.reverse = bits := by
obtain β¨d, rflβ© := h
simp [splitCode]
theorem valid_split_length (N : β) (bits : List Bool) (h : ValidSplit N bits) :
bits.length β€ N := by
obtain β¨d, rflβ© := h
simp only [splitCode, List.length_replicate]
have := d.isLt
omega
omit [Field K] [DecidableEq K] in
theorem valid_table_length (code : StackEncoding.BlockCode K) (N : β)
(bits : List Bool) (h : ValidTable code N bits) : bits.length = N * N * code.width := by
obtain β¨C, rflβ© := h
simp [encodeTuple, StackEncoding.length_encodeDataStack]
omit [Field K] [DecidableEq K] in
theorem valid_coefficient_length (code : StackEncoding.BlockCode K) (N : β)
(bits : List Bool) (h : ValidCoefficient code N bits) : bits.length = N * code.width := by
obtain β¨x, rflβ© := h
simp [encodeTuple, StackEncoding.length_encodeDataStack]
omit [Field K] [DecidableEq K] in
theorem coefficients_eq (code : StackEncoding.BlockCode K) (alphabet : List K) {N : β}
(d : Fin (N + 1)) (C : Fin N β Fin N β K) :
BlockSearchProgram.coefficientRecords code alphabet (splitPair d C) =
coefficients code alphabet N := by
simp only [BlockSearchProgram.coefficientRecords, splitPair_dimensions_add, coefficients]
theorem generated_success (code : StackEncoding.BlockCode K) (alphabet : List K)
(hfull : β x, x β alphabet) {m N : β} (M : Fin m β Fin N β K) :
(tables code alphabet N).any
(tableTest (coefficients code alphabet N) (dimensions N) (encodedTest code alphabet M)) = true := by
obtain β¨d, C, ht, hd, hpβ© := exists_encoded_success code alphabet hfull M
apply List.any_eq_true.mpr
refine β¨encodeTuple code (flattenTable C), ht, ?_β©
apply List.any_eq_true.mpr
exact β¨splitCode d, hd, by simpa only [coefficients_eq] using hpβ©
theorem selected_good (code : StackEncoding.BlockCode K) (alphabet : List K)
(hfull : β x, x β alphabet) {m N : β} (M : Fin m β Fin N β K)
(table split : List Bool) (ht : table β tables code alphabet N)
(hd : split β dimensions N)
(hgood : (coefficients code alphabet N).all (encodedTest code alphabet M table split) = true) :
β (C : Fin N β Fin N β K) (d : Fin (N + 1)), GoodPair M (splitPair d C) β§
table = encodeTuple code (flattenTable C) β§ split = splitCode d := by
obtain β¨C, rflβ© := valid_table code alphabet N table ht
obtain β¨d, rflβ© := valid_split N split hd
refine β¨C, d, ?_, rfl, rflβ©
apply (all_encoded_iff_goodPair code alphabet hfull M d C).mp
simpa only [coefficients_eq] using hgood
omit [Field K] [DecidableEq K] in
theorem list_lengths (code : StackEncoding.BlockCode K) (alphabet : List K) (N : β) :
(tables code alphabet N).length = alphabet.length ^ (N * N) β§
(coefficients code alphabet N).length = alphabet.length ^ N β§
(dimensions N).length = N + 1 := by
simp [tables, coefficients, dimensions, TupleProgram.powerRows_length,
DimensionProgram.dimensionRows_length]
/-- The checked nested loop returns an actual basis/complement encoding once
its concrete arithmetic callback meets the execution contract. -/
theorem program_runsIn (matrixPair : Cmd 24 42) (ctx : Context)
(code : StackEncoding.BlockCode K) (alphabet : List K) (hfull : β x, x β alphabet)
{m N : β} (M : Fin m β Fin N β K) (bound : β)
(contract : β (C : Fin N β Fin N β K) (d : Fin (N + 1)),
CoefficientContract matrixPair ctx (encodeTuple code (flattenTable C)) (splitCode d)
(encodedTest code alphabet M (encodeTuple code (flattenTable C)) (splitCode d))
(fun _ => bound) (ValidCoefficient code N))
(base : StructuredProgram.State 24 42)
(hb : TableEntry ctx (coefficients code alphabet N) (dimensions N) N (N * N * code.width) base)
(h0 : base.stacks 0 = ProgramEncoding.encodeRecords (tables code alphabet N))
(h2 : base.stacks 2 = []) :
β (next : StructuredProgram.State 24 42) (C : Fin N β Fin N β K) (d : Fin (N + 1)),
GoodPair M (splitPair d C) β§ next.stacks 41 = encodeTuple code (flattenTable C) β§
next.stacks 8 = splitCode d β§
RunsIn (program matrixPair)
(alphabet.length ^ (N * N) * ((N + 1) *
(alphabet.length ^ N * (24 * (N * code.width) + bound + 27) + 35 * N + 62) +
15 * (N * N * code.width) + 41) + 9)
(base.withPC (some (program matrixPair).entry)) (next.withPC none) := by
have hc : β table, ValidTable code N table β β split, ValidSplit N split β
CoefficientContract matrixPair ctx table split (encodedTest code alphabet M table split)
(fun _ => bound) (ValidCoefficient code N) := by
rintro table β¨C, rflβ© split β¨d, rflβ©
exact contract C d
obtain β¨n, next, hn, hselected, hempty, hfound, hevalβ© :=
BlockSearchOuter.command_eval matrixPair ctx (coefficients code alphabet N) (dimensions N)
(tables code alphabet N) N (N * N * code.width) (encodedTest code alphabet M)
(fun _ _ _ => bound) (ValidTable code N) (ValidSplit N) (ValidCoefficient code N)
(fun bits h => (valid_table_length code N bits h).le)
(valid_split_reverse N) (valid_split_length N)
(valid_coefficient code alphabet N) (valid_split N) (valid_table code alphabet N)
hc (generated_success code alphabet hfull M) base hb h0 h2
obtain β¨table, ht, split, hd, hgood, hout, hsplitβ© := hselected
obtain β¨C, d, hpair, heC, hedβ© := selected_good code alphabet hfull M table split ht hd hgood
refine β¨next, C, d, hpair, hout.trans heC, hsplit.trans hed, n + 1, ?_,
StructuredCalls.compiled_halt_trace heval 0 41β©
have hcap := BlockSearchCost.searchCost_le N (N * N * code.width) (N * code.width) bound
(fun _ _ _ => bound) (coefficients code alphabet N) (dimensions N) (tables code alphabet N)
(fun bits h => (valid_table_length code N bits (valid_table code alphabet N bits h)).le)
(fun bits h => valid_split_length N bits (valid_split N bits h))
(fun bits h => (valid_coefficient_length code N bits (valid_coefficient code alphabet N bits h)).le)
(fun _ _ _ _ _ _ => le_rfl)
rcases list_lengths code alphabet N with β¨htlen, hclen, hdlenβ©
rw [htlen, hclen, hdlen] at hcap
omega
end SubexponentialSAT.Subexp.BlockSearchCoverage
end OAI.Algorithms
|