Online data structures: ServesOnline from a representation invariant and three per-run lemmas
ProvedDynLZ77.Main.servesOnline_of_invariantdata-structuresdynamic-lz77hoare-logicverified-programmingword-ram
This reduces the online data-structure statements of the Dynamic LZ77 mission (Lemmas 1.4, 2.1, 7.5, 9.6 and Theorem 1.1, all of the form ServesOnline) to three statements about single runs.
Let be a query family, a program of the word RAM CentralStrQ, the edit-time function, and constants. Write with the current length. Let be any predicate, read as "at word width , memory represents the string ". Suppose that, for every width and every with bounding the lengths and words involved:
- Initialization. For every valid LZ-like parsing with tokens of a string , the run of on the input layout (and arbitrary uninitialized memory) halts within steps, touches addresses below , and leaves a memory satisfying .
- Edits. For every memory satisfying and every valid edit , the run on that memory with the edit's code written in halts within steps, touches addresses below (length ), and leaves a memory satisfying .
- Queries. For every memory satisfying and every valid query , the run with the query's code written in halts within steps, touches addresses below , leaves a correct answer to in cells , and leaves a memory satisfying .
Then
Formalization Note The global width condition of ServesOnline, , is passed to each run as the bound . Here is the largest length over the operation sequence and the largest input or code word.
Preamble
import Mathlib import Definitions.Def_CentralStrQ_Machine import Definitions.Def_CentralStrQ_Hoare import Definitions.Def_DynLZ77_Main_DataStructure set_option autoImplicit false
Formal statement
namespace DynLZ77.Main
open CentralStrQ WordRAM
/-- **`ServesOnline` from a representation invariant.** A program is a dynamic data structure
for the query family `F` as soon as there is an invariant `Inv w S mem` ("`mem` represents `S`")
such that the initialization run establishes it within the `Õ(z′)` bounds, every edit run
preserves it (for the edited string) within the edit bounds, and every query run preserves it
within the query bounds and leaves a correct answer. Each run may assume one bound `B` on the
lengths and words involved with `(B + 2)^cw ≤ 2^w`. -/
theorem servesOnline_of_invariant (F : QueryFamily) (editCost : ℕ → ℕ → ℝ) (P : Program)
(c : ℕ) (C : ℝ) (cw : ℕ) (Inv : (w : Width) → List ℕ → Memory w → Prop)
(hinit : ∀ (toks : List Token) (w : Width) (rest : Memory w) (B : ℕ),
TokensValid toks → (decode toks).length ≤ B → (∀ x ∈ initLayout toks, x ≤ B) →
(B + 2) ^ cw ≤ 2 ^ w.bits →
RunsWithin P (loadMem (initLayout toks) rest)
(otilde c C (decode toks).length (toks.length : ℝ))
(fun mem reach => (reach : ℝ) ≤ otilde c C (decode toks).length (toks.length : ℝ) ∧
Inv w (decode toks) mem))
(hedit : ∀ (S : List ℕ) (e : Edit ℕ) (w : Width) (mem : Memory w) (B : ℕ),
Inv w S mem → e.Valid S.length → S.length ≤ B → (e.apply S).length ≤ B →
(∀ x ∈ e.code, x ≤ B) → (B + 2) ^ cw ≤ 2 ^ w.bits →
RunsWithin P (writeInput mem e.code) (otilde c C S.length (editCost S.length (z S)))
(fun mem' reach => (reach : ℝ) ≤
otilde c C (max S.length (e.apply S).length) ((max (z S) (z (e.apply S)) : ℕ) : ℝ) ∧
Inv w (e.apply S) mem'))
(hquery : ∀ (S : List ℕ) (q : F.Q) (w : Width) (mem : Memory w) (B : ℕ),
Inv w S mem → F.Valid S q → S.length ≤ B → (∀ x ∈ 3 :: F.code q, x ≤ B) →
(B + 2) ^ cw ≤ 2 ^ w.bits →
RunsWithin P (writeInput mem (3 :: F.code q)) (otilde c C S.length 1)
(fun mem' reach => (reach : ℝ) ≤ otilde c C S.length (z S) ∧
F.Correct S q (fun a => (mem' a).toNat) ∧ Inv w S mem')) :
ServesOnline F editCost P c C cw := by sorry
end DynLZ77.Main
Source
Online protocol of Def_DynLZ77_Main_DataStructure: Boneh, Fried, Golan, Kraus, Dynamic LZ77: No Space for Improvement, STOC 2027 submission (manuscript), Section 4.1, p. 16 (dynamic algorithms, edit operations) and footnote 1, p. 1 (Otilde bounds), formalized in the mission definition DynLZ77_Main_DataStructure; machine Def_CentralStrQ_Machine. Infrastructure for the published deterministic word RAM Def_CentralStrQ_Machine (Kempa, Kociumaka, A Complete Characterization of Central String Queries in Compact Space, STOC 2027 submission, Section 3.2, p. 13; T. Hagerup, Sorting and searching on the word RAM, STACS 1998, https://doi.org/10.1007/BFb0028575). Hoare-style rules after C. A. R. Hoare, An axiomatic basis for computer programming, Commun. ACM 12(10), 1969, https://doi.org/10.1145/363235.363259.