Documentation

LeanPool.OrderMaintenance.Proof.Cost.GMove

Split moves and group removal #

Split moves #

The label of the element moved to the left sibling.

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

    The label of the element moved to the right sibling.

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

      Transfers one element from the source group count to the destination group count.

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

        The state after moving the first element of p to its left sibling.

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

          The state after moving the last element of p to its right sibling.

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

            What a successful left move needs: p alive and non-empty, the left sibling lighter and adjacent, and room for a pushed label.

            Instances For

              Conditions for moving right: a live nonempty source, adjacent lighter sibling and label room.

              Instances For
                theorem OrderMaintenance.Proof.getX_modify_chk (a : Array Model.Group) (i j : ℕ) (f : Model.Group → Model.Group) (hf : ∀ (X : Model.Group), (f X).chk = X.chk) :
                ((a.modify i f).getX j).chk = (a.getX j).chk

                groupSplitStep after a successful move into a sibling in the same chunk.

                Finishes a group split by clearing its state and source pointer.

                Equations
                Instances For

                  Unlinks an emptied source group and returns its siblings to the quiet state.

                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For
                    theorem OrderMaintenance.Proof.removeGroup_ok {s : Model.Core} {p : ℕ} (hp : LiveG s p) (he : gF s p = Model.NIL) (hlr : gLl s p ≠ gRr s p) (hl : gSt s (gLl s p) = Model.St.overflow ∧ gSrc s (gLl s p) = p) (hr : gSt s (gRr s p) = Model.St.overflow ∧ gSrc s (gRr s p) = p) (hszl : gSz s (gLl s p) < s.P.G) (hszr : gSz s (gRr s p) < s.P.G) :
                    theorem OrderMaintenance.Proof.groupSplitStep_remove {s : Model.Core} {p : ℕ} (hp : LiveG s p) (he : gF s p = Model.NIL) (hlr : gLl s p ≠ gRr s p) (hl : gSt s (gLl s p) = Model.St.overflow ∧ gSrc s (gLl s p) = p) (hr : gSt s (gRr s p) = Model.St.overflow ∧ gSrc s (gRr s p) = p) (hszl : gSz s (gLl s p) < s.P.G) (hszr : gSz s (gRr s p) < s.P.G) :

                    Runs of adjacent groups #

                    theorem OrderMaintenance.Proof.INV.runs_adj {s : Model.Core} {A : Abs} (hI : INV s A) {l p : ℕ} (hl : l ∈ A.glist) (hadj : gN s l = p) (hp0 : p ≠ Model.NIL) :
                    ∃ (X : List ℕ) (Y : List ℕ), A.elist = X ++ runOf s A.elist l ++ runOf s A.elist p ++ Y ∧ ∀ z ∈ X ++ Y, eG s z ≠ l ∧ eG s z ≠ p

                    Two adjacent groups' runs are adjacent in the element list.

                    theorem OrderMaintenance.Proof.filter_nil_of {p : ℕ → Bool} {L : List ℕ} (h : ∀ z ∈ L, p z = false) :
                    theorem OrderMaintenance.Proof.nodup_mid {A B : List ℕ} {e : ℕ} (h : (A ++ e :: B).Nodup) :
                    e ∉ A ∧ e ∉ B
                    theorem OrderMaintenance.Proof.runOf_moveFront {s s' : Model.Core} {L X Y rest : List ℕ} {l p e : ℕ} (hL : L = X ++ runOf s L l ++ e :: rest ++ Y) (hXY : ∀ z ∈ X ++ Y, eG s z ≠ l ∧ eG s z ≠ p) (hrest : ∀ z ∈ rest, eG s z = p) (hRl : ∀ z ∈ runOf s L l, eG s z = l) (he : eG s e = p) (hlp : l ≠ p) (hnd : L.Nodup) (heG : ∀ (z : ℕ), eG s' z = if z = e then l else eG s z) (b : ℕ) :
                    runOf s' L b = if b = l then runOf s L l ++ [e] else if b = p then rest else runOf s L b

                    Moving element e from the front of p's run to the end of the adjacent l's run.

                    theorem OrderMaintenance.Proof.runOf_moveBack {s s' : Model.Core} {L X Y front : List ℕ} {p r e : ℕ} (hL : L = X ++ (front ++ [e]) ++ runOf s L r ++ Y) (hXY : ∀ z ∈ X ++ Y, eG s z ≠ p ∧ eG s z ≠ r) (hfront : ∀ z ∈ front, eG s z = p) (hRr : ∀ z ∈ runOf s L r, eG s z = r) (he : eG s e = p) (hpr : p ≠ r) (hnd : L.Nodup) (heG : ∀ (z : ℕ), eG s' z = if z = e then r else eG s z) (b : ℕ) :
                    runOf s' L b = if b = r then e :: runOf s L r else if b = p then front else runOf s L b

                    Moving element e from the back of p's run to the front of the adjacent r's run.

                    The records after a move #

                    theorem OrderMaintenance.Proof.sizeAdj_getX (t : Model.Core) (a b z : ℕ) (hab : a ≠ b) (ha : a < t.Gs.size) (hb : b < t.Gs.size) :
                    (sizeAdj t a b).Gs.getX z = if z = a then have __src := t.Gs.getX z; { next := __src.next, prev := __src.prev, first := __src.first, last := __src.last, chk := __src.chk, lab := __src.lab, size := (t.Gs.getX z).size - 1, st := __src.st, src := __src.src, l := __src.l, r := __src.r, alive := __src.alive } else if z = b then have __src := t.Gs.getX z; { next := __src.next, prev := __src.prev, first := __src.first, last := __src.last, chk := __src.chk, lab := __src.lab, size := (t.Gs.getX z).size + 1, st := __src.st, src := __src.src, l := __src.l, r := __src.r, alive := __src.alive } else t.Gs.getX z
                    theorem OrderMaintenance.Proof.moveFirstLeft_fields (s : Model.Core) (g gl e lab z : ℕ) :
                    gSt (Model.moveFirstLeft s g gl e lab) z = gSt s z ∧ gSrc (Model.moveFirstLeft s g gl e lab) z = gSrc s z ∧ gLl (Model.moveFirstLeft s g gl e lab) z = gLl s z ∧ gRr (Model.moveFirstLeft s g gl e lab) z = gRr s z ∧ gSz (Model.moveFirstLeft s g gl e lab) z = gSz s z
                    theorem OrderMaintenance.Proof.moveLastRight_fields (s : Model.Core) (g gr e lab z : ℕ) :
                    gSt (Model.moveLastRight s g gr e lab) z = gSt s z ∧ gSrc (Model.moveLastRight s g gr e lab) z = gSrc s z ∧ gLl (Model.moveLastRight s g gr e lab) z = gLl s z ∧ gRr (Model.moveLastRight s g gr e lab) z = gRr s z ∧ gSz (Model.moveLastRight s g gr e lab) z = gSz s z
                    structure OrderMaintenance.Proof.MoveSpec (s s' : Model.Core) (src dst e lab : ℕ) :

                    What a move does to the fields the cost invariants read.

                    Instances For
                      theorem OrderMaintenance.Proof.moveLState_spec {s : Model.Core} {p : ℕ} (hlp : gLl s p ≠ p) (hp : p < s.Gs.size) (hl : gLl s p < s.Gs.size) (he : gF s p < s.E.size) :
                      MoveSpec s (moveLState s p) p (gLl s p) (gF s p) (labMoveL s p)
                      theorem OrderMaintenance.Proof.moveRState_spec {s : Model.Core} {p : ℕ} (hrp : gRr s p ≠ p) (hp : p < s.Gs.size) (hr : gRr s p < s.Gs.size) (he : gLs s p < s.E.size) :
                      MoveSpec s (moveRState s p) p (gRr s p) (gLs s p) (labMoveR s p)

                      GInvE across a move #

                      theorem OrderMaintenance.Proof.FamOK.disjoint {s : Model.Core} {p q : ℕ} (Fp : FamOK s p) (Fq : FamOK s q) (hpq : p ≠ q) (hps : gSt s p = Model.St.splitting) (hqs : gSt s q = Model.St.splitting) :
                      q ≠ gLl s p ∧ q ≠ gRr s p ∧ gLl s q ≠ gLl s p ∧ gLl s q ≠ gRr s p ∧ gLl s q ≠ p ∧ gRr s q ≠ gLl s p ∧ gRr s q ≠ gRr s p ∧ gRr s q ≠ p

                      The family members of a splitting group other than p are not in p's family.

                      theorem OrderMaintenance.Proof.FamOK.lp {s : Model.Core} {A : Abs} (hI : INV s A) {p : ℕ} (F : FamOK s p) (hp : LiveG s p) :
                      gLl s p ≠ p
                      theorem OrderMaintenance.Proof.FamOK.rp {s : Model.Core} {A : Abs} (hI : INV s A) {p : ℕ} (F : FamOK s p) (hp : LiveG s p) :
                      gRr s p ≠ p
                      theorem OrderMaintenance.Proof.FamOK.lr {s : Model.Core} {A : Abs} (hI : INV s A) {p : ℕ} (F : FamOK s p) (hp : LiveG s p) :
                      gLl s p ≠ gRr s p
                      theorem OrderMaintenance.Proof.INV.run_head {s : Model.Core} {A : Abs} (hI : INV s A) {g : ℕ} (hg : g ∈ A.glist) (hne : gF s g ≠ Model.NIL) :
                      ∃ (rest : List ℕ), runOf s A.elist g = gF s g :: rest

                      The run of a non-empty group starts at its first element.

                      theorem OrderMaintenance.Proof.INV.run_last {s : Model.Core} {A : Abs} (hI : INV s A) {g : ℕ} (hg : g ∈ A.glist) (hne : gF s g ≠ Model.NIL) :
                      ∃ (front : List ℕ), runOf s A.elist g = front ++ [gLs s g]

                      The run of a non-empty group ends at its last element.

                      theorem OrderMaintenance.Proof.ginv_moveL {s : Model.Core} {A : Abs} {gh : GGh} {δ : ℕ → ℕ} {p : ℕ} (hI : INV s A) (hG : GInvE s A.elist gh δ p) (hp : LiveG s p) (hs : gSt s p = Model.St.splitting) (hne : gF s p ≠ Model.NIL) :
                      GInvE (moveLState s p) A.elist { hv := gh.hv, pb := Function.update gh.pb (gLl s p) (gh.pb (gLl s p) + 1), pf := gh.pf } δ p
                      theorem OrderMaintenance.Proof.ginv_moveR {s : Model.Core} {A : Abs} {gh : GGh} {δ : ℕ → ℕ} {p : ℕ} (hI : INV s A) (hG : GInvE s A.elist gh δ p) (hp : LiveG s p) (hs : gSt s p = Model.St.splitting) (hne : gF s p ≠ Model.NIL) (hroom : gF s (gRr s p) ≠ Model.NIL → s.P.elementSpacing ≤ eL s (gF s (gRr s p))) :
                      GInvE (moveRState s p) A.elist { hv := gh.hv, pb := gh.pb, pf := Function.update gh.pf (gRr s p) (gh.pf (gRr s p) + 1) } δ p

                      Group removal #

                      structure OrderMaintenance.Proof.RemSpec (s s' : Model.Core) (p l r : ℕ) :

                      What removing the emptied group p (with siblings l, r) does to the group records.

                      Instances For
                        theorem OrderMaintenance.Proof.removeState_getX {s : Model.Core} {p : ℕ} (hl : gLl s p < s.Gs.size) (hr : gRr s p < s.Gs.size) (z : ℕ) :
                        theorem OrderMaintenance.Proof.removeState_spec {s : Model.Core} {p : ℕ} (hp : p < s.Gs.size) (hl : gLl s p < s.Gs.size) (hr : gRr s p < s.Gs.size) (hpp : gP s p ≠ p) (hps : gP s p ≠ Model.NIL → gP s p < s.Gs.size) :
                        RemSpec s (removeState s p) p (gLl s p) (gRr s p)
                        theorem OrderMaintenance.Proof.ginv_remove {s : Model.Core} {A : Abs} {gh : GGh} {δ : ℕ → ℕ} {p : ℕ} (hI : INV s A) (hG : GInvE s A.elist gh δ p) (hp : LiveG s p) (hs : gSt s p = Model.St.splitting) (hδ : ∀ (z : ℕ), z ≠ gLl s p → z ≠ p → z ≠ gRr s p → δ z = 0) (hfam : famT s p ≤ s.P.G + kG s.P) (hql : gSz s (gLl s p) < s.P.G ∧ gmin s.P ≤ gSz s (gLl s p)) (hqr : gSz s (gRr s p) < s.P.G ∧ gmin s.P ≤ gSz s (gRr s p)) (hg1 : 1 ≤ gmin s.P) :
                        GInv (removeState s p) A.elist gh fun (x : ℕ) => 0

                        Removing an emptied group keeps GInv. Its siblings become quiet groups of the right size.

                        The drive loop #

                        theorem OrderMaintenance.Proof.forIn_loop {α β : Type} (f : α → β → Model.CM (ForInStep β)) (I : ℕ → Model.Core → Prop) (Q : Model.Core → Prop) (N : ℕ) (hstep : ∀ (x : α) (j : ℕ) (b : β) (t : Model.Core), I j t → j < N → ∃ (c : β) (t' : Model.Core), EStateM.run (f x b) t = EStateM.Result.ok (ForInStep.yield c) t' ∧ I (j + 1) t' ∨ EStateM.run (f x b) t = EStateM.Result.ok (ForInStep.done c) t' ∧ Q t') (l : List α) (k : ℕ) (b : β) (t : Model.Core) :
                        I k t → k + l.length ≤ N → ∃ (c : β) (t' : Model.Core), EStateM.run (forIn l b f) t = EStateM.Result.ok c t' ∧ (I (k + l.length) t' ∨ Q t')
                        theorem OrderMaintenance.Proof.driveGroupFrom_ok {s : Model.Core} {p : ℕ} (I : ℕ → Model.Core → Prop) (Q : Model.Core → Prop) (h0 : I 0 s) (hstep : ∀ (j : ℕ) (t : Model.Core), I j t → j < s.P.groupBudget → ∃ (t' : Model.Core), EStateM.run (Model.groupSplitStep p) t = EStateM.Result.ok true t' ∧ I (j + 1) t' ∨ EStateM.run (Model.groupSplitStep p) t = EStateM.Result.ok false t' ∧ Q t') :

                        The drive loop: groupBudget split steps of p, stopping when p is removed.

                        theorem OrderMaintenance.Proof.Good.ok_inv {α : Type} {m : Model.CM α} (h : Good m) {s : Model.Core} {A : Abs} (hI : INV s A) {a : α} {s' : Model.Core} (hr : EStateM.run m s = EStateM.Result.ok a s') :
                        EFrame s s' ∧ ∃ (A' : Abs), INV s' A' ∧ A'.elist = A.elist
                        theorem OrderMaintenance.Proof.GInvE.close {s : Model.Core} {L : List ℕ} {gh : GGh} {δ : ℕ → ℕ} {p : ℕ} (hG : GInvE s L gh δ p) (hp : LiveG s p) (hs : gSt s p = Model.St.splitting) (hδ : ∀ (z : ℕ), z ≠ gLl s p → z ≠ p → z ≠ gRr s p → δ z = 0) (hG1 : G1 s (fun (x : ℕ) => 0) p) :
                        GInv s L gh fun (x : ℕ) => 0

                        Closing a drive: the family of p satisfies G1 again, and nothing else was exempt.

                        structure OrderMaintenance.Proof.DriveInv (X : Model.Core → Prop) (s : Model.Core) (L : List ℕ) (δ : ℕ → ℕ) (p l r a b c j : ℕ) (t : Model.Core) :

                        The drive's invariant after j moves of p's split. a, b, c are the sizes of l, p, r before the drive.

                        Instances For
                          theorem OrderMaintenance.Proof.DriveInv.removal_bounds {X : Model.Core → Prop} {s t : Model.Core} {L : List ℕ} {δ : ℕ → ℕ} {p l r a b c j : ℕ} (h : DriveInv X s L δ p l r a b c j t) (hP : GParams s.P) (hlo : s.P.G ≤ a + b + c) (hhi : a + b + c ≤ s.P.G + s.P.G / (s.P.groupBudget - 1) + 1) (hbal : a ≤ c + 2 ∧ c ≤ a + 2) (hz : gSz t p = 0) :
                          gSz t l < t.P.G ∧ gSz t r < t.P.G ∧ gmin t.P ≤ gSz t l ∧ gmin t.P ≤ gSz t r ∧ famT t p ≤ t.P.G + kG t.P

                          Empty-source removal bounds follow from the drive's total size and balance invariant.

                          The drive ended by removing p.

                          Instances For
                            structure OrderMaintenance.Proof.XSteps (X Y : Model.Core → Prop) (L : List ℕ) (δ : ℕ → ℕ) (p c : ℕ) :

                            The extra invariant X survives the steps of a drive.

                            Instances For
                              theorem OrderMaintenance.Proof.GInvE.move_left_ok {s : Model.Core} {A : Abs} {gh : GGh} {δ : ℕ → ℕ} {p : ℕ} (hG : GInvE s A.elist gh δ p) (hI : INV s A) (hP : GParams s.P) (hp : LiveG s p) (hs : gSt s p = Model.St.splitting) (hne : gF s p ≠ Model.NIL) (hdir : gSz s (gLl s p) ≤ gSz s (gRr s p)) (hsize : gSz s (gLl s p) + 1 ≤ s.P.G + kG s.P) :

                              Overflow label bounds supply every guard for a left move into the lighter sibling.

                              theorem OrderMaintenance.Proof.GInvE.move_right_ok {s : Model.Core} {A : Abs} {gh : GGh} {δ : ℕ → ℕ} {p : ℕ} (hG : GInvE s A.elist gh δ p) (hI : INV s A) (hP : GParams s.P) (hp : LiveG s p) (hs : gSt s p = Model.St.splitting) (hne : gF s p ≠ Model.NIL) (hdir : gSz s (gRr s p) < gSz s (gLl s p)) (hsize : gSz s (gRr s p) + 1 ≤ s.P.G + kG s.P) :

                              Overflow label bounds supply every guard for a right move into the strictly lighter sibling.

                              theorem OrderMaintenance.Proof.DriveInv.step {X Y : Model.Core → Prop} {s : Model.Core} {L : List ℕ} {δ : ℕ → ℕ} {p l r a b c j : ℕ} {t : Model.Core} (hXs : XSteps X Y L δ p (gC s p)) (hP : GParams s.P) (hδ : ∀ (z : ℕ), z ≠ l → z ≠ p → z ≠ r → δ z = 0) (hTlo : s.P.G ≤ a + b + c) (hThi : a + b + c ≤ s.P.G + s.P.G / (s.P.groupBudget - 1) + 1) (hbal0 : a ≤ c + 2 ∧ c ≤ a + 2) (hD : DriveInv X s L δ p l r a b c j t) :
                              theorem OrderMaintenance.Proof.ginv_drive {X Y : Model.Core → Prop} {s : Model.Core} {A : Abs} {gh : GGh} {δ : ℕ → ℕ} {p : ℕ} (hI : INV s A) (hXs : XSteps X Y A.elist δ p (gC s p)) (hX : X s) (hG : GInvE s A.elist gh δ p) (hP : GParams s.P) (hp : LiveG s p) (hs : gSt s p = Model.St.splitting) (hG1 : G1 s δ p) (hδ : ∀ (z : ℕ), z ≠ gLl s p → z ≠ p → z ≠ gRr s p → δ z = 0) (hδs : δ (gLl s p) + δ p + δ (gRr s p) ≤ 1) (hδle : δ (gLl s p) ≤ gSz s (gLl s p) ∧ δ p ≤ gSz s p ∧ δ (gRr s p) ≤ gSz s (gRr s p)) :

                              Lemma G1 for one drive. Driving the family of p after at most one undriven insertion into it ends with GInv (no undriven insertion): either p has made groupBudget moves and the family satisfies G1 again, or p was removed and its siblings are quiet groups of the right size.

                              The group phase of background #

                              Room for the labels of a split start (Lemma C3 provides it).

                              Equations
                              • One or more equations did not get rendered due to their size.
                              Instances For
                                theorem OrderMaintenance.Proof.GInvE.weaken {s : Model.Core} {L : List ℕ} {gh : GGh} {δ : ℕ → ℕ} (hG : GInv s L gh δ) (x : ℕ) :
                                GInvE s L gh δ x
                                theorem OrderMaintenance.Proof.GInv.quiet_close {s : Model.Core} {L : List ℕ} {gh : GGh} {g : ℕ} (hG : GInv s L gh fun (b : ℕ) => if b = g then 1 else 0) (hq : gSt s g = Model.St.quiet) (hsz : gSz s g < s.P.G) :
                                GInv s L gh fun (x : ℕ) => 0

                                A quiet group that did not split leaves no undriven insertion.

                                structure OrderMaintenance.Proof.XGroup (X Y : Model.Core → Prop) (L : List ℕ) (c : ℕ) :

                                What the extra invariant must survive in the group phase.

                                Instances For
                                  theorem OrderMaintenance.Proof.groupPhase_ok {X Y : Model.Core → Prop} {s : Model.Core} {A : Abs} {gh : GGh} {g : ℕ} (hI : INV s A) (hXg : XGroup X Y A.elist (gC s g)) (hX : X s) (hG : GInv s A.elist gh fun (b : ℕ) => if b = g then 1 else 0) (hP : GParams s.P) (hg : LiveG s g) (hpos : 1 ≤ gSz s g) (hroom : gSt s g = Model.St.quiet → s.P.G ≤ gSz s g → SplitRoom s g) :
                                  ∃ (s' : Model.Core), EStateM.run (have __do_jp := fun (__r : PUnit.{1}) => Model.driveGroup g; if ((s.Gs.getX g).st == Model.St.quiet && decide ((s.Gs.getX g).size ≥ s.P.G)) = true then do let __r ← Model.startGroupSplit g __do_jp __r else __do_jp ()) s = EStateM.Result.ok () s' ∧ DriveDone X Y s A.elist s'

                                  The group phase. After an insertion into group g, the optional split start and the drive of g's family succeed and restore GInv with no undriven insertion.