Fibonacci Heap with Handles and Satellite Values #
This file implements the relational priority-queue specification
Cslib.DataStructure.PriorityQueue.minPQSpec
(returning an opaque handle h : Fin n_max on insert and (u, v, h) on extractMin) as a
Word-RAM StateTransitionImpl over Cslib.WordRAM.Basis.exact (and lifted to Basis.standard),
layered on top of Cslib.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.
Over capacity n_max in a contiguous memory block [base, base + 11 * n_max + 1):
[base, base + 9 * n_max + 1)holds the inner Fibonacci heap arrays (key,par,child,left,right,deg,mark,inHeap,cons);[base + (9 * n_max + 1), base + (10 * n_max + 1))holds satellite valuesval[0..n_max-1];[base + (10 * n_max + 1), base + (11 * n_max + 1))holds the recycled-handle stackfreeStack[0..n_max-1], paired with persistent bump pointerfreshRegand stack heightfreeTopReg.
Main definitions #
Cslib.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.MinPQ.rMinPQ,space,subroutineCode:48-register,(11 * n_max + 1)-wordSubroutineCode .exact rMinPQ 1.Cslib.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.MinPQ.Rep,charge: relational representation invariant and per-operation amortized instruction charges (O(log n + 1)onextractMinin the current number of stored elementsn = MinPQ.size s).Cslib.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.MinPQ.impl:StateTransitionImplcertificate overBasis.exact.Cslib.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.MinPQ.RunsClient: sequentialBasis.exactflat-program execution predicate for adaptiveClients.
Main results #
Cslib.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.MinPQ.amortized,run_client_amortized: standaloneAmortizedcertificate and adaptive-client bound overBasis.standard.Cslib.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.MinPQ.run_client_exact_fresh,run_client_exact_reusable: standaloneBasis.exactflat-program adaptive-client execution theorems.
References #
Total register count of the key–value Fibonacci heap with handle allocation.
Persistent base address of val[0..n_max-1] (base + 9 * n_max + 1). Also serves as the
relocated image of the inner FibonacciHeap.frontierReg.
Persistent base address of freeStack[0..n_max-1] (base + 10 * n_max + 1).
Persistent bump-pointer watermark fresh for never-allocated handles.
Persistent stack height freeTop for recycled handles in freeStack.
Caller input register carrying the satellite value v on insert.
Output register carrying the satellite value v on get and extractMin.
Injective register embedding from the inner rFib = 42 Fibonacci heap into rMinPQ = 48,
mapping FibonacciHeap.frontierReg (R[1]) to valBaseReg (R[42]) so outerFrontierReg
(R[1]) remains outside Set.range f42.
Persistent register holding handle capacity n_max (R[0]).
Persistent base address of key[0..n_max-1] (R[2]).
Persistent constant register 0 (R[11]).
Persistent constant register 1 (R[12]).
Caller high tag bit (R[17], ≠ 0 selects extractMin).
Caller middle tag bit (R[18]).
Caller low tag bit (R[19]).
Handle register (R[20], input for get/decreaseKey, scratch for insert).
Key input register (R[21], u for insert, u' for decreaseKey).
Primary output flag register (R[22]).
Output handle register (R[23], h.val for insert and non-empty extractMin).
Output key register (R[24], u for present get and non-empty extractMin).
Scratch pointer register for zeroFillCode (R[25]).
Scratch zero register for zeroFillCode (R[26]).
Scratch one register for zeroFillCode (R[27]).
Scratch address register (R[35]).
Persistent registers are 0..16 and 42..45 (false); caller/scratch registers are 17..41
and 46..47 (true).
Static memory footprint on capacity n_max: 11 * n_max + 1 words (9 * n_max + 1 for the
inner Fibonacci heap plus n_max for val and n_max for freeStack).
Instruction bound for isEmpty (including dispatch).
Instruction bound for get (including dispatch and value read).
Amortized instruction bound for insert (including handle allocation, value write, and +80
root potential).
Amortized instruction bound for decreaseKey (including dispatch and cascading cuts).
Amortized instruction bound for extractMin (420 * (Nat.log 2 n + 1)).
Per-operation amortized instruction charge for the key–value Fibonacci heap, charging
tExt (MinPQ.size s) on .extractMin in terms of the current number of stored elements
MinPQ.size s.
Since MinPQ.size s ≤ n_max, charge n_max s .extractMin ≤ tExt n_max.
Concrete integer potential 80 * (numRoots + 2 * numMarked) inherited from the inner
Fibonacci heap.
Structured Basis.exact subprograms and subroutineCode #
Copy outerFrontierReg into valBaseReg, run FibonacciHeap.allocSpan.rename f42 to set
baseReg = base and valBaseReg = base + 9 * n_max + 1, then advance freeBaseReg and
outerFrontierReg by n_max each (15 steps total).
Initialize freeBaseReg = outerFrontierReg - nReg, valBaseReg = freeBaseReg - nReg,
freshReg = 0, freeTopReg = 0, and run FibonacciHeap.initSetup.rename f42 (18 steps
total).
isEmpty: delegates directly to FibonacciHeap.isEmptyCode.rename f42.
get h: runs FibonacciHeap.getKeyCode.rename f42 and, when outFlag ≠ 0, loads the
satellite value outValReg ← val[argV].
Handle-allocation branch of insertCode: pops a recycled handle from
freeStack[freeTopReg - 1] when freeTopReg ≠ 0, or allocates freshReg and increments
freshReg when freeTopReg = 0.
insert u v: allocates a handle argV from freeStack (if freeTopReg > 0) or bumps
freshReg via allocHandleBranch, stores val[argV] ← inValReg, runs
FibonacciHeap.insertCode.rename f42 with key argK = u, and outputs outV ← argV.
decreaseKey h u': delegates directly to FibonacciHeap.decreaseKeyCode.rename f42.
extractMin: runs FibonacciHeap.extractMinCode.rename f42 and, when outFlag ≠ 0, loads
outValReg ← val[outV] and pushes outV onto freeStack[freeTopReg].
Unified dispatcher over 1-bit tags (tag2, tag1, tag0).
Uniform SubroutineCode .exact rMinPQ 1 for the key–value Fibonacci heap with handles.
Register encoding for PriorityQueue.MinPQ.Op n_max bounded by U on decreaseKey
so arguments_fit holds on arbitrary states; coincides with rawEncode on every operation
valid in a represented state (encode_eq_rawEncode_of_rep).
Full machine-state representation invariant for an internal allocator state
s : PriorityQueue.MinPQ.AllocState n_max.
Existential relational representation invariant over abstract state
e : PriorityQueue.MinPQ.State n_max.
Initialization: incCur_eval, allocSpan_exec, initSetup_exec #
Operation specifications: isEmptyCode, getCode, insertCode #
Unified dispatcher and WordRAM.StateTransitionImpl certificate #
Unified dispatcher dispatchCode implements all five MinPQ operations within
charge n_max e o amortized instructions over Basis.exact.
Unified standalone and inline-subroutine relational certificate for the key–value
Fibonacci heap with handles over Basis.exact.
Canonical native formats of key/value queue observations.
The native format is an equality presentation of each existing result type.
One fixed result bank: presence flag, key, satellite value, and handle.
Native conversion reads the actual original operation tags from the machine.
Insertion places its returned handle in the first payload slot and writes its presence tag; all other observations retain their payloads. Every flag is normalized to zero or one.
Conversion pays at most nine native instructions and changes only its two output slots.
The fixed native suffix preserves the heap representation and its amortized potential.
Original operation execution preserves the opcode words consumed by native conversion.
Standalone Basis.standard DynamicProgram and Amortized implementations #
Standalone DynamicProgram implementation of the key–value Fibonacci heap over
Basis.standard.
Standalone DynamicCertificate for the key–value Fibonacci heap over Basis.standard.
Standalone Amortized certificate for the key–value Fibonacci heap over
Basis.standard, charging nine native conversion instructions and one trailing halt
per operation.
Adaptive-client amortized execution bound for any demonically admissible MinPQ client p
over Basis.standard.
Standalone end-to-end Basis.exact flat-program adaptive-client theorems #
Compiled flat Program .exact rMinPQ for O(1) fresh zeroed-memory initialization.
Compiled flat Program .exact rMinPQ for O(n_max) dirty-memory reusable initialization.
Compiled flat Program .exact rMinPQ serving all five priority-queue operations.
Initial register assignment supplying n_max in nReg (R[0]), base in outerFrontierReg
(R[1]), and 0 elsewhere.
Deliver operation o's 3-bit tag into tag2..tag0 (R[17..19]), handle/key arguments into
argV, argK (R[20..21]), and satellite value into inValReg (R[46]), leaving all other
registers unchanged.
Sum of Nat.log 2 (MinPQ.size s) + 1 over all extractMin steps along a relational
transcript tr starting from state s, where MinPQ.size s is the number of stored elements
immediately before each extractMin.
Sequential flat-program execution of an adaptive client p : (minPQSpec n_max U V).Client α
by repeated calls to opProg: each .liftBind o k call prepares input registers via
prepareRegs, runs opProg from pc = 0 to halt, decodes a valid minPQSpec transition
(s₁, a), modifies memory only within [base, base + space n_max), continues with k a,
records the resulting return value v and transcript tr, and accumulates total instructions
executed (including each trailing halt).
- pure {n_max U V : ℕ} {α : Type u_1} {w base : ℕ} {s : MinPQ.State n_max} {x : WordRAM.Data rMinPQ} {a : α} : RunsClient w base s x (PFunctor.FreeM.pure a) a [] s x 0
- liftBind {n_max U V : ℕ} {α : Type u_1} {w base : ℕ} {s s₁ : (minPQSpec n_max U V).State} {s₂ : MinPQ.State n_max} {x : WordRAM.Data rMinPQ} {o : MinPQ.Op n_max} {k : (minPQSpec n_max U V).signature.B o → (minPQSpec n_max U V).signature.FreeM α} {a : (minPQSpec n_max U V).Result o} {v : α} {tr : (minPQSpec n_max U V).Transcript} {pc : ℕ} {y z : WordRAM.Data rMinPQ} {steps rest : ℕ} : WordRAM.Runs w opProg { pc := 0, data := { regs := prepareRegs o x.regs, mem := x.mem } } { pc := pc, data := y } steps → (∃ (out : ℕ), WordRAM.step w opProg { pc := pc, data := y } = WordRAM.Outcome.halt out) → (minPQSpec n_max U V).step s o s₁ a → decode o y.regs = some a → WordRAM.Modifies { base := base, length := space n_max }.footprint x.mem y.mem → RunsClient w base s₁ y (k a) v tr s₂ z rest → RunsClient w base s x (PFunctor.FreeM.liftBind o k) v ({ op := o, result := a, nextState := s₁ } :: tr) s₂ z (steps + 1 + rest)
Standalone Basis.exact adaptive-client theorem with O(1) fresh initialization on zeroed
[base, base + 11 * n_max + 1) and per-extraction O(log n + 1) amortized cost in the current
number of stored elements n = MinPQ.size s.
Standalone Basis.exact adaptive-client theorem with O(n_max) reusable initialization on
arbitrary w-bounded memory mem₀ and per-extraction O(log n + 1) amortized cost in the current
number of stored elements n = MinPQ.size s.