Documentation

CslibFrontier.DataStructure.Dictionary.WordRAM.ResizableSuccinct.Migration.ParamsCompute.Primitives

Shared Low-Level Memory.Prog Combinators, Bounded log₂ Loop, and Block Writers #

Internal primitive evaluators, Fits offset helpers, bounded floor-log₂ iteration (log2CapProg), saturating/min/max/zero-branch combinators, and 3/4/8-word contiguous block writers shared across the ParamsCompute submodules.

Word-Width Fits and Ceiling-Logarithm Helpers #

Any word width accommodating 225 satisfies 8 ≤ w.

Whenever Fits w 225, 3 * w + 5 also fits in w bits.

theorem Cslib.DataStructure.Dictionary.WordRAM.ResizableSuccinct.ParamsComputeAux.fits_add_of_fits_offCompItems {w U N dstMetaBase k : ℕ} (hfit_dst : WordRAM.Fits w (dstMetaBase + offCompItems U w N)) (hk : k ≤ 225) :
WordRAM.Fits w (dstMetaBase + k)

Any header offset dstMetaBase + k with k ≤ 225 fits in w bits when dstMetaBase + offCompItems U w N fits.

The end of the hash-table region (dstMetaBase + epochHdrWords) + epochHashSpace U w N fits in w bits when dstMetaBase + offCompItems U w N fits.

Exact ceiling-to-floor binary logarithm identity ⌈log₂ x⌉ = ⌊log₂ (x - 1)⌋ + 1 for 1 < x.

Shifted ceiling-to-floor binary logarithm identity ⌈log₂ (m + 1)⌉ = ⌊log₂ m⌋ + 1 for 1 ≤ m.

Bounded Floor-log₂ Loop (log2CapProg) #

Bounded K-step evaluator computing min K (Nat.log 2 x₀) via iterate.

theorem Cslib.DataStructure.Dictionary.WordRAM.ResizableSuccinct.ParamsComputeAux.log2CapProg_spec {w hdrAddr K x₀ : ℕ} {s₀ : Memory.State} (hfr : hdrAddr < s₀.frontier) (hx₀ : WordRAM.Fits w x₀) (hK : WordRAM.Fits w (min K (Nat.log 2 x₀) + 1)) :
have prog := log2CapProg (hdrAddr, K, x₀); Log2CapPre w (hdrAddr, K, x₀) s₀ ∧ (Memory.spec w).ValidHistory s₀ ((Memory.spec w).clientHistory s₀ prog) ∧ WordRAM.Realization.memoryCost prog s₀ ≤ K ∧ (Memory.spec 0).clientState s₀ prog = s₀ ∧ (Memory.spec 0).clientResult s₀ prog = min K (Nat.log 2 x₀)

Functional specification and ≤ K cost bound for log2CapProg.

Pure Scalar Combinators and Read/Write Step Helpers #

theorem Cslib.DataStructure.Dictionary.WordRAM.ResizableSuccinct.ParamsComputeAux.validHistory_read_step {α : Type} {w a fr : ℕ} {mem : ℕ → ℕ} {k : ℕ → Memory.Prog α} (ha : a < fr) (hk : (Memory.spec w).ValidHistory { mem := mem, frontier := fr } ((Memory.spec w).clientHistory { mem := mem, frontier := fr } (k (mem a)))) :
(Memory.spec w).ValidHistory { mem := mem, frontier := fr } ((Memory.spec w).clientHistory { mem := mem, frontier := fr } (Memory.read a >>= k))

ValidHistory step lemma for a single Memory.read.

theorem Cslib.DataStructure.Dictionary.WordRAM.ResizableSuccinct.ParamsComputeAux.validHistory_write_step {α : Type} {w a v fr : ℕ} {mem : ℕ → ℕ} {k : Unit → Memory.Prog α} (ha : a < fr) (hv : WordRAM.Fits w v) (hk : (Memory.spec w).ValidHistory { mem := Function.update mem a v, frontier := fr } ((Memory.spec w).clientHistory { mem := Function.update mem a v, frontier := fr } (k ()))) :
(Memory.spec w).ValidHistory { mem := mem, frontier := fr } ((Memory.spec w).clientHistory { mem := mem, frontier := fr } (Memory.write a v >>= k))

ValidHistory step lemma for a single Memory.write.

Saturating natural subtraction a - b in Memory.Prog without underflow.

Zero-comparison conditional if x = 0 then tVal else fVal in Memory.Prog.

Contiguous 3-, 4-, and 8-Word Block Writers #

theorem Cslib.DataStructure.Dictionary.WordRAM.ResizableSuccinct.ParamsComputeAux.writeBlock3Prog_spec {w : ℕ} (base v0 v1 v2 : ℕ) {s : Memory.State} (hfr : base + 3 ≤ s.frontier) (hfit_end : WordRAM.Fits w (base + 2)) (hv0 : WordRAM.Fits w v0) (hv1 : WordRAM.Fits w v1) (hv2 : WordRAM.Fits w v2) :
have d := (base, v0, v1, v2); have prog := writeBlock3Prog d; have s' := (Memory.spec 0).clientState s prog; WriteBlock3Pre w d s ∧ (Memory.spec w).ValidHistory s ((Memory.spec w).clientHistory s prog) ∧ s'.frontier = s.frontier ∧ (s'.mem base = v0 ∧ s'.mem (base + 1) = v1 ∧ s'.mem (base + 2) = v2) ∧ (∀ (a : ℕ), ¬(base ≤ a ∧ a < base + 3) → s'.mem a = s.mem a) ∧ WordRAM.Realization.memoryCost prog s = 3
theorem Cslib.DataStructure.Dictionary.WordRAM.ResizableSuccinct.ParamsComputeAux.writeBlock4Prog_spec {w : ℕ} (base v0 v1 v2 v3 : ℕ) {s : Memory.State} (hfr : base + 4 ≤ s.frontier) (hfit_end : WordRAM.Fits w (base + 3)) (hv0 : WordRAM.Fits w v0) (hv1 : WordRAM.Fits w v1) (hv2 : WordRAM.Fits w v2) (hv3 : WordRAM.Fits w v3) :
have d := (base, (v0, v1), v2, v3); have prog := writeBlock4Prog d; have s' := (Memory.spec 0).clientState s prog; WriteBlock4Pre w d s ∧ (Memory.spec w).ValidHistory s ((Memory.spec w).clientHistory s prog) ∧ s'.frontier = s.frontier ∧ (s'.mem base = v0 ∧ s'.mem (base + 1) = v1 ∧ s'.mem (base + 2) = v2 ∧ s'.mem (base + 3) = v3) ∧ (∀ (a : ℕ), ¬(base ≤ a ∧ a < base + 4) → s'.mem a = s.mem a) ∧ WordRAM.Realization.memoryCost prog s = 4
theorem Cslib.DataStructure.Dictionary.WordRAM.ResizableSuccinct.ParamsComputeAux.writeTwoBlock4Fin_spec {w n : ℕ} (base : ℕ) (g : Fin n → ℕ) (off : ℕ) (hoff : off + 8 ≤ n) {s : Memory.State} (hfr : base + 8 ≤ s.frontier) (hfit_end : WordRAM.Fits w (base + 7)) (hg : ∀ (i : Fin n), WordRAM.Fits w (g i)) :
have b0 := ((g ⟨off, ⋯⟩, g ⟨off + 1, ⋯⟩), g ⟨off + 2, ⋯⟩, g ⟨off + 3, ⋯⟩); have b1 := ((g ⟨off + 4, ⋯⟩, g ⟨off + 5, ⋯⟩), g ⟨off + 6, ⋯⟩, g ⟨off + 7, ⋯⟩); have prog := do writeBlock4Prog (base, b0) writeBlock4Prog (base + 4, b1); have s' := (Memory.spec 0).clientState s prog; (Memory.spec w).ValidHistory s ((Memory.spec w).clientHistory s prog) ∧ s'.frontier = s.frontier ∧ (∀ (j : ℕ) (hj : j < 8), s'.mem (base + j) = g ⟨off + j, ⋯⟩) ∧ (∀ (a : ℕ), ¬(base ≤ a ∧ a < base + 8) → s'.mem a = s.mem a) ∧ WordRAM.Realization.memoryCost prog s = 8

Specification for two consecutive writeBlock4Prog calls writing slice [off, off + 8) of g : Fin n → ℕ into [base, base + 8).

theorem Cslib.DataStructure.Dictionary.WordRAM.ResizableSuccinct.ParamsComputeAux.writeTwoBlock4FinRet_spec {w n : ℕ} (base : ℕ) (g : Fin n → ℕ) (off : ℕ) (hoff : off + 8 ≤ n) (ret : ℕ) {s : Memory.State} (hfr : base + 8 ≤ s.frontier) (hfit_end : WordRAM.Fits w (base + 7)) (hg : ∀ (i : Fin n), WordRAM.Fits w (g i)) :
have b0 := ((g ⟨off, ⋯⟩, g ⟨off + 1, ⋯⟩), g ⟨off + 2, ⋯⟩, g ⟨off + 3, ⋯⟩); have b1 := ((g ⟨off + 4, ⋯⟩, g ⟨off + 5, ⋯⟩), g ⟨off + 6, ⋯⟩, g ⟨off + 7, ⋯⟩); have prog := do writeBlock4Prog (base, b0) writeBlock4Prog (base + 4, b1) pure ret; have s' := (Memory.spec 0).clientState s prog; (Memory.spec w).ValidHistory s ((Memory.spec w).clientHistory s prog) ∧ (Memory.spec 0).clientResult s prog = ret ∧ s'.frontier = s.frontier ∧ (∀ (j : ℕ) (hj : j < 8), s'.mem (base + j) = g ⟨off + j, ⋯⟩) ∧ (∀ (a : ℕ), ¬(base ≤ a ∧ a < base + 8) → s'.mem a = s.mem a) ∧ WordRAM.Realization.memoryCost prog s = 8

Specification for two consecutive writeBlock4Prog calls followed by pure ret.