Reasoning about Level F code #
Result.state: the state anEStateMcomputation ends in, whether it succeeds or throws.Pres R m: every run ofmends in a state related to its start state byR. For a reflexive, transitiveRthis composes through the wholedo-notation; the tacticpresdecomposes a computation into its primitive state updates.- Shared total-map array facts are reexported from
ArrayLemmas.
Results #
Recover the reached state from a successful or failed state-monad result.
Equations
Instances For
@[simp]
@[simp]
run lemmas #
@[simp]
@[simp]
@[simp]
@[simp]
@[simp]
theorem
OrderMaintenance.Proof.run_modifyGet
{α : Type}
(f : Model.Core → α × Model.Core)
(s : Model.Core)
:
@[simp]
@[simp]
@[simp]
theorem
OrderMaintenance.Proof.run_ite
{α : Type}
{c : Prop}
[Decidable c]
(a b : Model.CM α)
(s : Model.Core)
:
theorem
OrderMaintenance.Proof.run_bind
{α β : Type}
(m : Model.CM α)
(f : α → Model.CM β)
(s : Model.Core)
:
EStateM.run (m >>= f) s = match EStateM.run m s with
| EStateM.Result.ok a s' => EStateM.run (f a) s'
| EStateM.Result.error e s' => EStateM.Result.error e s'
Frame preservation #
Every run of m ends, normally or by a failed guard, in a state related to its start state
by R; and m never hits Err.bug.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A preorder on states, for Pres.
- refl (s : Model.Core) : R s s
- trans (s t u : Model.Core) : R s t → R t u → R s u
Instances
theorem
OrderMaintenance.Proof.Pres.pure
{R : Model.Core → Model.Core → Prop}
[IsPre R]
{α : Type}
(a : α)
:
theorem
OrderMaintenance.Proof.Pres.guard
{R : Model.Core → Model.Core → Prop}
[IsPre R]
{α : Type}
(msg : String)
:
Pres R (Model.guard msg)
theorem
OrderMaintenance.Proof.Pres.modify
{R : Model.Core → Model.Core → Prop}
{f : Model.Core → Model.Core}
(h : ∀ (s : Model.Core), R s (f s))
:
Pres R (_root_.modify f)
theorem
OrderMaintenance.Proof.Pres.modifyGet
{R : Model.Core → Model.Core → Prop}
{α : Type}
{f : Model.Core → α × Model.Core}
(h : ∀ (s : Model.Core), R s (f s).snd)
:
Pres R (MonadState.modifyGet f)
theorem
OrderMaintenance.Proof.Pres.bind
{R : Model.Core → Model.Core → Prop}
[IsPre R]
{α β : Type}
{m : Model.CM α}
{f : α → Model.CM β}
(hm : Pres R m)
(hf : ∀ (a : α), Pres R (f a))
:
theorem
OrderMaintenance.Proof.Pres.ite
{R : Model.Core → Model.Core → Prop}
{α : Type}
{c : Prop}
[Decidable c]
{a b : Model.CM α}
(ha : Pres R a)
(hb : Pres R b)
:
theorem
OrderMaintenance.Proof.Pres.forIn_list
{R : Model.Core → Model.Core → Prop}
[IsPre R]
{β γ : Type}
(l : List γ)
(b : β)
{f : γ → β → Model.CM (ForInStep β)}
(hf : ∀ (x : γ) (b : β), Pres R (f x b))
:
theorem
OrderMaintenance.Proof.Pres.mapM_list
{R : Model.Core → Model.Core → Prop}
[IsPre R]
{γ δ : Type}
(l : List γ)
{f : γ → Model.CM δ}
(hf : ∀ (x : γ), Pres R (f x))
:
theorem
OrderMaintenance.Proof.Pres.forM_list
{R : Model.Core → Model.Core → Prop}
[IsPre R]
{γ : Type}
(l : List γ)
{f : γ → Model.CM PUnit}
(hf : ∀ (x : γ), Pres R (f x))
:
theorem
OrderMaintenance.Proof.Pres.forIn_array
{R : Model.Core → Model.Core → Prop}
[IsPre R]
{β γ : Type}
(a : Array γ)
(b : β)
{f : γ → β → Model.CM (ForInStep β)}
(hf : ∀ (x : γ) (b : β), Pres R (f x b))
:
theorem
OrderMaintenance.Proof.Pres.mono
{R : Model.Core → Model.Core → Prop}
{α : Type}
{R' : Model.Core → Model.Core → Prop}
{m : Model.CM α}
(h : Pres R m)
(hR : ∀ (s t : Model.Core), R s t → R' s t)
:
Pres R' m
Decompose a computation into primitive state updates, using the given lemmas for calls.
Leaves goals of the form ∀ s, R s (f s) for the updates.
Equations
- One or more equations did not get rendered due to their size.
Instances For
run of reads followed by a continuation #
theorem
OrderMaintenance.Proof.run_get_bind
{β : Type}
(s : Model.Core)
(k : Model.Core → Model.CM β)
:
theorem
OrderMaintenance.Proof.run_modify_bind
{β : Type}
(s : Model.Core)
(g : Model.Core → Model.Core)
(k : PUnit → Model.CM β)
:
theorem
OrderMaintenance.Proof.run_getE_bind
{β : Type}
(s : Model.Core)
(i : Nat)
(k : Model.Elem → Model.CM β)
:
theorem
OrderMaintenance.Proof.run_getG_bind
{β : Type}
(s : Model.Core)
(i : Nat)
(k : Model.Group → Model.CM β)
:
theorem
OrderMaintenance.Proof.run_getC_bind
{β : Type}
(s : Model.Core)
(i : Nat)
(k : Model.Chunk → Model.CM β)
:
theorem
OrderMaintenance.Proof.run_getP_bind
{β : Type}
(s : Model.Core)
(k : Model.Params → Model.CM β)
:
theorem
OrderMaintenance.Proof.run_pure_bind
{β : Type}
(s : Model.Core)
{α : Type}
(a : α)
(k : α → Model.CM β)
:
@[simp]
theorem
OrderMaintenance.Proof.run_map_guard
{β : Type}
(s : Model.Core)
{γ : Type}
(g : γ → β)
(msg : String)
:
theorem
OrderMaintenance.Proof.run_between
(s : Model.Core)
(a b : Nat)
(why : String)
:
EStateM.run (Model.between a b why) s = if a + 1 ≥ b then EStateM.Result.error (Model.Err.guard why) s else EStateM.Result.ok ((a + b) / 2) s
theorem
OrderMaintenance.Proof.run_after
(s : Model.Core)
(a D B : Nat)
(why : String)
:
EStateM.run (Model.after a D B why) s = if a + D ≥ 1 <<< B ∨ a + D ≤ a then EStateM.Result.error (Model.Err.guard why) s else EStateM.Result.ok (a + D) s
theorem
OrderMaintenance.Proof.run_before
(s : Model.Core)
(b D : Nat)
(why : String)
:
EStateM.run (Model.before b D why) s = if b < D ∨ D = 0 then EStateM.Result.error (Model.Err.guard why) s else EStateM.Result.ok (b - D) s