src/HOL/MicroJava/DFA/Err.thy
changeset 67613 ce654b0e6d69
parent 63258 576fb8068ba6
child 69597 ff784d5a5bfb
equal deleted inserted replaced
67610:4939494ed791 67613:ce654b0e6d69
    32 
    32 
    33 definition sup :: "('a \<Rightarrow> 'b \<Rightarrow> 'c) \<Rightarrow> ('a err \<Rightarrow> 'b err \<Rightarrow> 'c err)" where
    33 definition sup :: "('a \<Rightarrow> 'b \<Rightarrow> 'c) \<Rightarrow> ('a err \<Rightarrow> 'b err \<Rightarrow> 'c err)" where
    34 "sup f == lift2(%x y. OK(x +_f y))"
    34 "sup f == lift2(%x y. OK(x +_f y))"
    35 
    35 
    36 definition err :: "'a set \<Rightarrow> 'a err set" where
    36 definition err :: "'a set \<Rightarrow> 'a err set" where
    37 "err A == insert Err {x . ? y:A. x = OK y}"
    37 "err A == insert Err {x . \<exists>y\<in>A. x = OK y}"
    38 
    38 
    39 definition esl :: "'a sl \<Rightarrow> 'a esl" where
    39 definition esl :: "'a sl \<Rightarrow> 'a esl" where
    40 "esl == %(A,r,f). (A,r, %x y. OK(f x y))"
    40 "esl == %(A,r,f). (A,r, %x y. OK(f x y))"
    41 
    41 
    42 definition sl :: "'a esl \<Rightarrow> 'a err sl" where
    42 definition sl :: "'a esl \<Rightarrow> 'a err sl" where
    66 lemma unfold_lesub_err:
    66 lemma unfold_lesub_err:
    67   "e1 <=_(le r) e2 == le r e1 e2"
    67   "e1 <=_(le r) e2 == le r e1 e2"
    68   by (simp add: lesub_def)
    68   by (simp add: lesub_def)
    69 
    69 
    70 lemma le_err_refl:
    70 lemma le_err_refl:
    71   "!x. x <=_r x \<Longrightarrow> e <=_(Err.le r) e"
    71   "\<forall>x. x <=_r x \<Longrightarrow> e <=_(Err.le r) e"
    72 apply (unfold lesub_def Err.le_def)
    72 apply (unfold lesub_def Err.le_def)
    73 apply (simp split: err.split)
    73 apply (simp split: err.split)
    74 done 
    74 done 
    75 
    75 
    76 lemma le_err_trans [rule_format]:
    76 lemma le_err_trans [rule_format]:
   108 lemma Err_le_conv [iff]:
   108 lemma Err_le_conv [iff]:
   109  "Err <=_(le r) e  = (e = Err)"
   109  "Err <=_(le r) e  = (e = Err)"
   110   by (simp add: unfold_lesub_err le_def  split: err.split)
   110   by (simp add: unfold_lesub_err le_def  split: err.split)
   111 
   111 
   112 lemma le_OK_conv [iff]:
   112 lemma le_OK_conv [iff]:
   113   "e <=_(le r) OK x  =  (? y. e = OK y & y <=_r x)"
   113   "e <=_(le r) OK x  =  (\<exists>y. e = OK y & y <=_r x)"
   114   by (simp add: unfold_lesub_err le_def split: err.split)
   114   by (simp add: unfold_lesub_err le_def split: err.split)
   115 
   115 
   116 lemma OK_le_conv:
   116 lemma OK_le_conv:
   117  "OK x <=_(le r) e  =  (e = Err | (? y. e = OK y & x <=_r y))"
   117  "OK x <=_(le r) e  =  (e = Err | (\<exists>y. e = OK y & x <=_r y))"
   118   by (simp add: unfold_lesub_err le_def split: err.split)
   118   by (simp add: unfold_lesub_err le_def split: err.split)
   119 
   119 
   120 lemma top_Err [iff]: "top (le r) Err"
   120 lemma top_Err [iff]: "top (le r) Err"
   121   by (simp add: top_def)
   121   by (simp add: top_def)
   122 
   122 
   123 lemma OK_less_conv [rule_format, iff]:
   123 lemma OK_less_conv [rule_format, iff]:
   124   "OK x <_(le r) e = (e=Err | (? y. e = OK y & x <_r y))"
   124   "OK x <_(le r) e = (e=Err | (\<exists>y. e = OK y & x <_r y))"
   125   by (simp add: lesssub_def lesub_def le_def split: err.split)
   125   by (simp add: lesssub_def lesub_def le_def split: err.split)
   126 
   126 
   127 lemma not_Err_less [rule_format, iff]:
   127 lemma not_Err_less [rule_format, iff]:
   128   "~(Err <_(le r) x)"
   128   "~(Err <_(le r) x)"
   129   by (simp add: lesssub_def lesub_def le_def split: err.split)
   129   by (simp add: lesssub_def lesub_def le_def split: err.split)
   150 
   150 
   151 lemma acc_err [simp, intro!]:  "acc r \<Longrightarrow> acc(le r)"
   151 lemma acc_err [simp, intro!]:  "acc r \<Longrightarrow> acc(le r)"
   152 apply (unfold acc_def lesub_def le_def lesssub_def)
   152 apply (unfold acc_def lesub_def le_def lesssub_def)
   153 apply (simp add: wf_eq_minimal split: err.split)
   153 apply (simp add: wf_eq_minimal split: err.split)
   154 apply clarify
   154 apply clarify
   155 apply (case_tac "Err : Q")
   155 apply (case_tac "Err \<in> Q")
   156  apply blast
   156  apply blast
   157 apply (erule_tac x = "{a . OK a : Q}" in allE)
   157 apply (erule_tac x = "{a . OK a \<in> Q}" in allE)
   158 apply (case_tac "x")
   158 apply (case_tac "x")
   159  apply fast
   159  apply fast
   160 apply blast
   160 apply blast
   161 done 
   161 done 
   162 
   162 
   163 lemma Err_in_err [iff]: "Err : err A"
   163 lemma Err_in_err [iff]: "Err \<in> err A"
   164   by (simp add: err_def)
   164   by (simp add: err_def)
   165 
   165 
   166 lemma Ok_in_err [iff]: "(OK x : err A) = (x:A)"
   166 lemma Ok_in_err [iff]: "(OK x \<in> err A) = (x\<in>A)"
   167   by (auto simp add: err_def)
   167   by (auto simp add: err_def)
   168 
   168 
   169 subsection \<open>lift\<close>
   169 subsection \<open>lift\<close>
   170 
   170 
   171 lemma lift_in_errI:
   171 lemma lift_in_errI:
   172   "\<lbrakk> e : err S; !x:S. e = OK x \<longrightarrow> f x : err S \<rbrakk> \<Longrightarrow> lift f e : err S"
   172   "\<lbrakk> e \<in> err S; \<forall>x\<in>S. e = OK x \<longrightarrow> f x \<in> err S \<rbrakk> \<Longrightarrow> lift f e \<in> err S"
   173 apply (unfold lift_def)
   173 apply (unfold lift_def)
   174 apply (simp split: err.split)
   174 apply (simp split: err.split)
   175 apply blast
   175 apply blast
   176 done 
   176 done 
   177 
   177 
   201 lemma Err_sup_OK [simp]:
   201 lemma Err_sup_OK [simp]:
   202   "OK x +_(Err.sup f) OK y = OK(x +_f y)"
   202   "OK x +_(Err.sup f) OK y = OK(x +_f y)"
   203   by (simp add: plussub_def Err.sup_def Err.lift2_def)
   203   by (simp add: plussub_def Err.sup_def Err.lift2_def)
   204 
   204 
   205 lemma Err_sup_eq_OK_conv [iff]:
   205 lemma Err_sup_eq_OK_conv [iff]:
   206   "(Err.sup f ex ey = OK z) = (? x y. ex = OK x & ey = OK y & f x y = z)"
   206   "(Err.sup f ex ey = OK z) = (\<exists>x y. ex = OK x & ey = OK y & f x y = z)"
   207 apply (unfold Err.sup_def lift2_def plussub_def)
   207 apply (unfold Err.sup_def lift2_def plussub_def)
   208 apply (rule iffI)
   208 apply (rule iffI)
   209  apply (simp split: err.split_asm)
   209  apply (simp split: err.split_asm)
   210 apply clarify
   210 apply clarify
   211 apply simp
   211 apply simp
   218 done 
   218 done 
   219 
   219 
   220 subsection \<open>semilat (err A) (le r) f\<close>
   220 subsection \<open>semilat (err A) (le r) f\<close>
   221 
   221 
   222 lemma semilat_le_err_Err_plus [simp]:
   222 lemma semilat_le_err_Err_plus [simp]:
   223   "\<lbrakk> x: err A; semilat(err A, le r, f) \<rbrakk> \<Longrightarrow> Err +_f x = Err"
   223   "\<lbrakk> x \<in> err A; semilat(err A, le r, f) \<rbrakk> \<Longrightarrow> Err +_f x = Err"
   224   by (blast intro: Semilat.le_iff_plus_unchanged [OF Semilat.intro, THEN iffD1]
   224   by (blast intro: Semilat.le_iff_plus_unchanged [OF Semilat.intro, THEN iffD1]
   225                    Semilat.le_iff_plus_unchanged2 [OF Semilat.intro, THEN iffD1])
   225                    Semilat.le_iff_plus_unchanged2 [OF Semilat.intro, THEN iffD1])
   226 
   226 
   227 lemma semilat_le_err_plus_Err [simp]:
   227 lemma semilat_le_err_plus_Err [simp]:
   228   "\<lbrakk> x: err A; semilat(err A, le r, f) \<rbrakk> \<Longrightarrow> x +_f Err = Err"
   228   "\<lbrakk> x \<in> err A; semilat(err A, le r, f) \<rbrakk> \<Longrightarrow> x +_f Err = Err"
   229   by (blast intro: Semilat.le_iff_plus_unchanged [OF Semilat.intro, THEN iffD1]
   229   by (blast intro: Semilat.le_iff_plus_unchanged [OF Semilat.intro, THEN iffD1]
   230                    Semilat.le_iff_plus_unchanged2 [OF Semilat.intro, THEN iffD1])
   230                    Semilat.le_iff_plus_unchanged2 [OF Semilat.intro, THEN iffD1])
   231 
   231 
   232 lemma semilat_le_err_OK1:
   232 lemma semilat_le_err_OK1:
   233   "\<lbrakk> x:A; y:A; semilat(err A, le r, f); OK x +_f OK y = OK z \<rbrakk> 
   233   "\<lbrakk> x \<in> A; y \<in> A; semilat(err A, le r, f); OK x +_f OK y = OK z \<rbrakk> 
   234   \<Longrightarrow> x <=_r z"
   234   \<Longrightarrow> x <=_r z"
   235 apply (rule OK_le_err_OK [THEN iffD1])
   235 apply (rule OK_le_err_OK [THEN iffD1])
   236 apply (erule subst)
   236 apply (erule subst)
   237 apply (simp add: Semilat.ub1 [OF Semilat.intro])
   237 apply (simp add: Semilat.ub1 [OF Semilat.intro])
   238 done
   238 done
   239 
   239 
   240 lemma semilat_le_err_OK2:
   240 lemma semilat_le_err_OK2:
   241   "\<lbrakk> x:A; y:A; semilat(err A, le r, f); OK x +_f OK y = OK z \<rbrakk> 
   241   "\<lbrakk> x \<in> A; y \<in> A; semilat(err A, le r, f); OK x +_f OK y = OK z \<rbrakk> 
   242   \<Longrightarrow> y <=_r z"
   242   \<Longrightarrow> y <=_r z"
   243 apply (rule OK_le_err_OK [THEN iffD1])
   243 apply (rule OK_le_err_OK [THEN iffD1])
   244 apply (erule subst)
   244 apply (erule subst)
   245 apply (simp add: Semilat.ub2 [OF Semilat.intro])
   245 apply (simp add: Semilat.ub2 [OF Semilat.intro])
   246 done
   246 done
   250 apply (unfold Semilat.order_def)
   250 apply (unfold Semilat.order_def)
   251 apply blast
   251 apply blast
   252 done
   252 done
   253 
   253 
   254 lemma OK_plus_OK_eq_Err_conv [simp]:
   254 lemma OK_plus_OK_eq_Err_conv [simp]:
   255   assumes "x:A" and "y:A" and "semilat(err A, le r, fe)"
   255   assumes "x \<in> A" and "y \<in> A" and "semilat(err A, le r, fe)"
   256   shows "((OK x) +_fe (OK y) = Err) = (~(? z:A. x <=_r z & y <=_r z))"
   256   shows "((OK x) +_fe (OK y) = Err) = (\<not>(\<exists>z\<in>A. x <=_r z & y <=_r z))"
   257 proof -
   257 proof -
   258   have plus_le_conv3: "\<And>A x y z f r. 
   258   have plus_le_conv3: "\<And>A x y z f r. 
   259     \<lbrakk> semilat (A,r,f); x +_f y <=_r z; x:A; y:A; z:A \<rbrakk> 
   259     \<lbrakk> semilat (A,r,f); x +_f y <=_r z; x \<in> A; y \<in> A; z \<in> A \<rbrakk> 
   260     \<Longrightarrow> x <=_r z \<and> y <=_r z"
   260     \<Longrightarrow> x <=_r z \<and> y <=_r z"
   261     by (rule Semilat.plus_le_conv [OF Semilat.intro, THEN iffD1])
   261     by (rule Semilat.plus_le_conv [OF Semilat.intro, THEN iffD1])
   262   from assms show ?thesis
   262   from assms show ?thesis
   263   apply (rule_tac iffI)
   263   apply (rule_tac iffI)
   264    apply clarify
   264    apply clarify
   272     apply simp
   272     apply simp
   273    apply simp
   273    apply simp
   274   apply (case_tac "(OK x) +_fe (OK y)")
   274   apply (case_tac "(OK x) +_fe (OK y)")
   275    apply assumption
   275    apply assumption
   276   apply (rename_tac z)
   276   apply (rename_tac z)
   277   apply (subgoal_tac "OK z: err A")
   277   apply (subgoal_tac "OK z \<in> err A")
   278   apply (drule eq_order_le)
   278   apply (drule eq_order_le)
   279     apply (erule Semilat.orderI [OF Semilat.intro])
   279     apply (erule Semilat.orderI [OF Semilat.intro])
   280    apply (blast dest: plus_le_conv3) 
   280    apply (blast dest: plus_le_conv3) 
   281   apply (erule subst)
   281   apply (erule subst)
   282   apply (blast intro: Semilat.closedI [OF Semilat.intro] closedD)
   282   apply (blast intro: Semilat.closedI [OF Semilat.intro] closedD)
   285 
   285 
   286 subsection \<open>semilat (err (Union AS))\<close>
   286 subsection \<open>semilat (err (Union AS))\<close>
   287 
   287 
   288 (* FIXME? *)
   288 (* FIXME? *)
   289 lemma all_bex_swap_lemma [iff]:
   289 lemma all_bex_swap_lemma [iff]:
   290   "(!x. (? y:A. x = f y) \<longrightarrow> P x) = (!y:A. P(f y))"
   290   "(\<forall>x. (\<exists>y\<in>A. x = f y) \<longrightarrow> P x) = (\<forall>y\<in>A. P(f y))"
   291   by blast
   291   by blast
   292 
   292 
   293 lemma closed_err_Union_lift2I: 
   293 lemma closed_err_Union_lift2I: 
   294   "\<lbrakk> !A:AS. closed (err A) (lift2 f); AS ~= {}; 
   294   "\<lbrakk> \<forall>A\<in>AS. closed (err A) (lift2 f); AS \<noteq> {}; 
   295       !A:AS.!B:AS. A~=B \<longrightarrow> (!a:A.!b:B. a +_f b = Err) \<rbrakk> 
   295       \<forall>A\<in>AS. \<forall>B\<in>AS. A\<noteq>B \<longrightarrow> (\<forall>a\<in>A. \<forall>b\<in>B. a +_f b = Err) \<rbrakk> 
   296   \<Longrightarrow> closed (err (\<Union>AS)) (lift2 f)"
   296   \<Longrightarrow> closed (err (\<Union>AS)) (lift2 f)"
   297 apply (unfold closed_def err_def)
   297 apply (unfold closed_def err_def)
   298 apply simp
   298 apply simp
   299 apply clarify
   299 apply clarify
   300 apply simp
   300 apply simp
   305   If @{term "AS = {}"} the thm collapses to
   305   If @{term "AS = {}"} the thm collapses to
   306   @{prop "order r & closed {Err} f & Err +_f Err = Err"}
   306   @{prop "order r & closed {Err} f & Err +_f Err = Err"}
   307   which may not hold 
   307   which may not hold 
   308 \<close>
   308 \<close>
   309 lemma err_semilat_UnionI:
   309 lemma err_semilat_UnionI:
   310   "\<lbrakk> !A:AS. err_semilat(A, r, f); AS ~= {}; 
   310   "\<lbrakk> \<forall>A\<in>AS. err_semilat(A, r, f); AS \<noteq> {}; 
   311       !A:AS.!B:AS. A~=B \<longrightarrow> (!a:A.!b:B. ~ a <=_r b & a +_f b = Err) \<rbrakk> 
   311       \<forall>A\<in>AS. \<forall>B\<in>AS. A\<noteq>B \<longrightarrow> (\<forall>a\<in>A. \<forall>b\<in>B. \<not> a <=_r b & a +_f b = Err) \<rbrakk> 
   312   \<Longrightarrow> err_semilat (\<Union>AS, r, f)"
   312   \<Longrightarrow> err_semilat (\<Union>AS, r, f)"
   313 apply (unfold semilat_def sl_def)
   313 apply (unfold semilat_def sl_def)
   314 apply (simp add: closed_err_Union_lift2I)
   314 apply (simp add: closed_err_Union_lift2I)
   315 apply (rule conjI)
   315 apply (rule conjI)
   316  apply blast
   316  apply blast