monpred.v 46.2 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
      bi_index_rel : SqSubsetEq bi_index_type;
10
      bi_index_rel_preorder : PreOrder (@{bi_index_type}) }.
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 -d> 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 -d> 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 monPredO := OfeT monPred monPred_ofe_mixin.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
64

65
  Global Instance monPred_cofe `{Cofe PROP} : Cofe monPredO.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
66
  Proof.
67
    unshelve refine (iso_cofe_subtype (A:=I-d>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 -d> 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 monPredO _ _ : 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 }.
Tej Chajed's avatar
Tej Chajed committed
122
Hint Immediate monPred_in_entails : core.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
123

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
End Bi.

215 216
Arguments monPred_objectively {_ _} _%I.
Arguments monPred_subjectively {_ _} _%I.
Ralf Jung's avatar
Ralf Jung committed
217 218
Notation "'<obj>' P" := (monPred_objectively P) : bi_scope.
Notation "'<subj>' P" := (monPred_subjectively P) : bi_scope.
219

220 221 222 223 224 225
Section Sbi.
Context {I : biIndex} {PROP : sbi}.
Implicit Types i : I.
Notation monPred := (monPred I PROP).
Implicit Types P Q : monPred.

226 227
Definition monPred_internal_eq_def (A : ofeT) (a b : A) : monPred :=
  MonPred (λ _, a  b)%I _.
228
Definition monPred_internal_eq_aux : seal (@monPred_internal_eq_def). by eexists. Qed.
229
Definition monPred_internal_eq := monPred_internal_eq_aux.(unseal).
230 231
Definition monPred_internal_eq_eq : @monPred_internal_eq = _ :=
  monPred_internal_eq_aux.(seal_eq).
232

233
Program Definition monPred_later_def P : monPred := MonPred (λ i,  (P i))%I _.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
234
Next Obligation. solve_proper. Qed.
235
Definition monPred_later_aux : seal monPred_later_def. by eexists. Qed.
236 237
Definition monPred_later := monPred_later_aux.(unseal).
Definition monPred_later_eq : monPred_later = _ := monPred_later_aux.(seal_eq).
238
End Sbi.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
239

240
Module MonPred.
241 242
Definition unseal_eqs :=
  (@monPred_and_eq, @monPred_or_eq, @monPred_impl_eq,
243
   @monPred_forall_eq, @monPred_exist_eq, @monPred_sep_eq, @monPred_wand_eq,
244
   @monPred_persistently_eq, @monPred_later_eq, @monPred_internal_eq_eq, @monPred_in_eq,
245 246
   @monPred_embed_eq, @monPred_emp_eq, @monPred_pure_eq,
   @monPred_objectively_eq, @monPred_subjectively_eq).
247 248
Ltac unseal :=
  unfold bi_affinely, bi_absorbingly, sbi_except_0, bi_pure, bi_emp,
249
         monPred_upclosed, bi_and, bi_or,
250
         bi_impl, bi_forall, bi_exist, sbi_internal_eq, bi_sep, bi_wand,
Robbert Krebbers's avatar
Robbert Krebbers committed
251
         bi_persistently, bi_affinely, sbi_later;
252
  simpl;
253
  unfold sbi_emp, sbi_pure, sbi_and, sbi_or, sbi_impl, sbi_forall, sbi_exist,
Robbert Krebbers's avatar
Robbert Krebbers committed
254
         sbi_internal_eq, sbi_sep, sbi_wand, sbi_persistently;
Ralf Jung's avatar
Ralf Jung committed
255
  simpl;
256
  rewrite !unseal_eqs /=.
257 258
End MonPred.
Import MonPred.
259

Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
260
Section canonical_bi.
261
Context (I : biIndex) (PROP : bi).
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
262

263
Lemma monPred_bi_mixin : BiMixin (PROP:=monPred I PROP)
264
  monPred_entails monPred_emp monPred_pure monPred_and monPred_or
265
  monPred_impl monPred_forall monPred_exist monPred_sep monPred_wand
Robbert Krebbers's avatar
Robbert Krebbers committed
266
  monPred_persistently.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
267
Proof.
268
  split; try unseal; try by (split=> ? /=; repeat f_equiv).
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
269
  - split.
Robbert Krebbers's avatar
Robbert Krebbers committed
270 271
    + intros P. by split.
    + intros P Q R [H1] [H2]. split => ?. by rewrite H1 H2.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
272
  - split.
273 274
    + 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
275 276 277 278 279 280 281 282 283 284 285 286 287 288
  - 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 //.
289
    apply bi.impl_elim_l.
Robbert Krebbers's avatar
Robbert Krebbers committed
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305
  - 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.
306
  - split=> i. by apply bi.persistently_emp_intro.
Robbert Krebbers's avatar
Robbert Krebbers committed
307 308 309 310
  - 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.
311
Qed.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
312

Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
313
Canonical Structure monPredI : bi :=
Robbert Krebbers's avatar
Robbert Krebbers committed
314
  {| bi_ofe_mixin := monPred_ofe_mixin; bi_bi_mixin := monPred_bi_mixin |}.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
315 316 317
End canonical_bi.

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

Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
320
Lemma monPred_sbi_mixin :
Robbert Krebbers's avatar
Robbert Krebbers committed
321 322 323
  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
324
Proof.
Robbert Krebbers's avatar
Robbert Krebbers committed
325 326 327
  split; unseal.
  - intros n P Q HPQ. split=> i /=.
    apply bi.later_contractive. destruct n as [|n]=> //. by apply HPQ.
328 329 330 331 332 333 334 335
  - 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
336 337 338
  - 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.
339
  - intros P. split=> i /=. by apply bi.later_intro.
Robbert Krebbers's avatar
Robbert Krebbers committed
340 341 342 343 344 345 346 347
  - 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
348
Qed.
349

Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
350
Canonical Structure monPredSI : sbi :=
Robbert Krebbers's avatar
Robbert Krebbers committed
351 352
  {| sbi_ofe_mixin := monPred_ofe_mixin; sbi_bi_mixin := monPred_bi_mixin I PROP;
     sbi_sbi_mixin := monPred_sbi_mixin |}.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
353
End canonical_sbi.
354

355 356 357 358 359
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.
360
Instance: Params (@Objective) 2 := {}.
361

362 363
(** Primitive facts that cannot be deduced from the BI structure. *)

Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
364
Section bi_facts.
365
Context {I : biIndex} {PROP : bi}.
366
Local Notation monPred := (monPred I PROP).
367 368
Local Notation monPredI := (monPredI I PROP).
Local Notation monPred_at := (@monPred_at I PROP).
369
Local Notation BiIndexBottom := (@BiIndexBottom I).
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
370
Implicit Types i : I.
371
Implicit Types P Q : monPred.
372

373 374 375 376 377 378 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 420
(** monPred_at unfolding laws *)
Lemma monPred_at_pure i (φ : Prop) : monPred_at ⌜φ⌝ i  ⌜φ⌝.
Proof. by unseal. Qed.
Lemma monPred_at_emp i : monPred_at emp i  emp.
Proof. by unseal. Qed.
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.
Lemma monPred_at_forall {A} i (Φ : A  monPred) : ( x, Φ x) i   x, Φ x i.
Proof. by unseal. Qed.
Lemma monPred_at_exist {A} i (Φ : A  monPred) : ( x, Φ x) i   x, Φ x i.
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.
Lemma monPred_at_persistently i P : (<pers> P) i  <pers> (P i).
Proof. by unseal. Qed.
Lemma monPred_at_in i j : monPred_at (monPred_in j) i  j  i.
Proof. by unseal. Qed.
Lemma monPred_at_objectively i P : (<obj> P) i   j, P j.
Proof. by unseal. Qed.
Lemma monPred_at_subjectively i P : (<subj> P) i   j, P j.
Proof. by unseal. Qed.
Lemma monPred_at_persistently_if i p P : (<pers>?p P) i  <pers>?p (P i).
Proof. destruct p=>//=. apply monPred_at_persistently. Qed.
Lemma monPred_at_affinely i P : (<affine> P) i  <affine> (P i).
Proof. by rewrite /bi_affinely monPred_at_and monPred_at_emp. Qed.
Lemma monPred_at_affinely_if i p P : (<affine>?p P) i  <affine>?p (P i).
Proof. destruct p=>//=. apply monPred_at_affinely. Qed.
Lemma monPred_at_intuitionistically i P : ( P) i   (P i).
Proof. by rewrite /bi_intuitionistically monPred_at_affinely monPred_at_persistently. Qed.
Lemma monPred_at_intuitionistically_if i p P : (?p P) i  ?p (P i).
Proof. destruct p=>//=. apply monPred_at_intuitionistically. Qed.

Lemma monPred_at_absorbingly i P : (<absorb> P) i  <absorb> (P i).
Proof. by rewrite /bi_absorbingly monPred_at_sep monPred_at_pure. Qed.
Lemma monPred_at_absorbingly_if i p P : (<absorb>?p P) i  <absorb>?p (P i).
Proof. destruct p=>//=. apply monPred_at_absorbingly. 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.

421
(** Instances *)
422
Global Instance monPred_at_mono :
423
  Proper (() ==> () ==> ()) monPred_at.
424
Proof. by move=> ?? [?] ?? ->. Qed.
425
Global Instance monPred_at_flip_mono :
426
  Proper (flip () ==> flip () ==> flip ()) monPred_at.
427 428
Proof. solve_proper. Qed.

Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
429
Global Instance monPred_in_proper (R : relation I) :
430
  Proper (R ==> R ==> iff) ()  Reflexive R 
431
  Proper (R ==> ()) (@monPred_in I PROP).
432
Proof. unseal. split. solve_proper. Qed.
433
Global Instance monPred_in_mono : Proper (flip () ==> ()) (@monPred_in I PROP).
434
Proof. unseal. split. solve_proper. Qed.
435
Global Instance monPred_in_flip_mono : Proper (() ==> flip ()) (@monPred_in I PROP).
436 437
Proof. solve_proper. Qed.

438
Global Instance monPred_bi_positive : BiPositive PROP  BiPositive monPredI.
439
Proof. split => ?. unseal. apply bi_positive. Qed.
440
Global Instance monPred_bi_affine : BiAffine PROP  BiAffine monPredI.
441 442
Proof. split => ?. unseal. by apply affine. Qed.

443 444 445 446 447 448 449
Lemma monPred_persistent P : ( i, Persistent (P i))  Persistent P.
Proof. intros HP. constructor=> i. unseal. apply HP. Qed.
Lemma monPred_absorbing P : ( i, Absorbing (P i))  Absorbing P.
Proof. intros HP. constructor=> i. unseal. apply HP. Qed.
Lemma monPred_affine P : ( i, Affine (P i))  Affine P.
Proof. intros HP. constructor=> i. unseal. apply HP. Qed.

450
Global Instance monPred_at_persistent P i : Persistent P  Persistent (P i).
451
Proof. move => [] /(_ i). by unseal. Qed.
452
Global Instance monPred_at_absorbing P i : Absorbing P  Absorbing (P i).
453
Proof. move => [] /(_ i). unfold Absorbing. by unseal. Qed.
454
Global Instance monPred_at_affine P i : Affine P  Affine (P i).
455
Proof. move => [] /(_ i). unfold Affine. by unseal. Qed.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
456

457 458
(** Note that [monPred_in] is *not* [Plain], because it depends on the index. *)
Global Instance monPred_in_persistent i : Persistent (@monPred_in I PROP i).
459
Proof. apply monPred_persistent=> j. rewrite monPred_at_in. apply _. Qed.
460
Global Instance monPred_in_absorbing i : Absorbing (@monPred_in I PROP i).
461
Proof. apply monPred_absorbing=> j. rewrite monPred_at_in. apply _. Qed.
462

463
Definition monPred_embedding_mixin : BiEmbedMixin PROP monPredI monPred_embed.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
464
Proof.
Robbert Krebbers's avatar
Robbert Krebbers committed
465 466 467
  split; try apply _; rewrite /bi_emp_valid; unseal; try done.
  - move=> P /= [/(_ inhabitant) ?] //.
  - intros P Q. split=> i /=.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
468
    by rewrite bi.forall_elim bi.pure_impl_forall bi.forall_elim.
Robbert Krebbers's avatar
Robbert Krebbers committed
469
  - intros P Q. split=> i /=.
Jacques-Henri Jourdan's avatar
Jacques-Henri Jourdan committed
470 471
    by rewrite bi.forall_elim bi.pure_impl_forall bi.forall_elim.
Qed.
472 473
Global Instance monPred_bi_embed : BiEmbed PROP monPredI :=
  {| bi_embed_mixin := monPred_embedding_mixin |}.
Robbert Krebbers's avatar
Robbert Krebbers committed
474 475
Global Instance monPred_bi_embed_emp : BiEmbedEmp PROP monPredI.
Proof. split. by unseal. Qed.
476

477 478 479
Lemma monPred_at_embed i (P : PROP) : monPred_at P i  P.
Proof. by unseal. Qed.

480 481 482 483
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.
484
Lemma monPred_objectively_unfold : monPred_objectively = λ P,  i, P i%I.
485
Proof. by unseal. Qed.
486
Lemma monPred_subjectively_unfold : monPred_subjectively = λ P,  i, P i%I.
487
Proof. by unseal. Qed.
488

489 490 491
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).
492
Proof. apply (ne_proper _). Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
493
Lemma monPred_objectively_mono P Q : (P  Q)  (<obj> P  <obj> Q).
494 495 496 497 498 499 500
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
501
Global Instance monPred_objectively_persistent P : Persistent P  Persistent (<obj> P).
502
Proof. rewrite monPred_objectively_unfold. apply _. Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
503
Global Instance monPred_objectively_absorbing P : Absorbing P  Absorbing (<obj> P).
504
Proof. rewrite monPred_objectively_unfold. apply _. Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
505
Global Instance monPred_objectively_affine P : Affine P  Affine (<obj> P).
506 507 508 509 510
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).
511
Proof. apply (ne_proper _). Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
512
Lemma monPred_subjectively_mono P Q : (P  Q)  <subj> P  <subj> Q.
513 514 515 516 517 518 519
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
520
Global Instance monPred_subjectively_persistent P : Persistent P  Persistent (<subj> P).
521
Proof. rewrite monPred_subjectively_unfold. apply _. Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
522
Global Instance monPred_subjectively_absorbing P : Absorbing P  Absorbing (<subj> P).
523
Proof. rewrite monPred_subjectively_unfold. apply _. Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
524
Global Instance monPred_subjectively_affine P : Affine P  Affine (<subj> P).
525
Proof. rewrite monPred_subjectively_unfold. apply _. Qed.
526

527
(* Laws for monPred_objectively and of Objective. *)
Robbert Krebbers's avatar
Robbert Krebbers committed
528
Lemma monPred_objectively_elim P : <obj> P  P.
529
Proof. rewrite monPred_objectively_unfold. unseal. split=>?. apply bi.forall_elim. Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
530
Lemma monPred_objectively_idemp P : <obj> <obj> P  <obj> P.
531
Proof.
532
  apply bi.equiv_spec; split; [by apply monPred_objectively_elim|].
533 534 535
  unseal. split=>i /=. by apply bi.forall_intro=>_.
Qed.

Robbert Krebbers's avatar
Robbert Krebbers committed
536
Lemma monPred_objectively_forall {A} (Φ : A  monPred) : <obj> ( x, Φ x)   x, <obj> (Φ x).
537 538 539 540
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
541
Lemma monPred_objectively_and P Q : <obj> (P  Q)  <obj> P  <obj> Q.
542 543 544 545 546
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.
547
Lemma monPred_objectively_exist {A} (Φ : A  monPred) :
Robbert Krebbers's avatar
Robbert Krebbers committed
548
  ( x, <obj> (Φ x))  <obj> ( x, (Φ x)).
549
Proof. apply bi.exist_elim=>?. f_equiv. apply bi.exist_intro. Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
550
Lemma monPred_objectively_or P Q : <obj> P  <obj> Q  <obj> (P  Q).
551 552
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
553
Lemma monPred_objectively_sep_2 P Q : <obj> P  <obj> Q  <obj> (P  Q).
554
Proof. unseal. split=>i /=. apply bi.forall_intro=>?. by rewrite !bi.forall_elim. Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
555
Lemma monPred_objectively_sep `{BiIndexBottom bot} P Q : <obj> (P  Q)  <obj> P  <obj> Q.
556
Proof.
557
  apply bi.equiv_spec, conj, monPred_objectively_sep_2. unseal. split=>i /=.
