Documentation

Examples.Language.Splay.Specification

The mathematical and storage contract of a splay access #

Access describes ordinary trees: the inorder sequence is unchanged and the matching or last-visited node becomes the root. BST order and distinct labels are consequences of this relation, not additional implementation obligations.

Input records the actual borrowed storage and its legal aliasing. Post is shared by source correctness and the RAM endpoint: it retains the represented output, rotation certificate and real initial/final heap frame. No execution semantics, word-capacity assumption or proposed running time is defined here.

structure Complexity.Language.Examples.Splay.Access (key : ℕ → ℕ) (query : ℕ) (initial final : Tree ℕ) :

The mathematical effect of an access, independently of heap encoding.

  • inorder : final.inorder = initial.inorder

    All nodes keep their exact inorder positions.

  • root_eq : final.root? = (searchFocus key query initial).root?

    Ordinary search selects the final root, including unsuccessful searches.

Instances For
    theorem Complexity.Language.Examples.Splay.Access.of_trace {key : ℕ → ℕ} {query : ℕ} {initial final : Tree ℕ} {rotations : ℕ} (trace : SplayTrace (searchFocus key query initial) initial final rotations) :
    Access key query initial final

    The certified rotations establish the ordinary mathematical specification.

    theorem Complexity.Language.Examples.Splay.Access.nodup {key : ℕ → ℕ} {query : ℕ} {initial final : Tree ℕ} (access : Access key query initial final) (unique : initial.inorder.Nodup) :

    Distinct node identities survive an access.

    theorem Complexity.Language.Examples.Splay.Access.ordered {key : ℕ → ℕ} {query : ℕ} {initial final : Tree ℕ} (access : Access key query initial final) (ordered : List.Pairwise (fun (x1 x2 : ℕ) => x1 < x2) (List.map key initial.inorder)) :
    List.Pairwise (fun (x1 x2 : ℕ) => x1 < x2) (List.map key final.inorder)

    BST order is an ordinary list property transported by inorder equality.

    structure Complexity.Language.Examples.Splay.Input (key : ℕ → ℕ) (keys left right : Buffer CellTy.nat) (tree : Tree ℕ) (heap : Heap) :

    Legal source inputs. Buffer columns may be disjoint slices of one object; BST ordering and finite-machine capacities are not required for source safety.

    Instances For
      def Complexity.Language.Examples.Splay.Post (key : ℕ → ℕ) (keys left right : Buffer CellTy.nat) (query : ℕ) (tree : Tree ℕ) (initial : Heap) (result : ℕ) (finish : Heap) :

      The shared source/RAM postcondition. Its existential tree is a mathematical view of the actual final heap; result is the root returned by that execution.

      Equations
      • One or more equations did not get rendered due to their size.
      Instances For
        theorem Complexity.Language.Examples.Splay.Post.access {key : ℕ → ℕ} {keys left right : Buffer CellTy.nat} {query result : ℕ} {tree : Tree ℕ} {initial finish : Heap} (post : Post key keys left right query tree initial result finish) :
        ∃ (final : Tree ℕ), result = BufferTree.root final ∧ BufferTree.Rep key keys left right finish final ∧ Access key query tree final

        A caller can forget the rotation certificate and use the ordinary tree specification together with the actual returned root and represented storage.

        theorem Complexity.Language.Examples.Splay.Post.frame {key : ℕ → ℕ} {keys left right : Buffer CellTy.nat} {query result : ℕ} {tree : Tree ℕ} {initial finish : Heap} (post : Post key keys left right query tree initial result finish) :
        Heap.PreservesOutside (BufferTree.linkCells left right tree) initial finish

        Cells outside the original tree's child links retain their actual values.

        theorem Complexity.Language.Examples.Splay.Post.keys_contents {key : ℕ → ℕ} {keys left right : Buffer CellTy.nat} {query result : ℕ} {tree : Tree ℕ} {initial finish : Heap} (post : Post key keys left right query tree initial result finish) (input : Input key keys left right tree initial) {values : Array ℕ} (observed : keys.Contents initial values) :
        keys.Contents finish values

        The complete key-array contents are unchanged, not only the keys of nodes that happened to be visited. This consequence is shared by source and RAM users.