diff options
author | Rutger Broekhoff | 2024-06-27 01:56:05 +0200 |
---|---|---|
committer | Rutger Broekhoff | 2024-06-27 01:56:05 +0200 |
commit | 4598e77a9406d8040357c943a05dd1ab939932db (patch) | |
tree | e990beaa94803da3585547f22e186e8819f6a887 /maptools.v | |
parent | 73df1945b31c0beee88cf4476df4ccd09d31403b (diff) | |
download | mininix-formalization-4598e77a9406d8040357c943a05dd1ab939932db.tar.gz mininix-formalization-4598e77a9406d8040357c943a05dd1ab939932db.zip |
Tidy up project
* Write README.md
* Add LICENSE
* Clean up some theorems and proofs
Diffstat (limited to 'maptools.v')
-rw-r--r-- | maptools.v | 63 |
1 files changed, 44 insertions, 19 deletions
@@ -4,8 +4,8 @@ From stdpp Require Import countable fin_maps fin_map_dom. | |||
4 | (** Generic lemmas for finite maps and their domains *) | 4 | (** Generic lemmas for finite maps and their domains *) |
5 | 5 | ||
6 | Lemma map_insert_empty_lookup {A} `{FinMap K M} | 6 | Lemma map_insert_empty_lookup {A} `{FinMap K M} |
7 | (i j : K) (u v : A) : | 7 | (i j : K) (x y : A) : |
8 | <[i := u]> (∅ : M A) !! j = Some v → i = j ∧ v = u. | 8 | <[i := x]> (∅ : M A) !! j = Some y → i = j ∧ y = x. |
9 | Proof. | 9 | Proof. |
10 | intros Hiel. | 10 | intros Hiel. |
11 | destruct (decide (i = j)). | 11 | destruct (decide (i = j)). |
@@ -106,6 +106,32 @@ Lemma map_dom_insert_eq_L `{FinMapDom K M D} `{!LeibnizEquiv D} {A} | |||
106 | dom (delete i m1) = dom (delete i m2) ∧ i ∈ dom m2. | 106 | dom (delete i m1) = dom (delete i m2) ∧ i ∈ dom m2. |
107 | Proof. set_solver. Qed. | 107 | Proof. set_solver. Qed. |
108 | 108 | ||
109 | (* Copied from stdpp and changed so that the value types | ||
110 | of m1 and m2 are decoupled *) | ||
111 | Lemma map_dom_subseteq_size `{FinMapDom K M D} {A B} (m1 : M A) (m2 : M B) : | ||
112 | dom m2 ⊆ dom m1 → size m2 ≤ size m1. | ||
113 | Proof. | ||
114 | revert m1. induction m2 as [|i x m2 ? IH] using map_ind; intros m1 Hdom. | ||
115 | { rewrite map_size_empty. lia. } | ||
116 | rewrite dom_insert in Hdom. | ||
117 | assert (i ∉ dom m2) by (by apply not_elem_of_dom). | ||
118 | assert (i ∈ dom m1) as [x' Hx'] % elem_of_dom by set_solver. | ||
119 | rewrite <-(insert_delete m1 i x') by done. | ||
120 | rewrite !map_size_insert_None, <-Nat.succ_le_mono | ||
121 | by (by rewrite ?lookup_delete). | ||
122 | apply IH. rewrite dom_delete. set_solver. | ||
123 | Qed. | ||
124 | |||
125 | Lemma map_dom_empty_subset `{Countable K} `{FinMapDom K M D} {A B} (m : M A) : | ||
126 | dom m ⊆ dom (∅ : M B) → m = ∅. | ||
127 | Proof. | ||
128 | intros Hdom. | ||
129 | apply map_dom_subseteq_size in Hdom. | ||
130 | rewrite map_size_empty in Hdom. | ||
131 | inv Hdom. | ||
132 | by apply map_size_empty_inv. | ||
133 | Qed. | ||
134 | |||
109 | (** map_mapM *) | 135 | (** map_mapM *) |
110 | 136 | ||
111 | Definition map_mapM {M : Type → Type} `{MBind F} `{MRet F} `{FinMap K M} {A B} | 137 | Definition map_mapM {M : Type → Type} `{MBind F} `{MRet F} `{FinMap K M} {A B} |
@@ -137,11 +163,10 @@ Proof. | |||
137 | Qed. | 163 | Qed. |
138 | 164 | ||
139 | Lemma map_mapM_option_insert_L `{FinMapDom K M D} `{!LeibnizEquiv D} {A B} | 165 | Lemma map_mapM_option_insert_L `{FinMapDom K M D} `{!LeibnizEquiv D} {A B} |
140 | (f : A → option B) (m1 : M A) (m2 m2' : M B) | 166 | (f : A → option B) (m1 : M A) (m2 m2' : M B) (i : K) (x : A) : |
141 | (i : K) (x : A) (x' : B) : | 167 | m1 !! i = None → |
142 | m1 !! i = None → | 168 | map_mapM f (<[i := x]>m1) = Some m2 → |
143 | map_mapM f (<[i := x]>m1) = Some m2 → | 169 | ∃ x', f x = Some x' ∧ map_mapM f m1 = Some (delete i m2). |
144 | ∃ x', f x = Some x' ∧ map_mapM f m1 = Some (delete i m2). | ||
145 | Proof. | 170 | Proof. |
146 | intros Helem HmapM. | 171 | intros Helem HmapM. |
147 | unfold map_mapM in HmapM. | 172 | unfold map_mapM in HmapM. |
@@ -315,7 +340,7 @@ Qed. | |||
315 | 340 | ||
316 | Lemma map_Forall2_impl_L `{FinMapDom K M D} `{!LeibnizEquiv D} {A B} | 341 | Lemma map_Forall2_impl_L `{FinMapDom K M D} `{!LeibnizEquiv D} {A B} |
317 | (R1 R2 : A → B → Prop) : | 342 | (R1 R2 : A → B → Prop) : |
318 | (∀ a b, R1 a b → R2 a b) → | 343 | (∀ x y, R1 x y → R2 x y) → |
319 | ∀ (m1 : M A) (m2 : M B), | 344 | ∀ (m1 : M A) (m2 : M B), |
320 | map_Forall2 R1 m1 m2 → map_Forall2 R2 m1 m2. | 345 | map_Forall2 R1 m1 m2 → map_Forall2 R2 m1 m2. |
321 | Proof. | 346 | Proof. |
@@ -327,8 +352,8 @@ Proof. | |||
327 | Qed. | 352 | Qed. |
328 | 353 | ||
329 | Lemma map_Forall2_fmap_r_L `{FinMapDom K M D} `{!LeibnizEquiv D} {A B C} | 354 | Lemma map_Forall2_fmap_r_L `{FinMapDom K M D} `{!LeibnizEquiv D} {A B C} |
330 | (P : A → C → Prop) (m1 : M A) (m2 : M B) (f : B → C) : | 355 | (R : A → C → Prop) (m1 : M A) (m2 : M B) (f : B → C) : |
331 | map_Forall2 P m1 (f <$> m2) → map_Forall2 (λ l r, P l (f r)) m1 m2. | 356 | map_Forall2 R m1 (f <$> m2) → map_Forall2 (λ x y, R x (f y)) m1 m2. |
332 | Proof. | 357 | Proof. |
333 | intros HForall2. | 358 | intros HForall2. |
334 | unfold map_Forall2, map_relation, option_relation in *. | 359 | unfold map_Forall2, map_relation, option_relation in *. |
@@ -355,10 +380,10 @@ Proof. | |||
355 | Qed. | 380 | Qed. |
356 | 381 | ||
357 | Lemma map_insert_L `{FinMapDom K M D} `{!LeibnizEquiv D} {A} | 382 | Lemma map_insert_L `{FinMapDom K M D} `{!LeibnizEquiv D} {A} |
358 | (i : K) (x1 x2 : A) (m1 m2 : M A) : | 383 | (i : K) (x y : A) (m1 m2 : M A) : |
359 | x1 = x2 → | 384 | x = y → |
360 | delete i m1 = delete i m2 → | 385 | delete i m1 = delete i m2 → |
361 | <[i := x1]>m1 = <[i := x2]>m2. | 386 | <[i := x]>m1 = <[i := y]>m2. |
362 | Proof. | 387 | Proof. |
363 | intros Heq Hdel. | 388 | intros Heq Hdel. |
364 | apply map_Forall2_eq_L. | 389 | apply map_Forall2_eq_L. |
@@ -367,8 +392,8 @@ Proof. | |||
367 | Qed. | 392 | Qed. |
368 | 393 | ||
369 | Lemma map_insert_rev_L `{FinMapDom K M D} `{!LeibnizEquiv D} {A} | 394 | Lemma map_insert_rev_L `{FinMapDom K M D} `{!LeibnizEquiv D} {A} |
370 | (i : K) (x1 x2 : A) (m1 m2 : M A) : | 395 | (m1 m2 : M A) (i : K) (x y : A) : |
371 | <[i := x1]>m1 = <[i := x2]>m2 → x1 = x2 ∧ delete i m1 = delete i m2. | 396 | <[i := x]>m1 = <[i := y]>m2 → x = y ∧ delete i m1 = delete i m2. |
372 | Proof. | 397 | Proof. |
373 | intros Heq. apply map_Forall2_eq_L in Heq. | 398 | intros Heq. apply map_Forall2_eq_L in Heq. |
374 | apply map_Forall2_insert_inv in Heq as [Heq1 Heq2]. | 399 | apply map_Forall2_insert_inv in Heq as [Heq1 Heq2]. |
@@ -376,13 +401,13 @@ Proof. | |||
376 | Qed. | 401 | Qed. |
377 | 402 | ||
378 | Lemma map_insert_rev_1_L `{FinMapDom K M D} `{!LeibnizEquiv D} {A} | 403 | Lemma map_insert_rev_1_L `{FinMapDom K M D} `{!LeibnizEquiv D} {A} |
379 | (i : K) (x1 x2 : A) (m1 m2 : M A) : | 404 | (m1 m2 : M A) (i : K) (x y : A) : |
380 | <[i := x1]>m1 = <[i := x2]>m2 → x1 = x2. | 405 | <[i := x]>m1 = <[i := y]>m2 → x = y. |
381 | Proof. apply map_insert_rev_L. Qed. | 406 | Proof. apply map_insert_rev_L. Qed. |
382 | 407 | ||
383 | Lemma map_insert_rev_2_L `{FinMapDom K M D} `{!LeibnizEquiv D} {A} | 408 | Lemma map_insert_rev_2_L `{FinMapDom K M D} `{!LeibnizEquiv D} {A} |
384 | (i : K) (x1 x2 : A) (m1 m2 : M A) : | 409 | (m1 m2 : M A) (i : K) (x y : A) : |
385 | <[i := x1]>m1 = <[i := x2]>m2 → delete i m1 = delete i m2. | 410 | <[i := x]>m1 = <[i := y]>m2 → delete i m1 = delete i m2. |
386 | Proof. apply map_insert_rev_L. Qed. | 411 | Proof. apply map_insert_rev_L. Qed. |
387 | 412 | ||
388 | Lemma map_Forall2_alt_L `{FinMapDom K M D} `{!LeibnizEquiv D} {A B} | 413 | Lemma map_Forall2_alt_L `{FinMapDom K M D} `{!LeibnizEquiv D} {A B} |