558 559
  rewrite (bi.forall_elim bot). by f_equiv; apply bi.forall_intro=>j; f_equiv.
Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
560
Lemma monPred_objectively_embed (P : PROP) : <obj> P  P.
561 562 563 564
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
565
Lemma monPred_objectively_emp : <obj> (emp : monPred)  emp.
566
Proof. rewrite monPred_emp_unfold. apply monPred_objectively_embed. Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
567
Lemma monPred_objectively_pure φ : <obj> ( φ  : monPred)   φ .
568
Proof. rewrite monPred_pure_unfold. apply monPred_objectively_embed. Qed.
569

Robbert Krebbers's avatar
Robbert Krebbers committed
570
Lemma monPred_subjectively_intro P : P  <subj> P.
571
Proof. unseal. split=>?. apply bi.exist_intro. Qed.
572

573
Lemma monPred_subjectively_forall {A} (Φ : A  monPred) :
Robbert Krebbers's avatar
Robbert Krebbers committed
574
  (<subj> ( x, Φ x))   x, <subj> (Φ x).
575
Proof. apply bi.forall_intro=>?. f_equiv. apply bi.forall_elim. Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
576
Lemma monPred_subjectively_and P Q : <subj> (P  Q)  <subj> P  <subj> Q.
577
Proof. apply bi.and_intro; f_equiv. apply bi.and_elim_l. apply bi.and_elim_r. Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
578
Lemma monPred_subjectively_exist {A} (Φ : A  monPred) : <subj> ( x, Φ x)   x, <subj> (Φ x).
579 580 581 582
Proof.
  unseal. split=>i. apply bi.equiv_spec; split=>/=;
    do 2 apply bi.exist_elim=>?; by do 2 rewrite -bi.exist_intro.
Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
583
Lemma monPred_subjectively_or P Q : <subj> (P  Q)  <subj> P  <subj> Q.
584 585 586 587 588 589
Proof.
  unseal. split=>i. apply bi.equiv_spec; split=>/=.
  - apply bi.exist_elim=>?. by rewrite -!bi.exist_intro.
  - apply bi.or_elim; do 2 f_equiv. apply bi.or_intro_l. apply bi.or_intro_r.
