Documentation

LeanPool.OrderMaintenance.Impl.Sim

M6: the compiled code simulates the source #

sim: if machine state m holds core s (Enc) with the same locals, then running the compiled statement on m ends exactly as evalF says: the same outcome, a machine state that holds the resulting core, the same locals, and the same number of steps. A .bug outcome promises nothing (the agreement lemmas exclude it).

@[simp]
@[simp]
@[simp]
theorem OrderMaintenance.Impl.st_write_mem (m : Machine.State) (a : Machine.Arr) (j v : ℕ) (b : Machine.Arr) :
(m.write a j v).mem b = if b = a then Machine.State.upd (m.mem a) j v else m.mem b

The encoding under machine updates #

theorem OrderMaintenance.Impl.Enc.congr {p : ℕ} {κ : Caps} {s : Model.Core} {m m' : Machine.State} (h : Enc p κ s m) (hm : m'.mem = m.mem) (hc : m'.cap = m.cap) :
Enc p κ s m'
theorem OrderMaintenance.Impl.Enc.bump {p : ℕ} {κ : Caps} {s : Model.Core} {m : Machine.State} (h : Enc p κ s m) (v : ℕ) :
Enc p κ s (m.bump v)
theorem OrderMaintenance.Impl.Enc.setLoc {p : ℕ} {κ : Caps} {s : Model.Core} {m : Machine.State} (h : Enc p κ s m) (x : Machine.Reg) (v : ℕ) :
Enc p κ s (m.setLoc x v)
theorem OrderMaintenance.Impl.Enc.withLoc {p : ℕ} {κ : Caps} {s : Model.Core} {m : Machine.State} (h : Enc p κ s m) (l : Machine.Reg → ℕ) :
Enc p κ s { mem := m.mem, cap := m.cap, loc := l, peak := m.peak }
theorem OrderMaintenance.Impl.Fld.set_prep {κ : Caps} {s s' : Model.Core} {f : Fld} {j v : ℕ} (hs : set κ s j v f = some s') :
s'.prep = s.prep

The encoding of s' holds when every array other than a is unchanged, the cores agree on everything stored outside a, and a holds what s' needs.

theorem OrderMaintenance.Impl.lt_mul_add {x y a b : ℕ} (hx : x < a) (hy : y < b) :
x * b + y < a * b
theorem OrderMaintenance.Impl.write_other {m : Machine.State} {a b : Machine.Arr} {j v i : ℕ} (h : b ≠ a) :
(m.write a j v).mem b i = m.mem b i
theorem OrderMaintenance.Impl.write_same {m : Machine.State} {a : Machine.Arr} {j v i : ℕ} :
(m.write a j v).mem a i = if i = j then v else m.mem a i
theorem OrderMaintenance.Impl.Enc.write {p : ℕ} {κ : Caps} {s s' : Model.Core} {m : Machine.State} (h : Enc p κ s m) {f : Fld} {j v : ℕ} (hs : Fld.set κ s j v f = some s') :
Enc p κ s' (m.write (arrF p f) j v)
theorem OrderMaintenance.Impl.Enc.push {p : ℕ} {κ : Caps} {s : Model.Core} {m : Machine.State} (h : Enc p κ s m) {t : Tbl} (ht : Tbl.size s t < κ.tbl t) :
Enc p κ (Tbl.push s t) (m.write (arrS p t) 0 (Tbl.size s t + 1))

Expressions #

theorem OrderMaintenance.Impl.mul_add_inj {i i' j j' w : ℕ} (hj : j < w) (hj' : j' < w) (h : i * w + j = i' * w + j') :
i = i' ∧ j = j'
theorem OrderMaintenance.Impl.Enc.stride_lt {p : ℕ} {κ : Caps} {s : Model.Core} {m : Machine.State} (h : Enc p κ s m) {k : LK} {i j : ℕ} (hi : i < κ.lrec k) (hj : j < κ.lcap k) :
i * LK.stride κ.lcap k + j < κ.lrec k * κ.lcap k
theorem OrderMaintenance.Impl.Enc.stride_inj {p : ℕ} {κ : Caps} {s : Model.Core} {m : Machine.State} (h : Enc p κ s m) {k : LK} {i i' j j' : ℕ} (hi : i < κ.lrec k) (hi' : i' < κ.lrec k) (hj : j < κ.lcap k) (hj' : j' < κ.lcap k) (e : i * LK.stride κ.lcap k + j = i' * LK.stride κ.lcap k + j') :
i = i' ∧ j = j'
theorem OrderMaintenance.Impl.Enc.rowW_eval {p : ℕ} {κ : Caps} {s : Model.Core} {m : Machine.State} (h : Enc p κ s m) :
theorem OrderMaintenance.Impl.Exp.ev_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.eval m (compile p κ e) = some v
theorem OrderMaintenance.Impl.evList_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.evalList m (List.map (Exp.compile p κ) es) = some vs

Memory reasoning on written machine states: which arrays a write changes.

Equations
Instances For

    Statements #

    Outcome r of the source and outcome o of the compiled code agree.

    Equations
    Instances For
      theorem OrderMaintenance.Impl.Agree.addCost {p : ℕ} {κ : Caps} {r : Res} {o : Machine.Out} (h : Agree p κ r o) (c : ℕ) :
      Agree p κ (Res.addCost c r) { st := o.st, cost := c + o.cost, status := o.status }
      theorem OrderMaintenance.Impl.Agree.bind {p : ℕ} {κ : Caps} {r : Res} {o : Machine.Out} (h : Agree p κ r o) {g : Model.Core → Loc → Res} {k : Machine.State → Machine.Out} (hg : ∀ (s : Model.Core) (L : Machine.Reg → ℕ) (m : Machine.State), Enc p κ s m → m.loc = L → Agree p κ (g s L) (k m)) :
      Agree p κ (r.bind g) (o.bind k)
      theorem OrderMaintenance.Impl.Enc.frame {p : ℕ} {κ : Caps} {s s' : Model.Core} {m m' : Machine.State} (h : Enc p κ s m) (hcap : m'.cap = m.cap) (hF : ∀ (f : Fld) (j : ℕ), Fld.get s' j f = Fld.get s j f) (hT : ∀ (t : Tbl), Tbl.size s' t = Tbl.size s t) (hP : s'.P = s.P) (hFm : ∀ (f : Fld), m'.mem (arrF p f) = m.mem (arrF p f)) (hSm : ∀ (t : Tbl), m'.mem (arrS p t) = m.mem (arrS p t)) (hPm : m'.mem (arrP p) = m.mem (arrP p)) (hlen : ∀ (k : LK) (i : ℕ), i < κ.lrec k → m'.mem (arrLen p k) i = (LK.view s' i k).length ∧ (LK.view s' i k).length ≤ κ.lcap k) (hlm : ∀ (k : LK) (i : ℕ), i < κ.lrec k → ∀ (j : ℕ), j < (LK.view s' i k).length → m'.mem (arrL p k false) (i * LK.stride κ.lcap k + j) = ((LK.view s' i k).getD j (0, 0)).1 ∧ m'.mem (arrL p k true) (i * LK.stride κ.lcap k + j) = ((LK.view s' i k).getD j (0, 0)).2) (hw : ∀ (c : ℕ), c < κ.tbl Tbl.C → ∀ (j : ℕ), j < κ.pw → m'.mem (arrPath p) (c * κ.pw + j) = (rowOf s' c).getX j) (ho : ∀ (o : OF), m'.mem (arrO p o) 0 = OF.get s' o) (hpc : ∀ (pr : Model.Prep), s'.prep = some pr → pr.chunk < κ.tbl Tbl.C) :
      Enc p κ s' m'

      Frame: the encoding of s' in m', from that of s in m, for the parts both keep.

      theorem OrderMaintenance.Impl.Enc.optOnly {p : ℕ} {κ : Caps} {s s' : Model.Core} {m m' : Machine.State} (h : Enc p κ s m) (hcap : m'.cap = m.cap) (hF : ∀ (f : Fld) (j : ℕ), Fld.get s' j f = Fld.get s j f) (hT : ∀ (t : Tbl), Tbl.size s' t = Tbl.size s t) (hP : s'.P = s.P) (hv : ∀ (k : LK) (i : ℕ), LK.view s' i k = LK.view s i k) (hR : ∀ (c : ℕ), c < κ.tbl Tbl.C → ∀ (j : ℕ), j < κ.pw → (rowOf s' c).getX j = (rowOf s c).getX j) (hmem : ∀ (sl : Slot), (∀ (o : OF), sl ≠ Slot.opt o) → m'.mem (arr p sl) = m.mem (arr p sl)) (ho : ∀ (o : OF), m'.mem (arrO p o) 0 = OF.get s' o) (hpc : ∀ (pr : Model.Prep), s'.prep = some pr → pr.chunk < κ.tbl Tbl.C) :
      Enc p κ s' m'

      A step that changes only the optional records, and only their cells.

      theorem OrderMaintenance.Impl.exec_st1 {m : Machine.State} {a : Machine.Arr} {e : Machine.Expr} {v : ℕ} (hc : m.cap a = 1) (he : Machine.Expr.eval m e = some v) :
      Machine.exec (st1 a e) m = { st := ((m.bump 0).bump (Machine.Expr.maxv m e)).write a 0 v, cost := 2 + e.cost, status := Machine.Status.ok }
      theorem OrderMaintenance.Impl.sim_jobClear {p : ℕ} {κ : Caps} {s : Model.Core} {L : Loc} {m : Machine.State} (h : Enc p κ s m) (hL : m.loc = L) :
      theorem OrderMaintenance.Impl.evList_cons_some {κ : Caps} {s : Model.Core} {L : Loc} {e : Exp} {es : List Exp} {v : ℕ} {vs : List ℕ} :
      evList κ s L (e :: es) = some (v :: vs) ↔ Exp.ev κ s L e = some v ∧ evList κ s L es = some vs
      theorem OrderMaintenance.Impl.pcEnc_dec {t a b c d : ℕ} {pc : Model.JobPc} (h : pcDec t a b c d = some pc) :
      pcEnc pc = (t, a, b, c, d)
      theorem OrderMaintenance.Impl.sim_jobSet {p : ℕ} {κ : Caps} {s : Model.Core} {L : Loc} {m : Machine.State} (h : Enc p κ s m) (hL : m.loc = L) (x y z t a b c d : Exp) :
      Agree p κ (evalF κ (Stm.jobSet x y z t a b c d) s L) (Machine.exec (Stm.compile p κ (Stm.jobSet x y z t a b c d)) m)
      theorem OrderMaintenance.Impl.sim_pcSet {p : ℕ} {κ : Caps} {s : Model.Core} {L : Loc} {m : Machine.State} (h : Enc p κ s m) (hL : m.loc = L) (t a b c d : Exp) :
      Agree p κ (evalF κ (Stm.pcSet t a b c d) s L) (Machine.exec (Stm.compile p κ (Stm.pcSet t a b c d)) m)
      theorem OrderMaintenance.Impl.sim_prepInit {p : ℕ} {κ : Caps} {s : Model.Core} {L : Loc} {m : Machine.State} (h : Enc p κ s m) (hL : m.loc = L) (c b : Exp) :
      Agree p κ (evalF κ (Stm.prepInit c b) s L) (Machine.exec (Stm.compile p κ (Stm.prepInit c b)) m)
      theorem OrderMaintenance.Impl.sim_prepSet {p : ℕ} {κ : Caps} {s : Model.Core} {L : Loc} {m : Machine.State} (h : Enc p κ s m) (hL : m.loc = L) (hh b t : Exp) :
      Agree p κ (evalF κ (Stm.prepSet hh b t) s L) (Machine.exec (Stm.compile p κ (Stm.prepSet hh b t)) m)
      theorem OrderMaintenance.Impl.sim_prepCommit {p : ℕ} {κ : Caps} {s : Model.Core} {L : Loc} {m : Machine.State} (h : Enc p κ s m) (hL : m.loc = L) :
      theorem OrderMaintenance.Impl.sim_pwr {p : ℕ} {κ : Caps} {s : Model.Core} {L : Loc} {m : Machine.State} (h : Enc p κ s m) (hL : m.loc = L) (c j e : Exp) :
      Agree p κ (evalF κ (Stm.pwr c j e) s L) (Machine.exec (Stm.compile p κ (Stm.pwr c j e)) m)
      theorem OrderMaintenance.Impl.sim_rowReset {p : ℕ} {κ : Caps} {s : Model.Core} {L : Loc} {m : Machine.State} (h : Enc p κ s m) (hL : m.loc = L) (c : Exp) :
      Agree p κ (evalF κ (Stm.rowReset c) s L) (Machine.exec (Stm.compile p κ (Stm.rowReset c)) m)
      theorem OrderMaintenance.Impl.sim_prepPath {p : ℕ} {κ : Caps} {s : Model.Core} {L : Loc} {m : Machine.State} (h : Enc p κ s m) (hL : m.loc = L) (j e : Exp) :
      Agree p κ (evalF κ (Stm.prepPath j e) s L) (Machine.exec (Stm.compile p κ (Stm.prepPath j e)) m)
      theorem OrderMaintenance.Impl.LK.put_prep (s : Model.Core) (i : ℕ) (l : List (ℕ × ℕ)) (k : LK) :
      (put s i l k).prep = s.prep
      theorem OrderMaintenance.Impl.Enc.listUpd {p : ℕ} {κ : Caps} {s s' : Model.Core} {m m' : Machine.State} (h : Enc p κ s m) {k : LK} {x : ℕ} {l' : List (ℕ × ℕ)} (hs : LK.set κ s x l' k = some s') (hcap : m'.cap = m.cap) (hmem : ∀ (sl : Slot), (∀ (b : Bool), sl ≠ Slot.lst k b) → sl ≠ Slot.len k → m'.mem (arr p sl) = m.mem (arr p sl)) (hlen : ∀ (i : ℕ), i ≠ x → m'.mem (arrLen p k) i = m.mem (arrLen p k) i) (hlenx : m'.mem (arrLen p k) x = l'.length) (hel : ∀ (b : Bool) (i j : ℕ), i < κ.lrec k → i ≠ x → j < κ.lcap k → m'.mem (arrL p k b) (i * LK.stride κ.lcap k + j) = m.mem (arrL p k b) (i * LK.stride κ.lcap k + j)) (helx : ∀ (j : ℕ), j < l'.length → m'.mem (arrL p k false) (x * LK.stride κ.lcap k + j) = (l'.getD j (0, 0)).1 ∧ m'.mem (arrL p k true) (x * LK.stride κ.lcap k + j) = (l'.getD j (0, 0)).2) :
      Enc p κ s' m'

      Frame for a list replacement: only list k of record x changes.

      theorem OrderMaintenance.Impl.LK.set_lrec {κ : Caps} {s s' : Model.Core} {k : LK} {x : ℕ} {l : List (ℕ × ℕ)} (hs : set κ s x l k = some s') :
      x < κ.lrec k ∧ l.length ≤ κ.lcap k
      theorem OrderMaintenance.Impl.sim_lwr {p : ℕ} {κ : Caps} {s : Model.Core} {L : Loc} {m : Machine.State} (h : Enc p κ s m) (hL : m.loc = L) (k : LK) (b : Bool) (i j e : Exp) :
      Agree p κ (evalF κ (Stm.lwr k b i j e) s L) (Machine.exec (Stm.compile p κ (Stm.lwr k b i j e)) m)
      theorem OrderMaintenance.Impl.Enc.writeBeyond {p : ℕ} {κ : Caps} {s : Model.Core} {m : Machine.State} (h : Enc p κ s m) {k : LK} {b : Bool} {x n v : ℕ} (hx : x < κ.lrec k) (hn : (LK.view s x k).length ≤ n) (hnc : n < κ.lcap k) :
      Enc p κ s (m.write (arrL p k b) (x * LK.stride κ.lcap k + n) v)

      A write past the end of a list keeps the encoding.

      theorem OrderMaintenance.Impl.exec_store_ok {m : Machine.State} {a : Machine.Arr} {i e : Machine.Expr} {j v : ℕ} (hi : Machine.Expr.eval m i = some j) (he : Machine.Expr.eval m e = some v) (hj : j < m.cap a) :
      Machine.exec (Machine.Stmt.store a i e) m = { st := ((m.bump (Machine.Expr.maxv m i)).bump (Machine.Expr.maxv m e)).write a j v, cost := 1 + i.cost + e.cost, status := Machine.Status.ok }
      theorem OrderMaintenance.Impl.out_bind_ok (st : Machine.State) (c : ℕ) (g : Machine.State → Machine.Out) :
      { st := st, cost := c, status := Machine.Status.ok }.bind g = { st := (g st).st, cost := c + (g st).cost, status := (g st).status }
      theorem OrderMaintenance.Impl.sim_lgrow {p : ℕ} {κ : Caps} {s : Model.Core} {L : Loc} {m : Machine.State} (h : Enc p κ s m) (hL : m.loc = L) (k : LK) (i a b : Exp) :
      Agree p κ (evalF κ (Stm.lgrow k i a b) s L) (Machine.exec (Stm.compile p κ (Stm.lgrow k i a b)) m)
      theorem OrderMaintenance.Impl.sim_lshrink {p : ℕ} {κ : Caps} {s : Model.Core} {L : Loc} {m : Machine.State} (h : Enc p κ s m) (hL : m.loc = L) (k : LK) (i : Exp) :
      Agree p κ (evalF κ (Stm.lshrink k i) s L) (Machine.exec (Stm.compile p κ (Stm.lshrink k i)) m)
      theorem OrderMaintenance.Impl.sim_lclear {p : ℕ} {κ : Caps} {s : Model.Core} {L : Loc} {m : Machine.State} (h : Enc p κ s m) (hL : m.loc = L) (k : LK) (i : Exp) :
      Agree p κ (evalF κ (Stm.lclear k i) s L) (Machine.exec (Stm.compile p κ (Stm.lclear k i)) m)
      theorem OrderMaintenance.Impl.Fld.set_lt {κ : Caps} {s s' : Model.Core} {f : Fld} {j v : ℕ} (h : set κ s j v f = some s') (hle : ∀ (t : Tbl), Tbl.size s t ≤ κ.tbl t) :
      j < cap κ f
      theorem OrderMaintenance.Impl.sim_runFor {p : ℕ} {κ : Caps} {b : Stm} {x : Machine.Reg} (ih : ∀ (s : Model.Core) (L : Machine.Reg → ℕ) (m : Machine.State), Enc p κ s m → m.loc = L → Agree p κ (evalF κ b s L) (Machine.exec (Stm.compile p κ b) m)) (n k : ℕ) (s : Model.Core) (L : Machine.Reg → ℕ) (m : Machine.State) :
      Enc p κ s m → m.loc = L → Agree p κ (runForF (evalF κ b) x k n s L) (Machine.runFor (Machine.exec (Stm.compile p κ b)) x k n m)
      theorem OrderMaintenance.Impl.sim {p : ℕ} {κ : Caps} (c : Stm) {s : Model.Core} {L : Loc} {m : Machine.State} :
      Enc p κ s m → m.loc = L → Agree p κ (evalF κ c s L) (Machine.exec (Stm.compile p κ c) m)

      The compiled code simulates the source, step for step.