Commit 36c6dc3a authored by Robbert Krebbers's avatar Robbert Krebbers

Better use of canonical structures.

parent a198e45b
......@@ -12,27 +12,27 @@ Arguments agree_car {_} _ _.
Arguments agree_is_valid {_} _ _.
Section agree.
Context `{Cofe A}.
Context {A : cofeT}.
Global Instance agree_validN : ValidN (agree A) := λ n x,
Instance agree_validN : ValidN (agree A) := λ n x,
agree_is_valid x n n', n' n x n' ={n'}= x n.
Lemma agree_valid_le (x : agree A) n n' :
agree_is_valid x n n' n agree_is_valid x n'.
Proof. induction 2; eauto using agree_valid_S. Qed.
Global Instance agree_valid : Valid (agree A) := λ x, n, {n} x.
Global Instance agree_equiv : Equiv (agree A) := λ x y,
Instance agree_valid : Valid (agree A) := λ x, n, {n} x.
Instance agree_equiv : Equiv (agree A) := λ x y,
( n, agree_is_valid x n agree_is_valid y n)
( n, agree_is_valid x n x n ={n}= y n).
Global Instance agree_dist : Dist (agree A) := λ n x y,
Instance agree_dist : Dist (agree A) := λ n x y,
( n', n' n agree_is_valid x n' agree_is_valid y n')
( n', n' n agree_is_valid x n' x n' ={n'}= y n').
Global Program Instance agree_compl : Compl (agree A) := λ c,
Program Instance agree_compl : Compl (agree A) := λ c,
{| agree_car n := c n n; agree_is_valid n := agree_is_valid (c n) n |}.
Next Obligation. intros; apply agree_valid_0. Qed.
Next Obligation.
intros c n ?; apply (chain_cauchy c n (S n)), agree_valid_S; auto.
Qed.
Instance agree_cofe : Cofe (agree A).
Definition agree_cofe_mixin : CofeMixin (agree A).
Proof.
split.
* intros x y; split.
......@@ -49,14 +49,15 @@ Proof.
by split; intros; apply agree_valid_0.
* by intros c n; split; intros; apply (chain_cauchy c).
Qed.
Canonical Structure agreeC := CofeT agree_cofe_mixin.
Global Program Instance agree_op : Op (agree A) := λ x y,
Program Instance agree_op : Op (agree A) := λ x y,
{| agree_car := x;
agree_is_valid n := agree_is_valid x n agree_is_valid y n x ={n}= y |}.
Next Obligation. by intros; simpl; split_ands; try apply agree_valid_0. Qed.
Next Obligation. naive_solver eauto using agree_valid_S, dist_S. Qed.
Global Instance agree_unit : Unit (agree A) := id.
Global Instance agree_minus : Minus (agree A) := λ x y, x.
Instance agree_unit : Unit (agree A) := id.
Instance agree_minus : Minus (agree A) := λ x y, x.
Instance: Commutative () (@op (agree A) _).
Proof. intros x y; split; [naive_solver|by intros n (?&?&Hxy); apply Hxy]. Qed.
Definition agree_idempotent (x : agree A) : x x x.
......@@ -70,7 +71,7 @@ Proof.
* etransitivity; [apply Hxy|symmetry; apply Hy, Hy'];
eauto using agree_valid_le.
Qed.
Instance: Proper (dist n ==> dist n ==> dist n) op.
Instance: Proper (dist n ==> dist n ==> dist n) (@op (agree A) _).
Proof. by intros n x1 x2 Hx y1 y2 Hy; rewrite Hy !(commutative _ _ y2) Hx. Qed.
Instance: Proper (() ==> () ==> ()) op := ne_proper_2 _.
Instance: Associative () (@op (agree A) _).
......@@ -84,7 +85,7 @@ Proof.
split; [|by intros ?; exists y].
by intros [z Hz]; rewrite Hz (associative _) agree_idempotent.
Qed.
Global Instance agree_cmra : CMRA (agree A).
Definition agree_cmra_mixin : CMRAMixin (agree A).
Proof.
split; try (apply _ || done).
* intros n x y Hxy [? Hx]; split; [by apply Hxy|intros n' ?].
......@@ -103,12 +104,15 @@ Qed.
Lemma agree_op_inv (x y1 y2 : agree A) n :
{n} x x ={n}= y1 y2 y1 ={n}= y2.
Proof. by intros [??] Hxy; apply Hxy. Qed.
Global Instance agree_extend : CMRAExtend (agree A).
Definition agree_cmra_extend_mixin : CMRAExtendMixin (agree A).
Proof.
intros n x y1 y2 ? Hx; exists (x,x); simpl; split.
* by rewrite agree_idempotent.
* by rewrite Hx (agree_op_inv x y1 y2) // agree_idempotent.
Qed.
Canonical Structure agreeRA : cmraT :=
CMRAT agree_cofe_mixin agree_cmra_mixin agree_cmra_extend_mixin.
Program Definition to_agree (x : A) : agree A :=
{| agree_car n := x; agree_is_valid n := True |}.
Solve Obligations with done.
......@@ -125,12 +129,20 @@ Proof.
Qed.
End agree.
Arguments agreeC : clear implicits.
Arguments agreeRA : clear implicits.
Program Definition agree_map {A B} (f : A B) (x : agree A) : agree B :=
{| agree_car n := f (x n); agree_is_valid := agree_is_valid x |}.
Solve Obligations with auto using agree_valid_0, agree_valid_S.
Lemma agree_map_id {A} (x : agree A) : agree_map id x = x.
Proof. by destruct x. Qed.
Lemma agree_map_compose {A B C} (f : A B) (g : B C)
(x : agree A) : agree_map (g f) x = agree_map g (agree_map f x).
Proof. done. Qed.
Section agree_map.
Context `{Cofe A, Cofe B} (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).
Proof. by intros x1 x2 Hx; split; simpl; intros; [apply Hx|apply Hf, Hx]. Qed.
Global Instance agree_map_proper :
......@@ -147,13 +159,7 @@ Section agree_map.
try apply Hxy; try apply Hf; eauto using @agree_valid_le.
Qed.
End agree_map.
Lemma agree_map_id {A} (x : agree A) : agree_map id x = x.
Proof. by destruct x. Qed.
Lemma agree_map_compose {A B C} (f : A B) (g : B C) (x : agree A) :
agree_map (g f) x = agree_map g (agree_map f x).
Proof. done. Qed.
Canonical Structure agreeRA (A : cofeT) : cmraT := CMRAT (agree A).
Definition agreeRA_map {A B} (f : A -n> B) : agreeRA A -n> agreeRA B :=
CofeMor (agree_map f : agreeRA A agreeRA B).
Instance agreeRA_map_ne A B n : Proper (dist n ==> dist n) (@agreeRA_map A B).
......
......@@ -10,22 +10,24 @@ Notation "◯ x" := (Auth ExclUnit x) (at level 20).
Notation "● x" := (Auth (Excl x) ) (at level 20).
(* COFE *)
Instance auth_equiv `{Equiv A} : Equiv (auth A) := λ x y,
Section cofe.
Context {A : cofeT}.
Instance auth_equiv : Equiv (auth A) := λ x y,
authoritative x authoritative y own x own y.
Instance auth_dist `{Dist A} : Dist (auth A) := λ n x y,
Instance auth_dist : Dist (auth A) := λ n x y,
authoritative x ={n}= authoritative y own x ={n}= own y.
Instance Auth_ne `{Dist A} : Proper (dist n ==> dist n ==> dist n) (@Auth A).
Global Instance Auth_ne : Proper (dist n ==> dist n ==> dist n) (@Auth A).
Proof. by split. Qed.
Instance authoritative_ne `{Dist A} :
Proper (dist n ==> dist n) (@authoritative A).
Global Instance authoritative_ne: Proper (dist n ==> dist n) (@authoritative A).
Proof. by destruct 1. Qed.
Instance own_ne `{Dist A} : Proper (dist n ==> dist n) (@own A).
Global Instance own_ne : Proper (dist n ==> dist n) (@own A).
Proof. by destruct 1. Qed.
Instance auth_compl `{Cofe A} : Compl (auth A) := λ c,
Instance auth_compl : Compl (auth A) := λ c,
Auth (compl (chain_map authoritative c)) (compl (chain_map own c)).
Local Instance auth_cofe `{Cofe A} : Cofe (auth A).
Definition auth_cofe_mixin : CofeMixin (auth A).
Proof.
split.
* intros x y; unfold dist, auth_dist, equiv, auth_equiv.
......@@ -39,53 +41,59 @@ Proof.
* intros c n; split. apply (conv_compl (chain_map authoritative c) n).
apply (conv_compl (chain_map own c) n).
Qed.
Instance Auth_timeless `{Dist A, Equiv A} (x : excl A) (y : A) :
Canonical Structure authC := CofeT auth_cofe_mixin.
Instance Auth_timeless (x : excl A) (y : A) :
Timeless x Timeless y Timeless (Auth x y).
Proof. by intros ?? [??] [??]; split; apply (timeless _). Qed.
Proof. by intros ?? [??] [??]; split; simpl in *; apply (timeless _). Qed.
End cofe.
Arguments authC : clear implicits.
(* CMRA *)
Instance auth_empty `{Empty A} : Empty (auth A) := Auth .
Instance auth_valid `{Equiv A, Valid A, Op A} : Valid (auth A) := λ x,
Section cmra.
Context {A : cmraT}.
Global Instance auth_empty `{Empty A} : Empty (auth A) := Auth .
Instance auth_valid : Valid (auth A) := λ x,
match authoritative x with
| Excl a => own x a a
| ExclUnit => (own x)
| ExclBot => False
end.
Arguments auth_valid _ _ _ _ !_ /.
Instance auth_validN `{Dist A, ValidN A, Op A} : ValidN (auth A) := λ n x,
Global Arguments auth_valid !_ /.
Instance auth_validN : ValidN (auth A) := λ n x,
match authoritative x with
| Excl a => own x {n} a {n} a
| ExclUnit => {n} (own x)
| ExclBot => n = 0
end.
Arguments auth_validN _ _ _ _ _ !_ /.
Instance auth_unit `{Unit A} : Unit (auth A) := λ x,
Global Arguments auth_validN _ !_ /.
Instance auth_unit : Unit (auth A) := λ x,
Auth (unit (authoritative x)) (unit (own x)).
Instance auth_op `{Op A} : Op (auth A) := λ x y,
Instance auth_op : Op (auth A) := λ x y,
Auth (authoritative x authoritative y) (own x own y).
Instance auth_minus `{Minus A} : Minus (auth A) := λ x y,
Instance auth_minus : Minus (auth A) := λ x y,
Auth (authoritative x authoritative y) (own x own y).
Lemma auth_included `{Equiv A, Op A} (x y : auth A) :
Lemma auth_included (x y : auth A) :
x y authoritative x authoritative y own x 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 auth_includedN `{Dist A, Op A} n (x y : auth A) :
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 `{CMRA A} 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.
Lemma own_validN `{CMRA A} 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_valid_includedN. Qed.
Instance auth_cmra `{CMRA A} : CMRA (auth A).
Definition auth_cmra_mixin : CMRAMixin (auth A).
Proof.
split.
* apply _.
* by intros n x y1 y2 [Hy Hy']; split; simpl; rewrite ?Hy ?Hy'.
* by intros n y1 y2 [Hy Hy']; split; simpl; rewrite ?Hy ?Hy'.
* intros n [x a] [y b] [Hx Ha]; simpl in *;
......@@ -103,14 +111,14 @@ Proof.
* by split; simpl; rewrite ?(ra_unit_idempotent _).
* intros n ??; rewrite! auth_includedN; intros [??].
by split; simpl; apply cmra_unit_preserving.
* assert ( n a b1 b2, b1 b2 {n} a b1 {n} a).
* assert ( n (a b1 b2 : A), b1 b2 {n} a b1 {n} a).
{ intros n a b1 b2 <-; apply cmra_included_l. }
intros n [[a1| |] b1] [[a2| |] b2];
naive_solver eauto using cmra_valid_op_l, cmra_valid_includedN.
* by intros n ??; rewrite auth_includedN;
intros [??]; split; simpl; apply cmra_op_minus.
Qed.
Instance auth_cmra_extend `{CMRA A, !CMRAExtend A} : CMRAExtend (auth A).
Definition auth_cmra_extend_mixin : CMRAExtendMixin (auth A).
Proof.
intros n x y1 y2 ? [??]; simpl in *.
destruct (cmra_extend_op n (authoritative x) (authoritative y1)
......@@ -119,39 +127,49 @@ Proof.
as (z2&?&?&?); auto using own_validN.
by exists (Auth (z1.1) (z2.1), Auth (z1.2) (z2.2)).
Qed.
Instance auth_ra_empty `{CMRA A, Empty A, !RAIdentity A} : RAIdentity (auth A).
Canonical Structure authRA : cmraT :=
CMRAT auth_cofe_mixin auth_cmra_mixin auth_cmra_extend_mixin.
Instance auth_ra_empty `{Empty A} : RAIdentity A RAIdentity (auth A).
Proof.
split; [apply (ra_empty_valid (A:=A))|].
split; simpl; [apply ra_empty_valid|].
by intros x; constructor; simpl; rewrite (left_id _ _).
Qed.
Instance auth_frag_valid_timeless `{CMRA A} (x : A) :
Global Instance auth_frag_valid_timeless (x : A) :
ValidTimeless x ValidTimeless ( x).
Proof. by intros ??; apply (valid_timeless x). Qed.
Instance auth_valid_timeless `{CMRA A, Empty A, !RAIdentity A} (x : A) :
Global Instance auth_valid_timeless `{Empty A, !RAIdentity A} (x : A) :
ValidTimeless x ValidTimeless ( x).
Proof.
by intros ? [??]; split; [apply ra_empty_least|apply (valid_timeless x)].
Qed.
Lemma auth_frag_op `{CMRA A} a b : (a b) a b.
Lemma auth_frag_op (a b : A) : (a b) a b.
Proof. done. Qed.
Lemma auth_includedN' n (x y : authC 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.
End cmra.
Arguments authRA : clear implicits.
(* Functor *)
Definition authRA (A : cmraT) : cmraT := CMRAT (auth A).
Instance auth_fmap : FMap auth := λ A B f x,
Auth (f <$> authoritative x) (f (own x)).
Instance auth_fmap_cmra_ne `{Dist A, Dist B} n :
Instance auth_fmap_cmra_ne {A B : cmraT} n :
Proper ((dist n ==> dist n) ==> dist n ==> dist n) (@fmap auth _ A B).
Proof.
intros f g Hf [??] [??] [??]; split; [by apply excl_fmap_cmra_ne|by apply Hf].
Qed.
Instance auth_fmap_cmra_monotone `{CMRA A, CMRA B} (f : A B) :
Instance auth_fmap_cmra_monotone {A B : cmraT} (f : A B) :
( n, Proper (dist n ==> dist n) f) CMRAMonotone f
CMRAMonotone (fmap f : auth A auth B).
Proof.
split.
* by intros n [x a] [y b]; rewrite !auth_includedN; simpl;
intros [??]; split; apply includedN_preserving.
* intros n [[a| |] b];
* by intros n [x a] [y b]; rewrite !auth_includedN /=;
intros [??]; split; simpl; apply: includedN_preserving.
* intros n [[a| |] b]; rewrite /= /cmra_validN;
naive_solver eauto using @includedN_preserving, @validN_preserving.
Qed.
Definition authRA_map {A B : cmraT} (f : A -n> B) : authRA A -n> authRA B :=
......
This diff is collapsed.
This diff is collapsed.
......@@ -2,7 +2,7 @@ Require Export modures.cofe.
Section solver.
Context (F : cofeT cofeT cofeT).
Context `{Finhab : Inhabited (F (CofeT unit) (CofeT unit))}.
Context `{Finhab : Inhabited (F unitC unitC)}.
Context (map : {A1 A2 B1 B2 : cofeT},
((A2 -n> A1) * (B1 -n> B2)) (F A1 B1 -n> F A2 B2)).
Arguments map {_ _ _ _} _.
......@@ -20,11 +20,11 @@ Lemma map_ext {A1 A2 B1 B2 : cofeT}
Proof. by rewrite -!cofe_mor_ext; intros -> -> ->. Qed.
Fixpoint A (k : nat) : cofeT :=
match k with 0 => CofeT unit | S k => F (A k) (A k) end.
match k with 0 => unitC | S k => F (A k) (A k) end.
Fixpoint f {k} : A k -n> A (S k) :=
match k with 0 => CofeMor (λ _, inhabitant) | S k => map (g,f) end
with g {k} : A (S k) -n> A k :=
match k with 0 => CofeMor (λ _, () : CofeT ()) | S k => map (f,g) end.
match k with 0 => CofeMor (λ _, () : unitC) | S k => map (f,g) end.
Definition f_S k (x : A (S k)) : f x = map (g,f) x := eq_refl.
Definition g_S k (x : A (S (S k))) : g x = map (f,g) x := eq_refl.
Lemma gf {k} (x : A k) : g (f x) x.
......@@ -58,7 +58,7 @@ Next Obligation.
rewrite (conv_compl (tower_chain c k) n).
by rewrite (conv_compl (tower_chain c (S k)) n) /= (g_tower (c n) k).
Qed.
Instance tower_cofe : Cofe tower.
Definition tower_cofe_mixin : CofeMixin tower.
Proof.
split.
* intros X Y; split; [by intros HXY n k; apply equiv_dist|].
......@@ -73,7 +73,7 @@ Proof.
* intros c n k; rewrite /= (conv_compl (tower_chain c k) n).
apply (chain_cauchy c); lia.
Qed.
Definition T : cofeT := CofeT tower.
Definition T : cofeT := CofeT tower_cofe_mixin.
Fixpoint ff {k} (i : nat) : A k -n> A (i + k) :=
match i with 0 => cid | S i => f ff i end.
......
......@@ -12,8 +12,11 @@ Arguments ExclBot {_}.
Instance maybe_Excl {A} : Maybe (@Excl A) := λ x,
match x with Excl a => Some a | _ => None end.
Section excl.
Context {A : cofeT}.
(* Cofe *)
Inductive excl_equiv `{Equiv A} : Equiv (excl A) :=
Inductive excl_equiv : Equiv (excl A) :=
| Excl_equiv (x y : A) : x y Excl x Excl y
| ExclUnit_equiv : ExclUnit ExclUnit
| ExclBot_equiv : ExclBot ExclBot.
......@@ -24,21 +27,21 @@ Inductive excl_dist `{Dist A} : Dist (excl A) :=
| ExclUnit_dist n : ExclUnit ={n}= ExclUnit
| ExclBot_dist n : ExclBot ={n}= ExclBot.
Existing Instance excl_dist.
Program Definition excl_chain `{Cofe A}
Program Definition excl_chain
(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 |}.
Next Obligation.
intros A ???? c x ? n i ?; simpl; destruct (c 1) eqn:?; simplify_equality'.
intros c x ? n i ?; simpl; destruct (c 1) eqn:?; simplify_equality'.
destruct (decide (i = 0)) as [->|].
{ by replace n with 0 by lia. }
feed inversion (chain_cauchy c 1 i); auto with lia congruence.
feed inversion (chain_cauchy c n i); simpl; auto with lia congruence.
Qed.
Instance excl_compl `{Cofe A} : Compl (excl A) := λ c,
Instance excl_compl : Compl (excl A) := λ c,
match Some_dec (maybe Excl (c 1)) with
| inleft (exist x H) => Excl (compl (excl_chain c x H)) | inright _ => c 1
end.
Local Instance excl_cofe `{Cofe A} : Cofe (excl A).
Definition excl_cofe_mixin : CofeMixin (excl A).
Proof.
split.
* intros mx my; split; [by destruct 1; constructor; apply equiv_dist|].
......@@ -61,39 +64,40 @@ Proof.
feed inversion (chain_cauchy c 1 n); auto with lia; constructor.
destruct (c 1); simplify_equality'.
Qed.
Instance Excl_timeless `{Equiv A, Dist A} (x:A) :Timeless x Timeless (Excl x).
Canonical Structure exclC : cofeT := CofeT excl_cofe_mixin.
Global Instance Excl_timeless (x : A) : Timeless x Timeless (Excl x).
Proof. by inversion_clear 2; constructor; apply (timeless _). Qed.
Instance ExclUnit_timeless `{Equiv A, Dist A} : Timeless (@ExclUnit A).
Global Instance ExclUnit_timeless : Timeless (@ExclUnit A).
Proof. by inversion_clear 1; constructor. Qed.
Instance ExclBot_timeless `{Equiv A, Dist A} : Timeless (@ExclBot A).
Global Instance ExclBot_timeless : Timeless (@ExclBot A).
Proof. by inversion_clear 1; constructor. Qed.
Instance excl_timeless `{Equiv A, Dist A} :
Global Instance excl_timeless :
( x : A, Timeless x) x : excl A, Timeless x.
Proof. intros ? []; apply _. Qed.
(* CMRA *)
Instance excl_valid {A} : Valid (excl A) := λ x,
Instance excl_valid : Valid (excl A) := λ x,
match x with Excl _ | ExclUnit => True | ExclBot => False end.
Instance excl_validN {A} : ValidN (excl A) := λ n x,
Instance excl_validN : ValidN (excl A) := λ n x,
match x with Excl _ | ExclUnit => True | ExclBot => n = 0 end.
Instance excl_empty {A} : Empty (excl A) := ExclUnit.
Instance excl_unit {A} : Unit (excl A) := λ _, .
Instance excl_op {A} : Op (excl A) := λ x y,
Global Instance excl_empty : Empty (excl A) := ExclUnit.
Instance excl_unit : Unit (excl A) := λ _, .
Instance excl_op : Op (excl A) := λ x y,
match x, y with
| Excl x, ExclUnit | ExclUnit, Excl x => Excl x
| ExclUnit, ExclUnit => ExclUnit
| _, _=> ExclBot
end.
Instance excl_minus {A} : Minus (excl A) := λ x y,
Instance excl_minus : Minus (excl A) := λ x y,
match x, y with
| _, ExclUnit => x
| Excl _, Excl _ => ExclUnit
| _, _ => ExclBot
end.
Instance excl_cmra `{Cofe A} : CMRA (excl A).
Definition excl_cmra_mixin : CMRAMixin (excl A).
Proof.
split.
* apply _.
* by intros n []; destruct 1; constructor.
* constructor.
* by destruct 1 as [? []| | |]; intros ?.
......@@ -110,9 +114,9 @@ Proof.
* by intros n [?| |] [?| |].
* by intros n [?| |] [?| |] [[?| |] Hz]; inversion_clear Hz; constructor.
Qed.
Instance excl_empty_ra `{Cofe A} : RAIdentity (excl A).
Global Instance excl_empty_ra : RAIdentity (excl A).
Proof. split. done. by intros []. Qed.
Instance excl_extend `{Cofe A} : CMRAExtend (excl A).
Definition excl_cmra_extend_mixin : CMRAExtendMixin (excl A).
Proof.
intros [|n] x y1 y2 ? Hx; [by exists (x,); destruct x|].
by exists match y1, y2 with
......@@ -121,23 +125,28 @@ Proof.
| ExclUnit, _ => (ExclUnit, x) | _, ExclUnit => (x, ExclUnit)
end; destruct y1, y2; inversion_clear Hx; repeat constructor.
Qed.
Instance excl_valid_timeless {A} (x : excl A) : ValidTimeless x.
Canonical Structure exclRA : cmraT :=
CMRAT excl_cofe_mixin excl_cmra_mixin excl_cmra_extend_mixin.
Global Instance excl_valid_timeless (x : excl A) : ValidTimeless x.
Proof. by destruct x; intros ?. Qed.
(* Updates *)
Lemma excl_update {A} (x : A) y : y Excl x y.
Lemma excl_update (x : A) y : y Excl x y.
Proof. by destruct y; intros ? [?| |]. Qed.
End excl.
Arguments exclC : clear implicits.
Arguments exclRA : clear implicits.
(* Functor *)
Definition exclRA (A : cofeT) : cmraT := CMRAT (excl A).
Instance excl_fmap : FMap excl := λ A B f x,
match x with
| Excl a => Excl (f a) | ExclUnit => ExclUnit | ExclBot => ExclBot
end.
Instance excl_fmap_cmra_ne `{Dist A, Dist B} n :
Instance excl_fmap_cmra_ne {A B : cofeT} n :
Proper ((dist n ==> dist n) ==> dist n ==> dist n) (@fmap excl _ A B).
Proof. by intros f f' Hf; destruct 1; constructor; apply Hf. Qed.
Instance excl_fmap_cmra_monotone `{Cofe A, Cofe B} :
Instance excl_fmap_cmra_monotone {A B : cofeT} :
( n, Proper (dist n ==> dist n) f) CMRAMonotone (fmap f : excl A excl B).
Proof.
split.
......@@ -145,7 +154,7 @@ Proof.
by destruct x, z; constructor.
* by intros n [a| |].
Qed.
Definition exclRA_map {A B : cofeT} (f : A -n> B) : exclRA A -n> exclRA B :=
Definition exclRA_map {A B} (f : A -n> B) : exclRA A -n> exclRA B :=
CofeMor (fmap f : exclRA A exclRA B).
Lemma exclRA_map_ne A B n : Proper (dist n ==> dist n) (@exclRA_map A B).
Proof. by intros f f' Hf []; constructor; apply Hf. Qed.
This diff is collapsed.
......@@ -15,36 +15,41 @@ Hint Resolve uPred_0.
Add Printing Constructor uPred.
Instance: Params (@uPred_holds) 3.
Instance uPred_equiv (M : cmraT) : Equiv (uPred M) := λ P Q, x n,
{n} x P n x Q n x.
Instance uPred_dist (M : cmraT) : Dist (uPred M) := λ n P Q, x n',
n' n {n'} x P n' x Q n' x.
Program Instance uPred_compl (M : cmraT) : Compl (uPred M) := λ c,
{| uPred_holds n x := c n n x |}.
Next Obligation. by intros M c x y n ??; simpl in *; apply uPred_ne with x. Qed.
Next Obligation. by intros M c x; simpl. Qed.
Next Obligation.
intros M c x1 x2 n1 n2 ????; simpl in *.
apply (chain_cauchy c n2 n1); eauto using uPred_weaken.
Qed.
Instance uPred_cofe (M : cmraT) : Cofe (uPred M).
Proof.
split.
* intros P Q; split; [by intros HPQ n x i ??; apply HPQ|].
intros HPQ x n ?; apply HPQ with n; auto.
* intros n; split.
+ by intros P x i.
+ by intros P Q HPQ x i ??; symmetry; apply HPQ.
+ by intros P Q Q' HP HQ x i ??; transitivity (Q i x); [apply HP|apply HQ].
* intros n P Q HPQ x i ??; apply HPQ; auto.
* intros P Q x i; rewrite Nat.le_0_r; intros ->; split; intros; apply uPred_0.
* by intros c n x i ??; apply (chain_cauchy c i n).
Qed.
Section cofe.
Context {M : cmraT}.
Instance uPred_equiv : Equiv (uPred M) := λ P Q, x n,
{n} x P n x Q n x.
Instance uPred_dist : Dist (uPred M) := λ n P Q, x n',
n' n {n'} x P n' x Q n' x.
Program Instance uPred_compl : Compl (uPred M) := λ c,
{| uPred_holds n x := c n n x |}.
Next Obligation. by intros c x y n ??; simpl in *; apply uPred_ne with x. Qed.
Next Obligation. by intros c x; simpl. Qed.
Next Obligation.
intros c x1 x2 n1 n2 ????; simpl in *.
apply (chain_cauchy c n2 n1); eauto using uPred_weaken.
Qed.
Definition uPred_cofe_mixin : CofeMixin (uPred M).
Proof.
split.
* intros P Q; split; [by intros HPQ n x i ??; apply HPQ|].
intros HPQ x n ?; apply HPQ with n; auto.
* intros n; split.
+ by intros P x i.
+ by intros P Q HPQ x i ??; symmetry; apply HPQ.
+ by intros P Q Q' HP HQ x i ??; transitivity (Q i x); [apply HP|apply HQ].
* intros n P Q HPQ x i ??; apply HPQ; auto.
* intros P Q x i; rewrite Nat.le_0_r; intros ->; split; intros; apply uPred_0.
* by intros c n x i ??; apply (chain_cauchy c i n).
Qed.
Canonical Structure uPredC : cofeT := CofeT uPred_cofe_mixin.
End cofe.
Arguments uPredC : clear implicits.
Instance uPred_holds_ne {M} (P : uPred M) n : Proper (dist n ==> iff) (P n).
Proof. intros x1 x2 Hx; split; eauto using uPred_ne. Qed.
Instance uPred_holds_proper {M} (P : uPred M) n : Proper (() ==> iff) (P n).
Proof. by intros x1 x2 Hx; apply uPred_holds_ne, equiv_dist. Qed.
Canonical Structure uPredC (M : cmraT) : cofeT := CofeT (uPred M).
(** functor *)
Program Definition uPred_map {M1 M2 : cmraT} (f : M2 M1)
......@@ -125,7 +130,7 @@ Next Obligation. by intros M P Q x; exists x, x. Qed.
Next Obligation.
intros M P Q x y n1 n2 (x1&x2&Hx&?&?) Hxy ??.
assert ( x2', y ={n2}= x1 x2' x2 x2') as (x2'&Hy&?).
{ destruct Hxy as [z Hy]; exists (x2 z); split; eauto using ra_included_l.
{ destruct Hxy as [z Hy]; exists (x2 z); split; eauto using @ra_included_l.
apply dist_le with n1; auto. by rewrite (associative op) -Hx Hy. }
exists x1, x2'; split_ands; [done| |].
* cofe_subst y; apply uPred_weaken with x1 n1; eauto using cmra_valid_op_l.
......@@ -144,7 +149,7 @@ Next Obligation. intros M P Q x1 x2 [|n]; auto with lia. Qed.
Next Obligation.
intros M P Q x1 x2 n1 n2 HPQ ??? x3 n3 ???; simpl in *.
apply uPred_weaken with (x1 x3) n3;
eauto using cmra_valid_included, ra_preserving_r.
eauto using cmra_valid_included, @ra_preserving_r.
Qed.
Program Definition uPred_later {M} (P : uPred M) : uPred M :=
......@@ -160,7 +165,7 @@ Next Obligation. by intros M P x1 x2 n ? Hx; simpl in *; rewrite <-Hx. Qed.
Next Obligation. by intros; simpl. Qed.
Next Obligation.
intros M P x1 x2 n1 n2 ????; eapply uPred_weaken with (unit x1) n1;
auto using ra_unit_preserving, cmra_unit_valid.
eauto using @ra_unit_preserving, cmra_unit_valid.
Qed.
Program Definition uPred_own {M : cmraT} (a : M) : uPred M :=
......@@ -480,7 +485,7 @@ Qed.
Global Instance True_sep : LeftId () True%I (@uPred_sep M).
Proof.
intros P x n Hvalid; split.
* intros (x1&x2&?&_&?); cofe_subst;