Qed.

Robbert Krebbers's avatar
Robbert Krebbers committed
590
Lemma monPred_subjectively_sep P Q : <subj> (P  Q)  <subj> P  <subj> Q.
591 592
Proof. unseal. split=>i /=. apply bi.exist_elim=>?. by rewrite -!bi.exist_intro. Qed.

Robbert Krebbers's avatar
Robbert Krebbers committed
593
Lemma monPred_subjectively_idemp P : <subj> <subj> P  <subj> P.
594
Proof.
595
  apply bi.equiv_spec; split; [|by apply monPred_subjectively_intro].
596 597 598
  unseal. split=>i /=. by apply bi.exist_elim=>_.
Qed.

Robbert Krebbers's avatar
Robbert Krebbers committed
599
Lemma objective_objectively P `{!Objective P} : P  <obj> P.
600
Proof.
601 602
  rewrite monPred_objectively_unfold /= embed_forall. apply bi.forall_intro=>?.
  split=>?. unseal. apply objective_at, _.
603
Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
604
Lemma objective_subjectively P `{!Objective P} : <subj> P  P.
605
Proof.
606 607
  rewrite monPred_subjectively_unfold /= embed_exist. apply bi.exist_elim=>?.
  split=>?. unseal. apply objective_at, _.
608 609
Qed.

