File size: 4,851 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 | import OAI.Algorithms.SubexponentialSAT.SqrtLogSpace.DisjointReuse.DFSVisit
import OAI.Algorithms.SubexponentialSAT.SqrtLogSpace.DisjointReuse.DFSCompletedTree
/-! Well-founded assembly of the actual fixed DFS while command.
The body obligation is the concrete visit theorem; no finite successful run,
termination oracle, derivation tree or precomputed visit list is assumed.
-/
namespace OAI.Algorithms.SubexponentialSAT.SqrtLogSpace.DisjointReuse.DFSLoop
open BitProgram StructuredCalls SparseDFSProgram SparseDFSRefinement DFSVisit
variable {n : ℕ}
/-- This intermediate invariant is instantiated by the concrete prepared frame
and the proved per-visit resource envelope, before the final endpoint. -/
theorem execute (k M : ℕ) (threshold : List Bool) (leaf : Code) (budget bound : ℕ)
(I : Frontier n → Data → Prop) (hM : 2 ≤ M)
(hboundary : ∀ s d, I s d → Boundary threshold s d)
(hspace : ∀ s d, I s d → ∀ i, (d.stacks i).length ≤ bound)
(hbody : ∀ (node : Node n) rest total d, I ⟨node :: rest, total⟩ d →
∃ next t, t ≤ budget ∧ ∃ e, BoundedEval (body k leaf) t d e bound ∧
Transition k M ⟨node :: rest, total⟩ next ∧ I next e)
(s : Frontier n) (d : Data) (hI : I s d) :
∃ visits t total e, t ≤ visits * (budget + 1) + 1 ∧
BoundedEval (loop k leaf) t d e bound ∧
Transitions k M visits s ⟨[], total⟩ ∧ I ⟨[], total⟩ e := by
generalize hm : DFSCompletedTree.potential s = measure
induction measure using Nat.strong_induction_on generalizing s d with
| h measure ih =>
rcases s with ⟨pending, total⟩
cases pending with
| nil =>
have hf : d.regs 2 = false := by
simpa using (hboundary ⟨[], total⟩ d hI).continue_flag
refine ⟨0, 1, total, d, by simp, ⟨.while_false hf, ?_⟩, .refl _, hI⟩
exact StructuredSpace.while_false_stack_bound (body k leaf) 2 d hf
(hspace ⟨[], total⟩ d hI) (compiled (loop k leaf) 256 256)
(siteAddress (loop k leaf)) (exitAddress (loop k leaf))
(compiled_site (loop k leaf) 256 256)
| cons node rest =>
obtain ⟨next, tb, htb, afterBody, hb, transition, hnext⟩ :=
hbody node rest total d hI
have hlt : DFSCompletedTree.potential next < measure :=
hm ▸ DFSCompletedTree.transition_potential_lt transition hM
obtain ⟨visits, t, result, final, ht, he, transitions, hfinal⟩ :=
ih _ hlt next afterBody hnext rfl
have hf : d.regs 2 = true := by
simpa using (hboundary ⟨node :: rest, total⟩ d hI).continue_flag
refine ⟨visits + 1, tb + t + 1, result, final, ?_,
⟨.while_true hf hb.eval he.eval, ?_⟩, .cons transition transitions, hfinal⟩
· simp only [Nat.add_mul, Nat.one_mul]
omega
· exact StructuredSpace.while_true_stack_bound hf hb.eval he.eval 256 256
hb.space he.space (compiled (loop k leaf) 256 256)
(siteAddress (loop k leaf)) (exitAddress (loop k leaf))
(compiled_site (loop k leaf) 256 256)
/-- The exact completed count and sharp node budget refer to the same
measured while execution, whose uniform prefix bound is independent of visits. -/
theorem execute_sharp (k : ℕ) (σ : ℚ) (hk : 2 ≤ k) (hσ : 0 < σ)
(threshold : List Bool) (leaf : Code) (budget bound : ℕ)
(I : Frontier n → Data → Prop)
(hboundary : ∀ s d, I s d → Boundary threshold s d)
(hspace : ∀ s d, I s d → ∀ i, (d.stacks i).length ≤ bound)
(hbody : ∀ (node : Node n) rest total d, I ⟨node :: rest, total⟩ d →
∃ next t, t ≤ budget ∧ ∃ e, BoundedEval (body k leaf) t d e bound ∧
Transition k (SparseBudget.chooseForSigma k σ hσ) ⟨node :: rest, total⟩ next ∧ I next e)
(F : RawCNF n) (d : Data) (hv : Valid k F) (hI : I ⟨[⟨F, 0⟩], 0⟩ d) :
∃ visits t e, t ≤ visits * (budget + 1) + 1 ∧
BoundedEval (loop k leaf) t d e bound ∧
Boundary (n := n) threshold ⟨[], rawCount F⟩ e ∧
(visits : ℝ) ≤
((SparseCharging.depthConstant k (SparseBudget.chooseForSigma k σ hσ) * n + 1 : ℕ) : ℝ) ^ 2 *
(2 : ℝ) ^ ((σ : ℝ) * n) := by
have hM := (SparseBudget.chooseM_spec k σ.num.natAbs σ.den
(SparseBudget.rational_data σ hσ).1).1
obtain ⟨visits, t, total, e, ht, he, transitions, hfinal⟩ :=
execute k (SparseBudget.chooseForSigma k σ hσ) threshold leaf budget bound I hM
hboundary hspace hbody ⟨[⟨F, 0⟩], 0⟩ d hI
have hcount := transitions.finished_count
refine ⟨visits, t, e, ht, he, ?_, ?_⟩
· simpa only [hcount] using hboundary ⟨[], total⟩ e hfinal
· exact DFSCompletedTree.completed_visits_bound k σ hk hσ hv transitions
end OAI.Algorithms.SubexponentialSAT.SqrtLogSpace.DisjointReuse.DFSLoop
|