Documentation

LeanPool.OrderMaintenance.Proof.Correct.GroupMove

Group split steps preserve INV-S (Lemma 3.2: split moves and group removal) #

Neither changes the element list. groupSplitStep, removeGroup and driveGroup are compositions of these with updates that INV-S does not see.

Removing an empty group #

theorem OrderMaintenance.Proof.unlinkGroup_gN {s : Model.Core} {g : ℕ} (hpg : gP s g ≠ g) (z : ℕ) :
gN (Model.unlinkGroup s g) z = if z = g ∧ g < s.Gs.size then Model.NIL else if z = gP s g ∧ gP s g ≠ Model.NIL ∧ gP s g < s.Gs.size then gN s g else gN s z
theorem OrderMaintenance.Proof.unlinkGroup_gP {s : Model.Core} {g : ℕ} (hng : gN s g ≠ g) (z : ℕ) :
gP (Model.unlinkGroup s g) z = if z = g ∧ g < s.Gs.size then Model.NIL else if z = gN s g ∧ gN s g ≠ Model.NIL ∧ gN s g < s.Gs.size then gP s g else gP s z
theorem OrderMaintenance.Proof.unlinkGroup_C {s : Model.Core} {g : ℕ} (z : ℕ) (hc : gC s g < s.C.size) :
(Model.unlinkGroup s g).C.getX z = if z = gC s g then have __src := s.C.getX z; { next := __src.next, prev := __src.prev, first := if cF s (gC s g) = g ∧ cLs s (gC s g) = g then Model.NIL else if cF s (gC s g) = g then gN s g else cF s (gC s g), last := if cF s (gC s g) = g ∧ cLs s (gC s g) = g then Model.NIL else if cF s (gC s g) = g then cLs s (gC s g) else if cLs s (gC s g) = g then gP s g else cLs s (gC s g), size := __src.size, st := __src.st, src := __src.src, l := __src.l, r := __src.r, tag := __src.tag, alive := __src.alive } else s.C.getX z

The abstract nesting without group g (in chunk c).

