Correct output and charged space at every text prefix
ProvedExactPatternStream.MachineProof.counted_public_text_by_prefixexact-pattern-matchingstreaming-algorithmsword-ram
Let be the pattern and text, with lengths , , over an alphabet of size . The machine uses words of bits.
Suppose the machine begins text processing with the reset rows representing their learned meanings. An unchanged frontier preserves these meanings and each actually emitted child is evaluated by the placed packed-row routine. At every sufficiently large width and every , the prefix completes with
answers, each equal to the seeded packet-matcher bit for its window. At its output is the seeded answer list. The text scan keeps its initial coin cursor and every feed obeys the trained-arena and logarithmic space bounds.
Preamble
import Definitions.Def_ExactPatternStream_StreamingImplementation open ExactPatternStream open ExactPatternStream.MachineProof open DynBrooks ImplementationProof PackedRAM CounterProof SoundProof OnlineReport Dispatch
Formal statement
theorem ExactPatternStream.MachineProof.counted_public_text_by_prefix (k : ℕ) : ∃ W : ℕ,∀ cw,W≤ cw → ∃ K : ℕ,
∀ {σ : ℕ} (P T : List (Fin σ)) (seed : Seeds σ P.length) (a : ZMod (residualPrime T.length P.length σ).val)
(pre post : Program) (row : ℕ→Program),1≤ P.length → P.length≤ T.length → T.length≤2*P.length →
3≤ T.length → σ≤ T.length^k →
let w:=cw*ell T.length
let B:=seededBuild P T seed
let h:=topIndex B
let base:=promotionHeapBase w σ P.length
let arena:=trainedParentArena w σ P.length T.length B h
let counts:=trainedCounts B
let widths:=fun i=>(lvl B i).w
let entry:=(pre++textLeafInputCode).length
let Q:=countedTextProgram pre post row
let pat:=learnPattern seed a T.length (rawEvents P)
let initial:=bareInit pat.residual pat.symbol (triggerStart pat.count (decide (pat.layers.length=0)))
let rows:=compileLayers seed T.length pat.layers
∀ (ω : ℕ→BitVec w) (z : Config w) (payload : ℕ→List Bool)
(meaning : ℕ→TextRowMeaning LaneMemory),
streamState Q P T ω P.length=some z → z.pc=pre.length → z.output=[] →
z.written⊆arena → TextPhaseReady P T seed a payload z →
(∀ j< h,meaning 0 j (trainedLane T.length seed j (textLayer (lvl B j))) ((resetRowsFrom w σ P.length h 0 counts payload) j)) →
(∀ i : ℕ, ∀ hi : i< T.length,
let st:=(T.take i).foldl (packetTextTick a pat.residual pat.symbol) (rows,initial)
∀ ls f remaining tot, TextVisit pat.residual.1 st.1 (.raw T[i].val) ls (f::remaining) none tot →
∀ j lane,(ls++f::remaining)[j]?=some lane → ls.length≤ j →
∀ bits,meaning i j lane bits → meaning (i+1) j lane bits) →
(∀ i : ℕ, ∀ hi : i< T.length,
let st:=(T.take i).foldl (packetTextTick a pat.residual pat.symbol) (rows,initial)
let mix:=mixedTextMeaning (meaning i) (meaning (i+1))
∀ ls f remaining y tot, TextVisit pat.residual.1 st.1 (.raw T[i].val) ls (f::remaining) (some y) tot →
TextRowEvaluatorBetween Q ω σ P.length T.length base h pat.residual.1 (entry+25+82)
(entry+25+82+(row (entry+25+82)).length) counts widths
(TextPackedRows σ P.length T.length base h counts widths (mix ls.length))
(TextPackedRows σ P.length T.length base h counts widths (mix (ls.length+1))) arena ls f remaining y tot) →
∀ i≤ T.length, ∃ d, streamState Q P T ω (P.length+i)=some d ∧
d.output.length=i+1-P.length ∧
(∀ j < i+1-P.length,d.output[j]?=some (packetTextBit seed a T.length pat (T.take (P.length+j))).toNat) ∧
(i=T.length → d.output=answersOf P T (seededMatch P T (seed,a))) ∧ d.coinPos=z.coinPos ∧
d.written⊆arena ∧
(i< T.length → ∀ t,let e:=run Q ω (feed d [(streamWords P T).getD (P.length+i) 0]) t
e.written⊆arena ∧ (spaceBits w e:ℝ)≤ K*Real.logb 2 T.length*Real.logb 2 (Real.logb 2 T.length)) := by sorrySource
Gawrychowski, Janczewski, Jin and Nelson, An Improved Streaming Algorithm for Exact Pattern Matching, STOC 2027 submission, §9, Lemma 9.2, p. 29 (PDF p. 30). Derived implementation lemma in Stage.TextPassProgram, declaration counted_public_text_by_prefix.