section"LTL integration" theory PromelaLTL imports
Promela
LTL.LTL begin
text‹We have a semantic engine for Promela. But we need to have
integration with LTL -- more specificly, we must know when a proposition
true in a global state. This is achieved in this theory.›
subsection‹LTL optimization›
text‹For efficiency reasons, we do not store the whole @{typ expr} on the labels
a system automaton, but @{typ nat} instead. This index then is used to look up the
@{typ expr}.›
type_synonym APs = "expr iarray"
primrec ltlc_aps_list' :: "'a ltlc ==> 'a list ==> 'a list" where "ltlc_aps_list' True_ltlc l = l"
| "ltlc_aps_list' False_ltlc l = l"
| "ltlc_aps_list' (Prop_ltlc p) l = (if List.member l p then l else p#l)"
| "ltlc_aps_list' (Not_ltlc x) l = ltlc_aps_list' x l"
| "ltlc_aps_list' (Next_ltlc x) l = ltlc_aps_list' x l"
| "ltlc_aps_list' (Final_ltlc x) l = ltlc_aps_list' x l"
| "ltlc_aps_list' (Global_ltlc x) l = ltlc_aps_list' x l"
| "ltlc_aps_list' (And_ltlc x y) l = ltlc_aps_list' y (ltlc_aps_list' x l)"
| "ltlc_aps_list' (Or_ltlc x y) l = ltlc_aps_list' y (ltlc_aps_list' x l)"
| "ltlc_aps_list' (Implies_ltlc x y) l = ltlc_aps_list' y (ltlc_aps_list' x l)"
| "ltlc_aps_list' (Until_ltlc x y) l = ltlc_aps_list' y (ltlc_aps_list' x l)"
| "ltlc_aps_list' (Release_ltlc x y) l = ltlc_aps_list' y (ltlc_aps_list' x l)"
| "ltlc_aps_list' (WeakUntil_ltlc x y) l = ltlc_aps_list' y (ltlc_aps_list' x l)"
| "ltlc_aps_list' (StrongRelease_ltlc x y) l = ltlc_aps_list' y (ltlc_aps_list' x l)"
lemma ltlc_aps_list'_correct: "set (ltlc_aps_list' φ l) = atoms_ltlc φ ∪ set l" by (induct φ arbitrary: l) auto
lemma ltlc_aps_list'_distinct: "distinct l ==> distinct (ltlc_aps_list' φ l)" by (induct φ arbitrary: l) auto
definition ltlc_aps_list :: "'a ltlc ==> 'a list" where "ltlc_aps_list φ = ltlc_aps_list' φ []"
primrec idx' :: "nat ==> 'a list ==> 'a ==> nat option"where "idx' _ [] _ = None"
| "idx' ctr (x#xs) y = (if x = y then Some ctr else idx' (ctr+1) xs y)"
definition"idx = idx' 0"
lemma idx'_correct: assumes"distinct xs" shows"idx' ctr xs y = Some n ⟷ n ≥ ctr ∧ n < length xs + ctr ∧ xs ! (n-ctr) = y" using assms proof (induction xs arbitrary: n ctr) case (Cons x xs) show ?case proof (cases "x=y") case True with Cons.prems have *: "y ∉ set xs"by auto
{ assume A: "(y#xs)!(n-ctr) = y" and less: "ctr ≤ n" and length: "n < length (y#xs) + ctr" have"n = ctr" proof (rule ccontr) assume"n ≠ ctr"with less have"n-ctr > 0"by auto moreoverfrom‹n≠ctr› length have"n-ctr < length(y#xs)"by auto ultimatelyhave"(y#xs)!(n-ctr) ∈ set xs"by simp with A * show False by auto qed
} with True Cons show ?thesis by auto next case False from Cons have"distinct xs"by simp with Cons.IH False have"idx' (Suc ctr) xs y = Some n ⟷ Suc ctr ≤ n ∧ n < length xs + Suc ctr ∧ xs ! (n - Suc ctr) = y" by simp with False show ?thesis apply - apply (rule iffI) apply clarsimp_all done qed qed simp
lemma idx_correct: assumes"distinct xs" shows"idx xs y = Some n ⟷ n < length xs ∧ xs ! n = y" using idx'_correct[OF assms] by (simp add: idx_def)
lemma idx_dom: assumes"distinct xs" shows"dom (idx xs) = set xs" by (auto simp add: idx_correct assms in_set_conv_nth)
lemma idx_image_self: assumes"distinct xs" shows"(the ∘ idx xs) ` set xs = {..<length xs}" proof (safe) fix x assume"x ∈ set xs"with in_set_conv_nth obtain n where n: "n < length xs""xs ! n = x"by metis with idx_correct[OF assms] have"idx xs x = Some n"by simp hence"the (idx xs x) = n"by simp with n show"(the ∘ idx xs) x < length xs"by simp next fix n assume"n < length xs" moreoverwith nth_mem have"xs ! n ∈ set xs"by simp thenobtain x where"xs ! n = x""x ∈ set xs"by simp_all ultimatelyhave"idx xs x = Some n"by (simp add: idx_correct[OF assms]) hence"the (idx xs x) = n"by simp thus"n ∈ (the ∘ idx xs) ` set xs" using‹x ∈ set xs› by auto qed
lemma idx_ran: assumes"distinct xs" shows"ran (idx xs) = {..<length xs}" using ran_is_image[where M="idx xs"] using idx_image_self[OF assms] idx_dom[OF assms] by simp
definition promela_is_run_ltl :: "program × APs × gState ==> gState word ==> bool" where "promela_is_run_ltl promg r ≡ let (prog,APs,g) = promg in promela_is_run' (prog,g) r"
definition promela_props :: "gState ==> expr set" where "promela_props g = {e. exprArith g emptyProc e ≠ 0}"
definition promela_props_ltl :: "APs ==> gState ==> nat set" where "promela_props_ltl APs g ≡ Collect (propValid APs g)"
definition promela_language :: "ast ==> expr set word set"where "promela_language ast ≡ {promela_props ∘ r | r. promela_is_run ast r}"
definition promela_language_ltl :: "program × APs × gState ==> nat set word set"where "promela_language_ltl promg ≡ let (prog,APs,g) = promg in {promela_props_ltl APs ∘ r | r. promela_is_run_ltl promg r}"
from ltl_convert_correct assms have D: "distinct ?APs"by simp
show ?thesis proof (intro ext set_eqI iffI) fix g i assume"i ∈ promela_props_ltl APs g" hence"propValid APs g i"by (simp add: promela_props_ltl_def) hence l: "i < IArray.length APs""exprArith g emptyProc (APs!!i) ≠ 0" by (simp_all add: propValid_def) hence"APs!!i ∈ promela_props g"by (simp add: promela_props_def) moreoverfrom idx_correct l D have"?idx (APs!!i) = Some i"by fastforce ultimatelyshow"i ∈ (map_props ?idx ∘ promela_props) g" unfolding o_def map_props_def by blast next fix g i assume"i ∈ (map_props ?idx ∘ promela_props) g" thenobtain p where p_def: "p ∈ promela_props g""?idx p = Some i" unfolding map_props_def o_def by auto hence expr: "exprArith g emptyProc p ≠ 0"by (simp add: promela_props_def)
from D p_def have"i < IArray.length APs""APs !! i = p" using idx_correct by fastforce+ with expr have"propValid APs g i"by (simp add: propValid_def) thus"i ∈ promela_props_ltl APs g" by (simp add: promela_props_ltl_def) qed qed
from conv have D: "distinct ?APs" by (simp add: ltl_convert_correct) with conv have APs: "atoms_ltlc φ ⊆ dom (idx ?APs)" by (simp add: idx_dom ltl_convert_correct)
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.