Documentation

CslibFrontier.DataStructure.Dictionary.WordRAM.SuccinctDispatch

Register Wiring and Per-Operation Native Dispatch for the Succinct Dictionary #

This module wires the five parameter-free Realizes .exact certificates from SuccinctHash.lean (realizes_extractQuotGen, realizes_queryWithHashGen, realizes_insertWithHashGen, realizes_deletePrepWithHashGen, realizes_deleteFinishWithHashGen) together with loadParamsCode, ReducedKWise.evalCode, ReducedKWise.initTableCode, and ReducedKWise.resampleCode into a single SubroutineCode (subroutineCode U V w n_max) on a parameter-free constant number of registers rSuccinct, and proves the unified per-operation deterministic execution theorem (exec_opCode) with a parameter-free O(1) amortized instruction charge chargeVal.

Main definitions #

Main results #

Section 1: Parameter-free register layout, scratch bank, and exchange factor #

Combined parameter-free scratch register bank size for the five Realizes certificates used in operation dispatch.

Parameter-free total register count 292 + scratchSuccinct for the succinct dictionary subroutine (0..239 for ReducedKWise, 240..255 for fixed control/input/output registers, 256..291 for the 36 runtime DictParams registers paramReg, and 292.. for scratch).

Canonical embedding Fin 292 → Fin rSuccinct for fixed control, hash, and parameter registers.

@[simp]
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.update_sReg (f : Fin rSuccinct → ℕ) (j : Fin 292) (v : ℕ) (i : Fin 292) :
Function.update f (sReg j) v (sReg i) = if i = j then v else f (sReg i)

Combined parameter-free exchange factor ≥ 1 dominating the five Realizes.factor constants.

Embed a ReducedKWise register i : Fin 240 into Fin rSuccinct.

@[reducible, inline]

Persistent base-address register 0 (sReg 0).

@[reducible, inline]

Hash input register 1 (sReg 1).

@[reducible, inline]

Hash output register 2 (sReg 2).

@[reducible, inline]

Bump-pointer frontier register 240 (sReg 240).

@[reducible, inline]

Scratch pointer register 241 for zeroFillCode and allocSpan.

@[reducible, inline]

Constant-0 scratch register 242 for zeroFillCode and operation dispatch.

@[reducible, inline]

Constant-1 scratch register 243 for zeroFillCode and operation dispatch.

@[reducible, inline]

Input operation-tag register 244 (0 = query, 1 = insert, 2 = delete).

@[reducible, inline]

Input key register 245 (u.val).

@[reducible, inline]

Input value register 246 (v for insert, 0 otherwise).

@[reducible, inline]

Nominal output register 247 for SubroutineCode.output.

@[reducible, inline]

Register 248 saving the first hash evaluation h_q across the second hash call in delete.

@[reducible, inline]

Register 249 storing found from deletePrepWithHashGenProg.

@[reducible, inline]

Register 250 storing j_del from deletePrepWithHashGenProg.

@[reducible, inline]

Register 251 storing phys_del from deletePrepWithHashGenProg.

@[reducible, inline]

Register 252 storing the Option ℕ presence tag (0 = none, 1 = some) from queryWithHashGenProg.

@[reducible, inline]

Register 253 storing the Option ℕ payload value v from queryWithHashGenProg.

Register block 256..291 holding the 36 words of DictParams.

Section 2: Register wirings (src*, tmp*), loadParamsCode, and emitted native code #

Load entries 0 .. k (k < 36) of dp : DictParams into paramReg 0 .. paramReg k in k + 1 instructions.

Load all 36 words of mkDictParams U V w n_max (hashSpace U w n_max) into paramReg 0 .. 35 in 36 instructions.

Payload source register wiring ![argUReg] for extractQuotGenProg.

Full source register wiring Fin.append paramReg srcExtD for extractQuotGenProg.

Scratch/output register wiring for extractQuotGenProg, placing output 0 directly in hashKeyReg (1) and remaining scratch registers at 292 + j.val.

Payload source register wiring ![baseReg, argUReg, hashOutReg] for queryWithHashGenProg.

Full source register wiring Fin.append paramReg srcQryD for queryWithHashGenProg.

