dec_agree.v 2.09 KB
 Robbert Krebbers committed Mar 10, 2016 1 ``````From iris.algebra Require Export cmra. `````` Ralf Jung committed Feb 23, 2016 2 3 4 ``````Local Arguments validN _ _ _ !_ /. Local Arguments valid _ _ !_ /. Local Arguments op _ _ _ !_ /. `````` Robbert Krebbers committed May 28, 2016 5 ``````Local Arguments pcore _ _ !_ /. `````` Ralf Jung committed Feb 23, 2016 6 `````` `````` Robbert Krebbers committed Feb 24, 2016 7 ``````(* This is isomorphic to option, but has a very different RA structure. *) `````` Ralf Jung committed Feb 23, 2016 8 9 10 11 12 ``````Inductive dec_agree (A : Type) : Type := | DecAgree : A → dec_agree A | DecAgreeBot : dec_agree A. Arguments DecAgree {_} _. Arguments DecAgreeBot {_}. `````` Robbert Krebbers committed Feb 26, 2016 13 14 ``````Instance maybe_DecAgree {A} : Maybe (@DecAgree A) := λ x, match x with DecAgree a => Some a | _ => None end. `````` Ralf Jung committed Feb 23, 2016 15 16 17 18 19 20 21 22 23 24 25 26 27 `````` Section dec_agree. Context {A : Type} `{∀ x y : A, Decision (x = y)}. Instance dec_agree_valid : Valid (dec_agree A) := λ x, if x is DecAgree _ then True else False. Canonical Structure dec_agreeC : cofeT := leibnizC (dec_agree A). Instance dec_agree_op : Op (dec_agree A) := λ x y, match x, y with | DecAgree a, DecAgree b => if decide (a = b) then DecAgree a else DecAgreeBot | _, _ => DecAgreeBot end. `````` Robbert Krebbers committed May 28, 2016 28 ``````Instance dec_agree_pcore : PCore (dec_agree A) := Some. `````` Ralf Jung committed Feb 23, 2016 29 `````` `````` Robbert Krebbers committed May 25, 2016 30 ``````Definition dec_agree_ra_mixin : RAMixin (dec_agree A). `````` Ralf Jung committed Feb 23, 2016 31 32 33 ``````Proof. split. - apply _. `````` Robbert Krebbers committed May 28, 2016 34 `````` - intros x y cx ? [=<-]; eauto. `````` Ralf Jung committed Feb 23, 2016 35 `````` - apply _. `````` Robbert Krebbers committed Feb 24, 2016 36 37 `````` - intros [?|] [?|] [?|]; by repeat (simplify_eq/= || case_match). - intros [?|] [?|]; by repeat (simplify_eq/= || case_match). `````` Robbert Krebbers committed May 28, 2016 38 `````` - intros [?|] ? [=<-]; by repeat (simplify_eq/= || case_match). `````` Robbert Krebbers committed Feb 24, 2016 39 `````` - intros [?|]; by repeat (simplify_eq/= || case_match). `````` Robbert Krebbers committed May 28, 2016 40 `````` - intros [?|] [?|] ?? [=<-]; eauto. `````` Robbert Krebbers committed Feb 24, 2016 41 `````` - by intros [?|] [?|] ?. `````` Ralf Jung committed Feb 23, 2016 42 43 ``````Qed. `````` Robbert Krebbers committed May 25, 2016 44 45 ``````Canonical Structure dec_agreeR : cmraT := discreteR (dec_agree A) dec_agree_ra_mixin. `````` Ralf Jung committed Feb 23, 2016 46 `````` `````` Ralf Jung committed Feb 23, 2016 47 ``````(* Some properties of this CMRA *) `````` Robbert Krebbers committed Mar 15, 2016 48 ``````Global Instance dec_agree_persistent (x : dec_agreeR) : Persistent x. `````` Robbert Krebbers committed May 28, 2016 49 ``````Proof. by constructor. Qed. `````` Robbert Krebbers committed Mar 15, 2016 50 `````` `````` Robbert Krebbers committed Feb 26, 2016 51 52 ``````Lemma dec_agree_ne a b : a ≠ b → DecAgree a ⋅ DecAgree b = DecAgreeBot. Proof. intros. by rewrite /= decide_False. Qed. `````` Ralf Jung committed Feb 23, 2016 53 `````` `````` Robbert Krebbers committed Feb 26, 2016 54 55 56 57 ``````Lemma dec_agree_idemp (x : dec_agree A) : x ⋅ x = x. Proof. destruct x; by rewrite /= ?decide_True. Qed. Lemma dec_agree_op_inv (x1 x2 : dec_agree A) : ✓ (x1 ⋅ x2) → x1 = x2. `````` Robbert Krebbers committed Feb 24, 2016 58 ``````Proof. destruct x1, x2; by repeat (simplify_eq/= || case_match). Qed. `````` Ralf Jung committed Feb 23, 2016 59 ``````End dec_agree. `````` Robbert Krebbers committed Feb 26, 2016 60 `````` `````` Robbert Krebbers committed Jun 17, 2016 61 ``````Arguments dec_agreeC : clear implicits. `````` Robbert Krebbers committed Mar 01, 2016 62 ``Arguments dec_agreeR _ {_}.``