src/HOL/Bali/AxSound.thy
author wenzelm
Wed Jun 13 00:01:41 2007 +0200 (2007-06-13)
changeset 23350 50c5b0912a0c
parent 21765 89275a3ed7be
child 23366 a1e61b5c000f
permissions -rw-r--r--
tuned proofs: avoid implicit prems;
wenzelm@12857
     1
(*  Title:      HOL/Bali/AxSound.thy
schirmer@12854
     2
    ID:         $Id$
schirmer@13688
     3
    Author:     David von Oheimb and Norbert Schirmer
schirmer@12854
     4
*)
schirmer@12854
     5
header {* Soundness proof for Axiomatic semantics of Java expressions and 
schirmer@12854
     6
          statements
schirmer@12854
     7
       *}
schirmer@12854
     8
haftmann@16417
     9
theory AxSound imports AxSem begin
schirmer@12854
    10
schirmer@12854
    11
section "validity"
schirmer@12854
    12
schirmer@12854
    13
consts
schirmer@12854
    14
schirmer@12854
    15
 triple_valid2:: "prog \<Rightarrow> nat \<Rightarrow>        'a triple  \<Rightarrow> bool"
schirmer@12854
    16
                                                (   "_\<Turnstile>_\<Colon>_"[61,0, 58] 57)
schirmer@12854
    17
    ax_valids2:: "prog \<Rightarrow> 'a triples \<Rightarrow> 'a triples \<Rightarrow> bool"
schirmer@12854
    18
                                                ("_,_|\<Turnstile>\<Colon>_" [61,58,58] 57)
schirmer@12854
    19
schirmer@12854
    20
