Documentation

LeanPool.OrderMaintenance.Proof.Top.RunIns

M5: inserting two entries around one, in every table holding it #

insertAroundIn e n1 n2 (T, a, b) puts (n1, a) right before and (n2, b) right after entry e in table T (insertAroundIn_run); over a list of distinct tables, a fold (forM_around_run). Both insertAround (new chunks) and startDrain (new targets) do this.

The side list after inserting n1, n2 around e.

Equations
  • One or more equations did not get rendered due to their size.
Instances For
    theorem OrderMaintenance.Proof.Top.lookup_map_replace {β : Type} (l : List (ℕ × β)) (k k' : ℕ) (v : β) (h : k' ≠ k) :
    Option.map (fun (x : ℕ × β) => x.2) (List.find? (fun (x : ℕ × β) => x.1 == k') (List.map (fun (p : ℕ × β) => if (p.1 == k) = true then (k, v) else p) l)) = Option.map (fun (x : ℕ × β) => x.2) (List.find? (fun (x : ℕ × β) => x.1 == k') l)
    theorem OrderMaintenance.Proof.Top.lookup_append_cons_self {β : Type} {A R : List (ℕ × β)} {k : ℕ} {v : β} (hA : k ∉ List.map (fun (x : ℕ × β) => x.1) A) :
    Model.lookup (A ++ (k, v) :: R) k = some v
    theorem OrderMaintenance.Proof.Top.lookup_around {β : Type} (A B : List (ℕ × β)) {k y z x : ℕ} {a le b : β} (hy : k ≠ y) (hz : k ≠ z) :
    Model.lookup (A ++ (y, a) :: (x, le) :: (z, b) :: B) k = Model.lookup (A ++ (x, le) :: B) k
    theorem OrderMaintenance.Proof.Top.idx?_getD_map {l : List ℕ} {a i : ℕ} (h : l.idx? a = some i) (g : ℕ → ℕ) :
    (List.map g l).getD i 0 = g a
    theorem OrderMaintenance.Proof.Top.lookup_assocSet_ne {β : Type} (l : List (ℕ × β)) (k k' : ℕ) (v : β) (h : k' ≠ k) :
    def OrderMaintenance.Proof.Top.aroundTab (A Bs : List (ℕ × ℕ)) (e le n1 n2 a b : ℕ) :

    The table of T after insertAroundIn.

    Equations
    Instances For
      theorem OrderMaintenance.Proof.Top.insertAroundIn_run {s : Model.Core} {e n1 n2 T a b : ℕ} {A Bs : List (ℕ × ℕ)} {le : ℕ} (htab : (s.nodes.getX T).table = A ++ (e, le) :: Bs) (hA : e ∉ List.map (fun (x : ℕ × ℕ) => x.1) A) (hn1 : n1 ≠ e) (hside : (s.nodes.getX T).draining = true → (Model.lookup (s.nodes.getX T).side e).isSome = true) :
      EStateM.run (Model.insertAroundIn e n1 n2 (T, a, b)) 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 (aroundTab A Bs e le n1 n2 a b) (sideAround (s.nodes.getX T) e n1 n2)), path := s.path, cin := s.cin, lpar := s.lpar }
      theorem OrderMaintenance.Proof.Top.foldl_ext {α β : Type} {f g : β → α → β} (l : List α) (init : β) :
      (∀ x ∈ l, ∀ (acc : β), f acc x = g acc x) → List.foldl f init l = List.foldl g init l
      def OrderMaintenance.Proof.Top.aroundT (tab : List (ℕ × ℕ)) (e n1 n2 a b : ℕ) :

      aroundTab, computed from the table itself.

      Equations
      • One or more equations did not get rendered due to their size.
      Instances For
        theorem OrderMaintenance.Proof.Top.aroundT_eq {A Bs : List (ℕ × ℕ)} {e le n1 n2 a b : ℕ} (hA : e ∉ List.map (fun (x : ℕ × ℕ) => x.1) A) :
        aroundT (A ++ (e, le) :: Bs) e n1 n2 a b = aroundTab A Bs e le n1 n2 a b

        The update insertAroundIn makes to table T.

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

          Entry e is in table T, once (as the table's keys are distinct).

          Equations
          • One or more equations did not get rendered due to their size.
          Instances For
            theorem OrderMaintenance.Proof.Top.forM_around_run (e n1 n2 : ℕ) (f : ℕ → ℕ × ℕ) (hne : n1 ≠ e) (tbs : List ℕ) (s : Model.Core) :
            tbs.Nodup → (∀ T ∈ tbs, AroundOK s e T) → EStateM.run ((List.map (fun (T : ℕ) => (T, f T)) tbs).forM (Model.insertAroundIn e n1 n2)) 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 := List.foldl (fun (ns : Array Model.Node) (T : ℕ) => ns.modify T (aroundF s e n1 n2 f T)) s.nodes tbs, path := s.path, cin := s.cin, lpar := s.lpar }

            Insertions around e in a list of distinct tables.

            insertAround #

            def OrderMaintenance.Proof.Top.roomL (β : ℕ) (tab : List (ℕ × ℕ)) (e : ℕ) (before : Bool) :

            The label roomNextTo picks, computed from the table.

            Equations
            • One or more equations did not get rendered due to their size.
            Instances For
              theorem OrderMaintenance.Proof.Top.roomL_eq {β : ℕ} {A Bs : List (ℕ × ℕ)} {e le : ℕ} (hA : e ∉ List.map (fun (x : ℕ × ℕ) => x.1) A) (before : Bool) :
              roomL β (A ++ (e, le) :: Bs) e before = (roomLo A le before + roomHi β Bs le before - 1) / 2

              The table of T has room on both sides of e.

              Equations
              • One or more equations did not get rendered due to their size.
              Instances For
                theorem OrderMaintenance.Proof.Top.roomNextTo_run' {s : Model.Core} {e T : ℕ} (h : RoomOK s e T) (before : Bool) :
                theorem OrderMaintenance.Proof.Top.zip_map_self {α β : Type} (l : List α) (f : α → β) :
                l.zip (List.map f l) = List.map (fun (x : α) => (x, f x)) l
                theorem OrderMaintenance.Proof.Top.insertAroundPrep_run {s : Model.Core} {x f1x i1 : ℕ} (hroom : ∀ T ∈ s.cin.getX x, RoomOK s x T) (hf1 : (s.nodes.getX ((s.path.getX x).getX 1)).lab? x = some f1x) (hi1 : (s.cin.getX x).idx? ((s.path.getX x).getX 1) = some i1) (htx : f1x ≤ (s.C.getX x).tag) (hlp : x ∈ (s.nodes.getX (s.lpar.getX x)).children) :
                have ly := List.map (fun (T : ℕ) => roomL s.P.beta (s.nodes.getX T).table x true) (s.cin.getX x); have lz := List.map (fun (T : ℕ) => roomL s.P.beta (s.nodes.getX T).table x false) (s.cin.getX x); EStateM.run (Model.insertAroundPrep x) s = EStateM.Result.ok ((s.C.getX x).tag - f1x + ly.getD i1 0, (s.C.getX x).tag - f1x + lz.getD i1 0, s.cin.getX x, ly, lz, s.lpar.getX x) s

                Running insertAroundPrep.

                joinChunk, as a state update.

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

                  The state after insertAroundFinish.

                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For
                    theorem OrderMaintenance.Proof.Top.insertAroundFinish_run {s : Model.Core} {x y z : ℕ} (g1 g2 : ℕ → ℕ) (hyx : y ≠ x) (hnd : (s.cin.getX x).Nodup) (hok : ∀ T ∈ s.cin.getX x, AroundOK s x T) :
                    EStateM.run (Model.insertAroundFinish x y z (s.cin.getX x) (List.map g1 (s.cin.getX x)) (List.map g2 (s.cin.getX x)) (s.lpar.getX x)) s = EStateM.Result.ok { x := x, y := y, z := z, pc := Model.JobPc.copy 1 } (insFinS s x y z fun (T : ℕ) => (g1 T, g2 T))

                    The tags written by insertAround.

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

                      The tag assigned to the new chunk immediately after the split chunk.

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

                        The core after both tag writes.

                        Equations
                        • One or more equations did not get rendered due to their size.
                        Instances For
                          theorem OrderMaintenance.Proof.Top.insertAround_run {s : Model.Core} {x y z f1x i1 : ℕ} (hroom : ∀ T ∈ s.cin.getX x, RoomOK s x T) (hnd : (s.cin.getX x).Nodup) (hyx : y ≠ x) (hf1 : (s.nodes.getX ((s.path.getX x).getX 1)).lab? x = some f1x) (hi1 : (s.cin.getX x).idx? ((s.path.getX x).getX 1) = some i1) (htx : f1x ≤ (s.C.getX x).tag) (hlp : x ∈ (s.nodes.getX (s.lpar.getX x)).children) (hgy : TagOK s y (tagY s x f1x i1)) (hgz : TagOK { P := s.P, E := s.E, Gs := s.Gs, C := s.C.modify y fun (C : Model.Chunk) => { next := C.next, prev := C.prev, first := C.first, last := C.last, size := C.size, st := C.st, src := C.src, l := C.l, r := C.r, tag := tagY s x f1x i1, alive := C.alive }, 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, path := s.path, cin := s.cin, lpar := s.lpar } z (tagZ s x f1x i1)) :
                          EStateM.run (Model.insertAround x y z) s = EStateM.Result.ok { x := x, y := y, z := z, pc := Model.JobPc.copy 1 } (insFinS (tagsS s y z (tagY s x f1x i1) (tagZ s x f1x i1)) x y z fun (T : ℕ) => (roomL s.P.beta (s.nodes.getX T).table x true, roomL s.P.beta (s.nodes.getX T).table x false))

                          Running insertAround.