Documentation

Examples.Language.Splay.Trace

Declarative certificates for splay rotations #

SplayTrace records the shape changes made by bottom-up splaying and their number of rotations. It is a proposition, not a second executable splay function. A source-program proof must construct this certificate from its actual execution; the certificate alone assigns no RAM instruction cost.

The focus is the original subtree rooted at the accessed node. A failed search may instead focus on its last visited node. Empty grandchildren do not introduce double-rotation cases: their source calls can perform work, but the tree transformation is a single zig and that work must be charged separately.

inductive Complexity.Language.Examples.Splay.SplayTrace {α : Type u_1} :
Tree α → Tree α → Tree α → ℕ → Prop

A bottom-up splay certificate, indexed by its original focus and rotation count.

Instances For
    theorem Complexity.Language.Examples.Splay.SplayTrace.inorder_eq {α : Type u_1} {focus initial final : Tree α} {rotations : ℕ} (trace : SplayTrace focus initial final rotations) :
    final.inorder = initial.inorder

    Every label, including duplicates, retains its inorder position.

    theorem Complexity.Language.Examples.Splay.SplayTrace.numNodes_eq {α : Type u_1} {focus initial final : Tree α} {rotations : ℕ} (trace : SplayTrace focus initial final rotations) :
    final.numNodes = initial.numNodes

    Splaying neither creates nor removes nodes.

    theorem Complexity.Language.Examples.Splay.SplayTrace.numLeaves_eq {α : Type u_1} {focus initial final : Tree α} {rotations : ℕ} (trace : SplayTrace focus initial final rotations) :
    final.numLeaves = initial.numLeaves
    theorem Complexity.Language.Examples.Splay.SplayTrace.root_eq {α : Type u_1} {focus initial final : Tree α} {rotations : ℕ} (trace : SplayTrace focus initial final rotations) :
    final.root? = focus.root?

    The original focus label is the final root, without choosing a value for nil.

    theorem Complexity.Language.Examples.Splay.SplayTrace.eq_nil_iff {α : Type u_1} {focus initial final : Tree α} {rotations : ℕ} (trace : SplayTrace focus initial final rotations) :
    final = Tree.nil ↔ initial = Tree.nil

    Empty and nonempty trees are preserved.

    theorem Complexity.Language.Examples.Splay.SplayTrace.focus_eq_nil_iff {α : Type u_1} {focus initial final : Tree α} {rotations : ℕ} (trace : SplayTrace focus initial final rotations) :
    focus = Tree.nil ↔ final = Tree.nil

    A nonempty splay result has a nonempty original focus.

    theorem Complexity.Language.Examples.Splay.SplayTrace.focus_numLeaves_le {α : Type u_1} {focus initial final : Tree α} {rotations : ℕ} (trace : SplayTrace focus initial final rotations) :
    focus.numLeaves ≤ initial.numLeaves

    The selected original subtree fits inside the original whole tree.

    theorem Complexity.Language.Examples.Splay.SplayTrace.access {α : Type u_1} {focus initial final : Tree α} {rotations : ℕ} (trace : SplayTrace focus initial final rotations) :
    ↑rotations + potential final - potential initial ≤ 3 * (rank initial - rank focus) + 1

    The access lemma for certified rotations. An execution-cost theorem must separately bound actual program work by these rotations and its constant overhead.

    theorem Complexity.Language.Examples.Splay.SplayTrace.rotations_add_potential_le {α : Type u_1} {focus initial final : Tree α} {rotations : ℕ} (trace : SplayTrace focus initial final rotations) :
    ↑rotations + potential final ≤ potential initial + 3 * rank initial + 1

    A root-size-only amortized bound, retaining both initial and final credit.