Logarithmic pointer-machine search in AVL trees #
search_correct applies the concrete linked-tree search program to the existing AVL
representation and height theorem. Its bound counts pointer-machine instructions, including
comparisons, null tests, jumps and halt. The initial linked representation is supplied;
this theorem does not construct it or implement AVL insertion and rebalancing.
theorem Cslib.DataStructure.AVLTree.search_correct {M : PointerMachine.Model} [LinearOrder M.Value] {extra regs : ℕ} (lt : M.Test) (compare : ∀ (a b : M.Value), M.evalTest lt a b = decide (a < b)) (t : AVLTree M.Value) (valid : t.Valid) (tree : BinaryTree (SearchTree.PointerMachine.Label M extra)) (shape : SearchTree.PointerMachine.keys tree = t.toBinaryTree) (x : PointerMachine.State M (SearchTree.PointerMachine.layout extra regs)) (parent : PointerMachine.Pointer) (rep : SearchTree.PointerMachine.Represents x.heap parent tree) (cursor : x.ptr 0 = SearchTree.PointerMachine.root tree) (pc : x.pc = 0) :
∃ (y : PointerMachine.State M (SearchTree.PointerMachine.layout extra regs)) (time : ℕ),
PointerMachine.Executes (SearchTree.PointerMachine.search lt) x y time ∧ time ≤ 12 * Nat.log 2 (t.elements.card + 1) + 3 ∧ SearchTree.PointerMachine.SearchResult x y tree ∧ (Option.isSome (y.ptr 0) = true ↔ x.data 0 ∈ t.elements)
A represented valid AVL tree admits a concrete pointer-machine search in at most
12 * log₂(card + 1) + 3 instructions. Nonnull output is exactly key membership;
SearchResult additionally gives the matching record and the complete register/heap frame.