610
Global Instance embed_objective (P : PROP) : @Objective I PROP P.
611
Proof. intros ??. by unseal. Qed.
612
Global Instance pure_objective φ : @Objective I PROP ⌜φ⌝.
613
Proof. intros ??. by unseal. Qed.
614
Global Instance emp_objective : @Objective I PROP emp.
615
Proof. intros ??. by unseal. Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
616
Global Instance objectively_objective P : Objective (<obj> P).
617
Proof. intros ??. by unseal. Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
618
Global Instance subjectively_objective P : Objective (<subj> P).
619
Proof. intros ??. by unseal. Qed.
620

621 622 623 624 625
Global Instance and_objective P Q `{!Objective P, !Objective Q} : Objective (P  Q).
Proof. intros i j. unseal. by rewrite !(objective_at _ i j). Qed.
Global Instance or_objective P Q `{!Objective P, !Objective Q} : Objective (P  Q).
Proof. intros i j. by rewrite !monPred_at_or !(objective_at _ i j). Qed.
Global Instance impl_objective P Q `{!Objective P, !Objective Q} : Objective (P  Q).
626
Proof.
627 628
  intros i j. unseal. rewrite (bi.forall_elim i) bi.pure_impl_forall.
  rewrite bi.forall_elim //. apply bi.forall_intro=> k.
629
  rewrite bi.pure_impl_forall. apply bi.forall_intro=>_.
630
  rewrite (objective_at Q i). by rewrite (objective_at P k).
631
Qed.
632 633 634 635 636 637
Global Instance forall_objective {A} Φ {H :  x : A, Objective (Φ x)} :
  @Objective I PROP ( x, Φ x)%I.
Proof. intros i j. unseal. do 2 f_equiv. by apply objective_at. Qed.
Global Instance exists_objective {A} Φ {H :  x : A, Objective (Φ x)} :
  @Objective I PROP ( x, Φ x)%I.
Proof. intros i j. unseal. do 2 f_equiv. by apply objective_at. Qed.
638

639 640 641
Global Instance sep_objective P Q `{!Objective P, !Objective Q} : Objective (P  Q).
Proof. intros i j. unseal. by rewrite !(objective_at _ i j). Qed.
Global Instance wand_objective P Q `{!Objective P, !Objective Q} : Objective (P - Q).
642
Proof.
643 644
  intros i j. unseal. rewrite (bi.forall_elim i) bi.pure_impl_forall.
  rewrite bi.forall_elim //. apply bi.forall_intro=> k.
645
  rewrite bi.pure_impl_forall. apply bi.forall_intro=>_.
646
  rewrite (objective_at Q i). by rewrite (objective_at P k).
647
Qed.
648
Global Instance persistently_objective P `{!Objective P} : Objective (<pers> P).
649
Proof. intros i j. unseal. by rewrite objective_at. Qed.
650

