File size: 7,829 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 | import OAI.Algorithms.SubexponentialSAT.LeanCompat
import OAI.Algorithms.SubexponentialSAT.Subexp.BlockSearchExecution
import OAI.Algorithms.SubexponentialSAT.Subexp.BlockSearchBounds
import OAI.Algorithms.SubexponentialSAT.Subexp.BlockCoefficientProgram
namespace OAI.Algorithms
/-! A fixed executable prime-field kernel-basis and complement search. -/
namespace SubexponentialSAT.Subexp.BlockSearchConcrete
open BitProgram StructuredCalls BlockSearch BlockSearchEncoding BlockSearchPredicate
open SubexpTupleRefinement
/-- This instruction table is independent of the prime and matrix dimensions. -/
def program := BlockSearchExecution.program BlockCoefficientProgram.matrixPair
def inputState (p : β) [Fact p.Prime] {m N : β}
(M : Fin m β Fin N β ZMod p) (regs : Fin 24 β Bool) : StructuredProgram.State 24 42 :=
BlockSearchExecution.inputState (BlockCoefficientProgram.context p M) (scalarCode p)
(QuarticSearch.elements p) N regs
def cost (p : β) [Fact p.Prime] (m N : β) : β :=
BlockSearchExecution.cost (scalarCode p) (QuarticSearch.elements p) N
(BlockCoefficientProgram.coefficientCost p m N)
/-- The complete instruction bound is exponential in a polynomial of the
local dimension and logarithmic field width, including tuple generation. -/
theorem cost_le (p : β) [Fact p.Prime] (m N : β) :
cost p m N β€
800 * (N * N + 1) * p ^ (N * N) *
((N * N + 1) * (2 * MatrixWordEncoding.width p + 1) + 1) +
800 * (N + 1) * p ^ N * ((N + 1) * (2 * MatrixWordEncoding.width p + 1) + 1) +
6 * N ^ 2 + 22 * N + 37 +
BlockSearchExecution.searchBound p N (2 * MatrixWordEncoding.width p + 1)
(BlockCoefficientProgram.coefficientCost p m N) := by
have hp := (show Nat.Prime p from Fact.out).two_le
have ha : 1 β€ (QuarticSearch.elements p).length := by
rw [QuarticSearch.length_elements]
omega
have h := BlockSearchBounds.cost_le (scalarCode p) (QuarticSearch.elements p) ha N
(BlockCoefficientProgram.coefficientCost p m N)
simpa only [cost, QuarticSearch.length_elements, scalarCode,
BlockSearchProgram.framedCode, MatrixWordEncoding.code] using h
theorem validCoefficient_eq (p : β) [Fact p.Prime] (N : β) :
BlockSearchCoverage.ValidCoefficient (scalarCode p) N =
BlockCoefficientProgram.validCoefficient p N := by
funext bits
apply propext
constructor
Β· rintro β¨x, hxβ©
refine β¨x, ?_β©
simpa only [encoded_vector_eq_words, BlockCoefficientProgram.vectorWords] using hx
Β· rintro β¨x, hxβ©
refine β¨x, ?_β©
simpa only [encoded_vector_eq_words, BlockCoefficientProgram.vectorWords] using hx
theorem tableBits_eq (p : β) [Fact p.Prime] {N : β}
(C : Fin N β Fin N β ZMod p) :
encodeTuple (scalarCode p) (flattenTable C) = BlockCoefficientProgram.tableBits p C := by
simpa only [BlockCoefficientProgram.tableBits, BlockCoefficientProgram.matrixBits,
BlockCoefficientProgram.matrixRows, BlockCoefficientProgram.vectorWords] using
encoded_table_eq_flatten_words p C
theorem coefficientContract_with_alphabet (p : β) [Fact p.Prime]
(alphabet : List (ZMod p)) (hfull : β x, x β alphabet) {m N : β}
(M : Fin m β Fin N β ZMod p) (C : Fin N β Fin N β ZMod p) (d : Fin (N + 1)) :
BlockSearchLoop.CoefficientContract BlockCoefficientProgram.matrixPair
(BlockCoefficientProgram.context p M) (encodeTuple (scalarCode p) (flattenTable C))
(splitCode d)
(encodedTest (scalarCode p) alphabet M
(encodeTuple (scalarCode p) (flattenTable C)) (splitCode d))
(fun _ => BlockCoefficientProgram.coefficientCost p m N)
(BlockSearchCoverage.ValidCoefficient (scalarCode p) N) := by
have hc := BlockCoefficientProgram.coefficientContract p M C d
(encodedTest (scalarCode p) alphabet M
(encodeTuple (scalarCode p) (flattenTable C)) (splitCode d)) (fun x => by
simpa only [test, BlockCoefficientProgram.vectorWords] using
test_on_words p alphabet hfull M d C x)
simpa only [β tableBits_eq p C, β validCoefficient_eq p N, splitCode] using hc
theorem coefficientContract (p : β) [Fact p.Prime] {m N : β}
(M : Fin m β Fin N β ZMod p) (C : Fin N β Fin N β ZMod p) (d : Fin (N + 1)) :
BlockSearchLoop.CoefficientContract BlockCoefficientProgram.matrixPair
(BlockCoefficientProgram.context p M) (encodeTuple (scalarCode p) (flattenTable C))
(splitCode d)
(encodedTest (scalarCode p) (QuarticSearch.elements p) M
(encodeTuple (scalarCode p) (flattenTable C)) (splitCode d))
(fun _ => BlockCoefficientProgram.coefficientCost p m N)
(BlockSearchCoverage.ValidCoefficient (scalarCode p) N) :=
coefficientContract_with_alphabet p (QuarticSearch.elements p)
(QuarticSearch.mem_elements p) M C d
/-- The executable search accepts any supplied complete scalar alphabet,
including the reversed order emitted by the scalar-alphabet formatter. -/
theorem program_runsIn_with_alphabet (p : β) [Fact p.Prime]
(alphabet : List (ZMod p)) (hfull : β x, x β alphabet) {m N : β}
(M : Fin m β Fin N β ZMod p) (regs : Fin 24 β Bool) :
β (next : StructuredProgram.State 24 42) (C : Fin N β Fin N β ZMod p) (d : Fin (N + 1)),
GoodPair M (splitPair d C) β§ next.stacks 41 = encodeTuple (scalarCode p) (flattenTable C) β§
next.stacks 8 = splitCode d β§
RunsIn program
(BlockSearchExecution.cost (scalarCode p) alphabet N
(BlockCoefficientProgram.coefficientCost p m N))
((BlockSearchExecution.inputState (BlockCoefficientProgram.context p M)
(scalarCode p) alphabet N regs).withPC (some program.entry)) (next.withPC none) :=
BlockSearchExecution.program_runsIn BlockCoefficientProgram.matrixPair
(BlockCoefficientProgram.context p M) (scalarCode p) alphabet hfull M
(BlockCoefficientProgram.coefficientCost p m N) rfl
(coefficientContract_with_alphabet p alphabet hfull M) regs
/-- All enumeration, arithmetic tests, and selection are executions of the
same fixed instruction table. The output supplies a certified kernel basis
and complement for the input matrix. -/
theorem program_runsIn (p : β) [Fact p.Prime] {m N : β}
(M : Fin m β Fin N β ZMod p) (regs : Fin 24 β Bool) :
β (next : StructuredProgram.State 24 42) (C : Fin N β Fin N β ZMod p) (d : Fin (N + 1)),
GoodPair M (splitPair d C) β§ next.stacks 41 = encodeTuple (scalarCode p) (flattenTable C) β§
next.stacks 8 = splitCode d β§
RunsIn program (cost p m N)
((inputState p M regs).withPC (some program.entry)) (next.withPC none) := by
exact BlockSearchExecution.program_runsIn BlockCoefficientProgram.matrixPair
(BlockCoefficientProgram.context p M) (scalarCode p) (QuarticSearch.elements p)
(QuarticSearch.mem_elements p) M (BlockCoefficientProgram.coefficientCost p m N)
rfl (coefficientContract p M) regs
theorem program_primitive_runsIn (p : β) [Fact p.Prime] {m N : β}
(M : Fin m β Fin N β ZMod p) (regs : Fin 24 β Bool) :
β (next : StructuredProgram.State 24 42) (C : Fin N β Fin N β ZMod p) (d : Fin (N + 1)),
GoodPair M (splitPair d C) β§ next.stacks 41 = encodeTuple (scalarCode p) (flattenTable C) β§
next.stacks 8 = splitCode d β§
Computation.RunsIn (BitProgram.primitive program).step
(BitProgram.primitiveOverhead program * cost p m N)
(BitProgram.primitiveCfg program ((inputState p M regs).withPC (some program.entry)))
(BitProgram.primitiveCfg program (next.withPC none)) := by
obtain β¨next, C, d, hgood, hC, hd, hrunβ© := program_runsIn p M regs
exact β¨next, C, d, hgood, hC, hd, BitProgram.primitive_execution program hrunβ©
end SubexponentialSAT.Subexp.BlockSearchConcrete
end OAI.Algorithms
|