Documentation

CslibFrontier.DataStructure.Dictionary.WordRAM.ResizableSuccinct.Migration

Single-Tape 1 · OPT Capacity Migration and Trajectory-Relative Dispatcher #

This module formalizes single-tape capacity migration and trajectory-relative operational dispatch for the resizable succinct dynamic dictionary on the word-granular Resizable Word RAM (Cslib.WordRAM.Resizable), combining the in-epoch dispatcher inEpochOpCode (Dispatch) with the single-tape 1 · OPT streaming rebuild migrateActiveCode, empty-to-active initializer initFirstEpochCode, and singleton collapse deleteLastOneCode (Migration.Exec) into the unified parameter-free operational dispatcher resizableOpCode : RCode .exact rResize (¬resizableOpCode.ReadsWidth).

Main definitions #

Main results #

References #

Section 1: ABI Register Wrappers and RCode.rename epochEmb Bridge #

Caller-overwritable input mask on Fin rResize: false on persistent mBase (0), true on all other registers 1 .. rResize - 1.

Standalone register encoding for Dynamic.Op U on Fin rResize.

Entry argument-agreement predicate on Fin rResize (mTag, mArgU, mArgV).

Output decoder on Fin rResize, delegating to decode along epochEmb.

theorem Cslib.DataStructure.Dictionary.WordRAM.ResizableSuccinct.fits_resizableEncode {U V w : ℕ} {s_abs : State U} {o : Dynamic.Op U} (hw2 : WordRAM.Fits w 2) (hU : WordRAM.Fits w U) (hV : V ≤ 2 ^ w) (hval : (Dynamic.spec U V U).valid s_abs o) (i : Fin rResize) :

Section 2: Unified Parameter-Free Operational Dispatcher (resizableOpCode) #

Unified parameter-free operational dispatcher (RCode .exact rResize) for query, insert, and delete across empty, in-epoch, 0 → 1, 1 → 0, and capacity-doubling/halving states.

Section 3: Epoch Trajectory, 1 · OPT Peak Space, Potential, and Charges #

Epoch capacity and anchor-count invariant (N = targetCap U n_init): EpochValid U n N, N = targetCap U n_init, n = 0 ↔ n_init = 0, and n_init ≤ U.

Deterministic post-step epoch capacity N' on o : Dynamic.Op U.

Deterministic post-step epoch anchor count n_init' on o : Dynamic.Op U.

Deterministic epoch-trajectory state (dict, cap, initCount).

  • dict : State U

    Current abstract dictionary Fin U → Option ℕ.

  • cap : ℕ

    Current epoch capacity (0 when empty, targetCap U initCount when active).

  • initCount : ℕ

    Live key count when the current epoch was initialized (0 when empty).

Epoch state reached after executing ops : List (Dynamic.Op U) from st.

@[simp]
theorem Cslib.DataStructure.Dictionary.WordRAM.ResizableSuccinct.EpochState.run_cons {U : ℕ} (V : ℕ) (st : EpochState U) (o : Dynamic.Op U) (os : List (Dynamic.Op U)) :
run V st (o :: os) = run V (step V st o) os
theorem Cslib.DataStructure.Dictionary.WordRAM.ResizableSuccinct.epochAnchorInv_step {U V : ℕ} {st : EpochState U} {o : Dynamic.Op U} (hU_pos : 0 < U) (hinv : EpochAnchorInv U (dom st.dict).card st.cap st.initCount) (hval : (Dynamic.spec U V U).valid st.dict o) :
have st' := EpochState.step V st o; EpochAnchorInv U (dom st'.dict).card st'.cap st'.initCount

Exact peak hardware word footprint above base during resizableOpCode on o.

theorem Cslib.DataStructure.Dictionary.WordRAM.ResizableSuccinct.stepExactPeakWords_inEpoch_le_succinctWords {U V w N : ℕ} {s_abs : State U} {o : Dynamic.Op U} (hw : 0 < w) (hU : WordRAM.Fits w U) (hU_pos : 0 < U) (hV_pos : 0 < V) (hev : EpochValid U (dom s_abs).card N) (hval : (Dynamic.spec U V U).valid s_abs o) (hno_mig : (∀ (u : Fin U) (v : ℕ), o = Dynamic.Op.insert u v → (dom s_abs).card ≠ 0 → ¬((dom s_abs).card = N ∧ N < U)) ∧ ∀ (u : Fin U), o = Dynamic.Op.delete u → 2 ≤ (dom s_abs).card → ¬4 * ((dom s_abs).card - 1) < N) :
have n := (dom s_abs).card; have n' := (dom ((Dynamic.spec U V U).stepFn s_abs o).1).card; stepExactPeakWords V w N s_abs o ≤ Dynamic.succinctWords 1355 441 U V w (max n n')

