upred_big_op.v 18.5 KB
 Robbert Krebbers committed Mar 21, 2016 1 ``````From iris.algebra Require Export upred list. `````` Robbert Krebbers committed Apr 11, 2016 2 ``````From iris.prelude Require Import gmap fin_collections functions. `````` Ralf Jung committed Feb 17, 2016 3 ``````Import uPred. `````` Robbert Krebbers committed Feb 14, 2016 4 `````` `````` Robbert Krebbers committed May 24, 2016 5 6 7 8 9 10 11 12 13 14 15 ``````(** We define the following big operators: - The operators [ [★] Ps ] and [ [∧] Ps ] fold [★] and [∧] over the list [Ps]. This operator is not a quantifier, so it binds strongly. - The operator [ [★ map] k ↦ x ∈ m, P ] asserts that [P] holds separately for each [k ↦ x] in the map [m]. This operator is a quantifier, and thus has the same precedence as [∀] and [∃]. - The operator [ [★ set] x ∈ X, P ] asserts that [P] holds separately for each [x] in the set [X]. This operator is a quantifier, and thus has the same precedence as [∀] and [∃]. *) `````` Robbert Krebbers committed Feb 16, 2016 16 17 ``````(** * Big ops over lists *) (* These are the basic building blocks for other big ops *) `````` Robbert Krebbers committed May 24, 2016 18 ``````Fixpoint uPred_big_and {M} (Ps : list (uPred M)) : uPred M := `````` Robbert Krebbers committed Feb 16, 2016 19 20 `````` match Ps with [] => True | P :: Ps => P ∧ uPred_big_and Ps end%I. Instance: Params (@uPred_big_and) 1. `````` Robbert Krebbers committed May 24, 2016 21 ``````Notation "'[∧]' Ps" := (uPred_big_and Ps) (at level 20) : uPred_scope. `````` Robbert Krebbers committed Feb 16, 2016 22 23 24 ``````Fixpoint uPred_big_sep {M} (Ps : list (uPred M)) : uPred M := match Ps with [] => True | P :: Ps => P ★ uPred_big_sep Ps end%I. Instance: Params (@uPred_big_sep) 1. `````` Robbert Krebbers committed May 24, 2016 25 ``````Notation "'[★]' Ps" := (uPred_big_sep Ps) (at level 20) : uPred_scope. `````` Robbert Krebbers committed Feb 14, 2016 26 `````` `````` Robbert Krebbers committed Feb 16, 2016 27 ``````(** * Other big ops *) `````` Robbert Krebbers committed Feb 17, 2016 28 ``````Definition uPred_big_sepM {M} `{Countable K} {A} `````` Robbert Krebbers committed Feb 18, 2016 29 `````` (m : gmap K A) (Φ : K → A → uPred M) : uPred M := `````` Robbert Krebbers committed May 24, 2016 30 `````` [★] (curry Φ <\$> map_to_list m). `````` Robbert Krebbers committed Feb 17, 2016 31 ``````Instance: Params (@uPred_big_sepM) 6. `````` Robbert Krebbers committed Aug 24, 2016 32 ``````Typeclasses Opaque uPred_big_sepM. `````` Robbert Krebbers committed May 24, 2016 33 34 35 ``````Notation "'[★' 'map' ] k ↦ x ∈ m , P" := (uPred_big_sepM m (λ k x, P)) (at level 200, m at level 10, k, x at level 1, right associativity, format "[★ map ] k ↦ x ∈ m , P") : uPred_scope. `````` Robbert Krebbers committed Feb 14, 2016 36 `````` `````` Robbert Krebbers committed Feb 17, 2016 37 ``````Definition uPred_big_sepS {M} `{Countable A} `````` Robbert Krebbers committed May 24, 2016 38 `````` (X : gset A) (Φ : A → uPred M) : uPred M := [★] (Φ <\$> elements X). `````` Robbert Krebbers committed Feb 17, 2016 39 ``````Instance: Params (@uPred_big_sepS) 5. `````` Robbert Krebbers committed Aug 24, 2016 40 ``````Typeclasses Opaque uPred_big_sepS. `````` Robbert Krebbers committed May 24, 2016 41 42 43 ``````Notation "'[★' 'set' ] x ∈ X , P" := (uPred_big_sepS X (λ x, P)) (at level 200, X at level 10, x at level 1, right associativity, format "[★ set ] x ∈ X , P") : uPred_scope. `````` Robbert Krebbers committed Feb 16, 2016 44 `````` `````` Robbert Krebbers committed Aug 24, 2016 45 ``````(** * Persistence and timelessness of lists of uPreds *) `````` Robbert Krebbers committed Mar 11, 2016 46 ``````Class PersistentL {M} (Ps : list (uPred M)) := `````` Robbert Krebbers committed Mar 15, 2016 47 `````` persistentL : Forall PersistentP Ps. `````` Robbert Krebbers committed Mar 11, 2016 48 ``````Arguments persistentL {_} _ {_}. `````` Robbert Krebbers committed Feb 14, 2016 49 `````` `````` Robbert Krebbers committed Aug 24, 2016 50 51 52 53 ``````Class TimelessL {M} (Ps : list (uPred M)) := timelessL : Forall TimelessP Ps. Arguments timelessL {_} _ {_}. `````` Robbert Krebbers committed Apr 08, 2016 54 ``````(** * Properties *) `````` Robbert Krebbers committed Feb 14, 2016 55 ``````Section big_op. `````` Robbert Krebbers committed May 27, 2016 56 ``````Context {M : ucmraT}. `````` Robbert Krebbers committed Feb 14, 2016 57 58 59 ``````Implicit Types Ps Qs : list (uPred M). Implicit Types A : Type. `````` Robbert Krebbers committed Apr 08, 2016 60 ``````(** ** Big ops over lists *) `````` Ralf Jung committed Mar 10, 2016 61 ``````Global Instance big_and_proper : Proper ((≡) ==> (⊣⊢)) (@uPred_big_and M). `````` Robbert Krebbers committed Feb 14, 2016 62 ``````Proof. by induction 1 as [|P Q Ps Qs HPQ ? IH]; rewrite /= ?HPQ ?IH. Qed. `````` Ralf Jung committed Mar 10, 2016 63 ``````Global Instance big_sep_proper : Proper ((≡) ==> (⊣⊢)) (@uPred_big_sep M). `````` Robbert Krebbers committed Feb 14, 2016 64 ``````Proof. by induction 1 as [|P Q Ps Qs HPQ ? IH]; rewrite /= ?HPQ ?IH. Qed. `````` Robbert Krebbers committed Feb 17, 2016 65 `````` `````` Robbert Krebbers committed Mar 21, 2016 66 ``````Global Instance big_and_ne n : Proper (dist n ==> dist n) (@uPred_big_and M). `````` Robbert Krebbers committed Feb 17, 2016 67 ``````Proof. by induction 1 as [|P Q Ps Qs HPQ ? IH]; rewrite /= ?HPQ ?IH. Qed. `````` Robbert Krebbers committed Mar 21, 2016 68 ``````Global Instance big_sep_ne n : Proper (dist n ==> dist n) (@uPred_big_sep M). `````` Robbert Krebbers committed Feb 17, 2016 69 70 ``````Proof. by induction 1 as [|P Q Ps Qs HPQ ? IH]; rewrite /= ?HPQ ?IH. Qed. `````` Ralf Jung committed Mar 10, 2016 71 ``````Global Instance big_and_mono' : Proper (Forall2 (⊢) ==> (⊢)) (@uPred_big_and M). `````` Robbert Krebbers committed Feb 17, 2016 72 ``````Proof. by induction 1 as [|P Q Ps Qs HPQ ? IH]; rewrite /= ?HPQ ?IH. Qed. `````` Ralf Jung committed Mar 10, 2016 73 ``````Global Instance big_sep_mono' : Proper (Forall2 (⊢) ==> (⊢)) (@uPred_big_sep M). `````` Robbert Krebbers committed Feb 17, 2016 74 75 ``````Proof. by induction 1 as [|P Q Ps Qs HPQ ? IH]; rewrite /= ?HPQ ?IH. Qed. `````` Ralf Jung committed Mar 10, 2016 76 ``````Global Instance big_and_perm : Proper ((≡ₚ) ==> (⊣⊢)) (@uPred_big_and M). `````` Robbert Krebbers committed Feb 14, 2016 77 78 ``````Proof. induction 1 as [|P Ps Qs ? IH|P Q Ps|]; simpl; auto. `````` Robbert Krebbers committed Feb 17, 2016 79 80 `````` - by rewrite IH. - by rewrite !assoc (comm _ P). `````` Ralf Jung committed Feb 20, 2016 81 `````` - etrans; eauto. `````` Robbert Krebbers committed Feb 14, 2016 82 ``````Qed. `````` Ralf Jung committed Mar 10, 2016 83 ``````Global Instance big_sep_perm : Proper ((≡ₚ) ==> (⊣⊢)) (@uPred_big_sep M). `````` Robbert Krebbers committed Feb 14, 2016 84 85 ``````Proof. induction 1 as [|P Ps Qs ? IH|P Q Ps|]; simpl; auto. `````` Robbert Krebbers committed Feb 17, 2016 86 87 `````` - by rewrite IH. - by rewrite !assoc (comm _ P). `````` Ralf Jung committed Feb 20, 2016 88 `````` - etrans; eauto. `````` Robbert Krebbers committed Feb 14, 2016 89 ``````Qed. `````` Robbert Krebbers committed Feb 17, 2016 90 `````` `````` Robbert Krebbers committed May 31, 2016 91 ``````Lemma big_and_app Ps Qs : [∧] (Ps ++ Qs) ⊣⊢ [∧] Ps ∧ [∧] Qs. `````` Robbert Krebbers committed May 24, 2016 92 ``````Proof. induction Ps as [|?? IH]; by rewrite /= ?left_id -?assoc ?IH. Qed. `````` Robbert Krebbers committed May 31, 2016 93 ``````Lemma big_sep_app Ps Qs : [★] (Ps ++ Qs) ⊣⊢ [★] Ps ★ [★] Qs. `````` Robbert Krebbers committed Feb 14, 2016 94 ``````Proof. by induction Ps as [|?? IH]; rewrite /= ?left_id -?assoc ?IH. Qed. `````` Robbert Krebbers committed Feb 17, 2016 95 `````` `````` Robbert Krebbers committed May 24, 2016 96 ``````Lemma big_and_contains Ps Qs : Qs `contains` Ps → [∧] Ps ⊢ [∧] Qs. `````` Robbert Krebbers committed Feb 17, 2016 97 ``````Proof. `````` Ralf Jung committed Feb 17, 2016 98 `````` intros [Ps' ->]%contains_Permutation. by rewrite big_and_app and_elim_l. `````` Robbert Krebbers committed Feb 17, 2016 99 ``````Qed. `````` Robbert Krebbers committed May 24, 2016 100 ``````Lemma big_sep_contains Ps Qs : Qs `contains` Ps → [★] Ps ⊢ [★] Qs. `````` Robbert Krebbers committed Feb 17, 2016 101 ``````Proof. `````` Ralf Jung committed Feb 17, 2016 102 `````` intros [Ps' ->]%contains_Permutation. by rewrite big_sep_app sep_elim_l. `````` Robbert Krebbers committed Feb 17, 2016 103 104 ``````Qed. `````` Robbert Krebbers committed May 24, 2016 105 ``````Lemma big_sep_and Ps : [★] Ps ⊢ [∧] Ps. `````` Robbert Krebbers committed Feb 14, 2016 106 ``````Proof. by induction Ps as [|P Ps IH]; simpl; auto with I. Qed. `````` Robbert Krebbers committed Feb 17, 2016 107 `````` `````` Robbert Krebbers committed May 24, 2016 108 ``````Lemma big_and_elem_of Ps P : P ∈ Ps → [∧] Ps ⊢ P. `````` Robbert Krebbers committed Feb 14, 2016 109 ``````Proof. induction 1; simpl; auto with I. Qed. `````` Robbert Krebbers committed May 24, 2016 110 ``````Lemma big_sep_elem_of Ps P : P ∈ Ps → [★] Ps ⊢ P. `````` Robbert Krebbers committed Feb 14, 2016 111 112 ``````Proof. induction 1; simpl; auto with I. Qed. `````` Robbert Krebbers committed Aug 24, 2016 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 ``````(** ** Persistence *) Global Instance big_and_persistent Ps : PersistentL Ps → PersistentP ([∧] Ps). Proof. induction 1; apply _. Qed. Global Instance big_sep_persistent Ps : PersistentL Ps → PersistentP ([★] Ps). Proof. induction 1; apply _. Qed. Global Instance nil_persistent : PersistentL (@nil (uPred M)). Proof. constructor. Qed. Global Instance cons_persistent P Ps : PersistentP P → PersistentL Ps → PersistentL (P :: Ps). Proof. by constructor. Qed. Global Instance app_persistent Ps Ps' : PersistentL Ps → PersistentL Ps' → PersistentL (Ps ++ Ps'). Proof. apply Forall_app_2. Qed. Global Instance fmap_persistent {A} (f : A → uPred M) xs : (∀ x, PersistentP (f x)) → PersistentL (f <\$> xs). Proof. unfold PersistentL=> ?; induction xs; constructor; auto. Qed. Global Instance zip_with_persistent {A B} (f : A → B → uPred M) xs ys : (∀ x y, PersistentP (f x y)) → PersistentL (zip_with f xs ys). Proof. unfold PersistentL=> ?; revert ys; induction xs=> -[|??]; constructor; auto. Qed. (** ** Timelessness *) Global Instance big_and_timeless Ps : TimelessL Ps → TimelessP ([∧] Ps). Proof. induction 1; apply _. Qed. Global Instance big_sep_timeless Ps : TimelessL Ps → TimelessP ([★] Ps). Proof. induction 1; apply _. Qed. Global Instance nil_timeless : TimelessL (@nil (uPred M)). Proof. constructor. Qed. Global Instance cons_timeless P Ps : TimelessP P → TimelessL Ps → TimelessL (P :: Ps). Proof. by constructor. Qed. Global Instance app_timeless Ps Ps' : TimelessL Ps → TimelessL Ps' → TimelessL (Ps ++ Ps'). Proof. apply Forall_app_2. Qed. Global Instance fmap_timeless {A} (f : A → uPred M) xs : (∀ x, TimelessP (f x)) → TimelessL (f <\$> xs). Proof. unfold TimelessL=> ?; induction xs; constructor; auto. Qed. Global Instance zip_with_timeless {A B} (f : A → B → uPred M) xs ys : (∀ x y, TimelessP (f x y)) → TimelessL (zip_with f xs ys). Proof. unfold TimelessL=> ?; revert ys; induction xs=> -[|??]; constructor; auto. Qed. `````` Robbert Krebbers committed Apr 08, 2016 161 ``````(** ** Big ops over finite maps *) `````` Robbert Krebbers committed Feb 17, 2016 162 163 164 ``````Section gmap. Context `{Countable K} {A : Type}. Implicit Types m : gmap K A. `````` Robbert Krebbers committed Feb 18, 2016 165 `````` Implicit Types Φ Ψ : K → A → uPred M. `````` Robbert Krebbers committed Feb 14, 2016 166 `````` `````` Robbert Krebbers committed Feb 18, 2016 167 `````` Lemma big_sepM_mono Φ Ψ m1 m2 : `````` Robbert Krebbers committed May 30, 2016 168 `````` m2 ⊆ m1 → (∀ k x, m2 !! k = Some x → Φ k x ⊢ Ψ k x) → `````` Robbert Krebbers committed May 31, 2016 169 `````` ([★ map] k ↦ x ∈ m1, Φ k x) ⊢ [★ map] k ↦ x ∈ m2, Ψ k x. `````` Robbert Krebbers committed Feb 16, 2016 170 `````` Proof. `````` Robbert Krebbers committed May 24, 2016 171 `````` intros HX HΦ. trans ([★ map] k↦x ∈ m2, Φ k x)%I. `````` Robbert Krebbers committed Feb 17, 2016 172 `````` - by apply big_sep_contains, fmap_contains, map_to_list_contains. `````` Robbert Krebbers committed Mar 21, 2016 173 `````` - apply big_sep_mono', Forall2_fmap, Forall_Forall2. `````` Robbert Krebbers committed Feb 18, 2016 174 `````` apply Forall_forall=> -[i x] ? /=. by apply HΦ, elem_of_map_to_list. `````` Robbert Krebbers committed Feb 16, 2016 175 `````` Qed. `````` Robbert Krebbers committed Jul 22, 2016 176 177 178 `````` Lemma big_sepM_proper Φ Ψ m : (∀ k x, m !! k = Some x → Φ k x ⊣⊢ Ψ k x) → ([★ map] k ↦ x ∈ m, Φ k x) ⊣⊢ ([★ map] k ↦ x ∈ m, Ψ k x). `````` Robbert Krebbers committed Jul 25, 2016 179 180 181 182 `````` Proof. intros ?; apply (anti_symm (⊢)); apply big_sepM_mono; eauto using equiv_entails, equiv_entails_sym, lookup_weaken. Qed. `````` Robbert Krebbers committed Feb 17, 2016 183 184 185 186 187 `````` Global Instance big_sepM_ne m n : Proper (pointwise_relation _ (pointwise_relation _ (dist n)) ==> (dist n)) (uPred_big_sepM (M:=M) m). Proof. `````` Robbert Krebbers committed Feb 18, 2016 188 `````` intros Φ1 Φ2 HΦ. apply big_sep_ne, Forall2_fmap. `````` Robbert Krebbers committed Mar 21, 2016 189 `````` apply Forall_Forall2, Forall_true=> -[i x]; apply HΦ. `````` Robbert Krebbers committed Feb 17, 2016 190 `````` Qed. `````` Robbert Krebbers committed Apr 11, 2016 191 `````` Global Instance big_sepM_proper' m : `````` Ralf Jung committed Mar 10, 2016 192 `````` Proper (pointwise_relation _ (pointwise_relation _ (⊣⊢)) ==> (⊣⊢)) `````` Robbert Krebbers committed Feb 17, 2016 193 `````` (uPred_big_sepM (M:=M) m). `````` Robbert Krebbers committed Apr 11, 2016 194 `````` Proof. intros Φ1 Φ2 HΦ. by apply big_sepM_proper; intros; last apply HΦ. Qed. `````` Robbert Krebbers committed Feb 17, 2016 195 `````` Global Instance big_sepM_mono' m : `````` Ralf Jung committed Mar 10, 2016 196 `````` Proper (pointwise_relation _ (pointwise_relation _ (⊢)) ==> (⊢)) `````` Robbert Krebbers committed Feb 17, 2016 197 `````` (uPred_big_sepM (M:=M) m). `````` Robbert Krebbers committed Apr 11, 2016 198 `````` Proof. intros Φ1 Φ2 HΦ. by apply big_sepM_mono; intros; last apply HΦ. Qed. `````` Robbert Krebbers committed Feb 17, 2016 199 `````` `````` Robbert Krebbers committed May 24, 2016 200 `````` Lemma big_sepM_empty Φ : ([★ map] k↦x ∈ ∅, Φ k x) ⊣⊢ True. `````` Robbert Krebbers committed Feb 17, 2016 201 `````` Proof. by rewrite /uPred_big_sepM map_to_list_empty. Qed. `````` Robbert Krebbers committed May 30, 2016 202 `````` `````` Robbert Krebbers committed May 31, 2016 203 `````` Lemma big_sepM_insert Φ m i x : `````` Robbert Krebbers committed May 24, 2016 204 `````` m !! i = None → `````` Robbert Krebbers committed May 31, 2016 205 `````` ([★ map] k↦y ∈ <[i:=x]> m, Φ k y) ⊣⊢ Φ i x ★ [★ map] k↦y ∈ m, Φ k y. `````` Robbert Krebbers committed Feb 17, 2016 206 `````` Proof. intros ?; by rewrite /uPred_big_sepM map_to_list_insert. Qed. `````` Robbert Krebbers committed May 30, 2016 207 `````` `````` Robbert Krebbers committed May 31, 2016 208 `````` Lemma big_sepM_delete Φ m i x : `````` Robbert Krebbers committed May 24, 2016 209 `````` m !! i = Some x → `````` Robbert Krebbers committed May 31, 2016 210 `````` ([★ map] k↦y ∈ m, Φ k y) ⊣⊢ Φ i x ★ [★ map] k↦y ∈ delete i m, Φ k y. `````` Robbert Krebbers committed May 31, 2016 211 212 213 214 `````` Proof. intros. rewrite -big_sepM_insert ?lookup_delete //. by rewrite insert_delete insert_id. Qed. `````` Robbert Krebbers committed May 30, 2016 215 `````` `````` Robbert Krebbers committed May 31, 2016 216 217 218 219 `````` Lemma big_sepM_lookup Φ m i x : m !! i = Some x → ([★ map] k↦y ∈ m, Φ k y) ⊢ Φ i x. Proof. intros. by rewrite big_sepM_delete // sep_elim_l. Qed. `````` Robbert Krebbers committed May 24, 2016 220 `````` Lemma big_sepM_singleton Φ i x : ([★ map] k↦y ∈ {[i:=x]}, Φ k y) ⊣⊢ Φ i x. `````` Robbert Krebbers committed Feb 14, 2016 221 222 223 224 `````` Proof. rewrite -insert_empty big_sepM_insert/=; last auto using lookup_empty. by rewrite big_sepM_empty right_id. Qed. `````` Ralf Jung committed Feb 17, 2016 225 `````` `````` Robbert Krebbers committed May 31, 2016 226 227 228 229 230 231 232 `````` Lemma big_sepM_fmap {B} (f : A → B) (Φ : K → B → uPred M) m : ([★ map] k↦y ∈ f <\$> m, Φ k y) ⊣⊢ ([★ map] k↦y ∈ m, Φ k (f y)). Proof. rewrite /uPred_big_sepM map_to_list_fmap -list_fmap_compose. f_equiv; apply reflexive_eq, list_fmap_ext. by intros []. done. Qed. `````` Robbert Krebbers committed May 31, 2016 233 `````` Lemma big_sepM_insert_override (Φ : K → uPred M) m i x y : `````` Robbert Krebbers committed May 31, 2016 234 `````` m !! i = Some x → `````` Robbert Krebbers committed May 31, 2016 235 `````` ([★ map] k↦_ ∈ <[i:=y]> m, Φ k) ⊣⊢ ([★ map] k↦_ ∈ m, Φ k). `````` Robbert Krebbers committed May 31, 2016 236 237 238 239 240 `````` Proof. intros. rewrite -insert_delete big_sepM_insert ?lookup_delete //. by rewrite -big_sepM_delete. Qed. `````` Robbert Krebbers committed Jun 01, 2016 241 `````` Lemma big_sepM_fn_insert {B} (Ψ : K → A → B → uPred M) (f : K → B) m i x b : `````` Robbert Krebbers committed May 31, 2016 242 `````` m !! i = None → `````` Robbert Krebbers committed Jun 01, 2016 243 244 `````` ([★ map] k↦y ∈ <[i:=x]> m, Ψ k y (<[i:=b]> f k)) ⊣⊢ (Ψ i x b ★ [★ map] k↦y ∈ m, Ψ k y (f k)). `````` Robbert Krebbers committed May 31, 2016 245 246 `````` Proof. intros. rewrite big_sepM_insert // fn_lookup_insert. `````` Robbert Krebbers committed Jul 22, 2016 247 `````` apply sep_proper, big_sepM_proper; auto=> k y ?. `````` Robbert Krebbers committed May 31, 2016 248 249 250 251 252 253 254 `````` by rewrite fn_lookup_insert_ne; last set_solver. Qed. Lemma big_sepM_fn_insert' (Φ : K → uPred M) m i x P : m !! i = None → ([★ map] k↦y ∈ <[i:=x]> m, <[i:=P]> Φ k) ⊣⊢ (P ★ [★ map] k↦y ∈ m, Φ k). Proof. apply (big_sepM_fn_insert (λ _ _, id)). Qed. `````` Robbert Krebbers committed Feb 18, 2016 255 `````` Lemma big_sepM_sepM Φ Ψ m : `````` Robbert Krebbers committed May 24, 2016 256 `````` ([★ map] k↦x ∈ m, Φ k x ★ Ψ k x) `````` Robbert Krebbers committed May 31, 2016 257 `````` ⊣⊢ ([★ map] k↦x ∈ m, Φ k x) ★ ([★ map] k↦x ∈ m, Ψ k x). `````` Ralf Jung committed Feb 17, 2016 258 `````` Proof. `````` Robbert Krebbers committed Feb 17, 2016 259 260 `````` rewrite /uPred_big_sepM. induction (map_to_list m) as [|[i x] l IH]; csimpl; rewrite ?right_id //. `````` Robbert Krebbers committed Feb 18, 2016 261 `````` by rewrite IH -!assoc (assoc _ (Ψ _ _)) [(Ψ _ _ ★ _)%I]comm -!assoc. `````` Ralf Jung committed Feb 17, 2016 262 `````` Qed. `````` Robbert Krebbers committed May 31, 2016 263 `````` `````` Robbert Krebbers committed May 24, 2016 264 `````` Lemma big_sepM_later Φ m : `````` Robbert Krebbers committed May 31, 2016 265 `````` ▷ ([★ map] k↦x ∈ m, Φ k x) ⊣⊢ ([★ map] k↦x ∈ m, ▷ Φ k x). `````` Ralf Jung committed Feb 17, 2016 266 `````` Proof. `````` Robbert Krebbers committed Feb 17, 2016 267 268 269 `````` rewrite /uPred_big_sepM. induction (map_to_list m) as [|[i x] l IH]; csimpl; rewrite ?later_True //. by rewrite later_sep IH. `````` Ralf Jung committed Feb 17, 2016 270 `````` Qed. `````` Robbert Krebbers committed May 31, 2016 271 272 273 274 275 `````` Lemma big_sepM_always Φ m : (□ [★ map] k↦x ∈ m, Φ k x) ⊣⊢ ([★ map] k↦x ∈ m, □ Φ k x). Proof. rewrite /uPred_big_sepM. `````` Robbert Krebbers committed Jun 24, 2016 276 `````` induction (map_to_list m) as [|[i x] l IH]; csimpl; rewrite ?always_pure //. `````` Robbert Krebbers committed May 31, 2016 277 278 279 280 `````` by rewrite always_sep IH. Qed. Lemma big_sepM_always_if p Φ m : `````` Robbert Krebbers committed May 31, 2016 281 `````` □?p ([★ map] k↦x ∈ m, Φ k x) ⊣⊢ ([★ map] k↦x ∈ m, □?p Φ k x). `````` Robbert Krebbers committed May 31, 2016 282 `````` Proof. destruct p; simpl; auto using big_sepM_always. Qed. `````` Robbert Krebbers committed May 31, 2016 283 284 285 286 287 288 289 `````` Lemma big_sepM_forall Φ m : (∀ k x, PersistentP (Φ k x)) → ([★ map] k↦x ∈ m, Φ k x) ⊣⊢ (∀ k x, m !! k = Some x → Φ k x). Proof. intros. apply (anti_symm _). { apply forall_intro=> k; apply forall_intro=> x. `````` Robbert Krebbers committed Jun 24, 2016 290 `````` apply impl_intro_l, pure_elim_l=> ?; by apply big_sepM_lookup. } `````` Robbert Krebbers committed May 31, 2016 291 292 293 `````` rewrite /uPred_big_sepM. setoid_rewrite <-elem_of_map_to_list. induction (map_to_list m) as [|[i x] l IH]; csimpl; auto. rewrite -always_and_sep_l; apply and_intro. `````` Robbert Krebbers committed Jun 24, 2016 294 `````` - rewrite (forall_elim i) (forall_elim x) pure_equiv; last by left. `````` Robbert Krebbers committed May 31, 2016 295 296 `````` by rewrite True_impl. - rewrite -IH. apply forall_mono=> k; apply forall_mono=> y. `````` Robbert Krebbers committed Jun 24, 2016 297 `````` apply impl_intro_l, pure_elim_l=> ?. rewrite pure_equiv; last by right. `````` Robbert Krebbers committed May 31, 2016 298 299 300 301 `````` by rewrite True_impl. Qed. Lemma big_sepM_impl Φ Ψ m : `````` Robbert Krebbers committed May 31, 2016 302 `````` □ (∀ k x, m !! k = Some x → Φ k x → Ψ k x) ∧ ([★ map] k↦x ∈ m, Φ k x) `````` Robbert Krebbers committed May 31, 2016 303 304 305 `````` ⊢ [★ map] k↦x ∈ m, Ψ k x. Proof. rewrite always_and_sep_l. do 2 setoid_rewrite always_forall. `````` Robbert Krebbers committed Jun 24, 2016 306 `````` setoid_rewrite always_impl; setoid_rewrite always_pure. `````` Robbert Krebbers committed May 31, 2016 307 308 309 `````` rewrite -big_sepM_forall -big_sepM_sepM. apply big_sepM_mono; auto=> k x ?. by rewrite -always_wand_impl always_elim wand_elim_l. Qed. `````` Robbert Krebbers committed Aug 24, 2016 310 311 312 313 314 315 316 317 `````` Global Instance big_sepM_persistent Φ m : (∀ k x, PersistentP (Φ k x)) → PersistentP ([★ map] k↦x ∈ m, Φ k x). Proof. intros. apply big_sep_persistent, fmap_persistent=>-[??] /=; auto. Qed. Global Instance big_sepM_timeless Φ m : (∀ k x, TimelessP (Φ k x)) → TimelessP ([★ map] k↦x ∈ m, Φ k x). Proof. intro. apply big_sep_timeless, fmap_timeless=> -[??] /=; auto. Qed. `````` Robbert Krebbers committed Feb 17, 2016 318 319 ``````End gmap. `````` Robbert Krebbers committed Apr 08, 2016 320 ``````(** ** Big ops over finite sets *) `````` Robbert Krebbers committed Feb 17, 2016 321 322 323 ``````Section gset. Context `{Countable A}. Implicit Types X : gset A. `````` Robbert Krebbers committed Feb 18, 2016 324 `````` Implicit Types Φ : A → uPred M. `````` Robbert Krebbers committed Feb 17, 2016 325 `````` `````` Robbert Krebbers committed Feb 18, 2016 326 `````` Lemma big_sepS_mono Φ Ψ X Y : `````` Robbert Krebbers committed May 24, 2016 327 `````` Y ⊆ X → (∀ x, x ∈ Y → Φ x ⊢ Ψ x) → `````` Robbert Krebbers committed May 31, 2016 328 `````` ([★ set] x ∈ X, Φ x) ⊢ [★ set] x ∈ Y, Ψ x. `````` Robbert Krebbers committed Feb 17, 2016 329 `````` Proof. `````` Robbert Krebbers committed May 24, 2016 330 `````` intros HX HΦ. trans ([★ set] x ∈ Y, Φ x)%I. `````` Robbert Krebbers committed Feb 17, 2016 331 `````` - by apply big_sep_contains, fmap_contains, elements_contains. `````` Robbert Krebbers committed Mar 21, 2016 332 `````` - apply big_sep_mono', Forall2_fmap, Forall_Forall2. `````` Robbert Krebbers committed Feb 18, 2016 333 `````` apply Forall_forall=> x ? /=. by apply HΦ, elem_of_elements. `````` Robbert Krebbers committed Feb 17, 2016 334 `````` Qed. `````` Robbert Krebbers committed Apr 11, 2016 335 `````` Lemma big_sepS_proper Φ Ψ X Y : `````` Robbert Krebbers committed May 24, 2016 336 337 `````` X ≡ Y → (∀ x, x ∈ X → x ∈ Y → Φ x ⊣⊢ Ψ x) → ([★ set] x ∈ X, Φ x) ⊣⊢ ([★ set] x ∈ Y, Ψ x). `````` Robbert Krebbers committed Apr 11, 2016 338 `````` Proof. `````` Robbert Krebbers committed Jul 22, 2016 339 340 `````` move=> /collection_equiv_spec [??] ?; apply (anti_symm (⊢)); apply big_sepS_mono; eauto using equiv_entails, equiv_entails_sym. `````` Robbert Krebbers committed Apr 11, 2016 341 `````` Qed. `````` Robbert Krebbers committed Feb 17, 2016 342 343 344 345 `````` Lemma big_sepS_ne X n : Proper (pointwise_relation _ (dist n) ==> dist n) (uPred_big_sepS (M:=M) X). Proof. `````` Robbert Krebbers committed Feb 18, 2016 346 `````` intros Φ1 Φ2 HΦ. apply big_sep_ne, Forall2_fmap. `````` Robbert Krebbers committed Mar 21, 2016 347 `````` apply Forall_Forall2, Forall_true=> x; apply HΦ. `````` Robbert Krebbers committed Feb 17, 2016 348 `````` Qed. `````` Robbert Krebbers committed Apr 11, 2016 349 `````` Lemma big_sepS_proper' X : `````` Ralf Jung committed Mar 10, 2016 350 `````` Proper (pointwise_relation _ (⊣⊢) ==> (⊣⊢)) (uPred_big_sepS (M:=M) X). `````` Robbert Krebbers committed Apr 11, 2016 351 `````` Proof. intros Φ1 Φ2 HΦ. apply big_sepS_proper; naive_solver. Qed. `````` Robbert Krebbers committed Feb 17, 2016 352 `````` Lemma big_sepS_mono' X : `````` Ralf Jung committed Mar 10, 2016 353 `````` Proper (pointwise_relation _ (⊢) ==> (⊢)) (uPred_big_sepS (M:=M) X). `````` Robbert Krebbers committed Feb 18, 2016 354 `````` Proof. intros Φ1 Φ2 HΦ. apply big_sepS_mono; naive_solver. Qed. `````` Robbert Krebbers committed Feb 17, 2016 355 `````` `````` Robbert Krebbers committed May 24, 2016 356 `````` Lemma big_sepS_empty Φ : ([★ set] x ∈ ∅, Φ x) ⊣⊢ True. `````` Robbert Krebbers committed Feb 17, 2016 357 `````` Proof. by rewrite /uPred_big_sepS elements_empty. Qed. `````` Robbert Krebbers committed Apr 11, 2016 358 `````` `````` Robbert Krebbers committed Feb 18, 2016 359 `````` Lemma big_sepS_insert Φ X x : `````` Robbert Krebbers committed May 24, 2016 360 `````` x ∉ X → ([★ set] y ∈ {[ x ]} ∪ X, Φ y) ⊣⊢ (Φ x ★ [★ set] y ∈ X, Φ y). `````` Robbert Krebbers committed Feb 17, 2016 361 `````` Proof. intros. by rewrite /uPred_big_sepS elements_union_singleton. Qed. `````` Robbert Krebbers committed Jun 01, 2016 362 `````` Lemma big_sepS_fn_insert {B} (Ψ : A → B → uPred M) f X x b : `````` Robbert Krebbers committed Apr 11, 2016 363 `````` x ∉ X → `````` Robbert Krebbers committed Jun 01, 2016 364 365 `````` ([★ set] y ∈ {[ x ]} ∪ X, Ψ y (<[x:=b]> f y)) ⊣⊢ (Ψ x b ★ [★ set] y ∈ X, Ψ y (f y)). `````` Robbert Krebbers committed Apr 11, 2016 366 367 368 369 370 `````` Proof. intros. rewrite big_sepS_insert // fn_lookup_insert. apply sep_proper, big_sepS_proper; auto=> y ??. by rewrite fn_lookup_insert_ne; last set_solver. Qed. `````` Robbert Krebbers committed May 30, 2016 371 `````` Lemma big_sepS_fn_insert' Φ X x P : `````` Robbert Krebbers committed May 24, 2016 372 `````` x ∉ X → ([★ set] y ∈ {[ x ]} ∪ X, <[x:=P]> Φ y) ⊣⊢ (P ★ [★ set] y ∈ X, Φ y). `````` Robbert Krebbers committed May 30, 2016 373 `````` Proof. apply (big_sepS_fn_insert (λ y, id)). Qed. `````` Robbert Krebbers committed Apr 11, 2016 374 `````` `````` Robbert Krebbers committed Feb 18, 2016 375 `````` Lemma big_sepS_delete Φ X x : `````` Robbert Krebbers committed May 31, 2016 376 `````` x ∈ X → ([★ set] y ∈ X, Φ y) ⊣⊢ Φ x ★ [★ set] y ∈ X ∖ {[ x ]}, Φ y. `````` Robbert Krebbers committed Feb 17, 2016 377 `````` Proof. `````` Robbert Krebbers committed Feb 17, 2016 378 379 `````` intros. rewrite -big_sepS_insert; last set_solver. by rewrite -union_difference_L; last set_solver. `````` Robbert Krebbers committed Feb 17, 2016 380 `````` Qed. `````` Robbert Krebbers committed Apr 11, 2016 381 `````` `````` Robbert Krebbers committed May 31, 2016 382 383 384 `````` Lemma big_sepS_elem_of Φ X x : x ∈ X → ([★ set] y ∈ X, Φ y) ⊢ Φ x. Proof. intros. by rewrite big_sepS_delete // sep_elim_l. Qed. `````` Robbert Krebbers committed May 24, 2016 385 `````` Lemma big_sepS_singleton Φ x : ([★ set] y ∈ {[ x ]}, Φ y) ⊣⊢ Φ x. `````` Robbert Krebbers committed Feb 17, 2016 386 `````` Proof. intros. by rewrite /uPred_big_sepS elements_singleton /= right_id. Qed. `````` Ralf Jung committed Feb 17, 2016 387 `````` `````` Robbert Krebbers committed Feb 18, 2016 388 `````` Lemma big_sepS_sepS Φ Ψ X : `````` Robbert Krebbers committed May 31, 2016 389 `````` ([★ set] y ∈ X, Φ y ★ Ψ y) ⊣⊢ ([★ set] y ∈ X, Φ y) ★ ([★ set] y ∈ X, Ψ y). `````` Ralf Jung committed Feb 17, 2016 390 `````` Proof. `````` Robbert Krebbers committed Feb 17, 2016 391 392 `````` rewrite /uPred_big_sepS. induction (elements X) as [|x l IH]; csimpl; first by rewrite ?right_id. `````` Robbert Krebbers committed Feb 18, 2016 393 `````` by rewrite IH -!assoc (assoc _ (Ψ _)) [(Ψ _ ★ _)%I]comm -!assoc. `````` Ralf Jung committed Feb 17, 2016 394 395 `````` Qed. `````` Robbert Krebbers committed May 31, 2016 396 `````` Lemma big_sepS_later Φ X : ▷ ([★ set] y ∈ X, Φ y) ⊣⊢ ([★ set] y ∈ X, ▷ Φ y). `````` Ralf Jung committed Feb 17, 2016 397 `````` Proof. `````` Robbert Krebbers committed Feb 17, 2016 398 399 400 `````` rewrite /uPred_big_sepS. induction (elements X) as [|x l IH]; csimpl; first by rewrite ?later_True. by rewrite later_sep IH. `````` Ralf Jung committed Feb 17, 2016 401 `````` Qed. `````` Robbert Krebbers committed May 31, 2016 402 `````` `````` Robbert Krebbers committed May 31, 2016 403 `````` Lemma big_sepS_always Φ X : □ ([★ set] y ∈ X, Φ y) ⊣⊢ ([★ set] y ∈ X, □ Φ y). `````` Robbert Krebbers committed May 31, 2016 404 405 `````` Proof. rewrite /uPred_big_sepS. `````` Robbert Krebbers committed Jun 24, 2016 406 `````` induction (elements X) as [|x l IH]; csimpl; first by rewrite ?always_pure. `````` Robbert Krebbers committed May 31, 2016 407 408 409 410 `````` by rewrite always_sep IH. Qed. Lemma big_sepS_always_if q Φ X : `````` Robbert Krebbers committed May 31, 2016 411 `````` □?q ([★ set] y ∈ X, Φ y) ⊣⊢ ([★ set] y ∈ X, □?q Φ y). `````` Robbert Krebbers committed May 31, 2016 412 `````` Proof. destruct q; simpl; auto using big_sepS_always. Qed. `````` Robbert Krebbers committed May 31, 2016 413 414 415 416 417 418 `````` Lemma big_sepS_forall Φ X : (∀ x, PersistentP (Φ x)) → ([★ set] x ∈ X, Φ x) ⊣⊢ (∀ x, ■ (x ∈ X) → Φ x). Proof. intros. apply (anti_symm _). { apply forall_intro=> x. `````` Robbert Krebbers committed Jun 24, 2016 419 `````` apply impl_intro_l, pure_elim_l=> ?; by apply big_sepS_elem_of. } `````` Robbert Krebbers committed May 31, 2016 420 421 422 `````` rewrite /uPred_big_sepS. setoid_rewrite <-elem_of_elements. induction (elements X) as [|x l IH]; csimpl; auto. rewrite -always_and_sep_l; apply and_intro. `````` Robbert Krebbers committed Jun 24, 2016 423 `````` - rewrite (forall_elim x) pure_equiv; last by left. by rewrite True_impl. `````` Robbert Krebbers committed May 31, 2016 424 `````` - rewrite -IH. apply forall_mono=> y. `````` Robbert Krebbers committed Jun 24, 2016 425 `````` apply impl_intro_l, pure_elim_l=> ?. rewrite pure_equiv; last by right. `````` Robbert Krebbers committed May 31, 2016 426 427 428 429 `````` by rewrite True_impl. Qed. Lemma big_sepS_impl Φ Ψ X : `````` Robbert Krebbers committed May 31, 2016 430 `````` □ (∀ x, ■ (x ∈ X) → Φ x → Ψ x) ∧ ([★ set] x ∈ X, Φ x) ⊢ [★ set] x ∈ X, Ψ x. `````` Robbert Krebbers committed May 31, 2016 431 432 `````` Proof. rewrite always_and_sep_l always_forall. `````` Robbert Krebbers committed Jun 24, 2016 433 `````` setoid_rewrite always_impl; setoid_rewrite always_pure. `````` Robbert Krebbers committed May 31, 2016 434 435 436 `````` rewrite -big_sepS_forall -big_sepS_sepS. apply big_sepS_mono; auto=> x ?. by rewrite -always_wand_impl always_elim wand_elim_l. Qed. `````` Robbert Krebbers committed Feb 14, 2016 437 `````` `````` Robbert Krebbers committed Aug 24, 2016 438 439 440 `````` Global Instance big_sepS_persistent Φ X : (∀ x, PersistentP (Φ x)) → PersistentP ([★ set] x ∈ X, Φ x). Proof. rewrite /uPred_big_sepS. apply _. Qed. `````` Robbert Krebbers committed Feb 14, 2016 441 `````` `````` Robbert Krebbers committed Aug 24, 2016 442 443 444 445 `````` Global Instance big_sepS_timeless Φ X : (∀ x, TimelessP (Φ x)) → TimelessP ([★ set] x ∈ X, Φ x). Proof. rewrite /uPred_big_sepS. apply _. Qed. End gset. `````` Robbert Krebbers committed Feb 16, 2016 446 ``End big_op.``