Commit 69d67c60 authored by Robbert Krebbers's avatar Robbert Krebbers

Introduce a canonical structure for CMRAs with a unit element.

parent d6aadd43
...@@ -66,11 +66,10 @@ Arguments authC : clear implicits. ...@@ -66,11 +66,10 @@ Arguments authC : clear implicits.
(* CMRA *) (* CMRA *)
Section cmra. Section cmra.
Context {A : cmraT}. Context {A : ucmraT}.
Implicit Types a b : A. Implicit Types a b : A.
Implicit Types x y : auth A. Implicit Types x y : auth A.
Global Instance auth_empty `{Empty A} : Empty (auth A) := Auth .
Instance auth_valid : Valid (auth A) := λ x, Instance auth_valid : Valid (auth A) := λ x,
match authoritative x with match authoritative x with
| Excl a => ( n, own x {n} a) a | Excl a => ( n, own x {n} a) a
...@@ -101,7 +100,7 @@ Proof. by destruct x as [[]]. Qed. ...@@ -101,7 +100,7 @@ Proof. by destruct x as [[]]. Qed.
Lemma own_validN n (x : auth A) : {n} x {n} own x. Lemma own_validN n (x : auth A) : {n} x {n} own x.
Proof. destruct x as [[]]; naive_solver eauto using cmra_validN_includedN. Qed. Proof. destruct x as [[]]; naive_solver eauto using cmra_validN_includedN. Qed.
Definition auth_cmra_mixin : CMRAMixin (auth A). Lemma auth_cmra_mixin : CMRAMixin (auth A).
Proof. Proof.
split. split.
- by intros n x y1 y2 [Hy Hy']; split; simpl; rewrite ?Hy ?Hy'. - by intros n x y1 y2 [Hy Hy']; split; simpl; rewrite ?Hy ?Hy'.
...@@ -128,7 +127,7 @@ Proof. ...@@ -128,7 +127,7 @@ Proof.
as (b&?&?&?); auto using own_validN. as (b&?&?&?); auto using own_validN.
by exists (Auth (ea.1) (b.1), Auth (ea.2) (b.2)). by exists (Auth (ea.1) (b.1), Auth (ea.2) (b.2)).
Qed. Qed.
Canonical Structure authR : cmraT := Canonical Structure authR :=
CMRAT (auth A) auth_cofe_mixin auth_cmra_mixin. CMRAT (auth A) auth_cofe_mixin auth_cmra_mixin.
Global Instance auth_cmra_discrete : CMRADiscrete A CMRADiscrete authR. Global Instance auth_cmra_discrete : CMRADiscrete A CMRADiscrete authR.
Proof. Proof.
...@@ -139,6 +138,17 @@ Proof. ...@@ -139,6 +138,17 @@ Proof.
- by rewrite -cmra_discrete_valid_iff. - by rewrite -cmra_discrete_valid_iff.
Qed. Qed.
Instance auth_empty : Empty (auth A) := Auth .
Lemma auth_ucmra_mixin : UCMRAMixin (auth A).
Proof.
split; simpl.
- apply (@ucmra_unit_valid A).
- by intros x; constructor; rewrite /= left_id.
- apply _.
Qed.
Canonical Structure authUR :=
UCMRAT (auth A) auth_cofe_mixin auth_cmra_mixin auth_ucmra_mixin.
(** Internalized properties *) (** Internalized properties *)
Lemma auth_equivI {M} (x y : auth A) : Lemma auth_equivI {M} (x y : auth A) :
(x y) (authoritative x authoritative y own x own y : uPred M). (x y) (authoritative x authoritative y own x own y : uPred M).
...@@ -151,17 +161,6 @@ Lemma auth_validI {M} (x : auth A) : ...@@ -151,17 +161,6 @@ Lemma auth_validI {M} (x : auth A) :
end : uPred M). end : uPred M).
Proof. uPred.unseal. by destruct x as [[]]. Qed. Proof. uPred.unseal. by destruct x as [[]]. Qed.
(** The notations ◯ and ● only work for CMRAs with an empty element. So, in
what follows, we assume we have an empty element. *)
Context `{Empty A, !CMRAUnit A}.
Global Instance auth_cmra_unit : CMRAUnit authR.
Proof.
split; simpl.
- by apply (@cmra_unit_valid A _).
- by intros x; constructor; rewrite /= left_id.
- apply _.
Qed.
Lemma auth_frag_op a b : (a b) a b. Lemma auth_frag_op a b : (a b) a b.
Proof. done. Qed. Proof. done. Qed.
Lemma auth_both_op a b : Auth (Excl a) b a b. Lemma auth_both_op a b : Auth (Excl a) b a b.
...@@ -206,6 +205,7 @@ Qed. ...@@ -206,6 +205,7 @@ Qed.
End cmra. End cmra.
Arguments authR : clear implicits. Arguments authR : clear implicits.
Arguments authUR : clear implicits.
(* Functor *) (* Functor *)
Definition auth_map {A B} (f : A B) (x : auth A) : auth B := Definition auth_map {A B} (f : A B) (x : auth A) : auth B :=
...@@ -223,7 +223,7 @@ Instance auth_map_cmra_ne {A B : cofeT} n : ...@@ -223,7 +223,7 @@ Instance auth_map_cmra_ne {A B : cofeT} n :
Proof. Proof.
intros f g Hf [??] [??] [??]; split; [by apply excl_map_cmra_ne|by apply Hf]. intros f g Hf [??] [??] [??]; split; [by apply excl_map_cmra_ne|by apply Hf].
Qed. Qed.
Instance auth_map_cmra_monotone {A B : cmraT} (f : A B) : Instance auth_map_cmra_monotone {A B : ucmraT} (f : A B) :
CMRAMonotone f CMRAMonotone (auth_map f). CMRAMonotone f CMRAMonotone (auth_map f).
Proof. Proof.
split; try apply _. split; try apply _.
...@@ -237,24 +237,24 @@ Definition authC_map {A B} (f : A -n> B) : authC A -n> authC B := ...@@ -237,24 +237,24 @@ Definition authC_map {A B} (f : A -n> B) : authC A -n> authC B :=
Lemma authC_map_ne A B n : Proper (dist n ==> dist n) (@authC_map A B). Lemma authC_map_ne A B n : Proper (dist n ==> dist n) (@authC_map A B).
Proof. intros f f' Hf [[a| |] b]; repeat constructor; apply Hf. Qed. Proof. intros f f' Hf [[a| |] b]; repeat constructor; apply Hf. Qed.
Program Definition authRF (F : rFunctor) : rFunctor := {| Program Definition authURF (F : urFunctor) : urFunctor := {|
rFunctor_car A B := authR (rFunctor_car F A B); urFunctor_car A B := authUR (urFunctor_car F A B);
rFunctor_map A1 A2 B1 B2 fg := authC_map (rFunctor_map F fg) urFunctor_map A1 A2 B1 B2 fg := authC_map (urFunctor_map F fg)
|}. |}.
Next Obligation. Next Obligation.
by intros F A1 A2 B1 B2 n f g Hfg; apply authC_map_ne, rFunctor_ne. by intros F A1 A2 B1 B2 n f g Hfg; apply authC_map_ne, urFunctor_ne.
Qed. Qed.
Next Obligation. Next Obligation.
intros F A B x. rewrite /= -{2}(auth_map_id x). intros F A B x. rewrite /= -{2}(auth_map_id x).
apply auth_map_ext=>y; apply rFunctor_id. apply auth_map_ext=>y; apply urFunctor_id.
Qed. Qed.
Next Obligation. Next Obligation.
intros F A1 A2 A3 B1 B2 B3 f g f' g' x. rewrite /= -auth_map_compose. intros F A1 A2 A3 B1 B2 B3 f g f' g' x. rewrite /= -auth_map_compose.
apply auth_map_ext=>y; apply rFunctor_compose. apply auth_map_ext=>y; apply urFunctor_compose.
Qed. Qed.
Instance authRF_contractive F : Instance authURF_contractive F :
rFunctorContractive F rFunctorContractive (authRF F). urFunctorContractive F urFunctorContractive (authURF F).
Proof. Proof.
by intros ? A1 A2 B1 B2 n f g Hfg; apply authC_map_ne, rFunctor_contractive. by intros ? A1 A2 B1 B2 n f g Hfg; apply authC_map_ne, urFunctor_contractive.
Qed. Qed.
This diff is collapsed.
From iris.algebra Require Export cmra list. From iris.algebra Require Export cmra list.
From iris.prelude Require Import gmap. From iris.prelude Require Import gmap.
Fixpoint big_op {A : cmraT} `{Empty A} (xs : list A) : A := Fixpoint big_op {A : ucmraT} (xs : list A) : A :=
match xs with [] => | x :: xs => x big_op xs end. match xs with [] => | x :: xs => x big_op xs end.
Arguments big_op _ _ !_ /. Arguments big_op _ !_ /.
Instance: Params (@big_op) 2. Instance: Params (@big_op) 1.
Definition big_opM `{Countable K} {A : cmraT} `{Empty A} (m : gmap K A) : A := Definition big_opM `{Countable K} {A : ucmraT} (m : gmap K A) : A :=
big_op (snd <$> map_to_list m). big_op (snd <$> map_to_list m).
Instance: Params (@big_opM) 5. Instance: Params (@big_opM) 4.
(** * Properties about big ops *) (** * Properties about big ops *)
Section big_op. Section big_op.
Context `{CMRAUnit A}. Context {A : ucmraT}.
Implicit Types xs : list A.
(** * Big ops *) (** * Big ops *)
Lemma big_op_nil : big_op (@nil A) = . Lemma big_op_nil : big_op (@nil A) = .
Proof. done. Qed. Proof. done. Qed.
Lemma big_op_cons x xs : big_op (x :: xs) = x big_op xs. Lemma big_op_cons x xs : big_op (x :: xs) = x big_op xs.
Proof. done. Qed. Proof. done. Qed.
Global Instance big_op_permutation : Proper (() ==> ()) big_op. Global Instance big_op_permutation : Proper (() ==> ()) (@big_op A).
Proof. Proof.
induction 1 as [|x xs1 xs2 ? IH|x y xs|xs1 xs2 xs3]; simpl; auto. induction 1 as [|x xs1 xs2 ? IH|x y xs|xs1 xs2 xs3]; simpl; auto.
- by rewrite IH. - by rewrite IH.
- by rewrite !assoc (comm _ x). - by rewrite !assoc (comm _ x).
- by trans (big_op xs2). - by trans (big_op xs2).
Qed. Qed.
Global Instance big_op_ne n : Proper (dist n ==> dist n) big_op. Global Instance big_op_ne n : Proper (dist n ==> dist n) (@big_op A).
Proof. by induction 1; simpl; repeat apply (_ : Proper (_ ==> _ ==> _) op). Qed. Proof. by induction 1; simpl; repeat apply (_ : Proper (_ ==> _ ==> _) op). Qed.
Global Instance big_op_proper : Proper (() ==> ()) big_op := ne_proper _. Global Instance big_op_proper : Proper (() ==> ()) big_op := ne_proper _.
Lemma big_op_app xs ys : big_op (xs ++ ys) big_op xs big_op ys. Lemma big_op_app xs ys : big_op (xs ++ ys) big_op xs big_op ys.
......
...@@ -3,7 +3,7 @@ From iris.algebra Require Import cmra_big_op. ...@@ -3,7 +3,7 @@ From iris.algebra Require Import cmra_big_op.
(** * Simple solver for validity and inclusion by reflection *) (** * Simple solver for validity and inclusion by reflection *)
Module ra_reflection. Section ra_reflection. Module ra_reflection. Section ra_reflection.
Context `{CMRAUnit A}. Context {A : ucmraT}.
Inductive expr := Inductive expr :=
| EVar : nat expr | EVar : nat expr
...@@ -24,8 +24,8 @@ Module ra_reflection. Section ra_reflection. ...@@ -24,8 +24,8 @@ Module ra_reflection. Section ra_reflection.
Lemma eval_flatten Σ e : Lemma eval_flatten Σ e :
eval Σ e big_op ((λ n, from_option id (Σ !! n)) <$> flatten e). eval Σ e big_op ((λ n, from_option id (Σ !! n)) <$> flatten e).
Proof. Proof.
by induction e as [| |e1 IH1 e2 IH2]; induction e as [| |e1 IH1 e2 IH2]; rewrite /= ?right_id //.
rewrite /= ?right_id ?fmap_app ?big_op_app ?IH1 ?IH2. by rewrite fmap_app IH1 IH2 big_op_app.
Qed. Qed.
Lemma flatten_correct Σ e1 e2 : Lemma flatten_correct Σ e1 e2 :
flatten e1 `contains` flatten e2 eval Σ e1 eval Σ e2. flatten e1 `contains` flatten e2 eval Σ e1 eval Σ e2.
......
...@@ -91,8 +91,8 @@ End cofe_mixin. ...@@ -91,8 +91,8 @@ End cofe_mixin.
(** Discrete COFEs and Timeless elements *) (** Discrete COFEs and Timeless elements *)
(* TODO: On paper, We called these "discrete elements". I think that makes (* TODO: On paper, We called these "discrete elements". I think that makes
more sense. *) more sense. *)
Class Timeless {A : cofeT} (x : A) := timeless y : x {0} y x y. Class Timeless `{Equiv A, Dist A} (x : A) := timeless y : x {0} y x y.
Arguments timeless {_} _ {_} _ _. Arguments timeless {_ _ _} _ {_} _ _.
Class Discrete (A : cofeT) := discrete_timeless (x : A) :> Timeless x. Class Discrete (A : cofeT) := discrete_timeless (x : A) :> Timeless x.
(** General properties *) (** General properties *)
......
...@@ -77,8 +77,7 @@ Instance excl_valid : Valid (excl A) := λ x, ...@@ -77,8 +77,7 @@ Instance excl_valid : Valid (excl A) := λ x,
match x with Excl _ | ExclUnit => True | ExclBot => False end. match x with Excl _ | ExclUnit => True | ExclBot => False end.
Instance excl_validN : ValidN (excl A) := λ n x, Instance excl_validN : ValidN (excl A) := λ n x,
match x with Excl _ | ExclUnit => True | ExclBot => False end. match x with Excl _ | ExclUnit => True | ExclBot => False end.
Global Instance excl_empty : Empty (excl A) := ExclUnit. Instance excl_core : Core (excl A) := λ _, ExclUnit.
Instance excl_core : Core (excl A) := λ _, .
Instance excl_op : Op (excl A) := λ x y, Instance excl_op : Op (excl A) := λ x y,
match x, y with match x, y with
| Excl a, ExclUnit | ExclUnit, Excl a => Excl a | Excl a, ExclUnit | ExclUnit, Excl a => Excl a
...@@ -86,7 +85,7 @@ Instance excl_op : Op (excl A) := λ x y, ...@@ -86,7 +85,7 @@ Instance excl_op : Op (excl A) := λ x y,
| _, _=> ExclBot | _, _=> ExclBot
end. end.
Definition excl_cmra_mixin : CMRAMixin (excl A). Lemma excl_cmra_mixin : CMRAMixin (excl A).
Proof. Proof.
split. split.
- by intros n []; destruct 1; constructor. - by intros n []; destruct 1; constructor.
...@@ -98,7 +97,7 @@ Proof. ...@@ -98,7 +97,7 @@ Proof.
- by intros [?| |] [?| |]; constructor. - by intros [?| |] [?| |]; constructor.
- by intros [?| |]; constructor. - by intros [?| |]; constructor.
- constructor. - constructor.
- by intros [?| |] [?| |]; exists . - by intros [?| |] [?| |]; exists ExclUnit.
- by intros n [?| |] [?| |]. - by intros n [?| |] [?| |].
- intros n x y1 y2 ? Hx. - intros n x y1 y2 ? Hx.
by exists match y1, y2 with by exists match y1, y2 with
...@@ -107,13 +106,18 @@ Proof. ...@@ -107,13 +106,18 @@ Proof.
| ExclUnit, _ => (ExclUnit, x) | _, ExclUnit => (x, ExclUnit) | ExclUnit, _ => (ExclUnit, x) | _, ExclUnit => (x, ExclUnit)
end; destruct y1, y2; inversion_clear Hx; repeat constructor. end; destruct y1, y2; inversion_clear Hx; repeat constructor.
Qed. Qed.
Canonical Structure exclR : cmraT := Canonical Structure exclR :=
CMRAT (excl A) excl_cofe_mixin excl_cmra_mixin. CMRAT (excl A) excl_cofe_mixin excl_cmra_mixin.
Global Instance excl_cmra_unit : CMRAUnit exclR.
Proof. split. done. by intros []. apply _. Qed.
Global Instance excl_cmra_discrete : Discrete A CMRADiscrete exclR. Global Instance excl_cmra_discrete : Discrete A CMRADiscrete exclR.
Proof. split. apply _. by intros []. Qed. Proof. split. apply _. by intros []. Qed.
Instance excl_empty : Empty (excl A) := ExclUnit.
Lemma excl_ucmra_mixin : UCMRAMixin (excl A).
Proof. split. done. by intros []. apply _. Qed.
Canonical Structure exclUR :=
UCMRAT (excl A) excl_cofe_mixin excl_cmra_mixin excl_ucmra_mixin.
Lemma excl_validN_inv_l n x a : {n} (Excl a x) x = . Lemma excl_validN_inv_l n x a : {n} (Excl a x) x = .
Proof. by destruct x. Qed. Proof. by destruct x. Qed.
Lemma excl_validN_inv_r n x a : {n} (x Excl a) x = . Lemma excl_validN_inv_r n x a : {n} (x Excl a) x = .
...@@ -152,6 +156,7 @@ End excl. ...@@ -152,6 +156,7 @@ End excl.
Arguments exclC : clear implicits. Arguments exclC : clear implicits.
Arguments exclR : clear implicits. Arguments exclR : clear implicits.
Arguments exclUR : clear implicits.
(* Functor *) (* Functor *)
Definition excl_map {A B} (f : A B) (x : excl A) : excl B := Definition excl_map {A B} (f : A B) (x : excl A) : excl B :=
...@@ -182,9 +187,9 @@ Definition exclC_map {A B} (f : A -n> B) : exclC A -n> exclC B := ...@@ -182,9 +187,9 @@ Definition exclC_map {A B} (f : A -n> B) : exclC A -n> exclC B :=
Instance exclC_map_ne A B n : Proper (dist n ==> dist n) (@exclC_map A B). Instance exclC_map_ne A B n : Proper (dist n ==> dist n) (@exclC_map A B).
Proof. by intros f f' Hf []; constructor; apply Hf. Qed. Proof. by intros f f' Hf []; constructor; apply Hf. Qed.
Program Definition exclRF (F : cFunctor) : rFunctor := {| Program Definition exclURF (F : cFunctor) : urFunctor := {|
rFunctor_car A B := exclR (cFunctor_car F A B); urFunctor_car A B := (exclUR (cFunctor_car F A B) : ucmraT);
rFunctor_map A1 A2 B1 B2 fg := exclC_map (cFunctor_map F fg) urFunctor_map A1 A2 B1 B2 fg := exclC_map (cFunctor_map F fg)
|}. |}.
Next Obligation. Next Obligation.
intros F A1 A2 B1 B2 n x1 x2 ??. by apply exclC_map_ne, cFunctor_ne. intros F A1 A2 B1 B2 n x1 x2 ??. by apply exclC_map_ne, cFunctor_ne.
...@@ -198,8 +203,8 @@ Next Obligation. ...@@ -198,8 +203,8 @@ Next Obligation.
apply excl_map_ext=>y; apply cFunctor_compose. apply excl_map_ext=>y; apply cFunctor_compose.
Qed. Qed.
Instance exclRF_contractive F : Instance exclURF_contractive F :
cFunctorContractive F rFunctorContractive (exclRF F). cFunctorContractive F urFunctorContractive (exclURF F).
Proof. Proof.
intros A1 A2 B1 B2 n x1 x2 ??. by apply exclC_map_ne, cFunctor_contractive. intros A1 A2 B1 B2 n x1 x2 ??. by apply exclC_map_ne, cFunctor_contractive.
Qed. Qed.
...@@ -119,8 +119,7 @@ Instance frac_valid : Valid (frac A) := λ x, ...@@ -119,8 +119,7 @@ Instance frac_valid : Valid (frac A) := λ x,
match x with Frac q a => (q 1)%Qc a | FracUnit => True end. match x with Frac q a => (q 1)%Qc a | FracUnit => True end.
Instance frac_validN : ValidN (frac A) := λ n x, Instance frac_validN : ValidN (frac A) := λ n x,
match x with Frac q a => (q 1)%Qc {n} a | FracUnit => True end. match x with Frac q a => (q 1)%Qc {n} a | FracUnit => True end.
Global Instance frac_empty : Empty (frac A) := FracUnit. Instance frac_core : Core (frac A) := λ _, FracUnit.
Instance frac_core : Core (frac A) := λ _, .
Instance frac_op : Op (frac A) := λ x y, Instance frac_op : Op (frac A) := λ x y,
match x, y with match x, y with
| Frac q1 a, Frac q2 b => Frac (q1 + q2) (a b) | Frac q1 a, Frac q2 b => Frac (q1 + q2) (a b)
...@@ -148,25 +147,30 @@ Proof. ...@@ -148,25 +147,30 @@ Proof.
trans (q1 + q2)%Qp; simpl; last done. trans (q1 + q2)%Qp; simpl; last done.
rewrite -{1}(Qcplus_0_r q1) -Qcplus_le_mono_l; auto using Qclt_le_weak. rewrite -{1}(Qcplus_0_r q1) -Qcplus_le_mono_l; auto using Qclt_le_weak.
- intros n [q a|] y1 y2 Hx Hx'; last first. - intros n [q a|] y1 y2 Hx Hx'; last first.
{ by exists (, ); destruct y1, y2; inversion_clear Hx'. } { by exists (FracUnit, FracUnit); destruct y1, y2; inversion_clear Hx'. }
destruct Hx, y1 as [q1 b1|], y2 as [q2 b2|]. destruct Hx, y1 as [q1 b1|], y2 as [q2 b2|].
+ apply (inj2 Frac) in Hx'; destruct Hx' as [-> ?]. + apply (inj2 Frac) in Hx'; destruct Hx' as [-> ?].
destruct (cmra_extend n a b1 b2) as ([z1 z2]&?&?&?); auto. destruct (cmra_extend n a b1 b2) as ([z1 z2]&?&?&?); auto.
exists (Frac q1 z1,Frac q2 z2); by repeat constructor. exists (Frac q1 z1,Frac q2 z2); by repeat constructor.
+ exists (Frac q a, ); inversion_clear Hx'; by repeat constructor. + exists (Frac q a, FracUnit); inversion_clear Hx'; by repeat constructor.
+ exists (, Frac q a); inversion_clear Hx'; by repeat constructor. + exists (FracUnit, Frac q a); inversion_clear Hx'; by repeat constructor.
+ exfalso; inversion_clear Hx'. + exfalso; inversion_clear Hx'.
Qed. Qed.
Canonical Structure fracR : cmraT := Canonical Structure fracR :=
CMRAT (frac A) frac_cofe_mixin frac_cmra_mixin. CMRAT (frac A) frac_cofe_mixin frac_cmra_mixin.
Global Instance frac_cmra_unit : CMRAUnit fracR.
Proof. split. done. by intros []. apply _. Qed.
Global Instance frac_cmra_discrete : CMRADiscrete A CMRADiscrete fracR. Global Instance frac_cmra_discrete : CMRADiscrete A CMRADiscrete fracR.
Proof. Proof.
split; first apply _. split; first apply _.
intros [q a|]; destruct 1; split; auto using cmra_discrete_valid. intros [q a|]; destruct 1; split; auto using cmra_discrete_valid.
Qed. Qed.
Instance frac_empty : Empty (frac A) := FracUnit.
Definition frac_ucmra_mixin : UCMRAMixin (frac A).
Proof. split. done. by intros []. apply _. Qed.
Canonical Structure fracUR :=
UCMRAT (frac A) frac_cofe_mixin frac_cmra_mixin frac_ucmra_mixin.
Lemma frac_validN_inv_l n y a : {n} (Frac 1 a y) y = . Lemma frac_validN_inv_l n y a : {n} (Frac 1 a y) y = .
Proof. Proof.
destruct y as [q b|]; [|done]=> -[Hq ?]; destruct (Qcle_not_lt _ _ Hq). destruct y as [q b|]; [|done]=> -[Hq ?]; destruct (Qcle_not_lt _ _ Hq).
...@@ -217,6 +221,7 @@ Qed. ...@@ -217,6 +221,7 @@ Qed.
End cmra. End cmra.
Arguments fracR : clear implicits. Arguments fracR : clear implicits.
Arguments fracUR : clear implicits.
(* Functor *) (* Functor *)
Instance frac_map_cmra_monotone {A B : cmraT} (f : A B) : Instance frac_map_cmra_monotone {A B : cmraT} (f : A B) :
...@@ -225,15 +230,15 @@ Proof. ...@@ -225,15 +230,15 @@ Proof.
split; try apply _. split; try apply _.
- intros n [p a|]; destruct 1; split; auto using validN_preserving. - intros n [p a|]; destruct 1; split; auto using validN_preserving.
- intros [q1 a1|] [q2 a2|] [[q3 a3|] Hx]; - intros [q1 a1|] [q2 a2|] [[q3 a3|] Hx];
inversion Hx; setoid_subst; try apply: cmra_unit_least; auto. inversion Hx; setoid_subst; try apply: ucmra_unit_least; auto.
destruct (included_preserving f a1 (a1 a3)) as [b ?]. destruct (included_preserving f a1 (a1 a3)) as [b ?].
{ by apply cmra_included_l. } { by apply cmra_included_l. }
by exists (Frac q3 b); constructor. by exists (Frac q3 b); constructor.
Qed. Qed.
Program Definition fracRF (F : rFunctor) : rFunctor := {| Program Definition fracURF (F : rFunctor) : urFunctor := {|
rFunctor_car A B := fracR (rFunctor_car F A B); urFunctor_car A B := fracUR (rFunctor_car F A B);
rFunctor_map A1 A2 B1 B2 fg := fracC_map (rFunctor_map F fg) urFunctor_map A1 A2 B1 B2 fg := fracC_map (rFunctor_map F fg)
|}. |}.
Next Obligation. Next Obligation.
by intros F A1 A2 B1 B2 n f g Hfg; apply fracC_map_ne, rFunctor_ne. by intros F A1 A2 B1 B2 n f g Hfg; apply fracC_map_ne, rFunctor_ne.
...@@ -247,8 +252,8 @@ Next Obligation. ...@@ -247,8 +252,8 @@ Next Obligation.
apply frac_map_ext=>y; apply rFunctor_compose. apply frac_map_ext=>y; apply rFunctor_compose.
Qed. Qed.
Instance fracRF_contractive F : Instance fracURF_contractive F :
rFunctorContractive F rFunctorContractive (fracRF F). rFunctorContractive F urFunctorContractive (fracURF F).
Proof. Proof.
by intros ? A1 A2 B1 B2 n f g Hfg; apply fracC_map_ne, rFunctor_contractive. by intros ? A1 A2 B1 B2 n f g Hfg; apply fracC_map_ne, rFunctor_contractive.
Qed. Qed.
...@@ -109,7 +109,7 @@ Proof. ...@@ -109,7 +109,7 @@ Proof.
{ exists m2. by rewrite left_id. } { exists m2. by rewrite left_id. }
destruct (IH (delete i m2)) as [m2' Hm2']. destruct (IH (delete i m2)) as [m2' Hm2'].
{ intros j. move: (Hm j); destruct (decide (i = j)) as [->|]. { intros j. move: (Hm j); destruct (decide (i = j)) as [->|].
- intros _. rewrite Hi. apply: cmra_unit_least. - intros _. rewrite Hi. apply: ucmra_unit_least.
- rewrite lookup_insert_ne // lookup_delete_ne //. } - rewrite lookup_insert_ne // lookup_delete_ne //. }
destruct (Hm i) as [my Hi']; simplify_map_eq. destruct (Hm i) as [my Hi']; simplify_map_eq.
exists (partial_alter (λ _, my) i m2')=>j; destruct (decide (i = j)) as [->|]. exists (partial_alter (λ _, my) i m2')=>j; destruct (decide (i = j)) as [->|].
...@@ -118,7 +118,7 @@ Proof. ...@@ -118,7 +118,7 @@ Proof.
lookup_insert_ne // lookup_partial_alter_ne. lookup_insert_ne // lookup_partial_alter_ne.
Qed. Qed.
Definition gmap_cmra_mixin : CMRAMixin (gmap K A). Lemma gmap_cmra_mixin : CMRAMixin (gmap K A).
Proof. Proof.
split. split.
- by intros n m1 m2 m3 Hm i; rewrite !lookup_op (Hm i). - by intros n m1 m2 m3 Hm i; rewrite !lookup_op (Hm i).
...@@ -152,17 +152,21 @@ Proof. ...@@ -152,17 +152,21 @@ Proof.
pose proof (Hm12' i) as Hm12''; rewrite Hx in Hm12''. pose proof (Hm12' i) as Hm12''; rewrite Hx in Hm12''.
by symmetry; apply option_op_positive_dist_r with (m1 !! i). by symmetry; apply option_op_positive_dist_r with (m1 !! i).
Qed. Qed.
Canonical Structure gmapR : cmraT := Canonical Structure gmapR :=
CMRAT (gmap K A) gmap_cofe_mixin gmap_cmra_mixin. CMRAT (gmap K A) gmap_cofe_mixin gmap_cmra_mixin.
Global Instance gmap_cmra_unit : CMRAUnit gmapR.
Global Instance gmap_cmra_discrete : CMRADiscrete A CMRADiscrete gmapR.
Proof. split; [apply _|]. intros m ? i. by apply: cmra_discrete_valid. Qed.
Lemma gmap_ucmra_mixin : UCMRAMixin (gmap K A).
Proof. Proof.
split. split.
- by intros i; rewrite lookup_empty. - by intros i; rewrite lookup_empty.
- by intros m i<