Documentation

CslibFrontier.DataStructure.PriorityQueue.WordRAM.Decode

Decoding indexed priority-queue answers #

These equations apply the existing PQCode.decode to actual output-register values. Presence flags may be any nonzero word; keys and handles are unshifted, and extraction retains the decoder's handle-range check. These generic decoding equations alone imply no execution or word bounds. For native typed calls, nativeResultCode_spec certifies an actual paid suffix that normalizes flags and copies lookup keys to one fixed canonical result bank.

Main results #

theorem Cslib.DataStructure.PriorityQueue.WordRAM.PQCode.decode_isEmpty {B : WordRAM.Basis} {r n K : ℕ} (P : PQCode B r) (regs : Fin r → ℕ) {b : Bool} (hflag : regs P.outFlag = b.toNat) :

A canonical Boolean output flag decodes to that Boolean.

theorem Cslib.DataStructure.PriorityQueue.WordRAM.PQCode.decode_getKey_none {B : WordRAM.Basis} {r n K : ℕ} (P : PQCode B r) (regs : Fin r → ℕ) (v : Fin n) (hflag : regs P.outFlag = 0) :

A zero flag decodes to an absent key, regardless of the unused key register.

theorem Cslib.DataStructure.PriorityQueue.WordRAM.PQCode.decode_getKey_some {B : WordRAM.Basis} {r n K : ℕ} (P : PQCode B r) (regs : Fin r → ℕ) (v : Fin n) {k : ℕ} (hflag : regs P.outFlag ≠ 0) (hkey : regs P.outK = k) :

A nonzero flag decodes the actual unshifted key register.

A zero flag decodes to no extracted entry, even when no handle exists.

theorem Cslib.DataStructure.PriorityQueue.WordRAM.PQCode.decode_extractMin_some {B : WordRAM.Basis} {r n K : ℕ} (P : PQCode B r) (regs : Fin r → ℕ) (v : Fin n) {k : ℕ} (hflag : regs P.outFlag ≠ 0) (hhandle : regs P.outV = ↑v) (hkey : regs P.outK = k) :

A nonzero flag with an actual in-range handle and key decodes to that typed entry.

Canonical structural result format for indexed queues. Its layout depends only on the result type: flag, then optional handle and key words.

The indexed queue's explicit canonical result type agrees definitionally with its result.

One fixed output bank: tag, handle (or the copied lookup key), and extraction key.

The original dispatch tag bits identify the completed operation. The paid conversion reads these machine words; the operation parameter only states the required precondition.

Paid result conversion: lookup copies its key to the common first payload slot, and every presence/Boolean flag is reduced to exactly zero or one by native control.

theorem Cslib.DataStructure.PriorityQueue.WordRAM.PQCode.nativeResultCode_spec {r : ℕ} (P : PQCode WordRAM.Basis.standard r) (zero : Fin r) (hfv : P.outFlag ≠ P.outV) (hfk : P.outFlag ≠ P.outK) (hvz : P.outV ≠ zero) {w : ℕ} {x : WordRAM.Data r} (h1 : WordRAM.Fits w 1) (hzero : x.regs zero = 0) {n K : ℕ} (o : IndexedMinPQ.Op n) (a : (indexedMinPQSpec n K).Result o) (hready : P.nativeResultReady o x) (hd : P.decode o x.regs = some a) :
∃ (y : WordRAM.Data r), WordRAM.ExecWithin w (P.nativeResultCode zero) x y 8 ∧ (nativeResultType n o).decode (y.regs ∘ P.nativeResultBank) 0 = some (cast ⋯ a) ∧ y.mem = x.mem ∧ ∀ (i : Fin r), i ≠ P.outFlag → i ≠ P.outV → y.regs i = x.regs i

The conversion runs within eight instructions, produces the canonical observation, and preserves all memory and all registers except the two result slots it writes.

def Cslib.DataStructure.PriorityQueue.WordRAM.PQCode.nativeResultRecoding {r : ℕ} (P : PQCode WordRAM.Basis.standard r) {w base n K : ℕ} {params : Fin 1 → ℕ} {s₀ : IndexedMinPQ.State n} (C : WordRAM.StateTransitionImpl P.toSubroutineCode (indexedMinPQSpec n K) w base params s₀) (zero : Fin r) (h1 : WordRAM.Fits w 1) (hzero : ∀ {s : (indexedMinPQSpec n K).State} {x : WordRAM.Data r}, C.rep s x → x.regs zero = 0) (hfv : P.outFlag ≠ P.outV) (hfk : P.outFlag ≠ P.outK) (hvz : P.outV ≠ zero) (hflag : P.input P.outFlag = true) (hvalue : P.input P.outV = true) (hdecode : C.decode = P.decode) :

Convert a checked indexed-queue implementation to canonical native observations. The caller supplies its zero register and verifies that both output slots are outside persistent state.