Documentation

LeanPool.OrderMaintenance.Impl.Cut

M6: startDrain's cut (drainCut) as loops #

Each loop of drainCutP only changes locals; its result is a fold over the iterations, and the lemmas here identify those folds with List.sum, cutLen, shiftR and shiftL.

The folds #

theorem OrderMaintenance.Impl.foldl_sum (w : ℕ → ℕ) (l : List ℕ) (a : ℕ) :
List.foldl (fun (a j : ℕ) => a + w j) a l = a + (List.map w l).sum

One step of the greedy cut: count cnt, remaining budget b, and a stop flag.

Equations
Instances For
    def OrderMaintenance.Impl.shRStep (pr : ℕ → Bool) (n : ℕ) (st : ℕ × ℕ) :

    One step of shiftR (the iteration number is not used).

    Equations
    Instances For
      theorem OrderMaintenance.Impl.foldl_shRStep_stop (pr : ℕ → Bool) (n : ℕ) (l : List ℕ) (k : ℕ) :
      List.foldl (fun (st : ℕ × ℕ) (x : ℕ) => shRStep pr n st) (k, 1) l = (k, 1)
      theorem OrderMaintenance.Impl.foldl_shRStep (pr : ℕ → Bool) (n : ℕ) (l : List ℕ) (k : ℕ) :
      (List.foldl (fun (st : ℕ × ℕ) (x : ℕ) => shRStep pr n st) (k, 0) l).1 = Model.shiftR pr n l.length k

      One step of shiftL.

      Equations
      Instances For
        theorem OrderMaintenance.Impl.foldl_shLStep_stop (pr : ℕ → Bool) (l : List ℕ) (k : ℕ) :
        List.foldl (fun (st : ℕ × ℕ) (x : ℕ) => shLStep pr st) (k, 1) l = (k, 1)
        theorem OrderMaintenance.Impl.foldl_shLStep (pr : ℕ → Bool) (l : List ℕ) (k : ℕ) :
        (List.foldl (fun (st : ℕ × ℕ) (x : ℕ) => shLStep pr st) (k, 0) l).1 = Model.shiftL pr l.length k
        theorem OrderMaintenance.Impl.range_map_getD (l : List ℕ) (g : ℕ → ℕ) {m : ℕ} (hm : m ≤ l.length) :
        List.map (fun (j : ℕ) => g (l.getD j 0)) (List.range m) = List.take m (List.map g l)

        The procedure #

        w := drainWt h e.

        Equations
        • One or more equations did not get rendered due to their size.
        Instances For
          theorem OrderMaintenance.Impl.wtS_ok {κ : Caps} {s : Model.Core} {L : Loc} {h e : ℕ} (hh : L "h" = h) (he : L "e" = e) (heN : h ≠ 1 → e < κ.tbl Tbl.N) :
          ∃ (c : ℕ), evalF κ wtS s L = Res.ok s (Machine.State.upd L "w" (Model.drainWt s.nodes h e)) c ∧ c ≤ 10

          t := the sum of the weights of the children of v``.

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

            Accumulate the weights of the first n children in local t.

            Equations
            Instances For
              theorem OrderMaintenance.Impl.sumS_ok {κ : Caps} {s : Model.Core} {L : Loc} {v h : ℕ} (hv : L "v" = v) (hh : L "h" = h) (hn : L "n" = (s.nodes.getX v).children.length) (hvr : v < κ.lrec LK.children) (hkN : h ≠ 1 → ∀ e ∈ (s.nodes.getX v).children, e < κ.tbl Tbl.N) :
              ∃ (L' : Loc) (c : ℕ), evalF κ sumS s L = Res.ok s L' c ∧ c ≤ 10 + 40 * (s.nodes.getX v).children.length ∧ L' "t" = (List.map (Model.drainWt s.nodes h) (s.nodes.getX v).children).sum ∧ ∀ (r : String), r ≠ "j" → r ≠ "e" → r ≠ "w" → r ≠ "t" → L' r = L r

              The greedy cut over the first n - 1 children, with budget t / 2.

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

                Find a weight-balanced cut before the last child.

                Equations
                • One or more equations did not get rendered due to their size.
                Instances For
                  theorem OrderMaintenance.Impl.cutS_ok {κ : Caps} {s : Model.Core} {L : Loc} {v h : ℕ} (hv : L "v" = v) (hh : L "h" = h) (hn : L "n" = (s.nodes.getX v).children.length) (hvr : v < κ.lrec LK.children) (hkN : h ≠ 1 → ∀ e ∈ (s.nodes.getX v).children, e < κ.tbl Tbl.N) :
                  ∃ (L' : Loc) (c : ℕ), evalF κ cutS s L = Res.ok s L' c ∧ c ≤ 40 + 60 * (s.nodes.getX v).children.length ∧ L' "c" = Model.cutLen (List.take ((s.nodes.getX v).children.length - 1) (List.map (Model.drainWt s.nodes h) (s.nodes.getX v).children)) (L "t" / 2) ∧ ∀ (r : String), r ≠ "j" → r ≠ "e" → r ≠ "w" → r ≠ "b" → r ≠ "c" → r ≠ "d" → L' r = L r

                  Read children k - 1 and k into a, e (for 0 < k < n).

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

                    drainPr: children a, e are targets of one drain.

                    Equations
                    • One or more equations did not get rendered due to their size.
                    Instances For
                      theorem OrderMaintenance.Impl.prS_ok {κ : Caps} {s : Model.Core} {L : Loc} {v k : ℕ} (hv : L "v" = v) (hk : L "k" = k) (hk0 : 0 < k) (hkn : k < (s.nodes.getX v).children.length) (hvr : v < κ.lrec LK.children) (hkN : ∀ e ∈ (s.nodes.getX v).children, e < κ.tbl Tbl.N) :
                      ∃ (L' : Loc) (c : ℕ), evalF κ prS s L = Res.ok s L' c ∧ c ≤ 20 ∧ Exp.ev κ s L' prE = some (if Model.drainPr s.nodes (s.nodes.getX v).children k = true then 1 else 0) ∧ ∀ (r : String), r ≠ "a" → r ≠ "e" → L' r = L r

                      shiftR: move the cut k right past pairs, at most n times.

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

                        Advance a cut right by one while the adjacent children satisfy the pair restriction.

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

                          Scan right for an admissible cut, stopping at the first rejected pair.

                          Equations
                          Instances For
                            theorem OrderMaintenance.Impl.shRS_ok {κ : Caps} {s : Model.Core} {L : Loc} {v : ℕ} (hv : L "v" = v) (hn : L "n" = (s.nodes.getX v).children.length) (hvr : v < κ.lrec LK.children) (hkN : ∀ e ∈ (s.nodes.getX v).children, e < κ.tbl Tbl.N) :
                            ∃ (L' : Loc) (c : ℕ), evalF κ shRS s L = Res.ok s L' c ∧ c ≤ 10 + 60 * (s.nodes.getX v).children.length ∧ L' "k" = Model.shiftR (Model.drainPr s.nodes (s.nodes.getX v).children) (s.nodes.getX v).children.length (s.nodes.getX v).children.length (L "k") ∧ ∀ (r : String), r ≠ "j" → r ≠ "a" → r ≠ "e" → r ≠ "k" → r ≠ "d" → L' r = L r

                            shiftL from n - 1: move the cut left past pairs, at most n times.

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

                              Advance a cut left by one while the adjacent children satisfy the pair restriction.

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

                                Scan left from the last child for an admissible cut.

                                Equations
                                • One or more equations did not get rendered due to their size.
                                Instances For
                                  theorem OrderMaintenance.Impl.shLS_ok {κ : Caps} {s : Model.Core} {L : Loc} {v : ℕ} (hv : L "v" = v) (hn : L "n" = (s.nodes.getX v).children.length) (hvr : v < κ.lrec LK.children) (hkN : ∀ e ∈ (s.nodes.getX v).children, e < κ.tbl Tbl.N) :
                                  ∃ (L' : Loc) (c : ℕ), evalF κ shLS s L = Res.ok s L' c ∧ c ≤ 40 + 60 * (s.nodes.getX v).children.length ∧ L' "k" = Model.shiftL (Model.drainPr s.nodes (s.nodes.getX v).children) (s.nodes.getX v).children.length ((s.nodes.getX v).children.length - 1) ∧ ∀ (r : String), r ≠ "j" → r ≠ "a" → r ≠ "e" → r ≠ "k" → r ≠ "d" → L' r = L r

                                  startDrain's cut: k := drainCut (children of v) … for a node v of height h.

                                  Equations
                                  • One or more equations did not get rendered due to their size.
                                  Instances For
                                    theorem OrderMaintenance.Impl.drainCutS_ok {κ : Caps} {s : Model.Core} {L : Loc} {v h : ℕ} (hv : L "v" = v) (hh : L "h" = h) (hvr : v < κ.lrec LK.children) (hkN : h ≠ 1 → ∀ e ∈ (s.nodes.getX v).children, e < κ.tbl Tbl.N) :
                                    ∃ (L' : Loc) (c : ℕ), evalF κ drainCutS s L = Res.ok s L' c ∧ c ≤ 200 + 300 * (s.nodes.getX v).children.length ∧ L' "k" = Model.drainCut (List.map (Model.drainWt s.nodes h) (s.nodes.getX v).children) (Model.drainPr s.nodes (s.nodes.getX v).children) (decide (h > 1)) ∧ ∀ (r : String), r ≠ "n" → r ≠ "j" → r ≠ "e" → r ≠ "w" → r ≠ "t" → r ≠ "b" → r ≠ "c" → r ≠ "d" → r ≠ "a" → r ≠ "k" → L' r = L r