Documentation

CslibFrontier.DataStructure.ListUpdate.Timestamp

The Timestamp(0) algorithm and pairwise projection for list update #

This file formalizes Susanne Albers's deterministic Timestamp(0) (TS(0)) list-update algorithm (Albers, Improved Randomized On-Line Algorithms for the List Update Problem; see also Borodin and El-Yaniv, Online Computation and Competitive Analysis, Chapter 1) and develops the pairwise projection framework shared with CslibFrontier.DataStructure.ListUpdate.Comb.

Algorithm #

Controller memory (TimestampMem α) stores the current list arrangement together with the past request sequence in reverse chronological order (history). On request r:

Because moveBeforeFirst only moves r forward without reordering other items, Timestamp(0) pays exactly the 1-based position l.idxOf r + 1 in ListUpdate.problem α (stepCost_moveBeforeFirst, stepCost_timestampStep).

Pairwise invariant and 2-competitiveness #

Timestamp(0) maintains the inductive suffix-frequency invariant (TimestampInv): for every length k and items u, v with u ahead of v in the list, if v was requested at least twice in the last k requests then u was also requested at least twice in the last k requests. Consequently, on any second or later access to r, an item x preceding r stays ahead of r iff x was requested at least twice since r's last access (idxOf_timestampStep_lt_self_iff), which depends only on the projection of the request sequence onto {x, r}.

This pairwise behavior is tracked by the 6-state automaton PairPhase (xx, yx, xxy, yyx, xy, yy), which also tracks the exact bit-averaged state of BIT in CslibFrontier.DataStructure.ListUpdate.Comb. Summing a 6-state pairwise potential over all initially ordered pairs orderedPairs m₀ yields cost_TS0 + |reqs| ≤ 2 * scheduleCost + 2 * inversions m₀ s₀ (timestamp0_cost_add_length_le), establishing (2, 0)-competitiveness from a common initial arrangement (timestamp0_isCompetitive) and (2, n * (n - 1))-competitiveness across arbitrary initial arrangements (timestamp0_isCompetitiveAnyInit).

The primary journal text of [Alb98] was not inspected firsthand; no internal theorem or section numbers are claimed.

Main definitions #

Main results #

References #

Moving an item forward before the first matching item #

def Cslib.DataStructure.ListUpdate.moveBeforeFirst {α : Type} [DecidableEq α] (r : α) (p : α → Bool) :
List α → List α

Move r immediately before the first item preceding r in l that satisfies p, preserving the relative order of all other items. If no earlier item satisfies p, l is unchanged.

moveBeforeFirst preserves IsArrangement.

theorem Cslib.DataStructure.ListUpdate.idxOf_moveBeforeFirst_lt_iff_of_ne {α : Type} [DecidableEq α] {l : List α} (hl : l.Nodup) {r : α} (hr : r ∈ l) (p : α → Bool) {x y : α} (hx : x ≠ r) (hy : y ≠ r) :

moveBeforeFirst r p preserves the relative order of every pair of items distinct from r.

theorem Cslib.DataStructure.ListUpdate.idxOf_moveBeforeFirst_lt_self_iff {α : Type} [DecidableEq α] {l : List α} (hl : l.Nodup) {r x : α} (hr : r ∈ l) (hxmem : x ∈ l) (hx : x ≠ r) (p : α → Bool) :
List.idxOf x (moveBeforeFirst r p l) < List.idxOf r (moveBeforeFirst r p l) ↔ List.idxOf x l < List.idxOf r l ∧ ∀ (w : α), List.idxOf w l ≤ List.idxOf x l → p w = false

In moveBeforeFirst r p l, an item x ≠ r stays before r iff x preceded r in l and every item at or before x in l fails p.

theorem Cslib.DataStructure.ListUpdate.stepCost_moveBeforeFirst {α : Type} [DecidableEq α] [Fintype α] {l : List α} (hl : IsArrangement l) (r : α) (p : α → Bool) :

Moving r forward with moveBeforeFirst costs l.idxOf r + 1 in ListUpdate.problem α.

Timestamp(0) definition and suffix-frequency invariant #

Controller memory for Timestamp(0): current list arrangement and past requests in reverse chronological order (most recent first).

  • list : List α

    Current list arrangement.

  • history : List α

    Past requests in reverse chronological order (head is the most recent request).

Single step of Timestamp(0) on request r: if r was previously requested, move r immediately before the first earlier item appearing at most once since r's last request; otherwise leave the list unchanged.

Suffix-frequency invariant of Timestamp(0): for every suffix length k and items u, v with u preceding v in m.list, if v appears at least twice among the k most recent requests then u also appears at least twice among the k most recent requests.

Under TimestampInv, moving r on a repeat access leaves x ≠ r ahead of r iff x was ahead of r and appeared at least twice since r's last access.

