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