Correctness of the Pure Breadth-First Aho–Corasick Automaton #
Proves that PBFS.build (PTrie.build P) σ satisfies AutomatonInv: fail, deterministic
next-move table delta, and linked output chains (outHead, outNext) agree with the reference
Aho–Corasick failure/output specification from Cslib.Algorithms.Lean.AhoCorasick.
Main definitions #
Cslib.Algorithms.WordRAM.AhoCorasick.BFSInv,InnerLoopInv: outer and inner BFS loop invariants.Cslib.Algorithms.WordRAM.AhoCorasick.AutomatonInv: completed automaton invariant relatingdelta,fail,outHead,outNext, andfollowOuttofailureandout.
Main results #
Cslib.Algorithms.WordRAM.AhoCorasick.innerStep_spec,Cslib.Algorithms.WordRAM.AhoCorasick.outerStep_spec: inner and outer BFS induction steps.Cslib.Algorithms.WordRAM.AhoCorasick.rootLoopInv_init,Cslib.Algorithms.WordRAM.AhoCorasick.bfsInv_rootLoop: transition from depth-1 pass toBFSInv.Cslib.Algorithms.WordRAM.AhoCorasick.build_bfs_spec: end-to-end purity certificate.
theorem Cslib.Algorithms.WordRAM.AhoCorasick.innerStep_spec {P : List (List ℕ)} {σ : ℕ} {T : PTrie} (hT : TreeInv σ T) (hchar : ∀ u < T.numStates, ∀ a < σ, Lean.AhoCorasick.IsNode P (T.strOf u ++ [a]) ↔ 0 < T.trie u a) (hterm : ∀ u < T.numStates, T.isTerm u = if T.strOf u ≠ [] ∧ T.strOf u ∈ P then 1 else 0) {qHead₀ r fr a : ℕ} (ha : a < σ) {B : PBFS} (hinv : InnerLoopInv P σ T qHead₀ r fr a B) :
theorem Cslib.Algorithms.WordRAM.AhoCorasick.outerStep_spec {P : List (List ℕ)} {σ : ℕ} {T : PTrie} (hT : TreeInv σ T) (hchar : ∀ u < T.numStates, ∀ a < σ, Lean.AhoCorasick.IsNode P (T.strOf u ++ [a]) ↔ 0 < T.trie u a) (hterm : ∀ u < T.numStates, T.isTerm u = if T.strOf u ≠ [] ∧ T.strOf u ∈ P then 1 else 0) {B : PBFS} (hinv : BFSInv P σ T B) (hlt : B.qHead < B.qTail) :
theorem Cslib.Algorithms.WordRAM.AhoCorasick.rootLoopInv_init {P : List (List ℕ)} {σ : ℕ} {T : PTrie} (hT : TreeInv σ T) :
RootLoopInv P σ T 0 PBFS.init
theorem Cslib.Algorithms.WordRAM.AhoCorasick.bfsInv_rootLoop {P : List (List ℕ)} {σ : ℕ} {T : PTrie} (hT : TreeInv σ T) (hchar : ∀ u < T.numStates, ∀ a < σ, Lean.AhoCorasick.IsNode P (T.strOf u ++ [a]) ↔ 0 < T.trie u a) (hterm : ∀ u < T.numStates, T.isTerm u = if T.strOf u ≠ [] ∧ T.strOf u ∈ P then 1 else 0) :