Documentation

LeanPool.OrderMaintenance.Impl.PeakCore1

Theorem W, option (A), stage A2: the peak of the queue, list, element and group procedures #

For each procedure, PK: from a state with the invariant Gd (and, for the few that store a computed value, a bound on it), the run computes nothing at or above 2^W, W ≥ 2K + 4, and keeps the invariant. Most procedures are safe (Stm.Safe, closed by proveSafe); the others store a label after its guard (afterS), a centre label 2^(B−1), a size plus one, or a loop counter.

The locals are at width K (ΓK), except the candidate label v of afterS, at width K + 1 (ΓV).

Nothing here is used by Theorems A and B.

@[reducible, inline]

Every local at width K.

Equations
Instances For
    @[reducible, inline]

    Every local at width K, except the candidate label v of afterS, at K + 1.

    Equations
    Instances For
      @[reducible, inline]

      The locals of a chunk split step: v (of afterS) at width K + 1, the moved size mv at K + 2, every other at K.

      Equations
      Instances For
        @[reducible, inline]

        The locals of an element insertion: the handle h at width KH, the candidate label v at K + 1, every other at K.

        Equations
        Instances For
          @[reducible, inline]

          The locals of a drain start: the weight sums t, b, ws (of at most 511 weights) at width K + 9, every other at K.

          Equations
          Instances For
            @[reducible, inline]

            The locals of roomNextTo: the lower bound lo (a label plus one) at width K + 1.

            Equations
            Instances For

              Close Stm.Safe of a concrete statement (after its definitions are unfolded).

              Equations
              Instances For

                Safe procedures #

                theorem OrderMaintenance.Impl.pqLinkAfter_safe {K KH W : ℕ} (hK : 8 ≤ K) (hW : 2 * K + 4 ≤ W) :
                theorem OrderMaintenance.Impl.pqAdd_safe {K KH W : ℕ} (hK : 8 ≤ K) (hW : 2 * K + 4 ≤ W) :
                Stm.Safe K KH (ΓK K) W pqAddP.body
                theorem OrderMaintenance.Impl.pqDel_safe {K KH W : ℕ} (hK : 8 ≤ K) (hW : 2 * K + 4 ≤ W) :
                Stm.Safe K KH (ΓK K) W pqDelP.body
                theorem OrderMaintenance.Impl.pqInsertScan_safe {K KH W : ℕ} (hK : 8 ≤ K) (hW : 2 * K + 4 ≤ W) :
                theorem OrderMaintenance.Impl.pqEnterIfAbove_safe {K KH W : ℕ} (hK : 8 ≤ K) (hW : 2 * K + 4 ≤ W) :
                theorem OrderMaintenance.Impl.pqPopMax_safe {K KH W : ℕ} (hK : 8 ≤ K) (hW : 2 * K + 4 ≤ W) :
                theorem OrderMaintenance.Impl.pqEmpty_safe {K KH W : ℕ} (hK : 8 ≤ K) (hW : 2 * K + 4 ≤ W) :
                theorem OrderMaintenance.Impl.find_safe {K KH W : ℕ} (hK : 8 ≤ K) (hW : 2 * K + 4 ≤ W) (k : LK) :
                Stm.Safe K KH (ΓK K) W (findP k).body
                theorem OrderMaintenance.Impl.assocSet_safe {K KH W : ℕ} (hK : 8 ≤ K) (hW : 2 * K + 4 ≤ W) (k : LK) :
                Stm.Safe K KH (ΓK K) W (assocSetP k).body
                theorem OrderMaintenance.Impl.lookup_safe {K KH W : ℕ} (hK : 8 ≤ K) (hW : 2 * K + 4 ≤ W) (k : LK) :
                Stm.Safe K KH (ΓK K) W (lookupP k).body
                theorem OrderMaintenance.Impl.insertIdx_safe {K KH W : ℕ} (hK : 8 ≤ K) (hW : 2 * K + 4 ≤ W) (k : LK) :
                Stm.Safe K KH (ΓK K) W (insertIdxP k).body
                theorem OrderMaintenance.Impl.copyS_safe {K KH W : ℕ} (hK : 8 ≤ K) (hW : 2 * K + 4 ≤ W) (k : LK) :
                Stm.Safe K KH (ΓK K) W (copyS k)
                theorem OrderMaintenance.Impl.eraseIdx_safe {K KH W : ℕ} (hK : 8 ≤ K) (hW : 2 * K + 4 ≤ W) (k : LK) :
                Stm.Safe K KH (ΓK K) W (eraseIdxP k).body
                theorem OrderMaintenance.Impl.order_safe {K KH W : ℕ} (hK : 8 ≤ K) (hW : 2 * K + 4 ≤ W) :
                Stm.Safe K KH (ΓK K) W orderP.body
                theorem OrderMaintenance.Impl.markDead_safe {K KH W : ℕ} (hK : 8 ≤ K) (hW : 2 * K + 4 ≤ W) :
                theorem OrderMaintenance.Impl.labBefore_safe {K KH W : ℕ} (hK : 8 ≤ K) (hW : 2 * K + 4 ≤ W) :
                theorem OrderMaintenance.Impl.newGroup_safe {K KH W : ℕ} (hK : 8 ≤ K) (hW : 2 * K + 4 ≤ W) :
                theorem OrderMaintenance.Impl.linkGroupPair_safe {K KH W : ℕ} (hK : 8 ≤ K) (hW : 2 * K + 4 ≤ W) :
                theorem OrderMaintenance.Impl.unlinkGroup_safe {K KH W : ℕ} (hK : 8 ≤ K) (hW : 2 * K + 4 ≤ W) :
                theorem OrderMaintenance.Impl.move_safe {K KH W : ℕ} (hK : 8 ≤ K) (hW : 2 * K + 4 ≤ W) (b : Bool) :
                Stm.Safe K KH (ΓK K) W (moveP b).body

                Rules for the procedures below #

                theorem OrderMaintenance.Impl.PK.ite_ok {K KH W : ℕ} {κ : Caps} {Γ : Machine.Reg → ℕ} {s : Model.Core} {L : Loc} {c : Exp} {t f : Stm} (hG : Gd K KH κ Γ s L) (hC : CapsW K κ) (hc : Exp.OK Γ K KH W c) (ht : ∀ (v : ℕ), Exp.ev κ s L c = some v → v ≠ 0 → PK K KH κ Γ W t s L) (hf : Exp.ev κ s L c = some 0 → PK K KH κ Γ W f s L) :
                PK K KH κ Γ W (Stm.ite c t f) s L
                theorem OrderMaintenance.Impl.PK.safe_seq {K KH W : ℕ} {κ : Caps} {Γ : Machine.Reg → ℕ} {s : Model.Core} {L : Loc} {c d : Stm} {Γ' : Machine.Reg → ℕ} (hC : CapsW K κ) (hK : 3 ≤ K) (hW : K ≤ W) (hS : Stm.Safe K KH Γ W c) (hG : Gd K KH κ Γ s L) (hd : ∀ (s1 : Model.Core) (L1 : Loc) (n1 : ℕ), evalF κ c s L = Res.ok s1 L1 n1 → Gd K KH κ Γ s1 L1 → PK K KH κ Γ' W d s1 L1) :
                PK K KH κ Γ' W (c;; d) s L
                theorem OrderMaintenance.Impl.evalF_assign_inv {κ : Caps} {s : Model.Core} {L : Loc} {x : Machine.Reg} {e : Exp} {s1 : Model.Core} {L1 : Loc} {n : ℕ} (h : evalF κ (x ::= e) s L = Res.ok s1 L1 n) :
                ∃ (v : ℕ), Exp.ev κ s L e = some v ∧ s = s1 ∧ L1 = Machine.State.upd L x v
                theorem OrderMaintenance.Impl.upd_ne (L : Loc) {x y : Machine.Reg} (v : ℕ) (h : y ≠ x) :
                Machine.State.upd L x v y = L y
                theorem OrderMaintenance.Impl.pow_le_pow' {a b : ℕ} (h : a ≤ b) :
                2 ^ a ≤ 2 ^ b

                Close a width goal Exp.wq … ≤ W or Exp.vw … ≤ w of a concrete expression.

                Equations
                Instances For

                  Labels: afterS, and the centre label #

                  theorem OrderMaintenance.Impl.afterS_pk {K KH W : ℕ} {κ : Caps} {s : Model.Core} {L : Loc} (hC : CapsW K κ) (hW : 2 * K + 4 ≤ W) (hG : Gd K KH κ (ΓV K) s L) (hB : L "B" ≤ K) (ha : L "a" < 2 ^ K) (hD : L "D" < 2 ^ K) :
                  PK K KH κ (ΓV K) W afterS s L

                  Bound afterS: the candidate a + D, its guard, and the label below 2^B.

                  theorem OrderMaintenance.Impl.centre_ev {κ : Caps} (s : Model.Core) (L : Loc) (k : PF) :
                  Exp.ev κ s L (Exp.bin Machine.BinOp.shl 1 ((Exp.prm k).monus 1)) = some (2 ^ (PF.get s.P k - 1))

                  The value of 1 <<< monus (prm k) 1 (the centre label of elementBits or groupBits).

                  theorem OrderMaintenance.Impl.centre_shOK {K : ℕ} {κ : Caps} (s : Model.Core) (L : Loc) {k : PF} (hk : PF.get s.P k ≤ K) :
                  theorem OrderMaintenance.Impl.centre_pk {K KH W : ℕ} {κ : Caps} {s : Model.Core} {L : Loc} {Γ : Machine.Reg → ℕ} (hC : CapsW K κ) (hK : 8 ≤ K) (hW : 2 * K + 4 ≤ W) (hG : Gd K KH κ Γ s L) {k : PF} (hk : PF.get s.P k ≤ K) {x : Machine.Reg} (hx : K ≤ Γ x) :
                  PK K KH κ Γ W (x ::= Exp.bin Machine.BinOp.shl 1 ((Exp.prm k).monus 1)) s L

                  The centre label 2^(B − 1) with B ≤ K: an assignment below 2^K.

                  More rules #

                  theorem OrderMaintenance.Impl.PK.assign_seq {K KH W : ℕ} {κ : Caps} {Γ : Machine.Reg → ℕ} {s : Model.Core} {L : Loc} {x : Machine.Reg} {e : Exp} {d : Stm} {v : ℕ} (hG : Gd K KH κ Γ s L) (hv : Exp.ev κ s L e = some v) (hp : Exp.pk κ s L e < 2 ^ W) (hx : v < 2 ^ Γ x) (hd : Gd K KH κ Γ s (Machine.State.upd L x v) → PK K KH κ Γ W d s (Machine.State.upd L x v)) :
                  PK K KH κ Γ W (x ::= e;; d) s L

                  An assignment whose value is known, then the rest.

                  theorem OrderMaintenance.Impl.PK.safe_assign_seq {K KH W : ℕ} {κ : Caps} {Γ : Machine.Reg → ℕ} {s : Model.Core} {L : Loc} {x : Machine.Reg} {e : Exp} {d : Stm} {v : ℕ} (hC : CapsW K κ) (hG : Gd K KH κ Γ s L) (he : Exp.OK Γ K KH W e) (hw : Exp.vw Γ K KH K e ≤ Γ x) (hv : Exp.ev κ s L e = some v) (hd : Gd K KH κ Γ s (Machine.State.upd L x v) → PK K KH κ Γ W d s (Machine.State.upd L x v)) :
                  PK K KH κ Γ W (x ::= e;; d) s L

                  A safe assignment whose value is known, then the rest.

                  theorem OrderMaintenance.Impl.evalF_wr_inv {κ : Caps} {s : Model.Core} {L : Loc} {f : Fld} {i e : Exp} {s1 : Model.Core} {L1 : Loc} {n : ℕ} (h : evalF κ (Stm.wr f i e) s L = Res.ok s1 L1 n) :
                  ∃ (j : ℕ) (v : ℕ), Exp.ev κ s L i = some j ∧ Exp.ev κ s L e = some v ∧ Fld.set κ s j v f = some s1 ∧ L1 = L
                  theorem OrderMaintenance.Impl.PK.callS {K KH W : ℕ} {κ : Caps} {Γ : Machine.Reg → ℕ} {s : Model.Core} {L : Loc} {q : Proc} {args : List Exp} {ds : List Machine.Reg} {Γc Γe : Machine.Reg → ℕ} (hC : CapsW K κ) (hG : Gd K KH κ Γ s L) (ha : ∀ e ∈ args, Exp.OK Γ K KH W e ∧ Exp.vw Γ K KH K e ≤ K) (hps : ∀ (x : Machine.Reg), K ≤ Γe x) (hb : ∀ (vs : List ℕ), evList κ s L args = some vs → Gd K KH κ Γe s (Machine.State.setLocs (fun (x : Machine.Reg) => 0) q.params vs) → PK K KH κ Γc W q.body s (Machine.State.setLocs (fun (x : Machine.Reg) => 0) q.params vs)) (hr : ∀ r ∈ q.rets, Γc r ≤ K) (hd : ∀ d ∈ ds, K ≤ Γ d) :
                  PK K KH κ Γ W (q.call args ds) s L

                  A call with argument expressions of width K; the body's bound is given for the callee's entry frame.

                  theorem OrderMaintenance.Impl.PK.safe_seq' {K KH W : ℕ} {κ : Caps} {c d : Stm} {Γ : Machine.Reg → ℕ} {s : Model.Core} {L : Loc} (hC : CapsW K κ) (hK : 3 ≤ K) (hW : K ≤ W) (hS : Stm.Safe K KH Γ W c) (hG : Gd K KH κ Γ s L) (hd : ∀ (s1 : Model.Core) (L1 : Loc) (n1 : ℕ), evalF κ c s L = Res.ok s1 L1 n1 → Gd K KH κ Γ s1 L1 → PK K KH κ Γ W d s1 L1) :
                  PK K KH κ Γ W (c;; d) s L

                  Run a safe first statement of a sequence.

                  Equations
                  Instances For

                    Group labels and moves #

                    theorem OrderMaintenance.Impl.gd_a {K KH : ℕ} {κ : Caps} {s : Model.Core} {L : Loc} (hG : Gd K KH κ (ΓV K) s L) (x : Machine.Reg) (hx : x ≠ "v") :
                    L x < 2 ^ K
                    theorem OrderMaintenance.Impl.afterTail_pk {K KH W : ℕ} {κ : Caps} {s : Model.Core} {L : Loc} (hC : CapsW K κ) (hK : 8 ≤ K) (hW : 2 * K + 4 ≤ W) {a : Exp} {kD kB : PF} (hG : Gd K KH κ (ΓV K) s L) (hB : PF.get s.P kB ≤ K) (ha : Exp.OK (ΓV K) K KH W a) (haw : Exp.vw (ΓV K) K KH K a ≤ K) :
                    PK K KH κ (ΓV K) W ("a" ::= a;; "D" ::= Exp.prm kD;; "B" ::= Exp.prm kB;; afterS) s L

                    The tail of labAfter and of the left label of a move: a, D, B := prm k, afterS.

                    theorem OrderMaintenance.Impl.labAfter_pk {K KH W : ℕ} {κ : Caps} {s : Model.Core} {L : Loc} (hC : CapsW K κ) (hK : 8 ≤ K) (hW : 2 * K + 4 ≤ W) (hG : Gd K KH κ (ΓV K) s L) (hP : PRoom K s.P) :
                    PK K KH κ (ΓV K) W labAfterS s L
                    theorem OrderMaintenance.Impl.moveLabL_pk {K KH W : ℕ} {κ : Caps} {s : Model.Core} {L : Loc} (hC : CapsW K κ) (hK : 8 ≤ K) (hW : 2 * K + 4 ≤ W) (hG : Gd K KH κ (ΓV K) s L) (hP : PRoom K s.P) :
                    PK K KH κ (ΓV K) W moveLabL s L
                    theorem OrderMaintenance.Impl.moveLabR_pk {K KH W : ℕ} {κ : Caps} {s : Model.Core} {L : Loc} (hC : CapsW K κ) (hK : 8 ≤ K) (hW : 2 * K + 4 ≤ W) (hG : Gd K KH κ (ΓV K) s L) (hP : PRoom K s.P) :
                    PK K KH κ (ΓV K) W moveLabR s L
                    theorem OrderMaintenance.Impl.moveElem_pk {K KH W : ℕ} {κ : Caps} {s : Model.Core} {L : Loc} (hC : CapsW K κ) (hK : 8 ≤ K) (hW : 2 * K + 4 ≤ W) (hG : Gd K KH κ (ΓV K) s L) (hP : PRoom K s.P) :
                    PK K KH κ (ΓV K) W moveElemS s L

                    Reads #

                    theorem OrderMaintenance.Impl.Exp.ev_rd_inv {κ : Caps} {f : Fld} {i : Exp} {s : Model.Core} {L : Loc} {w : ℕ} (h : ev κ s L (rd f i) = some w) :
                    ∃ (j : ℕ), ev κ s L i = some j ∧ j < Fld.cap κ f ∧ w = Fld.get s j f
                    theorem OrderMaintenance.Impl.Exp.ev_add1_inv {κ : Caps} {e : Exp} {s : Model.Core} {L : Loc} {w : ℕ} (h : ev κ s L (e + 1) = some w) :
                    ∃ (x : ℕ), ev κ s L e = some x ∧ w = x + 1
                    theorem OrderMaintenance.Impl.Exp.ev_monus_le {κ : Caps} {a b : Exp} {s : Model.Core} {L : Loc} {w : ℕ} (h : ev κ s L (a.monus b) = some w) :
                    ∃ (x : ℕ), ev κ s L a = some x ∧ w ≤ x

                    The tail of a group split step, the split start, the removal #

                    theorem OrderMaintenance.Impl.gssTail_pk {K KH W : ℕ} {κ : Caps} {s : Model.Core} {L : Loc} (hC : CapsW K κ) (hK : 8 ≤ K) (hW : 2 * K + 4 ≤ W) (hG : Gd K KH κ (ΓV K) s L) (hd : L "d" < κ.tbl Tbl.G → (s.Gs.getX (L "d")).size + 1 < 2 ^ K) :
                    PK K KH κ (ΓV K) W gssTail s L

                    The sizes after a move: size d + 1 below 2^K.

                    theorem OrderMaintenance.Impl.labAfterCall_pk {K KH W : ℕ} {κ : Caps} {s : Model.Core} {L : Loc} (hC : CapsW K κ) (hK : 8 ≤ K) (hW : 2 * K + 4 ≤ W) {args : List Exp} {ds : List Machine.Reg} {Γ : Machine.Reg → ℕ} (hG : Gd K KH κ Γ s L) (ha : ∀ e ∈ args, Exp.OK Γ K KH W e ∧ Exp.vw Γ K KH K e ≤ K) (hd : ∀ d ∈ ds, K ≤ Γ d) :
                    PK K KH κ Γ W (labAfterP.call args ds) s L
                    theorem OrderMaintenance.Impl.startGroupSplit_pk {K KH W : ℕ} {κ : Caps} {s : Model.Core} {L : Loc} (hC : CapsW K κ) (hK : 8 ≤ K) (hW : 2 * K + 4 ≤ W) (hG : Gd K KH κ (ΓK K) s L) :
                    PK K KH κ (ΓK K) W startGroupSplitS s L
                    theorem OrderMaintenance.Impl.splitIf_pk {K KH W : ℕ} {κ : Caps} {s : Model.Core} {L : Loc} (hC : CapsW K κ) (hK : 8 ≤ K) (hW : 2 * K + 4 ≤ W) {x q : Machine.Reg} (hG : Gd K KH κ (ΓK K) s L) :
                    PK K KH κ (ΓK K) W (splitIfS x q) s L
                    theorem OrderMaintenance.Impl.removeGroup_pk {K KH W : ℕ} {κ : Caps} {s : Model.Core} {L : Loc} (hC : CapsW K κ) (hK : 8 ≤ K) (hW : 2 * K + 4 ≤ W) (hG : Gd K KH κ (ΓK K) s L) :
                    PK K KH κ (ΓK K) W removeGroupS s L

                    A group split step and the drive #

                    theorem OrderMaintenance.Impl.groupSplitStep_pk {K KH W : ℕ} {κ : Caps} {s : Model.Core} {L : Loc} (hC : CapsW K κ) (hK : 8 ≤ K) (hW : 2 * K + 4 ≤ W) (hG : Gd K KH κ (ΓK K) s L) (hsz : ∀ (L0 : Loc) (S1 : Model.Core) (L1 : Loc) (n : ℕ), L0 "g" = L "g" → evalF κ moveElemS s L0 = Res.ok S1 L1 n → L1 "d" < κ.tbl Tbl.G → (S1.Gs.getX (L1 "d")).size + 1 < 2 ^ K) :
                    PK K KH κ (ΓV K) W groupSplitStepS s L

                    A group split step, given the size bound of the group that receives the element (after the move, at the local d the move sets).