Documentation

CslibFrontier.DataStructure.Paging.FIFO

First-in, first-out (FIFO) paging and LIFO non-competitiveness #

This file formalizes two companion deterministic paging results from Section 4 ("Paging"), pp. 207–208, of Sleator and Tarjan, Amortized Efficiency of List Update and Paging Rules in the equal-capacity (n_A = n_MIN = k) demand-paging model of CslibFrontier.DataStructure.Paging.Basic:

  1. FIFO k-competitiveness (fifoStrategy_isCompetitive, fifoStrategy_isCompetitiveAnyInit): First-in, first-out (FIFO) replaces the page that has resided in fast memory longest (p. 207), leaving arrival order unchanged on a cache hit (fifoNext k q p = q when p ∈ q) and matching lruNext on every cache miss ((p :: q).take k when p ∉ q). Consequently, lruPotential from CslibFrontier.DataStructure.Paging.LRU is directly an Amortized potential certificate for FIFO (fifoPotential_step, fifoAmortized, p. 208), giving (k, 0)-competitiveness from any common initial cache and (k, k)-competitiveness across arbitrary initial caches.
  2. LIFO non-competitiveness (lifo_not_isCompetitiveFrom_empty, lifo_not_isCompetitive): Last-in, first-out (LIFO) replaces the page most recently moved into fast memory (p. 207). For k = 1, LIFO coincides with FIFO and is (1, 0)-competitive (lifoStrategy_one_isCompetitive). For every capacity k ≥ 2 over at least k + 1 distinct pages, Sleator and Tarjan's sequence of k - 1 distinct warmup accesses followed by repeated alternating accesses to two further pages (p. 208) forces LIFO to fault at every step while an offline cache of size k faults only k + 1 times in total, refuting (c, b)-competitiveness for all c, b : Nat.

Resource augmentation with unequal fast-memory capacities (n_MIN < n_FIFO) and the LFU counterexample are not formalized here.

Main definitions #

Main results #

References #

First-in, first-out (FIFO) paging and k-competitiveness #

def Cslib.DataStructure.Paging.fifoNext {α : Type} [DecidableEq α] (k : ℕ) (q : List α) (p : α) :
List α

Advance the arrival-ordered FIFO queue (most recently inserted first, longest-resident last) of capacity k on page p: hits leave the queue unchanged, while misses prepend p and truncate to length k.

def Cslib.DataStructure.Paging.fifoStep {α : Type} [DecidableEq α] (k : ℕ) (q : List α) (p : α) :

Single-step FIFO update returning the new queue and whether a page fault occurred.

def Cslib.DataStructure.Paging.fifoRun {α : Type} [DecidableEq α] (k : ℕ) (q : List α) :
List α → List α

Run fifoNext k across a request list from initial arrival queue q.

def Cslib.DataStructure.Paging.fifoFaults {α : Type} [DecidableEq α] (k : ℕ) (q : List α) :
List α → ℕ

Count total page faults incurred by computable queue-based FIFO from q on reqs.

@[simp]
theorem Cslib.DataStructure.Paging.fifoRun_nil {α : Type} [DecidableEq α] (k : ℕ) (q : List α) :
fifoRun k q [] = q
@[simp]
theorem Cslib.DataStructure.Paging.fifoRun_cons {α : Type} [DecidableEq α] (k : ℕ) (q : List α) (p : α) (ps : List α) :
fifoRun k q (p :: ps) = fifoRun k (fifoNext k q p) ps
@[simp]
@[simp]
theorem Cslib.DataStructure.Paging.fifoFaults_cons {α : Type} [DecidableEq α] (k : ℕ) (q : List α) (p : α) (ps : List α) :
fifoFaults k q (p :: ps) = (if p ∈ q then 0 else 1) + fifoFaults k (fifoNext k q p) ps
theorem Cslib.DataStructure.Paging.fifoNext_eq_lruNext_of_notMem {α : Type} [DecidableEq α] {k : ℕ} {q : List α} {p : α} (hp : p ∉ q) :
fifoNext k q p = lruNext k q p

