Phase 3a: BFSMem Invariant and Depth-1 Root Loop (exec_bfsRootLoop) #
Shared Word-RAM automaton invariant BFSMem together with its frame/update lemmas and the
depth-1 root-loop execution proof (exec_bfsRootLoop). Both Phase3Loop (bfsBuildCode) and
Phase4Step / Phase4Scan (scanCode) build directly on top of BFSMem in parallel.
Main definitions #
Cslib.Algorithms.WordRAM.AhoCorasick.Input.bfs: opaque pure BFS automatonPBFS.build.Cslib.Algorithms.WordRAM.AhoCorasick.BFSMem: memory invariant pairing the nine Word-RAM tables withPTrieandPBFS.
Main results #
Cslib.Algorithms.WordRAM.AhoCorasick.Input.bfs_spec:AutomatonInvforinp.bfs.Cslib.Algorithms.WordRAM.AhoCorasick.bfsMem_init,Cslib.Algorithms.WordRAM.AhoCorasick.bfsMem_of_eq_below_outBase,Cslib.Algorithms.WordRAM.AhoCorasick.bfsMem_of_set_delta,Cslib.Algorithms.WordRAM.AhoCorasick.bfsMem_of_enqueue: initialization and table updates.Cslib.Algorithms.WordRAM.AhoCorasick.exec_bfsRootLoop: depth-1 BFS root loop proof.
Pure BFS automaton built from inp.trie over alphabet [0, inp.alphabetSize).
Unfolding equation for opaque Input.bfs.
Completed AutomatonInv certificate for inp.bfs under inp.Valid.
theorem Cslib.Algorithms.WordRAM.AhoCorasick.bfsMem_of_eq_below_outBase {inp : Input} {T : PTrie} {B : PBFS} {mem mem' : ℕ → ℕ} (hM : BFSMem inp T B mem) (heq : ∀ a < inp.outBase, mem' a = mem a) :
BFSMem inp T B mem'
Transport a BFSMem invariant across writes that agree with mem on every address strictly
below inp.outBase. Shared by Phase 4 output writes.
theorem Cslib.Algorithms.WordRAM.AhoCorasick.bfsMem_of_enqueue {inp : Input} {T : PTrie} {B : PBFS} {mem : ℕ → ℕ} {u₀ a s fval onval ohval : ℕ} (hu₀ : u₀ < inp.maxS) (ha : a < inp.alphabetSize) (hs : s < inp.maxS) (hM : BFSMem inp T B mem) :
BFSMem inp T
{ delta := fun (u c : ℕ) => if u = u₀ ∧ c = a then s else B.delta u c, fail := Function.update B.fail s fval,
outHead := Function.update B.outHead s ohval, outNext := Function.update B.outNext s onval,
queue := Function.update B.queue B.qTail s, qHead := B.qHead, qTail := B.qTail + 1 }
(Function.update
(Function.update
(Function.update
(Function.update (Function.update mem (inp.deltaBase + (u₀ * inp.alphabetSize + a)) s) (inp.failBase + s) fval)
(inp.queueBase + B.qTail) s)
(inp.outNextBase + s) onval)
(inp.outHeadBase + s) ohval)
Combined five-write update preserving BFSMem when enqueuing child state s.
theorem Cslib.Algorithms.WordRAM.AhoCorasick.exec_bfsRootLoop (inp : Input) (w : ℕ) (hvalid : inp.Valid) (hw : WordRAM.Fits w inp.wordBound) (k a : ℕ) (B : PBFS) (x : WordRAM.Data 26) :
a + k = inp.alphabetSize →
LayoutInv inp x →
BFSMem inp inp.trie B x.mem →
RootLoopInv inp.patterns inp.alphabetSize inp.trie a B →
x.regs Reg.r1 = 0 →
x.regs Reg.r2 = B.qTail →
x.regs Reg.r5 = a →
∃ (y : WordRAM.Data 26),
WordRAM.ExecWithin w (WordRAM.Code.loop (WordRAM.Cond.lt Reg.r5 Reg.sigma) bfsRootStepCode) x y
(21 * k + 2) ∧ LayoutInv inp y ∧ BFSMem inp inp.trie (PBFS.rootLoop inp.trie k a B) y.mem ∧ y.regs Reg.r1 = 0 ∧ y.regs Reg.r2 = (PBFS.rootLoop inp.trie k a B).qTail