Theory Sep_Algebra_Add
section ‹Additions to Separation Algebra Library›
theory Sep_Algebra_Add
imports "Separation_Algebra.Sep_Tactics"
begin
no_notation pred_K ("⟨_⟩")
hide_const (open) Separation_Algebra.pure
subsection ‹Simp-Lemmas for Separation Algebra›
named_theorems sep_algebra_simps ‹Advanced simplification lemmas for separation algebra›
lemmas [sep_algebra_simps] = sep_conj_exists sep_add_ac
lemmas [simp] = sep_conj_assoc
lemmas sep_conj_c = sep_conj_commute sep_conj_left_commute
lemmas sep_conj_aci = sep_conj_ac sep_conj_empty sep_conj_empty'
subsection ‹Separation Algebra with a Unique Zero›
class unique_zero_sep_algebra = stronger_sep_algebra +
assumes unique_zero: "x##x ⟹ x=0"
begin
lemma unique_zero_simps[simp]:
"a##a ⟷ a=0"
"a##b ⟹ a+b = a ⟷ b=0"
"a##b ⟹ a+b = b ⟷ a=0"
"a##b ⟹ a + b = 0 ⟷ a=0 ∧ b=0"
apply -
using local.sep_disj_zero local.unique_zero apply blast
apply (metis local.sep_add_disjD local.sep_add_zero local.unique_zero)
apply (metis local.sep_add_disjD local.sep_add_zero_sym local.sep_disj_commute local.unique_zero)
by (metis local.sep_add_disjD local.sep_add_zero local.sep_disj_zero local.unique_zero)
end
subsection ‹Standard Instantiations›
instantiation "fun" :: (type,stronger_sep_algebra) stronger_sep_algebra
begin
definition "f1 ## f2 ⟷ (∀x. f1 x ## f2 x)"
definition [simp]: "(f1 + f2) x = (f1 x + f2 x)"
definition [simp]: "0 x ≡ 0"
instance
apply standard
unfolding sep_disj_fun_def plus_fun_def zero_fun_def
apply (auto)
subgoal
by (simp add: sep_disj_commute)
subgoal
using sep_add_commute by auto
subgoal
by (simp add: sep_add_assoc)
done
end
instance "fun" :: (type,unique_zero_sep_algebra) unique_zero_sep_algebra
apply standard
unfolding sep_disj_fun_def plus_fun_def zero_fun_def
by (metis unique_zero)
lemma disj_fun_upd_iff[simp]:
"⟦f a = 0; g a = 0⟧ ⟹ (f(a:=x) ## g(a:=y)) ⟷ (f ## g ∧ x ## y)"
unfolding sep_disj_fun_def by force
lemma fun_upd_Z_Z[simp]: "fun_upd 0 i 0 = 0" by auto
lemma sep_disj_fun_updI[sep_algebra_simps, intro]: "⟦f##g; a##b⟧ ⟹ f(x:=a) ## g(x:=b)"
by (simp add: sep_disj_fun_def)
lemma sep_disj_fun_Zupd_eq[sep_algebra_simps]:
"f##0(x:=y) ⟷ f x ## y"
"0(x:=y) ## f ⟷ y ## f x"
by (auto simp add: sep_disj_fun_def)
lemma sep_disj_funD: "f##g ⟹ f x ## g x" by (auto simp: sep_disj_fun_def)
lemma merge_fun_singleton: "fun_upd 0 i a + fun_upd 0 i b = fun_upd 0 i (a+b)" by auto
lemma split_fun_upd_0: "fun_upd (a+b) i 0 = fun_upd a i 0 + fun_upd b i 0" by auto
instantiation option :: (stronger_sep_algebra) stronger_sep_algebra begin
fun sep_disj_option :: "'a option ⇒ 'a option ⇒ bool" where
"sep_disj None None ⟷ True"
| "sep_disj None (Some _) ⟷ True"
| "sep_disj (Some _) None ⟷ True"
| "sep_disj (Some x) (Some y) ⟷ x##y"
lemma sep_disj_option_add_simps[simp]:
"sep_disj None x"
"sep_disj x None"
by (cases x; simp)+
fun plus_option :: "'a option ⇒ 'a option ⇒ 'a option" where
"plus None None = None"
| "plus None (Some x) = Some x"
| "plus (Some x) None = Some x"
| "plus (Some x) (Some y) = Some (x+y)"
lemma plus_option_add_simps[simp]: "plus None x = x" "plus x None = x"
by (cases x; simp)+
definition "0 = None"
instance
apply standard
apply (simp_all add: zero_option_def)
apply (case_tac x; case_tac y; simp add: sep_disj_commute)
apply (case_tac x; case_tac y; auto simp add: sep_disj_commute sep_add_commute)
apply (case_tac x; case_tac y; case_tac z; simp add: sep_add_assoc)
apply (case_tac x; case_tac y; case_tac z; auto dest: sep_disj_addD1)
done
end
instantiation prod :: (stronger_sep_algebra, stronger_sep_algebra) stronger_sep_algebra
begin
definition "a##b ⟷ fst a ## fst b ∧ snd a ## snd b"
definition "a+b = (fst a + fst b, snd a + snd b)"
definition "0 = (0,0)"
instance
apply standard
unfolding sep_disj_prod_def plus_prod_def zero_prod_def
by (auto
simp: sep_add_ac
intro: sep_disj_commuteI sep_disj_addD1 sep_disj_addI1)
end
lemma sep_disj_prod_lower[sep_algebra_simps]: "(a,b) ## (c,d) ⟷ a##c ∧ b##d"
by (simp add: sep_disj_prod_def)
lemma plus_prod_lower[sep_algebra_simps]: "(a,b) + (c,d) = (a+c,b+d)"
by (simp add: plus_prod_def)
instance prod :: (unique_zero_sep_algebra,unique_zero_sep_algebra) unique_zero_sep_algebra
by standard (auto simp: zero_prod_def sep_algebra_simps)
lemma prod_Z_lower[sep_algebra_simps]:
"(a,b) = 0 ⟷ a=0 ∧ b=0"
"0 = (a,b) ⟷ a=0 ∧ b=0"
by (auto simp: zero_prod_def)
lemma plus_prod_eqI: "(a+b,c+d) = (a,c) + (b,d)" by (simp add: sep_algebra_simps)
lemma fst_Z[simp]: "fst 0 = 0" by (simp add: zero_prod_def)
lemma snd_Z[simp]: "snd 0 = 0" by (simp add: zero_prod_def)
lemma fst_plus[sep_algebra_simps]: "fst (a+b) = fst a + fst b" by (auto simp: plus_prod_def)
lemma snd_plus[sep_algebra_simps]: "snd (a+b) = snd a + snd b" by (auto simp: plus_prod_def)
lemma disj_fstI[sep_algebra_simps]: "a##b ⟹ fst a ## fst b" by (auto simp: sep_disj_prod_def)
lemma disj_sndI[sep_algebra_simps]: "a##b ⟹ snd a ## snd b" by (auto simp: sep_disj_prod_def)