Documentation

LeanPool.OrderMaintenance.Proof.Correct.Insert

Element insertion preserves INV-S (Lemma 3.2, first case) #

insertElem x h either fails its label guard and changes nothing, or links a new element y right after x in x's group, with a label strictly between those of x and its successor in the group.

Reading INV-S #

theorem OrderMaintenance.Proof.INV.mem_elist {s : Model.Core} {A : Abs} (h : INV s A) {e : ℕ} (he : e ∈ A.elist) :
eG s e ∈ A.glist ∧ e ∈ A.elts (eG s e)
theorem OrderMaintenance.Proof.INV.mem_glist {s : Model.Core} {A : Abs} (h : INV s A) {g : ℕ} (hg : g ∈ A.glist) :
gC s g ∈ A.chunks ∧ g ∈ A.grps (gC s g)
theorem OrderMaintenance.Proof.Abs.elts_sub_elist (A : Abs) {g e : ℕ} (hg : g ∈ A.glist) (he : e ∈ A.elts g) :
theorem OrderMaintenance.Proof.Abs.grps_sub_glist (A : Abs) {c g : ℕ} (hc : c ∈ A.chunks) (hg : g ∈ A.grps c) :
theorem OrderMaintenance.Proof.INV.eN_in_run {s : Model.Core} {A : Abs} (h : INV s A) {g x : ℕ} (hg : g ∈ A.glist) (hx : x ∈ A.elts g) (hl : (A.elts g).getLast? ≠ some x) :
eN s x = succOf (A.elts g) x

Inside a group's run, the element after x is its successor in the run.

Lists #

theorem OrderMaintenance.Proof.isChain_insert {l1 l2 : List ℕ} {x y : ℕ} {f f' : ℕ → ℕ} (hs : List.IsChain (fun (x1 x2 : ℕ) => x1 < x2) (List.map f (l1 ++ x :: l2))) (hagree : ∀ (z : ℕ), z ∈ l1 ++ x :: l2 → f' z = f z) (hxy : f x < f' y) (hy2 : ∀ (w : ℕ), w ∈ l2.head? → f' y < f w) :
List.IsChain (fun (x1 x2 : ℕ) => x1 < x2) (List.map f' (l1 ++ x :: y :: l2))
theorem OrderMaintenance.Proof.insertAfterL_mid {l1 l2 : List ℕ} {x y : ℕ} (h : ¬x ∈ l1) :
Spec.insertAfterL x y (l1 ++ x :: l2) = l1 ++ x :: y :: l2
theorem OrderMaintenance.Proof.flatMap_insertAfter {L : List ℕ} {F F' : ℕ → List ℕ} {g x y : ℕ} (hnd : (List.flatMap F L).Nodup) (hgnd : L.Nodup) (hg : g ∈ L) (hx : x ∈ F g) (hF : ∀ (b : ℕ), F' b = if b = g then Spec.insertAfterL x y (F g) else F b) :

Linking a new element #

The abstract nesting after inserting y after x in x's group.

Equations
Instances For
    theorem OrderMaintenance.Proof.linkElem_eN (s : Model.Core) (x lab h z : ℕ) (hx : x < s.E.size) :
    eN (Model.linkElem s x s.E.size lab h) z = if z = x then s.E.size else if z = s.E.size then eN s x else eN s z
    theorem OrderMaintenance.Proof.linkElem_eP (s : Model.Core) (x lab h z : ℕ) (hx : x < s.E.size) (hns : eN s x = Model.NIL ∨ eN s x < s.E.size) :
    eP (Model.linkElem s x s.E.size lab h) z = if z = s.E.size then x else if z = eN s x ∧ eN s x ≠ Model.NIL then s.E.size else eP s z
    theorem OrderMaintenance.Proof.linkElem_eG (s : Model.Core) (x lab h z : ℕ) :
    eG (Model.linkElem s x s.E.size lab h) z = if z = s.E.size then eG s x else eG s z
    theorem OrderMaintenance.Proof.linkElem_eL (s : Model.Core) (x lab h z : ℕ) :
    eL (Model.linkElem s x s.E.size lab h) z = if z = s.E.size then lab else eL s z
    theorem OrderMaintenance.Proof.linkElem_live (s : Model.Core) (x lab h z : ℕ) :
    ((Model.linkElem s x s.E.size lab h).E.getX z).live = if z = s.E.size then true else (s.E.getX z).live
    theorem OrderMaintenance.Proof.linkElem_h (s : Model.Core) (x lab h z : ℕ) :
    ((Model.linkElem s x s.E.size lab h).E.getX z).h = if z = s.E.size then h else (s.E.getX z).h
    theorem OrderMaintenance.Proof.linkElem_groupNext (s : Model.Core) (x lab h y b : ℕ) :
    gN (Model.linkElem s x y lab h) b = gN s b
    theorem OrderMaintenance.Proof.linkElem_groupPrevious (s : Model.Core) (x lab h y b : ℕ) :
    gP (Model.linkElem s x y lab h) b = gP s b
    theorem OrderMaintenance.Proof.linkElem_groupFirst (s : Model.Core) (x lab h y b : ℕ) :
    gF (Model.linkElem s x y lab h) b = gF s b
    theorem OrderMaintenance.Proof.linkElem_groupChunk (s : Model.Core) (x lab h y b : ℕ) :
    gC (Model.linkElem s x y lab h) b = gC s b
    theorem OrderMaintenance.Proof.linkElem_groupLabel (s : Model.Core) (x lab h y b : ℕ) :
    gL (Model.linkElem s x y lab h) b = gL s b
    theorem OrderMaintenance.Proof.linkElem_groupAlive (s : Model.Core) (x lab h y b : ℕ) :
    gA (Model.linkElem s x y lab h) b = gA s b
    theorem OrderMaintenance.Proof.linkElem_groupLast (s : Model.Core) (x lab h y b : ℕ) (hg : eG s x < s.Gs.size) :
    gLs (Model.linkElem s x y lab h) b = if b = eG s x ∧ gLs s b = x then y else gLs s b
    theorem OrderMaintenance.Proof.INV.size_pos {s : Model.Core} {A : Abs} (h : INV s A) {x : ℕ} (hx : x ∈ A.elist) :
    1 ≤ x ∧ x < s.E.size
    theorem OrderMaintenance.Proof.INV.eN_mem {s : Model.Core} {A : Abs} (h : INV s A) {x : ℕ} (hx : x ∈ A.elist) :
    theorem OrderMaintenance.Proof.getLastD_split_eq_iff {l1 l2 : List ℕ} {x d : ℕ} (hnd : (l1 ++ x :: l2).Nodup) :
    (l1 ++ x :: l2).getLastD d = x ↔ l2 = []
    theorem OrderMaintenance.Proof.inv_linkElem {s : Model.Core} {A : Abs} (hI : INV s A) {x lab h : ℕ} (hx : x ∈ A.elist) (hlab1 : eL s x < lab) (hlab2 : x ≠ gLs s (eG s x) → lab < eL s (eN s x)) :
    INV (Model.linkElem s x s.E.size lab h) (A.insElem (eG s x) x s.E.size) ∧ (A.insElem (eG s x) x s.E.size).elist = Spec.insertAfterL x s.E.size A.elist

    Linking a new element preserves INV-S when its label lies above x's, and below the label of x's successor if that successor is in the same group.

    What insertElem does: it fails its label guard and changes nothing, or it links the new element E.size after x with a label above x's, and below that of x's successor unless x is its group's last element.