Documentation

CslibFrontier.DataStructure.Dictionary.WordRAM.ResizableSuccinct.WindowOps

Metadata and Circular-Window Memory.Prog Primitives #

This module builds on Accessors.lean to provide RealizesBounded .exact (¬ReadsWidth) Memory.Prog primitives for:

Main definitions #

Main results #

Section 1: Item Copy/Clear and Metadata Array Accessors #

theorem Cslib.DataStructure.Dictionary.WordRAM.ResizableSuccinct.clientState_copyCompItemGenProg {U V w N m_items itemBase src dst : ℕ} (hsrc : src < m_items) (s : Memory.State) :
(Memory.spec 0).clientState s (copyCompItemGenProg ((mkCompParams U V w N, itemBase), src, dst)) = { mem := writeCompVal itemBase U V w N (writeCompQuot itemBase U V w N s.mem dst (compQuotAt itemBase U V w N m_items s.mem src)) dst (compValAt itemBase U V w N m_items s.mem src), frontier := s.frontier }

Copying dense item slot src (src < m_items) to dst writes its quotient and value into dst and preserves s.frontier.

Precondition for copying an item between two compacted item slots.

Clear (quot, val) to (0, 0) at dense index d before shrinking trailing words.

theorem Cslib.DataStructure.Dictionary.WordRAM.ResizableSuccinct.clientState_clearCompItemGenProg (U V w N itemBase d : ℕ) (s : Memory.State) :
(Memory.spec 0).clientState s (clearCompItemGenProg ((mkCompParams U V w N, itemBase), d)) = { mem := writeCompVal itemBase U V w N (writeCompQuot itemBase U V w N s.mem d 0) d 0, frontier := s.frontier }

Clearing dense slot d writes 0 to both its quotient and value, preserving s.frontier.

@[simp]

Reading LocalMeta[c, idx] returns compLmAt metaBase U w N s.mem (c.val, idx).

@[simp]

simp-indexed projection form of clientState_readCompLMGenProg (clientState unfolds to a match that simp cannot index directly).

Precondition for reading from local metadata array LM.

Write val into LocalMeta[c, idx] at metaBase in Memory.Prog.

Writing val to LocalMeta[c, idx] updates that packed slot and preserves s.frontier.

@[simp]
theorem Cslib.DataStructure.Dictionary.WordRAM.ResizableSuccinct.runClient_state_writeCompLMGenProg (c : Fin 9) (U V w N metaBase idx val : ℕ) (s : Memory.State) :
((Memory.spec 0).runClient s (writeCompLMGenProg c (((mkCompParams U V w N, metaBase), idx), val))).2.1 = { mem := BitPackedArray.writePacked (metaBase + offCompLMSub U w N ↑c) (SuccinctBucket.effBucketPosBits N) w s.mem idx val, frontier := s.frontier }

simp-indexed projection form of clientState_writeCompLMGenProg.

Precondition for writing to local metadata array LM.

@[simp]

Reading GlobalMeta[idx] returns compGmAt metaBase U w N s.mem idx.

Precondition for reading from global metadata array GM.

Writing val to GlobalMeta[idx] updates that packed slot and preserves s.frontier.

@[simp]

simp-indexed projection form of clientState_writeCompGMGenProg.

Precondition for writing to global metadata array GM.

@[simp]

Reading TailToDense[t] (t < maxTailItems N) returns compTDAt metaBase U w N s.mem t.

Precondition for reading from tail map TailToDense.

Writing val to TailToDense[t] updates that packed slot and preserves s.frontier.

@[simp]

Reading DenseToTail[r] (r < maxTailItems N) returns compDTAt metaBase U w N s.mem r.

Writing val to DenseToTail[r] updates that packed slot and preserves s.frontier.

Section 2: Circular-Window Transitions, Owner-Bucket Recovery, and fits_mkCompParams #

When positive, the tail-capacity bound maxTailItems N is at most N.

Overflow-free evaluation of denseOfCirc (cpMaxTail cp) b_win c in Memory.Prog.

