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