author | kleing |
Wed, 20 Mar 2002 13:21:07 +0100 | |
changeset 13062 | 4b1edf2f6bd2 |
parent 13006 | 51c5f3f11d16 |
child 13071 | f538a1dba7ee |
permissions | -rw-r--r-- |
9757
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
1 |
(* Title: HOL/MicroJava/BV/BVLCorrect.thy |
8245 | 2 |
ID: $Id$ |
3 |
Author: Gerwin Klein |
|
4 |
Copyright 1999 Technische Universitaet Muenchen |
|
9054 | 5 |
*) |
8245 | 6 |
|
12911 | 7 |
header {* \isaheader{Correctness of the LBV} *} |
8245 | 8 |
|
13062 | 9 |
theory LBVCorrect = LBVSpec + Typing_Framework: |
9757
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
10 |
|
8245 | 11 |
constdefs |
13062 | 12 |
fits :: "'s option list \<Rightarrow> 's certificate \<Rightarrow> 's ebinop \<Rightarrow> 's ord \<Rightarrow> |
13 |
's steptype \<Rightarrow> 's option \<Rightarrow> 'a list \<Rightarrow> bool" |
|
14 |
"fits phi cert f r step s0 is \<equiv> |
|
15 |
length phi = length is \<and> |
|
16 |
(\<forall>pc s. pc < length is --> |
|
17 |
(wtl_inst_list (take pc is) cert f r step 0 s0 = OK s \<longrightarrow> |
|
18 |
(case cert!pc of None => phi!pc = s |
|
19 |
| Some t => phi!pc = Some t)))" |
|
9757
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
20 |
|
13062 | 21 |
make_phi :: "'s certificate \<Rightarrow> 's ebinop \<Rightarrow> 's ord \<Rightarrow> |
22 |
's steptype \<Rightarrow> 's option \<Rightarrow> 'a list \<Rightarrow> 's option list" |
|
23 |
"make_phi cert f r step s0 is \<equiv> |
|
9757
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
24 |
map (\<lambda>pc. case cert!pc of |
13062 | 25 |
None => ok_val (wtl_inst_list (take pc is) cert f r step 0 s0) |
26 |
| Some t => Some t) [0..length is(]" |
|
9012 | 27 |
|
13062 | 28 |
lemma fitsD_None [intro?]: |
29 |
"\<lbrakk> fits phi cert f r step s0 is; pc < length is; |
|
30 |
wtl_inst_list (take pc is) cert f r step 0 s0 = OK s; |
|
31 |
cert!pc = None \<rbrakk> \<Longrightarrow> phi!pc = s" |
|
9757
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
32 |
by (auto simp add: fits_def) |
9012 | 33 |
|
13062 | 34 |
lemma fitsD_Some [intro?]: |
35 |
"\<lbrakk> fits phi cert f r step s0 is; pc < length is; |
|
36 |
wtl_inst_list (take pc is) cert f r step 0 s0 = OK s; |
|
37 |
cert!pc = Some t \<rbrakk> \<Longrightarrow> phi!pc = Some t" |
|
9757
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
38 |
by (auto simp add: fits_def) |
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
39 |
|
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
40 |
lemma make_phi_Some: |
13062 | 41 |
"pc < length is \<Longrightarrow> cert!pc = Some t \<Longrightarrow> |
42 |
make_phi cert f r step s0 is ! pc = Some t" |
|
9757
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
43 |
by (simp add: make_phi_def) |
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
44 |
|
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
45 |
lemma make_phi_None: |
13062 | 46 |
"pc < length is \<Longrightarrow> cert!pc = None \<Longrightarrow> |
47 |
make_phi cert f r step s0 is ! pc = |
|
48 |
ok_val (wtl_inst_list (take pc is) cert f r step 0 s0)" |
|
49 |
by (simp add: make_phi_def) |
|
50 |
||
51 |
lemma make_phi_len: |
|
52 |
"length (make_phi cert f r step s0 is) = length is" |
|
9757
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
53 |
by (simp add: make_phi_def) |
9012 | 54 |
|
55 |
lemma exists_phi: |
|
13062 | 56 |
"\<exists>phi. fits phi cert f r step s0 is" |
9757
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
57 |
proof - |
13062 | 58 |
have "fits (make_phi cert f r step s0 is) cert f r step s0 is" |
59 |
by (auto simp add: fits_def make_phi_Some make_phi_None make_phi_len |
|
9757
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
60 |
split: option.splits) |
12516 | 61 |
thus ?thesis by fast |
9757
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
62 |
qed |
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
63 |
|
13062 | 64 |
lemma fits_lemma1 [intro?]: |
65 |
"\<lbrakk>wtl_inst_list is cert f r step 0 s \<noteq> Err; fits phi cert f r step s is\<rbrakk> |
|
13006 | 66 |
\<Longrightarrow> \<forall>pc t. pc < length is \<longrightarrow> cert!pc = Some t \<longrightarrow> phi!pc = Some t" |
9757
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
67 |
proof (intro strip) |
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
68 |
fix pc t |
13062 | 69 |
assume "wtl_inst_list is cert f r step 0 s \<noteq> Err" |
12516 | 70 |
then obtain s'' where |
13062 | 71 |
"wtl_inst_list (take pc is) cert f r step 0 s = OK s''" |
9757
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
72 |
by (blast dest: wtl_take) |
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
73 |
moreover |
13062 | 74 |
assume "fits phi cert f r step s is" |
75 |
"pc < length is" "cert ! pc = Some t" |
|
9757
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
76 |
ultimately |
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
77 |
show "phi!pc = Some t" by (auto dest: fitsD_Some) |
9580 | 78 |
qed |
9012 | 79 |
|
80 |
||
81 |
lemma wtl_suc_pc: |
|
13062 | 82 |
assumes |
83 |
semi: "err_semilat (A,r,f)" and |
|
84 |
all: "wtl_inst_list is cert f r step 0 s0 \<noteq> Err" and |
|
85 |
wtl: "wtl_inst_list (take pc is) cert f r step 0 s0 = OK s'" and |
|
86 |
cert: "wtl_cert cert f r step pc s' = OK s''" and |
|
87 |
fits: "fits phi cert f r step s0 is" and |
|
88 |
pc: "pc+1 < length is" |
|
89 |
shows "OK s'' \<le>|r OK (phi!(pc+1))" |
|
9757
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
90 |
proof - |
13062 | 91 |
from wtl cert pc |
92 |
have wts: "wtl_inst_list (take (pc+1) is) cert f r step 0 s0 = OK s''" |
|
93 |
by (rule wtl_Suc) |
|
94 |
moreover |
|
95 |
from all pc |
|
96 |
have "\<exists>s' s''. wtl_inst_list (take (pc+1) is) cert f r step 0 s0 = OK s' \<and> |
|
97 |
wtl_cert cert f r step (pc+1) s' = OK s''" |
|
98 |
by (rule wtl_all) |
|
99 |
ultimately |
|
100 |
obtain x where "wtl_cert cert f r step (pc+1) s'' = OK x" by auto |
|
101 |
hence "\<And>t. cert!(pc+1) = Some t \<Longrightarrow> OK s'' \<le>|r OK (cert!(pc+1))" |
|
102 |
by (simp add: wtl_cert_def split: split_if_asm) |
|
103 |
also from fits pc wts |
|
104 |
have "\<And>t. cert!(pc+1) = Some t \<Longrightarrow> cert!(pc+1) = phi!(pc+1)" |
|
105 |
by (auto dest!: fitsD_Some) |
|
106 |
finally have "\<And>t. cert!(pc+1) = Some t \<Longrightarrow> OK s'' \<le>|r OK (phi!(pc+1))" . |
|
107 |
moreover |
|
108 |
from fits pc wts have "cert!(pc+1) = None \<Longrightarrow> s'' = phi!(pc+1)" |
|
109 |
by (rule fitsD_None [symmetric]) |
|
110 |
with semi have "cert!(pc+1) = None \<Longrightarrow> OK s'' \<le>|r OK (phi!(pc+1))" by simp |
|
111 |
ultimately |
|
112 |
show "OK s'' \<le>|r OK (phi!(pc+1))" by (cases "cert!(pc+1)", blast+) |
|
113 |
qed |
|
9757
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
114 |
|
13062 | 115 |
lemma wtl_stable: |
116 |
assumes |
|
117 |
semi: "err_semilat (A,r,f)" and |
|
118 |
pres: "pres_type step (length is) (err (opt A))" and |
|
119 |
s0_in_A: "s0 \<in> opt A" and |
|
120 |
cert_ok: "cert_ok cert (length is) A" and |
|
121 |
fits: "fits phi cert f r step s0 is" and |
|
122 |
wtl: "wtl_inst_list is cert f r step 0 s0 \<noteq> Err" and |
|
123 |
pc: "pc < length is" and |
|
124 |
bounded: "bounded step (length is)" |
|
125 |
shows "stable (Err.le (Opt.le r)) step (map OK phi) pc" |
|
126 |
proof (unfold stable_def, clarify) |
|
127 |
fix pc' s' assume step: "(pc',s') \<in> set (step pc ((map OK phi) ! pc))" |
|
128 |
(is "(pc',s') \<in> set (?step pc)") |
|
129 |
||
130 |
from step pc bounded have pc': "pc' < length is" |
|
131 |
by (unfold bounded_def) blast |
|
132 |
||
133 |
from wtl pc obtain s1 s2 where |
|
134 |
tkpc: "wtl_inst_list (take pc is) cert f r step 0 s0 = OK s1" and |
|
135 |
cert: "wtl_cert cert f r step pc s1 = OK s2" |
|
136 |
by - (drule wtl_all, auto) |
|
9012 | 137 |
|
13062 | 138 |
have c_Some: "\<forall>pc t. pc < length is \<longrightarrow> cert!pc = Some t \<longrightarrow> phi!pc = Some t" .. |
139 |
have c_None: "cert!pc = None \<Longrightarrow> phi!pc = s1" .. |
|
140 |
||
141 |
from cert pc c_None c_Some |
|
142 |
have inst: "wtl_inst cert f r step pc (phi!pc) = OK s2" |
|
143 |
by (simp add: wtl_cert_def split: option.splits split_if_asm) |
|
144 |
||
145 |
from semi have "order (Err.le (Opt.le r))" by simp note order_trans [OF this, trans] |
|
146 |
||
147 |
from pc fits have [simp]: "map OK phi!pc = OK (phi!pc)" by (simp add: fits_def) |
|
148 |
from pc' fits have [simp]: "map OK phi!pc' = OK (phi!pc')" by (simp add: fits_def) |
|
149 |
||
150 |
have "s1 \<in> opt A" by (rule wtl_inst_list_pres) |
|
151 |
with pc c_Some cert_ok c_None |
|
152 |
have "phi!pc \<in> opt A" by (cases "cert!pc") (auto dest: cert_okD) |
|
153 |
with pc pres |
|
154 |
have step_in_A: "\<forall>(pc',s') \<in> set (?step pc). s' \<in> err (opt A)" |
|
155 |
by (auto dest: pres_typeD) |
|
9012 | 156 |
|
13062 | 157 |
show "s' \<le>|r (map OK phi) ! pc'" |
158 |
proof (cases "pc' = pc+1") |
|
159 |
case True |
|
160 |
with pc' cert_ok |
|
161 |
have cert_in_A: "OK (cert!(pc+1)) \<in> err (opt A)" by (auto dest: cert_okD) |
|
162 |
from inst |
|
163 |
have ok: "OK s2 = merge cert f r pc (?step pc) (OK (cert!(pc+1)))" |
|
164 |
by (simp add: wtl_inst_def) |
|
165 |
also |
|
166 |
have "\<dots> = (map snd [(p',t')\<in>?step pc. p'=pc+1] ++|f (OK (cert!(pc+1))))" |
|
167 |
using cert_in_A step_in_A semi ok |
|
168 |
by - (drule merge_def, auto split: split_if_asm) |
|
169 |
finally |
|
170 |
have "s' \<le>|r OK s2" |
|
171 |
using semi step_in_A cert_in_A True step by (auto intro: ub1') |
|
172 |
also |
|
173 |
from True pc' have "pc+1 < length is" by simp |
|
174 |
with semi wtl tkpc cert fits |
|
175 |
have "OK s2 \<le>|r (OK (phi ! (pc+1)))" by (rule wtl_suc_pc) |
|
176 |
also note True [symmetric] |
|
177 |
finally show ?thesis by simp |
|
178 |
next |
|
179 |
case False |
|
180 |
from inst |
|
181 |
have "\<forall>(pc', s')\<in>set (?step pc). pc'\<noteq>pc+1 \<longrightarrow> s' \<le>|r OK (cert!pc')" |
|
182 |
by (unfold wtl_inst_def) (rule merge_ok, simp) |
|
183 |
with step False |
|
184 |
have ok: "s' \<le>|r (OK (cert!pc'))" by blast |
|
185 |
moreover |
|
186 |
from ok |
|
187 |
have "cert!pc' = None \<longrightarrow> s' = OK None" by auto |
|
188 |
moreover |
|
189 |
from c_Some pc' |
|
190 |
have "cert!pc' \<noteq> None \<longrightarrow> phi!pc' = cert!pc'" by auto |
|
191 |
ultimately |
|
192 |
show ?thesis by auto |
|
193 |
qed |
|
9549
40d64cb4f4e6
BV and LBV specified in terms of app and step functions
kleing
parents:
9376
diff
changeset
|
194 |
qed |
9012 | 195 |
|
9376 | 196 |
|
13062 | 197 |
lemma wtl_fits: |
198 |
"wtl_inst_list is cert f r step 0 s0 \<noteq> Err \<Longrightarrow> |
|
199 |
fits phi cert f r step s0 is \<Longrightarrow> |
|
200 |
err_semilat (A,r,f) \<Longrightarrow> |
|
201 |
bounded step (length is) \<Longrightarrow> |
|
202 |
pres_type step (length is) (err (opt A)) \<Longrightarrow> |
|
203 |
s0 \<in> opt A \<Longrightarrow> |
|
204 |
cert_ok cert (length is) A \<Longrightarrow> |
|
205 |
wt_step (Err.le (Opt.le r)) Err step (map OK phi)" |
|
206 |
apply (unfold wt_step_def) |
|
207 |
apply (intro strip) |
|
208 |
apply (rule conjI, simp) |
|
209 |
apply (rule wtl_stable) |
|
210 |
apply assumption+ |
|
211 |
apply (simp add: fits_def) |
|
212 |
apply assumption |
|
213 |
done |
|
9549
40d64cb4f4e6
BV and LBV specified in terms of app and step functions
kleing
parents:
9376
diff
changeset
|
214 |
|
13062 | 215 |
|
216 |
theorem wtl_sound: |
|
217 |
assumes "wtl_inst_list is cert f r step 0 s0 \<noteq> Err" |
|
218 |
assumes "err_semilat (A,r,f)" and "bounded step (length is)" |
|
219 |
assumes "s0 \<in> opt A" and "cert_ok cert (length is) A" |
|
220 |
assumes "pres_type step (length is) (err (opt A))" |
|
221 |
shows "\<exists>ts. wt_step (Err.le (Opt.le r)) Err step ts" |
|
222 |
proof - |
|
223 |
obtain phi where "fits phi cert f r step s0 is" by (insert exists_phi) fast |
|
224 |
have "wt_step (Err.le (Opt.le r)) Err step (map OK phi)" by (rule wtl_fits) |
|
225 |
thus ?thesis .. |
|
9549
40d64cb4f4e6
BV and LBV specified in terms of app and step functions
kleing
parents:
9376
diff
changeset
|
226 |
qed |
40d64cb4f4e6
BV and LBV specified in terms of app and step functions
kleing
parents:
9376
diff
changeset
|
227 |
|
40d64cb4f4e6
BV and LBV specified in terms of app and step functions
kleing
parents:
9376
diff
changeset
|
228 |
|
10812
ead84e90bfeb
merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents:
10628
diff
changeset
|
229 |
end |