Scratch/output register wiring for queryWithHashGenProg, placing outputs 0, 1 in resTagReg (252) and resValReg (253).

Payload source register wiring ![baseReg, argUReg, argVReg, hashOutReg] for insertWithHashGenProg.

Full source register wiring Fin.append paramReg srcInsD for insertWithHashGenProg.

@[simp]
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.val_srcInsD (i : Fin 4) :
↑(srcInsD i) = if ↑i = 0 then 0 else if ↑i = 1 then 245 else if ↑i = 2 then 246 else 2

Scratch register wiring for insertWithHashGenProg at 292 + j.val.

Emitted native code for insertWithHashGenProg.

Payload source register wiring ![baseReg, argUReg, hqReg] for deletePrepWithHashGenProg.

Full source register wiring Fin.append paramReg srcDelPrepD for deletePrepWithHashGenProg.

Scratch/output register wiring for deletePrepWithHashGenProg, placing outputs 0..3 in foundReg (249), jDelReg (250), physDelReg (251), and hashKeyReg (1).

Emitted native code for deletePrepWithHashGenProg.

Payload source register wiring ![baseReg, argUReg, hqReg, foundReg, jDelReg, physDelReg, hashOutReg] for deleteFinishWithHashGenProg.

Full source register wiring Fin.append paramReg srcDelFinD for deleteFinishWithHashGenProg.

@[simp]
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.val_srcDelFinD (i : Fin 7) :
↑(srcDelFinD i) = if ↑i = 0 then 0 else if ↑i = 1 then 245 else if ↑i = 2 then 248 else if ↑i = 3 then 249 else if ↑i = 4 then 250 else if ↑i = 5 then 251 else 2

Scratch register wiring for deleteFinishWithHashGenProg at 292 + j.val.

Emitted native code for deleteFinishWithHashGenProg.

Native quotient hash evaluation code (ReducedKWise.evalCode ...).rename coreReg.

Complete delete branch code: saves h_q into hqReg, runs delPrepCode (which puts q_last into hashKeyReg), evaluates h_q_last via hashEvalCode, and runs delFinCode.

Complete operation dispatch code for subroutineCode: loads DictParams into paramReg, extracts q, evaluates h_q, and branches on tagReg between qryCode, insCode, and delCode.

Canonical SubroutineCode for the fixed-capacity succinct dynamic dictionary on rSuccinct registers. Note that subroutineCode U V w n_max depends on the static parameters (U, V, w, n_max) (through space, loadParamsCode, and ReducedKWise bit-width constants) and is independent of base.

Section 3: Generic register-wiring disjointness and encoding helpers #

theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.append_paramReg_ne_tmp {k m : ℕ} (srcD : Fin k → Fin rSuccinct) (tmp : Fin m → Fin rSuccinct) (htmp_out : ∀ (j : Fin m), ↑(tmp j) < 256 ∨ 292 ≤ ↑(tmp j)) (hd : ∀ (i : Fin k) (j : Fin m), srcD i ≠ tmp j) (i : Fin (36 + k)) (j : Fin m) :
Fin.append paramReg srcD i ≠ tmp j

Generic disjointness between Fin.append paramReg srcD and tmp whenever tmp maps every index outside [256, 292) and is disjoint from srcD.

theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.append_paramReg_ne_frontier {k : ℕ} (srcD : Fin k → Fin rSuccinct) (hf : ∀ (i : Fin k), ↑(srcD i) ≠ 240) (i : Fin (36 + k)) :

Generic disjointness between Fin.append paramReg srcD and frontierReg (240).

Section 4: Representation invariant, potential, charge, and ABI encoding #

def Cslib.DataStructure.Dictionary.WordRAM.Succinct.Rep (U V w n_max base : ℕ) (θ : QuotHashSeed U n_max) (s_abs : State U) (x : WordRAM.Data rSuccinct) :

Concrete Word-RAM representation invariant at base coupling θ : QuotHashSeed U n_max, abstract dictionary state s_abs : Dictionary.State U, and machine state x.

noncomputable def Cslib.DataStructure.Dictionary.WordRAM.Succinct.potential (U V w n_max base : ℕ) (_θ : QuotHashSeed U n_max) (x : WordRAM.Data rSuccinct) :

