monpred.v 46.4 KB
Newer Older
1
From stdpp Require Import coPset.
2
From iris.bi Require Import bi.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
3

4
(** Definitions. *)
5
Structure biIndex :=
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
6 7
  BiIndex
    { bi_index_type :> Type;
8
      bi_index_inhabited : Inhabited bi_index_type;
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
9 10
      bi_index_rel : SqSubsetEq bi_index_type;
      bi_index_rel_preorder : PreOrder () }.
11
Existing Instances bi_index_inhabited bi_index_rel bi_index_rel_preorder.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
12

Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
13 14 15 16
(* We may want to instantiate monPred with the reflexivity relation in
   the case where there is no relevent order. In that case, there is
   no bottom element, so that we do not want to force any BI index to
   have one. *)
17 18 19
Class BiIndexBottom {I : biIndex} (bot : I) :=
  bi_index_bot i : bot  i.

Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
20
Section Ofe_Cofe.
21
Context {I : biIndex} {PROP : bi}.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
22 23 24
Implicit Types i : I.

Record monPred :=
25 26
  MonPred { monPred_at :> I  PROP;
            monPred_mono : Proper (() ==> ()) monPred_at }.
27
Local Existing Instance monPred_mono.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
28

29 30
Bind Scope monPred with bi.

Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
31
Implicit Types P Q : monPred.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
32

33
(** Ofe + Cofe instances  *)
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
34

Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
35 36
Section Ofe_Cofe_def.
  Inductive monPred_equiv' P Q : Prop :=
37
    { monPred_in_equiv i : P i  Q i } .
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
38 39
  Instance monPred_equiv : Equiv monPred := monPred_equiv'.
  Inductive monPred_dist' (n : nat) (P Q : monPred) : Prop :=
40
    { monPred_in_dist i : P i {n} Q i }.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
41
  Instance monPred_dist : Dist monPred := monPred_dist'.
42

43
  Definition monPred_sig P : { f : I -c> PROP | Proper (() ==> ()) f } :=
44
    exist _ (monPred_at P) (monPred_mono P).
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
45

