8011
|
1 |
(* Title: HOL/MicroJava/BV/Convert.thy
|
|
2 |
ID: $Id$
|
|
3 |
Author: Cornelia Pusch
|
|
4 |
Copyright 1999 Technische Universitaet Muenchen
|
|
5 |
|
|
6 |
The supertype relation lifted to type options, type lists and state types.
|
|
7 |
*)
|
|
8 |
|
9594
|
9 |
theory Convert = JVMExec:
|
8011
|
10 |
|
|
11 |
types
|
9594
|
12 |
locvars_type = "ty option list"
|
|
13 |
opstack_type = "ty list"
|
|
14 |
state_type = "opstack_type \<times> locvars_type"
|
8011
|
15 |
|
|
16 |
constdefs
|
|
17 |
|
9594
|
18 |
(* lifts a relation to option with None as top element *)
|
|
19 |
lift_top :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> ('a option \<Rightarrow> 'a option \<Rightarrow> bool)"
|
|
20 |
"lift_top P a' a \<equiv> case a of
|
|
21 |
None \<Rightarrow> True
|
|
22 |
| Some t \<Rightarrow> (case a' of None \<Rightarrow> False | Some t' \<Rightarrow> P t' t)"
|
|
23 |
|
|
24 |
|
|
25 |
sup_ty_opt :: "['code prog,ty option,ty option] \<Rightarrow> bool" ("_ \<turnstile>_ <=o _")
|
|
26 |
"sup_ty_opt G \<equiv> lift_top (\<lambda>t t'. G \<turnstile> t \<preceq> t')"
|
|
27 |
|
|
28 |
sup_loc :: "['code prog,locvars_type,locvars_type] \<Rightarrow> bool" ("_ \<turnstile> _ <=l _" [71,71] 70)
|
|
29 |
"G \<turnstile> LT <=l LT' \<equiv> list_all2 (\<lambda>t t'. (G \<turnstile> t <=o t')) LT LT'"
|
|
30 |
|
|
31 |
sup_state :: "['code prog,state_type,state_type] \<Rightarrow> bool" ("_ \<turnstile> _ <=s _" [71,71] 70)
|
|
32 |
"G \<turnstile> s <=s s' \<equiv> (G \<turnstile> map Some (fst s) <=l map Some (fst s')) \<and> G \<turnstile> snd s <=l snd s'"
|
|
33 |
|
|
34 |
|
|
35 |
lemma lift_top_refl [simp]:
|
|
36 |
"[| !!x. P x x |] ==> lift_top P x x"
|
|
37 |
by (simp add: lift_top_def split: option.splits)
|
|
38 |
|
|
39 |
lemma lift_top_trans [trans]:
|
|
40 |
"[| !!x y z. [| P x y; P y z |] ==> P x z; lift_top P x y; lift_top P y z |] ==> lift_top P x z"
|
|
41 |
proof -
|
|
42 |
assume [trans]: "!!x y z. [| P x y; P y z |] ==> P x z"
|
|
43 |
assume a: "lift_top P x y"
|
|
44 |
assume b: "lift_top P y z"
|
|
45 |
|
|
46 |
{ assume "z = None"
|
|
47 |
hence ?thesis by (simp add: lift_top_def)
|
|
48 |
} note z_none = this
|
|
49 |
|
|
50 |
{ assume "x = None"
|
|
51 |
with a b
|
|
52 |
have ?thesis
|
|
53 |
by (simp add: lift_top_def split: option.splits)
|
|
54 |
} note x_none = this
|
|
55 |
|
|
56 |
{ fix r t
|
|
57 |
assume x: "x = Some r" and z: "z = Some t"
|
|
58 |
with a b
|
|
59 |
obtain s where y: "y = Some s"
|
|
60 |
by (simp add: lift_top_def split: option.splits)
|
|
61 |
|
|
62 |
from a x y
|
|
63 |
have "P r s" by (simp add: lift_top_def)
|
|
64 |
also
|
|
65 |
from b y z
|
|
66 |
have "P s t" by (simp add: lift_top_def)
|
|
67 |
finally
|
|
68 |
have "P r t" .
|
|
69 |
|
|
70 |
with x z
|
|
71 |
have ?thesis by (simp add: lift_top_def)
|
|
72 |
}
|
|
73 |
|
|
74 |
with x_none z_none
|
|
75 |
show ?thesis by blast
|
|
76 |
qed
|
|
77 |
|
|
78 |
lemma lift_top_None_any [simp]:
|
|
79 |
"lift_top P None any = (any = None)"
|
|
80 |
by (simp add: lift_top_def split: option.splits)
|
|
81 |
|
|
82 |
lemma lift_top_Some_Some [simp]:
|
|
83 |
"lift_top P (Some a) (Some b) = P a b"
|
|
84 |
by (simp add: lift_top_def split: option.splits)
|
|
85 |
|
|
86 |
lemma lift_top_any_Some [simp]:
|
|
87 |
"lift_top P any (Some b) = (\<exists>a. any = Some a \<and> P a b)"
|
|
88 |
by (simp add: lift_top_def split: option.splits)
|
|
89 |
|
|
90 |
lemma lift_top_Some_any:
|
|
91 |
"lift_top P (Some a) any = (any = None \<or> (\<exists>b. any = Some b \<and> P a b))"
|
|
92 |
by (simp add: lift_top_def split: option.splits)
|
|
93 |
|
|
94 |
|
|
95 |
|
|
96 |
theorem sup_ty_opt_refl [simp]:
|
|
97 |
"G \<turnstile> t <=o t"
|
|
98 |
by (simp add: sup_ty_opt_def)
|
|
99 |
|
|
100 |
theorem sup_loc_refl [simp]:
|
|
101 |
"G \<turnstile> t <=l t"
|
|
102 |
by (induct t, auto simp add: sup_loc_def)
|
|
103 |
|
|
104 |
theorem sup_state_refl [simp]:
|
|
105 |
"G \<turnstile> s <=s s"
|
|
106 |
by (simp add: sup_state_def)
|
|
107 |
|
|
108 |
|
|
109 |
|
|
110 |
theorem anyConvNone [simp]:
|
|
111 |
"(G \<turnstile> None <=o any) = (any = None)"
|
|
112 |
by (simp add: sup_ty_opt_def)
|
|
113 |
|
|
114 |
theorem SomeanyConvSome [simp]:
|
|
115 |
"(G \<turnstile> (Some ty') <=o (Some ty)) = (G \<turnstile> ty' \<preceq> ty)"
|
|
116 |
by (simp add: sup_ty_opt_def)
|
|
117 |
|
|
118 |
theorem sup_ty_opt_Some:
|
|
119 |
"G \<turnstile> a <=o (Some b) \<Longrightarrow> \<exists> x. a = Some x"
|
|
120 |
by (clarsimp simp add: sup_ty_opt_def)
|
|
121 |
|
|
122 |
lemma widen_PrimT_conv1 [simp]:
|
|
123 |
"[| G \<turnstile> S \<preceq> T; S = PrimT x|] ==> T = PrimT x"
|
|
124 |
by (auto elim: widen.elims)
|
|
125 |
|
|
126 |
theorem sup_PTS_eq:
|
|
127 |
"(G \<turnstile> Some (PrimT p) <=o X) = (X=None \<or> X = Some (PrimT p))"
|
|
128 |
by (auto simp add: sup_ty_opt_def lift_top_Some_any)
|
|
129 |
|
|
130 |
|
|
131 |
|
|
132 |
theorem sup_loc_Nil [iff]:
|
|
133 |
"(G \<turnstile> [] <=l XT) = (XT=[])"
|
|
134 |
by (simp add: sup_loc_def)
|
|
135 |
|
|
136 |
theorem sup_loc_Cons [iff]:
|
|
137 |
"(G \<turnstile> (Y#YT) <=l XT) = (\<exists>X XT'. XT=X#XT' \<and> (G \<turnstile> Y <=o X) \<and> (G \<turnstile> YT <=l XT'))"
|
|
138 |
by (simp add: sup_loc_def list_all2_Cons1)
|
|
139 |
|
|
140 |
theorem sup_loc_Cons2:
|
|
141 |
"(G \<turnstile> YT <=l (X#XT)) = (\<exists>Y YT'. YT=Y#YT' \<and> (G \<turnstile> Y <=o X) \<and> (G \<turnstile> YT' <=l XT))";
|
|
142 |
by (simp add: sup_loc_def list_all2_Cons2)
|
|
143 |
|
|
144 |
|
|
145 |
theorem sup_loc_length:
|
|
146 |
"G \<turnstile> a <=l b \<Longrightarrow> length a = length b"
|
|
147 |
proof -
|
|
148 |
assume G: "G \<turnstile> a <=l b"
|
|
149 |
have "\<forall> b. (G \<turnstile> a <=l b) \<longrightarrow> length a = length b"
|
|
150 |
by (induct a, auto)
|
|
151 |
with G
|
|
152 |
show ?thesis by blast
|
|
153 |
qed
|
|
154 |
|
|
155 |
theorem sup_loc_nth:
|
|
156 |
"[| G \<turnstile> a <=l b; n < length a |] ==> G \<turnstile> (a!n) <=o (b!n)"
|
|
157 |
proof -
|
|
158 |
assume a: "G \<turnstile> a <=l b" "n < length a"
|
|
159 |
have "\<forall> n b. (G \<turnstile> a <=l b) \<longrightarrow> n < length a \<longrightarrow> (G \<turnstile> (a!n) <=o (b!n))"
|
|
160 |
(is "?P a")
|
|
161 |
proof (induct a)
|
|
162 |
show "?P []" by simp
|
|
163 |
|
|
164 |
fix x xs assume IH: "?P xs"
|
|
165 |
|
|
166 |
show "?P (x#xs)"
|
|
167 |
proof (intro strip)
|
|
168 |
fix n b
|
|
169 |
assume "G \<turnstile> (x # xs) <=l b" "n < length (x # xs)"
|
|
170 |
with IH
|
|
171 |
show "G \<turnstile> ((x # xs) ! n) <=o (b ! n)"
|
|
172 |
by - (cases n, auto)
|
|
173 |
qed
|
|
174 |
qed
|
|
175 |
with a
|
|
176 |
show ?thesis by blast
|
|
177 |
qed
|
|
178 |
|
|
179 |
|
|
180 |
theorem all_nth_sup_loc:
|
|
181 |
"\<forall>b. length a = length b \<longrightarrow> (\<forall> n. n < length a \<longrightarrow> (G \<turnstile> (a!n) <=o (b!n))) \<longrightarrow> (G \<turnstile> a <=l b)"
|
|
182 |
(is "?P a")
|
|
183 |
proof (induct a)
|
|
184 |
show "?P []" by simp
|
8011
|
185 |
|
9594
|
186 |
fix l ls assume IH: "?P ls"
|
|
187 |
|
|
188 |
show "?P (l#ls)"
|
|
189 |
proof (intro strip)
|
|
190 |
fix b
|
|
191 |
assume f: "\<forall>n. n < length (l # ls) \<longrightarrow> (G \<turnstile> ((l # ls) ! n) <=o (b ! n))"
|
|
192 |
assume l: "length (l#ls) = length b"
|
|
193 |
|
|
194 |
then obtain b' bs where b: "b = b'#bs"
|
|
195 |
by - (cases b, simp, simp add: neq_Nil_conv, rule that)
|
|
196 |
|
|
197 |
with f
|
|
198 |
have "\<forall>n. n < length ls \<longrightarrow> (G \<turnstile> (ls!n) <=o (bs!n))"
|
|
199 |
by auto
|
|
200 |
|
|
201 |
with f b l IH
|
|
202 |
show "G \<turnstile> (l # ls) <=l b"
|
|
203 |
by auto
|
|
204 |
qed
|
|
205 |
qed
|
|
206 |
|
|
207 |
|
|
208 |
theorem sup_loc_append:
|
|
209 |
"[| length a = length b |] ==> (G \<turnstile> (a@x) <=l (b@y)) = ((G \<turnstile> a <=l b) \<and> (G \<turnstile> x <=l y))"
|
|
210 |
proof -
|
|
211 |
assume l: "length a = length b"
|
|
212 |
|
|
213 |
have "\<forall>b. length a = length b \<longrightarrow> (G \<turnstile> (a@x) <=l (b@y)) = ((G \<turnstile> a <=l b) \<and> (G \<turnstile> x <=l y))"
|
|
214 |
(is "?P a")
|
|
215 |
proof (induct a)
|
|
216 |
show "?P []" by simp
|
|
217 |
|
|
218 |
fix l ls assume IH: "?P ls"
|
|
219 |
show "?P (l#ls)"
|
|
220 |
proof (intro strip)
|
|
221 |
fix b
|
|
222 |
assume "length (l#ls) = length (b::ty option list)"
|
|
223 |
with IH
|
|
224 |
show "(G \<turnstile> ((l#ls)@x) <=l (b@y)) = ((G \<turnstile> (l#ls) <=l b) \<and> (G \<turnstile> x <=l y))"
|
|
225 |
by - (cases b, auto)
|
|
226 |
qed
|
|
227 |
qed
|
|
228 |
with l
|
|
229 |
show ?thesis by blast
|
|
230 |
qed
|
|
231 |
|
|
232 |
theorem sup_loc_rev [simp]:
|
|
233 |
"(G \<turnstile> (rev a) <=l rev b) = (G \<turnstile> a <=l b)"
|
|
234 |
proof -
|
|
235 |
have "\<forall>b. (G \<turnstile> (rev a) <=l rev b) = (G \<turnstile> a <=l b)" (is "\<forall>b. ?Q a b" is "?P a")
|
|
236 |
proof (induct a)
|
|
237 |
show "?P []" by simp
|
|
238 |
|
|
239 |
fix l ls assume IH: "?P ls"
|
|
240 |
|
|
241 |
{
|
|
242 |
fix b
|
|
243 |
have "?Q (l#ls) b"
|
9664
|
244 |
proof (cases (open) b)
|
9594
|
245 |
case Nil
|
|
246 |
thus ?thesis by (auto dest: sup_loc_length)
|
|
247 |
next
|
|
248 |
case Cons
|
|
249 |
show ?thesis
|
|
250 |
proof
|
|
251 |
assume "G \<turnstile> (l # ls) <=l b"
|
|
252 |
thus "G \<turnstile> rev (l # ls) <=l rev b"
|
|
253 |
by (clarsimp simp add: Cons IH sup_loc_length sup_loc_append)
|
|
254 |
next
|
|
255 |
assume "G \<turnstile> rev (l # ls) <=l rev b"
|
|
256 |
hence G: "G \<turnstile> (rev ls @ [l]) <=l (rev list @ [a])"
|
|
257 |
by (simp add: Cons)
|
|
258 |
|
|
259 |
hence "length (rev ls) = length (rev list)"
|
|
260 |
by (auto dest: sup_loc_length)
|
|
261 |
|
|
262 |
from this G
|
|
263 |
obtain "G \<turnstile> rev ls <=l rev list" "G \<turnstile> l <=o a"
|
|
264 |
by (simp add: sup_loc_append)
|
|
265 |
|
|
266 |
thus "G \<turnstile> (l # ls) <=l b"
|
|
267 |
by (simp add: Cons IH)
|
|
268 |
qed
|
|
269 |
qed
|
|
270 |
}
|
|
271 |
thus "?P (l#ls)" by blast
|
|
272 |
qed
|
8011
|
273 |
|
9594
|
274 |
thus ?thesis by blast
|
|
275 |
qed
|
|
276 |
|
|
277 |
|
|
278 |
theorem sup_loc_update [rulify]:
|
|
279 |
"\<forall> n y. (G \<turnstile> a <=o b) \<longrightarrow> n < length y \<longrightarrow> (G \<turnstile> x <=l y) \<longrightarrow> (G \<turnstile> x[n := a] <=l y[n := b])"
|
|
280 |
(is "?P x")
|
|
281 |
proof (induct x)
|
|
282 |
show "?P []" by simp
|
|
283 |
|
|
284 |
fix l ls assume IH: "?P ls"
|
|
285 |
show "?P (l#ls)"
|
|
286 |
proof (intro strip)
|
|
287 |
fix n y
|
|
288 |
assume "G \<turnstile>a <=o b" "G \<turnstile> (l # ls) <=l y" "n < length y"
|
|
289 |
with IH
|
|
290 |
show "G \<turnstile> (l # ls)[n := a] <=l y[n := b]"
|
|
291 |
by - (cases n, auto simp add: sup_loc_Cons2 list_all2_Cons1)
|
|
292 |
qed
|
|
293 |
qed
|
|
294 |
|
|
295 |
|
|
296 |
theorem sup_state_length [simp]:
|
|
297 |
"G \<turnstile> s2 <=s s1 \<Longrightarrow> length (fst s2) = length (fst s1) \<and> length (snd s2) = length (snd s1)"
|
|
298 |
by (auto dest: sup_loc_length simp add: sup_state_def);
|
|
299 |
|
|
300 |
theorem sup_state_append_snd:
|
|
301 |
"length a = length b \<Longrightarrow> (G \<turnstile> (i,a@x) <=s (j,b@y)) = ((G \<turnstile> (i,a) <=s (j,b)) \<and> (G \<turnstile> (i,x) <=s (j,y)))"
|
|
302 |
by (auto simp add: sup_state_def sup_loc_append)
|
|
303 |
|
|
304 |
theorem sup_state_append_fst:
|
|
305 |
"length a = length b \<Longrightarrow> (G \<turnstile> (a@x,i) <=s (b@y,j)) = ((G \<turnstile> (a,i) <=s (b,j)) \<and> (G \<turnstile> (x,i) <=s (y,j)))"
|
|
306 |
by (auto simp add: sup_state_def sup_loc_append)
|
|
307 |
|
|
308 |
theorem sup_state_Cons1:
|
|
309 |
"(G \<turnstile> (x#xt, a) <=s (yt, b)) = (\<exists>y yt'. yt=y#yt' \<and> (G \<turnstile> x \<preceq> y) \<and> (G \<turnstile> (xt,a) <=s (yt',b)))"
|
|
310 |
by (auto simp add: sup_state_def map_eq_Cons)
|
|
311 |
|
|
312 |
theorem sup_state_Cons2:
|
|
313 |
"(G \<turnstile> (xt, a) <=s (y#yt, b)) = (\<exists>x xt'. xt=x#xt' \<and> (G \<turnstile> x \<preceq> y) \<and> (G \<turnstile> (xt',a) <=s (yt,b)))"
|
|
314 |
by (auto simp add: sup_state_def map_eq_Cons sup_loc_Cons2)
|
|
315 |
|
|
316 |
theorem sup_state_ignore_fst:
|
|
317 |
"G \<turnstile> (a, x) <=s (b, y) \<Longrightarrow> G \<turnstile> (c, x) <=s (c, y)"
|
|
318 |
by (simp add: sup_state_def)
|
|
319 |
|
|
320 |
theorem sup_state_rev_fst:
|
|
321 |
"(G \<turnstile> (rev a, x) <=s (rev b, y)) = (G \<turnstile> (a, x) <=s (b, y))"
|
|
322 |
proof -
|
|
323 |
have m: "!!f x. map f (rev x) = rev (map f x)" by (simp add: rev_map)
|
|
324 |
show ?thesis by (simp add: m sup_state_def)
|
|
325 |
qed
|
|
326 |
|
|
327 |
theorem sup_ty_opt_trans [trans]:
|
|
328 |
"\<lbrakk>G \<turnstile> a <=o b; G \<turnstile> b <=o c\<rbrakk> \<Longrightarrow> G \<turnstile> a <=o c"
|
|
329 |
by (auto intro: lift_top_trans widen_trans simp add: sup_ty_opt_def)
|
|
330 |
|
|
331 |
|
|
332 |
theorem sup_loc_trans [trans]:
|
|
333 |
"\<lbrakk>G \<turnstile> a <=l b; G \<turnstile> b <=l c\<rbrakk> \<Longrightarrow> G \<turnstile> a <=l c"
|
|
334 |
proof -
|
|
335 |
assume G: "G \<turnstile> a <=l b" "G \<turnstile> b <=l c"
|
|
336 |
|
|
337 |
hence "\<forall> n. n < length a \<longrightarrow> (G \<turnstile> (a!n) <=o (c!n))"
|
|
338 |
proof (intro strip)
|
|
339 |
fix n
|
|
340 |
assume n: "n < length a"
|
|
341 |
with G
|
|
342 |
have "G \<turnstile> (a!n) <=o (b!n)"
|
|
343 |
by - (rule sup_loc_nth)
|
|
344 |
also
|
|
345 |
from n G
|
|
346 |
have "G \<turnstile> ... <=o (c!n)"
|
|
347 |
by - (rule sup_loc_nth, auto dest: sup_loc_length)
|
|
348 |
finally
|
|
349 |
show "G \<turnstile> (a!n) <=o (c!n)" .
|
|
350 |
qed
|
|
351 |
|
|
352 |
with G
|
|
353 |
show ?thesis
|
|
354 |
by (auto intro!: all_nth_sup_loc [rulify] dest!: sup_loc_length)
|
|
355 |
qed
|
|
356 |
|
|
357 |
|
|
358 |
theorem sup_state_trans [trans]:
|
|
359 |
"\<lbrakk>G \<turnstile> a <=s b; G \<turnstile> b <=s c\<rbrakk> \<Longrightarrow> G \<turnstile> a <=s c"
|
|
360 |
by (auto intro: sup_loc_trans simp add: sup_state_def)
|
8011
|
361 |
|
|
362 |
end
|