Documentation

CslibFrontier.DataStructure.BallsToSlots.Spec

Balls-to-Slots Problem Specification #

This module formalizes the pure balls-to-slots (probe-complexity) problem of Bender, Farach-Colton, J. Kuszmaul, W. Kuszmaul, and Liu, "On the Optimal Time/Space Tradeoff for Hash Tables", Proc. 54th ACM STOC, pp. 1284–1297, 2022 (arXiv:2111.00602v2, Section 2.1, printed p. 3 / PDF p. 4, and Section 3, printed p. 8 / PDF p. 9) [BFCK+22], aligned with Cslib's StateTransitionSpec grid:

General k-wise fiber conditioning, disjoint-restriction concentration, and two-stage product union-tail bounds live in CslibFrontier.Probability.KWiseIndependent.Restriction, CslibFrontier.Probability.KWiseIndependent.Concentration, and CslibFrontier.Foundations.Probability.TwoStage.

Main definitions #

Main results #

References #

Operations on a balls-to-slots scheme over ball universe α.

  • insert {α : Type u_1} (x : α) : Op α

    Insert ball x into the active set (no-op if x is already present).

  • delete {α : Type u_1} (x : α) : Op α

    Delete ball x from the active set (no-op if x is absent).

  • query {α : Type u_1} (x : α) : Op α

    Query the slot currently assigned to ball x (none if x is absent).

