Documentation

CslibFrontier.DataStructure.Dictionary.WordRAM.SuccinctWhpPermHealProg

Certified Memory.Prog Implementations of locState, permuteByTarget, and fastToCsr #

This module implements the overflow-free 2-bit locState accessors (readLocStateGenProg, writeLocStateGenProg), the bucket-interval scanner scanBucketLoopProg, the in-place cycle-following permutation permuteByTargetProg shared by fastToCsr and csrToFast, and the fastToCsrGenProg transition from FastMemRep to CsrMemRep, all certified over Basis.exact with zero local work via realize and Realizes.iterate₀.

Main definitions #

Main results #

Section 1: Overflow-Free 2-Bit offLocState Accessors #

Precondition for readLocStateGenProg (d = (((base, offLoc), (totalLoc, w)), (b, loc))).

@[irreducible]

Read readPacked (base + offLoc) 2 w s.mem (b * totalLoc + loc) without overflowing w bits (d = (((base, offLoc), (totalLoc, w)), (b, loc))).

theorem Cslib.DataStructure.Dictionary.WordRAM.SuccinctWhp.readLocStateGenProg_spec {c U V w n_max base b loc : ℕ} {s : Memory.State} (henv : WhpLargeEnv c U V w n_max w base) (hb : b < SuccinctWhp.numBucketsWhp n_max) (hloc : loc < SuccinctWhp.totalLocalCoordsWhp n_max) :
have prog := readLocStateGenProg (((base, offLocState c U V w n_max), SuccinctWhp.totalLocalCoordsWhp n_max, w), b, loc); have idx := b * SuccinctWhp.totalLocalCoordsWhp n_max + loc; (Memory.spec 0).clientState s prog = s ∧ (Memory.spec 0).clientResult s prog = BitPackedArray.readPacked (base + offLocState c U V w n_max) 2 w s.mem idx ∧ WordRAM.Realization.memoryCost prog s = 2 ∧ Succinct.ValidProg w (base + SuccinctWhp.largeSpaceWhp c U V w n_max) s prog

Precondition for writeLocStateGenProg (d = ((((base, offLoc), (totalLoc, w)), (b, loc)), val)).

@[irreducible]

Write val (< 4) into offLocState at b * totalLoc + loc without overflowing w bits (d = ((((base, offLoc), (totalLoc, w)), (b, loc)), val)).

theorem Cslib.DataStructure.Dictionary.WordRAM.SuccinctWhp.writeLocStateGenProg_spec {c U V w n_max base b loc val : ℕ} {s : Memory.State} (henv : WhpLargeEnv c U V w n_max w base) (hb : b < SuccinctWhp.numBucketsWhp n_max) (hloc : loc < SuccinctWhp.totalLocalCoordsWhp n_max) :
have prog := writeLocStateGenProg ((((base, offLocState c U V w n_max), SuccinctWhp.totalLocalCoordsWhp n_max, w), b, loc), val); have idx := b * SuccinctWhp.totalLocalCoordsWhp n_max + loc; (Memory.spec 0).clientState s prog = { mem := BitPackedArray.writePacked (base + offLocState c U V w n_max) 2 w s.mem idx val, frontier := s.frontier } ∧ WordRAM.Realization.memoryCost prog s = 4 ∧ Succinct.ValidProg w (base + SuccinctWhp.largeSpaceWhp c U V w n_max) s prog

Section 2: PermRt, scanBucketProg, permuteByTargetProg, and fastToCsrGenProg #

@[reducible, inline]

Compact 19-word runtime parameter bundle for permuteByTarget, fastToCsr, and csrToFast array loops: (((base, w), (n_max, M)), (((cf, cb), (frontTotal, poolSize)), (((gBits, quotBits), (valBits, permActBits)), ((offQuot, offVal), ((offPermAct, offBktMeta), (offFbStart, (offBackPtr, offPoolOwner))))))).

Pure constructor for PermRt (19 words).

Runtime envelope for PermRt in the large regime.

@[irreducible]

Extract PermRt from (cp, base) in 0 memory operations.

@[irreducible]

iterate wrapper for scanBucketStepProg computing csrBucketOfIdx across 0 .. rem - 1.

theorem Cslib.DataStructure.Dictionary.WordRAM.SuccinctWhp.scanBucketLoop_invariant {c U V w n_max base offArr stride target : ℕ} {s : Memory.State} (henv : WhpLargeEnv c U V w n_max w base) (hmode : stride = 1 ∧ offArr = offFbStart c U V w n_max ∨ stride = 2 ∧ offArr = offBktMeta c U V w n_max) :
have arr := fun (x : ℕ) => BitPackedArray.readPacked (base + offArr) (SuccinctBucket.globalPtrBits n_max) w s.mem (stride * x); have cfg := (((base, offArr), SuccinctBucket.globalPtrBits n_max, w), stride, target); have prog := scanBucketLoopProg ((cfg, 0, 0), SuccinctWhp.numBucketsWhp n_max); ScanBucketLoopSafe w ((cfg, 0, 0), SuccinctWhp.numBucketsWhp n_max) s ∧ (Memory.spec 0).clientState s prog = s ∧ (Memory.spec 0).clientResult s prog = (SuccinctWhp.numBucketsWhp n_max, SuccinctWhp.csrBucketOfIdx arr target (SuccinctWhp.numBucketsWhp n_max)) ∧ Succinct.ValidProg w (base + SuccinctWhp.largeSpaceWhp c U V w n_max) s prog
@[irreducible]

