|
1 | 1 | From Coq Require Import |
2 | 2 | List |
3 | | - Classes.EquivDec. |
| 3 | + Classes.EquivDec |
| 4 | + Classes.SetoidClass. |
4 | 5 |
|
5 | 6 | Section defns. |
6 | 7 | Context {K V : Type}. |
@@ -53,16 +54,75 @@ Section Operations. |
53 | 54 | Defined. |
54 | 55 | End Operations. |
55 | 56 |
|
56 | | -Section Equivalence. |
| 57 | +Section EquivalenceOfDistinctStorages. |
57 | 58 | Context {K V} {T1 T2} `{@Storage K V T1, Storage K V T2}. |
58 | 59 |
|
59 | 60 | Inductive s_eq (s1 : T1) (s2 : T2) := |
60 | 61 | | s_eq_ : (forall k, get k s1 = get k s2) -> s_eq s1 s2. |
61 | | -End Equivalence. |
| 62 | +End EquivalenceOfDistinctStorages. |
62 | 63 |
|
63 | 64 | Notation "s1 =s= s2" := (s_eq s1 s2) (at level 50). |
64 | 65 | #[export] Hint Constructors s_eq : storage. |
65 | 66 |
|
| 67 | +Section Setoid. |
| 68 | + Context `{Hstorage : Storage}. |
| 69 | + |
| 70 | + Global Instance s_eq_refl : Reflexive s_eq. |
| 71 | + Proof. |
| 72 | + intros x. constructor. intros k. |
| 73 | + reflexivity. |
| 74 | + Qed. |
| 75 | + |
| 76 | + Global Instance s_eq_symmetry : Symmetric s_eq. |
| 77 | + Proof. |
| 78 | + intros x y H. constructor. intros k. |
| 79 | + destruct H as [H]. |
| 80 | + now rewrite H. |
| 81 | + Qed. |
| 82 | + |
| 83 | + Global Instance s_eq_transitive : Transitive s_eq. |
| 84 | + Proof. |
| 85 | + intros x y z Hxy Hyz. constructor. intros k. |
| 86 | + destruct Hxy as [Hxy]. destruct Hyz as [Hyz]. |
| 87 | + now rewrite Hxy, Hyz. |
| 88 | + Qed. |
| 89 | + |
| 90 | + Global Instance s_eq_equiv : Equivalence s_eq := |
| 91 | + {| |
| 92 | + Equivalence_Reflexive := s_eq_refl; |
| 93 | + Equivalence_Symmetric := s_eq_symmetry; |
| 94 | + Equivalence_Transitive := s_eq_transitive; |
| 95 | + |}. |
| 96 | + |
| 97 | + Global Instance s_eq_setiod : Setoid t := |
| 98 | + {| |
| 99 | + equiv := s_eq; |
| 100 | + setoid_equiv := s_eq_equiv; |
| 101 | + |}. |
| 102 | +End Setoid. |
| 103 | + |
| 104 | +Add Parametric Morphism {K V} t `{H : @Storage K V t} `{Hkdec : EqDec K eq} : (@put K V t H) with |
| 105 | + signature (@eq K) ==> (@eq V) ==> (@s_eq K V t t H H) ==> (@s_eq K V t t H H) as put_mor. |
| 106 | +Proof. |
| 107 | + intros k v s1 s2 Hs. |
| 108 | + destruct Hs as [Hs]. |
| 109 | + constructor. intros k_. |
| 110 | + destruct (equiv_dec k k_) as [Heq | Hneq]. |
| 111 | + - rewrite Heq. now repeat rewrite keep. |
| 112 | + - repeat rewrite <- distinct; auto. |
| 113 | +Qed. |
| 114 | + |
| 115 | +Add Parametric Morphism {K V} t `{H : @Storage K V t} `{Hkdec : EqDec K eq} : (@delete K V t H) with |
| 116 | + signature (@eq K) ==> (@s_eq K V t t H H) ==> (@s_eq K V t t H H) as delete_mor. |
| 117 | +Proof. |
| 118 | + intros k s1 s2 Hs. |
| 119 | + destruct Hs as [Hs]. |
| 120 | + constructor. intros k_. |
| 121 | + destruct (equiv_dec k k_) as [Heq | Hneq]. |
| 122 | + - rewrite Heq. now repeat rewrite delete_keep. |
| 123 | + - repeat rewrite <- delete_distinct; auto. |
| 124 | +Qed. |
| 125 | + |
66 | 126 | Section WriteLog. |
67 | 127 | Context {K V : Type} `{HKeq_dec : EqDec K eq} {T} `{HT_Storage : @Storage K V T}. |
68 | 128 |
|
|
0 commit comments