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

Better use of canonical structures.

parent a198e45b
...@@ -12,27 +12,27 @@ Arguments agree_car {_} _ _. ...@@ -12,27 +12,27 @@ Arguments agree_car {_} _ _.
Arguments agree_is_valid {_} _ _. Arguments agree_is_valid {_} _ _.
Section agree. 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. agree_is_valid x n n', n' n x n' ={n'}= x n.
Lemma agree_valid_le (x : agree A) n n' : Lemma agree_valid_le (x : agree A) n n' :
agree_is_valid x n n' n agree_is_valid x n'. agree_is_valid x n n' n agree_is_valid x n'.
Proof. induction 2; eauto using agree_valid_S. Qed. Proof. induction 2; eauto using agree_valid_S. Qed.
Global Instance agree_valid : Valid (agree A) := λ x, n, {n} x. Instance agree_valid : Valid (agree A) := λ x, n, {n} x.
Global Instance agree_equiv : Equiv (agree A) := λ x y, 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 agree_is_valid y n)
( n, agree_is_valid x n x n ={n}= 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' agree_is_valid y n')
( n', n' n agree_is_valid x n' x n' ={n'}= 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 |}. {| 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; apply agree_valid_0. Qed.
Next Obligation. Next Obligation.
intros c n ?; apply (chain_cauchy c n (S n)), agree_valid_S; auto. intros c n ?; apply (chain_cauchy c n (S n)), agree_valid_S; auto.
Qed. Qed.
Instance agree_cofe : Cofe (agree A). Definition agree_cofe_mixin : CofeMixin (agree A).
Proof. Proof.
split. split.
* intros x y; split. * intros x y; split.
...@@ -49,14 +49,15 @@ Proof. ...@@ -49,14 +49,15 @@ Proof.
by split; intros; apply agree_valid_0. by split; intros; apply agree_valid_0.
* by intros c n; split; intros; apply (chain_cauchy c). * by intros c n; split; intros; apply (chain_cauchy c).
Qed. 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_car := x;
agree_is_valid n := agree_is_valid x n agree_is_valid y n x ={n}= y |}. 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. by intros; simpl; split_ands; try apply agree_valid_0. Qed.
Next Obligation. naive_solver eauto using agree_valid_S, dist_S. Qed. Next Obligation. naive_solver eauto using agree_valid_S, dist_S. Qed.
Global Instance agree_unit : Unit (agree A) := id. Instance agree_unit : Unit (agree A) := id.
Global Instance agree_minus : Minus (agree A) := λ x y, x. Instance agree_minus : Minus (agree A) := λ x y, x.
Instance: Commutative () (@op (agree A) _). Instance: Commutative () (@op (agree A) _).
Proof. intros x y; split; [naive_solver|by intros n (?&?&Hxy); apply Hxy]. Qed. Proof. intros x y; split; [naive_solver|by intros n (?&?&Hxy); apply Hxy]. Qed.
Definition agree_idempotent (x : agree A) : x x x. Definition agree_idempotent (x : agree A) : x x x.
...@@ -70,7 +71,7 @@ Proof. ...@@ -70,7 +71,7 @@ Proof.
* etransitivity; [apply Hxy|symmetry; apply Hy, Hy']; * etransitivity; [apply Hxy|symmetry; apply Hy, Hy'];
eauto using agree_valid_le. eauto using agree_valid_le.
Qed. 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. Proof. by intros n x1 x2 Hx y1 y2 Hy; rewrite Hy !(commutative _ _ y2) Hx. Qed.
Instance: Proper (() ==> () ==> ()) op := ne_proper_2 _. Instance: Proper (() ==> () ==> ()) op := ne_proper_2 _.
Instance: Associative () (@op (agree A) _). Instance: Associative () (@op (agree A) _).
...@@ -84,7 +85,7 @@ Proof. ...@@ -84,7 +85,7 @@ Proof.
split; [|by intros ?; exists y]. split; [|by intros ?; exists y].
by intros [z Hz]; rewrite Hz (associative _) agree_idempotent. by intros [z Hz]; rewrite Hz (associative _) agree_idempotent.
Qed. Qed.
Global Instance agree_cmra : CMRA (agree A). Definition agree_cmra_mixin : CMRAMixin (agree A).
Proof. Proof.
split; try (apply _ || done). split; try (apply _ || done).
* intros n x y Hxy [? Hx]; split; [by apply Hxy|intros n' ?]. * intros n x y Hxy [? Hx]; split; [by apply Hxy|intros n' ?].
...@@ -103,12 +104,15 @@ Qed. ...@@ -103,12 +104,15 @@ Qed.
Lemma agree_op_inv (x y1 y2 : agree A) n : Lemma agree_op_inv (x y1 y2 : agree A) n :
{n} x x ={n}= y1 y2 y1 ={n}= y2. {n} x x ={n}= y1 y2 y1 ={n}= y2.
Proof. by intros [??] Hxy; apply Hxy. Qed. Proof. by intros [??] Hxy; apply Hxy. Qed.
Global Instance agree_extend : CMRAExtend (agree A). Definition agree_cmra_extend_mixin : CMRAExtendMixin (agree A).
Proof. Proof.
intros n x y1 y2 ? Hx; exists (x,x); simpl; split. intros n x y1 y2 ? Hx; exists (x,x); simpl; split.
* by rewrite agree_idempotent. * by rewrite agree_idempotent.
* by rewrite Hx (agree_op_inv x y1 y2) // agree_idempotent. * by rewrite Hx (agree_op_inv x y1 y2) // agree_idempotent.
Qed. Qed.
Canonical Structure agreeRA : cmraT :=
CMRAT agree_cofe_mixin agree_cmra_mixin agree_cmra_extend_mixin.
Program Definition to_agree (x : A) : agree A := Program Definition to_agree (x : A) : agree A :=
{| agree_car n := x; agree_is_valid n := True |}. {| agree_car n := x; agree_is_valid n := True |}.
Solve Obligations with done. Solve Obligations with done.
...@@ -125,12 +129,20 @@ Proof. ...@@ -125,12 +129,20 @@ Proof.
Qed. Qed.
End agree. End agree.
Arguments agreeC : clear implicits.
Arguments agreeRA : clear implicits.
Program Definition agree_map {A B} (f : A B) (x : agree A) : agree B := 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 |}. {| agree_car n := f (x n); agree_is_valid := agree_is_valid x |}.
Solve Obligations with auto using agree_valid_0, agree_valid_S. 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. 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). 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. Proof. by intros x1 x2 Hx; split; simpl; intros; [apply Hx|apply Hf, Hx]. Qed.
Global Instance agree_map_proper : Global Instance agree_map_proper :
...@@ -147,13 +159,7 @@ Section agree_map. ...@@ -147,13 +159,7 @@ Section agree_map.
try apply Hxy; try apply Hf; eauto using @agree_valid_le. try apply Hxy; try apply Hf; eauto using @agree_valid_le.
Qed. Qed.
End agree_map. 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 := Definition agreeRA_map {A B} (f : A -n> B) : agreeRA A -n> agreeRA B :=
CofeMor (agree_map f : agreeRA A 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). 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). ...@@ -10,22 +10,24 @@ Notation "◯ x" := (Auth ExclUnit x) (at level 20).
Notation "● x" := (Auth (Excl x) ) (at level 20). Notation "● x" := (Auth (Excl x) ) (at level 20).
(* COFE *) (* 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. 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. 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. Proof. by split. Qed.
Instance authoritative_ne `{Dist A} : Global Instance authoritative_ne: Proper (dist n ==> dist n) (@authoritative A).
Proper (dist n ==> dist n) (@authoritative A).
Proof. by destruct 1. Qed. 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. 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)). 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. Proof.
split. split.
* intros x y; unfold dist, auth_dist, equiv, auth_equiv. * intros x y; unfold dist, auth_dist, equiv, auth_equiv.
...@@ -39,53 +41,59 @@ Proof. ...@@ -39,53 +41,59 @@ Proof.
* intros c n; split. apply (conv_compl (chain_map authoritative c) n). * intros c n; split. apply (conv_compl (chain_map authoritative c) n).
apply (conv_compl (chain_map own c) n). apply (conv_compl (chain_map own c) n).
Qed. 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). 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 *) (* CMRA *)
Instance auth_empty `{Empty A} : Empty (auth A) := Auth . Section cmra.
Instance auth_valid `{Equiv A, Valid A, Op A} : Valid (auth A) := λ x, Context {A : cmraT}.
Global Instance auth_empty `{Empty A} : Empty (auth A) := Auth .
Instance auth_valid : Valid (auth A) := λ x,
match authoritative x with match authoritative x with
| Excl a => own x a a | Excl a => own x a a
| ExclUnit => (own x) | ExclUnit => (own x)
| ExclBot => False | ExclBot => False
end. end.
Arguments auth_valid _ _ _ _ !_ /. Global Arguments auth_valid !_ /.
Instance auth_validN `{Dist A, ValidN A, Op A} : ValidN (auth A) := λ n x, Instance auth_validN : ValidN (auth A) := λ n x,
match authoritative x with match authoritative x with
| Excl a => own x {n} a {n} a | Excl a => own x {n} a {n} a
| ExclUnit => {n} (own x) | ExclUnit => {n} (own x)
| ExclBot => n = 0 | ExclBot => n = 0
end. end.
Arguments auth_validN _ _ _ _ _ !_ /. Global Arguments auth_validN _ !_ /.
Instance auth_unit `{Unit A} : Unit (auth A) := λ x, Instance auth_unit : Unit (auth A) := λ x,
Auth (unit (authoritative x)) (unit (own 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). 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). 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. x y authoritative x authoritative y own x own y.
Proof. 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 `{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. x {n} y authoritative x {n} authoritative y own x {n} own y.
Proof. 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 authoritative_validN `{CMRA A} n (x : auth A) : Lemma authoritative_validN n (x : auth A) : {n} x {n} (authoritative x).
{n} x {n} (authoritative x).
Proof. by destruct x as [[]]. Qed. 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. 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. Proof.
split. split.
* apply _.
* 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'.
* by intros n 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 *; * intros n [x a] [y b] [Hx Ha]; simpl in *;
...@@ -103,14 +111,14 @@ Proof. ...@@ -103,14 +111,14 @@ Proof.
* by split; simpl; rewrite ?(ra_unit_idempotent _). * by split; simpl; rewrite ?(ra_unit_idempotent _).
* intros n ??; rewrite! auth_includedN; intros [??]. * intros n ??; rewrite! auth_includedN; intros [??].
by split; simpl; apply cmra_unit_preserving. 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 a b1 b2 <-; apply cmra_included_l. }
intros n [[a1| |] b1] [[a2| |] b2]; intros n [[a1| |] b1] [[a2| |] b2];
naive_solver eauto using cmra_valid_op_l, cmra_valid_includedN. naive_solver eauto using cmra_valid_op_l, cmra_valid_includedN.
* by intros n ??; rewrite auth_includedN; * by intros n ??; rewrite auth_includedN;
intros [??]; split; simpl; apply cmra_op_minus. intros [??]; split; simpl; apply cmra_op_minus.
Qed. Qed.
Instance auth_cmra_extend `{CMRA A, !CMRAExtend A} : CMRAExtend (auth A). Definition auth_cmra_extend_mixin : CMRAExtendMixin (auth A).
Proof. Proof.
intros n x y1 y2 ? [??]; simpl in *. intros n x y1 y2 ? [??]; simpl in *.
destruct (cmra_extend_op n (authoritative x) (authoritative y1) destruct (cmra_extend_op n (authoritative x) (authoritative y1)
...@@ -119,39 +127,49 @@ Proof. ...@@ -119,39 +127,49 @@ Proof.
as (z2&?&?&?); auto using own_validN. as (z2&?&?&?); auto using own_validN.
by exists (Auth (z1.1) (z2.1), Auth (z1.2) (z2.2)). by exists (Auth (z1.1) (z2.1), Auth (z1.2) (z2.2)).
Qed. 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. Proof.
split; [apply (ra_empty_valid (A:=A))|]. split; simpl; [apply ra_empty_valid|].
by intros x; constructor; simpl; rewrite (left_id _ _). by intros x; constructor; simpl; rewrite (left_id _ _).
Qed. Qed.
Instance auth_frag_valid_timeless `{CMRA A} (x : A) : Global Instance auth_frag_valid_timeless (x : A) :
ValidTimeless x ValidTimeless ( x). ValidTimeless x ValidTimeless ( x).
Proof. by intros ??; apply (valid_timeless x). Qed. 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). ValidTimeless x ValidTimeless ( x).
Proof. Proof.
by intros ? [??]; split; [apply ra_empty_least|apply (valid_timeless x)]. by intros ? [??]; split; [apply ra_empty_least|apply (valid_timeless x)].
Qed. 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. 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 *) (* Functor *)
Definition authRA (A : cmraT) : cmraT := CMRAT (auth A).
Instance auth_fmap : FMap auth := λ A B f x, Instance auth_fmap : FMap auth := λ A B f x,
Auth (f <$> authoritative x) (f (own 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). Proper ((dist n ==> dist n) ==> dist n ==> dist n) (@fmap auth _ A B).
Proof. Proof.
intros f g Hf [??] [??] [??]; split; [by apply excl_fmap_cmra_ne|by apply Hf]. intros f g Hf [??] [??] [??]; split; [by apply excl_fmap_cmra_ne|by apply Hf].
Qed. 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 ( n, Proper (dist n ==> dist n) f) CMRAMonotone f
CMRAMonotone (fmap f : auth A auth B). CMRAMonotone (fmap f : auth A auth B).
Proof. Proof.
split. split.
* by intros n [x a] [y b]; rewrite !auth_includedN; simpl; * by intros n [x a] [y b]; rewrite !auth_includedN /=;
intros [??]; split; apply includedN_preserving. intros [??]; split; simpl; apply: includedN_preserving.
* intros n [[a| |] b]; * intros n [[a| |] b]; rewrite /= /cmra_validN;
naive_solver eauto using @includedN_preserving, @validN_preserving. naive_solver eauto using @includedN_preserving, @validN_preserving.
Qed. Qed.
Definition authRA_map {A B : cmraT} (f : A -n> B) : authRA A -n> authRA B := 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. ...@@ -2,7 +2,7 @@ Require Export modures.cofe.
Section solver. Section solver.
Context (F : cofeT cofeT cofeT). 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}, Context (map : {A1 A2 B1 B2 : cofeT},
((A2 -n> A1) * (B1 -n> B2)) (F A1 B1 -n> F A2 B2)). ((A2 -n> A1) * (B1 -n> B2)) (F A1 B1 -n> F A2 B2)).
Arguments map {_ _ _ _} _. Arguments map {_ _ _ _} _.
...@@ -20,11 +20,11 @@ Lemma map_ext {A1 A2 B1 B2 : cofeT} ...@@ -20,11 +20,11 @@ Lemma map_ext {A1 A2 B1 B2 : cofeT}
Proof. by rewrite -!cofe_mor_ext; intros -> -> ->. Qed. Proof. by rewrite -!cofe_mor_ext; intros -> -> ->. Qed.
Fixpoint A (k : nat) : cofeT := 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) := Fixpoint f {k} : A k -n> A (S k) :=
match k with 0 => CofeMor (λ _, inhabitant) | S k => map (g,f) end match k with 0 => CofeMor (λ _, inhabitant) | S k => map (g,f) end
with g {k} : A (S k) -n> A k := 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 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. 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. Lemma gf {k} (x : A k) : g (f x) x.
...@@ -58,7 +58,7 @@ Next Obligation. ...@@ -58,7 +58,7 @@ Next Obligation.
rewrite (conv_compl (tower_chain c k) n). rewrite (conv_compl (tower_chain c k) n).
by rewrite (conv_compl (tower_chain c (S k)) n) /= (g_tower (c n) k). by rewrite (conv_compl (tower_chain c (S k)) n) /= (g_tower (c n) k).
Qed. Qed.
Instance tower_cofe : Cofe tower. Definition tower_cofe_mixin : CofeMixin tower.
Proof. Proof.
split. split.
* intros X Y; split; [by intros HXY n k; apply equiv_dist|]. * intros X Y; split; [by intros HXY n k; apply equiv_dist|].
...@@ -73,7 +73,7 @@ Proof. ...@@ -73,7 +73,7 @@ Proof.
* intros c n k; rewrite /= (conv_compl (tower_chain c k) n). * intros c n k; rewrite /= (conv_compl (tower_chain c k) n).
apply (chain_cauchy c); lia. apply (chain_cauchy c); lia.
Qed. Qed.
Definition T : cofeT := CofeT tower. Definition T : cofeT := CofeT tower_cofe_mixin.
Fixpoint ff {k} (i : nat) : A k -n> A (i + k) := Fixpoint ff {k} (i : nat) : A k -n> A (i + k) :=
match i with 0 => cid | S i => f ff i end. match i with 0 => cid | S i => f ff i end.
......
...@@ -12,8 +12,11 @@ Arguments ExclBot {_}. ...@@ -12,8 +12,11 @@ Arguments ExclBot {_}.
Instance maybe_Excl {A} : Maybe (@Excl A) := λ x, Instance maybe_Excl {A} : Maybe (@Excl A) := λ x,
match x with Excl a => Some a | _ => None end. match x with Excl a => Some a | _ => None end.
Section excl.
Context {A : cofeT}.
(* Cofe *) (* 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 | Excl_equiv (x y : A) : x y Excl x Excl y
| ExclUnit_equiv : ExclUnit ExclUnit | ExclUnit_equiv : ExclUnit ExclUnit
| ExclBot_equiv : ExclBot ExclBot. | ExclBot_equiv : ExclBot ExclBot.
...@@ -24,21 +27,21 @@ Inductive excl_dist `{Dist A} : Dist (excl A) := ...@@ -24,21 +27,21 @@ Inductive excl_dist `{Dist A} : 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.
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 := (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 |}.