Skip to content

Commit 0a25f1f

Browse files
committed
add missing file factoring_upred.v
1 parent 583efac commit 0a25f1f

File tree

1 file changed

+341
-0
lines changed

1 file changed

+341
-0
lines changed
Lines changed: 341 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,341 @@
1+
From iris.prelude Require Import options.
2+
From iris.algebra Require Export cmra updates.
3+
From iris.algebra Require Import proofmode_classes functions.
4+
From iris.base_logic Require Import upred.
5+
From iris.base_logic.lib Require Export own iprop invariants wsat.
6+
From iris.proofmode Require Import base ltac_tactics tactics coq_tactics reduction.
7+
From iris.bi Require Import derived_laws.
8+
9+
Section FactoringUpred.
10+
11+
Context {Σ: gFunctors}.
12+
13+
(* Split-Own *)
14+
15+
Lemma uPred_ownM_separates_out x (P : iProp Σ)
16+
: (P -∗ uPred_ownM x) ∗ P ⊢ (
17+
(uPred_ownM x)
18+
19+
((uPred_ownM x) -∗ P)
20+
).
21+
Proof.
22+
uPred.unseal.
23+
split.
24+
intros n x0 val t.
25+
26+
unfold uPred_holds, upred.uPred_sep_def in t.
27+
destruct t as [x1 [x2 [sum [t1 t2]]]].
28+
29+
unfold uPred_holds, upred.uPred_wand_def in t1.
30+
31+
assert (✓{n} (x1 ⋅ x2)) as val_12. { setoid_rewrite <- sum. trivial. }
32+
assert (n ≤ n) as nle by trivial.
33+
have t11 := t1 n x2 nle val_12 t2.
34+
35+
unfold uPred_holds in t11. unfold upred.uPred_ownM_def in t11.
36+
unfold includedN in t11. destruct t11 as [z h].
37+
38+
unfold uPred_holds. unfold upred.uPred_sep_def.
39+
exists x. exists z.
40+
41+
assert (uPred_holds P n x0) as ux0. {
42+
eapply uPred_mono. { apply t2. }
43+
{ setoid_rewrite sum. unfold includedN. exists x1.
44+
rewrite cmra_comm. trivial. }
45+
trivial.
46+
}
47+
48+
split.
49+
{ setoid_rewrite sum. trivial. }
50+
split.
51+
{ unfold uPred_holds. unfold upred.uPred_ownM_def. trivial. }
52+
{ unfold uPred_holds. unfold upred.uPred_wand_def. intros n' x' incl val2 uh.
53+
unfold uPred_holds in uh.
54+
unfold upred.uPred_ownM_def in uh.
55+
unfold includedN in uh. destruct uh as [w j].
56+
setoid_rewrite j.
57+
apply uPred_mono with (n1 := n) (x1 := x0); trivial.
58+
assert (z ⋅ (x ⋅ w) ≡ (z ⋅ x) ⋅ w) as associ. { apply cmra_assoc. }
59+
setoid_rewrite associ.
60+
assert ((z ⋅ x) ≡ (x ⋅ z)) as commu. { apply cmra_comm. }
61+
setoid_rewrite commu.
62+
unfold includedN. exists w.
63+
apply dist_le with (n := n); trivial.
64+
setoid_rewrite sum.
65+
setoid_rewrite h.
66+
trivial.
67+
}
68+
Qed.
69+
70+
(* Split-Own-Except0 *)
71+
72+
Lemma uPred_ownM_separates_out_except0 x (P : iProp Σ)
73+
: (P -∗ ◇ uPred_ownM x) ∗ P ⊢ (
74+
(◇ uPred_ownM x)
75+
76+
(uPred_ownM x -∗ P)
77+
).
78+
Proof.
79+
unfold "◇". uPred.unseal.
80+
split.
81+
intros n x0 val t.
82+
83+
unfold uPred_holds, upred.uPred_sep_def in t.
84+
destruct t as [x1 [x2 [sum [t1 t2]]]].
85+
86+
unfold uPred_holds, upred.uPred_wand_def in t1.
87+
88+
assert (✓{n} (x1 ⋅ x2)) as val_12. { setoid_rewrite <- sum. trivial. }
89+
assert (n ≤ n) as nle by trivial.
90+
have t11 := t1 n x2 nle val_12 t2.
91+
92+
unfold uPred_holds in t11. unfold upred.uPred_or_def in t11.
93+
destruct t11 as [tlatfalse|t11].
94+
{
95+
unfold uPred_holds in tlatfalse. unfold upred.uPred_later_def in tlatfalse.
96+
unfold uPred_holds in tlatfalse. unfold upred.uPred_pure_def in tlatfalse.
97+
destruct n; try contradiction.
98+
unfold uPred_holds, upred.uPred_sep_def. exists ε, x0.
99+
split.
100+
{ rewrite ucmra_unit_left_id. trivial. }
101+
split.
102+
{ unfold uPred_holds, upred.uPred_or_def. left. unfold uPred_holds, upred.uPred_later_def. trivial. }
103+
unfold uPred_holds, upred.uPred_wand_def.
104+
intros n' x' le0 valxx uh.
105+
assert (n' = 0) by lia. subst n'.
106+
setoid_rewrite sum.
107+
eapply uPred_mono. { apply t2. }
108+
{ unfold includedN. exists (x1 ⋅ x').
109+
assert (x2 ⋅ (x1 ⋅ x') ≡ (x2 ⋅ x1 ⋅ x')) as J. { apply cmra_assoc. }
110+
setoid_rewrite J.
111+
assert (x1 ⋅ x2 ≡ x2 ⋅ x1) as K. { apply cmra_comm. }
112+
setoid_rewrite K.
113+
trivial.
114+
}
115+
lia.
116+
}
117+
118+
unfold uPred_holds in t11. unfold upred.uPred_ownM_def in t11.
119+
unfold includedN in t11. destruct t11 as [z h].
120+
121+
unfold uPred_holds. unfold upred.uPred_sep_def.
122+
exists x. exists z.
123+
124+
split.
125+
{ setoid_rewrite sum. trivial. }
126+
split.
127+
{ unfold uPred_holds, upred.uPred_or_def. right.
128+
unfold uPred_holds, upred.uPred_ownM_def. trivial. }
129+
{ unfold uPred_holds, upred.uPred_wand_def.
130+
intros n' x' incl val2 uh.
131+
unfold uPred_holds in uh.
132+
unfold upred.uPred_ownM_def in uh.
133+
unfold includedN in uh. destruct uh as [w j].
134+
setoid_rewrite j.
135+
136+
137+
assert (uPred_holds P n x0) as ux0. {
138+
eapply uPred_mono. { apply t2. }
139+
{ setoid_rewrite sum. unfold includedN. exists x1.
140+
rewrite cmra_comm. trivial. }
141+
trivial.
142+
}
143+
144+
apply uPred_mono with (n1 := n) (x1 := x0); trivial.
145+
assert (z ⋅ (x ⋅ w) ≡ (z ⋅ x) ⋅ w) as associ. { apply cmra_assoc. }
146+
setoid_rewrite associ.
147+
assert ((z ⋅ x) ≡ (x ⋅ z)) as commu. { apply cmra_comm. }
148+
setoid_rewrite commu.
149+
unfold includedN. exists w.
150+
apply dist_le with (n := n); trivial.
151+
setoid_rewrite sum.
152+
setoid_rewrite h.
153+
trivial.
154+
}
155+
Qed.
156+
157+
Local Lemma uPred_holds_later_m m (P : iProp Σ) n x
158+
: n < m -> (uPred_holds (▷^m P) n x).
159+
Proof.
160+
generalize n.
161+
induction m as [|m IHm].
162+
{ intros. lia. }
163+
{ intro n0. intro n0_lt_sm. assert ((▷^(S m) P)%I = (▷ ▷^m P)%I) as Heq by trivial.
164+
rewrite Heq. unfold "▷". uPred.unseal.
165+
unfold uPred_holds, upred.uPred_later_def.
166+
destruct n0; trivial. apply IHm. lia.
167+
}
168+
Qed.
169+
170+
Local Lemma uPred_holds_later_m2 m (P : iProp Σ) n x
171+
: n >= m -> (uPred_holds (▷^m P) n x <-> uPred_holds P (n - m) x).
172+
Proof.
173+
generalize n.
174+
induction m as [|m IHm].
175+
{ intro n0. replace (n0 - 0) with n0 by lia. trivial. }
176+
{ intro n0. intro n0_lt_sm. assert ((▷^(S m) P)%I = (▷ ▷^m P)%I) as Heq by trivial.
177+
rewrite Heq. split.
178+
{ unfold "▷". uPred.unseal.
179+
intro uh.
180+
unfold uPred_holds, upred.uPred_later_def in uh.
181+
destruct n0 as [|n0].
182+
{ lia. }
183+
{ replace (S n0 - S m) with (n0 - m) by lia.
184+
apply IHm. { lia. } trivial.
185+
}
186+
}
187+
{
188+
unfold "▷". uPred.unseal.
189+
intro uh.
190+
unfold uPred_holds, upred.uPred_later_def.
191+
destruct n0 as [|n0].
192+
{ lia. }
193+
{ replace (S n0 - S m) with (n0 - m) by lia.
194+
apply IHm. { lia. } trivial. }
195+
}
196+
}
197+
Qed.
198+
199+
Local Lemma uPred_holds_later_m3 m (P : iProp Σ) n x
200+
: uPred_holds (▷^m P) n x <-> (n < m \/ uPred_holds P (n - m) x).
201+
Proof.
202+
have h : Decision (n < m) by solve_decision. destruct h.
203+
{ intuition. { apply uPred_holds_later_m. trivial. }
204+
{ apply uPred_holds_later_m. trivial. }
205+
}
206+
{ intuition. { right. apply uPred_holds_later_m2. { lia. } trivial. }
207+
{ apply uPred_holds_later_m2. { lia. } trivial. }
208+
}
209+
Qed.
210+
211+
Lemma uPred_ownM_separates_out_except0_later x (P : iProp Σ) (m: nat)
212+
: (P -∗ ▷^m ◇ uPred_ownM x) ∗ P ⊢ (
213+
▷^m ((◇ uPred_ownM x) ∗ (uPred_ownM x -∗ P))).
214+
Proof.
215+
unfold "◇". uPred.unseal.
216+
split.
217+
intros n x0 val t.
218+
219+
unfold uPred_holds, upred.uPred_sep_def in t.
220+
destruct t as [x1 [x2 [sum [t1 t2]]]].
221+
222+
unfold uPred_holds, upred.uPred_wand_def in t1.
223+
224+
assert (✓{n} (x1 ⋅ x2)) as val_12. { setoid_rewrite <- sum. trivial. }
225+
assert (n ≤ n) as nle by trivial.
226+
have t11 := t1 n x2 nle val_12 t2.
227+
228+
rewrite uPred_holds_later_m3 in t11.
229+
230+
unfold uPred_holds in t11. unfold upred.uPred_or_def in t11.
231+
232+
have h : Decision (n < m) by solve_decision. destruct h.
233+
{
234+
rewrite uPred_holds_later_m3. left. trivial.
235+
}
236+
237+
(*unfold uPred_holds, upred.uPred_sep_def. exists ε, x0.
238+
split.
239+
{ rewrite ucmra_unit_left_id. trivial. }
240+
split.
241+
{ rewrite uPred_holds_later_m3. left. trivial. }
242+
unfold uPred_holds, upred.uPred_wand_def.
243+
intros n' x' n'_le_n valn' uh.
244+
245+
apply upred.uPred_mono with (n1 := n) (x1 := x2); trivial.
246+
unfold includedN. exists (x1 ⋅ x').
247+
apply dist_le with (n := n); trivial.
248+
setoid_rewrite sum.
249+
assert (x2 ⋅ (x1 ⋅ x') ≡ (x2 ⋅ x1 ⋅ x')) as J. { apply cmra_assoc. }
250+
setoid_rewrite J.
251+
252+
assert (x1 ⋅ x2 ≡ x2 ⋅ x1) as K. { apply cmra_comm. }
253+
setoid_rewrite K.
254+
trivial.
255+
}*)
256+
257+
destruct t11 as [n_lt_m|[tlatfalse|t11]].
258+
{ lia. }
259+
{
260+
unfold uPred_holds in tlatfalse. unfold upred.uPred_later_def in tlatfalse.
261+
unfold uPred_holds in tlatfalse. unfold upred.uPred_pure_def in tlatfalse.
262+
263+
have h : Decision (n = m) by solve_decision. destruct h.
264+
2: { assert (n - m > 0) as X by lia. destruct (n-m). { lia. } contradiction. }
265+
subst n.
266+
267+
rewrite uPred_holds_later_m3. right.
268+
269+
unfold uPred_holds, upred.uPred_sep_def. exists ε, x0.
270+
split.
271+
{ rewrite ucmra_unit_left_id. trivial. }
272+
split.
273+
{ unfold uPred_holds, upred.uPred_or_def. left. unfold uPred_holds, upred.uPred_later_def. trivial. }
274+
unfold uPred_holds, upred.uPred_wand_def.
275+
intros n' x' le_m valxx uh.
276+
apply uPred_mono with (n1 := m) (x1 := x0 ⋅ x'); trivial.
277+
{
278+
setoid_rewrite sum.
279+
eapply uPred_mono. { apply t2. }
280+
{ unfold includedN. exists (x1 ⋅ x').
281+
assert (x2 ⋅ (x1 ⋅ x') ≡ (x2 ⋅ x1 ⋅ x')) as J. { apply cmra_assoc. }
282+
setoid_rewrite J.
283+
assert (x1 ⋅ x2 ≡ x2 ⋅ x1) as K. { apply cmra_comm. }
284+
setoid_rewrite K.
285+
trivial.
286+
}
287+
lia.
288+
}
289+
lia.
290+
}
291+
292+
unfold uPred_holds in t11. unfold upred.uPred_ownM_def in t11.
293+
unfold includedN in t11. destruct t11 as [z h].
294+
295+
rewrite uPred_holds_later_m3. right.
296+
297+
unfold uPred_holds. unfold upred.uPred_sep_def.
298+
destruct (cmra_extend (n-m) (x1 ⋅ x2) x z) as (xe&ze&Hx'&Hy1&Hy2); trivial.
299+
{ apply cmra_validN_le with (n := n); trivial. lia. }
300+
301+
exists xe. exists ze.
302+
303+
split.
304+
{ setoid_rewrite <- Hx'.
305+
apply dist_le with (n := n); trivial. lia. }
306+
split.
307+
{ unfold uPred_holds, upred.uPred_or_def. right.
308+
unfold uPred_holds, upred.uPred_ownM_def.
309+
setoid_rewrite Hy1. trivial. }
310+
{ unfold uPred_holds, upred.uPred_wand_def.
311+
intros n' x' incl val2 uh.
312+
unfold uPred_holds in uh.
313+
unfold upred.uPred_ownM_def in uh.
314+
unfold includedN in uh. destruct uh as [w j].
315+
setoid_rewrite j.
316+
317+
assert (uPred_holds P n x0) as ux0. {
318+
eapply uPred_mono. { apply t2. }
319+
{ setoid_rewrite sum. unfold includedN. exists x1.
320+
rewrite cmra_comm. trivial. }
321+
trivial.
322+
}
323+
324+
apply uPred_mono with (n1 := n) (x1 := x0); trivial.
325+
{
326+
assert (ze ⋅ (x ⋅ w) ≡ (ze ⋅ x) ⋅ w) as associ. { apply cmra_assoc. }
327+
setoid_rewrite associ.
328+
assert ((ze ⋅ x) ≡ (x ⋅ ze)) as commu. { apply cmra_comm. }
329+
setoid_rewrite commu.
330+
unfold includedN. exists w.
331+
apply dist_le with (n := n - m); trivial.
332+
setoid_rewrite <- Hy1.
333+
setoid_rewrite <- Hx'.
334+
apply dist_le with (n := n); trivial.
335+
{ setoid_rewrite sum. trivial. }
336+
lia.
337+
} lia.
338+
}
339+
Qed.
340+
341+
End FactoringUpred.

0 commit comments

Comments
 (0)