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 #
Lists #
theorem
OrderMaintenance.Proof.insertAfterL_append
(x y : ℕ)
(a b : List ℕ)
:
Spec.insertAfterL x y (a ++ b) = if x ∈ a then Spec.insertAfterL x y a ++ b else a ++ Spec.insertAfterL x y b
Linking a new element #
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))
:
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.
theorem
OrderMaintenance.Proof.insertElem_run
(s : Model.Core)
(x hh : ℕ)
:
(∃ (lab : ℕ), eL s x < lab ∧ (x ≠ gLs s (eG s x) → lab < eL s (eN s x)) ∧ EStateM.run (Model.insertElem x hh) s = EStateM.Result.ok s.E.size (Model.linkElem s x s.E.size lab hh)) ∨ ∃ (msg : String), EStateM.run (Model.insertElem x hh) s = EStateM.Result.error (Model.Err.guard msg) s
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.