Documentation

CslibFrontier.DataStructure.Dictionary.WordRAM.SuccinctBucketOps

Bucket-Level Dictionary Lookup and Insertion (query, insert) in Memory.Prog #

This module defines the bucket-level representation invariant BucketStateInv and realizes the bucket-level lookup and insertion operations of the fixed-capacity succinct dictionary in Memory.Prog via realize:

Main definitions #

Main results #

Section 1: BucketStateInv and queryBodyProg_bucket_spec #

structure Cslib.DataStructure.Dictionary.WordRAM.Succinct.BucketStateInv (U V w₀ n_max h_space base : ℕ) (mOf : ℕ → ℕ) (L : ℕ → ℕ → List ℕ) (B : ℕ → ℕ → Option ℕ) (s : Memory.State) :

Combined bucket-level state invariant at base with local micro-bucket mapping mOf : ℕ → ℕ, per-bucket micro-chain lists L : ℕ → ℕ → List ℕ, and abstract per-bucket quotient-to-value map B : ℕ → ℕ → Option ℕ.

theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.bucketStateInv_of_zero {U V w₀ n_max h_space base : ℕ} (mOf : ℕ → ℕ) {s : Memory.State} (hgm0 : ∀ (i : ℕ), gmAt base U V w₀ n_max h_space s.mem i = 0) (hlm0 : ∀ (p : ℕ × ℕ), lmAt base U V w₀ n_max h_space s.mem p = 0) :
BucketStateInv U V w₀ n_max h_space base mOf (fun (x x_1 : ℕ) => []) (fun (x x_1 : ℕ) => none) s ∧ totalSlots n_max (gmAt base U V w₀ n_max h_space s.mem) = 0 ∧ slotPotential n_max (gmAt base U V w₀ n_max h_space s.mem) = 0

An all-zero dictionary memory region satisfies BucketStateInv with empty chains and empty bucket maps.

theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.BucketStateInv.searchMicroChainPre {U V w₀ n_max h_space w base b q_target m : ℕ} {mOf : ℕ → ℕ} {L : ℕ → ℕ → List ℕ} {B : ℕ → ℕ → Option ℕ} {s : Memory.State} (hinv : BucketStateInv U V w₀ n_max h_space base mOf L B s) (henv : DictEnvGen w (mkDictParams U V w₀ n_max h_space) base) (hb : b < FeistelQuotient.numBuckets n_max) (hm : m < SuccinctBucket.numMicroPerBucket n_max) :
SearchMicroChainPre U V w₀ n_max h_space w (((base, b), q_target), m) s

BucketStateInv implies SearchMicroChainPre for any valid (b, q_target, m).

theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.searchBucket_exists_iff {U V w₀ n_max h_space base b q_target m : ℕ} {mOf : ℕ → ℕ} {L : ℕ → ℕ → List ℕ} {B : ℕ → ℕ → Option ℕ} {s : Memory.State} (hinv : BucketStateInv U V w₀ n_max h_space base mOf L B s) (hb : b < FeistelQuotient.numBuckets n_max) (hm_eq : m = mOf q_target) (hm_lt : m < SuccinctBucket.numMicroPerBucket n_max) :
have gm := gmAt base U V w₀ n_max h_space s.mem; ((∃ j ∈ L b m, quotAt base U w₀ n_max h_space s.mem (slotOf n_max gm b j) = q_target) ∨ ∃ (j : ℕ), SuccinctBucket.effBucketCap n_max ≤ j ∧ j < bCount n_max gm b ∧ quotAt base U w₀ n_max h_space s.mem (slotOf n_max gm b j) = q_target) ↔ ∃ j < bCount n_max gm b, quotAt base U w₀ n_max h_space s.mem (slotOf n_max gm b j) = q_target

Under BucketStateInv and m = mOf q_target < numMicroPerBucket n_max, the two-phase search condition in searchBucketProg_spec is equivalent to ∃ j < bCount b, quotAt (slotOf b j) = q_target.

@[reducible, inline]

Found flag (1 if present, 0 if absent) in a searchBucketProg result ((found, j_found), phys).

