big_op.v 23.3 KB
 Robbert Krebbers committed Aug 17, 2017 1 ``````From stdpp Require Export functions gmap gmultiset. `````` Jacques-Henri Jourdan committed Sep 13, 2019 2 ``````From iris.algebra Require Export monoid. `````` Robbert Krebbers committed Mar 24, 2017 3 4 5 ``````Set Default Proof Using "Type*". Local Existing Instances monoid_ne monoid_assoc monoid_comm monoid_left_id monoid_right_id monoid_proper `````` Robbert Krebbers committed Aug 17, 2017 6 7 `````` monoid_homomorphism_rel_po monoid_homomorphism_rel_proper monoid_homomorphism_op_proper `````` Robbert Krebbers committed Mar 24, 2017 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 `````` monoid_homomorphism_ne weak_monoid_homomorphism_proper. (** We define the following big operators with binders build in: - The operator [ [^o list] k ↦ x ∈ l, P ] folds over a list [l]. The binder [x] refers to each element at index [k]. - The operator [ [^o map] k ↦ x ∈ m, P ] folds over a map [m]. The binder [x] refers to each element at index [k]. - The operator [ [^o set] x ∈ X, P ] folds over a set [X]. The binder [x] refers to each element. Since these big operators are like quantifiers, they have the same precedence as [∀] and [∃]. *) (** * Big ops over lists *) Fixpoint big_opL `{Monoid M o} {A} (f : nat → A → M) (xs : list A) : M := match xs with | [] => monoid_unit | x :: xs => o (f 0 x) (big_opL (λ n, f (S n)) xs) end. `````` Maxime Dénès committed Jan 24, 2019 28 ``````Instance: Params (@big_opL) 4 := {}. `````` Robbert Krebbers committed Mar 24, 2017 29 ``````Arguments big_opL {M} o {_ A} _ !_ /. `````` Robbert Krebbers committed Mar 24, 2017 30 ``````Typeclasses Opaque big_opL. `````` Robbert Krebbers committed Mar 24, 2017 31 32 ``````Notation "'[^' o 'list]' k ↦ x ∈ l , P" := (big_opL o (λ k x, P) l) (at level 200, o at level 1, l at level 10, k, x at level 1, right associativity, `````` Robbert Krebbers committed Nov 11, 2017 33 `````` format "[^ o list] k ↦ x ∈ l , P") : stdpp_scope. `````` Robbert Krebbers committed Mar 24, 2017 34 35 ``````Notation "'[^' o 'list]' x ∈ l , P" := (big_opL o (λ _ x, P) l) (at level 200, o at level 1, l at level 10, x at level 1, right associativity, `````` Robbert Krebbers committed Nov 11, 2017 36 `````` format "[^ o list] x ∈ l , P") : stdpp_scope. `````` Robbert Krebbers committed Mar 24, 2017 37 `````` `````` Michael Sammler committed Jan 16, 2020 38 39 40 41 42 43 ``````Definition big_opM_def `{Monoid M o} `{Countable K} {A} (f : K → A → M) (m : gmap K A) : M := big_opL o (λ _, curry f) (map_to_list m). Definition big_opM_aux : seal (@big_opM_def). by eexists. Qed. Definition big_opM := big_opM_aux.(unseal). Arguments big_opM {M} o {_ K _ _ A} _ _. Definition big_opM_eq : @big_opM = @big_opM_def := big_opM_aux.(seal_eq). `````` Maxime Dénès committed Jan 24, 2019 44 ``````Instance: Params (@big_opM) 7 := {}. `````` Robbert Krebbers committed Mar 24, 2017 45 46 ``````Notation "'[^' o 'map]' k ↦ x ∈ m , P" := (big_opM o (λ k x, P) m) (at level 200, o at level 1, m at level 10, k, x at level 1, right associativity, `````` Robbert Krebbers committed Nov 11, 2017 47 `````` format "[^ o map] k ↦ x ∈ m , P") : stdpp_scope. `````` Robbert Krebbers committed Mar 24, 2017 48 49 ``````Notation "'[^' o 'map]' x ∈ m , P" := (big_opM o (λ _ x, P) m) (at level 200, o at level 1, m at level 10, x at level 1, right associativity, `````` Robbert Krebbers committed Nov 11, 2017 50 `````` format "[^ o map] x ∈ m , P") : stdpp_scope. `````` Robbert Krebbers committed Mar 24, 2017 51 `````` `````` Michael Sammler committed Jan 16, 2020 52 ``````Definition big_opS_def `{Monoid M o} `{Countable A} (f : A → M) `````` Robbert Krebbers committed Mar 24, 2017 53 `````` (X : gset A) : M := big_opL o (λ _, f) (elements X). `````` Michael Sammler committed Jan 16, 2020 54 55 56 57 ``````Definition big_opS_aux : seal (@big_opS_def). by eexists. Qed. Definition big_opS := big_opS_aux.(unseal). Arguments big_opS {M} o {_ A _ _} _ _. Definition big_opS_eq : @big_opS = @big_opS_def := big_opS_aux.(seal_eq). `````` Maxime Dénès committed Jan 24, 2019 58 ``````Instance: Params (@big_opS) 6 := {}. `````` Robbert Krebbers committed Mar 24, 2017 59 60 ``````Notation "'[^' o 'set]' x ∈ X , P" := (big_opS o (λ x, P) X) (at level 200, o at level 1, X at level 10, x at level 1, right associativity, `````` Robbert Krebbers committed Nov 11, 2017 61 `````` format "[^ o set] x ∈ X , P") : stdpp_scope. `````` Robbert Krebbers committed Mar 24, 2017 62 `````` `````` Michael Sammler committed Jan 16, 2020 63 ``````Definition big_opMS_def `{Monoid M o} `{Countable A} (f : A → M) `````` Robbert Krebbers committed Mar 24, 2017 64 `````` (X : gmultiset A) : M := big_opL o (λ _, f) (elements X). `````` Michael Sammler committed Jan 16, 2020 65 66 67 68 69 ``````Definition big_opMS_aux : seal (@big_opMS_def). by eexists. Qed. Definition big_opMS := big_opMS_aux.(unseal). Arguments big_opMS {M} o {_ A _ _} _ _. Definition big_opMS_eq : @big_opMS = @big_opMS_def := big_opMS_aux.(seal_eq). Instance: Params (@big_opMS) 6 := {}. `````` Robbert Krebbers committed Mar 24, 2017 70 71 ``````Notation "'[^' o 'mset]' x ∈ X , P" := (big_opMS o (λ x, P) X) (at level 200, o at level 1, X at level 10, x at level 1, right associativity, `````` Robbert Krebbers committed Nov 11, 2017 72 `````` format "[^ o mset] x ∈ X , P") : stdpp_scope. `````` Robbert Krebbers committed Mar 24, 2017 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 `````` (** * Properties about big ops *) Section big_op. Context `{Monoid M o}. Implicit Types xs : list M. Infix "`o`" := o (at level 50, left associativity). (** ** Big ops over lists *) Section list. Context {A : Type}. Implicit Types l : list A. Implicit Types f g : nat → A → M. Lemma big_opL_nil f : ([^o list] k↦y ∈ [], f k y) = monoid_unit. Proof. done. Qed. Lemma big_opL_cons f x l : ([^o list] k↦y ∈ x :: l, f k y) = f 0 x `o` [^o list] k↦y ∈ l, f (S k) y. Proof. done. Qed. Lemma big_opL_singleton f x : ([^o list] k↦y ∈ [x], f k y) ≡ f 0 x. Proof. by rewrite /= right_id. Qed. Lemma big_opL_app f l1 l2 : ([^o list] k↦y ∈ l1 ++ l2, f k y) ≡ ([^o list] k↦y ∈ l1, f k y) `o` ([^o list] k↦y ∈ l2, f (length l1 + k) y). Proof. revert f. induction l1 as [|x l1 IH]=> f /=; first by rewrite left_id. by rewrite IH assoc. Qed. `````` Robbert Krebbers committed Jun 12, 2017 101 102 103 `````` Lemma big_opL_unit l : ([^o list] k↦y ∈ l, monoid_unit) ≡ (monoid_unit : M). Proof. induction l; rewrite /= ?left_id //. Qed. `````` Robbert Krebbers committed Mar 24, 2017 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 `````` Lemma big_opL_forall R f g l : Reflexive R → Proper (R ==> R ==> R) o → (∀ k y, l !! k = Some y → R (f k y) (g k y)) → R ([^o list] k ↦ y ∈ l, f k y) ([^o list] k ↦ y ∈ l, g k y). Proof. intros ??. revert f g. induction l as [|x l IH]=> f g ? //=; f_equiv; eauto. Qed. Lemma big_opL_ext f g l : (∀ k y, l !! k = Some y → f k y = g k y) → ([^o list] k ↦ y ∈ l, f k y) = [^o list] k ↦ y ∈ l, g k y. Proof. apply big_opL_forall; apply _. Qed. Lemma big_opL_proper f g l : (∀ k y, l !! k = Some y → f k y ≡ g k y) → ([^o list] k ↦ y ∈ l, f k y) ≡ ([^o list] k ↦ y ∈ l, g k y). Proof. apply big_opL_forall; apply _. Qed. Lemma big_opL_permutation (f : A → M) l1 l2 : l1 ≡ₚ l2 → ([^o list] x ∈ l1, f x) ≡ ([^o list] x ∈ l2, f x). Proof. induction 1 as [|x xs1 xs2 ? IH|x y xs|xs1 xs2 xs3]; simpl; auto. - by rewrite IH. - by rewrite !assoc (comm _ (f x)). - by etrans. Qed. Global Instance big_opL_permutation' (f : A → M) : Proper ((≡ₚ) ==> (≡)) (big_opL o (λ _, f)). Proof. intros xs1 xs2. apply big_opL_permutation. Qed. Global Instance big_opL_ne n : Proper (pointwise_relation _ (pointwise_relation _ (dist n)) ==> eq ==> dist n) (big_opL o (A:=A)). `````` Robbert Krebbers committed Sep 06, 2019 137 `````` Proof. intros f f' Hf l ? <-. apply big_opL_forall; apply _ || intros; apply Hf. Qed. `````` Robbert Krebbers committed Mar 24, 2017 138 139 140 `````` Global Instance big_opL_proper' : Proper (pointwise_relation _ (pointwise_relation _ (≡)) ==> eq ==> (≡)) (big_opL o (A:=A)). `````` Robbert Krebbers committed Sep 06, 2019 141 `````` Proof. intros f f' Hf l ? <-. apply big_opL_forall; apply _ || intros; apply Hf. Qed. `````` Robbert Krebbers committed Mar 24, 2017 142 143 144 145 146 147 148 149 150 151 152 153 `````` Lemma big_opL_consZ_l (f : Z → A → M) x l : ([^o list] k↦y ∈ x :: l, f k y) = f 0 x `o` [^o list] k↦y ∈ l, f (1 + k)%Z y. Proof. rewrite big_opL_cons. auto using big_opL_ext with f_equal lia. Qed. Lemma big_opL_consZ_r (f : Z → A → M) x l : ([^o list] k↦y ∈ x :: l, f k y) = f 0 x `o` [^o list] k↦y ∈ l, f (k + 1)%Z y. Proof. rewrite big_opL_cons. auto using big_opL_ext with f_equal lia. Qed. Lemma big_opL_fmap {B} (h : A → B) (f : nat → B → M) l : ([^o list] k↦y ∈ h <\$> l, f k y) ≡ ([^o list] k↦y ∈ l, f k (h y)). Proof. revert f. induction l as [|x l IH]=> f; csimpl=> //. by rewrite IH. Qed. `````` Robbert Krebbers committed May 01, 2019 154 `````` Lemma big_opL_op f g l : `````` Robbert Krebbers committed Mar 24, 2017 155 156 157 158 159 160 161 162 `````` ([^o list] k↦x ∈ l, f k x `o` g k x) ≡ ([^o list] k↦x ∈ l, f k x) `o` ([^o list] k↦x ∈ l, g k x). Proof. revert f g; induction l as [|x l IH]=> f g /=; first by rewrite left_id. by rewrite IH -!assoc (assoc _ (g _ _)) [(g _ _ `o` _)]comm -!assoc. Qed. End list. `````` Robbert Krebbers committed May 02, 2019 163 164 165 166 167 168 ``````Lemma big_opL_bind {A B} (h : A → list B) (f : B → M) l : ([^o list] y ∈ l ≫= h, f y) ≡ ([^o list] x ∈ l, [^o list] y ∈ h x, f y). Proof. revert f. induction l as [|x l IH]=> f; csimpl=> //. by rewrite big_opL_app IH. Qed. `````` Robbert Krebbers committed Mar 24, 2017 169 170 171 172 173 174 175 176 177 178 179 ``````(** ** Big ops over finite maps *) Section gmap. Context `{Countable K} {A : Type}. Implicit Types m : gmap K A. Implicit Types f g : K → A → M. Lemma big_opM_forall R f g m : Reflexive R → Proper (R ==> R ==> R) o → (∀ k x, m !! k = Some x → R (f k x) (g k x)) → R ([^o map] k ↦ x ∈ m, f k x) ([^o map] k ↦ x ∈ m, g k x). Proof. `````` Michael Sammler committed Jan 16, 2020 180 `````` intros ?? Hf. rewrite big_opM_eq. apply (big_opL_forall R); auto. `````` Robbert Krebbers committed Mar 24, 2017 181 182 183 184 185 186 187 188 189 190 191 192 193 194 `````` intros k [i x] ?%elem_of_list_lookup_2. by apply Hf, elem_of_map_to_list. Qed. Lemma big_opM_ext f g m : (∀ k x, m !! k = Some x → f k x = g k x) → ([^o map] k ↦ x ∈ m, f k x) = ([^o map] k ↦ x ∈ m, g k x). Proof. apply big_opM_forall; apply _. Qed. Lemma big_opM_proper f g m : (∀ k x, m !! k = Some x → f k x ≡ g k x) → ([^o map] k ↦ x ∈ m, f k x) ≡ ([^o map] k ↦ x ∈ m, g k x). Proof. apply big_opM_forall; apply _. Qed. Global Instance big_opM_ne n : Proper (pointwise_relation _ (pointwise_relation _ (dist n)) ==> eq ==> dist n) `````` Robbert Krebbers committed Sep 21, 2017 195 `````` (big_opM o (K:=K) (A:=A)). `````` Robbert Krebbers committed Mar 24, 2017 196 197 198 `````` Proof. intros f g Hf m ? <-. apply big_opM_forall; apply _ || intros; apply Hf. Qed. Global Instance big_opM_proper' : Proper (pointwise_relation _ (pointwise_relation _ (≡)) ==> eq ==> (≡)) `````` Robbert Krebbers committed Sep 21, 2017 199 `````` (big_opM o (K:=K) (A:=A)). `````` Robbert Krebbers committed Mar 24, 2017 200 201 202 `````` Proof. intros f g Hf m ? <-. apply big_opM_forall; apply _ || intros; apply Hf. Qed. Lemma big_opM_empty f : ([^o map] k↦x ∈ ∅, f k x) = monoid_unit. `````` Michael Sammler committed Jan 16, 2020 203 `````` Proof. by rewrite big_opM_eq /big_opM_def map_to_list_empty. Qed. `````` Robbert Krebbers committed Mar 24, 2017 204 205 206 207 `````` Lemma big_opM_insert f m i x : m !! i = None → ([^o map] k↦y ∈ <[i:=x]> m, f k y) ≡ f i x `o` [^o map] k↦y ∈ m, f k y. `````` Michael Sammler committed Jan 16, 2020 208 `````` Proof. intros ?. by rewrite big_opM_eq /big_opM_def map_to_list_insert. Qed. `````` Robbert Krebbers committed Mar 24, 2017 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 `````` Lemma big_opM_delete f m i x : m !! i = Some x → ([^o map] k↦y ∈ m, f k y) ≡ f i x `o` [^o map] k↦y ∈ delete i m, f k y. Proof. intros. rewrite -big_opM_insert ?lookup_delete //. by rewrite insert_delete insert_id. Qed. Lemma big_opM_singleton f i x : ([^o map] k↦y ∈ {[i:=x]}, f k y) ≡ f i x. Proof. rewrite -insert_empty big_opM_insert/=; last auto using lookup_empty. by rewrite big_opM_empty right_id. Qed. `````` Robbert Krebbers committed Jun 12, 2017 224 `````` Lemma big_opM_unit m : ([^o map] k↦y ∈ m, monoid_unit) ≡ (monoid_unit : M). `````` Michael Sammler committed Jan 16, 2020 225 `````` Proof. by induction m using map_ind; rewrite /= ?big_opM_insert ?left_id // big_opM_eq. Qed. `````` Robbert Krebbers committed Jun 12, 2017 226 `````` `````` Robbert Krebbers committed Mar 24, 2017 227 228 229 `````` Lemma big_opM_fmap {B} (h : A → B) (f : K → B → M) m : ([^o map] k↦y ∈ h <\$> m, f k y) ≡ ([^o map] k↦y ∈ m, f k (h y)). Proof. `````` Michael Sammler committed Jan 16, 2020 230 `````` rewrite big_opM_eq /big_opM_def map_to_list_fmap big_opL_fmap. `````` Robbert Krebbers committed Mar 24, 2017 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 `````` by apply big_opL_proper=> ? [??]. Qed. Lemma big_opM_insert_override (f : K → A → M) m i x x' : m !! i = Some x → f i x ≡ f i x' → ([^o map] k↦y ∈ <[i:=x']> m, f k y) ≡ ([^o map] k↦y ∈ m, f k y). Proof. intros ? Hx. rewrite -insert_delete big_opM_insert ?lookup_delete //. by rewrite -Hx -big_opM_delete. Qed. Lemma big_opM_fn_insert {B} (g : K → A → B → M) (f : K → B) m i (x : A) b : m !! i = None → ([^o map] k↦y ∈ <[i:=x]> m, g k y (<[i:=b]> f k)) ≡ g i x b `o` [^o map] k↦y ∈ m, g k y (f k). Proof. intros. rewrite big_opM_insert // fn_lookup_insert. f_equiv; apply big_opM_proper; auto=> k y ?. by rewrite fn_lookup_insert_ne; last set_solver. Qed. Lemma big_opM_fn_insert' (f : K → M) m i x P : m !! i = None → ([^o map] k↦y ∈ <[i:=x]> m, <[i:=P]> f k) ≡ (P `o` [^o map] k↦y ∈ m, f k). Proof. apply (big_opM_fn_insert (λ _ _, id)). Qed. `````` Dan Frumin committed Nov 01, 2018 256 257 258 259 260 261 262 263 264 265 266 267 `````` Lemma big_opM_union f m1 m2 : m1 ##ₘ m2 → ([^o map] k↦y ∈ m1 ∪ m2, f k y) ≡ ([^o map] k↦y ∈ m1, f k y) `o` ([^o map] k↦y ∈ m2, f k y). Proof. intros. induction m1 as [|i x m ? IH] using map_ind. { by rewrite big_opM_empty !left_id. } decompose_map_disjoint. rewrite -insert_union_l !big_opM_insert //; last by apply lookup_union_None. rewrite -assoc IH //. Qed. `````` Robbert Krebbers committed May 01, 2019 268 `````` Lemma big_opM_op f g m : `````` Robbert Krebbers committed Mar 24, 2017 269 270 `````` ([^o map] k↦x ∈ m, f k x `o` g k x) ≡ ([^o map] k↦x ∈ m, f k x) `o` ([^o map] k↦x ∈ m, g k x). `````` Michael Sammler committed Jan 16, 2020 271 `````` Proof. rewrite big_opM_eq /big_opM_def -big_opL_op. by apply big_opL_proper=> ? [??]. Qed. `````` Robbert Krebbers committed Mar 24, 2017 272 273 274 275 276 277 278 279 280 281 282 283 284 285 ``````End gmap. (** ** Big ops over finite sets *) Section gset. Context `{Countable A}. Implicit Types X : gset A. Implicit Types f : A → M. Lemma big_opS_forall R f g X : Reflexive R → Proper (R ==> R ==> R) o → (∀ x, x ∈ X → R (f x) (g x)) → R ([^o set] x ∈ X, f x) ([^o set] x ∈ X, g x). Proof. `````` Michael Sammler committed Jan 16, 2020 286 `````` rewrite big_opS_eq. intros ?? Hf. apply (big_opL_forall R); auto. `````` Robbert Krebbers committed Mar 24, 2017 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 `````` intros k x ?%elem_of_list_lookup_2. by apply Hf, elem_of_elements. Qed. Lemma big_opS_ext f g X : (∀ x, x ∈ X → f x = g x) → ([^o set] x ∈ X, f x) = ([^o set] x ∈ X, g x). Proof. apply big_opS_forall; apply _. Qed. Lemma big_opS_proper f g X : (∀ x, x ∈ X → f x ≡ g x) → ([^o set] x ∈ X, f x) ≡ ([^o set] x ∈ X, g x). Proof. apply big_opS_forall; apply _. Qed. Global Instance big_opS_ne n : Proper (pointwise_relation _ (dist n) ==> eq ==> dist n) (big_opS o (A:=A)). Proof. intros f g Hf m ? <-. apply big_opS_forall; apply _ || intros; apply Hf. Qed. Global Instance big_opS_proper' : Proper (pointwise_relation _ (≡) ==> eq ==> (≡)) (big_opS o (A:=A)). Proof. intros f g Hf m ? <-. apply big_opS_forall; apply _ || intros; apply Hf. Qed. Lemma big_opS_empty f : ([^o set] x ∈ ∅, f x) = monoid_unit. `````` Michael Sammler committed Jan 16, 2020 307 `````` Proof. by rewrite big_opS_eq /big_opS_def elements_empty. Qed. `````` Robbert Krebbers committed Mar 24, 2017 308 309 310 `````` Lemma big_opS_insert f X x : x ∉ X → ([^o set] y ∈ {[ x ]} ∪ X, f y) ≡ (f x `o` [^o set] y ∈ X, f y). `````` Michael Sammler committed Jan 16, 2020 311 `````` Proof. intros. by rewrite big_opS_eq /big_opS_def elements_union_singleton. Qed. `````` Robbert Krebbers committed Mar 24, 2017 312 313 314 315 316 317 318 319 320 321 322 323 324 325 `````` Lemma big_opS_fn_insert {B} (f : A → B → M) h X x b : x ∉ X → ([^o set] y ∈ {[ x ]} ∪ X, f y (<[x:=b]> h y)) ≡ f x b `o` [^o set] y ∈ X, f y (h y). Proof. intros. rewrite big_opS_insert // fn_lookup_insert. f_equiv; apply big_opS_proper; auto=> y ?. by rewrite fn_lookup_insert_ne; last set_solver. Qed. Lemma big_opS_fn_insert' f X x P : x ∉ X → ([^o set] y ∈ {[ x ]} ∪ X, <[x:=P]> f y) ≡ (P `o` [^o set] y ∈ X, f y). Proof. apply (big_opS_fn_insert (λ y, id)). Qed. Lemma big_opS_union f X Y : `````` 326 `````` X ## Y → `````` Robbert Krebbers committed Mar 24, 2017 327 328 `````` ([^o set] y ∈ X ∪ Y, f y) ≡ ([^o set] y ∈ X, f y) `o` ([^o set] y ∈ Y, f y). Proof. `````` Robbert Krebbers committed Feb 20, 2019 329 `````` intros. induction X as [|x X ? IH] using set_ind_L. `````` Robbert Krebbers committed Mar 24, 2017 330 331 332 333 334 335 336 337 338 339 340 341 342 `````` { by rewrite left_id_L big_opS_empty left_id. } rewrite -assoc_L !big_opS_insert; [|set_solver..]. by rewrite -assoc IH; last set_solver. Qed. Lemma big_opS_delete f X x : x ∈ X → ([^o set] y ∈ X, f y) ≡ f x `o` [^o set] y ∈ X ∖ {[ x ]}, f y. Proof. intros. rewrite -big_opS_insert; last set_solver. by rewrite -union_difference_L; last set_solver. Qed. Lemma big_opS_singleton f x : ([^o set] y ∈ {[ x ]}, f y) ≡ f x. `````` Michael Sammler committed Jan 16, 2020 343 `````` Proof. intros. by rewrite big_opS_eq /big_opS_def elements_singleton /= right_id. Qed. `````` Robbert Krebbers committed Mar 24, 2017 344 `````` `````` Robbert Krebbers committed Jun 12, 2017 345 346 `````` Lemma big_opS_unit X : ([^o set] y ∈ X, monoid_unit) ≡ (monoid_unit : M). Proof. `````` Michael Sammler committed Jan 16, 2020 347 `````` by induction X using set_ind_L; rewrite /= ?big_opS_insert ?left_id // big_opS_eq. `````` Robbert Krebbers committed Jun 12, 2017 348 349 `````` Qed. `````` Robbert Krebbers committed May 01, 2019 350 `````` Lemma big_opS_op f g X : `````` Robbert Krebbers committed Mar 24, 2017 351 `````` ([^o set] y ∈ X, f y `o` g y) ≡ ([^o set] y ∈ X, f y) `o` ([^o set] y ∈ X, g y). `````` Michael Sammler committed Jan 16, 2020 352 `````` Proof. by rewrite big_opS_eq /big_opS_def -big_opL_op. Qed. `````` Robbert Krebbers committed Mar 24, 2017 353 354 355 356 357 ``````End gset. Lemma big_opM_dom `{Countable K} {A} (f : K → M) (m : gmap K A) : ([^o map] k↦_ ∈ m, f k) ≡ ([^o set] k ∈ dom _ m, f k). Proof. `````` Michael Sammler committed Jan 16, 2020 358 `````` induction m as [|i x ?? IH] using map_ind; [by rewrite big_opM_eq big_opS_eq dom_empty_L|]. `````` Robbert Krebbers committed Mar 24, 2017 359 360 361 362 363 364 365 366 367 368 369 370 371 372 `````` by rewrite dom_insert_L big_opM_insert // IH big_opS_insert ?not_elem_of_dom. Qed. (** ** Big ops over finite msets *) Section gmultiset. Context `{Countable A}. Implicit Types X : gmultiset A. Implicit Types f : A → M. Lemma big_opMS_forall R f g X : Reflexive R → Proper (R ==> R ==> R) o → (∀ x, x ∈ X → R (f x) (g x)) → R ([^o mset] x ∈ X, f x) ([^o mset] x ∈ X, g x). Proof. `````` Michael Sammler committed Jan 16, 2020 373 `````` rewrite big_opMS_eq. intros ?? Hf. apply (big_opL_forall R); auto. `````` Robbert Krebbers committed Mar 24, 2017 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 `````` intros k x ?%elem_of_list_lookup_2. by apply Hf, gmultiset_elem_of_elements. Qed. Lemma big_opMS_ext f g X : (∀ x, x ∈ X → f x = g x) → ([^o mset] x ∈ X, f x) = ([^o mset] x ∈ X, g x). Proof. apply big_opMS_forall; apply _. Qed. Lemma big_opMS_proper f g X : (∀ x, x ∈ X → f x ≡ g x) → ([^o mset] x ∈ X, f x) ≡ ([^o mset] x ∈ X, g x). Proof. apply big_opMS_forall; apply _. Qed. Global Instance big_opMS_ne n : Proper (pointwise_relation _ (dist n) ==> eq ==> dist n) (big_opMS o (A:=A)). Proof. intros f g Hf m ? <-. apply big_opMS_forall; apply _ || intros; apply Hf. Qed. Global Instance big_opMS_proper' : Proper (pointwise_relation _ (≡) ==> eq ==> (≡)) (big_opMS o (A:=A)). Proof. intros f g Hf m ? <-. apply big_opMS_forall; apply _ || intros; apply Hf. Qed. Lemma big_opMS_empty f : ([^o mset] x ∈ ∅, f x) = monoid_unit. `````` Michael Sammler committed Jan 16, 2020 394 `````` Proof. by rewrite big_opMS_eq /big_opMS_def gmultiset_elements_empty. Qed. `````` Robbert Krebbers committed Mar 24, 2017 395 `````` `````` Robbert Krebbers committed Feb 21, 2019 396 397 `````` Lemma big_opMS_disj_union f X Y : ([^o mset] y ∈ X ⊎ Y, f y) ≡ ([^o mset] y ∈ X, f y) `o` [^o mset] y ∈ Y, f y. `````` Michael Sammler committed Jan 16, 2020 398 `````` Proof. by rewrite big_opMS_eq /big_opMS_def gmultiset_elements_disj_union big_opL_app. Qed. `````` Robbert Krebbers committed Mar 24, 2017 399 400 401 `````` Lemma big_opMS_singleton f x : ([^o mset] y ∈ {[ x ]}, f y) ≡ f x. Proof. `````` Michael Sammler committed Jan 16, 2020 402 `````` intros. by rewrite big_opMS_eq /big_opMS_def gmultiset_elements_singleton /= right_id. `````` Robbert Krebbers committed Mar 24, 2017 403 404 405 406 407 `````` Qed. Lemma big_opMS_delete f X x : x ∈ X → ([^o mset] y ∈ X, f y) ≡ f x `o` [^o mset] y ∈ X ∖ {[ x ]}, f y. Proof. `````` Robbert Krebbers committed Feb 21, 2019 408 409 `````` intros. rewrite -big_opMS_singleton -big_opMS_disj_union. by rewrite -gmultiset_disj_union_difference'. `````` Robbert Krebbers committed Mar 24, 2017 410 411 `````` Qed. `````` Robbert Krebbers committed Jun 12, 2017 412 413 `````` Lemma big_opMS_unit X : ([^o mset] y ∈ X, monoid_unit) ≡ (monoid_unit : M). Proof. `````` Michael Sammler committed Jan 16, 2020 414 415 `````` by induction X using gmultiset_ind; rewrite /= ?big_opMS_disj_union ?big_opMS_singleton ?left_id // big_opMS_eq. `````` Robbert Krebbers committed Jun 12, 2017 416 417 `````` Qed. `````` Robbert Krebbers committed May 01, 2019 418 `````` Lemma big_opMS_op f g X : `````` Robbert Krebbers committed Mar 24, 2017 419 `````` ([^o mset] y ∈ X, f y `o` g y) ≡ ([^o mset] y ∈ X, f y) `o` ([^o mset] y ∈ X, g y). `````` Michael Sammler committed Jan 16, 2020 420 `````` Proof. by rewrite big_opMS_eq /big_opMS_def -big_opL_op. Qed. `````` Robbert Krebbers committed Mar 24, 2017 421 422 423 424 425 426 427 ``````End gmultiset. End big_op. Section homomorphisms. Context `{Monoid M1 o1, Monoid M2 o2}. Infix "`o1`" := o1 (at level 50, left associativity). Infix "`o2`" := o2 (at level 50, left associativity). `````` 428 429 430 431 `````` (** The ssreflect rewrite tactic only works for relations that have a [RewriteRelation] instance. For the purpose of this section, we want to rewrite with arbitrary relations, so we declare any relation to be a [RewriteRelation]. *) `````` Maxime Dénès committed Jan 24, 2019 432 `````` Local Instance: ∀ {A} (R : relation A), RewriteRelation R := {}. `````` Robbert Krebbers committed Mar 24, 2017 433 `````` `````` Robbert Krebbers committed Aug 17, 2017 434 `````` Lemma big_opL_commute {A} (h : M1 → M2) `{!MonoidHomomorphism o1 o2 R h} `````` Robbert Krebbers committed Mar 24, 2017 435 `````` (f : nat → A → M1) l : `````` Robbert Krebbers committed Aug 17, 2017 436 `````` R (h ([^o1 list] k↦x ∈ l, f k x)) ([^o2 list] k↦x ∈ l, h (f k x)). `````` Robbert Krebbers committed Mar 24, 2017 437 438 `````` Proof. revert f. induction l as [|x l IH]=> f /=. `````` Robbert Krebbers committed Aug 17, 2017 439 440 `````` - apply monoid_homomorphism_unit. - by rewrite monoid_homomorphism IH. `````` Robbert Krebbers committed Mar 24, 2017 441 `````` Qed. `````` Robbert Krebbers committed Aug 17, 2017 442 `````` Lemma big_opL_commute1 {A} (h : M1 → M2) `{!WeakMonoidHomomorphism o1 o2 R h} `````` Robbert Krebbers committed Mar 24, 2017 443 `````` (f : nat → A → M1) l : `````` Robbert Krebbers committed Aug 17, 2017 444 `````` l ≠ [] → R (h ([^o1 list] k↦x ∈ l, f k x)) ([^o2 list] k↦x ∈ l, h (f k x)). `````` Robbert Krebbers committed Mar 24, 2017 445 446 447 `````` Proof. intros ?. revert f. induction l as [|x [|x' l'] IH]=> f //. - by rewrite !big_opL_singleton. `````` Robbert Krebbers committed Aug 17, 2017 448 `````` - by rewrite !(big_opL_cons _ x) monoid_homomorphism IH. `````` Robbert Krebbers committed Mar 24, 2017 449 450 451 `````` Qed. Lemma big_opM_commute `{Countable K} {A} (h : M1 → M2) `````` Robbert Krebbers committed Aug 17, 2017 452 453 `````` `{!MonoidHomomorphism o1 o2 R h} (f : K → A → M1) m : R (h ([^o1 map] k↦x ∈ m, f k x)) ([^o2 map] k↦x ∈ m, h (f k x)). `````` Robbert Krebbers committed Mar 24, 2017 454 455 456 457 458 459 `````` Proof. intros. induction m as [|i x m ? IH] using map_ind. - by rewrite !big_opM_empty monoid_homomorphism_unit. - by rewrite !big_opM_insert // monoid_homomorphism -IH. Qed. Lemma big_opM_commute1 `{Countable K} {A} (h : M1 → M2) `````` Robbert Krebbers committed Aug 17, 2017 460 461 `````` `{!WeakMonoidHomomorphism o1 o2 R h} (f : K → A → M1) m : m ≠ ∅ → R (h ([^o1 map] k↦x ∈ m, f k x)) ([^o2 map] k↦x ∈ m, h (f k x)). `````` Robbert Krebbers committed Mar 24, 2017 462 463 464 465 466 467 468 469 `````` Proof. intros. induction m as [|i x m ? IH] using map_ind; [done|]. destruct (decide (m = ∅)) as [->|]. - by rewrite !big_opM_insert // !big_opM_empty !right_id. - by rewrite !big_opM_insert // monoid_homomorphism -IH //. Qed. Lemma big_opS_commute `{Countable A} (h : M1 → M2) `````` Robbert Krebbers committed Aug 17, 2017 470 471 `````` `{!MonoidHomomorphism o1 o2 R h} (f : A → M1) X : R (h ([^o1 set] x ∈ X, f x)) ([^o2 set] x ∈ X, h (f x)). `````` Robbert Krebbers committed Mar 24, 2017 472 `````` Proof. `````` Robbert Krebbers committed Feb 20, 2019 473 `````` intros. induction X as [|x X ? IH] using set_ind_L. `````` Robbert Krebbers committed Mar 24, 2017 474 475 476 477 `````` - by rewrite !big_opS_empty monoid_homomorphism_unit. - by rewrite !big_opS_insert // monoid_homomorphism -IH. Qed. Lemma big_opS_commute1 `{Countable A} (h : M1 → M2) `````` Robbert Krebbers committed Aug 17, 2017 478 479 `````` `{!WeakMonoidHomomorphism o1 o2 R h} (f : A → M1) X : X ≠ ∅ → R (h ([^o1 set] x ∈ X, f x)) ([^o2 set] x ∈ X, h (f x)). `````` Robbert Krebbers committed Mar 24, 2017 480 `````` Proof. `````` Robbert Krebbers committed Feb 20, 2019 481 `````` intros. induction X as [|x X ? IH] using set_ind_L; [done|]. `````` Robbert Krebbers committed Mar 24, 2017 482 483 484 485 486 487 `````` destruct (decide (X = ∅)) as [->|]. - by rewrite !big_opS_insert // !big_opS_empty !right_id. - by rewrite !big_opS_insert // monoid_homomorphism -IH //. Qed. Lemma big_opMS_commute `{Countable A} (h : M1 → M2) `````` Robbert Krebbers committed Aug 17, 2017 488 489 `````` `{!MonoidHomomorphism o1 o2 R h} (f : A → M1) X : R (h ([^o1 mset] x ∈ X, f x)) ([^o2 mset] x ∈ X, h (f x)). `````` Robbert Krebbers committed Mar 24, 2017 490 491 492 `````` Proof. intros. induction X as [|x X IH] using gmultiset_ind. - by rewrite !big_opMS_empty monoid_homomorphism_unit. `````` Robbert Krebbers committed Feb 21, 2019 493 `````` - by rewrite !big_opMS_disj_union !big_opMS_singleton monoid_homomorphism -IH. `````` Robbert Krebbers committed Mar 24, 2017 494 495 `````` Qed. Lemma big_opMS_commute1 `{Countable A} (h : M1 → M2) `````` Robbert Krebbers committed Aug 17, 2017 496 497 `````` `{!WeakMonoidHomomorphism o1 o2 R h} (f : A → M1) X : X ≠ ∅ → R (h ([^o1 mset] x ∈ X, f x)) ([^o2 mset] x ∈ X, h (f x)). `````` Robbert Krebbers committed Mar 24, 2017 498 499 500 `````` Proof. intros. induction X as [|x X IH] using gmultiset_ind; [done|]. destruct (decide (X = ∅)) as [->|]. `````` Robbert Krebbers committed Feb 21, 2019 501 502 `````` - by rewrite !big_opMS_disj_union !big_opMS_singleton !big_opMS_empty !right_id. - by rewrite !big_opMS_disj_union !big_opMS_singleton monoid_homomorphism -IH //. `````` Robbert Krebbers committed Mar 24, 2017 503 504 505 506 507 `````` Qed. Context `{!LeibnizEquiv M2}. Lemma big_opL_commute_L {A} (h : M1 → M2) `````` Robbert Krebbers committed Aug 17, 2017 508 `````` `{!MonoidHomomorphism o1 o2 (≡) h} (f : nat → A → M1) l : `````` Robbert Krebbers committed Mar 24, 2017 509 510 511 `````` h ([^o1 list] k↦x ∈ l, f k x) = ([^o2 list] k↦x ∈ l, h (f k x)). Proof. unfold_leibniz. by apply big_opL_commute. Qed. Lemma big_opL_commute1_L {A} (h : M1 → M2) `````` Robbert Krebbers committed Aug 17, 2017 512 `````` `{!WeakMonoidHomomorphism o1 o2 (≡) h} (f : nat → A → M1) l : `````` Robbert Krebbers committed Mar 24, 2017 513 514 515 516 `````` l ≠ [] → h ([^o1 list] k↦x ∈ l, f k x) = ([^o2 list] k↦x ∈ l, h (f k x)). Proof. unfold_leibniz. by apply big_opL_commute1. Qed. Lemma big_opM_commute_L `{Countable K} {A} (h : M1 → M2) `````` Robbert Krebbers committed Aug 17, 2017 517 `````` `{!MonoidHomomorphism o1 o2 (≡) h} (f : K → A → M1) m : `````` Robbert Krebbers committed Mar 24, 2017 518 519 520 `````` h ([^o1 map] k↦x ∈ m, f k x) = ([^o2 map] k↦x ∈ m, h (f k x)). Proof. unfold_leibniz. by apply big_opM_commute. Qed. Lemma big_opM_commute1_L `{Countable K} {A} (h : M1 → M2) `````` Robbert Krebbers committed Aug 17, 2017 521 `````` `{!WeakMonoidHomomorphism o1 o2 (≡) h} (f : K → A → M1) m : `````` Robbert Krebbers committed Mar 24, 2017 522 523 524 525 `````` m ≠ ∅ → h ([^o1 map] k↦x ∈ m, f k x) = ([^o2 map] k↦x ∈ m, h (f k x)). Proof. unfold_leibniz. by apply big_opM_commute1. Qed. Lemma big_opS_commute_L `{Countable A} (h : M1 → M2) `````` Robbert Krebbers committed Aug 17, 2017 526 `````` `{!MonoidHomomorphism o1 o2 (≡) h} (f : A → M1) X : `````` Robbert Krebbers committed Mar 24, 2017 527 528 529 `````` h ([^o1 set] x ∈ X, f x) = ([^o2 set] x ∈ X, h (f x)). Proof. unfold_leibniz. by apply big_opS_commute. Qed. Lemma big_opS_commute1_L `{ Countable A} (h : M1 → M2) `````` Robbert Krebbers committed Aug 17, 2017 530 `````` `{!WeakMonoidHomomorphism o1 o2 (≡) h} (f : A → M1) X : `````` Robbert Krebbers committed Mar 24, 2017 531 532 533 534 `````` X ≠ ∅ → h ([^o1 set] x ∈ X, f x) = ([^o2 set] x ∈ X, h (f x)). Proof. intros. rewrite <-leibniz_equiv_iff. by apply big_opS_commute1. Qed. Lemma big_opMS_commute_L `{Countable A} (h : M1 → M2) `````` Robbert Krebbers committed Aug 17, 2017 535 `````` `{!MonoidHomomorphism o1 o2 (≡) h} (f : A → M1) X : `````` Robbert Krebbers committed Mar 24, 2017 536 537 538 `````` h ([^o1 mset] x ∈ X, f x) = ([^o2 mset] x ∈ X, h (f x)). Proof. unfold_leibniz. by apply big_opMS_commute. Qed. Lemma big_opMS_commute1_L `{Countable A} (h : M1 → M2) `````` Robbert Krebbers committed Aug 17, 2017 539 `````` `{!WeakMonoidHomomorphism o1 o2 (≡) h} (f : A → M1) X : `````` Robbert Krebbers committed Mar 24, 2017 540 541 542 `````` X ≠ ∅ → h ([^o1 mset] x ∈ X, f x) = ([^o2 mset] x ∈ X, h (f x)). Proof. intros. rewrite <-leibniz_equiv_iff. by apply big_opMS_commute1. Qed. End homomorphisms.``````