src/HOL/NanoJava/TypeRel.thy
author krauss
Sun, 21 Aug 2011 22:13:04 +0200
changeset 44375 dfc2e722fe47
parent 44146 8bc84fa57a13
child 45605 a89b4bc311a5
permissions -rw-r--r--
modernized specifications
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11376
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
     1
(*  Title:      HOL/NanoJava/TypeRel.thy
41589
bbd861837ebc tuned headers;
wenzelm
parents: 35416
diff changeset
     2
    Author:     David von Oheimb, Technische Universitaet Muenchen
11376
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
     3
*)
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
     4
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
     5
header "Type relations"
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
     6
44146
8bc84fa57a13 eliminated use of recdef
krauss
parents: 44013
diff changeset
     7
theory TypeRel imports Decl "~~/src/HOL/Library/Wfrec" begin
11376
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
     8
44375
dfc2e722fe47 modernized specifications
krauss
parents: 44146
diff changeset
     9
text{* Direct subclass relation *}
dfc2e722fe47 modernized specifications
krauss
parents: 44146
diff changeset
    10
dfc2e722fe47 modernized specifications
krauss
parents: 44146
diff changeset
    11
definition subcls1 :: "(cname \<times> cname) set"
dfc2e722fe47 modernized specifications
krauss
parents: 44146
diff changeset
    12
where
dfc2e722fe47 modernized specifications
krauss
parents: 44146
diff changeset
    13
  "subcls1 \<equiv> {(C,D). C\<noteq>Object \<and> (\<exists>c. class C = Some c \<and> super c=D)}"
11376
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    14
35102
cc7a0b9f938c modernized translations;
wenzelm
parents: 31166
diff changeset
    15
abbreviation
cc7a0b9f938c modernized translations;
wenzelm
parents: 31166
diff changeset
    16
  subcls1_syntax :: "[cname, cname] => bool"  ("_ <=C1 _" [71,71] 70)
cc7a0b9f938c modernized translations;
wenzelm
parents: 31166
diff changeset
    17
  where "C <=C1 D == (C,D) \<in> subcls1"
cc7a0b9f938c modernized translations;
wenzelm
parents: 31166
diff changeset
    18
abbreviation
cc7a0b9f938c modernized translations;
wenzelm
parents: 31166
diff changeset
    19
  subcls_syntax  :: "[cname, cname] => bool" ("_ <=C _"  [71,71] 70)
cc7a0b9f938c modernized translations;
wenzelm
parents: 31166
diff changeset
    20
  where "C <=C D == (C,D) \<in> subcls1^*"
11376
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    21
35102
cc7a0b9f938c modernized translations;
wenzelm
parents: 31166
diff changeset
    22
notation (xsymbols)
cc7a0b9f938c modernized translations;
wenzelm
parents: 31166
diff changeset
    23
  subcls1_syntax  ("_ \<prec>C1 _"  [71,71] 70) and
cc7a0b9f938c modernized translations;
wenzelm
parents: 31166
diff changeset
    24
  subcls_syntax  ("_ \<preceq>C _"   [71,71] 70)
11376
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    25
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    26
11565
ab004c0ecc63 Minor improvements, added Example
oheimb
parents: 11558
diff changeset
    27
subsection "Declarations and properties not used in the meta theory"
11376
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    28
11565
ab004c0ecc63 Minor improvements, added Example
oheimb
parents: 11558
diff changeset
    29
text{* Widening, viz. method invocation conversion *}
23755
1c4672d130b1 Adapted to new inductive definition package.
berghofe
parents: 16417
diff changeset
    30
inductive
1c4672d130b1 Adapted to new inductive definition package.
berghofe
parents: 16417
diff changeset
    31
  widen :: "ty => ty => bool"  ("_ \<preceq> _" [71,71] 70)
1c4672d130b1 Adapted to new inductive definition package.
berghofe
parents: 16417
diff changeset
    32
