(* Title: HOL/Bali/Evaln.thy Author: David von Oheimb and Norbert Schirmer
*)
subsection \<open>Operational evaluation (big-step) semantics of Java expressions and
statements \<close>
theory Evaln imports TypeSafe begin
text\<open>
Variant of \<^term>\<open>eval\<close> relation with counter for bounded recursive depth. In principal \<^term>\<open>evaln\<close> could replace \<^term>\<open>eval\<close>.
Validity of the axiomatic semantics builds on \<^term>\<open>evaln\<close>. For recursive method calls the axiomatic semantics rule assumes the method ok to derive a prooffor the body. To prove the method rule sound we need to
perform induction on the recursion depth. For the completeness proof of the axiomatic semantics the notion of the most
general formula is used. The most general formula right now builds on the
ordinary evaluation relation \<^term>\<open>eval\<close>.
So sometimes we haveto switch between \<^term>\<open>evaln\<close> and \<^term>\<open>eval\<close> and vice
versa. To make
this switch easy \<^term>\<open>evaln\<close> also does all the technical accessibility tests \<^term>\<open>check_field_access\<close> and \<^term>\<open>check_method_access\<close> like \<^term>\<open>eval\<close>. If it would omit them \<^term>\<open>evaln\<close> and \<^term>\<open>eval\<close> would only be equivalent for welltyped, and definitely assigned terms. \<close>
inductive
evaln :: "[prog, state, term, nat, vals, state] \ bool"
(\<open>_\<turnstile>_ \<midarrow>_\<succ>\<midarrow>_\<rightarrow> '(_, _')\<close> [61,61,80,61,0,0] 60) and evarn :: "[prog, state, var, vvar, nat, state] \ bool"
(\<open>_\<turnstile>_ \<midarrow>_=\<succ>_\<midarrow>_\<rightarrow> _\<close> [61,61,90,61,61,61] 60) and eval_n:: "[prog, state, expr, val, nat, state] \ bool"
(\<open>_\<turnstile>_ \<midarrow>_-\<succ>_\<midarrow>_\<rightarrow> _\<close> [61,61,80,61,61,61] 60) and evalsn :: "[prog, state, expr list, val list, nat, state] \ bool"
(\<open>_\<turnstile>_ \<midarrow>_\<doteq>\<succ>_\<midarrow>_\<rightarrow> _\<close> [61,61,61,61,61,61] 60) and execn :: "[prog, state, stmt, nat, state] \ bool"
(\<open>_\<turnstile>_ \<midarrow>_\<midarrow>_\<rightarrow> _\<close> [61,61,65, 61,61] 60) for G :: prog where
"G\s \c \n\ s' \ G\s \In1r c\\n\ (\ , s')"
| "G\s \e-\v \n\ s' \ G\s \In1l e\\n\ (In1 v , s')"
| "G\s \e=\vf \n\ s' \ G\s \In2 e\\n\ (In2 vf, s')"
| "G\s \e\\v \n\ s' \ G\s \In3 e\\n\ (In3 v , s')"
\<comment> \<open>propagation of abrupt completion\<close>
| Call: "\G\Norm s0 \e-\a'\n\ s1; G\s1 \args\\vs\n\ s2;
D = invocation_declclass G mode (store s2) a' statT \name=mn,parTs=pTs\;
s3=init_lvars G D \<lparr>name=mn,parTs=pTs\<rparr> mode a' vs s2;
s3' = check_method_access G accC statT mode \name=mn,parTs=pTs\ a' s3;
G\<turnstile>s3'\<midarrow>Methd D \<lparr>name=mn,parTs=pTs\<rparr>-\<succ>v\<midarrow>n\<rightarrow> s4 \<rbrakk> \<Longrightarrow>
G\<turnstile>Norm s0 \<midarrow>{accC,statT,mode}e\<cdot>mn({pTs}args)-\<succ>v\<midarrow>n\<rightarrow> (restore_lvars s2 s4)"
| Methd:"\G\Norm s0 \body G D sig-\v\n\ s1\ \
G\<turnstile>Norm s0 \<midarrow>Methd D sig-\<succ>v\<midarrow>Suc n\<rightarrow> s1"
| Body: "\G\Norm s0\Init D\n\ s1; G\s1 \c\n\ s2;
s3 = (if (\<exists> l. abrupt s2 = Some (Jump (Break l)) \<or>
abrupt s2 = Some (Jump (Cont l))) then abupd (\<lambda> x. Some (Error CrossMethodJump)) s2
else s2)\<rbrakk>\<Longrightarrow>
G\<turnstile>Norm s0 \<midarrow>Body D c
-\<succ>the (locals (store s2) Result)\<midarrow>n\<rightarrow>abupd (absorb Ret) s3"
\<comment> \<open>evaluation of expression lists\<close>
lemma evaln_Inj_elim: "G\s \t\\n\ (w,s') \ case t of In1 ec \
(case ec of Inl e \<Rightarrow> (\<exists>v. w = In1 v) | Inr c \<Rightarrow> w = \<diamondsuit>)
| In2 e \<Rightarrow> (\<exists>v. w = In2 v) | In3 e \<Rightarrow> (\<exists>v. w = In3 v)" apply (erule evaln_cases , auto) apply (induct_tac "t") apply (rename_tac a, induct_tac "a") apply auto done
text\<open>The following simplification procedures set up the proper injections of
terms and their corresponding values in the evaluation relation:
E.g. an expression
(injection \<^term>\<open>In1l\<close> into terms) always evaluates to ordinary values
(injection \<^term>\<open>In1\<close> into generalised values \<^term>\<open>vals\<close>). \<close>
ML \<open>ML_Thms.bind_thms ("evaln_AbruptIs", sum3_instantiate \<^context> @{thm evaln.Abrupt})\<close> declare evaln_AbruptIs [intro!]
lemma evaln_Callee: "G\Norm s\In1l (Callee l e)\\n\ (v,s') = False" proof - have"False" if eval: "G\s \t\\n\ (v,s')" and normal: "normal s" and callee: "t=In1l (Callee l e)" for s t v s' using that by induct auto thenshow ?thesis by (cases s') fastforce qed
lemma evaln_InsInitE: "G\Norm s\In1l (InsInitE c e)\\n\ (v,s') = False" proof - have"False" if eval: "G\s \t\\n\ (v,s')" and normal: "normal s" and callee: "t=In1l (InsInitE c e)" for s t v s' using that by induct auto thenshow ?thesis by (cases s') fastforce qed
lemma evaln_InsInitV: "G\Norm s\In2 (InsInitV c w)\\n\ (v,s') = False" proof - have"False" if eval: "G\s \t\\n\ (v,s')" and normal: "normal s" and callee: "t=In2 (InsInitV c w)" for s t v s' using that by induct auto thenshow ?thesis by (cases s') fastforce qed
lemma evaln_FinA: "G\Norm s\In1r (FinA a c)\\n\ (v,s') = False" proof - have"False" if eval: "G\s \t\\n\ (v,s')" and normal: "normal s" and callee: "t=In1r (FinA a c)" for s t v s' using that by induct auto thenshow ?thesis by (cases s') fastforce qed
lemma evaln_abrupt_lemma: "G\s \e\\n\ (v,s') \
fst s = Some xc \<longrightarrow> s' = s \<and> v = undefined3 e" apply (erule evaln_cases , auto) done
lemma evaln_IfI: "\G\s \e-\v\n\ s1; G\s1 \(if the_Bool v then c1 else c2)\n\ s2\ \
G\<turnstile>s \<midarrow>If(e) c1 Else c2\<midarrow>n\<rightarrow> s2" apply (case_tac "s", case_tac "a = None") by (auto intro!: evaln.If)
lemma evaln_SkipD [dest!]: "G\s \Skip\n\ s' \ s' = s" by (erule evaln_cases, auto)
lemma evaln_Skip_eq [simp]: "G\s \Skip\n\ s' = (s = s')" apply auto done
subsubsection \<open>evaln implies eval\<close>
lemma evaln_eval: assumes evaln: "G\s0 \t\\n\ (v,s1)" shows"G\s0 \t\\ (v,s1)" using evaln proof (induct) case (Loop s0 e b n s1 c s2 l s3) note\<open>G\<turnstile>Norm s0 \<midarrow>e-\<succ>b\<rightarrow> s1\<close> moreover have"if the_Bool b then (G\<turnstile>s1 \<midarrow>c\<rightarrow> s2) \<and>
G\<turnstile>abupd (absorb (Cont l)) s2 \<midarrow>l\<bullet> While(e) c\<rightarrow> s3
else s3 = s1" using Loop.hyps by simp ultimatelyshow ?caseby (rule eval.Loop) next case (Try s0 c1 n s1 s2 C vn c2 s3) note\<open>G\<turnstile>Norm s0 \<midarrow>c1\<rightarrow> s1\<close> moreover note\<open>G\<turnstile>s1 \<midarrow>sxalloc\<rightarrow> s2\<close> moreover have"if G,s2\catch C then G\new_xcpt_var vn s2 \c2\ s3 else s3 = s2" using Try.hyps by simp ultimatelyshow ?caseby (rule eval.Try) next case (Init C c s0 s3 n s1 s2) note\<open>the (class G C) = c\<close> moreover have"if inited C (globs s0) then s3 = Norm s0
else G\<turnstile>Norm ((init_class_obj G C) s0) \<midarrow>(if C = Object then Skip else Init (super c))\<rightarrow> s1 \<and>
G\<turnstile>(set_lvars Map.empty) s1 \<midarrow>init c\<rightarrow> s2 \<and>
s3 = (set_lvars (locals (store s1))) s2" using Init.hyps by simp ultimatelyshow ?caseby (rule eval.Init) qed (rule eval.intros,(assumption+ | assumption?))+
lemma Suc_le_D_lemma: "\Suc n <= m'; (\m. n <= m \ P (Suc m)) \ \ P m'" apply (frule Suc_le_D) apply fast done
lemma le_max3I1: "(n2::nat) \ max n1 (max n2 n3)" proof - have"n2 \ max n2 n3" by (rule max.cobounded1) also have"max n2 n3 \ max n1 (max n2 n3)" by (rule max.cobounded2) finally show ?thesis . qed
lemma le_max3I2: "(n3::nat) \ max n1 (max n2 n3)" proof - have"n3 \ max n2 n3" by (rule max.cobounded2) also have"max n2 n3 \ max n1 (max n2 n3)" by (rule max.cobounded2) finally show ?thesis . qed
subsubsection \<open>eval implies evaln\<close> lemma eval_evaln: assumes eval: "G\s0 \t\\ (v,s1)" shows"\n. G\s0 \t\\n\ (v,s1)" using eval proof (induct) case (Abrupt xc s t) obtain n where "G\(Some xc, s) \t\\n\ (undefined3 t, (Some xc, s))" by (iprover intro: evaln.Abrupt) thenshow ?case .. next case Skip show ?caseby (blast intro: evaln.Skip) next case (Expr s0 e v s1) thenobtain n where "G\Norm s0 \e-\v\n\ s1" by (iprover) thenhave"G\Norm s0 \Expr e\n\ s1" by (rule evaln.Expr) thenshow ?case .. next case (Lab s0 c s1 l) thenobtain n where "G\Norm s0 \c\n\ s1" by (iprover) thenhave"G\Norm s0 \l\ c\n\ abupd (absorb l) s1" by (rule evaln.Lab) thenshow ?case .. next case (Comp s0 c1 s1 c2 s2) thenobtain n1 n2 where "G\Norm s0 \c1\n1\ s1" "G\s1 \c2\n2\ s2" by (iprover) thenhave"G\Norm s0 \c1;; c2\max n1 n2\ s2" by (blast intro: evaln.Comp dest: evaln_max2 ) thenshow ?case .. next case (If s0 e b s1 c1 c2 s2) thenobtain n1 n2 where "G\Norm s0 \e-\b\n1\ s1" "G\s1 \(if the_Bool b then c1 else c2)\n2\ s2" by (iprover) thenhave"G\Norm s0 \If(e) c1 Else c2\max n1 n2\ s2" by (blast intro: evaln.If dest: evaln_max2) thenshow ?case .. next case (Loop s0 e b s1 c s2 l s3) from Loop.hyps obtain n1 where "G\Norm s0 \e-\b\n1\ s1" by (iprover) moreoverfrom Loop.hyps obtain n2 where "if the_Bool b then (G\<turnstile>s1 \<midarrow>c\<midarrow>n2\<rightarrow> s2 \<and>
G\<turnstile>(abupd (absorb (Cont l)) s2)\<midarrow>l\<bullet> While(e) c\<midarrow>n2\<rightarrow> s3)
else s3 = s1" by simp (iprover intro: evaln_nonstrict max.cobounded1 max.cobounded2) ultimately have"G\Norm s0 \l\ While(e) c\max n1 n2\ s3" apply - apply (rule evaln.Loop) apply (iprover intro: evaln_nonstrict intro: max.cobounded1) apply (auto intro: evaln_nonstrict intro: max.cobounded2) done thenshow ?case .. next case (Jmp s j) fix n have"G\Norm s \Jmp j\n\ (Some (Jump j), s)" by (rule evaln.Jmp) thenshow ?case .. next case (Throw s0 e a s1) thenobtain n where "G\Norm s0 \e-\a\n\ s1" by (iprover) thenhave"G\Norm s0 \Throw e\n\ abupd (throw a) s1" by (rule evaln.Throw) thenshow ?case .. next case (Try s0 c1 s1 s2 catchC vn c2 s3) from Try.hyps obtain n1 where "G\Norm s0 \c1\n1\ s1" by (iprover) moreover note sxalloc = \<open>G\<turnstile>s1 \<midarrow>sxalloc\<rightarrow> s2\<close> moreover from Try.hyps obtain n2 where "if G,s2\catch catchC then G\new_xcpt_var vn s2 \c2\n2\ s3 else s3 = s2" by fastforce ultimately have"G\Norm s0 \Try c1 Catch(catchC vn) c2\max n1 n2\ s3" by (auto intro!: evaln.Try max.cobounded1 max.cobounded2) thenshow ?case .. next case (Fin s0 c1 x1 s1 c2 s2 s3) from Fin obtain n1 n2 where "G\Norm s0 \c1\n1\ (x1, s1)" "G\Norm s1 \c2\n2\ s2" by iprover moreover note s3 = \<open>s3 = (if \<exists>err. x1 = Some (Error err) then (x1, s1)
else abupd (abrupt_if (x1 \<noteq> None) x1) s2)\<close> ultimately have "G\Norm s0 \c1 Finally c2\max n1 n2\ s3" by (blast intro: evaln.Fin dest: evaln_max2) thenshow ?case .. next case (Init C c s0 s3 s1 s2) note cls = \<open>the (class G C) = c\<close> moreoverfrom Init.hyps obtain n where "if inited C (globs s0) then s3 = Norm s0
else (G\<turnstile>Norm (init_class_obj G C s0) \<midarrow>(if C = Object then Skip else Init (super c))\<midarrow>n\<rightarrow> s1 \<and>
G\<turnstile>set_lvars Map.empty s1 \<midarrow>init c\<midarrow>n\<rightarrow> s2 \<and>
s3 = restore_lvars s1 s2)" by (auto intro: evaln_nonstrict max.cobounded1 max.cobounded2) ultimatelyhave"G\Norm s0 \Init C\n\ s3" by (rule evaln.Init) thenshow ?case .. next case (NewC s0 C s1 a s2) thenobtain n where "G\Norm s0 \Init C\n\ s1" by (iprover) with NewC have"G\Norm s0 \NewC C-\Addr a\n\ s2" by (iprover intro: evaln.NewC) thenshow ?case .. next case (NewA s0 T s1 e i s2 a s3) thenobtain n1 n2 where "G\Norm s0 \init_comp_ty T\n1\ s1" "G\s1 \e-\i\n2\ s2" by (iprover) moreover note\<open>G\<turnstile>abupd (check_neg i) s2 \<midarrow>halloc Arr T (the_Intg i)\<succ>a\<rightarrow> s3\<close> ultimately have"G\Norm s0 \New T[e]-\Addr a\max n1 n2\ s3" by (blast intro: evaln.NewA dest: evaln_max2) thenshow ?case .. next case (Cast s0 e v s1 s2 castT) thenobtain n where "G\Norm s0 \e-\v\n\ s1" by (iprover) moreover note\<open>s2 = abupd (raise_if (\<not> G,snd s1\<turnstile>v fits castT) ClassCast) s1\<close> ultimately have"G\Norm s0 \Cast castT e-\v\n\ s2" by (rule evaln.Cast) thenshow ?case .. next case (Inst s0 e v s1 b T) thenobtain n where "G\Norm s0 \e-\v\n\ s1" by (iprover) moreover note\<open>b = (v \<noteq> Null \<and> G,snd s1\<turnstile>v fits RefT T)\<close> ultimately have"G\Norm s0 \e InstOf T-\Bool b\n\ s1" by (rule evaln.Inst) thenshow ?case .. next case (Lit s v) fix n have"G\Norm s \Lit v-\v\n\ Norm s" by (rule evaln.Lit) thenshow ?case .. next case (UnOp s0 e v s1 unop) thenobtain n where "G\Norm s0 \e-\v\n\ s1" by (iprover) hence"G\Norm s0 \UnOp unop e-\eval_unop unop v\n\ s1" by (rule evaln.UnOp) thenshow ?case .. next case (BinOp s0 e1 v1 s1 binop e2 v2 s2) thenobtain n1 n2 where "G\Norm s0 \e1-\v1\n1\ s1" "G\s1 \(if need_second_arg binop v1 then In1l e2
else In1r Skip)\<succ>\<midarrow>n2\<rightarrow> (In1 v2, s2)" by (iprover) hence"G\Norm s0 \BinOp binop e1 e2-\(eval_binop binop v1 v2)\max n1 n2 \<rightarrow> s2" by (blast intro!: evaln.BinOp dest: evaln_max2) thenshow ?case .. next case (Super s ) fix n have"G\Norm s \Super-\val_this s\n\ Norm s" by (rule evaln.Super) thenshow ?case .. next case (Acc s0 va v f s1) thenobtain n where "G\Norm s0 \va=\(v, f)\n\ s1" by (iprover) then have"G\Norm s0 \Acc va-\v\n\ s1" by (rule evaln.Acc) thenshow ?case .. next case (Ass s0 var w f s1 e v s2) thenobtain n1 n2 where "G\Norm s0 \var=\(w, f)\n1\ s1" "G\s1 \e-\v\n2\ s2" by (iprover) then have"G\Norm s0 \var:=e-\v\max n1 n2\ assign f v s2" by (blast intro: evaln.Ass dest: evaln_max2) thenshow ?case .. next case (Cond s0 e0 b s1 e1 e2 v s2) thenobtain n1 n2 where "G\Norm s0 \e0-\b\n1\ s1" "G\s1 \(if the_Bool b then e1 else e2)-\v\n2\ s2" by (iprover) then have"G\Norm s0 \e0 ? e1 : e2-\v\max n1 n2\ s2" by (blast intro: evaln.Cond dest: evaln_max2) thenshow ?case .. next case (Call s0 e a' s1 args vs s2 invDeclC mode statT mn pTs' s3 s3' accC' v s4) thenobtain n1 n2 where "G\Norm s0 \e-\a'\n1\ s1" "G\s1 \args\\vs\n2\ s2" by iprover moreover note\<open>invDeclC = invocation_declclass G mode (store s2) a' statT \<lparr>name=mn,parTs=pTs'\<rparr>\<close> moreover note\<open>s3 = init_lvars G invDeclC \<lparr>name=mn,parTs=pTs'\<rparr> mode a' vs s2\<close> moreover note\<open>s3'=check_method_access G accC' statT mode \<lparr>name=mn,parTs=pTs'\<rparr> a' s3\<close> moreover from Call.hyps obtain m where "G\s3' \Methd invDeclC \name=mn, parTs=pTs'\-\v\m\ s4" by iprover ultimately have"G\Norm s0 \{accC',statT,mode}e\mn( {pTs'}args)-\v\max n1 (max n2 m)\
(set_lvars (locals (store s2))) s4" by (auto intro!: evaln.Call max.cobounded1 le_max3I1 le_max3I2) thus ?case .. next case (Methd s0 D sig v s1) thenobtain n where "G\Norm s0 \body G D sig-\v\n\ s1" by iprover thenhave"G\Norm s0 \Methd D sig-\v\Suc n\ s1" by (rule evaln.Methd) thenshow ?case .. next case (Body s0 D s1 c s2 s3) from Body.hyps obtain n1 n2 where
evaln_init: "G\Norm s0 \Init D\n1\ s1" and
evaln_c: "G\s1 \c\n2\ s2" by (iprover) moreover note\<open>s3 = (if \<exists>l. fst s2 = Some (Jump (Break l)) \<or>
fst s2 = Some (Jump (Cont l)) then abupd (\<lambda>x. Some (Error CrossMethodJump)) s2
else s2)\<close> ultimately have "G\Norm s0 \Body D c-\the (locals (store s2) Result)\max n1 n2 \<rightarrow> abupd (absorb Ret) s3" by (iprover intro: evaln.Body dest: evaln_max2) thenshow ?case .. next case (LVar s vn ) obtain n where "G\Norm s \LVar vn=\lvar vn s\n\ Norm s" by (iprover intro: evaln.LVar) thenshow ?case .. next case (FVar s0 statDeclC s1 e a s2 v s2' stat fn s3 accC) thenobtain n1 n2 where "G\Norm s0 \Init statDeclC\n1\ s1" "G\s1 \e-\a\n2\ s2" by iprover moreover note\<open>s3 = check_field_access G accC statDeclC fn stat a s2'\<close> and\<open>(v, s2') = fvar statDeclC stat fn a s2\<close> ultimately have"G\Norm s0 \{accC,statDeclC,stat}e..fn=\v\max n1 n2\ s3" by (iprover intro: evaln.FVar dest: evaln_max2) thenshow ?case .. next case (AVar s0 e1 a s1 e2 i s2 v s2') thenobtain n1 n2 where "G\Norm s0 \e1-\a\n1\ s1" "G\s1 \e2-\i\n2\ s2" by iprover moreover note\<open>(v, s2') = avar G i a s2\<close> ultimately have"G\Norm s0 \e1.[e2]=\v\max n1 n2\ s2'" by (blast intro!: evaln.AVar dest: evaln_max2) thenshow ?case .. next case (Nil s0) show ?caseby (iprover intro: evaln.Nil) next case (Cons s0 e v s1 es vs s2) thenobtain n1 n2 where "G\Norm s0 \e-\v\n1\ s1" "G\s1 \es\\vs\n2\ s2" by iprover then have"G\Norm s0 \e # es\\v # vs\max n1 n2\ s2" by (blast intro!: evaln.Cons dest: evaln_max2) thenshow ?case .. qed
end
¤ Dauer der Verarbeitung: 0.18 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.