Documentation

LeanPool.OrderMaintenance.Impl.ListLib

M6: a list library for the core language #

Procedures on list k of record i, each with its agreement lemma:

@[reducible, inline]

The key of element m of a list (0 past the end).

Equations
Instances For

    Procedure finding the first index of a key in a stored list.

    Equations
    • One or more equations did not get rendered due to their size.
    Instances For
      theorem OrderMaintenance.Impl.findIdx_key (l : List (ℕ × ℕ)) (x : ℕ) :
      (∀ m < l.length, key l m ≠ x) → List.findIdx (fun (x_1 : ℕ × ℕ) => x_1.1 == x) l = l.length
      theorem OrderMaintenance.Impl.findIdx_key_eq (l : List (ℕ × ℕ)) (x r : ℕ) (hr : r < l.length) (h1 : key l r = x) (h2 : ∀ m < r, key l m ≠ x) :
      List.findIdx (fun (x_1 : ℕ × ℕ) => x_1.1 == x) l = r
      theorem OrderMaintenance.Impl.findP_agree (κ : Caps) (k : LK) (s : Model.Core) (L : Loc) {i x : ℕ} (hi : L "i" = i) (hx : L "x" = x) (hir : i < κ.lrec k) :
      ∃ (L' : Loc) (c : ℕ), evalF κ (findP k).body s L = Res.ok s L' c ∧ L' "r" = List.findIdx (fun (x_1 : ℕ × ℕ) => x_1.1 == x) (LK.view s i k) ∧ c ≤ 20 + 20 * (LK.view s i k).length

      findP computes findIdx.

      List replacement #

      theorem OrderMaintenance.Impl.Array.ext_getX {α : Type} [Inhabited α] {a b : Array α} (h : a.size = b.size) (h2 : ∀ (j : ℕ), a.getX j = b.getX j) :
      a = b
      theorem OrderMaintenance.Impl.size_setX {α : Type} [Inhabited α] (a : Array α) (i : ℕ) (v : α) :
      (a.setX i v).size = if i < a.size then a.size else i + 1
      theorem OrderMaintenance.Impl.setX_setX {α : Type} [Inhabited α] (a : Array α) (i : ℕ) (u v : α) :
      (a.setX i u).setX i v = a.setX i v
      theorem OrderMaintenance.Impl.setX_getX {α : Type} [Inhabited α] (a : Array α) {i : ℕ} (h : i < a.size) :
      a.setX i (a.getX i) = a

      The list can be put back without change.

      Equations
      Instances For
        theorem OrderMaintenance.Impl.LK.put_put (s : Model.Core) (i : ℕ) (l1 l2 : List (ℕ × ℕ)) (k : LK) :
        put (put s i l1 k) i l2 k = put s i l2 k
        theorem OrderMaintenance.Impl.LK.put_view {s : Model.Core} {i : ℕ} {k : LK} (h : idOk s i k) :
        put s i (view s i k) k = s
        theorem OrderMaintenance.Impl.LK.valid_iff (l : List (ℕ × ℕ)) (k : LK) :
        valid l k = true ↔ ∀ q ∈ l, valid [q] k = true

        Every element of a valid list is valid on its own.

        theorem OrderMaintenance.Impl.LK.set_ok {κ : Caps} {s : Model.Core} {i : ℕ} {l : List (ℕ × ℕ)} {k : LK} (hr : recOk s i k = true) (hv : valid l k = true) (hc : l.length ≤ κ.lcap k) (hi : i < κ.lrec k) :
        set κ s i l k = some (put s i l k)
        theorem OrderMaintenance.Impl.LK.recOk_put (s : Model.Core) (i j : ℕ) (l : List (ℕ × ℕ)) (k k' : LK) :
        recOk (put s i l k) j k' = recOk s j k'

        assocSet #

        The list after j rounds of assocSetP: entries before j with key x get value y.

        Equations
        Instances For
          theorem OrderMaintenance.Impl.preSet_zero (l : List (ℕ × ℕ)) (x y : ℕ) :
          preSet l x y 0 = l
          theorem OrderMaintenance.Impl.preSet_getD {l : List (ℕ × ℕ)} {x y j : ℕ} (hj : j < l.length) :
          (preSet l x y j).getD j (0, 0) = l[j]
          theorem OrderMaintenance.Impl.preSet_succ {l : List (ℕ × ℕ)} {x y j : ℕ} (hj : j < l.length) :
          preSet l x y (j + 1) = (preSet l x y j).set j (if l[j].1 = x then (l[j].1, y) else l[j])
          theorem OrderMaintenance.Impl.preSet_len (l : List (ℕ × ℕ)) (x y : ℕ) :
          preSet l x y l.length = List.map (fun (p : ℕ × ℕ) => if p.1 = x then (p.1, y) else p) l
          theorem OrderMaintenance.Impl.assocSet_eq (l : List (ℕ × ℕ)) (x y : ℕ) :
          Model.assocSet l x y = if (l.any fun (x_1 : ℕ × ℕ) => x_1.1 == x) = true then preSet l x y l.length else l ++ [(x, y)]
          theorem OrderMaintenance.Impl.preSet_noMatch {l : List (ℕ × ℕ)} {x y : ℕ} (h : (l.any fun (x_1 : ℕ × ℕ) => x_1.1 == x) = false) :
          preSet l x y l.length = l
          theorem OrderMaintenance.Impl.valid_preSet {k : LK} {l : List (ℕ × ℕ)} {x y j : ℕ} (hl : LK.valid l k = true) (hy : ∀ (a : ℕ), LK.valid [(a, y)] k = true) :
          LK.valid (preSet l x y j) k = true

          Procedure replacing an association-list value or appending a fresh key.

          Equations
          • One or more equations did not get rendered due to their size.
          Instances For
            theorem OrderMaintenance.Impl.take_succ_any (l : List (ℕ × ℕ)) (x j : ℕ) (hj : j < l.length) :
            ((List.take (j + 1) l).any fun (x_1 : ℕ × ℕ) => x_1.1 == x) = (((List.take j l).any fun (x_1 : ℕ × ℕ) => x_1.1 == x) || l[j].1 == x)
            theorem OrderMaintenance.Impl.assocSetP_agree (κ : Caps) (k : LK) (s : Model.Core) (L : Loc) {i x y : ℕ} (hi : L "i" = i) (hx : L "x" = x) (hy : L "y" = y) (hid : LK.idOk s i k) (hr : LK.recOk s i k = true) (hir : i < κ.lrec k) (hyv : ∀ (a : ℕ), LK.valid [(a, y)] k = true) (hcap : (Model.assocSet (LK.view s i k) x y).length ≤ κ.lcap k) :
            ∃ (L' : Loc) (c : ℕ), evalF κ (assocSetP k).body s L = Res.ok (LK.put s i (Model.assocSet (LK.view s i k) x y) k) L' c ∧ c ≤ 40 + 25 * (LK.view s i k).length

            assocSetP computes assocSet.

            lookup #

            Procedure returning whether an association key exists and its stored value.

            Equations
            • One or more equations did not get rendered due to their size.
            Instances For
              theorem OrderMaintenance.Impl.lookup_findIdx (l : List (ℕ × ℕ)) (x : ℕ) :
              Model.lookup l x = if h : List.findIdx (fun (x_1 : ℕ × ℕ) => x_1.1 == x) l < l.length then some l[List.findIdx (fun (x_1 : ℕ × ℕ) => x_1.1 == x) l].2 else none
              theorem OrderMaintenance.Impl.lookupP_agree (κ : Caps) (k : LK) (s : Model.Core) (L : Loc) {i x : ℕ} (hi : L "i" = i) (hx : L "x" = x) (hir : i < κ.lrec k) :
              ∃ (L' : Loc) (c : ℕ), evalF κ (lookupP k).body s L = Res.ok s L' c ∧ (L' "f" = if (Model.lookup (LK.view s i k) x).isSome = true then 1 else 0) ∧ L' "v" = (Model.lookup (LK.view s i k) x).getD 0 ∧ L' "i" = i ∧ L' "x" = x ∧ c ≤ 60 + 20 * (LK.view s i k).length

              lookupP computes lookup.

              insertIdx #

              The list after t swaps of insertIdxP: the new element sits at position n - t.

              Equations
              Instances For
                theorem OrderMaintenance.Impl.length_bubble (l : List (ℕ × ℕ)) (x : ℕ × ℕ) (m : ℕ) (hm : m ≤ l.length) :
                (bubble l x m).length = l.length + 1
                theorem OrderMaintenance.Impl.bubble_get_lo {l : List (ℕ × ℕ)} {x : ℕ × ℕ} {m q : ℕ} (hq : q < m) (hm : m ≤ l.length) :
                (bubble l x m).getD q (0, 0) = l[q]
                theorem OrderMaintenance.Impl.bubble_get_mid {l : List (ℕ × ℕ)} {x : ℕ × ℕ} {m : ℕ} (hm : m ≤ l.length) :
                (bubble l x m).getD m (0, 0) = x
                theorem OrderMaintenance.Impl.bubble_swap {l : List (ℕ × ℕ)} {x : ℕ × ℕ} {m : ℕ} (h1 : 1 ≤ m) (hm : m ≤ l.length) :
                ((bubble l x m).set (m - 1) x).set m l[m - 1] = bubble l x (m - 1)
                theorem OrderMaintenance.Impl.insertIdx_take_drop {α : Type} (x : α) (p : ℕ) (l : List α) :
                p ≤ l.length → l.insertIdx p x = List.take p l ++ x :: List.drop p l
                theorem OrderMaintenance.Impl.bubble_insertIdx (l : List (ℕ × ℕ)) (x : ℕ × ℕ) {p : ℕ} (hp : p ≤ l.length) :
                bubble l x p = l.insertIdx p x

                Exchange the working pair with one stored list entry.

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

                  Procedure inserting a pair at a specified list index.

                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For
                    theorem OrderMaintenance.Impl.LK.valid_set {k : LK} {l : List (ℕ × ℕ)} {q : ℕ} {y : ℕ × ℕ} (hl : valid l k = true) (hy : valid [y] k = true) :
                    valid (l.set q y) k = true
                    theorem OrderMaintenance.Impl.lwr_put_ok {κ : Caps} {k : LK} {s : Model.Core} {Lc : Loc} {i y w : ℕ} {L0 : List (ℕ × ℕ)} (snd : Bool) {jx ex : Exp} (hLi : Lc "i" = i) (hj : Exp.ev κ (LK.put s i L0 k) Lc jx = some y) (he : Exp.ev κ (LK.put s i L0 k) Lc ex = some w) (hy : y < L0.length) (hr : LK.recOk s i k = true) (hir : i < κ.lrec k) (hv0 : LK.valid L0 k = true) (hvn : LK.valid [if snd = true then ((L0.getD y (0, 0)).1, w) else (w, (L0.getD y (0, 0)).2)] k = true) (hlen : L0.length ≤ κ.lcap k) :
                    evalF κ (Stm.lwr k snd (Exp.var "i") jx ex) (LK.put s i L0 k) Lc = Res.ok (LK.put s i (L0.set y (if snd = true then ((L0.getD y (0, 0)).1, w) else (w, (L0.getD y (0, 0)).2))) k) Lc (4 + 1 + jx.cost + ex.cost)

                    A component write to a list that has been put.

                    theorem OrderMaintenance.Impl.getD_set' (l : List (ℕ × ℕ)) (i j : ℕ) (a : ℕ × ℕ) :
                    (l.set i a).getD j (0, 0) = if i = j ∧ i < l.length then a else l.getD j (0, 0)
                    theorem OrderMaintenance.Impl.valid_bubble {k : LK} {l : List (ℕ × ℕ)} {x : ℕ × ℕ} {m : ℕ} (hl : LK.valid l k = true) (hx : LK.valid [x] k = true) :
                    LK.valid (bubble l x m) k = true
                    theorem OrderMaintenance.Impl.swapS_ok {κ : Caps} {k : LK} {s : Model.Core} {L : Loc} {i : ℕ} {l : List (ℕ × ℕ)} {x : ℕ × ℕ} {m t : ℕ} (hLi : L "i" = i) (hLn : L "n" = l.length) (hLt : L "t" = t) (hm : m + t = l.length) (h1 : 1 ≤ m) (hr : LK.recOk s i k = true) (hir : i < κ.lrec k) (hvl : LK.valid l k = true) (hvx : LK.valid [x] k = true) (hcap : l.length + 1 ≤ κ.lcap k) :
                    ∃ (L' : Loc) (c : ℕ), evalF κ (swapS k) (LK.put s i (bubble l x m) k) L = Res.ok (LK.put s i (bubble l x (m - 1)) k) L' c ∧ c ≤ 90 ∧ ∀ (r : String), r ≠ "q" → r ≠ "x1" → r ≠ "y1" → r ≠ "x2" → r ≠ "y2" → L' r = L r
                    theorem OrderMaintenance.Impl.insertIdxP_agree (κ : Caps) (k : LK) (s : Model.Core) (L : Loc) {i p a b : ℕ} (hi : L "i" = i) (hp : L "p" = p) (ha : L "a" = a) (hb : L "b" = b) (hr : LK.recOk s i k = true) (hir : i < κ.lrec k) (hab : LK.valid [(a, b)] k = true) (hpl : p ≤ (LK.view s i k).length) (hcap : (LK.view s i k).length + 1 ≤ κ.lcap k) :
                    ∃ (L' : Loc) (c : ℕ), evalF κ (insertIdxP k).body s L = Res.ok (LK.put s i ((LK.view s i k).insertIdx p (a, b)) k) L' c ∧ c ≤ 50 + 91 * (LK.view s i k).length

                    insertIdxP computes insertIdx.

                    Copying a list #

                    Append one entry of the source list to the destination list.

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

                      Append the source list to the destination list in list order.

                      Equations
                      • One or more equations did not get rendered due to their size.
                      Instances For
                        theorem OrderMaintenance.Impl.copyS_ok {κ : Caps} {k : LK} {s : Model.Core} {L : Loc} {a w : ℕ} (ha : L "a" = a) (hw : L "w" = w) (hne : w ≠ a) (hid : LK.idOk s w k) (hr : LK.recOk s w k = true) (hra : a < κ.lrec k) (hrw : w < κ.lrec k) (hcap : (LK.view s w k).length + (LK.view s a k).length ≤ κ.lcap k) :
                        ∃ (L' : Loc) (c : ℕ), evalF κ (copyS k) s L = Res.ok (LK.put s w (LK.view s w k ++ LK.view s a k) k) L' c ∧ c ≤ 5 + 40 * (LK.view s a k).length ∧ ∀ (r : String), r ≠ "n" → r ≠ "j" → L' r = L r

                        copyS appends list k of record a to that of record w (w ≠ a).