agree.v 17.9 KB
 Robbert Krebbers committed Mar 10, 2016 1 ``````From iris.algebra Require Export cmra. `````` Ralf Jung committed Nov 25, 2016 2 ``````From iris.algebra Require Import list. `````` Robbert Krebbers committed Oct 25, 2016 3 ``````From iris.base_logic Require Import base_logic. `````` Ralf Jung committed Nov 25, 2016 4 5 6 7 ``````Local Arguments validN _ _ _ !_ /. Local Arguments valid _ _ !_ /. Local Arguments op _ _ _ !_ /. Local Arguments pcore _ _ !_ /. `````` Robbert Krebbers committed Nov 11, 2015 8 `````` `````` Robbert Krebbers committed Dec 21, 2015 9 ``````Record agree (A : Type) : Type := Agree { `````` Ralf Jung committed Nov 25, 2016 10 11 `````` agree_car : A; agree_with : list A; `````` Robbert Krebbers committed Nov 11, 2015 12 ``````}. `````` Ralf Jung committed Nov 25, 2016 13 14 15 16 17 18 19 20 21 22 ``````Arguments Agree {_} _ _. Arguments agree_car {_} _. Arguments agree_with {_} _. (* Some theory about set-inclusion on lists and lists of which all elements are equal. TODO: Move this elsewhere. *) Definition list_setincl `(R : relation A) (al bl : list A) := ∀ a, a ∈ al → ∃ b, b ∈ bl ∧ R a b. Definition list_setequiv `(R : relation A) (al bl : list A) := list_setincl R al bl ∧ list_setincl R bl al. `````` Jacques-Henri Jourdan committed Jan 04, 2017 23 24 25 ``````(* list_agrees is carefully written such that, when applied to a singleton, it is convertible to True. This makes working with agreement much more pleasant. *) `````` Ralf Jung committed Nov 25, 2016 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 ``````Definition list_agrees `(R : relation A) (al : list A) := match al with | [] => True | [a] => True | a :: al => ∀ b, b ∈ al → R a b end. Lemma list_agrees_alt `(R : relation A) `{Equivalence _ R} al : list_agrees R al ↔ (∀ a b, a ∈ al → b ∈ al → R a b). Proof. destruct al as [|a [|b al]]. - split; last done. intros _ ? ? []%elem_of_nil. - split; last done. intros _ ? ? ->%elem_of_list_singleton ->%elem_of_list_singleton. done. - simpl. split. + intros Hl a' b' [->|Ha']%elem_of_cons. * intros [->|Hb']%elem_of_cons; first done. auto. * intros [->|Hb']%elem_of_cons; first by (symmetry; auto). trans a; last by auto. symmetry. auto. + intros Hl b' Hb'. apply Hl; set_solver. Qed. Section list_theory. Context `(R: relation A) `{Equivalence A R}. `````` Ralf Jung committed Jan 05, 2017 49 `````` Collection Hyps := Type H. `````` Ralf Jung committed Jan 25, 2017 50 `````` Local Set Default Proof Using "Hyps". `````` Ralf Jung committed Nov 25, 2016 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 `````` Global Instance: PreOrder (list_setincl R). Proof. split. - intros al a Ha. set_solver. - intros al bl cl Hab Hbc a Ha. destruct (Hab _ Ha) as (b & Hb & Rab). destruct (Hbc _ Hb) as (c & Hc & Rbc). exists c. split; first done. by trans b. Qed. Global Instance: Equivalence (list_setequiv R). Proof. split. - by split. - intros ?? [??]. split; auto. - intros ??? [??] [??]. split; etrans; done. Qed. Global Instance list_setincl_subrel `(R' : relation A) : subrelation R R' → subrelation (list_setincl R) (list_setincl R'). `````` Ralf Jung committed Jan 05, 2017 71 `````` Proof using. `````` Ralf Jung committed Nov 25, 2016 72 73 74 75 76 77 `````` intros HRR' al bl Hab. intros a Ha. destruct (Hab _ Ha) as (b & Hb & HR). exists b. split; first done. exact: HRR'. Qed. Global Instance list_setequiv_subrel `(R' : relation A) : subrelation R R' → subrelation (list_setequiv R) (list_setequiv R'). `````` Ralf Jung committed Jan 05, 2017 78 `````` Proof using. intros HRR' ?? [??]. split; exact: list_setincl_subrel. Qed. `````` Ralf Jung committed Nov 25, 2016 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 `````` Global Instance list_setincl_perm : subrelation (≡ₚ) (list_setincl R). Proof. intros al bl Hab a Ha. exists a. split; last done. by rewrite -Hab. Qed. Global Instance list_setincl_app l : Proper (list_setincl R ==> list_setincl R) (app l). Proof. intros al bl Hab a [Ha|Ha]%elem_of_app. - exists a. split; last done. apply elem_of_app. by left. - destruct (Hab _ Ha) as (b & Hb & HR). exists b. split; last done. apply elem_of_app. by right. Qed. Global Instance list_setequiv_app l : Proper (list_setequiv R ==> list_setequiv R) (app l). Proof. intros al bl [??]. split; apply list_setincl_app; done. Qed. Global Instance: subrelation (≡ₚ) (flip (list_setincl R)). Proof. intros ???. apply list_setincl_perm. done. Qed. Global Instance list_agrees_setincl : Proper (flip (list_setincl R) ==> impl) (list_agrees R). Proof. move=> al bl /= Hab /list_agrees_alt Hal. apply (list_agrees_alt _) => a b Ha Hb. destruct (Hab _ Ha) as (a' & Ha' & HRa). destruct (Hab _ Hb) as (b' & Hb' & HRb). trans a'; first done. etrans; last done. eapply Hal; done. Qed. Global Instance list_agrees_setequiv : Proper (list_setequiv R ==> iff) (list_agrees R). Proof. intros ?? [??]. split; by apply: list_agrees_setincl. Qed. Lemma list_setincl_contains al bl : (∀ x, x ∈ al → x ∈ bl) → list_setincl R al bl. Proof. intros Hin a Ha. exists a. split; last done. naive_solver. Qed. Lemma list_setequiv_equiv al bl : (∀ x, x ∈ al ↔ x ∈ bl) → list_setequiv R al bl. Proof. intros Hin. split; apply list_setincl_contains; naive_solver. Qed. Lemma list_agrees_contains al bl : (∀ x, x ∈ bl → x ∈ al) → list_agrees R al → list_agrees R bl. Proof. intros ?. by eapply (list_agrees_setincl _),list_setincl_contains. Qed. Lemma list_agrees_equiv al bl : (∀ x, x ∈ bl ↔ x ∈ al) → list_agrees R al ↔ list_agrees R bl. Proof. intros ?. by eapply (list_agrees_setequiv _), list_setequiv_equiv. Qed. Lemma list_setincl_singleton a b : R a b → list_setincl R [a] [b]. Proof. intros HR c ->%elem_of_list_singleton. exists b. split; last done. apply elem_of_list_singleton. done. Qed. Lemma list_setincl_singleton_rev a b : list_setincl R [a] [b] → R a b. `````` Ralf Jung committed Jan 05, 2017 147 `````` Proof using. `````` Ralf Jung committed Nov 25, 2016 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 `````` intros Hl. destruct (Hl a) as (? & ->%elem_of_list_singleton & HR); last done. by apply elem_of_list_singleton. Qed. Lemma list_setequiv_singleton a b : R a b → list_setequiv R [a] [b]. Proof. intros ?. split; by apply list_setincl_singleton. Qed. Lemma list_agrees_iff_setincl al a : a ∈ al → list_agrees R al ↔ list_setincl R al [a]. Proof. intros Hin. split. - move=>/list_agrees_alt Hl b Hb. exists a. split; first set_solver+. exact: Hl. - intros Hl. apply (list_agrees_alt _)=> b c Hb Hc. destruct (Hl _ Hb) as (? & ->%elem_of_list_singleton & ?). destruct (Hl _ Hc) as (? & ->%elem_of_list_singleton & ?). by trans a. Qed. Lemma list_setincl_singleton_in al a : a ∈ al → list_setincl R [a] al. Proof. intros Hin b ->%elem_of_list_singleton. exists a. split; done. Qed. Global Instance list_setincl_ext : subrelation (Forall2 R) (list_setincl R). Proof. move=>al bl. induction 1. - intros ? []%elem_of_nil. - intros a [->|Ha]%elem_of_cons. + eexists. split; first constructor. done. + destruct (IHForall2 _ Ha) as (b & ? & ?). exists b. split; first by constructor. done. Qed. Global Instance list_setequiv_ext : subrelation (Forall2 R) (list_setequiv R). Proof. move=>al bl ?. split; apply list_setincl_ext; done. Qed. Lemma list_agrees_subrel `(R' : relation A) `{Equivalence _ R'} : subrelation R R' → ∀ l, list_agrees R l → list_agrees R' l. Proof. move=> HR l /list_agrees_alt Hl. apply (list_agrees_alt _)=> a b Ha Hb. by apply HR, Hl. Qed. Section fmap. Context `(R' : relation B) (f : A → B) {Hf: Proper (R ==> R') f}. `````` Ralf Jung committed Jan 05, 2017 194 `````` Collection Hyps := Type Hf. `````` Ralf Jung committed Jan 25, 2017 195 `````` Local Set Default Proof Using "Hyps". `````` Robbert Krebbers committed Jan 30, 2017 196 `````` `````` Ralf Jung committed Nov 25, 2016 197 198 `````` Global Instance list_setincl_fmap : Proper (list_setincl R ==> list_setincl R') (fmap f). `````` Ralf Jung committed Jan 05, 2017 199 `````` Proof using Hf. `````` Ralf Jung committed Nov 25, 2016 200 201 202 203 `````` intros al bl Hab a' (a & -> & Ha)%elem_of_list_fmap. destruct (Hab _ Ha) as (b & Hb & HR). exists (f b). split; first eapply elem_of_list_fmap; eauto. Qed. `````` Robbert Krebbers committed Jan 30, 2017 204 `````` `````` Ralf Jung committed Nov 25, 2016 205 206 `````` Global Instance list_setequiv_fmap : Proper (list_setequiv R ==> list_setequiv R') (fmap f). `````` Ralf Jung committed Jan 05, 2017 207 `````` Proof using Hf. intros ?? [??]. split; apply list_setincl_fmap; done. Qed. `````` Ralf Jung committed Nov 25, 2016 208 209 210 `````` Lemma list_agrees_fmap `{Equivalence _ R'} al : list_agrees R al → list_agrees R' (f <\$> al). `````` Ralf Jung committed Jan 05, 2017 211 `````` Proof using Type*. `````` Ralf Jung committed Jan 05, 2017 212 `````` move=> /list_agrees_alt Hl. apply (list_agrees_alt R') => a' b'. `````` Ralf Jung committed Nov 25, 2016 213 214 215 216 217 `````` intros (a & -> & Ha)%elem_of_list_fmap (b & -> & Hb)%elem_of_list_fmap. apply Hf. exact: Hl. Qed. End fmap. End list_theory. `````` Robbert Krebbers committed Nov 11, 2015 218 219 `````` Section agree. `````` Ralf Jung committed Jan 25, 2017 220 ``````Local Set Default Proof Using "Type". `````` Ralf Jung committed Nov 22, 2016 221 ``````Context {A : ofeT}. `````` Robbert Krebbers committed Nov 11, 2015 222 `````` `````` Ralf Jung committed Nov 25, 2016 223 ``````Definition agree_list (x : agree A) := agree_car x :: agree_with x. `````` Robbert Krebbers committed Feb 24, 2016 224 `````` `````` Ralf Jung committed Nov 25, 2016 225 226 227 228 ``````Instance agree_validN : ValidN (agree A) := λ n x, list_agrees (dist n) (agree_list x). Instance agree_valid : Valid (agree A) := λ x, list_agrees (equiv) (agree_list x). `````` Robbert Krebbers committed Feb 24, 2016 229 `````` `````` Robbert Krebbers committed Jan 14, 2016 230 ``````Instance agree_dist : Dist (agree A) := λ n x y, `````` Ralf Jung committed Nov 25, 2016 231 232 233 234 235 236 237 `````` list_setequiv (dist n) (agree_list x) (agree_list y). Instance agree_equiv : Equiv (agree A) := λ x y, ∀ n, list_setequiv (dist n) (agree_list x) (agree_list y). Definition agree_dist_incl n (x y : agree A) := list_setincl (dist n) (agree_list x) (agree_list y). `````` Ralf Jung committed Nov 22, 2016 238 ``````Definition agree_ofe_mixin : OfeMixin (agree A). `````` Robbert Krebbers committed Nov 11, 2015 239 240 ``````Proof. split. `````` Ralf Jung committed Nov 25, 2016 241 242 243 244 245 246 `````` - intros x y; split; intros Hxy; done. - split; rewrite /dist /agree_dist; intros ? *. + reflexivity. + by symmetry. + intros. etrans; eassumption. - intros ???. apply list_setequiv_subrel=>??. apply dist_S. `````` Robbert Krebbers committed Nov 11, 2015 247 ``````Qed. `````` Ralf Jung committed Nov 22, 2016 248 249 ``````Canonical Structure agreeC := OfeT (agree A) agree_ofe_mixin. `````` Robbert Krebbers committed Jan 14, 2016 250 ``````Program Instance agree_op : Op (agree A) := λ x y, `````` Robbert Krebbers committed Jul 21, 2016 251 `````` {| agree_car := agree_car x; `````` Ralf Jung committed Nov 25, 2016 252 `````` agree_with := agree_with x ++ agree_car y :: agree_with y |}. `````` Robbert Krebbers committed May 28, 2016 253 ``````Instance agree_pcore : PCore (agree A) := Some. `````` Robbert Krebbers committed Feb 24, 2016 254 `````` `````` Robbert Krebbers committed Feb 11, 2016 255 ``````Instance: Comm (≡) (@op (agree A) _). `````` Ralf Jung committed Nov 25, 2016 256 257 ``````Proof. intros x y n. apply: list_setequiv_equiv. set_solver. Qed. `````` Ralf Jung committed Feb 23, 2016 258 ``````Lemma agree_idemp (x : agree A) : x ⋅ x ≡ x. `````` Ralf Jung committed Nov 25, 2016 259 260 ``````Proof. intros n. apply: list_setequiv_equiv. set_solver. Qed. `````` Robbert Krebbers committed Jan 16, 2016 261 262 ``````Instance: ∀ n : nat, Proper (dist n ==> impl) (@validN (agree A) _ n). Proof. `````` Ralf Jung committed Nov 25, 2016 263 264 `````` intros n x y. rewrite /dist /validN /agree_dist /agree_validN. by intros ->. `````` Robbert Krebbers committed Jan 16, 2016 265 ``````Qed. `````` Ralf Jung committed Nov 25, 2016 266 267 268 269 270 271 ``````Instance: ∀ n : nat, Proper (equiv ==> iff) (@validN (agree A) _ n). Proof. intros n ???. assert (x ≡{n}≡ y) as Hxy by by apply equiv_dist. split; rewrite Hxy; done. Qed. `````` Ralf Jung committed Jan 27, 2017 272 ``````Instance: ∀ x : agree A, NonExpansive (op x). `````` Robbert Krebbers committed Nov 11, 2015 273 ``````Proof. `````` Jacques-Henri Jourdan committed Feb 01, 2017 274 `````` intros x n y1 y2. rewrite /dist /agree_dist /agree_list /=. `````` Ralf Jung committed Nov 25, 2016 275 `````` rewrite !app_comm_cons. apply: list_setequiv_app. `````` Robbert Krebbers committed Nov 11, 2015 276 ``````Qed. `````` Ralf Jung committed Jan 27, 2017 277 ``````Instance: NonExpansive2 (@op (agree A) _). `````` Robbert Krebbers committed Feb 11, 2016 278 ``````Proof. by intros n x1 x2 Hx y1 y2 Hy; rewrite Hy !(comm _ _ y2) Hx. Qed. `````` Robbert Krebbers committed Nov 12, 2015 279 ``````Instance: Proper ((≡) ==> (≡) ==> (≡)) op := ne_proper_2 _. `````` Robbert Krebbers committed Feb 11, 2016 280 ``````Instance: Assoc (≡) (@op (agree A) _). `````` Ralf Jung committed Nov 25, 2016 281 ``````Proof. intros x y z n. apply: list_setequiv_equiv. set_solver. Qed. `````` Robbert Krebbers committed Feb 24, 2016 282 `````` `````` Robbert Krebbers committed Feb 26, 2016 283 284 285 286 287 ``````Lemma agree_included (x y : agree A) : x ≼ y ↔ y ≡ x ⋅ y. Proof. split; [|by intros ?; exists y]. by intros [z Hz]; rewrite Hz assoc agree_idemp. Qed. `````` Ralf Jung committed Nov 25, 2016 288 289 290 291 292 293 294 295 296 297 298 299 ``````Lemma agree_op_inv_inclN n x1 x2 : ✓{n} (x1 ⋅ x2) → agree_dist_incl n x1 x2. Proof. rewrite /validN /= => /list_agrees_alt Hv a /elem_of_cons Ha. exists (agree_car x2). split; first by constructor. eapply Hv. - simpl. destruct Ha as [->|Ha]; set_solver. - simpl. set_solver+. Qed. Lemma agree_op_invN n (x1 x2 : agree A) : ✓{n} (x1 ⋅ x2) → x1 ≡{n}≡ x2. Proof. intros Hxy. split; apply agree_op_inv_inclN; first done. by rewrite comm. Qed. `````` Robbert Krebbers committed Feb 24, 2016 300 301 302 ``````Lemma agree_valid_includedN n (x y : agree A) : ✓{n} y → x ≼{n} y → x ≡{n}≡ y. Proof. move=> Hval [z Hy]; move: Hval; rewrite Hy. `````` Ralf Jung committed Nov 25, 2016 303 `````` by move=> /agree_op_invN->; rewrite agree_idemp. `````` Robbert Krebbers committed Feb 24, 2016 304 305 ``````Qed. `````` Robbert Krebbers committed Jan 14, 2016 306 ``````Definition agree_cmra_mixin : CMRAMixin (agree A). `````` Robbert Krebbers committed Nov 11, 2015 307 ``````Proof. `````` Robbert Krebbers committed May 28, 2016 308 `````` apply cmra_total_mixin; try apply _ || by eauto. `````` Ralf Jung committed Nov 25, 2016 309 310 311 312 313 314 `````` - move=>x. split. + move=>/list_agrees_alt Hx n. apply (list_agrees_alt _)=> a b Ha Hb. apply equiv_dist, Hx; done. + intros Hx. apply (list_agrees_alt _)=> a b Ha Hb. apply equiv_dist=>n. eapply (list_agrees_alt _); first (by apply Hx); done. - intros n x. apply (list_agrees_subrel _ _)=>??. apply dist_S. `````` Robbert Krebbers committed May 28, 2016 315 `````` - intros x. apply agree_idemp. `````` Ralf Jung committed Nov 25, 2016 316 `````` - intros ??? Hl. apply: list_agrees_contains Hl. set_solver. `````` Robbert Krebbers committed Aug 14, 2016 317 `````` - intros n x y1 y2 Hval Hx; exists x, x; simpl; split. `````` Robbert Krebbers committed Feb 24, 2016 318 `````` + by rewrite agree_idemp. `````` Ralf Jung committed Nov 25, 2016 319 `````` + by move: Hval; rewrite Hx; move=> /agree_op_invN->; rewrite agree_idemp. `````` Robbert Krebbers committed Nov 11, 2015 320 ``````Qed. `````` Robbert Krebbers committed Feb 09, 2017 321 ``````Canonical Structure agreeR : cmraT := CMRAT (agree A) agree_cmra_mixin. `````` Robbert Krebbers committed Jan 14, 2016 322 `````` `````` Robbert Krebbers committed May 28, 2016 323 324 ``````Global Instance agree_total : CMRATotal agreeR. Proof. rewrite /CMRATotal; eauto. Qed. `````` Robbert Krebbers committed Mar 15, 2016 325 ``````Global Instance agree_persistent (x : agree A) : Persistent x. `````` Robbert Krebbers committed May 28, 2016 326 ``````Proof. by constructor. Qed. `````` Robbert Krebbers committed Mar 15, 2016 327 `````` `````` Ralf Jung committed Nov 25, 2016 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 ``````Lemma agree_op_inv (x1 x2 : agree A) : ✓ (x1 ⋅ x2) → x1 ≡ x2. Proof. intros ?. apply equiv_dist=>n. by apply agree_op_invN, cmra_valid_validN. Qed. Global Instance agree_discrete : Discrete A → CMRADiscrete agreeR. Proof. intros HD. split. - intros x y Hxy n. eapply list_setequiv_subrel; last exact Hxy. clear -HD. intros x y ?. apply equiv_dist, HD. done. - rewrite /valid /cmra_valid /agree_valid /validN /cmra_validN /agree_validN /=. move=> x. apply (list_agrees_subrel _ _). clear -HD. intros x y. apply HD. Qed. Definition to_agree (x : A) : agree A := {| agree_car := x; agree_with := [] |}. `````` Robbert Krebbers committed Jul 21, 2016 346 `````` `````` Ralf Jung committed Jan 27, 2017 347 ``````Global Instance to_agree_ne : NonExpansive to_agree. `````` Ralf Jung committed Nov 25, 2016 348 349 350 351 ``````Proof. intros x1 x2 Hx; rewrite /= /dist /agree_dist /=. exact: list_setequiv_singleton. Qed. `````` Robbert Krebbers committed Jan 16, 2016 352 ``````Global Instance to_agree_proper : Proper ((≡) ==> (≡)) to_agree := ne_proper _. `````` Robbert Krebbers committed Jul 21, 2016 353 `````` `````` Ralf Jung committed Nov 25, 2016 354 ``````Global Instance to_agree_injN n : Inj (dist n) (dist n) (to_agree). `````` Jacques-Henri Jourdan committed Feb 01, 2017 355 ``````Proof. intros a b [Hxy%list_setincl_singleton_rev _]. done. Qed. `````` Ralf Jung committed Nov 25, 2016 356 357 358 359 ``````Global Instance to_agree_inj : Inj (≡) (≡) (to_agree). Proof. intros a b ?. apply equiv_dist=>n. apply to_agree_injN. by apply equiv_dist. Qed. `````` Robbert Krebbers committed Jul 21, 2016 360 `````` `````` Ralf Jung committed Dec 13, 2016 361 ``````Lemma to_agree_uninjN n (x : agree A) : ✓{n} x → ∃ y : A, to_agree y ≡{n}≡ x. `````` Robbert Krebbers committed Jul 21, 2016 362 ``````Proof. `````` Ralf Jung committed Nov 25, 2016 363 364 365 366 367 368 `````` intros Hl. exists (agree_car x). rewrite /dist /agree_dist /=. split. - apply: list_setincl_singleton_in. set_solver+. - apply (list_agrees_iff_setincl _); first set_solver+. done. Qed. `````` Ralf Jung committed Dec 13, 2016 369 370 371 372 373 374 375 376 377 378 ``````Lemma to_agree_uninj (x : agree A) : ✓ x → ∃ y : A, to_agree y ≡ x. Proof. intros Hl. exists (agree_car x). rewrite /dist /agree_dist /=. split. - apply: list_setincl_singleton_in. set_solver+. - apply (list_agrees_iff_setincl _); first set_solver+. eapply list_agrees_subrel; last exact: Hl; [apply _..|]. intros ???. by apply equiv_dist. Qed. `````` Ralf Jung committed Nov 25, 2016 379 380 381 382 383 384 385 386 387 388 ``````Lemma to_agree_included (a b : A) : to_agree a ≼ to_agree b ↔ a ≡ b. Proof. split. - intros (x & Heq). apply equiv_dist=>n. destruct (Heq n) as [_ Hincl]. (* TODO: This could become a generic lemma about list_setincl. *) destruct (Hincl a) as (? & ->%elem_of_list_singleton & ?); first set_solver+. done. - intros Hab. rewrite Hab. eexists. symmetry. eapply agree_idemp. Qed. `````` Jacques-Henri Jourdan committed Feb 01, 2017 389 390 ``````Lemma to_agree_comp_validN n (a b : A) : ✓{n} (to_agree a ⋅ to_agree b) ↔ a ≡{n}≡ b. `````` Ralf Jung committed Nov 25, 2016 391 392 ``````Proof. split. `````` Jacques-Henri Jourdan committed Feb 01, 2017 393 394 `````` - (* TODO: can this be derived from other stuff? Otherwise, should probably become sth. generic about list_agrees. *) `````` Ralf Jung committed Nov 25, 2016 395 396 `````` intros Hv. apply Hv; simpl; set_solver. - intros ->. rewrite agree_idemp. done. `````` Robbert Krebbers committed Jul 21, 2016 397 ``````Qed. `````` Robbert Krebbers committed Feb 13, 2016 398 `````` `````` Jacques-Henri Jourdan committed Feb 01, 2017 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 ``````Lemma to_agree_comp_valid (a b : A) : ✓ (to_agree a ⋅ to_agree b) ↔ a ≡ b. Proof. rewrite cmra_valid_validN equiv_dist. by setoid_rewrite to_agree_comp_validN. Qed. Global Instance agree_cancelable (x : agree A) : Cancelable x. Proof. intros n y z Hv Heq. destruct (to_agree_uninjN n x) as [x' EQx]; first by eapply cmra_validN_op_l. destruct (to_agree_uninjN n y) as [y' EQy]; first by eapply cmra_validN_op_r. destruct (to_agree_uninjN n z) as [z' EQz]. { eapply (cmra_validN_op_r n x z). by rewrite -Heq. } assert (Hx'y' : x' ≡{n}≡ y'). { apply to_agree_comp_validN. by rewrite EQx EQy. } assert (Hx'z' : x' ≡{n}≡ z'). { apply to_agree_comp_validN. by rewrite EQx EQz -Heq. } by rewrite -EQy -EQz -Hx'y' -Hx'z'. Qed. `````` Robbert Krebbers committed Feb 13, 2016 418 ``````(** Internalized properties *) `````` Robbert Krebbers committed May 31, 2016 419 ``````Lemma agree_equivI {M} a b : to_agree a ≡ to_agree b ⊣⊢ (a ≡ b : uPred M). `````` Robbert Krebbers committed Feb 25, 2016 420 ``````Proof. `````` Ralf Jung committed Nov 25, 2016 421 422 423 `````` uPred.unseal. do 2 split. - intros Hx. exact: to_agree_injN. - intros Hx. exact: to_agree_ne. `````` Robbert Krebbers committed Feb 25, 2016 424 ``````Qed. `````` Ralf Jung committed Mar 10, 2016 425 ``````Lemma agree_validI {M} x y : ✓ (x ⋅ y) ⊢ (x ≡ y : uPred M). `````` Ralf Jung committed Nov 25, 2016 426 ``````Proof. uPred.unseal; split=> r n _ ?; by apply: agree_op_invN. Qed. `````` Robbert Krebbers committed Nov 11, 2015 427 428 ``````End agree. `````` Robbert Krebbers committed Jan 30, 2017 429 ``````Instance: Params (@to_agree) 1. `````` Robbert Krebbers committed Jan 14, 2016 430 ``````Arguments agreeC : clear implicits. `````` Robbert Krebbers committed Mar 01, 2016 431 ``````Arguments agreeR : clear implicits. `````` Robbert Krebbers committed Jan 14, 2016 432 `````` `````` Robbert Krebbers committed Dec 21, 2015 433 ``````Program Definition agree_map {A B} (f : A → B) (x : agree A) : agree B := `````` Ralf Jung committed Nov 25, 2016 434 `````` {| agree_car := f (agree_car x); agree_with := f <\$> (agree_with x) |}. `````` Robbert Krebbers committed Jan 14, 2016 435 ``````Lemma agree_map_id {A} (x : agree A) : agree_map id x = x. `````` Ralf Jung committed Nov 25, 2016 436 ``````Proof. rewrite /agree_map /= list_fmap_id. by destruct x. Qed. `````` Robbert Krebbers committed Jan 16, 2016 437 438 ``````Lemma agree_map_compose {A B C} (f : A → B) (g : B → C) (x : agree A) : agree_map (g ∘ f) x = agree_map g (agree_map f x). `````` Ralf Jung committed Nov 25, 2016 439 ``````Proof. rewrite /agree_map /= list_fmap_compose. done. Qed. `````` Robbert Krebbers committed Dec 15, 2015 440 `````` `````` Robbert Krebbers committed Nov 11, 2015 441 ``````Section agree_map. `````` Ralf Jung committed Jan 27, 2017 442 `````` Context {A B : ofeT} (f : A → B) `{Hf: NonExpansive f}. `````` Ralf Jung committed Jan 05, 2017 443 `````` Collection Hyps := Type Hf. `````` Ralf Jung committed Jan 27, 2017 444 `````` Instance agree_map_ne : NonExpansive (agree_map f). `````` Ralf Jung committed Jan 05, 2017 445 `````` Proof using Hyps. `````` Ralf Jung committed Jan 27, 2017 446 `````` intros n x y Hxy. `````` Ralf Jung committed Nov 25, 2016 447 `````` change (list_setequiv (dist n)(f <\$> (agree_list x))(f <\$> (agree_list y))). `````` Jacques-Henri Jourdan committed Feb 01, 2017 448 `````` eapply list_setequiv_fmap; last exact Hxy. apply _. `````` Ralf Jung committed Nov 25, 2016 449 `````` Qed. `````` Robbert Krebbers committed Feb 26, 2016 450 `````` Instance agree_map_proper : Proper ((≡) ==> (≡)) (agree_map f) := ne_proper _. `````` Ralf Jung committed Nov 25, 2016 451 `````` `````` Robbert Krebbers committed Dec 15, 2015 452 453 `````` Lemma agree_map_ext (g : A → B) x : (∀ x, f x ≡ g x) → agree_map f x ≡ agree_map g x. `````` Ralf Jung committed Nov 25, 2016 454 455 456 457 458 459 `````` Proof. intros Hfg n. apply: list_setequiv_ext. change (f <\$> (agree_list x) ≡{n}≡ g <\$> (agree_list x)). apply list_fmap_ext_ne=>y. by apply equiv_dist. Qed. `````` Robbert Krebbers committed Dec 15, 2015 460 `````` Global Instance agree_map_monotone : CMRAMonotone (agree_map f). `````` Ralf Jung committed Jan 05, 2017 461 `````` Proof using Hyps. `````` Robbert Krebbers committed Feb 26, 2016 462 `````` split; first apply _. `````` Ralf Jung committed Nov 25, 2016 463 464 465 `````` - intros n x. rewrite /cmra_validN /validN /= /agree_validN /= => ?. change (list_agrees (dist n) (f <\$> agree_list x)). eapply (list_agrees_fmap _ _ _); done. `````` Robbert Krebbers committed Feb 26, 2016 466 `````` - intros x y; rewrite !agree_included=> ->. `````` Ralf Jung committed Nov 25, 2016 467 468 `````` rewrite /equiv /agree_equiv /agree_map /agree_op /agree_list /=. rewrite !fmap_app=>n. apply: list_setequiv_equiv. set_solver+. `````` Robbert Krebbers committed Nov 11, 2015 469 470 `````` Qed. End agree_map. `````` Robbert Krebbers committed Nov 16, 2015 471 `````` `````` Robbert Krebbers committed Feb 04, 2016 472 473 ``````Definition agreeC_map {A B} (f : A -n> B) : agreeC A -n> agreeC B := CofeMor (agree_map f : agreeC A → agreeC B). `````` Ralf Jung committed Jan 27, 2017 474 ``````Instance agreeC_map_ne A B : NonExpansive (@agreeC_map A B). `````` Robbert Krebbers committed Nov 16, 2015 475 ``````Proof. `````` Ralf Jung committed Jan 27, 2017 476 `````` intros n f g Hfg x. apply: list_setequiv_ext. `````` Ralf Jung committed Nov 25, 2016 477 478 `````` change (f <\$> (agree_list x) ≡{n}≡ g <\$> (agree_list x)). apply list_fmap_ext_ne. done. `````` Robbert Krebbers committed Nov 16, 2015 479 ``````Qed. `````` Ralf Jung committed Feb 05, 2016 480 `````` `````` Robbert Krebbers committed Mar 02, 2016 481 482 483 484 ``````Program Definition agreeRF (F : cFunctor) : rFunctor := {| rFunctor_car A B := agreeR (cFunctor_car F A B); rFunctor_map A1 A2 B1 B2 fg := agreeC_map (cFunctor_map F fg) |}. `````` Robbert Krebbers committed Mar 07, 2016 485 486 487 ``````Next Obligation. intros ? A1 A2 B1 B2 n ???; simpl. by apply agreeC_map_ne, cFunctor_ne. Qed. `````` Robbert Krebbers committed Mar 02, 2016 488 489 490 491 492 493 494 495 ``````Next Obligation. intros F A B x; simpl. rewrite -{2}(agree_map_id x). apply agree_map_ext=>y. by rewrite cFunctor_id. Qed. Next Obligation. intros F A1 A2 A3 B1 B2 B3 f g f' g' x; simpl. rewrite -agree_map_compose. apply agree_map_ext=>y; apply cFunctor_compose. Qed. `````` Ralf Jung committed Mar 07, 2016 496 497 498 499 500 501 502 `````` Instance agreeRF_contractive F : cFunctorContractive F → rFunctorContractive (agreeRF F). Proof. intros ? A1 A2 B1 B2 n ???; simpl. by apply agreeC_map_ne, cFunctor_contractive. Qed.``````