In-Epoch Tight 1 · OPT Peak Word-Space Bound (stepExactPeakWords_inEpoch_le_succinctWords): Whenever (Dynamic.spec U V U).valid s_abs o holds and o does not trigger active capacity migration, stepExactPeakWords V w N s_abs o ≤ Dynamic.succinctWords 1355 441 U V w (max n n').

theorem Cslib.DataStructure.Dictionary.WordRAM.ResizableSuccinct.stepExactPeakWords_le_succinctWords {U V w N : ℕ} {s_abs : State U} {o : Dynamic.Op U} (hw : 0 < w) (hU : WordRAM.Fits w U) (hU_pos : 0 < U) (hV_pos : 0 < V) (hev : EpochValid U (dom s_abs).card N) (hval : (Dynamic.spec U V U).valid s_abs o) :
have n := (dom s_abs).card; have n' := (dom ((Dynamic.spec U V U).stepFn s_abs o).1).card; stepExactPeakWords V w N s_abs o ≤ Dynamic.succinctWords 2699 888 U V w (max n n')

1 · OPT Stepwise Peak Word-Space Bound (stepExactPeakWords_le_succinctWords): Across every admissible operation o (in-epoch, 0 → 1, 1 → 0, capacity-doubling, and capacity-halving migrations), stepExactPeakWords V w N s_abs o never exceeds Dynamic.succinctWords 2699 888 U V w (max n n') — strictly 1 · OPT(U, V, max n n') plus O((max n n') log log (max n n')) bits, never 2 · OPT.

theorem Cslib.DataStructure.Dictionary.WordRAM.ResizableSuccinct.w_mul_stepExactPeakWords_le_bits {U V w N : ℕ} {s_abs : State U} {o : Dynamic.Op U} (hw : 0 < w) (hU : WordRAM.Fits w U) (hU_pos : 0 < U) (hV_pos : 0 < V) (hev : EpochValid U (dom s_abs).card N) (hval : (Dynamic.spec U V U).valid s_abs o) :
have m := max (dom s_abs).card (dom ((Dynamic.spec U V U).stepFn s_abs o).1).card; w * stepExactPeakWords V w N s_abs o ≤ Dynamic.optBits U V m + 2699 * m * Dynamic.logLogFactor m + 889 * w

