src/HOL/Bali/AxSem.thy
author wenzelm
Wed Feb 10 00:45:16 2010 +0100 (2010-02-10)
changeset 35067 af4c18c30593
parent 32960 69916a850301
child 35069 09154b995ed8
permissions -rw-r--r--
modernized syntax translations, using mostly abbreviation/notation;
minor tuning;
wenzelm@12857
     1
(*  Title:      HOL/Bali/AxSem.thy
schirmer@12854
     2
    ID:         $Id$
schirmer@12854
     3
    Author:     David von Oheimb
schirmer@12854
     4
*)
schirmer@12854
     5
schirmer@12854
     6
header {* Axiomatic semantics of Java expressions and statements 
schirmer@12854
     7
          (see also Eval.thy)
schirmer@12854
     8
        *}
haftmann@16417
     9
theory AxSem imports Evaln TypeSafe begin
schirmer@12854
    10
schirmer@12854
    11
text {*
schirmer@12854
    12
design issues:
schirmer@12854
    13
\begin{itemize}
schirmer@12854
    14
\item a strong version of validity for triples with premises, namely one that 
schirmer@12854
    15
      takes the recursive depth needed to complete execution, enables 
schirmer@12854
    16
      correctness proof
schirmer@12854
    17
\item auxiliary variables are handled first-class (-> Thomas Kleymann)
schirmer@12854
    18
\item expressions not flattened to elementary assignments (as usual for 
schirmer@12854
    19
      axiomatic semantics) but treated first-class => explicit result value 
schirmer@12854
    20
      handling
schirmer@12854
    21
\item intermediate values not on triple, but on assertion level 
schirmer@12854
    22
      (with result entry)
schirmer@12854
    23
\item multiple results with semantical substitution mechnism not requiring a 
schirmer@12854
    24
      stack 
schirmer@12854
    25
\item because of dynamic method binding, terms need to be dependent on state.
schirmer@12854
    26
  this is also useful for conditional expressions and statements
schirmer@12854
    27
\item result values in triples exactly as in eval relation (also for xcpt 
schirmer@12854
    28
      states)
schirmer@12854
    29
\item validity: additional assumption of state conformance and well-typedness,
schirmer@12854
    30
  which is required for soundness and thus rule hazard required of completeness
schirmer@12854
    31
\end{itemize}
schirmer@12854
    32
schirmer@12854
    33
restrictions:
schirmer@12854
    34
\begin{itemize}
schirmer@12854
    35
\item all triples in a derivation are of the same type (due to weak 
schirmer@12854
    36
      polymorphism)
schirmer@12854
    37
\end{itemize}
schirmer@12854
    38
*}
schirmer@12854
    39
schirmer@13688
    40
types  res = vals --{* result entry *}
wenzelm@35067
    41
wenzelm@35067
    42
abbreviation (input)
wenzelm@35067
    43
  Val where "Val x == In1 x"
wenzelm@35067
    44
wenzelm@35067
    45
abbreviation (input)
wenzelm@35067
    46
  Var where "Var x == In2 x"
wenzelm@35067
    47
wenzelm@35067
    48
abbreviation (input)
wenzelm@35067
    49
  Vals where "Vals x == In3 x"
schirmer@12854
    50
schirmer@12854
    51
syntax
wenzelm@24783
    52
  "_Val"    :: "[pttrn] => pttrn"     ("Val:_"  [951] 950)
wenzelm@24783
    53
  "_Var"    :: "[pttrn] => pttrn"     ("Var:_"  [951] 950)
wenzelm@24783
    54
  "_Vals"   :: "[pttrn] => pttrn"     ("Vals:_" [951] 950)
schirmer@12854
    55
schirmer@12854
    56
translations
wenzelm@35067
    57
  "\<lambda>Val:v . b"  == "(\<lambda>v. b) \<circ> CONST the_In1"
wenzelm@35067
    58
  "\<lambda>Var:v . b"  == "(\<lambda>v. b) \<circ> CONST the_In2"
wenzelm@35067
    59
  "\<lambda>Vals:v. b"  == "(\<lambda>v. b) \<circ> CONST the_In3"
schirmer@12854
    60
schirmer@13688
    61
  --{* relation on result values, state and auxiliary variables *}
schirmer@12854
    62
types 'a assn   =        "res \<Rightarrow> state \<Rightarrow> 'a \<Rightarrow> bool"
schirmer@12854
    63
translations
schirmer@12854
    64
      "res"    <= (type) "AxSem.res"
schirmer@12854
    65
      "a assn" <= (type) "vals \<Rightarrow> state \<Rightarrow> a \<Rightarrow> bool"
schirmer@12854
    66
schirmer@12854
    67
constdefs
schirmer@12854
    68
  assn_imp   :: "'a assn \<Rightarrow> 'a assn \<Rightarrow> bool"             (infixr "\<Rightarrow>" 25)
schirmer@12854
    69
 "P \<Rightarrow> Q \<equiv> \<forall>Y s Z. P Y s Z \<longrightarrow> Q Y s Z"
schirmer@12854
    70
  
schirmer@12854
    71
lemma assn_imp_def2 [iff]: "(P \<Rightarrow> Q) = (\<forall>Y s Z. P Y s Z \<longrightarrow> Q Y s Z)"
schirmer@12854
    72
apply (unfold assn_imp_def)
schirmer@12854
    73
apply (rule HOL.refl)
schirmer@12854
    74
done
schirmer@12854
    75
schirmer@12854
    76
schirmer@12854
    77
section "assertion transformers"
schirmer@12854
    78
schirmer@12854
    79
subsection "peek-and"
schirmer@12854
    80
schirmer@12854
    81
constdefs
schirmer@12854
    82
  peek_and   :: "'a assn \<Rightarrow> (state \<Rightarrow>  bool) \<Rightarrow> 'a assn" (infixl "\<and>." 13)
schirmer@12854
    83
 "P \<and>. p \<equiv> \<lambda>Y s Z. P Y s Z \<and> p s"
schirmer@12854
    84
schirmer@12854
    85
lemma peek_and_def2 [simp]: "peek_and P p Y s = (\<lambda>Z. (P Y s Z \<and> p s))"
schirmer@12854
    86
apply (unfold peek_and_def)
schirmer@12854
    87
apply (simp (no_asm))
schirmer@12854
    88
done
schirmer@12854
    89
schirmer@12854
    90
lemma peek_and_Not [simp]: "(P \<and>. (\<lambda>s. \<not> f s)) = (P \<and>. Not \<circ> f)"
schirmer@12854
    91
apply (rule ext)
schirmer@12854
    92
apply (rule ext)
schirmer@12854
    93
apply (simp (no_asm))
schirmer@12854
    94
done
schirmer@12854
    95
schirmer@12854
    96
lemma peek_and_and [simp]: "peek_and (peek_and P p) p = peek_and P p"
schirmer@12854
    97
apply (unfold peek_and_def)
schirmer@12854
    98
apply (simp (no_asm))
schirmer@12854
    99
done
schirmer@12854
   100
schirmer@12854
   101
lemma peek_and_commut: "(P \<and>. p \<and>. q) = (P \<and>. q \<and>. p)"
schirmer@12854
   102
apply (rule ext)
schirmer@12854
   103
apply (rule ext)
schirmer@12854
   104
apply (rule ext)
schirmer@12854
   105
apply auto
schirmer@12854
   106
done
schirmer@12854
   107
wenzelm@35067
   108
abbreviation
wenzelm@35067
   109
  Normal :: "'a assn \<Rightarrow> 'a assn"
wenzelm@35067
   110
  where "Normal P == P \<and>. normal"
schirmer@12854
   111
schirmer@12854
   112
lemma peek_and_Normal [simp]: "peek_and (Normal P) p = Normal (peek_and P p)"
schirmer@12854
   113
apply (rule ext)
schirmer@12854
   114
apply (rule ext)
schirmer@12854
   115
apply (rule ext)
schirmer@12854
   116
apply auto
schirmer@12854
   117
done
schirmer@12854
   118
schirmer@12854
   119
subsection "assn-supd"
schirmer@12854
   120
schirmer@12854
   121
constdefs
schirmer@12854
   122
  assn_supd  :: "'a assn \<Rightarrow> (state \<Rightarrow> state) \<Rightarrow> 'a assn" (infixl ";." 13)
schirmer@12854
   123
 "P ;. f \<equiv> \<lambda>Y s' Z. \<exists>s. P Y s Z \<and> s' = f s"
schirmer@12854
   124
schirmer@12854
   125
lemma assn_supd_def2 [simp]: "assn_supd P f Y s' Z = (\<exists>s. P Y s Z \<and> s' = f s)"
schirmer@12854
   126
apply (unfold assn_supd_def)
schirmer@12854
   127
apply (simp (no_asm))
schirmer@12854
   128
done
schirmer@12854
   129
schirmer@12854
   130
subsection "supd-assn"
schirmer@12854
   131
schirmer@12854
   132
constdefs
schirmer@12854
   133
  supd_assn  :: "(state \<Rightarrow> state) \<Rightarrow> 'a assn \<Rightarrow> 'a assn" (infixr ".;" 13)
schirmer@12854
   134
 "f .; P \<equiv> \<lambda>Y s. P Y (f s)"
schirmer@12854
   135
schirmer@12854
   136
schirmer@12854
   137
lemma supd_assn_def2 [simp]: "(f .; P) Y s = P Y (f s)"
schirmer@12854
   138
apply (unfold supd_assn_def)
schirmer@12854
   139
apply (simp (no_asm))
schirmer@12854
   140
done
schirmer@12854
   141
schirmer@12854
   142
lemma supd_assn_supdD [elim]: "((f .; Q) ;. f) Y s Z \<Longrightarrow> Q Y s Z"
schirmer@12854
   143
apply auto
schirmer@12854
   144
done
schirmer@12854
   145
schirmer@12854
   146
lemma supd_assn_supdI [elim]: "Q Y s Z \<Longrightarrow> (f .; (Q ;. f)) Y s Z"
schirmer@12854
   147
apply (auto simp del: split_paired_Ex)
schirmer@12854
   148
done
schirmer@12854
   149
schirmer@12854
   150
subsection "subst-res"
schirmer@12854
   151
schirmer@12854
   152
constdefs
schirmer@12854
   153
  subst_res   :: "'a assn \<Rightarrow> res \<Rightarrow> 'a assn"              ("_\<leftarrow>_"  [60,61] 60)
schirmer@12854
   154
 "P\<leftarrow>w \<equiv> \<lambda>Y. P w"
schirmer@12854
   155
schirmer@12854
   156
lemma subst_res_def2 [simp]: "(P\<leftarrow>w) Y = P w"
schirmer@12854
   157
apply (unfold subst_res_def)
schirmer@12854
   158
apply (simp (no_asm))
schirmer@12854
   159
done
schirmer@12854
   160
schirmer@12854
   161
lemma subst_subst_res [simp]: "P\<leftarrow>w\<leftarrow>v = P\<leftarrow>w"
schirmer@12854
   162
apply (rule ext)
schirmer@12854
   163
apply (simp (no_asm))
schirmer@12854
   164
done
schirmer@12854
   165
schirmer@12854
   166
lemma peek_and_subst_res [simp]: "(P \<and>. p)\<leftarrow>w = (P\<leftarrow>w \<and>. p)"
schirmer@12854
   167
apply (rule ext)
schirmer@12854
   168
apply (rule ext)
schirmer@12854
   169
apply (simp (no_asm))
schirmer@12854
   170
done
schirmer@12854
   171
schirmer@12854
   172
(*###Do not work for some strange (unification?) reason
schirmer@12854
   173
lemma subst_res_Val_beta [simp]: "(\<lambda>Y. P (the_In1 Y))\<leftarrow>Val v = (\<lambda>Y. P v)"
schirmer@12854
   174
apply (rule ext)
schirmer@12854
   175
by simp
schirmer@12854
   176
schirmer@12854
   177
lemma subst_res_Var_beta [simp]: "(\<lambda>Y. P (the_In2 Y))\<leftarrow>Var vf = (\<lambda>Y. P vf)";
schirmer@12854
   178
apply (rule ext)
schirmer@12854
   179
by simp
schirmer@12854
   180
schirmer@12854
   181
lemma subst_res_Vals_beta [simp]: "(\<lambda>Y. P (the_In3 Y))\<leftarrow>Vals vs = (\<lambda>Y. P vs)";
schirmer@12854
   182
apply (rule ext)
schirmer@12854
   183
by simp
schirmer@12854
   184
*)
schirmer@12854
   185