651
Global Instance affinely_objective P `{!Objective P} : Objective (<affine> P).
652
Proof. rewrite /bi_affinely. apply _. Qed.
653 654
Global Instance intuitionistically_objective P `{!Objective P} : Objective ( P).
Proof. rewrite /bi_intuitionistically. apply _. Qed.
655
Global Instance absorbingly_objective P `{!Objective P} : Objective (<absorb> P).
656
Proof. rewrite /bi_absorbingly. apply _. Qed.
657
Global Instance persistently_if_objective P p `{!Objective P} : Objective (<pers>?p P).
658
Proof. rewrite /bi_persistently_if. destruct p; apply _. Qed.
659
Global Instance affinely_if_objective P p `{!Objective P} : Objective (<affine>?p P).
660
Proof. rewrite /bi_affinely_if. destruct p; apply _. Qed.
661 662
Global Instance absorbingly_if_objective P p `{!Objective P} : Objective (<absorb>?p P).
Proof. rewrite /bi_absorbingly_if. destruct p; apply _. Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
663
Global Instance intuitionistically_if_objective P p `{!Objective P} : Objective (?p P).
664
Proof. rewrite /bi_intuitionistically_if. destruct p; apply _. Qed.
665 666

(** monPred_in *)
667 668 669 670 671
Lemma monPred_in_intro P : P   i, monPred_in i  P i.
Proof.
  unseal. split=>i /=.
  rewrite /= -(bi.exist_intro i). apply bi.and_intro=>//. by apply bi.pure_intro.
Qed.
672
Lemma monPred_in_elim P i : monPred_in i - P i  P .
673
Proof.
674
  apply bi.impl_intro_r. unseal. split=>i' /=.
675 676
  eapply bi.pure_elim; [apply bi.and_elim_l|]=>?. rewrite bi.and_elim_r. by f_equiv.
Qed.
677

678 679 680 681
(** Big op *)
Global Instance monPred_at_monoid_and_homomorphism i :
  MonoidHomomorphism bi_and bi_and () (flip monPred_at i).
Proof. split; [split|]; try apply _. apply monPred_at_and. apply monPred_at_pure. Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
682
Global Instance monPred_at_monoid_or_homomorphism i :
683 684
  MonoidHomomorphism bi_or bi_or () (flip monPred_at i).
Proof. split; [split|]; try apply _. apply monPred_at_or. apply monPred_at_pure. Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
685
Global Instance monPred_at_monoid_sep_homomorphism i :
686 687 688
  MonoidHomomorphism bi_sep bi_sep () (flip monPred_at i).
Proof. split; [split|]; try apply _. apply monPred_at_sep. apply monPred_at_emp. Qed.

689
Lemma monPred_at_big_sepL {A} i (Φ :