dra.v 6.22 KB
 Robbert Krebbers committed Nov 22, 2015 1 ``````Require Export iris.ra iris.cmra. `````` Robbert Krebbers committed Nov 11, 2015 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 `````` (** From disjoint pcm *) Record validity {A} (P : A → Prop) : Type := Validity { validity_car : A; validity_is_valid : Prop; validity_prf : validity_is_valid → P validity_car }. Arguments Validity {_ _} _ _ _. Arguments validity_car {_ _} _. Arguments validity_is_valid {_ _} _. Definition to_validity {A} {P : A → Prop} (x : A) : validity P := Validity x (P x) id. Instance validity_valid {A} (P : A → Prop) : Valid (validity P) := validity_is_valid. Instance validity_equiv `{Equiv A} (P : A → Prop) : Equiv (validity P) := λ x y, (valid x ↔ valid y) ∧ (valid x → validity_car x ≡ validity_car y). Instance validity_equivalence `{Equiv A,!Equivalence ((≡) : relation A)} P : Equivalence ((≡) : relation (validity P)). Proof. split; unfold equiv, validity_equiv. * by intros [x px ?]; simpl. * intros [x px ?] [y py ?]; naive_solver. * intros [x px ?] [y py ?] [z pz ?] [? Hxy] [? Hyz]; simpl in *. split; [|intros; transitivity y]; tauto. Qed. Instance validity_valid_proper `{Equiv A} (P : A → Prop) : Proper ((≡) ==> iff) (valid : validity P → Prop). Proof. intros ?? [??]; naive_solver. Qed. Local Notation V := valid. `````` Robbert Krebbers committed Nov 20, 2015 33 34 35 36 37 38 39 `````` Definition dra_included `{Equiv A, Valid A, Disjoint A, Op A} := λ x y, ∃ z, y ≡ x ⋅ z ∧ V z ∧ x ⊥ z. Instance: Params (@dra_included) 4. Local Infix "≼" := dra_included. Class DRA A `{Equiv A, Valid A, Unit A, Disjoint A, Op A, Minus A} := { `````` Robbert Krebbers committed Nov 11, 2015 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 `````` (* setoids *) dra_equivalence :> Equivalence ((≡) : relation A); dra_op_proper :> Proper ((≡) ==> (≡) ==> (≡)) (⋅); dra_unit_proper :> Proper ((≡) ==> (≡)) unit; dra_disjoint_proper :> ∀ x, Proper ((≡) ==> impl) (disjoint x); dra_minus_proper :> Proper ((≡) ==> (≡) ==> (≡)) minus; (* validity *) dra_op_valid x y : V x → V y → x ⊥ y → V (x ⋅ y); dra_unit_valid x : V x → V (unit x); dra_minus_valid x y : V x → V y → x ≼ y → V (y ⩪ x); (* monoid *) dra_associative :> Associative (≡) (⋅); dra_disjoint_ll x y z : V x → V y → V z → x ⊥ y → x ⋅ y ⊥ z → x ⊥ z; dra_disjoint_move_l x y z : V x → V y → V z → x ⊥ y → x ⋅ y ⊥ z → x ⊥ y ⋅ z; dra_symmetric :> Symmetric (@disjoint A _); dra_commutative x y : V x → V y → x ⊥ y → x ⋅ y ≡ y ⋅ x; dra_unit_disjoint_l x : V x → unit x ⊥ x; dra_unit_l x : V x → unit x ⋅ x ≡ x; dra_unit_idempotent x : V x → unit (unit x) ≡ unit x; `````` Robbert Krebbers committed Nov 20, 2015 59 60 61 `````` dra_unit_preserving x y : V x → V y → x ≼ y → unit x ≼ unit y; dra_disjoint_minus x y : V x → V y → x ≼ y → x ⊥ y ⩪ x; dra_op_minus x y : V x → V y → x ≼ y → x ⋅ y ⩪ x ≡ y `````` Robbert Krebbers committed Nov 11, 2015 62 63 64 65 66 ``````}. Section dra. Context A `{DRA A}. Arguments valid _ _ !_ /. `````` Robbert Krebbers committed Nov 20, 2015 67 ``````Hint Immediate dra_op_proper : typeclass_instances. `````` Robbert Krebbers committed Nov 11, 2015 68 `````` `````` Robbert Krebbers committed Nov 20, 2015 69 ``````Instance: Proper ((≡) ==> (≡) ==> iff) (⊥). `````` Robbert Krebbers committed Nov 11, 2015 70 ``````Proof. `````` Robbert Krebbers committed Nov 20, 2015 71 72 73 `````` intros x1 x2 Hx y1 y2 Hy; split. * by rewrite Hy, (symmetry_iff (⊥) x1), (symmetry_iff (⊥) x2), Hx. * by rewrite <-Hy, (symmetry_iff (⊥) x2), (symmetry_iff (⊥) x1), <-Hx. `````` Robbert Krebbers committed Nov 11, 2015 74 75 76 77 78 79 80 81 82 83 84 85 86 ``````Qed. Lemma dra_disjoint_rl x y z : V x → V y → V z → y ⊥ z → x ⊥ y ⋅ z → x ⊥ y. Proof. intros ???. rewrite !(symmetry_iff _ x). by apply dra_disjoint_ll. Qed. Lemma dra_disjoint_lr x y z : V x → V y → V z → x ⊥ y → x ⋅ y ⊥ z → y ⊥ z. Proof. intros ????. rewrite dra_commutative by done. by apply dra_disjoint_ll. Qed. Lemma dra_disjoint_move_r x y z : V x → V y → V z → y ⊥ z → x ⊥ y ⋅ z → x ⋅ y ⊥ z. Proof. intros; symmetry; rewrite dra_commutative by eauto using dra_disjoint_rl. apply dra_disjoint_move_l; auto; by rewrite dra_commutative. Qed. `````` Robbert Krebbers committed Nov 20, 2015 87 88 ``````Hint Immediate dra_disjoint_move_l dra_disjoint_move_r. Hint Unfold dra_included. `````` Robbert Krebbers committed Nov 11, 2015 89 90 `````` Notation T := (validity (valid : A → Prop)). `````` Robbert Krebbers committed Nov 22, 2015 91 92 93 ``````Lemma validity_valid_car_valid (z : T) : V z → V (validity_car z). Proof. apply validity_prf. Qed. Hint Resolve validity_valid_car_valid. `````` Robbert Krebbers committed Nov 11, 2015 94 95 ``````Program Instance validity_unit : Unit T := λ x, Validity (unit (validity_car x)) (V x) _. `````` Robbert Krebbers committed Nov 22, 2015 96 ``````Solve Obligations with naive_solver auto using dra_unit_valid. `````` Robbert Krebbers committed Nov 11, 2015 97 98 99 ``````Program Instance validity_op : Op T := λ x y, Validity (validity_car x ⋅ validity_car y) (V x ∧ V y ∧ validity_car x ⊥ validity_car y) _. `````` Robbert Krebbers committed Nov 22, 2015 100 ``````Solve Obligations with naive_solver auto using dra_op_valid. `````` Robbert Krebbers committed Nov 11, 2015 101 102 103 ``````Program Instance validity_minus : Minus T := λ x y, Validity (validity_car x ⩪ validity_car y) (V x ∧ V y ∧ validity_car y ≼ validity_car x) _. `````` Robbert Krebbers committed Nov 22, 2015 104 ``````Solve Obligations with naive_solver auto using dra_minus_valid. `````` Robbert Krebbers committed Nov 11, 2015 105 106 107 108 109 110 111 112 113 114 115 ``````Instance validity_ra : RA T. Proof. split. * apply _. * intros ??? [? Heq]; split; simpl; [|by intros (?&?&?); rewrite Heq]. split; intros (?&?&?); split_ands'; first [by rewrite ?Heq by tauto|by rewrite <-?Heq by tauto|tauto]. * by intros ?? [? Heq]; split; [done|]; simpl; intros ?; rewrite Heq. * by intros ?? Heq ?; rewrite <-Heq. * intros x1 x2 [? Hx] y1 y2 [? Hy]; split; simpl; [|by intros (?&?&?); rewrite Hx, Hy]. `````` Robbert Krebbers committed Nov 20, 2015 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 `````` split; intros (?&?&z&?&?); split_ands'; try tauto. + exists z. by rewrite <-Hy, <-Hx. + exists z. by rewrite Hx, Hy by tauto. * intros [x px ?] [y py ?] [z pz ?]; split; simpl; [intuition eauto 2 using dra_disjoint_lr, dra_disjoint_rl |intros; apply (associative _)]. * intros [x px ?] [y py ?]; split; naive_solver eauto using dra_commutative. * intros [x px ?]; split; naive_solver eauto using dra_unit_l, dra_unit_disjoint_l. * intros [x px ?]; split; naive_solver eauto using dra_unit_idempotent. * intros x y Hxy; exists (unit y ⩪ unit x). destruct x as [x px ?], y as [y py ?], Hxy as [[z pz ?] [??]]; simpl in *. assert (py → unit x ≼ unit y) by intuition eauto 10 using dra_unit_preserving. constructor; [|symmetry]; simpl in *; intuition eauto using dra_op_minus, dra_disjoint_minus, dra_unit_valid. `````` Robbert Krebbers committed Nov 11, 2015 132 `````` * by intros [x px ?] [y py ?] (?&?&?). `````` Robbert Krebbers committed Nov 20, 2015 133 134 `````` * intros [x px ?] [y py ?] [[z pz ?] [??]]; split; simpl in *; intuition eauto 10 using dra_disjoint_minus, dra_op_minus. `````` Robbert Krebbers committed Nov 11, 2015 135 ``````Qed. `````` Robbert Krebbers committed Nov 22, 2015 136 137 ``````Definition validityRA : cmraT := discreteRA T. Definition validity_update (x y : validityRA) : `````` Robbert Krebbers committed Nov 11, 2015 138 139 `````` (∀ z, V x → V z → validity_car x ⊥ z → V y ∧ validity_car y ⊥ z) → x ⇝ y. Proof. `````` Robbert Krebbers committed Nov 22, 2015 140 141 `````` intros Hxy; apply discrete_update. intros z (?&?&?); split_ands'; try eapply Hxy; eauto. `````` Robbert Krebbers committed Nov 11, 2015 142 143 ``````Qed. End dra.``````