Min-priority queue state-transition specifications #
This file defines two abstract state-transition specifications
(Cslib.DataStructure.StateTransitionSpec) for min-priority queues over finite handles:
Cslib.DataStructure.PriorityQueue.indexedMinPQSpec n K_max: a deterministic, graph-free specification for an indexed min-priority queue over caller-chosen handlesFin nand natural-number keys bounded byK_max(used by graph algorithms such as Dijkstra's algorithm). Equal-key ties inextractMinare broken deterministically by smallest handle index (IndexedMinPQ.PrioLE).Cslib.DataStructure.PriorityQueue.minPQSpec n_max U V: a relational specification for a bounded-capacity min-priority queue storing key–value entries(u, v)(u < U,v < V) addressed by handlesh : Fin n_maxallocated by the data structure (insert u vnondeterministically chooses any unused handlehandextractMinnondeterministically removes any minimum-key entry), together with a deterministic free-list handle allocator (MinPQ.AllocState,MinPQ.stepAlloc) refiningminPQSpec.
Main definitions #
Cslib.DataStructure.PriorityQueue.IndexedMinPQ.Op,State,empty,dom,PrioLE,PrioLT,findMin,numQueries,numInserts,numDecreaseKeys,numExtractMins: operations, state, priority orders, minimum selector, and operation-sequence counters for indexed min-priority queues.Cslib.DataStructure.PriorityQueue.indexedMinPQSpec: deterministicStateTransitionSpecfor indexed min-priority queues with key boundK_max.Cslib.DataStructure.PriorityQueue.MinPQ.State,dom,size,Op,Op.Result,isMinEntry: operations, state, and minimum-entry predicate for handle-allocating min-priority queues.Cslib.DataStructure.PriorityQueue.minPQSpec: relationalStateTransitionSpecfor handle-allocating min-priority queues.Cslib.DataStructure.PriorityQueue.MinPQ.AllocState,stepAlloc: deterministic free-list handle allocator and lexicographic tie-breaking transition refiningminPQSpec.
Main results #
Cslib.DataStructure.PriorityQueue.IndexedMinPQ.not_rawPrioLT_iff_rawPrioLE,not_prioLT_iff_prioLE,prioLT_or_prioLT_of_ne: relationship between strict and weak lexicographic priority orders.Cslib.DataStructure.PriorityQueue.IndexedMinPQ.dom_empty,dom_insert,dom_decreaseKey,dom_extractMin: domain evolution under each indexed priority-queue operation.Cslib.DataStructure.PriorityQueue.IndexedMinPQ.findMin_eq_none_iff,findMin_eq_some_iff,findMin_mem_dom,findMin_le,findMin_key_le,totalCost_le: characterization and optimality ofIndexedMinPQ.findMin, and per-kind history cost bounds.Cslib.DataStructure.PriorityQueue.MinPQ.instTotalSpec:minPQSpec n_max U Vis total (StateTransitionSpec.Total).Cslib.DataStructure.PriorityQueue.MinPQ.stepAlloc_refines_spec: every validstepAlloctransition satisfies(minPQSpec n_max U V).stepand preservesAllocState.WellFormed.Cslib.DataStructure.PriorityQueue.MinPQ.toIndexed_update_some,toIndexed_update_none:toIndexedcommutes withFunction.updateon active and cleared handles.
References #
Operations on an indexed min-priority queue over handles Fin n and natural-number keys.
- isEmpty {n : ℕ} : Op n
Test whether the queue holds no handles.
- getKey {n : ℕ} (v : Fin n) : Op n
Query the current key of handle
v, if present. - insert {n : ℕ} (v : Fin n) (k : ℕ) : Op n
Insert an absent handle
vwith keyk. - decreaseKey {n : ℕ} (v : Fin n) (k : ℕ) : Op n
Lower the key of a present handle
vtok. - extractMin {n : ℕ} : Op n
Remove and return the present
(handle, key)pair of minimum(key, handle).
Instances For
Abstract state of an indexed min-priority queue on Fin n.
The empty priority queue on Fin n.
Graph-free indexed min-priority queue specification with key upper bound K_max.
Operation counts and per-kind cost bounds #
Count decreaseKey operations in an operation sequence.
Count extractMin operations in an operation sequence.
Bound totalCost of an indexed priority-queue history by per-kind charge upper bounds.
Abstract state of a min-priority queue of capacity n_max: each handle h : Fin n_max is
either unused (none) or stores a key–value pair some (u, v).
Initial empty priority queue with all handles unused.
The current number of stored elements in s.
Operations of a min-priority queue with handles of capacity n_max.
- isEmpty {n_max : ℕ} : Op n_max
Test whether the priority queue currently stores no elements.
- get {n_max : ℕ} (h : Fin n_max) : Op n_max
Query the
(key, value)pair currently stored at handleh(noneifhis inactive). - insert {n_max : ℕ} (u v : ℕ) : Op n_max
Insert a new entry with key
uand valuev, returning its allocated handlesome h. - decreaseKey {n_max : ℕ} (h : Fin n_max) (u' : ℕ) : Op n_max
Decrease the key at active handle
htou'. - extractMin {n_max : ℕ} : Op n_max
Remove and return a minimum-key entry
some (u, v, h), ornoneif empty.
Domain, element count, and minimum-entry lemmas #
Project a key–value priority-queue state to an IndexedMinPQ.State n_max by retaining only the
key at each handle.
Pure relational specification of a capacity-n_max min-priority queue with handles storing keys
u < U and values v < V:
insert u vnondeterministically chooses any unused handleh : Fin n_max(s h = none);extractMinnondeterministically removes and returns any stored entry(u, v, h)attaining the minimum key (MinPQ.isMinEntry s h u v), ornonewhenMinPQ.dom s = ∅.
Instances For
Every admissible MinPQ operation has at least one valid relational transition:
insert finds an unused handle by pigeonhole (exists_none_of_size_lt), and extractMin on a
nonempty queue selects a minimum-key entry (exists_isMinEntry_of_dom_ne_empty).
Invariant of the free-list + bump-pointer handle allocator:
Deterministic handle allocation: pops the head of s.freeList when nonempty, or allocates the
bump-pointer handle ⟨s.fresh, _⟩ and increments fresh when s.freeList = [] and
s.fresh < n_max.
Deterministic transition on AllocState n_max using allocHandle for insert and
findMin s.entries (lexicographic (key, handle) tie-breaking) for extractMin.
On any well-formed AllocState with size s.entries < n_max, allocHandle s succeeds,
returns an unused handle h (s.entries h = none), and preserves AllocState.WellFormed after
storing some (u, v) at h.
Every valid operation on a well-formed AllocState stepped by stepAlloc:
- satisfies the relational transition
(minPQSpec n_max U V).step s.entries o (stepAlloc s o).1.entries (stepAlloc s o).2, and - preserves
AllocState.WellFormed.