Documentation

CslibFrontier.DataStructure.AVLTree.PointerMachine.DictionaryRepresentation

Memory represented by a linked AVL dictionary #

A node stores its key in field zero, height in field one, and memory value in field two. The tree may retain keys with the default value. Keys absent from the tree have that default; this represents a total RAM memory without allocating a node for every possible address.

Field-two payloads represent a total memory; absent keys have the specified default.

The empty tree represents the everywhere-default memory.

An unsuccessful ordered search reads the default memory value.

A payload store retains the key and height match with the same mathematical AVL tree.

theorem Cslib.DataStructure.AVLTree.PointerMachine.Dictionary.payload_except_insert {M : PointerMachine.Model} [LinearOrder M.Value] {regs : ℕ} {encode : ℕ → M.Value} {s t : PointerMachine.State M (SearchTree.PointerMachine.layout 2 (regs + 2))} {before after : BinaryTree (SearchTree.PointerMachine.Label M 2)} {original : AVLTree M.Value} {memory : M.Value → M.Value} (rep : SearchTree.PointerMachine.Represents s.heap none before) (stored : Stores (encode 0) before memory) (result : InsertResult encode 1 (fun (x : Fin (2 + 1)) => 3) s t before after original) (q : PosNum) (u : SearchTree.PointerMachine.Label M 2) :
BinaryTree.get q after = some u → u.data 0 ≠ s.data 0 → u.data 2 = memory (u.data 0)

Inserting a key preserves the represented memory values at every other key, including when rotations move the new node above old nodes.

theorem Cslib.DataStructure.AVLTree.PointerMachine.Dictionary.stores_updatePayload {M : PointerMachine.Model} [LinearOrder M.Value] (zero : M.Value) (tree : BinaryTree (SearchTree.PointerMachine.Label M 2)) (memory : M.Value → M.Value) (query value : M.Value) (p : PosNum) (label : SearchTree.PointerMachine.Label M 2) (ordered : SearchTree.Ordered (SearchTree.PointerMachine.keys tree)) (distinct : SearchTree.PointerMachine.AddressesDistinct tree) (found : BinaryTree.get p tree = some label) (key : label.data 0 = query) (other : ∀ (q : PosNum) (u : SearchTree.PointerMachine.Label M 2), BinaryTree.get q tree = some u → u.data 0 ≠ query → u.data 2 = memory (u.data 0)) (support : ∀ (k : M.Value), memory k ≠ zero → k ∈ SearchTree.elements (SearchTree.PointerMachine.keys tree)) :
Stores zero (SearchTree.PointerMachine.updateData tree label.address 2 value) (Function.update memory query value)

Writing a located key establishes its new memory value; values at every other key are inherited. This also covers a newly inserted node whose old payload was arbitrary.

theorem Cslib.DataStructure.AVLTree.PointerMachine.Dictionary.stores_insert_updatePayload {M : PointerMachine.Model} [LinearOrder M.Value] {regs : ℕ} {encode : ℕ → M.Value} {s t : PointerMachine.State M (SearchTree.PointerMachine.layout 2 (regs + 2))} {before after : BinaryTree (SearchTree.PointerMachine.Label M 2)} {original : AVLTree M.Value} {memory : M.Value → M.Value} (rep : SearchTree.PointerMachine.Represents s.heap none before) (matched : Matches encode 1 before original) (valid : original.Valid) (stored : Stores (encode 0) before memory) (result : InsertResult encode 1 (fun (x : Fin (2 + 1)) => 3) s t before after original) (p : PosNum) (label : SearchTree.PointerMachine.Label M 2) (found : BinaryTree.get p after = some label) (key : label.data 0 = s.data 0) (value : M.Value) :
Stores (encode 0) (SearchTree.PointerMachine.updateData after label.address 2 value) (Function.update memory (s.data 0) value)

After inserting the query key, writing a value at its node updates the represented memory at that key and leaves every other cell unchanged.