@[reducible, inline]

Bucket-local slot index j_found in a searchBucketProg result ((found, j_found), phys).

theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.searchBucketProg_bucket_spec {U V w₀ n_max h_space w base b q_target m : ℕ} {mOf : ℕ → ℕ} {L : ℕ → ℕ → List ℕ} {B : ℕ → ℕ → Option ℕ} {s : Memory.State} (hinv : BucketStateInv U V w₀ n_max h_space base mOf L B s) (henv : DictEnvGen w (mkDictParams U V w₀ n_max h_space) base) (hb : b < FeistelQuotient.numBuckets n_max) (hm_eq : m = mOf q_target) (hm_lt : m < SuccinctBucket.numMicroPerBucket n_max) :
have gm := gmAt base U V w₀ n_max h_space s.mem; have d := (((base, b), q_target), m); have prog := searchBucketProg U V w₀ n_max h_space d; (Memory.spec 0).clientState s prog = s ∧ WordRAM.Realization.memoryCost prog s ≤ 10 + 8 * (L b m).length + 6 * (bCount n_max gm b - SuccinctBucket.effBucketCap n_max) ∧ have res := (Memory.spec 0).clientResult s prog; if ∃ j < bCount n_max gm b, quotAt base U w₀ n_max h_space s.mem (slotOf n_max gm b j) = q_target then searchResFound res = 1 ∧ searchResIdx res < bCount n_max gm b ∧ quotAt base U w₀ n_max h_space s.mem (slotOf n_max gm b (searchResIdx res)) = q_target ∧ res.2 = slotOf n_max gm b (searchResIdx res) else searchResFound res = 0

Specification of searchBucketProg under BucketStateInv when m = mOf q_target.

theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.queryBodyProg_bucket_spec {U V w₀ n_max h_space w base b q_target m : ℕ} {mOf : ℕ → ℕ} {L : ℕ → ℕ → List ℕ} {B : ℕ → ℕ → Option ℕ} {s : Memory.State} (hinv : BucketStateInv U V w₀ n_max h_space base mOf L B s) (henv : DictEnvGen w (mkDictParams U V w₀ n_max h_space) base) (hb : b < FeistelQuotient.numBuckets n_max) (hm_eq : m = mOf q_target) (hm_lt : m < SuccinctBucket.numMicroPerBucket n_max) :
have gm := gmAt base U V w₀ n_max h_space s.mem; have d := (((base, b), q_target), m); have prog := queryBodyProg U V w₀ n_max h_space d; (Memory.spec 0).clientState s prog = s ∧ WordRAM.Realization.memoryCost prog s ≤ 12 + 8 * (L b m).length + 6 * (bCount n_max gm b - SuccinctBucket.effBucketCap n_max) ∧ (Memory.spec 0).clientResult s prog = B b q_target

Specification of queryBodyProg under BucketStateInv when m = mOf q_target: returns B b q_target without modifying memory.

Section 2: insertBodyProg via realize #

@[reducible, inline]

Base address d.1.1.1 of a bucket-level dictionary call (((base, b), x), y).

@[reducible, inline]

Bucket index d.1.1.2 of a bucket-level dictionary call (((base, b), x), y).

@[reducible, inline]

Base-and-bucket pair (base, b) of a bucket-level dictionary call (((base, b), x), y).

@[reducible, inline]

Base address d.1.1.1.1 of a nested bucket-level call ((((base, b), x), y), z).

@[reducible, inline]

Bucket index d.1.1.1.2 of a nested bucket-level call ((((base, b), x), y), z).

@[reducible, inline]

Base-and-bucket pair (base, b) of a nested bucket-level call ((((base, b), x), y), z).

@[reducible, inline]

Target quotient q_target in an insertion input ((((base, b), q_target), v_new), m).

@[reducible, inline]

Query prefix ((base, b), q_target) in an insertion input ((((base, b), q_target), v_new), m).

@[reducible, inline]

Inserted value v_new in an insertion input ((((base, b), q_target), v_new), m).

@[reducible, inline]

Micro-bucket index m in an insertion input ((((base, b), q_target), v_new), m).

