src/HOL/MicroJava/BV/Err.thy
changeset 33954 1bc3b688548c
parent 33930 6a973bd43949
child 33955 fff6f11b1f09
     1.1 --- a/src/HOL/MicroJava/BV/Err.thy	Wed Dec 02 12:04:07 2009 +0100
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,353 +0,0 @@
     1.4 -(*  Title:      HOL/MicroJava/BV/Err.thy
     1.5 -    ID:         $Id$
     1.6 -    Author:     Tobias Nipkow
     1.7 -    Copyright   2000 TUM
     1.8 -
     1.9 -The error type
    1.10 -*)
    1.11 -
    1.12 -header {* \isaheader{The Error Type} *}
    1.13 -
    1.14 -theory Err
    1.15 -imports Semilat
    1.16 -begin
    1.17 -
    1.18 -datatype 'a err = Err | OK 'a
    1.19 -
    1.20 -types 'a ebinop = "'a \<Rightarrow> 'a \<Rightarrow> 'a err"
    1.21 -      'a esl =    "'a set * 'a ord * 'a ebinop"
    1.22 -
    1.23 -consts
    1.24 -  ok_val :: "'a err \<Rightarrow> 'a"
    1.25 -primrec
    1.26 -  "ok_val (OK x) = x"
    1.27 -
    1.28 -constdefs
    1.29 - lift :: "('a \<Rightarrow> 'b err) \<Rightarrow> ('a err \<Rightarrow> 'b err)"
    1.30 -"lift f e == case e of Err \<Rightarrow> Err | OK x \<Rightarrow> f x"
    1.31 -
    1.32 - lift2 :: "('a \<Rightarrow> 'b \<Rightarrow> 'c err) \<Rightarrow> 'a err \<Rightarrow> 'b err \<Rightarrow> 'c err"
    1.33 -"lift2 f e1 e2 ==
    1.34 - case e1 of Err  \<Rightarrow> Err
    1.35 -          | OK x \<Rightarrow> (case e2 of Err \<Rightarrow> Err | OK y \<Rightarrow> f x y)"
    1.36 -
    1.37 - le :: "'a ord \<Rightarrow> 'a err ord"
    1.38 -"le r e1 e2 ==
    1.39 -        case e2 of Err \<Rightarrow> True |
    1.40 -                   OK y \<Rightarrow> (case e1 of Err \<Rightarrow> False | OK x \<Rightarrow> x <=_r y)"
    1.41 -
    1.42 - sup :: "('a \<Rightarrow> 'b \<Rightarrow> 'c) \<Rightarrow> ('a err \<Rightarrow> 'b err \<Rightarrow> 'c err)"
    1.43 -"sup f == lift2(%x y. OK(x +_f y))"
    1.44 -
    1.45 - err :: "'a set \<Rightarrow> 'a err set"
    1.46 -"err A == insert Err {x . ? y:A. x = OK y}"
    1.47 -
    1.48 - esl :: "'a sl \<Rightarrow> 'a esl"
    1.49 -"esl == %(A,r,f). (A,r, %x y. OK(f x y))"
    1.50 -
    1.51 - sl :: "'a esl \<Rightarrow> 'a err sl"
    1.52 -"sl == %(A,r,f). (err A, le r, lift2 f)"
    1.53 -
    1.54 -syntax
    1.55 - err_semilat :: "'a esl \<Rightarrow> bool"
    1.56 -translations
    1.57 -"err_semilat L" == "semilat(Err.sl L)"
    1.58 -
    1.59 -
    1.60 -consts
    1.61 -  strict  :: "('a \<Rightarrow> 'b err) \<Rightarrow> ('a err \<Rightarrow> 'b err)"
    1.62 -primrec
    1.63 -  "strict f Err    = Err"
    1.64 -  "strict f (OK x) = f x"
    1.65 -
    1.66 -lemma strict_Some [simp]: 
    1.67 -  "(strict f x = OK y) = (\<exists> z. x = OK z \<and> f z = OK y)"
    1.68 -  by (cases x, auto)
    1.69 -
    1.70 -lemma not_Err_eq:
    1.71 -  "(x \<noteq> Err) = (\<exists>a. x = OK a)" 
    1.72 -  by (cases x) auto
    1.73 -
    1.74 -lemma not_OK_eq:
    1.75 -  "(\<forall>y. x \<noteq> OK y) = (x = Err)"
    1.76 -  by (cases x) auto  
    1.77 -
    1.78 -lemma unfold_lesub_err:
    1.79 -  "e1 <=_(le r) e2 == le r e1 e2"
    1.80 -  by (simp add: lesub_def)
    1.81 -
    1.82 -lemma le_err_refl:
    1.83 -  "!x. x <=_r x \<Longrightarrow> e <=_(Err.le r) e"
    1.84 -apply (unfold lesub_def Err.le_def)
    1.85 -apply (simp split: err.split)
    1.86 -done 
    1.87 -
    1.88 -lemma le_err_trans [rule_format]:
    1.89 -  "order r \<Longrightarrow> e1 <=_(le r) e2 \<longrightarrow> e2 <=_(le r) e3 \<longrightarrow> e1 <=_(le r) e3"
    1.90 -apply (unfold unfold_lesub_err le_def)
    1.91 -apply (simp split: err.split)
    1.92 -apply (blast intro: order_trans)
    1.93 -done
    1.94 -
    1.95 -lemma le_err_antisym [rule_format]:
    1.96 -  "order r \<Longrightarrow> e1 <=_(le r) e2 \<longrightarrow> e2 <=_(le r) e1 \<longrightarrow> e1=e2"
    1.97 -apply (unfold unfold_lesub_err le_def)
    1.98 -apply (simp split: err.split)
    1.99 -apply (blast intro: order_antisym)
   1.100 -done 
   1.101 -
   1.102 -lemma OK_le_err_OK:
   1.103 -  "(OK x <=_(le r) OK y) = (x <=_r y)"
   1.104 -  by (simp add: unfold_lesub_err le_def)
   1.105 -
   1.106 -lemma order_le_err [iff]:
   1.107 -  "order(le r) = order r"
   1.108 -apply (rule iffI)
   1.109 - apply (subst Semilat.order_def)
   1.110 - apply (blast dest: order_antisym OK_le_err_OK [THEN iffD2]
   1.111 -              intro: order_trans OK_le_err_OK [THEN iffD1])
   1.112 -apply (subst Semilat.order_def)
   1.113 -apply (blast intro: le_err_refl le_err_trans le_err_antisym
   1.114 -             dest: order_refl)
   1.115 -done 
   1.116 -
   1.117 -lemma le_Err [iff]:  "e <=_(le r) Err"
   1.118 -  by (simp add: unfold_lesub_err le_def)
   1.119 -
   1.120 -lemma Err_le_conv [iff]:
   1.121 - "Err <=_(le r) e  = (e = Err)"
   1.122 -  by (simp add: unfold_lesub_err le_def  split: err.split)
   1.123 -
   1.124 -lemma le_OK_conv [iff]:
   1.125 -  "e <=_(le r) OK x  =  (? y. e = OK y & y <=_r x)"
   1.126 -  by (simp add: unfold_lesub_err le_def split: err.split)
   1.127 -
   1.128 -lemma OK_le_conv:
   1.129 - "OK x <=_(le r) e  =  (e = Err | (? y. e = OK y & x <=_r y))"
   1.130 -  by (simp add: unfold_lesub_err le_def split: err.split)
   1.131 -
   1.132 -lemma top_Err [iff]: "top (le r) Err";
   1.133 -  by (simp add: top_def)
   1.134 -
   1.135 -lemma OK_less_conv [rule_format, iff]:
   1.136 -  "OK x <_(le r) e = (e=Err | (? y. e = OK y & x <_r y))"
   1.137 -  by (simp add: lesssub_def lesub_def le_def split: err.split)
   1.138 -
   1.139 -lemma not_Err_less [rule_format, iff]:
   1.140 -  "~(Err <_(le r) x)"
   1.141 -  by (simp add: lesssub_def lesub_def le_def split: err.split)
   1.142 -
   1.143 -lemma semilat_errI [intro]:
   1.144 -  assumes semilat: "semilat (A, r, f)"
   1.145 -  shows "semilat(err A, Err.le r, lift2(%x y. OK(f x y)))"
   1.146 -  apply(insert semilat)
   1.147 -  apply (unfold semilat_Def closed_def plussub_def lesub_def 
   1.148 -    lift2_def Err.le_def err_def)
   1.149 -  apply (simp split: err.split)
   1.150 -  done
   1.151 -
   1.152 -lemma err_semilat_eslI_aux:
   1.153 -  assumes semilat: "semilat (A, r, f)"
   1.154 -  shows "err_semilat(esl(A,r,f))"
   1.155 -  apply (unfold sl_def esl_def)
   1.156 -  apply (simp add: semilat_errI[OF semilat])
   1.157 -  done
   1.158 -
   1.159 -lemma err_semilat_eslI [intro, simp]:
   1.160 - "\<And>L. semilat L \<Longrightarrow> err_semilat(esl L)"
   1.161 -by(simp add: err_semilat_eslI_aux split_tupled_all)
   1.162 -
   1.163 -lemma acc_err [simp, intro!]:  "acc r \<Longrightarrow> acc(le r)"
   1.164 -apply (unfold acc_def lesub_def le_def lesssub_def)
   1.165 -apply (simp add: wfP_eq_minimal split: err.split)
   1.166 -apply clarify
   1.167 -apply (case_tac "Err : Q")
   1.168 - apply blast
   1.169 -apply (erule_tac x = "{a . OK a : Q}" in allE)
   1.170 -apply (case_tac "x")
   1.171 - apply fast
   1.172 -apply blast
   1.173 -done 
   1.174 -
   1.175 -lemma Err_in_err [iff]: "Err : err A"
   1.176 -  by (simp add: err_def)
   1.177 -
   1.178 -lemma Ok_in_err [iff]: "(OK x : err A) = (x:A)"
   1.179 -  by (auto simp add: err_def)
   1.180 -
   1.181 -section {* lift *}
   1.182 -
   1.183 -lemma lift_in_errI:
   1.184 -  "\<lbrakk> e : err S; !x:S. e = OK x \<longrightarrow> f x : err S \<rbrakk> \<Longrightarrow> lift f e : err S"
   1.185 -apply (unfold lift_def)
   1.186 -apply (simp split: err.split)
   1.187 -apply blast
   1.188 -done 
   1.189 -
   1.190 -lemma Err_lift2 [simp]: 
   1.191 -  "Err +_(lift2 f) x = Err"
   1.192 -  by (simp add: lift2_def plussub_def)
   1.193 -
   1.194 -lemma lift2_Err [simp]: 
   1.195 -  "x +_(lift2 f) Err = Err"
   1.196 -  by (simp add: lift2_def plussub_def split: err.split)
   1.197 -
   1.198 -lemma OK_lift2_OK [simp]:
   1.199 -  "OK x +_(lift2 f) OK y = x +_f y"
   1.200 -  by (simp add: lift2_def plussub_def split: err.split)
   1.201 -
   1.202 -
   1.203 -section {* sup *}
   1.204 -
   1.205 -lemma Err_sup_Err [simp]:
   1.206 -  "Err +_(Err.sup f) x = Err"
   1.207 -  by (simp add: plussub_def Err.sup_def Err.lift2_def)
   1.208 -
   1.209 -lemma Err_sup_Err2 [simp]:
   1.210 -  "x +_(Err.sup f) Err = Err"
   1.211 -  by (simp add: plussub_def Err.sup_def Err.lift2_def split: err.split)
   1.212 -
   1.213 -lemma Err_sup_OK [simp]:
   1.214 -  "OK x +_(Err.sup f) OK y = OK(x +_f y)"
   1.215 -  by (simp add: plussub_def Err.sup_def Err.lift2_def)
   1.216 -
   1.217 -lemma Err_sup_eq_OK_conv [iff]:
   1.218 -  "(Err.sup f ex ey = OK z) = (? x y. ex = OK x & ey = OK y & f x y = z)"
   1.219 -apply (unfold Err.sup_def lift2_def plussub_def)
   1.220 -apply (rule iffI)
   1.221 - apply (simp split: err.split_asm)
   1.222 -apply clarify
   1.223 -apply simp
   1.224 -done
   1.225 -
   1.226 -lemma Err_sup_eq_Err [iff]:
   1.227 -  "(Err.sup f ex ey = Err) = (ex=Err | ey=Err)"
   1.228 -apply (unfold Err.sup_def lift2_def plussub_def)
   1.229 -apply (simp split: err.split)
   1.230 -done 
   1.231 -
   1.232 -section {* semilat (err A) (le r) f *}
   1.233 -
   1.234 -lemma semilat_le_err_Err_plus [simp]:
   1.235 -  "\<lbrakk> x: err A; semilat(err A, le r, f) \<rbrakk> \<Longrightarrow> Err +_f x = Err"
   1.236 -  by (blast intro: Semilat.le_iff_plus_unchanged [OF Semilat.intro, THEN iffD1]
   1.237 -                   Semilat.le_iff_plus_unchanged2 [OF Semilat.intro, THEN iffD1])
   1.238 -
   1.239 -lemma semilat_le_err_plus_Err [simp]:
   1.240 -  "\<lbrakk> x: err A; semilat(err A, le r, f) \<rbrakk> \<Longrightarrow> x +_f Err = Err"
   1.241 -  by (blast intro: Semilat.le_iff_plus_unchanged [OF Semilat.intro, THEN iffD1]
   1.242 -                   Semilat.le_iff_plus_unchanged2 [OF Semilat.intro, THEN iffD1])
   1.243 -
   1.244 -lemma semilat_le_err_OK1:
   1.245 -  "\<lbrakk> x:A; y:A; semilat(err A, le r, f); OK x +_f OK y = OK z \<rbrakk> 
   1.246 -  \<Longrightarrow> x <=_r z";
   1.247 -apply (rule OK_le_err_OK [THEN iffD1])
   1.248 -apply (erule subst)
   1.249 -apply (simp add: Semilat.ub1 [OF Semilat.intro])
   1.250 -done
   1.251 -
   1.252 -lemma semilat_le_err_OK2:
   1.253 -  "\<lbrakk> x:A; y:A; semilat(err A, le r, f); OK x +_f OK y = OK z \<rbrakk> 
   1.254 -  \<Longrightarrow> y <=_r z"
   1.255 -apply (rule OK_le_err_OK [THEN iffD1])
   1.256 -apply (erule subst)
   1.257 -apply (simp add: Semilat.ub2 [OF Semilat.intro])
   1.258 -done
   1.259 -
   1.260 -lemma eq_order_le:
   1.261 -  "\<lbrakk> x=y; order r \<rbrakk> \<Longrightarrow> x <=_r y"
   1.262 -apply (unfold Semilat.order_def)
   1.263 -apply blast
   1.264 -done
   1.265 -
   1.266 -lemma OK_plus_OK_eq_Err_conv [simp]:
   1.267 -  assumes "x:A" and "y:A" and "semilat(err A, le r, fe)"
   1.268 -  shows "((OK x) +_fe (OK y) = Err) = (~(? z:A. x <=_r z & y <=_r z))"
   1.269 -proof -
   1.270 -  have plus_le_conv3: "\<And>A x y z f r. 
   1.271 -    \<lbrakk> semilat (A,r,f); x +_f y <=_r z; x:A; y:A; z:A \<rbrakk> 
   1.272 -    \<Longrightarrow> x <=_r z \<and> y <=_r z"
   1.273 -    by (rule Semilat.plus_le_conv [OF Semilat.intro, THEN iffD1])
   1.274 -  from prems show ?thesis
   1.275 -  apply (rule_tac iffI)
   1.276 -   apply clarify
   1.277 -   apply (drule OK_le_err_OK [THEN iffD2])
   1.278 -   apply (drule OK_le_err_OK [THEN iffD2])
   1.279 -   apply (drule Semilat.lub [OF Semilat.intro, of _ _ _ "OK x" _ "OK y"])
   1.280 -        apply assumption
   1.281 -       apply assumption
   1.282 -      apply simp
   1.283 -     apply simp
   1.284 -    apply simp
   1.285 -   apply simp
   1.286 -  apply (case_tac "(OK x) +_fe (OK y)")
   1.287 -   apply assumption
   1.288 -  apply (rename_tac z)
   1.289 -  apply (subgoal_tac "OK z: err A")
   1.290 -  apply (drule eq_order_le)
   1.291 -    apply (erule Semilat.orderI [OF Semilat.intro])
   1.292 -   apply (blast dest: plus_le_conv3) 
   1.293 -  apply (erule subst)
   1.294 -  apply (blast intro: Semilat.closedI [OF Semilat.intro] closedD)
   1.295 -  done 
   1.296 -qed
   1.297 -
   1.298 -section {* semilat (err(Union AS)) *}
   1.299 -
   1.300 -(* FIXME? *)
   1.301 -lemma all_bex_swap_lemma [iff]:
   1.302 -  "(!x. (? y:A. x = f y) \<longrightarrow> P x) = (!y:A. P(f y))"
   1.303 -  by blast
   1.304 -
   1.305 -lemma closed_err_Union_lift2I: 
   1.306 -  "\<lbrakk> !A:AS. closed (err A) (lift2 f); AS ~= {}; 
   1.307 -      !A:AS.!B:AS. A~=B \<longrightarrow> (!a:A.!b:B. a +_f b = Err) \<rbrakk> 
   1.308 -  \<Longrightarrow> closed (err(Union AS)) (lift2 f)"
   1.309 -apply (unfold closed_def err_def)
   1.310 -apply simp
   1.311 -apply clarify
   1.312 -apply simp
   1.313 -apply fast
   1.314 -done 
   1.315 -
   1.316 -text {* 
   1.317 -  If @{term "AS = {}"} the thm collapses to
   1.318 -  @{prop "order r & closed {Err} f & Err +_f Err = Err"}
   1.319 -  which may not hold 
   1.320 -*}
   1.321 -lemma err_semilat_UnionI:
   1.322 -  "\<lbrakk> !A:AS. err_semilat(A, r, f); AS ~= {}; 
   1.323 -      !A:AS.!B:AS. A~=B \<longrightarrow> (!a:A.!b:B. ~ a <=_r b & a +_f b = Err) \<rbrakk> 
   1.324 -  \<Longrightarrow> err_semilat(Union AS, r, f)"
   1.325 -apply (unfold semilat_def sl_def)
   1.326 -apply (simp add: closed_err_Union_lift2I)
   1.327 -apply (rule conjI)
   1.328 - apply blast
   1.329 -apply (simp add: err_def)
   1.330 -apply (rule conjI)
   1.331 - apply clarify
   1.332 - apply (rename_tac A a u B b)
   1.333 - apply (case_tac "A = B")
   1.334 -  apply simp
   1.335 - apply simp
   1.336 -apply (rule conjI)
   1.337 - apply clarify
   1.338 - apply (rename_tac A a u B b)
   1.339 - apply (case_tac "A = B")
   1.340 -  apply simp
   1.341 - apply simp
   1.342 -apply clarify
   1.343 -apply (rename_tac A ya yb B yd z C c a b)
   1.344 -apply (case_tac "A = B")
   1.345 - apply (case_tac "A = C")
   1.346 -  apply simp
   1.347 - apply (rotate_tac -1)
   1.348 - apply simp
   1.349 -apply (rotate_tac -1)
   1.350 -apply (case_tac "B = C")
   1.351 - apply simp
   1.352 -apply (rotate_tac -1)
   1.353 -apply simp
   1.354 -done 
   1.355 -
   1.356 -end