fact
stringlengths
14
11.5k
type
stringclasses
22 values
library
stringclasses
7 values
imports
listlengths
0
7
filename
stringclasses
136 values
symbolic_name
stringlengths
1
36
docstring
stringclasses
1 value
bind_iforest_stronger {E} : forall A B, iforest E A -> (A -> iforest E B) -> iforest E B := fun A B (PA: iforest E A) (K: A -> iforest E B) (tb: itree E B) => exists (ta: itree E A) (k: A -> itree E B), PA ta /\ tb ≈ bind ta k /\ (forall a, Leaf a ta -> K a (k a)). (** Alternate, logically equivalent version of [bind_i...
Definition
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
bind_iforest_stronger
bind_iforest' {E} : forall A B, iforest E A -> (A -> iforest E B) -> iforest E B := fun A B (PA: iforest E A) (K: A -> iforest E B) (tb: itree E B) => exists (ta: itree E A), PA ta /\ ((exists (k: A -> itree E B), (forall a, Leaf a ta -> K a (k a)) /\ tb ≈ bind ta k) \/ (forall k, (forall a, K a (k a)) /\ tb ≈ bind ta ...
Definition
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
bind_iforest'
bind_iforest_bind_iforest' {E}: forall A B PA K (tb : itree E B), bind_iforest A B PA K tb <-> bind_iforest' A B PA K tb. Proof. intros. split. intros. - red. red in H. destruct H as (ta & ka & HPA & eq & HR). exists ta. split; auto. left. exists ka. split; auto. - intros. red. red in H. destruct H as (ta & EQ1 & [(k &...
Lemma
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
bind_iforest_bind_iforest'
handler_correct {E F} (h_spec: E ~> iforest F) (h: E ~> itree F) : Prop := (forall T e, h_spec T e (h T e)).
Definition
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
handler_correct
interp_iforestF {E F} (h_spec : forall T, E T -> itree F T -> Prop) {R : Type} (RR : relation R) (sim : itree E R -> itree F R -> Prop) : itree' E R -> itree F R -> Prop := | Interp_iforest_Ret : forall r1 r2 (REL: RR r1 r2) (t2 : itree F R) (eq2 : t2 ≈ (Ret r2)), interp_iforestF h_spec RR sim (RetF r1) t2 | Interp_ifo...
Inductive
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
interp_iforestF
interp_iforestF_mono E F h_spec R RR (t0 : itree' E R) (t1 : itree F R) sim sim' (IN : interp_iforestF h_spec RR sim t0 t1) (LE : sim <2= sim') : (interp_iforestF h_spec RR sim' t0 t1). Proof. induction IN; eauto with itree. Qed. #[global] Hint Resolve interp_iforestF_mono : paco.
Lemma
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
interp_iforestF_mono
interp_iforest_ E F h_spec R RR sim (t0 : itree E R) (t1 : itree F R) : Prop := interp_iforestF h_spec RR sim (observe t0) t1. #[global] Hint Unfold interp_iforest_ : itree.
Definition
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
interp_iforest_
interp_iforest__mono E F h_spec R RR : monotone2 (interp_iforest_ E F h_spec R RR). Proof. do 2 red. intros. eapply interp_iforestF_mono; eauto. Qed. #[global] Hint Resolve interp_iforest__mono : paco. (* Definition 5.2 *)
Lemma
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
interp_iforest__mono
interp_iforest {E F} (h_spec : E ~> iforest F) : forall R (RR: relation R), itree E R -> iforest F R := fun R (RR: relation R) => paco2 (interp_iforest_ E F h_spec R RR) bot2. (* Figure 7: Interpreter law for Ret *)
Definition
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
interp_iforest
interp_iforest_ret : forall R E F (h_spec : E ~> iforest F) (r : R) , Eq1_iforest _ (interp_iforest h_spec R eq (ret r)) (ret r). Proof. intros. repeat red. split; [| split]. - intros. split; intros. + unfold interp_iforest in H0. pinversion H0. subst. cbn. rewrite <- H. assumption. + pstep. econstructor. reflexivity. ...
Lemma
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
interp_iforest_ret
inj_pair2 : forall (U : Type) (P : U -> Type) (p : U) (x y : P p), existT P p x = existT P p y -> x = y. Proof. intros. apply JMeq.JMeq_eq. refine ( match H in _ = w return JMeq.JMeq x (projT2 w) with | eq_refl => JMeq.JMeq_refl end). Qed. #[global] Instance interp_iforest_Proper3 {E F} (h_spec : E ~> iforest F) R RR :...
Lemma
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
inj_pair2
interp_iforest_correct_exec : forall {E F} (h_spec: E ~> iforest F) (h: E ~> itree F), handler_correct h_spec h -> forall R RR `{Reflexive _ RR} t t', t ≈ t' -> interp_iforest h_spec R RR t (interp h t'). Proof. intros. revert t t' H1. pcofix CIH. intros t t' eq. pstep. red. unfold interp, Basics.iter, MonadIter_itree....
Lemma
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
interp_iforest_correct_exec
Leaf_Vis_sub : forall {E} {R} X (e : E X) (k : X -> itree E R) u x, Leaf u (k x) -> Leaf u (Vis e k). Proof. intros. eapply LeafVis. reflexivity. apply H. Qed.
Lemma
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
Leaf_Vis_sub
eutt_Leaf_ : forall {E} {R} (RR : R -> Prop) (ta : itree E R) (IN: forall (a : R), Leaf a ta -> RR a), eutt (fun u1 u2 => u1 = u2 /\ RR u1) ta ta. Proof. intros E R. ginit. gcofix CIH; intros. setoid_rewrite (itree_eta ta) in IN. gstep. red. destruct (observe ta). - econstructor. split; auto. apply IN. econstructor. re...
Lemma
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
eutt_Leaf_
eutt_Leaf : forall E R (ta : itree E R), eutt (fun u1 u2 => u1 = u2 /\ Leaf u1 ta) ta ta. Proof. intros. apply eutt_Leaf_. auto. Qed. (* Figure 7: interp Trigger law *) (* morally, we should only work with "proper" triggers everywhere *)
Lemma
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
eutt_Leaf
interp_iforest_trigger : forall E F (h_spec : E ~> iforest F) R (e : E R) (HP : forall T, Proper (eq ==> Eq1_iforest T) (h_spec T)) , Eq1_iforest _ (interp_iforest h_spec R eq (trigger e)) (h_spec R e). Proof. intros. red. split; [| split]. - intros; split; intros. + unfold trigger in H0. red in H0. pinversion H0; subs...
Lemma
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
interp_iforest_trigger
interp_iforest_spin_accepts_anything : forall E F (h_spec : E ~> iforest F) R RR (t : itree F R), interp_iforest h_spec R RR ITree.spin t. Proof. intros. pcofix CIH. pstep. red. cbn. econstructor. right. apply CIH. Qed. (* Figure 7: Structural law for tau *)
Lemma
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
interp_iforest_spin_accepts_anything
interp_iforest_tau : forall E F (h_spec : E ~> iforest F) R RR (t_spec : itree E R), Eq1_iforest _ (interp_iforest h_spec R RR t_spec) (interp_iforest h_spec R RR (Tau t_spec)). Proof. intros. split; [| split]. - intros; split; intros. + rewrite <- H. pstep. red. econstructor. left. apply H0. + rewrite H. pinversion H0...
Lemma
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
interp_iforest_tau
interp_iforest_ret_inv : forall E F (h_spec : E ~> iforest F) R RR (r1 : R) (t : itree F R) (H : interp_iforest h_spec R RR (ret r1) t), exists r2, RR r1 r2 /\ t ≈ ret r2. Proof. intros. punfold H. red in H. inversion H; subst. exists r2; eauto. Qed.
Lemma
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
interp_iforest_ret_inv
interp_iforest_vis_inv : forall E F (h_spec : E ~> iforest F) R RR S (e : E S) (k : S -> itree E R) (t : itree F R) (H : interp_iforest h_spec R RR (vis e k) t), exists ms, exists (ks : S -> itree F R), h_spec S e ms /\ t ≈ (bind ms ks). Proof. intros. punfold H. red in H. inversion H; subst. apply inj_pair2 in H2. app...
Lemma
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
interp_iforest_vis_inv
interp_iforest_tau_inv : forall E F (h_spec : E ~> iforest F) R RR (s : itree E R) (t : itree F R) (H : interp_iforest h_spec R RR (Tau s) t), interp_iforest h_spec R RR s t. Proof. intros. punfold H. red in H. inversion H; subst. pclearbot. apply HS. Qed.
Lemma
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
interp_iforest_tau_inv
case_iforest_handler_correct : forall {E1 E2 F} (h1_spec: E1 ~> iforest F) (h2_spec: E2 ~> iforest F) (h1: E1 ~> itree F) (h2: E2 ~> itree F) (C1: handler_correct h1_spec h1) (C2: handler_correct h2_spec h2), handler_correct (case_ h1_spec h2_spec) (case_ h1 h2). Proof. intros E1 E2 F h1_spec h2_spec h1 h2 C1 C2. unfol...
Lemma
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
case_iforest_handler_correct
iforest_compose {F G : Type -> Type} {T : Type} (TT : relation T) (g_spec : F ~> iforest G) (PF: iforest F T) : iforest G T := fun (g:itree G T) => exists f : itree F T, PF f /\ (interp_iforest g_spec) T TT f g.
Definition
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
iforest_compose
handler_correct_iforest {E F G} (h_spec: E ~> iforest F) (h: E ~> itree F) (g_spec: F ~> iforest G) (g: F ~> itree G) := (forall T TT e, (iforest_compose TT g_spec (h_spec T e)) (interp g (h T e))).
Definition
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
handler_correct_iforest
singletonT {E}: itree E ~> iforest E := fun R t t' => t' ≈ t.
Definition
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
singletonT
iter_cont {I E R} (step' : I -> itree E (I + R)) : I + R -> itree E R := fun lr => ITree.on_left lr l (Tau (ITree.iter step' l)). #[global] Polymorphic Instance MonadIter_iforest {E} : MonadIter (iforest E) := fun R I (step : I -> iforest E (I + R)) i => fun (r : itree E R) => (exists (step' : I -> (itree E (I + R)%typ...
Definition
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
iter_cont
eqit_Leaf_bind_clo b1 b2 (r : itree E R -> itree E S -> Prop) : itree E R -> itree E S -> Prop := | pbc_intro_h U (t1 t2: itree E U) (k1 : U -> itree E R) (k2 : U -> itree E S) (EQV: eqit eq b1 b2 t1 t2) (REL: forall u, Leaf u t1 -> r (k1 u) (k2 u)) : eqit_Leaf_bind_clo b1 b2 r (ITree.bind t1 k1) (ITree.bind t2 k2) . H...
Inductive
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
eqit_Leaf_bind_clo
eqit_Leaf_clo_bind (RS : R -> S -> Prop) b1 b2 vclo (MON: monotone2 vclo) (CMP: compose (eqitC RS b1 b2) vclo <3= compose vclo (eqitC RS b1 b2)) (ID: id <3= vclo): eqit_Leaf_bind_clo b1 b2 <3= gupaco2 (eqit_ RS b1 b2 vclo) (eqitC RS b1 b2). Proof. gcofix CIH. intros. destruct PR. guclo eqit_clo_trans. econstructor; aut...
Lemma
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
eqit_Leaf_clo_bind
eqit_Leaf_bind' {E} {R} {T} b1 b2 (t1 t2: itree E T) (k1 k2: T -> itree E R) : eqit eq b1 b2 t1 t2 -> (forall r, Leaf r t1 -> eqit eq b1 b2 (k1 r) (k2 r)) -> @eqit E _ _ eq b1 b2 (ITree.bind t1 k1) (ITree.bind t2 k2). Proof. intros. ginit. guclo (@eqit_Leaf_clo_bind E R R eq). unfold eqit in *. econstructor; eauto with...
Lemma
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
eqit_Leaf_bind'
eqit_Leaf_bind'' {E} {R S} {T} (RS : R -> S -> Prop) b1 b2 (t1 t2: itree E T) (k1: T -> itree E R) (k2 : T -> itree E S) : eqit eq b1 b2 t1 t2 -> (forall r, Leaf r t1 -> eqit RS b1 b2 (k1 r) (k2 r)) -> @eqit E _ _ RS b1 b2 (ITree.bind t1 k1) (ITree.bind t2 k2). Proof. intros. ginit. guclo (@eqit_Leaf_clo_bind E R S RS)...
Lemma
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
eqit_Leaf_bind''
eutt_ret_vis_abs : forall {X Y E} (x: X) (e: E Y) k, Ret x ≈ Vis e k -> False. Proof. intros. punfold H; inv H. Qed.
Lemma
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
eutt_ret_vis_abs
simpl_iter := unfold iter, Iter_Kleisli, Basics.iter, MonadIter_itree.
Ltac
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
simpl_iter
g {a b : Type} {E} (x0 : a * nat -> itree E (a + b)) (a1 : a) := (fun '(x, k) => bind (x0 (x, k)) (fun ir : a + b => match ir with | inl i0 => ret (inl (i0, k)) | inr r0 => ret (inr r0) end)).
Definition
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
g
f {a b : Type} {E} : a * nat -> itree E (a * nat + b) := fun '(x, k) => ret (inl ((x, S k))).
Definition
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
f
iter_succ_dinatural : forall {a b : Type} {E} (x0 : a * nat -> itree E (a + b)) (a1 : a), iter (C := Kleisli (itree E)) (bif := sum) (f >>> case_ (g x0 a1) inr_) ⩯ f >>> case_ (iter (C := Kleisli (itree E)) (bif := sum) ((g x0 a1) >>> (case_ f inr_))) (id_ _). Proof. intros. rewrite iter_dinatural. reflexivity. Qed.
Lemma
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
iter_succ_dinatural
iter_eq_start_index : forall (a b : Type) (E : Type -> Type) (x0 : a * nat -> itree E (a + b)) (a1 : a), iter (C := Kleisli (itree E)) (bif := sum) (fun '(x, k) => bind (x0 (x, S k)) (fun ir : a + b => match ir with | inl i0 => ret (inl (i0, S k)) | inr r0 => ret (inr r0) end)) (a1, 0) ≈ iter (C := Kleisli (itree E)) (...
Lemma
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
iter_eq_start_index
Eq1_iforest' {E} : Eq1 (iforest E) := fun a PA PA' => (forall x, (PA x -> exists y, x ≈ y /\ PA' y)) /\ (forall y, (PA' y -> exists x, x ≈ y /\ PA x)) /\ eutt_closed PA /\ eutt_closed PA'.
Definition
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
Eq1_iforest'
Eq1_iforest'_Eq1_iforest : forall E a PA PA', @Eq1_iforest E a PA PA' -> Eq1_iforest' a PA PA'. Proof. intros. red. red in H. destruct H as (HXY & EPA & EPA'). split. intros. exists x. split; [reflexivity|]. specialize (HXY x x). apply HXY. reflexivity. assumption. split; try tauto. intros. exists y. split; [reflexivit...
Lemma
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
Eq1_iforest'_Eq1_iforest
ret_bind : forall {E} (a b : Type) (f : a -> iforest E b) (x : a), eutt_closed (f x) -> eq1 (bind (ret x) f) (f x). Proof. intros. split; [| split]. - intros t t' eq; split; intros eqtt'. * cbn in *. repeat red in eqtt'. destruct eqtt' as (ta & k & EQ1 & EQ2 & KA). + unfold bind, Monad_itree in EQ2. rewrite EQ1, Eqit.b...
Lemma
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
ret_bind
agrees_itree := (eutt (fun a p => p a)) (only parsing).
Notation
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
agrees_itree
bind_stronger {E A B} (PA: iforest E A) (K: A -> iforest E B) : iforest E B := fun (tb: itree E B) => exists (ta: itree E A), PA ta /\ exists (k: A -> itree E B), (agrees_itree (fmap k ta) (fmap K ta) /\ tb ≈ bind ta k).
Definition
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
bind_stronger
agree_itree_Leaf E A B (ta : itree E A) (K : A -> iforest E B) (k : A -> itree E B) : (forall a, Leaf a ta -> K a (k a)) <-> (agrees_itree (fmap k ta) (fmap K ta)). Proof. split; intros. - cbn. red. unfold ITree.map. eapply eqit_Leaf_bind''. + reflexivity. + intros. apply eqit_Ret. apply H. assumption. - revert H. indu...
Lemma
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
agree_itree_Leaf
distinguish_bind {E} {A B} (a : A) (ma : itree E A) (k1 k2 : A -> itree E B) (HRET : Leaf a ma) (NEQ: ~((k1 a) ≈ (k2 a))) : not ((ITree.bind ma k1) ≈ (ITree.bind ma k2)). Proof. intros HI; eapply eqit_bind_Leaf_inv in HI; eauto. Qed.
Lemma
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
distinguish_bind
not_Leaf {E} {A B} : inhabited B -> forall (ta: itree E A), (exists tb, forall (k : A -> itree E B), tb ≈ bind ta k) -> forall (a:A), ~ Leaf a ta. Proof. intros [b] ta [tb HK] a HRet. revert tb HK; induction HRet; intros tb HK. - setoid_rewrite unfold_bind in HK. setoid_rewrite H in HK. generalize (HK (fun _ => ITree.s...
Lemma
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
not_Leaf
bind_ret : forall {E} (A : Type) (PA : iforest E A), eutt_closed PA -> eq1 (bind PA (fun x => ret x)) PA. Proof. intros. split; [| split]. + intros t t' eq; split; intros eqtt'. * cbn in *. destruct eqtt' as (ta & k & HPA & EQ & HRET). eapply H; [symmetry; eauto | clear eq t']. eapply H; [eauto | clear EQ t]. eapply H;...
Lemma
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
bind_ret
EQ_REL {E A} (ta : itree E A) : A -> A -> Prop := fun a b => a = b /\ Leaf a ta.
Definition
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
EQ_REL
Symmteric_EQ_REL {E A} (ta : itree E A) : Symmetric (EQ_REL ta). Proof. repeat red. intros a b (EQ & H). split. - symmetry. assumption. - subst; auto. Qed.
Lemma
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
Symmteric_EQ_REL
Transitive_EQ_REL {E A} (ta : itree E A) : Transitive (EQ_REL ta). Proof. repeat red. intros a b c (EQ1 & H1) (EQ2 & H2). split. - rewrite EQ1. assumption. - assumption. Qed. #[global] Instance EQ_REL_Proper {E A} : Proper (eutt eq ==> eq ==> eq ==> iff) (@EQ_REL E A). Proof. repeat red. intros. subst. split; intros; u...
Lemma
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
Transitive_EQ_REL
eq_relation {A} (R S : A -> A -> Prop) := R <2= S /\ S <2= R. #[global] Instance eutt_EQ_REL_Proper {E} {A} : Proper (eq_relation ==> eutt eq ==> @eutt E A A eq ==> iff) (eutt). Proof. repeat red. intros; split; intros. - rewrite <- H0. rewrite <- H1. clear H0 H1. destruct H. eapply eqit_mon; eauto. - rewrite H0, H1. d...
Definition
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
eq_relation
eutt_EQ_REL_Reflexive_ {E} {A} (ta : itree E A) : forall R, (EQ_REL ta) <2= R -> eutt R ta ta. Proof. revert ta. ginit. gcofix CIH. intros ta HEQ. gstep. red. genobs ta obs. destruct obs. - econstructor. apply HEQ. red. split; auto. rewrite itree_eta. rewrite <- Heqobs. constructor 1. reflexivity. - econstructor. gbase...
Lemma
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
eutt_EQ_REL_Reflexive_
eutt_EQ_REL_Reflexive {E} {A} (ta : itree E A) : eutt (EQ_REL ta) ta ta. Proof. apply eutt_EQ_REL_Reflexive_. auto. Qed.
Lemma
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
eutt_EQ_REL_Reflexive
RET_EQ {E} {A} (ta : itree E A) : A -> A -> Prop := fun x y => Leaf x ta /\ Leaf y ta. (* Figure 7: 3rd monad law, one direction bind associativity *)
Definition
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
RET_EQ
bind_bind_iforest : forall {E} (A B C : Type) (PA : iforest E A) (KB : A -> iforest E B) (KC : B -> iforest E C) (PQOK : eutt_closed PA) (KBP : Proper (eq ==> eq1) KB) (KCP : Proper (eq ==> eq1) KC) (t : itree E C), (bind (bind PA KB) KC) t -> (bind PA (fun a => bind (KB a) KC)) t. Proof. (* PA ~a> KB a ~b> KC b *) int...
Lemma
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
bind_bind_iforest
ND : Type -> Prop := | Pick : ND bool.
Inductive
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
ND
PA : iforest ND bool := fun (ta : itree ND bool) => ta ≈ trigger Pick.
Definition
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
PA
KB : bool -> iforest ND bool := fun b => PA.
Definition
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
KB
KC : bool -> iforest ND bool := fun b => if b then (fun tc : itree ND bool => (tc ≈ ret true) \/ (tc ≈ ret false)) else (fun tc : itree ND bool => tc ≈ ITree.spin).
Definition
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
KC
t : itree ND bool := bind (trigger Pick) (fun (b:bool) => if b then bind (trigger Pick) (fun (x:bool) => if x then ret true else ITree.spin) else bind (trigger Pick) (fun (x:bool) => if x then ret false else ITree.spin)).
Definition
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
t
bind_right_assoc : bind PA (fun a => bind (KB a) KC) t. Proof. repeat red. exists (trigger Pick). exists (fun (b:bool) => if b then (bind (trigger Pick) (fun (x:bool) => if x then ret true else ITree.spin)) else (bind (trigger Pick) (fun (x:bool) => if x then ret false else ITree.spin))). split; auto. red. reflexivity....
Lemma
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
bind_right_assoc
not_bind_left_assoc : ~ (bind (bind PA KB) KC t). Proof. intro H. repeat red in H. destruct H as (ta & k & HB & HEQ & HRET). destruct HB as (tb & kb & HX & HEQ' & HRET'). red in HX. rewrite HX in *. setoid_rewrite HX in HRET'. clear tb HX. rewrite HEQ' in HEQ. unfold t in HEQ. unfold bind, Monad_itree in HEQ. rewrite E...
Lemma
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
not_bind_left_assoc
bind_bind_counterexample : exists t, bind PA (fun a => bind (KB a) KC) t /\ ~ (bind (bind PA KB) KC t). Proof. exists t. split. apply bind_right_assoc. apply not_bind_left_assoc. Qed.
Lemma
extra
[ "From Paco Require Import paco.", "From ExtLib Require Import\n Structures." ]
extra/IForest.v
bind_bind_counterexample
aexp : Type := | ANum (n : nat) | AId (x : string) | APlus (a1 a2 : aexp) | AMinus (a1 a2 : aexp) | AMult (a1 a2 : aexp).
Inductive
hoare_example
[ "From Coq Require Import\n Arith.", "From ExtLib Require Import\n Data.", "From ITree Require Import\n Events.", "From ExtLib Require Import\n Core." ]
hoare_example/Imp.v
aexp
bexp : Type := | BTrue | BFalse | BEq (a1 a2 : aexp) | BLe (a1 a2 : aexp) | BNot (b : bexp) | BAnd (b1 b2 : bexp).
Inductive
hoare_example
[ "From Coq Require Import\n Arith.", "From ExtLib Require Import\n Data.", "From ITree Require Import\n Events.", "From ExtLib Require Import\n Core." ]
hoare_example/Imp.v
bexp
com : Set := CSkip : com | CAss : string -> aexp -> com | CSeq : com -> com -> com | CIf : bexp -> com -> com -> com | CWhile : bexp -> com -> com. (* ========================================================================== *) (** ** Notations *)
Inductive
hoare_example
[ "From Coq Require Import\n Arith.", "From ExtLib Require Import\n Data.", "From ITree Require Import\n Events.", "From ExtLib Require Import\n Core." ]
hoare_example/Imp.v
com
AId : string >-> aexp.
Coercion
hoare_example
[ "From Coq Require Import\n Arith.", "From ExtLib Require Import\n Data.", "From ITree Require Import\n Events.", "From ExtLib Require Import\n Core." ]
hoare_example/Imp.v
AId
ANum : nat >-> aexp.
Coercion
hoare_example
[ "From Coq Require Import\n Arith.", "From ExtLib Require Import\n Data.", "From ITree Require Import\n Events.", "From ExtLib Require Import\n Core." ]
hoare_example/Imp.v
ANum
bool_to_bexp (b : bool) : bexp := if b then BTrue else BFalse.
Definition
hoare_example
[ "From Coq Require Import\n Arith.", "From ExtLib Require Import\n Data.", "From ITree Require Import\n Events.", "From ExtLib Require Import\n Core." ]
hoare_example/Imp.v
bool_to_bexp
bool_to_bexp : bool >-> bexp. Bind Scope imp_scope with aexp. Bind Scope imp_scope with bexp. Delimit Scope imp_scope with imp.
Coercion
hoare_example
[ "From Coq Require Import\n Arith.", "From ExtLib Require Import\n Data.", "From ITree Require Import\n Events.", "From ExtLib Require Import\n Core." ]
hoare_example/Imp.v
bool_to_bexp
var := string. (* Definition var : Set := string. *) (** For simplicity, the language manipulates [nat]s as values. *) (* Definition value : Type := nat. *)
Notation
hoare_example
[ "From Coq Require Import\n Arith.", "From ExtLib Require Import\n Data.", "From ITree Require Import\n Events.", "From ExtLib Require Import\n Core." ]
hoare_example/Imp.v
var
value := nat. (* (** Expressions are made of variables, constant literals, and arithmetic operations. *)
Notation
hoare_example
[ "From Coq Require Import\n Arith.", "From ExtLib Require Import\n Data.", "From ITree Require Import\n Events.", "From ExtLib Require Import\n Core." ]
hoare_example/Imp.v
value
expr : Type := | Var (_ : var) | Lit (_ : value) | Plus (_ _ : expr) | Minus (_ _ : expr) | Mult (_ _ : expr). (** The statements are straightforward. The [While] statement is the only potentially diverging one. *)
Inductive
hoare_example
[ "From Coq Require Import\n Arith.", "From ExtLib Require Import\n Data.", "From ITree Require Import\n Events.", "From ExtLib Require Import\n Core." ]
hoare_example/Imp.v
expr
stmt : Type := | Assign (x : var) (e : expr) (* x = e *) | Seq (a b : stmt) (* a ; b *) | If (i : expr) (t e : stmt) (* if (i) then { t } else { e } *) | While (t : expr) (b : stmt) (* while (t) { b } *) | Skip (* ; *) . (* ========================================================================== *) (** ** Notations *...
Inductive
hoare_example
[ "From Coq Require Import\n Arith.", "From ExtLib Require Import\n Data.", "From ITree Require Import\n Events.", "From ExtLib Require Import\n Core." ]
hoare_example/Imp.v
stmt
Var_coerce : string -> expr := Var.
Definition
hoare_example
[ "From Coq Require Import\n Arith.", "From ExtLib Require Import\n Data.", "From ITree Require Import\n Events.", "From ExtLib Require Import\n Core." ]
hoare_example/Imp.v
Var_coerce
Lit_coerce : nat -> expr := Lit.
Definition
hoare_example
[ "From Coq Require Import\n Arith.", "From ExtLib Require Import\n Data.", "From ITree Require Import\n Events.", "From ExtLib Require Import\n Core." ]
hoare_example/Imp.v
Lit_coerce
Var_coerce : string >-> expr.
Coercion
hoare_example
[ "From Coq Require Import\n Arith.", "From ExtLib Require Import\n Data.", "From ITree Require Import\n Events.", "From ExtLib Require Import\n Core." ]
hoare_example/Imp.v
Var_coerce
Lit_coerce : nat >-> expr. Bind Scope expr_scope with expr. Infix "+" := Plus : expr_scope. Infix "-" := Minus : expr_scope. Infix "*" := Mult : expr_scope. Bind Scope stmt_scope with stmt.
Coercion
hoare_example
[ "From Coq Require Import\n Arith.", "From ExtLib Require Import\n Data.", "From ITree Require Import\n Events.", "From ExtLib Require Import\n Core." ]
hoare_example/Imp.v
Lit_coerce
ImpState : Type -> Type := | GetVar (x : var) : ImpState value | SetVar (x : var) (v : value) : ImpState unit.
Variant
hoare_example
[ "From Coq Require Import\n Arith.", "From ExtLib Require Import\n Data.", "From ITree Require Import\n Events.", "From ExtLib Require Import\n Core." ]
hoare_example/Imp.v
ImpState
denote_aexp (e : aexp) : itree eff value := match e with | AId v => trigger (GetVar v) | ANum n => ret n | APlus a b => l <- denote_aexp a ;; r <- denote_aexp b ;; ret (l + r) | AMinus a b => l <- denote_aexp a ;; r <- denote_aexp b ;; ret (l - r) | AMult a b => l <- denote_aexp a ;; r <- denote_aexp b ;; ret (l * r) e...
Fixpoint
hoare_example
[ "From Coq Require Import\n Arith.", "From ExtLib Require Import\n Data.", "From ITree Require Import\n Events.", "From ExtLib Require Import\n Core." ]
hoare_example/Imp.v
denote_aexp
denote_bexp (e : bexp) : itree eff bool := match e with | BTrue => ret true | BFalse => ret false | BEq a b => l <- denote_aexp a ;; r <- denote_aexp b ;; ret (Nat.eqb l r) | BLe a b => l <- denote_aexp a ;; r <- denote_aexp b ;; ret (Nat.leb l r) | BNot a => b <- denote_bexp a ;; ret (negb b) | BAnd a b => l <- denote...
Fixpoint
hoare_example
[ "From Coq Require Import\n Arith.", "From ExtLib Require Import\n Data.", "From ITree Require Import\n Events.", "From ExtLib Require Import\n Core." ]
hoare_example/Imp.v
denote_bexp
while (step : itree eff (unit + unit)) : itree eff unit := @iter _ _ _ Iter_Kleisli _ _ (fun _ => step) tt. (** The meaning of statements is now easy to define. They are all straightforward, except for [While], which uses our new [while] combinator over the computation that evaluates the conditional, and then the body ...
Definition
hoare_example
[ "From Coq Require Import\n Arith.", "From ExtLib Require Import\n Data.", "From ITree Require Import\n Events.", "From ExtLib Require Import\n Core." ]
hoare_example/Imp.v
while
denote_com (s : com) : itree eff unit := match s with | CAss x e => v <- denote_aexp e ;; trigger (SetVar x v) | CSeq a b => denote_com a ;; denote_com b | CIf i t e => b <- denote_bexp i ;; if (b: bool) then denote_com t else denote_com e | CWhile t body => while (b <- denote_bexp t ;; if (b: bool) then denote_com bod...
Fixpoint
hoare_example
[ "From Coq Require Import\n Arith.", "From ExtLib Require Import\n Data.", "From ITree Require Import\n Events.", "From ExtLib Require Import\n Core." ]
hoare_example/Imp.v
denote_com
fact (n:nat): com := input ::= n;;; output ::= 1;;; WHILE ~(n = 0) DO output ::= output * input;;; input ::= input - 1 END. (** We have given _a_ notion of denotation to [fact 6] via [denote_com]. However this is naturally not actually runnable yet, since it contains uninterpreted [ImpState] events. We therefore now ne...
Definition
hoare_example
[ "From Coq Require Import\n Arith.", "From ExtLib Require Import\n Data.", "From ITree Require Import\n Events.", "From ExtLib Require Import\n Core." ]
hoare_example/Imp.v
fact
handle_ImpState {E: Type -> Type} `{mapE var 0 -< E}: ImpState ~> itree E := fun _ e => match e with | GetVar x => lookup_def x | SetVar x v => insert x v end. (** We now concretely implement this environment using ExtLib's finite maps. *)
Definition
hoare_example
[ "From Coq Require Import\n Arith.", "From ExtLib Require Import\n Data.", "From ITree Require Import\n Events.", "From ExtLib Require Import\n Core." ]
hoare_example/Imp.v
handle_ImpState
env := alist var value. (** Finally, we can define an evaluator for our statements. To do so, we first denote them, leading to an [itree ImpState unit]. We then [interp]ret [ImpState] into [mapE] using [handle_ImpState], leading to an [itree (mapE var value) unit]. Finally, [interp_map] interprets the latter [itree] in...
Definition
hoare_example
[ "From Coq Require Import\n Arith.", "From ExtLib Require Import\n Data.", "From ITree Require Import\n Events.", "From ExtLib Require Import\n Core." ]
hoare_example/Imp.v
env
interp_imp {E A} (t : itree (ImpState +' E) A) : stateT env (itree E) A := let t' := interp (bimap handle_ImpState (id_ E)) t in interp_map t'.
Definition
hoare_example
[ "From Coq Require Import\n Arith.", "From ExtLib Require Import\n Data.", "From ITree Require Import\n Events.", "From ExtLib Require Import\n Core." ]
hoare_example/Imp.v
interp_imp
eval_imp (s: com) : itree void1 (env * unit) := interp_imp (denote_com s) empty. (** Equipped with this evaluator, we can now compute. Naturally since Coq is total, we cannot do it directly inside of it. We can either rely on extraction, or use some fuel. *) (* YZ Is [burn] broken? *) (* Compute (burn 200 (eval_imp (fa...
Definition
hoare_example
[ "From Coq Require Import\n Arith.", "From ExtLib Require Import\n Data.", "From ITree Require Import\n Events.", "From ExtLib Require Import\n Core." ]
hoare_example/Imp.v
eval_imp
E := (ImpState +' E'). (** This interpreter is compatible with the equivalence-up-to-tau. *) Global Instance eutt_interp_imp {R}: Proper (@eutt E R R eq ==> eq ==> @eutt E' (prod (env) R) (prod _ R) eq) interp_imp. Proof. repeat intro. unfold interp_imp. unfold interp_map. rewrite H0. eapply eutt_interp_state_eq; auto....
Notation
hoare_example
[ "From Coq Require Import\n Arith.", "From ExtLib Require Import\n Data.", "From ITree Require Import\n Events.", "From ExtLib Require Import\n Core." ]
hoare_example/Imp.v
E
interp_imp_bind : forall {R S} (t: itree E R) (k: R -> itree E S) (g : env), (interp_imp (ITree.bind t k) g) ≅ (ITree.bind (interp_imp t g) (fun '(g', x) => interp_imp (k x) g')). Proof. intros. unfold interp_imp. unfold interp_map. repeat rewrite interp_bind. repeat rewrite interp_state_bind. apply eqit_bind. reflexiv...
Lemma
hoare_example
[ "From Coq Require Import\n Arith.", "From ExtLib Require Import\n Data.", "From ITree Require Import\n Events.", "From ExtLib Require Import\n Core." ]
hoare_example/Imp.v
interp_imp_bind
denote_imp (c : com) : stateT env Delay unit := interp_imp (denote_com c).
Definition
hoare_example
[ "From ExtLib Require Import\n Data.", "From ITree.Extra Require Import\n Dijkstra.", "From Paco Require Import paco.", "From hoare Require Import Imp." ]
hoare_example/ImpHoare.v
denote_imp
hoare_triple (P Q : env -> Prop) (c : com) : Prop := forall (s s' :env), P s -> (denote_imp c s ≈ ret (s',tt)) -> Q s'.
Definition
hoare_example
[ "From ExtLib Require Import\n Data.", "From ITree.Extra Require Import\n Dijkstra.", "From Paco Require Import paco.", "From hoare Require Import Imp." ]
hoare_example/ImpHoare.v
hoare_triple
lift_imp_post (P : env -> Prop) : Delay (env * unit) -> Prop := fun (t : Delay (env * unit) ) => (exists (s : env), ret (s, tt) ≈ t /\ P s).
Definition
hoare_example
[ "From ExtLib Require Import\n Data.", "From ITree.Extra Require Import\n Dijkstra.", "From Paco Require Import paco.", "From hoare Require Import Imp." ]
hoare_example/ImpHoare.v
lift_imp_post
is_bool (E : Type -> Type) (bc : bool) (be : bexp) (s : env) : Prop := @interp_imp E bool (denote_bexp be) s ≈ ret (s, bc).
Definition
hoare_example
[ "From ExtLib Require Import\n Data.", "From ITree.Extra Require Import\n Dijkstra.", "From Paco Require Import paco.", "From hoare Require Import Imp." ]
hoare_example/ImpHoare.v
is_bool
is_true (b : bexp) (s : env) : Prop := is_bool void1 true b s.
Definition
hoare_example
[ "From ExtLib Require Import\n Data.", "From ITree.Extra Require Import\n Dijkstra.", "From Paco Require Import paco.", "From hoare Require Import Imp." ]
hoare_example/ImpHoare.v
is_true
is_false (b : bexp) (s : env) : Prop := is_bool void1 false b s. (*
Definition
hoare_example
[ "From ExtLib Require Import\n Data.", "From ITree.Extra Require Import\n Dijkstra.", "From Paco Require Import paco.", "From hoare Require Import Imp." ]
hoare_example/ImpHoare.v
is_false
unf_intep := unfold interp_imp, interp_map, interp_state, interp, Basics.iter, MonadIter_stateT0, interp, Basics.iter, MonadIter_stateT0. *)
Ltac
hoare_example
[ "From ExtLib Require Import\n Data.", "From ITree.Extra Require Import\n Dijkstra.", "From Paco Require Import paco.", "From hoare Require Import Imp." ]
hoare_example/ImpHoare.v
unf_intep
aexp_term : forall (E : Type -> Type) (ae : aexp) (s : env), exists (n : nat), @interp_imp void1 _ (denote_aexp ae) s ≈ Ret (s,n). Proof. intros. induction ae. - exists n. cbn. tau_steps. reflexivity. (*getvar case, extract to a lemma*) - cbn. exists (lookup_default x 0 s). tau_steps. reflexivity. - basic_solve. exists...
Lemma
hoare_example
[ "From ExtLib Require Import\n Data.", "From ITree.Extra Require Import\n Dijkstra.", "From Paco Require Import paco.", "From hoare Require Import Imp." ]
hoare_example/ImpHoare.v
aexp_term
bools_term : forall (be : bexp) (s : env), exists (bc : bool), @interp_imp void1 _ (denote_bexp be) s ≈ Ret (s,bc). Proof. intros. induction be. - exists true. cbn. unfold interp_imp, interp_map, interp_state. repeat rewrite interp_ret. tau_steps. reflexivity. - exists false. tau_steps. reflexivity. - specialize (aexp_...
Lemma
hoare_example
[ "From ExtLib Require Import\n Data.", "From ITree.Extra Require Import\n Dijkstra.", "From Paco Require Import paco.", "From hoare Require Import Imp." ]
hoare_example/ImpHoare.v
bools_term
classic_bool : forall (b : bexp) (s : env), is_true b s \/ is_false b s. Proof. intros. specialize (bools_term b s) as Hbs. basic_solve. destruct bc; auto. Qed. (* *)
Lemma
hoare_example
[ "From ExtLib Require Import\n Data.", "From ITree.Extra Require Import\n Dijkstra.", "From Paco Require Import paco.", "From hoare Require Import Imp." ]
hoare_example/ImpHoare.v
classic_bool
hoare_seq : forall (c1 c2 : com) (P Q R : env -> Prop), {{P}} c1 {{Q}} -> {{Q}} c2 {{R}} -> {{P}} c1 ;;; c2 {{R}}. Proof. unfold hoare_triple. intros c1 c2 P Q R Hc1 Hc2 s s' Hs Hs'. unfold denote_imp in Hs'. cbn in Hs'. rewrite interp_imp_bind in Hs'. fold (denote_imp c1) in Hs'. fold (denote_imp c2) in Hs'. destruct ...
Lemma
hoare_example
[ "From ExtLib Require Import\n Data.", "From ITree.Extra Require Import\n Dijkstra.", "From Paco Require Import paco.", "From hoare Require Import Imp." ]
hoare_example/ImpHoare.v
hoare_seq
hoare_if : forall (c1 c2 : com) (b : bexp) (P Q : env -> Prop), {{fun s => is_true b s /\ P s}} c1 {{Q}} -> {{fun s => is_false b s /\ P s}} c2 {{Q}} -> {{ P }} TEST b THEN c1 ELSE c2 FI {{Q}}. Proof. unfold hoare_triple. intros c1 c2 b P Q Hc1 Hc2 s s' Hs. unfold denote_imp. cbn. destruct (classic_bool b s). - unfold ...
Lemma
hoare_example
[ "From ExtLib Require Import\n Data.", "From ITree.Extra Require Import\n Dijkstra.", "From Paco Require Import paco.", "From hoare Require Import Imp." ]
hoare_example/ImpHoare.v
hoare_if