subsection‹Axiomatic semantics of Java expressions and statements
(see also Eval.thy) › theory AxSem imports Evaln TypeSafe begin
text‹
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 is also useful for conditional expressions and statements
item result values in triples exactly as in eval relation (also for xcpt
states)
item validity: additional assumption of state conformance and well-typedness,
which is required for soundness and thus rule hazard required of completeness
end{itemize}
:
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 lemmasubst_res_Val_beta[simp]:"(\<lambda>Y.P(the_In1Y))\<leftarrow>Valv=(\<lambda>Y.Pv)" apply(ruleext) bysimp
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 = \<forall>'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
"G,A ⊨t ≡ G,A|⊨{t}"
| empty: " G,A|⊨{}"
| insert:"[G,A⊨t; G,A|⊨ts]==> G,A|⊨insert t ts"
| asm: "ts⊆A ==> G,A|⊨ts"
(* 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
.›
| 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 have to give some type annotations like: term‹G,(A::'a triple set)⊨{P::'a assn} t≻ {Q}›.
only the term above without annotations, Isabelle would infer a more
type were we could have
types of auxiliary variables in the assumption set (term‹A›) and
the triple itself (term‹P› and term‹Q›). But ‹ax_derivs.Methd› enforces the same type in the inductive definition of
derivation. So we have to restrict the types to be able to apply the
. › 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} \<rbrakk> ==> 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}] \<Longrightarrow> 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) *)(* unused *)(* 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.