(* Title: HOL/Bali/AxSem.thy Author: David von Oheimb
*)
subsection‹Axiomatic semantics of Java expressions and statements
(see also Eval.thy) › theory AxSem imports Evaln TypeSafe begin
text‹
design issues: \begin{itemize} \item a strong version of validity for triples with premises, namely one that
takes the recursive depth needed to complete execution, enables
correctness proof \item auxiliary variables are handled first-class (-> Thomas Kleymann) \item expressions not flattened to elementary assignments (as usual for
axiomatic semantics) but treated first-class => explicit result value
handling \item intermediate values not on triple, but on assertion level
(with result entry) \item multiple results with semantical substitution mechnism not requiring a
stack \item because of dynamic method binding, terms need to be dependent on state.
this isalso useful for conditional expressions and statements \item result values in triples exactly as in eval relation (alsofor xcpt states) \item validity: additional assumption of state conformance and well-typedness,
which is required for soundness andthus rule hazard required of completeness \end{itemize}
restrictions: \begin{itemize} \item all triples in a derivation are of the same type (due to weak
polymorphism) \end{itemize} ›
translations "\Val:v . b" == "(\v. b) \ CONST the_In1" "\Var:v . b" == "(\v. b) \ CONST the_In2" "\Vals:v. b" == "(\v. b) \ CONST the_In3"
🍋‹relation on result values, state and auxiliary variables› type_synonym'a assn = "res \ state \ 'a ==> bool" translations
(type) "'a assn" <= (type) "vals \ state \ 'a \ bool"
definition
assn_imp :: "'a assn \ 'a assn \ bool" (infixr‹==>› 25) where"(P \ Q) = (\Y s Z. P Y s Z \ Q Y s Z)"
lemma assn_imp_def2 [iff]: "(P \ Q) = (\Y s Z. P Y s Z \ Q Y s Z)" apply (unfold assn_imp_def) apply (rule HOL.refl) done
subsubsection "assertion transformers"
subsection"peek-and"
definition
peek_and :: "'a assn \ (state \ bool) \ 'a assn" (infixl‹∧.› 13) where"(P \. p) = (\Y s Z. P Y s Z \ p s)"
lemma peek_and_def2 [simp]: "peek_and P p Y s = (\Z. (P Y s Z \ p s))" apply (unfold peek_and_def) apply (simp (no_asm)) done
(*###Do not work for some strange (unification?) reason lemma subst_res_Val_beta [simp]: "(\<lambda>Y. P (the_In1 Y))\<leftarrow>Val v = (\<lambda>Y. P v)" apply (rule ext) by simp
lemma subst_res_Var_beta [simp]: "(\<lambda>Y. P (the_In2 Y))\<leftarrow>Var vf = (\<lambda>Y. P vf)"; apply (rule ext) by simp
lemma subst_res_Vals_beta [simp]: "(\<lambda>Y. P (the_In3 Y))\<leftarrow>Vals vs = (\<lambda>Y. P vs)"; apply (rule ext) by simp
*)
subsection"subst-Bool"
definition
subst_Bool :: "'a assn \ bool \ 'a assn" (‹_←=_› [60,61] 60) where"P\=b = (\Y s Z. \v. P (Val v) s Z \ (normal s \ the_Bool v=b))"
lemma subst_Bool_def2 [simp]: "(P\=b) Y s Z = (\v. P (Val v) s Z \ (normal s \ the_Bool v=b))" apply (unfold subst_Bool_def) apply (simp (no_asm)) done
lemma subst_Bool_the_BoolI: "P (Val b) s Z \ (P\=the_Bool b) Y s Z" apply auto done
subsection"peek-res"
definition
peek_res :: "(res \ 'a assn) \ 'a assn" where"peek_res Pf = (\Y. Pf Y Y)"
(* unused *) lemma subst_Bool_ign_res_eq: "((P\=b)\=x) Y s Z = ((P\=b) Y s Z \ Y=x)" apply (simp (no_asm)) done
subsection"RefVar"
definition
RefVar :: "(state \ vvar \ state) \ 'a assn \ 'a assn" (infixr‹..;› 13) where"(vf ..; P) = (\Y s. let (v,s') = vf s in P (Var v) s')"
lemma RefVar_def2 [simp]: "(vf ..; P) Y s =
P (Var (fst (vf s))) (snd (vf s))" apply (unfold RefVar_def Let_def) apply (simp (no_asm) add: split_beta) done
subsection"allocation"
definition
Alloc :: "prog \ obj_tag \ 'a assn \ 'a assn" where"Alloc G otag P = (\Y s Z. \s' a. G\s \halloc otag\a\ s'\ P (Val (Addr a)) s' Z)"
definition
SXAlloc :: "prog \ 'a assn \ 'a assn" where"SXAlloc G P = (\Y s Z. \s'. G\s \sxalloc\ s' \ P Y s' Z)"
lemma Alloc_def2 [simp]: "Alloc G otag P Y s Z =
(∀s' a. G\s \halloc otag\a\ s'⟶ P (Val (Addr a)) s' Z)" apply (unfold Alloc_def) apply (simp (no_asm)) done
lemma SXAlloc_def2 [simp]: "SXAlloc G P Y s Z = (\s'. G\s \sxalloc\ s' \ P Y s' Z)" apply (unfold SXAlloc_def) apply (simp (no_asm)) done
subsubsection "validity"
definition
type_ok :: "prog \ term \ state \ bool"where "type_ok G t s =
(∃L T C A. (normal s ⟶(prg=G,cls=C,lcl=L)⊨t#x003a;T ∧ (prg=G,cls=C,lcl=L)⊨dom (locals (store s))¬t¬A ) ∧ s#x003a;⪯(G,L))"
datatype'a triple = triple "('a assn)" "term" "('a assn)" (** should be
something like triple = ∀'a. triple ('a assn) term ('a assn) **)
(‹{(1_)}/ _≻/ {(1_)}› [3,65,3] 75) type_synonym'a triples = "'a triple set"
definition mtriples :: "('c \ 'sig \ 'a assn) \ ('c \ 'sig \ expr) \
('c \ 'sig ==>'a assn) \ ('c ×'sig) set \ 'a triples" (\{{(1_)}/ _-\/ {(1_)} | _}\[3,65,3,65]75) where "{{P} tf-\ {Q} | ms} = (\(C,sig). {Normal(P C sig)} tf C sig-\ {Q C sig})`ms"
definition
triple_valid :: "prog \ nat \ 'a triple \ bool" (‹_⊨_:_› [61,0, 58] 57) where "G\n:t =
(case t of {P} t≻ {Q} ==> ∀Y s Z. P Y s Z ⟶ type_ok G t s ⟶
(∀Y' s'. G⊨s ←-t≻←-n→ (Y',s') ⟶ Q Y' s' Z))"
lemma triple_valid_def2: "G\n:{P} t\ {Q} =
(∀Y s Z. P Y s Z ⟶ (∃L. (normal s ⟶ (∃ C T A. (prg=G,cls=C,lcl=L)⊨t#x003a;T ∧ (prg=G,cls=C,lcl=L)⊨dom (locals (store s))¬t¬A)) ∧
s#x003a;⪯(G,L)) ⟶ (∀Y' s'. G⊨s ←-t≻←-n→ (Y',s')⟶ Q Y' s' Z))" apply (unfold triple_valid_def type_ok_def) apply (simp (no_asm)) done
inductive
ax_derivs :: "prog \ 'a triples \ 'a triples \ bool" (‹_,_|⊨_› [61,58,58] 57) and ax_deriv :: "prog \ 'a triples \ 'a triple \ bool" (‹_,_⊨_› [61,58,58] 57) for G :: prog where
(* could be added for convenience and efficiency, but is not necessary cut: "\<lbrakk>G,A'|\<turnstile>ts; G,A|\<turnstile>A'\<rbrakk> \<Longrightarrow> G,A |\<turnstile>ts"
*)
| weaken:"\G,A|\ts'; ts \ ts'\ \ G,A|\ts"
| conseq:"\Y s Z . P Y s Z \ (\P' Q'. G,A\{P'} t\ {Q'} \ (\Y' s'.
(∀Y Z'. P' Y s Z' \ Q' Y' s' Z') \
Q Y' s' Z )) ==> G,A⊨{P } t≻ {Q }"
| hazard:"G,A\{P \. Not \ type_ok G t} t\ {Q}"
| Abrupt: "G,A\{P\(undefined3 t) \. Not \ normal} t\ {P}"
| Done: "G,A\{Normal (P\\ \. initd C)} .Init C. {P}"
| Init: "\the (class G C) = c;
G,A⊨{Normal ((P ∧. Not ∘ initd C) ;. supd (init_class_obj G C))}
.(if C = Object then Skip else Init (super c)). {Q}; ∀l. G,A⊨{Q ∧. (λs. l = locals (store s)) ;. set_lvars Map.empty}
.init c. {set_lvars l .; R}]==>
G,A⊨{Normal (P ∧. Not ∘ initd C)} .Init C. {R}"
🍋‹Some dummy rules for the intermediate terms ‹Callee›, ‹InsInitE›, ‹InsInitV›, ‹FinA› only used by the smallstep
semantics.›
| InsInitV: " G,A\{Normal P} InsInitV c v=\ {Q}"
| InsInitE: " G,A\{Normal P} InsInitE c e-\ {Q}"
| Callee: " G,A\{Normal P} Callee l e-\ {Q}"
| FinA: " G,A\{Normal P} .FinA a c. {Q}" (* axioms
*)
definition
adapt_pre :: "'a assn \ 'a assn \ 'a assn \ 'a assn" where"adapt_pre P Q Q' = (\Y s Z. \Y' s'. \Z'. P Y s Z' \ (Q Y' s' Z' \ Q' Y' s' Z))"
text‹In the following rules we often haveto give some type annotations like: 🍋‹G,(A::'a triple set)\{P::'a assn} t≻ {Q}›.
Given only the term above without annotations, Isabelle would infer a more
general type were we could have
different types of auxiliary variables in the assumption set (🍋‹A›) and in the triple itself (🍋‹P›and🍋‹Q›). But ‹ax_derivs.Methd› enforces the same type in the inductivedefinition of
the derivation. So we havetorestrict the typesto be able toapply the
rules. › lemma conseq12: "\G,(A::'a triple set)\{P'::'a assn} t\ {Q'}; ∀Y s Z. P Y s Z ⟶ (∀Y' s'. (∀Y Z'. P' Y s Z' \ Q' Y' s' Z') \
Q Y' s' Z)] ==> G,A⊨{P ::'a assn} t\ {Q }" apply (rule ax_derivs.conseq) apply clarsimp apply blast done
🍋‹Nice variant, since it is so symmetric we might be able to memorise it.› lemma conseq12': "\G,(A::'a triple set)⊨{P'::'a assn} t≻ {Q'}; \s Y' s'.
(∀Y Z. P' Y s Z \ Q' Y' s' Z) ⟶
(∀Y Z. P Y s Z ⟶ Q Y' s' Z)] ==> G,A⊨{P::'a assn } t\ {Q }" apply (erule conseq12) apply fast done
lemma conseq12_from_conseq12': "\G,(A::'a triple set)⊨{P'::'a assn} t≻ {Q'}; ∀Y s Z. P Y s Z ⟶ (∀Y' s'. (∀Y Z'. P' Y s Z' \ Q' Y' s' Z') \
Q Y' s' Z)] ==> G,A⊨{P::'a assn} t\ {Q }" apply (erule conseq12') apply blast done
lemma ax_escape: "\\Y s Z. P Y s Z ⟶ G,(A::'a triple set)\{\Y' s' (Z'::'a). (Y',s') = (Y,s)}
t≻
{λY s Z'. Q Y s Z} ]==> G,A⊨{P::'a assn} t\ {Q::'a assn}" apply (rule ax_derivs.conseq) apply force done
(* unused *) lemma ax_constant: "\ C \ G,(A::'a triple set)\{P::'a assn} t\ {Q}\ ==> G,A⊨{λY s Z. C ∧ P Y s Z} t≻ {Q}" apply (rule ax_escape (* unused *)) apply clarify apply (rule conseq12) apply fast apply auto done (*alternative (more direct) proof:
apply (rule ax_derivs.conseq) *) apply (fast)
*)
lemma ax_impossible [intro]: "G,(A::'a triple set)\{\Y s Z. False} t\ {Q::'a assn}" apply (rule ax_escape) apply clarify done
(* unused *) lemma ax_nochange_lemma: "\P Y s; All ((=) w)\ \ P w s" apply auto done
lemma ax_nochange: "G,(A::(res \ state) triple set)\{\Y s Z. (Y,s)=Z} t\ {\Y s Z. (Y,s)=Z} ==> G,A⊨{P::(res × state) assn} t≻ {P}" apply (erule conseq12) apply auto apply (erule (1) ax_nochange_lemma) done
(* unused *) lemma ax_trivial: "G,(A::'a triple set)\{P::'a assn} t\ {\Y s Z. True}" apply (rule ax_derivs.conseq(* unused *)) apply auto done
(* unused *) lemma ax_disj: "\G,(A::'a triple set)\{P1::'a assn} t\ {Q1}; G,A\{P2::'a assn} t\ {Q2}\ ==> G,A⊨{λY s Z. P1 Y s Z ∨ P2 Y s Z} t≻ {λY s Z. Q1 Y s Z ∨ Q2 Y s Z}" apply (rule ax_escape (* unused *)) apply safe apply (erule conseq12, fast)+ done
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 und die Messung sind noch experimentell.