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