Documentation

LeanPool.OrderMaintenance.Impl.ChunkStep

M6: chunk split steps (removeChunk, moveUnit, chunkSplitStep, driveChunk) #

As for groups, the agreement lemmas cover the cases Level F's cost proof uses, and reach the states it names (cremoveState, cmoveLState, cmoveRState). A unit has at most three groups, kept in locals.

removeChunk #

Test whether a chunk is an overflow sibling of the source in local x.

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

    Release an overflow sibling to the quiet state and reconsider its queue entry.

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

      removeChunk x: x is dead, its overflow siblings quiet (and offered to the queue).

      Equations
      • One or more equations did not get rendered due to their size.
      Instances For
        theorem OrderMaintenance.Impl.cquietS_ok {κ : Caps} {S0 : Model.Core} {L : Loc} {y : Machine.Reg} {j x : ℕ} (hy : L y = j) (hx : L "x" = x) (hst : (S0.C.getX j).st = Model.St.overflow) (hsrc : (S0.C.getX j).src = x) (hsz : (S0.C.getX j).size ≤ S0.P.theta) (hj : j < S0.C.size) (hjT : j < κ.tbl Tbl.C) :
        ∃ (n : ℕ), evalF κ (cquietS y) S0 L = Res.ok { P := S0.P, E := S0.E, Gs := S0.Gs, C := S0.C.modify j Proof.quietC, freeG := S0.freeG, count := S0.count, head := S0.head, tail := S0.tail, firstGroup := S0.firstGroup, firstChunk := S0.firstChunk, ready := S0.ready, prep := S0.prep, resJob := S0.resJob, fallbacks := S0.fallbacks, pqHead := S0.pqHead, pqNext := S0.pqNext, pqPrev := S0.pqPrev, pqWhere := S0.pqWhere, nbNext := S0.nbNext, nbPrev := S0.nbPrev, pqHi := S0.pqHi, pqLo := S0.pqLo, nodes := S0.nodes, path := S0.path, cin := S0.cin, lpar := S0.lpar } L n ∧ n ≤ 50
        theorem OrderMaintenance.Impl.removeChunkS_agree (κ : Caps) (s : Model.Core) (L : Loc) {x : ℕ} (hx : L "x" = x) (hlr : Proof.cLl s x ≠ Proof.cRr s x) (hlx : Proof.cLl s x ≠ x) (hrx : Proof.cRr s x ≠ x) (hxs : x < s.C.size) (hl : Proof.cSt s (Proof.cLl s x) = Model.St.overflow ∧ Proof.cSrc s (Proof.cLl s x) = x) (hr : Proof.cSt s (Proof.cRr s x) = Model.St.overflow ∧ Proof.cSrc s (Proof.cRr s x) = x) (hszl : Proof.cSz s (Proof.cLl s x) ≤ s.P.theta) (hszr : Proof.cSz s (Proof.cRr s x) ≤ s.P.theta) (hlS : Proof.cLl s x < s.C.size) (hrS : Proof.cRr s x < s.C.size) (hC : s.C.size ≤ κ.tbl Tbl.C) :
        ∃ (L' : Loc) (n : ℕ), evalF κ removeChunkS s L = Res.ok (Proof.cremoveState s x) L' n ∧ n ≤ 150

        The unit at an end of a chunk #

        The unit held in locals: [u0], or [u0, u1, u2] when uk = 3.

        Equations
        Instances For

          Test whether the left candidate is the source group's left overflow sibling.

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

            Test whether the right candidate is the source group's right overflow sibling.

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

              unitCand x (lf = 1) into uk, u0, u1, u2 (locals x lf).

              Equations
              • One or more equations did not get rendered due to their size.
              Instances For
                theorem OrderMaintenance.Impl.unitCand_eq (s : Model.Core) (x : ℕ) (left : Bool) :
                Model.unitCand s x left = have g0 := if left = true then (s.C.getX x).first else (s.C.getX x).last; have G0 := s.Gs.getX g0; if G0.st = Model.St.overflow then have S := s.Gs.getX G0.src; if left = true ∧ S.l = g0 then [g0, G0.src, S.r] else if left = false ∧ S.r = g0 then [S.l, G0.src, g0] else [g0] else [g0]
                theorem OrderMaintenance.Impl.unitS_ok {κ : Caps} {s : Model.Core} {L : Loc} {x : ℕ} {left : Bool} (hx : L "x" = x) (hlf : L "lf" = b2n left) (hxT : x < κ.tbl Tbl.C) (hg0T : (if left = true then (s.C.getX x).first else (s.C.getX x).last) < κ.tbl Tbl.G) (hsrT : (s.Gs.getX (if left = true then (s.C.getX x).first else (s.C.getX x).last)).st = Model.St.overflow → (s.Gs.getX (if left = true then (s.C.getX x).first else (s.C.getX x).last)).src < κ.tbl Tbl.G) :
                ∃ (L' : Loc) (n : ℕ), evalF κ unitS s L = Res.ok s L' n ∧ unitOf L' = Model.unitCand s x left ∧ (L' "uk" = 1 ∨ L' "uk" = 3) ∧ n ≤ 80 ∧ ∀ (r : String), r ≠ "g0" → r ≠ "uk" → r ≠ "u0" → r ≠ "u1" → r ≠ "u2" → r ≠ "sr" → L' r = L r

                Labels for a moved unit #

                theorem OrderMaintenance.Impl.pushBackLabs_inv {c D B k : ℕ} {prev : Option ℕ} {s s' : Model.Core} {labs : List ℕ} (h : EStateM.run (Model.pushBackLabs c D B prev (k + 1)) s = EStateM.Result.ok labs s') :
                ∃ (l : ℕ) (rest : List ℕ), labs = l :: rest ∧ EStateM.run (Model.pushBackLabs c D B (some l) k) s = EStateM.Result.ok rest s' ∧ (prev = none → l = c) ∧ ∀ (p : ℕ), prev = some p → p + D < 1 <<< B ∧ p < p + D ∧ l = p + D
                theorem OrderMaintenance.Impl.pushFrontLabs_inv {c D k : ℕ} {nxt : Option ℕ} {s s' : Model.Core} {labs : List ℕ} (h : EStateM.run (Model.pushFrontLabs c D nxt (k + 1)) s = EStateM.Result.ok labs s') :
                ∃ (l : ℕ) (rest : List ℕ), labs = rest ++ [l] ∧ EStateM.run (Model.pushFrontLabs c D (some l) k) s = EStateM.Result.ok rest s' ∧ (nxt = none → l = c) ∧ ∀ (n : ℕ), nxt = some n → D ≤ n ∧ D ≠ 0 ∧ l = n - D
                theorem OrderMaintenance.Impl.pushBackLabs_zero {c D B : ℕ} {prev : Option ℕ} {s s' : Model.Core} {labs : List ℕ} (h : EStateM.run (Model.pushBackLabs c D B prev 0) s = EStateM.Result.ok labs s') :
                labs = [] ∧ s' = s
                theorem OrderMaintenance.Impl.pushFrontLabs_zero {c D : ℕ} {nxt : Option ℕ} {s s' : Model.Core} {labs : List ℕ} (h : EStateM.run (Model.pushFrontLabs c D nxt 0) s = EStateM.Result.ok labs s') :
                labs = [] ∧ s' = s

                The labels held in locals: [l0], or [l0, l1, l2] when uk = 3.

                Equations
                Instances For
                  theorem OrderMaintenance.Impl.centreG_ev {κ : Caps} {S0 : Model.Core} {L : Loc} :
                  Exp.ev κ S0 L centreG = some (1 <<< (S0.P.groupBits - 1))

                  pushBackLabs after the last group of chunk y (locals y uk).

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

                    pushFrontLabs before the first group of chunk y (locals y uk).

                    Equations
                    • One or more equations did not get rendered due to their size.
                    Instances For
                      theorem OrderMaintenance.Impl.labLS_ok {κ : Caps} {s : Model.Core} {L : Loc} {y k : ℕ} {labs : List ℕ} (hy : L "y" = y) (hk : L "uk" = 1 ∧ k = 1 ∨ L "uk" = 3 ∧ k = 3) (hyT : y < κ.tbl Tbl.C) (hlT : (s.C.getX y).last < κ.tbl Tbl.G) (hlabs : EStateM.run (Model.pushBackLabs (1 <<< (s.P.groupBits - 1)) s.P.groupSpacing s.P.groupBits (if (s.C.getX y).first = Model.NIL then none else some (s.Gs.getX (s.C.getX y).last).lab) k) s = EStateM.Result.ok labs s) :
                      ∃ (L' : Loc) (n : ℕ), evalF κ labLS s L = Res.ok s L' n ∧ labsOf L' = labs ∧ L' "uk" = L "uk" ∧ n ≤ 150 ∧ ∀ (r : String), r ≠ "D" → r ≠ "B" → r ≠ "l0" → r ≠ "l1" → r ≠ "l2" → r ≠ "a" → r ≠ "v" → r ≠ "lab" → L' r = L r
                      theorem OrderMaintenance.Impl.labRS_ok {κ : Caps} {s : Model.Core} {L : Loc} {y k : ℕ} {labs : List ℕ} (hy : L "y" = y) (hk : L "uk" = 1 ∧ k = 1 ∨ L "uk" = 3 ∧ k = 3) (hyT : y < κ.tbl Tbl.C) (hfT : (s.C.getX y).first < κ.tbl Tbl.G) (hlabs : EStateM.run (Model.pushFrontLabs (1 <<< (s.P.groupBits - 1)) s.P.groupSpacing (if (s.C.getX y).first = Model.NIL then none else some (s.Gs.getX (s.C.getX y).first).lab) k) s = EStateM.Result.ok labs s) :
                      ∃ (L' : Loc) (n : ℕ), evalF κ labRS s L = Res.ok s L' n ∧ labsOf L' = labs ∧ L' "uk" = L "uk" ∧ n ≤ 150 ∧ ∀ (r : String), r ≠ "D" → r ≠ "m" → r ≠ "l0" → r ≠ "l1" → r ≠ "l2" → r ≠ "b" → r ≠ "lab" → L' r = L r

                      Moving a unit's groups #

                      The moved groups join chunk y with their labels.

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

                        Update chunk indices and labels for the one or three groups in a moving unit.

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

                          Join groups u to chunk y with labs, matching the Level F group update.

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

                            Change a group's containing chunk and order label.

                            Equations
                            • One or more equations did not get rendered due to their size.
                            Instances For
                              theorem OrderMaintenance.Impl.mgGS_ok {κ : Caps} {S0 : Model.Core} {L : Loc} {y : ℕ} (hy : L "y" = y) (hk : L "uk" = 1 ∨ L "uk" = 3) (hu : ∀ g ∈ unitOf L, g < S0.Gs.size ∧ g < κ.tbl Tbl.G) :
                              ∃ (n : ℕ), evalF κ mgGS S0 L = Res.ok { P := S0.P, E := S0.E, Gs := moveGs y (unitOf L) (labsOf L) S0.Gs, C := S0.C, freeG := S0.freeG, count := S0.count, head := S0.head, tail := S0.tail, firstGroup := S0.firstGroup, firstChunk := S0.firstChunk, ready := S0.ready, prep := S0.prep, resJob := S0.resJob, fallbacks := S0.fallbacks, pqHead := S0.pqHead, pqNext := S0.pqNext, pqPrev := S0.pqPrev, pqWhere := S0.pqWhere, nbNext := S0.nbNext, nbPrev := S0.nbPrev, pqHi := S0.pqHi, pqLo := S0.pqLo, nodes := S0.nodes, path := S0.path, cin := S0.cin, lpar := S0.lpar } L n ∧ n ≤ 40

                              Select the last group of a moving unit, according to whether it has one or three groups.

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

                                Remove the moving prefix from the source chunk's endpoint registers.

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

                                  Append the moving prefix to the destination chunk's endpoints.

                                  Equations
                                  • One or more equations did not get rendered due to their size.
                                  Instances For
                                    theorem OrderMaintenance.Impl.ulS_ok {κ : Caps} {S0 : Model.Core} {L : Loc} (hk : L "uk" = 1 ∨ L "uk" = 3) :
                                    theorem OrderMaintenance.Impl.mgLS_ok {κ : Caps} {s : Model.Core} {L : Loc} {x y : ℕ} (hx : L "x" = x) (hy : L "y" = y) (hk : L "uk" = 1 ∨ L "uk" = 3) (hxy : x ≠ y) (hxs : x < s.C.size) (hys : y < s.C.size) (hC : s.C.size ≤ κ.tbl Tbl.C) (hu : ∀ g ∈ unitOf L, g < s.Gs.size ∧ g < κ.tbl Tbl.G) :
                                    ∃ (L' : Loc) (n : ℕ), evalF κ mgLS s L = Res.ok (Model.moveGroupsLeft s x y (unitOf L) (labsOf L)) L' n ∧ n ≤ 100 ∧ ∀ (r : String), r ≠ "ul" → L' r = L r

                                    Remove the moving suffix from the source chunk's endpoints.

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

                                      Prepend the moving suffix to the destination chunk's endpoints.

                                      Equations
                                      • One or more equations did not get rendered due to their size.
                                      Instances For
                                        theorem OrderMaintenance.Impl.mgRS_ok {κ : Caps} {s : Model.Core} {L : Loc} {x y : ℕ} (hx : L "x" = x) (hy : L "y" = y) (hk : L "uk" = 1 ∨ L "uk" = 3) (hxy : x ≠ y) (hxs : x < s.C.size) (hys : y < s.C.size) (hC : s.C.size ≤ κ.tbl Tbl.C) (hu : ∀ g ∈ unitOf L, g < s.Gs.size ∧ g < κ.tbl Tbl.G) :
                                        ∃ (L' : Loc) (n : ℕ), evalF κ mgRS s L = Res.ok (Model.moveGroupsRight s x y (unitOf L) (labsOf L)) L' n ∧ n ≤ 100 ∧ ∀ (r : String), r ≠ "ul" → L' r = L r

                                        Sizes after a move #

                                        moveSizes x y unit (locals x y uk u0 u1 u2).

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

                                          Transfer the moving unit's element count between its source and destination chunks.

                                          Equations
                                          • One or more equations did not get rendered due to their size.
                                          Instances For
                                            theorem OrderMaintenance.Impl.msS_ok {κ : Caps} {s : Model.Core} {L : Loc} {x y : ℕ} (hx : L "x" = x) (hy : L "y" = y) (hk : L "uk" = 1 ∨ L "uk" = 3) (hxs : x < s.C.size) (hys : y < s.C.size) (hC : s.C.size ≤ κ.tbl Tbl.C) (hu : ∀ g ∈ unitOf L, g < κ.tbl Tbl.G) :
                                            ∃ (L' : Loc) (n : ℕ), evalF κ msS s L = Res.ok (Proof.cmoveSizes s x y (unitOf L)) L' n ∧ n ≤ 80 ∧ ∀ (r : String), r ≠ "mv" → L' r = L r

                                            chunkSplitStep #

                                            Choose the lighter overflow sibling, breaking equal-size ties to the left.

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

                                              Choose a unit and destination, move it, and update the two chunk sizes.

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

                                                Move one unit to the lighter sibling, or remove an empty chunk, returning ok.

                                                Equations
                                                • One or more equations did not get rendered due to their size.
                                                Instances For
                                                  theorem OrderMaintenance.Impl.chunkSplitStepS_left (κ : Caps) (s : Model.Core) (L : Loc) {x : ℕ} {labs : List ℕ} (hx : L "x" = x) (hne : Proof.cF s x ≠ Model.NIL) (hdir : Proof.cSz s (Proof.cLl s x) ≤ Proof.cSz s (Proof.cRr s x)) (hlabs : EStateM.run (Proof.pushLabsL s x (Model.unitCand s x true).length) s = EStateM.Result.ok labs s) (hxs : x < s.C.size) (hlS : Proof.cLl s x < s.C.size) (hrS : Proof.cRr s x < s.C.size) (hxl : x ≠ Proof.cLl s x) (hC : s.C.size ≤ κ.tbl Tbl.C) (hG : s.Gs.size ≤ κ.tbl Tbl.G) (hu : ∀ g ∈ Model.unitCand s x true, g < s.Gs.size) (hg0 : Proof.cF s x < κ.tbl Tbl.G) (hsr : (s.Gs.getX (Proof.cF s x)).st = Model.St.overflow → (s.Gs.getX (Proof.cF s x)).src < κ.tbl Tbl.G) (hyl : Proof.cLs s (Proof.cLl s x) < κ.tbl Tbl.G) :
                                                  ∃ (L' : Loc) (n : ℕ), evalF κ chunkSplitStepS s L = Res.ok (Proof.cmoveLState s x (Model.unitCand s x true) labs) L' n ∧ L' "ok" = 1 ∧ L' "x" = x ∧ n ≤ 700
                                                  theorem OrderMaintenance.Impl.chunkSplitStepS_right (κ : Caps) (s : Model.Core) (L : Loc) {x : ℕ} {labs : List ℕ} (hx : L "x" = x) (hne : Proof.cF s x ≠ Model.NIL) (hdir : Proof.cSz s (Proof.cRr s x) < Proof.cSz s (Proof.cLl s x)) (hlabs : EStateM.run (Proof.pushLabsR s x (Model.unitCand s x false).length) s = EStateM.Result.ok labs s) (hxs : x < s.C.size) (hlS : Proof.cLl s x < s.C.size) (hrS : Proof.cRr s x < s.C.size) (hxl : x ≠ Proof.cRr s x) (hC : s.C.size ≤ κ.tbl Tbl.C) (hG : s.Gs.size ≤ κ.tbl Tbl.G) (hu : ∀ g ∈ Model.unitCand s x false, g < s.Gs.size) (hg0 : Proof.cLs s x < κ.tbl Tbl.G) (hsr : (s.Gs.getX (Proof.cLs s x)).st = Model.St.overflow → (s.Gs.getX (Proof.cLs s x)).src < κ.tbl Tbl.G) (hyl : Proof.cF s (Proof.cRr s x) < κ.tbl Tbl.G) :
                                                  ∃ (L' : Loc) (n : ℕ), evalF κ chunkSplitStepS s L = Res.ok (Proof.cmoveRState s x (Model.unitCand s x false) labs) L' n ∧ L' "ok" = 1 ∧ L' "x" = x ∧ n ≤ 700
                                                  theorem OrderMaintenance.Impl.chunkSplitStepS_remove (κ : Caps) (s : Model.Core) (L : Loc) {x : ℕ} (hx : L "x" = x) (he : Proof.cF s x = Model.NIL) (hlr : Proof.cLl s x ≠ Proof.cRr s x) (hlx : Proof.cLl s x ≠ x) (hrx : Proof.cRr s x ≠ x) (hxs : x < s.C.size) (hl : Proof.cSt s (Proof.cLl s x) = Model.St.overflow ∧ Proof.cSrc s (Proof.cLl s x) = x) (hr : Proof.cSt s (Proof.cRr s x) = Model.St.overflow ∧ Proof.cSrc s (Proof.cRr s x) = x) (hszl : Proof.cSz s (Proof.cLl s x) ≤ s.P.theta) (hszr : Proof.cSz s (Proof.cRr s x) ≤ s.P.theta) (hlS : Proof.cLl s x < s.C.size) (hrS : Proof.cRr s x < s.C.size) (hC : s.C.size ≤ κ.tbl Tbl.C) :
                                                  ∃ (L' : Loc) (n : ℕ), evalF κ chunkSplitStepS s L = Res.ok (Proof.cremoveState s x) L' n ∧ L' "ok" = 0 ∧ n ≤ 200

                                                  The drive loop #

                                                  Procedure moving one chunk-split unit and reporting whether work remains.

                                                  Equations
                                                  Instances For

                                                    Perform one chunk-split step unless an earlier iteration finished the split.

                                                    Equations
                                                    • One or more equations did not get rendered due to their size.
                                                    Instances For
                                                      def OrderMaintenance.Impl.CStepAgree (κ : Caps) (p : ℕ) (t t' : Model.Core) (b : Bool) :

                                                      A Level M split step that agrees with a Level F one (b = Level F's result).

                                                      Equations
                                                      • One or more equations did not get rendered due to their size.
                                                      Instances For
                                                        theorem OrderMaintenance.Impl.driveChunkFromS_agree (κ : Caps) (s : Model.Core) (L : Loc) {p : ℕ} (hg : L "x" = p) (I : ℕ → Model.Core → Prop) (h0 : I 0 s) (hstep : ∀ (j : ℕ) (t : Model.Core), I j t → j < s.P.chunkBudget → ∃ (b : Bool) (t' : Model.Core), EStateM.run (Model.chunkSplitStep p) t = EStateM.Result.ok b t' ∧ (b = true → I (j + 1) t') ∧ CStepAgree κ p t t' b) :

                                                        driveChunk #

                                                        Procedure performing at most the configured chunk-split budget.

                                                        Equations
                                                        Instances For

                                                          driveChunk g: drive the split g belongs to, if any (local g).

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

                                                            The drive of the split rooted at q agrees at Level M, ending in t'.

                                                            Equations
                                                            • One or more equations did not get rendered due to their size.
                                                            Instances For
                                                              theorem OrderMaintenance.Impl.driveChunkFromS_agree' (κ : Caps) (s : Model.Core) {p : ℕ} (I : ℕ → Model.Core → Prop) (h0 : I 0 s) (hstep : ∀ (j : ℕ) (t : Model.Core), I j t → j < s.P.chunkBudget → ∃ (b : Bool) (t' : Model.Core), EStateM.run (Model.chunkSplitStep p) t = EStateM.Result.ok b t' ∧ (b = true → I (j + 1) t') ∧ CStepAgree κ p t t' b) :
                                                              ∃ (t' : Model.Core), CDriveAgree κ p s t'
                                                              theorem OrderMaintenance.Impl.driveChunkS_agree (κ : Caps) (s : Model.Core) (L : Loc) {g : ℕ} (hg : L "x" = g) (hgT : g < κ.tbl Tbl.C) {σ' : Model.Core} (h : EStateM.run (Model.driveChunk g) s = EStateM.Result.ok () σ') (hA : ∀ (q : ℕ), (s.C.getX g).st = Model.St.splitting ∧ q = g ∨ (s.C.getX g).st = Model.St.overflow ∧ q = (s.C.getX g).src → CDriveAgree κ q s σ') :
                                                              ∃ (L' : Loc) (n : ℕ), evalF κ driveChunkS s L = Res.ok σ' L' n ∧ n ≤ 30 + s.P.chunkBudget * 751