timestampStep preserves the relative order of any two items distinct from r.

Timestamp(0) pays exactly the 1-based position of the requested item.

@[reducible, inline]

The deterministic Timestamp(0) strategy for list update over α ([Alb98]).

Pairwise cost decomposition and the 6-state phase automaton #

Ordered pairs (x, y) with x preceding y in the reference arrangement m₀. Every unordered pair of distinct items appears in orderedPairs m₀ with a unique orientation.

theorem Cslib.DataStructure.ListUpdate.ne_of_mem_orderedPairs {α : Type} [DecidableEq α] [Fintype α] {m₀ : List α} {p : α × α} (hp : p ∈ orderedPairs m₀) :
p.1 ≠ p.2

Every pair in orderedPairs m₀ has distinct components.

def Cslib.DataStructure.ListUpdate.pairOffCost {α : Type} [DecidableEq α] (x y : α) (s : List α) (r : α) (s' : List α) :

Partial-cost contribution of an offline transition s ↦ s' serving r on the unordered pair {x, y}: 1 if s and s' disagree on {x, y}, plus 1 if r ∈ {x, y} and the other item precedes r in s'.

theorem Cslib.DataStructure.ListUpdate.sum_orderedPairs_idxOf {α : Type} [DecidableEq α] [Fintype α] {m₀ l : List α} (hm₀ : IsArrangement m₀) (hl : IsArrangement l) (r : α) :
∑ p ∈ orderedPairs m₀, ((if r = p.1 ∧ List.idxOf p.2 l < List.idxOf p.1 l then 1 else 0) + if r = p.2 ∧ List.idxOf p.1 l < List.idxOf p.2 l then 1 else 0) = List.idxOf r l

Sum of pairwise access indicators over orderedPairs m₀ equals l.idxOf r.

theorem Cslib.DataStructure.ListUpdate.sum_orderedPairs_inversions {α : Type} [DecidableEq α] [Fintype α] {m₀ s s' : List α} (hm₀ : IsArrangement m₀) (hs : IsArrangement s) (hs' : IsArrangement s') :
(∑ p ∈ orderedPairs m₀, if (decide (List.idxOf p.1 s < List.idxOf p.2 s) != decide (List.idxOf p.1 s' < List.idxOf p.2 s')) = true then 1 else 0) = inversions s s'

Sum of pairwise disagreement indicators over orderedPairs m₀ equals inversions s s'.

theorem Cslib.DataStructure.ListUpdate.sum_orderedPairs_pairOffCost {α : Type} [DecidableEq α] [Fintype α] {m₀ s s' : List α} (hm₀ : IsArrangement m₀) (hs : IsArrangement s) (hs' : IsArrangement s') (r : α) :
∑ p ∈ orderedPairs m₀, pairOffCost p.1 p.2 s r s' = inversions s s' + List.idxOf r s'

Exact pairwise decomposition of offline partial cost inversions s s' + s'.idxOf r.

The 6-state pairwise history automaton for a pair (x, y) initially ordered x before y. Each state records the recent {x, y} access pattern determining both Timestamp(0)'s relative order and BIT's exact 4-bit distribution.

Transition on a request to the first item x.

Transition on a request to the second item y.

Transition on an arbitrary request r (requests outside {x, y} leave the phase fixed).

Whether y precedes x in Timestamp(0)'s list at phase ph.

Partial-cost contribution of Timestamp(0) on {x, y} at request r.

Invariant linking a Timestamp(0) controller state m to the pairwise phase ph on (x, y).

theorem Cslib.DataStructure.ListUpdate.TimestampPairRel.init {α : Type} [DecidableEq α] {m₀ : List α} {x y : α} (hord : List.idxOf x m₀ < List.idxOf y m₀) :
TimestampPairRel x y { list := m₀, history := [] } PairPhase.xx
theorem Cslib.DataStructure.ListUpdate.TimestampPairRel.step {α : Type} [DecidableEq α] {x y : α} (hxy : x ≠ y) {m : TimestampMem α} (hm : IsArrangement m.list) (hinv : TimestampInv m) {ph : PairPhase} (hrel : TimestampPairRel x y m ph) (r : α) :

PairPhase.step tracks timestampStep on every pair of distinct items.

2-competitiveness of Timestamp(0) #

theorem Cslib.DataStructure.ListUpdate.pairPhase_step_le_of_cases {α : Type} [DecidableEq α] {x y : α} (hxy : x ≠ y) {s s' : List α} (hs : IsArrangement s) (hs' : IsArrangement s') {c : ℕ} {pot : PairPhase → Bool → ℕ} {algCost : PairPhase → α → ℕ} (hfst : ∀ (ph : PairPhase) (o o' : Bool), algCost ph x + pot ph.stepFst o' ≤ c * ((if (o != o') = true then 1 else 0) + if o' = true then 1 else 0) + pot ph o) (hsnd : ∀ (ph : PairPhase) (o o' : Bool), algCost ph y + pot ph.stepSnd o' ≤ c * ((if (o != o') = true then 1 else 0) + if o' = false then 1 else 0) + pot ph o) (hother : ∀ (r : α), r ≠ x → r ≠ y → ∀ (ph : PairPhase) (o o' : Bool), algCost ph r + pot ph o' ≤ (c * if (o != o') = true then 1 else 0) + pot ph o) (ph : PairPhase) (r : α) :
algCost ph r + pot (PairPhase.step x y r ph) (decide (List.idxOf y s' < List.idxOf x s')) ≤ c * pairOffCost x y s r s' + pot ph (decide (List.idxOf y s < List.idxOf x s))

