src/HOL/Bali/AxCompl.thy
author Thomas Sewell <thomas.sewell@nicta.com.au>
Wed, 11 Jun 2014 14:24:23 +1000
changeset 58834 74bf65a1910a
parent 49016 c79adcae9869
child 59180 85ec71012df8
permissions -rw-r--r--
Hypsubst preserves equality hypotheses

Fixes included for various theories affected by this change.
wenzelm@12857
     1
(*  Title:      HOL/Bali/AxCompl.thy
schirmer@13688
     2
    Author:     David von Oheimb and Norbert Schirmer
schirmer@12854
     3
*)
schirmer@12854
     4
schirmer@12854
     5
header {*
schirmer@12854
     6
Completeness proof for Axiomatic semantics of Java expressions and statements
schirmer@12854
     7
*}
schirmer@12854
     8
haftmann@16417
     9
theory AxCompl imports AxSem begin
schirmer@12854
    10
schirmer@12854
    11
text {*
schirmer@12854
    12
design issues:
schirmer@12854
    13
\begin{itemize}
schirmer@12854
    14
\item proof structured by Most General Formulas (-> Thomas Kleymann)
schirmer@12854
    15
\end{itemize}
schirmer@12854
    16
*}
schirmer@12925
    17
schirmer@12925
    18
schirmer@12925
    19
schirmer@13688
    20
           
schirmer@12854
    21
section "set of not yet initialzed classes"
schirmer@12854
    22
wenzelm@38219
    23
definition
wenzelm@38219
    24
  nyinitcls :: "prog \<Rightarrow> state \<Rightarrow> qtname set"
wenzelm@38219
    25
  where "nyinitcls G s = {C. is_class G C \<and> \<not> initd C s}"
schirmer@12854
    26
schirmer@12854
    27
lemma nyinitcls_subset_class: "nyinitcls G s \<subseteq> {C. is_class G C}"
schirmer@12854
    28
apply (unfold nyinitcls_def)
schirmer@12854
    29
apply fast
schirmer@12854
    30
done
schirmer@12854
    31
schirmer@12854
    32
lemmas finite_nyinitcls [simp] =
wenzelm@46476
    33
   finite_is_class [THEN nyinitcls_subset_class [THEN finite_subset]]
schirmer@12854
    34
schirmer@12854
    35
lemma card_nyinitcls_bound: "card (nyinitcls G s) \<le> card {C. is_class G C}"
schirmer@12854
    36
apply (rule nyinitcls_subset_class [THEN finite_is_class [THEN card_mono]])
schirmer@12854
    37
done
schirmer@12854
    38
schirmer@12854
    39
lemma nyinitcls_set_locals_cong [simp]: 
schirmer@12854
    40
  "nyinitcls G (x,set_locals l s) = nyinitcls G (x,s)"
wenzelm@49016
    41
  by (simp add: nyinitcls_def)
schirmer@12854
    42
schirmer@12854
    43
lemma nyinitcls_abrupt_cong [simp]: "nyinitcls G (f x, y) = nyinitcls G (x, y)"
wenzelm@49016
    44
  by (simp add: nyinitcls_def)
schirmer@12854
    45
wenzelm@49016
    46
lemma nyinitcls_abupd_cong [simp]: "nyinitcls G (abupd f s) = nyinitcls G s"
wenzelm@49016
    47
  by (simp add: nyinitcls_def)
schirmer@12854
    48
schirmer@12854
    49
lemma card_nyinitcls_abrupt_congE [elim!]: 
wenzelm@49016
    50
  "card (nyinitcls G (x, s)) \<le> n \<Longrightarrow> card (nyinitcls G (y, s)) \<le> n"
wenzelm@49016
    51
  unfolding nyinitcls_def by auto
schirmer@12854
    52
schirmer@12854
    53
lemma nyinitcls_new_xcpt_var [simp]: 
wenzelm@49016
    54
  "nyinitcls G (new_xcpt_var vn s) = nyinitcls G s"
wenzelm@49016
    55
  by (induct s) (simp_all add: nyinitcls_def)
schirmer@12854
    56
schirmer@12854
    57
lemma nyinitcls_init_lvars [simp]: 
schirmer@12854
    58
  "nyinitcls G ((init_lvars G C sig mode a' pvs) s) = nyinitcls G s"
wenzelm@49016
    59
  by (induct s) (simp add: init_lvars_def2 split add: split_if)
schirmer@12854
    60
schirmer@12854
    61
lemma nyinitcls_emptyD: "\<lbrakk>nyinitcls G s = {}; is_class G C\<rbrakk> \<Longrightarrow> initd C s"
wenzelm@49016
    62
  unfolding nyinitcls_def by fast
schirmer@12854
    63
schirmer@13688
    64
lemma card_Suc_lemma: 
schirmer@13688
    65
  "\<lbrakk>card (insert a A) \<le> Suc n; a\<notin>A; finite A\<rbrakk> \<Longrightarrow> card A \<le> n"
wenzelm@49016
    66
  by auto
schirmer@12854
    67
schirmer@12854
    68
lemma nyinitcls_le_SucD: 
schirmer@12854
    69
"\<lbrakk>card (nyinitcls G (x,s)) \<le> Suc n; \<not>inited C (globs s); class G C=Some y\<rbrakk> \<Longrightarrow> 
schirmer@12854
    70
  card (nyinitcls G (x,init_class_obj G C s)) \<le> n"
schirmer@12854
    71
apply (subgoal_tac 
schirmer@12854
    72
        "nyinitcls G (x,s) = insert C (nyinitcls G (x,init_class_obj G C s))")
schirmer@12854
    73
apply  clarsimp
berghofe@13601
    74
apply  (erule_tac V="nyinitcls G (x, s) = ?rhs" in thin_rl)
schirmer@12854
    75
apply  (rule card_Suc_lemma [OF _ _ finite_nyinitcls])
schirmer@12854
    76
apply   (auto dest!: not_initedD elim!: 
schirmer@12854
    77
              simp add: nyinitcls_def inited_def split add: split_if_asm)
schirmer@12854
    78
done
schirmer@12854
    79
schirmer@13688
    80
lemma inited_gext': "\<lbrakk>s\<le>|s';inited C (globs s)\<rbrakk> \<Longrightarrow> inited C (globs s')"
wenzelm@49016
    81
  by (rule inited_gext)
schirmer@12854
    82
schirmer@12854
    83
lemma nyinitcls_gext: "snd s\<le>|snd s' \<Longrightarrow> nyinitcls G s' \<subseteq> nyinitcls G s"
wenzelm@49016
    84
  unfolding nyinitcls_def by (force dest!: inited_gext')
schirmer@12854
    85
schirmer@12854
    86
lemma card_nyinitcls_gext: 
schirmer@12854
    87
  "\<lbrakk>snd s\<le>|snd s'; card (nyinitcls G s) \<le> n\<rbrakk>\<Longrightarrow> card (nyinitcls G s') \<le> n"
schirmer@12854
    88
apply (rule le_trans)
schirmer@12854
    89
apply  (rule card_mono)
schirmer@12854
    90
apply   (rule finite_nyinitcls)
schirmer@12854
    91
apply  (erule nyinitcls_gext)
schirmer@12854
    92
apply assumption
schirmer@12854
    93
done
schirmer@12854
    94
schirmer@12854
    95
schirmer@12854
    96
section "init-le"
schirmer@12854
    97
wenzelm@38219
    98
definition
wenzelm@38219
    99
  init_le :: "prog \<Rightarrow> nat \<Rightarrow> state \<Rightarrow> bool" ("_\<turnstile>init\<le>_"  [51,51] 50)
wenzelm@38219
   100
  where "G\<turnstile>init\<le>n = (\<lambda>s. card (nyinitcls G s) \<le> n)"
schirmer@12854
   101
  
schirmer@12854
   102
lemma init_le_def2 [simp]: "(G\<turnstile>init\<le>n) s = (card (nyinitcls G s)\<le>n)"
schirmer@12854
   103
apply (unfold init_le_def)
schirmer@12854
   104
apply auto
schirmer@12854
   105
done
schirmer@12854
   106
schirmer@13688
   107
lemma All_init_leD: 
schirmer@13688
   108
 "\<forall>n::nat. G,(A::'a triple set)\<turnstile>{P \<and>. G\<turnstile>init\<le>n} t\<succ> {Q::'a assn} 
schirmer@13688
   109
  \<Longrightarrow> G,A\<turnstile>{P} t\<succ> {Q}"
schirmer@12854
   110
apply (drule spec)
schirmer@12854
   111
apply (erule conseq1)
schirmer@12854
   112
apply clarsimp
schirmer@12854
   113
apply (rule card_nyinitcls_bound)
schirmer@12854
   114
done
schirmer@12854
   115
schirmer@12854
   116
section "Most General Triples and Formulas"
schirmer@12854
   117
wenzelm@38219
   118
definition
wenzelm@38219
   119
  remember_init_state :: "state assn" ("\<doteq>")
wenzelm@38219
   120
  where "\<doteq> \<equiv> \<lambda>Y s Z. s = Z"
schirmer@12854
   121
schirmer@12854
   122
lemma remember_init_state_def2 [simp]: "\<doteq> Y = op ="
schirmer@12854
   123
apply (unfold remember_init_state_def)
schirmer@12854
   124
apply (simp (no_asm))
schirmer@12854
   125
done
schirmer@12854
   126
wenzelm@38219
   127
definition
schirmer@12854
   128
  MGF ::"[state assn, term, prog] \<Rightarrow> state triple"   ("{_} _\<succ> {_\<rightarrow>}"[3,65,3]62)
wenzelm@38219
   129
  where "{P} t\<succ> {G\<rightarrow>} = {P} t\<succ> {\<lambda>Y s' s. G\<turnstile>s \<midarrow>t\<succ>\<rightarrow> (Y,s')}"
schirmer@12854
   130
wenzelm@38219
   131
definition
wenzelm@38219
   132
  MGFn :: "[nat, term, prog] \<Rightarrow> state triple" ("{=:_} _\<succ> {_\<rightarrow>}"[3,65,3]62)
wenzelm@38219
   133
  where "{=:n} t\<succ> {G\<rightarrow>} = {\<doteq> \<and>. G\<turnstile>init\<le>n} t\<succ> {G\<rightarrow>}"
schirmer@12854
   134
schirmer@12854
   135
(* unused *)
schirmer@12925
   136
lemma MGF_valid: "wf_prog G \<Longrightarrow> G,{}\<Turnstile>{\<doteq>} t\<succ> {G\<rightarrow>}"
schirmer@12854
   137
apply (unfold MGF_def)
schirmer@12925
   138
apply (simp add:  ax_valids_def triple_valid_def2)
schirmer@12925
   139
apply (auto elim: evaln_eval)
schirmer@12854
   140
done
schirmer@12854
   141
schirmer@12925
   142
schirmer@12854
   143
lemma MGF_res_eq_lemma [simp]: 
schirmer@12854
   144
  "(\<forall>Y' Y s. Y = Y' \<and> P s \<longrightarrow> Q s) = (\<forall>s. P s \<longrightarrow> Q s)"
wenzelm@49016
   145
  by auto
schirmer@12854
   146
schirmer@12854
   147
lemma MGFn_def2: 
schirmer@12854
   148
"G,A\<turnstile>{=:n} t\<succ> {G\<rightarrow>} = G,A\<turnstile>{\<doteq> \<and>. G\<turnstile>init\<le>n} 
schirmer@12854
   149
                    t\<succ> {\<lambda>Y s' s. G\<turnstile>s \<midarrow>t\<succ>\<rightarrow> (Y,s')}"
wenzelm@49016
   150
  unfolding MGFn_def MGF_def by fast
schirmer@12854
   151
schirmer@13688
   152
lemma MGF_MGFn_iff: 
schirmer@13688
   153
"G,(A::state triple set)\<turnstile>{\<doteq>} t\<succ> {G\<rightarrow>} = (\<forall>n. G,A\<turnstile>{=:n} t\<succ> {G\<rightarrow>})"
wenzelm@49016
   154
apply (simp add: MGFn_def2 MGF_def)
schirmer@12854
   155
apply safe
schirmer@12854
   156
apply  (erule_tac [2] All_init_leD)
schirmer@12854
   157
apply (erule conseq1)
schirmer@12854
   158
apply clarsimp
schirmer@12854
   159
done
schirmer@12854
   160
schirmer@12854
   161
lemma MGFnD: 
schirmer@13688
   162
"G,(A::state triple set)\<turnstile>{=:n} t\<succ> {G\<rightarrow>} \<Longrightarrow>  
schirmer@12854
   163
 G,A\<turnstile>{(\<lambda>Y' s' s. s' = s           \<and> P s) \<and>. G\<turnstile>init\<le>n}  
schirmer@12854
   164
 t\<succ>  {(\<lambda>Y' s' s. G\<turnstile>s\<midarrow>t\<succ>\<rightarrow>(Y',s') \<and> P s) \<and>. G\<turnstile>init\<le>n}"
schirmer@12854
   165
apply (unfold init_le_def)
schirmer@12854
   166
apply (simp (no_asm_use) add: MGFn_def2)
schirmer@12854
   167
apply (erule conseq12)
schirmer@12854
   168
apply clarsimp
schirmer@12854
   169
apply (erule (1) eval_gext [THEN card_nyinitcls_gext])
schirmer@12854
   170
done
schirmer@12854
   171
lemmas MGFnD' = MGFnD [of _ _ _ _ "\<lambda>x. True"] 
schirmer@12854
   172
schirmer@13688
   173
text {* To derive the most general formula, we can always assume a normal
schirmer@13688
   174
state in the precondition, since abrupt cases can be handled uniformally by
schirmer@13688
   175
the abrupt rule.
schirmer@13688
   176
*}
schirmer@12854
   177
lemma MGFNormalI: "G,A\<turnstile>{Normal \<doteq>} t\<succ> {G\<rightarrow>} \<Longrightarrow>  
schirmer@12854
   178
  G,(A::state triple set)\<turnstile>{\<doteq>::state assn} t\<succ> {G\<rightarrow>}"
schirmer@12854
   179
apply (unfold MGF_def)
schirmer@12854
   180
apply (rule ax_Normal_cases)
schirmer@12854
   181
apply  (erule conseq1)
schirmer@12854
   182
apply  clarsimp
schirmer@12854
   183
apply (rule ax_derivs.Abrupt [THEN conseq1])
schirmer@12854
   184
apply (clarsimp simp add: Let_def)
schirmer@12854
   185
done
schirmer@12854
   186
schirmer@13688
   187
lemma MGFNormalD: 
schirmer@13688
   188
"G,(A::state triple set)\<turnstile>{\<doteq>} t\<succ> {G\<rightarrow>} \<Longrightarrow> G,A\<turnstile>{Normal \<doteq>} t\<succ> {G\<rightarrow>}"
schirmer@12854
   189
apply (unfold MGF_def)
schirmer@12854
   190
apply (erule conseq1)
schirmer@12854
   191
apply clarsimp
schirmer@12854
   192
done
schirmer@12854
   193
schirmer@13688
   194
text {* Additionally to @{text MGFNormalI}, we also expand the definition of 
schirmer@13688
   195
the most general formula here *} 
schirmer@12854
   196
lemma MGFn_NormalI: 
schirmer@12854
   197
"G,(A::state triple set)\<turnstile>{Normal((\<lambda>Y' s' s. s'=s \<and> normal s) \<and>. G\<turnstile>init\<le>n)}t\<succ> 
schirmer@12854
   198
 {\<lambda>Y s' s. G\<turnstile>s \<midarrow>t\<succ>\<rightarrow> (Y,s')} \<Longrightarrow> G,A\<turnstile>{=:n}t\<succ>{G\<rightarrow>}"
schirmer@12854
   199
apply (simp (no_asm_use) add: MGFn_def2)
schirmer@12854
   200
apply (rule ax_Normal_cases)
schirmer@12854
   201
apply  (erule conseq1)
schirmer@12854
   202
apply  clarsimp
schirmer@12854
   203
apply (rule ax_derivs.Abrupt [THEN conseq1])
schirmer@12854
   204
apply (clarsimp simp add: Let_def)
schirmer@12854
   205
done
schirmer@12854
   206
schirmer@13688
   207
text {* To derive the most general formula, we can restrict ourselves to 
schirmer@13688
   208
welltyped terms, since all others can be uniformally handled by the hazard
schirmer@13688
   209
rule. *} 
schirmer@12854
   210
lemma MGFn_free_wt: 
schirmer@12854
   211
  "(\<exists>T L C. \<lparr>prg=G,cls=C,lcl=L\<rparr>\<turnstile>t\<Colon>T) 
schirmer@12854
   212
    \<longrightarrow> G,(A::state triple set)\<turnstile>{=:n} t\<succ> {G\<rightarrow>} 
schirmer@12854
   213
   \<Longrightarrow> G,A\<turnstile>{=:n} t\<succ> {G\<rightarrow>}"
schirmer@12854
   214
apply (rule MGFn_NormalI)
schirmer@12854
   215
apply (rule ax_free_wt)
schirmer@12854
   216
apply (auto elim: conseq12 simp add: MGFn_def MGF_def)
schirmer@12854
   217
done
schirmer@12854
   218
schirmer@13688
   219
text {* To derive the most general formula, we can restrict ourselves to 
schirmer@13688
   220
welltyped terms and assume that the state in the precondition conforms to the
schirmer@13688
   221
environment. All type violations can be uniformally handled by the hazard
schirmer@13688
   222
rule. *} 
schirmer@12925
   223
lemma MGFn_free_wt_NormalConformI: 
schirmer@13688
   224
"(\<forall> T L C . \<lparr>prg=G,cls=C,lcl=L\<rparr>\<turnstile>t\<Colon>T 
schirmer@12925
   225
  \<longrightarrow> G,(A::state triple set)
schirmer@12925
   226
      \<turnstile>{Normal((\<lambda>Y' s' s. s'=s \<and> normal s) \<and>. G\<turnstile>init\<le>n) \<and>. (\<lambda> s. s\<Colon>\<preceq>(G, L))}
schirmer@12925
   227
      t\<succ> 
schirmer@12925
   228
      {\<lambda>Y s' s. G\<turnstile>s \<midarrow>t\<succ>\<rightarrow> (Y,s')}) 
schirmer@12925
   229
 \<Longrightarrow> G,A\<turnstile>{=:n}t\<succ>{G\<rightarrow>}"
schirmer@12925
   230
apply (rule MGFn_NormalI)
schirmer@12925
   231
apply (rule ax_no_hazard)
schirmer@12925
   232
apply (rule ax_escape)
schirmer@12925
   233
apply (intro strip)
schirmer@12925
   234
apply (simp only: type_ok_def peek_and_def)
schirmer@12925
   235
apply (erule conjE)+
schirmer@13688
   236
apply (erule exE,erule exE, erule exE, erule exE,erule conjE,drule (1) mp,
schirmer@13688
   237
       erule conjE)
schirmer@12925
   238
apply (drule spec,drule spec, drule spec, drule (1) mp)
schirmer@12925
   239
apply (erule conseq12)
schirmer@12925
   240
apply blast
schirmer@12925
   241
done
schirmer@12925
   242
schirmer@13688
   243
text {* To derive the most general formula, we can restrict ourselves to 
schirmer@13688
   244
welltyped terms and assume that the state in the precondition conforms to the
schirmer@13688
   245
environment and that the term is definetly assigned with respect to this state.
schirmer@13688
   246
All type violations can be uniformally handled by the hazard rule. *} 
schirmer@13688
   247
lemma MGFn_free_wt_da_NormalConformI: 
schirmer@13688
   248
"(\<forall> T L C B. \<lparr>prg=G,cls=C,lcl=L\<rparr>\<turnstile>t\<Colon>T
schirmer@13688
   249
  \<longrightarrow> G,(A::state triple set)
schirmer@13688
   250
      \<turnstile>{Normal((\<lambda>Y' s' s. s'=s \<and> normal s) \<and>. G\<turnstile>init\<le>n) \<and>. (\<lambda> s. s\<Colon>\<preceq>(G, L))
schirmer@13688
   251
        \<and>. (\<lambda> s. \<lparr>prg=G,cls=C,lcl=L\<rparr>\<turnstile>dom (locals (store s))\<guillemotright>t\<guillemotright>B)}
schirmer@13688
   252
      t\<succ> 
schirmer@13688
   253
      {\<lambda>Y s' s. G\<turnstile>s \<midarrow>t\<succ>\<rightarrow> (Y,s')}) 
schirmer@13688
   254
 \<Longrightarrow> G,A\<turnstile>{=:n}t\<succ>{G\<rightarrow>}"
schirmer@13688
   255
apply (rule MGFn_NormalI)
schirmer@13688
   256
apply (rule ax_no_hazard)
schirmer@13688
   257
apply (rule ax_escape)
schirmer@13688
   258
apply (intro strip)
schirmer@13688
   259
apply (simp only: type_ok_def peek_and_def)
schirmer@13688
   260
apply (erule conjE)+
schirmer@13688
   261
apply (erule exE,erule exE, erule exE, erule exE,erule conjE,drule (1) mp,
schirmer@13688
   262
       erule conjE)
schirmer@13688
   263
apply (drule spec,drule spec, drule spec,drule spec, drule (1) mp)
schirmer@13688
   264
apply (erule conseq12)
schirmer@13688
   265
apply blast
schirmer@13688
   266
done
schirmer@12854
   267
schirmer@12854
   268
section "main lemmas"
schirmer@12854
   269
schirmer@13688
   270
lemma MGFn_Init: 
schirmer@13688
   271
 assumes mgf_hyp: "\<forall>m. Suc m\<le>n \<longrightarrow> (\<forall>t. G,A\<turnstile>{=:m} t\<succ> {G\<rightarrow>})"
schirmer@13688
   272
 shows "G,(A::state triple set)\<turnstile>{=:n} \<langle>Init C\<rangle>\<^sub>s\<succ> {G\<rightarrow>}"
schirmer@13688
   273
proof (rule MGFn_free_wt [rule_format],elim exE,rule MGFn_NormalI)
schirmer@13688
   274
  fix T L accC
schirmer@13688
   275
  assume "\<lparr>prg=G, cls=accC, lcl= L\<rparr>\<turnstile>\<langle>Init C\<rangle>\<^sub>s\<Colon>T"
schirmer@13688
   276
  hence is_cls: "is_class G C"
schirmer@13688
   277
    by cases simp
schirmer@13688
   278
  show "G,A\<turnstile>{Normal ((\<lambda>Y' s' s. s' = s \<and> normal s) \<and>. G\<turnstile>init\<le>n)} 
schirmer@13688
   279
            .Init C.
schirmer@13688
   280
            {\<lambda>Y s' s. G\<turnstile>s \<midarrow>\<langle>Init C\<rangle>\<^sub>s\<succ>\<rightarrow> (Y, s')}"
schirmer@13688
   281
       (is "G,A\<turnstile>{Normal ?P} .Init C. {?R}")
schirmer@13688
   282
  proof (rule ax_cases [where ?C="initd C"])
schirmer@13688
   283
    show "G,A\<turnstile>{Normal ?P  \<and>. initd C} .Init C. {?R}"
nipkow@45761
   284
      by (rule ax_derivs.Done [THEN conseq1]) (fastforce intro: init_done)
schirmer@13688
   285
  next
schirmer@13688
   286
    have "G,A\<turnstile>{Normal (?P  \<and>. Not \<circ> initd C)} .Init C. {?R}" 
schirmer@13688
   287
    proof (cases n)
schirmer@13688
   288
      case 0
schirmer@13688
   289
      with is_cls
schirmer@13688
   290
      show ?thesis
nipkow@45761
   291
        by - (rule ax_impossible [THEN conseq1],fastforce dest: nyinitcls_emptyD)
schirmer@13688
   292
    next
schirmer@13688
   293
      case (Suc m)
schirmer@13688
   294
      with mgf_hyp have mgf_hyp': "\<And> t. G,A\<turnstile>{=:m} t\<succ> {G\<rightarrow>}"
wenzelm@32962
   295
        by simp
schirmer@13688
   296
      from is_cls obtain c where c: "the (class G C) = c"
wenzelm@32962
   297
        by auto
schirmer@13688
   298
      let ?Q= "(\<lambda>Y s' (x,s) . 
schirmer@13688
   299
          G\<turnstile> (x,init_class_obj G C s) 
schirmer@13688
   300
             \<midarrow> (if C=Object then Skip else Init (super (the (class G C))))\<rightarrow> s'
schirmer@13688
   301
          \<and> x=None \<and> \<not>inited C (globs s)) \<and>. G\<turnstile>init\<le>m"
schirmer@13688
   302
      from c
schirmer@13688
   303
      show ?thesis
schirmer@13688
   304
      proof (rule ax_derivs.Init [where ?Q="?Q"])
wenzelm@32962
   305
        let ?P' = "Normal ((\<lambda>Y s' s. s' = supd (init_class_obj G C) s 
schirmer@13688
   306
                           \<and> normal s \<and> \<not> initd C s) \<and>. G\<turnstile>init\<le>m)" 
