Documentation

CslibFrontier.DataStructure.SearchTree.Impl

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. Deletion uses the existing successor-splicing operation, including unsuccessful and repeated deletions.

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.

@[reducible, inline]

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

Representation includes both set semantics and strict subtree ordering.

Empty trees represent empty sets without an initialization assumption.

Semantic correctness is independent of the later resource certificate.

theorem Cslib.DataStructure.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.DataStructure.SearchTree.realized_client {α : Type} [LinearOrder α] {β : Type} (p : (OrderedSet.spec α).Client β) {s : Finset α} {t : BinaryTree α} (hr : Rep s t) :
match (OrderedSet.spec α).runClient s p with | (value, finalState, history) => ∃ (t' : BinaryTree α) (ns : List ℕ), Executes Exec p t value t' ns ∧ Rep finalState t' ∧ total id ns ≤ (OrderedSet.spec α).totalCost (fun (s : (OrderedSet.spec α).State) (x : (OrderedSet.spec α).Op) => Finset.card s) s history

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.

@[reducible, inline]

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

theorem Cslib.DataStructure.SearchTree.run_correct {α : Type} [LinearOrder α] {β : Type} (p : (OrderedSet.spec α).Client β) {s : Finset α} {t : BinaryTree α} (hr : Rep s t) :
match (OrderedSet.spec α).runClient s p with | (value, finalState, history) => (run t p).value = value ∧ Rep finalState (run t p).state ∧ total id (run t p).traces ≤ (OrderedSet.spec α).totalCost (fun (s : (OrderedSet.spec α).State) (x : (OrderedSet.spec α).Op) => Finset.card s) s history

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