Reduce a pairwise potential step inequality on arrangements (s, s') to finite checks over PairPhase × Bool × Bool for the three request cases (r = x, r = y, and r ∉ {x, y}).

Advance a pairwise phase along a request list.

theorem Cslib.DataStructure.ListUpdate.sum_orderedPairs_init_pot {α : Type} [DecidableEq α] [Fintype α] (m₀ s₀ : List α) (f : Bool → ℕ) (hf : f false = 0) :
∑ p ∈ orderedPairs m₀, f (decide (List.idxOf p.2 s₀ < List.idxOf p.1 s₀)) = f true * inversions m₀ s₀

Summing a pairwise initial potential that vanishes on aligned pairs yields f true * inversions.

theorem Cslib.DataStructure.ListUpdate.sum_orderedPairs_tsCost {α : Type} [DecidableEq α] [Fintype α] {m₀ : List α} (hm₀ : IsArrangement m₀) {m : TimestampMem α} (hm : IsArrangement m.list) (ph : α × α → PairPhase) (hrel : ∀ p ∈ orderedPairs m₀, TimestampPairRel p.1 p.2 m (ph p)) (r : α) :
∑ p ∈ orderedPairs m₀, PairPhase.tsCost p.1 p.2 r (ph p) = List.idxOf r m.list

Summing a pairwise Timestamp(0) cost indicator over orderedPairs m₀ equals m.list.idxOf r.

theorem Cslib.DataStructure.ListUpdate.sum_orderedPairs_pairStep_le {α : Type} [DecidableEq α] [Fintype α] {m₀ s₀ s' : List α} (hm₀ : IsArrangement m₀) (hs₀ : IsArrangement s₀) (hs' : IsArrangement s') (ph : α × α → PairPhase) (r : α) (stepCostF : α × α → ℕ) (pot : PairPhase → Bool → ℕ) (c : ℕ) (hstep : ∀ p ∈ orderedPairs m₀, stepCostF p + pot (PairPhase.step p.1 p.2 r (ph p)) (decide (List.idxOf p.2 s' < List.idxOf p.1 s')) ≤ c * pairOffCost p.1 p.2 s₀ r s' + pot (ph p) (decide (List.idxOf p.2 s₀ < List.idxOf p.1 s₀))) :
∑ p ∈ orderedPairs m₀, stepCostF p + ∑ p ∈ orderedPairs m₀, pot (PairPhase.step p.1 p.2 r (ph p)) (decide (List.idxOf p.2 s' < List.idxOf p.1 s')) ≤ c * (inversions s₀ s' + List.idxOf r s') + ∑ p ∈ orderedPairs m₀, pot (ph p) (decide (List.idxOf p.2 s₀ < List.idxOf p.1 s₀))

Sum a pairwise step potential inequality over orderedPairs m₀ and substitute the pairwise offline cost decomposition sum_orderedPairs_pairOffCost.

theorem Cslib.DataStructure.ListUpdate.timestamp0_cost_add_length_le {α : Type} [DecidableEq α] [Fintype α] {m₀ s₀ : List α} (hm₀ : IsArrangement m₀) (hs₀ : IsArrangement s₀) {reqs : List α} {states : List (List α)} (hv : (problem α).ValidSchedule s₀ reqs states) :
(timestamp0 α).cost m₀ reqs + reqs.length ≤ 2 * (problem α).scheduleCost s₀ reqs states + 2 * inversions m₀ s₀

Competitiveness inequality for Timestamp(0) ([Alb98]): for every valid offline schedule states serving reqs from s₀, Timestamp(0) started from m₀ satisfies cost_TS0 + |reqs| ≤ 2 * scheduleCost + 2 * inversions m₀ s₀.

Timestamp(0) is (2, 0)-competitive from a common initial arrangement ([Alb98]).

Timestamp(0) is (2, n * (n - 1))-competitive across arbitrary initial arrangements, where n = Fintype.card α.