Documentation

LeanPool.OrderMaintenance.Impl.OpsM

M6: the wrapper's operations as machine code #

The Level M side conditions of the cores (Mc, PrepM) are not part of Level F's invariant; they are carried alongside it (MX). Level F's run supplies the rest of what the core calls need (RLSafeF, insert_safe, delete_safe).

@[reducible, inline]

Level F's safety facts at the proof parameters.

Equations
  • One or more equations did not get rendered due to their size.
Instances For

    The Level M side condition of nxt: in preparation, or in service with the capacities.

    Equations
    Instances For

      The Level M side conditions of the wrapper state.

      Equations
      • One or more equations did not get rendered due to their size.
      Instances For
        theorem OrderMaintenance.Impl.copy_M {om : Model.OrderMaintenance} {n : Model.Core} (hC : CopyOK om n) (hM : Mc (capsOf n.P) n.P n) {om' : Model.OrderMaintenance} {n' : Model.Core} (hcp : Model.copyAtCursor om n = Except.ok (om', n')) :
        om'.cursorSet = om.cursorSet ∧ om'.cur = om.cur ∧ Mc (capsOf n'.P) n'.P n'

        A copy step keeps the capacities of nxt.

        theorem OrderMaintenance.Impl.loop_M (f b : ℕ) (om : Model.OrderMaintenance) (n : Model.Core) :
        RLSafeP om n f b → NxtM om n → Mc (capsOf om.cur.P) om.cur.P om.cur → RLSafe om n f b ∧ ∀ (R : Model.OrderMaintenance), Model.rebuildLoop om n f b = Except.ok R → MX R

        Along the rebuild loop: Level F's safety facts and the side conditions give what the machine iterations need, and the side conditions hold at the end.

        The rebuild step #

        The rebuild's share of an operation: start a rebuild, or run the loop.

        Equations
        • One or more equations did not get rendered due to their size.
        Instances For

          The cost bound of the rebuild step.

          Equations
          Instances For

            The locals the rebuild step may change.

            Equations
            Instances For
              theorem OrderMaintenance.Impl.rebuild_MX {om : Model.OrderMaintenance} (hX : MX om) (hF : ∀ (n : Model.Core), om.nxt = some n → RLSafeP { 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 } n (om.KB + 1) om.KB) {R : Model.OrderMaintenance} (hr : Model.OrderMaintenance.rebuildStep Proof.proofParams om = Except.ok R) :
              MX R

              The rebuild step keeps the side conditions.

              theorem OrderMaintenance.Impl.rebuildW_ok {om : Model.OrderMaintenance} {m : Machine.State} {p : ℕ} (h : WEnc om m p) (hX : MX om) (hkb : 1 ≤ om.KB) (hF : ∀ (n : Model.Core), om.nxt = some n → RLSafeP { 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 } n (om.KB + 1) om.KB) {R : Model.OrderMaintenance} (hr : Model.OrderMaintenance.rebuildStep Proof.proofParams om = Except.ok R) :
              MX R ∧ Machine.wp (rebuildC p) (fun (m' : Machine.State) (k : ℕ) => (WEnc R m' p ∨ WEnc R m' (1 - p)) ∧ (∀ (x : Machine.Reg), RbLoc x → m'.loc x = m.loc x) ∧ k ≤ rebB om.KB) m

              The rebuild step: the machine ends holding Level F's result (in one slot or the other), which satisfies the side conditions.

              K_B never changes #

              The wrapper invariant at Level M #

              @[reducible, inline]

              Level F's cost invariant at the proof parameters.

              Equations
              • One or more equations did not get rendered due to their size.
              Instances For

                The wrapper invariant at Level M: Level F's, with the side conditions.

                Equations
                Instances For

                  cur is in service.

                  theorem OrderMaintenance.Impl.MInv.mirror {om : Model.OrderMaintenance} {Sp : Spec.State} (hI : MInv om Sp) (hx : Option ℕ) (n : Model.Core) :
                  om.nxt = some n → om.cursorSet = true → (hx = none ∨ ∃ (x : ℕ), hx = some x ∧ om.nxtIdx.getX x ≠ 0) → ∃ (B : List ℕ), InService n B ∧ mirAnchor om n hx ∈ B

                  What mirroring an insertion needs.

                  theorem OrderMaintenance.Impl.mirrorInsert_M {om : Model.OrderMaintenance} {hx : Option ℕ} {hy : ℕ} (hX : ∀ (n : Model.Core), om.nxt = some n → NxtM om n) (hN : ∀ (n : Model.Core), om.nxt = some n → om.cursorSet = true → (hx = none ∨ ∃ (x : ℕ), hx = some x ∧ om.nxtIdx.getX x ≠ 0) → ∃ (B : List ℕ), InService n B ∧ mirAnchor om n hx ∈ B) {om2 : Model.OrderMaintenance} (hm : om.mirrorInsert hx hy = Except.ok om2) :
                  om2.cur = om.cur ∧ om2.KB = om.KB ∧ ∀ (n : Model.Core), om2.nxt = some n → NxtM om2 n

                  Mirroring an insertion keeps the side conditions of nxt.

                  theorem OrderMaintenance.Impl.insert_eq {mk : ℕ → Model.Params} {om : Model.OrderMaintenance} {hx : Option ℕ} {c' : Model.Core} {om2 : Model.OrderMaintenance} (hr : EStateM.run (Model.insertAfter (Proof.insXi om hx) om.nextHandle) om.cur = EStateM.Result.ok om.cur.E.size c') (hm : { 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) (R : Model.OrderMaintenance) :
                  Model.OrderMaintenance.insert mk om hx = Except.ok (om.nextHandle, R) ↔ Model.OrderMaintenance.rebuildStep mk { cur := om2.cur, curIdx := om2.curIdx, nxt := om2.nxt, nxtIdx := om2.nxtIdx, cursor := om2.cursor, cursorSet := om2.cursorSet, live := om2.live + 1, nextHandle := om2.nextHandle, rebuilds := om2.rebuilds, KB := om2.KB } = Except.ok R

                  Level F's insertion, step by step: the insertion into cur, its mirroring, and the rebuild step.

                  Insertion #

                  Increment the wrapper's live-handle counter.

                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For
                    theorem OrderMaintenance.Impl.liveIncW_ok {om : Model.OrderMaintenance} {m : Machine.State} {p : ℕ} (h : WEnc om m p) :
                    Machine.wp liveIncC (fun (m' : Machine.State) (k : ℕ) => WEnc { cur := om.cur, curIdx := om.curIdx, nxt := om.nxt, nxtIdx := om.nxtIdx, cursor := om.cursor, cursorSet := om.cursorSet, live := om.live + 1, nextHandle := om.nextHandle, rebuilds := om.rebuilds, KB := om.KB } m' p ∧ m'.loc = m.loc ∧ k ≤ 10) m

                    The wrapper's insertion: the handle of the anchor in local x (if hx = 1).

                    Equations
                    Instances For

                      The cost bound of an insertion.

                      Equations
                      Instances For
                        theorem OrderMaintenance.Impl.wp_par_or {om : Model.OrderMaintenance} {m : Machine.State} {p : ℕ} (hp : p < 2) (h : WEnc om m p ∨ WEnc om m (1 - p)) :
                        WEnc om m 0 ∨ WEnc om m 1
                        theorem OrderMaintenance.Impl.MInv.insert_prefix {om : Model.OrderMaintenance} {Sp : Spec.State} (hI : MInv om Sp) {hx : Option ℕ} (hv : Spec.Op.Valid Sp (Proof.insOp hx)) :
                        ∃ (om' : Model.OrderMaintenance) (c' : Model.Core) (om2 : Model.OrderMaintenance), Model.OrderMaintenance.insert Proof.proofParams om hx = Except.ok (Sp.fresh, om') ∧ MInv om' (Spec.step Sp (Proof.insOp hx)).1 ∧ EStateM.run (Model.insertAfter (Proof.insXi om hx) om.nextHandle) om.cur = EStateM.Result.ok om.cur.E.size c' ∧ (insOM om c' om.cur.E.size).mirrorInsert hx om.nextHandle = Except.ok om2 ∧ (∀ (n : Model.Core), om2.nxt = some n → RLSafeP { 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) ∧ Model.OrderMaintenance.rebuildStep Proof.proofParams { cur := om2.cur, curIdx := om2.curIdx, nxt := om2.nxt, nxtIdx := om2.nxtIdx, cursor := om2.cursor, cursorSet := om2.cursorSet, live := om2.live + 1, nextHandle := om2.nextHandle, rebuilds := om2.rebuilds, KB := om2.KB } = Except.ok om' ∧ c'.P = om.cur.P ∧ c'.count = om.cur.count + 1 ∧ om2.cur = c' ∧ om2.KB = om.KB ∧ MX { cur := om2.cur, curIdx := om2.curIdx, nxt := om2.nxt, nxtIdx := om2.nxtIdx, cursor := om2.cursor, cursorSet := om2.cursorSet, live := om2.live + 1, nextHandle := om2.nextHandle, rebuilds := om2.rebuilds, KB := om2.KB }

                        The shared functional prefix of insertion: the core update, mirroring, and safe rebuild preserve parameters and the Level M invariant. Machine and word bounds reuse it.

                        theorem OrderMaintenance.Impl.insertW_ok {om : Model.OrderMaintenance} {m : Machine.State} {p : ℕ} {Sp : Spec.State} (h : WEnc om m p) (hI : MInv om Sp) {hx : Option ℕ} (hv : Spec.Op.Valid Sp (Proof.insOp hx)) (hhx : m.loc "hx" = b2n hx.isSome) (hxl : ∀ (x : ℕ), hx = some x → m.loc "x" = x) :
                        ∃ (om' : Model.OrderMaintenance), Model.OrderMaintenance.insert Proof.proofParams om hx = Except.ok (Sp.fresh, om') ∧ MInv om' (Spec.step Sp (Proof.insOp hx)).1 ∧ om'.KB = om.KB ∧ Machine.wp insertWS (fun (m' : Machine.State) (k : ℕ) => (WEnc om' m' 0 ∨ WEnc om' m' 1) ∧ m'.loc "hy" = Sp.fresh ∧ k ≤ insW om.KB) m

                        An insertion at Level M: it answers Level F's handle, keeps the invariant, and the machine code runs in at most insW K_B steps.

                        Deletion #

                        theorem OrderMaintenance.Impl.MInv.mirrorDel {om : Model.OrderMaintenance} {Sp : Spec.State} (hI : MInv om Sp) (x : ℕ) (n : Model.Core) :
                        om.nxt = some n → om.nxtIdx.getX x ≠ 0 → om.cursorSet = true ∧ DelOK n (om.nxtIdx.getX x)

                        What mirroring a deletion needs: an element copied into nxt is in service there.

                        theorem OrderMaintenance.Impl.mirrorDelete_M {om : Model.OrderMaintenance} {x : ℕ} (hX : ∀ (n : Model.Core), om.nxt = some n → NxtM om n) (hN : ∀ (n : Model.Core), om.nxt = some n → om.nxtIdx.getX x ≠ 0 → om.cursorSet = true ∧ DelOK n (om.nxtIdx.getX x)) {om2 : Model.OrderMaintenance} (hm : om.mirrorDelete x = Except.ok om2) :
                        om2.cur = om.cur ∧ om2.KB = om.KB ∧ om2.live = om.live ∧ ∀ (n : Model.Core), om2.nxt = some n → NxtM om2 n

                        Mirroring a deletion keeps the side conditions of nxt.

                        theorem OrderMaintenance.Impl.delete_eq {mk : ℕ → Model.Params} {om : Model.OrderMaintenance} {x : ℕ} {c' : Model.Core} {om2 : Model.OrderMaintenance} (hr : EStateM.run (Model.markDead (om.curIdx.getX x)) om.cur = EStateM.Result.ok () c') (hm : { 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) (R : Model.OrderMaintenance) :
                        Model.OrderMaintenance.delete mk om x = Except.ok R ↔ Model.OrderMaintenance.rebuildStep mk { cur := om2.cur, curIdx := om2.curIdx, nxt := om2.nxt, nxtIdx := om2.nxtIdx, cursor := om2.cursor, cursorSet := om2.cursorSet, live := om2.live - 1, nextHandle := om2.nextHandle, rebuilds := om2.rebuilds, KB := om2.KB } = Except.ok R

                        Level F's deletion, step by step.

                        Decrement the wrapper's live-handle counter with truncated subtraction.

                        Equations
                        • One or more equations did not get rendered due to their size.
                        Instances For
                          theorem OrderMaintenance.Impl.liveDecW_ok {om : Model.OrderMaintenance} {m : Machine.State} {p : ℕ} (h : WEnc om m p) :
                          Machine.wp liveDecC (fun (m' : Machine.State) (k : ℕ) => WEnc { cur := om.cur, curIdx := om.curIdx, nxt := om.nxt, nxtIdx := om.nxtIdx, cursor := om.cursor, cursorSet := om.cursorSet, live := om.live - 1, nextHandle := om.nextHandle, rebuilds := om.rebuilds, KB := om.KB } m' p ∧ m'.loc = m.loc ∧ k ≤ 20) m

                          The cost bound of a deletion.

                          Equations
                          Instances For
                            theorem OrderMaintenance.Impl.MInv.delete_prefix {om : Model.OrderMaintenance} {Sp : Spec.State} (hI : MInv om Sp) {x : ℕ} (hv : x ∈ Sp.list) :
                            ∃ (om' : Model.OrderMaintenance) (c' : Model.Core) (om2 : Model.OrderMaintenance), Model.OrderMaintenance.delete Proof.proofParams om x = Except.ok om' ∧ MInv om' (Spec.step Sp (Spec.Op.delete x)).1 ∧ 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 → RLSafeP { 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) ∧ Model.OrderMaintenance.rebuildStep Proof.proofParams { cur := om2.cur, curIdx := om2.curIdx, nxt := om2.nxt, nxtIdx := om2.nxtIdx, cursor := om2.cursor, cursorSet := om2.cursorSet, live := om2.live - 1, nextHandle := om2.nextHandle, rebuilds := om2.rebuilds, KB := om2.KB } = Except.ok om' ∧ c'.P = om.cur.P ∧ om2.cur = c' ∧ om2.KB = om.KB ∧ MX { cur := om2.cur, curIdx := om2.curIdx, nxt := om2.nxt, nxtIdx := om2.nxtIdx, cursor := om2.cursor, cursorSet := om2.cursorSet, live := om2.live - 1, nextHandle := om2.nextHandle, rebuilds := om2.rebuilds, KB := om2.KB }

                            The shared functional prefix of deletion: marking, mirroring, and the safe rebuild retain the core parameters and intermediate Level M invariant.

                            theorem OrderMaintenance.Impl.deleteW_ok {om : Model.OrderMaintenance} {m : Machine.State} {p : ℕ} {Sp : Spec.State} (h : WEnc om m p) (hI : MInv om Sp) {x : ℕ} (hv : x ∈ Sp.list) (hxl : m.loc "x" = x) :

                            A deletion at Level M: it keeps the invariant, and the machine code runs in at most delW K_B steps.

                            Order queries #

                            theorem OrderMaintenance.Impl.orderW_okM {om : Model.OrderMaintenance} {m : Machine.State} {p : ℕ} {Sp : Spec.State} (h : WEnc om m p) (hI : MInv om Sp) {x y : ℕ} (hxv : x ∈ Sp.list) (hyv : y ∈ Sp.list) (hxl : m.loc "x" = x) (hyl : m.loc "y" = y) :
                            om.order x y = Except.ok (Spec.precedes Sp.list x y) ∧ Machine.wp orderWS (fun (m' : Machine.State) (k : ℕ) => WEnc om m' p ∧ m'.loc "r" = b2n (Spec.precedes Sp.list x y) ∧ k ≤ 100) m

                            An order query at Level M: the specification's answer in local r, the state unchanged, at most 100 steps.