(* Title: Singleton.thy Author: Diego Marmsoler *) section "A Theory of Singletons" text\ In the following, we formalize the specification of the singleton pattern as described in~\cite{Marmsoler2018c}. \ theory Singleton imports DynamicArchitectures.Dynamic_Architecture_Calculus begin subsection Singletons text \ In the following we formalize a variant of the Singleton pattern. \ locale singleton = dynamic_component cmp active for active :: "'id \ cnf \ bool" ("\_\\<^bsub>_\<^esub>" [0,110]60) and cmp :: "'id \ cnf \ 'cmp" ("\\<^bsub>_\<^esub>(_)" [0,110]60) + assumes alwaysActive: "\k. \id. \id\\<^bsub>k\<^esub>" and unique: "\id. \k. \id'. (\id'\\<^bsub>k\<^esub> \ id = id')" begin subsubsection "Calculus Interpretation" text \ \noindent @{thm[source] baIA}: @{thm baIA [no_vars]} \ text \ \noindent @{thm[source] baIN1}: @{thm baIN1 [no_vars]} \ text \ \noindent @{thm[source] baIN2}: @{thm baIN2 [no_vars]} \ subsubsection "Architectural Guarantees" definition "the_singleton \ THE id. \k. \id'. \id'\\<^bsub>k\<^esub> \ id' = id" theorem ts_prop: fixes k::cnf shows "\id. \id\\<^bsub>k\<^esub> \ id = the_singleton" and "\the_singleton\\<^bsub>k\<^esub>" proof - { fix id assume a1: "\id\\<^bsub>k\<^esub>" have "(THE id. \k. \id'. \id'\\<^bsub>k\<^esub> \ id' = id) = id" proof (rule the_equality) show "\k id'. \id'\\<^bsub>k\<^esub> \ id' = id" proof fix k show "\id'. \id'\\<^bsub>k\<^esub> \ id' = id" proof fix id' show "\id'\\<^bsub>k\<^esub> \ id' = id" proof assume "\id'\\<^bsub>k\<^esub>" from unique have "\id. \k. \id'. (\id'\\<^bsub>k\<^esub> \ id = id')" . then obtain i'' where "\k. \id'. (\id'\\<^bsub>k\<^esub> \ i'' = id')" by auto with \\id'\\<^bsub>k\<^esub>\ have "id=i''" and "id'=i''" using a1 by auto thus "id' = id" by simp qed qed qed next fix i'' show "\k id'. \id'\\<^bsub>k\<^esub> \ id' = i'' \ i'' = id" using a1 by auto qed hence "\id\\<^bsub>k\<^esub> \ id = the_singleton" by (simp add: the_singleton_def) } note g1 = this thus "\id. \id\\<^bsub>k\<^esub> \ id = the_singleton" by simp from alwaysActive obtain id where "\id\\<^bsub>k\<^esub>" by blast with g1 have "id = the_singleton" by simp with \\id\\<^bsub>k\<^esub>\ show "\the_singleton\\<^bsub>k\<^esub>" by simp qed declare ts_prop(2)[simp] lemma lNact_active[simp]: fixes cid t n shows "\the_singleton \ t\\<^bsub>n\<^esub> = n" using lNact_active ts_prop(2) by auto lemma lNxt_active[simp]: fixes cid t n shows "\the_singleton \ t\\<^bsub>n\<^esub> = n" by (simp add: nxtAct_active) lemma baI[intro]: fixes t n a assumes "\ (\\<^bsub>the_singleton\<^esub>(t n))" shows "eval the_singleton t t' n [\]\<^sub>b" using assms by (simp add: baIANow) lemma baE[elim]: fixes t n a assumes "eval the_singleton t t' n [\]\<^sub>b" shows "\ (\\<^bsub>the_singleton\<^esub>(t n))" using assms by (simp add: baEANow) lemma evtE[elim]: fixes t id n a assumes "eval the_singleton t t' n (\\<^sub>b \)" shows "\n'\n. eval the_singleton t t' n' \" proof - have "\the_singleton\\<^bsub>t n\<^esub>" by simp with assms obtain n' where "n'\\the_singleton \ t\\<^bsub>n\<^esub>" and "(\i\n'. \the_singleton\\<^bsub>t i\<^esub> \ (\n''\\the_singleton \ t\\<^bsub>n'\<^esub>. n'' \ \the_singleton \ t\\<^bsub>n'\<^esub> \ eval the_singleton t t' n'' \)) \ \ (\i\n'. \the_singleton\\<^bsub>t i\<^esub>) \ eval the_singleton t t' n' \" using evtEA[of n "the_singleton" t] by blast moreover have "\the_singleton\\<^bsub>t n'\<^esub>" by simp ultimately have "\n''\\the_singleton \ t\\<^bsub>n'\<^esub>. n'' \ \the_singleton \ t\\<^bsub>n'\<^esub> \ eval the_singleton t t' n'' \" by auto hence "eval the_singleton t t' n' \" by simp moreover from \n'\\the_singleton \ t\\<^bsub>n\<^esub>\ have "n'\n" by (simp add: nxtAct_active) ultimately show ?thesis by auto qed lemma globE[elim]: fixes t id n a assumes "eval the_singleton t t' n (\\<^sub>b \)" shows "\n'\n. eval the_singleton t t' n' \" proof fix n' show "n \ n' \ eval the_singleton t t' n' \" proof assume "n\n'" hence "\the_singleton \ t\\<^bsub>n\<^esub> \ n'" by simp moreover have "\the_singleton\\<^bsub>t n\<^esub>" by simp ultimately show "eval the_singleton t t' n' \" using \eval the_singleton t t' n (\\<^sub>b \)\ globEA by blast qed qed lemma untilI[intro]: fixes t::"nat \ cnf" and t'::"nat \ 'cmp" and n::nat and n'::nat assumes "n'\n" and "eval the_singleton t t' n' \" and "\n''. \n\n''; n'' \ eval the_singleton t t' n'' \'" shows "eval the_singleton t t' n (\' \\<^sub>b \)" proof - have "\the_singleton\\<^bsub>t n\<^esub>" by simp moreover from \n'\n\ have "\the_singleton \ t\\<^bsub>n\<^esub> \ n'" by simp moreover have "\the_singleton\\<^bsub>t n'\<^esub>" by simp moreover have "\n''\\the_singleton \ t\\<^bsub>n'\<^esub>. n'' \ \the_singleton \ t\\<^bsub>n'\<^esub> \ eval the_singleton t t' n'' \ \ (\n'''\\the_singleton \ t\\<^bsub>n\<^esub>. n''' < \the_singleton \ t\\<^bsub>n''\<^esub> \ (\n''''\\the_singleton \ t\\<^bsub>n'''\<^esub>. n'''' \ \the_singleton \ t\\<^bsub>n'''\<^esub> \ eval the_singleton t t' n'''' \'))" proof - have "n'\\the_singleton \ t\\<^bsub>n'\<^esub>" by simp moreover have "n' \ \the_singleton \ t\\<^bsub>n'\<^esub>" by simp moreover from assms(3) have "(\n''\\the_singleton \ t\\<^bsub>n\<^esub>. n'' < \the_singleton \ t\\<^bsub>n'\<^esub> \ (\n'''\\the_singleton \ t\\<^bsub>n''\<^esub>. n''' \ \the_singleton \ t\\<^bsub>n''\<^esub> \ eval the_singleton t t' n''' \'))" by auto ultimately show ?thesis using \eval the_singleton t t' n' \\ by auto qed ultimately show ?thesis using untilIA[of n "the_singleton" t n' t' \ \'] by blast qed lemma untilE[elim]: fixes t id n \' \ assumes "eval the_singleton t t' n (\' \\<^sub>b \)" shows "\n'\n. eval the_singleton t t' n' \ \ (\n''\n. n'' < n' \ eval the_singleton t t' n'' \')" proof - have "\the_singleton\\<^bsub>t n\<^esub>" by simp with \eval the_singleton t t' n (\' \\<^sub>b \)\ obtain n' where "n'\\the_singleton \ t\\<^bsub>n\<^esub>" and "(\i\n'. \the_singleton\\<^bsub>t i\<^esub>) \ (\n''\\the_singleton \ t\\<^bsub>n'\<^esub>. n'' \ \the_singleton \ t\\<^bsub>n'\<^esub> \ eval the_singleton t t' n'' \) \ (\n''\\the_singleton \ t\\<^bsub>n\<^esub>. n'' < \the_singleton \ t\\<^bsub>n'\<^esub> \ eval the_singleton t t' n'' \') \ \ (\i\n'. \the_singleton\\<^bsub>t i\<^esub>) \ eval the_singleton t t' n' \ \ (\n''\\the_singleton \ t\\<^bsub>n\<^esub>. n'' < n' \ eval the_singleton t t' n'' \')" using untilEA[of n "the_singleton" t t' \' \] by auto moreover have "\the_singleton\\<^bsub>t n'\<^esub>" by simp ultimately have "(\n''\\the_singleton \ t\\<^bsub>n'\<^esub>. n'' \ \the_singleton \ t\\<^bsub>n'\<^esub> \ eval the_singleton t t' n'' \) \ (\n''\\the_singleton \ t\\<^bsub>n\<^esub>. n'' < \the_singleton \ t\\<^bsub>n'\<^esub> \ eval the_singleton t t' n'' \')" by auto hence "eval the_singleton t t' n' \" and "(\n''\n. n'' < n' \ eval the_singleton t t' n'' \')" by auto with \eval the_singleton t t' n' \\ \n'\\the_singleton \ t\\<^bsub>n\<^esub>\ show ?thesis by auto qed end end