Documentation

CslibFrontier.Computability.WordRAM.Realization.RecordOps

Fixed-stride record arrays and three-way concatenation #

This module provides:

  1. HoldsRecords: a fixed-stride record-array representation predicate over raw RAM memory, together with framing (HoldsRecords.congr, HoldsRecords.of_modifies_disjoint), slicing (HoldsRecords.append_iff), and Memory.copy-based record copying (HoldsRecords.copy).
  2. FramedTriple.frame_empty_of_ge_frontier: shrinks a Memory.FramedTriple's modification set to ∅ whenever all modified addresses lie at or above s.frontier.
  3. concatRecordsProg: three-way dirty concatenation of fixed-stride record slices.

Main definitions #

Main results #

Fixed-stride record arrays (HoldsRecords) #

def Cslib.WordRAM.Realization.HoldsRecords (stride base : ℕ) (rows : List (Fin stride → ℕ)) (mem : ℕ → ℕ) :

Memory mem stores rows.length consecutive fixed-stride records of width stride starting at base.

theorem Cslib.WordRAM.Realization.HoldsRecords.nil (stride base : ℕ) (mem : ℕ → ℕ) :
HoldsRecords stride base [] mem

An empty list of records holds trivially at any base and stride.

theorem Cslib.WordRAM.Realization.HoldsRecords.congr {stride base : ℕ} {rows : List (Fin stride → ℕ)} {m₁ m₂ : ℕ → ℕ} (heq : ∀ (a : ℕ), base ≤ a → a < base + stride * rows.length → m₂ a = m₁ a) (h : HoldsRecords stride base rows m₁) :
HoldsRecords stride base rows m₂

Congruence for HoldsRecords over [base, base + stride * rows.length).

theorem Cslib.WordRAM.Realization.HoldsRecords.of_modifies_disjoint {stride base : ℕ} {rows : List (Fin stride → ℕ)} {S : Set ℕ} {s s' : DataStructure.Memory.State} (hb : { base := base, length := stride * rows.length }.Allocated s) (hh : HoldsRecords stride base rows s.mem) (hmod : DataStructure.Memory.Modifies S s s') (hdisj : Disjoint S (Set.Ico base (base + stride * rows.length))) :
HoldsRecords stride base rows s'.mem

A HoldsRecords predicate on an allocated block disjoint from S survives Memory.Modifies S s s'.

theorem Cslib.WordRAM.Realization.HoldsRecords.append_iff {stride base : ℕ} {rows₁ rows₂ : List (Fin stride → ℕ)} {mem : ℕ → ℕ} :
HoldsRecords stride base (rows₁ ++ rows₂) mem ↔ HoldsRecords stride base rows₁ mem ∧ HoldsRecords stride (base + stride * rows₁.length) rows₂ mem

Concatenating two consecutive HoldsRecords slices into one rows₁ ++ rows₂ slice.

theorem Cslib.WordRAM.Realization.HoldsRecords.copy {w stride src dst : ℕ} {rows : List (Fin stride → ℕ)} {s : DataStructure.Memory.State} (hdisj : src + stride * rows.length ≤ dst ∨ dst + stride * rows.length ≤ src) (hsrc : src + stride * rows.length ≤ s.frontier) (hdst : dst + stride * rows.length ≤ s.frontier) (hwf : DataStructure.Memory.WellFormed w s) (hrows : HoldsRecords stride src rows s.mem) :
DataStructure.Memory.FramedTriple w s (DataStructure.Memory.copy src dst (stride * rows.length)) (2 * (stride * rows.length)) (Set.Ico dst (dst + stride * rows.length)) fun (x : Unit) (s' : DataStructure.Memory.State) => s'.frontier = s.frontier ∧ DataStructure.Memory.WellFormed w s' ∧ HoldsRecords stride dst rows s'.mem

Non-overlapping Memory.copy transfers HoldsRecords stride src rows directly to HoldsRecords stride dst rows under Memory.FramedTriple.

Three-way dirty record concatenation (concatRecordsProg) #

Input arguments for concatenating three stride-stride record arrays into a freshly allocated dirty block.

  • stride : ℕ

    Fixed record width in words.

  • srcA : ℕ

    Base address of the first slice.

  • lenA : ℕ

    Number of records in the first slice.

  • srcB : ℕ

    Base address of the second slice.

  • lenB : ℕ

    Number of records in the second slice.

  • srcC : ℕ

    Base address of the third slice.

  • lenC : ℕ

    Number of records in the third slice.

@[reducible, inline]

The tuple word encoding of the fields of concatRecordsArgsWords.

theorem Cslib.WordRAM.Realization.concatRecordsArgsWords_fits {w : ℕ} {a : ConcatRecordsArgs} (h_stride : Fits w a.stride) (h_srcA : Fits w a.srcA) (h_lenA : Fits w a.lenA) (h_srcB : Fits w a.srcB) (h_lenB : Fits w a.lenB) (h_srcC : Fits w a.srcC) (h_lenC : Fits w a.lenC) (j✝ : Fin 7) :
theorem Cslib.DataStructure.Memory.FramedTriple.frame_empty_of_ge_frontier {α : Type} {w c : ℕ} {s : State} {p : Prog α} {S : Set ℕ} {Q : α → State → Prop} (h : FramedTriple w s p c S Q) (hge : ∀ a ∈ S, s.frontier ≤ a) :
FramedTriple w s p c ∅ Q

Shrink the modification set of a Memory.FramedTriple to ∅ when every address in S lies at or above s.frontier.

Concatenate three fixed-stride record slices into a freshly dirty-allocated Block of length a.stride * (a.lenA + a.lenB + a.lenC).

theorem Cslib.WordRAM.Realization.concatRecordsProg_spec {w stride srcA srcB srcC : ℕ} {rowsA rowsB rowsC : List (Fin stride → ℕ)} {s : DataStructure.Memory.State} (hwf : DataStructure.Memory.WellFormed w s) (hA : HoldsRecords stride srcA rowsA s.mem) (hA_lt : srcA + stride * rowsA.length ≤ s.frontier) (hB : HoldsRecords stride srcB rowsB s.mem) (hB_lt : srcB + stride * rowsB.length ≤ s.frontier) (hC : HoldsRecords stride srcC rowsC s.mem) (hC_lt : srcC + stride * rowsC.length ≤ s.frontier) (hfit : Fits w (s.frontier + stride * (rowsA.length + rowsB.length + rowsC.length))) :
have a := { stride := stride, srcA := srcA, lenA := rowsA.length, srcB := srcB, lenB := rowsB.length, srcC := srcC, lenC := rowsC.length }; have tot := rowsA.length + rowsB.length + rowsC.length; DataStructure.Memory.FramedTriple w s (concatRecordsProg a) (2 * (stride * tot) + 1) ∅ fun (out : Block) (s' : DataStructure.Memory.State) => out = { base := s.frontier, length := stride * tot } ∧ out.Allocated s' ∧ s'.frontier = s.frontier + stride * tot ∧ DataStructure.Memory.WellFormed w s' ∧ HoldsRecords stride out.base (rowsA ++ rowsB ++ rowsC) s'.mem

Framed specification for concatRecordsProg: allocates a dirty Block of size stride * (rowsA.length + rowsB.length + rowsC.length) at s.frontier, preserves all cells below s.frontier (Memory.Modifies ∅), realizes HoldsRecords stride out.base (rowsA ++ rowsB ++ rowsC) in cost at most 2 * (stride * (rowsA.length + rowsB.length + rowsC.length)) + 1, and preserves Memory.WellFormed.