src/HOL/MicroJava/BV/LBVSpec.thy
changeset 13006 51c5f3f11d16
parent 12978 16cc829b9c65
child 13062 4b1edf2f6bd2
equal deleted inserted replaced
13005:42a54d6cec15 13006:51c5f3f11d16
    20   development of \mJava.
    20   development of \mJava.
    21 *}
    21 *}
    22 
    22 
    23 types
    23 types
    24   certificate       = "state_type option list" 
    24   certificate       = "state_type option list" 
    25   class_certificate = "sig => certificate"
    25   class_certificate = "sig \<Rightarrow> certificate"
    26   prog_certificate  = "cname => class_certificate"
    26   prog_certificate  = "cname \<Rightarrow> class_certificate"
    27 
    27 
    28 consts
    28 consts
    29   merge :: "[jvm_prog, p_count, nat, nat, p_count, certificate, (nat \<times> (state_type option)) list, state] \<Rightarrow> state"
    29   merge :: "[jvm_prog, p_count, nat, nat, p_count, certificate, (nat \<times> (state_type option)) list, state] \<Rightarrow> state"
    30 primrec
    30 primrec
    31   "merge G pc mxs mxr max_pc cert []     x = x"
    31   "merge G pc mxs mxr max_pc cert []     x = x"
    36                                          merge G pc mxs mxr max_pc cert ss x
    36                                          merge G pc mxs mxr max_pc cert ss x
    37                                        else Err)"
    37                                        else Err)"
    38 
    38 
    39 constdefs 
    39 constdefs 
    40   wtl_inst :: "[instr,jvm_prog,ty,state_type option,certificate,nat,nat,p_count,exception_table,p_count] 
    40   wtl_inst :: "[instr,jvm_prog,ty,state_type option,certificate,nat,nat,p_count,exception_table,p_count] 
    41                => state_type option err" 
    41                \<Rightarrow> state_type option err" 
    42   "wtl_inst i G rT s cert maxs maxr max_pc et pc == 
    42   "wtl_inst i G rT s cert maxs maxr max_pc et pc == 
    43      if app i G maxs rT pc et s then 
    43      if app i G maxs rT pc et s then 
    44        merge G pc maxs maxr max_pc cert (eff i G pc et s) (OK (cert!(pc+1)))
    44        merge G pc maxs maxr max_pc cert (eff i G pc et s) (OK (cert!(pc+1)))
    45      else Err"
    45      else Err"
    46 
    46 
    47   wtl_cert :: "[instr,jvm_prog,ty,state_type option,certificate,nat,nat,p_count,exception_table,p_count] 
    47   wtl_cert :: "[instr,jvm_prog,ty,state_type option,certificate,nat,nat,p_count,exception_table,p_count] 
    48                => state_type option err"  
    48                \<Rightarrow> state_type option err"  
    49   "wtl_cert i G rT s cert maxs maxr max_pc et pc ==
    49   "wtl_cert i G rT s cert maxs maxr max_pc et pc ==
    50      case cert!pc of
    50      case cert!pc of
    51         None    => wtl_inst i G rT s cert maxs maxr max_pc et pc
    51         None    \<Rightarrow> wtl_inst i G rT s cert maxs maxr max_pc et pc
    52       | Some s' => if G \<turnstile> s <=' (Some s') then 
    52       | Some s' \<Rightarrow> if G \<turnstile> s <=' (Some s') then 
    53                     wtl_inst i G rT (Some s') cert maxs maxr max_pc et pc 
    53                     wtl_inst i G rT (Some s') cert maxs maxr max_pc et pc 
    54                   else Err"
    54                   else Err"
    55 
    55 
    56 consts 
    56 consts 
    57   wtl_inst_list :: "[instr list,jvm_prog,ty,certificate,nat,nat,p_count,exception_table,p_count,
    57   wtl_inst_list :: "[instr list,jvm_prog,ty,certificate,nat,nat,p_count,exception_table,p_count,
    58                      state_type option] => state_type option err"
    58                      state_type option] \<Rightarrow> state_type option err"
    59 primrec
    59 primrec
    60   "wtl_inst_list []     G rT cert maxs maxr max_pc et pc s = OK s"
    60   "wtl_inst_list []     G rT cert maxs maxr max_pc et pc s = OK s"
    61   "wtl_inst_list (i#is) G rT cert maxs maxr max_pc et pc s = 
    61   "wtl_inst_list (i#is) G rT cert maxs maxr max_pc et pc s = 
    62     (let s' = wtl_cert i G rT s cert maxs maxr max_pc et pc in
    62     (let s' = wtl_cert i G rT s cert maxs maxr max_pc et pc in
    63      strict (wtl_inst_list is G rT cert maxs maxr max_pc et (pc+1)) s')"
    63      strict (wtl_inst_list is G rT cert maxs maxr max_pc et (pc+1)) s')"
    64               
    64               
    65 
    65 
    66 constdefs
    66 constdefs
    67  wtl_method :: "[jvm_prog,cname,ty list,ty,nat,nat,exception_table,instr list,certificate] => bool"  
    67  wtl_method :: "[jvm_prog,cname,ty list,ty,nat,nat,exception_table,instr list,certificate] \<Rightarrow> bool"  
    68  "wtl_method G C pTs rT mxs mxl et ins cert ==  
    68  "wtl_method G C pTs rT mxs mxl et ins cert ==  
    69 	let max_pc = length ins  
    69 	let max_pc = length ins  
    70   in 
    70   in 
    71   0 < max_pc \<and>   
    71   0 < max_pc \<and>   
    72   wtl_inst_list ins G rT cert mxs mxl max_pc et 0 
    72   wtl_inst_list ins G rT cert mxs mxl max_pc et 0 
    73                 (Some ([],(OK (Class C))#((map OK pTs))@(replicate mxl Err))) \<noteq> Err"
    73                 (Some ([],(OK (Class C))#((map OK pTs))@(replicate mxl Err))) \<noteq> Err"
    74 
    74 
    75  wtl_jvm_prog :: "[jvm_prog,prog_certificate] => bool" 
    75  wtl_jvm_prog :: "[jvm_prog,prog_certificate] \<Rightarrow> bool" 
    76  "wtl_jvm_prog G cert ==  
    76  "wtl_jvm_prog G cert ==  
    77   wf_prog (\<lambda>G C (sig,rT,maxs,maxl,b,et). wtl_method G C (snd sig) rT maxs maxl et b (cert C sig)) G"
    77   wf_prog (\<lambda>G C (sig,rT,maxs,maxl,b,et). wtl_method G C (snd sig) rT maxs maxl et b (cert C sig)) G"
    78 
    78 
    79 
    79 
    80 lemmas [iff] = not_Err_eq
    80 lemmas [iff] = not_Err_eq
    82 lemma if_eq_cases:
    82 lemma if_eq_cases:
    83   "(P \<Longrightarrow> x = z) \<Longrightarrow> (\<not>P \<Longrightarrow> y = z) \<Longrightarrow> (if P then x else y) = z"
    83   "(P \<Longrightarrow> x = z) \<Longrightarrow> (\<not>P \<Longrightarrow> y = z) \<Longrightarrow> (if P then x else y) = z"
    84   by simp
    84   by simp
    85 
    85 
    86 lemma merge_def:
    86 lemma merge_def:
    87   "!!x. merge G pc mxs mxr max_pc cert ss x = 
    87   "\<And>x. merge G pc mxs mxr max_pc cert ss x = 
    88   (if \<forall>(pc',s') \<in> set ss. pc' < max_pc \<and> (pc' \<noteq> pc+1 \<longrightarrow> G \<turnstile> s' <=' cert!pc') then
    88   (if \<forall>(pc',s') \<in> set ss. pc' < max_pc \<and> (pc' \<noteq> pc+1 \<longrightarrow> G \<turnstile> s' <=' cert!pc') then
    89     map (OK \<circ> snd) [(p',t') \<in> ss. p'=pc+1] ++_(sup G mxs mxr) x
    89     map (OK \<circ> snd) [(p',t') \<in> ss. p'=pc+1] ++_(sup G mxs mxr) x
    90   else Err)" (is "!!x. ?merge ss x = ?if ss x" is "!!x. ?P ss x")
    90   else Err)" (is "\<And>x. ?merge ss x = ?if ss x" is "\<And>x. ?P ss x")
    91 proof (induct ss)
    91 proof (induct ss)
    92   show "!!x. ?P [] x" by simp
    92   show "\<And>x. ?P [] x" by simp
    93 next
    93 next
    94   have OK_snd: "(\<lambda>u. OK (snd u)) = OK \<circ> snd" by (rule ext) auto
    94   have OK_snd: "(\<lambda>u. OK (snd u)) = OK \<circ> snd" by (rule ext) auto
    95   fix x ss and s::"nat \<times> (state_type option)"
    95   fix x ss and s::"nat \<times> (state_type option)"
    96   assume IH: "\<And>x. ?P ss x"
    96   assume IH: "\<And>x. ?P ss x"
    97   obtain pc' s' where s: "s = (pc',s')" by (cases s)  
    97   obtain pc' s' where s: "s = (pc',s')" by (cases s)  
   171     qed
   171     qed
   172   qed
   172   qed
   173 qed
   173 qed
   174 
   174 
   175 lemma wtl_take:
   175 lemma wtl_take:
   176   "wtl_inst_list is G rT cert mxs mxr mpc et pc s = OK s'' ==>
   176   "wtl_inst_list is G rT cert mxs mxr mpc et pc s = OK s'' \<Longrightarrow>
   177    \<exists>s'. wtl_inst_list (take pc' is) G rT cert mxs mxr mpc et pc s = OK s'"
   177    \<exists>s'. wtl_inst_list (take pc' is) G rT cert mxs mxr mpc et pc s = OK s'"
   178 proof -
   178 proof -
   179   assume "wtl_inst_list is G rT cert mxs mxr mpc et pc s = OK s''"
   179   assume "wtl_inst_list is G rT cert mxs mxr mpc et pc s = OK s''"
   180   hence "wtl_inst_list (take pc' is @ drop pc' is) G rT cert mxs mxr mpc et pc s = OK s''"
   180   hence "wtl_inst_list (take pc' is @ drop pc' is) G rT cert mxs mxr mpc et pc s = OK s''"
   181     by simp
   181     by simp
   182   thus ?thesis by (auto simp add: wtl_append simp del: append_take_drop_id)
   182   thus ?thesis by (auto simp add: wtl_append simp del: append_take_drop_id)
   183 qed
   183 qed
   184 
   184 
   185 lemma take_Suc:
   185 lemma take_Suc:
   186   "\<forall>n. n < length l --> take (Suc n) l = (take n l)@[l!n]" (is "?P l")
   186   "\<forall>n. n < length l \<longrightarrow> take (Suc n) l = (take n l)@[l!n]" (is "?P l")
   187 proof (induct l)
   187 proof (induct l)
   188   show "?P []" by simp
   188   show "?P []" by simp
   189 next
   189 next
   190   fix x xs assume IH: "?P xs"  
   190   fix x xs assume IH: "?P xs"  
   191   show "?P (x#xs)"
   191   show "?P (x#xs)"
   195       by (cases n, auto)
   195       by (cases n, auto)
   196   qed
   196   qed
   197 qed
   197 qed
   198 
   198 
   199 lemma wtl_Suc:
   199 lemma wtl_Suc:
   200  "[| wtl_inst_list (take pc is) G rT cert maxs maxr (length is) et 0 s = OK s'; 
   200  "\<lbrakk> wtl_inst_list (take pc is) G rT cert maxs maxr (length is) et 0 s = OK s'; 
   201      wtl_cert (is!pc) G rT s' cert maxs maxr (length is) et pc = OK s'';
   201      wtl_cert (is!pc) G rT s' cert maxs maxr (length is) et pc = OK s'';
   202      Suc pc < length is |] ==>
   202      Suc pc < length is \<rbrakk> \<Longrightarrow>
   203   wtl_inst_list (take (Suc pc) is) G rT cert maxs maxr (length is) et 0 s = OK s''" 
   203   wtl_inst_list (take (Suc pc) is) G rT cert maxs maxr (length is) et 0 s = OK s''" 
   204 proof -
   204 proof -
   205   assume "wtl_inst_list (take pc is) G rT cert maxs maxr (length is) et 0 s = OK s'"
   205   assume "wtl_inst_list (take pc is) G rT cert maxs maxr (length is) et 0 s = OK s'"
   206          "wtl_cert (is!pc) G rT s' cert maxs maxr (length is) et pc = OK s''"
   206          "wtl_cert (is!pc) G rT s' cert maxs maxr (length is) et pc = OK s''"
   207          "Suc pc < length is"
   207          "Suc pc < length is"
   208   hence "take (Suc pc) is = (take pc is)@[is!pc]" by (simp add: take_Suc)
   208   hence "take (Suc pc) is = (take pc is)@[is!pc]" by (simp add: take_Suc)
   209   thus ?thesis by (simp! add: wtl_append min_def)
   209   thus ?thesis by (simp! add: wtl_append min_def)
   210 qed
   210 qed
   211 
   211 
   212 lemma wtl_all:
   212 lemma wtl_all:
   213   "[| wtl_inst_list is G rT cert maxs maxr (length is) et 0 s \<noteq> Err;
   213   "\<lbrakk> wtl_inst_list is G rT cert maxs maxr (length is) et 0 s \<noteq> Err;
   214       pc < length is |] ==> 
   214       pc < length is \<rbrakk> \<Longrightarrow> 
   215    \<exists>s' s''. wtl_inst_list (take pc is) G rT cert maxs maxr (length is) et 0 s = OK s' \<and> 
   215    \<exists>s' s''. wtl_inst_list (take pc is) G rT cert maxs maxr (length is) et 0 s = OK s' \<and> 
   216             wtl_cert (is!pc) G rT s' cert maxs maxr (length is) et pc = OK s''"
   216             wtl_cert (is!pc) G rT s' cert maxs maxr (length is) et pc = OK s''"
   217 proof -
   217 proof -
   218   assume all: "wtl_inst_list is G rT cert maxs maxr (length is) et 0 s \<noteq> Err"
   218   assume all: "wtl_inst_list is G rT cert maxs maxr (length is) et 0 s \<noteq> Err"
   219 
   219