Parameter-free helper Memory.Prog appending a new (q_target, v_new) entry to bucket b and prepending its logical index j_new = bCount b to micro-chain (b, m) when totalSlots < n_max. Input d = (dp, ((((base, b), q_target), v_new), m)).

Helper Memory.Prog appending a new (q_target, v_new) entry to bucket b and prepending its logical index j_new = bCount b to micro-chain (b, m) when totalSlots < n_max. Input d = ((((base, b), q_target), v_new), m).

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

Precondition for insertNewProg in Realizes.

@[simp]
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.insertNewGenPre_mk (U V w₀ n_max h_space w : ℕ) (d : (((ℕ × ℕ) × ℕ) × ℕ) × ℕ) (s : Memory.State) :
InsertNewGenPre w (mkDictParams U V w₀ n_max h_space, d) s ↔ InsertNewPre U V w₀ n_max h_space w d s

Parameter-free dictionary insert body insertBodyGenProg (d = (dp, ((((base, b), q_target), v_new), m))).

Dictionary insert body insertBodyProg (d = ((((base, b), q_target), v_new), m)): searches bucket b for q_target via searchBucketProg; if found, overwrites valAt in-place; otherwise calls insertNewProg.

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

Precondition for insertBodyProg in Realizes.

@[simp]
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.insertBodyGenPre_mk (U V w₀ n_max h_space w : ℕ) (d : (((ℕ × ℕ) × ℕ) × ℕ) × ℕ) (s : Memory.State) :
InsertBodyGenPre w (mkDictParams U V w₀ n_max h_space, d) s ↔ InsertBodyPre U V w₀ n_max h_space w d s
theorem Cslib.DataStructure.Dictionary.WordRAM.Succinct.insertBodyProg_bucket_spec {U V w₀ n_max h_space w base b q_target v_new m : ℕ} {mOf : ℕ → ℕ} {L : ℕ → ℕ → List ℕ} {B : ℕ → ℕ → Option ℕ} {s : Memory.State} (hw : 0 < w₀) (hinv : BucketStateInv U V w₀ n_max h_space base mOf L B s) (henv : DictEnvGen w (mkDictParams U V w₀ n_max h_space) base) (hb : b < FeistelQuotient.numBuckets n_max) (hm_eq : m = mOf q_target) (hm_lt : m < SuccinctBucket.numMicroPerBucket n_max) (hq_lt : q_target < 2 ^ FeistelQuotient.quotientBits U n_max) (hv_lt : v_new < 2 ^ FeistelQuotient.valBits V) (hcap : (B b q_target).isSome = true ∨ totalSlots n_max (gmAt base U V w₀ n_max h_space s.mem) < n_max) :
have gm₀ := gmAt base U V w₀ n_max h_space s.mem; have d := ((((base, b), q_target), v_new), m); have s' := (Memory.spec 0).clientState s (insertBodyProg U V w₀ n_max h_space d); have gm' := gmAt base U V w₀ n_max h_space s'.mem; have B' := Function.update B b (Function.update (B b) q_target (some v_new)); s'.frontier = s.frontier ∧ (∀ (a : ℕ), ¬(base + offQuot h_space ≤ a ∧ a < base + totalSpace U V w₀ n_max h_space) → s'.mem a = s.mem a) ∧ (∃ (L' : ℕ → ℕ → List ℕ), BucketStateInv U V w₀ n_max h_space base mOf L' B' s') ∧ (totalSlots n_max gm' = if (B b q_target).isSome = true then totalSlots n_max gm₀ else totalSlots n_max gm₀ + 1) ∧ WordRAM.Realization.memoryCost (insertBodyProg U V w₀ n_max h_space d) s + 66 * slotPotential n_max gm' ≤ 66 * slotPotential n_max gm₀ + 170 + 8 * (L b m).length + 6 * (bCount n_max gm₀ b - SuccinctBucket.effBucketCap n_max)

Pure state effect, BucketStateInv preservation, and amortized memoryCost bound of insertBodyProg when m = mOf q_target and (B b q_target).isSome ∨ totalSlots < n_max.