Instances For
    def Cslib.DataStructure.BallsToSlots.instDecidableEqOp.decEq {α✝ : Type u_1} [DecidableEq α✝] (x✝ x✝¹ : Op α✝) :
    Decidable (x✝ = x✝¹)
    @[instance_reducible]
    @[instance_reducible]
    instance Cslib.DataStructure.BallsToSlots.instReprOp {α✝ : Type u_1} [Repr α✝] :
    Repr (Op α✝)
    @[reducible, inline]

    Observation type returned by each Op α over M slots Fin M.

    Single-step evolution of the finite set of present balls.

    @[simp]
    @[simp]
    theorem Cslib.DataStructure.BallsToSlots.stepSet_delete {α : Type u_1} [DecidableEq α] (S : Finset α) (x : α) :
    @[simp]
    theorem Cslib.DataStructure.BallsToSlots.stepSet_query {α : Type u_1} [DecidableEq α] (S : Finset α) (x : α) :

    Active set of balls after executing ops starting from S.

    @[simp]
    theorem Cslib.DataStructure.BallsToSlots.activeSetFrom_cons {α : Type u_1} [DecidableEq α] (S : Finset α) (o : Op α) (ops : List (Op α)) :
    activeSetFrom S (o :: ops) = activeSetFrom (stepSet S o) ops
    theorem Cslib.DataStructure.BallsToSlots.activeSetFrom_append {α : Type u_1} [DecidableEq α] (S : Finset α) (ops₁ ops₂ : List (Op α)) :
    activeSetFrom S (ops₁ ++ ops₂) = activeSetFrom (activeSetFrom S ops₁) ops₂

    Active set of balls after executing ops starting from ∅.

    Finite set of balls mentioned anywhere in ops.

    def Cslib.DataStructure.BallsToSlots.ValidOp {α : Type u_1} (n_max : ℕ) (S : Finset α) :
    Op α → Prop

    Single-step operation admissibility at active set S under capacity n_max.

    def Cslib.DataStructure.BallsToSlots.ValidOpSeqFrom {α : Type u_1} [DecidableEq α] (n_max : ℕ) :
    Finset α → List (Op α) → Prop

    Admissibility of an oblivious operation sequence ops starting from active set S.

    def Cslib.DataStructure.BallsToSlots.ValidOpSeq {α : Type u_1} [DecidableEq α] (n_max : ℕ) (ops : List (Op α)) :

    Admissibility of an oblivious operation sequence ops starting from ∅.

    theorem Cslib.DataStructure.BallsToSlots.card_stepSet_le {α : Type u_1} [DecidableEq α] {n_max : ℕ} {S : Finset α} {o : Op α} (hS : S.card ≤ n_max) (ho : ValidOp n_max S o) :
    (stepSet S o).card ≤ n_max
    theorem Cslib.DataStructure.BallsToSlots.card_activeSetFrom_le {α : Type u_1} [DecidableEq α] {n_max : ℕ} {S : Finset α} {ops : List (Op α)} (hS : S.card ≤ n_max) (hval : ValidOpSeqFrom n_max S ops) :
    (activeSetFrom S ops).card ≤ n_max
    theorem Cslib.DataStructure.BallsToSlots.card_activeSet_le {α : Type u_1} [DecidableEq α] {n_max : ℕ} {ops : List (Op α)} (hval : ValidOpSeq n_max ops) :
    (activeSet ops).card ≤ n_max

    Every admissible operation sequence from ∅ maintains at most n_max present balls.

    theorem Cslib.DataStructure.BallsToSlots.validOpSeqFrom_append {α : Type u_1} [DecidableEq α] {n_max : ℕ} {S : Finset α} {ops₁ ops₂ : List (Op α)} :
    ValidOpSeqFrom n_max S (ops₁ ++ ops₂) ↔ ValidOpSeqFrom n_max S ops₁ ∧ ValidOpSeqFrom n_max (activeSetFrom S ops₁) ops₂
    theorem Cslib.DataStructure.BallsToSlots.opsBalls_append {α : Type u_1} [DecidableEq α] (ops₁ ops₂ : List (Op α)) :
    opsBalls (ops₁ ++ ops₂) = opsBalls ops₁ ∪ opsBalls ops₂
    theorem Cslib.DataStructure.BallsToSlots.exists_split_last_insert_of_mem_activeSet {α : Type u_1} [DecidableEq α] {n_max : ℕ} {ops : List (Op α)} (hval : ValidOpSeq n_max ops) {x : α} (hx : x ∈ activeSet ops) :
    ∃ (pre : List (Op α)) (suf : List (Op α)), ops = pre ++ Op.insert x :: suf ∧ ValidOpSeq n_max pre ∧ x ∉ activeSet pre ∧ (activeSet pre).card < n_max ∧ ∀ o ∈ suf, o ≠ Op.delete x

    Every ball x ∈ activeSet ops of an admissible sequence ops has a last absent-to-present insertion split ops = pre ++ .insert x :: suf where ValidOpSeq n_max pre, x ∉ activeSet pre, #(activeSet pre) < n_max, and suf contains no .delete x.

    Injective slot assignments #

    An injective assignment of balls from α into M unit-capacity primary slots Fin M.

    • occupant : Fin M → Option α

      Partial map giving the ball stored in each slot (none if the slot is free).

    • injective ⦃r₁ r₂ : Fin M⦄ ⦃x : α⦄ : self.occupant r₁ = some x → self.occupant r₂ = some x → r₁ = r₂

      Slot-wise injectivity: each ball occupies at most one slot.

    theorem Cslib.DataStructure.BallsToSlots.SlotAssignment.ext {α : Type u_1} {M : ℕ} {x y : SlotAssignment α M} (occupant : x.occupant = y.occupant) :
    x = y

    The empty slot assignment over M free slots.

    Finite set of currently unoccupied slots in s.

    Computable lookup of the unique slot holding ball x (none if x is absent).

    Finite set of balls currently present in s.

    @[simp]
    @[simp]
    @[simp]
    theorem Cslib.DataStructure.BallsToSlots.SlotAssignment.mem_present_iff {α : Type u_1} [DecidableEq α] {M : ℕ} (s : SlotAssignment α M) (x : α) :
    x ∈ s.present ↔ ∃ (r : Fin M), s.occupant r = some x

    Occupied balls and free slots partition all M slots.

    Strictly fewer than M balls are present if and only if at least one slot is free.

    Delete ball x by vacating its slot (leaving all other slots untouched).

    theorem Cslib.DataStructure.BallsToSlots.SlotAssignment.slotOf_delete_of_ne {α : Type u_1} [DecidableEq α] {M : ℕ} (s : SlotAssignment α M) {x y : α} (hne : y ≠ x) :
    (s.delete x).slotOf y = s.slotOf y

    Place ball y into slot r, preserving injective unconditionally.

    theorem Cslib.DataStructure.BallsToSlots.SlotAssignment.occupant_put_of_absent {α : Type u_1} [DecidableEq α] {M : ℕ} (s : SlotAssignment α M) (r : Fin M) {y : α} (hy : ∀ (r' : Fin M), s.occupant r' ≠ some y) :
    @[simp]
    theorem Cslib.DataStructure.BallsToSlots.SlotAssignment.slotOf_put_self {α : Type u_1} [DecidableEq α] {M : ℕ} (s : SlotAssignment α M) (r : Fin M) (y : α) :
    (s.put r y).slotOf y = some r
    theorem Cslib.DataStructure.BallsToSlots.SlotAssignment.slotOf_put_of_ne {α : Type u_1} [DecidableEq α] {M : ℕ} (s : SlotAssignment α M) (r : Fin M) (y : α) {z : α} (hzy : z ≠ y) (hrz : s.occupant r ≠ some z) :
    (s.put r y).slotOf z = s.slotOf z
    theorem Cslib.DataStructure.BallsToSlots.SlotAssignment.put_occupant_ne_old {α : Type u_1} [DecidableEq α] {M : ℕ} (s : SlotAssignment α M) {r : Fin M} {y y' : α} (hy : ∀ (r' : Fin M), s.occupant r' ≠ some y) (hocc : s.occupant r = some y') (r' : Fin M) :
    (s.put r y).occupant r' ≠ some y'
    theorem Cslib.DataStructure.BallsToSlots.SlotAssignment.present_put_of_some {α : Type u_1} [DecidableEq α] {M : ℕ} (s : SlotAssignment α M) {r : Fin M} {y y' : α} (hy : ∀ (r' : Fin M), s.occupant r' ≠ some y) (hocc : s.occupant r = some y') :
    (s.put r y).present = insert y (s.present.erase y')

    Probe sequences, probe complexity, and switching cost #

    def Cslib.DataStructure.BallsToSlots.RespectsProbeSeq {α : Type u_1} {M : ℕ} (probeSeq : α → ℕ → Fin M) (s : SlotAssignment α M) :

    A slot assignment s respects probeSeq when every present ball sits at a slot appearing on its probe sequence.

    theorem Cslib.DataStructure.BallsToSlots.respectsProbeSeq_empty {α : Type u_1} {M : ℕ} (probeSeq : α → ℕ → Fin M) :
    theorem Cslib.DataStructure.BallsToSlots.RespectsProbeSeq.delete {α : Type u_1} [DecidableEq α] {M : ℕ} {probeSeq : α → ℕ → Fin M} {s : SlotAssignment α M} (hs : RespectsProbeSeq probeSeq s) (x : α) :
    RespectsProbeSeq probeSeq (s.delete x)
    noncomputable def Cslib.DataStructure.BallsToSlots.probeIndex {α : Type u_1} {M : ℕ} (probeSeq : α → ℕ → Fin M) (x : α) (r : Fin M) :

    Minimum 0-based probe offset at which probeSeq x reaches slot r.

    theorem Cslib.DataStructure.BallsToSlots.probeIndex_le {α : Type u_1} {M : ℕ} (probeSeq : α → ℕ → Fin M) (x : α) {idx : ℕ} {r : Fin M} (h : probeSeq x idx = r) :
    probeIndex probeSeq x r ≤ idx
    theorem Cslib.DataStructure.BallsToSlots.probeSeq_probeIndex {α : Type u_1} {M : ℕ} (probeSeq : α → ℕ → Fin M) (x : α) {r : Fin M} (h : ∃ (idx : ℕ), probeSeq x idx = r) :
    probeSeq x (probeIndex probeSeq x r) = r
    noncomputable def Cslib.DataStructure.BallsToSlots.slotProbeComplexity {α : Type u_1} {M : ℕ} (probeSeq : α → ℕ → Fin M) (x : α) (r : Fin M) :

    Integer probe complexity 1 + ⌊log₂ (probeIndex + 1)⌋ of storing ball x in slot r. Uses the floor logarithm Nat.log 2 for 1-based probe index i = probeIndex + 1, differing from the real-logarithm measure 1 + log₂ i of [BFCK+22] (Section 2.1, printed p. 3 / PDF p. 4, and Section 3, printed p. 8 / PDF p. 9) by strictly less than 1 per ball and agreeing asymptotically.

    theorem Cslib.DataStructure.BallsToSlots.slotProbeComplexity_le_of_probeIndex_lt_two_pow {α : Type u_1} {M : ℕ} (probeSeq : α → ℕ → Fin M) (x : α) (r : Fin M) {e : ℕ} (h : probeIndex probeSeq x r < 2 ^ e) :
    slotProbeComplexity probeSeq x r ≤ 1 + e
    def Cslib.DataStructure.BallsToSlots.xorProbeSeq {α : Type u_1} (m : ℕ) (g : α → Fin (2 ^ m)) (x : α) (idx : ℕ) :
    Fin (2 ^ m)

    Canonical deduplicated XOR probe sequence idx ↦ g(x) ^^^ (idx % 2 ^ m) around g(x).

    theorem Cslib.DataStructure.BallsToSlots.xorProbeSeq_xor_self {α : Type u_1} (m : ℕ) (g : α → Fin (2 ^ m)) (x : α) (r : Fin (2 ^ m)) :
    xorProbeSeq m g x (↑(g x) ^^^ ↑r) = r
    theorem Cslib.DataStructure.BallsToSlots.slotProbeComplexity_xorProbeSeq_le_of_div_eq {α : Type u_1} (m : ℕ) (g : α → Fin (2 ^ m)) (x : α) {e : ℕ} {r : Fin (2 ^ m)} (hr : ↑r / 2 ^ e = ↑(g x) / 2 ^ e) :

    Canonical bijection splitting an (m + c)-bit word into (low m bits, high c bits), built from finProdFinEquiv.

    @[simp]
    theorem Cslib.DataStructure.BallsToSlots.val_dyadicSplitEquiv_fst (m c : ℕ) (u : Fin (2 ^ (m + c))) :
    ↑((dyadicSplitEquiv m c) u).1 = ↑u % 2 ^ m
    @[simp]
    theorem Cslib.DataStructure.BallsToSlots.val_dyadicSplitEquiv_snd (m c : ℕ) (u : Fin (2 ^ (m + c))) :
    ↑((dyadicSplitEquiv m c) u).2 = ↑u / 2 ^ m
    @[simp]
    theorem Cslib.DataStructure.BallsToSlots.val_dyadicSplitEquiv_symm (m c : ℕ) (p : Fin (2 ^ m) × Fin (2 ^ c)) :
    ↑((dyadicSplitEquiv m c).symm p) = ↑p.1 + 2 ^ m * ↑p.2
    noncomputable def Cslib.DataStructure.BallsToSlots.ballProbeComplexity {α : Type u_1} [DecidableEq α] {M : ℕ} (probeSeq : α → ℕ → Fin M) (s : SlotAssignment α M) (x : α) :

    Probe complexity of ball x in assignment s (0 if x is absent).

    @[simp]
    theorem Cslib.DataStructure.BallsToSlots.ballProbeComplexity_of_slotOf_eq_none {α : Type u_1} [DecidableEq α] {M : ℕ} (probeSeq : α → ℕ → Fin M) {s : SlotAssignment α M} {x : α} (h : s.slotOf x = none) :
    ballProbeComplexity probeSeq s x = 0
    @[simp]
    theorem Cslib.DataStructure.BallsToSlots.ballProbeComplexity_of_slotOf_eq_some {α : Type u_1} [DecidableEq α] {M : ℕ} (probeSeq : α → ℕ → Fin M) {s : SlotAssignment α M} {x : α} {r : Fin M} (h : s.slotOf x = some r) :
    ballProbeComplexity probeSeq s x = slotProbeComplexity probeSeq x r
    noncomputable def Cslib.DataStructure.BallsToSlots.totalProbeComplexity {α : Type u_1} {M : ℕ} (probeSeq : α → ℕ → Fin M) (s : SlotAssignment α M) :

    Total probe complexity summed across all occupied slots of s.

    theorem Cslib.DataStructure.BallsToSlots.totalProbeComplexity_eq_sum_present {α : Type u_1} [DecidableEq α] {M : ℕ} (probeSeq : α → ℕ → Fin M) (s : SlotAssignment α M) :
    totalProbeComplexity probeSeq s = ∑ x ∈ s.present, ballProbeComplexity probeSeq s x

    Total probe complexity over occupied slots equals the sum of ballProbeComplexity over s.present.

    Deterministic switching cost between s and s': balls in s.present ∪ s'.present whose assigned slot changed.

    Number of balls present in both s and s' that moved to a different slot.

    Number of slots r : Fin M whose occupant changed between s and s'.

    theorem Cslib.DataStructure.BallsToSlots.changedSlots_triangle {α : Type u_1} [DecidableEq α] {M : ℕ} (s₁ s₂ s₃ : SlotAssignment α M) :
    changedSlots s₁ s₃ ≤ changedSlots s₁ s₂ + changedSlots s₂ s₃
    theorem Cslib.DataStructure.BallsToSlots.SlotAssignment.changedSlots_put_le {α : Type u_1} [DecidableEq α] {M : ℕ} (s : SlotAssignment α M) (r : Fin M) {y : α} (hy : ∀ (r' : Fin M), s.occupant r' ≠ some y) :
    changedSlots s (s.put r y) ≤ 1
    theorem Cslib.DataStructure.BallsToSlots.displacedBalls_add_one_le_switchingCost {α : Type u_1} [DecidableEq α] {M : ℕ} {s s' : SlotAssignment α M} {y : α} (hy_old : y ∉ s.present) (hy_new : y ∈ s'.present) :
    @[simp]

    Deleting x displaces 0 remaining balls.

    Deleting x has switching cost at most 1.

    Deleting x modifies at most 1 slot.

    Relational StateTransitionSpec for a balls-to-slots scheme over α, M slots, and capacity n_max.

    def Cslib.DataStructure.BallsToSlots.schemeSpec (α : Type u_1) [DecidableEq α] (M n_max B_switch : ℕ) (probeSeq : α → ℕ → Fin M) :

    Relational StateTransitionSpec additionally enforcing probe-sequence validity and worst-case per-operation switching-cost bound B_switch.

    theorem Cslib.DataStructure.BallsToSlots.dens_sum_totalProbeComplexity_gt_le_of_snapshotBound {ι : Type u_1} {α : Type u_2} {β : Type u_3} {Y : Type u_4} [Fintype ι] [DecidableEq α] [Fintype Y] [DecidableEq Y] [Nonempty Y] {m M B_max k_indep : ℕ} (hm : 1 ≤ m) (hM : 0 < M) (hB_max : 0 < B_max) {h : ι → α → Y} (hh : Probability.IsKWiseIndependentHash k_indep h) (hk : 2 * m * (M * M) ≤ k_indep) (probe : (α → Y) → α → ℕ → Fin M) (assign : (α → Y) → List (Op α) → SlotAssignment α M) (bound : (α → Y) → Finset α → α → ℕ) (hbound_le : ∀ (f : α → Y) (S : Finset α) (x : α), bound f S x ≤ B_max) (hbound_congr : ∀ {f₁ f₂ : α → Y} {S : Finset α} {x : α}, (∀ a ∈ insert x S, f₁ a = f₂ a) → bound f₁ S x = bound f₂ S x) (hpres : ∀ (f : α → Y) {l : List (Op α)}, ValidOpSeq M l → (assign f l).present = activeSet l) (hdom : ∀ (f : α → Y) {l : List (Op α)} (hl : ValidOpSeq M l) {x : α} (hx : x ∈ activeSet l), ballProbeComplexity (probe f) (assign f l) x ≤ bound f (activeSet ⋯.choose) x) (R : Finset β) (ops : β → List (Op α)) (hval : ∀ b ∈ R, ValidOpSeq M (ops b)) (hdisj : (↑R).Pairwise fun (b₁ b₂ : β) => Disjoint (opsBalls (ops b₁)) (opsBalls (ops b₂))) {c μ Δ : ℝ} (hexp : ∀ {S : Finset α}, S.card ≤ M → ∀ {x : α}, x ∉ S → (Finset.univ.expect fun (θ : ι) => ↑(bound (h θ) S x)) ≤ c) (hμ : c * ∑ b ∈ R, ↑(activeSet (ops b)).card ≤ μ) (hmμ : 2 * ↑m * ↑M * ↑B_max ≤ 3 * μ) (hΔ : 0 < Δ) :
    ↑{θ : ι | μ + Δ ≤ ∑ b ∈ R, ↑(totalProbeComplexity (probe (h θ)) (assign (h θ) (ops b)))}.dens ≤ 2 * (3 * ↑m * ↑M * ↑B_max * μ / Δ ^ 2) ^ m

    2m-th moment concentration for total probe complexity across a collection R of admissible histories ops b with pairwise disjoint opsBalls (ops b), given a per-ball snapshot bound.