schirmer@12854
   186
subsection "subst-Bool"
schirmer@12854
   187
schirmer@12854
   188
constdefs
schirmer@12854
   189
  subst_Bool  :: "'a assn \<Rightarrow> bool \<Rightarrow> 'a assn"             ("_\<leftarrow>=_" [60,61] 60)
schirmer@12854
   190
 "P\<leftarrow>=b \<equiv> \<lambda>Y s Z. \<exists>v. P (Val v) s Z \<and> (normal s \<longrightarrow> the_Bool v=b)"
schirmer@12854
   191
schirmer@12854
   192
lemma subst_Bool_def2 [simp]: 
schirmer@12854
   193
"(P\<leftarrow>=b) Y s Z = (\<exists>v. P (Val v) s Z \<and> (normal s \<longrightarrow> the_Bool v=b))"
schirmer@12854
   194
apply (unfold subst_Bool_def)
schirmer@12854
   195
apply (simp (no_asm))
schirmer@12854
   196
done
schirmer@12854
   197
schirmer@12854
   198
lemma subst_Bool_the_BoolI: "P (Val b) s Z \<Longrightarrow> (P\<leftarrow>=the_Bool b) Y s Z"
schirmer@12854
   199
apply auto
schirmer@12854
   200
done
schirmer@12854
   201
schirmer@12854
   202
subsection "peek-res"
schirmer@12854
   203
schirmer@12854
   204
constdefs
schirmer@12854
   205
  peek_res    :: "(res \<Rightarrow> 'a assn) \<Rightarrow> 'a assn"
schirmer@12854
   206
 "peek_res Pf \<equiv> \<lambda>Y. Pf Y Y"
schirmer@12854
   207
schirmer@12854
   208
syntax
wenzelm@35067
   209
  "_peek_res" :: "pttrn \<Rightarrow> 'a assn \<Rightarrow> 'a assn"            ("\<lambda>_:. _" [0,3] 3)
schirmer@12854
   210
translations
wenzelm@35067
   211
  "\<lambda>w:. P"   == "CONST peek_res (\<lambda>w. P)"
schirmer@12854
   212
schirmer@12854
   213
lemma peek_res_def2 [simp]: "peek_res P Y = P Y Y"
schirmer@12854
   214
apply (unfold peek_res_def)
schirmer@12854
   215
apply (simp (no_asm))
schirmer@12854
   216
done
schirmer@12854
   217
schirmer@12854
   218
lemma peek_res_subst_res [simp]: "peek_res P\<leftarrow>w = P w\<leftarrow>w"
schirmer@12854
   219
apply (rule ext)
schirmer@12854
   220
apply (simp (no_asm))
schirmer@12854
   221
done
schirmer@12854
   222
schirmer@12854
   223
(* unused *)
schirmer@12854
   224
lemma peek_subst_res_allI: 
schirmer@12854
   225
 "(\<And>a. T a (P (f a)\<leftarrow>f a)) \<Longrightarrow> \<forall>a. T a (peek_res P\<leftarrow>f a)"
schirmer@12854
   226
apply (rule allI)
schirmer@12854
   227
apply (simp (no_asm))
schirmer@12854
   228
apply fast
schirmer@12854
   229
done
schirmer@12854
   230
schirmer@12854
   231
subsection "ign-res"
schirmer@12854
   232
schirmer@12854
   233
constdefs
schirmer@12854
   234
  ign_res    ::  "        'a assn \<Rightarrow> 'a assn"            ("_\<down>" [1000] 1000)
schirmer@12854
   235
  "P\<down>        \<equiv> \<lambda>Y s Z. \<exists>Y. P Y s Z"
schirmer@12854
   236
schirmer@12854
   237
lemma ign_res_def2 [simp]: "P\<down> Y s Z = (\<exists>Y. P Y s Z)"
schirmer@12854
   238
apply (unfold ign_res_def)
schirmer@12854
   239
apply (simp (no_asm))
schirmer@12854
   240
done
schirmer@12854
   241
schirmer@12854
   242
lemma ign_ign_res [simp]: "P\<down>\<down> = P\<down>"
schirmer@12854
   243
apply (rule ext)
schirmer@12854
   244
apply (rule ext)
schirmer@12854
   245
apply (rule ext)
schirmer@12854
   246
apply (simp (no_asm))
schirmer@12854
   247
done
schirmer@12854
   248
schirmer@12854
   249
lemma ign_subst_res [simp]: "P\<down>\<leftarrow>w = P\<down>"
schirmer@12854
   250
apply (rule ext)
schirmer@12854
   251
apply (rule ext)
schirmer@12854
   252
apply (rule ext)
schirmer@12854
   253
apply (simp (no_asm))
schirmer@12854
   254
done
schirmer@12854
   255
schirmer@12854
   256
lemma peek_and_ign_res [simp]: "(P \<and>. p)\<down> = (P\<down> \<and>. p)"
schirmer@12854
   257
apply (rule ext)
schirmer@12854
   258
apply (rule ext)
schirmer@12854
   259
apply (rule ext)
schirmer@12854
   260
apply (simp (no_asm))
schirmer@12854
   261
done
schirmer@12854
   262
schirmer@12854
   263
subsection "peek-st"
schirmer@12854
   264
schirmer@12854
   265
constdefs
schirmer@12854
   266
  peek_st    :: "(st \<Rightarrow> 'a assn) \<Rightarrow> 'a assn"
schirmer@12854
   267
 "peek_st P \<equiv> \<lambda>Y s. P (store s) Y s"
schirmer@12854
   268
schirmer@12854
   269
syntax
wenzelm@35067
   270
  "_peek_st"   :: "pttrn \<Rightarrow> 'a assn \<Rightarrow> 'a assn"            ("\<lambda>_.. _" [0,3] 3)
schirmer@12854
   271
translations
wenzelm@35067
   272
  "\<lambda>s.. P"   == "CONST peek_st (\<lambda>s. P)"
schirmer@12854
   273
schirmer@12854
   274
lemma peek_st_def2 [simp]: "(\<lambda>s.. Pf s) Y s = Pf (store s) Y s"
schirmer@12854
   275
apply (unfold peek_st_def)
schirmer@12854
   276
apply (simp (no_asm))
schirmer@12854
   277
done
schirmer@12854
   278
schirmer@12854
   279
lemma peek_st_triv [simp]: "(\<lambda>s.. P) = P"
schirmer@12854
   280
apply (rule ext)
schirmer@12854
   281
apply (rule ext)
schirmer@12854
   282
apply (simp (no_asm))
schirmer@12854
   283
done
schirmer@12854
   284
schirmer@12854
   285
lemma peek_st_st [simp]: "(\<lambda>s.. \<lambda>s'.. P s s') = (\<lambda>s.. P s s)"
schirmer@12854
   286
apply (rule ext)
schirmer@12854
   287
apply (rule ext)
schirmer@12854
   288
apply (simp (no_asm))
schirmer@12854
   289
done
schirmer@12854
   290
schirmer@12854
   291
lemma peek_st_split [simp]: "(\<lambda>s.. \<lambda>Y s'. P s Y s') = (\<lambda>Y s. P (store s) Y s)"
schirmer@12854
   292
apply (rule ext)
schirmer@12854
   293
apply (rule ext)
schirmer@12854
   294
apply (simp (no_asm))
schirmer@12854
   295
done
schirmer@12854
   296
schirmer@12854
   297
lemma peek_st_subst_res [simp]: "(\<lambda>s.. P s)\<leftarrow>w = (\<lambda>s.. P s\<leftarrow>w)"
schirmer@12854
   298
apply (rule ext)
schirmer@12854
   299
apply (simp (no_asm))
schirmer@12854
   300
done
schirmer@12854
   301
schirmer@12854
   302
lemma peek_st_Normal [simp]: "(\<lambda>s..(Normal (P s))) = Normal (\<lambda>s.. P s)"
schirmer@12854
   303
apply (rule ext)
schirmer@12854
   304
apply (rule ext)
schirmer@12854
   305
apply (simp (no_asm))
schirmer@12854
   306
done
schirmer@12854
   307
schirmer@12854
   308
subsection "ign-res-eq"
schirmer@12854
   309
schirmer@12854
   310
constdefs
schirmer@12854
   311
  ign_res_eq :: "'a assn \<Rightarrow> res \<Rightarrow> 'a assn"               ("_\<down>=_"  [60,61] 60)
schirmer@12854
   312
 "P\<down>=w       \<equiv> \<lambda>Y:. P\<down> \<and>. (\<lambda>s. Y=w)"
schirmer@12854
   313
schirmer@12854
   314
lemma ign_res_eq_def2 [simp]: "(P\<down>=w) Y s Z = ((\<exists>Y. P Y s Z) \<and> Y=w)"
schirmer@12854
   315
apply (unfold ign_res_eq_def)
schirmer@12854
   316
apply auto
schirmer@12854
   317
done
schirmer@12854
   318
schirmer@12854
   319
lemma ign_ign_res_eq [simp]: "(P\<down>=w)\<down> = P\<down>"
schirmer@12854
   320
apply (rule ext)
schirmer@12854
   321
apply (rule ext)
schirmer@12854
   322
apply (rule ext)
schirmer@12854
   323
apply (simp (no_asm))
schirmer@12854
   324
done
schirmer@12854
   325
schirmer@12854
   326
(* unused *)
schirmer@12854
   327
lemma ign_res_eq_subst_res: "P\<down>=w\<leftarrow>w = P\<down>"
schirmer@12854
   328
apply (rule ext)
schirmer@12854
   329
apply (rule ext)
schirmer@12854
   330
apply (rule ext)
schirmer@12854
   331
apply (simp (no_asm))
schirmer@12854
   332
done
schirmer@12854
   333
schirmer@12854
   334
(* unused *)
schirmer@12854
   335
lemma subst_Bool_ign_res_eq: "((P\<leftarrow>=b)\<down>=x) Y s Z = ((P\<leftarrow>=b) Y s Z  \<and> Y=x)"
schirmer@12854
   336
apply (simp (no_asm))
schirmer@12854
   337
done
schirmer@12854
   338
schirmer@12854
   339
subsection "RefVar"
schirmer@12854
   340
schirmer@12854
   341
constdefs
schirmer@12854
   342
  RefVar    :: "(state \<Rightarrow> vvar \<times> state) \<Rightarrow> 'a assn \<Rightarrow> 'a assn"(infixr "..;" 13)
schirmer@12854
   343
 "vf ..; P \<equiv> \<lambda>Y s. let (v,s') = vf s in P (Var v) s'"
schirmer@12854
   344
 
schirmer@12854
   345
lemma RefVar_def2 [simp]: "(vf ..; P) Y s =  
schirmer@12854
   346
  P (Var (fst (vf s))) (snd (vf s))"
schirmer@12854
   347
apply (unfold RefVar_def Let_def)
schirmer@12854
   348
apply (simp (no_asm) add: split_beta)
schirmer@12854
   349
done
schirmer@12854
   350
schirmer@12854
   351
subsection "allocation"
schirmer@12854
   352
schirmer@12854
   353
constdefs
schirmer@12854
   354
  Alloc      :: "prog \<Rightarrow> obj_tag \<Rightarrow> 'a assn \<Rightarrow> 'a assn"
schirmer@12854
   355
 "Alloc G otag P \<equiv> \<lambda>Y s Z.
schirmer@12854
   356
                   \<forall>s' a. G\<turnstile>s \<midarrow>halloc otag\<succ>a\<rightarrow> s'\<longrightarrow> P (Val (Addr a)) s' Z"
schirmer@12854
   357
schirmer@12854
   358
  SXAlloc     :: "prog \<Rightarrow> 'a assn \<Rightarrow> 'a assn"
schirmer@12854
   359
 "SXAlloc G P \<equiv> \<lambda>Y s Z. \<forall>s'. G\<turnstile>s \<midarrow>sxalloc\<rightarrow> s' \<longrightarrow> P Y s' Z"
schirmer@12854
   360
schirmer@12854
   361
schirmer@12854
   362
