Documentation

CslibFrontier.DataStructure.Memory.Resizable

Word-granular resizable memory specification #

Word-granular resizable memory specification (Cslib.DataStructure.Memory.Resizable) accompanying the Resizable Word RAM (Cslib.WordRAM.Resizable), modeling the dynamically resizable w-bit word memory of [LLYZ23a], Section 2.1, [LLYZ24], Section 3.2, and [KLZ26], Section 5.1 (termed the "virtual memory (VM) model" in those papers, with 1-indexed addresses [1..M] mapped here to 0-indexed [0, s.frontier)).

A data structure operating over word-granular resizable memory owns a 0-indexed active prefix [0, s.frontier) of w-bit words in s : Memory.State, where s.frontier is the current number of allocated words. In addition to reading and writing allocated words (a < s.frontier), a client may grow (grow k, growDirty k) or shrink (shrink k) the active prefix by whole words.

Main definitions #

Main results #

References #

Empty state and zero-above invariant #

The empty memory state with all cells zeroed and frontier = 0.

Every address at or above s.frontier holds 0.

Operations, deterministic spec w, and relational demonicSpec w #

Operations of a word-granular resizable memory ([LLYZ23a], Section 2.1; [KLZ26], Section 5.1).

  • read (a : ℕ) : Op

    Read the w-bit word at address a < frontier.

  • write (a v : ℕ) : Op

    Write the w-bit word v at address a < frontier.

  • grow (k : ℕ) : Op

    Grow [0, frontier) by k zeroed words to [0, frontier + k), returning old frontier.

  • growDirty (k : ℕ) : Op

    Grow [0, frontier) by k words without caller zero-fill (arbitrary w-bit words in demonicSpec w, zeroed in canonical spec w), returning old frontier.

  • shrink (k : ℕ) : Op

    Shrink [0, frontier) by k ≤ frontier words, clearing [frontier - k, frontier).

