src/HOL/MicroJava/J/TypeRel.thy
changeset 33954 1bc3b688548c
parent 32461 eee4fa79398f
child 35416 d8d7d1b785af
     1.1 --- a/src/HOL/MicroJava/J/TypeRel.thy	Wed Dec 02 12:04:07 2009 +0100
     1.2 +++ b/src/HOL/MicroJava/J/TypeRel.thy	Tue Nov 24 14:37:23 2009 +0100
     1.3 @@ -9,44 +9,47 @@
     1.4  theory TypeRel imports Decl begin
     1.5  
     1.6  -- "direct subclass, cf. 8.1.3"
     1.7 -inductive
     1.8 -  subcls1 :: "'c prog => [cname, cname] => bool" ("_ \<turnstile> _ \<prec>C1 _" [71,71,71] 70)
     1.9 +
    1.10 +inductive_set
    1.11 +  subcls1 :: "'c prog => (cname \<times> cname) set"
    1.12 +  and subcls1' :: "'c prog => cname \<Rightarrow> cname => bool" ("_ \<turnstile> _ \<prec>C1 _" [71,71,71] 70)
    1.13    for G :: "'c prog"
    1.14  where
    1.15 -  subcls1I: "\<lbrakk>class G C = Some (D,rest); C \<noteq> Object\<rbrakk> \<Longrightarrow> G\<turnstile>C\<prec>C1D"
    1.16 +  "G \<turnstile> C \<prec>C1 D \<equiv> (C, D) \<in> subcls1 G"
    1.17 +  | subcls1I: "\<lbrakk>class G C = Some (D,rest); C \<noteq> Object\<rbrakk> \<Longrightarrow> G \<turnstile> C \<prec>C1 D"
    1.18  
    1.19  abbreviation
    1.20 -  subcls  :: "'c prog => [cname, cname] => bool" ("_ \<turnstile> _ \<preceq>C _"  [71,71,71] 70)
    1.21 -  where "G\<turnstile>C \<preceq>C  D \<equiv> (subcls1 G)^** C D"
    1.22 -  
    1.23 +  subcls  :: "'c prog => cname \<Rightarrow> cname => bool" ("_ \<turnstile> _ \<preceq>C _"  [71,71,71] 70)
    1.24 +  where "G \<turnstile> C \<preceq>C D \<equiv> (C, D) \<in> (subcls1 G)^*"
    1.25 +
    1.26  lemma subcls1D: 
    1.27    "G\<turnstile>C\<prec>C1D \<Longrightarrow> C \<noteq> Object \<and> (\<exists>fs ms. class G C = Some (D,fs,ms))"
    1.28  apply (erule subcls1.cases)
    1.29  apply auto
    1.30  done
    1.31  
    1.32 -lemma subcls1_def2: 
    1.33 -  "subcls1 G = (\<lambda>C D. (C, D) \<in>
    1.34 -     (SIGMA C: {C. is_class G C} . {D. C\<noteq>Object \<and> fst (the (class G C))=D}))"
    1.35 -  by (auto simp add: is_class_def expand_fun_eq dest: subcls1D intro: subcls1I)
    1.36 +lemma subcls1_def2:
    1.37 +  "subcls1 P =
    1.38 +     (SIGMA C:{C. is_class P C}. {D. C\<noteq>Object \<and> fst (the (class P C))=D})"
    1.39 +  by (auto simp add: is_class_def dest: subcls1D intro: subcls1I)
    1.40  
    1.41 -lemma finite_subcls1: "finite {(C, D). subcls1 G C D}"
    1.42 +lemma finite_subcls1: "finite (subcls1 G)"
    1.43  apply(simp add: subcls1_def2 del: mem_Sigma_iff)
    1.44  apply(rule finite_SigmaI [OF finite_is_class])
    1.45  apply(rule_tac B = "{fst (the (class G C))}" in finite_subset)
    1.46  apply  auto
    1.47  done
    1.48  
    1.49 -lemma subcls_is_class: "(subcls1 G)^++ C D ==> is_class G C"
    1.50 +lemma subcls_is_class: "(C, D) \<in> (subcls1 G)^+  ==> is_class G C"
    1.51  apply (unfold is_class_def)
    1.52 -apply(erule tranclp_trans_induct)
    1.53 +apply(erule trancl_trans_induct)
    1.54  apply (auto dest!: subcls1D)
    1.55  done
    1.56  
    1.57  lemma subcls_is_class2 [rule_format (no_asm)]: 
    1.58    "G\<turnstile>C\<preceq>C D \<Longrightarrow> is_class G D \<longrightarrow> is_class G C"
    1.59  apply (unfold is_class_def)
    1.60 -apply (erule rtranclp_induct)
    1.61 +apply (erule rtrancl_induct)
    1.62  apply  (drule_tac [2] subcls1D)
    1.63  apply  auto
    1.64  done
    1.65 @@ -54,48 +57,28 @@
    1.66  constdefs
    1.67    class_rec :: "'c prog \<Rightarrow> cname \<Rightarrow> 'a \<Rightarrow>
    1.68      (cname \<Rightarrow> fdecl list \<Rightarrow> 'c mdecl list \<Rightarrow> 'a \<Rightarrow> 'a) \<Rightarrow> 'a"
    1.69 -  "class_rec G == wfrec {(C, D). (subcls1 G)^--1 C D}
    1.70 +  "class_rec G == wfrec ((subcls1 G)^-1)
    1.71      (\<lambda>r C t f. case class G C of
    1.72           None \<Rightarrow> undefined
    1.73         | Some (D,fs,ms) \<Rightarrow> 
    1.74             f C fs ms (if C = Object then t else r D t f))"
    1.75  
    1.76 -lemma class_rec_lemma: "wfP ((subcls1 G)^--1) \<Longrightarrow> class G C = Some (D,fs,ms) \<Longrightarrow>
    1.77 - class_rec G C t f = f C fs ms (if C=Object then t else class_rec G D t f)"
    1.78 -  by (simp add: class_rec_def wfrec [to_pred, where r="(subcls1 G)^--1", simplified]
    1.79 -    cut_apply [where r="{(C, D). subcls1 G D C}", simplified, OF subcls1I])
    1.80 +lemma class_rec_lemma:
    1.81 +  assumes wf: "wf ((subcls1 G)^-1)"
    1.82 +    and cls: "class G C = Some (D, fs, ms)"
    1.83 +  shows "class_rec G C t f = f C fs ms (if C=Object then t else class_rec G D t f)"
    1.84 +proof -
    1.85 +  from wf have step: "\<And>H a. wfrec ((subcls1 G)\<inverse>) H a =
    1.86 +    H (cut (wfrec ((subcls1 G)\<inverse>) H) ((subcls1 G)\<inverse>) a) a"
    1.87 +    by (rule wfrec)
    1.88 +  have cut: "\<And>f. C \<noteq> Object \<Longrightarrow> cut f ((subcls1 G)\<inverse>) C D = f D"
    1.89 +    by (rule cut_apply [where r="(subcls1 G)^-1", simplified, OF subcls1I, OF cls])
    1.90 +  from cls show ?thesis by (simp add: step cut class_rec_def)
    1.91 +qed
    1.92  
    1.93  definition
    1.94 -  "wf_class G = wfP ((subcls1 G)^--1)"
    1.95 +  "wf_class G = wf ((subcls1 G)^-1)"
    1.96  
    1.97 -lemma class_rec_func (*[code]*):
    1.98 -  "class_rec G C t f = (if wf_class G then
    1.99 -    (case class G C
   1.100 -      of None \<Rightarrow> undefined
   1.101 -       | Some (D, fs, ms) \<Rightarrow> f C fs ms (if C = Object then t else class_rec G D t f))
   1.102 -    else class_rec G C t f)"
   1.103 -proof (cases "wf_class G")
   1.104 -  case False then show ?thesis by auto
   1.105 -next
   1.106 -  case True
   1.107 -  from `wf_class G` have wf: "wfP ((subcls1 G)^--1)"
   1.108 -    unfolding wf_class_def .
   1.109 -  show ?thesis
   1.110 -  proof (cases "class G C")
   1.111 -    case None
   1.112 -    with wf show ?thesis
   1.113 -      by (simp add: class_rec_def wfrec [to_pred, where r="(subcls1 G)^--1", simplified]
   1.114 -        cut_apply [where r="{(C, D).subcls1 G D C}", simplified, OF subcls1I])
   1.115 -  next
   1.116 -    case (Some x) show ?thesis
   1.117 -    proof (cases x)
   1.118 -      case (fields D fs ms)
   1.119 -      then have is_some: "class G C = Some (D, fs, ms)" using Some by simp
   1.120 -      note class_rec = class_rec_lemma [OF wf is_some]
   1.121 -      show ?thesis unfolding class_rec by (simp add: is_some)
   1.122 -    qed
   1.123 -  qed
   1.124 -qed
   1.125  
   1.126  text {* Code generator setup (FIXME!) *}
   1.127  
   1.128 @@ -115,7 +98,7 @@
   1.129  defs method_def: "method \<equiv> \<lambda>(G,C). class_rec G C empty (\<lambda>C fs ms ts.
   1.130                             ts ++ map_of (map (\<lambda>(s,m). (s,(C,m))) ms))"
   1.131  
   1.132 -lemma method_rec_lemma: "[|class G C = Some (D,fs,ms); wfP ((subcls1 G)^--1)|] ==>
   1.133 +lemma method_rec_lemma: "[|class G C = Some (D,fs,ms); wf ((subcls1 G)^-1)|] ==>
   1.134    method (G,C) = (if C = Object then empty else method (G,D)) ++  
   1.135    map_of (map (\<lambda>(s,m). (s,(C,m))) ms)"
   1.136  apply (unfold method_def)
   1.137 @@ -129,7 +112,7 @@
   1.138  defs fields_def: "fields \<equiv> \<lambda>(G,C). class_rec G C []    (\<lambda>C fs ms ts.
   1.139                             map (\<lambda>(fn,ft). ((fn,C),ft)) fs @ ts)"
   1.140  
   1.141 -lemma fields_rec_lemma: "[|class G C = Some (D,fs,ms); wfP ((subcls1 G)^--1)|] ==>
   1.142 +lemma fields_rec_lemma: "[|class G C = Some (D,fs,ms); wf ((subcls1 G)^-1)|] ==>
   1.143   fields (G,C) = 
   1.144    map (\<lambda>(fn,ft). ((fn,C),ft)) fs @ (if C = Object then [] else fields (G,D))"
   1.145  apply (unfold fields_def)