author | nipkow |
Tue, 02 Apr 2002 13:47:01 +0200 | |
changeset 13074 | 96bf406fd3e5 |
parent 13071 | f538a1dba7ee |
child 13078 | 1dd711c6b93c |
permissions | -rw-r--r-- |
8388 | 1 |
(* Title: HOL/MicroJava/BV/LBVComplete.thy |
2 |
ID: $Id$ |
|
3 |
Author: Gerwin Klein |
|
4 |
Copyright 2000 Technische Universitaet Muenchen |
|
9054 | 5 |
*) |
8388 | 6 |
|
12911 | 7 |
header {* \isaheader{Completeness of the LBV} *} |
8388 | 8 |
|
13064 | 9 |
theory LBVComplete = LBVSpec + Typing_Framework: |
9549
40d64cb4f4e6
BV and LBV specified in terms of app and step functions
kleing
parents:
9376
diff
changeset
|
10 |
|
8388 | 11 |
constdefs |
13066 | 12 |
contains_targets :: "['s steptype, 's certificate, 's option list, nat] \<Rightarrow> bool" |
13 |
"contains_targets step cert phi pc \<equiv> |
|
14 |
\<forall>(pc',s') \<in> set (step pc (OK (phi!pc))). pc' \<noteq> pc+1 \<and> pc' < length phi \<longrightarrow> cert!pc' = phi!pc'" |
|
8388 | 15 |
|
13066 | 16 |
fits :: "['s steptype, 's certificate, 's option list] \<Rightarrow> bool" |
17 |
"fits step cert phi \<equiv> \<forall>pc. pc < length phi \<longrightarrow> |
|
18 |
contains_targets step cert phi pc \<and> |
|
19 |
(cert!pc = None \<or> cert!pc = phi!pc)" |
|
9012 | 20 |
|
13066 | 21 |
is_target :: "['s steptype, 's option list, nat] \<Rightarrow> bool" |
22 |
"is_target step phi pc' \<equiv> |
|
23 |
\<exists>pc s'. pc' \<noteq> pc+1 \<and> pc < length phi \<and> (pc',s') \<in> set (step pc (OK (phi!pc)))" |
|
8388 | 24 |
|
13066 | 25 |
make_cert :: "['s steptype, 's option list] \<Rightarrow> 's certificate" |
26 |
"make_cert step phi \<equiv> |
|
13071 | 27 |
map (\<lambda>pc. if is_target step phi pc then phi!pc else None) [0..length phi(] @ [None]" |
9757
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
28 |
|
8388 | 29 |
|
9559 | 30 |
lemmas [simp del] = split_paired_Ex |
31 |
||
9757
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
32 |
lemma make_cert_target: |
13066 | 33 |
"\<lbrakk> pc < length phi; is_target step phi pc \<rbrakk> \<Longrightarrow> make_cert step phi ! pc = phi!pc" |
13071 | 34 |
by (simp add: make_cert_def nth_append) |
9012 | 35 |
|
9757
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
36 |
lemma make_cert_approx: |
13066 | 37 |
"\<lbrakk> pc < length phi; make_cert step phi ! pc \<noteq> phi!pc \<rbrakk> \<Longrightarrow> |
38 |
make_cert step phi ! pc = None" |
|
13071 | 39 |
by (auto simp add: make_cert_def nth_append) |
9012 | 40 |
|
9757
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
41 |
lemma make_cert_contains_targets: |
13066 | 42 |
"pc < length phi \<Longrightarrow> contains_targets step (make_cert step phi) phi pc" |
13064 | 43 |
proof (unfold contains_targets_def, clarify) |
44 |
fix pc' s' |
|
13066 | 45 |
assume "pc < length phi" |
13064 | 46 |
"(pc',s') \<in> set (step pc (OK (phi ! pc)))" |
9757
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
47 |
"pc' \<noteq> pc+1" and |
13066 | 48 |
pc': "pc' < length phi" |
49 |
hence "is_target step phi pc'" by (auto simp add: is_target_def) |
|
50 |
with pc' show "make_cert step phi ! pc' = phi!pc'" |
|
9757
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
51 |
by (auto intro: make_cert_target) |
9549
40d64cb4f4e6
BV and LBV specified in terms of app and step functions
kleing
parents:
9376
diff
changeset
|
52 |
qed |
9012 | 53 |
|
9757
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
54 |
theorem fits_make_cert: |
13066 | 55 |
"fits step (make_cert step phi) phi" |
9757
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
56 |
by (auto dest: make_cert_approx simp add: fits_def make_cert_contains_targets) |
9549
40d64cb4f4e6
BV and LBV specified in terms of app and step functions
kleing
parents:
9376
diff
changeset
|
57 |
|
40d64cb4f4e6
BV and LBV specified in terms of app and step functions
kleing
parents:
9376
diff
changeset
|
58 |
lemma fitsD: |
13071 | 59 |
"\<lbrakk> fits step cert phi; (pc',s') \<in> set (step pc (OK (phi!pc))); |
60 |
pc' \<noteq> pc+1; pc < length phi; pc' < length phi \<rbrakk> |
|
13006 | 61 |
\<Longrightarrow> cert!pc' = phi!pc'" |
13064 | 62 |
by (auto simp add: fits_def contains_targets_def) |
9549
40d64cb4f4e6
BV and LBV specified in terms of app and step functions
kleing
parents:
9376
diff
changeset
|
63 |
|
40d64cb4f4e6
BV and LBV specified in terms of app and step functions
kleing
parents:
9376
diff
changeset
|
64 |
lemma fitsD2: |
13066 | 65 |
"\<lbrakk> fits step cert phi; pc < length phi; cert!pc = Some s \<rbrakk> |
13006 | 66 |
\<Longrightarrow> cert!pc = phi!pc" |
9757
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
67 |
by (auto simp add: fits_def) |
13064 | 68 |
|
69 |
||
70 |
lemma merge_mono: |
|
71 |
assumes merge: "merge cert f r pc ss1 x = OK s1" |
|
72 |
assumes less: "ss2 <=|Err.le (Opt.le r)| ss1" |
|
13070 | 73 |
assumes esl: "err_semilat (A, r, f)" |
74 |
assumes x: "x \<in> err (opt A)" |
|
75 |
assumes ss1: "\<forall>(pc', s')\<in>set ss1. s' \<in> err (opt A)" |
|
76 |
assumes ss2: "\<forall>(pc', s')\<in>set ss2. s' \<in> err (opt A)" |
|
13064 | 77 |
shows "\<exists>s2. merge cert f r pc ss2 x = s2 \<and> s2 \<le>|r (OK s1)" |
78 |
proof- |
|
13070 | 79 |
from esl have eosl: "err_semilat (opt A, Opt.le r, Opt.sup f)" |
80 |
by - (drule semilat_opt, simp add: Opt.esl_def) |
|
81 |
hence order: "order (Opt.le r)" .. |
|
82 |
from esl x ss1 have "merge cert f r pc ss1 x = |
|
83 |
(if \<forall>(pc', s')\<in>set ss1. pc' \<noteq> pc + 1 \<longrightarrow> s' \<le>|r (OK (cert!pc')) |
|
84 |
then (map snd [(p', t')\<in>ss1 . p'=pc+1]) ++|f x |
|
85 |
else Err)" |
|
86 |
by (rule merge_def) |
|
87 |
with merge obtain |
|
88 |
app: "\<forall>(pc',s')\<in>set ss1. pc' \<noteq> pc+1 \<longrightarrow> s' \<le>|r (OK (cert!pc'))" |
|
89 |
(is "?app ss1") and |
|
90 |
sum: "(map snd [(p',t')\<in>ss1 . p' = pc+1] ++|f x) = OK s1" |
|
91 |
(is "?map ss1 ++|f x = _" is "?sum ss1 = _") |
|
92 |
by (simp split: split_if_asm) |
|
93 |
from app less |
|
94 |
have "?app ss2" |
|
95 |
apply clarify |
|
96 |
apply (drule lesub_step_typeD, assumption) |
|
97 |
apply clarify |
|
98 |
apply (drule bspec, assumption) |
|
99 |
apply clarify |
|
100 |
apply (drule order_trans [OF order], assumption) |
|
101 |
apply blast |
|
102 |
done |
|
103 |
moreover { |
|
104 |
have "set (?map ss1) \<subseteq> snd`(set ss1)" by auto |
|
105 |
also from ss1 have "snd`(set ss1) \<subseteq> err (opt A)" by auto |
|
106 |
finally have map1: "set (?map ss1) \<subseteq> err (opt A)" . |
|
107 |
with eosl x have "?sum ss1 \<in> err (opt A)" |
|
108 |
by (auto intro!: plusplus_closed simp add: Err.sl_def) |
|
109 |
with sum have "OK s1 \<in> err (opt A)" by simp |
|
110 |
moreover |
|
111 |
have mapD: "\<And>x ss. x \<in> set (?map ss) \<Longrightarrow> \<exists>p. (p,x) \<in> set ss \<and> p=pc+1" by auto |
|
112 |
from eosl x map1 |
|
13074 | 113 |
have "\<forall>x \<in> set (?map ss1). x \<le>|r (?sum ss1)" |
114 |
by clarify (rule semilat.pp_ub1, simp add: Err.sl_def) |
|
13070 | 115 |
with sum have "\<forall>x \<in> set (?map ss1). x \<le>|r (OK s1)" by simp |
116 |
with less have "\<forall>x \<in> set (?map ss2). x \<le>|r (OK s1)" |
|
117 |
apply clarify |
|
118 |
apply (drule mapD) |
|
119 |
apply clarify |
|
120 |
apply (drule lesub_step_typeD, assumption) |
|
121 |
apply clarify |
|
122 |
apply simp |
|
123 |
apply (erule allE, erule impE, assumption) |
|
124 |
apply clarify |
|
125 |
apply simp |
|
126 |
apply (rule order_trans [OF order],assumption+) |
|
127 |
done |
|
128 |
moreover |
|
129 |
from eosl map1 x have "x \<le>|r (?sum ss1)" |
|
13074 | 130 |
by - (rule semilat.pp_ub2, simp add: Err.sl_def) |
13070 | 131 |
with sum have "x \<le>|r (OK s1)" by simp |
132 |
moreover { |
|
133 |
have "set (?map ss2) \<subseteq> snd`(set ss2)" by auto |
|
134 |
also from ss2 have "snd`(set ss2) \<subseteq> err (opt A)" by auto |
|
135 |
finally have "set (?map ss2) \<subseteq> err (opt A)" . } |
|
136 |
ultimately |
|
137 |
have "?sum ss2 \<le>|r (OK s1)" using eosl x |
|
13074 | 138 |
by - (rule semilat.pp_lub, simp add: Err.sl_def) |
13070 | 139 |
also obtain s2 where sum2: "?sum ss2 = s2" by blast |
140 |
finally have "s2 \<le>|r (OK s1)" . |
|
141 |
with sum2 have "\<exists>s2. ?sum ss2 = s2 \<and> s2 \<le>|r (OK s1)" by blast |
|
142 |
} |
|
143 |
moreover |
|
144 |
from esl x ss2 have |
|
145 |
"merge cert f r pc ss2 x = |
|
146 |
(if \<forall>(pc', s')\<in>set ss2. pc' \<noteq> pc + 1 \<longrightarrow> s' \<le>|r (OK (cert!pc')) |
|
147 |
then map snd [(p', t')\<in>ss2 . p' = pc + 1] ++|f x |
|
148 |
else Err)" |
|
149 |
by (rule merge_def) |
|
150 |
ultimately show ?thesis by simp |
|
13064 | 151 |
qed |
152 |
||
153 |
||
154 |
lemma wtl_inst_mono: |
|
155 |
assumes wtl: "wtl_inst cert f r step pc s1 = OK s1'" |
|
13071 | 156 |
assumes less: "OK s2 \<le>|r (OK s1)" |
13064 | 157 |
assumes pc: "pc < n" |
13071 | 158 |
assumes s1: "s1 \<in> opt A" |
159 |
assumes s2: "s2 \<in> opt A" |
|
160 |
assumes esl: "err_semilat (A,r,f)" |
|
161 |
assumes cert: "cert_ok cert n A" |
|
162 |
assumes mono: "mono (Err.le (Opt.le r)) step n (err (opt A))" |
|
163 |
assumes pres: "pres_type step n (err (opt A))" |
|
13064 | 164 |
shows "\<exists>s2'. wtl_inst cert f r step pc s2 = OK s2' \<and> OK s2' \<le>|r (OK s1')" |
9549
40d64cb4f4e6
BV and LBV specified in terms of app and step functions
kleing
parents:
9376
diff
changeset
|
165 |
proof - |
13071 | 166 |
let "?step s1" = "step pc (OK s1)" |
167 |
let ?cert = "OK (cert!Suc pc)" |
|
168 |
from wtl |
|
169 |
have "merge cert f r pc (?step s1) ?cert = OK s1'" by (simp add: wtl_inst_def) |
|
170 |
moreover |
|
171 |
have s2: "OK s2 \<in> err (opt A)" by simp |
|
172 |
with mono have "?step s2 <=|Err.le (Opt.le r)| ?step s1" by - (rule monoD) |
|
173 |
moreover note esl |
|
174 |
moreover |
|
175 |
from pc cert have "?cert \<in> err (opt A)" by (simp add: cert_okD3) |
|
176 |
moreover |
|
177 |
have s1: "OK s1 \<in> err (opt A)" by simp |
|
178 |
with pres pc |
|
179 |
have "\<forall>(pc', s')\<in>set (?step s1). s' \<in> err (opt A)" |
|
180 |
by (blast intro: pres_typeD) |
|
181 |
moreover |
|
182 |
from pres s2 pc |
|
183 |
have "\<forall>(pc', s')\<in>set (?step s2). s' \<in> err (opt A)" |
|
184 |
by (blast intro: pres_typeD) |
|
185 |
ultimately |
|
186 |
obtain s2' where "merge cert f r pc (?step s2) ?cert = s2' \<and> s2' \<le>|r (OK s1')" |
|
187 |
by (blast dest: merge_mono) |
|
188 |
thus ?thesis by (simp add: wtl_inst_def) |
|
189 |
qed |
|
9012 | 190 |
|
13071 | 191 |
lemma wtl_cert_mono: |
192 |
assumes wtl: "wtl_cert cert f r step pc s1 = OK s1'" |
|
193 |
assumes less: "OK s2 \<le>|r (OK s1)" |
|
194 |
assumes pc: "pc < n" |
|
195 |
assumes s1: "s1 \<in> opt A" |
|
196 |
assumes s2: "s2 \<in> opt A" |
|
197 |
assumes esl: "err_semilat (A,r,f)" |
|
198 |
assumes cert: "cert_ok cert n A" |
|
199 |
assumes mono: "mono (Err.le (Opt.le r)) step n (err (opt A))" |
|
200 |
assumes pres: "pres_type step n (err (opt A))" |
|
201 |
shows "\<exists>s2'. wtl_cert cert f r step pc s2 = OK s2' \<and> OK s2' \<le>|r (OK s1')" |
|
202 |
proof (cases "cert!pc") |
|
203 |
case None |
|
204 |
with wtl have "wtl_inst cert f r step pc s1 = OK s1'" |
|
205 |
by (simp add: wtl_cert_def) |
|
206 |
hence "\<exists>s2'. wtl_inst cert f r step pc s2 = OK s2' \<and> OK s2' \<le>|r (OK s1')" |
|
207 |
by - (rule wtl_inst_mono) |
|
208 |
with None show ?thesis by (simp add: wtl_cert_def) |
|
209 |
next |
|
210 |
case (Some s') |
|
211 |
with wtl obtain |
|
212 |
wti: "wtl_inst cert f r step pc (Some s') = OK s1'" and |
|
213 |
s': "OK s1 \<le>|r OK (Some s')" |
|
214 |
by (auto simp add: wtl_cert_def split: split_if_asm) |
|
215 |
from esl have order: "order (Opt.le r)" by simp |
|
216 |
hence "order (Err.le (Opt.le r))" by simp |
|
217 |
with less s' have "OK s2 \<le>|r OK (Some s')" by - (drule order_trans) |
|
218 |
with Some wti order show ?thesis by (simp add: wtl_cert_def) |
|
9376 | 219 |
qed |
9757
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
220 |
|
9559 | 221 |
|
13071 | 222 |
lemma stable_wtl: |
223 |
assumes stable: "stable (Err.le (Opt.le r)) step (map OK phi) pc" |
|
224 |
assumes fits: "fits step cert phi" |
|
225 |
assumes pc: "pc < length phi" |
|
226 |
assumes bounded: "bounded step (length phi)" |
|
227 |
assumes esl: "err_semilat (A, r, f)" |
|
228 |
assumes cert_ok: "cert_ok cert (length phi) A" |
|
229 |
assumes phi_ok: "\<forall>pc < length phi. phi!pc \<in> opt A" |
|
230 |
assumes pres: "pres_type step (length phi) (err (opt A))" |
|
231 |
shows "wtl_inst cert f r step pc (phi!pc) \<noteq> Err" |
|
9559 | 232 |
proof - |
13071 | 233 |
from esl have order: "order (Opt.le r)" by simp |
9559 | 234 |
|
13071 | 235 |
let ?step = "step pc (OK (phi!pc))" |
236 |
from pc have [simp]: "map OK phi ! pc = OK (phi!pc)" by simp |
|
237 |
from stable |
|
238 |
have less: "\<forall>(q,s')\<in>set ?step. s' \<le>|r (map OK phi!q)" |
|
239 |
by (simp add: stable_def) |
|
240 |
||
241 |
from cert_ok pc |
|
242 |
have cert_suc: "OK (cert!Suc pc) \<in> err (opt A)" by (auto dest: cert_okD3) |
|
243 |
moreover |
|
244 |
from phi_ok pc |
|
245 |
have "OK (phi!pc) \<in> err (opt A)" by simp |
|
246 |
with pres pc |
|
247 |
have stepA: "\<forall>(pc',s') \<in> set ?step. s' \<in> err (opt A)" |
|
248 |
by (blast dest: pres_typeD) |
|
249 |
ultimately |
|
250 |
have "merge cert f r pc ?step (OK (cert!Suc pc)) = |
|
251 |
(if \<forall>(pc',s')\<in>set ?step. pc'\<noteq>pc+1 \<longrightarrow> s' \<le>|r (OK (cert!pc')) |
|
252 |
then map snd [(p',t')\<in>?step.p'=pc+1] ++|f (OK (cert!Suc pc)) |
|
253 |
else Err)" using esl by - (rule merge_def) |
|
254 |
moreover { |
|
255 |
fix pc' s' assume s': "(pc', s') \<in> set ?step" and suc_pc: "pc' \<noteq> pc+1" |
|
256 |
from bounded pc s' have pc': "pc' < length phi" by (rule boundedD) |
|
257 |
hence [simp]: "map OK phi ! pc' = OK (phi!pc')" by simp |
|
258 |
with s' less have "s' \<le>|r OK (phi!pc')" by auto |
|
259 |
also from fits s' suc_pc pc pc' |
|
260 |
have "cert!pc' = phi!pc'" by (rule fitsD) |
|
261 |
hence "phi!pc' = cert!pc'" .. |
|
262 |
finally have "s' \<le>|r (OK (cert!pc'))" . |
|
263 |
} hence "\<forall>(pc',s')\<in>set ?step. pc'\<noteq>pc+1 \<longrightarrow> s' \<le>|r (OK (cert!pc'))" by auto |
|
264 |
moreover |
|
265 |
from pc have "Suc pc = length phi \<or> Suc pc < length phi" by auto |
|
266 |
hence "(map snd [(p',t')\<in>?step.p'=pc+1] ++|f (OK (cert!Suc pc))) \<noteq> Err" |
|
267 |
(is "(?map ++|f _) \<noteq> _") |
|
268 |
proof (rule disjE) |
|
269 |
assume pc': "Suc pc = length phi" |
|
270 |
with cert_ok have "cert!Suc pc = None" by (simp add: cert_okD2) |
|
271 |
moreover |
|
272 |
from pc' bounded pc |
|
273 |
have "\<forall>(p',t')\<in>set ?step. p'\<noteq>pc+1" by clarify (drule boundedD, auto) |
|
274 |
hence "[(p',t')\<in>?step.p'=pc+1] = []" by (blast intro: filter_False) |
|
275 |
hence "?map = []" by simp |
|
276 |
ultimately show ?thesis by simp |
|
277 |
next |
|
278 |
assume pc': "Suc pc < length phi" |
|
279 |
hence [simp]: "map OK phi ! Suc pc = OK (phi!Suc pc)" by simp |
|
280 |
from esl |
|
281 |
have "semilat (err (opt A), Err.le (Opt.le r), lift2 (Opt.sup f))" |
|
282 |
by (simp add: Err.sl_def) |
|
283 |
moreover |
|
284 |
from pc' phi_ok |
|
285 |
have "OK (phi!Suc pc) \<in> err (opt A)" by simp |
|
286 |
moreover note cert_suc |
|
287 |
moreover from stepA |
|
288 |
have "snd`(set ?step) \<subseteq> err (opt A)" by auto |
|
289 |
hence "set ?map \<subseteq> err (opt A)" by auto |
|
290 |
moreover |
|
291 |
have "\<And>s. s \<in> set ?map \<Longrightarrow> \<exists>t. (Suc pc, t) \<in> set ?step" by auto |
|
292 |
with less have "\<forall>s' \<in> set ?map. s' \<le>|r OK (phi!Suc pc)" by auto |
|
293 |
moreover |
|
294 |
from order fits pc' |
|
295 |
have "OK (cert!Suc pc) \<le>|r OK (phi!Suc pc)" |
|
296 |
by (cases "cert!Suc pc") (simp, blast dest: fitsD2) |
|
297 |
ultimately |
|
13074 | 298 |
have "?map ++|f OK (cert!Suc pc) \<le>|r OK (phi!Suc pc)" |
299 |
by (rule semilat.pp_lub) |
|
13071 | 300 |
thus ?thesis by auto |
9559 | 301 |
qed |
13071 | 302 |
ultimately |
303 |
have "merge cert f r pc ?step (OK (cert!Suc pc)) \<noteq> Err" by simp |
|
304 |
thus ?thesis by (simp add: wtl_inst_def) |
|
9376 | 305 |
qed |
9012 | 306 |
|
13071 | 307 |
lemma stable_cert: |
308 |
assumes stable: "stable (Err.le (Opt.le r)) step (map OK phi) pc" |
|
309 |
assumes fits: "fits step cert phi" |
|
310 |
assumes pc: "pc < length phi" |
|
311 |
assumes bounded: "bounded step (length phi)" |
|
312 |
assumes esl: "err_semilat (A, r, f)" |
|
313 |
assumes cert_ok: "cert_ok cert (length phi) A" |
|
314 |
assumes phi_ok: "\<forall>pc < length phi. phi!pc \<in> opt A" |
|
315 |
assumes pres: "pres_type step (length phi) (err (opt A))" |
|
316 |
shows "wtl_cert cert f r step pc (phi!pc) \<noteq> Err" |
|
9757
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
317 |
proof - |
13071 | 318 |
have wtl: "wtl_inst cert f r step pc (phi!pc) \<noteq> Err" by (rule stable_wtl) |
319 |
show ?thesis |
|
320 |
proof (cases "cert!pc") |
|
321 |
case None with wtl show ?thesis by (simp add: wtl_cert_def) |
|
322 |
next |
|
323 |
case (Some s) |
|
324 |
with pc fits have "cert!pc = phi!pc" by - (rule fitsD2) |
|
325 |
with Some have "phi!pc = Some s" by simp |
|
326 |
with Some wtl esl show ?thesis by (simp add: wtl_cert_def) |
|
9549
40d64cb4f4e6
BV and LBV specified in terms of app and step functions
kleing
parents:
9376
diff
changeset
|
327 |
qed |
40d64cb4f4e6
BV and LBV specified in terms of app and step functions
kleing
parents:
9376
diff
changeset
|
328 |
qed |
9559 | 329 |
|
9012 | 330 |
|
13071 | 331 |
lemma wtl_less: |
332 |
assumes stable: "stable (Err.le (Opt.le r)) step (map OK phi) pc" |
|
333 |
assumes wtl: "wtl_inst cert f r step pc (phi!pc) = OK s" |
|
334 |
assumes fits: "fits step cert phi" |
|
335 |
assumes suc_pc: "Suc pc < length phi" |
|
336 |
assumes bounded: "bounded step (length phi)" |
|
337 |
assumes esl: "err_semilat (A, r, f)" |
|
338 |
assumes cert_ok: "cert_ok cert (length phi) A" |
|
339 |
assumes phi_ok: "\<forall>pc < length phi. phi!pc \<in> opt A" |
|
340 |
assumes pres: "pres_type step (length phi) (err (opt A))" |
|
341 |
shows "OK s \<le>|r OK (phi!Suc pc)" |
|
342 |
proof - |
|
343 |
from esl have order: "order (Opt.le r)" by simp |
|
344 |
||
345 |
let ?step = "step pc (OK (phi!pc))" |
|
346 |
from suc_pc have [simp]: "map OK phi ! pc = OK (phi!pc)" by simp |
|
347 |
from suc_pc have [simp]: "map OK phi ! Suc pc = OK (phi!Suc pc)" by simp |
|
348 |
from suc_pc have pc: "pc < length phi" by simp |
|
349 |
||
350 |
from stable |
|
351 |
have less: "\<forall>(q,s')\<in>set ?step. s' \<le>|r (map OK phi!q)" |
|
352 |
by (simp add: stable_def) |
|
353 |
||
354 |
from cert_ok pc |
|
355 |
have cert_suc: "OK (cert!Suc pc) \<in> err (opt A)" by (auto dest: cert_okD3) |
|
356 |
moreover |
|
357 |
from phi_ok pc |
|
358 |
have "OK (phi!pc) \<in> err (opt A)" by simp |
|
359 |
with pres pc |
|
360 |
have stepA: "\<forall>(pc',s') \<in> set ?step. s' \<in> err (opt A)" |
|
361 |
by (blast dest: pres_typeD) |
|
362 |
ultimately |
|
363 |
have "merge cert f r pc ?step (OK (cert!Suc pc)) = |
|
364 |
(if \<forall>(pc',s')\<in>set ?step. pc'\<noteq>pc+1 \<longrightarrow> s' \<le>|r (OK (cert!pc')) |
|
365 |
then map snd [(p',t')\<in>?step.p'=pc+1] ++|f (OK (cert!Suc pc)) |
|
366 |
else Err)" using esl by - (rule merge_def) |
|
367 |
with wtl have |
|
368 |
"OK s = (map snd [(p',t')\<in>?step.p'=pc+1] ++|f (OK (cert!Suc pc)))" |
|
369 |
(is "_ = (?map ++|f _)" is "_ = ?sum") |
|
370 |
by (simp add: wtl_inst_def split: split_if_asm) |
|
371 |
also { |
|
372 |
from esl |
|
373 |
have "semilat (err (opt A), Err.le (Opt.le r), lift2 (Opt.sup f))" |
|
374 |
by (simp add: Err.sl_def) |
|
375 |
moreover |
|
376 |
from suc_pc phi_ok |
|
377 |
have "OK (phi!Suc pc) \<in> err (opt A)" by simp |
|
378 |
moreover note cert_suc |
|
379 |
moreover from stepA |
|
380 |
have "snd`(set ?step) \<subseteq> err (opt A)" by auto |
|
381 |
hence "set ?map \<subseteq> err (opt A)" by auto |
|
382 |
moreover |
|
383 |
have "\<And>s. s \<in> set ?map \<Longrightarrow> \<exists>t. (Suc pc, t) \<in> set ?step" by auto |
|
384 |
with less have "\<forall>s' \<in> set ?map. s' \<le>|r OK (phi!Suc pc)" by auto |
|
385 |
moreover |
|
386 |
from order fits suc_pc |
|
387 |
have "OK (cert!Suc pc) \<le>|r OK (phi!Suc pc)" |
|
388 |
by (cases "cert!Suc pc") (simp, blast dest: fitsD2) |
|
389 |
ultimately |
|
13074 | 390 |
have "?sum \<le>|r OK (phi!Suc pc)" by (rule semilat.pp_lub) |
13071 | 391 |
} |
392 |
finally show ?thesis . |
|
393 |
qed |
|
9012 | 394 |
|
395 |
||
13071 | 396 |
lemma cert_less: |
397 |
assumes stable: "stable (Err.le (Opt.le r)) step (map OK phi) pc" |
|
398 |
assumes cert: "wtl_cert cert f r step pc (phi!pc) = OK s" |
|
399 |
assumes fits: "fits step cert phi" |
|
400 |
assumes suc_pc: "Suc pc < length phi" |
|
401 |
assumes bounded: "bounded step (length phi)" |
|
402 |
assumes esl: "err_semilat (A, r, f)" |
|
403 |
assumes cert_ok: "cert_ok cert (length phi) A" |
|
404 |
assumes phi_ok: "\<forall>pc < length phi. phi!pc \<in> opt A" |
|
405 |
assumes pres: "pres_type step (length phi) (err (opt A))" |
|
406 |
shows "OK s \<le>|r OK (phi!Suc pc)" |
|
407 |
proof (cases "cert!pc") |
|
408 |
case None with cert |
|
409 |
have "wtl_inst cert f r step pc (phi!pc) = OK s" by (simp add: wtl_cert_def) |
|
410 |
thus ?thesis by - (rule wtl_less) |
|
411 |
next |
|
412 |
case (Some s') with cert |
|
413 |
have "wtl_inst cert f r step pc (Some s') = OK s" |
|
414 |
by (simp add: wtl_cert_def split: split_if_asm) |
|
415 |
also |
|
416 |
from suc_pc have "pc < length phi" by simp |
|
417 |
with fits Some have "cert!pc = phi!pc" by - (rule fitsD2) |
|
418 |
with Some have "Some s' = phi!pc" by simp |
|
419 |
finally |
|
420 |
have "wtl_inst cert f r step pc (phi!pc) = OK s" . |
|
421 |
thus ?thesis by - (rule wtl_less) |
|
422 |
qed |
|
423 |
||
424 |
||
425 |
||
426 |
lemma wt_step_wtl_lemma: |
|
427 |
assumes wt_step: "wt_step (Err.le (Opt.le r)) Err step (map OK phi)" |
|
428 |
assumes fits: "fits step cert phi" |
|
429 |
assumes bounded: "bounded step (length phi)" |
|
430 |
assumes esl: "err_semilat (A, r, f)" |
|
431 |
assumes cert_ok: "cert_ok cert (length phi) A" |
|
432 |
assumes phi_ok: "\<forall>pc < length phi. phi!pc \<in> opt A" |
|
433 |
assumes pres: "pres_type step (length phi) (err (opt A))" |
|
434 |
assumes mono: "mono (Err.le (Opt.le r)) step (length phi) (err (opt A))" |
|
435 |
shows "\<And>pc s. pc+length ins = length phi \<Longrightarrow> OK s \<le>|r OK (phi!pc) \<Longrightarrow> s \<in> opt A \<Longrightarrow> |
|
436 |
wtl_inst_list ins cert f r step pc s \<noteq> Err" |
|
437 |
(is "\<And>pc s. _ \<Longrightarrow> _ \<Longrightarrow> _ \<Longrightarrow> ?wtl ins pc s \<noteq> Err") |
|
438 |
proof (induct ins) |
|
439 |
fix pc s show "?wtl [] pc s \<noteq> Err" by simp |
|
440 |
next |
|
441 |
fix pc s i ins |
|
442 |
assume "\<And>pc s. pc+length ins=length phi \<Longrightarrow> OK s \<le>|r OK (phi!pc) \<Longrightarrow> s \<in> opt A \<Longrightarrow> |
|
443 |
?wtl ins pc s \<noteq> Err" |
|
9757
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
444 |
moreover |
13071 | 445 |
assume pc_l: "pc + length (i#ins) = length phi" |
446 |
hence suc_pc_l: "Suc pc + length ins = length phi" by simp |
|
447 |
ultimately |
|
448 |
have IH: |
|
449 |
"\<And>s. OK s \<le>|r OK (phi!Suc pc) \<Longrightarrow> s \<in> opt A \<Longrightarrow> ?wtl ins (Suc pc) s \<noteq> Err" . |
|
450 |
||
451 |
from pc_l obtain pc: "pc < length phi" by simp |
|
452 |
with wt_step |
|
453 |
have stable: "stable (Err.le (Opt.le r)) step (map OK phi) pc" |
|
454 |
by (simp add: wt_step_def) |
|
455 |
moreover |
|
456 |
assume s_phi: "OK s \<le>|r OK (phi!pc)" |
|
457 |
ultimately |
|
458 |
have "wtl_cert cert f r step pc (phi!pc) \<noteq> Err" by - (rule stable_cert) |
|
459 |
then obtain s'' where s'': "wtl_cert cert f r step pc (phi!pc) = OK s''" by fast |
|
460 |
moreover |
|
461 |
from phi_ok pc |
|
462 |
have phi_pc: "phi!pc \<in> opt A" by simp |
|
463 |
moreover |
|
464 |
assume s: "s \<in> opt A" |
|
9757
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
kleing
parents:
9664
diff
changeset
|
465 |
ultimately |
13071 | 466 |
obtain s' where "wtl_cert cert f r step pc s = OK s'" |
467 |
by - (drule wtl_cert_mono, assumption+, blast) |
|
468 |
hence "ins = [] \<Longrightarrow> ?wtl (i#ins) pc s \<noteq> Err" by simp |
|
469 |
moreover { |
|
470 |
assume "ins \<noteq> []" |
|
471 |
with pc_l have suc_pc: "Suc pc < length phi" by (auto simp add: neq_Nil_conv) |
|
472 |
with stable s'' have "OK s'' \<le>|r OK (phi!Suc pc)" by - (rule cert_less) |
|
473 |
moreover |
|
474 |
from s'' s_phi obtain s' where |
|
475 |
cert: "wtl_cert cert f r step pc s = OK s'" and |
|
476 |
"OK s' \<le>|r OK s''" |
|
477 |
using phi_pc |
|
478 |
by - (drule wtl_cert_mono, assumption+, blast) |
|
479 |
moreover from esl have "order (Err.le (Opt.le r))" by simp |
|
480 |
ultimately have less: "OK s' \<le>|r OK (phi!Suc pc)" by - (rule order_trans) |
|
481 |
||
482 |
from cert_ok suc_pc have "cert!pc \<in> opt A" and "cert!(pc+1) \<in> opt A" |
|
483 |
by (auto simp add: cert_ok_def) |
|
484 |
with s cert pres have "s' \<in> opt A" by - (rule wtl_cert_pres) |
|
485 |
||
486 |
with less IH have "?wtl ins (Suc pc) s' \<noteq> Err" by blast |
|
487 |
with cert have "?wtl (i#ins) pc s \<noteq> Err" by simp |
|
488 |
} |
|
489 |
ultimately show "?wtl (i#ins) pc s \<noteq> Err" by (cases ins) auto |
|
9580 | 490 |
qed |
9012 | 491 |
|
492 |
||
10628 | 493 |
theorem wtl_complete: |
13071 | 494 |
assumes "wt_step (Err.le (Opt.le r)) Err step (map OK phi)" |
495 |
assumes "OK s \<le>|r OK (phi!0)" and "s \<in> opt A" |
|
496 |
defines cert: "cert \<equiv> make_cert step phi" |
|
497 |
||
498 |
assumes "bounded step (length phi)" and "err_semilat (A, r, f)" |
|
499 |
assumes "pres_type step (length phi) (err (opt A))" |
|
500 |
assumes "mono (Err.le (Opt.le r)) step (length phi) (err (opt A))" |
|
501 |
assumes "length ins = length phi" |
|
502 |
assumes phi_ok: "\<forall>pc < length phi. phi!pc \<in> opt A" |
|
503 |
||
504 |
shows "wtl_inst_list ins cert f r step 0 s \<noteq> Err" |
|
10628 | 505 |
proof - |
13071 | 506 |
have "0+length ins = length phi" by simp |
507 |
moreover |
|
508 |
have "fits step cert phi" by (unfold cert) (rule fits_make_cert) |
|
509 |
moreover |
|
510 |
from phi_ok have "cert_ok cert (length phi) A" |
|
511 |
by (simp add: cert make_cert_def cert_ok_def nth_append) |
|
512 |
ultimately |
|
513 |
show ?thesis by - (rule wt_step_wtl_lemma) |
|
514 |
qed |
|
10592 | 515 |
|
9549
40d64cb4f4e6
BV and LBV specified in terms of app and step functions
kleing
parents:
9376
diff
changeset
|
516 |
|
40d64cb4f4e6
BV and LBV specified in terms of app and step functions
kleing
parents:
9376
diff
changeset
|
517 |
end |