Instances For
    @[reducible, inline]

    Result type of each resizable-memory operation.

    Deterministic zero-initialized transition function on Memory.State (the canonical instance of demonicStep w that chooses 0 for newly allocated growDirty words as well as grow words).

    Admissibility precondition at word width w.

    Instances For
      @[instance_reducible]
      @[reducible, inline]

      Deterministic zero-initialized word-granular resizable memory specification at word width w.

      @[instance_reducible]

      Admissibility of a concrete history on Resizable.spec w is decidable.

      Demonic relational transition at word width w: .grow k zero-initializes [s.frontier, s.frontier + k), whereas .growDirty k permits any post-state s' preserving s.mem outside [s.frontier, s.frontier + k) and placing arbitrary w-bit words in [s.frontier, s.frontier + k) ([KuszmaulLiangZhou2026], Section 5.1, Footnote 10).

      Demonic relational word-granular resizable memory specification at word width w.

      Effectful program primitives #

      @[reducible, inline]

      A program over the word-granular resizable memory oracle.

      @[reducible, inline]

      Read the word at address a.

      @[reducible, inline]

      Write v to address a.

      @[reducible, inline]

      Grow the active prefix by k zeroed words, returning the old frontier.

      @[reducible, inline]

      Grow the active prefix by k words without caller zero-fill (arbitrary w-bit words in demonicSpec w, zeroed in canonical spec w), returning the old frontier.

      @[reducible, inline]

      Shrink the active prefix by k words.

      @[reducible, inline]

      Allocate a single zeroed word at frontier.

      @[reducible, inline]

      Allocate a single word at frontier without caller zero-fill (growDirty 1).

      @[reducible, inline]

      Release a single word from frontier.

      @[simp]
      theorem Cslib.DataStructure.Memory.Resizable.step_write (s : State) (a v : ℕ) :
      step s (Op.write a v) = ({ mem := Function.update s.mem a v, frontier := s.frontier }, ())
      @[simp]
      @[simp]
      theorem Cslib.DataStructure.Memory.Resizable.step_shrink (s : State) (k : ℕ) :
      step s (Op.shrink k) = ({ mem := WordRAM.clear s.mem (s.frontier - k) k, frontier := s.frontier - k }, ())

      Well-formedness and canonical state preservation #

      A resizable memory state is canonical at word width w when all words and the frontier fit in w bits (WellFormed w s) and all unallocated addresses a ≥ s.frontier hold 0 (ZeroAbove s).

      When ZeroAbove s holds, clearing [s.frontier, s.frontier + k) is a no-op.

      theorem Cslib.DataStructure.Memory.Resizable.wellFormed_step {w : ℕ} {s : State} {o : Op} (hs : WellFormed w s) (hv : valid w s o) :
      WellFormed w (step s o).1

      Every valid operation preserves WellFormed w.

      theorem Cslib.DataStructure.Memory.Resizable.zeroAbove_step {w : ℕ} {s : State} {o : Op} (hs : ZeroAbove s) (hv : valid w s o) :
      ZeroAbove (step s o).1

      Every valid operation preserves ZeroAbove.

      theorem Cslib.DataStructure.Memory.Resizable.canonical_step {w : ℕ} {s : State} {o : Op} (hs : Canonical w s) (hv : valid w s o) :
      Canonical w (step s o).1

      Every valid operation preserves Canonical w.

      theorem Cslib.DataStructure.Memory.Resizable.wellFormed_demonicStep {w : ℕ} {s s' : State} {o : Op} {r : o.Result} (hs : WellFormed w s) (hv : valid w s o) (hstep : demonicStep w s o s' r) :

      Every valid transition of demonicStep w preserves WellFormed w.

      theorem Cslib.DataStructure.Memory.Resizable.zeroAbove_demonicStep {w : ℕ} {s s' : State} {o : Op} {r : o.Result} (hs : ZeroAbove s) (hv : valid w s o) (hstep : demonicStep w s o s' r) :

      Every valid transition of demonicStep w preserves ZeroAbove.

      theorem Cslib.DataStructure.Memory.Resizable.canonical_demonicStep {w : ℕ} {s s' : State} {o : Op} {r : o.Result} (hs : Canonical w s) (hv : valid w s o) (hstep : demonicStep w s o s' r) :

      Every valid transition of demonicStep w preserves Canonical w.

      Refinement specRefinesDemonicSpec #

      Every deterministic step transition satisfies demonicStep w.

      Any machine-level WordRAM.Resizable.DemonicGrow transition from a ZeroAbove state satisfies demonicStep w s (.growDirty k).

      The zero-initialized specification spec w refines demonicSpec w over the identity state map: every client verified against demonicSpec w is valid and has its behavior included in demonicSpec w when executed on spec w.

      Cost, live space measures, and resize-aware frame condition #

      Operation cost measure (charge): read and write cost 1 unit; bulk resize operations grow k, growDirty k, and shrink k cost max k 1 units, matching the Θ(k + 1) step cost of looping single-word hardware .grow and .shrink primitives ([KLZ26], Section 5.1, PDF pp. 16–17 / printed pp. 15–16).

      @[reducible, inline]

      Current allocated space of s in w-bit words (s.frontier).

      Current allocated space of s in bits (w * s.frontier).

      Total space in bits of s.frontier allocated words plus a spillover integer in [0, K) ([LiLiangYuZhou2023Succincter], Section 1.3, PDF p. 4 / printed p. 3; [KLZ26], Section 5.1, PDF p. 17 / printed p. 16). Here Nat.clog 2 K = ⌈log₂ K⌉ rounds the papers' real-valued lg K up to ℕ (adding < 1 bit of slack when K is not a power of two).

      Peak number of allocated words reached during execution of p from s on spec.

      Word-level frame condition across resizes: every address a < min s.frontier s'.frontier outside W retains its value (s'.mem a = s.mem a).

      theorem Cslib.DataStructure.Memory.Resizable.UnchangedOutside.mono {s s' : State} {W₁ W₂ : Set ℕ} (h : UnchangedOutside s s' W₁) (hsub : W₁ ⊆ W₂) :
      theorem Cslib.DataStructure.Memory.Resizable.Block.realizes_of_unchangedOutside (b : WordRAM.Block) {s s' : State} {W : Set ℕ} {vs : Fin b.length → ℕ} (hreal : b.Realizes s.mem vs) (hfit : b.base + b.length ≤ min s.frontier s'.frontier) (hframe : UnchangedOutside s s' W) (hdisj : ∀ (a : ℕ), b.Owns a → a ∉ W) :
      b.Realizes s'.mem vs

      If a block b lies below min s.frontier s'.frontier and is disjoint from W, then UnchangedOutside s s' W preserves b.Realizes.