17 opstack_type = "ty list" |
17 opstack_type = "ty list" |
18 state_type = "opstack_type \<times> locvars_type" |
18 state_type = "opstack_type \<times> locvars_type" |
19 |
19 |
20 |
20 |
21 consts |
21 consts |
22 strict :: "('a \<Rightarrow> 'b err) \<Rightarrow> ('a err \<Rightarrow> 'b err)" |
22 strict :: "('a => 'b err) => ('a err => 'b err)" |
23 primrec |
23 primrec |
24 "strict f Err = Err" |
24 "strict f Err = Err" |
25 "strict f (Ok x) = f x" |
25 "strict f (Ok x) = f x" |
26 |
26 |
|
27 |
27 consts |
28 consts |
28 opt_map :: "('a \<Rightarrow> 'b) \<Rightarrow> ('a option \<Rightarrow> 'b option)" |
29 val :: "'a err => 'a" |
29 primrec |
|
30 "opt_map f None = None" |
|
31 "opt_map f (Some x) = Some (f x)" |
|
32 |
|
33 consts |
|
34 val :: "'a err \<Rightarrow> 'a" |
|
35 primrec |
30 primrec |
36 "val (Ok s) = s" |
31 "val (Ok s) = s" |
37 |
32 |
38 |
33 |
39 constdefs |
34 constdefs |
40 (* lifts a relation to err with Err as top element *) |
35 (* lifts a relation to err with Err as top element *) |
41 lift_top :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> ('a err \<Rightarrow> 'b err \<Rightarrow> bool)" |
36 lift_top :: "('a => 'b => bool) => ('a err => 'b err => bool)" |
42 "lift_top P a' a \<equiv> case a of |
37 "lift_top P a' a == case a of |
43 Err \<Rightarrow> True |
38 Err => True |
44 | Ok t \<Rightarrow> (case a' of Err \<Rightarrow> False | Ok t' \<Rightarrow> P t' t)" |
39 | Ok t => (case a' of Err => False | Ok t' => P t' t)" |
45 |
40 |
46 (* lifts a relation to option with None as bottom element *) |
41 (* lifts a relation to option with None as bottom element *) |
47 lift_bottom :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> ('a option \<Rightarrow> 'b option \<Rightarrow> bool)" |
42 lift_bottom :: "('a => 'b => bool) => ('a option => 'b option => bool)" |
48 "lift_bottom P a' a \<equiv> case a' of |
43 "lift_bottom P a' a == case a' of |
49 None \<Rightarrow> True |
44 None => True |
50 | Some t' \<Rightarrow> (case a of None \<Rightarrow> False | Some t \<Rightarrow> P t' t)" |
45 | Some t' => (case a of None => False | Some t => P t' t)" |
51 |
46 |
52 sup_ty_opt :: "['code prog,ty err,ty err] \<Rightarrow> bool" ("_ \<turnstile>_ <=o _") |
47 sup_ty_opt :: "['code prog,ty err,ty err] => bool" ("_ \<turnstile> _ <=o _" [71,71] 70) |
53 "sup_ty_opt G \<equiv> lift_top (\<lambda>t t'. G \<turnstile> t \<preceq> t')" |
48 "sup_ty_opt G == lift_top (\<lambda>t t'. G \<turnstile> t \<preceq> t')" |
54 |
49 |
55 sup_loc :: "['code prog,locvars_type,locvars_type] \<Rightarrow> bool" |
50 sup_loc :: "['code prog,locvars_type,locvars_type] => bool" |
56 ("_ \<turnstile> _ <=l _" [71,71] 70) |
51 ("_ \<turnstile> _ <=l _" [71,71] 70) |
57 "G \<turnstile> LT <=l LT' \<equiv> list_all2 (\<lambda>t t'. (G \<turnstile> t <=o t')) LT LT'" |
52 "G \<turnstile> LT <=l LT' == list_all2 (\<lambda>t t'. (G \<turnstile> t <=o t')) LT LT'" |
58 |
53 |
59 sup_state :: "['code prog,state_type,state_type] \<Rightarrow> bool" |
54 sup_state :: "['code prog,state_type,state_type] => bool" |
60 ("_ \<turnstile> _ <=s _" [71,71] 70) |
55 ("_ \<turnstile> _ <=s _" [71,71] 70) |
61 "G \<turnstile> s <=s s' \<equiv> (G \<turnstile> map Ok (fst s) <=l map Ok (fst s')) \<and> G \<turnstile> snd s <=l snd s'" |
56 "G \<turnstile> s <=s s' == (G \<turnstile> map Ok (fst s) <=l map Ok (fst s')) \<and> G \<turnstile> snd s <=l snd s'" |
62 |
57 |
63 sup_state_opt :: "['code prog,state_type option,state_type option] \<Rightarrow> bool" |
58 sup_state_opt :: "['code prog,state_type option,state_type option] => bool" |
64 ("_ \<turnstile> _ <=' _" [71,71] 70) |
59 ("_ \<turnstile> _ <=' _" [71,71] 70) |
65 "sup_state_opt G \<equiv> lift_bottom (\<lambda>t t'. G \<turnstile> t <=s t')" |
60 "sup_state_opt G == lift_bottom (\<lambda>t t'. G \<turnstile> t <=s t')" |
66 |
61 |
|
62 syntax (HTML output) |
|
63 sup_ty_opt :: "['code prog,ty err,ty err] => bool" ("_ |- _ <=o _") |
|
64 sup_loc :: "['code prog,locvars_type,locvars_type] => bool" ("_ |- _ <=l _" [71,71] 70) |
|
65 sup_state :: "['code prog,state_type,state_type] => bool" ("_ |- _ <=s _" [71,71] 70) |
|
66 sup_state_opt :: "['code prog,state_type option,state_type option] => bool" ("_ |- _ <=' _" [71,71] 70) |
|
67 |
67 |
68 |
68 lemma not_Err_eq [iff]: |
69 lemma not_Err_eq [iff]: |
69 "(x \<noteq> Err) = (\<exists>a. x = Ok a)" |
70 "(x \<noteq> Err) = (\<exists>a. x = Ok a)" |
70 by (cases x) auto |
71 by (cases x) auto |
71 |
72 |
221 theorem OkanyConvOk [simp]: |
222 theorem OkanyConvOk [simp]: |
222 "(G \<turnstile> (Ok ty') <=o (Ok ty)) = (G \<turnstile> ty' \<preceq> ty)" |
223 "(G \<turnstile> (Ok ty') <=o (Ok ty)) = (G \<turnstile> ty' \<preceq> ty)" |
223 by (simp add: sup_ty_opt_def) |
224 by (simp add: sup_ty_opt_def) |
224 |
225 |
225 theorem sup_ty_opt_Ok: |
226 theorem sup_ty_opt_Ok: |
226 "G \<turnstile> a <=o (Ok b) \<Longrightarrow> \<exists> x. a = Ok x" |
227 "G \<turnstile> a <=o (Ok b) ==> \<exists> x. a = Ok x" |
227 by (clarsimp simp add: sup_ty_opt_def) |
228 by (clarsimp simp add: sup_ty_opt_def) |
228 |
229 |
229 lemma widen_PrimT_conv1 [simp]: |
230 lemma widen_PrimT_conv1 [simp]: |
230 "[| G \<turnstile> S \<preceq> T; S = PrimT x|] ==> T = PrimT x" |
231 "[| G \<turnstile> S \<preceq> T; S = PrimT x|] ==> T = PrimT x" |
231 by (auto elim: widen.elims) |
232 by (auto elim: widen.elims) |
248 "(G \<turnstile> YT <=l (X#XT)) = (\<exists>Y YT'. YT=Y#YT' \<and> (G \<turnstile> Y <=o X) \<and> (G \<turnstile> YT' <=l XT))" |
249 "(G \<turnstile> YT <=l (X#XT)) = (\<exists>Y YT'. YT=Y#YT' \<and> (G \<turnstile> Y <=o X) \<and> (G \<turnstile> YT' <=l XT))" |
249 by (simp add: sup_loc_def list_all2_Cons2) |
250 by (simp add: sup_loc_def list_all2_Cons2) |
250 |
251 |
251 |
252 |
252 theorem sup_loc_length: |
253 theorem sup_loc_length: |
253 "G \<turnstile> a <=l b \<Longrightarrow> length a = length b" |
254 "G \<turnstile> a <=l b ==> length a = length b" |
254 proof - |
255 proof - |
255 assume G: "G \<turnstile> a <=l b" |
256 assume G: "G \<turnstile> a <=l b" |
256 have "\<forall> b. (G \<turnstile> a <=l b) \<longrightarrow> length a = length b" |
257 have "\<forall> b. (G \<turnstile> a <=l b) --> length a = length b" |
257 by (induct a, auto) |
258 by (induct a, auto) |
258 with G |
259 with G |
259 show ?thesis by blast |
260 show ?thesis by blast |
260 qed |
261 qed |
261 |
262 |
262 theorem sup_loc_nth: |
263 theorem sup_loc_nth: |
263 "[| G \<turnstile> a <=l b; n < length a |] ==> G \<turnstile> (a!n) <=o (b!n)" |
264 "[| G \<turnstile> a <=l b; n < length a |] ==> G \<turnstile> (a!n) <=o (b!n)" |
264 proof - |
265 proof - |
265 assume a: "G \<turnstile> a <=l b" "n < length a" |
266 assume a: "G \<turnstile> a <=l b" "n < length a" |
266 have "\<forall> n b. (G \<turnstile> a <=l b) \<longrightarrow> n < length a \<longrightarrow> (G \<turnstile> (a!n) <=o (b!n))" |
267 have "\<forall> n b. (G \<turnstile> a <=l b) --> n < length a --> (G \<turnstile> (a!n) <=o (b!n))" |
267 (is "?P a") |
268 (is "?P a") |
268 proof (induct a) |
269 proof (induct a) |
269 show "?P []" by simp |
270 show "?P []" by simp |
270 |
271 |
271 fix x xs assume IH: "?P xs" |
272 fix x xs assume IH: "?P xs" |
283 show ?thesis by blast |
284 show ?thesis by blast |
284 qed |
285 qed |
285 |
286 |
286 |
287 |
287 theorem all_nth_sup_loc: |
288 theorem all_nth_sup_loc: |
288 "\<forall>b. length a = length b \<longrightarrow> (\<forall> n. n < length a \<longrightarrow> (G \<turnstile> (a!n) <=o (b!n))) \<longrightarrow> |
289 "\<forall>b. length a = length b --> (\<forall> n. n < length a --> (G \<turnstile> (a!n) <=o (b!n))) --> |
289 (G \<turnstile> a <=l b)" (is "?P a") |
290 (G \<turnstile> a <=l b)" (is "?P a") |
290 proof (induct a) |
291 proof (induct a) |
291 show "?P []" by simp |
292 show "?P []" by simp |
292 |
293 |
293 fix l ls assume IH: "?P ls" |
294 fix l ls assume IH: "?P ls" |
294 |
295 |
295 show "?P (l#ls)" |
296 show "?P (l#ls)" |
296 proof (intro strip) |
297 proof (intro strip) |
297 fix b |
298 fix b |
298 assume f: "\<forall>n. n < length (l # ls) \<longrightarrow> (G \<turnstile> ((l # ls) ! n) <=o (b ! n))" |
299 assume f: "\<forall>n. n < length (l # ls) --> (G \<turnstile> ((l # ls) ! n) <=o (b ! n))" |
299 assume l: "length (l#ls) = length b" |
300 assume l: "length (l#ls) = length b" |
300 |
301 |
301 then obtain b' bs where b: "b = b'#bs" |
302 then obtain b' bs where b: "b = b'#bs" |
302 by - (cases b, simp, simp add: neq_Nil_conv, rule that) |
303 by - (cases b, simp, simp add: neq_Nil_conv, rule that) |
303 |
304 |
304 with f |
305 with f |
305 have "\<forall>n. n < length ls \<longrightarrow> (G \<turnstile> (ls!n) <=o (bs!n))" |
306 have "\<forall>n. n < length ls --> (G \<turnstile> (ls!n) <=o (bs!n))" |
306 by auto |
307 by auto |
307 |
308 |
308 with f b l IH |
309 with f b l IH |
309 show "G \<turnstile> (l # ls) <=l b" |
310 show "G \<turnstile> (l # ls) <=l b" |
310 by auto |
311 by auto |
425 "(G \<turnstile> (xt, a) <=s (y#yt, b)) = |
426 "(G \<turnstile> (xt, a) <=s (y#yt, b)) = |
426 (\<exists>x xt'. xt=x#xt' \<and> (G \<turnstile> x \<preceq> y) \<and> (G \<turnstile> (xt',a) <=s (yt,b)))" |
427 (\<exists>x xt'. xt=x#xt' \<and> (G \<turnstile> x \<preceq> y) \<and> (G \<turnstile> (xt',a) <=s (yt,b)))" |
427 by (auto simp add: sup_state_def map_eq_Cons sup_loc_Cons2) |
428 by (auto simp add: sup_state_def map_eq_Cons sup_loc_Cons2) |
428 |
429 |
429 theorem sup_state_ignore_fst: |
430 theorem sup_state_ignore_fst: |
430 "G \<turnstile> (a, x) <=s (b, y) \<Longrightarrow> G \<turnstile> (c, x) <=s (c, y)" |
431 "G \<turnstile> (a, x) <=s (b, y) ==> G \<turnstile> (c, x) <=s (c, y)" |
431 by (simp add: sup_state_def) |
432 by (simp add: sup_state_def) |
432 |
433 |
433 theorem sup_state_rev_fst: |
434 theorem sup_state_rev_fst: |
434 "(G \<turnstile> (rev a, x) <=s (rev b, y)) = (G \<turnstile> (a, x) <=s (b, y))" |
435 "(G \<turnstile> (rev a, x) <=s (rev b, y)) = (G \<turnstile> (a, x) <=s (b, y))" |
435 proof - |
436 proof - |
458 "(G \<turnstile> any <=' (Some b)) = (any = None \<or> (\<exists>a. any = Some a \<and> G \<turnstile> a <=s b))" |
459 "(G \<turnstile> any <=' (Some b)) = (any = None \<or> (\<exists>a. any = Some a \<and> G \<turnstile> a <=s b))" |
459 by (simp add: sup_state_opt_def lift_bottom_Some_any) |
460 by (simp add: sup_state_opt_def lift_bottom_Some_any) |
460 |
461 |
461 |
462 |
462 theorem sup_ty_opt_trans [trans]: |
463 theorem sup_ty_opt_trans [trans]: |
463 "\<lbrakk>G \<turnstile> a <=o b; G \<turnstile> b <=o c\<rbrakk> \<Longrightarrow> G \<turnstile> a <=o c" |
464 "[|G \<turnstile> a <=o b; G \<turnstile> b <=o c|] ==> G \<turnstile> a <=o c" |
464 by (auto intro: lift_top_trans widen_trans simp add: sup_ty_opt_def) |
465 by (auto intro: lift_top_trans widen_trans simp add: sup_ty_opt_def) |
465 |
466 |
466 theorem sup_loc_trans [trans]: |
467 theorem sup_loc_trans [trans]: |
467 "\<lbrakk>G \<turnstile> a <=l b; G \<turnstile> b <=l c\<rbrakk> \<Longrightarrow> G \<turnstile> a <=l c" |
468 "[|G \<turnstile> a <=l b; G \<turnstile> b <=l c|] ==> G \<turnstile> a <=l c" |
468 proof - |
469 proof - |
469 assume G: "G \<turnstile> a <=l b" "G \<turnstile> b <=l c" |
470 assume G: "G \<turnstile> a <=l b" "G \<turnstile> b <=l c" |
470 |
471 |
471 hence "\<forall> n. n < length a \<longrightarrow> (G \<turnstile> (a!n) <=o (c!n))" |
472 hence "\<forall> n. n < length a --> (G \<turnstile> (a!n) <=o (c!n))" |
472 proof (intro strip) |
473 proof (intro strip) |
473 fix n |
474 fix n |
474 assume n: "n < length a" |
475 assume n: "n < length a" |
475 with G |
476 with G |
476 have "G \<turnstile> (a!n) <=o (b!n)" |
477 have "G \<turnstile> (a!n) <=o (b!n)" |