File size: 3,492 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
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