Documentation

CslibFrontier.DataStructure.CellProbe.StateTransition

Deterministic Cell-Probe State-Transition Implementations #

This file connects deterministic adaptive cell-probe schemes (Cslib.CellProbe.Scheme, [Mil99], §1.2) to the general relational data-structure specification hierarchy (Cslib.DataStructure.StateTransitionSpec, [CLRS09], Section 17.3).

A Cslib.DataStructure.CellProbe.StateTransitionImpl D P s₀ certifies that a time-invariant cell-probe scheme P : Cslib.CellProbe.Scheme D.Op D.Result cells w implements D starting from abstract initial state s₀ in cells cells of w-bit words (cells * w bits total, with no persistent registers across operations), with nonnegative integer potential potential and amortized per-operation probe charge charge.

From a single StateTransitionImpl, this file derives:

Main definitions #

Main results #

References #

Native single-operation execution evidence #

Native execution evidence of a single deterministic cell-probe operation: the number of probes incurred and the finite set of distinct cells accessed.

  • probes : ℕ

    Number of cell reads and writes executed during the operation.

  • probedCells : Finset (Fin cells)

    Set of distinct cell indices accessed during the operation.

def Cslib.DataStructure.CellProbe.ExecOp {Op : Type v} {Result : Op → Type} {cells w : ℕ} (P : CellProbe.Scheme Op Result cells w) :
Execution { A := Op, B := Result } (CellProbe.Mem cells w) (OperationTrace cells)

Native Cslib.DataStructure.Execution semantics of a deterministic cell-probe Scheme.

theorem Cslib.DataStructure.CellProbe.execOp_run {Op : Type v} {Result : Op → Type} {cells w : ℕ} (P : CellProbe.Scheme Op Result cells w) (m : CellProbe.Mem cells w) (o : Op) :
ExecOp P m o ((P.step o).run m).1 ((P.step o).run m).2 { probes := (P.step o).probes m, probedCells := (P.step o).probedCells m }

Every memory m and operation o admits a canonical ExecOp step of P.

theorem Cslib.DataStructure.CellProbe.ExecOp.eq_of_execOp {Op : Type v} {Result : Op → Type} {cells w : ℕ} {P : CellProbe.Scheme Op Result cells w} {m m' : CellProbe.Mem cells w} {o : Op} {a : Result o} {tr : OperationTrace cells} (he : ExecOp P m o a m' tr) :
a = ((P.step o).run m).1 ∧ m' = ((P.step o).run m).2 ∧ tr = { probes := (P.step o).probes m, probedCells := (P.step o).probedCells m }

ExecOp P is deterministic: its answer, post-memory, and trace are uniquely determined by (P.step o) and m.

theorem Cslib.DataStructure.CellProbe.ExecOp.card_probedCells_le_probes {Op : Type v} {Result : Op → Type} {cells w : ℕ} {P : CellProbe.Scheme Op Result cells w} {m m' : CellProbe.Mem cells w} {o : Op} {a : Result o} {tr : OperationTrace cells} (he : ExecOp P m o a m' tr) :

On any ExecOp P step, the number of distinct probed cells is at most tr.probes.

Deterministic cell-probe StateTransitionImpl #

structure Cslib.DataStructure.CellProbe.StateTransitionImpl {cells w : ℕ} (D : StateTransitionSpec) (P : CellProbe.Scheme D.Op D.Result cells w) (s₀ : D.State) :
Type (max u v)

Certified deterministic cell-probe implementation of D : StateTransitionSpec from initial state s₀ using cells cells of w-bit words (cells * w bits total) with nonnegative potential potential and per-operation amortized probe charge charge.

@[reducible, inline]
abbrev Cslib.DataStructure.CellProbe.StateTransitionImpl.ofFn {cells w : ℕ} {D : StateTransitionSpec} {P : CellProbe.Scheme D.Op D.Result cells w} {s₀ : D.State} {f : D.State → (o : D.Op) → D.State × D.Result o} [D.HasStepFn f] (rep : D.State → CellProbe.Mem cells w → Prop) (charge : D.State → D.Op → ℕ) (init_rep : rep s₀ P.init) (potential : CellProbe.Mem cells w → ℕ := fun (x : CellProbe.Mem cells w) => 0) (initPotential : ℕ := 0) (init_potential : potential P.init ≤ initPotential := by simp) (step_exec : ∀ (s : D.State) (m : CellProbe.Mem cells w) (o : D.Op), rep s m → D.valid s o → ((P.step o).run m).1 = (D.stepFn s o).2 ∧ rep (D.stepFn s o).1 ((P.step o).run m).2 ∧ (P.step o).probes m + potential ((P.step o).run m).2 ≤ charge s o + potential m) :

