statement stringlengths 6 506 | proof stringlengths 0 2.66k | type stringclasses 17
values | symbolic_name stringlengths 1 55 | library stringclasses 5
values | filename stringclasses 22
values | imports listlengths 2 12 | deps listlengths 0 20 | docstring stringlengths 0 1.35k | source_url stringclasses 1
value | commit stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|
contract_equ `(c1 : contract i Ω1) `(c2 : contract i Ω2)
: Type | :=
| mk_contract_equ (f : Ω1 -> Ω2) (g : Ω2 -> Ω1)
(iso1 : forall x, f (g x) = x) (iso2 : forall x, g (f x) = x)
(caller_equ : contract_caller_equ c1 c2 f)
(callee_equ : contract_callee_equ c1 c2 f)
(witness_equ : contract_witness_equ c1 c2 f)
: contract_equ c1 c2. | Inductive | contract_equ | Core | theories/Core/Contract.v | [
"Coq",
"Setoid",
"Morphisms",
"ExtLib",
"StateMonad",
"MonadState",
"MonadTrans",
"FreeSpec.Core",
"Interface",
"Impure",
"Semantics",
"Component"
] | [
"contract",
"contract_callee_equ",
"contract_caller_equ",
"contract_witness_equ"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
contract_iso_lr `(c1 : contract i Ω1) `(c2 : contract i Ω2)
(equ : contract_equ c1 c2) (ω1 : Ω1)
: Ω2 | :=
match equ with
| @mk_contract_equ _ _ _ _ _ f _ _ _ _ _ _ => f ω1
end. | Definition | contract_iso_lr | Core | theories/Core/Contract.v | [
"Coq",
"Setoid",
"Morphisms",
"ExtLib",
"StateMonad",
"MonadState",
"MonadTrans",
"FreeSpec.Core",
"Interface",
"Impure",
"Semantics",
"Component"
] | [
"contract",
"contract_equ"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
contract_iso_rl `(c1 : contract i Ω1) `(c2 : contract i Ω2)
(equ : contract_equ c1 c2) (ω2 : Ω2)
: Ω1 | :=
match equ with
| @mk_contract_equ _ _ _ _ _ _ g _ _ _ _ _ => g ω2
end. | Definition | contract_iso_rl | Core | theories/Core/Contract.v | [
"Coq",
"Setoid",
"Morphisms",
"ExtLib",
"StateMonad",
"MonadState",
"MonadTrans",
"FreeSpec.Core",
"Interface",
"Impure",
"Semantics",
"Component"
] | [
"contract",
"contract_equ"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
contract_equ_refl `(c : contract i Ω)
: contract_equ c c. | Proof.
apply mk_contract_equ with (f:=fun x => x) (g:=fun x => x); auto.
+ now intros ω α p.
+ now intros ω α p x.
+ now intros ω α p x.
Defined. | Lemma | contract_equ_refl | Core | theories/Core/Contract.v | [
"Coq",
"Setoid",
"Morphisms",
"ExtLib",
"StateMonad",
"MonadState",
"MonadTrans",
"FreeSpec.Core",
"Interface",
"Impure",
"Semantics",
"Component"
] | [
"contract",
"contract_equ"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
contract_equ_sym `(c1 : contract i Ω1) `(c2 : contract i Ω2)
(equ : contract_equ c1 c2)
: contract_equ c2 c1. | Proof.
induction equ.
apply mk_contract_equ with (f0:=g) (g0:=f).
+ apply iso2.
+ apply iso1.
+ intros ω α p.
transitivity (caller_obligation c2 (f (g ω)) p).
++ now rewrite iso1.
++ now symmetry.
+ intros ω α p x.
transitivity (callee_obligation c2 (f (g ω)) p x).
++ now rewrite iso1.
... | Lemma | contract_equ_sym | Core | theories/Core/Contract.v | [
"Coq",
"Setoid",
"Morphisms",
"ExtLib",
"StateMonad",
"MonadState",
"MonadTrans",
"FreeSpec.Core",
"Interface",
"Impure",
"Semantics",
"Component"
] | [
"contract",
"contract_equ"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
contract_equ_trans `(c1 : contract i Ω1) `(c2 : contract i Ω2)
`(c3 : contract i Ω3)
`(is_equ12 : contract_equ c1 c2)
`(is_equ23 : contract_equ c2 c3)
: contract_equ c1 c3. | Proof.
destruct is_equ12 as [f12 g21 isofg12 isogf12 caller_equ12 callee_equ12 witness_equ12].
destruct is_equ23 as [f23 g32 isofg23 isogf23 caller_equ23 callee_equ23 witness_equ23].
apply mk_contract_equ
with (f:=fun x => f23 (f12 x)) (g:=fun x => g21 (g32 x)).
+ setoid_rewrite isofg12.
now setoid_rewr... | Lemma | contract_equ_trans | Core | theories/Core/Contract.v | [
"Coq",
"Setoid",
"Morphisms",
"ExtLib",
"StateMonad",
"MonadState",
"MonadTrans",
"FreeSpec.Core",
"Interface",
"Impure",
"Semantics",
"Component"
] | [
"contract",
"contract_equ"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
gen_witness_update `{MayProvide ix i} {Ω α} (c : contract i Ω)
(ω : Ω) (e : ix α) (x : α)
: Ω | :=
match proj_p e with
| Some e => witness_update c ω e x
| None => ω
end. | Definition | gen_witness_update | Core | theories/Core/Contract.v | [
"Coq",
"Setoid",
"Morphisms",
"ExtLib",
"StateMonad",
"MonadState",
"MonadTrans",
"FreeSpec.Core",
"Interface",
"Impure",
"Semantics",
"Component"
] | [
"MayProvide",
"contract"
] | As we compose interfaces and operational semantics, we can easily compose
contracts together, by means of the [contractprod] operator. Given [i] and [j]
two interfaces, if we can reason about [i] and [j] independently (e.g., the
caller obligations of [j] do not vary when we use [i]), then we can compose
... | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 |
gen_caller_obligation `{MayProvide ix i} {Ω α} (c : contract i Ω)
(ω : Ω) (e : ix α)
: Prop | :=
match proj_p e with
| Some e => caller_obligation c ω e
| None => True
end. | Definition | gen_caller_obligation | Core | theories/Core/Contract.v | [
"Coq",
"Setoid",
"Morphisms",
"ExtLib",
"StateMonad",
"MonadState",
"MonadTrans",
"FreeSpec.Core",
"Interface",
"Impure",
"Semantics",
"Component"
] | [
"MayProvide",
"contract"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
gen_callee_obligation `{MayProvide ix i} {Ω α} (c : contract i Ω)
(ω : Ω) (e : ix α) (x : α)
: Prop | :=
match proj_p e with
| Some e => callee_obligation c ω e x
| None => True
end. | Definition | gen_callee_obligation | Core | theories/Core/Contract.v | [
"Coq",
"Setoid",
"Morphisms",
"ExtLib",
"StateMonad",
"MonadState",
"MonadTrans",
"FreeSpec.Core",
"Interface",
"Impure",
"Semantics",
"Component"
] | [
"MayProvide",
"contract"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
contractprod `{Provide ix i, Provide ix j} {Ωi Ωj}
(ci : contract i Ωi) (cj : contract j Ωj)
: contract ix (Ωi * Ωj) | :=
{| witness_update := fun (ω : Ωi * Ωj) (α : Type) (e : ix α) (x : α) =>
(gen_witness_update ci (fst ω) e x, gen_witness_update cj (snd ω) e x)
; caller_obligation := fun (ω : Ωi * Ωj) (α : Type) (e : ix α) =>
gen_caller_obligation ci (fst ω) e /\ gen_caller_obliga... | Definition | contractprod | Core | theories/Core/Contract.v | [
"Coq",
"Setoid",
"Morphisms",
"ExtLib",
"StateMonad",
"MonadState",
"MonadTrans",
"FreeSpec.Core",
"Interface",
"Impure",
"Semantics",
"Component"
] | [
"Provide",
"contract",
"gen_callee_obligation",
"gen_caller_obligation",
"gen_witness_update"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
sharedcontractprod `{Provide ix i, Provide ix j}
`(ci : contract i Ω) (cj : contract j Ω)
: contract ix Ω | :=
{|
witness_update :=
fun (ω : Ω) (α : Type) (e : ix α) (x : α) =>
(* we need to check [i] before [j] because [sharedcontractprod]
will be right associative *)
match proj_p (i:=i) e with
| Some e => witness_update ci ω e x
| _ => match proj_p (i:=j) e with
| Some ... | Definition | sharedcontractprod | Core | theories/Core/Contract.v | [
"Coq",
"Setoid",
"Morphisms",
"ExtLib",
"StateMonad",
"MonadState",
"MonadTrans",
"FreeSpec.Core",
"Interface",
"Impure",
"Semantics",
"Component"
] | [
"Provide",
"contract",
"gen_callee_obligation",
"gen_caller_obligation"
] | FIXME: Should be [StrictProvide2 ix i j] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 |
store_update (s : Type) | :=
fun (x : s) (α : Type) (e : STORE s α) (_ : α) =>
match e with
| Get => x
| Put x' => x'
end. | Definition | store_update | Core | theories/Core/Contract.v | [
"Coq",
"Setoid",
"Morphisms",
"ExtLib",
"StateMonad",
"MonadState",
"MonadTrans",
"FreeSpec.Core",
"Interface",
"Impure",
"Semantics",
"Component"
] | [
"STORE"
] | Finally, and as an example, we define a contract for the interface
[STORE s] we discuss in [FreeSpec.Core.Impure]. As a reminder, the
interface is defined as follows:
<<
Inductive STORE (s : Type) : interface :=
| Get : STORE s s
| Put (x : s) : STORE s unit.
>>
For [STORE s], the best witness is the act... | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 |
o_callee_store (s : Type) (x : s) : forall (α : Type), STORE s α -> α -> Prop | :=
| get_o_callee (x' : s) (equ : x = x') : o_callee_store s x s Get x'
| put_o_callee (x' : s) (u : unit) : o_callee_store s x unit (Put x') u. | Inductive | o_callee_store | Core | theories/Core/Contract.v | [
"Coq",
"Setoid",
"Morphisms",
"ExtLib",
"StateMonad",
"MonadState",
"MonadTrans",
"FreeSpec.Core",
"Interface",
"Impure",
"Semantics",
"Component"
] | [
"STORE"
] | Assuming the mutable variable is being initialized prior to any impure
computation interpretation, we do not have any obligations over the use of
[STORE s] primitives. We will get back to this assertion once we have
defined our contract, but in the meantime, we define its callee obligation.
The logic ... | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 |
store_specs (s : Type) : contract (STORE s) s | :=
{| witness_update := store_update s
; caller_obligation := no_caller_obligation
; callee_obligation := o_callee_store s
|}. | Definition | store_specs | Core | theories/Core/Contract.v | [
"Coq",
"Setoid",
"Morphisms",
"ExtLib",
"StateMonad",
"MonadState",
"MonadTrans",
"FreeSpec.Core",
"Interface",
"Impure",
"Semantics",
"Component"
] | [
"STORE",
"contract",
"no_caller_obligation",
"o_callee_store",
"store_update"
] | The actual contract can therefore be defined as follows: | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 |
hoare (Σ : Type) (α : Type) : Type | :=
mk_hoare { pre : Σ -> Prop
; post : Σ -> α -> Σ -> Prop
}. | Record | hoare | Core | theories/Core/Hoare.v | [
"ExtLib",
"Functor",
"Applicative",
"Monad",
"FreeSpec.Core",
"Interface",
"Impure",
"Contract"
] | [] | * Definition | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 |
hoare_pure {Σ α} (x : α) : hoare Σ α | :=
mk_hoare (fun _ => True) (fun s y s' => x = y /\ s = s'). | Definition | hoare_pure | Core | theories/Core/Hoare.v | [
"ExtLib",
"Functor",
"Applicative",
"Monad",
"FreeSpec.Core",
"Interface",
"Impure",
"Contract"
] | [
"hoare"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
hoare_bind {Σ α β} (h : hoare Σ α) (k : α -> hoare Σ β) : hoare Σ β | :=
mk_hoare (fun s => pre h s /\ (forall x s', post h s x s' -> pre (k x) s'))
(fun s x s'' => exists y s', post h s y s' /\ post (k y) s' x s''). | Definition | hoare_bind | Core | theories/Core/Hoare.v | [
"ExtLib",
"Functor",
"Applicative",
"Monad",
"FreeSpec.Core",
"Interface",
"Impure",
"Contract"
] | [
"hoare"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
hoare_map {Σ α β} (f : α -> β) (h : hoare Σ α) : hoare Σ β | :=
hoare_bind h (fun x => hoare_pure (f x)). | Definition | hoare_map | Core | theories/Core/Hoare.v | [
"ExtLib",
"Functor",
"Applicative",
"Monad",
"FreeSpec.Core",
"Interface",
"Impure",
"Contract"
] | [
"hoare",
"hoare_bind",
"hoare_pure"
] | ** Functor | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 |
hoare_Functor Σ : Functor (hoare Σ) | :=
{ fmap := fun _ _ => hoare_map }. | Instance | hoare_Functor | Core | theories/Core/Hoare.v | [
"ExtLib",
"Functor",
"Applicative",
"Monad",
"FreeSpec.Core",
"Interface",
"Impure",
"Contract"
] | [
"hoare",
"hoare_map"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
hoare_apply {Σ α β} (hf : hoare Σ (α -> β)) (h : hoare Σ α)
: hoare Σ β | :=
hoare_bind hf (fun f => hoare_map f h). | Definition | hoare_apply | Core | theories/Core/Hoare.v | [
"ExtLib",
"Functor",
"Applicative",
"Monad",
"FreeSpec.Core",
"Interface",
"Impure",
"Contract"
] | [
"hoare",
"hoare_bind",
"hoare_map"
] | ** Applicative | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 |
hoare_Applicative Σ : Applicative (hoare Σ) | :=
{ ap := fun _ _ => hoare_apply
; pure := fun _ => hoare_pure
}. | Instance | hoare_Applicative | Core | theories/Core/Hoare.v | [
"ExtLib",
"Functor",
"Applicative",
"Monad",
"FreeSpec.Core",
"Interface",
"Impure",
"Contract"
] | [
"hoare",
"hoare_apply",
"hoare_pure"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
hoare_Monad Σ : Monad (hoare Σ) | :=
{ ret := @hoare_pure Σ; bind := @hoare_bind Σ }. | Instance | hoare_Monad | Core | theories/Core/Hoare.v | [
"ExtLib",
"Functor",
"Applicative",
"Monad",
"FreeSpec.Core",
"Interface",
"Impure",
"Contract"
] | [
"hoare",
"hoare_bind",
"hoare_pure"
] | ** Monad | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 |
interface_to_hoare `{MayProvide ix i} `(c : contract i Ω) : ix ~> hoare Ω | :=
fun a e =>
{| pre := fun ω => gen_caller_obligation c ω e
; post := fun ω x ω' => gen_callee_obligation c ω e x
/\ ω' = gen_witness_update c ω e x
|}. | Definition | interface_to_hoare | Core | theories/Core/Hoare.v | [
"ExtLib",
"Functor",
"Applicative",
"Monad",
"FreeSpec.Core",
"Interface",
"Impure",
"Contract"
] | [
"MayProvide",
"contract",
"gen_callee_obligation",
"gen_caller_obligation",
"gen_witness_update",
"hoare"
] | * Reasoning about Programs | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 |
to_hoare `{MayProvide ix i} `(c : contract i Ω)
: impure ix ~> hoare Ω | :=
impure_lift (interface_to_hoare c). | Definition | to_hoare | Core | theories/Core/Hoare.v | [
"ExtLib",
"Functor",
"Applicative",
"Monad",
"FreeSpec.Core",
"Interface",
"Impure",
"Contract"
] | [
"MayProvide",
"contract",
"hoare",
"impure",
"impure_lift",
"interface_to_hoare"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
hoare_eq {Σ α} (h1 h2 : hoare Σ α) : Prop | :=
| mk_hoare_eq
(pre_eq : forall s, pre h1 s <-> pre h2 s)
(post_eq : forall s x s', post h1 s x s' <-> post h2 s x s')
: hoare_eq h1 h2. | Inductive | hoare_eq | Core | theories/Core/HoareFacts.v | [
"FreeSpec.Core",
"Interface",
"ImpureFacts",
"Contract",
"Hoare"
] | [
"hoare"
] | * Equivalence Relation | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 |
hoare_Equivalence Σ α : @Equivalence (hoare Σ α) hoare_eq. | Next Obligation.
easy.
Qed. | Instance | hoare_Equivalence | Core | theories/Core/HoareFacts.v | [
"FreeSpec.Core",
"Interface",
"ImpureFacts",
"Contract",
"Hoare"
] | [
"hoare",
"hoare_eq"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
pre_Proper Σ α : Proper (hoare_eq ==> eq ==> iff) (@pre Σ α). | Next Obligation.
add_morphism_tactic.
intros h1 h2 equ s.
apply equ.
Qed. | Instance | pre_Proper | Core | theories/Core/HoareFacts.v | [
"FreeSpec.Core",
"Interface",
"ImpureFacts",
"Contract",
"Hoare"
] | [
"hoare_eq"
] | * Proper Instances | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 |
post_Proper Σ α : Proper (hoare_eq ==> eq ==> eq ==> eq ==> iff) (@post Σ α). | Next Obligation.
add_morphism_tactic.
intros h1 h2 equ s x s'.
apply equ.
Qed. | Instance | post_Proper | Core | theories/Core/HoareFacts.v | [
"FreeSpec.Core",
"Interface",
"ImpureFacts",
"Contract",
"Hoare"
] | [
"hoare_eq"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
to_hoare_Proper ix i Ω c α MP
: Proper (impure_eq ==> hoare_eq) (@to_hoare ix i MP Ω c α). | Next Obligation.
add_morphism_tactic.
intros p q equ.
induction equ.
+ reflexivity.
+ constructor.
++ intros ω.
cbn in *.
setoid_rewrite H.
reflexivity.
++ intros ω x ω'.
cbn in *.
setoid_rewrite H.
reflexivity.
Qed. | Instance | to_hoare_Proper | Core | theories/Core/HoareFacts.v | [
"FreeSpec.Core",
"Interface",
"ImpureFacts",
"Contract",
"Hoare"
] | [
"hoare_eq",
"impure_eq",
"to_hoare"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
to_hoare_step `{MayProvide ix i} `(c : contract i Ω)
`(e : ix a) `(f : a -> impure ix a)
`(hpre : pre (to_hoare c (request_then e f)) ω)
(x : a) (step : gen_callee_obligation c ω e x)
: pre (to_hoare c (f x)) (gen_witness_update c ω e x). | Proof.
destruct hpre as [hbefore hafter].
apply hafter.
cbn.
unfold gen_callee_obligation, gen_witness_update in *.
now destruct proj_p.
Qed. | Lemma | to_hoare_step | Core | theories/Core/HoareFacts.v | [
"FreeSpec.Core",
"Interface",
"ImpureFacts",
"Contract",
"Hoare"
] | [
"MayProvide",
"contract",
"gen_callee_obligation",
"gen_witness_update",
"impure",
"step",
"to_hoare"
] | * General Lemmas | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 |
to_hoare_pre_bind_assoc `{MayProvide ix i} `(c : contract i Ω)
`(p : impure ix a) `(Hp : pre (to_hoare c p) ω)
`(f : a -> impure ix b)
(run : forall (x : a) (ω' : Ω),
post (to_hoare c p) ω x ω' -> pre (to_hoare c (f x)) ω')
: pre (to_hoare c (p >>= f)) ω. | Proof.
revert ω Hp run.
induction p; intros ω Hp run.
+ now apply run.
+ cbn in Hp.
destruct Hp as [He Hn].
change (request_then e f0 >>= f)
with (request_then e (fun x => f0 x >>= f)).
split.
++ exact He.
++ intros x ω' Hpost.
specialize Hn with x ω'.
destruct Hpost.
... | Lemma | to_hoare_pre_bind_assoc | Core | theories/Core/HoareFacts.v | [
"FreeSpec.Core",
"Interface",
"ImpureFacts",
"Contract",
"Hoare"
] | [
"MayProvide",
"contract",
"gen_witness_update",
"impure",
"to_hoare"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
to_hoare_post_bind_assoc `{MayProvide ix i} `(c : contract i Ω)
`(p : impure ix a) `(f : a -> impure ix b)
`(Hp : post (to_hoare c (impure_bind p f)) ω x ω')
: exists y ω'',
post (to_hoare c p) ω y ω'' /\ post (to_hoare c $ f y) ω'' x ω'. | Proof.
revert ω Hp.
induction p; intros ω Hp.
+ now exists x0, ω.
+ destruct Hp as [y [ω'' [Hp1 Hp2]]].
apply H0 in Hp2.
destruct Hp2 as [z [ω''' [Hp2 Hp3]]].
exists z, ω'''.
split; [| apply Hp3].
exists y, ω''.
now split.
Qed. | Lemma | to_hoare_post_bind_assoc | Core | theories/Core/HoareFacts.v | [
"FreeSpec.Core",
"Interface",
"ImpureFacts",
"Contract",
"Hoare"
] | [
"MayProvide",
"contract",
"impure",
"impure_bind",
"to_hoare"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
to_hoare_contractprod `{Provide ix i, Provide ix j}
`(ci : contract i Ωi) `(cj : contract j Ωj)
`(p : impure ix a)
`(prei : pre (to_hoare ci p) ωi) `(prej : pre (to_hoare cj p) ωj)
: pre (to_hoare (ci * cj) p) (ωi, ωj). | Proof.
revert ωi prei ωj prej.
induction p; intros ωi prei ωj prej.
+ auto.
+ destruct prei as [calleri Hcalleei].
destruct prej as [callerj Hcalleej].
split.
++ now split.
++ intros x [ωi' ωj'] [[calleei calleej] equωs].
cbn in equωs.
inversion equωs; subst.
apply H3.
... | Lemma | to_hoare_contractprod | Core | theories/Core/HoareFacts.v | [
"FreeSpec.Core",
"Interface",
"ImpureFacts",
"Contract",
"Hoare"
] | [
"Provide",
"contract",
"impure",
"to_hoare"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
contract_equ_pre `(c1 : contract i Ω1) `(c2 : contract i Ω2)
`(equ : contract_equ c1 c2) (ω1 : Ω1)
`(p : impure i a)
: pre (to_hoare c1 p) ω1 <-> pre (to_hoare c2 p) (contract_iso_lr equ ω1). | Proof.
induction equ.
revert ω1.
induction p; intros ω1.
+ now split.
+ cbn.
rewrite (caller_equ ω1 β e).
setoid_rewrite (callee_equ ω1 β e).
split.
++ intros [ocaller onext].
split; auto.
intros x ω1' [ocallee owitness].
rewrite owitness.
rewrite <- witness_equ.
... | Lemma | contract_equ_pre | Core | theories/Core/HoareFacts.v | [
"FreeSpec.Core",
"Interface",
"ImpureFacts",
"Contract",
"Hoare"
] | [
"contract",
"contract_equ",
"contract_iso_lr",
"impure",
"to_hoare"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
contract_equ_post `(c1 : contract i Ω1) `(c2 : contract i Ω2)
`(equ : contract_equ c1 c2) (ω1 ω1' : Ω1)
`(p : impure i a) (x : a)
(post1 : post (to_hoare c1 p) ω1 x ω1')
: post (to_hoare c2 p) (contract_iso_lr equ ω1) x (contract_iso_lr equ ω1'). | Proof.
induction equ.
cbn in *.
revert x ω1 ω1' post1.
induction p; intros y ω1 ω1' post1.
+ destruct post1 as [xequ ω1equ].
cbn.
now subst.
+ cbn in post1.
destruct post1 as [x [ω1'' [[ocallee owitness] post1]]].
eapply H in post1.
exists x.
exists (f ω1'').
split; auto.
cbn... | Lemma | contract_equ_post | Core | theories/Core/HoareFacts.v | [
"FreeSpec.Core",
"Interface",
"ImpureFacts",
"Contract",
"Hoare"
] | [
"contract",
"contract_equ",
"contract_iso_lr",
"impure",
"repeat",
"to_hoare"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
impure (i : interface) (α : Type) : Type | :=
| local (x : α) : impure i α
| request_then {β} (e : i β) (f : β -> impure i α) : impure i α. | Inductive | impure | Core | theories/Core/Impure.v | [
"Coq",
"Program",
"Setoid",
"Morphisms",
"ExtLib",
"MonadState",
"FreeSpec.Core",
"Interface"
] | [
"interface"
] | The [impure] monad is an inductive datatype with two parameters: the
interface [i] to be used, and the type [α] of the result of the computation.
The fact that [impure] is inductive rather than co-inductive means it is not
possible to describe infinite computations. This also means it is possible
to in... | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 |
impure_bind {i α β} (p : impure i α) (f : α -> impure i β) : impure i β | :=
match p with
| local x => f x
| request_then e g => request_then e (fun x => impure_bind (g x) f)
end. | Fixpoint | impure_bind | Core | theories/Core/Impure.v | [
"Coq",
"Program",
"Setoid",
"Morphisms",
"ExtLib",
"MonadState",
"FreeSpec.Core",
"Interface"
] | [
"impure"
] | We then provide the necessary instances of the <<coq-prelude>> Monad
typeclasses hierarchy. | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 |
impure_map {i α β} (f : α -> β) (p : impure i α) : impure i β | :=
impure_bind p (fun x => local (f x)). | Definition | impure_map | Core | theories/Core/Impure.v | [
"Coq",
"Program",
"Setoid",
"Morphisms",
"ExtLib",
"MonadState",
"FreeSpec.Core",
"Interface"
] | [
"impure",
"impure_bind"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
impure_Functor i : Functor (impure i) | :=
{ fmap := @impure_map i
}. | Instance | impure_Functor | Core | theories/Core/Impure.v | [
"Coq",
"Program",
"Setoid",
"Morphisms",
"ExtLib",
"MonadState",
"FreeSpec.Core",
"Interface"
] | [
"impure",
"impure_map"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
impure_pure {i α} (x : α) : impure i α | := local x. | Definition | impure_pure | Core | theories/Core/Impure.v | [
"Coq",
"Program",
"Setoid",
"Morphisms",
"ExtLib",
"MonadState",
"FreeSpec.Core",
"Interface"
] | [
"impure"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
impure_apply {i α β} (p : impure i (α -> β)) (q : impure i α) : impure i β | :=
impure_bind p (fun f => fmap f q). | Definition | impure_apply | Core | theories/Core/Impure.v | [
"Coq",
"Program",
"Setoid",
"Morphisms",
"ExtLib",
"MonadState",
"FreeSpec.Core",
"Interface"
] | [
"impure",
"impure_bind"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
impure_Applicative i : Applicative (impure i) | :=
{ pure := @impure_pure i
; ap := @impure_apply i
}. | Instance | impure_Applicative | Core | theories/Core/Impure.v | [
"Coq",
"Program",
"Setoid",
"Morphisms",
"ExtLib",
"MonadState",
"FreeSpec.Core",
"Interface"
] | [
"impure",
"impure_apply",
"impure_pure"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
impure_Monad (i : interface) : Monad (impure i) | :=
{ ret := @impure_pure i
; bind := @impure_bind i
}. | Instance | impure_Monad | Core | theories/Core/Impure.v | [
"Coq",
"Program",
"Setoid",
"Morphisms",
"ExtLib",
"MonadState",
"FreeSpec.Core",
"Interface"
] | [
"impure",
"impure_bind",
"impure_pure",
"interface"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
request `{Provide ix i} {α} (e : i α) : impure ix α | :=
request_then (inj_p e) (fun x => pure x). | Definition | request | Core | theories/Core/Impure.v | [
"Coq",
"Program",
"Setoid",
"Morphisms",
"ExtLib",
"MonadState",
"FreeSpec.Core",
"Interface"
] | [
"Provide",
"impure"
] | FreeSpec users shall not use the [impure] monad constructors directly. The
[pure] function from the [Applicative] typeclass allows for defining pure
computations which do not depend on any impure primitive. The [bind]
function from the [Monad] typeclass allows for seamlessly combine impure
computation... | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 |
store_monad_state (s : Type) (ix : interface) `{Provide ix (STORE s)}
: MonadState s (impure ix) | :=
{ put := fun (x : s) => request (Put x)
; get := request Get
}. | Instance | store_monad_state | Core | theories/Core/Impure.v | [
"Coq",
"Program",
"Setoid",
"Morphisms",
"ExtLib",
"MonadState",
"FreeSpec.Core",
"Interface"
] | [
"Provide",
"STORE",
"impure",
"interface",
"request"
] | Note: there have been attempts to turn [request] into a typeclass
function (to seamlessly use [request] with a [MonadTrans] instance such as
[state_t]). The reason why it has not been kept into the codebase is that
the flexibility it gives for writing code has a real impact on the
verification process. ... | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 |
impure_lift `{Monad m} `(l : i ~> m) : impure i ~> m | :=
fix aux a (p : impure i a) :=
match p with
| local x => ret x
| request_then e f => let* x := l _ e in aux a (f x)
end. | Definition | impure_lift | Core | theories/Core/Impure.v | [
"Coq",
"Program",
"Setoid",
"Morphisms",
"ExtLib",
"MonadState",
"FreeSpec.Core",
"Interface"
] | [
"impure"
] | * Lift | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 |
impure_eq {i α} : impure i α -> impure i α -> Prop | :=
(** - Two impure computations are equivalent if and only if they compute the
exact same term (wrt. Coq [eq] function). *)
| local_eq (x : α) : impure_eq (local x) (local x)
(** - Two computations which consist in requesting the interpretation of an
primitive and passing the result to a monadic continu... | Inductive | impure_eq | Core | theories/Core/ImpureFacts.v | [
"FreeSpec.Core",
"Impure"
] | [
"function_eq",
"impure"
] | The definition of [impure_equiv] is two-fold. | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 |
impure_Equivalence i α : @Equivalence (impure i α) impure_eq := {}. | Next Obligation.
intros p.
induction p; constructor.
intros x.
apply H.
Qed. | Instance | impure_Equivalence | Core | theories/Core/ImpureFacts.v | [
"FreeSpec.Core",
"Impure"
] | [
"impure",
"impure_eq"
] | The definition of [impure_equiv] is very similar to [eq], with the exception
of the treatment of the continuation. There is no much effort to put into
proving this is indeed a proper equivalence. | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 |
change_request_then | :=
match goal with
| |- (request_then ?e ?f === request_then ?e ?g)%impure =>
let R := fresh "R" in
assert (R: function_eq impure_eq f g); [ intros ?x | rewrite R; clear R ]
end. | Ltac | change_request_then | Core | theories/Core/ImpureFacts.v | [
"FreeSpec.Core",
"Impure"
] | [
"function_eq",
"impure",
"impure_eq"
] | ** Proper Instances | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 |
change_impure_bind | :=
match goal with
| |- (impure_bind ?e ?f === impure_bind ?e ?g)%impure =>
let R := fresh "R" in
assert (R: function_eq impure_eq f g); [ intros ?x | now rewrite R ]
end. | Ltac | change_impure_bind | Core | theories/Core/ImpureFacts.v | [
"FreeSpec.Core",
"Impure"
] | [
"function_eq",
"impure",
"impure_bind",
"impure_eq"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
request_then_Proper i α β
: Proper (eq ==> function_eq impure_eq ==> impure_eq) (@request_then i α β). | Next Obligation.
add_morphism_tactic.
intros e f g equ.
constructor.
intros y.
specialize (equ y).
now rewrite equ.
Qed. | Instance | request_then_Proper | Core | theories/Core/ImpureFacts.v | [
"FreeSpec.Core",
"Impure"
] | [
"function_eq",
"impure_eq"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
impure_bind_Proper i α β
: Proper (impure_eq ==> function_eq impure_eq ==> impure_eq) (@impure_bind i α β). | Next Obligation.
add_morphism_tactic.
intros x y equ1 f g equ2.
induction equ1.
+ cbn.
now rewrite (equ2 x).
+ cbn.
constructor.
intros x.
apply H.
Qed. | Instance | impure_bind_Proper | Core | theories/Core/ImpureFacts.v | [
"FreeSpec.Core",
"Impure"
] | [
"function_eq",
"impure_bind",
"impure_eq"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
impure_map_Proper i α β
: Proper (function_eq eq ==> impure_eq ==> impure_eq) (@impure_map i α β). | Proof.
add_morphism_tactic.
intros f g equf p q equp.
unfold impure_map.
rewrite equp.
change_impure_bind.
now rewrite equf.
Qed. | Instance | impure_map_Proper | Core | theories/Core/ImpureFacts.v | [
"FreeSpec.Core",
"Impure"
] | [
"change_impure_bind",
"function_eq",
"impure_eq",
"impure_map"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
impure_apply_Proper i α β
: Proper (impure_eq ==> impure_eq ==> impure_eq) (@impure_apply i α β). | Next Obligation.
add_morphism_tactic.
intros p q equ1 r s equ2.
unfold impure_apply.
rewrite equ1.
change_impure_bind.
cbn.
now rewrite equ2.
Qed. | Instance | impure_apply_Proper | Core | theories/Core/ImpureFacts.v | [
"FreeSpec.Core",
"Impure"
] | [
"change_impure_bind",
"impure_apply",
"impure_eq"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
impure_bind_local {i α} (p : impure i α)
: (impure_bind p (fun x => local x) === p)%impure. | Proof.
induction p.
+ reflexivity.
+ cbn.
change_request_then; [| reflexivity].
now rewrite H.
Qed. | Lemma | impure_bind_local | Core | theories/Core/ImpureFacts.v | [
"FreeSpec.Core",
"Impure"
] | [
"change_request_then",
"impure",
"impure_bind"
] | Monadic laws as defined in [ExtLib.Structures.MonadLaws] an related are
expressed against [eq], which is too strong in the general case, and in
[impure]’s case in particular. We could prove them using the functional
extensionality axiom, but we’d rather provide an alternative implementaiton
of these law... | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 |
impure_bind_assoc {i α β δ}
(p : impure i α) (f : α -> impure i β) (g : β -> impure i δ)
: (impure_bind (impure_bind p f) g
=== impure_bind p (fun x => impure_bind (f x) g))%impure. | Proof.
induction p; [reflexivity |].
cbn.
change_request_then; auto.
reflexivity.
Qed. | Lemma | impure_bind_assoc | Core | theories/Core/ImpureFacts.v | [
"FreeSpec.Core",
"Impure"
] | [
"change_request_then",
"impure",
"impure_bind"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
bind_request_then_assoc `(e : i a) `(f : a -> impure i b) `(g : b -> impure i c)
: request_then e f >>= g = request_then e (fun x => f x >>= g). | Proof.
reflexivity.
Qed. | Lemma | bind_request_then_assoc | Core | theories/Core/ImpureFacts.v | [
"FreeSpec.Core",
"Impure"
] | [
"impure"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
when {m : Type -> Type} `{Monad m} (cond : bool) `(p : m a) : m unit | :=
if cond then (p;; pure tt) else pure tt. | Definition | when | Core | theories/Core/Init.v | [
"Coq",
"Eqdep"
] | [] | * Utils Functions | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 |
ssubst | :=
lazymatch goal with
| [ H : existT _ _ _ = existT _ _ _ |- _ ]
=> apply Eqdep.EqdepTheory.inj_pair2 in H; ssubst
| [ |- _] => subst
end. | Ltac | ssubst | Core | theories/Core/Init.v | [
"Coq",
"Eqdep"
] | [] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
"m '~>' n" | :=
(forall (α : Type), m α -> n α)
(at level 80, no associativity)
: type_scope. | Notation | m '~>' n | Core | theories/Core/Init.v | [
"Coq",
"Eqdep"
] | [] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
function_eq {a b} (r : b -> b -> Prop) (f g : a -> b) : Prop | :=
forall (x : a), r (f x) (g x). | Definition | function_eq | Core | theories/Core/Init.v | [
"Coq",
"Eqdep"
] | [] | * Generalizable Functions Equality | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 |
function_eq_Equivalence a `(Equivalence b r)
: @Equivalence (a -> b) (function_eq r). | Next Obligation.
now intros f x.
Qed. | Instance | function_eq_Equivalence | Core | theories/Core/Init.v | [
"Coq",
"Eqdep"
] | [
"function_eq"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
instrument Ω i | := (stateT Ω (state (semantics i))). | Notation | instrument | Core | theories/Core/Instrument.v | [
"ExtLib",
"StateMonad",
"MonadTrans",
"FreeSpec.Core",
"Interface",
"Semantics",
"Contract"
] | [
"semantics"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
interface_to_instrument `{MayProvide ix i} `(c : contract i Ω)
: ix ~> instrument Ω ix | :=
fun a e =>
let* x := lift $ interface_to_state _ e in
modify (fun ω => gen_witness_update c ω e x);;
ret x. | Definition | interface_to_instrument | Core | theories/Core/Instrument.v | [
"ExtLib",
"StateMonad",
"MonadTrans",
"FreeSpec.Core",
"Interface",
"Semantics",
"Contract"
] | [
"MayProvide",
"contract",
"gen_witness_update",
"instrument",
"interface_to_state"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
to_instrument `{MayProvide ix i} `(c : contract i Ω)
: impure ix ~> instrument Ω ix | :=
impure_lift $ interface_to_instrument c. | Definition | to_instrument | Core | theories/Core/Instrument.v | [
"ExtLib",
"StateMonad",
"MonadTrans",
"FreeSpec.Core",
"Interface",
"Semantics",
"Contract"
] | [
"MayProvide",
"contract",
"impure",
"impure_lift",
"instrument",
"interface_to_instrument"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
instrument_to_state {i} `(ω : Ω) : instrument Ω i ~> state (semantics i) | :=
fun a instr => fst <$> runStateT instr ω. | Definition | instrument_to_state | Core | theories/Core/Instrument.v | [
"ExtLib",
"StateMonad",
"MonadTrans",
"FreeSpec.Core",
"Interface",
"Semantics",
"Contract"
] | [
"instrument",
"semantics"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
instrument_to_state_eval_morphism `{MayProvide ix i}
`(c : contract i Ω) `(p : impure ix a) (ω : Ω)
: forall (sem : semantics ix),
evalState (to_state p) sem
= fst (evalState (runStateT (to_instrument c p) ω) sem). | Proof.
unfold evalState.
revert ω.
induction p.
+ reflexivity.
+ intros ω sem.
cbn -[gen_witness_update].
destruct run_effect; cbn.
now rewrite H0 with (ω := gen_witness_update c ω e β0).
Qed. | Lemma | instrument_to_state_eval_morphism | Core | theories/Core/InstrumentFacts.v | [
"ExtLib",
"StateMonad",
"FreeSpec.Core",
"Contract",
"HoareFacts",
"SemanticsFacts",
"Instrument"
] | [
"MayProvide",
"contract",
"gen_witness_update",
"impure",
"run_effect",
"semantics",
"to_instrument",
"to_state"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
instrument_to_state_exec_morphism `{MayProvide ix i}
`(c : contract i Ω) `(p : impure ix a) (ω : Ω)
: forall (sem : semantics ix),
execState (to_state p) sem
= execState (runStateT (to_instrument c p) ω) sem. | Proof.
unfold execState.
revert ω.
induction p.
+ reflexivity.
+ intros ω sem.
cbn -[gen_witness_update].
destruct run_effect; cbn.
now rewrite H0 with (ω := gen_witness_update c ω e β0).
Qed. | Lemma | instrument_to_state_exec_morphism | Core | theories/Core/InstrumentFacts.v | [
"ExtLib",
"StateMonad",
"FreeSpec.Core",
"Contract",
"HoareFacts",
"SemanticsFacts",
"Instrument"
] | [
"MayProvide",
"contract",
"gen_witness_update",
"impure",
"run_effect",
"semantics",
"to_instrument",
"to_state"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
instrument_satisfies_hoare `{MayProvide ix i}
`(c : contract i Ω) `(p : impure ix a)
`(comp : compliant_semantics c ω sem)
: pre (to_hoare c p) ω
-> post
(to_hoare c p)
ω
(fst $ evalState (runStateT (to_instrument c p) ω) sem)
(snd $ evalState (runStateT (to_instrument c ... | Proof.
revert comp. revert ω. revert sem.
induction p; intros sem ω comp.
+ cbn.
intros _.
split; reflexivity.
+ intros pre.
cbn -[interface_to_hoare] in pre.
destruct pre as [He Hf].
cbn in He.
inversion comp; subst.
pose proof He as He'.
apply o_callee in He.
cbn.
exist... | Lemma | instrument_satisfies_hoare | Core | theories/Core/InstrumentFacts.v | [
"ExtLib",
"StateMonad",
"FreeSpec.Core",
"Contract",
"HoareFacts",
"SemanticsFacts",
"Instrument"
] | [
"MayProvide",
"compliant_semantics",
"contract",
"eval_effect",
"gen_witness_update",
"impure",
"interface_to_hoare",
"repeat",
"run_effect_equation",
"to_hoare",
"to_instrument"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
instrument_preserves_compliance `{MayProvide ix i}
`(c : contract i Ω) `(p : impure ix a)
`(comp : compliant_semantics c ω sem)
: pre (to_hoare c p) ω
-> compliant_semantics
c
(snd $ evalState (runStateT (to_instrument c p) ω) sem)
(execState (runStateT (to_instrument c p) ω) sem)... | Proof.
revert comp. revert ω. revert sem.
induction p; intros sem ω comp pre.
+ auto.
+ cbn in pre.
destruct pre as [He Hn].
specialize Hn with (eval_effect sem e)
(gen_witness_update (H := H) c ω e (eval_effect sem e)).
inversion comp; subst.
assert (Hn' : pre (to_hoare c... | Lemma | instrument_preserves_compliance | Core | theories/Core/InstrumentFacts.v | [
"ExtLib",
"StateMonad",
"FreeSpec.Core",
"Contract",
"HoareFacts",
"SemanticsFacts",
"Instrument"
] | [
"MayProvide",
"compliant_semantics",
"contract",
"eval_effect",
"exec_effect",
"gen_witness_update",
"impure",
"run_effect_equation",
"to_hoare",
"to_instrument"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
interface | := Type -> Type. | Definition | interface | Core | theories/Core/Interface.v | [
"FreeSpec.Core",
"Init",
"Coq",
"Program"
] | [] | Following the definition of the <<operational>> package, interfaces in
FreeSpec are parameterized inductive types whose terms purposely describe
the primitives the interface provides. | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 |
iempty : interface | := . | Inductive | iempty | Core | theories/Core/Interface.v | [
"FreeSpec.Core",
"Init",
"Coq",
"Program"
] | [
"interface"
] | Given [i : interface], a term of type [i α] identifies a primitive of [i]
expected to produce a result of type [α].
The simpler interface is the empty interface, which provides no primitives
whatsoever. | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 |
STORE (s : Type) : interface | :=
| Get : STORE s s
| Put (x : s) : STORE s unit. | Inductive | STORE | Core | theories/Core/Interface.v | [
"FreeSpec.Core",
"Init",
"Coq",
"Program"
] | [
"interface"
] | Another example of general-purpose interface we can define is the [STORE s]
interface, where [s] is a type for a state, and [STORE s] allows for
manipulating a global, mutable variable of type [s] within an impure
computation. | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 |
MayProvide (ix i : interface) : Type | :=
{ proj_p {α} (e : ix α) : option (i α)
}. | Class | MayProvide | Core | theories/Core/Interface.v | [
"FreeSpec.Core",
"Init",
"Coq",
"Program"
] | [
"interface"
] | When defining general-purpose impure computations that we expect to reuse in
different context, we want to leave the interface as a parameter, and rather
express the constraints in terms of interface availability. We tackle this
challenge by means of _interface composites_.
- We say an interface compo... | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 |
Provide (ix i : interface) `{MayProvide ix i} : Type | :=
{ inj_p {α} (e : i α) : ix α
; proj_inj_p_equ {α} (e : i α) : proj_p (inj_p e) = Some e
}. | Class | Provide | Core | theories/Core/Interface.v | [
"FreeSpec.Core",
"Init",
"Coq",
"Program"
] | [
"MayProvide",
"interface"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
default_MayProvide (i j : interface) : MayProvide i j|1000 | :=
{ proj_p := fun _ _ => None
}. | Instance | default_MayProvide | Core | theories/Core/Interface.v | [
"FreeSpec.Core",
"Init",
"Coq",
"Program"
] | [
"MayProvide",
"interface"
] | We provide a default instance for [MayProvide] in the form of a function
[proj_p] which always return [None]. We give to this default instance a
ridiculously high priority number to ensure it is selected only if no other
instances are found. | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 |
Distinguish (ix i j : interface) `{Provide ix i, MayProvide ix j} : Prop | :=
{ distinguish : forall {α} (e : i α), proj_p (i := j) (inj_p (ix := ix) e) = None
}. | Class | Distinguish | Core | theories/Core/Interface.v | [
"FreeSpec.Core",
"Init",
"Coq",
"Program"
] | [
"MayProvide",
"Provide",
"interface"
] | It is expected that, for an interface composite [ix] which provides [i] and
may provide [j], [inj_p] and [proj_p] do not mix up [i] and [j]
primitives. That is, injecting a primitive [e] of [i] inside [ix], then
projecting the resulting primitive into [j] returns [None] as long as [i]
and [j] are two di... | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 |
iplus (i j : interface) (α : Type) | :=
| in_left (e : i α) : iplus i j α
| in_right (e : j α) : iplus i j α. | Inductive | iplus | Core | theories/Core/Interface.v | [
"FreeSpec.Core",
"Init",
"Coq",
"Program"
] | [
"interface"
] | We provide the [iplus] operator to compose interface together. That is,
[iplus] can be used to build _concrete_ (as opposed to polymorphic)
interface composite. | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 |
refl_MayProvide (i : interface) : MayProvide i i | :=
{ proj_p := fun _ e => Some e
}. | Instance | refl_MayProvide | Core | theories/Core/Interface.v | [
"FreeSpec.Core",
"Init",
"Coq",
"Program"
] | [
"MayProvide",
"interface"
] | For [iplus] to be used seamlessly as a concrete interface composite, we
provide the necessary instances for the [MayProvide], [Provide] and
[Distinguish] type classes. Note that these instances always prefer the
left operand of [iplus]. For instance, considering a situation where
there is an instance fo... | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 |
refl_Provide (i : interface) : @Provide i i (refl_MayProvide i) | :=
{ inj_p := fun (a : Type) (e : i a) => e
}. | Instance | refl_Provide | Core | theories/Core/Interface.v | [
"FreeSpec.Core",
"Init",
"Coq",
"Program"
] | [
"Provide",
"interface",
"refl_MayProvide"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
iplus_left_MayProvide (ix i j : interface) `{MayProvide ix i}
: MayProvide (ix + j) i | :=
{ proj_p := fun _ e =>
match e with
| in_left e => proj_p e
| _ => None
end
}. | Instance | iplus_left_MayProvide | Core | theories/Core/Interface.v | [
"FreeSpec.Core",
"Init",
"Coq",
"Program"
] | [
"MayProvide",
"interface"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
iplus_left_Provide (ix i j : interface) `{Provide ix i}
: @Provide (ix + j) i (iplus_left_MayProvide ix i j) :=
{ inj_p := fun (a : Type) (e : i a) => in_left (inj_p e)
}. | Next Obligation.
now rewrite proj_inj_p_equ.
Qed. | Instance | iplus_left_Provide | Core | theories/Core/Interface.v | [
"FreeSpec.Core",
"Init",
"Coq",
"Program"
] | [
"Provide",
"interface",
"iplus_left_MayProvide"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
iplus_right_MayProvide (i jx j : interface) `{MayProvide jx j}
: MayProvide (i + jx) j | :=
{ proj_p := fun _ e =>
match e with
| in_right e => proj_p e
| _ => None
end
}. | Instance | iplus_right_MayProvide | Core | theories/Core/Interface.v | [
"FreeSpec.Core",
"Init",
"Coq",
"Program"
] | [
"MayProvide",
"interface"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
iplus_right_Provide (i jx j : interface) `{Provide jx j}
: @Provide (i + jx) j (iplus_right_MayProvide i jx j) :=
{ inj_p := fun _ e => in_right (inj_p e)
}. | Next Obligation.
now rewrite proj_inj_p_equ.
Qed. | Instance | iplus_right_Provide | Core | theories/Core/Interface.v | [
"FreeSpec.Core",
"Init",
"Coq",
"Program"
] | [
"Provide",
"interface",
"iplus_right_MayProvide"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
find_may_provide | :=
eapply refl_MayProvide +
(eapply iplus_left_MayProvide; find_may_provide) +
(eapply iplus_right_MayProvide; find_may_provide). | Ltac | find_may_provide | Core | theories/Core/Interface.v | [
"FreeSpec.Core",
"Init",
"Coq",
"Program"
] | [
"iplus_left_MayProvide",
"iplus_right_MayProvide",
"refl_MayProvide"
] | By default, Coq's inference algorithm for type classe instances inference is
a depth-first search. This is not without consequence in our case. For
instance, if we consider the search of an instance for [MayProvide (i + j)
j], Coq will first try [iplus_right_MayProvide] (as explained previously),
meanin... | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 |
refl_Distinguish (i j : interface)
: @Distinguish i i j (@refl_MayProvide i) (@refl_Provide i) (@default_MayProvide i j). | Instance | refl_Distinguish | Core | theories/Core/Interface.v | [
"FreeSpec.Core",
"Init",
"Coq",
"Program"
] | [
"Distinguish",
"default_MayProvide",
"interface",
"refl_MayProvide",
"refl_Provide"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | ||
iplus_left_default_Distinguish (ix jx i j : interface)
`{M1 : MayProvide ix i} `{P1 : @Provide ix i M1}
: @Distinguish (ix + jx) i j
(@iplus_left_MayProvide ix i jx M1)
(@iplus_left_Provide ix i jx M1 P1)
(@default_MayProvide _ j). | Instance | iplus_left_default_Distinguish | Core | theories/Core/Interface.v | [
"FreeSpec.Core",
"Init",
"Coq",
"Program"
] | [
"Distinguish",
"MayProvide",
"Provide",
"default_MayProvide",
"interface",
"iplus_left_MayProvide",
"iplus_left_Provide"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | ||
iplus_right_default_Distinguish (ix jx i j : interface)
`{M1 : MayProvide jx i} `{P1 : @Provide jx i M1}
: @Distinguish (ix + jx) i j
(@iplus_right_MayProvide ix jx i M1)
(@iplus_right_Provide ix jx i M1 P1)
(@default_MayProvide _ j). | Instance | iplus_right_default_Distinguish | Core | theories/Core/Interface.v | [
"FreeSpec.Core",
"Init",
"Coq",
"Program"
] | [
"Distinguish",
"MayProvide",
"Provide",
"default_MayProvide",
"interface",
"iplus_right_MayProvide",
"iplus_right_Provide"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | ||
iplus_left_may_right_Distinguish (ix jx i j : interface)
`{M1 : MayProvide ix i} `{P1 : @Provide ix i M1} `{M2 : MayProvide jx j}
: @Distinguish (ix + jx) i j
(@iplus_left_MayProvide ix i jx M1)
(@iplus_left_Provide ix i jx M1 P1)
(@iplus_right_MayProvide ix jx j ... | Instance | iplus_left_may_right_Distinguish | Core | theories/Core/Interface.v | [
"FreeSpec.Core",
"Init",
"Coq",
"Program"
] | [
"Distinguish",
"MayProvide",
"Provide",
"interface",
"iplus_left_MayProvide",
"iplus_left_Provide",
"iplus_right_MayProvide"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | ||
iplus_right_may_left_Distinguish (ix jx i j : interface)
`{M1 : MayProvide jx i} `{P1 : @Provide jx i M1} `{M2 : MayProvide ix j}
: @Distinguish (ix + jx) i j
(@iplus_right_MayProvide ix jx i M1)
(@iplus_right_Provide ix jx i M1 P1)
(@iplus_left_MayProvide ix j jx... | Instance | iplus_right_may_left_Distinguish | Core | theories/Core/Interface.v | [
"FreeSpec.Core",
"Init",
"Coq",
"Program"
] | [
"Distinguish",
"MayProvide",
"Provide",
"interface",
"iplus_left_MayProvide",
"iplus_right_MayProvide",
"iplus_right_Provide"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | ||
iplus_left_distinguish_left_Distinguish (ix jx i j : interface)
`{M1 : MayProvide ix i} `{P1 : @Provide ix i M1} `{M2 : MayProvide ix j}
`{@Distinguish ix i j M1 P1 M2}
: @Distinguish (ix + jx) i j
(@iplus_left_MayProvide ix i jx M1)
(@iplus_left_Provide ix i jx M1 P1)
... | Next Obligation.
apply distinguish.
Defined. | Instance | iplus_left_distinguish_left_Distinguish | Core | theories/Core/Interface.v | [
"FreeSpec.Core",
"Init",
"Coq",
"Program"
] | [
"Distinguish",
"MayProvide",
"Provide",
"interface",
"iplus_left_MayProvide",
"iplus_left_Provide"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
iplus_right_distinguish_right_Distinguish (ix jx i j : interface)
`{M1 : MayProvide jx i} `{P1 : @Provide jx i M1} `{M2 : MayProvide jx j}
`{@Distinguish jx i j M1 P1 M2}
: @Distinguish (ix + jx) i j
(@iplus_right_MayProvide ix jx i M1)
(@iplus_right_Provide ix jx i M1 P1)
... | Next Obligation.
apply distinguish.
Defined. | Instance | iplus_right_distinguish_right_Distinguish | Core | theories/Core/Interface.v | [
"FreeSpec.Core",
"Init",
"Coq",
"Program"
] | [
"Distinguish",
"MayProvide",
"Provide",
"interface",
"iplus_right_MayProvide",
"iplus_right_Provide"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
semantics (i : interface) : Type | :=
| mk_semantics (f : forall (α : Type), i α -> α * semantics i) : semantics i. | CoInductive | semantics | Core | theories/Core/Semantics.v | [
"Coq",
"Program",
"Setoid",
"Morphisms",
"ExtLib",
"Monad",
"StateMonad",
"FreeSpec.Core",
"Interface",
"Impure"
] | [
"interface"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
iempty_semantics : semantics iempty | :=
mk_semantics (fun α (e : iempty α) => match e with end). | Definition | iempty_semantics | Core | theories/Core/Semantics.v | [
"Coq",
"Program",
"Setoid",
"Morphisms",
"ExtLib",
"Monad",
"StateMonad",
"FreeSpec.Core",
"Interface",
"Impure"
] | [
"iempty",
"semantics"
] | Thus, a [semantics] does not only compute a result for a primitive, but also
provides a new semantics. This is necessary to model impurity: the same
primitive may or may not return the same result when called several
times.
As for interfaces, the simpler [semantics] is the operational semantics for
... | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 |
store {s} (init : s) : semantics (STORE s) | :=
mk_semantics (fun α (e : STORE s α) =>
match e with
| Get => (init, store init)
| Put next => (tt, store next)
end). | CoFixpoint | store | Core | theories/Core/Semantics.v | [
"Coq",
"Program",
"Setoid",
"Morphisms",
"ExtLib",
"Monad",
"StateMonad",
"FreeSpec.Core",
"Interface",
"Impure"
] | [
"STORE",
"semantics"
] | We also provide a semantics for the [STORE s] interface: | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 |
run_effect {i α} (sem : semantics i) (e : i α) : α * semantics i | :=
match sem with mk_semantics f => f α e end. | Definition | run_effect | Core | theories/Core/Semantics.v | [
"Coq",
"Program",
"Setoid",
"Morphisms",
"ExtLib",
"Monad",
"StateMonad",
"FreeSpec.Core",
"Interface",
"Impure"
] | [
"semantics"
] | We provide several helper functions to interpret primitives with
semantics. | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 |
eval_effect {i α} (sem : semantics i) (e : i α) : α | :=
fst (run_effect sem e). | Definition | eval_effect | Core | theories/Core/Semantics.v | [
"Coq",
"Program",
"Setoid",
"Morphisms",
"ExtLib",
"Monad",
"StateMonad",
"FreeSpec.Core",
"Interface",
"Impure"
] | [
"run_effect",
"semantics"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
exec_effect {i α} (sem : semantics i) (e : i α) : semantics i | :=
snd (run_effect sem e). | Definition | exec_effect | Core | theories/Core/Semantics.v | [
"Coq",
"Program",
"Setoid",
"Morphisms",
"ExtLib",
"Monad",
"StateMonad",
"FreeSpec.Core",
"Interface",
"Impure"
] | [
"run_effect",
"semantics"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
run_effect_equation {i α} (sem : semantics i) (e : i α)
: run_effect sem e = (eval_effect sem e, exec_effect sem e). | Proof.
unfold eval_effect, exec_effect.
destruct run_effect; reflexivity.
Qed. | Lemma | run_effect_equation | Core | theories/Core/Semantics.v | [
"Coq",
"Program",
"Setoid",
"Morphisms",
"ExtLib",
"Monad",
"StateMonad",
"FreeSpec.Core",
"Interface",
"Impure"
] | [
"eval_effect",
"exec_effect",
"run_effect",
"semantics"
] | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 | |
semprod {i j} (sem_i : semantics i) (sem_j : semantics j)
: semantics (i + j) | :=
mk_semantics (fun _ e =>
match e with
| in_left e =>
let (x, out) := run_effect sem_i e in
(x, semprod out sem_j)
| in_right e =>
let (x, out) := run_effect sem_j e in
(x, semprod s... | CoFixpoint | semprod | Core | theories/Core/Semantics.v | [
"Coq",
"Program",
"Setoid",
"Morphisms",
"ExtLib",
"Monad",
"StateMonad",
"FreeSpec.Core",
"Interface",
"Impure"
] | [
"run_effect",
"semantics"
] | Besides, and similarly to interfaces, operational semantics can and should
be composed together. To that end, we provide the [semprod] operator. | https://github.com/lthms/FreeSpec | d4e2f3a3fc7e82effddca202a8b0210dbbcf3663 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.