Evaluate (actBit, destVal) for permuteByTarget in mode 1 (fastToCsr) or mode 0 (csrToFast), guaranteeing destVal < prNMax prt unconditionally (d = ((prt, mode), x)).

@[irreducible]

Complete in-place permuteByTarget in Memory.Prog (d = (prt, mode)).

theorem Cslib.DataStructure.Dictionary.WordRAM.SuccinctWhp.permuteByTargetProg_spec {c U V w n_max base mode : ℕ} {act₀ : ℕ → Bool} {dest qArr vArr : ℕ → ℕ} {s : Memory.State} (henv : WhpLargeEnv c U V w n_max w base) (hq : ∀ i < n_max, BitPackedArray.readPacked (base + offQuotWhp c w n_max) (SuccinctWhp.quotBitsWhp U n_max) w s.mem i = qArr i ∧ qArr i < 2 ^ SuccinctWhp.quotBitsWhp U n_max) (hv : ∀ i < n_max, BitPackedArray.readPacked (base + offValWhp c U w n_max) (FeistelQuotient.valBits V) w s.mem i = vArr i ∧ vArr i < 2 ^ FeistelQuotient.valBits V) (heval : ∀ 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, mode), 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, mode), x))).2 = dest x ∧ dest x < n_max)) :
have prog := permuteByTargetProg (mkPermRt c U V w n_max base, mode); have s' := (Memory.spec 0).clientState s prog; have pv := SuccinctWhp.permuteByTarget n_max dest act₀ qArr vArr; (∀ i < n_max, BitPackedArray.readPacked (base + offQuotWhp c w n_max) (SuccinctWhp.quotBitsWhp U n_max) w s'.mem i = pv.1 i ∧ BitPackedArray.readPacked (base + offValWhp c U w n_max) (FeistelQuotient.valBits V) w s'.mem i = pv.2 i) ∧ (∀ (a : ℕ), a < base + offQuotWhp c w n_max ∨ base + offLocState c U V w n_max ≤ a → s'.mem a = s.mem a) ∧ s'.frontier = s.frontier ∧ Succinct.ValidProg w (base + SuccinctWhp.largeSpaceWhp c U V w n_max) s prog

Exact memory specification of permuteByTargetProg: rearranges offQuotWhp and offValWhp according to permuteByTarget n_max dest act₀ qArr vArr while leaving all memory words outside [base + offQuotWhp c w n_max, base + offLocState c U V w n_max) unchanged.

Section 3: fastToCsrGenProg (FastMemRep → CsrMemRep) #

@[irreducible]

Convert FastMemRep in place to CsrMemRep (d = (cp, base)).

theorem Cslib.DataStructure.Dictionary.WordRAM.SuccinctWhp.fastToCsrGenProg_spec {c U V w n_max base : ℕ} {θ : SuccinctWhp.SeedWhp c U n_max} {fs : SuccinctWhp.FastState} {dict : State U} {s : Memory.State} (henv : WhpLargeEnv c U V w n_max w base) (hseed : SeedWhpMemRep base c U w n_max θ s.mem) (hrep : FastMemRep base c U V w n_max fs s.mem) (hv : SuccinctWhp.ValidFastState c U V n_max θ fs dict) :
have prog := fastToCsrGenProg (mkWhpCoreParams c U V w n_max, base); have s' := (Memory.spec 0).clientState s prog; SeedWhpMemRep base c U w n_max θ s'.mem ∧ CsrMemRep base c U V w n_max (SuccinctWhp.fastToCsr n_max fs) s'.mem ∧ s'.frontier = s.frontier ∧ Succinct.ValidProg w (base + SuccinctWhp.largeSpaceWhp c U V w n_max) s prog ∧ ∀ (a : ℕ), a < base ∨ base + SuccinctWhp.largeSpaceWhp c U V w n_max ≤ a → s'.mem a = s.mem a

Exact specification of fastToCsrGenProg: converts any valid FastMemRep into CsrMemRep for fastToCsr n_max fs while preserving SeedWhpMemRep and leaving memory outside [base, base + largeSpaceWhp c U V w n_max) untouched.

theorem Cslib.DataStructure.Dictionary.WordRAM.SuccinctWhp.clientResult_permEvalActDestProg_of_ne_one {c U V w n_max base mode x : ℕ} (henv : WhpLargeEnv c U V w n_max w base) (hm : mode ≠ 1) (s : Memory.State) :
have M := SuccinctWhp.numBucketsWhp n_max; have cf := SuccinctWhp.capFrontWhp n_max; have cb := SuccinctWhp.capBackWhp n_max; have gBits := SuccinctBucket.globalPtrBits n_max; have fbRd := fun (k : ℕ) => BitPackedArray.readPacked (base + offFbStart c U V w n_max) gBits w s.mem k; have b := SuccinctWhp.csrBucketOfIdx fbRd x M; have bpVal := BitPackedArray.readPacked (base + offBackPtr c U V w n_max) gBits w s.mem (b * cb + (x - fbRd b - cf)); (Memory.spec 0).clientResult s (permEvalActDestProg ((mkPermRt c U V w n_max base, mode), x)) = if x < fbRd M then if b < M then if x < fbRd b then (0, 0) else if x - fbRd b < cf then (1, b * cf + (x - fbRd b)) else if x - fbRd b - cf < cb then if bpVal < SuccinctWhp.poolSizeWhp n_max then (1, M * cf + bpVal) else (0, 0) else (0, 0) else (0, 0) else (0, 0)

Exact evaluation of permEvalActDestProg in mode mode ≠ 1 (csrToFast).