-
Notifications
You must be signed in to change notification settings - Fork 0
/
WfMod_Helper.v
290 lines (271 loc) · 8.26 KB
/
WfMod_Helper.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
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
(*
* Helper theorems and tactics for verifying WfMod properties
*)
Require Import Kami.AllNotations.
Require Import Kami.Notations.
Require Import Kami.Rewrites.Notations_rewrites.
Require Import Kami.Properties.
Require Import Kami.PProperties.
Require Import Kami.Syntax.
Require Import Vector.
Require Import List.
Require Import Coq.Strings.String.
Local Open Scope kami_action.
Local Open Scope kami_expr.
Theorem string_equal_prefix: forall (a: string) (b: string) (c: string), (a++b=a++c)%string<->(b=c)%string.
Proof.
split.
- intros.
induction a.
+ simpl in H.
apply H.
+ inversion H; subst; clear H.
apply IHa.
apply H1.
- intros.
subst.
reflexivity.
Qed.
Theorem DisjKey_nil2: forall A B (l: list (A*B)), DisjKey l List.nil.
Proof.
intros.
unfold DisjKey.
intros.
right.
simpl.
intro X.
elim X.
Qed.
Theorem DisjKey_nil1: forall A B (l: list (A*B)), DisjKey List.nil l.
Proof.
intros.
unfold DisjKey.
intros.
left.
simpl.
intro X.
elim X.
Qed.
(*Theorem or_diff: forall p a b, a<> b -> forall k : string,
~ ((p ++ a)%string = k \/ False) \/
~ ((p ++ b)%string = k \/ False).
Proof.
intros.
classical_left.
apply NNPP in H0.
inversion H0;subst;clear H0.
+ intro X.
inversion X;subst;clear X.
- apply string_equal_prefix in H0.
apply H in H0.
elim H0.
- elim H0.
+ elim H1.
Qed.*)
Ltac trivialSolve :=
match goal with
| |- forall _, In _ (getAllRules (Base (BaseRegFile _))) -> _ => simpl;intros;trivialSolve
| H: False |- _ => elim H
| |- DisjKey _ List.nil => apply DisjKey_nil2
| |- DisjKey List.nil _ => apply DisjKey_nil1
| |- DisjKeyWeak _ List.nil => rewrite <- DisjKeyWeak_same;[apply DisjKey_nil2 | repeat (decide equality)]
| |- DisjKeyWeak List.nil _ => rewrite <- DisjKeyWeak_same;[apply DisjKey_nil1 | repeat (decide equality)]
| |- ~ (List.In _ _) => simpl;trivialSolve
| |- ~ (_ \/ _) => let X := fresh in intro X;inversion X;subst;clear X;trivialSolve
| |- _ /\ _ => split;trivialSolve
| |- ~False => let X := fresh in intro X;inversion X
| |- (_++_)%string <> (_++_)%string => let X := fresh in try (intro X;apply string_equal_prefix in X; inversion X)
(*| |- ~((?P++_)%string = _ \/ False) \/ ~((?P++_)%string = _ \/ False) => let X := fresh in try (apply or_diff;intro X;inversion X)*)
| |- NoDup (_::_) => econstructor; simpl; trivialSolve
| |- NoDup [] => econstructor
| H: _ \/ _ |- _ => inversion H;subst;clear H;trivialSolve
| H: (?P++_)%string=(?P++_)%string |- _ => apply string_equal_prefix in H;inversion H;subst;clear H;trivialSolve
| H: In _ (map fst _) |- _ => simpl in H;trivialSolve
| |- (?P = ?P) => reflexivity
| _ => idtac
end.
Theorem ne_disjunction_break1: forall a b c, (~(a \/ False) \/ ~(b \/ False)) /\
(~(a \/ False) \/ ~c) ->
~(a \/ False) \/ ~(b \/ c).
Proof.
tauto.
Qed.
Theorem ne_disjunction_break2: forall a b c, (~(a \/ False) \/ ~c) /\
(~b \/ ~c) ->
~(a \/ b) \/ ~ c.
Proof.
tauto.
Qed.
(*Ltac DisjKey_solve :=
match goal with
(*| |- ~((?P++_)%string = _ \/ False) \/ ~((?P++_)%string = _ \/ False) => let X := fresh in try (apply or_diff;intro X;inversion X)*)
| |- ~(_ \/ False) \/ ~(_ \/ _) => apply ne_disjunction_break1;split;DisjKey_solve
| |- ~(_ \/ _ \/ _) \/ ~_ => apply ne_disjunction_break2;split;DisjKey_solve
(*| |- DisjKey _ _ => unfold DisjKey; simpl; intros;DisjKey_solve*)
| |- DisjKey _ _ => rewrite DisjKeyWeak_same;[ DisjKey_solve | repeat (decide equality) ]
| |- DisjKeyWeak _ _ => unfold DisjKeyWeak;intros;DisjKey_solve
| H: In _ (map fst ((_,_)::_)) |- _ => simpl in H;DisjKey_solve
| |- _ => trivialSolve
end.*)
Theorem DisjKey_NubBy1: forall T (x: list (string * T)) (y: list (string * T)), DisjKey x y -> DisjKey (nubBy (fun '(a,_) '(b,_) => String.eqb a b) x) y.
Proof.
intros T x y.
generalize y.
induction x.
+ simpl.
intros.
apply H.
+ simpl.
remember (
existsb (let '(a0, _) := a in fun '(b, _) => a0 =? b)%string
(nubBy (fun '(a0, _) '(b, _) => a0 =? b)%string x)).
destruct b.
- simpl.
intros.
apply IHx.
unfold DisjKey in H.
simpl in H.
unfold DisjKey.
intros.
assert(
~ (fst a = k \/ In k (map fst x)) \/ ~ In k (map fst y0)
).
++ apply H.
++ inversion H0;subst;clear H0.
-- left.
intro X.
apply H1.
right.
apply X.
-- right.
apply H1.
- intros.
rewrite DisjKey_Cons1.
rewrite DisjKey_Cons1 in H.
inversion H;subst;clear H.
split.
++ apply H0.
++ apply IHx.
apply H1.
++ repeat (decide equality).
++ repeat (decide equality).
Qed.
Theorem DisjKey_NubBy2: forall T (x: list (string * T)) (y: list (string * T)), DisjKey x y -> DisjKey x (nubBy (fun '(a,_) '(b,_) => String.eqb a b) y).
Proof.
intros T x y.
generalize x.
induction y.
+ simpl.
intros.
apply H.
+ simpl.
remember (
existsb (let '(a0, _) := a in fun '(b, _) => a0 =? b)%string
(nubBy (fun '(a0, _) '(b, _) => a0 =? b) y)%string).
destruct b.
- simpl.
intros.
apply IHy.
unfold DisjKey in H.
simpl in H.
unfold DisjKey.
intros.
assert(
~ In k (map fst x0) \/ ~ (fst a = k \/ In k (map fst y))
).
++ apply H.
++ inversion H0; subst; clear H0.
-- left.
apply H1.
-- right.
intro X.
apply H1.
right.
apply X.
- intros.
rewrite DisjKey_Cons2.
rewrite DisjKey_Cons2 in H.
inversion H;subst;clear H.
split.
++ apply H0.
++ apply IHy.
apply H1.
++ repeat (decide equality).
++ repeat (decide equality).
Qed.
Theorem NoDup_NubBy_helper: forall T (a:(string * T)) (l:list (string *T)),
false = existsb (let '(a0, _) := a in fun '(b, _) => a0 =? b)%string l ->
~ In (fst a) (map fst l).
Proof.
induction l.
+ simpl.
intros.
intro X.
elim X.
+ simpl.
intros.
intro X.
inversion X;subst;clear X.
destruct a0.
destruct a.
simpl in H0.
subst.
remember (s0=?s0)%string.
destruct b.
- simpl in H.
inversion H.
- rewrite eqb_refl in Heqb.
inversion Heqb.
- destruct a.
destruct a0.
simpl in H0.
simpl in IHl.
remember (s =? s0)%string.
destruct b.
* simpl in H.
inversion H.
* simpl in H.
apply IHl.
** apply H.
** apply H0.
Qed.
Theorem NoDup_NubBy: forall T (x: list (string * T)), NoDup (map fst (nubBy (fun '(a,_) '(b,_) => String.eqb a b) x)).
Proof.
intros.
induction x.
+ simpl.
apply NoDup_nil.
+ simpl.
remember (
existsb (let '(a0, _) := a in fun '(b, _) => a0 =? b)%string
(nubBy (fun '(a0, _) '(b, _) => a0 =? b)%string x)
).
destruct b.
- apply IHx.
- simpl.
apply NoDup_cons.
apply NoDup_NubBy_helper.
apply Heqb.
apply IHx.
Qed.
Ltac ltac_wfMod_ConcatMod :=
apply ConcatModWf;autorewrite with kami_rewrite_db;repeat split;try assumption;auto with wfMod_ConcatMod_Helper;trivialSolve.
(*Ltac WfMod_Solve :=
match goal with
| |- _ => (progress discharge_wf);WfMod_Solve
| |- forall _, _ => intros;WfMod_Solve
| |- _ -> _ => intros;WfMod_Solve
| |- _ /\ _ => split;WfMod_Solve
| |- In _ _ => simpl;WfMod_Solve
| |- (_ \/ False) => left;WfMod_Solve
| |- _ => trivialSolve
end.
Ltac WfConcatAction_Solve :=
match goal with
| |- _ => progress discharge_wf;WfConcatAction_Solve
| |- forall _, _ => intros;simpl;WfConcatAction_Solve
| H: In _ (getAllMethods _) |- _ => simpl in H;inversion H;subst;clear H;simpl;WfConcatAction_Solve
| H: _ \/ _ |- _ => simpl in H;inversion H;subst;clear H;simpl;WfConcatAction_Solve
| H: False |- _ => inversion H
| |- _ => idtac
end.*)