derived.v 2.12 KB
Newer Older
1
From heap_lang Require Export lifting.
2 3 4 5 6 7 8 9 10
Import uPred.

(** Define some derived forms, and derived lemmas about them. *)
Notation Lam x e := (Rec "" x e).
Notation Let x e1 e2 := (App (Lam x e2) e1).
Notation Seq e1 e2 := (Let "" e1 e2).
Notation LamV x e := (RecV "" x e).
Notation LetCtx x e2 := (AppRCtx (LamV x e2)).
Notation SeqCtx e2 := (LetCtx "" e2).
11
Notation Skip := (Seq (Lit LitUnit) (Lit LitUnit)).
12 13 14 15 16 17 18

Section derived.
Context {Σ : iFunctor}.
Implicit Types P : iProp heap_lang Σ.
Implicit Types Q : val  iProp heap_lang Σ.

(** Proof rules for the sugar *)
19
Lemma wp_lam' E x ef e v Q :
20
  to_val e = Some v   wp E (subst ef x v) Q  wp E (App (Lam x ef) e) Q.
21
Proof. intros. by rewrite -wp_rec' ?subst_empty. Qed.
22

23
Lemma wp_let' E x e1 e2 v Q :
24
  to_val e1 = Some v   wp E (subst e2 x v) Q  wp E (Let x e1 e2) Q.
25
Proof. apply wp_lam'. Qed.
26 27 28 29

Lemma wp_seq E e1 e2 Q : wp E e1 (λ _,  wp E e2 Q)  wp E (Seq e1 e2) Q.
Proof.
  rewrite -(wp_bind [LetCtx "" e2]). apply wp_mono=>v.
30
  by rewrite -wp_let' //= ?to_of_val ?subst_empty.
31 32
Qed.

33
Lemma wp_skip E Q :  (Q (LitV LitUnit))  wp E Skip Q.
34 35
Proof. rewrite -wp_seq -wp_value // -wp_value //. Qed.

36
Lemma wp_le E (n1 n2 : Z) P Q :
37 38
  (n1  n2  P   Q (LitV $ LitBool true)) 
  (n2 < n1  P   Q (LitV $ LitBool false)) 
39
  P  wp E (BinOp LeOp (Lit $ LitInt n1) (Lit $ LitInt n2)) Q.
40 41 42 43 44
Proof.
  intros. rewrite -wp_bin_op //; [].
  destruct (bool_decide_reflect (n1  n2)); by eauto with omega.
Qed.

45
Lemma wp_lt E (n1 n2 : Z) P Q :
46 47
  (n1 < n2  P   Q (LitV $ LitBool true)) 
  (n2  n1  P   Q (LitV $ LitBool false)) 
48
  P  wp E (BinOp LtOp (Lit $ LitInt n1) (Lit $ LitInt n2)) Q.
49 50 51 52 53
Proof.
  intros. rewrite -wp_bin_op //; [].
  destruct (bool_decide_reflect (n1 < n2)); by eauto with omega.
Qed.

54
Lemma wp_eq E (n1 n2 : Z) P Q :
55 56
  (n1 = n2  P   Q (LitV $ LitBool true)) 
  (n1  n2  P   Q (LitV $ LitBool false)) 
57
  P  wp E (BinOp EqOp (Lit $ LitInt n1) (Lit $ LitInt n2)) Q.
58 59 60 61 62
Proof.
  intros. rewrite -wp_bin_op //; [].
  destruct (bool_decide_reflect (n1 = n2)); by eauto with omega.
Qed.
End derived.