type_synonym
init_stack = "expr list × bool" ― ‹Stack of expressions waiting on initialization in small step; indicator boolean True if current expression has been init checked›
text‹The semantics of binary operators: ›
fun binop :: "bop × val × val ==> val option"where "binop(Eq,v1,v2) = Some(Bool (v1 = v2))"
| "binop(Add,Intg i1,Intg i2) = Some(Intg(i1+i2))"
| "binop(bop,v1,v2) = None"
lemma map_Val_throw_eq: "map Val vs @ throw ex # es = map Val vs' @ throw ex' # es' ==> ex = ex'" (*<*)by(induct vs arbitrary: vs'; case_tac vs') auto(*>*)
lemma map_Val_nthrow_neq: "map Val vs = map Val vs' @ throw ex' # es' ==> False" (*<*)by(induct vs arbitrary: vs'; case_tac vs') auto(*>*)
lemma map_Val_eq: "map Val vs = map Val vs' ==> vs = vs'" (*<*)by(induct vs arbitrary: vs'; case_tac vs') auto(*>*)
lemma init_rhs_neq [simp]: "e ≠ INIT C (Cs,b) ← e" proof - have"size e ≠ size (INIT C (Cs,b) ← e)"by auto thenshow ?thesis by fastforce qed
lemma init_rhs_neq' [simp]: "INIT C (Cs,b) ← e ≠ e" proof - have"size e ≠ size (INIT C (Cs,b) ← e)"by auto thenshow ?thesis by fastforce qed
lemma ri_rhs_neq [simp]: "e ≠ RI(C,e');Cs ← e" proof - have"size e ≠ size (RI(C,e');Cs ← e)"by auto thenshow ?thesis by fastforce qed
lemma ri_rhs_neq' [simp]: "RI(C,e');Cs ← e ≠ e" proof - have"size e ≠ size (RI(C,e');Cs ← e)"by auto thenshow ?thesis by fastforce qed
subsection"Syntactic sugar"
abbreviation (input)
InitBlock:: "'a ==> ty ==> 'a exp ==> 'a exp ==> 'a exp" (‹(1'{_:_ := _;/ _})›) where "InitBlock V T e1 e2 == {V:T; V := e1;; e2}"
abbreviation unit where"unit == Val Unit" abbreviation null where"null == Val Null" abbreviation"addr a == Val(Addr a)" abbreviation"true == Val(Bool True)" abbreviation"false == Val(Bool False)"
abbreviation
Throw :: "addr ==> 'a exp"where "Throw a == throw(Val(Addr a))"
lemma lass_val_of_spec: assumes"lass_val_of e = ⌊a⌋" shows"e = (fst a:=Val (snd a))" using assms proof(cases e) case (LAss V e') thenshow ?thesis using assms proof(cases e')qed(auto) qed(auto)
fun map_vals_of :: "'a exp list ==> val list option"where "map_vals_of (e#es) = (case val_of e of Some v ==> (case map_vals_of es of Some vs ==> Some (v#vs) | _ ==> None) | _ ==> None)" | "map_vals_of [] = Some []"
lemma map_vals_of_spec: "map_vals_of es = Some vs ==> es = map Val vs" proof(induct es arbitrary: vs) qed(auto simp: val_of_spec)
lemma map_vals_of_Vals[simp]: "map_vals_of (map Val vs) = ⌊vs⌋"by(induct vs, auto)
lemma map_vals_of_throw[simp]: "map_vals_of (map Val vs @ throw e # es') = None" by(induct vs, auto)
fun bool_of :: "'a exp ==> bool option"where "bool_of true = Some True" | "bool_of false = Some False" | "bool_of _ = None"
lemma bool_of_specT: assumes"bool_of e = Some True"shows"e = true" proof - have"bool_of e = Some True"by fact thenshow ?thesis proof(cases e) case (Val x3) with assms show ?thesis proof(cases x3) case (Bool x) with assms Val show ?thesis proof(cases x)qed(auto) qed(simp_all) qed(auto) qed
lemma bool_of_specF: assumes"bool_of e = Some False"shows"e = false" proof - have"bool_of e = Some False"by fact thenshow ?thesis proof(cases e) case (Val x3) with assms show ?thesis proof(cases x3) case (Bool x) with assms Val show ?thesis proof(cases x)qed(auto) qed(simp_all) qed(auto) qed
fun throw_of :: "'a exp ==> 'a exp option"where "throw_of (throw e') = Some e'" | "throw_of _ = None"
lemma throw_of_spec: "throw_of e = Some e' ==> e = throw e'" proof(cases e) qed(auto)
fun init_exp_of :: "'a exp ==> 'a exp option"where "init_exp_of (INIT C (Cs,b) ← e) = Some e" | "init_exp_of (RI(C,e');Cs ← e) = Some e" | "init_exp_of _ = None"
lemma init_exp_of_neq [simp]: "init_exp_of e = ⌊e'⌋==> e' ≠ e"by(cases e, auto) lemma init_exp_of_neq'[simp]: "init_exp_of e = ⌊e'⌋==> e ≠ e'"by(cases e, auto)
subsection‹Class initialization›
text‹ This section defines a few functions that return information
about an expression's current initialization status. ›
lemma nsub_RIs_def[simp]: "¬sub_RIs es ==>∀e ∈ set es. ¬sub_RI e" by(induct es, auto)
lemma sub_RI_base: "e = INIT C (Cs, b) ← e' ∨ e = RI(C,e0);Cs ← e' ==> sub_RI e" by(cases e, auto)
lemma nsub_RI_Vals[simp]: "¬sub_RIs (map Val vs)" by(induct vs, auto)
lemma lass_val_of_nsub_RI: "lass_val_of e = ⌊a⌋==>¬sub_RI e" by(drule lass_val_of_spec, simp)
― ‹ is not currently initializing class @{text C'} (point past checking flag) › primrec not_init :: "cname ==> 'a exp ==> bool"and not_inits :: "cname ==> 'a exp list==> bool"where "not_init C' (new C) = True"
| "not_init C' (Cast C e) = not_init C' e"
| "not_init C' (Val v) = True"
| "not_init C' (e1«bop¬ e2) = (not_init C' e1∧ not_init C' e2)"
| "not_init C' (Var V) = True"
| "not_init C' (LAss V e) = not_init C' e"
| "not_init C' (e∙F{D}) = not_init C' e"
| "not_init C' (C∙sF{D}) = True"
| "not_init C' (e1∙F{D}:=e2) = (not_init C' e1∧ not_init C' e2)"
| "not_init C' (C∙sF{D}:=e2) = not_init C' e2"
| "not_init C' (e∙M(es)) = (not_init C' e ∧ not_inits C' es)"
| "not_init C' (C∙sM(es)) = not_inits C' es"
| "not_init C' ({V:T; e}) = not_init C' e"
| "not_init C' (e1;;e2) = (not_init C' e1∧ not_init C' e2)"
| "not_init C' (if (b) e1 else e2) = (not_init C' b ∧ not_init C' e1∧ not_init C' e2)"
| "not_init C' (while (b) e) = (not_init C' b ∧ not_init C' e)"
| "not_init C' (throw e) = not_init C' e"
| "not_init C' (try e1 catch(C V) e2) = (not_init C' e1∧ not_init C' e2)"
| "not_init C' (INIT C (Cs,b) ← e) = ((b ⟶ Cs = Nil ∨ C' ≠ hd Cs) ∧ C' ∉ set(tl Cs) ∧ not_init C' e)"
| "not_init C' (RI (C,e);Cs ← e') = (C' ∉ set (C#Cs) ∧ not_init C' e ∧ not_init C' e')"
| "not_inits C' ([]) = True"
| "not_inits C' (e#es) = (not_init C' e ∧ not_inits C' es)"
lemma not_inits_def'[simp]: "not_inits C es ==>∀e ∈ set es. not_init C e" by(induct es, auto)
lemma nsub_RIs_not_inits_aux: "∀e ∈ set es. ¬sub_RI e ⟶ not_init C e ==>¬sub_RIs es ==> not_inits C es" by(induct es, auto)
lemma nsub_RI_not_init: "¬sub_RI e ==> not_init C e" proof(induct e) qed(auto intro: nsub_RIs_not_inits_aux)
lemma nsub_RIs_not_inits: "¬sub_RIs es ==> not_inits C es" by(rule nsub_RIs_not_inits_aux) (simp_all add: nsub_RI_not_init)
abbreviation subexp_of :: "'a exp ==> 'a exp ==> bool"where "subexp_of e e' ≡ e ∈ subexp e'"
lemma subexp_size_le: "(e' ∈ subexp e ⟶ size e' < size e) ∧ (e' ∈ subexps es ⟶ size e' < size_list size es)" proof(induct rule: subexp_subexps.induct) case Call:11thenshow ?caseusing not_less_eq size_list_estimation by fastforce next case SCall:12thenshow ?caseusing not_less_eq size_list_estimation by fastforce qed(auto)
lemma subexps_def2: "subexps es = set es ∪ (∪e ∈ set es. subexp e)"by(induct es, auto)
― ‹ strong induction › lemmashows subexp_induct[consumes 1]: "(∧e. subexp e = {} ==> R e) ==> (∧e. (∧e'. e' ∈ subexp e ==> R e') ==> R e) ==> (∧es. (∧e'. e' ∈ subexps es ==> R e') ==> Rs es) ==> (∀e'. e' ∈ subexp e ⟶ R e') ∧ R e" and subexps_induct[consumes 1]: "(∧es. subexps es = {} ==> Rs es) ==> (∧e. (∧e'. e' ∈ subexp e ==> R e') ==> R e) ==> (∧es. (∧e'. e' ∈ subexps es ==> R e') ==> Rs es) ==> (∀e'. e' ∈ subexps es ⟶ R e') ∧ Rs es" proof(induct rule: subexp_subexps_induct) case (Cast x1 x2) thenhave"(∀e'. subexp_of e' x2 ⟶ R e') ∧ R x2"by fast thenhave"(∀e'. subexp_of e' (Cast x1 x2) ⟶ R e')"by auto thenshow ?caseusing Cast.prems(2) by fast next case (BinOp x1 x2 x3) thenhave"(∀e'. subexp_of e' x1 ⟶ R e') ∧ R x1"and"(∀e'. subexp_of e' x3 ⟶ R e') ∧ R x3" by fast+ thenhave"(∀e'. subexp_of e' (x1 «x2¬ x3) ⟶ R e')"by auto thenshow ?caseusing BinOp.prems(2) by fast next case (LAss x1 x2) thenhave"(∀e'. subexp_of e' x2 ⟶ R e') ∧ R x2"by fast thenhave"(∀e'. subexp_of e' (LAss x1 x2) ⟶ R e')"by auto thenshow ?caseusing LAss.prems(2) by fast next case (FAcc x1 x2 x3) thenhave"(∀e'. subexp_of e' x1 ⟶ R e') ∧ R x1"by fast thenhave"(∀e'. subexp_of e' (x1∙x2{x3}) ⟶ R e')"by auto thenshow ?caseusing FAcc.prems(2) by fast next case (FAss x1 x2 x3 x4) thenhave"(∀e'. subexp_of e' x1 ⟶ R e') ∧ R x1"and"(∀e'. subexp_of e' x4 ⟶ R e') ∧ R x4" by fast+ thenhave"(∀e'. subexp_of e' (x1∙x2{x3} := x4) ⟶ R e')"by auto thenshow ?caseusing FAss.prems(2) by fast next case (SFAss x1 x2 x3 x4) thenhave"(∀e'. subexp_of e' x4 ⟶ R e') ∧ R x4"by fast thenhave"(∀e'. subexp_of e' (x1∙sx2{x3} := x4) ⟶ R e')"by auto thenshow ?caseusing SFAss.prems(2) by fast next case (Call x1 x2 x3) thenhave"(∀e'. subexp_of e' x1 ⟶ R e') ∧ R x1"and"(∀e'. e' ∈ subexps x3 ⟶ R e') ∧ Rs x3" by fast+ thenhave"(∀e'. subexp_of e' (x1∙x2(x3)) ⟶ R e')"using subexps_def2 by auto thenshow ?caseusing Call.prems(2) by fast next case (SCall x1 x2 x3) thenhave"(∀e'. e' ∈ subexps x3 ⟶ R e') ∧ Rs x3"by fast thenhave"(∀e'. subexp_of e' (x1∙sx2(x3)) ⟶ R e')"using subexps_def2 by auto thenshow ?caseusing SCall.prems(2) by fast next case (Block x1 x2 x3) thenhave"(∀e'. subexp_of e' x3 ⟶ R e') ∧ R x3"by fast thenhave"(∀e'. subexp_of e' {x1:x2; x3} ⟶ R e')"by auto thenshow ?caseusing Block.prems(2) by fast next case (Seq x1 x2) thenhave"(∀e'. subexp_of e' x1 ⟶ R e') ∧ R x1"and"(∀e'. subexp_of e' x2 ⟶ R e') ∧ R x2" by fast+ thenhave"(∀e'. subexp_of e' (x1;; x2) ⟶ R e')"by auto thenshow ?caseusing Seq.prems(2) by fast next case (Cond x1 x2 x3) thenhave"(∀e'. subexp_of e' x1 ⟶ R e') ∧ R x1"and"(∀e'. subexp_of e' x2 ⟶ R e') ∧ R x2" and"(∀e'. subexp_of e' x3 ⟶ R e') ∧ R x3"by fast+ thenhave"(∀e'. subexp_of e' (if (x1) x2 else x3) ⟶ R e')"by auto thenshow ?caseusing Cond.prems(2) by fast next case (While x1 x2) thenhave"(∀e'. subexp_of e' x1 ⟶ R e') ∧ R x1"and"(∀e'. subexp_of e' x2 ⟶ R e') ∧ R x2" by fast+ thenhave"(∀e'. subexp_of e' (while (x1) x2) ⟶ R e')"by auto thenshow ?caseusing While.prems(2) by fast next case (throw x) thenhave"(∀e'. subexp_of e' x ⟶ R e') ∧ R x"by fast thenhave"(∀e'. subexp_of e' (throw x) ⟶ R e')"by auto thenshow ?caseusing throw.prems(2) by fast next case (TryCatch x1 x2 x3 x4) thenhave"(∀e'. subexp_of e' x1 ⟶ R e') ∧ R x1"and"(∀e'. subexp_of e' x4 ⟶ R e') ∧ R x4" by fast+ thenhave"(∀e'. subexp_of e' (try x1 catch(x2 x3) x4) ⟶ R e')"by auto thenshow ?caseusing TryCatch.prems(2) by fast next case (INIT x1 x2 x3 x4) thenhave"(∀e'. subexp_of e' x4 ⟶ R e') ∧ R x4"by fast thenhave"(∀e'. subexp_of e' (INIT x1 (x2,x3) ← x4) ⟶ R e')"by auto thenshow ?caseusing INIT.prems(2) by fast next case (RI x1 x2 x3 x4) thenhave"(∀e'. subexp_of e' x2 ⟶ R e') ∧ R x2"and"(∀e'. subexp_of e' x4 ⟶ R e') ∧ R x4" by fast+ thenhave"(∀e'. subexp_of e' (RI (x1,x2) ; x3 ← x4) ⟶ R e')"by auto thenshow ?caseusing RI.prems(2) by fast next case (Cons_exp x1 x2) thenhave"(∀e'. subexp_of e' x1 ⟶ R e') ∧ R x1"and"(∀e'. e' ∈ subexps x2 ⟶ R e') ∧ Rs x2" by fast+ thenhave"(∀e'. e' ∈ subexps (x1 # x2) ⟶ R e')"using subexps_def2 by auto thenshow ?caseusing Cons_exp.prems(3) by fast qed(auto)
subsection"Final expressions" (* these definitions and most of the lemmas were in BigStep.thy in the original Jinja *)
definition final :: "'a exp ==> bool" where "final e ≡ (∃v. e = Val v) ∨ (∃a. e = Throw a)"
definition finals:: "'a exp list ==> bool" where "finals es ≡ (∃vs. es = map Val vs) ∨ (∃vs a es'. es = map Val vs @ Throw a # es')"
lemma [iff]: "finals (Val v # es) = finals es" (*<*) proof(rule iffI) assume"finals (Val v # es)" moreover { fix vs a es' assume"∀vs a es'. es ≠ map Val vs @ Throw a # es'" and"Val v # es = map Val vs @ Throw a # es'" thenhave"∃vs. es = map Val vs"by(case_tac vs; simp)
} ultimatelyshow"finals es"by(clarsimp simp add: finals_def) next assume"finals es" moreover { fix vs a es' assume"es = map Val vs @ Throw a # es'" thenhave"∃vs' a' es''. Val v # map Val vs @ Throw a # es' = map Val vs' @ Throw a' # es''" by(rule_tac x = "v#vs"in exI) simp
} ultimatelyshow"finals (Val v # es)"by(clarsimp simp add: finals_def) qed (*>*)
lemma finals_app_map[iff]: "finals (map Val vs @ es) = finals es" (*<*)by(induct_tac vs, auto)(*>*)
lemma [iff]: "finals (map Val vs)" (*<*)using finals_app_map[of vs "[]"]by(simp)(*>*)
lemma [iff]: "finals (throw e # es) = (∃a. e = addr a)" (*<*) proof(rule iffI) assume"finals (throw e # es)" moreover { fix vs a es' assume"throw e # es = map Val vs @ Throw a # es'" thenhave"∃a. e = addr a"by(case_tac vs; simp)
} ultimatelyshow"∃a. e = addr a"by(clarsimp simp add: finals_def) next assume"∃a. e = addr a" moreover { fix vs a es' assume"e = addr a" thenhave"∃vs aa es'. Throw a # es = map Val vs @ Throw aa # es'" by(rule_tac x = "[]"in exI) simp
} ultimatelyshow"finals (throw e # es)"by(clarsimp simp add: finals_def) qed (*>*)
lemma not_finals_ConsI: "¬ final e ==>¬ finals(e#es)" (*<*) proof - assume"¬ final e" moreover { fix vs a es' assume"∀v. e ≠ Val v"and"∀a. e ≠ Throw a" thenhave"e # es ≠ map Val vs @ Throw a # es'"by(case_tac vs; simp)
} ultimatelyshow ?thesis by(clarsimp simp add:finals_def final_def) qed (*>*)
lemma not_finals_ConsI2: "e = Val v ==>¬ finals es ==>¬ finals(e#es)" (*<*) proof - assume [simp]: "e = Val v"and"¬ finals es" moreover { fix vs a es' assume"∀vs. es ≠ map Val vs"and"∀vs a es'. es ≠ map Val vs @ Throw a # es'" thenhave"e # es ≠ map Val vs @ Throw a # es'"by(case_tac vs; simp)
} ultimatelyshow ?thesis by(clarsimp simp add:finals_def final_def) qed (*>*)
end
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.14 Sekunden
(vorverarbeitet am 2026-06-10)
¤
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.