derived.v 5.45 KB
Newer Older
Robbert Krebbers's avatar
Robbert Krebbers committed
1
From iris.base_logic Require Export upred.
2
From iris.bi Require Export derived_laws.
3
Set Default Proof Using "Type".
Robbert Krebbers's avatar
Robbert Krebbers committed
4
Import upred.uPred.
5
Import interface.bi derived_laws.bi.
6

7
Module uPred.
8 9 10 11 12 13
Section derived.
Context {M : ucmraT}.
Implicit Types φ : Prop.
Implicit Types P Q : uPred M.
Implicit Types A : Type.

Robbert Krebbers's avatar
Robbert Krebbers committed
14 15 16
(* Force implicit argument M *)
Notation "P ⊢ Q" := (bi_entails (PROP:=uPredI M) P%I Q%I).
Notation "P ⊣⊢ Q" := (equiv (A:=uPredI M) P%I Q%I).
17

Robbert Krebbers's avatar
Robbert Krebbers committed
18 19 20
(* Limits *)
Lemma limit_preserving_entails {A : ofeT} `{Cofe A} (Φ Ψ : A  uPred M) :
  NonExpansive Φ  NonExpansive Ψ  LimitPreserving (λ x, Φ x  Ψ x).
21
Proof.
Robbert Krebbers's avatar
Robbert Krebbers committed
22 23 24
  intros HΦ HΨ c Hc. etrans; [apply equiv_spec, compl_chain_map|].
  etrans; [|apply equiv_spec, symmetry, compl_chain_map].
  by apply entails_lim.
25
Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
26 27
Lemma limit_preserving_equiv {A : ofeT} `{Cofe A} (Φ Ψ : A  uPred M) :
  NonExpansive Φ  NonExpansive Ψ  LimitPreserving (λ x, Φ x  Ψ x).
28
Proof.
Robbert Krebbers's avatar
Robbert Krebbers committed
29 30 31
  intros HΦ HΨ. eapply limit_preserving_ext.
  { intros x. symmetry; apply equiv_spec. }
  apply limit_preserving_and; by apply limit_preserving_entails.
32 33 34
Qed.

(* Own and valid derived *)
35 36 37
Lemma persistently_cmra_valid_1 {A : cmraT} (a : A) :
   a  bi_persistently ( a : uPred M).
Proof. by rewrite {1}plainly_cmra_valid_1 plainly_elim_persistently. Qed.
38
Lemma affinely_persistently_ownM (a : M) : CoreId a   uPred_ownM a  uPred_ownM a.
39
Proof.
40
  rewrite affine_affinely=>?; apply (anti_symm _); [by rewrite persistently_elim|].
41
  by rewrite {1}persistently_ownM_core core_id_core.