1 · OPT Stepwise Peak Bit-Space Bound (w_mul_stepExactPeakWords_le_bits): Multiplying stepExactPeakWords V w N s_abs o by w never exceeds Dynamic.optBits U V (max n n') + 2699 * (max n n') * Dynamic.logLogFactor (max n n') + 889 * w bits across all dynamic operations and capacity migrations.

Trajectory-relative address-space fit predicate (ReachedEpochsFit): requires Fits w (base + stepExactPeakWords V w st_t.cap st_t.dict o_t) only at epoch states st_t reached along ops, never globally across U.

Combined potential function for the resizable succinct dictionary: inEpochPotential (slab/tail hysteresis) plus (2 * migLinearFactor) * Nat.dist n n_init (epoch-migration potential, zero at epoch creation n = n_init and when empty n = n_init = 0).

Parameter-free base charge before adding (12 * inEpochFactor) * probeExcess.

Parameter-free $O(1)$ expected amortized instruction charge per operation across all query, insert, and delete steps (including capacity-doubling and capacity-halving rebuilds).

Section 4: Latent Seed Bundle, Pointwise Step Execution, and Expected Amortized Bounds #

Latent quotient-hash seed coupled with its active epoch capacity cap.

Extract a QuotHashSeed U N from ls : LatentSeed U without dependent casts in callers.

Canonical empty latent seed (cap = 0).

Per-state representation coupling st : EpochState U, ls : LatentSeed U, and x : RData rResize.

theorem Cslib.DataStructure.Dictionary.WordRAM.ResizableSuccinct.EpochRep.prepare {U V w base : ℕ} {st : EpochState U} {ls : LatentSeed U} {x : WordRAM.Resizable.RData rResize} {o : Dynamic.Op U} (hrep : EpochRep U V w base st ls x) (hbdd : WordRAM.Resizable.RData.Bounded w { regs := fun (i : Fin rResize) => if resizableInput i = true then resizableEncode o i else x.regs i, mem := x.mem, frontier := x.frontier }) :
EpochRep U V w base st ls { regs := fun (i : Fin rResize) => if resizableInput i = true then resizableEncode o i else x.regs i, mem := x.mem, frontier := x.frontier }
theorem Cslib.DataStructure.Dictionary.WordRAM.ResizableSuccinct.resizableOpCode_step_pointwise {U V w base : ℕ} {st : EpochState U} {ls : LatentSeed U} (o : Dynamic.Op U) {x : WordRAM.Resizable.RData rResize} (hanc : EpochAnchorInv U (dom st.dict).card st.cap st.initCount) (hrep : EpochRep U V w base st ls x) (hval : (Dynamic.spec U V U).valid st.dict o) (harg : resizableArgMatch o x.regs) (hfit_peak : WordRAM.Fits w (base + stepExactPeakWords V w st.cap st.dict o)) :
have n := (dom st.dict).card; have st' := EpochState.step V st o; have n' := (dom st'.dict).card; have L_peak := base + stepExactPeakWords V w st.cap st.dict o; have θ := LatentSeed.seedAt st.cap ls; ∃ (μ_out : PMF (WordRAM.Resizable.Randomized.StepROutcome (LatentSeed U) o.Result rResize)) (T_out : ENNReal), WordRAM.Resizable.ExecRCodeDist w resizableOpCode x (PMF.map WordRAM.Resizable.Randomized.StepROutcome.data μ_out) T_out L_peak ∧ (∀ q ∈ μ_out.support, EpochRep U V w base st' q.latent q.data ∧ q.result = ((Dynamic.spec U V U).stepFn st.dict o).2 ∧ resizableDecode o q.data.regs = some q.result ∧ ∀ addr < base, q.data.mem addr = x.mem addr) ∧ (0 < n' → if st'.cap = st.cap then 0 < n ∧ PMF.map (fun (q : WordRAM.Resizable.Randomized.StepROutcome (LatentSeed U) o.Result rResize) => LatentSeed.seedAt st.cap q.latent) μ_out = PMF.pure θ else PMF.map (fun (q : WordRAM.Resizable.Randomized.StepROutcome (LatentSeed U) o.Result rResize) => LatentSeed.seedAt st'.cap q.latent) μ_out = Probability.PMF.uniformOfFintype (Succinct.QuotHashSeed U st'.cap)) ∧ T_out + ∑' (q : WordRAM.Resizable.Randomized.StepROutcome (LatentSeed U) o.Result rResize), μ_out q * ↑(resizablePotential U w st'.cap n' st'.initCount base q.data) ≤ ↑(resizablePotential U w st.cap n st.initCount base x) + (↑resizableBaseCharge + if 0 < n then 12 * ↑inEpochFactor * ↑(SuccinctBucket.probeExcess st.cap (Succinct.qStage1 U st.cap θ.1) (Succinct.polyStage2 U st.cap) θ.2 (dom st.dict) (opKey o)) else 0)

Pointwise Distributional Step Certificate (resizableOpCode_step_pointwise): From any state (ls, x) satisfying EpochRep U V w base st ls x and resizableArgMatch o x.regs, resizableOpCode executes under ExecRCodeDist within base + stepExactPeakWords, establishes EpochRep for st' = st.step V o, either resamples a uniform QuotHashSeed U st'.cap or preserves ls identically, and satisfies the potential-amortized bound with probeExcess.

Section 5: Multi-Step Trajectory-Relative Expected Amortized Execution #

Exact resting word footprint above base after executing prefOps from EpochState.empty U.

Exact stepwise peak word footprint above base on o after executing prefOps from EpochState.empty U.

