Documentation

LeanPool.OrderMaintenance.Proof.Word.Insert

Theorem W, stage B1: a core insertion keeps the stored-value bound #

insertAfter_wb: from the cost invariant of a core (CostInv, as in insertAfter_cost), the stored-value bound WB K, room for labels and numeric room for the sizes, an insertion ends in a core with WB K. The proof follows insertAfter_cost and background_ok step by step and runs the cost proof's phase lemmas with the hooks of Hooks.lean added.

The top structure's two operations (insertAround, jobStep) enter through the contract TopWB, which stage B2 proves (the Tag, weight and node sites of docs/WORD.md §2).

structure OrderMaintenance.Proof.Word.TopWB (K : ℕ) (TI : Model.Core → Prop) (μ : Model.Core → ℕ) :

The top structure keeps the stored-value bound (the contract stage B2 proves, topWB in TopWB.lean): the insertion of a split's two new chunks into the tree, and each step of the running job. The top invariant of the state after the operation is a hypothesis (it bounds the tags the operation writes); a job step also needs room for two fresh nodes and the chunk count below 2^K (for the weights), and does not grow nodes.size + μ (so the node count stays within a budget, as in NodeB).

Instances For

    What an insertion leaves of the top structure #

    Close ∀ s, TopSame s (f s) for an update of the queue's fields.

    Equations
    Instances For

      The split start #

      The run of a split start, decomposed.

      theorem OrderMaintenance.Proof.LowInv.Csize {t : Model.Core} {L : List ℕ} (hL : LowInv t L) :
      t.C.size ≤ 2 + 2 * t.count

      The chunk count of a state of the low invariant is at most 2 + 2·count (CountInv).

      theorem OrderMaintenance.Proof.Word.reservation_wb {K : ℕ} {TI : Model.Core → Prop} {μ : Model.Core → ℕ} {J k n R NB0 : ℕ} {cap : Model.Params → ℕ} {L : List ℕ} {s : Model.Core} (hTC : TopContract TI μ J cap) (hT : TopWB K TI μ) (h0 : ResInv TI k J n R μ L s 0 s) (hn : 1 ≤ n) (hsize : 2 + 2 * (s.count / (s.P.theta + 1 - cmax s.P)) ≤ n + 1) (hcap : 2 + 2 * (s.count / (s.P.theta + 1 - cmax s.P)) ≤ cap s.P) (hI5 : ↑s.P.theta + ↑R * (Zeroing.Hn (n - 1) + 1) ≤ ↑s.P.T) (hW : WB K s) (hcnt : 2 * s.count + 2 ≤ 2 ^ K) (hNB : s.nodes.size + μ s ≤ NB0 + J * s.C.size) (hNK : NB0 + J * (2 + 2 * s.count) + 2 ≤ 2 ^ K) :

      The reservation keeps the stored-value bound, given the top structure's contract, room for the chunks (2·count + 2 ≤ 2^K; the chunk count is at most 2 + 2·count, CountInv), and a node budget: nodes.size + μ ≤ NB0 + J·C.size (a split start adds 2 chunks and a job of measure at most J; a job step does not grow nodes.size + μ), with NB0 + J·(2 + 2·count) + 2 ≤ 2^K.

      The chunk phase #

      theorem OrderMaintenance.Proof.Word.driveChunk_wb {K : ℕ} {t : Model.Core} {A : Abs} {L : List ℕ} {gh : GGh} {s₀ δu : ℕ → ℕ} {c : ℕ} (hI : INV t A) (hel : A.elist = L) (hG : GInv t L gh fun (x : ℕ) => 0) (hC : CInv t L (δ1 c) δu s₀) (hLX : LX s₀ (δ1 c) δu t) (hGP : GParams t.P) (hCP : CParams t.P) (hcL : LiveC t c) (hcnd : cSt t c ≠ Model.St.dead) (hcsz : 1 ≤ cSz t c) (hW : WB K t) (hL : LabRoom K t.P) (hlen : 4 * L.length + 1 ≤ 2 ^ K) :

      The chunk phase keeps the stored-value bound (the context of driveChunk_ok).

      The background work #

      theorem OrderMaintenance.Proof.Word.background_wb {K : ℕ} {TI : Model.Core → Prop} {μ : Model.Core → ℕ} {J k n R NB0 : ℕ} {cap : Model.Params → ℕ} {L : List ℕ} {s0 s1 s2 : Model.Core} {y g c : ℕ} (hTC : TopContract TI μ J cap) (hT : TopWB K TI μ) (hPost : InsPost TI k J n R μ L s0 g c s2) (hy : y ∈ L) (heg1 : eG s1 y = g) (hgc1 : gC s1 g = c) (hchunk : EStateM.run (Model.chunkSize c true) s1 = EStateM.Result.ok () s2) (hE12 : s2.E = s1.E) (hP1 : s1.P = s0.P) (hkP : s0.P.reservationBudget = k) (hn : 1 ≤ n) (hsize : 2 + 2 * (s2.count / (s0.P.theta + 1 - cmax s0.P)) ≤ n + 1) (hcap : 2 + 2 * (s2.count / (s0.P.theta + 1 - cmax s0.P)) ≤ cap s0.P) (hI5 : ↑s0.P.theta + ↑R * (Zeroing.Hn (n - 1) + 1) ≤ ↑s0.P.T) (hW2 : WB K s2) (hL : LabRoom K s0.P) (hlen : 4 * L.length + 4 ≤ 2 ^ K) (hG2 : s2.Gs.size + 2 ≤ 2 ^ K) (hcnt : 2 * s2.count + 2 ≤ 2 ^ K) (hNB : s2.nodes.size + μ s2 ≤ NB0 + J * s2.C.size) (hNK : NB0 + J * (2 + 2 * s2.count) + 2 ≤ 2 ^ K) :

      The background work of an insertion keeps the stored-value bound (the context of background_ok).

      A core insertion #

      theorem OrderMaintenance.Proof.INV.len_lt {s : Model.Core} {A : Abs} (hI : INV s A) :

      The element list has at most E.size - 1 entries (indices 1 … E.size - 1).

      theorem OrderMaintenance.Proof.Word.insertAfter_wb {K : ℕ} {TI : Model.Core → Prop} {μ : Model.Core → ℕ} {J n R NB0 : ℕ} {cap : Model.Params → ℕ} {L : List ℕ} {s : Model.Core} {x : ℕ} (hTC : TopContract TI μ J cap) (hT : TopWB K TI μ) (hC : CostInv TI μ J n R L s) (hx : x ∈ L) (hk : 1 ≤ s.P.reservationBudget) (hR : J / s.P.reservationBudget + 1 ≤ R) (hn : 1 ≤ n) (hsize : 2 + 2 * ((s.count + 1) / (s.P.theta + 1 - cmax s.P)) ≤ n + 1) (hcap : 2 + 2 * ((s.count + 1) / (s.P.theta + 1 - cmax s.P)) ≤ cap s.P) (hI5 : ↑s.P.theta + ↑R * (Zeroing.Hn (n - 1) + 1) ≤ ↑s.P.T) (hh : ℕ) (hW : WB K s) (hL : LabRoom K s.P) (hE : 4 * s.E.size + 8 ≤ 2 ^ K) (hG : s.Gs.size + 2 ≤ 2 ^ K) (hcnt : 2 * s.count + 4 ≤ 2 ^ K) (hNB : s.nodes.size + μ s ≤ NB0 + J * s.C.size) (hNK : NB0 + J * (2 + 2 * (s.count + 1)) + 2 ≤ 2 ^ K) :

      A core insertion keeps the stored-value bound (the context of insertAfter_cost), given the top structure's contract TopWB, room for labels, and room for the sizes and record counts: 4·E.size + 8, Gs.size + 2 and 2·count + 4 at most 2^K.

      theorem OrderMaintenance.Proof.Word.markDead_wb {K : ℕ} {s : Model.Core} (hW : WB K s) (x : ℕ) {s' : Model.Core} (h : EStateM.run (Model.markDead x) s = EStateM.Result.ok () s') :
      WB K s'

      A deletion keeps the stored-value bound.

      An order query changes nothing.