Documentation

Examples.Language.Splay.Potential

Splay-tree potential #

Ranks are binary logarithms of leaf counts, equivalently internal-node counts plus one. The potential sums these ranks over internal nodes. Both quantities are proof-only observations of mathlib trees: the implementation does not maintain subtree sizes or compute logarithms.

The local inequalities below count one or two rotations, not RAM instructions. An implementation's measured execution must separately justify the cost of those rotations and all surrounding work before using a scaled potential for runtime.

noncomputable def Complexity.Language.Examples.Splay.rank {α : Type u_1} (t : Tree α) :

A proof-only rank with a well-defined zero value at the empty tree.

Equations
Instances For
    noncomputable def Complexity.Language.Examples.Splay.potential {α : Type u_1} :
    Tree α → ℝ

    Sum the ranks of the internal nodes.

    Equations
    Instances For

      Leaf-count rank in terms of the ordinary input-size measure.

      theorem Complexity.Language.Examples.Splay.rank_left_le {α : Type u_1} (x : α) (l r : Tree α) :
      theorem Complexity.Language.Examples.Splay.rank_right_le {α : Type u_1} (x : α) (l r : Tree α) :

      The logarithmic slack available for two disjoint subtrees.

      @[simp]

      Initial credit is bounded by the number of nodes times the root rank.

      A uniform bound on the initial potential of any tree of the given size.

      theorem Complexity.Language.Examples.Splay.zig_left {α : Type u_1} (x y : α) (a b c : Tree α) :
      1 + potential (Tree.node x a (Tree.node y b c)) - potential (Tree.node y (Tree.node x a b) c) ≤ 3 * (rank (Tree.node y (Tree.node x a b) c) - rank (Tree.node x a b)) + 1

      A final left-child single rotation has one additive unit of amortized cost.

      theorem Complexity.Language.Examples.Splay.zig_right {α : Type u_1} (x y : α) (a b c : Tree α) :
      1 + potential (Tree.node x (Tree.node y a b) c) - potential (Tree.node y a (Tree.node x b c)) ≤ 3 * (rank (Tree.node y a (Tree.node x b c)) - rank (Tree.node x b c)) + 1

      A final right-child single rotation has one additive unit of amortized cost.

      theorem Complexity.Language.Examples.Splay.zig_zig_left {α : Type u_1} (x y z : α) (a b c d : Tree α) :
      2 + potential (Tree.node x a (Tree.node y b (Tree.node z c d))) - potential (Tree.node z (Tree.node y (Tree.node x a b) c) d) ≤ 3 * (rank (Tree.node z (Tree.node y (Tree.node x a b) c) d) - rank (Tree.node x a b))

      Two left-child rotations are paid for by three times the accessed rank gain.

      theorem Complexity.Language.Examples.Splay.zig_zig_right {α : Type u_1} (x y z : α) (a b c d : Tree α) :
      2 + potential (Tree.node x (Tree.node y (Tree.node z a b) c) d) - potential (Tree.node z a (Tree.node y b (Tree.node x c d))) ≤ 3 * (rank (Tree.node z a (Tree.node y b (Tree.node x c d))) - rank (Tree.node x c d))

      Two right-child rotations are paid for by three times the accessed rank gain.

      theorem Complexity.Language.Examples.Splay.zig_zag_left {α : Type u_1} (x y z : α) (a b c d : Tree α) :
      2 + potential (Tree.node x (Tree.node y a b) (Tree.node z c d)) - potential (Tree.node z (Tree.node y a (Tree.node x b c)) d) ≤ 2 * (rank (Tree.node z (Tree.node y a (Tree.node x b c)) d) - rank (Tree.node x b c))

      A left-right double rotation satisfies the stronger two-rank-gain bound.

      theorem Complexity.Language.Examples.Splay.zig_zag_right {α : Type u_1} (x y z : α) (a b c d : Tree α) :
      2 + potential (Tree.node x (Tree.node z a b) (Tree.node y c d)) - potential (Tree.node z a (Tree.node y (Tree.node x b c) d)) ≤ 2 * (rank (Tree.node z a (Tree.node y (Tree.node x b c) d)) - rank (Tree.node x b c))

      A right-left double rotation satisfies the stronger two-rank-gain bound.