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