theorem Cslib.DataStructure.Dictionary.WordRAM.ResizableSuccinct.epochAnchorInv_run {U V : ℕ} (hU_pos : 0 < U) {st : EpochState U} {ops : List (Dynamic.Op U)} (hanc : EpochAnchorInv U (dom st.dict).card st.cap st.initCount) (hvh : (Dynamic.spec U V U).ValidHistory st.dict ops) :
have st' := EpochState.run V st ops; EpochAnchorInv U (dom st'.dict).card st'.cap st'.initCount

Distributional sequence invariant on ν : PMF (SeqROutcome (LatentSeed U) Dynamic.Op.Result rResize) after executing a prefix reaching st : EpochState U with canonical output trace out_pref and initial caller memory mem₀:

  1. Every t ∈ ν.support satisfies EpochRep U V w base st t.latent t.data, t.transcript = out_pref, and ∀ addr < base, t.data.mem addr = mem₀ addr;
  2. Whenever 0 < (Dictionary.dom st.dict).card, the marginal of t.latent.seedAt st.cap under ν is uniform (PMF.uniformOfFintype (QuotHashSeed U st.cap)).
theorem Cslib.DataStructure.Dictionary.WordRAM.ResizableSuccinct.resizableOpCode_step_expected_amortized {U V w base k_init : ℕ} (P : WordRAM.Resizable.SubroutineCode WordRAM.Basis.exact rResize k_init) (hP_base : P.baseReg = mBase) (hP_in : P.input = resizableInput) (hP_code : P.code = resizableOpCode) {st : EpochState U} {out_pref : List (Sigma Dynamic.Op.Result)} {mem₀ : ℕ → ℕ} {ν : PMF (WordRAM.Resizable.Randomized.SeqROutcome (LatentSeed U) Dynamic.Op.Result rResize)} (o : Dynamic.Op U) (hw2 : WordRAM.Fits w 2) (hU : WordRAM.Fits w U) (hV : V ≤ 2 ^ w) (hanc : EpochAnchorInv U (dom st.dict).card st.cap st.initCount) (hval : (Dynamic.spec U V U).valid st.dict o) (hfit_peak : WordRAM.Fits w (base + stepExactPeakWords V w st.cap st.dict o)) (hinv : EpochSeqInv V w base st out_pref mem₀ ν) :
have n := (dom st.dict).card; have st' := EpochState.step V st o; have n' := (dom st'.dict).card; have a := ((Dynamic.spec U V U).stepFn st.dict o).2; ∃ (μ_step : WordRAM.Resizable.Randomized.SeqROutcome (LatentSeed U) Dynamic.Op.Result rResize → PMF (WordRAM.Resizable.Randomized.StepROutcome (LatentSeed U) o.Result rResize)) (T_step : WordRAM.Resizable.Randomized.SeqROutcome (LatentSeed U) Dynamic.Op.Result rResize → ENNReal), (∀ t ∈ ν.support, WordRAM.Resizable.RData.Bounded w t.data ∧ (∀ (i : Fin rResize), P.input i = true → WordRAM.Fits w (resizableEncode o i)) ∧ WordRAM.Resizable.RData.Bounded w (P.prepare resizableEncode o t.data) ∧ WordRAM.Resizable.ExecRCodeDist w P.code (P.prepare resizableEncode o t.data) (PMF.map WordRAM.Resizable.Randomized.StepROutcome.data (μ_step t)) (T_step t) (base + stepExactPeakWords V w st.cap st.dict o) ∧ ∀ q ∈ (μ_step t).support, WordRAM.Resizable.RData.Bounded w q.data ∧ (base ≤ q.data.frontier ∧ q.data.frontier = base + compactedEpochWords U V w st'.cap n' ∧ q.data.regs P.baseReg = base) ∧ resizableDecode o q.data.regs = some q.result ∧ ∀ addr < base, q.data.mem addr = t.data.mem addr) ∧ EpochSeqInv V w base st' (out_pref ++ [⟨o, a⟩]) mem₀ (ν.bind fun (t : WordRAM.Resizable.Randomized.SeqROutcome (LatentSeed U) Dynamic.Op.Result rResize) => PMF.map (t.appendStep o) (μ_step t)) ∧ ∑' (t : WordRAM.Resizable.Randomized.SeqROutcome (LatentSeed U) Dynamic.Op.Result rResize), ν t * T_step t + ∑' (q_seq : WordRAM.Resizable.Randomized.SeqROutcome (LatentSeed U) Dynamic.Op.Result rResize), (ν.bind fun (t : WordRAM.Resizable.Randomized.SeqROutcome (LatentSeed U) Dynamic.Op.Result rResize) => PMF.map (t.appendStep o) (μ_step t)) q_seq * ↑(resizablePotential U w st'.cap n' st'.initCount base q_seq.data) ≤ ∑' (t : WordRAM.Resizable.Randomized.SeqROutcome (LatentSeed U) Dynamic.Op.Result rResize), ν t * ↑(resizablePotential U w st.cap n st.initCount base t.data) + ↑resizableCharge

Single-Step Expected Amortized Bound (resizableOpCode_step_expected_amortized): From any sequence distribution ν satisfying EpochSeqInv V w base st out_pref mem₀ ν, executing one admissible operation o via P.code = resizableOpCode preserves EpochSeqInv at st' = st.step V o and pays expected instruction cost plus expected potential change at most resizableCharge = O(1).

theorem Cslib.DataStructure.Dictionary.WordRAM.ResizableSuccinct.resizableOpCode_steps_expected_amortized {U V w base k_init : ℕ} (P : WordRAM.Resizable.SubroutineCode WordRAM.Basis.exact rResize k_init) (hP_base : P.baseReg = mBase) (hP_in : P.input = resizableInput) (hP_code : P.code = resizableOpCode) (prefOps remOps : List (Dynamic.Op U)) {out_pref : List (Sigma Dynamic.Op.Result)} {mem₀ : ℕ → ℕ} (ν : PMF (WordRAM.Resizable.Randomized.SeqROutcome (LatentSeed U) Dynamic.Op.Result rResize)) (hw2 : WordRAM.Fits w 2) (hU_pos : 0 < U) (hU : WordRAM.Fits w U) (hV : V ≤ 2 ^ w) (hvh : (Dynamic.spec U V U).ValidHistory (EpochState.run V (EpochState.empty U) prefOps).dict remOps) (hfit : ReachedEpochsFit V w base (EpochState.run V (EpochState.empty U) prefOps) remOps) (hanc : EpochAnchorInv U (dom (EpochState.run V (EpochState.empty U) prefOps).dict).card (EpochState.run V (EpochState.empty U) prefOps).cap (EpochState.run V (EpochState.empty U) prefOps).initCount) (hinv : EpochSeqInv V w base (EpochState.run V (EpochState.empty U) prefOps) out_pref mem₀ ν) :
have st := EpochState.run V (EpochState.empty U) prefOps; have st_fin := EpochState.run V st remOps; ∃ (ν_final : PMF (WordRAM.Resizable.Randomized.SeqROutcome (LatentSeed U) Dynamic.Op.Result rResize)) (T_ops : ENNReal), WordRAM.Resizable.Randomized.ExecSteps P ((Dynamic.spec U V U).toObliviousSequenceSpec (empty U)) (LatentSeed U) w base (epochSpaceBound U V w) (epochPeakSpaceBound U V w) resizableEncode resizableDecode prefOps remOps ν ν_final T_ops ∧ EpochSeqInv V w base st_fin (out_pref ++ ((Dynamic.spec U V U).run st.dict remOps).2) mem₀ ν_final ∧ T_ops + ∑' (q_seq : WordRAM.Resizable.Randomized.SeqROutcome (LatentSeed U) Dynamic.Op.Result rResize), ν_final q_seq * ↑(resizablePotential U w st_fin.cap (dom st_fin.dict).card st_fin.initCount base q_seq.data) ≤ ∑' (t : WordRAM.Resizable.Randomized.SeqROutcome (LatentSeed U) Dynamic.Op.Result rResize), ν t * ↑(resizablePotential U w st.cap (dom st.dict).card st.initCount base t.data) + ↑(remOps.length * resizableCharge)

Multi-Step Trajectory-Relative Expected Amortized Execution (resizableOpCode_steps_expected_amortized): Across any admissible operation sequence remOps from prefix prefOps whose trajectory peaks fit in w-bit words (ReachedEpochsFit V w base st remOps), resizableOpCode executes under Resizable.Randomized.ExecSteps, produces the exact canonical dictionary transcript, preserves EpochSeqInv, and executes in at most E[Φ_init] + remOps.length * resizableCharge expected instructions.