Documentation

CslibFrontier.DataStructure.Dictionary.WordRAM.SuccinctWhpTickHealProg.PoolLocSlices

Pool Ownership, Free-Stack, locState, and Slice-Reset Loops for csrToFastGenProg #

This internal module implements Phases D1, D2, D3, and E1 of csrToFastGenProg:

Main definitions #

Main results #

Phase D1: fillPoolOwnerLoopProg (populate offPoolOwner[poolIdx]) #

theorem Cslib.DataStructure.Dictionary.WordRAM.SuccinctWhp.fillPoolOwnerLoop_safe {c U V w n_max base totalBack : ℕ} (henv : WhpLargeEnv c U V w n_max w base) :
have rt := mkHealRt c U V w n_max base; ∀ (rem p₀ : ℕ) (s : Memory.State), p₀ + rem ≤ SuccinctWhp.poolSizeWhp n_max → WordRAM.Realization.iterationSafe fillPoolOwnerStepProg FillPoolOwnerPre w (rt, totalBack) rem p₀ s

Loop-safety invariant for fillPoolOwnerLoopProg.

theorem Cslib.DataStructure.Dictionary.WordRAM.SuccinctWhp.fillPoolOwnerLoop_spec {c U V w n_max base : ℕ} {fbStart : ℕ → ℕ} {s₀ : Memory.State} (henv : WhpLargeEnv c U V w n_max w base) (hback_cb : ∀ b < SuccinctWhp.numBucketsWhp n_max, fbStart (b + 1) - fbStart b - SuccinctWhp.capFrontWhp n_max < SuccinctWhp.capBackWhp n_max) (hbp_mem : ∀ x ≤ SuccinctWhp.numBucketsWhp n_max, BitPackedArray.readPacked (base + offBktMeta c U V w n_max) (SuccinctBucket.globalPtrBits n_max) w s₀.mem (2 * x) = SuccinctWhp.buildBackPrefix (SuccinctWhp.numBucketsWhp n_max) (SuccinctWhp.capFrontWhp n_max) fbStart x) :
have rt := mkHealRt c U V w n_max base; have M := SuccinctWhp.numBucketsWhp n_max; have cf := SuccinctWhp.capFrontWhp n_max; have cb := SuccinctWhp.capBackWhp n_max; have bp := SuccinctWhp.buildBackPrefix M cf fbStart; have findOwner := fun (poolIdx : ℕ) => have b := SuccinctWhp.csrBucketOfIdx bp poolIdx M; have k := poolIdx - bp b; if poolIdx < bp M then b * cb + k else 0; ∀ (rem p₀ : ℕ) (s : Memory.State), p₀ + rem ≤ SuccinctWhp.poolSizeWhp n_max → (∀ idx < p₀, BitPackedArray.readPacked (base + offPoolOwner c U V w n_max) (SuccinctBucket.globalPtrBits n_max) w s.mem idx = findOwner idx) → (∀ (a : ℕ), a < base + offPoolOwner c U V w n_max ∨ base + offBtMeta c U V w n_max ≤ a → s.mem a = s₀.mem a) → have prog := fillPoolOwnerLoopProg (((rt, bp M), p₀), rem); have s' := (Memory.spec 0).clientState s prog; s'.frontier = s.frontier ∧ Succinct.ValidProg w (base + SuccinctWhp.largeSpaceWhp c U V w n_max) s prog ∧ (∀ idx < p₀ + rem, BitPackedArray.readPacked (base + offPoolOwner c U V w n_max) (SuccinctBucket.globalPtrBits n_max) w s'.mem idx = findOwner idx) ∧ ∀ (a : ℕ), a < base + offPoolOwner c U V w n_max ∨ base + offBtMeta c U V w n_max ≤ a → s'.mem a = s₀.mem a

Exact memory specification of fillPoolOwnerLoopProg.

Phase D2: fillFreeStackLoopProg (populate offPoolFreeStack[j]) #

theorem Cslib.DataStructure.Dictionary.WordRAM.SuccinctWhp.fillFreeStackLoop_safe {c U V w n_max base tb ft : ℕ} (henv : WhpLargeEnv c U V w n_max w base) :
have rt := mkHealRt c U V w n_max base; ∀ (rem j₀ : ℕ) (s : Memory.State), j₀ + rem ≤ SuccinctWhp.poolSizeWhp n_max → WordRAM.Realization.iterationSafe fillFreeStackStepProg FillFreeStackPre w (rt, tb, ft) rem j₀ s

Loop-safety invariant for fillFreeStackLoopProg.

theorem Cslib.DataStructure.Dictionary.WordRAM.SuccinctWhp.fillFreeStackLoop_spec {c U V w n_max base totalBack : ℕ} (henv : WhpLargeEnv c U V w n_max w base) (htb_le : totalBack ≤ SuccinctWhp.poolSizeWhp n_max) :
have rt := mkHealRt c U V w n_max base; have ps := SuccinctWhp.poolSizeWhp n_max; have freeTop := ps - totalBack; ∀ (rem j₀ : ℕ) (s : Memory.State), j₀ + rem ≤ ps → (∀ idx < j₀, BitPackedArray.readPacked (base + offPoolFreeStack c U V w n_max) (SuccinctBucket.globalPtrBits n_max) w s.mem idx = if idx < freeTop then totalBack + idx else 0) → have prog := fillFreeStackLoopProg (((rt, totalBack, freeTop), j₀), rem); have s' := (Memory.spec 0).clientState s prog; s'.frontier = s.frontier ∧ Succinct.ValidProg w (base + SuccinctWhp.largeSpaceWhp c U V w n_max) s prog ∧ (∀ idx < j₀ + rem, BitPackedArray.readPacked (base + offPoolFreeStack c U V w n_max) (SuccinctBucket.globalPtrBits n_max) w s'.mem idx = if idx < freeTop then totalBack + idx else 0) ∧ ∀ (a : ℕ), a < base + offPoolFreeStack c U V w n_max ∨ base + offPoolOwner c U V w n_max ≤ a → s'.mem a = s.mem a

Exact memory specification of fillFreeStackLoopProg.

Phase D3: fillLocStateOuterLoopProg (populate offLocState) #

theorem Cslib.DataStructure.Dictionary.WordRAM.SuccinctWhp.fillLocStateOuterLoop_safe {c U V w n_max base : ℕ} (henv : WhpLargeEnv c U V w n_max w base) :
have rt := mkHealRt c U V w n_max base; ∀ (rem b₀ : ℕ) (s : Memory.State), b₀ + rem ≤ SuccinctWhp.numBucketsWhp n_max → WordRAM.Realization.iterationSafe fillLocStateOuterStepProg HealBktStepPre w rt rem b₀ s

Loop-safety invariant for fillLocStateOuterLoopProg.

theorem Cslib.DataStructure.Dictionary.WordRAM.SuccinctWhp.fillLocStateOuterLoop_spec {c U V w n_max base : ℕ} {fbStart : ℕ → ℕ} {s₀ : Memory.State} (henv : WhpLargeEnv c U V w n_max w base) (hfb_adj : ∀ b < SuccinctWhp.numBucketsWhp n_max, fbStart b ≤ fbStart (b + 1)) (hfb_mem : ∀ x ≤ SuccinctWhp.numBucketsWhp n_max, BitPackedArray.readPacked (base + offFbStart c U V w n_max) (SuccinctBucket.globalPtrBits n_max) w s₀.mem x = fbStart x) :
have rt := mkHealRt c U V w n_max base; have M := SuccinctWhp.numBucketsWhp n_max; have totalLoc := SuccinctWhp.totalLocalCoordsWhp n_max; ∀ (rem b₀ : ℕ) (s : Memory.State), b₀ + rem ≤ M → (∀ b < b₀, ∀ loc < totalLoc, BitPackedArray.readPacked (base + offLocState c U V w n_max) 2 w s.mem (b * totalLoc + loc) = if loc < fbStart (b + 1) - fbStart b then 1 else 0) → (∀ (a : ℕ), a < base + offLocState c U V w n_max ∨ base + offBktMeta c U V w n_max ≤ a → s.mem a = s₀.mem a) → have prog := fillLocStateOuterLoopProg ((rt, b₀), rem); have s' := (Memory.spec 0).clientState s prog; s'.frontier = s.frontier ∧ Succinct.ValidProg w (base + SuccinctWhp.largeSpaceWhp c U V w n_max) s prog ∧ (∀ b < b₀ + rem, ∀ loc < totalLoc, BitPackedArray.readPacked (base + offLocState c U V w n_max) 2 w s'.mem (b * totalLoc + loc) = if loc < fbStart (b + 1) - fbStart b then 1 else 0) ∧ ∀ (a : ℕ), a < base + offLocState c U V w n_max ∨ base + offBktMeta c U V w n_max ≤ a → s'.mem a = s₀.mem a

Exact memory specification of fillLocStateOuterLoopProg.

Phase E1: resetAllSlicesLoopProg (reset all 3 * M slices to zeroBTreeSlice) #

@[irreducible]

Loop resetting all 3 * M slices to zeroBTreeSlice.

theorem Cslib.DataStructure.Dictionary.WordRAM.SuccinctWhp.resetAllSlicesLoop_safe {c U V w n_max base : ℕ} (henv : WhpLargeEnv c U V w n_max w base) :
have cp := mkWhpCoreParams c U V w n_max; ∀ (rem s₀ : ℕ) (s : Memory.State), s₀ + rem ≤ 3 * SuccinctWhp.numBucketsWhp n_max → WordRAM.Realization.iterationSafe resetAllSlicesStepProg ResetAllSlicesPre w (cp, base) rem s₀ s

Loop-safety invariant for resetAllSlicesLoopProg.

theorem Cslib.DataStructure.Dictionary.WordRAM.SuccinctWhp.resetAllSlicesLoop_spec {c U V w n_max base : ℕ} (henv : WhpLargeEnv c U V w n_max w base) :
have cp := mkWhpCoreParams c U V w n_max; have M := SuccinctWhp.numBucketsWhp n_max; ∀ (rem s₀ : ℕ) (s : Memory.State), s₀ + rem ≤ 3 * M → (∀ sIdx < s₀, BTreeSliceMemRep base c U V w n_max sIdx SuccinctWhp.zeroBTreeSlice s.mem) → have prog := resetAllSlicesLoopProg (((cp, base), s₀), rem); have s' := (Memory.spec 0).clientState s prog; s'.frontier = s.frontier ∧ Succinct.ValidProg w (base + SuccinctWhp.largeSpaceWhp c U V w n_max) s prog ∧ (∀ sIdx < s₀ + rem, BTreeSliceMemRep base c U V w n_max sIdx SuccinctWhp.zeroBTreeSlice s'.mem) ∧ (∀ idx < 16 * M, idx % 16 = 1 → BitPackedArray.readPacked (base + offBktMeta c U V w n_max) (SuccinctBucket.globalPtrBits n_max) w s'.mem idx = BitPackedArray.readPacked (base + offBktMeta c U V w n_max) (SuccinctBucket.globalPtrBits n_max) w s.mem idx) ∧ ∀ (a : ℕ), a < base + offBktMeta c U V w n_max ∨ base + offFbStart c U V w n_max ≤ a → s'.mem a = s.mem a

Exact memory specification of resetAllSlicesLoopProg.