Built with
doc-gen4 , running Lean4.
Bubbles (
) indicate interactive fragments: hover for details, tap to reveal contents.
Use
Ctrl+โ Ctrl+โ to navigate,
Ctrl+๐ฑ๏ธ to focus.
On Mac, use
Cmd instead of
Ctrl .
import Mt.Reservation
import Mt.Task.Basic
namespace Mt.TaskM
variable { spec : Spec }
local instance : IsReservation : Type โ Type
IsReservation spec . Reservation : Spec โ Type Reservation := spec . is_reservation
/-- Validation primitive for reasoning for composable tasks.
Validation may assume `assuming` and must ensure the following:
* The task has to behave conform to the specification at all times
* The task never panics
* Finally, `motive` holds after the task completes
### Proving `valid`
The definition is rather cumbersome to work with. You should use
helper theorems like `valid_pure`, `valid_bind`, `valid_rmr`, ...
They are designed to be used with the `apply` tactic.
### Blocking predicate: `assuming`
When validating our task, we can assume `assuming state = true`. However,
in most cases we have `assuming = ฮป _ => true`, i.e. our hypothesis does
not provide anything useful.
There is one important exception: Blocking threads. If a thread
waits for a certain condition before it continues its task, we can
safely assume that this condition holds when the task is excuting.
### Final goal: `motive`
A valid thread must drop its reservations in the end. Therefore, the
final goal on those tasks is `ฮป _ r => r = IsReservation.empty`.
However, intermediate tasks (i.e. single operations) do not need to
share this goal.
In fact, they usally do not. If one operation
prepares the next operation, it usually creates some reservation to
ensure that no other thread undos this preparation. In this example,
the motive should encode that the preparation has been made.
`motive` is the only way to pass facts from one iteration to the next.
See `valid_bind` for more information.
-/
def valid : {spec : Spec } โ
{T : Type } โ
(_ : TaskM spec T ) ร' (_ : spec .Reservation ) ร' (_ : spec .State โ Bool ) ร' (T โ spec .Reservation โ Prop ) โ Prop valid { T : Type } ( p : TaskM : Spec โ Type โ Type TaskM spec T ) ( r : spec . Reservation : Spec โ Type Reservation)
( assuming : spec .State โ Bool assuming : spec . State -> Bool )
( motive : T โ spec .Reservation โ Prop
motive : T -> spec . Reservation : Spec โ Type Reservation -> Prop )
: Prop :=โ env_r s ,
assuming : spec .State โ Bool assuming s โ
spec . validate : (self : Spec ) โ self .Reservation โ self .State โ Prop validate ( env_r + r ) s โ โ r' : spec . Reservation : Spec โ Type Reservation,
match h : p . iterate s with
| IterationResult.Done : {spec : Spec } โ {T : Type } โ spec .State โ T โ IterationResult spec T IterationResult.Done s' t => spec . validate : (self : Spec ) โ self .Reservation โ self .State โ Prop validate ( env_r + r' ) s' โง motive : T โ spec .Reservation โ Prop
motive t r'
| IterationResult.Panic .. => False
| IterationResult.Running s' block_until : spec .State โ Bool block_until cont =>
spec . validate : (self : Spec ) โ self .Reservation โ self .State โ Prop validate ( env_r + r' ) s' โง
cont . valid : {T : Type } โ TaskM spec T โ spec .Reservation โ (spec .State โ Bool ) โ (T โ spec .Reservation โ Prop ) โ Prop valid r' block_until : spec .State โ Bool block_until motive : T โ spec .Reservation โ Prop
motive
termination_by valid => p
decreasing_by simp_wf spec : Spec T : Type p : TaskM spec T r : spec .Reservationassuming : spec .State โ Bool motive : T โ spec .Reservation โ Prop env_r : spec .Reservations : spec .Stater' : spec .Reservations' : spec .Stateblock_until : spec .State โ Bool cont : TaskM spec T h : iterate p s = IterationResult.Running s' block_until cont spec : Spec T : Type p : TaskM spec T r : spec .Reservationassuming : spec .State โ Bool motive : T โ spec .Reservation โ Prop env_r : spec .Reservations : spec .Stater' : spec .Reservations' : spec .Stateblock_until : spec .State โ Bool cont : TaskM spec T h : iterate p s = IterationResult.Running s' block_until cont (invImage
(fun a => PSigma.casesOn a fun p snd => PSigma.casesOn snd fun r snd => PSigma.casesOn snd fun assuming snd => p )
instWf ).1
{ fst := cont , snd := { fst := r' , snd := { fst := block_until , snd := motive } } }
{ fst := p , snd := { fst := r , snd := { fst := assuming , snd := motive } } } ; spec : Spec T : Type p : TaskM spec T r : spec .Reservationassuming : spec .State โ Bool motive : T โ spec .Reservation โ Prop env_r : spec .Reservations : spec .Stater' : spec .Reservations' : spec .Stateblock_until : spec .State โ Bool cont : TaskM spec T h : iterate p s = IterationResult.Running s' block_until cont spec : Spec T : Type p : TaskM spec T r : spec .Reservationassuming : spec .State โ Bool motive : T โ spec .Reservation โ Prop env_r : spec .Reservations : spec .Stater' : spec .Reservations' : spec .Stateblock_until : spec .State โ Bool cont : TaskM spec T h : iterate p s = IterationResult.Running s' block_until cont (invImage
(fun a => PSigma.casesOn a fun p snd => PSigma.casesOn snd fun r snd => PSigma.casesOn snd fun assuming snd => p )
instWf ).1
{ fst := cont , snd := { fst := r' , snd := { fst := block_until , snd := motive } } }
{ fst := p , snd := { fst := r , snd := { fst := assuming , snd := motive } } } exact is_direct_cont.running h
/-- To prove that `pure t` is valid you need to prove that the `motive` holds -/
theorem valid_pure : โ {T : Type } {t : T } {r : spec .Reservation } {assuming : spec .State โ Bool } {motive : T โ spec .Reservation โ Prop },
motive t r โ valid (pure t ) r assuming motive valid_pure { T : Type } { t : T } { r assuming motive }
( is_valid : motive t r )
: valid : {spec : Spec } โ
{T : Type } โ TaskM spec T โ spec .Reservation โ (spec .State โ Bool ) โ (T โ spec .Reservation โ Prop ) โ Prop valid (spec := spec ) ( pure : {f : Type ?u.1213 โ Type ?u.1212 } โ [self : Pure f ] โ {ฮฑ : Type ?u.1213 } โ ฮฑ โ f ฮฑ pure t ) r assuming motive := by
spec : Spec T : Type t : T r : spec .Reservationassuming : spec .State โ Bool motive : T โ spec .Reservation โ Prop is_valid : motive t r rw [ spec : Spec T : Type t : T r : spec .Reservationassuming : spec .State โ Bool motive : T โ spec .Reservation โ Prop is_valid : motive t r valid : {spec : Spec } โ
{T : Type } โ TaskM spec T โ spec .Reservation โ (spec .State โ Bool ) โ (T โ spec .Reservation โ Prop ) โ Prop validspec : Spec T : Type t : T r : spec .Reservationassuming : spec .State โ Bool motive : T โ spec .Reservation โ Prop is_valid : motive t r ] spec : Spec T : Type t : T r : spec .Reservationassuming : spec .State โ Bool motive : T โ spec .Reservation โ Prop is_valid : motive t r
spec : Spec T : Type t : T r : spec .Reservationassuming : spec .State โ Bool motive : T โ spec .Reservation โ Prop is_valid : motive t r intro env_r s _ initial_valid spec : Spec T : Type t : T r : spec .Reservationassuming : spec .State โ Bool motive : T โ spec .Reservation โ Prop is_valid : motive t r env_r : spec .Reservations : spec .Stateinitial_valid : Spec.validate spec (env_r + r ) s
spec : Spec T : Type t : T r : spec .Reservationassuming : spec .State โ Bool motive : T โ spec .Reservation โ Prop is_valid : motive t r exists r
/-- To prove that `a >>= f` is valid you need to prove that both `a` and `f u`
for all results `u` are valid.
In many cases, `a` does something to prepare `f u`. Since only `f u` needs
to fulfil the final motive, we can choose an arbitrary motive to validate `a`
as "intermediate goal".
To validate `f u` with the original `motive`, we can use the fact that the
intermediate goal `motive_u` has been ensured by `a`. Motives use only results
and reservations, which cannot be changed by other threads. Therefore, they
stay valid even if other threads become active between `a` and `f u`.
-/
theorem valid_bind : โ {spec : Spec } {U V : Type }
(_x :
(mu : TaskM spec U ) ร'
(f : U โ TaskM spec V ) ร'
(r : spec .Reservation ) ร'
(assuming : spec .State โ Bool ) ร'
(motive : V โ spec .Reservation โ Prop ) ร'
(motive_u : U โ spec .Reservation โ Prop ) ร'
(_ : valid mu r assuming motive_u ) ร'
โ (r' : spec .Reservation ) (u : U ), motive_u u r' โ valid (f u ) r' (fun x => true ) motive ),
valid (_x .1 >>= _x .2 .1 ) _x .2 .2 .1 _x .2 .2 .2 .1 _x .2 .2 .2 .2 .1 valid_bind { U V : Type }
{ mu : TaskM : Spec โ Type โ Type TaskM spec U }
{ f : U -> TaskM : Spec โ Type โ Type TaskM spec V }
{ r assuming motive : V โ spec .Reservation โ Prop
motive }
( motive_u : U โ spec .Reservation โ Prop
motive_u : U -> spec . Reservation : Spec โ Type Reservation -> Prop )
( mu_valid : valid mu r assuming motive_u mu_valid : mu . valid : {spec : Spec } โ
{T : Type } โ TaskM spec T โ spec .Reservation โ (spec .State โ Bool ) โ (T โ spec .Reservation โ Prop ) โ Prop valid r assuming motive_u : U โ spec .Reservation โ Prop
motive_u )
( f_valid : โ (r' : spec .Reservation ) (u : U ), motive_u u r' โ valid (f u ) r' (fun x => true ) motive f_valid : โ r' u ,
motive_u : U โ spec .Reservation โ Prop
motive_u u r' โ
( f u ). valid : {spec : Spec } โ
{T : Type } โ TaskM spec T โ spec .Reservation โ (spec .State โ Bool ) โ (T โ spec .Reservation โ Prop ) โ Prop valid r' (ฮป _ => true ) motive )
: valid : {spec : Spec } โ
{T : Type } โ TaskM spec T โ spec .Reservation โ (spec .State โ Bool ) โ (T โ spec .Reservation โ Prop ) โ Prop valid ( mu >>= f ) r assuming motive := by
spec : Spec U, V : Type mu : TaskM spec U f : U โ TaskM spec V r : spec .Reservationassuming : spec .State โ Bool motive : V โ spec .Reservation โ Prop motive_u : U โ spec .Reservation โ Prop mu_valid : valid mu r assuming motive_u f_valid : โ (r' : spec .Reservation ) (u : U ), motive_u u r' โ valid (f u ) r' (fun x => true ) motive rw [ spec : Spec U, V : Type mu : TaskM spec U f : U โ TaskM spec V r : spec .Reservationassuming : spec .State โ Bool motive : V โ spec .Reservation โ Prop motive_u : U โ spec .Reservation โ Prop mu_valid : valid mu r assuming motive_u f_valid : โ (r' : spec .Reservation ) (u : U ), motive_u u r' โ valid (f u ) r' (fun x => true ) motive valid : {spec : Spec } โ
{T : Type } โ TaskM spec T โ spec .Reservation โ (spec .State โ Bool ) โ (T โ spec .Reservation โ Prop ) โ Prop validspec : Spec U, V : Type mu : TaskM spec U f : U โ TaskM spec V r : spec .Reservationassuming : spec .State โ Bool motive : V โ spec .Reservation โ Prop motive_u : U โ spec .Reservation โ Prop mu_valid : valid mu r assuming motive_u f_valid : โ (r' : spec .Reservation ) (u : U ), motive_u u r' โ valid (f u ) r' (fun x => true ) motive ] spec : Spec U, V : Type mu : TaskM spec U f : U โ TaskM spec V r : spec .Reservationassuming : spec .State โ Bool motive : V โ spec .Reservation โ Prop motive_u : U โ spec .Reservation โ Prop mu_valid : valid mu r assuming motive_u f_valid : โ (r' : spec .Reservation ) (u : U ), motive_u u r' โ valid (f u ) r' (fun x => true ) motive
spec : Spec U, V : Type mu : TaskM spec U f : U โ TaskM spec V r : spec .Reservationassuming : spec .State โ Bool motive : V โ spec .Reservation โ Prop motive_u : U โ spec .Reservation โ Prop mu_valid : valid mu r assuming motive_u f_valid : โ (r' : spec .Reservation ) (u : U ), motive_u u r' โ valid (f u ) r' (fun x => true ) motive intro env_r s assuming_true : assuming s = true assuming_true initial_valid spec : Spec U, V : Type mu : TaskM spec U f : U โ TaskM spec V r : spec .Reservationassuming : spec .State โ Bool motive : V โ spec .Reservation โ Prop motive_u : U โ spec .Reservation โ Prop mu_valid : valid mu r assuming motive_u f_valid : โ (r' : spec .Reservation ) (u : U ), motive_u u r' โ valid (f u ) r' (fun x => true ) motive env_r : spec .Reservations : spec .Stateassuming_true : assuming s = true initial_valid : Spec.validate spec (env_r + r ) s
spec : Spec U, V : Type mu : TaskM spec U f : U โ TaskM spec V r : spec .Reservationassuming : spec .State โ Bool motive : V โ spec .Reservation โ Prop motive_u : U โ spec .Reservation โ Prop mu_valid : valid mu r assuming motive_u f_valid : โ (r' : spec .Reservation ) (u : U ), motive_u u r' โ valid (f u ) r' (fun x => true ) motive rw [ spec : Spec U, V : Type mu : TaskM spec U f : U โ TaskM spec V r : spec .Reservationassuming : spec .State โ Bool motive : V โ spec .Reservation โ Prop motive_u : U โ spec .Reservation โ Prop mu_valid : valid mu r assuming motive_u f_valid : โ (r' : spec .Reservation ) (u : U ), motive_u u r' โ valid (f u ) r' (fun x => true ) motive env_r : spec .Reservations : spec .Stateassuming_true : assuming s = true initial_valid : Spec.validate spec (env_r + r ) s iterate_bind spec : Spec U, V : Type mu : TaskM spec U f : U โ TaskM spec V r : spec .Reservationassuming : spec .State โ Bool motive : V โ spec .Reservation โ Prop motive_u : U โ spec .Reservation โ Prop mu_valid : valid mu r assuming motive_u f_valid : โ (r' : spec .Reservation ) (u : U ), motive_u u r' โ valid (f u ) r' (fun x => true ) motive env_r : spec .Reservations : spec .Stateassuming_true : assuming s = true initial_valid : Spec.validate spec (env_r + r ) s ] spec : Spec U, V : Type mu : TaskM spec U f : U โ TaskM spec V r : spec .Reservationassuming : spec .State โ Bool motive : V โ spec .Reservation โ Prop motive_u : U โ spec .Reservation โ Prop mu_valid : valid mu r assuming motive_u f_valid : โ (r' : spec .Reservation ) (u : U ), motive_u u r' โ valid (f u ) r' (fun x => true ) motive env_r : spec .Reservations : spec .Stateassuming_true : assuming s = true initial_valid : Spec.validate spec (env_r + r ) s
spec : Spec U, V : Type mu : TaskM spec U f : U โ TaskM spec V r : spec .Reservationassuming : spec .State โ Bool motive : V โ spec .Reservation โ Prop motive_u : U โ spec .Reservation โ Prop mu_valid : valid mu r assuming motive_u f_valid : โ (r' : spec .Reservation ) (u : U ), motive_u u r' โ valid (f u ) r' (fun x => true ) motive rw [ spec : Spec U, V : Type mu : TaskM spec U f : U โ TaskM spec V r : spec .Reservationassuming : spec .State โ Bool motive : V โ spec .Reservation โ Prop motive_u : U โ spec .Reservation โ Prop mu_valid : valid mu r assuming motive_u f_valid : โ (r' : spec .Reservation ) (u : U ), motive_u u r' โ valid (f u ) r' (fun x => true ) motive env_r : spec .Reservations : spec .Stateassuming_true : assuming s = true initial_valid : Spec.validate spec (env_r + r ) s valid : {spec : Spec } โ
{T : Type } โ TaskM spec T โ spec .Reservation โ (spec .State โ Bool ) โ (T โ spec .Reservation โ Prop ) โ Prop valid] at mu_valid : valid mu r assuming motive_u mu_valid
spec : Spec U, V : Type mu : TaskM spec U f : U โ TaskM spec V r : spec .Reservationassuming : spec .State โ Bool motive : V โ spec .Reservation โ Prop motive_u : U โ spec .Reservation โ Prop mu_valid : valid mu r assuming motive_u f_valid : โ (r' : spec .Reservation ) (u : U ), motive_u u r' โ valid (f u ) r' (fun x => true ) motive cases iteration : iterate mu s
spec : Spec U, V : Type mu : TaskM spec U f : U โ TaskM spec V r : spec .Reservationassuming : spec .State โ Bool motive : V โ spec .Reservation โ Prop motive_u : U โ spec .Reservation โ Prop mu_valid : valid mu r assuming motive_u f_valid : โ (r' : spec .Reservation ) (u : U ), motive_u u r' โ valid (f u ) r' (fun x => true ) motive all_goals (
simp only []
have mu_valid := mu_valid env_r s assuming_true : assuming s = true assuming_true initial_valid
rw [ iteration ] at mu_valid
simp only [] at mu_valid spec : Spec U, V : Type mu : TaskM spec U f : U โ TaskM spec V r : spec .Reservationassuming : spec .State โ Bool motive : V โ spec .Reservation โ Prop motive_u : U โ spec .Reservation โ Prop f_valid : โ (r' : spec .Reservation ) (u : U ), motive_u u r' โ valid (f u ) r' (fun x => true ) motive env_r : spec .Reservations : spec .Stateassuming_true : assuming s = true initial_valid : Spec.validate spec (env_r + r ) s aโยน : spec .Stateaโ : U iteration : iterate mu s = IterationResult.Done aโยน aโ mu_valid : โ r' , Spec.validate spec (env_r + r' ) aโยน โง motive_u aโ r' Done
cases mu_valid ; rename_i r' mu_valid spec : Spec U, V : Type mu : TaskM spec U f : U โ TaskM spec V r : spec .Reservationassuming : spec .State โ Bool motive : V โ spec .Reservation โ Prop motive_u : U โ spec .Reservation โ Prop f_valid : โ (r' : spec .Reservation ) (u : U ), motive_u u r' โ valid (f u ) r' (fun x => true ) motive env_r : spec .Reservations : spec .Stateassuming_true : assuming s = true initial_valid : Spec.validate spec (env_r + r ) s aโยน : spec .Stateaโ : String iteration : iterate mu s = IterationResult.Panic aโยน aโ r' : spec .Reservationmu_valid : False Panic.intro
exists r' spec : Spec U, V : Type mu : TaskM spec U f : U โ TaskM spec V r : spec .Reservationassuming : spec .State โ Bool motive : V โ spec .Reservation โ Prop motive_u : U โ spec .Reservation โ Prop f_valid : โ (r' : spec .Reservation ) (u : U ), motive_u u r' โ valid (f u ) r' (fun x => true ) motive env_r : spec .Reservations : spec .Stateassuming_true : assuming s = true initial_valid : Spec.validate spec (env_r + r ) s aโยน : spec .Stateaโ : U iteration : iterate mu s = IterationResult.Done aโยน aโ r' : spec .Reservationmu_valid : Spec.validate spec (env_r + r' ) aโยน โง motive_u aโ r' Done.intro
) spec : Spec U, V : Type mu : TaskM spec U f : U โ TaskM spec V r : spec .Reservationassuming : spec .State โ Bool motive : V โ spec .Reservation โ Prop motive_u : U โ spec .Reservation โ Prop f_valid : โ (r' : spec .Reservation ) (u : U ), motive_u u r' โ valid (f u ) r' (fun x => true ) motive env_r : spec .Reservations : spec .Stateassuming_true : assuming s = true initial_valid : Spec.validate spec (env_r + r ) s aโยน : spec .Stateaโ : U iteration : iterate mu s = IterationResult.Done aโยน aโ r' : spec .Reservationmu_valid : Spec.validate spec (env_r + r' ) aโยน โง motive_u aโ r' Done.intro
spec : Spec U, V : Type mu : TaskM spec U f : U โ TaskM spec V r : spec .Reservationassuming : spec .State โ Bool motive : V โ spec .Reservation โ Prop motive_u : U โ spec .Reservation โ Prop mu_valid : valid mu r assuming motive_u f_valid : โ (r' : spec .Reservation ) (u : U ), motive_u u r' โ valid (f u ) r' (fun x => true ) motive . spec : Spec U, V : Type mu : TaskM spec U f : U โ TaskM spec V r : spec .Reservationassuming : spec .State โ Bool motive : V โ spec .Reservation โ Prop motive_u : U โ spec .Reservation โ Prop f_valid : โ (r' : spec .Reservation ) (u : U ), motive_u u r' โ valid (f u ) r' (fun x => true ) motive env_r : spec .Reservations : spec .Stateassuming_true : assuming s = true initial_valid : Spec.validate spec (env_r + r ) s aโยน : spec .Stateaโ : U iteration : iterate mu s = IterationResult.Done aโยน aโ r' : spec .Reservationmu_valid : Spec.validate spec (env_r + r' ) aโยน โง motive_u aโ r' Done.intro spec : Spec U, V : Type mu : TaskM spec U f : U โ TaskM spec V r : spec .Reservationassuming : spec .State โ Bool motive : V โ spec .Reservation โ Prop motive_u : U โ spec .Reservation โ Prop f_valid : โ (r' : spec .Reservation ) (u : U ), motive_u u r' โ valid (f u ) r' (fun x => true ) motive env_r : spec .Reservations : spec .Stateassuming_true : assuming s = true initial_valid : Spec.validate spec (env_r + r ) s aโยน : spec .Stateaโ : U iteration : iterate mu s = IterationResult.Done aโยน aโ r' : spec .Reservationmu_valid : Spec.validate spec (env_r + r' ) aโยน โง motive_u aโ r' Done.intro spec : Spec U, V : Type mu : TaskM spec U f : U โ TaskM spec V r : spec .Reservationassuming : spec .State โ Bool motive : V โ spec .Reservation โ Prop motive_u : U โ spec .Reservation โ Prop f_valid : โ (r' : spec .Reservation ) (u : U ), motive_u u r' โ valid (f u ) r' (fun x => true ) motive env_r : spec .Reservations : spec .Stateassuming_true : assuming s = true initial_valid : Spec.validate spec (env_r + r ) s aโยฒ : spec .Stateaโยน : spec .State โ Bool aโ : TaskM spec U iteration : iterate mu s = IterationResult.Running aโยฒ aโยน aโ r' : spec .Reservationmu_valid : Spec.validate spec (env_r + r' ) aโยฒ โง valid aโ r' aโยน motive_u Running.intro exact โจ mu_valid . left : โ {a b : Prop }, a โง b โ a left, f_valid : โ (r' : spec .Reservation ) (u : U ), motive_u u r' โ valid (f u ) r' (fun x => true ) motive f_valid _ _ mu_valid . right : โ {a b : Prop }, a โง b โ b rightโฉ
spec : Spec U, V : Type mu : TaskM spec U f : U โ TaskM spec V r : spec .Reservationassuming : spec .State โ Bool motive : V โ spec .Reservation โ Prop motive_u : U โ spec .Reservation โ Prop mu_valid : valid mu r assuming motive_u f_valid : โ (r' : spec .Reservation ) (u : U ), motive_u u r' โ valid (f u ) r' (fun x => true ) motive . spec : Spec U, V : Type mu : TaskM spec U f : U โ TaskM spec V r : spec .Reservationassuming : spec .State โ Bool motive : V โ spec .Reservation โ Prop motive_u : U โ spec .Reservation โ Prop f_valid : โ (r' : spec .Reservation ) (u : U ), motive_u u r' โ valid (f u ) r' (fun x => true ) motive env_r : spec .Reservations : spec .Stateassuming_true : assuming s = true initial_valid : Spec.validate spec (env_r + r ) s aโยฒ : spec .Stateaโยน : spec .State โ Bool aโ : TaskM spec U iteration : iterate mu s = IterationResult.Running aโยฒ aโยน aโ r' : spec .Reservationmu_valid : Spec.validate spec (env_r + r' ) aโยฒ โง valid aโ r' aโยน motive_u Running.intro spec : Spec U, V : Type mu : TaskM spec U f : U โ TaskM spec V r : spec .Reservationassuming : spec .State โ Bool motive : V โ spec .Reservation โ Prop motive_u : U โ spec .Reservation โ Prop f_valid : โ (r' : spec .Reservation ) (u : U ), motive_u u r' โ valid (f u ) r' (fun x => true ) motive env_r : spec .Reservations : spec .Stateassuming_true : assuming s = true initial_valid : Spec.validate spec (env_r + r ) s aโยฒ : spec .Stateaโยน : spec .State โ Bool aโ : TaskM spec U iteration : iterate mu s = IterationResult.Running aโยฒ aโยน aโ r' : spec .Reservationmu_valid : Spec.validate spec (env_r + r' ) aโยฒ โง valid aโ r' aโยน motive_u Running.intro constructor spec : Spec U, V : Type mu : TaskM spec U f : U โ TaskM spec V r : spec .Reservationassuming : spec .State โ Bool motive : V โ spec .Reservation โ Prop motive_u : U โ spec .Reservation โ Prop f_valid : โ (r' : spec .Reservation ) (u : U ), motive_u u r' โ valid (f u ) r' (fun x => true ) motive env_r : spec .Reservations : spec .Stateassuming_true : assuming s = true initial_valid : Spec.validate spec (env_r + r ) s aโยฒ : spec .Stateaโยน : spec .State โ Bool aโ : TaskM spec U iteration : iterate mu s = IterationResult.Running aโยฒ aโยน aโ r' : spec .Reservationmu_valid : Spec.validate spec (env_r + r' ) aโยฒ โง valid aโ r' aโยน motive_u Running.intro.left spec : Spec U, V : Type mu : TaskM spec U f : U โ TaskM spec V r : spec .Reservationassuming : spec .State โ Bool motive : V โ spec .Reservation โ Prop motive_u : U โ spec .Reservation โ Prop f_valid : โ (r' : spec .Reservation ) (u : U ), motive_u u r' โ valid (f u ) r' (fun x => true ) motive env_r : spec .Reservations : spec .Stateassuming_true : assuming s = true initial_valid : Spec.validate spec (env_r + r ) s aโยฒ : spec .Stateaโยน : spec .State โ Bool aโ : TaskM spec U iteration : iterate mu s = IterationResult.Running aโยฒ aโยน aโ r' : spec .Reservationmu_valid : Spec.validate spec (env_r + r' ) aโยฒ โง valid aโ r' aโยน motive_u Running.intro.right
spec : Spec U, V : Type mu : TaskM spec U f : U โ TaskM spec V r : spec .Reservationassuming : spec .State โ Bool motive : V โ spec .Reservation โ Prop motive_u : U โ spec .Reservation โ Prop f_valid : โ (r' : spec .Reservation ) (u : U ), motive_u u r' โ valid (f u ) r' (fun x => true ) motive env_r : spec .Reservations : spec .Stateassuming_true : assuming s = true initial_valid : Spec.validate spec (env_r + r ) s aโยฒ : spec .Stateaโยน : spec .State โ Bool aโ : TaskM spec U iteration : iterate mu s = IterationResult.Running aโยฒ aโยน aโ r' : spec .Reservationmu_valid : Spec.validate spec (env_r + r' ) aโยฒ โง valid aโ r' aโยน motive_u Running.intro . spec : Spec U, V : Type mu : TaskM spec U f : U โ TaskM spec V r : spec .Reservationassuming : spec .State โ Bool motive : V โ spec .Reservation โ Prop motive_u : U โ spec .Reservation โ Prop f_valid : โ (r' : spec .Reservation ) (u : U ), motive_u u r' โ valid (f u ) r' (fun x => true ) motive env_r : spec .Reservations : spec .Stateassuming_true : assuming s = true initial_valid : Spec.validate spec (env_r + r ) s aโยฒ : spec .Stateaโยน : spec .State โ Bool aโ : TaskM spec U iteration : iterate mu s = IterationResult.Running aโยฒ aโยน aโ r' : spec .Reservationmu_valid : Spec.validate spec (env_r + r' ) aโยฒ โง valid aโ r' aโยน motive_u Running.intro.left spec : Spec U, V : Type mu : TaskM spec U f : U โ TaskM spec V r : spec .Reservationassuming : spec .State โ Bool motive : V โ spec .Reservation โ Prop motive_u : U โ spec .Reservation โ Prop f_valid : โ (r' : spec .Reservation ) (u : U ), motive_u u r' โ valid (f u ) r' (fun x => true ) motive env_r : spec .Reservations : spec .Stateassuming_true : assuming s = true initial_valid : Spec.validate spec (env_r + r ) s aโยฒ : spec .Stateaโยน : spec .State โ Bool aโ : TaskM spec U iteration : iterate mu s = IterationResult.Running aโยฒ aโยน aโ r' : spec .Reservationmu_valid : Spec.validate spec (env_r + r' ) aโยฒ โง valid aโ r' aโยน motive_u Running.intro.left spec : Spec U, V : Type mu : TaskM spec U f : U โ TaskM spec V r : spec .Reservationassuming : spec .State โ Bool motive : V โ spec .Reservation โ Prop motive_u : U โ spec .Reservation โ Prop f_valid : โ (r' : spec .Reservation ) (u : U ), motive_u u r' โ valid (f u ) r' (fun x => true ) motive env_r : spec .Reservations : spec .Stateassuming_true : assuming s = true initial_valid : Spec.validate spec (env_r + r ) s aโยฒ : spec .Stateaโยน : spec .State โ Bool aโ : TaskM spec U iteration : iterate mu s = IterationResult.Running aโยฒ aโยน aโ r' : spec .Reservationmu_valid : Spec.validate spec (env_r + r' ) aโยฒ โง valid aโ r' aโยน motive_u Running.intro.right exact mu_valid . left : โ {a b : Prop }, a โง b โ a left
spec : Spec U, V : Type mu : TaskM spec U f : U โ TaskM spec V r : spec .Reservationassuming : spec .State โ Bool motive : V โ spec .Reservation โ Prop motive_u : U โ spec .Reservation โ Prop f_valid : โ (r' : spec .Reservation ) (u : U ), motive_u u r' โ valid (f u ) r' (fun x => true ) motive env_r : spec .Reservations : spec .Stateassuming_true : assuming s = true initial_valid : Spec.validate spec (env_r + r ) s aโยฒ : spec .Stateaโยน : spec .State โ Bool aโ : TaskM spec U iteration : iterate mu s = IterationResult.Running aโยฒ aโยน aโ r' : spec .Reservationmu_valid : Spec.validate spec (env_r + r' ) aโยฒ โง valid aโ r' aโยน motive_u Running.intro . spec : Spec U, V : Type mu : TaskM spec U f : U โ TaskM spec V r : spec .Reservationassuming : spec .State โ Bool motive : V โ spec .Reservation โ Prop motive_u : U โ spec .Reservation โ Prop f_valid : โ (r' : spec .Reservation ) (u : U ), motive_u u r' โ valid (f u ) r' (fun x => true ) motive env_r : spec .Reservations : spec .Stateassuming_true : assuming s = true initial_valid : Spec.validate spec (env_r + r ) s aโยฒ : spec .Stateaโยน : spec .State โ Bool aโ : TaskM spec U iteration : iterate mu s = IterationResult.Running aโยฒ aโยน aโ r' : spec .Reservationmu_valid : Spec.validate spec (env_r + r' ) aโยฒ โง valid aโ r' aโยน motive_u Running.intro.right spec : Spec U, V : Type mu : TaskM spec U f : U โ TaskM spec V r : spec .Reservationassuming : spec .State โ Bool motive : V โ spec .Reservation โ Prop motive_u : U โ spec .Reservation โ Prop f_valid : โ (r' : spec .Reservation ) (u : U ), motive_u u r' โ valid (f u ) r' (fun x => true ) motive env_r : spec .Reservations : spec .Stateassuming_true : assuming s = true initial_valid : Spec.validate spec (env_r + r ) s aโยฒ : spec .Stateaโยน : spec .State โ Bool aโ : TaskM spec U iteration : iterate mu s = IterationResult.Running aโยฒ aโยน aโ r' : spec .Reservationmu_valid : Spec.validate spec (env_r + r' ) aโยฒ โง valid aโ r' aโยน motive_u Running.intro.right have := is_direct_cont.running iteration spec : Spec U, V : Type mu : TaskM spec U f : U โ TaskM spec V r : spec .Reservationassuming : spec .State โ Bool motive : V โ spec .Reservation โ Prop motive_u : U โ spec .Reservation โ Prop f_valid : โ (r' : spec .Reservation ) (u : U ), motive_u u r' โ valid (f u ) r' (fun x => true ) motive env_r : spec .Reservations : spec .Stateassuming_true : assuming s = true initial_valid : Spec.validate spec (env_r + r ) s aโยฒ : spec .Stateaโยน : spec .State โ Bool aโ : TaskM spec U iteration : iterate mu s = IterationResult.Running aโยฒ aโยน aโ r' : spec .Reservationmu_valid : Spec.validate spec (env_r + r' ) aโยฒ โง valid aโ r' aโยน motive_u this : is_direct_cont aโ mu Running.intro.right
spec : Spec U, V : Type mu : TaskM spec U f : U โ TaskM spec V r : spec .Reservationassuming : spec .State โ Bool motive : V โ spec .Reservation โ Prop motive_u : U โ spec .Reservation โ Prop f_valid : โ (r' : spec .Reservation ) (u : U ), motive_u u r' โ valid (f u ) r' (fun x => true ) motive env_r : spec .Reservations : spec .Stateassuming_true : assuming s = true initial_valid : Spec.validate spec (env_r + r ) s aโยฒ : spec .Stateaโยน : spec .State โ Bool aโ : TaskM spec U iteration : iterate mu s = IterationResult.Running aโยฒ aโยน aโ r' : spec .Reservationmu_valid : Spec.validate spec (env_r + r' ) aโยฒ โง valid aโ r' aโยน motive_u Running.intro.right exact valid_bind : โ {U V : Type } {mu : TaskM spec U } {f : U โ TaskM spec V } {r : spec .Reservation } {assuming : spec .State โ Bool }
{motive : V โ spec .Reservation โ Prop } (motive_u : U โ spec .Reservation โ Prop ),
valid mu r assuming motive_u โ
(โ (r' : spec .Reservation ) (u : U ), motive_u u r' โ valid (f u ) r' (fun x => true ) motive ) โ
valid (mu >>= f ) r assuming motive valid_bind motive_u : U โ spec .Reservation โ Prop
motive_u mu_valid . right : โ {a b : Prop }, a โง b โ b right f_valid : โ (r' : spec .Reservation ) (u : U ), motive_u u r' โ valid (f u ) r' (fun x => true ) motive f_valid
termination_by valid_bind => mu
theorem valid_rmr : โ {T : Type } {f : spec .State โ T ร spec .State } {r : spec .Reservation } {assuming : spec .State โ Bool }
{motive : T โ spec .Reservation โ Prop },
(โ (env_r : spec .Reservation ) (s : spec .State ),
assuming s = true โ
Spec.validate spec (env_r + r ) s โ
โ r' ,
let _discr := f s ;
match f s with
| (t , s' ) => Spec.validate spec (env_r + r' ) s' โง motive t r' ) โ
valid (atomic_read_modify_read f ) r assuming motive valid_rmr { T : Type }
{ f : spec .State โ T ร spec .Statef : spec . State -> T ร spec . State }
{ r assuming : spec .State โ Bool assuming motive : T โ spec .Reservation โ Prop
motive }
( f_valid : โ (env_r : spec .Reservation ) (s : spec .State ),
?m.6797 env_r s โ
Spec.validate spec (env_r + r ) s โ
โ r' ,
let _discr := f s ;
match f s with
| (t , s' ) => Spec.validate spec (env_r + r' ) s' โง ?m.6798 env_r s r' t s' f_valid : โ env_r s ,
assuming s โ
spec . validate : (self : Spec ) โ self .Reservation โ self .State โ Prop validate ( env_r + r ) s โ โ r' : spec . Reservation : Spec โ Type Reservation,
match f : spec .State โ T ร spec .Statef s with
| โจ t , s' โฉ => spec . validate : (self : Spec ) โ self .Reservation โ self .State โ Prop validate ( env_r + r' ) s' โง motive t r'
)
: ( atomic_read_modify_read : {spec : Spec } โ {T : Type } โ (spec .State โ T ร spec .State ) โ TaskM spec T atomic_read_modify_read f : spec .State โ T ร spec .Statef ). valid : {spec : Spec } โ
{T : Type } โ TaskM spec T โ spec .Reservation โ (spec .State โ Bool ) โ (T โ spec .Reservation โ Prop ) โ Prop valid r assuming motive := by
spec : Spec T : Type f : spec .State โ T ร spec .Stater : spec .Reservationassuming : spec .State โ Bool motive : T โ spec .Reservation โ Prop f_valid : โ (env_r : spec .Reservation ) (s : spec .State ),
assuming s = true โ
Spec.validate spec (env_r + r ) s โ
โ r' ,
let _discr := f s ;
match f s with
| (t , s' ) => Spec.validate spec (env_r + r' ) s' โง motive t r' rw [ spec : Spec T : Type f : spec .State โ T ร spec .Stater : spec .Reservationassuming : spec .State โ Bool motive : T โ spec .Reservation โ Prop f_valid : โ (env_r : spec .Reservation ) (s : spec .State ),
assuming s = true โ
Spec.validate spec (env_r + r ) s โ
โ r' ,
let _discr := f s ;
match f s with
| (t , s' ) => Spec.validate spec (env_r + r' ) s' โง motive t r' valid : {spec : Spec } โ
{T : Type } โ TaskM spec T โ spec .Reservation โ (spec .State โ Bool ) โ (T โ spec .Reservation โ Prop ) โ Prop validspec : Spec T : Type f : spec .State โ T ร spec .Stater : spec .Reservationassuming : spec .State โ Bool motive : T โ spec .Reservation โ Prop f_valid : โ (env_r : spec .Reservation ) (s : spec .State ),
assuming s = true โ
Spec.validate spec (env_r + r ) s โ
โ r' ,
let _discr := f s ;
match f s with
| (t , s' ) => Spec.validate spec (env_r + r' ) s' โง motive t r' ] spec : Spec T : Type f : spec .State โ T ร spec .Stater : spec .Reservationassuming : spec .State โ Bool motive : T โ spec .Reservation โ Prop f_valid : โ (env_r : spec .Reservation ) (s : spec .State ),
assuming s = true โ
Spec.validate spec (env_r + r ) s โ
โ r' ,
let _discr := f s ;
match f s with
| (t , s' ) => Spec.validate spec (env_r + r' ) s' โง motive t r'
spec : Spec T : Type f : spec .State โ T ร spec .Stater : spec .Reservationassuming : spec .State โ Bool motive : T โ spec .Reservation โ Prop f_valid : โ (env_r : spec .Reservation ) (s : spec .State ),
assuming s = true โ
Spec.validate spec (env_r + r ) s โ
โ r' ,
let _discr := f s ;
match f s with
| (t , s' ) => Spec.validate spec (env_r + r' ) s' โง motive t r' intro env_r s assuming_true : assuming s = true assuming_true initial_valid spec : Spec T : Type f : spec .State โ T ร spec .Stater : spec .Reservationassuming : spec .State โ Bool motive : T โ spec .Reservation โ Prop f_valid : โ (env_r : spec .Reservation ) (s : spec .State ),
assuming s = true โ
Spec.validate spec (env_r + r ) s โ
โ r' ,
let _discr := f s ;
match f s with
| (t , s' ) => Spec.validate spec (env_r + r' ) s' โง motive t r' env_r : spec .Reservations : spec .Stateassuming_true : assuming s = true initial_valid : Spec.validate spec (env_r + r ) s
spec : Spec T : Type f : spec .State โ T ร spec .Stater : spec .Reservationassuming : spec .State โ Bool motive : T โ spec .Reservation โ Prop f_valid : โ (env_r : spec .Reservation ) (s : spec .State ),
assuming s = true โ
Spec.validate spec (env_r + r ) s โ
โ r' ,
let _discr := f s ;
match f s with
| (t , s' ) => Spec.validate spec (env_r + r' ) s' โง motive t r' rw [ spec : Spec T : Type f : spec .State โ T ร spec .Stater : spec .Reservationassuming : spec .State โ Bool motive : T โ spec .Reservation โ Prop f_valid : โ (env_r : spec .Reservation ) (s : spec .State ),
assuming s = true โ
Spec.validate spec (env_r + r ) s โ
โ r' ,
let _discr := f s ;
match f s with
| (t , s' ) => Spec.validate spec (env_r + r' ) s' โง motive t r' env_r : spec .Reservations : spec .Stateassuming_true : assuming s = true initial_valid : Spec.validate spec (env_r + r ) s iterate_rmr spec : Spec T : Type f : spec .State โ T ร spec .Stater : spec .Reservationassuming : spec .State โ Bool motive : T โ spec .Reservation โ Prop f_valid : โ (env_r : spec .Reservation ) (s : spec .State ),
assuming s = true โ
Spec.validate spec (env_r + r ) s โ
โ r' ,
let _discr := f s ;
match f s with
| (t , s' ) => Spec.validate spec (env_r + r' ) s' โง motive t r' env_r : spec .Reservations : spec .Stateassuming_true : assuming s = true initial_valid : Spec.validate spec (env_r + r ) s ] spec : Spec T : Type f : spec .State โ T ร spec .Stater : spec .Reservationassuming : spec .State โ Bool motive : T โ spec .Reservation โ Prop f_valid : โ (env_r : spec .Reservation ) (s : spec .State ),
assuming s = true โ
Spec.validate spec (env_r + r ) s โ
โ r' ,
let _discr := f s ;
match f s with
| (t , s' ) => Spec.validate spec (env_r + r' ) s' โง motive t r' env_r : spec .Reservations : spec .Stateassuming_true : assuming s = true initial_valid : Spec.validate spec (env_r + r ) s
spec : Spec T : Type f : spec .State โ T ร spec .Stater : spec .Reservationassuming : spec .State โ Bool motive : T โ spec .Reservation โ Prop f_valid : โ (env_r : spec .Reservation ) (s : spec .State ),
assuming s = true โ
Spec.validate spec (env_r + r ) s โ
โ r' ,
let _discr := f s ;
match f s with
| (t , s' ) => Spec.validate spec (env_r + r' ) s' โง motive t r' exact f_valid : โ (env_r : spec .Reservation ) (s : spec .State ),
assuming s = true โ
Spec.validate spec (env_r + r ) s โ
โ r' ,
let _discr := f s ;
match f s with
| (t , s' ) => Spec.validate spec (env_r + r' ) s' โง motive t r' f_valid env_r s assuming_true : assuming s = true assuming_true initial_valid
theorem valid_rm : โ {f : spec .State โ spec .State } {r : spec .Reservation } {assuming : spec .State โ Bool }
{motive : Unit โ spec .Reservation โ Prop },
(โ (env_r : spec .Reservation ) (s : spec .State ),
assuming s = true โ
Spec.validate spec (env_r + r ) s โ
โ r' ,
let s' := f s ;
Spec.validate spec (env_r + r' ) s' โง motive PUnit.unit r' ) โ
valid (atomic_read_modify f ) r assuming motive valid_rm
{ f : spec .State โ spec .State
f : spec . State -> spec . State }
{ r assuming : spec .State โ Bool assuming motive : Unit โ spec .Reservation โ Prop motive }
( f_valid : โ (env_r : spec .Reservation ) (s : spec .State ),
?m.7259 env_r s โ
Spec.validate spec (env_r + r ) s โ
โ r' ,
let s' := f s ;
Spec.validate spec (env_r + r' ) s' โง ?m.7260 env_r s r' s' f_valid : โ env_r s ,
assuming s โ
spec . validate : (self : Spec ) โ self .Reservation โ self .State โ Prop validate ( env_r + r ) s โ โ r' : spec . Reservation : Spec โ Type Reservation,
match f : spec .State โ spec .State
f s with
| s' => spec . validate : (self : Spec ) โ self .Reservation โ self .State โ Prop validate ( env_r + r' ) s' โง motive โจโฉ r' )
: ( atomic_read_modify : {spec : Spec } โ (spec .State โ spec .State ) โ TaskM spec Unit atomic_read_modify f : spec .State โ spec .State
f ). valid : {spec : Spec } โ
{T : Type } โ TaskM spec T โ spec .Reservation โ (spec .State โ Bool ) โ (T โ spec .Reservation โ Prop ) โ Prop valid r assuming motive := valid_rmr : โ {spec : Spec } {T : Type } {f : spec .State โ T ร spec .State } {r : spec .Reservation } {assuming : spec .State โ Bool }
{motive : T โ spec .Reservation โ Prop },
(โ (env_r : spec .Reservation ) (s : spec .State ),
assuming s = true โ
Spec.validate spec (env_r + r ) s โ
โ r' ,
let _discr := f s ;
match f s with
| (t , s' ) => Spec.validate spec (env_r + r' ) s' โง motive t r' ) โ
valid (atomic_read_modify_read f ) r assuming motive valid_rmr f_valid
theorem valid_read : โ {T : Type } {f : spec .State โ T } {r : spec .Reservation } {assuming : spec .State โ Bool }
{motive : T โ spec .Reservation โ Prop },
(โ (env_r : spec .Reservation ) (s : spec .State ),
assuming s = true โ
Spec.validate spec (env_r + r ) s โ
โ r' ,
let t := f s ;
Spec.validate spec (env_r + r' ) s โง motive t r' ) โ
valid (atomic_read f ) r assuming motive valid_read
{ f : spec . State -> T }
{ r assuming : spec .State โ Bool assuming motive : T โ spec .Reservation โ Prop
motive }
( f_valid : โ (env_r : spec .Reservation ) (s : spec .State ),
assuming s = true โ
Spec.validate spec (env_r + r ) s โ
โ r' ,
let t := f s ;
Spec.validate spec (env_r + r' ) s โง motive t r' f_valid : โ env_r s ,
assuming s โ
spec . validate : (self : Spec ) โ self .Reservation โ self .State โ Prop validate ( env_r + r ) s โ โ r' : spec . Reservation : Spec โ Type Reservation,
match f s with
| t => spec . validate : (self : Spec ) โ self .Reservation โ self .State โ Prop validate ( env_r + r' ) s โง motive t r' )
: ( atomic_read : {spec : Spec } โ {T : Type } โ (spec .State โ T ) โ TaskM spec T atomic_read f ). valid : {spec : Spec } โ
{T : Type } โ TaskM spec T โ spec .Reservation โ (spec .State โ Bool ) โ (T โ spec .Reservation โ Prop ) โ Prop valid r assuming motive := valid_rmr : โ {spec : Spec } {T : Type } {f : spec .State โ T ร spec .State } {r : spec .Reservation } {assuming : spec .State โ Bool }
{motive : T โ spec .Reservation โ Prop },
(โ (env_r : spec .Reservation ) (s : spec .State ),
assuming s = true โ
Spec.validate spec (env_r + r ) s โ
โ r' ,
let _discr := f s ;
match f s with
| (t , s' ) => Spec.validate spec (env_r + r' ) s' โง motive t r' ) โ
valid (atomic_read_modify_read f ) r assuming motive valid_rmr f_valid : โ (env_r : spec .Reservation ) (s : spec .State ),
assuming s = true โ
Spec.validate spec (env_r + r ) s โ
โ r' ,
let t := f s ;
Spec.validate spec (env_r + r' ) s โง motive t r' f_valid
theorem valid_assert : โ {cond : spec .State โ Bool } {r : spec .Reservation } {assuming : spec .State โ Bool }
{motive : Unit โ spec .Reservation โ Prop },
motive PUnit.unit r โ
(โ (env_r : spec .Reservation ) (s : spec .State ),
assuming s = true โ Spec.validate spec (env_r + r ) s โ cond s = true ) โ
valid (atomic_assert cond ) r assuming motive valid_assert
{ cond : spec .State โ Bool cond : spec . State -> Bool }
{ r assuming : spec .State โ Bool assuming motive : Unit โ spec .Reservation โ Prop motive }
( motive_holds : motive โจโฉ r )
( assertion_succeeds : โ (env_r : spec .Reservation ) (s : spec .State ), assuming s = true โ Spec.validate spec (env_r + r ) s โ cond s = true assertion_succeeds : โ env_r s ,
assuming s โ
spec . validate : (self : Spec ) โ self .Reservation โ self .State โ Prop validate ( env_r + r ) s โ
cond : spec .State โ Bool cond s )
: ( atomic_assert cond : spec .State โ Bool cond ). valid : {spec : Spec } โ
{T : Type } โ TaskM spec T โ spec .Reservation โ (spec .State โ Bool ) โ (T โ spec .Reservation โ Prop ) โ Prop valid r assuming motive := by
spec : Spec cond : spec .State โ Bool r : spec .Reservationassuming : spec .State โ Bool motive : Unit โ spec .Reservation โ Prop motive_holds : motive PUnit.unit r assertion_succeeds : โ (env_r : spec .Reservation ) (s : spec .State ), assuming s = true โ Spec.validate spec (env_r + r ) s โ cond s = true rw [ spec : Spec cond : spec .State โ Bool r : spec .Reservationassuming : spec .State โ Bool motive : Unit โ spec .Reservation โ Prop motive_holds : motive PUnit.unit r assertion_succeeds : โ (env_r : spec .Reservation ) (s : spec .State ), assuming s = true โ Spec.validate spec (env_r + r ) s โ cond s = true valid : {spec : Spec } โ
{T : Type } โ TaskM spec T โ spec .Reservation โ (spec .State โ Bool ) โ (T โ spec .Reservation โ Prop ) โ Prop validspec : Spec cond : spec .State โ Bool r : spec .Reservationassuming : spec .State โ Bool motive : Unit โ spec .Reservation โ Prop motive_holds : motive PUnit.unit r assertion_succeeds : โ (env_r : spec .Reservation ) (s : spec .State ), assuming s = true โ Spec.validate spec (env_r + r ) s โ cond s = true ] spec : Spec cond : spec .State โ Bool r : spec .Reservationassuming : spec .State โ Bool motive : Unit โ spec .Reservation โ Prop motive_holds : motive PUnit.unit r assertion_succeeds : โ (env_r : spec .Reservation ) (s : spec .State ), assuming s = true โ Spec.validate spec (env_r + r ) s โ cond s = true
spec : Spec cond : spec .State โ Bool r : spec .Reservationassuming : spec .State โ Bool motive : Unit โ spec .Reservation โ Prop motive_holds : motive PUnit.unit r assertion_succeeds : โ (env_r : spec .Reservation ) (s : spec .State ), assuming s = true โ Spec.validate spec (env_r + r ) s โ cond s = true intro env_r s assuming_true : assuming s = true assuming_true initial_valid spec : Spec cond : spec .State โ Bool r : spec .Reservationassuming : spec .State โ Bool motive : Unit โ spec .Reservation โ Prop motive_holds : motive PUnit.unit r assertion_succeeds : โ (env_r : spec .Reservation ) (s : spec .State ), assuming s = true โ Spec.validate spec (env_r + r ) s โ cond s = true env_r : spec .Reservations : spec .Stateassuming_true : assuming s = true initial_valid : Spec.validate spec (env_r + r ) s
spec : Spec cond : spec .State โ Bool r : spec .Reservationassuming : spec .State โ Bool motive : Unit โ spec .Reservation โ Prop motive_holds : motive PUnit.unit r assertion_succeeds : โ (env_r : spec .Reservation ) (s : spec .State ), assuming s = true โ Spec.validate spec (env_r + r ) s โ cond s = true rw [ spec : Spec cond : spec .State โ Bool r : spec .Reservationassuming : spec .State โ Bool motive : Unit โ spec .Reservation โ Prop motive_holds : motive PUnit.unit r assertion_succeeds : โ (env_r : spec .Reservation ) (s : spec .State ), assuming s = true โ Spec.validate spec (env_r + r ) s โ cond s = true env_r : spec .Reservations : spec .Stateassuming_true : assuming s = true initial_valid : Spec.validate spec (env_r + r ) s iterate_assert spec : Spec cond : spec .State โ Bool r : spec .Reservationassuming : spec .State โ Bool motive : Unit โ spec .Reservation โ Prop motive_holds : motive PUnit.unit r assertion_succeeds : โ (env_r : spec .Reservation ) (s : spec .State ), assuming s = true โ Spec.validate spec (env_r + r ) s โ cond s = true env_r : spec .Reservations : spec .Stateassuming_true : assuming s = true initial_valid : Spec.validate spec (env_r + r ) s ] spec : Spec cond : spec .State โ Bool r : spec .Reservationassuming : spec .State โ Bool motive : Unit โ spec .Reservation โ Prop motive_holds : motive PUnit.unit r assertion_succeeds : โ (env_r : spec .Reservation ) (s : spec .State ), assuming s = true โ Spec.validate spec (env_r + r ) s โ cond s = true env_r : spec .Reservations : spec .Stateassuming_true : assuming s = true initial_valid : Spec.validate spec (env_r + r ) s
spec : Spec cond : spec .State โ Bool r : spec .Reservationassuming : spec .State โ Bool motive : Unit โ spec .Reservation โ Prop motive_holds : motive PUnit.unit r assertion_succeeds : โ (env_r : spec .Reservation ) (s : spec .State ), assuming s = true โ Spec.validate spec (env_r + r ) s โ cond s = true have cond_true := assertion_succeeds : โ (env_r : spec .Reservation ) (s : spec .State ), assuming s = true โ Spec.validate spec (env_r + r ) s โ cond s = true assertion_succeeds env_r s assuming_true : assuming s = true assuming_true initial_valid spec : Spec cond : spec .State โ Bool r : spec .Reservationassuming : spec .State โ Bool motive : Unit โ spec .Reservation โ Prop motive_holds : motive PUnit.unit r assertion_succeeds : โ (env_r : spec .Reservation ) (s : spec .State ), assuming s = true โ Spec.validate spec (env_r + r ) s โ cond s = true env_r : spec .Reservations : spec .Stateassuming_true : assuming s = true initial_valid : Spec.validate spec (env_r + r ) s cond_true : cond s = true
spec : Spec cond : spec .State โ Bool r : spec .Reservationassuming : spec .State โ Bool motive : Unit โ spec .Reservation โ Prop motive_holds : motive PUnit.unit r assertion_succeeds : โ (env_r : spec .Reservation ) (s : spec .State ), assuming s = true โ Spec.validate spec (env_r + r ) s โ cond s = true rw [ spec : Spec cond : spec .State โ Bool r : spec .Reservationassuming : spec .State โ Bool motive : Unit โ spec .Reservation โ Prop motive_holds : motive PUnit.unit r assertion_succeeds : โ (env_r : spec .Reservation ) (s : spec .State ), assuming s = true โ Spec.validate spec (env_r + r ) s โ cond s = true env_r : spec .Reservations : spec .Stateassuming_true : assuming s = true initial_valid : Spec.validate spec (env_r + r ) s cond_true : cond s = true cond_true spec : Spec cond : spec .State โ Bool r : spec .Reservationassuming : spec .State โ Bool motive : Unit โ spec .Reservation โ Prop motive_holds : motive PUnit.unit r assertion_succeeds : โ (env_r : spec .Reservation ) (s : spec .State ), assuming s = true โ Spec.validate spec (env_r + r ) s โ cond s = true env_r : spec .Reservations : spec .Stateassuming_true : assuming s = true initial_valid : Spec.validate spec (env_r + r ) s cond_true : cond s = true ] spec : Spec cond : spec .State โ Bool r : spec .Reservationassuming : spec .State โ Bool motive : Unit โ spec .Reservation โ Prop motive_holds : motive PUnit.unit r assertion_succeeds : โ (env_r : spec .Reservation ) (s : spec .State ), assuming s = true โ Spec.validate spec (env_r + r ) s โ cond s = true env_r : spec .Reservations : spec .Stateassuming_true : assuming s = true initial_valid : Spec.validate spec (env_r + r ) s cond_true : cond s = true
spec : Spec cond : spec .State โ Bool r : spec .Reservationassuming : spec .State โ Bool motive : Unit โ spec .Reservation โ Prop motive_holds : motive PUnit.unit r assertion_succeeds : โ (env_r : spec .Reservation ) (s : spec .State ), assuming s = true โ Spec.validate spec (env_r + r ) s โ cond s = true exists r
theorem valid_blocking_rmr : โ {spec : Spec } {T : Type } {block_until : spec .State โ Bool } {f : spec .State โ T ร spec .State } {r : spec .Reservation }
{assuming : spec .State โ Bool } {motive : T โ spec .Reservation โ Prop },
(โ (env_r : spec .Reservation ) (s : spec .State ),
block_until s = true โ
Spec.validate spec (env_r + r ) s โ
โ r' ,
let _discr := f s ;
match f s with
| (t , s' ) => Spec.validate spec (env_r + r' ) s' โง motive t r' ) โ
valid (atomic_blocking_rmr block_until f ) r assuming motive valid_blocking_rmr
{ block_until : spec .State โ Bool block_until : spec . State -> Bool }
{ f : spec .State โ T ร spec .Statef : spec . State -> T ร spec . State }
{ r assuming : spec .State โ Bool assuming motive : T โ spec .Reservation โ Prop
motive }
( f_valid : โ (env_r : spec .Reservation ) (s : spec .State ),
block_until s = true โ
Spec.validate spec (env_r + r ) s โ
โ r' ,
let _discr := f s ;
match f s with
| (t , s' ) => Spec.validate spec (env_r + r' ) s' โง motive t r' f_valid : โ env_r s ,
block_until : spec .State โ Bool block_until s โ
spec . validate : (self : Spec ) โ self .Reservation โ self .State โ Prop validate ( env_r + r ) s โ โ r' : spec . Reservation : Spec โ Type Reservation,
match f : spec .State โ T ร spec .Statef s with
| โจ t , s' โฉ => spec . validate : (self : Spec ) โ self .Reservation โ self .State โ Prop validate ( env_r + r' ) s' โง motive t r'
)
: ( atomic_blocking_rmr : {spec : Spec } โ {T : Type } โ (spec .State โ Bool ) โ (spec .State โ T ร spec .State ) โ TaskM spec T atomic_blocking_rmr block_until : spec .State โ Bool block_until f : spec .State โ T ร spec .Statef ). valid : {spec : Spec } โ
{T : Type } โ TaskM spec T โ spec .Reservation โ (spec .State โ Bool ) โ (T โ spec .Reservation โ Prop ) โ Prop valid r assuming motive := by
spec : Spec T : Type block_until : spec .State โ Bool f : spec .State โ T ร spec .Stater : spec .Reservationassuming : spec .State โ Bool motive : T โ spec .Reservation โ Prop f_valid : โ (env_r : spec .Reservation ) (s : spec .State ),
block_until s = true โ
Spec.validate spec (env_r + r ) s โ
โ r' ,
let _discr := f s ;
match f s with
| (t , s' ) => Spec.validate spec (env_r + r' ) s' โง motive t r' rw [ spec : Spec T : Type block_until : spec .State โ Bool f : spec .State โ T ร spec .Stater : spec .Reservationassuming : spec .State โ Bool motive : T โ spec .Reservation โ Prop f_valid : โ (env_r : spec .Reservation ) (s : spec .State ),
block_until s = true โ
Spec.validate spec (env_r + r ) s โ
โ r' ,
let _discr := f s ;
match f s with
| (t , s' ) => Spec.validate spec (env_r + r' ) s' โง motive t r' valid : {spec : Spec } โ
{T : Type } โ TaskM spec T โ spec .Reservation โ (spec .State โ Bool ) โ (T โ spec .Reservation โ Prop ) โ Prop validspec : Spec T : Type block_until : spec .State โ Bool f : spec .State โ T ร spec .Stater : spec .Reservationassuming : spec .State โ Bool motive : T โ spec .Reservation โ Prop f_valid : โ (env_r : spec .Reservation ) (s : spec .State ),
block_until s = true โ
Spec.validate spec (env_r + r ) s โ
โ r' ,
let _discr := f s ;
match f s with
| (t , s' ) => Spec.validate spec (env_r + r' ) s' โง motive t r' ] spec : Spec T : Type block_until : spec .State โ Bool f : spec .State โ T ร spec .Stater : spec .Reservationassuming : spec .State โ Bool motive : T โ spec .Reservation โ Prop f_valid : โ (env_r : spec .Reservation ) (s : spec .State ),
block_until s = true โ
Spec.validate spec (env_r + r ) s โ
โ r' ,
let _discr := f s ;
match f s with
| (t , s' ) => Spec.validate spec (env_r + r' ) s' โง motive t r'
spec : Spec T : Type block_until : spec .State โ Bool f : spec .State โ T ร spec .Stater : spec .Reservationassuming : spec .State โ Bool motive : T โ spec .Reservation โ Prop f_valid : โ (env_r : spec .Reservation ) (s : spec .State ),
block_until s = true โ
Spec.validate spec (env_r + r ) s โ
โ r' ,
let _discr := f s ;
match f s with
| (t , s' ) => Spec.validate spec (env_r + r' ) s' โง motive t r' intro env_r s _ initial_valid spec : Spec T : Type block_until : spec .State โ Bool f : spec .State โ T ร spec .Stater : spec .Reservationassuming : spec .State โ Bool motive : T โ spec .Reservation โ Prop f_valid : โ (env_r : spec .Reservation ) (s : spec .State ),
block_until s = true โ
Spec.validate spec (env_r + r ) s โ
โ r' ,
let _discr := f s ;
match f s with
| (t , s' ) => Spec.validate spec (env_r + r' ) s' โง motive t r' env_r : spec .Reservations : spec .Stateinitial_valid : Spec.validate spec (env_r + r ) s
spec : Spec T : Type block_until : spec .State โ Bool f : spec .State โ T ร spec .Stater : spec .Reservationassuming : spec .State โ Bool motive : T โ spec .Reservation โ Prop f_valid : โ (env_r : spec .Reservation ) (s : spec .State ),
block_until s = true โ
Spec.validate spec (env_r + r ) s โ
โ r' ,
let _discr := f s ;
match f s with
| (t , s' ) => Spec.validate spec (env_r + r' ) s' โง motive t r' simp only [ iterate_blocking_rmr , initial_valid , true_and : โ (p : Prop ), (True โง p ) = p true_and] spec : Spec T : Type block_until : spec .State โ Bool f : spec .State โ T ร spec .Stater : spec .Reservationassuming : spec .State โ Bool motive : T โ spec .Reservation โ Prop f_valid : โ (env_r : spec .Reservation ) (s : spec .State ),
block_until s = true โ
Spec.validate spec (env_r + r ) s โ
โ r' ,
let _discr := f s ;
match f s with
| (t , s' ) => Spec.validate spec (env_r + r' ) s' โง motive t r' env_r : spec .Reservations : spec .Stateinitial_valid : Spec.validate spec (env_r + r ) s
spec : Spec T : Type block_until : spec .State โ Bool f : spec .State โ T ร spec .Stater : spec .Reservationassuming : spec .State โ Bool motive : T โ spec .Reservation โ Prop f_valid : โ (env_r : spec .Reservation ) (s : spec .State ),
block_until s = true โ
Spec.validate spec (env_r + r ) s โ
โ r' ,
let _discr := f s ;
match f s with
| (t , s' ) => Spec.validate spec (env_r + r' ) s' โง motive t r' exists r spec : Spec T : Type block_until : spec .State โ Bool f : spec .State โ T ร spec .Stater : spec .Reservationassuming : spec .State โ Bool motive : T โ spec .Reservation โ Prop f_valid : โ (env_r : spec .Reservation ) (s : spec .State ),
block_until s = true โ
Spec.validate spec (env_r + r ) s โ
โ r' ,
let _discr := f s ;
match f s with
| (t , s' ) => Spec.validate spec (env_r + r' ) s' โง motive t r' env_r : spec .Reservations : spec .Stateinitial_valid : Spec.validate spec (env_r + r ) s
spec : Spec T : Type block_until : spec .State โ Bool f : spec .State โ T ร spec .Stater : spec .Reservationassuming : spec .State โ Bool motive : T โ spec .Reservation โ Prop f_valid : โ (env_r : spec .Reservation ) (s : spec .State ),
block_until s = true โ
Spec.validate spec (env_r + r ) s โ
โ r' ,
let _discr := f s ;
match f s with
| (t , s' ) => Spec.validate spec (env_r + r' ) s' โง motive t r' exact โจ initial_valid , valid_rmr : โ {spec : Spec } {T : Type } {f : spec .State โ T ร spec .State } {r : spec .Reservation } {assuming : spec .State โ Bool }
{motive : T โ spec .Reservation โ Prop },
(โ (env_r : spec .Reservation ) (s : spec .State ),
assuming s = true โ
Spec.validate spec (env_r + r ) s โ
โ r' ,
let _discr := f s ;
match f s with
| (t , s' ) => Spec.validate spec (env_r + r' ) s' โง motive t r' ) โ
valid (atomic_read_modify_read f ) r assuming motive valid_rmr f_valid : โ (env_r : spec .Reservation ) (s : spec .State ),
block_until s = true โ
Spec.validate spec (env_r + r ) s โ
โ r' ,
let _discr := f s ;
match f s with
| (t , s' ) => Spec.validate spec (env_r + r' ) s' โง motive t r' f_valid โฉ
end Mt.TaskM