Bounded-capacity dictionary specification #
This file defines a deterministic abstract specification
(Cslib.Algorithms.Lean.Dictionary.spec) for a bounded-capacity dictionary mapping keys from a
finite universe Fin U to natural-number values bounded by V, supporting at most n_max
distinct stored keys at any point in time.
States map each key u : Fin U to Option ℕ (none when absent, some v when present with
value v). Following Cslib.Algorithms.Lean.IndexedMinPQ, values are represented as ℕ with the
bound v < V enforced by operation admissibility (valid), so Word-RAM realizations can encode
Option ℕ in a single machine register (0 for none and v + 1 for some v) without carrying
dependent Fin V proof obligations inside register decoding.
An insertion insert u v is admissible whenever v < V and either the current number of stored
keys (dom s).card is strictly below the capacity bound n_max, or u is already present in s
(in which case updating s u to some v overwrites the existing value in place without increasing
(dom s).card). This specification models lookup-and-insert dictionaries without a deletion
operation.
Main definitions #
Cslib.Algorithms.Lean.Dictionary.Op: dictionary operations (get,insert).Cslib.Algorithms.Lean.Dictionary.State,empty,dom: abstract map state, empty dictionary, and finite set of present keys.Cslib.Algorithms.Lean.Dictionary.ValuesBounded: invariant that all stored values lie belowV.Cslib.Algorithms.Lean.Dictionary.spec: theCslib.Stateful.Specwith universeU, value boundV, and capacity boundn_max.
Main results #
dom_empty,card_dom_empty,dom_insert: domain evolution under initialization and insertion.card_dom_insert_le,card_dom_insert_eq_of_isSome,card_dom_insert_eq_of_eq_none: cardinality laws fordomunder in-place updates and new-key insertions.card_dom_step_le_of_valid,card_dom_run_le_of_validHistory,card_dom_run_empty_le: any admissible operation history starting fromempty Umaintains(dom s).card ≤ n_max.valuesBounded_empty,valuesBounded_step_of_valid,valuesBounded_run_of_validHistory: any admissible operation history maintainsValuesBounded V s.
References #
Lookup and insertion operations on a dictionary over keys Fin U and natural-number values.
- get {U : ℕ} (u : Fin U) : Op U
Look up the value associated with key
u, if present. - insert {U : ℕ} (u : Fin U) (v : ℕ) : Op U
Associate key
uwith valuev, insertinguif absent or overwriting its value if present.
Instances For
Instances For
The empty dictionary on Fin U.
Instances For
Bounded-capacity dictionary specification over key universe Fin U, value bound V, and
maximum key count n_max.
Instances For
Domain, capacity, and value-bound lemmas #
Any admissible operation history preserves (dom s).card ≤ n_max.
Any admissible operation history starting from empty U reaches a state with at most n_max
keys.
The empty dictionary satisfies ValuesBounded V.
Any single admissible dictionary operation preserves ValuesBounded V.
Any admissible operation history preserves ValuesBounded V.