Skip to content

Commit f683680

Browse files
committed
It works \o/
1 parent 166f1b6 commit f683680

File tree

7 files changed

+177
-103
lines changed

7 files changed

+177
-103
lines changed

Uppaal_Networks/AbsInt/AbsInt.thy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ proof -
409409
from step_le this show ?thesis by force
410410
qed
411411

412-
definition[simp, code]: "ai_loop \<equiv> finite_loop ai_step"
412+
definition[simp]: "ai_loop \<equiv> finite_loop ai_step"
413413

414414
theorem ai_loop_correct: "collect_loop prog n (\<gamma>_map entry) \<le> \<gamma>_map (ai_loop prog n entry)"
415415
proof (induction n arbitrary: entry)
@@ -423,7 +423,7 @@ next
423423
thus ?case by simp
424424
qed
425425

426-
definition[simp, code]: "ai_loop_fp \<equiv> finite_loop_fp ai_step"
426+
definition[simp]: "ai_loop_fp \<equiv> finite_loop_fp ai_step"
427427

428428
theorem ai_loop_fp_correct: "collect_loop prog m (\<gamma>_map entry) \<le> \<gamma>_map (ai_loop_fp prog n entry)"
429429
by (metis (no_types, lifting) \<gamma>_map_mono ai_loop_correct ai_loop_def ai_loop_fp_def finite_loop_fp_supercomplete le_iff_sup le_sup_iff)

Uppaal_Networks/AbsInt/AbsInt_Final.thy

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ global_interpretation Abs_Int_Final: Smart_Base
2222
and \<gamma>_stack = "\<gamma>_stack_window n \<gamma>_word"
2323
and push = "push_stack_window n"
2424
and pop = "pop_stack_window n"
25+
defines "final_step_base" = "Abs_Int_Final.step_smart_base"
26+
and "final_step" = "Abs_Int_Final.step_smart"
27+
and "final_astore_singleton" = "Abs_Int_Final.astore_singleton"
28+
and "final_astore_multi" = "Abs_Int_Final.astore_multi"
29+
and "final_astore" = "Abs_Int_Final.astore"
30+
and "final_load" = "Abs_Int_Final.load"
31+
and "final_cmp_op" = "Abs_Int_Final.cmp_op"
32+
and "final_pop2" = "Abs_Int_Final.pop2"
33+
and "final_pop2_push" = "Abs_Int_Final.pop2_push"
34+
and "final_word_of" = "Abs_Int_Final.word_of"
2535
proof(standard, goal_cases)
2636
case (1 a b) then show ?case by (simp add: Word_Strided_Interval.mono_gamma) next
2737
case (3 a x) then show ?case by (simp add: Word_Strided_Interval.contains_correct) next
@@ -37,11 +47,10 @@ proof(standard, goal_cases)
3747
case (15 cx c b) then show ?case by (simp add: Word_Strided_Interval.mono_gamma window_pop_correct(2))
3848
qed auto
3949

40-
definition[simp, code]: "final_loop_fp \<equiv> finite_loop_fp Abs_Int_Final.step_smart"
41-
theorem ai_loop_fp_correct: "collect_loop prog m (Abs_Int_Final.Smart.\<gamma>_map entry) \<le> Abs_Int_Final.Smart.\<gamma>_map (final_loop_fp prog n entry)" using Abs_Int_Final.Smart.ai_loop_fp_correct by simp
50+
definition[simp]: "final_loop_fp \<equiv> finite_loop_fp final_step"
51+
theorem ai_loop_fp_correct: "collect_loop prog m (Abs_Int_Final.Smart.\<gamma>_map entry) \<le> Abs_Int_Final.Smart.\<gamma>_map (final_loop_fp prog n entry)"
52+
using Abs_Int_Final.Smart.ai_loop_fp_correct by simp
4253

43-
lemma[code]: "HOL.equal (SM a) (SM b) = False" sorry
44-
45-
export_code final_loop_fp in SML
54+
export_code final_loop_fp in SML module_name AbsInt_Final
4655

4756
end

Uppaal_Networks/AbsInt/AbsInt_Refine.thy

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ code_datatype RSM RSMS
5656
definition "r_empty_map \<equiv> Mapping.empty::('a::bot) r_state_map"
5757

5858
lemma r_bot[code]: "\<bottom> = RSM r_empty_map"
59-
by (rule lookup_eq; simp add: lookup_default_empty r_empty_map_def)
59+
by (rule state_map_eq_fwd; simp add: lookup_default_empty r_empty_map_def)
6060

6161
lemma r_top[code]: "\<top> = RSMS SMTop" by simp
6262

@@ -68,7 +68,7 @@ fun r_single :: "addr \<Rightarrow> 'a::absstate \<Rightarrow> 'a r_state_map" w
6868
"r_single k v = Mapping.update k v \<bottom>"
6969