On every cache miss p ∉ q, fifoNext coincides with lruNext.

theorem Cslib.DataStructure.Paging.nodup_fifoNext {α : Type} [DecidableEq α] {k : ℕ} {q : List α} (hq : q.Nodup) (p : α) :
(fifoNext k q p).Nodup

fifoNext preserves List.Nodup.

theorem Cslib.DataStructure.Paging.length_fifoNext_le {α : Type} [DecidableEq α] {k : ℕ} {q : List α} (hq : q.length ≤ k) (p : α) :
(fifoNext k q p).length ≤ k

fifoNext k preserves length ≤ k.

theorem Cslib.DataStructure.Paging.validStep_fifoNext {α : Type} [DecidableEq α] {k : ℕ} (hk : 0 < k) {q : List α} (hlen : q.length ≤ k) (p : α) :

For 0 < k, fifoNext induces a valid demand-paging transition on q.toFinset.

@[reducible, inline]
noncomputable abbrev Cslib.DataStructure.Paging.fifoStrategy {α : Type} [DecidableEq α] (k : ℕ) (hk : 0 < k) :

Deterministic online strategy realizing FIFO for demand paging with positive capacity k.

Marked noncomputable solely because init s₀ := s₀.toList chooses an initial arrival order on pre-loaded cache elements from s₀ : Finset α ([] when s₀ = ∅, witnessed by fifoStrategy_cost_empty).

theorem Cslib.DataStructure.Paging.fifoStrategy_runMem_eq {α : Type} [DecidableEq α] (k : ℕ) (hk : 0 < k) (q reqs : List α) :
(fifoStrategy k hk).runMem q reqs = fifoRun k q reqs

fifoStrategy.runMem agrees with computable fifoRun.

theorem Cslib.DataStructure.Paging.fifoStrategy_costFrom_eq {α : Type} [DecidableEq α] (k : ℕ) (hk : 0 < k) (q reqs : List α) :
(fifoStrategy k hk).costFrom q reqs = fifoFaults k q reqs

fifoStrategy.costFrom agrees with computable fifoFaults.

theorem Cslib.DataStructure.Paging.fifoStrategy_cost_empty {α : Type} [DecidableEq α] (k : ℕ) (hk : 0 < k) (reqs : List α) :
(fifoStrategy k hk).cost ∅ reqs = fifoFaults k [] reqs

From an empty cache ∅, fifoStrategy.cost equals computable fifoFaults k [] reqs.

theorem Cslib.DataStructure.Paging.fifoPotential_step {α : Type} [DecidableEq α] {k : ℕ} (hk : 0 < k) {s s' : Finset α} {q : List α} {p : α} (hq : q.Nodup ∧ q.length ≤ k) (hv : ValidStep k s p s') :

Single-step competitive potential inequality for FIFO (0 < k), reusing lruPotential: hits keep fifoNext k q p = q unchanged while misses delegate to lruPotential_step.

theorem Cslib.DataStructure.Paging.fifoAmortized {α : Type} [DecidableEq α] (k : ℕ) (hk : 0 < k) :
Amortized (fifoStrategy k hk).impl id (lruPotential k) fun (s : (problem α k).offlineSpec.State) (o : (problem α k).offlineSpec.Op) => k * stepCost s o.1 o.2

Native Cslib.DataStructure.Amortized potential certificate for fifoStrategy k hk against k times the offline demand-paging step cost.

theorem Cslib.DataStructure.Paging.fifoFaults_amortized_bound {α : Type} [DecidableEq α] {k : ℕ} (hk : 0 < k) {s_off : Finset α} {q reqs : List α} {offStates : List (Finset α)} (hq : q.Nodup ∧ q.length ≤ k) (hv : (problem α k).ValidSchedule s_off reqs offStates) :
fifoFaults k q reqs + lruPotential k ((problem α k).finalState s_off offStates) (fifoRun k q reqs) ≤ k * (problem α k).scheduleCost s_off reqs offStates + lruPotential k s_off q

