Documentation

LeanPool.OrderMaintenance.Proof.Top.Labels

M5: labels in tables #

A new entry next to entry e gets the midpoint of the gap on that side (roomNextTo), and is inserted there (tableInsert). With the table split as A ++ (e, l) :: B: the run lemmas roomNextTo_run, tableInsert_run, and the gap arithmetic gapsGe_insert_before/after: if all gaps are at least B ≥ 2, the insertion succeeds and all gaps stay at least B / 2.

Chains with gaps #

theorem OrderMaintenance.Proof.Top.isChain_insert_mid {X Y : List ℕ} {p q B : ℕ} (hB : 2 ≤ B) (h : List.IsChain (fun (a b : ℕ) => a + B ≤ b) (X ++ p :: q :: Y)) :
List.IsChain (fun (a b : ℕ) => a + B / 2 ≤ b) (X ++ p :: (p + q) / 2 :: q :: Y)
theorem OrderMaintenance.Proof.Top.gapsGe_split {β B : ℕ} {A Bs : List (ℕ × ℕ)} {e le : ℕ} :
GapsGe β B (List.map (fun (x : ℕ × ℕ) => x.2) (A ++ (e, le) :: Bs)) ↔ List.IsChain (fun (a b : ℕ) => a + B ≤ b) (0 :: List.map (fun (p : ℕ × ℕ) => p.2 + 1) A ++ (le + 1) :: (List.map (fun (p : ℕ × ℕ) => p.2 + 1) Bs ++ [2 ^ β + 1]))

The shifted labels of a table, with sentinels: all gaps at least B.

Room next to an entry #

theorem OrderMaintenance.Proof.Top.findIdx_split {A Bs : List (ℕ × ℕ)} {e le : ℕ} (hA : e ∉ List.map (fun (x : ℕ × ℕ) => x.1) A) :
List.findIdx? (fun (x : ℕ × ℕ) => x.1 == e) (A ++ (e, le) :: Bs) = some A.length
theorem OrderMaintenance.Proof.Top.getD_split_left {A Bs : List (ℕ × ℕ)} {x : ℕ × ℕ} (hA : A ≠ []) :
(A ++ x :: Bs).getD (A.length - 1) (0, 0) = A.getLast hA
theorem OrderMaintenance.Proof.Top.getD_split_right {A Bs : List (ℕ × ℕ)} {x : ℕ × ℕ} (hB : Bs ≠ []) :
(A ++ x :: Bs).getD (A.length + 1) (0, 0) = Bs.head hB
def OrderMaintenance.Proof.Top.roomLo (A : List (ℕ × ℕ)) (le : ℕ) (before : Bool) :

The label roomNextTo picks before (before) or after entry e.