lemma Alloc_def2 [simp]: "Alloc G otag P Y s Z =  
schirmer@12854
   363
       (\<forall>s' a. G\<turnstile>s \<midarrow>halloc otag\<succ>a\<rightarrow> s'\<longrightarrow> P (Val (Addr a)) s' Z)"
schirmer@12854
   364
apply (unfold Alloc_def)
schirmer@12854
   365
apply (simp (no_asm))
schirmer@12854
   366
done
schirmer@12854
   367
schirmer@12854
   368
lemma SXAlloc_def2 [simp]: 
schirmer@12854
   369
  "SXAlloc G P Y s Z = (\<forall>s'. G\<turnstile>s \<midarrow>sxalloc\<rightarrow> s' \<longrightarrow> P Y s' Z)"
schirmer@12854
   370
apply (unfold SXAlloc_def)
schirmer@12854
   371
apply (simp (no_asm))
schirmer@12854
   372
done
schirmer@12854
   373
schirmer@12854
   374
section "validity"
schirmer@12854
   375
schirmer@12854
   376
constdefs
schirmer@12854
   377
  type_ok  :: "prog \<Rightarrow> term \<Rightarrow> state \<Rightarrow> bool"
schirmer@13688
   378
 "type_ok G t s \<equiv> 
schirmer@13688
   379
    \<exists>L T C A. (normal s \<longrightarrow> \<lparr>prg=G,cls=C,lcl=L\<rparr>\<turnstile>t\<Colon>T \<and> 
schirmer@13688
   380
                            \<lparr>prg=G,cls=C,lcl=L\<rparr>\<turnstile>dom (locals (store s))\<guillemotright>t\<guillemotright>A )
schirmer@13688
   381
              \<and> s\<Colon>\<preceq>(G,L)"
schirmer@12854
   382
schirmer@12854
   383
datatype    'a triple = triple "('a assn)" "term" "('a assn)" (** should be
schirmer@12854
   384
something like triple = \<forall>'a. triple ('a assn) term ('a assn)   **)
schirmer@12854
   385
                                        ("{(1_)}/ _>/ {(1_)}"      [3,65,3]75)
schirmer@12854
   386
types    'a triples = "'a triple set"
schirmer@12854
   387
wenzelm@35067
   388
abbreviation
schirmer@12854
   389
  var_triple   :: "['a assn, var         ,'a assn] \<Rightarrow> 'a triple"
schirmer@12854
   390
                                         ("{(1_)}/ _=>/ {(1_)}"    [3,80,3] 75)
wenzelm@35067
   391
  where "{P} e=> {Q} == {P} In2  e> {Q}"
wenzelm@35067
   392
wenzelm@35067
   393
abbreviation
schirmer@12854
   394
  expr_triple  :: "['a assn, expr        ,'a assn] \<Rightarrow> 'a triple"
schirmer@12854
   395
                                         ("{(1_)}/ _->/ {(1_)}"    [3,80,3] 75)
wenzelm@35067
   396
  where "{P} e-> {Q} == {P} In1l e> {Q}"
wenzelm@35067
   397
wenzelm@35067
   398
abbreviation
schirmer@12854
   399
  exprs_triple :: "['a assn, expr list   ,'a assn] \<Rightarrow> 'a triple"
schirmer@12854
   400
                                         ("{(1_)}/ _#>/ {(1_)}"    [3,65,3] 75)
wenzelm@35067
   401
  where "{P} e#> {Q} == {P} In3  e> {Q}"
wenzelm@35067
   402
wenzelm@35067
   403
abbreviation
schirmer@12854
   404
  stmt_triple  :: "['a assn, stmt,        'a assn] \<Rightarrow> 'a triple"
schirmer@12854
   405
                                         ("{(1_)}/ ._./ {(1_)}"     [3,65,3] 75)
wenzelm@35067
   406
  where "{P} .c. {Q} == {P} In1r c> {Q}"
schirmer@12854
   407
wenzelm@35067
   408
notation (xsymbols)
wenzelm@35067
   409
  triple  ("{(1_)}/ _\<succ>/ {(1_)}"     [3,65,3] 75) and
wenzelm@35067
   410
  var_triple  ("{(1_)}/ _=\<succ>/ {(1_)}"    [3,80,3] 75) and
wenzelm@35067
   411
  expr_triple  ("{(1_)}/ _-\<succ>/ {(1_)}"    [3,80,3] 75) and
wenzelm@35067
   412
  exprs_triple  ("{(1_)}/ _\<doteq>\<succ>/ {(1_)}"    [3,65,3] 75)
schirmer@12854
   413
schirmer@12854
   414
lemma inj_triple: "inj (\<lambda>(P,t,Q). {P} t\<succ> {Q})"
paulson@13585
   415
apply (rule inj_onI)
schirmer@12854
   416
apply auto
schirmer@12854
   417
done
schirmer@12854
   418
schirmer@12854
   419
lemma triple_inj_eq: "({P} t\<succ> {Q} = {P'} t'\<succ> {Q'} ) = (P=P' \<and> t=t' \<and> Q=Q')"
schirmer@12854
   420
apply auto
schirmer@12854
   421
done
schirmer@12854
   422
schirmer@12854
   423
constdefs
schirmer@12854
   424
  mtriples  :: "('c \<Rightarrow> 'sig \<Rightarrow> 'a assn) \<Rightarrow> ('c \<Rightarrow> 'sig \<Rightarrow> expr) \<Rightarrow> 
schirmer@12854
   425
                ('c \<Rightarrow> 'sig \<Rightarrow> 'a assn) \<Rightarrow> ('c \<times>  'sig) set \<Rightarrow> 'a triples"
schirmer@12854
   426
                                     ("{{(1_)}/ _-\<succ>/ {(1_)} | _}"[3,65,3,65]75)
schirmer@12854
   427
 "{{P} tf-\<succ> {Q} | ms} \<equiv> (\<lambda>(C,sig). {Normal(P C sig)} tf C sig-\<succ> {Q C sig})`ms"
schirmer@12854
   428
  
schirmer@12854
   429
consts
schirmer@12854
   430
schirmer@12854
   431
 triple_valid :: "prog \<Rightarrow> nat \<Rightarrow>        'a triple  \<Rightarrow> bool"
schirmer@12854
   432
                                                (   "_\<Turnstile>_:_" [61,0, 58] 57)
schirmer@12854
   433
    ax_valids :: "prog \<Rightarrow> 'b triples \<Rightarrow> 'a triples \<Rightarrow> bool"
schirmer@12854
   434
                                                ("_,_|\<Turnstile>_"   [61,58,58] 57)
schirmer@12854
   435
wenzelm@35067
   436
abbreviation
schirmer@12854
   437
 triples_valid:: "prog \<Rightarrow> nat \<Rightarrow>         'a triples \<Rightarrow> bool"
schirmer@12854
   438
                                                (  "_||=_:_" [61,0, 58] 57)
wenzelm@35067
   439
 where "G||=n:ts == Ball ts (triple_valid G n)"
schirmer@12854
   440
wenzelm@35067
   441
abbreviation
wenzelm@35067
   442
 ax_valid :: "prog \<Rightarrow>  'b triples \<Rightarrow> 'a triple  \<Rightarrow> bool"
wenzelm@35067
   443
                                                ( "_,_|=_"   [61,58,58] 57)
wenzelm@35067
   444
 where "G,A |=t == G,A|\<Turnstile>{t}"
wenzelm@35067
   445
wenzelm@35067
   446
notation (xsymbols)
wenzelm@35067
   447
  triples_valid  ("_|\<Turnstile>_:_" [61,0, 58] 57) and
wenzelm@35067
   448
  ax_valid  ("_,_\<Turnstile>_" [61,58,58] 57)
schirmer@12854
   449
schirmer@12854
   450
defs  triple_valid_def:  "G\<Turnstile>n:t  \<equiv> case t of {P} t\<succ> {Q} \<Rightarrow>
schirmer@12854
   451
                          \<forall>Y s Z. P Y s Z \<longrightarrow> type_ok G t s \<longrightarrow>
schirmer@12854
   452
                          (\<forall>Y' s'. G\<turnstile>s \<midarrow>t\<succ>\<midarrow>n\<rightarrow> (Y',s') \<longrightarrow> Q Y' s' Z)"
wenzelm@35067
   453
wenzelm@35067
   454
defs  ax_valids_def:"G,A|\<Turnstile>ts  \<equiv>  \<forall>n. G|\<Turnstile>n:A \<longrightarrow> G|\<Turnstile>n:ts"
schirmer@12854
   455
schirmer@12854
   456
lemma triple_valid_def2: "G\<Turnstile>n:{P} t\<succ> {Q} =  
schirmer@12854
   457
 (\<forall>Y s Z. P Y s Z 
schirmer@13688
   458
  \<longrightarrow> (\<exists>L. (normal s \<longrightarrow> (\<exists> C T A. \<lparr>prg=G,cls=C,lcl=L\<rparr>\<turnstile>t\<Colon>T \<and> 
schirmer@13688
   459
                   \<lparr>prg=G,cls=C,lcl=L\<rparr>\<turnstile>dom (locals (store s))\<guillemotright>t\<guillemotright>A)) \<and> 
schirmer@13688
   460
           s\<Colon>\<preceq>(G,L))
schirmer@13688
   461
  \<longrightarrow> (\<forall>Y' s'. G\<turnstile>s \<midarrow>t\<succ>\<midarrow>n\<rightarrow> (Y',s')\<longrightarrow> Q Y' s' Z))"
schirmer@12854
   462
apply (unfold triple_valid_def type_ok_def)
schirmer@12854
   463
apply (simp (no_asm))
schirmer@12854
   464
done
schirmer@12854
   465
schirmer@12854
   466
schirmer@12854
   467
declare split_paired_All [simp del] split_paired_Ex [simp del] 
schirmer@12854
   468
declare split_if     [split del] split_if_asm     [split del] 
schirmer@12854
   469
        option.split [split del] option.split_asm [split del]
wenzelm@24019
   470
declaration {* K (Simplifier.map_ss (fn ss => ss delloop "split_all_tac")) *}
wenzelm@24019
   471
declaration {* K (Classical.map_cs (fn cs => cs delSWrapper "split_all_tac")) *}
schirmer@12854
   472
berghofe@23747
   473
inductive
berghofe@21765
   474
  ax_derivs :: "prog \<Rightarrow> 'a triples \<Rightarrow> 'a triples \<Rightarrow> bool" ("_,_|\<turnstile>_" [61,58,58] 57)
berghofe@21765
   475
  and ax_deriv :: "prog \<Rightarrow> 'a triples \<Rightarrow> 'a triple  \<Rightarrow> bool" ("_,_\<turnstile>_" [61,58,58] 57)
berghofe@21765
   476
  for G :: prog
berghofe@21765
   477
where
schirmer@12854
   478
berghofe@21765
   479
  "G,A \<turnstile>t \<equiv> G,A|\<turnstile>{t}"
berghofe@21765
   480
berghofe@21765
   481
| empty: " G,A|\<turnstile>{}"
berghofe@21765
   482
| insert:"\<lbrakk>G,A\<turnstile>t; G,A|\<turnstile>ts\<rbrakk> \<Longrightarrow>
schirmer@12854
   483
          G,A|\<turnstile>insert t ts"
schirmer@12854
   484
berghofe@21765
   485
| asm:   "ts\<subseteq>A \<Longrightarrow> G,A|\<turnstile>ts"
schirmer@12854
   486
schirmer@12854
   487
(* could be added for convenience and efficiency, but is not necessary
schirmer@12854
   488
  cut:   "\<lbrakk>G,A'|\<turnstile>ts; G,A|\<turnstile>A'\<rbrakk> \<Longrightarrow>
schirmer@12854
   489
           G,A |\<turnstile>ts"
schirmer@12854
   490
*)
berghofe@21765
   491
| weaken:"\<lbrakk>G,A|\<turnstile>ts'; ts \<subseteq> ts'\<rbrakk> \<Longrightarrow> G,A|\<turnstile>ts"
schirmer@12854
   492
berghofe@21765
   493
| conseq:"\<forall>Y s Z . P  Y s Z  \<longrightarrow> (\<exists>P' Q'. G,A\<turnstile>{P'} t\<succ> {Q'} \<and> (\<forall>Y' s'. 
schirmer@12854
   494
         (\<forall>Y   Z'. P' Y s Z' \<longrightarrow> Q' Y' s' Z') \<longrightarrow>
schirmer@12854
   495
                                 Q  Y' s' Z ))
schirmer@12854
   496
                                         \<Longrightarrow> G,A\<turnstile>{P } t\<succ> {Q }"
schirmer@12854
   497
berghofe@21765
   498
| hazard:"G,A\<turnstile>{P \<and>. Not \<circ> type_ok G t} t\<succ> {Q}"
schirmer@12854
   499
haftmann@28524
   500
| Abrupt:  "G,A\<turnstile>{P\<leftarrow>(undefined3 t) \<and>. Not \<circ> normal} t\<succ> {P}"
schirmer@12854
   501
schirmer@13688
   502
  --{* variables *}
berghofe@21765
   503
| LVar:  " G,A\<turnstile>{Normal (\<lambda>s.. P\<leftarrow>Var (lvar vn s))} LVar vn=\<succ> {P}"
schirmer@12854
   504
berghofe@21765
   505
| FVar: "\<lbrakk>G,A\<turnstile>{Normal P} .Init C. {Q};
schirmer@12854
   506
          G,A\<turnstile>{Q} e-\<succ> {\<lambda>Val:a:. fvar C stat fn a ..; R}\<rbrakk> \<Longrightarrow>
schirmer@12925
   507
                                 G,A\<turnstile>{Normal P} {accC,C,stat}e..fn=\<succ> {R}"
schirmer@12854
   508
berghofe@21765
   509
| AVar:  "\<lbrakk>G,A\<turnstile>{Normal P} e1-\<succ> {Q};
schirmer@12854
   510
          \<forall>a. G,A\<turnstile>{Q\<leftarrow>Val a} e2-\<succ> {\<lambda>Val:i:. avar G i a ..; R}\<rbrakk> \<Longrightarrow>
schirmer@12854
   511
                                 G,A\<turnstile>{Normal P} e1.[e2]=\<succ> {R}"
schirmer@13688
   512
  --{* expressions *}
schirmer@12854
   513
berghofe@21765
   514
| NewC: "\<lbrakk>G,A\<turnstile>{Normal P} .Init C. {Alloc G (CInst C) Q}\<rbrakk> \<Longrightarrow>
schirmer@12854
   515
                                 G,A\<turnstile>{Normal P} NewC C-\<succ> {Q}"
schirmer@12854
   516
berghofe@21765
   517
| NewA: "\<lbrakk>G,A\<turnstile>{Normal P} .init_comp_ty T. {Q};  G,A\<turnstile>{Q} e-\<succ>
wenzelm@32960
   518
          {\<lambda>Val:i:. abupd (check_neg i) .; Alloc G (Arr T (the_Intg i)) R}\<rbrakk> \<Longrightarrow>
schirmer@12854
   519
                                 G,A\<turnstile>{Normal P} New T[e]-\<succ> {R}"
schirmer@12854
   520
berghofe@21765
   521
| Cast: "\<lbrakk>G,A\<turnstile>{Normal P} e-\<succ> {\<lambda>Val:v:. \<lambda>s..
schirmer@12854
   522
          abupd (raise_if (\<not>G,s\<turnstile>v fits T) ClassCast) .; Q\<leftarrow>Val v}\<rbrakk> \<Longrightarrow>