42 43 44 45
Qed.
Lemma ownM_invalid (a : M) : ¬ {0} a  uPred_ownM a  False.
Proof. by intros; rewrite ownM_valid cmra_valid_elim. Qed.
Global Instance ownM_mono : Proper (flip () ==> ()) (@uPred_ownM M).
Robbert Krebbers's avatar
Robbert Krebbers committed
46
Proof. intros a b [b' ->]. by rewrite ownM_op sep_elim_l. Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
47
Lemma ownM_unit' : uPred_ownM ε  True.
48
Proof. apply (anti_symm _); first by apply pure_intro. apply ownM_unit. Qed.
49 50 51 52 53
Lemma affinely_plainly_cmra_valid {A : cmraT} (a : A) :   a   a.
Proof.
  rewrite affine_affinely.
  apply (anti_symm _), plainly_cmra_valid_1. apply plainly_elim, _.
Qed.
54
Lemma affinely_persistently_cmra_valid {A : cmraT} (a : A) :   a   a.
55
Proof.
56
  rewrite affine_affinely. intros; apply (anti_symm _); first by rewrite persistently_elim.
57
  apply:persistently_cmra_valid_1.
58 59 60 61 62 63 64
Qed.

(** * Derived rules *)
Global Instance bupd_mono' : Proper (() ==> ()) (@uPred_bupd M).
Proof. intros P Q; apply bupd_mono. Qed.
Global Instance bupd_flip_mono' : Proper (flip () ==> flip ()) (@uPred_bupd M).
Proof. intros P Q; apply bupd_mono. Qed.
65
Lemma bupd_frame_l R Q : (R  |==> Q) == R  Q.
66
Proof. rewrite !(comm _ R); apply bupd_frame_r. Qed.
67
Lemma bupd_wand_l P Q : (P - Q)  (|==> P) == Q.
68
Proof. by rewrite bupd_frame_l wand_elim_l. Qed.
69
Lemma bupd_wand_r P Q : (|==> P)  (P - Q) == Q.
70
Proof. by rewrite bupd_frame_r wand_elim_r. Qed.
71
Lemma bupd_sep P Q : (|==> P)  (|==> Q) == P  Q.
72 73 74 75 76 77
Proof. by rewrite bupd_frame_r bupd_frame_l bupd_trans. Qed.
Lemma bupd_ownM_update x y : x ~~> y  uPred_ownM x  |==> uPred_ownM y.
Proof.
  intros; rewrite (bupd_ownM_updateP _ (y =)); last by apply cmra_update_updateP.
  by apply bupd_mono, exist_elim=> y'; apply pure_elim_l=> ->.
Qed.
78
Lemma except_0_bupd P :  (|==> P)  (|==>  P).
79
Proof.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
80
  rewrite /sbi_except_0. apply or_elim; auto using bupd_mono, or_intro_r.
81 82 83
  by rewrite -bupd_intro -or_intro_l.
Qed.

Robbert Krebbers's avatar
Robbert Krebbers committed
84
(* Timeless instances *)
85
Global Instance valid_timeless {A : cmraT} `{CmraDiscrete A} (a : A) :
86
  Timeless ( a : uPred M)%I.
Robbert Krebbers's avatar
Robbert Krebbers committed
87
Proof. rewrite /Timeless !discrete_valid. apply (timeless _). Qed.
88
Global Instance ownM_timeless (a : M) : Discrete a  Timeless (uPred_ownM a).
89
Proof.
90
  intros ?. rewrite /Timeless later_ownM. apply exist_elim=> b.
Robbert Krebbers's avatar
Robbert Krebbers committed
91
  rewrite (timeless (ab)) (except_0_intro (uPred_ownM b)) -except_0_and.
92
  apply except_0_mono. rewrite internal_eq_sym.
Robbert Krebbers's avatar
Robbert Krebbers committed
93 94
  apply (internal_eq_rewrite' b a (uPred_ownM) _);
    auto using and_elim_l, and_elim_r.
95 96
Qed.

97
(* Plainness *)
98 99
Global Instance limit_preserving_Plain {A:ofeT} `{Cofe A} (Φ : A  uPred M) :
  NonExpansive Φ  LimitPreserving (λ x, Plain (Φ x)).
100
Proof. intros. apply limit_preserving_entails; solve_proper. Qed.
101 102 103
Global Instance cmra_valid_plain {A : cmraT} (a : A) :
  Plain ( a : uPred M)%I.
Proof. rewrite /Persistent. apply plainly_cmra_valid_1. Qed.
104

105 106
Lemma bupd_affinely_plainly P : (|==>  P)  P.
Proof. by rewrite affine_affinely bupd_plainly. Qed.
107 108

Lemma bupd_plain P `{!Plain P} : (|==> P)  P.
109
Proof. by rewrite -{1}(plain_plainly P) bupd_plainly. Qed.
110

111
(* Persistence *)
112 113
Global Instance limit_preserving_Persistent {A:ofeT} `{Cofe A} (Φ : A  uPred M) :
  NonExpansive Φ  LimitPreserving (λ x, Persistent (Φ x)).
Robbert Krebbers's avatar
Robbert Krebbers committed
114
Proof. intros. apply limit_preserving_entails; solve_proper. Qed.
115
Global Instance cmra_valid_persistent {A : cmraT} (a : A) :
116
  Persistent ( a : uPred M)%I.
117 118 119 120 121
Proof. rewrite /Persistent. apply persistently_cmra_valid_1. Qed.
Global Instance ownM_persistent a : CoreId a  Persistent (@uPred_ownM M a).
Proof.
  intros. rewrite /Persistent -{2}(core_id_core a). apply persistently_ownM_core.
Qed.
122 123 124

(* For big ops *)
Global Instance uPred_ownM_sep_homomorphism :
125
  MonoidHomomorphism op uPred_sep () (@uPred_ownM M).
Robbert Krebbers's avatar
Robbert Krebbers committed
126
Proof. split; [split; try apply _|]. apply ownM_op. apply ownM_unit'. Qed.
127
End derived.
Robbert Krebbers's avatar
Robbert Krebbers committed
128 129

(* Also add this to the global hint database, otherwise [eauto] won't work for
130
many lemmas that have [BiAffine] as a premise. *)
Robbert Krebbers's avatar
Robbert Krebbers committed
131
Hint Immediate uPred_affine.
132
End uPred.