Construct a deterministic cell-probe StateTransitionImpl on a functional specification (D.HasStepFn f) from a functional step-correctness and amortized probe proof.

@[simp]
theorem Cslib.DataStructure.CellProbe.StateTransitionImpl.ofFn_rep {cells w : ℕ} {D : StateTransitionSpec} {P : CellProbe.Scheme D.Op D.Result cells w} {s₀ : D.State} {f : D.State → (o : D.Op) → D.State × D.Result o} [D.HasStepFn f] (rep : D.State → CellProbe.Mem cells w → Prop) (charge : D.State → D.Op → ℕ) (init_rep : rep s₀ P.init) (potential : CellProbe.Mem cells w → ℕ) (initPotential : ℕ) (init_potential : potential P.init ≤ initPotential) (step_exec : ∀ (s : D.State) (m : CellProbe.Mem cells w) (o : D.Op), rep s m → D.valid s o → ((P.step o).run m).1 = (D.stepFn s o).2 ∧ rep (D.stepFn s o).1 ((P.step o).run m).2 ∧ (P.step o).probes m + potential ((P.step o).run m).2 ≤ charge s o + potential m) :
(ofFn rep charge init_rep potential initPotential init_potential step_exec).rep = rep
@[simp]
theorem Cslib.DataStructure.CellProbe.StateTransitionImpl.ofFn_potential {cells w : ℕ} {D : StateTransitionSpec} {P : CellProbe.Scheme D.Op D.Result cells w} {s₀ : D.State} {f : D.State → (o : D.Op) → D.State × D.Result o} [D.HasStepFn f] (rep : D.State → CellProbe.Mem cells w → Prop) (charge : D.State → D.Op → ℕ) (init_rep : rep s₀ P.init) (potential : CellProbe.Mem cells w → ℕ) (initPotential : ℕ) (init_potential : potential P.init ≤ initPotential) (step_exec : ∀ (s : D.State) (m : CellProbe.Mem cells w) (o : D.Op), rep s m → D.valid s o → ((P.step o).run m).1 = (D.stepFn s o).2 ∧ rep (D.stepFn s o).1 ((P.step o).run m).2 ∧ (P.step o).probes m + potential ((P.step o).run m).2 ≤ charge s o + potential m) :
(ofFn rep charge init_rep potential initPotential init_potential step_exec).potential = potential
@[simp]
theorem Cslib.DataStructure.CellProbe.StateTransitionImpl.ofFn_initPotential {cells w : ℕ} {D : StateTransitionSpec} {P : CellProbe.Scheme D.Op D.Result cells w} {s₀ : D.State} {f : D.State → (o : D.Op) → D.State × D.Result o} [D.HasStepFn f] (rep : D.State → CellProbe.Mem cells w → Prop) (charge : D.State → D.Op → ℕ) (init_rep : rep s₀ P.init) (potential : CellProbe.Mem cells w → ℕ) (initPotential : ℕ) (init_potential : potential P.init ≤ initPotential) (step_exec : ∀ (s : D.State) (m : CellProbe.Mem cells w) (o : D.Op), rep s m → D.valid s o → ((P.step o).run m).1 = (D.stepFn s o).2 ∧ rep (D.stepFn s o).1 ((P.step o).run m).2 ∧ (P.step o).probes m + potential ((P.step o).run m).2 ≤ charge s o + potential m) :
(ofFn rep charge init_rep potential initPotential init_potential step_exec).initPotential = initPotential
@[simp]
theorem Cslib.DataStructure.CellProbe.StateTransitionImpl.ofFn_charge {cells w : ℕ} {D : StateTransitionSpec} {P : CellProbe.Scheme D.Op D.Result cells w} {s₀ : D.State} {f : D.State → (o : D.Op) → D.State × D.Result o} [D.HasStepFn f] (rep : D.State → CellProbe.Mem cells w → Prop) (charge : D.State → D.Op → ℕ) (init_rep : rep s₀ P.init) (potential : CellProbe.Mem cells w → ℕ) (initPotential : ℕ) (init_potential : potential P.init ≤ initPotential) (step_exec : ∀ (s : D.State) (m : CellProbe.Mem cells w) (o : D.Op), rep s m → D.valid s o → ((P.step o).run m).1 = (D.stepFn s o).2 ∧ rep (D.stepFn s o).1 ((P.step o).run m).2 ∧ (P.step o).probes m + potential ((P.step o).run m).2 ≤ charge s o + potential m) :
(ofFn rep charge init_rep potential initPotential init_potential step_exec).charge = charge
theorem Cslib.DataStructure.CellProbe.StateTransitionImpl.toBound {cells w : ℕ} {D : StateTransitionSpec} {P : CellProbe.Scheme D.Op D.Result cells w} {s₀ : D.State} (C : StateTransitionImpl D P s₀) (hpot : ∀ (m : CellProbe.Mem cells w), C.potential m = 0 := by intro _; first | rfl | simp) :

