(* (C) Copyright Andreas Viktor Hess, DTU, 2020 (C) Copyright Sebastian A. Mödersheim, DTU, 2020 (C) Copyright Achim D. Brucker, University of Exeter, 2020 (C) Copyright Anders Schlichtkrull, DTU, 2020 All Rights Reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *) (* Title: Term_Abstraction.thy Author: Andreas Viktor Hess, DTU Author: Sebastian A. Mödersheim, DTU Author: Achim D. Brucker, University of Exeter Author: Anders Schlichtkrull, DTU *) section\Term Abstraction\ theory Term_Abstraction imports Transactions begin subsection \Definitions\ fun to_abs ("\\<^sub>0") where "\\<^sub>0 [] _ = {}" | "\\<^sub>0 ((Fun (Val m) [],Fun (Set s) S)#D) n = (if m = n then insert s (\\<^sub>0 D n) else \\<^sub>0 D n)" | "\\<^sub>0 (_#D) n = \\<^sub>0 D n" fun abs_apply_term (infixl "\\<^sub>\" 67) where "Var x \\<^sub>\ \ = Var x" | "Fun (Val n) T \\<^sub>\ \ = Fun (Abs (\ n)) (map (\t. t \\<^sub>\ \) T)" | "Fun f T \\<^sub>\ \ = Fun f (map (\t. t \\<^sub>\ \) T)" definition abs_apply_list (infixl "\\<^sub>\\<^sub>l\<^sub>i\<^sub>s\<^sub>t" 67) where "M \\<^sub>\\<^sub>l\<^sub>i\<^sub>s\<^sub>t \ \ map (\t. t \\<^sub>\ \) M" definition abs_apply_terms (infixl "\\<^sub>\\<^sub>s\<^sub>e\<^sub>t" 67) where "M \\<^sub>\\<^sub>s\<^sub>e\<^sub>t \ \ (\t. t \\<^sub>\ \) ` M" definition abs_apply_pairs (infixl "\\<^sub>\\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s" 67) where "F \\<^sub>\\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s \ \ map (\(s,t). (s \\<^sub>\ \, t \\<^sub>\ \)) F" definition abs_apply_strand_step (infixl "\\<^sub>\\<^sub>s\<^sub>t\<^sub>p" 67) where "s \\<^sub>\\<^sub>s\<^sub>t\<^sub>p \ \ (case s of (l,send\t\) \ (l,send\t \\<^sub>\ \\) | (l,receive\t\) \ (l,receive\t \\<^sub>\ \\) | (l,\ac: t \ t'\) \ (l,\ac: (t \\<^sub>\ \) \ (t' \\<^sub>\ \)\) | (l,insert\t,t'\) \ (l,insert\t \\<^sub>\ \,t' \\<^sub>\ \\) | (l,delete\t,t'\) \ (l,delete\t \\<^sub>\ \,t' \\<^sub>\ \\) | (l,\ac: t \ t'\) \ (l,\ac: (t \\<^sub>\ \) \ (t' \\<^sub>\ \)\) | (l,\X\\\: F \\: F'\) \ (l,\X\\\: (F \\<^sub>\\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s \) \\: (F' \\<^sub>\\<^sub>p\<^sub>a\<^sub>i\<^sub>r\<^sub>s \)\))" definition abs_apply_strand (infixl "\\<^sub>\\<^sub>s\<^sub>t" 67) where "S \\<^sub>\\<^sub>s\<^sub>t \ \ map (\x. x \\<^sub>\\<^sub>s\<^sub>t\<^sub>p \) S" subsection \Lemmata\ lemma to_abs_alt_def: "\\<^sub>0 D n = {s. \S. (Fun (Val n) [], Fun (Set s) S) \ set D}" by (induct D n rule: to_abs.induct) auto lemma abs_term_apply_const[simp]: "is_Val f \ Fun f [] \\<^sub>\ a = Fun (Abs (a (the_Val f))) []" "\is_Val f \ Fun f [] \\<^sub>\ a = Fun f []" by (cases f; auto)+ lemma abs_fv: "fv (t \\<^sub>\ a) = fv t" by (induct t a rule: abs_apply_term.induct) auto lemma abs_eq_if_no_Val: assumes "\f \ funs_term t. \is_Val f" shows "t \\<^sub>\ a = t \\<^sub>\ b" using assms proof (induction t) case (Fun f T) thus ?case by (cases f) simp_all qed simp lemma abs_list_set_is_set_abs_set: "set (M \\<^sub>\\<^sub>l\<^sub>i\<^sub>s\<^sub>t \) = (set M) \\<^sub>\\<^sub>s\<^sub>e\<^sub>t \" unfolding abs_apply_list_def abs_apply_terms_def by simp lemma abs_set_empty[simp]: "{} \\<^sub>\\<^sub>s\<^sub>e\<^sub>t \ = {}" unfolding abs_apply_terms_def by simp lemma abs_in: assumes "t \ M" shows "t \\<^sub>\ \ \ M \\<^sub>\\<^sub>s\<^sub>e\<^sub>t \" using assms unfolding abs_apply_terms_def by (induct t \ rule: abs_apply_term.induct) blast+ lemma abs_set_union: "(A \ B) \\<^sub>\\<^sub>s\<^sub>e\<^sub>t a = (A \\<^sub>\\<^sub>s\<^sub>e\<^sub>t a) \ (B \\<^sub>\\<^sub>s\<^sub>e\<^sub>t a)" unfolding abs_apply_terms_def by auto lemma abs_subterms: "subterms (t \\<^sub>\ \) = subterms t \\<^sub>\\<^sub>s\<^sub>e\<^sub>t \" proof (induction t) case (Fun f T) thus ?case by (cases f) (auto simp add: abs_apply_terms_def) qed (simp add: abs_apply_terms_def) lemma abs_subterms_in: "s \ subterms t \ s \\<^sub>\ a \ subterms (t \\<^sub>\ a)" proof (induction t) case (Fun f T) thus ?case by (cases f) auto qed simp lemma abs_ik_append: "(ik\<^sub>s\<^sub>s\<^sub>t (A@B) \\<^sub>s\<^sub>e\<^sub>t I) \\<^sub>\\<^sub>s\<^sub>e\<^sub>t a = (ik\<^sub>s\<^sub>s\<^sub>t A \\<^sub>s\<^sub>e\<^sub>t I) \\<^sub>\\<^sub>s\<^sub>e\<^sub>t a \ (ik\<^sub>s\<^sub>s\<^sub>t B \\<^sub>s\<^sub>e\<^sub>t I) \\<^sub>\\<^sub>s\<^sub>e\<^sub>t a" unfolding abs_apply_terms_def ik\<^sub>s\<^sub>s\<^sub>t_def by auto lemma to_abs_in: assumes "(Fun (Val n) [], Fun (Set s) []) \ set D" shows "s \ \\<^sub>0 D n" using assms by (induct rule: to_abs.induct) auto lemma to_abs_empty_iff_notin_db: "Fun (Val n) [] \\<^sub>\ \\<^sub>0 D = Fun (Abs {}) [] \ (\s S. (Fun (Val n) [], Fun (Set s) S) \ set D)" by (simp add: to_abs_alt_def) lemma to_abs_list_insert: assumes "Fun (Val n) [] \ t" shows "\\<^sub>0 D n = \\<^sub>0 (List.insert (t,s) D) n" using assms to_abs_alt_def[of D n] to_abs_alt_def[of "List.insert (t,s) D" n] by auto lemma to_abs_list_insert': "insert s (\\<^sub>0 D n) = \\<^sub>0 (List.insert (Fun (Val n) [], Fun (Set s) S) D) n" using to_abs_alt_def[of D n] to_abs_alt_def[of "List.insert (Fun (Val n) [], Fun (Set s) S) D" n] by auto lemma to_abs_list_remove_all: assumes "Fun (Val n) [] \ t" shows "\\<^sub>0 D n = \\<^sub>0 (List.removeAll (t,s) D) n" using assms to_abs_alt_def[of D n] to_abs_alt_def[of "List.removeAll (t,s) D" n] by auto lemma to_abs_list_remove_all': "\\<^sub>0 D n - {s} = \\<^sub>0 (filter (\d. \S. d = (Fun (Val n) [], Fun (Set s) S)) D) n" using to_abs_alt_def[of D n] to_abs_alt_def[of "filter (\d. \S. d = (Fun (Val n) [], Fun (Set s) S)) D" n] by auto lemma to_abs_db\<^sub>s\<^sub>s\<^sub>t_append: assumes "\u s. insert\u, s\ \ set B \ Fun (Val n) [] \ u \ \" and "\u s. delete\u, s\ \ set B \ Fun (Val n) [] \ u \ \" shows "\\<^sub>0 (db'\<^sub>s\<^sub>s\<^sub>t A \ D) n = \\<^sub>0 (db'\<^sub>s\<^sub>s\<^sub>t (A@B) \ D) n" using assms proof (induction B rule: List.rev_induct) case (snoc b B) hence IH: "\\<^sub>0 (db'\<^sub>s\<^sub>s\<^sub>t A \ D) n = \\<^sub>0 (db'\<^sub>s\<^sub>s\<^sub>t (A@B) \ D) n" by auto have *: "\u s. b = insert\u,s\ \ Fun (Val n) [] \ u \ \" "\u s. b = delete\u,s\ \ Fun (Val n) [] \ u \ \" using snoc.prems by simp_all show ?case proof (cases b) case (Insert u s) hence **: "db'\<^sub>s\<^sub>s\<^sub>t (A@B@[b]) \ D = List.insert (u \ \,s \ \) (db'\<^sub>s\<^sub>s\<^sub>t (A@B) \ D)" using db\<^sub>s\<^sub>s\<^sub>t_append[of "A@B" "[b]"] by simp have "Fun (Val n) [] \ u \ \" using *(1) Insert by auto thus ?thesis using IH ** to_abs_list_insert by metis next case (Delete u s) hence **: "db'\<^sub>s\<^sub>s\<^sub>t (A@B@[b]) \ D = List.removeAll (u \ \,s \ \) (db'\<^sub>s\<^sub>s\<^sub>t (A@B) \ D)" using db\<^sub>s\<^sub>s\<^sub>t_append[of "A@B" "[b]"] by simp have "Fun (Val n) [] \ u \ \" using *(2) Delete by auto thus ?thesis using IH ** to_abs_list_remove_all by metis qed (simp_all add: db\<^sub>s\<^sub>s\<^sub>t_no_upd_append[of "[b]" "A@B"] IH) qed simp lemma to_abs_neq_imp_db_update: assumes "\\<^sub>0 (db\<^sub>s\<^sub>s\<^sub>t A I) n \ \\<^sub>0 (db\<^sub>s\<^sub>s\<^sub>t (A@B) I) n" shows "\u s. u \ I = Fun (Val n) [] \ (insert\u,s\ \ set B \ delete\u,s\ \ set B)" proof - { fix D have ?thesis when "\\<^sub>0 D n \ \\<^sub>0 (db'\<^sub>s\<^sub>s\<^sub>t B I D) n" using that proof (induction B I D rule: db'\<^sub>s\<^sub>s\<^sub>t.induct) case 2 thus ?case by (metis db'\<^sub>s\<^sub>s\<^sub>t.simps(2) list.set_intros(1,2) subst_apply_pair_pair to_abs_list_insert) next case 3 thus ?case by (metis db'\<^sub>s\<^sub>s\<^sub>t.simps(3) list.set_intros(1,2) subst_apply_pair_pair to_abs_list_remove_all) qed simp_all } thus ?thesis using assms by (metis db\<^sub>s\<^sub>s\<^sub>t_append db\<^sub>s\<^sub>s\<^sub>t_def) qed lemma abs_term_subst_eq: fixes \ \::"(('a,'b,'c) prot_fun, ('d,'e prot_atom) term \ nat) subst" assumes "\x \ fv t. \ x \\<^sub>\ a = \ x \\<^sub>\ b" and "\n T. Fun (Val n) T \ subterms t" shows "t \ \ \\<^sub>\ a = t \ \ \\<^sub>\ b" using assms proof (induction t) case (Fun f T) thus ?case proof (cases f) case (Val n) hence False using Fun.prems(2) by blast thus ?thesis by metis qed auto qed simp lemma abs_term_subst_eq': fixes \ \::"(('a,'b,'c) prot_fun, ('d,'e prot_atom) term \ nat) subst" assumes "\x \ fv t. \ x \\<^sub>\ a = \ x" and "\n T. Fun (Val n) T \ subterms t" shows "t \ \ \\<^sub>\ a = t \ \" using assms proof (induction t) case (Fun f T) thus ?case proof (cases f) case (Val n) hence False using Fun.prems(2) by blast thus ?thesis by metis qed auto qed simp lemma abs_val_in_funs_term: assumes "f \ funs_term t" "is_Val f" shows "Abs (\ (the_Val f)) \ funs_term (t \\<^sub>\ \)" using assms by (induct t \ rule: abs_apply_term.induct) auto end