defs  triple_valid2_def: "G\<Turnstile>n\<Colon>t \<equiv> case t of {P} t\<succ> {Q} \<Rightarrow>
schirmer@12854
    21
 \<forall>Y s Z. P Y s Z \<longrightarrow> (\<forall>L. s\<Colon>\<preceq>(G,L) 
schirmer@13688
    22
 \<longrightarrow> (\<forall>T C A. (normal s \<longrightarrow> (\<lparr>prg=G,cls=C,lcl=L\<rparr>\<turnstile>t\<Colon>T \<and> 
schirmer@13688
    23
                            \<lparr>prg=G,cls=C,lcl=L\<rparr>\<turnstile>dom (locals (store s))\<guillemotright>t\<guillemotright>A)) \<longrightarrow>
schirmer@12854
    24
 (\<forall>Y' s'. G\<turnstile>s \<midarrow>t\<succ>\<midarrow>n\<rightarrow> (Y',s') \<longrightarrow> Q Y' s' Z \<and> s'\<Colon>\<preceq>(G,L))))"
schirmer@12854
    25
schirmer@13688
    26
text {* This definition differs from the ordinary  @{text triple_valid_def} 
schirmer@13688
    27
manly in the conclusion: We also ensures conformance of the result state. So
schirmer@13688
    28
we don't have to apply the type soundness lemma all the time during
schirmer@13688
    29
induction. This definition is only introduced for the soundness
schirmer@13688
    30
proof of the axiomatic semantics, in the end we will conclude to 
schirmer@13688
    31
the ordinary definition.
schirmer@13688
    32
*}
schirmer@13688
    33
 
schirmer@12854
    34
defs  ax_valids2_def:    "G,A|\<Turnstile>\<Colon>ts \<equiv>  \<forall>n. (\<forall>t\<in>A. G\<Turnstile>n\<Colon>t) \<longrightarrow> (\<forall>t\<in>ts. G\<Turnstile>n\<Colon>t)"
schirmer@12854
    35
schirmer@12854
    36
lemma triple_valid2_def2: "G\<Turnstile>n\<Colon>{P} t\<succ> {Q} =  
schirmer@12854
    37
 (\<forall>Y s Z. P Y s Z \<longrightarrow> (\<forall>Y' s'. G\<turnstile>s \<midarrow>t\<succ>\<midarrow>n\<rightarrow> (Y',s')\<longrightarrow>  
schirmer@13688
    38
  (\<forall>L. s\<Colon>\<preceq>(G,L) \<longrightarrow> (\<forall>T C A. (normal s \<longrightarrow> (\<lparr>prg=G,cls=C,lcl=L\<rparr>\<turnstile>t\<Colon>T \<and> 
schirmer@13688
    39
                            \<lparr>prg=G,cls=C,lcl=L\<rparr>\<turnstile>dom (locals (store s))\<guillemotright>t\<guillemotright>A)) \<longrightarrow>
schirmer@12854
    40
  Q Y' s' Z \<and> s'\<Colon>\<preceq>(G,L)))))"
schirmer@12854
    41
apply (unfold triple_valid2_def)
schirmer@12854
    42
apply (simp (no_asm) add: split_paired_All)
schirmer@12854
    43
apply blast
schirmer@12854
    44
done
schirmer@12854
    45
schirmer@12854
    46
lemma triple_valid2_eq [rule_format (no_asm)]: 
schirmer@12854
    47
  "wf_prog G ==> triple_valid2 G = triple_valid G"
schirmer@12854
    48
apply (rule ext)
schirmer@12854
    49
apply (rule ext)
schirmer@12854
    50
apply (rule triple.induct)
schirmer@12854
    51
apply (simp (no_asm) add: triple_valid_def2 triple_valid2_def2)
schirmer@12854
    52
apply (rule iffI)
schirmer@12854
    53
apply  fast
schirmer@12854
    54
apply clarify
schirmer@12854
    55
apply (tactic "smp_tac 3 1")
schirmer@12854
    56
apply (case_tac "normal s")
schirmer@12854
    57
apply  clarsimp
schirmer@13688
    58
apply  (elim conjE impE)
schirmer@13688
    59
apply    blast
schirmer@13688
    60
schirmer@13688
    61
apply    (tactic "smp_tac 2 1")
schirmer@13688
    62
apply    (drule evaln_eval)
schirmer@13688
    63
apply    (drule (1) eval_type_sound [THEN conjunct1],simp, assumption+)
schirmer@13688
    64
apply    simp
schirmer@13688
    65
schirmer@13688
    66
apply    clarsimp
schirmer@12854
    67
done
schirmer@12854
    68
schirmer@13688
    69
schirmer@12854
    70
lemma ax_valids2_eq: "wf_prog G \<Longrightarrow> G,A|\<Turnstile>\<Colon>ts = G,A|\<Turnstile>ts"
schirmer@12854
    71
apply (unfold ax_valids_def ax_valids2_def)
schirmer@12854
    72
apply (force simp add: triple_valid2_eq)
schirmer@12854
    73
done
schirmer@12854
    74
schirmer@12854
    75
lemma triple_valid2_Suc [rule_format (no_asm)]: "G\<Turnstile>Suc n\<Colon>t \<longrightarrow> G\<Turnstile>n\<Colon>t"
schirmer@12854
    76
apply (induct_tac "t")
schirmer@12854
    77
apply (subst triple_valid2_def2)
schirmer@12854
    78
apply (subst triple_valid2_def2)
schirmer@12854
    79
apply (fast intro: evaln_nonstrict_Suc)
schirmer@12854
    80
done
schirmer@12854
    81
schirmer@12854
    82
lemma Methd_triple_valid2_0: "G\<Turnstile>0\<Colon>{Normal P} Methd C sig-\<succ> {Q}"
schirmer@12854
    83
apply (clarsimp elim!: evaln_elim_cases simp add: triple_valid2_def2)
schirmer@12854
    84
done
schirmer@12854
    85
schirmer@12854
    86
lemma Methd_triple_valid2_SucI: 
schirmer@12854
    87
"\<lbrakk>G\<Turnstile>n\<Colon>{Normal P} body G C sig-\<succ>{Q}\<rbrakk> 
schirmer@12854
    88
  \<Longrightarrow> G\<Turnstile>Suc n\<Colon>{Normal P} Methd C sig-\<succ> {Q}"
schirmer@12854
    89
apply (simp (no_asm_use) add: triple_valid2_def2)
schirmer@12854
    90
apply (intro strip, tactic "smp_tac 3 1", clarify)
schirmer@13688
    91
apply (erule wt_elim_cases, erule da_elim_cases, erule evaln_elim_cases)
schirmer@12854
    92
apply (unfold body_def Let_def)
schirmer@13688
    93
apply (clarsimp simp add: inj_term_simps)
schirmer@12854
    94
apply blast
schirmer@12854
    95
done
schirmer@12854
    96
schirmer@12854
    97
lemma triples_valid2_Suc: 
schirmer@12854
    98
 "Ball ts (triple_valid2 G (Suc n)) \<Longrightarrow> Ball ts (triple_valid2 G n)"
schirmer@12854
    99
apply (fast intro: triple_valid2_Suc)
schirmer@12854
   100
done
schirmer@12854
   101
wenzelm@23350
   102
lemma "G|\<Turnstile>n:insert t A = (G\<Turnstile>n:t \<and> G|\<Turnstile>n:A)"
schirmer@12854
   103
oops
schirmer@12854
   104
schirmer@12854
   105
schirmer@12854
   106
section "soundness"
schirmer@12854
   107
schirmer@12854
   108
lemma Methd_sound: 
schirmer@13688
   109
  assumes recursive: "G,A\<union>  {{P} Methd-\<succ> {Q} | ms}|\<Turnstile>\<Colon>{{P} body G-\<succ> {Q} | ms}"
schirmer@13688
   110
  shows "G,A|\<Turnstile>\<Colon>{{P} Methd-\<succ> {Q} | ms}"
schirmer@13688
   111
proof -
schirmer@13688
   112
  {
schirmer@13688
   113
    fix n
schirmer@13688
   114
    assume recursive: "\<And> n. \<forall>t\<in>(A \<union> {{P} Methd-\<succ> {Q} | ms}). G\<Turnstile>n\<Colon>t
schirmer@13688
   115
                              \<Longrightarrow>  \<forall>t\<in>{{P} body G-\<succ> {Q} | ms}.  G\<Turnstile>n\<Colon>t"
schirmer@13688
   116
    have "\<forall>t\<in>A. G\<Turnstile>n\<Colon>t \<Longrightarrow> \<forall>t\<in>{{P} Methd-\<succ> {Q} | ms}.  G\<Turnstile>n\<Colon>t"
schirmer@13688
   117
    proof (induct n)
schirmer@13688
   118
      case 0
schirmer@13688
   119
      show "\<forall>t\<in>{{P} Methd-\<succ> {Q} | ms}.  G\<Turnstile>0\<Colon>t"
schirmer@13688
   120
      proof -
schirmer@13688
   121
	{
schirmer@13688
   122
	  fix C sig
schirmer@13688
   123
	  assume "(C,sig) \<in> ms" 
schirmer@13688
   124
	  have "G\<Turnstile>0\<Colon>{Normal (P C sig)} Methd C sig-\<succ> {Q C sig}"
schirmer@13688
   125
	    by (rule Methd_triple_valid2_0)
schirmer@13688
   126
	}
schirmer@13688
   127
	thus ?thesis
schirmer@13688
   128
	  by (simp add: mtriples_def split_def)
schirmer@13688
   129
      qed
schirmer@13688
   130
    next
schirmer@13688
   131
      case (Suc m)
wenzelm@23350
   132
      note hyp = `\<forall>t\<in>A. G\<Turnstile>m\<Colon>t \<Longrightarrow> \<forall>t\<in>{{P} Methd-\<succ> {Q} | ms}.  G\<Turnstile>m\<Colon>t`
wenzelm@23350
   133
      note prem = `\<forall>t\<in>A. G\<Turnstile>Suc m\<Colon>t`
schirmer@13688
   134
      show "\<forall>t\<in>{{P} Methd-\<succ> {Q} | ms}.  G\<Turnstile>Suc m\<Colon>t"
schirmer@13688
   135
      proof -
schirmer@13688
   136
	{
schirmer@13688
   137
	  fix C sig
schirmer@13688
   138
	  assume m: "(C,sig) \<in> ms" 
schirmer@13688
   139
	  have "G\<Turnstile>Suc m\<Colon>{Normal (P C sig)} Methd C sig-\<succ> {Q C sig}"
schirmer@13688
   140
	  proof -
schirmer@13688
   141
	    from prem have prem_m: "\<forall>t\<in>A. G\<Turnstile>m\<Colon>t"
schirmer@13688
   142
	      by (rule triples_valid2_Suc)
schirmer@13688
   143
	    hence "\<forall>t\<in>{{P} Methd-\<succ> {Q} | ms}.  G\<Turnstile>m\<Colon>t"
schirmer@13688
   144
	      by (rule hyp)
schirmer@13688
   145
	    with prem_m
schirmer@13688
   146
	    have "\<forall>t\<in>(A \<union> {{P} Methd-\<succ> {Q} | ms}). G\<Turnstile>m\<Colon>t"
schirmer@13688
   147
	      by (simp add: ball_Un)
schirmer@13688
   148
	    hence "\<forall>t\<in>{{P} body G-\<succ> {Q} | ms}.  G\<Turnstile>m\<Colon>t"
schirmer@13688
   149
	      by (rule recursive)
schirmer@13688
   150
	    with m have "G\<Turnstile>m\<Colon>{Normal (P C sig)} body G C sig-\<succ> {Q C sig}"
schirmer@13688
   151
	      by (auto simp add: mtriples_def split_def)
schirmer@13688
   152
	    thus ?thesis
schirmer@13688
   153
	      by (rule Methd_triple_valid2_SucI)
schirmer@13688
   154
	  qed
schirmer@13688
   155
	}
schirmer@13688
   156
	thus ?thesis
schirmer@13688
   157
	  by (simp add: mtriples_def split_def)
schirmer@13688
   158
      qed
schirmer@13688
   159
    qed
schirmer@13688
   160
  }
schirmer@13688
   161
  with recursive show ?thesis
schirmer@13688
   162
    by (unfold ax_valids2_def) blast
schirmer@13688
   163
qed
schirmer@12854
   164
schirmer@12854
   165
schirmer@12854
   166
lemma valids2_inductI: "\<forall>s t n Y' s'. G\<turnstile>s\<midarrow>t\<succ>\<midarrow>n\<rightarrow> (Y',s') \<longrightarrow> t = c \<longrightarrow>    
schirmer@12854
   167
  Ball A (triple_valid2 G n) \<longrightarrow> (\<forall>Y Z. P Y s Z \<longrightarrow>  
schirmer@13688
   168
  (\<forall>L. s\<Colon>\<preceq>(G,L) \<longrightarrow> 
schirmer@13688
   169
    (\<forall>T C A. (normal s \<longrightarrow> (\<lparr>prg=G,cls=C,lcl=L\<rparr>\<turnstile>t\<Colon>T) \<and> 
schirmer@13688
   170
                            \<lparr>prg=G,cls=C,lcl=L\<rparr>\<turnstile>dom (locals (store s))\<guillemotright>t\<guillemotright>A) \<longrightarrow>
schirmer@13688
   171
    Q Y' s' Z \<and> s'\<Colon>\<preceq>(G, L)))) \<Longrightarrow>  
schirmer@12854
   172
  G,A|\<Turnstile>\<Colon>{ {P} c\<succ> {Q}}"
schirmer@12854
   173
apply (simp (no_asm) add: ax_valids2_def triple_valid2_def2)
schirmer@12854
   174
apply clarsimp
schirmer@12854
   175
done
schirmer@12854
   176
schirmer@13688
   177
lemma da_good_approx_evalnE [consumes 4]:
schirmer@13688
   178
  assumes evaln: "G\<turnstile>s0 \<midarrow>t\<succ>\<midarrow>n\<rightarrow> (v, s1)"
schirmer@13688
   179
     and     wt: "\<lparr>prg=G,cls=C,lcl=L\<rparr>\<turnstile>t\<Colon>T"
schirmer@13688
   180
     and     da: "\<lparr>prg=G,cls=C,lcl=L\<rparr>\<turnstile> dom (locals (store s0)) \<guillemotright>t\<guillemotright> A"
schirmer@13688
   181
     and     wf: "wf_prog G"
schirmer@13688
   182
     and   elim: "\<lbrakk>normal s1 \<Longrightarrow> nrm A \<subseteq> dom (locals (store s1));
schirmer@13688
   183
                  \<And> l. \<lbrakk>abrupt s1 = Some (Jump (Break l)); normal s0\<rbrakk>
schirmer@13688
   184
                        \<Longrightarrow> brk A l \<subseteq> dom (locals (store s1));
schirmer@13688
   185
                   \<lbrakk>abrupt s1 = Some (Jump Ret);normal s0\<rbrakk>
schirmer@13688
   186
                   \<Longrightarrow>Result \<in> dom (locals (store s1))
schirmer@13688
   187
                  \<rbrakk> \<Longrightarrow> P"
schirmer@13688
   188
  shows "P"
schirmer@13688
   189
proof -
schirmer@13688
   190
  from evaln have "G\<turnstile>s0 \<midarrow>t\<succ>\<rightarrow> (v, s1)"
schirmer@13688
   191
    by (rule evaln_eval)
schirmer@13688
   192
  from this wt da wf elim show P
nipkow@17589
   193
    by (rule da_good_approxE') iprover+
schirmer@13688
   194
qed
schirmer@12854
   195
schirmer@13688
   196
lemma validI: 
schirmer@13688
   197
   assumes I: "\<And> n s0 L accC T C v s1 Y Z.
schirmer@13688
   198
               \<lbrakk>\<forall>t\<in>A. G\<Turnstile>n\<Colon>t; s0\<Colon>\<preceq>(G,L); 
schirmer@13688
   199
               normal s0 \<Longrightarrow> \<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>t\<Colon>T;
schirmer@13688
   200
               normal s0 \<Longrightarrow> \<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>dom (locals (store s0))\<guillemotright>t\<guillemotright>C;
schirmer@13688
   201
               G\<turnstile>s0 \<midarrow>t\<succ>\<midarrow>n\<rightarrow> (v,s1); P Y s0 Z\<rbrakk> \<Longrightarrow> Q v s1 Z \<and> s1\<Colon>\<preceq>(G,L)" 
schirmer@13688
   202
  shows "G,A|\<Turnstile>\<Colon>{ {P} t\<succ> {Q} }"
schirmer@13688
   203
apply (simp add: ax_valids2_def triple_valid2_def2)
schirmer@13688
   204
apply (intro allI impI)
schirmer@13688
   205
apply (case_tac "normal s")
schirmer@13688
   206
apply   clarsimp 
schirmer@13688
   207
apply   (rule I,(assumption|simp)+)
schirmer@13688
   208
schirmer@13688
   209
apply   (rule I,auto)
schirmer@13688
   210
done
schirmer@13688
   211
  
schirmer@13688
   212
schirmer@13688
   213
schirmer@13688
   214
schirmer@13688
   215
ML "Addsimprocs [wt_expr_proc,wt_var_proc,wt_exprs_proc,wt_stmt_proc]"
schirmer@13688
   216
schirmer@13688
   217
lemma valid_stmtI: 
schirmer@13688
   218
   assumes I: "\<And> n s0 L accC C s1 Y Z.
schirmer@13688
   219
             \<lbrakk>\<forall>t\<in>A. G\<Turnstile>n\<Colon>t; s0\<Colon>\<preceq>(G,L); 
schirmer@13688
   220
              normal s0\<Longrightarrow> \<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>c\<Colon>\<surd>;
schirmer@13688
   221
              normal s0\<Longrightarrow>\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>dom (locals (store s0))\<guillemotright>\<langle>c\<rangle>\<^sub>s\<guillemotright>C;
schirmer@13688
   222
              G\<turnstile>s0 \<midarrow>c\<midarrow>n\<rightarrow> s1; P Y s0 Z\<rbrakk> \<Longrightarrow> Q \<diamondsuit> s1 Z \<and> s1\<Colon>\<preceq>(G,L)" 
schirmer@13688
   223
  shows "G,A|\<Turnstile>\<Colon>{ {P} \<langle>c\<rangle>\<^sub>s\<succ> {Q} }"
schirmer@13688
   224
apply (simp add: ax_valids2_def triple_valid2_def2)
schirmer@13688
   225
apply (intro allI impI)
schirmer@13688
   226
apply (case_tac "normal s")
schirmer@13688
   227
apply   clarsimp 
schirmer@13688
   228
apply   (rule I,(assumption|simp)+)
schirmer@13688
   229
schirmer@13688
   230
apply   (rule I,auto)
schirmer@12854
   231
done
schirmer@12854
   232
schirmer@13688
   233
lemma valid_stmt_NormalI: 
schirmer@13688
   234
   assumes I: "\<And> n s0 L accC C s1 Y Z.
schirmer@13688
   235
               \<lbrakk>\<forall>t\<in>A. G\<Turnstile>n\<Colon>t; s0\<Colon>\<preceq>(G,L); normal s0; \<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>c\<Colon>\<surd>;
schirmer@13688
   236
               \<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>dom (locals (store s0))\<guillemotright>\<langle>c\<rangle>\<^sub>s\<guillemotright>C;
schirmer@13688
   237
               G\<turnstile>s0 \<midarrow>c\<midarrow>n\<rightarrow> s1; (Normal P) Y s0 Z\<rbrakk> \<Longrightarrow> Q \<diamondsuit> s1 Z \<and> s1\<Colon>\<preceq>(G,L)" 
schirmer@13688
   238
  shows "G,A|\<Turnstile>\<Colon>{ {Normal P} \<langle>c\<rangle>\<^sub>s\<succ> {Q} }"
schirmer@13688
   239
apply (simp add: ax_valids2_def triple_valid2_def2)
schirmer@13688
   240
apply (intro allI impI)
schirmer@13688
   241
apply (elim exE conjE)
schirmer@13688
   242
apply (rule I)
schirmer@13688
   243
by auto
schirmer@13688
   244
schirmer@13688
   245
lemma valid_var_NormalI: 
schirmer@13688
   246
   assumes I: "\<And> n s0 L accC T C vf s1 Y Z.
schirmer@13688
   247
               \<lbrakk>\<forall>t\<in>A. G\<Turnstile>n\<Colon>t; s0\<Colon>\<preceq>(G,L); normal s0; 
schirmer@13688
   248
                \<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>t\<Colon>=T;
schirmer@13688
   249
                \<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>dom (locals (store s0))\<guillemotright>\<langle>t\<rangle>\<^sub>v\<guillemotright>C;
schirmer@13688
   250
                G\<turnstile>s0 \<midarrow>t=\<succ>vf\<midarrow>n\<rightarrow> s1; (Normal P) Y s0 Z\<rbrakk> 
schirmer@13688
   251
               \<Longrightarrow> Q (In2 vf) s1 Z \<and> s1\<Colon>\<preceq>(G,L)"
schirmer@13688
   252
   shows "G,A|\<Turnstile>\<Colon>{ {Normal P} \<langle>t\<rangle>\<^sub>v\<succ> {Q} }"
schirmer@13688
   253
apply (simp add: ax_valids2_def triple_valid2_def2)
schirmer@13688
   254
apply (intro allI impI)
schirmer@13688
   255
apply (elim exE conjE)
schirmer@13688
   256
apply simp
schirmer@13688
   257
apply (rule I)
schirmer@13688
   258
by auto
schirmer@13688
   259
schirmer@13688
   260
lemma valid_expr_NormalI: 
schirmer@13688
   261
   assumes I: "\<And> n s0 L accC T C v s1 Y Z.
schirmer@13688
   262
               \<lbrakk>\<forall>t\<in>A. G\<Turnstile>n\<Colon>t; s0\<Colon>\<preceq>(G,L); normal s0; 
schirmer@13688
   263
                \<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>t\<Colon>-T;
schirmer@13688
   264
                \<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>dom (locals (store s0))\<guillemotright>\<langle>t\<rangle>\<^sub>e\<guillemotright>C;
schirmer@13688
   265
                G\<turnstile>s0 \<midarrow>t-\<succ>v\<midarrow>n\<rightarrow> s1; (Normal P) Y s0 Z\<rbrakk> 
schirmer@13688
   266
               \<Longrightarrow> Q (In1 v) s1 Z \<and> s1\<Colon>\<preceq>(G,L)"
schirmer@13688
   267
   shows "G,A|\<Turnstile>\<Colon>{ {Normal P} \<langle>t\<rangle>\<^sub>e\<succ> {Q} }"
schirmer@13688
   268
apply (simp add: ax_valids2_def triple_valid2_def2)
schirmer@13688
   269
apply (intro allI impI)
schirmer@13688
   270
apply (elim exE conjE)
schirmer@13688
   271
apply simp
schirmer@13688
   272
apply (rule I)
schirmer@13688
   273
by auto
schirmer@13688
   274
schirmer@13688
   275
lemma valid_expr_list_NormalI: 
schirmer@13688
   276
   assumes I: "\<And> n s0 L accC T C vs s1 Y Z.
schirmer@13688
   277
               \<lbrakk>\<forall>t\<in>A. G\<Turnstile>n\<Colon>t; s0\<Colon>\<preceq>(G,L); normal s0; 
schirmer@13688
   278
                \<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>t\<Colon>\<doteq>T;
schirmer@13688
   279
                \<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>dom (locals (store s0))\<guillemotright>\<langle>t\<rangle>\<^sub>l\<guillemotright>C;
schirmer@13688
   280
                G\<turnstile>s0 \<midarrow>t\<doteq>\<succ>vs\<midarrow>n\<rightarrow> s1; (Normal P) Y s0 Z\<rbrakk> 
schirmer@13688
   281
                \<Longrightarrow> Q (In3 vs) s1 Z \<and> s1\<Colon>\<preceq>(G,L)"
schirmer@13688
   282
   shows "G,A|\<Turnstile>\<Colon>{ {Normal P} \<langle>t\<rangle>\<^sub>l\<succ> {Q} }"
schirmer@13688
   283
apply (simp add: ax_valids2_def triple_valid2_def2)
schirmer@13688
   284
apply (intro allI impI)
schirmer@13688
   285
apply (elim exE conjE)
schirmer@13688
   286
apply simp
schirmer@13688
   287
apply (rule I)
schirmer@13688
   288
by auto
schirmer@13688
   289
schirmer@13688
   290
lemma validE [consumes 5]: 
schirmer@13688
   291
  assumes valid: "G,A|\<Turnstile>\<Colon>{ {P} t\<succ> {Q} }"
schirmer@13688
   292
   and    P: "P Y s0 Z"
schirmer@13688
   293
   and    valid_A: "\<forall>t\<in>A. G\<Turnstile>n\<Colon>t"
schirmer@13688
   294
   and    conf: "s0\<Colon>\<preceq>(G,L)"
schirmer@13688
   295
   and    eval: "G\<turnstile>s0 \<midarrow>t\<succ>\<midarrow>n\<rightarrow> (v,s1)"
schirmer@13688
   296
   and    wt: "normal s0 \<Longrightarrow> \<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>t\<Colon>T"
schirmer@13688
   297
   and    da: "normal s0 \<Longrightarrow> \<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>dom (locals (store s0))\<guillemotright>t\<guillemotright>C"
schirmer@13688
   298
   and    elim: "\<lbrakk>Q v s1 Z; s1\<Colon>\<preceq>(G,L)\<rbrakk> \<Longrightarrow> concl" 
schirmer@13688
   299
  shows "concl"
schirmer@13688
   300
using prems
schirmer@13688
   301
by (simp add: ax_valids2_def triple_valid2_def2) fast
schirmer@13688
   302
(* why consumes 5?. If I want to apply this lemma in a context wgere
schirmer@13688
   303
   \<not> normal s0 holds,
schirmer@13688
   304
   I can chain "\<not> normal s0" as fact number 6 and apply the rule with
schirmer@13688
   305
   cases. Auto will then solve premise 6 and 7.
schirmer@13688
   306
*)
schirmer@13688
   307
schirmer@12854
   308
lemma all_empty: "(!x. P) = P"
schirmer@12854
   309
by simp
schirmer@12854
   310
schirmer@12925
   311
corollary evaln_type_sound:
wenzelm@12937
   312
  assumes evaln: "G\<turnstile>s0 \<midarrow>t\<succ>\<midarrow>n\<rightarrow> (v,s1)" and
wenzelm@12937
   313
             wt: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>t\<Colon>T" and
schirmer@13688
   314
             da: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>dom (locals (store s0)) \<guillemotright>t\<guillemotright> A" and
wenzelm@12937
   315
        conf_s0: "s0\<Colon>\<preceq>(G,L)" and
wenzelm@12937
   316
             wf: "wf_prog G"                         
wenzelm@12937
   317
  shows "s1\<Colon>\<preceq>(G,L) \<and>  (normal s1 \<longrightarrow> G,L,store s1\<turnstile>t\<succ>v\<Colon>\<preceq>T) \<and> 
schirmer@12925
   318
         (error_free s0 = error_free s1)"
schirmer@12925
   319
proof -
schirmer@13688
   320
  from evaln have "G\<turnstile>s0 \<midarrow>t\<succ>\<rightarrow> (v,s1)"
schirmer@13688
   321
    by (rule evaln_eval)
schirmer@13688
   322
  from this wt da wf conf_s0 show ?thesis
schirmer@13688
   323
    by (rule eval_type_sound)
schirmer@12925
   324
qed
schirmer@12925
   325
schirmer@13688
   326
corollary dom_locals_evaln_mono_elim [consumes 1]: 
schirmer@13688
   327
  assumes   
schirmer@13688
   328
  evaln: "G\<turnstile> s0 \<midarrow>t\<succ>\<midarrow>n\<rightarrow> (v,s1)" and
schirmer@13688
   329
    hyps: "\<lbrakk>dom (locals (store s0)) \<subseteq> dom (locals (store s1));
schirmer@13688
   330
           \<And> vv s val. \<lbrakk>v=In2 vv; normal s1\<rbrakk> 
schirmer@13688
   331
                        \<Longrightarrow> dom (locals (store s)) 
schirmer@13688
   332
                             \<subseteq> dom (locals (store ((snd vv) val s)))\<rbrakk> \<Longrightarrow> P"
schirmer@13688
   333
 shows "P"
schirmer@13688
   334
proof -
schirmer@13688
   335
  from evaln have "G\<turnstile> s0 \<midarrow>t\<succ>\<rightarrow> (v,s1)" by (rule evaln_eval)
schirmer@13688
   336
  from this hyps show ?thesis
nipkow@17589
   337
    by (rule dom_locals_eval_mono_elim) iprover+
schirmer@13688
   338
qed
schirmer@12854
   339
schirmer@12854
   340
schirmer@12854
   341
schirmer@13688
   342
lemma evaln_no_abrupt: 
schirmer@13688
   343
   "\<And>s s'. \<lbrakk>G\<turnstile>s \<midarrow>t\<succ>\<midarrow>n\<rightarrow> (w,s'); normal s'\<rbrakk> \<Longrightarrow> normal s"
schirmer@13688
   344
by (erule evaln_cases,auto)
schirmer@13688
   345
schirmer@13688
   346
declare inj_term_simps [simp]
schirmer@13688
   347
lemma ax_sound2: 
schirmer@13688
   348
  assumes    wf: "wf_prog G" 
schirmer@13688
   349
    and   deriv: "G,A|\<turnstile>ts"
schirmer@13688
   350
  shows "G,A|\<Turnstile>\<Colon>ts"
schirmer@13688
   351
using deriv
schirmer@13688
   352
proof (induct)
schirmer@13688
   353
  case (empty A)
schirmer@13688
   354
  show ?case
schirmer@13688
   355
    by (simp add: ax_valids2_def triple_valid2_def2)
schirmer@13688
   356
next
schirmer@13688
   357
  case (insert A t ts)
wenzelm@23350
   358
  note valid_t = `G,A|\<Turnstile>\<Colon>{t}`
wenzelm@23350
   359
  moreover
wenzelm@23350
   360
  note valid_ts = `G,A|\<Turnstile>\<Colon>ts`
schirmer@13688
   361
  {
schirmer@13688
   362
    fix n assume valid_A: "\<forall>t\<in>A. G\<Turnstile>n\<Colon>t"
schirmer@13688
   363
    have "G\<Turnstile>n\<Colon>t" and "\<forall>t\<in>ts. G\<Turnstile>n\<Colon>t"
schirmer@13688
   364
    proof -
schirmer@13688
   365
      from valid_A valid_t show "G\<Turnstile>n\<Colon>t"
schirmer@13688
   366
	by (simp add: ax_valids2_def)
schirmer@13688
   367
    next
schirmer@13688
   368
      from valid_A valid_ts show "\<forall>t\<in>ts. G\<Turnstile>n\<Colon>t"
schirmer@13688
   369
	by (unfold ax_valids2_def) blast
schirmer@13688
   370
    qed
schirmer@13688
   371
    hence "\<forall>t'\<in>insert t ts. G\<Turnstile>n\<Colon>t'"
schirmer@13688
   372
      by simp
schirmer@13688
   373
  }
schirmer@13688
   374
  thus ?case
schirmer@13688
   375
    by (unfold ax_valids2_def) blast
schirmer@13688
   376
next
berghofe@21765
   377
  case (asm ts A)
wenzelm@23350
   378
  from `ts \<subseteq> A`
wenzelm@23350
   379
  show "G,A|\<Turnstile>\<Colon>ts"
schirmer@13688
   380
    by (auto simp add: ax_valids2_def triple_valid2_def)
schirmer@13688
   381
next
berghofe@21765
   382
  case (weaken A ts' ts)
wenzelm@23350
   383
  note `G,A|\<Turnstile>\<Colon>ts'`
wenzelm@23350
   384
  moreover note `ts \<subseteq> ts'`
schirmer@13688
   385
  ultimately show "G,A|\<Turnstile>\<Colon>ts"
schirmer@13688
   386
    by (unfold ax_valids2_def triple_valid2_def) blast
schirmer@13688
   387
next
berghofe@21765
   388
  case (conseq P A t Q)
wenzelm@23350
   389
  note con = `\<forall>Y s Z. P Y s Z \<longrightarrow> 
schirmer@13688
   390
              (\<exists>P' Q'.
schirmer@13688
   391
                  (G,A\<turnstile>{P'} t\<succ> {Q'} \<and> G,A|\<Turnstile>\<Colon>{ {P'} t\<succ> {Q'} }) \<and>
wenzelm@23350
   392
                  (\<forall>Y' s'. (\<forall>Y Z'. P' Y s Z' \<longrightarrow> Q' Y' s' Z') \<longrightarrow> Q Y' s' Z))`
schirmer@13688
   393
  show "G,A|\<Turnstile>\<Colon>{ {P} t\<succ> {Q} }"
schirmer@13688
   394
  proof (rule validI)
schirmer@13688
   395
    fix n s0 L accC T C v s1 Y Z
schirmer@13688
   396
    assume valid_A: "\<forall>t\<in>A. G\<Turnstile>n\<Colon>t" 
schirmer@13688
   397
    assume conf: "s0\<Colon>\<preceq>(G,L)"
schirmer@13688
   398
    assume wt: "normal s0 \<Longrightarrow> \<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>t\<Colon>T"
schirmer@13688
   399
    assume da: "normal s0 
schirmer@13688
   400
                 \<Longrightarrow> \<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>dom (locals (store s0)) \<guillemotright>t\<guillemotright> C"
schirmer@13688
   401
    assume eval: "G\<turnstile>s0 \<midarrow>t\<succ>\<midarrow>n\<rightarrow> (v, s1)"
schirmer@13688
   402
    assume P: "P Y s0 Z"
schirmer@13688
   403
    show "Q v s1 Z \<and> s1\<Colon>\<preceq>(G, L)"
schirmer@13688
   404
    proof -
schirmer@13688
   405
      from valid_A conf wt da eval P con
schirmer@13688
   406
      have "Q v s1 Z"
schirmer@13688
   407
	apply (simp add: ax_valids2_def triple_valid2_def2)
schirmer@13688
   408
	apply (tactic "smp_tac 3 1")
schirmer@13688
   409
	apply clarify
schirmer@13688
   410
	apply (tactic "smp_tac 1 1")
schirmer@13688
   411
	apply (erule allE,erule allE, erule mp)
schirmer@13688
   412
	apply (intro strip)
schirmer@13688
   413
	apply (tactic "smp_tac 3 1")
schirmer@13688
   414
	apply (tactic "smp_tac 2 1")
schirmer@13688
   415
	apply (tactic "smp_tac 1 1")
schirmer@13688
   416
	by blast
schirmer@13688
   417
      moreover have "s1\<Colon>\<preceq>(G, L)"
schirmer@13688
   418
      proof (cases "normal s0")
schirmer@13688
   419
	case True
schirmer@13688
   420
	from eval wt [OF True] da [OF True] conf wf 
schirmer@13688
   421
	show ?thesis
schirmer@13688
   422
	  by (rule evaln_type_sound [elim_format]) simp
schirmer@13688
   423
      next
schirmer@13688
   424
	case False
schirmer@13688
   425
	with eval have "s1=s0"
schirmer@13688
   426
	  by auto
schirmer@13688
   427
	with conf show ?thesis by simp
schirmer@13688
   428
      qed
schirmer@13688
   429
      ultimately show ?thesis ..
schirmer@13688
   430
    qed
schirmer@13688
   431
  qed
schirmer@13688
   432
next
berghofe@21765
   433
  case (hazard A P t Q)
schirmer@13688
   434
  show "G,A|\<Turnstile>\<Colon>{ {P \<and>. Not \<circ> type_ok G t} t\<succ> {Q} }"
schirmer@13688
   435
    by (simp add: ax_valids2_def triple_valid2_def2 type_ok_def) fast
schirmer@13688
   436
next
schirmer@13688
   437
  case (Abrupt A P t)
schirmer@13688
   438
  show "G,A|\<Turnstile>\<Colon>{ {P\<leftarrow>arbitrary3 t \<and>. Not \<circ> normal} t\<succ> {P} }"
schirmer@13688
   439
  proof (rule validI)
schirmer@13688
   440
    fix n s0 L accC T C v s1 Y Z 
schirmer@13688
   441
    assume conf_s0: "s0\<Colon>\<preceq>(G, L)"
schirmer@13688
   442
    assume eval: "G\<turnstile>s0 \<midarrow>t\<succ>\<midarrow>n\<rightarrow> (v, s1)"
schirmer@13688
   443
    assume "(P\<leftarrow>arbitrary3 t \<and>. Not \<circ> normal) Y s0 Z"
schirmer@13688
   444
    then obtain P: "P (arbitrary3 t) s0 Z" and abrupt_s0: "\<not> normal s0"
schirmer@13688
   445
      by simp
schirmer@13688
   446
    from eval abrupt_s0 obtain "s1=s0" and "v=arbitrary3 t"
schirmer@13688
   447
      by auto
schirmer@13688
   448
    with P conf_s0
schirmer@13688
   449
    show "P v s1 Z \<and> s1\<Colon>\<preceq>(G, L)"
schirmer@13688
   450
      by simp
schirmer@13688
   451
  qed
schirmer@13688
   452
next
schirmer@13688
   453
  case (LVar A P vn)
schirmer@13688
   454
  show "G,A|\<Turnstile>\<Colon>{ {Normal (\<lambda>s.. P\<leftarrow>In2 (lvar vn s))} LVar vn=\<succ> {P} }"
schirmer@13688
   455
  proof (rule valid_var_NormalI)
schirmer@13688
   456
    fix n s0 L accC T C vf s1 Y Z
schirmer@13688
   457
    assume conf_s0: "s0\<Colon>\<preceq>(G, L)"
schirmer@13688
   458
    assume normal_s0: "normal s0"
schirmer@13688
   459
    assume wt: "\<lparr>prg = G, cls = accC, lcl = L\<rparr>\<turnstile>LVar vn\<Colon>=T"
schirmer@13688
   460
    assume da: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile> dom (locals (store s0)) \<guillemotright>\<langle>LVar vn\<rangle>\<^sub>v\<guillemotright> C"
schirmer@13688
   461
    assume eval: "G\<turnstile>s0 \<midarrow>LVar vn=\<succ>vf\<midarrow>n\<rightarrow> s1" 
schirmer@13688
   462
    assume P: "(Normal (\<lambda>s.. P\<leftarrow>In2 (lvar vn s))) Y s0 Z"
schirmer@13688
   463
    show "P (In2 vf) s1 Z \<and> s1\<Colon>\<preceq>(G, L)"
schirmer@13688
   464
    proof 
schirmer@13688
   465
      from eval normal_s0 obtain "s1=s0" "vf=lvar vn (store s0)"
schirmer@13688
   466
	by (fastsimp elim: evaln_elim_cases)
schirmer@13688
   467
      with P show "P (In2 vf) s1 Z"
schirmer@13688
   468
	by simp
schirmer@13688
   469
    next
schirmer@13688
   470
      from eval wt da conf_s0 wf
schirmer@13688
   471
      show "s1\<Colon>\<preceq>(G, L)"
schirmer@13688
   472
	by (rule evaln_type_sound [elim_format]) simp
schirmer@13688
   473
    qed
schirmer@13688
   474
  qed
schirmer@13688
   475
next
berghofe@21765
   476
  case (FVar A P statDeclC Q e stat fn R accC)
wenzelm@23350
   477
  note valid_init = `G,A|\<Turnstile>\<Colon>{ {Normal P} .Init statDeclC. {Q} }`
wenzelm@23350
   478
  note valid_e = `G,A|\<Turnstile>\<Colon>{ {Q} e-\<succ> {\<lambda>Val:a:. fvar statDeclC stat fn a ..; R} }`
schirmer@13688
   479
  show "G,A|\<Turnstile>\<Colon>{ {Normal P} {accC,statDeclC,stat}e..fn=\<succ> {R} }"
schirmer@13688
   480
  proof (rule valid_var_NormalI)
schirmer@13688
   481
    fix n s0 L accC' T V vf s3 Y Z
schirmer@13688
   482
    assume valid_A: "\<forall>t\<in>A. G\<Turnstile>n\<Colon>t"
schirmer@13688
   483
    assume conf_s0:  "s0\<Colon>\<preceq>(G,L)"  
schirmer@13688
   484
    assume normal_s0: "normal s0"
schirmer@13688
   485
    assume wt: "\<lparr>prg=G,cls=accC',lcl=L\<rparr>\<turnstile>{accC,statDeclC,stat}e..fn\<Colon>=T"
schirmer@13688
   486
    assume da: "\<lparr>prg=G,cls=accC',lcl=L\<rparr>
schirmer@13688
   487
                  \<turnstile> dom (locals (store s0)) \<guillemotright>\<langle>{accC,statDeclC,stat}e..fn\<rangle>\<^sub>v\<guillemotright> V"
schirmer@13688
   488
    assume eval: "G\<turnstile>s0 \<midarrow>{accC,statDeclC,stat}e..fn=\<succ>vf\<midarrow>n\<rightarrow> s3"
schirmer@13688
   489
    assume P: "(Normal P) Y s0 Z"
schirmer@13688
   490
    show "R \<lfloor>vf\<rfloor>\<^sub>v s3 Z \<and> s3\<Colon>\<preceq>(G, L)"
schirmer@13688
   491
    proof -
schirmer@13688
   492
      from wt obtain statC f where
schirmer@13688
   493
        wt_e: "\<lparr>prg=G, cls=accC, lcl=L\<rparr>\<turnstile>e\<Colon>-Class statC" and
schirmer@13688
   494
        accfield: "accfield G accC statC fn = Some (statDeclC,f)" and
schirmer@13688
   495
	eq_accC: "accC=accC'" and
schirmer@13688
   496
        stat: "stat=is_static f" and
schirmer@13688
   497
	T: "T=(type f)"
schirmer@13688
   498
	by (cases) (auto simp add: member_is_static_simp)
schirmer@13688
   499
      from da eq_accC
schirmer@13688
   500
      have da_e: "\<lparr>prg=G, cls=accC, lcl=L\<rparr>\<turnstile>dom (locals (store s0))\<guillemotright>\<langle>e\<rangle>\<^sub>e\<guillemotright> V"
schirmer@13688
   501
	by cases simp
schirmer@13688
   502
      from eval obtain a s1 s2 s2' where
schirmer@13688
   503
	eval_init: "G\<turnstile>s0 \<midarrow>Init statDeclC\<midarrow>n\<rightarrow> s1" and 
schirmer@13688
   504
        eval_e: "G\<turnstile>s1 \<midarrow>e-\<succ>a\<midarrow>n\<rightarrow> s2" and 
schirmer@13688
   505
	fvar: "(vf,s2')=fvar statDeclC stat fn a s2" and
schirmer@13688
   506
	s3: "s3 = check_field_access G accC statDeclC fn stat a s2'"
schirmer@13688
   507
	using normal_s0 by (fastsimp elim: evaln_elim_cases) 
schirmer@13688
   508
      have wt_init: "\<lparr>prg=G, cls=accC, lcl=L\<rparr>\<turnstile>(Init statDeclC)\<Colon>\<surd>"
schirmer@13688
   509
      proof -
schirmer@13688
   510
	from wf wt_e 
schirmer@13688
   511
	have iscls_statC: "is_class G statC"
schirmer@13688
   512
	  by (auto dest: ty_expr_is_type type_is_class)
schirmer@13688
   513
	with wf accfield 
schirmer@13688
   514
	have iscls_statDeclC: "is_class G statDeclC"
schirmer@13688
   515
	  by (auto dest!: accfield_fields dest: fields_declC)
schirmer@13688
   516
	thus ?thesis by simp
schirmer@13688
   517
      qed
schirmer@13688
   518
      obtain I where 
schirmer@13688
   519
	da_init: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>
schirmer@13688
   520
                    \<turnstile> dom (locals (store s0)) \<guillemotright>\<langle>Init statDeclC\<rangle>\<^sub>s\<guillemotright> I"
schirmer@13688
   521
	by (auto intro: da_Init [simplified] assigned.select_convs)
schirmer@13688
   522
      from valid_init P valid_A conf_s0 eval_init wt_init da_init
schirmer@13688
   523
      obtain Q: "Q \<diamondsuit> s1 Z" and conf_s1: "s1\<Colon>\<preceq>(G, L)"
schirmer@13688
   524
	by (rule validE)
schirmer@13688
   525
      obtain 
schirmer@13688
   526
	R: "R \<lfloor>vf\<rfloor>\<^sub>v s2' Z" and 
schirmer@13688
   527
        conf_s2: "s2\<Colon>\<preceq>(G, L)" and
schirmer@13688
   528
	conf_a: "normal s2 \<longrightarrow> G,store s2\<turnstile>a\<Colon>\<preceq>Class statC"
schirmer@13688
   529
      proof (cases "normal s1")
schirmer@13688
   530
	case True
schirmer@13688
   531
	obtain V' where 
schirmer@13688
   532
	  da_e':
schirmer@13688
   533
	  "\<lparr>prg=G,cls=accC,lcl=L\<rparr> \<turnstile>dom (locals (store s1))\<guillemotright>\<langle>e\<rangle>\<^sub>e\<guillemotright> V'"
schirmer@13688
   534
	proof -
schirmer@13688
   535
	  from eval_init 
schirmer@13688
   536
	  have "(dom (locals (store s0))) \<subseteq> (dom (locals (store s1)))"
schirmer@13688
   537
	    by (rule dom_locals_evaln_mono_elim)
wenzelm@23350
   538
	  with da_e show thesis
wenzelm@23350
   539
	    by (rule da_weakenE) (rule that)
schirmer@13688
   540
	qed
schirmer@13688
   541
	with valid_e Q valid_A conf_s1 eval_e wt_e
schirmer@13688
   542
	obtain "R \<lfloor>vf\<rfloor>\<^sub>v s2' Z" and "s2\<Colon>\<preceq>(G, L)"
schirmer@13688
   543
	  by (rule validE) (simp add: fvar [symmetric])
schirmer@13688
   544
	moreover
schirmer@13688
   545
	from eval_e wt_e da_e' conf_s1 wf
schirmer@13688
   546
	have "normal s2 \<longrightarrow> G,store s2\<turnstile>a\<Colon>\<preceq>Class statC"
schirmer@13688
   547
	  by (rule evaln_type_sound [elim_format]) simp
schirmer@13688
   548
	ultimately show ?thesis ..
schirmer@13688
   549
      next
schirmer@13688
   550
	case False
schirmer@13688
   551
	with valid_e Q valid_A conf_s1 eval_e
schirmer@13688
   552
	obtain  "R \<lfloor>vf\<rfloor>\<^sub>v s2' Z" and "s2\<Colon>\<preceq>(G, L)"
schirmer@13688
   553
	  by (cases rule: validE) (simp add: fvar [symmetric])+
schirmer@13688
   554
	moreover from False eval_e have "\<not> normal s2"
schirmer@13688
   555
	  by auto
schirmer@13688
   556
	hence "normal s2 \<longrightarrow> G,store s2\<turnstile>a\<Colon>\<preceq>Class statC"
schirmer@13688
   557
	  by auto
schirmer@13688
   558
	ultimately show ?thesis ..
schirmer@13688
   559
      qed
schirmer@13688
   560
      from accfield wt_e eval_init eval_e conf_s2 conf_a fvar stat s3 wf
schirmer@13688
   561
      have eq_s3_s2': "s3=s2'"  
schirmer@13688
   562
	using normal_s0 by (auto dest!: error_free_field_access evaln_eval)
schirmer@13688
   563
      moreover
schirmer@13688
   564
      from eval wt da conf_s0 wf
schirmer@13688
   565
      have "s3\<Colon>\<preceq>(G, L)"
schirmer@13688
   566
	by (rule evaln_type_sound [elim_format]) simp
schirmer@13688
   567
      ultimately show ?thesis using Q by simp
schirmer@13688
   568
    qed
schirmer@13688
   569
  qed
schirmer@13690
   570
next
berghofe@21765
   571
  case (AVar A P e1 Q e2 R)
wenzelm@23350
   572
  note valid_e1 = `G,A|\<Turnstile>\<Colon>{ {Normal P} e1-\<succ> {Q} }`
schirmer@13688
   573
  have valid_e2: "\<And> a. G,A|\<Turnstile>\<Colon>{ {Q\<leftarrow>In1 a} e2-\<succ> {\<lambda>Val:i:. avar G i a ..; R} }"
schirmer@13688
   574
    using AVar.hyps by simp
schirmer@13688
   575
  show "G,A|\<Turnstile>\<Colon>{ {Normal P} e1.[e2]=\<succ> {R} }"
schirmer@13688
   576
  proof (rule valid_var_NormalI)
schirmer@13688
   577
    fix n s0 L accC T V vf s2' Y Z
schirmer@13688
   578
    assume valid_A: "\<forall>t\<in>A. G\<Turnstile>n\<Colon>t"
schirmer@13688
   579
    assume conf_s0: "s0\<Colon>\<preceq>(G,L)"  
schirmer@13688
   580
    assume normal_s0: "normal s0"
schirmer@13688
   581
    assume wt: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>e1.[e2]\<Colon>=T"
schirmer@13688
   582
    assume da: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>
schirmer@13688
   583
                  \<turnstile> dom (locals (store s0)) \<guillemotright>\<langle>e1.[e2]\<rangle>\<^sub>v\<guillemotright> V"
schirmer@13688
   584
    assume eval: "G\<turnstile>s0 \<midarrow>e1.[e2]=\<succ>vf\<midarrow>n\<rightarrow> s2'"
schirmer@13688
   585
    assume P: "(Normal P) Y s0 Z"
schirmer@13688
   586
    show "R \<lfloor>vf\<rfloor>\<^sub>v s2' Z \<and> s2'\<Colon>\<preceq>(G, L)"
schirmer@13688
   587
    proof -
schirmer@13688
   588
      from wt obtain 
schirmer@13688
   589
	wt_e1: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>e1\<Colon>-T.[]" and
schirmer@13688
   590
        wt_e2: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>e2\<Colon>-PrimT Integer" 
schirmer@13688
   591
	by (rule wt_elim_cases) simp
schirmer@13688
   592
      from da obtain E1 where
schirmer@13688
   593
	da_e1: "\<lparr>prg=G,cls=accC,lcl=L\<rparr> \<turnstile>dom (locals (store s0))\<guillemotright>\<langle>e1\<rangle>\<^sub>e\<guillemotright> E1" and
schirmer@13688
   594
	da_e2: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile> nrm E1 \<guillemotright>\<langle>e2\<rangle>\<^sub>e\<guillemotright> V"
schirmer@13688
   595
	by (rule da_elim_cases) simp
schirmer@13688
   596
      from eval obtain s1 a i s2 where
schirmer@13688
   597
	eval_e1: "G\<turnstile>s0 \<midarrow>e1-\<succ>a\<midarrow>n\<rightarrow> s1" and
schirmer@13688
   598
	eval_e2: "G\<turnstile>s1 \<midarrow>e2-\<succ>i\<midarrow>n\<rightarrow> s2" and
schirmer@13688
   599
	avar: "avar G i a s2 =(vf, s2')"
schirmer@13688
   600
	using normal_s0 by (fastsimp elim: evaln_elim_cases)
schirmer@13688
   601
      from valid_e1 P valid_A conf_s0 eval_e1 wt_e1 da_e1
schirmer@13688
   602
      obtain Q: "Q \<lfloor>a\<rfloor>\<^sub>e s1 Z" and conf_s1: "s1\<Colon>\<preceq>(G, L)"
schirmer@13688
   603
	by (rule validE)
schirmer@13688
   604
      from Q have Q': "\<And> v. (Q\<leftarrow>In1 a) v s1 Z"
schirmer@13688
   605
	by simp
schirmer@13688
   606
      have "R \<lfloor>vf\<rfloor>\<^sub>v s2' Z"
schirmer@13688
   607
      proof (cases "normal s1")
schirmer@13688
   608
	case True
schirmer@13688
   609
	obtain V' where 
schirmer@13688
   610
	  "\<lparr>prg=G,cls=accC,lcl=L\<rparr> \<turnstile>dom (locals (store s1))\<guillemotright>\<langle>e2\<rangle>\<^sub>e\<guillemotright> V'"
schirmer@13688
   611
	proof -
schirmer@13688
   612
	  from eval_e1  wt_e1 da_e1 wf True
schirmer@13688
   613
	  have "nrm E1 \<subseteq> dom (locals (store s1))"
nipkow@17589
   614
	    by (cases rule: da_good_approx_evalnE) iprover
schirmer@13688
   615
	  with da_e2 show ?thesis
schirmer@13688
   616
	    by (rule da_weakenE)
schirmer@13688
   617
	qed
schirmer@13688
   618
	with valid_e2 Q' valid_A conf_s1 eval_e2 wt_e2 
schirmer@13688
   619
	show ?thesis
schirmer@13688
   620
	  by (rule validE) (simp add: avar)
schirmer@13688
   621
      next
schirmer@13688
   622
	case False
schirmer@13688
   623
	with valid_e2 Q' valid_A conf_s1 eval_e2
schirmer@13688
   624
	show ?thesis
schirmer@13688
   625
	  by (cases rule: validE) (simp add: avar)+
schirmer@13688
   626
      qed
schirmer@13688
   627
      moreover
schirmer@13688
   628
      from eval wt da conf_s0 wf
schirmer@13688
   629
      have "s2'\<Colon>\<preceq>(G, L)"
schirmer@13688
   630
	by (rule evaln_type_sound [elim_format]) simp
schirmer@13688
   631
      ultimately show ?thesis ..
schirmer@13688
   632
    qed
schirmer@13688
   633
  qed
schirmer@13688
   634
next
berghofe@21765
   635
  case (NewC A P C Q)
schirmer@13688
   636
  have valid_init: "G,A|\<Turnstile>\<Colon>{ {Normal P} .Init C. {Alloc G (CInst C) Q} }".
schirmer@13688
   637
  show "G,A|\<Turnstile>\<Colon>{ {Normal P} NewC C-\<succ> {Q} }"
schirmer@13688
   638
  proof (rule valid_expr_NormalI)
schirmer@13688
   639
    fix n s0 L accC T E v s2 Y Z
schirmer@13688
   640
    assume valid_A: "\<forall>t\<in>A. G\<Turnstile>n\<Colon>t"
schirmer@13688
   641
    assume conf_s0: "s0\<Colon>\<preceq>(G,L)"  
schirmer@13688
   642
    assume normal_s0: "normal s0"
schirmer@13688
   643
    assume wt: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>NewC C\<Colon>-T"
schirmer@13688
   644
    assume da: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>
schirmer@13688
   645
                  \<turnstile> dom (locals (store s0)) \<guillemotright>\<langle>NewC C\<rangle>\<^sub>e\<guillemotright> E"
schirmer@13688
   646
    assume eval: "G\<turnstile>s0 \<midarrow>NewC C-\<succ>v\<midarrow>n\<rightarrow> s2"
schirmer@13688
   647
    assume P: "(Normal P) Y s0 Z"
schirmer@13688
   648
    show "Q \<lfloor>v\<rfloor>\<^sub>e s2 Z \<and> s2\<Colon>\<preceq>(G, L)"
schirmer@13688
   649
    proof -
schirmer@13688
   650
      from wt obtain is_cls_C: "is_class G C" 
schirmer@13688
   651
	by (rule wt_elim_cases) (auto dest: is_acc_classD)
schirmer@13688
   652
      hence wt_init: "\<lparr>prg=G, cls=accC, lcl=L\<rparr>\<turnstile>Init C\<Colon>\<surd>" 
schirmer@13688
   653
	by auto
schirmer@13688
   654
      obtain I where 
schirmer@13688
   655
	da_init: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile> dom (locals (store s0)) \<guillemotright>\<langle>Init C\<rangle>\<^sub>s\<guillemotright> I"
schirmer@13688
   656
	by (auto intro: da_Init [simplified] assigned.select_convs)
schirmer@13688
   657
      from eval obtain s1 a where
schirmer@13688
   658
	eval_init: "G\<turnstile>s0 \<midarrow>Init C\<midarrow>n\<rightarrow> s1" and 
schirmer@13688
   659
        alloc: "G\<turnstile>s1 \<midarrow>halloc CInst C\<succ>a\<rightarrow> s2" and
schirmer@13688
   660
	v: "v=Addr a"
schirmer@13688
   661
	using normal_s0 by (fastsimp elim: evaln_elim_cases)
schirmer@13688
   662
      from valid_init P valid_A conf_s0 eval_init wt_init da_init
schirmer@13688
   663
      obtain "(Alloc G (CInst C) Q) \<diamondsuit> s1 Z" 
schirmer@13688
   664
	by (rule validE)
schirmer@13688
   665
      with alloc v have "Q \<lfloor>v\<rfloor>\<^sub>e s2 Z"
schirmer@13688
   666
	by simp
schirmer@13688
   667
      moreover
schirmer@13688
   668
      from eval wt da conf_s0 wf
schirmer@13688
   669
      have "s2\<Colon>\<preceq>(G, L)"
schirmer@13688
   670
	by (rule evaln_type_sound [elim_format]) simp
schirmer@13688
   671
      ultimately show ?thesis ..
schirmer@13688
   672
    qed
schirmer@13688
   673
  qed
schirmer@13688
   674
next
berghofe@21765
   675
  case (NewA A P T Q e R)
wenzelm@23350
   676
  note valid_init = `G,A|\<Turnstile>\<Colon>{ {Normal P} .init_comp_ty T. {Q} }`
wenzelm@23350
   677
  note valid_e = `G,A|\<Turnstile>\<Colon>{ {Q} e-\<succ> {\<lambda>Val:i:. abupd (check_neg i) .; 
wenzelm@23350
   678
                                            Alloc G (Arr T (the_Intg i)) R}}`
schirmer@13688
   679
  show "G,A|\<Turnstile>\<Colon>{ {Normal P} New T[e]-\<succ> {R} }"
schirmer@13688
   680
  proof (rule valid_expr_NormalI)
schirmer@13688
   681
    fix n s0 L accC arrT E v s3 Y Z
schirmer@13688
   682
    assume valid_A: "\<forall>t\<in>A. G\<Turnstile>n\<Colon>t"
schirmer@13688
   683
    assume conf_s0: "s0\<Colon>\<preceq>(G,L)"  
schirmer@13688
   684
    assume normal_s0: "normal s0"
schirmer@13688
   685
    assume wt: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>New T[e]\<Colon>-arrT"
schirmer@13688
   686
    assume da: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>dom (locals (store s0)) \<guillemotright>\<langle>New T[e]\<rangle>\<^sub>e\<guillemotright> E"
schirmer@13688
   687
    assume eval: "G\<turnstile>s0 \<midarrow>New T[e]-\<succ>v\<midarrow>n\<rightarrow> s3"
schirmer@13688
   688
    assume P: "(Normal P) Y s0 Z"
schirmer@13688
   689
    show "R \<lfloor>v\<rfloor>\<^sub>e s3 Z \<and> s3\<Colon>\<preceq>(G, L)"
schirmer@13688
   690
    proof -
schirmer@13688
   691
      from wt obtain
schirmer@13688
   692
	wt_init: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>init_comp_ty T\<Colon>\<surd>" and 
schirmer@13688
   693
	wt_e: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>e\<Colon>-PrimT Integer" 
schirmer@13688
   694
	by (rule wt_elim_cases) (auto intro: wt_init_comp_ty )
schirmer@13688
   695
      from da obtain
schirmer@13688
   696
	da_e:"\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile> dom (locals (store s0)) \<guillemotright>\<langle>e\<rangle>\<^sub>e\<guillemotright> E"
schirmer@13688
   697
	by cases simp
schirmer@13688
   698
      from eval obtain s1 i s2 a where
schirmer@13688
   699
	eval_init: "G\<turnstile>s0 \<midarrow>init_comp_ty T\<midarrow>n\<rightarrow> s1" and 
schirmer@13688
   700
        eval_e: "G\<turnstile>s1 \<midarrow>e-\<succ>i\<midarrow>n\<rightarrow> s2" and
schirmer@13688
   701
        alloc: "G\<turnstile>abupd (check_neg i) s2 \<midarrow>halloc Arr T (the_Intg i)\<succ>a\<rightarrow> s3" and
schirmer@13688
   702
        v: "v=Addr a"
schirmer@13688
   703
	using normal_s0 by (fastsimp elim: evaln_elim_cases)
schirmer@13688
   704
      obtain I where
schirmer@13688
   705
	da_init:
schirmer@13688
   706
	"\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>dom (locals (store s0)) \<guillemotright>\<langle>init_comp_ty T\<rangle>\<^sub>s\<guillemotright> I"
schirmer@13688
   707
      proof (cases "\<exists>C. T = Class C")
schirmer@13688
   708
	case True
schirmer@13688
   709
	thus ?thesis
schirmer@13688
   710
	  by - (rule that, (auto intro: da_Init [simplified] 
schirmer@13688
   711
                                        assigned.select_convs
schirmer@13688
   712
                              simp add: init_comp_ty_def))
schirmer@13688
   713
	 (* simplified: to rewrite \<langle>Init C\<rangle> to In1r (Init C) *)
schirmer@13688
   714
      next
schirmer@13688
   715
	case False
schirmer@13688
   716
	thus ?thesis
schirmer@13688
   717
	  by - (rule that, (auto intro: da_Skip [simplified] 
schirmer@13688
   718
                                      assigned.select_convs
schirmer@13688
   719
                           simp add: init_comp_ty_def))
schirmer@13688
   720
         (* simplified: to rewrite \<langle>Skip\<rangle> to In1r (Skip) *)
schirmer@13688
   721
      qed
schirmer@13688
   722
      with valid_init P valid_A conf_s0 eval_init wt_init 
schirmer@13688
   723
      obtain Q: "Q \<diamondsuit> s1 Z" and conf_s1: "s1\<Colon>\<preceq>(G, L)"
schirmer@13688
   724
	by (rule validE)
schirmer@13688
   725
      obtain E' where
schirmer@13688
   726
       "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile> dom (locals (store s1)) \<guillemotright>\<langle>e\<rangle>\<^sub>e\<guillemotright> E'"
schirmer@13688
   727
      proof -
schirmer@13688
   728
	from eval_init 
schirmer@13688
   729
	have "dom (locals (store s0)) \<subseteq> dom (locals (store s1))"
schirmer@13688
   730
	  by (rule dom_locals_evaln_mono_elim)
schirmer@13688
   731
	with da_e show ?thesis
schirmer@13688
   732
	  by (rule da_weakenE)
schirmer@13688
   733
      qed
schirmer@13688
   734
      with valid_e Q valid_A conf_s1 eval_e wt_e
schirmer@13688
   735
      have "(\<lambda>Val:i:. abupd (check_neg i) .; 
schirmer@13688
   736
                      Alloc G (Arr T (the_Intg i)) R) \<lfloor>i\<rfloor>\<^sub>e s2 Z"
schirmer@13688
   737
	by (rule validE)
schirmer@13688
   738
      with alloc v have "R \<lfloor>v\<rfloor>\<^sub>e s3 Z"
schirmer@13688
   739
	by simp
schirmer@13688
   740
      moreover 
schirmer@13688
   741
      from eval wt da conf_s0 wf
schirmer@13688
   742
      have "s3\<Colon>\<preceq>(G, L)"
schirmer@13688
   743
	by (rule evaln_type_sound [elim_format]) simp
schirmer@13688
   744
      ultimately show ?thesis ..
schirmer@13688
   745
    qed
schirmer@13688
   746
  qed
schirmer@13688
   747
next
berghofe@21765
   748
  case (Cast A P e T Q)
schirmer@13688
   749
  have valid_e: "G,A|\<Turnstile>\<Colon>{ {Normal P} e-\<succ> 
schirmer@13688
   750
                 {\<lambda>Val:v:. \<lambda>s.. abupd (raise_if (\<not> G,s\<turnstile>v fits T) ClassCast) .;
schirmer@13688
   751
                  Q\<leftarrow>In1 v} }" .
schirmer@13688
   752
  show "G,A|\<Turnstile>\<Colon>{ {Normal P} Cast T e-\<succ> {Q} }"
schirmer@13688
   753
  proof (rule valid_expr_NormalI)
schirmer@13688
   754
    fix n s0 L accC castT E v s2 Y Z
schirmer@13688
   755
    assume valid_A: "\<forall>t\<in>A. G\<Turnstile>n\<Colon>t"
schirmer@13688
   756
    assume conf_s0: "s0\<Colon>\<preceq>(G,L)"  
schirmer@13688
   757
    assume normal_s0: "normal s0"
schirmer@13688
   758
    assume wt: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>Cast T e\<Colon>-castT"
schirmer@13688
   759
    assume da: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>dom (locals (store s0)) \<guillemotright>\<langle>Cast T e\<rangle>\<^sub>e\<guillemotright> E"
schirmer@13688
   760
    assume eval: "G\<turnstile>s0 \<midarrow>Cast T e-\<succ>v\<midarrow>n\<rightarrow> s2"
schirmer@13688
   761
    assume P: "(Normal P) Y s0 Z"
schirmer@13688
   762
    show "Q \<lfloor>v\<rfloor>\<^sub>e s2 Z \<and> s2\<Colon>\<preceq>(G, L)"
schirmer@13688
   763
    proof -
schirmer@13688
   764
      from wt obtain eT where 
schirmer@13688
   765
	wt_e: "\<lparr>prg = G, cls = accC, lcl = L\<rparr>\<turnstile>e\<Colon>-eT" 
schirmer@13688
   766
	by cases simp
schirmer@13688
   767
      from da obtain
schirmer@13688
   768
	da_e: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile> dom (locals (store s0)) \<guillemotright>\<langle>e\<rangle>\<^sub>e\<guillemotright> E"
schirmer@13688
   769
	by cases simp
schirmer@13688
   770
      from eval obtain s1 where
schirmer@13688
   771
	eval_e: "G\<turnstile>s0 \<midarrow>e-\<succ>v\<midarrow>n\<rightarrow> s1" and
schirmer@13688
   772
        s2: "s2 = abupd (raise_if (\<not> G,snd s1\<turnstile>v fits T) ClassCast) s1"
schirmer@13688
   773
	using normal_s0 by (fastsimp elim: evaln_elim_cases)
schirmer@13688
   774
      from valid_e P valid_A conf_s0 eval_e wt_e da_e
schirmer@13688
   775
      have "(\<lambda>Val:v:. \<lambda>s.. abupd (raise_if (\<not> G,s\<turnstile>v fits T) ClassCast) .;
schirmer@13688
   776
                  Q\<leftarrow>In1 v) \<lfloor>v\<rfloor>\<^sub>e s1 Z"
schirmer@13688
   777
	by (rule validE)
schirmer@13688
   778
      with s2 have "Q \<lfloor>v\<rfloor>\<^sub>e s2 Z"
schirmer@13688
   779
	by simp
schirmer@13688
   780
      moreover
schirmer@13688
   781
      from eval wt da conf_s0 wf
schirmer@13688
   782
      have "s2\<Colon>\<preceq>(G, L)"
schirmer@13688
   783
	by (rule evaln_type_sound [elim_format]) simp
schirmer@13688
   784
      ultimately show ?thesis ..
schirmer@13688
   785
    qed
schirmer@13688
   786
  qed
schirmer@13688
   787
next
berghofe@21765
   788
  case (Inst A P e Q T)
schirmer@13688
   789
  assume valid_e: "G,A|\<Turnstile>\<Colon>{ {Normal P} e-\<succ>
schirmer@13688
   790
               {\<lambda>Val:v:. \<lambda>s.. Q\<leftarrow>In1 (Bool (v \<noteq> Null \<and> G,s\<turnstile>v fits RefT T))} }"
schirmer@13688
   791
  show "G,A|\<Turnstile>\<Colon>{ {Normal P} e InstOf T-\<succ> {Q} }"
schirmer@13688
   792
  proof (rule valid_expr_NormalI)
schirmer@13688
   793
    fix n s0 L accC instT E v s1 Y Z
schirmer@13688
   794
    assume valid_A: "\<forall>t\<in>A. G\<Turnstile>n\<Colon>t"
schirmer@13688
   795
    assume conf_s0: "s0\<Colon>\<preceq>(G,L)"  
schirmer@13688
   796
    assume normal_s0: "normal s0"
schirmer@13688
   797
    assume wt: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>e InstOf T\<Colon>-instT"
schirmer@13688
   798
    assume da: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>dom (locals (store s0))\<guillemotright>\<langle>e InstOf T\<rangle>\<^sub>e\<guillemotright> E"
schirmer@13688
   799
    assume eval: "G\<turnstile>s0 \<midarrow>e InstOf T-\<succ>v\<midarrow>n\<rightarrow> s1"
schirmer@13688
   800
    assume P: "(Normal P) Y s0 Z"
schirmer@13688
   801
    show "Q \<lfloor>v\<rfloor>\<^sub>e s1 Z \<and> s1\<Colon>\<preceq>(G, L)"
schirmer@13688
   802
    proof -
schirmer@13688
   803
      from wt obtain eT where 
schirmer@13688
   804
	wt_e: "\<lparr>prg = G, cls = accC, lcl = L\<rparr>\<turnstile>e\<Colon>-eT" 
schirmer@13688
   805
	by cases simp
schirmer@13688
   806
      from da obtain
schirmer@13688
   807
	da_e: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile> dom (locals (store s0)) \<guillemotright>\<langle>e\<rangle>\<^sub>e\<guillemotright> E"
schirmer@13688
   808
	by cases simp
schirmer@13688
   809
      from eval obtain a where
schirmer@13688
   810
	eval_e: "G\<turnstile>s0 \<midarrow>e-\<succ>a\<midarrow>n\<rightarrow> s1" and
schirmer@13688
   811
        v: "v = Bool (a \<noteq> Null \<and> G,store s1\<turnstile>a fits RefT T)"
schirmer@13688
   812
	using normal_s0 by (fastsimp elim: evaln_elim_cases)
schirmer@13688
   813
      from valid_e P valid_A conf_s0 eval_e wt_e da_e
schirmer@13688
   814
      have "(\<lambda>Val:v:. \<lambda>s.. Q\<leftarrow>In1 (Bool (v \<noteq> Null \<and> G,s\<turnstile>v fits RefT T))) 
schirmer@13688
   815
              \<lfloor>a\<rfloor>\<^sub>e s1 Z"
schirmer@13688
   816
	by (rule validE)
schirmer@13688
   817
      with v have "Q \<lfloor>v\<rfloor>\<^sub>e s1 Z"
schirmer@13688
   818
	by simp
schirmer@13688
   819
      moreover
schirmer@13688
   820
      from eval wt da conf_s0 wf
schirmer@13688
   821
      have "s1\<Colon>\<preceq>(G, L)"
schirmer@13688
   822
	by (rule evaln_type_sound [elim_format]) simp
schirmer@13688
   823
      ultimately show ?thesis ..
schirmer@13688
   824
    qed
schirmer@13688
   825
  qed
schirmer@13688
   826
next
schirmer@13688
   827
  case (Lit A P v)
schirmer@13688
   828
  show "G,A|\<Turnstile>\<Colon>{ {Normal (P\<leftarrow>In1 v)} Lit v-\<succ> {P} }"
schirmer@13688
   829
  proof (rule valid_expr_NormalI)
schirmer@13688
   830
    fix n L s0 s1 v'  Y Z
schirmer@13688
   831
    assume conf_s0: "s0\<Colon>\<preceq>(G, L)"
schirmer@13688
   832
    assume normal_s0: " normal s0"
schirmer@13688
   833
    assume eval: "G\<turnstile>s0 \<midarrow>Lit v-\<succ>v'\<midarrow>n\<rightarrow> s1"
schirmer@13688
   834
    assume P: "(Normal (P\<leftarrow>In1 v)) Y s0 Z"
schirmer@13688
   835
    show "P \<lfloor>v'\<rfloor>\<^sub>e s1 Z \<and> s1\<Colon>\<preceq>(G, L)"
schirmer@13688
   836
    proof -
schirmer@13688
   837
      from eval have "s1=s0" and  "v'=v"
schirmer@13688
   838
	using normal_s0 by (auto elim: evaln_elim_cases)
schirmer@13688
   839
      with P conf_s0 show ?thesis by simp
schirmer@13688
   840
    qed
schirmer@13688
   841
  qed
schirmer@13688
   842
next
berghofe@21765
   843
  case (UnOp A P e Q unop)
schirmer@13688
   844
  assume valid_e: "G,A|\<Turnstile>\<Colon>{ {Normal P}e-\<succ>{\<lambda>Val:v:. Q\<leftarrow>In1 (eval_unop unop v)} }"
schirmer@13688
   845
  show "G,A|\<Turnstile>\<Colon>{ {Normal P} UnOp unop e-\<succ> {Q} }"
schirmer@13688
   846
  proof (rule valid_expr_NormalI)
schirmer@13688
   847
    fix n s0 L accC T E v s1 Y Z
schirmer@13688
   848
    assume valid_A: "\<forall>t\<in>A. G\<Turnstile>n\<Colon>t"
schirmer@13688
   849
    assume conf_s0: "s0\<Colon>\<preceq>(G,L)"  
schirmer@13688
   850
    assume normal_s0: "normal s0"
schirmer@13688
   851
    assume wt: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>UnOp unop e\<Colon>-T"
schirmer@13688
   852
    assume da: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>dom (locals (store s0))\<guillemotright>\<langle>UnOp unop e\<rangle>\<^sub>e\<guillemotright>E"
schirmer@13688
   853
    assume eval: "G\<turnstile>s0 \<midarrow>UnOp unop e-\<succ>v\<midarrow>n\<rightarrow> s1"
schirmer@13688
   854
    assume P: "(Normal P) Y s0 Z"
schirmer@13688
   855
    show "Q \<lfloor>v\<rfloor>\<^sub>e s1 Z \<and> s1\<Colon>\<preceq>(G, L)"
schirmer@13688
   856
    proof -
schirmer@13688
   857
      from wt obtain eT where 
schirmer@13688
   858
	wt_e: "\<lparr>prg = G, cls = accC, lcl = L\<rparr>\<turnstile>e\<Colon>-eT" 
schirmer@13688
   859
	by cases simp
schirmer@13688
   860
      from da obtain
schirmer@13688
   861
	da_e: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile> dom (locals (store s0)) \<guillemotright>\<langle>e\<rangle>\<^sub>e\<guillemotright> E"
schirmer@13688
   862
	by cases simp
schirmer@13688
   863
      from eval obtain ve where
schirmer@13688
   864
	eval_e: "G\<turnstile>s0 \<midarrow>e-\<succ>ve\<midarrow>n\<rightarrow> s1" and
schirmer@13688
   865
        v: "v = eval_unop unop ve"
schirmer@13688
   866
	using normal_s0 by (fastsimp elim: evaln_elim_cases)
schirmer@13688
   867
      from valid_e P valid_A conf_s0 eval_e wt_e da_e
schirmer@13688
   868
      have "(\<lambda>Val:v:. Q\<leftarrow>In1 (eval_unop unop v)) \<lfloor>ve\<rfloor>\<^sub>e s1 Z"
schirmer@13688
   869
	by (rule validE)
schirmer@13688
   870
      with v have "Q \<lfloor>v\<rfloor>\<^sub>e s1 Z"
schirmer@13688
   871
	by simp
schirmer@13688
   872
      moreover
schirmer@13688
   873
      from eval wt da conf_s0 wf
schirmer@13688
   874
      have "s1\<Colon>\<preceq>(G, L)"
schirmer@13688
   875
	by (rule evaln_type_sound [elim_format]) simp
schirmer@13688
   876
      ultimately show ?thesis ..
schirmer@13688
   877
    qed
schirmer@13688
   878
  qed
schirmer@13688
   879
next
berghofe@21765
   880
  case (BinOp A P e1 Q binop e2 R)
schirmer@13688
   881
  assume valid_e1: "G,A|\<Turnstile>\<Colon>{ {Normal P} e1-\<succ> {Q} }" 
schirmer@13688
   882
  have valid_e2: "\<And> v1.  G,A|\<Turnstile>\<Colon>{ {Q\<leftarrow>In1 v1}
schirmer@13688
   883
              (if need_second_arg binop v1 then In1l e2 else In1r Skip)\<succ>
schirmer@13688
   884
              {\<lambda>Val:v2:. R\<leftarrow>In1 (eval_binop binop v1 v2)} }"
schirmer@13688
   885
    using BinOp.hyps by simp
schirmer@13688
   886
  show "G,A|\<Turnstile>\<Colon>{ {Normal P} BinOp binop e1 e2-\<succ> {R} }"
schirmer@13688
   887
  proof (rule valid_expr_NormalI)
schirmer@13688
   888
    fix n s0 L accC T E v s2 Y Z
schirmer@13688
   889
    assume valid_A: "\<forall>t\<in>A. G\<Turnstile>n\<Colon>t"
schirmer@13688
   890
    assume conf_s0: "s0\<Colon>\<preceq>(G,L)"  
schirmer@13688
   891
    assume normal_s0: "normal s0"
schirmer@13688
   892
    assume wt: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>BinOp binop e1 e2\<Colon>-T"
schirmer@13688
   893
    assume da: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>
schirmer@13688
   894
                  \<turnstile>dom (locals (store s0)) \<guillemotright>\<langle>BinOp binop e1 e2\<rangle>\<^sub>e\<guillemotright> E"
schirmer@13688
   895
    assume eval: "G\<turnstile>s0 \<midarrow>BinOp binop e1 e2-\<succ>v\<midarrow>n\<rightarrow> s2"
schirmer@13688
   896
    assume P: "(Normal P) Y s0 Z"
schirmer@13688
   897
    show "R \<lfloor>v\<rfloor>\<^sub>e s2 Z \<and> s2\<Colon>\<preceq>(G, L)"
schirmer@13688
   898
    proof -
schirmer@13688
   899
      from wt obtain e1T e2T where
schirmer@13688
   900
        wt_e1: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>e1\<Colon>-e1T" and
schirmer@13688
   901
        wt_e2: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>e2\<Colon>-e2T" and
schirmer@13688
   902
	wt_binop: "wt_binop G binop e1T e2T" 
schirmer@13688
   903
	by cases simp
schirmer@13688
   904
      have wt_Skip: "\<lparr>prg = G, cls = accC, lcl = L\<rparr>\<turnstile>Skip\<Colon>\<surd>"
schirmer@13688
   905
	by simp
schirmer@13688
   906
      (*
schirmer@13688
   907
      obtain S where
schirmer@13688
   908
	daSkip: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>
schirmer@13688
   909
                   \<turnstile> dom (locals (store s1)) \<guillemotright>In1r Skip\<guillemotright> S"
schirmer@13688
   910
	by (auto intro: da_Skip [simplified] assigned.select_convs) *)
schirmer@13688
   911
      from da obtain E1 where
schirmer@13688
   912
	da_e1: "\<lparr>prg=G,cls=accC,lcl=L\<rparr> \<turnstile> dom (locals (store s0)) \<guillemotright>\<langle>e1\<rangle>\<^sub>e\<guillemotright> E1"
schirmer@13688
   913
	by cases simp+
schirmer@13688
   914
      from eval obtain v1 s1 v2 where
schirmer@13688
   915
	eval_e1: "G\<turnstile>s0 \<midarrow>e1-\<succ>v1\<midarrow>n\<rightarrow> s1" and
schirmer@13688
   916
	eval_e2: "G\<turnstile>s1 \<midarrow>(if need_second_arg binop v1 then \<langle>e2\<rangle>\<^sub>e else \<langle>Skip\<rangle>\<^sub>s)
schirmer@13688
   917
                        \<succ>\<midarrow>n\<rightarrow> (\<lfloor>v2\<rfloor>\<^sub>e, s2)" and
schirmer@13688
   918
        v: "v=eval_binop binop v1 v2"
schirmer@13688
   919
	using normal_s0 by (fastsimp elim: evaln_elim_cases)
schirmer@13688
   920
      from valid_e1 P valid_A conf_s0 eval_e1 wt_e1 da_e1
schirmer@13688
   921
      obtain Q: "Q \<lfloor>v1\<rfloor>\<^sub>e s1 Z" and conf_s1: "s1\<Colon>\<preceq>(G,L)"
schirmer@13688
   922
	by (rule validE)
schirmer@13688
   923
      from Q have Q': "\<And> v. (Q\<leftarrow>In1 v1) v s1 Z"
schirmer@13688
   924
	by simp
schirmer@13688
   925
      have "(\<lambda>Val:v2:. R\<leftarrow>In1 (eval_binop binop v1 v2)) \<lfloor>v2\<rfloor>\<^sub>e s2 Z"
schirmer@13688
   926
      proof (cases "normal s1")
schirmer@13688
   927
	case True
schirmer@13688
   928
	from eval_e1 wt_e1 da_e1 conf_s0 wf
schirmer@13688
   929
	have conf_v1: "G,store s1\<turnstile>v1\<Colon>\<preceq>e1T" 
schirmer@13688
   930
	  by (rule evaln_type_sound [elim_format]) (insert True,simp)
schirmer@13688
   931
	from eval_e1 
schirmer@13688
   932
	have "G\<turnstile>s0 \<midarrow>e1-\<succ>v1\<rightarrow> s1"
schirmer@13688
   933
	  by (rule evaln_eval)
schirmer@13688
   934
	from da wt_e1 wt_e2 wt_binop conf_s0 True this conf_v1 wf
schirmer@13688
   935
	obtain E2 where
schirmer@13688
   936
	  da_e2: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile> dom (locals (store s1)) 
schirmer@13688
   937
                   \<guillemotright>(if need_second_arg binop v1 then \<langle>e2\<rangle>\<^sub>e else \<langle>Skip\<rangle>\<^sub>s)\<guillemotright> E2"
nipkow@17589
   938
	  by (rule da_e2_BinOp [elim_format]) iprover
schirmer@13688
   939
	from wt_e2 wt_Skip obtain T2 
schirmer@13688
   940
	  where "\<lparr>prg=G,cls=accC,lcl=L\<rparr>
schirmer@13688
   941
                  \<turnstile>(if need_second_arg binop v1 then \<langle>e2\<rangle>\<^sub>e else \<langle>Skip\<rangle>\<^sub>s)\<Colon>T2"
schirmer@13688
   942
	  by (cases "need_second_arg binop v1") auto
schirmer@13688
   943
	note ve=validE [OF valid_e2,OF  Q' valid_A conf_s1 eval_e2 this da_e2]
schirmer@13688
   944
	(* chaining Q', without extra OF causes unification error *)
schirmer@13688
   945
	thus ?thesis
schirmer@13688
   946
	  by (rule ve)
schirmer@13688
   947
      next
schirmer@13688
   948
	case False
schirmer@13688
   949
	note ve=validE [OF valid_e2,OF Q' valid_A conf_s1 eval_e2]
schirmer@13688
   950
	with False show ?thesis
nipkow@17589
   951
	  by iprover
schirmer@13688
   952
      qed
schirmer@13688
   953
      with v have "R \<lfloor>v\<rfloor>\<^sub>e s2 Z"
schirmer@13688
   954
	by simp
schirmer@13688
   955
      moreover
schirmer@13688
   956
      from eval wt da conf_s0 wf
schirmer@13688
   957
      have "s2\<Colon>\<preceq>(G, L)"
schirmer@13688
   958
	by (rule evaln_type_sound [elim_format]) simp
schirmer@13688
   959
      ultimately show ?thesis ..
schirmer@13688
   960
    qed
schirmer@13688
   961
  qed
schirmer@13688
   962
next
schirmer@13688
   963
  case (Super A P)
schirmer@13688
   964
  show "G,A|\<Turnstile>\<Colon>{ {Normal (\<lambda>s.. P\<leftarrow>In1 (val_this s))} Super-\<succ> {P} }"
schirmer@13688
   965
  proof (rule valid_expr_NormalI)
schirmer@13688
   966
    fix n L s0 s1 v  Y Z
schirmer@13688
   967
    assume conf_s0: "s0\<Colon>\<preceq>(G, L)"
schirmer@13688
   968
    assume normal_s0: " normal s0"
schirmer@13688
   969
    assume eval: "G\<turnstile>s0 \<midarrow>Super-\<succ>v\<midarrow>n\<rightarrow> s1"
schirmer@13688
   970
    assume P: "(Normal (\<lambda>s.. P\<leftarrow>In1 (val_this s))) Y s0 Z"
schirmer@13688
   971
    show "P \<lfloor>v\<rfloor>\<^sub>e s1 Z \<and> s1\<Colon>\<preceq>(G, L)"
schirmer@13688
   972
    proof -
schirmer@13688
   973
      from eval have "s1=s0" and  "v=val_this (store s0)"
schirmer@13688
   974
	using normal_s0 by (auto elim: evaln_elim_cases)
schirmer@13688
   975
      with P conf_s0 show ?thesis by simp
schirmer@13688
   976
    qed
schirmer@13688
   977
  qed
schirmer@13688
   978
next
berghofe@21765
   979
  case (Acc A P var Q)
wenzelm@23350
   980
  note valid_var = `G,A|\<Turnstile>\<Colon>{ {Normal P} var=\<succ> {\<lambda>Var:(v, f):. Q\<leftarrow>In1 v} }`
schirmer@13688
   981
  show "G,A|\<Turnstile>\<Colon>{ {Normal P} Acc var-\<succ> {Q} }"
schirmer@13688
   982
  proof (rule valid_expr_NormalI)
schirmer@13688
   983
    fix n s0 L accC T E v s1 Y Z
schirmer@13688
   984
    assume valid_A: "\<forall>t\<in>A. G\<Turnstile>n\<Colon>t"
schirmer@13688
   985
    assume conf_s0: "s0\<Colon>\<preceq>(G,L)"  
schirmer@13688
   986
    assume normal_s0: "normal s0"
schirmer@13688
   987
    assume wt: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>Acc var\<Colon>-T"
schirmer@13688
   988
    assume da: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>dom (locals (store s0))\<guillemotright>\<langle>Acc var\<rangle>\<^sub>e\<guillemotright>E"
schirmer@13688
   989
    assume eval: "G\<turnstile>s0 \<midarrow>Acc var-\<succ>v\<midarrow>n\<rightarrow> s1"
schirmer@13688
   990
    assume P: "(Normal P) Y s0 Z"
schirmer@13688
   991
    show "Q \<lfloor>v\<rfloor>\<^sub>e s1 Z \<and> s1\<Colon>\<preceq>(G, L)"
schirmer@13688
   992
    proof -
schirmer@13688
   993
      from wt obtain 
schirmer@13688
   994
	wt_var: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>var\<Colon>=T" 
schirmer@13688
   995
	by cases simp
schirmer@13688
   996
      from da obtain V where 
schirmer@13688
   997
	da_var: "\<lparr>prg=G,cls=accC,lcl=L\<rparr> \<turnstile> dom (locals (store s0)) \<guillemotright>\<langle>var\<rangle>\<^sub>v\<guillemotright> V"
schirmer@13688
   998
	by (cases "\<exists> n. var=LVar n") (insert da.LVar,auto elim!: da_elim_cases)
schirmer@13688
   999
      from eval obtain w upd where
schirmer@13688
  1000
	eval_var: "G\<turnstile>s0 \<midarrow>var=\<succ>(v, upd)\<midarrow>n\<rightarrow> s1"
schirmer@13688
  1001
	using normal_s0 by (fastsimp elim: evaln_elim_cases)
schirmer@13688
  1002
      from valid_var P valid_A conf_s0 eval_var wt_var da_var
schirmer@13688
  1003
      have "(\<lambda>Var:(v, f):. Q\<leftarrow>In1 v) \<lfloor>(v, upd)\<rfloor>\<^sub>v s1 Z"
schirmer@13688
  1004
	by (rule validE)
schirmer@13688
  1005
      then have "Q \<lfloor>v\<rfloor>\<^sub>e s1 Z"
schirmer@13688
  1006
	by simp
schirmer@13688
  1007
      moreover
schirmer@13688
  1008
      from eval wt da conf_s0 wf
schirmer@13688
  1009
      have "s1\<Colon>\<preceq>(G, L)"
schirmer@13688
  1010
	by (rule evaln_type_sound [elim_format]) simp
schirmer@13688
  1011
      ultimately show ?thesis ..
schirmer@13688
  1012
    qed
schirmer@13688
  1013
  qed
schirmer@13688
  1014
next
berghofe@21765
  1015
  case (Ass A P var Q e R)
wenzelm@23350
  1016
  note valid_var = `G,A|\<Turnstile>\<Colon>{ {Normal P} var=\<succ> {Q} }`
schirmer@13688
  1017
  have valid_e: "\<And> vf. 
schirmer@13688
  1018
                  G,A|\<Turnstile>\<Colon>{ {Q\<leftarrow>In2 vf} e-\<succ> {\<lambda>Val:v:. assign (snd vf) v .; R} }"
schirmer@13688
  1019
    using Ass.hyps by simp
schirmer@13688
  1020
  show "G,A|\<Turnstile>\<Colon>{ {Normal P} var:=e-\<succ> {R} }"
schirmer@13688
  1021
  proof (rule valid_expr_NormalI)
schirmer@13688
  1022
    fix n s0 L accC T E v s3 Y Z
schirmer@13688
  1023
    assume valid_A: "\<forall>t\<in>A. G\<Turnstile>n\<Colon>t"
schirmer@13688
  1024
    assume conf_s0: "s0\<Colon>\<preceq>(G,L)"  
schirmer@13688
  1025
    assume normal_s0: "normal s0"
schirmer@13688
  1026
    assume wt: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>var:=e\<Colon>-T"
schirmer@13688
  1027
    assume da: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>dom (locals (store s0))\<guillemotright>\<langle>var:=e\<rangle>\<^sub>e\<guillemotright>E"
schirmer@13688
  1028
    assume eval: "G\<turnstile>s0 \<midarrow>var:=e-\<succ>v\<midarrow>n\<rightarrow> s3"
schirmer@13688
  1029
    assume P: "(Normal P) Y s0 Z"
schirmer@13688
  1030
    show "R \<lfloor>v\<rfloor>\<^sub>e s3 Z \<and> s3\<Colon>\<preceq>(G, L)"
schirmer@13688
  1031
    proof -
schirmer@13688
  1032
      from wt obtain varT  where
schirmer@13688
  1033
	wt_var: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>var\<Colon>=varT" and
schirmer@13688
  1034
	wt_e: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>e\<Colon>-T" 
schirmer@13688
  1035
	by cases simp
schirmer@13688
  1036
      from eval obtain w upd s1 s2 where
schirmer@13688
  1037
	eval_var: "G\<turnstile>s0 \<midarrow>var=\<succ>(w, upd)\<midarrow>n\<rightarrow> s1" and
schirmer@13688
  1038
        eval_e: "G\<turnstile>s1 \<midarrow>e-\<succ>v\<midarrow>n\<rightarrow> s2" and
schirmer@13688
  1039
	s3: "s3=assign upd v s2"
schirmer@13688
  1040
	using normal_s0 by (auto elim: evaln_elim_cases)
schirmer@13688
  1041
      have "R \<lfloor>v\<rfloor>\<^sub>e s3 Z"
schirmer@13688
  1042
      proof (cases "\<exists> vn. var = LVar vn")
schirmer@13688
  1043
	case False
schirmer@13688
  1044
	with da obtain V where
schirmer@13688
  1045
	  da_var: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>
schirmer@13688
  1046
                      \<turnstile> dom (locals (store s0)) \<guillemotright>\<langle>var\<rangle>\<^sub>v\<guillemotright> V" and
schirmer@13688
  1047
	  da_e:   "\<lparr>prg=G,cls=accC,lcl=L\<rparr> \<turnstile> nrm V \<guillemotright>\<langle>e\<rangle>\<^sub>e\<guillemotright> E"
schirmer@13688
  1048
	  by cases simp+
schirmer@13688
  1049
	from valid_var P valid_A conf_s0 eval_var wt_var da_var
schirmer@13688
  1050
	obtain Q: "Q \<lfloor>(w,upd)\<rfloor>\<^sub>v s1 Z" and conf_s1: "s1\<Colon>\<preceq>(G,L)"  
schirmer@13688
  1051
	  by (rule validE) 
schirmer@13688
  1052
	hence Q': "\<And> v. (Q\<leftarrow>In2 (w,upd)) v s1 Z"
schirmer@13688
  1053
	  by simp
schirmer@13688
  1054
	have "(\<lambda>Val:v:. assign (snd (w,upd)) v .; R) \<lfloor>v\<rfloor>\<^sub>e s2 Z"
schirmer@13688
  1055
	proof (cases "normal s1")
schirmer@13688
  1056
	  case True
schirmer@13688
  1057
	  obtain E' where 
schirmer@13688
  1058
	    da_e': "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile> dom (locals (store s1)) \<guillemotright>\<langle>e\<rangle>\<^sub>e\<guillemotright> E'"
schirmer@13688
  1059
	  proof -
schirmer@13688
  1060
	    from eval_var wt_var da_var wf True
schirmer@13688
  1061
	    have "nrm V \<subseteq>  dom (locals (store s1))"
nipkow@17589
  1062
	      by (cases rule: da_good_approx_evalnE) iprover
schirmer@13688
  1063
	    with da_e show ?thesis
schirmer@13688
  1064
	      by (rule da_weakenE) 
schirmer@13688
  1065
	  qed
schirmer@13688
  1066
	  note ve=validE [OF valid_e,OF Q' valid_A conf_s1 eval_e wt_e da_e']
schirmer@13688
  1067
	  show ?thesis
schirmer@13688
  1068
	    by (rule ve)
schirmer@13688
  1069
	next
schirmer@13688
  1070
	  case False
schirmer@13688
  1071
	  note ve=validE [OF valid_e,OF Q' valid_A conf_s1 eval_e]
schirmer@13688
  1072
	  with False show ?thesis
nipkow@17589
  1073
	    by iprover
schirmer@13688
  1074
	qed
schirmer@13688
  1075
	with s3 show "R \<lfloor>v\<rfloor>\<^sub>e s3 Z"
schirmer@13688
  1076
	  by simp
schirmer@13688
  1077
      next
schirmer@13688
  1078
	case True
schirmer@13688
  1079
	then obtain vn where 
schirmer@13688
  1080
	  vn: "var = LVar vn" 
schirmer@13688
  1081
	  by auto
schirmer@13688
  1082
	with da obtain E where
schirmer@13688
  1083
	    da_e:   "\<lparr>prg=G,cls=accC,lcl=L\<rparr> \<turnstile> dom (locals (store s0)) \<guillemotright>\<langle>e\<rangle>\<^sub>e\<guillemotright> E"
schirmer@13688
  1084
	  by cases simp+
schirmer@13688
  1085
	from da.LVar vn obtain  V where
schirmer@13688
  1086
	  da_var: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>
schirmer@13688
  1087
                      \<turnstile> dom (locals (store s0)) \<guillemotright>\<langle>var\<rangle>\<^sub>v\<guillemotright> V"
schirmer@13688
  1088
	  by auto
schirmer@13688
  1089
	from valid_var P valid_A conf_s0 eval_var wt_var da_var
schirmer@13688
  1090
	obtain Q: "Q \<lfloor>(w,upd)\<rfloor>\<^sub>v s1 Z" and conf_s1: "s1\<Colon>\<preceq>(G,L)"  
schirmer@13688
  1091
	  by (rule validE) 
schirmer@13688
  1092
	hence Q': "\<And> v. (Q\<leftarrow>In2 (w,upd)) v s1 Z"
schirmer@13688
  1093
	  by simp
schirmer@13688
  1094
	have "(\<lambda>Val:v:. assign (snd (w,upd)) v .; R) \<lfloor>v\<rfloor>\<^sub>e s2 Z"
schirmer@13688
  1095
	proof (cases "normal s1")
schirmer@13688
  1096
	  case True
schirmer@13688
  1097
	  obtain E' where
schirmer@13688
  1098
	    da_e': "\<lparr>prg=G,cls=accC,lcl=L\<rparr>
schirmer@13688
  1099
                       \<turnstile> dom (locals (store s1)) \<guillemotright>\<langle>e\<rangle>\<^sub>e\<guillemotright> E'"
schirmer@13688
  1100
	  proof -
schirmer@13688
  1101
	    from eval_var
schirmer@13688
  1102
	    have "dom (locals (store s0)) \<subseteq> dom (locals (store (s1)))"
schirmer@13688
  1103
	      by (rule dom_locals_evaln_mono_elim)
schirmer@13688
  1104
	    with da_e show ?thesis
schirmer@13688
  1105
	      by (rule da_weakenE)
schirmer@13688
  1106
	  qed
schirmer@13688
  1107
	  note ve=validE [OF valid_e,OF Q' valid_A conf_s1 eval_e wt_e da_e']
schirmer@13688
  1108
	  show ?thesis
schirmer@13688
  1109
	    by (rule ve)
schirmer@13688
  1110
	next
schirmer@13688
  1111
	  case False
schirmer@13688
  1112
	  note ve=validE [OF valid_e,OF Q' valid_A conf_s1 eval_e]
schirmer@13688
  1113
	  with False show ?thesis
nipkow@17589
  1114
	    by iprover
schirmer@13688
  1115
	qed
schirmer@13688
  1116
	with s3 show "R \<lfloor>v\<rfloor>\<^sub>e s3 Z"
schirmer@13688
  1117
	  by simp
schirmer@13688
  1118
      qed
schirmer@13688
  1119
      moreover
schirmer@13688
  1120
      from eval wt da conf_s0 wf
schirmer@13688
  1121
      have "s3\<Colon>\<preceq>(G, L)"
schirmer@13688
  1122
	by (rule evaln_type_sound [elim_format]) simp
schirmer@13688
  1123
      ultimately show ?thesis ..
schirmer@13688
  1124
    qed
schirmer@13688
  1125
  qed
schirmer@13688
  1126
next
berghofe@21765
  1127
  case (Cond A P e0 P' e1 e2 Q)
wenzelm@23350
  1128
  note valid_e0 = `G,A|\<Turnstile>\<Colon>{ {Normal P} e0-\<succ> {P'} }`
schirmer@13688
  1129
  have valid_then_else:"\<And> b.  G,A|\<Turnstile>\<Colon>{ {P'\<leftarrow>=b} (if b then e1 else e2)-\<succ> {Q} }"
schirmer@13688
  1130
    using Cond.hyps by simp
schirmer@13688
  1131
  show "G,A|\<Turnstile>\<Colon>{ {Normal P} e0 ? e1 : e2-\<succ> {Q} }"
schirmer@13688
  1132
  proof (rule valid_expr_NormalI)
schirmer@13688
  1133
    fix n s0 L accC T E v s2 Y Z
schirmer@13688
  1134
    assume valid_A: "\<forall>t\<in>A. G\<Turnstile>n\<Colon>t"
schirmer@13688
  1135
    assume conf_s0: "s0\<Colon>\<preceq>(G,L)"  
schirmer@13688
  1136
    assume normal_s0: "normal s0"
schirmer@13688
  1137
    assume wt: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>e0 ? e1 : e2\<Colon>-T"
schirmer@13688
  1138
    assume da: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>dom (locals (store s0))\<guillemotright>\<langle>e0 ? e1:e2\<rangle>\<^sub>e\<guillemotright>E"
schirmer@13688
  1139
    assume eval: "G\<turnstile>s0 \<midarrow>e0 ? e1 : e2-\<succ>v\<midarrow>n\<rightarrow> s2"
schirmer@13688
  1140
    assume P: "(Normal P) Y s0 Z"
schirmer@13688
  1141
    show "Q \<lfloor>v\<rfloor>\<^sub>e s2 Z \<and> s2\<Colon>\<preceq>(G, L)"
schirmer@13688
  1142
    proof -
schirmer@13688
  1143
      from wt obtain T1 T2 where
schirmer@13688
  1144
	wt_e0: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>e0\<Colon>-PrimT Boolean" and
schirmer@13688
  1145
	wt_e1: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>e1\<Colon>-T1" and
schirmer@13688
  1146
	wt_e2: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>e2\<Colon>-T2" 
schirmer@13688
  1147
	by cases simp
schirmer@13688
  1148
      from da obtain E0 E1 E2 where
schirmer@13688
  1149
        da_e0: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile> dom (locals (store s0)) \<guillemotright>\<langle>e0\<rangle>\<^sub>e\<guillemotright> E0" and
schirmer@13688
  1150
        da_e1: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>
schirmer@13688
  1151
                 \<turnstile>(dom (locals (store s0)) \<union> assigns_if True e0)\<guillemotright>\<langle>e1\<rangle>\<^sub>e\<guillemotright> E1" and
schirmer@13688
  1152
        da_e2: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>
schirmer@13688
  1153
                 \<turnstile>(dom (locals (store s0)) \<union> assigns_if False e0)\<guillemotright>\<langle>e2\<rangle>\<^sub>e\<guillemotright> E2"
schirmer@13688
  1154
	by cases simp+
schirmer@13688
  1155
      from eval obtain b s1 where
schirmer@13688
  1156
	eval_e0: "G\<turnstile>s0 \<midarrow>e0-\<succ>b\<midarrow>n\<rightarrow> s1" and
schirmer@13688
  1157
        eval_then_else: "G\<turnstile>s1 \<midarrow>(if the_Bool b then e1 else e2)-\<succ>v\<midarrow>n\<rightarrow> s2"
schirmer@13688
  1158
	using normal_s0 by (fastsimp elim: evaln_elim_cases)
schirmer@13688
  1159
      from valid_e0 P valid_A conf_s0 eval_e0 wt_e0 da_e0
schirmer@13688
  1160
      obtain "P' \<lfloor>b\<rfloor>\<^sub>e s1 Z" and conf_s1: "s1\<Colon>\<preceq>(G,L)"  
schirmer@13688
  1161
	by (rule validE)
schirmer@13688
  1162
      hence P': "\<And> v. (P'\<leftarrow>=(the_Bool b)) v s1 Z"
schirmer@13688
  1163
	by (cases "normal s1") auto
schirmer@13688
  1164
      have "Q \<lfloor>v\<rfloor>\<^sub>e s2 Z"
schirmer@13688
  1165
      proof (cases "normal s1")
schirmer@13688
  1166
	case True
schirmer@13688
  1167
	note normal_s1=this
schirmer@13688
  1168
	from wt_e1 wt_e2 obtain T' where
schirmer@13688
  1169
	  wt_then_else: 
schirmer@13688
  1170
	  "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>(if the_Bool b then e1 else e2)\<Colon>-T'"
schirmer@13688
  1171
	  by (cases "the_Bool b") simp+
schirmer@13688
  1172
	have s0_s1: "dom (locals (store s0)) 
schirmer@13688
  1173
                      \<union> assigns_if (the_Bool b) e0 \<subseteq> dom (locals (store s1))"
schirmer@13688
  1174
	proof -
schirmer@13688
  1175
	  from eval_e0 
schirmer@13688
  1176
	  have eval_e0': "G\<turnstile>s0 \<midarrow>e0-\<succ>b\<rightarrow> s1"
schirmer@13688
  1177
	    by (rule evaln_eval)
schirmer@13688
  1178
	  hence
schirmer@13688
  1179
	    "dom (locals (store s0)) \<subseteq> dom (locals (store s1))"
schirmer@13688
  1180
	    by (rule dom_locals_eval_mono_elim)
schirmer@13688
  1181
          moreover
schirmer@13688
  1182
	  from eval_e0' True wt_e0 
schirmer@13688
  1183
	  have "assigns_if (the_Bool b) e0 \<subseteq> dom (locals (store s1))"
schirmer@13688
  1184
	    by (rule assigns_if_good_approx') 
schirmer@13688
  1185
	  ultimately show ?thesis by (rule Un_least)
schirmer@13688
  1186
	qed
schirmer@13688
  1187
	obtain E' where
schirmer@13688
  1188
	  da_then_else:
schirmer@13688
  1189
	  "\<lparr>prg=G,cls=accC,lcl=L\<rparr>
schirmer@13688
  1190
              \<turnstile>dom (locals (store s1))\<guillemotright>\<langle>if the_Bool b then e1 else e2\<rangle>\<^sub>e\<guillemotright> E'"
schirmer@13688
  1191
	proof (cases "the_Bool b")
schirmer@13688
  1192
	  case True
schirmer@13688
  1193
	  with that da_e1 s0_s1 show ?thesis
schirmer@13688
  1194
	    by simp (erule da_weakenE,auto)
schirmer@13688
  1195
	next
schirmer@13688
  1196
	  case False
schirmer@13688
  1197
	  with that da_e2 s0_s1 show ?thesis
schirmer@13688
  1198
	    by simp (erule da_weakenE,auto)
schirmer@13688
  1199
	qed
schirmer@13688
  1200
	with valid_then_else P' valid_A conf_s1 eval_then_else wt_then_else
schirmer@13688
  1201
	show ?thesis
schirmer@13688
  1202
	  by (rule validE)
schirmer@13688
  1203
      next
schirmer@13688
  1204
	case False
schirmer@13688
  1205
	with valid_then_else P' valid_A conf_s1 eval_then_else
schirmer@13688
  1206
	show ?thesis
nipkow@17589
  1207
	  by (cases rule: validE) iprover+
schirmer@13688
  1208
      qed
schirmer@13688
  1209
      moreover
schirmer@13688
  1210
      from eval wt da conf_s0 wf
schirmer@13688
  1211
      have "s2\<Colon>\<preceq>(G, L)"
schirmer@13688
  1212
	by (rule evaln_type_sound [elim_format]) simp
schirmer@13688
  1213
      ultimately show ?thesis ..
schirmer@13688
  1214
    qed
schirmer@13688
  1215
  qed
schirmer@13688
  1216
next
berghofe@21765
  1217
  case (Call A P e Q args R mode statT mn pTs' S accC')
wenzelm@23350
  1218
  note valid_e = `G,A|\<Turnstile>\<Colon>{ {Normal P} e-\<succ> {Q} }`
schirmer@13688
  1219
  have valid_args: "\<And> a. G,A|\<Turnstile>\<Colon>{ {Q\<leftarrow>In1 a} args\<doteq>\<succ> {R a} }"
schirmer@13688
  1220
    using Call.hyps by simp
schirmer@13688
  1221
  have valid_methd: "\<And> a vs invC declC l.
schirmer@13688
  1222
        G,A|\<Turnstile>\<Colon>{ {R a\<leftarrow>In3 vs \<and>.
schirmer@13688
  1223
                 (\<lambda>s. declC =
schirmer@13688
  1224
                    invocation_declclass G mode (store s) a statT
schirmer@13688
  1225
                     \<lparr>name = mn, parTs = pTs'\<rparr> \<and>
schirmer@13688
  1226
                    invC = invocation_class mode (store s) a statT \<and>
schirmer@13688
  1227
                    l = locals (store s)) ;.
schirmer@13688
  1228
                 init_lvars G declC \<lparr>name = mn, parTs = pTs'\<rparr> mode a vs \<and>.
schirmer@13688
  1229
                 (\<lambda>s. normal s \<longrightarrow> G\<turnstile>mode\<rightarrow>invC\<preceq>statT)}
schirmer@13688
  1230
            Methd declC \<lparr>name=mn,parTs=pTs'\<rparr>-\<succ> {set_lvars l .; S} }"
schirmer@13688
  1231
    using Call.hyps by simp
schirmer@13688
  1232
  show "G,A|\<Turnstile>\<Colon>{ {Normal P} {accC',statT,mode}e\<cdot>mn( {pTs'}args)-\<succ> {S} }"
schirmer@13688
  1233
  proof (rule valid_expr_NormalI)
schirmer@13688
  1234
    fix n s0 L accC T E v s5 Y Z
schirmer@13688
  1235
    assume valid_A: "\<forall>t\<in>A. G\<Turnstile>n\<Colon>t"
schirmer@13688
  1236
    assume conf_s0: "s0\<Colon>\<preceq>(G,L)"  
schirmer@13688
  1237
    assume normal_s0: "normal s0"
schirmer@13688
  1238
    assume wt: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>{accC',statT,mode}e\<cdot>mn( {pTs'}args)\<Colon>-T"
schirmer@13688
  1239
    assume da: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>dom (locals (store s0))
schirmer@13688
  1240
                   \<guillemotright>\<langle>{accC',statT,mode}e\<cdot>mn( {pTs'}args)\<rangle>\<^sub>e\<guillemotright> E"
schirmer@13688
  1241
    assume eval: "G\<turnstile>s0 \<midarrow>{accC',statT,mode}e\<cdot>mn( {pTs'}args)-\<succ>v\<midarrow>n\<rightarrow> s5"
schirmer@13688
  1242
    assume P: "(Normal P) Y s0 Z"
schirmer@13688
  1243
    show "S \<lfloor>v\<rfloor>\<^sub>e s5 Z \<and> s5\<Colon>\<preceq>(G, L)"
schirmer@13688
  1244
    proof -
schirmer@13688
  1245
      from wt obtain pTs statDeclT statM where
schirmer@13688
  1246
                 wt_e: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>e\<Colon>-RefT statT" and
schirmer@13688
  1247
              wt_args: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>args\<Colon>\<doteq>pTs" and
schirmer@13688
  1248
                statM: "max_spec G accC statT \<lparr>name=mn,parTs=pTs\<rparr> 
schirmer@13688
  1249
                         = {((statDeclT,statM),pTs')}" and
schirmer@13688
  1250
                 mode: "mode = invmode statM e" and
schirmer@13688
  1251
                    T: "T =(resTy statM)" and
schirmer@13688
  1252
        eq_accC_accC': "accC=accC'"
schirmer@13688
  1253
	by cases fastsimp+
schirmer@13688
  1254
      from da obtain C where
schirmer@13688
  1255
	da_e: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile> (dom (locals (store s0)))\<guillemotright>\<langle>e\<rangle>\<^sub>e\<guillemotright> C" and
schirmer@13688
  1256
	da_args: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile> nrm C \<guillemotright>\<langle>args\<rangle>\<^sub>l\<guillemotright> E" 
schirmer@13688
  1257
	by cases simp
schirmer@13688
  1258
      from eval eq_accC_accC' obtain a s1 vs s2 s3 s3' s4 invDeclC where
schirmer@13688
  1259
	evaln_e: "G\<turnstile>s0 \<midarrow>e-\<succ>a\<midarrow>n\<rightarrow> s1" and
schirmer@13688
  1260
        evaln_args: "G\<turnstile>s1 \<midarrow>args\<doteq>\<succ>vs\<midarrow>n\<rightarrow> s2" and
schirmer@13688
  1261
	invDeclC: "invDeclC = invocation_declclass 
schirmer@13688
  1262
                G mode (store s2) a statT \<lparr>name=mn,parTs=pTs'\<rparr>" and
schirmer@13688
  1263
        s3: "s3 = init_lvars G invDeclC \<lparr>name=mn,parTs=pTs'\<rparr> mode a vs s2" and
schirmer@13688
  1264
        check: "s3' = check_method_access G 
schirmer@13688
  1265
                           accC' statT mode \<lparr>name = mn, parTs = pTs'\<rparr> a s3" and
schirmer@13688
  1266
	evaln_methd:
schirmer@13688
  1267
           "G\<turnstile>s3' \<midarrow>Methd invDeclC  \<lparr>name=mn,parTs=pTs'\<rparr>-\<succ>v\<midarrow>n\<rightarrow> s4" and
schirmer@13688
  1268
        s5: "s5=(set_lvars (locals (store s2))) s4"
schirmer@13688
  1269
	using normal_s0 by (auto elim: evaln_elim_cases)
schirmer@13688
  1270
schirmer@13688
  1271
      from evaln_e
schirmer@13688
  1272
      have eval_e: "G\<turnstile>s0 \<midarrow>e-\<succ>a\<rightarrow> s1"
schirmer@13688
  1273
	by (rule evaln_eval)
schirmer@13688
  1274
      
schirmer@13688
  1275
      from eval_e _ wt_e wf
schirmer@13688
  1276
      have s1_no_return: "abrupt s1 \<noteq> Some (Jump Ret)"
schirmer@13688
  1277
	by (rule eval_expression_no_jump 
schirmer@13688
  1278
                 [where ?Env="\<lparr>prg=G,cls=accC,lcl=L\<rparr>",simplified])
schirmer@13688
  1279
	   (insert normal_s0,auto)
schirmer@13688
  1280
schirmer@13688
  1281
      from valid_e P valid_A conf_s0 evaln_e wt_e da_e
schirmer@13688
  1282
      obtain "Q \<lfloor>a\<rfloor>\<^sub>e s1 Z" and conf_s1: "s1\<Colon>\<preceq>(G,L)"
schirmer@13688
  1283
	by (rule validE)
schirmer@13688
  1284
      hence Q: "\<And> v. (Q\<leftarrow>In1 a) v s1 Z"
schirmer@13688
  1285
	by simp
schirmer@13688
  1286
      obtain 
schirmer@13688
  1287
	R: "(R a) \<lfloor>vs\<rfloor>\<^sub>l s2 Z" and 
schirmer@13688
  1288
	conf_s2: "s2\<Colon>\<preceq>(G,L)" and 
schirmer@13688
  1289
	s2_no_return: "abrupt s2 \<noteq> Some (Jump Ret)"
schirmer@13688
  1290
      proof (cases "normal s1")
schirmer@13688
  1291
	case True
schirmer@13688
  1292
	obtain E' where 
schirmer@13688
  1293
	  da_args':
schirmer@13688
  1294
	  "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile> dom (locals (store s1)) \<guillemotright>\<langle>args\<rangle>\<^sub>l\<guillemotright> E'"
schirmer@13688
  1295
	proof -
schirmer@13688
  1296
	  from evaln_e wt_e da_e wf True
schirmer@13688
  1297
	  have "nrm C \<subseteq>  dom (locals (store s1))"
nipkow@17589
  1298
	    by (cases rule: da_good_approx_evalnE) iprover
schirmer@13688
  1299
	  with da_args show ?thesis
schirmer@13688
  1300
	    by (rule da_weakenE) 
schirmer@13688
  1301
	qed
schirmer@13688
  1302
	with valid_args Q valid_A conf_s1 evaln_args wt_args 
schirmer@13688
  1303
	obtain "(R a) \<lfloor>vs\<rfloor>\<^sub>l s2 Z" "s2\<Colon>\<preceq>(G,L)" 
schirmer@13688
  1304
	  by (rule validE)
schirmer@13688
  1305
	moreover
schirmer@13688
  1306
	from evaln_args
schirmer@13688
  1307
	have e: "G\<turnstile>s1 \<midarrow>args\<doteq>\<succ>vs\<rightarrow> s2"
schirmer@13688
  1308
	  by (rule evaln_eval)
schirmer@13688
  1309
	from this s1_no_return wt_args wf
schirmer@13688
  1310
	have "abrupt s2 \<noteq> Some (Jump Ret)"
schirmer@13688
  1311
	  by (rule eval_expression_list_no_jump 
schirmer@13688
  1312
                 [where ?Env="\<lparr>prg=G,cls=accC,lcl=L\<rparr>",simplified])
schirmer@13688
  1313
	ultimately show ?thesis ..
schirmer@13688
  1314
      next
schirmer@13688
  1315
	case False
schirmer@13688
  1316
	with valid_args Q valid_A conf_s1 evaln_args
schirmer@13688
  1317
	obtain "(R a) \<lfloor>vs\<rfloor>\<^sub>l s2 Z" "s2\<Colon>\<preceq>(G,L)" 
nipkow@17589
  1318
	  by (cases rule: validE) iprover+
schirmer@13688
  1319
	moreover
schirmer@13688
  1320
	from False evaln_args have "s2=s1"
schirmer@13688
  1321
	  by auto
schirmer@13688
  1322
	with s1_no_return have "abrupt s2 \<noteq> Some (Jump Ret)"
schirmer@13688
  1323
	  by simp
schirmer@13688
  1324
	ultimately show ?thesis ..
schirmer@13688
  1325
      qed
schirmer@13688
  1326
schirmer@13688
  1327
      obtain invC where
schirmer@13688
  1328
	invC: "invC = invocation_class mode (store s2) a statT"
schirmer@13688
  1329
	by simp
schirmer@13688
  1330
      with s3
schirmer@13688
  1331
      have invC': "invC = (invocation_class mode (store s3) a statT)"
schirmer@13688
  1332
	by (cases s2,cases mode) (auto simp add: init_lvars_def2 )
schirmer@13688
  1333
      obtain l where
schirmer@13688
  1334
	l: "l = locals (store s2)"
schirmer@13688
  1335
	by simp
schirmer@13688
  1336
schirmer@13688
  1337
      from eval wt da conf_s0 wf
schirmer@13688
  1338
      have conf_s5: "s5\<Colon>\<preceq>(G, L)"
schirmer@13688
  1339
	by (rule evaln_type_sound [elim_format]) simp
schirmer@13688
  1340
      let "PROP ?R" = "\<And> v.
schirmer@13688
  1341
             (R a\<leftarrow>In3 vs \<and>.
schirmer@13688
  1342
                 (\<lambda>s. invDeclC = invocation_declclass G mode (store s) a statT
schirmer@13688
  1343
                                  \<lparr>name = mn, parTs = pTs'\<rparr> \<and>
schirmer@13688
  1344
                       invC = invocation_class mode (store s) a statT \<and>
schirmer@13688
  1345
                          l = locals (store s)) ;.
schirmer@13688
  1346
                  init_lvars G invDeclC \<lparr>name = mn, parTs = pTs'\<rparr> mode a vs \<and>.
schirmer@13688
  1347
                  (\<lambda>s. normal s \<longrightarrow> G\<turnstile>mode\<rightarrow>invC\<preceq>statT)
schirmer@13688
  1348
               ) v s3' Z"
schirmer@13688
  1349
      {
schirmer@13688
  1350
	assume abrupt_s3: "\<not> normal s3"
schirmer@13688
  1351
	have "S \<lfloor>v\<rfloor>\<^sub>e s5 Z"
schirmer@13688
  1352
	proof -
schirmer@13688
  1353
	  from abrupt_s3 check have eq_s3'_s3: "s3'=s3"
schirmer@13688
  1354
	    by (auto simp add: check_method_access_def Let_def)
schirmer@13688
  1355
	  with R s3 invDeclC invC l abrupt_s3
schirmer@13688
  1356
	  have R': "PROP ?R"
schirmer@13688
  1357
	    by auto
schirmer@13688
  1358
	  have conf_s3': "s3'\<Colon>\<preceq>(G, empty)"
schirmer@13688
  1359
	   (* we need an arbirary environment (here empty) that s2' conforms to
schirmer@13688
  1360
              to apply validE *)
schirmer@13688
  1361
	  proof -
schirmer@13688
  1362
	    from s2_no_return s3
schirmer@13688
  1363
	    have "abrupt s3 \<noteq> Some (Jump Ret)"
schirmer@13688
  1364
	      by (cases s2) (auto simp add: init_lvars_def2 split: split_if_asm)
schirmer@13688
  1365
	    moreover
schirmer@13688
  1366
	    obtain abr2 str2 where s2: "s2=(abr2,str2)"
schirmer@13688
  1367
	      by (cases s2) simp
schirmer@13688
  1368
	    from s3 s2 conf_s2 have "(abrupt s3,str2)\<Colon>\<preceq>(G, L)"
schirmer@13688
  1369
	      by (auto simp add: init_lvars_def2 split: split_if_asm)
schirmer@13688
  1370
	    ultimately show ?thesis
schirmer@13688
  1371
	      using s3 s2 eq_s3'_s3
schirmer@13688
  1372
	      apply (simp add: init_lvars_def2)
schirmer@13688
  1373
	      apply (rule conforms_set_locals [OF _ wlconf_empty])
schirmer@13688
  1374
	      by auto
schirmer@13688
  1375
	  qed
schirmer@13688
  1376
	  from valid_methd R' valid_A conf_s3' evaln_methd abrupt_s3 eq_s3'_s3
schirmer@13688
  1377
	  have "(set_lvars l .; S) \<lfloor>v\<rfloor>\<^sub>e s4 Z"
schirmer@13688
  1378
	    by (cases rule: validE) simp+
schirmer@13688
  1379
	  with s5 l show ?thesis
schirmer@13688
  1380
	    by simp
schirmer@13688
  1381
	qed
schirmer@13688
  1382
      } note abrupt_s3_lemma = this
schirmer@13688
  1383
schirmer@13688
  1384
      have "S \<lfloor>v\<rfloor>\<^sub>e s5 Z"
schirmer@13688
  1385
      proof (cases "normal s2")
schirmer@13688
  1386
	case False
schirmer@13688
  1387
	with s3 have abrupt_s3: "\<not> normal s3"
schirmer@13688
  1388
	  by (cases s2) (simp add: init_lvars_def2)
schirmer@13688
  1389
	thus ?thesis
schirmer@13688
  1390
	  by (rule abrupt_s3_lemma)
schirmer@13688
  1391
      next
schirmer@13688
  1392
	case True
schirmer@13688
  1393
	note normal_s2 = this
schirmer@13688
  1394
	with evaln_args 
schirmer@13688
  1395
	have normal_s1: "normal s1"
schirmer@13688
  1396
	  by (rule evaln_no_abrupt)
schirmer@13688
  1397
	obtain E' where 
schirmer@13688
  1398
	  da_args':
schirmer@13688
  1399
	  "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile> dom (locals (store s1)) \<guillemotright>\<langle>args\<rangle>\<^sub>l\<guillemotright> E'"
schirmer@13688
  1400
	proof -
schirmer@13688
  1401
	  from evaln_e wt_e da_e wf normal_s1
schirmer@13688
  1402
	  have "nrm C \<subseteq>  dom (locals (store s1))"
nipkow@17589
  1403
	    by (cases rule: da_good_approx_evalnE) iprover
schirmer@13688
  1404
	  with da_args show ?thesis
schirmer@13688
  1405
	    by (rule da_weakenE) 
schirmer@13688
  1406
	qed
schirmer@13688
  1407
	from evaln_args
schirmer@13688
  1408
	have eval_args: "G\<turnstile>s1 \<midarrow>args\<doteq>\<succ>vs\<rightarrow> s2"
schirmer@13688
  1409
	  by (rule evaln_eval)
schirmer@13688
  1410
	from evaln_e wt_e da_e conf_s0 wf
schirmer@13688
  1411
	have conf_a: "G, store s1\<turnstile>a\<Colon>\<preceq>RefT statT"
schirmer@13688
  1412
	  by (rule evaln_type_sound [elim_format]) (insert normal_s1,simp)
schirmer@13688
  1413
	with normal_s1 normal_s2 eval_args 
schirmer@13688
  1414
	have conf_a_s2: "G, store s2\<turnstile>a\<Colon>\<preceq>RefT statT"
schirmer@13688
  1415
	  by (auto dest: eval_gext intro: conf_gext)
schirmer@13688
  1416
	from evaln_args wt_args da_args' conf_s1 wf
schirmer@13688
  1417
	have conf_args: "list_all2 (conf G (store s2)) vs pTs"
schirmer@13688
  1418
	  by (rule evaln_type_sound [elim_format]) (insert normal_s2,simp)
schirmer@13688
  1419
	from statM 
schirmer@13688
  1420
	obtain
schirmer@13688
  1421
	  statM': "(statDeclT,statM)\<in>mheads G accC statT \<lparr>name=mn,parTs=pTs'\<rparr>" 
schirmer@13688
  1422
	  and
schirmer@13688
  1423
	  pTs_widen: "G\<turnstile>pTs[\<preceq>]pTs'"
schirmer@13688
  1424
	  by (blast dest: max_spec2mheads)
schirmer@13688
  1425
	show ?thesis
schirmer@13688
  1426
	proof (cases "normal s3")
schirmer@13688
  1427
	  case False
schirmer@13688
  1428
	  thus ?thesis
schirmer@13688
  1429
	    by (rule abrupt_s3_lemma)
schirmer@13688
  1430
	next
schirmer@13688
  1431
	  case True
schirmer@13688
  1432
	  note normal_s3 = this
schirmer@13688
  1433
	  with s3 have notNull: "mode = IntVir \<longrightarrow> a \<noteq> Null"
schirmer@13688
  1434
	    by (cases s2) (auto simp add: init_lvars_def2)
schirmer@13688
  1435
	  from conf_s2 conf_a_s2 wf notNull invC
schirmer@13688
  1436
	  have dynT_prop: "G\<turnstile>mode\<rightarrow>invC\<preceq>statT"
schirmer@13688
  1437
	    by (cases s2) (auto intro: DynT_propI)
schirmer@13688
  1438
schirmer@13688
  1439
	  with wt_e statM' invC mode wf 
schirmer@13688
  1440
	  obtain dynM where 
schirmer@13688
  1441
            dynM: "dynlookup G statT invC  \<lparr>name=mn,parTs=pTs'\<rparr> = Some dynM" and
schirmer@13688
  1442
            acc_dynM: "G \<turnstile>Methd  \<lparr>name=mn,parTs=pTs'\<rparr> dynM 
schirmer@13688
  1443
                            in invC dyn_accessible_from accC"
schirmer@13688
  1444
	    by (force dest!: call_access_ok)
schirmer@13688
  1445
	  with invC' check eq_accC_accC'
schirmer@13688
  1446
	  have eq_s3'_s3: "s3'=s3"
schirmer@13688
  1447
	    by (auto simp add: check_method_access_def Let_def)
schirmer@13688
  1448
	  
schirmer@13688
  1449
	  with dynT_prop R s3 invDeclC invC l 
schirmer@13688
  1450
	  have R': "PROP ?R"
schirmer@13688
  1451
	    by auto
schirmer@12854
  1452
schirmer@13688
  1453
	  from dynT_prop wf wt_e statM' mode invC invDeclC dynM
schirmer@13688
  1454
	  obtain 
schirmer@13688
  1455
            dynM: "dynlookup G statT invC  \<lparr>name=mn,parTs=pTs'\<rparr> = Some dynM" and
schirmer@13688
  1456
	    wf_dynM: "wf_mdecl G invDeclC (\<lparr>name=mn,parTs=pTs'\<rparr>,mthd dynM)" and
schirmer@13688
  1457
	      dynM': "methd G invDeclC \<lparr>name=mn,parTs=pTs'\<rparr> = Some dynM" and
schirmer@13688
  1458
            iscls_invDeclC: "is_class G invDeclC" and
schirmer@13688
  1459
	         invDeclC': "invDeclC = declclass dynM" and
schirmer@13688
  1460
	      invC_widen: "G\<turnstile>invC\<preceq>\<^sub>C invDeclC" and
schirmer@13688
  1461
	     resTy_widen: "G\<turnstile>resTy dynM\<preceq>resTy statM" and
schirmer@13688
  1462
	    is_static_eq: "is_static dynM = is_static statM" and
schirmer@13688
  1463
	    involved_classes_prop:
schirmer@13688
  1464
             "(if invmode statM e = IntVir
schirmer@13688
  1465
               then \<forall>statC. statT = ClassT statC \<longrightarrow> G\<turnstile>invC\<preceq>\<^sub>C statC
schirmer@13688
  1466
               else ((\<exists>statC. statT = ClassT statC \<and> G\<turnstile>statC\<preceq>\<^sub>C invDeclC) \<or>
schirmer@13688
  1467
                     (\<forall>statC. statT \<noteq> ClassT statC \<and> invDeclC = Object)) \<and>
schirmer@13688
  1468
                      statDeclT = ClassT invDeclC)"
schirmer@13688
  1469
	    by (cases rule: DynT_mheadsE) simp
schirmer@13688
  1470
	  obtain L' where 
schirmer@13688
  1471
	    L':"L'=(\<lambda> k. 
schirmer@13688
  1472
                    (case k of
schirmer@13688
  1473
                       EName e
schirmer@13688
  1474
                       \<Rightarrow> (case e of 
schirmer@13688
  1475
                             VNam v 
schirmer@13688
  1476
                             \<Rightarrow>(table_of (lcls (mbody (mthd dynM)))
schirmer@13688
  1477
                                (pars (mthd dynM)[\<mapsto>]pTs')) v
schirmer@13688
  1478
                           | Res \<Rightarrow> Some (resTy dynM))
schirmer@13688
  1479
                     | This \<Rightarrow> if is_static statM 
schirmer@13688
  1480
                               then None else Some (Class invDeclC)))"
schirmer@13688
  1481
	    by simp
schirmer@13688
  1482
	  from wf_dynM [THEN wf_mdeclD1, THEN conjunct1] normal_s2 conf_s2 wt_e
schirmer@13688
  1483
            wf eval_args conf_a mode notNull wf_dynM involved_classes_prop
schirmer@13688
  1484
	  have conf_s3: "s3\<Colon>\<preceq>(G,L')"
schirmer@13688
  1485
	    apply - 
schirmer@13688
  1486
               (* FIXME confomrs_init_lvars should be 
schirmer@13688
  1487
                  adjusted to be more directy applicable *)
schirmer@13688
  1488
	    apply (drule conforms_init_lvars [of G invDeclC 
schirmer@13688
  1489
                    "\<lparr>name=mn,parTs=pTs'\<rparr>" dynM "store s2" vs pTs "abrupt s2" 
schirmer@13688
  1490
                    L statT invC a "(statDeclT,statM)" e])
schirmer@13688
  1491
	    apply (rule wf)
schirmer@13688
  1492
	    apply (rule conf_args)
schirmer@13688
  1493
	    apply (simp add: pTs_widen)
schirmer@13688
  1494
	    apply (cases s2,simp)
schirmer@13688
  1495
	    apply (rule dynM')
schirmer@13688
  1496
	    apply (force dest: ty_expr_is_type)
schirmer@13688
  1497
	    apply (rule invC_widen)
schirmer@13688
  1498
	    apply (force intro: conf_gext dest: eval_gext)
schirmer@13688
  1499
	    apply simp
schirmer@13688
  1500
	    apply simp
schirmer@13688
  1501
	    apply (simp add: invC)
schirmer@13688
  1502
	    apply (simp add: invDeclC)
schirmer@13688
  1503
	    apply (simp add: normal_s2)
schirmer@13688
  1504
	    apply (cases s2, simp add: L' init_lvars_def2 s3
schirmer@13688
  1505
	                     cong add: lname.case_cong ename.case_cong)
schirmer@13688
  1506
	    done
schirmer@13688
  1507
	  with eq_s3'_s3 have conf_s3': "s3'\<Colon>\<preceq>(G,L')" by simp
schirmer@13688
  1508
	  from is_static_eq wf_dynM L'
schirmer@13688
  1509
	  obtain mthdT where
schirmer@13688
  1510
	    "\<lparr>prg=G,cls=invDeclC,lcl=L'\<rparr>
schirmer@13688
  1511
               \<turnstile>Body invDeclC (stmt (mbody (mthd dynM)))\<Colon>-mthdT" and
schirmer@13688
  1512
	    mthdT_widen: "G\<turnstile>mthdT\<preceq>resTy dynM"
schirmer@13688
  1513
	    by - (drule wf_mdecl_bodyD,
schirmer@13688
  1514
                  auto simp add: callee_lcl_def  
schirmer@13688
  1515
                       cong add: lname.case_cong ename.case_cong)
schirmer@13688
  1516
	  with dynM' iscls_invDeclC invDeclC'
schirmer@13688
  1517
	  have
schirmer@13688
  1518
	    wt_methd:
schirmer@13688
  1519
	    "\<lparr>prg=G,cls=invDeclC,lcl=L'\<rparr>
schirmer@13688
  1520
               \<turnstile>(Methd invDeclC \<lparr>name = mn, parTs = pTs'\<rparr>)\<Colon>-mthdT"
schirmer@13688
  1521
	    by (auto intro: wt.Methd)
schirmer@13688
  1522
	  obtain M where 
schirmer@13688
  1523
	    da_methd:
schirmer@13688
  1524
	    "\<lparr>prg=G,cls=invDeclC,lcl=L'\<rparr> 
schirmer@13688
  1525
	       \<turnstile> dom (locals (store s3')) 
schirmer@13688
  1526
                   \<guillemotright>\<langle>Methd invDeclC \<lparr>name=mn,parTs=pTs'\<rparr>\<rangle>\<^sub>e\<guillemotright> M"
schirmer@13688
  1527
	  proof -
schirmer@13688
  1528
	    from wf_dynM
schirmer@13688
  1529
	    obtain M' where
schirmer@13688
  1530
	      da_body: 
schirmer@13688
  1531
	      "\<lparr>prg=G, cls=invDeclC
schirmer@13688
  1532
               ,lcl=callee_lcl invDeclC \<lparr>name = mn, parTs = pTs'\<rparr> (mthd dynM)
schirmer@13688
  1533
               \<rparr> \<turnstile> parameters (mthd dynM) \<guillemotright>\<langle>stmt (mbody (mthd dynM))\<rangle>\<guillemotright> M'" and
schirmer@13688
  1534
              res: "Result \<in> nrm M'"
nipkow@17589
  1535
	      by (rule wf_mdeclE) iprover
schirmer@13688
  1536
	    from da_body is_static_eq L' have
schirmer@13688
  1537
	      "\<lparr>prg=G, cls=invDeclC,lcl=L'\<rparr> 
schirmer@13688
  1538
                 \<turnstile> parameters (mthd dynM) \<guillemotright>\<langle>stmt (mbody (mthd dynM))\<rangle>\<guillemotright> M'"
schirmer@13688
  1539
	      by (simp add: callee_lcl_def  
schirmer@13688
  1540
                  cong add: lname.case_cong ename.case_cong)
schirmer@13688
  1541
	    moreover have "parameters (mthd dynM) \<subseteq>  dom (locals (store s3'))"
schirmer@13688
  1542
	    proof -
schirmer@13688
  1543
	      from is_static_eq 
schirmer@13688
  1544
	      have "(invmode (mthd dynM) e) = (invmode statM e)"
schirmer@13688
  1545
		by (simp add: invmode_def)
schirmer@14030
  1546
	      moreover
schirmer@14030
  1547
	      have "length (pars (mthd dynM)) = length vs" 
schirmer@14030
  1548
	      proof -
schirmer@14030
  1549
		from normal_s2 conf_args
schirmer@14030
  1550
		have "length vs = length pTs"
schirmer@14030
  1551
		  by (simp add: list_all2_def)