Documentation

CslibFrontier.DataStructure.AVLTree.PointerMachine.Dictionary

Pointer-machine memory dictionary operations #

The root lives in pointer register one. Scalar zero supplies the address, scalar three the value to write or the result of a read. Scalars one and two are scratch; registers from four onward belong to the simulated machine. Every access navigates ordinary AVL links.

Read a dictionary address, returning the default value on a missing key.

Insert an absent key and replace the selected node's payload. Existing keys keep their node address; scalar three supplies the fresh or replacement value.

theorem Cslib.DataStructure.AVLTree.PointerMachine.Dictionary.read_correct {M : PointerMachine.Model} {regs : ℕ} [LinearOrder M.Value] (zero : M.Op) (lt : M.Test) (encode : ℕ → M.Value) (zero_spec : ∀ (a b : M.Value), M.evalOp zero a b = encode 0) (compare : ∀ (a b : M.Value), M.evalTest lt a b = decide (a < b)) (s : PointerMachine.State M (SearchTree.PointerMachine.layout 2 (regs + 2))) (tree : BinaryTree (SearchTree.PointerMachine.Label M 2)) (avl : AVLTree M.Value) (memory : M.Value → M.Value) (rep : SearchTree.PointerMachine.Represents s.heap none tree) (matched : Matches encode 1 tree avl) (valid : avl.Valid) (stored : Stores (encode 0) tree memory) (rootReg : s.ptr 1 = SearchTree.PointerMachine.root tree) (pc : s.pc = 0) :
∃ (t : PointerMachine.State M (SearchTree.PointerMachine.layout 2 (regs + 2))) (time : ℕ), PointerMachine.Executes (read zero lt) s t time ∧ time ≤ 6 * avl.cachedHeight + 10 ∧ t.heap = s.heap ∧ t.ptr 1 = s.ptr 1 ∧ t.data 3 = memory (s.data 0) ∧ ∀ (i : Fin (SearchTree.PointerMachine.layout 2 (regs + 2)).dataRegs), i ≠ 1 → i ≠ 3 → t.data i = s.data i

A complete dictionary read follows the AVL search path and returns the represented value. It preserves the heap, root, query, and every client scalar register.

The output dictionary implements a total-memory update and preserves client registers.

theorem Cslib.DataStructure.AVLTree.PointerMachine.Dictionary.write_correct {M : PointerMachine.Model} {regs : ℕ} [LinearOrder M.Value] (zero maxSucc : M.Op) (lt heavy le : M.Test) (encode : ℕ → M.Value) (zero_spec : ∀ (a b : M.Value), M.evalOp zero a b = encode 0) (max_spec : ∀ (a b : ℕ), M.evalOp maxSucc (encode a) (encode b) = encode (max a b + 1)) (compare : ∀ (a b : M.Value), M.evalTest lt a b = decide (a < b)) (heavy_spec : ∀ (a b : ℕ), M.evalTest heavy (encode a) (encode b) = decide (b + 1 < a)) (le_spec : ∀ (a b : ℕ), M.evalTest le (encode a) (encode b) = decide (a ≤ b)) (s : PointerMachine.State M (SearchTree.PointerMachine.layout 2 (regs + 2))) (tree : BinaryTree (SearchTree.PointerMachine.Label M 2)) (avl : AVLTree M.Value) (memory : M.Value → M.Value) (rep : SearchTree.PointerMachine.Represents s.heap none tree) (matched : Matches encode 1 tree avl) (valid : avl.Valid) (distinct : SearchTree.PointerMachine.AddressesDistinct tree) (stored : Stores (encode 0) tree memory) (rootReg : s.ptr 1 = SearchTree.PointerMachine.root tree) (pc : s.pc = 0) :
∃ (t : PointerMachine.State M (SearchTree.PointerMachine.layout 2 (regs + 2))) (result : BinaryTree (SearchTree.PointerMachine.Label M 2)) (time : ℕ), PointerMachine.Executes (write zero maxSucc lt heavy le) s t time ∧ time ≤ 147 * avl.cachedHeight + 52 ∧ WriteResult encode s t result avl memory

A concrete dictionary write inserts a missing address and changes its payload, with logarithmic cost and at most one allocation. Existing memory cells retain their values.