src/HOL/MicroJava/BV/Typing_Framework_err.thy
changeset 13224 6f0928a942d1
parent 13067 a59af3a83c61
child 15425 6356d2523f73
equal deleted inserted replaced
13223:45be08fbdcff 13224:6f0928a942d1
     3     Author:     Gerwin Klein
     3     Author:     Gerwin Klein
     4     Copyright   2000 TUM
     4     Copyright   2000 TUM
     5 
     5 
     6 *)
     6 *)
     7 
     7 
     8 header {* \isaheader{Static and Dynamic Welltyping} *}
     8 header {* \isaheader{Lifting the Typing Framework to err, app, and eff} *}
     9 
     9 
    10 theory Typing_Framework_err = Typing_Framework + SemilatAlg:
    10 theory Typing_Framework_err = Typing_Framework + SemilatAlg:
    11 
    11 
    12 constdefs
    12 constdefs
    13 
    13 
    16 
    16 
    17 wt_app_eff :: "'s ord \<Rightarrow> (nat \<Rightarrow> 's \<Rightarrow> bool) \<Rightarrow> 's step_type \<Rightarrow> 's list \<Rightarrow> bool"
    17 wt_app_eff :: "'s ord \<Rightarrow> (nat \<Rightarrow> 's \<Rightarrow> bool) \<Rightarrow> 's step_type \<Rightarrow> 's list \<Rightarrow> bool"
    18 "wt_app_eff r app step ts \<equiv>
    18 "wt_app_eff r app step ts \<equiv>
    19   \<forall>p < size ts. app p (ts!p) \<and> (\<forall>(q,t) \<in> set (step p (ts!p)). t <=_r ts!q)"
    19   \<forall>p < size ts. app p (ts!p) \<and> (\<forall>(q,t) \<in> set (step p (ts!p)). t <=_r ts!q)"
    20 
    20 
    21 
       
    22 map_snd :: "('b \<Rightarrow> 'c) \<Rightarrow> ('a \<times> 'b) list \<Rightarrow> ('a \<times> 'c) list"
    21 map_snd :: "('b \<Rightarrow> 'c) \<Rightarrow> ('a \<times> 'b) list \<Rightarrow> ('a \<times> 'c) list"
    23 "map_snd f \<equiv> map (\<lambda>(x,y). (x, f y))"
    22 "map_snd f \<equiv> map (\<lambda>(x,y). (x, f y))"
    24 
    23 
    25 error :: "nat \<Rightarrow> (nat \<times> 'a err) list"
    24 error :: "nat \<Rightarrow> (nat \<times> 'a err) list"
    26 "error n \<equiv> map (\<lambda>x. (x,Err)) [0..n(]"
    25 "error n \<equiv> map (\<lambda>x. (x,Err)) [0..n(]"
    27 
       
    28 
    26 
    29 err_step :: "nat \<Rightarrow> (nat \<Rightarrow> 's \<Rightarrow> bool) \<Rightarrow> 's step_type \<Rightarrow> 's err step_type"
    27 err_step :: "nat \<Rightarrow> (nat \<Rightarrow> 's \<Rightarrow> bool) \<Rightarrow> 's step_type \<Rightarrow> 's err step_type"
    30 "err_step n app step p t \<equiv> 
    28 "err_step n app step p t \<equiv> 
    31   case t of 
    29   case t of 
    32     Err   \<Rightarrow> error n
    30     Err   \<Rightarrow> error n
    33   | OK t' \<Rightarrow> if app p t' then map_snd OK (step p t') else error n"
    31   | OK t' \<Rightarrow> if app p t' then map_snd OK (step p t') else error n"
    34 
    32 
       
    33 app_mono :: "'s ord \<Rightarrow> (nat \<Rightarrow> 's \<Rightarrow> bool) \<Rightarrow> nat \<Rightarrow> 's set \<Rightarrow> bool"
       
    34 "app_mono r app n A \<equiv>
       
    35  \<forall>s p t. s \<in> A \<and> p < n \<and> s <=_r t \<longrightarrow> app p t \<longrightarrow> app p s"
       
    36 
       
    37 
    35 lemmas err_step_defs = err_step_def map_snd_def error_def
    38 lemmas err_step_defs = err_step_def map_snd_def error_def
       
    39 
    36 
    40 
    37 lemma bounded_err_stepD:
    41 lemma bounded_err_stepD:
    38   "bounded (err_step n app step) n \<Longrightarrow> 
    42   "bounded (err_step n app step) n \<Longrightarrow> 
    39   p < n \<Longrightarrow>  app p a \<Longrightarrow> (q,b) \<in> set (step p a) \<Longrightarrow> 
    43   p < n \<Longrightarrow>  app p a \<Longrightarrow> (q,b) \<in> set (step p a) \<Longrightarrow> 
    40   q < n"
    44   q < n"
    64 apply (simp split: split_if_asm) 
    68 apply (simp split: split_if_asm) 
    65  apply (blast dest: in_map_sndD)
    69  apply (blast dest: in_map_sndD)
    66 apply (simp add: error_def)
    70 apply (simp add: error_def)
    67 apply blast
    71 apply blast
    68 done
    72 done
       
    73 
       
    74 
       
    75 lemma bounded_lift:
       
    76   "bounded step n \<Longrightarrow> bounded (err_step n app step) n"
       
    77   apply (unfold bounded_def err_step_def error_def)
       
    78   apply clarify
       
    79   apply (erule allE, erule impE, assumption)
       
    80   apply (case_tac s)
       
    81   apply (auto simp add: map_snd_def split: split_if_asm)
       
    82   done
       
    83 
       
    84 
       
    85 lemma le_list_map_OK [simp]:
       
    86   "\<And>b. map OK a <=[Err.le r] map OK b = (a <=[r] b)"
       
    87   apply (induct a)
       
    88    apply simp
       
    89   apply simp
       
    90   apply (case_tac b)
       
    91    apply simp
       
    92   apply simp
       
    93   done
       
    94 
       
    95 
       
    96 lemma map_snd_lessI:
       
    97   "x <=|r| y \<Longrightarrow> map_snd OK x <=|Err.le r| map_snd OK y"
       
    98   apply (induct x)
       
    99   apply (unfold lesubstep_type_def map_snd_def)
       
   100   apply auto
       
   101   done
       
   102 
       
   103 
       
   104 lemma mono_lift:
       
   105   "order r \<Longrightarrow> app_mono r app n A \<Longrightarrow> bounded (err_step n app step) n \<Longrightarrow>
       
   106   \<forall>s p t. s \<in> A \<and> p < n \<and> s <=_r t \<longrightarrow> app p t \<longrightarrow> step p s <=|r| step p t \<Longrightarrow>
       
   107   mono (Err.le r) (err_step n app step) n (err A)"
       
   108 apply (unfold app_mono_def mono_def err_step_def)
       
   109 apply clarify
       
   110 apply (case_tac s)
       
   111  apply simp 
       
   112 apply simp
       
   113 apply (case_tac t)
       
   114  apply simp
       
   115  apply clarify
       
   116  apply (simp add: lesubstep_type_def error_def)
       
   117  apply clarify
       
   118  apply (drule in_map_sndD)
       
   119  apply clarify
       
   120  apply (drule bounded_err_stepD, assumption+)
       
   121  apply (rule exI [of _ Err])
       
   122  apply simp
       
   123 apply simp
       
   124 apply (erule allE, erule allE, erule allE, erule impE)
       
   125  apply (rule conjI, assumption)
       
   126  apply (rule conjI, assumption)
       
   127  apply assumption
       
   128 apply (rule conjI)
       
   129 apply clarify
       
   130 apply (erule allE, erule allE, erule allE, erule impE)
       
   131  apply (rule conjI, assumption)
       
   132  apply (rule conjI, assumption)
       
   133  apply assumption
       
   134 apply (erule impE, assumption)
       
   135 apply (rule map_snd_lessI, assumption)
       
   136 apply clarify
       
   137 apply (simp add: lesubstep_type_def error_def)
       
   138 apply clarify
       
   139 apply (drule in_map_sndD)
       
   140 apply clarify
       
   141 apply (drule bounded_err_stepD, assumption+)
       
   142 apply (rule exI [of _ Err])
       
   143 apply simp
       
   144 done
       
   145  
       
   146 lemma in_errorD:
       
   147   "(x,y) \<in> set (error n) \<Longrightarrow> y = Err"
       
   148   by (auto simp add: error_def)
       
   149 
       
   150 lemma pres_type_lift:
       
   151   "\<forall>s\<in>A. \<forall>p. p < n \<longrightarrow> app p s \<longrightarrow> (\<forall>(q, s')\<in>set (step p s). s' \<in> A) 
       
   152   \<Longrightarrow> pres_type (err_step n app step) n (err A)"  
       
   153 apply (unfold pres_type_def err_step_def)
       
   154 apply clarify
       
   155 apply (case_tac b)
       
   156  apply simp
       
   157 apply (case_tac s)
       
   158  apply simp
       
   159  apply (drule in_errorD)
       
   160  apply simp
       
   161 apply (simp add: map_snd_def split: split_if_asm)
       
   162  apply fast
       
   163 apply (drule in_errorD)
       
   164 apply simp
       
   165 done
       
   166 
    69 
   167 
    70 
   168 
    71 text {*
   169 text {*
    72   There used to be a condition here that each instruction must have a
   170   There used to be a condition here that each instruction must have a
    73   successor. This is not needed any more, because the definition of
   171   successor. This is not needed any more, because the definition of
   156   thus "stable (Err.le r) (err_step (size ts) app step) (map OK ts) p"
   254   thus "stable (Err.le r) (err_step (size ts) app step) (map OK ts) p"
   157     by (unfold stable_def) blast
   255     by (unfold stable_def) blast
   158 qed
   256 qed
   159 
   257 
   160 end
   258 end
       
   259