denseOfCircGenProg returns denseOfCirc (maxTailItems N) b_win c when 0 < maxTailItems N → c < maxTailItems N.

Precondition for circular tail offset mapping denseOfCirc.

Map physical slot g < N to dense index denseOfPhys N gm td g in Memory.Prog.

denseOfPhysGenProg returns denseOfPhys N applied to the packed GlobalMeta and TailToDense arrays at metaBase.

Precondition for mapping physical slot index to dense index denseOfPhys.

Grow circular window [b_win, b_win + n_win) on the right by 1 (winGrowRight).

Precondition for growing the circular window on the right.

Growing the circular window on the right links TailToDense[n_win] and DenseToTail[c] for c = (b_win + n_win) % maxTailItems N, preserving s.frontier.

Grow circular window [b_win + 1, b_win + 1 + n_win) on the left by 1 (winGrowLeft).

Precondition for growing the circular window on the left.

Growing the circular window on the left links TailToDense[n_win] and DenseToTail[c] for c = b_win % maxTailItems N, preserving s.frontier.

Shrink circular window [b_win, b_win + n_win + 1) on the right by 1 (winShrinkRight).

Precondition for shrinking the circular window on the right.

Shrink circular window [b_win, b_win + n_win + 1) on the left by 1 (winShrinkLeft).

Precondition for shrinking the circular window on the left.

theorem Cslib.DataStructure.Dictionary.WordRAM.ResizableSuccinct.clientState_winShrinkRightGenProg {U V w N metaBase b_win n_win : ℕ} {s : Memory.State} (hc : (b_win + n_win) % SuccinctBucket.maxTailItems N < SuccinctBucket.maxTailItems N) (hn : n_win < SuccinctBucket.maxTailItems N) :
(Memory.spec 0).clientState s (winShrinkRightGenProg ((mkCompParams U V w N, metaBase), b_win, n_win)) = { mem := BitPackedArray.writePacked (metaBase + offDenseToTail U w N) (SuccinctBucket.globalPtrBits N) w (BitPackedArray.writePacked (metaBase + offTailToDense U w N) (SuccinctBucket.globalPtrBits N) w s.mem (compDTAt metaBase U w N s.mem ((b_win + n_win) % SuccinctBucket.maxTailItems N)) (compTDAt metaBase U w N s.mem n_win)) (compTDAt metaBase U w N s.mem n_win) (compDTAt metaBase U w N s.mem ((b_win + n_win) % SuccinctBucket.maxTailItems N)), frontier := s.frontier }

Final memory state of winShrinkRightGenProg, linking DenseToTail[c_rem] with TailToDense[n_win] for c_rem = (b_win + n_win) % maxTailItems N and preserving s.frontier.

theorem Cslib.DataStructure.Dictionary.WordRAM.ResizableSuccinct.clientState_winShrinkLeftGenProg {U V w N metaBase b_win n_win : ℕ} {s : Memory.State} (hc : b_win % SuccinctBucket.maxTailItems N < SuccinctBucket.maxTailItems N) (hn : n_win < SuccinctBucket.maxTailItems N) :
(Memory.spec 0).clientState s (winShrinkLeftGenProg ((mkCompParams U V w N, metaBase), b_win, n_win)) = { mem := BitPackedArray.writePacked (metaBase + offDenseToTail U w N) (SuccinctBucket.globalPtrBits N) w (BitPackedArray.writePacked (metaBase + offTailToDense U w N) (SuccinctBucket.globalPtrBits N) w s.mem (compDTAt metaBase U w N s.mem (b_win % SuccinctBucket.maxTailItems N)) (compTDAt metaBase U w N s.mem n_win)) (compTDAt metaBase U w N s.mem n_win) (compDTAt metaBase U w N s.mem (b_win % SuccinctBucket.maxTailItems N)), frontier := s.frontier }

Final memory state of winShrinkLeftGenProg, linking DenseToTail[c_rem] with TailToDense[n_win] for c_rem = b_win % maxTailItems N and preserving s.frontier.