big_op.v 73 KB
 Robbert Krebbers committed Oct 30, 2017 1 ``````From iris.algebra Require Export big_op. `````` Ralf Jung committed Mar 21, 2018 2 ``````From iris.bi Require Import derived_laws_sbi plainly. `````` Robbert Krebbers committed Feb 20, 2019 3 ``````From stdpp Require Import countable fin_sets functions. `````` Ralf Jung committed Jan 05, 2017 4 ``````Set Default Proof Using "Type". `````` Robbert Krebbers committed Jun 15, 2018 5 ``````Import interface.bi derived_laws_bi.bi derived_laws_sbi.bi. `````` Robbert Krebbers committed Feb 14, 2016 6 `````` `````` Dan Frumin committed Apr 07, 2019 7 ``````(** Notations for unary variants *) `````` Ralf Jung committed Jun 05, 2018 8 9 10 11 12 13 14 15 16 17 18 19 ``````Notation "'[∗' 'list]' k ↦ x ∈ l , P" := (big_opL bi_sep (λ k x, P) l) : bi_scope. Notation "'[∗' 'list]' x ∈ l , P" := (big_opL bi_sep (λ _ x, P) l) : bi_scope. Notation "'[∗]' Ps" := (big_opL bi_sep (λ _ x, x) Ps) : bi_scope. Notation "'[∧' 'list]' k ↦ x ∈ l , P" := (big_opL bi_and (λ k x, P) l) : bi_scope. Notation "'[∧' 'list]' x ∈ l , P" := (big_opL bi_and (λ _ x, P) l) : bi_scope. Notation "'[∧]' Ps" := (big_opL bi_and (λ _ x, x) Ps) : bi_scope. `````` Robbert Krebbers committed May 01, 2019 20 21 22 23 24 25 ``````Notation "'[∨' 'list]' k ↦ x ∈ l , P" := (big_opL bi_or (λ k x, P) l) : bi_scope. Notation "'[∨' 'list]' x ∈ l , P" := (big_opL bi_or (λ _ x, P) l) : bi_scope. Notation "'[∨]' Ps" := (big_opL bi_or (λ _ x, x) Ps) : bi_scope. `````` Ralf Jung committed Jun 05, 2018 26 27 28 29 30 31 ``````Notation "'[∗' 'map]' k ↦ x ∈ m , P" := (big_opM bi_sep (λ k x, P) m) : bi_scope. Notation "'[∗' 'map]' x ∈ m , P" := (big_opM bi_sep (λ _ x, P) m) : bi_scope. Notation "'[∗' 'set]' x ∈ X , P" := (big_opS bi_sep (λ x, P) X) : bi_scope. Notation "'[∗' 'mset]' x ∈ X , P" := (big_opMS bi_sep (λ x, P) X) : bi_scope. `````` Robbert Krebbers committed Aug 24, 2016 32 `````` `````` Dan Frumin committed Apr 07, 2019 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 ``````(** Definitions and notations for binary variants *) (** A version of the separating big operator that ranges over two lists. This version also ensures that both lists have the same length. Although this version can be defined in terms of the unary using a [zip] (see [big_sepL2_alt]), we do not define it that way to get better computational behavior (for [simpl]). *) Fixpoint big_sepL2 {PROP : bi} {A B} (Φ : nat → A → B → PROP) (l1 : list A) (l2 : list B) : PROP := match l1, l2 with | [], [] => emp | x1 :: l1, x2 :: l2 => Φ 0 x1 x2 ∗ big_sepL2 (λ n, Φ (S n)) l1 l2 | _, _ => False end%I. Instance: Params (@big_sepL2) 3 := {}. Arguments big_sepL2 {PROP A B} _ !_ !_ /. Typeclasses Opaque big_sepL2. Notation "'[∗' 'list]' k ↦ x1 ; x2 ∈ l1 ; l2 , P" := (big_sepL2 (λ k x1 x2, P) l1 l2) : bi_scope. Notation "'[∗' 'list]' x1 ; x2 ∈ l1 ; l2 , P" := (big_sepL2 (λ _ x1 x2, P) l1 l2) : bi_scope. Definition big_sepM2 {PROP : bi} `{Countable K} {A B} (Φ : K → A → B → PROP) (m1 : gmap K A) (m2 : gmap K B) : PROP := (⌜ ∀ k, is_Some (m1 !! k) ↔ is_Some (m2 !! k) ⌝ ∧ [∗ map] k ↦ xy ∈ map_zip m1 m2, Φ k xy.1 xy.2)%I. Instance: Params (@big_sepM2) 6 := {}. Typeclasses Opaque big_sepM2. Notation "'[∗' 'map]' k ↦ x1 ; x2 ∈ m1 ; m2 , P" := (big_sepM2 (λ k x1 x2, P) m1 m2) : bi_scope. Notation "'[∗' 'map]' x1 ; x2 ∈ m1 ; m2 , P" := (big_sepM2 (λ _ x1 x2, P) m1 m2) : bi_scope. `````` Robbert Krebbers committed Apr 08, 2016 64 ``````(** * Properties *) `````` Robbert Krebbers committed Oct 30, 2017 65 66 ``````Section bi_big_op. Context {PROP : bi}. `````` Robbert Krebbers committed Oct 31, 2018 67 ``````Implicit Types P Q : PROP. `````` Robbert Krebbers committed Oct 30, 2017 68 ``````Implicit Types Ps Qs : list PROP. `````` Robbert Krebbers committed Feb 14, 2016 69 70 ``````Implicit Types A : Type. `````` Robbert Krebbers committed Aug 24, 2016 71 ``````(** ** Big ops over lists *) `````` Robbert Krebbers committed Oct 30, 2017 72 ``````Section sep_list. `````` Robbert Krebbers committed Aug 24, 2016 73 74 `````` Context {A : Type}. Implicit Types l : list A. `````` Robbert Krebbers committed Oct 30, 2017 75 `````` Implicit Types Φ Ψ : nat → A → PROP. `````` Robbert Krebbers committed Aug 24, 2016 76 `````` `````` Robbert Krebbers committed Oct 30, 2017 77 `````` Lemma big_sepL_nil Φ : ([∗ list] k↦y ∈ nil, Φ k y) ⊣⊢ emp. `````` Robbert Krebbers committed Sep 28, 2016 78 `````` Proof. done. Qed. `````` Jacques-Henri Jourdan committed Dec 04, 2017 79 `````` Lemma big_sepL_nil' `{BiAffine PROP} P Φ : P ⊢ [∗ list] k↦y ∈ nil, Φ k y. `````` Robbert Krebbers committed Oct 30, 2017 80 `````` Proof. apply (affine _). Qed. `````` Robbert Krebbers committed Sep 28, 2016 81 `````` Lemma big_sepL_cons Φ x l : `````` Robbert Krebbers committed Nov 03, 2016 82 `````` ([∗ list] k↦y ∈ x :: l, Φ k y) ⊣⊢ Φ 0 x ∗ [∗ list] k↦y ∈ l, Φ (S k) y. `````` Robbert Krebbers committed Sep 28, 2016 83 `````` Proof. by rewrite big_opL_cons. Qed. `````` Robbert Krebbers committed Nov 03, 2016 84 `````` Lemma big_sepL_singleton Φ x : ([∗ list] k↦y ∈ [x], Φ k y) ⊣⊢ Φ 0 x. `````` Robbert Krebbers committed Sep 28, 2016 85 86 `````` Proof. by rewrite big_opL_singleton. Qed. Lemma big_sepL_app Φ l1 l2 : `````` Robbert Krebbers committed Nov 03, 2016 87 88 `````` ([∗ list] k↦y ∈ l1 ++ l2, Φ k y) ⊣⊢ ([∗ list] k↦y ∈ l1, Φ k y) ∗ ([∗ list] k↦y ∈ l2, Φ (length l1 + k) y). `````` Robbert Krebbers committed Sep 28, 2016 89 90 `````` Proof. by rewrite big_opL_app. Qed. `````` Robbert Krebbers committed Aug 24, 2016 91 92 `````` Lemma big_sepL_mono Φ Ψ l : (∀ k y, l !! k = Some y → Φ k y ⊢ Ψ k y) → `````` Robbert Krebbers committed Nov 03, 2016 93 `````` ([∗ list] k ↦ y ∈ l, Φ k y) ⊢ [∗ list] k ↦ y ∈ l, Ψ k y. `````` Robbert Krebbers committed Sep 28, 2016 94 `````` Proof. apply big_opL_forall; apply _. Qed. `````` Robbert Krebbers committed Aug 24, 2016 95 96 `````` Lemma big_sepL_proper Φ Ψ l : (∀ k y, l !! k = Some y → Φ k y ⊣⊢ Ψ k y) → `````` Robbert Krebbers committed Nov 03, 2016 97 `````` ([∗ list] k ↦ y ∈ l, Φ k y) ⊣⊢ ([∗ list] k ↦ y ∈ l, Ψ k y). `````` Robbert Krebbers committed Sep 28, 2016 98 `````` Proof. apply big_opL_proper. Qed. `````` Jacques-Henri Jourdan committed Dec 04, 2017 99 `````` Lemma big_sepL_submseteq `{BiAffine PROP} (Φ : A → PROP) l1 l2 : `````` Robbert Krebbers committed Jan 06, 2017 100 `````` l1 ⊆+ l2 → ([∗ list] y ∈ l2, Φ y) ⊢ [∗ list] y ∈ l1, Φ y. `````` Robbert Krebbers committed Oct 30, 2017 101 102 103 `````` Proof. intros [l ->]%submseteq_Permutation. by rewrite big_sepL_app sep_elim_l. Qed. `````` Robbert Krebbers committed Aug 24, 2016 104 `````` `````` Robbert Krebbers committed Mar 24, 2017 105 106 `````` Global Instance big_sepL_mono' : Proper (pointwise_relation _ (pointwise_relation _ (⊢)) ==> (=) ==> (⊢)) `````` Robbert Krebbers committed Oct 30, 2017 107 `````` (big_opL (@bi_sep PROP) (A:=A)). `````` Robbert Krebbers committed Mar 24, 2017 108 `````` Proof. intros f g Hf m ? <-. apply big_opL_forall; apply _ || intros; apply Hf. Qed. `````` Robbert Krebbers committed Jun 14, 2018 109 `````` Global Instance big_sepL_id_mono' : `````` Robbert Krebbers committed Oct 31, 2018 110 `````` Proper (Forall2 (⊢) ==> (⊢)) (big_opL (@bi_sep PROP) (λ _ P, P)). `````` Robbert Krebbers committed Mar 24, 2017 111 `````` Proof. by induction 1 as [|P Q Ps Qs HPQ ? IH]; rewrite /= ?HPQ ?IH. Qed. `````` Robbert Krebbers committed Aug 24, 2016 112 `````` `````` Ralf Jung committed Apr 05, 2018 113 `````` Lemma big_sepL_emp l : ([∗ list] k↦y ∈ l, emp) ⊣⊢@{PROP} emp. `````` Robbert Krebbers committed Oct 30, 2017 114 115 `````` Proof. by rewrite big_opL_unit. Qed. `````` Jacques-Henri Jourdan committed Dec 05, 2016 116 117 118 119 `````` Lemma big_sepL_lookup_acc Φ l i x : l !! i = Some x → ([∗ list] k↦y ∈ l, Φ k y) ⊢ Φ i x ∗ (Φ i x -∗ ([∗ list] k↦y ∈ l, Φ k y)). Proof. `````` Robbert Krebbers committed Mar 24, 2017 120 121 122 `````` intros Hli. rewrite -(take_drop_middle l i x) // big_sepL_app /=. rewrite Nat.add_0_r take_length_le; eauto using lookup_lt_Some, Nat.lt_le_incl. rewrite assoc -!(comm _ (Φ _ _)) -assoc. by apply sep_mono_r, wand_intro_l. `````` Jacques-Henri Jourdan committed Dec 05, 2016 123 124 `````` Qed. `````` Robbert Krebbers committed Oct 30, 2017 125 `````` Lemma big_sepL_lookup Φ l i x `{!Absorbing (Φ i x)} : `````` Robbert Krebbers committed Nov 03, 2016 126 `````` l !! i = Some x → ([∗ list] k↦y ∈ l, Φ k y) ⊢ Φ i x. `````` Robbert Krebbers committed Oct 30, 2017 127 `````` Proof. intros. rewrite big_sepL_lookup_acc //. by rewrite sep_elim_l. Qed. `````` Robbert Krebbers committed Aug 24, 2016 128 `````` `````` Robbert Krebbers committed Oct 30, 2017 129 `````` Lemma big_sepL_elem_of (Φ : A → PROP) l x `{!Absorbing (Φ x)} : `````` Robbert Krebbers committed Nov 03, 2016 130 `````` x ∈ l → ([∗ list] y ∈ l, Φ y) ⊢ Φ x. `````` Robbert Krebbers committed Mar 24, 2017 131 132 133 `````` Proof. intros [i ?]%elem_of_list_lookup; eauto using (big_sepL_lookup (λ _, Φ)). Qed. `````` Robbert Krebbers committed Aug 28, 2016 134 `````` `````` Robbert Krebbers committed Oct 30, 2017 135 `````` Lemma big_sepL_fmap {B} (f : A → B) (Φ : nat → B → PROP) l : `````` Robbert Krebbers committed Nov 03, 2016 136 `````` ([∗ list] k↦y ∈ f <\$> l, Φ k y) ⊣⊢ ([∗ list] k↦y ∈ l, Φ k (f y)). `````` Robbert Krebbers committed Sep 28, 2016 137 `````` Proof. by rewrite big_opL_fmap. Qed. `````` Robbert Krebbers committed Aug 24, 2016 138 `````` `````` Robbert Krebbers committed May 02, 2019 139 140 141 142 `````` Lemma big_sepL_bind {B} (f : A → list B) (Φ : B → PROP) l : ([∗ list] y ∈ l ≫= f, Φ y) ⊣⊢ ([∗ list] x ∈ l, [∗ list] y ∈ f x, Φ y). Proof. by rewrite big_opL_bind. Qed. `````` Robbert Krebbers committed May 01, 2019 143 `````` Lemma big_sepL_sep Φ Ψ l : `````` Robbert Krebbers committed Nov 03, 2016 144 145 `````` ([∗ list] k↦x ∈ l, Φ k x ∗ Ψ k x) ⊣⊢ ([∗ list] k↦x ∈ l, Φ k x) ∗ ([∗ list] k↦x ∈ l, Ψ k x). `````` Robbert Krebbers committed May 01, 2019 146 `````` Proof. by rewrite big_opL_op. Qed. `````` Robbert Krebbers committed Sep 28, 2016 147 `````` `````` Robbert Krebbers committed Nov 27, 2016 148 149 150 `````` Lemma big_sepL_and Φ Ψ l : ([∗ list] k↦x ∈ l, Φ k x ∧ Ψ k x) ⊢ ([∗ list] k↦x ∈ l, Φ k x) ∧ ([∗ list] k↦x ∈ l, Ψ k x). `````` Robbert Krebbers committed Oct 30, 2017 151 `````` Proof. auto using and_intro, big_sepL_mono, and_elim_l, and_elim_r. Qed. `````` Robbert Krebbers committed Nov 27, 2016 152 `````` `````` Jacques-Henri Jourdan committed Dec 04, 2017 153 `````` Lemma big_sepL_persistently `{BiAffine PROP} Φ l : `````` Robbert Krebbers committed Mar 04, 2018 154 `````` ([∗ list] k↦x ∈ l, Φ k x) ⊣⊢ [∗ list] k↦x ∈ l, (Φ k x). `````` Robbert Krebbers committed Sep 28, 2016 155 `````` Proof. apply (big_opL_commute _). Qed. `````` Robbert Krebbers committed Aug 24, 2016 156 `````` `````` Jacques-Henri Jourdan committed Dec 04, 2017 157 `````` Lemma big_sepL_forall `{BiAffine PROP} Φ l : `````` Robbert Krebbers committed Oct 25, 2017 158 `````` (∀ k x, Persistent (Φ k x)) → `````` Ralf Jung committed Nov 22, 2016 159 `````` ([∗ list] k↦x ∈ l, Φ k x) ⊣⊢ (∀ k x, ⌜l !! k = Some x⌝ → Φ k x). `````` Robbert Krebbers committed Aug 24, 2016 160 161 162 `````` Proof. intros HΦ. apply (anti_symm _). { apply forall_intro=> k; apply forall_intro=> x. `````` Robbert Krebbers committed Oct 30, 2017 163 164 `````` apply impl_intro_l, pure_elim_l=> ?; by apply: big_sepL_lookup. } revert Φ HΦ. induction l as [|x l IH]=> Φ HΦ; [by auto using big_sepL_nil'|]. `````` Robbert Krebbers committed Oct 30, 2017 165 `````` rewrite big_sepL_cons. rewrite -persistent_and_sep; apply and_intro. `````` Robbert Krebbers committed Nov 21, 2016 166 `````` - by rewrite (forall_elim 0) (forall_elim x) pure_True // True_impl. `````` Robbert Krebbers committed Aug 24, 2016 167 168 169 170 `````` - rewrite -IH. apply forall_intro=> k; by rewrite (forall_elim (S k)). Qed. Lemma big_sepL_impl Φ Ψ l : `````` Robbert Krebbers committed Oct 30, 2017 171 `````` ([∗ list] k↦x ∈ l, Φ k x) -∗ `````` Jacques-Henri Jourdan committed Nov 02, 2017 172 `````` □ (∀ k x, ⌜l !! k = Some x⌝ → Φ k x -∗ Ψ k x) -∗ `````` Robbert Krebbers committed Oct 30, 2017 173 `````` [∗ list] k↦x ∈ l, Ψ k x. `````` Robbert Krebbers committed Aug 24, 2016 174 `````` Proof. `````` Robbert Krebbers committed Oct 30, 2017 175 176 `````` apply wand_intro_l. revert Φ Ψ. induction l as [|x l IH]=> Φ Ψ /=. { by rewrite sep_elim_r. } `````` 177 `````` rewrite intuitionistically_sep_dup -assoc [(□ _ ∗ _)%I]comm -!assoc assoc. `````` Robbert Krebbers committed Oct 30, 2017 178 179 `````` apply sep_mono. - rewrite (forall_elim 0) (forall_elim x) pure_True // True_impl. `````` 180 `````` by rewrite intuitionistically_elim wand_elim_l. `````` Robbert Krebbers committed Oct 30, 2017 181 `````` - rewrite comm -(IH (Φ ∘ S) (Ψ ∘ S)) /=. `````` Jacques-Henri Jourdan committed Nov 02, 2017 182 `````` apply sep_mono_l, affinely_mono, persistently_mono. `````` Robbert Krebbers committed Oct 30, 2017 183 `````` apply forall_intro=> k. by rewrite (forall_elim (S k)). `````` Robbert Krebbers committed Aug 24, 2016 184 185 `````` Qed. `````` Robbert Krebbers committed Apr 04, 2018 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 `````` Lemma big_sepL_delete Φ l i x : l !! i = Some x → ([∗ list] k↦y ∈ l, Φ k y) ⊣⊢ Φ i x ∗ [∗ list] k↦y ∈ l, if decide (k = i) then emp else Φ k y. Proof. intros. rewrite -(take_drop_middle l i x) // !big_sepL_app /= Nat.add_0_r. rewrite take_length_le; last eauto using lookup_lt_Some, Nat.lt_le_incl. rewrite decide_True // left_id. rewrite assoc -!(comm _ (Φ _ _)) -assoc. do 2 f_equiv. - apply big_sepL_proper=> k y Hk. apply lookup_lt_Some in Hk. rewrite take_length in Hk. by rewrite decide_False; last lia. - apply big_sepL_proper=> k y _. by rewrite decide_False; last lia. Qed. Lemma big_sepL_delete' `{!BiAffine PROP} Φ l i x : l !! i = Some x → ([∗ list] k↦y ∈ l, Φ k y) ⊣⊢ Φ i x ∗ [∗ list] k↦y ∈ l, ⌜ k ≠ i ⌝ → Φ k y. Proof. intros. rewrite big_sepL_delete //. (do 2 f_equiv)=> k y. rewrite -decide_emp. by repeat case_decide. Qed. `````` Robbert Krebbers committed Oct 31, 2018 208 209 210 211 `````` Lemma big_sepL_replicate l P : [∗] replicate (length l) P ⊣⊢ [∗ list] y ∈ l, P. Proof. induction l as [|x l]=> //=; by f_equiv. Qed. `````` Robbert Krebbers committed Oct 30, 2017 212 `````` Global Instance big_sepL_nil_persistent Φ : `````` Robbert Krebbers committed Oct 25, 2017 213 `````` Persistent ([∗ list] k↦x ∈ [], Φ k x). `````` Robbert Krebbers committed Mar 24, 2017 214 `````` Proof. simpl; apply _. Qed. `````` Robbert Krebbers committed Oct 30, 2017 215 `````` Global Instance big_sepL_persistent Φ l : `````` Robbert Krebbers committed Oct 25, 2017 216 `````` (∀ k x, Persistent (Φ k x)) → Persistent ([∗ list] k↦x ∈ l, Φ k x). `````` Robbert Krebbers committed Mar 24, 2017 217 `````` Proof. revert Φ. induction l as [|x l IH]=> Φ ? /=; apply _. Qed. `````` Robbert Krebbers committed Oct 30, 2017 218 `````` Global Instance big_sepL_persistent_id Ps : `````` Robbert Krebbers committed Oct 25, 2017 219 `````` TCForall Persistent Ps → Persistent ([∗] Ps). `````` Robbert Krebbers committed Mar 24, 2017 220 `````` Proof. induction 1; simpl; apply _. Qed. `````` Aleš Bizjak committed Oct 30, 2017 221 `````` `````` Robbert Krebbers committed Oct 30, 2017 222 223 224 `````` Global Instance big_sepL_nil_affine Φ : Affine ([∗ list] k↦x ∈ [], Φ k x). Proof. simpl; apply _. Qed. `````` Aleš Bizjak committed Oct 30, 2017 225 226 227 `````` Global Instance big_sepL_affine Φ l : (∀ k x, Affine (Φ k x)) → Affine ([∗ list] k↦x ∈ l, Φ k x). Proof. revert Φ. induction l as [|x l IH]=> Φ ? /=; apply _. Qed. `````` Robbert Krebbers committed Oct 30, 2017 228 229 `````` Global Instance big_sepL_affine_id Ps : TCForall Affine Ps → Affine ([∗] Ps). Proof. induction 1; simpl; apply _. Qed. `````` Robbert Krebbers committed Oct 30, 2017 230 ``````End sep_list. `````` Robbert Krebbers committed Aug 24, 2016 231 `````` `````` Robbert Krebbers committed Jun 15, 2018 232 ``````Section sep_list_more. `````` Ralf Jung committed Dec 20, 2016 233 234 `````` Context {A : Type}. Implicit Types l : list A. `````` Robbert Krebbers committed Oct 30, 2017 235 `````` Implicit Types Φ Ψ : nat → A → PROP. `````` Ralf Jung committed Dec 20, 2016 236 237 238 `````` (* Some lemmas depend on the generalized versions of the above ones. *) Lemma big_sepL_zip_with {B C} Φ f (l1 : list B) (l2 : list C) : `````` Robbert Krebbers committed Mar 14, 2017 239 `````` ([∗ list] k↦x ∈ zip_with f l1 l2, Φ k x) `````` Robbert Krebbers committed Oct 30, 2017 240 `````` ⊣⊢ ([∗ list] k↦x ∈ l1, if l2 !! k is Some y then Φ k (f x y) else emp). `````` Ralf Jung committed Dec 20, 2016 241 `````` Proof. `````` Robbert Krebbers committed Oct 30, 2017 242 243 244 `````` revert Φ l2; induction l1 as [|x l1 IH]=> Φ [|y l2] //=. - by rewrite big_sepL_emp left_id. - by rewrite IH. `````` Ralf Jung committed Dec 20, 2016 245 `````` Qed. `````` Robbert Krebbers committed Jun 15, 2018 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 ``````End sep_list_more. Lemma big_sepL2_alt {A B} (Φ : nat → A → B → PROP) l1 l2 : ([∗ list] k↦y1;y2 ∈ l1; l2, Φ k y1 y2) ⊣⊢ ⌜ length l1 = length l2 ⌝ ∧ [∗ list] k ↦ y ∈ zip l1 l2, Φ k (y.1) (y.2). Proof. apply (anti_symm _). - apply and_intro. + revert Φ l2. induction l1 as [|x1 l1 IH]=> Φ -[|x2 l2] /=; auto using pure_intro, False_elim. rewrite IH sep_elim_r. apply pure_mono; auto. + revert Φ l2. induction l1 as [|x1 l1 IH]=> Φ -[|x2 l2] /=; auto using pure_intro, False_elim. by rewrite IH. - apply pure_elim_l=> /Forall2_same_length Hl. revert Φ. induction Hl as [|x1 l1 x2 l2 _ _ IH]=> Φ //=. by rewrite -IH. Qed. (** ** Big ops over two lists *) Section sep_list2. Context {A B : Type}. Implicit Types Φ Ψ : nat → A → B → PROP. Lemma big_sepL2_nil Φ : ([∗ list] k↦y1;y2 ∈ []; [], Φ k y1 y2) ⊣⊢ emp. Proof. done. Qed. Lemma big_sepL2_nil' `{BiAffine PROP} P Φ : P ⊢ [∗ list] k↦y1;y2 ∈ [];[], Φ k y1 y2. Proof. apply (affine _). Qed. Lemma big_sepL2_cons Φ x1 x2 l1 l2 : ([∗ list] k↦y1;y2 ∈ x1 :: l1; x2 :: l2, Φ k y1 y2) ⊣⊢ Φ 0 x1 x2 ∗ [∗ list] k↦y1;y2 ∈ l1;l2, Φ (S k) y1 y2. Proof. done. Qed. Lemma big_sepL2_cons_inv_l Φ x1 l1 l2 : ([∗ list] k↦y1;y2 ∈ x1 :: l1; l2, Φ k y1 y2) -∗ ∃ x2 l2', ⌜ l2 = x2 :: l2' ⌝ ∧ Φ 0 x1 x2 ∗ [∗ list] k↦y1;y2 ∈ l1;l2', Φ (S k) y1 y2. Proof. destruct l2 as [|x2 l2]; simpl; auto using False_elim. by rewrite -(exist_intro x2) -(exist_intro l2) pure_True // left_id. Qed. Lemma big_sepL2_cons_inv_r Φ x2 l1 l2 : ([∗ list] k↦y1;y2 ∈ l1; x2 :: l2, Φ k y1 y2) -∗ ∃ x1 l1', ⌜ l1 = x1 :: l1' ⌝ ∧ Φ 0 x1 x2 ∗ [∗ list] k↦y1;y2 ∈ l1';l2, Φ (S k) y1 y2. Proof. destruct l1 as [|x1 l1]; simpl; auto using False_elim. by rewrite -(exist_intro x1) -(exist_intro l1) pure_True // left_id. Qed. Lemma big_sepL2_singleton Φ x1 x2 : ([∗ list] k↦y1;y2 ∈ [x1];[x2], Φ k y1 y2) ⊣⊢ Φ 0 x1 x2. Proof. by rewrite /= right_id. Qed. Lemma big_sepL2_length Φ l1 l2 : ([∗ list] k↦y1;y2 ∈ l1; l2, Φ k y1 y2) -∗ ⌜ length l1 = length l2 ⌝. Proof. by rewrite big_sepL2_alt and_elim_l. Qed. Lemma big_sepL2_app Φ l1 l2 l1' l2' : ([∗ list] k↦y1;y2 ∈ l1; l1', Φ k y1 y2) -∗ ([∗ list] k↦y1;y2 ∈ l2; l2', Φ (length l1 + k) y1 y2) -∗ ([∗ list] k↦y1;y2 ∈ l1 ++ l2; l1' ++ l2', Φ k y1 y2). Proof. apply wand_intro_r. revert Φ l1'. induction l1 as [|x1 l1 IH]=> Φ -[|x1' l1'] /=. - by rewrite left_id. - rewrite left_absorb. apply False_elim. - rewrite left_absorb. apply False_elim. - by rewrite -assoc IH. Qed. Lemma big_sepL2_app_inv_l Φ l1' l1'' l2 : ([∗ list] k↦y1;y2 ∈ l1' ++ l1''; l2, Φ k y1 y2) -∗ ∃ l2' l2'', ⌜ l2 = l2' ++ l2'' ⌝ ∧ ([∗ list] k↦y1;y2 ∈ l1';l2', Φ k y1 y2) ∗ ([∗ list] k↦y1;y2 ∈ l1'';l2'', Φ (length l1' + k) y1 y2). Proof. rewrite -(exist_intro (take (length l1') l2)) -(exist_intro (drop (length l1') l2)) take_drop pure_True // left_id. revert Φ l2. induction l1' as [|x1 l1' IH]=> Φ -[|x2 l2] /=; [by rewrite left_id|by rewrite left_id|apply False_elim|]. by rewrite IH -assoc. Qed. Lemma big_sepL2_app_inv_r Φ l1 l2' l2'' : ([∗ list] k↦y1;y2 ∈ l1; l2' ++ l2'', Φ k y1 y2) -∗ ∃ l1' l1'', ⌜ l1 = l1' ++ l1'' ⌝ ∧ ([∗ list] k↦y1;y2 ∈ l1';l2', Φ k y1 y2) ∗ ([∗ list] k↦y1;y2 ∈ l1'';l2'', Φ (length l2' + k) y1 y2). Proof. rewrite -(exist_intro (take (length l2') l1)) -(exist_intro (drop (length l2') l1)) take_drop pure_True // left_id. revert Φ l1. induction l2' as [|x2 l2' IH]=> Φ -[|x1 l1] /=; [by rewrite left_id|by rewrite left_id|apply False_elim|]. by rewrite IH -assoc. Qed. `````` Dan Frumin committed Jul 14, 2019 338 339 340 341 342 343 344 345 346 347 `````` Lemma big_sepL2_app_inv Φ l1 l2 l1' l2' : length l1 = length l1' → ([∗ list] k↦y1;y2 ∈ l1 ++ l2; l1' ++ l2', Φ k y1 y2) -∗ ([∗ list] k↦y1;y2 ∈ l1; l1', Φ k y1 y2) ∗ ([∗ list] k↦y1;y2 ∈ l2; l2', Φ (length l1 + k)%nat y1 y2). Proof. revert Φ l1'. induction l1 as [|x1 l1 IH]=> Φ -[|x1' l1'] //= ?; simplify_eq. - by rewrite left_id. - by rewrite -assoc IH. Qed. `````` Robbert Krebbers committed Jun 15, 2018 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 `````` Lemma big_sepL2_mono Φ Ψ l1 l2 : (∀ k y1 y2, l1 !! k = Some y1 → l2 !! k = Some y2 → Φ k y1 y2 ⊢ Ψ k y1 y2) → ([∗ list] k ↦ y1;y2 ∈ l1;l2, Φ k y1 y2) ⊢ [∗ list] k ↦ y1;y2 ∈ l1;l2, Ψ k y1 y2. Proof. intros H. rewrite !big_sepL2_alt. f_equiv. apply big_sepL_mono=> k [y1 y2]. rewrite lookup_zip_with=> ?; simplify_option_eq; auto. Qed. Lemma big_sepL2_proper Φ Ψ l1 l2 : (∀ k y1 y2, l1 !! k = Some y1 → l2 !! k = Some y2 → Φ k y1 y2 ⊣⊢ Ψ k y1 y2) → ([∗ list] k ↦ y1;y2 ∈ l1;l2, Φ k y1 y2) ⊣⊢ [∗ list] k ↦ y1;y2 ∈ l1;l2, Ψ k y1 y2. Proof. intros; apply (anti_symm _); apply big_sepL2_mono; auto using equiv_entails, equiv_entails_sym. Qed. Global Instance big_sepL2_ne n : Proper (pointwise_relation _ (pointwise_relation _ (pointwise_relation _ (dist n))) ==> (=) ==> (=) ==> (dist n)) (big_sepL2 (PROP:=PROP) (A:=A) (B:=B)). Proof. intros Φ1 Φ2 HΦ x1 ? <- x2 ? <-. rewrite !big_sepL2_alt. f_equiv. f_equiv=> k [y1 y2]. apply HΦ. Qed. Global Instance big_sepL2_mono' : Proper (pointwise_relation _ (pointwise_relation _ (pointwise_relation _ (⊢))) ==> (=) ==> (=) ==> (⊢)) (big_sepL2 (PROP:=PROP) (A:=A) (B:=B)). Proof. intros f g Hf l1 ? <- l2 ? <-. apply big_sepL2_mono; intros; apply Hf. Qed. Global Instance big_sepL2_proper' : Proper (pointwise_relation _ (pointwise_relation _ (pointwise_relation _ (⊣⊢))) ==> (=) ==> (=) ==> (⊣⊢)) (big_sepL2 (PROP:=PROP) (A:=A) (B:=B)). Proof. intros f g Hf l1 ? <- l2 ? <-. apply big_sepL2_proper; intros; apply Hf. Qed. Lemma big_sepL2_lookup_acc Φ l1 l2 i x1 x2 : l1 !! i = Some x1 → l2 !! i = Some x2 → ([∗ list] k↦y1;y2 ∈ l1;l2, Φ k y1 y2) ⊢ Φ i x1 x2 ∗ (Φ i x1 x2 -∗ ([∗ list] k↦y1;y2 ∈ l1;l2, Φ k y1 y2)). Proof. intros Hl1 Hl2. rewrite big_sepL2_alt. apply pure_elim_l=> Hl. rewrite {1}big_sepL_lookup_acc; last by rewrite lookup_zip_with; simplify_option_eq. by rewrite pure_True // left_id. Qed. Lemma big_sepL2_lookup Φ l1 l2 i x1 x2 `{!Absorbing (Φ i x1 x2)} : l1 !! i = Some x1 → l2 !! i = Some x2 → ([∗ list] k↦y1;y2 ∈ l1;l2, Φ k y1 y2) ⊢ Φ i x1 x2. Proof. intros. rewrite big_sepL2_lookup_acc //. by rewrite sep_elim_l. Qed. Lemma big_sepL2_fmap_l {A'} (f : A → A') (Φ : nat → A' → B → PROP) l1 l2 : ([∗ list] k↦y1;y2 ∈ f <\$> l1; l2, Φ k y1 y2) ⊣⊢ ([∗ list] k↦y1;y2 ∈ l1;l2, Φ k (f y1) y2). Proof. rewrite !big_sepL2_alt fmap_length zip_with_fmap_l zip_with_zip big_sepL_fmap. by f_equiv; f_equiv=> k [??]. Qed. Lemma big_sepL2_fmap_r {B'} (g : B → B') (Φ : nat → A → B' → PROP) l1 l2 : ([∗ list] k↦y1;y2 ∈ l1; g <\$> l2, Φ k y1 y2) ⊣⊢ ([∗ list] k↦y1;y2 ∈ l1;l2, Φ k y1 (g y2)). Proof. rewrite !big_sepL2_alt fmap_length zip_with_fmap_r zip_with_zip big_sepL_fmap. by f_equiv; f_equiv=> k [??]. Qed. `````` Robbert Krebbers committed Jul 05, 2019 413 414 415 416 417 418 419 420 421 422 423 `````` Lemma big_sepL2_reverse_2 (Φ : A → B → PROP) l1 l2 : ([∗ list] y1;y2 ∈ l1;l2, Φ y1 y2) ⊢ ([∗ list] y1;y2 ∈ reverse l1;reverse l2, Φ y1 y2). Proof. revert l2. induction l1 as [|x1 l1 IH]; intros [|x2 l2]; simpl; auto using False_elim. rewrite !reverse_cons (comm bi_sep) IH. by rewrite (big_sepL2_app _ _ [x1] _ [x2]) big_sepL2_singleton wand_elim_l. Qed. Lemma big_sepL2_reverse (Φ : A → B → PROP) l1 l2 : ([∗ list] y1;y2 ∈ reverse l1;reverse l2, Φ y1 y2) ⊣⊢ ([∗ list] y1;y2 ∈ l1;l2, Φ y1 y2). Proof. apply (anti_symm _); by rewrite big_sepL2_reverse_2 ?reverse_involutive. Qed. `````` Robbert Krebbers committed May 01, 2019 424 `````` Lemma big_sepL2_sep Φ Ψ l1 l2 : `````` Robbert Krebbers committed Jun 15, 2018 425 426 427 `````` ([∗ list] k↦y1;y2 ∈ l1;l2, Φ k y1 y2 ∗ Ψ k y1 y2) ⊣⊢ ([∗ list] k↦y1;y2 ∈ l1;l2, Φ k y1 y2) ∗ ([∗ list] k↦y1;y2 ∈ l1;l2, Ψ k y1 y2). Proof. `````` Robbert Krebbers committed May 01, 2019 428 `````` rewrite !big_sepL2_alt big_sepL_sep !persistent_and_affinely_sep_l. `````` Robbert Krebbers committed Jun 15, 2018 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 `````` rewrite -assoc (assoc _ _ ( _)%I). rewrite -(comm bi_sep ( _)%I). rewrite -assoc (assoc _ _ ( _)%I) -!persistent_and_affinely_sep_l. by rewrite affinely_and_r persistent_and_affinely_sep_l idemp. Qed. Lemma big_sepL2_and Φ Ψ l1 l2 : ([∗ list] k↦y1;y2 ∈ l1;l2, Φ k y1 y2 ∧ Ψ k y1 y2) ⊢ ([∗ list] k↦y1;y2 ∈ l1;l2, Φ k y1 y2) ∧ ([∗ list] k↦y1;y2 ∈ l1;l2, Ψ k y1 y2). Proof. auto using and_intro, big_sepL2_mono, and_elim_l, and_elim_r. Qed. Lemma big_sepL2_persistently `{BiAffine PROP} Φ l1 l2 : ([∗ list] k↦y1;y2 ∈ l1;l2, Φ k y1 y2) ⊣⊢ [∗ list] k↦y1;y2 ∈ l1;l2, (Φ k y1 y2). Proof. by rewrite !big_sepL2_alt persistently_and persistently_pure big_sepL_persistently. Qed. Lemma big_sepL2_impl Φ Ψ l1 l2 : ([∗ list] k↦y1;y2 ∈ l1;l2, Φ k y1 y2) -∗ □ (∀ k x1 x2, ⌜l1 !! k = Some x1⌝ → ⌜l2 !! k = Some x2⌝ → Φ k x1 x2 -∗ Ψ k x1 x2) -∗ [∗ list] k↦y1;y2 ∈ l1;l2, Ψ k y1 y2. Proof. apply wand_intro_l. revert Φ Ψ l2. induction l1 as [|x1 l1 IH]=> Φ Ψ [|x2 l2] /=; [by rewrite sep_elim_r..|]. rewrite intuitionistically_sep_dup -assoc [(□ _ ∗ _)%I]comm -!assoc assoc. apply sep_mono. - rewrite (forall_elim 0) (forall_elim x1) (forall_elim x2) !pure_True // !True_impl. by rewrite intuitionistically_elim wand_elim_l. - rewrite comm -(IH (Φ ∘ S) (Ψ ∘ S)) /=. apply sep_mono_l, affinely_mono, persistently_mono. apply forall_intro=> k. by rewrite (forall_elim (S k)). Qed. Global Instance big_sepL2_nil_persistent Φ : Persistent ([∗ list] k↦y1;y2 ∈ []; [], Φ k y1 y2). Proof. simpl; apply _. Qed. Global Instance big_sepL2_persistent Φ l1 l2 : (∀ k x1 x2, Persistent (Φ k x1 x2)) → Persistent ([∗ list] k↦y1;y2 ∈ l1;l2, Φ k y1 y2). Proof. rewrite big_sepL2_alt. apply _. Qed. Global Instance big_sepL2_nil_affine Φ : Affine ([∗ list] k↦y1;y2 ∈ []; [], Φ k y1 y2). Proof. simpl; apply _. Qed. Global Instance big_sepL2_affine Φ l1 l2 : (∀ k x1 x2, Affine (Φ k x1 x2)) → Affine ([∗ list] k↦y1;y2 ∈ l1;l2, Φ k y1 y2). Proof. rewrite big_sepL2_alt. apply _. Qed. `````` Robbert Krebbers committed Oct 30, 2017 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 ``````End sep_list2. Section and_list. Context {A : Type}. Implicit Types l : list A. Implicit Types Φ Ψ : nat → A → PROP. Lemma big_andL_nil Φ : ([∧ list] k↦y ∈ nil, Φ k y) ⊣⊢ True. Proof. done. Qed. Lemma big_andL_nil' P Φ : P ⊢ [∧ list] k↦y ∈ nil, Φ k y. Proof. by apply pure_intro. Qed. Lemma big_andL_cons Φ x l : ([∧ list] k↦y ∈ x :: l, Φ k y) ⊣⊢ Φ 0 x ∧ [∧ list] k↦y ∈ l, Φ (S k) y. Proof. by rewrite big_opL_cons. Qed. Lemma big_andL_singleton Φ x : ([∧ list] k↦y ∈ [x], Φ k y) ⊣⊢ Φ 0 x. Proof. by rewrite big_opL_singleton. Qed. Lemma big_andL_app Φ l1 l2 : ([∧ list] k↦y ∈ l1 ++ l2, Φ k y) ⊣⊢ ([∧ list] k↦y ∈ l1, Φ k y) ∧ ([∧ list] k↦y ∈ l2, Φ (length l1 + k) y). Proof. by rewrite big_opL_app. Qed. Lemma big_andL_mono Φ Ψ l : (∀ k y, l !! k = Some y → Φ k y ⊢ Ψ k y) → ([∧ list] k ↦ y ∈ l, Φ k y) ⊢ [∧ list] k ↦ y ∈ l, Ψ k y. Proof. apply big_opL_forall; apply _. Qed. Lemma big_andL_proper Φ Ψ l : (∀ k y, l !! k = Some y → Φ k y ⊣⊢ Ψ k y) → ([∧ list] k ↦ y ∈ l, Φ k y) ⊣⊢ ([∧ list] k ↦ y ∈ l, Ψ k y). Proof. apply big_opL_proper. Qed. Lemma big_andL_submseteq (Φ : A → PROP) l1 l2 : l1 ⊆+ l2 → ([∧ list] y ∈ l2, Φ y) ⊢ [∧ list] y ∈ l1, Φ y. Proof. intros [l ->]%submseteq_Permutation. by rewrite big_andL_app and_elim_l. Qed. Global Instance big_andL_mono' : Proper (pointwise_relation _ (pointwise_relation _ (⊢)) ==> (=) ==> (⊢)) (big_opL (@bi_and PROP) (A:=A)). Proof. intros f g Hf m ? <-. apply big_opL_forall; apply _ || intros; apply Hf. Qed. `````` Robbert Krebbers committed Jun 14, 2018 517 `````` Global Instance big_andL_id_mono' : `````` Robbert Krebbers committed Oct 31, 2018 518 `````` Proper (Forall2 (⊢) ==> (⊢)) (big_opL (@bi_and PROP) (λ _ P, P)). `````` Robbert Krebbers committed Oct 30, 2017 519 520 `````` Proof. by induction 1 as [|P Q Ps Qs HPQ ? IH]; rewrite /= ?HPQ ?IH. Qed. `````` Robbert Krebbers committed May 01, 2019 521 `````` Lemma big_andL_lookup Φ l i x : `````` Robbert Krebbers committed Oct 30, 2017 522 523 524 525 526 527 528 `````` l !! i = Some x → ([∧ list] k↦y ∈ l, Φ k y) ⊢ Φ i x. Proof. intros. rewrite -(take_drop_middle l i x) // big_andL_app /=. rewrite Nat.add_0_r take_length_le; eauto using lookup_lt_Some, Nat.lt_le_incl, and_elim_l', and_elim_r'. Qed. `````` Robbert Krebbers committed May 01, 2019 529 `````` Lemma big_andL_elem_of (Φ : A → PROP) l x : `````` Robbert Krebbers committed Oct 30, 2017 530 531 532 533 534 535 536 537 538 `````` x ∈ l → ([∧ list] y ∈ l, Φ y) ⊢ Φ x. Proof. intros [i ?]%elem_of_list_lookup; eauto using (big_andL_lookup (λ _, Φ)). Qed. Lemma big_andL_fmap {B} (f : A → B) (Φ : nat → B → PROP) l : ([∧ list] k↦y ∈ f <\$> l, Φ k y) ⊣⊢ ([∧ list] k↦y ∈ l, Φ k (f y)). Proof. by rewrite big_opL_fmap. Qed. `````` Robbert Krebbers committed May 02, 2019 539 540 541 542 `````` Lemma big_andL_bind {B} (f : A → list B) (Φ : B → PROP) l : ([∧ list] y ∈ l ≫= f, Φ y) ⊣⊢ ([∧ list] x ∈ l, [∧ list] y ∈ f x, Φ y). Proof. by rewrite big_opL_bind. Qed. `````` Robbert Krebbers committed Oct 30, 2017 543 544 `````` Lemma big_andL_and Φ Ψ l : ([∧ list] k↦x ∈ l, Φ k x ∧ Ψ k x) `````` Robbert Krebbers committed May 01, 2019 545 546 `````` ⊣⊢ ([∧ list] k↦x ∈ l, Φ k x) ∧ ([∧ list] k↦x ∈ l, Ψ k x). Proof. by rewrite big_opL_op. Qed. `````` Robbert Krebbers committed Oct 30, 2017 547 548 `````` Lemma big_andL_persistently Φ l : `````` Robbert Krebbers committed Mar 04, 2018 549 `````` ([∧ list] k↦x ∈ l, Φ k x) ⊣⊢ [∧ list] k↦x ∈ l, (Φ k x). `````` Robbert Krebbers committed Oct 30, 2017 550 551 `````` Proof. apply (big_opL_commute _). Qed. `````` Robbert Krebbers committed May 01, 2019 552 `````` Lemma big_andL_forall Φ l : `````` Robbert Krebbers committed Oct 30, 2017 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 `````` ([∧ list] k↦x ∈ l, Φ k x) ⊣⊢ (∀ k x, ⌜l !! k = Some x⌝ → Φ k x). Proof. apply (anti_symm _). { apply forall_intro=> k; apply forall_intro=> x. apply impl_intro_l, pure_elim_l=> ?; by apply: big_andL_lookup. } revert Φ. induction l as [|x l IH]=> Φ; [by auto using big_andL_nil'|]. rewrite big_andL_cons. apply and_intro. - by rewrite (forall_elim 0) (forall_elim x) pure_True // True_impl. - rewrite -IH. apply forall_intro=> k; by rewrite (forall_elim (S k)). Qed. Global Instance big_andL_nil_persistent Φ : Persistent ([∧ list] k↦x ∈ [], Φ k x). Proof. simpl; apply _. Qed. Global Instance big_andL_persistent Φ l : (∀ k x, Persistent (Φ k x)) → Persistent ([∧ list] k↦x ∈ l, Φ k x). Proof. revert Φ. induction l as [|x l IH]=> Φ ? /=; apply _. Qed. End and_list. `````` Robbert Krebbers committed Aug 24, 2016 571 `````` `````` Robbert Krebbers committed May 01, 2019 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 ``````Section or_list. Context {A : Type}. Implicit Types l : list A. Implicit Types Φ Ψ : nat → A → PROP. Lemma big_orL_nil Φ : ([∨ list] k↦y ∈ nil, Φ k y) ⊣⊢ False. Proof. done. Qed. Lemma big_orL_cons Φ x l : ([∨ list] k↦y ∈ x :: l, Φ k y) ⊣⊢ Φ 0 x ∨ [∨ list] k↦y ∈ l, Φ (S k) y. Proof. by rewrite big_opL_cons. Qed. Lemma big_orL_singleton Φ x : ([∨ list] k↦y ∈ [x], Φ k y) ⊣⊢ Φ 0 x. Proof. by rewrite big_opL_singleton. Qed. Lemma big_orL_app Φ l1 l2 : ([∨ list] k↦y ∈ l1 ++ l2, Φ k y) ⊣⊢ ([∨ list] k↦y ∈ l1, Φ k y) ∨ ([∨ list] k↦y ∈ l2, Φ (length l1 + k) y). Proof. by rewrite big_opL_app. Qed. Lemma big_orL_mono Φ Ψ l : (∀ k y, l !! k = Some y → Φ k y ⊢ Ψ k y) → ([∨ list] k ↦ y ∈ l, Φ k y) ⊢ [∨ list] k ↦ y ∈ l, Ψ k y. Proof. apply big_opL_forall; apply _. Qed. Lemma big_orL_proper Φ Ψ l : (∀ k y, l !! k = Some y → Φ k y ⊣⊢ Ψ k y) → ([∨ list] k ↦ y ∈ l, Φ k y) ⊣⊢ ([∨ list] k ↦ y ∈ l, Ψ k y). Proof. apply big_opL_proper. Qed. Lemma big_orL_submseteq (Φ : A → PROP) l1 l2 : l1 ⊆+ l2 → ([∨ list] y ∈ l1, Φ y) ⊢ [∨ list] y ∈ l2, Φ y. Proof. intros [l ->]%submseteq_Permutation. by rewrite big_orL_app -or_intro_l. Qed. Global Instance big_orL_mono' : Proper (pointwise_relation _ (pointwise_relation _ (⊢)) ==> (=) ==> (⊢)) (big_opL (@bi_or PROP) (A:=A)). Proof. intros f g Hf m ? <-. apply big_opL_forall; apply _ || intros; apply Hf. Qed. Global Instance big_orL_id_mono' : Proper (Forall2 (⊢) ==> (⊢)) (big_opL (@bi_or PROP) (λ _ P, P)). Proof. by induction 1 as [|P Q Ps Qs HPQ ? IH]; rewrite /= ?HPQ ?IH. Qed. Lemma big_orL_lookup Φ l i x : l !! i = Some x → Φ i x ⊢ ([∨ list] k↦y ∈ l, Φ k y). Proof. intros. rewrite -(take_drop_middle l i x) // big_orL_app /=. rewrite Nat.add_0_r take_length_le; eauto using lookup_lt_Some, Nat.lt_le_incl, or_intro_l', or_intro_r'. Qed. Lemma big_orL_elem_of (Φ : A → PROP) l x : x ∈ l → Φ x ⊢ ([∨ list] y ∈ l, Φ y). Proof. intros [i ?]%elem_of_list_lookup; eauto using (big_orL_lookup (λ _, Φ)). Qed. Lemma big_orL_fmap {B} (f : A → B) (Φ : nat → B → PROP) l : ([∨ list] k↦y ∈ f <\$> l, Φ k y) ⊣⊢ ([∨ list] k↦y ∈ l, Φ k (f y)). Proof. by rewrite big_opL_fmap. Qed. `````` Robbert Krebbers committed May 02, 2019 629 630 631 632 `````` Lemma big_orL_bind {B} (f : A → list B) (Φ : B → PROP) l : ([∨ list] y ∈ l ≫= f, Φ y) ⊣⊢ ([∨ list] x ∈ l, [∨ list] y ∈ f x, Φ y). Proof. by rewrite big_opL_bind. Qed. `````` Robbert Krebbers committed May 01, 2019 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 `````` Lemma big_orL_or Φ Ψ l : ([∨ list] k↦x ∈ l, Φ k x ∨ Ψ k x) ⊣⊢ ([∨ list] k↦x ∈ l, Φ k x) ∨ ([∨ list] k↦x ∈ l, Ψ k x). Proof. by rewrite big_opL_op. Qed. Lemma big_orL_persistently Φ l : ([∨ list] k↦x ∈ l, Φ k x) ⊣⊢ [∨ list] k↦x ∈ l, (Φ k x). Proof. apply (big_opL_commute _). Qed. Lemma big_orL_exist Φ l : ([∨ list] k↦x ∈ l, Φ k x) ⊣⊢ (∃ k x, ⌜l !! k = Some x⌝ ∧ Φ k x). Proof. apply (anti_symm _). { revert Φ. induction l as [|x l IH]=> Φ. { rewrite big_orL_nil. apply False_elim. } rewrite big_orL_cons. apply or_elim. - by rewrite -(exist_intro 0) -(exist_intro x) pure_True // left_id. - rewrite IH. apply exist_elim=> k. by rewrite -(exist_intro (S k)). } apply exist_elim=> k; apply exist_elim=> x. apply pure_elim_l=> ?. by apply: big_orL_lookup. Qed. Lemma big_orL_sep_l P Φ l : P ∗ ([∨ list] k↦x ∈ l, Φ k x) ⊣⊢ ([∨ list] k↦x ∈ l, P ∗ Φ k x). Proof. rewrite !big_orL_exist sep_exist_l. f_equiv=> k. rewrite sep_exist_l. f_equiv=> x. by rewrite !persistent_and_affinely_sep_l !assoc (comm _ P). Qed. Lemma big_orL_sep_r Q Φ l : ([∨ list] k↦x ∈ l, Φ k x) ∗ Q ⊣⊢ ([∨ list] k↦x ∈ l, Φ k x ∗ Q). Proof. setoid_rewrite (comm bi_sep). apply big_orL_sep_l. Qed. Global Instance big_orL_nil_persistent Φ : Persistent ([∨ list] k↦x ∈ [], Φ k x). Proof. simpl; apply _. Qed. Global Instance big_orL_persistent Φ l : (∀ k x, Persistent (Φ k x)) → Persistent ([∨ list] k↦x ∈ l, Φ k x). Proof. revert Φ. induction l as [|x l IH]=> Φ ? /=; apply _. Qed. End or_list. `````` Robbert Krebbers committed Apr 08, 2016 674 ``````(** ** Big ops over finite maps *) `````` Dan Frumin committed Apr 07, 2019 675 ``````Section map. `````` Robbert Krebbers committed Feb 17, 2016 676 677 `````` Context `{Countable K} {A : Type}. Implicit Types m : gmap K A. `````` Robbert Krebbers committed Oct 30, 2017 678 `````` Implicit Types Φ Ψ : K → A → PROP. `````` Robbert Krebbers committed Feb 14, 2016 679 `````` `````` Robbert Krebbers committed Oct 30, 2017 680 681 682 683 `````` Lemma big_sepM_mono Φ Ψ m : (∀ k x, m !! k = Some x → Φ k x ⊢ Ψ k x) → ([∗ map] k ↦ x ∈ m, Φ k x) ⊢ [∗ map] k ↦ x ∈ m, Ψ k x. Proof. apply big_opM_forall; apply _ || auto. Qed. `````` Robbert Krebbers committed Jul 22, 2016 684 685 `````` Lemma big_sepM_proper Φ Ψ m : (∀ k x, m !! k = Some x → Φ k x ⊣⊢ Ψ k x) → `````` Robbert Krebbers committed Nov 03, 2016 686 `````` ([∗ map] k ↦ x ∈ m, Φ k x) ⊣⊢ ([∗ map] k ↦ x ∈ m, Ψ k x). `````` Robbert Krebbers committed Sep 28, 2016 687 `````` Proof. apply big_opM_proper. Qed. `````` Jacques-Henri Jourdan committed Dec 04, 2017 688 `````` Lemma big_sepM_subseteq `{BiAffine PROP} Φ m1 m2 : `````` Robbert Krebbers committed Oct 30, 2017 689 690 `````` m2 ⊆ m1 → ([∗ map] k ↦ x ∈ m1, Φ k x) ⊢ [∗ map] k ↦ x ∈ m2, Φ k x. Proof. intros. by apply big_sepL_submseteq, map_to_list_submseteq. Qed. `````` Robbert Krebbers committed Feb 17, 2016 691 `````` `````` Robbert Krebbers committed Mar 24, 2017 692 693 `````` Global Instance big_sepM_mono' : Proper (pointwise_relation _ (pointwise_relation _ (⊢)) ==> (=) ==> (⊢)) `````` Robbert Krebbers committed Oct 30, 2017 694 695 `````` (big_opM (@bi_sep PROP) (K:=K) (A:=A)). Proof. intros f g Hf m ? <-. apply big_sepM_mono=> ???; apply Hf. Qed. `````` Robbert Krebbers committed Feb 17, 2016 696 `````` `````` Robbert Krebbers committed Oct 30, 2017 697 `````` Lemma big_sepM_empty Φ : ([∗ map] k↦x ∈ ∅, Φ k x) ⊣⊢ emp. `````` Robbert Krebbers committed Sep 28, 2016 698 `````` Proof. by rewrite big_opM_empty. Qed. `````` Jacques-Henri Jourdan committed Dec 04, 2017 699 `````` Lemma big_sepM_empty' `{BiAffine PROP} P Φ : P ⊢ [∗ map] k↦x ∈ ∅, Φ k x. `````` Robbert Krebbers committed Oct 30, 2017 700 `````` Proof. rewrite big_sepM_empty. apply: affine. Qed. `````` Robbert Krebbers committed May 30, 2016 701 `````` `````` Robbert Krebbers committed May 31, 2016 702 `````` Lemma big_sepM_insert Φ m i x : `````` Robbert Krebbers committed May 24, 2016 703 `````` m !! i = None → `````` Robbert Krebbers committed Nov 03, 2016 704 `````` ([∗ map] k↦y ∈ <[i:=x]> m, Φ k y) ⊣⊢ Φ i x ∗ [∗ map] k↦y ∈ m, Φ k y. `````` Robbert Krebbers committed Mar 24, 2017 705 `````` Proof. apply big_opM_insert. Qed. `````` Robbert Krebbers committed May 30, 2016 706 `````` `````` Robbert Krebbers committed May 31, 2016 707 `````` Lemma big_sepM_delete Φ m i x : `````` Robbert Krebbers committed May 24, 2016 708 `````` m !! i = Some x → `````` Robbert Krebbers committed Nov 03, 2016 709 `````` ([∗ map] k↦y ∈ m, Φ k y) ⊣⊢ Φ i x ∗ [∗ map] k↦y ∈ delete i m, Φ k y. `````` Robbert Krebbers committed Mar 24, 2017 710 `````` Proof. apply big_opM_delete. Qed. `````` Robbert Krebbers committed May 30, 2016 711 `````` `````` Robbert Krebbers committed Dec 12, 2018 712 713 714 715 716 717 718 719 720 721 722 723 724 `````` Lemma big_sepM_insert_2 Φ m i x : TCOr (∀ x, Affine (Φ i x)) (Absorbing (Φ i x)) → Φ i x -∗ ([∗ map] k↦y ∈ m, Φ k y) -∗ [∗ map] k↦y ∈ <[i:=x]> m, Φ k y. Proof. intros Ha. apply wand_intro_r. destruct (m !! i) as [y|] eqn:Hi; last first. { by rewrite -big_sepM_insert. } assert (TCOr (Affine (Φ i y)) (Absorbing (Φ i x))). { destruct Ha; try apply _. } rewrite big_sepM_delete // assoc. rewrite (sep_elim_l (Φ i x)) -big_sepM_insert ?lookup_delete //. by rewrite insert_delete. Qed. `````` Robbert Krebbers committed Nov 24, 2016 725 726 727 728 729 730 731 `````` Lemma big_sepM_lookup_acc Φ m i x : m !! i = Some x → ([∗ map] k↦y ∈ m, Φ k y) ⊢ Φ i x ∗ (Φ i x -∗ ([∗ map] k↦y ∈ m, Φ k y)). Proof. intros. rewrite big_sepM_delete //. by apply sep_mono_r, wand_intro_l. Qed. `````` Robbert Krebbers committed Oct 30, 2017 732 `````` Lemma big_sepM_lookup Φ m i x `{!Absorbing (Φ i x)} : `````` Robbert Krebbers committed Nov 03, 2016 733 `````` m !! i = Some x → ([∗ map] k↦y ∈ m, Φ k y) ⊢ Φ i x. `````` Robbert Krebbers committed Oct 30, 2017 734 `````` Proof. intros. rewrite big_sepM_lookup_acc //. by rewrite sep_elim_l. Qed. `````` Robbert Krebbers committed Nov 24, 2016 735 `````` `````` Robbert Krebbers committed Oct 30, 2017 736 `````` Lemma big_sepM_lookup_dom (Φ : K → PROP) m i `{!Absorbing (Φ i)} : `````` Robbert Krebbers committed Nov 20, 2016 737 738 `````` is_Some (m !! i) → ([∗ map] k↦_ ∈ m, Φ k) ⊢ Φ i. Proof. intros [x ?]. by eapply (big_sepM_lookup (λ i x, Φ i)). Qed. `````` Robbert Krebbers committed May 31, 2016 739 `````` `````` Robbert Krebbers committed Nov 03, 2016 740 `````` Lemma big_sepM_singleton Φ i x : ([∗ map] k↦y ∈ {[i:=x]}, Φ k y) ⊣⊢ Φ i x. `````` Robbert Krebbers committed Sep 28, 2016 741 `````` Proof. by rewrite big_opM_singleton. Qed. `````` Ralf Jung committed Feb 17, 2016 742 `````` `````` Robbert Krebbers committed Oct 30, 2017 743 `````` Lemma big_sepM_fmap {B} (f : A → B) (Φ : K → B → PROP) m : `````` Robbert Krebbers committed Nov 03, 2016 744 `````` ([∗ map] k↦y ∈ f <\$> m, Φ k y) ⊣⊢ ([∗ map] k↦y ∈ m, Φ k (f y)). `````` Robbert Krebbers committed Sep 28, 2016 745 `````` Proof. by rewrite big_opM_fmap. Qed. `````` Robbert Krebbers committed May 31, 2016 746 `````` `````` Robbert Krebbers committed Dec 02, 2016 747 748 749 `````` Lemma big_sepM_insert_override Φ m i x x' : m !! i = Some x → (Φ i x ⊣⊢ Φ i x') → ([∗ map] k↦y ∈ <[i:=x']> m, Φ k y) ⊣⊢ ([∗ map] k↦y ∈ m, Φ k y). `````` Robbert Krebbers committed Mar 24, 2017 750 `````` Proof. apply big_opM_insert_override. Qed. `````` Robbert Krebbers committed May 31, 2016 751 `````` `````` Robbert Krebbers committed Dec 02, 2016 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 `````` Lemma big_sepM_insert_override_1 Φ m i x x' : m !! i = Some x → ([∗ map] k↦y ∈ <[i:=x']> m, Φ k y) ⊢ (Φ i x' -∗ Φ i x) -∗ ([∗ map] k↦y ∈ m, Φ k y). Proof. intros ?. apply wand_intro_l. rewrite -insert_delete big_sepM_insert ?lookup_delete //. by rewrite assoc wand_elim_l -big_sepM_delete. Qed. Lemma big_sepM_insert_override_2 Φ m i x x' : m !! i = Some x → ([∗ map] k↦y ∈ m, Φ k y) ⊢ (Φ i x -∗ Φ i x') -∗ ([∗ map] k↦y ∈ <[i:=x']> m, Φ k y). Proof. intros ?. apply wand_intro_l. rewrite {1}big_sepM_delete //; rewrite assoc wand_elim_l. rewrite -insert_delete big_sepM_insert ?lookup_delete //. Qed. `````` Dan Frumin committed Feb 03, 2019 772 773 774 775 776 777 778 779 780 781 782 `````` Lemma big_sepM_insert_acc Φ m i x : m !! i = Some x → ([∗ map] k↦y ∈ m, Φ k y) ⊢ Φ i x ∗ (∀ x', Φ i x' -∗ ([∗ map] k↦y ∈ <[i:=x']> m, Φ k y)). Proof. intros ?. rewrite {1}big_sepM_delete //. apply sep_mono; [done|]. apply forall_intro=> x'. rewrite -insert_delete big_sepM_insert ?lookup_delete //. by apply wand_intro_l. Qed. `````` Robbert Krebbers committed Oct 30, 2017 783 `````` Lemma big_sepM_fn_insert {B} (Ψ : K → A → B → PROP) (f : K → B) m i x b : `````` Robbert Krebbers committed May 31, 2016 784 `````` m !! i = None → `````` Robbert Krebbers committed Nov 03, 2016 785 786 `````` ([∗ 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 Mar 24, 2017 787 `````` Proof. apply big_opM_fn_insert. Qed. `````` Robbert Krebbers committed Sep 28, 2016 788 `````` `````` Robbert Krebbers committed Oct 30, 2017 789 `````` Lemma big_sepM_fn_insert' (Φ : K → PROP) m i x P : `````` Robbert Krebbers committed May 31, 2016 790 `````` m !! i = None → `````` Robbert Krebbers committed Nov 03, 2016 791 `````` ([∗ map] k↦y ∈ <[i:=x]> m, <[i:=P]> Φ k) ⊣⊢ (P ∗ [∗ map] k↦y ∈ m, Φ k). `````` Robbert Krebbers committed Mar 24, 2017 792 `````` Proof. apply big_opM_fn_insert'. Qed. `````` Robbert Krebbers committed May 31, 2016 793 `````` `````` Dan Frumin committed Nov 01, 2018 794 795 796 797 798 799 `````` Lemma big_sepM_union Φ m1 m2 : m1 ##ₘ m2 → ([∗ map] k↦y ∈ m1 ∪ m2, Φ k y) ⊣⊢ ([∗ map] k↦y ∈ m1, Φ k y) ∗ ([∗ map] k↦y ∈ m2, Φ k y). Proof. apply big_opM_union. Qed. `````` Robbert Krebbers committed May 01, 2019 800 `````` Lemma big_sepM_sep Φ Ψ m : `````` Robbert Krebbers committed Nov 27, 2016 801 `````` ([∗ map] k↦x ∈ m, Φ k x ∗ Ψ k x) `````` Robbert Krebbers committed Nov 03, 2016 802 `````` ⊣⊢ ([∗ map] k↦x ∈ m, Φ k x) ∗ ([∗ map] k↦x ∈ m, Ψ k x). `````` Robbert Krebbers committed May 01, 2019 803 `````` Proof. apply big_opM_op. Qed. `````` Robbert Krebbers committed May 31, 2016 804 `````` `````` Robbert Krebbers committed Nov 27, 2016 805 806 807 `````` Lemma big_sepM_and Φ Ψ m : ([∗ map] k↦x ∈ m, Φ k x ∧ Ψ k x) ⊢ ([∗ map] k↦x ∈ m, Φ k x) ∧ ([∗ map] k↦x ∈ m, Ψ k x). `````` Robbert Krebbers committed Oct 30, 2017 808 `````` Proof. auto using and_intro, big_sepM_mono, and_elim_l, and_elim_r. Qed. `````` Robbert Krebbers committed Sep 28, 2016 809 `````` `````` Jacques-Henri Jourdan committed Dec 04, 2017 810 `````` Lemma big_sepM_persistently `{BiAffine PROP} Φ m : `````` Robbert Krebbers committed Mar 04, 2018 811 `````` ( ([∗ map] k↦x ∈ m, Φ k x)) ⊣⊢ ([∗ map] k↦x ∈ m, (Φ k x)). `````` Robbert Krebbers committed Sep 28, 2016 812 `````` Proof. apply (big_opM_commute _). Qed. `````` Robbert Krebbers committed May 31, 2016 813 `````` `````` Jacques-Henri Jourdan committed Dec 04, 2017 814 `````` Lemma big_sepM_forall `{BiAffine PROP} Φ m : `````` Robbert Krebbers committed Oct 25, 2017 815 `````` (∀ k x, Persistent (Φ k x)) → `````` Ralf Jung committed Nov 22, 2016 816 `````` ([∗ map] k↦x ∈ m, Φ k x) ⊣⊢ (∀ k x, ⌜m !! k = Some x⌝ → Φ k x). `````` Robbert Krebbers committed May 31, 2016 817 818 819 `````` Proof. intros. apply (anti_symm _). { apply forall_intro=> k; apply forall_intro=> x. `````` Robbert Krebbers committed Oct 30, 2017 820 821 `````` apply impl_intro_l, pure_elim_l=> ?; by apply: big_sepM_lookup. } induction m as [|i x m ? IH] using map_ind; auto using big_sepM_empty'. `````` Robbert Krebbers committed Oct 30, 2017 822 `````` rewrite big_sepM_insert // -persistent_and_sep. apply and_intro. `````` Robbert Krebbers committed Sep 28, 2016 823 `````` - rewrite (forall_elim i) (forall_elim x) lookup_insert. `````` Robbert Krebbers committed Nov 21, 2016 824 `````` by rewrite pure_True // True_impl. `````` Robbert Krebbers committed May 31, 2016 825 `````` - rewrite -IH. apply forall_mono=> k; apply forall_mono=> y. `````` Robbert Krebbers committed Sep 28, 2016 826 827 `````` apply impl_intro_l, pure_elim_l=> ?. rewrite lookup_insert_ne; last by intros ?; simplify_map_eq. `````` Robbert Krebbers committed Nov 21, 2016 828 `````` by rewrite pure_True // True_impl. `````` Robbert Krebbers committed May 31, 2016 829 830 831 `````` Qed. Lemma big_sepM_impl Φ Ψ m : `````` Robbert Krebbers committed Oct 30, 2017 832 `````` ([∗ map] k↦x ∈ m, Φ k x) -∗ `````` Jacques-Henri Jourdan committed Nov 02, 2017 833 `````` □ (∀ k x, ⌜m !! k = Some x⌝ → Φ k x -∗ Ψ k x) -∗ `````` Robbert Krebbers committed Oct 30, 2017 834 `` [∗ map] k↦x ∈ m, Ψ k x``