Documentation

LeanPool.OrderMaintenance.Impl.Peak

Theorem W, option (A), stage A1: the peak of the core language #

The machine records the largest value it computes (State.peak, raised by bump with Expr.maxv at every evaluated expression). sim (Sim.lean) says nothing about it. This file computes the same quantity on Level F, without running the machine (docs/WORD.md §4, approach (i′)):

Nothing here is used by Theorems A and B.

Expressions #

def OrderMaintenance.Impl.Exp.val (κ : Caps) (s : Model.Core) (L : Loc) (e : Exp) :

The value of an expression, 0 if it does not evaluate.

Equations
Instances For

    The peak of the compiled row width H + 1 (it reads parameter 15 and adds 1).

    Equations
    Instances For
      def OrderMaintenance.Impl.pkList (κ : Caps) (s : Model.Core) (L : Loc) (es : List Exp) :

      The peak of an argument list (maxvList of the compiled list).

      Equations
      Instances For
        theorem OrderMaintenance.Impl.Exp.val_of {κ : Caps} {s : Model.Core} {L : Loc} {e : Exp} {v : ℕ} (h : ev κ s L e = some v) :
        val κ s L e = v
        theorem OrderMaintenance.Impl.Exp.val_le_pk (κ : Caps) (s : Model.Core) (L : Loc) (e : Exp) :
        val κ s L e ≤ pk κ s L e

        The peak bounds the value.

        theorem OrderMaintenance.Impl.Exp.le_pk {κ : Caps} {s : Model.Core} {L : Loc} {e : Exp} {v : ℕ} (h : ev κ s L e = some v) :
        v ≤ pk κ s L e
        theorem OrderMaintenance.Impl.Exp.maxv_compile {p : ℕ} {κ : Caps} {s : Model.Core} {m : Machine.State} {L : Loc} (h : Enc p κ s m) (hL : m.loc = L) (e : Exp) {v : ℕ} :
        ev κ s L e = some v → Machine.Expr.maxv m (compile p κ e) = pk κ s L e

        pk is the machine's maxv of the compiled expression, whenever the expression evaluates.

        theorem OrderMaintenance.Impl.maxvList_compile {p : ℕ} {κ : Caps} {s : Model.Core} {m : Machine.State} {L : Loc} (h : Enc p κ s m) (hL : m.loc = L) (es : List Exp) {vs : List ℕ} :
        evList κ s L es = some vs → Machine.maxvList m (List.map (Exp.compile p κ) es) = pkList κ s L es

        Statements #

        def OrderMaintenance.Impl.lidxPk (κ : Caps) (s : Model.Core) (L : Loc) (k : LK) (i j : Exp) :

        The peak of the compiled index i·stride + j of list k (as in .lrd and .lwr).

        Equations
        • One or more equations did not get rendered due to their size.
        Instances For
          def OrderMaintenance.Impl.pidxPk (κ : Caps) (s : Model.Core) (L : Loc) (px x : ℕ) (j : Exp) :

          The peak of the compiled path index x·(H+1) + j, where px is the peak and x the value of the row expression (as in .prd, .pwr and .prepPath).

          Equations
          • One or more equations did not get rendered due to their size.
          Instances For
            def OrderMaintenance.Impl.pkFor (f : Model.Core → Loc → Res) (g : Model.Core → Loc → ℕ) (x : Machine.Reg) :
            ℕ → ℕ → Model.Core → Loc → ℕ

            The peak of iterations k, …, k+n-1 of a loop whose body runs as f with peak g (mirrors runForF).

            Equations
            Instances For

              The peak of a run of the core language: the largest pk of every expression that the compiled code evaluates, following evalF's run (sim_peak, PeakSim.lean).

              Equations
              Instances For

                Rules for bounding pkF (stage A2 follows the agreement proofs with these) #

                theorem OrderMaintenance.Impl.pkF_seq_ok {κ : Caps} {s s1 : Model.Core} {L L1 : Loc} {A B : Stm} {c1 : ℕ} (h : evalF κ A s L = Res.ok s1 L1 c1) :
                pkF κ (A;; B) s L = max (pkF κ A s L) (pkF κ B s1 L1)
                theorem OrderMaintenance.Impl.pkF_seq_le {κ : Caps} {s s1 : Model.Core} {L L1 : Loc} {A B : Stm} {c1 W : ℕ} (h : evalF κ A s L = Res.ok s1 L1 c1) (hA : pkF κ A s L ≤ W) (hB : pkF κ B s1 L1 ≤ W) :
                pkF κ (A;; B) s L ≤ W
                theorem OrderMaintenance.Impl.pkF_seq_fail {κ : Caps} {s s1 : Model.Core} {L L1 : Loc} {A B : Stm} {c1 : ℕ} (h : evalF κ A s L = Res.fail s1 L1 c1) :
                pkF κ (A;; B) s L = pkF κ A s L
                theorem OrderMaintenance.Impl.pkF_assign {κ : Caps} {s : Model.Core} {L : Loc} {x : Machine.Reg} {e : Exp} :
                pkF κ (x ::= e) s L = Exp.pk κ s L e
                theorem OrderMaintenance.Impl.pkF_ite {κ : Caps} {s : Model.Core} {L : Loc} {c : Exp} {t f : Stm} {v : ℕ} (hc : Exp.ev κ s L c = some v) :
                pkF κ (Stm.ite c t f) s L = max (Exp.pk κ s L c) (if v ≠ 0 then pkF κ t s L else pkF κ f s L)
                theorem OrderMaintenance.Impl.pkF_call {κ : Caps} {s : Model.Core} {L : Loc} {q : Proc} {args : List Exp} {ds : List Machine.Reg} {vs : List ℕ} (ha : evList κ s L args = some vs) :
                pkF κ (q.call args ds) s L = max (pkList κ s L args) (pkF κ q.body s (Machine.State.setLocs (fun (x : Machine.Reg) => 0) q.params vs))
                theorem OrderMaintenance.Impl.pkF_catch_ok {κ : Caps} {s s1 : Model.Core} {L L1 : Loc} {c h : Stm} {c1 : ℕ} (hc : evalF κ c s L = Res.ok s1 L1 c1) :
                pkF κ (c.catch h) s L = pkF κ c s L
                theorem OrderMaintenance.Impl.pkF_catch_fail {κ : Caps} {s s1 : Model.Core} {L L1 : Loc} {c h : Stm} {c1 : ℕ} (hc : evalF κ c s L = Res.fail s1 L1 c1) :
                pkF κ (c.catch h) s L = max (pkF κ c s L) (pkF κ h s1 L1)
                theorem OrderMaintenance.Impl.pkFor_le {κ : Caps} {b : Stm} {x : Machine.Reg} {W : ℕ} (I : ℕ → Model.Core → Loc → Prop) (hb : ∀ (k : ℕ) (s : Model.Core) (L : Loc), I k s L → pkF κ b s (Machine.State.upd L x k) ≤ W ∧ ∀ (s' : Model.Core) (L' : Loc) (c : ℕ), evalF κ b s (Machine.State.upd L x k) = Res.ok s' L' c → I (k + 1) s' L') (n k : ℕ) (s : Model.Core) (L : Loc) :
                I k s L → pkFor (evalF κ b) (pkF κ b) x k n s L ≤ W

                The loop rule: an invariant I k before iteration k under which the body's peak is at most W and which a normal end of the body passes on.

                theorem OrderMaintenance.Impl.pkF_loop_le {κ : Caps} {s : Model.Core} {L : Loc} {x : Machine.Reg} {n : Exp} {b : Stm} {N W : ℕ} (hn : Exp.ev κ s L n = some N) (hW : Exp.pk κ s L n ≤ W) (I : ℕ → Model.Core → Loc → Prop) (h0 : I 0 s L) (hb : ∀ (k : ℕ) (s : Model.Core) (L : Loc), I k s L → pkF κ b s (Machine.State.upd L x k) ≤ W ∧ ∀ (s' : Model.Core) (L' : Loc) (c : ℕ), evalF κ b s (Machine.State.upd L x k) = Res.ok s' L' c → I (k + 1) s' L') :
                pkF κ (Stm.loop x n b) s L ≤ W