When C.potential is identically zero, StateTransitionImpl projects directly to a worst-case per-operation Cslib.DataStructure.Bound certificate.

Adaptive-client and multi-operation sequence theorems #

theorem Cslib.DataStructure.CellProbe.StateTransitionImpl.run_client_demonic_amortized {cells w : ℕ} {D : StateTransitionSpec} {P : CellProbe.Scheme D.Op D.Result cells w} {s₀ : D.State} (C : StateTransitionImpl D P s₀) {α : Type u_1} (p : D.Client α) (hv : D.DemonicValid s₀ p) :
∃ (a : α) (m' : CellProbe.Mem cells w) (traces : List (OperationTrace cells)) (s' : D.State) (tr : D.Transcript), Executes (ExecOp P) p P.init a m' traces ∧ D.ClientRun s₀ p a s' tr ∧ C.rep s' m' ∧ traces.length = List.length tr ∧ total OperationTrace.probes traces + C.potential m' ≤ C.initPotential + D.totalCostTranscript C.charge s₀ tr

Adaptive-client amortized probe bound from P.init along any demonically admissible client p : D.Client α.

theorem Cslib.DataStructure.CellProbe.StateTransitionImpl.run_client_amortized {cells w : ℕ} {D : StateTransitionSpec} {P : CellProbe.Scheme D.Op D.Result cells w} {s₀ : D.State} (C : StateTransitionImpl D P s₀) {f : D.State → (o : D.Op) → D.State × D.Result o} [D.HasStepFn f] {α : Type u_1} (p : D.Client α) (hv : D.ValidHistory s₀ (D.clientHistory s₀ p)) :
∃ (m' : CellProbe.Mem cells w) (traces : List (OperationTrace cells)), Executes (ExecOp P) p P.init (D.clientResult s₀ p) m' traces ∧ C.rep (D.clientState s₀ p) m' ∧ total OperationTrace.probes traces + C.potential m' ≤ C.initPotential + D.totalCost C.charge s₀ (D.clientHistory s₀ p)

Adaptive-client amortized probe bound from P.init on a deterministic specification (D.HasStepFn f).

theorem Cslib.DataStructure.CellProbe.StateTransitionImpl.run_client_bound {cells w : ℕ} {D : StateTransitionSpec} {P : CellProbe.Scheme D.Op D.Result cells w} {s₀ : D.State} (C : StateTransitionImpl D P s₀) {f : D.State → (o : D.Op) → D.State × D.Result o} [D.HasStepFn f] {α : Type u_1} (p : D.Client α) (hv : D.ValidHistory s₀ (D.clientHistory s₀ p)) (hpot : ∀ (m : CellProbe.Mem cells w), C.potential m = 0 := by intro _; first | rfl | simp) :
∃ (m' : CellProbe.Mem cells w) (traces : List (OperationTrace cells)), Executes (ExecOp P) p P.init (D.clientResult s₀ p) m' traces ∧ C.rep (D.clientState s₀ p) m' ∧ total OperationTrace.probes traces ≤ D.totalCost C.charge s₀ (D.clientHistory s₀ p)

Adaptive-client worst-case probe bound from P.init on a deterministic specification when C.potential is identically zero.

theorem Cslib.DataStructure.CellProbe.StateTransitionImpl.runFrom_amortized {cells w : ℕ} {D : StateTransitionSpec} {P : CellProbe.Scheme D.Op D.Result cells w} {s₀ : D.State} (C : StateTransitionImpl D P s₀) {s : D.State} {m : CellProbe.Mem cells w} (ops : List D.Op) (hr : C.rep s m) (hv : D.ValidOpSeq s ops) :
∃ (tr : D.Transcript) (s' : D.State), tr.ops = ops ∧ tr.labels = (P.runFrom m ops).1 ∧ D.ValidTranscript s tr s' ∧ C.rep s' (P.runFrom m ops).2 ∧ P.probesFrom m ops + C.potential (P.runFrom m ops).2 ≤ D.totalCostTranscript C.charge s tr + C.potential m

Multi-operation execution of P.runFrom m ops from any represented memory m: every demonically admissible sequence ops witnesses a valid relational transcript tr whose labels equal (P.runFrom m ops).1 and whose total charge bounds P.probesFrom m ops up to potential.

theorem Cslib.DataStructure.CellProbe.StateTransitionImpl.runSeq_amortized {cells w : ℕ} {D : StateTransitionSpec} {P : CellProbe.Scheme D.Op D.Result cells w} {s₀ : D.State} (C : StateTransitionImpl D P s₀) (ops : List D.Op) (hv : D.ValidOpSeq s₀ ops) :
∃ (tr : D.Transcript) (s' : D.State), tr.ops = ops ∧ tr.labels = (P.runSeq ops).1 ∧ D.ValidTranscript s₀ tr s' ∧ C.rep s' (P.runSeq ops).2 ∧ P.seqProbes ops + C.potential (P.runSeq ops).2 ≤ C.initPotential + D.totalCostTranscript C.charge s₀ tr

Multi-operation execution of P.runSeq ops from P.init: every demonically admissible sequence D.ValidOpSeq s₀ ops produces a valid relational transcript tr matching (P.runSeq ops).1 with P.seqProbes ops + C.potential (P.runSeq ops).2 ≤ C.initPotential + D.totalCostTranscript C.charge s₀ tr.

theorem Cslib.DataStructure.CellProbe.StateTransitionImpl.runSeq_ofFn {cells w : ℕ} {D : StateTransitionSpec} {P : CellProbe.Scheme D.Op D.Result cells w} {s₀ : D.State} (C : StateTransitionImpl D P s₀) {f : D.State → (o : D.Op) → D.State × D.Result o} [D.HasStepFn f] (ops : List D.Op) (hv : D.ValidHistory s₀ ops) :
(P.runSeq ops).1 = (D.run s₀ ops).2 ∧ C.rep (D.run s₀ ops).1 (P.runSeq ops).2 ∧ P.seqProbes ops + C.potential (P.runSeq ops).2 ≤ C.initPotential + D.totalCost C.charge s₀ ops

On a deterministic specification (D.HasStepFn f), P.runSeq ops on any admissible history D.ValidHistory s₀ ops produces the exact canonical transcript (D.run s₀ ops).2, reaches a memory representing (D.run s₀ ops).1, and satisfies P.seqProbes ops + C.potential (P.runSeq ops).2 ≤ C.initPotential + D.totalCost C.charge s₀ ops.

theorem Cslib.DataStructure.CellProbe.StateTransitionImpl.seqProbes_le_ofFn {cells w : ℕ} {D : StateTransitionSpec} {P : CellProbe.Scheme D.Op D.Result cells w} {s₀ : D.State} (C : StateTransitionImpl D P s₀) {f : D.State → (o : D.Op) → D.State × D.Result o} [D.HasStepFn f] (ops : List D.Op) (hv : D.ValidHistory s₀ ops) :

Total cell probes P.seqProbes ops across any admissible history D.ValidHistory s₀ ops on a deterministic specification is at most C.initPotential + D.totalCost C.charge s₀ ops.

Cell padding (cells ≤ cells') #

Lift a deterministic cell-probe StateTransitionImpl from cells cells to cells' cells (cells ≤ cells') via Cslib.CellProbe.Scheme.padCells, preserving initPotential and charge.

@[simp]
@[simp]
theorem Cslib.DataStructure.CellProbe.StateTransitionImpl.padCells_charge {cells cells' w : ℕ} {D : StateTransitionSpec} {P : CellProbe.Scheme D.Op D.Result cells w} {s₀ : D.State} (h : cells ≤ cells') (C : StateTransitionImpl D P s₀) :
@[simp]
theorem Cslib.DataStructure.CellProbe.StateTransitionImpl.padCells_rep {cells cells' w : ℕ} {D : StateTransitionSpec} {P : CellProbe.Scheme D.Op D.Result cells w} {s₀ : D.State} (h : cells ≤ cells') (C : StateTransitionImpl D P s₀) (s : D.State) (m' : CellProbe.Mem cells' w) :
(padCells h C).rep s m' ↔ ∃ (m : CellProbe.Mem cells w), m' = CellProbe.padMem h m ∧ C.rep s m
@[simp]
theorem Cslib.DataStructure.CellProbe.StateTransitionImpl.padCells_potential {cells cells' w : ℕ} {D : StateTransitionSpec} {P : CellProbe.Scheme D.Op D.Result cells w} {s₀ : D.State} (h : cells ≤ cells') (C : StateTransitionImpl D P s₀) (m' : CellProbe.Mem cells' w) :
(padCells h C).potential m' = C.potential fun (i : Fin cells) => m' (Fin.castLE h i)