derived.v 2.69 KB
Newer Older
1
From heap_lang Require Export lifting.
2 3 4
Import uPred.

(** Define some derived forms, and derived lemmas about them. *)
5
Notation Lam x e := (Rec BAnom x e).
6
Notation Let x e1 e2 := (App (Lam x e2) e1).
7 8
Notation Seq e1 e2 := (Let BAnom e1 e2).
Notation LamV x e := (RecV BAnom x e).
9
Notation LetCtx x e2 := (AppRCtx (LamV x e2)).
10
Notation SeqCtx e2 := (LetCtx BAnom e2).
11
Notation Skip := (Seq (Lit LitUnit) (Lit LitUnit)).
12
Notation Match e0 x1 e1 x2 e2 := (Case e0 (Lam x1 e1) (Lam x2 e2)).
13 14

Section derived.
15
Context {Σ : rFunctor}.
16 17
Implicit Types P Q : iProp heap_lang Σ.
Implicit Types Φ : val  iProp heap_lang Σ.
18 19

(** Proof rules for the sugar *)
20
Lemma wp_lam E x ef e v Φ :
21
  to_val e = Some v 
22 23
   || subst' ef x v @ E {{ Φ }}  || App (Lam x ef) e @ E {{ Φ }}.
Proof. intros. by rewrite -wp_rec. Qed.
24

25
Lemma wp_let E x e1 e2 v Φ :
26
  to_val e1 = Some v 
27
   || subst' e2 x v @ E {{ Φ }}  || Let x e1 e2 @ E {{ Φ }}.
28
Proof. apply wp_lam. Qed.
29

30 31 32
Lemma wp_seq E e1 e2 v Φ :
  to_val e1 = Some v 
   || e2 @ E {{ Φ }}  || Seq e1 e2 @ E {{ Φ }}.
33
Proof. intros ?. by rewrite -wp_let. Qed.
34

35
Lemma wp_skip E Φ :  Φ (LitV LitUnit)  || Skip @ E {{ Φ }}.
36
Proof. rewrite -wp_seq // -wp_value //. Qed.
37

38 39 40 41 42 43 44 45 46 47 48 49 50 51
Lemma wp_match_inl E e0 v0 x1 e1 x2 e2 Φ :
  to_val e0 = Some v0 
   || subst' e1 x1 v0 @ E {{ Φ }}  || Match (InjL e0) x1 e1 x2 e2 @ E {{ Φ }}.
Proof.
  intros. rewrite -wp_case_inl // -[X in _  X]later_intro. by apply wp_let.
Qed.

Lemma wp_match_inr E e0 v0 x1 e1 x2 e2 Φ :
  to_val e0 = Some v0 
   || subst' e2 x2 v0 @ E {{ Φ }}  || Match (InjR e0) x1 e1 x2 e2 @ E {{ Φ }}.
Proof.
  intros. rewrite -wp_case_inr // -[X in _  X]later_intro. by apply wp_let.
Qed.

52
Lemma wp_le E (n1 n2 : Z) P Φ :
53 54 55
  (n1  n2  P   Φ (LitV (LitBool true))) 
  (n2 < n1  P   Φ (LitV (LitBool false))) 
  P  || BinOp LeOp (Lit (LitInt n1)) (Lit (LitInt n2)) @ E {{ Φ }}.
56 57 58 59 60
Proof.
  intros. rewrite -wp_bin_op //; [].
  destruct (bool_decide_reflect (n1  n2)); by eauto with omega.
Qed.

61
Lemma wp_lt E (n1 n2 : Z) P Φ :
62 63 64
  (n1 < n2  P   Φ (LitV (LitBool true))) 
  (n2  n1  P   Φ (LitV (LitBool false))) 
  P  || BinOp LtOp (Lit (LitInt n1)) (Lit (LitInt n2)) @ E {{ Φ }}.
65 66 67 68 69
Proof.
  intros. rewrite -wp_bin_op //; [].
  destruct (bool_decide_reflect (n1 < n2)); by eauto with omega.
Qed.

70
Lemma wp_eq E (n1 n2 : Z) P Φ :
71 72 73
  (n1 = n2  P   Φ (LitV (LitBool true))) 
  (n1  n2  P   Φ (LitV (LitBool false))) 
  P  || BinOp EqOp (Lit (LitInt n1)) (Lit (LitInt n2)) @ E {{ Φ }}.
74 75 76 77 78
Proof.
  intros. rewrite -wp_bin_op //; [].
  destruct (bool_decide_reflect (n1 = n2)); by eauto with omega.
Qed.
End derived.