| author | wenzelm | 
| Sun, 04 Mar 2012 19:24:05 +0100 | |
| changeset 46815 | 6bccb1dc9bc3 | 
| parent 42150 | b0c0638c4aad | 
| child 56073 | 29e308b56d23 | 
| permissions | -rw-r--r-- | 
| 42150 | 1 | (* Title: HOL/MicroJava/BV/EffectMono.thy | 
| 12516 | 2 | Author: Gerwin Klein | 
| 3 | Copyright 2000 Technische Universitaet Muenchen | |
| 4 | *) | |
| 5 | ||
| 12911 | 6 | header {* \isaheader{Monotonicity of eff and app} *}
 | 
| 12516 | 7 | |
| 33954 
1bc3b688548c
backported parts of abstract byte code verifier from AFP/Jinja
 haftmann parents: 
25362diff
changeset | 8 | theory EffectMono | 
| 
1bc3b688548c
backported parts of abstract byte code verifier from AFP/Jinja
 haftmann parents: 
25362diff
changeset | 9 | imports Effect | 
| 
1bc3b688548c
backported parts of abstract byte code verifier from AFP/Jinja
 haftmann parents: 
25362diff
changeset | 10 | begin | 
| 12516 | 11 | |
| 12 | lemma PrimT_PrimT: "(G \<turnstile> xb \<preceq> PrimT p) = (xb = PrimT p)" | |
| 22271 | 13 | by (auto elim: widen.cases) | 
| 12516 | 14 | |
| 15 | ||
| 16 | lemma sup_loc_some [rule_format]: | |
| 13006 | 17 | "\<forall>y n. (G \<turnstile> b <=l y) \<longrightarrow> n < length y \<longrightarrow> y!n = OK t \<longrightarrow> | 
| 34915 | 18 | (\<exists>t. b!n = OK t \<and> (G \<turnstile> (b!n) <=o (y!n)))" | 
| 19 | proof (induct b) | |
| 20 | case Nil | |
| 21 | show ?case by simp | |
| 25362 | 22 | next | 
| 23 | case (Cons a list) | |
| 34915 | 24 | show ?case | 
| 12516 | 25 | proof (clarsimp simp add: list_all2_Cons1 sup_loc_def Listn.le_def lesub_def) | 
| 26 | fix z zs n | |
| 25362 | 27 | assume *: | 
| 12516 | 28 | "G \<turnstile> a <=o z" "list_all2 (sup_ty_opt G) list zs" | 
| 29 | "n < Suc (length list)" "(z # zs) ! n = OK t" | |
| 30 | ||
| 31 | show "(\<exists>t. (a # list) ! n = OK t) \<and> G \<turnstile>(a # list) ! n <=o OK t" | |
| 32 | proof (cases n) | |
| 33 | case 0 | |
| 34 | with * show ?thesis by (simp add: sup_ty_opt_OK) | |
| 35 | next | |
| 36 | case Suc | |
| 37 | with Cons * | |
| 38 | show ?thesis by (simp add: sup_loc_def Listn.le_def lesub_def) | |
| 39 | qed | |
| 40 | qed | |
| 41 | qed | |
| 42 | ||
| 43 | ||
| 44 | lemma all_widen_is_sup_loc: | |
| 13006 | 45 | "\<forall>b. length a = length b \<longrightarrow> | 
| 22271 | 46 | (\<forall>(x, y)\<in>set (zip a b). G \<turnstile> x \<preceq> y) = (G \<turnstile> (map OK a) <=l (map OK b))" | 
| 13006 | 47 | (is "\<forall>b. length a = length b \<longrightarrow> ?Q a b" is "?P a") | 
| 12516 | 48 | proof (induct "a") | 
| 49 | show "?P []" by simp | |
| 50 | ||
| 51 | fix l ls assume Cons: "?P ls" | |
| 52 | ||
| 53 | show "?P (l#ls)" | |
| 54 | proof (intro allI impI) | |
| 55 | fix b | |
| 56 | assume "length (l # ls) = length (b::ty list)" | |
| 57 | with Cons | |
| 58 | show "?Q (l # ls) b" by - (cases b, auto) | |
| 59 | qed | |
| 60 | qed | |
| 61 | ||
| 62 | ||
| 63 | lemma append_length_n [rule_format]: | |
| 34915 | 64 | "\<forall>n. n \<le> length x \<longrightarrow> (\<exists>a b. x = a@b \<and> length a = n)" | 
| 65 | proof (induct x) | |
| 66 | case Nil | |
| 67 | show ?case by simp | |
| 25362 | 68 | next | 
| 34915 | 69 | case (Cons l ls) | 
| 12516 | 70 | |
| 34915 | 71 | show ?case | 
| 12516 | 72 | proof (intro allI impI) | 
| 73 | fix n | |
| 74 | assume l: "n \<le> length (l # ls)" | |
| 75 | ||
| 76 | show "\<exists>a b. l # ls = a @ b \<and> length a = n" | |
| 77 | proof (cases n) | |
| 78 | assume "n=0" thus ?thesis by simp | |
| 79 | next | |
| 80 | fix n' assume s: "n = Suc n'" | |
| 81 | with l have "n' \<le> length ls" by simp | |
| 82 | hence "\<exists>a b. ls = a @ b \<and> length a = n'" by (rule Cons [rule_format]) | |
| 17589 | 83 | then obtain a b where "ls = a @ b" "length a = n'" by iprover | 
| 12516 | 84 | with s have "l # ls = (l#a) @ b \<and> length (l#a) = n" by simp | 
| 85 | thus ?thesis by blast | |
| 86 | qed | |
| 87 | qed | |
| 88 | qed | |
| 89 | ||
| 90 | lemma rev_append_cons: | |
| 13006 | 91 | "n < length x \<Longrightarrow> \<exists>a b c. x = (rev a) @ b # c \<and> length a = n" | 
| 12516 | 92 | proof - | 
| 93 | assume n: "n < length x" | |
| 94 | hence "n \<le> length x" by simp | |
| 95 | hence "\<exists>a b. x = a @ b \<and> length a = n" by (rule append_length_n) | |
| 17589 | 96 | then obtain r d where x: "x = r@d" "length r = n" by iprover | 
| 12516 | 97 | with n have "\<exists>b c. d = b#c" by (simp add: neq_Nil_conv) | 
| 17589 | 98 | then obtain b c where "d = b#c" by iprover | 
| 12516 | 99 | with x have "x = (rev (rev r)) @ b # c \<and> length (rev r) = n" by simp | 
| 100 | thus ?thesis by blast | |
| 101 | qed | |
| 102 | ||
| 103 | lemma sup_loc_length_map: | |
| 104 | "G \<turnstile> map f a <=l map g b \<Longrightarrow> length a = length b" | |
| 105 | proof - | |
| 106 | assume "G \<turnstile> map f a <=l map g b" | |
| 107 | hence "length (map f a) = length (map g b)" by (rule sup_loc_length) | |
| 108 | thus ?thesis by simp | |
| 109 | qed | |
| 110 | ||
| 111 | lemmas [iff] = not_Err_eq | |
| 112 | ||
| 113 | lemma app_mono: | |
| 13006 | 114 | "\<lbrakk>G \<turnstile> s <=' s'; app i G m rT pc et s'\<rbrakk> \<Longrightarrow> app i G m rT pc et s" | 
| 12516 | 115 | proof - | 
| 116 | ||
| 117 |   { fix s1 s2
 | |
| 118 | assume G: "G \<turnstile> s2 <=s s1" | |
| 119 | assume app: "app i G m rT pc et (Some s1)" | |
| 120 | ||
| 121 | note [simp] = sup_loc_length sup_loc_length_map | |
| 122 | ||
| 123 | have "app i G m rT pc et (Some s2)" | |
| 25362 | 124 | proof (cases i) | 
| 12516 | 125 | case Load | 
| 126 | ||
| 127 | from G Load app | |
| 128 | have "G \<turnstile> snd s2 <=l snd s1" by (auto simp add: sup_state_conv) | |
| 129 | ||
| 130 | with G Load app show ?thesis | |
| 131 | by (cases s2) (auto simp add: sup_state_conv dest: sup_loc_some) | |
| 132 | next | |
| 133 | case Store | |
| 134 | with G app show ?thesis | |
| 25362 | 135 | by (cases s2) (auto simp add: sup_loc_Cons2 sup_state_conv) | 
| 12516 | 136 | next | 
| 137 | case LitPush | |
| 25362 | 138 | with G app show ?thesis by (cases s2) (auto simp add: sup_state_conv) | 
| 12516 | 139 | next | 
| 140 | case New | |
| 25362 | 141 | with G app show ?thesis by (cases s2) (auto simp add: sup_state_conv) | 
| 12516 | 142 | next | 
| 143 | case Getfield | |
| 144 | with app G show ?thesis | |
| 145 | by (cases s2) (clarsimp simp add: sup_state_Cons2, rule widen_trans) | |
| 146 | next | |
| 25362 | 147 | case (Putfield vname cname) | 
| 12516 | 148 | |
| 149 | with app | |
| 150 | obtain vT oT ST LT b | |
| 151 | where s1: "s1 = (vT # oT # ST, LT)" and | |
| 152 | "field (G, cname) vname = Some (cname, b)" | |
| 153 | "is_class G cname" and | |
| 154 | oT: "G\<turnstile> oT\<preceq> (Class cname)" and | |
| 155 | vT: "G\<turnstile> vT\<preceq> b" and | |
| 13718 | 156 | xc: "Ball (set (match G NullPointer pc et)) (is_class G)" | 
| 12516 | 157 | by force | 
| 158 | moreover | |
| 159 | from s1 G | |
| 160 | obtain vT' oT' ST' LT' | |
| 161 | where s2: "s2 = (vT' # oT' # ST', LT')" and | |
| 162 | oT': "G\<turnstile> oT' \<preceq> oT" and | |
| 163 | vT': "G\<turnstile> vT' \<preceq> vT" | |
| 164 | by - (cases s2, simp add: sup_state_Cons2, elim exE conjE, simp, rule that) | |
| 165 | moreover | |
| 166 | from vT' vT | |
| 167 | have "G \<turnstile> vT' \<preceq> b" by (rule widen_trans) | |
| 168 | moreover | |
| 169 | from oT' oT | |
| 170 | have "G\<turnstile> oT' \<preceq> (Class cname)" by (rule widen_trans) | |
| 171 | ultimately | |
| 172 | show ?thesis by (auto simp add: Putfield xc) | |
| 173 | next | |
| 174 | case Checkcast | |
| 175 | with app G show ?thesis | |
| 25362 | 176 | by (cases s2) (auto intro!: widen_RefT2 simp add: sup_state_Cons2) | 
| 12516 | 177 | next | 
| 178 | case Return | |
| 179 | with app G show ?thesis | |
| 180 | by (cases s2) (auto simp add: sup_state_Cons2, rule widen_trans) | |
| 181 | next | |
| 182 | case Pop | |
| 183 | with app G show ?thesis | |
| 25362 | 184 | by (cases s2) (clarsimp simp add: sup_state_Cons2) | 
| 12516 | 185 | next | 
| 186 | case Dup | |
| 187 | with app G show ?thesis | |
| 25362 | 188 | by (cases s2) (clarsimp simp add: sup_state_Cons2, | 
| 12516 | 189 | auto dest: sup_state_length) | 
| 190 | next | |
| 191 | case Dup_x1 | |
| 192 | with app G show ?thesis | |
| 25362 | 193 | by (cases s2) (clarsimp simp add: sup_state_Cons2, | 
| 12516 | 194 | auto dest: sup_state_length) | 
| 195 | next | |
| 196 | case Dup_x2 | |
| 197 | with app G show ?thesis | |
| 25362 | 198 | by (cases s2) (clarsimp simp add: sup_state_Cons2, | 
| 12516 | 199 | auto dest: sup_state_length) | 
| 200 | next | |
| 201 | case Swap | |
| 202 | with app G show ?thesis | |
| 25362 | 203 | by (cases s2) (auto simp add: sup_state_Cons2) | 
| 12516 | 204 | next | 
| 205 | case IAdd | |
| 206 | with app G show ?thesis | |
| 25362 | 207 | by (cases s2) (auto simp add: sup_state_Cons2 PrimT_PrimT) | 
| 12516 | 208 | next | 
| 209 | case Goto | |
| 210 | with app show ?thesis by simp | |
| 211 | next | |
| 212 | case Ifcmpeq | |
| 213 | with app G show ?thesis | |
| 25362 | 214 | by (cases s2) (auto simp add: sup_state_Cons2 PrimT_PrimT widen_RefT2) | 
| 12516 | 215 | next | 
| 25362 | 216 | case (Invoke cname mname list) | 
| 12516 | 217 | |
| 218 | with app | |
| 219 | obtain apTs X ST LT mD' rT' b' where | |
| 220 | s1: "s1 = (rev apTs @ X # ST, LT)" and | |
| 221 | l: "length apTs = length list" and | |
| 222 | c: "is_class G cname" and | |
| 223 | C: "G \<turnstile> X \<preceq> Class cname" and | |
| 22271 | 224 | w: "\<forall>(x, y) \<in> set (zip apTs list). G \<turnstile> x \<preceq> y" and | 
| 12516 | 225 | m: "method (G, cname) (mname, list) = Some (mD', rT', b')" and | 
| 226 | x: "\<forall>C \<in> set (match_any G pc et). is_class G C" | |
| 227 | by (simp del: not_None_eq, elim exE conjE) (rule that) | |
| 228 | ||
| 229 | obtain apTs' X' ST' LT' where | |
| 230 | s2: "s2 = (rev apTs' @ X' # ST', LT')" and | |
| 231 | l': "length apTs' = length list" | |
| 232 | proof - | |
| 233 | from l s1 G | |
| 234 | have "length list < length (fst s2)" | |
| 235 | by simp | |
| 236 | hence "\<exists>a b c. (fst s2) = rev a @ b # c \<and> length a = length list" | |
| 237 | by (rule rev_append_cons [rule_format]) | |
| 238 | thus ?thesis | |
| 25362 | 239 | by (cases s2) (elim exE conjE, simp, rule that) | 
| 12516 | 240 | qed | 
| 241 | ||
| 242 | from l l' | |
| 243 | have "length (rev apTs') = length (rev apTs)" by simp | |
| 244 | ||
| 245 | from this s1 s2 G | |
| 246 | obtain | |
| 247 | G': "G \<turnstile> (apTs',LT') <=s (apTs,LT)" and | |
| 248 | X : "G \<turnstile> X' \<preceq> X" and "G \<turnstile> (ST',LT') <=s (ST,LT)" | |
| 249 | by (simp add: sup_state_rev_fst sup_state_append_fst sup_state_Cons1) | |
| 250 | ||
| 251 | with C | |
| 252 | have C': "G \<turnstile> X' \<preceq> Class cname" | |
| 253 | by - (rule widen_trans, auto) | |
| 254 | ||
| 255 | from G' | |
| 256 | have "G \<turnstile> map OK apTs' <=l map OK apTs" | |
| 257 | by (simp add: sup_state_conv) | |
| 258 | also | |
| 259 | from l w | |
| 260 | have "G \<turnstile> map OK apTs <=l map OK list" | |
| 261 | by (simp add: all_widen_is_sup_loc) | |
| 262 | finally | |
| 263 | have "G \<turnstile> map OK apTs' <=l map OK list" . | |
| 264 | ||
| 265 | with l' | |
| 22271 | 266 | have w': "\<forall>(x, y) \<in> set (zip apTs' list). G \<turnstile> x \<preceq> y" | 
| 12516 | 267 | by (simp add: all_widen_is_sup_loc) | 
| 268 | ||
| 269 | from Invoke s2 l' w' C' m c x | |
| 270 | show ?thesis | |
| 271 | by (simp del: split_paired_Ex) blast | |
| 272 | next | |
| 273 | case Throw | |
| 274 | with app G show ?thesis | |
| 275 | by (cases s2, clarsimp simp add: sup_state_Cons2 widen_RefT2) | |
| 276 | qed | |
| 277 | } note this [simp] | |
| 278 | ||
| 279 | assume "G \<turnstile> s <=' s'" "app i G m rT pc et s'" | |
| 280 | thus ?thesis by (cases s, cases s', auto) | |
| 281 | qed | |
| 282 | ||
| 283 | lemmas [simp del] = split_paired_Ex | |
| 284 | ||
| 285 | lemma eff'_mono: | |
| 13006 | 286 | "\<lbrakk> app i G m rT pc et (Some s2); G \<turnstile> s1 <=s s2 \<rbrakk> \<Longrightarrow> | 
| 12516 | 287 | G \<turnstile> eff' (i,G,s1) <=s eff' (i,G,s2)" | 
| 288 | proof (cases s1, cases s2) | |
| 289 | fix a1 b1 a2 b2 | |
| 290 | assume s: "s1 = (a1,b1)" "s2 = (a2,b2)" | |
| 291 | assume app2: "app i G m rT pc et (Some s2)" | |
| 292 | assume G: "G \<turnstile> s1 <=s s2" | |
| 293 | ||
| 294 | note [simp] = eff_def | |
| 295 | ||
| 23467 | 296 | with G have "G \<turnstile> (Some s1) <=' (Some s2)" by simp | 
| 12516 | 297 | from this app2 | 
| 298 | have app1: "app i G m rT pc et (Some s1)" by (rule app_mono) | |
| 299 | ||
| 300 | show ?thesis | |
| 25362 | 301 | proof (cases i) | 
| 302 | case (Load n) | |
| 12516 | 303 | |
| 304 | with s app1 | |
| 305 | obtain y where | |
| 25362 | 306 | y: "n < length b1" "b1 ! n = OK y" by clarsimp | 
| 12516 | 307 | |
| 308 | from Load s app2 | |
| 309 | obtain y' where | |
| 25362 | 310 | y': "n < length b2" "b2 ! n = OK y'" by clarsimp | 
| 12516 | 311 | |
| 312 | from G s | |
| 313 | have "G \<turnstile> b1 <=l b2" by (simp add: sup_state_conv) | |
| 314 | ||
| 315 | with y y' | |
| 316 | have "G \<turnstile> y \<preceq> y'" | |
| 317 | by - (drule sup_loc_some, simp+) | |
| 318 | ||
| 319 | with Load G y y' s app1 app2 | |
| 320 | show ?thesis by (clarsimp simp add: sup_state_conv) | |
| 321 | next | |
| 322 | case Store | |
| 323 | with G s app1 app2 | |
| 324 | show ?thesis | |
| 325 | by (clarsimp simp add: sup_state_conv sup_loc_update) | |
| 326 | next | |
| 327 | case LitPush | |
| 328 | with G s app1 app2 | |
| 329 | show ?thesis | |
| 330 | by (clarsimp simp add: sup_state_Cons1) | |
| 331 | next | |
| 332 | case New | |
| 333 | with G s app1 app2 | |
| 334 | show ?thesis | |
| 335 | by (clarsimp simp add: sup_state_Cons1) | |
| 336 | next | |
| 337 | case Getfield | |
| 338 | with G s app1 app2 | |
| 339 | show ?thesis | |
| 340 | by (clarsimp simp add: sup_state_Cons1) | |
| 341 | next | |
| 342 | case Putfield | |
| 343 | with G s app1 app2 | |
| 344 | show ?thesis | |
| 345 | by (clarsimp simp add: sup_state_Cons1) | |
| 346 | next | |
| 347 | case Checkcast | |
| 348 | with G s app1 app2 | |
| 349 | show ?thesis | |
| 350 | by (clarsimp simp add: sup_state_Cons1) | |
| 351 | next | |
| 25362 | 352 | case (Invoke cname mname list) | 
| 12516 | 353 | |
| 354 | with s app1 | |
| 355 | obtain a X ST where | |
| 356 | s1: "s1 = (a @ X # ST, b1)" and | |
| 357 | l: "length a = length list" | |
| 13601 | 358 | by (simp, elim exE conjE, simp (no_asm_simp)) | 
| 12516 | 359 | |
| 360 | from Invoke s app2 | |
| 361 | obtain a' X' ST' where | |
| 362 | s2: "s2 = (a' @ X' # ST', b2)" and | |
| 363 | l': "length a' = length list" | |
| 13601 | 364 | by (simp, elim exE conjE, simp (no_asm_simp)) | 
| 12516 | 365 | |
| 366 | from l l' | |
| 367 | have lr: "length a = length a'" by simp | |
| 368 | ||
| 13601 | 369 | from lr G s1 s2 | 
| 12516 | 370 | have "G \<turnstile> (ST, b1) <=s (ST', b2)" | 
| 371 | by (simp add: sup_state_append_fst sup_state_Cons1) | |
| 372 | ||
| 373 | moreover | |
| 374 | ||
| 375 | obtain b1' b2' where eff': | |
| 376 | "b1' = snd (eff' (i,G,s1))" | |
| 377 | "b2' = snd (eff' (i,G,s2))" by simp | |
| 378 | ||
| 379 | from Invoke G s eff' app1 app2 | |
| 380 | obtain "b1 = b1'" "b2 = b2'" by simp | |
| 381 | ||
| 382 | ultimately | |
| 383 | ||
| 384 | have "G \<turnstile> (ST, b1') <=s (ST', b2')" by simp | |
| 385 | ||
| 386 | with Invoke G s app1 app2 eff' s1 s2 l l' | |
| 387 | show ?thesis | |
| 388 | by (clarsimp simp add: sup_state_conv) | |
| 389 | next | |
| 390 | case Return | |
| 391 | with G | |
| 392 | show ?thesis | |
| 393 | by simp | |
| 394 | next | |
| 395 | case Pop | |
| 396 | with G s app1 app2 | |
| 397 | show ?thesis | |
| 398 | by (clarsimp simp add: sup_state_Cons1) | |
| 399 | next | |
| 400 | case Dup | |
| 401 | with G s app1 app2 | |
| 402 | show ?thesis | |
| 403 | by (clarsimp simp add: sup_state_Cons1) | |
| 404 | next | |
| 405 | case Dup_x1 | |
| 406 | with G s app1 app2 | |
| 407 | show ?thesis | |
| 408 | by (clarsimp simp add: sup_state_Cons1) | |
| 409 | next | |
| 410 | case Dup_x2 | |
| 411 | with G s app1 app2 | |
| 412 | show ?thesis | |
| 413 | by (clarsimp simp add: sup_state_Cons1) | |
| 414 | next | |
| 415 | case Swap | |
| 416 | with G s app1 app2 | |
| 417 | show ?thesis | |
| 418 | by (clarsimp simp add: sup_state_Cons1) | |
| 419 | next | |
| 420 | case IAdd | |
| 421 | with G s app1 app2 | |
| 422 | show ?thesis | |
| 423 | by (clarsimp simp add: sup_state_Cons1) | |
| 424 | next | |
| 425 | case Goto | |
| 426 | with G s app1 app2 | |
| 427 | show ?thesis by simp | |
| 428 | next | |
| 429 | case Ifcmpeq | |
| 430 | with G s app1 app2 | |
| 431 | show ?thesis | |
| 432 | by (clarsimp simp add: sup_state_Cons1) | |
| 433 | next | |
| 434 | case Throw | |
| 435 | with G | |
| 436 | show ?thesis | |
| 437 | by simp | |
| 438 | qed | |
| 439 | qed | |
| 440 | ||
| 441 | lemmas [iff del] = not_Err_eq | |
| 442 | ||
| 443 | end |