7070
lemma r_single[code]: "single k v = RSM (r_single k v)"
71-
by (rule lookup_eq; simp add: bot_mapping_def lookup_default_empty lookup_default_update')
71+
by (rule state_map_eq_fwd; simp add: bot_mapping_def lookup_default_empty lookup_default_update')
7272

7373
lemma single_lookup: "lookup (single k v) k = v" by simp
7474

@@ -117,7 +117,7 @@ proof -
117117
qed
118118

119119
lemma r_merge_single[code]: "merge_single (RSM m) pc x = RSM (r_merge_single m pc x)"
120-
proof(rule lookup_eq)
120+
proof(rule state_map_eq_fwd)
121121
obtain mm where func: "RSM m = SM mm" using state_map_single_constructor by blast
122122
have "(if k = pc then x \<squnion> mm k else mm k) = lookup (RSM (r_merge_single m pc x)) k" for k
123123
proof(cases "k = pc")
@@ -462,7 +462,7 @@ proof (rule ccontr)
462462
from this obtain infpc where infpc: "infinite (slurp f prog ctx infpc)" by blast
463463
let ?slurpset = "{ost. \<exists>ipc op. prog ipc = Some op \<and> lookup ctx ipc \<noteq> \<bottom> \<and> lookup (f op ipc (lookup ctx ipc)) infpc = ost}"
464464
let ?aset = "{ipc. lookup ctx ipc \<noteq> \<bottom>}"
465-
from assms(1) have finite_lookup: "finite ?aset" by (metis (full_types) domain.simps lookup.simps lookup_eq)
465+
from assms(1) have finite_lookup: "finite ?aset" by (metis (full_types) domain.simps lookup.simps state_map_eq_fwd)
466466
let ?magic = "\<lambda>ipc. case prog ipc of None \<Rightarrow> None | Some op \<Rightarrow> Some (lookup (f op ipc (lookup ctx ipc)) infpc)"
467467
let ?youbet = "List.map_project ?magic ?aset"
468468
from finite_lookup have finite: "finite ?youbet" using map_project_finite by blast
@@ -483,7 +483,7 @@ proof (rule ccontr)
483483
qed
484484

485485
lemma[code]: "finite_step_map (f::('a::absstate) astep) prog (RSM (Mapping tree)) = r_step_map f prog (RSM (Mapping tree))"
486-
proof(rule lookup_eq)
486+
proof(rule state_map_eq_fwd)
487487
fix pc
488488
let ?ctx = "RSM (Mapping tree)"
489489
let ?smf = "r_step_map_from f prog ?ctx"
@@ -605,6 +605,24 @@ proof (cases "finite_advance f prog st = \<top>")
605605
qed simp
606606
qed simp
607607

608+
text\<open>Equality over state sets, necessary for ai_loop_fp\<close>
609+
610+
lemma state_map_HOL_equal: "HOL.equal a b \<longleftrightarrow> (\<forall>k. lookup a k = lookup b k)"
611+
proof -
612+
have "HOL.equal a b \<longleftrightarrow> a = b" by (rule HOL.equal_eq)
613+
thus ?thesis using state_map_eq by blast
614+
qed
615+
616+
lemma[code]: "HOL.equal (RSM a) (RSM b) \<longleftrightarrow> (\<forall>k \<in> (r_domain a \<union> r_domain b). r_lookup a k = r_lookup b k)"
617+
proof -
618+
have "(\<forall>k. lookup (RSM a) k = lookup (RSM b) k) \<longleftrightarrow> (\<forall>k \<in> (r_domain a \<union> r_domain b). r_lookup a k = r_lookup b k)"
619+
by (metis (mono_tags, lifting) UnI1 UnI2 mem_Collect_eq r_domain r_lookup)
620+
moreover have "equal_class.equal (RSM a) (RSM b) = (\<forall>k. lookup (RSM a) k = lookup (RSM b) k)" by (rule state_map_HOL_equal)
621+
ultimately show ?thesis by simp
622+
qed
623+
624+
lemma[code]: "HOL.equal SMTop SMTop = True" by (rule HOL.equal_class.equal_refl)
625+
608626
subsection \<open>Helper Refinement\<close>
609627

610628
fun r_deep_merge_l :: "(addr * ('a::absstate)) list \<Rightarrow> 'a r_state_map \<Rightarrow> 'a r_state_map" where
@@ -683,6 +701,29 @@ proof -
683701
thus ?thesis by simp
684702
qed
685703

704+
fun list_is_singleton :: "'a list \<Rightarrow> bool" where
705+
"list_is_singleton [] = False" |
706+
"list_is_singleton [_] = True" |
707+
"list_is_singleton (x # y # r) = (x = y \<and> list_is_singleton (y # r))"
708+
709+
lemma[code]: "is_singleton (set a) = list_is_singleton a"
710+
proof (induction a)
711+
case Nil
712+
then show ?case
713+
by (simp add: is_singleton_def)
714+
next
715+
case (Cons x yr)
716+
then show ?case
717+
proof (cases yr)
718+
case Nil
719+
then show ?thesis by simp
720+
next
721+
fix y r assume "yr = y # r"
722+
then show ?thesis
723+
by (metis empty_iff insert_absorb2 insert_iff is_singleton_the_elem list.simps(15) list_is_singleton.simps(3) local.Cons)
724+
qed
725+
qed
726+
686727
(***********)
687728

688729
value "

Uppaal_Networks/AbsInt/AbsInt_Test.thy

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
theory AbsInt_Test
22
imports
33
"HOL.String"
4-
AbsInt_Refine
54
Uppaal_Networks.UPPAAL_Asm_Show
6-
Word_StridedInterval
7-
Stack_Direct
8-
State_Smart
5+
AbsInt_Final
96
begin
107

118
instantiation toption :: ("show") "show"
@@ -84,11 +81,11 @@ definition "dumb_result \<equiv>
8481
definition "abs_res_str \<equiv> String.implode (show (DisplayCtx myprog dumb_result))"
8582
(*ML \<open>val _ = writeln (@{code abs_res_str})\<close>*)
8683

87-
type_synonym si_state = "(strided_interval toption option, strided_interval toption option stack_direct) smart state_map"
84+
type_synonym si_state = "(strided_interval toption option, strided_interval toption option stack_window) smart state_map"
8885

8986
definition "set_entry \<equiv> (merge_single \<bottom> 0 (Some (Smart \<bottom> \<bottom> BFalse)))::si_state"
90-
definition "set_result \<equiv> undefined (fetch_op myprog) 3 set_entry"
91-
definition "set_res_str \<equiv> String.implode (show (DisplayCtx myprog set_entry))"
87+
definition "set_result \<equiv> final_loop_fp (fetch_op myprog) 100 set_entry"
88+
definition "set_res_str \<equiv> String.implode (show (DisplayCtx myprog set_result))"
9289
ML \<open>val _ = writeln (@{code set_res_str})\<close>
9390

9491

Uppaal_Networks/AbsInt/Stack.thy

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -14,44 +14,5 @@ locale Abs_Stack =
1414
and push_correct: "c \<in> \<gamma>_stack b \<Longrightarrow> cx \<in> \<gamma>_word x \<Longrightarrow> (cx # c) \<in> \<gamma>_stack (push b x)"
1515
and pop_stack_correct: "(cx # c) \<in> \<gamma>_stack b \<Longrightarrow> c \<in> \<gamma>_stack (snd (pop b))"
1616
and pop_return_correct: "(cx # c) \<in> \<gamma>_stack b \<Longrightarrow> cx \<in> \<gamma>_word (fst (pop b))"
17-
begin
18-
19-
fun pop2 :: "'b \<Rightarrow> ('a * 'a * 'b)" where
20-
"pop2 stack =
21-
(let (a, astack) = pop stack;
22-
(b, bstack) = pop astack
23-
in (a, b, bstack))"
24-
lemma pop2_stack_correct: "(ca # cb # c) \<in> \<gamma>_stack b \<Longrightarrow> c \<in> \<gamma>_stack (snd (snd (pop2 b)))"
25-
by (metis (no_types, lifting) Pair_inject case_prod_beta' pop2.elims pop_stack_correct prod.exhaust_sel)
26-
27-
lemma pop2_return_b_correct: "(ca # cb # c) \<in> \<gamma>_stack b \<Longrightarrow> cb \<in> \<gamma>_word (fst (snd (pop2 b)))"
28-
proof -
29-
assume ass: "(ca # cb # c) \<in> \<gamma>_stack b"
30-
hence i: "(cb # c) \<in> \<gamma>_stack (snd (pop b))" using pop_stack_correct by simp
31-
have "snd (pop2 b) = pop (snd (pop b))"
32-
by (metis (no_types, lifting) case_prod_beta' pop2.elims prod.exhaust_sel snd_conv)
33-
from this i show "cb \<in> \<gamma>_word (fst (snd (pop2 b)))" using pop_return_correct by auto
34-
qed
35-
36-
lemma pop2_return_a_correct: "(ca # cb # c) \<in> \<gamma>_stack b \<Longrightarrow> ca \<in> \<gamma>_word (fst (pop2 b))"
37-
by (metis (no_types, lifting) case_prod_beta' fst_conv pop2.elims pop_return_correct)
38-
39-
fun pop2_push :: "('a \<Rightarrow> 'a \<Rightarrow> 'a) \<Rightarrow> 'b \<Rightarrow> 'b" where
40-
"pop2_push f stack =
41-
(let (a, b, rstack) = pop2 stack
42-
in push rstack (f a b))"
43-
44-
lemma[simp]: "pop2_push f stack =
45-
push (snd (snd (pop2 stack))) (f (fst (pop2 stack)) (fst (snd (pop2 stack))))"
46-
by (simp add: case_prod_beta)
47-
48-
lemma pop2_push:
49-
assumes
50-
"\<And>x y a b. x \<in> \<gamma>_word a \<Longrightarrow> y \<in> \<gamma>_word b \<Longrightarrow> (cop x y) \<in> \<gamma>_word (f a b)"
51-
"a # b # rcstack \<in> \<gamma>_stack iastack"
52-
shows "(cop a b) # rcstack \<in> \<gamma>_stack (pop2_push f iastack)"
53-
apply (simp add: case_prod_beta Let_def)
54-
using assms by (meson pop_return_correct pop_stack_correct push_correct)
55-
end
5617

5718
end

0 commit comments

Comments
 (0)