9580
|
1 |
(* Title: HOL/MicroJava/BV/StepMono.thy
|
9559
|
2 |
ID: $Id$
|
|
3 |
Author: Gerwin Klein
|
|
4 |
Copyright 2000 Technische Universitaet Muenchen
|
|
5 |
*)
|
|
6 |
|
9594
|
7 |
header {* Monotonicity of step and app *}
|
9559
|
8 |
|
9594
|
9 |
theory StepMono = Step:
|
9559
|
10 |
|
|
11 |
|
9580
|
12 |
lemma PrimT_PrimT: "(G \<turnstile> xb \<preceq> PrimT p) = (xb = PrimT p)"
|
9594
|
13 |
by (auto elim: widen.elims)
|
9559
|
14 |
|
|
15 |
|
|
16 |
lemma sup_loc_some [rulify]:
|
9580
|
17 |
"\<forall> y n. (G \<turnstile> b <=l y) \<longrightarrow> n < length y \<longrightarrow> y!n = Some t \<longrightarrow> (\<exists>t. b!n = Some t \<and> (G \<turnstile> (b!n) <=o (y!n)))" (is "?P b")
|
9559
|
18 |
proof (induct "?P" b)
|
|
19 |
show "?P []" by simp
|
|
20 |
|
|
21 |
case Cons
|
|
22 |
show "?P (a#list)"
|
|
23 |
proof (clarsimp simp add: list_all2_Cons1 sup_loc_def)
|
|
24 |
fix z zs n
|
|
25 |
assume * :
|
9580
|
26 |
"G \<turnstile> a <=o z" "list_all2 (sup_ty_opt G) list zs"
|
9559
|
27 |
"n < Suc (length zs)" "(z # zs) ! n = Some t"
|
|
28 |
|
9580
|
29 |
show "(\<exists>t. (a # list) ! n = Some t) \<and> G \<turnstile>(a # list) ! n <=o Some t"
|
9559
|
30 |
proof (cases n)
|
|
31 |
case 0
|
9594
|
32 |
with * show ?thesis by (simp add: sup_ty_opt_Some)
|
9559
|
33 |
next
|
|
34 |
case Suc
|
|
35 |
with Cons *
|
|
36 |
show ?thesis by (simp add: sup_loc_def)
|
|
37 |
qed
|
|
38 |
qed
|
|
39 |
qed
|
|
40 |
|
|
41 |
|
|
42 |
lemma all_widen_is_sup_loc:
|
9580
|
43 |
"\<forall>b. length a = length b \<longrightarrow> (\<forall>x\<in>set (zip a b). x \<in> widen G) = (G \<turnstile> (map Some a) <=l (map Some b))"
|
|
44 |
(is "\<forall>b. length a = length b \<longrightarrow> ?Q a b" is "?P a")
|
9559
|
45 |
proof (induct "a")
|
|
46 |
show "?P []" by simp
|
|
47 |
|
|
48 |
fix l ls assume Cons: "?P ls"
|
|
49 |
|
|
50 |
show "?P (l#ls)"
|
|
51 |
proof (intro allI impI)
|
|
52 |
fix b
|
|
53 |
assume "length (l # ls) = length (b::ty list)"
|
|
54 |
with Cons
|
|
55 |
show "?Q (l # ls) b" by - (cases b, auto)
|
|
56 |
qed
|
|
57 |
qed
|
|
58 |
|
|
59 |
|
|
60 |
lemma append_length_n [rulify]:
|
9580
|
61 |
"\<forall>n. n \<le> length x \<longrightarrow> (\<exists>a b. x = a@b \<and> length a = n)" (is "?P x")
|
9559
|
62 |
proof (induct "?P" "x")
|
|
63 |
show "?P []" by simp
|
|
64 |
|
|
65 |
fix l ls assume Cons: "?P ls"
|
|
66 |
|
|
67 |
show "?P (l#ls)"
|
|
68 |
proof (intro allI impI)
|
|
69 |
fix n
|
9580
|
70 |
assume l: "n \<le> length (l # ls)"
|
9559
|
71 |
|
9580
|
72 |
show "\<exists>a b. l # ls = a @ b \<and> length a = n"
|
9559
|
73 |
proof (cases n)
|
|
74 |
assume "n=0" thus ?thesis by simp
|
|
75 |
next
|
|
76 |
fix "n'" assume s: "n = Suc n'"
|
|
77 |
with l
|
9580
|
78 |
have "n' \<le> length ls" by simp
|
|
79 |
hence "\<exists>a b. ls = a @ b \<and> length a = n'" by (rule Cons [rulify])
|
9559
|
80 |
thus ?thesis
|
|
81 |
proof elim
|
|
82 |
fix a b
|
|
83 |
assume "ls = a @ b" "length a = n'"
|
|
84 |
with s
|
9580
|
85 |
have "l # ls = (l#a) @ b \<and> length (l#a) = n" by simp
|
9559
|
86 |
thus ?thesis by blast
|
|
87 |
qed
|
|
88 |
qed
|
|
89 |
qed
|
|
90 |
qed
|
|
91 |
|
|
92 |
|
|
93 |
|
|
94 |
lemma rev_append_cons:
|
9580
|
95 |
"\<lbrakk>n < length x\<rbrakk> \<Longrightarrow> \<exists>a b c. x = (rev a) @ b # c \<and> length a = n"
|
9559
|
96 |
proof -
|
|
97 |
assume n: "n < length x"
|
9580
|
98 |
hence "n \<le> length x" by simp
|
|
99 |
hence "\<exists>a b. x = a @ b \<and> length a = n" by (rule append_length_n)
|
9559
|
100 |
thus ?thesis
|
|
101 |
proof elim
|
|
102 |
fix r d assume x: "x = r@d" "length r = n"
|
|
103 |
with n
|
9580
|
104 |
have "\<exists>b c. d = b#c" by (simp add: neq_Nil_conv)
|
9559
|
105 |
|
|
106 |
thus ?thesis
|
|
107 |
proof elim
|
|
108 |
fix b c
|
|
109 |
assume "d = b#c"
|
|
110 |
with x
|
9580
|
111 |
have "x = (rev (rev r)) @ b # c \<and> length (rev r) = n" by simp
|
9559
|
112 |
thus ?thesis by blast
|
|
113 |
qed
|
|
114 |
qed
|
|
115 |
qed
|
|
116 |
|
|
117 |
|
|
118 |
lemma app_mono:
|
9580
|
119 |
"\<lbrakk>G \<turnstile> s2 <=s s1; app (i, G, rT, s1)\<rbrakk> \<Longrightarrow> app (i, G, rT, s2)";
|
9559
|
120 |
proof -
|
9580
|
121 |
assume G: "G \<turnstile> s2 <=s s1"
|
9559
|
122 |
assume app: "app (i, G, rT, s1)"
|
|
123 |
|
|
124 |
show ?thesis
|
|
125 |
proof (cases i)
|
|
126 |
case Load
|
|
127 |
|
|
128 |
from G
|
|
129 |
have l: "length (snd s1) = length (snd s2)" by (simp add: sup_state_length)
|
|
130 |
|
|
131 |
from G Load app
|
9580
|
132 |
have "G \<turnstile> snd s2 <=l snd s1" by (auto simp add: sup_state_def)
|
9559
|
133 |
|
|
134 |
with G Load app l
|
|
135 |
show ?thesis by clarsimp (drule sup_loc_some, simp+)
|
|
136 |
next
|
|
137 |
case Store
|
|
138 |
with G app
|
|
139 |
show ?thesis
|
|
140 |
by - (cases s2,
|
9594
|
141 |
auto simp add: map_eq_Cons sup_loc_Cons2 sup_loc_length sup_state_def)
|
9559
|
142 |
next
|
|
143 |
case Bipush
|
|
144 |
thus ?thesis by simp
|
|
145 |
next
|
|
146 |
case Aconst_null
|
|
147 |
thus ?thesis by simp
|
|
148 |
next
|
|
149 |
case New
|
|
150 |
with app
|
|
151 |
show ?thesis by simp
|
|
152 |
next
|
|
153 |
case Getfield
|
|
154 |
with app G
|
|
155 |
show ?thesis
|
|
156 |
by - (cases s2, clarsimp simp add: sup_state_Cons2, rule widen_trans)
|
|
157 |
next
|
|
158 |
case Putfield
|
|
159 |
|
|
160 |
with app
|
|
161 |
obtain vT oT ST LT b
|
|
162 |
where s1: "s1 = (vT # oT # ST, LT)" and
|
|
163 |
"field (G, cname) vname = Some (cname, b)"
|
|
164 |
"is_class G cname" and
|
9580
|
165 |
oT: "G\<turnstile> oT\<preceq> (Class cname)" and
|
|
166 |
vT: "G\<turnstile> vT\<preceq> b"
|
9559
|
167 |
by simp (elim exE conjE, simp, rule that)
|
|
168 |
moreover
|
|
169 |
from s1 G
|
|
170 |
obtain vT' oT' ST' LT'
|
|
171 |
where s2: "s2 = (vT' # oT' # ST', LT')" and
|
9580
|
172 |
oT': "G\<turnstile> oT' \<preceq> oT" and
|
|
173 |
vT': "G\<turnstile> vT' \<preceq> vT"
|
9559
|
174 |
by - (cases s2, simp add: sup_state_Cons2, elim exE conjE, simp, rule that)
|
|
175 |
moreover
|
|
176 |
from vT' vT
|
9580
|
177 |
have "G \<turnstile> vT' \<preceq> b" by (rule widen_trans)
|
9559
|
178 |
moreover
|
|
179 |
from oT' oT
|
9580
|
180 |
have "G\<turnstile> oT' \<preceq> (Class cname)" by (rule widen_trans)
|
9559
|
181 |
ultimately
|
|
182 |
show ?thesis
|
|
183 |
by (auto simp add: Putfield)
|
|
184 |
next
|
|
185 |
case Checkcast
|
|
186 |
with app G
|
|
187 |
show ?thesis
|
9580
|
188 |
by - (cases s2, auto intro!: widen_RefT2 simp add: sup_state_Cons2)
|
9559
|
189 |
next
|
|
190 |
case Return
|
|
191 |
with app G
|
|
192 |
show ?thesis
|
9580
|
193 |
by - (cases s2, auto simp add: sup_state_Cons2, rule widen_trans)
|
9559
|
194 |
next
|
|
195 |
case Pop
|
|
196 |
with app G
|
|
197 |
show ?thesis
|
|
198 |
by - (cases s2, clarsimp simp add: sup_state_Cons2)
|
|
199 |
next
|
|
200 |
case Dup
|
|
201 |
with app G
|
|
202 |
show ?thesis
|
|
203 |
by - (cases s2, clarsimp simp add: sup_state_Cons2)
|
|
204 |
next
|
|
205 |
case Dup_x1
|
|
206 |
with app G
|
|
207 |
show ?thesis
|
|
208 |
by - (cases s2, clarsimp simp add: sup_state_Cons2)
|
|
209 |
next
|
|
210 |
case Dup_x2
|
|
211 |
with app G
|
|
212 |
show ?thesis
|
|
213 |
by - (cases s2, clarsimp simp add: sup_state_Cons2)
|
|
214 |
next
|
|
215 |
case Swap
|
|
216 |
with app G
|
|
217 |
show ?thesis
|
|
218 |
by - (cases s2, clarsimp simp add: sup_state_Cons2)
|
|
219 |
next
|
|
220 |
case IAdd
|
|
221 |
with app G
|
|
222 |
show ?thesis
|
|
223 |
by - (cases s2, auto simp add: sup_state_Cons2 PrimT_PrimT)
|
|
224 |
next
|
|
225 |
case Goto
|
|
226 |
with app
|
|
227 |
show ?thesis by simp
|
|
228 |
next
|
|
229 |
case Ifcmpeq
|
|
230 |
with app G
|
|
231 |
show ?thesis
|
|
232 |
by - (cases s2, auto simp add: sup_state_Cons2 PrimT_PrimT widen_RefT2)
|
|
233 |
next
|
|
234 |
case Invoke
|
|
235 |
|
|
236 |
with app
|
|
237 |
obtain apTs X ST LT where
|
|
238 |
s1: "s1 = (rev apTs @ X # ST, LT)" and
|
|
239 |
l: "length apTs = length list" and
|
9580
|
240 |
C: "G \<turnstile> X \<preceq> Class cname" and
|
|
241 |
w: "\<forall>x \<in> set (zip apTs list). x \<in> widen G" and
|
|
242 |
m: "method (G, cname) (mname, list) \<noteq> None"
|
9559
|
243 |
by (simp del: not_None_eq, elim exE conjE) (rule that)
|
|
244 |
|
|
245 |
obtain apTs' X' ST' LT' where
|
|
246 |
s2: "s2 = (rev apTs' @ X' # ST', LT')" and
|
|
247 |
l': "length apTs' = length list"
|
|
248 |
proof -
|
|
249 |
from l s1 G
|
|
250 |
have "length list < length (fst s2)"
|
|
251 |
by (simp add: sup_state_length)
|
9580
|
252 |
hence "\<exists>a b c. (fst s2) = rev a @ b # c \<and> length a = length list"
|
9559
|
253 |
by (rule rev_append_cons [rulify])
|
|
254 |
thus ?thesis
|
|
255 |
by - (cases s2, elim exE conjE, simp, rule that)
|
|
256 |
qed
|
|
257 |
|
|
258 |
from l l'
|
|
259 |
have "length (rev apTs') = length (rev apTs)" by simp
|
|
260 |
|
|
261 |
from this s1 s2 G
|
|
262 |
obtain
|
9580
|
263 |
G': "G \<turnstile> (apTs',LT') <=s (apTs,LT)" and
|
|
264 |
X : "G \<turnstile> X' \<preceq> X" and "G \<turnstile> (ST',LT') <=s (ST,LT)"
|
9559
|
265 |
by (simp add: sup_state_rev_fst sup_state_append_fst sup_state_Cons1);
|
|
266 |
|
|
267 |
with C
|
9580
|
268 |
have C': "G \<turnstile> X' \<preceq> Class cname"
|
9559
|
269 |
by - (rule widen_trans, auto)
|
|
270 |
|
|
271 |
from G'
|
9580
|
272 |
have "G \<turnstile> map Some apTs' <=l map Some apTs"
|
9559
|
273 |
by (simp add: sup_state_def)
|
|
274 |
also
|
|
275 |
from l w
|
9580
|
276 |
have "G \<turnstile> map Some apTs <=l map Some list"
|
9559
|
277 |
by (simp add: all_widen_is_sup_loc)
|
|
278 |
finally
|
9580
|
279 |
have "G \<turnstile> map Some apTs' <=l map Some list" .
|
9559
|
280 |
|
|
281 |
with l'
|
9580
|
282 |
have w': "\<forall>x \<in> set (zip apTs' list). x \<in> widen G"
|
9559
|
283 |
by (simp add: all_widen_is_sup_loc)
|
|
284 |
|
|
285 |
from Invoke s2 l' w' C' m
|
|
286 |
show ?thesis
|
|
287 |
by simp blast
|
|
288 |
qed
|
|
289 |
qed
|
|
290 |
|
|
291 |
|
|
292 |
lemma step_mono:
|
9580
|
293 |
"\<lbrakk>succs i pc \<noteq> {}; app (i,G,rT,s2); G \<turnstile> s1 <=s s2\<rbrakk> \<Longrightarrow>
|
|
294 |
G \<turnstile> the (step (i,G,s1)) <=s the (step (i,G,s2))"
|
9559
|
295 |
proof (cases s1, cases s2)
|
|
296 |
fix a1 b1 a2 b2
|
|
297 |
assume s: "s1 = (a1,b1)" "s2 = (a2,b2)"
|
9580
|
298 |
assume succs: "succs i pc \<noteq> {}"
|
9559
|
299 |
assume app2: "app (i,G,rT,s2)"
|
9580
|
300 |
assume G: "G \<turnstile> s1 <=s s2"
|
9559
|
301 |
|
|
302 |
from G app2
|
|
303 |
have app1: "app (i,G,rT,s1)" by (rule app_mono)
|
|
304 |
|
|
305 |
from app1 app2 succs
|
|
306 |
obtain a1' b1' a2' b2'
|
|
307 |
where step: "step (i,G,s1) = Some (a1',b1')" "step (i,G,s2) = Some (a2',b2')";
|
9580
|
308 |
by (auto dest!: app_step_some);
|
9559
|
309 |
|
9580
|
310 |
have "G \<turnstile> (a1',b1') <=s (a2',b2')"
|
9559
|
311 |
proof (cases i)
|
|
312 |
case Load
|
|
313 |
|
|
314 |
with s app1
|
|
315 |
obtain y where
|
|
316 |
y: "nat < length b1" "b1 ! nat = Some y" by clarsimp
|
|
317 |
|
|
318 |
from Load s app2
|
|
319 |
obtain y' where
|
|
320 |
y': "nat < length b2" "b2 ! nat = Some y'" by clarsimp
|
|
321 |
|
|
322 |
from G s
|
9580
|
323 |
have "G \<turnstile> b1 <=l b2" by (simp add: sup_state_def)
|
9559
|
324 |
|
|
325 |
with y y'
|
9580
|
326 |
have "G \<turnstile> y \<preceq> y'"
|
9559
|
327 |
by - (drule sup_loc_some, simp+)
|
|
328 |
|
|
329 |
with Load G y y' s step app1 app2
|
|
330 |
show ?thesis by (clarsimp simp add: sup_state_def)
|
|
331 |
next
|
|
332 |
case Store
|
|
333 |
with G s step app1 app2
|
|
334 |
show ?thesis
|
|
335 |
by (clarsimp simp add: sup_state_def sup_loc_update)
|
|
336 |
next
|
|
337 |
case Bipush
|
|
338 |
with G s step app1 app2
|
|
339 |
show ?thesis
|
|
340 |
by (clarsimp simp add: sup_state_Cons1)
|
|
341 |
next
|
|
342 |
case New
|
|
343 |
with G s step app1 app2
|
|
344 |
show ?thesis
|
|
345 |
by (clarsimp simp add: sup_state_Cons1)
|
|
346 |
next
|
|
347 |
case Aconst_null
|
|
348 |
with G s step app1 app2
|
|
349 |
show ?thesis
|
|
350 |
by (clarsimp simp add: sup_state_Cons1)
|
|
351 |
next
|
|
352 |
case Getfield
|
|
353 |
with G s step app1 app2
|
|
354 |
show ?thesis
|
|
355 |
by (clarsimp simp add: sup_state_Cons1)
|
|
356 |
next
|
|
357 |
case Putfield
|
|
358 |
with G s step app1 app2
|
|
359 |
show ?thesis
|
|
360 |
by (clarsimp simp add: sup_state_Cons1)
|
|
361 |
next
|
|
362 |
case Checkcast
|
|
363 |
with G s step app1 app2
|
|
364 |
show ?thesis
|
|
365 |
by (clarsimp simp add: sup_state_Cons1)
|
|
366 |
next
|
|
367 |
case Invoke
|
|
368 |
|
|
369 |
with s app1
|
|
370 |
obtain a X ST where
|
|
371 |
s1: "s1 = (a @ X # ST, b1)" and
|
|
372 |
l: "length a = length list"
|
|
373 |
by (simp, elim exE conjE, simp)
|
|
374 |
|
|
375 |
from Invoke s app2
|
|
376 |
obtain a' X' ST' where
|
|
377 |
s2: "s2 = (a' @ X' # ST', b2)" and
|
|
378 |
l': "length a' = length list"
|
|
379 |
by (simp, elim exE conjE, simp)
|
|
380 |
|
|
381 |
from l l'
|
|
382 |
have lr: "length a = length a'" by simp
|
|
383 |
|
|
384 |
from lr G s s1 s2
|
9580
|
385 |
have "G \<turnstile> (ST, b1) <=s (ST', b2)"
|
9559
|
386 |
by (simp add: sup_state_append_fst sup_state_Cons1)
|
|
387 |
|
|
388 |
moreover
|
|
389 |
|
|
390 |
from Invoke G s step app1 app2
|
9580
|
391 |
have "b1 = b1' \<and> b2 = b2'" by simp
|
9559
|
392 |
|
|
393 |
ultimately
|
|
394 |
|
9580
|
395 |
have "G \<turnstile> (ST, b1') <=s (ST', b2')" by simp
|
9559
|
396 |
|
|
397 |
with Invoke G s step app1 app2 s1 s2 l l'
|
|
398 |
show ?thesis
|
|
399 |
by (clarsimp simp add: sup_state_def)
|
|
400 |
next
|
|
401 |
case Return
|
|
402 |
with succs have "False" by simp
|
|
403 |
thus ?thesis by blast
|
|
404 |
next
|
|
405 |
case Pop
|
|
406 |
with G s step app1 app2
|
|
407 |
show ?thesis
|
|
408 |
by (clarsimp simp add: sup_state_Cons1)
|
|
409 |
next
|
|
410 |
case Dup
|
|
411 |
with G s step app1 app2
|
|
412 |
show ?thesis
|
|
413 |
by (clarsimp simp add: sup_state_Cons1)
|
|
414 |
next
|
|
415 |
case Dup_x1
|
|
416 |
with G s step app1 app2
|
|
417 |
show ?thesis
|
|
418 |
by (clarsimp simp add: sup_state_Cons1)
|
|
419 |
next
|
|
420 |
case Dup_x2
|
|
421 |
with G s step app1 app2
|
|
422 |
show ?thesis
|
|
423 |
by (clarsimp simp add: sup_state_Cons1)
|
|
424 |
next
|
|
425 |
case Swap
|
|
426 |
with G s step app1 app2
|
|
427 |
show ?thesis
|
|
428 |
by (clarsimp simp add: sup_state_Cons1)
|
|
429 |
next
|
|
430 |
case IAdd
|
|
431 |
with G s step app1 app2
|
|
432 |
show ?thesis
|
|
433 |
by (clarsimp simp add: sup_state_Cons1)
|
|
434 |
next
|
|
435 |
case Goto
|
|
436 |
with G s step app1 app2
|
|
437 |
show ?thesis by simp
|
|
438 |
next
|
|
439 |
case Ifcmpeq
|
|
440 |
with G s step app1 app2
|
|
441 |
show ?thesis
|
|
442 |
by (clarsimp simp add: sup_state_Cons1)
|
|
443 |
qed
|
|
444 |
|
|
445 |
with step
|
|
446 |
show ?thesis by auto
|
|
447 |
qed
|
|
448 |
|
|
449 |
|
|
450 |
|
|
451 |
end
|