schirmer@12854
   523
                                 G,A\<turnstile>{Normal P} Cast T e-\<succ> {Q}"
schirmer@12854
   524
berghofe@21765
   525
| Inst: "\<lbrakk>G,A\<turnstile>{Normal P} e-\<succ> {\<lambda>Val:v:. \<lambda>s..
schirmer@12854
   526
                  Q\<leftarrow>Val (Bool (v\<noteq>Null \<and> G,s\<turnstile>v fits RefT T))}\<rbrakk> \<Longrightarrow>
schirmer@12854
   527
                                 G,A\<turnstile>{Normal P} e InstOf T-\<succ> {Q}"
schirmer@12854
   528
berghofe@21765
   529
| Lit:                          "G,A\<turnstile>{Normal (P\<leftarrow>Val v)} Lit v-\<succ> {P}"
schirmer@12854
   530
berghofe@21765
   531
| UnOp: "\<lbrakk>G,A\<turnstile>{Normal P} e-\<succ> {\<lambda>Val:v:. Q\<leftarrow>Val (eval_unop unop v)}\<rbrakk>
schirmer@13337
   532
          \<Longrightarrow>
schirmer@13337
   533
          G,A\<turnstile>{Normal P} UnOp unop e-\<succ> {Q}"
schirmer@13337
   534
berghofe@21765
   535
| BinOp:
schirmer@13337
   536
   "\<lbrakk>G,A\<turnstile>{Normal P} e1-\<succ> {Q};
schirmer@13384
   537
     \<forall>v1. G,A\<turnstile>{Q\<leftarrow>Val v1} 
schirmer@13384
   538
               (if need_second_arg binop v1 then (In1l e2) else (In1r Skip))\<succ>
schirmer@13384
   539
               {\<lambda>Val:v2:. R\<leftarrow>Val (eval_binop binop v1 v2)}\<rbrakk>
schirmer@13337
   540
    \<Longrightarrow>
schirmer@13337
   541
    G,A\<turnstile>{Normal P} BinOp binop e1 e2-\<succ> {R}" 
schirmer@13337
   542
berghofe@21765
   543
| Super:" G,A\<turnstile>{Normal (\<lambda>s.. P\<leftarrow>Val (val_this s))} Super-\<succ> {P}"
schirmer@12854
   544
berghofe@21765
   545
| Acc:  "\<lbrakk>G,A\<turnstile>{Normal P} va=\<succ> {\<lambda>Var:(v,f):. Q\<leftarrow>Val v}\<rbrakk> \<Longrightarrow>
schirmer@12854
   546
                                 G,A\<turnstile>{Normal P} Acc va-\<succ> {Q}"
schirmer@12854
   547
berghofe@21765
   548
| Ass:  "\<lbrakk>G,A\<turnstile>{Normal P} va=\<succ> {Q};
schirmer@12854
   549
     \<forall>vf. G,A\<turnstile>{Q\<leftarrow>Var vf} e-\<succ> {\<lambda>Val:v:. assign (snd vf) v .; R}\<rbrakk> \<Longrightarrow>
schirmer@12854
   550
                                 G,A\<turnstile>{Normal P} va:=e-\<succ> {R}"
schirmer@12854
   551
berghofe@21765
   552
