excl.v 6.1 KB
 Robbert Krebbers committed Mar 10, 2016 1 ``````From iris.algebra Require Export cmra. `````` Robbert Krebbers committed Oct 25, 2016 2 ``````From iris.base_logic Require Import base_logic. `````` Ralf Jung committed Jan 05, 2017 3 ``````Set Default Proof Using "Type". `````` Robbert Krebbers committed Nov 22, 2015 4 5 ``````Local Arguments validN _ _ _ !_ /. Local Arguments valid _ _ !_ /. `````` Robbert Krebbers committed Nov 11, 2015 6 7 8 9 10 11 `````` Inductive excl (A : Type) := | Excl : A → excl A | ExclBot : excl A. Arguments Excl {_} _. Arguments ExclBot {_}. `````` Robbert Krebbers committed May 28, 2016 12 `````` `````` Robbert Krebbers committed Jan 30, 2017 13 14 15 ``````Instance: Params (@Excl) 1. Instance: Params (@ExclBot) 1. `````` Robbert Krebbers committed Sep 01, 2016 16 ``````Notation excl' A := (option (excl A)). `````` Robbert Krebbers committed May 28, 2016 17 18 19 ``````Notation Excl' x := (Some (Excl x)). Notation ExclBot' := (Some ExclBot). `````` Robbert Krebbers committed Nov 22, 2015 20 21 ``````Instance maybe_Excl {A} : Maybe (@Excl A) := λ x, match x with Excl a => Some a | _ => None end. `````` Robbert Krebbers committed Nov 11, 2015 22 `````` `````` Robbert Krebbers committed Jan 14, 2016 23 ``````Section excl. `````` Ralf Jung committed Nov 22, 2016 24 ``````Context {A : ofeT}. `````` Robbert Krebbers committed Feb 26, 2016 25 26 ``````Implicit Types a b : A. Implicit Types x y : excl A. `````` Robbert Krebbers committed Jan 14, 2016 27 `````` `````` Robbert Krebbers committed Nov 22, 2015 28 ``````(* Cofe *) `````` Robbert Krebbers committed Jan 14, 2016 29 ``````Inductive excl_equiv : Equiv (excl A) := `````` Robbert Krebbers committed Feb 26, 2016 30 `````` | Excl_equiv a b : a ≡ b → Excl a ≡ Excl b `````` Robbert Krebbers committed Nov 11, 2015 31 32 `````` | ExclBot_equiv : ExclBot ≡ ExclBot. Existing Instance excl_equiv. `````` Robbert Krebbers committed Feb 26, 2016 33 ``````Inductive excl_dist : Dist (excl A) := `````` Robbert Krebbers committed Feb 26, 2016 34 `````` | Excl_dist a b n : a ≡{n}≡ b → Excl a ≡{n}≡ Excl b `````` Ralf Jung committed Feb 10, 2016 35 `````` | ExclBot_dist n : ExclBot ≡{n}≡ ExclBot. `````` Robbert Krebbers committed Nov 22, 2015 36 ``````Existing Instance excl_dist. `````` Robbert Krebbers committed Feb 26, 2016 37 `````` `````` Ralf Jung committed Jan 27, 2017 38 ``````Global Instance Excl_ne : NonExpansive (@Excl A). `````` Robbert Krebbers committed Feb 02, 2016 39 40 41 ``````Proof. by constructor. Qed. Global Instance Excl_proper : Proper ((≡) ==> (≡)) (@Excl A). Proof. by constructor. Qed. `````` Robbert Krebbers committed Feb 11, 2016 42 ``````Global Instance Excl_inj : Inj (≡) (≡) (@Excl A). `````` Robbert Krebbers committed Feb 02, 2016 43 ``````Proof. by inversion_clear 1. Qed. `````` Robbert Krebbers committed Feb 11, 2016 44 ``````Global Instance Excl_dist_inj n : Inj (dist n) (dist n) (@Excl A). `````` Robbert Krebbers committed Feb 02, 2016 45 ``````Proof. by inversion_clear 1. Qed. `````` Robbert Krebbers committed Feb 26, 2016 46 `````` `````` Ralf Jung committed Nov 22, 2016 47 ``````Definition excl_ofe_mixin : OfeMixin (excl A). `````` Robbert Krebbers committed Nov 22, 2015 48 ``````Proof. `````` Robbert Krebbers committed Feb 10, 2017 49 50 51 `````` apply (iso_ofe_mixin (maybe Excl)). - by intros [a|] [b|]; split; inversion_clear 1; constructor. - by intros n [a|] [b|]; split; inversion_clear 1; constructor. `````` Robbert Krebbers committed Nov 22, 2015 52 ``````Qed. `````` Ralf Jung committed Nov 22, 2016 53 54 ``````Canonical Structure exclC : ofeT := OfeT (excl A) excl_ofe_mixin. `````` Robbert Krebbers committed Feb 10, 2017 55 56 ``````Global Instance excl_cofe `{Cofe A} : Cofe exclC. Proof. `````` Robbert Krebbers committed Feb 10, 2017 57 58 59 `````` apply (iso_cofe (from_option Excl ExclBot) (maybe Excl)). - by intros n [a|] [b|]; split; inversion_clear 1; constructor. - by intros []; constructor. `````` Ralf Jung committed Nov 22, 2016 60 61 ``````Qed. `````` Robbert Krebbers committed Feb 24, 2016 62 63 64 65 ``````Global Instance excl_discrete : Discrete A → Discrete exclC. Proof. by inversion_clear 2; constructor; apply (timeless _). Qed. Global Instance excl_leibniz : LeibnizEquiv A → LeibnizEquiv (excl A). Proof. by destruct 2; f_equal; apply leibniz_equiv. Qed. `````` Robbert Krebbers committed Jan 14, 2016 66 `````` `````` Robbert Krebbers committed Feb 26, 2016 67 ``````Global Instance Excl_timeless a : Timeless a → Timeless (Excl a). `````` Robbert Krebbers committed Dec 11, 2015 68 ``````Proof. by inversion_clear 2; constructor; apply (timeless _). Qed. `````` Robbert Krebbers committed Jan 14, 2016 69 ``````Global Instance ExclBot_timeless : Timeless (@ExclBot A). `````` Robbert Krebbers committed Dec 11, 2015 70 ``````Proof. by inversion_clear 1; constructor. Qed. `````` Robbert Krebbers committed Nov 22, 2015 71 72 `````` (* CMRA *) `````` Robbert Krebbers committed Feb 24, 2016 73 ``````Instance excl_valid : Valid (excl A) := λ x, `````` Robbert Krebbers committed May 28, 2016 74 `````` match x with Excl _ => True | ExclBot => False end. `````` Robbert Krebbers committed Jan 14, 2016 75 ``````Instance excl_validN : ValidN (excl A) := λ n x, `````` Robbert Krebbers committed May 28, 2016 76 77 78 `````` match x with Excl _ => True | ExclBot => False end. Instance excl_pcore : PCore (excl A) := λ _, None. Instance excl_op : Op (excl A) := λ x y, ExclBot. `````` Robbert Krebbers committed Mar 11, 2016 79 `````` `````` Robbert Krebbers committed May 27, 2016 80 ``````Lemma excl_cmra_mixin : CMRAMixin (excl A). `````` Robbert Krebbers committed Nov 11, 2015 81 ``````Proof. `````` Robbert Krebbers committed May 28, 2016 82 `````` split; try discriminate. `````` Robbert Krebbers committed Feb 17, 2016 83 84 `````` - by intros n []; destruct 1; constructor. - by destruct 1; intros ?. `````` Robbert Krebbers committed Feb 24, 2016 85 `````` - intros x; split. done. by move=> /(_ 0). `````` Robbert Krebbers committed May 28, 2016 86 87 88 89 `````` - intros n [?|]; simpl; auto with lia. - by intros [?|] [?|] [?|]; constructor. - by intros [?|] [?|]; constructor. - by intros n [?|] [?|]. `````` Robbert Krebbers committed Aug 14, 2016 90 `````` - intros n x [?|] [?|] ?; inversion_clear 1; eauto. `````` Robbert Krebbers committed Nov 11, 2015 91 ``````Qed. `````` Robbert Krebbers committed Feb 09, 2017 92 ``````Canonical Structure exclR := CMRAT (excl A) excl_cmra_mixin. `````` Robbert Krebbers committed May 27, 2016 93 `````` `````` Robbert Krebbers committed Mar 01, 2016 94 ``````Global Instance excl_cmra_discrete : Discrete A → CMRADiscrete exclR. `````` Robbert Krebbers committed Feb 24, 2016 95 96 ``````Proof. split. apply _. by intros []. Qed. `````` Robbert Krebbers committed Feb 13, 2016 97 98 ``````(** Internalized properties *) Lemma excl_equivI {M} (x y : excl A) : `````` Robbert Krebbers committed May 31, 2016 99 100 101 102 103 `````` x ≡ y ⊣⊢ (match x, y with | Excl a, Excl b => a ≡ b | ExclBot, ExclBot => True | _, _ => False end : uPred M). `````` Robbert Krebbers committed Feb 25, 2016 104 105 106 ``````Proof. uPred.unseal. do 2 split. by destruct 1. by destruct x, y; try constructor. Qed. `````` Robbert Krebbers committed Feb 13, 2016 107 ``````Lemma excl_validI {M} (x : excl A) : `````` Robbert Krebbers committed May 28, 2016 108 `````` ✓ x ⊣⊢ (if x is ExclBot then False else True : uPred M). `````` Robbert Krebbers committed Feb 25, 2016 109 ``````Proof. uPred.unseal. by destruct x. Qed. `````` Robbert Krebbers committed Feb 13, 2016 110 `````` `````` Jacques-Henri Jourdan committed May 31, 2016 111 112 113 ``````(** Exclusive *) Global Instance excl_exclusive x : Exclusive x. Proof. by destruct x; intros n []. Qed. `````` Robbert Krebbers committed May 28, 2016 114 115 116 117 118 119 `````` (** Option excl *) Lemma excl_validN_inv_l n mx a : ✓{n} (Excl' a ⋅ mx) → mx = None. Proof. by destruct mx. Qed. Lemma excl_validN_inv_r n mx a : ✓{n} (mx ⋅ Excl' a) → mx = None. Proof. by destruct mx. Qed. `````` Robbert Krebbers committed Sep 21, 2016 120 121 122 123 124 `````` Lemma Excl_includedN n a b : Excl' a ≼{n} Excl' b → a ≡{n}≡ b. Proof. by intros [[c|] Hb%(inj Some)]; inversion_clear Hb. Qed. Lemma Excl_included a b : Excl' a ≼ Excl' b → a ≡ b. Proof. by intros [[c|] Hb%(inj Some)]; inversion_clear Hb. Qed. `````` Robbert Krebbers committed Jan 14, 2016 125 126 127 ``````End excl. Arguments exclC : clear implicits. `````` Robbert Krebbers committed Mar 01, 2016 128 ``````Arguments exclR : clear implicits. `````` Robbert Krebbers committed Nov 11, 2015 129 `````` `````` Robbert Krebbers committed Nov 22, 2015 130 ``````(* Functor *) `````` Robbert Krebbers committed Feb 04, 2016 131 ``````Definition excl_map {A B} (f : A → B) (x : excl A) : excl B := `````` Robbert Krebbers committed May 28, 2016 132 `````` match x with Excl a => Excl (f a) | ExclBot => ExclBot end. `````` Robbert Krebbers committed Feb 04, 2016 133 ``````Lemma excl_map_id {A} (x : excl A) : excl_map id x = x. `````` Robbert Krebbers committed Jan 19, 2016 134 ``````Proof. by destruct x. Qed. `````` Robbert Krebbers committed Feb 04, 2016 135 136 ``````Lemma excl_map_compose {A B C} (f : A → B) (g : B → C) (x : excl A) : excl_map (g ∘ f) x = excl_map g (excl_map f x). `````` Robbert Krebbers committed Jan 19, 2016 137 ``````Proof. by destruct x. Qed. `````` Ralf Jung committed Nov 22, 2016 138 ``````Lemma excl_map_ext {A B : ofeT} (f g : A → B) x : `````` Robbert Krebbers committed Feb 04, 2016 139 140 `````` (∀ x, f x ≡ g x) → excl_map f x ≡ excl_map g x. Proof. by destruct x; constructor. Qed. `````` Ralf Jung committed Nov 22, 2016 141 ``````Instance excl_map_ne {A B : ofeT} n : `````` Robbert Krebbers committed Feb 04, 2016 142 `````` Proper ((dist n ==> dist n) ==> dist n ==> dist n) (@excl_map A B). `````` Robbert Krebbers committed Nov 22, 2015 143 ``````Proof. by intros f f' Hf; destruct 1; constructor; apply Hf. Qed. `````` 144 145 146 ``````Instance excl_map_cmra_morphism {A B : ofeT} (f : A → B) : NonExpansive f → CMRAMorphism (excl_map f). Proof. split; try done; try apply _. by intros n [a|]. Qed. `````` Robbert Krebbers committed Feb 04, 2016 147 ``````Definition exclC_map {A B} (f : A -n> B) : exclC A -n> exclC B := `````` Robbert Krebbers committed Feb 04, 2016 148 `````` CofeMor (excl_map f). `````` Ralf Jung committed Jan 27, 2017 149 150 ``````Instance exclC_map_ne A B : NonExpansive (@exclC_map A B). Proof. by intros n f f' Hf []; constructor; apply Hf. Qed. `````` Ralf Jung committed Feb 05, 2016 151 `````` `````` Robbert Krebbers committed May 28, 2016 152 153 154 ``````Program Definition exclRF (F : cFunctor) : rFunctor := {| rFunctor_car A B := (exclR (cFunctor_car F A B)); rFunctor_map A1 A2 B1 B2 fg := exclC_map (cFunctor_map F fg) `````` Robbert Krebbers committed Mar 02, 2016 155 ``````|}. `````` Robbert Krebbers committed Mar 07, 2016 156 157 158 ``````Next Obligation. intros F A1 A2 B1 B2 n x1 x2 ??. by apply exclC_map_ne, cFunctor_ne. Qed. `````` Robbert Krebbers committed Mar 06, 2016 159 160 161 162 163 164 165 166 ``````Next Obligation. intros F A B x; simpl. rewrite -{2}(excl_map_id x). apply excl_map_ext=>y. by rewrite cFunctor_id. Qed. Next Obligation. intros F A1 A2 A3 B1 B2 B3 f g f' g' x; simpl. rewrite -excl_map_compose. apply excl_map_ext=>y; apply cFunctor_compose. Qed. `````` Ralf Jung committed Mar 07, 2016 167 `````` `````` Robbert Krebbers committed May 28, 2016 168 169 ``````Instance exclRF_contractive F : cFunctorContractive F → rFunctorContractive (exclRF F). `````` Ralf Jung committed Mar 07, 2016 170 ``````Proof. `````` Robbert Krebbers committed Mar 07, 2016 171 `````` intros A1 A2 B1 B2 n x1 x2 ??. by apply exclC_map_ne, cFunctor_contractive. `````` Ralf Jung committed Mar 07, 2016 172 ``Qed.``