Documentation

CslibFrontier.DataStructure.Dictionary.WordRAM.ResizableSuccinct.Migration.StreamStep

Single-Tape Block Copy, New-Epoch Metadata Initialization, and Streaming Rebuild (Memory.Prog) #

This module implements the deterministic Memory.Prog subroutines (¬ReadsWidth, certified via RealizesBounded .exact) for single-tape 1 · OPT epoch capacity migration:

  1. Overlapping-Safe Block Copy (copyRightwardProg, copyLeftwardProg):
    • copyRightwardProg copies [srcBase, +len) rightward to [dstBase, +len) (srcBase ≤ dstBase) in reverse index order len - 1 .. 0 so overlapping ranges never clobber unread words;
    • copyLeftwardProg copies [srcBase, +len) leftward to [dstBase, +len) (dstBase ≤ srcBase) in forward index order 0 .. len - 1.
  2. New-Epoch Table & Zeroed Metadata Initialization (initNewEpochMetaProg):
    • builds the Four-Russians carryless multiplication table via initTableGenProg and zeros [newMetaBase + offCompLM, newMetaBase + offCompItems), establishing ReducedKWise.Rep, DictStateInv ... (Dictionary.empty U), FixedCoupled, and slotPotential = 0.
  3. Old-Item Key/Value Reconstruction & Fresh-Key Streaming Append (readOldItemKeyValGenProg, streamInsertFreshGenProg, streamAllItemsProg):
    • reconstructs (u_i, v_i) from dense slot i < n of the right-aligned old item suffix via recoverOwnerBucketGenProg, evalHashGenProg, and Feistel inversion;
    • appends (u_i, v_i) into [0, i + 1) at (newMetaBase, arenaBase) without duplicate search (valid by injectivity of reconstructKeyAt_spec), preserving all unread old items d > i by newItemEnd_le_oldItemNextWord.

Main definitions #

Main results #

References #

Section 1: Overlapping-Safe Rightward and Leftward Block Copy (Memory.Prog) #

Copy len words rightward from [srcBase, +len) to [dstBase, +len) (srcBase ≤ dstBase) in reverse order (¬ReadsWidth).