Computable-list telescoping bound for FIFO: for any valid arrival queue q and valid offline schedule (s_off, reqs, offStates), fifoFaults k q reqs plus final potential is at most k times offline faults plus initial potential.

FIFO k-competitiveness from a common initial cache ([ST85a], Section 4, p. 208 at n_FIFO = n_MIN = k with identical initial caches): when online and offline algorithms start from the same valid cache s₀ (including ∅), fifoStrategy k hk incurs at most k times the faults of any valid offline schedule, with zero additive constant.

FIFO k-competitiveness across arbitrary initial caches ([ST85a], Section 4, p. 208 at n_FIFO = n_MIN = k): for any valid initial caches s₀ and s_off of size at most k, fifoStrategy k hk incurs at most k * optCost + k faults.

Last-in, first-out (LIFO) paging and Sleator–Tarjan's counterexample (2 ≤ k) #

def Cslib.DataStructure.Paging.lifoNext {α : Type} [DecidableEq α] (k : ℕ) (q : List α) (p : α) :
List α

Advance the LIFO stack (most recently inserted page at the head) of capacity k on page p: hits leave the stack unchanged, misses into a non-full cache push p, and misses into a full cache replace the head (the page most recently moved into fast memory) with p.

def Cslib.DataStructure.Paging.lifoRun {α : Type} [DecidableEq α] (k : ℕ) (q : List α) :
List α → List α

Run lifoNext k across a request list from initial LIFO stack q.

def Cslib.DataStructure.Paging.lifoFaults {α : Type} [DecidableEq α] (k : ℕ) (q : List α) :
List α → ℕ

Count total page faults incurred by computable LIFO from q on reqs.

@[simp]
theorem Cslib.DataStructure.Paging.lifoRun_nil {α : Type} [DecidableEq α] (k : ℕ) (q : List α) :
lifoRun k q [] = q
@[simp]
theorem Cslib.DataStructure.Paging.lifoRun_cons {α : Type} [DecidableEq α] (k : ℕ) (q : List α) (p : α) (ps : List α) :
lifoRun k q (p :: ps) = lifoRun k (lifoNext k q p) ps
@[simp]
@[simp]
theorem Cslib.DataStructure.Paging.lifoFaults_cons {α : Type} [DecidableEq α] (k : ℕ) (q : List α) (p : α) (ps : List α) :
lifoFaults k q (p :: ps) = (if p ∈ q then 0 else 1) + lifoFaults k (lifoNext k q p) ps
@[simp]
theorem Cslib.DataStructure.Paging.lifoFaults_append {α : Type} [DecidableEq α] (k : ℕ) (q rs₁ rs₂ : List α) :
lifoFaults k q (rs₁ ++ rs₂) = lifoFaults k q rs₁ + lifoFaults k (lifoRun k q rs₁) rs₂
theorem Cslib.DataStructure.Paging.nodup_lifoNext {α : Type} [DecidableEq α] {k : ℕ} {q : List α} (hq : q.Nodup) (p : α) :
(lifoNext k q p).Nodup

lifoNext preserves List.Nodup.

theorem Cslib.DataStructure.Paging.length_lifoNext_le {α : Type} [DecidableEq α] {k : ℕ} {q : List α} (hq : q.length ≤ k) (p : α) :
(lifoNext k q p).length ≤ k

lifoNext k preserves length ≤ k.

theorem Cslib.DataStructure.Paging.validStep_lifoNext {α : Type} [DecidableEq α] {k : ℕ} (hk : 0 < k) {q : List α} (hnodup : q.Nodup) (hlen : q.length ≤ k) (p : α) :

For 0 < k, lifoNext induces a valid demand-paging transition on q.toFinset.

@[reducible, inline]
noncomputable abbrev Cslib.DataStructure.Paging.lifoStrategy {α : Type} [DecidableEq α] (k : ℕ) (hk : 0 < k) :

Deterministic online strategy realizing LIFO for demand paging with positive capacity k.

