Commit dcc164e3 authored by Robbert Krebbers's avatar Robbert Krebbers

Also specialize big ops on CMRAs to gmap.

parent 5726049c
From algebra Require Export cmra. From algebra Require Export cmra.
From prelude Require Import fin_maps. From prelude Require Import gmap.
Fixpoint big_op {A : cmraT} `{Empty A} (xs : list A) : A := Fixpoint big_op {A : cmraT} `{Empty A} (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) 2.
Definition big_opM {A : cmraT} `{FinMapToList K A M, Empty A} (m : M) : A := Definition big_opM `{Countable K} {A : cmraT} `{Empty A} (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) 5.
...@@ -34,33 +34,31 @@ Proof. ...@@ -34,33 +34,31 @@ Proof.
Qed. Qed.
Lemma big_op_contains xs ys : xs `contains` ys big_op xs big_op ys. Lemma big_op_contains xs ys : xs `contains` ys big_op xs big_op ys.
Proof. Proof.
induction 1 as [|x xs ys|x y xs|x xs ys|xs ys zs]; rewrite //=. intros [xs' ->]%contains_Permutation.
- by apply cmra_preserving_l. rewrite big_op_app; apply cmra_included_l.
- by rewrite !assoc (comm _ y).
- by transitivity (big_op ys); last apply cmra_included_r.
- by transitivity (big_op ys).
Qed. Qed.
Lemma big_op_delete xs i x : Lemma big_op_delete xs i x :
xs !! i = Some x x big_op (delete i xs) big_op xs. xs !! i = Some x x big_op (delete i xs) big_op xs.
Proof. by intros; rewrite {2}(delete_Permutation xs i x). Qed. Proof. by intros; rewrite {2}(delete_Permutation xs i x). Qed.
Context `{FinMap K M}. Context `{Countable K}.
Lemma big_opM_empty : big_opM ( : M A) . Implicit Types m : gmap K A.
Lemma big_opM_empty : big_opM ( : gmap K A) .
Proof. unfold big_opM. by rewrite map_to_list_empty. Qed. Proof. unfold big_opM. by rewrite map_to_list_empty. Qed.
Lemma big_opM_insert (m : M A) i x : Lemma big_opM_insert m i x :
m !! i = None big_opM (<[i:=x]> m) x big_opM m. m !! i = None big_opM (<[i:=x]> m) x big_opM m.
Proof. intros ?; by rewrite /big_opM map_to_list_insert. Qed. Proof. intros ?; by rewrite /big_opM map_to_list_insert. Qed.
Lemma big_opM_delete (m : M A) i x : Lemma big_opM_delete m i x :
m !! i = Some x x big_opM (delete i m) big_opM m. m !! i = Some x x big_opM (delete i m) big_opM m.
Proof. Proof.
intros. by rewrite -{2}(insert_delete m i x) // big_opM_insert ?lookup_delete. intros. by rewrite -{2}(insert_delete m i x) // big_opM_insert ?lookup_delete.
Qed. Qed.
Lemma big_opM_singleton i x : big_opM ({[i := x]} : M A) x. Lemma big_opM_singleton i x : big_opM ({[i := x]} : gmap K A) x.
Proof. Proof.
rewrite -insert_empty big_opM_insert /=; last auto using lookup_empty. rewrite -insert_empty big_opM_insert /=; last auto using lookup_empty.
by rewrite big_opM_empty right_id. by rewrite big_opM_empty right_id.
Qed. Qed.
Global Instance big_opM_proper : Proper (() ==> ()) (big_opM : M A _). Global Instance big_opM_proper : Proper (() ==> ()) (big_opM : gmap K A _).
Proof. Proof.
intros m1; induction m1 as [|i x m1 ? IH] using map_ind. intros m1; induction m1 as [|i x m1 ? IH] using map_ind.
{ by intros m2; rewrite (symmetry_iff ()) map_equiv_empty; intros ->. } { by intros m2; rewrite (symmetry_iff ()) map_equiv_empty; intros ->. }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment