File: proofmode_monpred.v

package info (click to toggle)
coq-iris 4.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,116 kB
  • sloc: python: 130; makefile: 61; sh: 28; sed: 2
file content (228 lines) | stat: -rw-r--r-- 7,935 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
From iris.bi.lib Require Import fractional.
From iris.proofmode Require Import tactics monpred.
From iris.base_logic.lib Require Import invariants ghost_var.
From iris.prelude Require Import options.

Unset Mangle Names.

Section tests.
  Context {I : biIndex} {PROP : bi}.
  Local Notation monPred := (monPred I PROP).
  Local Notation monPredI := (monPredI I PROP).
  Implicit Types P Q R : monPred.
  Implicit Types π“Ÿ 𝓠 𝓑 : PROP.
  Implicit Types i j : I.

  Lemma test0 P : P -βˆ— P.
  Proof. iIntros "$". Qed.

  Lemma test_iStartProof_1 P : P -βˆ— P.
  Proof. iStartProof. iStartProof. iIntros "$". Qed.
  Lemma test_iStartProof_2 P : P -βˆ— P.
  Proof. iStartProof monPred. iStartProof monPredI. iIntros "$". Qed.
  Lemma test_iStartProof_3 P : P -βˆ— P.
  Proof. iStartProof monPredI. iStartProof monPredI. iIntros "$". Qed.
  Lemma test_iStartProof_4 P : P -βˆ— P.
  Proof. iStartProof monPredI. iStartProof monPred. iIntros "$". Qed.
  Lemma test_iStartProof_5 P : P -βˆ— P.
  Proof. iStartProof PROP. iIntros (i) "$". Qed.
  Lemma test_iStartProof_6 P : P ⊣⊒ P.
  Proof. iStartProof PROP. iIntros (i). iSplit; iIntros "$". Qed.
  Lemma test_iStartProof_7 `{!BiInternalEq PROP} P : ⊒@{monPredI} P ≑ P.
  Proof. iStartProof PROP. done. Qed.

  Lemma test_intowand_1 P Q : (P -βˆ— Q) -βˆ— P -βˆ— Q.
  Proof.
    iStartProof PROP. iIntros (i) "HW". Show.
    iIntros (j ->) "HP". Show. by iApply "HW".
  Qed.
  Lemma test_intowand_2 P Q : (P -βˆ— Q) -βˆ— P -βˆ— Q.
  Proof.
    iStartProof PROP. iIntros (i) "HW". iIntros (j ->) "HP".
    iSpecialize ("HW" with "[HP //]"). done.
  Qed.
  Lemma test_intowand_3 P Q : (P -βˆ— Q) -βˆ— P -βˆ— Q.
  Proof.
    iStartProof PROP. iIntros (i) "HW". iIntros (j ->) "HP".
    iSpecialize ("HW" with "HP"). done.
  Qed.
  Lemma test_intowand_4 P Q : (P -βˆ— Q) -βˆ— β–· P -βˆ— β–· Q.
  Proof.
    iStartProof PROP. iIntros (i) "HW". iIntros (j ->) "HP". by iApply "HW".
  Qed.
  Lemma test_intowand_5 P Q : (P -βˆ— Q) -βˆ— β–· P -βˆ— β–· Q.
  Proof.
    iStartProof PROP. iIntros (i) "HW". iIntros (j ->) "HP".
    iSpecialize ("HW" with "HP"). done.
  Qed.

  Lemma test_apply_in_elim (P : monPredI) (i : I) : monPred_in i -βˆ— ⎑ P i ⎀ β†’ P.
  Proof. iIntros. by iApply monPred_in_elim. Qed.

  Lemma test_iStartProof_forall_1 (Ξ¦ : nat β†’ monPredI) : βˆ€ n, Ξ¦ n -βˆ— Ξ¦ n.
  Proof.
    iStartProof PROP. iIntros (n i) "$".
  Qed.
  Lemma test_iStartProof_forall_2 (Ξ¦ : nat β†’ monPredI) : βˆ€ n, Ξ¦ n -βˆ— Ξ¦ n.
  Proof.
    iStartProof. iIntros (n) "$".
  Qed.

  Lemma test_embed_wand (P Q : PROP) : (⎑P⎀ -βˆ— ⎑Q⎀) ⊒@{monPredI} ⎑P -βˆ— Q⎀.
  Proof.
    iIntros "H HP". by iApply "H".
  Qed.

  Lemma test_objectively `{!BiPersistentlyForall PROP} P Q :
    <obj> emp -βˆ— <obj> P -βˆ— <obj> Q -βˆ— <obj> (P βˆ— Q).
  Proof. iIntros "#? HP HQ". iModIntro. by iSplitL "HP". Qed.

  Lemma test_objectively_absorbing `{!BiPersistentlyForall PROP} P Q R `{!Absorbing P} :
    <obj> emp -βˆ— <obj> P -βˆ— <obj> Q -βˆ— R -βˆ— <obj> (P βˆ— Q).
  Proof. iIntros "#? HP HQ HR". iModIntro. by iSplitL "HP". Qed.

  Lemma test_objectively_affine `{!BiPersistentlyForall PROP} P Q R `{!Affine R} :
    <obj> emp -βˆ— <obj> P -βˆ— <obj> Q -βˆ— R -βˆ— <obj> (P βˆ— Q).
  Proof. iIntros "#? HP HQ HR". iModIntro. by iSplitL "HP". Qed.

  Lemma test_iModIntro_embed P `{!Affine Q} π“Ÿ 𝓠 :
    β–‘ P -βˆ— Q -βˆ— βŽ‘π“ŸβŽ€ -βˆ— βŽ‘π“ βŽ€ -βˆ— ⎑ π“Ÿ βˆ— 𝓠 ⎀.
  Proof. iIntros "#H1 _ H2 H3". iModIntro. iFrame. Qed.

  Lemma test_iModIntro_embed_objective P `{!Objective Q} π“Ÿ 𝓠 :
    β–‘ P -βˆ— Q -βˆ— βŽ‘π“ŸβŽ€ -βˆ— βŽ‘π“ βŽ€ -βˆ— ⎑ βˆ€ i, π“Ÿ βˆ— 𝓠 βˆ— Q i ⎀.
  Proof. iIntros "#H1 H2 H3 H4". iModIntro. Show. iFrame. Qed.

  Lemma test_iModIntro_embed_nested P π“Ÿ 𝓠 :
    β–‘ P -βˆ— βŽ‘β—‡ π“ŸβŽ€ -βˆ— βŽ‘β—‡ π“ βŽ€ -βˆ— ⎑ β—‡ (π“Ÿ βˆ— 𝓠) ⎀.
  Proof. iIntros "#H1 H2 H3". iModIntro ⎑ _ ⎀%I. by iSplitL "H2". Qed.

  Lemma test_into_wand_embed π“Ÿ 𝓠 :
    (π“Ÿ -βˆ— β—‡ 𝓠) β†’
    βŽ‘π“ŸβŽ€ ⊒@{monPredI} β—‡ βŽ‘π“ βŽ€.
  Proof.
    iIntros (HPQ) "HP".
    iMod (HPQ with "[-]") as "$"; last by auto.
    iAssumption.
  Qed.

  Lemma test_monPred_at_and_pure P i j :
    (monPred_in j ∧ P) i ⊒ ⌜ j βŠ‘ i ⌝ ∧ P i.
  Proof.
    iDestruct 1 as "[% $]". done.
  Qed.
  Lemma test_monPred_at_sep_pure P i j :
    (monPred_in j βˆ— <absorb> P) i ⊒ ⌜ j βŠ‘ i ⌝ ∧ <absorb> P i.
  Proof.
    iDestruct 1 as "[% ?]". auto.
  Qed.

  Context (FU : BiFUpd PROP).

  Lemma test_apply_fupd_intro_mask_subseteq E1 E2 P :
    E2 βŠ† E1 β†’ P -βˆ— |={E1,E2}=> |={E2,E1}=> P.
  Proof. iIntros. by iApply @fupd_mask_intro_subseteq. Qed.
  Lemma test_apply_fupd_mask_subseteq E1 E2 P :
    E2 βŠ† E1 β†’ P -βˆ— |={E1,E2}=> |={E2,E1}=> P.
  Proof. iIntros. iFrame. by iApply @fupd_mask_subseteq. Qed.

  Lemma test_iFrame_embed_persistent (P : PROP) (Q: monPred) :
    Q βˆ— β–‘ ⎑P⎀ ⊒ Q βˆ— ⎑P βˆ— P⎀.
  Proof.
    iIntros "[$ #HP]". iFrame "HP".
  Qed.

  Lemma test_iNext_Bi P :
    β–· P ⊒@{monPredI} β–· P.
  Proof. iIntros "H". by iNext. Qed.

  (** Test monPred_at framing *)
  Lemma test_iFrame_monPred_at_wand (P Q : monPred) i :
    P i -βˆ— (Q -βˆ— P) i.
  Proof. iIntros "$". Show. Abort.

  Program Definition monPred_id (R : monPred) : monPred :=
    MonPred (Ξ» V, R V) _.
  Next Obligation. intros ? ???. eauto. Qed.

  Lemma test_iFrame_monPred_id (Q R : monPred) i :
    Q i βˆ— R i -βˆ— (Q βˆ— monPred_id R) i.
  Proof.
    iIntros "(HQ & HR)". iFrame "HR". iAssumption.
  Qed.

  Lemma test_iFrame_rel P i j ij :
    IsBiIndexRel i ij β†’ IsBiIndexRel j ij β†’
    P i -βˆ— P j -βˆ— P ij βˆ— P ij.
  Proof. iIntros (??) "HPi HPj". iFrame. Qed.

  Lemma test_iFrame_later_rel `{!BiAffine PROP} P i j :
    IsBiIndexRel i j β†’
    β–· (P i) -βˆ— (β–· P) j.
  Proof. iIntros (?) "?". iFrame. Qed.

  Lemma test_iFrame_laterN n P i :
    β–·^n (P i) -βˆ— (β–·^n P) i.
  Proof. iIntros "?". iFrame. Qed.

  Lemma test_iFrame_quantifiers P i :
    P i -βˆ— (βˆ€ _:(), βˆƒ _:(), P) i.
  Proof. iIntros "?". iFrame. Show. iIntros ([]). iExists (). iEmpIntro. Qed.

  Lemma test_iFrame_embed (P : PROP) i :
    P -βˆ— (embed (B:=monPredI) P) i.
  Proof. iIntros "$". Qed.

  (* Make sure search doesn't diverge on an evar *)
  Lemma test_iFrame_monPred_at_evar (P : monPred) i j :
    P i -βˆ— βˆƒ Q, (Q j).
  Proof. iIntros "HP". iExists _. Fail iFrame "HP". Abort.

End tests.

Section tests_iprop.
  Context {I : biIndex} `{!invGS_gen hlc Ξ£}.

  Local Notation monPred := (monPred I (iPropI Ξ£)).
  Local Notation monPredI := (monPredI I (iPropI Ξ£)).
  Implicit Types P Q R : monPred.
  Implicit Types π“Ÿ 𝓠 𝓑 : iProp Ξ£.

  Lemma test_iInv_0 N π“Ÿ :
    embed (B:=monPred) (inv N (<pers> π“Ÿ)) ={⊀}=βˆ— βŽ‘β–· π“ŸβŽ€.
  Proof.
    iIntros "#H".
    iInv N as "#H2". Show.
    iModIntro. iSplit=>//. iModIntro. iModIntro; auto.
  Qed.

  Lemma test_iInv_0_with_close N π“Ÿ :
    embed (B:=monPred) (inv N (<pers> π“Ÿ)) ={⊀}=βˆ— βŽ‘β–· π“ŸβŽ€.
  Proof.
    iIntros "#H".
    iInv N as "#H2" "Hclose". Show.
    iMod ("Hclose" with "H2").
    iModIntro. iModIntro. by iNext.
  Qed.

  Lemma test_iPoseProof `{inG Ξ£ A} P Ξ³ (x y : A) :
    x ~~> y β†’ P βˆ— ⎑own Ξ³ x⎀ ==βˆ— ⎑own Ξ³ y⎀.
  Proof.
    iIntros (?) "[_ HΞ³]".
    iPoseProof (own_update with "HΞ³") as "H"; first done.
    by iMod "H".
  Qed.

  Lemma test_embed_fractional `{!ghost_varG Ξ£ A} Ξ³ q (a : A) :
    ⎑ghost_var Ξ³ q a⎀ ⊒@{monPredI} ⎑ghost_var Ξ³ (q/2) a⎀ βˆ— ⎑ghost_var Ξ³ (q/2) a⎀.
  Proof. iIntros "[$ $]". Qed.

  Lemma test_embed_combine `{!ghost_varG Ξ£ A} Ξ³ q (a1 a2 : A) :
    β–· ⎑ghost_var Ξ³ (q/2) a1⎀ βˆ— β–· ⎑ghost_var Ξ³ (q/2) a2⎀ ⊒@{monPredI}
            β–·βŽ‘ghost_var Ξ³ q a1⎀ βˆ— β–· ⌜a1 = a2⌝.
  Proof.
    iIntros "[H1 H2]".
    iCombine "H1 H2" as "$" gives "#H". iNext.
    by iDestruct "H" as %[_ ->].
  Qed.
End tests_iprop.