Documentation

CslibFrontier.DataStructure.Dictionary.WordRAM.SuccinctWhpEpochTickProg.Internal.Common

Shared Helpers for Global Epoch Ticks #

This module provides shared header representations, Memory.Prog transition helpers, sequential proof combinators, Stage-2 scan preservation facts, and the rollover success predicate epochTickWillSucceed used across the split submodules of SuccinctWhpEpochTickProg.

Projection of the header-word and bucket-count invariants from FastMemRep.

theorem Cslib.DataStructure.Dictionary.WordRAM.SuccinctWhp.EpochTickInternal.fastMemHdrs {base c U V w n_max : ℕ} {fs : SuccinctWhp.FastState} {mem : ℕ → ℕ} (hrep : FastMemRep base c U V w n_max fs mem) :
FastMemHdrs base c U V w n_max fs mem

Extract FastMemHdrs from a full FastMemRep witness.

@[reducible, inline]

Named bucket accessor for a bufCheckSlotGenProg result (presentFlag, (bkt, loc)).

@[irreducible]

Read (tr.nodeAlloc, tr.itemAlloc) for buffer ep ∈ {0, 1} (d = (base, ep)).

theorem Cslib.DataStructure.Dictionary.WordRAM.SuccinctWhp.EpochTickInternal.readBufAllocsProg_spec {c U V w n_max base ep : ℕ} {fs : SuccinctWhp.FastState} {s : Memory.State} (_henv : WhpLargeEnv c U V w n_max w base) (hep : ep = 0 ∨ ep = 1) (hrep : FastMemRep base c U V w n_max fs s.mem) :

Cost and result specification for readBufAllocsProg.

