Word-RAM interface for indexed min-priority queues #
This file packages uniform Word-RAM calling conventions (PQCode) and parametric specification /
resource certificates (PQPackage) for Cslib.DataStructure.PriorityQueue.indexedMinPQSpec.
A PQPackage B r_pq bundles a SubroutineCode B r_pq 1 with:
- three 1-bit operation-tag registers (
tag2,tag1,tag0) taking values only in{0, 1}, so encoded operation arguments fit inw-bit words even at small word sizes (w ≥ 1); - standard argument registers (
argV,argK) and result registers (outFlag,outV,outK); - parametric
StateTransitionImplcertificates over(n, K_max, w, base)supporting arbitrary concrete potentialspotential : Data r_pq → ℕ(both worst-casepotential = 0heaps such asBinaryHeapand amortized heaps such asFibonacciHeap).
It also provides basis-polymorphic inline caller helpers (callIsEmpty, callGetKey, callInsert,
callDecreaseKey, callExtractMin) built from Op.copy and StateTransitionImpl.call_rename.
Main definitions #
Cslib.DataStructure.PriorityQueue.WordRAM.PQCode:SubroutineCode B r_pq 1equipped with standard priority-queue interface registers,encode,argMatch,decode,initRegs,prepareRegs,RunsOps, and inline caller blocks.Cslib.DataStructure.PriorityQueue.WordRAM.PQPackage: uniform code together with parametricStateTransitionImplcertificates and per-operation amortized charge bounds.
Main results #
PQCode.arguments_fit,PQCode.encode_matches,PQCode.prepareRegs_matches: generic proof that the standard priority-queue encoding fits inw-bit words and satisfiesargMatch.PQCode.run_ops_exact: generic standalone flat-program operation-sequence execution theorem over anyPQCode,StateTransitionImplcertificate, and initializer (initFreshorinitClear).PQCode.callIsEmpty_exec,PQCode.callGetKey_exec,PQCode.callInsert_exec,PQCode.callDecreaseKey_exec,PQCode.callExtractMin_exec: relocated inline operation calls with amortized potential accounting and bidirectional framing.
References #
Uniform machine code and register calling convention for an indexed min-priority queue over
basis B using r_pq local registers.
- frontierReg : Fin r_pq
- nReg : Fin r_pq
Register holding the handle-universe size
nat initialization (initParams = ![nReg]). - tag2 : Fin r_pq
High tag bit (
≠ 0selectsextractMin). - tag1 : Fin r_pq
Middle tag bit (
≠ 0selectsinsert/decreaseKeywhentag2 = 0). - tag0 : Fin r_pq
Low tag bit (
0selectsisEmpty/insert;≠ 0selectsgetKey/decreaseKey). - argV : Fin r_pq
Handle argument register (
v.valforgetKey,insert,decreaseKey). - argK : Fin r_pq
Key argument register (
kforinsert,decreaseKey). - outFlag : Fin r_pq
Flag output register (
1/0forisEmpty,getKey,extractMin). - outV : Fin r_pq
Extracted handle output register (
u.valfor non-emptyextractMin). - outK : Fin r_pq
Key output register (
kfor presentgetKeyand non-emptyextractMin). Initialization takes
ninnReg.Tag and argument registers are pairwise distinct.
tag2is a caller-overwritable input register.tag1is a caller-overwritable input register.tag0is a caller-overwritable input register.argVis a caller-overwritable input register.argKis a caller-overwritable input register.Primary halting output register is
outFlag.
Translate a PQCode bundle along a basis simulation.
Lift an exact-basis PQCode to Basis.standard.
Standard register encoding for IndexedMinPQ.Op n using 1-bit tags (tag2, tag1, tag0).
Partial argument-matching predicate for inline priority-queue calls.
Standard output decoder for indexedMinPQSpec n K_max.
Standard encoded arguments fit in w-bit words whenever n + 1 ≤ space,
Fits w (base + space), and Fits w K_max.
Full standalone prepare register delivery satisfies P.argMatch.
Standalone flat-program register conventions and operation-sequence execution #
Initial register assignment supplying n in P.nReg, base in P.frontierReg,
and 0 elsewhere.
P.initRegs n base places base in P.frontierReg.
P.initRegs n base supplies the single initialization parameter ![n].
Initial data built from P.initRegs n base is w-bounded when n, base, and mem₀ fit.
Deliver operation o's 3-bit tag into P.tag2..P.tag0 and its handle/key arguments into
P.argV, P.argK, leaving all other registers unchanged.
Delivering operation o via P.prepareRegs satisfies P.argMatch.
Sequential flat-program execution of ops by repeated calls to P.opProg: each call prepares
input registers via P.prepareRegs, runs P.opProg from pc = 0 to halt, decodes the exact
IndexedMinPQ result via P.decode, modifies memory only within [base, base + space), and
accumulates total instructions executed (including each trailing halt).
- nil {B : WordRAM.Basis} {r_pq : ℕ} {P : PQCode B r_pq} {n K_max space w base : ℕ} {s : IndexedMinPQ.State n} {x : WordRAM.Data r_pq} : P.RunsOps space w base s x [] x 0
- cons {B : WordRAM.Basis} {r_pq : ℕ} {P : PQCode B r_pq} {n K_max space w base : ℕ} {s : (indexedMinPQSpec n K_max).State} {x : WordRAM.Data r_pq} {o : IndexedMinPQ.Op n} {ops : List (IndexedMinPQ.Op n)} {pc : ℕ} {y z : WordRAM.Data r_pq} {steps rest : ℕ} : WordRAM.Runs w P.opProg { pc := 0, data := { regs := P.prepareRegs o x.regs, mem := x.mem } } { pc := pc, data := y } steps → (∃ (out : ℕ), WordRAM.step w P.opProg { pc := pc, data := y } = WordRAM.Outcome.halt out) → P.decode o y.regs = some ((indexedMinPQSpec n K_max).stepFn s o).2 → WordRAM.Modifies { base := base, length := space }.footprint x.mem y.mem → P.RunsOps space w base ((indexedMinPQSpec n K_max).stepFn s o).1 y ops z rest → P.RunsOps space w base s x (o :: ops) z (steps + 1 + rest)
Generic flat-program operation-sequence theorem for any PQCode, StateTransitionImpl
certificate C, and initializer block c (such as P.initFresh via C.initFresh_exec or
P.initClear via C.initClear_exec).
Basis-polymorphic inline caller blocks and execution lemmas #
Relocated inline call to isEmpty, copying 0 from zeroReg_c.
Relocated inline call to extractMin, copying 1 from oneReg_c.
Relocated inline call to getKey, copying 0, 1, and handle vReg_c.
Relocated inline call to insert, copying 0, 1, handle vReg_c, and key kReg_c.
Relocated inline call to decreaseKey, copying 0, 1, handle vReg_c, and key kReg_c.
Inline execution of P.callIsEmpty: preserves abstract state s, sets z.regs (f P.outFlag)
so z.regs (f P.outFlag) = 0 ↔ IndexedMinPQ.dom s ≠ ∅, and charges 3 + C.charge s .isEmpty.
Inline execution of P.callExtractMin: extracts findMin s and charges
1 + C.charge s .extractMin.
Inline execution of P.callInsert: inserts (v, k) and charges
5 + C.charge s (.insert v k).
Inline execution of P.callDecreaseKey: lowers v's key to k and charges
5 + C.charge s (.decreaseKey v k).
Inline execution of P.callGetKey: queries s v and charges 4 + C.charge s (.getKey v).
A priority-queue implementation over basis B with uniform PQCode B r_pq, memory footprint
space n, per-operation amortized instruction charges *Time n, and parametric
WordRAM.StateTransitionImpl
certificates supporting arbitrary concrete potentials potential : Data r_pq → ℕ.
- code : PQCode B r_pq
Uniform priority-queue code and register convention.
Memory footprint size on
nhandles ([base, base + space n)).Every priority queue on
nhandles reserves at leastn + 1words (n + 1 ≤ space n), so handle argumentsv < nfit inwbits viaFits w (base + space n)inPQCode.arguments_fit.Fresh-initialization instruction bound (
initFresh).Amortized instruction bound for
isEmpty.Amortized instruction bound for
getKey.Amortized instruction bound for
insert.Amortized instruction bound for
decreaseKey.Amortized instruction bound for
extractMin.- cert {n K_max w base : ℕ} : WordRAM.Fits w (base + self.space n) → WordRAM.Fits w K_max → WordRAM.StateTransitionImpl self.code.toSubroutineCode (indexedMinPQSpec n K_max) w base ![n] (IndexedMinPQ.empty n)
Parametric
StateTransitionImplcertificate wheneverbase + space nandK_maxfit inwbits. - rep_unique {n K_max w base : ℕ} (hS : WordRAM.Fits w (base + self.space n)) (hK : WordRAM.Fits w K_max) {s₁ s₂ : IndexedMinPQ.State n} {x : WordRAM.Data r_pq} : (self.cert hS hK).rep s₁ x → (self.cert hS hK).rep s₂ x → s₁ = s₂
Each concrete state represents at most one
IndexedMinPQ.State n. - cert_space {n K_max w base : ℕ} (hS : WordRAM.Fits w (base + self.space n)) (hK : WordRAM.Fits w K_max) : (self.cert hS hK).space = self.space n
Certificate footprint agrees with
space n. - cert_initTime {n K_max w base : ℕ} (hS : WordRAM.Fits w (base + self.space n)) (hK : WordRAM.Fits w K_max) : (self.cert hS hK).initTime ≤ self.initTime n
Fresh initialization runs within
initTime ninstructions. - cert_initPotential {n K_max w base : ℕ} (hS : WordRAM.Fits w (base + self.space n)) (hK : WordRAM.Fits w K_max) : (self.cert hS hK).initPotential = 0
Empty priority queue starts with
initPotential = 0. - cert_argMatch {n K_max w base : ℕ} (hS : WordRAM.Fits w (base + self.space n)) (hK : WordRAM.Fits w K_max) : (self.cert hS hK).argMatch = self.code.argMatch
- cert_decode {n K_max w base : ℕ} (hS : WordRAM.Fits w (base + self.space n)) (hK : WordRAM.Fits w K_max) : (self.cert hS hK).decode = self.code.decode
- charge_isEmpty {n K_max w base : ℕ} (hS : WordRAM.Fits w (base + self.space n)) (hK : WordRAM.Fits w K_max) (s : IndexedMinPQ.State n) : (self.cert hS hK).charge s IndexedMinPQ.Op.isEmpty ≤ self.emptyTime n
Amortized charge bound for
isEmpty. - charge_getKey {n K_max w base : ℕ} (hS : WordRAM.Fits w (base + self.space n)) (hK : WordRAM.Fits w K_max) (s : IndexedMinPQ.State n) (v : Fin n) : (self.cert hS hK).charge s (IndexedMinPQ.Op.getKey v) ≤ self.getTime n
Amortized charge bound for
getKey. - charge_insert {n K_max w base : ℕ} (hS : WordRAM.Fits w (base + self.space n)) (hK : WordRAM.Fits w K_max) (s : IndexedMinPQ.State n) (v : Fin n) (k : ℕ) : (self.cert hS hK).charge s (IndexedMinPQ.Op.insert v k) ≤ self.insertTime n
Amortized charge bound for
insert. - charge_decreaseKey {n K_max w base : ℕ} (hS : WordRAM.Fits w (base + self.space n)) (hK : WordRAM.Fits w K_max) (s : IndexedMinPQ.State n) (v : Fin n) (k : ℕ) : (self.cert hS hK).charge s (IndexedMinPQ.Op.decreaseKey v k) ≤ self.decreaseTime n
Amortized charge bound for
decreaseKey. - charge_extractMin {n K_max w base : ℕ} (hS : WordRAM.Fits w (base + self.space n)) (hK : WordRAM.Fits w K_max) (s : IndexedMinPQ.State n) : (self.cert hS hK).charge s IndexedMinPQ.Op.extractMin ≤ self.extractTime n
Amortized charge bound for
extractMin.
Translate a PQPackage along any basis simulation.
Lift an exact-basis PQPackage to Basis.standard.