Scaled concrete potential (66 * opFactor) * slotPotential.

Parameter-free O(1) per-operation amortized instruction charge 313 * opFactor + 284725 (independent of U, V, w, n_max, base, and operation-sequence length).

Per-operation amortized instruction charge (chargeVal for every operation).

Standalone register encoding for Dynamic.Op U:

Partial argument-matching predicate for inline callers.

Output decoder reading Option ℕ from (resTagReg, resValReg) for .query and () for .insert/.delete.

Section 5: Memory footprint congruence lemmas for TableRep, SeedRep, DictStateInv #

theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.bucketStateInv_congr {U V w n_max h_space base : ℕ} (hw : 0 < w) {mOf : ℕ → ℕ} {L : ℕ → ℕ → List ℕ} {B : ℕ → ℕ → Option ℕ} {s₁ s₂ : Memory.State} (heq : ∀ (a : ℕ), base + h_space ≤ a → a < base + totalSpace U V w n_max h_space → s₁.mem a = s₂.mem a) (hinv : BucketStateInv U V w n_max h_space base mOf L B s₁) :
BucketStateInv U V w n_max h_space base mOf L B s₂
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.dictStateInv_congr {U V w n_max base : ℕ} (hw : 0 < w) {θ : QuotHashSeed U n_max} {s_abs : State U} {s₁ s₂ : Memory.State} (heq : ∀ (a : ℕ), base + hashSpace U w n_max ≤ a → a < base + space U V w n_max → s₁.mem a = s₂.mem a) (hinv : DictStateInv U V w n_max base θ s_abs s₁) :
DictStateInv U V w n_max base θ s_abs s₂
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.modifies_footprint_of_table {U V w n_max base : ℕ} {mem₁ mem₂ : ℕ → ℕ} (hout : ∀ (a : ℕ), ¬(base + offQuot (hashSpace U w n_max) ≤ a ∧ a < base + space U V w n_max) → mem₂ a = mem₁ a) :
WordRAM.Modifies { base := base, length := space U V w n_max }.footprint mem₁ mem₂

Section 6: loadParamsCode and common prefix execution helpers #

theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.fits_mkDictParams {U V w n_max base : ℕ} (hwf : DictParamsWf U V w n_max) (hV_fit : WordRAM.Fits w V) (hfit : WordRAM.Fits w (base + space U V w n_max)) (i : Fin 36) :
WordRAM.Fits w (mkDictParams U V w n_max (hashSpace U w n_max) i)

Every entry of mkDictParams U V w n_max (hashSpace U w n_max) fits in a w-bit word under DictParamsWf U V w n_max, Fits w V, and Fits w (base + space U V w n_max).

Section 7: Per-operation deterministic execution of opCode #

Extract the target key u : Fin U of a dynamic dictionary operation o : Dynamic.Op U.

theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.exec_opCode {U V w n_max base : ℕ} (hwf : DictParamsWf U V w n_max) (hV_fit : WordRAM.Fits w V) (hfit : WordRAM.Fits w (base + space U V w n_max)) (θ : QuotHashSeed U n_max) (s_abs : State U) (o : Dynamic.Op U) (hval : (Dynamic.spec U V n_max).valid s_abs o) {x : WordRAM.Data rSuccinct} (hrep : Rep U V w n_max base θ s_abs x) (harg : argMatch o x.regs) :
∃ (y : WordRAM.Data rSuccinct) (steps : ℕ), WordRAM.ExecWithin w (opCode U V w n_max) x y steps ∧ decode o y.regs = some ((Dynamic.spec U V n_max).stepFn s_abs o).2 ∧ Rep U V w n_max base θ ((Dynamic.spec U V n_max).stepFn s_abs o).1 y ∧ WordRAM.Modifies { base := base, length := space U V w n_max }.footprint x.mem y.mem ∧ steps + potential U V w n_max base θ y ≤ potential U V w n_max base θ x + (273 * opFactor + 284725) + 8 * opFactor * SuccinctBucket.probeExcess n_max (qStage1 U n_max θ.1) (polyStage2 U n_max) θ.2 (dom s_abs) (opKey o)

Unified per-operation deterministic execution of opCode for any o : Dynamic.Op U.