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