Documentation

CslibFrontier.DataStructure.Dictionary.Dynamic.Spec

Dynamic dictionary specification with deletions and succinct space bounds #

This file defines a deterministic abstract specification (Cslib.DataStructure.Dictionary.Dynamic.spec) for a bounded-capacity dynamic dictionary mapping keys from a finite universe Fin U to natural-number values bounded by V, supporting query, insert (with in-place value overwrite), and delete, with at most n_max distinct keys present at any point in time.

Unlike the insert-only interface Cslib.DataStructure.Dictionary.spec (which provides query and insert), Cslib.DataStructure.Dictionary.Dynamic.Op includes key deletion (delete u, removing u if present and acting as a no-op if absent) while sharing the underlying state representation Dictionary.State U = Fin U → Option ℕ, empty state Dictionary.empty U, active key set Dictionary.dom, and value-bound invariant Dictionary.ValuesBounded. When U ≤ n_max, the capacity condition (dom s).card < n_max ∨ (s u).isSome holds automatically for every state s and key u, so spec U V n_max also covers unbounded-capacity dynamic dictionaries over Fin U (valid_insert_iff_of_le).

This file also defines the information-theoretic bit bound optBits U V n = ⌈log₂ C(U, n)⌉ + n * ⌈log₂ V⌉ for n keys. When 0 < V and n ≤ U, optBits U V n equals the exact minimum ⌈log₂ (C(U, n) * V^n)⌉ when V is a power of two and exceeds it by at most n bits otherwise. When n > U, C(U, n) = 0; when V = 0, there are no valued non-empty dictionaries. From optBits, succinctWords C C₀ U V w n_max defines the word bound ⌈(optBits U V n_max + C * n_max * ⌈log₂ ⌈log₂ (max n_max 4)⌉⌉) / w⌉ + C₀ on the w-bit Word RAM.

Main definitions #

Main results #

References #

Lookup, insertion (with in-place value overwrite), and deletion operations on a dynamic dictionary over keys Fin U and natural-number values.

  • query {U : ℕ} (u : Fin U) : Op U

    Look up the value associated with key u, returning some v if present with value v or none if absent.

  • insert {U : ℕ} (u : Fin U) (v : ℕ) : Op U

    Associate key u with value v, inserting u if absent or overwriting its existing value in place if present.

  • delete {U : ℕ} (u : Fin U) : Op U

    Remove key u from the dictionary if present, or leave the dictionary unchanged if u is absent.

Instances For
    @[instance_reducible]
    @[reducible, inline]

    Return type for each Op U.

    Instances For
      @[reducible, inline]

      Pure transition function for dynamic dictionary operations.

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

      Admissibility precondition for bounded-capacity dynamic dictionary operations: query and delete are always admissible; insert u v is admissible whenever v < V and either (dom s).card < n_max or u is already present in s ((s u).isSome, in which case updating s u overwrites its value in place without increasing (dom s).card).

      @[reducible, inline]

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

      Domain, deletion, capacity, and value-bound lemmas #

      @[simp]

      Deleting u removes u from dom s.

      Deleting an absent key u ∉ dom s leaves dom s unchanged.

      Deleting a key u with s u = none leaves dom s unchanged.

      Deleting u never increases (dom s).card.

      Deleting a present key u ((s u).isSome) decreases (dom s).card by 1.

      Deleting an absent key u (s u = none) leaves (dom s).card unchanged.

      The number of present keys in any state s : State U is at most U.

      theorem Cslib.DataStructure.Dictionary.Dynamic.valid_insert_iff_of_le {U V n_max : ℕ} (hU : U ≤ n_max) (s : State U) (u : Fin U) (v : ℕ) :
      (spec U V n_max).valid s (Op.insert u v) ↔ v < V

      When U ≤ n_max, every key insertion into s : State U satisfies the capacity condition (dom s).card < n_max ∨ (s u).isSome automatically, so insertion admissibility reduces to v < V.

      theorem Cslib.DataStructure.Dictionary.Dynamic.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 dynamic dictionary operation preserves the capacity bound (dom s).card ≤ n_max.

      theorem Cslib.DataStructure.Dictionary.Dynamic.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 dynamic dictionary operation history preserves (dom s).card ≤ n_max.

      theorem Cslib.DataStructure.Dictionary.Dynamic.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 dynamic dictionary operation history starting from empty U reaches a state with at most n_max keys.

      Deleting a key u preserves ValuesBounded V.

      theorem Cslib.DataStructure.Dictionary.Dynamic.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 dynamic dictionary operation preserves ValuesBounded V.

      theorem Cslib.DataStructure.Dictionary.Dynamic.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 dynamic dictionary operation history preserves ValuesBounded V.

      theorem Cslib.DataStructure.Dictionary.Dynamic.valuesBounded_run_empty {U V n_max : ℕ} {os : List (Op U)} (hvh : (spec U V n_max).ValidHistory (empty U) os) :
      ValuesBounded V ((spec U V n_max).run (empty U) os).1

      Any admissible dynamic dictionary operation history starting from empty U reaches a state satisfying ValuesBounded V.

      Information-theoretic minimum bits and succinct word bounds #

      Information-theoretic bit bound OPT(U, V, n) = ⌈log₂ C(U, n)⌉ + n * ⌈log₂ V⌉ for representing n keys in Fin U with values in Fin V. When 0 < V and n ≤ U, this equals the exact minimum ⌈log₂ (C(U, n) * V^n)⌉ when V is a power of two and exceeds it by at most n bits otherwise. When n > U, U.choose n = 0; when V = 0, there are no valued non-empty dictionaries.

      Iterated logarithmic factor ⌈log₂ ⌈log₂ (max n 4)⌉⌉ ≥ 1.

      Succinct space bound ⌈(OPT(U, V, n_max) + C * n_max * ⌈log₂ ⌈log₂ (max n_max 4)⌉⌉) / w⌉ + C₀ in w-bit machine words.

      @[simp]

      For n = 0 keys, optBits U V 0 = 0.

      Quadrupling n increases logLogFactor by at most a factor of 4.