src/HOL/NanoJava/TypeRel.thy
author nipkow
Mon Mar 17 18:38:50 2003 +0100 (2003-03-17)
changeset 13867 1fdecd15437f
parent 12264 9c356e2da72f
child 14134 0fdf5708c7a8
permissions -rw-r--r--
just a few mods to a few thms
     1 (*  Title:      HOL/NanoJava/TypeRel.thy
     2     ID:         $Id$
     3     Author:     David von Oheimb
     4     Copyright   2001 Technische Universitaet Muenchen
     5 *)
     6 
     7 header "Type relations"
     8 
     9 theory TypeRel = Decl:
    10 
    11 consts
    12   widen   :: "(ty    \<times> ty   ) set"  --{* widening *}
    13   subcls1 :: "(cname \<times> cname) set"  --{* subclass *}
    14 
    15 syntax (xsymbols)
    16   widen   :: "[ty   , ty   ] => bool" ("_ \<preceq> _"    [71,71] 70)
    17   subcls1 :: "[cname, cname] => bool" ("_ \<prec>C1 _"  [71,71] 70)
    18   subcls  :: "[cname, cname] => bool" ("_ \<preceq>C _"   [71,71] 70)
    19 syntax
    20   widen   :: "[ty   , ty   ] => bool" ("_ <= _"   [71,71] 70)
    21   subcls1 :: "[cname, cname] => bool" ("_ <=C1 _" [71,71] 70)
    22   subcls  :: "[cname, cname] => bool" ("_ <=C _"  [71,71] 70)
    23 
    24 translations
    25   "C \<prec>C1 D" == "(C,D) \<in> subcls1"
    26   "C \<preceq>C  D" == "(C,D) \<in> subcls1^*"
    27   "S \<preceq>   T" == "(S,T) \<in> widen"
    28 
    29 consts
    30   method :: "cname => (mname \<leadsto> methd)"
    31   field  :: "cname => (fname \<leadsto> ty)"
    32 
    33 
    34 subsection "Declarations and properties not used in the meta theory"
    35 
    36 text{* Direct subclass relation *}
    37 defs
    38  subcls1_def: "subcls1 \<equiv> {(C,D). C\<noteq>Object \<and> (\<exists>c. class C = Some c \<and> super c=D)}"
    39 
    40 text{* Widening, viz. method invocation conversion *}
    41 inductive widen intros 
    42   refl   [intro!, simp]:           "T \<preceq> T"
    43   subcls         : "C\<preceq>C D \<Longrightarrow> Class C \<preceq> Class D"
    44   null   [intro!]:                "NT \<preceq> R"
    45 
    46 lemma subcls1D: 
    47   "C\<prec>C1D \<Longrightarrow> C \<noteq> Object \<and> (\<exists>c. class C = Some c \<and> super c=D)"
    48 apply (unfold subcls1_def)
    49 apply auto
    50 done
    51 
    52 lemma subcls1I: "\<lbrakk>class C = Some m; super m = D; C \<noteq> Object\<rbrakk> \<Longrightarrow> C\<prec>C1D"
    53 apply (unfold subcls1_def)
    54 apply auto
    55 done
    56 
    57 lemma subcls1_def2: 
    58 "subcls1 = (\<Sigma>C\<in>{C. is_class C} . {D. C\<noteq>Object \<and> super (the (class C)) = D})"
    59 apply (unfold subcls1_def is_class_def)
    60 apply auto
    61 done
    62 
    63 lemma finite_subcls1: "finite subcls1"
    64 apply(subst subcls1_def2)
    65 apply(rule finite_SigmaI [OF finite_is_class])
    66 apply(rule_tac B = "{super (the (class C))}" in finite_subset)
    67 apply  auto
    68 done
    69 
    70 constdefs
    71 
    72   ws_prog  :: "bool"
    73  "ws_prog \<equiv> \<forall>(C,c)\<in>set Prog. C\<noteq>Object \<longrightarrow> 
    74                               is_class (super c) \<and> (super c,C)\<notin>subcls1^+"
    75 
    76 lemma ws_progD: "\<lbrakk>class C = Some c; C\<noteq>Object; ws_prog\<rbrakk> \<Longrightarrow>  
    77   is_class (super c) \<and> (super c,C)\<notin>subcls1^+"
    78 apply (unfold ws_prog_def class_def)
    79 apply (drule_tac map_of_SomeD)
    80 apply auto
    81 done
    82 
    83 lemma subcls1_irrefl_lemma1: "ws_prog \<Longrightarrow> subcls1^-1 \<inter> subcls1^+ = {}"
    84 by (fast dest: subcls1D ws_progD)
    85 
    86 (* irrefl_tranclI in Transitive_Closure.thy is more general *)
    87 lemma irrefl_tranclI': "r^-1 Int r^+ = {} ==> !x. (x, x) ~: r^+"
    88 by(blast elim: tranclE dest: trancl_into_rtrancl)
    89 
    90 
    91 lemmas subcls1_irrefl_lemma2 = subcls1_irrefl_lemma1 [THEN irrefl_tranclI']
    92 
    93 lemma subcls1_irrefl: "\<lbrakk>(x, y) \<in> subcls1; ws_prog\<rbrakk> \<Longrightarrow> x \<noteq> y"
    94 apply (rule irrefl_trancl_rD)
    95 apply (rule subcls1_irrefl_lemma2)
    96 apply auto
    97 done
    98 
    99 lemmas subcls1_acyclic = subcls1_irrefl_lemma2 [THEN acyclicI, standard]
   100 
   101 lemma wf_subcls1: "ws_prog \<Longrightarrow> wf (subcls1\<inverse>)"
   102 by (auto intro: finite_acyclic_wf_converse finite_subcls1 subcls1_acyclic)
   103 
   104 
   105 consts class_rec ::"cname \<Rightarrow> (class \<Rightarrow> ('a \<times> 'b) list) \<Rightarrow> ('a \<leadsto> 'b)"
   106 
   107 recdef (permissive) class_rec "subcls1\<inverse>"
   108       "class_rec C = (\<lambda>f. case class C of None   \<Rightarrow> arbitrary 
   109                                         | Some m \<Rightarrow> if wf (subcls1\<inverse>) 
   110        then (if C=Object then empty else class_rec (super m) f) ++ map_of (f m)
   111        else arbitrary)"
   112 (hints intro: subcls1I)
   113 
   114 lemma class_rec: "\<lbrakk>class C = Some m;  ws_prog\<rbrakk> \<Longrightarrow>
   115  class_rec C f = (if C = Object then empty else class_rec (super m) f) ++ 
   116                  map_of (f m)";
   117 apply (drule wf_subcls1)
   118 apply (rule class_rec.simps [THEN trans [THEN fun_cong]])
   119 apply  assumption
   120 apply simp
   121 done
   122 
   123 --{* Methods of a class, with inheritance and hiding *}
   124 defs method_def: "method C \<equiv> class_rec C methods"
   125 
   126 lemma method_rec: "\<lbrakk>class C = Some m; ws_prog\<rbrakk> \<Longrightarrow>
   127 method C = (if C=Object then empty else method (super m)) ++ map_of (methods m)"
   128 apply (unfold method_def)
   129 apply (erule (1) class_rec [THEN trans]);
   130 apply simp
   131 done
   132 
   133 
   134 --{* Fields of a class, with inheritance and hiding *}
   135 defs field_def: "field C \<equiv> class_rec C flds"
   136 
   137 lemma flds_rec: "\<lbrakk>class C = Some m; ws_prog\<rbrakk> \<Longrightarrow>
   138 field C = (if C=Object then empty else field (super m)) ++ map_of (flds m)"
   139 apply (unfold field_def)
   140 apply (erule (1) class_rec [THEN trans]);
   141 apply simp
   142 done
   143 
   144 end