Phase 4a: Amortized Failure-Link Transition Step (stepCode) #
Verifies stepCode (Algorithm 1 of [AhoCorasick1975]): follows failure links using the
failure-depth potential depth[u] (Theorem 2) to compute the next automaton state in amortized
constant time (17 * (depth[u] - depth[u']) + 20 instructions, independent of σ).
Main results #
Cslib.Algorithms.WordRAM.AhoCorasick.exec_stepCode: execution and amortized potential proof for one character transition ofscanCode.
Phase 4: Amortized text scanning (scanCode) #
theorem Cslib.Algorithms.WordRAM.AhoCorasick.exec_stepCode (inp : Input) (w : ℕ) (hvalid : inp.Valid) (hw : WordRAM.Fits w inp.wordBound) (x : WordRAM.Data 26) (hL : LayoutInv inp x) (hM : BFSMem inp inp.trie inp.bfs x.mem) (hu_lt : x.regs Reg.rState < inp.trie.numStates) (ha_lt : x.regs Reg.r5 < inp.alphabetSize) :
∃ (y : WordRAM.Data 26),
∃ u' < inp.trie.numStates,
WordRAM.ExecWithin w stepCode x y (13 * (inp.trie.depth (x.regs Reg.rState) + 1 - inp.trie.depth u') + 15) ∧ LayoutInv inp y ∧ y.mem = x.mem ∧ y.regs Reg.rState = u' ∧ inp.trie.strOf u' = Lean.AhoCorasick.nextMove inp.patterns (inp.trie.strOf (x.regs Reg.rState)) (x.regs Reg.r5) ∧ inp.trie.depth u' ≤ inp.trie.depth (x.regs Reg.rState) + 1 ∧ y.regs Reg.r1 = x.regs Reg.r1 ∧ y.regs Reg.r2 = x.regs Reg.r2 ∧ y.regs Reg.r3 = x.regs Reg.r3 ∧ y.regs Reg.r5 = x.regs Reg.r5