| Cond: "\<lbrakk>G,A \<turnstile>{Normal P} e0-\<succ> {P'};
schirmer@12854
   553
          \<forall>b. G,A\<turnstile>{P'\<leftarrow>=b} (if b then e1 else e2)-\<succ> {Q}\<rbrakk> \<Longrightarrow>
schirmer@12854
   554
                                 G,A\<turnstile>{Normal P} e0 ? e1 : e2-\<succ> {Q}"
schirmer@12854
   555
berghofe@21765
   556
| Call: 
schirmer@12854
   557
"\<lbrakk>G,A\<turnstile>{Normal P} e-\<succ> {Q}; \<forall>a. G,A\<turnstile>{Q\<leftarrow>Val a} args\<doteq>\<succ> {R a};
schirmer@12854
   558
  \<forall>a vs invC declC l. G,A\<turnstile>{(R a\<leftarrow>Vals vs \<and>.
schirmer@12854
   559
 (\<lambda>s. declC=invocation_declclass G mode (store s) a statT \<lparr>name=mn,parTs=pTs\<rparr> \<and>
schirmer@12854
   560
      invC = invocation_class mode (store s) a statT \<and>
schirmer@12854
   561
         l = locals (store s)) ;.
schirmer@12854
   562
      init_lvars G declC \<lparr>name=mn,parTs=pTs\<rparr> mode a vs) \<and>.
schirmer@12854
   563
      (\<lambda>s. normal s \<longrightarrow> G\<turnstile>mode\<rightarrow>invC\<preceq>statT)}
schirmer@12854
   564
 Methd declC \<lparr>name=mn,parTs=pTs\<rparr>-\<succ> {set_lvars l .; S}\<rbrakk> \<Longrightarrow>
schirmer@12925
   565
         G,A\<turnstile>{Normal P} {accC,statT,mode}e\<cdot>mn({pTs}args)-\<succ> {S}"
schirmer@12854
   566
berghofe@21765
   567
| Methd:"\<lbrakk>G,A\<union> {{P} Methd-\<succ> {Q} | ms} |\<turnstile> {{P} body G-\<succ> {Q} | ms}\<rbrakk> \<Longrightarrow>
schirmer@12854
   568
                                 G,A|\<turnstile>{{P} Methd-\<succ>  {Q} | ms}"
schirmer@12854
   569
berghofe@21765
   570
| Body: "\<lbrakk>G,A\<turnstile>{Normal P} .Init D. {Q}; 
schirmer@12854
   571
  G,A\<turnstile>{Q} .c. {\<lambda>s.. abupd (absorb Ret) .; R\<leftarrow>(In1 (the (locals s Result)))}\<rbrakk> 
schirmer@12854
   572
    \<Longrightarrow>
schirmer@12854
   573
                                 G,A\<turnstile>{Normal P} Body D c-\<succ> {R}"
schirmer@12854
   574
  
schirmer@13688
   575
  --{* expression lists *}
schirmer@12854
   576
berghofe@21765
   577
| Nil:                          "G,A\<turnstile>{Normal (P\<leftarrow>Vals [])} []\<doteq>\<succ> {P}"
schirmer@12854
   578
berghofe@21765
   579
| Cons: "\<lbrakk>G,A\<turnstile>{Normal P} e-\<succ> {Q};
schirmer@12854
   580
          \<forall>v. G,A\<turnstile>{Q\<leftarrow>Val v} es\<doteq>\<succ> {\<lambda>Vals:vs:. R\<leftarrow>Vals (v#vs)}\<rbrakk> \<Longrightarrow>
schirmer@12854
   581
                                 G,A\<turnstile>{Normal P} e#es\<doteq>\<succ> {R}"
schirmer@12854
   582
schirmer@13688
   583
  --{* statements *}
schirmer@12854
   584
berghofe@21765
   585
| Skip:                         "G,A\<turnstile>{Normal (P\<leftarrow>\<diamondsuit>)} .Skip. {P}"
schirmer@12854
   586
berghofe@21765
   587
| Expr: "\<lbrakk>G,A\<turnstile>{Normal P} e-\<succ> {Q\<leftarrow>\<diamondsuit>}\<rbrakk> \<Longrightarrow>
schirmer@12854
   588
                                 G,A\<turnstile>{Normal P} .Expr e. {Q}"
schirmer@12854
   589
berghofe@21765
   590
| Lab: "\<lbrakk>G,A\<turnstile>{Normal P} .c. {abupd (absorb l) .; Q}\<rbrakk> \<Longrightarrow>
schirmer@12854
   591
                           G,A\<turnstile>{Normal P} .l\<bullet> c. {Q}"
schirmer@12854
   592
berghofe@21765
   593
| Comp: "\<lbrakk>G,A\<turnstile>{Normal P} .c1. {Q};
schirmer@12854
   594
          G,A\<turnstile>{Q} .c2. {R}\<rbrakk> \<Longrightarrow>
schirmer@12854
   595
                                 G,A\<turnstile>{Normal P} .c1;;c2. {R}"
schirmer@12854
   596
berghofe@21765
   597
| If:   "\<lbrakk>G,A \<turnstile>{Normal P} e-\<succ> {P'};
schirmer@12854
   598
          \<forall>b. G,A\<turnstile>{P'\<leftarrow>=b} .(if b then c1 else c2). {Q}\<rbrakk> \<Longrightarrow>
schirmer@12854
   599
                                 G,A\<turnstile>{Normal P} .If(e) c1 Else c2. {Q}"
schirmer@12854
   600
(* unfolding variant of Loop, not needed here
schirmer@12854
   601
  LoopU:"\<lbrakk>G,A \<turnstile>{Normal P} e-\<succ> {P'};
schirmer@12854
   602
          \<forall>b. G,A\<turnstile>{P'\<leftarrow>=b} .(if b then c;;While(e) c else Skip).{Q}\<rbrakk>
schirmer@12854
   603
         \<Longrightarrow>              G,A\<turnstile>{Normal P} .While(e) c. {Q}"
schirmer@12854
   604
*)
berghofe@21765
   605
| Loop: "\<lbrakk>G,A\<turnstile>{P} e-\<succ> {P'}; 
schirmer@12854
   606
          G,A\<turnstile>{Normal (P'\<leftarrow>=True)} .c. {abupd (absorb (Cont l)) .; P}\<rbrakk> \<Longrightarrow>
schirmer@12854
   607
                            G,A\<turnstile>{P} .l\<bullet> While(e) c. {(P'\<leftarrow>=False)\<down>=\<diamondsuit>}"
schirmer@12854
   608
  
berghofe@21765
   609
| Jmp: "G,A\<turnstile>{Normal (abupd (\<lambda>a. (Some (Jump j))) .; P\<leftarrow>\<diamondsuit>)} .Jmp j. {P}"
schirmer@12854
   610
berghofe@21765
   611
| Throw:"\<lbrakk>G,A\<turnstile>{Normal P} e-\<succ> {\<lambda>Val:a:. abupd (throw a) .; Q\<leftarrow>\<diamondsuit>}\<rbrakk> \<Longrightarrow>
schirmer@12854
   612
                                 G,A\<turnstile>{Normal P} .Throw e. {Q}"
schirmer@12854
   613
berghofe@21765
   614
| Try:  "\<lbrakk>G,A\<turnstile>{Normal P} .c1. {SXAlloc G Q};
schirmer@12854
   615
          G,A\<turnstile>{Q \<and>. (\<lambda>s.  G,s\<turnstile>catch C) ;. new_xcpt_var vn} .c2. {R};
schirmer@12854
   616
              (Q \<and>. (\<lambda>s. \<not>G,s\<turnstile>catch C)) \<Rightarrow> R\<rbrakk> \<Longrightarrow>
schirmer@12854
   617
                                 G,A\<turnstile>{Normal P} .Try c1 Catch(C vn) c2. {R}"
schirmer@12854
   618
berghofe@21765
   619
| Fin:  "\<lbrakk>G,A\<turnstile>{Normal P} .c1. {Q};
schirmer@12854
   620
      \<forall>x. G,A\<turnstile>{Q \<and>. (\<lambda>s. x = fst s) ;. abupd (\<lambda>x. None)}
schirmer@12854
   621
              .c2. {abupd (abrupt_if (x\<noteq>None) x) .; R}\<rbrakk> \<Longrightarrow>
schirmer@12854
   622
                                 G,A\<turnstile>{Normal P} .c1 Finally c2. {R}"
schirmer@12854
   623
berghofe@21765
   624
| Done:                       "G,A\<turnstile>{Normal (P\<leftarrow>\<diamondsuit> \<and>. initd C)} .Init C. {P}"
schirmer@12854
   625
berghofe@21765
   626
| Init: "\<lbrakk>the (class G C) = c;
schirmer@12854
   627
          G,A\<turnstile>{Normal ((P \<and>. Not \<circ> initd C) ;. supd (init_class_obj G C))}
schirmer@12854
   628
              .(if C = Object then Skip else Init (super c)). {Q};
schirmer@12854
   629
      \<forall>l. G,A\<turnstile>{Q \<and>. (\<lambda>s. l = locals (store s)) ;. set_lvars empty}
schirmer@12854
   630
              .init c. {set_lvars l .; R}\<rbrakk> \<Longrightarrow>
schirmer@12854
   631
                               G,A\<turnstile>{Normal (P \<and>. Not \<circ> initd C)} .Init C. {R}"
schirmer@12854
   632
schirmer@13337
   633
-- {* Some dummy rules for the intermediate terms @{text Callee},
schirmer@13337
   634
@{text InsInitE}, @{text InsInitV}, @{text FinA} only used by the smallstep 
schirmer@13337
   635
semantics.
schirmer@13337
   636
*}
berghofe@21765
   637
| InsInitV: " G,A\<turnstile>{Normal P} InsInitV c v=\<succ> {Q}"
berghofe@21765
   638
| InsInitE: " G,A\<turnstile>{Normal P} InsInitE c e-\<succ> {Q}"
berghofe@21765
   639
| Callee:    " G,A\<turnstile>{Normal P} Callee l e-\<succ> {Q}"
berghofe@21765
   640
| FinA:      " G,A\<turnstile>{Normal P} .FinA a c. {Q}"
schirmer@13688
   641
(*
schirmer@13688
   642
axioms 
schirmer@13688
   643
*)
schirmer@12854
   644
schirmer@12854
   645
constdefs
schirmer@12854
   646
 adapt_pre :: "'a assn \<Rightarrow> 'a assn \<Rightarrow> 'a assn \<Rightarrow> 'a assn"
schirmer@12854
   647
"adapt_pre P Q Q'\<equiv>\<lambda>Y s Z. \<forall>Y' s'. \<exists>Z'. P Y s Z' \<and> (Q Y' s' Z' \<longrightarrow> Q' Y' s' Z)"
schirmer@12854
   648
schirmer@12854
   649
schirmer@12854
   650
section "rules derived by induction"
schirmer@12854
   651
schirmer@12854
   652
lemma cut_valid: "\<lbrakk>G,A'|\<Turnstile>ts; G,A|\<Turnstile>A'\<rbrakk> \<Longrightarrow> G,A|\<Turnstile>ts"
schirmer@12854
   653
apply (unfold ax_valids_def)
schirmer@12854
   654
apply fast
schirmer@12854
   655
done
schirmer@12854
   656
schirmer@12854
   657
(*if cut is available
schirmer@12854
   658
Goal "\<lbrakk>G,A'|\<turnstile>ts; A' \<subseteq> A; \<forall>P Q t. {P} t\<succ> {Q} \<in> A' \<longrightarrow> (\<exists>T. (G,L)\<turnstile>t\<Colon>T) \<rbrakk> \<Longrightarrow>  
schirmer@12854
   659
       G,A|\<turnstile>ts"
schirmer@12854
   660
b y etac ax_derivs.cut 1;
schirmer@12854
   661
b y eatac ax_derivs.asm 1 1;
schirmer@12854
   662
qed "ax_thin";
schirmer@12854
   663
*)
schirmer@12854
   664
lemma ax_thin [rule_format (no_asm)]: 
schirmer@12854
   665
  "G,(A'::'a triple set)|\<turnstile>(ts::'a triple set) \<Longrightarrow> \<forall>A. A' \<subseteq> A \<longrightarrow> G,A|\<turnstile>ts"
schirmer@12854
   666
apply (erule ax_derivs.induct)
wenzelm@23894
   667
apply                (tactic "ALLGOALS(EVERY'[clarify_tac @{claset}, REPEAT o smp_tac 1])")
schirmer@12854
   668
apply                (rule ax_derivs.empty)
schirmer@12854
   669
apply               (erule (1) ax_derivs.insert)
schirmer@12854
   670
apply              (fast intro: ax_derivs.asm)
schirmer@12854
   671
(*apply           (fast intro: ax_derivs.cut) *)
schirmer@12854
   672
apply            (fast intro: ax_derivs.weaken)
schirmer@13337
   673
apply           (rule ax_derivs.conseq, intro strip, tactic "smp_tac 3 1",clarify, tactic "smp_tac 1 1",rule exI, rule exI, erule (1) conjI) 
schirmer@13337
   674
(* 37 subgoals *)
schirmer@13337
   675
prefer 18 (* Methd *)
paulson@23563
   676
apply (rule ax_derivs.Methd, drule spec, erule mp, fast) 
paulson@23563
   677
apply (tactic {* TRYALL (resolve_tac ((funpow 5 tl) (thms "ax_derivs.intros"))) *})
paulson@23563
   678
apply auto
schirmer@12854
   679
done
schirmer@12854
   680
schirmer@12854
   681
lemma ax_thin_insert: "G,(A::'a triple set)\<turnstile>(t::'a triple) \<Longrightarrow> G,insert x A\<turnstile>t"
schirmer@12854
   682
apply (erule ax_thin)
schirmer@12854
   683
apply fast
schirmer@12854
   684
done
schirmer@12854
   685
schirmer@12854
   686
lemma subset_mtriples_iff: 
schirmer@12854
   687
  "ts \<subseteq> {{P} mb-\<succ> {Q} | ms} = (\<exists>ms'. ms'\<subseteq>ms \<and>  ts = {{P} mb-\<succ> {Q} | ms'})"
schirmer@12854
   688
apply (unfold mtriples_def)
schirmer@12854
   689
apply (rule subset_image_iff)
schirmer@12854
   690
done
schirmer@12854
   691
schirmer@12854
   692
lemma weaken: 
schirmer@12854
   693
 "G,(A::'a triple set)|\<turnstile>(ts'::'a triple set) \<Longrightarrow> !ts. ts \<subseteq> ts' \<longrightarrow> G,A|\<turnstile>ts"
schirmer@12854
   694
apply (erule ax_derivs.induct)
schirmer@13337
   695
(*42 subgoals*)
schirmer@12854
   696
apply       (tactic "ALLGOALS strip_tac")
schirmer@12854
   697
apply       (tactic {* ALLGOALS(REPEAT o (EVERY'[dtac (thm "subset_singletonD"),
wenzelm@26342
   698
         etac disjE, fast_tac (@{claset} addSIs [thm "ax_derivs.empty"])]))*})
schirmer@12854
   699
apply       (tactic "TRYALL hyp_subst_tac")
schirmer@12854
   700
apply       (simp, rule ax_derivs.empty)
schirmer@12854
   701
apply      (drule subset_insertD)
schirmer@12854
   702
apply      (blast intro: ax_derivs.insert)
schirmer@12854
   703
apply     (fast intro: ax_derivs.asm)
schirmer@12854
   704
(*apply  (blast intro: ax_derivs.cut) *)
schirmer@12854
   705
apply   (fast intro: ax_derivs.weaken)
schirmer@12854
   706
apply  (rule ax_derivs.conseq, clarify, tactic "smp_tac 3 1", blast(* unused *))
schirmer@13337
   707
(*37 subgoals*)
schirmer@12854
   708
apply (tactic {* TRYALL (resolve_tac ((funpow 5 tl) (thms "ax_derivs.intros")) 
wenzelm@23894
   709
                   THEN_ALL_NEW fast_tac @{claset}) *})
schirmer@12854
   710
(*1 subgoal*)
schirmer@12854
   711
apply (clarsimp simp add: subset_mtriples_iff)
schirmer@12854
   712
apply (rule ax_derivs.Methd)
schirmer@12854
   713
apply (drule spec)
schirmer@12854
   714
apply (erule impE)
schirmer@12854
   715
apply  (rule exI)
schirmer@12854
   716
apply  (erule conjI)
schirmer@12854
   717
apply  (rule HOL.refl)
schirmer@12854
   718
oops (* dead end, Methd is to blame *)
schirmer@12854
   719
schirmer@12854
   720
schirmer@12854
   721
section "rules derived from conseq"
schirmer@12854
   722
schirmer@13688
   723
text {* In the following rules we often have to give some type annotations like:
schirmer@13688
   724
 @{term "G,(A::'a triple set)\<turnstile>{P::'a assn} t\<succ> {Q}"}.
schirmer@13688
   725
Given only the term above without annotations, Isabelle would infer a more 
schirmer@13688
   726
general type were we could have 
schirmer@13688
   727
different types of auxiliary variables in the assumption set (@{term A}) and 
schirmer@13688
   728
in the triple itself (@{term P} and @{term Q}). But 
schirmer@13688
   729
@{text "ax_derivs.Methd"} enforces the same type in the inductive definition of
schirmer@13688
   730
the derivation. So we have to restrict the types to be able to apply the
schirmer@13688
   731
rules. 
schirmer@13688
   732
*}
schirmer@13688
   733
lemma conseq12: "\<lbrakk>G,(A::'a triple set)\<turnstile>{P'::'a assn} t\<succ> {Q'};  
schirmer@12854
   734
 \<forall>Y s Z. P Y s Z \<longrightarrow> (\<forall>Y' s'. (\<forall>Y Z'. P' Y s Z' \<longrightarrow> Q' Y' s' Z') \<longrightarrow>  
schirmer@12854
   735
  Q Y' s' Z)\<rbrakk>  
schirmer@12854
   736
  \<Longrightarrow>  G,A\<turnstile>{P ::'a assn} t\<succ> {Q }"
schirmer@13688
   737
apply (rule ax_derivs.conseq)
schirmer@12854
   738
apply clarsimp
schirmer@12854
   739
apply blast
schirmer@12854
   740
done
schirmer@12854
   741
schirmer@13688
   742
-- {* Nice variant, since it is so symmetric we might be able to memorise it. *}
schirmer@13688
   743
lemma conseq12': "\<lbrakk>G,(A::'a triple set)\<turnstile>{P'::'a assn} t\<succ> {Q'}; \<forall>s Y' s'.  
schirmer@12854
   744
       (\<forall>Y Z. P' Y s Z \<longrightarrow> Q' Y' s' Z) \<longrightarrow>  
schirmer@12854
   745
       (\<forall>Y Z. P  Y s Z \<longrightarrow> Q  Y' s' Z)\<rbrakk>  
schirmer@13688
   746
  \<Longrightarrow>  G,A\<turnstile>{P::'a assn } t\<succ> {Q }"
schirmer@12854
   747
apply (erule conseq12)
schirmer@12854
   748
apply fast
schirmer@12854
   749
done
schirmer@12854
   750
schirmer@13688
   751
lemma conseq12_from_conseq12': "\<lbrakk>G,(A::'a triple set)\<turnstile>{P'::'a assn} t\<succ> {Q'};  
schirmer@12854
   752
 \<forall>Y s Z. P Y s Z \<longrightarrow> (\<forall>Y' s'. (\<forall>Y Z'. P' Y s Z' \<longrightarrow> Q' Y' s' Z') \<longrightarrow>  
schirmer@12854
   753
  Q Y' s' Z)\<rbrakk>  
schirmer@13688
   754
  \<Longrightarrow>  G,A\<turnstile>{P::'a assn} t\<succ> {Q }"
schirmer@12854
   755
apply (erule conseq12')
schirmer@12854
   756
apply blast
schirmer@12854
   757
done
schirmer@12854
   758
schirmer@13688
   759
lemma conseq1: "\<lbrakk>G,(A::'a triple set)\<turnstile>{P'::'a assn} t\<succ> {Q}; P \<Rightarrow> P'\<rbrakk> 
schirmer@13688
   760
 \<Longrightarrow> G,A\<turnstile>{P::'a assn} t\<succ> {Q}"
schirmer@12854
   761
apply (erule conseq12)
schirmer@12854
   762
apply blast
schirmer@12854
   763
done
schirmer@12854
   764
schirmer@13688
   765
lemma conseq2: "\<lbrakk>G,(A::'a triple set)\<turnstile>{P::'a assn} t\<succ> {Q'}; Q' \<Rightarrow> Q\<rbrakk> 
schirmer@13688
   766
\<Longrightarrow> G,A\<turnstile>{P::'a assn} t\<succ> {Q}"
schirmer@12854
   767
apply (erule conseq12)
schirmer@12854
   768
apply blast
schirmer@12854
   769
done
schirmer@12854
   770
schirmer@13688
   771
lemma ax_escape: 
schirmer@13688
   772
 "\<lbrakk>\<forall>Y s Z. P Y s Z 
schirmer@13688
   773
   \<longrightarrow> G,(A::'a triple set)\<turnstile>{\<lambda>Y' s' (Z'::'a). (Y',s') = (Y,s)} 
schirmer@13688
   774
                             t\<succ> 
schirmer@13688
   775
                            {\<lambda>Y s Z'. Q Y s Z}
schirmer@13688
   776
\<rbrakk> \<Longrightarrow>  G,A\<turnstile>{P::'a assn} t\<succ> {Q::'a assn}"
schirmer@13688
   777
apply (rule ax_derivs.conseq)
schirmer@12854
   778
apply force
schirmer@12854
   779
done
schirmer@12854
   780
schirmer@12854
   781
(* unused *)
schirmer@13688
   782
lemma ax_constant: "\<lbrakk> C \<Longrightarrow> G,(A::'a triple set)\<turnstile>{P::'a assn} t\<succ> {Q}\<rbrakk> 
schirmer@13688
   783
\<Longrightarrow> G,A\<turnstile>{\<lambda>Y s Z. C \<and> P Y s Z} t\<succ> {Q}"
schirmer@12854
   784
apply (rule ax_escape (* unused *))
schirmer@12854
   785
apply clarify
schirmer@12854
   786
apply (rule conseq12)
schirmer@12854
   787
apply  fast
schirmer@12854
   788
apply auto
schirmer@12854
   789
done
schirmer@12854
   790
(*alternative (more direct) proof:
schirmer@12854
   791
apply (rule ax_derivs.conseq) *)(* unused *)(*
schirmer@12854
   792
apply (fast)
schirmer@12854
   793
*)
schirmer@12854
   794
schirmer@12854
   795
schirmer@13688
   796
lemma ax_impossible [intro]: 
schirmer@13688
   797
  "G,(A::'a triple set)\<turnstile>{\<lambda>Y s Z. False} t\<succ> {Q::'a assn}"
schirmer@12854
   798
apply (rule ax_escape)
schirmer@12854
   799
apply clarify
schirmer@12854
   800
done
schirmer@12854
   801
schirmer@12854
   802
(* unused *)
schirmer@12854
   803
lemma ax_nochange_lemma: "\<lbrakk>P Y s; All (op = w)\<rbrakk> \<Longrightarrow> P w s"
schirmer@12854
   804
apply auto
schirmer@12854
   805
done
schirmer@13688
   806
schirmer@13688
   807
lemma ax_nochange:
schirmer@13688
   808
 "G,(A::(res \<times> state) triple set)\<turnstile>{\<lambda>Y s Z. (Y,s)=Z} t\<succ> {\<lambda>Y s Z. (Y,s)=Z} 
schirmer@13688
   809
  \<Longrightarrow> G,A\<turnstile>{P::(res \<times> state) assn} t\<succ> {P}"
schirmer@12854
   810
apply (erule conseq12)
schirmer@12854
   811
apply auto
schirmer@12854
   812
apply (erule (1) ax_nochange_lemma)
schirmer@12854
   813
done
schirmer@12854
   814
schirmer@12854
   815
(* unused *)
schirmer@13688
   816
lemma ax_trivial: "G,(A::'a triple set)\<turnstile>{P::'a assn}  t\<succ> {\<lambda>Y s Z. True}"
schirmer@13688
   817
apply (rule ax_derivs.conseq(* unused *))
schirmer@12854
   818
apply auto
schirmer@12854
   819
done
schirmer@12854
   820
schirmer@12854
   821
(* unused *)
schirmer@13688
   822
lemma ax_disj: 
schirmer@13688
   823
 "\<lbrakk>G,(A::'a triple set)\<turnstile>{P1::'a assn} t\<succ> {Q1}; G,A\<turnstile>{P2::'a assn} t\<succ> {Q2}\<rbrakk> 
schirmer@13688
   824
  \<Longrightarrow>  G,A\<turnstile>{\<lambda>Y s Z. P1 Y s Z \<or> P2 Y s Z} t\<succ> {\<lambda>Y s Z. Q1 Y s Z \<or> Q2 Y s Z}"
schirmer@12854
   825
apply (rule ax_escape (* unused *))
schirmer@12854
   826
apply safe
schirmer@12854
   827
apply  (erule conseq12, fast)+
schirmer@12854
   828
done
schirmer@12854
   829
schirmer@12854
   830
(* unused *)
schirmer@13688
   831
lemma ax_supd_shuffle: 
schirmer@13688
   832
 "(\<exists>Q. G,(A::'a triple set)\<turnstile>{P::'a assn} .c1. {Q} \<and> G,A\<turnstile>{Q ;. f} .c2. {R}) =  
schirmer@12854
   833
       (\<exists>Q'. G,A\<turnstile>{P} .c1. {f .; Q'} \<and> G,A\<turnstile>{Q'} .c2. {R})"
schirmer@12854
   834
apply (best elim!: conseq1 conseq2)
schirmer@12854
   835
done
schirmer@12854
   836
schirmer@13688
   837
lemma ax_cases: "
schirmer@13688
   838
 \<lbrakk>G,(A::'a triple set)\<turnstile>{P \<and>.       C} t\<succ> {Q::'a assn};  
schirmer@13688
   839
                   G,A\<turnstile>{P \<and>. Not \<circ> C} t\<succ> {Q}\<rbrakk> \<Longrightarrow> G,A\<turnstile>{P} t\<succ> {Q}"
schirmer@12854
   840
apply (unfold peek_and_def)
schirmer@12854
   841
apply (rule ax_escape)
schirmer@12854
   842
apply clarify
schirmer@12854
   843
apply (case_tac "C s")
schirmer@12854
   844
apply  (erule conseq12, force)+
schirmer@12854
   845
done
schirmer@12854
   846
(*alternative (more direct) proof:
schirmer@12854
   847
apply (rule rtac ax_derivs.conseq) *)(* unused *)(*
schirmer@12854
   848
apply clarify
schirmer@12854
   849
apply (case_tac "C s")
schirmer@12854
   850
apply  force+
schirmer@12854
   851
*)
schirmer@12854
   852
schirmer@13688
   853
lemma ax_adapt: "G,(A::'a triple set)\<turnstile>{P::'a assn} t\<succ> {Q} 
schirmer@13688
   854
  \<Longrightarrow> G,A\<turnstile>{adapt_pre P Q Q'} t\<succ> {Q'}"
schirmer@12854
   855
apply (unfold adapt_pre_def)
schirmer@12854
   856
apply (erule conseq12)
schirmer@12854
   857
apply fast
schirmer@12854
   858
done
schirmer@12854
   859
schirmer@13688
   860
lemma adapt_pre_adapts: "G,(A::'a triple set)\<Turnstile>{P::'a assn} t\<succ> {Q} 
schirmer@13688
   861
\<longrightarrow> G,A\<Turnstile>{adapt_pre P Q Q'} t\<succ> {Q'}"
schirmer@12854
   862
apply (unfold adapt_pre_def)
schirmer@12854
   863
apply (simp add: ax_valids_def triple_valid_def2)
schirmer@12854
   864
apply fast
schirmer@12854
   865
done
schirmer@12854
   866
schirmer@12854
   867
schirmer@12854
   868
lemma adapt_pre_weakest: 
schirmer@12854
   869
"\<forall>G (A::'a triple set) t. G,A\<Turnstile>{P} t\<succ> {Q} \<longrightarrow> G,A\<Turnstile>{P'} t\<succ> {Q'} \<Longrightarrow>  
schirmer@12854
   870
  P' \<Rightarrow> adapt_pre P Q (Q'::'a assn)"
schirmer@12854
   871
apply (unfold adapt_pre_def)
schirmer@12854
   872
apply (drule spec)
schirmer@12854
   873
apply (drule_tac x = "{}" in spec)
schirmer@12854
   874
apply (drule_tac x = "In1r Skip" in spec)
schirmer@12854
   875
apply (simp add: ax_valids_def triple_valid_def2)
schirmer@12854
   876
oops
schirmer@12854
   877
schirmer@12854
   878
lemma peek_and_forget1_Normal: 
schirmer@13688
   879
 "G,(A::'a triple set)\<turnstile>{Normal P} t\<succ> {Q::'a assn} 
schirmer@13688
   880
 \<Longrightarrow> G,A\<turnstile>{Normal (P \<and>. p)} t\<succ> {Q}"
schirmer@12854
   881
apply (erule conseq1)
schirmer@12854
   882
apply (simp (no_asm))
schirmer@12854
   883
done
schirmer@12854
   884
schirmer@13688
   885
lemma peek_and_forget1: 
schirmer@13688
   886
"G,(A::'a triple set)\<turnstile>{P::'a assn} t\<succ> {Q} 
schirmer@13688
   887
 \<Longrightarrow> G,A\<turnstile>{P \<and>. p} t\<succ> {Q}"
schirmer@12854
   888
apply (erule conseq1)
schirmer@12854
   889
apply (simp (no_asm))
schirmer@12854
   890
done
schirmer@12854
   891
schirmer@12854
   892
lemmas ax_NormalD = peek_and_forget1 [of _ _ _ _ _ normal] 
schirmer@12854
   893
schirmer@13688
   894
lemma peek_and_forget2: 
schirmer@13688
   895
"G,(A::'a triple set)\<turnstile>{P::'a assn} t\<succ> {Q \<and>. p} 
schirmer@13688
   896
\<Longrightarrow> G,A\<turnstile>{P} t\<succ> {Q}"
schirmer@12854
   897
apply (erule conseq2)
schirmer@12854
   898
apply (simp (no_asm))
schirmer@12854
   899
done
schirmer@12854
   900
schirmer@13688
   901
lemma ax_subst_Val_allI: 
schirmer@13688
   902
"\<forall>v. G,(A::'a triple set)\<turnstile>{(P'               v )\<leftarrow>Val v} t\<succ> {(Q v)::'a assn}
schirmer@13688
   903
 \<Longrightarrow>  \<forall>v. G,A\<turnstile>{(\<lambda>w:. P' (the_In1 w))\<leftarrow>Val v} t\<succ> {Q v}"
schirmer@12854
   904
apply (force elim!: conseq1)
schirmer@12854
   905
done
schirmer@12854
   906
schirmer@13688
   907
lemma ax_subst_Var_allI: 
schirmer@13688
   908
"\<forall>v. G,(A::'a triple set)\<turnstile>{(P'               v )\<leftarrow>Var v} t\<succ> {(Q v)::'a assn}
schirmer@13688
   909
 \<Longrightarrow>  \<forall>v. G,A\<turnstile>{(\<lambda>w:. P' (the_In2 w))\<leftarrow>Var v} t\<succ> {Q v}"
schirmer@12854
   910
apply (force elim!: conseq1)
schirmer@12854
   911
done
schirmer@12854
   912
schirmer@13688
   913
lemma ax_subst_Vals_allI: 
schirmer@13688
   914
"(\<forall>v. G,(A::'a triple set)\<turnstile>{(     P'          v )\<leftarrow>Vals v} t\<succ> {(Q v)::'a assn})
schirmer@13688
   915
 \<Longrightarrow>  \<forall>v. G,A\<turnstile>{(\<lambda>w:. P' (the_In3 w))\<leftarrow>Vals v} t\<succ> {Q v}"
schirmer@12854
   916
apply (force elim!: conseq1)
schirmer@12854
   917
done
schirmer@12854
   918
schirmer@12854
   919
schirmer@12854
   920
section "alternative axioms"
schirmer@12854
   921
schirmer@12854
   922
lemma ax_Lit2: 
schirmer@12854
   923
  "G,(A::'a triple set)\<turnstile>{Normal P::'a assn} Lit v-\<succ> {Normal (P\<down>=Val v)}"
schirmer@12854
   924
apply (rule ax_derivs.Lit [THEN conseq1])
schirmer@12854
   925
apply force
schirmer@12854
   926
done
schirmer@12854
   927
lemma ax_Lit2_test_complete: 
schirmer@12854
   928
  "G,(A::'a triple set)\<turnstile>{Normal (P\<leftarrow>Val v)::'a assn} Lit v-\<succ> {P}"
schirmer@12854
   929
apply (rule ax_Lit2 [THEN conseq2])
schirmer@12854
   930
apply force
schirmer@12854
   931
done
schirmer@12854
   932
schirmer@12854
   933
lemma ax_LVar2: "G,(A::'a triple set)\<turnstile>{Normal P::'a assn} LVar vn=\<succ> {Normal (\<lambda>s.. P\<down>=Var (lvar vn s))}"
schirmer@12854
   934
apply (rule ax_derivs.LVar [THEN conseq1])
schirmer@12854
   935
apply force
schirmer@12854
   936
done
schirmer@12854
   937
schirmer@12854
   938
lemma ax_Super2: "G,(A::'a triple set)\<turnstile>
schirmer@12854
   939
  {Normal P::'a assn} Super-\<succ> {Normal (\<lambda>s.. P\<down>=Val (val_this s))}"
schirmer@12854
   940
apply (rule ax_derivs.Super [THEN conseq1])
schirmer@12854
   941
apply force
schirmer@12854
   942
done
schirmer@12854
   943
schirmer@12854
   944
lemma ax_Nil2: 
schirmer@12854
   945
  "G,(A::'a triple set)\<turnstile>{Normal P::'a assn} []\<doteq>\<succ> {Normal (P\<down>=Vals [])}"
schirmer@12854
   946
apply (rule ax_derivs.Nil [THEN conseq1])
schirmer@12854
   947
apply force
schirmer@12854
   948
done
schirmer@12854
   949
schirmer@12854
   950
schirmer@12854
   951
section "misc derived structural rules"
schirmer@12854
   952
schirmer@12854
   953
(* unused *)
schirmer@12854
   954
lemma ax_finite_mtriples_lemma: "\<lbrakk>F \<subseteq> ms; finite ms; \<forall>(C,sig)\<in>ms. 
schirmer@12854
   955
    G,(A::'a triple set)\<turnstile>{Normal (P C sig)::'a assn} mb C sig-\<succ> {Q C sig}\<rbrakk> \<Longrightarrow> 
schirmer@12854
   956
       G,A|\<turnstile>{{P} mb-\<succ> {Q} | F}"
schirmer@12854
   957
apply (frule (1) finite_subset)
wenzelm@24038
   958
apply (erule rev_mp)
schirmer@12854
   959
apply (erule thin_rl)
schirmer@12854
   960
apply (erule finite_induct)
schirmer@12854
   961
apply  (unfold mtriples_def)
schirmer@12854
   962
apply  (clarsimp intro!: ax_derivs.empty ax_derivs.insert)+
schirmer@12854
   963
apply force
schirmer@12854
   964
done
schirmer@12854
   965
lemmas ax_finite_mtriples = ax_finite_mtriples_lemma [OF subset_refl]
schirmer@12854
   966
schirmer@12854
   967
lemma ax_derivs_insertD: 
schirmer@12854
   968
 "G,(A::'a triple set)|\<turnstile>insert (t::'a triple) ts \<Longrightarrow> G,A\<turnstile>t \<and> G,A|\<turnstile>ts"
schirmer@12854
   969
apply (fast intro: ax_derivs.weaken)
schirmer@12854
   970
done
schirmer@12854
   971
schirmer@12854
   972
lemma ax_methods_spec: 
schirmer@12854
   973
"\<lbrakk>G,(A::'a triple set)|\<turnstile>split f ` ms; (C,sig) \<in> ms\<rbrakk>\<Longrightarrow> G,A\<turnstile>((f C sig)::'a triple)"
schirmer@12854
   974
apply (erule ax_derivs.weaken)
schirmer@12854
   975
apply (force del: image_eqI intro: rev_image_eqI)
schirmer@12854
   976
done
schirmer@12854
   977
schirmer@12854
   978
(* this version is used to avoid using the cut rule *)
schirmer@12854
   979
lemma ax_finite_pointwise_lemma [rule_format]: "\<lbrakk>F \<subseteq> ms; finite ms\<rbrakk> \<Longrightarrow>  
schirmer@12854
   980
  ((\<forall>(C,sig)\<in>F. G,(A::'a triple set)\<turnstile>(f C sig::'a triple)) \<longrightarrow> (\<forall>(C,sig)\<in>ms. G,A\<turnstile>(g C sig::'a triple))) \<longrightarrow>  
schirmer@12854
   981
      G,A|\<turnstile>split f ` F \<longrightarrow> G,A|\<turnstile>split g ` F"
schirmer@12854
   982
apply (frule (1) finite_subset)
wenzelm@24038
   983
apply (erule rev_mp)
schirmer@12854
   984
apply (erule thin_rl)
schirmer@12854
   985
apply (erule finite_induct)
schirmer@12854
   986
apply  clarsimp+
schirmer@12854
   987
apply (drule ax_derivs_insertD)
schirmer@12854
   988
apply (rule ax_derivs.insert)
schirmer@12854
   989
apply  (simp (no_asm_simp) only: split_tupled_all)
schirmer@12854
   990
apply  (auto elim: ax_methods_spec)
schirmer@12854
   991
done
schirmer@12854
   992
lemmas ax_finite_pointwise = ax_finite_pointwise_lemma [OF subset_refl]
schirmer@12854
   993
 
schirmer@12854
   994
lemma ax_no_hazard: 
schirmer@12854
   995
  "G,(A::'a triple set)\<turnstile>{P \<and>. type_ok G t} t\<succ> {Q::'a assn} \<Longrightarrow> G,A\<turnstile>{P} t\<succ> {Q}"
schirmer@12854
   996
apply (erule ax_cases)
schirmer@12854
   997
apply (rule ax_derivs.hazard [THEN conseq1])
schirmer@12854
   998
apply force
schirmer@12854
   999
done
schirmer@12854
  1000
schirmer@12854
  1001
lemma ax_free_wt: 
schirmer@12854
  1002
 "(\<exists>T L C. \<lparr>prg=G,cls=C,lcl=L\<rparr>\<turnstile>t\<Colon>T) 
schirmer@12854
  1003
  \<longrightarrow> G,(A::'a triple set)\<turnstile>{Normal P} t\<succ> {Q::'a assn} \<Longrightarrow> 
schirmer@12854
  1004
  G,A\<turnstile>{Normal P} t\<succ> {Q}"
schirmer@12854
  1005
apply (rule ax_no_hazard)
schirmer@12854
  1006
apply (rule ax_escape)
schirmer@12854
  1007
apply clarify
schirmer@12854
  1008
apply (erule mp [THEN conseq12])
schirmer@12854
  1009
apply  (auto simp add: type_ok_def)
schirmer@12854
  1010
done
schirmer@12854
  1011
wenzelm@27226
  1012
ML {* bind_thms ("ax_Abrupts", sum3_instantiate @{context} @{thm ax_derivs.Abrupt}) *}
schirmer@12854
  1013
declare ax_Abrupts [intro!]
schirmer@12854
  1014
berghofe@21765
  1015
lemmas ax_Normal_cases = ax_cases [of _ _ _ normal]
schirmer@12854
  1016
schirmer@12854
  1017
lemma ax_Skip [intro!]: "G,(A::'a triple set)\<turnstile>{P\<leftarrow>\<diamondsuit>} .Skip. {P::'a assn}"
schirmer@12854
  1018
apply (rule ax_Normal_cases)
schirmer@12854
  1019
apply  (rule ax_derivs.Skip)
schirmer@12854
  1020
apply fast
schirmer@12854
  1021
done
schirmer@12854
  1022
lemmas ax_SkipI = ax_Skip [THEN conseq1, standard]
schirmer@12854
  1023
schirmer@12854
  1024
schirmer@12854
  1025
section "derived rules for methd call"
schirmer@12854
  1026
schirmer@12854
  1027
lemma ax_Call_known_DynT: 
schirmer@12854
  1028
"\<lbrakk>G\<turnstile>IntVir\<rightarrow>C\<preceq>statT; 
schirmer@12854
  1029
  \<forall>a vs l. G,A\<turnstile>{(R a\<leftarrow>Vals vs \<and>. (\<lambda>s. l = locals (store s)) ;.
schirmer@12854
  1030
  init_lvars G C \<lparr>name=mn,parTs=pTs\<rparr> IntVir a vs)} 
schirmer@12854
  1031
    Methd C \<lparr>name=mn,parTs=pTs\<rparr>-\<succ> {set_lvars l .; S}; 
schirmer@12854
  1032
  \<forall>a. G,A\<turnstile>{Q\<leftarrow>Val a} args\<doteq>\<succ>  
schirmer@12854
  1033
       {R a \<and>. (\<lambda>s. C = obj_class (the (heap (store s) (the_Addr a))) \<and>
schirmer@12854
  1034
                     C = invocation_declclass 
schirmer@12854
  1035
                            G IntVir (store s) a statT \<lparr>name=mn,parTs=pTs\<rparr> )};  
schirmer@12854
  1036
       G,(A::'a triple set)\<turnstile>{Normal P} e-\<succ> {Q::'a assn}\<rbrakk>  
schirmer@12925
  1037
   \<Longrightarrow> G,A\<turnstile>{Normal P} {accC,statT,IntVir}e\<cdot>mn({pTs}args)-\<succ> {S}"
schirmer@12854
  1038
apply (erule ax_derivs.Call)
schirmer@12854
  1039
apply  safe
schirmer@12854
  1040
apply  (erule spec)
schirmer@12854
  1041
apply (rule ax_escape, clarsimp)
schirmer@12854
  1042
apply (drule spec, drule spec, drule spec,erule conseq12)
schirmer@12854
  1043
apply force
schirmer@12854
  1044
done
schirmer@12854
  1045
schirmer@12854
  1046
schirmer@12854
  1047
lemma ax_Call_Static: 
schirmer@12854
  1048
 "\<lbrakk>\<forall>a vs l. G,A\<turnstile>{R a\<leftarrow>Vals vs \<and>. (\<lambda>s. l = locals (store s)) ;.  
schirmer@12854
  1049
               init_lvars G C \<lparr>name=mn,parTs=pTs\<rparr> Static any_Addr vs}  
schirmer@12854
  1050
              Methd C \<lparr>name=mn,parTs=pTs\<rparr>-\<succ> {set_lvars l .; S}; 
schirmer@12854
  1051
  G,A\<turnstile>{Normal P} e-\<succ> {Q};
schirmer@12854
  1052
  \<forall> a. G,(A::'a triple set)\<turnstile>{Q\<leftarrow>Val a} args\<doteq>\<succ> {(R::val \<Rightarrow> 'a assn)  a 
schirmer@12854
  1053
  \<and>. (\<lambda> s. C=invocation_declclass 
schirmer@12854
  1054
                G Static (store s) a statT \<lparr>name=mn,parTs=pTs\<rparr>)}
schirmer@12925
  1055
\<rbrakk>  \<Longrightarrow>  G,A\<turnstile>{Normal P} {accC,statT,Static}e\<cdot>mn({pTs}args)-\<succ> {S}"
schirmer@12854
  1056
apply (erule ax_derivs.Call)
schirmer@12854
  1057
apply  safe
schirmer@12854
  1058
apply  (erule spec)
schirmer@12854
  1059
apply (rule ax_escape, clarsimp)
schirmer@12854
  1060
apply (erule_tac V = "?P \<longrightarrow> ?Q" in thin_rl)
schirmer@12854
  1061
apply (drule spec,drule spec,drule spec, erule conseq12)
schirmer@20014
  1062
apply (force simp add: init_lvars_def Let_def)
schirmer@12854
  1063
done
schirmer@12854
  1064
schirmer@12854
  1065
lemma ax_Methd1: 
schirmer@12854
  1066
 "\<lbrakk>G,A\<union>{{P} Methd-\<succ> {Q} | ms}|\<turnstile> {{P} body G-\<succ> {Q} | ms}; (C,sig)\<in> ms\<rbrakk> \<Longrightarrow> 
schirmer@12854
  1067
       G,A\<turnstile>{Normal (P C sig)} Methd C sig-\<succ> {Q C sig}"
schirmer@12854
  1068
apply (drule ax_derivs.Methd)
schirmer@12854
  1069
apply (unfold mtriples_def)
schirmer@12854
  1070
apply (erule (1) ax_methods_spec)
schirmer@12854
  1071
done
schirmer@12854
  1072
schirmer@12854
  1073
lemma ax_MethdN: 
schirmer@12854
  1074
"G,insert({Normal P} Methd  C sig-\<succ> {Q}) A\<turnstile> 
schirmer@12854
  1075
          {Normal P} body G C sig-\<succ> {Q} \<Longrightarrow>  
schirmer@12854
  1076
      G,A\<turnstile>{Normal P} Methd   C sig-\<succ> {Q}"
schirmer@12854
  1077
apply (rule ax_Methd1)
schirmer@12854
  1078
apply  (rule_tac [2] singletonI)
schirmer@12854
  1079
apply (unfold mtriples_def)
schirmer@12854
  1080
apply clarsimp
schirmer@12854
  1081
done
schirmer@12854
  1082
schirmer@12854
  1083
lemma ax_StatRef: 
schirmer@12854
  1084
  "G,(A::'a triple set)\<turnstile>{Normal (P\<leftarrow>Val Null)} StatRef rt-\<succ> {P::'a assn}"
schirmer@12854
  1085
apply (rule ax_derivs.Cast)
schirmer@12854
  1086
apply (rule ax_Lit2 [THEN conseq2])
schirmer@12854
  1087
apply clarsimp
schirmer@12854
  1088
done
schirmer@12854
  1089
schirmer@12854
  1090
section "rules derived from Init and Done"
schirmer@12854
  1091
schirmer@12854
  1092
  lemma ax_InitS: "\<lbrakk>the (class G C) = c; C \<noteq> Object;  
schirmer@12854
  1093
     \<forall>l. G,A\<turnstile>{Q \<and>. (\<lambda>s. l = locals (store s)) ;. set_lvars empty}  
schirmer@12854
  1094
            .init c. {set_lvars l .; R};   
schirmer@12854
  1095
         G,A\<turnstile>{Normal ((P \<and>. Not \<circ> initd C) ;. supd (init_class_obj G C))}  
schirmer@12854
  1096
  .Init (super c). {Q}\<rbrakk> \<Longrightarrow>  
schirmer@12854
  1097
  G,(A::'a triple set)\<turnstile>{Normal (P \<and>. Not \<circ> initd C)} .Init C. {R::'a assn}"
schirmer@12854
  1098
apply (erule ax_derivs.Init)
schirmer@12854
  1099
apply  (simp (no_asm_simp))
schirmer@12854
  1100
apply assumption
schirmer@12854
  1101
done
schirmer@12854
  1102
schirmer@12854
  1103
lemma ax_Init_Skip_lemma: 
schirmer@12854
  1104
"\<forall>l. G,(A::'a triple set)\<turnstile>{P\<leftarrow>\<diamondsuit> \<and>. (\<lambda>s. l = locals (store s)) ;. set_lvars l'}
schirmer@12854
  1105
  .Skip. {(set_lvars l .; P)::'a assn}"
schirmer@12854
  1106
apply (rule allI)
schirmer@12854
  1107
apply (rule ax_SkipI)
schirmer@12854
  1108
apply clarsimp
schirmer@12854
  1109
done
schirmer@12854
  1110
schirmer@12854
  1111
lemma ax_triv_InitS: "\<lbrakk>the (class G C) = c;init c = Skip; C \<noteq> Object; 
schirmer@12854
  1112
       P\<leftarrow>\<diamondsuit> \<Rightarrow> (supd (init_class_obj G C) .; P);  
schirmer@12854
  1113
       G,A\<turnstile>{Normal (P \<and>. initd C)} .Init (super c). {(P \<and>. initd C)\<leftarrow>\<diamondsuit>}\<rbrakk> \<Longrightarrow>  
schirmer@12854
  1114
       G,(A::'a triple set)\<turnstile>{Normal P\<leftarrow>\<diamondsuit>} .Init C. {(P \<and>. initd C)::'a assn}"
schirmer@12854
  1115
apply (rule_tac C = "initd C" in ax_cases)
schirmer@12854
  1116
apply  (rule conseq1, rule ax_derivs.Done, clarsimp)
schirmer@12854
  1117
apply (simp (no_asm))
schirmer@12854
  1118
apply (erule (1) ax_InitS)
schirmer@12854
  1119
apply  simp
schirmer@12854
  1120
apply  (rule ax_Init_Skip_lemma)
schirmer@12854
  1121
apply (erule conseq1)
schirmer@12854
  1122
apply force
schirmer@12854
  1123
done
schirmer@12854
  1124
schirmer@12854
  1125
lemma ax_Init_Object: "wf_prog G \<Longrightarrow> G,(A::'a triple set)\<turnstile>
schirmer@12854
  1126
  {Normal ((supd (init_class_obj G Object) .; P\<leftarrow>\<diamondsuit>) \<and>. Not \<circ> initd Object)} 
schirmer@12854
  1127
       .Init Object. {(P \<and>. initd Object)::'a assn}"
schirmer@12854
  1128
apply (rule ax_derivs.Init)
schirmer@12854
  1129
apply   (drule class_Object, force)
schirmer@12854
  1130
apply (simp_all (no_asm))
schirmer@12854
  1131
apply (rule_tac [2] ax_Init_Skip_lemma)
schirmer@12854
  1132
apply (rule ax_SkipI, force)
schirmer@12854
  1133
done
schirmer@12854
  1134
schirmer@12854
  1135
lemma ax_triv_Init_Object: "\<lbrakk>wf_prog G;  
schirmer@12854
  1136
       (P::'a assn) \<Rightarrow> (supd (init_class_obj G Object) .; P)\<rbrakk> \<Longrightarrow>  
schirmer@12854
  1137
  G,(A::'a triple set)\<turnstile>{Normal P\<leftarrow>\<diamondsuit>} .Init Object. {P \<and>. initd Object}"
schirmer@12854
  1138
apply (rule_tac C = "initd Object" in ax_cases)
schirmer@12854
  1139
apply  (rule conseq1, rule ax_derivs.Done, clarsimp)
schirmer@12854
  1140
apply (erule ax_Init_Object [THEN conseq1])
schirmer@12854
  1141
apply force
schirmer@12854
  1142
done
schirmer@12854
  1143
schirmer@12854
  1144
schirmer@12854
  1145
section "introduction rules for Alloc and SXAlloc"
schirmer@12854
  1146
schirmer@13688
  1147
lemma ax_SXAlloc_Normal: 
schirmer@13688
  1148
 "G,(A::'a triple set)\<turnstile>{P::'a assn} .c. {Normal Q} 
schirmer@13688
  1149
 \<Longrightarrow> G,A\<turnstile>{P} .c. {SXAlloc G Q}"
schirmer@12854
  1150
apply (erule conseq2)
schirmer@12854
  1151
apply (clarsimp elim!: sxalloc_elim_cases simp add: split_tupled_all)
schirmer@12854
  1152
done
schirmer@12854
  1153
schirmer@12854
  1154
lemma ax_Alloc: 
schirmer@13688
  1155
  "G,(A::'a triple set)\<turnstile>{P::'a assn} t\<succ> 
schirmer@13688
  1156
     {Normal (\<lambda>Y (x,s) Z. (\<forall>a. new_Addr (heap s) = Some a \<longrightarrow>  
schirmer@13688
  1157
      Q (Val (Addr a)) (Norm(init_obj G (CInst C) (Heap a) s)) Z)) \<and>. 
schirmer@13688
  1158
      heap_free (Suc (Suc 0))}
schirmer@12854
  1159
   \<Longrightarrow> G,A\<turnstile>{P} t\<succ> {Alloc G (CInst C) Q}"
schirmer@12854
  1160
apply (erule conseq2)
schirmer@12854
  1161
apply (auto elim!: halloc_elim_cases)
schirmer@12854
  1162
done
schirmer@12854
  1163
schirmer@12854
  1164
lemma ax_Alloc_Arr: 
schirmer@13688
  1165
 "G,(A::'a triple set)\<turnstile>{P::'a assn} t\<succ> 
schirmer@13688
  1166
   {\<lambda>Val:i:. Normal (\<lambda>Y (x,s) Z. \<not>the_Intg i<0 \<and>  
schirmer@13688
  1167
    (\<forall>a. new_Addr (heap s) = Some a \<longrightarrow>  
schirmer@13688
  1168
    Q (Val (Addr a)) (Norm (init_obj G (Arr T (the_Intg i)) (Heap a) s)) Z)) \<and>.
schirmer@13688
  1169
    heap_free (Suc (Suc 0))} 
schirmer@13688
  1170
 \<Longrightarrow>  
schirmer@12854
  1171
 G,A\<turnstile>{P} t\<succ> {\<lambda>Val:i:. abupd (check_neg i) .; Alloc G (Arr T(the_Intg i)) Q}"
schirmer@12854
  1172
apply (erule conseq2)
schirmer@12854
  1173
apply (auto elim!: halloc_elim_cases)
schirmer@12854
  1174
done
schirmer@12854
  1175
schirmer@12854
  1176
lemma ax_SXAlloc_catch_SXcpt: 
schirmer@13688
  1177
 "\<lbrakk>G,(A::'a triple set)\<turnstile>{P::'a assn} t\<succ> 
schirmer@13688
  1178
     {(\<lambda>Y (x,s) Z. x=Some (Xcpt (Std xn)) \<and>  
schirmer@13688
  1179
      (\<forall>a. new_Addr (heap s) = Some a \<longrightarrow>  
schirmer@13688
  1180
      Q Y (Some (Xcpt (Loc a)),init_obj G (CInst (SXcpt xn)) (Heap a) s) Z))  
schirmer@13688
  1181
      \<and>. heap_free (Suc (Suc 0))}\<rbrakk> 
schirmer@13688
  1182
 \<Longrightarrow>  
schirmer@13688
  1183
 G,A\<turnstile>{P} t\<succ> {SXAlloc G (\<lambda>Y s Z. Q Y s Z \<and> G,s\<turnstile>catch SXcpt xn)}"
schirmer@12854
  1184
apply (erule conseq2)
schirmer@12854
  1185
apply (auto elim!: sxalloc_elim_cases halloc_elim_cases)
schirmer@12854
  1186
done
schirmer@12854
  1187
schirmer@12854
  1188
end