theorem Cslib.DataStructure.Dictionary.WordRAM.ResizableSuccinct.copyRightwardProg_spec {w srcBase dstBase len : ℕ} {s₀ : Memory.State} (hwf : ∀ a < s₀.frontier, WordRAM.Fits w (s₀.mem a)) (hle : srcBase ≤ dstBase) (hfr : dstBase + len ≤ s₀.frontier) (hfit1 : WordRAM.Fits w 1) :
have d := ((srcBase, dstBase), len); have prog := copyRightwardProg d; have s' := (Memory.spec 0).clientState s₀ prog; CopyRightwardPre w d s₀ ∧ (Memory.spec w).ValidHistory s₀ ((Memory.spec w).clientHistory s₀ prog) ∧ WordRAM.Realization.memoryCost prog s₀ ≤ 2 * len ∧ s'.frontier = s₀.frontier ∧ (∀ j < len, s'.mem (dstBase + j) = s₀.mem (srcBase + j)) ∧ ∀ (a : ℕ), ¬(dstBase ≤ a ∧ a < dstBase + len) → s'.mem a = s₀.mem a

Copy len words leftward from [srcBase, +len) to [dstBase, +len) (dstBase ≤ srcBase) in forward order (¬ReadsWidth).

theorem Cslib.DataStructure.Dictionary.WordRAM.ResizableSuccinct.copyLeftwardProg_spec {w srcBase dstBase len : ℕ} {s₀ : Memory.State} (hwf : ∀ a < s₀.frontier, WordRAM.Fits w (s₀.mem a)) (hle : dstBase ≤ srcBase) (hfr : srcBase + len ≤ s₀.frontier) (hfit1 : WordRAM.Fits w 1) :
have d := ((srcBase, dstBase), len); have prog := copyLeftwardProg d; have s' := (Memory.spec 0).clientState s₀ prog; CopyLeftwardPre w d s₀ ∧ (Memory.spec w).ValidHistory s₀ ((Memory.spec w).clientHistory s₀ prog) ∧ WordRAM.Realization.memoryCost prog s₀ ≤ 2 * len ∧ s'.frontier = s₀.frontier ∧ (∀ j < len, s'.mem (dstBase + j) = s₀.mem (srcBase + j)) ∧ ∀ (a : ℕ), ¬(dstBase ≤ a ∧ a < dstBase + len) → s'.mem a = s₀.mem a

Section 2: New-Epoch Four-Russians Table and Zeroed Metadata Initializer #

Build the Four-Russians table at newMetaBase + 225 and zero compacted metadata [newMetaBase + offCompLM, newMetaBase + offCompItems) (¬ReadsWidth).

theorem Cslib.DataStructure.Dictionary.WordRAM.ResizableSuccinct.initNewEpochMetaProg_spec {w U V N newMetaBase arenaBase : ℕ} {θ_new : Succinct.QuotHashSeed U N} {s₀ : Memory.State} (hw : 0 < w) (hN : 1 ≤ N) (hNU : N ≤ U) (hU : WordRAM.Fits w U) (hV : V ≤ 2 ^ w) (hfr : newMetaBase + offCompItems U w N ≤ s₀.frontier) (hfit : WordRAM.Fits w (newMetaBase + offCompItems U w N)) (hseed : HashFamily.WordRAM.ReducedKWise.SeedRep (newMetaBase + epochHdrWords) (Succinct.qBits U N) (Succinct.hashB N) (SuccinctBucket.totalMicroBits N) 3 θ_new s₀.mem) :
have d := ((HashFamily.WordRAM.RuntimeReducedKWise.mkHashParams w (Succinct.qBits U N) (Succinct.hashB N) (SuccinctBucket.totalMicroBits N) 3, mkCompParams U V w N), newMetaBase); have prog := initNewEpochMetaProg d; have s' := (Memory.spec 0).clientState s₀ prog; InitNewEpochMetaPre w d s₀ ∧ (Memory.spec w).ValidHistory s₀ ((Memory.spec w).clientHistory s₀ prog) ∧ WordRAM.Realization.memoryCost prog s₀ ≤ 256 * N + 475 ∧ s'.frontier = s₀.frontier ∧ HashFamily.WordRAM.ReducedKWise.Rep (newMetaBase + epochHdrWords) w (Succinct.qBits U N) (Succinct.hashB N) (SuccinctBucket.totalMicroBits N) 3 θ_new s'.mem ∧ Succinct.totalSlots N (compGmAt newMetaBase U w N s'.mem) = 0 ∧ Succinct.slotPotential N (compGmAt newMetaBase U w N s'.mem) = 0 ∧ (∃ (s_fix₀ : Memory.State), Succinct.DictStateInv U V (ghostW w) N 0 θ_new (empty U) s_fix₀ ∧ FixedCoupled newMetaBase arenaBase U V w N s_fix₀ s') ∧ ∀ (a : ℕ), ¬(newMetaBase + epochHdrWords ≤ a ∧ a < newMetaBase + offCompItems U w N) → s'.mem a = s₀.mem a

Section 3: Old-Item (u_i, v_i) Reconstruction (readOldItemKeyValGenProg) #

theorem Cslib.DataStructure.Dictionary.WordRAM.ResizableSuccinct.readOldItemKeyValGenProg_spec {w U V N n oldMetaBase oldItemBase idx_d : ℕ} {θ : Succinct.QuotHashSeed U N} {s₀ : Memory.State} (hw : 0 < w) (hN : 1 ≤ N) (hNU : N ≤ U) (hU : WordRAM.Fits w U) (hV : V ≤ 2 ^ w) (hitem : oldMetaBase + offCompItems U w N ≤ oldItemBase) (hfr : oldItemBase + compactedItemWords U V w N n ≤ s₀.frontier) (hfit : WordRAM.Fits w (oldMetaBase + offCompItems U w N)) (hrep : HashFamily.WordRAM.ReducedKWise.Rep (oldMetaBase + epochHdrWords) w (Succinct.qBits U N) (Succinct.hashB N) (SuccinctBucket.totalMicroBits N) 3 θ s₀.mem) (hslot : Succinct.SlotStoreInv N (compGmAt oldMetaBase U w N s₀.mem)) (htd : 0 < FeistelQuotient.bucketBits N → TailDenseInv N (compGmAt oldMetaBase U w N s₀.mem 0) (compGmAt oldMetaBase U w N s₀.mem 1) (compTDAt oldMetaBase U w N s₀.mem) (compDTAt oldMetaBase U w N s₀.mem)) (htot : epochTotalSlots N (compGmAt oldMetaBase U w N s₀.mem) = n) (hd : idx_d < n) (hrec_lt : reconstructKeyAt oldMetaBase oldItemBase U V w N n θ s₀.mem idx_d < U) :
have oldHp := HashFamily.WordRAM.RuntimeReducedKWise.mkHashParams w (Succinct.qBits U N) (Succinct.hashB N) (SuccinctBucket.totalMicroBits N) 3; have oldCp := mkCompParams U V w N; have d := (((oldHp, oldCp), oldMetaBase, oldItemBase), idx_d); have prog := readOldItemKeyValGenProg d; have s' := (Memory.spec 0).clientState s₀ prog; ReadOldItemKeyValPre w d s₀ ∧ Succinct.ValidProg w 0 s₀ prog ∧ WordRAM.Realization.memoryCost prog s₀ ≤ 45180 ∧ (Memory.spec 0).clientResult s₀ prog = (reconstructKeyAt oldMetaBase oldItemBase U V w N n θ s₀.mem idx_d, compValAt oldItemBase U V w N n s₀.mem idx_d) ∧ s'.frontier = s₀.frontier ∧ ∀ (a : ℕ), ¬(oldMetaBase + 63 ≤ a ∧ a < oldMetaBase + 225) → s'.mem a = s₀.mem a

Section 4: Fresh-Key Streaming Insertion (streamInsertFreshGenProg) #

Insert a fresh (u, v) pair (¬(s_abs ⟨u, hu⟩).isSome) into (newMetaBase, arenaBase) without duplicate bucket search (¬ReadsWidth).

theorem Cslib.DataStructure.Dictionary.WordRAM.ResizableSuccinct.streamInsertFreshGenProg_spec {w U V N m_cap newMetaBase arenaBase u v : ℕ} {θ : Succinct.QuotHashSeed U N} {s_abs : State U} {s_fix s₀ : Memory.State} (hu : u < U) (henv : CompEpochEnv U V w N newMetaBase arenaBase m_cap s₀) (hfit : WordRAM.Fits w (newMetaBase + offCompItems U w N)) (hrep : HashFamily.WordRAM.ReducedKWise.Rep (newMetaBase + epochHdrWords) w (Succinct.qBits U N) (Succinct.hashB N) (SuccinctBucket.totalMicroBits N) 3 θ s₀.mem) (hinv : Succinct.DictStateInv U V (ghostW w) N 0 θ s_abs s_fix) (hcpl : FixedCoupled newMetaBase arenaBase U V w N s_fix s₀) (htot_lt : Succinct.totalSlots N (compGmAt newMetaBase U w N s₀.mem) < N) (hm_cap : Succinct.totalSlots N (compGmAt newMetaBase U w N s₀.mem) + 1 ≤ m_cap) (hv : v < V) (hfresh : ¬(s_abs ⟨u, hu⟩).isSome = true) :
have newHp := HashFamily.WordRAM.RuntimeReducedKWise.mkHashParams w (Succinct.qBits U N) (Succinct.hashB N) (SuccinctBucket.totalMicroBits N) 3; have newCp := mkCompParams U V w N; have d := (((newHp, newCp), newMetaBase, arenaBase), u, v); have prog := streamInsertFreshGenProg d; have s' := (Memory.spec 0).clientState s₀ prog; StreamInsertFreshPre w d s₀ ∧ Succinct.ValidProg w 0 s₀ prog ∧ WordRAM.Realization.memoryCost prog s₀ + 98 * Succinct.slotPotential N (compGmAt newMetaBase U w N s'.mem) ≤ 98 * Succinct.slotPotential N (compGmAt newMetaBase U w N s₀.mem) + 45360 ∧ s'.frontier = s₀.frontier ∧ HashFamily.WordRAM.ReducedKWise.Rep (newMetaBase + epochHdrWords) w (Succinct.qBits U N) (Succinct.hashB N) (SuccinctBucket.totalMicroBits N) 3 θ s'.mem ∧ (∃ (s_fix' : Memory.State), Succinct.DictStateInv U V (ghostW w) N 0 θ (Function.update s_abs ⟨u, hu⟩ (some v)) s_fix' ∧ FixedCoupled newMetaBase arenaBase U V w N s_fix' s') ∧ ∀ (a : ℕ), ¬(newMetaBase + 63 ≤ a ∧ a < newMetaBase + 225) → ¬(newMetaBase + offCompLM U w N ≤ a ∧ a < newMetaBase + offCompItems U w N) → ¬(arenaBase ≤ a ∧ a < arenaBase + compactedItemWords U V w N m_cap) → s'.mem a = s₀.mem a

Section 5: Full n-Item Single-Tape Streaming Loop and Relocation #

Stream n items starting from index a (0 for a full epoch migration) from (oldMetaBase, oldItemBase) into (newMetaBase, arenaBase) (¬ReadsWidth).

structure Cslib.DataStructure.Dictionary.WordRAM.ResizableSuccinct.StreamRebuildEnv (U V w N_old N_new n oldMetaBase newMetaBase arenaBase : ℕ) (θ_old : Succinct.QuotHashSeed U N_old) (θ_new : Succinct.QuotHashSeed U N_new) (s_abs : State U) (s₀ : Memory.State) :

Single-tape zone and epoch-invariant bundle for streamAllItemsProg_spec.

theorem Cslib.DataStructure.Dictionary.WordRAM.ResizableSuccinct.streamAllItemsProg_spec {U V w N_old N_new n oldMetaBase newMetaBase arenaBase : ℕ} {θ_old : Succinct.QuotHashSeed U N_old} {θ_new : Succinct.QuotHashSeed U N_new} {s_abs : State U} {s₀ : Memory.State} (henv : StreamRebuildEnv U V w N_old N_new n oldMetaBase newMetaBase arenaBase θ_old θ_new s_abs s₀) :
have oldItemBase := arenaBase + (migrateArenaWords U V w N_old N_new n - compactedItemWords U V w N_old n); have oldHp := HashFamily.WordRAM.RuntimeReducedKWise.mkHashParams w (Succinct.qBits U N_old) (Succinct.hashB N_old) (SuccinctBucket.totalMicroBits N_old) 3; have oldCp := mkCompParams U V w N_old; have newHp := HashFamily.WordRAM.RuntimeReducedKWise.mkHashParams w (Succinct.qBits U N_new) (Succinct.hashB N_new) (SuccinctBucket.totalMicroBits N_new) 3; have newCp := mkCompParams U V w N_new; have d := (((((oldHp, oldCp), oldMetaBase, oldItemBase), (newHp, newCp), newMetaBase, arenaBase), 0), n); have prog := streamAllItemsProg d; have s' := (Memory.spec 0).clientState s₀ prog; StreamAllItemsPre w d s₀ ∧ Succinct.ValidProg w 0 s₀ prog ∧ WordRAM.Realization.memoryCost prog s₀ + 98 * Succinct.slotPotential N_new (compGmAt newMetaBase U w N_new s'.mem) ≤ 90540 * n ∧ s'.frontier = s₀.frontier ∧ HashFamily.WordRAM.ReducedKWise.Rep (newMetaBase + epochHdrWords) w (Succinct.qBits U N_new) (Succinct.hashB N_new) (SuccinctBucket.totalMicroBits N_new) 3 θ_new s'.mem ∧ Succinct.totalSlots N_new (compGmAt newMetaBase U w N_new s'.mem) = n ∧ (∃ (s_fix' : Memory.State), Succinct.DictStateInv U V (ghostW w) N_new 0 θ_new s_abs s_fix' ∧ FixedCoupled newMetaBase arenaBase U V w N_new s_fix' s') ∧ (∀ a < oldMetaBase + 63, s'.mem a = s₀.mem a) ∧ ∀ (a : ℕ), newMetaBase ≤ a ∧ a < newMetaBase + 63 → s'.mem a = s₀.mem a
theorem Cslib.DataStructure.Dictionary.WordRAM.ResizableSuccinct.compactedSplitRep_of_reloc {U V w N n n_init srcMetaBase srcItemBase base : ℕ} {θ : Succinct.QuotHashSeed U N} {s_abs : State U} {s_src s_dst : Memory.State} (hw : 0 < w) (hhdr : RootHeaderValid U V w N n n_init srcMetaBase s_src.mem) (hpar : EpochParamsStored U V w N srcMetaBase s_src.mem) (hhash : HashFamily.WordRAM.ReducedKWise.Rep (srcMetaBase + epochHdrWords) w (Succinct.qBits U N) (Succinct.hashB N) (SuccinctBucket.totalMicroBits N) 3 θ s_src.mem) (hcard : (dom s_abs).card = n) (hvals : ValuesBounded V s_abs) (hinv_cpl : ∃ (s_fix : Memory.State), Succinct.DictStateInv U V (ghostW w) N 0 θ s_abs s_fix ∧ FixedCoupled srcMetaBase srcItemBase U V w N s_fix s_src) (hmeta_eq : ∀ j < offCompItems U w N, s_dst.mem (base + j) = s_src.mem (srcMetaBase + j)) (hitem_eq : ∀ j < compactedItemWords U V w N n, s_dst.mem (base + offCompItems U w N + j) = s_src.mem (srcItemBase + j)) :
CompactedSplitRep base (base + offCompItems U w N) U V w N n n_init θ s_abs s_dst ∧ compGmAt base U w N s_dst.mem = compGmAt srcMetaBase U w N s_src.mem

Relocate an active compacted epoch representation from (srcMetaBase, srcItemBase) to (base, base + offCompItems U w N) after leftward block copy.