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.Algorithms.Lean.IndexedMinPQ.spec.
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
SubroutineDScertificates 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 SubroutineDS.call_rename.
Main definitions #
Cslib.Algorithms.WordRAM.PriorityQueue.PQCode:SubroutineCode B r_pq 1equipped with standard priority-queue interface registers,encode,argMatch,decode, and inline caller blocks.Cslib.Algorithms.WordRAM.PriorityQueue.PQPackage: uniform code together with parametricSubroutineDScertificates and per-operation amortized charge bounds.
Main results #
PQCode.arguments_fit,PQCode.encode_matches: generic proof that the standard priority-queue encoding fits inw-bit words and satisfiesargMatch.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
- initParams : Fin 1 → 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.
Instances For
Translate a PQCode bundle along a basis simulation.
Instances For
Lift an exact-basis PQCode to Basis.standard.
Instances For
Standard register encoding for IndexedMinPQ.Op n using 1-bit tags (tag2, tag1, tag0).
Instances For
Partial argument-matching predicate for inline priority-queue calls.
Instances For
Standard output decoder for IndexedMinPQ.spec n K_max.
Instances For
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.
Basis-polymorphic inline caller blocks and execution lemmas #
Relocated inline call to isEmpty, copying 0 from zeroReg_c.
Instances For
Relocated inline call to extractMin, copying 1 from oneReg_c.
Instances For
Relocated inline call to getKey, copying 0, 1, and handle vReg_c.
Instances For
Relocated inline call to insert, copying 0, 1, handle vReg_c, and key kReg_c.
Instances For
Relocated inline call to decreaseKey, copying 0, 1, handle vReg_c, and key kReg_c.
Instances For
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 SubroutineDS
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.SubroutineDS self.code.toSubroutineCode (Lean.IndexedMinPQ.spec n K_max) w base ![n] (Lean.IndexedMinPQ.empty n)
Parametric
SubroutineDScertificate wheneverbase + space nandK_maxfit inwbits. - 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 : Lean.IndexedMinPQ.State n) : (self.cert hS hK).charge s Lean.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 : Lean.IndexedMinPQ.State n) (v : Fin n) : (self.cert hS hK).charge s (Lean.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 : Lean.IndexedMinPQ.State n) (v : Fin n) (k : ℕ) : (self.cert hS hK).charge s (Lean.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 : Lean.IndexedMinPQ.State n) (v : Fin n) (k : ℕ) : (self.cert hS hK).charge s (Lean.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 : Lean.IndexedMinPQ.State n) : (self.cert hS hK).charge s Lean.IndexedMinPQ.Op.extractMin ≤ self.extractTime n
Amortized charge bound for
extractMin.
Instances For
Translate a PQPackage along any basis simulation.
Instances For
Lift an exact-basis PQPackage to Basis.standard.