sugar.v 2.36 KB
 Ralf Jung committed Feb 03, 2016 1 ``````Require Export heap_lang.heap_lang heap_lang.lifting. `````` Ralf Jung committed Jan 30, 2016 2 ``````Import uPred. `````` Robbert Krebbers committed Feb 02, 2016 3 ``````Import heap_lang. `````` Ralf Jung committed Jan 30, 2016 4 5 6 7 8 9 10 11 12 13 14 15 16 `````` (** Define some syntactic sugar. LitTrue and LitFalse are defined in heap_lang.v. *) Definition Lam (e : {bind expr}) := Rec e.[ren(+1)]. Definition Let (e1 : expr) (e2: {bind expr}) := App (Lam e2) e1. Definition Seq (e1 e2 : expr) := Let e1 e2.[ren(+1)]. Definition If (e0 e1 e2 : expr) := Case e0 e1.[ren(+1)] e2.[ren(+1)]. Definition Lt e1 e2 := Le (Plus e1 \$ LitNat 1) e2. Definition Eq e1 e2 := Let e1 (Let e2.[ren(+1)] (If (Le (Var 0) (Var 1)) (Le (Var 1) (Var 0)) LitFalse)). Definition LamV (e : {bind expr}) := RecV e.[ren(+1)]. `````` Robbert Krebbers committed Feb 02, 2016 17 18 ``````Definition LetCtx (e2 : {bind expr}) := AppRCtx (LamV e2). Definition SeqCtx (e2 : expr) := LetCtx (e2.[ren(+1)]). `````` Ralf Jung committed Jan 30, 2016 19 `````` `````` Robbert Krebbers committed Feb 01, 2016 20 ``````Section suger. `````` Robbert Krebbers committed Feb 01, 2016 21 22 ``````Context {Σ : iFunctor}. Implicit Types P : iProp heap_lang Σ. `````` Robbert Krebbers committed Feb 02, 2016 23 ``````Implicit Types Q : val → iProp heap_lang Σ. `````` Robbert Krebbers committed Feb 01, 2016 24 `````` `````` Ralf Jung committed Jan 30, 2016 25 26 ``````(** Proof rules for the sugar *) Lemma wp_lam E ef e v Q : `````` Robbert Krebbers committed Feb 02, 2016 27 `````` to_val e = Some v → ▷ wp E ef.[e/] Q ⊑ wp E (App (Lam ef) e) Q. `````` Ralf Jung committed Jan 30, 2016 28 29 30 31 32 33 ``````Proof. intros Hv. rewrite -wp_rec; last eassumption. (* RJ: This pulls in functional extensionality. If that bothers us, we have to talk to the Autosubst guys. *) by asimpl. Qed. `````` Robbert Krebbers committed Feb 02, 2016 34 ``````Lemma wp_let E e1 e2 Q : `````` Robbert Krebbers committed Feb 02, 2016 35 `````` wp E e1 (λ v, ▷wp E (e2.[of_val v/]) Q) ⊑ wp E (Let e1 e2) Q. `````` Ralf Jung committed Jan 30, 2016 36 ``````Proof. `````` Robbert Krebbers committed Feb 02, 2016 37 38 `````` rewrite -(wp_bind [LetCtx e2]). apply wp_mono=>v. by rewrite -wp_lam //= to_of_val. `````` Ralf Jung committed Jan 30, 2016 39 ``````Qed. `````` Robbert Krebbers committed Feb 02, 2016 40 ``````Lemma wp_if_true E e1 e2 Q : ▷ wp E e1 Q ⊑ wp E (If LitTrue e1 e2) Q. `````` Robbert Krebbers committed Feb 02, 2016 41 ``````Proof. rewrite -wp_case_inl //. by asimpl. Qed. `````` Robbert Krebbers committed Feb 02, 2016 42 ``````Lemma wp_if_false E e1 e2 Q : ▷ wp E e2 Q ⊑ wp E (If LitFalse e1 e2) Q. `````` Robbert Krebbers committed Feb 02, 2016 43 ``````Proof. rewrite -wp_case_inr //. by asimpl. Qed. `````` Robbert Krebbers committed Feb 02, 2016 44 ``````Lemma wp_lt E n1 n2 P Q : `````` Robbert Krebbers committed Feb 02, 2016 45 46 `````` (n1 < n2 → P ⊑ ▷ Q LitTrueV) → (n1 ≥ n2 → P ⊑ ▷ Q LitFalseV) → `````` Robbert Krebbers committed Feb 01, 2016 47 `````` P ⊑ wp E (Lt (LitNat n1) (LitNat n2)) Q. `````` Ralf Jung committed Jan 30, 2016 48 ``````Proof. `````` Robbert Krebbers committed Feb 02, 2016 49 50 `````` intros; rewrite -(wp_bind [LeLCtx _]) -wp_plus -later_intro /=. auto using wp_le with lia. `````` Ralf Jung committed Jan 30, 2016 51 ``````Qed. `````` Robbert Krebbers committed Feb 02, 2016 52 ``````Lemma wp_eq E n1 n2 P Q : `````` Robbert Krebbers committed Feb 02, 2016 53 54 `````` (n1 = n2 → P ⊑ ▷ Q LitTrueV) → (n1 ≠ n2 → P ⊑ ▷ Q LitFalseV) → `````` Robbert Krebbers committed Feb 01, 2016 55 `````` P ⊑ wp E (Eq (LitNat n1) (LitNat n2)) Q. `````` Ralf Jung committed Jan 30, 2016 56 57 ``````Proof. intros HPeq HPne. `````` Robbert Krebbers committed Feb 02, 2016 58 59 60 61 62 63 `````` rewrite -wp_let -wp_value' // -later_intro; asimpl. rewrite -wp_rec //; asimpl. rewrite -(wp_bind [CaseCtx _ _]) -later_intro; asimpl. apply wp_le; intros; asimpl. * rewrite -wp_case_inl // -!later_intro. apply wp_le; auto with lia. * rewrite -wp_case_inr // -later_intro -wp_value' //; auto with lia. `````` Ralf Jung committed Jan 30, 2016 64 ``````Qed. `````` Robbert Krebbers committed Feb 01, 2016 65 ``End suger.``