Documentation

CslibFrontier.DataStructure.AVLTree.WordRAM

AVL insertion by a standard word-RAM program #

The linked pointer-machine implementation of Frontier's AVL insertion compiles to ordinary word-RAM instructions using the certified natural scalar basis. The resulting finite program has logarithmic instruction cost and allocates at most one node. All nonheight payloads survive.

The input is an encoded linked AVL tree, with natural keys and scalar fields. The caller supplies a bound on its initial scalar values and enough word width for that bound plus the source instruction budget and a conservative allocation budget. Intermediate fit and scalar-operation correctness are proved, not supplied by the caller. Encoding the initial heap is not charged.

theorem Cslib.DataStructure.AVLTree.WordRAM.insert_correct {extra regs w b : ℕ} (field : Fin (extra + 1)) (notKey : field ≠ 0) (source : Fin (extra + 1) → Fin (regs + 3)) (safe : ∀ (f : Fin (extra + 1)), f ≠ field → f ≠ 0 → source f ≠ 1 ∧ source f ≠ 2) (s : PointerMachine.State PointerMachine.WordRAM.Natural.model (SearchTree.PointerMachine.layout extra (regs + 1))) (tree : BinaryTree (SearchTree.PointerMachine.Label PointerMachine.WordRAM.Natural.model extra)) (original : AVLTree ℕ) (stateValid : s.Valid) (initial : s.DataValid fun (x : PointerMachine.WordRAM.Natural.model.Value) => x ≤ b) (rep : SearchTree.PointerMachine.Represents s.heap none tree) (distinct : SearchTree.PointerMachine.AddressesDistinct tree) (matched : PointerMachine.Matches id field tree original) (valid : original.Valid) (cursor : s.ptr 0 = SearchTree.PointerMachine.root tree) (rootReg : s.ptr 1 = SearchTree.PointerMachine.root tree) (pc : s.pc = 0) :

A concrete standard word-RAM program implements AVL insertion with logarithmic time. Its final represented state has exactly the functional insertion's keys and caches, preserves old payloads, and allocates at most one node. Width requirements concern only the initial data bound and explicit instruction budget; input encoding is outside the charged run.