Given a pattern of length followed by a text of length , one character at a time, can an algorithm report each occurrence of in as soon as it ends, while remembering very little? Exact Pattern Matching in the streaming model is the basic problem of a large area: it is used as a black box in streaming algorithms for -mismatch, matching with wildcards, and periodicity.
Timeline. Porat and Porat (FOCS 2009, doi:10.1109/FOCS.2009.11) gave the first such algorithm, with bits and two-sided error . Breslauer and Galil (ACM Trans. Algorithms 2014, doi:10.1145/2635814) made the error one-sided and the time constant per character, at the same space. The best lower bound stayed at bits, which left a logarithmic gap. Ergün, Jowhari and Sağlam (APPROX-RANDOM 2010) and Gawrychowski and Janczewski (SPIRE 2025) showed that the stronger task of also reporting all prefixes of length needs bits when and is binary, so an improved algorithm cannot track those prefixes. Gawrychowski, Janczewski, Jin and Nelson (STOC 2027 submission) close the gap to a factor when .
A pattern and a text , , arrive as a stream . The alphabet is with , and the algorithm knows in advance. For every , after processing , it must output YES if and NO otherwise. The output is correct only if all answers are correct. The error is one-sided if the answer at every occurrence is always YES.
The algorithm parses both strings into parse trees. Level is P_0=\\circ PT_0=Tiu_i^{c_i}\circ v_i#_ic_i+2i+1F_i$ combine a recursive random linear map of the group, an approximate count of the group's input characters, and an activity bit.
The goal is Theorem 1.1 of the paper:
The milestones follow the paper's proof, in its order:
The result. Theorem 1.1 improves the bits of the previous algorithms nearly quadratically in the regime , and nearly matches the lower bound. It also bypasses the bound for the extended problem. Its error is and not , so the two kinds of guarantee trade against each other. The paper derives from it a bound for arbitrary and error , and a streaming algorithm for the smallest period.
The formalization. No machine-checked proof of this result or of its streaming predecessors is known. Formalizing it gives a string-matching algorithm with a space bound on an explicit machine. Lemmas 6.1–7.4 are reusable on their own, as a theory of false occurrences under random linear maps. Fine–Wilf is already formalized, in Mathlib. All other results here are to be proved.
The first idea is a Karp–Rabin fingerprint per level of a doubling hierarchy of prefixes. Each level then needs bits, for two independent reasons. A union bound over up to positions forces long fingerprints; and storing a position costs bits. Both must go at once. Short fingerprints are available as inner products with a long random string, but that string must be stored, and it is not clear how to update such a fingerprint in small space. The mismatch events at different positions are not independent, so a bound must count something smaller than positions. The paper counts planes covering the mismatch lines. Replacing stored positions needs parses of pattern and text that stay synchronized at trigger occurrences, even under hash collisions.
The paper names no machine. The goal is stated on the published word-RAM DynBrooks_Machine: one finite program, word size with , and space times the number of cells ever written, for every coin tape and every step. The coin tape cannot be rewound, so every kept random bit is charged. The quantifier order is , with . The goal covers all with , including footnote 1's case of small . Below the printed bounds degenerate. is . The goal has five clauses: space, one answer per text character on time, almost-sure completion (rejection sampling has no worst-case bound), YES at every occurrence on every tape, and all answers correct together with probability at least .
An automaton with a free random seed would state a weaker theorem, which the authors report having obtained first. A bound per position, a decision version, or constants chosen after the input would also be weaker, and are excluded by the form of the statement.
Build and Match take hash functions as arguments, so that §§4–5 are deterministic and hold for every choice. Lemmas 7.4 and 7.5 count working space through finite-state evaluators with a stated number of bits; the single program appears in Lemma 9.2. Definitions: strings and occurrences; Pad and Group; parse trees; Build and Match; the linear maps; the family ; counters; the functions and ; candidate sets. The linear-algebra and counter parts are reusable. Solvers may add helper lemmas, including Observations 4.2, 4.6 and Lemmas 4.10, 4.12, 4.14, which are stated in the paper and are not milestones here. Time is not bounded, as Theorem 1.1 has no time clause.
namespace ExactPatternStream
/-- Gawrychowski, Janczewski, Jin, Nelson, *An Improved Streaming Algorithm for Exact Pattern Matching* (preprint, STOC 2027 submission, sha256 351218cb…), Theorem 1.1, p.2 (PDF 3), with the task of §1, p.1 (PDF 2).
Exact Pattern Matching with `n ≤ 2m` is solved by one streaming program with `O(log n log log n)` bits and one-sided error probability at most `1/log n`: for every polynomial alphabet bound, for all `1 ≤ m ≤ n ≤ 2m` with `n ≥ 3`, (1) charged space is at most `K log₂ n log₂ log₂ n` on every tape at every step; (2) no answer comes before `T[m-1]` is processed, and then one per character, before the next is delivered; (3) the run almost surely completes; (4) at every occurrence, on every tape, the answer is YES; (5) all answers are correct together with probability at least `1 - 1/log₂ n`.
**Formalization Note.** The paper names no machine. A program is a `DynBrooks.Program`: it cannot rewind its coin tape, so every random bit it keeps is in a charged cell. Word size `w = cw · ℓ(n)`, space `w · |cells ever written|`. `Q, cw, K` come after `k` and **before** the input. `n, m, |Σ|` are delivered as the first words; symbols are `1..σ` in the stream; YES is `1`, NO is `0`. `P, T` are fixed before the coins. A hypothesis that symbols fit in a word is not needed: `σ ≤ n^k` and `cw` follows `k`. A word of `0` bits cannot output `1`, so `cw = 0` fails (4). Rejection sampling has no worst-case bound, so runs may not complete on a null set of tapes, which is clause (3). `n ≥ 3` is where the printed bounds make sense: `1/log₂ 1` is undefined, and `log₂ 2 · log₂ log₂ 2 = 0`. Time is not bounded: Theorem 1.1 has no time clause. -/
theorem theorem_1_1 : ∀ k : ℕ, ∃ (Q : DynBrooks.Program) (cw K : ℕ),
∀ (σ : ℕ) (P T : List (Fin σ)),
1 ≤ P.length → P.length ≤ T.length → T.length ≤ 2 * P.length → 3 ≤ T.length →
σ ≤ T.length ^ k →
let m := P.length
let n := T.length
let w := cw * ell n
let B : ℝ := (K : ℝ) * Real.logb 2 n * Real.logb 2 (Real.logb 2 n)
(∀ (ω : ℕ → BitVec w) (t : ℕ),
(spaceBits w (DynBrooks.run Q ω (startConfig w P T) t) : ℝ) ≤ B) ∧
(∀ (ω : ℕ → BitVec w) (j : ℕ) (c : DynBrooks.Config w), j < m + n →
streamState Q P T ω j = some c → ∀ t : ℕ,
(spaceBits w (DynBrooks.run Q ω (DynBrooks.feed c [(streamWords P T).getD j 0]) t) : ℝ) ≤ B) ∧
(∀ (ω : ℕ → BitVec w) (j : ℕ) (c : DynBrooks.Config w), j ≤ m + n →
streamState Q P T ω j = some c → c.output.length = (j + 1) - 2 * m) ∧
ProbAtLeast (DynBrooks.coinMeasure w)
{ω | ∀ j ≤ m + n, (streamState Q P T ω j).isSome} 1 ∧
(∀ (ω : ℕ → BitVec w) (i : ℕ) (c : DynBrooks.Config w), m ≤ i + 1 → i < n → EndsAt P T i →
streamState Q P T ω (m + i + 1) = some c → c.output[i + 1 - m]? = some 1) ∧
ProbAtLeast (DynBrooks.coinMeasure w)
{ω | ∃ c, streamState Q P T ω (m + n) = some c ∧ c.output = truthList P T}
(ENNReal.ofReal (1 - 1 / Real.logb 2 n)) := by sorry
end ExactPatternStream
Exact Pattern Matching with can be solved by a streaming algorithm with space complexity bits and one-sided error probability at most .
Precisely: for every there are one program and constants such that, for every alphabet size and all , with , , , with word size :
This improves the bits of Porat–Porat and Breslauer–Galil for , against an lower bound.
Differences from the source:
DynBrooks.Program, word size , bits per cell ever written, with a coin tape it cannot rewind; reason: the authors' disclosure says an uncharged seed was their earlier, weaker result, so every kept random bit must be charged, and a finite-state automaton per input size would hide workspace in its transition functionFin σ, and as the first words read; reason: the same taskNo open leaves. Every sub-goal is proved or awaiting decomposition.