derived.v 2.13 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).
Ralf Jung's avatar
Ralf Jung committed
11
Notation Skip := (Seq (Lit LitUnit) (Lit LitUnit)).
12 13

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

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

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

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

34
Lemma wp_skip E Φ :  Φ (LitV LitUnit)  || Skip @ E {{ Φ }}.
35
Proof. rewrite -wp_seq // -wp_value //. Qed.
Ralf Jung's avatar
Ralf Jung committed
36

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

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

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