Equations
Instances For
    theorem OrderMaintenance.Proof.isChain_erase {l1 l2 : List ℕ} {x : ℕ} {f : ℕ → ℕ} (hs : List.IsChain (fun (x1 x2 : ℕ) => x1 < x2) (List.map f (l1 ++ x :: l2))) :
    List.IsChain (fun (x1 x2 : ℕ) => x1 < x2) (List.map f (l1 ++ l2))
    theorem OrderMaintenance.Proof.mem_erase_mid {l1 l2 : List ℕ} {x z : ℕ} :
    z ∈ l1 ++ l2 → z ∈ l1 ++ x :: l2
    theorem OrderMaintenance.Proof.unlinkGroup_chunkEnds {s : Model.Core} {A : Abs} (hI : INV s A) {g : ℕ} (hg : g ∈ A.glist) (c' : ℕ) :
    c' ∈ A.chunks → Ends (cF (Model.unlinkGroup s g) c') (cLs (Model.unlinkGroup s g) c') ((A.removeGroup (gC s g) g).grps c')

    Removing a group updates the ends of its chunk to the neighbouring groups.

    theorem OrderMaintenance.Proof.removeGroup_glist_split {s : Model.Core} {A : Abs} (hI : INV s A) {c g : ℕ} (hc : c ∈ A.chunks) (hgc : g ∈ A.grps c) {l1 l2 : List ℕ} (hsplit : A.glist = l1 ++ g :: l2) :
    (A.removeGroup c g).glist = l1 ++ l2 ∧ ∀ (z : ℕ), z ∈ (A.removeGroup c g).glist ↔ z ≠ g ∧ z ∈ A.glist

    Flattening the abstract nesting after deleting one group removes exactly that group.

    Removing an empty group preserves INV-S.

    Moving one element to a sibling #

    theorem OrderMaintenance.Proof.moveFirstLeft_E {s : Model.Core} {g gl e lab : ℕ} :
    (Model.moveFirstLeft s g gl e lab).E = s.E.modify e fun (X : Model.Elem) => { next := X.next, prev := X.prev, grp := gl, lab := lab, live := X.live, h := X.h }
    theorem OrderMaintenance.Proof.moveFirstLeft_gF {s : Model.Core} {g gl e lab : ℕ} (hgl : gl ≠ g) (hg : g < s.Gs.size) (hl : gl < s.Gs.size) (z : ℕ) :
    gF (Model.moveFirstLeft s g gl e lab) z = if z = gl then if gF s gl = Model.NIL then e else gF s gl else if z = g then if gF s g = gLs s g then Model.NIL else eN s e else gF s z
    theorem OrderMaintenance.Proof.moveFirstLeft_gLs {s : Model.Core} {g gl e lab : ℕ} (hgl : gl ≠ g) (hg : g < s.Gs.size) (hl : gl < s.Gs.size) (z : ℕ) :
    gLs (Model.moveFirstLeft s g gl e lab) z = if z = gl then e else if z = g then if gF s g = gLs s g then Model.NIL else gLs s g else gLs s z
    theorem OrderMaintenance.Proof.moveFirstLeft_same {s : Model.Core} {g gl e lab : ℕ} :
    (∀ (z : ℕ), gN (Model.moveFirstLeft s g gl e lab) z = gN s z) ∧ (∀ (z : ℕ), gP (Model.moveFirstLeft s g gl e lab) z = gP s z) ∧ (∀ (z : ℕ), gC (Model.moveFirstLeft s g gl e lab) z = gC s z) ∧ (∀ (z : ℕ), gL (Model.moveFirstLeft s g gl e lab) z = gL s z) ∧ (∀ (z : ℕ), gA (Model.moveFirstLeft s g gl e lab) z = gA s z) ∧ (Model.moveFirstLeft s g gl e lab).Gs.size = s.Gs.size ∧ (∀ (z : ℕ), eN (Model.moveFirstLeft s g gl e lab) z = eN s z) ∧ (∀ (z : ℕ), eP (Model.moveFirstLeft s g gl e lab) z = eP s z) ∧ (∀ (z : ℕ), ((Model.moveFirstLeft s g gl e lab).E.getX z).live = (s.E.getX z).live) ∧ (∀ (z : ℕ), ((Model.moveFirstLeft s g gl e lab).E.getX z).h = (s.E.getX z).h) ∧ (Model.moveFirstLeft s g gl e lab).E.size = s.E.size ∧ (Model.moveFirstLeft s g gl e lab).C = s.C ∧ (Model.moveFirstLeft s g gl e lab).freeG = s.freeG ∧ (Model.moveFirstLeft s g gl e lab).head = s.head ∧ (Model.moveFirstLeft s g gl e lab).tail = s.tail ∧ (Model.moveFirstLeft s g gl e lab).firstGroup = s.firstGroup ∧ (Model.moveFirstLeft s g gl e lab).firstChunk = s.firstChunk
    theorem OrderMaintenance.Proof.moveFirstLeft_eG {s : Model.Core} {g gl e lab : ℕ} (z : ℕ) :
    eG (Model.moveFirstLeft s g gl e lab) z = if z = e ∧ e < s.E.size then gl else eG s z
    theorem OrderMaintenance.Proof.moveFirstLeft_eL {s : Model.Core} {g gl e lab : ℕ} (z : ℕ) :
    eL (Model.moveFirstLeft s g gl e lab) z = if z = e ∧ e < s.E.size then lab else eL s z
    theorem OrderMaintenance.Proof.INV.mem_of_gN {s : Model.Core} {A : Abs} (h : INV s A) {a b : ℕ} (hab : gN s a = b) (hb : b ≠ Model.NIL) :
    theorem OrderMaintenance.Proof.INV.mem_of_gP {s : Model.Core} {A : Abs} (h : INV s A) {a b : ℕ} (hab : gP s a = b) (hb : b ≠ Model.NIL) :
    theorem OrderMaintenance.Proof.INV.run_nodup {s : Model.Core} {A : Abs} (h : INV s A) {g : ℕ} (hg : g ∈ A.glist) :
    (A.elts g).Nodup
    theorem OrderMaintenance.Proof.INV.runs_disjoint {s : Model.Core} {A : Abs} (h : INV s A) {g g' e : ℕ} (hg : g ∈ A.glist) (hg' : g' ∈ A.glist) (he : e ∈ A.elts g) (he' : e ∈ A.elts g') :
    g = g'
    theorem OrderMaintenance.Proof.inv_moveFirstLeft {s : Model.Core} {A : Abs} (hI : INV s A) {g gl lab : ℕ} (hg : g ∈ A.glist) (hne : gF s g ≠ Model.NIL) (hadj : gN s gl = g) (hlab : gF s gl ≠ Model.NIL → eL s (gLs s gl) < lab) :
    ∃ (A' : Abs), INV (Model.moveFirstLeft s g gl (gF s g) lab) A' ∧ A'.elist = A.elist

    Moving the first element of g to the end of the group before it preserves INV-S.

    theorem OrderMaintenance.Proof.moveLastRight_gF {s : Model.Core} {g gr e lab : ℕ} (hgr : gr ≠ g) (hg : g < s.Gs.size) (hr : gr < s.Gs.size) (z : ℕ) :
    gF (Model.moveLastRight s g gr e lab) z = if z = gr then e else if z = g then if gF s g = gLs s g then Model.NIL else gF s g else gF s z
    theorem OrderMaintenance.Proof.moveLastRight_gLs {s : Model.Core} {g gr e lab : ℕ} (hgr : gr ≠ g) (hg : g < s.Gs.size) (hr : gr < s.Gs.size) (z : ℕ) :
    gLs (Model.moveLastRight s g gr e lab) z = if z = gr then if gF s gr = Model.NIL then e else gLs s gr else if z = g then if gF s g = gLs s g then Model.NIL else eP s e else gLs s z
    theorem OrderMaintenance.Proof.moveLastRight_same {s : Model.Core} {g gr e lab : ℕ} :
    (∀ (z : ℕ), gN (Model.moveLastRight s g gr e lab) z = gN s z) ∧ (∀ (z : ℕ), gP (Model.moveLastRight s g gr e lab) z = gP s z) ∧ (∀ (z : ℕ), gC (Model.moveLastRight s g gr e lab) z = gC s z) ∧ (∀ (z : ℕ), gL (Model.moveLastRight s g gr e lab) z = gL s z) ∧ (∀ (z : ℕ), gA (Model.moveLastRight s g gr e lab) z = gA s z) ∧ (Model.moveLastRight s g gr e lab).Gs.size = s.Gs.size ∧ (∀ (z : ℕ), eN (Model.moveLastRight s g gr e lab) z = eN s z) ∧ (∀ (z : ℕ), eP (Model.moveLastRight s g gr e lab) z = eP s z) ∧ (∀ (z : ℕ), ((Model.moveLastRight s g gr e lab).E.getX z).live = (s.E.getX z).live) ∧ (∀ (z : ℕ), ((Model.moveLastRight s g gr e lab).E.getX z).h = (s.E.getX z).h) ∧ (Model.moveLastRight s g gr e lab).E.size = s.E.size ∧ (Model.moveLastRight s g gr e lab).C = s.C ∧ (Model.moveLastRight s g gr e lab).freeG = s.freeG ∧ (Model.moveLastRight s g gr e lab).head = s.head ∧ (Model.moveLastRight s g gr e lab).tail = s.tail ∧ (Model.moveLastRight s g gr e lab).firstGroup = s.firstGroup ∧ (Model.moveLastRight s g gr e lab).firstChunk = s.firstChunk
    theorem OrderMaintenance.Proof.moveLastRight_eG {s : Model.Core} {g gr e lab : ℕ} (z : ℕ) :
    eG (Model.moveLastRight s g gr e lab) z = if z = e ∧ e < s.E.size then gr else eG s z
    theorem OrderMaintenance.Proof.moveLastRight_eL {s : Model.Core} {g gr e lab : ℕ} (z : ℕ) :
    eL (Model.moveLastRight s g gr e lab) z = if z = e ∧ e < s.E.size then lab else eL s z
    theorem OrderMaintenance.Proof.INV.eP_in_run {s : Model.Core} {A : Abs} (h : INV s A) {g x : ℕ} (hg : g ∈ A.glist) (hx : x ∈ A.elts g) (hf : (A.elts g).head? ≠ some x) :
    eP s x = predOf (A.elts g) x

    In INV-S, the element before x inside its run is its predecessor in the element list.

    theorem OrderMaintenance.Proof.inv_moveLastRight {s : Model.Core} {A : Abs} (hI : INV s A) {g gr lab : ℕ} (hg : g ∈ A.glist) (hne : gF s g ≠ Model.NIL) (hadj : gP s gr = g) (hlab : gF s gr ≠ Model.NIL → lab < eL s (gF s gr)) :
    ∃ (A' : Abs), INV (Model.moveLastRight s g gr (gLs s g) lab) A' ∧ A'.elist = A.elist

    Moving the last element of g to the front of the group after it preserves INV-S.

    theorem OrderMaintenance.Proof.pres_modG (i : ℕ) (f : Model.Group → Model.Group) (hf : ∀ (X : Model.Group), (f X).next = X.next ∧ (f X).prev = X.prev ∧ (f X).first = X.first ∧ (f X).last = X.last ∧ (f X).chk = X.chk ∧ (f X).lab = X.lab ∧ (f X).alive = X.alive) :

    Updating group fields that INV-S does not read.

    theorem OrderMaintenance.Proof.good_modG_quiet (i : ℕ) :
    Good (Model.modG i fun (X : Model.Group) => { next := X.next, prev := X.prev, first := X.first, last := X.last, chk := X.chk, lab := X.lab, size := X.size, l := X.l, r := X.r, alive := X.alive })
    theorem OrderMaintenance.Proof.good_modG_dec (i : ℕ) :
    Good (Model.modG i fun (X : Model.Group) => { next := X.next, prev := X.prev, first := X.first, last := X.last, chk := X.chk, lab := X.lab, size := X.size - 1, st := X.st, src := X.src, l := X.l, r := X.r, alive := X.alive })
    theorem OrderMaintenance.Proof.good_modG_inc (i : ℕ) :
    Good (Model.modG i fun (X : Model.Group) => { next := X.next, prev := X.prev, first := X.first, last := X.last, chk := X.chk, lab := X.lab, size := X.size + 1, st := X.st, src := X.src, l := X.l, r := X.r, alive := X.alive })