-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstate.v
More file actions
393 lines (335 loc) · 9.06 KB
/
state.v
File metadata and controls
393 lines (335 loc) · 9.06 KB
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
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
Require Import util Aid.
Require Import Coq.Arith.Arith.
Require Import Coq.Bool.Bool.
Require Import Coq.Lists.List.
Require Import Coq.Strings.String.
Require Import Coq.Logic.FunctionalExtensionality.
(*定义五元组来表示系统状态*)
(*Sv, Sb, Sf*)
Definition storeV := id -> nat.
Definition storeB := id -> nat.
Definition storeF := id -> list nat.
(*Hv,Hb因为可能对应不到值,所以用可选类型*)
Definition heapV := nat -> option nat.
Definition heapB := nat -> option (list (option nat)).
(*定义空堆*)
Definition emp_heapV : heapV :=
fun (n: nat) => None.
Definition emp_heapB : heapB :=
fun (n: nat) => None.
(*定义命题 : 在堆的定义域中*)
Definition in_domV (loc: nat) (hv: heapV) : Prop :=
exists n, hv loc = Some n.
Definition in_domB (bloc: nat) (hb: heapB) : Prop :=
exists l, hb bloc = Some l.
(*定义命题 : 不在堆的定义域中*)
Definition not_in_domV (loc: nat) (hv: heapV) : Prop :=
hv loc = None.
Definition not_in_domB (bloc: nat) (hb: heapB) : Prop :=
hb bloc = None.
(*在定义域的(Some n) + 不在定义域的(None) 为全集*)
Theorem in_not_in_dec_V :
forall l h, {in_domV l h} + {not_in_domV l h}.
Proof.
intros l h.
unfold in_domV, not_in_domV.
destruct (h l).
- left. exists n. auto.
- right. auto.
Qed.
Theorem in_not_in_dec_B :
forall l h, {in_domB l h} + {not_in_domB l h}.
Proof.
intros l h.
unfold in_domB, not_in_domB.
destruct (h l).
- left. exists l0. auto.
- right. auto.
Qed.
(*定义命题:两堆不相交*)
Definition disjointV (h1 h2: heapV) : Prop :=
forall l, not_in_domV l h1 \/ not_in_domV l h2.
Definition disjointB (h1 h2: heapB) : Prop :=
forall l, not_in_domB l h1 \/ not_in_domB l h2.
(*heap1 析取 heap2*)
Definition h_unionV (h1 h2: heapV) : heapV :=
fun l =>
if (in_not_in_dec_V l h1) then h1 l else h2 l.
Definition h_unionB (h1 h2: heapB) : heapB :=
fun l =>
if (in_not_in_dec_B l h1) then h1 l else h2 l.
(* h1 is a subset of h2 *)
Definition h_subsetV (h1 h2: heapV) : Prop :=
forall loc n, h1 loc = Some n -> h2 loc = Some n.
Definition h_subsetB (h1 h2: heapB) : Prop :=
forall bloc l, h1 bloc = Some l -> h2 bloc = Some l.
(* store update *)
Definition sV_update (s: storeV) (x: id) (n: nat) : storeV :=
fun x' => if beq_id x x' then n else s x'.
Definition sB_update (s: storeB) (x: id) (n: nat) : storeB :=
fun x' => if beq_id x x' then n else s x'.
Definition sF_update (s: storeF) (x: id) (nli: list nat) : storeF :=
fun x' => if beq_id x x' then nli else s x'.
Notation "x '!sv->' v ';' m" := (sV_update m x v)
(at level 100, v at next level, right associativity).
Notation "x '!sb->' v ';' m" := (sB_update m x v)
(at level 100, v at next level, right associativity).
Notation "x '!sf->' v ';' m" := (sF_update m x v)
(at level 100, v at next level, right associativity).
(* heap update *)
Definition hV_update (h: heapV) (loc: nat) (n: nat) : heapV :=
fun loc' => if beq_nat loc loc' then Some n else h loc'.
Definition hB_update (h: heapB) (bloc: nat) (l: list (option nat)) : heapB :=
fun bloc' => if beq_nat bloc bloc' then Some l else h bloc'.
Notation "x '!hv->' v ';' m" := (hV_update m x v)
(at level 100, v at next level, right associativity).
Notation "x '!hb->' v ';' m" := (hB_update m x v)
(at level 100, v at next level, right associativity).
(* heap remove *)
Definition hV_remove (h:heapV) (l:nat) : heapV :=
fun x => if beq_nat x l then None else h x.
Definition hB_remove (h:heapB) (l:nat) : heapB :=
fun x => if beq_nat x l then None else h x.
(****Some Lemma****)
Lemma sV_update_eq : forall storeV x v,
(x !sv-> v ; storeV) x = v.
Proof.
intros.
unfold sV_update.
rewrite beq_id_refl.
reflexivity.
Qed.
Lemma sB_update_eq : forall storeB x v,
(x !sb-> v ; storeB) x = v.
Proof.
intros.
unfold sB_update.
rewrite beq_id_refl.
reflexivity.
Qed.
Theorem sB_update_neq :forall sB x1 x2 v,
x1 <> x2
->(x2 !sb-> v ; sB) x1 = sB x1.
Proof.
intros.
unfold sB_update.
apply beq_neq_id in H.
rewrite beq_comm_id in H.
rewrite H.
reflexivity.
Qed.
Lemma sF_update_eq : forall storeF x v,
(x !sf-> v ; storeF) x = v.
Proof.
intros.
unfold sF_update.
rewrite beq_id_refl.
reflexivity.
Qed.
Theorem sF_update_neq :forall sF x1 x2 v,
x1 <> x2
->(x2 !sf-> v ; sF) x1 = sF x1.
Proof.
intros.
unfold sF_update.
apply beq_neq_id in H.
rewrite beq_comm_id in H.
rewrite H.
reflexivity.
Qed.
Lemma hV_update_eq : forall heapV x v,
(x !hv-> v ; heapV) x = Some v.
Proof.
intros.
unfold hV_update.
rewrite <- beq_nat_refl.
reflexivity.
Qed.
Lemma hB_update_eq : forall heapB x v,
(x !hb-> v ; heapB) x = Some v.
Proof.
intros.
unfold hB_update.
rewrite <- beq_nat_refl.
reflexivity.
Qed.
Theorem hB_update_neq :forall hB x1 x2 v,
x1 <> x2
->(x2 !hb-> v ; hB) x1 = hB x1.
Proof.
intros.
unfold hB_update.
apply beq_neq in H.
rewrite beq_comm in H.
rewrite H.
reflexivity.
Qed.
Lemma sV_update_shadow : forall storeV x v1 v2,
(x !sv-> v2 ; x !sv-> v1 ; storeV) = (x !sv-> v2; storeV).
Proof.
intros.
apply functional_extensionality.
intros.
unfold sV_update.
destruct (beq_id x x0) eqn:H.
trivial. trivial.
Qed.
Lemma sB_update_shadow : forall storeB x v1 v2,
(x !sb-> v2 ; x !sb-> v1 ; storeB) = (x !sb-> v2; storeB).
Proof.
intros.
apply functional_extensionality.
intros.
unfold sB_update.
destruct (beq_id x x0) eqn:H.
trivial. trivial.
Qed.
Lemma sB_update_shadow_3 : forall storeB x y v1 v2 v3,
(x !sb-> v2 ; y !sb-> v1 ; x !sb-> v3 ;storeB)
= (x !sb-> v2; y !sb-> v1; storeB).
Proof.
intros.
apply functional_extensionality.
intros.
unfold sB_update.
destruct (beq_id x x0) eqn:H.
trivial. trivial.
Qed.
Lemma sV_update_shadow_2 : forall storeV x y v1 v2 v3,
(x !sv-> v2 ; y !sv-> v1 ; x !sv-> v3 ;storeV)
= (x !sv-> v2; y !sv-> v1; storeV).
Proof.
intros.
apply functional_extensionality.
intros.
unfold sV_update.
destruct (beq_id x x0) eqn:H.
trivial. trivial.
Qed.
Lemma sV_update_shadow_3 : forall storeV x y z v1 v2 v3 v4,
(x !sv-> v2 ; y !sv-> v1 ; z !sv-> v4 ; x !sv-> v3 ;storeV)
= (x !sv-> v2; y !sv-> v1 ; z !sv-> v4 ; storeV).
Proof.
intros.
apply functional_extensionality.
intros.
unfold sV_update.
destruct (beq_id x x0) eqn:H.
trivial. trivial.
Qed.
Lemma sF_update_shadow : forall storeF x v1 v2,
(x !sf-> v2 ; x !sf-> v1 ; storeF) = (x !sf-> v2; storeF).
Proof.
intros.
apply functional_extensionality.
intros.
unfold sF_update.
destruct (beq_id x x0) eqn:H.
trivial. trivial.
Qed.
Lemma sF_update_shadow_3 : forall storeF x y v1 v2 v3,
(x !sf-> v2 ; y !sf-> v1 ; x !sf-> v3 ;storeF)
= (x !sf-> v2; y !sf-> v1; storeF).
Proof.
intros.
apply functional_extensionality.
intros.
unfold sF_update.
destruct (beq_id x x0) eqn:H.
trivial. trivial.
Qed.
Lemma hV_update_shadow : forall heapV x v1 v2,
(x !hv-> v2 ; x !hv-> v1 ; heapV) = (x !hv-> v2; heapV).
Proof.
intros.
apply functional_extensionality.
intros.
unfold hV_update.
destruct (beq_nat x x0) eqn:H.
trivial. trivial.
Qed.
Lemma hB_update_shadow : forall heapB x v1 v2,
(x !hb-> v2 ; x !hb-> v1 ; heapB) = (x !hb-> v2; heapB).
Proof.
intros.
apply functional_extensionality.
intros.
unfold hB_update.
destruct (beq_nat x x0) eqn:H.
trivial. trivial.
Qed.
Lemma hB_remove_neq : forall hB x1 x2 v,
x1 <> x2
-> hB_remove (x2 !hb-> v;hB) x1
= (x2 !hb-> v; hB_remove hB x1).
Proof.
intros.
apply functional_extensionality.
intros.
unfold hB_remove.
destruct (beq_nat x x1) eqn:H1.
+ rewrite beq_eq in H1.
rewrite H1,hB_update_neq.
rewrite <- beq_refl.
trivial. trivial.
+ destruct (beq_nat x x2) eqn:H2.
- rewrite beq_eq in H2. subst.
repeat rewrite hB_update_eq. trivial.
- rewrite beq_neq in H2.
repeat rewrite hB_update_neq; trivial.
rewrite H1.
trivial.
Qed.
(* Lemma hB_remove_eq : forall hB x1 x2 v,
x1 <> x2
-> (hB_remove (x2 !hb-> v;hB) x1) x2 = Some v.
Proof.
intros.
unfold hB_remove.
apply neq_comm in H.
rewrite <- beq_neq in H.
rewrite H.
apply hB_update_eq.
Qed.
Lemma hB_remove_neq : forall hB x1 x2 x3 v,
x1 <> x2 -> x3 <> x2
-> (hB_remove (x1 !hb-> v;hB) x3) x2
= (hB_remove hB x3) x2.
Proof.
intros.
unfold hB_remove.
apply neq_comm in H0.
rewrite <- beq_neq in H0.
rewrite H0.
apply hB_update_neq.
auto.
Qed. *)
Lemma hB_remove_emp : forall x,
hB_remove emp_heapB x = emp_heapB.
Proof.
intros.
apply functional_extensionality.
intros.
unfold hB_remove.
destruct (beq_nat x0 x) eqn:H1;
trivial.
Qed.
Lemma hB_remove_work : forall hB x v,
not_in_domB x hB
-> hB_remove (x !hb-> v;hB) x = hB.
Proof.
intros.
apply functional_extensionality.
intros.
unfold hB_remove.
destruct (beq_nat x0 x) eqn:H1.
- rewrite beq_eq in H1. subst. auto.
- rewrite beq_neq in H1.
rewrite hB_update_neq; auto.
Qed.
(*定义五元组*)
Definition state : Type := (storeV * storeB * storeF * heapV * heapB).
(*定义状态转换*)
Inductive ext_state : Type :=
| St: state -> ext_state (* normal state *)
| Abt: ext_state. (* abort *)