Equations
Instances For
    def OrderMaintenance.Proof.Top.roomHi (β : ℕ) (Bs : List (ℕ × ℕ)) (le : ℕ) (before : Bool) :

    The upper label boundary before or after an entry, with the full-width sentinel at the end.

    Equations
    Instances For
      theorem OrderMaintenance.Proof.Top.roomNextTo_run {s : Model.Core} {t e : ℕ} {A Bs : List (ℕ × ℕ)} {le : ℕ} (htab : (s.nodes.getX t).table = A ++ (e, le) :: Bs) (hA : e ∉ List.map (fun (x : ℕ × ℕ) => x.1) A) (before : Bool) (hroom : roomLo A le before < roomHi s.P.beta Bs le before) :
      EStateM.run (Model.roomNextTo t e before) s = EStateM.Result.ok ((roomLo A le before + roomHi s.P.beta Bs le before - 1) / 2) s

      Enough gap: the insertion succeeds and gaps halve at worst #

      theorem OrderMaintenance.Proof.Top.last_zero_cons_map (A : List (ℕ × ℕ)) :
      ∃ (X : List ℕ), 0 :: List.map (fun (p : ℕ × ℕ) => p.2 + 1) A = X ++ [if h : A = [] then 0 else (A.getLast h).2 + 1]
      theorem OrderMaintenance.Proof.Top.gaps_room_before {β B : ℕ} {A Bs : List (ℕ × ℕ)} {e le new : ℕ} (hB : 2 ≤ B) (hg : GapsGe β B (List.map (fun (x : ℕ × ℕ) => x.2) (A ++ (e, le) :: Bs))) :
      roomLo A le true < roomHi β Bs le true ∧ GapsGe β (B / 2) (List.map (fun (x : ℕ × ℕ) => x.2) (A ++ (new, (roomLo A le true + roomHi β Bs le true - 1) / 2) :: (e, le) :: Bs))
      theorem OrderMaintenance.Proof.Top.gaps_room_after {β B : ℕ} {A Bs : List (ℕ × ℕ)} {e le new : ℕ} (hB : 2 ≤ B) (hg : GapsGe β B (List.map (fun (x : ℕ × ℕ) => x.2) (A ++ (e, le) :: Bs))) :
      roomLo A le false < roomHi β Bs le false ∧ GapsGe β (B / 2) (List.map (fun (x : ℕ × ℕ) => x.2) (A ++ (e, le) :: (new, (roomLo A le false + roomHi β Bs le false - 1) / 2) :: Bs))

      Two new entries around one #

      theorem OrderMaintenance.Proof.Top.isChain_insert_around {X Y : List ℕ} {p r q B : ℕ} (hB : 2 ≤ B) (h : List.IsChain (fun (a b : ℕ) => a + B ≤ b) (X ++ p :: r :: q :: Y)) :
      List.IsChain (fun (a b : ℕ) => a + B / 2 ≤ b) (X ++ p :: (p + r) / 2 :: r :: (r + q) / 2 :: q :: Y)
      theorem OrderMaintenance.Proof.Top.gaps_room_around {β B : ℕ} {A Bs : List (ℕ × ℕ)} {e le y z : ℕ} (hB : 2 ≤ B) (hg : GapsGe β B (List.map (fun (x : ℕ × ℕ) => x.2) (A ++ (e, le) :: Bs))) :
      roomLo A le true < roomHi β Bs le true ∧ roomLo A le false < roomHi β Bs le false ∧ GapsGe β (B / 2) (List.map (fun (x : ℕ × ℕ) => x.2) (A ++ (y, (roomLo A le true + roomHi β Bs le true - 1) / 2) :: (e, le) :: (z, (roomLo A le false + roomHi β Bs le false - 1) / 2) :: Bs))

      Room around an entry: with all gaps at least B ≥ 2, both new labels exist, and with both new entries all gaps stay at least B / 2.

      Inserting the entry #

      The side list after an insertion next to e in table T.

      Equations
      • One or more equations did not get rendered due to their size.
      Instances For
        theorem OrderMaintenance.Proof.Top.insertIdx_len {α : Type} (A B : List α) (x y : α) :
        (A ++ y :: B).insertIdx A.length x = A ++ x :: y :: B
        theorem OrderMaintenance.Proof.Top.insertIdx_len1 {α : Type} (A B : List α) (x y : α) :
        (A ++ y :: B).insertIdx (A.length + 1) x = A ++ y :: x :: B
        def OrderMaintenance.Proof.Top.insTab (A Bs : List (ℕ × ℕ)) (e le new lab : ℕ) (before : Bool) :

        The table after inserting (new, lab) before or after the entry (e, le).

        Equations
        Instances For

          Updates a node table and its side map together.

          Equations
          • One or more equations did not get rendered due to their size.
          Instances For
            theorem OrderMaintenance.Proof.Top.tableInsert_run {s : Model.Core} {t e new : ℕ} {A Bs : List (ℕ × ℕ)} {le : ℕ} (htab : (s.nodes.getX t).table = A ++ (e, le) :: Bs) (hA : e ∉ List.map (fun (x : ℕ × ℕ) => x.1) A) (before : Bool) (lab : ℕ) (hside : (s.nodes.getX t).draining = true → (Model.lookup (s.nodes.getX t).side e).isSome = true) :
            EStateM.run (Model.tableInsert t e new before lab) s = EStateM.Result.ok PUnit.unit { P := s.P, E := s.E, Gs := s.Gs, C := s.C, freeG := s.freeG, count := s.count, head := s.head, tail := s.tail, firstGroup := s.firstGroup, firstChunk := s.firstChunk, ready := s.ready, prep := s.prep, resJob := s.resJob, fallbacks := s.fallbacks, pqHead := s.pqHead, pqNext := s.pqNext, pqPrev := s.pqPrev, pqWhere := s.pqWhere, nbNext := s.nbNext, nbPrev := s.nbPrev, pqHi := s.pqHi, pqLo := s.pqLo, nodes := s.nodes.modify t (setTS (insTab A Bs e le new lab before) (sideAfter (s.nodes.getX t) e new)), path := s.path, cin := s.cin, lpar := s.lpar }