Stateful ordered-set realization by height-balanced AVL trees #
This module realizes the shared Cslib.DataStructure.OrderedSet.spec α interface (contains,
insert, delete, minimum, successor) using height-cached AVL trees in the same
internal-node-visit cost model as
Cslib.DataStructure.SearchTree, upgrading SearchTree.nodeVisitBound's worst-case linear
s.card bound to the representation-independent logarithmic bound
2 * Nat.log 2 (s.card + 1).
Cost model and limitations #
As in Cslib.DataStructure.SearchTree, native operation traces count internal nodes visited along
the downward search (and splitMin) path (0 on an empty tree, at most t.cachedHeight on any
height-consistent tree), specified by SearchTree's path-visit functions on t.toBinaryTree. At
each visited ancestor during insert or erase, balance performs non-recursive O(1) reads of
off-path sibling/nephew cached heights and at most a single or double rotation; those constant-work
rebalancing steps, toBinaryTree trace-specification projection, node allocations, order-comparison
implementations, and pure client continuations are not charged as separate RAM or Turing-machine
instructions.
Main definitions #
step,Exec,run: concrete AVL operations, native execution relation, and executable client runner with exact internal-node-visit traces, built withCslib.DataStructure.Execution.ofStep.Rep,impl: AVL representation relation (Valid t ∧ elements t = s) andCslib.DataStructure.StateTransitionImplofCslib.DataStructure.OrderedSet.spec α.charge: representation-independent logarithmic node-visit budget2 * Nat.log 2 (s.card + 1).
Main results #
Rep.valid,Rep.elements_eq,rep_empty,impl_rep: representation invariant projections and empty-set initialization.exec_visits_le_cachedHeight: every native operation visits at mostt.cachedHeightpath nodes.nodeVisitBound: logarithmicCslib.DataStructure.Boundcertificate2 * Nat.log 2 (s.card + 1).realized_client,run_correct: adaptive ordered-set clients (includingextractMin) execute with finite-set correctness and additive logarithmic node-visit bounds.
References #
Execute a single OrderedSet.Op α on an AVL tree, returning the updated tree, answer, and
internal-node-visit count.
Native execution relation for OrderedSet.spec α over AVLTree α.
Representation relation coupling a mathematical Finset α with a valid AVL tree t.
Extract AVL validity from Rep.
Extract the key-set equality from Rep.
The empty AVL tree represents the empty Finset α.
Semantic realization of OrderedSet.spec α by AVLTree α.
impl.rep is definitionally Rep.
Every native AVL operation visits at most t.cachedHeight internal path nodes.
Representation-independent logarithmic node-visit budget (0 on ∅, 2 * log₂(|s| + 1) in
general).
Logarithmic per-operation node-visit certificate for AVLTree.impl.
Every adaptive OrderedSet client executes on AVLTree with finite-set correctness and
additive 2 * Nat.log 2 (s.card + 1) node-visit bounds along its chosen history.
Execute an OrderedSet client concretely on an AVL tree, recording exact node visits per
operation.
Running the concrete AVL interpreter agrees with abstract Finset α semantics, preserves Rep,
and satisfies the additive logarithmic node-visit bound.