Skip to content

Commit b790cde

Browse files
committed
Added state counting in HOL and fixed issue with free type variables
1 parent 177d202 commit b790cde

10 files changed

+526
-369
lines changed

ML/Checker.sml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,10 +300,15 @@ fun check_and_verify2 p m ignore_k max_steps inv trans prog query bounds pred s
300300
val _ = map (uncurry print_precondition_check) tests;
301301
in println "" end else ();
302302
val t = Time.now ()
303-
val result = Model_Checker.precond_mc Type Type Type p m k max_steps inv trans prog query bounds pred s na ()
303+
val result = Model_Checker.precond_mc p m k max_steps inv trans prog query bounds pred s na ()
304304
val t = Time.- (Time.now (), t)
305305
val _ = println("Internal time for precondition check + actual checking: " ^ Time.toString t)
306306
val _ = println("")
307+
val _ = if !debug_level >= 1 then
308+
let
309+
val _ = println("# explored states: " ^ Int.toString(Tracing.get_count ()))
310+
val _ = println("")
311+
in () end else ();
307312
(*val _ = if !debug_level >= 1 then
308313
let
309314
val _ = println("# additions on DBM entries:" ^ Int.toString (!cnt))

ML/UPPAAL_Model_Checker.sml

Lines changed: 331 additions & 307 deletions
Large diffs are not rendered by default.

ML/munta.mlb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ local
88
UPPAAL_Model_Checker_patched.sml
99
end
1010
in
11+
structure Tracing
1112
structure Model_Checker
1213
end
1314

Normalized_Zone_Semantics_Impl_Refine.thy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ begin
808808

809809
lemma liveness_hnr:
810810
"(uncurry0
811-
(dfs_map_impl' TYPE('bb) TYPE('cc) TYPE('dd) (succs_P_impl' F_fun) a\<^sub>0_impl subsumes_impl
811+
(dfs_map_impl' (succs_P_impl' F_fun) a\<^sub>0_impl subsumes_impl
812812
(return \<circ> fst) state_copy_impl),
813813
uncurry0 (SPEC (\<lambda>r. r = (\<exists>x. op.liveness_pre.reaches a\<^sub>0 x \<and> op.liveness_pre.reaches1 x x))))
814814
\<in> unit_assn\<^sup>k \<rightarrow>\<^sub>a bool_assn"
@@ -1057,7 +1057,7 @@ lemma op_liveness_reaches_cycle_equiv:
10571057
lemma Alw_ev_impl_hnr:
10581058
"(uncurry0
10591059
(if F l\<^sub>0 then
1060-
dfs_map_impl' TYPE('bb) TYPE('cc) TYPE('dd)
1060+
dfs_map_impl'
10611061
(succs_P_impl' F_fun) a\<^sub>0_impl subsumes_impl (return \<circ> fst) state_copy_impl
10621062
else return False),
10631063
uncurry0 (SPEC (\<lambda>r. l\<^sub>0 \<in> state_set (trans_of A) \<longrightarrow>
@@ -1126,7 +1126,7 @@ proof -
11261126

11271127
lemma leadsto_impl_hnr:
11281128
"(uncurry0
1129-
(leadsto_impl TYPE('bb) TYPE('cc) TYPE('dd) state_copy_impl
1129+
(leadsto_impl state_copy_impl
11301130
(succs_P_impl' Q_fun) a\<^sub>0_impl subsumes_impl (return \<circ> fst)
11311131
succs_impl' emptiness_check_impl F_impl (Q_impl Q_fun)),
11321132
uncurry0

UPPAAL_Model_Checking.thy

Lines changed: 68 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ proof -
393393
(* XXX *)
394394
lemma leadsto_impl_hnr':
395395
"(uncurry0
396-
(leadsto_impl TYPE('bb) TYPE('cc) TYPE('dd) state_copy_impl
396+
(leadsto_impl state_copy_impl
397397
(succs_P_impl' Q_fun) a\<^sub>0_impl subsumes_impl (return \<circ> fst)
398398
succs_impl' emptiness_check_impl F_impl (Q_impl Q_fun)),
399399
uncurry0
@@ -477,13 +477,13 @@ lemma F_reachable_correct_new':
477477
using prod_conv p_p p_gt_0 by simp+
478478

479479
definition
480-
"Alw_ev_checker = dfs_map_impl' TYPE('bb) TYPE('cc) TYPE('dd)
480+
"Alw_ev_checker = dfs_map_impl'
481481
(impl.succs_P_impl' final_fun) impl.a\<^sub>0_impl impl.subsumes_impl (return \<circ> fst)
482482
impl.state_copy_impl"
483483

484484
definition
485485
"leadsto_checker \<psi> = do {
486-
r \<leftarrow> leadsto_impl TYPE('bb) TYPE('cc) TYPE('dd)
486+
r \<leftarrow> leadsto_impl
487487
impl.state_copy_impl (impl.succs_P_impl' (\<lambda> (L, s). \<not> check_bexp \<psi> L s))
488488
impl.a\<^sub>0_impl impl.subsumes_impl (return \<circ> fst)
489489
impl.succs_impl' impl.emptiness_check_impl impl.F_impl
@@ -501,15 +501,15 @@ definition
501501
} |
502502
formula.AX _ \<Rightarrow> do {
503503
r \<leftarrow> if PR_CONST (\<lambda>(x, y). F x y) (init, s\<^sub>0)
504-
then Alw_ev_checker TYPE('bb) TYPE('cc) TYPE('dd)
504+
then Alw_ev_checker
505505
else return False;
506506
return (\<not> r)
507507
} |
508508
formula.EG _ \<Rightarrow>
509509
if PR_CONST (\<lambda>(x, y). F x y) (init, s\<^sub>0)
510-
then Alw_ev_checker TYPE('bb) TYPE('cc) TYPE('dd)
510+
then Alw_ev_checker
511511
else return False |
512-
formula.Leadsto _ \<psi> \<Rightarrow> leadsto_checker TYPE('bb) TYPE('cc) TYPE('dd) \<psi>
512+
formula.Leadsto _ \<psi> \<Rightarrow> leadsto_checker \<psi>
513513
)
514514
"
515515

@@ -673,7 +673,7 @@ lemma deadlock_start_iff:
673673
by - (rule deadlock_iff[of _ "(init, s\<^sub>0, u\<^sub>0)", symmetric]; simp)
674674

675675
theorem model_check':
676-
"(uncurry0 (model_checker TYPE('bb) TYPE('cc) TYPE('dd)),
676+
"(uncurry0 model_checker,
677677
uncurry0 (
678678
SPEC (\<lambda> r.
679679
\<not> Graph_Defs.deadlock
@@ -797,7 +797,7 @@ proof -
797797

798798
-- \<open>\<open>EG\<close>\<close>
799799
subgoal premises prems for \<phi>
800-
using impl.Alw_ev_impl_hnr[where 'bb = 'bb and 'cc = 'cc and 'dd = 'dd,
800+
using impl.Alw_ev_impl_hnr[
801801
to_hnr, unfolded hn_refine_def
802802
]
803803
unfolding final_fun_def F_def prems(2)
@@ -824,9 +824,7 @@ proof -
824824

825825
-- \<open>\<open>AX\<close>\<close>
826826
subgoal premises prems for \<phi>
827-
using impl.Alw_ev_impl_hnr[where 'bb = 'bb and 'cc = 'cc and 'dd = 'dd,
828-
to_hnr, unfolded hn_refine_def
829-
]
827+
using impl.Alw_ev_impl_hnr[to_hnr, unfolded hn_refine_def]
830828
unfolding final_fun_def F_def
831829
unfolding UPPAAL_Reachability_Problem_precompiled_defs.F_def
832830
apply (subst
@@ -874,30 +872,30 @@ qed
874872

875873
theorem model_check'_hoare:
876874
"<emp>
877-
model_checker TYPE('bb) TYPE('cc) TYPE('dd)
875+
model_checker
878876
<\<lambda>r. \<up> ((\<not> Bisim_A.B.deadlock (init, s\<^sub>0, \<lambda>_. 0)) \<longrightarrow> r = (
879877
conv N,(init, s\<^sub>0, u\<^sub>0) \<Turnstile>\<^sub>max_steps formula
880878
))>\<^sub>t"
881-
using model_check'[to_hnr, unfolded hn_refine_def, where 'bb = 'bb and 'cc = 'cc and 'dd = 'dd]
879+
using model_check'[to_hnr, unfolded hn_refine_def]
882880
by (sep_auto simp: pure_def elim!: cons_post_rule)
883881

884882
lemma Alw_ev_checker_alt_def':
885-
"Alw_ev_checker TYPE('bb) TYPE('cc) TYPE('dd) \<equiv>
883+
"Alw_ev_checker \<equiv>
886884
do {
887885
x \<leftarrow> let
888886
key = return \<circ> fst;
889887
sub = impl.subsumes_impl;
890888
copy = impl.state_copy_impl;
891889
start = impl.a\<^sub>0_impl;
892890
succs = impl.succs_P_impl' final_fun
893-
in dfs_map_impl' TYPE('bb) TYPE('cc) TYPE('dd) succs start sub key copy;
891+
in dfs_map_impl' succs start sub key copy;
894892
_ \<leftarrow> return ();
895893
return x
896894
}"
897895
unfolding Alw_ev_checker_def by simp
898896

899897
lemma leadsto_checker_alt_def':
900-
"leadsto_checker TYPE('bb) TYPE('cc) TYPE('dd) \<psi> \<equiv>
898+
"leadsto_checker \<psi> \<equiv>
901899
do {
902900
r \<leftarrow> let
903901
key = return \<circ> fst;
@@ -910,8 +908,7 @@ lemma leadsto_checker_alt_def':
910908
succs' = impl.succs_impl';
911909
empty = impl.emptiness_check_impl
912910
in
913-
leadsto_impl TYPE('bb) TYPE('cc) TYPE('dd)
914-
copy succs start sub key succs' empty final final';
911+
leadsto_impl copy succs start sub key succs' empty final final';
915912
return (\<not> r)
916913
}"
917914
unfolding leadsto_checker_def by simp
@@ -982,7 +979,7 @@ schematic_goal reachability_checker'_alt_def:
982979
by (rule Pure.reflexive)
983980

984981
schematic_goal Alw_ev_checker_alt_def:
985-
"Alw_ev_checker TYPE('bb) TYPE('cc) TYPE('dd) \<equiv> ?impl"
982+
"Alw_ev_checker \<equiv> ?impl"
986983
unfolding Alw_ev_checker_alt_def' final_fun_def
987984
impl.succs_P_impl_def[OF final_fun_final] impl.succs_P_impl'_def[OF final_fun_final]
988985
unfolding impl.E_op''_impl_def impl.abstr_repair_impl_def impl.abstra_repair_impl_def
@@ -1002,7 +999,7 @@ schematic_goal Alw_ev_checker_alt_def:
1002999
by (rule Pure.reflexive)
10031000

10041001
schematic_goal leadsto_checker_alt_def:
1005-
"leadsto_checker TYPE('bb) TYPE('cc) TYPE('dd) \<equiv> ?impl"
1002+
"leadsto_checker \<equiv> ?impl"
10061003
unfolding leadsto_checker_alt_def'
10071004
unfolding impl.F_impl_def impl.Q_impl_def[OF final_fun_final]
10081005
unfolding impl.succs_P_impl'_def[OF final_fun_final]
@@ -1051,7 +1048,7 @@ schematic_goal reachability_checker'_alt_def_refined:
10511048
by (rule Pure.reflexive)
10521049

10531050
schematic_goal Alw_ev_checker_alt_def_refined:
1054-
"Alw_ev_checker TYPE('bb) TYPE('cc) TYPE('dd) \<equiv> ?impl"
1051+
"Alw_ev_checker \<equiv> ?impl"
10551052
unfolding Alw_ev_checker_alt_def
10561053
unfolding fw_impl'_int
10571054
unfolding inv_fun_def trans_fun_def trans_s_fun_def trans_i_fun_def
@@ -1079,7 +1076,7 @@ schematic_goal Alw_ev_checker_alt_def_refined:
10791076
by (rule Pure.reflexive)
10801077

10811078
schematic_goal leadsto_checker_alt_def_refined:
1082-
"leadsto_checker TYPE('bb) TYPE('cc) TYPE('dd) \<equiv> ?impl"
1079+
"leadsto_checker \<equiv> ?impl"
10831080
unfolding leadsto_checker_alt_def
10841081
unfolding fw_impl'_int
10851082
unfolding inv_fun_def trans_fun_def trans_s_fun_def trans_i_fun_def
@@ -1135,12 +1132,58 @@ definition [code]:
11351132
"precond_mc p m k max_steps I T prog final bounds P s\<^sub>0 na \<equiv>
11361133
if UPPAAL_Reachability_Problem_precompiled' p m max_steps I T prog bounds P s\<^sub>0 na k
11371134
then
1138-
model_checker TYPE('bb) TYPE('cc) TYPE('dd) p m max_steps I T prog bounds P s\<^sub>0 na k final
1135+
model_checker p m max_steps I T prog bounds P s\<^sub>0 na k final
11391136
\<bind> (\<lambda> x. return (Some x))
11401137
else return None"
11411138

11421139
theorem model_check:
1143-
"<emp> precond_mc TYPE('bb) TYPE('cc) TYPE('dd) p m k max_steps I T prog formula bounds P s\<^sub>0 na
1140+
"<emp> precond_mc p m k max_steps I T prog formula bounds P s\<^sub>0 na
1141+
<\<lambda> Some r \<Rightarrow> \<up>(
1142+
UPPAAL_Reachability_Problem_precompiled' p m max_steps I T prog bounds P s\<^sub>0 na k \<and>
1143+
(\<not> Graph_Defs.deadlock
1144+
(\<lambda> (L, s, u) (L', s', u').
1145+
conv (N p I P T prog bounds) \<turnstile>\<^sup>max_steps \<langle>L, s, u\<rangle> \<rightarrow> \<langle>L', s', u'\<rangle>
1146+
)
1147+
(repeat 0 p, s\<^sub>0, \<lambda>_ . 0) \<longrightarrow>
1148+
r = conv (N p I P T prog bounds),(repeat 0 p, s\<^sub>0, \<lambda>_ . 0) \<Turnstile>\<^sub>max_steps formula
1149+
))
1150+
| None \<Rightarrow> \<up>(\<not> UPPAAL_Reachability_Problem_precompiled' p m max_steps I T prog bounds P s\<^sub>0 na k)
1151+
>\<^sub>t"
1152+
proof -
1153+
define A where "A \<equiv> conv (N p I P T prog bounds)"
1154+
define no_deadlock where
1155+
"no_deadlock \<equiv> (\<forall>u\<^sub>0. (\<forall>c\<in>{1..m}. u\<^sub>0 c = 0) \<longrightarrow> \<not> Graph_Defs.deadlock
1156+
(\<lambda>(l, u) (l', u').
1157+
(case Prod_TA_Defs.prod_ta
1158+
(Equiv_TA_Defs.state_ta
1159+
(N p I P T prog bounds) max_steps) of
1160+
(T, I) \<Rightarrow>
1161+
((\<lambda>(l, g, a, r, l').
1162+
(l, map conv_ac g, a, r, l')) `
1163+
T,
1164+
map conv_ac \<circ> I)) \<turnstile>' \<langle>l, u\<rangle> \<rightarrow> \<langle>l', u'\<rangle>)
1165+
((repeat 0 p,
1166+
s\<^sub>0),
1167+
u\<^sub>0))"
1168+
define check where
1169+
"check \<equiv>
1170+
A,(repeat 0 p, s\<^sub>0, \<lambda>_ . 0) \<Turnstile>\<^sub>max_steps formula"
1171+
note [sep_heap_rules] =
1172+
UPPAAL_Reachability_Problem_precompiled'.model_check'_hoare[
1173+
of p m max_steps I T prog bounds P s\<^sub>0 na k formula,
1174+
unfolded UPPAAL_Reachability_Problem_precompiled_defs.init_def,
1175+
folded A_def check_def no_deadlock_def
1176+
]
1177+
have *: "(no_deadlock \<longrightarrow> r = Some check) \<longleftrightarrow> (if no_deadlock then r = Some check else True)" for r
1178+
by auto
1179+
show ?thesis
1180+
unfolding UPPAAL_Reachability_Problem_precompiled_defs.init_def
1181+
unfolding A_def[symmetric] check_def[symmetric] no_deadlock_def[symmetric]
1182+
unfolding precond_mc_def * by (sep_auto simp: model_checker.refine[symmetric])
1183+
qed
1184+
1185+
theorem model_check_alt:
1186+
"<emp> precond_mc p m k max_steps I T prog formula bounds P s\<^sub>0 na
11441187
<\<lambda> r. \<up> (
11451188
if UPPAAL_Reachability_Problem_precompiled' p m max_steps I T prog bounds P s\<^sub>0 na k
11461189
then r \<noteq> None \<and>
@@ -1177,8 +1220,7 @@ proof -
11771220
UPPAAL_Reachability_Problem_precompiled'.model_check'_hoare[
11781221
of p m max_steps I T prog bounds P s\<^sub>0 na k formula,
11791222
unfolded UPPAAL_Reachability_Problem_precompiled_defs.init_def,
1180-
folded A_def check_def no_deadlock_def,
1181-
where 'bb = 'bb and 'cc = 'cc and 'dd = 'dd
1223+
folded A_def check_def no_deadlock_def
11821224
]
11831225
have *: "(no_deadlock \<longrightarrow> r = Some check) \<longleftrightarrow> (if no_deadlock then r = Some check else True)" for r
11841226
by auto

Worklist_Algorithms/Leadsto_Impl.thy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ begin
1919
sepref_thm pw_algo_map2_impl is
2020
"uncurry0 (pw_algo_map2)" ::
2121
"unit_assn\<^sup>k \<rightarrow>\<^sub>a bool_assn \<times>\<^sub>a (hm.hms_assn' id_assn (lso_assn A))"
22-
unfolding pw_algo_map2_def add_pw'_map2_alt_def PR_CONST_def
22+
unfolding pw_algo_map2_def add_pw'_map2_alt_def PR_CONST_def TRACE'_def[symmetric]
2323
supply [[goals_limit = 1]]
2424
supply conv_to_is_Nil[simp]
2525
unfolding fold_lso_bex
@@ -98,7 +98,7 @@ concrete_definition (in -) leadsto_impl
9898

9999
lemma leadsto_impl_hnr:
100100
"(uncurry0 (
101-
leadsto_impl TYPE('bb) TYPE('cc) TYPE('dd) copyi succsi a\<^sub>0i Lei keyi succs1i emptyi Pi Qi
101+
leadsto_impl copyi succsi a\<^sub>0i Lei keyi succs1i emptyi Pi Qi
102102
),
103103
uncurry0 leadsto_spec_alt
104104
) \<in> unit_assn\<^sup>k \<rightarrow>\<^sub>a bool_assn" if "V a\<^sub>0"

0 commit comments

Comments
 (0)