@@ -96,10 +96,13 @@ Lemma tp_external_steps_many_L {a} {rs : sReifier a} `{!Cofe A}
9696 tp_external_steps rs α1 σ1 α3 σ3 (S n2).
9797Proof .
9898 intros G H; revert G.
99- induction H as [| ????????? IH]; intros G.
99+ induction H as [| ??????????? IH]; intros G.
100100 - setoid_subst.
101- econstructor; last constructor; first apply G; done.
102- - by econstructor; last by apply IH; done.
101+ econstructor 2; [| eassumption |]; last constructor 1; [| eassumption | |].
102+ + lia.
103+ + done.
104+ + done.
105+ - econstructor 2; [| eassumption |]; last by apply IH. lia.
103106Qed .
104107
105108Lemma tp_internal_steps_many_L {a} {rs : sReifier a} `{!Cofe A}
@@ -117,16 +120,34 @@ Proof.
117120 iDestruct "H" as "(H1 & H2)".
118121 iRewrite "H1". iRewrite "H2".
119122 rewrite tp_internal_steps_S.
123+ iLeft.
120124 iExists α3, σ3.
121125 iSplit; first done.
122126 by rewrite tp_internal_steps_0.
123127 - iIntros "G H".
124128 iEval (rewrite tp_internal_steps_S) in "H".
125- iDestruct "H" as "(%γ & %σ' & H1 & H2)".
126- iPoseProof ("IH" $! γ σ' α2 σ2 α3 σ3 with "G H2") as "J".
127- iEval (rewrite tp_internal_steps_S).
128- iExists γ, σ'.
129- by iSplit.
129+ iDestruct "H" as "[H | H]".
130+ {
131+ iDestruct "H" as "(%γ & %σ' & H1 & H2)".
132+ iPoseProof ("IH" $! γ σ' α2 σ2 α3 σ3 with "G H2") as "J".
133+ iEval (rewrite tp_internal_steps_S).
134+ iLeft.
135+ iExists γ, σ'.
136+ by iSplit.
137+ }
138+ {
139+ iDestruct "H" as "(H1 & H2)".
140+ iRewrite "H1". iRewrite "H2".
141+ rewrite tp_internal_steps_unfold.
142+ iRight.
143+ iExists 0, α3, σ3.
144+ iSplit; first by (iPureIntro; lia).
145+ iFrame "G".
146+ rewrite tp_internal_steps_unfold.
147+ iLeft.
148+ iSplit; first by (iPureIntro; lia).
149+ done.
150+ }
130151Qed .
131152
132153Lemma IT_tau_err_ne' `{Cofe R} {F} α e :
@@ -266,10 +287,19 @@ Proof.
266287 done.
267288 - iIntros "G H".
268289 iEval (rewrite tp_internal_steps_S) in "G".
269- iDestruct "G" as "(%γ & %σ' & G1 & G2)".
270- rewrite Nat.add_succ_l -Nat.add_succ_r.
271- iDestruct (tp_internal_steps_many_L with "G1 H") as "K".
272- iApply ("IH" with "G2 K").
290+ iDestruct "G" as "[G | G]".
291+ {
292+ iDestruct "G" as "(%γ & %σ' & G1 & G2)".
293+ rewrite Nat.add_succ_l -Nat.add_succ_r.
294+ iDestruct (tp_internal_steps_many_L with "G1 H") as "K".
295+ iApply ("IH" with "G2 K").
296+ }
297+ {
298+ iDestruct "G" as "(H1 & H2)".
299+ iRewrite - "H1". iRewrite - "H2".
300+ iApply (tp_internal_steps_grow with "H").
301+ lia.
302+ }
273303Qed .
274304
275305Lemma tp_internal_steps_trans'
@@ -290,10 +320,19 @@ Proof.
290320 done.
291321 - iIntros "G H".
292322 iEval (rewrite tp_internal_steps_S) in "G".
293- iDestruct "G" as "(%γ & %σ' & G1 & G2)".
294- rewrite Nat.add_succ_l -Nat.add_succ_r.
295- iDestruct (tp_internal_steps_many_L with "G1 H") as "K".
296- iApply ("IH" with "G2 K").
323+ iDestruct "G" as "[G | G]".
324+ {
325+ iDestruct "G" as "(%γ & %σ' & G1 & G2)".
326+ rewrite Nat.add_succ_l -Nat.add_succ_r.
327+ iDestruct (tp_internal_steps_many_L with "G1 H") as "K".
328+ iApply ("IH" with "G2 K").
329+ }
330+ {
331+ iDestruct "G" as "(H1 & H2)".
332+ iRewrite - "H1". iRewrite - "H2".
333+ iApply (tp_internal_steps_grow with "H").
334+ lia.
335+ }
297336Qed .
298337
299338Class monoSG Σ := MONOSG { mono_inG :: mono_natG Σ; mono_name : gname }.
@@ -624,7 +663,19 @@ Section right_hand_side.
624663 - done.
625664 - apply map_Forall_lookup_2.
626665 intros i x H.
627- admit.
666+ clear -H.
667+ revert H.
668+ generalize (length σ).
669+ clear.
670+ induction α as [| ? ? IH]; intros l H.
671+ + inversion H.
672+ + simpl in H.
673+ destruct (decide (l = i)); first subst.
674+ * rewrite lookup_insert in H.
675+ inversion H; subst.
676+ done.
677+ * rewrite lookup_insert_ne in H; last done.
678+ by eapply IH.
628679 }
629680 rewrite map_union_comm; last apply (HD 0).
630681 iModIntro.
@@ -655,7 +706,7 @@ Section right_hand_side.
655706 -- intros.
656707 rewrite /= lookup_insert_ne; last lia.
657708 apply IH; lia.
658- Admitted .
709+ Qed .
659710
660711 Lemma tpool_loc_dom l α tp :
661712 own (tpool_name rs R) (to_tpool rs R tp)
@@ -675,12 +726,8 @@ Section right_hand_side.
675726 Proof .
676727 iIntros "H Hl".
677728 iMod (own_update_2 with "H Hl") as "[$ $]"; last done.
678- apply gmap_view_update.
679- intros.
680- split.
681- - admit.
682- - admit.
683- Admitted .
729+ by apply gmap_view_replace.
730+ Qed .
684731
685732 Lemma step_tick E j e :
686733 nclose specN ⊆ E →
@@ -1185,29 +1232,9 @@ Lemma logrel_adequacy_internal Σ cr n
11851232 (IT_of_V αv :: βs) st' k').
11861233Proof .
11871234 intros rg F IT' ITV' Hsteps Hprf.
1188- unshelve eapply (step_fupdN_soundness_lc _ (S (weakestpre.steps_sum id 0 k))
1235+ apply (step_fupdN_soundness_lc _ (S (weakestpre.steps_sum id 0 k))
11891236 ((weakestpre.steps_sum id 0 k) + (S cr))).
1190- {
1191- (* TODO: plain instance for fixpoints *)
1192- apply exist_plain. intros x1.
1193- apply exist_plain. intros x2.
1194- apply exist_plain. intros x3.
1195- apply exist_plain. intros x4.
1196- cut (∀ n α σ β σ', Plain (tp_internal_steps (Σ := Σ) (A := A)
1197- (gReifiers_sReifier rs) α σ β σ' n)).
1198- { intros H; apply H. }
1199- clear x1 x2 x3 x4.
1200- intros x5.
1201- induction x5 as [| ? IH]; intros x1 x2 x3 x4.
1202- - rewrite tp_internal_steps_0.
1203- apply _.
1204- - rewrite tp_internal_steps_S.
1205- apply exist_plain. intros y1.
1206- apply exist_plain. intros y2.
1207- apply and_plain.
1208- + apply _.
1209- + apply IH.
1210- }
1237+
12111238 iIntros (H1) "(_HCred' & (_HCred & _HCred''))".
12121239 iMod (new_state_interp σ) as (H2) "[Hs Hs2]".
12131240 assert (G1 : (nat → ∀ σ, state_interp σ
@@ -1315,12 +1342,12 @@ Proof.
13151342 iDestruct (option_equivI with "K") as "K".
13161343 destruct v'.
13171344 + iSimpl in "K".
1318- iDestruct (ret_discrete_pure' (gReifiers_sReifier rs) o o0 with "K") as (β') "%J".
1345+ iDestruct (ret_discrete_pure (gReifiers_sReifier rs) o o0 with "K") as (β') "%J".
13191346 iExists (core.RetV β'), tp'.
13201347 iPureIntro. simpl.
13211348 by rewrite J.
13221349 + iSimpl in "K".
1323- iDestruct (fun_discrete_pure' (gReifiers_sReifier rs) o o0 with "K") as (β') "%J".
1350+ iDestruct (fun_discrete_pure (gReifiers_sReifier rs) o o0 with "K") as (β') "%J".
13241351 iExists (core.FunV β'), tp'.
13251352 iPureIntro. simpl.
13261353 by rewrite J.
@@ -1347,7 +1374,98 @@ Proof.
13471374 iFrame "J3'".
13481375Qed .
13491376
1350- Lemma logrel_adequacy `{Classical} Σ cr n
1377+ Lemma internal_steps_bounding_fun_witness (AC : Choice) Σ {a} (rs : sReifier a)
1378+ {A} `{!Cofe A} (α : list (IT _ A)) σ :
1379+ (⊢@{iProp Σ} (∃ αv βs σ' k, tp_internal_steps rs α σ (IT_of_V αv :: βs) σ' k))
1380+ → ∃ f : nat → nat,
1381+ ∀ k, uPred_holds
1382+ (∃ αv βs σ', tp_internal_steps (Σ := Σ) rs
1383+ α σ (IT_of_V αv :: βs) σ' (f k))%I k ε.
1384+ Proof .
1385+ set (R := λ k p,
1386+ uPred_holds
1387+ (∃ (αv : ITV (sReifier_ops rs) A) (βs : list (IT (sReifier_ops rs) A))
1388+ (σ' : sReifier_state rs ♯ IT (sReifier_ops rs) A),
1389+ tp_internal_steps (Σ := Σ) rs α σ (IT_of_V αv :: βs) σ' p) k ε).
1390+ intros H.
1391+ apply (AC nat nat R).
1392+ intros x.
1393+ subst R.
1394+ assert (Hemp : uPred_holds (emp : iProp Σ) x ε).
1395+ { uPred.unseal. rewrite /upred.uPred_pure_def //=. }
1396+ pose proof (uPred_in_entails _ _ H x ε (ucmra_unit_validN _) Hemp) as G.
1397+ clear H.
1398+ revert G.
1399+ uPred.unseal.
1400+ intros [αv [βs [σ' [k H]]]].
1401+ exists k, αv, βs, σ'.
1402+ apply H.
1403+ Qed .
1404+
1405+ Definition bounded (f : nat → nat) : Prop :=
1406+ ∃ n, ∀ m, f m ≤ n.
1407+
1408+ Lemma bounding_fun_bounded_contra (AC : Choice) (XM : Classical) Σ {a} (rs : sReifier a)
1409+ {A} `{!Cofe A} (α : list (IT _ A)) σ (f : nat → nat) (Hf : bounded f → False) :
1410+ (∀ k, uPred_holds
1411+ (∃ αv βs σ', tp_internal_steps (Σ := Σ) rs
1412+ α σ (IT_of_V αv :: βs) σ' (f k))%I k ε)
1413+ → False.
1414+ Proof .
1415+ intros H.
1416+ unfold bounded in Hf.
1417+ pose proof (not_ex_all_not _ _ Hf) as Hf'.
1418+ simpl in Hf'.
1419+ assert (∀ n, ∃ m, f m > n) as Hf''.
1420+ {
1421+ intros n.
1422+ specialize (Hf' n).
1423+ apply not_all_ex_not in Hf'.
1424+ destruct Hf' as [m Hf'].
1425+ exists m.
1426+ lia.
1427+ }
1428+ clear Hf Hf'.
1429+
1430+ Admitted .
1431+
1432+ Lemma bounding_fun_bounded_reseal Σ {a} (rs : sReifier a)
1433+ {A} `{!Cofe A} (α : list (IT _ A)) σ (f : nat → nat) (Hf : bounded f) :
1434+ (∀ k, uPred_holds
1435+ (∃ αv βs σ', tp_internal_steps (Σ := Σ) rs
1436+ α σ (IT_of_V αv :: βs) σ' (f k))%I k ε)
1437+ → ∃ k, ⊢@{iProp Σ} (∃ αv βs σ', tp_internal_steps rs α σ (IT_of_V αv :: βs) σ' k).
1438+ Proof .
1439+ destruct Hf as [n Hf].
1440+ intros H.
1441+ exists n.
1442+ constructor.
1443+ intros m x _ _; simpl.
1444+ eapply (uPred_mono _ _ m m ε); last lia; last apply ucmra_unit_leastN.
1445+ specialize (H m).
1446+ revert H.
1447+ uPred.unseal.
1448+ intros H.
1449+ destruct H as [αv [βs [σ' H]]].
1450+ exists αv, βs, σ'.
1451+ apply (uPred_in_entails _ _
1452+ (tp_internal_steps_grow (Σ := Σ) rs
1453+ α (IT_of_V αv :: βs) σ σ' (f m) n (Hf _)) m
1454+ ε (ucmra_unit_validN _) H).
1455+ Qed .
1456+
1457+ Lemma extract_steps `{Classical} Σ {a} (rs : sReifier a)
1458+ {A} `{!Cofe A} (α : list (IT _ A)) σ :
1459+ (∃ k, (⊢@{iProp Σ} (∃ αv βs σ', tp_internal_steps rs α σ (IT_of_V αv :: βs) σ' k)))
1460+ → ∃ k αv βs σ', tp_external_steps rs α σ (IT_of_V αv :: βs) σ' k.
1461+ Proof .
1462+ intros [k G].
1463+ exists k.
1464+ eapply tp_internal_steps_safe_agnostic; first done.
1465+ apply G.
1466+ Qed .
1467+
1468+ Lemma logrel_adequacy `{Classical} `{Choice} Σ cr n
13511469 (rs : gReifiers NotCtxDep n)
13521470 {A} `{!Cofe A} `{!invGpreS Σ}
13531471 `{!Inhabited (gReifiers_state rs ♯ IT (sReifier_ops (gReifiers_sReifier rs)) A)}
@@ -1364,13 +1482,21 @@ Lemma logrel_adequacy `{Classical} Σ cr n
13641482 (⊢@{iProp Σ} (£ cr
13651483 -∗ @has_full_state _ _ rs _ _ _ HSTATE σ
13661484 -∗ (α) ⪯ₚ (β) @{ rs \ A \ s \ HSTATE })%I)) →
1367- (∃ αv βs st' k ', tp_external_steps (gReifiers_sReifier rs) [β] σ
1485+ (∃ k' αv βs st', tp_external_steps (gReifiers_sReifier rs) [β] σ
13681486 (IT_of_V αv :: βs) st' k').
13691487Proof .
13701488 intros rg ops IT ITV Hsteps Hwp.
1371- epose proof (logrel_adequacy_internal Σ cr n rs α β σ αv αs σ' s k Hsteps Hwp) as J.
1372-
1373- epose proof (@tp_internal_steps_safe_agnostic A _ NotCtxDep rg Σ _ [β] σ).
1489+ eapply extract_steps.
1490+ pose proof (logrel_adequacy_internal Σ cr n rs α β σ αv αs σ' s k Hsteps Hwp) as J.
1491+ apply internal_steps_bounding_fun_witness in J; last done.
1492+ destruct J as [f J].
1493+ destruct (excluded_middle (bounded f)).
1494+ - apply bounding_fun_bounded_reseal in J.
1495+ + apply J.
1496+ + done.
1497+ - exfalso.
1498+ by eapply bounding_fun_bounded_contra.
1499+ Qed .
13741500
13751501Section rules.
13761502 Context {n : nat} (rs : gReifiers NotCtxDep n).
0 commit comments