Commit 361308c7 authored by Robbert Krebbers's avatar Robbert Krebbers

Lots of refactoring. and new results on permutations and list containment.

The refactoring includes:
* Use infix notations for the various list relations
* More consistent naming
* Put lemmas on one line whenever possible
* Change proofs into one-liners when possible
* Make better use of the "Implicit Types" command
* Improve the order of the list module by placing all definitions at the start,
  then the proofs, and finally the tactics.

Besides, there is some new machinery for proofs by reflection on lists. It is
used for a decision procedure for permutations and list containment.
parent 2783aea9
This diff is collapsed.
...@@ -42,8 +42,7 @@ Section simple_collection. ...@@ -42,8 +42,7 @@ Section simple_collection.
Global Instance elem_of_proper: Proper ((=) ==> () ==> iff) () | 5. Global Instance elem_of_proper: Proper ((=) ==> () ==> iff) () | 5.
Proof. intros ???. subst. firstorder. Qed. Proof. intros ???. subst. firstorder. Qed.
Lemma elem_of_union_list (Xs : list C) (x : A) : Lemma elem_of_union_list Xs x : x Xs X, X Xs x X.
x Xs X, X Xs x X.
Proof. Proof.
split. split.
* induction Xs; simpl; intros HXs. * induction Xs; simpl; intros HXs.
...@@ -249,13 +248,11 @@ Section collection. ...@@ -249,13 +248,11 @@ Section collection.
Lemma not_elem_of_intersection x X Y : x X Y x X x Y. Lemma not_elem_of_intersection x X Y : x X Y x X x Y.
Proof. Proof.
rewrite elem_of_intersection. rewrite elem_of_intersection. destruct (decide (x X)); tauto.
destruct (decide (x X)); tauto.
Qed. Qed.
Lemma not_elem_of_difference x X Y : x X Y x X x Y. Lemma not_elem_of_difference x X Y : x X Y x X x Y.
Proof. Proof.
rewrite elem_of_difference. rewrite elem_of_difference. destruct (decide (x Y)); tauto.
destruct (decide (x Y)); tauto.
Qed. Qed.
Lemma union_difference X Y : X Y Y X Y X. Lemma union_difference X Y : X Y Y X Y X.
Proof. Proof.
...@@ -303,19 +300,18 @@ Section collection_ops. ...@@ -303,19 +300,18 @@ Section collection_ops.
( x y z, Q x P y f x y = Some z P z) ( x y z, Q x P y f x y = Some z P z)
x, x intersection_with_list f Y Xs P x. x, x intersection_with_list f Y Xs P x.
Proof. Proof.
intros HY HXs Hf. intros HY HXs Hf. induction Xs; simplify_option_equality; [done |].
induction Xs; simplify_option_equality; [done |].
intros x Hx. rewrite elem_of_intersection_with in Hx. intros x Hx. rewrite elem_of_intersection_with in Hx.
decompose_Forall. destruct Hx as (? & ? & ? & ? & ?). eauto. decompose_Forall. destruct Hx as (? & ? & ? & ? & ?). eauto.
Qed. Qed.
End collection_ops. End collection_ops.
(** * Sets without duplicates up to an equivalence *) (** * Sets without duplicates up to an equivalence *)
Section no_dup. Section NoDup.
Context `{SimpleCollection A B} (R : relation A) `{!Equivalence R}. Context `{SimpleCollection A B} (R : relation A) `{!Equivalence R}.
Definition elem_of_upto (x : A) (X : B) := y, y X R x y. Definition elem_of_upto (x : A) (X : B) := y, y X R x y.
Definition no_dup (X : B) := x y, x X y X R x y x = y. Definition set_NoDup (X : B) := x y, x X y X R x y x = y.
Global Instance: Proper (() ==> iff) (elem_of_upto x). Global Instance: Proper (() ==> iff) (elem_of_upto x).
Proof. intros ??? E. unfold elem_of_upto. by setoid_rewrite E. Qed. Proof. intros ??? E. unfold elem_of_upto. by setoid_rewrite E. Qed.
...@@ -325,7 +321,7 @@ Section no_dup. ...@@ -325,7 +321,7 @@ Section no_dup.
* rewrite <-E1, <-E2; intuition. * rewrite <-E1, <-E2; intuition.
* rewrite E1, E2; intuition. * rewrite E1, E2; intuition.
Qed. Qed.
Global Instance: Proper (() ==> iff) no_dup. Global Instance: Proper (() ==> iff) set_NoDup.
Proof. firstorder. Qed. Proof. firstorder. Qed.
Lemma elem_of_upto_elem_of x X : x X elem_of_upto x X. Lemma elem_of_upto_elem_of x X : x X elem_of_upto x X.
...@@ -341,60 +337,63 @@ Section no_dup. ...@@ -341,60 +337,63 @@ Section no_dup.
Lemma not_elem_of_upto x X : ¬elem_of_upto x X y, y X ¬R x y. Lemma not_elem_of_upto x X : ¬elem_of_upto x X y, y X ¬R x y.
Proof. unfold elem_of_upto. esolve_elem_of. Qed. Proof. unfold elem_of_upto. esolve_elem_of. Qed.
Lemma no_dup_empty: no_dup . Lemma set_NoDup_empty: set_NoDup .
Proof. unfold no_dup. solve_elem_of. Qed. Proof. unfold set_NoDup. solve_elem_of. Qed.
Lemma no_dup_add x X : ¬elem_of_upto x X no_dup X no_dup ({[ x ]} X). Lemma set_NoDup_add x X :
Proof. unfold no_dup, elem_of_upto. esolve_elem_of. Qed. ¬elem_of_upto x X set_NoDup X set_NoDup ({[ x ]} X).
Lemma no_dup_inv_add x X : x X no_dup ({[ x ]} X) ¬elem_of_upto x X. Proof. unfold set_NoDup, elem_of_upto. esolve_elem_of. Qed.
Lemma set_NoDup_inv_add x X :
x X set_NoDup ({[ x ]} X) ¬elem_of_upto x X.
Proof. Proof.
intros Hin Hnodup [y [??]]. intros Hin Hnodup [y [??]].
rewrite (Hnodup x y) in Hin; solve_elem_of. rewrite (Hnodup x y) in Hin; solve_elem_of.
Qed. Qed.
Lemma no_dup_inv_union_l X Y : no_dup (X Y) no_dup X. Lemma set_NoDup_inv_union_l X Y : set_NoDup (X Y) set_NoDup X.
Proof. unfold no_dup. solve_elem_of. Qed. Proof. unfold set_NoDup. solve_elem_of. Qed.
Lemma no_dup_inv_union_r X Y : no_dup (X Y) no_dup Y. Lemma set_NoDup_inv_union_r X Y : set_NoDup (X Y) set_NoDup Y.
Proof. unfold no_dup. solve_elem_of. Qed. Proof. unfold set_NoDup. solve_elem_of. Qed.
End no_dup. End NoDup.
(** * Quantifiers *) (** * Quantifiers *)
Section quantifiers. Section quantifiers.
Context `{SimpleCollection A B} (P : A Prop). Context `{SimpleCollection A B} (P : A Prop).
Definition cforall X := x, x X P x. Definition set_Forall X := x, x X P x.
Definition cexists X := x, x X P x. Definition set_Exists X := x, x X P x.
Lemma cforall_empty : cforall . Lemma set_Forall_empty : set_Forall .
Proof. unfold cforall. solve_elem_of. Qed. Proof. unfold set_Forall. solve_elem_of. Qed.
Lemma cforall_singleton x : cforall {[ x ]} P x. Lemma set_Forall_singleton x : set_Forall {[ x ]} P x.
Proof. unfold cforall. solve_elem_of. Qed. Proof. unfold set_Forall. solve_elem_of. Qed.
Lemma cforall_union X Y : cforall X cforall Y cforall (X Y). Lemma set_Forall_union X Y : set_Forall X set_Forall Y set_Forall (X Y).
Proof. unfold cforall. solve_elem_of. Qed. Proof. unfold set_Forall. solve_elem_of. Qed.
Lemma cforall_union_inv_1 X Y : cforall (X Y) cforall X. Lemma set_Forall_union_inv_1 X Y : set_Forall (X Y) set_Forall X.
Proof. unfold cforall. solve_elem_of. Qed. Proof. unfold set_Forall. solve_elem_of. Qed.
Lemma cforall_union_inv_2 X Y : cforall (X Y) cforall Y. Lemma set_Forall_union_inv_2 X Y : set_Forall (X Y) set_Forall Y.
Proof. unfold cforall. solve_elem_of. Qed. Proof. unfold set_Forall. solve_elem_of. Qed.
Lemma cexists_empty : ¬cexists . Lemma set_Exists_empty : ¬set_Exists .
Proof. unfold cexists. esolve_elem_of. Qed. Proof. unfold set_Exists. esolve_elem_of. Qed.
Lemma cexists_singleton x : cexists {[ x ]} P x. Lemma set_Exists_singleton x : set_Exists {[ x ]} P x.
Proof. unfold cexists. esolve_elem_of. Qed. Proof. unfold set_Exists. esolve_elem_of. Qed.
Lemma cexists_union_1 X Y : cexists X cexists (X Y). Lemma set_Exists_union_1 X Y : set_Exists X set_Exists (X Y).
Proof. unfold cexists. esolve_elem_of. Qed. Proof. unfold set_Exists. esolve_elem_of. Qed.
Lemma cexists_union_2 X Y : cexists Y cexists (X Y). Lemma set_Exists_union_2 X Y : set_Exists Y set_Exists (X Y).
Proof. unfold cexists. esolve_elem_of. Qed. Proof. unfold set_Exists. esolve_elem_of. Qed.
Lemma cexists_union_inv X Y : cexists (X Y) cexists X cexists Y. Lemma set_Exists_union_inv X Y :
Proof. unfold cexists. esolve_elem_of. Qed. set_Exists (X Y) set_Exists X set_Exists Y.
Proof. unfold set_Exists. esolve_elem_of. Qed.
End quantifiers. End quantifiers.
Section more_quantifiers. Section more_quantifiers.
Context `{Collection A B}. Context `{Collection A B}.
Lemma cforall_weaken (P Q : A Prop) (Hweaken : x, P x Q x) X : Lemma set_Forall_weaken (P Q : A Prop) (Hweaken : x, P x Q x) X :
cforall P X cforall Q X. set_Forall P X set_Forall Q X.
Proof. unfold cforall. naive_solver. Qed. Proof. unfold set_Forall. naive_solver. Qed.
Lemma cexists_weaken (P Q : A Prop) (Hweaken : x, P x Q x) X : Lemma set_Exists_weaken (P Q : A Prop) (Hweaken : x, P x Q x) X :
cexists P X cexists Q X. set_Exists P X set_Exists Q X.
Proof. unfold cexists. naive_solver. Qed. Proof. unfold set_Exists. naive_solver. Qed.
End more_quantifiers. End more_quantifiers.
(** * Fresh elements *) (** * Fresh elements *)
...@@ -417,8 +416,7 @@ Section fresh. ...@@ -417,8 +416,7 @@ Section fresh.
Global Instance fresh_list_proper: Proper ((=) ==> () ==> (=)) fresh_list. Global Instance fresh_list_proper: Proper ((=) ==> () ==> (=)) fresh_list.
Proof. Proof.
intros ? n ?. subst. intros ? n ?. subst. induction n; simpl; intros ?? E; f_equal.
induction n; simpl; intros ?? E; f_equal.
* by rewrite E. * by rewrite E.
* apply IHn. by rewrite E. * apply IHn. by rewrite E.
Qed. Qed.
...@@ -437,10 +435,8 @@ Section fresh. ...@@ -437,10 +435,8 @@ Section fresh.
Lemma fresh_list_nodup n X : NoDup (fresh_list n X). Lemma fresh_list_nodup n X : NoDup (fresh_list n X).
Proof. Proof.
revert X. revert X. induction n; simpl; constructor; auto.
induction n; simpl; constructor; auto. intros Hin. apply fresh_list_is_fresh in Hin. solve_elem_of.
intros Hin. apply fresh_list_is_fresh in Hin.
solve_elem_of.
Qed. Qed.
End fresh. End fresh.
...@@ -455,7 +451,10 @@ Section collection_monad. ...@@ -455,7 +451,10 @@ Section collection_monad.
Context `{CollectionMonad M}. Context `{CollectionMonad M}.
Global Instance collection_guard: MGuard M := λ P dec A x, Global Instance collection_guard: MGuard M := λ P dec A x,
if dec then x else . match dec with
| left H => x H
| _ =>
end.
Global Instance collection_fmap_proper {A B} (f : A B) : Global Instance collection_fmap_proper {A B} (f : A B) :
Proper (() ==> ()) (fmap f). Proper (() ==> ()) (fmap f).
...@@ -495,8 +494,7 @@ Section collection_monad. ...@@ -495,8 +494,7 @@ Section collection_monad.
Proof. revert l; induction k; esolve_elem_of. Qed. Proof. revert l; induction k; esolve_elem_of. Qed.
Lemma elem_of_mapM_fmap {A B} (f : A B) (g : B M A) l k : Lemma elem_of_mapM_fmap {A B} (f : A B) (g : B M A) l k :
Forall (λ x, y, y g x f y = x) l Forall (λ x, y, y g x f y = x) l k mapM g l fmap f k = l.
k mapM g l fmap f k = l.
Proof. Proof.
intros Hl. revert k. intros Hl. revert k.
induction Hl; simpl; intros; induction Hl; simpl; intros;
...@@ -504,14 +502,10 @@ Section collection_monad. ...@@ -504,14 +502,10 @@ Section collection_monad.
Qed. Qed.
Lemma elem_of_mapM_Forall {A B} (f : A M B) (P : B Prop) l k : Lemma elem_of_mapM_Forall {A B} (f : A M B) (P : B Prop) l k :
l mapM f k l mapM f k Forall (λ x, y, y f x P y) k Forall P l.
Forall (λ x, y, y f x P y) k
Forall P l.
Proof. rewrite elem_of_mapM. apply Forall2_Forall_l. Qed. Proof. rewrite elem_of_mapM. apply Forall2_Forall_l. Qed.
Lemma elem_of_mapM_Forall2_l {A B C} (f : A M B) Lemma elem_of_mapM_Forall2_l {A B C} (f : A M B) (P: B C Prop) l1 l2 k :
(P : B C Prop) l1 l2 k : l1 mapM f k Forall2 (λ x y, z, z f x P z y) k l2
l1 mapM f k
Forall2 (λ x y, z, z f x P z y) k l2
Forall2 P l1 l2. Forall2 P l1 l2.
Proof. Proof.
rewrite elem_of_mapM. intros Hl1. revert l2. rewrite elem_of_mapM. intros Hl1. revert l2.
......
...@@ -76,6 +76,7 @@ Notation cast_if_and3 S1 S2 S3 := (if S1 then cast_if_and S2 S3 else right _). ...@@ -76,6 +76,7 @@ Notation cast_if_and3 S1 S2 S3 := (if S1 then cast_if_and S2 S3 else right _).
Notation cast_if_and4 S1 S2 S3 S4 := Notation cast_if_and4 S1 S2 S3 S4 :=
(if S1 then cast_if_and3 S2 S3 S4 else right _). (if S1 then cast_if_and3 S2 S3 S4 else right _).
Notation cast_if_or S1 S2 := (if S1 then left _ else cast_if S2). Notation cast_if_or S1 S2 := (if S1 then left _ else cast_if S2).
Notation cast_if_or3 S1 S2 S3 := (if S1 then left _ else cast_if_or S2 S3).
Notation cast_if_not_or S1 S2 := (if S1 then cast_if S2 else left _). Notation cast_if_not_or S1 S2 := (if S1 then cast_if S2 else left _).
Notation cast_if_not S := (if S then right _ else left _). Notation cast_if_not S := (if S then right _ else left _).
......
...@@ -13,7 +13,7 @@ Definition collection_fold `{Elements A C} {B} ...@@ -13,7 +13,7 @@ Definition collection_fold `{Elements A C} {B}
Section fin_collection. Section fin_collection.
Context `{FinCollection A C}. Context `{FinCollection A C}.
Global Instance elements_proper: Proper (() ==> Permutation) elements. Global Instance elements_proper: Proper (() ==> (≡ₚ)) elements.
Proof. Proof.
intros ?? E. apply NoDup_Permutation. intros ?? E. apply NoDup_Permutation.
* apply elements_nodup. * apply elements_nodup.
...@@ -176,10 +176,8 @@ Proof. ...@@ -176,10 +176,8 @@ Proof.
apply Hadd. solve_elem_of. apply IH. esolve_elem_of. apply Hadd. solve_elem_of. apply IH. esolve_elem_of.
Qed. Qed.
Lemma collection_fold_proper {B} (R : relation B) Lemma collection_fold_proper {B} (R : relation B) `{!Equivalence R}
`{!Equivalence R} (f : A B B) (b : B) `{!Proper ((=) ==> R ==> R) f}
(f : A B B) (b : B)
`{!Proper ((=) ==> R ==> R) f}
(Hf : a1 a2 b, R (f a1 (f a2 b)) (f a2 (f a1 b))) : (Hf : a1 a2 b, R (f a1 (f a2 b)) (f a2 (f a1 b))) :
Proper (() ==> R) (collection_fold f b). Proper (() ==> R) (collection_fold f b).
Proof. Proof.
...@@ -188,22 +186,22 @@ Proof. ...@@ -188,22 +186,22 @@ Proof.
* by rewrite E. * by rewrite E.
Qed. Qed.
Global Instance cforall_dec `(P : A Prop) Global Instance set_Forall_dec `(P : A Prop)
`{ x, Decision (P x)} X : Decision (cforall P X) | 100. `{ x, Decision (P x)} X : Decision (set_Forall P X) | 100.
Proof. Proof.
refine (cast_if (decide (Forall P (elements X)))); refine (cast_if (decide (Forall P (elements X))));
abstract (unfold cforall; setoid_rewrite elements_spec; abstract (unfold set_Forall; setoid_rewrite elements_spec;
by rewrite <-Forall_forall). by rewrite <-Forall_forall).
Defined. Defined.
Global Instance cexists_dec `(P : A Prop) `{ x, Decision (P x)} X : Global Instance set_Exists_dec `(P : A Prop) `{ x, Decision (P x)} X :
Decision (cexists P X) | 100. Decision (set_Exists P X) | 100.
Proof. Proof.
refine (cast_if (decide (Exists P (elements X)))); refine (cast_if (decide (Exists P (elements X))));
abstract (unfold cexists; setoid_rewrite elements_spec; abstract (unfold set_Exists; setoid_rewrite elements_spec;
by rewrite <-Exists_exists). by rewrite <-Exists_exists).
Defined. Defined.
Global Instance rel_elem_of_dec `{ x y, Decision (R x y)} x X : Global Instance rel_elem_of_dec `{ x y, Decision (R x y)} x X :
Decision (elem_of_upto R x X) | 100 := decide (cexists (R x) X). Decision (elem_of_upto R x X) | 100 := decide (set_Exists (R x) X).
End fin_collection. End fin_collection.
...@@ -6,46 +6,34 @@ function in a generic way, to allow more efficient implementations. *) ...@@ -6,46 +6,34 @@ function in a generic way, to allow more efficient implementations. *)
Require Export collections fin_maps. Require Export collections fin_maps.
Class FinMapDom K M D `{!FMap M} Class FinMapDom K M D `{!FMap M}
`{ A, Lookup K A (M A)} `{ A, Lookup K A (M A)} `{ A, Empty (M A)} `{ A, PartialAlter K A (M A)}
`{ A, Empty (M A)} `{!Merge M} `{ A, FinMapToList K A (M A)}
`{ A, PartialAlter K A (M A)}
`{!Merge M}
`{ A, FinMapToList K A (M A)}
`{ i j : K, Decision (i = j)} `{ i j : K, Decision (i = j)}
`{ A, Dom (M A) D} `{ A, Dom (M A) D} `{ElemOf K D} `{Empty D} `{Singleton K D}
`{ElemOf K D} `{Union D}`{Intersection D} `{Difference D} := {
`{Empty D}
`{Singleton K D}
`{Union D}
`{Intersection D}
`{Difference D} := {
finmap_dom_map :>> FinMap K M; finmap_dom_map :>> FinMap K M;
finmap_dom_collection :>> Collection K D; finmap_dom_collection :>> Collection K D;
elem_of_dom {A} (m : M A) i : i dom D m is_Some (m !! i) elem_of_dom {A} (m : M A) i : i dom D m is_Some (m !! i)
}. }.
Section theorems. Section fin_map_dom.
Context `{FinMapDom K M D}. Context `{FinMapDom K M D}.
Lemma not_elem_of_dom {A} (m : M A) i : Lemma not_elem_of_dom {A} (m : M A) i : i dom D m m !! i = None.
i dom D m m !! i = None.
Proof. by rewrite elem_of_dom, eq_None_not_Some. Qed. Proof. by rewrite elem_of_dom, eq_None_not_Some. Qed.
Lemma subseteq_dom {A} (m1 m2 : M A) : Lemma subseteq_dom {A} (m1 m2 : M A) : m1 m2 dom D m1 dom D m2.
m1 m2 dom D m1 dom D m2.
Proof. Proof.
unfold subseteq, map_subseteq, collection_subseteq. unfold subseteq, map_subseteq, collection_subseteq.
intros ??. rewrite !elem_of_dom. inversion 1. eauto. intros ??. rewrite !elem_of_dom. inversion 1. eauto.
Qed. Qed.
Lemma subset_dom {A} (m1 m2 : M A) : Lemma subset_dom {A} (m1 m2 : M A) : m1 m2 dom D m1 dom D m2.
m1 m2 dom D m1 dom D m2.
Proof. Proof.
intros [Hss1 Hss2]. split. intros [Hss1 Hss2]. split.
{ by apply subseteq_dom. } { by apply subseteq_dom. }
intros Hdom. destruct Hss2. intros i x Hi. intros Hdom. destruct Hss2. intros i x Hi.
specialize (Hdom i). rewrite !elem_of_dom in Hdom. specialize (Hdom i). rewrite !elem_of_dom in Hdom.
feed inversion Hdom. eauto. feed inversion Hdom. eauto. by erewrite (Hss1 i) in Hi by eauto.
by erewrite (Hss1 i) in Hi by eauto.
Qed. Qed.
Lemma dom_empty {A} : dom D (@empty (M A) _) . Lemma dom_empty {A} : dom D (@empty (M A) _) .
...@@ -54,38 +42,32 @@ Proof. ...@@ -54,38 +42,32 @@ Proof.
* rewrite elem_of_dom, lookup_empty. by inversion 1. * rewrite elem_of_dom, lookup_empty. by inversion 1.
* solve_elem_of. * solve_elem_of.
Qed. Qed.
Lemma dom_empty_inv {A} (m : M A) : Lemma dom_empty_inv {A} (m : M A) : dom D m m = .
dom D m m = .
Proof. Proof.
intros E. apply map_empty. intros. apply not_elem_of_dom. intros E. apply map_empty. intros. apply not_elem_of_dom.
rewrite E. solve_elem_of. rewrite E. solve_elem_of.
Qed. Qed.
Lemma dom_insert {A} (m : M A) i x : Lemma dom_insert {A} (m : M A) i x : dom D (<[i:=x]>m) {[ i ]} dom D m.
dom D (<[i:=x]>m) {[ i ]} dom D m.
Proof. Proof.
apply elem_of_equiv. intros j. apply elem_of_equiv. intros j.
rewrite elem_of_union, !elem_of_dom, !is_Some_alt. rewrite elem_of_union, !elem_of_dom, !is_Some_alt.
setoid_rewrite lookup_insert_Some. setoid_rewrite lookup_insert_Some.
destruct (decide (i = j)); esolve_elem_of. destruct (decide (i = j)); esolve_elem_of.
Qed. Qed.
Lemma dom_insert_subseteq {A} (m : M A) i x : Lemma dom_insert_subseteq {A} (m : M A) i x : dom D m dom D (<[i:=x]>m).
dom D m dom D (<[i:=x]>m).
Proof. rewrite (dom_insert _). solve_elem_of. Qed. Proof. rewrite (dom_insert _). solve_elem_of. Qed.
Lemma dom_insert_subseteq_compat_l {A} (m : M A) i x X : Lemma dom_insert_subseteq_compat_l {A} (m : M A) i x X :
X dom D m X dom D m X dom D (<[i:=x]>m).
X dom D (<[i:=x]>m).
Proof. intros. transitivity (dom D m); eauto using dom_insert_subseteq. Qed. Proof. intros. transitivity (dom D m); eauto using dom_insert_subseteq. Qed.
Lemma dom_singleton {A} (i : K) (x : A) : Lemma dom_singleton {A} (i : K) (x : A) : dom D {[(i, x)]} {[ i ]}.
dom D {[(i, x)]} {[ i ]}.
Proof. Proof.
unfold singleton at 1, map_singleton. unfold singleton at 1, map_singleton.
rewrite dom_insert, dom_empty. solve_elem_of. rewrite dom_insert, dom_empty. solve_elem_of.
Qed. Qed.
Lemma dom_delete {A} (m : M A) i : Lemma dom_delete {A} (m : M A) i : dom D (delete i m) dom D m {[ i ]}.
dom D (delete i m) dom D m {[ i ]}.
Proof. Proof.
apply elem_of_equiv. intros j. apply elem_of_equiv. intros j.
rewrite elem_of_difference, !elem_of_dom, !is_Some_alt. rewrite elem_of_difference, !elem_of_dom, !is_Some_alt.
...@@ -99,27 +81,22 @@ Lemma delete_insert_dom {A} (m : M A) i x : ...@@ -99,27 +81,22 @@ Lemma delete_insert_dom {A} (m : M A) i x :
i dom D m delete i (<[i:=x]>m) = m. i dom D m delete i (<[i:=x]>m) = m.
Proof. rewrite not_elem_of_dom. apply delete_insert. Qed. Proof. rewrite not_elem_of_dom. apply delete_insert. Qed.
Lemma map_disjoint_dom {A} (m1 m2 : M A) : Lemma map_disjoint_dom {A} (m1 m2 : M A) : m1 m2 dom D m1 dom D m2 .
m1 m2 dom D m1 dom D m2 .
Proof. Proof.
unfold disjoint, map_disjoint, map_intersection_forall. unfold disjoint, map_disjoint, map_intersection_forall.
rewrite elem_of_equiv_empty. setoid_rewrite elem_of_intersection. rewrite elem_of_equiv_empty. setoid_rewrite elem_of_intersection.
setoid_rewrite elem_of_dom. setoid_rewrite is_Some_alt. naive_solver. setoid_rewrite elem_of_dom. setoid_rewrite is_Some_alt. naive_solver.
Qed. Qed.
Lemma map_disjoint_dom_1 {A} (m1 m2 : M A) : Lemma map_disjoint_dom_1 {A} (m1 m2 : M A) : m1 m2 dom D m1 dom D m2 .
m1 m2 dom D m1 dom D m2 .
Proof. apply map_disjoint_dom. Qed. Proof. apply map_disjoint_dom. Qed.
Lemma map_disjoint_dom_2 {A} (m1 m2 : M A) : Lemma map_disjoint_dom_2 {A} (m1 m2 : M A) : dom D m1 dom D m2 m1 m2.
dom D m1 dom D m2 m1 m2.
Proof. apply map_disjoint_dom. Qed. Proof. apply map_disjoint_dom. Qed.
Lemma dom_union {A} (m1 m2 : M A) : Lemma dom_union {A} (m1 m2 : M A) : dom D (m1 m2) dom D m1 dom D m2.
dom D (m1 m2) dom D m1 dom D m2.
Proof. Proof.
apply elem_of_equiv. intros i. apply elem_of_equiv. intros i.
rewrite elem_of_union, !elem_of_dom, !is_Some_alt. rewrite elem_of_union, !elem_of_dom, !is_Some_alt.
setoid_rewrite lookup_union_Some_raw. setoid_rewrite lookup_union_Some_raw. destruct (m1 !! i); naive_solver.
destruct (m1 !! i); naive_solver.
Qed. Qed.
Lemma dom_intersection {A} (m1 m2 : M A) : Lemma dom_intersection {A} (m1 m2 : M A) :
...@@ -131,12 +108,10 @@ Proof. ...@@ -131,12 +108,10 @@ Proof.
setoid_rewrite is_Some_alt. naive_solver. setoid_rewrite is_Some_alt. naive_solver.
Qed. Qed.
Lemma dom_difference {A} (m1 m2 : M A) : Lemma dom_difference {A} (m1 m2 : M A) : dom D (m1 m2) dom D m1 dom D m2.
dom D (m1 m2) dom D m1 dom D m2.
Proof. Proof.
apply elem_of_equiv. intros i. apply elem_of_equiv. intros i.
rewrite elem_of_difference, !elem_of_dom, !is_Some_alt. rewrite elem_of_difference, !elem_of_dom, !is_Some_alt.
setoid_rewrite lookup_difference_Some. setoid_rewrite lookup_difference_Some. destruct (m2 !! i); naive_solver.
destruct (m2 !! i); naive_solver.
Qed. Qed.
End theorems. End fin_map_dom.
This diff is collapsed.
...@@ -28,9 +28,7 @@ Proof. ...@@ -28,9 +28,7 @@ Proof.
split. split.
* apply _. * apply _.
* intros. unfold fresh, Nfresh. * intros. unfold fresh, Nfresh.
setoid_replace X with Y; [done |]. setoid_replace X with Y; [done |]. by apply elem_of_equiv.
by apply elem_of_equiv.
* intros X E. assert (1 0)%N as []; [| done]. * intros X E. assert (1 0)%N as []; [| done].
apply N.add_le_mono_r with (Nmax X). apply N.add_le_mono_r with (Nmax X). by apply Nmax_max.
by apply Nmax_max.
Qed. Qed.
This diff is collapsed.
...@@ -4,25 +4,18 @@ ...@@ -4,25 +4,18 @@
removed. This implementation forms a monad. *) removed. This implementation forms a monad. *)
Require Export base decidable collections list. Require Export base decidable collections list.
Record listset A := Listset { Record listset A := Listset { listset_car: list A }.
listset_car: list A
}.
Arguments listset_car {_} _. Arguments listset_car {_} _.
Arguments Listset {_} _. Arguments Listset {_} _.
Section listset. Section listset.
Context {A : Type}. Context {A : Type}.
Instance listset_elem_of: ElemOf A (listset A) := λ x l, Instance listset_elem_of: ElemOf A (listset A) := λ x l, x listset_car l.
x listset_car l. Instance listset_empty: Empty (listset A) := Listset [].
Instance listset_empty: Empty (listset A) := Instance listset_singleton: Singleton A (listset A) := λ x, Listset [x].
Listset [].
Instance listset_singleton: Singleton A (listset A) := λ x,
Listset [x].
Instance listset_union: Union (listset A) := λ l k, Instance listset_union: Union (listset A) := λ l k,
match l, k with