theorem Cslib.DataStructure.Dictionary.WordRAM.SuccinctWhp.EpochTickInternal.bufClearStepsGenProg_fastStep {c U V w n_max base ep k : ℕ} {θ : SuccinctWhp.SeedWhp c U n_max} {fs : SuccinctWhp.FastState} {s : Memory.State} (henv : WhpLargeEnv c U V w n_max w base) (hep : ep = 0 ∨ ep = 1) (hclr : SuccinctWhp.ClearableBufTrie (fs.buf ep)) (hseed : SeedWhpMemRep base c U w n_max θ s.mem) (hrep : FastMemRep base c U V w n_max fs s.mem) :
have prog := bufClearStepsGenProg (((mkWhpCoreParams c U V w n_max, base), ep), k); have s' := (Memory.spec 0).clientState s prog; have tr' := SuccinctWhp.bufClearSteps k (fs.buf ep); WordRAM.Realization.memoryCost prog s ≤ 15 * k ∧ Succinct.ValidProg w (base + SuccinctWhp.largeSpaceWhp c U V w n_max) s prog ∧ FastStateStep base c U V w n_max θ { quotArr := fs.quotArr, valArr := fs.valArr, locState := fs.locState, bktCount := fs.bktCount, bktSalt := fs.bktSalt, liveRole := fs.liveRole, liveInsCount := fs.liveInsCount, overmarsRole := fs.overmarsRole, overmarsActive := fs.overmarsActive, overmarsCursor := fs.overmarsCursor, overmarsInsCount := fs.overmarsInsCount, rebDoneFlag := fs.rebDoneFlag, rebQueued := fs.rebQueued, backPtr := fs.backPtr, poolFreeTop := fs.poolFreeTop, poolFreeStack := fs.poolFreeStack, poolOwner := fs.poolOwner, slices := fs.slices, buf := Function.update fs.buf ep tr', curEp := fs.curEp, epochClock := fs.epochClock, rebStage := fs.rebStage, stageCursor := fs.stageCursor, dirtyCount := fs.dirtyCount, dirtyBuckets := fs.dirtyBuckets, dirtyIdx := fs.dirtyIdx, rebCandSalt := fs.rebCandSalt, rebScanCursor := fs.rebScanCursor, rebInsCount := fs.rebInsCount, rebCollision := fs.rebCollision } s s'

FastStateStep wrapper around bufClearStepsGenProg_spec.

Under CoreFastInv, every bucket's rebuild slice index is < 3 * numBucketsWhp n_max.

theorem Cslib.DataStructure.Dictionary.WordRAM.SuccinctWhp.EpochTickInternal.seqUnitProg_fastStep {c U V w n_max base c₁ c₂ : ℕ} {θ : SuccinctWhp.SeedWhp c U n_max} {fs₁ fs₂ : SuccinctWhp.FastState} {s : Memory.State} {p₁ p₂ : Memory.Prog Unit} (h₁ : WordRAM.Realization.memoryCost p₁ s ≤ c₁ ∧ Succinct.ValidProg w (base + SuccinctWhp.largeSpaceWhp c U V w n_max) s p₁ ∧ FastStateStep base c U V w n_max θ fs₁ s ((Memory.spec 0).clientState s p₁)) (h₂ : WordRAM.Realization.memoryCost p₂ ((Memory.spec 0).clientState s p₁) ≤ c₂ ∧ Succinct.ValidProg w (base + SuccinctWhp.largeSpaceWhp c U V w n_max) ((Memory.spec 0).clientState s p₁) p₂ ∧ FastStateStep base c U V w n_max θ fs₂ ((Memory.spec 0).clientState s p₁) ((Memory.spec 0).clientState ((Memory.spec 0).clientState s p₁) p₂)) :
WordRAM.Realization.memoryCost (do p₁ p₂) s ≤ c₁ + c₂ ∧ (Succinct.ValidProg w (base + SuccinctWhp.largeSpaceWhp c U V w n_max) s do p₁ p₂) ∧ FastStateStep base c U V w n_max θ fs₂ s ((Memory.spec 0).clientState s do p₁ p₂)

Compose two sequential Memory.Prog Unit FastStateStep transitions p₁ >>= fun _ => p₂.

theorem Cslib.DataStructure.Dictionary.WordRAM.SuccinctWhp.EpochTickInternal.writeHdrStep {c U V w n_max base hdrOff val : ℕ} {θ : SuccinctWhp.SeedWhp c U n_max} {fs : SuccinctWhp.FastState} {s : Memory.State} (henv : WhpLargeEnv c U V w n_max w base) (hhdr : 1 ≤ hdrOff ∧ hdrOff ≤ 11) (hfit_val : WordRAM.Fits w val) (hdc : hdrOff = 6 → val ≤ fs.dirtyCount) (hseed : SeedWhpMemRep base c U w n_max θ s.mem) (hrep : FastMemRep base c U V w n_max fs s.mem) :
have prog := writeHdrProg ((base, hdrOff), val); WordRAM.Realization.memoryCost prog s ≤ 1 ∧ Succinct.ValidProg w (base + SuccinctWhp.largeSpaceWhp c U V w n_max) s prog ∧ FastStateStep base c U V w n_max θ (updateFastHdr fs hdrOff val) s ((Memory.spec 0).clientState s prog)

Write mem[base + hdrOff] := val as a single FastStateStep with cost ≤ 1.

theorem Cslib.DataStructure.Dictionary.WordRAM.SuccinctWhp.EpochTickInternal.writeHdrZeroStep {c U V w n_max base hdrOff : ℕ} {θ : SuccinctWhp.SeedWhp c U n_max} {fs : SuccinctWhp.FastState} {s : Memory.State} (henv : WhpLargeEnv c U V w n_max w base) (hhdr : 1 ≤ hdrOff ∧ hdrOff ≤ 11) (hseed : SeedWhpMemRep base c U w n_max θ s.mem) (hrep : FastMemRep base c U V w n_max fs s.mem) :
have prog := writeHdrProg ((base, hdrOff), 0); WordRAM.Realization.memoryCost prog s ≤ 1 ∧ Succinct.ValidProg w (base + SuccinctWhp.largeSpaceWhp c U V w n_max) s prog ∧ FastStateStep base c U V w n_max θ (updateFastHdr fs hdrOff 0) s ((Memory.spec 0).clientState s prog)

Write 0 into any header slot hdrOff ∈ [1, 11] as a single FastStateStep (cost ≤ 1).

theorem Cslib.DataStructure.Dictionary.WordRAM.SuccinctWhp.EpochTickInternal.thenWriteHdr {c U V w n_max base hdrOff val c₁ : ℕ} {θ : SuccinctWhp.SeedWhp c U n_max} {fs₁ : SuccinctWhp.FastState} {s : Memory.State} {p₁ : Memory.Prog Unit} (henv : WhpLargeEnv c U V w n_max w base) (hhdr : 1 ≤ hdrOff ∧ hdrOff ≤ 11) (hfit_val : WordRAM.Fits w val) (hdc : hdrOff = 6 → val ≤ fs₁.dirtyCount) (h₁ : WordRAM.Realization.memoryCost p₁ s ≤ c₁ ∧ Succinct.ValidProg w (base + SuccinctWhp.largeSpaceWhp c U V w n_max) s p₁ ∧ FastStateStep base c U V w n_max θ fs₁ s ((Memory.spec 0).clientState s p₁)) :
have prog := do p₁ writeHdrProg ((base, hdrOff), val); WordRAM.Realization.memoryCost prog s ≤ c₁ + 1 ∧ Succinct.ValidProg w (base + SuccinctWhp.largeSpaceWhp c U V w n_max) s prog ∧ FastStateStep base c U V w n_max θ (updateFastHdr fs₁ hdrOff val) s ((Memory.spec 0).clientState s prog)

Append a writeHdrProg ((base, hdrOff), val) write onto an existing Memory.Prog Unit step.

Bundled specification for the shared 3-read prefix (oldEp, allocs, sc) of Stages 0, 1, 3.

theorem Cslib.DataStructure.Dictionary.WordRAM.SuccinctWhp.EpochTickInternal.stageCursorReads_spec {c U V w n_max base : ℕ} {fs : SuccinctWhp.FastState} {s : Memory.State} (henv : WhpLargeEnv c U V w n_max w base) (hce : fs.curEp = 0 ∨ fs.curEp = 1) (hold_or : fs.oldEp = 0 ∨ fs.oldEp = 1) (hrep : FastMemRep base c U V w n_max fs s.mem) :
StageCursorReads w (base + SuccinctWhp.largeSpaceWhp c U V w n_max) base fs.oldEp (fs.buf fs.oldEp).nodeAlloc (fs.buf fs.oldEp).itemAlloc fs.stageCursor s

Read (oldEp, (na, ia), stageCursor) under FastMemRep and fs.curEp ∈ {0, 1}.

theorem Cslib.DataStructure.Dictionary.WordRAM.SuccinctWhp.EpochTickInternal.stageCursorPrefix_ge_fastStep {c U V w n_max base tailCost maxCost : ℕ} {θ : SuccinctWhp.SeedWhp c U n_max} {fs fsOut : SuccinctWhp.FastState} {s : Memory.State} {kLt kGe : ℕ → ℕ × ℕ → ℕ → Memory.Prog Unit} {pBranch : Memory.Prog Unit} (hr : StageCursorReads w (base + SuccinctWhp.largeSpaceWhp c U V w n_max) base fs.oldEp (fs.buf fs.oldEp).nodeAlloc (fs.buf fs.oldEp).itemAlloc fs.stageCursor s) (hnlt : ¬fs.stageCursor < (fs.buf fs.oldEp).itemAlloc) (hBr_eq : kGe fs.oldEp ((fs.buf fs.oldEp).nodeAlloc, (fs.buf fs.oldEp).itemAlloc) fs.stageCursor = pBranch) (hBr_mc : WordRAM.Realization.memoryCost pBranch s ≤ tailCost) (hBr_vp : Succinct.ValidProg w (base + SuccinctWhp.largeSpaceWhp c U V w n_max) s pBranch) (hBr_step : FastStateStep base c U V w n_max θ fsOut s ((Memory.spec 0).clientState s pBranch)) (hCost : tailCost + 4 ≤ maxCost) :
have prog := do let oldEp ← readOldEpProg base let allocs ← readBufAllocsProg (base, oldEp) let sc ← readHdrProg (base, hdrStageCursor) if sc < allocs.2 then kLt oldEp allocs sc else kGe oldEp allocs sc; WordRAM.Realization.memoryCost prog s ≤ maxCost ∧ Succinct.ValidProg w (base + SuccinctWhp.largeSpaceWhp c U V w n_max) s prog ∧ FastStateStep base c U V w n_max θ fsOut s ((Memory.spec 0).clientState s prog)

Lift a verified itemAlloc ≤ stageCursor branch across the Stage 0/1/3 3-read prefix.

theorem Cslib.DataStructure.Dictionary.WordRAM.SuccinctWhp.EpochTickInternal.stageSlotCheckSeq_fastStep {c U V w n_max base midCost tailCost maxCost : ℕ} {θ : SuccinctWhp.SeedWhp c U n_max} {fs fsMid fsOut : SuccinctWhp.FastState} {s : Memory.State} {kLt kGe : ℕ → ℕ × ℕ → ℕ → Memory.Prog Unit} {kSlot : ℕ × ℕ × ℕ → Memory.Prog Unit} {pMid pTail : Memory.Prog Unit} {csRes : ℕ × ℕ × ℕ} (hr : StageCursorReads w (base + SuccinctWhp.largeSpaceWhp c U V w n_max) base fs.oldEp (fs.buf fs.oldEp).nodeAlloc (fs.buf fs.oldEp).itemAlloc fs.stageCursor s) (hlt : fs.stageCursor < (fs.buf fs.oldEp).itemAlloc) (hkLt : kLt fs.oldEp ((fs.buf fs.oldEp).nodeAlloc, (fs.buf fs.oldEp).itemAlloc) fs.stageCursor = bufCheckSlotGenProg (((mkWhpCoreParams c U V w n_max, base), fs.oldEp), fs.stageCursor) >>= kSlot) (hcs_st : (Memory.spec 0).clientState s (bufCheckSlotGenProg (((mkWhpCoreParams c U V w n_max, base), fs.oldEp), fs.stageCursor)) = s) (hcs_res : (Memory.spec 0).clientResult s (bufCheckSlotGenProg (((mkWhpCoreParams c U V w n_max, base), fs.oldEp), fs.stageCursor)) = csRes) (hcs_mc : WordRAM.Realization.memoryCost (bufCheckSlotGenProg (((mkWhpCoreParams c U V w n_max, base), fs.oldEp), fs.stageCursor)) s ≤ 12) (hcs_vp : Succinct.ValidProg w (base + SuccinctWhp.largeSpaceWhp c U V w n_max) s (bufCheckSlotGenProg (((mkWhpCoreParams c U V w n_max, base), fs.oldEp), fs.stageCursor))) (hSlot_eq : kSlot csRes = do pMid pTail) (hMid_mc : WordRAM.Realization.memoryCost pMid s ≤ midCost) (hMid_vp : Succinct.ValidProg w (base + SuccinctWhp.largeSpaceWhp c U V w n_max) s pMid) (hMid_step : FastStateStep base c U V w n_max θ fsMid s ((Memory.spec 0).clientState s pMid)) (hTail_mc : WordRAM.Realization.memoryCost pTail ((Memory.spec 0).clientState s pMid) ≤ tailCost) (hTail_vp : Succinct.ValidProg w (base + SuccinctWhp.largeSpaceWhp c U V w n_max) ((Memory.spec 0).clientState s pMid) pTail) (hTail_step : FastStateStep base c U V w n_max θ fsOut ((Memory.spec 0).clientState s pMid) ((Memory.spec 0).clientState ((Memory.spec 0).clientState s pMid) pTail)) (hCost : midCost + tailCost + 16 ≤ maxCost) :
have prog := do let oldEp ← readOldEpProg base let allocs ← readBufAllocsProg (base, oldEp) let sc ← readHdrProg (base, hdrStageCursor) if sc < allocs.2 then kLt oldEp allocs sc else kGe oldEp allocs sc; WordRAM.Realization.memoryCost prog s ≤ maxCost ∧ Succinct.ValidProg w (base + SuccinctWhp.largeSpaceWhp c U V w n_max) s prog ∧ FastStateStep base c U V w n_max θ fsOut s ((Memory.spec 0).clientState s prog)

Lift a bufCheckSlotGenProg continuation across stageCursorPrefix_lt_fastStep and seqUnitProg_fastStep.

theorem Cslib.DataStructure.Dictionary.WordRAM.SuccinctWhp.EpochTickInternal.tickToStage3Prog_fastStep {c U V w n_max base : ℕ} {θ : SuccinctWhp.SeedWhp c U n_max} {fs : SuccinctWhp.FastState} {s : Memory.State} (henv : WhpLargeEnv c U V w n_max w base) (hseed : SeedWhpMemRep base c U w n_max θ s.mem) (hrep : FastMemRep base c U V w n_max fs s.mem) :
have prog := tickToStage3Prog base; have s' := (Memory.spec 0).clientState s prog; WordRAM.Realization.memoryCost prog s ≤ 2 ∧ Succinct.ValidProg w (base + SuccinctWhp.largeSpaceWhp c U V w n_max) s prog ∧ FastStateStep base c U V w n_max θ { quotArr := fs.quotArr, valArr := fs.valArr, locState := fs.locState, bktCount := fs.bktCount, bktSalt := fs.bktSalt, liveRole := fs.liveRole, liveInsCount := fs.liveInsCount, overmarsRole := fs.overmarsRole, overmarsActive := fs.overmarsActive, overmarsCursor := fs.overmarsCursor, overmarsInsCount := fs.overmarsInsCount, rebDoneFlag := fs.rebDoneFlag, rebQueued := fs.rebQueued, backPtr := fs.backPtr, poolFreeTop := fs.poolFreeTop, poolFreeStack := fs.poolFreeStack, poolOwner := fs.poolOwner, slices := fs.slices, buf := fs.buf, curEp := fs.curEp, epochClock := fs.epochClock, rebStage := 3, stageCursor := 0, dirtyCount := fs.dirtyCount, dirtyBuckets := fs.dirtyBuckets, dirtyIdx := fs.dirtyIdx, rebCandSalt := fs.rebCandSalt, rebScanCursor := fs.rebScanCursor, rebInsCount := fs.rebInsCount, rebCollision := fs.rebCollision } s s'

FastStateStep specification for tickToStage3Prog.

@[irreducible]

Set (rebCandSalt, rebScanCursor, rebInsCount, rebCollision) := (cand, 0, 0, 0) (d = (base, cand)).

theorem Cslib.DataStructure.Dictionary.WordRAM.SuccinctWhp.EpochTickInternal.resetRebScanHdrsProg_fastStep {c U V w n_max base cand : ℕ} {θ : SuccinctWhp.SeedWhp c U n_max} {fs : SuccinctWhp.FastState} {s : Memory.State} (henv : WhpLargeEnv c U V w n_max w base) (hcand : WordRAM.Fits w cand) (hseed : SeedWhpMemRep base c U w n_max θ s.mem) (hrep : FastMemRep base c U V w n_max fs s.mem) :
have prog := resetRebScanHdrsProg (base, cand); have s' := (Memory.spec 0).clientState s prog; WordRAM.Realization.memoryCost prog s ≤ 4 ∧ Succinct.ValidProg w (base + SuccinctWhp.largeSpaceWhp c U V w n_max) s prog ∧ FastStateStep base c U V w n_max θ { quotArr := fs.quotArr, valArr := fs.valArr, locState := fs.locState, bktCount := fs.bktCount, bktSalt := fs.bktSalt, liveRole := fs.liveRole, liveInsCount := fs.liveInsCount, overmarsRole := fs.overmarsRole, overmarsActive := fs.overmarsActive, overmarsCursor := fs.overmarsCursor, overmarsInsCount := fs.overmarsInsCount, rebDoneFlag := fs.rebDoneFlag, rebQueued := fs.rebQueued, backPtr := fs.backPtr, poolFreeTop := fs.poolFreeTop, poolFreeStack := fs.poolFreeStack, poolOwner := fs.poolOwner, slices := fs.slices, buf := fs.buf, curEp := fs.curEp, epochClock := fs.epochClock, rebStage := fs.rebStage, stageCursor := fs.stageCursor, dirtyCount := fs.dirtyCount, dirtyBuckets := fs.dirtyBuckets, dirtyIdx := fs.dirtyIdx, rebCandSalt := cand, rebScanCursor := 0, rebInsCount := 0, rebCollision := 0 } s s'

FastStateStep specification for resetRebScanHdrsProg.

Frame invariant preserved across rebScanSteps c U n_max θ b k fs.

rebScanSteps c U n_max θ b k fs satisfies RebScanPreserved fs _ k.

Exact read-only rollover pre-condition guaranteeing (epochTick c U n_max θ fs).isSome.