theorem Cslib.DataStructure.Paging.lifoStrategy_costFrom_eq {α : Type} [DecidableEq α] (k : ℕ) (hk : 0 < k) (q reqs : List α) :
(lifoStrategy k hk).costFrom q reqs = lifoFaults k q reqs

lifoStrategy.costFrom agrees with computable lifoFaults.

theorem Cslib.DataStructure.Paging.lifoStrategy_cost_empty {α : Type} [DecidableEq α] (k : ℕ) (hk : 0 < k) (reqs : List α) :
(lifoStrategy k hk).cost ∅ reqs = lifoFaults k [] reqs

From ∅, lifoStrategy.cost equals computable lifoFaults k [] reqs.

At capacity k = 1, lifoNext 1 equals fifoNext 1, so LIFO is (1, 0)-competitive; the hypothesis 2 ≤ k in lifo_not_isCompetitiveFrom_empty is therefore sharp.

def Cslib.DataStructure.Paging.lifoCounterexample {α : Type} (init : List α) (a b : α) (t : ℕ) :
List α

Sleator–Tarjan LIFO counterexample ([ST85a], p. 208): init (k - 1 distinct pages) followed by t + 1 alternating pairs [a, b] of two further distinct pages.

theorem Cslib.DataStructure.Paging.lifoFaults_lifoCounterexample {α : Type} [DecidableEq α] {k : ℕ} (hk : 1 ≤ k) {init : List α} {a b : α} (hinit : init.length = k - 1) (hnodup : (init ++ [a, b]).Nodup) (t : ℕ) :
lifoFaults k [] (lifoCounterexample init a b t) = k - 1 + 2 * (t + 1)

On lifoCounterexample init a b t (init.length = k - 1, (init ++ [a, b]).Nodup, 1 ≤ k), LIFO from [] faults on every single request ((k - 1) + 2 * (t + 1) faults).

theorem Cslib.DataStructure.Paging.exists_offline_lifoCounterexample {α : Type} [DecidableEq α] {k : ℕ} (hk2 : 2 ≤ k) {init : List α} {a b : α} (hinit : init.length = k - 1) (hnodup : (init ++ [a, b]).Nodup) (t : ℕ) :
∃ (offStates : List (problem α k).State), (problem α k).ValidSchedule ∅ (lifoCounterexample init a b t) offStates ∧ (problem α k).scheduleCost ∅ (lifoCounterexample init a b t) offStates = k + 1

For 2 ≤ k, an offline schedule of capacity k serves lifoCounterexample init a b t from ∅ with at most k + 1 faults by retaining {a, b} in fast memory across all alternating pairs.

theorem Cslib.DataStructure.Paging.lifo_not_isCompetitiveFrom_empty {α : Type} [DecidableEq α] {k : ℕ} (hk2 : 2 ≤ k) {pages : List α} (hnodup : pages.Nodup) (hlen : pages.length = k + 1) (c b : ℕ) :

LIFO is not competitive for 2 ≤ k ([ST85a], Section 4, p. 208): over any k + 1 distinct pages (pages.Nodup, pages.length = k + 1), lifoStrategy from ∅ fails (c, b)-competitiveness for every c, b : Nat.

theorem Cslib.DataStructure.Paging.lifo_not_isCompetitive {α : Type} [DecidableEq α] {k : ℕ} (hk2 : 2 ≤ k) {pages : List α} (hnodup : pages.Nodup) (hlen : pages.length = k + 1) (c b : ℕ) :

Over ≥ k + 1 pages with 2 ≤ k, lifoStrategy is not (c, b)-competitive.

theorem Cslib.DataStructure.Paging.lifo_not_isCompetitiveAnyInit {α : Type} [DecidableEq α] {k : ℕ} (hk2 : 2 ≤ k) {pages : List α} (hnodup : pages.Nodup) (hlen : pages.length = k + 1) (c b : ℕ) :

Over ≥ k + 1 pages with 2 ≤ k, lifoStrategy is not (c, b)-competitive across arbitrary initial caches.

Canonical LIFO impossibility on Fin (k + 1) (2 ≤ k): LIFO from ∅ is not (c, b)-competitive for any c, b : Nat.