-
Notifications
You must be signed in to change notification settings - Fork 2
/
BridgeProperties.v
375 lines (292 loc) · 8.57 KB
/
BridgeProperties.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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
(*
(Single-trace) properties of bridge relation
Author: Aslan Askarov
Created: 2016-07-26
*)
Require Import Bool Arith List CpdtTactics SfLib LibTactics.
Require Import Coq.Program.Equality.
Require Import Omega.
Set Implicit Arguments.
Require Import Identifier Environment Imperative Types Augmented Bridge.
Require Import WellFormedness LowEq NIexp.
Require Import InductionPrinciple.
Require Import UtilTactics.
Require Import BridgeTactics.
(* TODO : move these lemmas outside *)
(* 2016-07-25
- auxiliarly ltac to deal with inductive cases
(when inducting over n in bridge definition)
to disregard impossible cases;
- useful in the following two lemmas about inverting properties of skip and assign
*)
Ltac bridge_inductive_impossible_aux H:=
intros; inversion H; subst; invert_high_steps; eauto; stop_contradiction_alt.
Lemma preservation_bridge:
forall Γ pc c c' m m' ev n,
-{ Γ , pc ⊢ c }- ->
〈c, m 〉 ⇨+/(SL, Γ, ev, n) 〈c', m' 〉 ->
wf_mem m Γ ->
(wf_mem m' Γ /\ (c' <> STOP -> -{ Γ , pc ⊢ c' }- )) .
Proof.
intros.
dependent induction H0.
- invert_low_event_step.
forwards : preservation_event_step evt; eauto.
- invert_high_event_step.
forwards : preservation_event_step; eauto.
- invert_high_event_step.
destruct cfg' as [c'' m''].
forwards* (H_wf' & H_wt' ): preservation_event_step evt' c m c'' m''.
Qed.
Lemma while_bridge_properties:
forall Γ n e c m ev c_end m_end,
〈WHILE e DO c END, m 〉 ⇨+/(SL, Γ, ev, n) 〈c_end, m_end 〉
->
n >= 1 /\
〈 IFB e THEN c;; WHILE e DO c END ELSE SKIP FI, m〉 ⇨+/(SL, Γ, ev, n - 1) 〈c_end, m_end 〉.
Proof.
intros.
inverts~ H.
split*.
- exfalso. invert_low_steps.
- exfalso. invert_low_steps.
- exfalso. invert_high_steps. eauto.
-
invert_high_steps.
invert_step.
split; try omega.
match goal with [ |- context [S ?x - 1]] =>
replace (S x - 1 ) with x by omega
end; eauto.
Qed.
Lemma if_bridge_properties:
forall Γ n e c1 c2 m ev c_end m_end,
〈IFB e THEN c1 ELSE c2 FI, m 〉 ⇨+/(SL, Γ, ev, n) 〈c_end, m_end 〉
->
n >= 1 /\
(
( exists u, (eval e m u) /\ u <> 0 /\ 〈c1, m 〉 ⇨+/(SL, Γ, ev, n - 1) 〈c_end, m_end 〉)
\/
( (eval e m 0 ) /\ 〈c2, m 〉 ⇨+/(SL, Γ, ev, n - 1) 〈c_end, m_end 〉)
).
Proof.
intros.
inverts H.
- exfalso. invert_low_steps.
- exfalso. invert_high_steps. eauto.
- split~ ; try omega.
invert_high_steps.
invert_step; [left; exists u | right];
match goal with [ |- context [S ?x - 1]] =>
replace (S x - 1 ) with x by omega
end; eauto.
Qed.
Lemma is_not_stop_trivial_exf: forall m,
is_not_stop 〈STOP, m 〉 -> False.
Proof.
intros.
unfolds in H.
unfolds in H.
assert ( cmd_of 〈STOP, m 〉= STOP).
auto.
specialize_gen.
assumption.
Qed.
Hint Resolve is_not_stop_trivial_exf.
Lemma skip_bridge_properties:
forall Γ n m ev c_end m_end,
〈SKIP, m 〉 ⇨+/(SL, Γ, ev, n) 〈c_end, m_end 〉->
m_end = m /\ c_end = STOP /\ n = 0 /\ ev = EmptyEvent.
Proof.
intros.
bridge_num_cases (inverts* H) Case.
- inverts H0.
inverts* H.
- inverts H0.
inverts H.
split ~ .
- invert_high_steps.
exfalso.
eauto.
Qed.
Ltac eval_determinism :=
match goal with
| [ H : eval ?E ?M ?V1, H' : eval ?E ?M ?V2 |- _ ] =>
forwards* : eval_is_det V1 V2; clear H
end.
Lemma assign_bridge_properties:
forall Γ n x e m ev c_end m_end,
〈x ::= e, m 〉 ⇨+/(SL, Γ, ev, n) 〈c_end, m_end 〉
-> (exists v ℓ,
eval e m v /\ m_end = update_st m x v
/\ Γ (x) = Some ℓ /\
( ℓ ⊑ Low -> ev = AssignmentEvent ℓ x v )
/\
(~ℓ ⊑ Low -> high_event Γ Low ev)
)
/\ (c_end = STOP)
/\ (n = 0).
Proof.
intros Γ n x e. intros.
inverts* H.
- invert_low_steps; subst.
split ~ .
match goal with
[_: context [eval e m ?v] |- _ ] =>
(exists v Low)
end.
splits * .
+ invert_step. eval_determinism.
+ intros. destruct ℓ; eauto; impossible_flows.
+ intros. destruct ℓ; eauto; impossible_flows.
- invert_high_steps; subst.
splits ~ .
match goal with
[_: context [eval e m ?v], _: Γ _ = Some ?ℓ |- _ ] =>
(exists v ℓ)
end.
splits ~ .
+ invert_step. eval_determinism.
- exfalso.
invert_high_steps.
eauto.
Qed.
Lemma seq_comp_bridge_property:
forall Γ n c1 c2 m ev c_end m_end,
〈c1;; c2, m 〉 ⇨+/(SL, Γ, ev, n) 〈c_end, m_end 〉
->
(exists c1', 〈c1, m 〉 ⇨+/(SL, Γ, ev, n) 〈 c1', m_end 〉
/\ (c1' <> STOP -> c_end = (c1';; c2))
/\ (c1' = STOP -> c_end = c2)
/\ low_event Γ Low ev
)
\/
(exists m1' k evt,
k < n /\ n > 0 /\
high_event Γ Low evt /\
〈c1, m 〉 ⇨+/(SL, Γ, evt, k) 〈 STOP, m1' 〉
/\ 〈c2, m1' 〉 ⇨+/(SL, Γ, ev, n - k - 1 ) 〈 c_end, m_end 〉
).
Proof.
intros Γ n.
induction n.
(* base case *)
{
left.
intros.
inverts* H.
(* 2 cases *)
- (* low-step*)
do 2
match goal with
| [ H : context [low_event_step] |- _ ] =>
(inverts H ; clear H)
| [ H : context [event_step _ _ 〈 c1;; c2, _ 〉 _] |- _ ] =>
(inverts H ; clear H);
match goal with
| [ H : context [event_step _ _ 〈c1, _ 〉〈?C1, _ 〉] |- _ ] =>
(exists C1; repeat ( constructor || assumption))
end;
intros; exfalso;eauto
end.
- (* high_step *)
repeat
match goal with
| [ H : context [high_event_step] |- _ ] =>
unfold high_event_step in H
| [ H : context [event_step _ _ 〈 c1;; c2, _ 〉 _ ] |- _ ] =>
inversion H; subst; clear H
| [ H : context [is_stop] |- _ ] =>
do 2 unfolds in H; inverts* H
| [ H : context [ _ = 〈 STOP, _ 〉] |- _ ] =>
inversion H; clear H; contradiction
end; crush.
}
(* inductive case *)
{
intros.
inverts H.
do 3
match goal with
| [ H : context [high_event_step] |- _ ] =>
unfold high_event_step in H
| [ H : context [event_step _ _ 〈 c1;; c2, _ 〉 _ ] |- _ ] =>
inversion H; subst; clear H
end.
{
match goal with
| [ H: 〈?c1';; c2, ?st' 〉 ⇨+/(SL, Γ, ev, n) 〈c_end, m_end 〉 |- _ ]
=> specialize (IHn c1' c2 st' ev c_end m_end H)
end.
destruct IHn.
{
super_destruct.
match goal with [ H:〈c1', st' 〉 ⇨+/(SL, Γ, ev, n) 〈?x, m_end 〉 |- _ ] =>
rename x into c1_end
end.
left.
exists c1_end.
compare c1_end STOP; intros;
repeat (specialize_gen; subst; split; auto);
apply bridge_trans_num with evt' 〈c1', st' 〉; eauto.
}
{
super_destruct.
match goal with [ H:〈c2, ?X 〉 ⇨+/(SL, Γ, ev, n - ?K -1 ) 〈c_end, m_end 〉|- _ ] =>
rename X into m1_end;
rename K into k
end.
right; exists m1_end (S k).
match goal with
[ _ : 〈 c1', _ 〉 ⇨+/(SL, Γ, ?EV, k) 〈 STOP, _ 〉 |- _ ]
=> (exists EV)
end.
splits*; try omega.
apply bridge_trans_num with evt' 〈c1', st' 〉; eauto.
}
}
{
right; exists st' 0 evt'.
splits; try omega; eauto.
- apply bridge_stop_num; eauto.
- unfolds is_not_stop.
assert (( S n - 0 - 1 = n )) as X by omega.
rewrite X.
assumption.
}
}
Qed.
Lemma event_low_eq_empty:
forall Γ,
event_low_eq Γ EmptyEvent EmptyEvent.
Proof.
intros.
unfolds.
repeat (splits; auto).
Qed.
Hint Resolve event_low_eq_empty.
Lemma event_low_eq_high:
forall Γ x v y u,
event_low_eq Γ (AssignmentEvent High x v) (AssignmentEvent High y u).
Proof.
intros; unfolds.
repeat split; intros; inversion H; impossible_flows.
Qed.
Hint Resolve event_low_eq_high.
Lemma event_low_eq_low:
forall Γ x v,
event_low_eq Γ (AssignmentEvent Low x v) (AssignmentEvent Low x v).
Proof.
intros.
unfolds.
repeat split; auto.
Qed.
Hint Resolve event_low_eq_low.
Lemma config_low_eq_trivial:
forall Γ m s c,
state_low_eq Γ m s ->
config_low_eq Γ 〈 c, m 〉 〈c, s 〉.
Proof.
intros; constructor; auto.
Qed.
Hint Resolve config_low_eq_trivial.