Documentation

Complexity.Algorithms.Lean.IndexedMinPQ

Indexed min-priority queue specification #

This file defines a deterministic, graph-free abstract specification (Cslib.Algorithms.Lean.IndexedMinPQ.spec) for an indexed min-priority queue over finite handles Fin n and natural-number keys bounded by K_max.

States map each handle v : Fin n to Option ℕ (none when absent, some k when present with key k). To make extractMin a deterministic state transition (Cslib.Stateful.Spec.step) that depends only on the abstract state and not on insertion history, findMin breaks equal-key ties by choosing the smallest handle index (PrioLE). Both binary heaps and Fibonacci heaps over the word RAM can realize this exact specification.

Main definitions #

Main results #

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 v with key k.

  • decreaseKey {n : ℕ} (v : Fin n) (k : ℕ) : Op n

    Lower the key of a present handle v to k.

  • extractMin {n : ℕ} : Op n

    Remove and return the present (handle, key) pair of minimum (key, handle).

Instances For
    def Cslib.Algorithms.Lean.IndexedMinPQ.instDecidableEqOp.decEq {n✝ : ℕ} (x✝ x✝¹ : Op n✝) :
    Decidable (x✝ = x✝¹)
    Instances For
      @[instance_reducible]
      @[instance_reducible]
      @[reducible, inline]

      Abstract state of an indexed min-priority queue on Fin n.

      Instances For

        The empty priority queue on Fin n.

        Instances For

          The finite set of handles currently present in state s.

          Instances For
            @[reducible, inline]

            Lexicographic priority comparison on raw (handle, key) : ℕ × ℕ pairs: smaller key first, breaking equal-key ties by smaller handle index.

            Instances For

              Transitivity of RawPrioLE.

              Lexicographic priority comparison on (handle, key) pairs: smaller key first, breaking equal-key ties by smaller handle index.

              Instances For
                @[instance_reducible]
                theorem Cslib.Algorithms.Lean.IndexedMinPQ.PrioLE.trans {n : ℕ} {a b c : Fin n × ℕ} (hab : PrioLE a b) (hbc : PrioLE b c) :
                PrioLE a c

                Transitivity of PrioLE.

                theorem Cslib.Algorithms.Lean.IndexedMinPQ.PrioLE.antisymm {n : ℕ} {a b : Fin n × ℕ} (hab : PrioLE a b) (hba : PrioLE b a) :
                a = b

                Antisymmetry of PrioLE.

                Strict lexicographic priority comparison on raw (handle, key) : ℕ × ℕ pairs: smaller key first, breaking equal-key ties by strictly smaller handle index.

                Instances For

                  Transitivity of RawPrioLT.

                  Strict priority order RawPrioLT implies weak priority order RawPrioLE.

                  Negation of RawPrioLT is the converse weak priority order RawPrioLE.

                  Strict lexicographic priority comparison on (handle, key) pairs: smaller key first, breaking equal-key ties by strictly smaller handle index.

                  Instances For
                    @[instance_reducible]
                    theorem Cslib.Algorithms.Lean.IndexedMinPQ.PrioLT.trans {n : ℕ} {a b c : Fin n × ℕ} (hab : PrioLT a b) (hbc : PrioLT b c) :
                    PrioLT a c

                    Transitivity of PrioLT.

                    Asymmetry of PrioLT.

                    theorem Cslib.Algorithms.Lean.IndexedMinPQ.PrioLT.of_le_of_lt {n : ℕ} {a b c : Fin n × ℕ} (hab : PrioLE a b) (hbc : PrioLT b c) :
                    PrioLT a c

                    PrioLT mixed with PrioLE on the left.

                    theorem Cslib.Algorithms.Lean.IndexedMinPQ.PrioLT.of_lt_of_le {n : ℕ} {a b c : Fin n × ℕ} (hab : PrioLT a b) (hbc : PrioLE b c) :
                    PrioLT a c

                    PrioLT mixed with PrioLE on the right.

                    theorem Cslib.Algorithms.Lean.IndexedMinPQ.prioLT_or_prioLT_of_ne {n : ℕ} {u v : Fin n} (huv : u ≠ v) (ku kv : ℕ) :
                    PrioLT (u, ku) (v, kv) ∨ PrioLT (v, kv) (u, ku)

                    Any two pairs with distinct handles are strictly comparable under PrioLT.

                    Pick the lexicographically smaller (handle, key) pair.

                    Instances For

                      Minimum (handle, key) pair of a list under PrioLE, or none on the empty list.

                      Instances For

                        Unique present (u, k) minimizing (k, u.val) lexicographically, or none if empty.

                        Instances For

                          Graph-free indexed min-priority queue specification with key upper bound K_max.

                          Instances For

                            Domain and findMin lemmas #

                            theorem Cslib.Algorithms.Lean.IndexedMinPQ.mem_dom_iff {n : ℕ} {s : State n} {v : Fin n} :
                            v ∈ dom s ↔ ∃ (k : ℕ), s v = some k

                            A handle belongs to dom s if and only if s v is some k for some key k.

                            @[simp]
                            theorem Cslib.Algorithms.Lean.IndexedMinPQ.notMem_dom_iff {n : ℕ} {s : State n} {v : Fin n} :
                            v ∉ dom s ↔ s v = none

                            A handle is outside dom s if and only if s v = none.

                            @[simp]

                            The empty priority queue has empty domain.

                            @[simp]
                            theorem Cslib.Algorithms.Lean.IndexedMinPQ.dom_insert {n : ℕ} (s : State n) (v : Fin n) (k : ℕ) :

                            Updating v to some k inserts v into dom s.

                            theorem Cslib.Algorithms.Lean.IndexedMinPQ.dom_decreaseKey {n : ℕ} {s : State n} {v : Fin n} (hv : v ∈ dom s) (k : ℕ) :

                            Lowering the key of a handle already in dom s preserves dom s.

                            @[simp]

                            Clearing u to none erases u from dom s.

                            @[simp]

                            findMin s returns none if and only if dom s is empty.

                            theorem Cslib.Algorithms.Lean.IndexedMinPQ.findMin_eq_some_state {n : ℕ} {s : State n} {u : Fin n} {k : ℕ} (h : findMin s = some (u, k)) :
                            s u = some k

                            If findMin s = some (u, k), then s u = some k.

                            theorem Cslib.Algorithms.Lean.IndexedMinPQ.findMin_mem_dom {n : ℕ} {s : State n} {u : Fin n} {k : ℕ} (h : findMin s = some (u, k)) :
                            u ∈ dom s

                            Any handle returned by findMin belongs to dom s.

                            theorem Cslib.Algorithms.Lean.IndexedMinPQ.findMin_le {n : ℕ} {s : State n} {u : Fin n} {k : ℕ} (h : findMin s = some (u, k)) (v : Fin n) (k' : ℕ) :
                            s v = some k' → k < k' ∨ k = k' ∧ ↑u ≤ ↑v

                            findMin minimizes (k, u.val) lexicographically among all present handles.

                            theorem Cslib.Algorithms.Lean.IndexedMinPQ.findMin_key_le {n : ℕ} {s : State n} {u : Fin n} {k : ℕ} (h : findMin s = some (u, k)) {v : Fin n} {k' : ℕ} (hv : s v = some k') :
                            k ≤ k'

                            The key returned by findMin is at most the key of every present handle.

                            theorem Cslib.Algorithms.Lean.IndexedMinPQ.findMin_eq_some_iff {n : ℕ} {s : State n} {u : Fin n} {k : ℕ} :
                            findMin s = some (u, k) ↔ s u = some k ∧ ∀ (v : Fin n) (k' : ℕ), s v = some k' → k < k' ∨ k = k' ∧ ↑u ≤ ↑v

                            Complete characterization of findMin: findMin s = some (u, k) if and only if s u = some k and (u, k) precedes every present (v, k') under PrioLE.

                            theorem Cslib.Algorithms.Lean.IndexedMinPQ.dom_extractMin {n K_max : ℕ} {s : State n} {u : Fin n} {k : ℕ} (h : findMin s = some (u, k)) :
                            dom ((spec n K_max).step s Op.extractMin).1 = (dom s).erase u

                            Domain evolution of extractMin when findMin s = some (u, k).