12 |
12 |
13 constdefs |
13 constdefs |
14 fits :: "[method_type,instr list,jvm_prog,ty,state_type option,certificate] => bool" |
14 fits :: "[method_type,instr list,jvm_prog,ty,state_type option,certificate] => bool" |
15 "fits phi is G rT s0 cert == |
15 "fits phi is G rT s0 cert == |
16 (\<forall>pc s1. pc < length is --> |
16 (\<forall>pc s1. pc < length is --> |
17 (wtl_inst_list (take pc is) G rT cert (length is) 0 s0 = Ok s1 --> |
17 (wtl_inst_list (take pc is) G rT cert (length is) 0 s0 = OK s1 --> |
18 (case cert!pc of None => phi!pc = s1 |
18 (case cert!pc of None => phi!pc = s1 |
19 | Some t => phi!pc = Some t)))" |
19 | Some t => phi!pc = Some t)))" |
20 |
20 |
21 constdefs |
21 constdefs |
22 make_phi :: "[instr list,jvm_prog,ty,state_type option,certificate] => method_type" |
22 make_phi :: "[instr list,jvm_prog,ty,state_type option,certificate] => method_type" |
23 "make_phi is G rT s0 cert == |
23 "make_phi is G rT s0 cert == |
24 map (\<lambda>pc. case cert!pc of |
24 map (\<lambda>pc. case cert!pc of |
25 None => val (wtl_inst_list (take pc is) G rT cert (length is) 0 s0) |
25 None => ok_val (wtl_inst_list (take pc is) G rT cert (length is) 0 s0) |
26 | Some t => Some t) [0..length is(]" |
26 | Some t => Some t) [0..length is(]" |
27 |
27 |
28 |
28 |
29 lemma fitsD_None: |
29 lemma fitsD_None: |
30 "[|fits phi is G rT s0 cert; pc < length is; |
30 "[|fits phi is G rT s0 cert; pc < length is; |
31 wtl_inst_list (take pc is) G rT cert (length is) 0 s0 = Ok s1; |
31 wtl_inst_list (take pc is) G rT cert (length is) 0 s0 = OK s1; |
32 cert ! pc = None|] ==> phi!pc = s1" |
32 cert ! pc = None|] ==> phi!pc = s1" |
33 by (auto simp add: fits_def) |
33 by (auto simp add: fits_def) |
34 |
34 |
35 lemma fitsD_Some: |
35 lemma fitsD_Some: |
36 "[|fits phi is G rT s0 cert; pc < length is; |
36 "[|fits phi is G rT s0 cert; pc < length is; |
37 wtl_inst_list (take pc is) G rT cert (length is) 0 s0 = Ok s1; |
37 wtl_inst_list (take pc is) G rT cert (length is) 0 s0 = OK s1; |
38 cert ! pc = Some t|] ==> phi!pc = Some t" |
38 cert ! pc = Some t|] ==> phi!pc = Some t" |
39 by (auto simp add: fits_def) |
39 by (auto simp add: fits_def) |
40 |
40 |
41 lemma make_phi_Some: |
41 lemma make_phi_Some: |
42 "[| pc < length is; cert!pc = Some t |] ==> |
42 "[| pc < length is; cert!pc = Some t |] ==> |
44 by (simp add: make_phi_def) |
44 by (simp add: make_phi_def) |
45 |
45 |
46 lemma make_phi_None: |
46 lemma make_phi_None: |
47 "[| pc < length is; cert!pc = None |] ==> |
47 "[| pc < length is; cert!pc = None |] ==> |
48 make_phi is G rT s0 cert ! pc = |
48 make_phi is G rT s0 cert ! pc = |
49 val (wtl_inst_list (take pc is) G rT cert (length is) 0 s0)" |
49 ok_val (wtl_inst_list (take pc is) G rT cert (length is) 0 s0)" |
50 by (simp add: make_phi_def) |
50 by (simp add: make_phi_def) |
51 |
51 |
52 lemma exists_phi: |
52 lemma exists_phi: |
53 "\<exists>phi. fits phi is G rT s0 cert" |
53 "\<exists>phi. fits phi is G rT s0 cert" |
54 proof - |
54 proof - |
59 thus ?thesis |
59 thus ?thesis |
60 by blast |
60 by blast |
61 qed |
61 qed |
62 |
62 |
63 lemma fits_lemma1: |
63 lemma fits_lemma1: |
64 "[| wtl_inst_list is G rT cert (length is) 0 s = Ok s'; fits phi is G rT s cert |] |
64 "[| wtl_inst_list is G rT cert (length is) 0 s = OK s'; fits phi is G rT s cert |] |
65 ==> \<forall>pc t. pc < length is --> cert!pc = Some t --> phi!pc = Some t" |
65 ==> \<forall>pc t. pc < length is --> cert!pc = Some t --> phi!pc = Some t" |
66 proof (intro strip) |
66 proof (intro strip) |
67 fix pc t |
67 fix pc t |
68 assume "wtl_inst_list is G rT cert (length is) 0 s = Ok s'" |
68 assume "wtl_inst_list is G rT cert (length is) 0 s = OK s'" |
69 then |
69 then |
70 obtain s'' where |
70 obtain s'' where |
71 "wtl_inst_list (take pc is) G rT cert (length is) 0 s = Ok s''" |
71 "wtl_inst_list (take pc is) G rT cert (length is) 0 s = OK s''" |
72 by (blast dest: wtl_take) |
72 by (blast dest: wtl_take) |
73 moreover |
73 moreover |
74 assume "fits phi is G rT s cert" |
74 assume "fits phi is G rT s cert" |
75 "pc < length is" |
75 "pc < length is" |
76 "cert ! pc = Some t" |
76 "cert ! pc = Some t" |
79 qed |
79 qed |
80 |
80 |
81 |
81 |
82 lemma wtl_suc_pc: |
82 lemma wtl_suc_pc: |
83 "[| wtl_inst_list is G rT cert (length is) 0 s \<noteq> Err; |
83 "[| wtl_inst_list is G rT cert (length is) 0 s \<noteq> Err; |
84 wtl_inst_list (take pc is) G rT cert (length is) 0 s = Ok s'; |
84 wtl_inst_list (take pc is) G rT cert (length is) 0 s = OK s'; |
85 wtl_cert (is!pc) G rT s' cert (length is) pc = Ok s''; |
85 wtl_cert (is!pc) G rT s' cert (length is) pc = OK s''; |
86 fits phi is G rT s cert; Suc pc < length is |] ==> |
86 fits phi is G rT s cert; Suc pc < length is |] ==> |
87 G \<turnstile> s'' <=' phi ! Suc pc" |
87 G \<turnstile> s'' <=' phi ! Suc pc" |
88 proof - |
88 proof - |
89 |
89 |
90 assume all: "wtl_inst_list is G rT cert (length is) 0 s \<noteq> Err" |
90 assume all: "wtl_inst_list is G rT cert (length is) 0 s \<noteq> Err" |
91 assume fits: "fits phi is G rT s cert" |
91 assume fits: "fits phi is G rT s cert" |
92 |
92 |
93 assume wtl: "wtl_inst_list (take pc is) G rT cert (length is) 0 s = Ok s'" and |
93 assume wtl: "wtl_inst_list (take pc is) G rT cert (length is) 0 s = OK s'" and |
94 wtc: "wtl_cert (is!pc) G rT s' cert (length is) pc = Ok s''" and |
94 wtc: "wtl_cert (is!pc) G rT s' cert (length is) pc = OK s''" and |
95 pc: "Suc pc < length is" |
95 pc: "Suc pc < length is" |
96 |
96 |
97 hence wts: "wtl_inst_list (take (Suc pc) is) G rT cert (length is) 0 s = Ok s''" |
97 hence wts: "wtl_inst_list (take (Suc pc) is) G rT cert (length is) 0 s = OK s''" |
98 by (rule wtl_Suc) |
98 by (rule wtl_Suc) |
99 |
99 |
100 from all |
100 from all |
101 have app: |
101 have app: |
102 "wtl_inst_list (take (Suc pc) is@drop (Suc pc) is) G rT cert (length is) 0 s \<noteq> Err" |
102 "wtl_inst_list (take (Suc pc) is@drop (Suc pc) is) G rT cert (length is) 0 s \<noteq> Err" |
109 obtain l ls where |
109 obtain l ls where |
110 "drop (Suc pc) is = l#ls" |
110 "drop (Suc pc) is = l#ls" |
111 by (auto simp add: neq_Nil_conv simp del: length_drop) |
111 by (auto simp add: neq_Nil_conv simp del: length_drop) |
112 with app wts pc |
112 with app wts pc |
113 obtain x where |
113 obtain x where |
114 "wtl_cert l G rT s'' cert (length is) (Suc pc) = Ok x" |
114 "wtl_cert l G rT s'' cert (length is) (Suc pc) = OK x" |
115 by (auto simp add: wtl_append min_def simp del: append_take_drop_id) |
115 by (auto simp add: wtl_append min_def simp del: append_take_drop_id) |
116 |
116 |
117 hence c1: "!!t. cert!Suc pc = Some t ==> G \<turnstile> s'' <=' cert!Suc pc" |
117 hence c1: "!!t. cert!Suc pc = Some t ==> G \<turnstile> s'' <=' cert!Suc pc" |
118 by (simp add: wtl_cert_def split: if_splits) |
118 by (simp add: wtl_cert_def split: if_splits) |
119 moreover |
119 moreover |
142 assume pc: "pc < length is" and |
142 assume pc: "pc < length is" and |
143 wtl: "wtl_inst_list is G rT cert (length is) 0 s \<noteq> Err" |
143 wtl: "wtl_inst_list is G rT cert (length is) 0 s \<noteq> Err" |
144 |
144 |
145 then |
145 then |
146 obtain s' s'' where |
146 obtain s' s'' where |
147 w: "wtl_inst_list (take pc is) G rT cert (length is) 0 s = Ok s'" and |
147 w: "wtl_inst_list (take pc is) G rT cert (length is) 0 s = OK s'" and |
148 c: "wtl_cert (is!pc) G rT s' cert (length is) pc = Ok s''" |
148 c: "wtl_cert (is!pc) G rT s' cert (length is) pc = OK s''" |
149 by - (drule wtl_all, auto) |
149 by - (drule wtl_all, auto) |
150 |
150 |
151 from fits wtl pc |
151 from fits wtl pc |
152 have cert_Some: |
152 have cert_Some: |
153 "!!t pc. [| pc < length is; cert!pc = Some t |] ==> phi!pc = Some t" |
153 "!!t pc. [| pc < length is; cert!pc = Some t |] ==> phi!pc = Some t" |
156 from fits wtl pc |
156 from fits wtl pc |
157 have cert_None: "cert!pc = None ==> phi!pc = s'" |
157 have cert_None: "cert!pc = None ==> phi!pc = s'" |
158 by - (drule fitsD_None) |
158 by - (drule fitsD_None) |
159 |
159 |
160 from pc c cert_None cert_Some |
160 from pc c cert_None cert_Some |
161 have wti: "wtl_inst (is ! pc) G rT (phi!pc) cert (length is) pc = Ok s''" |
161 have wti: "wtl_inst (is ! pc) G rT (phi!pc) cert (length is) pc = OK s''" |
162 by (auto simp add: wtl_cert_def split: if_splits option.splits) |
162 by (auto simp add: wtl_cert_def split: if_splits option.splits) |
163 |
163 |
164 { fix pc' |
164 { fix pc' |
165 assume pc': "pc' \<in> set (succs (is!pc) pc)" |
165 assume pc': "pc' \<in> set (succs (is!pc) pc)" |
166 |
166 |
167 with wti |
167 with wti |
168 have less: "pc' < length is" |
168 have less: "pc' < length is" |
169 by (simp add: wtl_inst_Ok) |
169 by (simp add: wtl_inst_OK) |
170 |
170 |
171 have "G \<turnstile> step (is!pc) G (phi!pc) <=' phi ! pc'" |
171 have "G \<turnstile> step (is!pc) G (phi!pc) <=' phi ! pc'" |
172 proof (cases "pc' = Suc pc") |
172 proof (cases "pc' = Suc pc") |
173 case False |
173 case False |
174 with wti pc' |
174 with wti pc' |
175 have G: "G \<turnstile> step (is ! pc) G (phi ! pc) <=' cert ! pc'" |
175 have G: "G \<turnstile> step (is ! pc) G (phi ! pc) <=' cert ! pc'" |
176 by (simp add: wtl_inst_Ok) |
176 by (simp add: wtl_inst_OK) |
177 |
177 |
178 hence "cert!pc' = None ==> step (is ! pc) G (phi ! pc) = None" |
178 hence "cert!pc' = None ==> step (is ! pc) G (phi ! pc) = None" |
179 by simp |
179 by simp |
180 hence "cert!pc' = None ==> ?thesis" |
180 hence "cert!pc' = None ==> ?thesis" |
181 by simp |
181 by simp |
226 assume wtl: "wtl_inst_list is G rT cert (length is) 0 s \<noteq> Err" |
226 assume wtl: "wtl_inst_list is G rT cert (length is) 0 s \<noteq> Err" |
227 assume fits: "fits phi is G rT s cert" |
227 assume fits: "fits phi is G rT s cert" |
228 assume pc: "0 < length is" |
228 assume pc: "0 < length is" |
229 |
229 |
230 from wtl |
230 from wtl |
231 have wt0: "wtl_inst_list (take 0 is) G rT cert (length is) 0 s = Ok s" |
231 have wt0: "wtl_inst_list (take 0 is) G rT cert (length is) 0 s = OK s" |
232 by simp |
232 by simp |
233 |
233 |
234 with fits pc |
234 with fits pc |
235 have "cert!0 = None ==> phi!0 = s" |
235 have "cert!0 = None ==> phi!0 = s" |
236 by (rule fitsD_None) |
236 by (rule fitsD_None) |
242 from pc |
242 from pc |
243 obtain x xs where "is = x#xs" |
243 obtain x xs where "is = x#xs" |
244 by (simp add: neq_Nil_conv) (elim, rule that) |
244 by (simp add: neq_Nil_conv) (elim, rule that) |
245 with wtl |
245 with wtl |
246 obtain s' where |
246 obtain s' where |
247 "wtl_cert x G rT s cert (length is) 0 = Ok s'" |
247 "wtl_cert x G rT s cert (length is) 0 = OK s'" |
248 by simp (elim, rule that, simp) |
248 by simp (elim, rule that, simp) |
249 hence |
249 hence |
250 "!!t. cert!0 = Some t ==> G \<turnstile> s <=' cert!0" |
250 "!!t. cert!0 = Some t ==> G \<turnstile> s <=' cert!0" |
251 by (simp add: wtl_cert_def split: if_splits) |
251 by (simp add: wtl_cert_def split: if_splits) |
252 |
252 |
257 |
257 |
258 |
258 |
259 lemma wtl_method_correct: |
259 lemma wtl_method_correct: |
260 "wtl_method G C pTs rT mxl ins cert ==> \<exists> phi. wt_method G C pTs rT mxl ins phi" |
260 "wtl_method G C pTs rT mxl ins cert ==> \<exists> phi. wt_method G C pTs rT mxl ins phi" |
261 proof (unfold wtl_method_def, simp only: Let_def, elim conjE) |
261 proof (unfold wtl_method_def, simp only: Let_def, elim conjE) |
262 let "?s0" = "Some ([], Ok (Class C) # map Ok pTs @ replicate mxl Err)" |
262 let "?s0" = "Some ([], OK (Class C) # map OK pTs @ replicate mxl Err)" |
263 assume pc: "0 < length ins" |
263 assume pc: "0 < length ins" |
264 assume wtl: "wtl_inst_list ins G rT cert (length ins) 0 ?s0 \<noteq> Err" |
264 assume wtl: "wtl_inst_list ins G rT cert (length ins) 0 ?s0 \<noteq> Err" |
265 |
265 |
266 obtain phi where fits: "fits phi ins G rT ?s0 cert" |
266 obtain phi where fits: "fits phi ins G rT ?s0 cert" |
267 by (rule exists_phi [elim_format]) blast |
267 by (rule exists_phi [elim_format]) blast |