8245
|
1 |
(* Title: HOL/MicroJava/BV/BVLcorrect.thy
|
|
2 |
ID: $Id$
|
|
3 |
Author: Gerwin Klein
|
|
4 |
Copyright 1999 Technische Universitaet Muenchen
|
9054
|
5 |
*)
|
8245
|
6 |
|
9054
|
7 |
header {* Correctness of the LBV *}
|
8245
|
8 |
|
9012
|
9 |
theory LBVCorrect = LBVSpec:;
|
8245
|
10 |
|
|
11 |
constdefs
|
|
12 |
fits_partial :: "[method_type,nat,instr list,jvm_prog,ty,state_type,state_type,certificate] \\<Rightarrow> bool"
|
|
13 |
"fits_partial phi pc is G rT s0 s2 cert \\<equiv> (\\<forall> a b i s1. (a@(i#b) = is) \\<longrightarrow>
|
|
14 |
wtl_inst_list a G rT s0 s1 cert (pc+length is) pc \\<longrightarrow>
|
|
15 |
wtl_inst_list (i#b) G rT s1 s2 cert (pc+length is) (pc+length a) \\<longrightarrow>
|
8390
|
16 |
((cert!(pc+length a) = None \\<longrightarrow> phi!(pc+length a) = s1) \\<and>
|
|
17 |
(\\<forall> t. cert!(pc+length a) = Some t \\<longrightarrow> phi!(pc+length a) = t)))"
|
8245
|
18 |
|
9012
|
19 |
fits :: "[method_type,instr list,jvm_prog,ty,state_type,state_type,certificate] \\<Rightarrow> bool"
|
|
20 |
"fits phi is G rT s0 s2 cert \\<equiv> fits_partial phi 0 is G rT s0 s2 cert";
|
|
21 |
|
|
22 |
lemma fitsD:
|
|
23 |
"fits phi is G rT s0 s2 cert \\<Longrightarrow>
|
|
24 |
(a@(i#b) = is) \\<Longrightarrow>
|
|
25 |
wtl_inst_list a G rT s0 s1 cert (0+length is) 0 \\<Longrightarrow>
|
|
26 |
wtl_inst_list (i#b) G rT s1 s2 cert (0+length is) (0+length a) \\<Longrightarrow>
|
|
27 |
((cert!(0+length a) = None \\<longrightarrow> phi!(0+length a) = s1) \\<and>
|
|
28 |
(\\<forall> t. cert!(0+length a) = Some t \\<longrightarrow> phi!(0+length a) = t))";
|
|
29 |
by (unfold fits_def fits_partial_def) blast;
|
|
30 |
|
|
31 |
lemma exists_list: "\\<exists>l. n < length l" (is "?Q n");
|
|
32 |
proof (induct "n");
|
|
33 |
fix n; assume "?Q n";
|
|
34 |
thus "?Q (Suc n)";
|
|
35 |
proof elim;
|
|
36 |
fix l; assume "n < length (l::'a list)";
|
|
37 |
hence "Suc n < length (a#l)"; by simp;
|
|
38 |
thus ?thesis; ..;
|
|
39 |
qed;
|
|
40 |
qed auto;
|
|
41 |
|
|
42 |
lemma exists_phi:
|
|
43 |
"wtl_inst_list is G rT s0 s2 cert (length is) 0 \\<Longrightarrow>
|
|
44 |
\\<exists> phi. fits phi is G rT s0 s2 cert \\<and> length is < length phi";
|
|
45 |
proof -;
|
|
46 |
assume all: "wtl_inst_list is G rT s0 s2 cert (length is) 0";
|
|
47 |
have "\\<forall> s0 pc. wtl_inst_list is G rT s0 s2 cert (pc+length is) pc
|
|
48 |
\\<longrightarrow> (\\<exists> phi. pc + length is < length phi \\<and> fits_partial phi pc is G rT s0 s2 cert)"
|
|
49 |
(is "?P is");
|
|
50 |
proof (induct "?P" "is");
|
|
51 |
case Nil;
|
|
52 |
show "?P []"; by (simp add: fits_partial_def exists_list);
|
|
53 |
case Cons;
|
|
54 |
show "?P (a#list)";
|
|
55 |
proof (intro allI impI);
|
|
56 |
fix s0 pc;
|
|
57 |
assume wtl: "wtl_inst_list (a # list) G rT s0 s2 cert (pc + length (a # list)) pc";
|
|
58 |
thus "\\<exists>phi. pc + length (a # list) < length phi \\<and>
|
|
59 |
fits_partial phi pc (a # list) G rT s0 s2 cert";
|
|
60 |
obtain s1 where
|
|
61 |
opt: "wtl_inst_option a G rT s0 s1 cert (Suc pc + length list) pc" and
|
|
62 |
wtlSuc: "wtl_inst_list list G rT s1 s2 cert (Suc pc + length list) (Suc pc)";
|
|
63 |
by auto;
|
|
64 |
with Cons;
|
|
65 |
show ?thesis;
|
|
66 |
obtain phi where fits: "fits_partial phi (Suc pc) list G rT s1 s2 cert"
|
|
67 |
and length: "(Suc pc) + length list < length phi"; by blast;
|
|
68 |
let "?A phi pc x s1'" =
|
|
69 |
"(cert ! (pc + length (x::instr list)) = None \\<longrightarrow> phi ! (pc + length x) = s1') \\<and>
|
|
70 |
(\\<forall>t. cert ! (pc + length x) = Some t \\<longrightarrow> phi ! (pc + length x) = t)";
|
|
71 |
show ?thesis;
|
|
72 |
proof (cases "cert!pc");
|
|
73 |
case None;
|
|
74 |
have "fits_partial (phi[pc:= s0]) pc (a # list) G rT s0 s2 cert";
|
|
75 |
proof (unfold fits_partial_def, intro allI impI);
|
|
76 |
fix x i y s1';
|
|
77 |
assume * :
|
|
78 |
"x @ i # y = a # list"
|
|
79 |
"wtl_inst_list x G rT s0 s1' cert (pc + length (a # list)) pc"
|
|
80 |
"wtl_inst_list (i # y) G rT s1' s2 cert (pc + length (a # list)) (pc + length x)";
|
|
81 |
show "?A (phi[pc:= s0]) pc x s1'";
|
|
82 |
proof (cases "x");
|
|
83 |
assume "x = []";
|
|
84 |
with * length None;
|
|
85 |
show ?thesis; by simp;
|
|
86 |
next;
|
|
87 |
fix b l; assume Cons: "x = b#l";
|
|
88 |
with fits *;
|
|
89 |
have "?A (phi[pc:= s0]) (Suc pc) l s1'";
|
|
90 |
proof (unfold fits_partial_def, elim allE impE);
|
|
91 |
from * Cons;
|
|
92 |
show "l @ i # y = list"; by simp;
|
|
93 |
from Cons opt *;
|
|
94 |
show "wtl_inst_list l G rT s1 s1' cert (Suc pc + length list) (Suc pc)";
|
|
95 |
by (simp, elim) (drule wtl_inst_option_unique, assumption, simp);
|
|
96 |
qed simp+;
|
|
97 |
with Cons length;
|
|
98 |
show ?thesis; by auto;
|
|
99 |
qed;
|
|
100 |
qed;
|
|
101 |
with length;
|
|
102 |
show ?thesis; by intro auto;
|
|
103 |
next;
|
|
104 |
fix c; assume Some: "cert!pc = Some c";
|
|
105 |
have "fits_partial (phi[pc:= c]) pc (a # list) G rT s0 s2 cert";
|
|
106 |
proof (unfold fits_partial_def, intro allI impI);
|
|
107 |
fix x i y s1';
|
|
108 |
assume * :
|
|
109 |
"x @ i # y = a # list"
|
|
110 |
"wtl_inst_list x G rT s0 s1' cert (pc + length (a # list)) pc"
|
|
111 |
"wtl_inst_list (i # y) G rT s1' s2 cert (pc + length (a # list)) (pc + length x)";
|
|
112 |
show "?A (phi[pc:= c]) pc x s1'";
|
|
113 |
proof (cases "x");
|
|
114 |
assume "x = []";
|
|
115 |
with length Some;
|
|
116 |
show ?thesis; by simp;
|
|
117 |
next;
|
|
118 |
fix b l; assume Cons: "x = b#l";
|
|
119 |
with fits *;
|
|
120 |
have "?A (phi[pc:= c]) (Suc pc) l s1'";
|
|
121 |
proof (unfold fits_partial_def, elim allE impE);
|
|
122 |
from * Cons;
|
|
123 |
show "l @ i # y = list"; by simp;
|
|
124 |
from Cons opt *;
|
|
125 |
show "wtl_inst_list l G rT s1 s1' cert (Suc pc + length list) (Suc pc)";
|
|
126 |
by (simp, elim) (drule wtl_inst_option_unique, assumption, simp);
|
|
127 |
qed simp+;
|
|
128 |
with Cons length;
|
|
129 |
show ?thesis; by auto;
|
|
130 |
qed;
|
|
131 |
qed;
|
|
132 |
with length;
|
|
133 |
show ?thesis; by intro auto;
|
|
134 |
qed;
|
|
135 |
qed;
|
|
136 |
qed;
|
|
137 |
qed;
|
|
138 |
qed;
|
|
139 |
with all;
|
|
140 |
show ?thesis;
|
9260
|
141 |
proof (elim exE allE impE conjE);
|
9012
|
142 |
show "wtl_inst_list is G rT s0 s2 cert (0+length is) 0"; by simp;
|
9260
|
143 |
qed (auto simp add: fits_def);
|
9012
|
144 |
qed;
|
|
145 |
|
|
146 |
|
|
147 |
lemma fits_lemma1:
|
|
148 |
"\\<lbrakk>wtl_inst_list is G rT s0 s3 cert (length is) 0; fits phi is G rT s0 s3 cert\\<rbrakk> \\<Longrightarrow>
|
|
149 |
\\<forall> pc t. pc < length is \\<longrightarrow> (cert ! pc) = Some t \\<longrightarrow> (phi ! pc) = t";
|
|
150 |
proof intro;
|
|
151 |
fix pc t;
|
|
152 |
assume wtl: "wtl_inst_list is G rT s0 s3 cert (length is) 0";
|
|
153 |
assume fits: "fits phi is G rT s0 s3 cert";
|
|
154 |
assume pc: "pc < length is";
|
|
155 |
assume cert: "cert ! pc = Some t";
|
|
156 |
from pc;
|
|
157 |
have "is \\<noteq> []"; by auto;
|
|
158 |
hence cons: "\\<exists>i y. is = i#y"; by (simp add: neq_Nil_conv);
|
|
159 |
from wtl pc;
|
|
160 |
have "\\<exists>a b s1. a@b = is \\<and> length a = pc \\<and>
|
|
161 |
wtl_inst_list a G rT s0 s1 cert (length is) 0 \\<and>
|
|
162 |
wtl_inst_list b G rT s1 s3 cert (length is) (0+length a)"
|
|
163 |
(is "\\<exists>a b s1. ?A a b \\<and> ?L a \\<and> ?W1 a s1 \\<and> ?W2 a b s1");
|
|
164 |
by (rule wtl_partial [rulify]);
|
|
165 |
with cons;
|
|
166 |
show "phi ! pc = t";
|
|
167 |
proof (elim exE conjE);
|
|
168 |
fix a b s1 i y;
|
|
169 |
assume * :"?A a b" "?L a" "?W1 a s1" "?W2 a b s1" "is = i#y";
|
|
170 |
with pc;
|
|
171 |
have "b \\<noteq> []"; by auto;
|
|
172 |
hence "\\<exists>b' bs. b = b'#bs"; by (simp add: neq_Nil_conv);
|
|
173 |
thus ?thesis;
|
|
174 |
proof (elim exE);
|
|
175 |
fix b' bs; assume Cons: "b=b'#bs";
|
|
176 |
with * fits cert;
|
|
177 |
show ?thesis;
|
|
178 |
proof (unfold fits_def fits_partial_def, elim allE impE);
|
|
179 |
from * Cons; show "a@b'#bs=is"; by simp;
|
|
180 |
qed simp+;
|
|
181 |
qed;
|
|
182 |
qed;
|
|
183 |
qed;
|
|
184 |
|
|
185 |
lemma fits_lemma2:
|
|
186 |
"\\<lbrakk>wtl_inst_list a G rT s0 s1 cert (length (a@i#b)) 0;
|
|
187 |
wtl_inst_option i G rT s1 s2 cert (length (a@i#b)) (length a);
|
|
188 |
fits phi (a@i#b) G rT s0 s3 cert; cert!(length a) = None;
|
|
189 |
wtl_inst_list b G rT s2 s3 cert (length (a@i#b)) (Suc (length a))\\<rbrakk>
|
|
190 |
\\<Longrightarrow> phi!(length a) = s1";
|
|
191 |
proof (unfold fits_def fits_partial_def, elim allE impE);
|
|
192 |
qed (auto simp del: split_paired_Ex);
|
|
193 |
|
|
194 |
|
|
195 |
|
|
196 |
lemma wtl_suc_pc:
|
|
197 |
"\\<lbrakk>wtl_inst_list a G rT s0 s1 cert (length (a@i#b)) 0;
|
|
198 |
wtl_inst_option i G rT s1 s2 cert (length (a@i#b)) (length a);
|
|
199 |
wtl_inst_list b G rT s2 s3 cert (length (a@i#b)) (Suc (length a));
|
|
200 |
fits phi (a@i#b) G rT s0 s3 cert \\<rbrakk> \\<Longrightarrow>
|
|
201 |
b \\<noteq> [] \\<longrightarrow> G \\<turnstile> s2 <=s (phi ! (Suc (length a)))";
|
|
202 |
proof;
|
|
203 |
assume f: "fits phi (a@i#b) G rT s0 s3 cert";
|
|
204 |
assume "wtl_inst_list a G rT s0 s1 cert (length (a@i#b)) 0"
|
|
205 |
"wtl_inst_option i G rT s1 s2 cert (length (a@i#b)) (length a)"
|
|
206 |
and w: "wtl_inst_list b G rT s2 s3 cert (length (a@i#b)) (Suc (length a))";
|
|
207 |
hence a: "wtl_inst_list (a@[i]) G rT s0 s2 cert (length (a@i#b)) 0"; by (rule wtl_append);
|
|
208 |
assume "b \\<noteq> []";
|
|
209 |
thus "G \\<turnstile> s2 <=s phi ! Suc (length a)";
|
|
210 |
obtain b' bs where Cons: "b = b' # bs"; by (simp add: neq_Nil_conv) (elim exE, rule that);
|
|
211 |
hence "(a@[i]) @ b' # bs = a @ i # b"; by simp;
|
|
212 |
with f;
|
|
213 |
show ?thesis;
|
|
214 |
proof (rule fitsD [elimify]);
|
|
215 |
from Cons w;
|
|
216 |
show "wtl_inst_list (b' # bs) G rT s2 s3 cert (0 + length (a @ i # b)) (0 + length (a @ [i]))";
|
|
217 |
by simp;
|
|
218 |
from a;
|
|
219 |
show "wtl_inst_list (a @ [i]) G rT s0 s2 cert (0 + length (a @ i # b)) 0"; by simp;
|
|
220 |
|
|
221 |
assume cert:
|
|
222 |
"(cert ! (0 + length (a @ [i])) = None \\<longrightarrow> phi ! (0 + length (a @ [i])) = s2) \\<and>
|
|
223 |
(\\<forall>t. cert ! (0 + length (a @ [i])) = Some t \\<longrightarrow> phi ! (0 + length (a @ [i])) = t)";
|
|
224 |
show ?thesis;
|
|
225 |
proof (cases "cert ! Suc (length a)");
|
|
226 |
assume "cert ! Suc (length a) = None";
|
|
227 |
with cert;
|
|
228 |
have "s2 = phi ! Suc (length a)"; by simp;
|
|
229 |
thus ?thesis; by simp;
|
|
230 |
next;
|
|
231 |
fix t; assume "cert ! Suc (length a) = Some t";
|
|
232 |
with cert;
|
|
233 |
have "phi ! Suc (length a) = t"; by (simp del: split_paired_All);
|
|
234 |
with cert Cons w;
|
|
235 |
show ?thesis; by (auto simp add: wtl_inst_option_def);
|
|
236 |
qed;
|
|
237 |
qed;
|
|
238 |
qed;
|
|
239 |
qed;
|
|
240 |
|
|
241 |
lemma wtl_lemma:
|
|
242 |
"\\<lbrakk>wtl_inst_list i1 G rT s0 s1 cert (length (i1@i#i2)) 0;
|
|
243 |
wtl_inst_option i G rT s1 s2 cert (length (i1@i#i2)) (length i1);
|
|
244 |
wtl_inst_list i2 G rT s2 s3 cert (length (i1@i#i2)) (Suc (length i1));
|
|
245 |
fits phi (i1@i#i2) G rT s0 s3 cert\\<rbrakk> \\<Longrightarrow>
|
|
246 |
wt_instr i G rT phi (length (i1@i#i2)) (length i1)" (concl is "?P i");
|
|
247 |
proof -;
|
|
248 |
assume w1: "wtl_inst_list i1 G rT s0 s1 cert (length (i1@i#i2)) 0" (is ?w1);
|
|
249 |
assume wo: "wtl_inst_option i G rT s1 s2 cert (length (i1@i#i2)) (length i1)";
|
|
250 |
assume w2: "wtl_inst_list i2 G rT s2 s3 cert (length (i1@i#i2)) (Suc (length i1))";
|
|
251 |
assume f: "fits phi (i1@i#i2) G rT s0 s3 cert";
|
|
252 |
|
|
253 |
from w1 wo w2;
|
|
254 |
have wtl: "wtl_inst_list (i1@i#i2) G rT s0 s3 cert (length (i1@i#i2)) 0";
|
|
255 |
by (rule wtl_cons_appendl);
|
|
256 |
|
|
257 |
with f;
|
|
258 |
have c1: "\\<forall>t. cert ! (length i1) = Some t \\<longrightarrow> phi ! (length i1) = t";
|
|
259 |
by intro (rule fits_lemma1 [rulify], auto);
|
|
260 |
|
|
261 |
from w1 wo w2 f;
|
|
262 |
have c2: "cert ! (length i1) = None \\<Longrightarrow> phi ! (length i1) = s1";
|
|
263 |
by - (rule fits_lemma2);
|
|
264 |
|
|
265 |
from wtl f;
|
|
266 |
have c3: "\\<forall>pc t. pc < length(i1@i#i2) \\<longrightarrow> cert ! pc = Some t \\<longrightarrow> phi ! pc = t";
|
|
267 |
by (rule fits_lemma1);
|
|
268 |
|
|
269 |
from w1 wo w2 f;
|
|
270 |
have suc: "i2 \\<noteq> [] \\<Longrightarrow> G \\<turnstile> s2 <=s phi ! Suc (length i1)";
|
|
271 |
by (rule wtl_suc_pc [rulify]);
|
|
272 |
|
|
273 |
show ?thesis;
|
|
274 |
proof (cases "i");
|
|
275 |
case LS;
|
|
276 |
with wo suc;
|
|
277 |
show ?thesis;
|
|
278 |
by - (cases "load_and_store",
|
|
279 |
(cases "cert ! (length i1)",
|
|
280 |
clarsimp_tac simp add: c2 wt_instr_def wtl_inst_option_def split_beta,
|
|
281 |
clarsimp_tac simp add: c1 wt_instr_def wtl_inst_option_def)+);
|
|
282 |
next;
|
|
283 |
case CO;
|
|
284 |
with wo suc;
|
|
285 |
show ?thesis;
|
|
286 |
by - (cases "create_object" ,
|
|
287 |
cases "cert ! (length i1)",
|
|
288 |
clarsimp_tac simp add: c2 wt_instr_def wtl_inst_option_def split_beta,
|
|
289 |
clarsimp_tac simp add: c1 wt_instr_def wtl_inst_option_def);
|
|
290 |
next;
|
|
291 |
case MO;
|
|
292 |
with wo suc;
|
|
293 |
show ?thesis;
|
|
294 |
by - (cases "manipulate_object" ,
|
|
295 |
(cases "cert ! (length i1)",
|
|
296 |
clarsimp_tac simp add: c2 wt_instr_def wtl_inst_option_def split_beta,
|
|
297 |
clarsimp_tac simp add: c1 wt_instr_def wtl_inst_option_def)+);
|
|
298 |
next;
|
|
299 |
case CH;
|
|
300 |
with wo suc;
|
|
301 |
show ?thesis;
|
|
302 |
by - (cases "check_object" , cases "cert ! (length i1)",
|
|
303 |
clarsimp_tac simp add: c2 wt_instr_def wtl_inst_option_def split_beta,
|
|
304 |
clarsimp_tac simp add: c1 wt_instr_def wtl_inst_option_def);
|
|
305 |
next;
|
|
306 |
case MI;
|
|
307 |
with wo suc;
|
|
308 |
show ?thesis;
|
|
309 |
by - (cases "meth_inv", cases "cert ! (length i1)",
|
|
310 |
clarsimp_tac simp add: c2 wt_instr_def wtl_inst_option_def split_beta,
|
|
311 |
intro exI conjI, rule refl, simp, force,
|
|
312 |
clarsimp_tac simp add: c1 wt_instr_def wtl_inst_option_def,
|
|
313 |
intro exI conjI, rule refl, simp, force);
|
|
314 |
next;
|
|
315 |
case MR;
|
|
316 |
with wo suc;
|
|
317 |
show ?thesis;
|
|
318 |
by - (cases "meth_ret" , cases "cert ! (length i1)",
|
|
319 |
clarsimp_tac simp add: c2 wt_instr_def wtl_inst_option_def split_beta,
|
|
320 |
clarsimp_tac simp add: c1 wt_instr_def wtl_inst_option_def);
|
|
321 |
next;
|
|
322 |
case OS;
|
|
323 |
with wo suc;
|
|
324 |
show ?thesis;
|
|
325 |
by - (cases "op_stack" ,
|
|
326 |
(cases "cert ! (length i1)",
|
|
327 |
clarsimp_tac simp add: c2 wt_instr_def wtl_inst_option_def split_beta,
|
|
328 |
clarsimp_tac simp add: c1 wt_instr_def wtl_inst_option_def)+);
|
|
329 |
next;
|
|
330 |
case BR;
|
|
331 |
with wo suc;
|
|
332 |
show ?thesis;
|
|
333 |
by - (cases "branch",
|
|
334 |
(cases "cert ! (length i1)",
|
|
335 |
clarsimp_tac simp add: c2 c3 wt_instr_def wtl_inst_option_def split_beta,
|
|
336 |
clarsimp_tac simp add: c1 c3 wt_instr_def wtl_inst_option_def)+);
|
|
337 |
qed;
|
|
338 |
qed;
|
|
339 |
|
|
340 |
lemma wtl_fits_wt:
|
|
341 |
"\\<lbrakk>wtl_inst_list is G rT s0 s3 cert (length is) 0; fits phi is G rT s0 s3 cert\\<rbrakk>
|
|
342 |
\\<Longrightarrow> \\<forall>pc. pc < length is \\<longrightarrow> wt_instr (is ! pc) G rT phi (length is) pc";
|
|
343 |
proof intro;
|
|
344 |
assume fits: "fits phi is G rT s0 s3 cert";
|
|
345 |
|
|
346 |
fix pc;
|
|
347 |
assume wtl: "wtl_inst_list is G rT s0 s3 cert (length is) 0"
|
|
348 |
and pc: "pc < length is";
|
|
349 |
|
|
350 |
thus "wt_instr (is ! pc) G rT phi (length is) pc";
|
|
351 |
obtain i1 i2' s1 where l: "i1 @ i2' = is" "length i1 = pc" and
|
|
352 |
w1: "wtl_inst_list i1 G rT s0 s1 cert (length is) 0" and
|
|
353 |
w2: "wtl_inst_list i2' G rT s1 s3 cert (length is) (0 + length i1)";
|
|
354 |
by (rule wtl_partial [rulify, elimify]) (elim, rule that);
|
|
355 |
from l pc;
|
|
356 |
have "i2' \\<noteq> []"; by auto;
|
|
357 |
thus ?thesis;
|
|
358 |
obtain i i2 where c: "i2' = i#i2"; by (simp add: neq_Nil_conv) (elim, rule that);
|
|
359 |
with w2 l;
|
|
360 |
show ?thesis;
|
|
361 |
obtain s2 where w3:
|
|
362 |
"wtl_inst_option i G rT s1 s2 cert (length (i1@i#i2)) (length i1)"
|
|
363 |
"wtl_inst_list i2 G rT s2 s3 cert (length (i1@i#i2)) (Suc (length i1))"; by auto;
|
|
364 |
|
|
365 |
from w1 l c;
|
|
366 |
have w4: "wtl_inst_list i1 G rT s0 s1 cert (length (i1 @ i # i2)) 0"; by simp;
|
|
367 |
|
|
368 |
from l c fits;
|
|
369 |
have "fits phi (i1@i#i2) G rT s0 s3 cert"; by simp;
|
|
370 |
with w4 w3;
|
|
371 |
have "wt_instr i G rT phi (length (i1@i#i2)) (length i1)"; by (rule wtl_lemma);
|
|
372 |
with l c;
|
|
373 |
show ?thesis; by (auto simp add: nth_append);
|
|
374 |
qed;
|
|
375 |
qed;
|
|
376 |
qed;
|
|
377 |
qed;
|
|
378 |
|
|
379 |
lemma wtl_inst_list_correct:
|
|
380 |
"wtl_inst_list is G rT s0 s2 cert (length is) 0 \\<Longrightarrow>
|
|
381 |
\\<exists> phi. \\<forall>pc. pc < length is \\<longrightarrow> wt_instr (is ! pc) G rT phi (length is) pc";
|
|
382 |
proof -;
|
|
383 |
assume wtl: "wtl_inst_list is G rT s0 s2 cert (length is) 0";
|
|
384 |
thus ?thesis;
|
|
385 |
obtain phi where "fits phi is G rT s0 s2 cert";
|
|
386 |
by (rule exists_phi [elimify]) blast;
|
|
387 |
with wtl;
|
|
388 |
show ?thesis;
|
|
389 |
by (rule wtl_fits_wt [elimify]) blast;
|
|
390 |
qed;
|
|
391 |
qed;
|
|
392 |
|
|
393 |
lemma fits_first:
|
|
394 |
"\\<lbrakk>is \\<noteq> [];wtl_inst_list is G rT s0 s2 cert (length is) 0;
|
|
395 |
fits phi is G rT s0 s2 cert\\<rbrakk> \\<Longrightarrow> G \\<turnstile> s0 <=s phi ! 0";
|
|
396 |
proof -;
|
|
397 |
assume wtl: "wtl_inst_list is G rT s0 s2 cert (length is) 0";
|
|
398 |
assume fits: "fits phi is G rT s0 s2 cert";
|
|
399 |
assume "is \\<noteq> []";
|
|
400 |
thus ?thesis;
|
|
401 |
obtain y ys where cons: "is = y#ys"; by (simp add: neq_Nil_conv) (elim, rule that);
|
|
402 |
from fits;
|
|
403 |
show ?thesis;
|
|
404 |
proof (rule fitsD [elimify]);
|
|
405 |
from cons; show "[]@y#ys = is"; by simp;
|
|
406 |
from cons wtl;
|
|
407 |
show "wtl_inst_list (y#ys) G rT s0 s2 cert (0 + length is) (0 + length [])";
|
|
408 |
by simp;
|
|
409 |
|
|
410 |
assume cert:
|
|
411 |
"(cert ! (0 + length []) = None \\<longrightarrow> phi ! (0 + length []) = s0) \\<and>
|
|
412 |
(\\<forall>t. cert ! (0 + length []) = Some t \\<longrightarrow> phi ! (0 + length []) = t)";
|
|
413 |
|
|
414 |
show ?thesis;
|
|
415 |
proof (cases "cert!0");
|
|
416 |
assume "cert!0 = None";
|
|
417 |
with cert;
|
|
418 |
show ?thesis; by simp;
|
|
419 |
next;
|
|
420 |
fix t; assume "cert!0 = Some t";
|
|
421 |
with cert;
|
|
422 |
have "phi!0 = t"; by (simp del: split_paired_All);
|
|
423 |
with cert cons wtl;
|
|
424 |
show ?thesis; by (auto simp add: wtl_inst_option_def);
|
|
425 |
qed;
|
|
426 |
qed simp;
|
|
427 |
qed;
|
|
428 |
qed;
|
8245
|
429 |
|
9012
|
430 |
lemma wtl_method_correct:
|
|
431 |
"wtl_method G C pTs rT mxl ins cert \\<Longrightarrow> \\<exists> phi. wt_method G C pTs rT mxl ins phi";
|
|
432 |
proof (unfold wtl_method_def, simp del: split_paired_Ex, elim exE conjE);
|
|
433 |
let "?s0" = "([], Some (Class C) # map Some pTs @ replicate mxl None)";
|
|
434 |
fix s2;
|
|
435 |
assume neqNil: "ins \\<noteq> []";
|
|
436 |
assume wtl: "wtl_inst_list ins G rT ?s0 s2 cert (length ins) 0";
|
|
437 |
thus ?thesis;
|
|
438 |
obtain phi where fits: "fits phi ins G rT ?s0 s2 cert \\<and> length ins < length phi";
|
|
439 |
by (rule exists_phi [elimify]) blast;
|
|
440 |
with wtl;
|
|
441 |
have allpc:
|
|
442 |
"\\<forall>pc. pc < length ins \\<longrightarrow> wt_instr (ins ! pc) G rT phi (length ins) pc";
|
|
443 |
by elim (rule wtl_fits_wt [elimify]);
|
|
444 |
from neqNil wtl fits;
|
|
445 |
have "wt_start G C pTs mxl phi";
|
|
446 |
by (elim conjE, unfold wt_start_def) (rule fits_first);
|
|
447 |
with neqNil allpc fits;
|
|
448 |
show ?thesis; by (auto simp add: wt_method_def);
|
|
449 |
qed;
|
|
450 |
qed;
|
|
451 |
|
|
452 |
lemma unique_set:
|
|
453 |
"(a,b,c,d)\\<in>set l \\<longrightarrow> unique l \\<longrightarrow> (a',b',c',d') \\<in> set l \\<longrightarrow> a = a' \\<longrightarrow> b=b' \\<and> c=c' \\<and> d=d'";
|
|
454 |
by (induct "l") auto;
|
|
455 |
|
|
456 |
lemma unique_epsilon:
|
|
457 |
"(a,b,c,d)\\<in>set l \\<longrightarrow> unique l \\<longrightarrow> (\\<epsilon> (a',b',c',d'). (a',b',c',d') \\<in> set l \\<and> a'=a) = (a,b,c,d)";
|
|
458 |
by (auto simp add: unique_set);
|
|
459 |
|
|
460 |
theorem wtl_correct:
|
|
461 |
"wtl_jvm_prog G cert ==> \\<exists> Phi. wt_jvm_prog G Phi";
|
|
462 |
proof (clarsimp_tac simp add: wt_jvm_prog_def wf_prog_def, intro conjI);
|
|
463 |
|
|
464 |
assume wtl_prog: "wtl_jvm_prog G cert";
|
|
465 |
thus "ObjectC \\<in> set G"; by (simp add: wtl_jvm_prog_def wf_prog_def);
|
|
466 |
|
|
467 |
from wtl_prog;
|
|
468 |
show uniqueG: "unique G"; by (simp add: wtl_jvm_prog_def wf_prog_def);
|
|
469 |
|
|
470 |
show "\\<exists>Phi. Ball (set G) (wf_cdecl (\\<lambda>G C (sig,rT,maxl,b). wt_method G C (snd sig) rT maxl b (Phi C sig)) G)"
|
|
471 |
(is "\\<exists>Phi. ?Q Phi");
|
|
472 |
proof (intro exI);
|
|
473 |
let "?Phi" =
|
|
474 |
"\\<lambda> C sig. let (C,x,y,mdecls) = \\<epsilon> (Cl,x,y,mdecls). (Cl,x,y,mdecls) \\<in> set G \\<and> Cl = C in
|
|
475 |
let (sig,rT,maxl,b) = \\<epsilon> (sg,rT,maxl,b). (sg,rT,maxl,b) \\<in> set mdecls \\<and> sg = sig in\
|
|
476 |
\\<epsilon> phi. wt_method G C (snd sig) rT maxl b phi";
|
|
477 |
from wtl_prog;
|
|
478 |
show "?Q ?Phi";
|
|
479 |
proof (unfold wf_cdecl_def, intro);
|
|
480 |
fix x a b aa ba ab bb m;
|
|
481 |
assume 1: "x \\<in> set G" "x = (a, b)" "b = (aa, ba)" "ba = (ab, bb)" "m \\<in> set bb";
|
|
482 |
with wtl_prog;
|
|
483 |
show "wf_mdecl (\\<lambda>G C (sig,rT,maxl,b). wt_method G C (snd sig) rT maxl b (?Phi C sig)) G a m";
|
|
484 |
proof (simp add: wf_mdecl_def wtl_jvm_prog_def wf_prog_def wf_cdecl_def, elim conjE);
|
|
485 |
apply_end (drule bspec, assumption, simp, elim conjE);
|
|
486 |
assume "\\<forall>(sig,rT,mb)\\<in>set bb. wf_mhead G sig rT \\<and>
|
|
487 |
(\\<lambda>(maxl,b). wtl_method G a (snd sig) rT maxl b (cert a sig)) mb"
|
|
488 |
"unique bb";
|
|
489 |
with 1 uniqueG;
|
|
490 |
show "(\\<lambda>(sig,rT,mb).
|
|
491 |
wf_mhead G sig rT \\<and>
|
|
492 |
(\\<lambda>(maxl,b).
|
|
493 |
wt_method G a (snd sig) rT maxl b
|
|
494 |
((\\<lambda>(C,x,y,mdecls).
|
|
495 |
(\\<lambda>(sig,rT,maxl,b). Eps (wt_method G C (snd sig) rT maxl b))
|
|
496 |
(\\<epsilon>(sg,rT,maxl,b). (sg, rT, maxl, b) \\<in> set mdecls \\<and> sg = sig))
|
|
497 |
(\\<epsilon>(Cl,x,y,mdecls). (Cl, x, y, mdecls) \\<in> set G \\<and> Cl = a))) mb) m";
|
|
498 |
by - (drule bspec, assumption,
|
|
499 |
clarsimp_tac elim: wtl_method_correct [elimify],
|
|
500 |
clarsimp_tac intro: selectI simp add: unique_epsilon);
|
|
501 |
qed;
|
|
502 |
qed (auto simp add: wtl_jvm_prog_def wf_prog_def wf_cdecl_def);
|
|
503 |
qed;
|
|
504 |
qed;
|
|
505 |
|
|
506 |
|
|
507 |
end;
|