where
1c4672d130b1 Adapted to new inductive definition package.
berghofe
parents: 16417
diff changeset
    33
  refl [intro!, simp]: "T \<preceq> T"
1c4672d130b1 Adapted to new inductive definition package.
berghofe
parents: 16417
diff changeset
    34
| subcls: "C\<preceq>C D \<Longrightarrow> Class C \<preceq> Class D"
1c4672d130b1 Adapted to new inductive definition package.
berghofe
parents: 16417
diff changeset
    35
| null [intro!]: "NT \<preceq> R"
11376
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    36
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    37
lemma subcls1D: 
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    38
  "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
    39
apply (unfold subcls1_def)
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    40
apply auto
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    41
done
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    42
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    43
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
    44
apply (unfold subcls1_def)
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    45
apply auto
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    46
done
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    47
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    48
lemma subcls1_def2: 
14952
47455995693d removal of x-symbol syntax <Sigma> for dependent products
paulson
parents: 14171
diff changeset
    49
  "subcls1 = 
47455995693d removal of x-symbol syntax <Sigma> for dependent products
paulson
parents: 14171
diff changeset
    50
    (SIGMA C: {C. is_class C} . {D. C\<noteq>Object \<and> super (the (class C)) = D})"
11376
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    51
apply (unfold subcls1_def is_class_def)
31166
a90fe83f58ea "{x. P x & x=t & Q x}" is now rewritten to "if P t & Q t then {t} else {}"
nipkow
parents: 28524
diff changeset
    52
apply (auto split:split_if_asm)
11376
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    53
done
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    54
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    55
lemma finite_subcls1: "finite subcls1"
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    56
apply(subst subcls1_def2)
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    57
apply(rule finite_SigmaI [OF finite_is_class])
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    58
apply(rule_tac B = "{super (the (class C))}" in finite_subset)
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    59
apply  auto
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    60
done
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    61
35416
d8d7d1b785af replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents: 35102
diff changeset
    62
definition ws_prog :: "bool" where
11376
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    63
 "ws_prog \<equiv> \<forall>(C,c)\<in>set Prog. C\<noteq>Object \<longrightarrow> 
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    64
                              is_class (super c) \<and> (super c,C)\<notin>subcls1^+"
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    65
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    66
lemma ws_progD: "\<lbrakk>class C = Some c; C\<noteq>Object; ws_prog\<rbrakk> \<Longrightarrow>  
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    67
  is_class (super c) \<and> (super c,C)\<notin>subcls1^+"
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    68
apply (unfold ws_prog_def class_def)
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    69
apply (drule_tac map_of_SomeD)
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    70
apply auto
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    71
done
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    72
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    73
lemma subcls1_irrefl_lemma1: "ws_prog \<Longrightarrow> subcls1^-1 \<inter> subcls1^+ = {}"
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    74
by (fast dest: subcls1D ws_progD)
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    75
13867
1fdecd15437f just a few mods to a few thms
nipkow
parents: 12264
diff changeset
    76
(* irrefl_tranclI in Transitive_Closure.thy is more general *)
11376
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    77
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
    78
by(blast elim: tranclE dest: trancl_into_rtrancl)
1fdecd15437f just a few mods to a few thms
nipkow
parents: 12264
diff changeset
    79
