Documentation

CslibFrontier.DataStructure.Dictionary.Spec

Bounded-capacity dictionary specification #

This file defines a deterministic abstract specification (Cslib.DataStructure.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.DataStructure.PriorityQueue.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 #

Main results #

References #

Lookup and insertion operations on a dictionary over keys Fin U and natural-number values.

  • query {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 u with value v, inserting u if absent or overwriting its value if present.

Instances For
    @[instance_reducible]
    def Cslib.DataStructure.Dictionary.instDecidableEqOp.decEq {U✝ : ℕ} (x✝ x✝¹ : Op U✝) :
    Decidable (x✝ = x✝¹)
    @[instance_reducible]
    @[reducible, inline]

    Abstract state of a dictionary over universe Fin U.

    The empty dictionary on Fin U.

    The finite set of keys currently present in state s.

    Predicate asserting that every value stored in state s is strictly less than V.

    @[reducible, inline]

    Return type for each Op U.

    @[reducible, inline]
    abbrev Cslib.DataStructure.Dictionary.step {U : ℕ} (s : State U) (o : Op U) :

    Pure transition function for dictionary operations.

    @[reducible, inline]
    abbrev Cslib.DataStructure.Dictionary.valid {U : ℕ} (V n_max : ℕ) (s : State U) :
    Op U → Prop

    Admissibility precondition for dictionary operations.

    @[reducible, inline]

    Bounded-capacity dictionary specification over key universe Fin U, value bound V, and maximum key count n_max.

    Domain, capacity, and value-bound lemmas #

    @[simp]

    A key belongs to dom s if and only if (s u).isSome.

    theorem Cslib.DataStructure.Dictionary.mem_dom_iff {U : ℕ} {s : State U} {u : Fin U} :
    u ∈ dom s ↔ ∃ (v : ℕ), s u = some v

    A key belongs to dom s if and only if s u = some v for some value v.

    theorem Cslib.DataStructure.Dictionary.notMem_dom_iff {U : ℕ} {s : State U} {u : Fin U} :
    u ∉ dom s ↔ s u = none

    A key is outside dom s if and only if s u = none.

    @[simp]

    The empty dictionary has empty domain.

    The empty dictionary stores 0 keys.

    @[simp]
    theorem Cslib.DataStructure.Dictionary.dom_insert {U : ℕ} (s : State U) (u : Fin U) (v : ℕ) :

    Updating u to some v inserts u into dom s.

    theorem Cslib.DataStructure.Dictionary.dom_insert_of_mem {U : ℕ} {s : State U} {u : Fin U} (hu : u ∈ dom s) (v : ℕ) :

    Updating a key u already in dom s preserves dom s.

    theorem Cslib.DataStructure.Dictionary.dom_insert_of_isSome {U : ℕ} {s : State U} {u : Fin U} (hu : (s u).isSome = true) (v : ℕ) :

    Updating a key u with (s u).isSome preserves dom s.

    theorem Cslib.DataStructure.Dictionary.card_dom_insert_le {U : ℕ} (s : State U) (u : Fin U) (v : ℕ) :
    (dom (Function.update s u (some v))).card ≤ (dom s).card + 1

    Updating u to some v increases (dom s).card by at most 1.

    theorem Cslib.DataStructure.Dictionary.card_dom_insert_eq_of_isSome {U : ℕ} {s : State U} {u : Fin U} (hu : (s u).isSome = true) (v : ℕ) :

    Updating a present key u ((s u).isSome) leaves (dom s).card unchanged.

    theorem Cslib.DataStructure.Dictionary.card_dom_insert_eq_of_eq_none {U : ℕ} {s : State U} {u : Fin U} (hu : s u = none) (v : ℕ) :
    (dom (Function.update s u (some v))).card = (dom s).card + 1

    Inserting an absent key u (s u = none) increases (dom s).card by 1.

    theorem Cslib.DataStructure.Dictionary.card_dom_step_le_of_valid {U V n_max : ℕ} {s : State U} {o : Op U} (hs : (dom s).card ≤ n_max) (hval : (spec U V n_max).valid s o) :
    (dom ((spec U V n_max).stepFn s o).1).card ≤ n_max

    Any single admissible dictionary operation preserves the capacity bound (dom s).card ≤ n_max.

    theorem Cslib.DataStructure.Dictionary.card_dom_run_le_of_validHistory {U V n_max : ℕ} {s : State U} {os : List (Op U)} (hs : (dom s).card ≤ n_max) (hvh : (spec U V n_max).ValidHistory s os) :
    (dom ((spec U V n_max).run s os).1).card ≤ n_max

    Any admissible operation history preserves (dom s).card ≤ n_max.

    theorem Cslib.DataStructure.Dictionary.card_dom_run_empty_le {U V n_max : ℕ} {os : List (Op U)} (hvh : (spec U V n_max).ValidHistory (empty U) os) :
    (dom ((spec U V n_max).run (empty U) os).1).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.

    theorem Cslib.DataStructure.Dictionary.valuesBounded_step_of_valid {U V n_max : ℕ} {s : State U} {o : Op U} (hs : ValuesBounded V s) (hval : (spec U V n_max).valid s o) :
    ValuesBounded V ((spec U V n_max).stepFn s o).1

    Any single admissible dictionary operation preserves ValuesBounded V.

    theorem Cslib.DataStructure.Dictionary.valuesBounded_run_of_validHistory {U V n_max : ℕ} {s : State U} {os : List (Op U)} (hs : ValuesBounded V s) (hvh : (spec U V n_max).ValidHistory s os) :
    ValuesBounded V ((spec U V n_max).run s os).1

    Any admissible operation history preserves ValuesBounded V.