Commit a9e2d8f3 authored by Robbert Krebbers's avatar Robbert Krebbers
Browse files

Another failed approach to avoid declaring other projections than the carrier as canonical.

parent bf069d12
...@@ -35,92 +35,101 @@ Notation "x ≼{ n } y" := (includedN n x y) ...@@ -35,92 +35,101 @@ Notation "x ≼{ n } y" := (includedN n x y)
Instance: Params (@includedN) 4. Instance: Params (@includedN) 4.
Hint Extern 0 (_ {_} _) => reflexivity. Hint Extern 0 (_ {_} _) => reflexivity.
Record CMRAMixin A `{Dist A, Equiv A, PCore A, Op A, Valid A, ValidN A} := { Record cmra_laws A `{Dist A, Equiv A, PCore A, Op A, Valid A, ValidN A} := {
(* setoids *) (* setoids *)
mixin_cmra_op_ne (x : A) : NonExpansive (op x); law_cmra_op_ne (x : A) : NonExpansive (op x);
mixin_cmra_pcore_ne n x y cx : law_cmra_pcore_ne n x y cx :
x {n} y pcore x = Some cx cy, pcore y = Some cy cx {n} cy; x {n} y pcore x = Some cx cy, pcore y = Some cy cx {n} cy;
mixin_cmra_validN_ne n : Proper (dist n ==> impl) (validN n); law_cmra_validN_ne n : Proper (dist n ==> impl) (validN n);
(* valid *) (* valid *)
mixin_cmra_valid_validN x : x n, {n} x; law_cmra_valid_validN x : x n, {n} x;
mixin_cmra_validN_S n x : {S n} x {n} x; law_cmra_validN_S n x : {S n} x {n} x;
(* monoid *) (* monoid *)
mixin_cmra_assoc : Assoc () (); law_cmra_assoc : Assoc () ();
mixin_cmra_comm : Comm () (); law_cmra_comm : Comm () ();
mixin_cmra_pcore_l x cx : pcore x = Some cx cx x x; law_cmra_pcore_l x cx : pcore x = Some cx cx x x;
mixin_cmra_pcore_idemp x cx : pcore x = Some cx pcore cx Some cx; law_cmra_pcore_idemp x cx : pcore x = Some cx pcore cx Some cx;
mixin_cmra_pcore_mono x y cx : law_cmra_pcore_mono x y cx :
x y pcore x = Some cx cy, pcore y = Some cy cx cy; x y pcore x = Some cx cy, pcore y = Some cy cx cy;
mixin_cmra_validN_op_l n x y : {n} (x y) {n} x; law_cmra_validN_op_l n x y : {n} (x y) {n} x;
mixin_cmra_extend n x y1 y2 : law_cmra_extend n x y1 y2 :
{n} x x {n} y1 y2 {n} x x {n} y1 y2
z1 z2, x z1 z2 z1 {n} y1 z2 {n} y2 z1 z2, x z1 z2 z1 {n} y1 z2 {n} y2
}. }.
(** Bundeled version *) Record cmra_mixin (A : Type) := CMRAMixin {
Structure cmraT := CMRAT' { cmra_mixin_equiv : Equiv A;
cmra_car :> Type; cmra_mixin_dist : Dist A;
cmra_equiv : Equiv cmra_car; cmra_mixin_pcore : PCore A;
cmra_dist : Dist cmra_car; cmra_mixin_op : Op A;
cmra_pcore : PCore cmra_car; cmra_mixin_valid : Valid A;
cmra_op : Op cmra_car; cmra_mixin_validN : ValidN A;
cmra_valid : Valid cmra_car; cmra_mixin_ofe_laws_of : ofe_laws A;
cmra_validN : ValidN cmra_car; cmra_mixin_laws_of : cmra_laws A;
cmra_ofe_mixin : OfeMixin cmra_car;
cmra_mixin : CMRAMixin cmra_car;
_ : Type
}. }.
Arguments CMRAT' _ {_ _ _ _ _ _} _ _ _. Arguments CMRAMixin {_ _ _ _ _ _ _} _ _.
Notation CMRAT A m m' := (CMRAT' A m m' A).
(** Bundeled version *)
Structure cmraT := CMRAT' { cmra_car :> Type; _ : cmra_mixin cmra_car; _ : Type }.
Notation CMRAT A m := (CMRAT' A m A).
Add Printing Constructor cmraT.
Arguments cmra_car : simpl never. Arguments cmra_car : simpl never.
Arguments cmra_equiv : simpl never.
Arguments cmra_dist : simpl never. Definition cmra_mixin_of (A : cmraT) : cmra_mixin A := let 'CMRAT' _ m _ := A in m.
Arguments cmra_mixin_of : simpl never.
Definition cmra_pcore {A : cmraT} : PCore A := cmra_mixin_pcore _ (cmra_mixin_of A).
Arguments cmra_pcore : simpl never. Arguments cmra_pcore : simpl never.
Arguments cmra_op : simpl never.
Arguments cmra_valid : simpl never.
Arguments cmra_validN : simpl never.
Arguments cmra_ofe_mixin : simpl never.
Arguments cmra_mixin : simpl never.
Add Printing Constructor cmraT.
Hint Extern 0 (PCore _) => eapply (@cmra_pcore _) : typeclass_instances. Hint Extern 0 (PCore _) => eapply (@cmra_pcore _) : typeclass_instances.
Definition cmra_op {A : cmraT} : Op A := cmra_mixin_op _ (cmra_mixin_of A).
Arguments cmra_op : simpl never.
Hint Extern 0 (Op _) => eapply (@cmra_op _) : typeclass_instances. Hint Extern 0 (Op _) => eapply (@cmra_op _) : typeclass_instances.
Definition cmra_valid {A : cmraT} : Valid A := cmra_mixin_valid _ (cmra_mixin_of A).
Arguments cmra_valid : simpl never.
Hint Extern 0 (Valid _) => eapply (@cmra_valid _) : typeclass_instances. Hint Extern 0 (Valid _) => eapply (@cmra_valid _) : typeclass_instances.
Definition cmra_validN {A : cmraT} : ValidN A := cmra_mixin_validN _ (cmra_mixin_of A).
Arguments cmra_validN : simpl never.
Hint Extern 0 (ValidN _) => eapply (@cmra_validN _) : typeclass_instances. Hint Extern 0 (ValidN _) => eapply (@cmra_validN _) : typeclass_instances.
Coercion cmra_ofeC (A : cmraT) : ofeT := OfeT A (cmra_ofe_mixin A).
Definition cmra_ofe_mixin_of {A} (m : cmra_mixin A) : ofe_mixin A :=
OfeMixin (cmra_mixin_ofe_laws_of _ m).
Coercion cmra_ofeC (A : cmraT) : ofeT :=
OfeT A (cmra_ofe_mixin_of (cmra_mixin_of A)).
Canonical Structure cmra_ofeC. Canonical Structure cmra_ofeC.
(** Lifting properties from the mixin *) (** Lifting properties from the mixin *)
Section cmra_mixin. Section cmra_mixin.
Context {A : cmraT}. Context {A : cmraT}.
Implicit Types x y : A. Implicit Types x y : A.
Local Coercion cmra_mixin_of : cmraT >-> cmra_mixin.
Global Instance cmra_op_ne (x : A) : NonExpansive (op x). Global Instance cmra_op_ne (x : A) : NonExpansive (op x).
Proof. apply (mixin_cmra_op_ne _ (cmra_mixin A)). Qed. Proof. apply (law_cmra_op_ne _ (cmra_mixin_laws_of _ A)). Qed.
Lemma cmra_pcore_ne n x y cx : Lemma cmra_pcore_ne n x y cx :
x {n} y pcore x = Some cx cy, pcore y = Some cy cx {n} cy. x {n} y pcore x = Some cx cy, pcore y = Some cy cx {n} cy.
Proof. apply (mixin_cmra_pcore_ne _ (cmra_mixin A)). Qed. Proof. apply (law_cmra_pcore_ne _ (cmra_mixin_laws_of _ A)). Qed.
Global Instance cmra_validN_ne n : Proper (dist n ==> impl) (@validN A _ n). Global Instance cmra_validN_ne n : Proper (dist n ==> impl) (@validN A _ n).
Proof. apply (mixin_cmra_validN_ne _ (cmra_mixin A)). Qed. Proof. apply (law_cmra_validN_ne _ (cmra_mixin_laws_of _ A)). Qed.
Lemma cmra_valid_validN x : x n, {n} x. Lemma cmra_valid_validN x : x n, {n} x.
Proof. apply (mixin_cmra_valid_validN _ (cmra_mixin A)). Qed. Proof. apply (law_cmra_valid_validN _ (cmra_mixin_laws_of _ A)). Qed.
Lemma cmra_validN_S n x : {S n} x {n} x. Lemma cmra_validN_S n x : {S n} x {n} x.
Proof. apply (mixin_cmra_validN_S _ (cmra_mixin A)). Qed. Proof. apply (law_cmra_validN_S _ (cmra_mixin_laws_of _ A)). Qed.
Global Instance cmra_assoc : Assoc () (@op A _). Global Instance cmra_assoc : Assoc () (@op A _).
Proof. apply (mixin_cmra_assoc _ (cmra_mixin A)). Qed. Proof. apply (law_cmra_assoc _ (cmra_mixin_laws_of _ A)). Qed.
Global Instance cmra_comm : Comm () (@op A _). Global Instance cmra_comm : Comm () (@op A _).
Proof. apply (mixin_cmra_comm _ (cmra_mixin A)). Qed. Proof. apply (law_cmra_comm _ (cmra_mixin_laws_of _ A)). Qed.
Lemma cmra_pcore_l x cx : pcore x = Some cx cx x x. Lemma cmra_pcore_l x cx : pcore x = Some cx cx x x.
Proof. apply (mixin_cmra_pcore_l _ (cmra_mixin A)). Qed. Proof. apply (law_cmra_pcore_l _ (cmra_mixin_laws_of _ A)). Qed.
Lemma cmra_pcore_idemp x cx : pcore x = Some cx pcore cx Some cx. Lemma cmra_pcore_idemp x cx : pcore x = Some cx pcore cx Some cx.
Proof. apply (mixin_cmra_pcore_idemp _ (cmra_mixin A)). Qed. Proof. apply (law_cmra_pcore_idemp _ (cmra_mixin_laws_of _ A)). Qed.
Lemma cmra_pcore_mono x y cx : Lemma cmra_pcore_mono x y cx :
x y pcore x = Some cx cy, pcore y = Some cy cx cy. x y pcore x = Some cx cy, pcore y = Some cy cx cy.
Proof. apply (mixin_cmra_pcore_mono _ (cmra_mixin A)). Qed. Proof. apply (law_cmra_pcore_mono _ (cmra_mixin_laws_of _ A)). Qed.
Lemma cmra_validN_op_l n x y : {n} (x y) {n} x. Lemma cmra_validN_op_l n x y : {n} (x y) {n} x.
Proof. apply (mixin_cmra_validN_op_l _ (cmra_mixin A)). Qed. Proof. apply (law_cmra_validN_op_l _ (cmra_mixin_laws_of _ A)). Qed.
Lemma cmra_extend n x y1 y2 : Lemma cmra_extend n x y1 y2 :
{n} x x {n} y1 y2 {n} x x {n} y1 y2
z1 z2, x z1 z2 z1 {n} y1 z2 {n} y2. z1 z2, x z1 z2 z1 {n} y1 z2 {n} y2.
Proof. apply (mixin_cmra_extend _ (cmra_mixin A)). Qed. Proof. apply (law_cmra_extend _ (cmra_mixin_laws_of _ A)). Qed.
End cmra_mixin. End cmra_mixin.
Definition opM {A : cmraT} (x : A) (my : option A) := Definition opM {A : cmraT} (x : A) (my : option A) :=
...@@ -163,56 +172,66 @@ Arguments core' _ _ _ /. ...@@ -163,56 +172,66 @@ Arguments core' _ _ _ /.
(** * CMRAs with a unit element *) (** * CMRAs with a unit element *)
(** We use the notation ∅ because for most instances (maps, sets, etc) the (** We use the notation ∅ because for most instances (maps, sets, etc) the
`empty' element is the unit. *) `empty' element is the unit. *)
Record UCMRAMixin A `{Dist A, Equiv A, PCore A, Op A, Valid A, Empty A} := { Record ucmra_laws A `{Dist A, Equiv A, PCore A, Op A, Valid A, Empty A} := {
mixin_ucmra_unit_valid : ; mixin_ucmra_unit_valid : ;
mixin_ucmra_unit_left_id : LeftId () (); mixin_ucmra_unit_left_id : LeftId () ();
mixin_ucmra_pcore_unit : pcore Some mixin_ucmra_pcore_unit : pcore Some
}. }.
Structure ucmraT := UCMRAT' { Record ucmra_mixin (A : Type) := UCMRAMixin {
ucmra_car :> Type; ucmra_mixin_equiv : Equiv A;
ucmra_equiv : Equiv ucmra_car; ucmra_mixin_dist : Dist A;
ucmra_dist : Dist ucmra_car; ucmra_mixin_pcore : PCore A;
ucmra_pcore : PCore ucmra_car; ucmra_mixin_op : Op A;
ucmra_op : Op ucmra_car; ucmra_mixin_valid : Valid A;
ucmra_valid : Valid ucmra_car; ucmra_mixin_validN : ValidN A;
ucmra_validN : ValidN ucmra_car; ucmra_mixin_empty : Empty A;
ucmra_empty : Empty ucmra_car; ucmra_mixin_ofe_laws_of : ofe_laws A;
ucmra_ofe_mixin : OfeMixin ucmra_car; ucmra_mixin_cmra_laws_of : cmra_laws A;
ucmra_cmra_mixin : CMRAMixin ucmra_car; ucmra_mixin_laws_of : ucmra_laws A;
ucmra_mixin : UCMRAMixin ucmra_car;
_ : Type;
}. }.
Arguments UCMRAT' _ {_ _ _ _ _ _ _} _ _ _ _. Arguments UCMRAMixin {_ _ _ _ _ _ _ _} _ _ _.
Notation UCMRAT A m m' m'' := (UCMRAT' A m m' m'' A).
Arguments ucmra_car : simpl never. Structure ucmraT :=
Arguments ucmra_equiv : simpl never. UCMRAT' { ucmra_car :> Type; _ : ucmra_mixin ucmra_car; _ : Type }.
Arguments ucmra_dist : simpl never. Notation UCMRAT A m := (UCMRAT' A m A).
Arguments ucmra_pcore : simpl never.
Arguments ucmra_op : simpl never.
Arguments ucmra_valid : simpl never.
Arguments ucmra_validN : simpl never.
Arguments ucmra_ofe_mixin : simpl never.
Arguments ucmra_cmra_mixin : simpl never.
Arguments ucmra_mixin : simpl never.
Add Printing Constructor ucmraT. Add Printing Constructor ucmraT.
Arguments ucmra_car : simpl never.
Definition ucmra_mixin_of (A : ucmraT) : ucmra_mixin A :=
let 'UCMRAT' _ m _ := A in m.
Arguments ucmra_mixin_of : simpl never.
Definition ucmra_empty {A : ucmraT} : Empty A :=
ucmra_mixin_empty _ (ucmra_mixin_of A).
Arguments ucmra_empty : simpl never.
Hint Extern 0 (Empty _) => eapply (@ucmra_empty _) : typeclass_instances. Hint Extern 0 (Empty _) => eapply (@ucmra_empty _) : typeclass_instances.
Coercion ucmra_ofeC (A : ucmraT) : ofeT := OfeT A (ucmra_ofe_mixin A).
Definition ucmra_ofe_mixin_of {A} (m : ucmra_mixin A) : ofe_mixin A :=
OfeMixin (ucmra_mixin_ofe_laws_of _ m).
Definition ucmra_cmra_mixin_of {A} (m : ucmra_mixin A) : cmra_mixin A :=
CMRAMixin (ucmra_mixin_ofe_laws_of _ m) (ucmra_mixin_cmra_laws_of _ m).
Arguments ucmra_ofe_mixin_of : simpl never.
Arguments ucmra_cmra_mixin_of : simpl never.
Coercion ucmra_ofeC (A : ucmraT) : ofeT :=
OfeT A (ucmra_ofe_mixin_of (ucmra_mixin_of A)).
Canonical Structure ucmra_ofeC. Canonical Structure ucmra_ofeC.
Coercion ucmra_cmraR (A : ucmraT) : cmraT := Coercion ucmra_cmraR (A : ucmraT) : cmraT :=
CMRAT A (ucmra_ofe_mixin A) (ucmra_cmra_mixin A). CMRAT A (ucmra_cmra_mixin_of (ucmra_mixin_of A)).
Canonical Structure ucmra_cmraR. Canonical Structure ucmra_cmraR.
(** Lifting properties from the mixin *) (** Lifting properties from the mixin *)
Section ucmra_mixin. Section ucmra_mixin.
Context {A : ucmraT}. Context {A : ucmraT}.
Implicit Types x y : A. Implicit Types x y : A.
Local Coercion ucmra_mixin_of : ucmraT >-> ucmra_mixin.
Lemma ucmra_unit_valid : ( : A). Lemma ucmra_unit_valid : ( : A).
Proof. apply (mixin_ucmra_unit_valid _ (ucmra_mixin A)). Qed. Proof. apply (mixin_ucmra_unit_valid _ (ucmra_mixin_laws_of _ A)). Qed.
Global Instance ucmra_unit_left_id : LeftId () (@op A _). Global Instance ucmra_unit_left_id : LeftId () (@op A _).
Proof. apply (mixin_ucmra_unit_left_id _ (ucmra_mixin A)). Qed. Proof. apply (mixin_ucmra_unit_left_id _ (ucmra_mixin_laws_of _ A)). Qed.
Lemma ucmra_pcore_unit : pcore (:A) Some . Lemma ucmra_pcore_unit : pcore (:A) Some .
Proof. apply (mixin_ucmra_pcore_unit _ (ucmra_mixin A)). Qed. Proof. apply (mixin_ucmra_pcore_unit _ (ucmra_mixin_laws_of _ A)). Qed.
End ucmra_mixin. End ucmra_mixin.
(** * Discrete CMRAs *) (** * Discrete CMRAs *)
...@@ -698,7 +717,7 @@ Section cmra_total. ...@@ -698,7 +717,7 @@ Section cmra_total.
Context (extend : n (x y1 y2 : A), Context (extend : n (x y1 y2 : A),
{n} x x {n} y1 y2 {n} x x {n} y1 y2
z1 z2, x z1 z2 z1 {n} y1 z2 {n} y2). z1 z2, x z1 z2 z1 {n} y1 z2 {n} y2).
Lemma cmra_total_mixin : CMRAMixin A. Lemma cmra_total_laws : cmra_laws A.
Proof using Type*. Proof using Type*.
split; auto. split; auto.
- intros n x y ? Hcx%core_ne Hx; move: Hcx. rewrite /core /= Hx /=. - intros n x y ? Hcx%core_ne Hx; move: Hcx. rewrite /core /= Hx /=.
...@@ -850,7 +869,7 @@ End cmra_transport. ...@@ -850,7 +869,7 @@ End cmra_transport.
(** * Instances *) (** * Instances *)
(** ** Discrete CMRA *) (** ** Discrete CMRA *)
Record RAMixin A `{Equiv A, PCore A, Op A, Valid A} := { Record ra_laws A `{Equiv A, PCore A, Op A, Valid A} := {
(* setoids *) (* setoids *)
ra_op_proper (x : A) : Proper (() ==> ()) (op x); ra_op_proper (x : A) : Proper (() ==> ()) (op x);
ra_core_proper x y cx : ra_core_proper x y cx :
...@@ -869,18 +888,19 @@ Record RAMixin A `{Equiv A, PCore A, Op A, Valid A} := { ...@@ -869,18 +888,19 @@ Record RAMixin A `{Equiv A, PCore A, Op A, Valid A} := {
Section discrete. Section discrete.
Local Set Default Proof Using "Type*". Local Set Default Proof Using "Type*".
Context `{Equiv A, PCore A, Op A, Valid A, @Equivalence A ()}. Context `{Equiv A, PCore A, Op A, Valid A, @Equivalence A ()}.
Context (ra_mix : RAMixin A). Context (laws : ra_laws A).
Existing Instances discrete_dist. Existing Instances discrete_dist.
Instance discrete_validN : ValidN A := λ n x, x. Instance discrete_validN : ValidN A := λ n x, x.
Definition discrete_cmra_mixin : CMRAMixin A. Definition discrete_cmra_laws : cmra_laws A.
Proof. Proof.
destruct ra_mix; split; try done. destruct laws; split; try done.
- intros x; split; first done. by move=> /(_ 0). - intros x; split; first done. by move=> /(_ 0).
- intros n x y1 y2 ??; by exists y1, y2. - intros n x y1 y2 ??; by exists y1, y2.
Qed. Qed.
End discrete. End discrete.
(*
Notation discreteR A ra_mix := Notation discreteR A ra_mix :=
(CMRAT A discrete_ofe_mixin (discrete_cmra_mixin ra_mix)). (CMRAT A discrete_ofe_mixin (discrete_cmra_mixin ra_mix)).
Notation discreteUR A ra_mix ucmra_mix := Notation discreteUR A ra_mix ucmra_mix :=
...@@ -889,7 +909,7 @@ Notation discreteUR A ra_mix ucmra_mix := ...@@ -889,7 +909,7 @@ Notation discreteUR A ra_mix ucmra_mix :=
Global Instance discrete_cmra_discrete `{Equiv A, PCore A, Op A, Valid A, Global Instance discrete_cmra_discrete `{Equiv A, PCore A, Op A, Valid A,
@Equivalence A (≡)} (ra_mix : RAMixin A) : CMRADiscrete (discreteR A ra_mix). @Equivalence A (≡)} (ra_mix : RAMixin A) : CMRADiscrete (discreteR A ra_mix).
Proof. split. apply _. done. Qed. Proof. split. apply _. done. Qed.
*)
Section ra_total. Section ra_total.
Local Set Default Proof Using "Type*". Local Set Default Proof Using "Type*".
Context A `{Equiv A, PCore A, Op A, Valid A}. Context A `{Equiv A, PCore A, Op A, Valid A}.
...@@ -903,7 +923,7 @@ Section ra_total. ...@@ -903,7 +923,7 @@ Section ra_total.
Context (core_idemp : x : A, core (core x) core x). Context (core_idemp : x : A, core (core x) core x).
Context (core_mono : x y : A, x y core x core y). Context (core_mono : x y : A, x y core x core y).
Context (valid_op_l : x y : A, (x y) x). Context (valid_op_l : x y : A, (x y) x).
Lemma ra_total_mixin : RAMixin A. Lemma ra_total_laws : ra_laws A.
Proof. Proof.
split; auto. split; auto.
- intros x y ? Hcx%core_proper Hx; move: Hcx. rewrite /core /= Hx /=. - intros x y ? Hcx%core_proper Hx; move: Hcx. rewrite /core /= Hx /=.
...@@ -922,15 +942,17 @@ Section unit. ...@@ -922,15 +942,17 @@ Section unit.
Instance unit_validN : ValidN () := λ n x, True. Instance unit_validN : ValidN () := λ n x, True.
Instance unit_pcore : PCore () := λ x, Some x. Instance unit_pcore : PCore () := λ x, Some x.
Instance unit_op : Op () := λ x y, (). Instance unit_op : Op () := λ x y, ().
Lemma unit_cmra_mixin : CMRAMixin (). Lemma unit_cmra_laws : cmra_laws ().
Proof. apply discrete_cmra_mixin, ra_total_mixin; by eauto. Qed. Proof. apply discrete_cmra_laws, ra_total_laws; by eauto. Qed.
Canonical Structure unitR : cmraT := CMRAT () unit_ofe_mixin unit_cmra_mixin. Definition unit_cmra_mixin := CMRAMixin unit_ofe_laws unit_cmra_laws.
Canonical Structure unitR : cmraT := CMRAT () unit_cmra_mixin.
Instance unit_empty : Empty () := (). Instance unit_empty : Empty () := ().
Lemma unit_ucmra_mixin : UCMRAMixin (). Lemma unit_ucmra_laws : ucmra_laws ().
Proof. done. Qed. Proof. done. Qed.
Canonical Structure unitUR : ucmraT := Definition unit_ucmra_mixin :=
UCMRAT () unit_ofe_mixin unit_cmra_mixin unit_ucmra_mixin. UCMRAMixin unit_ofe_laws unit_cmra_laws unit_ucmra_laws.
Canonical Structure unitUR : ucmraT := UCMRAT () unit_ucmra_mixin.
Global Instance unit_cmra_discrete : CMRADiscrete unitR. Global Instance unit_cmra_discrete : CMRADiscrete unitR.
Proof. done. Qed. Proof. done. Qed.
...@@ -953,31 +975,35 @@ Section nat. ...@@ -953,31 +975,35 @@ Section nat.
- intros [z ->]; unfold op, nat_op; lia. - intros [z ->]; unfold op, nat_op; lia.
- exists (y - x). by apply le_plus_minus. - exists (y - x). by apply le_plus_minus.
Qed. Qed.
Lemma nat_ra_mixin : RAMixin nat. Lemma nat_ra_laws : ra_laws nat.
Proof. Proof.
apply ra_total_mixin; try by eauto. apply ra_total_laws; try by eauto.
- solve_proper. - solve_proper.
- intros x y z. apply Nat.add_assoc. - intros x y z. apply Nat.add_assoc.
- intros x y. apply Nat.add_comm. - intros x y. apply Nat.add_comm.
- by exists 0. - by exists 0.
Qed. Qed.
(*
Definition nat_cmra_mixin := CMRAMixin unit_ofe_laws unit_cmra_laws.
Canonical Structure natR : cmraT := discreteR nat nat_ra_mixin. Canonical Structure natR : cmraT := discreteR nat nat_ra_mixin.
*)
Instance nat_empty : Empty nat := 0. Instance nat_empty : Empty nat := 0.
Lemma nat_ucmra_mixin : UCMRAMixin nat. Lemma nat_ucmra_laws : ucmra_laws nat.
Proof. split; apply _ || done. Qed. Proof. split; apply _ || done. Qed.
(*
Canonical Structure natUR : ucmraT := Canonical Structure natUR : ucmraT :=
discreteUR nat nat_ra_mixin nat_ucmra_mixin. discreteUR nat nat_ra_mixin nat_ucmra_mixin.
Global Instance nat_cmra_discrete : CMRADiscrete natR. Global Instance nat_cmra_discrete : CMRADiscrete natR.
Proof. constructor; apply _ || done. Qed. Proof. constructor; apply _ || done. Qed.
Global Instance nat_cancelable (x : nat) : Cancelable x. Global Instance nat_cancelable (x : nat) : Cancelable x.
Proof. by intros ???? ?%Nat.add_cancel_l. Qed. Proof. by intros ???? ?%Nat.add_cancel_l. Qed.
*)
End nat. End nat.
Definition mnat := nat. Definition mnat := nat.
(*
Section mnat. Section mnat.
Instance mnat_valid : Valid mnat := λ x, True. Instance mnat_valid : Valid mnat := λ x, True.
Instance mnat_validN : ValidN mnat := λ n x, True. Instance mnat_validN : ValidN mnat := λ n x, True.
...@@ -1045,6 +1071,7 @@ Section positive. ...@@ -1045,6 +1071,7 @@ Section positive.
by apply leibniz_equiv. by apply leibniz_equiv.
Qed. Qed.
End positive. End positive.
*)
(** ** Product *) (** ** Product *)
Section prod. Section prod.
...@@ -1082,7 +1109,7 @@ Section prod. ...@@ -1082,7 +1109,7 @@ Section prod.
intros [[z1 Hz1] [z2 Hz2]]; exists (z1,z2); split; auto. intros [[z1 Hz1] [z2 Hz2]]; exists (z1,z2); split; auto.
Qed. Qed.
Definition prod_cmra_mixin : CMRAMixin (A * B). Definition prod_cmra_laws : cmra_laws (A * B).
Proof. Proof.
split; try apply _. split; try apply _.
- by intros n x y1 y2 [Hy1 Hy2]; split; rewrite /= ?Hy1 ?Hy2. - by intros n x y1 y2 [Hy1 Hy2]; split; rewrite /= ?Hy1 ?Hy2.
...@@ -1111,8 +1138,8 @@ Section prod. ...@@ -1111,8 +1138,8 @@ Section prod.
destruct (cmra_extend n (x.2) (y1.2) (y2.2)) as (z21&z22&?&?&?); auto. destruct (cmra_extend n (x.2) (y1.2) (y2.2)) as (z21&z22&?&?&?); auto.
by exists (z11,z21), (z12,z22). by exists (z11,z21), (z12,z22).
Qed. Qed.
Canonical Structure prodR := Definition prod_cmra_mixin := CMRAMixin prod_ofe_laws prod_cmra_laws.
CMRAT (A * B) prod_ofe_mixin prod_cmra_mixin. Canonical Structure prodR := CMRAT (A * B) prod_cmra_mixin.
Lemma pair_op (a a' : A) (b b' : B) : (a, b) (a', b') = (a a', b b'). Lemma pair_op (a a' : A) (b b' : B) : (a, b) (a', b') = (a a', b b').
Proof. done. Qed. Proof. done. Qed.
...@@ -1152,15 +1179,16 @@ Section prod_unit. ...@@ -1152,15 +1179,16 @@ Section prod_unit.
Context {A B : ucmraT}. Context {A B : ucmraT}.
Instance prod_empty `{Empty A, Empty B} : Empty (A * B) := (, ). Instance prod_empty `{Empty A, Empty B} : Empty (A * B) := (, ).
Lemma prod_ucmra_mixin : UCMRAMixin (A * B). Lemma prod_ucmra_laws : ucmra_laws (A * B).
Proof. Proof.
split. split.
- split; apply ucmra_unit_valid. - split; apply ucmra_unit_valid.
- by split; rewrite /=left_id. - by split; rewrite /=left_id.
- rewrite prod_pcore_Some'; split; apply (persistent _). - rewrite prod_pcore_Some'; split; apply (persistent _).
Qed. Qed.
Canonical Structure prodUR := Definition prod_ucmra_mixin :=
UCMRAT (A * B) prod_ofe_mixin prod_cmra_mixin prod_ucmra_mixin. UCMRAMixin prod_ofe_laws prod_cmra_laws prod_ucmra_laws.