46
  Definition sig_monPred (P' : { f : I -c> PROP | Proper (() ==> ()) f })
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
47 48
    : monPred :=
    MonPred (proj1_sig P') (proj2_sig P').
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
49

50 51 52 53
  (* These two lemma use the wrong Equiv and Dist instance for
    monPred. so we make sure they are not accessible outside of the
    section by using Let. *)
  Let monPred_sig_equiv:
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
54
     P Q, P  Q  monPred_sig P  monPred_sig Q.
55 56
  Proof. by split; [intros []|]. Qed.
  Let monPred_sig_dist:
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
57
     n,  P Q : monPred, P {n} Q  monPred_sig P {n} monPred_sig Q.
58
  Proof. by split; [intros []|]. Qed.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
59

Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
60
  Definition monPred_ofe_mixin : OfeMixin monPred.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
61 62
  Proof. by apply (iso_ofe_mixin monPred_sig monPred_sig_equiv monPred_sig_dist). Qed.

63
  Canonical Structure monPredC := OfeT monPred monPred_ofe_mixin.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
64

65
  Global Instance monPred_cofe `{Cofe PROP} : Cofe monPredC.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
66
  Proof.
67
    unshelve refine (iso_cofe_subtype (A:=I-c>PROP) _ MonPred monPred_at _ _ _);
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
68
      [apply _|by apply monPred_sig_dist|done|].
69 70
    intros c i j Hij. apply @limit_preserving;
      [by apply bi.limit_preserving_entails; intros ??|]=>n. by rewrite Hij.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
71
  Qed.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
72 73
End Ofe_Cofe_def.

74
Lemma monPred_sig_monPred (P' : { f : I -c> PROP | Proper (() ==> ()) f }) :
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
75 76 77 78 79 80 81 82 83 84 85 86 87
  monPred_sig (sig_monPred P')  P'.
Proof. by change (P'  P'). Qed.
Lemma sig_monPred_sig P : sig_monPred (monPred_sig P)  P.
Proof. done. Qed.

Global Instance monPred_sig_ne : NonExpansive monPred_sig.
Proof. move=> ??? [?] ? //=. Qed.
Global Instance monPred_sig_proper : Proper (() ==> ()) monPred_sig.
Proof. eapply (ne_proper _). Qed.
Global Instance sig_monPred_ne : NonExpansive (@sig_monPred).
Proof. split=>? //=. Qed.
Global Instance sig_monPred_proper : Proper (() ==> ()) sig_monPred.
Proof. eapply (ne_proper _). Qed.
88 89 90 91 92 93

(* We generalize over the relation R which is morally the equivalence
   relation over B. That way, the BI index can use equality as an
   equivalence relation (and Coq is able to infer the Proper and
   Reflexive instances properly), or any other equivalence relation,
   provided it is compatible with (⊑). *)
94
Global Instance monPred_at_ne (R : relation I) :
95
  Proper (R ==> R ==> iff) ()  Reflexive R 
96
   n, Proper (dist n ==> R ==> dist n) monPred_at.
97 98 99 100
Proof.
  intros ????? [Hd] ?? HR. rewrite Hd.
  apply equiv_dist, bi.equiv_spec; split; f_equiv; rewrite ->HR; done.
Qed.
101
Global Instance monPred_at_proper (R : relation I) :
102
  Proper (R ==> R ==> iff) ()  Reflexive R 
103
  Proper (() ==> R ==> ()) monPred_at.
104
Proof. repeat intro. apply equiv_dist=>?. f_equiv=>//. by apply equiv_dist. Qed.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
105 106 107
End Ofe_Cofe.

Arguments monPred _ _ : clear implicits.
108
Arguments monPred_at {_ _} _%I _.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
109
Local Existing Instance monPred_mono.
110
Arguments monPredC _ _ : clear implicits.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
111

112 113
(** BI and SBI structures. *)

Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
114
Section Bi.
115
Context {I : biIndex} {PROP : bi}.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
116
Implicit Types i : I.
117
Notation monPred := (monPred I PROP).
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
118 119 120
Implicit Types P Q : monPred.

Inductive monPred_entails (P1 P2 : monPred) : Prop :=
121
  { monPred_in_entails i : P1 i  P2 i }.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
122 123
Hint Immediate monPred_in_entails.

124
Program Definition monPred_upclosed (Φ : I  PROP) : monPred :=
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
125
  MonPred (λ i, ( j, i  j  Φ j)%I) _.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
126
Next Obligation. solve_proper. Qed.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
127

128 129
Definition monPred_embed_def (P : PROP) : monPred := MonPred (λ _, P) _.
Definition monPred_embed_aux : seal (@monPred_embed_def). by eexists. Qed.
130 131
Definition monPred_embed : Embed PROP monPred := monPred_embed_aux.(unseal).
Definition monPred_embed_eq : @embed _ _ monPred_embed = _ := monPred_embed_aux.(seal_eq).
132 133 134

Definition monPred_emp_def : monPred := MonPred (λ _, emp)%I _.
Definition monPred_emp_aux : seal (@monPred_emp_def). by eexists. Qed.
135 136
Definition monPred_emp := monPred_emp_aux.(unseal).
Definition monPred_emp_eq : @monPred_emp = _ := monPred_emp_aux.(seal_eq).
137 138 139

Definition monPred_pure_def (φ : Prop) : monPred := MonPred (λ _, ⌜φ⌝)%I _.
Definition monPred_pure_aux : seal (@monPred_pure_def). by eexists. Qed.
140 141
Definition monPred_pure := monPred_pure_aux.(unseal).
Definition monPred_pure_eq : @monPred_pure = _ := monPred_pure_aux.(seal_eq).
142

143 144
Definition monPred_objectively_def P : monPred := MonPred (λ _,  i, P i)%I _.
Definition monPred_objectively_aux : seal (@monPred_objectively_def). by eexists. Qed.
145 146
Definition monPred_objectively := monPred_objectively_aux.(unseal).
Definition monPred_objectively_eq : @monPred_objectively = _ := monPred_objectively_aux.(seal_eq).
147

148 149
Definition monPred_subjectively_def P : monPred := MonPred (λ _,  i, P i)%I _.
Definition monPred_subjectively_aux : seal (@monPred_subjectively_def). by eexists. Qed.
150 151
Definition monPred_subjectively := monPred_subjectively_aux.(unseal).
Definition monPred_subjectively_eq : @monPred_subjectively = _ := monPred_subjectively_aux.(seal_eq).
152

Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
153 154
Program Definition monPred_and_def P Q : monPred :=
  MonPred (λ i, P i  Q i)%I _.
155
Next Obligation. solve_proper. Qed.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
156
Definition monPred_and_aux : seal (@monPred_and_def). by eexists. Qed.
157 158
Definition monPred_and := monPred_and_aux.(unseal).
Definition monPred_and_eq : @monPred_and = _ := monPred_and_aux.(seal_eq).
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
159

Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
160 161
Program Definition monPred_or_def P Q : monPred :=
  MonPred (λ i, P i  Q i)%I _.
162
Next Obligation. solve_proper. Qed.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
163
Definition monPred_or_aux : seal (@monPred_or_def). by eexists. Qed.
164 165
Definition monPred_or := monPred_or_aux.(unseal).
Definition monPred_or_eq : @monPred_or = _ := monPred_or_aux.(seal_eq).
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
166

Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
167
Definition monPred_impl_def P Q : monPred :=
168
  monPred_upclosed (λ i, P i  Q i)%I.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
169
Definition monPred_impl_aux : seal (@monPred_impl_def). by eexists. Qed.
170 171
Definition monPred_impl := monPred_impl_aux.(unseal).
Definition monPred_impl_eq : @monPred_impl = _ := monPred_impl_aux.(seal_eq).
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
172

Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
173 174
Program Definition monPred_forall_def A (Φ : A  monPred) : monPred :=
  MonPred (λ i,  x : A, Φ x i)%I _.
175
Next Obligation. solve_proper. Qed.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
176
Definition monPred_forall_aux : seal (@monPred_forall_def). by eexists. Qed.
177 178
Definition monPred_forall := monPred_forall_aux.(unseal).
Definition monPred_forall_eq : @monPred_forall = _ := monPred_forall_aux.(seal_eq).
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
179

Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
180 181
Program Definition monPred_exist_def A (Φ : A  monPred) : monPred :=
  MonPred (λ i,  x : A, Φ x i)%I _.
182
Next Obligation. solve_proper. Qed.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
183
Definition monPred_exist_aux : seal (@monPred_exist_def). by eexists. Qed.
184 185
Definition monPred_exist := monPred_exist_aux.(unseal).
Definition monPred_exist_eq : @monPred_exist = _ := monPred_exist_aux.(seal_eq).
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
186

Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
187 188
Program Definition monPred_sep_def P Q : monPred :=
  MonPred (λ i, P i  Q i)%I _.
189
Next Obligation. solve_proper. Qed.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
190
Definition monPred_sep_aux : seal (@monPred_sep_def). by eexists. Qed.
191 192
Definition monPred_sep := monPred_sep_aux.(unseal).
Definition monPred_sep_eq : @monPred_sep = _ := monPred_sep_aux.(seal_eq).
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
193

Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
194
Definition monPred_wand_def P Q : monPred :=
195
  monPred_upclosed (λ i, P i - Q i)%I.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
196
Definition monPred_wand_aux : seal (@monPred_wand_def). by eexists. Qed.
197 198
Definition monPred_wand := monPred_wand_aux.(unseal).
Definition monPred_wand_eq : @monPred_wand = _ := monPred_wand_aux.(seal_eq).
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
199

Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
200
Program Definition monPred_persistently_def P : monPred :=
201
  MonPred (λ i, <pers> (P i))%I _.
202
Next Obligation. solve_proper. Qed.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
203
Definition monPred_persistently_aux : seal (@monPred_persistently_def). by eexists. Qed.
204 205
Definition monPred_persistently := monPred_persistently_aux.(unseal).
Definition monPred_persistently_eq : @monPred_persistently = _ := monPred_persistently_aux.(seal_eq).
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
206

Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
207 208
Program Definition monPred_in_def (i0 : I) : monPred :=
  MonPred (λ i : I, i0  i%I) _.
209
Next Obligation. solve_proper. Qed.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
210
Definition monPred_in_aux : seal (@monPred_in_def). by eexists. Qed.
211 212
Definition monPred_in := monPred_in_aux.(unseal).
Definition monPred_in_eq : @monPred_in = _ := monPred_in_aux.(seal_eq).
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
213

214 215 216 217 218 219 220
Definition monPred_bupd_def `{BUpd PROP} (P : monPred) : monPred :=
  (* monPred_upclosed is not actually needed, since bupd is always
     monotone. However, this depends on BUpdFacts, and we do not want
     this definition to depend on BUpdFacts to avoid having proofs
     terms in logical terms. *)
  monPred_upclosed (λ i, |==> P i)%I.
Definition monPred_bupd_aux `{BUpd PROP} : seal monPred_bupd_def. by eexists. Qed.
221 222
Definition monPred_bupd `{BUpd PROP} : BUpd _ := monPred_bupd_aux.(unseal).
Definition monPred_bupd_eq `{BUpd PROP} : @bupd _ monPred_bupd = _ := monPred_bupd_aux.(seal_eq).
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
223 224
End Bi.

225 226
Arguments monPred_objectively {_ _} _%I.
Arguments monPred_subjectively {_ _} _%I.
Robbert Krebbers's avatar
Robbert Krebbers committed
227 228
Notation "'<obj>' P" := (monPred_objectively P) (at level 20, right associativity) : bi_scope.
Notation "'<subj>' P" := (monPred_subjectively P) (at level 20, right associativity) : bi_scope.
229

230 231 232 233 234 235
Section Sbi.
Context {I : biIndex} {PROP : sbi}.
Implicit Types i : I.
Notation monPred := (monPred I PROP).
Implicit Types P Q : monPred.

Robbert Krebbers's avatar
Robbert Krebbers committed
236 237
Definition monPred_plainly_def `{BiPlainly PROP} P : monPred := MonPred (λ _,  i,  (P i))%I _.
Definition monPred_plainly_aux `{BiPlainly PROP} : seal monPred_plainly_def. by eexists. Qed.
238 239
Definition monPred_plainly `{BiPlainly PROP} : Plainly _ := monPred_plainly_aux.(unseal).
Definition monPred_plainly_eq `{BiPlainly PROP} : @plainly _ monPred_plainly = _ := monPred_plainly_aux.(seal_eq).
Robbert Krebbers's avatar
Robbert Krebbers committed
240

241 242
Definition monPred_internal_eq_def (A : ofeT) (a b : A) : monPred := MonPred (λ _, a  b)%I _.
Definition monPred_internal_eq_aux : seal (@monPred_internal_eq_def). by eexists. Qed.
243 244
Definition monPred_internal_eq := monPred_internal_eq_aux.(unseal).
Definition monPred_internal_eq_eq : @monPred_internal_eq = _ := monPred_internal_eq_aux.(seal_eq).
245

246
Program Definition monPred_later_def P : monPred := MonPred (λ i,  (P i))%I _.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
247
Next Obligation. solve_proper. Qed.
248
Definition monPred_later_aux : seal monPred_later_def. by eexists. Qed.
249 250
Definition monPred_later := monPred_later_aux.(unseal).
Definition monPred_later_eq : monPred_later = _ := monPred_later_aux.(seal_eq).
251 252 253 254 255 256 257 258

Definition monPred_fupd_def `{FUpd PROP} (E1 E2 : coPset) (P : monPred) : monPred :=
  (* monPred_upclosed is not actually needed, since fupd is always
     monotone. However, this depends on FUpdFacts, and we do not want
     this definition to depend on FUpdFacts to avoid having proofs
     terms in logical terms. *)
  monPred_upclosed (λ i, |={E1,E2}=> P i)%I.
Definition monPred_fupd_aux `{FUpd PROP} : seal monPred_fupd_def. by eexists. Qed.
259 260
Definition monPred_fupd `{FUpd PROP} : FUpd _ := monPred_fupd_aux.(unseal).
Definition monPred_fupd_eq `{FUpd PROP} : @fupd _ monPred_fupd = _ := monPred_fupd_aux.(seal_eq).
261
End Sbi.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
262

263
Module MonPred.
264 265
Definition unseal_eqs :=
  (@monPred_and_eq, @monPred_or_eq, @monPred_impl_eq,
266
   @monPred_forall_eq, @monPred_exist_eq,
267
   @monPred_sep_eq, @monPred_wand_eq,
268 269
   @monPred_persistently_eq, @monPred_later_eq, @monPred_internal_eq_eq, @monPred_in_eq,
   @monPred_embed_eq, @monPred_emp_eq, @monPred_pure_eq, @monPred_plainly_eq,
270
   @monPred_objectively_eq, @monPred_subjectively_eq, @monPred_bupd_eq, @monPred_fupd_eq).
271 272
Ltac unseal :=
  unfold bi_affinely, bi_absorbingly, sbi_except_0, bi_pure, bi_emp,
273
         monPred_upclosed, bi_and, bi_or,
274
         bi_impl, bi_forall, bi_exist, sbi_internal_eq, bi_sep, bi_wand,
Robbert Krebbers's avatar
Robbert Krebbers committed
275
         bi_persistently, bi_affinely, sbi_later;
276
  simpl;
277
  unfold sbi_emp, sbi_pure, sbi_and, sbi_or, sbi_impl, sbi_forall, sbi_exist,
Robbert Krebbers's avatar
Robbert Krebbers committed
278
         sbi_internal_eq, sbi_sep, sbi_wand, sbi_persistently;
Ralf Jung's avatar
Ralf Jung committed
279
  simpl;
280
  rewrite !unseal_eqs /=.
281 282
End MonPred.
Import MonPred.
283

Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
284
Section canonical_bi.
285
Context (I : biIndex) (PROP : bi).
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
286

287
Lemma monPred_bi_mixin : BiMixin (PROP:=monPred I PROP)
288
  monPred_entails monPred_emp monPred_pure monPred_and monPred_or
289
  monPred_impl monPred_forall monPred_exist monPred_sep monPred_wand
Robbert Krebbers's avatar
Robbert Krebbers committed
290
  monPred_persistently.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
291
Proof.
292
  split; try unseal; try by (split=> ? /=; repeat f_equiv).
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
293
  - split.
Robbert Krebbers's avatar
Robbert Krebbers committed
294 295
    + intros P. by split.
    + intros P Q R [H1] [H2]. split => ?. by rewrite H1 H2.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
296
  - split.
297 298
    + intros [HPQ]. split; split => i; move: (HPQ i); by apply bi.equiv_spec.
    + intros [[] []]. split=>i. by apply bi.equiv_spec.
Robbert Krebbers's avatar
Robbert Krebbers committed
299 300 301 302 303 304 305 306 307 308 309 310 311 312
  - intros P φ ?. split=> i. by apply bi.pure_intro.
  - intros φ P HP. split=> i. apply bi.pure_elim'=> ?. by apply HP.
  - intros A φ. split=> i. by apply bi.pure_forall_2.
  - intros P Q. split=> i. by apply bi.and_elim_l.
  - intros P Q. split=> i. by apply bi.and_elim_r.
  - intros P Q R [?] [?]. split=> i. by apply bi.and_intro.
  - intros P Q. split=> i. by apply bi.or_intro_l.
  - intros P Q. split=> i. by apply bi.or_intro_r.
  - intros P Q R [?] [?]. split=> i. by apply bi.or_elim.
  - intros P Q R [HR]. split=> i /=. setoid_rewrite bi.pure_impl_forall.
    apply bi.forall_intro=> j. apply bi.forall_intro=> Hij.
    apply bi.impl_intro_r. by rewrite -HR /= !Hij.
  - intros P Q R [HR]. split=> i /=.
     rewrite HR /= bi.forall_elim bi.pure_impl_forall bi.forall_elim //.
313
    apply bi.impl_elim_l.
Robbert Krebbers's avatar
Robbert Krebbers committed
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
  - intros A P Ψ HΨ. split=> i. apply bi.forall_intro => ?. by apply HΨ.
  - intros A Ψ. split=> i. by apply: bi.forall_elim.
  - intros A Ψ a. split=> i. by rewrite /= -bi.exist_intro.
  - intros A Ψ Q HΨ. split=> i. apply bi.exist_elim => a. by apply HΨ.
  - intros P P' Q Q' [?] [?]. split=> i. by apply bi.sep_mono.
  - intros P. split=> i. by apply bi.emp_sep_1.
  - intros P. split=> i. by apply bi.emp_sep_2.
  - intros P Q. split=> i. by apply bi.sep_comm'.
  - intros P Q R. split=> i. by apply bi.sep_assoc'.
  - intros P Q R [HR]. split=> i /=. setoid_rewrite bi.pure_impl_forall.
    apply bi.forall_intro=> j. apply bi.forall_intro=> Hij.
    apply bi.wand_intro_r. by rewrite -HR /= !Hij.
  - intros P Q R [HP]. split=> i. apply bi.wand_elim_l'.
    rewrite HP /= bi.forall_elim bi.pure_impl_forall bi.forall_elim //.
  - intros P Q [?]. split=> i /=. by f_equiv.
  - intros P. split=> i. by apply bi.persistently_idemp_2.
Robbert Krebbers's avatar
Robbert Krebbers committed
330
  - intros P. split=> i. by apply bi.persistently_emp_intro.
Robbert Krebbers's avatar
Robbert Krebbers committed
331 332 333 334
  - intros A Ψ. split=> i. by apply bi.persistently_forall_2.
  - intros A Ψ. split=> i. by apply bi.persistently_exist_1.
  - intros P Q. split=> i. apply bi.sep_elim_l, _.
  - intros P Q. split=> i. by apply bi.persistently_and_sep_elim.
335
Qed.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
336

Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
337
Canonical Structure monPredI : bi :=
Robbert Krebbers's avatar
Robbert Krebbers committed
338
  {| bi_ofe_mixin := monPred_ofe_mixin; bi_bi_mixin := monPred_bi_mixin |}.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
339 340 341
End canonical_bi.

Section canonical_sbi.
342
Context (I : biIndex) (PROP : sbi).
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
343

Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
344
Lemma monPred_sbi_mixin :
Robbert Krebbers's avatar
Robbert Krebbers committed
345 346 347
  SbiMixin (PROP:=monPred I PROP) monPred_entails monPred_pure
           monPred_or monPred_impl monPred_forall monPred_exist
           monPred_sep monPred_persistently monPred_internal_eq monPred_later.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
348
Proof.
Robbert Krebbers's avatar
Robbert Krebbers committed
349 350 351
  split; unseal.
  - intros n P Q HPQ. split=> i /=.
    apply bi.later_contractive. destruct n as [|n]=> //. by apply HPQ.
352 353 354 355 356 357 358 359
  - by split=> ? /=; repeat f_equiv.
  - intros A P a. split=> i. by apply bi.internal_eq_refl.
  - intros A a b Ψ ?. split=> i /=.
    setoid_rewrite bi.pure_impl_forall. do 2 apply bi.forall_intro => ?.
    erewrite (bi.internal_eq_rewrite _ _ (flip Ψ _)) => //=. solve_proper.
  - intros A1 A2 f g. split=> i. by apply bi.fun_ext.
  - intros A P x y. split=> i. by apply bi.sig_eq.
  - intros A a b ?. split=> i. by apply bi.discrete_eq_1.
Robbert Krebbers's avatar
Robbert Krebbers committed
360 361 362 363 364 365 366 367 368 369 370 371 372
  - intros A x y. split=> i. by apply bi.later_eq_1.
  - intros A x y. split=> i. by apply bi.later_eq_2.
  - intros P Q [?]. split=> i. by apply bi.later_mono.
  - intros P. split=> i /=.
    setoid_rewrite bi.pure_impl_forall. rewrite /= !bi.forall_elim //. by apply bi.löb.
  - intros A Ψ. split=> i. by apply bi.later_forall_2.
  - intros A Ψ. split=> i. by apply bi.later_exist_false.
  - intros P Q. split=> i. by apply bi.later_sep_1.
  - intros P Q. split=> i. by apply bi.later_sep_2.
  - intros P. split=> i. by apply bi.later_persistently_1.
  - intros P. split=> i. by apply bi.later_persistently_2.
  - intros P. split=> i /=. rewrite -bi.forall_intro. apply bi.later_false_em.
    intros j. rewrite bi.pure_impl_forall. apply bi.forall_intro=> Hij. by rewrite Hij.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
373
Qed.
374

Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
375
Canonical Structure monPredSI : sbi :=
Robbert Krebbers's avatar
Robbert Krebbers committed
376 377
  {| sbi_ofe_mixin := monPred_ofe_mixin; sbi_bi_mixin := monPred_bi_mixin I PROP;
     sbi_sbi_mixin := monPred_sbi_mixin |}.
378

Robbert Krebbers's avatar
Robbert Krebbers committed
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419
Lemma monPred_plainly_mixin `{BiPlainly PROP} : BiPlainlyMixin monPredSI monPred_plainly.
Proof.
  split; unseal.
  - by (split=> ? /=; repeat f_equiv).
  - intros P Q [?]. split=> i /=. by do 3 f_equiv.
  - intros P. split=> i /=. by rewrite bi.forall_elim plainly_elim_persistently.
  - intros P. split=> i /=. repeat setoid_rewrite <-plainly_forall.
    rewrite -plainly_idemp_2. f_equiv. by apply bi.forall_intro=>_.
  - intros A Ψ. split=> i /=. apply bi.forall_intro=> j.
    rewrite plainly_forall. apply bi.forall_intro=> a.
    by rewrite !bi.forall_elim.
  - intros P Q. split=> i /=. repeat setoid_rewrite bi.pure_impl_forall.
    repeat setoid_rewrite <-plainly_forall.
    repeat setoid_rewrite bi.persistently_forall. do 4 f_equiv.
    apply persistently_impl_plainly.
  - intros P Q. split=> i /=.
    repeat setoid_rewrite bi.pure_impl_forall. rewrite 2!bi.forall_elim //.
    repeat setoid_rewrite <-plainly_forall.
    setoid_rewrite plainly_impl_plainly. f_equiv.
    do 3 apply bi.forall_intro => ?. f_equiv. rewrite bi.forall_elim //.
  - intros P. split=> i /=. apply bi.forall_intro=>_. by apply plainly_emp_intro.
  - intros P Q. split=> i. apply bi.sep_elim_l, _.
  - intros P Q. split=> i /=.
    rewrite <-(sig_monPred_sig P), <-(sig_monPred_sig Q), <-(bi.f_equiv _).
    rewrite -bi.sig_equivI /= -bi.fun_ext. f_equiv=> j.
    rewrite -prop_ext !(bi.forall_elim j) !bi.pure_impl_forall
            !bi.forall_elim //.
  - intros P. split=> i /=.
    rewrite bi.later_forall. f_equiv=> j. by rewrite -later_plainly_1.
  - intros P. split=> i /=.
    rewrite bi.later_forall. f_equiv=> j. by rewrite -later_plainly_2.
Qed.
Global Instance monPred_plainlyC `{BiPlainly PROP} : BiPlainly monPredSI :=
  {| bi_plainly_mixin := monPred_plainly_mixin |}.

Global Instance monPred_plainly_exist `{BiPlainly PROP} `{@BiIndexBottom I bot} :
  BiPlainlyExist PROP  BiPlainlyExist monPredSI.
Proof.
  split=>?/=. unseal. rewrite (bi.forall_elim bot) plainly_exist_1. do 2 f_equiv.
  apply bi.forall_intro=>?. by do 2 f_equiv.
Qed.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
420
End canonical_sbi.
421

422 423 424 425 426 427
Class Objective {I : biIndex} {PROP : bi} (P : monPred I PROP) :=
  objective_at i j : P i - P j.
Arguments Objective {_ _} _%I.
Arguments objective_at {_ _} _%I {_}.
Hint Mode Objective + + ! : typeclass_instances.
Instance: Params (@Objective) 2.
428

429 430
(** Primitive facts that cannot be deduced from the BI structure. *)

Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
431
Section bi_facts.
432
Context {I : biIndex} {PROP : bi}.
433
Local Notation monPred := (monPred I PROP).
434 435
Local Notation monPredI := (monPredI I PROP).
Local Notation monPred_at := (@monPred_at I PROP).
436
Local Notation BiIndexBottom := (@BiIndexBottom I).
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
437
Implicit Types i : I.
438
Implicit Types P Q : monPred.
439 440

(** Instances *)
441
Global Instance monPred_at_mono :
442
  Proper (() ==> () ==> ()) monPred_at.
443
Proof. by move=> ?? [?] ?? ->. Qed.
444
Global Instance monPred_at_flip_mono :
445
  Proper (flip () ==> flip () ==> flip ()) monPred_at.
446 447
Proof. solve_proper. Qed.

Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
448
Global Instance monPred_in_proper (R : relation I) :
449
  Proper (R ==> R ==> iff) ()  Reflexive R 
450
  Proper (R ==> ()) (@monPred_in I PROP).
451
Proof. unseal. split. solve_proper. Qed.
452
Global Instance monPred_in_mono : Proper (flip () ==> ()) (@monPred_in I PROP).
453
Proof. unseal. split. solve_proper. Qed.
454
Global Instance monPred_in_flip_mono : Proper (() ==> flip ()) (@monPred_in I PROP).
455 456
Proof. solve_proper. Qed.

457
Global Instance monPred_positive : BiPositive PROP  BiPositive monPredI.
458
Proof. split => ?. unseal. apply bi_positive. Qed.
459
Global Instance monPred_affine : BiAffine PROP  BiAffine monPredI.
460 461
Proof. split => ?. unseal. by apply affine. Qed.

462
Global Instance monPred_at_persistent P i : Persistent P  Persistent (P i).
463
Proof. move => [] /(_ i). by unseal. Qed.
464
Global Instance monPred_at_absorbing P i : Absorbing P  Absorbing (P i).
465
Proof. move => [] /(_ i). unfold Absorbing. by unseal. Qed.
466
Global Instance monPred_at_affine P i : Affine P  Affine (P i).
467
Proof. move => [] /(_ i). unfold Affine. by unseal. Qed.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
468

469 470
(* Note that monPred_in is *not* Plain, because it does depend on the
   index. *)
471 472
Global Instance monPred_in_persistent i :
  Persistent (@monPred_in I PROP i).
473
Proof. unfold Persistent. unseal; split => ?. by apply bi.pure_persistent. Qed.
474 475
Global Instance monPred_in_absorbing i :
  Absorbing (@monPred_in I PROP i).
476
Proof. unfold Absorbing. unseal. split=> ? /=. apply absorbing, _. Qed.
477

478
Definition monPred_embedding_mixin : BiEmbedMixin PROP monPredI monPred_embed.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
479 480
Proof.
  split; try apply _; unseal; try done.
481
  - move =>?? /= [/(_ inhabitant) ?] //.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
482 483 484 485 486
  - split=>? /=.
    by rewrite bi.forall_elim bi.pure_impl_forall bi.forall_elim.
  - split=>? /=.
    by rewrite bi.forall_elim bi.pure_impl_forall bi.forall_elim.
Qed.
487 488 489 490 491 492 493
Global Instance monPred_bi_embed : BiEmbed PROP monPredI :=
  {| bi_embed_mixin := monPred_embedding_mixin |}.

Lemma monPred_emp_unfold : emp%I = emp : PROP%I.
Proof. by unseal. Qed.
Lemma monPred_pure_unfold : bi_pure = λ φ,   φ  : PROP%I.
Proof. by unseal. Qed.
494
Lemma monPred_objectively_unfold : monPred_objectively = λ P,  i, P i%I.
495
Proof. by unseal. Qed.
496
Lemma monPred_subjectively_unfold : monPred_subjectively = λ P,  i, P i%I.
497
Proof. by unseal. Qed.
498

499 500 501
Global Instance monPred_objectively_ne : NonExpansive (@monPred_objectively I PROP).
Proof. rewrite monPred_objectively_unfold. solve_proper. Qed.
Global Instance monPred_objectively_proper : Proper (() ==> ()) (@monPred_objectively I PROP).
502
Proof. apply (ne_proper _). Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
503
Lemma monPred_objectively_mono P Q : (P  Q)  (<obj> P  <obj> Q).
504 505 506 507 508 509 510
Proof. rewrite monPred_objectively_unfold. solve_proper. Qed.
Global Instance monPred_objectively_mono' : Proper (() ==> ()) (@monPred_objectively I PROP).
Proof. intros ???. by apply monPred_objectively_mono. Qed.
Global Instance monPred_objectively_flip_mono' :
  Proper (flip () ==> flip ()) (@monPred_objectively I PROP).
Proof. intros ???. by apply monPred_objectively_mono. Qed.

Robbert Krebbers's avatar
Robbert Krebbers committed
511
Global Instance monPred_objectively_persistent P : Persistent P  Persistent (<obj> P).
512
Proof. rewrite monPred_objectively_unfold. apply _. Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
513
Global Instance monPred_objectively_absorbing P : Absorbing P  Absorbing (<obj> P).
514
Proof. rewrite monPred_objectively_unfold. apply _. Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
515
Global Instance monPred_objectively_affine P : Affine P  Affine (<obj> P).
516 517 518 519 520
Proof. rewrite monPred_objectively_unfold. apply _. Qed.

Global Instance monPred_subjectively_ne : NonExpansive (@monPred_subjectively I PROP).
Proof. rewrite monPred_subjectively_unfold. solve_proper. Qed.
Global Instance monPred_subjectively_proper : Proper (() ==> ()) (@monPred_subjectively I PROP).
521
Proof. apply (ne_proper _). Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
522
Lemma monPred_subjectively_mono P Q : (P  Q)  <subj> P  <subj> Q.
523 524 525 526 527 528 529
Proof. rewrite monPred_subjectively_unfold. solve_proper. Qed.
Global Instance monPred_subjectively_mono' : Proper (() ==> ()) (@monPred_subjectively I PROP).
Proof. intros ???. by apply monPred_subjectively_mono. Qed.
Global Instance monPred_subjectively_flip_mono' :
  Proper (flip () ==> flip ()) (@monPred_subjectively I PROP).
Proof. intros ???. by apply monPred_subjectively_mono. Qed.

Robbert Krebbers's avatar
Robbert Krebbers committed
530
Global Instance monPred_subjectively_persistent P : Persistent P  Persistent (<subj> P).
531
Proof. rewrite monPred_subjectively_unfold. apply _. Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
532
Global Instance monPred_subjectively_absorbing P : Absorbing P  Absorbing (<subj> P).
533
Proof. rewrite monPred_subjectively_unfold. apply _. Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
534
Global Instance monPred_subjectively_affine P : Affine P  Affine (<subj> P).
535
Proof. rewrite monPred_subjectively_unfold. apply _. Qed.
536

537 538 539 540
(** monPred_at unfolding laws *)
Lemma monPred_at_embed i (P : PROP) : monPred_at P i  P.
Proof. by unseal. Qed.
Lemma monPred_at_pure i (φ : Prop) : monPred_at ⌜φ⌝ i  ⌜φ⌝.
541
Proof. by unseal. Qed.
542
Lemma monPred_at_emp i : monPred_at emp i  emp.
543
Proof. by unseal. Qed.
544 545 546 547 548 549
Lemma monPred_at_and i P Q : (P  Q) i  P i  Q i.
Proof. by unseal. Qed.
Lemma monPred_at_or i P Q : (P  Q) i  P i  Q i.
Proof. by unseal. Qed.
Lemma monPred_at_impl i P Q : (P  Q) i   j, i  j  P j  Q j.
Proof. by unseal. Qed.
550
Lemma monPred_at_forall {A} i (Φ : A  monPred) : ( x, Φ x) i   x, Φ x i.
551
Proof. by unseal. Qed.
552
Lemma monPred_at_exist {A} i (Φ : A  monPred) : ( x, Φ x) i   x, Φ x i.
553 554 555 556 557
Proof. by unseal. Qed.
Lemma monPred_at_sep i P Q : (P  Q) i  P i  Q i.
Proof. by unseal. Qed.
Lemma monPred_at_wand i P Q : (P - Q) i   j, i  j  P j - Q j.
Proof. by unseal. Qed.
558
Lemma monPred_at_persistently i P : (<pers> P) i  <pers> (P i).
559 560 561
Proof. by unseal. Qed.
Lemma monPred_at_in i j : monPred_at (monPred_in j) i  j  i.
Proof. by unseal. Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
562
Lemma monPred_at_objectively i P : (<obj> P) i   j, P j.
563
Proof. by unseal. Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
564
Lemma monPred_at_subjectively i P : (<subj> P) i   j, P j.
565
Proof. by unseal. Qed.
566
Lemma monPred_at_persistently_if i p P : (<pers>?p P) i  <pers>?p (P i).
567
Proof. destruct p=>//=. apply monPred_at_persistently. Qed.
568
Lemma monPred_at_affinely i P : (<affine> P) i  <affine> (P i).
569
Proof. by rewrite /bi_affinely monPred_at_and monPred_at_emp. Qed.
570
Lemma monPred_at_affinely_if i p P : (<affine>?p P) i  <affine>?p (P i).
571
Proof. destruct p=>//=. apply monPred_at_affinely. Qed.
572
Lemma monPred_at_absorbingly i P : (<absorb> P) i  <absorb> (P i).
573 574 575 576 577 578 579
Proof. by rewrite /bi_absorbingly monPred_at_sep monPred_at_pure. Qed.

Lemma monPred_wand_force i P Q : (P - Q) i - (P i - Q i).
Proof. unseal. rewrite bi.forall_elim bi.pure_impl_forall bi.forall_elim //. Qed.
Lemma monPred_impl_force i P Q : (P  Q) i - (P i  Q i).
Proof. unseal. rewrite bi.forall_elim bi.pure_impl_forall bi.forall_elim //. Qed.

580
(* Laws for monPred_objectively and of Objective. *)
Robbert Krebbers's avatar
Robbert Krebbers committed
581
Lemma monPred_objectively_elim P : <obj> P  P.
582
Proof. rewrite monPred_objectively_unfold. unseal. split=>?. apply bi.forall_elim. Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
583
Lemma monPred_objectively_idemp P : <obj> <obj> P  <obj> P.
584
Proof.
585
  apply bi.equiv_spec; split; [by apply monPred_objectively_elim|].
586 587 588
  unseal. split=>i /=. by apply bi.forall_intro=>_.
Qed.

Robbert Krebbers's avatar
Robbert Krebbers committed
589
Lemma monPred_objectively_forall {A} (Φ : A  monPred) : <obj> ( x, Φ x)   x, <obj> (Φ x).
590 591 592 593
Proof.
  unseal. split=>i. apply bi.equiv_spec; split=>/=;
    do 2 apply bi.forall_intro=>?; by do 2 rewrite bi.forall_elim.
Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
594
Lemma monPred_objectively_and P Q : <obj> (P  Q)  <obj> P  <obj> Q.
595 596 597 598 599
Proof.
  unseal. split=>i. apply bi.equiv_spec; split=>/=.
  - apply bi.and_intro; do 2 f_equiv. apply bi.and_elim_l. apply bi.and_elim_r.
  - apply bi.forall_intro=>?. by rewrite !bi.forall_elim.
Qed.
600
Lemma monPred_objectively_exist {A} (Φ : A  monPred) :
Robbert Krebbers's avatar
Robbert Krebbers committed
601
  ( x, <obj> (Φ x))  <obj> ( x, (Φ x)).
602
Proof. apply bi.exist_elim=>?. f_equiv. apply bi.exist_intro. Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
603
Lemma monPred_objectively_or P Q : <obj> P  <obj> Q  <obj> (P  Q).
604 605
Proof. apply bi.or_elim; f_equiv. apply bi.or_intro_l. apply bi.or_intro_r. Qed.

Robbert Krebbers's avatar
Robbert Krebbers committed
606
Lemma monPred_objectively_sep_2 P Q : <obj> P  <obj> Q  <obj> (P  Q).
607
Proof. unseal. split=>i /=. apply bi.forall_intro=>?. by rewrite !bi.forall_elim. Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
608
Lemma monPred_objectively_sep `{BiIndexBottom bot} P Q : <obj> (P  Q)  <obj> P  <obj> Q.
609
Proof.
610
  apply bi.equiv_spec, conj, monPred_objectively_sep_2. unseal. split=>i /=.
611 612
  rewrite (bi.forall_elim bot). by f_equiv; apply bi.forall_intro=>j; f_equiv.
Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
613
Lemma monPred_objectively_embed (P : PROP) : <obj> P  P.
614 615 616 617
Proof.
  apply bi.equiv_spec; split; unseal; split=>i /=.
  by rewrite (bi.forall_elim inhabitant). by apply bi.forall_intro.
Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
618
Lemma monPred_objectively_emp : <obj> (emp : monPred)  emp.
619
Proof. rewrite monPred_emp_unfold. apply monPred_objectively_embed. Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
620
Lemma monPred_objectively_pure φ : <obj> ( φ  : monPred)   φ .
Robbert Krebbers's avatar