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