@@ -56,7 +56,7 @@ code_datatype RSM RSMS
5656definition "r_empty_map \<equiv> Mapping.empty::('a::bot) r_state_map"
5757
5858lemma 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
6161lemma 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
7070lemma 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
7373lemma single_lookup : "lookup (single k v) k = v" by simp
7474
@@ -117,7 +117,7 @@ proof -
117117qed
118118
119119lemma 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)
483483qed
484484
485485lemma [ 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
606606qed 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+
608626subsection \<open>Helper Refinement\<close>
609627
610628fun 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
684702qed
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
688729value "
0 commit comments