11376
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    80
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    81
lemmas subcls1_irrefl_lemma2 = subcls1_irrefl_lemma1 [THEN irrefl_tranclI']
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    82
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    83
lemma subcls1_irrefl: "\<lbrakk>(x, y) \<in> subcls1; ws_prog\<rbrakk> \<Longrightarrow> x \<noteq> y"
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    84
apply (rule irrefl_trancl_rD)
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    85
apply (rule subcls1_irrefl_lemma2)
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    86
apply auto
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    87
done
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    88
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    89
lemmas subcls1_acyclic = subcls1_irrefl_lemma2 [THEN acyclicI, standard]
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    90
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    91
lemma wf_subcls1: "ws_prog \<Longrightarrow> wf (subcls1\<inverse>)"
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    92
by (auto intro: finite_acyclic_wf_converse finite_subcls1 subcls1_acyclic)
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    93
44146
8bc84fa57a13 eliminated use of recdef
krauss
parents: 44013
diff changeset
    94
definition class_rec ::"cname \<Rightarrow> (class \<Rightarrow> ('a \<times> 'b) list) \<Rightarrow> ('a \<rightharpoonup> 'b)"
8bc84fa57a13 eliminated use of recdef
krauss
parents: 44013
diff changeset
    95
where
8bc84fa57a13 eliminated use of recdef
krauss
parents: 44013
diff changeset
    96
  "class_rec \<equiv> wfrec (subcls1\<inverse>) (\<lambda>rec C f.
8bc84fa57a13 eliminated use of recdef
krauss
parents: 44013
diff changeset
    97
     case class C of None \<Rightarrow> undefined
8bc84fa57a13 eliminated use of recdef
krauss
parents: 44013
diff changeset
    98
      | Some m \<Rightarrow> (if C = Object then empty else rec (super m) f) ++ map_of (f m))"
11376
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
    99
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
   100
lemma class_rec: "\<lbrakk>class C = Some m;  ws_prog\<rbrakk> \<Longrightarrow>
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
   101
 class_rec C f = (if C = Object then empty else class_rec (super m) f) ++ 
44146
8bc84fa57a13 eliminated use of recdef
krauss
parents: 44013
diff changeset
   102
                 map_of (f m)"
11376
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
   103
apply (drule wf_subcls1)
44146
8bc84fa57a13 eliminated use of recdef
krauss
parents: 44013
diff changeset
   104
apply (subst def_wfrec[OF class_rec_def], auto)
8bc84fa57a13 eliminated use of recdef
krauss
parents: 44013
diff changeset
   105
apply (subst cut_apply, auto intro: subcls1I)
11376
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
   106
done
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
   107
11565
ab004c0ecc63 Minor improvements, added Example
oheimb
parents: 11558
diff changeset
   108
--{* Methods of a class, with inheritance and hiding *}
44375
dfc2e722fe47 modernized specifications
krauss
parents: 44146
diff changeset
   109
definition method :: "cname => (mname \<rightharpoonup> methd)" where
dfc2e722fe47 modernized specifications
krauss
parents: 44146
diff changeset
   110
  "method C \<equiv> class_rec C methods"
11376
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
   111
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
   112
lemma method_rec: "\<lbrakk>class C = Some m; ws_prog\<rbrakk> \<Longrightarrow>
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
   113
method C = (if C=Object then empty else method (super m)) ++ map_of (methods m)"
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
   114
apply (unfold method_def)
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
   115
apply (erule (1) class_rec [THEN trans]);
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
   116
apply simp
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
   117
done
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
   118
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
   119
11565
ab004c0ecc63 Minor improvements, added Example
oheimb
parents: 11558
diff changeset
   120
--{* Fields of a class, with inheritance and hiding *}
44375
dfc2e722fe47 modernized specifications
krauss
parents: 44146
diff changeset
   121
definition field  :: "cname => (fname \<rightharpoonup> ty)" where
dfc2e722fe47 modernized specifications
krauss
parents: 44146
diff changeset
   122
  "field C \<equiv> class_rec C flds"
11376
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
   123
12264
9c356e2da72f renamed "fields" to "flds" (avoid clash with new "fields" operation);
wenzelm
parents: 11626
diff changeset
   124
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
   125
field C = (if C=Object then empty else field (super m)) ++ map_of (flds m)"
11376
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
   126
apply (unfold field_def)
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
   127
apply (erule (1) class_rec [THEN trans]);
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
   128
apply simp
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
   129
done
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
   130
bf98ad1c22c6 added NanoJava
oheimb
parents:
diff changeset
   131
end