Skip to content
Snippets Groups Projects
Commit ca3da7ca authored by Robbert Krebbers's avatar Robbert Krebbers
Browse files

Simplify CMRAMonotone.

It now also contains a non-expansiveness proof.
parent c2725b24
No related branches found
No related tags found
No related merge requests found
...@@ -97,11 +97,6 @@ Proof. ...@@ -97,11 +97,6 @@ Proof.
split; [|by intros ?; exists y]. split; [|by intros ?; exists y].
by intros [z Hz]; rewrite Hz assoc agree_idemp. by intros [z Hz]; rewrite Hz assoc agree_idemp.
Qed. Qed.
Lemma agree_includedN n (x y : agree A) : x {n} y y {n} x y.
Proof.
split; [|by intros ?; exists y].
by intros [z Hz]; rewrite Hz assoc agree_idemp.
Qed.
Lemma agree_op_inv n (x1 x2 : agree A) : {n} (x1 x2) x1 {n} x2. Lemma agree_op_inv n (x1 x2 : agree A) : {n} (x1 x2) x1 {n} x2.
Proof. intros Hxy; apply Hxy. Qed. Proof. intros Hxy; apply Hxy. Qed.
Lemma agree_valid_includedN n (x y : agree A) : {n} y x {n} y x {n} y. Lemma agree_valid_includedN n (x y : agree A) : {n} y x {n} y x {n} y.
...@@ -160,20 +155,20 @@ Proof. done. Qed. ...@@ -160,20 +155,20 @@ Proof. done. Qed.
Section agree_map. Section agree_map.
Context {A B : cofeT} (f : A B) `{Hf: n, Proper (dist n ==> dist n) f}. Context {A B : cofeT} (f : A B) `{Hf: n, Proper (dist n ==> dist n) f}.
Global Instance agree_map_ne n : Proper (dist n ==> dist n) (agree_map f). Instance agree_map_ne n : Proper (dist n ==> dist n) (agree_map f).
Proof. by intros x1 x2 Hx; split; simpl; intros; [apply Hx|apply Hf, Hx]. Qed. Proof. by intros x1 x2 Hx; split; simpl; intros; [apply Hx|apply Hf, Hx]. Qed.
Global Instance agree_map_proper : Instance agree_map_proper : Proper (() ==> ()) (agree_map f) := ne_proper _.
Proper (() ==> ()) (agree_map f) := ne_proper _.
Lemma agree_map_ext (g : A B) x : Lemma agree_map_ext (g : A B) x :
( x, f x g x) agree_map f x agree_map g x. ( x, f x g x) agree_map f x agree_map g x.
Proof. by intros Hfg; split; simpl; intros; rewrite ?Hfg. Qed. Proof. by intros Hfg; split; simpl; intros; rewrite ?Hfg. Qed.
Global Instance agree_map_monotone : CMRAMonotone (agree_map f). Global Instance agree_map_monotone : CMRAMonotone (agree_map f).
Proof. Proof.
split; [|by intros n x [? Hx]; split; simpl; [|by intros n' ?; rewrite Hx]]. split; first apply _.
intros n x y; rewrite !agree_includedN; intros Hy; rewrite Hy. - by intros n x [? Hx]; split; simpl; [|by intros n' ?; rewrite Hx].
split; last done; split; simpl; last tauto. - intros x y; rewrite !agree_included=> ->.
by intros (?&?&Hxy); repeat split; intros; split; last done; split; simpl; last tauto.
try apply Hxy; try apply Hf; eauto using @agree_valid_le. by intros (?&?&Hxy); repeat split; intros;
try apply Hxy; try apply Hf; eauto using @agree_valid_le.
Qed. Qed.
End agree_map. End agree_map.
......
...@@ -98,12 +98,6 @@ Proof. ...@@ -98,12 +98,6 @@ Proof.
split; [intros [[z1 z2] Hz]; split; [exists z1|exists z2]; apply Hz|]. split; [intros [[z1 z2] Hz]; split; [exists z1|exists z2]; apply Hz|].
intros [[z1 Hz1] [z2 Hz2]]; exists (Auth z1 z2); split; auto. intros [[z1 Hz1] [z2 Hz2]]; exists (Auth z1 z2); split; auto.
Qed. Qed.
Lemma auth_includedN n (x y : auth A) :
x {n} y authoritative x {n} authoritative y own x {n} own y.
Proof.
split; [intros [[z1 z2] Hz]; split; [exists z1|exists z2]; apply Hz|].
intros [[z1 Hz1] [z2 Hz2]]; exists (Auth z1 z2); split; auto.
Qed.
Lemma authoritative_validN n (x : auth A) : {n} x {n} authoritative x. Lemma authoritative_validN n (x : auth A) : {n} x {n} authoritative x.
Proof. by destruct x as [[]]. Qed. 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.
...@@ -212,7 +206,6 @@ Proof. ...@@ -212,7 +206,6 @@ Proof.
intros. apply auth_update=>n af ? EQ; split; last by apply cmra_valid_validN. intros. apply auth_update=>n af ? EQ; split; last by apply cmra_valid_validN.
by rewrite -(local_updateN L) // EQ -(local_updateN L) // -EQ. by rewrite -(local_updateN L) // EQ -(local_updateN L) // -EQ.
Qed. Qed.
End cmra. End cmra.
Arguments authRA : clear implicits. Arguments authRA : clear implicits.
...@@ -234,14 +227,13 @@ Proof. ...@@ -234,14 +227,13 @@ 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 : cmraT} (f : A B) :
( n, Proper (dist n ==> dist n) f)
CMRAMonotone f CMRAMonotone (auth_map f). CMRAMonotone f CMRAMonotone (auth_map f).
Proof. Proof.
split. split; try apply _.
- by intros n [x a] [y b]; rewrite !auth_includedN /=; - intros n [[a| |] b]; rewrite /= /cmra_validN /=; try
intros [??]; split; simpl; apply: includedN_preserving. naive_solver eauto using includedN_preserving, validN_preserving.
- intros n [[a| |] b]; rewrite /= /cmra_validN; - by intros [x a] [y b]; rewrite !auth_included /=;
naive_solver eauto using @includedN_preserving, @validN_preserving. intros [??]; split; simpl; apply: included_preserving.
Qed. Qed.
Definition authC_map {A B} (f : A -n> B) : authC A -n> authC B := Definition authC_map {A B} (f : A -n> B) : authC A -n> authC B :=
CofeMor (auth_map f). CofeMor (auth_map f).
......
...@@ -142,8 +142,9 @@ Class CMRADiscrete (A : cmraT) : Prop := { ...@@ -142,8 +142,9 @@ Class CMRADiscrete (A : cmraT) : Prop := {
(** * Morphisms *) (** * Morphisms *)
Class CMRAMonotone {A B : cmraT} (f : A B) := { Class CMRAMonotone {A B : cmraT} (f : A B) := {
includedN_preserving n x y : x {n} y f x {n} f y; cmra_monotone_ne n :> Proper (dist n ==> dist n) f;
validN_preserving n x : {n} x {n} f x validN_preserving n x : {n} x {n} f x;
included_preserving x y : x y f x f y
}. }.
(** * Local updates *) (** * Local updates *)
...@@ -430,26 +431,28 @@ End cmra. ...@@ -430,26 +431,28 @@ End cmra.
(** * Properties about monotone functions *) (** * Properties about monotone functions *)
Instance cmra_monotone_id {A : cmraT} : CMRAMonotone (@id A). Instance cmra_monotone_id {A : cmraT} : CMRAMonotone (@id A).
Proof. by split. Qed. Proof. repeat split; by try apply _. Qed.
Instance cmra_monotone_compose {A B C : cmraT} (f : A B) (g : B C) : Instance cmra_monotone_compose {A B C : cmraT} (f : A B) (g : B C) :
CMRAMonotone f CMRAMonotone g CMRAMonotone (g f). CMRAMonotone f CMRAMonotone g CMRAMonotone (g f).
Proof. Proof.
split. split.
- move=> n x y Hxy /=. by apply includedN_preserving, includedN_preserving. - apply _.
- move=> n x Hx /=. by apply validN_preserving, validN_preserving. - move=> n x Hx /=. by apply validN_preserving, validN_preserving.
- move=> x y Hxy /=. by apply included_preserving, included_preserving.
Qed. Qed.
Section cmra_monotone. Section cmra_monotone.
Context {A B : cmraT} (f : A B) `{!CMRAMonotone f}. Context {A B : cmraT} (f : A B) `{!CMRAMonotone f}.
Lemma included_preserving x y : x y f x f y. Global Instance cmra_monotone_proper : Proper (() ==> ()) f := ne_proper _.
Lemma includedN_preserving n x y : x {n} y f x {n} f y.
Proof. Proof.
rewrite !cmra_included_includedN; eauto using includedN_preserving. intros [z ->].
apply cmra_included_includedN, included_preserving, cmra_included_l.
Qed. Qed.
Lemma valid_preserving x : x f x. Lemma valid_preserving x : x f x.
Proof. rewrite !cmra_valid_validN; eauto using validN_preserving. Qed. Proof. rewrite !cmra_valid_validN; eauto using validN_preserving. Qed.
End cmra_monotone. End cmra_monotone.
(** * Transporting a CMRA equality *) (** * Transporting a CMRA equality *)
Definition cmra_transport {A B : cmraT} (H : A = B) (x : A) : B := Definition cmra_transport {A B : cmraT} (H : A = B) (x : A) : B :=
eq_rect A id x _ H. eq_rect A id x _ H.
...@@ -607,8 +610,8 @@ Arguments prodRA : clear implicits. ...@@ -607,8 +610,8 @@ Arguments prodRA : clear implicits.
Instance prod_map_cmra_monotone {A A' B B' : cmraT} (f : A A') (g : B B') : Instance prod_map_cmra_monotone {A A' B B' : cmraT} (f : A A') (g : B B') :
CMRAMonotone f CMRAMonotone g CMRAMonotone (prod_map f g). CMRAMonotone f CMRAMonotone g CMRAMonotone (prod_map f g).
Proof. Proof.
split. split; first apply _.
- intros n x y; rewrite !prod_includedN; intros [??]; simpl.
by split; apply includedN_preserving.
- by intros n x [??]; split; simpl; apply validN_preserving. - by intros n x [??]; split; simpl; apply validN_preserving.
- intros x y; rewrite !prod_included=> -[??] /=.
by split; apply included_preserving.
Qed. Qed.
...@@ -27,6 +27,7 @@ Inductive excl_dist : Dist (excl A) := ...@@ -27,6 +27,7 @@ Inductive excl_dist : Dist (excl A) :=
| ExclUnit_dist n : ExclUnit {n} ExclUnit | ExclUnit_dist n : ExclUnit {n} ExclUnit
| ExclBot_dist n : ExclBot {n} ExclBot. | ExclBot_dist n : ExclBot {n} ExclBot.
Existing Instance excl_dist. Existing Instance excl_dist.
Global Instance Excl_ne n : Proper (dist n ==> dist n) (@Excl A). Global Instance Excl_ne n : Proper (dist n ==> dist n) (@Excl A).
Proof. by constructor. Qed. Proof. by constructor. Qed.
Global Instance Excl_proper : Proper (() ==> ()) (@Excl A). Global Instance Excl_proper : Proper (() ==> ()) (@Excl A).
...@@ -35,6 +36,7 @@ Global Instance Excl_inj : Inj (≡) (≡) (@Excl A). ...@@ -35,6 +36,7 @@ Global Instance Excl_inj : Inj (≡) (≡) (@Excl A).
Proof. by inversion_clear 1. Qed. Proof. by inversion_clear 1. Qed.
Global Instance Excl_dist_inj n : Inj (dist n) (dist n) (@Excl A). Global Instance Excl_dist_inj n : Inj (dist n) (dist n) (@Excl A).
Proof. by inversion_clear 1. Qed. Proof. by inversion_clear 1. Qed.
Program Definition excl_chain Program Definition excl_chain
(c : chain (excl A)) (x : A) (H : maybe Excl (c 1) = Some x) : chain A := (c : chain (excl A)) (x : A) (H : maybe Excl (c 1) = Some x) : chain A :=
{| chain_car n := match c n return _ with Excl y => y | _ => x end |}. {| chain_car n := match c n return _ with Excl y => y | _ => x end |}.
...@@ -191,10 +193,10 @@ Proof. by intros f f' Hf; destruct 1; constructor; apply Hf. Qed. ...@@ -191,10 +193,10 @@ Proof. by intros f f' Hf; destruct 1; constructor; apply Hf. Qed.
Instance excl_map_cmra_monotone {A B : cofeT} (f : A B) : Instance excl_map_cmra_monotone {A B : cofeT} (f : A B) :
( n, Proper (dist n ==> dist n) f) CMRAMonotone (excl_map f). ( n, Proper (dist n ==> dist n) f) CMRAMonotone (excl_map f).
Proof. Proof.
split. split; try apply _.
- intros n x y [z Hy]; exists (excl_map f z); rewrite Hy.
by destruct x, z; constructor.
- by intros n [a| |]. - by intros n [a| |].
- intros x y [z Hy]; exists (excl_map f z); apply equiv_dist=> n.
move: Hy=> /equiv_dist /(_ n) ->; by destruct x, z.
Qed. Qed.
Definition exclC_map {A B} (f : A -n> B) : exclC A -n> exclC B := Definition exclC_map {A B} (f : A -n> B) : exclC A -n> exclC B :=
CofeMor (excl_map f). CofeMor (excl_map f).
......
...@@ -231,8 +231,8 @@ Proof. ...@@ -231,8 +231,8 @@ Proof.
[exists (x y)|exists x]; eauto using cmra_included_l. [exists (x y)|exists x]; eauto using cmra_included_l.
- intros (y&Hi&?); rewrite map_includedN_spec=>j. - intros (y&Hi&?); rewrite map_includedN_spec=>j.
destruct (decide (i = j)); simplify_map_eq. destruct (decide (i = j)); simplify_map_eq.
+ by rewrite Hi; apply Some_Some_includedN, cmra_included_includedN. + rewrite Hi. by apply (includedN_preserving _), cmra_included_includedN.
+ apply None_includedN. + apply: cmra_empty_leastN.
Qed. Qed.
Lemma map_dom_op m1 m2 : dom (gset K) (m1 m2) dom _ m1 dom _ m2. Lemma map_dom_op m1 m2 : dom (gset K) (m1 m2) dom _ m1 dom _ m2.
Proof. Proof.
...@@ -338,10 +338,10 @@ Proof. by intros ? m m' Hm k; rewrite !lookup_fmap; apply option_fmap_ne. Qed. ...@@ -338,10 +338,10 @@ Proof. by intros ? m m' Hm k; rewrite !lookup_fmap; apply option_fmap_ne. Qed.
Instance map_fmap_cmra_monotone `{Countable K} {A B : cmraT} (f : A B) Instance map_fmap_cmra_monotone `{Countable K} {A B : cmraT} (f : A B)
`{!CMRAMonotone f} : CMRAMonotone (fmap f : gmap K A gmap K B). `{!CMRAMonotone f} : CMRAMonotone (fmap f : gmap K A gmap K B).
Proof. Proof.
split. split; try apply _.
- intros m1 m2 n; rewrite !map_includedN_spec; intros Hm i.
by rewrite !lookup_fmap; apply: includedN_preserving.
- by intros n m ? i; rewrite lookup_fmap; apply validN_preserving. - by intros n m ? i; rewrite lookup_fmap; apply validN_preserving.
- intros m1 m2; rewrite !map_included_spec=> Hm i.
by rewrite !lookup_fmap; apply: included_preserving.
Qed. Qed.
Definition mapC_map `{Countable K} {A B} (f: A -n> B) : mapC K A -n> mapC K B := Definition mapC_map `{Countable K} {A B} (f: A -n> B) : mapC K A -n> mapC K B :=
CofeMor (fmap f : mapC K A mapC K B). CofeMor (fmap f : mapC K A mapC K B).
......
...@@ -133,13 +133,6 @@ Section iprod_cmra. ...@@ -133,13 +133,6 @@ Section iprod_cmra.
- intros Hh; exists (g f)=> x; specialize (Hh x). - intros Hh; exists (g f)=> x; specialize (Hh x).
by rewrite /op /iprod_op /minus /iprod_minus cmra_op_minus. by rewrite /op /iprod_op /minus /iprod_minus cmra_op_minus.
Qed. Qed.
Lemma iprod_includedN_spec n (f g : iprod B) : f {n} g x, f x {n} g x.
Proof.
split.
- by intros [h Hh] x; exists (h x); rewrite /op /iprod_op (Hh x).
- intros Hh; exists (g f)=> x; specialize (Hh x).
by rewrite /op /iprod_op /minus /iprod_minus cmra_op_minus'.
Qed.
Definition iprod_cmra_mixin : CMRAMixin (iprod B). Definition iprod_cmra_mixin : CMRAMixin (iprod B).
Proof. Proof.
...@@ -283,10 +276,10 @@ Proof. by intros ? y1 y2 Hy x; rewrite /iprod_map (Hy x). Qed. ...@@ -283,10 +276,10 @@ Proof. by intros ? y1 y2 Hy x; rewrite /iprod_map (Hy x). Qed.
Instance iprod_map_cmra_monotone {A} {B1 B2: A cmraT} (f : x, B1 x B2 x) : Instance iprod_map_cmra_monotone {A} {B1 B2: A cmraT} (f : x, B1 x B2 x) :
( x, CMRAMonotone (f x)) CMRAMonotone (iprod_map f). ( x, CMRAMonotone (f x)) CMRAMonotone (iprod_map f).
Proof. Proof.
split. split; first apply _.
- intros n g1 g2; rewrite !iprod_includedN_spec=> Hf x.
rewrite /iprod_map; apply includedN_preserving, Hf.
- intros n g Hg x; rewrite /iprod_map; apply validN_preserving, Hg. - intros n g Hg x; rewrite /iprod_map; apply validN_preserving, Hg.
- intros g1 g2; rewrite !iprod_included_spec=> Hf x.
rewrite /iprod_map; apply included_preserving, Hf.
Qed. Qed.
Definition iprodC_map {A} {B1 B2 : A cofeT} (f : iprod (λ x, B1 x -n> B2 x)) : Definition iprodC_map {A} {B1 B2 : A cofeT} (f : iprod (λ x, B1 x -n> B2 x)) :
......
...@@ -72,6 +72,8 @@ Instance option_op : Op (option A) := union_with (λ x y, Some (x ⋅ y)). ...@@ -72,6 +72,8 @@ Instance option_op : Op (option A) := union_with (λ x y, Some (x ⋅ y)).
Instance option_minus : Minus (option A) := Instance option_minus : Minus (option A) :=
difference_with (λ x y, Some (x y)). difference_with (λ x y, Some (x y)).
Definition Some_op a b : Some (a b) = Some a Some b := eq_refl.
Lemma option_included (mx my : option A) : Lemma option_included (mx my : option A) :
mx my mx = None x y, mx = Some x my = Some y x y. mx my mx = None x y, mx = Some x my = Some y x y.
Proof. Proof.
...@@ -84,24 +86,6 @@ Proof. ...@@ -84,24 +86,6 @@ Proof.
- intros [->|(x&y&->&->&z&Hz)]; try (by exists my; destruct my; constructor). - intros [->|(x&y&->&->&z&Hz)]; try (by exists my; destruct my; constructor).
by exists (Some z); constructor. by exists (Some z); constructor.
Qed. Qed.
Lemma option_includedN n (mx my : option A) :
mx {n} my mx = None x y, mx = Some x my = Some y x {n} y.
Proof.
split.
- intros [mz Hmz].
destruct mx as [x|]; [right|by left].
destruct my as [y|]; [exists x, y|destruct mz; inversion_clear Hmz].
destruct mz as [z|]; inversion_clear Hmz; split_and?; auto;
cofe_subst; eauto using cmra_includedN_l.
- intros [->|(x&y&->&->&z&Hz)]; try (by exists my; destruct my; constructor).
by exists (Some z); constructor.
Qed.
Lemma None_includedN n (mx : option A) : None {n} mx.
Proof. rewrite option_includedN; auto. Qed.
Lemma Some_Some_includedN n (x y : A) : x {n} y Some x {n} Some y.
Proof. rewrite option_includedN; eauto 10. Qed.
Definition Some_op a b : Some (a b) = Some a Some b := eq_refl.
Definition option_cmra_mixin : CMRAMixin (option A). Definition option_cmra_mixin : CMRAMixin (option A).
Proof. Proof.
...@@ -140,6 +124,8 @@ Global Instance option_cmra_discrete : CMRADiscrete A → CMRADiscrete optionRA. ...@@ -140,6 +124,8 @@ Global Instance option_cmra_discrete : CMRADiscrete A → CMRADiscrete optionRA.
Proof. split; [apply _|]. by intros [x|]; [apply (cmra_discrete_valid x)|]. Qed. Proof. split; [apply _|]. by intros [x|]; [apply (cmra_discrete_valid x)|]. Qed.
(** Misc *) (** Misc *)
Global Instance Some_cmra_monotone : CMRAMonotone Some.
Proof. split; [apply _|done|intros x y [z ->]; by exists (Some z)]. Qed.
Lemma op_is_Some mx my : is_Some (mx my) is_Some mx is_Some my. Lemma op_is_Some mx my : is_Some (mx my) is_Some mx is_Some my.
Proof. Proof.
destruct mx, my; rewrite /op /option_op /= -!not_eq_None_Some; naive_solver. destruct mx, my; rewrite /op /option_op /= -!not_eq_None_Some; naive_solver.
...@@ -192,10 +178,10 @@ Proof. by intros Hf; destruct 1; constructor; apply Hf. Qed. ...@@ -192,10 +178,10 @@ Proof. by intros Hf; destruct 1; constructor; apply Hf. Qed.
Instance option_fmap_cmra_monotone {A B : cmraT} (f: A B) `{!CMRAMonotone f} : Instance option_fmap_cmra_monotone {A B : cmraT} (f: A B) `{!CMRAMonotone f} :
CMRAMonotone (fmap f : option A option B). CMRAMonotone (fmap f : option A option B).
Proof. Proof.
split. split; first apply _.
- intros n mx my; rewrite !option_includedN. - intros n [x|] ?; rewrite /cmra_validN /=; by repeat apply validN_preserving.
intros [->|(x&y&->&->&?)]; simpl; eauto 10 using @includedN_preserving. - intros mx my; rewrite !option_included.
- by intros n [x|] ?; rewrite /cmra_validN /=; try apply validN_preserving. intros [->|(x&y&->&->&?)]; simpl; eauto 10 using @included_preserving.
Qed. Qed.
Definition optionC_map {A B} (f : A -n> B) : optionC A -n> optionC B := Definition optionC_map {A B} (f : A -n> B) : optionC A -n> optionC B :=
CofeMor (fmap f : optionC A optionC B). CofeMor (fmap f : optionC A optionC B).
......
...@@ -205,10 +205,10 @@ Qed. ...@@ -205,10 +205,10 @@ Qed.
Instance res_map_cmra_monotone {Λ Σ} {A B : cofeT} (f : A -n> B) : Instance res_map_cmra_monotone {Λ Σ} {A B : cofeT} (f : A -n> B) :
CMRAMonotone (@res_map Λ Σ _ _ f). CMRAMonotone (@res_map Λ Σ _ _ f).
Proof. Proof.
split. split; first apply _.
- by intros n r1 r2; rewrite !res_includedN;
intros (?&?&?); split_and!; simpl; try apply includedN_preserving.
- by intros n r (?&?&?); split_and!; simpl; try apply validN_preserving. - by intros n r (?&?&?); split_and!; simpl; try apply validN_preserving.
- by intros r1 r2; rewrite !res_included;
intros (?&?&?); split_and!; simpl; try apply included_preserving.
Qed. Qed.
Definition resC_map {Λ Σ A B} (f : A -n> B) : resC Λ Σ A -n> resC Λ Σ B := Definition resC_map {Λ Σ A B} (f : A -n> B) : resC Λ Σ A -n> resC Λ Σ B :=
CofeMor (res_map f : resRA Λ Σ A resRA Λ Σ B). CofeMor (res_map f : resRA Λ Σ A resRA Λ Σ B).
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment