Documentation

CslibFrontier.DataStructure.Dictionary.WordRAM.SuccinctProg

Memory.Prog Dictionary Array Accessors and Slot Resolution via realize #

This module builds on the shared Memory.Prog bit-packed array primitives (readPackedProg, writePackedProg, realizes_readPackedGen, realizes_writePackedGen in CslibFrontier.DataStructure.Dictionary.WordRAM.BitPackedArrayProg) to wrap the four dictionary arrays (Quotients, Values, LocalMeta, GlobalMeta) as Memory.Prog operations with uniform Realizes .exact certificates, and realizes readBucketCountProg and resolveIndexedSlotProg via the realize tactic.

Main definitions #

Main results #

Memory charges of p >>= k when p leaves the state unchanged (for example, a run of reads): the continuation is charged from the same state. Unlike memoryCost_bind, this is stated for >>=, the form do blocks elaborate to, so it rewrites them directly.

Section 1: Dictionary array Memory.Prog primitives (Quot, Val, LM, GM) #

Runtime register block of 36 precomputed dictionary layout parameters.

Instances For

    Construct the 36-word parameter vector for (U, V, w, n_max, h_space).

    Quotient array word offset offQuot h_space in DictParams.

    Quotient bit width quotientBits U n_max in DictParams.

    Value array word offset offVal U w n_max h_space in DictParams.

    Sub-array word offset offLMSub U V w n_max h_space c in DictParams.

    Local metadata bit width effBucketPosBits n_max in DictParams.

    Global metadata word offset offGM U V w n_max h_space in DictParams.

    Global metadata pointer bit width globalPtrBits n_max in DictParams.

    Per-bucket slab directory size dirSlabsPerBucket n_max in DictParams.

    Per-bucket tail capacity tailCapPerBucket n_max in DictParams.

    Slab directory base index gmSlabDirBase n_max in DictParams.

    Tail pointer base index gmTailPtrBase n_max in DictParams.

    Slab metadata base index gmSlabMetaBase n_max in DictParams.

    Micro-buckets per bucket numMicroPerBucket n_max in DictParams.

    Effective per-bucket slot cap min n_max (effBucketCap n_max) in DictParams.

    @[simp]
    theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.p_w_mk (U V w n_max h_space : ℕ) :
    dpW (mkDictParams U V w n_max h_space) = w
    @[simp]
    theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.p_nMax_mk (U V w n_max h_space : ℕ) :
    dpNMax (mkDictParams U V w n_max h_space) = n_max
    @[simp]
    theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.p_nMaxSubOne_mk (U V w n_max h_space : ℕ) :
    dpNMaxSubOne (mkDictParams U V w n_max h_space) = n_max - 1
    @[simp]
    theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.p_offQuot_mk (U V w n_max h_space : ℕ) :
    dpOffQuot (mkDictParams U V w n_max h_space) = offQuot h_space
    @[simp]
    theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.p_offVal_mk (U V w n_max h_space : ℕ) :
    dpOffVal (mkDictParams U V w n_max h_space) = offVal U w n_max h_space
    @[simp]
    theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.p_offGM_mk (U V w n_max h_space : ℕ) :
    dpOffGM (mkDictParams U V w n_max h_space) = offGM U V w n_max h_space
    @[simp]
    @[simp]
    theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.p_U_mk (U V w n_max h_space : ℕ) :
    dpU (mkDictParams U V w n_max h_space) = U
    @[simp]
    theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.p_V_mk (U V w n_max h_space : ℕ) :
    dpV (mkDictParams U V w n_max h_space) = V
    @[simp]
    theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.p_hSpace_mk (U V w n_max h_space : ℕ) :
    dpHSpace (mkDictParams U V w n_max h_space) = h_space
    @[simp]
    theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.p_offLMSub_mk (U V w n_max h_space : ℕ) (c : Fin 9) :
    dpOffLMSub c (mkDictParams U V w n_max h_space) = offLMSub U V w n_max h_space ↑c

    Common entry envelope for dictionary Memory.Prog operations at base.

    Combined runtime parameter and memory envelope for parameter-free Realizes certificates.

    @[reducible, inline]

    Base address d.2.1 in a parameter-free dictionary read/bucket input (dp, (base, idx)).

    @[reducible, inline]

    Slot, entry, or bucket index d.2.2 in a parameter-free dictionary read/bucket input (dp, (base, idx)).

    @[reducible, inline]

    Base address d.2.1.1 in a parameter-free dictionary write/slot input (dp, ((base, idx), val)).

    @[reducible, inline]

    Primary slot or bucket index d.2.1.2 in a parameter-free dictionary write/slot input (dp, ((base, idx), val)).

    @[reducible, inline]

    Trailing value or local slot index d.2.2 in a parameter-free dictionary write/slot input (dp, ((base, idx), val)).

    @[reducible, inline]

    Base address d.1.1 of a left-nested dictionary input ((base, idx), extra).

    @[reducible, inline]

    Primary index d.1.2 (bucket or slab index) of a left-nested dictionary input ((base, idx), extra).

    Parameter-free Memory.Prog operation reading Quotients[dictReadIdx d] at base = dictReadBase d.

    Read Quotients[d.2] at base = d.1 in Memory.Prog.

    @[simp]
    theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.readQuotGenProg_mk (U V w n_max h_space : ℕ) (d : ℕ × ℕ) :
    readQuotGenProg (mkDictParams U V w n_max h_space, d) = readQuotProg U w n_max h_space d

    Parameter-free Memory.Prog operation writing dictWriteVal d to Quotients[dictWriteIdx d] at base = dictWriteBase d.

    Write val to Quotients[idx] at base in Memory.Prog.

    @[simp]
    theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.writeQuotGenProg_mk (U V w n_max h_space : ℕ) (d : (ℕ × ℕ) × ℕ) :
    writeQuotGenProg (mkDictParams U V w n_max h_space, d) = writeQuotProg U w n_max h_space d

    Parameter-free Memory.Prog operation reading Values[dictReadIdx d] at base = dictReadBase d.

    Read Values[d.2] at base = d.1 in Memory.Prog.

    @[simp]
    theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.readValGenProg_mk (U V w n_max h_space : ℕ) (d : ℕ × ℕ) :
    readValGenProg (mkDictParams U V w n_max h_space, d) = readValProg U V w n_max h_space d

    Parameter-free Memory.Prog operation writing dictWriteVal d to Values[dictWriteIdx d] at base = dictWriteBase d.

    Write val to Values[idx] at base in Memory.Prog.

    @[simp]
    theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.writeValGenProg_mk (U V w n_max h_space : ℕ) (d : (ℕ × ℕ) × ℕ) :
    writeValGenProg (mkDictParams U V w n_max h_space, d) = writeValProg U V w n_max h_space d

    Parameter-free Memory.Prog operation reading LocalMeta[c, dictReadIdx d] at base = dictReadBase d.

    Read LocalMeta[c, d.2] at base = d.1 in Memory.Prog.

    @[simp]
    theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.readLMGenProg_mk (U V w n_max h_space : ℕ) (c : Fin 9) (d : ℕ × ℕ) :
    readLMGenProg c (mkDictParams U V w n_max h_space, d) = readLMProg U V w n_max h_space (↑c) d

    Parameter-free Memory.Prog operation writing dictWriteVal d to LocalMeta[c, dictWriteIdx d] at base = dictWriteBase d.

    Write val to LocalMeta[c, idx] at base in Memory.Prog.

    @[simp]
    theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.writeLMGenProg_mk (U V w n_max h_space : ℕ) (c : Fin 9) (d : (ℕ × ℕ) × ℕ) :
    writeLMGenProg c (mkDictParams U V w n_max h_space, d) = writeLMProg U V w n_max h_space (↑c) d

    Parameter-free Memory.Prog operation reading GlobalMeta[dictReadIdx d] at base = dictReadBase d.

    Read GlobalMeta[d.2] at base = d.1 in Memory.Prog.

    @[simp]
    theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.readGMGenProg_mk (U V w n_max h_space : ℕ) (d : ℕ × ℕ) :
    readGMGenProg (mkDictParams U V w n_max h_space, d) = readGMProg U V w n_max h_space d

    Parameter-free Memory.Prog operation writing dictWriteVal d to GlobalMeta[dictWriteIdx d] at base = dictWriteBase d.

    Write val to GlobalMeta[idx] at base in Memory.Prog.

    @[simp]
    theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.writeGMGenProg_mk (U V w n_max h_space : ℕ) (d : (ℕ × ℕ) × ℕ) :
    writeGMGenProg (mkDictParams U V w n_max h_space, d) = writeGMProg U V w n_max h_space d

    Parameter-free Memory.Prog operation reading bCount (d = (dp, (base, b))).

    Memory.Prog operation reading bCount n_max gm b (d = (base, b)).

    @[simp]

    Parameter-free Memory.Prog operation resolving indexed local slot j = dictWriteVal d of bucket b = dictWriteIdx d at base = dictWriteBase d.

    Memory.Prog operation resolving indexed local slot j = d.2 < effBucketCap n_max of bucket b = dictArgIdx d at base = dictArgBase d to physical slot slotOf n_max gm b j < n_max.

    Helper tactic that simplifies all DictParams field accessors and primitive Memory.Prog projections after dp = mkDictParams U V w₀ n_max h_space has been substituted.

    Helper tactic for parameter-free Realizes proofs over DictParams × D with extra simplification lemmas for sub-programs and preconditions. Optional using [certificates] forwards method certificates to realize.

    Helper tactic for parameter-free Realizes proofs over DictParams × D: runs realize and unpacks d = (dp, d) and DictEnvGen (h.1) in every resulting goal. Optional using [certificates] supplies local method certificates.

    theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.clientResult_readGMProg {U V w n_max h_space base idx : ℕ} (s : Memory.State) (hidx : idx < SuccinctBucket.globalMetaLen n_max) :
    (Memory.spec 0).clientResult s (readGMProg U V w n_max h_space (base, idx)) = gmAt base U V w n_max h_space s.mem idx
    theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.fits_const_of_dictEnv {U V w₀ n_max h_space w base c : ℕ} (h : DictEnvGen w (mkDictParams U V w₀ n_max h_space) base) (hc : c ≤ 24) :
    theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.fits_of_le_globalMetaLen {U V w₀ n_max h_space w base x : ℕ} (h : DictEnvGen w (mkDictParams U V w₀ n_max h_space) base) (hb_pos : 0 < FeistelQuotient.bucketBits n_max) (hw : 0 < w₀) (hnU : n_max ≤ U) (hU : U < 2 ^ w₀) (hx : x ≤ SuccinctBucket.globalMetaLen n_max) :
    theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.fits_of_le_max_n_one {U V w₀ n_max h_space w base x : ℕ} (h : DictEnvGen w (mkDictParams U V w₀ n_max h_space) base) (hw : 0 < w₀) (hnU : n_max ≤ U) (hU : U < 2 ^ w₀) (hx : x ≤ max n_max 1) :

    Closes a routine side goal left by realizeDict/realizeDictWith over GlobalMeta: the entry envelope or an index bound from the context (possibly under the branch condition), or a Fits goal for a small constant, a GlobalMeta index or a value at most n_max. It uses the names hw, hnU and hU that realizeDict binds, and matches hypotheses only up to reducible unfolding, so that it never evaluates the programs inside clientResult.

    Section 3: readBucketCountProg and resolveIndexedSlotProg via realize #

    theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.clientResult_readBucketCountProg {U V w n_max h_space : ℕ} (d : ℕ × ℕ) (s : Memory.State) (hb : d.2 < FeistelQuotient.numBuckets n_max) :
    (Memory.spec 0).clientResult s (readBucketCountProg U V w n_max h_space d) = bCount n_max (gmAt d.1 U V w n_max h_space s.mem) d.2
    theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.clientResult_resolveIndexedSlotProg {U V w n_max h_space : ℕ} (d : (ℕ × ℕ) × ℕ) (s : Memory.State) (hinv : SlotStoreInv n_max (gmAt (dictArgBase d) U V w n_max h_space s.mem)) (hb : dictArgIdx d < FeistelQuotient.numBuckets n_max) (hj_bc : d.2 < bCount n_max (gmAt (dictArgBase d) U V w n_max h_space s.mem) (dictArgIdx d)) (hj_cap : d.2 < SuccinctBucket.effBucketCap n_max) :
    (Memory.spec 0).clientResult s (resolveIndexedSlotProg U V w n_max h_space d) = slotOf n_max (gmAt (dictArgBase d) U V w n_max h_space s.mem) (dictArgIdx d) d.2

    Section 4: Pure state effects and costs of read*Prog and write*Prog #

    theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.clientState_readLMProg (U V w n_max h_space c : ℕ) (d : ℕ × ℕ) (s : Memory.State) :
    (Memory.spec 0).clientState s (readLMProg U V w n_max h_space c d) = s
    theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.clientResult_readQuotProg {U w n_max h_space base idx : ℕ} (s : Memory.State) (hidx : idx < n_max) :
    (Memory.spec 0).clientResult s (readQuotProg U w n_max h_space (base, idx)) = quotAt base U w n_max h_space s.mem idx
    theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.clientResult_readValProg {U V w n_max h_space base idx : ℕ} (s : Memory.State) (hidx : idx < n_max) :
    (Memory.spec 0).clientResult s (readValProg U V w n_max h_space (base, idx)) = valAt base U V w n_max h_space s.mem idx
    theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.clientResult_readLMProg {U V w n_max h_space c base idx : ℕ} (s : Memory.State) (hc : c < 9) (hidx : idx < SuccinctBucket.totalMicroBuckets n_max) :
    (Memory.spec 0).clientResult s (readLMProg U V w n_max h_space c (base, idx)) = lmAt base U V w n_max h_space s.mem (c, idx)
    theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.writeQuotProg_effect {U V w n_max h_space base idx val : ℕ} (hw : 0 < w) (hidx_lt : idx < n_max) (hval_lt : val < 2 ^ FeistelQuotient.quotientBits U n_max) (s : Memory.State) :
    have s' := (Memory.spec 0).clientState s (writeQuotProg U w n_max h_space ((base, idx), val)); s'.frontier = s.frontier ∧ (∀ (a : ℕ), ¬(base + offQuot h_space ≤ a ∧ a < base + offVal U w n_max h_space) → s'.mem a = s.mem a) ∧ quotAt base U w n_max h_space s'.mem = Function.update (quotAt base U w n_max h_space s.mem) idx val ∧ valAt base U V w n_max h_space s'.mem = valAt base U V w n_max h_space s.mem ∧ lmAt base U V w n_max h_space s'.mem = lmAt base U V w n_max h_space s.mem ∧ gmAt base U V w n_max h_space s'.mem = gmAt base U V w n_max h_space s.mem

    Pure state effect of writeQuotProg.

    theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.writeValProg_effect {U V w n_max h_space base idx val : ℕ} (hw : 0 < w) (hidx_lt : idx < n_max) (hval_lt : val < 2 ^ FeistelQuotient.valBits V) (s : Memory.State) :
    have s' := (Memory.spec 0).clientState s (writeValProg U V w n_max h_space ((base, idx), val)); s'.frontier = s.frontier ∧ (∀ (a : ℕ), ¬(base + offVal U w n_max h_space ≤ a ∧ a < base + offLM U V w n_max h_space) → s'.mem a = s.mem a) ∧ quotAt base U w n_max h_space s'.mem = quotAt base U w n_max h_space s.mem ∧ valAt base U V w n_max h_space s'.mem = Function.update (valAt base U V w n_max h_space s.mem) idx val ∧ lmAt base U V w n_max h_space s'.mem = lmAt base U V w n_max h_space s.mem ∧ gmAt base U V w n_max h_space s'.mem = gmAt base U V w n_max h_space s.mem

    Pure state effect of writeValProg.

    theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.writeLMProg_effect {U V w n_max h_space c base idx val : ℕ} (hw : 0 < w) (hc : c < 9) (hidx_lt : idx < SuccinctBucket.totalMicroBuckets n_max) (hval_lt : val < 2 ^ SuccinctBucket.effBucketPosBits n_max) (s : Memory.State) :
    have s' := (Memory.spec 0).clientState s (writeLMProg U V w n_max h_space c ((base, idx), val)); s'.frontier = s.frontier ∧ (∀ (a : ℕ), ¬(base + offLM U V w n_max h_space ≤ a ∧ a < base + offGM U V w n_max h_space) → s'.mem a = s.mem a) ∧ quotAt base U w n_max h_space s'.mem = quotAt base U w n_max h_space s.mem ∧ valAt base U V w n_max h_space s'.mem = valAt base U V w n_max h_space s.mem ∧ lmAt base U V w n_max h_space s'.mem = Function.update (lmAt base U V w n_max h_space s.mem) (c, idx) val ∧ gmAt base U V w n_max h_space s'.mem = gmAt base U V w n_max h_space s.mem

    Pure state effect of writeLMProg.

    Section 5: GlobalMeta-only frames #

    structure Cslib.DataStructure.Dictionary.WordRAM.Succinct.GmFrame (U V w n_max h_space base : ℕ) (s s' : Memory.State) :

    Frame of a run that writes only the GlobalMeta region of the dictionary at base: the frontier and all memory outside [base + offGM U V w n_max h_space, base + totalSpace U V w n_max h_space) are unchanged. GmFrame.trans chains the frames of consecutive writes, and GmFrame.effect turns a frame and the resulting gmAt into the six-part form of the GlobalMeta operations' _effect theorems.

    theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.GmFrame.refl {U V w n_max h_space base : ℕ} (s : Memory.State) :
    GmFrame U V w n_max h_space base s s
    theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.GmFrame.trans {U V w n_max h_space base : ℕ} {s s₁ s₂ : Memory.State} (h₁ : GmFrame U V w n_max h_space base s s₁) (h₂ : GmFrame U V w n_max h_space base s₁ s₂) :
    GmFrame U V w n_max h_space base s s₂
    theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.GmFrame.quotAt_eq {U V w n_max h_space base : ℕ} {s s₁ : Memory.State} (hw : 0 < w) (h : GmFrame U V w n_max h_space base s s₁) :
    quotAt base U w n_max h_space s₁.mem = quotAt base U w n_max h_space s.mem
    theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.GmFrame.valAt_eq {U V w n_max h_space base : ℕ} {s s₁ : Memory.State} (hw : 0 < w) (h : GmFrame U V w n_max h_space base s s₁) :
    valAt base U V w n_max h_space s₁.mem = valAt base U V w n_max h_space s.mem
    theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.GmFrame.lmAt_eq {U V w n_max h_space base : ℕ} {s s₁ : Memory.State} (hw : 0 < w) (h : GmFrame U V w n_max h_space base s s₁) :
    lmAt base U V w n_max h_space s₁.mem = lmAt base U V w n_max h_space s.mem
    theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.GmFrame.effect {U V w n_max h_space base : ℕ} {s s₁ : Memory.State} (hw : 0 < w) (h : GmFrame U V w n_max h_space base s s₁) {g : ℕ → ℕ} (hg : gmAt base U V w n_max h_space s₁.mem = g) :
    s₁.frontier = s.frontier ∧ (∀ (a : ℕ), ¬(base + offGM U V w n_max h_space ≤ a ∧ a < base + totalSpace U V w n_max h_space) → s₁.mem a = s.mem a) ∧ quotAt base U w n_max h_space s₁.mem = quotAt base U w n_max h_space s.mem ∧ valAt base U V w n_max h_space s₁.mem = valAt base U V w n_max h_space s.mem ∧ lmAt base U V w n_max h_space s₁.mem = lmAt base U V w n_max h_space s.mem ∧ gmAt base U V w n_max h_space s₁.mem = g

    The six-part effect of a GlobalMeta-only run with resulting GlobalMeta contents g.

    theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.gmFrame_writeGMProg {U V w n_max h_space base idx val : ℕ} (hw : 0 < w) (hidx : idx < SuccinctBucket.globalMetaLen n_max) (s : Memory.State) :
    GmFrame U V w n_max h_space base s ((Memory.spec 0).clientState s (writeGMProg U V w n_max h_space ((base, idx), val)))
    theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.gmAt_writeGMProg {U V w n_max h_space base idx val : ℕ} (hw : 0 < w) (hidx : idx < SuccinctBucket.globalMetaLen n_max) (hval : val < 2 ^ SuccinctBucket.globalPtrBits n_max) (s : Memory.State) :
    gmAt base U V w n_max h_space ((Memory.spec 0).clientState s (writeGMProg U V w n_max h_space ((base, idx), val))).mem = Function.update (gmAt base U V w n_max h_space s.mem) idx val
    theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.writeGMProg_effect {U V w n_max h_space base idx val : ℕ} (hw : 0 < w) (hidx_lt : idx < SuccinctBucket.globalMetaLen n_max) (hval_lt : val < 2 ^ SuccinctBucket.globalPtrBits n_max) (s : Memory.State) :
    have s' := (Memory.spec 0).clientState s (writeGMProg U V w n_max h_space ((base, idx), val)); s'.frontier = s.frontier ∧ (∀ (a : ℕ), ¬(base + offGM U V w n_max h_space ≤ a ∧ a < base + totalSpace U V w n_max h_space) → s'.mem a = s.mem a) ∧ quotAt base U w n_max h_space s'.mem = quotAt base U w n_max h_space s.mem ∧ valAt base U V w n_max h_space s'.mem = valAt base U V w n_max h_space s.mem ∧ lmAt base U V w n_max h_space s'.mem = lmAt base U V w n_max h_space s.mem ∧ gmAt base U V w n_max h_space s'.mem = Function.update (gmAt base U V w n_max h_space s.mem) idx val

    Pure state effect of writeGMProg.