Documentation

CslibFrontier.DataStructure.Dictionary.WordRAM.SuccinctWhpTickHealProg.PrefixBackPtr

Backyard Prefix, Pointer Table, and Target-Permutation Specs for csrToFastGenProg #

This internal module implements Phases A, B, and C's target evaluator of csrToFastGenProg:

Main definitions #

Main results #

Phase A: bpPrefixLoopProg (buildBackPrefix into even slots offBktMeta[2 * x]) #

@[irreducible]

Loop writing buildBackPrefix into offBktMeta[2 * x] across rem buckets.

theorem Cslib.DataStructure.Dictionary.WordRAM.SuccinctWhp.bpPrefixLoop_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₀ acc₀ : ℕ) (s : Memory.State), b₀ + rem ≤ SuccinctWhp.numBucketsWhp n_max → WordRAM.Realization.iterationSafe bpPrefixStepProg BpPrefixStepPre w rt rem (b₀, acc₀) s

Loop-safety invariant for bpPrefixLoopProg.

theorem Cslib.DataStructure.Dictionary.WordRAM.SuccinctWhp.bpPrefixLoop_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)) (hbp_le : SuccinctWhp.buildBackPrefix (SuccinctWhp.numBucketsWhp n_max) (SuccinctWhp.capFrontWhp n_max) fbStart (SuccinctWhp.numBucketsWhp n_max) ≤ n_max) (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 bp := SuccinctWhp.buildBackPrefix M (SuccinctWhp.capFrontWhp n_max) fbStart; ∀ (rem b₀ : ℕ) (s : Memory.State), b₀ + rem ≤ M → (∀ x ≤ b₀, BitPackedArray.readPacked (base + offBktMeta c U V w n_max) (SuccinctBucket.globalPtrBits n_max) w s.mem (2 * x) = bp x) → (∀ idx < 16 * M, idx % 2 = 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) → have prog := bpPrefixLoopProg ((rt, b₀, bp 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 ∧ (∀ x ≤ b₀ + rem, BitPackedArray.readPacked (base + offBktMeta c U V w n_max) (SuccinctBucket.globalPtrBits n_max) w s'.mem (2 * x) = bp x) ∧ (∀ idx < 16 * M, idx % 2 = 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 bpPrefixLoopProg.

Phase B: fillBackPtrOuterLoopProg (populate offBackPtr[b * cb + k]) #

theorem Cslib.DataStructure.Dictionary.WordRAM.SuccinctWhp.fillBackPtrOuterLoop_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 fillBackPtrOuterStepProg HealBktStepPre w rt rem b₀ s

Loop-safety invariant for fillBackPtrOuterLoopProg.

theorem Cslib.DataStructure.Dictionary.WordRAM.SuccinctWhp.fillBackPtrOuterLoop_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)) (hbp_le : SuccinctWhp.buildBackPrefix (SuccinctWhp.numBucketsWhp n_max) (SuccinctWhp.capFrontWhp n_max) fbStart (SuccinctWhp.numBucketsWhp n_max) ≤ n_max) (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) (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; ∀ (rem b₀ : ℕ) (s : Memory.State), b₀ + rem ≤ M → (∀ b < b₀, ∀ k < cb, BitPackedArray.readPacked (base + offBackPtr c U V w n_max) (SuccinctBucket.globalPtrBits n_max) w s.mem (b * cb + k) = if k < fbStart (b + 1) - fbStart b - cf then bp b + k else 0) → (∀ (a : ℕ), a < base + offBackPtr c U V w n_max ∨ base + offBackAux c U V w n_max ≤ a → s.mem a = s₀.mem a) → have prog := fillBackPtrOuterLoopProg ((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, ∀ k < cb, BitPackedArray.readPacked (base + offBackPtr c U V w n_max) (SuccinctBucket.globalPtrBits n_max) w s'.mem (b * cb + k) = if k < fbStart (b + 1) - fbStart b - cf then bp b + k else 0) ∧ ∀ (a : ℕ), a < base + offBackPtr c U V w n_max ∨ base + offBackAux c U V w n_max ≤ a → s'.mem a = s₀.mem a

Exact memory specification of fillBackPtrOuterLoopProg.

Phase C Target-Evaluator Specification (permEvalActDestProg at mode = 2) #

theorem Cslib.DataStructure.Dictionary.WordRAM.SuccinctWhp.csrPermute_eval_spec {c U V w n_max base : ℕ} {csr : SuccinctWhp.CsrState} {s₀ : Memory.State} (henv : WhpLargeEnv c U V w n_max w base) (hfb0 : csr.fbStart 0 = 0) (hfb_adj : ∀ b < SuccinctWhp.numBucketsWhp n_max, csr.fbStart b ≤ csr.fbStart (b + 1)) (hback_cb : ∀ b < SuccinctWhp.numBucketsWhp n_max, csr.fbStart (b + 1) - csr.fbStart b - SuccinctWhp.capFrontWhp n_max < SuccinctWhp.capBackWhp n_max) (hbp_ps : SuccinctWhp.buildBackPrefix (SuccinctWhp.numBucketsWhp n_max) (SuccinctWhp.capFrontWhp n_max) csr.fbStart (SuccinctWhp.numBucketsWhp n_max) ≤ SuccinctWhp.poolSizeWhp n_max) (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 = csr.fbStart x) (hbp_mem : ∀ b < SuccinctWhp.numBucketsWhp n_max, ∀ k < SuccinctWhp.capBackWhp n_max, BitPackedArray.readPacked (base + offBackPtr c U V w n_max) (SuccinctBucket.globalPtrBits n_max) w s₀.mem (b * SuccinctWhp.capBackWhp n_max + k) = if k < csr.fbStart (b + 1) - csr.fbStart b - SuccinctWhp.capFrontWhp n_max then SuccinctWhp.buildBackPrefix (SuccinctWhp.numBucketsWhp n_max) (SuccinctWhp.capFrontWhp n_max) csr.fbStart b + k else 0) :
have M := SuccinctWhp.numBucketsWhp n_max; have cf := SuccinctWhp.capFrontWhp n_max; have bp := SuccinctWhp.buildBackPrefix M cf csr.fbStart; have bktCnt := fun (b : ℕ) => if b < M then csr.fbStart (b + 1) - csr.fbStart b else 0; have backPtr := fun (b k : ℕ) => if b < M ∧ k < bktCnt b - cf then bp b + k else 0; have act₀ := fun (i : ℕ) => decide (i < csr.fbStart M); have dest := fun (i : ℕ) => have b := SuccinctWhp.csrBucketOfIdx csr.fbStart i M; have loc := i - csr.fbStart b; if loc < cf then b * cf + loc else M * cf + backPtr b (loc - cf); ∀ x < n_max, ∀ (s' : Memory.State), (∀ (a : ℕ), a < base + offQuotWhp c w n_max ∨ base + offLocState c U V w n_max ≤ a → s'.mem a = s₀.mem a) → (((Memory.spec 0).clientResult s' (permEvalActDestProg ((mkPermRt c U V w n_max base, 2), x))).1 = if act₀ x = true then 1 else 0) ∧ (act₀ x = true → ((Memory.spec 0).clientResult s' (permEvalActDestProg ((mkPermRt c U V w n_max base, 2), x))).2 = dest x ∧ dest x < n_max)

Exact target-slot specification of permEvalActDestProg at mode = 2 for csrToFast.