math / data /lean /OAI /Algorithms /SubexponentialSAT /Subexp /BlockSearchExecution.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
3.49 kB
import OAI.Algorithms.SubexponentialSAT.LeanCompat
import OAI.Algorithms.SubexponentialSAT.Subexp.BlockSearchSetup
import OAI.Algorithms.SubexponentialSAT.Subexp.BlockSearchCoverage
namespace OAI.Algorithms
/-! Preparation and exhaustive search in one fixed instruction table. -/
namespace SubexponentialSAT.Subexp.BlockSearchExecution
open BitProgram StructuredCalls BlockSearch BlockSearchEncoding BlockSearchPredicate
open SubexpTupleRefinement BlockSearchLoop
abbrev command (matrixPair : Cmd 24 42) : Cmd 24 42 :=
.seq BlockSearchSetup.command (.call (BlockSearchLoop.program matrixPair))
abbrev program (matrixPair : Cmd 24 42) := compiled (command matrixPair) 0 41
def inputState {K : Type*} (ctx : Context) (code : StackEncoding.BlockCode K)
(alphabet : List K) (N : β„•) (regs : Fin 24 β†’ Bool) : StructuredProgram.State 24 42 :=
BlockSearchSetup.inputState ctx (alphabet.map code.block)
(List.replicate (N * N) true) (List.replicate N true) regs
def searchBound (q N width bound : β„•) : β„• :=
q ^ (N * N) * ((N + 1) * (q ^ N * (24 * (N * width) + bound + 27) +
35 * N + 62) + 15 * (N * N * width) + 41) + 9
def cost {K : Type*} (code : StackEncoding.BlockCode K) (alphabet : List K)
(N bound : β„•) : β„• :=
BlockSearchPreparation.cost (alphabet.map code.block)
(List.replicate (N * N) true) (List.replicate N true) +
searchBound alphabet.length N code.width bound + 1
theorem program_runsIn {K : Type*} [Field K] [DecidableEq K]
(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 : β„•)
(hdimension : ctx.dimension = List.replicate N true)
(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) (BlockSearchCoverage.ValidCoefficient code N))
(regs : Fin 24 β†’ Bool) :
βˆƒ (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) (cost code alphabet N bound)
((inputState ctx code alphabet N regs).withPC (some (program matrixPair).entry))
(next.withPC none) := by
obtain ⟨np, prepared, hnp, hp, h0, h2, hep⟩ := BlockSearchSetup.command_eval ctx
(alphabet.map code.block) (List.replicate (N * N) true) (List.replicate N true)
regs (N * N * code.width) (by simpa using hdimension)
simp only [List.length_replicate] at hp h0
obtain ⟨next, C, d, hgood, htable, hsplit, ns, hns, hes⟩ :=
BlockSearchCoverage.program_runsIn matrixPair ctx code alphabet hfull M bound contract
prepared hp h0 h2
refine ⟨next, C, d, hgood, htable, hsplit, np + ns + 1, ?_, ?_⟩
Β· change np + ns + 1 ≀
BlockSearchPreparation.cost (alphabet.map code.block)
(List.replicate (N * N) true) (List.replicate N true) +
searchBound alphabet.length N code.width bound + 1
change ns ≀ searchBound alphabet.length N code.width bound at hns
omega
Β· exact compiled_halt_trace
(hep.seq (Eval.call (BlockSearchLoop.program matrixPair) hes)) 0 41
end SubexponentialSAT.Subexp.BlockSearchExecution
end OAI.Algorithms