Documentation

CslibFrontier.Computability.WordRAM.Realization.ArrayOps

Reusable verified Word-RAM array primitives over Memory.Prog #

This module provides reusable verified array and block primitives over Memory.Prog, equipping both newly defined array routines (fillConstProg, prefixSumProg) and the existing memory operations (Memory.copy, Memory.allocBlock, Memory.allocBlockDirty) with uniform Realizes .exact certificates (work := 0) and Memory.FramedTriple specifications.

Main definitions #

Main results #

Constant fill (fillConstProg) #

Fill count consecutive cells [base, base + count) with val.

theorem Cslib.WordRAM.Realization.fillConstProg_spec {w base val count : ℕ} {s : DataStructure.Memory.State} (hwf : DataStructure.Memory.WellFormed w s) (hval : Fits w val) (hcount : Fits w count) (hbound : base + count ≤ s.frontier) :
DataStructure.Memory.FramedTriple w s (fillConstProg base val count) count (Set.Ico base (base + count)) fun (x : Unit) (s' : DataStructure.Memory.State) => s'.frontier = s.frontier ∧ DataStructure.Memory.WellFormed w s' ∧ ∀ j < count, s'.mem (base + j) = val

Framed specification for fillConstProg: fills [base, base + count) with val, preserves frontier and all cells outside [base, base + count), costs at most count, and preserves WellFormed.

theorem Cslib.WordRAM.Realization.realizes_fillConstProg :
Realizes Basis.exact (fun (x : (ℕ × ℕ) × ℕ) => match x with | ((base, val), count) => fillConstProg base val count) WordEncoding.encode WordEncoding.encode (fun (x : ℕ) (x_1 : (ℕ × ℕ) × ℕ) (s : DataStructure.Memory.State) => match x_1 with | ((base, snd), count) => base + count ≤ s.frontier) fun (x : (ℕ × ℕ) × ℕ) (x_1 : DataStructure.Memory.State) => 0

Uniform Realizes .exact certificate for fillConstProg with work = 0.

Uniform realization of Memory.copy #

theorem Cslib.WordRAM.Realization.realizes_copy :
Realizes Basis.exact (fun (x : (ℕ × ℕ) × ℕ) => match x with | ((src, dst), count) => DataStructure.Memory.copy src dst count) WordEncoding.encode WordEncoding.encode (fun (x : ℕ) (x_1 : (ℕ × ℕ) × ℕ) (s : DataStructure.Memory.State) => match x_1 with | ((src, dst), count) => src + count ≤ s.frontier ∧ dst + count ≤ s.frontier) fun (x : (ℕ × ℕ) × ℕ) (x_1 : DataStructure.Memory.State) => 0

Uniform Realizes .exact certificate for Memory.copy with work = 0.

In-place exclusive prefix sum (prefixSumProg) #

In-place exclusive prefix sum over [base, base + count): overwrites mem (base + j) with ∑ i ∈ Finset.range j, mem (base + i) for j < count, and returns the total sum ∑ i ∈ Finset.range count, mem (base + i).

theorem Cslib.WordRAM.Realization.prefixSumProg_spec {w base count : ℕ} {s : DataStructure.Memory.State} (hwf : DataStructure.Memory.WellFormed w s) (hcnt : Fits w count) (hbound : base + count ≤ s.frontier) (hsum : Fits w (∑ i ∈ Finset.range count, s.mem (base + i))) :
DataStructure.Memory.FramedTriple w s (prefixSumProg base count) (2 * count) (Set.Ico base (base + count)) fun (res : ℕ) (s' : DataStructure.Memory.State) => res = ∑ i ∈ Finset.range count, s.mem (base + i) ∧ s'.frontier = s.frontier ∧ DataStructure.Memory.WellFormed w s' ∧ ∀ j < count, s'.mem (base + j) = ∑ i ∈ Finset.range j, s.mem (base + i)

Framed specification for prefixSumProg: computes the in-place exclusive prefix sum over [base, base + count), returns the total sum ∑ i ∈ Finset.range count, s.mem (base + i), preserves frontier and all cells outside [base, base + count), costs at most 2 * count, and preserves WellFormed.

Uniform Realizes .exact certificate for prefixSumProg with work = 0.

Uniform realization and framed specs for Memory.allocBlock / Memory.allocBlockDirty #

Uniform Realizes .exact certificate for Memory.allocBlock with work = 0.

theorem Cslib.WordRAM.Realization.allocBlock_spec {w size : ℕ} {s : DataStructure.Memory.State} (hwf : DataStructure.Memory.WellFormed w s) (hfit : Fits w (s.frontier + size)) :
DataStructure.Memory.FramedTriple w s (DataStructure.Memory.allocBlock size) (size + 1) ∅ fun (b : Block) (s' : DataStructure.Memory.State) => b = { base := s.frontier, length := size } ∧ b.Allocated s' ∧ DataStructure.Memory.WellFormed w s' ∧ (∀ j < size, s'.mem (b.base + j) = 0) ∧ ∀ (b' : Block), b'.Allocated s → b'.Disjoint b

Framed specification for Memory.allocBlock: costs size + 1, preserves all cells below s.frontier (Memory.Modifies ∅), returns ⟨s.frontier, size⟩ allocated and zeroed, preserves WellFormed, and guarantees disjointness from every block previously allocated in s.

Uniform Realizes .exact certificate for Memory.allocBlockDirty with work = 0.

Framed specification for Memory.allocBlockDirty under Memory.ZeroAbove s: costs 1, modifies nothing below s.frontier (Memory.Modifies ∅), returns ⟨s.frontier, size⟩ allocated and zeroed, preserves WellFormed and ZeroAbove, and guarantees disjointness from every block previously allocated in s.