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