Documentation

LeanPool.OrderMaintenance.Impl.PeakM

Theorem W, option (A), stage A1: the peak of machine code #

Tools for the machine-only code (WrapM, RebuildM, OpsM, InitM, NewCore, Params, Fresh), which runs outside the core language and so outside sim_peak.

Nothing here is used by Theorems A and B.

The peak is ghost #

Raise the peak of a state to at least q.

Equations
Instances For

    Raise an execution outcome's ghost peak bound without changing its result or cost.

    Equations
    Instances For
      theorem OrderMaintenance.Machine.State.raise_setLoc (s : State) (q : ℕ) (x : Reg) (v : ℕ) :
      (s.raise q).setLoc x v = (s.setLoc x v).raise q
      theorem OrderMaintenance.Machine.State.raise_write (s : State) (q : ℕ) (a : Arr) (j v : ℕ) :
      (s.raise q).write a j v = (s.write a j v).raise q
      theorem OrderMaintenance.Machine.State.raise_alloc (s : State) (q : ℕ) (a : Arr) (n : ℕ) :
      (s.raise q).alloc a n = (s.alloc a n).raise q
      theorem OrderMaintenance.Machine.State.raise_enter (s : State) (q : ℕ) (ps : List Reg) (vs : List ℕ) :
      (s.raise q).enter ps vs = (s.enter ps vs).raise q
      theorem OrderMaintenance.Machine.State.raise_leave (s : State) (q : ℕ) (c : Reg → ℕ) (rs ds : List Reg) :
      (s.raise q).leave c rs ds = (s.leave c rs ds).raise q
      theorem OrderMaintenance.Machine.Out.raise_bind (o : Out) (q : ℕ) (g g' : State → Out) (hg : ∀ (s : State), g (s.raise q) = (g' s).raise q) :
      (o.raise q).bind g = (o.bind g').raise q
      theorem OrderMaintenance.Machine.runFor_raise (f : State → Out) (q : ℕ) (hf : ∀ (s : State), f (s.raise q) = (f s).raise q) (x : Reg) (n k : ℕ) (s : State) :
      runFor f x k n (s.raise q) = (runFor f x k n s).raise q
      theorem OrderMaintenance.Machine.exec_raise (q : ℕ) (c : Stmt) (s : State) :
      exec c (s.raise q) = (exec c s).raise q

      The peak is ghost: running from a state with a raised peak gives the same outcome with the final peak raised the same way.

      The peak of a run from s with the peak reset: the largest value the run computes.

      Equations
      Instances For
        theorem OrderMaintenance.Machine.raise_reset (s : State) :
        { mem := s.mem, cap := s.cap, loc := s.loc, peak := 0 }.raise s.peak = s
        theorem OrderMaintenance.Machine.peak_exec (c : Stmt) (s : State) :
        (exec c s).st.peak = max s.peak (dpk c s)

        The final peak is the initial one or a value the run computes.

        theorem OrderMaintenance.Machine.exec_reset (c : Stmt) (s : State) :
        (exec c s).st.mem = (exec c { mem := s.mem, cap := s.cap, loc := s.loc, peak := 0 }).st.mem ∧ (exec c s).st.loc = (exec c { mem := s.mem, cap := s.cap, loc := s.loc, peak := 0 }).st.loc ∧ (exec c s).st.cap = (exec c { mem := s.mem, cap := s.cap, loc := s.loc, peak := 0 }).st.cap ∧ (exec c s).cost = (exec c { mem := s.mem, cap := s.cap, loc := s.loc, peak := 0 }).cost ∧ (exec c s).status = (exec c { mem := s.mem, cap := s.cap, loc := s.loc, peak := 0 }).status

        The peak never decreases.

        wp with a peak budget #

        def OrderMaintenance.Machine.wpB (B : ℕ) (c : Stmt) (Q : State → ℕ → Prop) (s : State) :

        c terminates normally from s, Q holds, and every value it computes is at most B.

        Equations
        Instances For
          theorem OrderMaintenance.Machine.wpB.wp {B : ℕ} {c : Stmt} {Q : State → ℕ → Prop} {s : State} (h : wpB B c Q s) :
          theorem OrderMaintenance.Machine.wpB.peak_le {B : ℕ} {c : Stmt} {Q : State → ℕ → Prop} {s : State} (h : wpB B c Q s) :
          (exec c s).st.peak ≤ max s.peak B

          The final peak of a run with a budget.

          theorem OrderMaintenance.Machine.wpB_mono {B B' : ℕ} {c : Stmt} {Q R : State → ℕ → Prop} {s : State} (hB : B ≤ B') (hQ : ∀ (s' : State) (n : ℕ), Q s' n → R s' n) (h : wpB B c Q s) :
          wpB B' c R s
          theorem OrderMaintenance.Machine.wpB_skip {B : ℕ} {Q : State → ℕ → Prop} {s : State} (h : Q s 1) :
          theorem OrderMaintenance.Machine.wpB_assign_g {B : ℕ} {x : Reg} {e : Expr} {Q : State → ℕ → Prop} {s : State} (v : ℕ) (he : Expr.eval s e = some v) (hB : Expr.maxv s e ≤ B) (h : ∀ (s' : State), s'.loc = State.upd s.loc x v → s'.mem = s.mem → s'.cap = s.cap → Q s' (1 + e.cost)) :
          wpB B (x ::= e) Q s
          theorem OrderMaintenance.Machine.wpB_store_g {B : ℕ} {a : Arr} {i e : Expr} {Q : State → ℕ → Prop} {s : State} (j v : ℕ) (hi : Expr.eval s i = some j) (he : Expr.eval s e = some v) (hj : j < s.cap a) (hBi : Expr.maxv s i ≤ B) (hBe : Expr.maxv s e ≤ B) (h : ∀ (s' : State), s'.loc = s.loc → s'.mem = (s.write a j v).mem → s'.cap = s.cap → Q s' (1 + i.cost + e.cost)) :
          wpB B (Stmt.store a i e) Q s
          theorem OrderMaintenance.Machine.wpB_alloc_g {B : ℕ} {a : Arr} {n : Expr} {Q : State → ℕ → Prop} {s : State} (k : ℕ) (hn : Expr.eval s n = some k) (hB : Expr.maxv s n ≤ B) (h : ∀ (s' : State), s'.loc = s.loc → s'.mem = (s.alloc a k).mem → s'.cap = (s.alloc a k).cap → Q s' (1 + n.cost)) :
          wpB B (Stmt.alloc a n) Q s
          theorem OrderMaintenance.Machine.wpB_seq {B : ℕ} {c d : Stmt} {Q : State → ℕ → Prop} {s : State} (h : wpB B c (fun (s' : State) (n : ℕ) => wpB B d (fun (s'' : State) (m : ℕ) => Q s'' (n + m)) s') s) :
          wpB B (c;; d) Q s
          theorem OrderMaintenance.Machine.wpB_ite {B : ℕ} {c : Expr} {t f : Stmt} {Q : State → ℕ → Prop} {s : State} (v : ℕ) (hc : Expr.eval s c = some v) (hB : Expr.maxv s c ≤ B) (h : wpB B (if v ≠ 0 then t else f) (fun (s' : State) (m : ℕ) => Q s' (1 + c.cost + m)) (s.bump (Expr.maxv s c))) :
          wpB B (Stmt.ite c t f) Q s
          theorem OrderMaintenance.Machine.wpB_call {B : ℕ} {nm : String} {ps rs ds : List Reg} {b : Stmt} {args : List Expr} {Q : State → ℕ → Prop} {s : State} (vs : List ℕ) (ha : evalList s args = some vs) (hB : maxvList s args ≤ B) (h : wpB B b (fun (s' : State) (m : ℕ) => Q (s'.leave s.loc rs ds) (1 + costList args + ds.length + m)) ((s.bump (maxvList s args)).enter ps vs)) :
          wpB B (Stmt.call nm ps b rs args ds) Q s
          theorem OrderMaintenance.Machine.wpB_catch_ok {B : ℕ} {c h : Stmt} {Q : State → ℕ → Prop} {s : State} (hc : wpB B c (fun (s' : State) (n : ℕ) => Q s' (1 + n)) s) :
          wpB B (c.catch h) Q s
          theorem OrderMaintenance.Machine.wpB_loop {B : ℕ} {x : Reg} {n : Expr} {b : Stmt} {Q : State → ℕ → Prop} {s : State} (N : ℕ) (I : ℕ → State → Prop) (kb : ℕ) (hn : Expr.eval s n = some N) (hB : Expr.maxv s n ≤ B) (h0 : I 0 (s.bump (Expr.maxv s n))) (hb : ∀ (k : ℕ), k < N → ∀ (s' : State), I k s' → wpB B b (fun (s'' : State) (m : ℕ) => I (k + 1) s'' ∧ m ≤ kb) (s'.setLoc x k)) (hQ : ∀ (s' : State) (c : ℕ), I N s' → c ≤ 1 + n.cost + N * (1 + kb) → Q s' c) :
          wpB B (Stmt.loop x n b) Q s

          The loop rule with a budget: the bound's peak and every iteration's within B. The invariant carries the peak bound of the states it describes.

          theorem OrderMaintenance.Machine.wpB_of_wp {B : ℕ} {c : Stmt} {Q : State → ℕ → Prop} {s : State} (h : wp c Q s) (hd : dpk c s ≤ B) :
          wpB B c Q s

          Lift a wp proof whose run computes nothing above B (dpk).

          Widths of machine expressions #

          def OrderMaintenance.Machine.Expr.wvM (Γ : Reg → ℕ) (A : Arr → ℕ) (S : ℕ) :
          Expr → ℕ

          The width of a machine expression's value: Γ x for a local, A a for a cell of array a, n for a literal, the operations as in Exp.wv.

          Equations
          Instances For
            def OrderMaintenance.Machine.Expr.wpM (Γ : Reg → ℕ) (A : Arr → ℕ) (S : ℕ) :
            Expr → ℕ

            The width of a machine expression's peak (maxv).

            Equations
            Instances For
              def OrderMaintenance.Machine.Expr.LeafB (s : State) (Γ : Reg → ℕ) (A : Arr → ℕ) (S : ℕ) :

              The leaves an expression reads are small in s: each local it reads below 2^(Γ x), each cell it loads below 2^(A a), and each shift amount at most S.

              Equations
              Instances For
                theorem OrderMaintenance.Machine.max_lt_pow2 {x y a b : ℕ} (hx : x < 2 ^ a) (hy : y < 2 ^ b) :
                max x y < 2 ^ max a b
                theorem OrderMaintenance.Machine.Expr.wdM_sound {s : State} {Γ : Reg → ℕ} {A : Arr → ℕ} {S : ℕ} (e : Expr) {v : ℕ} :
                LeafB s Γ A S e → eval s e = some v → v < 2 ^ wvM Γ A S e ∧ maxv s e < 2 ^ wpM Γ A S e

                The machine expression lemma.

                theorem OrderMaintenance.Machine.maxvList_lt {s : State} {Γ : Reg → ℕ} {A : Arr → ℕ} {S W : ℕ} {es : List Expr} {vs : List ℕ} :
                (∀ (e : Expr), e ∈ es → Expr.LeafB s Γ A S e ∧ Expr.wpM Γ A S e ≤ W) → evalList s es = some vs → maxvList s es < 2 ^ W