| 1 |
From Coq Require Import Bool. |
| 2 |
From Coq Require Import List. |
| 3 |
From Coq Require Import Orders. |
| 4 |
From Coq Require Import OrdersEx. |
| 5 |
From Coq Require Import FMapInterface. |
| 6 |
Require Import Crypto.Util.ListUtil. |
| 7 |
Require Import Crypto.Util.ListUtil.SetoidList. |
| 8 |
Require Import Crypto.Util.Compose. |
| 9 |
Require Import Crypto.Util.Logic.Forall. |
| 10 |
Require Import Crypto.Util.Logic.Exists. |
| 11 |
Require Import Crypto.Util.Structures.Equalities.Empty. |
| 12 |
Require Import Crypto.Util.Structures.Equalities.Unit. |
| 13 |
Require Import Crypto.Util.Structures.Orders. |
| 14 |
Require Import Crypto.Util.Structures.Orders.Empty. |
| 15 |
Require Import Crypto.Util.Structures.Orders.Unit. |
| 16 |
Require Import Crypto.Util.Sorting.Sorted.Proper. |
| 17 |
Require Import Crypto.Util.Tactics.SplitInContext. |
| 18 |
Require Import Crypto.Util.Tactics.DestructHead. |
| 19 |
Require Import Crypto.Util.Tactics.SpecializeAllWays. |
| 20 |
Require Import Crypto.Util.Tactics.SpecializeBy. |
| 21 |
Require Import Crypto.Util.Tactics.SpecializeUnderBindersBy. |
| 22 |
Require Import Crypto.Util.Tactics.Head. |
| 23 |
Require Import Crypto.Util.Tactics.BreakMatch. |
| 24 |
Require Import Crypto.Util.Tactics.SetoidSubst. |
| 25 |
|
| 26 |
Local Set Implicit Arguments. |
| 27 |
(* TODO: move to global settings *) |
| 28 |
Local Set Keyed Unification. |
| 29 |
Local Set Keep Proof Equalities. |
| 30 |
|
| 31 |
Local Ltac t_safe_step := |
| 32 |
first [ progress cbv in * |
| 33 |
| progress intros |
| 34 |
| reflexivity |
| 35 |
| progress subst |
| 36 |
| progress destruct_head'_ex |
| 37 |
| progress destruct_head'_unit |
| 38 |
| progress destruct_head'_and |
| 39 |
| progress destruct_head'_False |
| 40 |
| progress destruct_head'_or |
| 41 |
| progress break_innermost_match |
| 42 |
| progress break_innermost_match_hyps |
| 43 |
| progress specialize_under_binders_by exact tt |
| 44 |
| progress specialize_under_binders_by eapply ex_intro |
| 45 |
| apply conj |
| 46 |
| congruence |
| 47 |
| progress invlist InA |
| 48 |
| match goal with |
| 49 |
| [ |- NoDupA _ (_ :: _) ] => constructor |
| 50 |
| [ |- NoDupA _ nil ] => constructor |
| 51 |
| [ H : ?x = ?y :> Compare _ _ _ _ |- _ = _ ] |
| 52 |
=> let x := head x in |
| 53 |
let y := head y in |
| 54 |
is_constructor x; |
| 55 |
is_constructor y; |
| 56 |
inversion H; clear H |
| 57 |
end |
| 58 |
| solve [ eauto ] ]. |
| 59 |
Local Ltac t := |
| 60 |
repeat first [ t_safe_step |
| 61 |
| progress specialize_under_binders_by reflexivity ]. |
| 62 |
|
| 63 |
Module EmptyMap <: S with Module E := EmptyOrderedTypeOrig. |
| 64 |
Module E := EmptyOrderedTypeOrig. |
| 65 |
Definition key := Empty_set. |
| 66 |
Definition t (elt : Type) := unit. |
| 67 |
|
| 68 |
Section Types. |
| 69 |
|
| 70 |
Variable elt:Type. |
| 71 |
|
| 72 |
Definition empty : t elt := tt. |
| 73 |
Definition is_empty (m : t elt) : bool := true. |
| 74 |
Definition add (k : key) (v : elt) (m : t elt) : t elt := match k with end. |
| 75 |
Definition find (k : key) (m : t elt) : option elt := match k with end. |
| 76 |
Definition remove (k : key) (m : t elt) : t elt := match k with end. |
| 77 |
Definition mem (k : key) (m : t elt) : bool := match k with end. |
| 78 |
Variable elt' elt'' : Type. |
| 79 |
|
| 80 |
Definition map : (elt -> elt') -> t elt -> t elt' := fun _ m => m. |
| 81 |
Definition mapi (f : key -> elt -> elt') : t elt -> t elt' := fun m => m. |
| 82 |
Definition map2 (f : option elt -> option elt' -> option elt'') (m : t elt) (m' : t elt') : t elt'' |
| 83 |
:= tt. |
| 84 |
Definition elements (m : t elt) : list (key*elt) := nil. |
| 85 |
Definition cardinal (m : t elt) : nat := 0%nat. |
| 86 |
Definition fold A (f : key -> elt -> A -> A) (m : t elt) (acc : A) : A := acc. |
| 87 |
Definition equal : (elt -> elt -> bool) -> t elt -> t elt -> bool := fun _ _ _ => true. |
| 88 |
Section Spec. |
| 89 |
|
| 90 |
Variable m m' m'' : t elt. |
| 91 |
Variable x y z : key. |
| 92 |
Variable e e' : elt. |
| 93 |
|
| 94 |
Local Hint Constructors NoDupA : core. |
| 95 |
|
| 96 |
Definition MapsTo (k : key) (v : elt) (m : t elt) : Prop := match k with end. |
| 97 |
|
| 98 |
Definition In (k:key)(m: t elt) : Prop := exists e:elt, MapsTo k e m. |
| 99 |
|
| 100 |
Definition Empty m := forall (a : key)(e:elt) , ~ MapsTo a e m. |
| 101 |
|
| 102 |
Definition eq_key (p p':key*elt) := E.eq (fst p) (fst p'). |
| 103 |
|
| 104 |
Definition eq_key_elt (p p':key*elt) := |
| 105 |
E.eq (fst p) (fst p') /\ (snd p) = (snd p'). |
| 106 |
|
| 107 |
Lemma MapsTo_1 : E.eq x y -> MapsTo x e m -> MapsTo y e m. |
| 108 |
Proof using Type. clear; t. Qed. |
| 109 |
Lemma mem_1 : In x m -> mem x m = true. |
| 110 |
Proof using Type. clear; t. Qed. |
| 111 |
Lemma mem_2 : mem x m = true -> In x m. |
| 112 |
Proof using Type. clear; t. Qed. |
| 113 |
Lemma empty_1 : Empty empty. |
| 114 |
Proof using Type. clear; t. Qed. |
| 115 |
Lemma is_empty_1 : Empty m -> is_empty m = true. |
| 116 |
Proof using Type. clear; t. Qed. |
| 117 |
Lemma is_empty_2 : is_empty m = true -> Empty m. |
| 118 |
Proof using Type. clear; t. Qed. |
| 119 |
Lemma add_1 : E.eq x y -> MapsTo y e (add x e m). |
| 120 |
Proof using Type. clear; t. Qed. |
| 121 |
Lemma add_2 : ~ E.eq x y -> MapsTo y e m -> MapsTo y e (add x e' m). |
| 122 |
Proof using Type. clear; t. Qed. |
| 123 |
Lemma add_3 : ~ E.eq x y -> MapsTo y e (add x e' m) -> MapsTo y e m. |
| 124 |
Proof using Type. clear; t. Qed. |
| 125 |
Lemma remove_1 : E.eq x y -> ~ In y (remove x m). |
| 126 |
Proof using Type. clear; t. Qed. |
| 127 |
Lemma remove_2 : ~ E.eq x y -> MapsTo y e m -> MapsTo y e (remove x m). |
| 128 |
Proof using Type. clear; t. Qed. |
| 129 |
Lemma remove_3 : MapsTo y e (remove x m) -> MapsTo y e m. |
| 130 |
Proof using Type. clear; t. Qed. |
| 131 |
Lemma find_1 : MapsTo x e m -> find x m = Some e. |
| 132 |
Proof using Type. clear; t. Qed. |
| 133 |
Lemma find_2 : find x m = Some e -> MapsTo x e m. |
| 134 |
Proof using Type. clear; t. Qed. |
| 135 |
Lemma elements_1 : |
| 136 |
MapsTo x e m -> InA eq_key_elt (x,e) (elements m). |
| 137 |
Proof using Type. clear; t. Qed. |
| 138 |
Lemma elements_2 : |
| 139 |
InA eq_key_elt (x,e) (elements m) -> MapsTo x e m. |
| 140 |
Proof using Type. clear; t. Qed. |
| 141 |
Lemma elements_3w : NoDupA eq_key (elements m). |
| 142 |
Proof using Type. clear; t. Qed. |
| 143 |
Lemma cardinal_1 : cardinal m = length (elements m). |
| 144 |
Proof using Type. clear; t. Qed. |
| 145 |
Lemma fold_1 : |
| 146 |
forall (A : Type) (i : A) (f : key -> elt -> A -> A), |
| 147 |
fold f m i = fold_left (fun a p => f (fst p) (snd p) a) (elements m) i. |
| 148 |
Proof using Type. clear; t. Qed. |
| 149 |
Definition Equal m m' := forall y, find y m = find y m'. |
| 150 |
Definition Equiv (eq_elt:elt->elt->Prop) m m' := |
| 151 |
(forall k, In k m <-> In k m') /\ |
| 152 |
(forall k e e', MapsTo k e m -> MapsTo k e' m' -> eq_elt e e'). |
| 153 |
Definition Equivb (cmp: elt->elt->bool) := Equiv (Cmp cmp). |
| 154 |
|
| 155 |
Variable cmp : elt -> elt -> bool. |
| 156 |
|
| 157 |
Lemma equal_1 : Equivb cmp m m' -> equal cmp m m' = true. |
| 158 |
Proof using Type. clear; t. Qed. |
| 159 |
Lemma equal_2 : equal cmp m m' = true -> Equivb cmp m m'. |
| 160 |
Proof using Type. clear; t. Qed. |
| 161 |
End Spec. |
| 162 |
End Types. |
| 163 |
|
| 164 |
Lemma map_1 : forall (elt elt':Type)(m: t elt)(x:key)(e:elt)(f:elt->elt'), |
| 165 |
MapsTo x e m -> MapsTo x (f e) (map f m). |
| 166 |
Proof using Type. clear; t. Qed. |
| 167 |
Lemma map_2 : forall (elt elt':Type)(m: t elt)(x:key)(f:elt->elt'), |
| 168 |
In x (map f m) -> In x m. |
| 169 |
Proof using Type. clear; t. Qed. |
| 170 |
|
| 171 |
Lemma mapi_1 : forall (elt elt':Type)(m: t elt)(x:key)(e:elt) |
| 172 |
(f:key->elt->elt'), MapsTo x e m -> |
| 173 |
exists y, E.eq y x /\ MapsTo x (f y e) (mapi f m). |
| 174 |
Proof using Type. clear; t. Qed. |
| 175 |
Lemma mapi_2 : forall (elt elt':Type)(m: t elt)(x:key) |
| 176 |
(f:key->elt->elt'), In x (mapi f m) -> In x m. |
| 177 |
Proof using Type. clear; t. Qed. |
| 178 |
Lemma map2_1 : forall (elt elt' elt'':Type)(m: t elt)(m': t elt') |
| 179 |
(x:key)(f:option elt->option elt'->option elt''), |
| 180 |
In x m \/ In x m' -> |
| 181 |
find x (map2 f m m') = f (find x m) (find x m'). |
| 182 |
Proof using Type. clear; t. Qed. |
| 183 |
|
| 184 |
Lemma map2_2 : forall (elt elt' elt'':Type)(m: t elt)(m': t elt') |
| 185 |
(x:key)(f:option elt->option elt'->option elt''), |
| 186 |
In x (map2 f m m') -> In x m \/ In x m'. |
| 187 |
Proof using Type. clear; t. Qed. |
| 188 |
Section elt. |
| 189 |
Variable elt:Type. |
| 190 |
Definition lt_key (p p':key*elt) := E.lt (fst p) (fst p'). |
| 191 |
Lemma elements_3 : forall m, sort lt_key (elements m). |
| 192 |
Proof using Type. clear; t. Qed. |
| 193 |
End elt. |
| 194 |
End EmptyMap. |
| 195 |
|
| 196 |
Module EmptyMapOrd (D : OrderedTypeOrig) <: Sord |
| 197 |
with Module Data := D |
| 198 |
with Module MapS := EmptyMap. |
| 199 |
Module Data <: OrderedTypeOrig := D. |
| 200 |
Module MapS <: S := EmptyMap. |
| 201 |
Import MapS. |
| 202 |
|
| 203 |
Definition t := EmptyMap.t Data.t. |
| 204 |
Include UnitHasEq. |
| 205 |
Include UnitHasLt. |
| 206 |
Include UnitIsEqOrig. |
| 207 |
Include UnitIsStrOrderOrig. |
| 208 |
Definition cmp e e' := match Data.compare e e' with EQ _ => true | _ => false end. |
| 209 |
Lemma eq_1 : forall m m', Equivb cmp m m' -> eq m m'. |
| 210 |
Proof. t. Qed. |
| 211 |
Lemma eq_2 : forall m m', eq m m' -> Equivb cmp m m'. |
| 212 |
Proof. pose proof Data.lt_not_eq. pose proof Data.eq_sym. t. Qed. |
| 213 |
|
| 214 |
Definition compare : forall m1 m2, Compare lt eq m1 m2. |
| 215 |
Proof. |
| 216 |
constructor; destruct_head'_unit; reflexivity. |
| 217 |
Defined. |
| 218 |
|
| 219 |
End EmptyMapOrd. |