Documentation

LeanPool.OrderMaintenance.Proof.Cost.WrapSafe

The wrapper: what the machine code needs along Level F's run #

The machine code of an operation calls core procedures; each call needs the core's cost invariant and some facts about its arguments. Level F's cost proof establishes them along the run, at intermediate states it does not expose. This file replays the proof of the rebuild loop (rebuildLoop_cost) and records them (RLSafeF).

def OrderMaintenance.Proof.RLSafeF (mk : ℕ → Model.Params) (TI : Model.Core → Prop) (μ : Model.Core → ℕ) (Jf nf Rf : Model.Params → ℕ) (om : Model.OrderMaintenance) (n : Model.Core) :
ℕ → ℕ → Prop

What the iterations of the rebuild loop need, along Level F's run: a preparation step needs a core of positive capacity and keeps its count; a copy step reads an element of cur, and if the element is live, nxt is in service with room, the anchor tail is in its list, and the handle is below the counter.

Equations
Instances For
    theorem OrderMaintenance.Proof.elist_lt {c : Model.Core} {A : Abs} (hR : CoreR c A) {e : ℕ} (he : e ∈ A.elist) :
    e < c.E.size
    theorem OrderMaintenance.Proof.rebuildLoop_safe {mk : ℕ → Model.Params} {TI PI : Model.Core → Prop} {μ ν : Model.Core → ℕ} {PP : Model.Params → Prop} {Jf capf nf Rf : Model.Params → ℕ} (S : CostSetup mk TI PI μ ν PP Jf capf nf Rf) {Sp : Spec.State} (hS : Spec.Inv Sp) {Φe live₀ I D N' : ℕ} (fuel budget : ℕ) (om : Model.OrderMaintenance) (n : Model.Core) (A : Abs) :
    CoreR om.cur A → liveH om.cur A.elist = Sp.list → IdxOK om.cur A om.curIdx Sp.list → NxtR' om.cur A om n → om.nextHandle = Sp.fresh → om.live = Sp.list.length → LoopC mk TI PI μ ν Jf nf Rf om n A budget Φe live₀ I D N' → RLSafeF mk TI μ Jf nf Rf om n fuel budget

    The rebuild loop is safe: under rebuildLoop_cost's hypotheses, its iterations get what they need.

    theorem OrderMaintenance.Proof.rebuildStep_safe {mk : ℕ → Model.Params} {TI PI : Model.Core → Prop} {μ ν : Model.Core → ℕ} {PP : Model.Params → Prop} {Jf capf nf Rf : Model.Params → ℕ} (S : CostSetup mk TI PI μ ν PP Jf capf nf Rf) {om : Model.OrderMaintenance} {Sp : Spec.State} (hW : WInv om Sp) (hlv : om.live = Sp.list.length) (hcur : ∀ (A : Abs), INV om.cur A → CoreOK mk TI μ Jf nf Rf om.cur A.elist) (hbusy : ∀ (n : Model.Core), om.nxt = some n → ∃ (c₀ : ℕ) (live₀ : ℕ) (I : ℕ) (D : ℕ), MidW mk TI PI μ ν Jf nf Rf om n c₀ live₀ I D) (n0 : Model.Core) :
    om.nxt = some n0 → RLSafeF mk TI μ Jf nf Rf { cur := om.cur, curIdx := om.curIdx, nxtIdx := om.nxtIdx, cursor := om.cursor, cursorSet := om.cursorSet, live := om.live, nextHandle := om.nextHandle, rebuilds := om.rebuilds, KB := om.KB } n0 (om.KB + 1) om.KB

    The rebuild step's loop is safe, under rebuildStep_cost's hypotheses.

    The anchor of an insertion in cur.

    Equations
    Instances For
      theorem OrderMaintenance.Proof.insert_safe {mk : ℕ → Model.Params} {TI PI : Model.Core → Prop} {μ ν : Model.Core → ℕ} {PP : Model.Params → Prop} {Jf capf nf Rf : Model.Params → ℕ} (S : CostSetup mk TI PI μ ν PP Jf capf nf Rf) {om : Model.OrderMaintenance} {Sp : Spec.State} (hW : WC mk TI PI μ ν Jf nf Rf om Sp) (hx : Option ℕ) (hv : Spec.Op.Valid Sp (insOp hx)) :
      ∃ (c' : Model.Core) (om2 : Model.OrderMaintenance), EStateM.run (Model.insertAfter (insXi om hx) om.nextHandle) om.cur = EStateM.Result.ok om.cur.E.size c' ∧ { cur := c', curIdx := om.curIdx.setX om.nextHandle om.cur.E.size, nxt := om.nxt, nxtIdx := om.nxtIdx, cursor := om.cursor, cursorSet := om.cursorSet, live := om.live, nextHandle := om.nextHandle + 1, rebuilds := om.rebuilds, KB := om.KB }.mirrorInsert hx om.nextHandle = Except.ok om2 ∧ ∀ (n : Model.Core), om2.nxt = some n → RLSafeF mk TI μ Jf nf Rf { cur := om2.cur, curIdx := om2.curIdx, nxtIdx := om2.nxtIdx, cursor := om2.cursor, cursorSet := om2.cursorSet, live := om2.live + 1, nextHandle := om2.nextHandle, rebuilds := om2.rebuilds, KB := om2.KB } n (om2.KB + 1) om2.KB

      An insertion's rebuild step is safe: after the insertion into cur and its mirroring, the rebuild loop gets what it needs.

      theorem OrderMaintenance.Proof.delete_safe {mk : ℕ → Model.Params} {TI PI : Model.Core → Prop} {μ ν : Model.Core → ℕ} {PP : Model.Params → Prop} {Jf capf nf Rf : Model.Params → ℕ} (S : CostSetup mk TI PI μ ν PP Jf capf nf Rf) {om : Model.OrderMaintenance} {Sp : Spec.State} (hW : WC mk TI PI μ ν Jf nf Rf om Sp) {x : ℕ} (hv : x ∈ Sp.list) :
      ∃ (c' : Model.Core) (om2 : Model.OrderMaintenance), EStateM.run (Model.markDead (om.curIdx.getX x)) om.cur = EStateM.Result.ok () c' ∧ { cur := c', curIdx := om.curIdx.setX x 0, nxt := om.nxt, nxtIdx := om.nxtIdx, cursor := om.cursor, cursorSet := om.cursorSet, live := om.live, nextHandle := om.nextHandle, rebuilds := om.rebuilds, KB := om.KB }.mirrorDelete x = Except.ok om2 ∧ ∀ (n : Model.Core), om2.nxt = some n → RLSafeF mk TI μ Jf nf Rf { cur := om2.cur, curIdx := om2.curIdx, nxtIdx := om2.nxtIdx, cursor := om2.cursor, cursorSet := om2.cursorSet, live := om2.live - 1, nextHandle := om2.nextHandle, rebuilds := om2.rebuilds, KB := om2.KB } n (om2.KB + 1) om2.KB

      A deletion's rebuild step is safe.