4 Copyright 1999 Technische Universitaet Muenchen |
4 Copyright 1999 Technische Universitaet Muenchen |
5 *) |
5 *) |
6 |
6 |
7 header "Lifted Type Relations" |
7 header "Lifted Type Relations" |
8 |
8 |
9 theory Convert = JVMExec: |
9 theory Convert = Err + JVMExec: |
10 |
10 |
11 text "The supertype relation lifted to type err, type lists and state types." |
11 text "The supertype relation lifted to type err, type lists and state types." |
12 |
|
13 datatype 'a err = Err | Ok 'a |
|
14 |
12 |
15 types |
13 types |
16 locvars_type = "ty err list" |
14 locvars_type = "ty err list" |
17 opstack_type = "ty list" |
15 opstack_type = "ty list" |
18 state_type = "opstack_type \<times> locvars_type" |
16 state_type = "opstack_type \<times> locvars_type" |
19 |
17 method_type = "state_type option list" |
|
18 class_type = "sig => method_type" |
|
19 prog_type = "cname => class_type" |
20 |
20 |
21 consts |
21 consts |
22 strict :: "('a => 'b err) => ('a err => '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 |
|
27 |
|
28 consts |
|
29 val :: "'a err => 'a" |
|
30 primrec |
|
31 "val (Ok s) = s" |
|
32 |
26 |
33 |
27 |
34 constdefs |
28 constdefs |
35 (* lifts a relation to err with Err as top element *) |
29 (* lifts a relation to err with Err as top element *) |
36 lift_top :: "('a => 'b => bool) => ('a err => 'b err => bool)" |
30 lift_top :: "('a => 'b => bool) => ('a err => 'b err => bool)" |
37 "lift_top P a' a == case a of |
31 "lift_top P a' a == case a of |
38 Err => True |
32 Err => True |
39 | Ok t => (case a' of Err => False | Ok t' => P t' t)" |
33 | OK t => (case a' of Err => False | OK t' => P t' t)" |
40 |
34 |
41 (* lifts a relation to option with None as bottom element *) |
35 (* lifts a relation to option with None as bottom element *) |
42 lift_bottom :: "('a => 'b => bool) => ('a option => 'b option => bool)" |
36 lift_bottom :: "('a => 'b => bool) => ('a option => 'b option => bool)" |
43 "lift_bottom P a' a == |
37 "lift_bottom P a' a == |
44 case a' of |
38 case a' of |
54 "G \<turnstile> LT <=l LT' == list_all2 (\<lambda>t t'. (G \<turnstile> t <=o t')) LT LT'" |
48 "G \<turnstile> LT <=l LT' == list_all2 (\<lambda>t t'. (G \<turnstile> t <=o t')) LT LT'" |
55 |
49 |
56 sup_state :: "['code prog,state_type,state_type] => bool" |
50 sup_state :: "['code prog,state_type,state_type] => bool" |
57 ("_ \<turnstile> _ <=s _" [71,71] 70) |
51 ("_ \<turnstile> _ <=s _" [71,71] 70) |
58 "G \<turnstile> s <=s s' == |
52 "G \<turnstile> s <=s s' == |
59 (G \<turnstile> map Ok (fst s) <=l map Ok (fst s')) \<and> G \<turnstile> snd s <=l snd s'" |
53 (G \<turnstile> map OK (fst s) <=l map OK (fst s')) \<and> G \<turnstile> snd s <=l snd s'" |
60 |
54 |
61 sup_state_opt :: "['code prog,state_type option,state_type option] => bool" |
55 sup_state_opt :: "['code prog,state_type option,state_type option] => bool" |
62 ("_ \<turnstile> _ <=' _" [71,71] 70) |
56 ("_ \<turnstile> _ <=' _" [71,71] 70) |
63 "sup_state_opt G == lift_bottom (\<lambda>t t'. G \<turnstile> t <=s t')" |
57 "sup_state_opt G == lift_bottom (\<lambda>t t'. G \<turnstile> t <=s t')" |
64 |
58 |
71 ("_ |- _ <=s _" [71,71] 70) |
65 ("_ |- _ <=s _" [71,71] 70) |
72 sup_state_opt :: "['code prog,state_type option,state_type option] => bool" |
66 sup_state_opt :: "['code prog,state_type option,state_type option] => bool" |
73 ("_ |- _ <=' _" [71,71] 70) |
67 ("_ |- _ <=' _" [71,71] 70) |
74 |
68 |
75 |
69 |
76 lemma not_Err_eq [iff]: |
70 lemmas [iff] = not_Err_eq not_OK_eq |
77 "(x \<noteq> Err) = (\<exists>a. x = Ok a)" |
|
78 by (cases x) auto |
|
79 |
|
80 lemma not_Some_eq [iff]: |
|
81 "(\<forall>y. x \<noteq> Ok y) = (x = Err)" |
|
82 by (cases x) auto |
|
83 |
|
84 |
71 |
85 lemma lift_top_refl [simp]: |
72 lemma lift_top_refl [simp]: |
86 "[| !!x. P x x |] ==> lift_top P x x" |
73 "[| !!x. P x x |] ==> lift_top P x x" |
87 by (simp add: lift_top_def split: err.splits) |
74 by (simp add: lift_top_def split: err.splits) |
88 |
75 |
103 have ?thesis |
90 have ?thesis |
104 by (simp add: lift_top_def split: err.splits) |
91 by (simp add: lift_top_def split: err.splits) |
105 } note x_none = this |
92 } note x_none = this |
106 |
93 |
107 { fix r t |
94 { fix r t |
108 assume x: "x = Ok r" and z: "z = Ok t" |
95 assume x: "x = OK r" and z: "z = OK t" |
109 with a b |
96 with a b |
110 obtain s where y: "y = Ok s" |
97 obtain s where y: "y = OK s" |
111 by (simp add: lift_top_def split: err.splits) |
98 by (simp add: lift_top_def split: err.splits) |
112 |
99 |
113 from a x y |
100 from a x y |
114 have "P r s" by (simp add: lift_top_def) |
101 have "P r s" by (simp add: lift_top_def) |
115 also |
102 also |
128 |
115 |
129 lemma lift_top_Err_any [simp]: |
116 lemma lift_top_Err_any [simp]: |
130 "lift_top P Err any = (any = Err)" |
117 "lift_top P Err any = (any = Err)" |
131 by (simp add: lift_top_def split: err.splits) |
118 by (simp add: lift_top_def split: err.splits) |
132 |
119 |
133 lemma lift_top_Ok_Ok [simp]: |
120 lemma lift_top_OK_OK [simp]: |
134 "lift_top P (Ok a) (Ok b) = P a b" |
121 "lift_top P (OK a) (OK b) = P a b" |
135 by (simp add: lift_top_def split: err.splits) |
122 by (simp add: lift_top_def split: err.splits) |
136 |
123 |
137 lemma lift_top_any_Ok [simp]: |
124 lemma lift_top_any_OK [simp]: |
138 "lift_top P any (Ok b) = (\<exists>a. any = Ok a \<and> P a b)" |
125 "lift_top P any (OK b) = (\<exists>a. any = OK a \<and> P a b)" |
139 by (simp add: lift_top_def split: err.splits) |
126 by (simp add: lift_top_def split: err.splits) |
140 |
127 |
141 lemma lift_top_Ok_any: |
128 lemma lift_top_OK_any: |
142 "lift_top P (Ok a) any = (any = Err \<or> (\<exists>b. any = Ok b \<and> P a b))" |
129 "lift_top P (OK a) any = (any = Err \<or> (\<exists>b. any = OK b \<and> P a b))" |
143 by (simp add: lift_top_def split: err.splits) |
130 by (simp add: lift_top_def split: err.splits) |
144 |
131 |
145 |
132 |
146 lemma lift_bottom_refl [simp]: |
133 lemma lift_bottom_refl [simp]: |
147 "[| !!x. P x x |] ==> lift_bottom P x x" |
134 "[| !!x. P x x |] ==> lift_bottom P x x" |
225 |
212 |
226 theorem anyConvErr [simp]: |
213 theorem anyConvErr [simp]: |
227 "(G \<turnstile> Err <=o any) = (any = Err)" |
214 "(G \<turnstile> Err <=o any) = (any = Err)" |
228 by (simp add: sup_ty_opt_def) |
215 by (simp add: sup_ty_opt_def) |
229 |
216 |
230 theorem OkanyConvOk [simp]: |
217 theorem OKanyConvOK [simp]: |
231 "(G \<turnstile> (Ok ty') <=o (Ok ty)) = (G \<turnstile> ty' \<preceq> ty)" |
218 "(G \<turnstile> (OK ty') <=o (OK ty)) = (G \<turnstile> ty' \<preceq> ty)" |
232 by (simp add: sup_ty_opt_def) |
219 by (simp add: sup_ty_opt_def) |
233 |
220 |
234 theorem sup_ty_opt_Ok: |
221 theorem sup_ty_opt_OK: |
235 "G \<turnstile> a <=o (Ok b) ==> \<exists> x. a = Ok x" |
222 "G \<turnstile> a <=o (OK b) ==> \<exists> x. a = OK x" |
236 by (clarsimp simp add: sup_ty_opt_def) |
223 by (clarsimp simp add: sup_ty_opt_def) |
237 |
224 |
238 lemma widen_PrimT_conv1 [simp]: |
225 lemma widen_PrimT_conv1 [simp]: |
239 "[| G \<turnstile> S \<preceq> T; S = PrimT x|] ==> T = PrimT x" |
226 "[| G \<turnstile> S \<preceq> T; S = PrimT x|] ==> T = PrimT x" |
240 by (auto elim: widen.elims) |
227 by (auto elim: widen.elims) |
241 |
228 |
242 theorem sup_PTS_eq: |
229 theorem sup_PTS_eq: |
243 "(G \<turnstile> Ok (PrimT p) <=o X) = (X=Err \<or> X = Ok (PrimT p))" |
230 "(G \<turnstile> OK (PrimT p) <=o X) = (X=Err \<or> X = OK (PrimT p))" |
244 by (auto simp add: sup_ty_opt_def lift_top_Ok_any) |
231 by (auto simp add: sup_ty_opt_def lift_top_OK_any) |
245 |
232 |
246 |
233 |
247 |
234 |
248 theorem sup_loc_Nil [iff]: |
235 theorem sup_loc_Nil [iff]: |
249 "(G \<turnstile> [] <=l XT) = (XT=[])" |
236 "(G \<turnstile> [] <=l XT) = (XT=[])" |