Documentation

Complexity.Algorithms.Lean.SearchTree.Stateful

A stateful ordered set realized by a binary search tree #

Clients see finite-set semantics and operation-dependent result types. The representation relation hides the tree's shape. Correctness transfers to every adaptive client through the common stateful calculus; node-visit costs are supplied afterwards as a separate resource certificate.

Main definitions #

Main results #

The cardinality bound is deliberately worst-case: these trees have no balancing invariant. The cost model excludes allocation, pure continuations and comparison implementation, and makes no RAM or Turing-machine time claim.

References #

Concrete operation and exact charge in the internal-node-visit model.

Instances For

    A native execution records an actual tree operation and its exact node-visit charge.

    Instances For

      Representation includes both set semantics and strict subtree ordering.

      Instances For

        Empty trees represent empty sets without an initialization assumption.

        Semantic correctness is independent of the later resource certificate.

        Instances For
          theorem Cslib.Algorithms.Lean.SearchTree.exec_visits_le_height {α : Type} [LinearOrder α] {t t' : BinaryTree α} {o : OrderedSet.Op α} {a : (OrderedSet.spec α).Result o} {n : ℕ} (he : Exec t o a t' n) :

          Costs depend on the actual initial tree height, even for an unsuccessful query.

          Forgetting shape gives a safe linear bound, not a logarithmic claim.

          theorem Cslib.Algorithms.Lean.SearchTree.realized_client {α : Type} [LinearOrder α] {β : Type} (p : (OrderedSet.spec α).Client β) {s : Finset α} {t : BinaryTree α} (hr : Rep s t) :
          ∃ (t' : BinaryTree α) (ns : List ℕ), Stateful.Executes Exec p t ((OrderedSet.spec α).runClient s p).1 t' ns ∧ Rep ((OrderedSet.spec α).runClient s p).2.1 t' ∧ Stateful.total id ns ≤ (OrderedSet.spec α).totalCost (fun (s : (OrderedSet.spec α).State) (x : (OrderedSet.spec α).Op) => Finset.card s) s ((OrderedSet.spec α).runClient s p).2.2

          Every adaptive client has the specified result and final set, together with a bound summing current-set cardinalities along the selected history. Pure continuation evaluation is uncharged.

          Execute a client concretely, retaining one exact node-visit count per operation.

          Instances For
            theorem Cslib.Algorithms.Lean.SearchTree.run_exec {α : Type} [LinearOrder α] {β : Type} (p : (OrderedSet.spec α).Client β) (t : BinaryTree α) :
            Stateful.Executes Exec p t (run t p).1 (run t p).2.1 (run t p).2.2

            The executable interpreter supplies native execution evidence rather than assuming it.

            theorem Cslib.Algorithms.Lean.SearchTree.run_correct {α : Type} [LinearOrder α] {β : Type} (p : (OrderedSet.spec α).Client β) {s : Finset α} {t : BinaryTree α} (hr : Rep s t) :
            (run t p).1 = ((OrderedSet.spec α).runClient s p).1 ∧ Rep ((OrderedSet.spec α).runClient s p).2.1 (run t p).2.1 ∧ Stateful.total id (run t p).2.2 ≤ (OrderedSet.spec α).totalCost (fun (s : (OrderedSet.spec α).State) (x : (OrderedSet.spec α).Op) => Finset.card s) s ((OrderedSet.spec α).runClient s p).2.2

            Running the concrete interpreter agrees with finite-set semantics and retains its cost bound.