Documentation

CslibFrontier.DataStructure.Paging.Basic

The demand-paging action and cost model #

This file instantiates Cslib.DataStructure.Online.Problem for the classical unweighted demand-paging (cache replacement) problem of Sleator and Tarjan, Amortized Efficiency of List Update and Paging Rules, Section 4 ("Paging"), pp. 207–208 and Cormen, Leiserson, Rivest, and Stein, Introduction to Algorithms, third edition, Problem 16-5 ("Off-line caching").

Over a page universe α ([DecidableEq α]) and cache capacity k : Nat:

Both online paging strategies (Online.DetStrategy (problem α k)) and offline reference schedules ((problem α k).ValidSchedule) share this exact transition and fault-counting specification, including initial cache configurations.

Main definitions #

Main results #

References #

A cache configuration is admissible for capacity k when it holds at most k pages.

def Cslib.DataStructure.Paging.ValidStep {α : Type} [DecidableEq α] (k : ℕ) (s : Finset α) (p : α) (s' : Finset α) :

Valid single-request demand-paging transition s ↦ s' on page p: both caches hold at most k pages, p resides in s', cache hits preserve s' = s, and cache misses satisfy s' ⊆ insert p s.

def Cslib.DataStructure.Paging.stepCost {α : Type} [DecidableEq α] (s : Finset α) (p : α) :
Finset α → ℕ

Standard paging cost: 0 on a cache hit (p ∈ s) and 1 on a cache miss (p ∉ s).

@[reducible, inline]

The demand-paging Online.Problem over page type α and cache capacity k.

@[simp]
theorem Cslib.DataStructure.Paging.stepCost_of_mem {α : Type} [DecidableEq α] {s s' : Finset α} {p : α} (hp : p ∈ s) :
stepCost s p s' = 0
@[simp]
theorem Cslib.DataStructure.Paging.stepCost_of_notMem {α : Type} [DecidableEq α] {s s' : Finset α} {p : α} (hp : p ∉ s) :
stepCost s p s' = 1
theorem Cslib.DataStructure.Paging.stepCost_le_one {α : Type} [DecidableEq α] (s : Finset α) (p : α) (s' : Finset α) :
stepCost s p s' ≤ 1

Every single-step paging transition charges at most one fault.

theorem Cslib.DataStructure.Paging.validStep_hit {α : Type} [DecidableEq α] {k : ℕ} {s : Finset α} {p : α} (hs : s.card ≤ k) (hp : p ∈ s) :
ValidStep k s p s

A cache hit keeps s unchanged as a valid transition.

theorem Cslib.DataStructure.Paging.validStep_hit_eq {α : Type} [DecidableEq α] {k : ℕ} {s s' : Finset α} {p : α} (hv : ValidStep k s p s') (hp : p ∈ s) :
s' = s

Every valid transition on a resident page p ∈ s leaves the cache unchanged.

theorem Cslib.DataStructure.Paging.validStep_miss_subset {α : Type} [DecidableEq α] {k : ℕ} {s s' : Finset α} {p : α} (hv : ValidStep k s p s') (hp : p ∉ s) :
s' ⊆ insert p s

Every valid transition on a missing page p ∉ s satisfies s' ⊆ insert p s.

theorem Cslib.DataStructure.Paging.validStep_insert {α : Type} [DecidableEq α] {k : ℕ} {s : Finset α} {p : α} (hs : s.card < k) (hp : p ∉ s) :
ValidStep k s p (insert p s)

Loading a missing page into a non-full cache (s.card < k) without eviction is valid.

theorem Cslib.DataStructure.Paging.card_insert_erase_of_notMem {α : Type} [DecidableEq α] {s : Finset α} {p e : α} (hp : p ∉ s) (he : e ∈ s) :
(insert p (s.erase e)).card = s.card

Evicting a resident page e ∈ s to load a missing page p ∉ s preserves cardinality.

theorem Cslib.DataStructure.Paging.validStep_replace {α : Type} [DecidableEq α] {k : ℕ} {s : Finset α} {p e : α} (hs : s.card ≤ k) (hp : p ∉ s) (he : e ∈ s) :
ValidStep k s p (insert p (s.erase e))

Evicting a resident page e ∈ s to load a missing page p ∉ s is a valid paging step.

theorem Cslib.DataStructure.Paging.scheduleCost_le_length {α : Type} [DecidableEq α] (k : ℕ) (s : Finset α) (reqs : List α) (states : List (Finset α)) :
(problem α k).scheduleCost s reqs states ≤ reqs.length

Total faults along any schedule are at most the number of requests.

theorem Cslib.DataStructure.Paging.validSchedule_replicate_of_forall_mem {α : Type} [DecidableEq α] {k : ℕ} {s : Finset α} {reqs : List α} (hs : s.card ≤ k) (hmem : ∀ p ∈ reqs, p ∈ s) :

Serving a request sequence whose pages are all already in s keeps s unchanged.

theorem Cslib.DataStructure.Paging.scheduleCost_replicate_of_forall_mem {α : Type} [DecidableEq α] {k : ℕ} {s : Finset α} {reqs : List α} (hmem : ∀ p ∈ reqs, p ∈ s) :
(problem α k).scheduleCost s reqs (List.replicate reqs.length s) = 0

Serving a request sequence whose pages are all already in s incurs zero faults.

@[simp]

Repeating s along any list ends in s.

theorem Cslib.DataStructure.Paging.validCache_finalState {α : Type} [DecidableEq α] {k : ℕ} {s₀ : Finset α} {reqs : List α} {states : List (Finset α)} (hs₀ : ValidCache k s₀) (hv : (problem α k).ValidSchedule s₀ reqs states) :
ValidCache k ((problem α k).finalState s₀ states)

Every valid demand-paging schedule starting from a valid cache ends in a valid cache.