wenzelm@32962
   307
        show "G,A\<turnstile>{Normal (?P \<and>. Not \<circ> initd C ;. supd (init_class_obj G C))}
schirmer@13688
   308
                  .(if C = Object then Skip else Init (super c)). 
schirmer@13688
   309
                  {?Q}"
wenzelm@32962
   310
        proof (rule conseq1 [where ?P'="?P'"])
wenzelm@32962
   311
          show "G,A\<turnstile>{?P'} .(if C = Object then Skip else Init (super c)). {?Q}"
wenzelm@32962
   312
          proof (cases "C=Object")
wenzelm@32962
   313
            case True
wenzelm@32962
   314
            have "G,A\<turnstile>{?P'} .Skip. {?Q}"
wenzelm@32962
   315
              by (rule ax_derivs.Skip [THEN conseq1])
wenzelm@32962
   316
                 (auto simp add: True intro: eval.Skip)
schirmer@13688
   317
            with True show ?thesis 
wenzelm@32962
   318
              by simp
wenzelm@32962
   319
          next
wenzelm@32962
   320
            case False
wenzelm@32962
   321
            from mgf_hyp'
wenzelm@32962
   322
            have "G,A\<turnstile>{?P'} .Init (super c). {?Q}"
nipkow@45761
   323
              by (rule MGFnD' [THEN conseq12]) (fastforce simp add: False c)
wenzelm@32962
   324
            with False show ?thesis
wenzelm@32962
   325
              by simp
wenzelm@32962
   326
          qed
wenzelm@32962
   327
        next
wenzelm@32962
   328
          from Suc is_cls
wenzelm@32962
   329
          show "Normal (?P \<and>. Not \<circ> initd C ;. supd (init_class_obj G C))
schirmer@13688
   330
                \<Rightarrow> ?P'"
nipkow@45761
   331
            by (fastforce elim: nyinitcls_le_SucD)
wenzelm@32962
   332
        qed
schirmer@13688
   333
      next
wenzelm@32962
   334
        from mgf_hyp'
wenzelm@32962
   335
        show "\<forall>l. G,A\<turnstile>{?Q \<and>. (\<lambda>s. l = locals (snd s)) ;. set_lvars empty} 
schirmer@13688
   336
                      .init c.
schirmer@13688
   337
                      {set_lvars l .; ?R}"
wenzelm@32962
   338
          apply (rule MGFnD' [THEN conseq12, THEN allI])
wenzelm@32962
   339
          apply (clarsimp simp add: split_paired_all)
wenzelm@32962
   340
          apply (rule eval.Init [OF c])
wenzelm@32962
   341
          apply (insert c)
wenzelm@32962
   342
          apply auto
wenzelm@32962
   343
          done
schirmer@13688
   344
      qed
schirmer@13688
   345
    qed
schirmer@13688
   346
    thus "G,A\<turnstile>{Normal ?P  \<and>. Not \<circ> initd C} .Init C. {?R}"
schirmer@13688
   347
      by clarsimp
schirmer@13688
   348
  qed
schirmer@13688
   349
qed
schirmer@12854
   350
lemmas MGFn_InitD = MGFn_Init [THEN MGFnD, THEN ax_NormalD]
schirmer@12854
   351
schirmer@12854
   352
lemma MGFn_Call: 
schirmer@13688
   353
  assumes mgf_methds: 
schirmer@13688
   354
           "\<forall>C sig. G,(A::state triple set)\<turnstile>{=:n} \<langle>(Methd C sig)\<rangle>\<^sub>e\<succ> {G\<rightarrow>}"
schirmer@13688
   355
  and mgf_e: "G,A\<turnstile>{=:n} \<langle>e\<rangle>\<^sub>e\<succ> {G\<rightarrow>}"
schirmer@13688
   356
  and mgf_ps: "G,A\<turnstile>{=:n} \<langle>ps\<rangle>\<^sub>l\<succ> {G\<rightarrow>}"
schirmer@13688
   357
  and wf: "wf_prog G"
schirmer@13688
   358
  shows "G,A\<turnstile>{=:n} \<langle>{accC,statT,mode}e\<cdot>mn({pTs'}ps)\<rangle>\<^sub>e\<succ> {G\<rightarrow>}"
schirmer@13688
   359
proof (rule MGFn_free_wt_da_NormalConformI [rule_format],clarsimp) 
schirmer@13688
   360
  note inj_term_simps [simp]
schirmer@13688
   361
  fix T L accC' E
schirmer@13688
   362
  assume wt: "\<lparr>prg=G,cls=accC',lcl = L\<rparr>\<turnstile>\<langle>({accC,statT,mode}e\<cdot>mn( {pTs'}ps))\<rangle>\<^sub>e\<Colon>T"
schirmer@13688
   363
  then obtain pTs statDeclT statM where
schirmer@13688
   364
                 wt_e: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>e\<Colon>-RefT statT" and
schirmer@13688
   365
              wt_args: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>ps\<Colon>\<doteq>pTs" and
schirmer@13688
   366
                statM: "max_spec G accC statT \<lparr>name=mn,parTs=pTs\<rparr> 
schirmer@13688
   367
                         = {((statDeclT,statM),pTs')}" and
schirmer@13688
   368
                 mode: "mode = invmode statM e" and
schirmer@13688
   369
                    T: "T =Inl (resTy statM)" and
schirmer@13688
   370
        eq_accC_accC': "accC=accC'"
nipkow@45761
   371
        by cases fastforce+
schirmer@13688
   372
  let ?Q="(\<lambda>Y s1 (x,s) . x = None \<and> 
schirmer@13688
   373
              (\<exists>a. G\<turnstile>Norm s \<midarrow>e-\<succ>a\<rightarrow> s1 \<and> 
schirmer@13688
   374
                   (normal s1 \<longrightarrow> G, store s1\<turnstile>a\<Colon>\<preceq>RefT statT)
schirmer@13688
   375
                   \<and> Y = In1 a) \<and> 
schirmer@13688
   376
              (\<exists> P. normal s1
schirmer@13688
   377
                  \<longrightarrow> \<lparr>prg=G,cls=accC',lcl=L\<rparr>\<turnstile>dom (locals (store s1))\<guillemotright>\<langle>ps\<rangle>\<^sub>l\<guillemotright>P)) 
schirmer@13688
   378
          \<and>. G\<turnstile>init\<le>n \<and>. (\<lambda> s. s\<Colon>\<preceq>(G, L))::state assn"
schirmer@13688
   379
  let ?R="\<lambda>a. ((\<lambda>Y (x2,s2) (x,s) . x = None \<and> 
schirmer@13688
   380
                (\<exists>s1 pvs. G\<turnstile>Norm s \<midarrow>e-\<succ>a\<rightarrow> s1 \<and> 
schirmer@13688
   381
                          (normal s1 \<longrightarrow> G, store s1\<turnstile>a\<Colon>\<preceq>RefT statT)\<and> 
schirmer@13688
   382
                          Y = \<lfloor>pvs\<rfloor>\<^sub>l \<and> G\<turnstile>s1 \<midarrow>ps\<doteq>\<succ>pvs\<rightarrow> (x2,s2))) 
schirmer@13688
   383
               \<and>. G\<turnstile>init\<le>n \<and>. (\<lambda> s. s\<Colon>\<preceq>(G, L)))::state assn"
schirmer@12925
   384
schirmer@13688
   385
  show "G,A\<turnstile>{Normal ((\<lambda>Y' s' s. s' = s \<and> abrupt s = None) \<and>. G\<turnstile>init\<le>n \<and>.
schirmer@13688
   386
                     (\<lambda>s. s\<Colon>\<preceq>(G, L)) \<and>.
schirmer@13688
   387
                     (\<lambda>s. \<lparr>prg=G, cls=accC',lcl=L\<rparr> \<turnstile> dom (locals (store s)) 
schirmer@13688
   388
                           \<guillemotright> \<langle>{accC,statT,mode}e\<cdot>mn( {pTs'}ps)\<rangle>\<^sub>e\<guillemotright> E))}
schirmer@13688
   389
             {accC,statT,mode}e\<cdot>mn( {pTs'}ps)-\<succ>
schirmer@13688
   390
             {\<lambda>Y s' s. \<exists>v. Y = \<lfloor>v\<rfloor>\<^sub>e \<and> 
schirmer@13688
   391
                           G\<turnstile>s \<midarrow>{accC,statT,mode}e\<cdot>mn( {pTs'}ps)-\<succ>v\<rightarrow> s'}"
schirmer@13688
   392
    (is "G,A\<turnstile>{Normal ?P} {accC,statT,mode}e\<cdot>mn( {pTs'}ps)-\<succ> {?S}")
schirmer@13688
   393
  proof (rule ax_derivs.Call [where ?Q="?Q" and ?R="?R"])
schirmer@13688
   394
    from mgf_e
schirmer@13688
   395
    show "G,A\<turnstile>{Normal ?P} e-\<succ> {?Q}"
schirmer@13688
   396
    proof (rule MGFnD' [THEN conseq12],clarsimp)
schirmer@13688
   397
      fix s0 s1 a
schirmer@13688
   398
      assume conf_s0: "Norm s0\<Colon>\<preceq>(G, L)"
schirmer@13688
   399
      assume da: "\<lparr>prg=G,cls=accC',lcl=L\<rparr>\<turnstile> 
schirmer@13688
   400
                     dom (locals s0) \<guillemotright>\<langle>{accC,statT,mode}e\<cdot>mn( {pTs'}ps)\<rangle>\<^sub>e\<guillemotright> E"
schirmer@13688
   401
      assume eval_e: "G\<turnstile>Norm s0 \<midarrow>e-\<succ>a\<rightarrow> s1"
schirmer@13688
   402
      show "(abrupt s1 = None \<longrightarrow> G,store s1\<turnstile>a\<Colon>\<preceq>RefT statT) \<and>
schirmer@13688
   403
            (abrupt s1 = None \<longrightarrow>
schirmer@13688
   404
              (\<exists>P. \<lparr>prg=G,cls=accC',lcl=L\<rparr>\<turnstile> dom (locals (store s1)) \<guillemotright>\<langle>ps\<rangle>\<^sub>l\<guillemotright> P))
schirmer@13688
   405
            \<and> s1\<Colon>\<preceq>(G, L)"
schirmer@13688
   406
      proof -
wenzelm@32962
   407
        from da obtain C where
wenzelm@32962
   408
          da_e:  "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>
schirmer@13688
   409
                    dom (locals (store ((Norm s0)::state)))\<guillemotright>\<langle>e\<rangle>\<^sub>e\<guillemotright> C" and
wenzelm@32962
   410
          da_ps: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile> nrm C \<guillemotright>\<langle>ps\<rangle>\<^sub>l\<guillemotright> E" 
wenzelm@32962
   411
          by cases (simp add: eq_accC_accC')
wenzelm@32962
   412
        from eval_e conf_s0 wt_e da_e wf
wenzelm@32962
   413
        obtain "(abrupt s1 = None \<longrightarrow> G,store s1\<turnstile>a\<Colon>\<preceq>RefT statT)"
wenzelm@32962
   414
          and  "s1\<Colon>\<preceq>(G, L)"
wenzelm@32962
   415
          by (rule eval_type_soundE) simp
wenzelm@32962
   416
        moreover
wenzelm@32962
   417
        {
wenzelm@32962
   418
          assume normal_s1: "normal s1"
wenzelm@32962
   419
          have "\<exists>P. \<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile> dom (locals (store s1)) \<guillemotright>\<langle>ps\<rangle>\<^sub>l\<guillemotright> P"
wenzelm@32962
   420
          proof -
wenzelm@32962
   421
            from eval_e wt_e da_e wf normal_s1
wenzelm@32962
   422
            have "nrm C \<subseteq>  dom (locals (store s1))"
wenzelm@32962
   423
              by (cases rule: da_good_approxE') iprover
wenzelm@32962
   424
            with da_ps show ?thesis
wenzelm@32962
   425
              by (rule da_weakenE) iprover
wenzelm@32962
   426
          qed
wenzelm@32962
   427
        }
wenzelm@32962
   428
        ultimately show ?thesis
wenzelm@32962
   429
          using eq_accC_accC' by simp
schirmer@13688
   430
      qed
schirmer@13688
   431
    qed
schirmer@13688
   432
  next
schirmer@13688
   433
    show "\<forall>a. G,A\<turnstile>{?Q\<leftarrow>In1 a} ps\<doteq>\<succ> {?R a}" (is "\<forall> a. ?PS a")
schirmer@13688
   434
    proof 
schirmer@13688
   435
      fix a  
schirmer@13688
   436
      show "?PS a"
schirmer@13688
   437
      proof (rule MGFnD' [OF mgf_ps, THEN conseq12],
schirmer@13688
   438
             clarsimp simp add: eq_accC_accC' [symmetric])
wenzelm@32962
   439
        fix s0 s1 s2 vs
wenzelm@32962
   440
        assume conf_s1: "s1\<Colon>\<preceq>(G, L)"
wenzelm@32962
   441
        assume eval_e: "G\<turnstile>Norm s0 \<midarrow>e-\<succ>a\<rightarrow> s1"
wenzelm@32962
   442
        assume conf_a: "abrupt s1 = None \<longrightarrow> G,store s1\<turnstile>a\<Colon>\<preceq>RefT statT"
wenzelm@32962
   443
        assume eval_ps: "G\<turnstile>s1 \<midarrow>ps\<doteq>\<succ>vs\<rightarrow> s2"
wenzelm@32962
   444
        assume da_ps: "abrupt s1 = None \<longrightarrow> 
schirmer@13688
   445
                       (\<exists>P. \<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile> 
schirmer@13688
   446
                               dom (locals (store s1)) \<guillemotright>\<langle>ps\<rangle>\<^sub>l\<guillemotright> P)"
wenzelm@32962
   447
        show "(\<exists>s1. G\<turnstile>Norm s0 \<midarrow>e-\<succ>a\<rightarrow> s1 \<and>
schirmer@13688
   448
                (abrupt s1 = None \<longrightarrow> G,store s1\<turnstile>a\<Colon>\<preceq>RefT statT) \<and>
schirmer@13688
   449
                G\<turnstile>s1 \<midarrow>ps\<doteq>\<succ>vs\<rightarrow> s2) \<and>
schirmer@13688
   450
              s2\<Colon>\<preceq>(G, L)"
wenzelm@32962
   451
        proof (cases "normal s1")
wenzelm@32962
   452
          case True
wenzelm@32962
   453
          with da_ps obtain P where
wenzelm@32962
   454
           "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile> dom (locals (store s1)) \<guillemotright>\<langle>ps\<rangle>\<^sub>l\<guillemotright> P"
wenzelm@32962
   455
            by auto
wenzelm@32962
   456
          from eval_ps conf_s1 wt_args this wf
wenzelm@32962
   457
          have "s2\<Colon>\<preceq>(G, L)"
wenzelm@32962
   458
            by (rule eval_type_soundE)
wenzelm@32962
   459
          with eval_e conf_a eval_ps 
wenzelm@32962
   460
          show ?thesis 
wenzelm@32962
   461
            by auto
wenzelm@32962
   462
        next
wenzelm@32962
   463
          case False
wenzelm@32962
   464
          with eval_ps have "s2=s1" by auto
wenzelm@32962
   465
          with eval_e conf_a eval_ps conf_s1 
wenzelm@32962
   466
          show ?thesis 
wenzelm@32962
   467
            by auto
wenzelm@32962
   468
        qed
schirmer@13688
   469
      qed
schirmer@13688
   470
    qed
schirmer@13688
   471
  next
schirmer@13688
   472
    show "\<forall>a vs invC declC l.
schirmer@13688
   473
      G,A\<turnstile>{?R a\<leftarrow>\<lfloor>vs\<rfloor>\<^sub>l \<and>.
schirmer@13688
   474
             (\<lambda>s. declC =
schirmer@13688
   475
                  invocation_declclass G mode (store s) a statT
schirmer@13688
   476
                      \<lparr>name=mn, parTs=pTs'\<rparr> \<and>
schirmer@13688
   477
                  invC = invocation_class mode (store s) a statT \<and>
schirmer@13688
   478
                  l = locals (store s)) ;.
schirmer@13688
   479
             init_lvars G declC \<lparr>name=mn, parTs=pTs'\<rparr> mode a vs \<and>.
schirmer@13688
   480
             (\<lambda>s. normal s \<longrightarrow> G\<turnstile>mode\<rightarrow>invC\<preceq>statT)}
schirmer@13688
   481
          Methd declC \<lparr>name=mn,parTs=pTs'\<rparr>-\<succ> 
schirmer@13688
   482
          {set_lvars l .; ?S}" 
schirmer@13688
   483
      (is "\<forall> a vs invC declC l. ?METHD a vs invC declC l")
schirmer@13688
   484
    proof (intro allI)
schirmer@13688
   485
      fix a vs invC declC l
schirmer@13688
   486
      from mgf_methds [rule_format]
schirmer@13688
   487
      show "?METHD a vs invC declC l"
schirmer@13688
   488
      proof (rule MGFnD' [THEN conseq12],clarsimp)
wenzelm@32962
   489
        fix s4 s2 s1::state
wenzelm@32962
   490
        fix s0 v
wenzelm@32962
   491
        let ?D= "invocation_declclass G mode (store s2) a statT 
schirmer@13688
   492
                    \<lparr>name=mn,parTs=pTs'\<rparr>"
wenzelm@32962
   493
        let ?s3= "init_lvars G ?D \<lparr>name=mn, parTs=pTs'\<rparr> mode a vs s2"
wenzelm@32962
   494
        assume inv_prop: "abrupt ?s3=None 
schirmer@13688
   495
             \<longrightarrow> G\<turnstile>mode\<rightarrow>invocation_class mode (store s2) a statT\<preceq>statT"
wenzelm@32962
   496
        assume conf_s2: "s2\<Colon>\<preceq>(G, L)"
wenzelm@32962
   497
        assume conf_a: "abrupt s1 = None \<longrightarrow> G,store s1\<turnstile>a\<Colon>\<preceq>RefT statT"
wenzelm@32962
   498
        assume eval_e: "G\<turnstile>Norm s0 \<midarrow>e-\<succ>a\<rightarrow> s1"
wenzelm@32962
   499
        assume eval_ps: "G\<turnstile>s1 \<midarrow>ps\<doteq>\<succ>vs\<rightarrow> s2"
wenzelm@32962
   500
        assume eval_mthd: "G\<turnstile>?s3 \<midarrow>Methd ?D \<lparr>name=mn,parTs=pTs'\<rparr>-\<succ>v\<rightarrow> s4"
wenzelm@32962
   501
        show "G\<turnstile>Norm s0 \<midarrow>{accC,statT,mode}e\<cdot>mn( {pTs'}ps)-\<succ>v
schirmer@13688
   502
                        \<rightarrow> (set_lvars (locals (store s2))) s4"
wenzelm@32962
   503
        proof -
wenzelm@32962
   504
          obtain D where D: "D=?D" by simp
wenzelm@32962
   505
          obtain s3 where s3: "s3=?s3" by simp
wenzelm@32962
   506
          obtain s3' where 
wenzelm@32962
   507
            s3': "s3' = check_method_access G accC statT mode 
schirmer@13688
   508
                           \<lparr>name=mn,parTs=pTs'\<rparr> a s3"
wenzelm@32962
   509
            by simp
wenzelm@32962
   510
          have eq_s3'_s3: "s3'=s3"
wenzelm@32962
   511
          proof -
wenzelm@32962
   512
            from inv_prop s3 mode
wenzelm@32962
   513
            have "normal s3 \<Longrightarrow> 
schirmer@13688
   514
             G\<turnstile>invmode statM e\<rightarrow>invocation_class mode (store s2) a statT\<preceq>statT"
wenzelm@32962
   515
              by auto
wenzelm@32962
   516
            with eval_ps wt_e statM conf_s2 conf_a [rule_format] 
wenzelm@32962
   517
            have "check_method_access G accC statT (invmode statM e)
schirmer@13688
   518
                      \<lparr>name=mn,parTs=pTs'\<rparr> a s3 = s3"
wenzelm@32962
   519
              by (rule error_free_call_access) (auto simp add: s3 mode wf)
wenzelm@32962
   520
            thus ?thesis 
wenzelm@32962
   521
              by (simp add: s3' mode)
wenzelm@32962
   522
          qed
wenzelm@32962
   523
          with eval_mthd D s3
wenzelm@32962
   524
          have "G\<turnstile>s3' \<midarrow>Methd D \<lparr>name=mn,parTs=pTs'\<rparr>-\<succ>v\<rightarrow> s4"
wenzelm@32962
   525
            by simp
wenzelm@32962
   526
          with eval_e eval_ps D _ s3' 
wenzelm@32962
   527
          show ?thesis
wenzelm@32962
   528
            by (rule eval_Call) (auto simp add: s3 mode D)
wenzelm@32962
   529
        qed
schirmer@13688
   530
      qed
schirmer@13688
   531
    qed
schirmer@13688
   532
  qed
schirmer@13688
   533
qed
wenzelm@32962
   534
                  
schirmer@13688
   535
lemma eval_expression_no_jump':
schirmer@13688
   536
  assumes eval: "G\<turnstile>s0 \<midarrow>e-\<succ>v\<rightarrow> s1"
schirmer@13688
   537
  and   no_jmp: "abrupt s0 \<noteq> Some (Jump j)"
schirmer@13688
   538
  and      wt: "\<lparr>prg=G, cls=C,lcl=L\<rparr>\<turnstile>e\<Colon>-T" 
schirmer@13688
   539
  and      wf: "wf_prog G"
schirmer@13688
   540
shows "abrupt s1 \<noteq> Some (Jump j)"
schirmer@13688
   541
using eval no_jmp wt wf
schirmer@13688
   542
by - (rule eval_expression_no_jump 
schirmer@13688
   543
            [where ?Env="\<lparr>prg=G, cls=C,lcl=L\<rparr>",simplified],auto)
schirmer@12925
   544
schirmer@12925
   545
schirmer@13688
   546
text {* To derive the most general formula for the loop statement, we need to
schirmer@13688
   547
come up with a proper loop invariant, which intuitively states that we are 
schirmer@13688
   548
currently inside the evaluation of the loop. To define such an invariant, we
schirmer@13688
   549
unroll the loop in iterated evaluations of the expression and evaluations of
schirmer@13688
   550
the loop body. *}
schirmer@12854
   551
wenzelm@38219
   552
definition
wenzelm@38219
   553
  unroll :: "prog \<Rightarrow> label \<Rightarrow> expr \<Rightarrow> stmt \<Rightarrow> (state \<times>  state) set" where
wenzelm@38219
   554
  "unroll G l e c = {(s,t). \<exists> v s1 s2.
schirmer@13688
   555
                             G\<turnstile>s \<midarrow>e-\<succ>v\<rightarrow> s1 \<and> the_Bool v \<and> normal s1 \<and>
schirmer@13688
   556
                             G\<turnstile>s1 \<midarrow>c\<rightarrow> s2 \<and> t=(abupd (absorb (Cont l)) s2)}"
schirmer@12854
   557
schirmer@12854
   558
schirmer@13688
   559
lemma unroll_while:
schirmer@13688
   560
  assumes unroll: "(s, t) \<in> (unroll G l e c)\<^sup>*"
schirmer@13688
   561
  and     eval_e: "G\<turnstile>t \<midarrow>e-\<succ>v\<rightarrow> s'" 
schirmer@13688
   562
  and     normal_termination: "normal s'  \<longrightarrow> \<not> the_Bool v"
schirmer@13688
   563
  and     wt: "\<lparr>prg=G,cls=C,lcl=L\<rparr>\<turnstile>e\<Colon>-T"
schirmer@13688
   564
  and     wf: "wf_prog G" 
schirmer@13688
   565
  shows "G\<turnstile>s \<midarrow>l\<bullet> While(e) c\<rightarrow> s'"
schirmer@13688
   566
using unroll (* normal_s *)
schirmer@13688
   567
proof (induct rule: converse_rtrancl_induct) 
schirmer@13688
   568
  show "G\<turnstile>t \<midarrow>l\<bullet> While(e) c\<rightarrow> s'"
schirmer@13688
   569
  proof (cases "normal t")
schirmer@13688
   570
    case False
schirmer@13688
   571
    with eval_e have "s'=t" by auto
schirmer@13688
   572
    with False show ?thesis by auto
schirmer@13688
   573
  next
schirmer@13688
   574
    case True
schirmer@13688
   575
    note normal_t = this
schirmer@13688
   576
    show ?thesis
schirmer@13688
   577
    proof (cases "normal s'")
schirmer@13688
   578
      case True
schirmer@13688
   579
      with normal_t eval_e normal_termination
schirmer@13688
   580
      show ?thesis
wenzelm@32962
   581
        by (auto intro: eval.Loop)
schirmer@13688
   582
    next
schirmer@13688
   583
      case False
schirmer@13688
   584
      note abrupt_s' = this
schirmer@13688
   585
      from eval_e _ wt wf
schirmer@13688
   586
      have no_cont: "abrupt s' \<noteq> Some (Jump (Cont l))"
wenzelm@32962
   587
        by (rule eval_expression_no_jump') (insert normal_t,simp)
schirmer@13688
   588
      have
wenzelm@32962
   589
        "if the_Bool v 
schirmer@13688
   590
             then (G\<turnstile>s' \<midarrow>c\<rightarrow> s' \<and> 
schirmer@13688
   591
                   G\<turnstile>(abupd (absorb (Cont l)) s') \<midarrow>l\<bullet> While(e) c\<rightarrow> s')
wenzelm@32962
   592
             else s' = s'"
schirmer@13688
   593
      proof (cases "the_Bool v")
wenzelm@32962
   594
        case False thus ?thesis by simp
schirmer@13688
   595
      next
wenzelm@32962
   596
        case True
wenzelm@32962
   597
        with abrupt_s' have "G\<turnstile>s' \<midarrow>c\<rightarrow> s'" by auto
wenzelm@32962
   598
        moreover from abrupt_s' no_cont 
wenzelm@32962
   599
        have no_absorb: "(abupd (absorb (Cont l)) s')=s'"
wenzelm@32962
   600
          by (cases s') (simp add: absorb_def split: split_if)
wenzelm@32962
   601
        moreover
wenzelm@32962
   602
        from no_absorb abrupt_s'
wenzelm@32962
   603
        have "G\<turnstile>(abupd (absorb (Cont l)) s') \<midarrow>l\<bullet> While(e) c\<rightarrow> s'"
wenzelm@32962
   604
          by auto
wenzelm@32962
   605
        ultimately show ?thesis
wenzelm@32962
   606
          using True by simp
schirmer@13688
   607
      qed
schirmer@13688
   608
      with eval_e 
schirmer@13688
   609
      show ?thesis
wenzelm@32962
   610
        using normal_t by (auto intro: eval.Loop)
schirmer@13688
   611
    qed
schirmer@13688
   612
  qed
schirmer@13688
   613
next
schirmer@13688
   614
  fix s s3
schirmer@13688
   615
  assume unroll: "(s,s3) \<in> unroll G l e c"
schirmer@13688
   616
  assume while: "G\<turnstile>s3 \<midarrow>l\<bullet> While(e) c\<rightarrow> s'"
schirmer@13688
   617
  show "G\<turnstile>s \<midarrow>l\<bullet> While(e) c\<rightarrow> s'"
schirmer@13688
   618
  proof -
schirmer@13688
   619
    from unroll obtain v s1 s2 where
schirmer@13688
   620
      normal_s1: "normal s1" and
schirmer@13688
   621
      eval_e: "G\<turnstile>s \<midarrow>e-\<succ>v\<rightarrow> s1" and
schirmer@13688
   622
      continue: "the_Bool v" and
schirmer@13688
   623
      eval_c: "G\<turnstile>s1 \<midarrow>c\<rightarrow> s2" and
schirmer@13688
   624
      s3: "s3=(abupd (absorb (Cont l)) s2)"
schirmer@13688
   625
      by  (unfold unroll_def) fast 
schirmer@13688
   626
    from eval_e normal_s1 have
schirmer@13688
   627
      "normal s"
schirmer@13688
   628
      by (rule eval_no_abrupt_lemma [rule_format])
schirmer@13688
   629
    with while eval_e continue eval_c s3 show ?thesis
schirmer@13688
   630
      by (auto intro!: eval.Loop)
schirmer@13688
   631
  qed
schirmer@13688
   632
qed
schirmer@13688
   633
schirmer@13688
   634
lemma MGFn_Loop:
schirmer@13688
   635
  assumes mfg_e: "G,(A::state triple set)\<turnstile>{=:n} \<langle>e\<rangle>\<^sub>e\<succ> {G\<rightarrow>}"
schirmer@13688
   636
  and     mfg_c: "G,A\<turnstile>{=:n} \<langle>c\<rangle>\<^sub>s\<succ> {G\<rightarrow>}"
schirmer@13688
   637
  and     wf: "wf_prog G" 
schirmer@13688
   638
shows "G,A\<turnstile>{=:n} \<langle>l\<bullet> While(e) c\<rangle>\<^sub>s\<succ> {G\<rightarrow>}"
schirmer@13688
   639
proof (rule MGFn_free_wt [rule_format],elim exE)
schirmer@13688
   640
  fix T L C
schirmer@13688
   641
  assume wt: "\<lparr>prg = G, cls = C, lcl = L\<rparr>\<turnstile>\<langle>l\<bullet> While(e) c\<rangle>\<^sub>s\<Colon>T"
schirmer@13688
   642
  then obtain eT where
schirmer@13688
   643
    wt_e: "\<lparr>prg = G, cls = C, lcl = L\<rparr>\<turnstile>e\<Colon>-eT" 
schirmer@13688
   644
    by cases simp
schirmer@13688
   645
  show ?thesis
schirmer@13688
   646
  proof (rule MGFn_NormalI)
schirmer@13688
   647
    show "G,A\<turnstile>{Normal ((\<lambda>Y' s' s. s' = s \<and> normal s) \<and>. G\<turnstile>init\<le>n)} 
schirmer@13688
   648
              .l\<bullet> While(e) c.
schirmer@13688
   649
              {\<lambda>Y s' s. G\<turnstile>s \<midarrow>In1r (l\<bullet> While(e) c)\<succ>\<rightarrow> (Y, s')}"
schirmer@13688
   650
    proof (rule conseq12 
schirmer@13688
   651
           [where ?P'="(\<lambda> Y s' s. (s,s') \<in> (unroll G l e c)\<^sup>* ) \<and>. G\<turnstile>init\<le>n"
schirmer@13688
   652
             and  ?Q'="((\<lambda> Y s' s. (\<exists> t b. (s,t) \<in> (unroll G l e c)\<^sup>* \<and> 
schirmer@13688
   653
                          Y=\<lfloor>b\<rfloor>\<^sub>e \<and> G\<turnstile>t \<midarrow>e-\<succ>b\<rightarrow> s')) 
schirmer@13688
   654
                        \<and>. G\<turnstile>init\<le>n)\<leftarrow>=False\<down>=\<diamondsuit>"])
schirmer@13688
   655
      show  "G,A\<turnstile>{(\<lambda>Y s' s. (s, s') \<in> (unroll G l e c)\<^sup>*) \<and>. G\<turnstile>init\<le>n} 
schirmer@13688
   656
                  .l\<bullet> While(e) c.
schirmer@13688
   657
                 {((\<lambda>Y s' s. (\<exists>t b. (s, t) \<in> (unroll G l e c)\<^sup>* \<and> 
schirmer@13688
   658
                                  Y = In1 b \<and> G\<turnstile>t \<midarrow>e-\<succ>b\<rightarrow> s')) 
schirmer@13688
   659
                              \<and>. G\<turnstile>init\<le>n)\<leftarrow>=False\<down>=\<diamondsuit>}"
schirmer@13688
   660
      proof (rule ax_derivs.Loop)
wenzelm@32962
   661
        from mfg_e
wenzelm@32962
   662
        show "G,A\<turnstile>{(\<lambda>Y s' s. (s, s') \<in> (unroll G l e c)\<^sup>*) \<and>. G\<turnstile>init\<le>n} 
schirmer@13688
   663
                   e-\<succ>
schirmer@13688
   664
                  {(\<lambda>Y s' s. (\<exists>t b. (s, t) \<in> (unroll G l e c)\<^sup>* \<and> 
schirmer@13688
   665
                                     Y = In1 b \<and> G\<turnstile>t \<midarrow>e-\<succ>b\<rightarrow> s')) 
schirmer@13688
   666
                   \<and>. G\<turnstile>init\<le>n}"
wenzelm@32962
   667
        proof (rule MGFnD' [THEN conseq12],clarsimp)
wenzelm@32962
   668
          fix s Z s' v
wenzelm@32962
   669
          assume "(Z, s) \<in> (unroll G l e c)\<^sup>*"
wenzelm@32962
   670
          moreover
wenzelm@32962
   671
          assume "G\<turnstile>s \<midarrow>e-\<succ>v\<rightarrow> s'"
wenzelm@32962
   672
          ultimately
wenzelm@32962
   673
          show "\<exists>t. (Z, t) \<in> (unroll G l e c)\<^sup>* \<and> G\<turnstile>t \<midarrow>e-\<succ>v\<rightarrow> s'"
wenzelm@32962
   674
            by blast
wenzelm@32962
   675
        qed
schirmer@13688
   676
      next
wenzelm@32962
   677
        from mfg_c
wenzelm@32962
   678
        show "G,A\<turnstile>{Normal (((\<lambda>Y s' s. \<exists>t b. (s, t) \<in> (unroll G l e c)\<^sup>* \<and>
schirmer@13688
   679
                                       Y = \<lfloor>b\<rfloor>\<^sub>e \<and> G\<turnstile>t \<midarrow>e-\<succ>b\<rightarrow> s') 
schirmer@13688
   680
                          \<and>. G\<turnstile>init\<le>n)\<leftarrow>=True)}
schirmer@13688
   681
                  .c.
schirmer@13688
   682
                  {abupd (absorb (Cont l)) .;
schirmer@13688
   683
                   ((\<lambda>Y s' s. (s, s') \<in> (unroll G l e c)\<^sup>*) \<and>. G\<turnstile>init\<le>n)}"
wenzelm@32962
   684
        proof (rule MGFnD' [THEN conseq12],clarsimp)
wenzelm@32962
   685
          fix Z s' s v t
wenzelm@32962
   686
          assume unroll: "(Z, t) \<in> (unroll G l e c)\<^sup>*"
wenzelm@32962
   687
          assume eval_e: "G\<turnstile>t \<midarrow>e-\<succ>v\<rightarrow> Norm s" 
wenzelm@32962
   688
          assume true: "the_Bool v"
wenzelm@32962
   689
          assume eval_c: "G\<turnstile>Norm s \<midarrow>c\<rightarrow> s'"
wenzelm@32962
   690
          show "(Z, abupd (absorb (Cont l)) s') \<in> (unroll G l e c)\<^sup>*"
wenzelm@32962
   691
          proof -
wenzelm@32962
   692
            note unroll
wenzelm@32962
   693
            also
wenzelm@32962
   694
            from eval_e true eval_c
wenzelm@32962
   695
            have "(t,abupd (absorb (Cont l)) s') \<in> unroll G l e c" 
wenzelm@32962
   696
              by (unfold unroll_def) force
wenzelm@32962
   697
            ultimately show ?thesis ..
wenzelm@32962
   698
          qed
wenzelm@32962
   699
        qed
schirmer@13688
   700
      qed
schirmer@13688
   701
    next
schirmer@13688
   702
      show 
wenzelm@32962
   703
        "\<forall>Y s Z.
schirmer@13688
   704
         (Normal ((\<lambda>Y' s' s. s' = s \<and> normal s) \<and>. G\<turnstile>init\<le>n)) Y s Z 
schirmer@13688
   705
         \<longrightarrow> (\<forall>Y' s'.
schirmer@13688
   706
               (\<forall>Y Z'. 
schirmer@13688
   707
                 ((\<lambda>Y s' s. (s, s') \<in> (unroll G l e c)\<^sup>*) \<and>. G\<turnstile>init\<le>n) Y s Z' 
schirmer@13688
   708
                 \<longrightarrow> (((\<lambda>Y s' s. \<exists>t b. (s,t) \<in> (unroll G l e c)\<^sup>* 
schirmer@13688
   709
                                       \<and> Y=\<lfloor>b\<rfloor>\<^sub>e \<and> G\<turnstile>t \<midarrow>e-\<succ>b\<rightarrow> s') 
schirmer@13688
   710
                     \<and>. G\<turnstile>init\<le>n)\<leftarrow>=False\<down>=\<diamondsuit>) Y' s' Z') 
schirmer@13688
   711
               \<longrightarrow> G\<turnstile>Z \<midarrow>\<langle>l\<bullet> While(e) c\<rangle>\<^sub>s\<succ>\<rightarrow> (Y', s'))"
schirmer@13688
   712
      proof (clarsimp)
wenzelm@32962
   713
        fix Y' s' s
wenzelm@32962
   714
        assume asm:
wenzelm@32962
   715
          "\<forall>Z'. (Z', Norm s) \<in> (unroll G l e c)\<^sup>* 
schirmer@13688
   716
                 \<longrightarrow> card (nyinitcls G s') \<le> n \<and>
schirmer@13688
   717
                     (\<exists>v. (\<exists>t. (Z', t) \<in> (unroll G l e c)\<^sup>* \<and> G\<turnstile>t \<midarrow>e-\<succ>v\<rightarrow> s') \<and>
schirmer@13688
   718
                     (fst s' = None \<longrightarrow> \<not> the_Bool v)) \<and> Y' = \<diamondsuit>"
wenzelm@32962
   719
        show "Y' = \<diamondsuit> \<and> G\<turnstile>Norm s \<midarrow>l\<bullet> While(e) c\<rightarrow> s'"
wenzelm@32962
   720
        proof -
wenzelm@32962
   721
          from asm obtain v t where 
wenzelm@32962
   722
            -- {* @{term "Z'"} gets instantiated with @{term "Norm s"} *}  
wenzelm@32962
   723
            unroll: "(Norm s, t) \<in> (unroll G l e c)\<^sup>*" and
schirmer@13688
   724
            eval_e: "G\<turnstile>t \<midarrow>e-\<succ>v\<rightarrow> s'" and
schirmer@13688
   725
            normal_termination: "normal s' \<longrightarrow> \<not> the_Bool v" and
wenzelm@32962
   726
             Y': "Y' = \<diamondsuit>"
wenzelm@32962
   727
            by auto
wenzelm@32962
   728
          from unroll eval_e normal_termination wt_e wf
wenzelm@32962
   729
          have "G\<turnstile>Norm s \<midarrow>l\<bullet> While(e) c\<rightarrow> s'"
wenzelm@32962
   730
            by (rule unroll_while)
wenzelm@32962
   731
          with Y' 
wenzelm@32962
   732
          show ?thesis
wenzelm@32962
   733
            by simp
wenzelm@32962
   734
        qed
schirmer@13688
   735
      qed
schirmer@13688
   736
    qed
schirmer@13688
   737
  qed
schirmer@13688
   738
qed
schirmer@13688
   739
schirmer@12925
   740
lemma MGFn_FVar:
schirmer@13688
   741
  fixes A :: "state triple set"
schirmer@13688
   742
 assumes mgf_init: "G,A\<turnstile>{=:n} \<langle>Init statDeclC\<rangle>\<^sub>s\<succ> {G\<rightarrow>}" 
schirmer@13688
   743
  and    mgf_e: "G,A\<turnstile>{=:n} \<langle>e\<rangle>\<^sub>e\<succ> {G\<rightarrow>}"
schirmer@13688
   744
  and    wf: "wf_prog G"
schirmer@13688
   745
  shows "G,A\<turnstile>{=:n} \<langle>{accC,statDeclC,stat}e..fn\<rangle>\<^sub>v\<succ> {G\<rightarrow>}"
schirmer@13688
   746
proof (rule MGFn_free_wt_da_NormalConformI [rule_format],clarsimp) 
schirmer@13688
   747
  note inj_term_simps [simp]
schirmer@13688
   748
  fix T L accC' V
schirmer@13688
   749
  assume wt: "\<lparr>prg = G, cls = accC', lcl = L\<rparr>\<turnstile>\<langle>{accC,statDeclC,stat}e..fn\<rangle>\<^sub>v\<Colon>T"
schirmer@13688
   750
  then obtain statC f where
schirmer@13688
   751
    wt_e: "\<lparr>prg=G, cls=accC', lcl=L\<rparr>\<turnstile>e\<Colon>-Class statC" and
schirmer@13688
   752
    accfield: "accfield G accC' statC fn = Some (statDeclC,f )" and
schirmer@13688
   753
    eq_accC: "accC=accC'" and
schirmer@13688
   754
    stat: "stat=is_static  f"
schirmer@13688
   755
    by (cases) (auto simp add: member_is_static_simp)
schirmer@13688
   756
  let ?Q="(\<lambda>Y s1 (x,s) . x = None \<and> 
schirmer@13688
   757
                (G\<turnstile>Norm s \<midarrow>Init statDeclC\<rightarrow> s1) \<and>
schirmer@13688
   758
                (\<exists> E. \<lparr>prg=G,cls=accC',lcl=L\<rparr>\<turnstile>dom (locals (store s1)) \<guillemotright>\<langle>e\<rangle>\<^sub>e\<guillemotright> E))
schirmer@13688
   759
                \<and>. G\<turnstile>init\<le>n \<and>. (\<lambda> s. s\<Colon>\<preceq>(G, L))"
schirmer@13688
   760
  show "G,A\<turnstile>{Normal
schirmer@13688
   761
             ((\<lambda>Y' s' s. s' = s \<and> abrupt s = None) \<and>. G\<turnstile>init\<le>n \<and>.
schirmer@13688
   762
              (\<lambda>s. s\<Colon>\<preceq>(G, L)) \<and>.
schirmer@13688
   763
              (\<lambda>s. \<lparr>prg=G,cls=accC',lcl=L\<rparr>
schirmer@13688
   764
                 \<turnstile> dom (locals (store s)) \<guillemotright> \<langle>{accC,statDeclC,stat}e..fn\<rangle>\<^sub>v\<guillemotright> V))
schirmer@13688
   765
             } {accC,statDeclC,stat}e..fn=\<succ>
schirmer@13688
   766
             {\<lambda>Y s' s. \<exists>vf. Y = \<lfloor>vf\<rfloor>\<^sub>v \<and> 
schirmer@13688
   767
                        G\<turnstile>s \<midarrow>{accC,statDeclC,stat}e..fn=\<succ>vf\<rightarrow> s'}"
schirmer@13688
   768
    (is "G,A\<turnstile>{Normal ?P} {accC,statDeclC,stat}e..fn=\<succ> {?R}")
schirmer@13688
   769
  proof (rule ax_derivs.FVar [where ?Q="?Q" ])
schirmer@13688
   770
    from mgf_init
schirmer@13688
   771
    show "G,A\<turnstile>{Normal ?P} .Init statDeclC. {?Q}"
schirmer@13688
   772
    proof (rule MGFnD' [THEN conseq12],clarsimp)
schirmer@13688
   773
      fix s s'
schirmer@13688
   774
      assume conf_s: "Norm s\<Colon>\<preceq>(G, L)"
schirmer@13688
   775
      assume da: "\<lparr>prg=G,cls=accC',lcl=L\<rparr>
schirmer@13688
   776
                    \<turnstile> dom (locals s) \<guillemotright>\<langle>{accC,statDeclC,stat}e..fn\<rangle>\<^sub>v\<guillemotright> V"
schirmer@13688
   777
      assume eval_init: "G\<turnstile>Norm s \<midarrow>Init statDeclC\<rightarrow> s'"
schirmer@13688
   778
      show "(\<exists>E. \<lparr>prg=G, cls=accC', lcl=L\<rparr>\<turnstile> dom (locals (store s')) \<guillemotright>\<langle>e\<rangle>\<^sub>e\<guillemotright> E) \<and>
schirmer@13688
   779
            s'\<Colon>\<preceq>(G, L)"
schirmer@13688
   780
      proof -
wenzelm@32962
   781
        from da 
wenzelm@32962
   782
        obtain E where
wenzelm@32962
   783
          "\<lparr>prg=G, cls=accC', lcl=L\<rparr>\<turnstile> dom (locals s) \<guillemotright>\<langle>e\<rangle>\<^sub>e\<guillemotright> E"
wenzelm@32962
   784
          by cases simp
wenzelm@32962
   785
        moreover
wenzelm@32962
   786
        from eval_init
wenzelm@32962
   787
        have "dom (locals s) \<subseteq> dom (locals (store s'))"
wenzelm@32962
   788
          by (rule dom_locals_eval_mono [elim_format]) simp
wenzelm@32962
   789
        ultimately obtain E' where
wenzelm@32962
   790
          "\<lparr>prg=G, cls=accC', lcl=L\<rparr>\<turnstile> dom (locals (store s')) \<guillemotright>\<langle>e\<rangle>\<^sub>e\<guillemotright> E'"
wenzelm@32962
   791
          by (rule da_weakenE)
wenzelm@32962
   792
        moreover
wenzelm@32962
   793
        have "s'\<Colon>\<preceq>(G, L)"
wenzelm@32962
   794
        proof -
wenzelm@32962
   795
          have wt_init: "\<lparr>prg=G, cls=accC, lcl=L\<rparr>\<turnstile>(Init statDeclC)\<Colon>\<surd>"
wenzelm@32962
   796
          proof -
wenzelm@32962
   797
            from wf wt_e 
wenzelm@32962
   798
            have iscls_statC: "is_class G statC"
wenzelm@32962
   799
              by (auto dest: ty_expr_is_type type_is_class)
wenzelm@32962
   800
            with wf accfield 
wenzelm@32962
   801
            have iscls_statDeclC: "is_class G statDeclC"
wenzelm@32962
   802
              by (auto dest!: accfield_fields dest: fields_declC)
wenzelm@32962
   803
            thus ?thesis by simp
wenzelm@32962
   804
          qed
wenzelm@32962
   805
          obtain I where 
wenzelm@32962
   806
            da_init: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>
schirmer@13688
   807
               \<turnstile> dom (locals (store ((Norm s)::state))) \<guillemotright>\<langle>Init statDeclC\<rangle>\<^sub>s\<guillemotright> I"
wenzelm@32962
   808
            by (auto intro: da_Init [simplified] assigned.select_convs)
wenzelm@32962
   809
          from eval_init conf_s wt_init da_init  wf
wenzelm@32962
   810
          show ?thesis
wenzelm@32962
   811
            by (rule eval_type_soundE)
wenzelm@32962
   812
        qed
wenzelm@32962
   813
        ultimately show ?thesis by iprover
schirmer@13688
   814
      qed
schirmer@13688
   815
    qed
schirmer@13688
   816
  next
schirmer@13688
   817
    from mgf_e
schirmer@13688
   818
    show "G,A\<turnstile>{?Q} e-\<succ> {\<lambda>Val:a:. fvar statDeclC stat fn a ..; ?R}"
schirmer@13688
   819
    proof (rule MGFnD' [THEN conseq12],clarsimp)
schirmer@13688
   820
      fix s0 s1 s2 E a
schirmer@13688
   821
      let ?fvar = "fvar statDeclC stat fn a s2"
schirmer@13688
   822
      assume eval_init: "G\<turnstile>Norm s0 \<midarrow>Init statDeclC\<rightarrow> s1"
schirmer@13688
   823
      assume eval_e: "G\<turnstile>s1 \<midarrow>e-\<succ>a\<rightarrow> s2"
schirmer@13688
   824
      assume conf_s1: "s1\<Colon>\<preceq>(G, L)"
schirmer@13688
   825
      assume da_e: "\<lparr>prg=G,cls=accC',lcl=L\<rparr>\<turnstile> dom (locals (store s1)) \<guillemotright>\<langle>e\<rangle>\<^sub>e\<guillemotright> E"
schirmer@13688
   826
      show "G\<turnstile>Norm s0 \<midarrow>{accC,statDeclC,stat}e..fn=\<succ>fst ?fvar\<rightarrow> snd ?fvar"
schirmer@13688
   827
      proof -
wenzelm@32962
   828
        obtain v s2' where
wenzelm@32962
   829
          v: "v=fst ?fvar" and s2': "s2'=snd ?fvar"
wenzelm@32962
   830
          by simp
wenzelm@32962
   831
        obtain s3 where
wenzelm@32962
   832
          s3: "s3= check_field_access G accC' statDeclC fn stat a s2'"
wenzelm@32962
   833
          by simp
wenzelm@32962
   834
        have eq_s3_s2': "s3=s2'"
wenzelm@32962
   835
        proof -
wenzelm@32962
   836
          from eval_e conf_s1 wt_e da_e wf obtain
wenzelm@32962
   837
            conf_s2: "s2\<Colon>\<preceq>(G, L)"  and
wenzelm@32962
   838
            conf_a: "normal s2 \<Longrightarrow> G,store s2\<turnstile>a\<Colon>\<preceq>Class statC"
wenzelm@32962
   839
            by (rule eval_type_soundE) simp
wenzelm@32962
   840
          from accfield wt_e eval_init eval_e conf_s2 conf_a _ wf
wenzelm@32962
   841
          show ?thesis
wenzelm@32962
   842
            by (rule  error_free_field_access 
schirmer@13688
   843
                      [where ?v=v and ?s2'=s2',elim_format])
wenzelm@32962
   844
               (simp add: s3 v s2' stat)+
schirmer@13688
   845
        qed
wenzelm@32962
   846
        from eval_init eval_e 
wenzelm@32962
   847
        show ?thesis
wenzelm@32962
   848
          apply (rule eval.FVar [where ?s2'=s2'])
wenzelm@32962
   849
          apply  (simp add: s2')
wenzelm@32962
   850
          apply  (simp add: s3 [symmetric]   eq_s3_s2' eq_accC s2' [symmetric])
wenzelm@32962
   851
          done
schirmer@13688
   852
      qed
schirmer@13688
   853
    qed
schirmer@13688
   854
  qed
schirmer@13688
   855
qed
schirmer@12925
   856
schirmer@12925
   857
schirmer@13688
   858
lemma MGFn_Fin:
schirmer@13688
   859
  assumes wf: "wf_prog G" 
schirmer@13688
   860
  and     mgf_c1: "G,A\<turnstile>{=:n} \<langle>c1\<rangle>\<^sub>s\<succ> {G\<rightarrow>}"
schirmer@13688
   861
  and     mgf_c2: "G,A\<turnstile>{=:n} \<langle>c2\<rangle>\<^sub>s\<succ> {G\<rightarrow>}"
schirmer@13688
   862
  shows "G,(A\<Colon>state triple set)\<turnstile>{=:n} \<langle>c1 Finally c2\<rangle>\<^sub>s\<succ> {G\<rightarrow>}"
schirmer@13688
   863
proof (rule MGFn_free_wt_da_NormalConformI [rule_format],clarsimp)
schirmer@13688
   864
  fix T L accC C 
schirmer@13688
   865
  assume wt: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>In1r (c1 Finally c2)\<Colon>T"
schirmer@13688
   866
  then obtain
schirmer@13688
   867
    wt_c1: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>c1\<Colon>\<surd>" and
schirmer@13688
   868
    wt_c2: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>c2\<Colon>\<surd>"
schirmer@13688
   869
    by cases simp
schirmer@13688
   870
  let  ?Q = "(\<lambda>Y' s' s. normal s \<and> G\<turnstile>s \<midarrow>c1\<rightarrow> s' \<and> 
schirmer@13688
   871
               (\<exists> C1. \<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>dom (locals (store s)) \<guillemotright>\<langle>c1\<rangle>\<^sub>s\<guillemotright> C1)
schirmer@13688
   872
               \<and> s\<Colon>\<preceq>(G, L)) 
schirmer@13688
   873
             \<and>. G\<turnstile>init\<le>n"
schirmer@13688
   874
  show "G,A\<turnstile>{Normal
schirmer@13688
   875
              ((\<lambda>Y' s' s. s' = s \<and> abrupt s = None) \<and>. G\<turnstile>init\<le>n \<and>.
schirmer@13688
   876
              (\<lambda>s. s\<Colon>\<preceq>(G, L)) \<and>.
schirmer@13688
   877
              (\<lambda>s. \<lparr>prg=G,cls=accC,lcl =L\<rparr>  
schirmer@13688
   878
                     \<turnstile>dom (locals (store s)) \<guillemotright>\<langle>c1 Finally c2\<rangle>\<^sub>s\<guillemotright> C))}
schirmer@13688
   879
             .c1 Finally c2. 
schirmer@13688
   880
             {\<lambda>Y s' s. Y = \<diamondsuit> \<and> G\<turnstile>s \<midarrow>c1 Finally c2\<rightarrow> s'}"
schirmer@13688
   881
    (is "G,A\<turnstile>{Normal ?P} .c1 Finally c2. {?R}")
schirmer@13688
   882
  proof (rule ax_derivs.Fin [where ?Q="?Q"])
schirmer@13688
   883
    from mgf_c1
schirmer@13688
   884
    show "G,A\<turnstile>{Normal ?P} .c1. {?Q}"
schirmer@13688
   885
    proof (rule MGFnD' [THEN conseq12],clarsimp)
schirmer@13688
   886
      fix s0
schirmer@13688
   887
      assume "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile> dom (locals s0) \<guillemotright>\<langle>c1 Finally c2\<rangle>\<^sub>s\<guillemotright> C"
schirmer@13688
   888
      thus "\<exists>C1. \<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile> dom (locals s0) \<guillemotright>\<langle>c1\<rangle>\<^sub>s\<guillemotright> C1"
wenzelm@32962
   889
        by cases (auto simp add: inj_term_simps)
schirmer@13688
   890
    qed
schirmer@13688
   891
  next
schirmer@13688
   892
    from mgf_c2
schirmer@13688
   893
    show "\<forall>abr. G,A\<turnstile>{?Q \<and>. (\<lambda>s. abr = abrupt s) ;. abupd (\<lambda>abr. None)} .c2.
schirmer@13688
   894
          {abupd (abrupt_if (abr \<noteq> None) abr) .; ?R}"
schirmer@13688
   895
    proof (rule MGFnD' [THEN conseq12, THEN allI],clarsimp)
schirmer@13688
   896
      fix s0 s1 s2 C1
schirmer@13688
   897
      assume da_c1:"\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile> dom (locals s0) \<guillemotright>\<langle>c1\<rangle>\<^sub>s\<guillemotright> C1"
schirmer@13688
   898
      assume conf_s0: "Norm s0\<Colon>\<preceq>(G, L)"
schirmer@13688
   899
      assume eval_c1: "G\<turnstile>Norm s0 \<midarrow>c1\<rightarrow> s1"
schirmer@13688
   900
      assume eval_c2: "G\<turnstile>abupd (\<lambda>abr. None) s1 \<midarrow>c2\<rightarrow> s2"
schirmer@13688
   901
      show "G\<turnstile>Norm s0 \<midarrow>c1 Finally c2
schirmer@13688
   902
               \<rightarrow> abupd (abrupt_if (\<exists>y. abrupt s1 = Some y) (abrupt s1)) s2"
schirmer@13688
   903
      proof -
wenzelm@32962
   904
        obtain abr1 str1 where s1: "s1=(abr1,str1)"
wenzelm@32962
   905
          by (cases s1)
wenzelm@32962
   906
        with eval_c1 eval_c2 obtain
wenzelm@32962
   907
          eval_c1': "G\<turnstile>Norm s0 \<midarrow>c1\<rightarrow> (abr1,str1)" and
wenzelm@32962
   908
          eval_c2': "G\<turnstile>Norm str1 \<midarrow>c2\<rightarrow> s2"
wenzelm@32962
   909
          by simp
wenzelm@32962
   910
        obtain s3 where 
wenzelm@32962
   911
          s3: "s3 = (if \<exists>err. abr1 = Some (Error err) 
wenzelm@32962
   912
                        then (abr1, str1)
schirmer@13688
   913
                        else abupd (abrupt_if (abr1 \<noteq> None) abr1) s2)"
wenzelm@32962
   914
          by simp
wenzelm@32962
   915
        from eval_c1' conf_s0 wt_c1 _ wf 
wenzelm@32962
   916
        have "error_free (abr1,str1)"
wenzelm@32962
   917
          by (rule eval_type_soundE) (insert da_c1,auto)
wenzelm@32962
   918
        with s3 have eq_s3: "s3=abupd (abrupt_if (abr1 \<noteq> None) abr1) s2"
wenzelm@32962
   919
          by (simp add: error_free_def)
wenzelm@32962
   920
        from eval_c1' eval_c2' s3
wenzelm@32962
   921
        show ?thesis
wenzelm@32962
   922
          by (rule eval.Fin [elim_format]) (simp add: s1 eq_s3)
schirmer@13688
   923
      qed
schirmer@13688
   924
    qed 
schirmer@13688
   925
  qed
schirmer@13688
   926
qed
schirmer@13688
   927
      
schirmer@13688
   928
lemma Body_no_break:
schirmer@13688
   929
 assumes eval_init: "G\<turnstile>Norm s0 \<midarrow>Init D\<rightarrow> s1" 
schirmer@13688
   930
   and      eval_c: "G\<turnstile>s1 \<midarrow>c\<rightarrow> s2" 
schirmer@13688
   931
   and       jmpOk: "jumpNestingOkS {Ret} c"
schirmer@13688
   932
   and        wt_c: "\<lparr>prg=G, cls=C, lcl=L\<rparr>\<turnstile>c\<Colon>\<surd>"
schirmer@13688
   933
   and        clsD: "class G D=Some d"
schirmer@13688
   934
   and          wf: "wf_prog G" 
schirmer@13688
   935
  shows "\<forall> l. abrupt s2 \<noteq> Some (Jump (Break l)) \<and> 
schirmer@13688
   936
              abrupt s2 \<noteq> Some (Jump (Cont l))"
schirmer@13688
   937
proof
schirmer@13688
   938
  fix l show "abrupt s2 \<noteq> Some (Jump (Break l)) \<and>  
schirmer@13688
   939
              abrupt s2 \<noteq> Some (Jump (Cont l))"
schirmer@13688
   940
  proof -
wenzelm@26932
   941
    fix accC from clsD have wt_init: "\<lparr>prg=G, cls=accC, lcl=L\<rparr>\<turnstile>(Init D)\<Colon>\<surd>"
schirmer@13688
   942
      by auto
schirmer@13688
   943
    from eval_init wf
schirmer@13688
   944
    have s1_no_jmp: "\<And> j. abrupt s1 \<noteq> Some (Jump j)"
schirmer@13688
   945
      by - (rule eval_statement_no_jump [OF _ _ _ wt_init],auto)
schirmer@13688
   946
    from eval_c _ wt_c wf
schirmer@13688
   947
    show ?thesis
schirmer@13688
   948
      apply (rule jumpNestingOk_eval [THEN conjE, elim_format])
schirmer@13688
   949
      using jmpOk s1_no_jmp
schirmer@13688
   950
      apply auto
schirmer@13688
   951
      done
schirmer@13688
   952
  qed
schirmer@13688
   953
qed
schirmer@12925
   954
schirmer@13688
   955
lemma MGFn_Body:
schirmer@13688
   956
  assumes wf: "wf_prog G"
schirmer@13688
   957
  and     mgf_init: "G,A\<turnstile>{=:n} \<langle>Init D\<rangle>\<^sub>s\<succ> {G\<rightarrow>}"
schirmer@13688
   958
  and     mgf_c: "G,A\<turnstile>{=:n} \<langle>c\<rangle>\<^sub>s\<succ> {G\<rightarrow>}"
schirmer@13688
   959
  shows  "G,(A\<Colon>state triple set)\<turnstile>{=:n} \<langle>Body D c\<rangle>\<^sub>e\<succ> {G\<rightarrow>}"
schirmer@13688
   960
proof (rule MGFn_free_wt_da_NormalConformI [rule_format],clarsimp)
schirmer@13688
   961
  fix T L accC E
schirmer@13688
   962
  assume wt: "\<lparr>prg=G, cls=accC,lcl=L\<rparr>\<turnstile>\<langle>Body D c\<rangle>\<^sub>e\<Colon>T"
schirmer@13688
   963
  let ?Q="(\<lambda>Y' s' s. normal s \<and> G\<turnstile>s \<midarrow>Init D\<rightarrow> s' \<and> jumpNestingOkS {Ret} c) 
schirmer@13688
   964
          \<and>. G\<turnstile>init\<le>n" 
schirmer@13688
   965
  show "G,A\<turnstile>{Normal
schirmer@13688
   966
               ((\<lambda>Y' s' s. s' = s \<and> fst s = None) \<and>. G\<turnstile>init\<le>n \<and>.
schirmer@13688
   967
                (\<lambda>s. s\<Colon>\<preceq>(G, L)) \<and>.
schirmer@13688
   968
                (\<lambda>s. \<lparr>prg=G,cls=accC,lcl=L\<rparr>
schirmer@13688
   969
                       \<turnstile> dom (locals (store s)) \<guillemotright>\<langle>Body D c\<rangle>\<^sub>e\<guillemotright> E))}
schirmer@13688
   970
             Body D c-\<succ> 
schirmer@13688
   971
             {\<lambda>Y s' s. \<exists>v. Y = In1 v \<and> G\<turnstile>s \<midarrow>Body D c-\<succ>v\<rightarrow> s'}"
schirmer@13688
   972
    (is "G,A\<turnstile>{Normal ?P} Body D c-\<succ> {?R}")
schirmer@13688
   973
  proof (rule ax_derivs.Body [where ?Q="?Q"])
schirmer@13688
   974
    from mgf_init
schirmer@13688
   975
    show "G,A\<turnstile>{Normal ?P} .Init D. {?Q}"
schirmer@13688
   976
    proof (rule MGFnD' [THEN conseq12],clarsimp)
schirmer@13688
   977
      fix s0
schirmer@13688
   978
      assume da: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile> dom (locals s0) \<guillemotright>\<langle>Body D c\<rangle>\<^sub>e\<guillemotright> E"
schirmer@13688
   979
      thus "jumpNestingOkS {Ret} c"
wenzelm@32962
   980
        by cases simp
schirmer@13688
   981
    qed
schirmer@13688
   982
  next
schirmer@13688
   983
    from mgf_c
schirmer@13688
   984
    show "G,A\<turnstile>{?Q}.c.{\<lambda>s.. abupd (absorb Ret) .; ?R\<leftarrow>\<lfloor>the (locals s Result)\<rfloor>\<^sub>e}"
schirmer@13688
   985
    proof (rule MGFnD' [THEN conseq12],clarsimp)
schirmer@13688
   986
      fix s0 s1 s2
schirmer@13688
   987
      assume eval_init: "G\<turnstile>Norm s0 \<midarrow>Init D\<rightarrow> s1"
schirmer@13688
   988
      assume eval_c: "G\<turnstile>s1 \<midarrow>c\<rightarrow> s2"
schirmer@13688
   989
      assume nestingOk: "jumpNestingOkS {Ret} c"
schirmer@13688
   990
      show "G\<turnstile>Norm s0 \<midarrow>Body D c-\<succ>the (locals (store s2) Result)
schirmer@13688
   991
              \<rightarrow> abupd (absorb Ret) s2"
schirmer@13688
   992
      proof -
wenzelm@32962
   993
        from wt obtain d where 
schirmer@13688
   994
          d: "class G D=Some d" and
schirmer@13688
   995
          wt_c: "\<lparr>prg = G, cls = accC, lcl = L\<rparr>\<turnstile>c\<Colon>\<surd>"
wenzelm@32962
   996
          by cases auto
wenzelm@32962
   997
        obtain s3 where 
wenzelm@32962
   998
          s3: "s3= (if \<exists>l. fst s2 = Some (Jump (Break l)) \<or>
schirmer@13688
   999
                           fst s2 = Some (Jump (Cont l))
schirmer@13688
  1000
                       then abupd (\<lambda>x. Some (Error CrossMethodJump)) s2 
schirmer@13688
  1001
                       else s2)"
wenzelm@32962
  1002
          by simp
wenzelm@32962
  1003
        from eval_init eval_c nestingOk wt_c d wf
wenzelm@32962
  1004
        have eq_s3_s2: "s3=s2"
wenzelm@32962
  1005
          by (rule Body_no_break [elim_format]) (simp add: s3)
wenzelm@32962
  1006
        from eval_init eval_c s3
wenzelm@32962
  1007
        show ?thesis
wenzelm@32962
  1008
          by (rule eval.Body [elim_format]) (simp add: eq_s3_s2)
schirmer@13688
  1009
      qed
schirmer@13688
  1010
    qed
schirmer@13688
  1011
  qed
schirmer@13688
  1012
qed
schirmer@12925
  1013
schirmer@13688
  1014
lemma MGFn_lemma:
schirmer@13688
  1015
  assumes mgf_methds: 
schirmer@13688
  1016
           "\<And> n. \<forall> C sig. G,(A::state triple set)\<turnstile>{=:n} \<langle>Methd C sig\<rangle>\<^sub>e\<succ> {G\<rightarrow>}"
schirmer@13688
  1017
  and wf: "wf_prog G"
schirmer@13688
  1018
  shows "\<And> t. G,A\<turnstile>{=:n} t\<succ> {G\<rightarrow>}"
schirmer@13688
  1019
proof (induct rule: full_nat_induct)
schirmer@13688
  1020
  fix n t
schirmer@13688
  1021
  assume hyp: "\<forall> m. Suc m \<le> n \<longrightarrow> (\<forall> t. G,A\<turnstile>{=:m} t\<succ> {G\<rightarrow>})"
schirmer@13688
  1022
  show "G,A\<turnstile>{=:n} t\<succ> {G\<rightarrow>}"
schirmer@13688
  1023
  proof -
schirmer@13688
  1024
  { 
schirmer@13688
  1025
    fix v e c es
schirmer@13688
  1026
    have "G,A\<turnstile>{=:n} \<langle>v\<rangle>\<^sub>v\<succ> {G\<rightarrow>}" and 
schirmer@13688
  1027
      "G,A\<turnstile>{=:n} \<langle>e\<rangle>\<^sub>e\<succ> {G\<rightarrow>}" and
schirmer@13688
  1028
      "G,A\<turnstile>{=:n} \<langle>c\<rangle>\<^sub>s\<succ> {G\<rightarrow>}" and  
schirmer@13688
  1029
      "G,A\<turnstile>{=:n} \<langle>es\<rangle>\<^sub>l\<succ> {G\<rightarrow>}"
wenzelm@18459
  1030
    proof (induct rule: var_expr_stmt.inducts)
schirmer@13688
  1031
      case (LVar v)
schirmer@13688
  1032
      show "G,A\<turnstile>{=:n} \<langle>LVar v\<rangle>\<^sub>v\<succ> {G\<rightarrow>}"
wenzelm@32962
  1033
        apply (rule MGFn_NormalI)
wenzelm@32962
  1034
        apply (rule ax_derivs.LVar [THEN conseq1])
wenzelm@32962
  1035
        apply (clarsimp)
wenzelm@32962
  1036
        apply (rule eval.LVar)
wenzelm@32962
  1037
        done
schirmer@13688
  1038
    next
schirmer@13688
  1039
      case (FVar accC statDeclC stat e fn)
wenzelm@23366
  1040
      from MGFn_Init [OF hyp] and `G,A\<turnstile>{=:n} \<langle>e\<rangle>\<^sub>e\<succ> {G\<rightarrow>}` and wf
schirmer@13688
  1041
      show ?case
wenzelm@32962
  1042
        by (rule MGFn_FVar)
schirmer@13688
  1043
    next
schirmer@13688
  1044
      case (AVar e1 e2)
wenzelm@23366
  1045
      note mgf_e1 = `G,A\<turnstile>{=:n} \<langle>e1\<rangle>\<^sub>e\<succ> {G\<rightarrow>}`
wenzelm@23366
  1046
      note mgf_e2 = `G,A\<turnstile>{=:n} \<langle>e2\<rangle>\<^sub>e\<succ> {G\<rightarrow>}`
schirmer@13688
  1047
      show "G,A\<turnstile>{=:n} \<langle>e1.[e2]\<rangle>\<^sub>v\<succ> {G\<rightarrow>}"
wenzelm@32962
  1048
        apply (rule MGFn_NormalI)
wenzelm@32962
  1049
        apply (rule ax_derivs.AVar)
wenzelm@32962
  1050
        apply  (rule MGFnD [OF mgf_e1, THEN ax_NormalD])
wenzelm@32962
  1051
        apply (rule allI)
wenzelm@32962
  1052
        apply (rule MGFnD' [OF mgf_e2, THEN conseq12])
nipkow@45761
  1053
        apply (fastforce intro: eval.AVar)
wenzelm@32962
  1054
        done
schirmer@13688
  1055
    next
schirmer@13688
  1056
      case (InsInitV c v)
schirmer@13688
  1057
      show ?case
wenzelm@32962
  1058
        by (rule MGFn_NormalI) (rule ax_derivs.InsInitV)
schirmer@13688
  1059
    next
schirmer@13688
  1060
      case (NewC C)
schirmer@13688
  1061
      show ?case
wenzelm@32962
  1062
        apply (rule MGFn_NormalI)
wenzelm@32962
  1063
        apply (rule ax_derivs.NewC)
wenzelm@32962
  1064
        apply (rule MGFn_InitD [OF hyp, THEN conseq2])
nipkow@45761
  1065
        apply (fastforce intro: eval.NewC)
wenzelm@32962
  1066
        done
schirmer@13688
  1067
    next
schirmer@13688
  1068
      case (NewA T e)
schirmer@13688
  1069
      thus ?case
wenzelm@32962
  1070
        apply -
wenzelm@32962
  1071
        apply (rule MGFn_NormalI) 
wenzelm@32962
  1072
        apply (rule ax_derivs.NewA 
schirmer@13688
  1073
               [where ?Q = "(\<lambda>Y' s' s. normal s \<and> G\<turnstile>s \<midarrow>In1r (init_comp_ty T) 
schirmer@13688
  1074
                              \<succ>\<rightarrow> (Y',s')) \<and>. G\<turnstile>init\<le>n"])
wenzelm@32962
  1075
        apply  (simp add: init_comp_ty_def split add: split_if)
wenzelm@32962
  1076
        apply  (rule conjI, clarsimp)
wenzelm@32962
  1077
        apply   (rule MGFn_InitD [OF hyp, THEN conseq2])
wenzelm@32962
  1078
        apply   (clarsimp intro: eval.Init)
wenzelm@32962
  1079
        apply  clarsimp
wenzelm@32962
  1080
        apply  (rule ax_derivs.Skip [THEN conseq1])
wenzelm@32962
  1081
        apply  (clarsimp intro: eval.Skip)
wenzelm@32962
  1082
        apply (erule MGFnD' [THEN conseq12])
nipkow@45761
  1083
        apply (fastforce intro: eval.NewA)
wenzelm@32962
  1084
        done
schirmer@13688
  1085
    next
schirmer@13688
  1086
      case (Cast C e)
schirmer@13688
  1087
      thus ?case
wenzelm@32962
  1088
        apply -
wenzelm@32962
  1089
        apply (rule MGFn_NormalI)
wenzelm@32962
  1090
        apply (erule MGFnD'[THEN conseq12,THEN ax_derivs.Cast])
nipkow@45761
  1091
        apply (fastforce intro: eval.Cast)
wenzelm@32962
  1092
        done
schirmer@13688
  1093
    next
schirmer@13688
  1094
      case (Inst e C)
schirmer@13688
  1095
      thus ?case
wenzelm@32962
  1096
        apply -
wenzelm@32962
  1097
        apply (rule MGFn_NormalI)
wenzelm@32962
  1098
        apply (erule MGFnD'[THEN conseq12,THEN ax_derivs.Inst])
nipkow@45761
  1099
        apply (fastforce intro: eval.Inst)
wenzelm@32962
  1100
        done
schirmer@13688
  1101
    next
schirmer@13688
  1102
      case (Lit v)
schirmer@13688
  1103
      show ?case
wenzelm@32962
  1104
        apply -
wenzelm@32962
  1105
        apply (rule MGFn_NormalI)
wenzelm@32962
  1106
        apply (rule ax_derivs.Lit [THEN conseq1])
nipkow@45761
  1107
        apply (fastforce intro: eval.Lit)
wenzelm@32962
  1108
        done
schirmer@13688
  1109
    next
schirmer@13688
  1110
      case (UnOp unop e)
schirmer@13688
  1111
      thus ?case
wenzelm@32962
  1112
        apply -
wenzelm@32962
  1113
        apply (rule MGFn_NormalI)
wenzelm@32962
  1114
        apply (rule ax_derivs.UnOp)
wenzelm@32962
  1115
        apply (erule MGFnD' [THEN conseq12])
nipkow@45761
  1116
        apply (fastforce intro: eval.UnOp)
wenzelm@32962
  1117
        done
schirmer@13688
  1118
    next
schirmer@13688
  1119
      case (BinOp binop e1 e2)
schirmer@13688
  1120
      thus ?case
wenzelm@32962
  1121
        apply -
wenzelm@32962
  1122
        apply (rule MGFn_NormalI)
wenzelm@32962
  1123
        apply (rule ax_derivs.BinOp)
wenzelm@32962
  1124
        apply  (erule MGFnD [THEN ax_NormalD])
wenzelm@32962
  1125
        apply (rule allI)
wenzelm@32962
  1126
        apply (case_tac "need_second_arg binop v1")
wenzelm@32962
  1127
        apply  simp
wenzelm@32962
  1128
        apply  (erule MGFnD' [THEN conseq12])
nipkow@45761
  1129
        apply  (fastforce intro: eval.BinOp)
wenzelm@32962
  1130
        apply simp
wenzelm@32962
  1131
        apply (rule ax_Normal_cases)
wenzelm@32962
  1132
        apply  (rule ax_derivs.Skip [THEN conseq1])
wenzelm@32962
  1133
        apply  clarsimp
wenzelm@32962
  1134
        apply  (rule eval_BinOp_arg2_indepI)
wenzelm@32962
  1135
        apply   simp
wenzelm@32962
  1136
        apply  simp
wenzelm@32962
  1137
        apply (rule ax_derivs.Abrupt [THEN conseq1], clarsimp simp add: Let_def)
nipkow@45761
  1138
        apply (fastforce intro: eval.BinOp)
wenzelm@32962
  1139
        done
schirmer@13688
  1140
    next
schirmer@13688
  1141
      case Super
schirmer@13688
  1142
      show ?case
wenzelm@32962
  1143
        apply -
wenzelm@32962
  1144
        apply (rule MGFn_NormalI)
wenzelm@32962
  1145
        apply (rule ax_derivs.Super [THEN conseq1])
nipkow@45761
  1146
        apply (fastforce intro: eval.Super)
wenzelm@32962
  1147
        done
schirmer@13688
  1148
    next
schirmer@13688
  1149
      case (Acc v)
schirmer@13688
  1150
      thus ?case
wenzelm@32962
  1151
        apply -
wenzelm@32962
  1152
        apply (rule MGFn_NormalI)
wenzelm@32962
  1153
        apply (erule MGFnD'[THEN conseq12,THEN ax_derivs.Acc])
nipkow@45761
  1154
        apply (fastforce intro: eval.Acc simp add: split_paired_all)
wenzelm@32962
  1155
        done
schirmer@13688
  1156
    next
schirmer@13688
  1157
      case (Ass v e)
schirmer@13688
  1158
      thus "G,A\<turnstile>{=:n} \<langle>v:=e\<rangle>\<^sub>e\<succ> {G\<rightarrow>}"
wenzelm@32962
  1159
        apply -
wenzelm@32962
  1160
        apply (rule MGFn_NormalI)
wenzelm@32962
  1161
        apply (rule ax_derivs.Ass)
wenzelm@32962
  1162
        apply  (erule MGFnD [THEN ax_NormalD])
wenzelm@32962
  1163
        apply (rule allI)
wenzelm@32962
  1164
        apply (erule MGFnD'[THEN conseq12])
nipkow@45761
  1165
        apply (fastforce intro: eval.Ass simp add: split_paired_all)
wenzelm@32962
  1166
        done
schirmer@13688
  1167
    next
schirmer@13688
  1168
      case (Cond e1 e2 e3)
schirmer@13688
  1169
      thus "G,A\<turnstile>{=:n} \<langle>e1 ? e2 : e3\<rangle>\<^sub>e\<succ> {G\<rightarrow>}"
wenzelm@32962
  1170
        apply -
wenzelm@32962
  1171
        apply (rule MGFn_NormalI)
wenzelm@32962
  1172
        apply (rule ax_derivs.Cond)
wenzelm@32962
  1173
        apply  (erule MGFnD [THEN ax_NormalD])
wenzelm@32962
  1174
        apply (rule allI)
wenzelm@32962
  1175
        apply (rule ax_Normal_cases)
wenzelm@32962
  1176
        prefer 2
wenzelm@32962
  1177
        apply  (rule ax_derivs.Abrupt [THEN conseq1],clarsimp simp add: Let_def)
nipkow@45761
  1178
        apply  (fastforce intro: eval.Cond)
wenzelm@32962
  1179
        apply (case_tac "b")
wenzelm@32962
  1180
        apply  simp
wenzelm@32962
  1181
        apply  (erule MGFnD'[THEN conseq12])
nipkow@45761
  1182
        apply  (fastforce intro: eval.Cond)
wenzelm@32962
  1183
        apply simp
wenzelm@32962
  1184
        apply (erule MGFnD'[THEN conseq12])
nipkow@45761
  1185
        apply (fastforce intro: eval.Cond)
wenzelm@32962
  1186
        done
schirmer@13688
  1187
    next
schirmer@13688
  1188
      case (Call accC statT mode e mn pTs' ps)
wenzelm@23366
  1189
      note mgf_e = `G,A\<turnstile>{=:n} \<langle>e\<rangle>\<^sub>e\<succ> {G\<rightarrow>}`
wenzelm@23366
  1190
      note mgf_ps = `G,A\<turnstile>{=:n} \<langle>ps\<rangle>\<^sub>l\<succ> {G\<rightarrow>}`
schirmer@13688
  1191
      from mgf_methds mgf_e mgf_ps wf
schirmer@13688
  1192
      show "G,A\<turnstile>{=:n} \<langle>{accC,statT,mode}e\<cdot>mn({pTs'}ps)\<rangle>\<^sub>e\<succ> {G\<rightarrow>}"
wenzelm@32962
  1193
        by (rule MGFn_Call)
schirmer@13688
  1194
    next
schirmer@13688
  1195
      case (Methd D mn)
schirmer@13688
  1196
      from mgf_methds
schirmer@13688
  1197
      show "G,A\<turnstile>{=:n} \<langle>Methd D mn\<rangle>\<^sub>e\<succ> {G\<rightarrow>}"
wenzelm@32962
  1198
        by simp
schirmer@13688
  1199
    next
schirmer@13688
  1200
      case (Body D c)
wenzelm@23366
  1201
      note mgf_c = `G,A\<turnstile>{=:n} \<langle>c\<rangle>\<^sub>s\<succ> {G\<rightarrow>}`
schirmer@13688
  1202
      from wf MGFn_Init [OF hyp] mgf_c
schirmer@13688
  1203
      show "G,A\<turnstile>{=:n} \<langle>Body D c\<rangle>\<^sub>e\<succ> {G\<rightarrow>}"
wenzelm@32962
  1204
        by (rule MGFn_Body)
schirmer@13688
  1205
    next
schirmer@13688
  1206
      case (InsInitE c e)
schirmer@13688
  1207
      show ?case
wenzelm@32962
  1208
        by (rule MGFn_NormalI) (rule ax_derivs.InsInitE)
schirmer@13688
  1209
    next
schirmer@13688
  1210
      case (Callee l e)
schirmer@13688
  1211
      show ?case
wenzelm@32962
  1212
        by (rule MGFn_NormalI) (rule ax_derivs.Callee)
schirmer@13688
  1213
    next
schirmer@13688
  1214
      case Skip
schirmer@13688
  1215
      show ?case
wenzelm@32962
  1216
        apply -
wenzelm@32962
  1217
        apply (rule MGFn_NormalI)
wenzelm@32962
  1218
        apply (rule ax_derivs.Skip [THEN conseq1])
nipkow@45761
  1219
        apply (fastforce intro: eval.Skip)
wenzelm@32962
  1220
        done
schirmer@13688
  1221
    next
schirmer@13688
  1222
      case (Expr e)
schirmer@13688
  1223
      thus ?case
wenzelm@32962
  1224
        apply -
wenzelm@32962
  1225
        apply (rule MGFn_NormalI)
wenzelm@32962
  1226
        apply (erule MGFnD'[THEN conseq12,THEN ax_derivs.Expr])
nipkow@45761
  1227
        apply (fastforce intro: eval.Expr)
wenzelm@32962
  1228
        done
schirmer@13688
  1229
    next
schirmer@13688
  1230
      case (Lab l c)
schirmer@13688
  1231
      thus "G,A\<turnstile>{=:n} \<langle>l\<bullet> c\<rangle>\<^sub>s\<succ> {G\<rightarrow>}"
wenzelm@32962
  1232
        apply -
wenzelm@32962
  1233
        apply (rule MGFn_NormalI)
wenzelm@32962
  1234
        apply (erule MGFnD' [THEN conseq12, THEN ax_derivs.Lab])
nipkow@45761
  1235
        apply (fastforce intro: eval.Lab)
wenzelm@32962
  1236
        done
schirmer@13688
  1237
    next
schirmer@13688
  1238
      case (Comp c1 c2)
schirmer@13688
  1239
      thus "G,A\<turnstile>{=:n} \<langle>c1;; c2\<rangle>\<^sub>s\<succ> {G\<rightarrow>}"
wenzelm@32962
  1240
        apply -
wenzelm@32962
  1241
        apply (rule MGFn_NormalI)
wenzelm@32962
  1242
        apply (rule ax_derivs.Comp)
wenzelm@32962
  1243
        apply  (erule MGFnD [THEN ax_NormalD])
wenzelm@32962
  1244
        apply (erule MGFnD' [THEN conseq12])
nipkow@45761
  1245
        apply (fastforce intro: eval.Comp) 
wenzelm@32962
  1246
        done
schirmer@13688
  1247
    next
wenzelm@24783
  1248
      case (If' e c1 c2)
schirmer@13688
  1249
      thus "G,A\<turnstile>{=:n} \<langle>If(e) c1 Else c2\<rangle>\<^sub>s\<succ> {G\<rightarrow>}"
wenzelm@32962
  1250
        apply -
wenzelm@32962
  1251
        apply (rule MGFn_NormalI)
wenzelm@32962
  1252
        apply (rule ax_derivs.If)
wenzelm@32962
  1253
        apply  (erule MGFnD [THEN ax_NormalD])
wenzelm@32962
  1254
        apply (rule allI)
wenzelm@32962
  1255
        apply (rule ax_Normal_cases)
wenzelm@32962
  1256
        prefer 2
wenzelm@32962
  1257
        apply  (rule ax_derivs.Abrupt [THEN conseq1],clarsimp simp add: Let_def)
nipkow@45761
  1258
        apply  (fastforce intro: eval.If)
wenzelm@32962
  1259
        apply (case_tac "b")
wenzelm@32962
  1260
        apply  simp
wenzelm@32962
  1261
        apply  (erule MGFnD' [THEN conseq12])
nipkow@45761
  1262
        apply  (fastforce intro: eval.If)
wenzelm@32962
  1263
        apply simp
wenzelm@32962
  1264
        apply (erule MGFnD' [THEN conseq12])
nipkow@45761
  1265
        apply (fastforce intro: eval.If)
wenzelm@32962
  1266
        done
schirmer@13688
  1267
    next
schirmer@13688
  1268
      case (Loop l e c)
wenzelm@23366
  1269
      note mgf_e = `G,A\<turnstile>{=:n} \<langle>e\<rangle>\<^sub>e\<succ> {G\<rightarrow>}`
wenzelm@23366
  1270
      note mgf_c = `G,A\<turnstile>{=:n} \<langle>c\<rangle>\<^sub>s\<succ> {G\<rightarrow>}`
schirmer@13688
  1271
      from mgf_e mgf_c wf
schirmer@13688
  1272
      show "G,A\<turnstile>{=:n} \<langle>l\<bullet> While(e) c\<rangle>\<^sub>s\<succ> {G\<rightarrow>}"
wenzelm@32962
  1273
        by (rule MGFn_Loop)
schirmer@13688
  1274
    next
schirmer@13688
  1275
      case (Jmp j)
schirmer@13688
  1276
      thus ?case
wenzelm@32962
  1277
        apply -
wenzelm@32962
  1278
        apply (rule MGFn_NormalI)
wenzelm@32962
  1279
        apply (rule ax_derivs.Jmp [THEN conseq1])
wenzelm@47585
  1280
        apply (auto intro: eval.Jmp)
wenzelm@32962
  1281
        done
schirmer@13688
  1282
    next
schirmer@13688
  1283
      case (Throw e)
schirmer@13688
  1284
      thus ?case
wenzelm@32962
  1285
        apply -
wenzelm@32962
  1286
        apply (rule MGFn_NormalI)
wenzelm@32962
  1287
        apply (erule MGFnD' [THEN conseq12, THEN ax_derivs.Throw])
nipkow@45761
  1288
        apply (fastforce intro: eval.Throw)
wenzelm@32962
  1289
        done
schirmer@13688
  1290
    next
schirmer@13688
  1291
      case (TryC c1 C vn c2)
schirmer@13688
  1292
      thus "G,A\<turnstile>{=:n} \<langle>Try c1 Catch(C vn) c2\<rangle>\<^sub>s\<succ> {G\<rightarrow>}"
wenzelm@32962
  1293
        apply -
wenzelm@32962
  1294
        apply (rule MGFn_NormalI)
wenzelm@32962
  1295
        apply (rule ax_derivs.Try [where 
schirmer@13688
  1296
          ?Q = " (\<lambda>Y' s' s. normal s \<and> (\<exists>s''. G\<turnstile>s \<midarrow>\<langle>c1\<rangle>\<^sub>s\<succ>\<rightarrow> (Y',s'') \<and> 
schirmer@13688
  1297
                            G\<turnstile>s'' \<midarrow>sxalloc\<rightarrow> s')) \<and>. G\<turnstile>init\<le>n"])
wenzelm@32962
  1298
        apply   (erule MGFnD [THEN ax_NormalD, THEN conseq2])
nipkow@45761
  1299
        apply   (fastforce elim: sxalloc_gext [THEN card_nyinitcls_gext])
wenzelm@32962
  1300
        apply  (erule MGFnD'[THEN conseq12])
nipkow@45761
  1301
        apply  (fastforce intro: eval.Try)
nipkow@45761
  1302
        apply (fastforce intro: eval.Try)
wenzelm@32962
  1303
        done
schirmer@13688
  1304
    next
schirmer@13688
  1305
      case (Fin c1 c2)
wenzelm@23366
  1306
      note mgf_c1 = `G,A\<turnstile>{=:n} \<langle>c1\<rangle>\<^sub>s\<succ> {G\<rightarrow>}`
wenzelm@23366
  1307
      note mgf_c2 = `G,A\<turnstile>{=:n} \<langle>c2\<rangle>\<^sub>s\<succ> {G\<rightarrow>}`
schirmer@13688
  1308
      from wf mgf_c1 mgf_c2
schirmer@13688
  1309
      show "G,A\<turnstile>{=:n} \<langle>c1 Finally c2\<rangle>\<^sub>s\<succ> {G\<rightarrow>}"
wenzelm@32962
  1310
        by (rule MGFn_Fin)
schirmer@13688
  1311
    next
schirmer@13688
  1312
      case (FinA abr c)
schirmer@13688
  1313
      show ?case
wenzelm@32962
  1314
        by (rule MGFn_NormalI) (rule ax_derivs.FinA)
schirmer@13688
  1315
    next
schirmer@13688
  1316
      case (Init C)
schirmer@13688
  1317
      from hyp
schirmer@13688
  1318
      show "G,A\<turnstile>{=:n} \<langle>Init C\<rangle>\<^sub>s\<succ> {G\<rightarrow>}"
wenzelm@32962
  1319
        by (rule MGFn_Init)
schirmer@13688
  1320
    next
schirmer@13688
  1321
      case Nil_expr
schirmer@13688
  1322
      show "G,A\<turnstile>{=:n} \<langle>[]\<rangle>\<^sub>l\<succ> {G\<rightarrow>}"
wenzelm@32962
  1323
        apply -
wenzelm@32962
  1324
        apply (rule MGFn_NormalI)
wenzelm@32962
  1325
        apply (rule ax_derivs.Nil [THEN conseq1])
nipkow@45761
  1326
        apply (fastforce intro: eval.Nil)
wenzelm@32962
  1327
        done
schirmer@13688
  1328
    next
schirmer@13688
  1329
      case (Cons_expr e es)
schirmer@13688
  1330
      thus "G,A\<turnstile>{=:n} \<langle>e# es\<rangle>\<^sub>l\<succ> {G\<rightarrow>}"
wenzelm@32962
  1331
        apply -
wenzelm@32962
  1332
        apply (rule MGFn_NormalI)
wenzelm@32962
  1333
        apply (rule ax_derivs.Cons)
wenzelm@32962
  1334
        apply  (erule MGFnD [THEN ax_NormalD])
wenzelm@32962
  1335
        apply (rule allI)
wenzelm@32962
  1336
        apply (erule MGFnD'[THEN conseq12])
nipkow@45761
  1337
        apply (fastforce intro: eval.Cons)
wenzelm@32962
  1338
        done
schirmer@13688
  1339
    qed
schirmer@13688
  1340
  }
schirmer@13688
  1341
  thus ?thesis
schirmer@13688
  1342
    by (cases rule: term_cases) auto
schirmer@13688
  1343
  qed
schirmer@13688
  1344
qed
schirmer@12854
  1345
schirmer@12925
  1346
lemma MGF_asm: 
schirmer@12925
  1347
"\<lbrakk>\<forall>C sig. is_methd G C sig \<longrightarrow> G,A\<turnstile>{\<doteq>} In1l (Methd C sig)\<succ> {G\<rightarrow>}; wf_prog G\<rbrakk>
schirmer@12925
  1348
 \<Longrightarrow> G,(A::state triple set)\<turnstile>{\<doteq>} t\<succ> {G\<rightarrow>}"
schirmer@12854
  1349
apply (simp (no_asm_use) add: MGF_MGFn_iff)
schirmer@12854
  1350
apply (rule allI)
schirmer@12854
  1351
apply (rule MGFn_lemma)
schirmer@12854
  1352
apply (intro strip)
schirmer@12854
  1353
apply (rule MGFn_free_wt)
schirmer@12854
  1354
apply (force dest: wt_Methd_is_methd)
schirmer@12925
  1355
apply assumption (* wf_prog G *)
schirmer@12854
  1356
done
schirmer@12854
  1357
schirmer@12854
  1358
section "nested version"
schirmer@12854
  1359
schirmer@13688
  1360
lemma nesting_lemma' [rule_format (no_asm)]: 
schirmer@13688
  1361
  assumes ax_derivs_asm: "\<And>A ts. ts \<subseteq> A \<Longrightarrow> P A ts" 
schirmer@13688
  1362
  and MGF_nested_Methd: "\<And>A pn. \<forall>b\<in>bdy pn. P (insert (mgf_call pn) A) {mgf b}
schirmer@13688
  1363
                                  \<Longrightarrow> P A {mgf_call pn}"
schirmer@13688
  1364
  and MGF_asm: "\<And>A t. \<forall>pn\<in>U. P A {mgf_call pn} \<Longrightarrow> P A {mgf t}"
schirmer@13688
  1365
  and finU: "finite U"
schirmer@13688
  1366
  and uA: "uA = mgf_call`U"
schirmer@13688
  1367
  shows "\<forall>A. A \<subseteq> uA \<longrightarrow> n \<le> card uA \<longrightarrow> card A = card uA - n 
schirmer@13688
  1368
             \<longrightarrow> (\<forall>t. P A {mgf t})"
schirmer@13688
  1369
using finU uA
schirmer@13688
  1370
apply -
schirmer@13688
  1371
apply (induct_tac "n")
wenzelm@43665
  1372
apply  (tactic "ALLGOALS (clarsimp_tac @{context})")
wenzelm@39406
  1373
apply  (tactic {* dtac (Thm.permute_prems 0 1 @{thm card_seteq}) 1 *})
schirmer@13688
  1374
apply    simp
schirmer@13688
  1375
apply   (erule finite_imageI)
schirmer@13688
  1376
apply  (simp add: MGF_asm ax_derivs_asm)
schirmer@13688
  1377
apply (rule MGF_asm)
schirmer@13688
  1378
apply (rule ballI)
schirmer@13688
  1379
apply (case_tac "mgf_call pn : A")
schirmer@13688
  1380
apply  (fast intro: ax_derivs_asm)
schirmer@13688
  1381
apply (rule MGF_nested_Methd)
schirmer@13688
  1382
apply (rule ballI)
schirmer@13688
  1383
apply (drule spec, erule impE, erule_tac [2] impE, erule_tac [3] spec)
thomas@58834
  1384
apply hypsubst_thin
schirmer@13688
  1385
apply   fast
schirmer@13688
  1386
apply (drule finite_subset)
schirmer@13688
  1387
apply (erule finite_imageI)
schirmer@13688
  1388
apply auto
schirmer@13688
  1389
done
schirmer@12854
  1390
schirmer@13688
  1391
schirmer@13688
  1392
lemma nesting_lemma [rule_format (no_asm)]:
schirmer@13688
  1393
  assumes ax_derivs_asm: "\<And>A ts. ts \<subseteq> A \<Longrightarrow> P A ts"
schirmer@13688
  1394
  and MGF_nested_Methd: "\<And>A pn. \<forall>b\<in>bdy pn. P (insert (mgf (f pn)) A) {mgf b}
schirmer@13688
  1395
                                  \<Longrightarrow> P A {mgf (f pn)}"
schirmer@13688
  1396
  and MGF_asm: "\<And>A t. \<forall>pn\<in>U. P A {mgf (f pn)} \<Longrightarrow> P A {mgf t}"
schirmer@13688
  1397
  and finU: "finite U"
schirmer@13688
  1398
shows "P {} {mgf t}"
schirmer@13688
  1399
using ax_derivs_asm MGF_nested_Methd MGF_asm finU
schirmer@13688
  1400
by (rule nesting_lemma') (auto intro!: le_refl)
schirmer@13688
  1401
schirmer@12854
  1402
schirmer@12854
  1403
lemma MGF_nested_Methd: "\<lbrakk>  
schirmer@13688
  1404
 G,insert ({Normal \<doteq>} \<langle>Methd  C sig\<rangle>\<^sub>e \<succ>{G\<rightarrow>}) A
schirmer@13688
  1405
    \<turnstile>{Normal \<doteq>} \<langle>body G C sig\<rangle>\<^sub>e \<succ>{G\<rightarrow>}  
schirmer@13688
  1406
 \<rbrakk> \<Longrightarrow>  G,A\<turnstile>{Normal \<doteq>}  \<langle>Methd  C sig\<rangle>\<^sub>e \<succ>{G\<rightarrow>}"
schirmer@12854
  1407
apply (unfold MGF_def)
schirmer@12854
  1408
apply (rule ax_MethdN)
schirmer@12854
  1409
apply (erule conseq2)
schirmer@12854
  1410
apply clarsimp
schirmer@12854
  1411
apply (erule MethdI)
schirmer@12854
  1412
done
schirmer@12854
  1413
schirmer@12925
  1414
lemma MGF_deriv: "wf_prog G \<Longrightarrow> G,({}::state triple set)\<turnstile>{\<doteq>} t\<succ> {G\<rightarrow>}"
schirmer@12854
  1415
apply (rule MGFNormalI)
schirmer@12854
  1416
apply (rule_tac mgf = "\<lambda>t. {Normal \<doteq>} t\<succ> {G\<rightarrow>}" and 
schirmer@13688
  1417
                bdy = "\<lambda> (C,sig) .{\<langle>body G C sig\<rangle>\<^sub>e }" and 
schirmer@13688
  1418
                f = "\<lambda> (C,sig) . \<langle>Methd C sig\<rangle>\<^sub>e " in nesting_lemma)
schirmer@12854
  1419
apply    (erule ax_derivs.asm)
schirmer@12854
  1420
apply   (clarsimp simp add: split_tupled_all)
schirmer@12854
  1421
apply   (erule MGF_nested_Methd)
schirmer@12925
  1422
apply  (erule_tac [2] finite_is_methd [OF wf_ws_prog])
schirmer@12854
  1423
apply (rule MGF_asm [THEN MGFNormalD])
schirmer@12925
  1424
apply (auto intro: MGFNormalI)
schirmer@12854
  1425
done
schirmer@12854
  1426
schirmer@12854
  1427
schirmer@12854
  1428
section "simultaneous version"
schirmer@12854
  1429
schirmer@12854
  1430
lemma MGF_simult_Methd_lemma: "finite ms \<Longrightarrow>  
schirmer@13688
  1431
  G,A \<union> (\<lambda>(C,sig). {Normal \<doteq>} \<langle>Methd  C sig\<rangle>\<^sub>e\<succ> {G\<rightarrow>}) ` ms  
schirmer@13688
  1432
      |\<turnstile>(\<lambda>(C,sig). {Normal \<doteq>} \<langle>body G C sig\<rangle>\<^sub>e\<succ> {G\<rightarrow>}) ` ms \<Longrightarrow>  
schirmer@13688
  1433
  G,A|\<turnstile>(\<lambda>(C,sig). {Normal \<doteq>} \<langle>Methd  C sig\<rangle>\<^sub>e\<succ> {G\<rightarrow>}) ` ms"
schirmer@12854
  1434
apply (unfold MGF_def)
schirmer@12854
  1435
apply (rule ax_derivs.Methd [unfolded mtriples_def])
schirmer@12854
  1436
apply (erule ax_finite_pointwise)
schirmer@12854
  1437
prefer 2
schirmer@12854
  1438
apply  (rule ax_derivs.asm)
schirmer@12854
  1439
apply  fast
schirmer@12854
  1440
apply clarsimp
schirmer@12854
  1441
apply (rule conseq2)
schirmer@12854
  1442
apply  (erule (1) ax_methods_spec)
schirmer@12854
  1443
apply clarsimp
schirmer@12854
  1444
apply (erule eval_Methd)
schirmer@12854
  1445
done
schirmer@12854
  1446
schirmer@12925
  1447
lemma MGF_simult_Methd: "wf_prog G \<Longrightarrow> 
schirmer@13688
  1448
   G,({}::state triple set)|\<turnstile>(\<lambda>(C,sig). {Normal \<doteq>} \<langle>Methd C sig\<rangle>\<^sub>e\<succ> {G\<rightarrow>}) 
schirmer@12854
  1449
   ` Collect (split (is_methd G)) "
schirmer@12925
  1450
apply (frule finite_is_methd [OF wf_ws_prog])
schirmer@12854
  1451
apply (rule MGF_simult_Methd_lemma)
schirmer@12854
  1452
apply  assumption
schirmer@12854
  1453
apply (erule ax_finite_pointwise)
schirmer@12854
  1454
prefer 2
schirmer@12854
  1455
apply  (rule ax_derivs.asm)
schirmer@12854
  1456
apply  blast
schirmer@12854
  1457
apply clarsimp
schirmer@12854
  1458
apply (rule MGF_asm [THEN MGFNormalD])
schirmer@12925
  1459
apply   (auto intro: MGFNormalI)
schirmer@12854
  1460
done
schirmer@12854
  1461
schirmer@12854
  1462
schirmer@12854
  1463
section "corollaries"
schirmer@12854
  1464
schirmer@12925
  1465
lemma eval_to_evaln: "\<lbrakk>G\<turnstile>s \<midarrow>t\<succ>\<rightarrow> (Y', s');type_ok G t s; wf_prog G\<rbrakk>
schirmer@12925
  1466
 \<Longrightarrow>   \<exists>n. G\<turnstile>s \<midarrow>t\<succ>\<midarrow>n\<rightarrow> (Y', s')"
schirmer@12925
  1467
apply (cases "normal s")
schirmer@12925
  1468
apply   (force simp add: type_ok_def intro: eval_evaln)
schirmer@12925
  1469
apply   (force intro: evaln.Abrupt)
schirmer@12925
  1470
done
schirmer@12925
  1471
schirmer@13688
  1472
lemma MGF_complete:
schirmer@13688
  1473
  assumes valid: "G,{}\<Turnstile>{P} t\<succ> {Q}"
schirmer@13688
  1474
  and     mgf: "G,({}::state triple set)\<turnstile>{\<doteq>} t\<succ> {G\<rightarrow>}"
schirmer@13688
  1475
  and      wf: "wf_prog G"
schirmer@13688
  1476
  shows "G,({}::state triple set)\<turnstile>{P::state assn} t\<succ> {Q}"
schirmer@13688
  1477
proof (rule ax_no_hazard)
schirmer@13688
  1478
  from mgf
schirmer@13688
  1479
  have "G,({}::state triple set)\<turnstile>{\<doteq>} t\<succ> {\<lambda>Y s' s. G\<turnstile>s \<midarrow>t\<succ>\<rightarrow> (Y, s')}"  
schirmer@13688
  1480
    by  (unfold MGF_def) 
schirmer@13688
  1481
  thus "G,({}::state triple set)\<turnstile>{P \<and>. type_ok G t} t\<succ> {Q}"
schirmer@13688
  1482
  proof (rule conseq12,clarsimp)
schirmer@13688
  1483
    fix Y s Z Y' s'
schirmer@13688
  1484
    assume P: "P Y s Z"
schirmer@13688
  1485
    assume type_ok: "type_ok G t s"
schirmer@13688
  1486
    assume eval_t: "G\<turnstile>s \<midarrow>t\<succ>\<rightarrow> (Y', s')"
schirmer@13688
  1487
    show "Q Y' s' Z"
schirmer@13688
  1488
    proof -
schirmer@13688
  1489
      from eval_t type_ok wf 
schirmer@13688
  1490
      obtain n where evaln: "G\<turnstile>s \<midarrow>t\<succ>\<midarrow>n\<rightarrow> (Y', s')"
wenzelm@32962
  1491
        by (rule eval_to_evaln [elim_format]) iprover
schirmer@13688
  1492
      from valid have 
wenzelm@32962
  1493
        valid_expanded:
wenzelm@32962
  1494
        "\<forall>n Y s Z. P Y s Z \<longrightarrow> type_ok G t s 
schirmer@13688
  1495
                   \<longrightarrow> (\<forall>Y' s'. G\<turnstile>s \<midarrow>t\<succ>\<midarrow>n\<rightarrow> (Y', s') \<longrightarrow> Q Y' s' Z)"
wenzelm@32962
  1496
        by (simp add: ax_valids_def triple_valid_def)
schirmer@13688
  1497
      from P type_ok evaln
schirmer@13688
  1498
      show "Q Y' s' Z"
wenzelm@32962
  1499
        by (rule valid_expanded [rule_format])
schirmer@13688
  1500
    qed
schirmer@13688
  1501
  qed 
schirmer@13688
  1502
qed
schirmer@13688
  1503
   
schirmer@13688
  1504
theorem ax_complete: 
schirmer@13688
  1505
  assumes wf: "wf_prog G" 
schirmer@13688
  1506
  and valid: "G,{}\<Turnstile>{P::state assn} t\<succ> {Q}"
schirmer@13688
  1507
  shows "G,({}::state triple set)\<turnstile>{P} t\<succ> {Q}"
schirmer@13688
  1508
proof -
schirmer@13688
  1509
  from wf have "G,({}::state triple set)\<turnstile>{\<doteq>} t\<succ> {G\<rightarrow>}"
schirmer@13688
  1510
    by (rule MGF_deriv)
schirmer@13688
  1511
  from valid this wf
schirmer@13688
  1512
  show ?thesis
schirmer@13688
  1513
    by (rule MGF_complete)
schirmer@13688
  1514
qed
schirmer@13688
  1515
 
schirmer@12854
  1516
end