src/HOL/MicroJava/J/TypeRel.thy
changeset 22271 51a80e238b29
parent 20970 c2a342e548a9
child 22597 284b2183d070
     1.1 --- a/src/HOL/MicroJava/J/TypeRel.thy	Wed Feb 07 17:41:11 2007 +0100
     1.2 +++ b/src/HOL/MicroJava/J/TypeRel.thy	Wed Feb 07 17:44:07 2007 +0100
     1.3 @@ -8,61 +8,45 @@
     1.4  
     1.5  theory TypeRel imports Decl begin
     1.6  
     1.7 -consts
     1.8 -  subcls1 :: "'c prog => (cname \<times> cname) set"  -- "subclass"
     1.9 -  widen   :: "'c prog => (ty    \<times> ty   ) set"  -- "widening"
    1.10 -  cast    :: "'c prog => (ty    \<times> ty   ) set"  -- "casting"
    1.11 -
    1.12 -syntax (xsymbols)
    1.13 +-- "direct subclass, cf. 8.1.3"
    1.14 +inductive2
    1.15    subcls1 :: "'c prog => [cname, cname] => bool" ("_ \<turnstile> _ \<prec>C1 _" [71,71,71] 70)
    1.16 -  subcls  :: "'c prog => [cname, cname] => bool" ("_ \<turnstile> _ \<preceq>C _"  [71,71,71] 70)
    1.17 -  widen   :: "'c prog => [ty   , ty   ] => bool" ("_ \<turnstile> _ \<preceq> _"   [71,71,71] 70)
    1.18 -  cast    :: "'c prog => [ty   , ty   ] => bool" ("_ \<turnstile> _ \<preceq>? _"  [71,71,71] 70)
    1.19 +  for G :: "'c prog"
    1.20 +where
    1.21 +  subcls1I: "\<lbrakk>class G C = Some (D,rest); C \<noteq> Object\<rbrakk> \<Longrightarrow> G\<turnstile>C\<prec>C1D"
    1.22  
    1.23 -syntax
    1.24 -  subcls1 :: "'c prog => [cname, cname] => bool" ("_ |- _ <=C1 _" [71,71,71] 70)
    1.25 -  subcls  :: "'c prog => [cname, cname] => bool" ("_ |- _ <=C _"  [71,71,71] 70)
    1.26 -  widen   :: "'c prog => [ty   , ty   ] => bool" ("_ |- _ <= _"   [71,71,71] 70)
    1.27 -  cast    :: "'c prog => [ty   , ty   ] => bool" ("_ |- _ <=? _"  [71,71,71] 70)
    1.28 -
    1.29 -translations
    1.30 -  "G\<turnstile>C \<prec>C1 D" == "(C,D) \<in> subcls1 G"
    1.31 -  "G\<turnstile>C \<preceq>C  D" == "(C,D) \<in> (subcls1 G)^*"
    1.32 -  "G\<turnstile>S \<preceq>   T" == "(S,T) \<in> widen   G"
    1.33 -  "G\<turnstile>C \<preceq>?  D" == "(C,D) \<in> cast    G"
    1.34 -
    1.35 --- "direct subclass, cf. 8.1.3"
    1.36 -inductive "subcls1 G" intros
    1.37 -  subcls1I: "\<lbrakk>class G C = Some (D,rest); C \<noteq> Object\<rbrakk> \<Longrightarrow> G\<turnstile>C\<prec>C1D"
    1.38 +abbreviation
    1.39 +  subcls  :: "'c prog => [cname, cname] => bool" ("_ \<turnstile> _ \<preceq>C _"  [71,71,71] 70)
    1.40 +  where "G\<turnstile>C \<preceq>C  D \<equiv> (subcls1 G)^** C D"
    1.41    
    1.42  lemma subcls1D: 
    1.43    "G\<turnstile>C\<prec>C1D \<Longrightarrow> C \<noteq> Object \<and> (\<exists>fs ms. class G C = Some (D,fs,ms))"
    1.44 -apply (erule subcls1.elims)
    1.45 +apply (erule subcls1.cases)
    1.46  apply auto
    1.47  done
    1.48  
    1.49  lemma subcls1_def2: 
    1.50 -  "subcls1 G = 
    1.51 +  "subcls1 G = member2
    1.52       (SIGMA C: {C. is_class G C} . {D. C\<noteq>Object \<and> fst (the (class G C))=D})"
    1.53 -  by (auto simp add: is_class_def dest: subcls1D intro: subcls1I)
    1.54 +  by (auto simp add: is_class_def expand_fun_eq dest: subcls1D intro: subcls1I)
    1.55  
    1.56 -lemma finite_subcls1: "finite (subcls1 G)"
    1.57 -apply(subst subcls1_def2)
    1.58 +lemma finite_subcls1: "finite (Collect2 (subcls1 G))"
    1.59 +apply(simp add: subcls1_def2)
    1.60  apply(rule finite_SigmaI [OF finite_is_class])
    1.61  apply(rule_tac B = "{fst (the (class G C))}" in finite_subset)
    1.62  apply  auto
    1.63  done
    1.64  
    1.65 -lemma subcls_is_class: "(C,D) \<in> (subcls1 G)^+ ==> is_class G C"
    1.66 +lemma subcls_is_class: "(subcls1 G)^++ C D ==> is_class G C"
    1.67  apply (unfold is_class_def)
    1.68 -apply(erule trancl_trans_induct)
    1.69 +apply(erule trancl_trans_induct')
    1.70  apply (auto dest!: subcls1D)
    1.71  done
    1.72  
    1.73  lemma subcls_is_class2 [rule_format (no_asm)]: 
    1.74    "G\<turnstile>C\<preceq>C D \<Longrightarrow> is_class G D \<longrightarrow> is_class G C"
    1.75  apply (unfold is_class_def)
    1.76 -apply (erule rtrancl_induct)
    1.77 +apply (erule rtrancl_induct')
    1.78  apply  (drule_tac [2] subcls1D)
    1.79  apply  auto
    1.80  done
    1.81 @@ -70,18 +54,19 @@
    1.82  constdefs
    1.83    class_rec :: "'c prog \<Rightarrow> cname \<Rightarrow> 'a \<Rightarrow>
    1.84      (cname \<Rightarrow> fdecl list \<Rightarrow> 'c mdecl list \<Rightarrow> 'a \<Rightarrow> 'a) \<Rightarrow> 'a"
    1.85 -  "class_rec G == wfrec ((subcls1 G)^-1)
    1.86 +  "class_rec G == wfrec (Collect2 ((subcls1 G)^--1))
    1.87      (\<lambda>r C t f. case class G C of
    1.88           None \<Rightarrow> arbitrary
    1.89         | Some (D,fs,ms) \<Rightarrow> 
    1.90             f C fs ms (if C = Object then t else r D t f))"
    1.91  
    1.92 -lemma class_rec_lemma: "wf ((subcls1 G)^-1) \<Longrightarrow> class G C = Some (D,fs,ms) \<Longrightarrow>
    1.93 +lemma class_rec_lemma: "wfP ((subcls1 G)^--1) \<Longrightarrow> class G C = Some (D,fs,ms) \<Longrightarrow>
    1.94   class_rec G C t f = f C fs ms (if C=Object then t else class_rec G D t f)"
    1.95 -  by (simp add: class_rec_def wfrec cut_apply [OF converseI [OF subcls1I]])
    1.96 +  by (simp add: class_rec_def wfrec [to_pred]
    1.97 +    cut_apply [OF Collect2I [where P="(subcls1 G)^--1"], OF conversepI, OF subcls1I])
    1.98  
    1.99  definition
   1.100 -  "wf_class G = wf ((subcls1 G)^-1)"
   1.101 +  "wf_class G = wfP ((subcls1 G)^--1)"
   1.102  
   1.103  lemma class_rec_func [code func]:
   1.104    "class_rec G C t f = (if wf_class G then
   1.105 @@ -93,13 +78,14 @@
   1.106    case False then show ?thesis by auto
   1.107  next
   1.108    case True
   1.109 -  from `wf_class G` have wf: "wf ((subcls1 G)^-1)"
   1.110 +  from `wf_class G` have wf: "wfP ((subcls1 G)^--1)"
   1.111      unfolding wf_class_def .
   1.112    show ?thesis
   1.113    proof (cases "class G C")
   1.114      case None
   1.115      with wf show ?thesis
   1.116 -      by (simp add: class_rec_def wfrec cut_apply [OF converseI [OF subcls1I]])
   1.117 +      by (simp add: class_rec_def wfrec [to_pred]
   1.118 +        cut_apply [OF Collect2I [where P="(subcls1 G)^--1"], OF conversepI, OF subcls1I])
   1.119    next
   1.120      case (Some x) show ?thesis
   1.121      proof (cases x)
   1.122 @@ -121,7 +107,7 @@
   1.123  defs method_def: "method \<equiv> \<lambda>(G,C). class_rec G C empty (\<lambda>C fs ms ts.
   1.124                             ts ++ map_of (map (\<lambda>(s,m). (s,(C,m))) ms))"
   1.125  
   1.126 -lemma method_rec_lemma: "[|class G C = Some (D,fs,ms); wf ((subcls1 G)^-1)|] ==>
   1.127 +lemma method_rec_lemma: "[|class G C = Some (D,fs,ms); wfP ((subcls1 G)^--1)|] ==>
   1.128    method (G,C) = (if C = Object then empty else method (G,D)) ++  
   1.129    map_of (map (\<lambda>(s,m). (s,(C,m))) ms)"
   1.130  apply (unfold method_def)
   1.131 @@ -135,7 +121,7 @@
   1.132  defs fields_def: "fields \<equiv> \<lambda>(G,C). class_rec G C []    (\<lambda>C fs ms ts.
   1.133                             map (\<lambda>(fn,ft). ((fn,C),ft)) fs @ ts)"
   1.134  
   1.135 -lemma fields_rec_lemma: "[|class G C = Some (D,fs,ms); wf ((subcls1 G)^-1)|] ==>
   1.136 +lemma fields_rec_lemma: "[|class G C = Some (D,fs,ms); wfP ((subcls1 G)^--1)|] ==>
   1.137   fields (G,C) = 
   1.138    map (\<lambda>(fn,ft). ((fn,C),ft)) fs @ (if C = Object then [] else fields (G,D))"
   1.139  apply (unfold fields_def)
   1.140 @@ -156,56 +142,62 @@
   1.141  
   1.142  
   1.143  -- "widening, viz. method invocation conversion,cf. 5.3 i.e. sort of syntactic subtyping"
   1.144 -inductive "widen G" intros 
   1.145 +inductive2
   1.146 +  widen   :: "'c prog => [ty   , ty   ] => bool" ("_ \<turnstile> _ \<preceq> _"   [71,71,71] 70)
   1.147 +  for G :: "'c prog"
   1.148 +where
   1.149    refl   [intro!, simp]:       "G\<turnstile>      T \<preceq> T"   -- "identity conv., cf. 5.1.1"
   1.150 -  subcls         : "G\<turnstile>C\<preceq>C D ==> G\<turnstile>Class C \<preceq> Class D"
   1.151 -  null   [intro!]:             "G\<turnstile>     NT \<preceq> RefT R"
   1.152 +| subcls         : "G\<turnstile>C\<preceq>C D ==> G\<turnstile>Class C \<preceq> Class D"
   1.153 +| null   [intro!]:             "G\<turnstile>     NT \<preceq> RefT R"
   1.154  
   1.155  -- "casting conversion, cf. 5.5 / 5.1.5"
   1.156  -- "left out casts on primitve types"
   1.157 -inductive "cast G" intros
   1.158 +inductive2
   1.159 +  cast    :: "'c prog => [ty   , ty   ] => bool" ("_ \<turnstile> _ \<preceq>? _"  [71,71,71] 70)
   1.160 +  for G :: "'c prog"
   1.161 +where
   1.162    widen:  "G\<turnstile> C\<preceq> D ==> G\<turnstile>C \<preceq>? D"
   1.163 -  subcls: "G\<turnstile> D\<preceq>C C ==> G\<turnstile>Class C \<preceq>? Class D"
   1.164 +| subcls: "G\<turnstile> D\<preceq>C C ==> G\<turnstile>Class C \<preceq>? Class D"
   1.165  
   1.166  lemma widen_PrimT_RefT [iff]: "(G\<turnstile>PrimT pT\<preceq>RefT rT) = False"
   1.167  apply (rule iffI)
   1.168 -apply (erule widen.elims)
   1.169 +apply (erule widen.cases)
   1.170  apply auto
   1.171  done
   1.172  
   1.173  lemma widen_RefT: "G\<turnstile>RefT R\<preceq>T ==> \<exists>t. T=RefT t"
   1.174 -apply (ind_cases "G\<turnstile>S\<preceq>T")
   1.175 +apply (ind_cases2 "G\<turnstile>RefT R\<preceq>T")
   1.176  apply auto
   1.177  done
   1.178  
   1.179  lemma widen_RefT2: "G\<turnstile>S\<preceq>RefT R ==> \<exists>t. S=RefT t"
   1.180 -apply (ind_cases "G\<turnstile>S\<preceq>T")
   1.181 +apply (ind_cases2 "G\<turnstile>S\<preceq>RefT R")
   1.182  apply auto
   1.183  done
   1.184  
   1.185  lemma widen_Class: "G\<turnstile>Class C\<preceq>T ==> \<exists>D. T=Class D"
   1.186 -apply (ind_cases "G\<turnstile>S\<preceq>T")
   1.187 +apply (ind_cases2 "G\<turnstile>Class C\<preceq>T")
   1.188  apply auto
   1.189  done
   1.190  
   1.191  lemma widen_Class_NullT [iff]: "(G\<turnstile>Class C\<preceq>NT) = False"
   1.192  apply (rule iffI)
   1.193 -apply (ind_cases "G\<turnstile>S\<preceq>T")
   1.194 +apply (ind_cases2 "G\<turnstile>Class C\<preceq>NT")
   1.195  apply auto
   1.196  done
   1.197  
   1.198  lemma widen_Class_Class [iff]: "(G\<turnstile>Class C\<preceq> Class D) = (G\<turnstile>C\<preceq>C D)"
   1.199  apply (rule iffI)
   1.200 -apply (ind_cases "G\<turnstile>S\<preceq>T")
   1.201 +apply (ind_cases2 "G\<turnstile>Class C \<preceq> Class D")
   1.202  apply (auto elim: widen.subcls)
   1.203  done
   1.204  
   1.205  lemma widen_NT_Class [simp]: "G \<turnstile> T \<preceq> NT \<Longrightarrow> G \<turnstile> T \<preceq> Class D"
   1.206 -by (ind_cases "G \<turnstile> T \<preceq> NT",  auto)
   1.207 +by (ind_cases2 "G \<turnstile> T \<preceq> NT",  auto)
   1.208  
   1.209  lemma cast_PrimT_RefT [iff]: "(G\<turnstile>PrimT pT\<preceq>? RefT rT) = False"
   1.210  apply (rule iffI)
   1.211 -apply (erule cast.elims)
   1.212 +apply (erule cast.cases)
   1.213  apply auto
   1.214  done
   1.215  
   1.216 @@ -223,7 +215,7 @@
   1.217    next
   1.218      case (subcls C D T)
   1.219      then obtain E where "T = Class E" by (blast dest: widen_Class)
   1.220 -    with subcls show "G\<turnstile>Class C\<preceq>T" by (auto elim: rtrancl_trans)
   1.221 +    with subcls show "G\<turnstile>Class C\<preceq>T" by auto
   1.222    next
   1.223      case (null R RT)
   1.224      then obtain rt where "RT = RefT rt" by (blast dest: widen_RefT)